rewrite to present a link rather than redirect, to attempt to present

the link only on Android devices, and to encourage users to email me
if I'm wrong about their not being on a device.
This commit is contained in:
Eric House 2012-11-25 10:39:46 -08:00
parent 5019d3960b
commit d7bb869a5b

View file

@ -1,9 +1,7 @@
<!-- -*- mode: sgml; -*- -->
<?php
// script to work around URLs with custom schemes not being clickable in
// Android's SMS app. It runs on my server and SMS messages hold links to it
// that it then redirects to the passed-in scheme.
$g_androidStrings = array( "android", );
$scheme = "newxwgame";
$host = "10.0.2.2";
@ -13,37 +11,40 @@ $np = $_REQUEST["np"];
$id = $_REQUEST["id"];
$wl = $_REQUEST["wl"];
$content = "0; url=$scheme://$host?room=$room&lang=$lang&np=$np";
if ( $id != "" ) {
$content .= "&id=$id";
}
if ( $wl != "" ) {
$content .= "&wl=$wl";
$agent = $_SERVER['HTTP_USER_AGENT'];
$onAndroid = false;
for ( $ii = 0; $ii < count($g_androidStrings) && !$onAndroid; ++$ii ) {
$needle = $g_androidStrings[$ii];
$onAndroid = 0 != stripos( $agent, $needle );
}
$localurl = "$scheme://$host?room=$room&lang=$lang&np=$np";
if ( $id != "" ) {
$localurl .= "&id=$id";
}
if ( $wl != "" ) {
$localurl .= "&wl=$wl";
}
if ( $onAndroid ) {
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 SMS redirect</title>
<meta http-equiv="REFRESH"
content="$content">
<title>Crosswords Invite redirect</title>
</head>
<body>
<div align="center">
<img src="./icon48x48.png">
<p>redirecting to Crosswords....</p>
<p>This page is meant to be viewed (briefly) on your Android
device after which Crosswords should launch.
</p>
<p>If this fails it's probably because you don't have a new enough
version of Crosswords installed. Or because your browser does
not allow URL redirects.
<h1><a href="$localurl">Tap this link to launch Crosswords with
your new game.</a>
</h1>
<p>If this fails it&apos;s probably because you don&apos;t have a new enough
version of Crosswords installed.
</p>
<img src="./icon48x48.png">
@ -54,4 +55,38 @@ print <<<EOF
EOF;
} else {
$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 script to recognize"
. " this as an Android browser.");
print <<<EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Crosswords Invite redirect</title>
</head>
<body>
<div align="center">
<img src="./icon48x48.png">
</div>
<p>This page is meant to be viewed on a browser on your Android
device. Please open the email that sent you here on that device to
complete the invitation process.
</p>
<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>
</body>
</html>
EOF;
}
?>