From dd7c2ad1784a91b03363acbabed66abe93e3414e Mon Sep 17 00:00:00 2001 From: DariusIII Date: Tue, 15 Apr 2014 23:48:50 +0200 Subject: [PATCH] Clean up, update phpdoc. --- bin/backfill.php | 58 +- bin/backfill_parts.php | 103 +- bin/backfill_parts_threaded.php | 90 +- bin/backfill_threaded.php | 115 +- bin/config.php | 4 +- bin/lib/db.php | 216 +- bin/nzb-import-sub.php | 45 +- bin/processSpotnab.php | 9 +- bin/requestID.php | 6 +- bin/safer_backfill_parts.php | 97 +- bin/sphinx.php | 8 +- bin/update_binaries.php | 90 +- bin/update_binaries_threaded.php | 120 +- bin/update_releases.php | 52 +- bin/update_releases_new.php | 54 +- lib/Net_SmartIRC/Net/SmartIRC/defines.php | 402 +- lib/Net_SmartIRC/Net/SmartIRC/irccommands.php | 32 +- lib/Net_SmartIRC/modules/PingFix.php | 52 +- .../www/lib/Net_NNTP/NNTP/Client.php | 368 +- .../www/lib/Net_NNTP/NNTP/Protocol/Client.php | 664 ++-- lib/copy_this/www/lib/Tmux.php | 10 +- lib/copy_this/www/lib/nntp.php | 33 +- .../www/templates/nntmux/scripts/utils.js | 1518 ++++---- .../nntmux/views/frontend/apiresult.tpl | 219 +- .../nntmux/views/frontend/profileedit.tpl | 290 +- .../nntmux/views/frontend/rssheader.tpl | 33 +- lib/dump_prehash.php | 25 +- lib/requestID.php | 246 +- lib/simple_html_dom.php | 3333 +++++++++-------- scripts/reset_rar_check.php | 6 +- scripts/reset_truncate.php | 20 +- scripts/truncate_tables.php | 7 +- 32 files changed, 4337 insertions(+), 3988 deletions(-) diff --git a/bin/backfill.php b/bin/backfill.php index 3c9c7f48c..b2e9586a2 100644 --- a/bin/backfill.php +++ b/bin/backfill.php @@ -1,47 +1,43 @@ backfillAllGroups($groupName); -function relativeTime($_time) { - $d[0] = array(1,"sec"); - $d[1] = array(60,"min"); - $d[2] = array(3600,"hr"); - $d[3] = array(86400,"day"); - $d[4] = array(31104000,"yr"); +function relativeTime($_time) +{ + $d[0] = array(1, "sec"); + $d[1] = array(60, "min"); + $d[2] = array(3600, "hr"); + $d[3] = array(86400, "day"); + $d[4] = array(31104000, "yr"); - $w = array(); + $w = array(); - $return = ""; - $now = TIME(); - $diff = ($now-$_time); - $secondsLeft = $diff; + $return = ""; + $now = TIME(); + $diff = ($now - $_time); + $secondsLeft = $diff; - for($i=4;$i>-1;$i--) - { - $w[$i] = intval($secondsLeft/$d[$i][0]); - $secondsLeft -= ($w[$i]*$d[$i][0]); - if($w[$i]!=0) - { - //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - $return.= $w[$i]. " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - } - } + for ($i = 4; $i > -1; $i--) { + $w[$i] = intval($secondsLeft / $d[$i][0]); + $secondsLeft -= ($w[$i] * $d[$i][0]); + if ($w[$i] != 0) { + //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; + $return .= $w[$i] . " " . $d[$i][1] . (($w[$i] > 1) ? 's' : '') . " "; + } + } - //$return .= ($diff>0)?"ago":"left"; - return $return; + //$return .= ($diff>0)?"ago":"left"; + return $return; } -echo "\n\033[1;33mStock backfill process completed in: " .relativeTime($time). "\n"; - -?> - +echo "\n\033[1;33mStock backfill process completed in: " . relativeTime($time) . "\n"; \ No newline at end of file diff --git a/bin/backfill_parts.php b/bin/backfill_parts.php index 4b58c7a76..64cac8808 100644 --- a/bin/backfill_parts.php +++ b/bin/backfill_parts.php @@ -1,13 +1,13 @@ Starting kevin123's backfill process for ".$groupName."<===\n\n"; +$groupPost = $_parts; +if (isset($argv[1])) { + $groupName = $argv[1]; + echo "\n\n===>Starting kevin123's backfill process for " . $groupName . "<===\n\n"; - $db = new DB; - $query = $db->queryOneRow(sprintf("select name from groups WHERE (first_record_postdate BETWEEN '${_date}' and now()) and (name = '$groupName')")) or die(mysql_error()); - if (isset($query)) - { - $backfill = new Backfill(); - $backfill->backfillPostAllGroups($groupName, $groupPost); - echo "\n===>Backfilling completed for ".$groupName."\n"; - } - else - { - echo "\nAlready have the target post, skipping the ".$groupName."\n"; - } - } - else - { - $groupName = ''; + $db = new DB; + $query = $db->queryOneRow(sprintf("select name from groups WHERE (first_record_postdate BETWEEN '${_date}' and now()) and (name = '$groupName')")) or die(mysql_error()); + if (isset($query)) { $backfill = new Backfill(); $backfill->backfillPostAllGroups($groupName, $groupPost); + echo "\n===>Backfilling completed for " . $groupName . "\n"; + } else { + echo "\nAlready have the target post, skipping the " . $groupName . "\n"; } - -function relativeTime($_time) { - $d[0] = array(1,"sec"); - $d[1] = array(60,"min"); - $d[2] = array(3600,"hr"); - $d[3] = array(86400,"day"); - $d[4] = array(31104000,"yr"); - - $w = array(); - - $return = ""; - $now = TIME(); - $diff = ($now-$_time); - $secondsLeft = $diff; - - for($i=4;$i>-1;$i--) - { - $w[$i] = intval($secondsLeft/$d[$i][0]); - $secondsLeft -= ($w[$i]*$d[$i][0]); - if($w[$i]!=0) - { - //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - $return.= $w[$i]. " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - } - } - - //$return .= ($diff>0)?"ago":"left"; - return $return; +} else { + $groupName = ''; + $backfill = new Backfill(); + $backfill->backfillPostAllGroups($groupName, $groupPost); } -echo "\nKevin123's backfill parts process completed in: " .relativeTime($time); +function relativeTime($_time) +{ + $d[0] = array(1, "sec"); + $d[1] = array(60, "min"); + $d[2] = array(3600, "hr"); + $d[3] = array(86400, "day"); + $d[4] = array(31104000, "yr"); -?> + $w = array(); + + $return = ""; + $now = TIME(); + $diff = ($now - $_time); + $secondsLeft = $diff; + + for ($i = 4; $i > -1; $i--) { + $w[$i] = intval($secondsLeft / $d[$i][0]); + $secondsLeft -= ($w[$i] * $d[$i][0]); + if ($w[$i] != 0) { + //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; + $return .= $w[$i] . " " . $d[$i][1] . (($w[$i] > 1) ? 's' : '') . " "; + } + } + + //$return .= ($diff>0)?"ago":"left"; + return $return; +} + +echo "\nKevin123's backfill parts process completed in: " . relativeTime($time); diff --git a/bin/backfill_parts_threaded.php b/bin/backfill_parts_threaded.php index b7c94538c..444e7c228 100644 --- a/bin/backfill_parts_threaded.php +++ b/bin/backfill_parts_threaded.php @@ -1,59 +1,51 @@ getActive(); unset($groups); -$ps = new PowerProcess(5,0,false); +$ps = new PowerProcess(5, 0, false); $ps->RegisterCallback('psUpdateComplete'); $ps->maxThreads = 5; -$ps->tickCount = 500000; // value in usecs. change this to 1000000 (one second) to reduce cpu use -$ps->threadTimeLimit = 0; // Disable child timeout +$ps->tickCount = 500000; // value in usecs. change this to 1000000 (one second) to reduce cpu use +$ps->threadTimeLimit = 0; // Disable child timeout echo "Starting kevin123's threaded backfill process\n\n"; -while ($ps->RunControlCode()) -{ +while ($ps->RunControlCode()) { // Start the parent loop - if (count($groupList)) - { + if (count($groupList)) { // We still have groups to process - if ($ps->SpawnReady()) - { + if ($ps->SpawnReady()) { // Spawn another thread $ps->threadData = array_pop($groupList); - echo "\n[Thread-MASTER] Spawning new thread. Still have " . count($groupList) ." group(s) to update after this\n"; + echo "\n[Thread-MASTER] Spawning new thread. Still have " . count($groupList) . " group(s) to update after this\n"; $ps->spawnThread(); - } - else - { + } else { // There are no more slots available to run //$ps->tick(); //echo "No threads avaialble.\n"; } - } - else - { + } else { // No more groups to process echo "\nNo more groups to process - Initiating shutdown\n"; $ps->Shutdown(); echo "\nShutdown complete\n"; - echo "\n\033[1;33m[Thread-MASTER] Kevin123's threaded backfill parts process completed in: " .relativeTime($time). "\n"; + echo "\n\033[1;33m[Thread-MASTER] Kevin123's threaded backfill parts process completed in: " . relativeTime($time) . "\n"; } } unset($groupList); -if ($ps->RunThreadCode()) -{ +if ($ps->RunThreadCode()) { $group = $ps->threadData; - $thread = sprintf("%05d",$ps->GetPID()); + $thread = sprintf("%05d", $ps->GetPID()); echo "\n[Thread-{$thread}] Begining backfill processing for group {$group['name']}\n"; @@ -68,33 +60,32 @@ if ($ps->RunThreadCode()) echo "\n[Thread-{$thread}] Completed update for group {$group['name']}\n"; } -function relativeTime($_time) { - $d[0] = array(1,"sec"); - $d[1] = array(60,"min"); - $d[2] = array(3600,"hr"); - $d[3] = array(86400,"day"); - $d[4] = array(31104000,"yr"); +function relativeTime($_time) +{ + $d[0] = array(1, "sec"); + $d[1] = array(60, "min"); + $d[2] = array(3600, "hr"); + $d[3] = array(86400, "day"); + $d[4] = array(31104000, "yr"); - $w = array(); + $w = array(); - $return = ""; - $now = TIME(); - $diff = ($now-$_time); - $secondsLeft = $diff; + $return = ""; + $now = TIME(); + $diff = ($now - $_time); + $secondsLeft = $diff; - for($i=4;$i>-1;$i--) - { - $w[$i] = intval($secondsLeft/$d[$i][0]); - $secondsLeft -= ($w[$i]*$d[$i][0]); - if($w[$i]!=0) - { - //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - $return.= $w[$i]. " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - } - } + for ($i = 4; $i > -1; $i--) { + $w[$i] = intval($secondsLeft / $d[$i][0]); + $secondsLeft -= ($w[$i] * $d[$i][0]); + if ($w[$i] != 0) { + //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; + $return .= $w[$i] . " " . $d[$i][1] . (($w[$i] > 1) ? 's' : '') . " "; + } + } - //$return .= ($diff>0)?"ago":"left"; - return $return; + //$return .= ($diff>0)?"ago":"left"; + return $return; } // Exit to call back to parent - Let know that child has completed @@ -103,9 +94,6 @@ exit(0); // Create callback function function psUpdateComplete() { - echo "\n\033[1;33mKevin123's threaded backfill parts process completed in: " .relativeTime($time). "\n"; + echo "\n\033[1;33mKevin123's threaded backfill parts process completed in: " . relativeTime($time) . "\n"; } - -?> - diff --git a/bin/backfill_threaded.php b/bin/backfill_threaded.php index e2df089ba..3aed74398 100644 --- a/bin/backfill_threaded.php +++ b/bin/backfill_threaded.php @@ -1,12 +1,12 @@ getActive(); @@ -16,75 +16,65 @@ $ps = new PowerProcess(); $ps->RegisterCallback('psUpdateComplete'); $ps->maxThreads = 5; $ps->tickCount = 500000; -$ps->threadTimeLimit = 0; // Disable child timeout +$ps->threadTimeLimit = 0; // Disable child timeout echo "Starting threaded backfill process\n"; -while ($ps->RunControlCode()) -{ +while ($ps->RunControlCode()) { // Start the parent loop - if (count($groupList)) - { + if (count($groupList)) { // We still have groups to process - if ($ps->SpawnReady()) - { + if ($ps->SpawnReady()) { // Spawn another thread $ps->threadData = array_pop($groupList); - echo "[Thread-MASTER] Spawning new thread. Still have " . count($groupList) ." group(s) to update after this\n"; + echo "[Thread-MASTER] Spawning new thread. Still have " . count($groupList) . " group(s) to update after this\n"; $ps->spawnThread(); - } - else - { + } else { // There are no more slots available to run //$ps->tick(); //echo ".\n"; } - } - else - { + } else { // No more groups to process echo "No more groups to process - Initiating shutdown\n"; $ps->Shutdown(); echo "Shutdown complete\n"; - echo "\n\033[1;33m[Thread-MASTER] Threaded stock backfill process completed in: " .relativeTime($time). "\n"; + echo "\n\033[1;33m[Thread-MASTER] Threaded stock backfill process completed in: " . relativeTime($time) . "\n"; } } unset($groupList); -if ($ps->RunThreadCode()) -{ +if ($ps->RunThreadCode()) { $group = $ps->threadData; - - $thread = sprintf("%05d",$ps->GetPID()); - + + $thread = sprintf("%05d", $ps->GetPID()); + echo "[Thread-{$thread}] Begining backfill processing for group {$group['name']}\n"; - + $param = $group['name']; - - $dir = WWW_DIR.'/../misc/update_scripts/'; + + $dir = WWW_DIR . '/../misc/update_scripts/'; $file = 'backfill.php'; - + //NewzDash $ndComm = new newzdashComms; $ndCommAllowed = false; - if ( $ndComm->init() ) + if ($ndComm->init()) $ndCommAllowed = true; - - if ( $ndCommAllowed ) - { + + if ($ndCommAllowed) { $args[] = null; $args[] = "backfill on " . $group['name']; $args[] = "started"; $ndComm->broadcast($args); } //End Newzdash - + $output = passthru("cd {$dir}/ && php {$file} {$param}"); - + //Newzdash - if ( $ndCommAllowed ) - { + if ($ndCommAllowed) { unset($args); $args[] = null; $args[] = "backfill on " . $group['name']; @@ -92,37 +82,36 @@ if ($ps->RunThreadCode()) $ndComm->broadcast($args); } //End Newzdash - + echo "[Thread-{$thread}] Completed update for group {$group['name']}\n"; } -function relativeTime($_time) { - $d[0] = array(1,"sec"); - $d[1] = array(60,"min"); - $d[2] = array(3600,"hr"); - $d[3] = array(86400,"day"); - $d[4] = array(31104000,"yr"); +function relativeTime($_time) +{ + $d[0] = array(1, "sec"); + $d[1] = array(60, "min"); + $d[2] = array(3600, "hr"); + $d[3] = array(86400, "day"); + $d[4] = array(31104000, "yr"); - $w = array(); + $w = array(); - $return = ""; - $now = TIME(); - $diff = ($now-$_time); - $secondsLeft = $diff; + $return = ""; + $now = TIME(); + $diff = ($now - $_time); + $secondsLeft = $diff; - for($i=4;$i>-1;$i--) - { - $w[$i] = intval($secondsLeft/$d[$i][0]); - $secondsLeft -= ($w[$i]*$d[$i][0]); - if($w[$i]!=0) - { - //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - $return.= $w[$i]. " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - } - } + for ($i = 4; $i > -1; $i--) { + $w[$i] = intval($secondsLeft / $d[$i][0]); + $secondsLeft -= ($w[$i] * $d[$i][0]); + if ($w[$i] != 0) { + //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; + $return .= $w[$i] . " " . $d[$i][1] . (($w[$i] > 1) ? 's' : '') . " "; + } + } - //$return .= ($diff>0)?"ago":"left"; - return $return; + //$return .= ($diff>0)?"ago":"left"; + return $return; } // Exit to call back to parent - Let know that child has completed @@ -131,7 +120,5 @@ exit(0); // Create callback function function psUpdateComplete() { - echo "\n\033[1;33mThreaded stock backfill process completed in: " .relativeTime($time). "\n"; + echo "\n\033[1;33mThreaded stock backfill process completed in: " . relativeTime($time) . "\n"; } - -?> diff --git a/bin/config.php b/bin/config.php index 105a8ebf0..260d0c5ec 100644 --- a/bin/config.php +++ b/bin/config.php @@ -1,6 +1,4 @@ +require(dirname(__FILE__) . "/../../../../../www/config.php"); diff --git a/bin/lib/db.php b/bin/lib/db.php index b7e78d146..fea4df5d0 100644 --- a/bin/lib/db.php +++ b/bin/lib/db.php @@ -6,192 +6,194 @@ class DB function DB() { - if (DB::$initialized === false) - { + if (DB::$initialized === false) { // initialize db connection mysql_pconnect(DB_HOST, DB_USER, DB_PASSWORD) or die("fatal error: could not connect to database! Check your config."); - + mysql_select_db(DB_NAME) or die("fatal error: could not select database! Check your config."); - + mysql_set_charset('utf8'); DB::$initialized = true; } - $this->mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); - if (mysqli_connect_errno()) { - printf("Connect failed: %s\n", mysqli_connect_error()); - exit(); - } - } - + $this->mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); + if (mysqli_connect_errno()) { + printf("Connect failed: %s\n", mysqli_connect_error()); + exit(); + } + } + public function escapeString($str) { - return "'".mysql_real_escape_string($str)."'"; - } + return "'" . mysql_real_escape_string($str) . "'"; + } public function makeLookupTable($rows, $keycol) { $arr = array(); - foreach($rows as $row) - $arr[$row[$keycol]] = $row; + foreach ($rows as $row) + $arr[$row[$keycol]] = $row; + return $arr; - } - - public function queryInsert($query, $returnlastid=true) + } + + public function queryInsert($query, $returnlastid = true) { $result = mysql_query($query); + return ($returnlastid) ? mysql_insert_id() : $result; } - + public function queryOneRow($query) { $rows = $this->query($query); - + if (!$rows) return false; - + if ($rows) return $rows[0]; else - return $rows; - } - + return $rows; + } + public function query($query) { $result = mysql_query($query); - + if ($result === false || $result === true) return array(); - + $rows = array(); - while ($row = mysql_fetch_assoc($result)) - $rows[] = $row; - + while ($row = mysql_fetch_assoc($result)) + $rows[] = $row; + mysql_free_result($result); + return $rows; - } - + } + public function queryDirect($query) { $result = mysql_query($query); + return $result; - } + } - public function optimize($force = false) + public function optimize($force = false) { $ret = array(); if ($force) - $alltables = $this->query("show table status where `Engine` = 'MyISAM'"); + $alltables = $this->query("show table status where `Engine` = 'MyISAM'"); else - $alltables = $this->query("show table status where `Engine` = 'MyISAM' and Data_free != 0"); + $alltables = $this->query("show table status where `Engine` = 'MyISAM' and Data_free != 0"); - foreach ($alltables as $tablename) - { + foreach ($alltables as $tablename) { $ret[] = $tablename['Name']; - $this->queryDirect("REPAIR TABLE `".$tablename['Name']."`"); - $this->queryDirect("OPTIMIZE TABLE `".$tablename['Name']."`"); - $this->queryDirect("ANALYZE TABLE `".$tablename['Name']."`"); + $this->queryDirect("REPAIR TABLE `" . $tablename['Name'] . "`"); + $this->queryDirect("OPTIMIZE TABLE `" . $tablename['Name'] . "`"); + $this->queryDirect("ANALYZE TABLE `" . $tablename['Name'] . "`"); } - + return $ret; } - public function optimizeinnodb($iforce = false) + public function optimizeinnodb($iforce = false) { $iret = array(); if ($iforce) - $ialltables = $this->query("show table status where `Engine` = 'InnoDB'"); + $ialltables = $this->query("show table status where `Engine` = 'InnoDB'"); else - $ialltables = $this->query("show table status where `Engine` = 'InnoDB' and Data_free != 0"); + $ialltables = $this->query("show table status where `Engine` = 'InnoDB' and Data_free != 0"); - foreach ($ialltables as $itablename) - { + foreach ($ialltables as $itablename) { $iret[] = $itablename['Name']; - $this->queryDirect("OPTIMIZE TABLE `".$itablename['Name']."`"); + $this->queryDirect("OPTIMIZE TABLE `" . $itablename['Name'] . "`"); } - + return $iret; } - /* Mysqli Functions */ - public function multiQueryTransaction($query) - { - $this->mysqli->autocommit(FALSE); - $this->mysqli->multi_query($query); + /* Mysqli Functions */ + public function multiQueryTransaction($query) + { + $this->mysqli->autocommit(false); + $this->mysqli->multi_query($query); - while($this->mysqli->next_result()) { - $result = $this->mysqli->use_result(); - if($result instanceof mysqli_result) - $result->free(); - } + while ($this->mysqli->next_result()) { + $result = $this->mysqli->use_result(); + if ($result instanceof mysqli_result) + $result->free(); + } - $this->mysqli->commit(); - } + $this->mysqli->commit(); + } - public function disableAutoCommit() - { - $this->mysqli->autocommit(FALSE); - } + public function disableAutoCommit() + { + $this->mysqli->autocommit(false); + } - public function mysqliQuery($sql) - { - $result = $this->mysqli->query($sql); - if ($result === false || $result === true) - return array(); + public function mysqliQuery($sql) + { + $result = $this->mysqli->query($sql); + if ($result === false || $result === true) + return array(); - $rows = array(); + $rows = array(); - while ($row = mysqli_fetch_assoc($result)) - $rows[] = $row; + while ($row = mysqli_fetch_assoc($result)) + $rows[] = $row; - mysqli_free_result($result); - return $rows; - } + mysqli_free_result($result); - public function mysqliQueryOneRow($query) - { - $rows = $this->mysqliQuery($query); + return $rows; + } - if (!$rows) - return false; + public function mysqliQueryOneRow($query) + { + $rows = $this->mysqliQuery($query); - if ($rows) - return $rows[0]; - else - return $rows; - } + if (!$rows) + return false; - public function mysqliQueryInsert($query, $returnlastid=true) - { - $result = $this->mysqli->query($query); - return ($returnlastid) ? $this->mysqli->insert_id : $result; - } + if ($rows) + return $rows[0]; + else + return $rows; + } - public function commit() - { - $this->mysqli->commit(); - } + public function mysqliQueryInsert($query, $returnlastid = true) + { + $result = $this->mysqli->query($query); - public function rollback() - { - $this->mysqli->rollback(); - } + return ($returnlastid) ? $this->mysqli->insert_id : $result; + } - public function mysqliQueryDirect($query) - { - return $this->mysqli->query($query); - } + public function commit() + { + $this->mysqli->commit(); + } + + public function rollback() + { + $this->mysqli->rollback(); + } + + public function mysqliQueryDirect($query) + { + return $this->mysqli->query($query); + } - public function enableAutoCommit() - { - $this->mysqli->autocommit(TRUE); - } + public function enableAutoCommit() + { + $this->mysqli->autocommit(true); + } } -?> diff --git a/bin/nzb-import-sub.php b/bin/nzb-import-sub.php index 70b05527f..a25f72588 100644 --- a/bin/nzb-import-sub.php +++ b/bin/nzb-import-sub.php @@ -1,27 +1,27 @@ 0){ - //echo "Directory {$subdir} contains {$filecount} nzb's.\n"; - $subdir_count++; + //echo "Directory {$subdir} contains {$filecount} nzb's.\n"; + $subdir_count++; //} } -if($subdir_count == 0){ +if ($subdir_count == 0) { echo "Nothing to import, sub-directories are empty or there are no sub-directories to process.\n"; die(); } //get variables from defaults.sh $path = dirname(__FILE__); -$varnames = shell_exec("cat ".$path."/../defaults.sh | grep ^export | cut -d \= -f1 | awk '{print $2;}'"); -$vardata = shell_exec("cat ".$path."/../defaults.sh | grep ^export | cut -d \\\" -f2 | awk '{print $1;}'"); +$varnames = shell_exec("cat " . $path . "/../defaults.sh | grep ^export | cut -d \= -f1 | awk '{print $2;}'"); +$vardata = shell_exec("cat " . $path . "/../defaults.sh | grep ^export | cut -d \\\" -f2 | awk '{print $1;}'"); $varnames = explode("\n", $varnames); $vardata = explode("\n", $vardata); $array = array_combine($varnames, $vardata); @@ -36,27 +36,21 @@ $selected = $subdir_count - 1; echo "Starting threaded import process, {$array['NZBCOUNT']} per thread\n"; -while ($ps->RunControlCode()) -{ - if ($selected >= 0) - { - if ($ps->SpawnReady()) - { - $ps->threadData = $subdirs[$selected]."/"; +while ($ps->RunControlCode()) { + if ($selected >= 0) { + if ($ps->SpawnReady()) { + $ps->threadData = $subdirs[$selected] . "/"; $ps->spawnThread(); - } - } - else - { + } + } else { $ps->Shutdown(); } -$selected--; + $selected--; } -if ($ps->RunThreadCode()) -{ +if ($ps->RunThreadCode()) { $subdir = $ps->threadData; - $thread = sprintf("%05d",$ps->GetPID()); + $thread = sprintf("%05d", $ps->GetPID()); $dir = dirname(__FILE__); $file = 'nzb-importonenzb.php'; @@ -72,6 +66,3 @@ function psUpdateComplete() echo "[Thread-MASTER] The threaded import process has completed.\n"; } -?> - - diff --git a/bin/processSpotnab.php b/bin/processSpotnab.php index 8d7fb9a9a..62729b9e5 100644 --- a/bin/processSpotnab.php +++ b/bin/processSpotnab.php @@ -1,18 +1,17 @@ processSpotnab(); //get variables from defaults.sh $path = dirname(__FILE__); -$varnames = shell_exec("cat ".$path."/../defaults.sh | grep ^export | cut -d \= -f1 | awk '{print $2;}'"); -$vardata = shell_exec("cat ".$path."/../defaults.sh | grep ^export | cut -d \\\" -f2 | awk '{print $1;}'"); +$varnames = shell_exec("cat " . $path . "/../defaults.sh | grep ^export | cut -d \= -f1 | awk '{print $2;}'"); +$vardata = shell_exec("cat " . $path . "/../defaults.sh | grep ^export | cut -d \\\" -f2 | awk '{print $1;}'"); $varnames = explode("\n", $varnames); $vardata = explode("\n", $vardata); $array = array_combine($varnames, $vardata); unset($array['']); -?> diff --git a/bin/requestID.php b/bin/requestID.php index 0e31dbb67..29effbfd1 100644 --- a/bin/requestID.php +++ b/bin/requestID.php @@ -103,6 +103,8 @@ function getReleaseNameFromRequestID($tmux, $requestID, $groupName) if (isset($request)) { return array('title' => $request['name'], 'ID' => 'NULL'); } + + return true; } function localLookup($requestID, $groupName, $oldname) @@ -133,4 +135,6 @@ function localLookup($requestID, $groupName, $oldname) if (isset($run1['title'])) { return array('title' => $run['title'], 'ID' => $run['ID']); } -} + + return true; +} \ No newline at end of file diff --git a/bin/safer_backfill_parts.php b/bin/safer_backfill_parts.php index 4e2e3a1df..c0bcb3351 100644 --- a/bin/safer_backfill_parts.php +++ b/bin/safer_backfill_parts.php @@ -2,64 +2,64 @@ /* This scripts backfills 100k parts, on ONE group from your active groups, reverse alphabetically, to a maximum of 2012-06-24. When that group is at 2012-06-24 it will move on to the next group. */ -require(dirname(__FILE__)."/config.php"); -require_once(WWW_DIR."/lib/backfill.php"); -require_once(WWW_DIR."/lib/framework/db.php"); +require(dirname(__FILE__) . "/config.php"); +require_once(WWW_DIR . "/lib/backfill.php"); +require_once(WWW_DIR . "/lib/framework/db.php"); $time = TIME(); //get variables from defaults.sh $path = dirname(__FILE__); -$varnames = shell_exec("cat ".$path."/../defaults.sh | grep ^export | cut -d \= -f1 | awk '{print $2;}'"); -$vardata = shell_exec("cat ".$path."/../defaults.sh | grep ^export | cut -d \\\" -f2 | awk '{print $1;}'"); +$varnames = shell_exec("cat " . $path . "/../defaults.sh | grep ^export | cut -d \= -f1 | awk '{print $2;}'"); +$vardata = shell_exec("cat " . $path . "/../defaults.sh | grep ^export | cut -d \\\" -f2 | awk '{print $1;}'"); $varnames = explode("\n", $varnames); $vardata = explode("\n", $vardata); $array = array_combine($varnames, $vardata); unset($array['']); -function relativeTime($_time) { - $d[0] = array(1,"sec"); - $d[1] = array(60,"min"); - $d[2] = array(3600,"hr"); - $d[3] = array(86400,"day"); - $d[4] = array(31104000,"yr"); +function relativeTime($_time) +{ + $d[0] = array(1, "sec"); + $d[1] = array(60, "min"); + $d[2] = array(3600, "hr"); + $d[3] = array(86400, "day"); + $d[4] = array(31104000, "yr"); - $w = array(); + $w = array(); - $return = ""; - $now = TIME(); - $diff = ($now-$_time); - $secondsLeft = $diff; + $return = ""; + $now = TIME(); + $diff = ($now - $_time); + $secondsLeft = $diff; - for($i=4;$i>-1;$i--) - { - $w[$i] = intval($secondsLeft/$d[$i][0]); - $secondsLeft -= ($w[$i]*$d[$i][0]); - if($w[$i]!=0) - { - //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - $return.= $w[$i]. " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - } - } + for ($i = 4; $i > -1; $i--) { + $w[$i] = intval($secondsLeft / $d[$i][0]); + $secondsLeft -= ($w[$i] * $d[$i][0]); + if ($w[$i] != 0) { + //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; + $return .= $w[$i] . " " . $d[$i][1] . (($w[$i] > 1) ? 's' : '') . " "; + } + } - //$return .= ($diff>0)?"ago":"left"; - return $return; + //$return .= ($diff>0)?"ago":"left"; + return $return; } function get_color() { - $from = 1; - $to = 231; - $exceptions = array( 4, 8, 16, 17, 18, 19, 52, 53, 59, 60, 67 ); - sort($exceptions); // lets us use break; in the foreach reliably - $number = mt_rand($from, $to - count($exceptions)); // or mt_rand() - foreach ($exceptions as $exception) { - if ($number >= $exception) { - $number++; // make up for the gap - } else /*if ($number < $exception)*/ { - break; - } - } - return $number; + $from = 1; + $to = 231; + $exceptions = array(4, 8, 16, 17, 18, 19, 52, 53, 59, 60, 67); + sort($exceptions); // lets us use break; in the foreach reliably + $number = mt_rand($from, $to - count($exceptions)); // or mt_rand() + foreach ($exceptions as $exception) { + if ($number >= $exception) { + $number++; // make up for the gap + } else /*if ($number < $exception)*/ { + break; + } + } + + return $number; } $_date = $array['KEVIN_DATE']; @@ -73,24 +73,21 @@ $query1 = $db->queryOneRow("select name from groups WHERE (first_record_postdate $query2 = $db->queryOneRow("select first_record_postdate from groups WHERE (first_record_postdate BETWEEN '$_date' and now()) and (active = 1) order by name ASC limit 1"); $groups = $db->query("select name from groups WHERE (first_record_postdate NOT BETWEEN '$_date' and now()) and (active = 1) order by name ASC"); -foreach($groups as $row) - { - $tbl = $row['name']; - echo "\033[1;33m$tbl Completed\n\033[0m"; - } +foreach ($groups as $row) { + $tbl = $row['name']; + echo "\033[1;33m$tbl Completed\n\033[0m"; +} $groupPost = $_parts; $groupName = $query1['name']; $groupDate = $query2['first_record_postdate']; -if($query1){ +if ($query1) { echo "\n\033[1;33mStarting kevin123's safer backfill process on $groupName ==> $_date ==> $groupDate\n\033[38;5;${color}m\n\n"; sleep(3); $backfill = new Backfill(); $backfill->backfillPostAllGroups($groupName, $groupPost); } -echo "\n\033[1;33mKevin123's safer backfill process completed in: " .relativeTime($time). "\n\033[0m\n"; - -?> +echo "\n\033[1;33mKevin123's safer backfill process completed in: " . relativeTime($time) . "\n\033[0m\n"; diff --git a/bin/sphinx.php b/bin/sphinx.php index 0a28bd029..711d8c0a8 100644 --- a/bin/sphinx.php +++ b/bin/sphinx.php @@ -1,13 +1,11 @@ processReleases(); $sphinx->update(); -?> - diff --git a/bin/update_binaries.php b/bin/update_binaries.php index ef90cb9d4..8b1d6016e 100644 --- a/bin/update_binaries.php +++ b/bin/update_binaries.php @@ -1,59 +1,53 @@ header("Updating group {$group}"); + + $g = new Groups; + $group = $g->getByName($group); + + $bin = new Binaries; + $bin->updateGroup(null, $group); +} else { + $binaries = new Binaries; + $binaries->updateAllGroups(); +} + +function relativeTime($_time) { - $group = $argv[1]; - echo $c->header("Updating group {$group}"); + $d[0] = array(1, "sec"); + $d[1] = array(60, "min"); + $d[2] = array(3600, "hr"); + $d[3] = array(86400, "day"); + $d[4] = array(31104000, "yr"); - $g = new Groups; - $group = $g->getByName($group); + $w = array(); - $bin = new Binaries; - $bin->updateGroup(null, $group); -} -else -{ - $binaries = new Binaries; - $binaries->updateAllGroups(); + $return = ""; + $now = TIME(); + $diff = ($now - $_time); + $secondsLeft = $diff; + + for ($i = 4; $i > -1; $i--) { + $w[$i] = intval($secondsLeft / $d[$i][0]); + $secondsLeft -= ($w[$i] * $d[$i][0]); + if ($w[$i] != 0) { + //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; + $return .= $w[$i] . " " . $d[$i][1] . (($w[$i] > 1) ? 's' : '') . " "; + } + } + + //$return .= ($diff>0)?"ago":"left"; + return $return; } -function relativeTime($_time) { - $d[0] = array(1,"sec"); - $d[1] = array(60,"min"); - $d[2] = array(3600,"hr"); - $d[3] = array(86400,"day"); - $d[4] = array(31104000,"yr"); - - $w = array(); - - $return = ""; - $now = TIME(); - $diff = ($now-$_time); - $secondsLeft = $diff; - - for($i=4;$i>-1;$i--) - { - $w[$i] = intval($secondsLeft/$d[$i][0]); - $secondsLeft -= ($w[$i]*$d[$i][0]); - if($w[$i]!=0) - { - //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - $return.= $w[$i]. " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - } - } - - //$return .= ($diff>0)?"ago":"left"; - return $return; -} - -echo $c->header("Group update process completed in: " .relativeTime($time). "\n"); - -?> +echo $c->header("Group update process completed in: " . relativeTime($time) . "\n"); diff --git a/bin/update_binaries_threaded.php b/bin/update_binaries_threaded.php index 0b2543aa3..1824424c8 100644 --- a/bin/update_binaries_threaded.php +++ b/bin/update_binaries_threaded.php @@ -1,12 +1,12 @@ getActive(); @@ -16,81 +16,71 @@ $ps = new PowerProcess(); $ps->RegisterCallback('psUpdateComplete'); $ps->maxThreads = 5; $ps->tickCount = 500000; -$ps->threadTimeLimit = 0; // Disable child timeout +$ps->threadTimeLimit = 0; // Disable child timeout echo "Starting threaded binary update process\n"; -//while ($ps->runParentCode()) -while ($ps->RunControlCode()) -{ +//while ($ps->runParentCode()) +while ($ps->RunControlCode()) { // Start the parent loop - if (count($groupList)) - { + if (count($groupList)) { // We still have groups to process - if ($ps->SpawnReady()) - { + if ($ps->SpawnReady()) { // Spawn another thread $ps->threadData = array_pop($groupList); - - echo "[Thread-MASTER] Spawning new thread. Still have " . count($groupList) ." group(s) to update after this\n"; + + echo "[Thread-MASTER] Spawning new thread. Still have " . count($groupList) . " group(s) to update after this\n"; $ps->spawnThread(); - } - else - { + } else { // There are no more slots available to run //$ps->tick(); //echo "- \n"; } - } - else - { + } else { // No more groups to process echo "No more groups to process - Initiating shutdown\n"; $ps->Shutdown(); echo "Shutdown complete\n"; - echo "\n\033[1;33m[Thread-MASTER] Threaded stock binaries update completed in: " .relativeTime($time). "\n"; + echo "\n\033[1;33m[Thread-MASTER] Threaded stock binaries update completed in: " . relativeTime($time) . "\n"; } } unset($groupList); -if ($ps->RunThreadCode()) -{ +if ($ps->RunThreadCode()) { $group = $ps->threadData; - - $thread = sprintf("%05d",$ps->GetPID()); - + + $thread = sprintf("%05d", $ps->GetPID()); + echo "[Thread-{$thread}] Begining processing for group {$group['name']}\n"; - + //NewzDash $ndComm = new newzdashComms; $ndCommAllowed = false; - if ( $ndComm->init() ) + if ($ndComm->init()) $ndCommAllowed = true; - - if ( $ndCommAllowed ) - { + + if ($ndCommAllowed) { $args[] = null; $args[] = "update_binaries on " . $group['name']; $args[] = "started"; $ndComm->broadcast($args); } //End Newzdash - + $param = $group['name']; - - $dir = WWW_DIR.'/../misc/update_scripts/'; + + $dir = WWW_DIR . '/../misc/update_scripts/'; $file = 'update_binaries.php'; - + //$output = shell_exec("php {$dir}/{$file} {$param}"); $output = passthru("cd {$dir}/ && php {$file} {$param}"); //$output = shell_exec("/usr/bin/php -c /etc/php5/cli/php.ini {$dir}/{$file} {$param}"); - + echo "[Thread-{$thread}] Completed update for group {$group['name']}\n"; - + //Newzdash - if ( $ndCommAllowed ) - { + if ($ndCommAllowed) { unset($args); $args[] = null; $args[] = "update_binaries on " . $group['name']; @@ -100,33 +90,32 @@ if ($ps->RunThreadCode()) //End Newzdash } -function relativeTime($_time) { - $d[0] = array(1,"sec"); - $d[1] = array(60,"min"); - $d[2] = array(3600,"hr"); - $d[3] = array(86400,"day"); - $d[4] = array(31104000,"yr"); +function relativeTime($_time) +{ + $d[0] = array(1, "sec"); + $d[1] = array(60, "min"); + $d[2] = array(3600, "hr"); + $d[3] = array(86400, "day"); + $d[4] = array(31104000, "yr"); - $w = array(); + $w = array(); - $return = ""; - $now = TIME(); - $diff = ($now-$_time); - $secondsLeft = $diff; + $return = ""; + $now = TIME(); + $diff = ($now - $_time); + $secondsLeft = $diff; - for($i=4;$i>-1;$i--) - { - $w[$i] = intval($secondsLeft/$d[$i][0]); - $secondsLeft -= ($w[$i]*$d[$i][0]); - if($w[$i]!=0) - { - //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - $return.= $w[$i]. " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - } - } + for ($i = 4; $i > -1; $i--) { + $w[$i] = intval($secondsLeft / $d[$i][0]); + $secondsLeft -= ($w[$i] * $d[$i][0]); + if ($w[$i] != 0) { + //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; + $return .= $w[$i] . " " . $d[$i][1] . (($w[$i] > 1) ? 's' : '') . " "; + } + } - //$return .= ($diff>0)?"ago":"left"; - return $return; + //$return .= ($diff>0)?"ago":"left"; + return $return; } // Exit to call back to parent - Let know that child has completed @@ -135,8 +124,5 @@ exit(0); // Create callback function function psUpdateComplete() { - echo "Threaded stock binaries update completed in: " .relativeTime($time). "\n"; + echo "Threaded stock binaries update completed in: " . relativeTime($time) . "\n"; } - - -?> diff --git a/bin/update_releases.php b/bin/update_releases.php index 38ba3665b..680c78563 100644 --- a/bin/update_releases.php +++ b/bin/update_releases.php @@ -1,7 +1,7 @@ processReleases(); //$sphinx->update(); -function relativeTime($_time) { - $d[0] = array(1,"\033[1;33msec"); - $d[1] = array(60,"\033[1;33mmin"); - $d[2] = array(3600,"\033[1;33mhr"); - $d[3] = array(86400,"\033[1;33mday"); - $d[4] = array(31104000,"\033[1;33myr"); +function relativeTime($_time) +{ + $d[0] = array(1, "\033[1;33msec"); + $d[1] = array(60, "\033[1;33mmin"); + $d[2] = array(3600, "\033[1;33mhr"); + $d[3] = array(86400, "\033[1;33mday"); + $d[4] = array(31104000, "\033[1;33myr"); - $w = array(); + $w = array(); - $return = ""; - $now = TIME(); - $diff = ($now-$_time); - $secondsLeft = $diff; + $return = ""; + $now = TIME(); + $diff = ($now - $_time); + $secondsLeft = $diff; - for($i=4;$i>-1;$i--) - { - $w[$i] = intval($secondsLeft/$d[$i][0]); - $secondsLeft -= ($w[$i]*$d[$i][0]); - if($w[$i]!=0) - { - //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - $return.= $w[$i]. " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - } - } + for ($i = 4; $i > -1; $i--) { + $w[$i] = intval($secondsLeft / $d[$i][0]); + $secondsLeft -= ($w[$i] * $d[$i][0]); + if ($w[$i] != 0) { + //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; + $return .= $w[$i] . " " . $d[$i][1] . (($w[$i] > 1) ? 's' : '') . " "; + } + } - //$return .= ($diff>0)?"ago":"left"; - return $return; + //$return .= ($diff>0)?"ago":"left"; + return $return; } -echo "\033[1;33mThis loop completed in: " .relativeTime($time). "\n"; -?> +echo "\033[1;33mThis loop completed in: " . relativeTime($time) . "\n"; diff --git a/bin/update_releases_new.php b/bin/update_releases_new.php index 0ece3d46f..600f5b93d 100644 --- a/bin/update_releases_new.php +++ b/bin/update_releases_new.php @@ -1,9 +1,9 @@ processReleases(); //$sphinx->update(); -function relativeTime($_time) { - $d[0] = array(1,"\033[1;33msec"); - $d[1] = array(60,"\033[1;33mmin"); - $d[2] = array(3600,"\033[1;33mhr"); - $d[3] = array(86400,"\033[1;33mday"); - $d[4] = array(31104000,"\033[1;33myr"); +function relativeTime($_time) +{ + $d[0] = array(1, "\033[1;33msec"); + $d[1] = array(60, "\033[1;33mmin"); + $d[2] = array(3600, "\033[1;33mhr"); + $d[3] = array(86400, "\033[1;33mday"); + $d[4] = array(31104000, "\033[1;33myr"); - $w = array(); + $w = array(); - $return = ""; - $now = TIME(); - $diff = ($now-$_time); - $secondsLeft = $diff; + $return = ""; + $now = TIME(); + $diff = ($now - $_time); + $secondsLeft = $diff; - for($i=4;$i>-1;$i--) - { - $w[$i] = intval($secondsLeft/$d[$i][0]); - $secondsLeft -= ($w[$i]*$d[$i][0]); - if($w[$i]!=0) - { - //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - $return.= $w[$i]. " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; - } - } + for ($i = 4; $i > -1; $i--) { + $w[$i] = intval($secondsLeft / $d[$i][0]); + $secondsLeft -= ($w[$i] * $d[$i][0]); + if ($w[$i] != 0) { + //$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." "; + $return .= $w[$i] . " " . $d[$i][1] . (($w[$i] > 1) ? 's' : '') . " "; + } + } - //$return .= ($diff>0)?"ago":"left"; - return $return; + //$return .= ($diff>0)?"ago":"left"; + return $return; } -echo "\033[1;33mThis loop completed in: " .relativeTime($time). "\n"; -?> +echo "\033[1;33mThis loop completed in: " . relativeTime($time) . "\n"; \ No newline at end of file diff --git a/lib/Net_SmartIRC/Net/SmartIRC/defines.php b/lib/Net_SmartIRC/Net/SmartIRC/defines.php index 87f46dc95..a78a50019 100644 --- a/lib/Net_SmartIRC/Net/SmartIRC/defines.php +++ b/lib/Net_SmartIRC/Net/SmartIRC/defines.php @@ -25,213 +25,211 @@ */ // don't change this! unless you know what you do -define('SMARTIRC_CRLF', "\r\n"); -define('SMARTIRC_UNUSED', '*'); -define('SMARTIRC_STDOUT', 0); -define('SMARTIRC_FILE', 1); -define('SMARTIRC_SYSLOG', 2); -define('SMARTIRC_BROWSEROUT', 3); -define('SMARTIRC_NONE', 4); -define('SMARTIRC_LOW', 0); -define('SMARTIRC_MEDIUM', 1); -define('SMARTIRC_HIGH', 2); -define('SMARTIRC_CRITICAL', 3); -define('SMARTIRC_STATE_DISCONNECTED', 0); -define('SMARTIRC_STATE_CONNECTING', 1); -define('SMARTIRC_STATE_CONNECTED', 2); -define('SMARTIRC_DEBUG_NONE', 0); -define('SMARTIRC_DEBUG_NOTICE', 1); -define('SMARTIRC_DEBUG_CONNECTION', 2); -define('SMARTIRC_DEBUG_SOCKET', 4); -define('SMARTIRC_DEBUG_IRCMESSAGES', 8); -define('SMARTIRC_DEBUG_MESSAGETYPES', 16); -define('SMARTIRC_DEBUG_ACTIONHANDLER', 32); -define('SMARTIRC_DEBUG_TIMEHANDLER', 64); -define('SMARTIRC_DEBUG_MESSAGEHANDLER', 128); -define('SMARTIRC_DEBUG_CHANNELSYNCING', 256); -define('SMARTIRC_DEBUG_MODULES', 512); -define('SMARTIRC_DEBUG_USERSYNCING', 1024); -define('SMARTIRC_DEBUG_MESSAGEPARSER', 2048); -define('SMARTIRC_DEBUG_DCC', 4096); -define('SMARTIRC_DEBUG_ALL', 8191); -define('SMARTIRC_TYPE_UNKNOWN', 1); -define('SMARTIRC_TYPE_CHANNEL', 2); -define('SMARTIRC_TYPE_QUERY', 4); -define('SMARTIRC_TYPE_CTCP', 8); -define('SMARTIRC_TYPE_NOTICE', 16); -define('SMARTIRC_TYPE_WHO', 32); -define('SMARTIRC_TYPE_JOIN', 64); -define('SMARTIRC_TYPE_INVITE', 128); -define('SMARTIRC_TYPE_ACTION', 256); -define('SMARTIRC_TYPE_TOPICCHANGE', 512); -define('SMARTIRC_TYPE_NICKCHANGE', 1024); -define('SMARTIRC_TYPE_KICK', 2048); -define('SMARTIRC_TYPE_QUIT', 4096); -define('SMARTIRC_TYPE_LOGIN', 8192); -define('SMARTIRC_TYPE_INFO', 16384); -define('SMARTIRC_TYPE_LIST', 32768); -define('SMARTIRC_TYPE_NAME', 65536); -define('SMARTIRC_TYPE_MOTD', 131072); -define('SMARTIRC_TYPE_MODECHANGE', 262144); -define('SMARTIRC_TYPE_PART', 524288); -define('SMARTIRC_TYPE_ERROR', 1048576); -define('SMARTIRC_TYPE_BANLIST', 2097152); -define('SMARTIRC_TYPE_TOPIC', 4194304); -define('SMARTIRC_TYPE_NONRELEVANT', 8388608); -define('SMARTIRC_TYPE_WHOIS', 16777216); -define('SMARTIRC_TYPE_WHOWAS', 33554432); -define('SMARTIRC_TYPE_USERMODE', 67108864); -define('SMARTIRC_TYPE_CHANNELMODE', 134217728); -define('SMARTIRC_TYPE_CTCP_REQUEST', 268435456); -define('SMARTIRC_TYPE_CTCP_REPLY', 536870912); +define('SMARTIRC_CRLF', "\r\n"); +define('SMARTIRC_UNUSED', '*'); +define('SMARTIRC_STDOUT', 0); +define('SMARTIRC_FILE', 1); +define('SMARTIRC_SYSLOG', 2); +define('SMARTIRC_BROWSEROUT', 3); +define('SMARTIRC_NONE', 4); +define('SMARTIRC_LOW', 0); +define('SMARTIRC_MEDIUM', 1); +define('SMARTIRC_HIGH', 2); +define('SMARTIRC_CRITICAL', 3); +define('SMARTIRC_STATE_DISCONNECTED', 0); +define('SMARTIRC_STATE_CONNECTING', 1); +define('SMARTIRC_STATE_CONNECTED', 2); +define('SMARTIRC_DEBUG_NONE', 0); +define('SMARTIRC_DEBUG_NOTICE', 1); +define('SMARTIRC_DEBUG_CONNECTION', 2); +define('SMARTIRC_DEBUG_SOCKET', 4); +define('SMARTIRC_DEBUG_IRCMESSAGES', 8); +define('SMARTIRC_DEBUG_MESSAGETYPES', 16); +define('SMARTIRC_DEBUG_ACTIONHANDLER', 32); +define('SMARTIRC_DEBUG_TIMEHANDLER', 64); +define('SMARTIRC_DEBUG_MESSAGEHANDLER', 128); +define('SMARTIRC_DEBUG_CHANNELSYNCING', 256); +define('SMARTIRC_DEBUG_MODULES', 512); +define('SMARTIRC_DEBUG_USERSYNCING', 1024); +define('SMARTIRC_DEBUG_MESSAGEPARSER', 2048); +define('SMARTIRC_DEBUG_DCC', 4096); +define('SMARTIRC_DEBUG_ALL', 8191); +define('SMARTIRC_TYPE_UNKNOWN', 1); +define('SMARTIRC_TYPE_CHANNEL', 2); +define('SMARTIRC_TYPE_QUERY', 4); +define('SMARTIRC_TYPE_CTCP', 8); +define('SMARTIRC_TYPE_NOTICE', 16); +define('SMARTIRC_TYPE_WHO', 32); +define('SMARTIRC_TYPE_JOIN', 64); +define('SMARTIRC_TYPE_INVITE', 128); +define('SMARTIRC_TYPE_ACTION', 256); +define('SMARTIRC_TYPE_TOPICCHANGE', 512); +define('SMARTIRC_TYPE_NICKCHANGE', 1024); +define('SMARTIRC_TYPE_KICK', 2048); +define('SMARTIRC_TYPE_QUIT', 4096); +define('SMARTIRC_TYPE_LOGIN', 8192); +define('SMARTIRC_TYPE_INFO', 16384); +define('SMARTIRC_TYPE_LIST', 32768); +define('SMARTIRC_TYPE_NAME', 65536); +define('SMARTIRC_TYPE_MOTD', 131072); +define('SMARTIRC_TYPE_MODECHANGE', 262144); +define('SMARTIRC_TYPE_PART', 524288); +define('SMARTIRC_TYPE_ERROR', 1048576); +define('SMARTIRC_TYPE_BANLIST', 2097152); +define('SMARTIRC_TYPE_TOPIC', 4194304); +define('SMARTIRC_TYPE_NONRELEVANT', 8388608); +define('SMARTIRC_TYPE_WHOIS', 16777216); +define('SMARTIRC_TYPE_WHOWAS', 33554432); +define('SMARTIRC_TYPE_USERMODE', 67108864); +define('SMARTIRC_TYPE_CHANNELMODE', 134217728); +define('SMARTIRC_TYPE_CTCP_REQUEST', 268435456); +define('SMARTIRC_TYPE_CTCP_REPLY', 536870912); //define('SMARTIRC_TYPE_DCC', 536870912); -define('SMARTIRC_TYPE_ALL', 1073741823); +define('SMARTIRC_TYPE_ALL', 1073741823); $SMARTIRC_replycodes = array( -'RPL_WELCOME' => '001', -'RPL_YOURHOST' => '002', -'RPL_CREATED' => '003', -'RPL_MYINFO' => '004', -'RPL_BOUNCE' => '005', -'RPL_TRACELINK' => '200', -'RPL_TRACECONNECTING' => '201', -'RPL_TRACEHANDSHAKE' => '202', -'RPL_TRACEUNKNOWN' => '203', -'RPL_TRACEOPERATOR' => '204', -'RPL_TRACEUSER' => '205', -'RPL_TRACESERVER' => '206', -'RPL_TRACESERVICE' => '207', -'RPL_TRACENEWTYPE' => '208', -'RPL_TRACECLASS' => '209', -'RPL_TRACERECONNECT' => '210', -'RPL_STATSLINKINFO' => '211', -'RPL_STATSCOMMANDS' => '212', -'RPL_ENDOFSTATS' => '219', -'RPL_UMODEIS' => '221', -'RPL_SERVLIST' => '234', -'RPL_SERVLISTEND' => '235', -'RPL_STATSUPTIME' => '242', -'RPL_STATSOLINE' => '243', -'RPL_LUSERCLIENT' => '251', -'RPL_LUSEROP' => '252', -'RPL_LUSERUNKNOWN' => '253', -'RPL_LUSERCHANNELS' => '254', -'RPL_LUSERME' => '255', -'RPL_ADMINME' => '256', -'RPL_ADMINLOC1' => '257', -'RPL_ADMINLOC2' => '258', -'RPL_ADMINEMAIL' => '259', -'RPL_TRACELOG' => '261', -'RPL_TRACEEND' => '262', -'RPL_TRYAGAIN' => '263', -'RPL_AWAY' => '301', -'RPL_USERHOST' => '302', -'RPL_ISON' => '303', -'RPL_UNAWAY' => '305', -'RPL_NOWAWAY' => '306', -'RPL_WHOISUSER' => '311', -'RPL_WHOISSERVER' => '312', -'RPL_WHOISOPERATOR' => '313', -'RPL_WHOWASUSER' => '314', -'RPL_ENDOFWHO' => '315', -'RPL_WHOISIDLE' => '317', -'RPL_ENDOFWHOIS' => '318', -'RPL_WHOISCHANNELS' => '319', -'RPL_LISTSTART' => '321', -'RPL_LIST' => '322', -'RPL_LISTEND' => '323', -'RPL_CHANNELMODEIS' => '324', -'RPL_UNIQOPIS' => '325', -'RPL_NOTOPIC' => '331', -'RPL_TOPIC' => '332', -'RPL_INVITING' => '341', -'RPL_SUMMONING' => '342', -'RPL_INVITELIST' => '346', -'RPL_ENDOFINVITELIST' => '347', -'RPL_EXCEPTLIST' => '348', -'RPL_ENDOFEXCEPTLIST' => '349', -'RPL_VERSION' => '351', -'RPL_WHOREPLY' => '352', -'RPL_NAMREPLY' => '353', -'RPL_LINKS' => '364', -'RPL_ENDOFLINKS' => '365', -'RPL_ENDOFNAMES' => '366', -'RPL_BANLIST' => '367', -'RPL_ENDOFBANLIST' => '368', -'RPL_ENDOFWHOWAS' => '369', -'RPL_INFO' => '371', -'RPL_MOTD' => '372', -'RPL_ENDOFINFO' => '374', -'RPL_MOTDSTART' => '375', -'RPL_ENDOFMOTD' => '376', -'RPL_YOUREOPER' => '381', -'RPL_REHASHING' => '382', -'RPL_YOURESERVICE' => '383', -'RPL_TIME' => '391', -'RPL_USERSSTART' => '392', -'RPL_USERS' => '393', -'RPL_ENDOFUSERS' => '394', -'RPL_NOUSERS' => '395', -'ERR_NOSUCHNICK' => '401', -'ERR_NOSUCHSERVER' => '402', -'ERR_NOSUCHCHANNEL' => '403', -'ERR_CANNOTSENDTOCHAN' => '404', -'ERR_TOOMANYCHANNELS' => '405', -'ERR_WASNOSUCHNICK' => '406', -'ERR_TOOMANYTARGETS' => '407', -'ERR_NOSUCHSERVICE' => '408', -'ERR_NOORIGIN' => '409', -'ERR_NORECIPIENT' => '411', -'ERR_NOTEXTTOSEND' => '412', -'ERR_NOTOPLEVEL' => '413', -'ERR_WILDTOPLEVEL' => '414', -'ERR_BADMASK' => '415', -'ERR_UNKNOWNCOMMAND' => '421', -'ERR_NOMOTD' => '422', -'ERR_NOADMININFO' => '423', -'ERR_FILEERROR' => '424', -'ERR_NONICKNAMEGIVEN' => '431', -'ERR_ERRONEUSNICKNAME' => '432', -'ERR_NICKNAMEINUSE' => '433', -'ERR_NICKCOLLISION' => '436', -'ERR_UNAVAILRESOURCE' => '437', -'ERR_USERNOTINCHANNEL' => '441', -'ERR_NOTONCHANNEL' => '442', -'ERR_USERONCHANNEL' => '443', -'ERR_NOLOGIN' => '444', -'ERR_SUMMONDISABLED' => '445', -'ERR_USERSDISABLED' => '446', -'ERR_NOTREGISTERED' => '451', -'ERR_NEEDMOREPARAMS' => '461', -'ERR_ALREADYREGISTRED' => '462', -'ERR_NOPERMFORHOST' => '463', -'ERR_PASSWDMISMATCH' => '464', -'ERR_YOUREBANNEDCREEP' => '465', -'ERR_YOUWILLBEBANNED' => '466', -'ERR_KEYSET' => '467', -'ERR_CHANNELISFULL' => '471', -'ERR_UNKNOWNMODE' => '472', -'ERR_INVITEONLYCHAN' => '473', -'ERR_BANNEDFROMCHAN' => '474', -'ERR_BADCHANNELKEY' => '475', -'ERR_BADCHANMASK' => '476', -'ERR_NOCHANMODES' => '477', -'ERR_BANLISTFULL' => '478', -'ERR_NOPRIVILEGES' => '481', -'ERR_CHANOPRIVSNEEDED' => '482', -'ERR_CANTKILLSERVER' => '483', -'ERR_RESTRICTED' => '484', -'ERR_UNIQOPPRIVSNEEDED' => '485', -'ERR_NOOPERHOST' => '491', -'ERR_UMODEUNKNOWNFLAG' => '501', -'ERR_USERSDONTMATCH' => '502', + 'RPL_WELCOME' => '001', + 'RPL_YOURHOST' => '002', + 'RPL_CREATED' => '003', + 'RPL_MYINFO' => '004', + 'RPL_BOUNCE' => '005', + 'RPL_TRACELINK' => '200', + 'RPL_TRACECONNECTING' => '201', + 'RPL_TRACEHANDSHAKE' => '202', + 'RPL_TRACEUNKNOWN' => '203', + 'RPL_TRACEOPERATOR' => '204', + 'RPL_TRACEUSER' => '205', + 'RPL_TRACESERVER' => '206', + 'RPL_TRACESERVICE' => '207', + 'RPL_TRACENEWTYPE' => '208', + 'RPL_TRACECLASS' => '209', + 'RPL_TRACERECONNECT' => '210', + 'RPL_STATSLINKINFO' => '211', + 'RPL_STATSCOMMANDS' => '212', + 'RPL_ENDOFSTATS' => '219', + 'RPL_UMODEIS' => '221', + 'RPL_SERVLIST' => '234', + 'RPL_SERVLISTEND' => '235', + 'RPL_STATSUPTIME' => '242', + 'RPL_STATSOLINE' => '243', + 'RPL_LUSERCLIENT' => '251', + 'RPL_LUSEROP' => '252', + 'RPL_LUSERUNKNOWN' => '253', + 'RPL_LUSERCHANNELS' => '254', + 'RPL_LUSERME' => '255', + 'RPL_ADMINME' => '256', + 'RPL_ADMINLOC1' => '257', + 'RPL_ADMINLOC2' => '258', + 'RPL_ADMINEMAIL' => '259', + 'RPL_TRACELOG' => '261', + 'RPL_TRACEEND' => '262', + 'RPL_TRYAGAIN' => '263', + 'RPL_AWAY' => '301', + 'RPL_USERHOST' => '302', + 'RPL_ISON' => '303', + 'RPL_UNAWAY' => '305', + 'RPL_NOWAWAY' => '306', + 'RPL_WHOISUSER' => '311', + 'RPL_WHOISSERVER' => '312', + 'RPL_WHOISOPERATOR' => '313', + 'RPL_WHOWASUSER' => '314', + 'RPL_ENDOFWHO' => '315', + 'RPL_WHOISIDLE' => '317', + 'RPL_ENDOFWHOIS' => '318', + 'RPL_WHOISCHANNELS' => '319', + 'RPL_LISTSTART' => '321', + 'RPL_LIST' => '322', + 'RPL_LISTEND' => '323', + 'RPL_CHANNELMODEIS' => '324', + 'RPL_UNIQOPIS' => '325', + 'RPL_NOTOPIC' => '331', + 'RPL_TOPIC' => '332', + 'RPL_INVITING' => '341', + 'RPL_SUMMONING' => '342', + 'RPL_INVITELIST' => '346', + 'RPL_ENDOFINVITELIST' => '347', + 'RPL_EXCEPTLIST' => '348', + 'RPL_ENDOFEXCEPTLIST' => '349', + 'RPL_VERSION' => '351', + 'RPL_WHOREPLY' => '352', + 'RPL_NAMREPLY' => '353', + 'RPL_LINKS' => '364', + 'RPL_ENDOFLINKS' => '365', + 'RPL_ENDOFNAMES' => '366', + 'RPL_BANLIST' => '367', + 'RPL_ENDOFBANLIST' => '368', + 'RPL_ENDOFWHOWAS' => '369', + 'RPL_INFO' => '371', + 'RPL_MOTD' => '372', + 'RPL_ENDOFINFO' => '374', + 'RPL_MOTDSTART' => '375', + 'RPL_ENDOFMOTD' => '376', + 'RPL_YOUREOPER' => '381', + 'RPL_REHASHING' => '382', + 'RPL_YOURESERVICE' => '383', + 'RPL_TIME' => '391', + 'RPL_USERSSTART' => '392', + 'RPL_USERS' => '393', + 'RPL_ENDOFUSERS' => '394', + 'RPL_NOUSERS' => '395', + 'ERR_NOSUCHNICK' => '401', + 'ERR_NOSUCHSERVER' => '402', + 'ERR_NOSUCHCHANNEL' => '403', + 'ERR_CANNOTSENDTOCHAN' => '404', + 'ERR_TOOMANYCHANNELS' => '405', + 'ERR_WASNOSUCHNICK' => '406', + 'ERR_TOOMANYTARGETS' => '407', + 'ERR_NOSUCHSERVICE' => '408', + 'ERR_NOORIGIN' => '409', + 'ERR_NORECIPIENT' => '411', + 'ERR_NOTEXTTOSEND' => '412', + 'ERR_NOTOPLEVEL' => '413', + 'ERR_WILDTOPLEVEL' => '414', + 'ERR_BADMASK' => '415', + 'ERR_UNKNOWNCOMMAND' => '421', + 'ERR_NOMOTD' => '422', + 'ERR_NOADMININFO' => '423', + 'ERR_FILEERROR' => '424', + 'ERR_NONICKNAMEGIVEN' => '431', + 'ERR_ERRONEUSNICKNAME' => '432', + 'ERR_NICKNAMEINUSE' => '433', + 'ERR_NICKCOLLISION' => '436', + 'ERR_UNAVAILRESOURCE' => '437', + 'ERR_USERNOTINCHANNEL' => '441', + 'ERR_NOTONCHANNEL' => '442', + 'ERR_USERONCHANNEL' => '443', + 'ERR_NOLOGIN' => '444', + 'ERR_SUMMONDISABLED' => '445', + 'ERR_USERSDISABLED' => '446', + 'ERR_NOTREGISTERED' => '451', + 'ERR_NEEDMOREPARAMS' => '461', + 'ERR_ALREADYREGISTRED' => '462', + 'ERR_NOPERMFORHOST' => '463', + 'ERR_PASSWDMISMATCH' => '464', + 'ERR_YOUREBANNEDCREEP' => '465', + 'ERR_YOUWILLBEBANNED' => '466', + 'ERR_KEYSET' => '467', + 'ERR_CHANNELISFULL' => '471', + 'ERR_UNKNOWNMODE' => '472', + 'ERR_INVITEONLYCHAN' => '473', + 'ERR_BANNEDFROMCHAN' => '474', + 'ERR_BADCHANNELKEY' => '475', + 'ERR_BADCHANMASK' => '476', + 'ERR_NOCHANMODES' => '477', + 'ERR_BANLISTFULL' => '478', + 'ERR_NOPRIVILEGES' => '481', + 'ERR_CHANOPRIVSNEEDED' => '482', + 'ERR_CANTKILLSERVER' => '483', + 'ERR_RESTRICTED' => '484', + 'ERR_UNIQOPPRIVSNEEDED' => '485', + 'ERR_NOOPERHOST' => '491', + 'ERR_UMODEUNKNOWNFLAG' => '501', + 'ERR_USERSDONTMATCH' => '502', ); $SMARTIRC_nreplycodes = array(); foreach ($SMARTIRC_replycodes as $key => $value) { - define('SMARTIRC_'.$key, $value); - $SMARTIRC_nreplycodes[$value] = $key; -} - -?> \ No newline at end of file + define('SMARTIRC_' . $key, $value); + $SMARTIRC_nreplycodes[$value] = $key; +} \ No newline at end of file diff --git a/lib/Net_SmartIRC/Net/SmartIRC/irccommands.php b/lib/Net_SmartIRC/Net/SmartIRC/irccommands.php index 9e33857b9..64ce0c8a2 100644 --- a/lib/Net_SmartIRC/Net/SmartIRC/irccommands.php +++ b/lib/Net_SmartIRC/Net/SmartIRC/irccommands.php @@ -26,20 +26,24 @@ class Net_SmartIRC_irccommands extends Net_SmartIRC_base { - /** - * sends a new message - * - * Sends a message to a channel or user. - * - * @see DOCUMENTATION - * @param integer $type specifies the type, like QUERY/ACTION or CTCP see 'Message Types' - * @param string $destination can be a user or channel - * @param mixed $message the message - * @return boolean - * @access public - */ - function message($type, $destination, $messagearray, $priority = SMARTIRC_MEDIUM) - { + /** + * sends a new message + * + * Sends a message to a channel or user. + * + * @see DOCUMENTATION + * + * @param integer $type specifies the type, like QUERY/ACTION or CTCP see 'Message Types' + * @param string $destination can be a user or channel + * @param $messagearray + * @param int $priority + * + * @internal param mixed $message the message + * @return boolean + * @access public + */ + function message($type, $destination, $messagearray, $priority = SMARTIRC_MEDIUM) + { if (!is_array($messagearray)) { $messagearray = array($messagearray); } diff --git a/lib/Net_SmartIRC/modules/PingFix.php b/lib/Net_SmartIRC/modules/PingFix.php index 58e025e72..6bf2e68ec 100644 --- a/lib/Net_SmartIRC/modules/PingFix.php +++ b/lib/Net_SmartIRC/modules/PingFix.php @@ -2,33 +2,35 @@ class Net_SmartIRC_module_PingFix { - public $name = 'PingFix'; - public $version = '1.0'; - public $description = 'An active-pinging system to keep the bot from dropping the connection'; - public $author = 'Garrett W.'; - public $license = 'LGPL'; + public $name = 'PingFix'; + public $version = '1.0'; + public $description = 'An active-pinging system to keep the bot from dropping the connection'; + public $author = 'Garrett W.'; + public $license = 'LGPL'; - private $irc; - private $thid; + private $irc; + private $thid; - function __construct (&$irc) { - $this->irc = $irc; - $this->thid = $this->irc->registerTimehandler( - $this->irc->_rxtimeout/8*1000, $this, 'pingCheck' - ); - } + function __construct(&$irc) + { + $this->irc = $irc; + $this->thid = $this->irc->registerTimehandler( + $this->irc->_rxtimeout / 8 * 1000, $this, 'pingCheck' + ); + } - function __destruct () { - $this->irc->unregisterTimeid($this->thid); - } + function __destruct() + { + $this->irc->unregisterTimeid($this->thid); + } - function pingCheck () { - if (time() - $this->irc->_lastrx > $this->irc->_rxtimeout) { - $this->irc->reconnect(); - $this->irc->_lastrx = time(); - } elseif (time() - $this->irc->_lastrx > $this->irc->_rxtimeout/3) { - $this->irc->_send('PING '.$this->irc->_address, SMARTIRC_CRITICAL); - } - } + function pingCheck() + { + if (time() - $this->irc->_lastrx > $this->irc->_rxtimeout) { + $this->irc->reconnect(); + $this->irc->_lastrx = time(); + } elseif (time() - $this->irc->_lastrx > $this->irc->_rxtimeout / 3) { + $this->irc->_send('PING ' . $this->irc->_address, SMARTIRC_CRITICAL); + } + } } -?> diff --git a/lib/copy_this/www/lib/Net_NNTP/NNTP/Client.php b/lib/copy_this/www/lib/Net_NNTP/NNTP/Client.php index 4105ac998..56779cf9c 100644 --- a/lib/copy_this/www/lib/Net_NNTP/NNTP/Client.php +++ b/lib/copy_this/www/lib/Net_NNTP/NNTP/Client.php @@ -104,7 +104,7 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * * @var array * @access private - * @since 1.3.0 + * @since 1.3.0 */ var $_overviewFormatCache = null; @@ -135,17 +135,17 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/connect.php} * - * @param string $host (optional) The hostname og IP-address of the NNTP-server to connect to, defaults to localhost. - * @param mixed $encryption (optional) false|'tls'|'ssl', defaults to false. - * @param int $port (optional) The port number to connect to, defaults to 119 or 563 dependng on $encryption. - * @param int $timeout (optional) + * @param string $host (optional) The hostname og IP-address of the NNTP-server to connect to, defaults to localhost. + * @param mixed $encryption (optional) false|'tls'|'ssl', defaults to false. + * @param int $port (optional) The port number to connect to, defaults to 119 or 563 dependng on $encryption. + * @param int $timeout (optional) * * @return mixed
- * - (bool) True when posting allowed, otherwise false - * - (object) Pear_Error on failure + * - (bool) True when posting allowed, otherwise false + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::disconnect() - * @see Net_NNTP_Client::authenticate() + * @see Net_NNTP_Client::disconnect() + * @see Net_NNTP_Client::authenticate() */ function connect($host = null, $encryption = null, $port = null, $timeout = 15) { @@ -176,13 +176,14 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * * @return mixed
* - (bool) - * - (object) Pear_Error on failure + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::connect() + * @see Net_NNTP_Client::connect() */ function disconnect() { $this->resetProperties(); + return parent::disconnect(); } @@ -201,14 +202,14 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/authenticate.php} * - * @param string $user The username - * @param string $pass The password + * @param string $user The username + * @param string $pass The password * * @return mixed
- * - (bool) True on successful authentification, otherwise false - * - (object) Pear_Error on failure + * - (bool) True on successful authentification, otherwise false + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::connect() + * @see Net_NNTP_Client::connect() */ function authenticate($user, $pass) { @@ -237,18 +238,18 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/selectGroup.php} * - * @param string $group Name of the group to select - * @param mixed $articles (optional) experimental! When true the article numbers is returned in 'articles' + * @param string $group Name of the group to select + * @param mixed $articles (optional) experimental! When true the article numbers is returned in 'articles' * * @return mixed
- * - (array) Summary about the selected group - * - (object) Pear_Error on failure + * - (array) Summary about the selected group + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::getGroups() - * @see Net_NNTP_Client::group() - * @see Net_NNTP_Client::first() - * @see Net_NNTP_Client::last() - * @see Net_NNTP_Client::count() + * @see Net_NNTP_Client::getGroups() + * @see Net_NNTP_Client::group() + * @see Net_NNTP_Client::first() + * @see Net_NNTP_Client::last() + * @see Net_NNTP_Client::count() */ function selectGroup($group, $articles = false) { @@ -292,17 +293,17 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/selectPreviousArticle.php} * - * @param int $_ret (optional) Experimental + * @param int $_ret (optional) Experimental * * @return mixed
- * - (integer) Article number, if $ret=0 (default) - * - (string) Message-id, if $ret=1 - * - (array) Both article number and message-id, if $ret=-1 - * - (bool) False if no prevoius article exists - * - (object) Pear_Error on failure + * - (integer) Article number, if $ret=0 (default) + * - (string) Message-id, if $ret=1 + * - (array) Both article number and message-id, if $ret=-1 + * - (bool) False if no prevoius article exists + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::selectArticle() - * @see Net_NNTP_Client::selectNextArticle() + * @see Net_NNTP_Client::selectArticle() + * @see Net_NNTP_Client::selectNextArticle() */ function selectPreviousArticle($_ret = 0) { @@ -314,13 +315,13 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client switch ($_ret) { case -1: - return array('Number' => (int) $response[0], 'Message-ID' => (string) $response[1]); + return array('Number' => (int)$response[0], 'Message-ID' => (string)$response[1]); break; case 0: - return (int) $response[0]; + return (int)$response[0]; break; case 1: - return (string) $response[1]; + return (string)$response[1]; break; default: error(); // ... @@ -338,17 +339,17 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/selectNextArticle.php} * - * @param int $_ret (optional) Experimental + * @param int $_ret (optional) Experimental * * @return mixed
- * - (integer) Article number, if $ret=0 (default) - * - (string) Message-id, if $ret=1 - * - (array) Both article number and message-id, if $ret=-1 - * - (bool) False if no further articles exist - * - (object) Pear_Error on unexpected failure + * - (integer) Article number, if $ret=0 (default) + * - (string) Message-id, if $ret=1 + * - (array) Both article number and message-id, if $ret=-1 + * - (bool) False if no further articles exist + * - (object) Pear_Error on unexpected failure * @access public - * @see Net_NNTP_Client::selectArticle() - * @see Net_NNTP_Client::selectPreviousArticle() + * @see Net_NNTP_Client::selectArticle() + * @see Net_NNTP_Client::selectPreviousArticle() */ function selectNextArticle($_ret = 0) { @@ -360,13 +361,13 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client switch ($_ret) { case -1: - return array('Number' => (int) $response[0], 'Message-ID' => (string) $response[1]); + return array('Number' => (int)$response[0], 'Message-ID' => (string)$response[1]); break; case 0: - return (int) $response[0]; + return (int)$response[0]; break; case 1: - return (string) $response[1]; + return (string)$response[1]; break; default: error(); // ... @@ -384,17 +385,17 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/selectArticle.php} * - * @param mixed $article The message-number (on the server) of + * @param mixed $article The message-number (on the server) of * the article to select as current article. - * @param int $_ret (optional) Experimental + * @param int $_ret (optional) Experimental * * @return mixed
- * - (integer) Article number - * - (bool) False if article doesn't exists - * - (object) Pear_Error on failure + * - (integer) Article number + * - (bool) False if article doesn't exists + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::selectNextArticle() - * @see Net_NNTP_Client::selectPreviousArticle() + * @see Net_NNTP_Client::selectNextArticle() + * @see Net_NNTP_Client::selectPreviousArticle() */ function selectArticle($article = null, $_ret = 0) { @@ -406,13 +407,13 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client switch ($_ret) { case -1: - return array('Number' => (int) $response[0], 'Message-ID' => (string) $response[1]); + return array('Number' => (int)$response[0], 'Message-ID' => (string)$response[1]); break; case 0: - return (int) $response[0]; + return (int)$response[0]; break; case 1: - return (string) $response[1]; + return (string)$response[1]; break; default: error(); // ... @@ -431,20 +432,20 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/getArticle.php} * - * @param mixed $article (optional) Either the message-id or the + * @param mixed $article (optional) Either the message-id or the * message-number on the server of the * article to fetch. - * @param bool $implode (optional) When true the result array + * @param bool $implode (optional) When true the result array * is imploded to a string, defaults to * false. * * @return mixed
- * - (array) Complete article (when $implode is false) - * - (string) Complete article (when $implode is true) - * - (object) Pear_Error on failure + * - (array) Complete article (when $implode is false) + * - (string) Complete article (when $implode is true) + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::getHeader() - * @see Net_NNTP_Client::getBody() + * @see Net_NNTP_Client::getHeader() + * @see Net_NNTP_Client::getBody() */ function getArticle($article = null, $implode = false) { @@ -490,20 +491,20 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/getHeader.php} * - * @param mixed $article (optional) Either message-id or message + * @param mixed $article (optional) Either message-id or message * number of the article to fetch. - * @param bool $implode (optional) When true the result array + * @param bool $implode (optional) When true the result array * is imploded to a string, defaults to * false. * * @return mixed
- * - (bool) False if article does not exist - * - (array) Header fields (when $implode is false) - * - (string) Header fields (when $implode is true) - * - (object) Pear_Error on failure + * - (bool) False if article does not exist + * - (array) Header fields (when $implode is false) + * - (string) Header fields (when $implode is true) + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::getArticle() - * @see Net_NNTP_Client::getBody() + * @see Net_NNTP_Client::getArticle() + * @see Net_NNTP_Client::getBody() */ function getHeader($article = null, $implode = false) { @@ -549,20 +550,20 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/getBody.php} * - * @param mixed $article (optional) Either the message-id or the + * @param mixed $article (optional) Either the message-id or the * message-number on the server of the * article to fetch. - * @param bool $implode (optional) When true the result array + * @param bool $implode (optional) When true the result array * is imploded to a string, defaults to * false. * * @return mixed
- * - (array) Message body (when $implode is false) - * - (string) Message body (when $implode is true) - * - (object) Pear_Error on failure + * - (array) Message body (when $implode is false) + * - (string) Message body (when $implode is true) + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::getHeader() - * @see Net_NNTP_Client::getArticle() + * @see Net_NNTP_Client::getHeader() + * @see Net_NNTP_Client::getArticle() */ function getBody($article = null, $implode = false) { @@ -605,14 +606,14 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/post.php} * - * @param mixed $article
- * - (string) Complete article in a ready to send format (lines terminated by LFCR etc.) - * - (array) First key is the article header, second key is article body - any further keys are ignored !!! - * - (mixed) Something 'callable' (which must return otherwise acceptable data as replacement) + * @param mixed $article
+ * - (string) Complete article in a ready to send format (lines terminated by LFCR etc.) + * - (array) First key is the article header, second key is article body - any further keys are ignored !!! + * - (mixed) Something 'callable' (which must return otherwise acceptable data as replacement) * * @return mixed
- * - (string) Server response - * - (object) Pear_Error on failure + * - (string) Server response + * - (object) Pear_Error on failure * @access public * @ignore */ @@ -671,14 +672,14 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/mail.php} * - * @param string $groups The groups to post to. - * @param string $subject The subject of the article. - * @param string $body The body of the article. - * @param string $additional (optional) Additional header fields to send. + * @param string $groups The groups to post to. + * @param string $subject The subject of the article. + * @param string $body The body of the article. + * @param string $additional (optional) Additional header fields to send. * * @return mixed
- * - (string) Server response - * - (object) Pear_Error on failure + * - (string) Server response + * - (object) Pear_Error on failure * @access public */ function mail($groups, $subject, $body, $additional = null) @@ -715,14 +716,14 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/getDate.php} * - * @param int $format (optional) Determines the format of returned date: + * @param int $format (optional) Determines the format of returned date: * - 0: return string * - 1: return integer/timestamp * - 2: return an array('y'=>year, 'm'=>month,'d'=>day) * * @return mixed
* - (mixed) - * - (object) Pear_Error on failure + * - (object) Pear_Error on failure * @access public */ function getDate($format = 1) @@ -741,8 +742,9 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client break; case 2: return array('y' => substr($date, 0, 4), - 'm' => substr($date, 4, 2), - 'd' => substr($date, 6, 2)); + 'm' => substr($date, 4, 2), + 'd' => substr($date, 6, 2) + ); break; default: error(); @@ -761,14 +763,14 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/getNewGroups.php} * - * @param mixed $time
- * - (integer) A timestamp - * - (string) Somthing parseable by strtotime() like '-1 week' - * @param string $distributions (optional) + * @param mixed $time
+ * - (integer) A timestamp + * - (string) Somthing parseable by strtotime() like '-1 week' + * @param string $distributions (optional) * * @return mixed
* - (array) - * - (object) Pear_Error on failure + * - (object) Pear_Error on failure * @access public */ function getNewGroups($time, $distributions = null) @@ -801,17 +803,17 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/getNewArticles.php} * - * @param mixed $time
- * - (integer) A timestamp - * - (string) Somthing parseable by strtotime() like '-1 week' - * @param string $groups (optional) - * @param string $distributions (optional) + * @param mixed $time
+ * - (integer) A timestamp + * - (string) Somthing parseable by strtotime() like '-1 week' + * @param string $groups (optional) + * @param string $distributions (optional) * * @return mixed
* - (array) - * - (object) Pear_Error on failure + * - (object) Pear_Error on failure * @access public - * @since 1.3.0 + * @since 1.3.0 */ function getNewArticles($time, $groups = '*', $distribution = null) { @@ -844,11 +846,11 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * {@example docs/examples/phpdoc/getGroups.php} * * @return mixed
- * - (array) Nested array with information about every valid group - * - (object) Pear_Error on failure + * - (array) Nested array with information about every valid group + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::getDescriptions() - * @see Net_NNTP_Client::selectGroup() + * @see Net_NNTP_Client::getDescriptions() + * @see Net_NNTP_Client::selectGroup() */ function getGroups($wildmat = null) { @@ -907,13 +909,13 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/getDescriptions.php} * - * @param mixed $wildmat (optional) + * @param mixed $wildmat (optional) * * @return mixed
- * - (array) Associated array with descriptions of known groups - * - (object) Pear_Error on failure + * - (array) Associated array with descriptions of known groups + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::getGroups() + * @see Net_NNTP_Client::getGroups() */ function getDescriptions($wildmat = null) { @@ -961,20 +963,20 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/getOverview.php} * - * @param mixed $range (optional) - * - '' - * - '-' - * - '-' - * - '' - * @param boolean $_names (optional) experimental parameter! Use field names as array kays - * @param boolean $_forceNames (optional) experimental parameter! + * @param mixed $range (optional) + * - '' + * - '-' + * - '-' + * - '' + * @param boolean $_names (optional) experimental parameter! Use field names as array kays + * @param boolean $_forceNames (optional) experimental parameter! * * @return mixed
- * - (array) Nested array of article overview data - * - (object) Pear_Error on failure + * - (array) Nested array of article overview data + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::getHeaderField() - * @see Net_NNTP_Client::getOverviewFormat() + * @see Net_NNTP_Client::getHeaderField() + * @see Net_NNTP_Client::getOverviewFormat() */ function getOverview($range = null, $_names = true, $_forceNames = true) { @@ -1010,6 +1012,7 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client // Use 'Message-ID' field as key $articles[$article['Message-ID']] = $article; } + return $articles; } @@ -1107,10 +1110,10 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * {@example docs/examples/phpdoc/getOveriewFormat.php} * * @return mixed
- * - (array) Overview field names - * - (object) Pear_Error on failure + * - (array) Overview field names + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::getOverview() + * @see Net_NNTP_Client::getOverview() */ function getOverviewFormat($_forceNames = true, $_full = false) { @@ -1122,13 +1125,15 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client // Force name of first seven fields if ($_forceNames) { array_splice($format, 0, 7); - $format = array_merge(array('Subject' => false, - 'From' => false, - 'Date' => false, - 'Message-ID' => false, - 'References' => false, - ':bytes' => false, - ':lines' => false), $format); + $format = array_merge(array('Subject' => false, + 'From' => false, + 'Date' => false, + 'Message-ID' => false, + 'References' => false, + ':bytes' => false, + ':lines' => false + ), $format + ); } if ($_full) { @@ -1153,19 +1158,19 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/getHeaderField.php} * - * @param string $field The name of the header field to retreive - * @param mixed $range (optional) + * @param string $field The name of the header field to retreive + * @param mixed $range (optional) * '' * '-' * '-' * '' * * @return mixed
- * - (array) Nested array of - * - (object) Pear_Error on failure + * - (array) Nested array of + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::getOverview() - * @see Net_NNTP_Client::getReferences() + * @see Net_NNTP_Client::getOverview() + * @see Net_NNTP_Client::getReferences() */ function getHeaderField($field, $range = null) { @@ -1211,13 +1216,13 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/getGroupArticles.php} * - * @param mixed $range (optional) Experimental! + * @param mixed $range (optional) Experimental! * * @return mixed
* - (array) - * - (object) Pear_Error on failure + * - (object) Pear_Error on failure * @access public - * @since 1.3.0 + * @since 1.3.0 */ function getGroupArticles($range = null) { @@ -1253,17 +1258,17 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * Usage example: * {@example docs/examples/phpdoc/getReferences.php} * - * @param mixed $range (optional) + * @param mixed $range (optional) * '' * '-' * '-' * '' * * @return mixed
- * - (array) Nested array of references - * - (object) Pear_Error on failure + * - (array) Nested array of references + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::getHeaderField() + * @see Net_NNTP_Client::getHeaderField() */ function getReferences($range = null) { @@ -1340,13 +1345,13 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * {@example docs/examples/phpdoc/count.php} * * @return mixed
- * - (string) the number of article in group - * - (object) Pear_Error on failure + * - (string) the number of article in group + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::group() - * @see Net_NNTP_Client::first() - * @see Net_NNTP_Client::last() - * @see Net_NNTP_Client::selectGroup() + * @see Net_NNTP_Client::group() + * @see Net_NNTP_Client::first() + * @see Net_NNTP_Client::last() + * @see Net_NNTP_Client::selectGroup() * @ignore */ function count() @@ -1364,13 +1369,13 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * {@example docs/examples/phpdoc/last.php} * * @return mixed
- * - (string) the last article's number - * - (object) Pear_Error on failure + * - (string) the last article's number + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::first() - * @see Net_NNTP_Client::group() - * @see Net_NNTP_Client::count() - * @see Net_NNTP_Client::selectGroup() + * @see Net_NNTP_Client::first() + * @see Net_NNTP_Client::group() + * @see Net_NNTP_Client::count() + * @see Net_NNTP_Client::selectGroup() * @ignore */ function last() @@ -1388,13 +1393,13 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * {@example docs/examples/phpdoc/first.php} * * @return mixed
- * - (string) the first article's number - * - (object) Pear_Error on failure + * - (string) the first article's number + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::last() - * @see Net_NNTP_Client::group() - * @see Net_NNTP_Client::count() - * @see Net_NNTP_Client::selectGroup() + * @see Net_NNTP_Client::last() + * @see Net_NNTP_Client::group() + * @see Net_NNTP_Client::count() + * @see Net_NNTP_Client::selectGroup() * @ignore */ function first() @@ -1412,13 +1417,13 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client * {@example docs/examples/phpdoc/group.php} * * @return mixed
- * - (string) group name - * - (object) Pear_Error on failure + * - (string) group name + * - (object) Pear_Error on failure * @access public - * @see Net_NNTP_Client::first() - * @see Net_NNTP_Client::last() - * @see Net_NNTP_Client::count() - * @see Net_NNTP_Client::selectGroup() + * @see Net_NNTP_Client::first() + * @see Net_NNTP_Client::last() + * @see Net_NNTP_Client::count() + * @see Net_NNTP_Client::selectGroup() * @ignore */ function group() @@ -1432,16 +1437,17 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client /** * Test whether a connection is currently open or closed. * - * @return bool True if connected, otherwise false - * @access public - * @see Net_NNTP_Client::connect() - * @see Net_NNTP_Client::quit() - * @deprecated since v1.3.0 due to use of protected method: Net_NNTP_Protocol_Client::isConnected() + * @return bool True if connected, otherwise false + * @access public + * @see Net_NNTP_Client::connect() + * @see Net_NNTP_Client::quit() + * @deprecated since v1.3.0 due to use of protected method: Net_NNTP_Protocol_Client::isConnected() * @ignore */ function isConnected() { trigger_error('You are using deprecated API v1.0 in Net_NNTP_Client: isConnected() !', E_USER_NOTICE); + return parent::_isConnected(); } @@ -1457,6 +1463,7 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client function getArticleRaw($article, $implode = false) { trigger_error('You are using deprecated API v1.0 in Net_NNTP_Client: getArticleRaw() !', E_USER_NOTICE); + return $this->getArticle($article, $implode); } @@ -1472,6 +1479,7 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client function getHeaderRaw($article = null, $implode = false) { trigger_error('You are using deprecated API v1.0 in Net_NNTP_Client: getHeaderRaw() !', E_USER_NOTICE); + return $this->getHeader($article, $implode); } @@ -1487,6 +1495,7 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client function getBodyRaw($article = null, $implode = false) { trigger_error('You are using deprecated API v1.0 in Net_NNTP_Client: getBodyRaw() !', E_USER_NOTICE); + return $this->getBody($article, $implode); } @@ -1502,6 +1511,7 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client function getNewNews($time, $groups = '*', $distribution = null) { trigger_error('You are using deprecated API v1.1 in Net_NNTP_Client: getNewNews() !', E_USER_NOTICE); + return $this->getNewArticles($time, $groups, $distribution); } @@ -1517,6 +1527,7 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client function getReferencesOverview($first, $last) { trigger_error('You are using deprecated API v1.0 in Net_NNTP_Client: getReferencesOverview() !', E_USER_NOTICE); + return $this->getReferences($first . '-' . $last); } @@ -1524,4 +1535,3 @@ class Net_NNTP_Client extends Net_NNTP_Protocol_Client } // }}} -?> diff --git a/lib/copy_this/www/lib/Net_NNTP/NNTP/Protocol/Client.php b/lib/copy_this/www/lib/Net_NNTP/NNTP/Protocol/Client.php index bb5a263f1..3b71c5a55 100644 --- a/lib/copy_this/www/lib/Net_NNTP/NNTP/Protocol/Client.php +++ b/lib/copy_this/www/lib/Net_NNTP/NNTP/Protocol/Client.php @@ -70,7 +70,8 @@ // Warn about PHP bugs if (version_compare(PHP_VERSION, '5.2.11') === 0) { trigger_error('PHP bug #16657 breaks feof() on socket streams! ' - .'Connection consistency might be compromised!', E_USER_WARNING); + . 'Connection consistency might be compromised!', E_USER_WARNING + ); } /** @@ -119,8 +120,8 @@ define('NET_NNTP_PROTOCOL_CLIENT_DEFAULT_PORT', '119'); * changes doesn't affect the public API of * the Net_NNTP_Client class, which is considered stable. * - * TODO: cmdListActiveTimes() - * cmdDistribPats() + * TODO: cmdListActiveTimes() + * cmdDistribPats() * * @category Net * @package Net_NNTP @@ -166,7 +167,8 @@ class Net_NNTP_Protocol_Client extends PEAR * * @access public */ - function Net_NNTP_Protocol_Client() { + function Net_NNTP_Protocol_Client() + { // // parent::PEAR('Net_NNTP_Error'); parent::PEAR(); @@ -180,7 +182,8 @@ class Net_NNTP_Protocol_Client extends PEAR * * @access public */ - function getPackageVersion() { + function getPackageVersion() + { return '1.5.0'; } @@ -192,7 +195,8 @@ class Net_NNTP_Protocol_Client extends PEAR * * @access public */ - function getApiVersion() { + function getApiVersion() + { return '0.9.0'; } @@ -206,7 +210,8 @@ class Net_NNTP_Protocol_Client extends PEAR * * @access protected */ - function setLogger($logger) { + function setLogger($logger) + { $this->_logger = $logger; } @@ -216,10 +221,12 @@ class Net_NNTP_Protocol_Client extends PEAR /** * @deprecated */ - function setDebug($debug = true) { + function setDebug($debug = true) + { trigger_error('You are using deprecated API v1.0 in ' - .'Net_NNTP_Protocol_Client: setDebug() ! Debugging in now ' - .'automatically handled when a logger is given.', E_USER_NOTICE); + . 'Net_NNTP_Protocol_Client: setDebug() ! Debugging in now ' + . 'automatically handled when a logger is given.', E_USER_NOTICE + ); } // }}} @@ -238,11 +245,13 @@ class Net_NNTP_Protocol_Client extends PEAR * pear_error on failure * @access private */ - function _sendCommand($cmd) { + function _sendCommand($cmd) + { // NNTP/RFC977 only allows command up to 512 (-2) chars. if (!strlen($cmd) > 510) - return$this->throwError( - 'Failed writing to socket! (Command to long - max 510 chars)'); + return $this->throwError( + 'Failed writing to socket! (Command to long - max 510 chars)' + ); /*************************************************************** * Credit: * @@ -253,7 +262,6 @@ class Net_NNTP_Protocol_Client extends PEAR * function with user input, by appending a new line * * character followed by the injection. * *************************************************************** - * Prevent new line (and possible future) characters in the NNTP * commands Net_NNTP does not support pipelined commands. * Inserting a new line charecter allows sending multiple @@ -262,10 +270,14 @@ class Net_NNTP_Protocol_Client extends PEAR */ if (preg_match_all('/\r?\n/', $cmd, $matches, PREG_PATTERN_ORDER)) { foreach ($matches[0] as $key => $match) { - $this->_logger->debug("Illegal character in command: ". - htmlentities(str_replace(array("\r","\n"), - array("'Carriage Return'", "'New Line'"), $match))); + $this->_logger->debug("Illegal character in command: " . + htmlentities(str_replace(array("\r", "\n"), + array("'Carriage Return'", "'New Line'"), $match + ) + ) + ); } + return $this->throwError("Illegal character(s) in NNTP command!"); } @@ -299,7 +311,8 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access private */ - function _getStatusResponse() { + function _getStatusResponse() + { // Retrieve a line (terminated by "\r\n") from the server. // RFC says max is 510, but IETF says "be liberal in what you accept"... $response = @fgets($this->_socket, 4096); @@ -319,8 +332,9 @@ class Net_NNTP_Protocol_Client extends PEAR $response = ltrim($response); $this->_currentStatusResponse = - array((int) substr($response, 0, 3), - (string) rtrim(substr($response, 4))); + array((int)substr($response, 0, 3), + (string)rtrim(substr($response, 4)) + ); // return $this->_currentStatusResponse[0]; @@ -338,7 +352,8 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access private */ - function _getTextResponse() { + function _getTextResponse() + { $data = array(); $line = ''; @@ -369,6 +384,7 @@ class Net_NNTP_Protocol_Client extends PEAR if ($this->_logger) { $this->_logger->notice('Max line length...'); } + return $this->throwError('Invalid line recieved!', null); } } @@ -406,7 +422,8 @@ class Net_NNTP_Protocol_Client extends PEAR if ($this->_logger) { $this->_logger->warning('Broke out of reception loop! ' - .'This souldn\'t happen unless connection has been lost?'); + . 'This souldn\'t happen unless connection has been lost?' + ); } // @@ -421,7 +438,8 @@ class Net_NNTP_Protocol_Client extends PEAR * * @access private */ - function _sendArticle($article) { + function _sendArticle($article) + { /* data should be in the format specified by RFC850 */ switch (true) { @@ -433,7 +451,7 @@ class Net_NNTP_Protocol_Client extends PEAR // if ($this->_logger && $this->_logger->_isMasked(PEAR_LOG_DEBUG)) { foreach (explode("\r\n", $article) as $line) { - $this->_logger->debug('D: ' . $line); + $this->_logger->debug('D: ' . $line); } $this->_logger->debug('D: .'); } @@ -444,12 +462,12 @@ class Net_NNTP_Protocol_Client extends PEAR $header = reset($article); $body = next($article); -/* Experimental... - // If header is an array, implode it. - if (is_array($header)) { - $header = implode("\r\n", $header) . "\r\n"; - } -*/ + /* Experimental... + // If header is an array, implode it. + if (is_array($header)) { + $header = implode("\r\n", $header) . "\r\n"; + } + */ // Send header (including separation line) @fwrite($this->_socket, $header); @@ -463,12 +481,12 @@ class Net_NNTP_Protocol_Client extends PEAR } -/* Experimental... - // If body is an array, implode it. - if (is_array($body)) { - $header = implode("\r\n", $body) . "\r\n"; - } -*/ + /* Experimental... + // If body is an array, implode it. + if (is_array($body)) { + $header = implode("\r\n", $body) . "\r\n"; + } + */ // Send body @fwrite($this->_socket, $body); @@ -499,7 +517,8 @@ class Net_NNTP_Protocol_Client extends PEAR * @return string status text * @access private */ - function _currentStatusResponse() { + function _currentStatusResponse() + { return $this->_currentStatusResponse[1]; } @@ -509,13 +528,14 @@ class Net_NNTP_Protocol_Client extends PEAR /** * * - * @param int $code Status code number + * @param int $code Status code number * @param string $text Status text * * @return mixed * @access private */ - function _handleUnexpectedResponse($code = null, $text = null) { + function _handleUnexpectedResponse($code = null, $text = null) + { if ($code === null) { $code = $this->_currentStatusResponse[0]; } @@ -530,44 +550,48 @@ class Net_NNTP_Protocol_Client extends PEAR */ case NET_NNTP_PROTOCOL_RESPONSECODE_NOT_PERMITTED: return $this->throwError('Command not permitted / Access' - .' restriction / Permission denied', $code, $text); + . ' restriction / Permission denied', $code, $text + ); break; default: return $this->throwError("Unexpected response: '$text'", - $code, $text); + $code, $text + ); } } // }}} -/* Session administration commands */ + /* Session administration commands */ // {{{ Connect() /** * Connect to a NNTP server * - * @param string $host (optional) The address of the - * NNTP-server to connect to, defaults to 'localhost'. - * @param mixed $encryption (optional) - * @param int $port (optional) The port number to connect to, - * defaults to 119. - * @param int $timeout (optional) + * @param string $host (optional) The address of the + * NNTP-server to connect to, defaults to 'localhost'. + * @param mixed $encryption (optional) + * @param int $port (optional) The port number to connect to, + * defaults to 119. + * @param int $timeout (optional) * * @return mixed (bool) on success (true when posting allowed, * otherwise false) or (object) pear_error on failure * @access protected */ - function connect($host = null, $encryption = null, $port = null, $timeout = 15) { + function connect($host = null, $encryption = null, $port = null, $timeout = 15) + { // - if ($this->_isConnected() ) { + if ($this->_isConnected()) { return $this->throwError('Already connected, disconnect first!', null); } // v1.0.x API if (is_int($encryption)) { trigger_error('You are using deprecated API v1.0 in ' - .'Net_NNTP_Protocol_Client: connect() !', E_USER_NOTICE); + . 'Net_NNTP_Protocol_Client: connect() !', E_USER_NOTICE + ); $port = $encryption; $encryption = false; } @@ -602,6 +626,7 @@ class Net_NNTP_Protocol_Client extends PEAR default: $message = '$encryption parameter must be either tcp, tls, ssl or sslv3.'; trigger_error($message, E_USER_ERROR); + return $this->throwError($message); } @@ -615,6 +640,7 @@ class Net_NNTP_Protocol_Client extends PEAR if ($this->_logger) { $this->_logger->notice($message); } + return $this->throwError($message); } @@ -639,7 +665,7 @@ class Net_NNTP_Protocol_Client extends PEAR return true; break; - // 201, Posting NOT allowed + // 201, Posting NOT allowed case NET_NNTP_PROTOCOL_RESPONSECODE_READY_POSTING_PROHIBITED: // if ($this->_logger) { @@ -652,7 +678,8 @@ class Net_NNTP_Protocol_Client extends PEAR case 400: return $this->throwError('Server refused connection', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; /* 502, 'access restriction or permission denied' @@ -660,7 +687,8 @@ class Net_NNTP_Protocol_Client extends PEAR */ case NET_NNTP_PROTOCOL_RESPONSECODE_NOT_PERMITTED: return $this->throwError('Server refused connection', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -676,7 +704,8 @@ class Net_NNTP_Protocol_Client extends PEAR * * @access protected */ - function disconnect() { + function disconnect() + { return $this->cmdQuit(); } @@ -690,7 +719,8 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access protected */ - function cmdCapabilities() { + function cmdCapabilities() + { // tell the newsserver we want an article $response = $this->_sendCommand('CAPABILITIES'); if ($this->isError($response)) { @@ -704,6 +734,7 @@ class Net_NNTP_Protocol_Client extends PEAR if ($this->isError($data)) { return $data; } + return $data; break; @@ -722,7 +753,8 @@ class Net_NNTP_Protocol_Client extends PEAR * postind disallowed or (object) pear_error on failure * @access protected */ - function cmdModeReader() { + function cmdModeReader() + { // tell the newsserver we want an article $response = $this->_sendCommand('MODE READER'); if ($this->isError($response)) { @@ -741,6 +773,7 @@ class Net_NNTP_Protocol_Client extends PEAR if ($this->_logger) { $this->_logger->info('Posting not allowed!'); } + // TODO: Set some variable before return return false; break; @@ -750,8 +783,9 @@ class Net_NNTP_Protocol_Client extends PEAR */ case NET_NNTP_PROTOCOL_RESPONSECODE_NOT_PERMITTED: return $this->throwError('Connection being closed, ' - .'since service so permanently unavailable', - $response, $this->_currentStatusResponse()); + . 'since service so permanently unavailable', + $response, $this->_currentStatusResponse() + ); break; default: @@ -769,7 +803,8 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access protected */ - function cmdQuit() { + function cmdQuit() + { // Tell the server to close the connection $response = $this->_sendCommand('QUIT'); if ($this->isError($response)) { @@ -788,6 +823,7 @@ class Net_NNTP_Protocol_Client extends PEAR } $this->_currentStatusResponse = null; $this->_socket = null; + return true; break; @@ -798,7 +834,7 @@ class Net_NNTP_Protocol_Client extends PEAR // }}} -/* */ + /* */ // {{{ cmdStartTLS() @@ -808,7 +844,8 @@ class Net_NNTP_Protocol_Client extends PEAR * @return mixed (bool) on success or (object) pear_error on failure * @access protected */ - function cmdStartTLS() { + function cmdStartTLS() + { $response = $this->_sendCommand('STARTTLS'); if ($this->isError($response)) { return $response; @@ -817,12 +854,14 @@ class Net_NNTP_Protocol_Client extends PEAR switch ($response) { case 382: // RFC4642: 'continue with TLS negotiation' $encrypted = stream_socket_enable_crypto($this->_socket, - true, STREAM_CRYPTO_METHOD_TLS_CLIENT); + true, STREAM_CRYPTO_METHOD_TLS_CLIENT + ); switch (true) { case $encrypted === true: if ($this->_logger) { $this->_logger->info('TLS encryption started.'); } + return true; break; @@ -830,27 +869,32 @@ class Net_NNTP_Protocol_Client extends PEAR if ($this->_logger) { $this->_logger->info('TLS encryption failed.'); } + return $this->throwError('Could not initiate ' - .'TLS negotiation', $response, - $this->_currentStatusResponse()); + . 'TLS negotiation', $response, + $this->_currentStatusResponse() + ); break; case is_int($encrypted): return $this->throwError('', $response, - $this->_currentStatusResponse()); + $this->_currentStatusResponse() + ); break; default: return $this->throwError('Internal error - ' - .'unknown response from' - .'stream_socket_enable_crypto()', - $response, $this->_currentStatusResponse()); + . 'unknown response from' + . 'stream_socket_enable_crypto()', + $response, $this->_currentStatusResponse() + ); } break; case 580: // RFC4642: 'can not initiate TLS negotiation' return $this->throwError('', $response, - $this->_currentStatusResponse()); + $this->_currentStatusResponse() + ); break; default: @@ -860,7 +904,7 @@ class Net_NNTP_Protocol_Client extends PEAR // }}} -/* Article posting and retrieval */ + /* Article posting and retrieval */ /* Group and article selection */ @@ -875,8 +919,9 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access protected */ - function cmdGroup($newsgroup) { - $response = $this->_sendCommand('GROUP '.$newsgroup); + function cmdGroup($newsgroup) + { + $response = $this->_sendCommand('GROUP ' . $newsgroup); if ($this->isError($response)) { return $response; } @@ -885,23 +930,27 @@ class Net_NNTP_Protocol_Client extends PEAR // 211, RFC977: 'n f l s group selected' case NET_NNTP_PROTOCOL_RESPONSECODE_GROUP_SELECTED: $response_arr = explode(' ', - trim($this->_currentStatusResponse())); + trim($this->_currentStatusResponse()) + ); if ($this->_logger) { $this->_logger->info('Group selected: ' - .$response_arr[3]); + . $response_arr[3] + ); } return array('group' => $response_arr[3], 'first' => $response_arr[1], 'last' => $response_arr[2], - 'count' => $response_arr[0]); + 'count' => $response_arr[0] + ); break; // 411, RFC977: 'no such news group' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_SUCH_GROUP: return $this->throwError('No such news group on server', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -922,7 +971,8 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access protected */ - function cmdListgroup($newsgroup = null, $range = null) { + function cmdListgroup($newsgroup = null, $range = null) + { if (is_null($newsgroup)) { $command = 'LISTGROUP'; } else { @@ -934,7 +984,7 @@ class Net_NNTP_Protocol_Client extends PEAR } $response = $this->_sendCommand($command); - if ($this->isError($response)){ + if ($this->isError($response)) { return $response; } @@ -948,7 +998,8 @@ class Net_NNTP_Protocol_Client extends PEAR } $response_arr = explode(' ', - trim($this->_currentStatusResponse()), 4); + trim($this->_currentStatusResponse()), 4 + ); /* If server does not return group summary in * status response, return null'ed array @@ -956,31 +1007,36 @@ class Net_NNTP_Protocol_Client extends PEAR if (!is_numeric($response_arr[0]) || !is_numeric($response_arr[1]) || !is_numeric($response_arr[2]) || - empty($response_arr[3])) { + empty($response_arr[3]) + ) { return array('group' => null, - 'first' => null, - 'last' => null, - 'count' => null, - 'articles' => $articles); + 'first' => null, + 'last' => null, + 'count' => null, + 'articles' => $articles + ); } return array('group' => $response_arr[3], 'first' => $response_arr[1], 'last' => $response_arr[2], 'count' => $response_arr[0], - 'articles' => $articles); + 'articles' => $articles + ); break; // 412, RFC2980: 'Not currently in newsgroup' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_GROUP_SELECTED: return $this->throwError('Not currently in newsgroup', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // RFC2980: 'no permission' case 502: return $this->throwError('No permission', $response, - $this->_currentStatusResponse()); + $this->_currentStatusResponse() + ); break; default: @@ -998,7 +1054,8 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access protected */ - function cmdLast() { + function cmdLast() + { // $response = $this->_sendCommand('LAST'); if ($this->isError($response)) { @@ -1011,32 +1068,37 @@ class Net_NNTP_Protocol_Client extends PEAR */ case NET_NNTP_PROTOCOL_RESPONSECODE_ARTICLE_SELECTED: $response_arr = explode(' ', - trim($this->_currentStatusResponse())); + trim($this->_currentStatusResponse()) + ); if ($this->_logger) { $this->_logger->info('Selected previous article: ' . - $response_arr[0] .' - '. $response_arr[1]); + $response_arr[0] . ' - ' . $response_arr[1] + ); } - return array($response_arr[0], (string) $response_arr[1]); + return array($response_arr[0], (string)$response_arr[1]); break; // 412, RFC977: 'no newsgroup selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_GROUP_SELECTED: return $this->throwError('No newsgroup has been selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 420, RFC977: 'no current article has been selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_ARTICLE_SELECTED: return $this->throwError('No current article has been selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 422, RFC977: 'no previous article in this group' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_PREVIOUS_ARTICLE: return $this->throwError('No previous article in this group', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -1054,7 +1116,8 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access protected */ - function cmdNext() { + function cmdNext() + { // $response = $this->_sendCommand('NEXT'); if ($this->isError($response)) { @@ -1067,32 +1130,37 @@ class Net_NNTP_Protocol_Client extends PEAR */ case NET_NNTP_PROTOCOL_RESPONSECODE_ARTICLE_SELECTED: $response_arr = explode(' ', - trim($this->_currentStatusResponse())); + trim($this->_currentStatusResponse()) + ); if ($this->_logger) { $this->_logger->info('Selected previous article: ' . - $response_arr[0] .' - '. $response_arr[1]); + $response_arr[0] . ' - ' . $response_arr[1] + ); } - return array($response_arr[0], (string) $response_arr[1]); + return array($response_arr[0], (string)$response_arr[1]); break; // 412, RFC977: 'no newsgroup selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_GROUP_SELECTED: return $this->throwError('No newsgroup has been selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 420, RFC977: 'no current article has been selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_ARTICLE_SELECTED: return $this->throwError('No current article has been selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 421, RFC977: 'no next article in this group' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_NEXT_ARTICLE: return $this->throwError('No next article in this group', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -1110,13 +1178,14 @@ class Net_NNTP_Protocol_Client extends PEAR * Get an article from the currently open connection. * * @param mixed $article Either a message-id or a message-number - * of the article to fetch. If null or '', then use current article. + * of the article to fetch. If null or '', then use current article. * * @return mixed (array) article on success or * (object) pear_error on failure * @access protected */ - function cmdArticle($article = null) { + function cmdArticle($article = null) + { if (is_null($article)) { $command = 'ARTICLE'; } else { @@ -1141,34 +1210,40 @@ class Net_NNTP_Protocol_Client extends PEAR if ($this->_logger) { $this->_logger->info(($article == null ? - 'Fetched current article' : 'Fetched article: '. - $article)); + 'Fetched current article' : 'Fetched article: ' . + $article) + ); } + return $data; break; // 412, RFC977: 'no newsgroup has been selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_GROUP_SELECTED: return $this->throwError('No newsgroup has been selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 420, RFC977: 'no current article has been selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_ARTICLE_SELECTED: return $this->throwError('No current article has been selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 423, RFC977: 'no such article number in this group' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_SUCH_ARTICLE_NUMBER: return $this->throwError('No such article number in this group', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 430, RFC977: 'no such article found' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_SUCH_ARTICLE_ID: return $this->throwError('No such article found', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -1183,14 +1258,15 @@ class Net_NNTP_Protocol_Client extends PEAR * Get the headers of an article from the currently open connection. * * @param mixed $article Either a message-id or a message-number - * of the article to fetch the headers from. If null or '', - * then use current article. + * of the article to fetch the headers from. If null or '', + * then use current article. * * @return mixed (array) headers on success or * (object) pear_error on failure * @access protected */ - function cmdHead($article = null) { + function cmdHead($article = null) + { if (is_null($article)) { $command = 'HEAD'; } else { @@ -1213,8 +1289,9 @@ class Net_NNTP_Protocol_Client extends PEAR if ($this->_logger) { $this->_logger->info(($article == null ? - 'Fetched current article header' : 'Fetched ' - .'article header for article: '.$article)); + 'Fetched current article header' : 'Fetched ' + . 'article header for article: ' . $article) + ); } return $data; @@ -1223,25 +1300,29 @@ class Net_NNTP_Protocol_Client extends PEAR // 412, RFC977: 'no newsgroup has been selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_GROUP_SELECTED: return $this->throwError('No newsgroup has been selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 420, RFC977: 'no current article has been selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_ARTICLE_SELECTED: return $this->throwError('No current article has been selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 423, RFC977: 'no such article number in this group' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_SUCH_ARTICLE_NUMBER: return $this->throwError('No such article number in this group', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 430, RFC977: 'no such article found' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_SUCH_ARTICLE_ID: return $this->throwError('No such article found', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -1256,14 +1337,15 @@ class Net_NNTP_Protocol_Client extends PEAR * Get the body of an article from the currently open connection. * * @param mixed $article Either a message-id or a message-number of - * the article to fetch the body from. If null or '', - * then use current article. + * the article to fetch the body from. If null or '', + * then use current article. * * @return mixed (array) body on success or * (object) pear_error on failure * @access protected */ - function cmdBody($article = null) { + function cmdBody($article = null) + { if (is_null($article)) { $command = 'BODY'; } else { @@ -1286,8 +1368,9 @@ class Net_NNTP_Protocol_Client extends PEAR if ($this->_logger) { $this->_logger->info(($article == null ? - 'Fetched current article body' : 'Fetched ' - .'article body for article: '.$article)); + 'Fetched current article body' : 'Fetched ' + . 'article body for article: ' . $article) + ); } return $data; @@ -1296,25 +1379,29 @@ class Net_NNTP_Protocol_Client extends PEAR // 412, RFC977: 'no newsgroup has been selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_GROUP_SELECTED: return $this->throwError('No newsgroup has been selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 420, RFC977: 'no current article has been selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_ARTICLE_SELECTED: return $this->throwError('No current article has been selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 423, RFC977: 'no such article number in this group' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_SUCH_ARTICLE_NUMBER: return $this->throwError('No such article number in this group', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 430, RFC977: 'no such article found' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_SUCH_ARTICLE_ID: return $this->throwError('No such article found', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -1334,7 +1421,8 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access protected */ - function cmdStat($article = null) { + function cmdStat($article = null) + { if (is_null($article)) { $command = 'STAT'; } else { @@ -1354,14 +1442,16 @@ class Net_NNTP_Protocol_Client extends PEAR */ case NET_NNTP_PROTOCOL_RESPONSECODE_ARTICLE_SELECTED: $response_arr = explode(' ', - trim($this->_currentStatusResponse())); + trim($this->_currentStatusResponse()) + ); if ($this->_logger) { $this->_logger->info('Selected article: ' . - $response_arr[0].' - '.$response_arr[1]); + $response_arr[0] . ' - ' . $response_arr[1] + ); } - return array($response_arr[0], (string) $response_arr[1]); + return array($response_arr[0], (string)$response_arr[1]); break; /* 412, RFC977: 'no newsgroup has been selected' @@ -1370,7 +1460,8 @@ class Net_NNTP_Protocol_Client extends PEAR */ case NET_NNTP_PROTOCOL_RESPONSECODE_NO_GROUP_SELECTED: return $this->throwError('No newsgroup has been selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; /* 423, RFC977: 'no such article number in this group' @@ -1379,7 +1470,8 @@ class Net_NNTP_Protocol_Client extends PEAR */ case NET_NNTP_PROTOCOL_RESPONSECODE_NO_SUCH_ARTICLE_NUMBER: return $this->throwError('No such article number in this group', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; /* 430, RFC977: 'no such article found' (actually not @@ -1387,7 +1479,8 @@ class Net_NNTP_Protocol_Client extends PEAR */ case NET_NNTP_PROTOCOL_RESPONSECODE_NO_SUCH_ARTICLE_ID: return $this->throwError('No such article found', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -1407,7 +1500,8 @@ class Net_NNTP_Protocol_Client extends PEAR * @return mixed (bool) true on success or (object) pear_error on failure * @access protected */ - function cmdPost() { + function cmdPost() + { // tell the newsserver we want to post an article $response = $this->_sendCommand('POST'); if ($this->isError($response)) { @@ -1423,7 +1517,8 @@ class Net_NNTP_Protocol_Client extends PEAR // 440, RFC977: 'posting not allowed' case NET_NNTP_PROTOCOL_RESPONSECODE_POSTING_PROHIBITED: return $this->throwError('Posting not allowed', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: return $this->_handleUnexpectedResponse($response); @@ -1443,7 +1538,8 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access protected */ - function cmdPost2($article) { + function cmdPost2($article) + { /* should be presented in the format specified by RFC850 */ // @@ -1464,7 +1560,8 @@ class Net_NNTP_Protocol_Client extends PEAR // 441, RFC977: 'posting failed' case NET_NNTP_PROTOCOL_RESPONSECODE_POSTING_FAILURE: return $this->throwError('Posting failed', $response, - $this->_currentStatusResponse()); + $this->_currentStatusResponse() + ); break; default: @@ -1484,7 +1581,8 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access protected */ - function cmdIhave($id) { + function cmdIhave($id) + { // tell the newsserver we want to post an article $response = $this->_sendCommand('IHAVE ' . $id); if ($this->isError($response)) { @@ -1498,13 +1596,15 @@ class Net_NNTP_Protocol_Client extends PEAR case NET_NNTP_PROTOCOL_RESPONSECODE_TRANSFER_UNWANTED: // 435 return $this->throwError('Article not wanted', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; case NET_NNTP_PROTOCOL_RESPONSECODE_TRANSFER_FAILURE: // 436 return $this->throwError ('Transfer not possible; try again later', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -1523,7 +1623,8 @@ class Net_NNTP_Protocol_Client extends PEAR * @return mixed (bool) true on success or (object) pear_error on failure * @access protected */ - function cmdIhave2($article) { + function cmdIhave2($article) + { /* should be presented in the format specified by RFC850 */ // @@ -1543,13 +1644,15 @@ class Net_NNTP_Protocol_Client extends PEAR case NET_NNTP_PROTOCOL_RESPONSECODE_TRANSFER_FAILURE: // 436 return $this->throwError ('Transfer not possible; try again later', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; case NET_NNTP_PROTOCOL_RESPONSECODE_TRANSFER_REJECTED: // 437 return $this->throwError ('Transfer rejected; do not retry', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -1559,7 +1662,7 @@ class Net_NNTP_Protocol_Client extends PEAR // }}} -/* Information commands */ + /* Information commands */ // {{{ cmdDate() @@ -1570,9 +1673,10 @@ class Net_NNTP_Protocol_Client extends PEAR * success or (object) pear_error on failure * @access protected */ - function cmdDate() { + function cmdDate() + { $response = $this->_sendCommand('DATE'); - if ($this->isError($response)){ + if ($this->isError($response)) { return $response; } @@ -1596,7 +1700,8 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access protected */ - function cmdHelp() { + function cmdHelp() + { // tell the newsserver we want an article $response = $this->_sendCommand('HELP'); if ($this->isError($response)) { @@ -1609,6 +1714,7 @@ class Net_NNTP_Protocol_Client extends PEAR if ($this->isError($data)) { return $data; } + return $data; break; @@ -1623,14 +1729,15 @@ class Net_NNTP_Protocol_Client extends PEAR /** * Fetches a list of all newsgroups created since a specified date. * - * @param int $time Last time you checked for groups (timestamp). - * @param optional string $distributions (deprecaded in rfc draft) + * @param int $time Last time you checked for groups (timestamp). + * @param optional string $distributions (deprecaded in rfc draft) * * @return mixed (array) nested array with informations about * existing newsgroups on success or (object) pear_error on failure * @access protected */ - function cmdNewgroups($time, $distributions = null) { + function cmdNewgroups($time, $distributions = null) + { $date = gmdate('ymd His', $time); if (is_null($distributions)) { @@ -1641,7 +1748,7 @@ class Net_NNTP_Protocol_Client extends PEAR } $response = $this->_sendCommand($command); - if ($this->isError($response)){ + if ($this->isError($response)) { return $response; } @@ -1654,16 +1761,18 @@ class Net_NNTP_Protocol_Client extends PEAR } $groups = array(); - foreach($data as $line) { + foreach ($data as $line) { $arr = explode(' ', trim($line)); - $group = array('group' => $arr[0], - 'last' => $arr[1], - 'first' => $arr[2], - 'posting' => $arr[3]); + $group = array('group' => $arr[0], + 'last' => $arr[1], + 'first' => $arr[2], + 'posting' => $arr[3] + ); $groups[$group['group']] = $group; } + return $groups; default: @@ -1678,13 +1787,14 @@ class Net_NNTP_Protocol_Client extends PEAR * * * @param timestamp $time - * @param mixed $newsgroups (string or array of strings) - * @param mixed $distribution (string or array of strings) + * @param mixed $newsgroups (string or array of strings) + * @param mixed $distribution (string or array of strings) * * @return mixed * @access protected */ - function cmdNewnews($time, $newsgroups, $distribution = null) { + function cmdNewnews($time, $newsgroups, $distribution = null) + { $date = gmdate('ymd His', $time); if (is_array($newsgroups)) { @@ -1695,7 +1805,7 @@ class Net_NNTP_Protocol_Client extends PEAR $command = 'NEWNEWS ' . $newsgroups . ' ' . $date . ' GMT'; } else { if (is_array($distribution)) { - $distribution = implode(',', $distribution); + $distribution = implode(',', $distribution); } $command = 'NEWNEWS ' . $newsgroups . ' ' . $date . ' GMT <' @@ -1705,7 +1815,7 @@ class Net_NNTP_Protocol_Client extends PEAR // TODO: the lenght of the request string may not exceed 510 chars $response = $this->_sendCommand($command); - if ($this->isError($response)){ + if ($this->isError($response)) { return $response; } @@ -1713,9 +1823,10 @@ class Net_NNTP_Protocol_Client extends PEAR // 230, RFC977: 'list of new articles by message-id follows' case NET_NNTP_PROTOCOL_RESPONSECODE_NEW_ARTICLES_FOLLOW: $messages = array(); - foreach($this->_getTextResponse() as $line) { + foreach ($this->_getTextResponse() as $line) { $messages[] = $line; } + return $messages; break; @@ -1737,9 +1848,10 @@ class Net_NNTP_Protocol_Client extends PEAR * existing newsgroups on success or (object) pear_error on failure * @access protected */ - function cmdList() { + function cmdList() + { $response = $this->_sendCommand('LIST'); - if ($this->isError($response)){ + if ($this->isError($response)) { return $response; } @@ -1752,16 +1864,18 @@ class Net_NNTP_Protocol_Client extends PEAR } $groups = array(); - foreach($data as $line) { + foreach ($data as $line) { $arr = explode(' ', trim($line)); - $group = array('group' => $arr[0], - 'last' => $arr[1], - 'first' => $arr[2], - 'posting' => $arr[3]); + $group = array('group' => $arr[0], + 'last' => $arr[1], + 'first' => $arr[2], + 'posting' => $arr[3] + ); $groups[$group['group']] = $group; } + return $groups; break; @@ -1782,7 +1896,8 @@ class Net_NNTP_Protocol_Client extends PEAR * existing newsgroups on success or (object) pear_error on failure * @access protected */ - function cmdListActive($wildmat = null) { + function cmdListActive($wildmat = null) + { if (is_null($wildmat)) { $command = 'LIST ACTIVE'; } else { @@ -1790,7 +1905,7 @@ class Net_NNTP_Protocol_Client extends PEAR } $response = $this->_sendCommand($command); - if ($this->isError($response)){ + if ($this->isError($response)) { return $response; } @@ -1803,13 +1918,14 @@ class Net_NNTP_Protocol_Client extends PEAR } $groups = array(); - foreach($data as $line) { + foreach ($data as $line) { $arr = explode(' ', trim($line)); - $group = array('group' => $arr[0], - 'last' => $arr[1], - 'first' => $arr[2], - 'posting' => $arr[3]); + $group = array('group' => $arr[0], + 'last' => $arr[1], + 'first' => $arr[2], + 'posting' => $arr[3] + ); $groups[$group['group']] = $group; } @@ -1832,14 +1948,15 @@ class Net_NNTP_Protocol_Client extends PEAR /** * Fetches a list of (all) avaible newsgroup descriptions. * - * @param string $wildmat Wildmat of the groups, that is to be + * @param string $wildmat Wildmat of the groups, that is to be * listed, defaults to null; * * @return mixed (array) nested array with description of existing * newsgroups on success or (object) pear_error on failure * @access protected */ - function cmdListNewsgroups($wildmat = null) { + function cmdListNewsgroups($wildmat = null) + { if (is_null($wildmat)) { $command = 'LIST NEWSGROUPS'; } else { @@ -1847,7 +1964,7 @@ class Net_NNTP_Protocol_Client extends PEAR } $response = $this->_sendCommand($command); - if ($this->isError($response)){ + if ($this->isError($response)) { return $response; } @@ -1861,14 +1978,17 @@ class Net_NNTP_Protocol_Client extends PEAR $groups = array(); - foreach($data as $line) { + foreach ($data as $line) { if (preg_match("/^(\S+)\s+(.*)$/", ltrim($line), - $matches)) { - $groups[$matches[1]] = (string) $matches[2]; + $matches + ) + ) { + $groups[$matches[1]] = (string)$matches[2]; } else { if ($this->_logger) { $this->_logger->warning - ("Recieved non-standard line: '$line'"); + ("Recieved non-standard line: '$line'" + ); } } } @@ -1878,13 +1998,14 @@ class Net_NNTP_Protocol_Client extends PEAR } return $groups; - break; + break; // RFC2980: 'program error, function not performed' case 503: return $this->throwError ('Internal server error, function not performed', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -1894,7 +2015,7 @@ class Net_NNTP_Protocol_Client extends PEAR // }}} -/* Article field access commands */ + /* Article field access commands */ // {{{ cmdOver() @@ -1910,15 +2031,16 @@ class Net_NNTP_Protocol_Client extends PEAR * on success or (object) pear_error on failure * @access protected */ - function cmdOver($range = null) { + function cmdOver($range = null) + { if (is_null($range)) { - $command = 'OVER'; + $command = 'OVER'; } else { $command = 'OVER ' . $range; } $response = $this->_sendCommand($command); - if ($this->isError($response)){ + if ($this->isError($response)) { return $response; } @@ -1937,7 +2059,8 @@ class Net_NNTP_Protocol_Client extends PEAR if ($this->_logger) { $this->_logger->info('Fetched overview ' . ($range == null ? - 'for current article' : 'for range: '.$range)); + 'for current article' : 'for range: ' . $range) + ); } return $data; @@ -1946,25 +2069,29 @@ class Net_NNTP_Protocol_Client extends PEAR // 412, RFC2980: 'No news group current selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_GROUP_SELECTED: return $this->throwError('No news group current selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 420, RFC2980: 'No article(s) selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_ARTICLE_SELECTED: return $this->throwError('No article(s) selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 423:, Draft27: 'No articles in that range' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_SUCH_ARTICLE_NUMBER: return $this->throwError('No articles in that range', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // RFC2980: 'no permission' case 502: return $this->throwError('No permission', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -1987,21 +2114,22 @@ class Net_NNTP_Protocol_Client extends PEAR * on success or (object) pear_error on failure * @access protected */ - function cmdXOver($range = null) { + function cmdXOver($range = null) + { // deprecated API (the code _is_ still in alpha state) - if (func_num_args() > 1 ) { + if (func_num_args() > 1) { die('The second parameter in cmdXOver() has been ' - .'deprecated! Use x-y instead...'); + . 'deprecated! Use x-y instead...'); } if (is_null($range)) { - $command = 'XOVER'; + $command = 'XOVER'; } else { $command = 'XOVER ' . $range; } $response = $this->_sendCommand($command); - if ($this->isError($response)){ + if ($this->isError($response)) { return $response; } @@ -2020,7 +2148,8 @@ class Net_NNTP_Protocol_Client extends PEAR if ($this->_logger) { $this->_logger->info('Fetched overview ' . ($range == null ? - 'for current article' : 'for range: '.$range)); + 'for current article' : 'for range: ' . $range) + ); } return $data; @@ -2029,19 +2158,22 @@ class Net_NNTP_Protocol_Client extends PEAR // 412, RFC2980: 'No news group current selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_GROUP_SELECTED: return $this->throwError('No news group current selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 420, RFC2980: 'No article(s) selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_ARTICLE_SELECTED: return $this->throwError('No article(s) selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // RFC2980: 'no permission' case 502: return $this->throwError('No permission', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -2060,9 +2192,10 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access protected */ - function cmdListOverviewFmt() { + function cmdListOverviewFmt() + { $response = $this->_sendCommand('LIST OVERVIEW.FMT'); - if ($this->isError($response)){ + if ($this->isError($response)) { return $response; } @@ -2085,12 +2218,13 @@ class Net_NNTP_Protocol_Client extends PEAR } else { // ':' is _not_ included in tag; value set to false $format[substr($line, 0, -1)] = false; - } + } } if ($this->_logger) { $this->_logger->info('Fetched overview format'); } + return $format; break; @@ -2098,7 +2232,8 @@ class Net_NNTP_Protocol_Client extends PEAR case 503: return $this->throwError ('Internal server error, function not performed', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -2122,15 +2257,16 @@ class Net_NNTP_Protocol_Client extends PEAR * on success or (object) pear_error on failure * @access protected */ - function cmdXHdr($field, $range = null) { + function cmdXHdr($field, $range = null) + { if (is_null($range)) { - $command = 'XHDR ' . $field; + $command = 'XHDR ' . $field; } else { $command = 'XHDR ' . $field . ' ' . $range; } $response = $this->_sendCommand($command); - if ($this->isError($response)){ + if ($this->isError($response)) { return $response; } @@ -2143,7 +2279,7 @@ class Net_NNTP_Protocol_Client extends PEAR } $return = array(); - foreach($data as $line) { + foreach ($data as $line) { $line = explode(' ', trim($line), 2); $return[$line[0]] = $line[1]; } @@ -2154,25 +2290,29 @@ class Net_NNTP_Protocol_Client extends PEAR // 412, RFC2980: 'No news group current selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_GROUP_SELECTED: return $this->throwError('No news group current selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 420, RFC2980: 'No current article selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_ARTICLE_SELECTED: return $this->throwError('No current article selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 430, RFC2980: 'No such article' case 430: return $this->throwError('No such article', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // RFC2980: 'no permission' case 502: return $this->throwError('No permission', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -2188,15 +2328,16 @@ class Net_NNTP_Protocol_Client extends PEAR * Depresated as of RFC2980. * * @param string $wildmat Wildmat of the groups, that is - * to be listed, defaults to '*'; + * to be listed, defaults to '*'; * * @return mixed (array) nested array with description of * existing newsgroups on success or (object) pear_error on failure * @access protected */ - function cmdXGTitle($wildmat = '*') { - $response = $this->_sendCommand('XGTITLE '.$wildmat); - if ($this->isError($response)){ + function cmdXGTitle($wildmat = '*') + { + $response = $this->_sendCommand('XGTITLE ' . $wildmat); + if ($this->isError($response)) { return $response; } @@ -2210,9 +2351,9 @@ class Net_NNTP_Protocol_Client extends PEAR $groups = array(); - foreach($data as $line) { + foreach ($data as $line) { preg_match("/^(.*?)\s(.*?$)/", trim($line), $matches); - $groups[$matches[1]] = (string) $matches[2]; + $groups[$matches[1]] = (string)$matches[2]; } return $groups; @@ -2221,7 +2362,8 @@ class Net_NNTP_Protocol_Client extends PEAR case 481: // RFC2980: 'Groups and descriptions unavailable' return $this->throwError ('Groups and descriptions unavailable', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; default: @@ -2241,11 +2383,12 @@ class Net_NNTP_Protocol_Client extends PEAR * success or (object) pear_error on failure * @access protected */ - function cmdXROver($range = null) { + function cmdXROver($range = null) + { // Warn about deprecated API (the code _is_ still in alpha state) - if (func_num_args() > 1 ) { + if (func_num_args() > 1) { die('The second parameter in cmdXROver() has been ' - .'deprecated! Use x-y instead...'); + . 'deprecated! Use x-y instead...'); } if (is_null($range)) { @@ -2255,7 +2398,7 @@ class Net_NNTP_Protocol_Client extends PEAR } $response = $this->_sendCommand($command); - if ($this->isError($response)){ + if ($this->isError($response)) { return $response; } @@ -2268,29 +2411,33 @@ class Net_NNTP_Protocol_Client extends PEAR } $return = array(); - foreach($data as $line) { + foreach ($data as $line) { $line = explode(' ', trim($line), 2); $return[$line[0]] = $line[1]; } + return $return; break; // 412, RFC2980: 'No news group current selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_GROUP_SELECTED: return $this->throwError('No news group current selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // 420, RFC2980: 'No article(s) selected' case NET_NNTP_PROTOCOL_RESPONSECODE_NO_ARTICLE_SELECTED: return $this->throwError('No article(s) selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; // RFC2980: 'no permission' case 502: return $this->throwError('No permission', $response, - $this->_currentStatusResponse()); + $this->_currentStatusResponse() + ); break; default: @@ -2306,20 +2453,22 @@ class Net_NNTP_Protocol_Client extends PEAR * * @param string $field * @param string $range - * @param mixed $wildmat + * @param mixed $wildmat * * @return mixed (array) nested array of message and there * headers on success or (object) pear_error on failure * @access protected */ - function cmdXPat($field, $range, $wildmat) { + function cmdXPat($field, $range, $wildmat) + { if (is_array($wildmat)) { - $wildmat = implode(' ', $wildmat); + $wildmat = implode(' ', $wildmat); } $response = $this->_sendCommand('XPAT ' . $field . ' ' . - $range . ' ' . $wildmat); - if ($this->isError($response)){ + $range . ' ' . $wildmat + ); + if ($this->isError($response)) { return $response; } @@ -2331,7 +2480,7 @@ class Net_NNTP_Protocol_Client extends PEAR } $return = array(); - foreach($data as $line) { + foreach ($data as $line) { $line = explode(' ', trim($line), 2); $return[$line[0]] = $line[1]; } @@ -2341,12 +2490,14 @@ class Net_NNTP_Protocol_Client extends PEAR case 430: // 430, RFC2980: 'No such article' return $this->throwError('No current article selected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; case 502: // RFC2980: 'no permission' return $this->throwError('No permission', $response, - $this->_currentStatusResponse()); + $this->_currentStatusResponse() + ); break; default: @@ -2367,9 +2518,10 @@ class Net_NNTP_Protocol_Client extends PEAR * (object) pear_error on failure * @access protected */ - function cmdAuthinfo($user, $pass) { + function cmdAuthinfo($user, $pass) + { // Send the username - $response = $this->_sendCommand('AUTHINFO user '.$user); + $response = $this->_sendCommand('AUTHINFO user ' . $user); if ($this->isError($response)) { return $response; } @@ -2377,7 +2529,7 @@ class Net_NNTP_Protocol_Client extends PEAR // Send the password, if the server asks if (($response == 381) && ($pass !== null)) { // Send the password - $response = $this->_sendCommand('AUTHINFO pass '.$pass); + $response = $this->_sendCommand('AUTHINFO pass ' . $pass); if ($this->isError($response)) { return $response; } @@ -2396,17 +2548,20 @@ class Net_NNTP_Protocol_Client extends PEAR case 381: // RFC2980: 'More authentication information required' return $this->throwError('Authentication uncompleted', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; case 482: // RFC2980: 'Authentication rejected' return $this->throwError('Authentication rejected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; case 502: // RFC2980: 'No permission' return $this->throwError('Authentication rejected', - $response, $this->_currentStatusResponse()); + $response, $this->_currentStatusResponse() + ); break; /*case 500: @@ -2431,10 +2586,12 @@ class Net_NNTP_Protocol_Client extends PEAR * @return mixed (bool) true on success or (object) pear_error on failure * @access protected */ - function cmdAuthinfoSimple($user, $pass) { + function cmdAuthinfoSimple($user, $pass) + { return $this->throwError ("The auth mode: 'simple' is has not been implemented yet", - null); + null + ); } // }}} @@ -2449,10 +2606,12 @@ class Net_NNTP_Protocol_Client extends PEAR * @return mixed (bool) true on success or (object) pear_error on failure * @access protected */ - function cmdAuthinfoGeneric($user, $pass) { + function cmdAuthinfoGeneric($user, $pass) + { return $this->throwError ("The auth mode: 'generic' is has not been implemented yet", - null); + null + ); } // }}} @@ -2464,7 +2623,8 @@ class Net_NNTP_Protocol_Client extends PEAR * @return bool true or false * @access protected */ - function _isConnected() { + function _isConnected() + { return (is_resource($this->_socket) && (!feof($this->_socket))); } @@ -2481,5 +2641,3 @@ class Net_NNTP_Protocol_Client extends PEAR * c-hanging-comment-ender-p: nil * End: */ - -?> diff --git a/lib/copy_this/www/lib/Tmux.php b/lib/copy_this/www/lib/Tmux.php index 191969212..3d2e9ad5b 100644 --- a/lib/copy_this/www/lib/Tmux.php +++ b/lib/copy_this/www/lib/Tmux.php @@ -1,6 +1,6 @@ get(); + return $site->version; } @@ -55,6 +56,7 @@ class Tmux } $obj->{'version'} = $this->version(); + return $obj; } @@ -73,7 +75,7 @@ class Tmux { $db = $this->db; $sql = sprintf("UPDATE tmux SET value = %s WHERE setting = %s", $db->escapeString($value), $db->escapeString($setting)); + return $db->exec($sql); } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/lib/copy_this/www/lib/nntp.php b/lib/copy_this/www/lib/nntp.php index 0ce266710..f51df1b52 100644 --- a/lib/copy_this/www/lib/nntp.php +++ b/lib/copy_this/www/lib/nntp.php @@ -433,7 +433,7 @@ class NNTP extends Net_NNTP_Client * * @param string $groupName The name of the group the articles are in. * @param array|string|int $identifiers Message-ID(string) or article number(int), or array containing M-ID's or A-Numbers. - * + * * * @return string On success : The article bodies. * @return object On failure : Pear error. @@ -981,15 +981,17 @@ class NNTP extends Net_NNTP_Client /** * Decode a string of text encoded with yEnc. * - * @note For usage outside of this class, please use the YEnc library. + * @note For usage outside of this class, please use the YEnc library. * - * @param string $string The encoded text to decode. + * @param $data + * + * @internal param string $string The encoded text to decode. * * @return string The decoded yEnc string, or the input, if it's not yEnc. * - * @access protected + * @access protected * - * @TODO: ? Maybe this function should be merged into the YEnc class? + * @TODO : ? Maybe this function should be merged into the YEnc class? */ protected function _decodeYEnc($data) { @@ -1325,15 +1327,18 @@ class NNTP extends Net_NNTP_Client } /** - * Fetch message header from message number $first until $last - * The format of the returned array is: - * $messages[message_id][header_name] - * @param optional string $range articles to fetch - * @return mixed (array) nested array of message and there headers on success or (object) pear_error on failure - * @access protected - */ - function cmdXZver($range = null) - { + * Fetch message header from message number $first until $last + * The format of the returned array is: + * $messages[message_id][header_name] + * + * @param null $range + * + * @internal param string $optional $range articles to fetch + * @return mixed (array) nested array of message and there headers on success or (object) pear_error on failure + * @access protected + */ + function cmdXZver($range = null) + { if (is_null($range)) $command = 'XZVER'; else diff --git a/lib/copy_this/www/templates/nntmux/scripts/utils.js b/lib/copy_this/www/templates/nntmux/scripts/utils.js index 0b7a09f9c..b7af5cce0 100644 --- a/lib/copy_this/www/templates/nntmux/scripts/utils.js +++ b/lib/copy_this/www/templates/nntmux/scripts/utils.js @@ -1,5 +1,5 @@ // event bindings -jQuery(function($){ +jQuery(function ($) { var vortexStates = Array(); vortexStates[0] = 'Waiting'; @@ -9,100 +9,96 @@ jQuery(function($){ vortexStates[4] = 'Saved'; vortexStates[5] = 'Skipped'; - //fix for autosizing plugin - $('.autosize').autosize({append: "\n"}); + //fix for autosizing plugin + $('.autosize').autosize({append: "\n"}); - // browse.tpl, search.tpl -- show icons on hover - var orig_opac = $('table.data tr').children('td.icons').children('div.icon').css('opacity'); - $('table.data tr').hover( - function(){ $(this).children('td.icons').children('div.icon').css('opacity',1); }, - function(){ $(this).children('td.icons').children('div.icon').css('opacity',orig_opac); } - ); - - $(".forumpostsubmit").click(function(e) { - if ($.trim($("#addMessage").val()) == "" || $.trim($("#addSubject").val()) == "") - { - alert ("Please enter a subject and message."); - return false; - } - }); - - $(".forumreplysubmit").click(function(e) { - if ($.trim($("#addReply").val()) == "") - { - alert ("Please enter a message."); - return false; - } - }); - - $(".check").click(function(e) { - if (!$(e.target).is('input')) - $(this).children(".nzb_check").attr('checked', !$(this).children(".nzb_check").attr('checked')); - }); - - $(".descmore").click(function(e) { - $(this).prev(".descinitial").hide(); - $(this).next(".descfull").show(); - $(this).hide(); - return false; - }); - - $('.nzb_check_all').change(function(){ - if($(this).attr('checked')) - { - $('table.data tr td input:checkbox').attr('checked',$(this).attr('checked')); - } else { - $('table.data tr td input:checkbox').removeAttr('checked'); - } - }); - - $('.nzb_check_all_season').change(function(){ - var season = $(this).attr('name'); - $('table.data tr td input:checkbox').each( function(i, row) { - if ($(row).attr('name') == season) { - $(row).attr('checked', !$(row).attr('checked')); - } - }); - }); - - // browse.tpl, search.tpl - $('.icon_cart').click(function(e){ - if ($(this).hasClass('icon_cart_clicked')) return false; - var guid = $(this).parent().parent().attr('id').substring(4); - $.post( SERVERROOT + "cart?add=" + guid, function(resp){ - $(e.target).addClass('icon_cart_clicked').attr('title','Added to Cart'); - createGrowl( 'Added to Cart' ); - }); - return false; - }); - - $('.icon_nzbvortex').click(function(event) - { - if ($(this).hasClass('icon_nzbvortex_clicked')) return false; - var guid = $(this).parent().parent().attr('id').substring(4); - - if (guid && guid.length > 0) - { - $.ajax - ({ - url: SERVERROOT + '/nzbvortex?addQueue='+ guid +'&isAjax', - cache: false - }).done(function(html) - { - var message = 'Added ' + guid + ' to queue.'; - $(event.target).addClass('icon_nzbvortex_clicked').attr('title', message); - createGrowl(message); - }).fail(function(response) - { - alert(response.responseText); - }); + // browse.tpl, search.tpl -- show icons on hover + var orig_opac = $('table.data tr').children('td.icons').children('div.icon').css('opacity'); + $('table.data tr').hover( + function () { + $(this).children('td.icons').children('div.icon').css('opacity', 1); + }, + function () { + $(this).children('td.icons').children('div.icon').css('opacity', orig_opac); } - + ); + + $(".forumpostsubmit").click(function (e) { + if ($.trim($("#addMessage").val()) == "" || $.trim($("#addSubject").val()) == "") { + alert("Please enter a subject and message."); + return false; + } + }); + + $(".forumreplysubmit").click(function (e) { + if ($.trim($("#addReply").val()) == "") { + alert("Please enter a message."); + return false; + } + }); + + $(".check").click(function (e) { + if (!$(e.target).is('input')) + $(this).children(".nzb_check").attr('checked', !$(this).children(".nzb_check").attr('checked')); + }); + + $(".descmore").click(function (e) { + $(this).prev(".descinitial").hide(); + $(this).next(".descfull").show(); + $(this).hide(); return false; }); - $('a.vortex-resume').live('click', function(event) - { + $('.nzb_check_all').change(function () { + if ($(this).attr('checked')) { + $('table.data tr td input:checkbox').attr('checked', $(this).attr('checked')); + } else { + $('table.data tr td input:checkbox').removeAttr('checked'); + } + }); + + $('.nzb_check_all_season').change(function () { + var season = $(this).attr('name'); + $('table.data tr td input:checkbox').each(function (i, row) { + if ($(row).attr('name') == season) { + $(row).attr('checked', !$(row).attr('checked')); + } + }); + }); + + // browse.tpl, search.tpl + $('.icon_cart').click(function (e) { + if ($(this).hasClass('icon_cart_clicked')) return false; + var guid = $(this).parent().parent().attr('id').substring(4); + $.post(SERVERROOT + "cart?add=" + guid, function (resp) { + $(e.target).addClass('icon_cart_clicked').attr('title', 'Added to Cart'); + createGrowl('Added to Cart'); + }); + return false; + }); + + $('.icon_nzbvortex').click(function (event) { + if ($(this).hasClass('icon_nzbvortex_clicked')) return false; + var guid = $(this).parent().parent().attr('id').substring(4); + + if (guid && guid.length > 0) { + $.ajax + ({ + url: SERVERROOT + '/nzbvortex?addQueue=' + guid + '&isAjax', + cache: false + }).done(function (html) { + var message = 'Added ' + guid + ' to queue.'; + $(event.target).addClass('icon_nzbvortex_clicked').attr('title', message); + createGrowl(message); + }).fail(function (response) { + alert(response.responseText); + }); + } + + return false; + }); + + $('a.vortex-resume').live('click', function (event) { event.preventDefault(); $('#vortex-overlay-' + $(this).attr('href')).show(); $.get(SERVERROOT + "nzbvortex?resume=" + $(this).attr('href') + '&isAjax'); @@ -110,8 +106,7 @@ jQuery(function($){ return false; }); - $('a.vortex-pause').live('click', function(event) - { + $('a.vortex-pause').live('click', function (event) { event.preventDefault(); $('#vortex-overlay-' + $(this).attr('href')).show(); $.get(SERVERROOT + "nzbvortex?pause=" + $(this).attr('href') + '&isAjax'); @@ -119,8 +114,7 @@ jQuery(function($){ return false; }); - $('a.vortex-moveup').live('click', function(event) - { + $('a.vortex-moveup').live('click', function (event) { event.preventDefault(); $('#vortex-overlay-' + $(this).attr('href')).show(); $.get(SERVERROOT + "nzbvortex?moveup=" + $(this).attr('href') + '&isAjax'); @@ -128,8 +122,7 @@ jQuery(function($){ return false; }); - $('a.vortex-movedown').live('click', function(event) - { + $('a.vortex-movedown').live('click', function (event) { event.preventDefault(); $('#vortex-overlay-' + $(this).attr('href')).show(); $.get(SERVERROOT + "nzbvortex?movedown=" + $(this).attr('href') + '&isAjax'); @@ -137,17 +130,15 @@ jQuery(function($){ return false; }); - $('a.vortex-movetop').live('click', function(event) - { + $('a.vortex-movetop').live('click', function (event) { event.preventDefault(); $('#vortex-overlay-' + $(this).attr('href')).show(); $.get(SERVERROOT + "nzbvortex?movetop=" + $(this).attr('href') + '&isAjax'); $(this).removeAttr('href'); return false; }); - - $('a.vortex-movebottom').live('click', function(event) - { + + $('a.vortex-movebottom').live('click', function (event) { event.preventDefault(); $('#vortex-overlay-' + $(this).attr('href')).show(); $.get(SERVERROOT + "nzbvortex?movebottom=" + $(this).attr('href') + '&isAjax'); @@ -155,712 +146,763 @@ jQuery(function($){ return false; }); - $('a.vortex-trash').live('click', function(event) - { + $('a.vortex-trash').live('click', function (event) { event.preventDefault(); $('#vortex-overlay-' + $(this).attr('href')).show(); $.get(SERVERROOT + "nzbvortex?delete=" + $(this).attr('href') + '&isAjax'); $(this).removeAttr('href'); return false; }); - - $('a.vortex-filelist').live('click', function(event) - { + + $('a.vortex-filelist').live('click', function (event) { event.preventDefault(); var id = $(this).attr('href'); $('#vortex-overlay-' + id).show(); $.colorbox({}); - + $.ajax ({ - url: SERVERROOT + '/nzbvortex?filelist='+ id +'&isAjax', + url: SERVERROOT + '/nzbvortex?filelist=' + id + '&isAjax', cache: false - }).done(function(response) - { + }).done(function (response) { $('#cboxLoadingGraphic').hide(); var json = $.parseJSON(response); console.log(json); - $.each(json.files, function(k, v) - { + $.each(json.files, function (k, v) { - $('#cboxContent').append('' + v.fileName + ' ('+ vortexStates[v.state] +')
'); + $('#cboxContent').append('' + v.fileName + ' (' + vortexStates[v.state] + ')
'); }); - - }).fail(function(response) - { + + }).fail(function (response) { alert('Unable to retrieve filelist: ' + response.responseText); }); - + $(this).removeAttr('href'); return false; }); - - $('.icon_sab').click(function(e){ // replace with cookies? - if ($(this).hasClass('icon_sab_clicked')) return false; - var guid = $(this).parent().parent().attr('id').substring(4); - var nzburl = SERVERROOT + "sendtosab/" + guid; + $('.icon_sab').click(function (e) { // replace with cookies? + if ($(this).hasClass('icon_sab_clicked')) return false; - $.post(nzburl, function(resp){ - $(e.target).addClass('icon_sab_clicked').attr('title','Added to Queue'); - createGrowl( 'Added to Queue' ); - }); - return false; - }); - $("table.data a.modal_nfo").colorbox({ // NFO modal - href: function(){ return $(this).attr('href') +'&modal'; }, - title: function(){ return $(this).parent().parent().children('a.title').text(); }, - innerWidth:"800px", innerHeight:"90%", initialWidth:"800px", initialHeight:"90%", speed:0, opacity:0.7 - }); - // Screenshot modal - $("table.data a.modal_prev").colorbox({scrolling:false, maxWidth:"800px", maxHeight:"450px"}); - - $("table.data a.modal_imdb").colorbox({ // IMDB modal - href: function(){ return SERVERROOT + "movie/"+$(this).attr('name').substring(4)+'&modal'; }, - title: function(){ return $(this).parent().parent().children('a.title').text(); }, - innerWidth:"800px", innerHeight:"450px", initialWidth:"800px", initialHeight:"450px", speed:0, opacity:0.7 - }).click(function(){ - $('#colorbox').removeClass().addClass('cboxMovie'); - }); + var guid = $(this).parent().parent().attr('id').substring(4); + var nzburl = SERVERROOT + "sendtosab/" + guid; + + $.post(nzburl, function (resp) { + $(e.target).addClass('icon_sab_clicked').attr('title', 'Added to Queue'); + createGrowl('Added to Queue'); + }); + return false; + }); + $("table.data a.modal_nfo").colorbox({ // NFO modal + href: function () { + return $(this).attr('href') + '&modal'; + }, + title: function () { + return $(this).parent().parent().children('a.title').text(); + }, + innerWidth: "800px", innerHeight: "90%", initialWidth: "800px", initialHeight: "90%", speed: 0, opacity: 0.7 + }); + // Screenshot modal + $("table.data a.modal_prev").colorbox({scrolling: false, maxWidth: "800px", maxHeight: "450px"}); + + $("table.data a.modal_imdb").colorbox({ // IMDB modal + href: function () { + return SERVERROOT + "movie/" + $(this).attr('name').substring(4) + '&modal'; + }, + title: function () { + return $(this).parent().parent().children('a.title').text(); + }, + innerWidth: "800px", innerHeight: "450px", initialWidth: "800px", initialHeight: "450px", speed: 0, opacity: 0.7 + }).click(function () { + $('#colorbox').removeClass().addClass('cboxMovie'); + }); $("a.modal_imdbtrailer").colorbox({ // IMDB trailer modal - href: function(){ return SERVERROOT + "movietrailer/"+$(this).attr('name').substring(4)+'&modal'; }, - title: function(){ return $(this).parent().parent().children('a.title').text(); }, - innerWidth:"800px", innerHeight:"450px", initialWidth:"800px", initialHeight:"450px", speed:0, opacity:0.7 - }).click(function(){ - $('#colorbox').removeClass().addClass('cboxMovie'); + href: function () { + return SERVERROOT + "movietrailer/" + $(this).attr('name').substring(4) + '&modal'; + }, + title: function () { + return $(this).parent().parent().children('a.title').text(); + }, + innerWidth: "800px", innerHeight: "450px", initialWidth: "800px", initialHeight: "450px", speed: 0, opacity: 0.7 + }).click(function () { + $('#colorbox').removeClass().addClass('cboxMovie'); + }); + + + $("table.data a.modal_music").colorbox({ // Music modal + href: function () { + return SERVERROOT + "musicmodal/" + $(this).attr('name').substring(4) + '&modal'; + }, + title: function () { + return $(this).parent().parent().children('a.title').text(); + }, + innerWidth: "800px", innerHeight: "450px", initialWidth: "800px", initialHeight: "450px", speed: 0, opacity: 0.7 + }).click(function () { + $('#colorbox').removeClass().addClass('cboxMusic'); + }); + $("table.data a.modal_console").colorbox({ // Console modal + href: function () { + return SERVERROOT + "consolemodal/" + $(this).attr('name').substring(4) + '&modal'; + }, + title: function () { + return $(this).parent().parent().children('a.title').text(); + }, + innerWidth: "800px", innerHeight: "450px", initialWidth: "800px", initialHeight: "450px", speed: 0, opacity: 0.7 + }).click(function () { + $('#colorbox').removeClass().addClass('cboxConsole'); + }); + $("table.data a.modal_book").colorbox({ // Book modal + href: function () { + return SERVERROOT + "bookmodal/" + $(this).attr('name').substring(4) + '&modal'; + }, + title: function () { + return $(this).parent().parent().children('a.title').text(); + }, + innerWidth: "800px", innerHeight: "450px", initialWidth: "800px", initialHeight: "450px", speed: 0, opacity: 0.7 + }).click(function () { + $('#colorbox').removeClass().addClass('cboxBook'); + }); + + + $('#nzb_multi_operations_form').submit(function () { + return false; + }); + $('input.nzb_multi_operations_download').click(function () { + var newFormName = 'nzbmulti' + Math.round(+new Date() / 1000); + var newForm = $("
", {'action': SERVERROOT + 'getnzb?zip=1', 'method': 'post', 'target': '_top', 'id': newFormName}); + $("table.data INPUT[type='checkbox']:checked").each(function (i, row) { + if ($(row).val() != "on") + $("", {'name': 'id[]', 'value': $(row).val(), 'type': 'hidden'}).appendTo(newForm); + }); + newForm.appendTo($('body')); + $('#' + newFormName).submit(); + }); + $('input.nzb_multi_operations_cart').click(function () { + var guids = new Array(); + $("table.data INPUT[type='checkbox']:checked").each(function (i, row) { + var guid = $(row).val(); + var $cartIcon = $(row).parent().parent().children('td.icons').children('.icon_cart'); + if (guid && !$cartIcon.hasClass('icon_cart_clicked')) { + $cartIcon.addClass('icon_cart_clicked').attr('title', 'Added to Cart'); // consider doing this only upon success + guids.push(guid); + createGrowl('Added to Cart'); + } + $(this).attr('checked', false); + }); + $.post(SERVERROOT + "cart?add", { 'add': guids }); + }); + $('input.nzb_multi_operations_sab').click(function () { + $("table.data INPUT[type='checkbox']:checked").each(function (i, row) { + var $sabIcon = $(row).parent().parent().children('td.icons').children('.icon_sab'); + var guid = $(row).val(); + if (guid && !$sabIcon.hasClass('icon_sab_clicked')) { + var nzburl = SERVERROOT + "sendtosab/" + guid; + $.post(nzburl, function (resp) { + $sabIcon.addClass('icon_sab_clicked').attr('title', 'Added to Queue'); + createGrowl('Added to Queue'); + }); + } + $(this).attr('checked', false); + }); + }); + //front end admin functions + $('input.nzb_multi_operations_edit').click(function () { + var ids = ""; + $("table.data INPUT[type='checkbox']:checked").each(function (i, row) { + if ($(row).val() != "on") + ids += '&id[]=' + $(row).val(); + }); + if (ids) + $('input.nzb_multi_operations_edit').colorbox({ + href: function () { + return SERVERROOT + "ajax_release-admin?action=edit" + ids + "&from=" + encodeURIComponent(window.location); + }, + title: 'Edit Release', + innerWidth: "400px", innerHeight: "250px", initialWidth: "400px", initialHeight: "250px", speed: 0, opacity: 0.7 + }); + }); + $('input.nzb_multi_operations_delete').click(function () { + var ids = ""; + $("table.data INPUT[type='checkbox']:checked").each(function (i, row) { + if ($(row).val() != "on") + ids += '&id[]=' + $(row).val(); + }); + if (ids) + if (confirm('Are you sure you want to delete the selected releases?')) { + $.post(SERVERROOT + "ajax_release-admin?action=dodelete" + ids, function (resp) { + window.location = window.location; + }); + } + }); + $('input.nzb_multi_operations_rebuild').click(function () { + var ids = ""; + $("table.data INPUT[type='checkbox']:checked").each(function (i, row) { + if ($(row).val() != "on") + ids += '&id[]=' + $(row).val(); + }); + if (ids) + if (confirm('Are you sure you want to rebuild the selected releases?')) { + $.post(SERVERROOT + "ajax_release-admin?action=dorebuild" + ids, function (resp) { + window.location = window.location; + }); + } + }); + //cart functions + $('input.nzb_multi_operations_cartdelete').click(function () { + var ids = new Array(); + $("table.data INPUT[type='checkbox']:checked").each(function (i, row) { + if ($(row).val() != "on") + ids.push($(row).val()); + }); + if (ids) { + if (confirm('Are you sure you want to delete the selected releases from your cart?')) { + $.post(SERVERROOT + "cart?delete", { 'delete': ids }, function (resp) { + window.location = window.location; + }); + } + } + }); + $('input.nzb_multi_operations_cartsab').click(function () { + var ids = new Array(); + $("table.data INPUT[type='checkbox']:checked").each(function (i, row) { + var guid = $(row).val(); + var nzburl = SERVERROOT + "sendtosab/" + guid; + $.post(nzburl, function (resp) { + createGrowl('Added to Queue'); + }); + }); + }); + + + // headermenu.tpl + $('#headsearch') + .focus(function () { + if (this.value == 'Enter keywords') this.value = ''; else this.select(); + }) + .blur(function () { + if (this.value == '') this.value = 'Enter keywords'; + }); + $('#headsearch_form').submit(function () { + $('#headsearch_go').trigger('click'); + return false; + }); + $('#headsearch_go').click(function () { + if ($('#headsearch').val() && $('#headsearch').val() != 'Enter keywords') { + + var sText = $('#headsearch').val(); + var sCat = ($("#headcat").val() != -1 ? "?t=" + $("#headcat").val() : ""); + document.location = WWW_TOP + "/search/" + sText + sCat; + } + }); + + // search.tpl + $('#search_search_button').click(function () { + if ($('#search').val()) + document.location = WWW_TOP + "/search/" + $('#search').val() + ($("#search_cat").val() != -1 ? "?t=" + $("#search_cat").val() : ""); + return false; + }); + + $('#search') + .focus(function () { + this.select(); + }) + + // searchraw.tpl + $('#searchraw_search_button').click(function () { + if ($('#search').val()) + document.location = WWW_TOP + "/searchraw/" + $('#search').val(); + return false; + }); + $('#searchraw_download_selected').click(function () { + if ($('#dl input:checked').length) + $('#dl').trigger('submit'); + return false; + }); + + // login.tpl, register.tpl, search.tpl, searchraw.tpl + if ($('#username').length) + $('#username').focus(); + if ($('#search').length) + $('#search').focus(); + + // viewfilelist.tpl + $('#viewfilelist_download_selected').click(function () { + if ($('#fileform input:checked').length) + $('#fileform').trigger('submit'); + return false; + }); + + // misc + $('.confirm_action').click(function () { + return confirm('Are you sure?'); + }); + + // play audio preview + $('.audioprev').click(function () { + var a = document.getElementById($(this).next('audio').attr('ID')); + if (a != null) { + if ($(this).text() == "Listen") { + a.play(); + $(this).text("Stop"); + } + else { + a.pause(); + a.currentTime = 0; + $(this).text("Listen"); + } + } + + a.addEventListener('ended', function () { + $(this).prev().text("Listen"); }); + return false; + }); - $("table.data a.modal_music").colorbox({ // Music modal - href: function(){ return SERVERROOT + "musicmodal/"+$(this).attr('name').substring(4)+'&modal'; }, - title: function(){ return $(this).parent().parent().children('a.title').text(); }, - innerWidth:"800px", innerHeight:"450px", initialWidth:"800px", initialHeight:"450px", speed:0, opacity:0.7 - }).click(function(){ - $('#colorbox').removeClass().addClass('cboxMusic'); - }); - $("table.data a.modal_console").colorbox({ // Console modal - href: function(){ return SERVERROOT + "consolemodal/"+$(this).attr('name').substring(4)+'&modal'; }, - title: function(){ return $(this).parent().parent().children('a.title').text(); }, - innerWidth:"800px", innerHeight:"450px", initialWidth:"800px", initialHeight:"450px", speed:0, opacity:0.7 - }).click(function(){ - $('#colorbox').removeClass().addClass('cboxConsole'); - }); - $("table.data a.modal_book").colorbox({ // Book modal - href: function(){ return SERVERROOT + "bookmodal/"+$(this).attr('name').substring(4)+'&modal'; }, - title: function(){ return $(this).parent().parent().children('a.title').text(); }, - innerWidth:"800px", innerHeight:"450px", initialWidth:"800px", initialHeight:"450px", speed:0, opacity:0.7 - }).click(function(){ - $('#colorbox').removeClass().addClass('cboxBook'); - }); + // mmenu + $('.mmenu').click(function () { + document.location = $(this).children('a').attr('href'); + return false; + }); + // mmenu_new + $('.mmenu_new').click(function () { + window.open($(this).children('a').attr('href')); + return false; + }); - $('#nzb_multi_operations_form').submit(function(){return false;}); - $('input.nzb_multi_operations_download').click(function(){ - var newFormName = 'nzbmulti' + Math.round(+new Date()/1000); - var newForm = $("", {'action': SERVERROOT + 'getnzb?zip=1', 'method':'post', 'target': '_top', 'id':newFormName}); - $("table.data INPUT[type='checkbox']:checked").each( function(i, row) { - if ($(row).val()!="on") - $("", {'name':'id[]', 'value':$(row).val(), 'type':'hidden'}).appendTo(newForm); - }); - newForm.appendTo($('body')); - $('#'+newFormName).submit(); - }); - $('input.nzb_multi_operations_cart').click(function(){ - var guids = new Array(); - $("table.data INPUT[type='checkbox']:checked").each( function(i, row) { - var guid = $(row).val(); - var $cartIcon = $(row).parent().parent().children('td.icons').children('.icon_cart'); - if (guid && !$cartIcon.hasClass('icon_cart_clicked')){ - $cartIcon.addClass('icon_cart_clicked').attr('title','Added to Cart'); // consider doing this only upon success - guids.push(guid); - createGrowl( 'Added to Cart' ); - } - $(this).attr('checked', false); - }); - $.post( SERVERROOT + "cart?add", { 'add': guids }); - }); - $('input.nzb_multi_operations_sab').click(function(){ - $("table.data INPUT[type='checkbox']:checked").each( function(i, row) { - var $sabIcon = $(row).parent().parent().children('td.icons').children('.icon_sab'); - var guid = $(row).val(); - if (guid && !$sabIcon.hasClass('icon_sab_clicked')) { - var nzburl = SERVERROOT + "sendtosab/" + guid; - $.post( nzburl, function(resp){ - $sabIcon.addClass('icon_sab_clicked').attr('title','Added to Queue'); - createGrowl( 'Added to Queue' ); - }); - } - $(this).attr('checked', false); - }); - }); - //front end admin functions - $('input.nzb_multi_operations_edit').click(function(){ - var ids = ""; - $("table.data INPUT[type='checkbox']:checked").each( function(i, row) { - if ($(row).val()!="on") - ids += '&id[]='+$(row).val(); - }); - if (ids) - $('input.nzb_multi_operations_edit').colorbox({ - href: function(){ return SERVERROOT + "ajax_release-admin?action=edit"+ids+"&from="+encodeURIComponent(window.location); }, - title: 'Edit Release', - innerWidth:"400px", innerHeight:"250px", initialWidth:"400px", initialHeight:"250px", speed:0, opacity:0.7 - }); - }); - $('input.nzb_multi_operations_delete').click(function(){ - var ids = ""; - $("table.data INPUT[type='checkbox']:checked").each( function(i, row) { - if ($(row).val()!="on") - ids += '&id[]='+$(row).val(); - }); - if (ids) - if (confirm('Are you sure you want to delete the selected releases?')) { - $.post(SERVERROOT + "ajax_release-admin?action=dodelete"+ids, function(resp){ - window.location = window.location; - }); - } - }); - $('input.nzb_multi_operations_rebuild').click(function(){ - var ids = ""; - $("table.data INPUT[type='checkbox']:checked").each( function(i, row) { - if ($(row).val()!="on") - ids += '&id[]='+$(row).val(); - }); - if (ids) - if (confirm('Are you sure you want to rebuild the selected releases?')) { - $.post(SERVERROOT + "ajax_release-admin?action=dorebuild"+ids, function(resp){ - window.location = window.location; - }); - } - }); - //cart functions - $('input.nzb_multi_operations_cartdelete').click(function(){ - var ids = new Array(); - $("table.data INPUT[type='checkbox']:checked").each( function(i, row) { - if ($(row).val()!="on") - ids.push($(row).val()); - }); - if (ids) - { - if (confirm('Are you sure you want to delete the selected releases from your cart?')) { - $.post( SERVERROOT + "cart?delete", { 'delete': ids }, function(resp){ - window.location = window.location; - }); - } - } - }); - $('input.nzb_multi_operations_cartsab').click(function(){ - var ids = new Array(); - $("table.data INPUT[type='checkbox']:checked").each( function(i, row) { - var guid = $(row).val(); - var nzburl = SERVERROOT + "sendtosab/" + guid; - $.post( nzburl, function(resp){ - createGrowl( 'Added to Queue' ); - }); - }); - }); + // searchraw.tpl, viewfilelist.tpl -- checkbox operations + // selections + var last1, last2; + $(".checkbox_operations .select_all").click(function () { + $("table.data INPUT[type='checkbox']").attr('checked', true).trigger('change'); + return false; + }); + $(".checkbox_operations .select_none").click(function () { + $("table.data INPUT[type='checkbox']").attr('checked', false).trigger('change'); + return false; + }); + $(".checkbox_operations .select_invert").click(function () { + $("table.data INPUT[type='checkbox']").each(function () { + $(this).attr('checked', !$(this).attr('checked')).trigger('change'); + }); + return false; + }); + $(".checkbox_operations .select_range").click(function () { + if (last1 && last2 && last1 < last2) + $("table.data INPUT[type='checkbox']").slice(last1, last2).attr('checked', true).trigger('change'); + else if (last1 && last2) + $("table.data INPUT[type='checkbox']").slice(last2, last1).attr('checked', true).trigger('change'); + return false; + }); + $('table.data td.check INPUT[type="checkbox"]').click(function (e) { + // range event interaction -- see further above + var rowNum = $(e.target).parent().parent()[0].rowIndex; + if (last1) last2 = last1; + last1 = rowNum; - + // perform range selection + if (e.shiftKey && last1 && last2) { + if (last1 < last2) + $("table.data INPUT[type='checkbox']").slice(last1, last2).attr('checked', true).trigger('change'); + else + $("table.data INPUT[type='checkbox']").slice(last2, last1).attr('checked', true).trigger('change'); + } + }); + $('table.data a.data_filename').click(function (e) { // click filenames to select + // range event interaction -- see further above + var rowNum = $(e.target).parent().parent()[0].rowIndex; + if (last1) last2 = last1; + last1 = rowNum; - // headermenu.tpl - $('#headsearch') - .focus(function(){if(this.value == 'Enter keywords') this.value = ''; else this.select(); }) - .blur (function(){if(this.value == '') this.value = 'Enter keywords';}); - $('#headsearch_form').submit(function(){ - $('#headsearch_go').trigger('click'); - return false; - }); - $('#headsearch_go').click(function(){ - if ($('#headsearch').val() && $('#headsearch').val() != 'Enter keywords') - { - - var sText = $('#headsearch').val(); - var sCat = ($("#headcat").val()!=-1 ? "?t="+$("#headcat").val() : ""); - document.location= WWW_TOP + "/search/" + sText + sCat; - } - }); + var $checkbox = $('table.data tr:nth-child(' + (rowNum + 1) + ') td.selection INPUT[type="checkbox"]'); + $checkbox.attr('checked', !$checkbox.attr('checked')); - // search.tpl - $('#search_search_button').click(function(){ - if ($('#search').val()) - document.location=WWW_TOP + "/search/" + $('#search').val() + ($("#search_cat").val()!=-1 ? "?t="+$("#search_cat").val() : ""); - return false; - }); - - $('#search') - .focus(function(){this.select(); }) - - // searchraw.tpl - $('#searchraw_search_button').click(function(){ - if ($('#search').val()) - document.location=WWW_TOP + "/searchraw/" + $('#search').val(); - return false; - }); - $('#searchraw_download_selected').click(function(){ - if ($('#dl input:checked').length) - $('#dl').trigger('submit'); - return false; - }); - - // login.tpl, register.tpl, search.tpl, searchraw.tpl - if ($('#username').length) - $('#username').focus(); - if ($('#search').length) - $('#search').focus(); - - // viewfilelist.tpl - $('#viewfilelist_download_selected').click(function(){ - if ($('#fileform input:checked').length) - $('#fileform').trigger('submit'); - return false; - }); - - // misc - $('.confirm_action').click(function(){ return confirm('Are you sure?'); }); - - // play audio preview - $('.audioprev').click(function(){ - var a = document.getElementById($(this).next('audio').attr('ID')); - if (a != null) { - if ($(this).text() == "Listen") { - a.play(); - $(this).text("Stop"); - } - else { - a.pause(); - a.currentTime = 0; - $(this).text("Listen"); - } - } - - a.addEventListener('ended', function () { - $(this).prev().text("Listen"); - } ); - - return false; - }); - - // mmenu - $('.mmenu').click(function(){ - document.location=$(this).children('a').attr('href'); - return false; - }); - - // mmenu_new - $('.mmenu_new').click(function(){ - window.open($(this).children('a').attr('href')); - return false; - }); - - // searchraw.tpl, viewfilelist.tpl -- checkbox operations - // selections - var last1, last2; - $(".checkbox_operations .select_all").click(function(){ - $("table.data INPUT[type='checkbox']").attr('checked', true).trigger('change'); - return false; - }); - $(".checkbox_operations .select_none").click(function(){ - $("table.data INPUT[type='checkbox']").attr('checked', false).trigger('change'); - return false; - }); - $(".checkbox_operations .select_invert").click(function(){ - $("table.data INPUT[type='checkbox']").each( function() { - $(this).attr('checked', !$(this).attr('checked')).trigger('change'); - }); - return false; - }); - $(".checkbox_operations .select_range").click(function(){ - if (last1 && last2 && last1 < last2) - $("table.data INPUT[type='checkbox']").slice(last1,last2).attr('checked', true).trigger('change'); - else if (last1 && last2) - $("table.data INPUT[type='checkbox']").slice(last2,last1).attr('checked', true).trigger('change'); - return false; - }); - $('table.data td.check INPUT[type="checkbox"]').click(function(e) { - // range event interaction -- see further above - var rowNum = $(e.target).parent().parent()[0].rowIndex ; - if (last1) last2 = last1; - last1 = rowNum; - - // perform range selection - if (e.shiftKey && last1 && last2) { - if (last1 < last2) - $("table.data INPUT[type='checkbox']").slice(last1,last2).attr('checked', true).trigger('change'); - else - $("table.data INPUT[type='checkbox']").slice(last2,last1).attr('checked', true).trigger('change'); - } - }); - $('table.data a.data_filename').click(function(e) { // click filenames to select - // range event interaction -- see further above - var rowNum = $(e.target).parent().parent()[0].rowIndex ; - if (last1) last2 = last1; - last1 = rowNum; - - var $checkbox = $('table.data tr:nth-child('+(rowNum+1)+') td.selection INPUT[type="checkbox"]'); - $checkbox.attr('checked', !$checkbox.attr('checked')); - - return false; - }); + return false; + }); // show/hide previews - $('#showmoviepreviews').click(function() - { + $('#showmoviepreviews').click(function () { $('#moviepreviews').next('form').toggle('fast'); - $('#moviepreviews').toggle('fast', function() { - $('#showmoviepreviews').text(($('#moviepreviews').is(":visible") ? "Hide" : "Show") + " previews"); + $('#moviepreviews').toggle('fast', function () { + $('#showmoviepreviews').text(($('#moviepreviews').is(":visible") ? "Hide" : "Show") + " previews"); }); return false; }); - // show/hide invite form - $('#lnkSendInvite').click(function() - { - $('#divInvite').slideToggle('fast'); - }); - - // send an invite - $('#frmSendInvite').submit(function() - { - var inputEmailto = $("#txtInvite").val(); - if (isValidEmailAddress(inputEmailto)) - { - - // no caching of results - $.ajax({ - url : WWW_TOP + '/ajax_profile?action=1&rand=' + $.now(), - data : { emailto: inputEmailto}, - dataType : "html", - success : function(data) - { - $("#txtInvite").val(""); - $('#divInvite').slideToggle('fast'); - $("#divInviteSuccess").text(data).show(); - $("#divInviteError").hide(); - }, - error: function(xhr,err,e) { alert( "Error in ajax_profile: " + err ); } - }); - } - else - { - $("#divInviteSuccess").hide(); - $("#divInviteError").text("Invalid email").show(); - } - return false; - }); + // show/hide invite form + $('#lnkSendInvite').click(function () { + $('#divInvite').slideToggle('fast'); + }); - // movie.tpl - $('.mlmore').click(function(){ // show more movies - $(this).parent().parent().hide(); - $(this).parent().parent().parent().children(".mlextra").show(); - return false; - }); - - // lookup tmdb for a movie - $('#frmMyMovieLookup').submit(function() - { - var movSearchText = $("#txtsearch").val(); - // no caching of results - $.ajax({ - url : WWW_TOP + '/ajax_mymovies?rand=' + $.now(), - data : { id: movSearchText}, - dataType : "html", - success : function(data) - { - $("#divMovResults").html(data); - }, - error: function(xhr,err,e) { alert( "Error in ajax_mymovies: " + err ); } - }); + // send an invite + $('#frmSendInvite').submit(function () { + var inputEmailto = $("#txtInvite").val(); + if (isValidEmailAddress(inputEmailto)) { - return false; - }); - - // season selector in TV - $('a[id^="seas_"]').click(function(){ - seas = $(this).attr("ID").replace("seas_",""); + // no caching of results + $.ajax({ + url: WWW_TOP + '/ajax_profile?action=1&rand=' + $.now(), + data: { emailto: inputEmailto}, + dataType: "html", + success: function (data) { + $("#txtInvite").val(""); + $('#divInvite').slideToggle('fast'); + $("#divInviteSuccess").text(data).show(); + $("#divInviteError").hide(); + }, + error: function (xhr, err, e) { + alert("Error in ajax_profile: " + err); + } + }); + } + else { + $("#divInviteSuccess").hide(); + $("#divInviteError").text("Invalid email").show(); + } + return false; + }); - $('table[class^="tb_"]').hide(); - $('.tb_' + seas).show(); - - $("li", $(this).closest("ul")).removeClass("active"); - $(this).closest("li").addClass("active"); - - return false; - }); - - // file list tooltip - $(".rarfilelist").each(function() { - var guid = $(this).children('img').attr('alt'); - $(this).qtip({ - content: { - title: { - text: 'rar archive contains...' - }, - text: 'loading...', - ajax: { - url: SERVERROOT + 'ajax_rarfilelist', - type: 'GET', - data: { id: guid }, - success: function(data, status) { - this.set('content.text', data); - } - } - }, - position: { - my: 'top right', - at: 'bottom left' - }, - style: { - classes: 'ui-tooltip-newznab', - width: { max: 500 }, - tip: { - corner: 'topRight', - size: { - x: 8, - y : 8 - } - } - } - }); - }); - - // seriesinfo tooltip - $(".seriesinfo").each(function() { - var guid = $(this).attr('title'); - $(this).qtip({ - content: { - title: { - text: 'Episode Info' - }, - text: 'loading...', - ajax: { - url: SERVERROOT + 'ajax_tvinfo', - type: 'GET', - data: { id: guid }, - success: function(data, status) { - this.set('content.text', data); - } - } - }, - style: { - classes: 'ui-tooltip-newznab' - } - }); - }); + // movie.tpl + $('.mlmore').click(function () { // show more movies + $(this).parent().parent().hide(); + $(this).parent().parent().parent().children(".mlextra").show(); + return false; + }); - // mediainfo tooltip - $(".mediainfo").each(function() { - var guid = $(this).attr('title'); - $(this).qtip({ - content: { - title: { - text: 'Extended Media Info' - }, - text: 'loading...', - ajax: { - url: SERVERROOT + 'ajax_mediainfo', - type: 'GET', - data: { id: guid }, - success: function(data, status) { - this.set('content.text', data); - } - } - }, - style: { - classes: 'ui-tooltip-newznab', - width: { max: 500 }, - tip: { - corner: 'topLeft', - size: { - x: 8, - y : 8 - } - } - } - }); - }); - - // preinfo tooltip - $(".preinfo").each(function() { - var searchname = $(this).attr('title'); - $(this).qtip({ - content: { - title: { - text: 'Pre Info' - }, - text: 'loading...', - ajax: { - url: SERVERROOT + 'ajax_preinfo', - type: 'GET', - data: { searchname: searchname }, - success: function(data, status) { - this.set('content.text', data); - } - } - }, - style: { - classes: 'ui-tooltip-newznab' - } - }); - }); + // lookup tmdb for a movie + $('#frmMyMovieLookup').submit(function () { + var movSearchText = $("#txtsearch").val(); + // no caching of results + $.ajax({ + url: WWW_TOP + '/ajax_mymovies?rand=' + $.now(), + data: { id: movSearchText}, + dataType: "html", + success: function (data) { + $("#divMovResults").html(data); + }, + error: function (xhr, err, e) { + alert("Error in ajax_mymovies: " + err); + } + }); + + return false; + }); + + // season selector in TV + $('a[id^="seas_"]').click(function () { + seas = $(this).attr("ID").replace("seas_", ""); + + $('table[class^="tb_"]').hide(); + $('.tb_' + seas).show(); + + $("li", $(this).closest("ul")).removeClass("active"); + $(this).closest("li").addClass("active"); + + return false; + }); + + // file list tooltip + $(".rarfilelist").each(function () { + var guid = $(this).children('img').attr('alt'); + $(this).qtip({ + content: { + title: { + text: 'rar archive contains...' + }, + text: 'loading...', + ajax: { + url: SERVERROOT + 'ajax_rarfilelist', + type: 'GET', + data: { id: guid }, + success: function (data, status) { + this.set('content.text', data); + } + } + }, + position: { + my: 'top right', + at: 'bottom left' + }, + style: { + classes: 'ui-tooltip-newznab', + width: { max: 500 }, + tip: { + corner: 'topRight', + size: { + x: 8, + y: 8 + } + } + } + }); + }); + + // seriesinfo tooltip + $(".seriesinfo").each(function () { + var guid = $(this).attr('title'); + $(this).qtip({ + content: { + title: { + text: 'Episode Info' + }, + text: 'loading...', + ajax: { + url: SERVERROOT + 'ajax_tvinfo', + type: 'GET', + data: { id: guid }, + success: function (data, status) { + this.set('content.text', data); + } + } + }, + style: { + classes: 'ui-tooltip-newznab' + } + }); + }); + + // mediainfo tooltip + $(".mediainfo").each(function () { + var guid = $(this).attr('title'); + $(this).qtip({ + content: { + title: { + text: 'Extended Media Info' + }, + text: 'loading...', + ajax: { + url: SERVERROOT + 'ajax_mediainfo', + type: 'GET', + data: { id: guid }, + success: function (data, status) { + this.set('content.text', data); + } + } + }, + style: { + classes: 'ui-tooltip-newznab', + width: { max: 500 }, + tip: { + corner: 'topLeft', + size: { + x: 8, + y: 8 + } + } + } + }); + }); + + // preinfo tooltip + $(".preinfo").each(function () { + var searchname = $(this).attr('title'); + $(this).qtip({ + content: { + title: { + text: 'Pre Info' + }, + text: 'loading...', + ajax: { + url: SERVERROOT + 'ajax_preinfo', + type: 'GET', + data: { searchname: searchname }, + success: function (data, status) { + this.set('content.text', data); + } + } + }, + style: { + classes: 'ui-tooltip-newznab' + } + }); + }); // prehashinfo tooltip - $(".prehashinfo").each(function() { - var prehashID = $(this).attr('title'); - $(this).qtip({ - content: { - title: { - text: 'Prehash info' - }, - text: 'loading...', // The text to use whilst the AJAX request is loading - ajax: { - url: SERVERROOT + 'ajax_prehashinfo', // URL to the local file - type: 'GET', // POST or GET - data: { ID: prehashID }, // Data to pass along with your request - success: function(data, status) { - this.set('content.text', data); - } - } - }, - }); - }); + $(".prehashinfo").each(function () { + var prehashID = $(this).attr('title'); + $(this).qtip({ + content: { + title: { + text: 'Prehash info' + }, + text: 'loading...', // The text to use whilst the AJAX request is loading + ajax: { + url: SERVERROOT + 'ajax_prehashinfo', // URL to the local file + type: 'GET', // POST or GET + data: { ID: prehashID }, // Data to pass along with your request + success: function (data, status) { + this.set('content.text', data); + } + } + }, + }); + }); }); $.extend({ // http://plugins.jquery.com/project/URLEncode -URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/; - while(x1 && m[1]!=''){o+=m[1];x+=m[1].length; - }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16); - o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;}, -URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/; - while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16); - t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;} + /** + * @return {string} + */ + URLEncode: function (c) { + var o = ''; + var x = 0; + c = c.toString(); + var r = /(^[a-zA-Z0-9_.]*)/; + while (x < c.length) { + var m = r.exec(c.substr(x)); + if (m != null && m.length > 1 && m[1] != '') { + o += m[1]; + x += m[1].length; + } else { + if (c[x] == ' ')o += '+'; else { + var d = c.charCodeAt(x); + var h = d.toString(16); + o += '%' + (h.length < 2 ? '0' : '') + h.toUpperCase(); + } + x++; + } + } + return o; + }, + URLDecode: function (s) { + var o = s; + var binVal, t; + var r = /(%[^%]{2})/; + while ((m = r.exec(o)) != null && m.length > 1 && m[1] != '') { + b = parseInt(m[1].substr(1), 16); + t = String.fromCharCode(b); + o = o.replace(m[1], t); + } + return o; + } }); -function isValidEmailAddress(emailAddress) -{ - var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); - return pattern.test(emailAddress); +function isValidEmailAddress(emailAddress) { + var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); + return pattern.test(emailAddress); } -function mymovie_del(imdbID, btn) -{ - $.ajax({ - url : WWW_TOP + '/ajax_mymovies?rand=' + $.now(), - data : { del: imdbID}, - dataType : "html", - success : function(data) - { - $(btn).hide(); - $(btn).prev("a").show(); - }, - error: function(xhr,err,e) { } - }); +function mymovie_del(imdbID, btn) { + $.ajax({ + url: WWW_TOP + '/ajax_mymovies?rand=' + $.now(), + data: { del: imdbID}, + dataType: "html", + success: function (data) { + $(btn).hide(); + $(btn).prev("a").show(); + }, + error: function (xhr, err, e) { + } + }); - return false; + return false; } -function mymovie_add(imdbID, btn) -{ - $(btn).hide(); - $(btn).next("a").show(); +function mymovie_add(imdbID, btn) { + $(btn).hide(); + $(btn).next("a").show(); - $.ajax({ - url : WWW_TOP + '/ajax_mymovies?rand=' + $.now(), - data : { add: imdbID}, - dataType : "html", - success : function(data) - { - }, - error: function(xhr,err,e) { } - }); + $.ajax({ + url: WWW_TOP + '/ajax_mymovies?rand=' + $.now(), + data: { add: imdbID}, + dataType: "html", + success: function (data) { + }, + error: function (xhr, err, e) { + } + }); - return false; + return false; } // qtip growl -$(document).ready(function() -{ - window.createGrowl = function(tipText ) { - - var target = $('.qtip.jgrowl:visible:last'); - var tipTitle = 'Attention!'; - var persistent = false; - - $(document.body).qtip({ - content: { - text: tipText, - title: { - text: tipTitle, - button: true +$(document).ready(function () { + window.createGrowl = function (tipText) { + + var target = $('.qtip.jgrowl:visible:last'); + var tipTitle = 'Attention!'; + var persistent = false; + + $(document.body).qtip({ + content: { + text: tipText, + title: { + text: tipTitle, + button: true + } + }, + position: { + my: 'top right', + at: (target.length ? 'bottom' : 'top') + ' right', + target: target.length ? target : $(document.body), + adjust: { y: 5 } + }, + show: { + event: false, + ready: true, + effect: function () { + $(this).stop(0, 1).fadeIn(400); + }, + + persistent: persistent + }, + hide: { + event: false, + effect: function (api) { + $(this).stop(0, 1).fadeOut(400).queue(function () { + api.destroy(); + updateGrowls(); + }) + } + }, + style: { + classes: 'jgrowl ui-tooltip-newznab ui-tooltip-rounded', + tip: false + }, + events: { + render: function (event, api) { + timer.call(api.elements.tooltip, event); + } } - }, - position: { - my: 'top right', - at: (target.length ? 'bottom' : 'top') + ' right', - target: target.length ? target : $(document.body), - adjust: { y: 5 } - }, - show: { - event: false, - ready: true, - effect: function() { $(this).stop(0,1).fadeIn(400); }, - - persistent: persistent - }, - hide: { - event: false, - effect: function(api) { - $(this).stop(0,1).fadeOut(400).queue(function() { - api.destroy(); - updateGrowls(); - }) - } - }, - style: { - classes: 'jgrowl ui-tooltip-newznab ui-tooltip-rounded', - tip: false - }, - events: { - render: function(event, api) { - timer.call(api.elements.tooltip, event); - } - } - }) - .removeData('qtip'); - }; - - window.updateGrowls = function() { - var each = $('.qtip.jgrowl:not(:animated)'); - each.each(function(i) { - var api = $(this).data('qtip'); - - api.options.position.target = !i ? $(document.body) : each.eq(i - 1); - api.set('position.at', (!i ? 'top' : 'bottom') + ' right'); - }); - }; - - function timer(event) { - var api = $(this).data('qtip'), - lifespan = 5000; - - if(api.get('show.persistent') === true) { return; } - - clearTimeout(api.timer); - if(event.type !== 'mouseover') { - api.timer = setTimeout(api.hide, lifespan); - } - } - - $(document).delegate('.qtip.jgrowl', 'mouseover mouseout', timer); + }) + .removeData('qtip'); + }; + + window.updateGrowls = function () { + var each = $('.qtip.jgrowl:not(:animated)'); + each.each(function (i) { + var api = $(this).data('qtip'); + + api.options.position.target = !i ? $(document.body) : each.eq(i - 1); + api.set('position.at', (!i ? 'top' : 'bottom') + ' right'); + }); + }; + + function timer(event) { + var api = $(this).data('qtip'), + lifespan = 5000; + + if (api.get('show.persistent') === true) { + return; + } + + clearTimeout(api.timer); + if (event.type !== 'mouseover') { + api.timer = setTimeout(api.hide, lifespan); + } + } + + $(document).delegate('.qtip.jgrowl', 'mouseover mouseout', timer); }); //reset users api counts -function resetapireq(uid, type) -{ - $.post( SERVERROOT + "ajax_resetusergrabs-admin?id=" + uid + "&action=" + type, function(resp){ }); +function resetapireq(uid, type) { + $.post(SERVERROOT + "ajax_resetusergrabs-admin?id=" + uid + "&action=" + type, function (resp) { + }); } \ No newline at end of file diff --git a/lib/copy_this/www/templates/nntmux/views/frontend/apiresult.tpl b/lib/copy_this/www/templates/nntmux/views/frontend/apiresult.tpl index b0e31a8d6..3dbcba6d1 100644 --- a/lib/copy_this/www/templates/nntmux/views/frontend/apiresult.tpl +++ b/lib/copy_this/www/templates/nntmux/views/frontend/apiresult.tpl @@ -1,99 +1,136 @@ {$rsshead} - - + {foreach from=$releases item=release} - - {$release.searchname|escape:html} - {$serverroot}details/{$release.guid} - {$serverroot}getnzb/{$release.guid}.nzb&i={$uid}&r={$rsstoken} - {$serverroot}details/{$release.guid}#comments - {$release.adddate|phpdate_format:"DATE_RSS"} - {$release.category_name|escape:html} - {$release.searchname|escape:html} - + + {$release.searchname|escape:html} + {$serverroot}details/{$release.guid} + {$serverroot}getnzb/{$release.guid}.nzb&i={$uid}&r={$rsstoken} + {$serverroot}details/{$release.guid}#comments + {$release.adddate|phpdate_format:"DATE_RSS"} + {$release.category_name|escape:html} + {$release.searchname|escape:html} + - {foreach from=$release.category_ids|parray:"," item=cat} - - {/foreach} - - -{if $extended=="1" || isset($attrs.files)} -{/if} -{if $extended=="1" || isset($attrs.poster)} -{/if} -{if $release.season != "" && ($extended=="1" || isset($attrs.season))} -{/if} -{if $release.episode != "" && ($extended=="1" || isset($attrs.episode))} -{/if} -{if $release.rageID != "-1" && $release.rageID != "-2" && ($extended=="1" || isset($attrs.rageid))} -{/if} -{if $release.tvtitle != "" && ($extended=="1" || isset($attrs.tvtitle))} -{/if} -{if $release.tvairdate != "" && ($extended=="1" || isset($attrs.tvairdate))} -{/if} -{if $release.imdbID != "" && ($extended=="1" || isset($attrs.imdb))} -{/if} -{if $release.moi_title != "" && ($extended=="1" || isset($attrs.imdbtitle))} -{/if} -{if $release.moi_tagline != "" && ($extended=="1" || isset($attrs.imdbtagline))} -{/if} -{if $release.moi_plot != "" && ($extended=="1" || isset($attrs.imdbplot))} -{/if} -{if $release.moi_rating != "" && ($extended=="1" || isset($attrs.imdbscore))} -{/if} -{if $release.moi_genre != "" && ($extended=="1" || isset($attrs.genre))} -{/if} -{if $release.moi_year != "" && ($extended=="1" || isset($attrs.imdbyear))} -{/if} -{if $release.moi_director != "" && ($extended=="1" || isset($attrs.imdbdirector))} -{/if} -{if $release.moi_actors != "" && ($extended=="1" || isset($attrs.imdbactors))} -{/if} -{if $release.moi_cover == 1 && ($extended=="1" || isset($attrs.coverurl))} -{/if} -{if $release.moi_backdrop == 1 && ($extended=="1" || isset($attrs.backdropurl))} -{/if} -{if $release.musicinfoID != "" && $release.mi_title != "" && ($extended=="1" || isset($attrs.album))} -{/if} -{if $release.musicinfoID != "" && $release.mi_artist != "" && ($extended=="1" || isset($attrs.artist))} -{/if} -{if $release.musicinfoID != "" && $release.mi_publisher != "" && ($extended=="1" || isset($attrs.label))} -{/if} -{if $release.musicinfoID != "" && $release.mi_tracks != "" && ($extended=="1" || isset($attrs.tracks))} -{/if} -{if $release.musicinfoID != "" && $release.mi_review != "" && ($extended=="1" || isset($attrs.review))} -{/if} -{if $release.musicinfoID != "" && $release.mi_cover == "1" && ($extended=="1" || isset($attrs.coverurl))} -{/if} -{if $release.musicinfoID != "" && $release.music_genrename != "" && ($extended=="1" || isset($attrs.genre))} -{/if} -{if $release.bookinfoID != "" && $release.bi_author != "" && ($extended=="1" || isset($attrs.author))} -{/if} -{if $release.bookinfoID != "" && $release.bi_title != "" && ($extended=="1" || isset($attrs.booktitle))} -{/if} -{if $release.bookinfoID != "" && $release.bi_cover == "1" && ($extended=="1" || isset($attrs.coverurl))} -{/if} -{if $release.bookinfoID != "" && $release.bi_review != "" && ($extended=="1" || isset($attrs.review))} -{/if} -{if $release.bookinfoID != "" && $release.bi_publishdate != "" && ($extended=="1" || isset($attrs.publishdate))} -{/if} -{if $release.bookinfoID != "" && $release.bi_publisher != "" && ($extended=="1" || isset($attrs.publisher))} -{/if} -{if $release.bookinfoID != "" && $release.bi_pages != "" && ($extended=="1" || isset($attrs.pages))} -{/if} + {foreach from=$release.category_ids|parray:"," item=cat} + + {/foreach} + + + {if $extended=="1" || isset($attrs.files)} + + {/if} + {if $extended=="1" || isset($attrs.poster)} + + {/if} + {if $release.season != "" && ($extended=="1" || isset($attrs.season))} + + {/if} + {if $release.episode != "" && ($extended=="1" || isset($attrs.episode))} + + {/if} + {if $release.rageID != "-1" && $release.rageID != "-2" && ($extended=="1" || isset($attrs.rageid))} + + {/if} + {if $release.tvtitle != "" && ($extended=="1" || isset($attrs.tvtitle))} + + {/if} + {if $release.tvairdate != "" && ($extended=="1" || isset($attrs.tvairdate))} + + {/if} + {if $release.imdbID != "" && ($extended=="1" || isset($attrs.imdb))} + + {/if} + {if $release.moi_title != "" && ($extended=="1" || isset($attrs.imdbtitle))} + + {/if} + {if $release.moi_tagline != "" && ($extended=="1" || isset($attrs.imdbtagline))} + + {/if} + {if $release.moi_plot != "" && ($extended=="1" || isset($attrs.imdbplot))} + + {/if} + {if $release.moi_rating != "" && ($extended=="1" || isset($attrs.imdbscore))} + + {/if} + {if $release.moi_genre != "" && ($extended=="1" || isset($attrs.genre))} + + {/if} + {if $release.moi_year != "" && ($extended=="1" || isset($attrs.imdbyear))} + + {/if} + {if $release.moi_director != "" && ($extended=="1" || isset($attrs.imdbdirector))} + + {/if} + {if $release.moi_actors != "" && ($extended=="1" || isset($attrs.imdbactors))} + + {/if} + {if $release.moi_cover == 1 && ($extended=="1" || isset($attrs.coverurl))} + + {/if} + {if $release.moi_backdrop == 1 && ($extended=="1" || isset($attrs.backdropurl))} + + {/if} + {if $release.musicinfoID != "" && $release.mi_title != "" && ($extended=="1" || isset($attrs.album))} + + {/if} + {if $release.musicinfoID != "" && $release.mi_artist != "" && ($extended=="1" || isset($attrs.artist))} + + {/if} + {if $release.musicinfoID != "" && $release.mi_publisher != "" && ($extended=="1" || isset($attrs.label))} + + {/if} + {if $release.musicinfoID != "" && $release.mi_tracks != "" && ($extended=="1" || isset($attrs.tracks))} + + {/if} + {if $release.musicinfoID != "" && $release.mi_review != "" && ($extended=="1" || isset($attrs.review))} + + {/if} + {if $release.musicinfoID != "" && $release.mi_cover == "1" && ($extended=="1" || isset($attrs.coverurl))} + + {/if} + {if $release.musicinfoID != "" && $release.music_genrename != "" && ($extended=="1" || isset($attrs.genre))} + + {/if} + {if $release.bookinfoID != "" && $release.bi_author != "" && ($extended=="1" || isset($attrs.author))} + + {/if} + {if $release.bookinfoID != "" && $release.bi_title != "" && ($extended=="1" || isset($attrs.booktitle))} + + {/if} + {if $release.bookinfoID != "" && $release.bi_cover == "1" && ($extended=="1" || isset($attrs.coverurl))} + + {/if} + {if $release.bookinfoID != "" && $release.bi_review != "" && ($extended=="1" || isset($attrs.review))} + + {/if} + {if $release.bookinfoID != "" && $release.bi_publishdate != "" && ($extended=="1" || isset($attrs.publishdate))} + + {/if} + {if $release.bookinfoID != "" && $release.bi_publisher != "" && ($extended=="1" || isset($attrs.publisher))} + + {/if} + {if $release.bookinfoID != "" && $release.bi_pages != "" && ($extended=="1" || isset($attrs.pages))} + + {/if} -{if $extended=="1" || isset($attrs.grabs)} -{/if} -{if $extended=="1" || isset($attrs.comments)} -{/if} -{if $extended=="1" || isset($attrs.password)} -{/if} -{if $extended=="1" || isset($attrs.usenetdate)} -{/if} -{if $extended=="1" || isset($attrs.group)} {$attrs.group} -{/if} + {if $extended=="1" || isset($attrs.grabs)} + + {/if} + {if $extended=="1" || isset($attrs.comments)} + + {/if} + {if $extended=="1" || isset($attrs.password)} + + {/if} + {if $extended=="1" || isset($attrs.usenetdate)} + + {/if} + {if $extended=="1" || isset($attrs.group)} {$attrs.group} + + {/if} - + {/foreach} diff --git a/lib/copy_this/www/templates/nntmux/views/frontend/profileedit.tpl b/lib/copy_this/www/templates/nntmux/views/frontend/profileedit.tpl index 3f7e41887..9dbbbd921 100644 --- a/lib/copy_this/www/templates/nntmux/views/frontend/profileedit.tpl +++ b/lib/copy_this/www/templates/nntmux/views/frontend/profileedit.tpl @@ -1,4 +1,3 @@ -

Edit your profile

{if $error != ''} @@ -9,125 +8,174 @@ -
-User Details - - - - - - - - -
Username:{$user.username|escape:"htmlall"}
Email:
Password: - -
Only enter your password if you want to change it.
-
Confirm Password: -
Site Api/Rss Key:{$user.rsstoken}
Generate
-
-
-Site Preferences - - - - - - - - - - - - - - - - -
View Movie Page: - -
Browse movie covers. Only shows movies with known IMDB info.
-
View Music Page: - -
Browse music covers. Only shows music with known lookup info.
-
View Console Page: - -
Browse console covers. Only shows games with known lookup info.
-
View Book Page: - -
Browse book covers. Only shows books with known lookup info.
-
Excluded Categories: - {html_options style="height:105px;" multiple=multiple name="exccat[]" options=$catlist selected=$userexccat} -
Use Ctrl and click to exclude multiple categories.
-
-
+
+ User Details + + + + + + + + + + + + + + + + + + + + + +
Username:{$user.username|escape:"htmlall"}
Email: +
Password: + -{if $page->site->sabintegrationtype == 2} -
-SABnzbd Integration - - - - - - - - - - - - - - - - - - - - - - - - -
: - -
The url of the SAB installation, for example: http://localhost:8080/sabnzbd/
-
: - -
The api key of the SAB installation. Can be the full api key or the nzb api key (as of SAB 0.6)
-
: - {html_radios id="sabapikeytype" name='sabapikeytype' values=$sabapikeytype_ids output=$sabapikeytype_names selected=$sabapikeytype_selected separator='
'} -
Select the type of api key you entered in the above setting. Using your full SAB api key will allow you access to the SAB queue from within this site.
-
: - {html_options id="sabpriority" name='sabpriority' values=$sabpriority_ids output=$sabpriority_names selected=$sabpriority_selected} -
Set the priority level for NZBs that are added to your queue
-
: - {html_radios id="sabsetting" name='sabsetting' values=$sabsetting_ids output=$sabsetting_names selected=$sabsetting_selected separator='  '}{if $sabsetting_selected == 2}  [Clear Cookies]{/if} -
Where to store the SAB setting.
Cookie will store the setting in your browsers coookies and will only work when using your current browser.
Site will store the setting in your user account enabling it to work no matter where you are logged in from.
Please Note: You should only store your full SAB api key with sites you trust.
-
-
-{/if} -
-NZBVortex Integration - - - - - - - - - -
: - -
Server URL for NZBVortex found in Preferences -> Remote. Do not put a / at the end! -
- Example: http://123.123.123.123:8080
-
: - -
Remote API key for NZBVortex found in Preferences -> Remote. -
- Example: 52FE-5ABD
-
-
- +
Only enter your password if you want to change it.
+
Confirm Password: +
Site Api/Rss Key:{$user.rsstoken}
Generate
+
+
+ Site Preferences + + + + + + + + + + + + + + + + + + + + + +
View Movie Page: + + +
Browse movie covers. Only shows movies with known IMDB info.
+
View Music Page: + + +
Browse music covers. Only shows music with known lookup info.
+
View Console Page: + + +
Browse console covers. Only shows games with known lookup info.
+
View Book Page: + + +
Browse book covers. Only shows books with known lookup info.
+
Excluded Categories: + {html_options style="height:105px;" multiple=multiple name="exccat[]" options=$catlist selected=$userexccat} +
Use Ctrl and click to exclude multiple categories.
+
+
+ + {if $page->site->sabintegrationtype == 2} +
+ SABnzbd Integration + + + + + + + + + + + + + + + + + + + + + + + + +
: + + +
The url of the SAB installation, for example: http://localhost:8080/sabnzbd/ +
+
: + + +
The api key of the SAB installation. Can be the full api key or the nzb api + key (as of SAB 0.6) +
+
: + {html_radios id="sabapikeytype" name='sabapikeytype' values=$sabapikeytype_ids output=$sabapikeytype_names selected=$sabapikeytype_selected separator='
'} +
Select the type of api key you entered in the above setting. Using your full + SAB api key will allow you access to the SAB queue from within this site. +
+
: + {html_options id="sabpriority" name='sabpriority' values=$sabpriority_ids output=$sabpriority_names selected=$sabpriority_selected} +
Set the priority level for NZBs that are added to your queue
+
: + {html_radios id="sabsetting" name='sabsetting' values=$sabsetting_ids output=$sabsetting_names selected=$sabsetting_selected separator='  '}{if $sabsetting_selected == 2}  [ + Clear Cookies + ]{/if} +
Where to store the SAB setting.
Cookie will store the + setting in your browsers coookies and will only work when using your current browser.
• + Site will store the setting in your user account enabling it to work no matter where + you are logged in from.
Please Note: You should only + store your full SAB api key with sites you trust. +
+
+
+ {/if} +
+ NZBVortex Integration + + + + + + + + + +
: + + +
Server URL for NZBVortex found in Preferences -> Remote. Do not + put a / at the end! +
+ Example: http://123.123.123.123:8080 +
+
: + + +
Remote API key for NZBVortex found in Preferences -> Remote. +
+ Example: 52FE-5ABD +
+
+
+ \ No newline at end of file diff --git a/lib/copy_this/www/templates/nntmux/views/frontend/rssheader.tpl b/lib/copy_this/www/templates/nntmux/views/frontend/rssheader.tpl index df68858c7..63e1d460a 100644 --- a/lib/copy_this/www/templates/nntmux/views/frontend/rssheader.tpl +++ b/lib/copy_this/www/templates/nntmux/views/frontend/rssheader.tpl @@ -1,16 +1,17 @@ - - - - -{$site->title|escape}{if $rsstitle!=""} {$rsstitle|escape:"htmlall"}{/if} -{if $rssdesc==""}{$site->title|escape} Feed{else}{$rssdesc|escape:"htmlall"}{/if} -{$serverroot} -en-gb -{$site->email} ({$site->title|escape}) -{$site->meta_keywords} - - {$serverroot}templates/nntmux/images/banner.jpg - {$site->title|escape} - {$serverroot} - Visit {$site->title|escape} - {$site->strapline|escape} - \ No newline at end of file + + + + + {$site->title|escape}{if $rsstitle!=""} {$rsstitle|escape:"htmlall"}{/if} + {if $rssdesc==""}{$site->title|escape} Feed{else}{$rssdesc|escape:"htmlall"}{/if} + {$serverroot} + en-gb + {$site->email} ({$site->title|escape}) + {$site->meta_keywords} + + {$serverroot}templates/nntmux/images/banner.jpg + {$site->title|escape} + {$serverroot} + Visit {$site->title|escape} - {$site->strapline|escape} + \ No newline at end of file diff --git a/lib/dump_prehash.php b/lib/dump_prehash.php index cd13317a0..a8eb8ed21 100644 --- a/lib/dump_prehash.php +++ b/lib/dump_prehash.php @@ -1,6 +1,6 @@ query('CREATE TABLE tmp_pre LIKE prehash'); // Drop indexes on tmp_pre - echo $c->info("Dropping indexes from temporary table."); + echo $c->info("Dropping indexes from temporary table."); $db->query('ALTER TABLE tmp_pre DROP INDEX `ix_prehash_md5`, DROP INDEX `ix_prehash_nfo`, DROP INDEX `ix_prehash_predate`, DROP INDEX `ix_prehash_source`, DROP INDEX `ix_prehash_title`, DROP INDEX `ix_prehash_requestid`'); $db->query('ALTER TABLE tmp_pre ADD COLUMN groupname VARCHAR (255)'); // Import file into tmp_pre - echo $c->info("Importing data into temporary table."); + echo $c->info("Importing data into temporary table."); if ($argv[1] == 'remote') { $db->queryDirect("LOAD DATA LOCAL INFILE '" . $path . "' IGNORE INTO TABLE tmp_pre FIELDS TERMINATED BY '\t\t' ENCLOSED BY \"'\" LINES TERMINATED BY '\r\n' (title, nfo, size, files, nuked, nukereason, category, predate, source, md5, requestID, groupname)"); } else { @@ -62,17 +62,18 @@ if (isset($argv[1]) && $argv[1] == 'export' && isset($argv[2])) { } // Insert and update table - echo $c->info("Inserting data into" . $table. "table."); + echo $c->info("Inserting data into" . $table . "table."); $db->queryDirect('INSERT INTO ' . $table . ' (title, nfo, size, files, nuked, nukereason, category, predate, source, md5, requestID, groupID) SELECT t.title, t.nfo, t.size, t.category, t.predate, t.source, t.md5, t.requestID, IF(g.ID IS NOT NULL, g.ID, 0) FROM tmp_pre t LEFT OUTER JOIN groups g ON t.groupname = g.name ON DUPLICATE KEY UPDATE prehash.nfo = IF(prehash.nfo is null, t.nfo, prehash.nfo), prehash.size = IF(prehash.size is null, t.size, prehash.size), prehash.files = IF(prehash.files is null, t.files, prehash.files), prehash.nuked = IF(prehash.nuked is null, t.nuked, prehash.nuked), prehash.nukereason = IF(prehash.nukereason is null, t.nukereason, prehash.nukereason), prehash.category = IF(prehash.category is null, t.category, prehash.category), prehash.requestID = IF(prehash.requestID = 0, t.requestID, prehash.requestID), prehash.groupID = IF(g.ID IS NOT NULL, g.ID, 0)'); // Drop tmp_pre table - echo $c->info("Dropping temporary table"); + echo $c->info("Dropping temporary table"); $db->query('DROP TABLE IF EXISTS tmp_pre'); - echo $c->info("Import complete"); + echo $c->info("Import complete"); } else { exit($c->error("\nThis script can export or import a prehash dump file. You may use the full path, or a relative path.\n" - . "For importing, the script insert new rows and update existing matched rows. For databases not on the local system, use remote, else use local.\n" - . "For exporting, the path must be writeable by mysql, any existing file[prebd_dump.csv] will be overwritten.\n\n" - . "php $argv[0] export /path/to/write/to ...: To export.\n" - . "php $argv[0] [remote | local] /path/to/filename ...: To import.\n")); + . "For importing, the script insert new rows and update existing matched rows. For databases not on the local system, use remote, else use local.\n" + . "For exporting, the path must be writeable by mysql, any existing file[prebd_dump.csv] will be overwritten.\n\n" + . "php $argv[0] export /path/to/write/to ...: To export.\n" + . "php $argv[0] [remote | local] /path/to/filename ...: To import.\n" + )); } \ No newline at end of file diff --git a/lib/requestID.php b/lib/requestID.php index bcad36f78..5a3a33e5a 100644 --- a/lib/requestID.php +++ b/lib/requestID.php @@ -1,8 +1,8 @@ error("\nThis script tries to match an MD5 of the releases.name or releases.searchname to predb.md5 doing local lookup only.\n" - . "php requestid.php 1000 true ...: to limit to 1000 sorted by newest postdate and show renaming.\n" - . "php requestid.php full true ...: to run on full database and show renaming.\n" - . "php requestid.php all true ...: to run on all hashed releases(including previously renamed) and show renaiming." - . "In addition an optional final argument is time, in minutes, to check releases that have previously been checked.\n")); + . "php requestid.php 1000 true ...: to limit to 1000 sorted by newest postdate and show renaming.\n" + . "php requestid.php full true ...: to run on full database and show renaming.\n" + . "php requestid.php all true ...: to run on all hashed releases(including previously renamed) and show renaiming." + . "In addition an optional final argument is time, in minutes, to check releases that have previously been checked.\n" + )); } $db = new DB(); @@ -48,135 +49,122 @@ if (isset($argv[1]) && $argv[1] === "all") { $res = $db->queryDirect("SELECT r.ID, r.searchname, r.categoryID, g.name AS groupname FROM releases r LEFT JOIN groups g ON r.groupID = g.ID WHERE (isrenamed = 0 AND isrequestid = 1 " . $time . " AND reqidstatus in (0, -1) ORDER BY postdate DESC LIMIT " . $argv[1]); } - $total = $res->rowCount(); - if ($total > 0) - { - $precount = $db->queryOneRow("SELECT COUNT(*) AS count FROM prehash WHERE requestID > 0"); - echo $c->header("\nComparing ".number_format($total).' releases against '.number_format($precount['count'])." Local requestID's."); +$total = $res->rowCount(); +if ($total > 0) { + $precount = $db->queryOneRow("SELECT COUNT(*) AS count FROM prehash WHERE requestID > 0"); + echo $c->header("\nComparing " . number_format($total) . ' releases against ' . number_format($precount['count']) . " Local requestID's."); sleep(2); - foreach ($res as $row) - { - if (!preg_match('/^\[\d+\]/', $row["searchname"]) && !preg_match('/^\[ \d+ \]/', $row["searchname"])) - { - $db->query(sprintf("UPDATE releases SET reqidstatus = -2 WHERE reqidstatus != 1 AND ID = %d", $row["ID"])); - continue; - } + foreach ($res as $row) { + if (!preg_match('/^\[\d+\]/', $row["searchname"]) && !preg_match('/^\[ \d+ \]/', $row["searchname"])) { + $db->query(sprintf("UPDATE releases SET reqidstatus = -2 WHERE reqidstatus != 1 AND ID = %d", $row["ID"])); + continue; + } - $requestIDtmp = explode(']', substr($row["searchname"], 1)); - $bFound = false; - $newTitle = ''; + $requestIDtmp = explode(']', substr($row["searchname"], 1)); + $bFound = false; + $newTitle = ''; - if (count($requestIDtmp) >= 1) - { - $requestID = (int) trim($requestIDtmp[0]); - if ($requestID != 0 and $requestID != '') - { - // Do a local lookup - $newTitle = localLookup($requestID, $row["groupname"], $row["searchname"]); - if (is_array($newTitle) && $newTitle['title'] != ''){ - $bFound = true; - } - } - } + if (count($requestIDtmp) >= 1) { + $requestID = (int)trim($requestIDtmp[0]); + if ($requestID != 0 and $requestID != '') { + // Do a local lookup + $newTitle = localLookup($requestID, $row["groupname"], $row["searchname"]); + if (is_array($newTitle) && $newTitle['title'] != '') { + $bFound = true; + } + } + } - if ($bFound === true) - { - $title = $newTitle['title']; - $prehashID = $newTitle['ID']; - $groupname = $functions->getByNameByID($row["groupname"]); - $determinedcat = $category->determineCategory($groupname, $title ); - $run = $db->queryDirect(sprintf('UPDATE releases SET rageID = NULL, seriesfull = NULL, season = NULL, episode = NULL, tvtitle = NULL, tvairdate = NULL, imdbID = NULL, musicinfoID = NULL, consoleinfoID = NULL, bookinfoID = NULL, " - . "anidbID = NULL, prehashID = %d, reqidstatus = 1, isrenamed = 1, iscategorized = 1, searchname = %s, categoryID = %d WHERE ID = %d', $prehashID, $db->escapeString($title), $determinedcat, $row['ID'])); - if ($row['searchname'] !== $newTitle) - { - $counter++; - if (isset($argv[2]) && $argv[2] === 'true') - { - $newcatname = $functions->getNameByID($determinedcat); - $oldcatname = $functions->getNameByID($row['categoryID']); + if ($bFound === true) { + $title = $newTitle['title']; + $prehashID = $newTitle['ID']; + $groupname = $functions->getByNameByID($row["groupname"]); + $determinedcat = $category->determineCategory($groupname, $title); + $run = $db->queryDirect(sprintf('UPDATE releases SET rageID = NULL, seriesfull = NULL, season = NULL, episode = NULL, tvtitle = NULL, tvairdate = NULL, imdbID = NULL, musicinfoID = NULL, consoleinfoID = NULL, bookinfoID = NULL, " + . "anidbID = NULL, prehashID = %d, reqidstatus = 1, isrenamed = 1, iscategorized = 1, searchname = %s, categoryID = %d WHERE ID = %d', $prehashID, $db->escapeString($title), $determinedcat, $row['ID'] + ) + ); + if ($row['searchname'] !== $newTitle) { + $counter++; + if (isset($argv[2]) && $argv[2] === 'true') { + $newcatname = $functions->getNameByID($determinedcat); + $oldcatname = $functions->getNameByID($row['categoryID']); - echo $c->headerOver($n.$n.'New name: ').$c->primary($title). - $c->headerOver('Old name: ').$c->primary($row["searchname"]). - $c->headerOver('New cat: ').$c->primary($newcatname). - $c->headerOver('Old cat: ').$c->primary($oldcatname). - $c->headerOver('Group: ').$c->primary($row["groupname"]). - $c->headerOver('Method: ').$c->primary('requestID local'). - $c->headerOver('ReleaseID: ').$c->primary($row["ID"]); - } - else - { - if ($counter % 100 == 0) - { - echo "."; - } - } - } - } - else - { - $db->exec("UPDATE releases SET reqidstatus = -3 WHERE reqidstatus != 1 AND ID = " . $row["ID"]); - echo '.'; - } - } - if ($total > 0) { - echo $c->header("\nRenamed " . number_format($counter) . " releases in " . $consoletools->convertTime(TIME() - $timestart) . "."); - } else { - echo $c->info("\nNothing to do."); - } + echo $c->headerOver($n . $n . 'New name: ') . $c->primary($title) . + $c->headerOver('Old name: ') . $c->primary($row["searchname"]) . + $c->headerOver('New cat: ') . $c->primary($newcatname) . + $c->headerOver('Old cat: ') . $c->primary($oldcatname) . + $c->headerOver('Group: ') . $c->primary($row["groupname"]) . + $c->headerOver('Method: ') . $c->primary('requestID local') . + $c->headerOver('ReleaseID: ') . $c->primary($row["ID"]); + } else { + if ($counter % 100 == 0) { + echo "."; + } + } + } + } else { + $db->exec("UPDATE releases SET reqidstatus = -3 WHERE reqidstatus != 1 AND ID = " . $row["ID"]); + echo '.'; + } + } + if ($total > 0) { + echo $c->header("\nRenamed " . number_format($counter) . " releases in " . $consoletools->convertTime(TIME() - $timestart) . "."); + } else { + echo $c->info("\nNothing to do."); + } } else { - echo $c->info("No work to process\n"); + echo $c->info("No work to process\n"); } - function localLookup($requestID, $groupName, $oldname) - { - $db = new DB(); - $groups = new Groups(); - $functions = new Functions(); - $groupID = $functions->getIDByName($groupName); - $run = $db->queryOneRow(sprintf("SELECT ID, title FROM prehash WHERE requestID = %d AND groupID = %d", $requestID, $groupID)); - if (isset($run["title"]) && preg_match('/s\d+/i', $run["title"]) && !preg_match('/s\d+e\d+/i', $run["title"])) { - return false; - } - if (isset($run["title"])) - return array('title' => $run['title'], 'ID' => $run['ID']); - if (preg_match('/\[#?a\.b\.teevee\]/', $oldname)) - $groupID = $functions->getIDByName('alt.binaries.teevee'); - else if (preg_match('/\[#?a\.b\.moovee\]/', $oldname)) - $groupID = $functions->getIDByName('alt.binaries.moovee'); - else if (preg_match('/\[#?a\.b\.erotica\]/', $oldname)) - $groupID = $functions->getIDByName('alt.binaries.erotica'); - else if (preg_match('/\[#?a\.b\.foreign\]/', $oldname)) - $groupID = $functions->getIDByName('alt.binaries.mom'); - else if ($groupName == 'alt.binaries.etc') - $groupID = $functions->getIDByName('alt.binaries.teevee'); - //groups below are added for testing purposes - else if (preg_match('/\[#?a\.b\.mom\]/', $oldname)) - $groupID = $functions->getIDByName('alt.binaries.mom'); - else if ($groupName == 'alt.binaries.mom') - $groupID = $functions->getIDByName('alt.binaries.mom'); - else if ($groupName == 'alt.binaries.town.xxx') - $groupID = $functions->getIDByName('alt.binaries.erotica'); - else if (preg_match('/\[#?a\.b\.town\.xxx\]/', $oldname)) - $groupID = $functions->getIDByName('alt.binaries.erotica'); - else if ($groupName == 'alt.binaries.tvseries') - $groupID = $functions->getIDByName('alt.binaries.teevee'); - else if (preg_match('/\[#?a\.b\.tvseries\]/', $oldname)) - $groupID = $functions->getIDByName('alt.binaries.teevee'); - else if ($groupName == 'alt.binaries.x264') - $groupID = $functions->getIDByName('alt.binaries.teevee'); - else if (preg_match('/\[#?a\.b\.x264\]/', $oldname)) - $groupID = $functions->getIDByName('alt.binaries.teevee'); - else if ($groupName == 'alt.binaries.town') - $groupID = $functions->getIDByName('alt.binaries.teevee'); - else if (preg_match('/\[#?a\.b\.town\]/', $oldname)) - $groupID = $functions->getIDByName('alt.binaries.teevee'); +function localLookup($requestID, $groupName, $oldname) +{ + $db = new DB(); + $groups = new Groups(); + $functions = new Functions(); + $groupID = $functions->getIDByName($groupName); + $run = $db->queryOneRow(sprintf("SELECT ID, title FROM prehash WHERE requestID = %d AND groupID = %d", $requestID, $groupID)); + if (isset($run["title"]) && preg_match('/s\d+/i', $run["title"]) && !preg_match('/s\d+e\d+/i', $run["title"])) { + return false; + } + if (isset($run["title"])) + return array('title' => $run['title'], 'ID' => $run['ID']); + if (preg_match('/\[#?a\.b\.teevee\]/', $oldname)) + $groupID = $functions->getIDByName('alt.binaries.teevee'); + else if (preg_match('/\[#?a\.b\.moovee\]/', $oldname)) + $groupID = $functions->getIDByName('alt.binaries.moovee'); + else if (preg_match('/\[#?a\.b\.erotica\]/', $oldname)) + $groupID = $functions->getIDByName('alt.binaries.erotica'); + else if (preg_match('/\[#?a\.b\.foreign\]/', $oldname)) + $groupID = $functions->getIDByName('alt.binaries.mom'); + else if ($groupName == 'alt.binaries.etc') + $groupID = $functions->getIDByName('alt.binaries.teevee'); + //groups below are added for testing purposes + else if (preg_match('/\[#?a\.b\.mom\]/', $oldname)) + $groupID = $functions->getIDByName('alt.binaries.mom'); + else if ($groupName == 'alt.binaries.mom') + $groupID = $functions->getIDByName('alt.binaries.mom'); + else if ($groupName == 'alt.binaries.town.xxx') + $groupID = $functions->getIDByName('alt.binaries.erotica'); + else if (preg_match('/\[#?a\.b\.town\.xxx\]/', $oldname)) + $groupID = $functions->getIDByName('alt.binaries.erotica'); + else if ($groupName == 'alt.binaries.tvseries') + $groupID = $functions->getIDByName('alt.binaries.teevee'); + else if (preg_match('/\[#?a\.b\.tvseries\]/', $oldname)) + $groupID = $functions->getIDByName('alt.binaries.teevee'); + else if ($groupName == 'alt.binaries.x264') + $groupID = $functions->getIDByName('alt.binaries.teevee'); + else if (preg_match('/\[#?a\.b\.x264\]/', $oldname)) + $groupID = $functions->getIDByName('alt.binaries.teevee'); + else if ($groupName == 'alt.binaries.town') + $groupID = $functions->getIDByName('alt.binaries.teevee'); + else if (preg_match('/\[#?a\.b\.town\]/', $oldname)) + $groupID = $functions->getIDByName('alt.binaries.teevee'); - - $run = $db->queryOneRow(sprintf("SELECT ID, title FROM prehash WHERE requestID = %d AND groupID = %d", $requestID, $groupID)); - if (isset($run['title'])) - return array('title' => $run['title'], 'ID' => $run['ID']); - } -?> \ No newline at end of file + $run = $db->queryOneRow(sprintf("SELECT ID, title FROM prehash WHERE requestID = %d AND groupID = %d", $requestID, $groupID)); + if (isset($run['title'])) + return array('title' => $run['title'], 'ID' => $run['ID']); +} \ No newline at end of file diff --git a/lib/simple_html_dom.php b/lib/simple_html_dom.php index 9a7b2f668..8aaaf0041 100644 --- a/lib/simple_html_dom.php +++ b/lib/simple_html_dom.php @@ -30,35 +30,36 @@ * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * - * @author S.C. Chen - * @author John Schlick - * @author Rus Carroll - * @version 1.5 ($Rev: 196 $) - * @package PlaceLocalInclude + * @author S.C. Chen + * @author John Schlick + * @author Rus Carroll + * @version 1.5 ($Rev: 196 $) + * @package PlaceLocalInclude * @subpackage simple_html_dom */ /** * All of the Defines for the classes below. + * * @author S.C. Chen */ define('HDOM_TYPE_ELEMENT', 1); define('HDOM_TYPE_COMMENT', 2); -define('HDOM_TYPE_TEXT', 3); -define('HDOM_TYPE_ENDTAG', 4); -define('HDOM_TYPE_ROOT', 5); +define('HDOM_TYPE_TEXT', 3); +define('HDOM_TYPE_ENDTAG', 4); +define('HDOM_TYPE_ROOT', 5); define('HDOM_TYPE_UNKNOWN', 6); define('HDOM_QUOTE_DOUBLE', 0); define('HDOM_QUOTE_SINGLE', 1); -define('HDOM_QUOTE_NO', 3); -define('HDOM_INFO_BEGIN', 0); -define('HDOM_INFO_END', 1); -define('HDOM_INFO_QUOTE', 2); -define('HDOM_INFO_SPACE', 3); -define('HDOM_INFO_TEXT', 4); -define('HDOM_INFO_INNER', 5); -define('HDOM_INFO_OUTER', 6); -define('HDOM_INFO_ENDSPACE',7); +define('HDOM_QUOTE_NO', 3); +define('HDOM_INFO_BEGIN', 0); +define('HDOM_INFO_END', 1); +define('HDOM_INFO_QUOTE', 2); +define('HDOM_INFO_SPACE', 3); +define('HDOM_INFO_TEXT', 4); +define('HDOM_INFO_INNER', 5); +define('HDOM_INFO_OUTER', 6); +define('HDOM_INFO_ENDSPACE', 7); define('DEFAULT_TARGET_CHARSET', 'UTF-8'); define('DEFAULT_BR_TEXT', "\r\n"); define('DEFAULT_SPAN_TEXT', " "); @@ -67,40 +68,41 @@ define('MAX_FILE_SIZE', 600000); // ----------------------------------------------------------------------------- // get html dom from file // $maxlen is defined in the code as PHP_STREAM_COPY_ALL which is defined as -1. -function file_get_html($url, $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) +function file_get_html($url, $use_include_path = false, $context = null, $offset = -1, $maxLen = -1, $lowercase = true, $forceTagsClosed = true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN = true, $defaultBRText = DEFAULT_BR_TEXT, $defaultSpanText = DEFAULT_SPAN_TEXT) { - // We DO force the tags to be terminated. - $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText); - // For sourceforge users: uncomment the next line and comment the retreive_url_contents line 2 lines down if it is not already done. - $contents = file_get_contents($url, $use_include_path, $context, $offset); - // Paperg - use our own mechanism for getting the contents as we want to control the timeout. - //$contents = retrieve_url_contents($url); - if (empty($contents) || strlen($contents) > MAX_FILE_SIZE) - { - return false; - } - // The second parameter can force the selectors to all be lowercase. - $dom->load($contents, $lowercase, $stripRN); - return $dom; + // We DO force the tags to be terminated. + $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText); + // For sourceforge users: uncomment the next line and comment the retreive_url_contents line 2 lines down if it is not already done. + $contents = file_get_contents($url, $use_include_path, $context, $offset); + // Paperg - use our own mechanism for getting the contents as we want to control the timeout. + //$contents = retrieve_url_contents($url); + if (empty($contents) || strlen($contents) > MAX_FILE_SIZE) { + return false; + } + // The second parameter can force the selectors to all be lowercase. + $dom->load($contents, $lowercase, $stripRN); + + return $dom; } // get html dom from string -function str_get_html($str, $lowercase=true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) +function str_get_html($str, $lowercase = true, $forceTagsClosed = true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN = true, $defaultBRText = DEFAULT_BR_TEXT, $defaultSpanText = DEFAULT_SPAN_TEXT) { - $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText); - if (empty($str) || strlen($str) > MAX_FILE_SIZE) - { - $dom->clear(); - return false; - } - $dom->load($str, $lowercase, $stripRN); - return $dom; + $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText); + if (empty($str) || strlen($str) > MAX_FILE_SIZE) { + $dom->clear(); + + return false; + } + $dom->load($str, $lowercase, $stripRN); + + return $dom; } // dump html dom tree -function dump_html_tree($node, $show_attr=true, $deep=0) +function dump_html_tree($node, $show_attr = true, $deep = 0) { - $node->dump($node); + $node->dump($node); } @@ -113,850 +115,944 @@ function dump_html_tree($node, $show_attr=true, $deep=0) */ class simple_html_dom_node { - public $nodetype = HDOM_TYPE_TEXT; - public $tag = 'text'; - public $attr = array(); - public $children = array(); - public $nodes = array(); - public $parent = null; - // The "info" array - see HDOM_INFO_... for what each element contains. - public $_ = array(); - public $tag_start = 0; - private $dom = null; - - function __construct($dom) - { - $this->dom = $dom; - $dom->nodes[] = $this; - } - - function __destruct() - { - $this->clear(); - } - - function __toString() - { - return $this->outertext(); - } - - // clean up memory due to php5 circular references memory leak... - function clear() - { - $this->dom = null; - $this->nodes = null; - $this->parent = null; - $this->children = null; - } - - // dump node's tree - function dump($show_attr=true, $deep=0) - { - $lead = str_repeat(' ', $deep); - - echo $lead.$this->tag; - if ($show_attr && count($this->attr)>0) - { - echo '('; - foreach ($this->attr as $k=>$v) - echo "[$k]=>\"".$this->$k.'", '; - echo ')'; - } - echo "\n"; - - if ($this->nodes) - { - foreach ($this->nodes as $c) - { - $c->dump($show_attr, $deep+1); - } - } - } - - - // Debugging function to dump a single dom node with a bunch of information about it. - function dump_node($echo=true) - { - - $string = $this->tag; - if (count($this->attr)>0) - { - $string .= '('; - foreach ($this->attr as $k=>$v) - { - $string .= "[$k]=>\"".$this->$k.'", '; - } - $string .= ')'; - } - if (count($this->_)>0) - { - $string .= ' $_ ('; - foreach ($this->_ as $k=>$v) - { - if (is_array($v)) - { - $string .= "[$k]=>("; - foreach ($v as $k2=>$v2) - { - $string .= "[$k2]=>\"".$v2.'", '; - } - $string .= ")"; - } else { - $string .= "[$k]=>\"".$v.'", '; - } - } - $string .= ")"; - } - - if (isset($this->text)) - { - $string .= " text: (" . $this->text . ")"; - } - - $string .= " HDOM_INNER_INFO: '"; - if (isset($node->_[HDOM_INFO_INNER])) - { - $string .= $node->_[HDOM_INFO_INNER] . "'"; - } - else - { - $string .= ' NULL '; - } - - $string .= " children: " . count($this->children); - $string .= " nodes: " . count($this->nodes); - $string .= " tag_start: " . $this->tag_start; - $string .= "\n"; - - if ($echo) - { - echo $string; - return; - } - else - { - return $string; - } - } - - // returns the parent of node - // If a node is passed in, it will reset the parent of the current node to that one. - function parent($parent=null) - { - // I am SURE that this doesn't work properly. - // It fails to unset the current node from it's current parents nodes or children list first. - if ($parent !== null) - { - $this->parent = $parent; - $this->parent->nodes[] = $this; - $this->parent->children[] = $this; - } - - return $this->parent; - } - - // verify that node has children - function has_child() - { - return !empty($this->children); - } - - // returns children of node - function children($idx=-1) - { - if ($idx===-1) - { - return $this->children; - } - if (isset($this->children[$idx])) return $this->children[$idx]; - return null; - } - - // returns the first child of node - function first_child() - { - if (count($this->children)>0) - { - return $this->children[0]; - } - return null; - } - - // returns the last child of node - function last_child() - { - if (($count=count($this->children))>0) - { - return $this->children[$count-1]; - } - return null; - } - - // returns the next sibling of node - function next_sibling() - { - if ($this->parent===null) - { - return null; - } - - $idx = 0; - $count = count($this->parent->children); - while ($idx<$count && $this!==$this->parent->children[$idx]) - { - ++$idx; - } - if (++$idx>=$count) - { - return null; - } - return $this->parent->children[$idx]; - } - - // returns the previous sibling of node - function prev_sibling() - { - if ($this->parent===null) return null; - $idx = 0; - $count = count($this->parent->children); - while ($idx<$count && $this!==$this->parent->children[$idx]) - ++$idx; - if (--$idx<0) return null; - return $this->parent->children[$idx]; - } - - // function to locate a specific ancestor tag in the path to the root. - function find_ancestor_tag($tag) - { - global $debugObject; - if (is_object($debugObject)) { $debugObject->debugLogEntry(1); } - - // Start by including ourselves in the comparison. - $returnDom = $this; - - while (!is_null($returnDom)) - { - if (is_object($debugObject)) { $debugObject->debugLog(2, "Current tag is: " . $returnDom->tag); } - - if ($returnDom->tag == $tag) - { - break; - } - $returnDom = $returnDom->parent; - } - return $returnDom; - } - - // get dom node's inner html - function innertext() - { - if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER]; - if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); - - $ret = ''; - foreach ($this->nodes as $n) - $ret .= $n->outertext(); - return $ret; - } - - // get dom node's outer text (with tag) - function outertext() - { - global $debugObject; - if (is_object($debugObject)) - { - $text = ''; - if ($this->tag == 'text') - { - if (!empty($this->text)) - { - $text = " with text: " . $this->text; - } - } - $debugObject->debugLog(1, 'Innertext of tag: ' . $this->tag . $text); - } - - if ($this->tag==='root') return $this->innertext(); - - // trigger callback - if ($this->dom && $this->dom->callback!==null) - { - call_user_func_array($this->dom->callback, array($this)); - } - - if (isset($this->_[HDOM_INFO_OUTER])) return $this->_[HDOM_INFO_OUTER]; - if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); - - // render begin tag - if ($this->dom && $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]) - { - $ret = $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]->makeup(); - } else { - $ret = ""; - } - - // render inner text - if (isset($this->_[HDOM_INFO_INNER])) - { - // If it's a br tag... don't return the HDOM_INNER_INFO that we may or may not have added. - if ($this->tag != "br") - { - $ret .= $this->_[HDOM_INFO_INNER]; - } - } else { - if ($this->nodes) - { - foreach ($this->nodes as $n) - { - $ret .= $this->convert_text($n->outertext()); - } - } - } - - // render end tag - if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END]!=0) - $ret .= 'tag.'>'; - return $ret; - } - - // get dom node's plain text - function text() - { - if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER]; - switch ($this->nodetype) - { - case HDOM_TYPE_TEXT: return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); - case HDOM_TYPE_COMMENT: return ''; - case HDOM_TYPE_UNKNOWN: return ''; - } - if (strcasecmp($this->tag, 'script')===0) return ''; - if (strcasecmp($this->tag, 'style')===0) return ''; - - $ret = ''; - // In rare cases, (always node type 1 or HDOM_TYPE_ELEMENT - observed for some span tags, and some p tags) $this->nodes is set to NULL. - // NOTE: This indicates that there is a problem where it's set to NULL without a clear happening. - // WHY is this happening? - if (!is_null($this->nodes)) - { - foreach ($this->nodes as $n) - { - $ret .= $this->convert_text($n->text()); - } - - // If this node is a span... add a space at the end of it so multiple spans don't run into each other. This is plaintext after all. - if ($this->tag == "span") - { - $ret .= $this->dom->default_span_text; - } - - - } - return $ret; - } - - function xmltext() - { - $ret = $this->innertext(); - $ret = str_ireplace('', '', $ret); - return $ret; - } - - // build node's text with tag - function makeup() - { - // text, comment, unknown - if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); - - $ret = '<'.$this->tag; - $i = -1; - - foreach ($this->attr as $key=>$val) - { - ++$i; - - // skip removed attribute - if ($val===null || $val===false) - continue; - - $ret .= $this->_[HDOM_INFO_SPACE][$i][0]; - //no value attr: nowrap, checked selected... - if ($val===true) - $ret .= $key; - else { - switch ($this->_[HDOM_INFO_QUOTE][$i]) - { - case HDOM_QUOTE_DOUBLE: $quote = '"'; break; - case HDOM_QUOTE_SINGLE: $quote = '\''; break; - default: $quote = ''; - } - $ret .= $key.$this->_[HDOM_INFO_SPACE][$i][1].'='.$this->_[HDOM_INFO_SPACE][$i][2].$quote.$val.$quote; - } - } - $ret = $this->dom->restore_noise($ret); - return $ret . $this->_[HDOM_INFO_ENDSPACE] . '>'; - } - - // find elements by css selector - //PaperG - added ability for find to lowercase the value of the selector. - function find($selector, $idx=null, $lowercase=false) - { - $selectors = $this->parse_selector($selector); - if (($count=count($selectors))===0) return array(); - $found_keys = array(); - - // find each selector - for ($c=0; $c<$count; ++$c) - { - // The change on the below line was documented on the sourceforge code tracker id 2788009 - // used to be: if (($levle=count($selectors[0]))===0) return array(); - if (($levle=count($selectors[$c]))===0) return array(); - if (!isset($this->_[HDOM_INFO_BEGIN])) return array(); - - $head = array($this->_[HDOM_INFO_BEGIN]=>1); - - // handle descendant selectors, no recursive! - for ($l=0; $l<$levle; ++$l) - { - $ret = array(); - foreach ($head as $k=>$v) - { - $n = ($k===-1) ? $this->dom->root : $this->dom->nodes[$k]; - //PaperG - Pass this optional parameter on to the seek function. - $n->seek($selectors[$c][$l], $ret, $lowercase); - } - $head = $ret; - } - - foreach ($head as $k=>$v) - { - if (!isset($found_keys[$k])) - $found_keys[$k] = 1; - } - } - - // sort keys - ksort($found_keys); - - $found = array(); - foreach ($found_keys as $k=>$v) - $found[] = $this->dom->nodes[$k]; - - // return nth-element or array - if (is_null($idx)) return $found; - else if ($idx<0) $idx = count($found) + $idx; - return (isset($found[$idx])) ? $found[$idx] : null; - } - - // seek for given conditions - // PaperG - added parameter to allow for case insensitive testing of the value of a selector. - protected function seek($selector, &$ret, $lowercase=false) - { - global $debugObject; - if (is_object($debugObject)) { $debugObject->debugLogEntry(1); } - - list($tag, $key, $val, $exp, $no_key) = $selector; - - // xpath index - if ($tag && $key && is_numeric($key)) - { - $count = 0; - foreach ($this->children as $c) - { - if ($tag==='*' || $tag===$c->tag) { - if (++$count==$key) { - $ret[$c->_[HDOM_INFO_BEGIN]] = 1; - return; - } - } - } - return; - } - - $end = (!empty($this->_[HDOM_INFO_END])) ? $this->_[HDOM_INFO_END] : 0; - if ($end==0) { - $parent = $this->parent; - while (!isset($parent->_[HDOM_INFO_END]) && $parent!==null) { - $end -= 1; - $parent = $parent->parent; - } - $end += $parent->_[HDOM_INFO_END]; - } - - for ($i=$this->_[HDOM_INFO_BEGIN]+1; $i<$end; ++$i) { - $node = $this->dom->nodes[$i]; - - $pass = true; - - if ($tag==='*' && !$key) { - if (in_array($node, $this->children, true)) - $ret[$i] = 1; - continue; - } - - // compare tag - if ($tag && $tag!=$node->tag && $tag!=='*') {$pass=false;} - // compare key - if ($pass && $key) { - if ($no_key) { - if (isset($node->attr[$key])) $pass=false; - } else { - if (($key != "plaintext") && !isset($node->attr[$key])) $pass=false; - } - } - // compare value - if ($pass && $key && $val && $val!=='*') { - // If they have told us that this is a "plaintext" search then we want the plaintext of the node - right? - if ($key == "plaintext") { - // $node->plaintext actually returns $node->text(); - $nodeKeyValue = $node->text(); - } else { - // this is a normal search, we want the value of that attribute of the tag. - $nodeKeyValue = $node->attr[$key]; - } - if (is_object($debugObject)) {$debugObject->debugLog(2, "testing node: " . $node->tag . " for attribute: " . $key . $exp . $val . " where nodes value is: " . $nodeKeyValue);} - - //PaperG - If lowercase is set, do a case insensitive test of the value of the selector. - if ($lowercase) { - $check = $this->match($exp, strtolower($val), strtolower($nodeKeyValue)); - } else { - $check = $this->match($exp, $val, $nodeKeyValue); - } - if (is_object($debugObject)) {$debugObject->debugLog(2, "after match: " . ($check ? "true" : "false"));} - - // handle multiple class - if (!$check && strcasecmp($key, 'class')===0) { - foreach (explode(' ',$node->attr[$key]) as $k) { - // Without this, there were cases where leading, trailing, or double spaces lead to our comparing blanks - bad form. - if (!empty($k)) { - if ($lowercase) { - $check = $this->match($exp, strtolower($val), strtolower($k)); - } else { - $check = $this->match($exp, $val, $k); - } - if ($check) break; - } - } - } - if (!$check) $pass = false; - } - if ($pass) $ret[$i] = 1; - unset($node); - } - // It's passed by reference so this is actually what this function returns. - if (is_object($debugObject)) {$debugObject->debugLog(1, "EXIT - ret: ", $ret);} - } - - protected function match($exp, $pattern, $value) { - global $debugObject; - if (is_object($debugObject)) {$debugObject->debugLogEntry(1);} - - switch ($exp) { - case '=': - return ($value===$pattern); - case '!=': - return ($value!==$pattern); - case '^=': - return preg_match("/^".preg_quote($pattern,'/')."/", $value); - case '$=': - return preg_match("/".preg_quote($pattern,'/')."$/", $value); - case '*=': - if ($pattern[0]=='/') { - return preg_match($pattern, $value); - } - return preg_match("/".$pattern."/i", $value); - } - return false; - } - - protected function parse_selector($selector_string) { - global $debugObject; - if (is_object($debugObject)) {$debugObject->debugLogEntry(1);} - - // pattern of CSS selectors, modified from mootools - // Paperg: Add the colon to the attrbute, so that it properly finds like google does. - // Note: if you try to look at this attribute, yo MUST use getAttribute since $dom->x:y will fail the php syntax check. + public $nodetype = HDOM_TYPE_TEXT; + public $tag = 'text'; + public $attr = array(); + public $children = array(); + public $nodes = array(); + public $parent = null; + // The "info" array - see HDOM_INFO_... for what each element contains. + public $_ = array(); + public $tag_start = 0; + private $dom = null; + + function __construct($dom) + { + $this->dom = $dom; + $dom->nodes[] = $this; + } + + function __destruct() + { + $this->clear(); + } + + function __toString() + { + return $this->outertext(); + } + + // clean up memory due to php5 circular references memory leak... + function clear() + { + $this->dom = null; + $this->nodes = null; + $this->parent = null; + $this->children = null; + } + + // dump node's tree + function dump($show_attr = true, $deep = 0) + { + $lead = str_repeat(' ', $deep); + + echo $lead . $this->tag; + if ($show_attr && count($this->attr) > 0) { + echo '('; + foreach ($this->attr as $k => $v) + echo "[$k]=>\"" . $this->$k . '", '; + echo ')'; + } + echo "\n"; + + if ($this->nodes) { + foreach ($this->nodes as $c) { + $c->dump($show_attr, $deep + 1); + } + } + } + + + // Debugging function to dump a single dom node with a bunch of information about it. + function dump_node($echo = true) + { + + $string = $this->tag; + if (count($this->attr) > 0) { + $string .= '('; + foreach ($this->attr as $k => $v) { + $string .= "[$k]=>\"" . $this->$k . '", '; + } + $string .= ')'; + } + if (count($this->_) > 0) { + $string .= ' $_ ('; + foreach ($this->_ as $k => $v) { + if (is_array($v)) { + $string .= "[$k]=>("; + foreach ($v as $k2 => $v2) { + $string .= "[$k2]=>\"" . $v2 . '", '; + } + $string .= ")"; + } else { + $string .= "[$k]=>\"" . $v . '", '; + } + } + $string .= ")"; + } + + if (isset($this->text)) { + $string .= " text: (" . $this->text . ")"; + } + + $string .= " HDOM_INNER_INFO: '"; + if (isset($node->_[HDOM_INFO_INNER])) { + $string .= $node->_[HDOM_INFO_INNER] . "'"; + } else { + $string .= ' NULL '; + } + + $string .= " children: " . count($this->children); + $string .= " nodes: " . count($this->nodes); + $string .= " tag_start: " . $this->tag_start; + $string .= "\n"; + + if ($echo) { + echo $string; + + return; + } else { + return $string; + } + } + + // returns the parent of node + // If a node is passed in, it will reset the parent of the current node to that one. + function parent($parent = null) + { + // I am SURE that this doesn't work properly. + // It fails to unset the current node from it's current parents nodes or children list first. + if ($parent !== null) { + $this->parent = $parent; + $this->parent->nodes[] = $this; + $this->parent->children[] = $this; + } + + return $this->parent; + } + + // verify that node has children + function has_child() + { + return !empty($this->children); + } + + // returns children of node + function children($idx = -1) + { + if ($idx === -1) { + return $this->children; + } + if (isset($this->children[$idx])) return $this->children[$idx]; + + return null; + } + + // returns the first child of node + function first_child() + { + if (count($this->children) > 0) { + return $this->children[0]; + } + + return null; + } + + // returns the last child of node + function last_child() + { + if (($count = count($this->children)) > 0) { + return $this->children[$count - 1]; + } + + return null; + } + + // returns the next sibling of node + function next_sibling() + { + if ($this->parent === null) { + return null; + } + + $idx = 0; + $count = count($this->parent->children); + while ($idx < $count && $this !== $this->parent->children[$idx]) { + ++$idx; + } + if (++$idx >= $count) { + return null; + } + + return $this->parent->children[$idx]; + } + + // returns the previous sibling of node + function prev_sibling() + { + if ($this->parent === null) return null; + $idx = 0; + $count = count($this->parent->children); + while ($idx < $count && $this !== $this->parent->children[$idx]) + ++$idx; + if (--$idx < 0) return null; + + return $this->parent->children[$idx]; + } + + // function to locate a specific ancestor tag in the path to the root. + function find_ancestor_tag($tag) + { + global $debugObject; + if (is_object($debugObject)) { + $debugObject->debugLogEntry(1); + } + + // Start by including ourselves in the comparison. + $returnDom = $this; + + while (!is_null($returnDom)) { + if (is_object($debugObject)) { + $debugObject->debugLog(2, "Current tag is: " . $returnDom->tag); + } + + if ($returnDom->tag == $tag) { + break; + } + $returnDom = $returnDom->parent; + } + + return $returnDom; + } + + // get dom node's inner html + function innertext() + { + if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER]; + if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); + + $ret = ''; + foreach ($this->nodes as $n) + $ret .= $n->outertext(); + + return $ret; + } + + // get dom node's outer text (with tag) + function outertext() + { + global $debugObject; + if (is_object($debugObject)) { + $text = ''; + if ($this->tag == 'text') { + if (!empty($this->text)) { + $text = " with text: " . $this->text; + } + } + $debugObject->debugLog(1, 'Innertext of tag: ' . $this->tag . $text); + } + + if ($this->tag === 'root') return $this->innertext(); + + // trigger callback + if ($this->dom && $this->dom->callback !== null) { + call_user_func_array($this->dom->callback, array($this)); + } + + if (isset($this->_[HDOM_INFO_OUTER])) return $this->_[HDOM_INFO_OUTER]; + if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); + + // render begin tag + if ($this->dom && $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]) { + $ret = $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]->makeup(); + } else { + $ret = ""; + } + + // render inner text + if (isset($this->_[HDOM_INFO_INNER])) { + // If it's a br tag... don't return the HDOM_INNER_INFO that we may or may not have added. + if ($this->tag != "br") { + $ret .= $this->_[HDOM_INFO_INNER]; + } + } else { + if ($this->nodes) { + foreach ($this->nodes as $n) { + $ret .= $this->convert_text($n->outertext()); + } + } + } + + // render end tag + if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END] != 0) + $ret .= 'tag . '>'; + + return $ret; + } + + // get dom node's plain text + function text() + { + if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER]; + switch ($this->nodetype) { + case HDOM_TYPE_TEXT: + return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); + case HDOM_TYPE_COMMENT: + return ''; + case HDOM_TYPE_UNKNOWN: + return ''; + } + if (strcasecmp($this->tag, 'script') === 0) return ''; + if (strcasecmp($this->tag, 'style') === 0) return ''; + + $ret = ''; + // In rare cases, (always node type 1 or HDOM_TYPE_ELEMENT - observed for some span tags, and some p tags) $this->nodes is set to NULL. + // NOTE: This indicates that there is a problem where it's set to NULL without a clear happening. + // WHY is this happening? + if (!is_null($this->nodes)) { + foreach ($this->nodes as $n) { + $ret .= $this->convert_text($n->text()); + } + + // If this node is a span... add a space at the end of it so multiple spans don't run into each other. This is plaintext after all. + if ($this->tag == "span") { + $ret .= $this->dom->default_span_text; + } + + + } + + return $ret; + } + + function xmltext() + { + $ret = $this->innertext(); + $ret = str_ireplace('', '', $ret); + + return $ret; + } + + // build node's text with tag + function makeup() + { + // text, comment, unknown + if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); + + $ret = '<' . $this->tag; + $i = -1; + + foreach ($this->attr as $key => $val) { + ++$i; + + // skip removed attribute + if ($val === null || $val === false) + continue; + + $ret .= $this->_[HDOM_INFO_SPACE][$i][0]; + //no value attr: nowrap, checked selected... + if ($val === true) + $ret .= $key; + else { + switch ($this->_[HDOM_INFO_QUOTE][$i]) { + case HDOM_QUOTE_DOUBLE: + $quote = '"'; + break; + case HDOM_QUOTE_SINGLE: + $quote = '\''; + break; + default: + $quote = ''; + } + $ret .= $key . $this->_[HDOM_INFO_SPACE][$i][1] . '=' . $this->_[HDOM_INFO_SPACE][$i][2] . $quote . $val . $quote; + } + } + $ret = $this->dom->restore_noise($ret); + + return $ret . $this->_[HDOM_INFO_ENDSPACE] . '>'; + } + + // find elements by css selector + //PaperG - added ability for find to lowercase the value of the selector. + function find($selector, $idx = null, $lowercase = false) + { + $selectors = $this->parse_selector($selector); + if (($count = count($selectors)) === 0) return array(); + $found_keys = array(); + + // find each selector + for ($c = 0; $c < $count; ++$c) { + // The change on the below line was documented on the sourceforge code tracker id 2788009 + // used to be: if (($levle=count($selectors[0]))===0) return array(); + if (($levle = count($selectors[$c])) === 0) return array(); + if (!isset($this->_[HDOM_INFO_BEGIN])) return array(); + + $head = array($this->_[HDOM_INFO_BEGIN] => 1); + + // handle descendant selectors, no recursive! + for ($l = 0; $l < $levle; ++$l) { + $ret = array(); + foreach ($head as $k => $v) { + $n = ($k === -1) ? $this->dom->root : $this->dom->nodes[$k]; + //PaperG - Pass this optional parameter on to the seek function. + $n->seek($selectors[$c][$l], $ret, $lowercase); + } + $head = $ret; + } + + foreach ($head as $k => $v) { + if (!isset($found_keys[$k])) + $found_keys[$k] = 1; + } + } + + // sort keys + ksort($found_keys); + + $found = array(); + foreach ($found_keys as $k => $v) + $found[] = $this->dom->nodes[$k]; + + // return nth-element or array + if (is_null($idx)) return $found; + else if ($idx < 0) $idx = count($found) + $idx; + + return (isset($found[$idx])) ? $found[$idx] : null; + } + + // seek for given conditions + // PaperG - added parameter to allow for case insensitive testing of the value of a selector. + protected function seek($selector, &$ret, $lowercase = false) + { + global $debugObject; + if (is_object($debugObject)) { + $debugObject->debugLogEntry(1); + } + + list($tag, $key, $val, $exp, $no_key) = $selector; + + // xpath index + if ($tag && $key && is_numeric($key)) { + $count = 0; + foreach ($this->children as $c) { + if ($tag === '*' || $tag === $c->tag) { + if (++$count == $key) { + $ret[$c->_[HDOM_INFO_BEGIN]] = 1; + + return; + } + } + } + + return; + } + + $end = (!empty($this->_[HDOM_INFO_END])) ? $this->_[HDOM_INFO_END] : 0; + if ($end == 0) { + $parent = $this->parent; + while (!isset($parent->_[HDOM_INFO_END]) && $parent !== null) { + $end -= 1; + $parent = $parent->parent; + } + $end += $parent->_[HDOM_INFO_END]; + } + + for ($i = $this->_[HDOM_INFO_BEGIN] + 1; $i < $end; ++$i) { + $node = $this->dom->nodes[$i]; + + $pass = true; + + if ($tag === '*' && !$key) { + if (in_array($node, $this->children, true)) + $ret[$i] = 1; + continue; + } + + // compare tag + if ($tag && $tag != $node->tag && $tag !== '*') { + $pass = false; + } + // compare key + if ($pass && $key) { + if ($no_key) { + if (isset($node->attr[$key])) $pass = false; + } else { + if (($key != "plaintext") && !isset($node->attr[$key])) $pass = false; + } + } + // compare value + if ($pass && $key && $val && $val !== '*') { + // If they have told us that this is a "plaintext" search then we want the plaintext of the node - right? + if ($key == "plaintext") { + // $node->plaintext actually returns $node->text(); + $nodeKeyValue = $node->text(); + } else { + // this is a normal search, we want the value of that attribute of the tag. + $nodeKeyValue = $node->attr[$key]; + } + if (is_object($debugObject)) { + $debugObject->debugLog(2, "testing node: " . $node->tag . " for attribute: " . $key . $exp . $val . " where nodes value is: " . $nodeKeyValue); + } + + //PaperG - If lowercase is set, do a case insensitive test of the value of the selector. + if ($lowercase) { + $check = $this->match($exp, strtolower($val), strtolower($nodeKeyValue)); + } else { + $check = $this->match($exp, $val, $nodeKeyValue); + } + if (is_object($debugObject)) { + $debugObject->debugLog(2, "after match: " . ($check ? "true" : "false")); + } + + // handle multiple class + if (!$check && strcasecmp($key, 'class') === 0) { + foreach (explode(' ', $node->attr[$key]) as $k) { + // Without this, there were cases where leading, trailing, or double spaces lead to our comparing blanks - bad form. + if (!empty($k)) { + if ($lowercase) { + $check = $this->match($exp, strtolower($val), strtolower($k)); + } else { + $check = $this->match($exp, $val, $k); + } + if ($check) break; + } + } + } + if (!$check) $pass = false; + } + if ($pass) $ret[$i] = 1; + unset($node); + } + // It's passed by reference so this is actually what this function returns. + if (is_object($debugObject)) { + $debugObject->debugLog(1, "EXIT - ret: ", $ret); + } + } + + protected function match($exp, $pattern, $value) + { + global $debugObject; + if (is_object($debugObject)) { + $debugObject->debugLogEntry(1); + } + + switch ($exp) { + case '=': + return ($value === $pattern); + case '!=': + return ($value !== $pattern); + case '^=': + return preg_match("/^" . preg_quote($pattern, '/') . "/", $value); + case '$=': + return preg_match("/" . preg_quote($pattern, '/') . "$/", $value); + case '*=': + if ($pattern[0] == '/') { + return preg_match($pattern, $value); + } + + return preg_match("/" . $pattern . "/i", $value); + } + + return false; + } + + protected function parse_selector($selector_string) + { + global $debugObject; + if (is_object($debugObject)) { + $debugObject->debugLogEntry(1); + } + + // pattern of CSS selectors, modified from mootools + // Paperg: Add the colon to the attrbute, so that it properly finds like google does. + // Note: if you try to look at this attribute, yo MUST use getAttribute since $dom->x:y will fail the php syntax check. // Notice the \[ starting the attbute? and the @? following? This implies that an attribute can begin with an @ sign that is not captured. // This implies that an html attribute specifier may start with an @ sign that is NOT captured by the expression. // farther study is required to determine of this should be documented or removed. // $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is"; - $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-:]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is"; - preg_match_all($pattern, trim($selector_string).' ', $matches, PREG_SET_ORDER); - if (is_object($debugObject)) {$debugObject->debugLog(2, "Matches Array: ", $matches);} + $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-:]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is"; + preg_match_all($pattern, trim($selector_string) . ' ', $matches, PREG_SET_ORDER); + if (is_object($debugObject)) { + $debugObject->debugLog(2, "Matches Array: ", $matches); + } - $selectors = array(); - $result = array(); - //print_r($matches); + $selectors = array(); + $result = array(); + //print_r($matches); - foreach ($matches as $m) { - $m[0] = trim($m[0]); - if ($m[0]==='' || $m[0]==='/' || $m[0]==='//') continue; - // for browser generated xpath - if ($m[1]==='tbody') continue; + foreach ($matches as $m) { + $m[0] = trim($m[0]); + if ($m[0] === '' || $m[0] === '/' || $m[0] === '//') continue; + // for browser generated xpath + if ($m[1] === 'tbody') continue; - list($tag, $key, $val, $exp, $no_key) = array($m[1], null, null, '=', false); - if (!empty($m[2])) {$key='id'; $val=$m[2];} - if (!empty($m[3])) {$key='class'; $val=$m[3];} - if (!empty($m[4])) {$key=$m[4];} - if (!empty($m[5])) {$exp=$m[5];} - if (!empty($m[6])) {$val=$m[6];} + list($tag, $key, $val, $exp, $no_key) = array($m[1], null, null, '=', false); + if (!empty($m[2])) { + $key = 'id'; + $val = $m[2]; + } + if (!empty($m[3])) { + $key = 'class'; + $val = $m[3]; + } + if (!empty($m[4])) { + $key = $m[4]; + } + if (!empty($m[5])) { + $exp = $m[5]; + } + if (!empty($m[6])) { + $val = $m[6]; + } - // convert to lowercase - if ($this->dom->lowercase) {$tag=strtolower($tag); $key=strtolower($key);} - //elements that do NOT have the specified attribute - if (isset($key[0]) && $key[0]==='!') {$key=substr($key, 1); $no_key=true;} + // convert to lowercase + if ($this->dom->lowercase) { + $tag = strtolower($tag); + $key = strtolower($key); + } + //elements that do NOT have the specified attribute + if (isset($key[0]) && $key[0] === '!') { + $key = substr($key, 1); + $no_key = true; + } - $result[] = array($tag, $key, $val, $exp, $no_key); - if (trim($m[7])===',') { - $selectors[] = $result; - $result = array(); - } - } - if (count($result)>0) - $selectors[] = $result; - return $selectors; - } + $result[] = array($tag, $key, $val, $exp, $no_key); + if (trim($m[7]) === ',') { + $selectors[] = $result; + $result = array(); + } + } + if (count($result) > 0) + $selectors[] = $result; - function __get($name) { - if (isset($this->attr[$name])) - { - return $this->convert_text($this->attr[$name]); - } - switch ($name) { - case 'outertext': return $this->outertext(); - case 'innertext': return $this->innertext(); - case 'plaintext': return $this->text(); - case 'xmltext': return $this->xmltext(); - default: return array_key_exists($name, $this->attr); - } - } + return $selectors; + } - function __set($name, $value) { - switch ($name) { - case 'outertext': return $this->_[HDOM_INFO_OUTER] = $value; - case 'innertext': - if (isset($this->_[HDOM_INFO_TEXT])) return $this->_[HDOM_INFO_TEXT] = $value; - return $this->_[HDOM_INFO_INNER] = $value; - } - if (!isset($this->attr[$name])) { - $this->_[HDOM_INFO_SPACE][] = array(' ', '', ''); - $this->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE; - } - $this->attr[$name] = $value; - } + function __get($name) + { + if (isset($this->attr[$name])) { + return $this->convert_text($this->attr[$name]); + } + switch ($name) { + case 'outertext': + return $this->outertext(); + case 'innertext': + return $this->innertext(); + case 'plaintext': + return $this->text(); + case 'xmltext': + return $this->xmltext(); + default: + return array_key_exists($name, $this->attr); + } + } - function __isset($name) { - switch ($name) { - case 'outertext': return true; - case 'innertext': return true; - case 'plaintext': return true; - } - //no value attr: nowrap, checked selected... - return (array_key_exists($name, $this->attr)) ? true : isset($this->attr[$name]); - } + function __set($name, $value) + { + switch ($name) { + case 'outertext': + return $this->_[HDOM_INFO_OUTER] = $value; + case 'innertext': + if (isset($this->_[HDOM_INFO_TEXT])) return $this->_[HDOM_INFO_TEXT] = $value; - function __unset($name) { - if (isset($this->attr[$name])) - unset($this->attr[$name]); - } + return $this->_[HDOM_INFO_INNER] = $value; + } + if (!isset($this->attr[$name])) { + $this->_[HDOM_INFO_SPACE][] = array(' ', '', ''); + $this->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE; + } + $this->attr[$name] = $value; + } - // PaperG - Function to convert the text from one character set to another if the two sets are not the same. - function convert_text($text) - { - global $debugObject; - if (is_object($debugObject)) {$debugObject->debugLogEntry(1);} + function __isset($name) + { + switch ($name) { + case 'outertext': + return true; + case 'innertext': + return true; + case 'plaintext': + return true; + } + //no value attr: nowrap, checked selected... + return (array_key_exists($name, $this->attr)) ? true : isset($this->attr[$name]); + } - $converted_text = $text; + function __unset($name) + { + if (isset($this->attr[$name])) + unset($this->attr[$name]); + } - $sourceCharset = ""; - $targetCharset = ""; + // PaperG - Function to convert the text from one character set to another if the two sets are not the same. + function convert_text($text) + { + global $debugObject; + if (is_object($debugObject)) { + $debugObject->debugLogEntry(1); + } - if ($this->dom) - { - $sourceCharset = strtoupper($this->dom->_charset); - $targetCharset = strtoupper($this->dom->_target_charset); - } - if (is_object($debugObject)) {$debugObject->debugLog(3, "source charset: " . $sourceCharset . " target charaset: " . $targetCharset);} + $converted_text = $text; - if (!empty($sourceCharset) && !empty($targetCharset) && (strcasecmp($sourceCharset, $targetCharset) != 0)) - { - // Check if the reported encoding could have been incorrect and the text is actually already UTF-8 - if ((strcasecmp($targetCharset, 'UTF-8') == 0) && ($this->is_utf8($text))) - { - $converted_text = $text; - } - else - { - $converted_text = iconv($sourceCharset, $targetCharset, $text); - } - } + $sourceCharset = ""; + $targetCharset = ""; - // Lets make sure that we don't have that silly BOM issue with any of the utf-8 text we output. - if ($targetCharset == 'UTF-8') - { - if (substr($converted_text, 0, 3) == "\xef\xbb\xbf") - { - $converted_text = substr($converted_text, 3); - } - if (substr($converted_text, -3) == "\xef\xbb\xbf") - { - $converted_text = substr($converted_text, 0, -3); - } - } + if ($this->dom) { + $sourceCharset = strtoupper($this->dom->_charset); + $targetCharset = strtoupper($this->dom->_target_charset); + } + if (is_object($debugObject)) { + $debugObject->debugLog(3, "source charset: " . $sourceCharset . " target charaset: " . $targetCharset); + } - return $converted_text; - } + if (!empty($sourceCharset) && !empty($targetCharset) && (strcasecmp($sourceCharset, $targetCharset) != 0)) { + // Check if the reported encoding could have been incorrect and the text is actually already UTF-8 + if ((strcasecmp($targetCharset, 'UTF-8') == 0) && ($this->is_utf8($text))) { + $converted_text = $text; + } else { + $converted_text = iconv($sourceCharset, $targetCharset, $text); + } + } - /** - * Returns true if $string is valid UTF-8 and false otherwise. - * - * @param mixed $str String to be tested - * @return boolean - */ - static function is_utf8($str) - { - $c=0; $b=0; - $bits=0; - $len=strlen($str); - for($i=0; $i<$len; $i++) - { - $c=ord($str[$i]); - if($c > 128) - { - if(($c >= 254)) return false; - elseif($c >= 252) $bits=6; - elseif($c >= 248) $bits=5; - elseif($c >= 240) $bits=4; - elseif($c >= 224) $bits=3; - elseif($c >= 192) $bits=2; - else return false; - if(($i+$bits) > $len) return false; - while($bits > 1) - { - $i++; - $b=ord($str[$i]); - if($b < 128 || $b > 191) return false; - $bits--; - } - } - } - return true; - } - /* - function is_utf8($string) - { - //this is buggy - return (utf8_encode(utf8_decode($string)) == $string); - } - */ + // Lets make sure that we don't have that silly BOM issue with any of the utf-8 text we output. + if ($targetCharset == 'UTF-8') { + if (substr($converted_text, 0, 3) == "\xef\xbb\xbf") { + $converted_text = substr($converted_text, 3); + } + if (substr($converted_text, -3) == "\xef\xbb\xbf") { + $converted_text = substr($converted_text, 0, -3); + } + } - /** - * Function to try a few tricks to determine the displayed size of an img on the page. - * NOTE: This will ONLY work on an IMG tag. Returns FALSE on all other tag types. - * - * @author John Schlick - * @version April 19 2012 - * @return array an array containing the 'height' and 'width' of the image on the page or -1 if we can't figure it out. - */ - function get_display_size() - { - global $debugObject; + return $converted_text; + } - $width = -1; - $height = -1; + /** + * Returns true if $string is valid UTF-8 and false otherwise. + * + * @param mixed $str String to be tested + * + * @return boolean + */ + static function is_utf8($str) + { + $c = 0; + $b = 0; + $bits = 0; + $len = strlen($str); + for ($i = 0; $i < $len; $i++) { + $c = ord($str[$i]); + if ($c > 128) { + if (($c >= 254)) return false; + elseif ($c >= 252) $bits = 6; + elseif ($c >= 248) $bits = 5; + elseif ($c >= 240) $bits = 4; + elseif ($c >= 224) $bits = 3; + elseif ($c >= 192) $bits = 2; + else return false; + if (($i + $bits) > $len) return false; + while ($bits > 1) { + $i++; + $b = ord($str[$i]); + if ($b < 128 || $b > 191) return false; + $bits--; + } + } + } - if ($this->tag !== 'img') - { - return false; - } + return true; + } + /* + function is_utf8($string) + { + //this is buggy + return (utf8_encode(utf8_decode($string)) == $string); + } + */ - // See if there is aheight or width attribute in the tag itself. - if (isset($this->attr['width'])) - { - $width = $this->attr['width']; - } + /** + * Function to try a few tricks to determine the displayed size of an img on the page. + * NOTE: This will ONLY work on an IMG tag. Returns FALSE on all other tag types. + * + * @author John Schlick + * @version April 19 2012 + * @return array an array containing the 'height' and 'width' of the image on the page or -1 if we can't figure it out. + */ + function get_display_size() + { + global $debugObject; - if (isset($this->attr['height'])) - { - $height = $this->attr['height']; - } + $width = -1; + $height = -1; - // Now look for an inline style. - if (isset($this->attr['style'])) - { - // Thanks to user gnarf from stackoverflow for this regular expression. - $attributes = array(); - preg_match_all("/([\w-]+)\s*:\s*([^;]+)\s*;?/", $this->attr['style'], $matches, PREG_SET_ORDER); - foreach ($matches as $match) { - $attributes[$match[1]] = $match[2]; - } + if ($this->tag !== 'img') { + return false; + } - // If there is a width in the style attributes: - if (isset($attributes['width']) && $width == -1) - { - // check that the last two characters are px (pixels) - if (strtolower(substr($attributes['width'], -2)) == 'px') - { - $proposed_width = substr($attributes['width'], 0, -2); - // Now make sure that it's an integer and not something stupid. - if (filter_var($proposed_width, FILTER_VALIDATE_INT)) - { - $width = $proposed_width; - } - } - } + // See if there is aheight or width attribute in the tag itself. + if (isset($this->attr['width'])) { + $width = $this->attr['width']; + } - // If there is a width in the style attributes: - if (isset($attributes['height']) && $height == -1) - { - // check that the last two characters are px (pixels) - if (strtolower(substr($attributes['height'], -2)) == 'px') - { - $proposed_height = substr($attributes['height'], 0, -2); - // Now make sure that it's an integer and not something stupid. - if (filter_var($proposed_height, FILTER_VALIDATE_INT)) - { - $height = $proposed_height; - } - } - } + if (isset($this->attr['height'])) { + $height = $this->attr['height']; + } - } + // Now look for an inline style. + if (isset($this->attr['style'])) { + // Thanks to user gnarf from stackoverflow for this regular expression. + $attributes = array(); + preg_match_all("/([\w-]+)\s*:\s*([^;]+)\s*;?/", $this->attr['style'], $matches, PREG_SET_ORDER); + foreach ($matches as $match) { + $attributes[$match[1]] = $match[2]; + } - // Future enhancement: - // Look in the tag to see if there is a class or id specified that has a height or width attribute to it. + // If there is a width in the style attributes: + if (isset($attributes['width']) && $width == -1) { + // check that the last two characters are px (pixels) + if (strtolower(substr($attributes['width'], -2)) == 'px') { + $proposed_width = substr($attributes['width'], 0, -2); + // Now make sure that it's an integer and not something stupid. + if (filter_var($proposed_width, FILTER_VALIDATE_INT)) { + $width = $proposed_width; + } + } + } - // Far future enhancement - // Look at all the parent tags of this image to see if they specify a class or id that has an img selector that specifies a height or width - // Note that in this case, the class or id will have the img subselector for it to apply to the image. + // If there is a width in the style attributes: + if (isset($attributes['height']) && $height == -1) { + // check that the last two characters are px (pixels) + if (strtolower(substr($attributes['height'], -2)) == 'px') { + $proposed_height = substr($attributes['height'], 0, -2); + // Now make sure that it's an integer and not something stupid. + if (filter_var($proposed_height, FILTER_VALIDATE_INT)) { + $height = $proposed_height; + } + } + } - // ridiculously far future development - // If the class or id is specified in a SEPARATE css file thats not on the page, go get it and do what we were just doing for the ones on the page. + } - $result = array('height' => $height, - 'width' => $width); - return $result; - } + // Future enhancement: + // Look in the tag to see if there is a class or id specified that has a height or width attribute to it. - // camel naming conventions - function getAllAttributes() {return $this->attr;} - function getAttribute($name) {return $this->__get($name);} - function setAttribute($name, $value) {$this->__set($name, $value);} - function hasAttribute($name) {return $this->__isset($name);} - function removeAttribute($name) {$this->__set($name, null);} - function getElementById($id) {return $this->find("#$id", 0);} - function getElementsById($id, $idx=null) {return $this->find("#$id", $idx);} - function getElementByTagName($name) {return $this->find($name, 0);} - function getElementsByTagName($name, $idx=null) {return $this->find($name, $idx);} - function parentNode() {return $this->parent();} - function childNodes($idx=-1) {return $this->children($idx);} - function firstChild() {return $this->first_child();} - function lastChild() {return $this->last_child();} - function nextSibling() {return $this->next_sibling();} - function previousSibling() {return $this->prev_sibling();} - function hasChildNodes() {return $this->has_child();} - function nodeName() {return $this->tag;} - function appendChild($node) {$node->parent($this); return $node;} + // Far future enhancement + // Look at all the parent tags of this image to see if they specify a class or id that has an img selector that specifies a height or width + // Note that in this case, the class or id will have the img subselector for it to apply to the image. + + // ridiculously far future development + // If the class or id is specified in a SEPARATE css file thats not on the page, go get it and do what we were just doing for the ones on the page. + + $result = array('height' => $height, + 'width' => $width + ); + + return $result; + } + + // camel naming conventions + function getAllAttributes() + { + return $this->attr; + } + + function getAttribute($name) + { + return $this->__get($name); + } + + function setAttribute($name, $value) + { + $this->__set($name, $value); + } + + function hasAttribute($name) + { + return $this->__isset($name); + } + + function removeAttribute($name) + { + $this->__set($name, null); + } + + function getElementById($id) + { + return $this->find("#$id", 0); + } + + function getElementsById($id, $idx = null) + { + return $this->find("#$id", $idx); + } + + function getElementByTagName($name) + { + return $this->find($name, 0); + } + + function getElementsByTagName($name, $idx = null) + { + return $this->find($name, $idx); + } + + function parentNode() + { + return $this->parent(); + } + + function childNodes($idx = -1) + { + return $this->children($idx); + } + + function firstChild() + { + return $this->first_child(); + } + + function lastChild() + { + return $this->last_child(); + } + + function nextSibling() + { + return $this->next_sibling(); + } + + function previousSibling() + { + return $this->prev_sibling(); + } + + function hasChildNodes() + { + return $this->has_child(); + } + + function nodeName() + { + return $this->tag; + } + + function appendChild($node) + { + $node->parent($this); + + return $node; + } } @@ -970,752 +1066,789 @@ class simple_html_dom_node */ class simple_html_dom { - public $root = null; - public $nodes = array(); - public $callback = null; - public $lowercase = false; - // Used to keep track of how large the text was when we started. - public $original_size; - public $size; - protected $pos; - protected $doc; - protected $char; - protected $cursor; - protected $parent; - protected $noise = array(); - protected $token_blank = " \t\r\n"; - protected $token_equal = ' =/>'; - protected $token_slash = " />\r\n\t"; - protected $token_attr = ' >'; - // Note that this is referenced by a child node, and so it needs to be public for that node to see this information. - public $_charset = ''; - public $_target_charset = ''; - protected $default_br_text = ""; - public $default_span_text = ""; - - // use isset instead of in_array, performance boost about 30%... - protected $self_closing_tags = array('img'=>1, 'br'=>1, 'input'=>1, 'meta'=>1, 'link'=>1, 'hr'=>1, 'base'=>1, 'embed'=>1, 'spacer'=>1); - protected $block_tags = array('root'=>1, 'body'=>1, 'form'=>1, 'div'=>1, 'span'=>1, 'table'=>1); - // Known sourceforge issue #2977341 - // B tags that are not closed cause us to return everything to the end of the document. - protected $optional_closing_tags = array( - 'tr'=>array('tr'=>1, 'td'=>1, 'th'=>1), - 'th'=>array('th'=>1), - 'td'=>array('td'=>1), - 'li'=>array('li'=>1), - 'dt'=>array('dt'=>1, 'dd'=>1), - 'dd'=>array('dd'=>1, 'dt'=>1), - 'dl'=>array('dd'=>1, 'dt'=>1), - 'p'=>array('p'=>1), - 'nobr'=>array('nobr'=>1), - 'b'=>array('b'=>1), - 'option'=>array('option'=>1), - ); - - function __construct($str=null, $lowercase=true, $forceTagsClosed=true, $target_charset=DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) - { - if ($str) - { - if (preg_match("/^http:\/\//i",$str) || is_file($str)) - { - $this->load_file($str); - } - else - { - $this->load($str, $lowercase, $stripRN, $defaultBRText, $defaultSpanText); - } - } - // Forcing tags to be closed implies that we don't trust the html, but it can lead to parsing errors if we SHOULD trust the html. - if (!$forceTagsClosed) { - $this->optional_closing_array=array(); - } - $this->_target_charset = $target_charset; - } - - function __destruct() - { - $this->clear(); - } - - // load html from string - function load($str, $lowercase=true, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) - { - global $debugObject; - - // prepare - $this->prepare($str, $lowercase, $stripRN, $defaultBRText, $defaultSpanText); - // strip out comments - $this->remove_noise("''is"); - // strip out cdata - $this->remove_noise("''is", true); - // Per sourceforge http://sourceforge.net/tracker/?func=detail&aid=2949097&group_id=218559&atid=1044037 - // Script tags removal now preceeds style tag removal. - // strip out