From f8300a1ab1e220623bfa71732eee2036eb82992d Mon Sep 17 00:00:00 2001 From: Darko Date: Mon, 8 Jun 2015 09:29:27 +0200 Subject: [PATCH] Fix the content pages in admin area. (cherry picked from commit 8d59b44) --- newznab/controllers/BasePage.php | 24 +-- www/admin/content-add.php | 91 +++++----- www/admin/content-list.php | 12 +- .../nntmux/views/admin/content-add.tpl | 157 ++++++++---------- .../nntmux/views/admin/content-list.tpl | 93 +++++------ 5 files changed, 169 insertions(+), 208 deletions(-) diff --git a/newznab/controllers/BasePage.php b/newznab/controllers/BasePage.php index 4702170d5..5961ff95d 100644 --- a/newznab/controllers/BasePage.php +++ b/newznab/controllers/BasePage.php @@ -36,7 +36,6 @@ class BasePage public $smarty = ''; public $userdata = array(); public $serverurl = ''; - public $site = ''; public $secure_connection = false; @@ -58,19 +57,14 @@ class BasePage $this->stripSlashes($_COOKIE); } - // set site variable - $s = new Sites(); - $this->site = $s->get(); - $this->pdo = new Settings(); - // Buffer settings/DB connection. - $this->settings = new newznab\db\Settings(); + $this->settings = new Settings(); $this->smarty = new Smarty(); $this->captcha = new Captcha(['Settings' => $this->settings]); $this->smarty->setTemplateDir( array( - 'user_frontend' => NN_WWW . 'templates/' . $this->pdo->getSetting('style') . '/views/frontend', + 'user_frontend' => NN_WWW . 'templates/' . $this->settings->getSetting('style') . '/views/frontend', 'frontend' => NN_WWW . 'templates/default/views/frontend' ) ); @@ -80,8 +74,8 @@ class BasePage $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->pdo->getSetting('style').'/theme.php')) - require_once(WWW_DIR.'templates/'.$this->pdo->getSetting('style').'/theme.php'); + if (file_exists(WWW_DIR.'templates/'.$this->settings->getSetting('style').'/theme.php')) + require_once(WWW_DIR.'templates/'.$this->settings->getSetting('style').'/theme.php'); $this->smarty->assign('themevars', (isset($themevars) ? $themevars : null)); $servername = null; @@ -105,7 +99,7 @@ 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 ($this->pdo->getSetting('userselstyle') == 1) { + if ($this->settings->getSetting('userselstyle') == 1) { if (isset($this->userdata['style']) && $this->userdata['style'] !== 'None') { $this->smarty->setTemplateDir( array( @@ -145,9 +139,9 @@ class BasePage if ($this->userdata["hideads"] == "1") { - $this->pdo->setSetting(['adheader', '']); - $this->pdo->setSetting(['adbrowse', '']); - $this->pdo->setSetting(['addetail', '']); + $this->settings->setSetting(['adheader', '']); + $this->settings->setSetting(['adbrowse', '']); + $this->settings->setSetting(['addetail', '']); } $this->floodCheck($this->userdata["role"]); @@ -162,7 +156,7 @@ class BasePage } - $this->smarty->assign('site', $this->site); + $this->smarty->assign('site', $this->settings); $this->smarty->assign('page', $this); } diff --git a/www/admin/content-add.php b/www/admin/content-add.php index 6ed423d96..e184bbc29 100644 --- a/www/admin/content-add.php +++ b/www/admin/content-add.php @@ -1,68 +1,59 @@ $page->settings]); +$id = 0; + +// Set the current action. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view'; -switch($action) -{ - case 'add': - $page->title = "Content Add"; - $content = array(); - $content["showinmenu"] = "1"; - $content["status"] = "1"; - $content["contenttype"] = "2"; - $page->smarty->assign('content',$content); - break; +switch ($action) { + case 'add': + $page->title = "Content Add"; + $content = new Content(); + $content->showinmenu = "1"; + $content->status = "1"; + $content->contenttype = "2"; + $page->smarty->assign('content', $content); + break; - case 'submit': - // - // validate and add or update - // - $returnid = 0; - if (!isset($_POST["id"]) || $_POST["id"]=="") - { - $returnid = $contents->add($_POST); - } - else - { - $content = $contents->update($_POST); - $returnid = $_POST["id"]; - } - header("Location:content-add.php?id=".$returnid); + case 'submit': + // Validate and add or update. + $returnid = 0; + if (!isset($_POST["id"]) || $_POST["id"] == "") { + $returnid = $contents->add($_POST); + } else { + $content = $contents->update($_POST); + $returnid = $content->id; + } + header("Location:content-add.php?id=" . $returnid); + break; - break; - case 'view': - default: + case 'view': + default: + if (isset($_GET["id"])) { + $page->title = "Content Edit"; + $id = $_GET["id"]; - if (isset($_GET["id"])) - { - $page->title = "Content Edit"; - $id = $_GET["id"]; - - $content = $contents->getByID($id, Users::ROLE_ADMIN); - $page->smarty->assign('content', $content); - } - - break; + $content = $contents->getByID($id, Users::ROLE_ADMIN); + $page->smarty->assign('content', $content); + } + break; } -$page->smarty->assign('status_ids', array(1,0)); -$page->smarty->assign('status_names', array( 'Enabled', 'Disabled')); +$page->smarty->assign('status_ids', [1, 0]); +$page->smarty->assign('status_names', ['Enabled', 'Disabled']); -$page->smarty->assign('yesno_ids', array(1,0)); -$page->smarty->assign('yesno_names', array( 'Yes', 'No')); +$page->smarty->assign('yesno_ids', [1, 0]); +$page->smarty->assign('yesno_names', ['Yes', 'No']); -$contenttypelist = array("1" => "Useful Link", "2" => "Article", "3" => "Homepage"); +$contenttypelist = ["1" => "Useful Link", "2" => "Article", "3" => "Homepage"]; $page->smarty->assign('contenttypelist', $contenttypelist); -$rolelist = array("0" => "Everyone", "1" => "Logged in Users", "2" => "Admins"); +$rolelist = ["0" => "Everyone", "1" => "Logged in Users", "2" => "Admins"]; $page->smarty->assign('rolelist', $rolelist); $page->content = $page->smarty->fetch('content-add.tpl'); -$page->render(); +$page->render(); \ No newline at end of file diff --git a/www/admin/content-list.php b/www/admin/content-list.php index 0432fa6e8..48d230d53 100644 --- a/www/admin/content-list.php +++ b/www/admin/content-list.php @@ -1,15 +1,13 @@ $page->settings]); $contentlist = $contents->getAll(); -$page->smarty->assign('contentlist',$contentlist); +$page->smarty->assign('contentlist', $contentlist); $page->title = "Content List"; $page->content = $page->smarty->fetch('content-list.tpl'); -$page->render(); - +$page->render(); \ No newline at end of file diff --git a/www/templates/nntmux/views/admin/content-add.tpl b/www/templates/nntmux/views/admin/content-add.tpl index 411de1c59..d3e1e7410 100644 --- a/www/templates/nntmux/views/admin/content-add.tpl +++ b/www/templates/nntmux/views/admin/content-add.tpl @@ -1,89 +1,74 @@ -

