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
00034 self::$_instance->_aSeoCache = array();
00035 }
00036
00037 return self::$_instance;
00038 }
00039
00045 protected function _getUrlExtension()
00046 {
00047 return '/';
00048 }
00049
00063 protected function _getContentUri( $oCont, $iLang = null, $blRegenerate = false )
00064 {
00065 return $this->getContentUri( $oCont, $iLang, $blRegenerate );
00066 }
00067
00078 public function getContentUri( $oCont, $iLang = null, $blRegenerate = false )
00079 {
00080 if (!isset($iLang)) {
00081 $iLang = $oCont->getLanguage();
00082 }
00083
00084 if ( $blRegenerate || !( $sSeoUrl = $this->_loadFromDb( 'oxcontent', $oCont->getId(), $iLang ) ) ) {
00085
00086 if ( $iLang != $oCont->getLanguage() ) {
00087 $sId = $oCont->getId();
00088 $oCont = oxNew('oxcontent');
00089 $oCont->loadInLang( $iLang, $sId );
00090 }
00091
00092 $sSeoUrl = '';
00093 if ( $oCont->oxcontents__oxcatid->value ) {
00094 $oCat = oxNew( 'oxcategory' );
00095 if ( $oCat->loadInLang( $iLang, $oCont->oxcontents__oxcatid->value ) ) {
00096 if ( $oCat->oxcategories__oxparentid->value && $oCat->oxcategories__oxparentid->value != 'oxrootid' ) {
00097 $oParentCat = oxNew( 'oxcategory' );
00098 if ( $oParentCat->loadInLang( $iLang, $oCat->oxcategories__oxparentid->value ) ) {
00099 $sSeoUrl .= oxSeoEncoderCategory::getInstance()->getCategoryUri( $oParentCat );
00100 }
00101 }
00102 }
00103 }
00104
00105 $sSeoUrl .= $this->_prepareTitle( $oCont->oxcontents__oxtitle->value ) . '/';
00106 $sSeoUrl = $this->_processSeoUrl( $sSeoUrl, $oCont->getId(), $iLang );
00107
00108 $this->_saveToDb( 'oxcontent', $oCont->getId(), $oCont->getBaseStdLink($iLang), $sSeoUrl, $iLang );
00109 }
00110 return $sSeoUrl;
00111 }
00112
00123 public function getContentUrl( $oCont, $iLang = null)
00124 {
00125 if (!isset($iLang)) {
00126 $iLang = $oCont->getLanguage();
00127 }
00128 return $this->_getFullUrl( $this->_getContentUri( $oCont, $iLang ), $iLang );
00129 }
00130
00138 public function onDeleteContent( $sId )
00139 {
00140 $oDb = oxDb::getDb();
00141 $sIdQuoted = $oDb->quote($sId);
00142 $oDb->execute("delete from oxseo where oxobjectid = $sIdQuoted and oxtype = 'oxcontent'");
00143 $oDb->execute("delete from oxobject2seodata where oxobjectid = $sIdQuoted");
00144 }
00145
00154 protected function _getAltUri( $sObjectId, $iLang )
00155 {
00156 $sSeoUrl = null;
00157 $oCont = oxNew( "oxcontent" );
00158 if ( $oCont->loadInLang( $iLang, $sObjectId ) ) {
00159 $sSeoUrl = $this->_getContentUri( $oCont, $iLang, true );
00160 }
00161 return $sSeoUrl;
00162 }
00163 }