X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=nucleus%2Flibs%2FADMIN.php;h=2bbcc40ad859852772641899e2816e2296776bbe;hb=refs%2Fheads%2Fmaster;hp=ba622d440770ee4ccb28830e1bbd64a844d03cdf;hpb=c7cd1f1ff20256994635e494d71ebe57b32c94ad;p=nucleus-jp%2Fnucleus-next.git diff --git a/nucleus/libs/ADMIN.php b/nucleus/libs/ADMIN.php index ba622d4..2bbcc40 100644 --- a/nucleus/libs/ADMIN.php +++ b/nucleus/libs/ADMIN.php @@ -1,5 +1,5 @@ isLoggedIn() ) + { + $memskin = $member->getAdminSkin(); + if ( $memskin && Skin::existsID($memskin)) + { + $skinid = $memskin; + } + } + + /* 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 + * @return void + */ + static public function action($action) + { + global $CONF, $manager, $member; + + /* 1. decide action name */ + $customAction = postvar('customaction'); + if ( empty($customAction) ) + { + $alias = array( + 'login' => 'overview', + '' => 'overview', + ); + } + else + { + $alias = array( + 'login' => $customAction, + '' => $customAction + ); + } + if ( array_key_exists($action, $alias) && isset($alias[$action]) ) + { + $action = $alias[$action]; + } + $method_name = "action_{$action}"; + self::$action = strtolower($action); + + /* 2. check ticket-needed action */ + if ( !in_array(self::$action, self::$ticketless_actions) && !$manager->checkTicket() ) + { + self::error(_ERROR_BADTICKET); + return; + } + + /* 3. parse according to the action */ + else if ( method_exists('Admin', $method_name) ) + { + call_user_func(array(__CLASS__, $method_name)); + return; + } + /* 4. parse special admin skin */ + elseif ( in_array(self::$action, self::$skinless_actions) ) + { + /* TODO: need to be implemented or not? + self::action_parseSpecialskin(); + */ + } + else + { + self::error(_BADACTION . ENTITY::hsc($action)); + return; + } + + return; + } + + /** + * Action::action_showlogin() + * + * @param void + * @return void + */ + static private function action_showlogin() + { + global $error; + self::action_login($error); + return; + } + + /** + * Action::action_login() + * + * @param string $msg message for pageheader + * @param integer $passvars ??? + */ + static private function action_login($msg = '', $passvars = 1) + { + global $member; + + // skip to overview when allowed + if ( $member->isLoggedIn() && $member->canLogin() ) + { + self::action_overview(); + return; + } + + /* TODO: needless variable??? */ + self::$passvar = $passvars; + if ( $msg ) + { + self::$headMess = $msg; + } + + self::$skin->parse('showlogin'); + } + + /** + * Action::action_overview() + * provides a screen with the overview of the actions available + * + * @param string $msg message for pageheader + * @return void + */ + static private function action_overview($msg = '') + { + if ( $msg ) + { + self::$headMess = $msg; + } + + self::$skin->parse('overview'); + return; + } + + /** + * Admin::action_manage() + * + * @param string $msg message for pageheader + * @retrn void + */ + static private function action_manage($msg = '') + { + global $member; + + if ( $msg ) + { + self::$headMess = $msg; + } + $member->isAdmin() or self::disallow(); + + self::$skin->parse('manage'); + return; + } + + /** + * Action::action_itemlist() + * + * @param integer id for weblod + * @return void + */ + static private function action_itemlist($blogid = '') +>>>>>>> skinnable-master { global $member, $manager, $CONF; @@ -349,6 +695,7 @@ class Admin $blogid = intRequestVar('blogid'); } +<<<<<<< HEAD $member->teamRights($blogid) or $member->isAdmin() or $this->disallow(); $this->pagehead(); @@ -913,10 +1260,7 @@ class Admin if ( $mode == 'category' ) { - if ( $blogs->rowCount() > 1 ) - { - $multipleBlogs = 1; - } + $multipleBlogs = ($blogs->rowCount() > 1); foreach ( $blogs as $row ) { @@ -973,217 +1317,296 @@ class Admin } } echo "\n"; +======= + $member->teamRights($blogid) or $member->isAdmin() or self::disallow(); + + self::$skin->parse('itemlist'); return; } /** - * Admin::action_browseownitems() + * Action::action_batchitem() * * @param void * @return void */ - public function action_browseownitems() + static private function action_batchitem() { - global $member, $manager, $CONF; + global $member, $manager; - $this->pagehead(); + $member->isLoggedIn() or self::disallow(); - echo '

(' . _BACKHOME . ")

\n"; - echo '

' . _ITEMLIST_YOUR . "

\n"; + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); - // start index - if ( postVar('start') ) - { - $start = intPostVar('start'); - } - else + if ( !is_array($selected) || sizeof($selected) == 0 ) { - $start = 0; + self::error(_BATCH_NOSELECTION); + return; } - // amount of items to show - if ( postVar('amount') ) + // On move: when no destination blog/category chosen, show choice now + $destCatid = intRequestVar('destcatid'); + if ( ($action == 'move') && (!$manager->existsCategory($destCatid)) ) { - $amount = intPostVar('amount'); + self::batchMoveSelectDestination('item', $selected); } - else + + // On delete: check if confirmation has been given + if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) { - $amount = (integer) $CONF['DefaultListSize']; - if ( $amount < 1 ) - { - $amount = 10; - } + self::batchAskDeleteConfirmation('item', $selected); } - $search = postVar('search'); // search through items + self::$skin->parse('batchitem'); + return; + } + + /** + * Action::action_batchcomment() + * + * @param void + * @return void + */ + static private function action_batchcomment() + { + global $member; - $query = 'SELECT bshortname, cname, mname, ititle, ibody, idraft, inumber, itime' - . ' FROM '.sql_table('item').', '.sql_table('blog') . ', '.sql_table('member') . ', '.sql_table('category') - . ' WHERE iauthor='. $member->getID() .' and iauthor=mnumber and iblog=bnumber and icat=catid'; + $member->isLoggedIn() or self::disallow(); - if ( $search ) + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); + + // Show error when no items were selected + if ( !is_array($selected) || sizeof($selected) == 0 ) { - $query .= " and ((ititle LIKE " . DB::quoteValue('%'.$search.'%') . ") or (ibody LIKE " . DB::quoteValue('%'.$search.'%') . ") or (imore LIKE " . DB::quoteValue('%'.$search.'%') . "))"; + self::error(_BATCH_NOSELECTION); + return; } - $query .= ' ORDER BY itime DESC' - . " LIMIT $start, $amount"; - - $template['content'] = 'itemlist'; - $template['now'] = time(); - - $manager->loadClass("ENCAPSULATE"); - $navList = new NavList('browseownitems', $start, $amount, 0, 1000, /*$blogid*/ 0, $search, 0); - $navList->showBatchList('item',$query,'table',$template); + // On delete: check if confirmation has been given + if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) + { + self::batchAskDeleteConfirmation('comment', $selected); + } - $this->pagefoot(); + self::$skin->parse('batchcomment'); return; } /** - * Admin::action_itemcommentlist() + * Admin::action_batchmember() * - * Show all the comments for a given item - * @param integer $itemid ID for item + * @param void * @return void */ - public function action_itemcommentlist($itemid = '') + static private function action_batchmember() { - global $member, $manager, $CONF; - - if ( $itemid == '' ) - { - $itemid = intRequestVar('itemid'); - } - - // only allow if user is allowed to alter item - $member->canAlterItem($itemid) or $this->disallow(); + global $member; - $blogid = getBlogIdFromItemId($itemid); + ($member->isLoggedIn() && $member->isAdmin()) or self::disallow(); - $this->pagehead(); + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); - // start index - if ( postVar('start') ) + // Show error when no members selected + if ( !is_array($selected) || sizeof($selected) == 0 ) { - $start = intPostVar('start'); - } - else - { - $start = 0; + self::error(_BATCH_NOSELECTION); + return; } - // amount of items to show - if ( postVar('amount') ) + // On delete: check if confirmation has been given + if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) { - $amount = intPostVar('amount'); - } - else - { - $amount = (integer) $CONF['DefaultListSize']; - if ( $amount < 1 ) - { - $amount = 10; - } + self::batchAskDeleteConfirmation('member',$selected); } - $search = postVar('search'); + self::$skin->parse('batchmember'); + return; + } + + /** + * Admin::action_batchteam() + * + * @param void + * @return void + */ + static private function action_batchteam() + { + global $member; - echo '

(' . _BACKTOOVERVIEW . ")

\n"; - echo '

',_COMMENTS,'

'; + $blogid = intRequestVar('blogid'); - $query = 'SELECT cbody, cuser, cmail, cemail, mname, ctime, chost, cnumber, cip, citem FROM ' . sql_table('comment') . ' LEFT OUTER JOIN ' . sql_table('member') . ' ON mnumber = cmember WHERE citem = ' . $itemid; + ($member->isLoggedIn() && $member->blogAdminRights($blogid)) or self::disallow(); - if ( $search ) + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); + + if ( !is_array($selected) || sizeof($selected) == 0 ) { - $query .= " and cbody LIKE " . DB::quoteValue('%'.$search.'%'); + self::error(_BATCH_NOSELECTION); + return; } - $query .= ' ORDER BY ctime ASC' - . " LIMIT $start,$amount"; - - $template['content'] = 'commentlist'; - $template['canAddBan'] = $member->blogAdminRights(getBlogIDFromItemID($itemid)); - - $manager->loadClass("ENCAPSULATE"); - $navList = new NavList('itemcommentlist', $start, $amount, 0, 1000, 0, $search, $itemid); - $navList->showBatchList('comment',$query,'table',$template,_NOCOMMENTS); + // On delete: check if confirmation has been given + if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) + { + self::batchAskDeleteConfirmation('team',$selected); + } - $this->pagefoot(); + self::$skin->parse('batchteam'); return; } /** - * Admin::action_browseowncomments() - * Browse own comments + * Admin::action_batchcategory() * * @param void * @return void */ - public function action_browseowncomments() + static private function action_batchcategory() { - global $member, $manager, $CONF; + global $member, $manager; - // start index - if ( postVar('start') ) - { - $start = intPostVar('start'); - } - else + $member->isLoggedIn() or self::disallow(); + + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); + + if ( !is_array($selected) || sizeof($selected) == 0 ) { - $start = 0; + self::error(_BATCH_NOSELECTION); + return; } - // amount of items to show - if ( postVar('amount') ) + // On move: when no destination blog chosen, show choice now + $destBlogId = intRequestVar('destblogid'); + if ( ($action == 'move') && (!$manager->existsBlogID($destBlogId)) ) { - $amount = intPostVar('amount'); + self::batchMoveCategorySelectDestination('category', $selected); } - else + + // On delete: check if confirmation has been given + if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) { - $amount = intval($CONF['DefaultListSize']); - if ( $amount < 1 ) - { - $amount = 10; - } + self::batchAskDeleteConfirmation('category', $selected); } - $search = postVar('search'); + self::$skin->parse('batchcategory'); + return; + } + + /** + * Admin::batchMoveSelectDestination() + * + * @param string $type type of batch action + * @param integer $ids needless??? + * @return void + * + * TODO: remove needless argument + */ + static private function batchMoveSelectDestination($type, $ids) + { + $_POST['batchmove'] = $type; + self::$skin->parse('batchmove'); + return; + } + + /** + * Admin::batchMoveCategorySelectDestination() + * + * @param string $type type of batch action + * @param integer $ids needless??? + * @return void + * + * TODO: remove needless argument + */ + static private function batchMoveCategorySelectDestination($type, $ids) + { + $_POST['batchmove'] = $type; + global $manager; + self::$skin->parse('batchmovecat'); + return; + } + + /** + * Admin::batchAskDeleteConfirmation() + * + * @param string $type type of batch action + * @param integer $ids needless??? + * @return void + * + * TODO: remove needless argument + */ + static private function batchAskDeleteConfirmation($type, $ids) + { + self::$skin->parse('batchdelete'); + return; + } + + /** + * Admin::action_browseownitems() + * + * @param void + * @return void + */ + static private function action_browseownitems() + { + global $member, $manager, $CONF; - $query = 'SELECT cbody, cuser, cmail, mname, ctime, chost, cnumber, cip, citem FROM '.sql_table('comment').' LEFT OUTER JOIN '.sql_table('member').' ON mnumber=cmember WHERE cmember=' . $member->getID(); + self::$skin->parse('browseownitems'); + return; + } + + /** + * Admin::action_itemcommentlist() + * Show all the comments for a given item + * + * @param integer $itemid ID for item + * @return void + */ + static private function action_itemcommentlist($itemid = '') + { + global $member, $manager, $CONF; - if ( $search ) + if ( $itemid == '' ) { - $query .= " and cbody LIKE " . DB::quoteValue('%'.$search.'%'); + $itemid = intRequestVar('itemid'); } - $query .= ' ORDER BY ctime DESC' - . " LIMIT $start,$amount"; - - $this->pagehead(); - - echo '

(' . _BACKHOME . ")

\n"; - echo '

' . _COMMENTS_YOUR . "

\n"; - - $template['content'] = 'commentlist'; - $template['canAddBan'] = 0; // doesn't make sense to allow banning yourself + // only allow if user is allowed to alter item + $member->canAlterItem($itemid) or self::disallow(); - $manager->loadClass("ENCAPSULATE"); - $navList = new NavList('browseowncomments', $start, $amount, 0, 1000, 0, $search, 0); - $navList->showBatchList('comment',$query,'table',$template,_NOCOMMENTS_YOUR); + $item =& $manager->getItem($itemid, 1, 1); + $_REQUEST['itemid'] = $item['itemid']; + $_REQUEST['blogid'] = $item['blogid']; - $this->pagefoot(); + self::$skin->parse('itemcommentlist'); return; } /** - * Admin::action_blogcommentlist() + * Admin::action_browseowncomments() + * Browse own comments * + * @param void + * @return void + */ + static private function action_browseowncomments() + { + self::$skin->parse('browseowncomments'); + return; + } + + /** + * Admin::action_blogcommentlist() * Browse all comments for a weblog + * * @param integer $blogid ID for weblog * @return void */ - function action_blogcommentlist($blogid = '') + static private function action_blogcommentlist($blogid = '') { global $member, $manager, $CONF; @@ -1196,345 +1619,2946 @@ class Admin $blogid = intval($blogid); } - $member->teamRights($blogid) or $member->isAdmin() or $this->disallow(); + $member->teamRights($blogid) or $member->isAdmin() or self::disallow(); - // start index - if ( postVar('start') ) - { - $start = intPostVar('start'); - } - else - { - $start = 0; - } + /* TODO: we consider to use the other way insterad of this */ + $_REQUEST['blogid'] = $blogid; - // amount of items to show - if ( postVar('amount') ) + self::$skin->parse('blogcommentlist'); + return; + } + + /** + * Admin::action_createaccount() + * + * @param void + * @return void + */ + static private function action_createaccount() + { + global $CONF; + + if ( $CONF['AllowMemberCreate'] != 1 ) { - $amount = intPostVar('amount'); + self::$skin->parse('createaccountdisable'); + return; } - else + + $name = ''; + $realname =''; + $email = ''; + $url = ''; + + $contents = array( + 'name' => '', + 'realname' => '', + 'email' => '', + 'url' => '' + ); + + if ( array_key_exists('showform', $_POST) && $_POST['showform'] == 1 ) { - $amount = intval($CONF['DefaultListSize']); - if ( $amount < 1 ) + $action = new Action(); + $message = $action->createAccount(); + if ( $message === 1 ) { - $amount = 10; + 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; + } - $search = postVar('search'); // search through comments + self::$skin->parse('createaccountinput'); + return; + } + + /** + * Admin::action_createitem() + * Provide a page to item a new item to the given blog + * + * @param void + * @return void + */ + static private function action_createitem() + { + global $member, $manager; - $query = 'SELECT cbody, cuser, cemail, cmail, mname, ctime, chost, cnumber, cip, citem FROM '.sql_table('comment').' LEFT OUTER JOIN '.sql_table('member').' ON mnumber=cmember WHERE cblog=' . intval($blogid); + $blogid = intRequestVar('blogid'); - if ( $search != '' ) + // check if allowed + $member->teamRights($blogid) or self::disallow(); + + $blog =& $manager->getBlog($blogid); + $contents = array(); + + $data = array( + 'blog' => &$blog, + 'contents' => &$contents + ); + $manager->notify('PreAddItemForm', $data); + + if ( $blog->convertBreaks() ) { - $query .= " and cbody LIKE " . DB::quoteValue('%'.$search.'%'); + 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']); + } } - $query .= ' ORDER BY ctime DESC' - . " LIMIT $start,$amount"; + self::$blog = &$blog; + self::$contents = &$contents; - $blog =& $manager->getBlog($blogid); + self::$skin->parse('createitem'); + return; + } + + /** + * Admin::action_itemedit() + * + * @param void + * @return void + */ + static private function action_itemedit() + { + global $member, $manager; - $this->pagehead(); + $itemid = intRequestVar('itemid'); - echo '

(' . _BACKHOME . ")

\n"; - echo '

', _COMMENTS_BLOG , ' ' , $this->bloglink($blog), '

'; + // only allow if user is allowed to alter item + $member->canAlterItem($itemid) or self::disallow(); - $template['content'] = 'commentlist'; - $template['canAddBan'] = $member->blogAdminRights($blogid); + $item =& $manager->getItem($itemid, 1, 1); + $blog =& $manager->getBlog($item['blogid']); + $data = array('blog'=> &$blog, 'item' => &$item); + $manager->notify('PrepareItemForEdit', $data); - $manager->loadClass("ENCAPSULATE"); - $navList = new NavList('blogcommentlist', $start, $amount, 0, 1000, $blogid, $search, 0); - $navList->showBatchList('comment',$query,'table',$template, _NOCOMMENTS_BLOG); + 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']); + } + } - $this->pagefoot(); + self::$blog = &$blog; + self::$contents = &$item; + + self::$skin->parse('itemedit'); return; } /** - * Admin::action_createitem() - * Provide a page to item a new item to the given blog + * Admin::action_itemupdate() * * @param void * @return void */ - public function action_createitem() + static private function action_itemupdate() { - global $member, $manager; + global $member, $manager, $CONF; - $blogid = intRequestVar('blogid'); + $itemid = intRequestVar('itemid'); + $catid = postVar('catid'); - // check if allowed - $member->teamRights($blogid) or $this->disallow(); + // only allow if user is allowed to alter item + $member->canUpdateItem($itemid, $catid) or self::disallow(); - $memberid = $member->getID(); + $actiontype = postVar('actiontype'); + + // delete actions are handled by itemdelete (which has confirmation) + if ( $actiontype == 'delete' ) + { + self::action_itemdelete(); + return; + } + + $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 ( 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 ) + { + 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 + */ + $blogid = getBlogIDFromItemID($itemid); $blog =& $manager->getBlog($blogid); - // generate the add-item form - $handler = new PageFactory($blog); + $wasdrafts = array('adddraft', 'addfuture', 'addnow'); + $wasdraft = in_array($actiontype, $wasdrafts) ? 1 : 0; + $publish = ($actiontype != 'adddraft' && $actiontype != 'backtodrafts') ? 1 : 0; + if ( $actiontype == 'addfuture' || $actiontype == 'changedate' ) + { + $timestamp = mktime(intPostVar('hour'), intPostVar('minutes'), 0, intPostVar('month'), intPostVar('day'), intPostVar('year')); + } + else + { + $timestamp =0; + } - $contents = $handler->getTemplateFor('admin', 'add'); - $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$blog)); + // edit the item for real + Item::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp); - $parser = new Parser($handler->getDefinedActions(), $handler); + self::updateFuturePosted($blogid); - $this->pagehead(); - $parser->parse($contents); - $this->pagefoot(); + if ( $draftid > 0 ) + { + // delete permission is checked inside Item::delete() + Item::delete($draftid); + } + if ( $catid != intPostVar('catid') ) + { + self::action_categoryedit( + $catid, + $blog->getID(), + $CONF['AdminURL'] . 'index.php?action=itemlist&blogid=' . getBlogIDFromItemID($itemid) + ); + } + else + { + // TODO: set start item correctly for itemlist + $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; + self::action_itemlist(getBlogIDFromItemID($itemid)); + } return; } /** - * Admin::action_itemedit() + * Admin::action_itemdelete() + * Delete item * - * @param void - * @return void + * @param Void + * @return Void */ - public function action_itemedit() + 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(); - - $variables =& $manager->getItem($itemid, 1, 1); - $blog =& $manager->getBlog(getBlogIDFromItemID($itemid)); - - $manager->notify('PrepareItemForEdit', array('item' => &$variables)); + $member->canAlterItem($itemid) or self::disallow(); - if ( $blog->convertBreaks() ) + if ( !$manager->existsItem($itemid,1,1) ) { - $variables['body'] = removeBreaks($variables['body']); - $variables['more'] = removeBreaks($variables['more']); + self::error(_ERROR_NOSUCHITEM); + return; + } + + self::$skin->parse('itemdelete'); + return; + } + + /** + * Admin::action_itemdeleteconfirm() + * + * @param void + * @return void + */ + static private function action_itemdeleteconfirm() + { + global $member, $manager; + + $itemid = intRequestVar('itemid'); + + // only allow if user is allowed to alter item + $member->canAlterItem($itemid) or self::disallow(); + + // get item first + $item =& $manager->getItem($itemid, 1, 1); + + // delete item (note: some checks will be performed twice) + self::deleteOneItem($item['itemid']); + + self::action_itemlist($item['blogid']); + return; + } + + /** + * Admin::deleteOneItem() + * Deletes one item and returns error if something goes wrong + * + * @param integer $itemid ID for item + * @return void + */ + 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 + $item =& $manager->getItem($itemid, 1, 1); + + $manager->loadClass('ITEM'); + Item::delete($item['itemid']); + + // update blog's futureposted + self::updateFuturePosted($item['itemid']); + return; + } + + /** + * Admin::updateFuturePosted() + * Update a blog's future posted flag + * + * @param integer $blogid + * @return void + */ + static private function updateFuturePosted($blogid) + { + global $manager; + + $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 = DB::getResult($query); + + if ( $result->rowCount() > 0 ) + { + $blog->setFuturePost(); + } + else + { + $blog->clearFuturePost(); + } + return; + } + + /** + * Admin::action_itemmove() + * + * @param void + * @return void + */ + static private function action_itemmove() + { + global $member, $manager; + + $itemid = intRequestVar('itemid'); + + $member->canAlterItem($itemid) or self::disallow(); + + self::$skin->parse('itemmove'); + return; + } + + /** + * Admin::action_itemmoveto() + * + * @param void + * @return void + */ + static private function action_itemmoveto() + { + global $member, $manager; + + $itemid = intRequestVar('itemid'); + $catid = requestVar('catid'); + + // create new category if needed + 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 ) + { + self::doError(_ERROR_CATCREATEFAIL); + } + } + + // only allow if user is allowed to alter item + $member->canUpdateItem($itemid, $catid) or self::disallow(); + + $old_blogid = getBlogIDFromItemId($itemid); + + Item::move($itemid, $catid); + + // set the futurePosted flag on the blog + self::updateFuturePosted(getBlogIDFromItemId($itemid)); + + // reset the futurePosted in case the item is moved from one blog to another + self::updateFuturePosted($old_blogid); + + if ( $catid != intRequestVar('catid') ) + { + self::action_categoryedit($catid, $blog->getID()); + } + else + { + 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 integer $itemid ID for item + * @param integer $destCatid ID for category to which the item will be moved + * @return void + */ + 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 + */ + static private function action_additem() + { + global $manager, $CONF; + + $manager->loadClass('ITEM'); + + $result = Item::createFromRequest(); + + if ( $result['status'] == 'error' ) + { + self::error($result['message']); + return; + } + + $item =& $manager->getItem($result['itemid'], 0, 0); + + if ( $result['status'] == 'newcategory' ) + { + $distURI = $manager->addTicketToUrl($CONF['AdminURL'] . 'index.php?action=itemList&blogid=' . $item['blogid']); + self::action_categoryedit($result['catid'], $item['blogid'], $distURI); + } + else + { + $methodName = 'action_itemlist'; + self::action_itemlist($item['blogid']); + } + return; + } + + /** + * Admin::action_commentedit() + * Allows to edit previously made comments + * + * @param void + * @return void + */ + static private function action_commentedit() + { + global $member, $manager; + + $commentid = intRequestVar('commentid'); + + $member->canAlterComment($commentid) or self::disallow(); + + $comment = Comment::getComment($commentid); + $data = array('comment' => &$comment); + $manager->notify('PrepareCommentForEdit', $data); + + self::$contents = $comment; + self::$skin->parse('commentedit'); + return; + } + + /** + * Admin::action_commentupdate() + * + * @param void + * @return void + */ + static private function action_commentupdate() + { + global $member, $manager; + + $commentid = intRequestVar('commentid'); + + $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) + { + self::error(_ERROR_COMMENT_LONGWORD); + return; + } + + // check length + if ( i18n::strlen($body) < 3 ) + { + self::error(_ERROR_COMMENT_NOCOMMENT); + return; + } + + if ( i18n::strlen($body) > 5000 ) + { + self::error(_ERROR_COMMENT_TOOLONG); + return; + } + + // prepare body + $body = Comment::prepareBody($body); + + // call plugins + $data = array( + 'body' => &$body + ); + $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 + $query = "SELECT citem FROM %s WHERE cnumber=%d;"; + $query = sprintf($query, sql_table('comment'), (integer) $commentid); + + $itemid = DB::getValue($query); + + if ( $member->canAlterItem($itemid) ) + { + self::action_itemcommentlist($itemid); + } + else + { + self::action_browseowncomments(); + } + return; + } + + /** + * Admin::action_commentdelete() + * Update comment + * + * @param void + * @return void + */ + static private function action_commentdelete() + { + global $member, $manager; + + $commentid = intRequestVar('commentid'); + $member->canAlterComment($commentid) or self::disallow(); + + self::$skin->parse('commentdelete'); + return; + } + + /** + * Admin::action_commentdeleteconfirm() + * + * @param void + * @return void + */ + static private function action_commentdeleteconfirm() + { + global $member; + + $commentid = intRequestVar('commentid'); + + // get item id first + $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 ) + { + self::doError($error); + } + + if ( $member->canAlterItem($itemid) ) + { + self::action_itemcommentlist($itemid); + } + else + { + self::action_browseowncomments(); + } + return; + } + + /** + * Admin::deleteOneComment() + * + * @param integer $commentid ID for comment + * @return void + */ + static public function deleteOneComment($commentid) + { + global $member, $manager; + + $commentid = (integer) $commentid; + + if ( !$member->canAlterComment($commentid) ) + { + return _ERROR_DISALLOWED; + } + + $data = array( + 'commentid' => $commentid + ); + + $manager->notify('PreDeleteComment', $data); + + // delete the comments associated with the item + $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 + */ + static private function action_usermanagement() + { + global $member, $manager; + + // check if allowed + $member->isAdmin() or self::disallow(); + + self::$skin->parse('usermanagement'); + return; + } + + /** + * Admin::action_memberedit() + * Edit member settings + * + * @param void + * @return void + */ + static private function action_memberedit() + { + self::action_editmembersettings(intRequestVar('memberid')); + return; + } + + /** + * Admin::action_editmembersettings() + * + * @param integer $memberid ID for member + * @return void + * + */ + 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 self::disallow(); + + self::$extrahead .= "\n"; + + self::$skin->parse('editmembersettings'); + return; + } + + /** + * Admin::action_changemembersettings() + * + * @param void + * @return void + */ + static private function action_changemembersettings() + { + global $member, $CONF, $manager; + + $memberid = intRequestVar('memberid'); + + // check if allowed + ($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'); + $bookmarklet = intPostVar('bookmarklet'); + + // 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 =& $manager->getMember($memberid); + + if ( $CONF['AllowLoginEdit'] || $member->isAdmin() ) + { + if ( !isValidDisplayName($name) ) + { + self::error(_ERROR_BADNAME); + return; + } + + if ( ($name != $mem->getDisplayName()) && Member::exists($name) ) + { + self::error(_ERROR_NICKNAMEINUSE); + return; + } + + if ( $password != $repeatpassword ) + { + self::error(_ERROR_PASSWORDMISMATCH); + return; + } + + if ( $password && (i18n::strlen($password) < 6) ) + { + self::error(_ERROR_PASSWORDTOOSHORT); + return; + } + + if ( $password ) + { + $pwdvalid = true; + $pwderror = ''; + + $data = array( + 'password' => $password, + 'errormessage' => &$pwderror, + 'valid' => &$pwdvalid + ); + $manager->notify('PrePasswordSet', $data); + + if ( !$pwdvalid ) + { + self::error($pwderror); + return; + } + } + } + + if ( !NOTIFICATION::address_validation($email) ) + { + self::error(_ERROR_BADMAILADDRESS); + return; + } + if ( !$realname ) + { + self::error(_ERROR_REALNAMEMISSING); + return; + } + if ( ($locale != '') && (!in_array($locale, i18n::get_available_locale_list())) ) + { + self::error(_ERROR_NOSUCHTRANSLATION); + return; + } + + // 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 = DB::getResult('SELECT * FROM '.sql_table('member').' WHERE madmin=1 and mcanlogin=1'); + if ( $r->rowCount() < 2 ) + { + self::error(_ERROR_ATLEASTONEADMIN); + return; + } + } + + if ( $CONF['AllowLoginEdit'] || $member->isAdmin() ) + { + $mem->setDisplayName($name); + if ( $password ) + { + $mem->setPassword($password); + } + } + + $oldEmail = $mem->getEmail(); + + $mem->setRealName($realname); + $mem->setEmail($email); + $mem->setURL($url); + $mem->setNotes($notes); + $mem->setLocale($locale); + $mem->setAdminSkin($adminskin); + $mem->setBookmarklet($bookmarklet); + + // 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); + $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(); + } + self::action_login(_MSG_ACTIVATION_SENT, 0); + return; + } + + if ( ($mem->getID() == $member->getID()) + && ($mem->getDisplayName() != $member->getDisplayName()) ) + { + $mem->newCookieKey(); + $member->logout(); + self::action_login(_MSG_LOGINAGAIN, 0); + } + else + { + self::action_overview(_MSG_SETTINGSCHANGED); + } + return; + } + + /** + * Admin::action_memberadd() + * + * @param void + * @return void + * + */ + static private function action_memberadd() + { + global $member, $manager; + + // check if allowed + $member->isAdmin() or self::disallow(); + + if ( postVar('password') != postVar('repeatpassword') ) + { + self::error(_ERROR_PASSWORDMISMATCH); + return; + } + + if ( i18n::strlen(postVar('password')) < 6 ) + { + self::error(_ERROR_PASSWORDTOOSHORT); + return; + } + + $res = Member::create( + postVar('name'), + postVar('realname'), + postVar('password'), + postVar('email'), + postVar('url'), + postVar('admin'), + postVar('canlogin'), + postVar('notes') + ); + + if ( $res != 1 ) + { + self::error($res); + return; + } + + // fire PostRegister event + $newmem = new Member(); + $newmem->readFromName(postVar('name')); + $data = array( + 'member' => &$newmem + ); + $manager->notify('PostRegister', $data); + + 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 + * + * @param void + * @return void + */ + static private function action_activate() + { + $key = getVar('key'); + self::showActivationPage($key); + return; + } + + /** + * Admin::showActivationPage() + * + * @param void + * @return void + */ + static private function showActivationPage($key, $message = '') + { + global $manager; + + // clean up old activation keys + Member::cleanupActivationTable(); + + // get activation info + $info = Member::getActivationInfo($key); + + if ( !$info ) + { + self::error(_ERROR_ACTIVATE); + return; + } + + $mem =& $manager->getMember($info->vmember); + + if ( !$mem ) + { + self::error(_ERROR_ACTIVATE); + return; + } + + /* 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 + * + * @param void + * @return void + */ + 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 self::showActivationPage($key, _ERROR_ACTIVATE); + } + + $mem =& $manager->getMember($info->vmember); + + if ( !$mem ) + { + return self::showActivationPage($key, _ERROR_ACTIVATE); + } + + $password = postVar('password'); + $repeatpassword = postVar('repeatpassword'); + + if ( $password != $repeatpassword ) + { + return self::showActivationPage($key, _ERROR_PASSWORDMISMATCH); + } + + if ( $password && (i18n::strlen($password) < 6) ) + { + return self::showActivationPage($key, _ERROR_PASSWORDTOOSHORT); + } + + if ( $password ) + { + $pwdvalid = true; + $pwderror = ''; + + $data = array( + 'password' => $password, + 'errormessage' => &$pwderror, + 'valid' => &$pwdvalid + ); + $manager->notify('PrePasswordSet', $data); + if ( !$pwdvalid ) + { + return self::showActivationPage($key,$pwderror); + } + } + + $error = ''; + + $data = array( + 'type' => 'activation', + 'member' => $mem, + 'error' => &$error + ); + $manager->notify('ValidateForm', $data); + if ( $error != '' ) + { + return self::showActivationPage($key, $error); + } + + // set password + $mem->setPassword($password); + $mem->write(); + + // do the activation + Member::activate($key); + + self::$skin->parse('activatesetpwd'); + return; + } + + /** + * Admin::action_manageteam() + * Manage team + * + * @param void + * @return void + */ + static private function action_manageteam() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + + // check if allowed + $member->blogAdminRights($blogid) or self::disallow(); + + self::$skin->parse('manageteam'); + return; + } + + /** + * Admin::action_teamaddmember() + * Add member to team + * + * @param void + * @return void + */ + static private function action_teamaddmember() + { + global $member, $manager; + + $memberid = intPostVar('memberid'); + $blogid = intPostVar('blogid'); + $admin = intPostVar('admin'); + + // check if allowed + $member->blogAdminRights($blogid) or self::disallow(); + + $blog =& $manager->getBlog($blogid); + if ( !$blog->addTeamMember($memberid, $admin) ) + { + self::error(_ERROR_ALREADYONTEAM); + return; + } + + self::action_manageteam(); + return; + } + + /** + * Admin::action_teamdelete() + * + * @param void + * @return void + */ + static private function action_teamdelete() + { + global $member, $manager; + + $memberid = intRequestVar('memberid'); + $blogid = intRequestVar('blogid'); + + // check if allowed + $member->blogAdminRights($blogid) or self::disallow(); + + $teammem =& $manager->getMember($memberid); + $blog =& $manager->getBlog($blogid); + + self::$skin->parse('teamdelete'); + return; + } + + /** + * Admin::action_teamdeleteconfirm() + * + * @param void + * @return void + */ + static private function action_teamdeleteconfirm() + { + global $member; + + $memberid = intRequestVar('memberid'); + $blogid = intRequestVar('blogid'); + + $error = self::deleteOneTeamMember($blogid, $memberid); + if ( $error ) + { + self::error($error); + return; + } + self::action_manageteam(); + return; + } + + /** + * Admin::deleteOneTeamMember() + * + * @param void + * @return void + */ + 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 =& $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 %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 %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 ''; + } + + /** + * Admin::action_teamchangeadmin() + * + * @param void + * @return void + */ + static private function action_teamchangeadmin() + { + global $manager, $member; + + $blogid = intRequestVar('blogid'); + $memberid = intRequestVar('memberid'); + + // check if allowed + $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) ) + { + $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 ) + { + self::error(_ERROR_ATLEASTONEBLOGADMIN); + return; + } + } + + if ( $mem->isBlogAdmin($blogid) ) + { + $newval = 0; + } + else + { + $newval = 1; + } + + $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) ) + { + self::action_manageteam(); + } + else + { + self::action_overview(_MSG_ADMINCHANGED); + } + return; + } + + /** + * Admin::action_blogsettings() + * + * @param void + * @return void + */ + static private function action_blogsettings() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + + // check if allowed + $member->blogAdminRights($blogid) or self::disallow(); + + $blog =& $manager->getBlog($blogid); + + self::$extrahead .= "\n"; + + self::$skin->parse('blogsettings'); + return; + } + + /** + * Admin::action_categorynew() + * + * @param void + * @return void + */ + static private function action_categorynew() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + + $member->blogAdminRights($blogid) or self::disallow(); + + $cname = postVar('cname'); + $cdesc = postVar('cdesc'); + + if ( !isValidCategoryName($cname) ) + { + self::error(_ERROR_BADCATEGORYNAME); + return; + } + + $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 ) + { + self::error(_ERROR_DUPCATEGORYNAME); + return; + } + + $blog =& $manager->getBlog($blogid); + $newCatID = $blog->createNewCategory($cname, $cdesc); + + self::action_blogsettings(); + return; + } + + /** + * Admin::action_categoryedit() + * + * @param void + * @return void + */ + static private function action_categoryedit($catid = '', $blogid = '', $desturl = '') + { + global $member, $manager; + + if ( $blogid == '' ) + { + $blogid = intGetVar('blogid'); + } + else + { + $blogid = intval($blogid); + } + if ( $catid == '' ) + { + $catid = intGetVar('catid'); + } + else + { + $catid = intval($catid); + } + + /* 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(); + + self::$extrahead .= "\n"; + + self::$skin->parse('categoryedit'); + return; + } + + /** + * Admin::action_categoryupdate() + * + * @param void + * @return void + */ + 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 self::disallow(); + + if ( !isValidCategoryName($cname) ) + { + self::error(_ERROR_BADCATEGORYNAME); + return; + } + + $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 ) + { + self::error(_ERROR_DUPCATEGORYNAME); + return; + } + + $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); + $data = array( + 'context' => 'category', + 'catid' => $catid + ); + $manager->notify('PostPluginOptionsUpdate', $data); + + if ( $desturl ) + { + redirect($desturl); + return; + } + + self::action_blogsettings(); + + return; + } + + /** + * Admin::action_categorydelete() + * + * @param void + * @return void + */ + static private function action_categorydelete() + { + global $member, $manager; + + $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) ) + { + self::error(_ERROR_NOSUCHCATEGORY); + return; + } + + // don't allow deletion of default category + if ( $blog->getDefaultCategory() == $catid ) + { + self::error(_ERROR_DELETEDEFCATEGORY); + return; + } + + // check if catid is the only category left for blogid + $query = "SELECT catid FROM %s WHERE cblog=%d;"; + $query = sprintf($query, sql_table('category'), $blogid); + $res = DB::getResult($query); + if ( $res->rowCount() == 1 ) + { + self::error(_ERROR_DELETELASTCATEGORY); + return; + } + + self::$skin->parse('categorydelete'); +>>>>>>> skinnable-master + return; + } + + /** +<<<<<<< HEAD + * Admin::action_browseownitems() +======= + * Admin::action_categorydeleteconfirm() +>>>>>>> skinnable-master + * + * @param void + * @return void + */ +<<<<<<< HEAD + public function action_browseownitems() + { + global $member, $manager, $CONF; + + $this->pagehead(); + + echo '

(' . _BACKHOME . ")

\n"; + echo '

' . _ITEMLIST_YOUR . "

\n"; + + // start index + if ( postVar('start') ) + { + $start = intPostVar('start'); + } + else + { + $start = 0; + } + + // amount of items to show + if ( postVar('amount') ) + { + $amount = intPostVar('amount'); + } + else + { + $amount = (integer) $CONF['DefaultListSize']; + if ( $amount < 1 ) + { + $amount = 10; + } + } + + $search = postVar('search'); // search through items + + $query = 'SELECT bshortname, cname, mname, ititle, ibody, idraft, inumber, itime' + . ' FROM '.sql_table('item').', '.sql_table('blog') . ', '.sql_table('member') . ', '.sql_table('category') + . ' WHERE iauthor='. $member->getID() .' and iauthor=mnumber and iblog=bnumber and icat=catid'; + + if ( $search ) + { + $query .= " and ((ititle LIKE " . DB::quoteValue('%'.$search.'%') . ") or (ibody LIKE " . DB::quoteValue('%'.$search.'%') . ") or (imore LIKE " . DB::quoteValue('%'.$search.'%') . "))"; + } + + $query .= ' ORDER BY itime DESC' + . " LIMIT $start, $amount"; + + $template['content'] = 'itemlist'; + $template['now'] = time(); + + $manager->loadClass("ENCAPSULATE"); + $navList = new NavList('browseownitems', $start, $amount, 0, 1000, /*$blogid*/ 0, $search, 0); + $navList->showBatchList('item',$query,'table',$template); + + $this->pagefoot(); +======= + static private function action_categorydeleteconfirm() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + $catid = intRequestVar('catid'); + + $member->blogAdminRights($blogid) or self::disallow(); + + $error = self::deleteOneCategory($catid); + if ( $error ) + { + self::error($error); + return; + } + + self::action_blogsettings(); + return; + } + + /** + * Admin::deleteOneCategory() + * Delete a category by its id + * + * @param String $catid category id for deleting + * @return Void + */ + 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 %s WHERE cblog=%d;"; + $query = sprintf($query, sql_table('category'), (integer) $blogid); + + $res = DB::getResult($query); + if ( $res->rowCount() == 1 ) + { + return _ERROR_DELETELASTCATEGORY; + } + + $data = array('catid' => $catid); + $manager->notify('PreDeleteCategory', $data); + + // change category for all items to the default category + $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', (integer) $catid); + + // delete category + $query = "DELETE FROM %s WHERE catid=%d;"; + $query = sprintf($query, sql_table('category'), (integer) $catid); + DB::execute($query); + + $data = array('catid' => $catid); + $manager->notify('PostDeleteCategory', $data); +>>>>>>> skinnable-master + return; + } + + /** +<<<<<<< HEAD + * Admin::action_itemcommentlist() + * + * Show all the comments for a given item + * @param integer $itemid ID for item + * @return void + */ + public function action_itemcommentlist($itemid = '') + { + global $member, $manager, $CONF; + + if ( $itemid == '' ) + { + $itemid = intRequestVar('itemid'); + } + + // only allow if user is allowed to alter item + $member->canAlterItem($itemid) or $this->disallow(); + + $blogid = getBlogIdFromItemId($itemid); + + $this->pagehead(); + + // start index + if ( postVar('start') ) + { + $start = intPostVar('start'); + } + else + { + $start = 0; + } + + // amount of items to show + if ( postVar('amount') ) + { + $amount = intPostVar('amount'); + } + else + { + $amount = (integer) $CONF['DefaultListSize']; + if ( $amount < 1 ) + { + $amount = 10; + } + } + + $search = postVar('search'); + + echo '

(' . _BACKTOOVERVIEW . ")

\n"; + echo '

',_COMMENTS,'

'; + + $query = 'SELECT cbody, cuser, cmail, cemail, mname, ctime, chost, cnumber, cip, citem FROM ' . sql_table('comment') . ' LEFT OUTER JOIN ' . sql_table('member') . ' ON mnumber = cmember WHERE citem = ' . $itemid; + + if ( $search ) + { + $query .= " and cbody LIKE " . DB::quoteValue('%'.$search.'%'); + } + + $query .= ' ORDER BY ctime ASC' + . " LIMIT $start,$amount"; + + $template['content'] = 'commentlist'; + $template['canAddBan'] = $member->blogAdminRights(getBlogIDFromItemID($itemid)); + + $manager->loadClass("ENCAPSULATE"); + $navList = new NavList('itemcommentlist', $start, $amount, 0, 1000, 0, $search, $itemid); + $navList->showBatchList('comment',$query,'table',$template,_NOCOMMENTS); + + $this->pagefoot(); +======= + * 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; + } + $data = array( + 'catid' => &$catid, + 'sourceblog' => &$blog, + 'destblog' => &$destblog + ); + $manager->notify('PreMoveCategory', $data); + // 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)); + + $data = array( + 'catid' => &$catid, + 'sourceblog' => &$blog, + 'destblog' => $destblog + ); + $manager->notify('PostMoveCategory', $data); + return; + } + + /** + * Admin::action_blogsettingsupdate + * Updating blog settings + * + * @param Void + * @return Void + */ + static private function action_blogsettingsupdate() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + + $member->blogAdminRights($blogid) or self::disallow(); + + $blog =& $manager->getBlog($blogid); + + $notify_address = trim(postVar('notify')); + $shortname = trim(postVar('shortname')); + $updatefile = trim(postVar('update')); + + $notifyComment = intPostVar('notifyComment'); + $notifyVote = intPostVar('notifyVote'); + $notifyNewItem = intPostVar('notifyNewItem'); + + if ( $notifyComment == 0 ) + { + $notifyComment = 1; + } + if ( $notifyVote == 0 ) + { + $notifyVote = 1; + } + if ( $notifyNewItem == 0 ) + { + $notifyNewItem = 1; + } + $notifyType = $notifyComment * $notifyVote * $notifyNewItem; + + if ( $notify_address && !NOTIFICATION::address_validation($notify_address) ) + { + self::error(_ERROR_BADNOTIFY); + return; + } + + if ( !isValidShortName($shortname) ) + { + self::error(_ERROR_BADSHORTBLOGNAME); + return; + } + + if ( ($blog->getShortName() != $shortname) && $manager->existsBlog($shortname) ) + { + self::error(_ERROR_DUPSHORTBLOGNAME); + return; + } + // check if update file is writable + if ( $updatefile && !is_writeable($updatefile) ) + { + self::error(_ERROR_UPDATEFILE); + return; + } + + $blog->setName(trim(postVar('name'))); + $blog->setShortName($shortname); + $blog->setNotifyAddress($notify_address); + $blog->setNotifyType($notifyType); + $blog->setMaxComments(postVar('maxcomments')); + $blog->setCommentsEnabled(postVar('comments')); + $blog->setTimeOffset(postVar('timeoffset')); + $blog->setUpdateFile($updatefile); + $blog->setURL(trim(postVar('url'))); + $blog->setDefaultSkin(intPostVar('defskin')); + $blog->setDescription(trim(postVar('desc'))); + $blog->setPublic(postVar('public')); + $blog->setConvertBreaks(intPostVar('convertbreaks')); + $blog->setAllowPastPosting(intPostVar('allowpastposting')); + $blog->setDefaultCategory(intPostVar('defcat')); + $blog->setSearchable(intPostVar('searchable')); + $blog->setEmailRequired(intPostVar('reqemail')); + $blog->writeSettings(); + + // store plugin options + $aOptions = requestArray('plugoption'); + NucleusPlugin::apply_plugin_options($aOptions); + + $data = array( + 'context' => 'blog', + 'blogid' => $blogid, + 'blog' => &$blog + ); + $manager->notify('PostPluginOptionsUpdate', $data); + + self::action_overview(_MSG_SETTINGSCHANGED); +>>>>>>> skinnable-master + return; + } + + /** +<<<<<<< HEAD + * Admin::action_browseowncomments() + * Browse own comments +======= + * Admin::action_deleteblog() +>>>>>>> skinnable-master + * + * @param void + * @return void + */ +<<<<<<< HEAD + public function action_browseowncomments() + { + global $member, $manager, $CONF; + + // start index + if ( postVar('start') ) + { + $start = intPostVar('start'); + } + else + { + $start = 0; + } + + // amount of items to show + if ( postVar('amount') ) + { + $amount = intPostVar('amount'); + } + else + { + $amount = intval($CONF['DefaultListSize']); + if ( $amount < 1 ) + { + $amount = 10; + } + } + + $search = postVar('search'); + + $query = 'SELECT cbody, cuser, cmail, mname, ctime, chost, cnumber, cip, citem FROM '.sql_table('comment').' LEFT OUTER JOIN '.sql_table('member').' ON mnumber=cmember WHERE cmember=' . $member->getID(); + + if ( $search ) + { + $query .= " and cbody LIKE " . DB::quoteValue('%'.$search.'%'); + } + + $query .= ' ORDER BY ctime DESC' + . " LIMIT $start,$amount"; + + $this->pagehead(); + + echo '

(' . _BACKHOME . ")

\n"; + echo '

' . _COMMENTS_YOUR . "

\n"; + + $template['content'] = 'commentlist'; + $template['canAddBan'] = 0; // doesn't make sense to allow banning yourself + + $manager->loadClass("ENCAPSULATE"); + $navList = new NavList('browseowncomments', $start, $amount, 0, 1000, 0, $search, 0); + $navList->showBatchList('comment',$query,'table',$template,_NOCOMMENTS_YOUR); + + $this->pagefoot(); +======= + static private function action_deleteblog() + { + global $member, $CONF, $manager; + + $blogid = intRequestVar('blogid'); + + $member->blogAdminRights($blogid) or self::disallow(); + + // check if blog is default blog + if ( $CONF['DefaultBlog'] == $blogid ) + { + self::error(_ERROR_DELDEFBLOG); + return; + } + + $blog =& $manager->getBlog($blogid); + + self::$skin->parse('deleteblog'); + return; + } + + /** + * Admin::action_deleteblogconfirm() + * Delete Blog + * + * @param Void + * @return Void + */ + static private function action_deleteblogconfirm() + { + global $member, $CONF, $manager; + + $blogid = intRequestVar('blogid'); + + $data = array('blogid' => $blogid); + $manager->notify('PreDeleteBlog', $data); + + $member->blogAdminRights($blogid) or self::disallow(); + + // check if blog is default blog + if ( $CONF['DefaultBlog'] == $blogid ) + { + self::error(_ERROR_DELDEFBLOG); + return; + } + + // delete all comments + $query = 'DELETE FROM ' . sql_table('comment') . ' WHERE cblog='.$blogid; + DB::execute($query); + + // delete all items + $query = 'DELETE FROM ' . sql_table('item') . ' WHERE iblog=' . $blogid; + DB::execute($query); + + // delete all team members + $query = 'DELETE FROM ' . sql_table('team') . ' WHERE tblog=' . $blogid; + DB::execute($query); + + // delete all bans + $query = 'DELETE FROM ' . sql_table('ban') . ' WHERE blogid=' . $blogid; + DB::execute($query); + + // delete all categories + $query = 'DELETE FROM ' . sql_table('category') . ' WHERE cblog=' . $blogid; + 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; + DB::execute($query); + + $data = array('blogid' => $blogid); + $manager->notify('PostDeleteBlog', $data); + + self::action_overview(_DELETED_BLOG); +>>>>>>> skinnable-master + return; + } + + /** +<<<<<<< HEAD + * Admin::action_blogcommentlist() + * + * Browse all comments for a weblog + * @param integer $blogid ID for weblog + * @return void + */ + function action_blogcommentlist($blogid = '') + { + global $member, $manager, $CONF; + + if ( $blogid == '' ) + { + $blogid = intRequestVar('blogid'); + } + else + { + $blogid = intval($blogid); + } + + $member->teamRights($blogid) or $member->isAdmin() or $this->disallow(); + + // start index + if ( postVar('start') ) + { + $start = intPostVar('start'); + } + else + { + $start = 0; + } + + // amount of items to show + if ( postVar('amount') ) + { + $amount = intPostVar('amount'); + } + else + { + $amount = intval($CONF['DefaultListSize']); + if ( $amount < 1 ) + { + $amount = 10; + } + } + + $search = postVar('search'); // search through comments + + $query = 'SELECT cbody, cuser, cemail, cmail, mname, ctime, chost, cnumber, cip, citem FROM '.sql_table('comment').' LEFT OUTER JOIN '.sql_table('member').' ON mnumber=cmember WHERE cblog=' . intval($blogid); + + if ( $search != '' ) + { + $query .= " and cbody LIKE " . DB::quoteValue('%'.$search.'%'); + } + + $query .= ' ORDER BY ctime DESC' + . " LIMIT $start,$amount"; + + $blog =& $manager->getBlog($blogid); + + $this->pagehead(); + + echo '

(' . _BACKHOME . ")

\n"; + echo '

', _COMMENTS_BLOG , ' ' , $this->bloglink($blog), '

'; + + $template['content'] = 'commentlist'; + $template['canAddBan'] = $member->blogAdminRights($blogid); + + $manager->loadClass("ENCAPSULATE"); + $navList = new NavList('blogcommentlist', $start, $amount, 0, 1000, $blogid, $search, 0); + $navList->showBatchList('comment',$query,'table',$template, _NOCOMMENTS_BLOG); + + $this->pagefoot(); +======= + * Admin::action_memberdelete() + * + * @param void + * @return void + */ + static private function action_memberdelete() + { + global $member, $manager; + + $memberid = intRequestVar('memberid'); + + ($member->getID() == $memberid) or $member->isAdmin() or self::disallow(); + + $mem =& $manager->getMember($memberid); + + self::$skin->parse('memberdelete'); + return; + } + + /** + * Admin::action_memberdeleteconfirm() + * + * @param void + * @return void + */ + static private function action_memberdeleteconfirm() + { + global $member; + + $memberid = intRequestVar('memberid'); + + ($member->getID() == $memberid) or $member->isAdmin() or self::disallow(); + + $error = self::deleteOneMember($memberid); + if ( $error ) + { + self::error($error); + return; + } + + if ( $member->isAdmin() ) + { + self::action_usermanagement(); + return; + } + else + { + self::action_overview(_DELETED_MEMBER); + return; + } + return; + } + + /** + * Admin::deleteOneMember() + * Delete a member by id + * + * @static + * @params Integer $memberid member id + * @return String null string or error messages + */ + static public function deleteOneMember($memberid) + { + global $manager; + + $memberid = intval($memberid); + $mem =& $manager->getMember($memberid); + + if ( !$mem->canBeDeleted() ) + { + return _ERROR_DELETEMEMBER; + } + + $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'), DB::quoteValue($mem->getDisplayName()), $memberid); + DB::execute($query); + } + + $query = 'DELETE FROM ' . sql_table('member') . ' WHERE mnumber=' . $memberid; + DB::execute($query); + + $query = 'DELETE FROM ' . sql_table('team') . ' WHERE tmember=' . $memberid; + DB::execute($query); + + $query = 'DELETE FROM ' . sql_table('activation') . ' WHERE vmember=' . $memberid; + DB::execute($query); + + // delete all associated plugin options + NucleusPlugin::delete_option_values('member', $memberid); + + $data = array('member' => &$mem); + $manager->notify('PostDeleteMember', $data); + + return ''; + } + + /** + * Admin::action_createnewlog() + * + * @param void + * @return void + */ + static private function action_createnewlog() + { + global $member, $CONF, $manager; + + // Only Super-Admins can do this + $member->isAdmin() or self::disallow(); + + self::$skin->parse('createnewlog'); + return; + } + + /** + * Admin::action_addnewlog() + * + * @param void + * @return void + */ + static private function action_addnewlog() + { + global $member, $manager, $CONF; + + // Only Super-Admins can do this + $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) ) + { + self::error(_ERROR_BADSHORTBLOGNAME); + return; + } + + if ( $manager->existsBlog($bshortname) ) + { + self::error(_ERROR_DUPSHORTBLOGNAME); + return; + } + + $data = array( + 'name' => &$bname, + 'shortname' => &$bshortname, + 'timeoffset' => &$btimeoffset, + 'description' => &$bdesc, + 'defaultskin' => &$bdefskin + ); + $manager->notify('PreAddBlog', $data); + + // add slashes for sql queries + $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 %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') ? '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 + $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, + $member->getID(), + $blog->getCorrectTime(), + 0, + 0, + 0 + ); + + $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; + self::$skin->parse('addnewlog'); +>>>>>>> skinnable-master + return; + } + + /** +<<<<<<< HEAD + * Admin::action_createitem() + * Provide a page to item a new item to the given blog +======= + * Admin::action_addnewlog2() +>>>>>>> skinnable-master + * + * @param void + * @return void + */ +<<<<<<< HEAD + public function action_createitem() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + + // check if allowed + $member->teamRights($blogid) or $this->disallow(); + + $memberid = $member->getID(); + + $blog =& $manager->getBlog($blogid); + + // generate the add-item form + $handler = new PageFactory($blog); + + $contents = $handler->getTemplateFor('admin', 'add'); + $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$blog)); + + $parser = new Parser($handler); + + $this->pagehead(); + $parser->parse($contents); + $this->pagefoot(); + +======= + static private function action_addnewlog2() + { + global $member, $manager; + $blogid = intRequestVar('blogid'); + + $member->blogAdminRights($blogid) or self::disallow(); + + $burl = requestVar('url'); + + $blog =& $manager->getBlog($blogid); + $blog->setURL(trim($burl)); + $blog->writeSettings(); + + self::action_overview(_MSG_NEWBLOG); + return; + } + + /** + * Admin::action_skinieoverview() + * + * @param void + * @return void + */ + static private function action_skinieoverview() + { + global $member, $DIR_LIBS, $manager; + + $member->isAdmin() or self::disallow(); + + include_once($DIR_LIBS . 'skinie.php'); + + self::$skin->parse('skinieoverview'); +>>>>>>> skinnable-master + return; + } + + /** +<<<<<<< HEAD + * Admin::action_itemedit() +======= + * Admin::action_skinieimport() +>>>>>>> skinnable-master + * + * @param void + * @return void + */ +<<<<<<< HEAD + public function action_itemedit() + { + global $member, $manager; + + $itemid = intRequestVar('itemid'); + + // only allow if user is allowed to alter item + $member->canAlterItem($itemid) or $this->disallow(); + + $variables =& $manager->getItem($itemid, 1, 1); + $blog =& $manager->getBlog(getBlogIDFromItemID($itemid)); + + $manager->notify('PrepareItemForEdit', array('item' => &$variables)); + + if ( $blog->convertBreaks() ) + { + $variables['body'] = removeBreaks($variables['body']); + $variables['more'] = removeBreaks($variables['more']); + } + + // form to edit blog items + $handler = new PageFactory($blog); + $handler->setVariables($variables); + + $content = $handler->getTemplateFor('admin', 'edit'); + + $parser = new Parser($handler); + + $this->pagehead(); + $parser->parse($content); + $this->pagefoot(); + return; + } + + /** + * @todo document this + */ + 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(); + + $actiontype = postVar('actiontype'); + + // delete actions are handled by itemdelete (which has confirmation) + if ($actiontype == 'delete') { + $this->action_itemdelete(); + return; + } + + $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 ( 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); + } + + /* + 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); + + $wasdrafts = array('adddraft', 'addfuture', 'addnow'); + $wasdraft = in_array($actiontype, $wasdrafts) ? 1 : 0; + $publish = ($actiontype != 'adddraft' && $actiontype != 'backtodrafts') ? 1 : 0; + if ($actiontype == 'addfuture' || $actiontype == 'changedate') { + $timestamp = mktime(intPostVar('hour'), intPostVar('minutes'), 0, intPostVar('month'), intPostVar('day'), intPostVar('year')); + } else { + $timestamp =0; + } + + // edit the item for real + Item::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp); + + $this->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( + $catid, + $blog->getID(), + $CONF['AdminURL'] . 'index.php?action=itemlist&blogid=' . getBlogIDFromItemID($itemid) + ); + } else { + // TODO: set start item correctly for itemlist + $this->action_itemlist(getBlogIDFromItemID($itemid)); + } + } +======= + static private function action_skinieimport() + { + global $member; + + $member->isAdmin() or self::disallow(); + + $skinFileRaw = postVar('skinfile'); + $mode = postVar('mode'); + + $error = self::skinieimport($mode, $skinFileRaw); + if ( $error ) + { + self::error($error); + return; + } + + self::$skin->parse('skinieimport'); + return; + } + + /** + * Admin::action_skiniedoimport() + * + * @param void + * @return void + */ + static private function action_skiniedoimport() + { + global $member, $DIR_LIBS, $DIR_SKINS; + + $member->isAdmin() or self::disallow(); + + // load skinie class + include_once($DIR_LIBS . 'skinie.php'); + + $mode = postVar('mode'); + $skinFileRaw = postVar('skinfile'); + $allowOverwrite = intPostVar('overwrite'); + + $error = self::skiniedoimport($mode, $skinFileRaw, $allowOverwrite); + if ( $error ) + { + self::error($msg); + return; + } + + self::$skin->parse('skiniedoimport'); + return; + } + + /** + * Admin::action_skinieexport() + * + * @param void + * @return void + */ + static private function action_skinieexport() + { + global $member; + + $member->isAdmin() or self::disallow(); + + $aSkins = requestIntArray('skin'); + $aTemplates = requestIntArray('template'); + $info = postVar('info'); + + self::skinieexport($aSkins, $aTemplates, $info); + + return; + } + + /** + * Admin::action_templateoverview() + * + * @param void + * @return void + */ + static private function action_templateoverview() + { + global $member, $manager; + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('templateoverview'); + return; + } + + /** + * Admin::action_templateedit() + * + * @param string $msg message for pageheader + * @return void + */ + static private function action_templateedit($msg = '') + { + global $member, $manager; + if ( $msg ) + { + self::$headMess = $msg; + } + + $templateid = intRequestVar('templateid'); + + $member->isAdmin() or self::disallow(); + + self::$extrahead .= "\n"; + self::$extrahead .= "\n"; + + self::$skin->parse('templateedit'); + return; + } + + /** + * Admin::action_templateupdate() + * + * @param void + * @return void + */ + static private function action_templateupdate() + { + global $member,$manager; + + $templateid = intRequestVar('templateid'); + + $member->isAdmin() or self::disallow(); + + $name = postVar('tname'); + $desc = postVar('tdesc'); + + if ( !isValidTemplateName($name) ) + { + self::error(_ERROR_BADTEMPLATENAME); + return; + } + + if ( (Template::getNameFromId($templateid) != $name) && Template::exists($name) ) + { + self::error(_ERROR_DUPTEMPLATENAME); + return; + } + + // 1. Remove all template parts + $query = "DELETE FROM %s WHERE tdesc=%d;"; + $query = sprintf($query, sql_table('template'), (integer) $templateid); + DB::execute($query); + + // 2. Update description + $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 + 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, '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 ) + { + self::addToTemplate($templateid, $pffield, postVar($pffield)); + } + } + + // jump back to template edit + self::action_templateedit(_TEMPLATE_UPDATED); + return; + } + + /** + * Admin::addToTemplate() + * + * @param Integer $id ID for template + * @param String $partname parts name + * @param String $content template contents + * @return Integer record index + * + */ + static private function addToTemplate($id, $partname, $content) + { + // don't add empty parts: + if ( !trim($content) ) + { + return -1; + } + + $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(); + } + + /** + * Admin::action_templatedelete() + * + * @param void + * @return void + */ + static private function action_templatedelete() + { + global $member, $manager; - // form to edit blog items - $handler = new PageFactory($blog); - $handler->setVariables($variables); - - $content = $handler->getTemplateFor('admin', 'edit'); + $member->isAdmin() or self::disallow(); - $parser = new Parser($handler->getDefinedActions(), $handler); + $templateid = intRequestVar('templateid'); + // TODO: check if template can be deleted - $this->pagehead(); - $parser->parse($content); - $this->pagefoot(); + self::$skin->parse('templatedelete'); return; } - - /** - * @todo document this - */ - 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(); - - $actiontype = postVar('actiontype'); - - // delete actions are handled by itemdelete (which has confirmation) - if ($actiontype == 'delete') { - $this->action_itemdelete(); - return; - } - - $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 ( 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); - } - - /* - 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); - - $wasdrafts = array('adddraft', 'addfuture', 'addnow'); - $wasdraft = in_array($actiontype, $wasdrafts) ? 1 : 0; - $publish = ($actiontype != 'adddraft' && $actiontype != 'backtodrafts') ? 1 : 0; - if ($actiontype == 'addfuture' || $actiontype == 'changedate') { - $timestamp = mktime(intPostVar('hour'), intPostVar('minutes'), 0, intPostVar('month'), intPostVar('day'), intPostVar('year')); - } else { - $timestamp =0; - } - - // edit the item for real - Item::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp); - - $this->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( - $catid, - $blog->getID(), - $CONF['AdminURL'] . 'index.php?action=itemlist&blogid=' . getBlogIDFromItemID($itemid) - ); - } else { - // TODO: set start item correctly for itemlist - $this->action_itemlist(getBlogIDFromItemID($itemid)); - } - } +>>>>>>> skinnable-master /** - * Admin::action_itemdelete() - * Delete item + * Admin::action_templatedeleteconfirm() * - * @param Void - * @return Void + * @param void + * @return void */ - function action_itemdelete() + static private function action_templatedeleteconfirm() { global $member, $manager; - $itemid = intRequestVar('itemid'); + $templateid = intRequestVar('templateid'); - // only allow if user is allowed to alter item - $member->canAlterItem($itemid) or $this->disallow(); + $member->isAdmin() or self::disallow(); - if ( !$manager->existsItem($itemid,1,1) ) - { - $this->error(_ERROR_NOSUCHITEM); - } + $data = array('templateid' => $templateid); + $manager->notify('PreDeleteTemplate', $data); - $item =& $manager->getItem($itemid,1,1); - $title = Entity::hsc(strip_tags($item['title'])); - $body = strip_tags($item['body']); - $body = Entity::hsc(Entity::shorten($body,300,'...')); + // 1. delete description + DB::execute('DELETE FROM ' . sql_table('template_desc') . ' WHERE tdnumber=' . $templateid); - $this->pagehead(); - echo '

' . _DELETE_CONFIRM . "

\n"; - echo '

' . _CONFIRMTXT_ITEM . "

\n"; - echo "
\n"; - echo "{$title}\n"; - echo "
\n"; - echo "{$body}\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "\n"; - echo $manager->addTicketHidden() . "\n"; - echo "\n"; - echo '\n"; - echo "
\n"; - echo "
\n"; - $this->pagefoot(); + // 2. delete parts + 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 - */ - function action_itemdeleteconfirm() { - global $member; - - $itemid = intRequestVar('itemid'); - - // only allow if user is allowed to alter item - $member->canAlterItem($itemid) or $this->disallow(); - - // get blogid first - $blogid = getBlogIdFromItemId($itemid); - - // delete item (note: some checks will be performed twice) - $this->deleteOneItem($itemid); - - $this->action_itemlist($blogid); - } - - /** - * Deletes one item and returns error if something goes wrong - * @param int $itemid - */ - 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); - - $manager->loadClass('ITEM'); - Item::delete($itemid); - - // update blog's futureposted - $this->updateFuturePosted($blogid); - } - /** - * Admin::updateFuturePosted() - * Update a blog's future posted flag + * Admin::action_templatenew() * - * @param integer $blogid + * @param void * @return void - * */ - function updateFuturePosted($blogid) + static private function action_templatenew() { - global $manager; + global $member; - $blog =& $manager->getBlog($blogid); - $currenttime = $blog->getCorrectTime(time()); + $member->isAdmin() or self::disallow(); - $query = "SELECT * FROM %s WHERE iblog=%d AND iposted=0 AND itime>'%s'"; +<<<<<<< HEAD + $query = "SELECT * FROM %s WHERE iblog=%d AND iposted=0 AND itime>%s"; $query = sprintf($query, sql_table('item'), (integer) $blogid, DB::formatDateTime($currenttime)); $result = DB::getResult($query); if ( $result->rowCount() > 0 ) +======= + $name = postVar('name'); + $desc = postVar('desc'); + + if ( !isValidTemplateName($name) ) +>>>>>>> skinnable-master { - $blog->setFuturePost(); + self::error(_ERROR_BADTEMPLATENAME); + return; } - else + + if ( Template::exists($name) ) { - $blog->clearFuturePost(); + self::error(_ERROR_DUPTEMPLATENAME); + return; } + + $newTemplateId = Template::createNew($name, $desc); + + self::action_templateoverview(); return; } +<<<<<<< HEAD /** * @todo document this @@ -1749,20 +4773,86 @@ class Admin // intercept words that are too long if (preg_match('#[a-zA-Z0-9|\.,;:!\?=\/\\\\]{90,90}#', $body) != FALSE) +======= + + /** + * Admin::action_templateclone() + * + * @param void + * @return void + */ + static private function action_templateclone() + { + global $member; + + $templateid = intRequestVar('templateid'); + + $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) ) +>>>>>>> skinnable-master { - $this->error(_ERROR_COMMENT_LONGWORD); + $i = 1; + while (Template::exists($name . $i)) + { + $i++; + } + $name .= $i; } - - // check length - if (i18n::strlen($body) < 3) + + $newid = Template::createNew($name, $desc); + + // 3. create clone + // go through parts of old template and add them to the new one + $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) { - $this->error(_ERROR_COMMENT_NOCOMMENT); + self::addToTemplate($newid, $row['tpartname'], $row['tcontent']); } - - if (i18n::strlen($body) > 5000) + + self::action_templateoverview(); + return; + } + + /** + * Admin::action_admintemplateoverview() + * + * @param void + * @return void + */ + static private function action_admintemplateoverview() + { + global $member; + $member->isAdmin() or self::disallow(); + self::$skin->parse('admntemplateoverview'); + return; + } + + /** + * Admin::action_admintemplateedit() + * + * @param string $msg message for pageheader + * @return void + */ + static private function action_admintemplateedit($msg = '') + { + global $member, $manager; + if ( $msg ) { - $this->error(_ERROR_COMMENT_TOOLONG); + self::$headMess = $msg; } +<<<<<<< HEAD // prepare body $body = Comment::prepareBody($body); @@ -1785,54 +4875,193 @@ class Admin $this->action_browseowncomments(); } +======= + $member->isAdmin() or self::disallow(); + + self::$extrahead .= "\n"; + self::$extrahead .= '' . "\n"; + + self::$skin->parse('admintemplateedit'); + return; + } +>>>>>>> skinnable-master /** - * Admin::action_commentdelete() - * Update comment + * Admin::action_admintemplateupdate() * - * @param Void - * @return Void + * @param void + * @return void + */ + static private function action_admintemplateupdate() + { + global $member, $manager; + $templateid = intRequestVar('templateid'); + $member->isAdmin() or self::disallow(); + $name = postVar('tname'); + $desc = postVar('tdesc'); + + if ( !isValidTemplateName($name) ) + { + self::error(_ERROR_BADTEMPLATENAME); + return; + } + + if ( (Template::getNameFromId($templateid) != $name) && Template::exists($name) ) + { + self::error(_ERROR_DUPTEMPLATENAME); + return; + } + + // 1. Remove all template parts + $query = "DELETE FROM %s WHERE tdesc=%d;"; + $query = sprintf($query, sql_table('template'), (integer) $templateid); + DB::execute($query); + + // 2. Update description + $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 + self::addToTemplate($templateid, 'NORMALSKINLIST_HEAD', postVar('NORMALSKINLIST_HEAD')); + self::addToTemplate($templateid, 'NORMALSKINLIST_BODY', postVar('NORMALSKINLIST_BODY')); + self::addToTemplate($templateid, 'NORMALSKINLIST_FOOT', postVar('NORMALSKINLIST_FOOT')); + self::addToTemplate($templateid, 'ADMIN_CUSTOMHELPLINK_ICON', postVar('ADMIN_CUSTOMHELPLINK_ICON')); + self::addToTemplate($templateid, 'ADMIN_CUSTOMHELPLINK_ANCHOR', postVar('ADMIN_CUSTOMHELPLINK_ANCHOR')); + self::addToTemplate($templateid, 'ADMIN_BLOGLINK', postVar('ADMIN_BLOGLINK')); + self::addToTemplate($templateid, 'ADMIN_BATCHLIST', postVar('ADMIN_BATCHLIST')); + self::addToTemplate($templateid, 'ACTIVATE_FORGOT_TITLE', postVar('ACTIVATE_FORGOT_TITLE')); + self::addToTemplate($templateid, 'ACTIVATE_FORGOT_TEXT', postVar('ACTIVATE_FORGOT_TEXT')); + self::addToTemplate($templateid, 'ACTIVATE_REGISTER_TITLE', postVar('ACTIVATE_REGISTER_TITLE')); + self::addToTemplate($templateid, 'ACTIVATE_REGISTER_TEXT', postVar('ACTIVATE_REGISTER_TEXT')); + self::addToTemplate($templateid, 'ACTIVATE_CHANGE_TITLE', postVar('ACTIVATE_CHANGE_TITLE')); + self::addToTemplate($templateid, 'ACTIVATE_CHANGE_TEXT', postVar('ACTIVATE_CHANGE_TEXT')); + self::addToTemplate($templateid, 'TEMPLATE_EDIT_EXPLUGNAME', postVar('TEMPLATE_EDIT_EXPLUGNAME')); + self::addToTemplate($templateid, 'TEMPLATE_EDIT_ROW_HEAD', postVar('TEMPLATE_EDIT_ROW_HEAD')); + self::addToTemplate($templateid, 'TEMPLATE_EDIT_ROW_TAIL', postVar('TEMPLATE_EDIT_ROW_TAIL')); + self::addToTemplate($templateid, 'SPECIALSKINLIST_HEAD', postVar('SPECIALSKINLIST_HEAD')); + self::addToTemplate($templateid, 'SPECIALSKINLIST_BODY', postVar('SPECIALSKINLIST_BODY')); + self::addToTemplate($templateid, 'SPECIALSKINLIST_FOOT', postVar('SPECIALSKINLIST_FOOT')); + self::addToTemplate($templateid, 'SYSTEMINFO_GDSETTINGS', postVar('SYSTEMINFO_GDSETTINGS')); + self::addToTemplate($templateid, 'BANLIST_DELETED_LIST', postVar('BANLIST_DELETED_LIST')); + self::addToTemplate($templateid, 'INSERT_PLUGOPTION_TITLE', postVar('INSERT_PLUGOPTION_TITLE')); + self::addToTemplate($templateid, 'INSERT_PLUGOPTION_BODY', postVar('INSERT_PLUGOPTION_BODY')); + self::addToTemplate($templateid, 'INPUTYESNO_TEMPLATE_ADMIN', postVar('INPUTYESNO_TEMPLATE_ADMIN')); + self::addToTemplate($templateid, 'INPUTYESNO_TEMPLATE_NORMAL', postVar('INPUTYESNO_TEMPLATE_NORMAL')); + self::addToTemplate($templateid, 'ADMIN_SPECIALSKINLIST_HEAD', postVar('ADMIN_SPECIALSKINLIST_HEAD')); + self::addToTemplate($templateid, 'ADMIN_SPECIALSKINLIST_BODY', postVar('ADMIN_SPECIALSKINLIST_BODY')); + self::addToTemplate($templateid, 'ADMIN_SPECIALSKINLIST_FOOT', postVar('ADMIN_SPECIALSKINLIST_FOOT')); + self::addToTemplate($templateid, 'SKINIE_EXPORT_LIST', postVar('SKINIE_EXPORT_LIST')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_SELECT_HEAD', postVar('SHOWLIST_LISTPLUG_SELECT_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_SELECT_BODY', postVar('SHOWLIST_LISTPLUG_SELECT_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_SELECT_FOOT', postVar('SHOWLIST_LISTPLUG_SELECT_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM', postVar('SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLIST_BD_SADM', postVar('SHOWLIST_LISTPLUG_TABLE_BLIST_BD_SADM')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SHORTNAM_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_NAVILIST', postVar('SHOWLIST_LISTPLUG_TABLE_NAVILIST')); + self::addToTemplate($templateid, 'PLUGIN_QUICKMENU_TITLE', postVar('PLUGIN_QUICKMENU_TITLE')); + self::addToTemplate($templateid, 'PLUGIN_QUICKMENU_HEAD', postVar('PLUGIN_QUICKMENU_HEAD')); + self::addToTemplate($templateid, 'PLUGIN_QUICKMENU_BODY', postVar('PLUGIN_QUICKMENU_BODY')); + self::addToTemplate($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::addToTemplate($templateid, $pffield, postVar($pffield)); + } + } + + // jump back to template edit + self::action_admintemplateedit(_TEMPLATE_UPDATED); + return; + } + + /** + * Admin::action_admintemplatedelete() + * + * @param void + * @return void */ - function action_commentdelete() + static private function action_admintemplatedelete() { global $member, $manager; + $member->isAdmin() or self::disallow(); - $commentid = intRequestVar('commentid'); - $member->canAlterComment($commentid) or $this->disallow(); - $comment = Comment::getComment($commentid); - - $body = strip_tags($comment['body']); - $body = Entity::hsc(Entity::shorten($body, 300, '...')); - - if ( $comment['member'] ) - { - $author = $comment['member']; - } - else - { - $author = $comment['user']; - } - - $this->pagehead(); - - echo '

' . _DELETE_CONFIRM . "

\n"; - echo '

' . _CONFIRMTXT_COMMENT . "

\n"; - echo "
\n"; - echo '' . _EDITC_WHO . ":{$author}
\n"; - echo '' . _EDITC_TEXT . ":{$body}\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "\n"; - echo $manager->addTicketHidden() . "\n"; - echo "\n"; - echo '\n"; - echo "
\n"; - echo "
\n"; - $this->pagefoot(); + // TODO: check if template can be deleted + self::$skin->parse('admintemplatedelete'); return; } +<<<<<<< HEAD /** * @todo document this */ @@ -1984,23 +5213,30 @@ class Admin $this->action_editmembersettings(intRequestVar('memberid')); } +======= +>>>>>>> skinnable-master /** - * @todo document this + * Admin::action_admintemplatedeleteconfirm() + * + * @param void + * @return void */ - function action_editmembersettings($memberid = '') { - global $member, $manager, $CONF; + static private function action_admintemplatedeleteconfirm() + { + global $member, $manager; - if ($memberid == '') - { - $memberid = $member->getID(); - } + $templateid = intRequestVar('templateid'); + $member->isAdmin() or self::disallow(); - // check if allowed - ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow(); + $data = array('templateid' => $templateid); + $manager->notify('PreDeleteAdminTemplate', $data); - $extrahead = ''; - $this->pagehead($extrahead); + // 1. delete description + $query = "DELETE FROM %s WHERE tdnumber=%s;"; + $query = sprintf($query, sql_table('template_desc'), (integer) $templateid); + DB::execute($query); +<<<<<<< HEAD // show message to go back to member overview (only for admins) if ($member->isAdmin()) { @@ -2012,7 +5248,7 @@ class Admin } echo '

' . _MEMBERS_EDIT . '

'; - $mem = Member::createFromID($memberid); + $mem =& $manager->getMember($memberid); ?>
@@ -2127,32 +5363,36 @@ class Admin ) ); $this->pagefoot(); +======= + // 2. delete parts + $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; +>>>>>>> skinnable-master } - /** - * @todo document this - */ - 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')); - - # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0 - # original eregi: !eregi("^https?://", $url) - - // 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) ) + /** + * Admin::action_admintemplatenew() + * + * @param void + * @return void + */ + static private function action_admintemplatenew() + { + global $member; + $member->isAdmin() or self::disallow(); + $name = postVar('name'); + $desc = postVar('desc'); + + if ( !isValidTemplateName($name) ) { +<<<<<<< HEAD $url = 'http://' . $url; } @@ -2161,7 +5401,7 @@ class Admin $notes = strip_tags(postVar('notes')); $locale = postVar('locale'); - $mem = Member::createFromID($memberid); + $mem =& $manager->getMember($memberid); if ($CONF['AllowLoginEdit'] || $member->isAdmin()) { @@ -2185,16 +5425,22 @@ class Admin $this->error($pwderror); } } +======= + self::error(_ERROR_BADTEMPLATENAME); + return; +>>>>>>> skinnable-master } - - if ( !NOTIFICATION::address_validation($email) ) + else if ( !preg_match('#^admin/#', $name) ) { - $this->error(_ERROR_BADMAILADDRESS); + self::error(_ERROR_BADADMINTEMPLATENAME); + return; } - if ( !$realname ) + else if ( Template::exists($name) ) { - $this->error(_ERROR_REALNAMEMISSING); + self::error(_ERROR_DUPTEMPLATENAME); + return; } +<<<<<<< HEAD if ( ($locale != '') && (!in_array($locale, i18n::get_available_locale_list())) ) $this->error(_ERROR_NOSUCHTRANSLATION); @@ -2266,44 +5512,109 @@ class Admin } } +======= + + $newTemplateId = Template::createNew($name, $desc); + self::action_admintemplateoverview(); + return; + } + +>>>>>>> skinnable-master /** - * Admin::action_memberadd() + * Admin::action_admintemplateclone() * * @param void * @return void - * - */ - function action_memberadd() + */ + static private function action_admintemplateclone() { - global $member, $manager; + global $member; + $templateid = intRequestVar('templateid'); + $member->isAdmin() or self::disallow(); - // check if allowed - $member->isAdmin() or $this->disallow(); + // 1. read old template + $name = Template::getNameFromId($templateid); + $desc = Template::getDesc($templateid); - if ( postVar('password') != postVar('repeatpassword') ) + // 2. create desc thing + $name = $name . "cloned"; + + // if a template with that name already exists: + if ( Template::exists($name) ) { - $this->error(_ERROR_PASSWORDMISMATCH); + $i = 1; + while ( Template::exists($name . $i) ) + { + $i++; + } + $name .= $i; } - if ( i18n::strlen(postVar('password')) < 6 ) + $newid = Template::createNew($name, $desc); + + // 3. create clone + // go through parts of old template and add them to the new one + $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 ) { - $this->error(_ERROR_PASSWORDTOOSHORT); + self::addToTemplate($newid, $row['tpartname'], $row['tcontent']); } - $res = Member::create(postVar('name'), postVar('realname'), postVar('password'), postVar('email'), postVar('url'), postVar('admin'), postVar('canlogin'), postVar('notes')); - if ( $res != 1 ) + self::action_admintemplateoverview(); + return; + } + + /** + * Admin::action_skinoverview() + * + * @param void + * @return void + */ + static private function action_skinoverview() + { + global $member, $manager; + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('skinoverview'); + return; + } + + /** + * Admin::action_skinnew() + * + * @param void + * @return void + */ + static private function action_skinnew() + { + global $member; + + $member->isAdmin() or self::disallow(); + + $name = trim(postVar('name')); + $desc = trim(postVar('desc')); + + if ( !isValidSkinName($name) ) + { + self::error(_ERROR_BADSKINNAME); + return; + } + else if ( SKIN::exists($name) ) { - $this->error($res); + self::error(_ERROR_DUPSKINNAME); + return; } - // fire PostRegister event - $newmem = new Member(); - $newmem->readFromName(postVar('name')); - $manager->notify('PostRegister',array('member' => &$newmem)); + SKIN::createNew($name, $desc); - $this->action_usermanagement(); + self::action_skinoverview(); return; } +<<<<<<< HEAD /** * Account activation @@ -2332,7 +5643,7 @@ class Admin if (!$info) $this->error(_ERROR_ACTIVATE); - $mem = Member::createFromId($info['vmember']); + $mem =& $manager->getMember($info['vmember']); if (!$mem) $this->error(_ERROR_ACTIVATE); @@ -2417,8 +5728,9 @@ class Admin * * @author dekarma */ - function action_activatesetpwd() { - + function action_activatesetpwd() + { + global $manager; $key = postVar('key'); // clean up old activation keys @@ -2430,7 +5742,7 @@ class Admin if (!$info || ($info['type'] == 'addresschange')) return $this->_showActivationPage($key, _ERROR_ACTIVATE); - $mem = Member::createFromId($info['vmember']); + $mem =& $manager->getMember($info['vmember']); if (!$mem) return $this->_showActivationPage($key, _ERROR_ACTIVATE); @@ -2586,7 +5898,7 @@ class Admin // check if allowed $member->blogAdminRights($blogid) or $this->disallow(); - $teammem = Member::createFromID($memberid); + $teammem =& $manager->getMember($memberid); $blog =& $manager->getBlog($blogid); $this->pagehead(); @@ -2640,7 +5952,7 @@ class Admin // check if: - there remains at least one blog admin // - (there remains at least one team member) - $tmem = Member::createFromID($memberid); + $tmem =& $manager->getMember($memberid); $manager->notify('PreDeleteTeamMember', array('member' => &$tmem, 'blogid' => $blogid)); @@ -2665,7 +5977,7 @@ class Admin * @todo document this */ function action_teamchangeadmin() { - global $member; + global $manager, $member; $blogid = intRequestVar('blogid'); $memberid = intRequestVar('memberid'); @@ -2673,7 +5985,7 @@ class Admin // check if allowed $member->blogAdminRights($blogid) or $this->disallow(); - $mem = Member::createFromID($memberid); + $mem =& $manager->getMember($memberid); // don't allow when there is only one admin at this moment if ($mem->isBlogAdmin($blogid)) { @@ -3168,154 +6480,515 @@ class Admin $this->action_blogsettings(); } +======= /** - * Admin::deleteOneCategory() - * Delete a category by its id + * Admin::action_skinedit() + * + * @param void + * @return void + */ + static private function action_skinedit() + { + global $member; + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('skinedit'); + return; + } + + /** + * Admin::action_skineditgeneral() + * + * @param void + * @return void + */ + static private function action_skineditgeneral() + { + global $member; + + $skinid = intRequestVar('skinid'); + + $member->isAdmin() or self::disallow(); + + $error = self::skineditgeneral($skinid); + if ( $error ) + { + self::error($error); + return; + } + + self::action_skinedit(); + return; + } + + static private function action_skinedittype($msg = '') + { + global $member; + + $member->isAdmin() or self::disallow(); + + if ( $msg ) + { + self::$headMess = $msg; + } + + $type = requestVar('type'); + $type = trim($type); + $type = strtolower($type); + + if ( !isValidShortName($type) ) + { + self::error(_ERROR_SKIN_PARTS_SPECIAL_FORMAT); + return; + } + + self::$skin->parse('skinedittype'); + return; + } +>>>>>>> skinnable-master + + /** + * Admin::action_skinupdate() + * + * @param void + * @return void + */ + static private function action_skinupdate() + { + global $manager, $member; + + $skinid = intRequestVar('skinid'); + $content = trim(postVar('content')); + $type = postVar('type'); + + $member->isAdmin() or self::disallow(); + + $skin =& $manager->getSKIN($skinid); + $skin->update($type, $content); + + self::action_skinedittype(_SKIN_UPDATED); + return; + } + + /** + * Admin::action_skindelete() + * + * @param void + * @return void + */ + static private function action_skindelete() + { + global $CONF, $member; + + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); + + // don't allow default skin to be deleted + if ( $skinid == $CONF['BaseSkin'] ) + { + self::error(_ERROR_DEFAULTSKIN); + return; + } + + // don't allow deletion of default skins for blogs + $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)); + return; + } + + self::$skin->parse('skindelete'); + return; + } + + /** + * Admin::action_skindeleteconfirm() + * + * @param void + * @return void + */ + static private function action_skindeleteconfirm() + { + global $member, $CONF; + + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); + + // don't allow default skin to be deleted + if ( $skinid == $CONF['BaseSkin'] ) + { + self::error(_ERROR_DEFAULTSKIN); + return; + } + +<<<<<<< HEAD + // check if catid is the only category left for blogid + $query = 'SELECT catid FROM '.sql_table('category').' WHERE cblog=' . $blogid; + $res = DB::getResult($query); + if ( $res->rowCount() == 1 ) +======= + // don't allow deletion of default skins for blogs + $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)); + return; + } + + self::skindeleteconfirm($skinid); + + self::action_skinoverview(); + return; + } + + /** + * Admin::action_skinremovetype() + * + * @param void + * @return void + */ + static private function action_skinremovetype() + { + global $member, $CONF; + + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); + $skintype = requestVar('type'); + + if ( !isValidShortName($skintype) ) +>>>>>>> skinnable-master + { + self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); + return; + } + + self::$skin->parse('skinremovetype'); + return; + } + + /** + * Admin::action_skinremovetypeconfirm() * - * @param String $catid category id for deleting - * @return Void + * @param void + * @return void */ - function deleteOneCategory($catid) + static private function action_skinremovetypeconfirm() { - global $manager, $member; + global $member; - $catid = intval($catid); - $blogid = getBlogIDFromCatID($catid); +<<<<<<< HEAD + // change category for all items to the default category + $query = 'UPDATE '.sql_table('item')." SET icat=$destcatid WHERE icat=$catid"; + DB::execute($query); +======= + $member->isAdmin() or self::disallow(); +>>>>>>> skinnable-master - if ( !$member->blogAdminRights($blogid) ) + $skinid = intRequestVar('skinid'); + $skintype = requestVar('type'); + +<<<<<<< HEAD + // delete category + $query = 'DELETE FROM '.sql_table('category').' WHERE catid=' .$catid; + DB::execute($query); +======= + $error = self::skinremovetypeconfirm($skinid, $skintype); + if ( $error ) { - return ERROR_DISALLOWED; + self::error($error); + return; } +>>>>>>> skinnable-master - // get blog - $blog =& $manager->getBlog($blogid); + self::action_skinedit(); + return; + } + + /** + * Admin::action_skinclone() + * + * @param void + * @return void + */ + static private function action_skinclone() + { + global $member; - // check if the category is valid - if ( !$blog || !$blog->isValidCategory($catid) ) - { - return _ERROR_NOSUCHCATEGORY; - } + $member->isAdmin() or self::disallow(); - $destcatid = $blog->getDefaultCategory(); + $skinid = intRequestVar('skinid'); - // don't allow deletion of default category - if ( $blog->getDefaultCategory() == $catid ) + self::skinclone($skinid); + + self::action_skinoverview(); + return; + } + + /** + * Admin::action_adminskinoverview() + * + * @param void + * @return void + */ + static private function action_adminskinoverview() + { + global $member; + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('adminskinoverview'); + return; + } + + /** + * Admin::action_adminskinnew() + * + * @param void + * @return void + */ + static private function action_adminskinnew() + { + global $member; + + $member->isAdmin() or self::disallow(); + + $name = trim(postVar('name')); + $desc = trim(postVar('desc')); + + if ( !isValidSkinName($name) ) { - return _ERROR_DELETEDEFCATEGORY; + self::error(_ERROR_BADSKINNAME); + return; } - - // check if catid is the only category left for blogid - $query = 'SELECT catid FROM '.sql_table('category').' WHERE cblog=' . $blogid; - $res = DB::getResult($query); - if ( $res->rowCount() == 1 ) + else if ( !preg_match('#^admin/#', $name) ) { - return _ERROR_DELETELASTCATEGORY; + self::error(_ERROR_BADADMINSKINNAME); + return; + } + else if ( Skin::exists($name) ) + { + self::error(_ERROR_DUPSKINNAME); + return; } - $manager->notify('PreDeleteCategory', array('catid' => $catid)); + Skin::createNew($name, $desc); - // change category for all items to the default category - $query = 'UPDATE '.sql_table('item')." SET icat=$destcatid WHERE icat=$catid"; - DB::execute($query); + self::action_adminskinoverview(); + return; + } + + /** + * Admin::action_adminskinedit() + * + * @param void + * @return void + */ + static private function action_adminskinedit() + { + global $member; - // delete all associated plugin options - NucleusPlugin::delete_option_values('category', $catid); + $member->isAdmin() or self::disallow(); - // delete category - $query = 'DELETE FROM '.sql_table('category').' WHERE catid=' .$catid; - DB::execute($query); + self::$skin->parse('adminskinedit'); - $manager->notify('PostDeleteCategory', array('catid' => $catid)); return; } /** - * Admin::action_blogsettingsupdate - * Updating blog settings + * Admin::action_adminskineditgeneral() * - * @param Void - * @return Void + * @param void + * @return void */ - function action_blogsettingsupdate() + static private function action_adminskineditgeneral() { - global $member, $manager; + global $member; - $blogid = intRequestVar('blogid'); + $skinid = intRequestVar('skinid'); - $member->blogAdminRights($blogid) or $this->disallow(); + $member->isAdmin() or self::disallow(); - $blog =& $manager->getBlog($blogid); + $error = self::skineditgeneral($skinid, 'AdminActions'); + if ( $error ) + { + self::error($error); + return; + } - $notify_address = trim(postVar('notify')); - $shortname = trim(postVar('shortname')); - $updatefile = trim(postVar('update')); + self::action_adminskinedit(); + return; + } + + /** + * Admin::action_adminskinedittype() + * + * @param string $msg message for pageheader + * @return void + */ + static private function action_adminskinedittype($msg = '') + { + global $member; - $notifyComment = intPostVar('notifyComment'); - $notifyVote = intPostVar('notifyVote'); - $notifyNewItem = intPostVar('notifyNewItem'); + $member->isAdmin() or self::disallow(); - if ( $notifyComment == 0 ) + if ( $msg ) { - $notifyComment = 1; + self::$headMess = $msg; } - if ( $notifyVote == 0 ) + $type = requestVar('type'); + $type = trim($type); + $type = strtolower($type); + + if ( !isValidShortName($type) ) { - $notifyVote = 1; + self::error(_ERROR_SKIN_PARTS_SPECIAL_FORMAT); + return; } - if ( $notifyNewItem == 0 ) + + self::$skin->parse('adminskinedittype'); + return; + } + + /** + * Admin::action_adminskinupdate() + * + * @param void + * @return void + */ + static private function action_adminskinupdate() + { + global $manager, $member; + + $skinid = intRequestVar('skinid'); + $content = trim(postVar('content')); + $type = postVar('type'); + + $member->isAdmin() or self::disallow(); + + $skin =& $manager->getSkin($skinid, 'AdminActions', 'AdminSkin'); + $skin->update($type, $content); + + self::action_adminskinedittype(_SKIN_UPDATED); + return; + } + + /** + * Admin::action_adminskindelete() + * + * @param void + * @return void + */ + static private function action_adminskindelete() + { + global $CONF, $member; + + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); + + // don't allow default skin to be deleted + if ( $skinid == $CONF['AdminSkin'] || $skinid == $CONF['BookmarkletSkin'] ) { - $notifyNewItem = 1; + self::error(_ERROR_DEFAULTSKIN); + return; } - $notifyType = $notifyComment * $notifyVote * $notifyNewItem; - if ( $notify_address && !NOTIFICATION::address_validation($notify_address) ) + /* don't allow if someone use it as a default*/ + $query = 'SELECT * FROM %s WHERE madminskin = %d or mbkmklt = %d;'; + $res = DB::getResult(sprintf($query, sql_table('member'), $skinid, $skinid)); + + $members = array(); + while ( $row = $res->fetch() ) { + $members[] = $row['mrealname']; + } + if ( count($members) ) { - $this->error(_ERROR_BADNOTIFY); + self::error(_ERROR_SKINDEFDELETE . implode(' ' . _AND . ' ', $members)); + return; } - if ( !isValidShortName($shortname) ) + self::$skin->parse('adminskindelete'); + return; + } + + /** + * Admin::action_adminskindeleteconfirm() + * + * @param void + * @return void + */ + static private function action_adminskindeleteconfirm() + { + global $member, $CONF; + + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); + + // don't allow default skin to be deleted + if ( $skinid == $CONF['AdminSkin'] || $skinid == $CONF['BookmarkletSkin'] ) { - $this->error(_ERROR_BADSHORTBLOGNAME); + self::error(_ERROR_DEFAULTSKIN); + return; } - if ( ($blog->getShortName() != $shortname) && $manager->existsBlog($shortname) ) - { - $this->error(_ERROR_DUPSHORTBLOGNAME); + /* don't allow if someone use it as a default*/ + $query = 'SELECT * FROM %s WHERE madminskin = %d or mbkmklt = %d;'; + $res = DB::getResult(sprintf($query, sql_table('member'), $skinid, $skinid)); + + $members = array(); + while ( $row = $res->fetch() ) { + $members[] = $row['mrealname']; } - // check if update file is writable - if ( $updatefile && !is_writeable($updatefile) ) + if ( count($members) ) { - $this->error(_ERROR_UPDATEFILE); + self::error(_ERROR_SKINDEFDELETE . implode(' ' . _AND . ' ', $members)); + return; } - $blog->setName(trim(postVar('name'))); - $blog->setShortName($shortname); - $blog->setNotifyAddress($notify_address); - $blog->setNotifyType($notifyType); - $blog->setMaxComments(postVar('maxcomments')); - $blog->setCommentsEnabled(postVar('comments')); - $blog->setTimeOffset(postVar('timeoffset')); - $blog->setUpdateFile($updatefile); - $blog->setURL(trim(postVar('url'))); - $blog->setDefaultSkin(intPostVar('defskin')); - $blog->setDescription(trim(postVar('desc'))); - $blog->setPublic(postVar('public')); - $blog->setConvertBreaks(intPostVar('convertbreaks')); - $blog->setAllowPastPosting(intPostVar('allowpastposting')); - $blog->setDefaultCategory(intPostVar('defcat')); - $blog->setSearchable(intPostVar('searchable')); - $blog->setEmailRequired(intPostVar('reqemail')); - $blog->writeSettings(); + self::skindeleteconfirm($skinid); - // store plugin options - $aOptions = requestArray('plugoption'); - NucleusPlugin::apply_plugin_options($aOptions); - $manager->notify('PostPluginOptionsUpdate',array('context' => 'blog', 'blogid' => $blogid, 'blog' => &$blog)); + self::action_adminskinoverview(); + return; + } + + /** + * Admin::action_adminskinremovetype() + * + * @param void + * @return void + */ + static private function action_adminskinremovetype() + { + global $member, $CONF; + + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); + $skintype = requestVar('type'); + + if ( !isValidShortName($skintype) ) + { + self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); + return; + } - $this->action_overview(_MSG_SETTINGSCHANGED); + self::$skin->parse('adminskinremovetype'); return; } +<<<<<<< HEAD /** * @todo document this @@ -3353,28 +7026,32 @@ class Admin pagefoot(); } +======= +>>>>>>> skinnable-master /** - * Admin::action_deleteblogconfirm() - * Delete Blog + * Admin::action_adminskinremovetypeconfirm() * - * @param Void - * @return Void + * @param void + * @return void */ - function action_deleteblogconfirm() + static private function action_adminskinremovetypeconfirm() { - global $member, $CONF, $manager; + global $member; - $blogid = intRequestVar('blogid'); - $manager->notify('PreDeleteBlog', array('blogid' => $blogid)); - $member->blogAdminRights($blogid) or $this->disallow(); + $member->isAdmin() or self::disallow(); - // check if blog is default blog - if ( $CONF['DefaultBlog'] == $blogid ) + $skinid = intRequestVar('skinid'); + $skintype = requestVar('type'); + + $error = self::skinremovetypeconfirm($skinid, $skintype); + if ( $error ) { - $this->error(_ERROR_DELDEFBLOG); + self::error($error); + return; } +<<<<<<< HEAD // delete all comments $query = 'DELETE FROM '.sql_table('comment').' WHERE cblog='.$blogid; DB::execute($query); @@ -3387,26 +7064,61 @@ class Admin $query = 'DELETE FROM '.sql_table('team').' WHERE tblog='.$blogid; DB::execute($query); - // delete all bans - $query = 'DELETE FROM '.sql_table('ban').' WHERE blogid='.$blogid; - DB::execute($query); + // delete all bans + $query = 'DELETE FROM '.sql_table('ban').' WHERE blogid='.$blogid; + DB::execute($query); + + // delete all categories + $query = 'DELETE FROM '.sql_table('category').' WHERE cblog='.$blogid; + DB::execute($query); +======= + self::action_adminskinedit(); + return; + } + + /** + * Admin::action_adminskinclone() + * + * @param void + * @return void + */ + static private function action_adminskinclone() + { + global $member; + + $member->isAdmin() or self::disallow(); - // delete all categories - $query = 'DELETE FROM '.sql_table('category').' WHERE cblog='.$blogid; - DB::execute($query); + $skinid = intRequestVar('skinid'); +>>>>>>> skinnable-master - // delete all associated plugin options - NucleusPlugin::delete_option_values('blog', $blogid); + self::skinclone($skinid, 'AdminActions'); +<<<<<<< HEAD // delete the blog itself $query = 'DELETE FROM '.sql_table('blog').' WHERE bnumber='.$blogid; DB::execute($query); +======= + self::action_adminskinoverview(); + return; + } + + /** + * Admin::action_adminskinieoverview() + * + * @param void + * @return void + */ + static private function action_adminskinieoverview() + { + global $member; +>>>>>>> skinnable-master - $manager->notify('PostDeleteBlog', array('blogid' => $blogid)); + $member->isAdmin() or self::disallow(); - $this->action_overview(_DELETED_BLOG); + self::$skin->parse('adminskinieoverview'); return; } +<<<<<<< HEAD /** * @todo document this @@ -3418,7 +7130,7 @@ class Admin ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow(); - $mem = Member::createFromID($memberid); + $mem =& $manager->getMember($memberid); $this->pagehead(); ?> @@ -3446,46 +7158,38 @@ class Admin */ function action_memberdeleteconfirm() { global $member; +======= +>>>>>>> skinnable-master - $memberid = intRequestVar('memberid'); - - ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow(); - - $error = $this->deleteOneMember($memberid); - if ($error) - $this->error($error); - - if ($member->isAdmin()) - $this->action_usermanagement(); - else - $this->action_overview(_DELETED_MEMBER); - } - /** - * Admin::deleteOneMember() - * Delete a member by id + * Admin::action_adminskinieimport() * - * @static - * @params Integer $memberid member id - * @return String null string or error messages + * @param void + * @return void */ - function deleteOneMember($memberid) + static private function action_adminskinieimport() { - global $manager; + global $member; +<<<<<<< HEAD $memberid = intval($memberid); - $mem = Member::createFromID($memberid); + $mem =& $manager->getMember($memberid); if ( !$mem->canBeDeleted() ) { return _ERROR_DELETEMEMBER; } +======= + $member->isAdmin() or self::disallow(); +>>>>>>> skinnable-master - $manager->notify('PreDeleteMember', array('member' => &$mem)); + $skinFileRaw = postVar('skinfile'); + $mode = postVar('mode'); - /* unlink comments from memberid */ - if ( $memberid ) + $error = self::skinieimport($mode, $skinFileRaw); + if ( $error ) { +<<<<<<< HEAD $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); @@ -4329,23 +8033,47 @@ selector(); } +======= + self::error($error); + return; + } + + if ( !is_object(self::$skin) ) + { + self::action_adminskiniedoimport(); + } + else + { + self::$skin->parse('adminskinieimport'); + } + return; + } + +>>>>>>> skinnable-master /** - * Admin::addToTemplate() - * - * @param Integer $id ID for template - * @param String $partname parts name - * @param String $content template contents - * @return Integer record index + * Admin::action_adminskiniedoimport() * + * @param void + * @return void */ - function addToTemplate($id, $partname, $content) + static private function action_adminskiniedoimport() { - // don't add empty parts: - if ( !trim($content) ) + global $DIR_SKINS, $member, $CONF; + + $member->isAdmin() or self::disallow(); + + $mode = postVar('mode'); + $skinFileRaw = postVar('skinfile'); + $allowOverwrite = intPostVar('overwrite'); + + $error = self::skiniedoimport($mode, $skinFileRaw, $allowOverwrite); + if ( $error ) { - return -1; + self::error($error); + return; } +<<<<<<< HEAD $partname = DB::quoteValue($partname); $content = DB::quoteValue($content); @@ -5070,17 +8798,41 @@ selector(); $this->action_skinoverview(); } +======= + 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); + if ( $res ) + { + redirect($CONF['AdminURL']); + exit; + } + $skin = new Skin(0, 'AdminActions', 'AdminSkin'); + $skin->parse('importAdmin', $DIR_SKINS . 'admin/defaultimporter.skn'); + } + else + { + self::$skin->parse('adminskiniedoimport'); + } + return; + } +>>>>>>> skinnable-master /** - * Admin::skinclonetype() + * Admin::action_adminskinieexport() * - * @param String $skin Skin object - * @param Integer $newid ID for this clone - * @param String $type type of skin - * @return Void + * @param void + * @return void */ - function skinclonetype($skin, $newid, $type) + static private function action_adminskinieexport() { +<<<<<<< HEAD $newid = intval($newid); $content = $skin->getContentFromDB($type); @@ -5090,6 +8842,19 @@ selector(); $query = sprintf($query, sql_table('skin'), (integer) $newid, $content, $type); DB::execute($query); } +======= + global $member; + + $member->isAdmin() or self::disallow(); + + // load skinie class + $aSkins = requestIntArray('skin'); + $aTemplates = requestIntArray('template'); + $info = postVar('info'); + + self::skinieexport($aSkins, $aTemplates, $info); + +>>>>>>> skinnable-master return; } @@ -5099,8 +8864,10 @@ selector(); * @param Void * @return Void */ - function action_settingsedit() { + static private function action_settingsedit() + { global $member, $manager, $CONF, $DIR_NUCLEUS, $DIR_MEDIA; +<<<<<<< HEAD $member->isAdmin() or $this->disallow(); @@ -5430,6 +9197,13 @@ selector(); ); $this->pagefoot(); +======= + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('settingsedit'); + return; +>>>>>>> skinnable-master } /** @@ -5439,61 +9213,65 @@ selector(); * @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); + return; } // 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')); + self::updateConfig('AdminSkin', postVar('adminskin')); + self::updateConfig('BookmarkletSkin', postVar('bookmarklet')); + // 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 @@ -5501,8 +9279,9 @@ selector(); * @param void * @return void */ - function action_systemoverview() + static private function action_systemoverview() { +<<<<<<< HEAD global $member, $nucleus, $CONF; $this->pagehead(); @@ -5681,8 +9460,12 @@ selector(); echo _ADMIN_SYSTEMOVERVIEW_NOT_ADMIN; } $this->pagefoot(); +======= + self::$skin->parse('systemoverview'); + return; +>>>>>>> skinnable-master } - + /** * Admin::updateConfig() * @@ -5690,8 +9473,9 @@ selector(); * @param string $val * @return integer return the ID in which the latest query posted */ - function updateConfig($name, $val) + static private function updateConfig($name, $val) { +<<<<<<< HEAD $name = DB::quoteValue($name); $val = DB::quoteValue(trim($val)); @@ -5701,24 +9485,30 @@ selector(); { $err = DB::getError(); die("Query error: " . $err[2]); +======= + $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]); +>>>>>>> skinnable-master } 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(); - - echo "

