Skip to content

Commit

Permalink
remove deprecated functions and various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Novik committed Aug 6, 2018
1 parent 302d5d8 commit 161cba2
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 35 deletions.
10 changes: 4 additions & 6 deletions php/Torrent.php
Expand Up @@ -64,19 +64,17 @@ public function __construct( $data, $meta = array(), $piece_length = 256, $log_c

protected function notify_log( $msg )
{
if(function_exists($this->log_callback))
if(is_callable($this->log_callback))
{
$f = $this->log_callback;
$f($msg);
call_user_func($this->log_callback,$msg);
}
}

protected function notify_err( $msg )
{
if(function_exists($this->err_callback))
if(is_callable($this->err_callback))
{
$f = $this->err_callback;
$f($msg);
call_user_func($this->err_callback,$msg);
}
$this->errors[] = new Exception($msg);
}
Expand Down
4 changes: 2 additions & 2 deletions php/addtorrent.php
Expand Up @@ -108,7 +108,7 @@
$torrent = new Torrent($file['file']);
if($torrent->errors())
{
unlink($file['file']);
@unlink($file['file']);
$file['status'] = "FailedFile";
}
else
Expand All @@ -120,7 +120,7 @@
!isset($_REQUEST['not_add_path']),
$dir_edit,$label,$saveUploadedTorrents,isset($_REQUEST['fast_resume']))===false)
{
unlink($file['file']);
@unlink($file['file']);
$file['status'] = "Failed";
}
}
Expand Down
2 changes: 1 addition & 1 deletion php/getsettings.php
Expand Up @@ -4,7 +4,7 @@

$s = '{}';
$fname = getSettingsPath()."/uisettings.json";
$fo = fopen($fname, 'r');
$fo = @fopen($fname, 'r');
if($fo!==false)
{
if(flock($fo, LOCK_SH))
Expand Down
5 changes: 5 additions & 0 deletions php/util.php
Expand Up @@ -240,6 +240,11 @@ function safe_json_encode($value)
return(!function_exists('json_last_error') || json_last_error()==JSON_ERROR_NONE ? $encoded : json_encode(utf8ize($value)));
}

function sortArrayTime( $a, $b )
{
return( ($a["time"] > $b["time"]) ? 1 : (($a["time"] < $b["time"]) ? -1 : 0) );
}

