OSDN Git Service

Merge commit 'b65daabb9967c28543ca406c4de1d2a903c3ac2c' into skinnable-master
[nucleus-jp/nucleus-next.git] / nucleus / libs / AdminActions.php
index 2d568c2..1182503 100644 (file)
@@ -35,7 +35,6 @@ class AdminActions extends BaseActions
                'batchmovetype',
                'blogcatlist',
                'blognotifysetting',
-               'blogselectbox',
                'blogsetting',
                'blogsettingyesno',
                'blogteamlist',
@@ -82,7 +81,6 @@ class AdminActions extends BaseActions
                'importskininfo',
                'inputyesno',
                'insertpluginfo',
-               'insertpluginoptions',
                'insplugoptcontent',
                'iprangeinput',
                'itemnavlist',
@@ -185,7 +183,6 @@ class AdminActions extends BaseActions
                'batchmovecat'                  => _ADM_SKPRT_BATCHMOVECAT,
                'batchteam'                             => _ADM_SKPRT_BATCHTEAM,
                'blogcommentlist'               => _ADM_SKPRT_BLOGCOMMENTLIST,
-               'blogselectbox'                 => _ADM_SKPRT_BLOGSELECTBOX,
                'blogsettings'                  => _ADM_SKPRT_BLOGSETTINGS,
                'bookmarklet'                   => _ADM_SKPRT_BOOKMARKLET,
                'browseowncomments'             => _ADM_SKPRT_BROWSEOWNCOMMENTS,
@@ -198,7 +195,6 @@ class AdminActions extends BaseActions
                'createnewlog'                  => _ADM_SKPRT_CREATENEWLOG,
                'deleteblog'                    => _ADM_SKPRT_DELETEBLOG,
                'editmembersettings'    => _ADM_SKPRT_EDITMEMBERSETTINGS,
-               'insertpluginoptions'   => _ADM_SKPRT_INSERTPLUGINO,
                'itemcommentlist'               => _ADM_SKPRT_ITEMCOMMENTLIST,
                'itemdelete'                    => _ADM_SKPRT_ITEMDELETE,
                'itemedit'                              => _ADM_SKPRT_ITEMEDIT,
@@ -472,11 +468,6 @@ class AdminActions extends BaseActions
                                        'adminbatchlist',
                                );
                                break;
-                       case 'blogselectbox':
-                               $extra_actions = array(
-                                       'blogselectbox',
-                               );
-                               break;
                        case 'blogsettings':
                                $extra_actions = array(
                                        'adminbloglink',
@@ -564,11 +555,6 @@ class AdminActions extends BaseActions
                                        'pluginoptions',
                                );
                                break;
