OSDN Git Service

Add some codes from 3.61. Currently files under /nucleus/libs and /nucleus/libs/sql...
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / ITEMACTIONS.php
index fb87f00..8f85186 100644 (file)
@@ -102,13 +102,13 @@ class ITEMACTIONS extends BaseActions {
                        'editlink',\r
                        'editpopupcode',\r
                        'comments',\r
-                       'relevance'/*,\r
+                       'relevance',\r
                        'if',\r
                        'else',\r
                        'endif',\r
                        'elseif',\r
                        'ifnot',\r
-                       'elseifnot'*/\r
+                       'elseifnot'\r
                );\r
        }\r
 \r
@@ -119,11 +119,13 @@ class ITEMACTIONS extends BaseActions {
        function setParser(&$parser) {\r
                $this->parser =& $parser;\r
        }\r
-\r
-       function setCurrentItem(&$item) {\r
-               $this->currentItem =& $item;\r
-       }\r
-\r
+       \r
+       function setCurrentItem(&$item) {
+               $this->currentItem =& $item;
+               global $currentitemid;
+               $currentitemid = $this->currentItem->itemid;
+       }
+       
        function setBlog(&$blog) {\r
                $this->blog =& $blog;\r
        }\r
@@ -540,7 +542,246 @@ class ITEMACTIONS extends BaseActions {
                $this->parser->actions = $this->getDefinedActions();\r
        }\r
        */\r
-\r
+       \r
+       // function to enable if-else-elseif-elseifnot-ifnot-endif to item template fields
+       
+               /**
+        * Checks conditions for if statements
+        *
+        * @param string $field type of <%if%>
+        * @param string $name property of field
+        * @param string $value value of property
+        */
+       function checkCondition($field, $name='', $value = '') {
+               global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
+
+               $condition = 0;
+               switch($field) {
+                       case 'category':
+                               $condition = ($blog && $this->_ifCategory($name,$value));
+                               break;
+                       case 'itemcategory':
+                               $condition = ($this->_ifItemCategory($name,$value));
+                               break;
+                       case 'blogsetting':
+                               $condition = ($blog && ($blog->getSetting($name) == $value));
+                               break;
+                       case 'itemblogsetting':
+                               $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
+                               $condition = ($b && ($b->getSetting($name) == $value));
+                               break;
+                       case 'loggedin':
+                               $condition = $member->isLoggedIn();
+                               break;
+                       case 'onteam':
+                               $condition = $member->isLoggedIn() && $this->_ifOnTeam($name);
+                               break;
+                       case 'admin':
+                               $condition = $member->isLoggedIn() && $this->_ifAdmin($name);
+                               break;
+                       case 'author':
+                               $condition = ($this->_ifAuthor($name,$value));
+                               break;
+/*                     case 'nextitem':
+                               $condition = ($itemidnext != '');
+                               break;
+                       case 'previtem':
+                               $condition = ($itemidprev != '');
+                               break;
+                       case 'archiveprevexists':
+                               $condition = ($archiveprevexists == true);
+                               break;
+                       case 'archivenextexists':
+                               $condition = ($archivenextexists == true);
+                               break; 
+                       case 'skintype':
+                               $condition = ($name == $this->skintype);
+                               break; */
+                       case 'hasplugin':
+                               $condition = $this->_ifHasPlugin($name, $value);
+                               break;
+                       default:
+                               $condition = $manager->pluginInstalled('NP_' . $field) && $this->_ifPlugin($field, $name, $value);
+                               break;
+               }
+               return $condition;
+       }       
+       
+       /**
+        *  Different checks for a category
+        */
+       function _ifCategory($name = '', $value='') {
+               global $blog, $catid;
+
+               // when no parameter is defined, just check if a category is selected
+               if (($name != 'catname' && $name != 'catid') || ($value == ''))
+                       return $blog->isValidCategory($catid);
+
+               // check category name
+               if ($name == 'catname') {
+                       $value = $blog->getCategoryIdFromName($value);
+                       if ($value == $catid)
+                               return $blog->isValidCategory($catid);
+               }
+
+               // check category id
+               if (($name == 'catid') && ($value == $catid))
+                       return $blog->isValidCategory($catid);
+
+               return false;
+       }
+       
+               
+       /**
+        *  Different checks for an author
+        */
+       function _ifAuthor($name = '', $value='') {
+               global $member, $manager;
+               
+               $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
+
+               // when no parameter is defined, just check if author is current visitor
+               if (($name != 'isadmin' && $name != 'name') || ($name == 'name' && $value == '')) {
+                       return (intval($member->getID()) > 0 && intval($member->getID()) == intval($this->currentItem->authorid));
+               }
+
+               // check author name
+               if ($name == 'name') {
+                       $value = strtolower($value);
+                       if ($value == strtolower($this->currentItem->author))
+                               return true;
+               }
+
+               // check if author is admin
+               if (($name == 'isadmin')) {                     
+                       $aid = intval($this->currentItem->authorid);
+                       $blogid = intval($b->getID());                  
+                       $amember =& $manager->getMember($aid);
+                       if ($amember->isAdmin())
+                               return true;
+                               
+                       return $amember->isBlogAdmin($blogid);
+               }
+
+               return false;
+       }
+       
+       /**
+        *  Different checks for a category
+        */
+       function _ifItemCategory($name = '', $value='') {
+               global $catid, $manager;
+               
+               $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
+
+               // when no parameter is defined, just check if a category is selected
+               if (($name != 'catname' && $name != 'catid') || ($value == ''))
+                       return $b->isValidCategory($catid);
+                       
+               $icatid = $this->currentItem->catid;
+               //$icategory = $this->currentItem->category;
+
+               // check category name
+               if ($name == 'catname') {
+                       $value = $b->getCategoryIdFromName($value);
+                       if ($value == $icatid)
+                               return $b->isValidCategory($icatid);
+               }
+
+               // check category id
+               if (($name == 'catid') && ($value == $icatid))
+                       return $b->isValidCategory($icatid);
+
+               return false;
+       }
+
+       
+       /**
+        *  Checks if a member is on the team of a blog and return his rights
+        */
+       function _ifOnTeam($blogName = '') {
+               global $blog, $member, $manager;
+
+               // when no blog found
+               if (($blogName == '') && (!is_object($blog)))
+                       return 0;
+
+               // explicit blog selection
+               if ($blogName != '')
+                       $blogid = getBlogIDFromName($blogName);
+
+               if (($blogName == '') || !$manager->existsBlogID($blogid))
+                       // use current blog
+                       $blogid = $blog->getID();
+
+               return $member->teamRights($blogid);
+       }
+
+       /**
+        *  Checks if a member is admin of a blog
+        */
+       function _ifAdmin($blogName = '') {
+               global $blog, $member, $manager;
+
+               // when no blog found
+               if (($blogName == '') && (!is_object($blog)))
+                       return 0;
+
+               // explicit blog selection
+               if ($blogName != '')
+                       $blogid = getBlogIDFromName($blogName);
+
+               if (($blogName == '') || !$manager->existsBlogID($blogid))
+                       // use current blog
+                       $blogid = $blog->getID();
+
+               return $member->isBlogAdmin($blogid);
+       }
+
+       
+       /**
+        *      hasplugin,PlugName
+        *         -> checks if plugin exists
+        *      hasplugin,PlugName,OptionName
+        *         -> checks if the option OptionName from plugin PlugName is not set to 'no'
+        *      hasplugin,PlugName,OptionName=value
+        *         -> checks if the option OptionName from plugin PlugName is set to value
+        */
+       function _ifHasPlugin($name, $value) {
+               global $manager;
+               $condition = false;
+               // (pluginInstalled method won't write a message in the actionlog on failure)
+               if ($manager->pluginInstalled('NP_'.$name)) {
+                       $plugin =& $manager->getPlugin('NP_' . $name);
+                       if ($plugin != NULL) {
+                               if ($value == "") {
+                                       $condition = true;
+                               } else {
+                                       list($name2, $value2) = explode('=', $value, 2);
+                                       if ($value2 == "" && $plugin->getOption($name2) != 'no') {
+                                               $condition = true;
+                                       } else if ($plugin->getOption($name2) == $value2) {
+                                               $condition = true;
+                                       }
+                               }
+                       }
+               }
+               return $condition;
+       }
+
+       /**
+        * Checks if a plugin exists and call its doIf function
+        */
+       function _ifPlugin($name, $key = '', $value = '') {
+               global $manager;
+
+               $plugin =& $manager->getPlugin('NP_' . $name);
+               if (!$plugin) return;
+
+               $params = func_get_args();
+               array_shift($params);
+
+               return call_user_func_array(array(&$plugin, 'doIf'), $params);
+       }
 }\r
-\r
 ?>
\ No newline at end of file