コード例 #1
0
ファイル: Menu.php プロジェクト: Jsechoo/sisome
 /**
  * 执行函数,初始化菜单
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     $parentNodes = array(NULL, _t('控制台'), _t('撰写'), _t('管理'), _t('设置'));
     $childNodes = array(array(array(_t('登录'), _t('登录到%s', $this->options->title), 'login.php', 'visitor'), array(_t('注册'), _t('注册到%s', $this->options->title), 'register.php', 'visitor')), array(array(_t('概要'), _t('网站概要'), 'index.php', 'subscriber'), array(_t('个人设置'), _t('个人设置'), 'profile.php', 'subscriber'), array(_t('插件'), _t('插件管理'), 'plugins.php', 'administrator'), array(array('Widget_Plugins_Config', 'getMenuTitle'), array('Widget_Plugins_Config', 'getMenuTitle'), 'options-plugin.php?config=', 'administrator', true), array(_t('外观'), _t('网站外观'), 'themes.php', 'administrator'), array(array('Widget_Themes_Files', 'getMenuTitle'), array('Widget_Themes_Files', 'getMenuTitle'), 'theme-editor.php', 'administrator', true), array(_t('设置外观'), _t('设置外观'), 'options-theme.php', 'administrator', true), array(_t('升级'), _t('升级程序'), 'upgrade.php', 'administrator', true), array(_t('欢迎'), _t('欢迎使用'), 'welcome.php', 'subscriber', true)), array(array(_t('撰写文章'), _t('撰写新文章'), 'write-post.php', 'contributor'), array(array('Widget_Contents_Post_Edit', 'getMenuTitle'), array('Widget_Contents_Post_Edit', 'getMenuTitle'), 'write-post.php?cid=', 'contributor', true), array(_t('创建页面'), _t('创建新页面'), 'write-page.php', 'editor'), array(array('Widget_Contents_Page_Edit', 'getMenuTitle'), array('Widget_Contents_Page_Edit', 'getMenuTitle'), 'write-page.php?cid=', 'editor', true)), array(array(_t('文章'), _t('管理文章'), 'manage-posts.php', 'contributor', false, 'write-post.php'), array(array('Widget_Contents_Post_Admin', 'getMenuTitle'), array('Widget_Contents_Post_Admin', 'getMenuTitle'), 'manage-posts.php?uid=', 'contributor', true), array(_t('独立页面'), _t('管理独立页面'), 'manage-pages.php', 'editor', false, 'write-page.php'), array(_t('评论'), _t('管理评论'), 'manage-comments.php', 'contributor'), array(array('Widget_Comments_Admin', 'getMenuTitle'), array('Widget_Comments_Admin', 'getMenuTitle'), 'manage-comments.php?cid=', 'contributor', true), array(_t('分类'), _t('管理分类'), 'manage-categories.php', 'editor', false, 'category.php'), array(_t('新增分类'), _t('新增分类'), 'category.php', 'editor', true), array(array('Widget_Metas_Category_Admin', 'getMenuTitle'), array('Widget_Metas_Category_Admin', 'getMenuTitle'), 'manage-categories.php?parent=', 'editor', true, array('Widget_Metas_Category_Admin', 'getAddLink')), array(array('Widget_Metas_Category_Edit', 'getMenuTitle'), array('Widget_Metas_Category_Edit', 'getMenuTitle'), 'category.php?mid=', 'editor', true), array(array('Widget_Metas_Category_Edit', 'getMenuTitle'), array('Widget_Metas_Category_Edit', 'getMenuTitle'), 'category.php?parent=', 'editor', true), array(_t('标签'), _t('管理标签'), 'manage-tags.php', 'editor'), array(array('Widget_Metas_Tag_Admin', 'getMenuTitle'), array('Widget_Metas_Tag_Admin', 'getMenuTitle'), 'manage-tags.php?mid=', 'editor', true), array(_t('文件'), _t('管理文件'), 'manage-medias.php', 'editor'), array(array('Widget_Contents_Attachment_Edit', 'getMenuTitle'), array('Widget_Contents_Attachment_Edit', 'getMenuTitle'), 'media.php?cid=', 'contributor', true), array(_t('用户'), _t('管理用户'), 'manage-users.php', 'administrator', false, 'user.php'), array(_t('新增用户'), _t('新增用户'), 'user.php', 'administrator', true), array(array('Widget_Users_Edit', 'getMenuTitle'), array('Widget_Users_Edit', 'getMenuTitle'), 'user.php?uid=', 'administrator', true)), array(array(_t('基本'), _t('基本设置'), 'options-general.php', 'administrator'), array(_t('评论'), _t('评论设置'), 'options-discussion.php', 'administrator'), array(_t('阅读'), _t('阅读设置'), 'options-reading.php', 'administrator'), array(_t('社区'), _t('社区设置'), 'options-forum.php', 'administrator'), array(_t('永久链接'), _t('永久链接设置'), 'options-permalink.php', 'administrator')));
     /** 获取扩展菜单 */
     $panelTable = unserialize($this->options->panelTable);
     $extendingParentMenu = empty($panelTable['parent']) ? array() : $panelTable['parent'];
     $extendingChildMenu = empty($panelTable['child']) ? array() : $panelTable['child'];
     $currentUrl = $this->request->makeUriByRequest();
     $adminUrl = $this->options->adminUrl;
     $menu = array();
     $defaultChildeNode = array(NULL, NULL, NULL, 'administrator', false, NULL);
     $currentUrlParts = parse_url($currentUrl);
     $currentUrlParams = array();
     if (!empty($currentUrlParts['query'])) {
         parse_str($currentUrlParts['query'], $currentUrlParams);
     }
     if ('/' == $currentUrlParts['path'][strlen($currentUrlParts['path']) - 1]) {
         $currentUrlParts['path'] .= 'index.php';
     }
     foreach ($extendingParentMenu as $key => $val) {
         $parentNodes[10 + $key] = $val;
     }
     foreach ($extendingChildMenu as $key => $val) {
         $childNodes[$key] = array_merge(isset($childNodes[$key]) ? $childNodes[$key] : array(), $val);
     }
     foreach ($parentNodes as $key => $parentNode) {
         // this is a simple struct than before
         $children = array();
         $showedChildrenCount = 0;
         $firstUrl = NULL;
         foreach ($childNodes[$key] as $inKey => $childNode) {
             // magic merge
             $childNode += $defaultChildeNode;
             list($name, $title, $url, $access, $hidden, $addLink) = $childNode;
             // 保存最原始的hidden信息
             $orgHidden = $hidden;
             // parse url
             $url = Typecho_Common::url($url, $adminUrl);
             // compare url
             $urlParts = parse_url($url);
             $urlParams = array();
             if (!empty($urlParts['query'])) {
                 parse_str($urlParts['query'], $urlParams);
             }
             $validate = true;
             if ($urlParts['path'] != $currentUrlParts['path']) {
                 $validate = false;
             } else {
                 foreach ($urlParams as $paramName => $paramValue) {
                     if (!isset($currentUrlParams[$paramName])) {
                         $validate = false;
                         break;
                     }
                 }
             }
             if ($validate && basename($urlParts['path']) == 'extending.php' && !empty($currentUrlParams['panel']) && !empty($urlParams['panel']) && $urlParams['panel'] != $currentUrlParams['panel']) {
                 $validate = false;
             }
             if ($hidden && $validate) {
                 $hidden = false;
             }
             if (!$hidden && !$this->user->pass($access, true)) {
                 $hidden = true;
             }
             if (!$hidden) {
                 $showedChildrenCount++;
                 if (empty($firstUrl)) {
                     $firstUrl = $url;
                 }
                 if (is_array($name)) {
                     list($widget, $method) = $name;
                     $name = Typecho_Widget::widget($widget)->{$method}();
                 }
                 if (is_array($title)) {
                     list($widget, $method) = $title;
                     $title = Typecho_Widget::widget($widget)->{$method}();
                 }
                 if (is_array($addLink)) {
                     list($widget, $method) = $addLink;
                     $addLink = Typecho_Widget::widget($widget)->{$method}();
                 }
             }
             if ($validate) {
                 if ('visitor' != $access) {
                     $this->user->pass($access);
                 }
                 $this->_currentParent = $key;
                 $this->_currentChild = $inKey;
                 $this->title = $title;
                 $this->addLink = $addLink ? Typecho_Common::url($addLink, $adminUrl) : NULL;
             }
             $children[$inKey] = array($name, $title, $url, $access, $hidden, $addLink, $orgHidden);
         }
         $menu[$key] = array($parentNode, $showedChildrenCount > 0, $firstUrl, $children);
     }
     $this->_menu = $menu;
     $this->_currentUrl = $currentUrl;
 }
