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
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
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
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] = array();
00244 foreach ($aTags as $sTitle => $sValue) {
00245 $aLangTags[$iLang][$oTagCloud->getTagTitle($sTitle)] = $sValue;
00246 }
00247 }
00248 }
00249
00250 return $aLangTags;
00251 }
00252
00258 public function getSelectedCategoryId()
00259 {
00260 if ( $this->_sActCatId === null) {
00261 $this->_sActCatId = false;
00262 $this->_sActCatType = false;
00263
00264 $aSeoData = oxConfig::getParameter( 'aSeoData' );
00265 if ( $aSeoData && isset( $aSeoData['oxparams'] ) ) {
00266 if ( $sData = $aSeoData['oxparams'] ) {
00267 $this->_sActCatId = substr( $sData, strpos( $sData, '#' ) + 1 );
00268 if ( strpos( $this->_sActCatId, '#' ) !== false ) {
00269 $this->_sActCatId = substr( $this->_sActCatId, 0, strpos( $this->_sActCatId, '#' ) );
00270 }
00271 $this->_iActCatLang = substr( $sData, strrpos( $sData, '#' ) + 1 );
00272 $this->_sActCatType = substr( $sData, 0, strpos( $sData, '#' ) );
00273 }
00274 } else {
00275 $oArticle = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00276 if ( ( $oList = $this->_getCategoryList( $oArticle ) ) && $oList->count() ) {
00277 $this->_sActCatType = 'oxcategories';
00278 $this->_sActCatId = $oList->current()->getId();
00279 } elseif ( ( $oList = $this->_getVendorList( $oArticle ) ) && $oList->count() ) {
00280 $this->_sActCatType = 'oxvendor';
00281 $this->_sActCatId = $oList->current()->getId();
00282 } elseif ( ( $oList = $this->_getManufacturerList( $oArticle ) ) && $oList->count() ) {
00283 $this->_sActCatType = 'oxmanufacturer';
00284 $this->_sActCatId = $oList->current()->getId();
00285 } elseif ( ( $aTagList = $this->_getTagList( $oArticle ) ) && count( $aTagList ) ) {
00286 $this->_sActCatType = 'oxtag';
00287 $this->_sActCatId = key( $aTagList );
00288 }
00289 }
00290 }
00291
00292 return $this->_sActCatId;
00293 }
00294
00302 protected function _getSeoUrl( $oArticle )
00303 {
00304
00305 $this->getSelectedCategoryId();
00306
00307
00308 switch ( $this->getActCatType() ) {
00309 case 'oxvendor':
00310 $sType = OXARTICLE_LINKTYPE_VENDOR;
00311 break;
00312 case 'oxmanufacturer':
00313 $sType = OXARTICLE_LINKTYPE_MANUFACTURER;
00314 break;
00315 case 'oxtag':
00316 $sType = OXARTICLE_LINKTYPE_TAG;
00317 break;
00318 default:
00319 $sType = OXARTICLE_LINKTYPE_CATEGORY;
00320 $oCat = oxNew( 'oxcategory' );
00321 $oCat->load( $this->_sActCatId );
00322 if ( $oCat->isPriceCategory() ) {
00323 $sType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00324 }
00325 break;
00326 }
00327
00328 $this->_getEncoder()->getArticleUrl( $oArticle, $this->getEditLang(), $sType );
00329 return parent::_getSeoUrl( $oArticle );
00330 }
00331
00337 public function getActCategory()
00338 {
00339 $oCat = oxNew( 'oxcategory' );
00340 return ( $oCat->load( $this->_sActCatId ) ) ? $oCat : null;
00341 }
00342
00348 public function getTag()
00349 {
00350 $sTag = $this->getSelectedCategoryId();
00351 return ( $this->getActCatType() == 'oxtag' ) ? $sTag : null;
00352 }
00353
00359 public function getActVendor()
00360 {
00361 $oVendor = oxNew( 'oxvendor' );
00362 return ( $this->getActCatType() == 'oxvendor' && $oVendor->load( $this->_sActCatId ) ) ? $oVendor : null;
00363 }
00364
00370 public function getActManufacturer()
00371 {
00372 $oManufacturer = oxNew( 'oxmanufacturer' );
00373 return ( $this->getActCatType() == 'oxmanufacturer' && $oManufacturer->load( $this->_sActCatId ) ) ? $oManufacturer : null;
00374 }
00375
00381 public function getListType()
00382 {
00383 $sListType = '';
00384 switch ( $this->getActCatType() ) {
00385 case 'oxvendor':
00386 $sListType = 'vendor';
00387 break;
00388 case 'oxmanufacturer':
00389 $sListType = 'manufacturer';
00390 break;
00391 case 'oxtag':
00392 $sListType = 'tag';
00393 break;
00394 default:
00395 break;
00396 }
00397 return $sListType;
00398 }
00399
00408 protected function _getSeoUrlQuery( $oObject, $iShopId )
00409 {
00410 $oDb = oxDb::getDb();
00411
00412
00413 if ( ( $sTag = $this->getTag() ) ) {
00414
00415 $sStdUrl = "index.php?cl=details&anid=".$oObject->getId()."&listtype=tag&searchtag=".rawurlencode( $sTag );
00416 $sObjectId = md5( strtolower( $oObject->getShopId() . $sStdUrl ) );
00417 $sQ = "select oxseourl from oxseo where oxobjectid = ".$oDb->quote( $sObjectId ).
00418 " and oxshopid = '{$iShopId}' and oxlang = ".$this->getActCategoryLang();
00419 } else {
00420 $sCatId = ( $this->_sActCatId == $this->_sNoCategoryId ) ? '' : $this->_sActCatId;
00421 $sQ = "select oxseourl from oxseo where oxobjectid = ".$oDb->quote( $oObject->getId() ).
00422 " and oxshopid = '{$iShopId}' and oxlang = {$this->_iEditLang}".
00423 " and oxparams = '{$sCatId}' ";
00424 }
00425
00426 return $sQ;
00427 }
00428
00434 public function getEditLang()
00435 {
00436 $iLang = $this->_iEditLang;
00437 if ( $this->getTag() ) {
00438 $iLang = $this->getActCategoryLang();
00439 }
00440 return $iLang;
00441 }
00442
00448 public function getActCategoryLang()
00449 {
00450 return (int) $this->_iActCatLang;
00451 }
00452
00458 protected function _getSeoEntryId()
00459 {
00460 $sId = '';
00461 if ( $sTag = $this->getTag() ) {
00462 $oObject = $this->_getObject( oxConfig::getParameter( 'oxid' ) );
00463 $sId = md5( strtolower( $oObject->getShopId() . $this->_getStdUrl( $oObject->getId() ) ) );
00464 } else {
00465 $sId = parent::_getSeoEntryId();
00466 }
00467 return $sId;
00468 }
00469
00475 protected function _getAltSeoEntryId()
00476 {
00477 return oxConfig::getParameter( 'oxid' );
00478 }
00479
00487 protected function getSeoEntryId()
00488 {
00489 return $this->_getSeoEntryId();
00490 }
00491
00497 protected function _getSeoEntryType()
00498 {
00499 if ( $this->getTag() ) {
00500 return 'dynamic';
00501 } else {
00502 return $this->_getType();
00503 }
00504 }
00505
00511 protected function _getType()
00512 {
00513 return 'oxarticle';
00514 }
00515
00523 protected function _getStdUrl( $sOxid )
00524 {
00525 $oArticle = oxNew( 'oxarticle' );
00526 $oArticle->loadInLang( $this->_iEditLang, $sOxid );
00527 $sStdLink = $oArticle->getBaseStdLink( $this->_iEditLang, true, false );
00528 if ( $sListType = $this->getListType() ) {
00529 $sStdLink .= "&listtype={$sListType}";
00530 }
00531
00532 $sCatId = $this->getSelectedCategoryId();
00533 $sCatId = ( $sCatId == $this->_sNoCategoryId ) ? false : $sCatId;
00534
00535
00536 switch ( $this->getActCatType() ) {
00537 case 'oxvendor':
00538 $sStdLink .= "&cnid=v_{$sCatId}";
00539 break;
00540 case 'oxmanufacturer':
00541 $sStdLink .= "&mnid={$sCatId}";
00542 break;
00543 case 'oxtag':
00544 $sStdLink .= "&searchtag=".rawurlencode( $this->getTag() );
00545 break;
00546 default:
00547 $sStdLink .= "&cnid={$sCatId}";
00548 break;
00549 }
00550
00551 return $sStdLink;
00552 }
00553
00559 public function getActCatType()
00560 {
00561 return $this->_sActCatType;
00562 }
00563
00571 public function processParam( $sParam )
00572 {
00573 if ($this->getTag()) {
00574 return '';
00575 } else {
00576 return trim( substr( $sParam, strpos( $sParam, '#') ), '#' );
00577 }
00578 }
00579
00585 public function getNoCatId()
00586 {
00587 return $this->_sNoCategoryId;
00588 }
00589
00595 protected function _getEncoder()
00596 {
00597 return oxSeoEncoderArticle::getInstance();
00598 }
00599 }