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( true );
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 = oxLang::getInstance()->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         $oTagCloud = oxNew("oxTagCloud");
00214         $aTagsList = array();
00215         if ( count( $aTags = $oTagCloud->getTags( $oArticle->getId(), false, $iLang ) ) ) {
00216             $sShopId = $this->getConfig()->getShopId();
00217             $iProdId = $oArticle->getId();
00218             foreach ( $aTags as $sTitle => $sValue ) {
00219                 // A. we do not have oxTag object yet, so reusing manufacturers for general interface
00220                 $oTag = oxNew( "oxManufacturer" );
00221                 $oTag->setLanguage( $iLang );
00222                 $oTag->setId( md5( strtolower ( $sShopId . $this->_getStdUrl( $iProdId, "oxtag", "tag", $iLang, $sTitle ) ) ) );
00223                 $oTag->oxmanufacturers__oxtitle = new oxField( $sTitle );
00224                 $aTagsList[] = $oTag;
00225             }
00226         }
00227 
00228         return $aTagsList;
00229     }
00230 
00236     public function getActCategory()
00237     {
00238         $oCat = oxNew( 'oxcategory' );
00239         return ( $oCat->load( $this->getActCatId() ) ) ? $oCat : null;
00240     }
00241 
00247     public function getTag()
00248     {
00249         if ( $this->getActCatType() == 'oxtag' ) {
00250 
00251             $iLang  = $this->getActCatLang();
00252             $sTagId = $this->getActCatId();
00253 
00254             $oProduct = oxNew( 'oxarticle' );
00255             $oProduct->loadInLang( $iLang, $this->getEditObjectId() );
00256 
00257             $aList = $this->_getTagList( $oProduct, $iLang );
00258             foreach ( $aList as $oTag ) {
00259                 if ( $oTag->getId() == $sTagId ) {
00260                     return $oTag->getTitle();
00261                 }
00262             }
00263         }
00264     }
00265 
00271     public function getActVendor()
00272     {
00273         $oVendor = oxNew( 'oxvendor' );
00274         return ( $this->getActCatType() == 'oxvendor' && $oVendor->load( $this->getActCatId() ) ) ? $oVendor : null;
00275     }
00276 
00282     public function getActManufacturer()
00283     {
00284         $oManufacturer = oxNew( 'oxmanufacturer' );
00285         return ( $this->getActCatType() == 'oxmanufacturer' && $oManufacturer->load( $this->getActCatId() ) ) ? $oManufacturer : null;
00286     }
00287 
00293     public function getListType()
00294     {
00295         switch ( $this->getActCatType() ) {
00296             case 'oxvendor':
00297                 return 'vendor';
00298             case 'oxmanufacturer':
00299                 return 'manufacturer';
00300             case 'oxtag':
00301                 return 'tag';
00302         }
00303     }
00304 
00310     public function getEditLang()
00311     {
00312         return $this->getActCatLang();
00313     }
00314 
00320     protected function _getAltSeoEntryId()
00321     {
00322         return $this->getEditObjectId();
00323     }
00324 
00330     protected function _getSeoEntryType()
00331     {
00332         if ( $this->getTag() ) {
00333             return 'dynamic';
00334         } else {
00335             return $this->_getType();
00336         }
00337     }
00338 
00344     protected function _getType()
00345     {
00346         return 'oxarticle';
00347     }
00348 
00356     public function processParam( $sParam )
00357     {
00358         if ( $this->getTag() ) {
00359             return '';
00360         } else {
00361             return $this->getActCatId();
00362         }
00363     }
00364 
00370     protected function _getEncoder()
00371     {
00372         return oxSeoEncoderArticle::getInstance();
00373     }
00374 
00380     public function getEntryUri()
00381     {
00382         $oProduct = oxNew( 'oxarticle' );
00383         if ( $oProduct->load( $this->getEditObjectId() ) ) {
00384             $oEncoder = $this->_getEncoder();
00385             switch ( $this->getActCatType() ) {
00386                 case 'oxvendor':
00387                     return $oEncoder->getArticleVendorUri( $oProduct, $this->getEditLang() );
00388                 case 'oxmanufacturer':
00389                     return $oEncoder->getArticleManufacturerUri( $oProduct, $this->getEditLang() );
00390                 case 'oxtag':
00391                     return $oEncoder->getArticleTagUri( $oProduct, $this->getActCatLang() );
00392                 default:
00393                     if ( $this->getActCatId() ) {
00394                         return $oEncoder->getArticleUri( $oProduct, $this->getEditLang() );
00395                     } else {
00396                         return $oEncoder->getArticleMainUri( $oProduct, $this->getEditLang() );
00397                     }
00398             }
00399         }
00400     }
00401 
00413     protected function _getStdUrl( $sOxid, $sCatType = null, $sListType = null, $iLang = null, $sTag = null )
00414     {
00415         $iLang = $iLang !== null ? $iLang : $this->getEditLang();
00416         $sCatType  = $sCatType !== null ? $sCatType : $this->getActCatType();
00417         $sListType = $sListType !== null ? $sListType : $this->getListType();
00418 
00419         $aParams = array();
00420         if ( $sListType ) {
00421             $aParams["listtype"] = $sListType;
00422         }
00423 
00424         $oProduct = oxNew( 'oxarticle' );
00425         $oProduct->loadInLang( $iLang, $sOxid );
00426 
00427         // adding vendor or manufacturer id
00428         switch ( $sCatType ) {
00429             case 'oxvendor':
00430                 $aParams["cnid"] = "v_" . $this->getActCatId();
00431                 break;
00432             case 'oxmanufacturer':
00433                 $aParams["mnid"] = $this->getActCatId();
00434                 break;
00435             case 'oxtag':
00436                 $aParams["searchtag"] = $sTag !== null ? $sTag : $this->getTag();
00437                 break;
00438             default:
00439                 $aParams["cnid"] = $this->getActCatId();
00440                 break;
00441         }
00442 
00443         return trim( oxUtilsUrl::getInstance()->appendUrl( $oProduct->getBaseStdLink( $iLang, true, false ), $aParams ), '&amp;' );
00444     }
00445 
00451     public function showCatSelect()
00452     {
00453         return true;
00454     }
00455 
00461     protected function _getSaveObjectId()
00462     {
00463         $sId = $this->getEditObjectId();
00464         if ( $this->getActCatType() == 'oxtag' ) {
00465             $sId = $this->_getEncoder()->getDynamicObjectId( $this->getConfig()->getShopId(), $this->_getStdUrl( $sId ) );
00466         }
00467         return $sId;
00468     }
00469 
00475     public function isEntryFixed()
00476     {
00477         $oDb = oxDb::getDb();
00478 
00479         $sId   = $this->_getSaveObjectId();
00480         $iLang = (int) $this->getEditLang();
00481         $iShopId = $this->getConfig()->getShopId();
00482         $sParam  = $this->processParam( $this->getActCatId() );
00483 
00484         $sQ = "select oxfixed from oxseo where
00485                    oxseo.oxobjectid = " . $oDb->quote( $sId ) . " and
00486                    oxseo.oxshopid = '{$iShopId}' and oxseo.oxlang = {$iLang} and oxparams = ".$oDb->quote( $sParam );
00487 
00488         return (bool) oxDb::getDb()->getOne( $sQ );
00489     }
00490 }