Created
November 7, 2011 16:05
-
-
Save mbmccormick/1345367 to your computer and use it in GitHub Desktop.
Gist caching and download logic.
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
| <?php | |
| // extract gist id from url | |
| $gist = $_GET[id]; | |
| // create cache directory | |
| if (file_exists("gists/") == false) | |
| mkdir("gists", 0700); | |
| // check if we have need to update our local copy of the gist | |
| if (file_exists("gists/" . $gist . ".js") == false || | |
| (time() - filemtime("gists/" . $gist . ".js")) > 1209600 || | |
| $_GET[force] == "true") // if file exists, or file is greater than 14 days old, or force update | |
| { | |
| // download javascript file from github | |
| $ch = curl_init("https://gist.github.com/" . $gist . ".js"); | |
| $fp = fopen("gists/" . $gist . ".js", "wb"); | |
| curl_setopt($ch, CURLOPT_FILE, $fp); | |
| curl_setopt($ch, CURLOPT_HEADER, 0); | |
| curl_exec($ch); | |
| curl_close($ch); | |
| fclose($fp); | |
| } | |
| // open local copy of gist | |
| $fp = fopen("gists/" . $gist . ".js", "r"); | |
| // parse javascript | |
| // render gist content | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment