Created
April 26, 2015 14:43
-
-
Save DaveFlash/a4556e45449faed7b9bb to your computer and use it in GitHub Desktop.
Grab Apple Watch screenshots, and directly display them on the same page for apps using iTunes URL. Inspired by @stroughtonsmith, based on @raphaelz php-version and some of my own work on it. For the live web version go to http://ddw.nu/applewatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>Preview Apple Watch screenshots</title> | |
<style> | |
.error {color: #FF0000;} | |
</style> | |
<script type="text/javascript"> | |
function setfocus() { | |
document.awatchpreview.url.focus(); | |
} | |
</script> | |
</head> | |
<body onLoad="setfocus()"> | |
<center> | |
<?php | |
//$url = $_GET['url']; | |
// define variables and set to empty values | |
$urlErr = ""; | |
$url = ""; | |
$booln = false; | |
if ($_SERVER["REQUEST_METHOD"] == "POST") { | |
if (empty($_POST["url"])) { | |
$url = ""; | |
} else { | |
$url = test_input($_POST["url"]); | |
// check if URL address syntax is valid (this regular expression also allows dashes in the URL) | |
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$url)) { | |
$urlErr = "Invalid URL"; | |
} | |
if (strpos($url, 'itunes.apple.com') === false || strpos($url, '/app/') === false) { | |
$urlErr = "The link you submitted is not a valid iTunes Store link for apps, please make sure you sumbit a valid App Store-app link."; | |
} else { | |
$screenshots = array(); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_USERAGENT, "AppleWatchStore/1 CFNetwork/720.2.4 Darwin/14.1.0 (x86_64)"); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Apple-Store-Front: 143441-1,20')); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 0); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$content = json_decode(curl_exec($ch)); | |
preg_match('/id(\d+)/', $url, $matches); | |
$id = $matches[1]; | |
$screenshotsArr = $content->storePlatformData->{'product-dv-product'}->results->{$id}->screenshotsByType->appleWatch; | |
$booln = true; | |
} | |
} | |
} | |
function test_input($data) { | |
$data = trim($data); | |
$data = stripslashes($data); | |
$data = htmlspecialchars($data); | |
return $data; | |
} | |
?> | |
<h2>Preview Apple Watch-apps</h2> | |
<p>Enter an App Store url/link and press preview</p> | |
<form name="awatchpreview" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> | |
App Store: <input type="text" name="url" value="<?php echo $url;?>" size="175"> | |
<br> | |
<span class="error"><?php echo $urlErr;?></span> | |
<br><br> | |
<input type="submit" name="submit" value="preview"> | |
</form> | |
<?php | |
echo "<br>"; | |
if ($booln === true) { | |
foreach($screenshotsArr as $screenshot) { | |
$screenshot = $screenshot[0]; | |
echo "<img src=\" $screenshot->url \" />"; | |
} | |
$booln = false; | |
} | |
?> | |
</center> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment