public function onAfterInitController($event) { //this extension should only run if no explicit model is given via request parameter "m" $request = new Zend_Controller_Request_Http(); if ($request->get("m")) { return; } $config = $this->_privateConfig->toArray(); $efApp = Erfurt_App::getInstance(); // disable model box if config value is true and modelmanangement isn't allowed if ($config['modelsHide'] && !$efApp->getAc()->isActionAllowed($config['modelsExclusiveRight'])) { $registry = OntoWiki_Module_Registry::getInstance(); $registry->disableModule('modellist', 'main.sidewindow'); } //only do this once (so if the model is changed later, this plugin will not prevent it) if ($config['setOnce'] && isset($_SESSION['defaultModelHasBeenSet']) && $_SESSION['defaultModelHasBeenSet']) { return; } $_SESSION['defaultModelHasBeenSet'] = true; require_once 'OntoWiki/Module/Registry.php'; $owApp = OntoWiki::getInstance(); $efStore = $efApp->getStore(); $availableModels = $efStore->getAvailableModels(); if (array_key_exists('modelUri', $config) && array_key_exists($config['modelUri'], $availableModels)) { $modelUri = $config['modelUri']; } elseif (count($availableModels) === 1) { $modelUri = current(array_keys($availableModels)); } else { $modelUri = false; } // set default model if it could be determined if ($modelUri && !$efApp->getAc()->isActionAllowed($config['modelsExclusiveRight'])) { if (!($owApp->selectedModel && $modelUri == $owApp->selectedModel->getModelUri())) { $owApp->selectedModel = $efStore->getModel($modelUri); return; } if ($config['setSelectedResource']) { $owApp->selectedResource = $modelUri; } } }
/** * Constructor */ public function __construct($extensionPath) { if (!(substr($extensionPath, -1) == DIRECTORY_SEPARATOR)) { $extensionPath .= DIRECTORY_SEPARATOR; } $this->_extensionPath = $extensionPath; OntoWiki_Module_Registry::reset(); //OntoWiki_Module_Registry::getInstance()->resetInstance(); $this->_moduleRegistry = OntoWiki_Module_Registry::getInstance(); $this->_moduleRegistry->setExtensionPath($extensionPath); //TODO nessesary? Erfurt_Wrapper_Registry::reset(); $this->_eventDispatcher = Erfurt_Event_Dispatcher::getInstance(); // scan for extensions $this->_scanExtensionPath(); // scan for translations $this->_scanTranslations(); // register for event $dispatcher = Erfurt_Event_Dispatcher::getInstance(); $dispatcher->register('onRouteShutdown', $this); }
/** * Menu Action to generate JSON serializations of OntoWiki_Menu for context-, module-, component-menus */ public function menuAction() { $module = $this->_request->getParam('module'); $resource = $this->_request->getParam('resource'); $model = $this->_request->getParam('model'); $translate = $this->_owApp->translate; // create empty menu first $menuRegistry = OntoWiki_Menu_Registry::getInstance(); if (!empty($resource)) { $menu = $menuRegistry->getMenu('resource', $resource); } else { if (!empty($model)) { $menu = $menuRegistry->getMenu('model', $model); } } if (!empty($module)) { $moduleRegistry = OntoWiki_Module_Registry::getInstance(); $menu = $moduleRegistry->getModule($module)->getContextMenu(); } // Fire a event; $event = new Erfurt_Event('onCreateMenu'); $event->menu = $menu; $event->resource = $resource; if (!empty($model)) { $event->isModel = true; $event->model = $model; } else { $event->model = $this->_owApp->selectedModel; } $event->trigger(); echo $menu->toJson(); }
public function setUp() { $this->_registry = OntoWiki_Module_Registry::getInstance(); }
/** * 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; } }