tag.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class Tag extends aList
00007 {
00012     protected $_sListType = 'tag';
00013 
00018     protected $_blShowSorting = true;
00019 
00025     protected $_sTag;
00026 
00032     protected $_sTagTitle;
00033 
00038     protected $_oPageNavigation = null;
00039 
00045     protected $_sTemplateLocation;
00046 
00052     protected $_iViewIndexState = VIEW_INDEXSTATE_INDEX;
00053 
00063     public function render()
00064     {
00065         oxUBase::render();
00066 
00067         $myConfig = $this->getConfig();
00068 
00069         $oArticleList = $this->getArticleList();
00070 
00071         //if no articles - showing 404 header (#2139)
00072         if ( !$oArticleList || count( $oArticleList ) < 1 ) {
00073             error_404_handler();
00074         }
00075 
00076         $this->_aViewData['articlelist']       = $oArticleList;
00077         $this->_aViewData['title']             = $this->getTitle();
00078         $this->_aViewData['template_location'] = $this->getTemplateLocation();
00079         $this->_aViewData['searchtag']         = $this->getTag();
00080 
00081         $this->_aViewData['pageNavigation']    = $this->getPageNavigation();
00082         $this->_aViewData['actCategory']       = $this->getActiveCategory();
00083 
00084         // processing list articles
00085         $this->_processListArticles();
00086 
00087         return $this->_sThisTemplate;
00088     }
00089 
00095     protected function _getProductLinkType()
00096     {
00097         return OXARTICLE_LINKTYPE_TAG;
00098     }
00099 
00105     public function getAddUrlParams()
00106     {
00107         $sAddParams  = parent::getAddUrlParams();
00108         $sAddParams .= ($sAddParams?'&amp;':'') . "listtype={$this->_sListType}";
00109         if ( $sParam = oxConfig::getParameter( 'searchtag', 1 ) ) {
00110             $sAddParams .= "&amp;searchtag=" . rawurlencode( $sParam );
00111         }
00112         return $sAddParams;
00113     }
00114 
00122     protected function _loadArticles( $oCategory )
00123     {
00124         // load only articles which we show on screen
00125         $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00126         $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00127         $oArtList = oxNew( 'oxarticlelist' );
00128         $oArtList->setSqlLimit( $iNrofCatArticles * $this->getActPage(), $iNrofCatArticles );
00129         $oArtList->setCustomSorting( $this->getSortingSql( 'oxtags' ) );
00130 
00131         // load the articles
00132         $this->_iAllArtCnt = $oArtList->loadTagArticles( $this->getTag(), oxLang::getInstance()->getBaseLanguage());
00133         $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00134 
00135         return $oArtList;
00136     }
00137 
00143     protected function _getCatPathString()
00144     {
00145         return $this->getTag();
00146     }
00147 
00153     protected function _getSeoObjectId()
00154     {
00155         return md5("tag" . $this->getTag() );
00156     }
00157 
00165     public function getSorting( $sCnid )
00166     {
00167         return parent::getSorting( "oxtags" );
00168     }
00169 
00179     public function setItemSorting( $sCnid, $sSortBy, $sSortOrder  = null )
00180     {
00181         parent::setItemSorting( "oxtags", $sSortBy, $sSortOrder );
00182     }
00183 
00189     public function generatePageNavigationUrl()
00190     {
00191         if ( ( oxUtils::getInstance()->seoIsActive() && ( $sTag = $this->getTag() ) ) ) {
00192             $sLink = oxSeoEncoderTag::getInstance()->getTagUrl( $sTag, oxLang::getInstance()->getBaseLanguage() );
00193         }
00194         return $sLink ? $sLink : oxUBase::generatePageNavigationUrl();
00195     }
00196 
00206     protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00207     {
00208         $sSeoUrl = $blSeo = oxUtils::getInstance()->seoIsActive();
00209         if ( $blSeo && ( $sTag = $this->getTag() ) ) {
00210             if ( $iPage && ( $sSeoUrl = oxSeoEncoderTag::getInstance()->getTagPageUrl( $sTag, $iPage, $iLang ) ) ) {
00211                 // only if page number > 0
00212                 $sUrl = $sSeoUrl;
00213             }
00214         }
00215 
00216         return ( !$blSeo || !$sSeoUrl ) ? oxUBase::_addPageNrParam( $sUrl, $iPage, $iLang ) : $sUrl;
00217     }
00218 
00224     public function getArticleList()
00225     {
00226         if ( $this->_aArticleList === null ) {
00227             if ( ( $this->getTag() ) ) {
00228                 $this->_aArticleList = $this->_loadArticles( null );
00229             }
00230         }
00231 
00232         return $this->_aArticleList;
00233     }
00234 
00240     public function getTag()
00241     {
00242         if ( $this->_sTag === null ) {
00243             $this->_sTag = oxConfig::getParameter("searchtag", 1);
00244         }
00245         return $this->_sTag;
00246     }
00247 
00253     public function getTitle()
00254     {
00255         if ( $this->_sTagTitle === null ) {
00256             $this->_sTagTitle = false;
00257             if ( ( $sTag = $this->getTag() ) ) {
00258                 $oStr = getStr();
00259                 $sTitle = $oStr->ucfirst( $sTag );
00260                 $this->_sTagTitle = $oStr->htmlspecialchars( $sTitle );
00261             }
00262         }
00263         return $this->_sTagTitle;
00264     }
00265 
00273     public function getTemplateLocation()
00274     {
00275         if ( $this->_sTemplateLocation === null ) {
00276             $this->_sTemplateLocation = false;
00277             if ( ( $sTag = $this->getTag() ) ) {
00278                 $oStr = getStr();
00279                 $sTitle = $oStr->ucfirst( $sTag );
00280                 $this->_sTemplateLocation = oxLang::getInstance()->translateString('TAGS')." / ".$oStr->htmlspecialchars( $sTitle );
00281             }
00282         }
00283         return $this->_sTemplateLocation;
00284     }
00285 
00291     public function getTreePath()
00292     {
00293         if ( ( $sTag = $this->getTag() ) ) {
00294             $oStr = getStr();
00295 
00296             $aPath[0] = oxNew( "oxcategory" );
00297             $aPath[0]->setLink( false );
00298             $aPath[0]->oxcategories__oxtitle = new oxField( oxLang::getInstance()->translateString('TAGS') );
00299 
00300             $aPath[1] = oxNew( "oxcategory" );
00301             $aPath[1]->setLink( false );
00302             $aPath[1]->oxcategories__oxtitle = new oxField( $oStr->ucfirst( $sTag ) );
00303             return $aPath;
00304         }
00305     }
00306 
00312     public function getActiveCategory()
00313     {
00314         return $this->getActTag();
00315     }
00316 
00326     protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00327     {
00328         return parent::_collectMetaKeyword( $sKeywords );
00329     }
00330 
00341     protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00342     {
00343         return parent::_collectMetaDescription( $sMeta, $iLength, $blDescTag );
00344     }
00345 
00351     public function getCanonicalUrl()
00352     {
00353         if ( ( $iPage = $this->getActPage() ) ) {
00354             return $this->_addPageNrParam( $this->generatePageNavigationUrl(), $iPage );
00355         } elseif ( ( $sTag = $this->getTag() ) ) {
00356             return oxSeoEncoderTag::getInstance()->getTagUrl( $sTag );
00357         }
00358     }
00359 }