Ejemplo n.º 1
0
    /**
     * display block
     *
     * @param  array  $blockinfo a blockinfo structure
     * @return output the rendered bock
     */
    public function display($blockinfo)
    {
        // security check
        if (!SecurityUtil::checkPermission('Menublock::', "$blockinfo[title]::", ACCESS_READ)) {
            return;
        }

        // Break out options from our content field
        $vars = BlockUtil::varsFromContent($blockinfo['content']);

        // add the stylesheet to the header
        if (isset($vars['stylesheet'])) {
            PageUtil::addVar('stylesheet', ThemeUtil::getModuleStyleSheet('Blocks', $vars['stylesheet']));
        }

        // if cache is enabled, checks for a cached output
        if ($this->view->getCaching()) {
            // set the cache id
            $this->view->setCacheId($blockinfo['bkey'].'/bid'.$blockinfo['bid'].'/'.UserUtil::getGidCacheString());

            // check out if the contents are cached
            if ($this->view->is_cached('blocks_block_menu.tpl')) {
                $blockinfo['content'] = $this->view->fetch('blocks_block_menu.tpl');

                return BlockUtil::themeBlock($blockinfo);
            }
        }

        // Styling - this is deprecated and is only to support old menu for now
        if (empty($vars['style'])) {
            $vars['style'] = 1;
        }

        // Content
        $menuitems = array();
        if (!empty($vars['content'])) {
            $contentlines = explode('LINESPLIT', $vars['content']);
            foreach ($contentlines as $contentline) {
                list($url, $title, $comment) = explode('|', $contentline);
                if (SecurityUtil::checkPermission('Menublock::', "$blockinfo[title]:$title:", ACCESS_READ)) {
                    $menuitems[] = self::addMenuItem($title, $url, $comment);
                    $content = true;
                }
            }
        }

        // Modules
        if (!empty($vars['displaymodules'])) {
            $mods = ModUtil::getUserMods();

            // Separate from current content, if any
            if ($vars['content'] == 1) {
                $menuitems[] = self::addMenuItem('', '', '');
            }

            foreach ($mods as $mod) {
                if (SecurityUtil::checkPermission("$mod[name]::", '::', ACCESS_OVERVIEW)) {
                    $menuitems[] = self::addMenuItem($mod['displayname'], ModUtil::url($mod['name'], 'user', 'main'), $mod['description']);
                    $content = true;
                }
            }
        }

        // check for any empty result set
        if (empty($menuitems)) {
            return;
        }

        // assign the items
        $this->view->assign('menuitems', $menuitems);

        // get the block content
        $blockinfo['content'] = $this->view->fetch('blocks_block_menu.tpl');

        // pass the block array back to the theme for display
        return BlockUtil::themeBlock($blockinfo);
    }