Error!

\n"; - echo $msg; - echo "
\n"; - echo '' . _BACK . "\n"; - $this->pagefoot(); - exit; + self::$headMess = $msg; + self::$skin->parse('adminerrorpage'); + return; } /** @@ -5728,19 +9518,35 @@ selector(); * @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::action_PluginAdmin() + * Output pluginadmin + * + * @param string $skinContents + * @param string $extrahead + * @return void + */ + static public function action_PluginAdmin($skinContents, $extrahead = '') + { + self::$extrahead .= $extrahead; + self::$skin->parse('pluginadmin', $skinContents); + return; } /** - * Admin::pagehead() - * Output admin page head + * Admin::action_bookmarklet() * * @param void * @return void */ +<<<<<<< HEAD function pagehead($extrahead = '') { global $member, $nucleus, $CONF, $manager; @@ -5797,194 +9603,131 @@ selector(); } echo ""._YOURSITE."
\n"; echo '('; +======= + static private function action_bookmarklet() + { + global $member, $manager; +>>>>>>> skinnable-master - if (array_key_exists('codename', $nucleus) && $nucleus['codename'] != '' ) - { - $codenamestring = ' "' . $nucleus['codename'].'"'; - } - else - { - $codenamestring = ''; - } + $blogid = intRequestVar('blogid'); + $member->teamRights($blogid) or self::disallow(); - 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::$skin->parse('bookmarklet'); return; } /** - * Admin::pagefoot() - * Output admin page foot include quickmenu + * Admin::action_actionlog() * * @param void * @return void */ - function pagefoot() + static private function action_actionlog() { - global $action, $member, $manager; + global $member, $manager; - $manager->notify( - 'AdminPrePageFoot', - array('action' => $this->action) - ); + $member->isAdmin() or self::disallow(); - if ( $member->isLoggedIn() && ($action != 'showlogin') ) - { - echo '

