From 83b8a886f41c2d4bc7ac3e736891a387bdd0cbea Mon Sep 17 00:00:00 2001 From: sakamocchi Date: Sun, 27 May 2012 09:46:26 +0900 Subject: [PATCH] =?utf8?q?CHANGE:=20getBlogIDFromItemID()=E3=82=92?= =?utf8?q?=E4=BD=BF=E3=82=8F=E3=81=9A=E3=81=ABManager::getItem()=E3=82=92?= =?utf8?q?=E4=BD=BF=E3=81=86=E3=82=88=E3=81=86=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit getBlogIDFromItemID()はSQL文を発行してデータベースへのアクセスを発生させる。これは、例えばアイテムを変更してnucleus_itemテーブルを更新した後には必要な操作かもしれないが、そうでなければ余計なアクセスとなる。この関数を利用している処理の大部分は後者であるため、キャッシュを利用するManager::getItem()を利用して書き換えた。 --- nucleus/libs/ACTION.php | 13 +++---- nucleus/libs/ACTIONS.php | 18 +++++---- nucleus/libs/ADMIN.php | 86 ++++++++++++++++++++--------------------- nucleus/libs/AdminActions.php | 32 ++++++++------- nucleus/libs/BLOG.php | 4 +- nucleus/libs/BODYACTIONS.php | 6 +-- nucleus/libs/COMMENTACTIONS.php | 73 +++++++++++++++++----------------- nucleus/libs/COMMENTS.php | 16 ++++---- nucleus/libs/ITEM.php | 17 ++++---- nucleus/libs/ITEMACTIONS.php | 25 ++++++------ nucleus/libs/MANAGER.php | 4 +- nucleus/libs/MEMBER.php | 7 ++-- 12 files changed, 151 insertions(+), 150 deletions(-) diff --git a/nucleus/libs/ACTION.php b/nucleus/libs/ACTION.php index 5ac9e75..42f6114 100644 --- a/nucleus/libs/ACTION.php +++ b/nucleus/libs/ACTION.php @@ -103,13 +103,12 @@ class Action setcookie($CONF['CookiePrefix'] . 'comment_email', $post['email'], $lifetime, '/', '', 0); } - $comments = new Comments($post['itemid']); - - $blog_id = getBlogIDFromItemID($post['itemid']); - $this->checkban($blog_id); - $blog =& $manager->getBlog($blog_id); + $item =& $manager->getItem($post['itemid'], 0, 0); + $this->checkban($item['blogid']); + $blog =& $manager->getBlog($item['blogid']); // note: PreAddComment and PostAddComment gets called somewhere inside addComment + $comments = new Comments($post['itemid']); $errormessage = $comments->addComment($blog->getCorrectTime(), $post); if ( $errormessage != '1' ) @@ -369,8 +368,8 @@ class Action doError(_ERROR_NOSUCHITEM); } - $blogid = getBlogIDFromItemID($itemid); - $this->checkban($blogid); + $item =& $manager->getItem($itemid, 0, 0); + $this->checkban($item['blogid']); $karma =& $manager->getKarma($itemid); diff --git a/nucleus/libs/ACTIONS.php b/nucleus/libs/ACTIONS.php index 15ea24c..8e86f6f 100644 --- a/nucleus/libs/ACTIONS.php +++ b/nucleus/libs/ACTIONS.php @@ -1424,7 +1424,7 @@ class Actions extends BaseActions public function parse_itemtitle($format = '') { global $manager, $itemid; - $item =& $manager->getItem($itemid,0,0); + $item =& $manager->getItem($itemid, 1, 1); switch ( $format ) { @@ -2206,17 +2206,19 @@ class Actions extends BaseActions * @param string $template name of template * @return void */ - public function parse_sticky($itemnumber = 0, $template = '') + public function parse_sticky($itemid = 0, $template = '') { global $manager; - $itemnumber = intval($itemnumber); - $itemarray = array($itemnumber); + $itemid = (integer) $itemid; + $itemarray = array($itemid); + + $item =& $manager->getItem($post['itemid'], 1, 1); + $blog =& $manager->getBlog($item['blogid']); - $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber)); - $this->preBlogContent('sticky',$b); - $this->amountfound = $b->readLogFromList($itemarray, $template); - $this->postBlogContent('sticky',$b); + $this->preBlogContent('sticky', $blog); + $this->amountfound = $blog->readLogFromList($itemarray, $template); + $this->postBlogContent('sticky', $blog); return; } } diff --git a/nucleus/libs/ADMIN.php b/nucleus/libs/ADMIN.php index 6dbf3b3..1800e68 100644 --- a/nucleus/libs/ADMIN.php +++ b/nucleus/libs/ADMIN.php @@ -666,14 +666,12 @@ class Admin $itemid = intRequestVar('itemid'); } - /* TODO: we consider to use the other way insterad of this */ - $_REQUEST['itemid'] = $itemid; - $_REQUEST['blogid'] = getBlogIdFromItemId($itemid); - // only allow if user is allowed to alter item $member->canAlterItem($itemid) or self::disallow(); - $blogid = getBlogIdFromItemId($itemid); + $item =& $manager->getItem($itemid, 1, 1); + $_REQUEST['itemid'] = $item['itemid']; + $_REQUEST['blogid'] = $item['blogid']; self::$skin->parse('itemcommentlist'); return; @@ -845,26 +843,24 @@ class Admin // only allow if user is allowed to alter item $member->canAlterItem($itemid) or self::disallow(); - $blogid = getBlogIDFromItemID($itemid); - $blog =& $manager->getBlog($blogid); - - $contents =& $manager->getItem($itemid, 1, 1); - $manager->notify('PrepareItemForEdit', array('blog'=> &$blog, 'item' => &$contents)); + $item =& $manager->getItem($itemid, 1, 1); + $blog =& $manager->getBlog($item['blogid']); + $manager->notify('PrepareItemForEdit', array('blog'=> &$blog, 'item' => &$item)); if ( $blog->convertBreaks() ) { - if ( array_key_exists('body', $contents) && !empty($contents['body']) ) + if ( array_key_exists('body', $item) && !empty($item['body']) ) { - $contents['body'] = removeBreaks($contents['body']); + $item['body'] = removeBreaks($item['body']); } - if ( array_key_exists('more', $contents) && !empty($contents['more']) ) + if ( array_key_exists('more', $item) && !empty($item['more']) ) { - $contents['more'] = removeBreaks($contents['more']); + $item['more'] = removeBreaks($item['more']); } } self::$blog = &$blog; - self::$contents = &$contents; + self::$contents = &$item; self::$skin->parse('itemedit'); return; @@ -924,20 +920,20 @@ class Admin } } - /* - set some variables based on actiontype - - actiontypes: - draft items -> addnow, addfuture, adddraft, delete - non-draft items -> edit, changedate, delete - - variables set: - $timestamp: set to a nonzero value for future dates or date changes - $wasdraft: set to 1 when the item used to be a draft item - $publish: set to 1 when the edited item is not a draft - */ + /** + * set some variables based on actiontype + * + * actiontypes: + * draft items -> addnow, addfuture, adddraft, delete + * non-draft items -> edit, changedate, delete + * + * variables set: + * $timestamp: set to a nonzero value for future dates or date changes + * $wasdraft: set to 1 when the item used to be a draft item + * $publish: set to 1 when the edited item is not a draft + */ $blogid = getBlogIDFromItemID($itemid); - $blog =& $manager->getBlog($blogid); + $blog =& $manager->getBlog($blogid); $wasdrafts = array('adddraft', 'addfuture', 'addnow'); $wasdraft = in_array($actiontype, $wasdrafts) ? 1 : 0; @@ -973,7 +969,7 @@ class Admin else { // TODO: set start item correctly for itemlist - $item =& $manager->getitem($itemid, 0, 0); + $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); @@ -1016,20 +1012,20 @@ class Admin */ static private function action_itemdeleteconfirm() { - global $member; + global $member, $manager; $itemid = intRequestVar('itemid'); // only allow if user is allowed to alter item $member->canAlterItem($itemid) or self::disallow(); - // get blogid first - $blogid = getBlogIdFromItemId($itemid); + // get item first + $item =& $manager->getItem($itemid, 1, 1); // delete item (note: some checks will be performed twice) - self::deleteOneItem($itemid); + self::deleteOneItem($item['itemid']); - self::action_itemlist($blogid); + self::action_itemlist($item['blogid']); return; } @@ -1051,13 +1047,13 @@ class Admin } // need to get blogid before the item is deleted - $blogid = getBlogIDFromItemId($itemid); + $item =& $manager->getItem($itemid, 1, 1); $manager->loadClass('ITEM'); - Item::delete($itemid); + Item::delete($item['itemid']); // update blog's futureposted - self::updateFuturePosted($blogid); + self::updateFuturePosted($item['itemid']); return; } @@ -1206,19 +1202,17 @@ class Admin self::error($result['message']); } - $itemid = (integer) $result['itemid']; - - $blogid = (integer) getBlogIDFromItemID($itemid); + $item =& $manager->getItem($result['itemid'], 0, 0); if ( $result['status'] == 'newcategory' ) { - $distURI = $manager->addTicketToUrl($CONF['AdminURL'] . 'index.php?action=itemList&blogid=' . $blogid); - self::action_categoryedit($result['catid'], $blogid, $distURI); + $distURI = $manager->addTicketToUrl($CONF['AdminURL'] . 'index.php?action=itemList&blogid=' . $item['blogid']); + self::action_categoryedit($result['catid'], $item['blogid'], $distURI); } else { $methodName = 'action_itemlist'; - self::action_itemlist($blogid); + self::action_itemlist($item['blogid']); } return; } @@ -4896,7 +4890,11 @@ class Admin */ static private function action_banlistnewfromitem() { - self::action_banlistnew(getBlogIDFromItemID(intRequestVar('itemid'))); + global $manager; + + $itemid = intRequestVar('itemid'); + $item =& $manager->getItem($itemid, 1, 1); + self::action_banlistnew($item['blogid']); return; } diff --git a/nucleus/libs/AdminActions.php b/nucleus/libs/AdminActions.php index 105c6e8..1a0398c 100644 --- a/nucleus/libs/AdminActions.php +++ b/nucleus/libs/AdminActions.php @@ -1620,12 +1620,15 @@ class AdminActions extends BaseActions $itemid = intRequestVar('itemid'); $item =& $manager->getItem($itemid, 1, 1); - $blog =& $manager->getBlog(getBlogIDFromItemID($itemid)); - - if ( $item && $blog->convertBreaks() && requestVar('action') == 'itemedit' ) + if ( $item ) { - $item['body'] = removeBreaks($item['body']); - $item['more'] = removeBreaks($item['more']); + $blog =& $manager->getBlog($item['blogid']); + + if ( $blog->convertBreaks() && requestVar('action') == 'itemedit' ) + { + $item['body'] = removeBreaks($item['body']); + $item['more'] = removeBreaks($item['more']); + } } $contents = array(); @@ -1695,9 +1698,9 @@ class AdminActions extends BaseActions } } $query = 'SELECT cbody, cuser, cmail, cemail, mname, ctime, chost, cnumber, cip, citem ' - . 'FROM %s ' - . 'LEFT OUTER JOIN %s ON mnumber=cmember ' - . 'WHERE '; + . 'FROM %s ' + . 'LEFT OUTER JOIN %s ON mnumber=cmember ' + . 'WHERE '; $query = sprintf($query, sql_table('comment'), sql_table('member')); if ( $this->skintype == 'itemcommentlist' ) @@ -3295,12 +3298,15 @@ class AdminActions extends BaseActions $itemid = intRequestVar('itemid'); $item =& $manager->getItem($itemid, 1, 1); - $blog =& $manager->getBlog(getBlogIDFromItemID($itemid)); - - if ( $item && $blog->convertBreaks() && requestVar('action') == 'itemedit' ) + if ( $item ) { - $item['body'] = removeBreaks($item['body']); - $item['more'] = removeBreaks($item['more']); + $blog =& $manager->getBlog($item['blogid']); + + if ( $blog->convertBreaks() && requestVar('action') == 'itemedit' ) + { + $item['body'] = removeBreaks($item['body']); + $item['more'] = removeBreaks($item['more']); + } } $contents = array(); diff --git a/nucleus/libs/BLOG.php b/nucleus/libs/BLOG.php index f0f91a5..faf5bbe 100644 --- a/nucleus/libs/BLOG.php +++ b/nucleus/libs/BLOG.php @@ -874,9 +874,9 @@ class Blog else { global $itemid; - if ( intval($itemid) && $manager->existsItem(intval($itemid), 0, 0) ) + if ( (integer) $itemid && $manager->existsItem((integer) $itemid, 0, 0) ) { - $iobj =& $manager->getItem(intval($itemid), 0, 0); + $iobj =& $manager->getItem($itemid, 0, 0); $cid = $iobj['catid']; if ( $cid == $data['catid'] ) diff --git a/nucleus/libs/BODYACTIONS.php b/nucleus/libs/BODYACTIONS.php index 83cb68d..7568331 100644 --- a/nucleus/libs/BODYACTIONS.php +++ b/nucleus/libs/BODYACTIONS.php @@ -280,7 +280,7 @@ class BodyActions extends BaseActions $condition = ($blog && ($blog->getSetting($name) == $value)); break; case 'itemblogsetting': - $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid'])); + $b =& $manager->getBlog($this->currentItem['blogid']); $condition = ($b && ($b->getSetting($name) == $value)); break; case 'loggedin': @@ -354,7 +354,7 @@ class BodyActions extends BaseActions { global $member, $manager; - $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid'])); + $b =& $manager->getBlog($this->currentItem['blogid']); // when no parameter is defined, just check if author is current visitor if ( ($key != 'isadmin' && $key != 'name') || ($key == 'name' && $value == '') ) @@ -400,7 +400,7 @@ class BodyActions extends BaseActions { global $catid, $manager; - $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid'])); + $b =& $manager->getBlog($this->currentItem['blogid']); // when no parameter is defined, just check if a category is selected if ( ($key != 'catname' && $key != 'catid') || ($value == '') ) diff --git a/nucleus/libs/COMMENTACTIONS.php b/nucleus/libs/COMMENTACTIONS.php index dd469f0..5dbe28f 100644 --- a/nucleus/libs/COMMENTACTIONS.php +++ b/nucleus/libs/COMMENTACTIONS.php @@ -232,8 +232,8 @@ class CommentActions extends BaseActions public function parse_blogurl() { global $manager; - $blogid = getBlogIDFromItemID($this->commentsObj->itemid); - $blog =& $manager->getBlog($blogid); + $item =& $manager->getItem($this->commentsObj->itemid, 1, 1); + $blog =& $manager->getBlog($item['blogid']); echo $blog->getURL(); return; } @@ -705,8 +705,9 @@ class CommentActions extends BaseActions $condition = ($blog && ($blog->getSetting($name) == $value)); break; case 'itemblogsetting': - $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid'])); - $condition = ($b && ($b->getSetting($name) == $value)); + $item =& $manager->getItem($this->currentComment['itemid'], 1, 1); + $blog =& $manager->getBlog($item['blogid']); + $condition = ($blog && ($blog->getSetting($name) == $value)); break; case 'loggedin': $condition = $member->isLoggedIn(); @@ -781,13 +782,13 @@ class CommentActions extends BaseActions return FALSE; } - $mem =& $manager->getMember($this->currentComment['memberid']); - $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid'])); - $citem =& $manager->getItem($this->currentComment['itemid'], 1, 1); + $member =& $manager->getMember($this->currentComment['memberid']); + $item =& $manager->getItem($this->currentComment['itemid'], 1, 1); // when no parameter is defined, just check if item author is current visitor - if (($key != 'isadmin' && $key != 'name' && $key != 'isauthor' && $key != 'isonteam')) { - return (intval($member->getID()) > 0 && intval($member->getID()) == intval($citem['authorid'])); + if ( ($key != 'isadmin' && $key != 'name' && $key != 'isauthor' && $key != 'isonteam') ) + { + return (intval($memberber->getID()) > 0 && intval($memberber->getID()) == (integer) $item['authorid']); } // check comment author name @@ -798,7 +799,7 @@ class CommentActions extends BaseActions { return FALSE; } - if ( $value == strtolower($mem->getDisplayName()) ) + if ( $value == strtolower($member->getDisplayName()) ) { return TRUE; } @@ -807,24 +808,23 @@ class CommentActions extends BaseActions // check if comment author is admin if ( $key == 'isadmin' ) { - $blogid = intval($b->getID()); - if ( $mem->isAdmin() ) + if ( $member->isAdmin() ) { return TRUE; } - return $mem->isBlogAdmin($blogid); + return $member->isBlogAdmin($item['blogid']); } // check if comment author is item author if ( $key == 'isauthor' ) { - return (intval($citem['authorid']) == intval($this->currentComment['memberid'])); + return ((integer) $item['authorid'] == (integer) $this->currentComment['memberid']); } // check if comment author is on team if ( $key == 'isonteam' ) { - return $mem->teamRights(intval($b->getID())); + return $member->teamRights((integer) $item['blogid']); } return FALSE; } @@ -840,31 +840,30 @@ class CommentActions extends BaseActions private function ifItemCategory($key = '', $value = '') { global $catid, $manager; - - $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid'])); - $citem =& $manager->getItem($this->currentComment['itemid'],1,1); - $icatid = $citem['catid']; - + + $item =& $manager->getItem($this->currentComment['itemid'],1,1); + $blog =& $manager->getBlog($item['blogid']); + // when no parameter is defined, just check if a category is selected if ( ($key != 'catname' && $key != 'catid') || ($value == '') ) { - return $b->isValidCategory($icatid); + return $blog->isValidCategory($item['catid']); } - + // check category name if ( $key == 'catname' ) { - $value = $b->getCategoryIdFromName($value); - if ( $value == $icatid ) + $value = $blog->getCategoryIdFromName($value); + if ( $value == $item['catid'] ) { - return $b->isValidCategory($icatid); + return $blog->isValidCategory($item['catid']); } } - + // check category id - if ( ($key == 'catid') && ($value == $icatid) ) + if ( ($key == 'catid') && ($value == $item['catid']) ) { - return $b->isValidCategory($icatid); + return $blog->isValidCategory($item['catid']); } return FALSE; } @@ -878,12 +877,13 @@ class CommentActions extends BaseActions */ private function ifOnTeam($blogName = '') { - global $blog, $member, $manager; + global $member, $manager; - $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid'])); + $item =& $manager->getItem($this->currentComment['itemid'], 1, 1); + $blog =& $manager->getBlog($item['blogid']); // when no blog found - if ( ($blogName == '') && (!is_object($b)) ) + if ( ($blogName == '') && !is_object($blog) ) { return 0; } @@ -897,7 +897,7 @@ class CommentActions extends BaseActions // use current blog if ( ($blogName == '') || !$manager->existsBlogID($blogid) ) { - $blogid = $b->getID(); + $blogid = $blog->getID(); } return $member->teamRights($blogid); @@ -912,12 +912,13 @@ class CommentActions extends BaseActions */ private function ifAdmin($blogName = '') { - global $blog, $member, $manager; + global $member, $manager; - $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid'])); + $item =& $manager->getItem($this->currentComment['itemid'], 1, 1); + $blog =& $manager->getBlog($item['blogid']); // when no blog found - if ( ($blogName == '') && (!is_object($b)) ) + if ( ($blogName == '') && !is_object($blog) ) { return 0; } @@ -931,7 +932,7 @@ class CommentActions extends BaseActions // use current blog if ( ($blogName == '') || !$manager->existsBlogID($blogid) ) { - $blogid = $b->getID(); + $blogid = $blog->getID(); } return $member->isBlogAdmin($blogid); diff --git a/nucleus/libs/COMMENTS.php b/nucleus/libs/COMMENTS.php index 375b569..d74c2bd 100644 --- a/nucleus/libs/COMMENTS.php +++ b/nucleus/libs/COMMENTS.php @@ -143,9 +143,8 @@ class Comments { global $CONF, $member, $manager; - $blogid = getBlogIDFromItemID($this->itemid); - - $settings =& $manager->getBlog($blogid); + $item =& $manager->getItem($this->itemid, 0, 0); + $settings =& $manager->getBlog($item['blogid']); $settings->readSettings(); // begin if: comments disabled @@ -233,7 +232,7 @@ class Comments $p = $manager->getPlugin($plugin); $continue = $continue || $p->supportsFeature('handleSpam'); } - + $spamcheck = array( 'type' => 'comment', 'body' => $comment['body'], @@ -310,7 +309,6 @@ class Comments $message .= _NOTIFY_COMMENT . "\n " . $comment['body'] . "\n"; $message .= NOTIFICATION::get_mail_footer(); - $item =& $manager->getItem($this->itemid, 0, 0); $subject = _NOTIFY_NC_TITLE . ' ' . strip_tags($item['title']) . ' (' . $this->itemid . ')'; $from = $member->getNotifyFromMailAddress($comment['email']); @@ -324,11 +322,11 @@ class Comments $name = DB::quoteValue($comment['user']); $url = DB::quoteValue($comment['userid']); - $email = DB::quoteValue($comment['email']); + $email = DB::quoteValue($comment['email']); $body = DB::quoteValue($comment['body']); $host = DB::quoteValue($comment['host']); $ip = DB::quoteValue($comment['ip']); - $memberid = intval($comment['memberid']); + $memberid = (integer) $comment['memberid']; $timestamp = DB::formatDateTime($comment['timestamp']); $itemid = $this->itemid; @@ -339,7 +337,7 @@ class Comments . ' AND cmember = ' . $memberid . ' AND cbody = ' . $body . ' AND citem = ' . $itemid - . ' AND cblog = ' . $blogid; + . ' AND cblog = ' . $item['blogid']; $result = (integer) DB::getValue($qSql); if ( $result > 0 ) @@ -349,7 +347,7 @@ class Comments $query = sprintf('INSERT INTO %s (cuser, cmail, cemail, cmember, cbody, citem, ctime, chost, cip, cblog) ' . 'VALUES (%s, %s, %s, %d, %s, %d, %s, %s, %s, %d)' - , sql_table('comment'), $name, $url, $email, $memberid, $body, $itemid, $timestamp, $host, $ip, $blogid); + , sql_table('comment'), $name, $url, $email, $memberid, $body, $itemid, $timestamp, $host, $ip, $item['blogid']); DB::execute($query); diff --git a/nucleus/libs/ITEM.php b/nucleus/libs/ITEM.php index 9de8eb4..602234f 100644 --- a/nucleus/libs/ITEM.php +++ b/nucleus/libs/ITEM.php @@ -97,6 +97,7 @@ class Item if ( !$allow_future ) { + /* FIXME: should be rewritten! */ $blog =& $manager->getBlog(getBlogIDFromItemID($item_id)); $query .= 'AND i.itime <= ' . DB::formatDateTime($blog->getCorrectTime()); } @@ -104,16 +105,13 @@ class Item $query .= ' LIMIT 1'; $result = DB::getResult($query); - if ( $result->rowCount() == 1 ) - { - $aItemInfo = $result->fetch(PDO::FETCH_ASSOC); - $aItemInfo['timestamp'] = strtotime($aItemInfo['itime']); - return $aItemInfo; - } - else + if ( $result->rowCount() != 1 ) { return 0; } + $aItemInfo = $result->fetch(PDO::FETCH_ASSOC); + $aItemInfo['timestamp'] = strtotime($aItemInfo['itime']); + return $aItemInfo; } /** @@ -504,7 +502,7 @@ class Item global $manager; $itemid = (integer) $itemid; - $query = 'select * FROM '.sql_table('item').' WHERE inumber='.$itemid; + $query = 'SELECT * FROM '.sql_table('item').' WHERE inumber='.$itemid; if ( !$future ) { @@ -558,7 +556,8 @@ class Item if ( $type == 'edit' ) { $itemid = intPostVar('itemid'); - $i_blogid = getBlogIDFromItemID($itemid); + $item =& $manager->getItem($itemid, 0, 0); + $i_blogid = $item['blogid']; } else { diff --git a/nucleus/libs/ITEMACTIONS.php b/nucleus/libs/ITEMACTIONS.php index 333dd81..b1de395 100644 --- a/nucleus/libs/ITEMACTIONS.php +++ b/nucleus/libs/ITEMACTIONS.php @@ -847,8 +847,9 @@ class ItemActions extends BaseActions $condition = ($blog && ($blog->getSetting($name) == $value)); break; case 'itemblogsetting': - $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid'])); - $condition = ($b && ($b->getSetting($name) == $value)); + $item =& $manager->getItem($this->currentItem['itemid'], 1, 1); + $t_blog =& $manager->getBlog($item['blogid']); + $condition = ($t_blog && ($t_blog->getSetting($name) == $value)); break; case 'loggedin': $condition = $member->isLoggedIn(); @@ -920,8 +921,6 @@ class ItemActions extends BaseActions { global $member, $manager; - $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid'])); - // when no parameter is defined, just check if author is current visitor if ( ($key != 'isadmin' && $key != 'name') || ($key == 'name' && $value == '') ) { @@ -941,14 +940,12 @@ class ItemActions extends BaseActions // check if author is admin if ( ($key == 'isadmin') ) { - $aid = intval($this->currentItem['authorid']); - $blogid = intval($b->getID()); - $amember =& $manager->getMember($aid); - if ( $amember->isAdmin() ) + $i_author =& $manager->getMember($this->currentItem['authorid']); + if ( $i_author->isAdmin() ) { return TRUE; } - return (boolean) $amember->isBlogAdmin($blogid); + return (boolean) $i_author->isBlogAdmin($this->currentItem['blogid']); } return FALSE; @@ -966,12 +963,12 @@ class ItemActions extends BaseActions { global $catid, $manager; - $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid'])); + $blog =& $manager->getBlog($this->currentItem['blogid']); // when no parameter is defined, just check if a category is selected if ( ($key != 'catname' && $key != 'catid') || ($value == '') ) { - return (boolean) $b->isValidCategory($catid); + return (boolean) $blog->isValidCategory($catid); } $icatid = $this->currentItem['catid']; @@ -979,17 +976,17 @@ class ItemActions extends BaseActions // check category name if ( $key == 'catname' ) { - $value = $b->getCategoryIdFromName($value); + $value = $blog->getCategoryIdFromName($value); if ( $value == $icatid ) { - return (boolean) $b->isValidCategory($icatid); + return (boolean) $blog->isValidCategory($icatid); } } // check category id if ( ($key == 'catid') && ($value == $icatid) ) { - return (boolean) $b->isValidCategory($icatid); + return (boolean) $blog->isValidCategory($icatid); } return FALSE; } diff --git a/nucleus/libs/MANAGER.php b/nucleus/libs/MANAGER.php index 892a71a..8dd1b6a 100644 --- a/nucleus/libs/MANAGER.php +++ b/nucleus/libs/MANAGER.php @@ -98,7 +98,7 @@ class Manager /** * Returns the requested item object. If it is not in the cache, it will * first be loaded and then placed in the cache. - * Intended use: $item =& $manager->getItem(1234) + * Intended use: $item =& $manager->getItem(1234, 0, 0) */ public function &getItem($itemid, $allowdraft, $allowfuture) { @@ -118,7 +118,7 @@ class Manager return 0; } - $blog =& $this->getBlog($item['iblog']); + $blog =& $this->getBlog($item['blogid']); if ( !$allowfuture && ($item['timestamp'] > $blog->getCorrectTime()) ) { return 0; diff --git a/nucleus/libs/MEMBER.php b/nucleus/libs/MEMBER.php index 8172d43..add9899 100644 --- a/nucleus/libs/MEMBER.php +++ b/nucleus/libs/MEMBER.php @@ -550,7 +550,7 @@ class Member global $manager; // item does not exists -> NOK - if ( !$manager->existsItem($itemid,1,1) ) + if ( !$manager->existsItem($itemid, 1, 1) ) { return 0; } @@ -578,7 +578,7 @@ class Member } // get item - $item =& $manager->getItem($itemid,1,1); + $item =& $manager->getItem($itemid, 1, 1); // old catid = new catid -> OK if ($item['catid'] == $newcat) @@ -594,7 +594,8 @@ class Member } // get destination blog - $source_blogid = getBlogIDFromItemID($itemid); + $item =& $manager->getItem($itemid, 1, 1); + $source_blogid = $item['blogid']; $dest_blogid = getBlogIDFromCatID($newcat); // not a team member of destination blog -> NOK -- 2.11.0