OSDN Git Service

Merge branch 'skinnable-master'
[nucleus-jp/nucleus-next.git] / nucleus / libs / ITEMACTIONS.php
index 7df5b87..7db9281 100644 (file)
  *
  * @license http://nucleuscms.org/license.txt GNU General Public License
  * @copyright Copyright (C) 2002-2009 The Nucleus Group
+<<<<<<< HEAD
  * @version $Id: ITEMACTIONS.php 1757 2012-04-15 09:02:32Z sakamocchi $
+=======
+ * @version $Id: ITEMACTIONS.php 1886 2012-06-17 08:27:27Z sakamocchi $
+>>>>>>> skinnable-master
  */
 class ItemActions extends BaseActions
 {
@@ -66,54 +70,47 @@ class ItemActions extends BaseActions
         * defined actions in this class
         */
        static private $defined_actions = array(
+               'author',
+               'authorid',
+               'authorlink',
                'blogid',
-               'title',
+               'blogurl',
                'body',
-               'more',
-               'smartbody',
-               'itemid',
-               'morelink',
                'category',
                'categorylink',
-               'author',
-               'authorid',
-               'authorlink',
                'catid',
-               'karma',
-               'date',
-               'time',
-               'query',
-               'itemlink',
-               'blogurl',
                'closed',
-               'syndicate_title',
-               'syndicate_description',
-               'karmaposlink',
-               'karmaneglink',
-               'new',
-               'image',
-               'popup',
-               'media',
+               'comments',
+               'date',
                'daylink',
-               'query',
-               'include',
-               'phpinclude',
-               'parsedinclude',
-               'skinfile',
-               'set',
-               'plugin',
                'edit',
                'editlink',
                'editpopupcode',
-               'comments',
+               'itemid',
+               'itemlink',
+               'karma',
+               'karmaneglink',
+               'karmaposlink',
+               'more',
+               'morelink',
+               'new',
+               'plugin',
+               'query',
                'relevance',
-               'if',
-               'else',
-               'endif',
-               'elseif',
-               'ifnot',
-               'elseifnot'
-       );
+               'smartbody',
+               'syndicate_description',
+               'syndicate_title',
+               'time',
+               'title',
+       /* actions defined in BodyAction class */
+               'image',
+               'media',
+<<<<<<< HEAD
+               'popup',
+=======
+               'popup'
+>>>>>>> skinnable-master
+               );
        
        /**
         * ItemActions::__construct
@@ -140,16 +137,16 @@ class ItemActions extends BaseActions
        }
        
        /**
-        * ItemActions::getDefinedActions()
+        * ItemActions::getAvailableActions()
         * Returns an array with the actions that are defined
         * in the ItemActions class
         * 
         * @param       void
         * @return      void
         */
-       public function getDefinedActions()
+       public function getAvailableActions()
        {
-               return self::$defined_actions;
+               return array_merge(self::$defined_actions, parent::getAvailableActions());
        }
        
        /**
@@ -165,18 +162,6 @@ class ItemActions extends BaseActions
        }
        
        /**
-        * ItemActions::setParser()
-        * 
-        * @param       object  &$parser        instance of Parser class
-        * @return      void
-        */
-       public function setParser(&$parser)
-       {
-               $this->parser =& $parser;
-               return;
-       }
-       
-       /**
         * ItemActions::setCurrentItem()
         * 
         * @param       object  $item   instance of Item class
@@ -186,7 +171,7 @@ class ItemActions extends BaseActions
        {
                global $currentitemid;
                $this->currentItem =& $item;
-               $currentitemid = $this->currentItem->itemid;
+               $currentitemid = $this->currentItem['itemid'];
                return;
        }
        
@@ -247,7 +232,7 @@ class ItemActions extends BaseActions
         */
        public function parse_body()
        {
-               $this->highlightAndParse($this->currentItem->body);
+               $this->highlightAndParse($this->currentItem['body']);
                return;
        }
        
