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 = oxSeoEncoderArticle::getInstance()->getDynamicObjectId( $iShopId, $oObject->getStdTagLink( $this->getTag() ) );
00100             $sQ = "select * from oxseo where oxobjectid = ".$oDb->quote( $sObjectId ).
00101                   " and oxshopid = '{$iShopId}' and oxlang = ".$this->getActCategoryLang();
00102         } else {
00103             $sParam = ( $sCat = $this->getSelectedCategoryId() ) ? " and oxparams = '$sCat' " : '';
00104             $sQ = "select * from oxseo where oxobjectid = ".$oDb->quote( $oObject->getId() ) .
00105                   " and oxshopid = '{$iShopId}' and oxlang = {$iLang} {$sParam} ";
00106         }
00107         return $sQ;
00108     }
00109 
00117     protected function _getCategoryList( $oArticle )
00118     {
00119         if ( $this->_oArtCategories === null && $oArticle ) {
00120             // adding categories
00121             $sO2CView = getViewName( 'oxobject2category');
00122             $oDb = oxDb::getDb( true );
00123             $sQ = "select oxobject2category.oxcatnid as oxid from $sO2CView as oxobject2category where oxobject2category.oxobjectid="
00124                   . $oDb->quote( $oArticle->getId() ) . " union ".$oArticle->getSqlForPriceCategories('oxid');
00125 
00126             $iLang = $this->getEditLang();
00127             $this->_oArtCategories = oxNew( "oxList" );
00128             $rs = $oDb->execute( $sQ );
00129             if ( $rs != false && $rs->recordCount() > 0 ) {
00130                 while ( !$rs->EOF ) {
00131                     $oCat = oxNew('oxcategory');
00132                     $oCat->setLanguage( $iLang );
00133                     if ( $oCat->load( current( $rs->fields ) ) ) {
00134                         $this->_oArtCategories->offsetSet( $oCat->getId(), $oCat );
00135                     }
00136                     $rs->moveNext();
00137                 }
00138             }
00139 
00140             $this->_setMainCategory( $oArticle, $this->_oArtCategories);
00141         }
00142 
00143         return $this->_oArtCategories;
00144     }
00145 
00154     protected function _setMainCategory( $oProduct, $oCatList )
00155     {
00156         // loading main category
00157         if ( !( $oMainCat = $oProduct->getCategory() ) ) {
00158             $sTitle = oxLang::getInstance()->translateString( '(no category)', $this->_iEditLang );
00159             $oMainCat = oxNew( "oxCategory" );
00160             $oMainCat->setId( $this->_sNoCategoryId );
00161             $oMainCat->oxcategories__oxtitle = new oxField( $sTitle, oxField::T_RAW );
00162         }
00163 
00164         $sSuffix = oxLang::getInstance()->translateString( '(main category)', $this->_iEditLang );
00165         $oMainCat->oxcategories__oxtitle = new oxField( $oMainCat->oxcategories__oxtitle->getRawValue()." ".$sSuffix, oxField::T_RAW );
00166 
00167         // overriding
00168         $oCatList->offsetSet( $oMainCat->getId(), $oMainCat );
00169     }
00170 
00178     protected function _getVendorList( $oArticle )
00179     {
00180         if ( $this->_oArtVendors === null ) {
00181             $this->_oArtVendors = false;
00182 
00183             if ( $oArticle->oxarticles__oxvendorid->value ) {
00184                 $oVendor = oxNew( 'oxvendor' );
00185                 if ( $oVendor->loadInLang( $this->_iEditLang, $oArticle->oxarticles__oxvendorid->value ) ) {
00186                     $this->_oArtVendors = oxNew( 'oxList', 'oxvendor' );
00187                     $this->_oArtVendors[] = $oVendor;
00188                 }
00189             }
00190         }
00191         return $this->_oArtVendors;
00192     }
00193 
00201     protected function _getManufacturerList( $oArticle )
00202     {
00203         if ( $this->_oArtManufacturers === null ) {
00204             $this->_oArtManufacturers = false;
00205 
00206             if ( $oArticle->oxarticles__oxmanufacturerid->value ) {
00207                 $oManufacturer = oxNew( 'oxmanufacturer' );
00208                 if ( $oManufacturer->loadInLang( $this->_iEditLang, $oArticle->oxarticles__oxmanufacturerid->value ) ) {
00209                     $this->_oArtManufacturers = oxNew( 'oxList', 'oxmanufacturer' );
00210                     $this->_oArtManufacturers[] = $oManufacturer;
00211                 }
00212             }
00213         }
00214         return $this->_oArtManufacturers;
00215     }
00216 
00224     protected function _getTagList( $oArticle )
00225     {
00226         $oTagCloud = oxNew("oxTagCloud");
00227         $aLangs = $oArticle ? $oArticle->getAvailableInLangs() : array();
00228 
00229         $aLangTags = array();
00230         foreach ( $aLangs as $iLang => $sLangTitle ) {
00231             if ( count( $aTags = $oTagCloud->getTags( $oArticle->getId(), false, $iLang ) ) ) {
00232                 $aLangTags[$iLang] = $aTags;
00233             }
00234         }
00235 
00236         return $aLangTags;
00237     }
00238 
00244     public function getSelectedCategoryId()
00245     {
00246         if ( $this->_sActCatId === null) {
00247             $this->_sActCatId   = false;
00248             $this->_sActCatType = false;
00249 
00250             $aSeoData = oxConfig::getParameter( 'aSeoData' );
00251             if ( $aSeoData && isset( $aSeoData['oxparams'] ) ) {
00252                 if ( $sData = $aSeoData['oxparams'] ) {
00253                     $this->_sActCatId = substr( $sData, strpos( $sData, '#' ) + 1 );
00254                     if ( strpos( $this->_sActCatId, '#' ) !== false ) {
00255                         $this->_sActCatId = substr( $this->_sActCatId, 0, strpos( $this->_sActCatId, '#' ) );
00256                     }
00257                     $this->_iActCatLang = substr( $sData, strrpos( $sData, '#' ) + 1 );
00258                     $this->_sActCatType = substr( $sData, 0, strpos( $sData, '#' ) );
00259                 }
00260             } else {
00261                 $oArticle = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00262                 if ( ( $oList = $this->_getCategoryList( $oArticle ) ) && $oList->count() ) {
00263                     $this->_sActCatType = 'oxcategories';
00264                     $this->_sActCatId   = $oList->current()->getId();
00265                 } elseif ( ( $oList = $this->_getVendorList( $oArticle ) ) && $oList->count() ) {
00266                     $this->_sActCatType = 'oxvendor';
00267                     $this->_sActCatId   = $oList->current()->getId();
00268                 } elseif ( ( $oList = $this->_getManufacturerList( $oArticle ) ) && $oList->count() ) {
00269                     $this->_sActCatType = 'oxmanufacturer';
00270                     $this->_sActCatId   = $oList->current()->getId();
00271                 } elseif ( ( $aTagList = $this->_getTagList( $oArticle ) ) && count( $aTagList ) ) {
00272                     $this->_sActCatType = 'oxtag';
00273                     $this->_sActCatId   = key( $aTagList );
00274                 }
00275             }
00276         }
00277 
00278         return $this->_sActCatId;
00279     }
00280 
00288     protected function _getSeoUrl( $oArticle )
00289     {
00290         // setting cat type and id ..
00291         $this->getSelectedCategoryId();
00292 
00293         // choosing type
00294         switch ( $this->getActCatType() ) {
00295             case 'oxvendor':
00296                 $sType = OXARTICLE_LINKTYPE_VENDOR;
00297                 break;
00298             case 'oxmanufacturer':
00299                 $sType = OXARTICLE_LINKTYPE_MANUFACTURER;
00300                 break;
00301             case 'oxtag':
00302                 $sType = OXARTICLE_LINKTYPE_TAG;
00303                 break;
00304             default:
00305                 $sType = OXARTICLE_LINKTYPE_CATEGORY;
00306                 $oCat = oxNew( 'oxcategory' );
00307                 $oCat->load( $this->_sActCatId );
00308                 if ( $oCat->isPriceCategory() ) {
00309                     $sType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00310                 }
00311                 break;
00312         }
00313 
00314         oxSeoEncoderArticle::getInstance()->getArticleUrl( $oArticle, $this->getEditLang(), $sType );
00315         return parent::_getSeoUrl( $oArticle );
00316     }
00317 
00323     public function getActCategory()
00324     {
00325         $oCat = oxNew( 'oxcategory' );
00326         return ( $oCat->load( $this->_sActCatId ) ) ? $oCat : null;
00327     }
00328 
00334     public function getTag()
00335     {
00336         $sTag = $this->getSelectedCategoryId();
00337         return ( $this->getActCatType() == 'oxtag' ) ? $sTag : null;
00338     }
00339 
00345     public function getActVendor()
00346     {
00347         $oVendor = oxNew( 'oxvendor' );
00348         return ( $this->getActCatType() == 'oxvendor' && $oVendor->load( $this->_sActCatId ) ) ? $oVendor : null;
00349     }
00350 
00356     public function getActManufacturer()
00357     {
00358         $oManufacturer = oxNew( 'oxmanufacturer' );
00359         return ( $this->getActCatType() == 'oxmanufacturer' && $oManufacturer->load( $this->_sActCatId ) ) ? $oManufacturer : null;
00360     }
00361 
00367     public function getListType()
00368     {
00369         $sListType = '';
00370         switch ( $this->getActCatType() ) {
00371             case 'oxvendor':
00372                 $sListType = 'vendor';
00373                 break;
00374             case 'oxmanufacturer':
00375                 $sListType = 'manufacturer';
00376                 break;
00377             case 'oxtag':
00378                 $sListType = 'tag';
00379                 break;
00380             default:
00381                 break;
00382         }
00383         return $sListType;
00384     }
00385 
00394     protected function _getSeoUrlQuery( $oObject, $iShopId )
00395     {
00396         $oDb = oxDb::getDb();
00397 
00398          // tag type urls are loaded differently from others..
00399         if ( ( $sTag = $this->getTag() ) ) {
00400 
00401             $sStdUrl = "index.php?cl=details&amp;anid=".$oObject->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
00402             $sObjectId = md5( strtolower( $oObject->getShopId() . $sStdUrl ) );
00403             $sQ = "select oxseourl from oxseo where oxobjectid = ".$oDb->quote( $sObjectId ).
00404                   " and oxshopid = '{$iShopId}' and oxlang = ".$this->getActCategoryLang();
00405         } else {
00406             $sCatId = ( $this->_sActCatId == $this->_sNoCategoryId ) ? '' : $this->_sActCatId;
00407             $sQ = "select oxseourl from oxseo where oxobjectid = ".$oDb->quote( $oObject->getId() ).
00408                   " and oxshopid = '{$iShopId}' and oxlang = {$this->_iEditLang}".
00409                   " and oxparams = '{$sCatId}' ";
00410         }
00411 
00412         return $sQ;
00413     }
00414 
00420     public function getEditLang()
00421     {
00422         $iLang = $this->_iEditLang;
00423         if ( $this->getTag() ) {
00424             $iLang = $this->getActCategoryLang();
00425         }
00426         return $iLang;
00427     }
00428 
00434     public function getActCategoryLang()
00435     {
00436         return (int) $this->_iActCatLang;
00437     }
00438 
00444     protected function _getSeoEntryId()
00445     {
00446         $sId = '';
00447         if ( $sTag = $this->getTag() ) {
00448             $oObject = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00449             $sId = md5( strtolower( $oObject->getShopId() . $this->_getStdUrl( $oObject->getId() ) ) );
00450         } else {
00451             $sId = parent::_getSeoEntryId();
00452         }
00453         return $sId;
00454     }
00455 
00463     protected function getSeoEntryId()
00464     {
00465         return $this->_getSeoEntryId();
00466     }
00467 
00473     protected function _getSeoEntryType()
00474     {
00475         if ( $this->getTag() ) {
00476             return 'dynamic';
00477         } else {
00478             return $this->_getType();
00479         }
00480     }
00481 
00487     protected function _getType()
00488     {
00489         return 'oxarticle';
00490     }
00491 
00499     protected function _getStdUrl( $sOxid )
00500     {
00501         $oArticle = oxNew( 'oxarticle' );
00502         $oArticle->loadInLang( $this->_iEditLang, $sOxid );
00503         $sStdLink = $oArticle->getBaseStdLink( $this->_iEditLang, true, false );
00504         if ( $sListType = $this->getListType() ) {
00505             $sStdLink .= "&amp;listtype={$sListType}";
00506         }
00507 
00508         $sCatId = $this->getSelectedCategoryId();
00509         $sCatId = ( $sCatId == $this->_sNoCategoryId ) ? false : $sCatId;
00510 
00511         // adding vendor or manufacturer id
00512         switch ( $this->getActCatType() ) {
00513             case 'oxvendor':
00514                 $sStdLink .= "&amp;cnid=v_{$sCatId}";
00515                 break;
00516             case 'oxmanufacturer':
00517                 $sStdLink .= "&amp;mnid={$sCatId}";
00518                 break;
00519             case 'oxtag':
00520                 $sStdLink .= "&amp;searchtag=".rawurlencode( $this->getTag() );
00521                 break;
00522             default:
00523                 $sStdLink .= "&amp;cnid={$sCatId}";
00524                 break;
00525         }
00526 
00527         return $sStdLink;
00528     }
00529 
00535     public function getActCatType()
00536     {
00537         return $this->_sActCatType;
00538     }
00539 
00547     public function processParam( $sParam )
00548     {
00549         if ($this->getTag()) {
00550             return '';
00551         } else {
00552             return trim( substr( $sParam, strpos( $sParam, '#') ), '#' );
00553         }
00554     }
00555 
00561     public function getNoCatId()
00562     {
00563         return $this->_sNoCategoryId;
00564     }
00565 }

Generated by  doxygen 1.6.2