oxseoencodercontent.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxSeoEncoderContent extends oxSeoEncoder
00008 {
00012     protected static $_instance = null;
00013 
00019     public static function getInstance()
00020     {
00021         if ( defined( 'OXID_PHP_UNIT' ) ) {
00022             self::$_instance = modInstances::getMod( __CLASS__ );
00023         }
00024 
00025         if (!self::$_instance) {
00026             self::$_instance = oxNew("oxSeoEncoderContent");
00027             if ( defined( 'OXID_PHP_UNIT' ) ) {
00028                 modInstances::addMod( __CLASS__, self::$_instance);
00029             }
00030         }
00031 
00032         if ( defined( 'OXID_PHP_UNIT' ) ) {
00033             // resetting cache
00034             self::$_instance->_aSeoCache = array();
00035         }
00036 
00037         return self::$_instance;
00038     }
00039 
00045     protected function _getUrlExtension()
00046     {
00047         return '/';
00048     }
00049 
00060     protected function _getContentUri( $oCont, $iLang = null, $blRegenerate = false )
00061     {
00062         if (!isset($iLang)) {
00063             $iLang = $oCont->getLanguage();
00064         }
00065         //load details link from DB
00066         if ( $blRegenerate || !( $sSeoUrl = $this->_loadFromDb( 'oxcontent', $oCont->getId(), $iLang ) ) ) {
00067 
00068             if ( $iLang != $oCont->getLanguage() ) {
00069                 $sId = $oCont->getId();
00070                 $oCont = oxNew('oxcontent');
00071                 $oCont->loadInLang( $iLang, $sId );
00072             }
00073 
00074             $sSeoUrl = '';
00075             if ( $oCont->oxcontents__oxcatid->value ) {
00076                 $oCat = oxNew( 'oxcategory' );
00077                 if ( $oCat->loadInLang( $iLang, $oCont->oxcontents__oxcatid->value ) ) {
00078                     if ( $oCat->oxcategories__oxparentid->value && $oCat->oxcategories__oxparentid->value != 'oxrootid' ) {
00079                         $oParentCat = oxNew( 'oxcategory' );
00080                         if ( $oParentCat->loadInLang( $iLang, $oCat->oxcategories__oxparentid->value ) ) {
00081                             $sSeoUrl .= oxSeoEncoderCategory::getInstance()->getCategoryUri( $oParentCat );
00082                         }
00083                     }
00084                 }
00085             }
00086 
00087             $sSeoUrl .= $this->_prepareTitle( $oCont->oxcontents__oxtitle->value ) . '/';
00088             $sSeoUrl  = $this->_processSeoUrl( $sSeoUrl, $oCont->getId(), $iLang );
00089 
00090             $this->_saveToDb( 'oxcontent', $oCont->getId(), $oCont->getBaseStdLink($iLang), $sSeoUrl, $iLang );
00091         }
00092         return $sSeoUrl;
00093     }
00094 
00105     public function getContentUrl( $oCont, $iLang = null)
00106     {
00107         if (!isset($iLang)) {
00108             $iLang = $oCont->getLanguage();
00109         }
00110         return $this->_getFullUrl( $this->_getContentUri( $oCont, $iLang ), $iLang );
00111     }
00112 
00120     public function onDeleteContent( $sId )
00121     {
00122         $oDb = oxDb::getDb();
00123         $sIdQuoted = $oDb->quote($sId);
00124         $oDb->execute("delete from oxseo where oxobjectid = $sIdQuoted and oxtype = 'oxcontent'");
00125         $oDb->execute("delete from oxobject2seodata where oxobjectid = $sIdQuoted");
00126     }
00127 
00136     protected function _getAltUri( $sObjectId, $iLang )
00137     {
00138         $sSeoUrl = null;
00139         $oCont = oxNew( "oxcontent" );
00140         if ( $oCont->loadInLang( $iLang, $sObjectId ) ) {
00141             $sSeoUrl = $this->_getContentUri( $oCont, $iLang, true );
00142         }
00143         return $sSeoUrl;
00144     }
00145 }