From 8598c140bf76ab7cbdad47f20dc67360d91c8648 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Mon, 24 Oct 2016 13:03:58 +0200 Subject: [PATCH] Move from nntmux/db/Settings to app/models/Settings --- app/config/bootstrap/connections.php | 6 +- app/config/bootstrap/libraries.php | 5 + app/models/Settings.php | 140 +++++++- cli/data/populate_anidb.php | 4 +- misc/sphinxsearch/toggle_search_type.php | 6 +- misc/testing/DB/convert_to_tpg.php | 7 +- misc/testing/DB/convert_to_tpg_alt.php | 4 +- misc/testing/DB/reset_truncate.php | 3 +- misc/testing/DB/resetdb.php | 3 +- misc/testing/Dev/clean_nzbs.php | 4 +- misc/testing/Releases/fixReleaseNames.php | 7 +- misc/testing/Tests/test_amazon_API.php | 4 +- misc/testing/Tests/test_giantbomb_API.php | 4 +- misc/testing/Tests/test_regex.php | 4 +- misc/testing/Tests/test_rottentomato_API.php | 4 +- misc/testing/Tests/transactiontest.php | 8 +- .../tpg_delete_triggers_2015-08-14.php | 7 +- misc/testing/_run_once/tpg_fixes.php | 7 +- .../tpg_update_triggers_2014-09-25.php | 7 +- misc/testing/dumpnfo.php | 6 +- misc/testing/fix_filesize.php | 7 +- misc/testing/refreshMovie.php | 4 +- misc/testing/rottentom.php | 4 +- misc/testing/tidynzbfolder.php | 4 +- misc/testing/updateCategories.php | 4 +- .../multiprocessing/.do_not_run/switch.php | 31 +- misc/update/nix/tmux/bin/fixreleasenames.php | 4 +- misc/update/nix/tmux/bin/groupfixrelnames.php | 7 +- misc/update/nix/tmux/monitor.php | 9 +- misc/update/nix/tmux/run.php | 19 +- misc/update/nntpproxy.php | 4 +- misc/update/postprocess.php | 7 +- misc/update/update_binaries.php | 7 +- misc/update/update_releases.php | 7 +- nntmux/Backfill.php | 15 +- nntmux/Binaries.php | 6 +- nntmux/Books.php | 19 +- nntmux/Console.php | 20 +- nntmux/Games.php | 15 +- nntmux/Logging.php | 9 +- nntmux/MiscSorter.php | 11 +- nntmux/Movie.php | 16 +- nntmux/Music.php | 17 +- nntmux/NNTP.php | 11 +- nntmux/NZB.php | 11 +- nntmux/NZBContents.php | 11 +- nntmux/NZBImport.php | 7 +- nntmux/Nfo.php | 31 +- nntmux/ReleaseComments.php | 7 +- nntmux/ReleaseImage.php | 4 +- nntmux/Releases.php | 9 +- nntmux/RequestIDWeb.php | 11 +- nntmux/SABnzbd.php | 12 +- nntmux/SpotNab.php | 4 +- nntmux/Tmux.php | 4 +- nntmux/TmuxOutput.php | 2 +- nntmux/TmuxRun.php | 6 +- nntmux/Users.php | 21 +- nntmux/XXX.php | 7 +- nntmux/db/DB.php | 340 ++++++++++++------ nntmux/db/DbUpdate.php | 16 +- nntmux/db/Settings.php | 2 +- nntmux/db/populate/AniDB.php | 14 +- nntmux/http/Capabilities.php | 15 +- nntmux/libraries/Forking.php | 52 +-- nntmux/processing/PostProcess.php | 29 +- nntmux/processing/ProcessReleases.php | 59 +-- nntmux/processing/Videos.php | 4 +- nntmux/processing/post/AniDB.php | 7 +- nntmux/processing/post/ProcessAdditional.php | 81 ++--- nntmux/processing/tv/TMDB.php | 3 +- nntmux/processing/tv/TV.php | 3 +- nntmux/processing/tv/TraktTv.php | 3 +- nntmux/utility/Utility.php | 13 +- nntmux/utility/Versions.php | 2 +- resources/db/patches/mysql/+1~settings.sql | 19 + www/admin/ajax_sharing_settings.php | 4 +- www/admin/collection_regexes-test.php | 2 +- www/admin/release-files.php | 2 +- www/admin/sharing.php | 4 +- www/admin/site-edit.php | 6 +- www/index.php | 6 +- www/install/step7.php | 4 +- www/pages/BasePage.php | 36 +- www/pages/ajax_profile.php | 2 +- www/pages/api.php | 5 +- www/pages/contact-us.php | 10 +- www/pages/details.php | 8 +- www/pages/failed.php | 4 +- www/pages/forgottenpassword.php | 8 +- www/pages/forum.php | 2 +- www/pages/forumpost.php | 2 +- www/pages/getnzb.php | 8 +- www/pages/mymovies.php | 2 +- www/pages/myshows.php | 2 +- www/pages/profile.php | 2 +- www/pages/profileedit.php | 2 +- www/pages/queue.php | 2 +- www/pages/register.php | 6 +- www/pages/rss.php | 8 +- www/pages/sitemap.php | 6 +- www/pages/terms-and-conditions.php | 4 +- www/themes/Charisma/templates/profileedit.tpl | 8 +- www/themes/Charisma/templates/viewqueue.tpl | 4 +- www/themes/Gamma/templates/profileedit.tpl | 8 +- www/themes/Gamma/templates/viewqueue.tpl | 4 +- www/themes/Gentele/templates/profileedit.tpl | 8 +- www/themes/Gentele/templates/viewqueue.tpl | 6 +- www/themes/Omicron/templates/profileedit.tpl | 8 +- www/themes/Omicron/templates/viewqueue.tpl | 4 +- 110 files changed, 919 insertions(+), 584 deletions(-) create mode 100644 resources/db/patches/mysql/+1~settings.sql diff --git a/app/config/bootstrap/connections.php b/app/config/bootstrap/connections.php index a0175f1c2..8604d1d33 100644 --- a/app/config/bootstrap/connections.php +++ b/app/config/bootstrap/connections.php @@ -109,9 +109,13 @@ if (file_exists($config) && !defined('NN_INSTALLER')) { 'persistent' => false, ] ); + + \nntmux\utility\Utility::setCoversConstant( + \app\models\Settings::value('site.main.coverspath') + ); } } else { - /** throw new ErrorException("Couldn't open NNTmux's configuration file!"); */ + /** throw new ErrorException("Couldn't open NN's configuration file!"); */ Connections::add('default', [ 'type' => 'database', diff --git a/app/config/bootstrap/libraries.php b/app/config/bootstrap/libraries.php index ff33a0e7b..734fa4d3c 100644 --- a/app/config/bootstrap/libraries.php +++ b/app/config/bootstrap/libraries.php @@ -53,6 +53,10 @@ */ define('LITHIUM_APP_PATH', realpath(dirname(dirname(__DIR__)))); +if (!defined('NN_ROOT')) { + define('NN_ROOT', realpath(dirname(LITHIUM_APP_PATH)) . DS); +} + /** * This is the path to the class libraries used by your application, and must contain a copy of the * Lithium core. By default, this directory is named `libraries`, and resides in the same @@ -133,6 +137,7 @@ if (!defined('NN_INSTALLER') || NN_INSTALLER !== true) { } require_once LITHIUM_APP_PATH . DS . 'libraries' . DS . 'autoload.php'; + /** * Add some plugins: */ diff --git a/app/models/Settings.php b/app/models/Settings.php index 2260654d2..f8c97b052 100644 --- a/app/models/Settings.php +++ b/app/models/Settings.php @@ -27,9 +27,80 @@ namespace app\models; * *@package app\models */ -class Settings extends \lithium\data\Model { +class Settings extends \lithium\data\Model +{ + const REGISTER_STATUS_OPEN = 0; - public $validates = []; + const REGISTER_STATUS_INVITE = 1; + + const REGISTER_STATUS_CLOSED = 2; + + const REGISTER_STATUS_API_ONLY = 3; + + const ERR_BADUNRARPATH = -1; + + const ERR_BADFFMPEGPATH = -2; + + const ERR_BADMEDIAINFOPATH = -3; + + const ERR_BADNZBPATH = -4; + + const ERR_DEEPNOUNRAR = -5; + + const ERR_BADTMPUNRARPATH = -6; + + const ERR_BADNZBPATH_UNREADABLE = -7; + + const ERR_BADNZBPATH_UNSET = -8; + + const ERR_BAD_COVERS_PATH = -9; + + const ERR_BAD_YYDECODER_PATH = -10; + + public $validates = [ + 'section' => [ + [ + 'required' => false + ] + ], + 'subsection' => [ + [ + 'required' => false + ] + ], + 'name' => [ + [ + 'required' => true + ], + [ + 'notEmpty', + 'message' => 'You must supply a name for this setting.' + ] + ], + 'value' => [ + [ + 'required' => true + ] + ], + 'hint' => [ + [ + 'required' => true + ], + [ + 'notEmpty', + 'message' => 'You must supply a hint/description for this setting.' + ] + ], + 'setting' => [ + [ + 'required' => true + ], + [ + 'notEmpty', + 'message' => 'You must supply a name for this setting.' + ] + ], + ]; protected $_meta = [ 'key' => ['section', 'subsection', 'name'] @@ -40,11 +111,7 @@ class Settings extends \lithium\data\Model { static::finder('setting', function ($params, $next) { - if (!is_array($params['options']['conditions'])) { - $params['options']['conditions'] = self::dottedToArray($params['options']['conditions']); - } elseif (count($params) == 1) { - $params['options']['conditions'] = self::dottedToArray($params['options']['conditions'][0]); - } + $params['options']['conditions'] = self::settingToArray($params['options']['conditions']); $params['type'] = 'first'; $array = array_diff_key( @@ -62,13 +129,65 @@ class Settings extends \lithium\data\Model { ); } + /** + * Return a tree-like array of all or selected settings. + * + * @param array $options Options array for Settings::find() i.e. ['conditions' => ...]. + * @param bool $excludeUnsectioned If rows with empty 'section' field should be excluded. + * Note this doesn't prevent empty 'subsection' fields. + * @return array + * @throws \RuntimeException + */ + public static function toTree(array $options = [], $excludeUnsectioned = true) + { + $results = empty($options) ? + Settings::find('all') : + Settings::find('all', $options); + + $tree = []; + if (is_array($results)) { + foreach ($results as $result) { + if (!empty($result['section']) || !$excludeUnsectioned) { + $tree[$result['section']][$result['subsection']][$result['name']] = + ['value' => $result['value'], 'hint' => $result['hint']]; + } + } + } else { + throw new \RuntimeException( + "NO results from Settings table! Check your table has been created and populated." + ); + } + + return $tree; + } + + /** + * Checks the supplied parameter is either a string or an array with single element. If + * either the value is passed to Settings::dottedToArray() for conversion. Otherwise the + * value is returned unchanged. + * + * @param $setting Setting array/string to check. + * + * @return array|boolean + */ + public static function settingToArray($setting) + { + if (!is_array($setting)) { + $setting = self::dottedToArray($setting); + } elseif (count($setting) == 1) { + $setting = self::dottedToArray($setting[0]); + } + + return $setting; + } + /** * Return the value of supplied setting. - * The setting can be either a a normal condition array for the custom 'setting' finder or a - * dotted string notation setting. + * The setting can be either a normal condition array for the custom 'setting' finder or a + * dotted string notation setting. Note that dotted notation will be converted to an array, + * so it will be slower: Explicitly use the array format if speed it paramount. * Be aware that this method only returns the first of any values found, so make sure your * $setting produces a unique result. - * * @param $setting * @param bool $returnAlways Indicates if the method should throw an exception (false) or return * null on failure. Defaults to throwing an exception. @@ -113,7 +232,6 @@ class Settings extends \lithium\data\Model { } else { return false; } - //var_dump($result); return $result; diff --git a/cli/data/populate_anidb.php b/cli/data/populate_anidb.php index c4d50a278..622659744 100755 --- a/cli/data/populate_anidb.php +++ b/cli/data/populate_anidb.php @@ -4,10 +4,10 @@ */ require_once realpath(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'bootstrap.php'); -use nntmux\db\Settings; +use nntmux\db\DB; use nntmux\db\populate\AniDB; -$pdo = new Settings(); +$pdo = new DB(); if ($argc > 1 && $argv[1] == true) { (new AniDB(['Settings' => $pdo, 'Echo' => true]))->populateTable('full'); diff --git a/misc/sphinxsearch/toggle_search_type.php b/misc/sphinxsearch/toggle_search_type.php index efc41f054..30fb0bf4f 100644 --- a/misc/sphinxsearch/toggle_search_type.php +++ b/misc/sphinxsearch/toggle_search_type.php @@ -2,7 +2,7 @@ require_once realpath(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'bootstrap.php'); use nntmux\ReleaseSearch; -use nntmux\db\Settings; +use nntmux\db\DB; if (!isset($argv[1]) || !in_array($argv[1], ['sphinx', 'standard'])) { @@ -15,13 +15,13 @@ if (!isset($argv[1]) || !in_array($argv[1], ['sphinx', 'standard'])) { switch ($argv[1]) { case 'sphinx': if (NN_RELEASE_SEARCH_TYPE == ReleaseSearch::SPHINX) { - optimizeForSphinx(new Settings()); + optimizeForSphinx(new DB()); } else { echo PHP_EOL . $pdo->log->error('Error, NN_RELEASE_SEARCH_TYPE in www/settings.php must be set to SPHINX to optimize for Sphinx!' . PHP_EOL); } break; case 'standard': - revertToStandard(new Settings()); + revertToStandard(new DB()); break; } diff --git a/misc/testing/DB/convert_to_tpg.php b/misc/testing/DB/convert_to_tpg.php index 67709d56b..ea29f573c 100644 --- a/misc/testing/DB/convert_to_tpg.php +++ b/misc/testing/DB/convert_to_tpg.php @@ -1,16 +1,17 @@ $pdo]); $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); -$DoPartRepair = ($pdo->getSetting('partrepair') == '0') ? false : true; +$DoPartRepair = (Settings::value('..partrepair') == '0') ? false : true; if ((!isset($argv[1])) || $argv[1] != 'true') { exit($pdo->log->error("\nMandatory argument missing\n\n" diff --git a/misc/testing/DB/convert_to_tpg_alt.php b/misc/testing/DB/convert_to_tpg_alt.php index d4892d71b..af81e08e1 100644 --- a/misc/testing/DB/convert_to_tpg_alt.php +++ b/misc/testing/DB/convert_to_tpg_alt.php @@ -1,12 +1,12 @@ log->error("\nThis script will move all collections, binaries, parts into tables per group.\n\n" diff --git a/misc/testing/DB/reset_truncate.php b/misc/testing/DB/reset_truncate.php index a0218f4a0..b22956064 100644 --- a/misc/testing/DB/reset_truncate.php +++ b/misc/testing/DB/reset_truncate.php @@ -1,6 +1,7 @@ getSetting('tablepergroup'); + $tpg = Settings::value('..tablepergroup'); $tablepergroup = (!empty($tpg)) ? $tpg : 0; if ($tablepergroup == 1) { diff --git a/misc/testing/DB/resetdb.php b/misc/testing/DB/resetdb.php index 610bd3cc9..05c6e16a4 100644 --- a/misc/testing/DB/resetdb.php +++ b/misc/testing/DB/resetdb.php @@ -1,6 +1,7 @@ optimise(false, 'full'); echo $pdo->log->header("Deleting nzbfiles subfolders."); try { - $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($pdo->getSetting('nzbpath'), \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); + $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(Settings::value('..nzbpath'), \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($files as $file) { if (basename($file) != '.gitignore' && basename($file) != 'tmpunrar') { $todo = ($file->isDir() ? 'rmdir' : 'unlink'); diff --git a/misc/testing/Dev/clean_nzbs.php b/misc/testing/Dev/clean_nzbs.php index cea45e673..04d91d189 100644 --- a/misc/testing/Dev/clean_nzbs.php +++ b/misc/testing/Dev/clean_nzbs.php @@ -1,7 +1,7 @@ log->header('Getting List of nzbs to check against db.'); echo $pdo->log->header("Checked / {$couldbe}moved\n"); -$dirItr = new \RecursiveDirectoryIterator($pdo->getSetting('nzbpath')); +$dirItr = new \RecursiveDirectoryIterator(Settings::value('..nzbpath')); $itr = new \RecursiveIteratorIterator($dirItr, \RecursiveIteratorIterator::LEAVES_ONLY); foreach ($itr as $filePath) { diff --git a/misc/testing/Releases/fixReleaseNames.php b/misc/testing/Releases/fixReleaseNames.php index 89ed7e0c0..e200866dc 100755 --- a/misc/testing/Releases/fixReleaseNames.php +++ b/misc/testing/Releases/fixReleaseNames.php @@ -9,13 +9,14 @@ require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'bootstrap.php'); +use app\models\Settings; use nntmux\NameFixer; use nntmux\NNTP; use nntmux\PreDb; -use nntmux\db\Settings; +use nntmux\db\DB; $n = "\n"; -$pdo = new Settings(); +$pdo = new DB(); $namefixer = new NameFixer(['Settings' => $pdo]); $predb = new PreDb(['Echo' => true, 'Settings' => $pdo]); @@ -37,7 +38,7 @@ if (isset($argv[1]) && isset($argv[2]) && isset($argv[3]) && isset($argv[4])) { $nntp = null; if ($argv[1] == 7 || $argv[1] == 8) { $nntp = new NNTP(['Settings' => $pdo]); - if (($pdo->getSetting('alternate_nntp') == '1' ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) { + if ((Settings::value('..alternate_nntp') == '1' ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) { echo $pdo->log->error("Unable to connect to usenet.\n"); return; } diff --git a/misc/testing/Tests/test_amazon_API.php b/misc/testing/Tests/test_amazon_API.php index e3e717b9a..5ef2ed827 100644 --- a/misc/testing/Tests/test_amazon_API.php +++ b/misc/testing/Tests/test_amazon_API.php @@ -4,9 +4,9 @@ require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . use ApaiIO\Configuration\GenericConfiguration; use ApaiIO\Operations\Search; use ApaiIO\ApaiIO; -use nntmux\db\Settings; +use nntmux\db\DB; -$s = new Settings(); +$s = new DB(); $pubkey = $s->getSetting('amazonpubkey'); $privkey = $s->getSetting('amazonprivkey'); diff --git a/misc/testing/Tests/test_giantbomb_API.php b/misc/testing/Tests/test_giantbomb_API.php index 2c893f589..047467297 100755 --- a/misc/testing/Tests/test_giantbomb_API.php +++ b/misc/testing/Tests/test_giantbomb_API.php @@ -4,9 +4,9 @@ require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . // Test if your giantbomb key is working. use nntmux\ColorCLI; -use nntmux\db\Settings; +use nntmux\db\DB; -$giantbombkey = (new Settings())->getSetting('giantbombkey'); +$giantbombkey = (new DB())->getSetting('giantbombkey'); $cli = new ColorCLI(); $obj = new GiantBomb($giantbombkey, $resp = "json"); diff --git a/misc/testing/Tests/test_regex.php b/misc/testing/Tests/test_regex.php index 7f8ce1428..c02ff1e01 100644 --- a/misc/testing/Tests/test_regex.php +++ b/misc/testing/Tests/test_regex.php @@ -7,7 +7,7 @@ // require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'bootstrap.php'); -use nntmux\db\Settings; +use nntmux\db\DB; function handleError($errno, $errstr, $errfile, $errline, array $errcontext) { @@ -26,7 +26,7 @@ $regs = array( "simple" => '"data.mp3', ); -$db = new Settings(); +$db = new DB(); # fetch enabled regular expression $catsql = "select ID,groupname,regex from releaseregex where status = 1"; $res = $db->query($catsql); diff --git a/misc/testing/Tests/test_rottentomato_API.php b/misc/testing/Tests/test_rottentomato_API.php index 553afa5df..bc27b83a9 100755 --- a/misc/testing/Tests/test_rottentomato_API.php +++ b/misc/testing/Tests/test_rottentomato_API.php @@ -3,11 +3,11 @@ require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . use nntmux\ColorCLI; use nntmux\RottenTomato; -use nntmux\db\Settings; +use nntmux\db\DB; $cli = new ColorCLI(); -$rtkey = (new Settings())->getSetting('rottentomatokey'); +$rtkey = (new DB())->getSetting('rottentomatokey'); if (isset($rtkey)) { $rt = new RottenTomato($rtkey); print_r(json_decode($rt->searchMovie("inception"))); diff --git a/misc/testing/Tests/transactiontest.php b/misc/testing/Tests/transactiontest.php index 60c3c61b2..3c5198cf0 100644 --- a/misc/testing/Tests/transactiontest.php +++ b/misc/testing/Tests/transactiontest.php @@ -1,9 +1,9 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -18,7 +18,7 @@ try { echo "--[ Insert run: {$i} ]----------------------------------------". PHP_EOL; // Create a new db class instance (multiple can exist) - $newDb = new Settings(); + $newDb = new DB(); // Check that there is a new db class instance, but no new PDO instance var_dump( $newDb, $newDb->getPDO() ); @@ -41,4 +41,4 @@ try { } } catch(PDOException $e) { var_dump( $e ); -} \ No newline at end of file +} diff --git a/misc/testing/_run_once/tpg_delete_triggers_2015-08-14.php b/misc/testing/_run_once/tpg_delete_triggers_2015-08-14.php index 49eaf0e31..a2b840f32 100644 --- a/misc/testing/_run_once/tpg_delete_triggers_2015-08-14.php +++ b/misc/testing/_run_once/tpg_delete_triggers_2015-08-14.php @@ -20,11 +20,12 @@ */ require_once dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'bootstrap.php'; -use nntmux\db\Settings; +use app\models\Settings; +use nntmux\db\DB; -$pdo = new Settings(); +$pdo = new DB(); -if (!$pdo->getSetting('tablepergroup')) { +if (!Settings::value('..tablepergroup')) { exit("Tables per groups is not enabled, quitting!"); } diff --git a/misc/testing/_run_once/tpg_fixes.php b/misc/testing/_run_once/tpg_fixes.php index a31648fac..1056e2ed3 100644 --- a/misc/testing/_run_once/tpg_fixes.php +++ b/misc/testing/_run_once/tpg_fixes.php @@ -27,11 +27,12 @@ if (!isset($argv[1]) || !in_array($argv[1], ['1'])) { } require_once dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'bootstrap.php'; -use nntmux\db\Settings; +use app\models\Settings; +use nntmux\db\DB; -$pdo = new Settings(); +$pdo = new DB(); -if (!$pdo->getSetting('tablepergroup')) { +if (!Settings::value('..tablepergroup')) { exit("Tables per groups is not enabled, quitting!"); } diff --git a/misc/testing/_run_once/tpg_update_triggers_2014-09-25.php b/misc/testing/_run_once/tpg_update_triggers_2014-09-25.php index 8d79e7602..f44b4e405 100644 --- a/misc/testing/_run_once/tpg_update_triggers_2014-09-25.php +++ b/misc/testing/_run_once/tpg_update_triggers_2014-09-25.php @@ -20,11 +20,12 @@ */ require_once dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'bootstrap.php'; -use nntmux\db\Settings; +use app\models\Settings; +use nntmux\db\DB; -$pdo = new Settings(); +$pdo = new DB(); -if (!$pdo->getSetting('tablepergroup')) { +if (!Settings::value('..tablepergroup')) { exit("Tables per groups is not enabled, quitting!"); } diff --git a/misc/testing/dumpnfo.php b/misc/testing/dumpnfo.php index 52bb5e2e7..02d5ff746 100644 --- a/misc/testing/dumpnfo.php +++ b/misc/testing/dumpnfo.php @@ -7,11 +7,11 @@ require_once realpath(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'bootstrap.php'); -use nntmux\db\Settings; +use nntmux\db\DB; use nntmux\utility\Utility; -$db = new Settings(); +$db = new DB(); $res = $db->queryDirect("select releases.searchname, releases.postdate, uncompress(release_nfos.nfo) as nfo from releases inner join release_nfos on releases.ID = release_nfos.releaseID and release_nfos.nfo is not null order by postdate"); while ($row = $db->getAssocArray($res)) @@ -29,4 +29,4 @@ while ($row = $db->getAssocArray($res)) fwrite($fh, Utility::cp437toUTF($row["nfo"])); fclose($fh); } -} \ No newline at end of file +} diff --git a/misc/testing/fix_filesize.php b/misc/testing/fix_filesize.php index 77a463be3..8f002507f 100644 --- a/misc/testing/fix_filesize.php +++ b/misc/testing/fix_filesize.php @@ -8,10 +8,11 @@ Author: lordgnu require_once realpath(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'bootstrap.php'); -use nntmux\db\Settings; +use app\models\Settings; +use nntmux\db\DB; use nntmux\NZB; -$pdo = new Settings; +$pdo = new DB; $nzb = new NZB; $items = $pdo->query("SELECT id,guid FROM releases WHERE size = 0"); @@ -21,7 +22,7 @@ echo "Updating file size for " . count($items) . " release(s)\n"; while ($item = array_pop($items)) { - $nzbpath = $nzb->getNZBPath($item['guid'], $pdo->getSetting('nzbpath')); + $nzbpath = $nzb->getNZBPath($item['guid'], Settings::value('..nzbpath')); ob_start(); @readgzfile($nzbpath); diff --git a/misc/testing/refreshMovie.php b/misc/testing/refreshMovie.php index c8d634127..788e63671 100644 --- a/misc/testing/refreshMovie.php +++ b/misc/testing/refreshMovie.php @@ -2,10 +2,10 @@ require_once realpath(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'bootstrap.php'); -use nntmux\db\Settings; +use nntmux\db\DB; use nntmux\Movie; -$db = new Settings(); +$db = new DB(); $movie = new Movie(['Echo' => true, 'Settings' => $pdo]); $movies = []; $counter = 1; diff --git a/misc/testing/rottentom.php b/misc/testing/rottentom.php index 846368fa9..9e1952c9c 100644 --- a/misc/testing/rottentom.php +++ b/misc/testing/rottentom.php @@ -1,10 +1,10 @@ getSetting('rottentomatokey'); $rt = new RottenTomato($rtkey); diff --git a/misc/testing/tidynzbfolder.php b/misc/testing/tidynzbfolder.php index 23b74667e..d5b853522 100644 --- a/misc/testing/tidynzbfolder.php +++ b/misc/testing/tidynzbfolder.php @@ -1,10 +1,10 @@ (int) backfill type from tmux settings. 1 = Backfill interval , 2 = Bakfill all case 'backfill': if (in_array((int)$options[3], [1, 2])) { - $pdo = new Settings(); + $pdo = new DB(); $value = $pdo->queryOneRow("SELECT value FROM tmux WHERE setting = 'backfill_qty'"); if ($value !== false) { $nntp = nntp($pdo); @@ -43,7 +44,7 @@ switch ($options[1]) { * $options[3] => (int) Quantity of articles to download. */ case 'backfill_all_quantity': - $pdo = new Settings(); + $pdo = new DB(); $nntp = nntp($pdo); (new Backfill())->backfillAllGroups($options[2], $options[3]); break; @@ -51,7 +52,7 @@ switch ($options[1]) { // BackFill a single group, 10000 parts. // $options[2] => (string)group name, Name of group to work on. case 'backfill_all_quick': - $pdo = new Settings(); + $pdo = new DB(); $nntp = nntp($pdo); (new Backfill())->backfillAllGroups($options[2], 10000, 'normal'); break; @@ -65,7 +66,7 @@ switch ($options[1]) { * $options[6] => (int) Number of threads. */ case 'get_range': - $pdo = new Settings(); + $pdo = new DB(); $nntp = nntp($pdo); $groups = new Groups(); $groupMySQL = $groups->getByName($options[3]); @@ -75,7 +76,7 @@ switch ($options[1]) { } } $binaries = new Binaries(['NNTP' => $nntp, 'Settings' => $pdo, 'Groups' => $groups]); - $return = $binaries->scan($groupMySQL, $options[4], $options[5], ($pdo->getSetting('safepartrepair') == 1 ? 'update' : 'backfill')); + $return = $binaries->scan($groupMySQL, $options[4], $options[5], (Settings::value('..safepartrepair') == 1 ? 'update' : 'backfill')); if (empty($return)) { exit(); } @@ -130,7 +131,7 @@ switch ($options[1]) { * $options[2] => (string) Group name. */ case 'part_repair': - $pdo = new Settings(); + $pdo = new DB(); $groups = new Groups(['Settings' => $pdo]); $groupMySQL = $groups->getByName($options[2]); $nntp = nntp($pdo); @@ -147,7 +148,7 @@ switch ($options[1]) { // Process releases. // $options[2] => (string)groupCount, number of groups terminated by _ | (int)groupid, group to work on case 'releases': - $pdo = new Settings(); + $pdo = new DB(); $releases = new ProcessReleases(['Settings' => $pdo]); //Runs function that are per group @@ -187,7 +188,7 @@ switch ($options[1]) { * $options[2] => (string) Group name. */ case 'update_group_headers': - $pdo = new Settings(); + $pdo = new DB(); $nntp = nntp($pdo); $groups = new Groups(); $groupMySQL = $groups->getByName($options[2]); @@ -200,7 +201,7 @@ switch ($options[1]) { case 'update_per_group': if (is_numeric($options[2])) { - $pdo = new Settings(); + $pdo = new DB(); // Get the group info from MySQL. $groupMySQL = $pdo->queryOneRow(sprintf('SELECT * FROM groups WHERE id = %d', $options[2])); @@ -234,7 +235,7 @@ switch ($options[1]) { case 'pp_additional': case 'pp_nfo': if (charCheck($options[2])) { - $pdo = new Settings(); + $pdo = new DB(); // Create the connection here and pass, this is for post processing, so check for alternate. $nntp = nntp($pdo, true); @@ -254,7 +255,7 @@ switch ($options[1]) { */ case 'pp_movie': if (charCheck($options[2])) { - $pdo = new Settings(); + $pdo = new DB(); (new PostProcess(['Settings' => $pdo]))->processMovies('', $options[2], (isset($options[3]) ? $options[3] : '')); } break; @@ -266,7 +267,7 @@ switch ($options[1]) { */ case 'pp_tv': if (charCheck($options[2])) { - $pdo = new Settings(); + $pdo = new DB(); (new PostProcess(['Settings' => $pdo]))->processTv('', $options[2], (isset($options[3]) ? $options[3] : '')); } break; @@ -281,7 +282,7 @@ switch ($options[1]) { */ function processReleases($pdo, $releases, $groupID) { - $releaseCreationLimit = ($pdo->getSetting('maxnzbsprocessed') != '' ? (int)$pdo->getSetting('maxnzbsprocessed') : 1000); + $releaseCreationLimit = (Settings::value('..maxnzbsprocessed') != '' ? (int)Settings::value('..maxnzbsprocessed') : 1000); $releases->processIncompleteCollections($groupID); $releases->processCollectionSizes($groupID); $releases->deleteUnwantedCollections($groupID); @@ -334,7 +335,7 @@ function collectionCheck(&$pdo, $groupID) function &nntp(&$pdo, $alternate = false) { $nntp = new NNTP(['Settings' => $pdo]); - if (($alternate && $pdo->getSetting('alternate_nntp') == 1 ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) { + if (($alternate && Settings::value('..alternate_nntp') == 1 ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) { exit("ERROR: Unable to connect to usenet." . PHP_EOL); } diff --git a/misc/update/nix/tmux/bin/fixreleasenames.php b/misc/update/nix/tmux/bin/fixreleasenames.php index a9253efd5..26873f8fa 100644 --- a/misc/update/nix/tmux/bin/fixreleasenames.php +++ b/misc/update/nix/tmux/bin/fixreleasenames.php @@ -1,7 +1,7 @@ error("This script is not intended to be run manually, it is called from fixreleasenames.php.")); } else if (isset($argv[1])) { - $db = new Settings(); + $db = new DB(); $namefixer = new NameFixer(['Settings' => $pdo]); $pieces = explode(' ', $argv[1]); if (isset($pieces[1]) && $pieces[0] == 'nfo') { diff --git a/misc/update/nix/tmux/bin/groupfixrelnames.php b/misc/update/nix/tmux/bin/groupfixrelnames.php index fc590ae6a..8e17c199c 100644 --- a/misc/update/nix/tmux/bin/groupfixrelnames.php +++ b/misc/update/nix/tmux/bin/groupfixrelnames.php @@ -1,6 +1,7 @@ log->error("This script is not intended to be run manually, it is called from Multiprocessing.")); @@ -181,7 +182,7 @@ if (!isset($argv[1])) { echo $pdo->log->primaryOver('p'); if (!isset($nzbcontents)) { $nntp = new NNTP(['Settings' => $pdo]); - if (($pdo->getSetting('alternate_nntp') == '1' ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) { + if ((Settings::value('..alternate_nntp') == '1' ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) { $pdo->log->error("Unable to connect to usenet."); } $Nfo = new Nfo(['Settings' => $pdo, 'Echo' => true]); diff --git a/misc/update/nix/tmux/monitor.php b/misc/update/nix/tmux/monitor.php index 6d9008e74..0cf7a485c 100644 --- a/misc/update/nix/tmux/monitor.php +++ b/misc/update/nix/tmux/monitor.php @@ -1,13 +1,14 @@ 0) { //check the db connection if ($pdo->ping(true) == false) { unset($pdo); - $pdo = new Settings(); + $pdo = new DB(); } $timer01 = time(); @@ -372,7 +373,7 @@ while ($runVar['counts']['iterations'] > 0) { $tRun->runPane('notrunning', $runVar); } - $exit = $pdo->getSetting('tmux.run.exit'); + $exit = Settings::value('tmux.run.exit'); if ($exit == 0) { $runVar['counts']['iterations']++; sleep(10); diff --git a/misc/update/nix/tmux/run.php b/misc/update/nix/tmux/run.php index 6775b4244..8802fc0a8 100644 --- a/misc/update/nix/tmux/run.php +++ b/misc/update/nix/tmux/run.php @@ -1,12 +1,13 @@ tmux_session)) ? $tmux->tmux_session : 0; $seq = (isset($tmux->sequential)) ? $tmux->sequential : 0; $powerline = (isset($tmux->powerline)) ? $tmux->powerline : 0; $colors = (isset($tmux->colors)) ? $tmux->colors : 0; -$nntpproxy = $pdo->getSetting('nntpproxy'); -$tablepergroup = $pdo->getSetting('tablepergroup'); +$nntpproxy = Settings::value('..nntpproxy'); +$tablepergroup = Settings::value('..tablepergroup'); $tablepergroup = ($tablepergroup != '') ? $tablepergroup : 0; -$delaytimet = $pdo->getSetting('delaytime'); +$delaytimet = Settings::value('..delaytime'); $delaytimet = ($delaytimet) ? (int)$delaytimet : 2; Utility::isPatched(); @@ -46,7 +47,7 @@ if (count($session) !== 0) { exit($pdo->log->error("tmux session: '" . $tmux_session . "' is already running, aborting.\n")); } -$nntpproxy = $pdo->getSetting('nntpproxy'); +$nntpproxy = Settings::value('..nntpproxy'); if ($nntpproxy == '1') { $modules = ["nntp", "socketpool"]; foreach ($modules as &$value) { @@ -121,7 +122,7 @@ function python_module_exist($module) return ($returnCode == 0 ? true : false); } -$nntpproxy = $pdo->getSetting('nntpproxy'); +$nntpproxy = Settings::value('..nntpproxy'); if ($nntpproxy == '1') { $modules = array("nntp", "socketpool"); foreach ($modules as &$value) { @@ -184,7 +185,7 @@ function start_apps($tmux_session) function window_proxy($tmux_session, $window) { global $pdo; - $nntpproxy = $pdo->getSetting('nntpproxy'); + $nntpproxy = Settings::value('..nntpproxy'); if ($nntpproxy === '1') { $DIR = NN_MISC; $nntpproxypy = $DIR . "update/python/nntpproxy.py"; @@ -194,7 +195,7 @@ function window_proxy($tmux_session, $window) } } - if ($nntpproxy === '1' && ($pdo->getSetting('alternate_nntp') == '1')) { + if ($nntpproxy === '1' && (Settings::value('..alternate_nntp') == '1')) { $DIR = NN_MISC; $nntpproxypy = $DIR . "update/python/nntpproxy.py"; if (file_exists($DIR . "python/lib/nntpproxy_a.conf")) { diff --git a/misc/update/nntpproxy.php b/misc/update/nntpproxy.php index 73c2469bd..95663dfe1 100644 --- a/misc/update/nntpproxy.php +++ b/misc/update/nntpproxy.php @@ -1,12 +1,12 @@ get(); $powerline = (isset($tmux->powerline)) ? $tmux->powerline : 0; diff --git a/misc/update/postprocess.php b/misc/update/postprocess.php index 3f49838c7..9ae2cc600 100644 --- a/misc/update/postprocess.php +++ b/misc/update/postprocess.php @@ -1,11 +1,12 @@ $pdo]); - if (($pdo->getSetting('alternate_nntp') == 1 ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) { + if ((Settings::value('..alternate_nntp') == 1 ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) { exit($pdo->log->error("Unable to connect to usenet." . PHP_EOL)); } } diff --git a/misc/update/update_binaries.php b/misc/update/update_binaries.php index 3c71ce1bb..0e7d55161 100644 --- a/misc/update/update_binaries.php +++ b/misc/update/update_binaries.php @@ -1,14 +1,15 @@ getSetting('max.headers.iteration') ?: 1000000; +$maxHeaders = Settings::value('max.headers.iteration') ?: 1000000; // Create the connection here and pass $nntp = new NNTP(['Settings' => $pdo]); diff --git a/misc/update/update_releases.php b/misc/update/update_releases.php index b24897391..d817dbfa9 100755 --- a/misc/update/update_releases.php +++ b/misc/update/update_releases.php @@ -1,14 +1,15 @@ log->error("Unable to connect to usenet.")); } } -if ($pdo->getSetting('tablepergroup') === 1) { +if (Settings::value('..tablepergroup') === 1) { exit($pdo->log->error("You are using 'tablepergroup', you must use .../misc/update/nix/multiprocessing/releases.php")); } diff --git a/nntmux/Backfill.php b/nntmux/Backfill.php index 5379f6a6c..4b1571739 100755 --- a/nntmux/Backfill.php +++ b/nntmux/Backfill.php @@ -1,7 +1,8 @@ _echoCLI = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $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]) @@ -117,11 +118,11 @@ class Backfill } } - $this->_compressedHeaders = ($this->pdo->getSetting('compressedheaders') == 1 ? true : false); - $this->_safeBackFillDate = ($this->pdo->getSetting('safebackfilldate') != '') ? (string)$this->pdo->getSetting('safebackfilldate') : '2008-08-14'; - $this->_safePartRepair = ($this->pdo->getSetting('safepartrepair') == 1 ? 'update' : 'backfill'); - $this->_tablePerGroup = ($this->pdo->getSetting('tablepergroup') == 1 ? true : false); - $this->_disableBackfillGroup = ($this->pdo->getSetting('disablebackfillgroup') == 1 ? true : false); + $this->_compressedHeaders = (Settings::value('..compressedheaders') == 1 ? true : false); + $this->_safeBackFillDate = (Settings::value('..safebackfilldate') != '') ? (string)Settings::value('safebackfilldate') : '2008-08-14'; + $this->_safePartRepair = (Settings::value('..safepartrepair') == 1 ? 'update' : 'backfill'); + $this->_tablePerGroup = (Settings::value('..tablepergroup') == 1 ? true : false); + $this->_disableBackfillGroup = (Settings::value('..disablebackfillgroup') == 1 ? true : false); } /** diff --git a/nntmux/Binaries.php b/nntmux/Binaries.php index 271e8eff8..169003d0d 100755 --- a/nntmux/Binaries.php +++ b/nntmux/Binaries.php @@ -1,7 +1,7 @@ _echoCLI = ($options['Echo'] && NN_ECHOCLI); - $this->_pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->_pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->_groups = ($options['Groups'] instanceof Groups ? $options['Groups'] : new Groups(['Settings' => $this->_pdo])); $this->_colorCLI = ($options['ColorCLI'] instanceof ColorCLI ? $options['ColorCLI'] : new ColorCLI()); $this->_nntp = ($options['NNTP'] instanceof NNTP ? $options['NNTP'] : new NNTP(['Echo' => $this->_colorCLI, 'Settings' => $this->_pdo, 'ColorCLI' => $this->_colorCLI])); @@ -193,7 +193,7 @@ class Binaries $this->_partRepairLimit = ($this->_pdo->getSetting('maxpartrepair') != '') ? (int)$this->_pdo->getSetting('maxpartrepair') : 15000; $this->_partRepairMaxTries = ($this->_pdo->getSetting('partrepairmaxtries') != '' ? (int)$this->_pdo->getSetting('partrepairmaxtries') : 3); $this->_showDroppedYEncParts = ($this->_pdo->getSetting('showdroppedyencparts') == 1 ? true : false); - $this->_tablePerGroup = ($this->_pdo->getSetting('tablepergroup') == 1 ? true : false); + $this->_tablePerGroup = ($this->_pdo->getSetting('..tablepergroup') == 1 ? true : false); $this->blackList = $this->whiteList = []; } diff --git a/nntmux/Books.php b/nntmux/Books.php index 9e75c3e5c..ac5af8ae7 100755 --- a/nntmux/Books.php +++ b/nntmux/Books.php @@ -1,7 +1,8 @@ echooutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); - $this->pubkey = $this->pdo->getSetting('amazonpubkey'); - $this->privkey = $this->pdo->getSetting('amazonprivkey'); - $this->asstag = $this->pdo->getSetting('amazonassociatetag'); - $this->bookqty = ($this->pdo->getSetting('maxbooksprocessed') != '') ? $this->pdo->getSetting('maxbooksprocessed') : 300; - $this->sleeptime = ($this->pdo->getSetting('amazonsleep') != '') ? $this->pdo->getSetting('amazonsleep') : 1000; + $this->pubkey = Settings::value('..amazonpubkey'); + $this->privkey = Settings::value('..amazonprivkey'); + $this->asstag = Settings::value('..amazonassociatetag'); + $this->bookqty = (Settings::value('..maxbooksprocessed') != '') ? Settings::value('..maxbooksprocessed') : 300; + $this->sleeptime = (Settings::value('..amazonsleep') != '') ? Settings::value('..amazonsleep') : 1000; $this->imgSavePath = NN_COVERS . 'book' . DS; - $this->bookreqids = ($this->pdo->getSetting('book_reqids') == null || $this->pdo->getSetting('book_reqids') == "") ? Category::BOOKS_MAGAZINES : $this->pdo->getSetting('book_reqids'); + $this->bookreqids = (Settings::value('..book_reqids') == null || Settings::value('..book_reqids') == "") ? Category::BOOKS_MAGAZINES : Settings::value('book_reqids'); $this->renamed = ''; - if ($this->pdo->getSetting('lookupbooks') == 2) { + if (Settings::value('..lookupbooks') == 2) { $this->renamed = 'AND isrenamed = 1'; } diff --git a/nntmux/Console.php b/nntmux/Console.php index f9f929d0a..4a3aace96 100755 --- a/nntmux/Console.php +++ b/nntmux/Console.php @@ -1,8 +1,8 @@ echooutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); - $this->pubkey = $this->pdo->getSetting('amazonpubkey'); - $this->privkey = $this->pdo->getSetting('amazonprivkey'); - $this->asstag = $this->pdo->getSetting('amazonassociatetag'); - $this->gameqty = ($this->pdo->getSetting('maxgamesprocessed') != '') ? $this->pdo->getSetting('maxgamesprocessed') : 150; - $this->sleeptime = ($this->pdo->getSetting('amazonsleep') != '') ? $this->pdo->getSetting('amazonsleep') : 1000; + $this->pubkey = Settings::value('..amazonpubkey'); + $this->privkey = Settings::value('..amazonprivkey'); + $this->asstag = Settings::value('..amazonassociatetag'); + $this->gameqty = (Settings::value('..maxgamesprocessed') != '') ? Settings::value('..maxgamesprocessed') : 150; + $this->sleeptime = (Settings::value('..amazonsleep') != '') ? Settings::value('..amazonsleep') : 1000; $this->imgSavePath = NN_COVERS . 'console' . DS; $this->renamed = ''; - if ($this->pdo->getSetting('lookupgames') == 2) { + if (Settings::value('..lookupgames') == 2) { $this->renamed = 'AND isrenamed = 1'; } - //$this->cleanconsole = ($this->pdo->getSetting('lookupgames') == 2) ? 'AND isrenamed = 1' : ''; + //$this->cleanconsole = (Settings::value('lookupgames') == 2) ? 'AND isrenamed = 1' : ''; $this->catWhere = "AND categories_id BETWEEN " . Category::GAME_ROOT . " AND " . Category::GAME_OTHER; $this->failCache =[]; diff --git a/nntmux/Games.php b/nntmux/Games.php index 51a88bcc8..a8c1a51eb 100755 --- a/nntmux/Games.php +++ b/nntmux/Games.php @@ -1,7 +1,8 @@ echoOutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); - $this->publicKey = $this->pdo->getSetting('giantbombkey'); - $this->gameQty = ($this->pdo->getSetting('maxgamesprocessed') != '') ? $this->pdo->getSetting('maxgamesprocessed') : 150; - $this->sleepTime = ($this->pdo->getSetting('amazonsleep') != '') ? $this->pdo->getSetting('amazonsleep') : 1000; + $this->publicKey = Settings::value('..giantbombkey'); + $this->gameQty = (Settings::value('..maxgamesprocessed') != '') ? Settings::value('..maxgamesprocessed') : 150; + $this->sleepTime = (Settings::value('..amazonsleep') != '') ? Settings::value('..amazonsleep') : 1000; $this->imgSavePath = NN_COVERS . 'games' . DS; $this->renamed = ''; $this->matchPercentage = 60; $this->maxHitRequest = false; $this->cookie = NN_TMP . 'xxx.cookie'; - if ($this->pdo->getSetting('lookupgames') == 2) { + if (Settings::value('..lookupgames') == 2) { $this->renamed = 'AND isrenamed = 1'; } $this->catWhere = 'AND categories_id = ' . Category::PC_GAMES . ' '; - //$this->cleangames = ($this->pdo->getSetting('('lookupgames') == 2) ? 'AND isrenamed = 1' : ''; + //$this->cleangames = (Settings::value('('lookupgames') == 2) ? 'AND isrenamed = 1' : ''; } public function getGamesInfo($id) diff --git a/nntmux/Logging.php b/nntmux/Logging.php index 38bed9f32..2818d951e 100755 --- a/nntmux/Logging.php +++ b/nntmux/Logging.php @@ -1,7 +1,8 @@ pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->newLine = PHP_EOL; } @@ -68,8 +69,8 @@ class Logging public function LogBadPasswd($username = '', $host = '') { // If logggingopt is = 0, then we do nothing, 0 = logging off. - $loggingOpt = $this->pdo->getSetting('loggingopt'); - $logFile = $this->pdo->getSetting('logfile'); + $loggingOpt = Settings::value('..loggingopt'); + $logFile = Settings::value('..logfile'); if ($loggingOpt == '1') { $this->pdo->queryInsert(sprintf('INSERT INTO logging (time, username, host) VALUES (NOW(), %s, %s)', $this->pdo->escapeString($username), $this->pdo->escapeString($host))); diff --git a/nntmux/MiscSorter.php b/nntmux/MiscSorter.php index 63d795963..50994a7c5 100755 --- a/nntmux/MiscSorter.php +++ b/nntmux/MiscSorter.php @@ -1,7 +1,8 @@ qty = 100; $this->DEBUGGING = NN_DEBUG; - $this->pdo = ($pdo instanceof Settings ? $pdo : new Settings()); + $this->pdo = ($pdo instanceof DB ? $pdo : new DB()); $this->category = new Categorize(['Settings' => $this->pdo]); $this->movie = new Movie(['Echo' => $this->echooutput, 'Settings' => $this->pdo]); $this->music = new Music(['Echo' => $this->echooutput, 'Settings' => $this->pdo]); - $this->pubkey = $this->pdo->getSetting('amazonpubkey'); - $this->privkey = $this->pdo->getSetting('amazonprivkey'); - $this->asstag = $this->pdo->getSetting('amazonassociatetag'); + $this->pubkey = Settings::value('..amazonpubkey'); + $this->privkey = Settings::value('..amazonprivkey'); + $this->asstag = Settings::value('..amazonassociatetag'); } // Main function that determines which operation(s) should be run based on the releases NFO file diff --git a/nntmux/Movie.php b/nntmux/Movie.php index 69657f23d..744b09d90 100755 --- a/nntmux/Movie.php +++ b/nntmux/Movie.php @@ -1,8 +1,8 @@ pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->releaseImage = ($options['ReleaseImage'] instanceof ReleaseImage ? $options['ReleaseImage'] : new ReleaseImage($this->pdo)); - $this->lookuplanguage = ($this->pdo->getSetting('lookuplanguage') != '') ? (string)$this->pdo->getSetting('lookuplanguage') : 'en'; + $this->lookuplanguage = (Settings::value('..lookuplanguage') != '') ? (string)Settings::value('..lookuplanguage') : 'en'; - $this->fanartapikey = $this->pdo->getSetting('fanarttvkey'); - $this->imdburl = ($this->pdo->getSetting('imdburl') == 0 ? false : true); - $this->movieqty = ($this->pdo->getSetting('maximdbprocessed') != '') ? $this->pdo->getSetting('maximdbprocessed') : 100; + $this->fanartapikey = Settings::value('f..anarttvkey'); + $this->imdburl = (Settings::value('..imdburl') == 0 ? false : true); + $this->movieqty = (Settings::value('..maximdbprocessed') != '') ? Settings::value('..maximdbprocessed') : 100; $this->searchEngines = true; $this->showPasswords = Releases::showPasswords($this->pdo); @@ -923,7 +923,7 @@ class Movie $buffer = Utility::getUrl([ 'url' => 'http://' . ($this->imdburl === false ? 'www' : 'akas') . '.imdb.com/title/tt' . $imdbId . '/', - 'Accept-Language' => (($this->pdo->getSetting('lookuplanguage') != '') ? $this->pdo->getSetting('lookuplanguage') : 'en'), + 'Accept-Language' => ((Settings::value('..lookuplanguage') != '') ? Settings::value('..lookuplanguage') : 'en'), 'useragent' => 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) ' . 'Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10', 'foo=bar' ] diff --git a/nntmux/Music.php b/nntmux/Music.php index bedd75b7e..c2e264c6e 100755 --- a/nntmux/Music.php +++ b/nntmux/Music.php @@ -1,7 +1,8 @@ echooutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); - $this->pubkey = $this->pdo->getSetting('amazonpubkey'); - $this->privkey = $this->pdo->getSetting('amazonprivkey'); - $this->asstag = $this->pdo->getSetting('amazonassociatetag'); - $this->musicqty = ($this->pdo->getSetting('maxmusicprocessed') != '') ? $this->pdo->getSetting('maxmusicprocessed') : 150; - $this->sleeptime = ($this->pdo->getSetting('amazonsleep') != '') ? $this->pdo->getSetting('amazonsleep') : 1000; + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pubkey = Settings::value('..amazonpubkey'); + $this->privkey = Settings::value('..amazonprivkey'); + $this->asstag = Settings::value('..amazonassociatetag'); + $this->musicqty = (Settings::value('..maxmusicprocessed') != '') ? Settings::value('..maxmusicprocessed') : 150; + $this->sleeptime = (Settings::value('..amazonsleep') != '') ? Settings::value('..amazonsleep') : 1000; $this->imgSavePath = NN_COVERS . 'music' . DS; $this->renamed = ''; - if ($this->pdo->getSetting('lookupmusic') == 2) { + if (Settings::value('..lookupmusic') == 2) { $this->renamed = 'AND isrenamed = 1'; } diff --git a/nntmux/NNTP.php b/nntmux/NNTP.php index 574b21d43..01bdf071a 100755 --- a/nntmux/NNTP.php +++ b/nntmux/NNTP.php @@ -2,7 +2,8 @@ namespace nntmux; use app\extensions\util\Yenc; -use nntmux\db\Settings; +use app\models\Settings; +use nntmux\db\DB; use nntmux\utility\Utility; /** @@ -107,7 +108,7 @@ class NNTP extends \Net_NNTP_Client $this->_echo = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->_debugBool = (NN_LOGGING || NN_DEBUG); if ($this->_debugBool) { @@ -118,7 +119,7 @@ class NNTP extends \Net_NNTP_Client } } - $this->_nntpRetries = ($this->pdo->getSetting('nntpretries') != '') ? (int)$this->pdo->getSetting('nntpretries') : 0 + 1; + $this->_nntpRetries = (Settings::value('..nntpretries') != '') ? (int)Settings::value('..nntpretries') : 0 + 1; } /** @@ -270,7 +271,7 @@ class NNTP extends \Net_NNTP_Client // If we are connected and authenticated, try enabling compression if we have it enabled. if ($connected === true && $authenticated === true) { // Check if we should use compression on the connection. - if ($compression === false || $this->pdo->getSetting('compressedheaders') == 0) { + if ($compression === false || Settings::value('..compressedheaders') == 0) { $this->_compressionSupported = false; } if ($this->_debugBool) { @@ -343,7 +344,7 @@ class NNTP extends \Net_NNTP_Client */ public function enableCompression() { - if (!$this->pdo->getSetting('compressedheaders') == 1) { + if (!Settings::value('..compressedheaders') == 1) { return; } $this->_enableCompression(); diff --git a/nntmux/NZB.php b/nntmux/NZB.php index d6eb5c581..2078397be 100755 --- a/nntmux/NZB.php +++ b/nntmux/NZB.php @@ -1,7 +1,8 @@ pdo = ($pdo instanceof Settings ? $pdo : new Settings()); + $this->pdo = ($pdo instanceof DB ? $pdo : new DB()); - $this->tablePerGroup = ($this->pdo->getSetting('tablepergroup') == 0 ? false : true); - $nzbSplitLevel = $this->pdo->getSetting('nzbsplitlevel'); + $this->tablePerGroup = (Settings::value('..tablepergroup') == 0 ? false : true); + $nzbSplitLevel = Settings::value('..nzbsplitlevel'); $this->nzbSplitLevel = (empty($nzbSplitLevel) ? 1 : $nzbSplitLevel); - $this->siteNzbPath = (string)$this->pdo->getSetting('nzbpath'); + $this->siteNzbPath = (string)Settings::value('..nzbpath'); if (substr($this->siteNzbPath, -1) !== DS) { $this->siteNzbPath .= DS; } diff --git a/nntmux/NZBContents.php b/nntmux/NZBContents.php index 0058145b9..94d2d2b5b 100755 --- a/nntmux/NZBContents.php +++ b/nntmux/NZBContents.php @@ -1,8 +1,9 @@ echooutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->nntp = ($options['NNTP'] instanceof NNTP ? $options['NNTP'] : new NNTP(['Echo' => $this->echooutput, 'Settings' => $this->pdo])); $this->nfo = ($options['Nfo'] instanceof Nfo ? $options['Nfo'] : new Nfo(['Echo' => $this->echooutput, 'Settings' => $this->pdo])); $this->pp = ( @@ -99,8 +100,8 @@ Class NZBContents $this->nzb = ($options['NZB'] instanceof NZB ? $options['NZB'] : new NZB($this->pdo)); $t = new Tmux(); $this->tmux = $t->get(); - $this->lookuppar2 = ($this->pdo->getSetting('lookuppar2') == 1 ? true : false); - $this->alternateNNTP = ($this->pdo->getSetting('alternate_nntp') == 1 ? true : false); + $this->lookuppar2 = (Settings::value('..lookuppar2') == 1 ? true : false); + $this->alternateNNTP = (Settings::value('..alternate_nntp') == 1 ? true : false); } /** diff --git a/nntmux/NZBImport.php b/nntmux/NZBImport.php index d83ce19c8..c831e2d9e 100755 --- a/nntmux/NZBImport.php +++ b/nntmux/NZBImport.php @@ -1,7 +1,8 @@ echoCLI = (!$this->browser && NN_ECHOCLI && $options['Echo']); - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->binaries = ($options['Binaries'] instanceof Binaries ? $options['Binaries'] : new Binaries(['Settings' => $this->pdo, 'Echo' => $this->echoCLI])); $this->category = ($options['Categorize'] instanceof Categorize ? $options['Categorize'] : new Categorize(['Settings' => $this->pdo])); $this->nzb = ($options['NZB'] instanceof NZB ? $options['NZB'] : new NZB($this->pdo)); @@ -126,7 +127,7 @@ class NZBImport $this->releases = ($options['Releases'] instanceof Releases ? $options['Releases'] : new Releases(['settings' => $this->pdo])); $this->groups = new Groups(['Settings' => $this->pdo]); - $this->crossPostt = ($this->pdo->getSetting('crossposttime') != '') ? $this->pdo->getSetting('crossposttime') : 2; + $this->crossPostt = (Settings::value('..crossposttime') != '') ? Settings::value('..crossposttime') : 2; $this->browser = $options['Browser']; $this->retVal = ''; } diff --git a/nntmux/Nfo.php b/nntmux/Nfo.php index f44e2bdad..ab0c3763e 100755 --- a/nntmux/Nfo.php +++ b/nntmux/Nfo.php @@ -1,9 +1,10 @@ echo = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); - $this->nzbs = ($this->pdo->getSetting('maxnfoprocessed') != '') ? (int)$this->pdo->getSetting('maxnfoprocessed') : 100; - $this->maxsize = ($this->pdo->getSetting('maxsizetoprocessnfo') != '') ? (int)$this->pdo->getSetting('maxsizetoprocessnfo') : 100; + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->nzbs = (Settings::value('..maxnfoprocessed') != '') ? (int)Settings::value('..maxnfoprocessed') : 100; + $this->maxsize = (Settings::value('..maxsizetoprocessnfo') != '') ? (int)Settings::value('..maxsizetoprocessnfo') : 100; $this->maxsize = ($this->maxsize > 0 ? ('AND size < ' . ($this->maxsize * 1073741824)) : ''); - $this->minsize = ($this->pdo->getSetting('minsizetoprocessnfo') != '') ? (int)$this->pdo->getSetting('minsizetoprocessnfo') : 100; + $this->minsize = (Settings::value('..minsizetoprocessnfo') != '') ? (int)Settings::value('..minsizetoprocessnfo') : 100; $this->minsize = ($this->minsize > 0 ? ('AND size > ' . ($this->minsize * 1048576)) : ''); - $this->maxRetries = (int)($this->pdo->getSetting('maxnforetries') >= 0 ? -((int)$this->pdo->getSetting('maxnforetries') + 1) : self::NFO_UNPROC); + $this->maxRetries = (int)(Settings::value('..maxnforetries') >= 0 ? -((int)Settings::value('..maxnforetries') + 1) : self::NFO_UNPROC); $this->maxRetries = ($this->maxRetries < -8 ? -8 : $this->maxRetries); - $this->tmpPath = (string)$this->pdo->getSetting('tmpunrarpath'); + $this->tmpPath = (string)Settings::value('..tmpunrarpath'); if (!preg_match('/[\/\\\\]$/', $this->tmpPath)) { $this->tmpPath .= DS; } @@ -249,15 +250,15 @@ class Nfo */ static public function NfoQueryString(&$pdo) { - if ($pdo instanceof Settings) { - $maxSize = $pdo->getSetting('maxsizetoprocessnfo'); - $minSize = $pdo->getSetting('minsizetoprocessnfo'); - $maxRetries = (int)($pdo->getSetting('maxnforetries') >= 0 ? - -((int)$pdo->getSetting('maxnforetries') + 1) : self::NFO_UNPROC); + if ($pdo instanceof DB) { + $maxSize = Settings::value('..maxsizetoprocessnfo'); + $minSize = Settings::value('..minsizetoprocessnfo'); + $maxRetries = (int)(Settings::value('..maxnforetries') >= 0 ? + -((int)Settings::value('..maxnforetries') + 1) : self::NFO_UNPROC); } else { - $maxSize = \app\models\Settings::value('maxsizetoprocessnfo'); - $minSize = \app\models\Settings::value('minsizetoprocessnfo'); - $value = \app\models\Settings::value('maxnforetries'); + $maxSize = Settings::value('..maxsizetoprocessnfo'); + $minSize = Settings::value('..minsizetoprocessnfo'); + $value = Settings::value('..maxnforetries'); $maxRetries = (int)$value >= 0 ? -((int)$value + 1) : self::NFO_UNPROC; } return ( diff --git a/nntmux/ReleaseComments.php b/nntmux/ReleaseComments.php index 5014c1af5..011c85ec5 100755 --- a/nntmux/ReleaseComments.php +++ b/nntmux/ReleaseComments.php @@ -1,7 +1,8 @@ pdo = ($settings instanceof Settings ? $settings : new Settings()); + $this->pdo = ($settings instanceof DB ? $settings : new DB()); } /** @@ -164,7 +165,7 @@ class ReleaseComments */ public function addComment($id, $gid, $text, $userid, $host) { - if ($this->pdo->getSetting('storeuserips') != "1") { + if (Settings::value('..storeuserips') != "1") { $host = ""; } diff --git a/nntmux/ReleaseImage.php b/nntmux/ReleaseImage.php index 9339da0dc..7ab6af574 100755 --- a/nntmux/ReleaseImage.php +++ b/nntmux/ReleaseImage.php @@ -1,7 +1,7 @@ audSavePath = NN_COVERS . 'audiosample' . DS; // releases guid diff --git a/nntmux/Releases.php b/nntmux/Releases.php index f3f0c390a..81ad71338 100755 --- a/nntmux/Releases.php +++ b/nntmux/Releases.php @@ -1,7 +1,8 @@ pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->groups = ($options['Groups'] instanceof Groups ? $options['Groups'] : new Groups(['Settings' => $this->pdo])); - $this->updategrabs = ($this->pdo->getSetting('grabstatus') == '0' ? false : true); - $this->passwordStatus = ($this->pdo->getSetting('checkpasswordedrar') == 1 ? -1 : 0); + $this->updategrabs = (Settings::value('..grabstatus') == '0' ? false : true); + $this->passwordStatus = (Settings::value('..checkpasswordedrar') == 1 ? -1 : 0); $this->sphinxSearch = new SphinxSearch(); $this->releaseSearch = new ReleaseSearch($this->pdo, $this->sphinxSearch); $this->showPasswords = self::showPasswords($this->pdo); diff --git a/nntmux/RequestIDWeb.php b/nntmux/RequestIDWeb.php index 11754dbec..b4e889112 100755 --- a/nntmux/RequestIDWeb.php +++ b/nntmux/RequestIDWeb.php @@ -1,6 +1,7 @@ _request_hours = ($this->pdo->getSetting('request_hours') != '') ? (int)$this->pdo->getSetting('request_hours') : 1; + $this->_request_hours = (Settings::value('..request_hours') != '') ? (int)Settings::value('..request_hours') : 1; } /** @@ -152,7 +153,7 @@ class RequestIDWeb extends RequestID // Do a web lookup. $returnXml = Utility::getUrl([ - 'url' => $this->pdo->getSetting('request_url'), + 'url' => Settings::value('..request_url'), 'method' => 'post', 'postdata' => 'data=' . serialize($requestArray), 'verifycert' => false, @@ -186,9 +187,9 @@ class RequestIDWeb extends RequestID $this->_release['gid'] = $this->_release['groups_id']; $this->_release['fromname'] = $requestArray[(string)$result['ident']]['fromname']; - + $this->_release['searchname'] = $requestArray[(int)$result['ident']]['sname']; - + $this->_insertIntoPreDB(); if ($this->_preDbID === false) { $this->_preDbID = 0; @@ -319,4 +320,4 @@ class RequestIDWeb extends RequestID ); } } -} \ No newline at end of file +} diff --git a/nntmux/SABnzbd.php b/nntmux/SABnzbd.php index 1bb32e07e..72bafa444 100755 --- a/nntmux/SABnzbd.php +++ b/nntmux/SABnzbd.php @@ -92,7 +92,7 @@ class SABnzbd $this->serverurl = $page->serverurl; // Set up properties. - switch ($page->settings->getSetting('sabintegrationtype')) { + switch ($page->getSettingValue('..sabintegrationtype')) { case self::INTEGRATION_TYPE_USER: if (!empty($_COOKIE['sabnzbd_' . $this->uid . '__apikey']) && !empty($_COOKIE['sabnzbd_' . $this->uid . '__host'])) { $this->url = $_COOKIE['sabnzbd_' . $this->uid . '__host']; @@ -118,11 +118,11 @@ class SABnzbd break; case self::INTEGRATION_TYPE_SITEWIDE: - if (($page->settings->getSetting('sabapikey') != '') && ($page->settings->getSetting('saburl') != '')) { - $this->url = $page->settings->getSetting('saburl'); - $this->apikey = $page->settings->getSetting('sabapikey'); - $this->priority = $page->settings->getSetting('sabpriority'); - $this->apikeytype = $page->settings->getSetting('sabapikeytype'); + if (($page->getSettingValue('..sabapikey') != '') && ($page->getSettingValue('..saburl') != '')) { + $this->url = $page->getSettingValue('..saburl'); + $this->apikey = $page->getSettingValue('..sabapikey'); + $this->priority = $page->getSettingValue('..sabpriority'); + $this->apikeytype = $page->getSettingValue('..sabapikeytype'); } $this->integrated = self::INTEGRATION_TYPE_SITEWIDE; $this->integratedBool = true; diff --git a/nntmux/SpotNab.php b/nntmux/SpotNab.php index 0e3bfcdb2..1cdc321fe 100755 --- a/nntmux/SpotNab.php +++ b/nntmux/SpotNab.php @@ -2,7 +2,7 @@ namespace nntmux; -use nntmux\db\Settings; +use nntmux\db\DB; use app\extensions\util\Yenc; // Help out those who don't have SSL enabled @@ -135,7 +135,7 @@ class SpotNab { private $_discovery_lastarticle; public function __construct($post_user = NULL, $post_email = NULL, $post_group = NULL) { - $this->_pdo = new Settings(); + $this->_pdo = new DB(); $this->_nntp = new NNTP(['Settings' => $this->_pdo]); $this->releaseImage = new ReleaseImage($this->_pdo); $this->nzb = new NZB($this->_pdo); diff --git a/nntmux/Tmux.php b/nntmux/Tmux.php index bbc9df148..6a2b56700 100755 --- a/nntmux/Tmux.php +++ b/nntmux/Tmux.php @@ -1,7 +1,7 @@ pdo = (empty($pdo) ? new Settings() : $pdo); + $this->pdo = (empty($pdo) ? new DB() : $pdo); } /** diff --git a/nntmux/TmuxOutput.php b/nntmux/TmuxOutput.php index 841524ddc..321b6b52e 100755 --- a/nntmux/TmuxOutput.php +++ b/nntmux/TmuxOutput.php @@ -1,7 +1,7 @@ _dateFormat = '%Y-%m-%d %T'; diff --git a/nntmux/Users.php b/nntmux/Users.php index f2323cf38..bfe7a2e11 100755 --- a/nntmux/Users.php +++ b/nntmux/Users.php @@ -1,7 +1,8 @@ pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->password_hash_cost = (defined('NN_PASSWORD_HASH_COST') ? NN_PASSWORD_HASH_COST : 11); } @@ -376,7 +377,7 @@ class Users { $data = $this->pdo->query(sprintf("SELECT id,email FROM users WHERE role = %d AND rolechangedate < now()", $uprole)); foreach ($data as $u) { - Utility::sendEmail($u["email"], $msgsubject, $msgbody, $this->pdo->getSetting('email')); + Utility::sendEmail($u["email"], $msgsubject, $msgbody, Settings::value('..email')); $this->pdo->queryExec(sprintf("UPDATE users SET role = %d, rolechangedate=null WHERE id = %d", $downrole, $u["id"])); } @@ -550,7 +551,7 @@ class Users // Make sure this is the last check, as if a further validation check failed, the invite would still have been used up. $invitedBy = 0; - if (($this->pdo->getSetting('registerstatus') == Settings::REGISTER_STATUS_INVITE) && !$forceInviteMode) { + if ((Settings::value('..registerstatus') == Settings::REGISTER_STATUS_INVITE) && !$forceInviteMode) { if ($inviteCode == '') { return self::ERR_SIGNUP_BADINVITECODE; } @@ -642,7 +643,7 @@ class Users $this->pdo->escapeString((string)$password), $this->pdo->escapeString($email), $role, - $this->pdo->escapeString(($this->pdo->getSetting('storeuserips') == 1 ? $host : '')), + $this->pdo->escapeString((Settings::value('..storeuserips') == 1 ? $host : '')), $this->pdo->escapeString(uniqid()), $invites, ($invitedBy == 0 ? 'NULL' : $invitedBy), @@ -682,7 +683,7 @@ class Users { $_SESSION['uid'] = $userID; - if ($this->pdo->getSetting('storeuserips') != 1) { + if (Settings::value('..storeuserips') != 1) { $host = ''; } @@ -929,11 +930,11 @@ class Users { $ipsql = "('-1')"; - if ($this->pdo->getSetting('userhostexclusion') != '') { + if (Settings::value('userhostexclusion') != '') { $ipsql = ""; - $ips = explode(",", $this->pdo->getSetting('userhostexclusion')); + $ips = explode(",", Settings::value('..userhostexclusion')); foreach ($ips as $ip) { - $ipsql .= $this->pdo->escapeString($this->getHostHash($ip, $this->pdo->getSetting('siteseed'))) . ","; + $ipsql .= $this->pdo->escapeString($this->getHostHash($ip, Settings::value('..siteseed'))) . ","; } $ipsql = "(" . $ipsql . " '-1')"; } @@ -957,7 +958,7 @@ class Users public function getHostHash($host, $siteseed = "") { if ($siteseed == "") { - $siteseed = $this->pdo->getSetting('siteseed'); + $siteseed = Settings::value('..siteseed'); } return self::hashSHA1($siteseed . $host . $siteseed); diff --git a/nntmux/XXX.php b/nntmux/XXX.php index a68336271..3625b784e 100755 --- a/nntmux/XXX.php +++ b/nntmux/XXX.php @@ -1,7 +1,8 @@ pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->releaseImage = ($options['ReleaseImage'] instanceof ReleaseImage ? $options['ReleaseImage'] : new ReleaseImage($this->pdo)); - $this->movieqty = ($this->pdo->getSetting('maxxxxprocessed') != '') ? $this->pdo->getSetting('maxxxxprocessed') : 100; + $this->movieqty = (Settings::value('..maxxxxprocessed') != '') ? Settings::value('..maxxxxprocessed') : 100; $this->showPasswords = Releases::showPasswords($this->pdo); $this->debug = NN_DEBUG; $this->echooutput = ($options['Echo'] && NN_ECHOCLI); diff --git a/nntmux/db/DB.php b/nntmux/db/DB.php index 0b0c69cb9..a57de3712 100755 --- a/nntmux/db/DB.php +++ b/nntmux/db/DB.php @@ -1,19 +1,20 @@ false, // create dbname if it does not exist? 'ct' => new ConsoleTools(), 'dbhost' => defined('DB_HOST') ? DB_HOST : '', - 'dbname' => defined('DB_NAME') ? DB_NAME : '', - 'dbpass' => defined('DB_PASSWORD') ? DB_PASSWORD : '', + 'dbname' => defined('DB_NAME') ? DB_NAME : '', + 'dbpass' => defined('DB_PASSWORD') ? DB_PASSWORD : '', 'dbport' => defined('DB_PORT') ? DB_PORT : '', 'dbsock' => defined('DB_SOCKET') ? DB_SOCKET : '', 'dbtype' => defined('DB_SYSTEM') ? DB_SYSTEM : '', - 'dbuser' => defined('DB_USER') ? DB_USER : '', + 'dbuser' => defined('DB_USER') ? DB_USER : '', 'log' => new ColorCLI(), 'persist' => false, ]; @@ -180,7 +181,14 @@ class DB extends \PDO $this->pdo = null; } - public function checkDbExists ($name = null) + public function __get($name) + { + $result = $this->queryOneRow("SELECT value FROM settings WHERE setting = '$name' LIMIT 1"); + + return is_array($result) ? $result['value'] : $result; + } + + public function checkDbExists($name = null) { if (empty($name)) { $name = $this->opts['dbname']; @@ -253,7 +261,46 @@ class DB extends \PDO } } - public function getTableList () + public function getSetting($name) + { + $result = $this->queryOneRow("SELECT value FROM settings WHERE setting = '$name' LIMIT 1"); + return is_array($result) ? $result['value'] : $result; + } + + /** + * Return a tree-like array of all or selected settings. + * + * @param array $options Options array for Settings::find() i.e. ['conditions' => ...]. + * @param bool $excludeUnsectioned If rows with empty 'section' field should be excluded. + * Note this doesn't prevent empty 'subsection' fields. + * + * @return array + * @throws \RuntimeException + */ + public function getSettingsAsTree($excludeUnsectioned = true) + { + $where = $excludeUnsectioned ? "WHERE section != ''" : ''; + + $sql = sprintf("SELECT section, subsection, name, value, hint FROM settings %s ORDER BY section, subsection, name", + $where); + $results = $this->queryArray($sql); + + $tree = []; + if (is_array($results)) { + foreach ($results as $result) { + if (!empty($result['section']) || !$excludeUnsectioned) { + $tree[$result['section']][$result['subsection']][$result['name']] = + ['value' => $result['value'], 'hint' => $result['hint']]; + } + } + } else { + echo "NO results!!\n"; + } + + return $tree; + } + + public function getTableList() { $query = ($this->opts['dbtype'] === 'mysql' ? 'SHOW DATABASES' : 'SELECT datname AS Database FROM pg_database'); $result = $this->pdo->query($query); @@ -412,20 +459,13 @@ class DB extends \PDO * * @return string */ - public function likeString($str, $left=true, $right=true) + public function likeString($str, $left = true, $right = true) { - return ( - 'LIKE ' . - $this->escapeString( - ($left ? '%' : '') . - $str . - ($right ? '%' : '') - ) - ); + return ('LIKE ' . $this->escapeString(($left ? '%' : '') . $str . ($right ? '%' : ''))); } /** - * Verify if pdo var is instance of \PDO class. + * Verify if pdo var is instance of PDO class. * * @return bool */ @@ -435,31 +475,30 @@ class DB extends \PDO } /** - * For inserting a row. Returns last insert id. queryExec is better if you do not need the id. + * For inserting a row. Returns last insert ID. queryExec is better if you do not need the id. * * @param string $query * - * @return bool|int + * @return integer|false|string */ public function queryInsert($query) { - if (empty($query)) { + if (!$this->parseQuery($query)) { return false; } - if (NN_QUERY_STRIP_WHITESPACE) { - $query = Utility::collapseWhiteSpace($query); - } - $i = 2; $error = ''; - while($i < 11) { + while ($i < 11) { $result = $this->queryExecHelper($query, true); if (is_array($result) && isset($result['deadlock'])) { $error = $result['message']; if ($result['deadlock'] === true) { - $this->echoError("A Deadlock or lock wait timeout has occurred, sleeping.(" . ($i-1) . ")", 'queryInsert', 4); - $this->ct->showsleep($i * ($i/2)); + $this->echoError("A Deadlock or lock wait timeout has occurred, sleeping. (" . + ($i - 1) . ")", + 'queryInsert', + 4); + $this->ct->showsleep($i * ($i / 2)); $i++; } else { break; @@ -478,6 +517,23 @@ class DB extends \PDO return false; } + /** + * Delete rows from MySQL. + * + * @param string $query + * @param bool $silent Echo or log errors? + * + * @return bool|\PDOStatement + */ + public function queryDelete($query, $silent = false) + { + // Accommodate for chained queries (SELECT 1;DELETE x FROM y) + if (preg_match('#(.*?[^a-z0-9]|^)DELETE\s+(.+?)$#is', $query, $matches)) { + $query = $matches[1] . 'DELETE ' . $this->DELETE_LOW_PRIORITY . $this->DELETE_QUICK . $matches[2]; + } + return $this->queryExec($query, $silent); + } + /** * Used for deleting, updating (and inserting without needing the last insert id). * @@ -488,23 +544,19 @@ class DB extends \PDO */ public function queryExec($query, $silent = false) { - if (empty($query)) { + if (!$this->parseQuery($query)) { return false; } - if (NN_QUERY_STRIP_WHITESPACE) { - $query = Utility::collapseWhiteSpace($query); - } - $i = 2; $error = ''; - while($i < 11) { + while ($i < 11) { $result = $this->queryExecHelper($query); if (is_array($result) && isset($result['deadlock'])) { $error = $result['message']; if ($result['deadlock'] === true) { - $this->echoError("A Deadlock or lock wait timeout has occurred, sleeping.(" . ($i-1) . ")", 'queryExec', 4); - $this->ct->showsleep($i * ($i/2)); + $this->echoError("A Deadlock or lock wait timeout has occurred, sleeping. (" . ($i - 1) . ")", 'queryExec', 4); + $this->ct->showsleep($i * ($i / 2)); $i++; } else { break; @@ -534,7 +586,7 @@ class DB extends \PDO protected function queryExecHelper($query, $insert = false) { try { - if ($insert === false ) { + if ($insert === false) { $run = $this->pdo->prepare($query); $run->execute(); return $run; @@ -577,7 +629,7 @@ class DB extends \PDO * @note If not "consumed", causes this error: * 'SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. * Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, - * you may enable query buffering by setting the \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.' + * you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.' * * @param string $query * @param bool $silent Whether to skip echoing errors to the console. @@ -586,14 +638,10 @@ class DB extends \PDO */ public function exec($query, $silent = false) { - if (empty($query)) { + if (!$this->parseQuery($query)) { return false; } - if (NN_QUERY_STRIP_WHITESPACE) { - $query = Utility::collapseWhiteSpace($query); - } - try { return $this->pdo->exec($query); @@ -637,14 +685,10 @@ class DB extends \PDO */ public function query($query, $cache = false, $cacheExpiry = 600) { - if (empty($query)) { + if (!$this->parseQuery($query)) { return false; } - if (NN_QUERY_STRIP_WHITESPACE) { - $query = Utility::collapseWhiteSpace($query); - } - if ($cache === true && $this->cacheEnabled === true) { try { $data = $this->cacheServer->get($this->cacheServer->createKey($query)); @@ -687,7 +731,7 @@ class DB extends \PDO // Remove LIMIT and OFFSET from query to allow queryCalc usage with browse $query = preg_replace('#(\s+LIMIT\s+\d+)?\s+OFFSET\s+\d+\s*$#i', '', $query); - if ($cache === true && $this->cacheEnabled === true ) { + if ($cache === true && $this->cacheEnabled === true) { try { $count = $this->cacheServer->get($this->cacheServer->createKey($query . 'count')); if ($count !== false) { @@ -705,10 +749,10 @@ class DB extends \PDO } return - [ - 'total' => ($result === false ? 0 : $result['total']), - 'result' => $data - ]; + [ + 'total' => ($result === false ? 0 : $result['total']), + 'result' => $data + ]; } /** @@ -755,33 +799,11 @@ class DB extends \PDO $result = $this->queryArray($query); if ($mode != \PDO::FETCH_ASSOC) { - $this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC); + $this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, $mode); // Restore old mode } return $result; } - /** - * Fetch a assoc row from a result set - * - * @param $result - * @return array|\PDOStatement - */ - public function getAssocArray($result) - { - return $result->fetch(\PDO::FETCH_ASSOC); - } - - /** - * Get the total number of rows in the result set - * - * @param $result - * @return int|\PDOStatement - */ - public function getNumRows($result) - { - return $result->rowCount(); - } - /** * Query without returning an empty array like our function query(). http://php.net/manual/en/pdo.query.php * @@ -792,14 +814,10 @@ class DB extends \PDO */ public function queryDirect($query, $ignore = false) { - if (empty($query)) { + if (!$this->parseQuery($query)) { return false; } - if (NN_QUERY_STRIP_WHITESPACE) { - $query = Utility::collapseWhiteSpace($query); - } - try { $result = $this->pdo->query($query); } catch (\PDOException $e) { @@ -878,9 +896,10 @@ class DB extends \PDO // Force the query to only return 1 row, so queryArray doesn't potentially run out of memory on a large data set. // First check if query already contains a LIMIT clause. if (preg_match('#\s+LIMIT\s+(?P\d+)(,\s+(?P\d+))?(;)?$#i', $query, $matches)) { - If (!isset($matches['upper']) && isset($matches['lower']) && $matches['lower'] == 1) { + if (!isset($matches['upper']) && isset($matches['lower']) && $matches['lower'] == 1) { // good it's already correctly set. - } else { // We have a limit, but it's not for a single row + } else { + // We have a limit, but it's not for a single row return false; } @@ -915,7 +934,7 @@ class DB extends \PDO foreach ($tableList as $tableName) { $tableAnd .= ($this->escapeString($tableName) . ','); } - $tableAnd = (' AND name IN (' . rtrim($tableAnd, ',') . ')'); + $tableAnd = (' AND Name IN (' . rtrim($tableAnd, ',') . ')'); } switch ($type) { @@ -967,18 +986,6 @@ class DB extends \PDO return $optimised; } - /** - * Get the amount of found rows after running a SELECT SQL_CALC_FOUND_ROWS query. - * - * @return int - * @access public - */ - public function get_Found_Rows() - { - $totalCount = $this->queryOneRow('SELECT FOUND_ROWS() AS total'); - return ($totalCount === false ? 0 : $totalCount['total']); - } - /** * Log/echo repaired/optimized/analyzed tables. * @@ -1040,6 +1047,109 @@ class DB extends \PDO return true; } + public function setCovers() + { + $path = Settings::value([ + 'section' => 'site', + 'subsection' => 'main', + 'name' => 'coverspath', + 'setting' => 'coverspath', + ]); + Utility::setCoversConstant($path); + } + + public function rowToArray(array $row) + { + $this->settings[$row['setting']] = $row['value']; + } + + public function rowsToArray(array $rows) + { + foreach ($rows as $row) { + if (is_array($row)) { + $this->rowToArray($row); + } + } + + return $this->settings; + } + + public function settingsUpdate($form) + { + $error = $this->settingsValidate($form); + + if ($error === null) { + $sql = $sqlKeys = []; + foreach ($form as $settingK => $settingV) { + $sql[] = sprintf("WHEN %s THEN %s", + $this->escapeString($settingK), + $this->escapeString($settingV)); + $sqlKeys[] = $this->escapeString($settingK); + } + + $this->queryExec( + sprintf("UPDATE settings SET value = CASE setting %s END WHERE setting IN (%s)", + implode(' ', $sql), + implode(', ', $sqlKeys) + ) + ); + } else { + $form = $error; + } + + return $form; + } + + protected function settingsValidate(array $fields) + { + $defaults = [ + 'checkpasswordedrar' => false, + 'ffmpegpath' => '', + 'mediainfopath' => '', + 'nzbpath' => '', + 'tmpunrarpath' => '', + 'unrarpath' => '', + 'yydecoderpath' => '', + ]; + $fields += $defaults; // Make sure keys exist to avoid error notices. + ksort($fields); + // Validate settings + $fields['nzbpath'] = Utility::trailingSlash($fields['nzbpath']); + $error = null; + switch (true) { + case ($fields['mediainfopath'] != '' && !is_file($fields['mediainfopath'])): + $error = Settings::ERR_BADMEDIAINFOPATH; + break; + case ($fields['ffmpegpath'] != '' && !is_file($fields['ffmpegpath'])): + $error = Settings::ERR_BADFFMPEGPATH; + break; + case ($fields['unrarpath'] != '' && !is_file($fields['unrarpath'])): + $error = Settings::ERR_BADUNRARPATH; + break; + case (empty($fields['nzbpath'])): + $error = Settings::ERR_BADNZBPATH_UNSET; + break; + case (!file_exists($fields['nzbpath']) || !is_dir($fields['nzbpath'])): + $error = Settings::ERR_BADNZBPATH; + break; + case (!is_readable($fields['nzbpath'])): + $error = Settings::ERR_BADNZBPATH_UNREADABLE; + break; + case ($fields['checkpasswordedrar'] == 1 && !is_file($fields['unrarpath'])): + $error = Settings::ERR_DEEPNOUNRAR; + break; + case ($fields['tmpunrarpath'] != '' && !file_exists($fields['tmpunrarpath'])): + $error = Settings::ERR_BADTMPUNRARPATH; + break; + case ($fields['yydecoderpath'] != '' && + $fields['yydecoderpath'] !== 'simple_php_yenc_decode' && + !file_exists($fields['yydecoderpath'])): + $error = Settings::ERR_BAD_YYDECODER_PATH; + } + + return $error; + } + /** * PHP interpretation of MySQL's from_unixtime method. * @param int $utime UnixTime @@ -1099,7 +1209,7 @@ class DB extends \PDO /** * Checks whether the connection to the server is working. Optionally restart a new connection. - * NOTE: Restart does not happen if \PDO is not using exceptions (PHP's default configuration). + * NOTE: Restart does not happen if PDO is not using exceptions (PHP's default configuration). * In this case check the return value === false. * * @param boolean $restart Whether an attempt should be made to reinitialise the Db object on failure. @@ -1109,7 +1219,7 @@ class DB extends \PDO public function ping($restart = false) { try { - return (bool) $this->pdo->query('SELECT 1+1'); + return (bool)$this->pdo->query('SELECT 1+1'); } catch (\PDOException $e) { if ($restart == true) { $this->initialiseDatabase(); @@ -1150,7 +1260,7 @@ class DB extends \PDO * * @param int $attribute * - * @return bool|mixed + * @return false|mixed */ public function getAttribute($attribute) { @@ -1175,7 +1285,7 @@ class DB extends \PDO * * @return string */ - public function getDbVersion () + public function getDbVersion() { return $this->dbVersion; } @@ -1186,7 +1296,7 @@ class DB extends \PDO * @return bool|null TRUE if Db version is greater than or eaqual to $requiredVersion, * false if not, and null if the version isn't available to check against. */ - public function isDbVersionAtLeast ($requiredVersion) + public function isDbVersionAtLeast($requiredVersion) { if (empty($this->dbVersion)) { return null; @@ -1197,7 +1307,7 @@ class DB extends \PDO /** * Performs the fetch from the Db server and stores the resulting Major.Minor.Version number. */ - private function fetchDbVersion () + private function fetchDbVersion() { $result = $this->queryOneRow("SELECT VERSION() AS version"); if (!empty($result)) { @@ -1205,4 +1315,24 @@ class DB extends \PDO $this->dbVersion = $dummy[0]; } } + + /** + * Checks if the query is empty. Cleans the query of whitespace if needed. + * + * @param string $query + * + * @return boolean + */ + private function parseQuery(&$query) + { + if (empty($query)) { + return false; + } + + if (NN_QUERY_STRIP_WHITESPACE) { + $query = Utility::collapseWhiteSpace($query); + } + return true; + } + } diff --git a/nntmux/db/DbUpdate.php b/nntmux/db/DbUpdate.php index 69e5e2d40..99a34de3d 100755 --- a/nntmux/db/DbUpdate.php +++ b/nntmux/db/DbUpdate.php @@ -20,8 +20,9 @@ */ namespace nntmux\db; +use app\models\Settings; use nntmux\ColorCLI; -use nntmux\db\Settings; +use nntmux\db\DB; use nntmux\utility\Git; use nntmux\utility\Utility; @@ -81,7 +82,7 @@ class DbUpdate $this->settings &= $this->pdo; } - $this->_DbSystem = strtolower($this->pdo->dbSystem()); + $this->_DbSystem = strtolower($this->pdo->DbSystem()); } public function loadTables(array $options = []) @@ -161,8 +162,6 @@ class DbUpdate ]; $options += $defaults; - $this->initSettings(); - $this->processPatches(['safe' => $options['safe']]); // Make sure we are completely up to date! echo $this->log->primaryOver('Looking for new patches...'); @@ -209,8 +208,6 @@ class DbUpdate ]; $options += $defaults; - $this->initSettings(); - $currentVersion = $this->settings->getSetting(['setting' => 'sqlpatch']); if (!is_numeric($currentVersion)) { exit("Bad sqlpatch value: '$currentVersion'\n"); @@ -454,13 +451,6 @@ class DbUpdate 'dump_tables.php db dump'); $this->backedup = true; } - - protected function initSettings() - { - if (!($this->settings instanceof Settings)) { - $this->settings = new Settings(); - } - } } ?> diff --git a/nntmux/db/Settings.php b/nntmux/db/Settings.php index 1a06dbc0d..e2112bb9c 100755 --- a/nntmux/db/Settings.php +++ b/nntmux/db/Settings.php @@ -341,5 +341,5 @@ class Settings extends DB * This is a temporary measure until a proper frontend for cli stuff can be implemented with li3. */ if (Utility::isCLI() && isset($argv[1])) { - echo (new Settings())->getSetting($argv[1]); + echo (new DB())->getSetting($argv[1]); } diff --git a/nntmux/db/populate/AniDB.php b/nntmux/db/populate/AniDB.php index e149cdf2f..0553bf497 100755 --- a/nntmux/db/populate/AniDB.php +++ b/nntmux/db/populate/AniDB.php @@ -2,9 +2,9 @@ namespace nntmux\db\populate; +use app\models\Settings; use nntmux\ReleaseImage; -use nntmux\db\Settings; -use nntmux\utility\Utility; +use nntmux\db\DB; class AniDB { @@ -69,13 +69,13 @@ class AniDB $options += $defaults; $this->echooutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); - $anidbupdint = $this->pdo->getSetting('intanidbupdate'); - $lastupdated = $this->pdo->getSetting('lastanidbupdate'); + $anidbupdint = Settings::value('..intanidbupdate'); + $lastupdated = Settings::value('..lastanidbupdate'); $this->imgSavePath = NN_COVERS . 'anime' . DS; - $this->apiKey = $this->pdo->getSetting('anidbkey'); + $this->apiKey = Settings::value('..anidbkey'); $this->updateInterval = (isset($anidbupdint) ? $anidbupdint : '7'); $this->lastUpdate = (isset($lastupdated) ? $lastupdated : '0'); @@ -136,7 +136,7 @@ class AniDB */ private function getAniDbAPI() { - $timestamp = $this->pdo->getSetting('APIs.AniDB.banned') + 90000; + $timestamp = Settings::value('APIs.AniDB.banned') + 90000; if ($timestamp > time()) { echo "Banned from AniDB lookups until " . date('Y-m-d H:i:s', $timestamp) . "\n"; return false; diff --git a/nntmux/http/Capabilities.php b/nntmux/http/Capabilities.php index cbbf50d71..87387e5d0 100755 --- a/nntmux/http/Capabilities.php +++ b/nntmux/http/Capabilities.php @@ -21,8 +21,9 @@ namespace nntmux\http; use app\extensions\util\Versions; +use app\models\Settings; use nntmux\Category; -use nntmux\db\Settings; +use nntmux\db\DB; use nntmux\utility\Utility; /** @@ -54,7 +55,7 @@ abstract class Capabilities 'Settings' => null, ]; $options += $defaults; - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); } /** @@ -132,10 +133,10 @@ abstract class Capabilities 'server' => [ 'appversion' => (new Versions())->getGitTagInRepo(), 'version' => '0.1', - 'title' => $this->pdo->getSetting('title'), - 'strapline' => $this->pdo->getSetting('strapline'), - 'email' => $this->pdo->getSetting('email'), - 'meta' => $this->pdo->getSetting('metakeywords'), + 'title' => Settings::value('..title'), + 'strapline' => Settings::value('..strapline'), + 'email' => Settings::value('..email'), + 'meta' => Settings::value('..metakeywords'), 'url' => $serverroot, 'image' => $serverroot . 'themes/shared/images/logo.png' ], @@ -145,7 +146,7 @@ abstract class Capabilities ], 'registration' => [ 'available' => 'yes', - 'open' => $this->pdo->getSetting('registerstatus') == 0 ? 'yes' : 'no' + 'open' => Settings::value('..registerstatus') == 0 ? 'yes' : 'no' ], 'searching' => [ 'search' => ['available' => 'yes', 'supportedParams' => 'q'], diff --git a/nntmux/libraries/Forking.php b/nntmux/libraries/Forking.php index 89db44530..4045e759b 100755 --- a/nntmux/libraries/Forking.php +++ b/nntmux/libraries/Forking.php @@ -290,7 +290,7 @@ class Forking extends \fork_daemon ($this->workTypeOptions[0] === false ? '' : (', ' . $this->workTypeOptions[0] . ' AS max')) ) ); - return Settings::value('backfillthreads'); + return Settings::value('..backfillthreads'); } public function backFillChildWorker($groups, $identifier = '') @@ -311,7 +311,7 @@ class Forking extends \fork_daemon $this->register_child_run([0 => $this, 1 => 'safeBackfillChildWorker']); $run = $this->pdo->query("SELECT (SELECT value FROM tmux WHERE setting = 'backfill_qty') AS qty, (SELECT value FROM tmux WHERE setting = 'backfill') AS backfill, (SELECT value FROM tmux WHERE setting = 'backfill_order') AS orderby, (SELECT value FROM tmux WHERE setting = 'backfill_days') AS days, (SELECT value FROM settings WHERE setting = 'maxmssgs') AS maxmsgs"); - $threads = Settings::value('backfillthreads'); + $threads = Settings::value('..backfillthreads'); $orderby = "ORDER BY a.last_record ASC"; switch ((int)$run[0]['orderby']) { @@ -340,7 +340,7 @@ class Forking extends \fork_daemon if ($run[0]['days'] == 1) { $backfilldays = "backfill_target"; } elseif ($run[0]['days'] == 2) { - $backfilldays = round(abs(strtotime(date("Y-m-d")) - strtotime(Settings::value('safebackfilldate'))) / 86400); + $backfilldays = round(abs(strtotime(date("Y-m-d")) - strtotime(Settings::value('..safebackfilldate'))) / 86400); } $data = $this->pdo->queryOneRow( @@ -409,7 +409,7 @@ class Forking extends \fork_daemon $this->workTypeOptions[0] ) ); - return Settings::value('binarythreads'); + return Settings::value('..binarythreads'); } public function binariesChildWorker($groups, $identifier = '') @@ -429,8 +429,8 @@ class Forking extends \fork_daemon $this->register_child_run([0 => $this, 1 => 'safeBinariesChildWorker']); $maxheaders = Settings::value('max.headers.iteration') ?: 1000000; - $maxmssgs = Settings::value('maxmssgs'); - $threads = Settings::value('binarythreads'); + $maxmssgs = Settings::value('..maxmssgs'); + $threads = Settings::value('..binarythreads'); $groups = $this->pdo->query(" SELECT g.name AS groupname, g.last_record AS our_last, @@ -495,8 +495,8 @@ class Forking extends \fork_daemon { $this->register_child_run([0 => $this, 1 => 'fixRelNamesChildWorker']); - $threads = Settings::value('fixnamethreads'); - $maxperrun = Settings::value('fixnamesperrun'); + $threads = Settings::value('..fixnamethreads'); + $maxperrun = Settings::value('..fixnamesperrun'); if ($threads > 16) { $threads = 16; @@ -556,7 +556,7 @@ class Forking extends \fork_daemon { $this->register_child_run([0 => $this, 1 => 'releasesChildWorker']); - $this->tablePerGroup = (Settings::value('tablepergroup') == 1 ? true : false); + $this->tablePerGroup = (Settings::value('..tablepergroup') == 1 ? true : false); if ($this->tablePerGroup === true) { $groups = $this->pdo->queryDirect('SELECT id FROM groups WHERE (active = 1 OR backfill = 1)'); @@ -572,7 +572,7 @@ class Forking extends \fork_daemon $this->work = $this->pdo->query('SELECT name FROM groups WHERE (active = 1 OR backfill = 1)'); } - return Settings::value('releasethreads'); + return Settings::value('..releasethreads'); } public function releasesChildWorker($groups, $identifier = '') @@ -630,10 +630,10 @@ class Forking extends \fork_daemon private function checkProcessAdditional() { $this->ppAddMinSize = - (Settings::value('minsizetopostprocess') != '') ? (int)Settings::value('minsizetopostprocess') : 1; + (Settings::value('..minsizetopostprocess') != '') ? (int)Settings::value('..minsizetopostprocess') : 1; $this->ppAddMinSize = ($this->ppAddMinSize > 0 ? ('AND r.size > ' . ($this->ppAddMinSize * 1048576)) : ''); $this->ppAddMaxSize = - (Settings::value('maxsizetopostprocess') != '') ? (int)Settings::value('maxsizetopostprocess') : 100; + (Settings::value('..maxsizetopostprocess') != '') ? (int)Settings::value('..maxsizetopostprocess') : 100; $this->ppAddMaxSize = ($this->ppAddMaxSize > 0 ? ('AND r.size < ' . ($this->ppAddMaxSize * 1073741824)) : ''); return ( $this->pdo->queryOneRow( @@ -678,7 +678,7 @@ class Forking extends \fork_daemon $this->ppAddMinSize ) ); - $maxProcesses = Settings::value('postthreads'); + $maxProcesses = Settings::value('..postthreads'); } return $maxProcesses; } @@ -691,7 +691,7 @@ class Forking extends \fork_daemon */ private function checkProcessNfo() { - if (Settings::value('lookupnfo') == 1) { + if (Settings::value('..lookupnfo') == 1) { $this->nfoQueryString = Nfo::NfoQueryString($this->pdo); return ( $this->pdo->queryOneRow( @@ -721,7 +721,7 @@ class Forking extends \fork_daemon $this->nfoQueryString ) ); - $maxProcesses = Settings::value('nfothreads'); + $maxProcesses = Settings::value('..nfothreads'); } return $maxProcesses; } @@ -732,7 +732,7 @@ class Forking extends \fork_daemon */ private function checkProcessMovies() { - if (Settings::value('lookupimdb') > 0) { + if (Settings::value('..lookupimdb') > 0) { return ( $this->pdo->queryOneRow( sprintf(' @@ -746,7 +746,7 @@ class Forking extends \fork_daemon NZB::NZB_ADDED, Category::MOVIE_ROOT, Category::MOVIE_OTHER, - (Settings::value('lookupimdb') == 2 ? 'AND isrenamed = 1' : ''), + (Settings::value('..lookupimdb') == 2 ? 'AND isrenamed = 1' : ''), ($this->ppRenamedOnly ? 'AND isrenamed = 1' : '') ) ) === false ? false : true @@ -773,11 +773,11 @@ class Forking extends \fork_daemon LIMIT 16', ($this->ppRenamedOnly ? 2 : 1), NZB::NZB_ADDED, - (Settings::value('lookupimdb') == 2 ? 'AND isrenamed = 1' : ''), + (Settings::value('..lookupimdb') == 2 ? 'AND isrenamed = 1' : ''), ($this->ppRenamedOnly ? 'AND isrenamed = 1' : '') ) ); - $maxProcesses = Settings::value('postthreadsnon'); + $maxProcesses = Settings::value('..postthreadsnon'); } return $maxProcesses; } @@ -788,7 +788,7 @@ class Forking extends \fork_daemon */ private function checkProcessTV() { - if (Settings::value('lookuptvrage') > 0) { + if (Settings::value('..lookuptvrage') > 0) { return ( $this->pdo->queryOneRow( sprintf(' @@ -803,7 +803,7 @@ class Forking extends \fork_daemon NZB::NZB_ADDED, Category::TV_ROOT, Category::TV_OTHER, - (Settings::value('lookuptvrage') == 2 ? 'AND isrenamed = 1' : ''), + (Settings::value('..lookuptvrage') == 2 ? 'AND isrenamed = 1' : ''), ($this->ppRenamedOnly ? 'AND isrenamed = 1' : '') ) ) === false ? false : true @@ -833,11 +833,11 @@ class Forking extends \fork_daemon NZB::NZB_ADDED, Category::TV_ROOT, Category::TV_OTHER, - (Settings::value('lookuptvrage') == 2 ? 'AND isrenamed = 1' : ''), + (Settings::value('..lookuptvrage') == 2 ? 'AND isrenamed = 1' : ''), ($this->ppRenamedOnly ? 'AND isrenamed = 1' : '') ) ); - $maxProcesses = Settings::value('postthreadsnon'); + $maxProcesses = Settings::value('..postthreadsnon'); } return $maxProcesses; } @@ -852,7 +852,7 @@ class Forking extends \fork_daemon $sharing = $this->pdo->queryOneRow('SELECT enabled FROM sharing'); if ($sharing !== false && $sharing['enabled'] == 1) { $nntp = new NNTP(['Settings' => $this->pdo]); - if ((Settings::value('alternate_nntp') == 1 ? $nntp->doConnect(true, true) : $nntp->doConnect()) === true) { + if ((Settings::value('..alternate_nntp') == 1 ? $nntp->doConnect(true, true) : $nntp->doConnect()) === true) { (new PostProcess(['Settings' => $this->pdo, 'ColorCLI' => $this->_colorCLI]))->processSharing($nntp); } return true; @@ -895,7 +895,7 @@ class Forking extends \fork_daemon RequestID::REQID_UPROC ) ); - return Settings::value('reqidthreads'); + return Settings::value('..reqidthreads'); } public function requestIDChildWorker($groups, $identifier = '') @@ -913,7 +913,7 @@ class Forking extends \fork_daemon { $this->register_child_run([0 => $this, 1 => 'updatePerGroupChildWorker']); $this->work = $this->pdo->query('SELECT id FROM groups WHERE (active = 1 OR backfill = 1)'); - return Settings::value('releasethreads'); + return Settings::value('..releasethreads'); } public function updatePerGroupChildWorker($groups, $identifier = '') diff --git a/nntmux/processing/PostProcess.php b/nntmux/processing/PostProcess.php index a1404815f..686612fb4 100755 --- a/nntmux/processing/PostProcess.php +++ b/nntmux/processing/PostProcess.php @@ -1,6 +1,7 @@ echooutput = ($options['Echo'] && NN_ECHOCLI); // Class instances. - $this->pdo = (($options['Settings'] instanceof Settings) ? $options['Settings'] : new Settings()); + $this->pdo = (($options['Settings'] instanceof DB) ? $options['Settings'] : new DB()); $this->groups = (($options['Groups'] instanceof Groups) ? $options['Groups'] : new Groups(['Settings' => $this->pdo])); $this->_par2Info = new Par2Info(); $this->debugging = ($options['Logger'] instanceof Logger ? $options['Logger'] : new Logger(['ColorCLI' => $this->pdo->log])); @@ -118,8 +119,8 @@ class PostProcess $this->releaseFiles = (($options['ReleaseFiles'] instanceof ReleaseFiles) ? $options['ReleaseFiles'] : new ReleaseFiles($this->pdo)); // Site settings. - $this->addpar2 = ($this->pdo->getSetting('addpar2') == 0) ? false : true; - $this->alternateNNTP = ($this->pdo->getSetting('alternate_nntp') == 1 ? true : false); + $this->addpar2 = (Settings::value('..addpar2') == 0) ? false : true; + $this->alternateNNTP = (Settings::value('..alternate_nntp') == 1 ? true : false); } /** @@ -152,7 +153,7 @@ class PostProcess */ public function processAnime() { - if ($this->pdo->getSetting('lookupanidb') != 0) { + if (Settings::value('..lookupanidb') != 0) { (new AniDB(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processAnimeReleases(); } } @@ -164,7 +165,7 @@ class PostProcess */ public function processBooks() { - if ($this->pdo->getSetting('lookupbooks') != 0) { + if (Settings::value('..lookupbooks') != 0) { (new Books(['Echo' => $this->echooutput, 'Settings' => $this->pdo, ]))->processBookReleases(); } } @@ -176,7 +177,7 @@ class PostProcess */ public function processConsoles() { - if ($this->pdo->getSetting('lookupgames') != 0) { + if (Settings::value('..lookupgames') != 0) { (new Console(['Settings' => $this->pdo, 'Echo' => $this->echooutput]))->processConsoleReleases(); } } @@ -188,7 +189,7 @@ class PostProcess */ public function processGames() { - if ($this->pdo->getSetting('lookupgames') != 0) { + if (Settings::value('..lookupgames') != 0) { (new Games(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processGamesReleases(); } } @@ -205,7 +206,7 @@ class PostProcess */ public function processMovies($groupID = '', $guidChar = '', $processMovies = '') { - $processMovies = (is_numeric($processMovies) ? $processMovies : $this->pdo->getSetting('lookupimdb')); + $processMovies = (is_numeric($processMovies) ? $processMovies : Settings::value('..lookupimdb')); if ($processMovies > 0) { (new Movie(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processMovieReleases($groupID, $guidChar, $processMovies); } @@ -218,7 +219,7 @@ class PostProcess */ public function processMusic() { - if ($this->pdo->getSetting('lookupmusic') != 0) { + if (Settings::value('..lookupmusic') != 0) { (new Music(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processMusicReleases(); } } @@ -234,8 +235,8 @@ class PostProcess */ public function processNfos(&$nntp, $groupID = '', $guidChar = '') { - if ($this->pdo->getSetting('lookupnfo') == 1) { - $this->Nfo->processNfoFiles($nntp, $groupID, $guidChar, (int)$this->pdo->getSetting('lookupimdb'), (int)$this->pdo->getSetting('lookuptvrage')); + if (Settings::value('..lookupnfo') == 1) { + $this->Nfo->processNfoFiles($nntp, $groupID, $guidChar, (int)Settings::value('..lookupimdb'), (int)Settings::value('..lookuptvrage')); } } @@ -261,7 +262,7 @@ class PostProcess */ public function processTv($groupID = '', $guidChar = '', $processTV = '') { - $processTV = (is_numeric($processTV) ? $processTV : $this->pdo->getSetting('lookuptvrage')); + $processTV = (is_numeric($processTV) ? $processTV : Settings::value('..lookuptvrage')); if ($processTV > 0) { (new TVDB(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processSite($groupID, $guidChar, $processTV); (new TVMaze(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processSite($groupID, $guidChar, $processTV); @@ -296,7 +297,7 @@ class PostProcess */ public function processXXX() { - if ($this->pdo->getSetting('lookupxxx') == 1) { + if (Settings::value('..lookupxxx') == 1) { (new XXX(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processXXXReleases(); } } diff --git a/nntmux/processing/ProcessReleases.php b/nntmux/processing/ProcessReleases.php index 17455ef36..3d5dbf8fc 100755 --- a/nntmux/processing/ProcessReleases.php +++ b/nntmux/processing/ProcessReleases.php @@ -1,7 +1,8 @@ echoCLI = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->consoleTools = ($options['ConsoleTools'] instanceof ConsoleTools ? $options['ConsoleTools'] : new ConsoleTools(['ColorCLI' => $this->pdo->log])); $this->groups = ($options['Groups'] instanceof Groups ? $options['Groups'] : new Groups(['Settings' => $this->pdo])); $this->nzb = ($options['NZB'] instanceof NZB ? $options['NZB'] : new NZB($this->pdo)); @@ -132,17 +133,17 @@ class ProcessReleases $this->releases = ($options['Releases'] instanceof Releases ? $options['Releases'] : new Releases(['Settings' => $this->pdo, 'Groups' => $this->groups])); $this->releaseImage = ($options['ReleaseImage'] instanceof ReleaseImage ? $options['ReleaseImage'] : new ReleaseImage($this->pdo)); - $this->tablePerGroup = ($this->pdo->getSetting('tablepergroup') == 0 ? false : true); - $this->collectionDelayTime = ($this->pdo->getSetting('delaytime') != '' ? (int)$this->pdo->getSetting('delaytime') : 2); - $this->crossPostTime = ($this->pdo->getSetting('crossposttime') != '' ? (int)$this->pdo->getSetting('crossposttime') : 2); - $this->releaseCreationLimit = ($this->pdo->getSetting('maxnzbsprocessed') != '' ? (int)$this->pdo->getSetting('maxnzbsprocessed') : 1000); - $this->completion = ($this->pdo->getSetting('completionpercent') != '' ? (int)$this->pdo->getSetting('completionpercent') : 0); - $this->processRequestIDs = (int)$this->pdo->getSetting('lookup_reqids'); + $this->tablePerGroup = (Settings::value('..tablepergroup') == 0 ? false : true); + $this->collectionDelayTime = (Settings::value('..delaytime') != '' ? (int)Settings::value('..delaytime') : 2); + $this->crossPostTime = (Settings::value('..crossposttime') != '' ? (int)Settings::value('..crossposttime') : 2); + $this->releaseCreationLimit = (Settings::value('..maxnzbsprocessed') != '' ? (int)Settings::value('..maxnzbsprocessed') : 1000); + $this->completion = (Settings::value('..completionpercent') != '' ? (int)Settings::value('..completionpercent') : 0); + $this->processRequestIDs = (int)Settings::value('..lookup_reqids'); if ($this->completion > 100) { $this->completion = 100; echo $this->pdo->log->error(PHP_EOL . 'You have an invalid setting for completion. It must be lower than 100.'); } - $this->collectionTimeout = intval($this->pdo->getSetting('collection_timeout')); + $this->collectionTimeout = intval(Settings::value('..collection_timeout')); } /** @@ -171,9 +172,9 @@ class ProcessReleases $this->pdo->log->doEcho($this->pdo->log->header("Starting release update process (" . date('Y-m-d H:i:s') . ")"), true); } - if (!file_exists($this->pdo->getSetting('nzbpath'))) { + if (!file_exists(Settings::value('..nzbpath'))) { if ($this->echoCLI) { - $this->pdo->log->doEcho($this->pdo->log->error('Bad or missing nzb directory - ' . $this->pdo->getSetting('nzbpath')), true); + $this->pdo->log->doEcho($this->pdo->log->error('Bad or missing nzb directory - ' . Settings::value('..nzbpath')), true); } return 0; @@ -409,9 +410,9 @@ class ProcessReleases $minSizeDeleted = $maxSizeDeleted = $minFilesDeleted = 0; - $maxSizeSetting = $this->pdo->getSetting('maxsizetoformrelease'); - $minSizeSetting = $this->pdo->getSetting('minsizetoformrelease'); - $minFilesSetting = $this->pdo->getSetting('minfilestoformrelease'); + $maxSizeSetting = Settings::value('.release.maxsizetoformrelease'); + $minSizeSetting = Settings::value('.release.minsizetoformrelease'); + $minFilesSetting = Settings::value('.release.minfilestoformrelease'); foreach ($groupIDs as $groupID) { if ($this->pdo->queryOneRow( @@ -749,7 +750,7 @@ class ProcessReleases */ public function processRequestIDs($groupID = '', $limit = 5000, $local = true) { - if ($local === false && $this->pdo->getSetting('lookup_reqids') == 0) { + if ($local === false && Settings::value('..lookup_reqids') == 0) { return; } @@ -875,7 +876,7 @@ class ProcessReleases $this->pdo->log->header("Process Releases -> Delete finished collections." . PHP_EOL) . $this->pdo->log->primary(sprintf( 'Deleting collections/binaries/parts older than %d hours.', - $this->pdo->getSetting('partretentionhours') + Settings::value('..partretentionhours') )) ); } @@ -890,7 +891,7 @@ class ProcessReleases $group['cname'], $group['bname'], $group['pname'], - $this->pdo->getSetting('partretentionhours'), + Settings::value('..partretentionhours'), (!empty($groupID) && $this->tablePerGroup === false ? ' AND c.group_id = ' . $groupID : '') ) ); @@ -1082,9 +1083,9 @@ class ProcessReleases $groupIDs = [['id' => $groupID]]; } - $maxSizeSetting = $this->pdo->getSetting('maxsizetoformrelease'); - $minSizeSetting = $this->pdo->getSetting('minsizetoformrelease'); - $minFilesSetting = $this->pdo->getSetting('minfilestoformrelease'); + $maxSizeSetting = Settings::value('.release.maxsizetoformrelease'); + $minSizeSetting = Settings::value('.release.minsizetoformrelease'); + $minFilesSetting = Settings::value('.release.minfilestoformrelease'); foreach ($groupIDs as $groupID) { $releases = $this->pdo->queryDirect( @@ -1181,11 +1182,11 @@ class ProcessReleases } // Releases past retention. - if ($this->pdo->getSetting('releaseretentiondays') != 0) { + if (Settings::value('..releaseretentiondays') != 0) { $releases = $this->pdo->queryDirect( sprintf( 'SELECT id, guid FROM releases WHERE postdate < (NOW() - INTERVAL %d DAY)', - $this->pdo->getSetting('releaseretentiondays') + Settings::value('..releaseretentiondays') ) ); if ($releases instanceof \Traversable) { @@ -1197,7 +1198,7 @@ class ProcessReleases } // Passworded releases. - if ($this->pdo->getSetting('deletepasswordedrelease') == 1) { + if (Settings::value('..deletepasswordedrelease') == 1) { $releases = $this->pdo->queryDirect( sprintf( 'SELECT id, guid FROM releases WHERE passwordstatus = %d', @@ -1213,7 +1214,7 @@ class ProcessReleases } // Possibly passworded releases. - if ($this->pdo->getSetting('deletepossiblerelease') == 1) { + if (Settings::value('..deletepossiblerelease') == 1) { $releases = $this->pdo->queryDirect( sprintf( 'SELECT id, guid FROM releases WHERE passwordstatus = %d', @@ -1331,7 +1332,7 @@ class ProcessReleases } // Misc other. - if ($this->pdo->getSetting('miscotherretentionhours') > 0) { + if (Settings::value('..miscotherretentionhours') > 0) { $releases = $this->pdo->queryDirect( sprintf(' SELECT id, guid @@ -1339,7 +1340,7 @@ class ProcessReleases WHERE categories_id = %d AND adddate <= NOW() - INTERVAL %d HOUR', Category::OTHER_MISC, - $this->pdo->getSetting('miscotherretentionhours') + Settings::value('..miscotherretentionhours') ) ); if ($releases instanceof \Traversable) { @@ -1351,7 +1352,7 @@ class ProcessReleases } // Misc hashed. - if ($this->pdo->getSetting('mischashedretentionhours') > 0) { + if (Settings::value('..mischashedretentionhours') > 0) { $releases = $this->pdo->queryDirect( sprintf(' SELECT id, guid @@ -1359,7 +1360,7 @@ class ProcessReleases WHERE categories_id = %d AND adddate <= NOW() - INTERVAL %d HOUR', Category::OTHER_HASHED, - $this->pdo->getSetting('mischashedretentionhours') + Settings::value('..mischashedretentionhours') ) ); if ($releases instanceof \Traversable) { @@ -1657,7 +1658,7 @@ class ProcessReleases */ private function processStuckCollections(array $group, $where) { - $lastRun = $this->pdo->getSetting('last_run_time'); + $lastRun = Settings::value('..last_run_time'); $obj = $this->pdo->queryExec( sprintf(" DELETE c, b, p FROM %s c diff --git a/nntmux/processing/Videos.php b/nntmux/processing/Videos.php index 937febd4b..b2b3feb1c 100755 --- a/nntmux/processing/Videos.php +++ b/nntmux/processing/Videos.php @@ -20,7 +20,7 @@ */ namespace nntmux\processing; -use nntmux\db\Settings; +use nntmux\db\DB; /** * Parent class for TV/Film and any similar classes to inherit from. @@ -66,7 +66,7 @@ abstract class Videos //date_default_timezone_set('UTC'); TODO: Make this a DTO instead and use as needed $this->echooutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->titleCache = []; } diff --git a/nntmux/processing/post/AniDB.php b/nntmux/processing/post/AniDB.php index cee6a0c39..45abc059d 100755 --- a/nntmux/processing/post/AniDB.php +++ b/nntmux/processing/post/AniDB.php @@ -2,9 +2,10 @@ namespace nntmux\processing\post; +use app\models\Settings; use nntmux\Category; use nntmux\NZB; -use nntmux\db\Settings; +use nntmux\db\DB; class AniDB { @@ -50,9 +51,9 @@ class AniDB $options += $defaults; $this->echooutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); - $qty = $this->pdo->getSetting('maxanidbprocessed'); + $qty = Settings::value('..maxanidbprocessed'); $this->aniqty = !empty($qty) ? $qty : 100; $this->status = 'NULL'; diff --git a/nntmux/processing/post/ProcessAdditional.php b/nntmux/processing/post/ProcessAdditional.php index 108344af5..c66af136f 100755 --- a/nntmux/processing/post/ProcessAdditional.php +++ b/nntmux/processing/post/ProcessAdditional.php @@ -1,6 +1,7 @@ _echoCLI = ($options['Echo'] && NN_ECHOCLI && (strtolower(PHP_SAPI) === 'cli')); $this->_echoDebug = NN_DEBUG; - $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->_nntp = ($options['NNTP'] instanceof NNTP ? $options['NNTP'] : new NNTP(['Echo' => $this->_echoCLI, 'Settings' => $this->pdo])); $this->_nzb = ($options['NZB'] instanceof NZB ? $options['NZB'] : new NZB($this->pdo)); @@ -414,32 +415,32 @@ class ProcessAdditional $this->_nfo = ($options['Nfo'] instanceof Nfo ? $options['Nfo'] : new Nfo(['Echo' => $this->_echoCLI, 'Settings' => $this->pdo])); $this->sphinx = ($options['SphinxSearch'] instanceof SphinxSearch ? $options['SphinxSearch'] : new SphinxSearch()); - $this->_innerFileBlacklist = ($this->pdo->getSetting('innerfileblacklist') == '' ? false : $this->pdo->getSetting('innerfileblacklist')); - $this->_maxNestedLevels = ($this->pdo->getSetting('maxnestedlevels') == 0 ? 3 : $this->pdo->getSetting('maxnestedlevels')); - $this->_extractUsingRarInfo = ($this->pdo->getSetting('extractusingrarinfo') == 0 ? false : true); - $this->_fetchLastFiles = ($this->pdo->getSetting('fetchlastcompressedfiles') == 0 ? false : true); + $this->_innerFileBlacklist = (Settings::value('..innerfileblacklist') == '' ? false : Settings::value('..innerfileblacklist')); + $this->_maxNestedLevels = (Settings::value('..maxnestedlevels') == 0 ? 3 : Settings::value('..maxnestedlevels')); + $this->_extractUsingRarInfo = (Settings::value('..extractusingrarinfo') == 0 ? false : true); + $this->_fetchLastFiles = (Settings::value('..fetchlastcompressedfiles') == 0 ? false : true); $this->_7zipPath = false; $this->_unrarPath = false; // Pass the binary extractors to ArchiveInfo. $clients = []; - if ($this->pdo->getSetting('unrarpath') != '') { - $clients += [ArchiveInfo::TYPE_RAR => $this->pdo->getSetting('unrarpath')]; - $this->_unrarPath = $this->pdo->getSetting('unrarpath'); + if (Settings::value('..unrarpath') != '') { + $clients += [ArchiveInfo::TYPE_RAR => Settings::value('..unrarpath')]; + $this->_unrarPath = Settings::value('..unrarpath'); } - if ($this->pdo->getSetting('zippath') != '') { - $clients += [ArchiveInfo::TYPE_ZIP => $this->pdo->getSetting('zippath')]; - $this->_7zipPath = $this->pdo->getSetting('zippath'); + if (Settings::value('..zippath') != '') { + $clients += [ArchiveInfo::TYPE_ZIP => Settings::value('..zippath')]; + $this->_7zipPath = Settings::value('..zippath'); } $this->_archiveInfo->setExternalClients($clients); $this->_killString = '"'; - if ($this->pdo->getSetting('timeoutpath') != '' && $this->pdo->getSetting('timeoutseconds') > 0) { + if (Settings::value('..timeoutpath') != '' && Settings::value('..timeoutseconds') > 0) { $this->_killString = ( - '"' . $this->pdo->getSetting('timeoutpath') . + '"' . Settings::value('..timeoutpath') . '" --foreground --signal=KILL ' . - $this->pdo->getSetting('timeoutseconds') . ' "' + Settings::value('..timeoutseconds') . ' "' ); } @@ -447,52 +448,52 @@ class ProcessAdditional // Maximum amount of releases to fetch per run. $this->_queryLimit = - ($this->pdo->getSetting('maxaddprocessed') != '') ? (int)$this->pdo->getSetting('maxaddprocessed') : 25; + (Settings::value('..maxaddprocessed') != '') ? (int)Settings::value('..maxaddprocessed') : 25; // Maximum message ID's to download per file type in the NZB (video, jpg, etc). $this->_segmentsToDownload = - ($this->pdo->getSetting('segmentstodownload') != '') ? (int)$this->pdo->getSetting('segmentstodownload') : 2; + (Settings::value('..segmentstodownload') != '') ? (int)Settings::value('..segmentstodownload') : 2; // Maximum message ID's to download for a RAR file. $this->_maximumRarSegments = - ($this->pdo->getSetting('maxpartsprocessed') != '') ? (int)$this->pdo->getSetting('maxpartsprocessed') : 3; + (Settings::value('..maxpartsprocessed') != '') ? (int)Settings::value('..maxpartsprocessed') : 3; // Maximum RAR files to check for a password before stopping. $this->_maximumRarPasswordChecks = - ($this->pdo->getSetting('passchkattempts') != '') ? (int)$this->pdo->getSetting('passchkattempts') : 1; + (Settings::value('..passchkattempts') != '') ? (int)Settings::value('..passchkattempts') : 1; $this->_maximumRarPasswordChecks = ($this->_maximumRarPasswordChecks < 1 ? 1 : $this->_maximumRarPasswordChecks); // Maximum size of releases in GB. $this->_maxSize = - ($this->pdo->getSetting('maxsizetopostprocess') != '') ? (int)$this->pdo->getSetting('maxsizetopostprocess') : 100; + (Settings::value('..maxsizetopostprocess') != '') ? (int)Settings::value('..maxsizetopostprocess') : 100; $this->_maxSize = ($this->_maxSize > 0 ? ('AND r.size < ' . ($this->_maxSize * 1073741824)) : ''); // Minimum size of releases in MB. $this->_minSize = - ($this->pdo->getSetting('minsizetopostprocess') != '') ? (int)$this->pdo->getSetting('minsizetopostprocess') : 100; + (Settings::value('..minsizetopostprocess') != '') ? (int)Settings::value('..minsizetopostprocess') : 100; $this->_minSize = ($this->_minSize > 0 ? ('AND r.size > ' . ($this->_minSize * 1048576)) : ''); // Use the alternate NNTP provider for downloading Message-ID's ? - $this->_alternateNNTP = ($this->pdo->getSetting('alternate_nntp') == 1 ? true : false); + $this->_alternateNNTP = (Settings::value('..alternate_nntp') == 1 ? true : false); - $this->_ffMPEGDuration = ($this->pdo->getSetting('ffmpeg_duration') != '') ? (int)$this->pdo->getSetting('ffmpeg_duration') : 5; + $this->_ffMPEGDuration = (Settings::value('..ffmpeg_duration') != '') ? (int)Settings::value('..ffmpeg_duration') : 5; - $this->_addPAR2Files = ($this->pdo->getSetting('addpar2') === '0') ? false : true; + $this->_addPAR2Files = (Settings::value('..addpar2') === '0') ? false : true; - if (!$this->pdo->getSetting('ffmpegpath')) { + if (!Settings::value('..ffmpegpath')) { $this->_processAudioSample = $this->_processThumbnails = $this->_processVideo = false; } else { - $this->_processAudioSample = ($this->pdo->getSetting('saveaudiopreview') == 0) ? false : true; - $this->_processThumbnails = ($this->pdo->getSetting('processthumbnails') == 0 ? false : true); - $this->_processVideo = ($this->pdo->getSetting('processvideos') == 0) ? false : true; + $this->_processAudioSample = (Settings::value('..saveaudiopreview') == 0) ? false : true; + $this->_processThumbnails = (Settings::value('..processthumbnails') == 0 ? false : true); + $this->_processVideo = (Settings::value('..processvideos') == 0) ? false : true; } - $this->_processJPGSample = ($this->pdo->getSetting('processjpg') == 0) ? false : true; - $this->_processMediaInfo = ($this->pdo->getSetting('mediainfopath') == '') ? false : true; + $this->_processJPGSample = (Settings::value('..processjpg') == 0) ? false : true; + $this->_processMediaInfo = (Settings::value('..mediainfopath') == '') ? false : true; $this->_processAudioInfo = $this->_processMediaInfo; $this->_processPasswords = ( - ((($this->pdo->getSetting('checkpasswordedrar') == 0) ? false : true)) && - (($this->pdo->getSetting('unrarpath') == '') ? false : true) + (((Settings::value('..checkpasswordedrar') == 0) ? false : true)) && + ((Settings::value('..unrarpath') == '') ? false : true) ); $this->_audioSavePath = NN_COVERS . 'audiosample' . DS; @@ -556,7 +557,7 @@ class ProcessAdditional protected function _setMainTempPath(&$guidChar, &$groupID = '') { // Set up the temporary files folder location. - $this->_mainTmpPath = (string)$this->pdo->getSetting('tmpunrarpath'); + $this->_mainTmpPath = (string)Settings::value('..tmpunrarpath'); // Check if it ends with a dir separator. if (!preg_match('/[\/\\\\]$/', $this->_mainTmpPath)) { @@ -1774,7 +1775,7 @@ class ProcessAdditional // Get the media info for the file. $xmlArray = Utility::runCmd( - $this->_killString . $this->pdo->getSetting('mediainfopath') . '" --Output=XML "' . $fileLocation . '"' + $this->_killString . Settings::value('..mediainfopath') . '" --Output=XML "' . $fileLocation . '"' ); if (is_array($xmlArray)) { @@ -1862,7 +1863,7 @@ class ProcessAdditional // Create an audio sample. Utility::runCmd( $this->_killString . - $this->pdo->getSetting('ffmpegpath') . + Settings::value('..ffmpegpath') . '" -t 30 -i "' . $fileLocation . '" -acodec libvorbis -loglevel quiet -y "' . @@ -1965,7 +1966,7 @@ class ProcessAdditional // Get the real duration of the file. $time = Utility::runCmd( $this->_killString . - $this->pdo->getSetting('ffmpegpath') . + Settings::value('..ffmpegpath') . '" -i "' . $videoLocation . '" -vcodec copy -y 2>&1 "' . $tmpVideo . '"', @@ -2011,7 +2012,7 @@ class ProcessAdditional // Create the image. Utility::runCmd( $this->_killString . - $this->pdo->getSetting('ffmpegpath') . + Settings::value('..ffmpegpath') . '" -i "' . $fileLocation . '" -ss ' . ($time === '' ? '00:00:03.00' : $time) . @@ -2104,7 +2105,7 @@ class ProcessAdditional // Try to get the sample (from the end instead of the start). Utility::runCmd( $this->_killString . - $this->pdo->getSetting('ffmpegpath') . + Settings::value('..ffmpegpath') . '" -i "' . $fileLocation . '" -ss ' . $lowestLength . @@ -2121,7 +2122,7 @@ class ProcessAdditional // If longer than 60 or we could not get the video length, run the old way. Utility::runCmd( $this->_killString . - $this->pdo->getSetting('ffmpegpath') . + Settings::value('..ffmpegpath') . '" -i "' . $fileLocation . '" -vcodec libtheora -filter:v scale=320:-1 -t ' . @@ -2195,7 +2196,7 @@ class ProcessAdditional // Run media info on it. $xmlArray = Utility::runCmd( - $this->_killString . $this->pdo->getSetting('mediainfopath') . '" --Output=XML "' . $fileLocation . '"' + $this->_killString . Settings::value('..mediainfopath') . '" --Output=XML "' . $fileLocation . '"' ); // Check if we got it. diff --git a/nntmux/processing/tv/TMDB.php b/nntmux/processing/tv/TMDB.php index 5fa5fb7db..52456ef71 100755 --- a/nntmux/processing/tv/TMDB.php +++ b/nntmux/processing/tv/TMDB.php @@ -1,6 +1,7 @@ client = new TmdbAPI($this->pdo->getSetting('tmdbkey')); + $this->client = new TmdbAPI(Settings::value('..tmdbkey')); } /** diff --git a/nntmux/processing/tv/TV.php b/nntmux/processing/tv/TV.php index ddfc7baac..9c611e159 100755 --- a/nntmux/processing/tv/TV.php +++ b/nntmux/processing/tv/TV.php @@ -1,6 +1,7 @@ catWhere = "categories_id BETWEEN " . Category::TV_ROOT . " AND " . Category::TV_OTHER . " AND categories_id != " . Category::TV_ANIME; - $this->tvqty = ($this->pdo->getSetting('maxrageprocessed') != '') ? $this->pdo->getSetting('maxrageprocessed') : 75; + $this->tvqty = (Settings::value('..maxrageprocessed') != '') ? Settings::value('..maxrageprocessed') : 75; $this->imgSavePath = NN_COVERS . 'tvshows' . DS; $this->siteColumns = ['tvdb', 'trakt', 'tvrage', 'tvmaze', 'imdb', 'tmdb']; } diff --git a/nntmux/processing/tv/TraktTv.php b/nntmux/processing/tv/TraktTv.php index 5ea633232..4eb5c43c6 100755 --- a/nntmux/processing/tv/TraktTv.php +++ b/nntmux/processing/tv/TraktTv.php @@ -1,6 +1,7 @@ clientId = $this->pdo->getSetting('trakttvclientkey'); + $this->clientId = Settings::value('APIs..trakttvclientkey'); $this->requestHeaders = [ 'Content-Type: application/json', 'trakt-api-version: 2', diff --git a/nntmux/utility/Utility.php b/nntmux/utility/Utility.php index 13f5a292e..917103575 100755 --- a/nntmux/utility/Utility.php +++ b/nntmux/utility/Utility.php @@ -1,8 +1,9 @@ getSetting(['section' => '', 'subsection' => '', 'name' => 'sqlpatch']); + $patch = Settings::value(['section' => '', 'subsection' => '', 'name' => 'sqlpatch']); $ver = $versions->versions->sql->file; // Check database patch version @@ -717,7 +718,7 @@ class Utility $mail->Password = PHPMAILER_SMTP_PASSWORD; } } - $settings = new Settings(); + $settings = new DB(); $fromEmail = (PHPMAILER_FROM_EMAIL == '') ? $settings->getSetting('email') : PHPMAILER_FROM_EMAIL; $fromName = (PHPMAILER_FROM_NAME == '') ? $settings->getSetting('title') : PHPMAILER_FROM_NAME; @@ -752,7 +753,7 @@ class Utility */ public static function fileInfo($path) { - $magicPath = (new Settings())->getSetting('magic_file_path'); + $magicPath = (new DB())->getSetting('magic_file_path'); if (self::hasCommand('file') && (!self::isWin() || !empty($magicPath))) { $magicSwitch = empty($magicPath) ? '' : " -m $magicPath"; $output = self::runCmd('file' . $magicSwitch . ' -b "' . $path . '"'); diff --git a/nntmux/utility/Versions.php b/nntmux/utility/Versions.php index a3c348d01..d74691f7a 100755 --- a/nntmux/utility/Versions.php +++ b/nntmux/utility/Versions.php @@ -184,7 +184,7 @@ class Versions { $this->checkSQLFileLatest($update); - //$settings = new Settings(); + //$settings = new DB(); //$setting = $settings->getSetting('sqlpatch'); if ($this->_vers->sql->db->__toString() != $this->_vers->sql->file->__toString()) { diff --git a/resources/db/patches/mysql/+1~settings.sql b/resources/db/patches/mysql/+1~settings.sql new file mode 100644 index 000000000..cd1b87983 --- /dev/null +++ b/resources/db/patches/mysql/+1~settings.sql @@ -0,0 +1,19 @@ +#Make sure innerfileblacklist setting exists. + +UPDATE settings SET section = 'indexer', subsection = 'ppa', name = 'innerfileblacklist', value = '/setup\.exe|password\.url/i', hint = 'You can add a regex here to set releases to potentially passworded when a file name inside a rar/zip matches this regex.' WHERE setting = 'innerfileblacklist'; + +#Make sure minsizetoformrelease setting exists. + + UPDATE settings SET subsection = 'release' where setting = 'minsizetoformrelease'; + + #Make sure maxsizetoformrelease setting exists. + + UPDATE settings SET subsection = 'release' where setting = 'maxsizetoformrelease'; + +#Make sure minfilestoformrelease setting exists. + +UPDATE settings SET subsection = 'release' where setting = 'minfilestoformrelease'; + +#Update coverspath setting. + + UPDATE settings SET sections = 'site', subsection = 'main' where setting = 'coverspath'; diff --git a/www/admin/ajax_sharing_settings.php b/www/admin/ajax_sharing_settings.php index 0bd9f4475..dca68dc2e 100644 --- a/www/admin/ajax_sharing_settings.php +++ b/www/admin/ajax_sharing_settings.php @@ -3,13 +3,13 @@ require_once './config.php'; -use nntmux\db\Settings; +use nntmux\db\DB; use nntmux\Sharing; use nntmux\ReleaseComments; // Login check. $admin = new AdminPage; -$db = new Settings(); +$db = new DB(); if (isset($_GET['site_ID']) && isset($_GET['site_status'])) { $db->queryExec(sprintf('UPDATE sharing_sites SET enabled = %d WHERE id = %d', $_GET['site_status'], $_GET['site_ID'])); diff --git a/www/admin/collection_regexes-test.php b/www/admin/collection_regexes-test.php index 1c03684f6..42a890f2a 100644 --- a/www/admin/collection_regexes-test.php +++ b/www/admin/collection_regexes-test.php @@ -8,7 +8,7 @@ $page = new AdminPage(); $page->title = "Collections Regex Test"; -$tpg = $page->settings->getSetting('tablepergroup'); +$tpg = $page->getSettingValue('..tablepergroup'); $page->smarty->assign('tpg', $tpg); if ($tpg) { diff --git a/www/admin/release-files.php b/www/admin/release-files.php index 71775acf9..82859f0b1 100644 --- a/www/admin/release-files.php +++ b/www/admin/release-files.php @@ -21,7 +21,7 @@ if (isset($_GET["id"])) if (!$rel) $page->show404(); - $nzbpath = $nzb->getNZBPath($_GET["id"], $page->settings->getSetting('nzbpath')); + $nzbpath = $nzb->getNZBPath($_GET["id"], $page->getSettingValue('..nzbpath')); if (!file_exists($nzbpath)) $page->show404(); diff --git a/www/admin/sharing.php b/www/admin/sharing.php index ec9412be2..a513450e9 100644 --- a/www/admin/sharing.php +++ b/www/admin/sharing.php @@ -1,13 +1,13 @@ title = 'Sharing Settings'; -$db = new Settings(); +$db = new DB(); $offset = (isset($_GET['offset']) ? $_GET['offset'] : 0); diff --git a/www/admin/site-edit.php b/www/admin/site-edit.php index 51b329cc1..3b4b23713 100644 --- a/www/admin/site-edit.php +++ b/www/admin/site-edit.php @@ -3,9 +3,9 @@ require_once './config.php'; +use app\models\Settings; use nntmux\Category; use nntmux\SABnzbd; -use nntmux\db\Settings; use nntmux\Sites; use nntmux\utility\Utility; @@ -27,7 +27,7 @@ switch($action) implode(', ', $_POST['book_reqids']) : $_POST['book_reqids']; } $error = ""; - $ret = $page->settings->update($_POST); + $ret = $page->settings->settingsUpdate($_POST); if (is_int($ret)) { if ($ret == Settings::ERR_BADUNRARPATH) @@ -163,7 +163,7 @@ $page->smarty->assign('book_reqids_ids', $book_reqids_ids); $page->smarty->assign('book_reqids_names', $book_reqids_names); // convert from a list to an array as we need to use an array, but teh Settings table only saves strings -$books_selected = explode(",", $page->settings->getSetting('book_reqids')); +$books_selected = explode(",", $page->getSettingValue('..book_reqids')); // convert from a string array to an int array $books_selected = array_map(create_function('$value', 'return (int)$value;'), $books_selected); diff --git a/www/index.php b/www/index.php index a03bc5ed6..702f55a74 100644 --- a/www/index.php +++ b/www/index.php @@ -2,7 +2,7 @@ require_once 'smarty.php'; require_once NN_ROOT . 'app' . DS . 'config' . DS . 'bootstrap' . DS . 'libraries.php'; -use nntmux\db\Settings; +use app\models\Settings; $page = new Page; @@ -65,8 +65,8 @@ switch ($page->page) { case 'xxx': case 'xxxmodal': // Don't show these pages if it's an API-only site. - if (!$page->users->isLoggedIn() && $page->settings->getSetting('registerstatus') == Settings::REGISTER_STATUS_API_ONLY) { - header("Location: " . $page->settings->getSetting('code')); + if (!$page->users->isLoggedIn() && $page->getSettingValue('..registerstatus') == Settings::REGISTER_STATUS_API_ONLY) { + header("Location: " . $page->getSettingValue('..code')); break; } case 'api': diff --git a/www/install/step7.php b/www/install/step7.php index a19b8be10..bbf41dfb4 100755 --- a/www/install/step7.php +++ b/www/install/step7.php @@ -3,7 +3,7 @@ require_once realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install.php'); use nntmux\Install; -use nntmux\db\Settings; +use nntmux\db\DB; $page = new InstallPage(); @@ -80,7 +80,7 @@ if ($page->isPostBack()) { mkdir($cfg->UNRAR_PATH); } - $pdo = new Settings(); + $pdo = new DB(); $sql1 = sprintf("UPDATE settings SET value = %s WHERE setting = 'nzbpath'", $pdo->escapeString($cfg->NZB_PATH)); $sql2 = sprintf("UPDATE settings SET value = %s WHERE setting = 'tmpunrarpath'", $pdo->escapeString($cfg->UNRAR_PATH)); $sql3 = sprintf("UPDATE settings SET value = %s WHERE setting = 'coverspath'", $pdo->escapeString($cfg->COVERS_PATH)); diff --git a/www/pages/BasePage.php b/www/pages/BasePage.php index 200005e04..a48873380 100644 --- a/www/pages/BasePage.php +++ b/www/pages/BasePage.php @@ -2,7 +2,8 @@ require_once NN_LIB . 'utility' . DS . 'SmartyUtils.php'; -use nntmux\db\Settings; +use app\models\Settings; +use nntmux\db\DB; use nntmux\Users; use nntmux\SABnzbd; @@ -95,7 +96,7 @@ class BasePage } // Buffer settings/DB connection. - $this->settings = new Settings(); + $this->settings = new DB(); $this->smarty = new Smarty(); $this->smarty->setCompileDir(NN_SMARTY_TEMPLATES); @@ -122,7 +123,7 @@ class BasePage if ($this->users->isLoggedIn()) { $this->setUserPreferences(); } else { - $this->theme = $this->settings->getSetting('style'); + $this->theme = $this->getSettingValue('main.site.style'); $this->smarty->assign('isadmin', 'false'); $this->smarty->assign('ismod', 'false'); @@ -371,4 +372,33 @@ class BasePage $this->settings->setSetting(['addetail', '']); } } + + /** + * Allows to fetch a value from the settings table. + * + * This method is deprecated, as the column it uses to select the data is due to be removed + * from the table *soon*. + * + * @param $setting + * + * @return array|bool|mixed|null|string + */ + public function getSetting($setting) + { + if (strpos($setting, '.') === false) { + trigger_error( + 'You should update your template to use the newer method "$page->getSettingValue()"" of fetching values from the "settings" table! This method *will* be removed in a future version.', + E_USER_WARNING); + } else { + return $this->getSettingValue($setting); + } + + return $this->settings->$setting; + + } + + public function getSettingValue($setting) + { + return Settings::value($setting); + } } diff --git a/www/pages/ajax_profile.php b/www/pages/ajax_profile.php index ed21572a9..63dddef88 100644 --- a/www/pages/ajax_profile.php +++ b/www/pages/ajax_profile.php @@ -6,7 +6,7 @@ if (!$page->users->isLoggedIn()) if (isset($_GET['action']) && $_GET['action'] == "1" && isset($_GET['emailto'])) { $emailto = $_GET['emailto']; - $ret = $page->users->sendInvite($page->settings->getSetting('title'), $page->settings->getSetting('email'), $page->serverurl, $page->users->currentUserId(), $emailto); + $ret = $page->users->sendInvite($page->getSettingValue('..title'), $page->getSettingValue('..email'), $page->serverurl, $page->users->currentUserId(), $emailto); if (!$ret) print "Invite not sent."; else diff --git a/www/pages/api.php b/www/pages/api.php index 196c2740b..a16fb3397 100644 --- a/www/pages/api.php +++ b/www/pages/api.php @@ -1,9 +1,8 @@ verifyEmptyParameter('email'); - if (!in_array((int)$page->settings->getSetting('registerstatus'), [Settings::REGISTER_STATUS_OPEN, Settings::REGISTER_STATUS_API_ONLY])) { + if (!in_array((int)$page->getSettingValue('..registerstatus'), [Settings::REGISTER_STATUS_OPEN, Settings::REGISTER_STATUS_API_ONLY])) { Utility::showApiError(104); } // Check email is valid format. diff --git a/www/pages/contact-us.php b/www/pages/contact-us.php index 47949c3fc..b5b941696 100644 --- a/www/pages/contact-us.php +++ b/www/pages/contact-us.php @@ -12,7 +12,7 @@ if (isset($_POST["useremail"])) { if ($captcha->getError() === false) { $email = $_POST["useremail"]; - $mailto = $page->settings->getSetting('email'); + $mailto = $page->getSettingValue('..email'); $mailsubj = "Contact Form Submitted"; $mailhead = "From: $email\n"; $mailbody = "Values submitted from contact form:\n"; @@ -27,14 +27,14 @@ if (isset($_POST["useremail"])) { Utility::sendEmail($mailto, $mailsubj, $mailbody, $email); } - $msg = "

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

"; + $msg = "

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

"; } } $page->smarty->assign('msg', $msg); -$page->title = "Contact ".$page->settings->getSetting('title'); -$page->meta_title = "Contact ".$page->settings->getSetting('title'); +$page->title = "Contact ".$page->getSettingValue('..title'); +$page->meta_title = "Contact ".$page->getSettingValue('..title'); $page->meta_keywords = "contact us,contact,get in touch,email"; -$page->meta_description = "Contact us at ".$page->settings->getSetting('title')." and submit your feedback"; +$page->meta_description = "Contact us at ".$page->getSettingValue('..title')." and submit your feedback"; $page->content = $page->smarty->fetch('contact.tpl'); diff --git a/www/pages/details.php b/www/pages/details.php index 7af1dd098..8bcae703e 100644 --- a/www/pages/details.php +++ b/www/pages/details.php @@ -60,13 +60,13 @@ if (isset($_GET["id"])) $mov['actors'] = $movie->makeFieldLinks($mov, 'actors'); $mov['genre'] = $movie->makeFieldLinks($mov, 'genre'); $mov['director'] = $movie->makeFieldLinks($mov, 'director'); - if ($page->settings->getSetting('trailers_display')) { + if ($page->getSettingValue('site.trailers.trailers_display')) { $trailer = (!isset($mov['trailer']) || empty($mov['trailer']) || $mov['trailer'] == '' ? $movie->getTrailer($data['imdbid']) : $mov['trailer']); if ($trailer) { $mov['trailer'] = sprintf( "", - $page->settings->getSetting('trailers_size_x'), - $page->settings->getSetting('trailers_size_y'), + $page->getSettingValue('site.trailers.trailers_size_x'), + $page->getSettingValue('site.trailers.trailers_size_y'), $trailer ); } @@ -148,7 +148,7 @@ if (isset($_GET["id"])) $page->smarty->assign('comments',$comments); $page->smarty->assign('searchname',$releases->getSimilarName($data['searchname'])); $page->smarty->assign('similars', $similars); - $page->smarty->assign('privateprofiles', ($page->settings->getSetting('privateprofiles') == 1) ? true : false ); + $page->smarty->assign('privateprofiles', ($page->getSettingValue('..privateprofiles') == 1) ? true : false ); $page->smarty->assign('failed', $failed); $page->smarty->assign('cpapi', $cpapi); $page->smarty->assign('cpurl', $cpurl); diff --git a/www/pages/failed.php b/www/pages/failed.php index d777cff1d..ce0824003 100644 --- a/www/pages/failed.php +++ b/www/pages/failed.php @@ -1,14 +1,14 @@ users->isLoggedIn()) { $uid = $page->users->currentUserId(); $rssToken = $page->userdata['rsstoken']; } else { - if ($page->settings->getSetting('registerstatus') == Settings::REGISTER_STATUS_API_ONLY) { + if ($page->getSettingValue('..registerstatus') == Settings::REGISTER_STATUS_API_ONLY) { if (!isset($_GET["rsstoken"])) { header("X-DNZB-RCode: 400"); header("X-DNZB-RText: Bad request, please supply all parameters!"); diff --git a/www/pages/forgottenpassword.php b/www/pages/forgottenpassword.php index df32efb0d..a7a729d88 100644 --- a/www/pages/forgottenpassword.php +++ b/www/pages/forgottenpassword.php @@ -32,10 +32,10 @@ switch($action) { $page->users->updatePassword($ret["id"], $newpass); $to = $ret["email"]; - $subject = $page->settings->getSetting('title') . " Password Reset"; + $subject = $page->getSettingValue('..title') . " Password Reset"; $contents = "Your password has been reset to " . $newpass; $onscreen = "Your password has been reset to " . $newpass ." and sent to your e-mail address."; - Utility::sendEmail($to, $subject, $contents, $page->settings->getSetting('email')); + Utility::sendEmail($to, $subject, $contents, $page->getSettingValue('..email')); $page->smarty->assign('notice', $onscreen); $confirmed = "true"; break; @@ -68,9 +68,9 @@ switch($action) { // Send the email // $to = $ret["email"]; - $subject = $page->settings->getSetting('title') . " Forgotten Password Request"; + $subject = $page->getSettingValue('..title') . " Forgotten Password Request"; $contents = "Someone has requested a password reset for this email address. To reset the password use the following link.\n\n " . $page->serverurl . "forgottenpassword?action=reset&guid=" . $guid; - Utility::sendEmail($to, $subject, $contents, $page->settings->getSetting('email')); + Utility::sendEmail($to, $subject, $contents, $page->getSettingValue('..email')); $sent = "true"; break; } diff --git a/www/pages/forum.php b/www/pages/forum.php index 07936314e..2029af393 100644 --- a/www/pages/forum.php +++ b/www/pages/forum.php @@ -46,7 +46,7 @@ $page->smarty->assign('pageroffset',$offset); $page->smarty->assign('pageritemsperpage',ITEMS_PER_PAGE); $page->smarty->assign('pagerquerybase', WWW_TOP."/forum?offset="); $page->smarty->assign('pagerquerysuffix', "#results"); -$page->smarty->assign('privateprofiles', ($page->settings->getSetting('privateprofiles') == 1) ? true : false ); +$page->smarty->assign('privateprofiles', ($page->getSettingValue('..privateprofiles') == 1) ? true : false ); $pager = $page->smarty->fetch("pager.tpl"); $page->smarty->assign('pager', $pager); diff --git a/www/pages/forumpost.php b/www/pages/forumpost.php index 64fd2fb8f..a1b6ecb5f 100644 --- a/www/pages/forumpost.php +++ b/www/pages/forumpost.php @@ -27,7 +27,7 @@ $page->meta_keywords = "view,forum,post,thread"; $page->meta_description = "View forum post"; $page->smarty->assign('results', $results); -$page->smarty->assign('privateprofiles', ($page->settings->getSetting('privateprofiles') == 1) ? true : false ); +$page->smarty->assign('privateprofiles', ($page->getSettingValue('..privateprofiles') == 1) ? true : false ); $page->content = $page->smarty->fetch('forumpost.tpl'); $page->render(); diff --git a/www/pages/getnzb.php b/www/pages/getnzb.php index 9890de163..848f9bcca 100644 --- a/www/pages/getnzb.php +++ b/www/pages/getnzb.php @@ -1,9 +1,9 @@ users->isLoggedIn()) { Utility::showApiError(101); } } else { - if ($page->settings->getSetting('registerstatus') == Settings::REGISTER_STATUS_API_ONLY) { + if ($page->getSettingValue('..registerstatus') == Settings::REGISTER_STATUS_API_ONLY) { $res = $page->users->getById(0); } else { if ((!isset($_GET["i"]) || !isset($_GET["r"]))) { @@ -44,8 +44,8 @@ if (isset($_GET['id'])) { // A hash of the users ip to record against the download // $hosthash = ""; -if ($page->settings->getSetting('storeuserips') == 1) { - $hosthash = $page->users->getHostHash($_SERVER["REMOTE_ADDR"], $page->settings->getSetting('siteseed')); +if ($page->getSettingValue('..storeuserips') == 1) { + $hosthash = $page->users->getHostHash($_SERVER["REMOTE_ADDR"], $page->getSettingValue('..siteseed')); } // Check download limit on user role. diff --git a/www/pages/mymovies.php b/www/pages/mymovies.php index aa017eabc..89abe7994 100755 --- a/www/pages/mymovies.php +++ b/www/pages/mymovies.php @@ -62,7 +62,7 @@ switch ($action) { $categories = []; foreach ($tmpcats as $c) { // If MOVIE WEB-DL categorization is disabled, don't include it as an option - if ($page->settings->getSetting('catwebdl') == 0 && $c['id'] == Category::MOVIE_WEBDL) { + if ($page->getSettingValue('..catwebdl') == 0 && $c['id'] == Category::MOVIE_WEBDL) { continue; } $categories[$c['id']] = $c['title']; diff --git a/www/pages/myshows.php b/www/pages/myshows.php index 7be69dafd..5f23a16f9 100755 --- a/www/pages/myshows.php +++ b/www/pages/myshows.php @@ -62,7 +62,7 @@ switch ($action) { $categories = []; foreach ($tmpcats as $c) { // If TV WEB-DL categorization is disabled, don't include it as an option - if ($page->settings->getSetting('catwebdl') == 0 && $c['id'] == Category::TV_WEBDL) { + if ($page->getSettingValue('..catwebdl') == 0 && $c['id'] == Category::TV_WEBDL) { continue; } $categories[$c['id']] = $c['title']; diff --git a/www/pages/profile.php b/www/pages/profile.php index f68afe713..bf8eeabee 100644 --- a/www/pages/profile.php +++ b/www/pages/profile.php @@ -13,7 +13,7 @@ $nzbget = new NZBGet($page); $userID = $page->users->currentUserId(); $privileged = ($page->users->isAdmin($userID) || $page->users->isModerator($userID)) ? true : false; -$privateProfiles = ($page->settings->getSetting('privateprofiles') == 1) ? true : false; +$privateProfiles = ($page->getSettingValue('..privateprofiles') == 1) ? true : false; $publicView = false; if (!$privateProfiles || $privileged) { diff --git a/www/pages/profileedit.php b/www/pages/profileedit.php index 398173ce8..c20698565 100644 --- a/www/pages/profileedit.php +++ b/www/pages/profileedit.php @@ -103,7 +103,7 @@ switch ($action) { default: break; } -if ($page->settings->getSetting('userselstyle') == 1) { +if ($page->getSettingValue('..userselstyle') == 1) { // Get the list of themes. $page->smarty->assign('themelist', Utility::getThemesList()); } diff --git a/www/pages/queue.php b/www/pages/queue.php index 47e2c5b4e..8f01e9540 100644 --- a/www/pages/queue.php +++ b/www/pages/queue.php @@ -15,7 +15,7 @@ $page->smarty->assign('user', $userData); $queueType = $error = ''; $queue = null; -switch($page->settings->getSetting('sabintegrationtype')) { +switch($page->getSettingValue('..sabintegrationtype')) { case SABnzbd::INTEGRATION_TYPE_NONE: if ($userData['queuetype'] == 2) { $queueType = 'NZBGet'; diff --git a/www/pages/register.php b/www/pages/register.php index 77d7d439a..98de05b5d 100644 --- a/www/pages/register.php +++ b/www/pages/register.php @@ -1,6 +1,6 @@ users->isLoggedIn()) { $error = $userName = $password = $confirmPassword = $email = $inviteCode = $inviteCodeQuery = ''; $showRegister = 1; -if ($page->settings->getSetting('registerstatus') == Settings::REGISTER_STATUS_CLOSED || $page->settings->getSetting('registerstatus') == Settings::REGISTER_STATUS_API_ONLY) { +if ($page->getSettingValue('..registerstatus') == Settings::REGISTER_STATUS_CLOSED || $page->getSettingValue('registerstatus') == Settings::REGISTER_STATUS_API_ONLY) { $error = "Registrations are currently disabled."; $showRegister = 0; -} elseif ($page->settings->getSetting('registerstatus') == Settings::REGISTER_STATUS_INVITE && (!isset($_REQUEST["invitecode"]) || empty($_REQUEST['invitecode']))) { +} elseif ($page->getSettingValue('..registerstatus') == Settings::REGISTER_STATUS_INVITE && (!isset($_REQUEST["invitecode"]) || empty($_REQUEST['invitecode']))) { $error = "Registrations are currently invite only."; $showRegister = 0; } diff --git a/www/pages/rss.php b/www/pages/rss.php index a0c2d480c..03d6136b1 100755 --- a/www/pages/rss.php +++ b/www/pages/rss.php @@ -1,8 +1,8 @@ $page->settings]); @@ -13,10 +13,10 @@ $offset = 0; if (!isset($_GET["t"]) && !isset($_GET["show"]) && !isset($_GET["anidb"])) { // User has to either be logged in, or using rsskey. if (!$page->users->isLoggedIn()) { - if ($page->settings->getSetting('registerstatus') != Settings::REGISTER_STATUS_API_ONLY) { + if ($page->getSettingValue('..registerstatus') != Settings::REGISTER_STATUS_API_ONLY) { Utility::showApiError(100); } else { - header("Location: " . $page->settings->getSetting('code')); + header("Location: " . $page->getSettingValue('..code')); } } @@ -56,7 +56,7 @@ if (!isset($_GET["t"]) && !isset($_GET["show"]) && !isset($_GET["anidb"])) { $rssToken = $page->userdata["rsstoken"]; $maxRequests = $page->userdata['apirequests']; } else { - if ($page->settings->getSetting('registerstatus') == Settings::REGISTER_STATUS_API_ONLY) { + if ($page->getSettingValue('..registerstatus') == Settings::REGISTER_STATUS_API_ONLY) { $res = $page->users->getById(0); } else { if (!isset($_GET["i"]) || !isset($_GET["r"])) { diff --git a/www/pages/sitemap.php b/www/pages/sitemap.php index d376ac456..883340ee3 100644 --- a/www/pages/sitemap.php +++ b/www/pages/sitemap.php @@ -76,10 +76,10 @@ if (isset($_GET["type"]) && $_GET["type"] == "xml") } else { - $page->title = $page->settings->getSetting('title'). " site map"; - $page->meta_title = $page->settings->getSetting('title'). " site map"; + $page->title = $page->getSettingValue('..title'). " site map"; + $page->meta_title = $page->getSettingValue('..title'). " site map"; $page->meta_keywords = "sitemap,site,map"; - $page->meta_description = $page->settings->getSetting('title')." site map shows all our pages."; + $page->meta_description = $page->getSettingValue('..title')." site map shows all our pages."; $page->content = $page->smarty->fetch('sitemap.tpl'); $page->render(); } diff --git a/www/pages/terms-and-conditions.php b/www/pages/terms-and-conditions.php index 636e80937..e0f5352cb 100644 --- a/www/pages/terms-and-conditions.php +++ b/www/pages/terms-and-conditions.php @@ -1,9 +1,9 @@ title = "Terms and Conditions"; -$page->meta_title = $page->settings->getSetting('title')." - Terms and conditions"; +$page->meta_title = $page->getSettingValue('..title')." - Terms and conditions"; $page->meta_keywords = "terms,conditions"; -$page->meta_description = "Terms and Conditions for ".$page->settings->getSetting('title'); +$page->meta_description = "Terms and Conditions for ".$page->getSettingValue('..title'); $page->content = $page->smarty->fetch('terms.tpl'); diff --git a/www/themes/Charisma/templates/profileedit.tpl b/www/themes/Charisma/templates/profileedit.tpl index dc275254c..cf72fee54 100755 --- a/www/themes/Charisma/templates/profileedit.tpl +++ b/www/themes/Charisma/templates/profileedit.tpl @@ -145,7 +145,7 @@ - {if $page->settings->getSetting('userselstyle') == 1} + {if $page->getSettingValue('..userselstyle') == 1} {html_options style="color: black;" id="style" name='style' values=$themelist output=$themelist selected=$user.style} {/if} @@ -170,7 +170,7 @@ function.
- {if $page->settings->getSetting('sabintegrationtype') != 1} + {if $page->getSettingValue('..sabintegrationtype') != 1} @@ -189,7 +189,7 @@
{/if} - {if $user.queuetype == 1 && $page->settings->getSetting('sabintegrationtype') == 2} + {if $user.queuetype == 1 && $page->getSettingValue('..sabintegrationtype') == 2} @@ -225,7 +225,7 @@
{/if} - {if $user.queuetype == 2 && ($page->settings->getSetting('sabintegrationtype') == 0 || $page->settings->getSetting('sabintegrationtype') == 2)} + {if $user.queuetype == 2 && ($page->getSettingValue('..sabintegrationtype') == 0 || $page->getSettingValue('..sabintegrationtype') == 2)} diff --git a/www/themes/Charisma/templates/viewqueue.tpl b/www/themes/Charisma/templates/viewqueue.tpl index acd7603cc..0e7256ad8 100755 --- a/www/themes/Charisma/templates/viewqueue.tpl +++ b/www/themes/Charisma/templates/viewqueue.tpl @@ -8,12 +8,12 @@ {if $error == ''} -{if $page->settings->getSetting('sabintegrationtype') > 0 || $user.queuetype == 2} +{if $page->getSettingValue('..sabintegrationtype') > 0 || $user.queuetype == 2}

The following queue is pulled from {$serverURL|escape:"htmlall"}.
- {if $page->settings->getSetting('sabintegrationtype') == 2 || $user.queuetype == 2}Edit your queue settings in + {if $page->getSettingValue('..sabintegrationtype') == 2 || $user.queuetype == 2}Edit your queue settings in your profile .{/if}

diff --git a/www/themes/Gamma/templates/profileedit.tpl b/www/themes/Gamma/templates/profileedit.tpl index ec2b27dcc..93266af91 100755 --- a/www/themes/Gamma/templates/profileedit.tpl +++ b/www/themes/Gamma/templates/profileedit.tpl @@ -52,11 +52,11 @@
Site Preferences - {if $page->settings->getSetting('userselstyle') == 1} + {if $page->getSettingValue('..userselstyle') == 1}
- {if $page->settings->getSetting('userselstyle') == 1} + {if $page->getSettingValue('..userselstyle') == 1} {html_options id="style" name='style' values=$themelist output=$themelist selected=$user.style} {/if}
@@ -112,8 +112,8 @@
- {if $page->settings->getSetting('sabintegrationtype') > 0} - {if $page->settings->getSetting('sabintegrationtype') != 1} + {if $page->getSettingValue('..sabintegrationtype') > 0} + {if $page->getSettingValue('..sabintegrationtype') != 1} Queue type (NZBget / Sabnzbd)
diff --git a/www/themes/Gamma/templates/viewqueue.tpl b/www/themes/Gamma/templates/viewqueue.tpl index acd7603cc..0e7256ad8 100755 --- a/www/themes/Gamma/templates/viewqueue.tpl +++ b/www/themes/Gamma/templates/viewqueue.tpl @@ -8,12 +8,12 @@
{if $error == ''} -{if $page->settings->getSetting('sabintegrationtype') > 0 || $user.queuetype == 2} +{if $page->getSettingValue('..sabintegrationtype') > 0 || $user.queuetype == 2}

The following queue is pulled from {$serverURL|escape:"htmlall"}.
- {if $page->settings->getSetting('sabintegrationtype') == 2 || $user.queuetype == 2}Edit your queue settings in + {if $page->getSettingValue('..sabintegrationtype') == 2 || $user.queuetype == 2}Edit your queue settings in your profile .{/if}

diff --git a/www/themes/Gentele/templates/profileedit.tpl b/www/themes/Gentele/templates/profileedit.tpl index 6271b1d31..fd5e6486f 100755 --- a/www/themes/Gentele/templates/profileedit.tpl +++ b/www/themes/Gentele/templates/profileedit.tpl @@ -144,7 +144,7 @@ @@ -169,7 +169,7 @@ function.
- {if $page->settings->getSetting('sabintegrationtype') != 1} + {if $page->getSettingValue('..sabintegrationtype') != 1}
- {if $page->settings->getSetting('userselstyle') == 1} + {if $page->getSettingValue('..userselstyle') == 1} {html_options id="style" name='style' values=$themelist output=$themelist selected=$user.style} {/if}
@@ -188,7 +188,7 @@
{/if} - {if $user.queuetype == 1 && $page->settings->getSetting('sabintegrationtype') == 2} + {if $user.queuetype == 1 && $page->getSettingValue('..sabintegrationtype') == 2} @@ -225,7 +225,7 @@
{/if} - {if $user.queuetype == 2 && ($page->settings->getSetting('sabintegrationtype') == 0 || $page->settings->getSetting('sabintegrationtype') == 2)} + {if $user.queuetype == 2 && ($page->getSettingValue('..sabintegrationtype') == 0 || $page->getSettingValue('..sabintegrationtype') == 2)} diff --git a/www/themes/Gentele/templates/viewqueue.tpl b/www/themes/Gentele/templates/viewqueue.tpl index 022119726..3d63b4177 100755 --- a/www/themes/Gentele/templates/viewqueue.tpl +++ b/www/themes/Gentele/templates/viewqueue.tpl @@ -9,12 +9,12 @@ {if $error == ''} - {if $page->settings->getSetting('sabintegrationtype') > 0 || $user.queuetype == 2} + {if $page->getSettingValue('..sabintegrationtype') > 0 || $user.queuetype == 2}

The following queue is pulled from {$serverURL|escape:"htmlall"}.
- {if $page->settings->getSetting('sabintegrationtype') == 2 || $user.queuetype == 2}Edit your queue settings in + {if $page->getSettingValue('..sabintegrationtype') == 2 || $user.queuetype == 2}Edit your queue settings in your profile .{/if}

@@ -67,4 +67,4 @@ {else}

{$error}

{/if} - \ No newline at end of file + diff --git a/www/themes/Omicron/templates/profileedit.tpl b/www/themes/Omicron/templates/profileedit.tpl index 991b8d2cf..026786dfd 100755 --- a/www/themes/Omicron/templates/profileedit.tpl +++ b/www/themes/Omicron/templates/profileedit.tpl @@ -145,7 +145,7 @@ @@ -170,7 +170,7 @@ function.
- {if $page->settings->getSetting('sabintegrationtype') != 1} + {if $page->getSettingValue('..sabintegrationtype') != 1}
- {if $page->settings->getSetting('userselstyle') == 1} + {if $page->getSettingValue('..userselstyle') == 1} {html_options id="style" name='style' values=$themelist output=$themelist selected=$user.style} {/if}
@@ -189,7 +189,7 @@
{/if} - {if $user.queuetype == 1 && $page->settings->getSetting('sabintegrationtype') == 2} + {if $user.queuetype == 1 && $page->getSettingValue('..sabintegrationtype') == 2} @@ -225,7 +225,7 @@
{/if} - {if $user.queuetype == 2 && ($page->settings->getSetting('sabintegrationtype') == 0 || $page->settings->getSetting('sabintegrationtype') == 2)} + {if $user.queuetype == 2 && ($page->getSettingValue('..sabintegrationtype') == 0 || $page->getSettingValue('..sabintegrationtype') == 2)} diff --git a/www/themes/Omicron/templates/viewqueue.tpl b/www/themes/Omicron/templates/viewqueue.tpl index acd7603cc..0e7256ad8 100755 --- a/www/themes/Omicron/templates/viewqueue.tpl +++ b/www/themes/Omicron/templates/viewqueue.tpl @@ -8,12 +8,12 @@ {if $error == ''} -{if $page->settings->getSetting('sabintegrationtype') > 0 || $user.queuetype == 2} +{if $page->getSettingValue('..sabintegrationtype') > 0 || $user.queuetype == 2}

The following queue is pulled from {$serverURL|escape:"htmlall"}.
- {if $page->settings->getSetting('sabintegrationtype') == 2 || $user.queuetype == 2}Edit your queue settings in + {if $page->getSettingValue('..sabintegrationtype') == 2 || $user.queuetype == 2}Edit your queue settings in your profile .{/if}