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 $_aSelectionList = null;
00021 
00027     public function getActCatType()
00028     {
00029         $sType = false;
00030         $aData = oxConfig::getParameter( "aSeoData" );
00031         if ( $aData && isset( $aData["oxparams"] ) ) {
00032             $oStr = getStr();
00033             $iEndPos = $oStr->strpos( $aData["oxparams"], "#" );
00034             $sType = $oStr->substr( $aData["oxparams"], 0, $iEndPos );
00035         } elseif ( $aList = $this->getSelectionList() ) {
00036             reset( $aList );
00037             $sType = key( $aList );
00038         }
00039 
00040         return $sType;
00041     }
00042 
00048     public function getActCatLang()
00049     {
00050         if ( oxConfig::getParameter( "editlanguage" ) !== null ) {
00051             return $this->_iEditLang;
00052         }
00053 
00054         $iLang = false;
00055         $aData = oxConfig::getParameter( "aSeoData" );
00056         if ( $aData && isset( $aData["oxparams"] ) ) {
00057             $oStr = getStr();
00058             $iStartPos = $oStr->strpos( $aData["oxparams"], "#" );
00059             $iEndPos = $oStr->strpos( $aData["oxparams"], "#", $iStartPos + 1 );
00060             $iLang = $oStr->substr( $aData["oxparams"], $iEndPos + 1 );
00061         } elseif ( $aList = $this->getSelectionList() ) {
00062             $aList = reset( $aList );
00063             $iLang = key( $aList );
00064         }
00065 
00066         return (int) $iLang;
00067     }
00068 
00074     public function getActCatId()
00075     {
00076         $sId = false;
00077         $aData = oxConfig::getParameter( "aSeoData" );
00078         if ( $aData && isset( $aData["oxparams"] ) ) {
00079             $oStr = getStr();
00080             $iStartPos = $oStr->strpos( $aData["oxparams"], "#" );
00081             $iEndPos = $oStr->strpos( $aData["oxparams"], "#", $iStartPos + 1 );
00082             $iLen = $oStr->strlen( $aData["oxparams"] );
00083             $sId = $oStr->substr( $aData["oxparams"], $iStartPos + 1, $iEndPos - $iLen );
00084         } elseif ( $aList = $this->getSelectionList() ) {
00085             $oItem = reset( $aList[$this->getActCatType()][$this->getActCatLang()] );
00086             $sId = $oItem->getId();
00087         }
00088 
00089         return $sId;
00090     }
00091 
00097     public function getSelectionList()
00098     {
00099         if ( $this->_aSelectionList === null ) {
00100             $this->_aSelectionList = array();
00101 
00102             $oProduct = oxNew( 'oxarticle' );
00103             $oProduct->load( $this->getEditObjectId() );
00104 
00105             if ( $oCatList = $this->_getCategoryList( $oProduct ) ) {
00106                 $this->_aSelectionList["oxcategory"][$this->_iEditLang] = $oCatList;
00107             }
00108 
00109             if ( $oVndList = $this->_getVendorList( $oProduct ) ) {
00110                 $this->_aSelectionList["oxvendor"][$this->_iEditLang] = $oVndList;
00111             }
00112 
00113             if ( $oManList = $this->_getManufacturerList( $oProduct ) ) {
00114                 $this->_aSelectionList["oxmanufacturer"][$this->_iEditLang] = $oManList;
00115             }
00116 
00117             $aLangs = $oProduct->getAvailableInLangs();
00118             foreach ( $aLangs as $iLang => $sLangTitle ) {
00119                 if ( $oTagList = $this->_getTagList( $oProduct, $iLang ) ) {
00120                     $this->_aSelectionList["oxtag"][$iLang] = $oTagList;
00121                 }
00122             }
00123         }
00124 
00125         return $this->_aSelectionList;
00126     }
00127 
00135     protected function _getCategoryList( $oArticle )
00136     {
00137         $sMainCatId = false;
00138         if ( $oMainCat = $oArticle->getCategory() ) {
00139             $sMainCatId = $oMainCat->getId();
00140         }
00141 
00142         $aCatList = array();
00143         $iLang = $this->getEditLang();
00144 
00145         // adding categories
00146         $sO2CView = getViewName( 'oxobject2category');
00147         $oDb = oxDb::getDb( oxDB::FETCH_MODE_ASSOC );
00148         $sQ = "select oxobject2category.oxcatnid as oxid from $sO2CView as oxobject2category where oxobject2category.oxobjectid="
00149               . $oDb->quote( $oArticle->getId() ) . " union ".$oArticle->getSqlForPriceCategories('oxid');
00150 
00151         $oRs = $oDb->execute( $sQ );
00152         if ( $oRs != false && $oRs->recordCount() > 0 ) {
00153             while ( !$oRs->EOF ) {
00154                 $oCat = oxNew('oxcategory');
00155                 if ( $oCat->loadInLang( $iLang, current( $oRs->fields ) ) ) {
00156                     if ( $sMainCatId == $oCat->getId() ) {
00157                         $sSuffix = oxRegistry::getLang()->translateString( '(main category)', $this->getEditLang() );
00158                         $oCat->oxcategories__oxtitle = new oxField( $oCat->oxcategories__oxtitle->getRawValue() . " " . $sSuffix, oxField::T_RAW );
00159                     }
00160                     $aCatList[] = $oCat;
00161                 }
00162                 $oRs->moveNext();
00163             }
00164         }
00165 
00166         return $aCatList;
00167     }
00168 
00176     protected function _getVendorList( $oArticle )
00177     {
00178         if ( $oArticle->oxarticles__oxvendorid->value ) {
00179             $oVendor = oxNew( 'oxvendor' );
00180             if ( $oVendor->loadInLang( $this->getEditLang(), $oArticle->oxarticles__oxvendorid->value ) ) {
00181                 return array( $oVendor );
00182             }
00183         }
00184     }
00185 
00193     protected function _getManufacturerList( $oArticle )
00194     {
00195         if ( $oArticle->oxarticles__oxmanufacturerid->value ) {
00196             $oManufacturer = oxNew( 'oxmanufacturer' );
00197             if ( $oManufacturer->loadInLang( $this->getEditLang(), $oArticle->oxarticles__oxmanufacturerid->value ) ) {
00198                     return array( $oManufacturer );
00199             }
00200         }
00201     }
00202 
00211     protected function _getTagList( $oArticle, $iLang )
00212     {
00213         $oArticleTagList = oxNew("oxarticletaglist");
00214         $oArticleTagList->setLanguage( $iLang );
00215         $oArticleTagList->load( $oArticle->getId() );
00216         $aTagsList = array();
00217         if ( count( $aTags = $oArticleTagList->getArray() ) ) {
00218             $sShopId = $this->getConfig()->getShopId();
00219             $iProdId = $oArticle->getId();
00220             foreach ( $aTags as $sTitle => $oTagObject ) {
00221                 // A. we do not have oxTag object yet, so reusing manufacturers for general interface
00222                 $oTag = oxNew( "oxManufacturer" );
00223                 $oTag->setLanguage( $iLang );
00224                 $oTag->setId( md5( strtolower ( $sShopId . $this->_getStdUrl( $iProdId, "oxtag", "tag", $iLang, $sTitle ) ) ) );
00225                 $oTag->oxmanufacturers__oxtitle = new oxField( $sTitle );
00226                 $aTagsList[] = $oTag;
00227             }
00228         }
00229 
00230         return $aTagsList;
00231     }
00232 
00238     public function getActCategory()
00239     {
00240         $oCat = oxNew( 'oxcategory' );
00241         return ( $oCat->load( $this->getActCatId() ) ) ? $oCat : null;
00242     }
00243 
00249     public function getTag()
00250     {
00251         if ( $this->getActCatType() == 'oxtag' ) {
00252 
00253             $iLang  = $this->getActCatLang();
00254             $sTagId = $this->getActCatId();
00255 
00256             $oProduct = oxNew( 'oxarticle' );
00257             $oProduct->loadInLang( $iLang, $this->getEditObjectId() );
00258 
00259             $aList = $this->_getTagList( $oProduct, $iLang );
00260             foreach ( $aList as $oTag ) {
00261                 if ( $oTag->getId() == $sTagId ) {
00262                     return $oTag->getTitle();
00263                 }
00264             }
00265         }
00266     }
00267 
00273     public function getActVendor()
00274     {
00275         $oVendor = oxNew( 'oxvendor' );
00276         return ( $this->getActCatType() == 'oxvendor' && $oVendor->load( $this->getActCatId() ) ) ? $oVendor : null;
00277     }
00278 
00284     public function getActManufacturer()
00285     {
00286         $oManufacturer = oxNew( 'oxmanufacturer' );
00287         return ( $this->getActCatType() == 'oxmanufacturer' && $oManufacturer->load( $this->getActCatId() ) ) ? $oManufacturer : null;
00288     }
00289 
00295     public function getListType()
00296     {
00297         switch ( $this->getActCatType() ) {
00298             case 'oxvendor':
00299                 return 'vendor';
00300             case 'oxmanufacturer':
00301                 return 'manufacturer';
00302             case 'oxtag':
00303                 return 'tag';
00304         }
00305     }
00306 
00312     public function getEditLang()
00313     {
00314         return $this->getActCatLang();
00315     }
00316 
00322     protected function _getAltSeoEntryId()
00323     {
00324         return $this->getEditObjectId();
00325     }
00326 
00332     protected function _getSeoEntryType()
00333     {
00334         if ( $this->getTag() ) {
00335             return 'dynamic';
00336         } else {
00337             return $this->_getType();
00338         }
00339     }
00340 
00346     protected function _getType()
00347     {
00348         return 'oxarticle';
00349     }
00350 
00358     public function processParam( $sParam )
00359     {
00360         if ( $this->getTag() ) {
00361             return '';
00362         } else {
00363             return $this->getActCatId();
00364         }
00365     }
00366 
00372     protected function _getEncoder()
00373     {
00374         return oxRegistry::get("oxSeoEncoderArticle");
00375     }
00376 
00382     public function getEntryUri()
00383     {
00384         $oProduct = oxNew( 'oxarticle' );
00385         if ( $oProduct->load( $this->getEditObjectId() ) ) {
00386             $oEncoder = $this->_getEncoder();
00387             switch ( $this->getActCatType() ) {
00388                 case 'oxvendor':
00389                     return $oEncoder->getArticleVendorUri( $oProduct, $this->getEditLang() );
00390                 case 'oxmanufacturer':
00391                     return $oEncoder->getArticleManufacturerUri( $oProduct, $this->getEditLang() );
00392                 case 'oxtag':
00393                     return $oEncoder->getArticleTagUri( $oProduct, $this->getActCatLang() );
00394                 default:
00395                     if ( $this->getActCatId() ) {
00396                         return $oEncoder->getArticleUri( $oProduct, $this->getEditLang() );
00397                     } else {
00398                         return $oEncoder->getArticleMainUri( $oProduct, $this->getEditLang() );
00399                     }
00400             }
00401         }
00402     }
00403 
00415     protected function _getStdUrl( $sOxid, $sCatType = null, $sListType = null, $iLang = null, $sTag = null )
00416     {
00417         $iLang = $iLang !== null ? $iLang : $this->getEditLang();
00418         $sCatType  = $sCatType !== null ? $sCatType : $this->getActCatType();
00419         $sListType = $sListType !== null ? $sListType : $this->getListType();
00420 
00421         $aParams = array();
00422         if ( $sListType ) {
00423             $aParams["listtype"] = $sListType;
00424         }
00425 
00426         $oProduct = oxNew( 'oxarticle' );
00427         $oProduct->loadInLang( $iLang, $sOxid );
00428 
00429         // adding vendor or manufacturer id
00430         switch ( $sCatType ) {
00431             case 'oxvendor':
00432                 $aParams["cnid"] = "v_" . $this->getActCatId();
00433                 break;
00434             case 'oxmanufacturer':
00435                 $aParams["mnid"] = $this->getActCatId();
00436                 break;
00437             case 'oxtag':
00438                 $aParams["searchtag"] = $sTag !== null ? $sTag : $this->getTag();
00439                 break;
00440             default:
00441                 $aParams["cnid"] = $this->getActCatId();
00442                 break;
00443         }
00444 
00445         return trim( oxRegistry::get("oxUtilsUrl")->appendUrl( $oProduct->getBaseStdLink( $iLang, true, false ), $aParams ), '&amp;' );
00446     }
00447 
00453     public function showCatSelect()
00454     {
00455         return true;
00456     }
00457 
00463     protected function _getSaveObjectId()
00464     {
00465         $sId = $this->getEditObjectId();
00466         if ( $this->getActCatType() == 'oxtag' ) {
00467             $sId = $this->_getEncoder()->getDynamicObjectId( $this->getConfig()->getShopId(), $this->_getStdUrl( $sId ) );
00468         }
00469         return $sId;
00470     }
00471 
00477     public function isEntryFixed()
00478     {
00479         $oDb = oxDb::getDb();
00480 
00481         $sId   = $this->_getSaveObjectId();
00482         $iLang = (int) $this->getEditLang();
00483         $iShopId = $this->getConfig()->getShopId();
00484         $sParam  = $this->processParam( $this->getActCatId() );
00485 
00486         $sQ = "select oxfixed from oxseo where
00487                    oxseo.oxobjectid = " . $oDb->quote( $sId ) . " and
00488                    oxseo.oxshopid = '{$iShopId}' and oxseo.oxlang = {$iLang} and oxparams = ".$oDb->quote( $sParam );
00489 
00490         return (bool) oxDb::getDb()->getOne( $sQ, false, false );
00491     }
00492 }