Пример #1
0
 /**
  * block configuration
  *
  * @param mixed[] $blockinfo {
  *      @type string $title   the title of the block
  *      @type int    $bid     the id of the block
  *      @type string $content the seralized block content array
  *                            }
  *
  * @return string html of block modification form
  */
 public function modify($blockinfo)
 {
     $vars = BlockUtil::varsFromContent($blockinfo['content']);
     // set some default vars
     $vars['isnew'] = empty($vars);
     $vars['menutree_content'] = isset($vars['menutree_content']) ? $vars['menutree_content'] : array();
     $vars['menutree_tpl'] = isset($vars['menutree_tpl']) ? $vars['menutree_tpl'] : '';
     $vars['menutree_stylesheet'] = isset($vars['menutree_stylesheet']) ? $vars['menutree_stylesheet'] : '';
     $vars['menutree_linkclass'] = isset($vars['menutree_linkclass']) ? $vars['menutree_linkclass'] : false;
     $vars['menutree_linkclasses'] = isset($vars['menutree_linkclasses']) ? $vars['menutree_linkclasses'] : array();
     $vars['menutree_titles'] = isset($vars['menutree_titles']) ? $vars['menutree_titles'] : array();
     $vars['menutree_editlinks'] = isset($vars['menutree_editlinks']) ? $vars['menutree_editlinks'] : false;
     $vars['menutree_stripbaseurl'] = isset($vars['menutree_stripbaseurl']) ? $vars['menutree_stripbaseurl'] : true;
     $vars['menutree_maxdepth'] = isset($vars['menutree_maxdepth']) ? $vars['menutree_maxdepth'] : 0;
     $vars['oldlanguages'] = isset($vars['oldlanguages']) ? $vars['oldlanguages'] : array();
     $vars['olddefaultlanguage'] = isset($vars['olddefaultlanguage']) ? $vars['olddefaultlanguage'] : '';
     // get list of languages
     $vars['languages'] = ZLanguage::getInstalledLanguageNames();
     $userlanguage = ZLanguage::getLanguageCode();
     // get default langs
     $vars['defaultlanguage'] = !empty($blockinfo['language']) ? $blockinfo['language'] : $userlanguage;
     // rebuild langs array - default lang has to be first
     if (isset($vars['languages']) && count($vars['languages']) > 1) {
         $deflang[$vars['defaultlanguage']] = $vars['languages'][$vars['defaultlanguage']];
         unset($vars['languages'][$vars['defaultlanguage']]);
         $vars['languages'] = array_merge($deflang, $vars['languages']);
         $vars['multilingual'] = true;
     } else {
         $vars['multilingual'] = false;
     }
     $langs = array('list' => array_keys($vars['languages']), 'flat' => false);
     // check if there is allredy content
     if (empty($vars['menutree_content'])) {
         // no content - get list of menus to allow import
         $vars['menutree_menus'] = $this->_get_current_menus($blockinfo['bid']);
     } else {
         // are there new langs not present in current menu?
         // check if there are new languages not present in current menu
         // if so - need to set reference lang to copy initial menu items data
         if (count(array_diff($vars['languages'], $vars['oldlanguages'])) > 1) {
             // fisrt try current default lang
             if (in_array($vars['defaultlanguage'], $vars['oldlanguages'])) {
                 $langs['ref'] = $vars['defaultlanguage'];
                 // or user lang
             } elseif (in_array($userlanguage, $vars['oldlanguages'])) {
                 $langs['ref'] = $userlanguage;
                 // or old default lang
             } elseif (in_array($vars['olddefaultlanguage'], $vars['languages'])) {
                 $langs['ref'] = $vars['olddefaultlanguage'];
                 // it must be any language present in old and new lang list
             } else {
                 $langs['ref'] = current(array_intersect($vars['languages'], $vars['oldlanguages']));
             }
         }
     }
     // decode tree array
     $tree = new MenutreeTree();
     $tree->setOption('id', 'adm-menutree' . $blockinfo['bid']);
     $tree->setOption('sortable', true);
     if (isset($langs)) {
         $tree->setOption('langs', $langs['list']);
     }
     $tree->setOption('stripbaseurl', $vars['menutree_stripbaseurl']);
     $tree->setOption('maxDepth', $vars['menutree_maxdepth']);
     $tree->loadArrayData($vars['menutree_content']);
     $vars['menutree_content'] = $tree->getHTML();
     // get all templates and stylesheets.
     $vars['tpls'] = MenutreeUtil::getTemplates();
     $vars['styles'] = MenutreeUtil::getStylesheets();
     $someThemes = $this->__('Only in some themes');
     $vars['somethemes'] = isset($vars['tpls'][$someThemes]) || isset($vars['styles'][$someThemes]) ? true : false;
     // template to use
     if (empty($vars['menutree_tpl']) || !$this->view->template_exists($vars['menutree_tpl'])) {
         $vars['menutree_tpl'] = 'Block/Menutree/default.tpl';
     }
     // prepare block titles array
     foreach (array_keys($vars['languages']) as $lang) {
         if (!array_key_exists($lang, $vars['menutree_titles'])) {
             $vars['menutree_titles'][$lang] = '';
         }
     }
     // for permissions settings get first supported permlevels
     $vars['permlevels'] = $this->_permlevels();
     // check if saved permlevels are correct
     $vars['menutree_titlesperms'] = !empty($vars['menutree_titlesperms']) ? $vars['menutree_titlesperms'] : 'ACCESS_EDIT';
     $vars['menutree_displayperms'] = !empty($vars['menutree_displayperms']) ? $vars['menutree_displayperms'] : 'ACCESS_EDIT';
     $vars['menutree_settingsperms'] = !empty($vars['menutree_settingsperms']) ? $vars['menutree_settingsperms'] : 'ACCESS_EDIT';
     // check user permissions for settings sections
     $useraccess = SecurityUtil::getSecurityLevel(SecurityUtil::getAuthInfo(), 'ZikulaBlocksModule::', "{$blockinfo['bkey']}:{$blockinfo['title']}:{$blockinfo['bid']}");
     $vars['menutree_titlesaccess'] = $useraccess >= constant($vars['menutree_titlesperms']);
     $vars['menutree_displayaccess'] = $useraccess >= constant($vars['menutree_displayperms']);
     $vars['menutree_settingsaccess'] = $useraccess >= constant($vars['menutree_settingsperms']);
     $vars['menutree_adminaccess'] = $useraccess >= ACCESS_ADMIN;
     $vars['menutree_anysettingsaccess'] = $vars['menutree_adminaccess'] || $vars['menutree_titlesaccess'] || $vars['menutree_displayaccess'] || $vars['menutree_settingsaccess'];
     // check if the users wants to add a new link via the "Add current url" link in the block
     $addurl = $this->request->query->get('addurl', 0);
     // or if we come from the normal "edit this block" link
     $fromblock = $this->request->query->get('fromblock', null);
     $vars['redirect'] = '';
     $vars['menutree_newurl'] = '';
     if ($addurl == 1) {
         // set a marker for redirection later on
         $newurl = System::serverGetVar('HTTP_REFERER');
         $vars['redirect'] = urlencode($newurl);
         $newurl = str_replace(System::getBaseUrl(), '', $newurl);
         if (empty($newurl)) {
             $newurl = System::getHomepageUrl();
         }
         $vars['menutree_newurl'] = $newurl;
     } elseif (isset($fromblock)) {
         $vars['redirect'] = urlencode(System::serverGetVar('HTTP_REFERER'));
     }
     // Create output object
     $this->view->setCaching(Zikula_View::CACHE_DISABLED);
     // assign all block variables
     $this->view->assign($vars)->assign('blockinfo', $blockinfo);
     // Return the output that has been generated by this function
     return $this->view->fetch('Block/Menutree/modify.tpl');
 }
