Skip to content

Instantly share code, notes, and snippets.

@sirkitree
Forked from MrM0bius/janus-rand-wlocalcache.php
Last active August 29, 2015 14:09
Show Gist options
  • Save sirkitree/efce49d5475bf5c645cc to your computer and use it in GitHub Desktop.
Save sirkitree/efce49d5475bf5c645cc to your computer and use it in GitHub Desktop.
<?php
$options = array('http' => array('user_agent' => 'JanusVR random site (v0.1)'));
$context = stream_context_create($options);
/**
* Should be able to use a more typical cache pattern here.
*
* Something like:
function _cache_get($var) {
static $cache_objects;
if (!isset($cache_objects[$var])) {
if (!isset($var)) {
$vrsites = file_get_contents();
}
$cache_objects[$var] = $vrsites;
}
return $cache_objects[$var];
}
*/
if (isset($_GET['refresh'])) {
$rvrsites1 = file_get_contents('http://reddit.com/r/vrsites/.json?limit=100', false, $context);
$rvrsites2 = file_get_contents('http://reddit.com/r/vrsites/.json?count=100&after=t3_2akppo&limit=100', false, $context);
if ($rvrsites1 === false || $rvrsites2 === false) {
die();
}
file_put_contents("vrsites_array1.json", $rvrsites1);
file_put_contents("vrsites_array2.json", $rvrsites2);
}
$rvrsites1 = file_get_contents('http://janusvr.thevirtualarts.com/vrsites_array1.json');
$rvrsites2 = file_get_contents('http://janusvr.thevirtualarts.com/vrsites_array2.json');
$set1 = json_decode($rvrsites1, true);
$set2 = json_decode($rvrsites2, true);
$rbool = rand(0, 1);
if ($rbool = =1){
$selectedset = $set1;
}
else {
$selectedset = $set2;
}
$rnum = rand(0, 99);
$link = $selectedset["data"]["children"][$rnum]["data"];
$fireboxroom = '<!--<FireBoxRoom>';
$fireboxroom .= '<AssetImage id="q" src="question.png" />';
$fireboxroom .= '<Room gravity="0" skybox_left_id="q" skybox_right_id="q" skybox_front_id="q" skybox_back_id="q" skybox_up_id="q" skybox_down_id="q">';
$fireboxroom .= '<Link pos="0 0 3.3" fwd="0 0 -1" url="' . $link["url"] . '" col="0.6 1 0.6" scale="2.8 3.5 1" auto_load="true" title="' . $link["title"] . '" /></Room></FireBoxRoom>-->';
$html_head = '<html><head><title>Random Room from /r/vrsites</title></head>';
$html_body = '<body>';
$html_body .= '<img src="http://janusvr.thevirtualarts.com/question.png" width="300">';
$html_body .= '<meta property="og:image" content="question.png">';
$html_body .= '<a href="' . $link["url"] . '">' . $link["title"] . '</a>';
$html_body .= $fireboxroom;
$html_body .= '</body></html>';
echo $html_head . $html_body;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment