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->getActCategoryLang();
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->getActCategoryLang();
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 && $oArticle ) {
00108             // adding categories
00109             $sO2CView = getViewName( 'oxobject2category');
00110             $oDb = oxDb::getDb( true );
00111             $sQ = "select oxobject2category.oxcatnid as oxid from $sO2CView as oxobject2category where oxobject2category.oxobjectid="
00112                   . $oDb->quote( $oArticle->getId() ) . " union ".$oArticle->getSqlForPriceCategories('oxid');
00113 
00114             $iLang = $this->getEditLang();
00115             $this->_oArtCategories = oxNew( "oxList" );
00116             $rs = $oDb->execute( $sQ );
00117             if ( $rs != false && $rs->recordCount() > 0 ) {
00118                 while ( !$rs->EOF ) {
00119                     $oCat = oxNew('oxcategory');
00120                     $oCat->setLanguage( $iLang );
00121                     if ( $oCat->load( current( $rs->fields ) ) ) {
00122                         $this->_oArtCategories->offsetSet( $oCat->getId(), $oCat );
00123                     }
00124                     $rs->moveNext();
00125                 }
00126             }
00127         }
00128 
00129         return $this->_oArtCategories;
00130     }
00131 
00137     protected function _getVendorList( $oArticle )
00138     {
00139         if ( $this->_oArtVendors === null ) {
00140             $this->_oArtVendors = false;
00141 
00142             if ( $oArticle->oxarticles__oxvendorid->value ) {
00143                 $oVendor = oxNew( 'oxvendor' );
00144                 if ( $oVendor->loadInLang( $this->_iEditLang, $oArticle->oxarticles__oxvendorid->value ) ) {
00145                     $this->_oArtVendors = oxNew( 'oxList', 'oxvendor' );
00146                     $this->_oArtVendors[] = $oVendor;
00147                 }
00148             }
00149         }
00150         return $this->_oArtVendors;
00151     }
00152 
00158     protected function _getManufacturerList( $oArticle )
00159     {
00160         if ( $this->_oArtManufacturers === null ) {
00161             $this->_oArtManufacturers = false;
00162 
00163             if ( $oArticle->oxarticles__oxmanufacturerid->value ) {
00164                 $oManufacturer = oxNew( 'oxmanufacturer' );
00165                 if ( $oManufacturer->loadInLang( $this->_iEditLang, $oArticle->oxarticles__oxmanufacturerid->value ) ) {
00166                     $this->_oArtManufacturers = oxNew( 'oxList', 'oxmanufacturer' );
00167                     $this->_oArtManufacturers[] = $oManufacturer;
00168                 }
00169             }
00170         }
00171         return $this->_oArtManufacturers;
00172     }
00173 
00179     protected function _getTagList( $oArticle )
00180     {
00181         $oTagCloud = oxNew("oxTagCloud");
00182         $aLangs = $oArticle->getAvailableInLangs();
00183 
00184         $aLangTags = array();
00185         foreach ( $aLangs as $iLang => $sLangTitle ) {
00186             if ( count( $aTags = $oTagCloud->getTags( $oArticle->getId(), false, $iLang ) ) ) {
00187                 $aLangTags[$iLang] = $aTags;
00188             }
00189         }
00190 
00191         return $aLangTags;
00192     }
00193 
00199     public function getSelectedCategoryId()
00200     {
00201         if ( $this->_sActCatId === null) {
00202             $this->_sActCatId   = false;
00203             $this->_sActCatType = false;
00204 
00205             $aSeoData = oxConfig::getParameter( 'aSeoData' );
00206             if ( $aSeoData && isset( $aSeoData['oxparams'] ) ) {
00207                 if ( $sData = $aSeoData['oxparams'] ) {
00208                     $this->_sActCatId = substr( $sData, strpos( $sData, '#' ) + 1 );
00209                     if ( strpos( $this->_sActCatId, '#' ) !== false ) {
00210                         $this->_sActCatId = substr( $this->_sActCatId, 0, strpos( $this->_sActCatId, '#' ) );
00211                     }
00212                     $this->_iActCatLang = substr( $sData, strrpos( $sData, '#' ) + 1 );
00213                     $this->_sActCatType = substr( $sData, 0, strpos( $sData, '#' ) );
00214                 }
00215             } else {
00216                 $oArticle = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00217                 if ( ( $oList = $this->_getCategoryList( $oArticle ) ) && $oList->count() ) {
00218                     $this->_sActCatType = 'oxcategories';
00219                     $this->_sActCatId   = $oList->current()->getId();
00220                 } elseif ( ( $oList = $this->_getVendorList( $oArticle ) ) && $oList->count() ) {
00221                     $this->_sActCatType = 'oxvendor';
00222                     $this->_sActCatId   = $oList->current()->getId();
00223                 } elseif ( ( $oList = $this->_getManufacturerList( $oArticle ) ) && $oList->count() ) {
00224                     $this->_sActCatType = 'oxmanufacturer';
00225                     $this->_sActCatId   = $oList->current()->getId();
00226                 } elseif ( ( $aTagList = $this->_getTagList( $oArticle ) ) && count( $aTagList ) ) {
00227                     $this->_sActCatType = 'oxtag';
00228                     $this->_sActCatId   = key( $aTagList );
00229                 }
00230             }
00231         }
00232 
00233         return $this->_sActCatId;
00234     }
00235 
00241     protected function _getSeoUrl( $oArticle )
00242     {
00243         // setting cat type and id ..
00244         $this->getSelectedCategoryId();
00245 
00246         // choosing type
00247         switch ( $this->_sActCatType ) {
00248             case 'oxvendor':
00249                 $sType = OXARTICLE_LINKTYPE_VENDOR;
00250                 break;
00251             case 'oxmanufacturer':
00252                 $sType = OXARTICLE_LINKTYPE_MANUFACTURER;
00253                 break;
00254             case 'oxtag':
00255                 $sType = OXARTICLE_LINKTYPE_TAG;
00256                 break;
00257             default:
00258                 $sType = OXARTICLE_LINKTYPE_CATEGORY;
00259                 $oCat = oxNew( 'oxcategory' );
00260                 $oCat->load( $this->_sActCatId );
00261                 if ( $oCat->isPriceCategory() ) {
00262                     $sType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00263                 }
00264         }
00265 
00266         oxSeoEncoderArticle::getInstance()->getArticleUrl( $oArticle, $this->getEditLang(), $sType );
00267         return parent::_getSeoUrl( $oArticle );
00268     }
00269 
00275     public function getActCategory()
00276     {
00277         $oCat = oxNew( 'oxcategory' );
00278         if ( $oCat->load( $this->_sActCatId ) ) {
00279             return $oCat;
00280         }
00281     }
00282 
00288     public function getTag()
00289     {
00290         $sTag = $this->getSelectedCategoryId();
00291         if ( $this->_sActCatType == 'oxtag' ) {
00292             return $sTag;
00293         }
00294     }
00295 
00303      protected function _getSeoUrlQuery( $oObject, $iShopId )
00304      {
00305         $oDb = oxDb::getDb();
00306 
00307          // tag type urls are loaded differently from others..
00308         if ( $sTag = $this->getTag() ) {
00309 
00310             $sStdUrl = "index.php?cl=details&amp;anid=".$oObject->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
00311             $sObjectId = md5( strtolower( $oObject->getShopId() . $sStdUrl ) );
00312             $sQ = "select oxseourl from oxseo where oxobjectid = ".$oDb->quote( $sObjectId )."
00313                    and oxshopid = '{$iShopId}' and oxlang = ".$this->getActCategoryLang();
00314         } else {
00315             $sQ = "select oxseourl from oxseo where oxobjectid = ".$oDb->quote( $oObject->getId() )."
00316                    and oxshopid = '{$iShopId}' and oxlang = {$this->_iEditLang}
00317                    and oxparams = '{$this->_sActCatId}' ";
00318         }
00319 
00320         return $sQ;
00321     }
00322 
00328     public function getEditLang()
00329     {
00330         $iLang = $this->_iEditLang;
00331         if ( $this->getTag() ) {
00332             $iLang = $this->getActCategoryLang();
00333         }
00334         return $iLang;
00335     }
00336 
00342     public function getActCategoryLang()
00343     {
00344         return (int) $this->_iActCatLang;
00345     }
00346 
00352     protected function getSeoEntryId()
00353     {
00354         if ( $sTag = $this->getTag() ) {
00355             $oObject = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00356             $sStdUrl = "index.php?cl=details&amp;anid=".$oObject->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
00357             return md5( strtolower( $oObject->getShopId() . $sStdUrl ) );
00358         } else {
00359             return parent::getSeoEntryId();
00360         }
00361     }
00362 
00368     protected function _getSeoEntryType()
00369     {
00370         if ( $this->getTag() ) {
00371             return 'dynamic';
00372         } else {
00373             return $this->_getType();
00374         }
00375     }
00376 
00381     protected function _getType()
00382     {
00383         return 'oxarticle';
00384     }
00385 
00390     protected function _getStdUrl( $sOxid )
00391     {
00392         $oArticle = oxNew( 'oxarticle' );
00393         $oArticle->loadInLang( $this->_iEditLang, $sOxid );
00394         $sStdLink = $oArticle->getStdLink();
00395 
00396         // adding vendor or manufacturer id
00397         switch ( $this->_sActCatType ) {
00398             case 'oxvendor':
00399                 $sStdLink .= '&amp;cnid=v_'.$this->getSelectedCategoryId();
00400                 break;
00401             case 'oxmanufacturer':
00402                 $sStdLink .= '&amp;mnid='.$this->getSelectedCategoryId();
00403                 break;
00404             case 'oxtag':
00405                 $sStdLink = "index.php?cl=details&amp;anid=".$oArticle->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $this->getTag() );
00406                 break;
00407         }
00408 
00409         return $sStdLink;
00410     }
00411 
00419     public function processParam( $sParam )
00420     {
00421         if ($this->getTag()) {
00422             return '';
00423         } else {
00424             return trim( substr( $sParam, strpos( $sParam, '#') ), '#' );
00425         }
00426     }
00427 }

Generated on Mon Oct 26 20:07:15 2009 for OXID eShop CE by  doxygen 1.5.5