Example #1
0
 /**
  * Display block.
  *
  * @param  array  $blockInfo a blockinfo structure
  *
  * @return string html block
  */
 public function display($blockInfo)
 {
     if (!SecurityUtil::checkPermission('Dashboard::', "::", ACCESS_READ)) {
         return;
     }
     // Break out options from our content field
     $vars = BlockUtil::varsFromContent($blockInfo['content']);
     if ($this->view->getCaching()) {
         $this->view->setCacheId($blockInfo['bkey'] . '/bid' . $blockInfo['bid'] . '/' . UserUtil::getGidCacheString());
         if ($this->view->is_cached('Block/dashboard.html.tpl')) {
             $blockInfo['content'] = $this->view->fetch('Block/dashboard.html.tpl');
             return BlockUtil::themeBlock($blockInfo);
         }
     }
     $uid = $this->request->getSession()->get('uid');
     $helper = new Dashboard_Helper_WidgetHelper($this->entityManager);
     $dashboard = $helper->getUserWidgets($uid);
     $this->view->assign('userWidgets', $dashboard);
     // get the block content
     $blockInfo['content'] = $this->view->fetch('Block/dashboard.html.tpl');
     // pass the block array back to the theme for display
     return BlockUtil::themeBlock($blockInfo);
 }
Example #2
0
 /**
  * display block
  *
  * @param        array       $blockinfo     a blockinfo structure
  * @return       output      the rendered bock
  */
 public function display($blockinfo)
 {
     // security check
     if (!SecurityUtil::checkPermission('ExtendedMenublock::', $blockinfo['bid'] . '::', ACCESS_READ)) {
         return;
     }
     // Break out options from our content field
     $vars = BlockUtil::varsFromContent($blockinfo['content']);
     // template to use
     if (empty($vars['template'])) {
         $vars['template'] = 'blocks_block_extmenu.tpl';
     }
     // stylesheet to use
     if (empty($vars['stylesheet'])) {
         $vars['stylesheet'] = 'extmenu.css';
     }
     // add the stylesheet to the header
     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($vars['template'])) {
             $blockinfo['content'] = $this->view->fetch($vars['template']);
             return BlockUtil::themeBlock($blockinfo);
         }
     }
     // create default block variables
     if (!isset($vars['blocktitles'])) {
         $vars['blocktitles'] = array();
     }
     if (!isset($vars['links'])) {
         $vars['links'] = array();
     }
     if (!isset($vars['stylesheet'])) {
         $vars['stylesheet'] = '';
     }
     if (!isset($vars['menuid'])) {
         $vars['menuid'] = 0;
     }
     // get language and default to en
     $thislang = ZLanguage::getLanguageCode();
     if (!array_key_exists($thislang, $vars['links'])) {
         $thislang = 'en';
     }
     // if specific blocktitle for selected language exists, use it
     if (array_key_exists($thislang, $vars['blocktitles']) && !empty($vars['blocktitles'][$thislang])) {
         $blockinfo['title'] = $vars['blocktitles'][$thislang];
     }
     // Content
     $menuitems = array();
     if (!empty($vars['links'][$thislang])) {
         $blocked = array();
         foreach ($vars['links'][$thislang] as $linkid => $link) {
             $link['parentid'] = isset($link['parentid']) ? $link['parentid'] : null;
             $denied = !SecurityUtil::checkPermission('ExtendedMenublock::', $blockinfo['bid'] . ':' . $linkid . ':', ACCESS_READ);
             if ($denied || !is_null($link['parentid']) && in_array($link['parentid'], $blocked)) {
                 $blocked[] = $linkid;
             } elseif (!isset($link['active']) || $link['active'] != '1') {
                 $blocked[] = $linkid;
             } else {
                 // pre zk1.2 check
                 if (!isset($link['id'])) {
                     $link['id'] = $linkid;
                 }
                 $link['url'] = ModUtil::apiFunc('Blocks', 'user', 'encodebracketurl', $link['url']);
                 // check for multiple options in image
                 $this->checkImage($link);
                 $menuitems[] = $link;
             }
         }
     }
     // Modules
     if (!empty($vars['displaymodules'])) {
         $newmods = ModUtil::getUserMods();
         $mods = array();
         foreach ($newmods as $module) {
             if (!preg_match('#(?:error|blocks)#', strtolower($module['name']))) {
                 $mods[] = $module;
             }
         }
         // Separate from current content, if any
         if (count($menuitems) > 0) {
             $menuitems[] = array('name' => ' ', 'url' => '', 'title' => '', 'level' => 0, 'parentid' => null, 'image' => '');
             if (SecurityUtil::checkPermission('ExtendedMenublock::', $blockinfo['bid'] . '::', ACCESS_ADMIN)) {
                 $menuitems[] = array('name' => $this->__('--Installed modules--'), 'url' => ModUtil::url('Blocks', 'admin', 'modify', array('bid' => $blockinfo['bid'])), 'title' => '', 'level' => 0, 'parentid' => null, 'image' => '');
             }
         }
         foreach ($mods as $mod) {
             // prepare image
             if (SecurityUtil::checkPermission("{$mod['name']}::", '::', ACCESS_OVERVIEW)) {
                 $menuitems[] = array('name' => $mod['displayname'], 'url' => ModUtil::url($mod['name'], 'user', 'main'), 'title' => $mod['description'], 'level' => 0, 'parentid' => null, 'image' => '');
             }
         }
     }
     // check for any empty result set
     if (empty($menuitems)) {
         return;
     }
     $currenturi = urlencode(str_replace(System::getBaseUri() . '/', '', System::getCurrentUri()));
     // assign the items
     $this->view->assign('menuitems', $menuitems)->assign('blockinfo', $blockinfo)->assign('currenturi', $currenturi)->assign('access_edit', Securityutil::checkPermission('ExtendedMenublock::', $blockinfo['bid'] . '::', ACCESS_EDIT));
     // get the block content
     $blockinfo['content'] = $this->view->fetch($vars['template']);
     // pass the block array back to the theme for display
     return BlockUtil::themeBlock($blockinfo);
 }