' . _LOGOUT . "

\n"; - echo "\n"; - } + self::$skin->parse('actionlog'); + return; + } + + /** + * Admin::action_banlist() + * + * @param void + * @return void + */ + static private function action_banlist() + { + global $member, $manager; - echo "
\n"; - echo 'Nucleus CMS © 2002-' . date('Y') . ' ' . _ADMINPAGEFOOT_COPYRIGHT; - echo '-'; - echo '' . _ADMINPAGEFOOT_DONATE . "\n"; - echo "
\n"; + $blogid = intRequestVar('blogid'); + $member->blogAdminRights($blogid) or self::disallow(); + + self::$skin->parse('banlist'); + return; + } + + /** + * Admin::action_banlistdelete() + * + * @param void + * @return void + */ + static private function action_banlistdelete() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + $member->blogAdminRights($blogid) or self::disallow(); + + self::$skin->parse('banlistdelete'); + return; + } + + /** + * Admin::action_banlistdeleteconfirm() + * + * @param void + * @return void + */ + static private function action_banlistdeleteconfirm() + { + global $member, $manager; + + $blogid = intPostVar('blogid'); + $allblogs = postVar('allblogs'); + $iprange = postVar('iprange'); + + $member->blogAdminRights($blogid) or self::disallow(); - echo "\n"; - echo "
\n"; + $deleted = array(); - if ( ($action != 'showlogin') && ($member->isLoggedIn()) ) + if ( !$allblogs ) { - 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() ) + if ( Ban::removeBan($blogid, $iprange) ) { - echo '

