/** * Class constructor * * @param string $p_uri * The full URI string */ public function __construct($p_uri = null) { parent::__construct($p_uri); try { $this->setURLType(URLTYPE_SHORT_NAMES); // HUGE TODO: rewrite this - remove globals controller usage! if (array_key_exists('controller', $GLOBALS)) { if (is_object($GLOBALS['controller'])) { $this->setURL($GLOBALS['controller']->getRequest()); } else { $this->setURLFromSymfony(Zend_Registry::get('container')->getService('request')); } } else { $this->setURL(new Zend_Controller_Request_Http()); } $this->m_validURI = true; $this->validateCache(false); } catch (Exception $e) { $this->m_validURI = false; $this->m_errorCode = $e->getCode(); if (!is_null($this->m_publication)) { $tplId = CampSystem::GetInvalidURLTemplate($this->m_publication->identifier, null, null, !$this->m_preview); $themePath = $this->getThemePath(); $tplId = substr($tplId, strlen($themePath)); $template = new MetaTemplate($tplId, $themePath); if ($template->defined()) { $this->m_template = $template; } CampTemplate::singleton()->config_dir = APPLICATION_PATH . '/../themes/' . $themePath . '_conf'; } CampTemplate::singleton()->trigger_error($e->getMessage()); } }
/** * Class constructor * * @param string $p_uri * The full URI string */ public function __construct($p_uri = null) { parent::__construct($p_uri); $this->setURLType(URLTYPE_SHORT_NAMES); $res = $this->setURL(); if (PEAR::isError($res)) { $this->m_validURI = false; $this->m_errorCode = $res->getCode(); if (!is_null($this->m_publication)) { $tplId = CampSystem::GetInvalidURLTemplate($this->m_publication->identifier); $template = new MetaTemplate($tplId); if ($template->defined()) { $this->m_template = $template; } } CampTemplate::singleton()->trigger_error($res->getMessage()); } else { $this->m_validURI = true; } $this->validateCache(false); } // fn __construct
/** * */ public function getTemplate($p_templateIdOrName = null) { if (!is_null($this->m_template)) { return $this->m_template->name; } if (!empty($p_templateIdOrName)) { $tplObj = new Template($p_templateIdOrName); if (!$tplObj->exists()) { return null; } $template = $tplObj->getName(); } elseif (is_null($this->m_errorCode)) { $template = CampSystem::GetTemplate($this->language->number, $this->publication->identifier, $this->issue->number, $this->section->number, $this->article->number); } else { return null; } return $template; } // fn getTemplate
/** * Sets the URI path and query values based on given parameters. * * @param array $p_params * An array of valid URL parameters * @param boolean $p_preview * If true, will keep the preview parameters in the URL * * @return void */ protected function buildURI(array &$p_params = array(), $p_preview = false) { if ($this->isValidCache()) { return; } $parameter = count($p_params) > 0 ? strtolower(array_shift($p_params)) : null; switch ($parameter) { case 'language': $this->m_buildPath = $this->buildPath(CampSystem::GetTemplate($this->m_language->number, $this->m_publication->identifier)); $keepParams = CampURITemplatePath::$m_languageParameters; if ($p_preview) { $keepParams = array_merge(CampURI::$m_previewParameters, $keepParams); } $this->m_buildQueryArray = $this->getQueryArray($keepParams); $p_params = array(); break; case 'publication': $this->m_buildPath = $this->buildPath(CampSystem::GetTemplate($this->m_language->number, $this->m_publication->identifier)); $keepParams = CampURITemplatePath::$m_languageParameters; if ($p_preview) { $keepParams = array_merge(CampURI::$m_previewParameters, $keepParams); } $this->m_buildQueryArray = $this->getQueryArray($keepParams); $p_params = array(); break; case 'issue': $this->m_buildPath = $this->buildPath(CampSystem::GetIssueTemplate($this->m_language->number, $this->m_publication->identifier, $this->m_issue->number)); $keepParams = CampURITemplatePath::$m_issueParameters; if ($p_preview) { $keepParams = array_merge(CampURI::$m_previewParameters, $keepParams); } $this->m_buildQueryArray = $this->getQueryArray($keepParams); $p_params = array(); break; case 'section': $this->m_buildPath = $this->buildPath(CampSystem::GetSectionTemplate($this->m_language->number, $this->m_publication->identifier, $this->m_issue->number, $this->m_section->number)); $keepParams = CampURITemplatePath::$m_sectionParameters; if ($p_preview) { $keepParams = array_merge(CampURI::$m_previewParameters, $keepParams); } $this->m_buildQueryArray = $this->getQueryArray($keepParams); $p_params = array(); break; case 'article': $this->m_buildPath = $this->buildPath(CampSystem::GetArticleTemplate($this->m_language->number, $this->m_publication->identifier, $this->m_issue->number, $this->m_section->number)); $keepParams = CampURITemplatePath::$m_articleParameters; if ($p_preview) { $keepParams = array_merge(CampURI::$m_previewParameters, $keepParams); } $this->m_buildQueryArray = $this->getQueryArray($keepParams); $p_params = array(); break; case 'template': $option = isset($p_params[0]) ? array_shift($p_params) : null; if (!is_null($option) && $this->isValidTemplate($option)) { $this->m_buildPath = $this->buildPath($option); } break; default: if (!empty($parameter)) { array_unshift($p_params, $parameter); $count = count($p_params); parent::buildURI($p_params, $p_preview); if (count($p_params) == $count) { array_shift($p_params); } } } if (count($p_params) > 0) { $this->buildURI($p_params); } if (is_null($this->m_buildPath)) { $template = $this->getTemplate(); if (empty($template)) { CampTemplate::singleton()->trigger_error('Invalid template in context'); return; } $this->m_buildPath = $this->buildPath($template); } if (is_null($this->m_buildQuery)) { $this->m_buildQuery = CampURI::QueryArrayToString($this->m_buildQueryArray); } $this->validateCache(true); } // fn buildURI
/** * Sets the URI path and query values based on given parameters. * * @param array $p_params * An array of valid URL parameters * @param boolean $p_preview * If true, will keep the preview parameters in the URL * * @return void */ protected function buildURI(array &$p_params = array(), $p_preview = false) { if ($this->isValidCache()) { return; } $parameter = count($p_params) > 0 ? strtolower(array_shift($p_params)) : null; switch ($parameter) { case 'language': case 'publication': $this->m_buildPath = $this->getURILanguage(); if ($p_preview) { $this->m_buildQueryArray = $this->getQueryArray(CampURI::$m_previewParameters); } else { $this->m_buildQueryArray = array(); } $p_params = array(); break; case 'issue': $this->m_buildPath = $this->getURIIssue(); if ($p_preview) { $this->m_buildQueryArray = $this->getQueryArray(CampURI::$m_previewParameters); } else { $this->m_buildQueryArray = array(); } $p_params = array(); break; case 'section': $this->m_buildPath = $this->getURISection(); if ($p_preview) { $this->m_buildQueryArray = $this->getQueryArray(CampURI::$m_previewParameters); } else { $this->m_buildQueryArray = array(); } $p_params = array(); break; case 'article': $this->m_buildPath = $this->getURIArticle(); if ($p_preview) { $this->m_buildQueryArray = $this->getQueryArray(CampURI::$m_previewParameters); } else { $this->m_buildQueryArray = array(); } $p_params = array(); break; case 'template': case 'id': $option = isset($p_params[0]) ? array_shift($p_params) : null; if (is_null($option)) { break; } if (is_null($this->_themePath)) { $this->_themePath = CampSystem::GetThemePath($this->m_language->number, $this->m_publication->identifier, $this->m_issue->number); } $pathRsc = new Resource(); $pathRsc->setName('buildPage'); $pathRsc->setPath($this->_themePath . $option); $resourceId = new ResourceId('template_engine/classes/CampURIShortNames'); $pathRsc = $resourceId->getService(ISyncResourceService::NAME)->getSynchronized($pathRsc); if (!is_null($pathRsc) && $pathRsc->exists()) { $this->m_buildQueryArray[CampRequest::TEMPLATE_ID] = $pathRsc->getId(); } break; default: if (!empty($parameter)) { array_unshift($p_params, $parameter); $count = count($p_params); parent::buildURI($p_params, $p_preview); if (count($p_params) == $count) { array_shift($p_params); } } } if (count($p_params) > 0) { $this->buildURI($p_params); } if (!is_null($this->m_language) && $this->m_language->defined() && is_null($this->m_buildPath)) { $this->m_buildPath = $this->m_config->getSetting('SUBDIR') . '/' . $this->m_language->code . '/'; if (!is_null($this->m_issue) && $this->m_issue->defined()) { $this->m_buildPath .= $this->m_issue->url_name . '/'; if (!is_null($this->m_section) && $this->m_section->defined()) { $this->m_buildPath .= $this->m_section->url_name . '/'; if (!is_null($this->m_article) && $this->m_article->defined()) { $this->m_buildPath = $this->getURIArticle(); } } } } if (is_null($this->m_buildQuery)) { $this->m_buildQuery = CampURI::QueryArrayToString($this->m_buildQueryArray); } $this->validateCache(true); }
/** * */ public function getTemplate($p_templateIdOrName = null) { if (!is_null($this->m_template)) { return $this->m_template->name; } if (!empty($p_templateIdOrName)) { $tplObj = new MetaTemplate($p_templateIdOrName); if (!$tplObj->defined()) { $template = CampSystem::GetInvalidURLTemplate($this->publication->identifier, $this->issue->number, $this->language->number, !$this->m_preview); $template = substr($template, strlen($this->getThemePath())); } else { $template = $tplObj->name; } } elseif (is_null($this->m_errorCode)) { $template = CampSystem::GetTemplate($this->language->number, $this->publication->identifier, $this->issue->number, $this->section->number, $this->article->number); if (is_null($template)) { $template = CampSystem::GetInvalidURLTemplate($this->publication->identifier, $this->issue->number, $this->language->number, !$this->m_preview); } $template = substr($template, strlen($this->getThemePath())); } else { return null; } $filePath = CS_PATH_TEMPLATES . DIR_SEP . $this->getThemePath() . $template; if (!file_exists($filePath)) { return null; } return $template; }