-                       case 'insertpluginoptions':
-                               $extra_actions = array(
-                                       'insertpluginoptions',
-                               );
-                               break;
                        case 'itemcommentlist':
                                $extra_actions = array(
                                        'requestblogid',
@@ -1689,99 +1675,6 @@ class AdminActions extends BaseActions
        }
        
        /**
-        * AdminActions::parse_blogselectbox()
-        * Parse skinvar blogselectbox
-        * 
-        * @param       void
-        * @return      void
-        */
-       public function parse_blogselectbox()
-       {
-               global $member;
-               
-               $selectData     = requestVar('selectData');
-               $mode           = $selectData['mode'];
-               $name           = Entity::hsc($selectData['name']);
-               $tabindex       = Entity::hsc($selectData['tabindex']);
-               $aBlogIds       = array_map('intval', $selectData['aBlogIds']);
-               $showNewCat     = intval($selectData['showNewCat']);
-               $selected       = intval($selectData['selected']);
-               
-               echo "<select name=\"{$name}\" tabindex=\"{$tabindex}\">\n";
-               
-               // 1. select blogs (we'll create optiongroups)
-               // (only select those blogs that have the user on the team)
-               $queryBlogs = "SELECT bnumber, bname FROM %s WHERE bnumber in (%s) ORDER BY bname;";
-               $queryBlogs = sprintf($queryBlogs, sql_table('blog'), implode(',', $aBlogIds));
-               $blogs = DB::getResult($queryBlogs);
-               
-               if ( $mode == 'category' )
-               {
-                       if ( $blogs->rowCount() > 1 )
-                       {
-                               $multipleBlogs = 1;
-                       }
-                       foreach ( $blogs as $rBlog )
-                       {
-                               if ( isset($multipleBlogs) && !empty($multipleBlogs) )
-                               {
-                                       echo '<optgroup label="' . Entity::hsc($rBlog['bname']) . "\">\n";
-                               }
-                               
-                               // show selection to create new category when allowed/wanted
-                               if ( $showNewCat )
-                               {
-                                       // check if allowed to do so
-                                       if ( $member->blogAdminRights($rBlog['bnumber']) )
-                                       {
-                                               echo '<option value="newcat-' . $rBlog['bnumber'] . '">' . _ADD_NEWCAT . "</option>\n";
-                                       }
-                               }
-                               
-                               // 2. for each category in that blog
-                               $catQuery = "SELECT cname, catid FROM %s WHERE cblog=%d ORDER BY cname ASC;";
-                               $catQuery = sprintf($catQuery, sql_table('category'), (integer) $rBlog['bnumber']);
-                               $categories = DB::getResult($catQuery);
-                               foreach ( $categories as $rCat )
-                               {
-                                       if ( $rCat['catid'] == $selected )
-                                       {
-                                               $selectText = ' selected="selected" ';
-                                       }
-                                       else
-                                       {
-                                               $selectText = '';
-                                       }
-                                       echo '<option value="' . $rCat['catid'] . '" ' . $selectText . '>' . Entity::hsc($rCat['cname']) . "</option>\n";
-                               }
-                               
-                               if ( isset($multipleBlogs) && !empty($multipleBlogs) )
-                               {
-                                       echo '</optgroup>';
-                               }
-                       }
-               }
-               else
-               {
-                       // blog mode
-                       foreach ( $blogs as $rBlog )
-                       {
-                               echo '<option value="' . $rBlog['bnumber'] . '"';
-                               if ( $rBlog['bnumber'] == $selected )
-                               {
-                                       echo '<option value="' . $rBlog['bnumber'] . '" selected="selected">' . Entity::hsc($rBlog['bname']) . "</option>\n";
-                               }
-                               else
-                               {
-                                       echo '<option value="' . $rBlog['bnumber'] . '">' . Entity::hsc($rBlog['bname']) . "</option>\n";
-                               }
-                       }
-               }
-               echo "</select>\n";
-               return;
-       }
-       
-       /**
         * AdminActions::parse_blogsetting()
         * Parse skinvar blogsetting
         * 
@@ -1984,7 +1877,7 @@ class AdminActions extends BaseActions
                        $catid = $contents['catid'];
                }
                
-               Admin::selectBlogCategory('catid', $catid, $startidx, 1, $blog->getID());
+               $this->selectBlog('catid', 'category', $catid, $startidx, 1, $blog->getID());
                
                return;
        }
@@ -3684,72 +3577,6 @@ class AdminActions extends BaseActions
        }
        
        /**
-        * AdminActions::parse_insertpluginoptions()
-        * Parse skinvar insertpluginoptions
-        * 
-        * @param       string  $templateName   name of template
-        * @return      void
-        */
-       public function parse_insertpluginoptions($templateName = '')
-       {
-               $options        = Admin::getAdminaOption();
-               $template       = array();
-               $templats       = array();
-               
-               if ( $templateName )
-               {
-                       $templates = Template::read($templateName);
-               }
-               
-               if ( !array_key_exists('INSERT_PLUGOPTION_TITLE', $templates) || empty($templates['INSERT_PLUGOPTION_TITLE']) )
-               {
-                       $template['title'] = "<tr>"
-                                          . "<th colspan=\"2\"><%sprinttext(_PLUGIN_OPTIONS_TITLE, <|%insertpluginfo(name)%|>)%></th>"
-                                          . "</tr>\n";
-               }
-               else
-               {
-                       $template['title'] = $templates['INSERT_PLUGOPTION_TITLE'];
-               }
-               
-               if ( !array_key_exists('INSERT_PLUGOPTION_BODY', $templates) || empty($templates['INSERT_PLUGOPTION_BODY']) )
-               {
-                       $template['body'] = "<tr>"
-                                         . "<%listplugplugoptionrow%>"
-                                         . "</tr>\n";
-               }
-               else
-               {
-                       $template['body'] = $templates['INSERT_PLUGOPTION_BODY'];
-               }
-               
-               $prevPid = -1;
-               
-               include_libs('ACTIONS.php');
-               $handler = new Actions($this->skintype);
-               $parser = new PARSER($handler);
-                       
-               foreach ( $options as $option )
-               {
-                       
-                       // new plugin?
-                       if ( $prevPid != $option['pid'] )
-                       {
-                               $prevPid  = $option['pid'];
-                               $parser->parse($template['title']);
-                       }
-                       
-                       $meta = NucleusPlugin::getOptionMeta($option['typeinfo']);
-                       
-                       if ( @$meta['access'] != 'hidden' )
-                       {
-                               $parsed = $parser->parse($template['body']);
-                       }
-               }
-               return;
-       }
-       
-       /**
         * AdminActions::parse_insplugoptcontent()
         * Parse skinvar insplugoptcontent
         * 
@@ -4069,10 +3896,10 @@ class AdminActions extends BaseActions
                switch ( $actionType )
                {
                        case 'batchitem':
-                               Admin::selectBlogCategory('destcatid');
+                               $this->selectBlog('destcatid', 'category');
                                break;
                        case 'batchcategory':
-                               Admin::selectBlog('destblogid');
+                               $this->selectBlog('destblogid');
                                break;
                        default:
                                if ( $this->skintype == 'itemmove' )
@@ -4080,7 +3907,7 @@ class AdminActions extends BaseActions
                                        $query  = "SELECT icat as result FROM %s WHERE inumber=%d;";
                                        $query = sprintf($query, sql_table('item'), intRequestVar('itemid'));
                                        $catid  = DB::getValue(sprintf($query, intRequestVar('itemid')));
-                                       Admin::selectBlogCategory('catid', $catid, 10, 1);
+                                       $this->selectBlog('catid', 'category', $catid, 10, 1);
                                }
                                break;
                }
@@ -4312,7 +4139,7 @@ class AdminActions extends BaseActions
         * @param       string  $type   type of plugin option
         * @return      void
         */