' . _QMENU_MANAGE . "

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

" . _QMENU_LAYOUT . "

\n"; - echo "\n"; + $deleted[] = $blogid; } - - $aPluginExtras = array(); - $manager->notify( - 'QuickMenu', - array( - 'options' => &$aPluginExtras)); - - if ( count($aPluginExtras) > 0 ) + } + else + { + // get blogs fot which member has admin rights + $adminblogs = $member->getAdminBlogs(); + foreach ($adminblogs as $blogje) { - echo "

" . _QMENU_PLUGINS . "

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

' . _QMENU_ACTIVATE . '

' . _QMENU_ACTIVATE_TEXT; - } - else + if ( sizeof($deleted) == 0 ) { - // introduction text on login screen - echo '

' . _QMENU_INTRO . '

' . _QMENU_INTRO_TEXT; + self::error(_ERROR_DELETEBAN); + return; } - echo "\n"; - echo "
\n"; - - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; + /* TODO: we should use other ways */ + $_REQUEST['delblogs'] = $deleted; - echo "\n"; - echo "\n"; + self::$skin->parse('banlistdeleteconfirm'); return; } /** +<<<<<<< HEAD * Admin::action_bookmarklet() +======= + * Admin::action_banlistnewfromitem() +>>>>>>> skinnable-master * * @param void * @return void */ +<<<<<<< HEAD public function action_bookmarklet() { global $member, $manager; @@ -6356,9 +10099,132 @@ selector();

