Advertisement
Guest User

Broken MLPG Beacon

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