rework mobile download links - add in QR code too
This commit is contained in:
		
							
								
								
									
										68
									
								
								website/page/code/mobile-download.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								website/page/code/mobile-download.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,68 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
include_once ( "apk/ApkParser.php" );
 | 
			
		||||
include_once ( "url/url_to_absolute.php" );
 | 
			
		||||
include_once ( "userscript.php" );
 | 
			
		||||
 | 
			
		||||
function getMobileVersion($apkfile)
 | 
			
		||||
{
 | 
			
		||||
	$result = Array();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	$apkinfo = new ApkParser ( $apkfile );
 | 
			
		||||
 | 
			
		||||
	$manifest = $apkinfo->getManifest();
 | 
			
		||||
 | 
			
		||||
	$result['apk_version'] = $manifest->getVersionName();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	$archive = $apkinfo->getApkArchive();
 | 
			
		||||
	$iitc_file = "assets/total-conversion-build.user.js";
 | 
			
		||||
	if ( $archive->statName ( $iitc_file ) === FALSE );
 | 
			
		||||
		$iitc_file = "assets/iitc.js";
 | 
			
		||||
 | 
			
		||||
	$stream = $archive->getStream ( $iitc_file );
 | 
			
		||||
 | 
			
		||||
	$header = loadUserScriptHeader ( $stream );
 | 
			
		||||
 | 
			
		||||
	$result['iitc_version'] = $header['@version'];
 | 
			
		||||
 | 
			
		||||
	return $result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function iitcMobileDownload ( $apkfile )
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
	$version = getMobileVersion ( $apkfile );
 | 
			
		||||
 | 
			
		||||
	$apk_version = $version['apk_version'];
 | 
			
		||||
	$iitc_version = preg_replace ( '/^(\d+\.\d+\.\d+)\.(\d{8}\.\d{6})/', '\1<small class="muted">.\2</small>', $version['iitc_version'] );
 | 
			
		||||
 | 
			
		||||
	# we need an absolute link for the QR Code
 | 
			
		||||
	# get the URL of this page itself
 | 
			
		||||
	$pageurl = ($_SERVER['HTTPS'] ? "https" : "http")."://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
 | 
			
		||||
	$apkurl = url_to_absolute ( $pageurl, $apkfile );
 | 
			
		||||
?>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<div>
 | 
			
		||||
 | 
			
		||||
<img style="float: right; margin: 10px;" src="https://chart.googleapis.com/chart?cht=qr&chs=120x120&chld=L|2&chl=<?php print urlencode($apkurl); ?>" alt="QR Code for download">
 | 
			
		||||
 | 
			
		||||
<p>
 | 
			
		||||
IITC Mobile version <?php print $apk_version; ?>, with IITC version <?php print $iitc_version; ?>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
<p>
 | 
			
		||||
<a style="margin-right: 1em;" onclick="if(track)({track{'mobile','download','release');}" class="btn btn-large btn-primary" href="<?php print $apkfile; ?>">Download</a> or scan the QR Code
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
</div>
 | 
			
		||||
<div style="clear: both"><div>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
@@ -1,32 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
include_once ( "apk/ApkParser.php" );
 | 
			
		||||
include_once ( "userscript.php" );
 | 
			
		||||
 | 
			
		||||
function getMobileVersion($apkfile)
 | 
			
		||||
{
 | 
			
		||||
	$result = Array();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	$apkinfo = new ApkParser ( $apkfile );
 | 
			
		||||
 | 
			
		||||
	$manifest = $apkinfo->getManifest();
 | 
			
		||||
 | 
			
		||||
	$result['apk_version'] = $manifest->getVersionName();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	$archive = $apkinfo->getApkArchive();
 | 
			
		||||
	$iitc_file = "assets/total-conversion-build.user.js";
 | 
			
		||||
	if ( $archive->statName ( $iitc_file ) === FALSE );
 | 
			
		||||
		$iitc_file = "assets/iitc.js";
 | 
			
		||||
 | 
			
		||||
	$stream = $archive->getStream ( $iitc_file );
 | 
			
		||||
 | 
			
		||||
	$header = loadUserScriptHeader ( $stream );
 | 
			
		||||
 | 
			
		||||
	$result['iitc_version'] = $header['@version'];
 | 
			
		||||
 | 
			
		||||
	return $result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
@@ -38,22 +38,14 @@ IITC Mobile is still in the early stages of development. Many things do not yet
 | 
			
		||||
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
include_once ( "code/mobile-version.php" );
 | 
			
		||||
include_once ( "code/mobile-download.php" );
 | 
			
		||||
 | 
			
		||||
$apkfile = "mobile/IITC-Mobile-0.3.apk";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if ( file_exists($apkfile) )
 | 
			
		||||
{
 | 
			
		||||
	$version = getMobileVersion ( $apkfile );
 | 
			
		||||
 | 
			
		||||
	$apk_version = $version['apk_version'];
 | 
			
		||||
	$iitc_version = preg_replace ( '/^(\d+\.\d+\.\d+)\.(\d{8}\.\d{6})/', '\1<small class="muted">.\2</small>', $version['iitc_version'] );
 | 
			
		||||
 | 
			
		||||
	print "<p>IITC Mobile version $apk_version, with IITC version $iitc_version</p>\n";
 | 
			
		||||
 | 
			
		||||
	print "<p><a onclick=\"if(track)({track{'mobile','download','release');}\" class=\"btn btn-large btn-primary\" href=\"$apkfile\">Download</a></p>\n";
 | 
			
		||||
 | 
			
		||||
	iitcMobileDownload ( $apkfile );
 | 
			
		||||
}
 | 
			
		||||
else
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -60,27 +60,21 @@ iitcDesktopPluginDownloadTable ( $path );
 | 
			
		||||
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
include_once ( "code/mobile-version.php" );
 | 
			
		||||
include_once ( "code/mobile-download.php" );
 | 
			
		||||
 | 
			
		||||
$apkfile = "$path/IITC_Mobile-test.apk";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if ( file_exists($apkfile) )
 | 
			
		||||
{
 | 
			
		||||
	$version = getMobileVersion ( $apkfile );
 | 
			
		||||
 | 
			
		||||
	$apk_version = $version['apk_version'];
 | 
			
		||||
	$iitc_version = preg_replace ( '/^(\d+\.\d+\.\d+)\.(\d{8}\.\d{6})/', '\1<small class="muted">.\2</small>', $version['iitc_version'] );
 | 
			
		||||
 | 
			
		||||
	print "<p>IITC Mobile version $apk_version, with IITC version $iitc_version</p>\n";
 | 
			
		||||
 | 
			
		||||
	print "<a onclick=\"if(track)({track{'mobile','download','$path');}\" class=\"btn btn-large btn-primary\" href=\"$apkfile\">Download</a>\n";
 | 
			
		||||
 | 
			
		||||
	iitcMobileDownload ( $apkfile );
 | 
			
		||||
}
 | 
			
		||||
else
 | 
			
		||||
{
 | 
			
		||||
	print "<div class=\"alert alert-error\">Error: <b>$apkfile</b> not found</div>\n";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user