+======= + static private function action_banlistnewfromitem() + { + global $manager; + + $itemid = intRequestVar('itemid'); + $item =& $manager->getItem($itemid, 1, 1); + self::action_banlistnew($item['blogid']); + return; + } + + /** + * Admin::action_banlistnew() + * + * @param integer $blogid ID for weblog + * @return void + */ + static private function action_banlistnew($blogid = '') + { + global $member, $manager; + + if ( $blogid == '' ) + { + $blogid = intRequestVar('blogid'); + } + + $ip = requestVar('ip'); + + $member->blogAdminRights($blogid) or self::disallow(); + + /* TODO: we should consider to use the other way instead of this */ + $_REQUEST['blogid'] = $blogid; + + self::$skin->parse('banlistnew'); + + return; + } +>>>>>>> skinnable-master - pagefoot(); - } + /** + * Admin::action_banlistadd() + * + * @param void + * @return void + */ + static private function action_banlistadd() + { + global $member; + + $blogid = intPostVar('blogid'); + $allblogs = postVar('allblogs'); + $iprange = postVar('iprange'); + + if ( $iprange == "custom" ) + { + $iprange = postVar('customiprange'); + } + $reason = postVar('reason'); + + $member->blogAdminRights($blogid) or self::disallow(); + + // TODO: check IP range validity + + if ( !$allblogs ) + { + if ( !Ban::addBan($blogid, $iprange, $reason) ) + { + self::error(_ERROR_ADDBAN); + return; + } + } + else + { + // get blogs fot which member has admin rights + $adminblogs = $member->getAdminBlogs(); + $failed = 0; + foreach ($adminblogs as $blogje) + { + if ( !Ban::addBan($blogje, $iprange, $reason) ) + { + $failed = 1; + } + } + if ( $failed ) + { + self::error(_ERROR_ADDBAN); + return; + } + } + self::action_banlist(); + return; + } + + /** + * Admin::action_clearactionlog() + * + * @param void + * @return void + */ + static private function action_clearactionlog() + { + global $member; + + $member->isAdmin() or self::disallow(); + + ActionLog::clear(); + + self::action_manage(_MSG_ACTIONLOGCLEARED); + return; + } + + /** + * Admin::action_backupoverview() + * + * @param void + * @return void + */ + static private function action_backupoverview() + { + global $member, $manager; + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('backupoverview'); + return; + } /** * Admin::action_backupcreate() @@ -6368,11 +10234,11 @@ selector(); * @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'); @@ -6384,7 +10250,7 @@ selector(); @set_time_limit(1200); Backup::do_backup($useGzip); - exit; + return; } /** @@ -6394,15 +10260,16 @@ selector(); * @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); + return; } include($DIR_LIBS . 'backup.php'); @@ -6414,11 +10281,10 @@ selector(); $message = Backup::do_restore(); if ( $message != '' ) { - $this->error($message); + self::error($message); + return; } - $this->pagehead(); - echo '

' . _RESTORE_COMPLETE . "

\n"; - $this->pagefoot(); + self::$skin->parse('backuprestore'); return; } @@ -6430,43 +10296,28 @@ selector(); * @return void * */ - function action_pluginlist() + static private function action_pluginlist() { global $DIR_PLUGINS, $member, $manager; // check if allowed - $member->isAdmin() or $this->disallow(); - - $this->pagehead(); - - echo '

(',_BACKTOMANAGE,')

'; - - echo '

' , _PLUGS_TITLE_MANAGE , ' ', help('plugins'), '

'; - - echo '

' , _PLUGS_TITLE_INSTALLED , '   ', helplink('getplugins'), _PLUGS_TITLE_GETPLUGINS, '

'; + $member->isAdmin() or self::disallow(); - $query = 'SELECT * FROM '.sql_table('plugin').' ORDER BY porder ASC'; - - $template['content'] = 'pluginlist'; - $template['tabindex'] = 10; - showlist($query, 'table', $template); - - echo '

' . _PLUGS_TITLE_UPDATE . "

\n"; - echo '

' . _PLUGS_TEXT_UPDATE . "

\n"; - echo '
' . "\n"; - echo "
\n"; - echo '' . "\n"; - $manager->addTicketHidden(); - echo '' . "\n"; - echo "
\n"; - echo "
\n"; - - echo '

' . _PLUGS_TITLE_NEW . "

\n"; - - // find a list of possibly non-installed plugins - $candidates = array(); - $dirhandle = opendir($DIR_PLUGINS); + self::$skin->parse('pluginlist'); + return; + } + + /** + * Admin::action_pluginhelp() + * + * @param void + * @return void + */ + static private function action_pluginhelp() + { + global $member, $manager, $DIR_PLUGINS, $CONF; +<<<<<<< HEAD while ( $filename = readdir($dirhandle) ) { if ( preg_match('#^NP_(.*)\.php$#', $filename, $matches) ) @@ -6484,38 +10335,24 @@ selector(); } } } +======= + // check if allowed + $member->isAdmin() or self::disallow(); +>>>>>>> skinnable-master - closedir($dirhandle); + $plugid = intGetVar('plugid'); - if ( sizeof($candidates) > 0 ) - { - echo '

' . _PLUGS_ADD_TEXT . "

\n"; - - echo '
' . "\n"; - echo "
\n"; - echo '' . "\n"; - $manager->addTicketHidden(); - echo '\n"; - echo '\n"; - echo "
\n"; - echo "
\n"; - } - else + if ( !$manager->pidInstalled($plugid) ) { - echo '

', _PLUGS_NOCANDIDATES, '

'; + self::error(_ERROR_NOSUCHPLUGIN); + return; } - $this->pagefoot(); + self::$skin->parse('pluginhelp'); return; } +<<<<<<< HEAD /** * @todo document this */ @@ -6530,7 +10367,7 @@ selector(); if (!$manager->pidInstalled($plugid)) $this->error(_ERROR_NOSUCHPLUGIN); - $plugName = getPluginNameFromPid($plugid); + $plugName = $manager->getPluginNameFromPid($plugid); $this->pagehead(); @@ -6552,6 +10389,8 @@ selector(); $this->pagefoot(); } +======= +>>>>>>> skinnable-master /** * Admin::action_pluginadd() * @@ -6559,80 +10398,312 @@ selector(); * @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) ) + { + self::error(_ERROR_DUPPLUGIN); + return; + } + + if ( !checkPlugin($name) ) + { + self::error(_ERROR_PLUGFILEERROR . ' (' . Entity::hsc($name) . ')'); + return; + } + + // get number of currently installed plugins +<<<<<<< HEAD + $res = DB::getResult('SELECT * FROM '.sql_table('plugin')); +======= + $res = DB::getResult('SELECT * FROM ' . sql_table('plugin')); +>>>>>>> skinnable-master + $numCurrent = $res->rowCount(); + + // plugin will be added as last one in the list + $newOrder = $numCurrent + 1; + + $data = array('file' => &$name); + $manager->notify('PreAddPlugin', $data); + + // do this before calling getPlugin (in case the plugin id is used there) +<<<<<<< HEAD + $query = 'INSERT INTO '.sql_table('plugin').' (porder, pfile) VALUES ('.$newOrder.','.DB::quoteValue($name).')'; +======= + $query = "INSERT INTO %s (porder, pfile) VALUES (%d, %s);"; + $query = sprintf($query, sql_table('plugin'), (integer) $newOrder, DB::quoteValue($name)); +>>>>>>> skinnable-master + DB::execute($query); + $iPid = DB::getInsertId(); + + $manager->clearCachedInfo('installedPlugins'); + + // Load the plugin for condition checking and instalation + $plugin =& $manager->getPlugin($name); + + // check if it got loaded (could have failed) + if ( !$plugin ) + { +<<<<<<< HEAD + DB::execute('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); + +>>>>>>> skinnable-master + $manager->clearCachedInfo('installedPlugins'); + self::error(_ERROR_PLUGIN_LOAD); + return; + } + + // check if plugin needs a newer Nucleus version + if ( getNucleusVersion() < $plugin->getMinNucleusVersion() ) + { + // uninstall plugin again... + self::deleteOnePlugin($plugin->getID()); + + // ...and show error + self::error(_ERROR_NUCLEUSVERSIONREQ . Entity::hsc($plugin->getMinNucleusVersion())); + return; + } + + // check if plugin needs a newer Nucleus version + if ( (getNucleusVersion() == $plugin->getMinNucleusVersion()) && (getNucleusPatchLevel() < $plugin->getMinNucleusPatchLevel()) ) + { + // uninstall plugin again... + self::deleteOnePlugin($plugin->getID()); + + // ...and show error + self::error(_ERROR_NUCLEUSVERSIONREQ . Entity::hsc( $plugin->getMinNucleusVersion() . ' patch ' . $plugin->getMinNucleusPatchLevel() ) ); + return; + } + + $pluginList = $plugin->getPluginDep(); + foreach ( $pluginList as $pluginName ) + { + $res = DB::getResult('SELECT * FROM '.sql_table('plugin') . ' WHERE pfile=' . DB::quoteValue($pluginName)); + if ($res->rowCount() == 0) + { + // uninstall plugin again... + self::deleteOnePlugin($plugin->getID()); + self::error(sprintf(_ERROR_INSREQPLUGIN, Entity::hsc($pluginName))); + return; + } + } + + // call the install method of the plugin + $plugin->install(); + + $data = array('plugin' => &$plugin); + $manager->notify('PostAddPlugin', $data); + + // update all events + self::action_pluginupdate(); + return; + } + + /** + * ADMIN:action_pluginupdate(): + * + * @param Void + * @return Void + * + */ + static private function action_pluginupdate() + { + global $member, $manager, $CONF; + + // check if allowed + $member->isAdmin() or self::disallow(); + + // delete everything from plugin_events + DB::execute('DELETE FROM '.sql_table('plugin_event')); + + // loop over all installed plugins + $res = DB::getResult('SELECT pid, pfile FROM '.sql_table('plugin')); + foreach ( $res as $row ) + { + $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, DB::quoteValue($eventName)); + DB::execute($query); + } + } + } + redirect($CONF['AdminURL'] . '?action=pluginlist'); + return; + } + + /** + * Admin::action_plugindelete() + * + * @param void + * @return void + */ + static private function action_plugindelete() + { + global $member, $manager; + + // check if allowed + $member->isAdmin() or self::disallow(); + + $pid = intGetVar('plugid'); + + if ( !$manager->pidInstalled($pid) ) + { + self::error(_ERROR_NOSUCHPLUGIN); + return; + } + + self::$skin->parse('plugindelete'); + return; + } + + /** + * Admin::action_plugindeleteconfirm() + * + * @param void + * @return void + */ + static private function action_plugindeleteconfirm() + { + global $member, $manager, $CONF; + + // check if allowed + $member->isAdmin() or self::disallow(); + + $pid = intPostVar('plugid'); + + $error = self::deleteOnePlugin($pid, 1); + if ( $error ) + { + self::error($error); + return; + } + + redirect($CONF['AdminURL'] . '?action=pluginlist'); + return; + } + + /** + * Admin::deleteOnePlugin() + * + * @param integer $pid + * @param boolean $callUninstall + * @return string empty or message if failed + */ + static public function deleteOnePlugin($pid, $callUninstall = 0) + { + global $manager; + + $pid = intval($pid); + + if ( !$manager->pidInstalled($pid) ) + { + return _ERROR_NOSUCHPLUGIN; + } + + $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 = DB::getResult('SELECT pfile FROM ' . sql_table('plugin')); + foreach ( $res as $row ) + { + $plug =& $manager->getPlugin($row['pfile']); + if ( $plug ) + { + $depList = $plug->getPluginDep(); + foreach ( $depList as $depName ) + { + if ( $name == $depName ) + { + return sprintf(_ERROR_DELREQPLUGIN, $row['pfile']); + } + } + } + } + + $data = array('plugid' => $pid); + $manager->notify('PreDeletePlugin', $data); + + // call the unInstall method of the plugin + if ( $callUninstall ) + { + $plugin =& $manager->getPlugin($name); + if ( $plugin ) + { + $plugin->unInstall(); + } + } - $name = postVar('filename'); + // delete all subscriptions + DB::execute('DELETE FROM ' . sql_table('plugin_event') . ' WHERE pid=' . $pid); - if ( $manager->pluginInstalled($name) ) + // delete all options + // get OIDs from plugin_option_desc + $res = DB::getResult('SELECT oid FROM ' . sql_table('plugin_option_desc') . ' WHERE opid=' . $pid); + $aOIDs = array(); + foreach ( $res as $row ) { - $this->error(_ERROR_DUPPLUGIN); + array_push($aOIDs, $row['oid']); } - if ( !checkPlugin($name) ) + // delete from plugin_option and plugin_option_desc + DB::execute('DELETE FROM ' . sql_table('plugin_option_desc') . ' WHERE opid=' . $pid); + if (count($aOIDs) > 0) { - $this->error(_ERROR_PLUGFILEERROR . ' (' . Entity::hsc($name) . ')'); + DB::execute('DELETE FROM ' . sql_table('plugin_option') . ' WHERE oid in (' . implode(',', $aOIDs) . ')'); } - // get number of currently installed plugins - $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 - ) - ); + // update order numbers + $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); - // do this before calling getPlugin (in case the plugin id is used there) - $query = 'INSERT INTO '.sql_table('plugin').' (porder, pfile) VALUES ('.$newOrder.','.DB::quoteValue($name).')'; - DB::execute($query); - $iPid = DB::getInsertId(); + // delete row + DB::execute('DELETE FROM ' . sql_table('plugin') . ' WHERE pid=' . $pid); $manager->clearCachedInfo('installedPlugins'); + $data = array('plugid' => $pid); + $manager->notify('PostDeletePlugin', $data); - // Load the plugin for condition checking and instalation - $plugin =& $manager->getPlugin($name); - - // check if it got loaded (could have failed) - if ( !$plugin ) - { - DB::execute('DELETE FROM ' . sql_table('plugin') . ' WHERE pid='. intval($iPid)); - $manager->clearCachedInfo('installedPlugins'); - $this->error(_ERROR_PLUGIN_LOAD); - } + return ''; + } + + /** + * Admin::action_pluginup() + * + * @param void + * @return void + */ + static private function action_pluginup() + { + global $member, $manager, $CONF; - // check if plugin needs a newer Nucleus version - if ( getNucleusVersion() < $plugin->getMinNucleusVersion() ) - { - // uninstall plugin again... - $this->deleteOnePlugin($plugin->getID()); - - // ...and show error - $this->error(_ERROR_NUCLEUSVERSIONREQ . Entity::hsc($plugin->getMinNucleusVersion())); - } + // check if allowed + $member->isAdmin() or self::disallow(); - // check if plugin needs a newer Nucleus version - if ( (getNucleusVersion() == $plugin->getMinNucleusVersion()) && (getNucleusPatchLevel() < $plugin->getMinNucleusPatchLevel()) ) - { - // uninstall plugin again... - $this->deleteOnePlugin($plugin->getID()); - - // ...and show error - $this->error(_ERROR_NUCLEUSVERSIONREQ . Entity::hsc( $plugin->getMinNucleusVersion() . ' patch ' . $plugin->getMinNucleusPatchLevel() ) ); - } + $plugid = intGetVar('plugid'); - $pluginList = $plugin->getPluginDep(); - foreach ( $pluginList as $pluginName ) + if ( !$manager->pidInstalled($plugid) ) { +<<<<<<< HEAD $res = DB::getResult('SELECT * FROM '.sql_table('plugin') . ' WHERE pfile=' . DB::quoteValue($pluginName)); if ($res->rowCount() == 0) { @@ -6640,35 +10711,40 @@ selector(); $this->deleteOnePlugin($plugin->getID()); $this->error(sprintf(_ERROR_INSREQPLUGIN, Entity::hsc($pluginName))); } +======= + self::error(_ERROR_NOSUCHPLUGIN); + return; +>>>>>>> skinnable-master } - // call the install method of the plugin - $plugin->install(); + // 1. get old order number + $oldOrder = DB::getValue('SELECT porder FROM ' . sql_table('plugin') . ' WHERE pid=' . $plugid); - $manager->notify( - 'PostAddPlugin', - array( - 'plugin' => &$plugin - ) - ); + // 2. calculate new order number + $newOrder = ($oldOrder > 1) ? ($oldOrder - 1) : 1; - // update all events - $this->action_pluginupdate(); + // 3. update plug numbers + 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; } /** - * ADMIN:action_pluginupdate(): - * - * @param Void - * @return Void + * Admin::action_plugindown() * + * @param void + * @return void */ - function action_pluginupdate() + static private function action_plugindown() { global $member, $manager, $CONF; // check if allowed +<<<<<<< HEAD $member->isAdmin() or $this->disallow(); // delete everything from plugin_events @@ -6690,11 +10766,37 @@ selector(); DB::execute($query); } } +======= + $member->isAdmin() or self::disallow(); + + $plugid = intGetVar('plugid'); + if ( !$manager->pidInstalled($plugid) ) + { + self::error(_ERROR_NOSUCHPLUGIN); + return; +>>>>>>> skinnable-master } + + // 1. get old order number + $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 + 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; } +<<<<<<< HEAD /** * @todo document this */ @@ -6713,7 +10815,7 @@ selector(); ?>