{$page->title}

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
: - - -
: - -
: - -
: - -
: - -
: - {html_options id="contenttype" name='contenttype' options=$contenttypelist selected=$content.contenttype} -
: - {html_options id="role" name='role' options=$rolelist selected=$content.role} -
Only appropriate for articles and useful links
-
: - {html_radios id="showinmenu" name='showinmenu' values=$yesno_ids output=$yesno_names selected=$content.showinmenu separator='
'} -
: - {html_radios id="status" name='status' values=$status_ids output=$status_names selected=$content.status separator='
'} -
: - -
- -
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ +
+ +
+ +
+ +
+ {html_options id="contenttype" name='contenttype' options=$contenttypelist selected=$content->contenttype} +
+ {html_options id="role" name='role' options=$rolelist selected=$content->role} +
Only appropriate for articles and useful links
+
+ {html_radios id="showinmenu" name='showinmenu' values=$yesno_ids output=$yesno_names selected=$content->showinmenu separator='
'} +
+ {html_radios id="status" name='status' values=$status_ids output=$status_names selected=$content->status separator='
'} +
+ +
If you set the ordinal = 1, then a all ordinals greater than 0 will be renumbered. This allows new content to be at the top without having to renumber all previous content.
If you set ordinal = 0, it will be at the top, sorted by ID(order added)
+
+ +
\ No newline at end of file diff --git a/www/templates/nntmux/views/admin/content-list.tpl b/www/templates/nntmux/views/admin/content-list.tpl index 285f56886..f55ac1d33 100644 --- a/www/templates/nntmux/views/admin/content-list.tpl +++ b/www/templates/nntmux/views/admin/content-list.tpl @@ -1,11 +1,8 @@ -

{$page->title}

- - - - + + @@ -15,50 +12,46 @@ - - {foreach from=$contentlist item=content} - - - - - - - - - - - - + + + + + + + + + + + + {/foreach} - - -
ordinalidordinalid title url typebody options
{$content.ordinal}{$content.id}{$content.title}/content/{$content.id}{$content.url} - {if $content.contenttype == "1"} - Useful Link - {elseif $content.contenttype == "2"} - Article - {elseif $content.contenttype == "3"} - Homepage - {/if} - - {if $content.status == "1"} - Enabled - {else} - Disabled - {/if} - - {if $content.role == "0"} - Everyone - {elseif $content.role == "1"} - Users - {elseif $content.role == "2"} - Admins - {/if} - - {if $content.showinmenu == "1"} - Yes - {else} - No - {/if} - {$content.body|truncate:100|escape:'htmlall'}{if $content.contenttype != "3"}delete{/if}
{$content->ordinal}{$content->id}{$content->title}{$content->url}c{$content->id} + {if $content->contenttype == "1"} + Useful Link + {elseif $content->contenttype == "2"} + Article + {elseif $content->contenttype == "3"} + Homepage + {/if} + + {if $content->status == "1"} + Enabled + {else} + Disabled + {/if} + + {if $content->role == "0"} + Everyone + {elseif $content->role == "1"} + Users + {elseif $content->role == "2"} + Admins + {/if} + + {if $content->showinmenu == "1"} + Yes + {else} + No + {/if} + {$content->body|truncate:100|escape:'htmlall'}{if $content->contenttype != "3"}delete{/if}
+ \ No newline at end of file