@@ -260,7 +245,7 @@ class ItemActions extends BaseActions
         */
        public function parse_more()
        {
-               $this->highlightAndParse($this->currentItem->more);
+               $this->highlightAndParse($this->currentItem['more']);
                return;
        }
        
@@ -273,7 +258,7 @@ class ItemActions extends BaseActions
         */
        public function parse_itemid()
        {
-               echo $this->currentItem->itemid;
+               echo $this->currentItem['itemid'];
                return;
        }
        
@@ -286,7 +271,7 @@ class ItemActions extends BaseActions
         */
        public function parse_category()
        {
-               echo $this->currentItem->category;
+               echo $this->currentItem['category'];
                return;
        }
        
@@ -299,7 +284,7 @@ class ItemActions extends BaseActions
         */
        public function parse_categorylink()
        {
-               echo Link::create_link('category', array('catid' => $this->currentItem->catid, 'name' => $this->currentItem->category));
+               echo Link::create_link('category', array('catid' => $this->currentItem['catid'], 'name' => $this->currentItem['category']));
                return;
        }
        
@@ -312,7 +297,7 @@ class ItemActions extends BaseActions
         */
        public function parse_catid()
        {
-               echo $this->currentItem->catid;
+               echo $this->currentItem['catid'];
                return;
        }
        
@@ -325,7 +310,7 @@ class ItemActions extends BaseActions
         */
        public function parse_authorid()
        {
-               echo $this->currentItem->authorid;
+               echo $this->currentItem['authorid'];
                return;
        }
        