-

?

+

getPluginNameFromPid($pid) ?>?

addTicketHidden() ?> @@ -6878,6 +10980,8 @@ selector(); redirect($CONF['AdminURL'] . '?action=pluginlist'); } +======= +>>>>>>> skinnable-master /** * Admin::action_pluginoptions() * @@ -6888,22 +10992,24 @@ selector(); * @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); + return; } - $pname = getPluginNameFromPid($pid); +<<<<<<< HEAD + $pname = $manager->getPluginNameFromPid($pid); - /* just for including translation */ + /* NOTE: to include translation file */ $manager->getPlugin($pname); $extrahead = "\n"; @@ -6922,50 +11028,54 @@ selector(); echo "\n"; $manager->addTicketHidden(); - $aOptions = array(); - $aOIDs = array(); + $options = array(); $query = "SELECT * FROM %s WHERE ocontext='global' and opid=%d ORDER BY oid ASC"; $query = sprintf($query, sql_table('plugin_option_desc'), $pid); $result = DB::getResult($query); foreach ( $result as $row ) { - array_push($aOIDs, $row['oid']); - $aOptions[$row['oid']] = array( - 'oid' => $row['oid'], - 'value' => $row['odef'], - 'name' => $row['oname'], - 'description' => $row['odesc'], - 'type' => $row['otype'], - 'typeinfo' => $row['oextra'], - 'contextid' => 0 + $options[$row['oid']] = array( + 'oid' => $row['oid'], + 'value' => $row['odef'], + 'name' => $row['oname'], + 'description' => $row['odesc'], + 'type' => $row['otype'], + 'typeinfo' => $row['oextra'], + 'contextid' => 0 ); } // fill out actual values - if ( count($aOIDs) > 0 ) + if ( count($options) > 0 ) { $query = "SELECT oid, ovalue FROM %s WHERE oid in (%s)"; - $query = sprintf($query, sql_table('plugin_option'), implode(',',$aOIDs)); + $query = sprintf($query, sql_table('plugin_option'), implode(',',array_keys($options))); $result = DB::getResult($query); foreach ( $result as $row ) { - $aOptions[$row['oid']]['value'] = $row['ovalue']; + $options[$row['oid']]['value'] = $row['ovalue']; } } // call plugins - $data = array('context' => 'global', 'plugid' => $pid, 'options'=>&$aOptions); + $data = array('context' => 'global', 'plugid' => $pid, 'options'=>&$options); $manager->notify('PrePluginOptionsEdit',$data); $template['content'] = 'plugoptionlist'; - $amount = showlist($aOptions,'table',$template); + $amount = showlist($options,'table', $template); if ( $amount == 0 ) { echo '

',_ERROR_NOPLUGOPTIONS,'

'; +======= + if ( isset($message) ) + { + self::$headMess = $message; +>>>>>>> skinnable-master } - echo "
\n"; - echo "
\n"; - $this->pagefoot(); + $plugname = $manager->getPluginNameFromPid($pid); + $plugin = $manager->getPlugin($plugname); + self::$extrahead .= "\n"; + self::$skin->parse('pluginoptions'); return; } @@ -6978,156 +11088,426 @@ selector(); * @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); + return; } $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() + * Admin::skineditgeneral() * - * Output plugin option field + * @param integer $skinid + * @param string $handler + * @return string empty or message if failed + */ + static private function skineditgeneral($skinid, $handler='') + { + global $manager; + + $name = postVar('name'); + $desc = postVar('desc'); + $type = postVar('type'); + $inc_mode = postVar('inc_mode'); + $inc_prefix = postVar('inc_prefix'); + + $skin =& $manager->getSkin($skinid, $handler); + + // 1. Some checks + if ( !isValidSkinName($name) ) + { + return _ERROR_BADSKINNAME; + } + + if ( ($skin->getName() != $name) && SKIN::exists($name) ) + { + return _ERROR_DUPSKINNAME; + } + + if ( !$type ) + { + $type = 'text/html'; + } + + if ( !$inc_mode ) + { + $inc_mode = 'normal'; + } + + // 2. Update description + $skin->updateGeneralInfo($name, $desc, $type, $inc_mode, $inc_prefix); + + return ''; + } + /** + * Admin::skindeleteconfirm() * - * @access public - * @param string $context plugin option context - * @param integer $contextid plugin option context id + * @param integer $skinid * @return void */ - public function _insertPluginOptions($context, $contextid = 0) + static private function skindeleteconfirm($skinid) { - // get all current values for this contextid - // (note: this might contain doubles for overlapping contextids) - $aIdToValue = array(); - $res = DB::getResult('SELECT oid, ovalue FROM ' . sql_table('plugin_option') . ' WHERE ocontextid=' . intval($contextid)); - foreach ( $res as $row ) + global $manager; + + if ( !in_array(self::$action, self::$adminskin_actions) ) { - $aIdToValue[$row['oid']] = $row['ovalue']; + $event_identifier = 'Skin'; } + else + { + $event_identifier = 'AdminSkin'; + } + + $data = array('skinid' => $skinid); + $manager->notify("PreDelete{$event_identifier}", $data); + + // 1. delete description + $query = "DELETE FROM %s WHERE sdnumber=%d;"; + $query = sprintf($query, sql_table('skin_desc'), (integer) $skinid); + DB::execute($query); + + // 2. delete parts + $query = "DELETE FROM %s WHERE sdesc=%d;"; + $query = sprintf($query, sql_table('skin'), (integer) $skinid); + DB::execute($query); + + $manager->notify("PostDelete{$event_identifier}", $data); + + return; + } + + /** + * Admin::skinremovetypeconfirm() + * + * @param integer $skinid + * @param string $skintype + * @return string empty or message if failed + */ + static private function skinremovetypeconfirm($skinid, $skintype) + { + global $manager; + +<<<<<<< HEAD + /* get current registered plugin option list in this context even if it's not used */ + $query = 'SELECT * FROM %s AS plugins, %s AS options LEFT OUTER JOIN %s AS added ' + . 'ON ( options.oid=added.oid ) ' + . 'WHERE plugins.pid=options.opid AND options.ocontext=%s AND added.ocontextid=%d ' + . 'ORDER BY options.oid ASC'; + $query = sprintf($query, sql_table('plugin'), sql_table('plugin_option_desc'), sql_table('plugin_option'), DB::quoteValue($context), intval($contextid)); - // get list of oids per pid - $query = 'SELECT * FROM ' . sql_table('plugin_option_desc') . ',' . sql_table('plugin') - . ' WHERE opid=pid and ocontext='.DB::quoteValue($context).' ORDER BY porder, oid ASC'; $res = DB::getResult($query); - $aOptions = array(); + + $options = array(); foreach ( $res as $row ) { - if (in_array($row['oid'], array_keys($aIdToValue))) - { - $value = $aIdToValue[$row['oid']]; - } - else - { - $value = $row['odef']; - } + /* NOTE: to include translation file */ + $manager->getPlugin($row['pfile']); - array_push($aOptions, array( - 'pid' => $row['pid'], - 'pfile' => $row['pfile'], - 'oid' => $row['oid'], - 'value' => $value, - 'name' => $row['oname'], + $options[] = array( + 'pid' => $row['pid'], + 'pfile' => $row['pfile'], + 'oid' => $row['oid'], + 'value' => ( !$row['ovalue'] ) ? $row['odef'] : $row['ovalue'], + 'name' => $row['oname'], 'description' => $row['odesc'], - 'type' => $row['otype'], - 'typeinfo' => $row['oextra'], - 'contextid' => $contextid, - 'extra' => '')); + 'type' => $row['otype'], + 'typeinfo' => $row['oextra'], + 'contextid' => $contextid, + 'extra' => '' + ); } - global $manager; - $manager->notify('PrePluginOptionsEdit',array('context' => $context, 'contextid' => $contextid, 'options'=>&$aOptions)); + $manager->notify('PrePluginOptionsEdit',array('context' => $context, 'contextid' => $contextid, 'options'=>&$options)); $iPrevPid = -1; - foreach ($aOptions as $aOption) + foreach ( $options as $option) { // new plugin? - if ( $iPrevPid != $aOption['pid'] ) + if ( $iPrevPid != $option['pid'] ) { - $iPrevPid = $aOption['pid']; + $iPrevPid = $option['pid']; if ( !defined('_PLUGIN_OPTIONS_TITLE') ) { define('_PLUGIN_OPTIONS_TITLE', 'Options for %s'); } - echo ''.sprintf(_PLUGIN_OPTIONS_TITLE, Entity::hsc($aOption['pfile'])).''; + echo "\n"; + echo '' . sprintf(_PLUGIN_OPTIONS_TITLE, Entity::hsc($option['pfile'])) . "\n"; + echo "\n"; } - $meta = NucleusPlugin::getOptionMeta($aOption['typeinfo']); + $meta = NucleusPlugin::getOptionMeta($option['typeinfo']); if ( @$meta['access'] != 'hidden' ) { echo ''; - listplug_plugOptionRow($aOption); + listplug_plugOptionRow($option); echo ''; +======= + if ( !in_array(self::$action, self::$adminskin_actions) ) + { + $event_identifier = 'Skin'; + } + else + { + $event_identifier = 'AdminSkin'; + } + + if ( !isValidShortName($skintype) ) + { + return _ERROR_SKIN_PARTS_SPECIAL_DELETE; + } + + $data = array( + 'skinid' => $skinid, + 'skintype' => $skintype + ); + $manager->notify("PreDelete{$event_identifier}Part", $data); + + // delete part + $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 + ); + $manager->notify("PostDelete{$event_identifier}Part", $data); + + return ''; + } + + /** + * Admin::skinclone() + * + * @param integer $skinid + * @param string $handler + * @return void + */ + static private function skinclone($skinid, $handler='') + { + global $manager; + + // 1. read skin to clone + $skin =& $manager->getSkin($skinid, $handler); + $name = "{$skin->getName()}_clone"; + + // if a skin with that name already exists: + if ( Skin::exists($name) ) + { + $i = 1; + while ( Skin::exists($name . $i) ) + { + $i++; + } + $name .= $i; + } + + // 2. create skin desc + $newid = Skin::createNew( + $name, + $skin->getDescription(), + $skin->getContentType(), + $skin->getIncludeMode(), + $skin->getIncludePrefix() + ); + + // 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 ) + { + $content = $skin->getContentFromDB($row['stype']); + 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($row['stype'])); + DB::execute($query); +>>>>>>> skinnable-master } } return; } /** - * Admin::input_yesno() - * Output input elements with radio attribute for yes/no options + * Admin::skinieimport() * - * @param string $name name attribute - * @param string $value_current current value attribute - * @param integer $tabindex tab index - * @param string $value_yes value attribute for yes option - * @param string $value_no value attribute for no option - * @param string $text_yes child text element for yes option - * @param string $text_no child text element for no option - * @param boolean $isAdmin have admin right or not - * @return void + * @param string $mode + * @param string $skinFileRaw + * @return string empty or message if failed + */ + static private function skinieimport($mode, $skinFileRaw) + { + global $DIR_LIBS, $DIR_SKINS; + + // load skinie class + include_once($DIR_LIBS . 'skinie.php'); + + $importer = new SkinImport(); + + // get full filename + if ( $mode == 'file' ) + { + $skinFile = $DIR_SKINS . $skinFileRaw . '/skinbackup.xml'; + } + else + { + $skinFile = $skinFileRaw; + } + + // read only metadata + $error = $importer->readFile($skinFile, 1); + if ( $error ) + { + unset($importer); + return $error; + } + + self::$contents['mode'] = $mode; + self::$contents['skinfile'] = $skinFileRaw; + self::$contents['skininfo'] = $importer->getInfo(); + self::$contents['skinnames'] = $importer->getSkinNames(); + self::$contents['tpltnames'] = $importer->getTemplateNames(); + + // clashes + $skinNameClashes = $importer->checkSkinNameClashes(); + $templateNameClashes = $importer->checkTemplateNameClashes(); + $hasNameClashes = (count($skinNameClashes) > 0) || (count($templateNameClashes) > 0); + + self::$contents['skinclashes'] = $skinNameClashes; + self::$contents['tpltclashes'] = $templateNameClashes; + self::$contents['nameclashes'] = $hasNameClashes ? 1 : 0; + + unset($importer); + return ''; + } + + /** + * Admin::skinieedoimport() + * + * @param string $mode + * @param string $skinFileRaw + * @param boolean $allowOverwrite + * @return string empty or message if failed */ - function input_yesno($name, $value_current, $tabindex = 0, $value_yes = 1, $value_no = 0, $text_yes = _YES, $text_no = _NO, $isAdmin = 0) + static private function skiniedoimport($mode, $skinFileRaw, $allowOverwrite) { - $id = preg_replace('#\[|\]#', '-', $name); - $id_yes = $id . $value_yes; - $id_no = $id . $value_no; + global $DIR_LIBS, $DIR_SKINS; + + // load skinie class + include_once($DIR_LIBS . 'skinie.php'); + + $importer = new SkinImport(); - /* yes option */ - echo 'readFile($skinFile); + if ( $error ) + { + unset($importer); + return $error; + } + + $error = $importer->writeToDatabase($allowOverwrite); + if ( $error ) + { + unset($importer); + return $error; + } + + self::$contents['mode'] = $mode; + self::$contents['skinfile'] = $skinFileRaw; + self::$contents['skininfo'] = $importer->getInfo(); + self::$contents['skinnames'] = $importer->getSkinNames(); + self::$contents['tpltnames'] = $importer->getTemplateNames(); + + unset($importer); + return ''; + } + + /** + * Admin::skinieexport() + * + * @param array $aSkins + * @param array $aTemplates + * @param string $info + * @return void + */ + static private function skinieexport($aSkins, $aTemplates, $info) + { + global $DIR_LIBS; + + // load skinie class + include_once($DIR_LIBS . 'skinie.php'); + + if ( !is_array($aSkins) ) { - echo " tabindex='$tabindex' checked='checked'"; + $aSkins = array(); } - echo " />\n"; - echo '\n"; - /* no option */ - echo 'addSkin($skinId); } - if ($isAdmin && $name=="canlogin") + foreach ( $templateList as $templateId ) { - echo ' disabled="disabled"'; + $exporter->addTemplate($templateId); } - echo " />\n"; - echo '\n"; + $exporter->setInfo($info); + $exporter->export(); return; } + + /** + * Admin::action_parseSpecialskin() + * + * @param void + * @return void + */ + static private function action_parseSpecialskin() + { + self::$skin->parse(self::$action); + return; + } }