示例#1
0
    /**
     * block configuration
     */
    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['olddefaultanguage'] =        isset($vars['olddefaultanguage']) ? $vars['olddefaultanguage'] :'';

        // get list of languages
        $vars['languages'] = ZLanguage::getInstalledLanguageNames();
        $userlanguage = ZLanguage::getLanguageCode();

        // get default langs
        $vars['defaultanguage'] = !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['defaultanguage']] = $vars['languages'][$vars['defaultanguage']];
            unset($vars['languages'][$vars['defaultanguage']]);
            $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['defaultanguage'],$vars['oldlanguages'])) {
                    $langs['ref'] = $vars['defaultanguage'];
                    // or user lang
                } elseif (in_array($userlanguage,$vars['oldlanguages'])) {
                    $langs['ref'] = $userlanguage;
                    // or old default lang
                } elseif (in_array($vars['olddefaultanguage'],$vars['languages'])) {
                    $langs['ref'] = $vars['olddefaultanguage'];
                    // 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 Blocks_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'] = Blocks_MenutreeUtil::getTemplates();
        $vars['styles'] =  Blocks_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'] = 'menutree/blocks_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(), 'Blocks::', "$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 = FormUtil::getPassedValue('addurl', 0, 'GET');

        // or if we come from the normal "edit this block" link
        $fromblock = FormUtil::getPassedValue('fromblock', null, 'GET');

        $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('menutree/blocks_block_menutree_modify.tpl');
    }
示例#2
0
 /**
  * Return some common user links
  *
  * Syntax used in menutree
  * {ext:Blocks: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 array $args['item'] menu node to be replaced
  * @param string $args['lang'] current menu language
  * @param string $args['extrainfo'] additional params - if 'flat' then return links ungrouped
  * @return mixed 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 ang lang params are required
     if (!$item || !$lang) {
         return false;
     }
     // get id for first element, use api func to aviod id conflicts inside menu
     $idoffset = Blocks_MenutreeUtil::getIdOffset($item['id']);
     $lineno = 0;
     // module config
     $profileModule = System::getVar('profilemodule') ? System::getVar('profilemodule') : 'Profile';
     $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('Users', 'user', 'logout'), 'title' => __('Logout', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode));
     } else {
         $serviceManager = ServiceUtil::getManager();
         $request = $this->serviceManager->getService('request');
         $loginArgs = array();
         if ($request->isGet()) {
             $loginArgs['returnpage'] = urlencode(System::getCurrentUri());
         }
         $links['login'] = array($lang => array('id' => $idoffset++, 'name' => __('Login', $dom), 'href' => ModUtil::url('Users', '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('Users', '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('Users', 'user', 'lostpassword'), 'title' => __('Lost password', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode));
     }
     return $links;
 }