Example #3
0
    /**
     * display block
     */
    public function display($blockinfo)
    {
        // Security check
        if (!Securityutil::checkPermission('Menutree:menutreeblock:', "{$blockinfo['bid']}::", ACCESS_READ)) {
            return false;
        }

        // Get variables from content block
        $vars = BlockUtil::varsFromContent($blockinfo['content']);

        // stylesheet
        if (file_exists($vars['menutree_stylesheet'])) {
            PageUtil::addVar('stylesheet', $vars['menutree_stylesheet']);
        }

        // template to use
        if (!isset($vars['menutree_tpl']) || empty($vars['menutree_tpl']) || !$this->view->template_exists($vars['menutree_tpl'])) {
            $vars['menutree_tpl'] = 'menutree/blocks_block_menutree_default.tpl';
        }

        // 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($vars['menutree_tpl'])) {
                $blockinfo['content'] = $this->view->fetch($vars['menutree_tpl']);

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

        // set default block vars
        $vars['menutree_content']    = isset($vars['menutree_content']) ? $vars['menutree_content'] : array();
        $vars['menutree_titles']     = isset($vars['menutree_titles']) ? $vars['menutree_titles'] : array();
        $vars['menutree_stylesheet'] = isset($vars['menutree_stylesheet']) ? $vars['menutree_stylesheet'] : '';
        $vars['menutree_editlinks']  = isset($vars['menutree_editlinks']) ? $vars['menutree_editlinks'] : false;

        // set current user lang
        $lang = ZLanguage::getLanguageCode();
        $deflang = 'en';

        if (!in_array($lang, array_keys(current($vars['menutree_content'])))) {
            $lang = $deflang;
        }

        if (!empty($vars['menutree_content'])) {
            // select current lang, check permissions for each item and exclude unactive nodes
            $newTree = array();
            $blocked = array();
            foreach ($vars['menutree_content'] as $id => $item) {
                $item = $item[$lang];
                // check the permission access to the current link
                $hasperms = Securityutil::checkPermission('Menutree:menutreeblock:',"$blockinfo[bid]:$item[name]:$item[id]", ACCESS_READ);
                // checks if has no access to it or the link is not active
                if (!$hasperms || in_array($item['parent'], $blocked) || $item['state'] != 1) {
                    $blocked[] = $item['id'];
                } else {
                    // dynamic components
                    if (strpos($item['href'],'{ext:') === 0) {
                        $dynamic = explode(':', substr($item['href'], 1,  - 1));
                        $modname = $dynamic[1];
                        $func = $dynamic[2]; // plugin
                        $extrainfo = (isset($dynamic[3]) && !empty($dynamic[3])) ? $dynamic[3] : null;
                        if (!empty($modname) && !empty($func)) {
                            $args = array(
                                    'item' => $item,
                                    'lang' => $lang,
                                    'bid' => $blockinfo['bid'],
                                    'extrainfo' => $extrainfo,
                            );
                            $node = ModUtil::apiFunc($modname, 'menutree', $func, $args);
                            if (!is_array($node)) {
                                $node = array(array($lang => $item));
                            }
                        }
                    } else {
                        $node = array(array($lang => $item));
                    }
                    $newTree = array_merge($newTree,(array)$node);
                }
            }

            // bulid structured array
            $langs = array('ref' => $lang,
                           'list' => $lang,
                           'flat' => true);

            $tree = new Blocks_MenutreeTree();
            $tree->setOption('langs',(array)$langs['list']);
            $tree->setOption('flat',$langs['flat']);
            $tree->setOption('parseURL',true);
            $tree->loadArrayData($newTree);

            $newTree = $tree->getData();
        } else {
            $newTree = array();
        }

        // block title
        if (!empty($vars['menutree_titles'][$lang])) {
            $blockinfo['title'] = $vars['menutree_titles'][$lang];
        }

        $this->view->assign('menutree_editlinks', $vars['menutree_editlinks'] && Securityutil::checkPermission('Blocks::', "$blockinfo[bkey]:$blockinfo[title]:$blockinfo[bid]", ACCESS_EDIT))
                   ->assign('menutree_content', $newTree)
                   ->assign('blockinfo', $blockinfo);

        $blockinfo['content'] = $this->view->fetch($vars['menutree_tpl']);

        return BlockUtil::themeBlock($blockinfo);
    }
Example #4
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);
    }