function toLog( $str )
{
global $log_file;
Expand Down
2 changes: 1 addition & 1 deletion plugins/create/action.php
Expand Up @@ -119,7 +119,7 @@ static public function getTrackerDomain($announce)
$useExternal = "inner";
$task = new rTask( array
(
'arg'=>call_user_func('getFileName',$path_edit),
'arg' => getFileName($path_edit),
'requester'=>'create',
'name'=>'create',
'path_edit'=>$_REQUEST['path_edit'],
Expand Down
18 changes: 16 additions & 2 deletions plugins/create/createtorrent.php
Expand Up @@ -16,6 +16,20 @@
ini_set('log_errors',false);
}

function log_stdout( $msg )
{
$fp=fopen("php://stdout","w");
fputs($fp, $msg."\n");
fclose($fp);
}

function log_stderr( $msg )
{
$fp=fopen("php://stderr","w");
fputs($fp, $msg."\n");
fclose($fp);
}

$taskNo = $argv[1];
$fname = rTask::formatPath($taskNo).'/params';
if(is_file($fname) && is_readable($fname))
Expand Down Expand Up @@ -50,8 +64,8 @@
$announce_list[] = $trackers;
$path_edit = trim($request['path_edit']);
$piece_size = $request['piece_size'];
$callback_log = create_function('$msg', '$fp=fopen("php://stdout","w"); fputs($fp, $msg."\n"); fclose($fp);' );
$callback_err = create_function('$msg', '$fp=fopen("php://stderr","w"); fputs($fp, $msg."\n"); fclose($fp);' );
$callback_log = "log_stdout";
$callback_err = "log_stderr";

if(count($announce_list)>0)
{
Expand Down
7 changes: 6 additions & 1 deletion plugins/erasedata/update.php
Expand Up @@ -13,6 +13,11 @@ function eLog( $str )
toLog( "erasedata: ".$str );
}

function sortByLevel( $a, $b )
{
return( strrpos($b,"/")-strrpos($a,"/") );
}

function parseOneItem($item)
{
global $enableForceDeletion;
Expand Down Expand Up @@ -62,7 +67,7 @@ function parseOneItem($item)
else
{
$dirs = array_unique($dirs);
usort( $dirs, create_function( '$a,$b', 'return strrpos($b,"/")-strrpos($a,"/");' ) );
usort( $dirs, "sortByLevel" );
foreach( $dirs as $dir )
if(@rmdir($dir))
eLog('Successfully delete dir '.$dir);
Expand Down
8 changes: 6 additions & 2 deletions plugins/extsearch/engines.php
Expand Up @@ -187,7 +187,7 @@ public function isOverflow()
}
public function pack()
{
uasort($this->lst, create_function( '$a,$b', 'return( ($a["time"] > $b["time"]) ? 1 : (($a["time"] < $b["time"]) ? -1 : 0) );'));
uasort($this->lst, "sortArrayTime");
$cnt = count($this->lst)/2;
$i=0;
foreach( $this->lst as $key=>$value )
Expand Down Expand Up @@ -366,6 +366,10 @@ static protected function correctItem(&$nfo)
$nfo["name"] = commonEngine::toUTF($nfo["name"],"ISO-8859-1");
}

static protected function sortBySeeds( $a, $b )
{
return( (intval($a["seeds"]) > intval($b["seeds"])) ? -1 : ((intval($a["seeds"]) < intval($b["seeds"])) ? 1 : 0) );
}

public function action( $eng, $what, $cat = "all" )
{
Expand Down Expand Up @@ -395,7 +399,7 @@ public function action( $eng, $what, $cat = "all" )
$object->action($what,$cat,$arr,$this->limit,false);
}
}
uasort($arr, create_function( '$a,$b', 'return( (intval($a["seeds"]) > intval($b["seeds"])) ? -1 : ((intval($a["seeds"]) < intval($b["seeds"])) ? 1 : 0) );'));
uasort($arr, array(__CLASS__,"sortBySeeds"));
$cnt = 0;
$history = self::loadHistory(true);

Expand Down
8 changes: 2 additions & 6 deletions plugins/extsearch/engines/RARbgTorrentAPI.php
Expand Up @@ -31,10 +31,8 @@ class RARbgTorrentAPIEngine extends commonEngine

public function get_token()
{
$tokenurl='https://torrentapi.org/pubapi_v2.php?app_id=ruTorrent_extsearch&get_token=get_token';
$json = file_get_contents($tokenurl);
$obj = json_decode($json);
return( $obj && property_exists($obj,'token') ? $obj->token : false );
$cli = $this->fetch('https://torrentapi.org/pubapi_v2.php?app_id=ruTorrent_extsearch&get_token=get_token');
return( $cli && ($obj = json_decode($cli->results)) && property_exists($obj,'token') ? $obj->token : false );
}

public function action($what,$cat,&$ret,$limit,$useGlobalCats)
Expand All @@ -43,7 +41,6 @@ public function action($what,$cat,&$ret,$limit,$useGlobalCats)
if( $token!==false )
{
$added = 0;

if($useGlobalCats)
$categories = array
(
Expand All @@ -61,7 +58,6 @@ public function action($what,$cat,&$ret,$limit,$useGlobalCats)
$cat = $categories['all'];
else
$cat = $categories[$cat];

$cli = $this->fetch( "https://torrentapi.org/pubapi_v2.php?app_id=ruTorrent_extsearch&token=$token&format=json_extended&mode=search&search_string=$what&category=$cat" );
if( $cli && ($obj = json_decode($cli->results)) && property_exists($obj,"torrent_results") )
{
Expand Down
7 changes: 6 additions & 1 deletion plugins/feeds/action.php
Expand Up @@ -107,6 +107,11 @@ function formatItemDescription($torrent)
return($desc);
}

function sortByPubDate( $a, $b )
{
return( (intval($a["pubDate"]) > intval($b["pubDate"])) ? -1 : ((intval($a["pubDate"]) < intval($b["pubDate"])) ? 1 : strcmp($a["title"],$b["title"])) );
}

$mode = (isset($_REQUEST['mode'])) ? $_REQUEST['mode'] : 'all';
$url = (empty($_SERVER['HTTPS']) ? "http" : "https")."://".$_SERVER['HTTP_HOST'].str_replace('/plugins/feeds/action.php','/',$_SERVER['PHP_SELF']);
$server = explode(':',rTorrentSettings::get()->server);
Expand Down Expand Up @@ -222,7 +227,7 @@ function formatItemDescription($torrent)
}
$items[] = $item;
}
usort( $items, create_function( '$a,$b', 'return( (intval($a["pubDate"]) > intval($b["pubDate"])) ? -1 : ((intval($a["pubDate"]) < intval($b["pubDate"])) ? 1 : strcmp($a["title"],$b["title"])) );'));
usort( $items, "sortByPubDate");
foreach( $items as $item )
{
$ret.="\r\n<item>";
Expand Down
4 changes: 2 additions & 2 deletions plugins/geoip/sqlite.php
Expand Up @@ -41,13 +41,13 @@ function sqlite_exec1($dbhandle, $query, &$error_msg)
{
if (PHP_VERSION_ID < 50400)
{
sqlite_exec($dbhandle, $query, $error_msg);
@sqlite_exec($dbhandle, $query, $error_msg);
}
else
{
try
{
$dbhandle->exec($query);
@$dbhandle->exec($query);
}
catch (Exception $exception)
{
Expand Down
6 changes: 5 additions & 1 deletion plugins/history/history.php
Expand Up @@ -29,12 +29,16 @@ public function delete( $hashes )
unset($this->data[$hash]);
$this->store();
}
static protected function sortByActionTime( $a, $b )
{
return($b["action_time"]-$a["action_time"]);
}
public function add( $e, $limit )
{
$e["action_time"] = time();
$e["hash"] = md5(serialize($e));
$this->data[$e["hash"]] = $e;
uasort($this->data, create_function( '$a,$b', 'return $b["action_time"]-$a["action_time"];' ));
uasort($this->data, array(__CLASS__,"sortByActionTime"));
$count = count($this->data);
if($limit<3)
$limit = 500;
Expand Down
2 changes: 1 addition & 1 deletion plugins/mediainfo/action.php
Expand Up @@ -45,7 +45,7 @@ static public function load()
$st = mediainfoSettings::load();
$task = new rTask( array
(
'arg'=>call_user_func('getFileName',$filename),
'arg' => getFileName($filename),
'requester'=>'mediainfo',
'name'=>'mediainfo',
'hash'=>$_REQUEST['hash'],
Expand Down
12 changes: 10 additions & 2 deletions plugins/rss/rss.php
Expand Up @@ -645,9 +645,13 @@ public function add( $filter )
{
$this->lst[] = $filter;
}
protected static function sortByName( $a, $b )
{
return(strcmp($a->name, $b->name));
}
public function sort()
{
usort($this->lst, create_function( '$a,$b', 'return(strcmp($a->name, $b->name));'));
usort($this->lst, array(__CLASS__,"sortByName"));
}
public function getContents()
{
Expand Down Expand Up @@ -700,9 +704,13 @@ public function add( $grp )
{
$this->lst[$grp->hash] = $grp;
}
protected static function sortByName( $a, $b )
{
return(strcmp($a->name, $b->name));
}
public function sort()
{
uasort($this->lst, create_function( '$a,$b', 'return(strcmp($a->name, $b->name));'));
uasort($this->lst, array(__CLASS__,"sortByName"));
}
public function getContents()
{
Expand Down
6 changes: 5 additions & 1 deletion plugins/rssurlrewrite/rules.php
Expand Up @@ -87,6 +87,10 @@ public function add( $filter )
{
$this->lst[] = $filter;
}
protected static function sortByName( $a, $b )
{
return(strcmp($a->name, $b->name));
}
public function set()
{
if(!isset($HTTP_RAW_POST_DATA))
Expand Down Expand Up @@ -150,7 +154,7 @@ public function set()
}
if($rule)
$this->lst[] = $rule;
usort($this->lst, create_function( '$a,$b', 'return(strcmp($a->name, $b->name));'));
usort($this->lst, array(__CLASS__,"sortByName"));
$this->store();
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/rutracker_check/batch_check.php
Expand Up @@ -11,5 +11,5 @@
if(is_array($hashes))
foreach( $hashes as $hash )
ruTrackerChecker::run($hash);
unlink($argv[1]);
@unlink($argv[1]);
}
2 changes: 1 addition & 1 deletion plugins/screenshots/action.php
Expand Up @@ -52,7 +52,7 @@
}
$task = new rTask( array
(
'arg'=>call_user_func('getFileName',$filename),
'arg' => getFileName($filename),
'requester'=>'screenshots',
'name'=>'ffmpeg',
'hash'=>$_REQUEST['hash'],
Expand Down
2 changes: 1 addition & 1 deletion plugins/spectrogram/action.php
Expand Up @@ -43,7 +43,7 @@
}
$task = new rTask( array
(
'arg'=>call_user_func('end',explode('/',$filename)),
'arg' => getFileName($filename),
'requester'=>'spectrogram',
'name'=>'sox',
'hash'=>$_REQUEST['hash'],
Expand Down
6 changes: 3 additions & 3 deletions plugins/unpack/unpack.php
Expand Up @@ -335,7 +335,7 @@ public function startSilentTask($basename,$downloadname,$label,$name,$hash)
$commands[] = 'rm -r "${dir}"';
$task = new rTask( array
(
'arg'=>call_user_func('getFileName',delslash($basename)),
'arg' => getFileName(delslash($basename)),
'requester'=>'unpack',
'name'=>'unpack',
'hash'=>$hash,
Expand Down Expand Up @@ -401,7 +401,7 @@ public function startTask( $hash, $outPath, $mode, $fileno )
escapeshellarg($arh)." ".
escapeshellarg($filename)." ".
escapeshellarg(addslash($outPath));
$taskArgs['arg'] = call_user_func('getFileName',$filename);
$taskArgs['arg'] = getFileName($filename);
$task = new rTask( $taskArgs );
$ret = $task->start($commands, 0);
}
Expand Down Expand Up @@ -472,7 +472,7 @@ public function startTask( $hash, $outPath, $mode, $fileno )
escapeshellarg($basename)." ".
escapeshellarg($outPath)." ".
escapeshellarg($pathToUnzip);
$taskArgs['arg'] = call_user_func('getFileName',delslash($basename));
$taskArgs['arg'] = getFileName(delslash($basename));
$task = new rTask( $taskArgs );
$ret = $task->start($commands, 0);
}
Expand Down

0 comments on commit 161cba2

Please sign in to comment.