diff --git a/lib/DB/patches/0119~users.sql b/lib/DB/patches/0119~users.sql new file mode 100644 index 000000000..30d72451c --- /dev/null +++ b/lib/DB/patches/0119~users.sql @@ -0,0 +1,4 @@ +ALTER TABLE users ADD COLUMN style VARCHAR(255) NULL DEFAULT NULL; +/* Add a column to pick a site theme */ + +UPDATE `tmux` SET `value` = '119' WHERE `setting` = 'sqlpatch'; diff --git a/lib/copy_this/newznab/controllers/BasePage.php b/lib/copy_this/newznab/controllers/BasePage.php index 656e1e317..3316bdb04 100644 --- a/lib/copy_this/newznab/controllers/BasePage.php +++ b/lib/copy_this/newznab/controllers/BasePage.php @@ -66,13 +66,16 @@ class BasePage $this->smarty = new Smarty(); $this->captcha = new Captcha(['Settings' => $this->settings]); - if ($this->site->style != "default") - $this->smarty->addTemplateDir(WWW_DIR.'templates/'.$this->site->style.'/views/frontend', 'style_frontend'); - $this->smarty->addTemplateDir(WWW_DIR.'templates/default/views/frontend', 'frontend'); + $this->smarty->setTemplateDir( + array( + 'user_frontend' => NN_WWW . 'templates/' . $this->site->style . '/views/frontend', + 'frontend' => NN_WWW . 'templates/default/views/frontend' + ) + ); $this->smarty->setCompileDir(SMARTY_DIR.'templates_c'.DIRECTORY_SEPARATOR); $this->smarty->setConfigDir(SMARTY_DIR.'configs'.DIRECTORY_SEPARATOR); $this->smarty->setCacheDir(SMARTY_DIR.'cache'.DIRECTORY_SEPARATOR); - $this->smarty->error_reporting = (E_ALL - E_NOTICE); + $this->smarty->error_reporting = ((NN_DEBUG ? E_ALL : E_ALL - E_NOTICE)); $this->secure_connection = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) ; if (file_exists(WWW_DIR.'templates/'.$this->site->style.'/theme.php')) @@ -109,6 +112,16 @@ class BasePage $this->userdata["categoryexclusions"] = $this->users->getCategoryExclusion($this->users->currentUserId()); + // Change the theme to user's selected theme if they selected one, else use the admin one. + if (isset($this->userdata['style']) && $this->userdata['style'] !== 'None') { + $this->smarty->setTemplateDir( + array( + 'user_frontend' => NN_WWW . 'templates/' . $this->userdata['style'] . '/views/frontend', + 'frontend' => NN_WWW . 'templates/default/views/frontend' + ) + ); + } + //update lastlogin every 15 mins if (strtotime($this->userdata['now'])-900 > strtotime($this->userdata['lastlogin'])) $this->users->updateSiteAccessed($this->userdata['id']); diff --git a/lib/copy_this/newznab/controllers/Users.php b/lib/copy_this/newznab/controllers/Users.php index 6df4ad53c..b72097d28 100644 --- a/lib/copy_this/newznab/controllers/Users.php +++ b/lib/copy_this/newznab/controllers/Users.php @@ -47,7 +47,7 @@ class Users ]; $options += $defaults; - $this->pdo = ($options['Settings'] instanceof newznab\db\DB ? $options['Settings'] : new newznab\db\DB()); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->password_hash_cost = (defined('NN_PASSWORD_HASH_COST') ? NN_PASSWORD_HASH_COST : 11); } @@ -93,6 +93,19 @@ class Users return $db->query("select * from users"); } + /** + * Get the users selected theme. + * + * @param string|int $userID The id of the user. + * + * @return array|bool The users selected theme. + */ + public function getStyle($userID) + { + $row = $this->pdo->queryOneRow(sprintf("SELECT style FROM users WHERE id = %d", $userID)); + return ($row === false ? 'None' : $row['style']); + } + public function delete($id) { $db = new DB(); @@ -218,7 +231,7 @@ class Users return $res["num"]; } - public function update($id, $uname, $email, $grabs, $role, $notes, $invites, $movieview, $musicview, $gameview, $xxxview, $consoleview, $bookview, $queueType = '', $nzbgetURL = '', $nzbgetUsername = '', $nzbgetPassword = '', $saburl = '', $sabapikey = '', $sabpriority = '', $sabapikeytype = '', $nzbvortexServerUrl = false, $nzbvortexApiKey = false, $cp_url = false, $cp_api = false) + public function update($id, $uname, $email, $grabs, $role, $notes, $invites, $movieview, $musicview, $gameview, $xxxview, $consoleview, $bookview, $queueType = '', $nzbgetURL = '', $nzbgetUsername = '', $nzbgetPassword = '', $saburl = '', $sabapikey = '', $sabpriority = '', $sabapikeytype = '', $nzbvortexServerUrl = false, $nzbvortexApiKey = false, $cp_url = false, $cp_api = false, $style = 'None') { $db = new DB(); @@ -255,6 +268,7 @@ class Users $sql[] = sprintf('xxxview = %d', $xxxview); $sql[] = sprintf('consoleview = %d', $consoleview); $sql[] = sprintf('bookview = %d', $bookview); + $sql[] = sprintf('style = %s', $this->pdo->escapeString($style)); if ($queueType !== '') { $sql[] = sprintf('queuetype = %d', $queueType); diff --git a/lib/copy_this/www/admin/site-edit.php b/lib/copy_this/www/admin/site-edit.php index 76197897a..5b7d642f3 100644 --- a/lib/copy_this/www/admin/site-edit.php +++ b/lib/copy_this/www/admin/site-edit.php @@ -115,6 +115,8 @@ $page->smarty->assign('lookuptv_names', ['Disabled', 'Lookup All TV', 'Lookup Re $page->smarty->assign('lookup_reqids_ids', array(0,1,2)); $page->smarty->assign('lookup_reqids_names', array('Disabled', 'Lookup Request IDs', 'Lookup Request IDs Threaded')); +$page->smarty->assign('coversPath', NN_COVERS); + // return a list of audiobooks, mags, ebooks, technical and foreign books $result = $page->settings->query("SELECT id, title FROM category WHERE id in (3030, 7010, 7020, 7040, 7060)"); @@ -139,11 +141,13 @@ $books_selected = explode(",", $page->site->book_reqids); $books_selected = array_map(create_function('$value', 'return (int)$value;'), $books_selected); $page->smarty->assign('book_reqids_selected', $books_selected); -$themelist = array(); -$themes = scandir(WWW_DIR."/templates"); -foreach ($themes as $theme) - if (strpos($theme, ".") === false && is_dir(WWW_DIR."/templates/".$theme)) +$themelist = []; +$themes = scandir(NN_WWW . "/templates"); +foreach ($themes as $theme) { + if (strpos($theme, ".") === false && is_dir(NN_WWW . "/templates/" . $theme)) { $themelist[] = $theme; + } +} $page->smarty->assign('themelist', $themelist); diff --git a/lib/copy_this/www/pages/profileedit.php b/lib/copy_this/www/pages/profileedit.php index f0038e433..1c9b071a9 100644 --- a/lib/copy_this/www/pages/profileedit.php +++ b/lib/copy_this/www/pages/profileedit.php @@ -79,7 +79,8 @@ switch ($action) { (isset($_POST['nzbvortex_server_url']) ? $_POST['nzbvortex_server_url'] : false), (isset($_POST['nzbvortex_api_key']) ? $_POST['nzbvortex_api_key'] : false), $_POST['cp_url'], - $_POST['cp_api'] + $_POST['cp_api'], + $_POST['style'] ); $_POST['exccat'] = (!isset($_POST['exccat']) || !is_array($_POST['exccat'])) ? array() : $_POST['exccat']; @@ -99,6 +100,16 @@ switch ($action) { break; } +// Get the list of themes. +$themeList[] = 'None'; +$themes = scandir(NN_WWW . '/templates'); +foreach ($themes as $theme) { + if (strpos($theme, ".") === false && $theme[0] !== '_' && is_dir(NN_WWW . '/templates/' . $theme)) { + $themeList[] = $theme; + } +} + +$page->smarty->assign('themelist', $themeList); $page->smarty->assign('error', $errorStr); $page->smarty->assign('user', $data); diff --git a/lib/copy_this/www/templates/nntmux/views/frontend/profile.tpl b/lib/copy_this/www/templates/nntmux/views/frontend/profile.tpl index 4e8c3af79..8afd37fb1 100644 --- a/lib/copy_this/www/templates/nntmux/views/frontend/profile.tpl +++ b/lib/copy_this/www/templates/nntmux/views/frontend/profile.tpl @@ -7,6 +7,7 @@ Registered:{$user.createddate|date_format} ({$user.createddate|timeago} ago) Last Login:{$user.lastlogin|date_format} ({$user.lastlogin|timeago} ago) Role:{$user.rolename} + Theme:{$user.style} {if $userdata.role==2}Notes:{$user.notes|escape:htmlall}{if $user.notes|count_characters > 0}
{/if}Add/Edit{/if} {if $user.id==$userdata.id || $userdata.role==2}Site Api/Rss Key:{$user.rsstoken}{/if} {if $user.id==$userdata.id || $userdata.role==2} diff --git a/lib/copy_this/www/templates/nntmux/views/frontend/profileedit.tpl b/lib/copy_this/www/templates/nntmux/views/frontend/profileedit.tpl index ce0e217c7..d6a71cfec 100644 --- a/lib/copy_this/www/templates/nntmux/views/frontend/profileedit.tpl +++ b/lib/copy_this/www/templates/nntmux/views/frontend/profileedit.tpl @@ -42,6 +42,13 @@
Site Preferences + + + +
Site theme: + {html_options id="style" name='style' values=$themelist output=$themelist selected=$user.style} + Change the site theme, None will use the theme the administrator set. +
View Movie Page: diff --git a/run.php b/run.php index 01eda962b..cb81c6f4f 100644 --- a/run.php +++ b/run.php @@ -36,8 +36,8 @@ if (count($nntpkill) !== 0) { } // Check database patch version -if ($patch < 118) { - exit($c->error("\nYour database is not up to date. Please update.\nphp ${DIR}lib/DB/patchDB.php\n")); +if ($patch < 119) { + exit($c->error("\nYour database is not up to date. Please update.\nphp ${NN_WWW}lib/DB/patchDB.php\n")); } //check if session exists