Created
April 29, 2016 15:18
-
-
Save anonymous/09ee76f76ad7fa57d60d33ce0a636fd3 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
$start = abs(date('w')-1); //monday = 0 | |
$start = $start . "1"; //monday = 01 (first index), friday = 41 | |
$feed = implode(file('https://www.googleapis.com/customsearch/v1?alt=atom&cx=xxx:yyy&key=abc&q=timesheet+meme&searchType=image&start='.$start)); | |
$xml = simplexml_load_string($feed); | |
$json = json_encode($xml); | |
$array = json_decode($json,TRUE); | |
$img = ""; | |
shuffle($array["entry"]); //random selection from ten results starting from $start to avoid meme repetition | |
foreach($array["entry"] as $entry) { //loops until a .jpg is found | |
$mystring = $entry["id"]; | |
$findme = '.jpg'; | |
$pos = strpos($mystring, $findme); | |
if ($pos !== false) { | |
$img = $mystring; | |
break; | |
} | |
} | |
//returns JPG as an actual image | |
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); | |
header("Cache-Control: post-check=0, pre-check=0", false); | |
header("Pragma: no-cache"); | |
header('Content-type: image/jpeg'); | |
echo file_get_contents($img); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment