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         if ( $this->_sActCatType == 'oxtag' ) {
00088             $sObjectId = oxSeoEncoderArticle::getInstance()->getDynamicObjectId( $iShopId, $oObject->getStdTagLink( $this->getTag() ) );
00089             $sQ = "select * from oxseo where oxobjectid = '".$sObjectId."' and
00090                    oxshopid = '{$iShopId}' and oxlang = {$this->_iActCatLang} ";
00091         } else {
00092             $sParam = ( $sCat = $this->getSelectedCategoryId() ) ? " and oxparams = '$sCat' " : '';
00093             $sQ = "select * from oxseo where oxobjectid = '".$oObject->getId()."' and
00094                    oxshopid = '{$iShopId}' and oxlang = {$iLang} {$sParam} ";
00095         }
00096         return $sQ;
00097     }
00098 
00104     protected function _getCategoryList( $oArticle )
00105     {
00106         if ( $this->_oArtCategories === null ) {
00107             $this->_oArtCategories = ( $oArticle ) ? oxSeoEncoderArticle::getInstance()->getSeoCategories( $oArticle ) : false;
00108 
00109             // adding price categories
00110             $sCatTable = "oxcategories";
00111             $sQ = "select oxid from $sCatTable where ( oxpricefrom != 0 || oxpriceto != 0 ) and ( oxpricefrom <= '{$oArticle->oxarticles__oxprice->value}' || oxpriceto >= '{$oArticle->oxarticles__oxprice->value}' ) ";
00112             $rs = oxDb::getDb( true )->execute( $sQ );
00113             if ( $rs != false && $rs->recordCount() > 0 ) {
00114                 while ( !$rs->EOF ) {
00115                     $oCat = oxNew('oxcategory');
00116                     $oCat->setLanguage($iLang);
00117                     if ( $oCat->load( $rs->fields['oxid'] ) ) {
00118                         $this->_oArtCategories[] = $oCat;
00119                     }
00120                     $rs->moveNext();
00121                 }
00122             }
00123 
00124         }
00125 
00126         return $this->_oArtCategories;
00127     }
00128 
00134     protected function _getVendorList( $oArticle )
00135     {
00136         if ( $this->_oArtVendors === null ) {
00137             $this->_oArtVendors = false;
00138 
00139             if ( $oArticle->oxarticles__oxvendorid->value ) {
00140                 $oVendor = oxNew( 'oxvendor' );
00141                 if ( $oVendor->loadInLang( $this->_iEditLang, $oArticle->oxarticles__oxvendorid->value ) ) {
00142                     $this->_oArtVendors = oxNew( 'oxList', 'oxvendor' );
00143                     $this->_oArtVendors[] = $oVendor;
00144                 }
00145             }
00146         }
00147         return $this->_oArtVendors;
00148     }
00149 
00155     protected function _getManufacturerList( $oArticle )
00156     {
00157         if ( $this->_oArtManufacturers === null ) {
00158             $this->_oArtManufacturers = false;
00159 
00160             if ( $oArticle->oxarticles__oxmanufacturerid->value ) {
00161                 $oManufacturer = oxNew( 'oxmanufacturer' );
00162                 if ( $oManufacturer->loadInLang( $this->_iEditLang, $oArticle->oxarticles__oxmanufacturerid->value ) ) {
00163                     $this->_oArtManufacturers = oxNew( 'oxList', 'oxmanufacturer' );
00164                     $this->_oArtManufacturers[] = $oManufacturer;
00165                 }
00166             }
00167         }
00168         return $this->_oArtManufacturers;
00169     }
00170 
00176     protected function _getTagList( $oArticle )
00177     {
00178         $oTagCloud = oxNew("oxTagCloud");
00179         $aLangs = $oArticle->getAvailableInLangs();
00180 
00181         $aLangTags = array();
00182         foreach ( $aLangs as $iLang => $sLangTitle ) {
00183             if ( count( $aTags = $oTagCloud->getTags( $oArticle->getId(), false, $iLang ) ) ) {
00184                 $aLangTags[$iLang] = $aTags;
00185             }
00186         }
00187 
00188         return $aLangTags;
00189     }
00190 
00196     public function getSelectedCategoryId()
00197     {
00198         if ( $this->_sActCatId === null) {
00199             $this->_sActCatId   = false;
00200             $this->_sActCatType = false;
00201 
00202             $aSeoData = oxConfig::getParameter( 'aSeoData' );
00203             if ( $aSeoData && isset( $aSeoData['oxparams'] ) ) {
00204                 if ( $sData = $aSeoData['oxparams'] ) {
00205                     $this->_sActCatId = substr( $sData, strpos( $sData, '#' ) + 1 );
00206                     if ( strpos( $this->_sActCatId, '#' ) !== false ) {
00207                         $this->_sActCatId = substr( $this->_sActCatId, 0, strpos( $this->_sActCatId, '#' ) );
00208                     }
00209                     $this->_iActCatLang = substr( $sData, strrpos( $sData, '#' ) + 1 );
00210                     $this->_sActCatType = substr( $sData, 0, strpos( $sData, '#' ) );
00211                 }
00212             } else {
00213                 $oArticle = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00214                 if ( ( $oList = $this->_getCategoryList( $oArticle ) ) && $oList->count() ) {
00215                     $this->_sActCatType = 'oxcategories';
00216                     $this->_sActCatId   = $oList->current()->oxcategories__oxrootid->value;
00217                 } elseif ( ( $oList = $this->_getVendorList( $oArticle ) ) && $oList->count() ) {
00218                     $this->_sActCatType = 'oxvendor';
00219                     $this->_sActCatId   = $oList->current()->getId();
00220                 } elseif ( ( $oList = $this->_getManufacturerList( $oArticle ) ) && $oList->count() ) {
00221                     $this->_sActCatType = 'oxmanufacturer';
00222                     $this->_sActCatId   = $oList->current()->getId();
00223                 } elseif ( ( $aTagList = $this->_getTagList( $oArticle ) ) && count( $aTagList ) ) {
00224                     $this->_sActCatType = 'oxtag';
00225                     $this->_sActCatId   = key( $aTagList );
00226                 }
00227             }
00228         }
00229 
00230         return $this->_sActCatId;
00231     }
00232 
00238     protected function _getSeoUrl( $oArticle )
00239     {
00240         // setting cat type and id ..
00241         $this->getSelectedCategoryId();
00242 
00243         // choosing type
00244         switch ( $this->_sActCatType ) {
00245             case 'oxvendor':
00246                 $sType = OXARTICLE_LINKTYPE_VENDOR;
00247                 break;
00248             case 'oxmanufacturer':
00249                 $sType = OXARTICLE_LINKTYPE_MANUFACTURER;
00250                 break;
00251             case 'oxtag':
00252                 $sType = OXARTICLE_LINKTYPE_TAG;
00253                 break;
00254             default:
00255                 $sType = OXARTICLE_LINKTYPE_CATEGORY;
00256                 $oCat = oxNew( 'oxcategory' );
00257                 $oCat->load( $this->_sActCatId );
00258                 if ( $oCat->isPriceCategory() ) {
00259                     $sType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00260                 }
00261         }
00262 
00263         oxSeoEncoderArticle::getInstance()->getArticleUrl( $oArticle, $this->getEditLang(), $sType );
00264         return parent::_getSeoUrl( $oArticle );
00265     }
00266 
00272     public function getActCategory()
00273     {
00274         $oCat = oxNew( 'oxcategory' );
00275         if ( $oCat->load( $this->_sActCatId ) ) {
00276             return $oCat;
00277         }
00278     }
00279 
00285     public function getTag()
00286     {
00287         $sTag = $this->getSelectedCategoryId();
00288         if ( $this->_sActCatType == 'oxtag' ) {
00289             return $sTag;
00290         }
00291     }
00292 
00300      protected function _getSeoUrlQuery( $oObject, $iShopId )
00301      {
00302         // tag type urls are loaded differently from others..
00303         if ( $sTag = $this->getTag() ) {
00304 
00305             $sStdUrl = "index.php?cl=details&amp;anid=".$oObject->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
00306             $sObjectId = md5( strtolower( $oObject->getShopId() . $sStdUrl ) );
00307             $sQ = "select oxseourl from oxseo where oxobjectid = '".$sObjectId."'
00308                    and oxshopid = '{$iShopId}' and oxlang = {$this->_iActCatLang}";
00309         } else {
00310             $sQ = "select oxseourl from oxseo where oxobjectid = '".$oObject->getId()."'
00311                    and oxshopid = '{$iShopId}' and oxlang = {$this->_iEditLang}
00312                    and oxparams = '{$this->_sActCatId}' ";
00313         }
00314 
00315         return $sQ;
00316     }
00317 
00323     public function getEditLang()
00324     {
00325         $iLang = $this->_iEditLang;
00326         if ( $this->getTag() ) {
00327             $iLang = (int) $this->_iActCatLang;
00328         }
00329         return $iLang;
00330     }
00331 
00337     protected function getSeoEntryId()
00338     {
00339         if ( $sTag = $this->getTag() ) {
00340             $oObject = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00341             $sStdUrl = "index.php?cl=details&amp;anid=".$oObject->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
00342             return md5( strtolower( $oObject->getShopId() . $sStdUrl ) );
00343         } else {
00344             return parent::getSeoEntryId();
00345         }
00346     }
00347 
00353     protected function _getSeoEntryType()
00354     {
00355         if ( $this->getTag() ) {
00356             return 'dynamic';
00357         } else {
00358             return $this->_getType();
00359         }
00360     }
00361 
00366     protected function _getType()
00367     {
00368         return 'oxarticle';
00369     }
00370 
00375     protected function _getStdUrl( $sOxid )
00376     {
00377         $oArticle = oxNew( 'oxarticle' );
00378         $oArticle->loadInLang( $this->_iEditLang, $sOxid );
00379         $sStdLink = $oArticle->getLink();
00380 
00381         // adding vendor or manufacturer id
00382         switch ( $this->_sActCatType ) {
00383             case 'oxvendor':
00384                 $sStdLink .= '&amp;cnid=v_'.$this->getSelectedCategoryId();
00385                 break;
00386             case 'oxmanufacturer':
00387                 $sStdLink .= '&amp;mnid='.$this->getSelectedCategoryId();
00388                 break;
00389             case 'oxtag':
00390                 $sStdLink = "index.php?cl=details&amp;anid=".$oArticle->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $this->getTag() );
00391                 break;
00392         }
00393 
00394         return $sStdLink;
00395     }
00396 
00404     public function processParam( $sParam )
00405     {
00406         if ($this->getTag()) {
00407             return '';
00408         } else {
00409             return trim( substr( $sParam, strpos( $sParam, '#') ), '#' );
00410         }
00411     }
00412 }

Generated on Tue Aug 18 09:21:04 2009 for OXID eShop CE by  doxygen 1.5.5