CampURI::buildURI PHP Method

buildURI() protected method

Sets the URI path and query values based on given parameters.
protected buildURI ( array &$p_params = [], boolean $p_preview = false ) : void
$p_params array An array of valid URL parameters
$p_preview boolean 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;
        }
        if (count($p_params) == 0) {
            return;
        }
        $parameter = strtolower(array_shift($p_params));
        switch ($parameter) {
            case 'static_file':
                $staticFile = isset($p_params[0]) ? array_shift($p_params) : null;
                $p_params = array();
                $this->m_buildQueryArray = array();
                if (empty($staticFile)) {
                    $this->m_buildPath = '';
                    break;
                }
                $this->m_buildPath = '/themes/' . $this->getThemePath() . $staticFile;
                break;
            case 'root_level':
                $this->m_buildPath = '/';
                if ($p_preview) {
                    $this->m_buildQueryArray = $this->getQueryArray(CampURI::$m_previewParameters);
                } else {
                    $this->m_buildQueryArray = array();
                }
                $p_params = array();
                break;
            case 'articleattachment':
                $context = CampTemplate::singleton()->context();
                $attachment = new Attachment($context->attachment->identifier);
                $this->m_buildPath = $attachment->getAttachmentUri();
                $this->m_buildQueryArray = array();
                $p_params = array();
                break;
            case 'articlecomment':
                $context = CampTemplate::singleton()->context();
                if ($context->comment->defined) {
                    $this->m_buildQueryArray['acid'] = $context->comment->identifier;
                }
                break;
            case 'image':
                $this->m_buildQueryArray = array();
                if (isset($p_params[0]) && is_numeric($p_params[0])) {
                    $this->processOldImageOptions($imageNo, $p_params);
                } else {
                    $this->processImageOptions($imageNo, $p_params);
                }
                $context = CampTemplate::singleton()->context();
                if (!is_null($imageNo)) {
                    $oldImage = $context->image;
                    $articleImage = new ArticleImage($context->article->number, null, $imageNo);
                    $context->image = new MetaImage($articleImage->getImageId());
                }
                $this->m_buildPath = '/get_img';
                $this->m_validURI = $context->image->defined();
                $this->m_buildQueryArray['ImageId'] = $context->image->number;
                if (!is_null($imageNo)) {
                    $context->image = $oldImage;
                }
                $p_params = array();
                break;
            case 'previous_subtitle':
            case 'next_subtitle':
            case 'all_subtitles':
                $option = isset($p_params[0]) ? array_shift($p_params) : null;
                $article = CampTemplate::singleton()->context()->article;
                $subtitleNo = $article->current_subtitle_no($option);
                if (!$article->defined || !is_null($subtitleNo) && !is_numeric($subtitleNo)) {
                    return;
                }
                $fieldObj = $article->{$option};
                if ($parameter == 'previous_subtitle' && !$fieldObj->has_previous_subtitles || $parameter == 'next_subtitle' && !$fieldObj->has_next_subtitles) {
                    return;
                }
                $subtitleURLId = $article->subtitle_url_id($option);
                if ($parameter == 'all_subtitles') {
                    $newSubtitleNo = 'all';
                } else {
                    $newSubtitleNo = $subtitleNo + ($parameter == 'previous_subtitle' ? -1 : 1);
                }
                $this->m_buildQueryArray[$subtitleURLId] = $newSubtitleNo;
                break;
            case 'previous_items':
            case 'next_items':
                $context = CampTemplate::singleton()->context();
                if ($context->current_list == null) {
                    return;
                }
                $listId = $context->current_list->id;
                $this->m_buildQueryArray[$listId] = $parameter == 'previous_items' ? $context->current_list->previous_start : $context->current_list->next_start;
                if ($this->m_buildQueryArray[$listId] == 0) {
                    unset($this->m_buildQueryArray[$listId]);
                }
                break;
            case 'reset_issue_list':
                $context = CampTemplate::singleton()->context();
                $listIdPrefix = $context->list_id_prefix('IssuesList');
                $this->resetList($listIdPrefix);
                break;
            case 'reset_section_list':
                $context = CampTemplate::singleton()->context();
                $listIdPrefix = $context->list_id_prefix('SectionsList');
                $this->resetList($listIdPrefix);
                break;
            case 'reset_article_list':
                $context = CampTemplate::singleton()->context();
                $listIdPrefix = $context->list_id_prefix('ArticlesList');
                $this->resetList($listIdPrefix);
                break;
            case 'reset_searchresult_list':
                $context = CampTemplate::singleton()->context();
                $listIdPrefix = $context->list_id_prefix('SearchResultsList');
                $this->resetList($listIdPrefix);
                break;
            case 'reset_subtitle_list':
                $context = CampTemplate::singleton()->context();
                $listIdPrefix = $context->list_id_prefix('SubtitlesList');
                $this->resetList($listIdPrefix);
                break;
            default:
        }
    }

Usage Example

Esempio n. 1
0
    /**
     * 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':
                $option = isset($p_params[0]) ? array_shift($p_params) : null;
                $template = new Template($option);
                if (!is_null($option) && $template->exists()) {
                    $this->m_buildQueryArray[CampRequest::TEMPLATE_ID] = $template->getTemplateId();
                }
                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);
    } // fn buildURI
All Usage Examples Of CampURI::buildURI