Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
<?php /* This is a hack of the thread locator to provide the old /go functionality from arch.413chan.net. Issue a redirect to the currently marked thread, also drop meta refresh tag in case headers can't be sent, and finally, if that doesn't work, just provide a link to the current marked thread rev1: simple hack of existing code. removed stylesheet and timing code. added redirect() function, changed markerFound() function to issue the redirect, rather than writing out the locator's usual HTML page. contact - fluxy@derpymail.com */ /*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; } } } } // 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 "<br/><br/>"; echo "<center><b>Sorry!</b> Could not find current thread.</center>"; echo "<center><a href='http://boards.4chan.org/mlp/catalog#s=general'>Click to check the catalog.</a></center>"; 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) { // quick hack to make this a /go page redirect("http://boards.4chan.org/mlp/thread/". $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 "<meta http-equiv='Location' content='" . $url . "'/>"; echo "<center>Oops! Could not write location header: headers already sent. You should be redirected to the correct thread in a few seconds. If not, <a href='" . $url . "'>Click here to go to the current marked thread</a></center>"; } 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(!$json->posts[0]->archived && checkForMarkerFromThreadJson($json)==true) { markerFound($json); } else { findthread(); } } else { findthread(); } } else { findthread(); } } checkCache(); ?>
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Crypto admin access
37 min ago | 0.43 KB
+12,000$ in 2 days
CSS | 37 min ago | 0.72 KB
Free Crypto Method
CSS | 38 min ago | 0.72 KB
Documents
38 min ago | 0.43 KB
Untitled
20 hours ago | 0.68 KB
The Road Not Taken
1 day ago | 0.79 KB
OG OLDHAM CODE
3 days ago | 27.75 KB
remove current bid and bid now button from au...
PHP | 4 days ago | 0.80 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!