Advertisement
Guest User

locator

a guest
Jan 6th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.64 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. if(preg_match("/^mlp general\b/i", $json_dump->threads[$i]->posts[0]->sub))
  114. {
  115. $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
  116. writeRawText("thread.cache", $json_dump->threads[$i]->posts[0]->no);
  117. markerFound($threadJson);
  118. return true;
  119. }
  120. }
  121. }
  122. }
  123. echo "<br/><br/>";
  124. echo "<center><a href='http://boards.4chan.org/mlp/catalog#s=general'><img src='sadmarkerpone.png'> </a></center><br/><br/>";
  125. 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
  126. return false;
  127. }
  128.  
  129. function writeRawText($fileURI, $content)
  130. {
  131. $fp = fopen($fileURI, "w+");
  132. if(!$fp) {
  133. //echo "cache failure";
  134. return false;
  135. }
  136. fputs($fp, $content);
  137. fclose($fp);
  138. }
  139. function readRawText($fileURI, $mode)
  140. {
  141.  
  142. $raw = "";
  143. $handle = @fopen($fileURI, $mode);
  144. if($handle==false)
  145. {
  146. return false;
  147. }
  148. while (!feof($handle))
  149. {
  150. $raw .= fread($handle,8192);
  151. }
  152. fclose($handle);
  153. return $raw;
  154. }
  155. function getThreadJson($threadID)
  156. {
  157. $threadRaw = readRawText("http://a.4cdn.org/mlp/thread/". $threadID. ".json", "r");
  158. if($threadRaw==false)
  159. {
  160. //echo "Thread failed to load, please refresh the page.<br/>";
  161. return false;
  162. }
  163. $threadJson = json_decode($threadRaw);//push the json data into something php can read
  164. return $threadJson;
  165. }
  166. function getpageJson($pageNum)
  167. {
  168. $pageRaw = readRawText("http://a.4cdn.org/mlp/". $pageNum. ".json", "r");
  169. if($pageRaw==false)
  170. {
  171. //echo "4chan page failed to load, please refresh the page.</br>";
  172. return false;
  173. }
  174. $pageJson = json_decode($pageRaw);//push the json data into something php can read
  175. return $pageJson;
  176. }
  177. function checkForMarkerFromThreadJson($threadJson)
  178. {
  179. return true;
  180.  
  181. for($i=0;$i<=sizeof($threadJson->posts)-1;$i++)//cycle through every post in thread
  182. {
  183. if(!empty($threadJson->posts[$i]->filename))//make sure the post has an image (by checking if post data contains a filename)
  184. {
  185. if($threadJson->posts[$i]->md5 == "YgIC5DRjGYcY2F4I+vJkOw==")//compare image md5 with the known marker md5
  186. {
  187. return true;
  188. }
  189. }
  190. }
  191. return false;
  192. }
  193. function markerFound($threadJson)
  194. {
  195. echo "<center><a href='http://boards.4chan.org/mlp/thread/". $threadJson->posts[0]->no. "' ><img src='otp.gif' /></center>";//BOOP
  196. echo "<br/><br/><br/>";
  197. if(!empty($threadJson->posts[0]->com))//if OP post has text
  198. {
  199. 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
  200. }
  201. echo "<center><b>Replies:</b> ". sizeof($threadJson->posts);//number of replies
  202. echo " <b>Images:</b> ". $threadJson->posts[0]->images; //number of images
  203. $name = "";
  204. if(!empty($threadJson->posts[0]->name)) //check for namefag OP
  205. {
  206. $name = strip_tags($threadJson->posts[0]->name);
  207. }
  208. elseif(!empty($threadJson->posts[0]->trip))//check for tripfag OP
  209. {
  210. $name = strip_tags($threadJson->posts[0]->trip);
  211. }
  212. else //check for anon OP
  213. {
  214. $name = "Anonymous";
  215. }
  216. echo " <b>Posted by:</b> ". $name;
  217. echo "</center>";
  218. }
  219. function checkCache()
  220. {
  221. //1 read thread from file (if none exists, skip to 3)
  222. //2 cycle through posts in thread for the marker to hit the md5
  223. //3 if it doesn't, return false, run the normal findthread() and write the result to the cache
  224.  
  225. $cachedThread = readRawText("thread.cache", "r");//read the file
  226.  
  227. if($cachedThread!=false)//if it finds text in the file
  228. {
  229. $json = getThreadJson($cachedThread);
  230. if ($json!=false)
  231. {
  232. if(!$json->posts[0]->archived && checkForMarkerFromThreadJson($json)==true)
  233. {
  234. markerFound($json);
  235. }
  236. else
  237. {
  238. findthread();
  239. }
  240. }
  241. else
  242. {
  243. findthread();
  244. }
  245. }
  246. else
  247. {
  248. findthread();
  249. }
  250. }
  251. checkCache();
  252. ?>
  253. <?php
  254. $mtime = microtime();
  255. $mtime = explode(" ",$mtime);
  256. $mtime = $mtime[1] + $mtime[0];
  257. $endtime = $mtime;
  258. $totaltime = ($endtime - $starttime);
  259. echo "<p style='position: absolute; right:15px; bottom:0px;'>time: ".substr($totaltime,0,5)."s </p>";
  260. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement