/** * 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'); }
/** * display block * @author The Zikula Development Team */ public function display($blockinfo) { // security check if (!SecurityUtil::checkPermission('Quotes:Quoteblock:', $blockinfo['bid'] . '::', ACCESS_READ)) { return; } // Get current content $vars = BlockUtil::varsFromContent($blockinfo['content']); // filter desplay by hour of the day: @nikp $a_datetime = getdate(); if (isset($vars['hourfrom']) and $vars['hourfrom'] > -1 and $a_datetime["hours"] < $vars['hourfrom']) { return ""; } if (isset($vars['hourto']) and $vars['hourto'] > -1 and $a_datetime["hours"] > $vars['hourto']) { return ""; } if (isset($vars['wdayfrom']) and $vars['wdayfrom'] > -1 and $a_datetime["wday"] < $vars['wdayfrom']) { return ""; } if (isset($vars['wdayto']) and $vars['wdayto'] > -1 and $a_datetime["wday"] > $vars['wdayto']) { return ""; } if (isset($vars['mdayfrom']) and $vars['mdayfrom'] > -1 and $a_datetime["mday"] < $vars['mdayfrom']) { return ""; } if (isset($vars['mdayto']) and $vars['mdayto'] > -1 and $a_datetime["mday"] > $vars['mdayto']) { return ""; } if (isset($vars['monfrom']) and $vars['monfrom'] > -1 and $a_datetime["mon"] < $vars['monfrom']) { return ""; } if (isset($vars['monto']) and $vars['monto'] > -1 and $a_datetime["mon"] > $vars['monto']) { return ""; } if (!isset($vars['category'])) { $vars['category'] = null; } if (isset($vars['ballooncolor'])) { $ballooncolor = $vars['ballooncolor']; } else { $ballooncolor = "grey"; } // Implementation cached content: @nikp $enable_cache = true; $write_to_cache = false; # flag $cache_time = 240; # seconds if (isset($vars['cache_time'])) { $cache_time = $vars['cache_time']; } $content = ""; if ($enable_cache and $cache_time > 0) { $cachefilestem = 'quote_' . $blockinfo['bid']; $cachedir = System::getVar('temp'); if (StringUtil::right($cachedir, 1) != '/') { $cachedir .= '/'; } if (isset($vars['cache_dir']) and !empty($vars['cache_dir'])) { $cachedir .= $vars['cache_dir']; } else { $cachedir .= 'any_cache'; } $cachefile = $cachedir . '/' . $cachefilestem . '_' . SecurityUtil::getSecurityLevel(SecurityUtil::getAuthInfo(), 'Quotes::', '::'); // attempt to load from cache if (file_exists($cachefile)) { $file_time = filectime($cachefile); $now = time(); $diff = $now - $file_time; if ($diff <= $cache_time) { $content = file_get_contents($cachefile); } } if (empty($content)) { $write_to_cache = true; # not loaded, flag to write to cache later } } if (empty($content)) { // Create output object $this->view->setCaching(false); // we implement caching other way mt_srand((double) microtime() * 1000000); $apiargs = array(); $apiargs['status'] = 1; // Make a category filter only if categorization is enabled $enablecategorization = ModUtil::getVar($this->name, 'enablecategorization'); if ($enablecategorization) { // load the categories system if (!Loader::loadClass('CategoryRegistryUtil')) { return LogUtil::registerError(__f('Error! Could not load [%s] class.'), 'CategoryRegistryUtil'); } // Get the registrered categories for the module $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories($this->name, 'quotes'); $this->view->assign('catregistry', $catregistry); $apiargs['catregistry'] = $catregistry; $apiargs['category'] = $vars['category']; } $this->view->assign('enablecategorization', $enablecategorization); $this->view->assign($vars); // assign the block vars if (!isset($vars['category']) || !is_array($vars['category'])) { $vars['category'] = array(); } $this->view->assign('category', $vars['category']); $quote = ModUtil::apiFunc($this->name, 'user', 'getrandom', $apiargs); $this->view->assign('quote', $quote); $this->view->assign('bid', $blockinfo['bid']); $this->view->assign('ballooncolor', $ballooncolor); $content = $this->view->fetch('quotes_block_quote.tpl'); # get the block output from the template } if ($write_to_cache and !empty($content)) { // attempt to write to cache if not loaded before if (!file_exists($cachedir)) { mkdir($cachedir, 0777); # attempt to make the dir } if (!file_put_contents($cachefile, $content)) { //echo "<br />Could not save data to cache. Please make sure your cache directory exists and is writable.<br />"; } } $blockinfo['content'] = $content; // return the rendered block return BlockUtil::themeBlock($blockinfo); }
/** * calculate security level for a test item * * @deprecated * @see SecurityUtil::getSecurityLevel * @param perms $ array of permissions to test against * @param testrealm $ realm of item under test * @param testcomponent $ component of item under test * @param testinstance $ instance of item under test * @return int matching security level */ function pnSecGetLevel($perms, $testrealm, $testcomponent, $testinstance) { LogUtil::log(__f('Warning! Function %1$s is deprecated. Please use %2$s instead.', array( 'pnSecGetLevel()', 'SecurityUtil::getSecurityLevel()')), E_USER_DEPRECATED); return SecurityUtil::getSecurityLevel($perms, $testcomponent, $testinstance); }
/** * display block * @author The Zikula Development Team */ public function display($blockinfo) { // security check if (!SecurityUtil::checkPermission('Ephemerides:Ephemerideblock:', $blockinfo['bid'] . '::', ACCESS_READ)) { return; } // Get current content $vars = BlockUtil::varsFromContent($blockinfo['content']); if (!isset($vars['category'])) { $vars['category'] = null; } // Implementation cached content: @nikp $enable_cache = true; $write_to_cache = false; # flag $cache_time = 3600; # seconds if (isset($vars['cache_time'])) { $cache_time = $vars['cache_time']; } $content = ""; $title = $blockinfo['title']; if ($enable_cache and $cache_time > 0) { $cachefilestem = 'ephem_' . $blockinfo['bid']; $cachedir = System::getVar('temp'); if (StringUtil::right($cachedir, 1) != '/') { $cachedir .= '/'; } if (isset($vars['cache_dir']) and !empty($vars['cache_dir'])) { $cachedir .= $vars['cache_dir']; } else { $cachedir .= 'any_cache'; } $cachefile = $cachedir . '/' . $cachefilestem . '_' . SecurityUtil::getSecurityLevel(SecurityUtil::getAuthInfo(), 'Ephemerides::', '::'); $cachefile_title = $cachedir . '/' . $cachefilestem . '_t'; // attempt to load from cache if (file_exists($cachefile)) { $file_time = filectime($cachefile); $now = time(); $diff = $now - $file_time; if ($diff <= $cache_time) { $content = file_get_contents($cachefile); } if (file_exists($cachefile_title)) { $title = file_get_contents($cachefile_title); } } if (empty($content)) { $write_to_cache = true; } # not loaded, flag to write to cache later } if (empty($content)) { // Create output object $this->view->setCaching(false); // we implement caching other way $apiargs = array(); $apiargs['status'] = 1; // Make a category filter only if categorization is enabled $enablecategorization = ModUtil::getVar($this->name, 'enablecategorization'); if ($enablecategorization) { // load the categories system if (!Loader::loadClass('CategoryRegistryUtil')) { return LogUtil::registerError(__f('Error! Could not load [%s] class.'), 'CategoryRegistryUtil'); } // Get the registrered categories for the module $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories($this->name, 'ephem'); $this->view->assign('catregistry', $catregistry); $apiargs['catregistry'] = $catregistry; $apiargs['category'] = $vars['category']; } $this->view->assign('enablecategorization', $enablecategorization); $this->view->assign($vars); // assign the block vars if (!isset($vars['category']) || !is_array($vars['category'])) { $vars['category'] = array(); } $this->view->assign('category', $vars['category']); // get items $items = ModUtil::apiFunc($this->name, 'user', 'gettoday', $apiargs); if (!$items) { return ''; # do not display empty block: @nikp } $this->view->assign('items', $items); // Populate block info and pass to theme $content = $this->view->fetch('ephemerides_block_ephemeride.tpl'); // loop to see if we have items of type=1 (events), if not - not to put title to the block (holidays only) $have_events = false; foreach ($items as $item) { if ($item['type'] == 1) { $have_events = true; break; } } if (!$have_events) { $title = ""; } } if ($write_to_cache and !empty($content)) { // attempt to write to cache if not loaded before if (!file_exists($cachedir)) { mkdir($cachedir, 0777); # attempt to make the dir } if (file_put_contents($cachefile, $content)) { file_put_contents($cachefile_title, $title); } else { //echo "<br />Could not save data to cache. Please make sure your cache directory exists and is writable.<br />"; } } $blockinfo['content'] = $content; $blockinfo['title'] = $title; // return the rendered block return BlockUtil::themeBlock($blockinfo); }