/** * indexAction * @author Cornelius Hansjakob <*****@*****.**> * @version 1.0 */ public function indexAction() { $this->view->addFilter('PageReplacer'); /** * get domain */ $strDomain = $_SERVER['SERVER_NAME']; /** * get uri */ $strUrl = $_SERVER['REQUEST_URI']; if (preg_match('/^\\/[a-zA-Z]{2}\\//', $strUrl)) { preg_match('/^\\/[a-zA-Z]{2}\\//', $strUrl, $arrMatches); $this->strLanguageCode = trim($arrMatches[0], '/'); foreach ($this->core->webConfig->languages->language->toArray() as $arrLanguage) { if (array_key_exists('code', $arrLanguage) && $arrLanguage['code'] == strtolower($this->strLanguageCode)) { $this->intLanguageId = $arrLanguage['id']; break; } } if ($this->intLanguageId == null) { $this->intLanguageId = $this->core->sysConfig->languages->default->id; $this->strLanguageCode = $this->core->sysConfig->languages->default->code; } $strUrl = preg_replace('/^\\/[a-zA-Z]{2}\\//', '', $strUrl); } else { $strUrl = preg_replace('/^\\//', '', $strUrl); $this->intLanguageId = $this->core->sysConfig->languages->default->id; $this->strLanguageCode = $this->core->sysConfig->languages->default->code; } $this->getModelUrls(); $this->getModelFolders(); $objTheme = $this->objModelFolders->getThemeByDomain($strDomain)->current(); $this->objUrlsData = $this->objModelUrls->loadByUrl($objTheme->idRootLevels, parse_url($strUrl, PHP_URL_PATH) === null ? '' : parse_url($strUrl, PHP_URL_PATH)); if (count($this->objUrlsData) > 0) { $objUrlData = $this->objUrlsData->current(); switch ($objUrlData->idUrlTypes) { // UrlType: Widget case $this->core->sysConfig->url_types->widget: $objWidget = new Widget(); $this->getModelWidgets(); $objWidgetInstance = $this->objModelWidgets->loadWidgetByInstanceId($objUrlData->relationId); $objWidget->setWidgetInstanceId($objUrlData->relationId); $this->_getParam('do') == null ? $objWidget->setAction('index') : $objWidget->setAction($this->_getParam('do')); $objWidget->setWidgetName($objWidgetInstance->name); $objWidget->setNavigationUrl(parse_url($strUrl, PHP_URL_PATH) === null ? '' : parse_url($strUrl, PHP_URL_PATH)); $objWidget->setWidgetTitle($objWidgetInstance->title); $objWidget->setRootLevelTitle($objTheme->title); $objWidget->setRootLevelId($objTheme->idRootLevels); $objWidget->setWidgetVersion($objUrlData->version); $objWidget->setLanguageId($objUrlData->idLanguages); $objWidget->setLanguageCode($this->strLanguageCode); $objWidget->setUrlParentId($objUrlData->idParent); Zend_Registry::set('Widget', $objWidget); $this->_forward($objWidget->getAction(), 'index', $objWidgetInstance->name); break; // UrlType: SubWidget // UrlType: SubWidget case $this->core->sysConfig->url_types->subwidget: $objWidget = new Widget(); $this->getModelWidgets(); $objWidgetInstance = $this->objModelWidgets->loadSubWidgetByInstanceId($objUrlData->relationId); $objWidget->setWidgetInstanceId($objUrlData->relationId); $this->_getParam('do') == null ? $objWidget->setAction('view') : $objWidget->setAction($this->_getParam('do')); $objWidget->setGenericFormTypesId($objWidgetInstance->idGenericFormTypes); $objWidget->setGenericFormId($objWidgetInstance->genericFormId); $objWidget->setGenericFormVersion($objWidgetInstance->version); $objWidget->setWidgetName($objWidgetInstance->name); $objWidget->setNavigationUrl(parse_url($strUrl, PHP_URL_PATH) === null ? '' : parse_url($strUrl, PHP_URL_PATH)); $objWidget->setWidgetTitle($objWidgetInstance->title); $objWidget->setRootLevelTitle($objTheme->title); $objWidget->setRootLevelId($objTheme->idRootLevels); $objWidget->setWidgetVersion($objUrlData->version); $objWidget->setLanguageId($objUrlData->idLanguages); $objWidget->setLanguageCode($this->strLanguageCode); Zend_Registry::set('Widget', $objWidget); $this->_forward($objWidget->getAction(), 'index', $objWidgetInstance->name); break; // Url Type: page // Url Type: page case $this->core->sysConfig->url_types->page: $arrFrontendOptions = array('lifetime' => 604800, 'automatic_serialization' => true); $arrBackendOptions = array('cache_dir' => GLOBAL_ROOT_PATH . 'tmp/cache/pages/'); // getting a Zend_Cache_Core object $this->objCache = Zend_Cache::factory('Output', 'File', $arrFrontendOptions, $arrBackendOptions); $strCacheId = 'page_' . $this->strLanguageCode . '_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $strUrl); if ($this->core->sysConfig->cache->page == 'false' || $this->core->sysConfig->cache->page == 'true' && $this->objCache->test($strCacheId) == false || $this->core->sysConfig->cache->page == 'true' && isset($_SESSION['sesTestMode'])) { $objNavigation = new Navigation(); $objNavigation->setRootLevelId($objTheme->idRootLevels); $objNavigation->setLanguageId($this->intLanguageId); require_once dirname(__FILE__) . '/../helpers/navigation.inc.php'; Zend_Registry::set('Navigation', $objNavigation); $this->getModelPages(); $this->objUrlsData = $this->objModelPages->loadByUrl($objTheme->idRootLevels, $strUrl); foreach ($this->objUrlsData as $objPageData) { $this->objUrlsData = $objPageData; } if (count($this->objUrlsData) > 0) { $this->core->logger->debug('Cache: ' . $this->core->sysConfig->cache->page); if ($this->core->sysConfig->cache->page == 'true' && !isset($_SESSION['sesTestMode'])) { $this->core->logger->debug('Start caching...'); $this->objCache->start($strCacheId); $this->blnCachingStart = true; } $this->objPage = new Page(); $this->objPage->setRootLevelId($objTheme->idRootLevels); $this->objPage->setRootLevelTitle($objTheme->title); $this->objPage->setPageId($this->objUrlsData->relationId); $this->objPage->setPageVersion($this->objUrlsData->version); $this->objPage->setLanguageId($this->objUrlsData->idLanguages); $this->objPage->load(); /** * set values for replacers */ Zend_Registry::set('TemplateCss', $this->objPage->getTemplateId() == $this->core->sysConfig->page_types->page->portal_startpage_templateId ? '<link rel="stylesheet" type="text/css" media="screen" href="/website/themes/' . $objTheme->path . '/css/startpage.css"></link>' : '<link rel="stylesheet" type="text/css" media="screen" href="/website/themes/' . $objTheme->path . '/css/content.css"></link>'); Zend_Registry::set('TemplateJs', $this->objPage->getTemplateId() == $this->core->sysConfig->page_types->page->event_templateId ? '<script src="http://maps.google.com/maps?file=api&v=2&key=' . $this->core->webConfig->gmaps->key . '" type="text/javascript"></script>' : ''); $objNavigation->setPage($this->objPage); /** * get page template filename */ $this->view->template = $this->objPage->getTemplateFile(); $this->view->intRootLevelId = $this->objPage->getRootLevelId(); //$this->view->strRootLevelUrl = $this->core->sysConfig->url->base; $this->view->publisher = $this->objPage->getPublisherName(); $this->view->publishdate = $this->objPage->getPublishDate(); Zend_Registry::set('Page', $this->objPage); require_once dirname(__FILE__) . '/../helpers/page.inc.php'; $this->view->setScriptPath(GLOBAL_ROOT_PATH . 'public/website/themes/' . $objTheme->path . '/'); $this->renderScript('master.php'); } else { $this->view->setScriptPath(GLOBAL_ROOT_PATH . 'public/website/themes/' . $objTheme->path . '/'); $this->renderScript('error-404.php'); } } else { $this->_helper->viewRenderer->setNoRender(); echo $this->objCache->load($strCacheId); } // end page type } //end if type } else { $objNavigation = new Navigation(); $objNavigation->setRootLevelId($objTheme->idRootLevels); $objNavigation->setLanguageId($this->intLanguageId); require_once dirname(__FILE__) . '/../helpers/navigation.inc.php'; Zend_Registry::set('Navigation', $objNavigation); $this->view->setScriptPath(GLOBAL_ROOT_PATH . 'public/website/themes/' . $objTheme->path . '/'); $this->renderScript('error-404.php'); } }
/** * getModelPages * @param string $strPageId * @param integer $intPageVersion * @param integer $intLanguageId * @return void * @author Thomas Schedler <*****@*****.**> * @version 1.0 */ public function indexPage($strPageId, $intPageVersion, $intLanguageId) { try { $objPage = new Page(); $objPage->setPageId($strPageId); $objPage->setPageVersion($intPageVersion); $objPage->setLanguageId($intLanguageId); $objPage->load(); $objPage->indexPage(); } catch (Exception $exc) { $this->core->logger->err($exc); } }
exit('The page name can only contain dashes, dots and alphanumerical characters.'); } // /{pagename}.{representation} if ($representation != '') { if (!$page_exists) { header('HTTP/1.0 404 Not Found'); die("Page not found: <a href=" . EDITH_URI . "/" . $page->name . ">Create me!</a>"); } if (!in_array($representation, $REPRESENTATIONS)) { header('HTTP/1.0 404 Not Found'); die('Representation can only be one of: ' . implode($REPRESENTATIONS, ', ')); } switch ($_SERVER['REQUEST_METHOD']) { case 'GET': case 'HEAD': $page->load(); require "templates/{$representation}.php"; exit; case 'POST': case 'PUT': case 'PATCH': case 'DELETE': header('HTTP/1.0 405 Method Not Allowed'); header('Allow: GET, HEAD'); exit; default: header('HTTP/1.0 501 Not Implemented'); header('Allow: GET, HEAD'); exit; } }
</select> <label for="force_article"><input type="checkbox" name="force_article" id="force_article" /> Force {{Article}} template</label> </div> </div> </form> <?php if (array_key_exists('URL', $_REQUEST)) { include 'page.php'; //Does the specified URL valid and exist? $url = $_REQUEST['URL']; if (!filter_var($url, FILTER_VALIDATE_URL)) { message_die(GENERAL_ERROR, "{$url} isn't a valid URL.", 'URL issue'); } //Gets page information setlocale(LC_TIME, 'fr_FR.UTF-8'); $page = Page::load($url); if ($page->error) { message_die(GENERAL_ERROR, "Can't open {$url}", 'URL issue'); } $force_article = array_key_exists('force_article', $_REQUEST) && $_REQUEST['force_article']; if (!$force_article && $page->is_article()) { echo "<h3>Note</h3><p>Cette URL pointe vers un article de revue, aussi le modèle <a href=\"https://fr.wikipedia.org/wiki/Template:Article\">{{Article}}</a> est indiqué.</p>"; } if ($page->switchTo != null) { $documentObject = new $page->switchTo['document']['class'](); foreach ($page->switchTo['document']['params'] as $key => $value) { $documentObject->{$key} = $value; } call_user_func([$documentObject, $page->switchTo['document']['method']]); } //Gets template
/** * * @return array */ public static function GetAllPages() { $res = array(); $rows = DataBase::Current()->ReadRows("SELECT * FROM {'dbprefix'}pages"); foreach ($rows as $row) { try { $obj = new Page(); $obj->load($row); $res[] = $obj; } catch (AccessDeniedException $ex) { } } return $res; }
/** * @expectedException LogicException */ public function testNotAllowedRepositoryMethod() { Page::load(); }
/** * Initialize the application. */ private function init() { $errorHandler = new ErrorHandler(); $errorHandler->register(); static::$DI = $DI = DI::instance(); $DI['Request'] = $request = new Http\Request(); $DI['Config'] = $config = new Config($this->sitePath, dirname($_SERVER['SCRIPT_FILENAME']), $request->getBaseUrl()); $DI['Alias'] = new Alias(['@app' => $config->get('app.path'), '@asset' => $this->sitePath . '/assets', '@media' => $config->get('media.path'), '@page' => $config->get('pages.path'), '@plugin' => $config->get('plugins.path'), '@post' => $config->get('posts.path'), '@site' => $this->sitePath, '@vendor' => $this->vendorDir, '@web' => $config->get('web.path')]); $DI['Assets'] = function ($DI) { return new Assets($DI['Alias'], $DI['Config']->get('web.url')); }; $DI['Cache\\PageCache'] = function ($DI) { return Cache\CacheFactory::create('page', $DI['Config']); }; $DI['Cache\\DataCache'] = function ($DI) { return Cache\CacheFactory::create('data', $DI['Config']); }; $DI['DataArray'] = function ($DI) { $loader = new Loader\DataLoader($DI['Config']->get('data.extensions')); return $loader->load($DI['Config']->get('data.path')); }; $DI['Loader\\PageLoader'] = function ($DI) { $loader = new Loader\PageLoader($DI['Alias']); return $loader; }; $DI['Menu\\Page\\Builder'] = function ($DI) { $paths = []; $paths['@page'] = realpath($DI['Config']->get('pages.path')); foreach ($DI['Config']->get('pages.extra_paths', []) as $alias) { $paths[$alias] = $DI['Alias']->get($alias); } $extensions = $DI['Config']->get('pages.extensions', []); $builder = new Menu\Page\Builder($paths, $extensions); return $builder; }; $DI['PluginManager'] = function ($DI) { $enabled = $DI['Config']->get('plugins.enable', []); $path = $DI['Config']->get('plugins.path'); $enabledSysPlugins = $DI['Config']->get('sysplugins.enable'); return new PluginManager($enabled, $path, $enabledSysPlugins); }; $DI['Url\\UrlGenerator'] = function ($DI) { return new Url\UrlGenerator($DI['Request'], $DI['Config']->get('nice_urls', false)); }; setlocale(LC_ALL, $DI['Config']->get('locale')); // Add custom PSR-4 plugin path to Composer autoloader $autoload = (require $this->vendorDir . '/autoload.php'); $autoload->addPsr4('herbie\\sysplugin\\', __DIR__ . '/../plugins/'); $autoload->addPsr4('herbie\\plugin\\', $DI['Config']->get('plugins.path')); // Init PluginManager at first if (true === $DI['PluginManager']->init($DI['Config'])) { Hook::trigger(Hook::ACTION, 'pluginsInitialized', $DI['PluginManager']); Hook::trigger(Hook::ACTION, 'shortcodeInitialized', $DI['Shortcode']); $DI['Menu\\Page\\Collection'] = function ($DI) { $DI['Menu\\Page\\Builder']->setCache($DI['Cache\\DataCache']); return $DI['Menu\\Page\\Builder']->buildCollection(); }; $DI['Menu\\Page\\Node'] = function ($DI) { return Menu\Page\Node::buildTree($DI['Menu\\Page\\Collection']); }; $DI['Menu\\Page\\RootPath'] = function ($DI) { $rootPath = new Menu\Page\RootPath($DI['Menu\\Page\\Collection'], $DI['Request']->getRoute()); return $rootPath; }; $DI['Menu\\Post\\Collection'] = function ($DI) { $builder = new Menu\Post\Builder($DI['Cache\\DataCache'], $DI['Config']); return $builder->build(); }; $DI['Page'] = function ($DI) { try { $route = $DI['Request']->getRoute(); $page = false; if (false === $page) { $menuItem = $DI['Url\\UrlMatcher']->match($route); $path = $menuItem->getPath(); $page = new Page(); $page->setLoader($DI['Loader\\PageLoader']); $page->load($path); Hook::trigger(Hook::ACTION, 'pageLoaded', $page); } } catch (\Exception $e) { $page = new Page(); $page->layout = 'error.html'; $page->setError($e); } return $page; }; $DI['Translator'] = function ($DI) { $translator = new Translator($DI['Config']->get('language'), ['app' => $DI['Alias']->get('@app/../messages')]); foreach ($DI['PluginManager']->getLoadedPlugins() as $key => $dir) { $translator->addPath($key, $dir . '/messages'); } $translator->init(); return $translator; }; $DI['Url\\UrlMatcher'] = function ($DI) { return new Url\UrlMatcher($DI['Menu\\Page\\Collection'], $DI['Menu\\Post\\Collection']); }; } }
private function load_post($post_path) { $post = Page::load($this->path . '/' . $post_path); $post->url = $this->relative_url($this->post_path_to_url($post_path)); return $post; }