Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed posts not having their images redirected correctly; also fixed …

…refresh issue & added pretty infoboxes
  • Loading branch information...
commit 84704801a0c481d4c15215c1e67452627ba93b2a 1 parent 9aec2f5
emoose authored
39 chan_archiver.php
View
@@ -106,7 +106,7 @@ protected function writeFile( $data, $location )
return false;
}
- public function checkThreads()
+ public function checkThreads($checktime)
{
$this->connectDB();
$query = mysql_query( "SELECT * FROM `Threads` WHERE `Status` = '1'" );
@@ -115,14 +115,16 @@ public function checkThreads()
$num = mysql_num_rows( $query );
if ( $num <= 0 )
return false;
+ $return = "";
while ( $row = mysql_fetch_object( $query ) )
{
- if ( time() - $row->LastChecked < 90 )
+ if ( $checktime && time() - $row->LastChecked < 90 )
continue;
- $this->updateThread( $row->ID, $row->Board );
+ $return .= $this->updateThread( $row->ID, $row->Board );
}
$this->closeDB();
+ return $return;
}
public function updateThread( $threadid, $board )
@@ -191,13 +193,18 @@ public function updateThread( $threadid, $board )
$this->downloadFile( $thumurl, $thumstor );
$fixeddata = str_replace( $fileurl, $pubfilestor, $fixeddata );
$fixeddata = str_replace( $thumurl, $pubthumstor, $fixeddata );
- //echo "<!-- " . $fileurl . " -->";
}
mysql_query( sprintf( "INSERT INTO `Posts` ( `ID`, `ThreadID`, `Board`, `PostTime` ) VALUES ( '%s', '%s', '%s', '%s' )", $id, $threadid, $board, $posttime ) );
}
- echo sprintf( "Checked %s (/%s/) at %s<br />\r\n", $threadid, $board, time() );
+ // fix for posts we already have downloaded
+ $fixeddata = str_replace( "http://1.thumbs.4chan.org/" . $board . "/thumb/", $archiver_config[ 'pubstorage' ] . $board . "/" . $threadid . "/thumbs/", $fixeddata );
+ $fixeddata = str_replace( "http://0.thumbs.4chan.org/" . $board . "/thumb/", $archiver_config[ 'pubstorage' ] . $board . "/" . $threadid . "/thumbs/", $fixeddata );
+ $fixeddata = str_replace( "http://images.4chan.org/" . $board . "/src/", $archiver_config[ 'pubstorage' ] . $board . "/" . $threadid . "/", $fixeddata );
+ // thread is done
mysql_query( sprintf( "UPDATE `Threads` SET `LastChecked` = '%s' WHERE `Board` = '%s' AND `ID` = '%s'", time(), $board, $threadid ) );
$this->writeFile( $fixeddata, $archiver_config[ 'storage' ] . $board . "/" . $threadid . ".html" );
+ $this->closeDB();
+ return sprintf( "Checked %s (/%s/) at %s<br />\r\n", $threadid, $board, time() );
}
public function addThread( $threadid, $board, $description )
@@ -214,9 +221,8 @@ public function addThread( $threadid, $board, $description )
$query = mysql_query( sprintf( "INSERT INTO `Threads` ( `ID`, `Board`, `Status`, `LastChecked`, `Description` ) VALUES ( '%s', '%s', '1', '0', '%s' )", $threadid, $board, $description ) );
if ( !$query )
die( 'Could not add thread: ' . mysql_error() );
- echo sprintf( "Added thread %s (/%s/)<br />\r\n", $threadid, $board );
$this->closeDB();
- return true;
+ return sprintf( "Added thread %s (/%s/)<br />\r\n", $threadid, $board );
}
public function removeThread( $threadid, $board )
@@ -231,9 +237,8 @@ public function removeThread( $threadid, $board )
return false;
mysql_query( sprintf( "DELETE FROM `Threads` WHERE `ID` = '%s' AND Board = '%s'", $threadid, $board ) );
mysql_query( sprintf( "DELETE FROM `Posts` WHERE `ThreadID` = '%s' AND Board = '%s'", $threadid, $board ) );
- echo sprintf( "Removed thread %s (/%s/)<br />\r\n", $threadid, $board );
$this->closeDB();
- return true;
+ return sprintf( "Removed thread %s (/%s/)<br />\r\n", $threadid, $board );
}
public function setThreadDescription( $threadid, $board, $description )
@@ -247,10 +252,22 @@ public function setThreadDescription( $threadid, $board, $description )
if ( $num <= 0 )
return false;
mysql_query( sprintf( "UPDATE `Threads` SET `Description` = '%s' WHERE `ID` = '%s' AND Board = '%s'", $description, $threadid, $board ) );
- echo sprintf( "Updated thread %s (/%s/)<br />\r\n", $threadid, $board );
$this->closeDB();
- return true;
+ return sprintf( "Updated thread %s (/%s/)<br />\r\n", $threadid, $board );
}
+
+ public function getOngoingThreadCount()
+ {
+ $this->connectDB();
+ $query = mysql_query( "SELECT * FROM `Threads` WHERE `Status` = '1'" );
+ if ( !$query )
+ die( 'Could not query database: ' . mysql_error() );
+
+ $num = mysql_num_rows($query);
+ $this->closeDB();
+ return $num;
+ }
+
public function getThreads()
{
$this->connectDB();
2  cron.php
View
@@ -1,5 +1,5 @@
<?php
include "chan_archiver.php";
$t = new chan_archiver();
-$t->checkThreads();
+echo $t->checkThreads(true);
?>
BIN  images/menu_light.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  images/menu_tick.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 index.php
View
@@ -3,52 +3,98 @@
include "chan_archiver.php";
$t = new chan_archiver();
$t->doUpdate();
-echo <<<ENDHTML
-<html>
-<head>
-<title>4chan archiver - by anon e moose</title>
-<link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico">
-</head>
-<body>
-<a href="http://github.com/emoose/4chan-archiver/"><h2>4chan archiver - by anon e moose</h2></a>
-<p>
-ENDHTML;
-if ( $t->updateAvailable )
-{
- echo <<<ENDHTML
-<h1>There is an <a href="{$t->updaterurl}" onclick="alert('make sure you delete version.txt after updating!');">update</a> available! <a href="{$t->compareurl}{$t->currentVersion}...{$t->latestVersion}">(diff)</a></h1>
-ENDHTML;
-}
+
// login stuff
if ( isset( $_REQUEST[ 'login' ] ) && isset( $_REQUEST[ 'user' ] ) && isset( $_REQUEST[ 'pass' ] ) )
{
$_SESSION[ 'uname' ] = $_REQUEST[ 'user' ];
$_SESSION[ 'pword' ] = $_REQUEST[ 'pass' ];
}
-
+// commands
$isloggedin = ( isset( $_SESSION[ 'uname' ] ) && isset( $_SESSION[ 'pword' ] ) && $_SESSION[ 'uname' ] == $archiver_config[ 'login_user' ] && $_SESSION[ 'pword' ] == $archiver_config[ 'login_pass' ] ) || !$archiver_config[ 'login_enabled' ];
$delenabled = ( !$archiver_config[ 'login_del' ] || $isloggedin );
$chkenabled = ( !$archiver_config[ 'login_chk' ] || $isloggedin );
$addenabled = ( !$archiver_config[ 'login_add' ] || $isloggedin );
-
+$return = "";
if ( $delenabled && isset( $_REQUEST[ 'del' ] ) && isset( $_REQUEST[ 'id' ] ) && isset( $_REQUEST[ 'brd' ] ) )
- $t->removeThread( $_REQUEST[ 'id' ], $_REQUEST[ 'brd' ] );
+ $return .= $t->removeThread( $_REQUEST[ 'id' ], $_REQUEST[ 'brd' ] );
if ( $chkenabled && isset( $_REQUEST[ 'chk' ] ) && isset( $_REQUEST[ 'id' ] ) && isset( $_REQUEST[ 'brd' ] ) )
- $t->updateThread( $_REQUEST[ 'id' ], $_REQUEST[ 'brd' ] );
+ $return .= $t->updateThread( $_REQUEST[ 'id' ], $_REQUEST[ 'brd' ] );
+
+if ( $chkenabled && isset( $_REQUEST[ 'chka' ] ) )
+ $return .= $t->checkThreads(false);
if ( $delenabled && isset( $_REQUEST[ 'upd' ] ) && isset( $_REQUEST[ 'id' ] ) && isset( $_REQUEST[ 'brd' ] ) )
- $t->setThreadDescription( $_REQUEST[ 'id' ], $_REQUEST[ 'brd' ], $_REQUEST[ 'desc' ] );
+ $return .= $t->setThreadDescription( $_REQUEST[ 'id' ], $_REQUEST[ 'brd' ], $_REQUEST[ 'desc' ] );
-if ( $addenabled && isset( $_REQUEST[ 'add' ] ) && isset( $_REQUEST[ 'url' ] ) && $c = preg_match_all( "/.*?(?:[a-z][a-z0-9_]*).*?(?:[a-z][a-z0-9_]*).*?(?:[a-z][a-z0-9_]*).*?(?:[a-z][a-z0-9_]*).*?((?:[a-z][a-z0-9_]*)).*?(\d+)/is", $_REQUEST[ 'url' ], $matches ) )
- $t->addThread( $matches[ 2 ][ 0 ], $matches[ 1 ][ 0 ], $_REQUEST[ 'desc' ] );
+if ( $addenabled && isset( $_REQUEST[ 'add' ] ) && isset( $_REQUEST[ 'url' ] ) )
+{
+ if(!substr($_REQUEST[ 'url' ],0,7) != "http://")
+ $_REQUEST[ 'url' ] = "http://" . $_REQUEST[ 'url' ];
+ if(!isset($_REQUEST[ 'desc' ]))
+ $_REQUEST[ 'desc' ] = "";
+ if( $c = preg_match_all( "/.*?(?:[a-z][a-z0-9_]*).*?(?:[a-z][a-z0-9_]*).*?(?:[a-z][a-z0-9_]*).*?(?:[a-z][a-z0-9_]*).*?((?:[a-z][a-z0-9_]*)).*?(\d+)/is", $_REQUEST[ 'url' ], $matches ) )
+ $return .= $t->addThread( $matches[ 2 ][ 0 ], $matches[ 1 ][ 0 ], $_REQUEST[ 'desc' ] );
+}
-echo "</p>";
+if($return != "")
+{
+ $_SESSION[ 'returnvar' ] = $return;
+ header('Location: index.php');
+ exit;
+}
+echo <<<ENDHTML
+<html>
+<head>
+<title>4chan archiver - by anon e moose</title>
+<link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico">
+<style type="text/css">
+.infobox{
+width:350px;
+border:solid 1px #DEDEDE;
+background:#FFFFCC url(images/menu_tick.png) 8px 6px no-repeat;
+color:#222222;
+padding:4px;
+text-align:center;
+}
+.alertbox{
+width:350px;
+border:solid 1px #DEDEDE;
+background:#FF3330 url(images/menu_light.png) 8px 6px no-repeat;
+color:#222222;
+padding:4px;
+text-align:center;
+}
+</style>
+</head>
+<body>
+<a href="http://github.com/emoose/4chan-archiver/"><h2>4chan archiver - by anon e moose</h2></a>
+ENDHTML;
+if ( $t->updateAvailable )
+{
+ echo <<<ENDHTML
+ <div class="alertbox">There is an <a href="{$t->updaterurl}" onclick="alert('make sure you delete version.txt after updating!');">update</a> available! <a href="{$t->compareurl}{$t->currentVersion}...{$t->latestVersion}">(diff)</a></div><br />
+ENDHTML;
+}
+if(isset($_SESSION['returnvar']) && $_SESSION['returnvar'] != "")
+{
+ $arr = explode('<br />', $_SESSION['returnvar']);
+ foreach($arr as $str)
+ {
+ if(empty($str) || strlen($str) <= 3) continue;
+ echo <<<ENDHTML
+ <div class="infobox">$str</div><br />
+ENDHTML;
+ }
+ $_SESSION['returnvar'] = "";
+ unset($_SESSION['returnvar']);
+}
if ( !$isloggedin )
{
echo <<<ENDHTML
-<form action="" method="POST">
+<form action="?refresh" method="POST">
<table border="1" bordercolor="#FFCC00" style="background-color:#FFFFCC" width="340" cellpadding="3" cellspacing="3">
<tr>
<td><b>Admin Login</b></td>
@@ -69,7 +115,7 @@
{
echo <<<ENDHTML
-<form action="" method="POST">
+<form action="?refresh" method="POST">
<input type="hidden" name="user" value="" />
<input type="hidden" name="pass" value="" />
<input type="submit" name="login" value="Logout"/>
@@ -78,10 +124,17 @@
}
$threads = $t->getThreads();
-echo <<<ENDHTML
-<form action="" method="POST">
-<input type="submit" name="refresh" value="Refresh"/>
+echo "<form action=\"?refresh\" method=\"POST\">";
+if ( $chkenabled )
+{
+ $onclick = $t->getOngoingThreadCount() >= 10 ? "alert('Since you have many ongoing threads it may seem like the page has hung, just be patient and they will all update');" : "";
+ echo <<<ENDHTML
+<form action="?refresh" method="POST">
+<input type="submit" name="chka" onclick="$onclick" value="Recheck All"/>
</form>
+ENDHTML;
+}
+echo <<<ENDHTML
<table border="1" bordercolor="#FFCC00" style="background-color:#FFFFCC" width="900" cellpadding="3" cellspacing="3">
<tr>
<td>Thread ID</td>
@@ -117,7 +170,7 @@
$lastpost = "N/A";
echo <<<ENDHTML
- <form action="" method="POST">
+ <form action="?refresh" method="POST">
<input type="hidden" name="id" value="{$thr[0]}"/>
<input type="hidden" name="brd" value="{$thr[1]}"/>
<tr>
@@ -138,7 +191,7 @@
if ( $addenabled )
{
echo <<<ENDHTML
-<form action="" method="POST">
+<form action="?refresh" method="POST">
<table border="1" bordercolor="#FFCC00" style="background-color:#FFFFCC" width="610" cellpadding="3" cellspacing="3">
<tr>
<td><b>Add Thread</b></td>
@@ -154,7 +207,8 @@
</form>
ENDHTML;
}
+$bookmarkleturl = "http://" . ($_SERVER['HTTP_HOST'] ? $_SERVER['HTTP_HOST'] : $_SERVER["SERVER_NAME"]) . $_SERVER["SCRIPT_NAME"];
?>
-<font size="1" family="Verdana">Downloaded from <a href="http://github.com/emoose/4chan-archiver/">github.com/emoose/4chan-archiver</a>. <a href="javascript:alert('nah just kidding');">check for updates?</a></font>
+<font size="1" family="Verdana">downloaded from <a href="http://github.com/emoose/4chan-archiver/">github.com/emoose/4chan-archiver</a>. <a href="javascript:alert('nah just kidding');">check for updates?</a>. <a href="javascript:open('<?php echo $bookmarkleturl; ?>?add=Add&url=' + document.URL.replace('http://', ''));" onclick="alert('use this when you're on the page you want to archive');">bookmarklet</a></font>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.