article_seo.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class Article_Seo extends Object_Seo
00007 {
00013     protected $_sActCatId = null;
00014 
00020     protected $_sActCatType = null;
00021 
00027     protected $_iActCatLang = null;
00028 
00034     protected $_oArtCategories = null;
00035 
00041     protected $_oArtVendors = null;
00042 
00048     protected $_oArtManufacturers = null;
00049 
00055     protected $_oArticle = null;
00056 
00063     public function render()
00064     {
00065         $oArticle = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00066 
00067         $this->_aViewData["edit"] = $oArticle;
00068         $this->_aViewData["blShowCatSelect"] = true;
00069         $this->_aViewData["oCategories"]     = $this->_getCategoryList( $oArticle );
00070         $this->_aViewData["oVendors"]        = $this->_getVendorList( $oArticle );
00071         $this->_aViewData["oManufacturers"]  = $this->_getManufacturerList( $oArticle );
00072         $this->_aViewData["oTags"]           = $this->_getTagList( $oArticle );
00073         $this->_aViewData["sCatId"]          = $this->getSelectedCategoryId();
00074         $this->_aViewData["sCatType"]        = $this->_sActCatType;
00075         $this->_aViewData["sCatLang"]        = $this->_iActCatLang;
00076 
00077         return parent::render();
00078     }
00079 
00085     protected function _getSeoDataSql( $oObject, $iShopId, $iLang )
00086     {
00087         $oDb = oxDb::getDb();
00088         if ( $this->_sActCatType == 'oxtag' ) {
00089             $sObjectId = oxSeoEncoderArticle::getInstance()->getDynamicObjectId( $iShopId, $oObject->getStdTagLink( $this->getTag() ) );
00090             $sQ = "select * from oxseo where oxobjectid = ".$oDb->quote( $sObjectId ) . " and
00091                    oxshopid = '{$iShopId}' and oxlang = {$this->_iActCatLang} ";
00092         } else {
00093             $sParam = ( $sCat = $this->getSelectedCategoryId() ) ? " and oxparams = '$sCat' " : '';
00094             $sQ = "select * from oxseo where oxobjectid = ".$oDb->quote( $oObject->getId() ) . " and
00095                    oxshopid = '{$iShopId}' and oxlang = {$iLang} {$sParam} ";
00096         }
00097         return $sQ;
00098     }
00099 
00105     protected function _getCategoryList( $oArticle )
00106     {
00107         if ( $this->_oArtCategories === null ) {
00108             $this->_oArtCategories = ( $oArticle ) ? oxSeoEncoderArticle::getInstance()->getSeoCategories( $oArticle ) : false;
00109 
00110             // adding price categories
00111             $sCatTable = "oxcategories";
00112             $oDb = oxDb::getDb( true );
00113             $sQ = "select oxid from $sCatTable where ( oxpricefrom != 0 || oxpriceto != 0 ) and ( oxpricefrom <= ".$oDb->quote( $oArticle->oxarticles__oxprice->value ) ." || oxpriceto >= ".$oDb->quote( $oArticle->oxarticles__oxprice->value ) ." ) ";
00114             $rs = $oDb->execute( $sQ );
00115             if ( $rs != false && $rs->recordCount() > 0 ) {
00116                 while ( !$rs->EOF ) {
00117                     $oCat = oxNew('oxcategory');
00118                     $oCat->setLanguage($iLang);
00119                     if ( $oCat->load( $rs->fields['oxid'] ) ) {
00120                         $this->_oArtCategories[] = $oCat;
00121                     }
00122                     $rs->moveNext();
00123                 }
00124             }
00125 
00126         }
00127 
00128         return $this->_oArtCategories;
00129     }
00130 
00136     protected function _getVendorList( $oArticle )
00137     {
00138         if ( $this->_oArtVendors === null ) {
00139             $this->_oArtVendors = false;
00140 
00141             if ( $oArticle->oxarticles__oxvendorid->value ) {
00142                 $oVendor = oxNew( 'oxvendor' );
00143                 if ( $oVendor->loadInLang( $this->_iEditLang, $oArticle->oxarticles__oxvendorid->value ) ) {
00144                     $this->_oArtVendors = oxNew( 'oxList', 'oxvendor' );
00145                     $this->_oArtVendors[] = $oVendor;
00146                 }
00147             }
00148         }
00149         return $this->_oArtVendors;
00150     }
00151 
00157     protected function _getManufacturerList( $oArticle )
00158     {
00159         if ( $this->_oArtManufacturers === null ) {
00160             $this->_oArtManufacturers = false;
00161 
00162             if ( $oArticle->oxarticles__oxmanufacturerid->value ) {
00163                 $oManufacturer = oxNew( 'oxmanufacturer' );
00164                 if ( $oManufacturer->loadInLang( $this->_iEditLang, $oArticle->oxarticles__oxmanufacturerid->value ) ) {
00165                     $this->_oArtManufacturers = oxNew( 'oxList', 'oxmanufacturer' );
00166                     $this->_oArtManufacturers[] = $oManufacturer;
00167                 }
00168             }
00169         }
00170         return $this->_oArtManufacturers;
00171     }
00172 
00178     protected function _getTagList( $oArticle )
00179     {
00180         $oTagCloud = oxNew("oxTagCloud");
00181         $aLangs = $oArticle->getAvailableInLangs();
00182 
00183         $aLangTags = array();
00184         foreach ( $aLangs as $iLang => $sLangTitle ) {
00185             if ( count( $aTags = $oTagCloud->getTags( $oArticle->getId(), false, $iLang ) ) ) {
00186                 $aLangTags[$iLang] = $aTags;
00187             }
00188         }
00189 
00190         return $aLangTags;
00191     }
00192 
00198     public function getSelectedCategoryId()
00199     {
00200         if ( $this->_sActCatId === null) {
00201             $this->_sActCatId   = false;
00202             $this->_sActCatType = false;
00203 
00204             $aSeoData = oxConfig::getParameter( 'aSeoData' );
00205             if ( $aSeoData && isset( $aSeoData['oxparams'] ) ) {
00206                 if ( $sData = $aSeoData['oxparams'] ) {
00207                     $this->_sActCatId = substr( $sData, strpos( $sData, '#' ) + 1 );
00208                     if ( strpos( $this->_sActCatId, '#' ) !== false ) {
00209                         $this->_sActCatId = substr( $this->_sActCatId, 0, strpos( $this->_sActCatId, '#' ) );
00210                     }
00211                     $this->_iActCatLang = substr( $sData, strrpos( $sData, '#' ) + 1 );
00212                     $this->_sActCatType = substr( $sData, 0, strpos( $sData, '#' ) );
00213                 }
00214             } else {
00215                 $oArticle = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00216                 if ( ( $oList = $this->_getCategoryList( $oArticle ) ) && $oList->count() ) {
00217                     $this->_sActCatType = 'oxcategories';
00218                     $this->_sActCatId   = $oList->current()->oxcategories__oxrootid->value;
00219                 } elseif ( ( $oList = $this->_getVendorList( $oArticle ) ) && $oList->count() ) {
00220                     $this->_sActCatType = 'oxvendor';
00221                     $this->_sActCatId   = $oList->current()->getId();
00222                 } elseif ( ( $oList = $this->_getManufacturerList( $oArticle ) ) && $oList->count() ) {
00223                     $this->_sActCatType = 'oxmanufacturer';
00224                     $this->_sActCatId   = $oList->current()->getId();
00225                 } elseif ( ( $aTagList = $this->_getTagList( $oArticle ) ) && count( $aTagList ) ) {
00226                     $this->_sActCatType = 'oxtag';
00227                     $this->_sActCatId   = key( $aTagList );
00228                 }
00229             }
00230         }
00231 
00232         return $this->_sActCatId;
00233     }
00234 
00240     protected function _getSeoUrl( $oArticle )
00241     {
00242         // setting cat type and id ..
00243         $this->getSelectedCategoryId();
00244 
00245         // choosing type
00246         switch ( $this->_sActCatType ) {
00247             case 'oxvendor':
00248                 $sType = OXARTICLE_LINKTYPE_VENDOR;
00249                 break;
00250             case 'oxmanufacturer':
00251                 $sType = OXARTICLE_LINKTYPE_MANUFACTURER;
00252                 break;
00253             case 'oxtag':
00254                 $sType = OXARTICLE_LINKTYPE_TAG;
00255                 break;
00256             default:
00257                 $sType = OXARTICLE_LINKTYPE_CATEGORY;
00258                 $oCat = oxNew( 'oxcategory' );
00259                 $oCat->load( $this->_sActCatId );
00260                 if ( $oCat->isPriceCategory() ) {
00261                     $sType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00262                 }
00263         }
00264 
00265         oxSeoEncoderArticle::getInstance()->getArticleUrl( $oArticle, $this->getEditLang(), $sType );
00266         return parent::_getSeoUrl( $oArticle );
00267     }
00268 
00274     public function getActCategory()
00275     {
00276         $oCat = oxNew( 'oxcategory' );
00277         if ( $oCat->load( $this->_sActCatId ) ) {
00278             return $oCat;
00279         }
00280     }
00281 
00287     public function getTag()
00288     {
00289         $sTag = $this->getSelectedCategoryId();
00290         if ( $this->_sActCatType == 'oxtag' ) {
00291             return $sTag;
00292         }
00293     }
00294 
00302      protected function _getSeoUrlQuery( $oObject, $iShopId )
00303      {
00304         $oDb = oxDb::getDb();
00305 
00306          // tag type urls are loaded differently from others..
00307         if ( $sTag = $this->getTag() ) {
00308 
00309             $sStdUrl = "index.php?cl=details&amp;anid=".$oObject->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
00310             $sObjectId = md5( strtolower( $oObject->getShopId() . $sStdUrl ) );
00311             $sQ = "select oxseourl from oxseo where oxobjectid = ".$oDb->quote( $sObjectId )."
00312                    and oxshopid = '{$iShopId}' and oxlang = {$this->_iActCatLang}";
00313         } else {
00314             $sQ = "select oxseourl from oxseo where oxobjectid = ".$oDb->quote( $oObject->getId() )."
00315                    and oxshopid = '{$iShopId}' and oxlang = {$this->_iEditLang}
00316                    and oxparams = '{$this->_sActCatId}' ";
00317         }
00318 
00319         return $sQ;
00320     }
00321 
00327     public function getEditLang()
00328     {
00329         $iLang = $this->_iEditLang;
00330         if ( $this->getTag() ) {
00331             $iLang = (int) $this->_iActCatLang;
00332         }
00333         return $iLang;
00334     }
00335 
00341     protected function getSeoEntryId()
00342     {
00343         if ( $sTag = $this->getTag() ) {
00344             $oObject = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00345             $sStdUrl = "index.php?cl=details&amp;anid=".$oObject->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
00346             return md5( strtolower( $oObject->getShopId() . $sStdUrl ) );
00347         } else {
00348             return parent::getSeoEntryId();
00349         }
00350     }
00351 
00357     protected function _getSeoEntryType()
00358     {
00359         if ( $this->getTag() ) {
00360             return 'dynamic';
00361         } else {
00362             return $this->_getType();
00363         }
00364     }
00365 
00370     protected function _getType()
00371     {
00372         return 'oxarticle';
00373     }
00374 
00379     protected function _getStdUrl( $sOxid )
00380     {
00381         $oArticle = oxNew( 'oxarticle' );
00382         $oArticle->loadInLang( $this->_iEditLang, $sOxid );
00383         $sStdLink = $oArticle->getLink();
00384 
00385         // adding vendor or manufacturer id
00386         switch ( $this->_sActCatType ) {
00387             case 'oxvendor':
00388                 $sStdLink .= '&amp;cnid=v_'.$this->getSelectedCategoryId();
00389                 break;
00390             case 'oxmanufacturer':
00391                 $sStdLink .= '&amp;mnid='.$this->getSelectedCategoryId();
00392                 break;
00393             case 'oxtag':
00394                 $sStdLink = "index.php?cl=details&amp;anid=".$oArticle->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $this->getTag() );
00395                 break;
00396         }
00397 
00398         return $sStdLink;
00399     }
00400 
00408     public function processParam( $sParam )
00409     {
00410         if ($this->getTag()) {
00411             return '';
00412         } else {
00413             return trim( substr( $sParam, strpos( $sParam, '#') ), '#' );
00414         }
00415     }
00416 }

Generated on Tue Sep 29 16:45:11 2009 for OXID eShop CE by  doxygen 1.5.5