diff --git a/libs/Net_NNTP/NNTP/Protocol/Client.php b/libs/Net_NNTP/NNTP/Protocol/Client.php index 9f360dd70..39efe15e5 100644 --- a/libs/Net_NNTP/NNTP/Protocol/Client.php +++ b/libs/Net_NNTP/NNTP/Protocol/Client.php @@ -447,9 +447,9 @@ class Net_NNTP_Protocol_Client extends PEAR * Return the last received response message. * * @return string The response message. - * @access private + * @access protected */ - private function _currentStatusResponse() + protected function _currentStatusResponse() { return $this->_currentStatusResponse[1]; } diff --git a/libs/smarty/autoloader.php b/libs/smarty/autoloader.php index 6de36a3fd..34e734ecf 100644 --- a/libs/smarty/autoloader.php +++ b/libs/smarty/autoloader.php @@ -1,30 +1,158 @@ 'Smarty.class.php', + 'SmartyBC' => 'SmartyBC.class.php', + ); + + private static $syspluginsClasses = array( + 'smarty_config_source' => true, + 'smarty_security' => true, + 'smarty_cacheresource' => true, + 'smarty_compiledresource' => true, + 'smarty_cacheresource_custom' => true, + 'smarty_cacheresource_keyvaluestore' => true, + 'smarty_resource' => true, + 'smarty_resource_custom' => true, + 'smarty_resource_uncompiled' => true, + 'smarty_resource_recompiled' => true, + 'smarty_template_source' => true, + 'smarty_template_compiled' => true, + 'smarty_template_cached' => true, + 'smarty_template_config' => true, + 'smarty_data' => true, + 'smarty_variable' => true, + 'smarty_undefined_variable' => true, + 'smartyexception' => true, + 'smartycompilerexception' => true, + 'smarty_internal_data' => true, + 'smarty_internal_template' => true, + 'smarty_internal_templatebase' => true, + 'smarty_internal_resource_file' => true, + 'smarty_internal_resource_extends' => true, + 'smarty_internal_resource_eval' => true, + 'smarty_internal_resource_string' => true, + 'smarty_internal_resource_registered' => true, + 'smarty_internal_extension_codeframe' => true, + 'smarty_internal_extension_config' => true, + 'smarty_internal_filter_handler' => true, + 'smarty_internal_function_call_handler' => true, + 'smarty_internal_cacheresource_file' => true, + 'smarty_internal_write_file' => true, + ); + + /** + * Registers Smarty_Autoloader backward compatible to older installations. + * + * @param bool $prepend Whether to prepend the autoloader or not. + */ + public static function registerBC($prepend = false) { - if ($className == 'Smarty') { - $className = 'Smarty.class'; + /** + * register the class autoloader + */ + if (!defined('SMARTY_SPL_AUTOLOAD')) { + define('SMARTY_SPL_AUTOLOAD', 0); } - - $paths = array( - SMARTY_DIR, - NN_WWW . 'pages' . DIRECTORY_SEPARATOR, - SMARTY_DIR . 'plugins' . DIRECTORY_SEPARATOR, - SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR - ); - - foreach ($paths as $path) - { - $spec = str_replace('\\', DIRECTORY_SEPARATOR, $path . strtolower($className) . '.php'); - if (file_exists($spec)) { - require_once $spec; - break; - } else if (NN_LOGAUTOLOADER) { - var_dump($spec); + if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) { + $registeredAutoLoadFunctions = spl_autoload_functions(); + if (!isset($registeredAutoLoadFunctions['spl_autoload'])) { + spl_autoload_register(); } + } else { + self::register($prepend); } } -); -?> + /** + * Registers Smarty_Autoloader as an SPL autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not. + */ + public static function register($prepend = false) + { + self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . '/'; + self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR : self::$SMARTY_DIR . 'sysplugins/'; + if (version_compare(phpversion(), '5.3.0', '>=')) { + spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); + } else { + spl_autoload_register(array(__CLASS__, 'autoload')); + } + } + + /** + * Handles autoloading of classes. + * + * @param string $class A class name. + */ + public static function autoload($class) + { + // Request for Smarty or already unknown class + if (isset(self::$unknown[$class])) { + return; + } + $_class = strtolower($class); + if (isset(self::$syspluginsClasses[$_class])) { + $_class = (self::$syspluginsClasses[$_class] === true) ? $_class : self::$syspluginsClasses[$_class]; + $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; + require_once $file; + return; + } elseif (0 !== strpos($_class, 'smarty_internal_')) { + if (isset(self::$rootClasses[$class])) { + $file = self::$SMARTY_DIR . self::$rootClasses[$class]; + require_once $file; + return; + } + self::$unknown[$class] = true; + return; + } + $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; + if (is_file($file)) { + require_once $file; + return; + } + self::$unknown[$class] = true; + return; + } +} diff --git a/newznab/controllers/Backfill.php b/newznab/controllers/Backfill.php index 1e7065ee7..445b2afd6 100644 --- a/newznab/controllers/Backfill.php +++ b/newznab/controllers/Backfill.php @@ -102,15 +102,15 @@ class Backfill $this->_echoCLI = ($options['Echo'] && NN_ECHOCLI); $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); - $this->_groups = ($options['Groups'] instanceof \Groups ? $options['Groups'] : new \Groups(['Settings' => $this->pdo])); - $this->_nntp = ($options['NNTP'] instanceof \NNTP - ? $options['NNTP'] : new \NNTP(['Settings' => $this->pdo]) + $this->_groups = ($options['Groups'] instanceof Groups ? $options['Groups'] : new Groups(['Settings' => $this->pdo])); + $this->_nntp = ($options['NNTP'] instanceof NNTP + ? $options['NNTP'] : new NNTP(['Settings' => $this->pdo]) ); $this->_debug = (NN_LOGGING || NN_DEBUG); if ($this->_debug) { try { - $this->_debugging = ($options['Logger'] instanceof \Logger ? $options['Logger'] : new \Logger(['ColorCLI' => $this->pdo->log])); + $this->_debugging = ($options['Logger'] instanceof Logger ? $options['Logger'] : new Logger(['ColorCLI' => $this->pdo->log])); } catch (\LoggerException $error) { $this->_debug = false; } @@ -159,14 +159,14 @@ class Backfill ($this->_compressedHeaders ? 'Yes' : 'No') ); if ($this->_debug) { - $this->_debugging->log('Backfill', "backfillAllGroups", $dMessage, \Logger::LOG_INFO); + $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_INFO); } if ($this->_echoCLI) { $this->pdo->log->doEcho($this->pdo->log->header($dMessage), true); } - $this->_binaries = new \Binaries( + $this->_binaries = new Binaries( ['NNTP' => $this->_nntp, 'Echo' => $this->_echoCLI, 'Settings' => $this->pdo, 'Groups' => $this->_groups] ); @@ -179,7 +179,7 @@ class Backfill if ($groupName === '') { $dMessage = "Starting group " . $counter . ' of ' . $groupCount; if ($this->_debug) { - $this->_debugging->log('Backfill', "backfillAllGroups", $dMessage, \Logger::LOG_INFO); + $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_INFO); } if ($this->_echoCLI) { @@ -192,7 +192,7 @@ class Backfill $dMessage = 'Backfilling completed in ' . number_format(microtime(true) - $allTime, 2) . " seconds."; if ($this->_debug) { - $this->_debugging->log('Backfill', "backfillAllGroups", $dMessage, \Logger::LOG_INFO); + $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_INFO); } if ($this->_echoCLI) { @@ -201,7 +201,7 @@ class Backfill } else { $dMessage = "No groups specified. Ensure groups are added to newznab's database for updating."; if ($this->_debug) { - $this->_debugging->log('Backfill', "backfillAllGroups", $dMessage, \Logger::LOG_FATAL); + $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_FATAL); } if ($this->_echoCLI) { @@ -232,7 +232,7 @@ class Backfill $groupName . ". Otherwise the group is dead, you must disable it."; if ($this->_debug) { - $this->_debugging->log('Backfill', "backfillGroup", $dMessage, \Logger::LOG_ERROR); + $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_ERROR); } if ($this->_echoCLI) { @@ -278,7 +278,7 @@ class Backfill ($this->_disableBackfillGroup ? ", disabling backfill on it." : ", skipping it, consider disabling backfill on it."); if ($this->_debug) { - $this->_debugging->log('Backfill', "backfillGroup", $dMessage, \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_NOTICE); } if ($this->_disableBackfillGroup) { @@ -418,7 +418,7 @@ class Backfill $this->_safeBackFillDate . ", or you have not enabled them to be backfilled in the groups page.\n"; if ($this->_debug) { - $this->_debugging->log('Backfill', "safeBackfill", $dMessage, \Logger::LOG_FATAL); + $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_FATAL); } exit($dMessage); } else { diff --git a/newznab/controllers/Film.php b/newznab/controllers/Film.php index 2a8c77b70..d2e098c52 100644 --- a/newznab/controllers/Film.php +++ b/newznab/controllers/Film.php @@ -738,8 +738,8 @@ class Film if ($percent < 40) { if ($this->debug) { $this->debugging->log( - 'Film', - 'fetchTmdbProperties', + get_class(), + __FUNCTION__, 'Found (' . $ret['title'] . ') from TMDB, but it\'s only ' . @@ -850,8 +850,8 @@ class Film if ($percent < 40) { if ($this->debug) { $this->debugging->log( - 'Film', - 'fetchImdbProperties', + get_class(), + __FUNCTION__, 'Found (' . $ret['title'] . ') from IMDB, but it\'s only ' . @@ -899,7 +899,7 @@ class Film public function doMovieUpdate($buffer, $service, $id, $processImdb = 1) { $imdbID = false; - if (preg_match('/(?:imdb.*?)?(?:tt|Title\?)(?P\d{5,7})/i', $buffer, $matches)) { + if (is_string($buffer) && preg_match('/(?:imdb.*?)?(?:tt|Title\?)(?P\d{5,7})/i', $buffer, $matches)) { $imdbID = $matches['imdbid']; } diff --git a/newznab/controllers/NNTP.php b/newznab/controllers/NNTP.php index f9c4ecdaf..bb7146535 100644 --- a/newznab/controllers/NNTP.php +++ b/newznab/controllers/NNTP.php @@ -221,7 +221,7 @@ class NNTP extends Net_NNTP_Client ': ' . $cError; if ($this->_debugBool) { - $this->_debugging->log('NNTP', "doConnect", $message, \Logger::LOG_ERROR); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_ERROR); } return $this->throwError($this->pdo->log->error($message)); } @@ -262,7 +262,7 @@ class NNTP extends Net_NNTP_Client $userName . ' (' . $aError . ')'; if ($this->_debugBool) { - $this->_debugging->log('NNTP', "doConnect", $message, \Logger::LOG_ERROR); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_ERROR); } return $this->throwError($this->pdo->log->error($message)); } @@ -276,7 +276,7 @@ class NNTP extends Net_NNTP_Client $this->_compressionSupported = false; } if ($this->_debugBool) { - $this->_debugging->log('NNTP', "doConnect", "Connected to " . $this->_currentServer . '.', \Logger::LOG_INFO); + $this->_debugging->log(get_class(), __FUNCTION__, "Connected to " . $this->_currentServer . '.', Logger::LOG_INFO); } return true; } @@ -291,7 +291,7 @@ class NNTP extends Net_NNTP_Client // If we somehow got out of the loop, return an error. $message = 'Unable to connect to ' . $this->_currentServer . $enc; if ($this->_debugBool) { - $this->_debugging->log('NNTP', "doConnect", $message, \Logger::LOG_ERROR); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_ERROR); } return $this->throwError($this->pdo->log->error($message)); } @@ -313,7 +313,7 @@ class NNTP extends Net_NNTP_Client // Check if we are connected to usenet. if ($force === true || parent::_isConnected(false)) { if ($this->_debugBool) { - $this->_debugging->log('NNTP', "doQuit", "Disconnecting from " . $this->_currentServer, \Logger::LOG_INFO); + $this->_debugging->log(get_class(), __FUNCTION__, "Disconnecting from " . $this->_currentServer, Logger::LOG_INFO); } // Disconnect from usenet. return parent::disconnect(); @@ -606,7 +606,7 @@ class NNTP extends Net_NNTP_Client return $body; } if ($this->_debugBool) { - $this->_debugging->log('NNTP', "getMessages", $newBody->getMessage(), \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $newBody->getMessage(), Logger::LOG_NOTICE); } // Return the error. return $newBody; @@ -637,7 +637,7 @@ class NNTP extends Net_NNTP_Client } else { $message = 'Wrong Identifier type, array, int or string accepted. This type of var was passed: ' . gettype($identifiers); if ($this->_debugBool) { - $this->_debugging->log('NNTP', "getMessages", $message, \Logger::LOG_WARNING); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_WARNING); } return $this->throwError($this->pdo->log->error($message)); } @@ -677,7 +677,7 @@ class NNTP extends Net_NNTP_Client // If there was an error selecting the group, return PEAR error object. if ($this->isError($summary)) { if ($this->_debugBool) { - $this->_debugging->log('NNTP', "get_Article", $summary->getMessage(), \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $summary->getMessage(), Logger::LOG_NOTICE); } return $summary; } @@ -694,7 +694,7 @@ class NNTP extends Net_NNTP_Client // If there was an error downloading the article, return a PEAR error object. if ($this->isError($article)) { if ($this->_debugBool) { - $this->_debugging->log('NNTP', "get_Article", $article->getMessage(), \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $article->getMessage(), Logger::LOG_NOTICE); } return $article; } @@ -760,7 +760,7 @@ class NNTP extends Net_NNTP_Client // Return PEAR error object on failure. if ($this->isError($summary)) { if ($this->_debugBool) { - $this->_debugging->log('NNTP', "get_Header", $summary->getMessage(), \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $summary->getMessage(), Logger::LOG_NOTICE); } return $summary; } @@ -777,7 +777,7 @@ class NNTP extends Net_NNTP_Client // If we failed, return PEAR error object. if ($this->isError($header)) { if ($this->_debugBool) { - $this->_debugging->log('NNTP', "get_Header", $header->getMessage(), \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $header->getMessage(), Logger::LOG_NOTICE); } return $header; } @@ -823,7 +823,7 @@ class NNTP extends Net_NNTP_Client if (!$this->_postingAllowed) { $message = 'You do not have the right to post articles on server ' . $this->_currentServer; if ($this->_debugBool) { - $this->_debugging->log('NNTP', "postArticle", $message, \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_NOTICE); } return $this->throwError($this->pdo->log->error($message)); } @@ -837,7 +837,7 @@ class NNTP extends Net_NNTP_Client if (strlen($subject) > 510) { $message = 'Max length of subject is 510 chars.'; if ($this->_debugBool) { - $this->_debugging->log('NNTP', "postArticle", $message, \Logger::LOG_WARNING); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_WARNING); } return $this->throwError($this->pdo->log->error($message)); } @@ -845,7 +845,7 @@ class NNTP extends Net_NNTP_Client if (strlen($from) > 510) { $message = 'Max length of from is 510 chars.'; if ($this->_debugBool) { - $this->_debugging->log('NNTP', "postArticle", $message, \Logger::LOG_WARNING); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_WARNING); } return $this->throwError($this->pdo->log->error($message)); } @@ -893,7 +893,7 @@ class NNTP extends Net_NNTP_Client // Try reconnecting. This uses another round of max retries. if ($nntp->doConnect($comp) !== true) { if ($this->_debugBool) { - $this->_debugging->log('NNTP', "dataError", 'Unable to reconnect to usenet!', \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, 'Unable to reconnect to usenet!', Logger::LOG_NOTICE); } return $this->throwError('Unable to reconnect to usenet!'); } @@ -903,7 +903,7 @@ class NNTP extends Net_NNTP_Client if ($this->isError($data)) { $message = "Code {$data->code}: {$data->message}\nSkipping group: {$group}"; if ($this->_debugBool) { - $this->_debugging->log('NNTP', "dataError", $message, \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_NOTICE); } if ($this->_echo) { @@ -937,7 +937,7 @@ class NNTP extends Net_NNTP_Client if ($lineLength < 1) { $message = $lineLength . ' is not a valid line length.'; if ($this->_debugBool) { - $this->_debugging->log('NNTP', 'encodeYEnc', $message, \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_NOTICE); } return $this->throwError($message); } @@ -1009,7 +1009,7 @@ class NNTP extends Net_NNTP_Client if ($headerSize != $trailerSize) { $message = 'Header and trailer file sizes do not match. This is a violation of the yEnc specification.'; if ($this->_debugBool) { - $this->_debugging->log('NNTP', 'decodeYEnc', $message, \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_NOTICE); } return $this->throwError($message); } @@ -1025,7 +1025,7 @@ class NNTP extends Net_NNTP_Client if (strlen($decoded) != $headerSize) { $message = 'Header file size and actual file size do not match. The file is probably corrupt.'; if ($this->_debugBool) { - $this->_debugging->log('NNTP', 'decodeYEnc', $message, \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_NOTICE); } return $this->throwError($message); } @@ -1034,7 +1034,7 @@ class NNTP extends Net_NNTP_Client if ($crc !== '' && (strtolower($crc) !== strtolower(sprintf("%04X", crc32($decoded))))) { $message = 'CRC32 checksums do not match. The file is probably corrupt.'; if ($this->_debugBool) { - $this->_debugging->log('NNTP', 'decodeYEnc', $message, \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_NOTICE); } return $this->throwError($message); } @@ -1272,13 +1272,14 @@ class NNTP extends Net_NNTP_Client * Try to see if the NNTP server implements XFeature GZip Compression, * change the compression bool object if so. * + * @param bool $secondTry This is only used if enabling compression fails, the function will call itself to retry. * @return mixed On success : (bool) True: The server understood and compression is enabled. * (bool) False: The server did not understand, compression is not enabled. * On failure : (object) PEAR_Error. * * @access protected */ - protected function _enableCompression() + protected function _enableCompression($secondTry = false) { if ($this->_compressionEnabled === true) { return true; @@ -1286,28 +1287,32 @@ class NNTP extends Net_NNTP_Client return false; } - // Send this command to the usenet server. $response = $this->_sendCommand('XFEATURE COMPRESS GZIP'); // Check if it's good. if ($this->isError($response)) { if ($this->_debugBool) { - $this->_debugging->log('NNTP', "_enableCompression", $response->getMessage(), \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $response->getMessage(), Logger::LOG_NOTICE); } $this->_compressionSupported = false; return $response; } else if ($response !== 290) { - $msg = "XFeature GZip Compression not supported. Consider disabling compression in site settings."; - if ($this->_debugBool) { - $this->_debugging->log('NNTP', "_enableCompression", $msg, \Logger::LOG_NOTICE); + if ($secondTry === false) { + // Retry. + $this->cmdQuit(); + if ($this->_checkConnection()) { + return $this->_enableCompression(true); + } } - - if ($this->_echo) { - $this->pdo->log->doEcho($this->pdo->log->error($msg), true); + $msg = "Sent 'XFEATURE COMPRESS GZIP' to server, got '$response: " . $this->_currentStatusResponse() . "'"; + if ($this->_debugBool) { + $this->_debugging->log(get_class(), __FUNCTION__, $msg, Logger::LOG_NOTICE); } $this->_compressionSupported = false; + return false; + } $this->_compressionEnabled = true; @@ -1404,7 +1409,7 @@ class NNTP extends Net_NNTP_Client } else { $message = 'Decompression of OVER headers failed.'; if ($this->_debugBool) { - $this->_debugging->log('NNTP', "_getXFeatureTextResponse", $message, \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_NOTICE); } $message = $this->throwError($this->pdo->log->error($message), 1000); return $message; @@ -1428,7 +1433,7 @@ class NNTP extends Net_NNTP_Client if (empty($buffer)) { $message = 'Error fetching data from usenet server while downloading OVER headers.'; if ($this->_debugBool) { - $this->_debugging->log('NNTP', "_getXFeatureTextResponse", $message, \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_NOTICE); } $message = $this->throwError($this->pdo->log->error($message), 1000); return $message; @@ -1447,7 +1452,7 @@ class NNTP extends Net_NNTP_Client $message = 'Unspecified error while downloading OVER headers.'; if ($this->_debugBool) { - $this->_debugging->log('NNTP', "_getXFeatureTextResponse", $message, \Logger::LOG_NOTICE); + $this->_debugging->log(get_class(), __FUNCTION__, $message, Logger::LOG_NOTICE); } $message = $this->throwError($this->pdo->log->error($message), 1000);; return $message; @@ -1502,7 +1507,7 @@ class NNTP extends Net_NNTP_Client // If there was an error selecting the group, return PEAR error object. if ($this->isError($summary)) { if ($this->_debugBool) { - $this->_debugging->log('NNTP', "getMessage", $summary->getMessage(), \Logger::LOG_WARNING); + $this->_debugging->log(get_class(), __FUNCTION__, $summary->getMessage(), Logger::LOG_WARNING); } return $summary; } @@ -1540,8 +1545,7 @@ class NNTP extends Net_NNTP_Client // Check if the line terminates the text response. if ($line === ".\r\n") { if ($this->_debugBool) { - $this->_debugging->log('NNTP', - 'getMessage', 'Fetched body for article ' . $identifier, \Logger::LOG_INFO + $this->_debugging->log(get_class(), __FUNCTION__, 'Fetched body for article ' . $identifier, Logger::LOG_INFO ); } // Attempt to yEnc decode and return the body. diff --git a/newznab/controllers/Users.php b/newznab/controllers/Users.php index 5806ab2e4..39c926f63 100644 --- a/newznab/controllers/Users.php +++ b/newznab/controllers/Users.php @@ -942,17 +942,20 @@ class Users } /** - * Get the quantity of API requests in the last day for the user_id. + * Get the quantity of API requests in the last day for the userid. * * @param int $userID * - * @return array|bool + * @return int */ public function getApiRequests($userID) { // Clear old requests. $this->clearApiRequests($userID); - return $this->pdo->queryOneRow(sprintf('SELECT COUNT(id) AS num FROM userrequests WHERE userid = %d', $userID)); + $requests = $this->pdo->queryOneRow( + sprintf('SELECT COUNT(id) AS num FROM userdownloads WHERE userid = %d', $userID) + ); + return (!$requests ? 0 : (int)$requests['num']); } /** diff --git a/newznab/db/DB.php b/newznab/db/DB.php index 453f7da4a..169379799 100644 --- a/newznab/db/DB.php +++ b/newznab/db/DB.php @@ -338,7 +338,7 @@ class DB extends \PDO protected function echoError($error, $method, $severity, $exit = false) { if ($this->_debug) { - $this->debugging->log('DB', $method, $error, $severity); + $this->debugging->log(get_class(), $method, $error, $severity); echo( ($this->cli ? $this->log->error($error) . PHP_EOL : '
' . $error . '
') @@ -444,7 +444,7 @@ class DB extends \PDO } if ($this->_debug) { $this->echoError($error, 'queryInsert', 4); - $this->debugging->log('DB', "queryInsert", $query, \Logger::LOG_SQL); + $this->debugging->log(get_class(), __FUNCTION__, $query, \Logger::LOG_SQL); } return false; } @@ -489,7 +489,7 @@ class DB extends \PDO } if ($silent === false && $this->_debug) { $this->echoError($error, 'queryExec', 4); - $this->debugging->log('DB', "queryExec", $query, \Logger::LOG_SQL); + $this->debugging->log(get_class(), __FUNCTION__, $query, \Logger::LOG_SQL); } return false; } @@ -588,7 +588,7 @@ class DB extends \PDO $this->echoError($e->getMessage(), 'Exec', 4, false); if ($this->_debug) { - $this->debugging->log('DB', "Exec", $query, \Logger::LOG_SQL); + $this->debugging->log(get_class(), __FUNCTION__, $query, \Logger::LOG_SQL); } } @@ -747,7 +747,7 @@ class DB extends \PDO if ($ignore === false) { $this->echoError($e->getMessage(), 'queryDirect', 4, false); if ($this->_debug) { - $this->debugging->log('DB', "queryDirect", $query, \Logger::LOG_SQL); + $this->debugging->log(get_class(), __FUNCTION__, $query, \Logger::LOG_SQL); } } $result = false; @@ -922,7 +922,7 @@ class DB extends \PDO } if ($this->_debug) { - $this->debugging->log('DB', 'optimise', $message, \Logger::LOG_INFO); + $this->debugging->log(get_class(), __FUNCTION__, $message, \Logger::LOG_INFO); } } @@ -1062,7 +1062,7 @@ class DB extends \PDO $PDOstatement = $this->pdo->prepare($query, $options); } catch (\PDOException $e) { if ($this->_debug) { - $this->debugging->log('DB', "Prepare", $e->getMessage(), \Logger::LOG_INFO); + $this->debugging->log(get_class(), __FUNCTION__, $e->getMessage(), \Logger::LOG_INFO); } echo $this->log->error("\n" . $e->getMessage()); $PDOstatement = false; @@ -1085,7 +1085,7 @@ class DB extends \PDO $result = $this->pdo->getAttribute($attribute); } catch (\PDOException $e) { if ($this->_debug) { - $this->debugging->log('DB', "getAttribute", $e->getMessage(), \Logger::LOG_INFO); + $this->debugging->log(get_class(), __FUNCTION__, $e->getMessage(), \Logger::LOG_INFO); } echo $this->log->error("\n" . $e->getMessage()); $result = false; diff --git a/newznab/processing/PProcess.php b/newznab/processing/PProcess.php index 4490ceafd..44240b133 100644 --- a/newznab/processing/PProcess.php +++ b/newznab/processing/PProcess.php @@ -424,7 +424,7 @@ class PProcess // If we found some files. if ($filesAdded > 0) { - $this->debugging->log('PostProcess', 'parsePAR2', 'Added ' . $filesAdded . ' releasefiles from PAR2 for ' . $query['searchname'], \Logger::LOG_INFO); + $this->debugging->log(get_class(), __FUNCTION__, 'Added ' . $filesAdded . ' releasefiles from PAR2 for ' . $query['searchname'], \Logger::LOG_INFO); // Update the file count with the new file count + old file count. $this->pdo->queryExec( diff --git a/www/pages/api.php b/www/pages/api.php index 820f5c7c6..ca2b9a6d4 100644 --- a/www/pages/api.php +++ b/www/pages/api.php @@ -108,8 +108,8 @@ $page->smarty->assign('rsstoken', $apiKey); if ($uid != '') { $page->users->updateApiAccessed($uid); $apiRequests = $page->users->getApiRequests($uid); - if ($apiRequests['num'] > $maxRequests) { - showApiError(500, 'Request limit reached (' . $apiRequests['num'] . '/' . $maxRequests . ')'); + if ($apiRequests > $maxRequests) { + showApiError(500, 'Request limit reached (' . $apiRequests . '/' . $maxRequests . ')'); } } diff --git a/www/pages/contact-us.php b/www/pages/contact-us.php index f05c51fb7..1b79f7fa0 100644 --- a/www/pages/contact-us.php +++ b/www/pages/contact-us.php @@ -24,9 +24,10 @@ if (isset($_POST["useremail"])) { Utility::sendEmail($mailto, $mailsubj, $mailbody, $email); } - $page->smarty->assign("msg", "

Thanks for getting in touch with " . $page->settings->getSetting('title') . ".

"); + $msg = "

Thank you for getting in touch with " . $page->settings->getSetting('title') . ".

"; } } +$page->smarty->assign("msg", $msg); $page->title = "Contact ".$page->settings->getSetting('title'); $page->meta_title = "Contact ".$page->settings->getSetting('title'); $page->meta_keywords = "contact us,contact,get in touch,email"; diff --git a/www/pages/movie.php b/www/pages/movie.php index 9e8142dd2..3acd8aebe 100644 --- a/www/pages/movie.php +++ b/www/pages/movie.php @@ -1,41 +1,31 @@ users->isLoggedIn()) $page->show403(); -if (isset($_GET["id"]) && ctype_digit($_GET["id"])) -{ +if (isset($_GET['modal']) && isset($_GET["id"]) && ctype_digit($_GET["id"])) { + $movie = new Film(['Settings' => $page->settings]); $mov = $movie->getMovieInfo($_GET['id']); - if (!$mov) + if (!$mov) { $page->show404(); + } $mov['actors'] = $movie->makeFieldLinks($mov, 'actors'); $mov['genre'] = $movie->makeFieldLinks($mov, 'genre'); $mov['director'] = $movie->makeFieldLinks($mov, 'director'); - $page->smarty->assign('movie', $mov); + $page->smarty->assign(['movie' => $mov, 'modal' => true]); - $page->title = "Info for ".$mov['title']; + $page->title = "Info for " . $mov['title']; $page->meta_title = ""; $page->meta_keywords = ""; $page->meta_description = ""; $page->smarty->registerPlugin('modifier', 'ss', 'stripslashes'); - $modal = false; - if (isset($_GET['modal'])) - { - $modal = true; - $page->smarty->assign('modal', true); - } - $page->content = $page->smarty->fetch('viewmovie.tpl'); - if ($modal) - echo $page->content; - else - $page->render(); -} - + echo $page->content; +} else { + $page->render(); +} \ No newline at end of file diff --git a/www/pages/profile.php b/www/pages/profile.php index 7adbee96a..75e17f0e5 100644 --- a/www/pages/profile.php +++ b/www/pages/profile.php @@ -7,19 +7,19 @@ $nzbget = new NZBGet($page); if (!$page->users->isLoggedIn()) $page->show403(); -$userid = 0; +$userID = 0; if (isset($_GET["id"])) - $userid = $_GET["id"] + 0; + $userID = $_GET["id"] + 0; elseif (isset($_GET["name"])) { $res = $page->users->getByUsername($_GET["name"]); if ($res) - $userid = $res["id"]; + $userID = $res["id"]; } else - $userid = $page->users->currentUserId(); + $userID = $page->users->currentUserId(); -$privileged = ($page->users->isAdmin($userid) || $page->users->isModerator($userid)) ? true : false; +$privileged = ($page->users->isAdmin($userID) || $page->users->isModerator($userID)) ? true : false; $privateProfiles = ($page->settings->getSetting('privateprofiles') == 1) ? true : false; $publicView = false; @@ -35,74 +35,64 @@ if (!$privateProfiles || $privileged) { $altID = $user['id']; } } else if ($altID !== false) { - $userid = $altID; + $userID = $altID; $publicView = true; } } -$data = $page->users->getById($userid); +$data = $page->users->getById($userID); if (!$data) $page->show404(); -$invitedby = ''; -if ($data["invitedby"] != "") - $invitedby = $page->users->getById($data["invitedby"]); +// Check if the user selected a theme. +if (!isset($data['style']) || $data['style'] == 'None') { + $data['style'] = 'Using the admin selected theme.'; +} -$page->smarty->assign('apihits', $page->users->getApiRequests($userid)); -$page->smarty->assign('grabstoday', $page->users->getDownloadRequests($userid)); -$page->smarty->assign('userinvitedby',$invitedby); -$page->smarty->assign('user',$data); -$page->smarty->assign('privateprofiles', $privateProfiles); -$page->smarty->assign('publicview', $publicView); -$page->smarty->assign('privileged', $privileged); +$offset = isset($_REQUEST["offset"]) ? $_REQUEST["offset"] : 0; +$page->smarty->assign([ + 'apirequests' => $page->users->getApiRequests($userID), + 'userinvitedby' => ($data['invitedby'] != '' ? $page->users->getById($data['invitedby']) : ''), + 'user' => $data, + 'privateprofiles' => $privateProfiles, + 'publicview' => $publicView, + 'privileged' => $privileged, + 'pagertotalitems' => $rc->getCommentCountForUser($userID), + 'pageroffset' => $offset, + 'pageritemsperpage' => ITEMS_PER_PAGE, + 'pagerquerybase' => "/profile?id=$userID&offset=", + 'pagerquerysuffix' => "#comments" + ] +); -$commentcount = $rc->getCommentCountForUser($userid); -$offset = isset($_REQUEST["offset"]) ? $_REQUEST["offset"] : 0; -$page->smarty->assign('pagertotalitems',$commentcount); -$page->smarty->assign('pageroffset',$offset); -$page->smarty->assign('pageritemsperpage',ITEMS_PER_PAGE); -$page->smarty->assign('pagerquerybase', "/profile?id=".$userid."&offset="); -$page->smarty->assign('pagerquerysuffix', "#comments"); -$page->smarty->assign('privateprofiles', ($page->settings->getSetting('privateprofiles') == 1) ? true : false ); +$sabApiKeyTypes = [ + SABnzbd::API_TYPE_NZB => 'Nzb Api Key', + SABnzbd::API_TYPE_FULL => 'Full Api Key' +]; +$sabPriorities = [ + SABnzbd::PRIORITY_FORCE => 'Force', SABnzbd::PRIORITY_HIGH => 'High', + SABnzbd::PRIORITY_NORMAL => 'Normal', SABnzbd::PRIORITY_LOW => 'Low' +]; +$sabSettings = [1 => 'Site', 2 => 'Cookie']; -$pager = $page->smarty->fetch("pager.tpl"); -$page->smarty->assign('pager', $pager); +// Pager must be fetched after the variables are assigned to smarty. +$page->smarty->assign([ + 'pager' => $page->smarty->fetch("pager.tpl"), + 'commentslist' => $rc->getCommentsForUserRange($userID, $offset, ITEMS_PER_PAGE), + 'exccats' => implode(",", $page->users->getCategoryExclusionNames($userID)), + 'saburl' => $sab->url, + 'sabapikey' => $sab->apikey, + 'sabapikeytype' => ($sab->apikeytype != '' ? $sabApiKeyTypes[$sab->apikeytype] : ''), + 'sabpriority' => ($sab->priority != '' ? $sabPriorities[$sab->priority] : ''), + 'sabsetting' => $sabSettings[($sab->checkCookie() === true ? 2 : 1)] + ] +); -$commentslist = $rc->getCommentsForUserRange($userid, $offset, ITEMS_PER_PAGE); -$page->smarty->assign('commentslist',$commentslist); - -$downloadlist = $page->users->getDownloadRequestsForUserAndAllHostHashes($userid); -$page->smarty->assign('downloadlist',$downloadlist); - - -$exccats = $page->users->getCategoryExclusionNames($userid); -$page->smarty->assign('exccats', implode(",", $exccats)); - -$page->smarty->assign('saburl', $sab->url); -$page->smarty->assign('sabapikey', $sab->apikey); - -$page->smarty->assign('nzbgeturl', $nzbget->url); -$page->smarty->assign('nzbgetusername', $nzbget->userName); -$page->smarty->assign('nzbgetpassword', $nzbget->password); - - -$sabapikeytypes = array(SABnzbd::API_TYPE_NZB=>'Nzb Api Key', SABnzbd::API_TYPE_FULL=>'Full Api Key'); -if ($sab->apikeytype != "") - $page->smarty->assign('sabapikeytype', $sabapikeytypes[$sab->apikeytype]); - -$sabpriorities = array(SABnzbd::PRIORITY_FORCE=>'Force', SABnzbd::PRIORITY_HIGH=>'High', SABnzbd::PRIORITY_NORMAL=>'Normal', SABnzbd::PRIORITY_LOW=>'Low', SABnzbd::PRIORITY_PAUSED=>'Paused'); -if ($sab->priority != "") - $page->smarty->assign('sabpriority', $sabpriorities[$sab->priority]); - -$sabsettings = array(1=>'Site', 2=>'Cookie'); -$page->smarty->assign('sabsetting', $sabsettings[($sab->checkCookie()===true?2:1)]); - -$page->meta_title = "View User Profile"; -$page->meta_keywords = "view,profile,user,details"; -$page->meta_description = "View User Profile for ".$data["username"] ; +$page->meta_title = "View User Profile"; +$page->meta_keywords = "view,profile,user,details"; +$page->meta_description = "View User Profile for " . $data["username"]; $page->content = $page->smarty->fetch('profile.tpl'); -$page->render(); - +$page->render(); \ No newline at end of file diff --git a/www/pages/rss.php b/www/pages/rss.php index f6aaf414e..8d49b4ca7 100644 --- a/www/pages/rss.php +++ b/www/pages/rss.php @@ -22,21 +22,21 @@ if (!isset($_GET["t"]) && !isset($_GET["rage"]) && !isset($_GET["anidb"])) { $page->meta_keywords = "view,nzb,description,details,rss,atom"; $page->meta_description = "View available Rss Nzb feeds."; - $categorylist = $category->get(true, $page->userdata["categoryexclusions"]); - $page->smarty->assign('categorylist', $categorylist); - - $parentcategorylist = $category->getForMenu($page->userdata["categoryexclusions"]); - $page->smarty->assign('parentcategorylist', $parentcategorylist); + $page->smarty->assign([ + 'categorylist' => $category->get(true, $page->userdata["categoryexclusions"]), + 'parentcategorylist' => $category->getForMenu($page->userdata["categoryexclusions"]) + ] + ); $page->content = $page->smarty->fetch('rssdesc.tpl'); $page->render(); } else { - $rsstoken = $uid = -1; + $rssToken = $uid = -1; // User requested a feed, ensure either logged in or passing a valid token. if ($page->users->isLoggedIn()) { $uid = $page->userdata["id"]; - $rsstoken = $page->userdata["rsstoken"]; - $maxrequests = $page->userdata['apirequests']; + $rssToken = $page->userdata["rsstoken"]; + $maxRequests = $page->userdata['apirequests']; } else { if ($page->settings->getSetting('registerstatus') == Settings::REGISTER_STATUS_API_ONLY) { $res = $page->users->getById(0); @@ -55,68 +55,46 @@ if (!isset($_GET["t"]) && !isset($_GET["rage"]) && !isset($_GET["anidb"])) { } $uid = $res["id"]; - $rsstoken = $res['rsstoken']; - $maxrequests = $res['apirequests']; + $rssToken = $res['rsstoken']; + $maxRequests = $res['apirequests']; } - $apirequests = $page->users->getApiRequests($uid); - if ($apirequests['num'] > $maxrequests) { + if ($page->users->getApiRequests($uid) > $maxRequests) { header('X-newznab: ERROR: You have reached your daily limit for API requests!'); $page->show503(); } else { $page->users->addApiRequest($uid, $_SERVER['REQUEST_URI']); } - // Valid or logged in user, get them the requested feed. - if (isset($_GET["dl"]) && $_GET["dl"] == "1") { - $page->smarty->assign("dl", "1"); - } - $usercat = -1; - if (isset($_GET["t"])) { - $usercat = ($_GET["t"] == 0 ? -1 : $_GET["t"]); - } - - $userrage = $useranidb = $page->userseries = -1; + $userRage = $userAnidb = -1; if (isset($_GET["rage"])) { - $userrage = ($_GET["rage"] == 0 ? -1 : $_GET["rage"] + 0); + $userRage = ($_GET["rage"] == 0 ? -1 : $_GET["rage"] + 0); } elseif (isset($_GET["anidb"])) { - $useranidb = ($_GET["anidb"] == 0 ? -1 : $_GET["anidb"] + 0); + $userAnidb = ($_GET["anidb"] == 0 ? -1 : $_GET["anidb"] + 0); } - $usernum = 100; - if (isset($_GET["num"])) { - $usernum = $_GET["num"] + 0; - } + $userCat = (isset($_GET['t']) ? ($_GET['t'] == 0 ? -1 : $_GET['t']) : -1); + $userNum = (isset($_GET["num"]) && is_numeric($_GET['num']) ? abs($_GET['num']) : 100); + $userAirDate = (isset($_GET["airdate"]) && is_numeric($_GET['airdate']) ? abs($_GET["airdate"]) : -1); - if (isset($_GET["del"]) && $_GET["del"] == "1") { - $page->smarty->assign("del", "1"); - } + $page->smarty->assign([ + 'dl' => (isset($_GET['dl']) && $_GET['dl'] == '1' ? '1' : '0'), + 'del' => (isset($_GET['del']) && $_GET['del'] == '1' ? '1' : '0'), + 'uid' => $uid, + 'rsstoken' => $rssToken + ] + ); - $userairdate = -1; - if (isset($_GET["airdate"])) { - $userairdate = $_GET["airdate"] + 0; - } - - $page->smarty->assign('uid', $uid); - $page->smarty->assign('rsstoken', $rsstoken); - - if ($usercat == -3) { - $catexclusions = $page->users->getCategoryExclusion($uid); - $reldata = $releases->getShowsRss($usernum, $uid, $catexclusions, $userairdate); - } elseif ($usercat == -4) { - $catexclusions = $page->users->getCategoryExclusion($uid); - $reldata = $releases->getMyMoviesRss($usernum, $uid, $catexclusions); + if ($userCat == -3) { + $relData = $releases->getShowsRss($userNum, $uid, $page->users->getCategoryExclusion($uid), $userAirDate); + } elseif ($userCat == -4) { + $relData = $releases->getMyMoviesRss($userNum, $uid, $page->users->getCategoryExclusion($uid)); } else { - $reldata = $releases->getRss(explode(",", $usercat), - $usernum, - $userrage, - $useranidb, - $uid, - $userairdate); + $relData = $releases->getRss(explode(',', $userCat), $userNum, $userRage, $userAnidb, $uid, $userAirDate); } - $page->smarty->assign('releases', $reldata); + $page->smarty->assign('releases', $relData); header("Content-type: text/xml"); echo trim($page->smarty->fetch('rss.tpl')); -} \ No newline at end of file +} diff --git a/www/pages/sitemap.php b/www/pages/sitemap.php index f044ac35f..bf920942f 100644 --- a/www/pages/sitemap.php +++ b/www/pages/sitemap.php @@ -61,7 +61,11 @@ if ($page->userdata != null) // echo appropriate site map // asort($arPages); -$page->smarty->assign('sitemaps',$arPages); +$page->smarty->assign([ + 'sitemaps' => $arPages, + 'last_type' => '' + ] +); if (isset($_GET["type"]) && $_GET["type"] == "xml") {