Пример #2
0
 /**
  * Return some common user links
  *
  * Syntax used in menutree
  * {ext:ZikulaBlocksModule:userlinks:[flat]}
  * Last param is optional
  *
  * This plugin generates a list of  some common user links. The list looks as follows:
  * for loggedin users:
  *      Your Account
  *          Profile
  *          Private Messages (if there is some message module)
  *          Logout
  * for anonymous users:
  *      Your Account
  *          Login
  *          Register
  *          Lost Password
  *
  * If you provide an additional param extrainfo = flat, then the links are not grouped within
  * Your Accont element
  *
  * @param mixed[] $args {
  *      @type  array  $item      menu node to be replaced
  *      @type  string $lang      current menu language
  *      @type  string $extrainfo additional params - if 'flat' then return links ungrouped
  *                       }
  *
  * @return array|bool array of links if successful, false otherwise
  */
 public function userlinks($args)
 {
     $dom = ZLanguage::getModuleDomain('menutree');
     $item = isset($args['item']) && !empty($args['item']) ? $args['item'] : null;
     $lang = isset($args['lang']) && !empty($args['lang']) ? $args['lang'] : null;
     $extrainfo = isset($args['extrainfo']) && !empty($args['extrainfo']) ? $args['extrainfo'] : null;
     // $item and lang params are required
     if (!$item || !$lang) {
         return false;
     }
     // get id for first element, use api func to avoid id conflicts inside menu
     $idoffset = MenutreeUtil::getIdOffset($item['id']);
     $lineno = 0;
     // module config
     $profileModule = System::getVar('profilemodule') ? System::getVar('profilemodule') : 'ZikulaProfileModule';
     $profileModule = ModUtil::available($profileModule) ? $profileModule : null;
     $messageModule = System::getVar('messagemodule') ? System::getVar('messagemodule') : 'InterCom';
     $messageModule = ModUtil::available($messageModule) ? $messageModule : null;
     $links = array();
     // if $extrainfo if 'flat' - don't group links in your_account node
     if ($extrainfo != 'flat') {
         $links['your_account'] = array($lang => array('id' => $idoffset++, 'name' => $item['name'], 'href' => ModUtil::url($profileModule), 'title' => $item['title'], 'className' => $item['className'], 'state' => $item['state'], 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $item['parent']));
     }
     // need to set parent node id - if links are grouped - use your_accont item id
     // otherwise parent id of replaced menu node
     $parentNode = $extrainfo != 'flat' ? $links['your_account'][$lang]['id'] : $item['parent'];
     if (UserUtil::isLoggedIn()) {
         $links['profile'] = array($lang => array('id' => $idoffset++, 'name' => __('Profile', $dom), 'href' => ModUtil::url($profileModule), 'title' => __('Profile', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode));
         if (!is_null($messageModule)) {
             $links['messages'] = array($lang => array('id' => $idoffset++, 'name' => __('Private messages', $dom), 'href' => ModUtil::url($messageModule), 'title' => __('Private messages', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode));
         }
         $links['logout'] = array($lang => array('id' => $idoffset++, 'name' => __('Logout', $dom), 'href' => ModUtil::url('ZikulaUsersModule', 'user', 'logout'), 'title' => __('Logout', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode));
     } else {
         $serviceManager = ServiceUtil::getManager();
         $request = $this->serviceManager->get('request');
         $loginArgs = array();
         if ($request->isMethod('GET')) {
             $loginArgs['returnpage'] = urlencode(System::getCurrentUri());
         }
         $links['login'] = array($lang => array('id' => $idoffset++, 'name' => __('Login', $dom), 'href' => ModUtil::url('ZikulaUsersModule', 'user', 'login', $loginArgs), 'title' => __('Login', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode));
         $links['register'] = array($lang => array('id' => $idoffset++, 'name' => __('Register', $dom), 'href' => ModUtil::url('ZikulaUsersModule', 'user', 'register'), 'title' => __('Register', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode));
         $links['lostpassword'] = array($lang => array('id' => $idoffset++, 'name' => __('Lost password', $dom), 'href' => ModUtil::url('ZikulaUsersModule', 'user', 'lostpassword'), 'title' => __('Lost password', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode));
     }
     return $links;
 }