Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Beacon Code

By: a guest on Jan 4th, 2014  |  syntax: PHP  |  size: 7.76 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. h3
  2. {
  3.         display: inline;
  4.         font-family: "Helvetica Neue", Helvetica, sans-serif;
  5.         font-size:200px;
  6.         color: #ed3c95;
  7.         text-shadow:
  8.                 0 1px 0 #99258e,
  9.                 0 2px 0 #99258e,
  10.                 0 3px 0 #99258e,
  11.                 0 4px 0 #f6b7d2,
  12.                 0 5px 0 #f6b7d2,
  13.                 0 6px 0 #f6b7d2,
  14.                 0 6px 1px rgba(0, 0, 0, 0.1),
  15.                 0 0 5px rgba(0, 0, 0, 0.1),
  16.                 0 1px 3px rgba(0, 0, 0, 0.3),
  17.                 0 3px 5px rgba(0, 0, 0, 0.2),
  18.                 0 5px 10px rgba(0, 0, 0, 0.25),
  19.                 0 10px 10px rgba(0, 0, 0, 0.2),
  20.                 0 20px 20px rgba(0, 0, 0, 0.15);
  21. }
  22. h3:hover
  23. {
  24.         position:relative;
  25.         top:3px;
  26.         text-shadow:
  27.                 0 1px 0 #99258e,
  28.                 0 2px 0 #99258e,
  29.                 0 3px 0 #f6b7d2,
  30.                 0 4px 0 #f6b7d2,
  31.                 0 0 5px rgba(0, 0, 0, 0.1),
  32.                 0 1px 3px rgba(0, 0, 0, 0.3),
  33.                 0 3px 5px rgba(0, 0, 0, 0.2),
  34.                 0 5px 10px rgba(0, 0, 0, 0.25),
  35.                 0 10px 10px rgba(0, 0, 0, 0.2);
  36. }
  37. h3:active
  38. {
  39.         position:relative;
  40.         top:6px;
  41.         text-shadow:
  42.                 0 1px 0 #99258e,
  43.                 0 2px 0 #f6b7d2,
  44.                 0 1px 3px rgba(0, 0, 0, 0.3),
  45.                 0 3px 5px rgba(0, 0, 0, 0.2),
  46.                 0 1px 5px rgba(0, 0, 0, 0.25);
  47. }
  48.  
  49. h3 a,a:link,a:visited,a:hover,a:active,a:focus
  50. {
  51.         text-decoration:none;
  52. }
  53. .console
  54. {
  55.         background-color:#EEE;
  56.         width:400px;
  57.         font-size:10px;
  58.         margin-left:auto;
  59.         margin-right:auto;
  60.         overflow:hidden;
  61. }
  62. .consolecontrol
  63. {
  64.         background-color:#EEE;
  65.         width:400px;
  66.         height:15px;
  67.         font-size:10px;
  68.         margin-left:auto;
  69.         margin-right:auto;
  70. }
  71. .consolecontrol:hover
  72. {
  73.         background-color:#ffffee;
  74. }
  75. .markerfailbar
  76. {
  77.         background:#ffffee;
  78.         width:100%;
  79. }
  80. </style>
  81. <?php
  82.    $mtime = microtime();
  83.    $mtime = explode(" ",$mtime);
  84.    $mtime = $mtime[1] + $mtime[0];
  85.    $starttime = $mtime;
  86. ;?>
  87. <?php
  88. /*This is a totally remade Thread locator.
  89. It uses the 4chan json API for speed and independance from other services which could cause shit to break.
  90. It's also a lot more accurate than the previous locator.
  91. The old one would only check for the first 21kb image in the thread, and give up if that wasn't it. This will search every image until the thread ends, then move on.
  92. It will search every thread with the keyword in the title, on every page, and offer a substitute if the marker isn't posted.
  93.  
  94. rev1: keyword support, better thread finding.
  95. rev2: makes sure thread info exists in the json before trying to display it (cuts down wait times and possible crashes)
  96. rev3: fixed the previously very broken keyword system because i'm dumb and php hates me. Added support for tripcode/anon OPs. Added Images counter. re-indented codes.
  97. Feb 2013:
  98. rev4: Caches thread IDs of current thread to save from having to search through 4chan each time someone requests the thread, cleaned up code a lot, optimized keywords
  99.           I still don't want to include the sub keywords to the search function, as it takes a really really long time to search with them, and people rarely adhere to them anyway.
  100. */
  101. function findthread()
  102. {
  103.         $keywords = array("mlp g", "mlpg", "my little pony general", "mlp: g");
  104.         //$keywords_sub = array("hub", "mlp", "pony", "ponies", "twilight", "sparkle", "rainbow", "dash", "pinkie", "pie", "rarity", "fluttershy", "applejack");
  105.         for($x=0;$x<=10;$x++) //cycle through every page on /mlp/
  106.         {
  107.                 $json_dump = getpageJson($x);
  108.                 for($i=0;$i<=sizeof($json_dump->threads);$i++) //cycle through all the threads on this page
  109.                 {
  110.                         if(!empty($json_dump->threads[$i]->posts[0]->sub)) //make sure the thread has a title (or sub (im guessing "subtext" or something))
  111.                         {
  112.                                 foreach($keywords as $key)//cycle through keywords
  113.                                 {
  114.                                         if(stristr($json_dump->threads[$i]->posts[0]->sub,$key)!=FALSE)//compare the title to the keywords, case insenstive.
  115.                                         {      
  116.                                                 $threadJson = getThreadJson($json_dump->threads[$i]->posts[0]->no); //do this once, to save from having to load the page from 4chan more than once
  117.                                                 if(checkForMarkerFromThreadJson($threadJson)==true)
  118.                                                 {
  119.                                                         writeRawText("thread.cache", $json_dump->threads[$i]->posts[0]->no);
  120.                                                         markerFound($threadJson);
  121.                                                         return true;
  122.                                                 }
  123.                                         }
  124.                                 }
  125.                         }
  126.                 }
  127.         }      
  128.         echo "<br/><br/>";
  129.         echo "<center><a href='http://arch.413chan.net/mlpgeneral/go'><h3 style='font-size:80px;'>*external boop*</h3></a></center><br/><br/>";
  130.         echo "<center>mlpg.co couldn't find the marker. Try the 413chan archive locator</center>";//In case the marker isn't anywhere we can find, give them a link to the 413chan locator
  131.         return false;
  132. }
  133.  
  134. function writeRawText($fileURI, $content)
  135. {
  136.         $fp = fopen($fileURI, "w+");
  137.         if(!$fp) {
  138.           //echo "cache failure";
  139.           return false;
  140.         }
  141.       fputs($fp, $content);
  142.       fclose($fp);
  143. }
  144. function readRawText($fileURI, $mode)
  145. {
  146.  
  147.         $raw = "";
  148.         $handle = @fopen($fileURI, $mode);
  149.         if($handle==false)
  150.         {
  151.                 return false;
  152.         }
  153.         while (!feof($handle))
  154.         {
  155.                 $raw .= fread($handle,8192);
  156.         }
  157.         fclose($handle);
  158.         return $raw;
  159. }
  160. function getThreadJson($threadID)
  161. {
  162.         $threadRaw = readRawText("http://a.4cdn.org/mlp/res/". $threadID. ".json", "r");
  163.         if($threadRaw==false)
  164.         {
  165.                 //echo "Thread failed to load, please refresh the page.<br/>";
  166.                 return false;
  167.         }
  168.         $threadJson = json_decode($threadRaw);//push the json data into something php can read
  169.         return $threadJson;
  170. }
  171. function getpageJson($pageNum)
  172. {
  173.         $pageRaw = readRawText("http://a.4cdn.org/mlp/". $pageNum. ".json", "r");
  174.         if($pageRaw==false)
  175.         {
  176.                 //echo "4chan page failed to load, please refresh the page.</br>";
  177.                 return false;
  178.         }
  179.         $pageJson = json_decode($pageRaw);//push the json data into something php can read
  180.         return $pageJson;
  181. }
  182. function checkForMarkerFromThreadJson($threadJson)
  183. {
  184.         for($i=0;$i<=sizeof($threadJson->posts)-1;$i++)//cycle through every post in thread
  185.         {
  186.                 if(!empty($threadJson->posts[$i]->filename))//make sure the post has an image (by checking if post data contains a filename)
  187.                 {
  188.                         if($threadJson->posts[$i]->md5 == "YgIC5DRjGYcY2F4I+vJkOw==")//compare image md5 with the known marker md5
  189.                         {
  190.                                 return true;
  191.                         }
  192.                 }
  193.         }
  194.         return false;
  195. }
  196. function markerFound($threadJson)
  197. {
  198.         echo "<center><a href='http://boards.4chan.org/mlp/res/". $threadJson->posts[0]->no. "' ><h3>*boop*</h3></a></center>";//BOOP
  199.         echo "<br/><br/><br/>";
  200.         if(!empty($threadJson->posts[0]->com))//if OP post has text
  201.         {
  202.                 echo "<center><b>Thread topic:</b> ". strip_tags(substr($threadJson->posts[0]->com,0,125)). "...". "</center>";//strip tags to remove any embedded html, and only display the first 125 chars
  203.         }
  204.         echo "<center><b>Replies:</b> ". sizeof($threadJson->posts);//number of replies
  205.         echo " <b>Images:</b> ". $threadJson->posts[0]->images; //number of images
  206.         $name = "";
  207.         if(!empty($threadJson->posts[0]->name)) //check for namefag OP
  208.         {
  209.                 $name = strip_tags($threadJson->posts[0]->name);
  210.         }
  211.         elseif(!empty($threadJson->posts[0]->trip))//check for tripfag OP
  212.         {
  213.                 $name = strip_tags($threadJson->posts[0]->trip);
  214.         }
  215.         else //check for anon OP
  216.         {
  217.         $name = "Anonymous";
  218.         }
  219.         echo " <b>Posted by:</b> ". $name;
  220.         echo "</center>";
  221. }
  222. function checkCache()
  223. {
  224. //1 read thread from file (if none exists, skip to 3)
  225. //2 cycle through posts in thread for the marker to hit the md5
  226. //3 if it doesn't, return false, run the normal findthread() and write the result to the cache
  227.  
  228. $cachedThread = readRawText("thread.cache", "r");//read the file
  229.  
  230.         if($cachedThread!=false)//if it finds text in the file
  231.         {
  232.                 $json = getThreadJson($cachedThread);
  233.                         if ($json!=false)
  234.                         {
  235.                         if(checkForMarkerFromThreadJson($json)==true)
  236.                         {
  237.                                 markerFound($json);
  238.                         }
  239.                         else
  240.                         {
  241.                                 findthread();
  242.                         }
  243.                 }
  244.                 else
  245.                 {
  246.                 findthread();
  247.                 }
  248.         }
  249.         else
  250.         {
  251.                 findthread();
  252.         }
  253. }
  254. checkCache();
  255. ?>
  256. <?php
  257.    $mtime = microtime();
  258.    $mtime = explode(" ",$mtime);
  259.    $mtime = $mtime[1] + $mtime[0];
  260.    $endtime = $mtime;
  261.    $totaltime = ($endtime - $starttime);
  262.    echo "<p style='position: absolute; right:15px; bottom:0px;'>time: ".substr($totaltime,0,5)."s </p>";
  263. ?>