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 $_oArtCategories = null;
00028 
00034     protected $_oArtVendors = null;
00035 
00041     protected $_oArtManufacturers = null;
00042 
00048     protected $_oArticle = null;
00049 
00056     public function render()
00057     {
00058         $oArticle = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00059 
00060         $this->_aViewData["edit"] = $oArticle;
00061         $this->_aViewData["blShowCatSelect"] = true;
00062         $this->_aViewData["oCategories"]     = $this->_getCategoryList( $oArticle );
00063         $this->_aViewData["oVendors"]        = $this->_getVendorList( $oArticle );
00064         $this->_aViewData["oManufacturers"]  = $this->_getManufacturerList( $oArticle );
00065         $this->_aViewData["oTags"]           = $this->_getTagList( $oArticle );
00066         $this->_aViewData["sCatId"]          = $this->getSelectedCategoryId();
00067         $this->_aViewData["sCatType"]        = $this->_sActCatType;
00068 
00069         return parent::render();
00070     }
00071 
00077     protected function _getSeoDataSql( $oObject, $iShopId, $iLang )
00078     {
00079         $sParam = ( $sCat = $this->getSelectedCategoryId() ) ? " and oxparams = '$sCat' " : '';
00080         $sQ = "select * from oxseo where oxobjectid = '".$oObject->getId()."' and
00081                oxshopid = '{$iShopId}' and oxlang = {$iLang} {$sParam} ";
00082         return $sQ;
00083     }
00084 
00090     protected function _getCategoryList( $oArticle )
00091     {
00092         if ( $this->_oArtCategories === null ) {
00093             $this->_oArtCategories = ( $oArticle ) ? oxSeoEncoderArticle::getInstance()->getSeoCategories( $oArticle ) : false;
00094 
00095             // adding price categories
00096             $sCatTable = "oxcategories";
00097             $sQ = "select oxid from $sCatTable where ( oxpricefrom != 0 || oxpriceto != 0 ) and ( oxpricefrom <= '{$oArticle->oxarticles__oxprice->value}' || oxpriceto >= '{$oArticle->oxarticles__oxprice->value}' ) ";
00098             $rs = oxDb::getDb( true )->execute( $sQ );
00099             if ( $rs != false && $rs->recordCount() > 0 ) {
00100                 while ( !$rs->EOF ) {
00101                     $oCat = oxNew('oxcategory');
00102                     $oCat->setLanguage($iLang);
00103                     if ( $oCat->load( $rs->fields['oxid'] ) ) {
00104                         $this->_oArtCategories[] = $oCat;
00105                     }
00106                     $rs->moveNext();
00107                 }
00108             }
00109 
00110         }
00111 
00112         return $this->_oArtCategories;
00113     }
00114 
00120     protected function _getVendorList( $oArticle )
00121     {
00122         if ( $this->_oArtVendors === null ) {
00123             $this->_oArtVendors = false;
00124 
00125             if ( $oArticle->oxarticles__oxvendorid->value ) {
00126                 $oVendor = oxNew( 'oxvendor' );
00127                 if ( $oVendor->loadInLang( $this->_iEditLang, $oArticle->oxarticles__oxvendorid->value ) ) {
00128                     $this->_oArtVendors = oxNew( 'oxList', 'oxvendor' );
00129                     $this->_oArtVendors[] = $oVendor;
00130                 }
00131             }
00132         }
00133         return $this->_oArtVendors;
00134     }
00135 
00141     protected function _getManufacturerList( $oArticle )
00142     {
00143         if ( $this->_oArtManufacturers === null ) {
00144             $this->_oArtManufacturers = false;
00145 
00146             if ( $oArticle->oxarticles__oxmanufacturerid->value ) {
00147                 $oManufacturer = oxNew( 'oxmanufacturer' );
00148                 if ( $oManufacturer->loadInLang( $this->_iEditLang, $oArticle->oxarticles__oxmanufacturerid->value ) ) {
00149                     $this->_oArtManufacturers = oxNew( 'oxList', 'oxmanufacturer' );
00150                     $this->_oArtManufacturers[] = $oManufacturer;
00151                 }
00152             }
00153         }
00154         return $this->_oArtManufacturers;
00155     }
00156 
00162     protected function _getTagList( $oArticle )
00163     {
00164         $oTagCloud = oxNew("oxTagCloud");
00165         return $oTagCloud->getTags( $oArticle->getId() );
00166     }
00167 
00173     public function getSelectedCategoryId()
00174     {
00175         if ( $this->_sActCatId === null) {
00176             $this->_sActCatId   = false;
00177             $this->_sActCatType = false;
00178 
00179             $aSeoData = oxConfig::getParameter( 'aSeoData' );
00180             if ( $aSeoData && isset( $aSeoData['oxparams'] ) ) {
00181                 if ( $sData = $aSeoData['oxparams'] ) {
00182                     $this->_sActCatId   = substr( $sData, strpos( $sData, '#' ) + 1 );
00183                     $this->_sActCatType = substr( $sData, 0, strpos( $sData, '#' ) );
00184                 }
00185             } else {
00186                 $oArticle = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00187                 if ( ( $oList = $this->_getCategoryList( $oArticle ) ) && $oList->count() ) {
00188                     $this->_sActCatType = 'oxcategories';
00189                     $this->_sActCatId   = $oList->current()->oxcategories__oxrootid->value;
00190                 } elseif ( ( $oList = $this->_getVendorList( $oArticle ) ) && $oList->count() ) {
00191                     $this->_sActCatType = 'oxvendor';
00192                     $this->_sActCatId   = $oList->current()->getId();
00193                 } elseif ( ( $oList = $this->_getManufacturerList( $oArticle ) ) && $oList->count() ) {
00194                     $this->_sActCatType = 'oxmanufacturer';
00195                     $this->_sActCatId   = $oList->current()->getId();
00196                 } elseif ( ( $aTagList = $this->_getTagList( $oArticle ) ) && count( $aTagList ) ) {
00197                     $this->_sActCatType = 'oxtag';
00198                     $this->_sActCatId   = key( $aTagList );
00199                 }
00200             }
00201         }
00202 
00203         return $this->_sActCatId;
00204     }
00205 
00211     protected function _getSeoUrl( $oArticle )
00212     {
00213         // setting cat type and id ..
00214         $this->getSelectedCategoryId();
00215 
00216         // choosing type
00217         switch ( $this->_sActCatType ) {
00218             case 'oxvendor':
00219                 $sType = OXARTICLE_LINKTYPE_VENDOR;
00220                 break;
00221             case 'oxmanufacturer':
00222                 $sType = OXARTICLE_LINKTYPE_MANUFACTURER;
00223                 break;
00224             case 'oxtag':
00225                 $sType = OXARTICLE_LINKTYPE_TAG;
00226                 break;
00227             default:
00228                 $sType = OXARTICLE_LINKTYPE_CATEGORY;
00229                 $oCat = oxNew( 'oxcategory' );
00230                 $oCat->load( $this->_sActCatId );
00231                 if ( $oCat->isPriceCategory() ) {
00232                     $sType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00233                 }
00234         }
00235 
00236         oxSeoEncoderArticle::getInstance()->getArticleUrl( $oArticle, null, $sType );
00237         return parent::_getSeoUrl( $oArticle );
00238     }
00239 
00245     public function getActCategory()
00246     {
00247         $oCat = oxNew( 'oxcategory' );
00248         $oCat->load( $this->_sActCatId );
00249         if ( $oCat->isPriceCategory() ) {
00250             return $oCat;
00251         }
00252     }
00253 
00259     public function getTag()
00260     {
00261         $sTag = $this->getSelectedCategoryId();
00262         if ( $this->_sActCatType == 'oxtag' ) {
00263             return $sTag;
00264         }
00265     }
00266 
00274      protected function _getSeoUrlQuery( $oObject, $iShopId )
00275      {
00276         // tag type urls are loaded differently from others..
00277         if ( $sTag = $this->getTag() ) {
00278 
00279             $sStdUrl = "index.php?cl=details&amp;anid=".$oObject->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
00280             $sObjectId = md5( strtolower( $oObject->getShopId() . $sStdUrl ) );
00281             $sQ = "select oxseourl from oxseo where oxobjectid = '".$sObjectId."'
00282                    and oxshopid = '{$iShopId}' and oxlang = {$this->_iEditLang}";
00283 
00284         } else {
00285             $sQ = "select oxseourl from oxseo where oxobjectid = '".$oObject->getId()."'
00286                    and oxshopid = '{$iShopId}' and oxlang = {$this->_iEditLang}
00287                    and oxparams = '{$this->_sActCatId}' ";
00288         }
00289 
00290         return $sQ;
00291      }
00292 
00298     protected function getSeoEntryId()
00299     {
00300         if ( $sTag = $this->getTag() ) {
00301             $oObject = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00302             $sStdUrl = "index.php?cl=details&amp;anid=".$oObject->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
00303             return md5( strtolower( $oObject->getShopId() . $sStdUrl ) );
00304         } else {
00305             return parent::getSeoEntryId();
00306         }
00307     }
00308 
00314     protected function _getSeoEntryType()
00315     {
00316         if ( $this->getTag() ) {
00317             return 'dynamic';
00318         } else {
00319             return $this->_getType();
00320         }
00321     }
00322 
00327     protected function _getType()
00328     {
00329         return 'oxarticle';
00330     }
00331 
00336     protected function _getStdUrl( $sOxid )
00337     {
00338         $oArticle = oxNew( 'oxarticle' );
00339         $oArticle->loadInLang( $this->_iEditLang, $sOxid );
00340         $sStdLink = $oArticle->getLink();
00341 
00342         // adding vendor or manufacturer id
00343         switch ( $this->_sActCatType ) {
00344             case 'oxvendor':
00345                 $sStdLink .= '&amp;cnid=v_'.$this->getSelectedCategoryId();
00346                 break;
00347             case 'oxmanufacturer':
00348                 $sStdLink .= '&amp;mnid='.$this->getSelectedCategoryId();
00349                 break;
00350             case 'oxtag':
00351                 $sStdLink = "index.php?cl=details&amp;anid=".$oArticle->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $this->getTag() );
00352                 break;
00353         }
00354 
00355         return $sStdLink;
00356     }
00357 
00365     public function processParam( $sParam )
00366     {
00367         if ($this->getTag()) {
00368             return '';
00369         } else {
00370             return trim( substr( $sParam, strpos( $sParam, '#') ), '#' );
00371         }
00372     }
00373 }

Generated on Wed Jun 17 12:09:01 2009 for OXID eShop CE by  doxygen 1.5.5