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 
00061     protected $_sNoCategoryId = '__nonecatid';
00062 
00069     public function render()
00070     {
00071         $oArticle = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00072 
00073         $this->_aViewData["edit"] = $oArticle;
00074         $this->_aViewData["blShowCatSelect"] = true;
00075         $this->_aViewData["oCategories"]     = $this->_getCategoryList( $oArticle );
00076         $this->_aViewData["oVendors"]        = $this->_getVendorList( $oArticle );
00077         $this->_aViewData["oManufacturers"]  = $this->_getManufacturerList( $oArticle );
00078         $this->_aViewData["oTags"]           = $this->_getTagList( $oArticle );
00079         $this->_aViewData["sCatId"]          = $this->getSelectedCategoryId();
00080         $this->_aViewData["sCatType"]        = $this->getActCatType();
00081         $this->_aViewData["sCatLang"]        = $this->getActCategoryLang();
00082 
00083         return parent::render();
00084     }
00085 
00095     protected function _getSeoDataSql( $oObject, $iShopId, $iLang )
00096     {
00097         $oDb = oxDb::getDb();
00098         if ( $this->getActCatType() == 'oxtag' ) {
00099             $sObjectId = $this->_getEncoder()->getDynamicObjectId( $iShopId, $oObject->getStdTagLink( $this->getTag() ) );
00100             $sQ = "select * from oxseo
00101                    left join oxobject2seodata on
00102                        oxobject2seodata.oxobjectid = ".$oDb->quote( $oObject->getId() ) . " and
00103                        oxobject2seodata.oxshopid = oxseo.oxshopid and
00104                        oxobject2seodata.oxlang = oxseo.oxlang
00105                    where
00106                        oxseo.oxobjectid = ".$oDb->quote( $sObjectId ) ."
00107                        and oxseo.oxshopid = '{$iShopId}' and oxseo.oxlang = ".$this->getActCategoryLang();
00108         } else {
00109             $sParam = ( $sCat = $this->getSelectedCategoryId() ) ? " and oxseo.oxparams = '$sCat' " : '';
00110             $sQ = "select * from oxseo
00111                    left join oxobject2seodata on
00112                        oxobject2seodata.oxobjectid = oxseo.oxobjectid and
00113                        oxobject2seodata.oxshopid = oxseo.oxshopid and
00114                        oxobject2seodata.oxlang = oxseo.oxlang
00115                     where oxseo.oxobjectid = ".$oDb->quote( $oObject->getId() ) . "
00116                     and oxseo.oxshopid = '{$iShopId}' and oxseo.oxlang = {$iLang} {$sParam} ";
00117         }
00118         return $sQ;
00119     }
00120 
00128     protected function _getCategoryList( $oArticle )
00129     {
00130         if ( $this->_oArtCategories === null && $oArticle ) {
00131             // adding categories
00132             $sO2CView = getViewName( 'oxobject2category');
00133             $oDb = oxDb::getDb( true );
00134             $sQ = "select oxobject2category.oxcatnid as oxid from $sO2CView as oxobject2category where oxobject2category.oxobjectid="
00135                   . $oDb->quote( $oArticle->getId() ) . " union ".$oArticle->getSqlForPriceCategories('oxid');
00136 
00137             $iLang = $this->getEditLang();
00138             $this->_oArtCategories = oxNew( "oxList" );
00139             $rs = $oDb->execute( $sQ );
00140             if ( $rs != false && $rs->recordCount() > 0 ) {
00141                 while ( !$rs->EOF ) {
00142                     $oCat = oxNew('oxcategory');
00143                     $oCat->setLanguage( $iLang );
00144                     if ( $oCat->load( current( $rs->fields ) ) ) {
00145                         $this->_oArtCategories->offsetSet( $oCat->getId(), $oCat );
00146                     }
00147                     $rs->moveNext();
00148                 }
00149             }
00150 
00151             $this->_setMainCategory( $oArticle, $this->_oArtCategories);
00152         }
00153 
00154         return $this->_oArtCategories;
00155     }
00156 
00165     protected function _setMainCategory( $oProduct, $oCatList )
00166     {
00167         // loading main category
00168         if ( !( $oMainCat = $oProduct->getCategory() ) ) {
00169             $sTitle = oxLang::getInstance()->translateString( '(no category)', $this->_iEditLang );
00170             $oMainCat = oxNew( "oxCategory" );
00171             $oMainCat->setId( $this->_sNoCategoryId );
00172             $oMainCat->oxcategories__oxtitle = new oxField( $sTitle, oxField::T_RAW );
00173         }
00174 
00175         $sSuffix = oxLang::getInstance()->translateString( '(main category)', $this->_iEditLang );
00176         $oMainCat->oxcategories__oxtitle = new oxField( $oMainCat->oxcategories__oxtitle->getRawValue()." ".$sSuffix, oxField::T_RAW );
00177 
00178         // overriding
00179         $oCatList->offsetSet( $oMainCat->getId(), $oMainCat );
00180     }
00181 
00189     protected function _getVendorList( $oArticle )
00190     {
00191         if ( $this->_oArtVendors === null ) {
00192             $this->_oArtVendors = false;
00193 
00194             if ( $oArticle->oxarticles__oxvendorid->value ) {
00195                 $oVendor = oxNew( 'oxvendor' );
00196                 if ( $oVendor->loadInLang( $this->_iEditLang, $oArticle->oxarticles__oxvendorid->value ) ) {
00197                     $this->_oArtVendors = oxNew( 'oxList', 'oxvendor' );
00198                     $this->_oArtVendors[] = $oVendor;
00199                 }
00200             }
00201         }
00202         return $this->_oArtVendors;
00203     }
00204 
00212     protected function _getManufacturerList( $oArticle )
00213     {
00214         if ( $this->_oArtManufacturers === null ) {
00215             $this->_oArtManufacturers = false;
00216 
00217             if ( $oArticle->oxarticles__oxmanufacturerid->value ) {
00218                 $oManufacturer = oxNew( 'oxmanufacturer' );
00219                 if ( $oManufacturer->loadInLang( $this->_iEditLang, $oArticle->oxarticles__oxmanufacturerid->value ) ) {
00220                     $this->_oArtManufacturers = oxNew( 'oxList', 'oxmanufacturer' );
00221                     $this->_oArtManufacturers[] = $oManufacturer;
00222                 }
00223             }
00224         }
00225         return $this->_oArtManufacturers;
00226     }
00227 
00235     protected function _getTagList( $oArticle )
00236     {
00237         $oTagCloud = oxNew("oxTagCloud");
00238         $aLangs = $oArticle ? $oArticle->getAvailableInLangs() : array();
00239 
00240         $aLangTags = array();
00241         foreach ( $aLangs as $iLang => $sLangTitle ) {
00242             if ( count( $aTags = $oTagCloud->getTags( $oArticle->getId(), false, $iLang ) ) ) {
00243                 $aLangTags[$iLang] = $aTags;
00244             }
00245         }
00246 
00247         return $aLangTags;
00248     }
00249 
00255     public function getSelectedCategoryId()
00256     {
00257         if ( $this->_sActCatId === null) {
00258             $this->_sActCatId   = false;
00259             $this->_sActCatType = false;
00260 
00261             $aSeoData = oxConfig::getParameter( 'aSeoData' );
00262             if ( $aSeoData && isset( $aSeoData['oxparams'] ) ) {
00263                 if ( $sData = $aSeoData['oxparams'] ) {
00264                     $this->_sActCatId = substr( $sData, strpos( $sData, '#' ) + 1 );
00265                     if ( strpos( $this->_sActCatId, '#' ) !== false ) {
00266                         $this->_sActCatId = substr( $this->_sActCatId, 0, strpos( $this->_sActCatId, '#' ) );
00267                     }
00268                     $this->_iActCatLang = substr( $sData, strrpos( $sData, '#' ) + 1 );
00269                     $this->_sActCatType = substr( $sData, 0, strpos( $sData, '#' ) );
00270                 }
00271             } else {
00272                 $oArticle = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00273                 if ( ( $oList = $this->_getCategoryList( $oArticle ) ) && $oList->count() ) {
00274                     $this->_sActCatType = 'oxcategories';
00275                     $this->_sActCatId   = $oList->current()->getId();
00276                 } elseif ( ( $oList = $this->_getVendorList( $oArticle ) ) && $oList->count() ) {
00277                     $this->_sActCatType = 'oxvendor';
00278                     $this->_sActCatId   = $oList->current()->getId();
00279                 } elseif ( ( $oList = $this->_getManufacturerList( $oArticle ) ) && $oList->count() ) {
00280                     $this->_sActCatType = 'oxmanufacturer';
00281                     $this->_sActCatId   = $oList->current()->getId();
00282                 } elseif ( ( $aTagList = $this->_getTagList( $oArticle ) ) && count( $aTagList ) ) {
00283                     $this->_sActCatType = 'oxtag';
00284                     $this->_sActCatId   = key( $aTagList );
00285                 }
00286             }
00287         }
00288 
00289         return $this->_sActCatId;
00290     }
00291 
00299     protected function _getSeoUrl( $oArticle )
00300     {
00301         // setting cat type and id ..
00302         $this->getSelectedCategoryId();
00303 
00304         // choosing type
00305         switch ( $this->getActCatType() ) {
00306             case 'oxvendor':
00307                 $sType = OXARTICLE_LINKTYPE_VENDOR;
00308                 break;
00309             case 'oxmanufacturer':
00310                 $sType = OXARTICLE_LINKTYPE_MANUFACTURER;
00311                 break;
00312             case 'oxtag':
00313                 $sType = OXARTICLE_LINKTYPE_TAG;
00314                 break;
00315             default:
00316                 $sType = OXARTICLE_LINKTYPE_CATEGORY;
00317                 $oCat = oxNew( 'oxcategory' );
00318                 $oCat->load( $this->_sActCatId );
00319                 if ( $oCat->isPriceCategory() ) {
00320                     $sType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00321                 }
00322                 break;
00323         }
00324 
00325         $this->_getEncoder()->getArticleUrl( $oArticle, $this->getEditLang(), $sType );
00326         return parent::_getSeoUrl( $oArticle );
00327     }
00328 
00334     public function getActCategory()
00335     {
00336         $oCat = oxNew( 'oxcategory' );
00337         return ( $oCat->load( $this->_sActCatId ) ) ? $oCat : null;
00338     }
00339 
00345     public function getTag()
00346     {
00347         $sTag = $this->getSelectedCategoryId();
00348         return ( $this->getActCatType() == 'oxtag' ) ? $sTag : null;
00349     }
00350 
00356     public function getActVendor()
00357     {
00358         $oVendor = oxNew( 'oxvendor' );
00359         return ( $this->getActCatType() == 'oxvendor' && $oVendor->load( $this->_sActCatId ) ) ? $oVendor : null;
00360     }
00361 
00367     public function getActManufacturer()
00368     {
00369         $oManufacturer = oxNew( 'oxmanufacturer' );
00370         return ( $this->getActCatType() == 'oxmanufacturer' && $oManufacturer->load( $this->_sActCatId ) ) ? $oManufacturer : null;
00371     }
00372 
00378     public function getListType()
00379     {
00380         $sListType = '';
00381         switch ( $this->getActCatType() ) {
00382             case 'oxvendor':
00383                 $sListType = 'vendor';
00384                 break;
00385             case 'oxmanufacturer':
00386                 $sListType = 'manufacturer';
00387                 break;
00388             case 'oxtag':
00389                 $sListType = 'tag';
00390                 break;
00391             default:
00392                 break;
00393         }
00394         return $sListType;
00395     }
00396 
00405     protected function _getSeoUrlQuery( $oObject, $iShopId )
00406     {
00407         $oDb = oxDb::getDb();
00408 
00409          // tag type urls are loaded differently from others..
00410         if ( ( $sTag = $this->getTag() ) ) {
00411 
00412             $sStdUrl = "index.php?cl=details&amp;anid=".$oObject->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
00413             $sObjectId = md5( strtolower( $oObject->getShopId() . $sStdUrl ) );
00414             $sQ = "select oxseourl from oxseo where oxobjectid = ".$oDb->quote( $sObjectId ).
00415                   " and oxshopid = '{$iShopId}' and oxlang = ".$this->getActCategoryLang();
00416         } else {
00417             $sCatId = ( $this->_sActCatId == $this->_sNoCategoryId ) ? '' : $this->_sActCatId;
00418             $sQ = "select oxseourl from oxseo where oxobjectid = ".$oDb->quote( $oObject->getId() ).
00419                   " and oxshopid = '{$iShopId}' and oxlang = {$this->_iEditLang}".
00420                   " and oxparams = '{$sCatId}' ";
00421         }
00422 
00423         return $sQ;
00424     }
00425 
00431     public function getEditLang()
00432     {
00433         $iLang = $this->_iEditLang;
00434         if ( $this->getTag() ) {
00435             $iLang = $this->getActCategoryLang();
00436         }
00437         return $iLang;
00438     }
00439 
00445     public function getActCategoryLang()
00446     {
00447         return (int) $this->_iActCatLang;
00448     }
00449 
00455     protected function _getSeoEntryId()
00456     {
00457         $sId = '';
00458         if ( $sTag = $this->getTag() ) {
00459             $oObject = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00460             $sId = md5( strtolower( $oObject->getShopId() . $this->_getStdUrl( $oObject->getId() ) ) );
00461         } else {
00462             $sId = parent::_getSeoEntryId();
00463         }
00464         return $sId;
00465     }
00466 
00472     protected function _getAltSeoEntryId()
00473     {
00474         return oxConfig::getParameter( 'oxid' );
00475     }
00476 
00484     protected function getSeoEntryId()
00485     {
00486         return $this->_getSeoEntryId();
00487     }
00488 
00494     protected function _getSeoEntryType()
00495     {
00496         if ( $this->getTag() ) {
00497             return 'dynamic';
00498         } else {
00499             return $this->_getType();
00500         }
00501     }
00502 
00508     protected function _getType()
00509     {
00510         return 'oxarticle';
00511     }
00512 
00520     protected function _getStdUrl( $sOxid )
00521     {
00522         $oArticle = oxNew( 'oxarticle' );
00523         $oArticle->loadInLang( $this->_iEditLang, $sOxid );
00524         $sStdLink = $oArticle->getBaseStdLink( $this->_iEditLang, true, false );
00525         if ( $sListType = $this->getListType() ) {
00526             $sStdLink .= "&amp;listtype={$sListType}";
00527         }
00528 
00529         $sCatId = $this->getSelectedCategoryId();
00530         $sCatId = ( $sCatId == $this->_sNoCategoryId ) ? false : $sCatId;
00531 
00532         // adding vendor or manufacturer id
00533         switch ( $this->getActCatType() ) {
00534             case 'oxvendor':
00535                 $sStdLink .= "&amp;cnid=v_{$sCatId}";
00536                 break;
00537             case 'oxmanufacturer':
00538                 $sStdLink .= "&amp;mnid={$sCatId}";
00539                 break;
00540             case 'oxtag':
00541                 $sStdLink .= "&amp;searchtag=".rawurlencode( $this->getTag() );
00542                 break;
00543             default:
00544                 $sStdLink .= "&amp;cnid={$sCatId}";
00545                 break;
00546         }
00547 
00548         return $sStdLink;
00549     }
00550 
00556     public function getActCatType()
00557     {
00558         return $this->_sActCatType;
00559     }
00560 
00568     public function processParam( $sParam )
00569     {
00570         if ($this->getTag()) {
00571             return '';
00572         } else {
00573             return trim( substr( $sParam, strpos( $sParam, '#') ), '#' );
00574         }
00575     }
00576 
00582     public function getNoCatId()
00583     {
00584         return $this->_sNoCategoryId;
00585     }
00586 
00592     protected function _getEncoder()
00593     {
00594         return oxSeoEncoderArticle::getInstance();
00595     }
00596 }