@@ -339,8 +324,8 @@ class ItemActions extends BaseActions
        public function parse_authorlink()
        {
                $data = array(
-                               'memberid' => $this->currentItem->authorid,
-                               'name' => $this->currentItem->author,
+                               'memberid' => $this->currentItem['authorid'],
+                               'name' => $this->currentItem['author'],
                                'extra' => $this->linkparams
                        );
                
@@ -371,9 +356,9 @@ class ItemActions extends BaseActions
        public function parse_itemlink()
        {
                $data = array(
-                       'itemid'        => $this->currentItem->itemid,
-                       'title'         => $this->currentItem->title,
-                       'timestamp'     => $this->currentItem->timestamp,
+                       'itemid'        => $this->currentItem['itemid'],
+                       'title'         => $this->currentItem['title'],
+                       'timestamp'     => $this->currentItem['timestamp'],
                        'extra'         => $this->linkparams
                );
                
@@ -403,7 +388,7 @@ class ItemActions extends BaseActions
         */
        public function parse_closed()
        {
-               echo $this->currentItem->closed;
+               echo $this->currentItem['closed'];
                return;
        }
        
@@ -416,7 +401,7 @@ class ItemActions extends BaseActions
         */
        public function parse_relevance()
        {
-               echo round($this->currentItem->score,2);
+               echo round($this->currentItem['score'], 2);
                return;
        }
        
@@ -433,10 +418,6 @@ class ItemActions extends BaseActions
                {
                        $itemtitle = $this->currentItem['title'];
                }
-               elseif ( is_object($this->currentItem) )
-               {
-                       $itemtitle = $this->currentItem->title;
-               }
                switch ( $format )
                {
                        case 'xml':
@@ -467,7 +448,7 @@ class ItemActions extends BaseActions
                global $manager;
                
                // get karma object
-               $karma =& $manager->getKarma($this->currentItem->itemid);
+               $karma =& $manager->getKarma($this->currentItem['itemid']);
                
                switch ( $type )
                {
@@ -508,20 +489,20 @@ class ItemActions extends BaseActions
                switch ( $which )
                {
                        case 'realname':
-                               echo $this->currentItem->authorname;
+                               echo $this->currentItem['authorname'];
                                break;
                        case 'id':
-                               echo $this->currentItem->authorid;
+                               echo $this->currentItem['authorid'];
                                break;
                        case 'email':
-                               echo $this->currentItem->authormail;
+                               echo $this->currentItem['authormail'];
                                break;
                        case 'url':
-                               echo $this->currentItem->authorurl;
+                               echo $this->currentItem['authorurl'];
                                break;
                        case 'name':
                        default:
-                               echo $this->currentItem->author;
+                               echo $this->currentItem['author'];
                }
                return;
        }
@@ -535,13 +516,13 @@ class ItemActions extends BaseActions
         */
        public function parse_smartbody()
        {
-               if ( !$this->currentItem->more )
+               if ( !$this->currentItem['more'] )
                {
-                       $this->highlightAndParse($this->currentItem->body);
+                       $this->highlightAndParse($this->currentItem['body']);
                }
                else
                {
-                       $this->highlightAndParse($this->currentItem->more);
+                       $this->highlightAndParse($this->currentItem['more']);
                }
                return;
        }
@@ -552,7 +533,7 @@ class ItemActions extends BaseActions
         */
        public function parse_morelink()
        {
-               if ( $this->currentItem->more )
+               if ( $this->currentItem['more'] )
                {
                        $this->parser->parse($this->template['MORELINK']);
                }
@@ -589,7 +570,7 @@ class ItemActions extends BaseActions
                        $offset = $this->blog->getTimeOffset() * 3600;
                }
                
-               echo i18n::formatted_datetime($format, $this->currentItem->timestamp, $offset);
+               echo i18n::formatted_datetime($format, $this->currentItem['timestamp'], $offset);
                return;
        }
        
@@ -616,7 +597,7 @@ class ItemActions extends BaseActions
                {
                        $format = $this->template['FORMAT_TIME'];
                }
-               echo i18n::formatted_datetime($format, $this->currentItem->timestamp);
+               echo i18n::formatted_datetime($format, $this->currentItem['timestamp']);
                return;
        }
        
@@ -628,7 +609,7 @@ class ItemActions extends BaseActions
         * @return      string  syndicated      title
         */
        public function parse_syndicate_title($maxLength = 100) {
-               $syndicated = strip_tags($this->currentItem->title);
+               $syndicated = strip_tags($this->currentItem['title']);
                echo Entity::hsc(Entity::shorten($syndicated,$maxLength,'...'));
        }
        
@@ -642,7 +623,7 @@ class ItemActions extends BaseActions
         */
        public function parse_syndicate_description($maxLength = 250, $addHighlight = 0)
        {
-               $syndicated = strip_tags($this->currentItem->body);
+               $syndicated = strip_tags($this->currentItem['body']);
                if ( $addHighlight )
                {
                        $tmp_highlight = Entity::hsc(Entity::shorten($syndicated,$maxLength,'...'));
@@ -665,7 +646,7 @@ class ItemActions extends BaseActions
        public function parse_karmaposlink($text = '')
        {
                global $CONF;
-               $link = $CONF['ActionURL'] . '?action=votepositive&amp;itemid=' . $this->currentItem->itemid;
+               $link = $CONF['ActionURL'] . '?action=votepositive&amp;itemid=' . $this->currentItem['itemid'];
                if ( !$text )
                {
                        echo '<a href="'.$link.'">' . $text . '</a>';
@@ -688,7 +669,7 @@ class ItemActions extends BaseActions
        public function parse_karmaneglink($text = '')
        {
                global $CONF;
-               $link = $CONF['ActionURL'] . '?action=votenegative&amp;itemid='.$this->currentItem->itemid;
+               $link = $CONF['ActionURL'] . '?action=votenegative&amp;itemid='.$this->currentItem['itemid'];
                
                if ( !$text )
                {
@@ -711,7 +692,7 @@ class ItemActions extends BaseActions
         */
        public function parse_new()
        {
-               if ( ($this->lastVisit != 0) && ($this->currentItem->timestamp > $this->lastVisit) )
+               if ( ($this->lastVisit != 0) && ($this->currentItem['timestamp'] > $this->lastVisit) )
                {
                        echo $this->template['NEW'];
                }
@@ -727,7 +708,7 @@ class ItemActions extends BaseActions
         */
        public function parse_daylink()
        {
-               echo Link::create_archive_link($this->blog->getID(), i18n::formatted_datetime('%Y-%m-%d', $this->currentItem->timestamp), $this->linkparams);
+               echo Link::create_archive_link($this->blog->getID(), i18n::formatted_datetime('%Y-%m-%d', $this->currentItem['timestamp']), $this->linkparams);
                return;
        }
        
@@ -748,9 +729,9 @@ class ItemActions extends BaseActions
                // add comments
                if ( $this->showComments && $this->blog->commentsEnabled() )
                {
-                       $comments = new Comments($this->currentItem->itemid);
+                       $comments = new Comments($this->currentItem['itemid']);
                        $comments->setItemActions($this);
-                       $comments->showComments($this->template, $maxToShow, $this->currentItem->closed ? 0 : 1, $this->strHighlight);
+                       $comments->showComments($this->template, $maxToShow, $this->currentItem['closed'] ? 0 : 1, $this->strHighlight);
                }
                return;
        }
@@ -780,9 +761,16 @@ class ItemActions extends BaseActions
                array_shift($params);
                
                // add item reference (array_unshift didn't work)
+<<<<<<< HEAD
                $params = array_merge(array(&$this->currentItem),$params);
                
                call_user_func_array(array(&$plugin,'doTemplateVar'), $params);
+=======
+               $target = array(&$this->currentItem);
+               $params = array_merge($target,$params);
+               
+               call_user_func_array(array($plugin,'doTemplateVar'), $params);
+>>>>>>> skinnable-master
                return;
        }
        
@@ -796,7 +784,7 @@ class ItemActions extends BaseActions
        public function parse_edit()
        {
                global $member, $CONF;
-               if ( $this->allowEditAll || ($member->isLoggedIn() && ($member->getID() == $this->currentItem->authorid)) )
+               if ( $this->allowEditAll || ($member->isLoggedIn() && ($member->getID() == $this->currentItem['authorid'])) )
                {
                        $this->parser->parse($this->template['EDITLINK']);
                }
@@ -810,7 +798,7 @@ class ItemActions extends BaseActions
        public function parse_editlink()
        {
                global $CONF;
-               echo $CONF['AdminURL'] . 'bookmarklet.php?action=edit&amp;itemid=' . $this->currentItem->itemid;
+               echo $CONF['AdminURL'] . 'bookmarklet.php?action=edit&amp;itemid=' . $this->currentItem['itemid'];
                return;
        }
        
@@ -838,12 +826,18 @@ class ItemActions extends BaseActions
         */
        public function highlightAndParse(&$data)
        {
-               $actions = new BodyActions($this->blog);
-               $parser = new Parser($actions->getDefinedActions(), $actions);
-               $actions->setTemplate($this->template);
-               $actions->setHighlight($this->strHighlight);
-               $actions->setCurrentItem($this->currentItem);
-               $parser->parse($actions->highlight($data));
+               $handler = new BodyActions($this->blog);
+               $handler->setTemplate($this->template);
+               $handler->setHighlight($this->strHighlight);
+               $handler->setCurrentItem($this->currentItem);
+               
+               $parser = new Parser($handler);
+<<<<<<< HEAD
+               $parser->parse($handler->highlight($data));
+=======
+               $highlight = $handler->highlight($data);
+               $parser->parse($highlight);
+>>>>>>> skinnable-master
                return;
        }
        
@@ -856,7 +850,7 @@ class ItemActions extends BaseActions
         * @param       string  $value  value of property
         * @return      boolean
         */
-       private function checkCondition($field, $name='', $value = '')
+       protected function checkCondition($field, $name='', $value = '')
        {
                global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
                
@@ -873,8 +867,14 @@ class ItemActions extends BaseActions
                                $condition = ($blog && ($blog->getSetting($name) == $value));
                                break;
                        case 'itemblogsetting':
-                               $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
+<<<<<<< HEAD
+                               $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));
+>>>>>>> skinnable-master
                                break;
                        case 'loggedin':
                                $condition = $member->isLoggedIn();
@@ -946,19 +946,22 @@ class ItemActions extends BaseActions
        {
                global $member, $manager;
                
-               $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
+<<<<<<< HEAD
+               $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid']));
                
+=======
+>>>>>>> skinnable-master
                // when no parameter is defined, just check if author is current visitor
                if ( ($key != 'isadmin' && $key != 'name') || ($key == 'name' && $value == '') )
                {
-                       return (boolean) ((integer) $member->getID() > 0 && (integer) $member->getID() == (integer) $this->currentItem->authorid);
+                       return (boolean) ((integer) $member->getID() > 0 && (integer) $member->getID() == (integer) $this->currentItem['authorid']);
                }
                
                // check author name
                if ( $key == 'name' )
                {
                        $value = strtolower($value);
-                       if ( $value == strtolower($this->currentItem->author) )
+                       if ( $value == strtolower($this->currentItem['author']) )
                        {
                                return TRUE;
                        }
@@ -967,7 +970,8 @@ class ItemActions extends BaseActions
                // check if author is admin
                if ( ($key == 'isadmin') )
                {
-                       $aid = intval($this->currentItem->authorid);
+<<<<<<< HEAD
+                       $aid = intval($this->currentItem['authorid']);
                        $blogid = intval($b->getID());                  
                        $amember =& $manager->getMember($aid);
                        if ( $amember->isAdmin() )
@@ -975,6 +979,14 @@ class ItemActions extends BaseActions
                                return TRUE;
                        }
                        return (boolean) $amember->isBlogAdmin($blogid);
+=======
+                       $i_author =& $manager->getMember($this->currentItem['authorid']);
+                       if ( $i_author->isAdmin() )
+                       {
+                               return TRUE;
+                       }
+                       return (boolean) $i_author->isBlogAdmin($this->currentItem['blogid']);
+>>>>>>> skinnable-master
                }
                
                return FALSE;
@@ -992,30 +1004,49 @@ class ItemActions extends BaseActions
        {
                global $catid, $manager;
                
-               $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
+<<<<<<< HEAD
+               $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid']));
+=======
+               $blog =& $manager->getBlog($this->currentItem['blogid']);
+>>>>>>> skinnable-master
                
                // when no parameter is defined, just check if a category is selected
                if ( ($key != 'catname' && $key != 'catid') || ($value == '') )
                {
+<<<<<<< HEAD
                        return (boolean) $b->isValidCategory($catid);
+=======
+                       return (boolean) $blog->isValidCategory($catid);
+>>>>>>> skinnable-master
                }
                
-               $icatid = $this->currentItem->catid;
+               $icatid = $this->currentItem['catid'];
                
                // check category name
                if ( $key == 'catname' )
                {
+<<<<<<< HEAD
                        $value = $b->getCategoryIdFromName($value);
                        if ( $value == $icatid )
                        {
                                return (boolean) $b->isValidCategory($icatid);
+=======
+                       $value = $blog->getCategoryIdFromName($value);
+                       if ( $value == $icatid )
+                       {
+                               return (boolean) $blog->isValidCategory($icatid);
+>>>>>>> skinnable-master
                        }
                }
                
                // check category id
                if ( ($key == 'catid') && ($value == $icatid) )
                {
+<<<<<<< HEAD
                        return (boolean) $b->isValidCategory($icatid);
+=======
+                       return (boolean) $blog->isValidCategory($icatid);
+>>>>>>> skinnable-master
                }
                return FALSE;
        }
@@ -1149,6 +1180,10 @@ class ItemActions extends BaseActions
                $params = func_get_args();
                array_shift($params);
                
+<<<<<<< HEAD
                return (boolean) call_user_func_array(array(&$plugin, 'doIf'), $params);
+=======
+               return (boolean) call_user_func_array(array($plugin, 'doIf'), $params);
+>>>>>>> skinnable-master
        }
-}
\ No newline at end of file
+}