OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
article_seo.php
Go to the documentation of this file.
1 <?php
2 
6 class Article_Seo extends Object_Seo
7 {
13  protected $_sActCatId = null;
14 
20  protected $_aSelectionList = null;
21 
27  public function getActCatType()
28  {
29  $sType = false;
30  $aData = oxConfig::getParameter( "aSeoData" );
31  if ( $aData && isset( $aData["oxparams"] ) ) {
32  $oStr = getStr();
33  $iEndPos = $oStr->strpos( $aData["oxparams"], "#" );
34  $sType = $oStr->substr( $aData["oxparams"], 0, $iEndPos );
35  } elseif ( $aList = $this->getSelectionList() ) {
36  reset( $aList );
37  $sType = key( $aList );
38  }
39 
40  return $sType;
41  }
42 
48  public function getActCatLang()
49  {
50  if ( oxConfig::getParameter( "editlanguage" ) !== null ) {
51  return $this->_iEditLang;
52  }
53 
54  $iLang = false;
55  $aData = oxConfig::getParameter( "aSeoData" );
56  if ( $aData && isset( $aData["oxparams"] ) ) {
57  $oStr = getStr();
58  $iStartPos = $oStr->strpos( $aData["oxparams"], "#" );
59  $iEndPos = $oStr->strpos( $aData["oxparams"], "#", $iStartPos + 1 );
60  $iLang = $oStr->substr( $aData["oxparams"], $iEndPos + 1 );
61  } elseif ( $aList = $this->getSelectionList() ) {
62  $aList = reset( $aList );
63  $iLang = key( $aList );
64  }
65 
66  return (int) $iLang;
67  }
68 
74  public function getActCatId()
75  {
76  $sId = false;
77  $aData = oxConfig::getParameter( "aSeoData" );
78  if ( $aData && isset( $aData["oxparams"] ) ) {
79  $oStr = getStr();
80  $iStartPos = $oStr->strpos( $aData["oxparams"], "#" );
81  $iEndPos = $oStr->strpos( $aData["oxparams"], "#", $iStartPos + 1 );
82  $iLen = $oStr->strlen( $aData["oxparams"] );
83  $sId = $oStr->substr( $aData["oxparams"], $iStartPos + 1, $iEndPos - $iLen );
84  } elseif ( $aList = $this->getSelectionList() ) {
85  $oItem = reset( $aList[$this->getActCatType()][$this->getActCatLang()] );
86  $sId = $oItem->getId();
87  }
88 
89  return $sId;
90  }
91 
97  public function getSelectionList()
98  {
99  if ( $this->_aSelectionList === null ) {
100  $this->_aSelectionList = array();
101 
102  $oProduct = oxNew( 'oxarticle' );
103  $oProduct->load( $this->getEditObjectId() );
104 
105  if ( $oCatList = $this->_getCategoryList( $oProduct ) ) {
106  $this->_aSelectionList["oxcategory"][$this->_iEditLang] = $oCatList;
107  }
108 
109  if ( $oVndList = $this->_getVendorList( $oProduct ) ) {
110  $this->_aSelectionList["oxvendor"][$this->_iEditLang] = $oVndList;
111  }
112 
113  if ( $oManList = $this->_getManufacturerList( $oProduct ) ) {
114  $this->_aSelectionList["oxmanufacturer"][$this->_iEditLang] = $oManList;
115  }
116 
117  $aLangs = $oProduct->getAvailableInLangs();
118  foreach ( $aLangs as $iLang => $sLangTitle ) {
119  if ( $oTagList = $this->_getTagList( $oProduct, $iLang ) ) {
120  $this->_aSelectionList["oxtag"][$iLang] = $oTagList;
121  }
122  }
123  }
124 
125  return $this->_aSelectionList;
126  }
127 
135  protected function _getCategoryList( $oArticle )
136  {
137  $sMainCatId = false;
138  if ( $oMainCat = $oArticle->getCategory() ) {
139  $sMainCatId = $oMainCat->getId();
140  }
141 
142  $aCatList = array();
143  $iLang = $this->getEditLang();
144 
145  // adding categories
146  $sO2CView = getViewName( 'oxobject2category');
147  $oDb = oxDb::getDb( oxDB::FETCH_MODE_ASSOC );
148  $sQ = "select oxobject2category.oxcatnid as oxid from $sO2CView as oxobject2category where oxobject2category.oxobjectid="
149  . $oDb->quote( $oArticle->getId() ) . " union ".$oArticle->getSqlForPriceCategories('oxid');
150 
151  $oRs = $oDb->execute( $sQ );
152  if ( $oRs != false && $oRs->recordCount() > 0 ) {
153  while ( !$oRs->EOF ) {
154  $oCat = oxNew('oxcategory');
155  if ( $oCat->loadInLang( $iLang, current( $oRs->fields ) ) ) {
156  if ( $sMainCatId == $oCat->getId() ) {
157  $sSuffix = oxRegistry::getLang()->translateString( '(main category)', $this->getEditLang() );
158  $oCat->oxcategories__oxtitle = new oxField( $oCat->oxcategories__oxtitle->getRawValue() . " " . $sSuffix, oxField::T_RAW );
159  }
160  $aCatList[] = $oCat;
161  }
162  $oRs->moveNext();
163  }
164  }
165 
166  return $aCatList;
167  }
168 
176  protected function _getVendorList( $oArticle )
177  {
178  if ( $oArticle->oxarticles__oxvendorid->value ) {
179  $oVendor = oxNew( 'oxvendor' );
180  if ( $oVendor->loadInLang( $this->getEditLang(), $oArticle->oxarticles__oxvendorid->value ) ) {
181  return array( $oVendor );
182  }
183  }
184  }
185 
193  protected function _getManufacturerList( $oArticle )
194  {
195  if ( $oArticle->oxarticles__oxmanufacturerid->value ) {
196  $oManufacturer = oxNew( 'oxmanufacturer' );
197  if ( $oManufacturer->loadInLang( $this->getEditLang(), $oArticle->oxarticles__oxmanufacturerid->value ) ) {
198  return array( $oManufacturer );
199  }
200  }
201  }
202 
211  protected function _getTagList( $oArticle, $iLang )
212  {
213  $oArticleTagList = oxNew("oxarticletaglist");
214  $oArticleTagList->setLanguage( $iLang );
215  $oArticleTagList->load( $oArticle->getId() );
216  $aTagsList = array();
217  if ( count( $aTags = $oArticleTagList->getArray() ) ) {
218  $sShopId = $this->getConfig()->getShopId();
219  $iProdId = $oArticle->getId();
220  foreach ( $aTags as $sTitle => $oTagObject ) {
221  // A. we do not have oxTag object yet, so reusing manufacturers for general interface
222  $oTag = oxNew( "oxManufacturer" );
223  $oTag->setLanguage( $iLang );
224  $oTag->setId( md5( strtolower ( $sShopId . $this->_getStdUrl( $iProdId, "oxtag", "tag", $iLang, $sTitle ) ) ) );
225  $oTag->oxmanufacturers__oxtitle = new oxField( $sTitle );
226  $aTagsList[] = $oTag;
227  }
228  }
229 
230  return $aTagsList;
231  }
232 
238  public function getActCategory()
239  {
240  $oCat = oxNew( 'oxcategory' );
241  return ( $oCat->load( $this->getActCatId() ) ) ? $oCat : null;
242  }
243 
249  public function getTag()
250  {
251  if ( $this->getActCatType() == 'oxtag' ) {
252 
253  $iLang = $this->getActCatLang();
254  $sTagId = $this->getActCatId();
255 
256  $oProduct = oxNew( 'oxarticle' );
257  $oProduct->loadInLang( $iLang, $this->getEditObjectId() );
258 
259  $aList = $this->_getTagList( $oProduct, $iLang );
260  foreach ( $aList as $oTag ) {
261  if ( $oTag->getId() == $sTagId ) {
262  return $oTag->getTitle();
263  }
264  }
265  }
266  }
267 
273  public function getActVendor()
274  {
275  $oVendor = oxNew( 'oxvendor' );
276  return ( $this->getActCatType() == 'oxvendor' && $oVendor->load( $this->getActCatId() ) ) ? $oVendor : null;
277  }
278 
284  public function getActManufacturer()
285  {
286  $oManufacturer = oxNew( 'oxmanufacturer' );
287  return ( $this->getActCatType() == 'oxmanufacturer' && $oManufacturer->load( $this->getActCatId() ) ) ? $oManufacturer : null;
288  }
289 
295  public function getListType()
296  {
297  switch ( $this->getActCatType() ) {
298  case 'oxvendor':
299  return 'vendor';
300  case 'oxmanufacturer':
301  return 'manufacturer';
302  case 'oxtag':
303  return 'tag';
304  }
305  }
306 
312  public function getEditLang()
313  {
314  return $this->getActCatLang();
315  }
316 
322  protected function _getAltSeoEntryId()
323  {
324  return $this->getEditObjectId();
325  }
326 
332  protected function _getSeoEntryType()
333  {
334  if ( $this->getTag() ) {
335  return 'dynamic';
336  } else {
337  return $this->_getType();
338  }
339  }
340 
346  protected function _getType()
347  {
348  return 'oxarticle';
349  }
350 
358  public function processParam( $sParam )
359  {
360  if ( $this->getTag() ) {
361  return '';
362  } else {
363  return $this->getActCatId();
364  }
365  }
366 
372  protected function _getEncoder()
373  {
374  return oxRegistry::get("oxSeoEncoderArticle");
375  }
376 
382  public function getEntryUri()
383  {
384  $oProduct = oxNew( 'oxarticle' );
385  if ( $oProduct->load( $this->getEditObjectId() ) ) {
386  $oEncoder = $this->_getEncoder();
387  switch ( $this->getActCatType() ) {
388  case 'oxvendor':
389  return $oEncoder->getArticleVendorUri( $oProduct, $this->getEditLang() );
390  case 'oxmanufacturer':
391  return $oEncoder->getArticleManufacturerUri( $oProduct, $this->getEditLang() );
392  case 'oxtag':
393  return $oEncoder->getArticleTagUri( $oProduct, $this->getActCatLang() );
394  default:
395  if ( $this->getActCatId() ) {
396  return $oEncoder->getArticleUri( $oProduct, $this->getEditLang() );
397  } else {
398  return $oEncoder->getArticleMainUri( $oProduct, $this->getEditLang() );
399  }
400  }
401  }
402  }
403 
415  protected function _getStdUrl( $sOxid, $sCatType = null, $sListType = null, $iLang = null, $sTag = null )
416  {
417  $iLang = $iLang !== null ? $iLang : $this->getEditLang();
418  $sCatType = $sCatType !== null ? $sCatType : $this->getActCatType();
419  $sListType = $sListType !== null ? $sListType : $this->getListType();
420 
421  $aParams = array();
422  if ( $sListType ) {
423  $aParams["listtype"] = $sListType;
424  }
425 
426  $oProduct = oxNew( 'oxarticle' );
427  $oProduct->loadInLang( $iLang, $sOxid );
428 
429  // adding vendor or manufacturer id
430  switch ( $sCatType ) {
431  case 'oxvendor':
432  $aParams["cnid"] = "v_" . $this->getActCatId();
433  break;
434  case 'oxmanufacturer':
435  $aParams["mnid"] = $this->getActCatId();
436  break;
437  case 'oxtag':
438  $aParams["searchtag"] = $sTag !== null ? $sTag : $this->getTag();
439  break;
440  default:
441  $aParams["cnid"] = $this->getActCatId();
442  break;
443  }
444 
445  return trim( oxRegistry::get("oxUtilsUrl")->appendUrl( $oProduct->getBaseStdLink( $iLang, true, false ), $aParams ), '&amp;' );
446  }
447 
453  public function showCatSelect()
454  {
455  return true;
456  }
457 
463  protected function _getSaveObjectId()
464  {
465  $sId = $this->getEditObjectId();
466  if ( $this->getActCatType() == 'oxtag' ) {
467  $sId = $this->_getEncoder()->getDynamicObjectId( $this->getConfig()->getShopId(), $this->_getStdUrl( $sId ) );
468  }
469  return $sId;
470  }
471 
477  public function isEntryFixed()
478  {
479  $oDb = oxDb::getDb();
480 
481  $sId = $this->_getSaveObjectId();
482  $iLang = (int) $this->getEditLang();
483  $iShopId = $this->getConfig()->getShopId();
484  $sParam = $this->processParam( $this->getActCatId() );
485 
486  $sQ = "select oxfixed from oxseo where
487  oxseo.oxobjectid = " . $oDb->quote( $sId ) . " and
488  oxseo.oxshopid = '{$iShopId}' and oxseo.oxlang = {$iLang} and oxparams = ".$oDb->quote( $sParam );
489 
490  return (bool) oxDb::getDb()->getOne( $sQ, false, false );
491  }
492 }