-       public function parse_pluginoptions($context='global')
+       public function parse_pluginoptions($context='global', $templateName='')
        {
                global $itemid, $manager;
                
@@ -4376,12 +4203,59 @@ class AdminActions extends BaseActions
                $data = array(
                        'context'       =>  $context,
                        'contextid'     =>  $contextid,
-                       'options'       => &$opt4ions
+                       'options'       => &$options
                );
                $manager->notify('PrePluginOptionsEdit', $data);
                
-               $content = $this->parser->skin->getContentFromDB('insertpluginoptions');
-               $this->parser->parse($content);
+               $template = array();
+               if ( $templateName )
+               {
+                       $templates = Template::read($templateName);
+                       if ( !array_key_exists('INSERT_PLUGOPTION_TITLE', $templates) || empty($templates['INSERT_PLUGOPTION_TITLE']) )
+                       {
+                               $template['title'] = "<tr>"
+                                                  . "<th colspan=\"2\"><%sprinttext(_PLUGIN_OPTIONS_TITLE, <|%insertpluginfo(name)%|>)%></th>"
+                                                  . "</tr>\n";
+                       }
+                       else
+                       {
+                               $template['title'] = $templates['INSERT_PLUGOPTION_TITLE'];
+                       }
+                       
+                       if ( !array_key_exists('INSERT_PLUGOPTION_BODY', $templates) || empty($templates['INSERT_PLUGOPTION_BODY']) )
+                       {
+                               $template['body'] = "<tr>"
+                                                 . "<%listplugplugoptionrow%>"
+                                                 . "</tr>\n";
+                       }
+                       else
+                       {
+                               $template['body'] = $templates['INSERT_PLUGOPTION_BODY'];
+                       }
+               }
+               
+               $prevPid = -1;
+               
+               include_libs('ACTIONS.php');
+               $handler = new Actions($this->skintype);
+               $parser = new PARSER($handler);
+                       
+               foreach ( $options as $option )
+               {
+                       // new plugin?
+                       if ( $prevPid != $option['pid'] )
+                       {
+                               $prevPid  = $option['pid'];
+                               $parser->parse($template['title']);
+                       }
+                       
+                       $meta = NucleusPlugin::getOptionMeta($option['typeinfo']);
+                       
+                       if ( @$meta['access'] != 'hidden' )
+                       {
+                               $parsed = $parser->parse($template['body']);
+                       }
+               }
                
                return;
        }
