Title: [PHP] 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))                         {                                 foreach($keywords as $key)//cycle through keywords                                 {                                         if(stristr($json_dump->threads[$i]->posts[0]->sub,$key)!=FALSE)//compare the title to the keywords, case insenstive.                                         {                                                       $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                                                 if(checkForMarkerFromThreadJson($threadJson)==true)                                                 {                                                         writeRawText("thread.cache", $json_dump->threads[$i]->posts[0]->no);                                                         markerFound($threadJson);                                                         return true;                                                 }                                         }                                 }                         }                 }         }                   // couldn't find a thread, so tell the user and drop a link back to the locator         // alternatively, we could just redirect to the locator without any information however it's probably best to let the user know what is happening.         echo "

";         echo "
Sorry!  Could not find current thread.
";         echo "
Return to 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/res/". $threadID. ".json", "r");         if($threadRaw==false)         {                 //echo "Thread failed to load, please refresh the page.
";                 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.
";                 return false;         }         $pageJson = json_decode($pageRaw);//push the json data into something php can read         return $pageJson; } function checkForMarkerFromThreadJson($threadJson) {         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) {         // quick hack to make this a /go page         redirect("http://boards.4chan.org/mlp/res/". $threadJson->posts[0]->no); //302 "Moved" Redirect to current thread } function redirect($url, $statusCode = 303) {         if (headers_sent() === false)     {                 header('Location: ' . $url, true, $statusCode);         } else { // couldn't send headers, so drop a meta refresh                 echo "";                 echo "
Oops! Could not write location header: headers already sent.  You should be redirected to the correct thread in a few seconds.  If not, Click here to go to the current marked thread
";         }    die(); } 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(checkForMarkerFromThreadJson($json)==true)                         {                                 markerFound($json);                         }                         else                         {                                 findthread();                         }                 }                 else                 {                 findthread();                 }         }         else         {                 findthread();         } } checkCache(); ?>