X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=nucleus%2Flibs%2FADMIN.php;h=8fa73100c7d9987f044e92d49dfb4b66fee2b793;hb=c4a6f69c983f5f173cb346b96f446ae725d27c19;hp=1c0ab0f1899db5d4a197105cd2c4d6051383366e;hpb=f94a3aae08a0d625bf32364739cb161ceefb8bd5;p=nucleus-jp%2Fnucleus-next.git diff --git a/nucleus/libs/ADMIN.php b/nucleus/libs/ADMIN.php index 1c0ab0f..8fa7310 100644 --- a/nucleus/libs/ADMIN.php +++ b/nucleus/libs/ADMIN.php @@ -15,759 +15,692 @@ * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2012 The Nucleus Group * @version $Id: ADMIN.php 1661 2012-02-12 11:55:39Z sakamocchi $ - * */ if ( !function_exists('requestVar') ) exit; require_once dirname(__FILE__) . '/showlist.php'; -/** - * Builds the admin area and executes admin actions - */ class Admin { - private $xml_version_info = '1.0'; - private $formal_public_identifier = '-//W3C//DTD XHTML 1.0 Strict//EN'; - private $system_identifier = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'; - private $xhtml_namespace = 'http://www.w3.org/1999/xhtml'; - - /** - * @var string $action action currently being executed ($action=xxxx -> action_xxxx method) - */ - public $action; - - /** - * @var object $adminSkin - */ - public $adminSkin; + static private $xml_version_info = '1.0'; + static private $formal_public_identifier = '-//W3C//DTD XHTML 1.0 Strict//EN'; + static private $system_identifier = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'; + static private $xhtml_namespace = 'http://www.w3.org/1999/xhtml'; - /** - * @var string $extrahead - */ - public $extrahead; + static public $headMess; + static private $action; + static private $skin; + static private $passvar; + static private $aOptions; + + static public $extrahead; + static public $blog; + static public $contents; + /** - * @var bool $passvar - */ - public $passvar; - + * Admin::$edit_actions + */ + static private $edit_actions = array( + 'adminskinoverview', + 'adminskinieoverview', + 'adminskinedittype', + 'adminskinremovetype', + 'adminskindelete', + 'adminskinedit', + 'adminskinieimport', + 'adminskiniedoimport', + 'admintemplateedit', + 'admintemplateoverview', + 'admintemplatedelete' + ); + /** - * @var string $headMess - */ - public $headMess; - - public $aOptions; + * Admin::$skinless_actions + */ + static private $skinless_actions = array( + 'plugindeleteconfirm', + 'pluginoptionsupdate', + 'skinremovetypeconfirm', + 'skinclone', + 'skindeleteconfirm', + 'skinnew', + 'skineditgeneral', + 'skinieexport', + 'skinupdate', + 'templateupdate', + 'templatedeleteconfirm', + 'templatenew', + 'templateclone', + 'adminskinremovetypeconfirm', + 'adminskinclone', + 'adminskindeleteconfirm', + 'adminskinnew', + 'adminskineditgeneral', + 'adminskinieexport', + 'adminskinupdate', + 'admintemplateupdate', + 'admintemplatedeleteconfirm', + 'admintemplatenew', + 'admintemplateclone', + 'blogsettingsupdate', + 'settingsupdate', + 'addnewlog2', + 'additem', + 'itemdeleteconfirm', + 'itemupdate', + 'changemembersettings', + 'clearactionlog', + 'memberedit' + ); - /** - * Class constructor - */ - /* function ADMIN() { - } */ - function __construct() - { - global $member, $DIR_LIBS; - $query = 'SELECT ' - . ' COUNT(*) as result ' - . 'FROM ' - . sql_table('adminskin_desc'); - if ( !(quickQuery($query)) ) - { - $this->action_importAdmin(); - } - if ( !isset($adminSkinid) || !($adminSkinid) ) - { - $adminSkinid = self::getAdminSkinID(); - } - if ( Skin::existsID($adminSkinid) ) - { - $this->adminSkin = new Skin($adminSkinid); - } - else - { - $this->adminSkin = 0; - } - } + static private $actions_needless_to_check = array( + 'showlogin', + 'login', + 'overview', + 'itemlist', + 'blogcommentlist', + 'bookmarklet', + 'blogsettings', + 'banlist', + 'createaccount', + 'deleteblog', + 'editmembersettings', + 'createaccount', + 'forgotpassword', + 'browseowncomments', + 'createitem', + 'itemedit', + 'itemmove', + 'categoryedit', + 'categorydelete', + 'manage', + 'actionlog', + 'settingsedit', + 'backupoverview', + 'pluginlist', + 'createnewlog', + 'usermanagement', + 'skinoverview', + 'templateoverview', + 'skinieoverview', + 'itemcommentlist', + 'commentedit', + 'commentdelete', + 'banlistnewfromitem', + 'banlistdelete', + 'itemdelete', + 'manageteam', + 'teamdelete', + 'banlistnew', + 'memberedit', + 'memberdelete', + 'pluginhelp', + 'pluginoptions', + 'plugindelete', + 'skinedittype', + 'skinremovetype', + 'skindelete', + 'skinedit', + 'templateedit', + 'templatedelete', + 'activate', + 'systemoverview', + 'activatesetpwd', + ); - static private function getAdminSkinID() + static public function initialize() { - global $CONF, $member, $manager; - if (isset($member) && $member->isLoggedIn()) { + global $CONF, $DIR_LIBS, $manager; + + /* NOTE: 1. decide which skinid to use */ + $skinid = $CONF['AdminSkin']; + /* + * NOTE: this is temporary escaped because not implemented yet + if (isset($member) && $member->isLoggedIn()) + { $memskin = $member->getAdminSkin(); - if ($memskin) { - return $memskin; + if ( $memskin ) + { + $skinid = $memskin; } } - return $CONF['DefaultAdminSkin']; - } - - function getAdminskinEditActions() - { - return array( - 'adminskinoverview', - 'adminskinieoverview', - 'adminskinedittype', - 'adminskinremovetype', - 'adminskindelete', - 'adminskinedit', - 'adminskinieimport', - 'adminskiniedoimport', - 'admintemplateedit', - 'admintemplateoverview', - 'admintemplatedelete', - ); - } - - function getSkinlessActions() - { - return array( - 'plugindeleteconfirm', - 'pluginoptionsupdate', - 'skinremovetypeconfirm', - 'skinclone', - 'skindeleteconfirm', - 'skinnew', - 'skineditgeneral', - 'skinieexport', - 'skinupdate', - 'templateupdate', - 'templatedeleteconfirm', - 'templatenew', - 'templateclone', - 'adminskinremovetypeconfirm', - 'adminskinclone', - 'adminskindeleteconfirm', - 'adminskinnew', - 'adminskineditgeneral', - 'adminskinieexport', - 'adminskinupdate', - 'admintemplateupdate', - 'admintemplatedeleteconfirm', - 'admintemplatenew', - 'admintemplateclone', - 'blogsettingsupdate', - 'settingsupdate', - 'addnewlog2', - 'additem', - 'itemdeleteconfirm', - 'itemupdate', - 'changemembersettings', - 'clearactionlog', - 'memberedit', - ); + */ + + /* NOTE: 2. make an instance of skin object */ + if ( !Skin::existsID($skinid) ) + { + return FALSE; + } + + /* NOTE: 3. initializing each members */ + self::$skin =& $manager->getSkin($skinid, 'AdminActions', 'AdminSkin'); + self::$action = ''; + self::$extrahead = ''; + self::$passvar = ''; + self::$headMess = ''; + self::$aOptions = ''; + return TRUE; } /** + * Admin::action() * Executes an action * - * @param string $action action to be performed + * @param string $action action to be performed + * @return void */ - function action($action) + static public function action($action) { - global $CONF, $manager; - $f = false; + global $CONF, $DIR_LIBS, $manager, $member; - // list of action aliases - $alias = array( - 'login' => 'overview', - '' => 'overview' - ); - + /* 1. decide action name */ $customAction = postvar('customaction'); if ( !empty($customAction) ) { $alias = array( - 'login' => $customAction, - '' => $customAction + 'login' => $customAction, + '' => $customAction + ); + } + else + { + $alias = array( + 'login' => 'overview', + '' => 'overview', ); } - if ( isset($alias[$action]) ) + if ( array_key_exists($action, $alias) && isset($alias[$action]) ) { $action = $alias[$action]; } - $methodName = 'action_' . $action; - - $this->action = strtolower($action); - - // check ticket. All actions need a ticket, unless they are considered to be safe (a safe action - // is an action that requires user interaction before something is actually done) - // all safe actions are in this array: - $aActionsNotToCheck = array( - 'showlogin', - 'login', - 'overview', - 'itemlist', - 'blogcommentlist', - 'bookmarklet', - 'blogsettings', - 'banlist', - 'deleteblog', - 'editmembersettings', - 'browseownitems', - 'browseowncomments', - 'createitem', - 'itemedit', - 'itemmove', - 'categoryedit', - 'categorydelete', - 'manage', - 'actionlog', - 'settingsedit', - 'backupoverview', - 'pluginlist', - 'createnewlog', - 'usermanagement', - 'skinoverview', - 'templateoverview', - 'skinieoverview', - 'itemcommentlist', - 'commentedit', - 'commentdelete', + $methodName = "action_{$action}"; + self::$action = strtolower($action); + + /* 2. check the action */ + $synonimActions = array( 'banlistnewfromitem', - 'banlistdelete', - 'itemdelete', - 'manageteam', - 'teamdelete', - 'banlistnew', 'memberedit', - 'memberdelete', - 'pluginhelp', - 'pluginoptions', - 'plugindelete', - 'skinedittype', - 'skinremovetype', - 'skindelete', - 'skinedit', - 'templateedit', - 'templatedelete', - 'activate', - 'systemoverview', - 'activatesetpwd', + 'login', ); - $synonimActions = array( - 'banlistnewfromitem', - 'memberedit', - 'login', - ); -/* - // the rest of the actions needs to be checked - $aActionsToCheck = array('additem', 'itemupdate', 'itemmoveto', 'categoryupdate', 'categorydeleteconfirm', 'itemdeleteconfirm', 'commentdeleteconfirm', 'teamdeleteconfirm', 'memberdeleteconfirm', 'templatedeleteconfirm', 'skindeleteconfirm', 'banlistdeleteconfirm', 'plugindeleteconfirm', 'batchitem', 'batchcomment', 'batchmember', 'batchcategory', 'batchteam', 'regfile', 'commentupdate', 'banlistadd', 'changemembersettings', 'clearactionlog', 'settingsupdate', 'blogsettingsupdate', 'categorynew', 'teamchangeadmin', 'teamaddmember', 'memberadd', 'addnewlog', 'addnewlog2', 'backupcreate', 'backuprestore', 'pluginup', 'plugindown', 'pluginupdate', 'pluginadd', 'pluginoptionsupdate', 'skinupdate', 'skinclone', 'skineditgeneral', 'templateclone', 'templatenew', 'templateupdate', 'skinieimport', 'skinieexport', 'skiniedoimport', 'skinnew', 'deleteblogconfirm', 'activatesetpwd'); -*/ - $adminskinEditActions = $this->getAdminskinEditActions(); - $skinLessActions = $this->getSkinlessActions(); - $allowActions = array_merge($synonimActions, $this->getSkinlessActions()); - $aActionsNotToCheck = array_merge($aActionsNotToCheck, $adminskinEditActions, $allowActions); - if (!in_array($this->action, $aActionsNotToCheck) && !$this->existsSkinContents($action) ) + $allowActions = array_merge($synonimActions, self::$skinless_actions); + $aActionsNotToCheck = array_merge(self::$actions_needless_to_check, self::$edit_actions, $allowActions); + if ( !in_array(self::$action, $aActionsNotToCheck) && !self::existsSkinContents($action) ) { if (!$manager->checkTicket()) { - $this->error(_ERROR_BADTICKET); + self::error(_ERROR_BADTICKET); } } - if ( !$this->adminSkin && $CONF['DefaultAdminSkin'] ) - { - $this->adminSkin = new Skin($CONF['DefaultAdminSkin']); - } - - if ( !method_exists($this, $methodName) && !in_array($this->action, $allowActions) && $this->existsSkinContents($action) ) + + /* 3. parse according to the action */ + if ( !method_exists('Admin', $methodName) && !in_array(self::$action, $allowActions) && self::existsSkinContents($action) ) { - $this->action_parseSpecialskin; - $f = true; + /* TODO: what is this? + self::action_parseSpecialskin(); + */ } - elseif ( method_exists($this, $methodName) ) + elseif ( method_exists('Admin', $methodName) ) { - call_user_func(array(&$this, $methodName)); - $f = true; - } - if ($f) { - exit; + call_user_func(array(__CLASS__, $methodName)); } - $id = self::getAdminSkinID(); - $this->adminSkin = new Skin($id); - if ( $this->adminSkin && $this->existsSkinContents('adminerrorpage') ) + else if ( self::existsSkinContents('adminerrorpage') ) { - $this->error(_BADACTION . ENTITY::hsc($action)); - $f = true; + self::error(_BADACTION . ENTITY::hsc($action)); } - elseif ( $id != $CONF['DefaultAdminSkin'] ) + elseif ( $id != $CONF['AdminSkin'] ) { - $this->adminSkin = new Skin($CONF['DefaultAdminSkin']); - if ( $this->adminSkin && $this->existsSkinContents('adminerrorpage') ) + self::$skin =& $manager->getSkin($CONF['AdminSkin'], 'AdminActions'); + if ( self::$skin && self::existsSkinContents('adminerrorpage') ) { - $this->error(_BADACTION . ENTITY::hsc($action)); - $f = true; + self::error(_BADACTION . ENTITY::hsc($action)); } } - if ($f) + else { - exit; + self::error(_BADACTION . ENTITY::hsc($action)); } - $this->error(_BADACTION . ENTITY::hsc($action)); + exit; } - + /** + * Action::existsSkinContents() * Check skin contents * - * @param string action type - * @return bool + * @param string $action action type + * @return boolean */ - function existsSkinContents($action) + static private function existsSkinContents($action) { - $nsActions = $this->getSkinlessActions(); - $in_array = in_array($action, $nsActions); - if ($in_array) { + $in_array = in_array($action, self::$skinless_actions); + + if ( $in_array ) + { return $in_array; - } else { - $query = 'SELECT ' - . ' scontent as result ' - . 'FROM ' - . sql_table('adminskin') . ' ' - . 'WHERE ' - . ' sdesc = %d ' - . 'AND stype = "%s"'; - if ( is_object($this->adminSkin) ) + } + else + { + $query = "SELECT scontent as result FROM %s WHERE sdesc=%d AND stype=%s"; + /* TODO: skinid should be a default */ + if ( !is_object(self::$skin) ) { - return quickQuery(sprintf($query, $this->adminSkin->id, sql_real_escape_string($action))); + global $CONF; + return DB::getValue(sprintf($query, sql_table('skin'), $CONF['AdminSkin'], DB::quoteValue($action))); } else { - return quickQuery(sprintf($query, 1, sql_real_escape_string($action))); + return DB::getValue(sprintf($query, sql_table('skin'), self::$skin->getID(), DB::quoteValue($action))); } } + return; } /** + * Action::specialActionsAllow() * Check exists specialskinparts * - * @param string action type - * @return bool + * @param string $action action type + * @return boolean */ - function specialActionsAllow($action) + static private function specialActionsAllow($action) { - $query = 'SELECT ' - . ' sdesc as result ' - . 'FROM ' - . sql_table('adminskin') . ' ' - . 'WHERE ' - . ' sdesc = %d ' - . 'AND stype = "%s"'; - return quickQuery(sprintf($query, $this->adminSkin->id, sql_real_escape_string($action))); + $query = "SELECT sdesc as result FROM %s WHERE sdesc = %d AND stype = %s"; + $query = sprintf($query, sql_table('skin'), (integer) self::$skin->id, DB::quoteValue($action)); + return DB::getValue($query); } /** - * @todo document this + * Action::action_showlogin() + * + * @param void + * @return void */ - function action_showlogin() + static private function action_showlogin() { global $error; - $this->action_login($error); + self::action_login($error); + return; } - + /** - * @todo document this + * Action::action_login() + * + * @param string $msg message for pageheader + * @param integer $passvars ??? */ - function action_login($msg = '', $passvars = 1) + static private function action_login($msg = '', $passvars = 1) { global $member; - + // skip to overview when allowed if ( $member->isLoggedIn() && $member->canLogin() ) { - $this->action_overview(); + self::action_overview(); exit; } - - $this->passvar = $passvars; + + /* TODO: needless variable??? */ + self::$passvar = $passvars; if ( $msg ) { - $this->headMess = $msg; + self::$headMess = $msg; } - - $this->pagehead(); - $this->parse('showlogin'); - $this->pagefoot(); + + self::$skin->parse('showlogin'); } - + /** + * Action::action_overview() * provides a screen with the overview of the actions available - * @todo document parameter + * + * @param string $msg message for pageheader + * @return void */ - function action_overview($msg = '') + static private function action_overview($msg = '') { if ( $msg ) { - $this->headMess = $msg; + self::$headMess = $msg; } - - $this->pagehead(); - $this->parse('overview'); - $this->pagefoot(); + + self::$skin->parse('overview'); + return; } - + /** - * @todo document this + * Admin::action_manage() + * + * @param string $msg message for pageheader + * @retrn void */ - function action_manage($msg = '') + static private function action_manage($msg = '') { global $member; - + if ( $msg ) { - $this->headMess = $msg; + self::$headMess = $msg; } - $member->isAdmin() or $this->disallow(); - - $this->pagehead(); - $this->parse('manage'); - $this->pagefoot(); + $member->isAdmin() or self::disallow(); + + self::$skin->parse('manage'); + return; } - + /** - * @todo document this + * Action::action_itemlist() + * + * @param integer id for weblod + * @return void */ - function action_itemlist($blogid = '') + static private function action_itemlist($blogid = '') { global $member, $manager, $CONF; - + if ( $blogid == '' ) { $blogid = intRequestVar('blogid'); } - - $member->teamRights($blogid) or $member->isAdmin() or $this->disallow(); - - $this->pagehead(); - $this->parse('itemlist'); - $this->pagefoot(); + + $member->teamRights($blogid) or $member->isAdmin() or self::disallow(); + + self::$skin->parse('itemlist'); + return; } - + /** - * @todo document this + * Action::action_batchitem() + * + * @param void + * @return void */ - function action_batchitem() + static private function action_batchitem() { global $member, $manager; - - // check if logged in - $member->isLoggedIn() or $this->disallow(); - - // more precise check will be done for each performed operation - - // get array of itemids from request - $selected = requestIntArray('batch'); - $action = requestVar('batchaction'); - - // Show error when no items were selected + + $member->isLoggedIn() or self::disallow(); + + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); + if ( !is_array($selected) || sizeof($selected) == 0 ) { - $this->error(_BATCH_NOSELECTION); + self::error(_BATCH_NOSELECTION); } - + // On move: when no destination blog/category chosen, show choice now $destCatid = intRequestVar('destcatid'); if ( ($action == 'move') && (!$manager->existsCategory($destCatid)) ) { - $this->batchMoveSelectDestination('item', $selected); + self::batchMoveSelectDestination('item', $selected); } - + // On delete: check if confirmation has been given if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) { - $this->batchAskDeleteConfirmation('item',$selected); + self::batchAskDeleteConfirmation('item', $selected); } - - $this->pagehead(); - $this->parse('batchitem'); - $this->pagefoot(); + + self::$skin->parse('batchitem'); + return; } - + /** - * @todo document this + * Action::action_batchcomment() + * + * @param void + * @return void */ - function action_batchcomment() + static private function action_batchcomment() { global $member; - - // check if logged in - $member->isLoggedIn() or $this->disallow(); - - // more precise check will be done for each performed operation - - // get array of itemids from request - $selected = requestIntArray('batch'); - $action = requestVar('batchaction'); - + + $member->isLoggedIn() or self::disallow(); + + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); + // Show error when no items were selected if ( !is_array($selected) || sizeof($selected) == 0 ) { - $this->error(_BATCH_NOSELECTION); + self::error(_BATCH_NOSELECTION); } - + // On delete: check if confirmation has been given if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) { - $this->batchAskDeleteConfirmation('comment',$selected); + self::batchAskDeleteConfirmation('comment', $selected); } - - $this->pagehead(); - $this->parse('batchcomment'); - $this->pagefoot(); + + self::$skin->parse('batchcomment'); + return; } - + + /** + * Admin::setAdminAction() + * + * @param string $action + * @return void + */ + static public function setAdminAction($action) + { + self::$action = $action; + return; + } + /** - * @todo document this + * Admin::action_batchmember() + * + * @param void + * @return void */ - function action_batchmember() + static private function action_batchmember() { global $member; - - // check if logged in and admin - ($member->isLoggedIn() && $member->isAdmin()) or $this->disallow(); - - // get array of itemids from request - $selected = requestIntArray('batch'); - $action = requestVar('batchaction'); - + + ($member->isLoggedIn() && $member->isAdmin()) or self::disallow(); + + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); + // Show error when no members selected if ( !is_array($selected) || sizeof($selected) == 0 ) { - $this->error(_BATCH_NOSELECTION); + self::error(_BATCH_NOSELECTION); } - + // On delete: check if confirmation has been given if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) { - $this->batchAskDeleteConfirmation('member',$selected); + self::batchAskDeleteConfirmation('member',$selected); } - - $this->pagehead(); - $this->parse('batchmember'); - $this->pagefoot(); + + self::$skin->parse('batchmember'); + return; } - + /** - * @todo document this + * Admin::action_batchteam() + * + * @param void + * @return void */ - function action_batchteam() + static private function action_batchteam() { global $member; - + $blogid = intRequestVar('blogid'); - - // check if logged in and admin - ($member->isLoggedIn() && $member->blogAdminRights($blogid)) or $this->disallow(); - - // get array of itemids from request - $selected = requestIntArray('batch'); - $action = requestVar('batchaction'); - - // Show error when no members selected + + ($member->isLoggedIn() && $member->blogAdminRights($blogid)) or self::disallow(); + + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); + if ( !is_array($selected) || sizeof($selected) == 0 ) { - $this->error(_BATCH_NOSELECTION); + self::error(_BATCH_NOSELECTION); } - + // On delete: check if confirmation has been given if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) { - $this->batchAskDeleteConfirmation('team',$selected); + self::batchAskDeleteConfirmation('team',$selected); } - - $this->pagehead(); - $this->parse('batchmember'); - $this->pagefoot(); + + self::$skin->parse('batchteam'); + return; } - + /** - * @todo document this + * Admin::action_batchcategory() + * + * @param void + * @return void */ - function action_batchcategory() + static private function action_batchcategory() { global $member, $manager; - - // check if logged in - $member->isLoggedIn() or $this->disallow(); - - // more precise check will be done for each performed operation - - // get array of itemids from request - $selected = requestIntArray('batch'); - $action = requestVar('batchaction'); - - // Show error when no items were selected + + $member->isLoggedIn() or self::disallow(); + + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); + if ( !is_array($selected) || sizeof($selected) == 0 ) { - $this->error(_BATCH_NOSELECTION); + self::error(_BATCH_NOSELECTION); } - + // On move: when no destination blog chosen, show choice now $destBlogId = intRequestVar('destblogid'); if ( ($action == 'move') && (!$manager->existsBlogID($destBlogId)) ) { - $this->batchMoveCategorySelectDestination('category', $selected); + self::batchMoveCategorySelectDestination('category', $selected); } - + // On delete: check if confirmation has been given if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) { - $this->batchAskDeleteConfirmation('category', $selected); + self::batchAskDeleteConfirmation('category', $selected); } - - $this->pagehead(); - $this->parse('batchcategory'); - $this->pagefoot(); + + self::$skin->parse('batchcategory'); + return; } - + /** - * @todo document this + * Admin::batchMoveSelectDestination() + * + * @param string $type type of batch action + * @param integer $ids needless??? + * @return void + * + * TODO: remove needless argument */ - function batchMoveSelectDestination($type, $ids) + static private function batchMoveSelectDestination($type, $ids) { - $this->pagehead(); - $this->parse('batchmove'); - $this->pagefoot(); - exit; + $_POST['batchmove'] = $type; + self::$skin->parse('batchmove'); + return; } - + /** - * @todo document this + * Admin::batchMoveCategorySelectDestination() + * + * @param string $type type of batch action + * @param integer $ids needless??? + * @return void + * + * TODO: remove needless argument */ - function batchMoveCategorySelectDestination($type, $ids) + static private function batchMoveCategorySelectDestination($type, $ids) { + $_POST['batchmove'] = $type; global $manager; - $this->pagehead(); - $this->parse('batchmovecat'); - $this->pagefoot(); - exit; + self::$skin->parse('batchmovecat'); + return; } - + /** - * @todo document this + * Admin::batchAskDeleteConfirmation() + * + * @param string $type type of batch action + * @param integer $ids needless??? + * @return void + * + * TODO: remove needless argument */ - function batchAskDeleteConfirmation($type, $ids) + static private function batchAskDeleteConfirmation($type, $ids) { - $this->pagehead(); - $this->parse('batchdelete'); - $this->pagefoot(); - exit; + self::$skin->parse('batchdelete'); + return; } - - + /** - * Inserts a HTML select element with choices for all categories to which the current - * member has access - * @see function selectBlog + * Admin::action_browseownitems() + * + * @param void + * @return void */ - function selectBlogCategory($name, $selected = 0, $tabindex = 0, $showNewCat = 0, $iForcedBlogInclude = -1) + static private function action_browseownitems() { - Admin::selectBlog($name, 'category', $selected, $tabindex, $showNewCat, $iForcedBlogInclude); + global $member, $manager, $CONF; + + self::$skin->parse('browseownitems'); + return; } - + /** - * Inserts a HTML select element with choices for all blogs to which the user has access - * mode = 'blog' => shows blognames and values are blogids - * mode = 'category' => show category names and values are catids - * - * @param $iForcedBlogInclude - * ID of a blog that always needs to be included, without checking if the - * member is on the blog team (-1 = none) - * @todo document parameters + * Admin::action_itemcommentlist() + * Show all the comments for a given item + * + * @param integer $itemid ID for item + * @return void */ - function selectBlog($name, $mode='blog', $selected = 0, $tabindex = 0, $showNewCat = 0, $iForcedBlogInclude = -1) + static private function action_itemcommentlist($itemid = '') { - global $member, $CONF; - - // 0. get IDs of blogs to which member can post items (+ forced blog) - $aBlogIds = array(); - if ( $iForcedBlogInclude != -1 ) - { - $aBlogIds[] = intval($iForcedBlogInclude); - } - - if ( ($member->isAdmin()) && ($CONF['ShowAllBlogs']) ) - { - $queryBlogs = 'SELECT bnumber FROM '.sql_table('blog').' ORDER BY bname'; - } - else - { - $queryBlogs = 'SELECT bnumber FROM '.sql_table('blog').', '.sql_table('team').' WHERE tblog=bnumber and tmember=' . $member->getID(); - } - $rblogids = sql_query($queryBlogs); - while ($o = sql_fetch_object($rblogids)) - { - if ( $o->bnumber != $iForcedBlogInclude ) - { - $aBlogIds[] = intval($o->bnumber); - } - } - - if ( count($aBlogIds) == 0 ) - { - return; - } - - $_REQUEST['selectData'] = array( - 'name' => $name, - 'tabindex' => $tabindex, - 'mode' => $mode, - 'selected' => $selected, - 'showNewCat' => $showNewCat, - 'aBlogIds' => $aBlogIds, - ); - $this->parse('blogselectbox'); - } - - /** - * @todo document this - */ - function action_browseownitems() { global $member, $manager, $CONF; - - $this->pagehead(); - $this->parse('browseownitems'); - $this->pagefoot(); - } - - /** - * Show all the comments for a given item - * @param int $itemid - */ - function action_itemcommentlist($itemid = '') { - global $member, $manager, $CONF; - + if ( $itemid == '' ) { $itemid = intRequestVar('itemid'); } - $_REQUEST['itemid'] = $itemid; - $_REQUEST['blogid'] = getBlogIdFromItemId($itemid); // only allow if user is allowed to alter item - $member->canAlterItem($itemid) or $this->disallow(); - - $blogid = getBlogIdFromItemId($itemid); - - $this->pagehead(); - $this->parse('itemcommentlist'); - $this->pagefoot(); + $member->canAlterItem($itemid) or self::disallow(); + + $item =& $manager->getItem($itemid, 1, 1); + $_REQUEST['itemid'] = $item['itemid']; + $_REQUEST['blogid'] = $item['blogid']; + + self::$skin->parse('itemcommentlist'); + return; } - + /** + * Admin::action_browseowncomments() * Browse own comments + * + * @param void + * @return void */ - function action_browseowncomments() { - $this->pagehead(); - $this->parse('browseowncomments'); - $this->pagefoot(); + static private function action_browseowncomments() + { + self::$skin->parse('browseowncomments'); + return; } - + /** + * Admin::action_blogcommentlist() * Browse all comments for a weblog - * @param int $blogid + * + * @param integer $blogid ID for weblog + * @return void */ - function action_blogcommentlist($blogid = '') + static private function action_blogcommentlist($blogid = '') { global $member, $manager, $CONF; - + if ( $blogid == '' ) { $blogid = intRequestVar('blogid'); @@ -776,122 +709,232 @@ class Admin { $blogid = intval($blogid); } - - $member->teamRights($blogid) or $member->isAdmin() or $this->disallow(); - + + $member->teamRights($blogid) or $member->isAdmin() or self::disallow(); + + /* TODO: we consider to use the other way insterad of this */ $_REQUEST['blogid'] = $blogid; - - $this->pagehead(); - $this->parse('blogcommentlist'); - $this->pagefoot(); + + self::$skin->parse('blogcommentlist'); + return; } - + + /** + * Admin::action_createaccount() + * + * @param void + * @return void + */ + static private function action_createaccount() + { + global $CONF; + + if ( $CONF['AllowMemberCreate'] != 1 ) + { + self::$skin->parse('createaccountdisable'); + return; + } + + $name = ''; + $realname =''; + $email = ''; + $url = ''; + + $contents = array( + 'name' => '', + 'realname' => '', + 'email' => '', + 'url' => '' + ); + + if ( array_key_exists('showform', $_POST) && $_POST['showform'] == 1 ) + { + $action = new Action(); + $message = $action->createAccount(); + if ( $message === 1 ) + { + self::$headMess = $message; + self::$skin->parse('createaccountsuccess'); + return; + } + + /* TODO: validation */ + if ( array_key_exists('name', $_POST) ) + { + $contents['name'] = $_POST['name']; + } + if ( array_key_exists('realname', $_POST) ) + { + $contents['realname'] = $_POST['realname']; + } + if ( array_key_exists('email', $_POST) ) + { + $contents['email'] = $_POST['email']; + } + if ( array_key_exists('url', $_POST) ) + { + $contents['url'] = $_POST['url']; + } + + self::$contents = $contents; + + } + + self::$skin->parse('createaccountinput'); + return; + } + /** + * Admin::action_createitem() * Provide a page to item a new item to the given blog + * + * @param void + * @return void */ - function action_createitem() + static private function action_createitem() { global $member, $manager; - + $blogid = intRequestVar('blogid'); - + // check if allowed - $member->teamRights($blogid) or $this->disallow(); - - $memberid = $member->getID(); - + $member->teamRights($blogid) or self::disallow(); + $blog =& $manager->getBlog($blogid); - - $this->pagehead(); - $this->parse('createitem'); - $this->pagefoot(); + $contents = array(); + + $data = array( + 'blog' => &$blog, + 'contents' => &$contents + ); + $manager->notify('PreAddItemForm', $data); + + if ( $blog->convertBreaks() ) + { + if ( array_key_exists('body', $contents) && !empty($contents['body']) ) + { + $contents['body'] = removeBreaks($contents['body']); + } + if ( array_key_exists('more', $contents) && !empty($contents['more']) ) + { + $contents['more'] = removeBreaks($contents['more']); + } + } + + self::$blog = &$blog; + self::$contents = &$contents; + + self::$skin->parse('createitem'); + return; } - + /** - * @todo document this + * Admin::action_itemedit() + * + * @param void + * @return void */ - function action_itemedit() + static private function action_itemedit() { global $member, $manager; - + $itemid = intRequestVar('itemid'); - + // only allow if user is allowed to alter item - $member->canAlterItem($itemid) or $this->disallow(); - + $member->canAlterItem($itemid) or self::disallow(); + $item =& $manager->getItem($itemid, 1, 1); - $blog =& $manager->getBlog(getBlogIDFromItemID($itemid)); - $this->pagehead(); - $this->parse('itemedit'); - $this->pagefoot(); + $blog =& $manager->getBlog($item['blogid']); + $manager->notify('PrepareItemForEdit', array('blog'=> &$blog, 'item' => &$item)); + + if ( $blog->convertBreaks() ) + { + if ( array_key_exists('body', $item) && !empty($item['body']) ) + { + $item['body'] = removeBreaks($item['body']); + } + if ( array_key_exists('more', $item) && !empty($item['more']) ) + { + $item['more'] = removeBreaks($item['more']); + } + } + + self::$blog = &$blog; + self::$contents = &$item; + + self::$skin->parse('itemedit'); + return; } - + /** - * @todo document this + * Admin::action_itemupdate() + * + * @param void + * @return void */ - function action_itemupdate() + static private function action_itemupdate() { global $member, $manager, $CONF; - + $itemid = intRequestVar('itemid'); $catid = postVar('catid'); - + // only allow if user is allowed to alter item - $member->canUpdateItem($itemid, $catid) or $this->disallow(); - + $member->canUpdateItem($itemid, $catid) or self::disallow(); + $actiontype = postVar('actiontype'); - + // delete actions are handled by itemdelete (which has confirmation) if ( $actiontype == 'delete' ) { - $this->action_itemdelete(); + self::action_itemdelete(); return; } - - $body = postVar('body'); - $title = postVar('title'); - $more = postVar('more'); - $closed = intPostVar('closed'); - $draftid = intPostVar('draftid'); - + + $body = postVar('body'); + $title = postVar('title'); + $more = postVar('more'); + $closed = intPostVar('closed'); + $draftid = intPostVar('draftid'); + // default action = add now if ( !$actiontype ) { $actiontype='addnow'; } - + // create new category if needed - if ( strstr($catid,'newcat') ) + if ( i18n::strpos($catid,'newcat') === 0 ) { // get blogid list($blogid) = sscanf($catid,"newcat-%d"); - + // create $blog =& $manager->getBlog($blogid); $catid = $blog->createNewCategory(); - + // show error when sth goes wrong if ( !$catid ) { - $this->doError(_ERROR_CATCREATEFAIL); + self::doError(_ERROR_CATCREATEFAIL); } } - - /* - set some variables based on actiontype - - actiontypes: - draft items -> addnow, addfuture, adddraft, delete - non-draft items -> edit, changedate, delete - - variables set: - $timestamp: set to a nonzero value for future dates or date changes - $wasdraft: set to 1 when the item used to be a draft item - $publish: set to 1 when the edited item is not a draft - */ + + /** + * set some variables based on actiontype + * + * actiontypes: + * draft items -> addnow, addfuture, adddraft, delete + * non-draft items -> edit, changedate, delete + * + * variables set: + * $timestamp: set to a nonzero value for future dates or date changes + * $wasdraft: set to 1 when the item used to be a draft item + * $publish: set to 1 when the edited item is not a draft + */ $blogid = getBlogIDFromItemID($itemid); - $blog =& $manager->getBlog($blogid); - + $blog =& $manager->getBlog($blogid); + $wasdrafts = array('adddraft', 'addfuture', 'addnow'); $wasdraft = in_array($actiontype, $wasdrafts) ? 1 : 0; $publish = ($actiontype != 'adddraft' && $actiontype != 'backtodrafts') ? 1 : 0; @@ -903,23 +946,21 @@ class Admin { $timestamp =0; } - + // edit the item for real Item::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp); - - $this->updateFuturePosted($blogid); - + + self::updateFuturePosted($blogid); + if ( $draftid > 0 ) { // delete permission is checked inside Item::delete() Item::delete($draftid); } - - // show category edit window when we created a new category - // ($catid will then be a new category ID, while postVar('catid') will be 'newcat-x') + if ( $catid != intPostVar('catid') ) { - $this->action_categoryedit( + self::action_categoryedit( $catid, $blog->getID(), $CONF['AdminURL'] . 'index.php?action=itemlist&blogid=' . getBlogIDFromItemID($itemid) @@ -928,11 +969,14 @@ class Admin else { // TODO: set start item correctly for itemlist - $item = Item::getItem($itemid, 0, 0); - $cnt = quickQuery('SELECT COUNT(*) FROM ' . sql_table('item') . ' WHERE unix_timestamp(itime) <= ' . $item['timestamp']); + $item =& $manager->getitem($itemid, 1, 1); + $query = "SELECT COUNT(*) FROM %s WHERE unix_timestamp(itime) <= '%s';"; + $query = sprintf($query, sql_table('item'), $item['timestamp']); + $cnt = DB::getValue($query); $_REQUEST['start'] = $cnt + 1; - $this->action_itemlist(getBlogIDFromItemID($itemid)); + self::action_itemlist(getBlogIDFromItemID($itemid)); } + return; } /** @@ -942,92 +986,97 @@ class Admin * @param Void * @return Void */ - function action_itemdelete() + static private function action_itemdelete() { global $member, $manager; $itemid = intRequestVar('itemid'); // only allow if user is allowed to alter item - $member->canAlterItem($itemid) or $this->disallow(); + $member->canAlterItem($itemid) or self::disallow(); if ( !$manager->existsItem($itemid,1,1) ) { - $this->error(_ERROR_NOSUCHITEM); + self::error(_ERROR_NOSUCHITEM); } - $this->pagehead(); - $this->parse('itemdelete'); - $this->pagefoot(); + self::$skin->parse('itemdelete'); return; } /** - * @todo document this + * Admin::action_itemdeleteconfirm() + * + * @param void + * @return void */ - function action_itemdeleteconfirm() + static private function action_itemdeleteconfirm() { - global $member; - + global $member, $manager; + $itemid = intRequestVar('itemid'); - + // only allow if user is allowed to alter item - $member->canAlterItem($itemid) or $this->disallow(); - - // get blogid first - $blogid = getBlogIdFromItemId($itemid); - + $member->canAlterItem($itemid) or self::disallow(); + + // get item first + $item =& $manager->getItem($itemid, 1, 1); + // delete item (note: some checks will be performed twice) - $this->deleteOneItem($itemid); - - $this->action_itemlist($blogid); + self::deleteOneItem($item['itemid']); + + self::action_itemlist($item['blogid']); + return; } - + /** + * Admin::deleteOneItem() * Deletes one item and returns error if something goes wrong - * @param int $itemid + * + * @param integer $itemid ID for item + * @return void */ - function deleteOneItem($itemid) + static public function deleteOneItem($itemid) { global $member, $manager; - + // only allow if user is allowed to alter item (also checks if itemid exists) if ( !$member->canAlterItem($itemid) ) { return _ERROR_DISALLOWED; } - + // need to get blogid before the item is deleted - $blogid = getBlogIDFromItemId($itemid); - + $item =& $manager->getItem($itemid, 1, 1); + $manager->loadClass('ITEM'); - Item::delete($itemid); - + Item::delete($item['itemid']); + // update blog's futureposted - $this->updateFuturePosted($blogid); + self::updateFuturePosted($item['itemid']); + return; } - + /** * Admin::updateFuturePosted() * Update a blog's future posted flag * * @param integer $blogid * @return void - * */ - function updateFuturePosted($blogid) + static private function updateFuturePosted($blogid) { global $manager; - $blogid = intval($blogid); - $blog =& $manager->getBlog($blogid); - $currenttime = $blog->getCorrectTime(time()); + $blogid = intval($blogid); + $blog =& $manager->getBlog($blogid); + $currenttime = $blog->getCorrectTime(time()); $query = "SELECT * FROM %s WHERE iblog=%d AND iposted=0 AND itime>'%s'"; $query = sprintf($query, sql_table('item'), (integer) $blogid, i18n::formatted_datetime('mysql', $currenttime)); - $result = sql_query($query); + $result = DB::getResult($query); - if ( sql_num_rows($result) > 0 ) + if ( $result->rowCount() > 0 ) { $blog->setFuturePost(); } @@ -1039,442 +1088,471 @@ class Admin } /** - * @todo document this + * Admin::action_itemmove() + * + * @param void + * @return void */ - function action_itemmove() + static private function action_itemmove() { global $member, $manager; - + $itemid = intRequestVar('itemid'); - - // only allow if user is allowed to alter item - $member->canAlterItem($itemid) or $this->disallow(); - - $this->pagehead(); - $this->parse('itemmove'); - $this->pagefoot(); + + $member->canAlterItem($itemid) or self::disallow(); + + self::$skin->parse('itemmove'); + return; } - + /** - * @todo document this + * Admin::action_itemmoveto() + * + * @param void + * @return void */ - function action_itemmoveto() + static private function action_itemmoveto() { global $member, $manager; - + $itemid = intRequestVar('itemid'); $catid = requestVar('catid'); - + // create new category if needed - if ( strstr($catid,'newcat') ) + if ( i18n::strpos($catid,'newcat') === 0 ) { // get blogid list($blogid) = sscanf($catid,'newcat-%d'); - + // create $blog =& $manager->getBlog($blogid); $catid = $blog->createNewCategory(); - + // show error when sth goes wrong if ( !$catid ) { - $this->doError(_ERROR_CATCREATEFAIL); + self::doError(_ERROR_CATCREATEFAIL); } } - + // only allow if user is allowed to alter item - $member->canUpdateItem($itemid, $catid) or $this->disallow(); - + $member->canUpdateItem($itemid, $catid) or self::disallow(); + $old_blogid = getBlogIDFromItemId($itemid); - + Item::move($itemid, $catid); - + // set the futurePosted flag on the blog - $this->updateFuturePosted(getBlogIDFromItemId($itemid)); - + self::updateFuturePosted(getBlogIDFromItemId($itemid)); + // reset the futurePosted in case the item is moved from one blog to another - $this->updateFuturePosted($old_blogid); - + self::updateFuturePosted($old_blogid); + if ( $catid != intRequestVar('catid') ) { - $this->action_categoryedit($catid, $blog->getID()); + self::action_categoryedit($catid, $blog->getID()); } else { - $this->action_itemlist(getBlogIDFromCatID($catid)); + self::action_itemlist(getBlogIDFromCatID($catid)); } + return; } - + /** + * Admin::moveOneItem() * Moves one item to a given category (category existance should be checked by caller) * errors are returned - * @param int $itemid - * @param int $destCatid category ID to which the item will be moved + * + * @param integer $itemid ID for item + * @param integer $destCatid ID for category to which the item will be moved + * @return void */ - function moveOneItem($itemid, $destCatid) + static public function moveOneItem($itemid, $destCatid) { global $member; - + // only allow if user is allowed to move item if ( !$member->canUpdateItem($itemid, $destCatid) ) { return _ERROR_DISALLOWED; } - + Item::move($itemid, $destCatid); + return; } - + /** + * Admin::action_additem() * Adds a item to the chosen blog + * + * @param void + * @return void */ - function action_additem() + static private function action_additem() { global $manager, $CONF; - + $manager->loadClass('ITEM'); - + $result = Item::createFromRequest(); - + if ( $result['status'] == 'error' ) { - $this->error($result['message']); + self::error($result['message']); } - - $blogid = getBlogIDFromItemID($result['itemid']); - $blog =& $manager->getBlog($blogid); - $btimestamp = $blog->getCorrectTime(); - $item = $manager->getItem(intval($result['itemid']), 1, 1); - + + $item =& $manager->getItem($result['itemid'], 0, 0); + if ( $result['status'] == 'newcategory' ) { - $distURI = $manager->addTicketToUrl($CONF['AdminURL'] . 'index.php?action=itemList&blogid=' . intval($blogid)); - $this->action_categoryedit($result['catid'], $blogid, $distURI); + $distURI = $manager->addTicketToUrl($CONF['AdminURL'] . 'index.php?action=itemList&blogid=' . $item['blogid']); + self::action_categoryedit($result['catid'], $item['blogid'], $distURI); } else { - $methodName = 'action_itemList'; - call_user_func(array(&$this, $methodName), $blogid); + $methodName = 'action_itemlist'; + self::action_itemlist($item['blogid']); } + return; } - + /** + * Admin::action_commentedit() * Allows to edit previously made comments - **/ - function action_commentedit() + * + * @param void + * @return void + */ + static private function action_commentedit() { - global $member, $manager; - + $commentid = intRequestVar('commentid'); - - $member->canAlterComment($commentid) or $this->disallow(); - - $this->pagehead(); - $this->parse('commentedit'); - $this->pagefoot(); + + $member->canAlterComment($commentid) or self::disallow(); + + self::$skin->parse('commentedit'); + return; } - + /** - * @todo document this + * Admin::action_commentupdate() + * + * @param void + * @return void */ - function action_commentupdate() + static private function action_commentupdate() { global $member, $manager; - + $commentid = intRequestVar('commentid'); - - $member->canAlterComment($commentid) or $this->disallow(); - - $url = postVar('url'); - $email = postVar('email'); - $body = postVar('body'); - - # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0 - # original eregi: eregi("[a-zA-Z0-9|\.,;:!\?=\/\\]{90,90}", $body) != FALSE - # important note that '\' must be matched with '\\\\' in preg* expressions - + + $member->canAlterComment($commentid) or self::disallow(); + + $url = postVar('url'); + $email = postVar('email'); + $body = postVar('body'); + // intercept words that are too long if (preg_match('#[a-zA-Z0-9|\.,;:!\?=\/\\\\]{90,90}#', $body) != FALSE) { - $this->error(_ERROR_COMMENT_LONGWORD); + self::error(_ERROR_COMMENT_LONGWORD); } - + // check length if ( i18n::strlen($body) < 3 ) { - $this->error(_ERROR_COMMENT_NOCOMMENT); + self::error(_ERROR_COMMENT_NOCOMMENT); } - + if ( i18n::strlen($body) > 5000 ) { - $this->error(_ERROR_COMMENT_TOOLONG); + self::error(_ERROR_COMMENT_TOOLONG); } - + // prepare body $body = Comment::prepareBody($body); - + // call plugins - $manager->notify( - 'PreUpdateComment', - array( - 'body' => &$body - ) + $data = array( + 'body' => &$body ); - - $query = 'UPDATE ' . sql_table('comment') - . " SET " - . " cmail = '" . sql_real_escape_string($url) . "'," - . " cemail = '" . sql_real_escape_string($email) . "'," - . " cbody = '" . sql_real_escape_string($body) . "'" - . " WHERE " - . " cnumber = " . $commentid; - sql_query($query); - + $manager->notify('PreUpdateComment', $data); + + $query = "UPDATE %s SET cmail=%s, cemail=%s, cbody=%s WHERE cnumber=%d;"; + $query = sprintf($query, sql_table('comment'), DB::quoteValue($url), DB::quoteValue($email), DB::quoteValue($body), (integer) $commentid); + DB::execute($query); + // get itemid - $res = sql_query('SELECT citem FROM '.sql_table('comment').' WHERE cnumber=' . $commentid); - $o = sql_fetch_object($res); - $itemid = $o->citem; - + $query = "SELECT citem FROM %s WHERE cnumber=%d;"; + $query = sprintf($query, sql_table('comment'), (integer) $commentid); + + $itemid = DB::getValue($query); + if ( $member->canAlterItem($itemid) ) { - $this->action_itemcommentlist($itemid); + self::action_itemcommentlist($itemid); } else { - $this->action_browseowncomments(); + self::action_browseowncomments(); } + return; } /** * Admin::action_commentdelete() * Update comment * - * @param Void - * @return Void + * @param void + * @return void */ - function action_commentdelete() + static private function action_commentdelete() { global $member, $manager; $commentid = intRequestVar('commentid'); - $member->canAlterComment($commentid) or $this->disallow(); - - $this->pagehead(); - $this->parse('commentdelete'); - $this->pagefoot(); + $member->canAlterComment($commentid) or self::disallow(); + + self::$skin->parse('commentdelete'); return; } /** - * @todo document this + * Admin::action_commentdeleteconfirm() + * + * @param void + * @return void */ - function action_commentdeleteconfirm() + static private function action_commentdeleteconfirm() { global $member; - + $commentid = intRequestVar('commentid'); - + // get item id first - $res = sql_query('SELECT citem FROM '.sql_table('comment') .' WHERE cnumber=' . $commentid); - $o = sql_fetch_object($res); - $itemid = $o->citem; - - $error = $this->deleteOneComment($commentid); + $query = "SELECT citem FROM %s WHERE cnumber=%d;"; + $query = sprintf($query, sql_table('comment'), (integer) $commentid); + + $itemid = DB::getValue($query); + + $error = self::deleteOneComment($commentid); if ( $error ) { - $this->doError($error); + self::doError($error); } - + if ( $member->canAlterItem($itemid) ) { - $this->action_itemcommentlist($itemid); + self::action_itemcommentlist($itemid); } else { - $this->action_browseowncomments(); + self::action_browseowncomments(); } + return; } - + /** - * @todo document this + * Admin::deleteOneComment() + * + * @param integer $commentid ID for comment + * @return void */ - function deleteOneComment($commentid) { + static public function deleteOneComment($commentid) + { global $member, $manager; - - $commentid = intval($commentid); - + + $commentid = (integer) $commentid; + if ( !$member->canAlterComment($commentid) ) { return _ERROR_DISALLOWED; } - - $manager->notify( - 'PreDeleteComment', - array( - 'commentid' => $commentid - ) + + $data = array( + 'commentid' => $commentid ); - + + $manager->notify('PreDeleteComment', $data); + // delete the comments associated with the item - $query = 'DELETE FROM ' . sql_table('comment') . ' WHERE cnumber=' . $commentid; - sql_query($query); - - $manager->notify( - 'PostDeleteComment', - array( - 'commentid' => $commentid - ) + $query = "DELETE FROM %s WHERE cnumber=%d;"; + $query = sprintf($query, sql_table('comment'), (integer) $commentid); + DB::execute($query); + + $data = array( + 'commentid' => $commentid ); - + + $manager->notify('PostDeleteComment', $data); + return ''; } - + /** + * Admin::action_usermanagement() * Usermanagement main + * + * @param void + * @return void */ - function action_usermanagement() + static private function action_usermanagement() { global $member, $manager; - + // check if allowed - $member->isAdmin() or $this->disallow(); - - $this->pagehead(); - $this->parse('usermanagement'); - $this->pagefoot(); + $member->isAdmin() or self::disallow(); + + self::$skin->parse('usermanagement'); + return; } - + /** + * Admin::action_memberedit() * Edit member settings + * + * @param void + * @return void */ - function action_memberedit() + static private function action_memberedit() { - $this->action_editmembersettings(intRequestVar('memberid')); + self::action_editmembersettings(intRequestVar('memberid')); + return; } - + /** - * @todo document this + * Admin::action_editmembersettings() + * + * @param integer $memberid ID for member + * @return void + * */ - function action_editmembersettings($memberid = '') { + static private function action_editmembersettings($memberid = '') + { global $member, $manager, $CONF; if ( $memberid == '' ) { $memberid = $member->getID(); } + + /* TODO: we should consider to use the other way insterad of this */ $_REQUEST['memberid'] = $memberid; - + // check if allowed - ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow(); + ($member->getID() == $memberid) or $member->isAdmin() or self::disallow(); - $extrahead = ''; - $this->pagehead($extrahead); - $this->parse('editmembersettings'); - $this->pagefoot(); + Admin::$extrahead .= "\n"; + + self::$skin->parse('editmembersettings'); + return; } /** - * @todo document this + * Admin::action_changemembersettings() + * + * @param void + * @return void */ - function action_changemembersettings() { + static private function action_changemembersettings() + { global $member, $CONF, $manager; - + $memberid = intRequestVar('memberid'); - + // check if allowed - ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow(); - - $name = trim(strip_tags(postVar('name'))); - $realname = trim(strip_tags(postVar('realname'))); - $password = postVar('password'); - $repeatpassword = postVar('repeatpassword'); - $email = strip_tags(postVar('email')); - $url = strip_tags(postVar('url')); - $adminskin = intPostVar('adminskin'); - - # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0 - # original eregi: !eregi("^https?://", $url) - + ($member->getID() == $memberid) or $member->isAdmin() or self::disallow(); + + $name = trim(strip_tags(postVar('name'))); + $realname = trim(strip_tags(postVar('realname'))); + $password = postVar('password'); + $repeatpassword = postVar('repeatpassword'); + $email = strip_tags(postVar('email')); + $url = strip_tags(postVar('url')); + $adminskin = intPostVar('adminskin'); + // begin if: sometimes user didn't prefix the URL with http:// or https://, this cause a malformed URL. Let's fix it. if ( !preg_match('#^https?://#', $url) ) { $url = 'http://' . $url; } - - $admin = postVar('admin'); - $canlogin = postVar('canlogin'); - $notes = strip_tags(postVar('notes')); - $locale = postVar('locale'); - - $mem = Member::createFromID($memberid); - - if ($CONF['AllowLoginEdit'] || $member->isAdmin()) { - + + $admin = postVar('admin'); + $canlogin = postVar('canlogin'); + $notes = strip_tags(postVar('notes')); + $locale = postVar('locale'); + + $mem =& $manager->getMember($memberid); + + if ( $CONF['AllowLoginEdit'] || $member->isAdmin() ) + { if ( !isValidDisplayName($name) ) { - $this->error(_ERROR_BADNAME); + self::error(_ERROR_BADNAME); } - + if ( ($name != $mem->getDisplayName()) && Member::exists($name) ) { - $this->error(_ERROR_NICKNAMEINUSE); + self::error(_ERROR_NICKNAMEINUSE); } - + if ( $password != $repeatpassword ) { - $this->error(_ERROR_PASSWORDMISMATCH); + self::error(_ERROR_PASSWORDMISMATCH); } - + if ( $password && (i18n::strlen($password) < 6) ) { - $this->error(_ERROR_PASSWORDTOOSHORT); + self::error(_ERROR_PASSWORDTOOSHORT); } if ( $password ) { $pwdvalid = true; $pwderror = ''; - $manager->notify( - 'PrePasswordSet', - array( - 'password' => $password, - 'errormessage' => &$pwderror, - 'valid' => &$pwdvalid - ) + + $data = array( + 'password' => $password, + 'errormessage' => &$pwderror, + 'valid' => &$pwdvalid ); + $manager->notify('PrePasswordSet', $data); + if ( !$pwdvalid ) { - $this->error($pwderror); + self::error($pwderror); } } } if ( !NOTIFICATION::address_validation($email) ) { - $this->error(_ERROR_BADMAILADDRESS); + self::error(_ERROR_BADMAILADDRESS); } if ( !$realname ) { - $this->error(_ERROR_REALNAMEMISSING); + self::error(_ERROR_REALNAMEMISSING); } if ( ($locale != '') && (!in_array($locale, i18n::get_available_locale_list())) ) { - $this->error(_ERROR_NOSUCHTRANSLATION); + self::error(_ERROR_NOSUCHTRANSLATION); } - + // check if there will remain at least one site member with both the logon and admin rights // (check occurs when taking away one of these rights from such a member) if ( (!$admin && $mem->isAdmin() && $mem->canLogin()) || (!$canlogin && $mem->isAdmin() && $mem->canLogin()) ) { - $r = sql_query('SELECT * FROM '.sql_table('member').' WHERE madmin=1 and mcanlogin=1'); - if ( sql_num_rows($r) < 2 ) + $r = DB::getResult('SELECT * FROM '.sql_table('member').' WHERE madmin=1 and mcanlogin=1'); + if ( $r->rowCount() < 2 ) { - $this->error(_ERROR_ATLEASTONEADMIN); + self::error(_ERROR_ATLEASTONEADMIN); } } - + if ( $CONF['AllowLoginEdit'] || $member->isAdmin() ) { $mem->setDisplayName($name); @@ -1483,69 +1561,65 @@ class Admin $mem->setPassword($password); } } - + $oldEmail = $mem->getEmail(); - + $mem->setRealName($realname); $mem->setEmail($email); $mem->setURL($url); $mem->setNotes($notes); $mem->setLocale($locale); - - + // only allow super-admins to make changes to the admin status if ( $member->isAdmin() ) { $mem->setAdmin($admin); $mem->setCanLogin($canlogin); } - + $autosave = postVar('autosave'); $mem->setAutosave($autosave); - + $mem->write(); - + // store plugin options $aOptions = requestArray('plugoption'); NucleusPlugin::apply_plugin_options($aOptions); - $manager->notify( - 'PostPluginOptionsUpdate', - array( - 'context' => 'member', - 'memberid' => $memberid, - 'member' => &$mem - ) + $data = array( + 'context' => 'member', + 'memberid' => $memberid, + 'member' => &$mem ); - + $manager->notify('PostPluginOptionsUpdate', $data); + // if email changed, generate new password if ( $oldEmail != $mem->getEmail() ) { $mem->sendActivationLink('addresschange', $oldEmail); // logout member $mem->newCookieKey(); - + // only log out if the member being edited is the current member. if ( $member->getID() == $memberid ) { $member->logout(); } - $this->action_login(_MSG_ACTIVATION_SENT, 0); + self::action_login(_MSG_ACTIVATION_SENT, 0); return; } - - - if ( ( $mem->getID() == $member->getID() ) - && ( $mem->getDisplayName() != $member->getDisplayName() ) - ) + + if ( ($mem->getID() == $member->getID()) + && ($mem->getDisplayName() != $member->getDisplayName()) ) { $mem->newCookieKey(); $member->logout(); - $this->action_login(_MSG_LOGINAGAIN, 0); + self::action_login(_MSG_LOGINAGAIN, 0); } else { - $this->action_overview(_MSG_SETTINGSCHANGED); + self::action_overview(_MSG_SETTINGSCHANGED); } + return; } /** @@ -1554,345 +1628,378 @@ class Admin * @param void * @return void * - */ - function action_memberadd() + */ + static private function action_memberadd() { global $member, $manager; // check if allowed - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); if ( postVar('password') != postVar('repeatpassword') ) { - $this->error(_ERROR_PASSWORDMISMATCH); + self::error(_ERROR_PASSWORDMISMATCH); } if ( i18n::strlen(postVar('password')) < 6 ) { - $this->error(_ERROR_PASSWORDTOOSHORT); + self::error(_ERROR_PASSWORDTOOSHORT); } $res = Member::create( - postVar('name'), - postVar('realname'), - postVar('password'), - postVar('email'), - postVar('url'), - postVar('admin'), - postVar('canlogin'), - postVar('notes') - ); + postVar('name'), + postVar('realname'), + postVar('password'), + postVar('email'), + postVar('url'), + postVar('admin'), + postVar('canlogin'), + postVar('notes') + ); + if ( $res != 1 ) { - $this->error($res); + self::error($res); } // fire PostRegister event $newmem = new Member(); $newmem->readFromName(postVar('name')); - $manager->notify( - 'PostRegister', - array( - 'member' => &$newmem - ) + $data = array( + 'member' => &$newmem ); + $manager->notify('PostRegister', $data); - $this->action_usermanagement(); + self::action_usermanagement(); return; } - + + /** + * Admin::action_forgotpassword() + * + * @param void + * @return void + */ + static private function action_forgotpassword() + { + self::$skin->parse('forgotpassword'); + return; + } + /** + * Admin::action_activate() * Account activation - * - * @author dekarma + * + * @param void + * @return void */ - function action_activate() + static private function action_activate() { - $key = getVar('key'); - $this->_showActivationPage($key); + self::showActivationPage($key); + return; } - + /** - * @todo document this + * Admin::showActivationPage() + * + * @param void + * @return void */ - function _showActivationPage($key, $message = '') + static private function showActivationPage($key, $message = '') { global $manager; - + // clean up old activation keys Member::cleanupActivationTable(); - + // get activation info $info = Member::getActivationInfo($key); - + if ( !$info ) { - $this->error(_ERROR_ACTIVATE); + self::error(_ERROR_ACTIVATE); } - - $mem = Member::createFromId($info->vmember); - + + $mem =& $manager->getMember($info->vmember); + if ( !$mem ) { - $this->error(_ERROR_ACTIVATE); + self::error(_ERROR_ACTIVATE); } - $_POST['ackey'] = $key; - $this->headMess = $message; - $_POST['bNeedsPasswordChange'] = true; - $this->pagehead(); - $this->parse('activate'); - $this->pagefoot(); - + + /* TODO: we should consider to use the other way insterad of this */ + $_POST['ackey'] = $key; + $_POST['bNeedsPasswordChange'] = TRUE; + + self::$headMess = $message; + self::$skin->parse('activate'); + return; } - + /** + * Admin::action_activatesetpwd() * Account activation - set password part - * - * @author dekarma + * + * @param void + * @return void */ - function action_activatesetpwd() + static private function action_activatesetpwd() { - + global $manager; $key = postVar('key'); - + // clean up old activation keys Member::cleanupActivationTable(); - + // get activation info $info = Member::getActivationInfo($key); - + if ( !$info || ($info->type == 'addresschange') ) { - return $this->_showActivationPage($key, _ERROR_ACTIVATE); + return self::showActivationPage($key, _ERROR_ACTIVATE); } - - $mem = Member::createFromId($info->vmember); - + + $mem =& $manager->getMember($info->vmember); + if ( !$mem ) { - return $this->_showActivationPage($key, _ERROR_ACTIVATE); + return self::showActivationPage($key, _ERROR_ACTIVATE); } - - $password = postVar('password'); - $repeatpassword = postVar('repeatpassword'); - + + $password = postVar('password'); + $repeatpassword = postVar('repeatpassword'); + if ( $password != $repeatpassword ) { - return $this->_showActivationPage($key, _ERROR_PASSWORDMISMATCH); + return self::showActivationPage($key, _ERROR_PASSWORDMISMATCH); } - + if ( $password && (i18n::strlen($password) < 6) ) { - return $this->_showActivationPage($key, _ERROR_PASSWORDTOOSHORT); + return self::showActivationPage($key, _ERROR_PASSWORDTOOSHORT); } if ( $password ) { $pwdvalid = true; $pwderror = ''; - global $manager; - $manager->notify( - 'PrePasswordSet', - array( - 'password' => $password, - 'errormessage' => &$pwderror, - 'valid' => &$pwdvalid - ) + + $data = array( + 'password' => $password, + 'errormessage' => &$pwderror, + 'valid' => &$pwdvalid ); + $manager->notify('PrePasswordSet', $data); if ( !$pwdvalid ) { - return $this->_showActivationPage($key,$pwderror); + return self::showActivationPage($key,$pwderror); } } - + $error = ''; - $manager->notify( - 'ValidateForm', - array( - 'type' => 'activation', - 'member' => $mem, - 'error' => &$error - ) + $data = array( + 'type' => 'activation', + 'member' => $mem, + 'error' => &$error ); + $manager->notify('ValidateForm', $data); if ( $error != '' ) { - return $this->_showActivationPage($key, $error); + return self::showActivationPage($key, $error); } - - + // set password $mem->setPassword($password); $mem->write(); - + // do the activation Member::activate($key); - - $this->pagehead(); - $this->parse('activatesetpwd'); - $this->pagefoot(); + + self::$skin->parse('activatesetpwd'); + return; } - + /** + * Admin::action_manageteam() * Manage team + * + * @param void + * @return void */ - function action_manageteam() + static private function action_manageteam() { global $member, $manager; - + $blogid = intRequestVar('blogid'); - + // check if allowed - $member->blogAdminRights($blogid) or $this->disallow(); - - $this->pagehead(); - $this->parse('manageteam'); - $this->pagefoot(); + $member->blogAdminRights($blogid) or self::disallow(); + + self::$skin->parse('manageteam'); + return; } - + /** + * Admin::action_teamaddmember() * Add member to team + * + * @param void + * @return void */ - function action_teamaddmember() + static private function action_teamaddmember() { global $member, $manager; - - $memberid = intPostVar('memberid'); - $blogid = intPostVar('blogid'); - $admin = intPostVar('admin'); - + + $memberid = intPostVar('memberid'); + $blogid = intPostVar('blogid'); + $admin = intPostVar('admin'); + // check if allowed - $member->blogAdminRights($blogid) or $this->disallow(); - + $member->blogAdminRights($blogid) or self::disallow(); + $blog =& $manager->getBlog($blogid); if ( !$blog->addTeamMember($memberid, $admin) ) { - $this->error(_ERROR_ALREADYONTEAM); + self::error(_ERROR_ALREADYONTEAM); } - - $this->action_manageteam(); - + + self::action_manageteam(); + return; } - + /** - * @todo document this + * Admin::action_teamdelete() + * + * @param void + * @return void */ - function action_teamdelete() + static private function action_teamdelete() { global $member, $manager; - - $memberid = intRequestVar('memberid'); - $blogid = intRequestVar('blogid'); - + + $memberid = intRequestVar('memberid'); + $blogid = intRequestVar('blogid'); + // check if allowed - $member->blogAdminRights($blogid) or $this->disallow(); - - $teammem = Member::createFromID($memberid); - $blog =& $manager->getBlog($blogid); - - $this->pagehead(); - $this->parse('teamdelete'); - $this->pagefoot(); + $member->blogAdminRights($blogid) or self::disallow(); + + $teammem =& $manager->getMember($memberid); + $blog =& $manager->getBlog($blogid); + + self::$skin->parse('teamdelete'); + return; } - + /** - * @todo document this + * Admin::action_teamdeleteconfirm() + * + * @param void + * @return void */ - function action_teamdeleteconfirm() + static private function action_teamdeleteconfirm() { global $member; - + $memberid = intRequestVar('memberid'); $blogid = intRequestVar('blogid'); - - $error = $this->deleteOneTeamMember($blogid, $memberid); + + $error = self::deleteOneTeamMember($blogid, $memberid); if ( $error ) { - $this->error($error); + self::error($error); } - $this->action_manageteam(); + self::action_manageteam(); + return; } - + /** - * @todo document this + * Admin::deleteOneTeamMember() + * + * @param void + * @return void */ - function deleteOneTeamMember($blogid, $memberid) + static public function deleteOneTeamMember($blogid, $memberid) { global $member, $manager; - + $blogid = intval($blogid); $memberid = intval($memberid); - + // check if allowed if ( !$member->blogAdminRights($blogid) ) { return _ERROR_DISALLOWED; } - + // check if: - there remains at least one blog admin // - (there remains at least one team member) - $tmem = Member::createFromID($memberid); - - $manager->notify( - 'PreDeleteTeamMember', - array( - 'member' => &$tmem, - 'blogid' => $blogid - ) - ); - + $tmem =& $manager->getMember($memberid); + + + $data = array( + 'member' => &$tmem, + 'blogid' => $blogid + ); $manager->notify('PreDeleteTeamMember', $data); + if ( $tmem->isBlogAdmin($blogid) ) { + /* TODO: why we did double check? */ // check if there are more blog members left and at least one admin // (check for at least two admins before deletion) - $query = 'SELECT * FROM ' . sql_table('team') . ' WHERE tblog=' . $blogid . ' and tadmin=1'; - $r = sql_query($query); - if ( sql_num_rows($r) < 2 ) + $query = "SELECT * FROM %s WHERE tblog=%d and tadmin=1;"; + $query = sprintf($query, sql_table('team'), (integer) $blogid); + $r = DB::getResult($query); + if ( $r->rowCount() < 2 ) { return _ERROR_ATLEASTONEBLOGADMIN; } } - - $query = 'DELETE FROM ' . sql_table('team') . " WHERE tblog=$blogid and tmember=$memberid"; - sql_query($query); - - $manager->notify( - 'PostDeleteTeamMember', - array( - 'member' => &$tmem, - 'blogid' => $blogid - ) + + $query = "DELETE FROM %s WHERE tblog=%d AND tmember=%d;"; + $query = sprintf($query, sql_table('team'), (integer) $blogid, (integer) $memberid); + DB::execute($query); + + $data = array( + 'member' => &$tmem, + 'blogid' => $blogid ); - + $manager->notify('PostDeleteTeamMember', $data); + return ''; } - + /** - * @todo document this + * Admin::action_teamchangeadmin() + * + * @param void + * @return void */ - function action_teamchangeadmin() + static private function action_teamchangeadmin() { - global $member; - - $blogid = intRequestVar('blogid'); - $memberid = intRequestVar('memberid'); - + global $manager, $member; + + $blogid = intRequestVar('blogid'); + $memberid = intRequestVar('memberid'); + // check if allowed - $member->blogAdminRights($blogid) or $this->disallow(); - - $mem = Member::createFromID($memberid); - + $member->blogAdminRights($blogid) or self::disallow(); + + $mem =& $manager->getMember($memberid); + // don't allow when there is only one admin at this moment if ( $mem->isBlogAdmin($blogid) ) { - $r = sql_query('SELECT * FROM '.sql_table('team') . " WHERE tblog=$blogid and tadmin=1"); - if ( sql_num_rows($r) == 1 ) + $query = "SELECT * FROM %s WHERE tblog=%d AND tadmin=1;"; + $query = sprintf($query, sql_table('team'), (integer) $blogid); + $r = DB::getResult($query); + if ( $r->rowCount() == 1 ) { - $this->error(_ERROR_ATLEASTONEBLOGADMIN); + self::error(_ERROR_ATLEASTONEBLOGADMIN); } } - + if ( $mem->isBlogAdmin($blogid) ) { $newval = 0; @@ -1901,80 +2008,93 @@ class Admin { $newval = 1; } - - $query = 'UPDATE ' . sql_table('team') . " SET tadmin=$newval WHERE tblog=$blogid and tmember=$memberid"; - sql_query($query); - + + $query = "UPDATE %s SET tadmin=%d WHERE tblog=%d and tmember=%d;"; + $query = sprintf($query, (integer) $blogid, (integer) $newval, (integer) $blogid, (integer) $memberid); + DB::execute($query); + // only show manageteam if member did not change its own admin privileges if ( $member->isBlogAdmin($blogid) ) { - $this->action_manageteam(); + self::action_manageteam(); } else { - $this->action_overview(_MSG_ADMINCHANGED); + self::action_overview(_MSG_ADMINCHANGED); } + return; } - + /** - * @todo document this + * Admin::action_blogsettings() + * + * @param void + * @return void */ - function action_blogsettings() + static private function action_blogsettings() { global $member, $manager; - + $blogid = intRequestVar('blogid'); - + // check if allowed - $member->blogAdminRights($blogid) or $this->disallow(); - + $member->blogAdminRights($blogid) or self::disallow(); + $blog =& $manager->getBlog($blogid); - - $extrahead = ''; - $this->pagehead($extrahead); - $this->parse('blogsettings'); - $this->pagefoot(); + + Admin::$extrahead .= "\n"; + + self::$skin->parse('blogsettings'); + return; } - + /** - * @todo document this + * Admin::action_categorynew() + * + * @param void + * @return void */ - function action_categorynew() + static private function action_categorynew() { global $member, $manager; - + $blogid = intRequestVar('blogid'); - - $member->blogAdminRights($blogid) or $this->disallow(); - + + $member->blogAdminRights($blogid) or self::disallow(); + $cname = postVar('cname'); $cdesc = postVar('cdesc'); - + if ( !isValidCategoryName($cname) ) { - $this->error(_ERROR_BADCATEGORYNAME); + self::error(_ERROR_BADCATEGORYNAME); } - - $query = 'SELECT * FROM ' . sql_table('category') . ' WHERE cname=\'' . sql_real_escape_string($cname) . '\' and cblog=' . intval($blogid); - $res = sql_query($query); - if ( sql_num_rows($res) > 0 ) + + $query = "SELECT * FROM %s WHERE cname=%s AND cblog=%d;"; + $query = sprintf($query, sql_table('category'), DB::quoteValue($cname), (integer) $blogid); + $res = DB::getResult($query); + if ( $res->rowCount() > 0 ) { - $this->error(_ERROR_DUPCATEGORYNAME); + self::error(_ERROR_DUPCATEGORYNAME); } - - $blog =& $manager->getBlog($blogid); - $newCatID = $blog->createNewCategory($cname, $cdesc); - - $this->action_blogsettings(); + + $blog =& $manager->getBlog($blogid); + $newCatID = $blog->createNewCategory($cname, $cdesc); + + self::action_blogsettings(); + return; } - + /** - * @todo document this + * Admin::action_categoryedit() + * + * @param void + * @return void */ - function action_categoryedit($catid = '', $blogid = '', $desturl = '') + static private function action_categoryedit($catid = '', $blogid = '', $desturl = '') { global $member, $manager; - + if ( $blogid == '' ) { $blogid = intGetVar('blogid'); @@ -1991,67 +2111,63 @@ class Admin { $catid = intval($catid); } - $_REQUEST['blogid'] = $blogid; - $_REQUEST['catid'] = $catid; - $_REQUEST['desturl'] = $desturl; - $member->blogAdminRights($blogid) or $this->disallow(); - - $extrahead = ''; - $this->pagehead($extrahead); - $this->parse('categoryedit'); - $this->pagefoot(); + + /* TODO: we should consider to use the other way insterad of this */ + $_REQUEST['blogid'] = $blogid; + $_REQUEST['catid'] = $catid; + $_REQUEST['desturl'] = $desturl; + $member->blogAdminRights($blogid) or self::disallow(); + + Admin::$extrahead .= "\n"; + + self::$skin->parse('categoryedit'); + return; } - + /** - * @todo document this + * Admin::action_categoryupdate() + * + * @param void + * @return void */ - function action_categoryupdate() + static private function action_categoryupdate() { global $member, $manager; - - $blogid = intPostVar('blogid'); - $catid = intPostVar('catid'); - $cname = postVar('cname'); - $cdesc = postVar('cdesc'); - $desturl = postVar('desturl'); - - $member->blogAdminRights($blogid) or $this->disallow(); - + + $blogid = intPostVar('blogid'); + $catid = intPostVar('catid'); + $cname = postVar('cname'); + $cdesc = postVar('cdesc'); + $desturl = postVar('desturl'); + + $member->blogAdminRights($blogid) or self::disallow(); + if ( !isValidCategoryName($cname) ) { - $this->error(_ERROR_BADCATEGORYNAME); + self::error(_ERROR_BADCATEGORYNAME); } - - $query = "SELECT *" - . " FROM " . sql_table('category') - . " WHERE cname='" . sql_real_escape_string($cname) . "'" - . " and cblog=" . intval($blogid) - . " and not(catid=" . intval($catid) . ")"; - $res = sql_query($query); - if ( sql_num_rows($res) > 0 ) + + $query = "SELECT * FROM %s WHERE cname=%s AND cblog=%d AND not(catid=%d);"; + $query = sprintf($query, sql_table('category'), DB::quoteValue($cname), (integer) $blogid, (integer) $catid); + $res = DB::getResult($query); + if ( $res->rowCount() > 0 ) { - $this->error(_ERROR_DUPCATEGORYNAME); + self::error(_ERROR_DUPCATEGORYNAME); } - - $query = 'UPDATE '.sql_table('category').' SET' - . " cname='" . sql_real_escape_string($cname) . "'," - . " cdesc='" . sql_real_escape_string($cdesc) . "'" - . " WHERE catid=" . intval($catid); - - sql_query($query); - + + $query = "UPDATE %s SET cname=%s, cdesc=%s WHERE catid=%d;"; + $query = sprintf($query, sql_table('category'), DB::quoteValue($cname), DB::quoteValue($cdesc), (integer) $catid); + DB::execute($query); + // store plugin options $aOptions = requestArray('plugoption'); NucleusPlugin::apply_plugin_options($aOptions); - $manager->notify( - 'PostPluginOptionsUpdate', - array( - 'context' => 'category', - 'catid' => $catid - ) + $data = array( + 'context' => 'category', + 'catid' => $catid ); - - + $manager->notify('PostPluginOptionsUpdate', $data); + if ( $desturl ) { redirect($desturl); @@ -2059,69 +2175,76 @@ class Admin } else { - $this->action_blogsettings(); + self::action_blogsettings(); } + return; } - + /** - * @todo document this + * Admin::action_categorydelete() + * + * @param void + * @return void */ - function action_categorydelete() + static private function action_categorydelete() { global $member, $manager; - - $blogid = intRequestVar('blogid'); - $catid = intRequestVar('catid'); - - $member->blogAdminRights($blogid) or $this->disallow(); - + + $blogid = intRequestVar('blogid'); + $catid = intRequestVar('catid'); + + $member->blogAdminRights($blogid) or self::disallow(); + $blog =& $manager->getBlog($blogid); - + // check if the category is valid if ( !$blog->isValidCategory($catid) ) { - $this->error(_ERROR_NOSUCHCATEGORY); + self::error(_ERROR_NOSUCHCATEGORY); } - + // don't allow deletion of default category if ( $blog->getDefaultCategory() == $catid ) { - $this->error(_ERROR_DELETEDEFCATEGORY); + self::error(_ERROR_DELETEDEFCATEGORY); } - + // check if catid is the only category left for blogid - $query = 'SELECT catid FROM ' . sql_table('category') . ' WHERE cblog=' . $blogid; - $res = sql_query($query); - if ( sql_num_rows($res) == 1 ) + $query = "SELECT catid FROM %s WHERE cblog=%d;"; + $query = sprintf($query, sql_table('category'), $blogid); + $res = DB::getResult($query); + if ( $res->rowCount() == 1 ) { - $this->error(_ERROR_DELETELASTCATEGORY); + self::error(_ERROR_DELETELASTCATEGORY); } - - - $this->pagehead(); - $this->parse('categorydelete'); - $this->pagefoot(); + + self::$skin->parse('categorydelete'); + return; } - + /** - * @todo document this + * Admin::action_categorydeleteconfirm() + * + * @param void + * @return void */ - function action_categorydeleteconfirm() + static private function action_categorydeleteconfirm() { global $member, $manager; - + $blogid = intRequestVar('blogid'); $catid = intRequestVar('catid'); - - $member->blogAdminRights($blogid) or $this->disallow(); - - $error = $this->deleteOneCategory($catid); + + $member->blogAdminRights($blogid) or self::disallow(); + + $error = self::deleteOneCategory($catid); if ( $error ) { - $this->error($error); + self::error($error); } - - $this->action_blogsettings(); + + self::action_blogsettings(); + return; } /** @@ -2131,90 +2254,176 @@ class Admin * @param String $catid category id for deleting * @return Void */ - function deleteOneCategory($catid) + static public function deleteOneCategory($catid) { global $manager, $member; $catid = intval($catid); $blogid = getBlogIDFromCatID($catid); - + if ( !$member->blogAdminRights($blogid) ) { return ERROR_DISALLOWED; } - + // get blog $blog =& $manager->getBlog($blogid); - + // check if the category is valid if ( !$blog || !$blog->isValidCategory($catid) ) { return _ERROR_NOSUCHCATEGORY; } - + $destcatid = $blog->getDefaultCategory(); - + // don't allow deletion of default category if ( $blog->getDefaultCategory() == $catid ) { return _ERROR_DELETEDEFCATEGORY; } - + // check if catid is the only category left for blogid - $query = 'SELECT catid FROM '.sql_table('category').' WHERE cblog=' . $blogid; - $res = sql_query($query); - if ( sql_num_rows($res) == 1 ) + $query = "SELECT catid FROM %s WHERE cblog=%d;"; + $query = sprintf($query, sql_table('category'), (integer) $blogid); + + $res = DB::getResult($query); + if ( $res->rowCount() == 1 ) { return _ERROR_DELETELASTCATEGORY; } - - $manager->notify( - 'PreDeleteCategory', - array( - 'catid' => $catid - ) - ); - + + $data = array('catid' => $catid); + $manager->notify('PreDeleteCategory', $data); + // change category for all items to the default category - $query = 'UPDATE ' . sql_table('item') . " SET icat=$destcatid WHERE icat=$catid"; - sql_query($query); + $query = "UPDATE %s SET icat=%d WHERE icat=%d;"; + $query =sprintf($query, sql_table('item'), (integer) $destcatid, (integer) $catid); + DB::execute($query); // delete all associated plugin options - NucleusPlugin::delete_option_values('category', $catid); + NucleusPlugin::delete_option_values('category', (integer) $catid); // delete category - $query = 'DELETE FROM ' . sql_table('category') . ' WHERE catid=' . $catid; - sql_query($query); + $query = "DELETE FROM %s WHERE catid=%d;"; + $query = sprintf($query, sql_table('category'), (integer) $catid); + DB::execute($query); - $manager->notify( - 'PostDeleteCategory', - array( - 'catid' => $catid - ) - ); + $data = array('catid' => $catid); + $manager->notify('PostDeleteCategory', $data); return; } /** + * Admin::moveOneCategory() + * Delete a category by its id + * + * @param int $catid category id for move + * @param int $destblogid blog id for destination + * @return void + */ + static public function moveOneCategory($catid, $destblogid) + { + global $manager, $member; + $catid = intval($catid); + $destblogid = intval($destblogid); + $blogid = getBlogIDFromCatID($catid); + // mover should have admin rights on both blogs + if (!$member->blogAdminRights($blogid)) { + return _ERROR_DISALLOWED; + } + if (!$member->blogAdminRights($destblogid)) { + return _ERROR_DISALLOWED; + } + // cannot move to self + if ($blogid == $destblogid) { + return _ERROR_MOVETOSELF; + } + // get blogs + $blog =& $manager->getBlog($blogid); + $destblog =& $manager->getBlog($destblogid); + // check if the category is valid + if (!$blog || !$blog->isValidCategory($catid)) { + return _ERROR_NOSUCHCATEGORY; + } + // don't allow default category to be moved + if ($blog->getDefaultCategory() == $catid) { + return _ERROR_MOVEDEFCATEGORY; + } + $manager->notify( + 'PreMoveCategory', + array( + 'catid' => &$catid, + 'sourceblog' => &$blog, + 'destblog' => &$destblog + ) + ); + // update comments table (cblog) + $query = 'SELECT ' + . ' inumber ' + . 'FROM ' + . sql_table('item') . ' ' + . 'WHERE ' + . ' icat = %d'; + $items = sql_query(sprintf($query, $catid)); + while ($oItem = sql_fetch_object($items)) { + $query = 'UPDATE ' + . sql_table('comment') . ' ' + . 'SET ' + . ' cblog = %d' . ' ' + . 'WHERE ' + . ' citem = %d'; + sql_query(sprintf($query, $destblogid, $oItem->inumber)); + } + + // update items (iblog) + $query = 'UPDATE ' + . sql_table('item') . ' ' + . 'SET ' + . ' iblog = %d ' + . 'WHERE ' + . ' icat = %d'; + sql_query(sprintf($query, $destblogid, $catid)); + + // move category + $query = 'UPDATE ' + . sql_table('category') . ' ' + . 'SET ' + . ' cblog = %d' . ' ' + . 'WHERE ' + . ' catid = %d'; + sql_query(sprintf($query, $destblogid, $catid)); + $manager->notify( + 'PostMoveCategory', + array( + 'catid' => &$catid, + 'sourceblog' => &$blog, + 'destblog' => $destblog + ) + ); + return; + } + + /** * Admin::action_blogsettingsupdate * Updating blog settings * * @param Void * @return Void */ - function action_blogsettingsupdate() + static private function action_blogsettingsupdate() { global $member, $manager; $blogid = intRequestVar('blogid'); - $member->blogAdminRights($blogid) or $this->disallow(); + $member->blogAdminRights($blogid) or self::disallow(); $blog =& $manager->getBlog($blogid); $notify_address = trim(postVar('notify')); - $shortname = trim(postVar('shortname')); - $updatefile = trim(postVar('update')); + $shortname = trim(postVar('shortname')); + $updatefile = trim(postVar('update')); $notifyComment = intPostVar('notifyComment'); $notifyVote = intPostVar('notifyVote'); @@ -2236,22 +2445,22 @@ class Admin if ( $notify_address && !NOTIFICATION::address_validation($notify_address) ) { - $this->error(_ERROR_BADNOTIFY); + self::error(_ERROR_BADNOTIFY); } if ( !isValidShortName($shortname) ) { - $this->error(_ERROR_BADSHORTBLOGNAME); + self::error(_ERROR_BADSHORTBLOGNAME); } if ( ($blog->getShortName() != $shortname) && $manager->existsBlog($shortname) ) { - $this->error(_ERROR_DUPSHORTBLOGNAME); + self::error(_ERROR_DUPSHORTBLOGNAME); } // check if update file is writable if ( $updatefile && !is_writeable($updatefile) ) { - $this->error(_ERROR_UPDATEFILE); + self::error(_ERROR_UPDATEFILE); } $blog->setName(trim(postVar('name'))); @@ -2276,41 +2485,42 @@ class Admin // store plugin options $aOptions = requestArray('plugoption'); NucleusPlugin::apply_plugin_options($aOptions); - $manager->notify( - 'PostPluginOptionsUpdate', - array( - 'context' => 'blog', - 'blogid' => $blogid, - 'blog' => &$blog - ) + + $data = array( + 'context' => 'blog', + 'blogid' => $blogid, + 'blog' => &$blog ); + $manager->notify('PostPluginOptionsUpdate', $data); - $this->action_overview(_MSG_SETTINGSCHANGED); + self::action_overview(_MSG_SETTINGSCHANGED); return; } - + /** - * @todo document this + * Admin::action_deleteblog() + * + * @param void + * @return void */ - function action_deleteblog() + static private function action_deleteblog() { global $member, $CONF, $manager; - + $blogid = intRequestVar('blogid'); - - $member->blogAdminRights($blogid) or $this->disallow(); - + + $member->blogAdminRights($blogid) or self::disallow(); + // check if blog is default blog if ( $CONF['DefaultBlog'] == $blogid ) { - $this->error(_ERROR_DELDEFBLOG); + self::error(_ERROR_DELDEFBLOG); } - + $blog =& $manager->getBlog($blogid); - - $this->pagehead(); - $this->parse('deleteblog'); - $this->pagefoot(); + + self::$skin->parse('deleteblog'); + return; } /** @@ -2320,106 +2530,106 @@ class Admin * @param Void * @return Void */ - function action_deleteblogconfirm() + static private function action_deleteblogconfirm() { global $member, $CONF, $manager; $blogid = intRequestVar('blogid'); - $manager->notify( - 'PreDeleteBlog', - array( - 'blogid' => $blogid - ) - ); - $member->blogAdminRights($blogid) or $this->disallow(); + + $data = array('blogid' => $blogid); + $manager->notify('PreDeleteBlog', $data); + + $member->blogAdminRights($blogid) or self::disallow(); // check if blog is default blog if ( $CONF['DefaultBlog'] == $blogid ) { - $this->error(_ERROR_DELDEFBLOG); + self::error(_ERROR_DELDEFBLOG); } // delete all comments $query = 'DELETE FROM ' . sql_table('comment') . ' WHERE cblog='.$blogid; - sql_query($query); + DB::execute($query); // delete all items $query = 'DELETE FROM ' . sql_table('item') . ' WHERE iblog=' . $blogid; - sql_query($query); + DB::execute($query); // delete all team members $query = 'DELETE FROM ' . sql_table('team') . ' WHERE tblog=' . $blogid; - sql_query($query); + DB::execute($query); // delete all bans $query = 'DELETE FROM ' . sql_table('ban') . ' WHERE blogid=' . $blogid; - sql_query($query); + DB::execute($query); // delete all categories $query = 'DELETE FROM ' . sql_table('category') . ' WHERE cblog=' . $blogid; - sql_query($query); + DB::execute($query); // delete all associated plugin options NucleusPlugin::delete_option_values('blog', $blogid); // delete the blog itself $query = 'DELETE FROM ' . sql_table('blog') . ' WHERE bnumber=' . $blogid; - sql_query($query); + DB::execute($query); - $manager->notify( - 'PostDeleteBlog', - array( - 'blogid' => $blogid - ) - ); + $data = array('blogid' => $blogid); + $manager->notify('PostDeleteBlog', $data); - $this->action_overview(_DELETED_BLOG); + self::action_overview(_DELETED_BLOG); return; } /** - * @todo document this + * Admin::action_memberdelete() + * + * @param void + * @return void */ - function action_memberdelete() + static private function action_memberdelete() { global $member, $manager; - + $memberid = intRequestVar('memberid'); - - ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow(); - - $mem = Member::createFromID($memberid); - - $this->pagehead(); - $this->parse('memberdelete'); - $this->pagefoot(); + + ($member->getID() == $memberid) or $member->isAdmin() or self::disallow(); + + $mem =& $manager->getMember($memberid); + + self::$skin->parse('memberdelete'); + return; } - + /** - * @todo document this + * Admin::action_memberdeleteconfirm() + * + * @param void + * @return void */ - function action_memberdeleteconfirm() + static private function action_memberdeleteconfirm() { global $member; - + $memberid = intRequestVar('memberid'); - - ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow(); - - $error = $this->deleteOneMember($memberid); + + ($member->getID() == $memberid) or $member->isAdmin() or self::disallow(); + + $error = self::deleteOneMember($memberid); if ( $error ) { - $this->error($error); + self::error($error); } - + if ( $member->isAdmin() ) { - $this->action_usermanagement(); + self::action_usermanagement(); } else { - $this->action_overview(_DELETED_MEMBER); + self::action_overview(_DELETED_MEMBER); } + return; } /** @@ -2430,368 +2640,354 @@ class Admin * @params Integer $memberid member id * @return String null string or error messages */ - function deleteOneMember($memberid) + static public function deleteOneMember($memberid) { global $manager; $memberid = intval($memberid); - $mem = Member::createFromID($memberid); + $mem =& $manager->getMember($memberid); if ( !$mem->canBeDeleted() ) { return _ERROR_DELETEMEMBER; } - $manager->notify( - 'PreDeleteMember', - array( - 'member' => &$mem - ) - ); + $data = array('member' => &$mem); + $manager->notify('PreDeleteMember', $data); /* unlink comments from memberid */ if ( $memberid ) { - $query = "UPDATE %s SET cmember=0, cuser='%s' WHERE cmember=%d"; - $query = sprintf($query, sql_table('comment'), sql_real_escape_string($mem->getDisplayName()), $memberid); - sql_query($query); + $query = "UPDATE %s SET cmember=0, cuser=%s WHERE cmember=%d;"; + $query = sprintf($query, sql_table('comment'), DB::quoteValue($mem->getDisplayName()), $memberid); + DB::execute($query); } $query = 'DELETE FROM ' . sql_table('member') . ' WHERE mnumber=' . $memberid; - sql_query($query); + DB::execute($query); $query = 'DELETE FROM ' . sql_table('team') . ' WHERE tmember=' . $memberid; - sql_query($query); + DB::execute($query); $query = 'DELETE FROM ' . sql_table('activation') . ' WHERE vmember=' . $memberid; - sql_query($query); + DB::execute($query); // delete all associated plugin options NucleusPlugin::delete_option_values('member', $memberid); - $manager->notify( - 'PostDeleteMember', - array( - 'member' => &$mem - ) - ); + $data = array('member' => &$mem); + $manager->notify('PostDeleteMember', $data); return ''; } /** - * @todo document this + * Admin::action_createnewlog() + * + * @param void + * @return void */ - function action_createnewlog() + static private function action_createnewlog() { global $member, $CONF, $manager; - + // Only Super-Admins can do this - $member->isAdmin() or $this->disallow(); - - $this->pagehead(); - $this->parse('createnewlog'); - $this->pagefoot(); + $member->isAdmin() or self::disallow(); + + self::$skin->parse('createnewlog'); + return; } - + /** - * @todo document this + * Admin::action_addnewlog() + * + * @param void + * @return void */ - function action_addnewlog() + static private function action_addnewlog() { global $member, $manager, $CONF; - + // Only Super-Admins can do this - $member->isAdmin() or $this->disallow(); - - $bname = trim(postVar('name')); - $bshortname = trim(postVar('shortname')); - $btimeoffset = postVar('timeoffset'); - $bdesc = trim(postVar('desc')); - $bdefskin = postVar('defskin'); - + $member->isAdmin() or self::disallow(); + + $bname = trim(postVar('name')); + $bshortname = trim(postVar('shortname')); + $btimeoffset = postVar('timeoffset'); + $bdesc = trim(postVar('desc')); + $bdefskin = postVar('defskin'); + if ( !isValidShortName($bshortname) ) { - $this->error(_ERROR_BADSHORTBLOGNAME); + self::error(_ERROR_BADSHORTBLOGNAME); } - + if ( $manager->existsBlog($bshortname) ) { - $this->error(_ERROR_DUPSHORTBLOGNAME); + self::error(_ERROR_DUPSHORTBLOGNAME); } - - $manager->notify( - 'PreAddBlog', - array( - 'name' => &$bname, - 'shortname' => &$bshortname, - 'timeoffset' => &$btimeoffset, - 'description' => &$bdesc, - 'defaultskin' => &$bdefskin - ) + + $data = array( + 'name' => &$bname, + 'shortname' => &$bshortname, + 'timeoffset' => &$btimeoffset, + 'description' => &$bdesc, + 'defaultskin' => &$bdefskin ); - - + $manager->notify('PreAddBlog', $data); + // add slashes for sql queries - $bname = sql_real_escape_string($bname); - $bshortname = sql_real_escape_string($bshortname); - $btimeoffset = sql_real_escape_string($btimeoffset); - $bdesc = sql_real_escape_string($bdesc); - $bdefskin = sql_real_escape_string($bdefskin); - + $bname = DB::quoteValue($bname); + $bshortname = DB::quoteValue($bshortname); + $btimeoffset = DB::quoteValue($btimeoffset); + $bdesc = DB::quoteValue($bdesc); + $bdefskin = DB::quoteValue($bdefskin); + // create blog - $query = 'INSERT ' - . 'INTO ' - . sql_table('blog') - . '(' - . ' bname, ' - . ' bshortname, ' - . ' bdesc, ' - . ' btimeoffset, ' - . ' bdefskin' - . ') VALUES (' - . "'" . $bname . "'," - . "'" . $bshortname . "'," - . "'" . $bdesc . "'," - . "'" . $btimeoffset . "'," - . "'" . $bdefskin . "'" - . ")"; - sql_query($query); - $blogid = sql_insert_id(); + $query = "INSERT INTO %s (bname, bshortname, bdesc, btimeoffset, bdefskin) VALUES (%s, %s, %s, %s, %s);"; + $query = sprintf($query, sql_table('blog'), $bname, $bshortname, $bdesc, $btimeoffset, $bdefskin); + DB::execute($query); + + $blogid = DB::getInsertId(); $blog =& $manager->getBlog($blogid); - + // create new category - $catdefname = (defined('_EBLOGDEFAULTCATEGORY_NAME') ? _EBLOGDEFAULTCATEGORY_NAME : 'General'); - $catdefdesc = (defined('_EBLOGDEFAULTCATEGORY_DESC') ? _EBLOGDEFAULTCATEGORY_DESC : 'Items that do not fit in other categories'); - $sql = 'INSERT INTO %s (cblog, cname, cdesc) VALUES (%d, "%s", "%s")'; - sql_query(sprintf($sql, sql_table('category'), $blogid, $catdefname, $catdefdesc)); - $catid = sql_insert_id(); - + $catdefname = (!defined('_EBLOGDEFAULTCATEGORY_NAME') ? 'General' : _EBLOGDEFAULTCATEGORY_NAME); + $catdefdesc = (!defined('_EBLOGDEFAULTCATEGORY_DESC') ? 'Items that do not fit in other categories' : _EBLOGDEFAULTCATEGORY_DESC); + + $query = 'INSERT INTO %s (cblog, cname, cdesc) VALUES (%d, %s, %s)'; + DB::execute(sprintf($query, sql_table('category'), (integer) $blogid, DB::quoteValue($catdefname), DB::quoteValue($catdefdesc))); + $catid = DB::getInsertId(); + // set as default category $blog->setDefaultCategory($catid); $blog->writeSettings(); - + // create team member - $memberid = $member->getID(); - $query = 'INSERT ' - . 'INTO ' - . sql_table('team') - . '(' - . ' tmember, ' - . ' tblog, ' - . ' tadmin' - . ') VALUES (' - . '%d, ' - . '%d, ' - . ' 1' - . ')'; - sql_query(sprintf($query), $memberid, $blogid); - + $query = "INSERT INTO %s (tmember, tblog, tadmin) VALUES (%d, %d, 1);"; + $query = sprintf($query, sql_table('team'), (integer) $member->getID(), (integer) $blogid); + DB::execute($query); + $itemdeftitle = (defined('_EBLOG_FIRSTITEM_TITLE') ? _EBLOG_FIRSTITEM_TITLE : 'First Item'); $itemdefbody = (defined('_EBLOG_FIRSTITEM_BODY') ? _EBLOG_FIRSTITEM_BODY : 'This is the first item in your weblog. Feel free to delete it.'); - + $blog->additem( $blog->getDefaultCategory(), $itemdeftitle,$itemdefbody, '', $blogid, - $memberid, + $member->getID(), $blog->getCorrectTime(), 0, 0, 0 ); - $manager->notify( - 'PostAddBlog', - array( - 'blog' => &$blog - ) - ); - - $manager->notify( - 'PostAddCategory', - array( - 'blog' => &$blog, - 'name' => _EBLOGDEFAULTCATEGORY_NAME, - 'description' => _EBLOGDEFAULTCATEGORY_DESC, - 'catid' => $catid - ) + + $data = array('blog' => &$blog); + $manager->notify('PostAddBlog', $data); + + $data = array( + 'blog' => &$blog, + 'name' => _EBLOGDEFAULTCATEGORY_NAME, + 'description' => _EBLOGDEFAULTCATEGORY_DESC, + 'catid' => $catid ); - + $manager->notify('PostAddCategory', $data); + + /* TODO: we should consider to use the other way insterad of this */ $_REQUEST['blogid'] = $blogid; $_REQUEST['catid'] = $catid; - $this->pagehead(); - $this->parse('addnewlog'); - $this->pagefoot(); + self::$skin->parse('addnewlog'); + return; } - + /** - * @todo document this + * Admin::action_addnewlog2() + * + * @param void + * @return void */ - function action_addnewlog2() + static private function action_addnewlog2() { global $member, $manager; $blogid = intRequestVar('blogid'); - - $member->blogAdminRights($blogid) or $this->disallow(); - - $burl = requestVar('url'); - + + $member->blogAdminRights($blogid) or self::disallow(); + + $burl = requestVar('url'); + $blog =& $manager->getBlog($blogid); $blog->setURL(trim($burl)); $blog->writeSettings(); - - $this->action_overview(_MSG_NEWBLOG); + + self::action_overview(_MSG_NEWBLOG); + return; } - + /** - * @todo document this + * Admin::action_skinieoverview() + * + * @param void + * @return void */ - function action_skinieoverview() + static private function action_skinieoverview() { global $member, $DIR_LIBS, $manager; - - $member->isAdmin() or $this->disallow(); - - // load skinie class + + $member->isAdmin() or self::disallow(); + include_once($DIR_LIBS . 'skinie.php'); - - $this->pagehead(); - $this->parse('skinieoverview'); - $this->pagefoot(); - + + self::$skin->parse('skinieoverview'); + return; } - + /** - * @todo document this + * Admin::action_skinieimport() + * + * @param void + * @return void */ - function action_skinieimport() { + static private function action_skinieimport() + { global $member, $DIR_LIBS, $DIR_SKINS, $manager; - - $member->isAdmin() or $this->disallow(); - + + $member->isAdmin() or self::disallow(); + // load skinie class include_once($DIR_LIBS . 'skinie.php'); - - $skinFileRaw = postVar('skinfile'); - $mode = postVar('mode'); - + + $skinFileRaw = postVar('skinfile'); + $mode = postVar('mode'); + $importer = new SkinImport(); - + // get full filename - if ($mode == 'file') + if ( $mode == 'file' ) { $skinFile = $DIR_SKINS . $skinFileRaw . '/skinbackup.xml'; - + + /* TODO: remove this // backwards compatibilty (in v2.0, exports were saved as skindata.xml) if ( !file_exists($skinFile) ) { $skinFile = $DIR_SKINS . $skinFileRaw . '/skindata.xml'; } - } else { + */ + } + else + { $skinFile = $skinFileRaw; } - + // read only metadata $error = $importer->readFile($skinFile, 1); - - $_REQUEST['skininfo'] = $importer->getInfo(); - $_REQUEST['skinnames'] = $importer->getSkinNames(); - $_REQUEST['tpltnames'] = $importer->getTemplateNames(); - + + /* TODO: we should consider to use the other way insterad of this */ + $_REQUEST['skininfo'] = $importer->getInfo(); + $_REQUEST['skinnames'] = $importer->getSkinNames(); + $_REQUEST['tpltnames'] = $importer->getTemplateNames(); + // clashes - $skinNameClashes = $importer->checkSkinNameClashes(); - $templateNameClashes = $importer->checkTemplateNameClashes(); - $hasNameClashes = (count($skinNameClashes) > 0) || (count($templateNameClashes) > 0); - + $skinNameClashes = $importer->checkSkinNameClashes(); + $templateNameClashes = $importer->checkTemplateNameClashes(); + $hasNameClashes = (count($skinNameClashes) > 0) || (count($templateNameClashes) > 0); + + /* TODO: we should consider to use the other way insterad of this */ $_REQUEST['skinclashes'] = $skinNameClashes; $_REQUEST['tpltclashes'] = $templateNameClashes; $_REQUEST['nameclashes'] = $hasNameClashes ? 1 : 0; if ( $error ) { - $this->error($error); + self::error($error); } - - $this->pagehead(); - $this->parse('skinieimport'); - $this->pagefoot(); + + self::$skin->parse('skinieimport'); + return; } - + /** - * @todo document this + * Admin::action_skiniedoimport() + * + * @param void + * @return void */ - function action_skiniedoimport() + static private function action_skiniedoimport() { global $member, $DIR_LIBS, $DIR_SKINS; - - $member->isAdmin() or $this->disallow(); - + + $member->isAdmin() or self::disallow(); + // load skinie class include_once($DIR_LIBS . 'skinie.php'); - - $skinFileRaw= postVar('skinfile'); - $mode = postVar('mode'); - + + $skinFileRaw = postVar('skinfile'); + $mode = postVar('mode'); + $allowOverwrite = intPostVar('overwrite'); - + // get full filename if ( $mode == 'file' ) { $skinFile = $DIR_SKINS . $skinFileRaw . '/skinbackup.xml'; - + + /* TODO: remove this // backwards compatibilty (in v2.0, exports were saved as skindata.xml) if ( !file_exists($skinFile) ) { $skinFile = $DIR_SKINS . $skinFileRaw . '/skindata.xml'; } - + */ } else { $skinFile = $skinFileRaw; } - + $importer = new SkinImport(); - - $error = $importer->readFile($skinFile); - + + $error = $importer->readFile($skinFile); + if ( $error ) { - $this->error($error); + self::error($error); } - + $error = $importer->writeToDatabase($allowOverwrite); - + if ( $error ) { - $this->error($error); + self::error($error); } - + + /* TODO: we should consider to use the other way insterad of this */ $_REQUEST['skininfo'] = $importer->getInfo(); $_REQUEST['skinnames'] = $importer->getSkinNames(); $_REQUEST['tpltnames'] = $importer->getTemplateNames(); - - $this->pagehead(); - $this->parse('skiniedoimport'); - $this->pagefoot(); + + self::$skin->parse('skiniedoimport'); + return; } /** - * @todo document this + * Admin::action_skinieexport() + * + * @param void + * @return void */ - function action_skinieexport() + static private function action_skinieexport() { global $member, $DIR_LIBS; - - $member->isAdmin() or $this->disallow(); - - // load skinie class + + $member->isAdmin() or self::disallow(); + + // load skinie class include_once($DIR_LIBS . 'skinie.php'); - - $aSkins = requestIntArray('skin'); - $aTemplates = requestIntArray('template'); - + + $aSkins = requestIntArray('skin'); + $aTemplates = requestIntArray('template'); + if ( !is_array($aTemplates) ) { $aTemplates = array(); @@ -2800,14 +2996,14 @@ class Admin { $aSkins = array(); } - - $skinList = array_keys($aSkins); - $templateList = array_keys($aTemplates); - + + $skinList = array_keys($aSkins); + $templateList = array_keys($aTemplates); + $info = postVar('info'); - + $exporter = new SkinExport(); - foreach ($skinList as $skinId) + foreach ( $skinList as $skinId ) { $exporter->addSkin($skinId); } @@ -2816,158 +3012,140 @@ class Admin $exporter->addTemplate($templateId); } $exporter->setInfo($info); - + $exporter->export(); + return; } - + /** - * @todo document this + * Admin::action_templateoverview() + * + * @param void + * @return void */ - function action_templateoverview() + static private function action_templateoverview() { global $member, $manager; - - $member->isAdmin() or $this->disallow(); - - $this->pagehead(); - $this->parse('templateoverview'); - $this->pagefoot(); + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('templateoverview'); + return; } - + /** - * @todo document this + * Admin::action_templateedit() + * + * @param string $msg message for pageheader + * @return void */ - function action_templateedit($msg = '') + static private function action_templateedit($msg = '') { global $member, $manager; if ( $msg ) { - $this->headMess = $msg; + self::$headMess = $msg; } $templateid = intRequestVar('templateid'); - - $member->isAdmin() or $this->disallow(); - - $extrahead = ''; - $extrahead .= ''; - - $this->pagehead($extrahead); - $this->parse('templateedit'); - $this->pagefoot(); + + $member->isAdmin() or self::disallow(); + + Admin::$extrahead .= "\n"; + Admin::$extrahead .= "\n"; + + self::$skin->parse('templateedit'); + return; } - - /** - * @todo document this - * - function _templateEditRow(&$template, $description, $name, $help = '', $tabindex = 0, $big = 0) { - static $count = 1; - if (!isset($template[$name])) $template[$name] = ''; - ?> - - - - isAdmin() or $this->disallow(); - + + $member->isAdmin() or self::disallow(); + $name = postVar('tname'); $desc = postVar('tdesc'); - + if ( !isValidTemplateName($name) ) { - $this->error(_ERROR_BADTEMPLATENAME); + self::error(_ERROR_BADTEMPLATENAME); } - + if ( (Template::getNameFromId($templateid) != $name) && Template::exists($name) ) { - $this->error(_ERROR_DUPTEMPLATENAME); + self::error(_ERROR_DUPTEMPLATENAME); } - - $name = sql_real_escape_string($name); - $desc = sql_real_escape_string($desc); - + // 1. Remove all template parts - $query = 'DELETE FROM ' . sql_table('template') . ' WHERE tdesc=' . $templateid; - sql_query($query); - + $query = "DELETE FROM %s WHERE tdesc=%d;"; + $query = sprintf($query, sql_table('template'), (integer) $templateid); + DB::execute($query); + // 2. Update description - $query = 'UPDATE ' - . sql_table('template_desc') - . ' SET' - . " tdname='" . $name . "'," - . " tddesc='" . $desc . "'" - . " WHERE" - . " tdnumber=" . $templateid; - sql_query($query); - + $query = "UPDATE %s SET tdname=%s, tddesc=%s WHERE tdnumber=%d;"; + $query = sprintf($query, sql_table('template_desc'), DB::quoteValue($name), DB::quoteValue($desc), (integer) $templateid); + DB::execute($query); + // 3. Add non-empty template parts - $this->addToTemplate($templateid, 'ITEM_HEADER', postVar('ITEM_HEADER')); - $this->addToTemplate($templateid, 'ITEM', postVar('ITEM')); - $this->addToTemplate($templateid, 'ITEM_FOOTER', postVar('ITEM_FOOTER')); - $this->addToTemplate($templateid, 'MORELINK', postVar('MORELINK')); - $this->addToTemplate($templateid, 'EDITLINK', postVar('EDITLINK')); - $this->addToTemplate($templateid, 'NEW', postVar('NEW')); - $this->addToTemplate($templateid, 'COMMENTS_HEADER', postVar('COMMENTS_HEADER')); - $this->addToTemplate($templateid, 'COMMENTS_BODY', postVar('COMMENTS_BODY')); - $this->addToTemplate($templateid, 'COMMENTS_FOOTER', postVar('COMMENTS_FOOTER')); - $this->addToTemplate($templateid, 'COMMENTS_CONTINUED', postVar('COMMENTS_CONTINUED')); - $this->addToTemplate($templateid, 'COMMENTS_TOOMUCH', postVar('COMMENTS_TOOMUCH')); - $this->addToTemplate($templateid, 'COMMENTS_AUTH', postVar('COMMENTS_AUTH')); - $this->addToTemplate($templateid, 'COMMENTS_ONE', postVar('COMMENTS_ONE')); - $this->addToTemplate($templateid, 'COMMENTS_MANY', postVar('COMMENTS_MANY')); - $this->addToTemplate($templateid, 'COMMENTS_NONE', postVar('COMMENTS_NONE')); - $this->addToTemplate($templateid, 'ARCHIVELIST_HEADER', postVar('ARCHIVELIST_HEADER')); - $this->addToTemplate($templateid, 'ARCHIVELIST_LISTITEM', postVar('ARCHIVELIST_LISTITEM')); - $this->addToTemplate($templateid, 'ARCHIVELIST_FOOTER', postVar('ARCHIVELIST_FOOTER')); - $this->addToTemplate($templateid, 'BLOGLIST_HEADER', postVar('BLOGLIST_HEADER')); - $this->addToTemplate($templateid, 'BLOGLIST_LISTITEM', postVar('BLOGLIST_LISTITEM')); - $this->addToTemplate($templateid, 'BLOGLIST_FOOTER', postVar('BLOGLIST_FOOTER')); - $this->addToTemplate($templateid, 'CATLIST_HEADER', postVar('CATLIST_HEADER')); - $this->addToTemplate($templateid, 'CATLIST_LISTITEM', postVar('CATLIST_LISTITEM')); - $this->addToTemplate($templateid, 'CATLIST_FOOTER', postVar('CATLIST_FOOTER')); - $this->addToTemplate($templateid, 'DATE_HEADER', postVar('DATE_HEADER')); - $this->addToTemplate($templateid, 'DATE_FOOTER', postVar('DATE_FOOTER')); - $this->addToTemplate($templateid, 'FORMAT_DATE', postVar('FORMAT_DATE')); - $this->addToTemplate($templateid, 'FORMAT_TIME', postVar('FORMAT_TIME')); - $this->addToTemplate($templateid, 'LOCALE', postVar('LOCALE')); - $this->addToTemplate($templateid, 'SEARCH_HIGHLIGHT', postVar('SEARCH_HIGHLIGHT')); - $this->addToTemplate($templateid, 'SEARCH_NOTHINGFOUND', postVar('SEARCH_NOTHINGFOUND')); - $this->addToTemplate($templateid, 'POPUP_CODE', postVar('POPUP_CODE')); - $this->addToTemplate($templateid, 'MEDIA_CODE', postVar('MEDIA_CODE')); - $this->addToTemplate($templateid, 'IMAGE_CODE', postVar('IMAGE_CODE')); - - $pluginfields = array(); - $manager->notify( - 'TemplateExtraFields', - array( - 'fields'=>&$pluginfields - ) - ); - foreach ($pluginfields as $pfkey=>$pfvalue) + self::addToTemplate($templateid, 'ITEM_HEADER', postVar('ITEM_HEADER')); + self::addToTemplate($templateid, 'ITEM', postVar('ITEM')); + self::addToTemplate($templateid, 'ITEM_FOOTER', postVar('ITEM_FOOTER')); + self::addToTemplate($templateid, 'MORELINK', postVar('MORELINK')); + self::addToTemplate($templateid, 'EDITLINK', postVar('EDITLINK')); + self::addToTemplate($templateid, 'NEW', postVar('NEW')); + self::addToTemplate($templateid, 'COMMENTS_HEADER', postVar('COMMENTS_HEADER')); + self::addToTemplate($templateid, 'COMMENTS_BODY', postVar('COMMENTS_BODY')); + self::addToTemplate($templateid, 'COMMENTS_FOOTER', postVar('COMMENTS_FOOTER')); + self::addToTemplate($templateid, 'COMMENTS_CONTINUED', postVar('COMMENTS_CONTINUED')); + self::addToTemplate($templateid, 'COMMENTS_TOOMUCH', postVar('COMMENTS_TOOMUCH')); + self::addToTemplate($templateid, 'COMMENTS_AUTH', postVar('COMMENTS_AUTH')); + self::addToTemplate($templateid, 'COMMENTS_ONE', postVar('COMMENTS_ONE')); + self::addToTemplate($templateid, 'COMMENTS_MANY', postVar('COMMENTS_MANY')); + self::addToTemplate($templateid, 'COMMENTS_NONE', postVar('COMMENTS_NONE')); + self::addToTemplate($templateid, 'ARCHIVELIST_HEADER', postVar('ARCHIVELIST_HEADER')); + self::addToTemplate($templateid, 'ARCHIVELIST_LISTITEM', postVar('ARCHIVELIST_LISTITEM')); + self::addToTemplate($templateid, 'ARCHIVELIST_FOOTER', postVar('ARCHIVELIST_FOOTER')); + self::addToTemplate($templateid, 'BLOGLIST_HEADER', postVar('BLOGLIST_HEADER')); + self::addToTemplate($templateid, 'BLOGLIST_LISTITEM', postVar('BLOGLIST_LISTITEM')); + self::addToTemplate($templateid, 'BLOGLIST_FOOTER', postVar('BLOGLIST_FOOTER')); + self::addToTemplate($templateid, 'CATLIST_HEADER', postVar('CATLIST_HEADER')); + self::addToTemplate($templateid, 'CATLIST_LISTITEM', postVar('CATLIST_LISTITEM')); + self::addToTemplate($templateid, 'CATLIST_FOOTER', postVar('CATLIST_FOOTER')); + self::addToTemplate($templateid, 'DATE_HEADER', postVar('DATE_HEADER')); + self::addToTemplate($templateid, 'DATE_FOOTER', postVar('DATE_FOOTER')); + self::addToTemplate($templateid, 'FORMAT_DATE', postVar('FORMAT_DATE')); + self::addToTemplate($templateid, 'FORMAT_TIME', postVar('FORMAT_TIME')); + self::addToTemplate($templateid, 'LOCALE', postVar('LOCALE')); + self::addToTemplate($templateid, 'SEARCH_HIGHLIGHT', postVar('SEARCH_HIGHLIGHT')); + self::addToTemplate($templateid, 'SEARCH_NOTHINGFOUND', postVar('SEARCH_NOTHINGFOUND')); + self::addToTemplate($templateid, 'POPUP_CODE', postVar('POPUP_CODE')); + self::addToTemplate($templateid, 'MEDIA_CODE', postVar('MEDIA_CODE')); + self::addToTemplate($templateid, 'IMAGE_CODE', postVar('IMAGE_CODE')); + + $data = array('fields' => array()); + $manager->notify('TemplateExtraFields', $data); + foreach ( $data['fields'] as $pfkey=>$pfvalue ) { - foreach ($pfvalue as $pffield=>$pfdesc) + foreach ( $pfvalue as $pffield => $pfdesc ) { - $this->addToTemplate($templateid, $pffield, postVar($pffield)); + self::addToTemplate($templateid, $pffield, postVar($pffield)); } } - + // jump back to template edit - $this->action_templateedit(_TEMPLATE_UPDATED); - + self::action_templateedit(_TEMPLATE_UPDATED); + return; } - + /** * Admin::addToTemplate() * @@ -2977,7 +3155,7 @@ class Admin * @return Integer record index * */ - function addToTemplate($id, $partname, $content) + static private function addToTemplate($id, $partname, $content) { // don't add empty parts: if ( !trim($content) ) @@ -2985,111 +3163,121 @@ class Admin return -1; } - $partname = sql_real_escape_string($partname); - $content = sql_real_escape_string($content); - - $query = "INSERT INTO %s (tdesc, tpartname, tcontent) VALUES (%d, '%s', '%s')"; - $query = sprintf($query, sql_table('template'), (integer) $id, $partname, $content); - sql_query($query) or exit(_ADMIN_SQLDIE_QUERYERROR . sql_error()); - return sql_insert_id(); + $query = "INSERT INTO %s (tdesc, tpartname, tcontent) VALUES (%d, %s, %s);"; + $query = sprintf($query, sql_table('template'), (integer) $id, DB::quoteValue($partname), DB::quoteValue($content)); + if ( DB::execute($query) === FALSE ) + { + $err = DB::getError(); + exit(_ADMIN_SQLDIE_QUERYERROR . $err[2]); + } + return DB::getInsertId(); } /** - * @todo document this + * Admin::action_templatedelete() + * + * @param void + * @return void */ - function action_templatedelete() { + static private function action_templatedelete() + { global $member, $manager; - - $member->isAdmin() or $this->disallow(); - + + $member->isAdmin() or self::disallow(); + $templateid = intRequestVar('templateid'); // TODO: check if template can be deleted - - $this->pagehead(); - $this->parse('templatedelete'); - $this->pagefoot(); + + self::$skin->parse('templatedelete'); + return; } - + /** - * @todo document this + * Admin::action_templatedeleteconfirm() + * + * @param void + * @return void */ - function action_templatedeleteconfirm() { + static private function action_templatedeleteconfirm() + { global $member, $manager; - + $templateid = intRequestVar('templateid'); - - $member->isAdmin() or $this->disallow(); - - $manager->notify( - 'PreDeleteTemplate', - array( - 'templateid' => $templateid - ) - ); - + + $member->isAdmin() or self::disallow(); + + $data = array('templateid' => $templateid); + $manager->notify('PreDeleteTemplate', $data); + // 1. delete description - sql_query('DELETE FROM ' . sql_table('template_desc') . ' WHERE tdnumber=' . $templateid); - + DB::execute('DELETE FROM ' . sql_table('template_desc') . ' WHERE tdnumber=' . $templateid); + // 2. delete parts - sql_query('DELETE FROM ' . sql_table('template') . ' WHERE tdesc=' . $templateid); - - $manager->notify( - 'PostDeleteTemplate', - array( - 'templateid' => $templateid - ) - ); - - $this->action_templateoverview(); + DB::execute('DELETE FROM ' . sql_table('template') . ' WHERE tdesc=' . $templateid); + + + $data = array('templateid' => $templateid); + $manager->notify('PostDeleteTemplate', $data); + + self::action_templateoverview(); + return; } - + /** - * @todo document this + * Admin::action_templatenew() + * + * @param void + * @return void */ - function action_templatenew() + static private function action_templatenew() { global $member; - - $member->isAdmin() or $this->disallow(); - + + $member->isAdmin() or self::disallow(); + $name = postVar('name'); $desc = postVar('desc'); - + if ( !isValidTemplateName($name) ) { - $this->error(_ERROR_BADTEMPLATENAME); + self::error(_ERROR_BADTEMPLATENAME); } - + if ( Template::exists($name) ) { - $this->error(_ERROR_DUPTEMPLATENAME); + self::error(_ERROR_DUPTEMPLATENAME); } - + $newTemplateId = Template::createNew($name, $desc); - - $this->action_templateoverview(); + + self::action_templateoverview(); + return; } - + /** - * @todo document this + * Admin::action_templateclone() + * + * @param void + * @return void */ - function action_templateclone() + static private function action_templateclone() { global $member; - + $templateid = intRequestVar('templateid'); - - $member->isAdmin() or $this->disallow(); - + + $member->isAdmin() or self::disallow(); + // 1. read old template $name = Template::getNameFromId($templateid); $desc = Template::getDesc($templateid); - + // 2. create desc thing $name = "cloned" . $name; - + // if a template with that name already exists: - if (Template::exists($name)) { + if ( Template::exists($name) ) + { $i = 1; while (Template::exists($name . $i)) { @@ -3097,454 +3285,465 @@ class Admin } $name .= $i; } - + $newid = Template::createNew($name, $desc); - + // 3. create clone // go through parts of old template and add them to the new one - $que = 'SELECT ' - . ' tpartname,' - . ' tcontent ' - . 'FROM ' - . sql_table('template') - . ' WHERE' - . ' tdesc=' . intval($templateid); - $res = sql_query($que); - while ($o = sql_fetch_object($res)) { - $this->addToTemplate($newid, $o->tpartname, $o->tcontent); + $query = "SELECT tpartname, tcontent FROM %s WHERE tdesc=%d;"; + $query = sprintf($query, sql_table('template'), (integer) $templateid); + + $res = DB::getResult($query); + foreach ( $res as $row) + { + self::addToTemplate($newid, $row['tpartname'], $row['tcontent']); } - - $this->action_templateoverview(); + + self::action_templateoverview(); + return; } /** - * @todo document this + * Admin::action_admintemplateoverview() + * + * @param void + * @return void */ - function action_admintemplateoverview() + static private function action_admintemplateoverview() { - global $member, $manager; - $member->isAdmin() or $this->disallow(); - $this->pagehead(); - $this->parse('admintemplateoverview'); - $this->pagefoot(); + global $member; + $member->isAdmin() or self::disallow(); + self::$skin->parse('admntemplateoverview'); + return; } /** - * @todo document this + * Admin::action_admintemplateedit() + * + * @param string $msg message for pageheader + * @return void */ - function action_admintemplateedit($msg = '') + static private function action_admintemplateedit($msg = '') { global $member, $manager; - if ($msg) { - $this->headMess = $msg; + if ( $msg ) + { + self::$headMess = $msg; } - $member->isAdmin() or $this->disallow(); - $extrahead = '' . "\n"; - $extrahead .= ''; - $this->pagehead($extrahead); - $this->parse('admintemplateedit'); - $this->pagefoot(); + $member->isAdmin() or self::disallow(); + + Admin::$extrahead .= "\n"; + Admin::$extrahead .= '' . "\n"; + + self::$skin->parse('admintemplateedit'); + return; } /** - * @todo document this + * Admin::action_admintemplateupdate() + * + * @param void + * @return void */ - function action_admintemplateupdate() + static private function action_admintemplateupdate() { global $member, $manager; $templateid = intRequestVar('templateid'); - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); $name = postVar('tname'); $desc = postVar('tdesc'); - - if (!isValidTemplateName($name)) { - $this->error(_ERROR_BADTEMPLATENAME); + + if ( !isValidTemplateName($name) ) + { + self::error(_ERROR_BADTEMPLATENAME); } - // if (!class_exists('Template')) { - // NP_SkinableAdmin::loadSkinableClass('Template'); - // } - if ((Template::getNameFromId($templateid) != $name) && Template::exists($name)) { - $this->error(_ERROR_DUPTEMPLATENAME); + + if ( (Template::getNameFromId($templateid) != $name) && Template::exists($name) ) + { + self::error(_ERROR_DUPTEMPLATENAME); } - $name = sql_real_escape_string($name); - $desc = sql_real_escape_string($desc); - + // 1. Remove all template parts - $query = 'DELETE ' - . 'FROM ' - . sql_table('admintemplate') . ' ' - . 'WHERE ' - . ' tdesc = %d'; - sql_query(sprintf($query, $templateid)); - + $query = "DELETE FROM %s WHERE tdesc=%d;"; + $query = sprintf($query, sql_table('template'), (integer) $templateid); + DB::execute($query); + // 2. Update description - $query = 'UPDATE ' - . sql_table('admintemplate_desc') . ' ' - . 'SET ' - . ' tdname = "' . sql_real_escape_string($name) . '", ' - . ' tddesc = "' . sql_real_escape_string($desc) . '" ' - . 'WHERE ' - . ' tdnumber = %d'; - sql_query(sprintf($query, $templateid)); - + $query = "UPDATE %s SET tdname=%s, tddesc=%s WHERE tdnumber=%d;"; + $query = sprintf($query, sql_table('template_desc'), DB::quoteValue($name), DB::quoteValue($desc), (integer) $templateid); + DB::execute($query); + // 3. Add non-empty template parts - $this->addToAdminTemplate($templateid, 'ADMINSKINTYPELIST_HEAD', postVar('ADMINSKINTYPELIST_HEAD')); - $this->addToAdminTemplate($templateid, 'ADMINSKINTYPELIST_BODY', postVar('ADMINSKINTYPELIST_BODY')); - $this->addToAdminTemplate($templateid, 'ADMINSKINTYPELIST_FOOT', postVar('ADMINSKINTYPELIST_FOOT')); - $this->addToAdminTemplate($templateid, 'ADMIN_CUSTOMHELPLINK_ICON', postVar('ADMIN_CUSTOMHELPLINK_ICON')); - $this->addToAdminTemplate($templateid, 'ADMIN_CUSTOMHELPLINK_ANCHOR', postVar('ADMIN_CUSTOMHELPLINK_ANCHOR')); - $this->addToAdminTemplate($templateid, 'ADMIN_BLOGLINK', postVar('ADMIN_BLOGLINK')); - $this->addToAdminTemplate($templateid, 'ADMIN_BATCHLIST', postVar('ADMIN_BATCHLIST')); - $this->addToAdminTemplate($templateid, 'ACTIVATE_FORGOT_TITLE', postVar('ACTIVATE_FORGOT_TITLE')); - $this->addToAdminTemplate($templateid, 'ACTIVATE_FORGOT_TEXT', postVar('ACTIVATE_FORGOT_TEXT')); - $this->addToAdminTemplate($templateid, 'ACTIVATE_REGISTER_TITLE', postVar('ACTIVATE_REGISTER_TITLE')); - $this->addToAdminTemplate($templateid, 'ACTIVATE_REGISTER_TEXT', postVar('ACTIVATE_REGISTER_TEXT')); - $this->addToAdminTemplate($templateid, 'ACTIVATE_CHANGE_TITLE', postVar('ACTIVATE_CHANGE_TITLE')); - $this->addToAdminTemplate($templateid, 'ACTIVATE_CHANGE_TEXT', postVar('ACTIVATE_CHANGE_TEXT')); - $this->addToAdminTemplate($templateid, 'TEMPLATE_EDIT_EXPLUGNAME', postVar('TEMPLATE_EDIT_EXPLUGNAME')); - $this->addToAdminTemplate($templateid, 'TEMPLATE_EDIT_ROW_HEAD', postVar('TEMPLATE_EDIT_ROW_HEAD')); - $this->addToAdminTemplate($templateid, 'TEMPLATE_EDIT_ROW_TAIL', postVar('TEMPLATE_EDIT_ROW_TAIL')); - $this->addToAdminTemplate($templateid, 'SPECIALSKINLIST_HEAD', postVar('SPECIALSKINLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SPECIALSKINLIST_BODY', postVar('SPECIALSKINLIST_BODY')); - $this->addToAdminTemplate($templateid, 'SPECIALSKINLIST_FOOT', postVar('SPECIALSKINLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SYSTEMINFO_GDSETTINGS', postVar('SYSTEMINFO_GDSETTINGS')); - $this->addToAdminTemplate($templateid, 'BANLIST_DELETED_LIST', postVar('BANLIST_DELETED_LIST')); - $this->addToAdminTemplate($templateid, 'INSERT_PLUGOPTION_TITLE', postVar('INSERT_PLUGOPTION_TITLE')); - $this->addToAdminTemplate($templateid, 'INSERT_PLUGOPTION_BODY', postVar('INSERT_PLUGOPTION_BODY')); - $this->addToAdminTemplate($templateid, 'INPUTYESNO_TEMPLATE_ADMIN', postVar('INPUTYESNO_TEMPLATE_ADMIN')); - $this->addToAdminTemplate($templateid, 'INPUTYESNO_TEMPLATE_NORMAL', postVar('INPUTYESNO_TEMPLATE_NORMAL')); - $this->addToAdminTemplate($templateid, 'ADMIN_SPECIALSKINLIST_HEAD', postVar('ADMIN_SPECIALSKINLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'ADMIN_SPECIALSKINLIST_BODY', postVar('ADMIN_SPECIALSKINLIST_BODY')); - $this->addToAdminTemplate($templateid, 'ADMIN_SPECIALSKINLIST_FOOT', postVar('ADMIN_SPECIALSKINLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SKINIE_EXPORT_LIST', postVar('SKINIE_EXPORT_LIST')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_SELECT_HEAD', postVar('SHOWLIST_LISTPLUG_SELECT_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_SELECT_BODY', postVar('SHOWLIST_LISTPLUG_SELECT_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_SELECT_FOOT', postVar('SHOWLIST_LISTPLUG_SELECT_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM', postVar('SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLIST_BD_SADM', postVar('SHOWLIST_LISTPLUG_TABLE_BLIST_BD_SADM')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SHORTNAM_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY')); - $this->addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT')); - $this->addToAdminTemplate($templateid, 'PLUGIN_QUICKMENU_TITLE', postVar('PLUGIN_QUICKMENU_TITLE')); - $this->addToAdminTemplate($templateid, 'PLUGIN_QUICKMENU_HEAD', postVar('PLUGIN_QUICKMENU_HEAD')); - $this->addToAdminTemplate($templateid, 'PLUGIN_QUICKMENU_BODY', postVar('PLUGIN_QUICKMENU_BODY')); - $this->addToAdminTemplate($templateid, 'PLUGIN_QUICKMENU_FOOT', postVar('PLUGIN_QUICKMENU_FOOT')); - - $pluginfields = array(); - $manager->notify( - 'TemplateExtraFields', - array( - 'fields' => &$pluginfields - ) - ); - foreach ($pluginfields as $pfkey => $pfvalue) { - foreach ($pfvalue as $pffield => $pfdesc) { - $this->addToAdminTemplate($templateid, $pffield, postVar($pffield)); + self::addToAdminTemplate($templateid, 'NORMALSKINLIST_HEAD', postVar('NORMALSKINLIST_HEAD')); + self::addToAdminTemplate($templateid, 'NORMALSKINLIST_BODY', postVar('NORMALSKINLIST_BODY')); + self::addToAdminTemplate($templateid, 'NORMALSKINLIST_FOOT', postVar('NORMALSKINLIST_FOOT')); + self::addToAdminTemplate($templateid, 'ADMIN_CUSTOMHELPLINK_ICON', postVar('ADMIN_CUSTOMHELPLINK_ICON')); + self::addToAdminTemplate($templateid, 'ADMIN_CUSTOMHELPLINK_ANCHOR', postVar('ADMIN_CUSTOMHELPLINK_ANCHOR')); + self::addToAdminTemplate($templateid, 'ADMIN_BLOGLINK', postVar('ADMIN_BLOGLINK')); + self::addToAdminTemplate($templateid, 'ADMIN_BATCHLIST', postVar('ADMIN_BATCHLIST')); + self::addToAdminTemplate($templateid, 'ACTIVATE_FORGOT_TITLE', postVar('ACTIVATE_FORGOT_TITLE')); + self::addToAdminTemplate($templateid, 'ACTIVATE_FORGOT_TEXT', postVar('ACTIVATE_FORGOT_TEXT')); + self::addToAdminTemplate($templateid, 'ACTIVATE_REGISTER_TITLE', postVar('ACTIVATE_REGISTER_TITLE')); + self::addToAdminTemplate($templateid, 'ACTIVATE_REGISTER_TEXT', postVar('ACTIVATE_REGISTER_TEXT')); + self::addToAdminTemplate($templateid, 'ACTIVATE_CHANGE_TITLE', postVar('ACTIVATE_CHANGE_TITLE')); + self::addToAdminTemplate($templateid, 'ACTIVATE_CHANGE_TEXT', postVar('ACTIVATE_CHANGE_TEXT')); + self::addToAdminTemplate($templateid, 'TEMPLATE_EDIT_EXPLUGNAME', postVar('TEMPLATE_EDIT_EXPLUGNAME')); + self::addToAdminTemplate($templateid, 'TEMPLATE_EDIT_ROW_HEAD', postVar('TEMPLATE_EDIT_ROW_HEAD')); + self::addToAdminTemplate($templateid, 'TEMPLATE_EDIT_ROW_TAIL', postVar('TEMPLATE_EDIT_ROW_TAIL')); + self::addToAdminTemplate($templateid, 'SPECIALSKINLIST_HEAD', postVar('SPECIALSKINLIST_HEAD')); + self::addToAdminTemplate($templateid, 'SPECIALSKINLIST_BODY', postVar('SPECIALSKINLIST_BODY')); + self::addToAdminTemplate($templateid, 'SPECIALSKINLIST_FOOT', postVar('SPECIALSKINLIST_FOOT')); + self::addToAdminTemplate($templateid, 'SYSTEMINFO_GDSETTINGS', postVar('SYSTEMINFO_GDSETTINGS')); + self::addToAdminTemplate($templateid, 'BANLIST_DELETED_LIST', postVar('BANLIST_DELETED_LIST')); + self::addToAdminTemplate($templateid, 'INSERT_PLUGOPTION_TITLE', postVar('INSERT_PLUGOPTION_TITLE')); + self::addToAdminTemplate($templateid, 'INSERT_PLUGOPTION_BODY', postVar('INSERT_PLUGOPTION_BODY')); + self::addToAdminTemplate($templateid, 'INPUTYESNO_TEMPLATE_ADMIN', postVar('INPUTYESNO_TEMPLATE_ADMIN')); + self::addToAdminTemplate($templateid, 'INPUTYESNO_TEMPLATE_NORMAL', postVar('INPUTYESNO_TEMPLATE_NORMAL')); + self::addToAdminTemplate($templateid, 'ADMIN_SPECIALSKINLIST_HEAD', postVar('ADMIN_SPECIALSKINLIST_HEAD')); + self::addToAdminTemplate($templateid, 'ADMIN_SPECIALSKINLIST_BODY', postVar('ADMIN_SPECIALSKINLIST_BODY')); + self::addToAdminTemplate($templateid, 'ADMIN_SPECIALSKINLIST_FOOT', postVar('ADMIN_SPECIALSKINLIST_FOOT')); + self::addToAdminTemplate($templateid, 'SKINIE_EXPORT_LIST', postVar('SKINIE_EXPORT_LIST')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_SELECT_HEAD', postVar('SHOWLIST_LISTPLUG_SELECT_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_SELECT_BODY', postVar('SHOWLIST_LISTPLUG_SELECT_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_SELECT_FOOT', postVar('SHOWLIST_LISTPLUG_SELECT_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM', postVar('SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLIST_BD_SADM', postVar('SHOWLIST_LISTPLUG_TABLE_BLIST_BD_SADM')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SHORTNAM_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY')); + self::addToAdminTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT')); + self::addToAdminTemplate($templateid, 'PLUGIN_QUICKMENU_TITLE', postVar('PLUGIN_QUICKMENU_TITLE')); + self::addToAdminTemplate($templateid, 'PLUGIN_QUICKMENU_HEAD', postVar('PLUGIN_QUICKMENU_HEAD')); + self::addToAdminTemplate($templateid, 'PLUGIN_QUICKMENU_BODY', postVar('PLUGIN_QUICKMENU_BODY')); + self::addToAdminTemplate($templateid, 'PLUGIN_QUICKMENU_FOOT', postVar('PLUGIN_QUICKMENU_FOOT')); + + $data = array('fields' => array()); + $manager->notify('AdminTemplateExtraFields', $data); + foreach ( $data['fields'] as $pfkey => $pfvalue ) + { + foreach ( $pfvalue as $pffield => $pfdesc ) + { + self::addToAdminTemplate($templateid, $pffield, postVar($pffield)); } } - + // jump back to template edit - $this->action_admintemplateedit(_TEMPLATE_UPDATED); + self::action_admintemplateedit(_TEMPLATE_UPDATED); + return; } /** - * @todo document this + * Admin::addToAdminTemplate() + * + * @param integer $id ID for template + * @param string $partname name of part for template + * @param void $contents content for part of template + * @return integer ID for newly inserted Template */ - function addToAdminTemplate($id, $partname, $content) + static private function addToAdminTemplate($id, $partname, $content) { - $partname = sql_real_escape_string($partname); - $content = sql_real_escape_string($content); - - - $id = intval($id); - // don't add empty parts: - if (!trim($content)) { + if ( !trim($content) ) + { return -1; } - $query = 'INSERT ' - . 'INTO ' - . sql_table('admintemplate') . ' ' - . '(' - . ' tdesc, ' - . ' tpartname, ' - . ' tcontent ' - . ') VALUES (' - . ' %d, ' - . ' "%s", ' - . ' "%s"' - . ')'; - sql_query(sprintf($query, $id, $partname, $content)) or exit(_ADMIN_SQLDIE_QUERYERROR . sql_error()); - return sql_insert_id(); + + $query = "INSERT INTO %s (tdesc, tpartname, tcontent ) VALUES (%d, %s, %s);"; + $query = sprintf($query, sql_table('template'), (integer) $id, DB::quoteValue($partname), DB::quoteValue($content)); + if ( DB::execute($query) === FALSE ) + { + $err = DB::getError(); + exit(_ADMIN_SQLDIE_QUERYERROR . $err[2]); + } + return DB::getInsertId(); } /** - * @todo document this + * Admin::action_admintemplatedelete() + * + * @param void + * @return void */ - function action_admintemplatedelete() + static private function action_admintemplatedelete() { global $member, $manager; - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); + // TODO: check if template can be deleted - $this->pagehead(); - $this->parse('admintemplatedelete'); - $this->pagefoot(); + self::$skin->parse('admintemplatedelete'); + return; } /** - * @todo document this + * Admin::action_admintemplatedeleteconfirm() + * + * @param void + * @return void */ - function action_admintemplatedeleteconfirm() + static private function action_admintemplatedeleteconfirm() { global $member, $manager; + $templateid = intRequestVar('templateid'); - $member->isAdmin() or $this->disallow(); - $manager->notify( - 'PreDeleteAdminTemplate', - array( - 'templateid' => $templateid - ) - ); - - $query = 'DELETE ' - . 'FROM ' - . ' %s ' - . 'WHERE ' - . ' %s = ' .intval($templateid); + $member->isAdmin() or self::disallow(); + + $data = array('templateid' => $templateid); + $manager->notify('PreDeleteAdminTemplate', $data); + // 1. delete description - sql_query(sprintf($query, sql_table('admintemplate_desc'), 'tdnumber')); + $query = "DELETE FROM %s WHERE tdnumber=%s;"; + $query = sprintf($query, sql_table('template_desc'), (integer) $templateid); + DB::execute($query); + // 2. delete parts - sql_query(sprintf($query, sql_table('admintemplate'), 'tdesc')); - - $manager->notify( - 'PostDeleteAdminTemplate', - array( - 'templateid' => $templateid - ) - ); - $this->action_admintemplateoverview(); + $query = "DELETE FROM %s WHERE tdesc=%d;"; + $query = sprintf($query, sql_table('template'), (integer) $templateid); + DB::execute($query); + + $data = array('templateid' => $templateid); + $manager->notify('PostDeleteAdminTemplate', $data); + + self::action_admintemplateoverview(); + return; } /** - * @todo document this + * Admin::action_admintemplatenew() + * + * @param void + * @return void */ - function action_admintemplatenew() + static private function action_admintemplatenew() { global $member; - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); $name = postVar('name'); $desc = postVar('desc'); - - if (!isValidTemplateName($name)) { - $this->error(_ERROR_BADTEMPLATENAME); + + if ( !isValidTemplateName($name) ) + { + self::error(_ERROR_BADTEMPLATENAME); } - if (Template::exists($name)) { - $this->error(_ERROR_DUPTEMPLATENAME); + else if ( !preg_match('#^admin/#', $name) ) + { + self::error(_ERROR_BADADMINTEMPLATENAME); } - + else if ( Template::exists($name) ) + { + self::error(_ERROR_DUPTEMPLATENAME); + } + $newTemplateId = Template::createNew($name, $desc); - $this->action_admintemplateoverview(); + self::action_admintemplateoverview(); + return; } /** - * @todo document this - */ - function action_admintemplateclone() + * Admin::action_admintemplateclone() + * + * @param void + * @return void + */ + static private function action_admintemplateclone() { global $member; $templateid = intRequestVar('templateid'); - $member->isAdmin() or $this->disallow(); - - // if (!class_exists('Template')) { - // NP_SkinableAdmin::loadSkinableClass('Template'); - // } - + $member->isAdmin() or self::disallow(); + // 1. read old template $name = Template::getNameFromId($templateid); $desc = Template::getDesc($templateid); + // 2. create desc thing - $name = "cloned" . $name; - + $name = $name . "cloned"; + // if a template with that name already exists: - if (Template::exists($name)) { + if ( Template::exists($name) ) + { $i = 1; - while (Template::exists($name . $i)) { + while ( Template::exists($name . $i) ) + { $i++; } $name .= $i; } - - $newid = Template::admincreateNew($name, $desc); - + + $newid = Template::createNew($name, $desc); + // 3. create clone // go through parts of old template and add them to the new one - $que = 'SELECT ' - . ' tpartname, ' - . ' tcontent ' - . 'FROM ' - . sql_table('admintemplate') . ' ' - . 'WHERE ' - . ' tdesc = ' . intval($templateid); - $res = sql_query($que); - while ($o = sql_fetch_object($res)) { - $this->addToAdminTemplate($newid, $o->tpartname, $o->tcontent); + $query = "SELECT tpartname, tcontent FROM %s WHERE tdesc=%d;"; + $query = sprintf($query, sql_table('template'), (integer) $templateid); + + $res = DB::getResult($query); + foreach ( $res as $row ) + { + self::addToAdminTemplate($newid, $row['tpartname'], $row['tcontent']); } - $this->action_admintemplateoverview(); + + self::action_admintemplateoverview(); + return; } /** - * @todo document this + * Admin::action_skinoverview() + * + * @param void + * @return void */ - function action_skinoverview() + static private function action_skinoverview() { global $member, $manager; - - $member->isAdmin() or $this->disallow(); - - $this->pagehead(); - $this->parse('skinoverview'); - $this->pagefoot(); + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('skinoverview'); + return; } - + /** - * @todo document this + * Admin::action_skinnew() + * + * @param void + * @return void */ - function action_skinnew() + static private function action_skinnew() { global $member; - - $member->isAdmin() or $this->disallow(); - + + $member->isAdmin() or self::disallow(); + $name = trim(postVar('name')); $desc = trim(postVar('desc')); - + if ( !isValidSkinName($name) ) { - $this->error(_ERROR_BADSKINNAME); + self::error(_ERROR_BADSKINNAME); } - + if ( SKIN::exists($name) ) { - $this->error(_ERROR_DUPSKINNAME); + self::error(_ERROR_DUPSKINNAME); } - + $newId = SKIN::createNew($name, $desc); - - $this->action_skinoverview(); + + self::action_skinoverview(); + return; } - + /** - * @todo document this + * Admin::action_skinedit() + * + * @param void + * @return void */ - function action_skinedit() + static private function action_skinedit() { global $member, $manager; - -// $skinid = intRequestVar('skinid'); - - $member->isAdmin() or $this->disallow(); - -// $skin = new SKIN($skinid); - - $this->pagehead(); - $this->parse('skinedit'); - $this->pagefoot(); + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('skinedit'); + return; } - + /** - * @todo document this + * Admin::action_skineditgeneral() + * + * @param void + * @return void */ - function action_skineditgeneral() + static private function action_skineditgeneral() { - global $member; - + global $manager, $member; + $skinid = intRequestVar('skinid'); - - $member->isAdmin() or $this->disallow(); - - $name = postVar('name'); - $desc = postVar('desc'); - $type = postVar('type'); - $inc_mode = postVar('inc_mode'); - $inc_prefix = postVar('inc_prefix'); - - $skin = new Skin($skinid); - + + $member->isAdmin() or self::disallow(); + + $name = postVar('name'); + $desc = postVar('desc'); + $type = postVar('type'); + $inc_mode = postVar('inc_mode'); + $inc_prefix = postVar('inc_prefix'); + + $skin =& $manager->getSkin($skinid); + // 1. Some checks if ( !isValidSkinName($name) ) { - $this->error(_ERROR_BADSKINNAME); + self::error(_ERROR_BADSKINNAME); } - + if ( ($skin->getName() != $name) && SKIN::exists($name) ) { - $this->error(_ERROR_DUPSKINNAME); + self::error(_ERROR_DUPSKINNAME); } - + if ( !$type ) { $type = 'text/html'; @@ -3553,239 +3752,254 @@ class Admin { $inc_mode = 'normal'; } - + // 2. Update description $skin->updateGeneralInfo($name, $desc, $type, $inc_mode, $inc_prefix); - - $this->action_skinedit(); - + + self::action_skinedit(); + return; } - - /** - * @todo document this - */ - function action_skinedittype($msg = '') + + static private function action_skinedittype($msg = '') { global $member, $manager; - - $member->isAdmin() or $this->disallow(); - - if ($msg) { - $this->headMess = $msg; + + $member->isAdmin() or self::disallow(); + + if ( $msg ) + { + self::$headMess = $msg; } - $skinid = intRequestVar('skinid'); - $type = requestVar('type'); - $type = trim($type); - $type = strtolower($type); - + + $skinid = intRequestVar('skinid'); + $type = requestVar('type'); + $type = trim($type); + $type = strtolower($type); + if ( !isValidShortName($type) ) { - $this->error(_ERROR_SKIN_PARTS_SPECIAL_FORMAT); + self::error(_ERROR_SKIN_PARTS_SPECIAL_FORMAT); } - - $this->pagehead(); - $this->parse('skinedittype'); - $this->pagefoot(); + + self::$skin->parse('skinedittype'); + return; } - + /** - * @todo document this + * Admin::action_skinupdate() + * + * @param void + * @return void */ - function action_skinupdate() + static private function action_skinupdate() { - global $member; - + global $manager, $member; + $skinid = intRequestVar('skinid'); $content = trim(postVar('content')); $type = postVar('type'); - - $member->isAdmin() or $this->disallow(); - - $skin = new SKIN($skinid); + + $member->isAdmin() or self::disallow(); + + $skin =& $manager->getSKIN($skinid); $skin->update($type, $content); - - $this->action_skinedittype(_SKIN_UPDATED); + + self::action_skinedittype(_SKIN_UPDATED); + return; } - + /** - * @todo document this + * Admin::action_skindelete() + * + * @param void + * @return void */ - function action_skindelete() + static private function action_skindelete() { - global $member, $manager, $CONF; - + global $manager, $member, $CONF; + $skinid = intRequestVar('skinid'); - - $member->isAdmin() or $this->disallow(); - + + $member->isAdmin() or self::disallow(); + // don't allow default skin to be deleted if ( $skinid == $CONF['BaseSkin'] ) { - $this->error(_ERROR_DEFAULTSKIN); + self::error(_ERROR_DEFAULTSKIN); } - + // don't allow deletion of default skins for blogs - $query = 'SELECT bname FROM ' . sql_table('blog') . ' WHERE bdefskin=' . $skinid; - $r = sql_query($query); - if ( $o = sql_fetch_object($r) ) + $query = "SELECT bname FROM %s WHERE bdefskin=%d"; + $query = sprintf($query, sql_table('blog'), (integer) $skinid); + + $name = DB::getValue($query); + if ( $name ) { - $this->error(_ERROR_SKINDEFDELETE . Entity::hsc($o->bname)); + self::error(_ERROR_SKINDEFDELETE . Entity::hsc($name)); } - - $this->pagehead(); - $this->parse('skindelete'); - $this->pagefoot(); + + self::$skin->parse('skindelete'); + return; } - + /** - * @todo document this + * Admin::action_skindeleteconfirm() + * + * @param void + * @return void */ - function action_skindeleteconfirm() + static private function action_skindeleteconfirm() { global $member, $CONF, $manager; - + $skinid = intRequestVar('skinid'); - - $member->isAdmin() or $this->disallow(); - + + $member->isAdmin() or self::disallow(); + // don't allow default skin to be deleted if ( $skinid == $CONF['BaseSkin'] ) { - $this->error(_ERROR_DEFAULTSKIN); + self::error(_ERROR_DEFAULTSKIN); } - + // don't allow deletion of default skins for blogs - $query = 'SELECT' - . ' bname ' - . 'FROM ' - . sql_table('blog') . ' ' - . 'WHERE' - . ' bdefskin=' . $skinid; - $r = sql_query($query); - if ( $o = sql_fetch_object($r) ) - { - $this->error(_ERROR_SKINDEFDELETE .$o->bname); + $query = "SELECT bname FROM %s WHERE bdefskin=%d;"; + $query = sprintf($query, sql_table('blog'), (integer) $skinid); + + $name = DB::getValue($query); + if ( $name ) + { + self::error(_ERROR_SKINDEFDELETE . Entity::hsc($name)); } - - $manager->notify( - 'PreDeleteSkin', - array( - 'skinid' => $skinid - ) - ); - + + $data = array('skinid' => $skinid); + $manager->notify('PreDeleteSkin', $data); + // 1. delete description - sql_query('DELETE FROM '.sql_table('skin_desc').' WHERE sdnumber=' . $skinid); - + $query = "DELETE FROM %s WHERE sdnumber=%d;"; + $query = sprintf($query, sql_table('skin_desc'), (integer) $skinid); + DB::execute($query); + // 2. delete parts - sql_query('DELETE FROM '.sql_table('skin').' WHERE sdesc=' . $skinid); - - $manager->notify( - 'PostDeleteSkin', - array( - 'skinid' => $skinid - ) - ); - - $this->action_skinoverview(); + $query = "DELETE FROM %s WHERE sdesc=%d;"; + $query = sprintf($query, sql_table('skin'), (integer) $skinid); + DB::execute($query); + + $data = array('skinid' => $skinid); + $manager->notify('PostDeleteSkin', $data); + + self::action_skinoverview(); + return; } - + /** - * @todo document this + * Admin::action_skinremovetype() + * + * @param void + * @return void */ - function action_skinremovetype() { + static private function action_skinremovetype() + { global $member, $manager, $CONF; - - $member->isAdmin() or $this->disallow(); - + + $member->isAdmin() or self::disallow(); + $skinid = intRequestVar('skinid'); $skintype = requestVar('type'); - + if ( !isValidShortName($skintype) ) { - $this->error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); + self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); } - - + // don't allow default skinparts to be deleted + /* TODO: this array should be retrieved from Action class */ if ( in_array($skintype, array('index', 'item', 'archivelist', 'archive', 'search', 'error', 'member', 'imagepopup')) ) { - $this->error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); + self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); } - - $this->pagehead(); - $this->parse('skinremovetype'); - $this->pagefoot(); + + self::$skin->parse('skinremovetype'); + return; } - + /** - * @todo document this + * Admin::action_skinremovetypeconfirm() + * + * @param void + * @return void */ - function action_skinremovetypeconfirm() { + static private function action_skinremovetypeconfirm() + { global $member, $CONF, $manager; - - $member->isAdmin() or $this->disallow(); - + + $member->isAdmin() or self::disallow(); + $skinid = intRequestVar('skinid'); $skintype = requestVar('type'); - + if ( !isValidShortName($skintype) ) { - $this->error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); + self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); } - + // don't allow default skinparts to be deleted + /* TODO: this array should be retrieved from Action class */ if ( in_array($skintype, array('index', 'item', 'archivelist', 'archive', 'search', 'error', 'member', 'imagepopup')) ) { - $this->error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); + self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); } - - $manager->notify( - 'PreDeleteSkinPart', - array( - 'skinid' => $skinid, - 'skintype' => $skintype - ) + + $data = array( + 'skinid' => $skinid, + 'skintype' => $skintype ); - + $manager->notify('PreDeleteSkinPart', $data); // delete part - sql_query("DELETE FROM " . sql_table('skin') . " WHERE sdesc=" . $skinid . " AND stype='" . $skintype . "'"); - - $manager->notify( - 'PostDeleteSkinPart', - array( - 'skinid' => $skinid, - 'skintype' => $skintype - ) + $query = "DELETE FROM %s WHERE sdesc=%d AND stype=%s;"; + $query = sprintf($query, sql_table('skin'), (integer) $skinid, DB::quoteValue($skintype) ); + DB::execute($query); + + $data = array( + 'skinid' => $skinid, + 'skintype' => $skintype ); - - $this->action_skinedit(); + $manager->notify('PostDeleteSkinPart', $data); + + self::action_skinedit(); + return; } /** - * @todo document this + * Admin::action_skinclone() + * + * @param void + * @return void */ - function action_skinclone() + static private function action_skinclone() { - global $member; - - $member->isAdmin() or $this->disallow(); - + global $manager, $member; + + $member->isAdmin() or self::disallow(); + $skinid = intRequestVar('skinid'); - + // 1. read skin to clone - $skin = new SKIN($skinid); - - $name = "clone_" . $skin->getName(); - + $skin =& $manager->getSkin($skinid); + + $name = "{$skin->getName()}_clone"; + // if a skin with that name already exists: - if (Skin::exists($name)) { + if ( Skin::exists($name) ) + { $i = 1; - while (Skin::exists($name . $i)) + while ( Skin::exists($name . $i) ) + { $i++; + } $name .= $i; } - + // 2. create skin desc $newid = Skin::createNew( $name, @@ -3794,19 +4008,21 @@ class Admin $skin->getIncludeMode(), $skin->getIncludePrefix() ); - - + // 3. clone - $query = "SELECT stype FROM " . sql_table('skin') . " WHERE sdesc = " . $skinid; - $res = sql_query($query); - while ($row = sql_fetch_assoc($res)) { - $this->skinclonetype($skin, $newid, $row['stype']); + $query = "SELECT stype FROM %s WHERE sdesc=%d;"; + $query = sprintf($query, sql_table('skin'), (integer) $skinid); + + $res = DB::getResult($query); + foreach ( $res as $row ) + { + self::skinclonetype($skin, $newid, $row['stype']); } - - $this->action_skinoverview(); - + + self::action_skinoverview(); + return; } - + /** * Admin::skinclonetype() * @@ -3815,265 +4031,340 @@ class Admin * @param String $type type of skin * @return Void */ - function skinclonetype($skin, $newid, $type) + static private function skinclonetype($skin, $newid, $type) { $newid = intval($newid); - $content = $skin->getContent($type); + $content = $skin->getContentFromDB($type); if ( $content ) { - $query = "INSERT INTO %s (sdesc, scontent, stype) VALUES (%d, '%s', '%s')"; - $query = sprintf($query, sql_table('skin'), (integer) $newid, $content, $type); - sql_query($query); + $query = "INSERT INTO %s (sdesc, scontent, stype) VALUES (%d, %s, %s)"; + $query = sprintf($query, sql_table('skin'), (integer) $newid, DB::quoteValue($content), DB::quoteValue($type)); + DB::execute($query); } return; } /** - * @todo document this + * Admin::action_adminskinoverview() + * + * @param void + * @return void */ - function action_adminskinoverview() { + static private function action_adminskinoverview() + { global $member, $manager; - - $member->isAdmin() or $this->disallow(); - - $this->pagehead(); - $this->parse('adminskinoverview'); - $this->pagefoot(); + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('adminskinoverview'); + return; } - + /** - * @todo document this + * Admin::action_adminskinnew() + * + * @param void + * @return void */ - function action_adminskinnew() + static private function action_adminskinnew() { global $member; - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); $name = trim(postVar('name')); $desc = trim(postVar('desc')); - - if (!isValidSkinName($name)) { - $this->error(_ERROR_BADSKINNAME); + + if ( !isValidSkinName($name) ) + { + self::error(_ERROR_BADSKINNAME); + } + else if ( !preg_match('#^admin/#', $name) ) + { + self::error(_ERROR_BADADMINSKINNAME); } - if (SkinSKIN::exists($name)) { - $this->error(_ERROR_DUPSKINNAME); + else if ( Skin::exists($name) ) + { + self::error(_ERROR_DUPSKINNAME); } + /* TODO: $newId is not reused... */ $newId = Skin::createNew($name, $desc); - $this->action_adminskinoverview(); + self::action_adminskinoverview(); + return; } - + /** - * @todo document this + * Admin::action_adminskinedit() + * + * @param void + * @return void */ - function action_adminskinedit() + static private function action_adminskinedit() { global $member, $manager; - - $member->isAdmin() or $this->disallow(); - $this->pagehead(); - $this->parse('adminskinedit'); - $this->pagefoot(); + + $member->isAdmin() or self::disallow(); + self::$skin->parse('adminskinedit'); + return; } - + /** - * @todo document this + * Admin::action_adminskineditgeneral() + * + * @param void + * @return void */ - function action_adminskineditgeneral() + static private function action_adminskineditgeneral() { - global $member; - + global $manager, $member; + $skinid = intRequestVar('skinid'); - - $member->isAdmin() or $this->disallow(); - - $name = postVar('name'); - $desc = postVar('desc'); - $type = postVar('type'); - $inc_mode = postVar('inc_mode'); - $inc_prefix = postVar('inc_prefix'); - - $skin = new Skin($skinid); - + + $member->isAdmin() or self::disallow(); + + $name = postVar('name'); + $desc = postVar('desc'); + $type = postVar('type'); + $inc_mode = postVar('inc_mode'); + $inc_prefix = postVar('inc_prefix'); + + $skin =& $manager->getSkin($skinid, 'AdminActions', 'AdminSkin'); + // 1. Some checks - if (!isValidSkinName($name)) { - $this->error(_ERROR_BADSKINNAME); + if ( !isValidSkinName($name) ) + { + self::error(_ERROR_BADSKINNAME); } - if (($skin->getName() != $name) && Skin::exists($name)) { - $this->error(_ERROR_DUPSKINNAME); + if ( ($skin->getName() != $name) && Skin::exists($name) ) + { + self::error(_ERROR_DUPSKINNAME); } - if (!$type) { + if ( !$type ) + { $type = 'text/html'; } - if (!$inc_mode) { + if ( !$inc_mode ) + { $inc_mode = 'normal'; } // 2. Update description $skin->updateGeneralInfo($name, $desc, $type, $inc_mode, $inc_prefix); - $this->action_adminskinedit(); + self::action_adminskinedit(); + return; } - + /** - * @todo document this + * Admin::action_adminskinedittype() + * + * @param string $msg message for pageheader + * @return void */ - function action_adminskinedittype($msg = '') + static private function action_adminskinedittype($msg = '') { global $member, $manager; - - $member->isAdmin() or $this->disallow(); - if ($msg) { - $this->headMess = $msg; + + $member->isAdmin() or self::disallow(); + + if ( $msg ) + { + self::$headMess = $msg; } $type = requestVar('type'); $type = trim($type); $type = strtolower($type); - if (!isValidShortName($type)) { - $this->error(_ERROR_SKIN_PARTS_SPECIAL_FORMAT); + + if ( !isValidShortName($type) ) + { + self::error(_ERROR_SKIN_PARTS_SPECIAL_FORMAT); } - $this->pagehead(); - $this->parse('adminskinedittype'); - $this->pagefoot(); + + self::$skin->parse('adminskinedittype'); + return; } - + /** - * @todo document this + * Admin::action_adminskinupdate() + * + * @param void + * @return void */ - function action_adminskinupdate() + static private function action_adminskinupdate() { - global $member; - $skinid = intRequestVar('skinid'); + global $manager, $member; + + $skinid = intRequestVar('skinid'); $content = trim(postVar('content')); - $type = postVar('type'); - - $member->isAdmin() or $this->disallow(); - - $skin = new Skin($skinid); + $type = postVar('type'); + + $member->isAdmin() or self::disallow(); + + $skin =& $manager->getSkin($skinid, 'Admin', 'AdminSkin'); $skin->update($type, $content); - $this->action_adminskinedittype(_SKIN_UPDATED); + self::action_adminskinedittype(_SKIN_UPDATED); + return; } - + /** - * @todo document this + * Admin::action_adminskindelete() + * + * @param void + * @return void */ - function action_adminskindelete() + static private function action_adminskindelete() { global $member, $manager, $CONF; - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); + + /* TODO: needless variable $skinid... */ $skinid = intRequestVar('skinid'); - $this->pagehead(); - $this->parse('adminskindelete'); - $this->pagefoot(); + self::$skin->parse('adminskindelete'); + return; } /** - * @todo document this + * Admin::action_adminskindeleteconfirm() + * + * @param void + * @return void */ - function action_adminskindeleteconfirm() + static private function action_adminskindeleteconfirm() { global $member, $CONF, $manager; - $member->isAdmin() or $this->disallow(); + + $member->isAdmin() or self::disallow(); $skinid = intRequestVar('skinid'); + // don't allow default skin to be deleted - if ($skinid == $CONF['DefaultAdminSkin']) { - $this->error(_ERROR_DEFAULTSKIN); + if ( $skinid == $CONF['AdminSkin'] ) + { + self::error(_ERROR_DEFAULTSKIN); } - // don't allow deletion of default skins for members + + /* + * TODO: NOT Implemented + * don't allow deletion of default skins for members $memberDefaults = $member->getAdminSkin(); - foreach ($memberDefaults as $memID => $adminskin) { - if ($skinid == $adminskin) { - $mem = MEMBER::createFromID($memID); - $this->error(_ERROR_SKINDEFDELETE . $mem->displayname); + foreach ( $memberDefaults as $memID => $adminskin ) + { + if ( $skinid == $adminskin ) + { + $mem =& $manager->getMember($memID); + self::error(_ERROR_SKINDEFDELETE . $mem->displayname); } } - $manager->notify( - 'PreDeleteAdminSkin', - array( - 'skinid' => intval($skinid) - ) - ); - $query = 'DELETE FROM %s WHERE %s = ' . intval($skinid); + */ + + $manager->notify('PreDeleteAdminSkin', array('skinid' => (integer) $skinid)); + // 1. delete description - sql_query(sprintf($query, sql_table('adminskin_desc'), 'sdnumber')); + $query = "DELETE FROM %s WHERE sdnumber=%d;"; + $query = sprintf($query, sql_table('skin_desc'), (integer) $skinid); + DB::execute($query); + // 2. delete parts - sql_query(sprintf($query, sql_table('adminskin'), 'sdesc')); - $manager->notify( - 'PostDeleteAdminSkin', - array( - 'skinid' => intval($skinid) - ) - ); - $this->action_adminskinoverview(); + $query = "DELETE FROM %s WHERE sdesc=%d;"; + $query = sprintf($query, sql_table('skin'), (integer) $skinid); + + DB::execute($query); + + $manager->notify('PostDeleteAdminSkin', array('skinid' => (integer) $skinid)); + self::action_adminskinoverview(); + return; } - + /** - * @todo document this + * Admin::action_adminskinremovetype() + * + * @param void + * @return void */ - function action_adminskinremovetype() + static private function action_adminskinremovetype() { global $member, $manager, $CONF; - $member->isAdmin() or $this->disallow(); - $skinid = intRequestVar('skinid'); - $skintype = requestVar('type'); - if (!isValidShortName($skintype)) { - $this->error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); + $skintype = requestVar('type'); + + if ( !isValidShortName($skintype) ) + { + self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); } - $this->pagehead(); - $this->parse('adminskinremovetype'); - $this->pagefoot(); + + self::$skin->parse('adminskinremovetype'); + return; } - + /** - * @todo document this + * Admin::action_adminskinremovetypeconfirm() + * + * @param void + * @return void */ - function action_adminskinremovetypeconfirm() + static private function action_adminskinremovetypeconfirm() { global $member, $CONF, $manager; - - $member->isAdmin() or $this->disallow(); - $skinid = intRequestVar('skinid'); - $skintype = requestVar('type'); - if (!isValidShortName($skintype)) { - $this->error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); + + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); + $skintype = requestVar('type'); + + if ( !isValidShortName($skintype) ) + { + self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); } - $manager->notify( - 'PreDeleteAdminSkinPart', - array( - 'skinid' => $skinid, - 'skintype' => $skintype - ) + + $data =array( + 'skinid' => $skinid, + 'skintype' => $skintype ); + $manager->notify('PreDeleteAdminSkinPart', $data); + // delete part - $query = 'DELETE FROM %s WHERE sdesc = %d AND stype ="%s"'; - sql_query(sprintf($query, sql_table('adminskin'), intval($skinid), $skintype )); - $manager->notify( - 'PostDeleteAdminSkinPart', - array( - 'skinid' => $skinid, - 'skintype' => $skintype - ) + $query = 'DELETE FROM %s WHERE sdesc = %d AND stype = %s ;'; + $query = sprintf($query, sql_table('skin'), (integer) $skinid, DB::quoteValue($skintype) ); + DB::execute($query); + + $data = array( + 'skinid' => $skinid, + 'skintype' => $skintype ); - $this->action_adminskinedit(); + $manager->notify('PostDeleteAdminSkinPart', $data); + + self::action_adminskinedit(); + return; } /** - * @todo document this + * Admin::action_adminskinclone() + * + * @param void + * @return void */ - function action_adminskinclone() + static private function action_adminskinclone() { - global $member; - $member->isAdmin() or $this->disallow(); + global $manager, $member; + + $member->isAdmin() or self::disallow(); + $skinid = intRequestVar('skinid'); + // 1. read skin to clone - $skin = new Skin($skinid); - $name = "clone_" . $skin->getName(); + $skin =& $manager->getSkin($skinid, 'Admin', 'AdminSkin'); + $name = "{$skin->getName()}_clone"; + // if a skin with that name already exists: - if (Skin::exists($name)) { + if ( Skin::exists($name) ) + { $i = 1; - while (Skin::exists($name . $i)) { + while ( Skin::exists($name . $i) ) + { $i++; } $name .= $i; } + // 2. create skin desc $newid = Skin::createNew( $name, @@ -4082,192 +4373,259 @@ class Admin $skin->getIncludeMode(), $skin->getIncludePrefix() ); - $query = 'SELECT ' - . ' stype ' - . 'FROM ' - . sql_table('adminskin') . ' ' - . 'WHERE ' - . ' sdesc = ' . $skinid; - $res = sql_query($query); - while ($row = sql_fetch_assoc($res)) { - $this->adminskinclonetype($skin, $newid, $row['stype']); + + // 3. clone + $query = "SELECT stype FROM %s WHERE sdesc=%d;"; + $query = sprintf($query, sql_table('skin'), (integer) $skinid); + + $res = DB::getResult($query); + foreach ( $res as $row ) + { + self::skinclonetype($skin, $newid, $row['stype']); } - $this->action_adminskinoverview(); + self::action_adminskinoverview(); + return; } - + /** - * @todo document this + * Admin::adminskinclonetype() + * + * @param string $skin an instance of Skin class + * @param integer $newid ID for new skin + * @param string $type skin type + * @return void */ - function adminskinclonetype($skin, $newid, $type) + static private function adminskinclonetype($skin, $newid, $type) { - $newid = intval($newid); - $content = $skin->getContent($type); - if ($content) { - $query = 'INSERT ' - . 'INTO ' - . sql_table('adminskin') . ' ' - . '(' - . ' sdesc, ' - . ' scontent, ' - . ' stype' - . ') VALUES (' - . intval($newid) . ', ' - . '"' . sql_real_escape_string($content) . '", ' - . '"' . sql_real_escape_string($type) . '" ' - . ')'; - sql_query($query); + $content = $skin->getContentFromDB($type); + + if ( $content ) + { + $query = "INSERT INTO %s (sdesc, scontent, stype) VALUES (%d, %s, %s)"; + $query = sprintf($query, sql_table('skin'), (integer) $newid, DB::quoteValue($content), DB::quoteValue($type)); + DB::execute($query); } + return; } - + /** - * @todo document this + * Admin::action_adminskinieoverview() + * + * @param void + * @return void */ - function action_adminskinieoverview() + static private function action_adminskinieoverview() { global $member, $DIR_LIBS, $manager; - $member->isAdmin() or $this->disallow(); + + $member->isAdmin() or self::disallow(); + // load skinie class include_once($DIR_LIBS . 'skinie.php'); - $this->pagehead(); - $this->parse('adminskinieoverview'); - $this->pagefoot(); - + + self::$skin->parse('adminskinieoverview'); + return; } /** - * @todo document this + * FIXME: DUPLICATION, NO NEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEED!!!!!! + * Admin::action_adminskinieimport() + * + * @param void + * @return void */ - function action_adminskinieimport() + static private function action_adminskinieimport() { - global $DIR_LIBS, $DIR_ADMINSKINS, $manager, $member; - $member->isAdmin() or $this->disallow(); + global $DIR_LIBS, $DIR_SKINS, $manager, $member; + + $member->isAdmin() or self::disallow(); + // load skinie class include_once($DIR_LIBS . 'skinie.php'); - $skinFileRaw= postVar('skinfile'); - $mode = postVar('mode'); - $importer = new SKINIMPORT(); + + $skinFileRaw = postVar('skinfile'); + $mode = postVar('mode'); + + $importer = new SKINIMPORT(); + // get full filename - if ($mode == 'file') { - $skinFile = $DIR_ADMINSKINS . $skinFileRaw . '/skinbackup.xml'; + if ( $mode == 'file' ) + { + $skinFile = "{$DIR_SKINS}admin/{$skinFileRaw}/skinbackup.xml"; + // backwards compatibilty (in v2.0, exports were saved as skindata.xml) - if (!file_exists($skinFile)) { - $skinFile = $DIR_ADMINSKINS . $skinFileRaw . '/skindata.xml'; + if ( !file_exists($skinFile) ) + { + $skinFile = "{$DIR_SKINS}admin/{$skinFileRaw}/skindata.xml"; } - } else { + } + else + { $skinFile = $skinFileRaw; } + // read only metadata $error = $importer->readFile($skinFile, 1); - if ($error) { - $this->error($error); + if ( $error ) + { + self::error($error); } - - $_REQUEST['skininfo'] = $importer->getInfo(); - $_REQUEST['skinnames'] = $importer->getSkinNames(); - $_REQUEST['tpltnames'] = $importer->getTemplateNames(); - + + /* TODO: we should consider to use the other way instead of this */ + $_REQUEST['skininfo'] = $importer->getInfo(); + $_REQUEST['skinnames'] = $importer->getSkinNames(); + $_REQUEST['tpltnames'] = $importer->getTemplateNames(); + // clashes - $skinNameClashes = $importer->checkSkinNameClashes(); - $templateNameClashes = $importer->checkTemplateNameClashes(); - $hasNameClashes = (count($skinNameClashes) > 0) || (count($templateNameClashes) > 0); - $_REQUEST['skinclashes'] = $skinNameClashes; - $_REQUEST['tpltclashes'] = $templateNameClashes; - $_REQUEST['nameclashes'] = $hasNameClashes ? 1 : 0; + $skinNameClashes = $importer->checkSkinNameClashes(); + $templateNameClashes = $importer->checkTemplateNameClashes(); + $hasNameClashes = (count($skinNameClashes) > 0) || (count($templateNameClashes) > 0); + /* TODO: we should consider to use the other way instead of this */ + $_REQUEST['skinclashes'] = $skinNameClashes; + $_REQUEST['tpltclashes'] = $templateNameClashes; + $_REQUEST['nameclashes'] = $hasNameClashes ? 1 : 0; - $this->pagehead(); - $this->parse('adminskinieimport'); - $this->pagefoot(); + if ( !is_object(self::$skin) ) + { + self::action_adminskiniedoimport(); + } + else + { + self::$skin->parse('adminskinieimport'); + } + return; } - + /** - * @todo document this + * FIXME: DUPLICATION, NO NEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEED!!!!!! + * Admin::action_adminskiniedoimport() + * + * @param void + * @return void */ - function action_adminskiniedoimport() + static private function action_adminskiniedoimport() { - global $DIR_LIBS, $DIR_ADMINSKINS, $member; - $member->isAdmin() or $this->disallow(); + global $DIR_LIBS, $DIR_SKINS, $manager, $member; + + $member->isAdmin() or self::disallow(); + // load skinie class include_once($DIR_LIBS . 'skinie.php'); - $skinFileRaw = postVar('skinfile'); - $mode = postVar('mode'); - $allowOverwrite = intPostVar('overwrite'); + + $skinFileRaw = postVar('skinfile'); + $mode = postVar('mode'); + $allowOverwrite = intPostVar('overwrite'); + // get full filename - if ($mode == 'file') { - $skinFile = $DIR_ADMINSKINS . $skinFileRaw . '/skinbackup.xml'; + if ( $mode == 'file' ) + { + $skinFile = "{$DIR_SKINS}admin/{$skinFileRaw}/skinbackup.xml"; // backwards compatibilty (in v2.0, exports were saved as skindata.xml) - if (!file_exists($skinFile)) { - $skinFile = $DIR_ADMINSKINS . $skinFileRaw . '/skindata.xml'; + if ( !file_exists($skinFile) ) + { + $skinFile = "{$DIR_SKINS}admin/{$skinFileRaw}/skindata.xml"; } - } else { + } + else + { $skinFile = $skinFileRaw; } + $importer = new SKINIMPORT(); - $error = $importer->readFile($skinFile); - if ($error) { - $this->error($error); + + $error = $importer->readFile($skinFile); + if ( $error ) + { + self::error($error); } + $error = $importer->writeToDatabase($allowOverwrite); - if ($error) { - $this->error($error); + if ( $error ) + { + self::error($error); } - - $_REQUEST['skininfo'] = $importer->getInfo(); - $_REQUEST['skinnames'] = $importer->getSkinNames(); - $_REQUEST['tpltnames'] = $importer->getTemplateNames(); - - $this->pagehead(); - $this->parse('adminskiniedoimport'); - $this->pagefoot(); - + + /* TODO: we should consider to use the other way instead of this */ + $_REQUEST['skininfo'] = $importer->getInfo(); + $_REQUEST['skinnames'] = $importer->getSkinNames(); + $_REQUEST['tpltnames'] = $importer->getTemplateNames(); + + if ( !is_object(self::$skin) ) + { + global $DIR_SKINS; + $query = "SELECT min(sdnumber) FROM %s WHERE sdname != 'admin/bookmarklet' AND sdname LIKE 'admin/%%'"; + $query = sprintf($query, sql_table('skin_desc')); + $res = intval(DB::getValue($query)); + $query = "UPDATE %s SET value = %d WHERE name = 'AdminSkin'"; + $query = sprintf($query, sql_table('config'), $res); + DB::execute($query); + $skin =& $manager->Skin(0, 'AdminActions', 'AdminSkin'); + $skin->parse('importAdmin', $DIR_SKINS . 'admin/defaultimporter.skn'); + } + else + { + self::$skin->parse('adminskiniedoimport'); + } + return; } /** - * @todo document this + * Admin::action_adminskinieexport() + * + * @param void + * @return void */ - function action_adminskinieexport() + static private function action_adminskinieexport() { global $member, $DIR_PLUGINS; - $member->isAdmin() or $this->disallow(); + + $member->isAdmin() or self::disallow(); + // load skinie class - $aSkins = requestIntArray('skin'); - $aTemplates = requestIntArray('template'); - if (!is_array($aTemplates)) { - $aTemplates = array(); - } + $aSkins = requestIntArray('skin'); if (!is_array($aSkins)) { $aSkins = array(); } - $skinList = array_keys($aSkins); + $skinList = array_keys($aSkins); + + $aTemplates = requestIntArray('template'); + if (!is_array($aTemplates)) + { + $aTemplates = array(); + } $templateList = array_keys($aTemplates); - + $info = postVar('info'); - - $exporter = new SkinEXPORT(); - foreach ($skinList as $skinId) { + + include_libs('skinie.php'); + $exporter = new SkinExport(); + foreach ( $skinList as $skinId ) + { $exporter->addSkin($skinId); } - foreach ($templateList as $templateId) { + foreach ( $templateList as $templateId ) + { $exporter->addTemplate($templateId); } $exporter->setInfo($info); $exporter->export(); - + return; } - + /** * Admin::action_settingsedit() * * @param Void * @return Void */ - function action_settingsedit() { + static private function action_settingsedit() + { global $member, $manager, $CONF, $DIR_NUCLEUS, $DIR_MEDIA; - - $member->isAdmin() or $this->disallow(); - - $this->pagehead(); - $this->parse('settingsedit'); - $this->pagefoot(); + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('settingsedit'); + return; } /** @@ -4277,61 +4635,62 @@ class Admin * @param void * @return void */ - function action_settingsupdate() { + static private function action_settingsupdate() + { global $member, $CONF; - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); // check if email address for admin is valid if ( !NOTIFICATION::address_validation(postVar('AdminEmail')) ) { - $this->error(_ERROR_BADMAILADDRESS); + self::error(_ERROR_BADMAILADDRESS); } // save settings - $this->updateConfig('DefaultBlog', postVar('DefaultBlog')); - $this->updateConfig('BaseSkin', postVar('BaseSkin')); - $this->updateConfig('IndexURL', postVar('IndexURL')); - $this->updateConfig('AdminURL', postVar('AdminURL')); - $this->updateConfig('PluginURL', postVar('PluginURL')); - $this->updateConfig('SkinsURL', postVar('SkinsURL')); - $this->updateConfig('ActionURL', postVar('ActionURL')); - $this->updateConfig('Locale', postVar('Locale')); - $this->updateConfig('AdminEmail', postVar('AdminEmail')); - $this->updateConfig('SessionCookie', postVar('SessionCookie')); - $this->updateConfig('AllowMemberCreate',postVar('AllowMemberCreate')); - $this->updateConfig('AllowMemberMail', postVar('AllowMemberMail')); - $this->updateConfig('NonmemberMail', postVar('NonmemberMail')); - $this->updateConfig('ProtectMemNames', postVar('ProtectMemNames')); - $this->updateConfig('SiteName', postVar('SiteName')); - $this->updateConfig('NewMemberCanLogon',postVar('NewMemberCanLogon')); - $this->updateConfig('DisableSite', postVar('DisableSite')); - $this->updateConfig('DisableSiteURL', postVar('DisableSiteURL')); - $this->updateConfig('LastVisit', postVar('LastVisit')); - $this->updateConfig('MediaURL', postVar('MediaURL')); - $this->updateConfig('AllowedTypes', postVar('AllowedTypes')); - $this->updateConfig('AllowUpload', postVar('AllowUpload')); - $this->updateConfig('MaxUploadSize', postVar('MaxUploadSize')); - $this->updateConfig('MediaPrefix', postVar('MediaPrefix')); - $this->updateConfig('AllowLoginEdit', postVar('AllowLoginEdit')); - $this->updateConfig('DisableJsTools', postVar('DisableJsTools')); - $this->updateConfig('CookieDomain', postVar('CookieDomain')); - $this->updateConfig('CookiePath', postVar('CookiePath')); - $this->updateConfig('CookieSecure', postVar('CookieSecure')); - $this->updateConfig('URLMode', postVar('URLMode')); - $this->updateConfig('CookiePrefix', postVar('CookiePrefix')); - $this->updateConfig('DebugVars', postVar('DebugVars')); - $this->updateConfig('DefaultListSize', postVar('DefaultListSize')); - $this->updateConfig('AdminCSS', postVar('AdminCSS')); + self::updateConfig('DefaultBlog', postVar('DefaultBlog')); + self::updateConfig('BaseSkin', postVar('BaseSkin')); + self::updateConfig('IndexURL', postVar('IndexURL')); + self::updateConfig('AdminURL', postVar('AdminURL')); + self::updateConfig('PluginURL', postVar('PluginURL')); + self::updateConfig('SkinsURL', postVar('SkinsURL')); + self::updateConfig('ActionURL', postVar('ActionURL')); + self::updateConfig('Locale', postVar('Locale')); + self::updateConfig('AdminEmail', postVar('AdminEmail')); + self::updateConfig('SessionCookie', postVar('SessionCookie')); + self::updateConfig('AllowMemberCreate', postVar('AllowMemberCreate')); + self::updateConfig('AllowMemberMail', postVar('AllowMemberMail')); + self::updateConfig('NonmemberMail', postVar('NonmemberMail')); + self::updateConfig('ProtectMemNames', postVar('ProtectMemNames')); + self::updateConfig('SiteName', postVar('SiteName')); + self::updateConfig('NewMemberCanLogon', postVar('NewMemberCanLogon')); + self::updateConfig('DisableSite', postVar('DisableSite')); + self::updateConfig('DisableSiteURL', postVar('DisableSiteURL')); + self::updateConfig('LastVisit', postVar('LastVisit')); + self::updateConfig('MediaURL', postVar('MediaURL')); + self::updateConfig('AllowedTypes', postVar('AllowedTypes')); + self::updateConfig('AllowUpload', postVar('AllowUpload')); + self::updateConfig('MaxUploadSize', postVar('MaxUploadSize')); + self::updateConfig('MediaPrefix', postVar('MediaPrefix')); + self::updateConfig('AllowLoginEdit', postVar('AllowLoginEdit')); + self::updateConfig('DisableJsTools', postVar('DisableJsTools')); + self::updateConfig('CookieDomain', postVar('CookieDomain')); + self::updateConfig('CookiePath', postVar('CookiePath')); + self::updateConfig('CookieSecure', postVar('CookieSecure')); + self::updateConfig('URLMode', postVar('URLMode')); + self::updateConfig('CookiePrefix', postVar('CookiePrefix')); + self::updateConfig('DebugVars', postVar('DebugVars')); + self::updateConfig('DefaultListSize', postVar('DefaultListSize')); + self::updateConfig('AdminCSS', postVar('AdminCSS')); // load new config and redirect (this way, the new locale will be used is necessary) // note that when changing cookie settings, this redirect might cause the user // to have to log in again. getConfig(); redirect($CONF['AdminURL'] . '?action=manage'); - exit; + return; } - + /** * Admin::action_systemoverview() * Output system overview @@ -4339,13 +4698,12 @@ class Admin * @param void * @return void */ - function action_systemoverview() + static private function action_systemoverview() { - $this->pagehead(); - $this->parse('systemoverview'); - $this->pagefoot(); + self::$skin->parse('systemoverview'); + return; } - + /** * Admin::updateConfig() * @@ -4353,28 +4711,30 @@ class Admin * @param string $val * @return integer return the ID in which the latest query posted */ - function updateConfig($name, $val) + static private function updateConfig($name, $val) { - $name = sql_real_escape_string($name); - $val = trim(sql_real_escape_string($val)); - - $query = "UPDATE %s SET value='%s' WHERE name='%s'"; - $query = sprintf($query, sql_table('config'), $val, $name); -// sql_query($query) or die("Query error: " . sql_error()); - sql_query($query) or die(_ADMIN_SQLDIE_QUERYERROR . sql_error()); - return sql_insert_id(); + $query = "UPDATE %s SET value=%s WHERE name=%s"; + $query = sprintf($query, sql_table('config'), DB::quoteValue($val), DB::quoteValue($name)); + if ( DB::execute($query) === FALSE ) + { + $err = DB::getError(); + die(_ADMIN_SQLDIE_QUERYERROR . $err[2]); + } + return DB::getInsertId(); } /** + * Admin::error() * Error message - * @param string $msg message that will be shown + * + * @param string $msg message that will be shown + * @return void */ - function error($msg) + static public function error($msg) { - $this->pagehead(); - $this->parse('adminerrorpage'); - $this->pagefoot(); - exit; + self::$headMess = $msg; + self::$skin->parse('adminerrorpage'); + return; } /** @@ -4384,389 +4744,118 @@ class Admin * @param void * @return void */ - function disallow() + static public function disallow() { ActionLog::add(WARNING, _ACTIONLOG_DISALLOWED . serverVar('REQUEST_URI')); - $this->error(_ERROR_DISALLOWED); + self::error(_ERROR_DISALLOWED); + return; } - + /** - * Admin::pagehead() - * Output admin page head - * - * @param void + * Admin::action_PluginAdmin() + * Output pluginadmin + * + * @param string $skinContents + * @param string $extrahead * @return void */ - function pagehead($extrahead = '') + static public function action_PluginAdmin($skinContents, $extrahead = '') { - if ( $this->existsSkinContents('pagehead') ) - { - if ( isset($extrahead) && !empty($extrahead) ) - { - $this->extrahead = $extrahead; - } - $this->parse('pagehead'); - } - else - { - global $member, $nucleus, $CONF, $manager; - - $manager->notify( - 'AdminPrePageHead', - array( - 'extrahead' => &$extrahead, - 'action' => $this->action - ) - ); - - $baseUrl = Entity::hsc($CONF['AdminURL']); - if ( !array_key_exists('AdminCSS',$CONF) ) - { - sql_query("INSERT INTO " . sql_table('config') . " VALUES ('AdminCSS', 'original')"); - $CONF['AdminCSS'] = 'original'; - } - - /* HTTP 1.1 application for no caching */ - header("Cache-Control: no-cache, must-revalidate"); - header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); - - $root_element = 'html'; - $charset = i18n::get_current_charset(); - $locale = preg_replace('#_#', '-', i18n::get_current_locale()); - - echo "xml_version_info}\" encoding=\"{$charset}\" ?>\n"; - echo "formal_public_identifier}\" \"{$this->system_identifier}\">\n"; - echo "<{$root_element} xmlns=\"{$this->xhtml_namespace}\" xml:lang=\"{$locale}\" lang=\"{$locale}\">\n"; - echo "\n"; - echo '' . Entity::hsc($CONF['SiteName']) . " - Admin\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "{$extrahead}\n"; - echo "\n\n"; - echo "\n"; - echo "
\n"; - echo "
\n"; - echo '

' . Entity::hsc($CONF['SiteName']) . "

\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - if ( $member->isLoggedIn() ) - { - echo _LOGGEDINAS . ' ' . $member->getDisplayName() ." - " . _LOGOUT. "
\n"; - echo "" . _ADMINHOME . " - "; - } - else - { - echo '' . _NOTLOGGEDIN . "
\n"; - } - echo ""._YOURSITE."
\n"; - echo '('; - - if (array_key_exists('codename', $nucleus) && $nucleus['codename'] != '' ) - { - $codenamestring = ' "' . $nucleus['codename'].'"'; - } - else - { - $codenamestring = ''; - } - - if ( $member->isLoggedIn() && $member->isAdmin() ) - { - $checkURL = sprintf(_ADMIN_SYSTEMOVERVIEW_VERSIONCHECK_URL, getNucleusVersion(), getNucleusPatchLevel()); - echo 'Nucleus CMS ' . $nucleus['version'] . $codenamestring . ''; - - $newestVersion = getLatestVersion(); - $newestCompare = str_replace('/','.',$newestVersion); - $currentVersion = str_replace(array('/','v'),array('.',''),$nucleus['version']); - if ( $newestVersion && version_compare($newestCompare, $currentVersion) > 0 ) - { - echo "
\n"; - echo ''; - echo _ADMIN_SYSTEMOVERVIEW_LATESTVERSION_TEXT . $newestVersion; - echo ""; - } - } - else - { - echo 'Nucleus CMS ' . $nucleus['version'] . $codenamestring; - } - echo ')'; - echo '
'; - } + self::$extrahead .= $extrahead; + self::$skin->parse('pluginadmin', $skinContents); return; } /** - * Admin::pagefoot() - * Output admin page foot include quickmenu + * Admin::action_bookmarklet() * * @param void * @return void */ - function pagefoot() + static private function action_bookmarklet() { - if ($this->existsSkinContents('pagefoot')) { - $this->parse('pagefoot'); - exit; - } - else - { - global $action, $member, $manager; - - $manager->notify( - 'AdminPrePageFoot', - array( - 'action' => $this->action - ) - ); - - if ( $member->isLoggedIn() && ($action != 'showlogin') ) - { - echo '

' . _LOGOUT . "

\n"; - echo "\n"; - } - - echo "
\n"; - echo 'Nucleus CMS © 2002-' . date('Y') . ' ' . _ADMINPAGEFOOT_COPYRIGHT; - echo '-'; - echo '' . _ADMINPAGEFOOT_DONATE . "\n"; - echo "
\n"; - - echo "\n"; - echo "
\n"; - - if ( ($action != 'showlogin') && ($member->isLoggedIn()) ) - { - echo "\n"; - - echo '

' . _QMENU_ADD . "

\n"; - echo "
\n"; - echo "

\n"; - echo "\n"; - - $showAll = requestVar('showall'); - - if ( ($member->isAdmin()) && ($showAll == 'yes') ) - { - // Super-Admins have access to all blogs! (no add item support though) - $query = 'SELECT bnumber as value, bname as text' - . ' FROM ' . sql_table('blog') - . ' ORDER BY bname'; - } - else - { - $query = 'SELECT bnumber as value, bname as text' - . ' FROM ' . sql_table('blog') . ', ' . sql_table('team') - . ' WHERE tblog=bnumber and tmember=' . $member->getID() - . ' ORDER BY bname'; - } - $template['name'] = 'blogid'; - $template['tabindex'] = 15000; - $template['extra'] = _QMENU_ADD_SELECT; - $template['selected'] = -1; - $template['shorten'] = 10; - $template['shortenel'] = ''; - $template['javascript'] = 'onchange="return form.submit()"'; - showlist($query,'select',$template); - - echo "

\n"; - echo "
\n"; - - echo "

{$member->getDisplayName()}

\n"; - echo "\n"; - - // ---- general settings ---- - if ( $member->isAdmin() ) - { - echo '

' . _QMENU_MANAGE . "

\n"; - echo "\n"; - - echo "

" . _QMENU_LAYOUT . "

\n"; - echo "\n"; - } - - $aPluginExtras = array(); - $manager->notify( - 'QuickMenu', - array( - 'options' => &$aPluginExtras)); - - if ( count($aPluginExtras) > 0 ) - { - echo "

" . _QMENU_PLUGINS . "

\n"; - echo "\n"; - } - } - else if ( ($action == 'activate') || ($action == 'activatesetpwd') ) - { - - echo '

' . _QMENU_ACTIVATE . '

' . _QMENU_ACTIVATE_TEXT; - } - else - { - // introduction text on login screen - echo '

' . _QMENU_INTRO . '

' . _QMENU_INTRO_TEXT; - } - - echo "\n"; - echo "
\n"; - - echo "\n"; - echo "
\n"; - - echo "\n"; - echo "
\n"; - - echo "\n"; - echo "
\n"; - - echo "\n"; - echo "\n"; - } + global $member, $manager; + + $blogid = intRequestVar('blogid'); + $member->teamRights($blogid) or self::disallow(); + + self::$skin->parse('bookmarklet'); return; } /** - * @todo document this - */ - function action_regfile() - { - global $member, $CONF; - - $blogid = intRequestVar('blogid'); - - $member->teamRights($blogid) or $this->disallow(); - - // header-code stolen from phpMyAdmin - // REGEDIT and bookmarklet code stolen from GreyMatter - - $sjisBlogName = sprintf(_WINREGFILE_TEXT, getBlogNameFromID($blogid)); - - - header('Content-Type: application/octetstream'); - header('Content-Disposition: filename="nucleus.reg"'); - header('Pragma: no-cache'); - header('Expires: 0'); - - echo "REGEDIT4\n"; - echo "[HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\MenuExt\\" . $sjisBlogName . "]\n"; - echo '@="' . $CONF['AdminURL'] . "bookmarklet.php?action=contextmenucode&blogid=".intval($blogid)."\"\n"; - echo '"contexts"=hex:31'; - } - - /** - * @todo document this + * Admin::action_actionlog() + * + * @param void + * @return void */ - function action_bookmarklet() + static private function action_actionlog() { global $member, $manager; - - $member->teamRights($blogid) or $this->disallow(); - - $blogid = intRequestVar('blogid'); - - $this->pagehead(); - $this->parse('bookmarklet'); - $this->pagefoot(); - + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('actionlog'); + return; } - + /** - * @todo document this + * Admin::action_banlist() + * + * @param void + * @return void */ - function action_actionlog() + static private function action_banlist() { global $member, $manager; - - $member->isAdmin() or $this->disallow(); - - $this->pagehead(); - $this->parse('actionlog'); - $this->pagefoot(); - - } - - /** - * @todo document this - */ - function action_banlist() { - global $member, $manager; - - $member->blogAdminRights($blogid) or $this->disallow(); - + $blogid = intRequestVar('blogid'); - - $this->pagehead(); - $this->parse('banlist'); - $this->pagefoot(); - + $member->blogAdminRights($blogid) or self::disallow(); + + self::$skin->parse('banlist'); + return; } - + /** - * @todo document this + * Admin::action_banlistdelete() + * + * @param void + * @return void */ - function action_banlistdelete() { + static private function action_banlistdelete() + { global $member, $manager; - + $blogid = intRequestVar('blogid'); - $member->blogAdminRights($blogid) or $this->disallow(); - - $this->pagehead(); - $this->parse('banlistdelete'); - $this->pagefoot(); + $member->blogAdminRights($blogid) or self::disallow(); + + self::$skin->parse('banlistdelete'); + return; } - + /** - * @todo document this + * Admin::action_banlistdeleteconfirm() + * + * @param void + * @return void */ - function action_banlistdeleteconfirm() + static private function action_banlistdeleteconfirm() { global $member, $manager; - - $member->blogAdminRights($blogid) or $this->disallow(); - - $blogid = intPostVar('blogid'); - $allblogs = postVar('allblogs'); - $iprange = postVar('iprange'); - + + $blogid = intPostVar('blogid'); + $allblogs = postVar('allblogs'); + $iprange = postVar('iprange'); + + $member->blogAdminRights($blogid) or self::disallow(); + $deleted = array(); - + if ( !$allblogs ) { if ( Ban::removeBan($blogid, $iprange) ) { - array_push($deleted, $blogid); + $deleted[] = $blogid; } } else @@ -4777,77 +4866,95 @@ class Admin { if ( Ban::removeBan($blogje, $iprange) ) { - array_push($deleted, $blogje); + $deleted[] = $blogje; } } } - + if ( sizeof($deleted) == 0 ) { - $this->error(_ERROR_DELETEBAN); + self::error(_ERROR_DELETEBAN); } - - $this->pagehead(); - $this->parse('banlistdeleteconfirm'); - $this->pagefoot(); - + + /* TODO: we should use other ways */ + $_REQUEST['delblogs'] = $deleted; + + self::$skin->parse('banlistdeleteconfirm'); + return; } - + /** - * @todo document this + * Admin::action_banlistnewfromitem() + * + * @param void + * @return void */ - function action_banlistnewfromitem() + static private function action_banlistnewfromitem() { - $this->action_banlistnew(getBlogIDFromItemID(intRequestVar('itemid'))); + global $manager; + + $itemid = intRequestVar('itemid'); + $item =& $manager->getItem($itemid, 1, 1); + self::action_banlistnew($item['blogid']); + return; } - + /** - * @todo document this + * Admin::action_banlistnew() + * + * @param integer $blogid ID for weblog + * @return void */ - function action_banlistnew($blogid = '') + static private function action_banlistnew($blogid = '') { global $member, $manager; - + if ( $blogid == '' ) { $blogid = intRequestVar('blogid'); } - + $ip = requestVar('ip'); - - $member->blogAdminRights($blogid) or $this->disallow(); - + + $member->blogAdminRights($blogid) or self::disallow(); + + /* TODO: we should consider to use the other way instead of this */ $_REQUEST['blogid'] = $blogid; - - $this->pagehead(); - $this->parse('banlistnew'); - $this->pagefoot(); + + self::$skin->parse('banlistnew'); + + return; } /** - * @todo document this + * Admin::action_banlistadd() + * + * @param void + * @return void */ - function action_banlistadd() { + static private function action_banlistadd() + { global $member; - - $blogid = intPostVar('blogid'); - $allblogs = postVar('allblogs'); - $iprange = postVar('iprange'); + + $blogid = intPostVar('blogid'); + $allblogs = postVar('allblogs'); + $iprange = postVar('iprange'); + if ( $iprange == "custom" ) { $iprange = postVar('customiprange'); } $reason = postVar('reason'); - - $member->blogAdminRights($blogid) or $this->disallow(); - + + $member->blogAdminRights($blogid) or self::disallow(); + // TODO: check IP range validity - + if ( !$allblogs ) { if ( !Ban::addBan($blogid, $iprange, $reason) ) { - $this->error(_ERROR_ADDBAN); + self::error(_ERROR_ADDBAN); } } else @@ -4864,38 +4971,45 @@ class Admin } if ( $failed ) { - $this->error(_ERROR_ADDBAN); + self::error(_ERROR_ADDBAN); } } - $this->action_banlist(); + self::action_banlist(); + return; } - + /** - * @todo document this + * Admin::action_clearactionlog() + * + * @param void + * @return void */ - function action_clearactionlog() + static private function action_clearactionlog() { global $member; - - $member->isAdmin() or $this->disallow(); - + + $member->isAdmin() or self::disallow(); + ActionLog::clear(); - - $this->action_manage(_MSG_ACTIONLOGCLEARED); + + self::action_manage(_MSG_ACTIONLOGCLEARED); + return; } - + /** - * @todo document this + * Admin::action_backupoverview() + * + * @param void + * @return void */ - function action_backupoverview() + static private function action_backupoverview() { global $member, $manager; - - $member->isAdmin() or $this->disallow(); - - $this->pagehead(); - $this->parse('backupoverview'); - $this->pagefoot(); + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('backupoverview'); + return; } /** @@ -4906,11 +5020,11 @@ class Admin * @return void * */ - function action_backupcreate() + static private function action_backupcreate() { global $member, $DIR_LIBS; - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); // use compression ? $useGzip = (integer) postVar('gzip'); @@ -4932,15 +5046,15 @@ class Admin * @param void * @return void */ - function action_backuprestore() + static private function action_backuprestore() { global $member, $DIR_LIBS; - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); if ( intPostVar('letsgo') != 1 ) { - $this->error(_ERROR_BACKUP_NOTSURE); + self::error(_ERROR_BACKUP_NOTSURE); } include($DIR_LIBS . 'backup.php'); @@ -4952,11 +5066,9 @@ class Admin $message = Backup::do_restore(); if ( $message != '' ) { - $this->error($message); + self::error($message); } - $this->pagehead(); - $this->parse('backuprestore'); - $this->pagefoot(); + self::$skin->parse('backuprestore'); return; } @@ -4968,41 +5080,41 @@ class Admin * @return void * */ - function action_pluginlist() + static private function action_pluginlist() { global $DIR_PLUGINS, $member, $manager; // check if allowed - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); - $this->pagehead(); - $this->parse('pluginlist'); - $this->pagefoot(); + self::$skin->parse('pluginlist'); return; } /** - * @todo document this + * Admin::action_pluginhelp() + * + * @param void + * @return void */ - function action_pluginhelp() + static private function action_pluginhelp() { global $member, $manager, $DIR_PLUGINS, $CONF; - + // check if allowed - $member->isAdmin() or $this->disallow(); - + $member->isAdmin() or self::disallow(); + $plugid = intGetVar('plugid'); - + if ( !$manager->pidInstalled($plugid) ) { - $this->error(_ERROR_NOSUCHPLUGIN); + self::error(_ERROR_NOSUCHPLUGIN); } - - $this->pagehead(); - $this->parse('pluginhelp'); - $this->pagefoot(); + + self::$skin->parse('pluginhelp'); + return; } - + /** * Admin::action_pluginadd() * @@ -5010,51 +5122,40 @@ class Admin * @return Void * */ - function action_pluginadd() + static private function action_pluginadd() { global $member, $manager, $DIR_PLUGINS; // check if allowed - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); $name = postVar('filename'); if ( $manager->pluginInstalled($name) ) { - $this->error(_ERROR_DUPPLUGIN); + self::error(_ERROR_DUPPLUGIN); } if ( !checkPlugin($name) ) { - $this->error(_ERROR_PLUGFILEERROR . ' (' . Entity::hsc($name) . ')'); + self::error(_ERROR_PLUGFILEERROR . ' (' . Entity::hsc($name) . ')'); } // get number of currently installed plugins - $res = sql_query('SELECT * FROM ' . sql_table('plugin')); - $numCurrent = sql_num_rows($res); + $res = DB::getResult('SELECT * FROM ' . sql_table('plugin')); + $numCurrent = $res->rowCount(); // plugin will be added as last one in the list $newOrder = $numCurrent + 1; - $manager->notify( - 'PreAddPlugin', - array( - 'file' => &$name - ) - ); + $data = array('file' => &$name); + $manager->notify('PreAddPlugin', $data); // do this before calling getPlugin (in case the plugin id is used there) - $query = 'INSERT INTO ' - . sql_table('plugin') - . ' (' - . ' porder,' - . ' pfile' - . ') VALUES (' - . $newOrder . ',' - . '"' . sql_real_escape_string($name) . '"' - . ')'; - sql_query($query); - $iPid = sql_insert_id(); + $query = "INSERT INTO %s (porder, pfile) VALUES (%d, %s);"; + $query = sprintf($query, sql_table('plugin'), (integer) $newOrder, DB::quoteValue($name)); + DB::execute($query); + $iPid = DB::getInsertId(); $manager->clearCachedInfo('installedPlugins'); @@ -5064,55 +5165,55 @@ class Admin // check if it got loaded (could have failed) if ( !$plugin ) { - sql_query('DELETE FROM ' . sql_table('plugin') . ' WHERE pid='. intval($iPid)); + $query = "DELETE FROM %s WHERE pid=%d;"; + $query = sprintf($query, sql_table('plugin'), (integer) $iPid); + + DB::execute($query); + $manager->clearCachedInfo('installedPlugins'); - $this->error(_ERROR_PLUGIN_LOAD); + self::error(_ERROR_PLUGIN_LOAD); } // check if plugin needs a newer Nucleus version if ( getNucleusVersion() < $plugin->getMinNucleusVersion() ) { // uninstall plugin again... - $this->deleteOnePlugin($plugin->getID()); + self::deleteOnePlugin($plugin->getID()); // ...and show error - $this->error(_ERROR_NUCLEUSVERSIONREQ . Entity::hsc($plugin->getMinNucleusVersion())); + self::error(_ERROR_NUCLEUSVERSIONREQ . Entity::hsc($plugin->getMinNucleusVersion())); } // check if plugin needs a newer Nucleus version if ( (getNucleusVersion() == $plugin->getMinNucleusVersion()) && (getNucleusPatchLevel() < $plugin->getMinNucleusPatchLevel()) ) { // uninstall plugin again... - $this->deleteOnePlugin($plugin->getID()); + self::deleteOnePlugin($plugin->getID()); // ...and show error - $this->error(_ERROR_NUCLEUSVERSIONREQ . Entity::hsc( $plugin->getMinNucleusVersion() . ' patch ' . $plugin->getMinNucleusPatchLevel() ) ); + self::error(_ERROR_NUCLEUSVERSIONREQ . Entity::hsc( $plugin->getMinNucleusVersion() . ' patch ' . $plugin->getMinNucleusPatchLevel() ) ); } $pluginList = $plugin->getPluginDep(); foreach ( $pluginList as $pluginName ) { - $res = sql_query('SELECT * FROM '.sql_table('plugin') . ' WHERE pfile="' . $pluginName . '"'); - if (sql_num_rows($res) == 0) + $res = DB::getResult('SELECT * FROM '.sql_table('plugin') . ' WHERE pfile=' . DB::quoteValue($pluginName)); + if ($res->rowCount() == 0) { // uninstall plugin again... - $this->deleteOnePlugin($plugin->getID()); - $this->error(sprintf(_ERROR_INSREQPLUGIN, Entity::hsc($pluginName))); + self::deleteOnePlugin($plugin->getID()); + self::error(sprintf(_ERROR_INSREQPLUGIN, Entity::hsc($pluginName))); } } // call the install method of the plugin $plugin->install(); - $manager->notify( - 'PostAddPlugin', - array( - 'plugin' => &$plugin - ) - ); + $data = array('plugin' => &$plugin); + $manager->notify('PostAddPlugin', $data); // update all events - $this->action_pluginupdate(); + self::action_pluginupdate(); return; } @@ -5123,30 +5224,30 @@ class Admin * @return Void * */ - function action_pluginupdate() + static private function action_pluginupdate() { global $member, $manager, $CONF; // check if allowed - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); // delete everything from plugin_events - sql_query('DELETE FROM '.sql_table('plugin_event')); + DB::execute('DELETE FROM '.sql_table('plugin_event')); // loop over all installed plugins - $res = sql_query('SELECT pid, pfile FROM '.sql_table('plugin')); - while ( $o = sql_fetch_object($res) ) + $res = DB::getResult('SELECT pid, pfile FROM '.sql_table('plugin')); + foreach ( $res as $row ) { - $pid = $o->pid; - $plug =& $manager->getPlugin($o->pfile); + $pid = $row['pid']; + $plug =& $manager->getPlugin($row['pfile']); if ( $plug ) { $eventList = $plug->getEventList(); foreach ( $eventList as $eventName ) { - $query = "INSERT INTO %s (pid, event) VALUES (%d, '%s')"; - $query = sprintf($query, sql_table('plugin_event'), (integer) $pid, sql_real_escape_string($eventName)); - sql_query($query); + $query = "INSERT INTO %s (pid, event) VALUES (%d, %s)"; + $query = sprintf($query, sql_table('plugin_event'), (integer) $pid, DB::quoteValue($eventName)); + DB::execute($query); } } } @@ -5155,95 +5256,96 @@ class Admin } /** - * @todo document this + * Admin::action_plugindelete() + * + * @param void + * @return void */ - function action_plugindelete() + static private function action_plugindelete() { global $member, $manager; - + // check if allowed - $member->isAdmin() or $this->disallow(); - + $member->isAdmin() or self::disallow(); + $pid = intGetVar('plugid'); - + if ( !$manager->pidInstalled($pid) ) { - $this->error(_ERROR_NOSUCHPLUGIN); + self::error(_ERROR_NOSUCHPLUGIN); } - - $this->pagehead(); - $this->parse('plugindelete'); - $this->pagefoot(); + + self::$skin->parse('plugindelete'); + return; } /** - * @todo document this + * Admin::action_plugindeleteconfirm() + * + * @param void + * @return void */ - function action_plugindeleteconfirm() + static private function action_plugindeleteconfirm() { global $member, $manager, $CONF; - + // check if allowed - $member->isAdmin() or $this->disallow(); - + $member->isAdmin() or self::disallow(); + $pid = intPostVar('plugid'); - - $error = $this->deleteOnePlugin($pid, 1); - if ($error) { - $this->error($error); + + $error = self::deleteOnePlugin($pid, 1); + if ( $error ) + { + self::error($error); } - + redirect($CONF['AdminURL'] . '?action=pluginlist'); -// $this->action_pluginlist(); + return; } - + /** - * @todo document this + * Admin:: + * + * @param void + * @return void */ - function deleteOnePlugin($pid, $callUninstall = 0) + static public function deleteOnePlugin($pid, $callUninstall = 0) { global $manager; - + $pid = intval($pid); - + if ( !$manager->pidInstalled($pid) ) { return _ERROR_NOSUCHPLUGIN; } - - $name = quickQuery('SELECT pfile as result FROM ' . sql_table('plugin') . ' WHERE pid=' . $pid); - -/* // call the unInstall method of the plugin - if ($callUninstall) { - $plugin =& $manager->getPlugin($name); - if ($plugin) $plugin->unInstall(); - }*/ - + + $query = "SELECT pfile as result FROM %s WHERE pid=%d;"; + $query = sprintf($query, sql_table('plugin'), (integer) $pid); + $name = DB::getValue($query); + // check dependency before delete - $res = sql_query('SELECT pfile FROM ' . sql_table('plugin')); - while ($o = sql_fetch_object($res)) + $res = DB::getResult('SELECT pfile FROM ' . sql_table('plugin')); + foreach ( $res as $row ) { - $plug =& $manager->getPlugin($o->pfile); - if ($plug) + $plug =& $manager->getPlugin($row['pfile']); + if ( $plug ) { $depList = $plug->getPluginDep(); - foreach ($depList as $depName) + foreach ( $depList as $depName ) { - if ($name == $depName) + if ( $name == $depName ) { - return sprintf(_ERROR_DELREQPLUGIN, $o->pfile); + return sprintf(_ERROR_DELREQPLUGIN, $row['pfile']); } } } } - - $manager->notify( - 'PreDeletePlugin', - array( - 'plugid' => $pid - ) - ); - + + $data = array('plugid' => $pid); + $manager->notify('PreDeletePlugin', $data); + // call the unInstall method of the plugin if ( $callUninstall ) { @@ -5253,113 +5355,112 @@ class Admin $plugin->unInstall(); } } - + // delete all subscriptions - sql_query('DELETE FROM ' . sql_table('plugin_event') . ' WHERE pid=' . $pid); - + DB::execute('DELETE FROM ' . sql_table('plugin_event') . ' WHERE pid=' . $pid); + // delete all options // get OIDs from plugin_option_desc - $res = sql_query('SELECT oid FROM ' . sql_table('plugin_option_desc') . ' WHERE opid=' . $pid); + $res = DB::getResult('SELECT oid FROM ' . sql_table('plugin_option_desc') . ' WHERE opid=' . $pid); $aOIDs = array(); - while ($o = sql_fetch_object($res)) + foreach ( $res as $row ) { - array_push($aOIDs, $o->oid); + array_push($aOIDs, $row['oid']); } - + // delete from plugin_option and plugin_option_desc - sql_query('DELETE FROM ' . sql_table('plugin_option_desc') . ' WHERE opid=' . $pid); + DB::execute('DELETE FROM ' . sql_table('plugin_option_desc') . ' WHERE opid=' . $pid); if (count($aOIDs) > 0) { - sql_query('DELETE FROM ' . sql_table('plugin_option') . ' WHERE oid in (' . implode(',',$aOIDs) . ')'); + DB::execute('DELETE FROM ' . sql_table('plugin_option') . ' WHERE oid in (' . implode(',', $aOIDs) . ')'); } - + // update order numbers - $res = sql_query('SELECT porder FROM ' . sql_table('plugin') . ' WHERE pid=' . $pid); - $o = sql_fetch_object($res); - sql_query('UPDATE ' . sql_table('plugin') . ' SET porder=(porder - 1) WHERE porder>' . $o->porder); - + $res = DB::getValue('SELECT porder FROM ' . sql_table('plugin') . ' WHERE pid=' . $pid); + DB::execute('UPDATE ' . sql_table('plugin') . ' SET porder=(porder - 1) WHERE porder>' . $res); + // delete row - sql_query('DELETE FROM ' . sql_table('plugin') . ' WHERE pid=' . $pid); - + DB::execute('DELETE FROM ' . sql_table('plugin') . ' WHERE pid=' . $pid); + $manager->clearCachedInfo('installedPlugins'); - $manager->notify( - 'PostDeletePlugin', - array( - 'plugid' => $pid - ) - ); - + $data = array('plugid' => $pid); + $manager->notify('PostDeletePlugin', $data); + return ''; } - + /** - * @todo document this + * Admin::action_pluginup() + * + * @param void + * @return void */ - function action_pluginup() + static private function action_pluginup() { global $member, $manager, $CONF; - + // check if allowed - $member->isAdmin() or $this->disallow(); - + $member->isAdmin() or self::disallow(); + $plugid = intGetVar('plugid'); - + if ( !$manager->pidInstalled($plugid) ) { - $this->error(_ERROR_NOSUCHPLUGIN); + self::error(_ERROR_NOSUCHPLUGIN); } - + // 1. get old order number - $res = sql_query('SELECT porder FROM ' . sql_table('plugin') . ' WHERE pid=' . $plugid); - $o = sql_fetch_object($res); - $oldOrder = $o->porder; - + $oldOrder = DB::getValue('SELECT porder FROM ' . sql_table('plugin') . ' WHERE pid=' . $plugid); + // 2. calculate new order number $newOrder = ($oldOrder > 1) ? ($oldOrder - 1) : 1; - + // 3. update plug numbers - sql_query('UPDATE ' . sql_table('plugin') . ' SET porder=' . $oldOrder . ' WHERE porder=' . $newOrder); - sql_query('UPDATE ' . sql_table('plugin') . ' SET porder=' . $newOrder . ' WHERE pid=' . $plugid); - - //$this->action_pluginlist(); + DB::execute('UPDATE ' . sql_table('plugin') . ' SET porder=' . $oldOrder . ' WHERE porder=' . $newOrder); + DB::execute('UPDATE ' . sql_table('plugin') . ' SET porder=' . $newOrder . ' WHERE pid=' . $plugid); + + //self::action_pluginlist(); // To avoid showing ticket in the URL, redirect to pluginlist, instead. redirect($CONF['AdminURL'] . '?action=pluginlist'); + return; } - + /** - * @todo document this + * Admin::action_plugindown() + * + * @param void + * @return void */ - function action_plugindown() + static private function action_plugindown() { global $member, $manager, $CONF; - + // check if allowed - $member->isAdmin() or $this->disallow(); - + $member->isAdmin() or self::disallow(); + $plugid = intGetVar('plugid'); if ( !$manager->pidInstalled($plugid) ) { - $this->error(_ERROR_NOSUCHPLUGIN); + self::error(_ERROR_NOSUCHPLUGIN); } - + // 1. get old order number - $res = sql_query('SELECT porder FROM ' . sql_table('plugin') . ' WHERE pid=' . $plugid); - $o = sql_fetch_object($res); - $oldOrder = $o->porder; - - $res = sql_query('SELECT * FROM ' . sql_table('plugin')); - $maxOrder = sql_num_rows($res); - + $oldOrder = DB::getValue('SELECT porder FROM ' . sql_table('plugin') . ' WHERE pid=' . $plugid); + + $res = DB::getResult('SELECT * FROM ' . sql_table('plugin')); + $maxOrder = $res->rowCount(); + // 2. calculate new order number $newOrder = ($oldOrder < $maxOrder) ? ($oldOrder + 1) : $maxOrder; - + // 3. update plug numbers - sql_query('UPDATE ' . sql_table('plugin') . ' SET porder=' . $oldOrder . ' WHERE porder=' . $newOrder); - sql_query('UPDATE ' . sql_table('plugin') . ' SET porder=' . $newOrder . ' WHERE pid=' . $plugid); - - //$this->action_pluginlist(); + DB::execute('UPDATE ' . sql_table('plugin') . ' SET porder=' . $oldOrder . ' WHERE porder=' . $newOrder); + DB::execute('UPDATE ' . sql_table('plugin') . ' SET porder=' . $newOrder . ' WHERE pid=' . $plugid); + + //self::action_pluginlist(); // To avoid showing ticket in the URL, redirect to pluginlist, instead. redirect($CONF['AdminURL'] . '?action=pluginlist'); + return; } /** @@ -5372,28 +5473,28 @@ class Admin * @return void * */ - public function action_pluginoptions($message = '') + static private function action_pluginoptions($message = '') { global $member, $manager; // check if allowed - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); -// $pid = (integer) requestVar('plugid'); $pid = intRequestVar('plugid'); if ( !$manager->pidInstalled($pid) ) { - $this->error(_ERROR_NOSUCHPLUGIN); + self::error(_ERROR_NOSUCHPLUGIN); } - + if ( isset($message) ) { - $this->headMess = $message; + self::$headMess = $message; } - $extrahead = "\n"; - $this->pagehead($extrahead); - $this->parse('pluginoptions'); - $this->pagefoot(); + $plugname = $manager->getPluginNameFromPid($pid); + $plugin = $manager->getPlugin($plugname); + Admin::$extrahead .= "\n"; + + self::$skin->parse('pluginoptions'); return; } @@ -5406,218 +5507,117 @@ class Admin * @param void * @return void */ - public function action_pluginoptionsupdate() + static private function action_pluginoptionsupdate() { global $member, $manager; // check if allowed - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); $pid = intRequestVar('plugid'); -// $pid = (integer) requestVar('plugid'); + if ( !$manager->pidInstalled($pid) ) { - $this->error(_ERROR_NOSUCHPLUGIN); + self::error(_ERROR_NOSUCHPLUGIN); } $aOptions = requestArray('plugoption'); NucleusPlugin::apply_plugin_options($aOptions); - - $manager->notify( - 'PostPluginOptionsUpdate', - array( - 'context' => 'global', - 'plugid' => $pid - ) + + $data = array( + 'context' => 'global', + 'plugid' => $pid ); + $manager->notify('PostPluginOptionsUpdate', $data); - $this->action_pluginoptions(_PLUGS_OPTIONS_UPDATED); + self::action_pluginoptions(_PLUGS_OPTIONS_UPDATED); return; } /** - * Admin::_insertPluginOptions() - * - * Output plugin option field + * Admin::action_parseSpecialskin() * - * @access public - * @param string $context plugin option context - * @param integer $contextid plugin option context id + * @param void * @return void */ - public function _insertPluginOptions($context, $contextid = 0) + static private function action_parseSpecialskin() { - // get all current values for this contextid - // (note: this might contain doubles for overlapping contextids) - $aIdToValue = array(); - $res = sql_query('SELECT oid, ovalue FROM ' . sql_table('plugin_option') . ' WHERE ocontextid=' . intval($contextid)); - while ( $object = sql_fetch_object($res) ) - { - $aIdToValue[$object->oid] = $object->ovalue; - } - - // get list of oids per pid - $query = 'SELECT ' - . ' * ' - . 'FROM ' - . sql_table('plugin_option_desc') . ', ' - . sql_table('plugin') . ' ' - . 'WHERE ' - . ' opid = pid ' - . 'and ocontext = "' . sql_real_escape_string($context) . '" ' - . 'ORDER BY ' - . ' porder, oid ASC'; - $res = sql_query($query); - $aOptions = array(); - while ( $object = sql_fetch_object($res) ) - { - if (in_array($object->oid, array_keys($aIdToValue))) - { - $value = $aIdToValue[$object->oid]; - } - else - { - $value = $object->odef; - } - - array_push( - $aOptions, - array( - 'pid' => $object->pid, - 'pfile' => $object->pfile, - 'oid' => $object->oid, - 'value' => $value, - 'name' => $object->oname, - 'description' => $object->odesc, - 'type' => $object->otype, - 'typeinfo' => $object->oextra, - 'contextid' => $contextid, - 'extra' => '' - ) - ); - } - - global $manager; - $manager->notify( - 'PrePluginOptionsEdit', - array( - 'context' => $context, - 'contextid' => $contextid, - 'options' =>& $aOptions - ) - ); - - $this->aOptions = $aOptions; - $this->parse('insertpluginoptions'); + self::$skin->parse(self::$action); return; } /** - * TODO: this document + * Admin::getAdminskinIDFromName() + * + * @param string $skinname name of skin + * @return integer ID for skin */ - function action_parseSpecialskin() + static private function getAdminskinIDFromName($skinname) { - $this->pagehead(); - $this->parse($this->action); - $this->pagefoot(); + $query = "SELECT 'sdnumber' as result FROM %s WHERE sdname = %s;"; + $query = sprintf($query, sql_table('skin_desc'), DB::quoteValue($skinname)); + $admnSknID = DB::getValue($query); + return (integer) $adminSkinID; } - function parse($type) + /** + * Admin::getAdminskinNameFromID() + * + * @param integer $skinid ID for skin + * @return integer ID for skin + */ + static private function getAdminskinNameFromID($skinid) { - global $manager, $CONF; - if ( $type == 'pagehead' ) - { - $manager->notify( - 'InitAdminSkinParse', - array( - 'skin' => &$this->adminSkin, - 'type' => $type - ) - ); - // set output type - sendContentType($this->adminSkin->getContentType(), 'skin', i18n::get_current_charset()); - } - // set skin name as global var (so plugins can access it) - global $currentSkinName; - $currentSkinName = $this->adminSkin->getName(); - - $contents = $this->adminSkin->getContent($type); - - if ( !$contents ) - { - // use base skin if this skin does not have contents - $defskin = new Skin($CONF['DefaultAdminSkin']); - $contents = $defskin->getContent($type); - if ( !$contents ) - { - echo _ERROR_SKIN; - return; - } - } - - $actions = $this->adminSkin->getAllowedActionsForType($type); - - if ( $type == 'pagehead' ) - { - $manager->notify( - 'PreAdminSkinParse', - array( - 'skin' => &$this->adminSkin, - 'type' => $type, - 'contents' => &$contents - ) - ); - } - - // set IncludeMode properties of parser - PARSER::setProperty('IncludeMode', $this->adminSkin->getIncludeMode()); - PARSER::setProperty('IncludePrefix', $this->adminSkin->getIncludePrefix()); + $query = "SELECT sdname as result FROM %s WHERE sdnumber = %d;"; + $query = sprintf($query, sql_table('skin_desc'), (integer) $skinid); + $admnSknID = DB::getValue($query); + return (integer) $adminSkinID; + } - if ( $type == 'createitem' || $type == 'itemedit' ) - { - $handler = new Factory(intRequestVar('blogid'), $type, $this->adminSkin, $this); - $actions = array_merge($actions, $handler->actions); - } else { - $handler = new AdminActions($type, $this->adminSkin, $this); - $actions = array_merge($actions, AdminActions::get_allowed_actions_for_type($type)); - } - $parser = new Parser($actions, $handler); - $handler->setParser($parser); - $handler->setSkin($this->adminSkin); - $parser->parse($contents); + /** + * Admin::getAdminextrahead() + */ + static public function getAdminextrahead() + { + return self::$extrahead; + } - if ( $type == 'pagefoot' ) - { - $manager->notify( - 'PostAdminSkinParse', - array( - 'skin' => &$this->adminSkin, - 'type' => $type, - ) - ); - } + /** + * Admin::getAdminpassvar() + */ + static public function getAdminpassvar() + { + return self::$passvar; } - function getAdminskinIDFromName($skinname) + /** + * Admin::getAdminAction() + */ + static public function getAdminAction() { - $query = 'SELECT `sdnumber` as result FROM `%s` WHERE `sdname` = "%s"'; - $admnSknID = quickQuery(sprintf($query, sql_table('nucleus_adminskin_desc'), mysql_real_escape_string($skinname))); - return intval($adminSkinID); + return self::$action; } - function getAdminskinNameFromID($skinid) + /** + * Admin::getAdminaOption() + */ + static public function getAdminaOption() { - $query = 'SELECT `sdname` as result FROM `%s` WHERE `sdnumber` = "%d"'; - $admnSknID = quickQuery(sprintf($query, sql_table('nucleus_adminskin_desc'), intval($skinid))); - return intval($adminSkinID); + return self::$aOptions; } - function action_importAdmin() + /** + * Admin::action_importAdmin() + * + * @param void + * @return void + */ + static private function action_importAdmin() { global $DIR_ADMINSKINS, $action; if ( $action == 'adminskinieimport' ) { - $this->_doAdminskinimport(); + self::doAdminskinimport(); } $skn = array(); if ( $action == 'showlogin' ) @@ -5630,64 +5630,69 @@ class Admin $skinName = 'defaultimporter'; $actnName = 'importAdmin'; } - $contents = file_get_contents($DIR_ADMINSKINS . $skinName . '.skn'); - $skn['id'] = 0; - $skn['description'] = $skinName; - $skn['contentType'] = 'importAdmin'; - $skn['includeMode'] = 'normal'; - $skn['includePrefix'] = ''; - $skn['name'] = 'defaultinporter'; - $this->adminSkin = (object)$skn; - $handler = new AdminActions($actnName, $this->adminSkin, $this); - $actions = Skin::getAllowedActionsForType($actnName); - $parser = new PARSER($actions, $handler); - $handler->setParser($parser); - $handler->setSkin($this->adminSkin); + + /* TODO: why??? */ + $contents = file_get_contents($DIR_ADMINSKINS . $skinName . '.skn'); + $skn['id'] = 0; + $skn['description'] = $skinName; + $skn['contentType'] = 'importAdmin'; + $skn['includeMode'] = 'normal'; + $skn['includePrefix'] = ''; + $skn['name'] = 'defaultinporter'; + + self::$skin = (object) $skn; + $handler = new AdminActions($actnName, self::$skin, $this); + + $parser = new PARSER($handler); + $parser->setSkin(self::$skin); $parser->parse($contents); + + return; } /** - * @todo document this + * Admin::doAdminskinimport() + * + * @param void + * @return void */ - private function _doAdminskinimport() + static private function doAdminskinimport() { global $DIR_LIBS, $DIR_ADMINSKINS, $CONF, $member; - $member->isAdmin() or $this->disallow(); - // load skinie class + + $member->isAdmin() or self::disallow(); + include_once($DIR_LIBS . 'Skinie.php'); - $skinFileRaw = postVar('skinfile'); - $mode = postVar('mode'); - $allowOverwrite = intPostVar('overwrite'); - // get full filename - if ($mode == 'file') { + $skinFileRaw = postVar('skinfile'); + $mode = postVar('mode'); + $allowOverwrite = intPostVar('overwrite'); + + if ( $mode == 'file' ) + { $skinFile = $DIR_ADMINSKINS . $skinFileRaw . '/skinbackup.xml'; - } else { + } + else + { $skinFile = $skinFileRaw; } - $importer = new SKINIMPORT(); - $error = $importer->readFile($skinFile); - if ($error) { - $this->error($error); + + $importer = new SKINIMPORT(); + $error = $importer->readFile($skinFile); + if ( $error ) + { + self::error($error); } $error = $importer->writeToDatabase($allowOverwrite); - if ($error) { - $this->error($error); + if ( $error ) + { + self::error($error); } - - $_REQUEST['skininfo'] = $importer->getInfo(); - $_REQUEST['skinnames'] = $importer->getSkinNames(); - $_REQUEST['tpltnames'] = $importer->getTemplateNames(); - + + $_REQUEST['skininfo'] = $importer->getInfo(); + $_REQUEST['skinnames'] = $importer->getSkinNames(); + $_REQUEST['tpltnames'] = $importer->getTemplateNames(); + header('Location: ' . $CONF['AdminURL']); exit; - - } - - /** - * Returns a link to a weblog - * @param object BLOG - */ - function bloglink(&$blog) { - return ''. Entity::hsc( $blog->getName() ) .''; } }