@@ -4644,7 +4518,7 @@ class AdminActions extends BaseActions
                switch ( $type )
                {
                        case 'skin':
-                               $res = DB::getResult('SELECT * FROM ' . sql_table('skin_desc'));
+                               $res = DB::getResult('SELECT * FROM ' . sql_table('skin_desc'). " WHERE sdname NOT LIKE 'admin/%%';");
                                foreach ( $res as $row )
                                {
                                        $data = array(
@@ -5745,7 +5619,7 @@ class AdminActions extends BaseActions
                        {
                                if ( !in_array($matches[1], $installed) )
                                {
-                                       $candidates[] = $matches[1];
+                                       $candidates[] = preg_replace("#^NP_#", "", $matches[1]);
                                }
                        }
                }
@@ -6023,4 +5897,129 @@ class AdminActions extends BaseActions
                
                return;
        }
+       /**
+        * AdminActions::selectBlog()
+        * Inserts a HTML select element with choices for all blogs to which the user has access
+        *      mode = 'blog' => shows blognames and values are blogids
+        *      mode = 'category' => show category names and values are catids
+        *
+        * @param       string  $name                           
+        * @param       string  $mode                           
+        * @param       integer $selected                       
+        * @param       integer $tabindex                       
+        * @param       integer $showNewCat                     
+        * @param       integer $iForcedBlogInclude     ID for weblog always included
+        * @param $iForcedBlogInclude
+        *      ID of a blog that always needs to be included, without checking if the
+        *      member is on the blog team (-1 = none)
+        * @return      void
+        */
+       private function selectBlog($name, $mode='blog', $selected = 0, $tabindex = 0, $showNewCat = 0, $iForcedBlogInclude = -1)
+       {
+               global $member, $CONF;
+               
+               // 0. get IDs of blogs to which member can post items (+ forced blog)
+               $aBlogIds = array();
+               if ( $iForcedBlogInclude != -1 )
+               {
+                       $aBlogIds[] = intval($iForcedBlogInclude);
+               }
+               
+               if ( $member->isAdmin() && array_key_exists('ShowAllBlogs', $CONF) && $CONF['ShowAllBlogs'] )
+               {
+                       $query =  "SELECT bnumber FROM %s ORDER BY bname;";
+                       $query = sprintf($query, sql_table('blog'));
+               }
+               else
+               {
+                       $query =  "SELECT bnumber FROM %s, %s WHERE tblog=bnumber AND tmember=%d;";
+                       $query = sprintf($query, sql_table('blog'), sql_table('team'), (integer) $member->getID());
+               }
+               
+               $rblogids = DB::getResult($query);
+               foreach ( $rblogids as $row )
+               {
+                       if ( $row['bnumber'] != $iForcedBlogInclude )
+                       {
+                               $aBlogIds[] = intval($row['bnumber']);
+                       }
+               }
+               
+               if ( count($aBlogIds) == 0 )
+               {
+                       return;
+               }
+               
+               echo "<select name=\"{$name}\" tabindex=\"{$tabindex}\">\n";
+               
+               // 1. select blogs (we'll create optiongroups)
+               // (only select those blogs that have the user on the team)
+               $queryBlogs = "SELECT bnumber, bname FROM %s WHERE bnumber in (%s) ORDER BY bname;";
+               $queryBlogs = sprintf($queryBlogs, sql_table('blog'), implode(',', $aBlogIds));
+               $blogs = DB::getResult($queryBlogs);
+               
+               if ( $mode == 'category' )
+               {
+                       if ( $blogs->rowCount() > 1 )
+                       {
+                               $multipleBlogs = 1;
+                       }
+                       foreach ( $blogs as $rBlog )
+                       {
+                               if ( isset($multipleBlogs) && !empty($multipleBlogs) )
+                               {
+                                       echo '<optgroup label="' . Entity::hsc($rBlog['bname']) . "\">\n";
+                               }
+                               
+                               // show selection to create new category when allowed/wanted
+                               if ( $showNewCat )
+                               {
+                                       // check if allowed to do so
+                                       if ( $member->blogAdminRights($rBlog['bnumber']) )
+                                       {
+                                               echo '<option value="newcat-' . $rBlog['bnumber'] . '">' . _ADD_NEWCAT . "</option>\n";
+                                       }
+                               }
+                               
+                               // 2. for each category in that blog
+                               $catQuery = "SELECT cname, catid FROM %s WHERE cblog=%d ORDER BY cname ASC;";
+                               $catQuery = sprintf($catQuery, sql_table('category'), (integer) $rBlog['bnumber']);
+                               $categories = DB::getResult($catQuery);
+                               foreach ( $categories as $rCat )
+                               {
+                                       if ( $rCat['catid'] == $selected )
+                                       {
+                                               $selectText = ' selected="selected" ';
+                                       }
+                                       else
+                                       {
+                                               $selectText = '';
+                                       }
+                                       echo '<option value="' . $rCat['catid'] . '" ' . $selectText . '>' . Entity::hsc($rCat['cname']) . "</option>\n";
+                               }
+                               
+                               if ( isset($multipleBlogs) && !empty($multipleBlogs) )
+                               {
+                                       echo '</optgroup>';
+                               }
+                       }
+               }
+               else
+               {
+                       foreach ( $blogs as $rBlog )
+                       {
+                               echo '<option value="' . $rBlog['bnumber'] . '"';
+                               if ( $rBlog['bnumber'] == $selected )
+                               {
+                                       echo '<option value="' . $rBlog['bnumber'] . '" selected="selected">' . Entity::hsc($rBlog['bname']) . "</option>\n";
+                               }
+                               else
+                               {
+                                       echo '<option value="' . $rBlog['bnumber'] . '">' . Entity::hsc($rBlog['bname']) . "</option>\n";
+                               }
+                       }
+               }
+               echo "</select>\n";
+               return;
+       }
 }