mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-07 05:24:46 +01:00
rewrite not-installed php script in py
This commit is contained in:
parent
ca64d69cef
commit
9e2ef3a698
2 changed files with 82 additions and 111 deletions
|
@ -1,111 +0,0 @@
|
|||
<?php
|
||||
|
||||
$g_androidStrings = array( "android", );
|
||||
$g_apk = 'XWords4-release_android_beta_55-39-gbffb231.apk';
|
||||
|
||||
function printHead() {
|
||||
print <<<EOF
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="/xw4mobile.css" />
|
||||
<title>CrossWords Invite redirect</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="center">
|
||||
<img class="center" src="../icon48x48.png"/>
|
||||
</div>
|
||||
EOF;
|
||||
}
|
||||
|
||||
function printTail() {
|
||||
print <<<EOF
|
||||
</body>
|
||||
</html>
|
||||
EOF;
|
||||
}
|
||||
|
||||
function printNonAndroid($agent) {
|
||||
$subject = "Android device not identified";
|
||||
|
||||
$body = htmlentities("My browser is running on an android device but"
|
||||
. " says its user agent is: \"$agent\"."
|
||||
. " Please fix your website to recognize"
|
||||
. " this as an Android browser.");
|
||||
print <<<EOF
|
||||
<div class="center">
|
||||
<p>This page is meant to be viewed on an Android device.</p>
|
||||
<hr>
|
||||
<p>(If you <em>are</em> viewing this on an Android device,
|
||||
you've found a bug! Please <a href="mailto:
|
||||
xwords@eehouse.org?subject=$subject&body=$body">email me</a>
|
||||
(and be sure to leave the user agent string in the email body.)
|
||||
</p>
|
||||
</div>
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
function printAndroid() {
|
||||
print <<<EOF
|
||||
<div>
|
||||
<p>You'll have come here after clicking a link in an email or
|
||||
text inviting you to a CrossWords game. But you should not be seeing
|
||||
this page.</p>
|
||||
|
||||
<p>If you got this page on your device, it means either
|
||||
<ul>
|
||||
<li>You don't have CrossWords installed</li>
|
||||
<li>OR</li>
|
||||
<li>that when you clicked on the link and were asked to choose between a
|
||||
browser and CrossWords you chose the browser.</li>
|
||||
</ul></p>
|
||||
|
||||
<p>In the first case, install the latest CrossWords,
|
||||
either <a href="market://search?q=pname:org.eehouse.android.xw4">via
|
||||
the Google Play store</a> or
|
||||
(sideloading) <a href="https://sourceforge.net/projects/xwords/files/xwords_Android/4.4%20beta%20129/XWords4-release_android_beta_129.apk/download">via
|
||||
Sourceforge.net</a>. After the install is finished go back to the
|
||||
invite email (or text) and tap the link again.</p>
|
||||
|
||||
<p>In the second case, hit your browser's back button, click the
|
||||
link in your invite email (or text) again, and this time let
|
||||
CrossWords handle it.</p>
|
||||
|
||||
<p>(If you get tired of having to having to make that choice, Android
|
||||
will allow you to make CrossWords the default. If you do that
|
||||
CrossWords will be given control of all URLs that start with
|
||||
"http://eehouse.org/and/" -- not all URLs of any type.)</p>
|
||||
|
||||
<p>Have fun. And as always, <a href="mailto:xwords@eehouse.org">let
|
||||
me know</a> if you have problems or suggestions.</p>
|
||||
</div>
|
||||
<div class="center">
|
||||
<img class="center" src="../icon48x48.png"/>
|
||||
</div>
|
||||
EOF;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Main()
|
||||
**********************************************************************/
|
||||
$agent = $_SERVER['HTTP_USER_AGENT'];
|
||||
$onAndroid = false;
|
||||
for ( $ii = 0; $ii < count($g_androidStrings) && !$onAndroid; ++$ii ) {
|
||||
$needle = $g_androidStrings[$ii];
|
||||
$onAndroid = false !== stripos( $agent, $needle );
|
||||
}
|
||||
$onFire = false !== stripos( $agent, 'silk' );
|
||||
|
||||
printHead();
|
||||
if ( /*true || */ $onFire || $onAndroid ) {
|
||||
printAndroid();
|
||||
} else {
|
||||
printNonAndroid($agent);
|
||||
}
|
||||
printTail();
|
||||
|
||||
|
||||
?>
|
82
xwords4/android/scripts/and_index.py
Executable file
82
xwords4/android/scripts/and_index.py
Executable file
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
try:
|
||||
from mod_python import apache
|
||||
apacheAvailable = True
|
||||
except ImportError:
|
||||
apacheAvailable = False
|
||||
|
||||
def printHead():
|
||||
return """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="/xw4mobile.css" />
|
||||
<title>CrossWords Invite redirect</title>
|
||||
</head>
|
||||
<body>
|
||||
"""
|
||||
|
||||
def printTail():
|
||||
return '</body></html>'
|
||||
|
||||
def printAndroid():
|
||||
return """
|
||||
<div>
|
||||
|
||||
<p>You should not be seeing this page.</p>
|
||||
|
||||
<p>One of two things went wrong:
|
||||
<div>• You don't have CrossWords installed</div>
|
||||
<div>OR</div>
|
||||
<div>• When you clicked on a link and were asked to choose between a
|
||||
browser and CrossWords you chose the browser.</div>
|
||||
</p>
|
||||
|
||||
<p>In the first case, install the latest CrossWords, either <a
|
||||
href="market://search?q=pname:org.eehouse.android.xw4">via the Google
|
||||
Play store</a> or <a href="https://eehouse.org/latest.apk">directly
|
||||
from the author's site</a> (sideloading). After the install is
|
||||
finished go back to the invite email (or text) and tap the link
|
||||
again.</p>
|
||||
|
||||
<p>Otherwise, hit your browser's back button, click the
|
||||
invitation link again, and this time choose CrossWords to handle
|
||||
it.</p>
|
||||
|
||||
<p>(If you get tired of having to having to make that choice, Android
|
||||
will allow you to make CrossWords the default. If you do that
|
||||
CrossWords will be launched for all URLs that start with
|
||||
"https://eehouse.org/and/" -- not all URLs of any type.)</p>
|
||||
|
||||
<p>Have fun. And as always, <a href="mailto:xwords@eehouse.org">let
|
||||
me know</a> if you have problems or suggestions.</p>
|
||||
</div>
|
||||
"""
|
||||
|
||||
def printNonAndroid(agent):
|
||||
subject = 'Android device not identified'
|
||||
body = 'My browser is running on an android device but says its' \
|
||||
+ ' user agent is: \"{agent}\". Please fix your website' \
|
||||
+ ' to recognize this as an Android browser'.format(agent=agent)
|
||||
fmt = """
|
||||
<div>
|
||||
<p>This page is meant to be viewed on an Android device.</p>
|
||||
<hr>
|
||||
<p>(If you <em>are</em> viewing this on an Android device,
|
||||
you've found a bug! Please <a href="mailto:
|
||||
xwords@eehouse.org?subject={subject}&body={body}\n\n">email me</a>.
|
||||
</p>
|
||||
</div>
|
||||
"""
|
||||
return fmt.format(subject=subject, body=body)
|
||||
|
||||
|
||||
def index(req):
|
||||
str = printHead()
|
||||
agent = req.headers_in.get('User-Agent', None)
|
||||
if agent and 'Android' in agent:
|
||||
str += printAndroid()
|
||||
else:
|
||||
str += printNonAndroid(agent)
|
||||
str += printTail()
|
||||
return str
|
Loading…
Reference in a new issue