article_seo.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class Article_Seo extends Object_Seo
00007 {
00008 
00014     protected $_sActCatId = null;
00015 
00021     protected $_aSelectionList = null;
00022 
00028     public function getActCatType()
00029     {
00030         $sType = false;
00031         $aData = oxRegistry::getConfig()->getRequestParameter("aSeoData");
00032         if ($aData && isset($aData["oxparams"])) {
00033             $oStr = getStr();
00034             $iEndPos = $oStr->strpos($aData["oxparams"], "#");
00035             $sType = $oStr->substr($aData["oxparams"], 0, $iEndPos);
00036         } elseif ($aList = $this->getSelectionList()) {
00037             reset($aList);
00038             $sType = key($aList);
00039         }
00040 
00041         return $sType;
00042     }
00043 
00049     public function getActCatLang()
00050     {
00051         if (oxRegistry::getConfig()->getRequestParameter("editlanguage") !== null) {
00052             return $this->_iEditLang;
00053         }
00054 
00055         $iLang = false;
00056         $aData = oxRegistry::getConfig()->getRequestParameter("aSeoData");
00057         if ($aData && isset($aData["oxparams"])) {
00058             $oStr = getStr();
00059             $iStartPos = $oStr->strpos($aData["oxparams"], "#");
00060             $iEndPos = $oStr->strpos($aData["oxparams"], "#", $iStartPos + 1);
00061             $iLang = $oStr->substr($aData["oxparams"], $iEndPos + 1);
00062         } elseif ($aList = $this->getSelectionList()) {
00063             $aList = reset($aList);
00064             $iLang = key($aList);
00065         }
00066 
00067         return (int) $iLang;
00068     }
00069 
00075     public function getActCatId()
00076     {
00077         $sId = false;
00078         $aData = oxRegistry::getConfig()->getRequestParameter("aSeoData");
00079         if ($aData && isset($aData["oxparams"])) {
00080             $oStr = getStr();
00081             $iStartPos = $oStr->strpos($aData["oxparams"], "#");
00082             $iEndPos = $oStr->strpos($aData["oxparams"], "#", $iStartPos + 1);
00083             $iLen = $oStr->strlen($aData["oxparams"]);
00084             $sId = $oStr->substr($aData["oxparams"], $iStartPos + 1, $iEndPos - $iLen);
00085         } elseif ($aList = $this->getSelectionList()) {
00086             $oItem = reset($aList[$this->getActCatType()][$this->getActCatLang()]);
00087             $sId = $oItem->getId();
00088         }
00089 
00090         return $sId;
00091     }
00092 
00098     public function getSelectionList()
00099     {
00100         if ($this->_aSelectionList === null) {
00101             $this->_aSelectionList = array();
00102 
00103             $oProduct = oxNew('oxarticle');
00104             $oProduct->load($this->getEditObjectId());
00105 
00106             if ($oCatList = $this->_getCategoryList($oProduct)) {
00107                 $this->_aSelectionList["oxcategory"][$this->_iEditLang] = $oCatList;
00108             }
00109 
00110             if ($oVndList = $this->_getVendorList($oProduct)) {
00111                 $this->_aSelectionList["oxvendor"][$this->_iEditLang] = $oVndList;
00112             }
00113 
00114             if ($oManList = $this->_getManufacturerList($oProduct)) {
00115                 $this->_aSelectionList["oxmanufacturer"][$this->_iEditLang] = $oManList;
00116             }
00117 
00118             $aLangs = $oProduct->getAvailableInLangs();
00119             foreach ($aLangs as $iLang => $sLangTitle) {
00120                 if ($oTagList = $this->_getTagList($oProduct, $iLang)) {
00121                     $this->_aSelectionList["oxtag"][$iLang] = $oTagList;
00122                 }
00123             }
00124         }
00125 
00126         return $this->_aSelectionList;
00127     }
00128 
00136     protected function _getCategoryList($oArticle)
00137     {
00138         $sMainCatId = false;
00139         if ($oMainCat = $oArticle->getCategory()) {
00140             $sMainCatId = $oMainCat->getId();
00141         }
00142 
00143         $aCatList = array();
00144         $iLang = $this->getEditLang();
00145 
00146         // adding categories
00147         $sView = getViewName('oxobject2category');
00148         $oDb = oxDb::getDb(oxDB::FETCH_MODE_ASSOC);
00149         $sSqlForPriceCategories = $oArticle->getSqlForPriceCategories('oxid');
00150         $sQuotesArticleId = $oDb->quote($oArticle->getId());
00151         $sQ = "select oxobject2category.oxcatnid as oxid from {$sView} as oxobject2category " .
00152               "where oxobject2category.oxobjectid=" . $sQuotesArticleId . " union " . $sSqlForPriceCategories;
00153 
00154         $oRs = $oDb->execute($sQ);
00155         if ($oRs != false && $oRs->recordCount() > 0) {
00156             while (!$oRs->EOF) {
00157                 $oCat = oxNew('oxcategory');
00158                 if ($oCat->loadInLang($iLang, current($oRs->fields))) {
00159                     if ($sMainCatId == $oCat->getId()) {
00160                         $sSuffix = oxRegistry::getLang()->translateString('(main category)', $this->getEditLang());
00161                         $sTitleField = 'oxcategories__oxtitle';
00162                         $sTitle = $oCat->$sTitleField->getRawValue() . " " . $sSuffix;
00163                         $oCat->$sTitleField = new oxField($sTitle, oxField::T_RAW);
00164                     }
00165                     $aCatList[] = $oCat;
00166                 }
00167                 $oRs->moveNext();
00168             }
00169         }
00170 
00171         return $aCatList;
00172     }
00173 
00181     protected function _getVendorList($oArticle)
00182     {
00183         if ($oArticle->oxarticles__oxvendorid->value) {
00184             $oVendor = oxNew('oxvendor');
00185             if ($oVendor->loadInLang($this->getEditLang(), $oArticle->oxarticles__oxvendorid->value)) {
00186                 return array($oVendor);
00187             }
00188         }
00189     }
00190 
00198     protected function _getManufacturerList($oArticle)
00199     {
00200         if ($oArticle->oxarticles__oxmanufacturerid->value) {
00201             $oManufacturer = oxNew('oxmanufacturer');
00202             if ($oManufacturer->loadInLang($this->getEditLang(), $oArticle->oxarticles__oxmanufacturerid->value)) {
00203                 return array($oManufacturer);
00204             }
00205         }
00206     }
00207 
00216     protected function _getTagList($oArticle, $iLang)
00217     {
00218         $oArticleTagList = oxNew("oxarticletaglist");
00219         $oArticleTagList->setLanguage($iLang);
00220         $oArticleTagList->load($oArticle->getId());
00221         $aTagsList = array();
00222         if (count($aTags = $oArticleTagList->getArray())) {
00223             $sShopId = $this->getConfig()->getShopId();
00224             $iProdId = $oArticle->getId();
00225             foreach ($aTags as $sTitle => $oTagObject) {
00226                 // A. we do not have oxTag object yet, so reusing manufacturers for general interface
00227                 $oTag = oxNew("oxManufacturer");
00228                 $oTag->setLanguage($iLang);
00229                 $oTag->setId(md5(strtolower($sShopId . $this->_getStdUrl($iProdId, "oxtag", "tag", $iLang, $sTitle))));
00230                 $oTag->oxmanufacturers__oxtitle = new oxField($sTitle);
00231                 $aTagsList[] = $oTag;
00232             }
00233         }
00234 
00235         return $aTagsList;
00236     }
00237 
00243     public function getActCategory()
00244     {
00245         $oCat = oxNew('oxcategory');
00246 
00247         return ($oCat->load($this->getActCatId())) ? $oCat : null;
00248     }
00249 
00255     public function getTag()
00256     {
00257         if ($this->getActCatType() == 'oxtag') {
00258 
00259             $iLang = $this->getActCatLang();
00260             $sTagId = $this->getActCatId();
00261 
00262             $oProduct = oxNew('oxarticle');
00263             $oProduct->loadInLang($iLang, $this->getEditObjectId());
00264 
00265             $aList = $this->_getTagList($oProduct, $iLang);
00266             foreach ($aList as $oTag) {
00267                 if ($oTag->getId() == $sTagId) {
00268                     return $oTag->getTitle();
00269                 }
00270             }
00271         }
00272     }
00273 
00279     public function getActVendor()
00280     {
00281         $oVendor = oxNew('oxvendor');
00282 
00283         return ($this->getActCatType() == 'oxvendor' && $oVendor->load($this->getActCatId())) ? $oVendor : null;
00284     }
00285 
00291     public function getActManufacturer()
00292     {
00293         $oManufacturer = oxNew('oxmanufacturer');
00294         $blLoaded = $this->getActCatType() == 'oxmanufacturer' && $oManufacturer->load($this->getActCatId());
00295 
00296         return ($blLoaded) ? $oManufacturer : null;
00297     }
00298 
00304     public function getListType()
00305     {
00306         switch ($this->getActCatType()) {
00307             case 'oxvendor':
00308                 return 'vendor';
00309             case 'oxmanufacturer':
00310                 return 'manufacturer';
00311             case 'oxtag':
00312                 return 'tag';
00313         }
00314     }
00315 
00321     public function getEditLang()
00322     {
00323         return $this->getActCatLang();
00324     }
00325 
00331     protected function _getAltSeoEntryId()
00332     {
00333         return $this->getEditObjectId();
00334     }
00335 
00341     protected function _getSeoEntryType()
00342     {
00343         if ($this->getTag()) {
00344             return 'dynamic';
00345         } else {
00346             return $this->_getType();
00347         }
00348     }
00349 
00355     protected function _getType()
00356     {
00357         return 'oxarticle';
00358     }
00359 
00367     public function processParam($sParam)
00368     {
00369         if ($this->getTag()) {
00370             return '';
00371         } else {
00372             return $this->getActCatId();
00373         }
00374     }
00375 
00381     protected function _getEncoder()
00382     {
00383         return oxRegistry::get("oxSeoEncoderArticle");
00384     }
00385 
00391     public function getEntryUri()
00392     {
00393         $oProduct = oxNew('oxarticle');
00394         if ($oProduct->load($this->getEditObjectId())) {
00395             $oEncoder = $this->_getEncoder();
00396             switch ($this->getActCatType()) {
00397                 case 'oxvendor':
00398                     return $oEncoder->getArticleVendorUri($oProduct, $this->getEditLang());
00399                 case 'oxmanufacturer':
00400                     return $oEncoder->getArticleManufacturerUri($oProduct, $this->getEditLang());
00401                 case 'oxtag':
00402                     return $oEncoder->getArticleTagUri($oProduct, $this->getActCatLang());
00403                 default:
00404                     if ($this->getActCatId()) {
00405                         return $oEncoder->getArticleUri($oProduct, $this->getEditLang());
00406                     } else {
00407                         return $oEncoder->getArticleMainUri($oProduct, $this->getEditLang());
00408                     }
00409             }
00410         }
00411     }
00412 
00424     protected function _getStdUrl($sOxid, $sCatType = null, $sListType = null, $iLang = null, $sTag = null)
00425     {
00426         $iLang = $iLang !== null ? $iLang : $this->getEditLang();
00427         $sCatType = $sCatType !== null ? $sCatType : $this->getActCatType();
00428         $sListType = $sListType !== null ? $sListType : $this->getListType();
00429 
00430         $aParams = array();
00431         if ($sListType) {
00432             $aParams["listtype"] = $sListType;
00433         }
00434 
00435         $oProduct = oxNew('oxarticle');
00436         $oProduct->loadInLang($iLang, $sOxid);
00437 
00438         // adding vendor or manufacturer id
00439         switch ($sCatType) {
00440             case 'oxvendor':
00441                 $aParams["cnid"] = "v_" . $this->getActCatId();
00442                 break;
00443             case 'oxmanufacturer':
00444                 $aParams["mnid"] = $this->getActCatId();
00445                 break;
00446             case 'oxtag':
00447                 $aParams["searchtag"] = $sTag !== null ? $sTag : $this->getTag();
00448                 break;
00449             default:
00450                 $aParams["cnid"] = $this->getActCatId();
00451                 break;
00452         }
00453 
00454         $oUtilsUrl = oxRegistry::get("oxUtilsUrl");
00455 
00456         return trim($oUtilsUrl->appendUrl($oProduct->getBaseStdLink($iLang, true, false), $aParams), '&amp;');
00457     }
00458 
00464     public function showCatSelect()
00465     {
00466         return true;
00467     }
00468 
00474     protected function _getSaveObjectId()
00475     {
00476         $sId = $this->getEditObjectId();
00477         if ($this->getActCatType() == 'oxtag') {
00478             $sId = $this->_getEncoder()->getDynamicObjectId($this->getConfig()->getShopId(), $this->_getStdUrl($sId));
00479         }
00480 
00481         return $sId;
00482     }
00483 
00489     public function isEntryFixed()
00490     {
00491         $oDb = oxDb::getDb();
00492 
00493         $sId = $this->_getSaveObjectId();
00494         $iLang = (int) $this->getEditLang();
00495         $iShopId = $this->getConfig()->getShopId();
00496         $sParam = $this->processParam($this->getActCatId());
00497 
00498         $sQ = "select oxfixed from oxseo where
00499                    oxseo.oxobjectid = " . $oDb->quote($sId) . " and
00500                    oxseo.oxshopid = '{$iShopId}' and oxseo.oxlang = {$iLang} and oxparams = " . $oDb->quote($sParam);
00501 
00502         return (bool) oxDb::getDb()->getOne($sQ, false, false);
00503     }
00504 }