コード例 #2
0
ファイル: Menu.php プロジェクト: raindali/express
 /**
  * 执行函数,初始化菜单
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     $this->_parentMenu = array(NULL, _t('控制台'), _t('创建'), _t('管理'), _t('设置'));
     $this->_childMenu = array(array(array(_t('登录'), _t('登录到%s', $this->options->title), 'login.php', 'visitor'), array(_t('注册'), _t('注册到%s', $this->options->title), 'register.php', 'visitor')), array(array(_t('概要'), _t('网站概要'), 'index.php', 'subscriber'), array(_t('个人设置'), _t('个人设置'), 'profile.php', 'subscriber'), array(_t('插件'), _t('插件管理'), 'plugins.php', 'administrator'), array(array('Widget_Plugins_Config', 'getMenuTitle'), array('Widget_Plugins_Config', 'getMenuTitle'), 'options-plugin.php?config=', 'administrator', true), array(_t('外观'), _t('网站外观'), 'themes.php', 'administrator'), array(array('Widget_Themes_Files', 'getMenuTitle'), array('Widget_Themes_Files', 'getMenuTitle'), 'theme-editor.php', 'administrator', true), array(array('Widget_Themes_Config', 'getMenuTitle'), array('Widget_Themes_Config', 'getMenuTitle'), 'options-theme.php', 'administrator', true), array(_t('升级'), _t('升级程序'), 'upgrade.php', 'administrator', true), array(_t('欢迎'), _t('欢迎使用'), 'welcome.php', 'subscriber', true)), array(array(_t('撰写文章'), _t('撰写新文章'), 'write-post.php', 'contributor'), array(array('Widget_Contents_Post_Edit', 'getMenuTitle'), array('Widget_Contents_Post_Edit', 'getMenuTitle'), 'write-post.php?cid=', 'contributor', true), array(_t('创建页面'), _t('创建新页面'), 'write-page.php', 'editor'), array(array('Widget_Contents_Page_Edit', 'getMenuTitle'), array('Widget_Contents_Page_Edit', 'getMenuTitle'), 'write-page.php?cid=', 'editor', true)), array(array(_t('文章'), _t('管理文章'), 'manage-posts.php', 'contributor', false, Typecho_Common::url('write-post.php', $this->options->adminUrl)), array(array('Widget_Contents_Post_Admin', 'getMenuTitle'), array('Widget_Contents_Post_Admin', 'getMenuTitle'), 'manage-posts.php?uid=', 'contributor', true), array(_t('独立页面'), _t('管理独立页面'), 'manage-pages.php', 'editor', false, Typecho_Common::url('write-page.php', $this->options->adminUrl)), array(_t('评论'), _t('管理评论'), 'manage-comments.php', 'contributor'), array(array('Widget_Comments_Admin', 'getMenuTitle'), array('Widget_Comments_Admin', 'getMenuTitle'), 'manage-comments.php?cid=', 'contributor', true), array(_t('标签和分类'), _t('标签和分类'), 'manage-metas.php', 'editor'), array(_t('附件'), _t('管理附件'), 'manage-medias.php', 'editor'), array(array('Widget_Contents_Attachment_Edit', 'getMenuTitle'), array('Widget_Contents_Attachment_Edit', 'getMenuTitle'), 'media.php?cid=', 'contributor', true), array(_t('用户'), _t('管理用户'), 'manage-users.php', 'administrator', false, Typecho_Common::url('user.php', $this->options->adminUrl)), array(_t('新增用户'), _t('新增用户'), 'user.php', 'administrator', true), array(array('Widget_Users_Edit', 'getMenuTitle'), array('Widget_Users_Edit', 'getMenuTitle'), 'user.php?uid=', 'administrator', true)), array(array(_t('基本'), _t('基本设置'), 'options-general.php', 'administrator'), array(_t('评论'), _t('评论设置'), 'options-discussion.php', 'administrator'), array(_t('文章'), _t('阅读设置'), 'options-reading.php', 'administrator'), array(_t('永久链接'), _t('永久链接设置'), 'options-permalink.php', 'administrator')));
     /** 获取扩展菜单 */
     $panelTable = unserialize($this->options->panelTable);
     $extendingParentMenu = empty($panelTable['parent']) ? array() : $panelTable['parent'];
     $extendingChildMenu = empty($panelTable['child']) ? array() : $panelTable['child'];
     foreach ($extendingParentMenu as $key => $val) {
         $this->_parentMenu[10 + $key] = $val;
     }
     foreach ($extendingChildMenu as $key => $val) {
         $this->_childMenu[$key] = isset($this->_childMenu[$key]) ? $this->_childMenu[$key] : array();
         if (isset($this->_parentMenu[$key])) {
             $this->_childMenu[$key] = array_merge($this->_childMenu[$key], $val);
         }
     }
     $this->_currentUrl = $this->request->makeUriByRequest();
     $childMenu = $this->_childMenu;
     $adminUrl = $this->options->adminUrl;
     foreach ($childMenu as $parentKey => $parentVal) {
         foreach ($parentVal as $childKey => $childVal) {
             $link = Typecho_Common::url($childVal[2], $adminUrl);
             $currentParts = parse_url($this->_currentUrl);
             $parts = parse_url($link);
             /** 精准比对 */
             if ($currentParts['path'] == $parts['path']) {
                 $validate = true;
                 if (!empty($parts['query'])) {
                     parse_str($parts['query'], $out);
                     if (empty($currentParts['query'])) {
                         $validate = false;
                     } else {
                         parse_str($currentParts['query'], $currentOut);
                         if (!empty($out)) {
                             if (!empty($currentOut)) {
                                 foreach ($out as $outKey => $outVal) {
                                     if (!isset($currentOut[$outKey])) {
                                         $validate = false;
                                         break;
                                     }
                                 }
                             } else {
                                 $validate = false;
                             }
                         }
                     }
                 }
                 if ($validate) {
                     $this->_currentParent = $parentKey;
                     $this->_currentChild = $childKey;
                 }
             }
             if ('visitor' != $childVal[3] && !$this->user->pass($childVal[3], true)) {
                 unset($this->_childMenu[$parentKey][$childKey]);
             }
         }
         if (0 == count($this->_childMenu[$parentKey])) {
             unset($this->_parentMenu[$parentKey]);
         }
     }
     $level = isset($this->_childMenu[$this->_currentParent][$this->_currentChild][3]) ? $this->_childMenu[$this->_currentParent][$this->_currentChild][3] : 'administrator';
     if ('visitor' != $level) {
         $this->user->pass($level);
     }
     if (isset($this->_childMenu[$this->_currentParent][$this->_currentChild][5])) {
         $this->addLink = $this->_childMenu[$this->_currentParent][$this->_currentChild][5];
     }
     if (is_array($this->_childMenu[$this->_currentParent][$this->_currentChild][1])) {
         list($widget, $method) = $this->_childMenu[$this->_currentParent][$this->_currentChild][1];
         $this->title = Typecho_Widget::widget($widget)->{$method}();
     } else {
         $this->title = $this->_childMenu[$this->_currentParent][$this->_currentChild][1];
     }
     array_shift($this->_parentMenu);
     array_shift($this->_childMenu);
     $this->_currentParent--;
 }