oxseoencodercontent.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxSeoEncoderContent extends oxSeoEncoder
00008 {
00012     protected static $_instance = null;
00013 
00021     public static function getInstance()
00022     {
00023         return oxRegistry::get("oxSeoEncoderContent");
00024     }
00025 
00031     protected function _getUrlExtension()
00032     {
00033         return '/';
00034     }
00035 
00046     public function getContentUri( $oCont, $iLang = null, $blRegenerate = false )
00047     {
00048         if (!isset($iLang)) {
00049             $iLang = $oCont->getLanguage();
00050         }
00051         //load details link from DB
00052         if ( $blRegenerate || !( $sSeoUrl = $this->_loadFromDb( 'oxcontent', $oCont->getId(), $iLang ) ) ) {
00053 
00054             if ( $iLang != $oCont->getLanguage() ) {
00055                 $sId = $oCont->getId();
00056                 $oCont = oxNew('oxcontent');
00057                 $oCont->loadInLang( $iLang, $sId );
00058             }
00059 
00060             $sSeoUrl = '';
00061             if ( $oCont->oxcontents__oxcatid->value ) {
00062                 $oCat = oxNew( 'oxcategory' );
00063                 if ( $oCat->loadInLang( $iLang, $oCont->oxcontents__oxcatid->value ) ) {
00064                     if ( $oCat->oxcategories__oxparentid->value && $oCat->oxcategories__oxparentid->value != 'oxrootid' ) {
00065                         $oParentCat = oxNew( 'oxcategory' );
00066                         if ( $oParentCat->loadInLang( $iLang, $oCat->oxcategories__oxparentid->value ) ) {
00067                             $sSeoUrl .= oxRegistry::get("oxSeoEncoderCategory")->getCategoryUri( $oParentCat );
00068                         }
00069                     }
00070                 }
00071             }
00072 
00073             $sSeoUrl .= $this->_prepareTitle( $oCont->oxcontents__oxtitle->value, false, $oCont->getLanguage() ) . '/';
00074             $sSeoUrl  = $this->_processSeoUrl( $sSeoUrl, $oCont->getId(), $iLang );
00075 
00076             $this->_saveToDb( 'oxcontent', $oCont->getId(), $oCont->getBaseStdLink($iLang), $sSeoUrl, $iLang );
00077         }
00078         return $sSeoUrl;
00079     }
00080 
00091     public function getContentUrl( $oCont, $iLang = null)
00092     {
00093         if (!isset($iLang)) {
00094             $iLang = $oCont->getLanguage();
00095         }
00096         return $this->_getFullUrl( $this->getContentUri( $oCont, $iLang ), $iLang );
00097     }
00098 
00106     public function onDeleteContent( $sId )
00107     {
00108         $oDb = oxDb::getDb();
00109         $sIdQuoted = $oDb->quote($sId);
00110         $oDb->execute("delete from oxseo where oxobjectid = $sIdQuoted and oxtype = 'oxcontent'");
00111         $oDb->execute("delete from oxobject2seodata where oxobjectid = $sIdQuoted");
00112     }
00113 
00122     protected function _getAltUri( $sObjectId, $iLang )
00123     {
00124         $sSeoUrl = null;
00125         $oCont = oxNew( "oxcontent" );
00126         if ( $oCont->loadInLang( $iLang, $sObjectId ) ) {
00127             $sSeoUrl = $this->getContentUri( $oCont, $iLang, true );
00128         }
00129         return $sSeoUrl;
00130     }
00131 }