Advertisement
Guest User

locator

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