00001 <?php
00002
00007 class oxSeoEncoder extends oxSuperCfg
00008 {
00015 protected static $_aReservedWords = array( 'admin' );
00016
00022 protected static $_aReservedEntryKeys = null;
00023
00029 protected static $_sSeparator = null;
00030
00036 protected $_iIdLength = 255;
00037
00043 protected static $_sPrefix = null;
00044
00050 protected $_sAddParams = null;
00051
00057 protected static $_instance = null;
00058
00064 protected $_aSeoCache = array();
00065
00071 public static function getInstance()
00072 {
00073 if (!self::$_instance) {
00074 self::$_instance = oxNew("oxSeoEncoder");
00075 }
00076
00077 if ( defined( 'OXID_PHP_UNIT' ) ) {
00078
00079 self::$_instance->_aSeoCache = array();
00080 }
00081
00082 return self::$_instance;
00083 }
00084
00093 public function addLanguageParam( $sSeoUrl, $iLang )
00094 {
00095 $iLang = (int) $iLang;
00096 $iDefLang = (int) $this->getConfig()->getConfigParam( 'iDefSeoLang' );
00097 $aLangIds = oxLang::getInstance()->getLanguageIds();
00098
00099 if ( $iLang != $iDefLang && isset( $aLangIds[$iLang] ) && getStr()->strpos( $sSeoUrl, $aLangIds[$iLang] . '/' ) !== 0 ) {
00100 $sSeoUrl = $aLangIds[$iLang] . '/'.$sSeoUrl;
00101 }
00102
00103 return $sSeoUrl;
00104 }
00105
00118 protected function _processSeoUrl( $sSeoUrl, $sObjectId = null, $iLang = null, $blExclude = false )
00119 {
00120 return $this->_getUniqueSeoUrl( $blExclude ? $sSeoUrl : $this->addLanguageParam( $sSeoUrl, $iLang ), $sObjectId, $iLang );
00121 }
00122
00128 public function resetCache()
00129 {
00130 $this->_aSeoCache = array();
00131 }
00132
00136 public function __construct()
00137 {
00138 $myConfig = $this->getConfig();
00139 if (!self::$_sSeparator) {
00140 $this->setSeparator( $myConfig->getConfigParam( 'sSEOSeparator' ) );
00141 }
00142 if (!self::$_sPrefix) {
00143 $this->setPrefix( $myConfig->getConfigParam( 'sSEOuprefix' ) );
00144 }
00145 $this->setReservedWords( $myConfig->getConfigParam( 'aSEOReservedWords' ) );
00146 }
00147
00159 protected function _copyToHistory( $sId, $iShopId, $iLang, $sType = null, $sNewId = null )
00160 {
00161 $sObjectid = $sNewId?"'$sNewId'":'oxobjectid';
00162 $sType = $sType?"oxtype = {$sType} and":'';
00163
00164
00165 $sSub = "select {$sObjectid}, MD5( LOWER( oxseourl ) ), oxshopid, oxlang, now() from oxseo where {$sType} oxobjectid = {$sId} and oxshopid = {$iShopId} and oxlang = {$iLang} limit 1";
00166 $sQ = "replace oxseohistory ( oxobjectid, oxident, oxshopid, oxlang, oxinsert ) {$sSub}";
00167 oxDb::getDb()->execute( $sQ );
00168 }
00169
00176 protected function _getAddParams()
00177 {
00178
00179 if ( $this->_sAddParams === null ) {
00180 $this->_sAddParams = $this->_getAddParamsFnc( oxConfig::getParameter('currency'), $this->getConfig()->getShopId() );
00181 }
00182 return $this->_sAddParams;
00183 }
00184
00194 protected function _getAddParamsFnc( $iCur, $iActShop )
00195 {
00196
00197 $this->_sAddParams = '';
00198 $sSep = '?';
00199 if ( $iCur ) {
00200 $this->_sAddParams .= $sSep . 'cur=' . $iCur;
00201 $sSep = '&';
00202 }
00203
00204
00205 return $this->_sAddParams;
00206 }
00207
00218 protected function _getDynamicObjectId( $iShopId, $sStdUrl )
00219 {
00220 return $this->getDynamicObjectId( $iShopId, $sStdUrl );
00221 }
00222
00231 public function getDynamicObjectId( $iShopId, $sStdUrl )
00232 {
00233 return $this->_getStaticObjectId( $iShopId, $sStdUrl );
00234 }
00235
00245 protected function _getDynamicUri( $sStdUrl, $sSeoUrl, $iLang )
00246 {
00247 $iShopId = $this->getConfig()->getShopId();
00248
00249 $sStdUrl = $this->_trimUrl( $sStdUrl );
00250 $sObjectId = $this->getDynamicObjectId( $iShopId, $sStdUrl );
00251 $sSeoUrl = $this->_prepareTitle( $sSeoUrl );
00252
00253
00254 $sOldSeoUrl = $this->_loadFromDb( 'dynamic', $sObjectId, $iLang );
00255 if ( $sOldSeoUrl === $sSeoUrl ) {
00256 $sSeoUrl = $sOldSeoUrl;
00257 } else {
00258
00259 if ( $sOldSeoUrl ) {
00260 $oDb = oxDb::getDb();
00261 $this->_copyToHistory( $oDb->quote( $sObjectId ), $oDb->quote( $iShopId ), $iLang, $oDb->quote( 'dynamic' ) );
00262 }
00263
00264
00265 $sSeoUrl = $this->_processSeoUrl( $sSeoUrl, $sObjectId, $iLang );
00266
00267
00268 $this->_saveToDb( 'dynamic', $sObjectId, $sStdUrl, $sSeoUrl, $iLang, $iShopId );
00269 }
00270
00271 return $sSeoUrl;
00272 }
00273
00282 protected function _getFullUrl( $sSeoUrl, $iLang = null)
00283 {
00284 $sFullUrl = $this->getConfig()->getShopUrl( $iLang ) . $sSeoUrl . $this->_getAddParams();
00285 return $this->getSession()->processUrl( $sFullUrl );
00286 }
00287
00298 protected function _getSeoIdent( $sSeoUrl, $iLang = null )
00299 {
00300 return md5( strtolower( $sSeoUrl ) );
00301 }
00302
00312 protected function _getStaticUri( $sStdUrl, $iShopId, $iLang )
00313 {
00314 $sStdUrl = $this->_trimUrl( $sStdUrl, $iLang );
00315 return $this->_loadFromDb( 'static', $this->_getStaticObjectId( $iShopId, $sStdUrl ), $iLang );
00316 }
00317
00323 protected function _getUrlExtension()
00324 {
00325 return;
00326 }
00327
00340 protected function _getUniqueSeoUrl( $sSeoUrl, $sObjectId = null, $iObjectLang = null )
00341 {
00342 $oStr = getStr();
00343 $sConstEnd = $this->_getUrlExtension();
00344 if ($sConstEnd === null) {
00345 $aMatched = array();
00346 if ( preg_match('/\.html?$/i', $sSeoUrl, $aMatched ) ) {
00347 $sConstEnd = $aMatched[0];
00348 } else {
00349 if ($sSeoUrl{$oStr->strlen($sSeoUrl)-1} != '/') {
00350 $sSeoUrl .= '/';
00351 }
00352 $sConstEnd = '/';
00353 }
00354 }
00355
00356
00357 $sAdd = ' ';
00358 if ('/' != self::$_sSeparator) {
00359 $sAdd = self::$_sSeparator . self::$_sPrefix;
00360 } else {
00361 $sAdd = '_' . self::$_sPrefix;
00362 }
00363 $sSeoUrl = preg_replace( "#^(/*)(".implode('|', $this->_getReservedEntryKeys()).")/#i", "\$1\$2$sAdd/", $sSeoUrl );
00364
00365 $sBaseSeoUrl = $sSeoUrl;
00366 if ( $sConstEnd && $oStr->substr( $sSeoUrl, 0 - $oStr->strlen( $sConstEnd ) ) == $sConstEnd ) {
00367 $sBaseSeoUrl = $oStr->substr( $sSeoUrl, 0, $oStr->strlen( $sSeoUrl ) - $oStr->strlen( $sConstEnd ) );
00368 }
00369
00370 $oDb = oxDb::getDb();
00371 $iShopId = $this->getConfig()->getShopId();
00372 $iCnt = 0;
00373 $sCheckSeoUrl = $this->_trimUrl( $sSeoUrl );
00374 $sQ = "select 1 from oxseo where oxshopid = '{$iShopId}'";
00375
00376
00377 if ( $sObjectId && isset($iObjectLang) ) {
00378 $sQ .= " and not (oxobjectid = '{$sObjectId}' and oxlang = $iObjectLang)";
00379 }
00380
00381 while ( $oDb->getOne( $sQ ." and oxident='".$this->_getSeoIdent( $sCheckSeoUrl )."' " ) ) {
00382 $sAdd = '';
00383 if ( self::$_sPrefix ) {
00384 $sAdd = self::$_sSeparator . self::$_sPrefix;
00385 }
00386 if ( $iCnt ) {
00387 $sAdd .= self::$_sSeparator . $iCnt;
00388 }
00389 ++$iCnt;
00390
00391 $sSeoUrl = $sBaseSeoUrl . $sAdd . $sConstEnd;
00392 $sCheckSeoUrl = $this->_trimUrl( $sSeoUrl );
00393 }
00394 return $sSeoUrl;
00395 }
00396
00412 protected function _loadFromDb( $sType, $sId, $iLang, $iShopId = null, $sParams = null, $blStrictParamsCheck = true)
00413 {
00414 $oDb = oxDb::getDb( true );
00415 if ( $iShopId === null ) {
00416 $iShopId = $this->getConfig()->getShopId();
00417 }
00418
00419 $iShopId = $oDb->quote( $iShopId );
00420 $sId = $oDb->quote( $sId );
00421 $sType = $oDb->quote( $sType );
00422 $iLang = (int) $iLang;
00423
00424 $sQ = "select oxfixed, oxseourl, oxexpired, oxtype from oxseo where oxtype = {$sType}
00425 and oxobjectid = {$sId} and oxshopid = {$iShopId} and oxlang = {$iLang}";
00426
00427 $sParams = $sParams ? $sParams : '';
00428 if ( $sParams && $blStrictParamsCheck ) {
00429 $sQ .= " and oxparams = '{$sParams}'";
00430 } else {
00431 $sQ .= " order by oxparams = '{$sParams}' desc";
00432 }
00433 $sQ .= " limit 1";
00434
00435
00436 $sIdent = md5($sQ);
00437 if ( isset( $this->_aSeoCache[$sIdent] ) ) {
00438 return $this->_aSeoCache[$sIdent];
00439 }
00440
00441 $sSeoUrl = false;
00442 $oRs = $oDb->execute( $sQ );
00443 if ( $oRs && $oRs->recordCount() > 0 && !$oRs->EOF ) {
00444
00445 if ( $oRs->fields['oxexpired'] && ( $oRs->fields['oxtype'] == 'static' || $oRs->fields['oxtype'] == 'dynamic' ) ) {
00446
00447 $this->_copyToHistory( $sId, $iShopId, $iLang );
00448 $oDb->execute( "update oxseo set oxexpired = 0 where oxobjectid = {$sId} and oxlang = '{$iLang}' " );
00449 $sSeoUrl = $oRs->fields['oxseourl'];
00450 } elseif ( !$oRs->fields['oxexpired'] || $oRs->fields['oxfixed'] ) {
00451
00452 $sSeoUrl = $oRs->fields['oxseourl'];
00453 }
00454
00455
00456 $this->_aSeoCache[$sIdent] = $sSeoUrl;
00457 }
00458 return $sSeoUrl;
00459 }
00460
00467 protected function _getReservedEntryKeys()
00468 {
00469 if (!isset(self::$_aReservedEntryKeys) && !is_array(self::$_aReservedEntryKeys)) {
00470 $sDir = getShopBasePath();
00471 self::$_aReservedEntryKeys = array();
00472 foreach (glob("$sDir/*") as $file) {
00473 if (preg_match('/^(.+)\.php[0-9]*$/i', basename($file), $m)) {
00474 self::$_aReservedEntryKeys[] = $m[0];
00475 self::$_aReservedEntryKeys[] = $m[1];
00476 } elseif (is_dir($file)) {
00477 self::$_aReservedEntryKeys[] = basename($file);
00478 }
00479 }
00480 }
00481 return self::$_aReservedEntryKeys;
00482 }
00483
00492 protected function _prepareTitle( $sTitle, $blSkipTruncate = false )
00493 {
00494
00495 $sTitle = $this->encodeString( $sTitle );
00496
00497
00498 $sTitle = strip_tags( $sTitle );
00499 $sSeparator = self::$_sSeparator;
00500 $sPrefix = self::$_sPrefix;
00501
00502 foreach ( self::$_aReservedWords as $sWord ) {
00503
00504 $sTitle = preg_replace( array( "/(\s$sWord)$/i", "/^($sWord\s)/i", "/(\s$sWord\s)/i", "/^($sWord)$/i",
00505 "/(\/$sWord)$/i", "/^($sWord\/)/i", "/(\/$sWord\/)/i"),
00506 " $1{$sSeparator}{$sPrefix}{$sSeparator} ", $sTitle );
00507 }
00508
00509
00510 $sExt = '';
00511 $oStr = getStr();
00512 $aMatched = array();
00513 if ( preg_match( '/\.html?$/i', $sTitle, $aMatched ) ) {
00514 $sExt = $oStr->substr( $sTitle, 0 - $oStr->strlen( $aMatched[0] ) );
00515 $sTitle = $oStr->substr( $sTitle, 0, $oStr->strlen( $sTitle ) - $oStr->strlen( $aMatched[0] ) );
00516 }
00517
00518
00519 if ( !$blSkipTruncate && $oStr->strlen( $sTitle ) > $this->_iIdLength ) {
00520
00521 if ( ( $iFirstSpace = $oStr->strstr( $oStr->substr( $sTitle, $this->_iIdLength ), ' ' ) !== false ) ) {
00522 $sTitle = $oStr->substr( $sTitle, 0, $this->_iIdLength + $iFirstSpace );
00523 }
00524 }
00525
00526
00527 $sRegExp = '/[^A-Za-z0-9'.preg_quote( self::$_sSeparator, '/').'\/]+/';
00528 $sTitle = trim( $oStr->preg_replace( array( "/\W*\/\W*/", $sRegExp ), array( "/", self::$_sSeparator ), $sTitle ), self::$_sSeparator );
00529
00530
00531 if ( !$sTitle ) {
00532 $sTitle = $this->_prepareTitle( self::$_sPrefix );
00533 }
00534
00535
00536 $sTitle .= $sExt;
00537
00538
00539 return $oStr->preg_replace( array( '|//+|', '/' . preg_quote( self::$_sSeparator . self::$_sSeparator, '/' ) .'+/' ),
00540 array( '/', self::$_sSeparator ), $sTitle );
00541 }
00542
00543
00562 protected function _saveToDb( $sType, $sObjectId, $sStdUrl, $sSeoUrl, $iLang, $iShopId = null, $blFixed = null, $sKeywords = false, $sDescription = false, $sParams = null )
00563 {
00564 $oDb = oxDb::getDb( true );
00565 if ( $iShopId === null ) {
00566 $iShopId = $this->getConfig()->getShopId();
00567 }
00568
00569 $iShopId = $oDb->quote( $iShopId );
00570
00571 $sObjectId = $oDb->quote( $sObjectId );
00572 $sType = $oDb->quote( $sType );
00573
00574 $iLang = (int) $iLang;
00575
00576 $sStdUrl = $this->_trimUrl( $sStdUrl );
00577 $sSeoUrl = $this->_trimUrl( $sSeoUrl );
00578
00579 $sIdent = $this->_getSeoIdent( $sSeoUrl );
00580
00581 $sStdUrl = $oDb->quote( $sStdUrl );
00582 $sSeoUrl = $oDb->quote( $sSeoUrl );
00583
00584
00585 $sQ = "select oxfixed, oxexpired, ( oxstdurl like {$sStdUrl} and oxexpired != 2 ) as samestdurl, oxseourl like {$sSeoUrl} as sameseourl from oxseo where oxtype = {$sType} and oxobjectid = {$sObjectId} and oxshopid = {$iShopId} and oxlang = {$iLang} ";
00586 $sQ .= $sParams ? " and oxparams = " . $oDb->quote( $sParams ) : '';
00587 $sQ .= ( $sKeywords !== false ) ? " and oxkeywords = " . $oDb->quote( $sKeywords ) . " " : '';
00588 $sQ .= ( $sDescription !== false ) ? " and oxdescription = " . $oDb->quote( $sDescription ) . " " : '';
00589 $sQ .= isset( $blFixed ) ? " and oxfixed = " . ( (int) $blFixed ) . " " : '';
00590 $sQ .= "limit 1";
00591
00592 $oRs = $oDb->execute( $sQ );
00593 if ( $oRs && $oRs->recordCount() > 0 && !$oRs->EOF ) {
00594
00595 if ( $oRs->fields['samestdurl'] && $oRs->fields['sameseourl'] && $oRs->fields['oxexpired'] ) {
00596
00597 return $oDb->execute( "update oxseo set oxexpired = 0 where oxtype = {$sType} and oxobjectid = {$sObjectId} and oxshopid = {$iShopId} and oxlang = {$iLang} limit 1" );
00598 } elseif ( $oRs->fields['oxexpired'] && !$oRs->fields['oxfixed'] ) {
00599
00600 $this->_copyToHistory( $sObjectId, $iShopId, $iLang, $sType );
00601 }
00602 }
00603 $oStr = getStr();
00604 if ( $sKeywords !== false ) {
00605 $sKeywords = $oDb->quote( $oStr->htmlentities( $this->encodeString( strip_tags( $sKeywords ), false ) ) );
00606 }
00607
00608 if ( $sDescription !== false ) {
00609 $sDescription = $oDb->quote( $oStr->htmlentities( strip_tags( $sDescription ) ) );
00610 }
00611
00612
00613 $sParams = $sParams ? $oDb->quote( $sParams ) :'""';
00614 $blFixed = (int) $blFixed;
00615
00616 $sQ = "insert into oxseo
00617 (oxobjectid, oxident, oxshopid, oxlang, oxstdurl, oxseourl, oxtype, oxfixed, oxexpired, oxkeywords, oxdescription, oxparams)
00618 values
00619 ( {$sObjectId}, '$sIdent', {$iShopId}, {$iLang}, {$sStdUrl}, {$sSeoUrl}, {$sType}, '$blFixed', '0',
00620 ".( $sKeywords ? $sKeywords : "''" ).", ".( $sDescription ? $sDescription : "''" ).", $sParams )
00621 on duplicate key update oxident = '$sIdent', oxstdurl = {$sStdUrl}, oxseourl = {$sSeoUrl}, oxfixed = '$blFixed', oxexpired = '0',
00622 oxkeywords = ".( $sKeywords ? $sKeywords : "oxkeywords" ).", oxdescription = ".( $sDescription ? $sDescription : "oxdescription" );
00623
00624 return $oDb->execute( $sQ );
00625 }
00626
00637 protected function _trimUrl( $sUrl, $iLang = null )
00638 {
00639 $sUrl = str_replace( $this->getConfig()->getShopURL( $iLang ), '', $sUrl );
00640 return preg_replace( '/(force_)?sid=[a-z0-9\.]+&?(amp;)?/i', '', $sUrl );
00641 }
00642
00651 public function encodeString( $sString, $blReplaceChars = true )
00652 {
00653
00654 $sString = getStr()->html_entity_decode( $sString );
00655
00656 if ( $blReplaceChars ) {
00657 $aReplaceChars = $this->getConfig()->getConfigParam( 'aSeoReplaceChars' );
00658 $sString = str_replace( array_keys( $aReplaceChars ), array_values( $aReplaceChars ), $sString );
00659 }
00660
00661
00662 $aReplaceWhat = array( '&', '"', ''', '<', '>' );
00663 return str_replace( $aReplaceWhat, '', $sString );
00664 }
00665
00673 public function setSeparator( $sSeparator = null )
00674 {
00675 self::$_sSeparator = $sSeparator;
00676 if ( !self::$_sSeparator ) {
00677 self::$_sSeparator = '-';
00678 }
00679 }
00680
00688 public function setPrefix( $sPrefix )
00689 {
00690 if ($sPrefix) {
00691 self::$_sPrefix = $sPrefix;
00692 } else {
00693 self::$_sPrefix = 'oxid';
00694 }
00695 }
00696
00704 public function setIdLength( $iIdlength = null )
00705 {
00706 if ( isset( $iIdlength ) ) {
00707 $this->_iIdLength = $iIdlength;
00708 }
00709 }
00710
00718 public function setReservedWords( $aReservedWords )
00719 {
00720 self::$_aReservedWords = array_merge( self::$_aReservedWords, $aReservedWords );
00721 }
00722
00723
00735 public function markAsExpired( $sId, $iShopId = null, $iExpStat = 1, $iLang = null, $sParams = null )
00736 {
00737 $sWhere = $sId ? "where oxobjectid = '{$sId}'" : '';
00738 $sWhere .= isset( $iShopId ) ? ( $sWhere ? " and oxshopid = '{$iShopId}'" : "where oxshopid = '{$iShopId}'" ) : '';
00739 $sWhere .= $iLang ? ( $sWhere ? " and oxlang = '{$iLang}'" : "where oxlang = '{$iLang}'" ) : '';
00740 $sWhere .= $sParams ? ( $sWhere ? " and {$sParams}" : "where {$sParams}" ) : '';
00741
00742 $sQ = "update oxseo set oxexpired = '{$iExpStat}' $sWhere ";
00743 oxDb::getDb()->execute( $sQ );
00744 }
00745
00759 protected function _getPageUri( $oObject, $sType, $sStdUrl, $sSeoUrl, $sParams, $iLang = null, $blFixed = false )
00760 {
00761 if (!isset($iLang)) {
00762 $iLang = $oObject->getLanguage();
00763 }
00764 $iShopId = $this->getConfig()->getShopId();
00765
00766
00767 if ( ( $sOldSeoUrl = $this->_loadFromDb( $sType, $oObject->getId(), $iLang, $iShopId, $sParams ) ) ) {
00768 if ( $sOldSeoUrl === $sSeoUrl ) {
00769 return $sSeoUrl;
00770 } else {
00771 $oDb = oxDb::getDb();
00772 $this->_copyToHistory( $oDb->quote( $oObject->getId() ), $oDb->quote( $iShopId ), $iLang, $oDb->quote( $sType ) );
00773 }
00774 }
00775
00776 $this->_saveToDb( $sType, $oObject->getId(), $sStdUrl, $sSeoUrl, $iLang, $iShopId, (int) $blFixed, false, false, $sParams );
00777
00778 return $sSeoUrl;
00779 }
00780
00789 protected function _getStaticObjectId( $iShopId, $sStdUrl )
00790 {
00791 return md5( strtolower ( $iShopId . $this->_trimUrl( $sStdUrl ) ) );
00792 }
00793
00803 public function encodeStaticUrls( $aStaticUrl, $iShopId, $iLang )
00804 {
00805 $oDb = oxDb::getDb();
00806 $sValues = '';
00807 $sOldObjectId = null;
00808
00809
00810 $sStdUrl = $this->_trimUrl( trim( $aStaticUrl['oxseo__oxstdurl'] ) );
00811 $sObjectId = $aStaticUrl['oxseo__oxobjectid'];
00812
00813 if ( !$sObjectId || $sObjectId == '-1' ) {
00814 $sObjectId = $this->_getStaticObjectId( $iShopId, $sStdUrl );
00815 } else {
00816
00817 $sOldObjectId = $sObjectId;
00818
00819
00820 if ( $this->_getStaticObjectId( $iShopId, $sStdUrl ) != $sObjectId ) {
00821 $sObjectId = $this->_getStaticObjectId( $iShopId, $sStdUrl );
00822 }
00823 }
00824
00825 foreach ( $aStaticUrl['oxseo__oxseourl'] as $iLang => $sSeoUrl ) {
00826
00827
00828 if ( ( $sSeoUrl = trim( $sSeoUrl ) ) ) {
00829 $sSeoUrl = $this->_prepareTitle( $this->_trimUrl( $sSeoUrl ) );
00830 $sSeoUrl = $this->_processSeoUrl( $sSeoUrl, $sObjectId, $iLang );
00831 }
00832
00833 if ( $sOldObjectId ) {
00834
00835 if ( !$oDb->getOne( "select ('{$sSeoUrl}' like oxseourl) & ('{$sStdUrl}' like oxstdurl) from oxseo where oxobjectid = '{$sOldObjectId}' and oxshopid = '{$iShopId}' and oxlang = '{$iLang}' " ) ) {
00836 $this->_copyToHistory( $oDb->quote( $sOldObjectId ), $oDb->quote( $iShopId ), $iLang, $oDb->quote( 'static' ), $sObjectId );
00837 }
00838 }
00839
00840 if ( !$sSeoUrl || !$sStdUrl ) {
00841 continue;
00842 }
00843
00844 $sIdent = $this->_getSeoIdent( $sSeoUrl );
00845
00846 if ( $sValues ) {
00847 $sValues .= ', ';
00848 }
00849
00850 $sValues .= "( '{$sObjectId}', '{$sIdent}', '{$iShopId}', '{$iLang}', '$sStdUrl', '$sSeoUrl', 'static' )";
00851 }
00852
00853
00854 if ( $sOldObjectId ) {
00855 $oDb->execute( "delete from oxseo where oxobjectid in ( '{$sOldObjectId}', '{$sObjectId}' )" );
00856 }
00857
00858
00859 if ( $sValues ) {
00860
00861 $sQ = "insert into oxseo ( oxobjectid, oxident, oxshopid, oxlang, oxstdurl, oxseourl, oxtype ) values {$sValues} ";
00862 $oDb->execute( $sQ );
00863 }
00864
00865 return $sObjectId;
00866 }
00867
00875 public function copyStaticUrls( $iShopId )
00876 {
00877 $iBaseShopId = $this->getConfig()->getBaseShopId();
00878 if ( $iShopId != $iBaseShopId ) {
00879 foreach (array_keys(oxLang::getInstance()->getLanguageIds()) as $iLang) {
00880 $iLang = (int) $iLang;
00881 $sQ = "insert into oxseo ( oxobjectid, oxident, oxshopid, oxlang, oxstdurl, oxseourl, oxtype )
00882 select MD5( LOWER( CONCAT( '{$iShopId}', oxstdurl ) ) ), MD5( LOWER( oxseourl ) ),
00883 '$iShopId', oxlang, oxstdurl, oxseourl, oxtype from oxseo where oxshopid = '{$iBaseShopId}' and oxtype = 'static' and oxlang='$iLang' ";
00884 oxDb::getDb()->execute( $sQ );
00885 }
00886 }
00887 }
00888
00898 public function getStaticUrl( $sStdUrl, $iLang = null, $iShopId = null )
00899 {
00900 if (!isset($iShopId)) {
00901 $iShopId = $this->getConfig()->getShopId();
00902 }
00903 if (!isset($iLang)) {
00904 $iLang = oxLang::getInstance()->getEditLanguage();
00905 }
00906
00907 $sFullUrl = '';
00908 if ( ( $sSeoUrl = $this->_getStaticUri( $sStdUrl, $iShopId, $iLang ) ) ) {
00909 $sFullUrl = $this->_getFullUrl( $sSeoUrl, $iLang );
00910 }
00911 return $sFullUrl;
00912 }
00913
00931 public function addSeoEntry( $sObjectId, $iShopId, $iLang, $sStdUrl, $sSeoUrl, $sType, $blFixed = 1, $sKeywords = '', $sDescription = '', $sParams = '', $blExclude = false )
00932 {
00933 $sSeoUrl = $this->_processSeoUrl( $this->_prepareTitle( $this->_trimUrl( $sSeoUrl ) ), $sObjectId, $iLang, $blExclude );
00934 $this->_saveToDb( $sType, $sObjectId, $sStdUrl, $sSeoUrl, $iLang, $iShopId, $blFixed, $sKeywords, $sDescription, $sParams );
00935 }
00936
00947 public function deleteSeoEntry( $sObjectId, $iShopId, $iLang, $sType )
00948 {
00949 $sQ = "delete from oxseo where oxobjectid = '{$sObjectId}' and oxshopid = '{$iShopId}' and oxlang = '{$iLang}' and oxtype = '{$sType}' ";
00950 oxDb::getDb()->execute( $sQ );
00951 }
00952
00963 public function getMetaData( $sObjectId, $sMetaType, $iShopId = null, $iLang = null )
00964 {
00965 $iShopId = ( !isset( $iShopId ) ) ? $this->getConfig()->getShopId():$iShopId;
00966 $iLang = ( !isset( $iLang ) ) ? oxLang::getInstance()->getTplLanguage():$iLang;
00967
00968 return oxDb::getDb()->getOne( "select {$sMetaType} from oxseo where oxobjectid = '{$sObjectId}' and oxshopid = '{$iShopId}' and oxlang = '{$iLang}' order by oxparams" );
00969 }
00970
00984 public function getDynamicUrl( $sStdUrl, $sSeoUrl, $iLang )
00985 {
00986 return $this->_getFullUrl( $this->_getDynamicUri( $sStdUrl, $sSeoUrl, $iLang ) );
00987 }
00988
00997 public function fetchSeoUrl( $sStdUrl, $iLanguage = null )
00998 {
00999 $oDb = oxDb::getDb( true );
01000 $sStdUrl = $oDb->quote( $sStdUrl );
01001 $iLanguage = isset( $iLanguage ) ? $iLanguage : oxLang::getInstance()->getBaseLanguage();
01002
01003 $sSeoUrl = false;
01004
01005 $sQ = "select oxseourl, oxlang from oxseo where oxstdurl = $sStdUrl and oxlang = '$iLanguage' limit 1";
01006 $oRs = $oDb->execute( $sQ );
01007 if ( !$oRs->EOF ) {
01008 $sSeoUrl = $oRs->fields['oxseourl'];
01009 }
01010
01011 return $sSeoUrl;
01012 }
01013 }