/** * 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); }
/** * Modify Theme settings. */ public function modifyconfig() { // Security check if (!SecurityUtil::checkPermission('Theme::', '::', ACCESS_EDIT)) { return LogUtil::registerPermissionError(); } // assign a list of modules suitable for html_options $usermods = ModUtil::getUserMods(); $mods = array(); foreach ($usermods as $usermod) { $mods[$usermod['name']] = $usermod['displayname']; } // register the renderer object allow access to various view values $this->view->register_object('render', $this->view); // check for a .htaccess file if (file_exists('.htaccess')) { $this->view->assign('htaccess', 1); } else { $this->view->assign('htaccess', 0); } // assign the output variables and fetch the template return $this->view->assign('mods', $mods) // assign all module vars ->assign($this->getVars()) // assign an csrftoken for the clear cache/compile links ->assign('csrftoken', SecurityUtil::generateCsrfToken($this->serviceManager, true)) // assign the core config var ->assign('theme_change', System::getVar('theme_change')) // extracted list of non-cached mods ->assign('modulesnocache', array_flip(explode(',', $this->getVar('modulesnocache')))) ->fetch('theme_admin_modifyconfig.tpl'); }
/** * Convert data of selected menu to menutree style * Used to import menus */ private function _import_menu($bid) { if ((!isset($bid)) || (isset($bid) && !is_numeric($bid))) { return; } $menu = BlockUtil::getBlockInfo($bid); $menuVars = BlockUtil::varsFromContent($menu['content']); $userlanguage = ZLanguage::getLanguageCode(); $menuType = strtolower($menu['bkey']); switch ($menuType) { case 'menutree': $data = isset($menuVars['menutree_content']) ? $menuVars['menutree_content'] : array(); break; case 'menu': if (isset($menuVars['content']) && !empty($menuVars['content'])) { $reflang = $userlanguage; $pid = 1; $data = array(); $contentlines = explode('LINESPLIT', $menuVars['content']); foreach ($contentlines as $lineno => $contentline) { list($href, $name, $title) = explode('|', $contentline); if (!empty($name)) { $className = ''; $parent = 0; $state = 1; $lang = $reflang; $id = $pid; $data[$lineno][$reflang] = compact('href','name','title','className','parent','state','lang','lineno','id'); $pid++; } } $langs = (array)$reflang; $lineno++; } break; case 'extmenu': if (isset($menuVars['links']) && !empty($menuVars['links'])) { $langs = array_keys($menuVars['links']); $data = array(); foreach ($langs as $lang) { foreach ($menuVars['links'][$lang] as $id => $link) { $data[$id][$lang] = array( 'id' => $id + 1, 'name' => isset($link['name']) && !empty($link['name']) ? $link['name'] : $this->__('no name'), 'href' => isset($link['url']) ? $link['url'] : '', 'title' => isset($link['title']) ? $link['title'] : '', 'className' => '', 'state' => isset($link['active']) && $link['active'] && $link['name'] ? 1 : 0, 'lang' => $lang, 'lineno' => $id, 'parent' => 0 ); } } ksort($data); $pid = $id + 2; $lineno = count($data); } break; } if (!empty($menuVars['displaymodules'])) { $mods = ModUtil::getUserMods(); if (is_array($mods) && count($mods)>0) { foreach ($mods as $mod) { $tmp = array('name' => $mod['displayname'], 'href' => DataUtil::formatForDisplay(ModUtil::url($mod['name'], 'user', 'main')), 'title' => $mod['description']); foreach ($langs as $lang) { $tmp = array_merge($tmp, array('className' => '', 'parent' => 0, 'lang' => $lang, 'state' => 1, 'lineno' => $lineno, 'id' => $pid)); $tmparray[$lang] = $tmp; } $data[] = $tmparray; $pid++; $lineno++; } } } return $data; }
/** * 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); }
/** * The pnModGetUserMods function gets a list of user modules. * * @deprecated * @see ModUtil::getUserMods() * * @return array An array of module information arrays. */ function pnModGetUserMods() { LogUtil::log(__f('Warning! Function %1$s is deprecated. Please use %2$s instead.', array(__FUNCTION__, 'ModUtil::getUserMods()')), E_USER_DEPRECATED); return ModUtil::getUserMods(); }
/** * Return list of user modules * * Syntax used in menutree * {ext:Blocks:modules:[flat]} * Last param is optional * * @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 modules($args) { $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; $links = array(); // if $extrainfo if 'flat' - don't group links if ($extrainfo != 'flat') { $links['modules'] = array($lang => array('id' => $idoffset++, 'name' => $item['name'], 'href' => '', '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['modules'][$lang]['id'] : $item['parent']; $mods = ModUtil::getUserMods(); foreach ($mods as $mod) { if (SecurityUtil::checkPermission("{$mod['name']}::", '::', ACCESS_OVERVIEW)) { $links[] = array($lang => array('id' => $idoffset++, 'name' => $mod['displayname'], 'href' => ModUtil::url($mod['name'], 'user', 'main'), 'title' => $mod['description'], 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode)); } } return $links; }