public function __construct($p_templateIdOrName = null, $p_themePath = null) { $this->m_properties = array(); $this->m_customProperties['name'] = 'getValue'; $this->m_customProperties['identifier'] = 'getId'; $this->m_customProperties['type'] = 'getTemplateType'; $this->m_customProperties['defined'] = 'defined'; $this->m_customProperties['theme_dir'] = 'getThemeDir'; $this->_map = array("frontPage" => "issue", "errorPage" => "default", "sectionPage" => "section", "issuePage" => "issue", "articlePage" => "article"); if ((is_string($p_templateIdOrName) || is_int($p_templateIdOrName)) && !empty($p_templateIdOrName)) { $filePath = is_numeric($p_templateIdOrName) ? $p_templateIdOrName : $p_themePath . $p_templateIdOrName; $resourceId = new ResourceId('template_engine/metaclasses/MetaTemplate'); /* @var $syncResourceService ISyncResourceService */ $syncResourceService = $resourceId->getService(ISyncResourceService::NAME); $this->m_dbObject = $syncResourceService->findByPathOrId($filePath); if (is_null($this->m_dbObject)) { $pathRsc = new Resource(); $pathRsc->setName('buildPage'); $filePath = CS_PATH_TEMPLATES . DIR_SEP . $p_themePath . $p_templateIdOrName; if (!is_numeric($p_templateIdOrName) && !is_null($p_themePath) && file_exists($filePath)) { $pathRsc->setPath($p_themePath . $p_templateIdOrName); $this->m_dbObject = $syncResourceService->getSynchronized($pathRsc); } else { $this->m_dbObject = $pathRsc; } } } }
function getThemePath($themePath) { Validation::notEmpty($themePath, 'themePath'); $pathRsc = new Resource(); $pathRsc->setName(self::THEME_PATH_RSC_NAME); $pathRsc->setPath($themePath); return $this->getSynchronized($pathRsc); }
/** * 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)) { $themesService = \Zend_Registry::get('container')->getService('newscoop_newscoop.themes_service'); $this->_themePath = $themesService->getThemePath(); } $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_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 getNonDbResource($name, $path) { $rsc = new Resource(); $rsc->setName($name); $rsc->setPath($path); return $rsc; }
public function setName($name) { $this->__load(); return parent::setName($name); }
/** * Reads the resources from an output tag. * * @param \SimpleXMLElement $parent * The parent output node to read the resources from, *(not null not empty). * @param string $tagName * The tag name containing the resource, *(not null not empty). * @param string $themePath * The theme path to construct the resource path based on, *(not null not empty). * @param string $name * The name of the created resource based on the found tag, *(not null not empty). * @throws FailedException * Thrown if the resource has failed to be obtained, this exception will not contain any message, the resons of failure * will be looged in the error handler. * @return \Newscoop\Entity\Resource * The obtained resource, not null. */ protected function loadOutputResource(\SimpleXMLElement $parent, $tagName, $themePath) { $nodes = $this->getNodes($parent, $tagName); if (count($nodes) == 0) { $this->getErrorHandler()->error(ThemeErrors::XML_MISSING_TAG, $tagName, $parent->getName()); throw new FailedException(); } if (count($nodes) > 1) { $this->getErrorHandler()->error(ThemeErrors::XML_TO_MANY_TAGS, $tagName, $parent->getName(), 1); throw new FailedException(); } $node = $nodes[0]; /* @var $node \SimpleXMLElement */ try { $rsc = new Resource(); $rsc->setName($tagName); $rsc->setPath($this->escapePath($themePath . $this->readAttribute($node, self::ATTR_PAGE_SRC))); return $rsc; } catch (XMLMissingAttribueException $e) { $this->getErrorHandler()->error(ThemeErrors::XML_MISSING_ATTRIBUTE, $e->getAttributeName(), $tagName); throw new FailedException(); } }
function getPresentationImages(Theme $theme) { Validation::notEmpty($theme, self::TAG_THEME); $xml = $this->loadXML($this->toFullPath($theme, $this->themeConfigFileName)); $presentResources = array(); if ($xml != NULL) { $nodes = $this->getNodes($xml, self::TAG_PRESENT); foreach ($nodes as $node) { /* @var $node \SimpleXMLElement */ $rsc = new Resource(); try { $rsc->setName($this->readAttribute($node, self::ATTR_PRESENT_NAME)); $rsc->setPath($theme->getPath() . $this->readAttribute($node, self::ATTR_PRESENT_SRC)); $presentResources[] = $rsc; } catch (XMLMissingAttribueException $e) { $this->getErrorHandler()->error(ThemeErrors::XML_MISSING_ATTRIBUTE, $e->getAttributeName(), $node->getName()); } } } return $presentResources; }