public static function var_export_die($var) { zphp_load_library('navigation'); NavigationHelper::header_content_text_plain(); die(var_export($var, true)); }
protected function _buildCountQuery($uri, $setup) { $query = new Erfurt_Sparql_Query2(); $query->addProjectionVar(new Erfurt_Sparql_Query2_Var('resourceUri')); $query->setCountStar(true); $query->setDistinct(); $query->addElements(NavigationHelper::getInstancesTriples($uri, $setup)); // error logging $this->_owApp->logger->info('NavigationController: COUNTQUERY: ' . $query->__toString()); //*/ return $query; }
/** * RouteShutdown is the earliest event in the dispatch cycle, where a * fully routed request object is available */ public function routeShutdown(Zend_Controller_Request_Abstract $request) { if (isset($request->noListRedirect)) { return; } $ontoWiki = OntoWiki::getInstance(); // TODO: Refactor! The list helper is from an extension! Do not access extensions // from core code! if (!Zend_Controller_Action_HelperBroker::hasHelper('List')) { return; } $listHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('List'); // only once and only when possible if (!$this->_isSetup && $ontoWiki->selectedModel != null && (isset($request->init) || isset($request->instancesconfig) || isset($request->s) || isset($request->class) || isset($request->p) || isset($request->limit))) { $frontController = Zend_Controller_Front::getInstance(); $store = $ontoWiki->erfurt->getStore(); $resource = $ontoWiki->selectedResource; $session = $ontoWiki->session; // when switching to another class: // reset session vars (regarding the list) if (isset($request->init)) { //echo 'kill list session'; // reset the instances object unset($session->instances); //reset config from tag explorer unset($session->cloudproperties); } //react on m parameter to set the selected model if (isset($request->m)) { try { $model = $store->getModel($request->getParam('m', null, false)); $ontoWiki->selectedModel = $model; } catch (Erfurt_Store_Exception $e) { $model = null; $ontoWiki->selectedModel = null; } } $list = $listHelper->getLastList(); if (!isset($request->list) && $list == null || isset($request->init)) { // instantiate model, that selects all resources $list = new OntoWiki_Model_Instances($store, $ontoWiki->selectedModel, array()); } else { // use the object from the session if (isset($request->list) && $request->list != $listHelper->getLastListName()) { if ($listHelper->listExists($request->list)) { $list = $listHelper->getList($request->list); $ontoWiki->appendMessage(new OntoWiki_Message('reuse list')); } else { throw new OntoWiki_Exception('your trying to configure a list, but there is no list name specified'); } } $list->setStore($store); // store is not serialized in session! reset it } //local function :) function _json_decode($string) { /* PHP 5.3 DEPRECATED ; REMOVE IN PHP 6.0 */ if (get_magic_quotes_gpc()) { // add slashes for unicode chars in json $string = str_replace('\\u', '\\\\u', $string); //$string = str_replace('\\u000a','', $string); $string = stripslashes($string); } /* ---- */ return json_decode($string, true); } //a shortcut for search param if (isset($request->s)) { if (isset($request->instancesconfig)) { $config = _json_decode($request->instancesconfig); if (null === $config) { throw new OntoWiki_Exception('Invalid parameter instancesconfig (json_decode failed): ' . $this->_request->setup); } } else { $config = array(); } if (!isset($config['filter'])) { $config['filter'] = array(); } $config['filter'][] = array('action' => 'add', 'mode' => 'search', 'searchText' => $request->s); $request->setParam('instancesconfig', json_encode($config)); } //a shortcut for class param if (isset($request->class)) { if (isset($request->instancesconfig)) { $config = _json_decode($request->instancesconfig); if (null === $config) { throw new OntoWiki_Exception('Invalid parameter instancesconfig (json_decode failed): ' . $this->_request->setup); } } else { $config = array(); } if (!isset($config['filter'])) { $config['filter'] = array(); } $config['filter'][] = array('action' => 'add', 'mode' => 'rdfsclass', 'rdfsclass' => $request->class); $request->setParam('instancesconfig', json_encode($config)); } //check for change-requests if (isset($request->instancesconfig)) { $config = _json_decode($request->instancesconfig); if (null === $config) { throw new OntoWiki_Exception('Invalid parameter instancesconfig (json_decode failed)'); } // TODO is this a bug? why access sort->asc when it is null? if (isset($config['sort'])) { if ($config['sort'] == null) { $list->orderByUri($config['sort']['asc']); } else { $list->setOrderProperty($config['sort']['uri'], $config['sort']['asc']); } } if (isset($config['shownProperties'])) { foreach ($config['shownProperties'] as $prop) { if ($prop['action'] == 'add') { $list->addShownProperty($prop['uri'], $prop['label'], $prop['inverse']); } else { $list->removeShownProperty($prop['uri'], $prop['inverse']); } } } if (isset($config['filter'])) { foreach ($config['filter'] as $filter) { // set default value for action and mode if they're not assigned if (!isset($filter['action'])) { $filter['action'] = 'add'; } if (!isset($filter['mode'])) { $filter['mode'] = 'box'; } if ($filter['action'] == 'add') { if ($filter['mode'] == 'box') { $list->addFilter($filter['property'], isset($filter['isInverse']) ? $filter['isInverse'] : false, isset($filter['propertyLabel']) ? $filter['propertyLabel'] : 'defaultLabel', $filter['filter'], isset($filter['value1']) ? $filter['value1'] : null, isset($filter['value2']) ? $filter['value2'] : null, isset($filter['valuetype']) ? $filter['valuetype'] : 'literal', isset($filter['literaltype']) ? $filter['literaltype'] : null, isset($filter['hidden']) ? $filter['hidden'] : false, isset($filter['id']) ? $filter['id'] : null, isset($filter['negate']) ? $filter['negate'] : false); } else { if ($filter['mode'] == 'search') { $list->addSearchFilter($filter['searchText'], isset($filter['id']) ? $filter['id'] : null); } else { if ($filter['mode'] == 'rdfsclass') { $list->addTypeFilter($filter['rdfsclass'], isset($filter['id']) ? $filter['id'] : null); } else { if ($filter['mode'] == 'cnav') { $list->addTripleFilter(NavigationHelper::getInstancesTriples($filter['uri'], $filter['cnav']), isset($filter['id']) ? $filter['id'] : null); } else { if ($filter['mode'] == 'query') { try { //echo $filter->query." "; $query = Erfurt_Sparql_Query2::initFromString($filter['query']); // TODO what the hell is this?! if (!$query instanceof Exception) { $list->addTripleFilter($query->getWhere()->getElements(), isset($filter['id']) ? $filter['id'] : null); } //echo $query->getSparql(); } catch (Erfurt_Sparql_ParserException $e) { $ontoWiki->appendMessage('the query could not be parsed'); } } } } } } } else { $list->removeFilter($filter['id']); } } } if (isset($config['order'])) { foreach ($config['order'] as $prop) { if ($prop['action'] == 'set') { if ($prop['mode'] == 'var') { $list->setOrderVar($prop['var']); } else { $list->setOrderUri($prop['uri']); } } } } } if (isset($request->limit)) { // how many results per page $list->setLimit($request->limit); } else { $list->setLimit(10); } if (isset($request->p)) { // p is the page number $list->setOffset($request->p * $list->getLimit() - $list->getLimit()); } else { $list->setOffset(0); } //save to session $name = isset($request->list) ? $request->list : 'instances'; $listHelper->updateList($name, $list, true); // avoid setting up twice $this->_isSetup = true; // redirect normal requests if config-params are given to a param-free uri // (so a browser reload by user does nothing unwanted) if (!$request->isXmlHttpRequest()) { //strip of url parameters that modify the list $url = new OntoWiki_Url(array(), null, array('init', 'instancesconfig', 's', 'p', 'limit', 'class', 'list')); //redirect $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $redirector->gotoUrl($url); } } }
/** * indexAction * @author Cornelius Hansjakob <*****@*****.**> * @version 1.0 */ public function indexAction() { $this->view->addFilter('PageReplacer'); /** * get uri */ $strUrl = $_SERVER['REQUEST_URI']; if (preg_match('/^\\/[a-zA-Z\\-]{2,5}\\//', $strUrl)) { $strUrl = preg_replace('/^\\/[a-zA-Z\\-]{2,5}\\//', '', $strUrl); } else { $strUrl = preg_replace('/^\\//', '', $strUrl); } // load theme $this->loadTheme(); // check portal security $this->checkPortalSecuirty(); // validate language $this->validateLanguage(); // set translate $this->setTranslate(); // init page cache $this->initPageCache($strUrl); /** * check if "q" param is in the url for the search */ if (strpos($strUrl, '?q=') !== false) { $this->blnSearch = true; $strUrl = ''; } // check, if cached page exists if ($this->core->sysConfig->cache->page == 'false' || $this->core->sysConfig->cache->page == 'true' && $this->objCache->test($this->strCacheId) == false || $this->core->sysConfig->cache->page == 'true' && isset($_SESSION['sesTestMode'])) { $this->getModelUrls(); $this->getModelPages(); if (file_exists(GLOBAL_ROOT_PATH . 'client/website/navigation.class.php')) { require_once GLOBAL_ROOT_PATH . 'client/website/navigation.class.php'; $objNavigation = new Client_Navigation(); } else { $objNavigation = new Navigation(); } $objNavigation->setRootLevelId($this->objTheme->idRootLevels); $objNavigation->setLanguageId($this->intLanguageId); if (file_exists(GLOBAL_ROOT_PATH . 'public/website/themes/' . $this->objTheme->path . '/helpers/NavigationHelper.php')) { require_once GLOBAL_ROOT_PATH . 'public/website/themes/' . $this->objTheme->path . '/helpers/NavigationHelper.php'; $strNavigationHelper = ucfirst($this->objTheme->path) . '_NavigationHelper'; $objNavigationHelper = new $strNavigationHelper(); } else { require_once dirname(__FILE__) . '/../helpers/NavigationHelper.php'; $objNavigationHelper = new NavigationHelper(); } $objNavigationHelper->setNavigation($objNavigation); $objNavigationHelper->setTranslate($this->translate); Zend_Registry::set('NavigationHelper', $objNavigationHelper); $objUrl = $this->objModelUrls->loadByUrl($this->objTheme->idRootLevels, parse_url($strUrl, PHP_URL_PATH) === null ? '' : parse_url($strUrl, PHP_URL_PATH)); if (isset($objUrl->url) && count($objUrl->url) > 0) { $objUrlData = $objUrl->url->current(); // check if url is main if (!$objUrlData->isMain) { $objMainUrl = $this->objModelUrls->loadUrl($objUrlData->relationId, $objUrlData->version, $objUrlData->idUrlTypes); if (count($objMainUrl) > 0) { $objMainUrl = $objMainUrl->current(); $this->getResponse()->setHeader('HTTP/1.1', '301 Moved Permanently'); $this->getResponse()->setHeader('Status', '301 Moved Permanently'); $this->getResponse()->setHttpResponseCode(301); $this->_redirect('/' . strtolower($objMainUrl->languageCode) . '/' . $objMainUrl->url); } } if ($this->core->sysConfig->cache->page == 'true' && !isset($_SESSION['sesTestMode']) && $this->blnSearch == false && (!isset($_POST) || count($_POST) == 0)) { $this->objCache->start($this->strCacheId); $this->blnCachingStart = true; } if (file_exists(GLOBAL_ROOT_PATH . 'client/website/page.class.php')) { require_once GLOBAL_ROOT_PATH . 'client/website/page.class.php'; $this->objPage = new Client_Page(); } else { $this->objPage = new Page(); } $this->objPage->setRootLevelId($this->objTheme->idRootLevels); $this->objPage->setRootLevelTitle($this->core->blnIsDefaultLanguage === true ? $this->objTheme->defaultTitle : $this->objTheme->title); $this->objPage->setRootLevelGroupId($this->objTheme->idRootLevelGroups); $this->objPage->setPageId($objUrlData->relationId); $this->objPage->setPageVersion($objUrlData->version); $this->objPage->setLanguageId($objUrlData->idLanguages); switch ($objUrlData->idUrlTypes) { case $this->core->sysConfig->url_types->page: $this->objPage->setType('page'); $this->objPage->setModelSubPath('cms/models/'); break; case $this->core->sysConfig->url_types->global: $this->objPage->setType('global'); $this->objPage->setModelSubPath('global/models/'); $this->objPage->setElementLinkId($objUrlData->idLink); $this->objPage->setNavParentId($objUrlData->idLinkParent); $this->objPage->setPageLinkId($objUrlData->linkId); break; } /** * preset navigation parent properties * e.g. is a collection page */ if ($objUrlData->idParent !== null) { $this->objPage->setNavParentId($objUrlData->idParent); $this->objPage->setNavParentTypeId($objUrlData->idParentTypes); } /** * has base url object * e.g. prduct tree */ if (isset($objUrl->baseUrl)) { $objNavigation->setBaseUrl($objUrl->baseUrl); $this->objPage->setBaseUrl($objUrl->baseUrl); $this->objPage->setNavParentId($objUrlData->idLinkParent); } $this->objPage->loadPage(); /** * check status */ if ($this->objPage->getStatus() != $this->core->sysConfig->status->live && (!isset($_SESSION['sesTestMode']) || isset($_SESSION['sesTestMode']) && $_SESSION['sesTestMode'] == false)) { $this->_redirect('/'); } if ($this->objPage->ParentPage() instanceof Page) { $objNavigation->setPage($this->objPage->ParentPage()); } else { $objNavigation->setPage($this->objPage); } /** * check page security */ if ($objNavigation->secuirtyZoneCheck()) { // deactivate caching $this->blnCachingStart = false; $objAuth = Zend_Auth::getInstance(); if (!Zend_Auth::getInstance()->hasIdentity()) { $this->_redirect('/login?re=' . urlencode($_SERVER['REQUEST_URI'])); } else { if (!$objNavigation->checkZonePrivileges()) { $this->getResponse()->setHeader('HTTP/1.1', '403 Forbidden'); $this->getResponse()->setHeader('Status', '403 Forbidden'); $this->getResponse()->setHttpResponseCode(401); $this->strRenderScript = 'error-403.php'; } } } /** * set values for replacers */ Zend_Registry::set('TemplateCss', $this->objPage->getTemplateId() == $this->core->sysConfig->page_types->page->portal_startpage_templateId ? '' : ''); Zend_Registry::set('TemplateJs', $this->objPage->getTemplateId() == $this->core->sysConfig->page_types->page->headquarters_templateId ? '<script src="http://maps.google.com/maps?file=api&v=2&key=' . $this->view->mapsKey . '" type="text/javascript"></script>' : ''); if (file_exists(GLOBAL_ROOT_PATH . 'public/website/themes/' . $this->objTheme->path . '/helpers/PageHelper.php')) { require_once GLOBAL_ROOT_PATH . 'public/website/themes/' . $this->objTheme->path . '/helpers/PageHelper.php'; $strPageHelper = ucfirst($this->objTheme->path) . '_PageHelper'; $objPageHelper = new $strPageHelper(); } else { require_once dirname(__FILE__) . '/../helpers/PageHelper.php'; $objPageHelper = new PageHelper(); } $objPageHelper->setTheme($this->objTheme->path); $objPageHelper->setPage($this->objPage); $objPageHelper->setTranslate($this->translate); Zend_Registry::set('PageHelper', $objPageHelper); /** * forward to SearchController */ if ($this->blnSearch == true) { $this->_forward('index', 'Search', null, array('rootLevelId' => $this->objPage->getRootLevelId(), 'theme' => $this->objTheme->path)); } else { /** * get page template filename */ $this->view->template = $this->objPage->getTemplateFile(); $this->view->publisher = $this->objPage->getPublisherName(); $this->view->publishdate = $this->objPage->getPublishDate(); $this->view->setScriptPath(GLOBAL_ROOT_PATH . 'public/website/themes/' . $this->objTheme->path . '/'); $this->renderScript($this->strRenderScript); } } else { // try url with/without slash redirect or error output $this->urlRetryRedirectAndError($strUrl); } } else { $this->blnCachingOutput = true; $this->getResponse()->setBody($this->objCache->load($this->strCacheId)); $this->_helper->viewRenderer->setNoRender(); } }