Permalink
Browse files

added option in config.php to disable the updater; cleaned up a bit too

  • Loading branch information...
1 parent 1f0ef38 commit 4433fd8668f7784e236efa002b1188b038afd0f8 anon e moose committed May 20, 2012
Showing with 56 additions and 52 deletions.
  1. +30 −30 chan_archiver.php
  2. +4 −3 config.php
  3. +22 −19 index.php
View
@@ -16,14 +16,14 @@ class chan_archiver
public function doUpdate()
{
- $size = 0;
+ $size = 0;
$handle = 0;
- if( file_exists( "version.txt" ) )
+ if ( file_exists( "version.txt" ) )
{
- $size = filesize( "version.txt" );
+ $size = filesize( "version.txt" );
$handle = fopen( "version.txt", "r+" );
}
- if( !$handle || $size <= 0)
+ if ( !$handle || $size <= 0 )
{
$this->currentVersion = $this->getCurrentLatest();
$this->saveCurrentVersion();
@@ -33,24 +33,24 @@ public function doUpdate()
$this->currentVersion = fread( $handle, $size );
fclose( $handle );
}
- $this->latestVersion = $this->getCurrentLatest();
+ $this->latestVersion = $this->getCurrentLatest();
$this->updateAvailable = $this->latestVersion != $this->currentVersion;
}
protected function saveCurrentVersion()
{
$handle = fopen( "version.txt", "w+" );
- if(!$handle)
+ if ( !$handle )
die( 'Unable to open version.txt' );
fwrite( $handle, $this->currentVersion );
- fclose( $handle );
+ fclose( $handle );
}
protected function getCurrentLatest()
{
$headers = get_headers( $this->updaterurl, 1 );
- $latest = explode( "filename=", $headers['Content-Disposition'] );
- $latest = str_replace( ".tar.gz", "", str_replace( "emoose-4chan-archiver-", "", $latest[1] ) );
+ $latest = explode( "filename=", $headers[ 'Content-Disposition' ] );
+ $latest = str_replace( ".tar.gz", "", str_replace( "emoose-4chan-archiver-", "", $latest[ 1 ] ) );
return $latest;
}
@@ -66,7 +66,7 @@ protected function connectDB()
}
}
-
+
protected function closeDB()
{
if ( $this->mysql )
@@ -75,14 +75,14 @@ protected function closeDB()
$this->mysql = null;
}
}
-
+
protected function getSource( $url )
{
if ( ( $source = @file_get_contents( $url ) ) == false )
return false;
return $source;
}
-
+
protected function downloadFile( $url, $location )
{
$file = "";
@@ -94,7 +94,7 @@ protected function downloadFile( $url, $location )
$this->writeFile( $file, $location );
}
}
-
+
protected function writeFile( $data, $location )
{
if ( ( $handle = fopen( $location, "w+" ) ) )
@@ -106,19 +106,19 @@ protected function writeFile( $data, $location )
return false;
}
- protected function rrmdir($dir)
+ protected function rrmdir( $dir )
{
- foreach(glob($dir . '/*') as $file)
+ foreach ( glob( $dir . '/*' ) as $file )
{
- if(is_dir($file))
- $this->rrmdir($file);
+ if ( is_dir( $file ) )
+ $this->rrmdir( $file );
else
- unlink($file);
+ unlink( $file );
}
- rmdir($dir);
+ rmdir( $dir );
}
- public function checkThreads($checktime)
+ public function checkThreads( $checktime )
{
$this->connectDB();
$query = mysql_query( "SELECT * FROM `Threads` WHERE `Status` = '1'" );
@@ -138,7 +138,7 @@ public function checkThreads($checktime)
$this->closeDB();
return $return;
}
-
+
public function updateThread( $threadid, $board )
{
global $archiver_config;
@@ -176,7 +176,7 @@ public function updateThread( $threadid, $board )
$id = $id[ 0 ];
if ( in_array( $id, $postarr ) )
continue;
-
+
$posttime = explode( "data-utc=\"", $post[ 0 ] );
$posttime = explode( "\"", $posttime[ 1 ] );
$posttime = $posttime[ 0 ];
@@ -218,7 +218,7 @@ public function updateThread( $threadid, $board )
$this->closeDB();
return sprintf( "Checked %s (/%s/) at %s<br />\r\n", $threadid, $board, time() );
}
-
+
public function addThread( $threadid, $board, $description )
{
$this->connectDB();
@@ -248,10 +248,10 @@ public function removeThread( $threadid, $board, $deletefiles = 0 )
$num = mysql_num_rows( $query );
if ( $num <= 0 )
return false;
- if($deletefiles)
+ if ( $deletefiles )
{
- $this->rrmdir($archiver_config[ 'storage' ] . $board . "/" . $threadid . "/");
- unlink($archiver_config[ 'storage' ] . $board . "/" . $threadid . ".html");
+ $this->rrmdir( $archiver_config[ 'storage' ] . $board . "/" . $threadid . "/" );
+ unlink( $archiver_config[ 'storage' ] . $board . "/" . $threadid . ".html" );
}
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 ) );
@@ -280,8 +280,8 @@ public function getOngoingThreadCount()
$query = mysql_query( "SELECT * FROM `Threads` WHERE `Status` = '1'" );
if ( !$query )
die( 'Could not query database: ' . mysql_error() );
-
- $num = mysql_num_rows($query);
+
+ $num = mysql_num_rows( $query );
$this->closeDB();
return $num;
}
@@ -295,7 +295,7 @@ public function getThreads()
$thrarray = array();
while ( $thr = mysql_fetch_object( $query ) )
{
- $q2 = mysql_query( sprintf("SELECT * FROM `Posts` WHERE `ThreadID` = '%s' AND `Board` = '%s' ORDER BY `PostTime` DESC", $thr->ID, $thr->Board));
+ $q2 = mysql_query( sprintf( "SELECT * FROM `Posts` WHERE `ThreadID` = '%s' AND `Board` = '%s' ORDER BY `PostTime` DESC", $thr->ID, $thr->Board ) );
$lasttime = 0;
if ( !$q2 )
die( 'Could not query database: ' . mysql_error() );
@@ -307,7 +307,7 @@ public function getThreads()
$thr->Status,
$thr->LastChecked,
$thr->Description,
- $lasttime
+ $lasttime
) );
}
$this->closeDB();
View
@@ -40,9 +40,10 @@
$archiver_config[ 'login_pass' ] = "implying";
// -----------------------------------------------------------
-// INTERNAL STUFF
-// leave this alone
+// ADVANCED STUFF
+// you should probably leave this alone
// -----------------------------------------------------------
-$archiver_config[ 'login_enabled' ] = $archiver_config[ 'login_del' ] || $archiver_config[ 'login_add' ] || $archiver_config[ 'login_chk' ];
+$archiver_config[ 'updater_enabled' ] = true;
+$archiver_config[ 'login_enabled' ] = $archiver_config[ 'login_del' ] || $archiver_config[ 'login_add' ] || $archiver_config[ 'login_chk' ];
?>
View
@@ -2,7 +2,8 @@
session_start();
include "chan_archiver.php";
$t = new chan_archiver();
-$t->doUpdate();
+if ( !isset($archiver_config[ 'updater_enabled' ]) || $archiver_config[ 'updater_enabled' ] )
+ $t->doUpdate();
// login stuff
if ( isset( $_REQUEST[ 'login' ] ) && isset( $_REQUEST[ 'user' ] ) && isset( $_REQUEST[ 'pass' ] ) )
@@ -18,31 +19,31 @@
$return = "";
if ( $delenabled && isset( $_REQUEST[ 'del' ] ) && isset( $_REQUEST[ 'id' ] ) && isset( $_REQUEST[ 'brd' ] ) )
- $return .= $t->removeThread( $_REQUEST[ 'id' ], $_REQUEST[ 'brd' ], $_REQUEST[ 'files' ]);
+ $return .= $t->removeThread( $_REQUEST[ 'id' ], $_REQUEST[ 'brd' ], $_REQUEST[ 'files' ] );
if ( $chkenabled && isset( $_REQUEST[ 'chk' ] ) && isset( $_REQUEST[ 'id' ] ) && isset( $_REQUEST[ 'brd' ] ) )
$return .= $t->updateThread( $_REQUEST[ 'id' ], $_REQUEST[ 'brd' ] );
if ( $chkenabled && isset( $_REQUEST[ 'chka' ] ) )
- $return .= $t->checkThreads(false);
+ $return .= $t->checkThreads( false );
if ( $delenabled && isset( $_REQUEST[ 'upd' ] ) && isset( $_REQUEST[ 'id' ] ) && isset( $_REQUEST[ 'brd' ] ) )
$return .= $t->setThreadDescription( $_REQUEST[ 'id' ], $_REQUEST[ 'brd' ], $_REQUEST[ 'desc' ] );
if ( $addenabled && isset( $_REQUEST[ 'add' ] ) && isset( $_REQUEST[ 'url' ] ) )
{
- if(substr($_REQUEST[ 'url' ],0,7) != "http://")
+ if ( substr( $_REQUEST[ 'url' ], 0, 7 ) != "http://" )
$_REQUEST[ 'url' ] = "http://" . $_REQUEST[ 'url' ];
- if(!isset($_REQUEST[ 'desc' ]))
+ 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 ) )
+ 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' ] );
}
-if($return != "")
+if ( $return != "" )
{
$_SESSION[ 'returnvar' ] = $return;
- header('Location: index.php');
+ header( 'Location: index.php' );
exit;
}
echo <<<ENDHTML
@@ -78,18 +79,19 @@
<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'] != "")
+if ( isset( $_SESSION[ 'returnvar' ] ) && $_SESSION[ 'returnvar' ] != "" )
{
- $arr = explode('<br />', $_SESSION['returnvar']);
- foreach($arr as $str)
+ $arr = explode( '<br />', $_SESSION[ 'returnvar' ] );
+ foreach ( $arr as $str )
{
- if(empty($str) || strlen($str) <= 3) continue;
+ if ( empty( $str ) || strlen( $str ) <= 3 )
+ continue;
echo <<<ENDHTML
<div class="infobox">$str</div><br />
ENDHTML;
}
- $_SESSION['returnvar'] = "";
- unset($_SESSION['returnvar']);
+ $_SESSION[ 'returnvar' ] = "";
+ unset( $_SESSION[ 'returnvar' ] );
}
if ( !$isloggedin )
@@ -110,12 +112,11 @@
</table>
</form>
ENDHTML;
-
+
}
else if ( $archiver_config[ 'login_enabled' ] )
{
-
echo <<<ENDHTML
<form action="?refresh" method="POST">
<input type="hidden" name="user" value="" />
@@ -184,7 +185,7 @@
$link = "<a href=\"$local\">{$thr[0]}</a>";
$check = "";
}
- if($delenabled)
+ if ( $delenabled )
$check .= <<<ENDHTML
<input type="submit" name="del" onclick="if(confirm('Delete files too?')) document.getElementById('files{$i}').value='1';" value="Remove"/>
ENDHTML;
@@ -212,8 +213,10 @@
}
echo "</table><br />";
-$bookmarkleturl = "http://" . ($_SERVER['HTTP_HOST'] ? $_SERVER['HTTP_HOST'] : $_SERVER["SERVER_NAME"]) . $_SERVER["SCRIPT_NAME"];
+$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>. <abbr title="use this when you're on the page you want to archive"><a href="javascript:open('<?php echo $bookmarkleturl; ?>?add=Add&url=' + document.URL.replace('http://', ''));">bookmarklet</a></abbr></font>
+<font size="1" family="Verdana">downloaded from <a href="http://github.com/emoose/4chan-archiver/">github.com/emoose/4chan-archiver</a>. <abbr title="use this when you're on the page you want to archive"><a href="javascript:open('<?php
+echo $bookmarkleturl;
+?>?add=Add&url=' + document.URL.replace('http://', ''));">bookmarklet</a></abbr></font>
</body>
</html>

0 comments on commit 4433fd8

Please sign in to comment.