Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <style media="screen" type="text/css">
- h3
- {
- display: inline;
- font-family: "Helvetica Neue", Helvetica, sans-serif;
- font-size:200px;
- color: #ed3c95;
- text-shadow:
- 0 1px 0 #99258e,
- 0 2px 0 #99258e,
- 0 3px 0 #99258e,
- 0 4px 0 #f6b7d2,
- 0 5px 0 #f6b7d2,
- 0 6px 0 #f6b7d2,
- 0 6px 1px rgba(0, 0, 0, 0.1),
- 0 0 5px rgba(0, 0, 0, 0.1),
- 0 1px 3px rgba(0, 0, 0, 0.3),
- 0 3px 5px rgba(0, 0, 0, 0.2),
- 0 5px 10px rgba(0, 0, 0, 0.25),
- 0 10px 10px rgba(0, 0, 0, 0.2),
- 0 20px 20px rgba(0, 0, 0, 0.15);
- }
- h3:hover
- {
- position:relative;
- top:3px;
- text-shadow:
- 0 1px 0 #99258e,
- 0 2px 0 #99258e,
- 0 3px 0 #f6b7d2,
- 0 4px 0 #f6b7d2,
- 0 0 5px rgba(0, 0, 0, 0.1),
- 0 1px 3px rgba(0, 0, 0, 0.3),
- 0 3px 5px rgba(0, 0, 0, 0.2),
- 0 5px 10px rgba(0, 0, 0, 0.25),
- 0 10px 10px rgba(0, 0, 0, 0.2);
- }
- h3:active
- {
- position:relative;
- top:6px;
- text-shadow:
- 0 1px 0 #99258e,
- 0 2px 0 #f6b7d2,
- 0 1px 3px rgba(0, 0, 0, 0.3),
- 0 3px 5px rgba(0, 0, 0, 0.2),
- 0 1px 5px rgba(0, 0, 0, 0.25);
- }
- h3 a,a:link,a:visited,a:hover,a:active,a:focus
- {
- text-decoration:none;
- }
- .console
- {
- background-color:#EEE;
- width:400px;
- font-size:10px;
- margin-left:auto;
- margin-right:auto;
- overflow:hidden;
- }
- .consolecontrol
- {
- background-color:#EEE;
- width:400px;
- height:15px;
- font-size:10px;
- margin-left:auto;
- margin-right:auto;
- }
- .consolecontrol:hover
- {
- background-color:#ffffee;
- }
- .markerfailbar
- {
- background:#ffffee;
- width:100%;
- }
- </style>
- <?php
- $mtime = microtime();
- $mtime = explode(" ",$mtime);
- $mtime = $mtime[1] + $mtime[0];
- $starttime = $mtime;
- ;?>
- <?php
- /*This is a totally remade Thread locator.
- It uses the 4chan json API for speed and independance from other services which could cause shit to break.
- It's also a lot more accurate than the previous locator.
- 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.
- It will search every thread with the keyword in the title, on every page, and offer a substitute if the marker isn't posted.
- rev1: keyword support, better thread finding.
- rev2: makes sure thread info exists in the json before trying to display it (cuts down wait times and possible crashes)
- 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.
- Feb 2013:
- 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
- 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.
- */
- function findthread()
- {
- $keywords = array("mlp g", "mlpg", "my little pony general", "mlp: g");
- //$keywords_sub = array("hub", "mlp", "pony", "ponies", "twilight", "sparkle", "rainbow", "dash", "pinkie", "pie", "rarity", "fluttershy", "applejack");
- for($x=0;$x<=10;$x++) //cycle through every page on /mlp/
- {
- $json_dump = getpageJson($x);
- for($i=0;$i<=sizeof($json_dump->threads);$i++) //cycle through all the threads on this page
- {
- if(!empty($json_dump->threads[$i]->posts[0]->sub)) //make sure the thread has a title (or sub (im guessing "subtext" or something))
- {
- if(preg_match("/^mlp general\b/i", $json_dump->threads[$i]->posts[0]->sub))
- {
- $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
- writeRawText("thread.cache", $json_dump->threads[$i]->posts[0]->no);
- markerFound($threadJson);
- return true;
- }
- }
- }
- }
- echo "<br/><br/>";
- echo "<center><a href='http://boards.4chan.org/mlp/catalog#s=general'><img src='sadmarkerpone.png'> </a></center><br/><br/>";
- 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
- return false;
- }
- function writeRawText($fileURI, $content)
- {
- $fp = fopen($fileURI, "w+");
- if(!$fp) {
- //echo "cache failure";
- return false;
- }
- fputs($fp, $content);
- fclose($fp);
- }
- function readRawText($fileURI, $mode)
- {
- $raw = "";
- $handle = @fopen($fileURI, $mode);
- if($handle==false)
- {
- return false;
- }
- while (!feof($handle))
- {
- $raw .= fread($handle,8192);
- }
- fclose($handle);
- return $raw;
- }
- function getThreadJson($threadID)
- {
- $threadRaw = readRawText("http://a.4cdn.org/mlp/thread/". $threadID. ".json", "r");
- if($threadRaw==false)
- {
- //echo "Thread failed to load, please refresh the page.<br/>";
- return false;
- }
- $threadJson = json_decode($threadRaw);//push the json data into something php can read
- return $threadJson;
- }
- function getpageJson($pageNum)
- {
- $pageRaw = readRawText("http://a.4cdn.org/mlp/". $pageNum. ".json", "r");
- if($pageRaw==false)
- {
- //echo "4chan page failed to load, please refresh the page.</br>";
- return false;
- }
- $pageJson = json_decode($pageRaw);//push the json data into something php can read
- return $pageJson;
- }
- function checkForMarkerFromThreadJson($threadJson)
- {
- return true;
- for($i=0;$i<=sizeof($threadJson->posts)-1;$i++)//cycle through every post in thread
- {
- if(!empty($threadJson->posts[$i]->filename))//make sure the post has an image (by checking if post data contains a filename)
- {
- if($threadJson->posts[$i]->md5 == "YgIC5DRjGYcY2F4I+vJkOw==")//compare image md5 with the known marker md5
- {
- return true;
- }
- }
- }
- return false;
- }
- function markerFound($threadJson)
- {
- echo "<center><a href='http://boards.4chan.org/mlp/thread/". $threadJson->posts[0]->no. "' ><img src='otp.gif' /></center>";//BOOP
- echo "<br/><br/><br/>";
- if(!empty($threadJson->posts[0]->com))//if OP post has text
- {
- 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
- }
- echo "<center><b>Replies:</b> ". sizeof($threadJson->posts);//number of replies
- echo " <b>Images:</b> ". $threadJson->posts[0]->images; //number of images
- $name = "";
- if(!empty($threadJson->posts[0]->name)) //check for namefag OP
- {
- $name = strip_tags($threadJson->posts[0]->name);
- }
- elseif(!empty($threadJson->posts[0]->trip))//check for tripfag OP
- {
- $name = strip_tags($threadJson->posts[0]->trip);
- }
- else //check for anon OP
- {
- $name = "Anonymous";
- }
- echo " <b>Posted by:</b> ". $name;
- echo "</center>";
- }
- function checkCache()
- {
- //1 read thread from file (if none exists, skip to 3)
- //2 cycle through posts in thread for the marker to hit the md5
- //3 if it doesn't, return false, run the normal findthread() and write the result to the cache
- $cachedThread = readRawText("thread.cache", "r");//read the file
- if($cachedThread!=false)//if it finds text in the file
- {
- $json = getThreadJson($cachedThread);
- if ($json!=false)
- {
- if(!$json->posts[0]->archived && checkForMarkerFromThreadJson($json)==true)
- {
- markerFound($json);
- }
- else
- {
- findthread();
- }
- }
- else
- {
- findthread();
- }
- }
- else
- {
- findthread();
- }
- }
- checkCache();
- ?>
- <?php
- $mtime = microtime();
- $mtime = explode(" ",$mtime);
- $mtime = $mtime[1] + $mtime[0];
- $endtime = $mtime;
- $totaltime = ($endtime - $starttime);
- echo "<p style='position: absolute; right:15px; bottom:0px;'>time: ".substr($totaltime,0,5)."s </p>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement