/** * Constructor */ public function __construct($root, $config = null) { // init view if (null === $this->view) { $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); if (null === $viewRenderer->view) { $viewRenderer->initView(); } $this->view = clone $viewRenderer->view; $this->view->clearVars(); } $this->_pluginUrlBase = OntoWiki::getInstance()->getStaticUrlBase() . str_replace(ONTOWIKI_ROOT, '', $root); parent::__construct($root, $config); }
/** * Constructor * * @param string $text * @param string $type */ public function __construct($text, $type = self::INFO, $options = array()) { $this->_options = array_merge(array('escape' => true, 'translate' => true), $options); $this->_type = $type; $this->_text = $text; // Clone view if (null === $this->_view) { $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); if (null === $viewRenderer->view) { $viewRenderer->initView(); } $this->_view = clone $viewRenderer->view; $this->_view->clearVars(); } // get translation for current language $this->_translate = OntoWiki::getInstance()->translate; }
/** * Module view helper. * * Returns an OntoWiki module either rendered or from cache. * * Fetches the module from the module registry and renders it into the * window template. If a rendering exists in the local module cache it * is used instead. * * @param string $moduleName * @param array $moduleOptions An associative array or and instance of * Zend_config with module options. * The following keys can be used: * enabled – whether the module is enabled or disabled * title – the module window's title * caching – whether the module should be cached * priority – priority of the module in the module contexts * lower number means higher priority * classes – string of css classes for the module window * id – a css id for the module window * * @return string */ public function module($moduleName, $renderOptions = null, $context = OntoWiki_Module_Registry::DEFAULT_CONTEXT) { $moduleRegistry = OntoWiki_Module_Registry::getInstance(); // allow old-style array config if (is_array($renderOptions)) { $renderOptions = new Zend_Config($renderOptions); } // get default options from the registry $defaultModuleOptions = $moduleRegistry->getModuleConfig($moduleName); if ($defaultModuleOptions == null) { $moduleOptions = $renderOptions; } else { if ($renderOptions != null) { $moduleOptions = $defaultModuleOptions->merge($renderOptions); } else { $moduleOptions = $defaultModuleOptions; } } $cssClasses = isset($moduleOptions->classes) ? $moduleOptions->classes : ''; $cssId = isset($moduleOptions->id) ? $moduleOptions->id : ''; $module = $moduleRegistry->getModule($moduleName, $context); // no module found if (null == $module) { return ''; } $module->setOptions($moduleOptions); if ($module->shouldShow()) { // init module view if (null == $this->_moduleView) { $this->_moduleView = clone $this; } $this->_moduleView->clearVars(); // query module's title $this->_moduleView->title = $module->getTitle(); // does the module have a message // TODO: allow multiple messages if (method_exists($module, 'getMessage')) { if ($message = $module->getMessage()) { $this->_moduleView->messages = array($message); } } // does the module have a menu? if (method_exists($module, 'getMenu')) { $menu = $module->getMenu(); $this->_moduleView->menu = $menu->toArray(false, false); } // does the module have a context menu? if (method_exists($module, 'getContextMenu')) { $contextMenu = $module->getContextMenu(); if ($contextMenu instanceof OntoWiki_Menu) { $contextMenu = $contextMenu->toArray(); } $this->_moduleView->contextmenu = $contextMenu; } // is caching enabled if ($this->_moduleCache && $module->allowCaching()) { // get cache id $cacheId = md5($module->getCacheId() . $cssClasses . $this->_config->languages->locale); // cache hit? if (!($moduleContent = $this->_moduleCache->load($cacheId))) { // render (expensive) contents $pre = microtime(true); $moduleContent = $module->getContents(); $post = (microtime(true) - $pre) * 1000; // $this->_owApp->logger->info("Rendering module '$moduleName': $post ms (cache miss)"); // save to cache $this->_moduleCache->save($moduleContent, $cacheId, array('module', $moduleName), $module->getCacheLivetime()); } } else { // caching disabled $pre = microtime(true); $moduleContent = $module->getContents(); $post = (microtime(true) - $pre) * 1000; // $this->_owApp->logger->info("Rendering module '$moduleName': $post ms (caching disabled)"); } // implement tabs if (is_array($moduleContent)) { // TODO: tabs $navigation = array(); $content = array(); $i = 0; foreach ($moduleContent as $key => $content) { $navigation[$key] = array('active' => $i++ == 0 ? 'active' : '', 'url' => '#' . $key, 'name' => $this->_($key)); } $this->_moduleView->navigation = $navigation; $this->_moduleView->content = $moduleContent; } else { if (is_string($moduleContent)) { $this->_moduleView->content = $moduleContent; } } // set variables $this->_moduleView->cssClasses = $cssClasses; $this->_moduleView->cssId = $cssId; if (isset($moduleOptions->noChrome) && (bool) $moduleOptions->noChrome) { // render without window chrome $moduleWindow = $this->_moduleView->render('partials/module.phtml'); } else { // render with window chrome $moduleWindow = $this->_moduleView->render('partials/window.phtml'); } return $moduleWindow; } }