Skip to content

Instantly share code, notes, and snippets.

@MrM0bius
Created November 15, 2014 16:26
Show Gist options
  • Save MrM0bius/f4749a2f318cf889b103 to your computer and use it in GitHub Desktop.
Save MrM0bius/f4749a2f318cf889b103 to your computer and use it in GitHub Desktop.
JanusVR Random r/vrsites link generator
<?php
$options = array('http' => array('user_agent' => 'JanusVR random site (v0.1)'));
$context = stream_context_create($options);
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) {
die();
}
if ($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);
echo '<html><head><title>Random Room from /r/vrsites</title></head><body><img src="http://janusvr.thevirtualarts.com/question.png" width="300"><p></p><meta property="og:image" content="question.png">';
echo '<a href="';
echo $selectedset["data"]["children"][$rnum]["data"]["url"];
echo '">';
echo $selectedset["data"]["children"][$rnum]["data"]["title"];
echo '</a>';
echo '<!--<FireBoxRoom><AssetImage id="q" src="question.png" /><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"><Link pos="0 0 3.3" fwd="0 0 -1" url="';
echo $selectedset["data"]["children"][$rnum]["data"]["url"];
echo '" col="0.6 1 0.6" scale="2.8 3.5 1" auto_load="true" title="';
echo $selectedset["data"]["children"][$rnum]["data"]["title"];
echo '" /></Room></FireBoxRoom>--></body></html>';
unset($rbool);
unset($selectedset);
unset($rnum);
die;
?>
@MrM0bius
Copy link
Author

Here's the newest version which includes caching the json array from Reddit locally and refreshing the cached file by running with ?random . A few other tweaks as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment