예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 /**
  * Returns the message's text
  *
  * @return string
  */
 public function getText()
 {
     $text = $this->_translate($this->_text);
     if (strlen($text) > 1000) {
         $text = substr($text, 0, 1000) . '...';
     }
     $text = $this->_options['escape'] ? $this->_view->escape($text) : $text;
     return $text;
 }
예제 #3
0
 /**
  * Sets up the view environment
  *
  * @since 0.9.5
  */
 public function _initView()
 {
     // require Config
     $this->bootstrap('Config');
     $config = $this->getResource('Config');
     // require Config
     $this->bootstrap('Translate');
     $translate = $this->getResource('Translate');
     // standard template path
     $defaultTemplatePath = ONTOWIKI_ROOT . 'application/views/templates';
     // path for theme template
     $themeTemplatePath = ONTOWIKI_ROOT . $config->themes->path . $config->themes->default . 'templates';
     $viewOptions = array('use_module_cache' => (bool) $config->cache->modules, 'cache_path' => $config->cache->path, 'lang' => $config->languages->locale);
     // init view
     $view = new OntoWiki_View($viewOptions, $translate);
     $view->addScriptPath($defaultTemplatePath)->addScriptPath($themeTemplatePath)->addScriptPath($config->extensions->base)->setEncoding($config->encoding)->setHelperPath(ONTOWIKI_ROOT . 'application/classes/OntoWiki/View/Helper', 'OntoWiki_View_Helper');
     // set Zend_View to emit notices in debug mode
     $view->strictVars(defined('_OWDEBUG'));
     // init view renderer action helper
     $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
     Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
     $themeLayoutTemplate = $themeTemplatePath . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . 'layout.phtml';
     $layoutPath = $defaultTemplatePath . DIRECTORY_SEPARATOR . 'layouts';
     if (is_readable($themeLayoutTemplate)) {
         $layoutPath = $themeTemplatePath . DIRECTORY_SEPARATOR . 'layouts';
     }
     // initialize layout
     Zend_Layout::startMvc(array('layoutPath' => $layoutPath));
     return $view;
 }
예제 #4
0
 /**
  * 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;
     }
 }