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 
00059     public function render()
00060     {
00061         oxUBase::render();
00062 
00063         $oArticleList = $this->getArticleList();
00064 
00065         // if tags are off or no articles - showing 404 header (#2139)
00066         if ( !$this->showTags() || !$oArticleList) {
00067             error_404_handler();
00068         }
00069 
00070         // processing list articles
00071         $this->_processListArticles();
00072 
00073         return $this->_sThisTemplate;
00074     }
00075 
00081     protected function _getProductLinkType()
00082     {
00083         return OXARTICLE_LINKTYPE_TAG;
00084     }
00085 
00091     public function getAddUrlParams()
00092     {
00093         $sAddParams  = parent::getAddUrlParams();
00094         $sAddParams .= ($sAddParams?'&amp;':'') . "listtype={$this->_sListType}";
00095         if ( $sParam = oxConfig::getParameter( 'searchtag', 1 ) ) {
00096             $sAddParams .= "&amp;searchtag=" . rawurlencode( $sParam );
00097         }
00098         return $sAddParams;
00099     }
00100 
00108     protected function _loadArticles( $oCategory )
00109     {
00110         // load only articles which we show on screen
00111         $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00112         $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00113         $oArtList = oxNew( 'oxarticlelist' );
00114         $oArtList->setSqlLimit( $iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles );
00115         $oArtList->setCustomSorting( $this->getSortingSql( $this->getSortIdent() ) );
00116         // load the articles
00117         $this->_iAllArtCnt = $oArtList->loadTagArticles( $this->getTag(), oxRegistry::getLang()->getBaseLanguage());
00118         $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00119 
00120         return $oArtList;
00121     }
00122 
00128     protected function _getCatPathString()
00129     {
00130         return $this->getTag();
00131     }
00132 
00138     protected function _getSeoObjectId()
00139     {
00140         return md5("tag" . $this->getTag() );
00141     }
00142 
00152     public function getSorting( $sCnid )
00153     {
00154         return parent::getSorting( $sCnid );
00155     }
00156 
00168     public function setItemSorting( $sCnid, $sSortBy, $sSortOrder  = null )
00169     {
00170         parent::setItemSorting( $sCnid, $sSortBy, $sSortOrder );
00171     }
00172 
00178     public function generatePageNavigationUrl()
00179     {
00180         if ( ( oxRegistry::getUtils()->seoIsActive() && ( $sTag = $this->getTag() ) ) ) {
00181             $sLink = oxRegistry::get("oxSeoEncoderTag")->getTagUrl( $sTag, oxRegistry::getLang()->getBaseLanguage() );
00182         }
00183         return $sLink ? $sLink : oxUBase::generatePageNavigationUrl();
00184     }
00185 
00195     protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00196     {
00197         $sSeoUrl = $blSeo = oxRegistry::getUtils()->seoIsActive();
00198         if ( $blSeo && ( $sTag = $this->getTag() ) ) {
00199             if ( $iPage && ( $sSeoUrl = oxRegistry::get("oxSeoEncoderTag")->getTagPageUrl( $sTag, $iPage, $iLang ) ) ) {
00200                 // only if page number > 0
00201                 $sUrl = $sSeoUrl;
00202             }
00203         }
00204 
00205         return ( !$blSeo || !$sSeoUrl ) ? oxUBase::_addPageNrParam( $sUrl, $iPage, $iLang ) : $sUrl;
00206     }
00207 
00213     public function getArticleList()
00214     {
00215         if ( $this->_aArticleList === null ) {
00216             if ( ( $this->getTag() ) ) {
00217                 $this->_aArticleList = $this->_loadArticles( null );
00218             }
00219         }
00220 
00221         return $this->_aArticleList;
00222     }
00223 
00229     public function getTag()
00230     {
00231         if ( $this->_sTag === null ) {
00232             $this->_sTag = oxConfig::getParameter("searchtag", 1);
00233         }
00234         return $this->_sTag;
00235     }
00236 
00242     public function getTitle()
00243     {
00244         if ( $this->_sTagTitle === null ) {
00245             $this->_sTagTitle = false;
00246             if ( ( $sTag = $this->getTag() ) ) {
00247                 $oStr = getStr();
00248                 $sTitle = $oStr->ucfirst( $sTag );
00249                 $this->_sTagTitle = $oStr->htmlspecialchars( $sTitle );
00250             }
00251         }
00252         return $this->_sTagTitle;
00253     }
00254 
00260     public function getTreePath()
00261     {
00262         if ( ( $sTag = $this->getTag() ) ) {
00263             $oStr = getStr();
00264 
00265             $aPath[0] = oxNew( "oxcategory" );
00266             $aPath[0]->setLink( false );
00267             $aPath[0]->oxcategories__oxtitle = new oxField( oxRegistry::getLang()->translateString('TAGS') );
00268 
00269             $aPath[1] = oxNew( "oxcategory" );
00270             $aPath[1]->setLink( false );
00271             $aPath[1]->oxcategories__oxtitle = new oxField( $oStr->ucfirst( $sTag ) );
00272             return $aPath;
00273         }
00274     }
00275 
00285     protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00286     {
00287         return parent::_collectMetaKeyword( $sKeywords );
00288     }
00289 
00300     protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00301     {
00302         return parent::_collectMetaDescription( $sMeta, $iLength, $blDescTag );
00303     }
00304 
00310     public function getCanonicalUrl()
00311     {
00312         if ( ( $iPage = $this->getActPage() ) ) {
00313             return $this->_addPageNrParam( $this->generatePageNavigationUrl(), $iPage );
00314         } elseif ( ( $sTag = $this->getTag() ) ) {
00315             return oxRegistry::get("oxSeoEncoderTag")->getTagUrl( $sTag );
00316         }
00317     }
00318 
00324     public function getBreadCrumb()
00325     {
00326         $aPaths = array();
00327         $aCatPath = array();
00328 
00329         $aCatPath['title'] = oxRegistry::getLang()->translateString( 'TAGS', oxRegistry::getLang()->getBaseLanguage(), false );
00330         $aCatPath['link']  = oxRegistry::get("oxSeoEncoder")->getStaticUrl( $this->getViewConfig()->getSelfLink() . 'cl=tags' );
00331         $aPaths[] = $aCatPath;
00332 
00333         $aCatPath['title'] = $this->getTitle();
00334         $aCatPath['link']  = $this->getCanonicalUrl();
00335         $aPaths[] = $aCatPath;
00336 
00337         return $aPaths;
00338     }
00339 
00340 }