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
00090 public function resetCache()
00091 {
00092 $this->_aSeoCache = array();
00093 }
00094
00098 public function __construct()
00099 {
00100 $myConfig = $this->getConfig();
00101 if (!self::$_sSeparator) {
00102 $this->setSeparator( $myConfig->getConfigParam( 'sSEOSeparator' ) );
00103 }
00104 if (!self::$_sPrefix) {
00105 $this->setPrefix( $myConfig->getConfigParam( 'sSEOuprefix' ) );
00106 }
00107 $this->setReservedWords( $myConfig->getConfigParam( 'aSEOReservedWords' ) );
00108 }
00109
00121 protected function _copyToHistory( $sId, $iShopId, $iLang, $sType = null, $sNewId = null )
00122 {
00123 $sObjectid = $sNewId?"'$sNewId'":'oxobjectid';
00124 $sType = $sType?"oxtype = {$sType} and":'';
00125
00126
00127 $sSub = "select {$sObjectid}, MD5( LOWER( oxseourl ) ), oxshopid, oxlang, now() from oxseo where {$sType} oxobjectid = {$sId} and oxshopid = {$iShopId} and oxlang = {$iLang} limit 1";
00128 $sQ = "replace oxseohistory ( oxobjectid, oxident, oxshopid, oxlang, oxinsert ) {$sSub}";
00129 oxDb::getDb()->execute( $sQ );
00130 }
00131
00138 protected function _getAddParams()
00139 {
00140
00141 if ( $this->_sAddParams === null ) {
00142 $this->_sAddParams = $this->_getAddParamsFnc( oxConfig::getParameter('currency'), $this->getConfig()->getShopId() );
00143 }
00144 return $this->_sAddParams;
00145 }
00146
00156 protected function _getAddParamsFnc( $iCur, $iActShop )
00157 {
00158
00159 $this->_sAddParams = '';
00160 $sSep = '?';
00161 if ( $iCur ) {
00162 $this->_sAddParams .= $sSep . 'cur=' . $iCur;
00163 $sSep = '&';
00164 }
00165
00166
00167 return $this->_sAddParams;
00168 }
00169
00178 protected function _getDynamicObjectId( $iShopId, $sStdUrl )
00179 {
00180 return $this->_getStaticObjectId( $iShopId, $sStdUrl );
00181 }
00182
00192 protected function _getDynamicUri( $sStdUrl, $sSeoUrl, $iLang )
00193 {
00194 $iShopId = $this->getConfig()->getShopId();
00195
00196 $sStdUrl = $this->_trimUrl( $sStdUrl );
00197 $sObjectId = $this->_getDynamicObjectId( $iShopId, $sStdUrl );
00198 $sSeoUrl = $this->_prepareTitle( $sSeoUrl );
00199
00200
00201 $sOldSeoUrl = $this->_loadFromDb( 'dynamic', $sObjectId, $iLang );
00202 if ( $sOldSeoUrl === $sSeoUrl ) {
00203 $sSeoUrl = $sOldSeoUrl;
00204 } else {
00205
00206 if ( $sOldSeoUrl ) {
00207 $oDb = oxDb::getDb();
00208 $this->_copyToHistory( $oDb->quote( $sObjectId ), $oDb->quote( $iShopId ), $iLang, $oDb->quote( 'dynamic' ) );
00209 }
00210
00211
00212 $sSeoUrl = $this->_getUniqueSeoUrl( $sSeoUrl, null, $sObjectId, $iLang );
00213
00214
00215 $this->_saveToDb( 'dynamic', $sObjectId, $sStdUrl, $sSeoUrl, $iLang, $iShopId );
00216 }
00217
00218 return $sSeoUrl;
00219 }
00220
00229 protected function _getFullUrl( $sSeoUrl, $iLang = null)
00230 {
00231 $sFullUrl = $this->getConfig()->getShopUrl( $iLang ) . $sSeoUrl . $this->_getAddParams();
00232 return $this->getSession()->processUrl( $sFullUrl );
00233 }
00234
00245 protected function _getSeoIdent( $sSeoUrl, $iLang = null )
00246 {
00247 return md5( strtolower( $sSeoUrl ) );
00248 }
00249
00259 protected function _getStaticUri( $sStdUrl, $iShopId, $iLang )
00260 {
00261 $sStdUrl = $this->_trimUrl( $sStdUrl, $iLang );
00262 return $this->_loadFromDb( 'static', $this->_getStaticObjectId( $iShopId, $sStdUrl ), $iLang );
00263 }
00264
00278 protected function _getUniqueSeoUrl( $sSeoUrl, $sConstEnd = null, $sObjectId = null, $iObjectLang = null )
00279 {
00280 $oStr = getStr();
00281 if ($sConstEnd === null) {
00282 $aMatched = array();
00283 if ( preg_match('/\.html?$/i', $sSeoUrl, $aMatched ) ) {
00284 $sConstEnd = $aMatched[0];
00285 } else {
00286 if ($sSeoUrl{$oStr->strlen($sSeoUrl)-1} != '/') {
00287 $sSeoUrl .= '/';
00288 }
00289 $sConstEnd = '/';
00290 }
00291 }
00292
00293
00294 $sAdd = ' ';
00295 if ('/' != self::$_sSeparator) {
00296 $sAdd = self::$_sSeparator . self::$_sPrefix;
00297 } else {
00298 $sAdd = '_' . self::$_sPrefix;
00299 }
00300 $sSeoUrl = preg_replace( "#^(/*)(".implode('|', $this->_getReservedEntryKeys()).")/#i" , "\$1\$2$sAdd/", $sSeoUrl );
00301
00302 $sBaseSeoUrl = $sSeoUrl;
00303 if ( $sConstEnd && $oStr->substr( $sSeoUrl, 0 - $oStr->strlen( $sConstEnd ) ) == $sConstEnd ) {
00304 $sBaseSeoUrl = $oStr->substr( $sSeoUrl, 0, $oStr->strlen( $sSeoUrl ) - $oStr->strlen( $sConstEnd ) );
00305 }
00306
00307 $oDb = oxDb::getDb();
00308 $iShopId = $this->getConfig()->getShopId();
00309 $iCnt = 0;
00310 $sCheckSeoUrl = $this->_trimUrl( $sSeoUrl );
00311 $sQ = "select 1 from oxseo where oxshopid = '{$iShopId}'";
00312
00313
00314 if ( $sObjectId && isset($iObjectLang) ) {
00315 $sQ .= " and not (oxobjectid = '{$sObjectId}' and oxlang = $iObjectLang)";
00316 }
00317
00318 while ( $oDb->getOne( $sQ ." and oxident='".$this->_getSeoIdent( $sCheckSeoUrl )."' " ) ) {
00319 $sAdd = '';
00320 if ( self::$_sPrefix ) {
00321 $sAdd = self::$_sSeparator . self::$_sPrefix;
00322 }
00323 if ( $iCnt ) {
00324 $sAdd .= self::$_sSeparator . $iCnt;
00325 }
00326 ++$iCnt;
00327
00328 $sSeoUrl = $sBaseSeoUrl . $sAdd . $sConstEnd;
00329 $sCheckSeoUrl = $this->_trimUrl( $sSeoUrl );
00330 }
00331 return $sSeoUrl;
00332 }
00333
00349 protected function _loadFromDb( $sType, $sId, $iLang, $iShopId = null, $sParams = null, $blStrictParamsCheck = true)
00350 {
00351 $oDb = oxDb::getDb( true );
00352 if ( $iShopId === null ) {
00353 $iShopId = $this->getConfig()->getShopId();
00354 }
00355
00356 $iShopId = $oDb->quote( $iShopId );
00357 $sId = $oDb->quote( $sId );
00358 $sType = $oDb->quote( $sType );
00359 $iLang = (int) $iLang;
00360
00361 $sQ = "select oxfixed, oxseourl, oxexpired, oxtype from oxseo where oxtype = {$sType}
00362 and oxobjectid = {$sId} and oxshopid = {$iShopId} and oxlang = {$iLang}";
00363
00364 $sParams = $sParams ? $sParams : '';
00365 if ( $sParams && $blStrictParamsCheck ) {
00366 $sQ .= " and oxparams = '{$sParams}'";
00367 } else {
00368 $sQ .= " order by oxparams = '{$sParams}' desc";
00369 }
00370 $sQ .= " limit 1";
00371
00372
00373 $sIdent = md5($sQ);
00374 if ( isset( $this->_aSeoCache[$sIdent] ) ) {
00375 return $this->_aSeoCache[$sIdent];
00376 }
00377
00378 $sSeoUrl = false;
00379 $oRs = $oDb->execute( $sQ );
00380 if ( $oRs && $oRs->recordCount() > 0 && !$oRs->EOF ) {
00381
00382 if ( $oRs->fields['oxexpired'] && ( $oRs->fields['oxtype'] == 'static' || $oRs->fields['oxtype'] == 'dynamic' ) ) {
00383
00384 $this->_copyToHistory( $sId, $iShopId, $iLang );
00385 $oDb->execute( "update oxseo set oxexpired = 0 where oxobjectid = {$sId} and oxlang = '{$iLang}' " );
00386 $sSeoUrl = $oRs->fields['oxseourl'];
00387 } elseif ( !$oRs->fields['oxexpired'] || $oRs->fields['oxfixed'] ) {
00388
00389 $sSeoUrl = $oRs->fields['oxseourl'];
00390 }
00391
00392
00393 $this->_aSeoCache[$sIdent] = $sSeoUrl;
00394 }
00395 return $sSeoUrl;
00396 }
00397
00404 protected function _getReservedEntryKeys()
00405 {
00406 if (!isset(self::$_aReservedEntryKeys) && !is_array(self::$_aReservedEntryKeys)) {
00407 $sDir = getShopBasePath();
00408 self::$_aReservedEntryKeys = array();
00409 foreach (glob("$sDir/*") as $file) {
00410 if (preg_match('/^(.+)\.php[0-9]*$/i', basename($file), $m)) {
00411 self::$_aReservedEntryKeys[] = $m[0];
00412 self::$_aReservedEntryKeys[] = $m[1];
00413 } elseif (is_dir($file)) {
00414 self::$_aReservedEntryKeys[] = basename($file);
00415 }
00416 }
00417 }
00418 return self::$_aReservedEntryKeys;
00419 }
00420
00429 protected function _prepareTitle( $sTitle, $blSkipTruncate = false )
00430 {
00431
00432 $sTitle = $this->encodeString( $sTitle );
00433
00434
00435 $sTitle = strip_tags( $sTitle );
00436 $sSeparator = self::$_sSeparator;
00437 $sPrefix = self::$_sPrefix;
00438
00439 foreach ( self::$_aReservedWords as $sWord ) {
00440
00441 $sTitle = preg_replace( array( "/(\s$sWord)$/i", "/^($sWord\s)/i", "/(\s$sWord\s)/i", "/^($sWord)$/i",
00442 "/(\/$sWord)$/i", "/^($sWord\/)/i", "/(\/$sWord\/)/i"),
00443 " $1{$sSeparator}{$sPrefix}{$sSeparator} ", $sTitle );
00444 }
00445
00446
00447 $sExt = '';
00448 $oStr = getStr();
00449 $aMatched = array();
00450 if ( preg_match( '/\.html?$/i', $sTitle, $aMatched ) ) {
00451 $sExt = $oStr->substr( $sTitle, 0 - $oStr->strlen( $aMatched[0] ) );
00452 $sTitle = $oStr->substr( $sTitle, 0, $oStr->strlen( $sTitle ) - $oStr->strlen( $aMatched[0] ) );
00453 }
00454
00455
00456 if ( !$blSkipTruncate && $oStr->strlen( $sTitle ) > $this->_iIdLength ) {
00457
00458 if ( ( $iFirstSpace = $oStr->strstr( $oStr->substr( $sTitle, $this->_iIdLength ), ' ' ) !== false ) ) {
00459 $sTitle = $oStr->substr( $sTitle, 0, $this->_iIdLength + $iFirstSpace );
00460 }
00461 }
00462
00463
00464 $sRegExp = '/[^A-Za-z0-9'.preg_quote( self::$_sSeparator, '/').'\/]+/';
00465 $sTitle = trim( $oStr->preg_replace( array( "/\W*\/\W*/", $sRegExp ), array( "/", self::$_sSeparator ), $sTitle ), self::$_sSeparator );
00466
00467
00468 if ( !$sTitle ) {
00469 $sTitle = $this->_prepareTitle( self::$_sPrefix );
00470 }
00471
00472
00473 $sTitle .= $sExt;
00474
00475
00476 return $oStr->preg_replace( array( '|//+|', '/' . preg_quote( self::$_sSeparator . self::$_sSeparator, '/' ) .'+/' ),
00477 array( '/', self::$_sSeparator ), $sTitle );
00478 }
00479
00480
00499 protected function _saveToDb( $sType, $sObjectId, $sStdUrl, $sSeoUrl, $iLang, $iShopId = null, $blFixed = null, $sKeywords = false, $sDescription = false, $sParams = null )
00500 {
00501 $oDb = oxDb::getDb( true );
00502 if ( $iShopId === null ) {
00503 $iShopId = $this->getConfig()->getShopId();
00504 }
00505
00506 $iShopId = $oDb->quote( $iShopId );
00507
00508 $sObjectId = $oDb->quote( $sObjectId );
00509 $sType = $oDb->quote( $sType );
00510
00511 $iLang = (int) $iLang;
00512
00513 $sStdUrl = $this->_trimUrl( $sStdUrl );
00514 $sSeoUrl = $this->_trimUrl( $sSeoUrl );
00515
00516 $sIdent = $this->_getSeoIdent( $sSeoUrl );
00517
00518 $sStdUrl = $oDb->quote( $sStdUrl );
00519 $sSeoUrl = $oDb->quote( $sSeoUrl );
00520
00521
00522 $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} ";
00523 $sQ .= $sParams ? " and oxparams = " . $oDb->quote( $sParams ) : '';
00524 $sQ .= ( $sKeywords !== false ) ? " and oxkeywords = " . $oDb->quote( $sKeywords ) . " " : '';
00525 $sQ .= ( $sDescription !== false ) ? " and oxdescription = " . $oDb->quote( $sDescription ) . " " : '';
00526 $sQ .= isset( $blFixed ) ? " and oxfixed = " . ( (int) $blFixed ) . " " : '';
00527 $sQ .= "limit 1";
00528
00529 $oRs = $oDb->execute( $sQ );
00530 if ( $oRs && $oRs->recordCount() > 0 && !$oRs->EOF ) {
00531
00532 if ( $oRs->fields['samestdurl'] && $oRs->fields['sameseourl'] && $oRs->fields['oxexpired'] ) {
00533
00534 return $oDb->execute( "update oxseo set oxexpired = 0 where oxtype = {$sType} and oxobjectid = {$sObjectId} and oxshopid = {$iShopId} and oxlang = {$iLang} limit 1" );
00535 } elseif ( $oRs->fields['oxexpired'] && !$oRs->fields['oxfixed'] ) {
00536
00537 $this->_copyToHistory( $sObjectId, $iShopId, $iLang, $sType );
00538 }
00539 }
00540 $oStr = getStr();
00541 if ( $sKeywords !== false ) {
00542 $sKeywords = $oDb->quote( $oStr->htmlentities( $this->encodeString( strip_tags( $sKeywords ), false ) ) );
00543 }
00544
00545 if ( $sDescription !== false ) {
00546 $sDescription = $oDb->quote( $oStr->htmlentities( strip_tags( $sDescription ) ) );
00547 }
00548
00549
00550 $sParams = $sParams ? $oDb->quote( $sParams ) :'""';
00551 $blFixed = (int) $blFixed;
00552
00553 $sQ = "insert into oxseo
00554 (oxobjectid, oxident, oxshopid, oxlang, oxstdurl, oxseourl, oxtype, oxfixed, oxexpired, oxkeywords, oxdescription, oxparams)
00555 values
00556 ( {$sObjectId}, '$sIdent', {$iShopId}, {$iLang}, {$sStdUrl}, {$sSeoUrl}, {$sType}, '$blFixed', '0',
00557 ".( $sKeywords ? $sKeywords : "''" ).", ".( $sDescription ? $sDescription : "''" ).", $sParams )
00558 on duplicate key update oxident = '$sIdent', oxstdurl = {$sStdUrl}, oxseourl = {$sSeoUrl}, oxfixed = '$blFixed', oxexpired = '0',
00559 oxkeywords = ".( $sKeywords ? $sKeywords : "oxkeywords" ).", oxdescription = ".( $sDescription ? $sDescription : "oxdescription" );
00560
00561 return $oDb->execute( $sQ );
00562 }
00563
00574 protected function _trimUrl( $sUrl, $iLang = null )
00575 {
00576 $sUrl = str_replace( $this->getConfig()->getShopURL( $iLang ), '', $sUrl );
00577 return preg_replace( '/(force_)?sid=[a-z0-9\.]+&?(amp;)?/i', '', $sUrl );
00578 }
00579
00588 public function encodeString( $sString, $blReplaceChars = true )
00589 {
00590
00591 $sString = getStr()->html_entity_decode( $sString );
00592
00593 if ( $blReplaceChars ) {
00594 $aReplaceChars = $this->getConfig()->getConfigParam( 'aSeoReplaceChars' );
00595 $sString = str_replace( array_keys( $aReplaceChars ), array_values( $aReplaceChars ), $sString );
00596 }
00597
00598
00599 $aReplaceWhat = array( '&', '"', ''', '<', '>' );
00600 return str_replace( $aReplaceWhat, '', $sString );
00601 }
00602
00610 public function setSeparator( $sSeparator = null )
00611 {
00612 self::$_sSeparator = $sSeparator;
00613 if ( !self::$_sSeparator ) {
00614 self::$_sSeparator = '-';
00615 }
00616 }
00617
00625 public function setPrefix( $sPrefix )
00626 {
00627 if ($sPrefix) {
00628 self::$_sPrefix = $sPrefix;
00629 } else {
00630 self::$_sPrefix = 'oxid';
00631 }
00632 }
00633
00641 public function setIdLength( $iIdlength = null )
00642 {
00643 if ( isset( $iIdlength ) ) {
00644 $this->_iIdLength = $iIdlength;
00645 }
00646 }
00647
00655 public function setReservedWords( $aReservedWords )
00656 {
00657 self::$_aReservedWords = array_merge( self::$_aReservedWords, $aReservedWords );
00658 }
00659
00660
00672 public function markAsExpired( $sId, $iShopId = null, $iExpStat = 1, $iLang = null, $sParams = null )
00673 {
00674 $sWhere = $sId ? "where oxobjectid = '{$sId}'" : '';
00675 $sWhere .= isset( $iShopId ) ? ( $sWhere ? " and oxshopid = '{$iShopId}'" : "where oxshopid = '{$iShopId}'" ) : '';
00676 $sWhere .= $iLang ? ( $sWhere ? " and oxlang = '{$iLang}'" : "where oxlang = '{$iLang}'" ) : '';
00677 $sWhere .= $sParams ? ( $sWhere ? " and {$sParams}" : "where {$sParams}" ) : '';
00678
00679 $sQ = "update oxseo set oxexpired = '{$iExpStat}' $sWhere ";
00680 oxDb::getDb()->execute( $sQ );
00681 }
00682
00696 protected function _getPageUri( $oObject, $sType, $sStdUrl, $sSeoUrl, $sParams, $iLang = null, $blFixed = false )
00697 {
00698 if (!isset($iLang)) {
00699 $iLang = $oObject->getLanguage();
00700 }
00701 $iShopId = $this->getConfig()->getShopId();
00702
00703
00704 if ( ( $sOldSeoUrl = $this->_loadFromDb( $sType, $oObject->getId(), $iLang, $iShopId, $sParams ) ) ) {
00705 if ( $sOldSeoUrl === $sSeoUrl ) {
00706 return $sSeoUrl;
00707 } else {
00708 $oDb = oxDb::getDb();
00709 $this->_copyToHistory( $oDb->quote( $oObject->getId() ), $oDb->quote( $iShopId ), $iLang, $oDb->quote( $sType ) );
00710 }
00711 }
00712
00713 $this->_saveToDb( $sType, $oObject->getId(), $sStdUrl, $sSeoUrl, $iLang, $iShopId, (int) $blFixed, false, false, $sParams );
00714
00715 return $sSeoUrl;
00716 }
00717
00726 protected function _getStaticObjectId( $iShopId, $sStdUrl )
00727 {
00728 return md5( strtolower ( $iShopId . $sStdUrl ) );
00729 }
00730
00740 public function encodeStaticUrls( $aStaticUrl, $iShopId, $iLang )
00741 {
00742 $oDb = oxDb::getDb();
00743 $sValues = '';
00744 $sOldObjectId = null;
00745
00746
00747 $sStdUrl = $this->_trimUrl( trim( $aStaticUrl['oxseo__oxstdurl'] ) );
00748 $sObjectId = $aStaticUrl['oxseo__oxobjectid'];
00749
00750 if ( !$sObjectId || $sObjectId == '-1' ) {
00751 $sObjectId = $this->_getStaticObjectId( $iShopId, $sStdUrl );
00752 } else {
00753
00754 $sOldObjectId = $sObjectId;
00755
00756
00757 if ( $this->_getStaticObjectId( $iShopId, $sStdUrl ) != $sObjectId ) {
00758 $sObjectId = $this->_getStaticObjectId( $iShopId, $sStdUrl );
00759 }
00760 }
00761
00762 foreach ( $aStaticUrl['oxseo__oxseourl'] as $iLang => $sSeoUrl ) {
00763
00764
00765 if ( ( $sSeoUrl = trim( $sSeoUrl ) ) ) {
00766 $sSeoUrl = $this->_prepareTitle( $this->_trimUrl( $sSeoUrl ) );
00767 $sSeoUrl = $this->_getUniqueSeoUrl( $sSeoUrl, null, $sObjectId, $iLang );
00768 }
00769
00770 if ( $sOldObjectId ) {
00771
00772 if ( !$oDb->getOne( "select ('{$sSeoUrl}' like oxseourl) & ('{$sStdUrl}' like oxstdurl) from oxseo where oxobjectid = '{$sOldObjectId}' and oxshopid = '{$iShopId}' and oxlang = '{$iLang}' " ) ) {
00773 $this->_copyToHistory( $oDb->quote( $sOldObjectId ), $oDb->quote( $iShopId ), $iLang, $oDb->quote( 'static' ), $sObjectId );
00774 }
00775 }
00776
00777 if ( !$sSeoUrl || !$sStdUrl ) {
00778 continue;
00779 }
00780
00781 $sIdent = $this->_getSeoIdent( $sSeoUrl );
00782
00783 if ( $sValues ) {
00784 $sValues .= ', ';
00785 }
00786
00787 $sValues .= "( '{$sObjectId}', '{$sIdent}', '{$iShopId}', '{$iLang}', '$sStdUrl', '$sSeoUrl', 'static' )";
00788 }
00789
00790
00791 if ( $sOldObjectId ) {
00792 $oDb->execute( "delete from oxseo where oxobjectid in ( '{$sOldObjectId}', '{$sObjectId}' )" );
00793 }
00794
00795
00796 if ( $sValues ) {
00797
00798 $sQ = "insert into oxseo ( oxobjectid, oxident, oxshopid, oxlang, oxstdurl, oxseourl, oxtype ) values {$sValues} ";
00799 $oDb->execute( $sQ );
00800 }
00801
00802 return $sObjectId;
00803 }
00804
00812 public function copyStaticUrls( $iShopId )
00813 {
00814 $iBaseShopId = $this->getConfig()->getBaseShopId();
00815 if ( $iShopId != $iBaseShopId ) {
00816 foreach (array_keys(oxLang::getInstance()->getLanguageIds()) as $iLang) {
00817 $iLang = (int) $iLang;
00818 $sQ = "insert into oxseo ( oxobjectid, oxident, oxshopid, oxlang, oxstdurl, oxseourl, oxtype )
00819 select MD5( LOWER( CONCAT( '{$iShopId}', oxstdurl ) ) ), MD5( LOWER( oxseourl ) ),
00820 '$iShopId', oxlang, oxstdurl, oxseourl, oxtype from oxseo where oxshopid = '{$iBaseShopId}' and oxtype = 'static' and oxlang='$iLang' ";
00821 oxDb::getDb()->execute( $sQ );
00822 }
00823 }
00824 }
00825
00835 public function getStaticUrl( $sStdUrl, $iLang = null, $iShopId = null )
00836 {
00837 if (!isset($iShopId)) {
00838 $iShopId = $this->getConfig()->getShopId();
00839 }
00840 if (!isset($iLang)) {
00841 $iLang = oxLang::getInstance()->getEditLanguage();
00842 }
00843
00844 $sFullUrl = '';
00845 if ( ( $sSeoUrl = $this->_getStaticUri( $sStdUrl, $iShopId, $iLang ) ) ) {
00846 $sFullUrl = $this->_getFullUrl( $sSeoUrl, $iLang );
00847 }
00848 return $sFullUrl;
00849 }
00850
00867 public function addSeoEntry( $sObjectId, $iShopId, $iLang, $sStdUrl, $sSeoUrl, $sType, $blFixed = 1, $sKeywords = '', $sDescription = '', $sParams = '' )
00868 {
00869 $sSeoUrl = $this->_getUniqueSeoUrl( $this->_prepareTitle( $this->_trimUrl( $sSeoUrl ) ), null, $sObjectId, $iLang );
00870 $this->_saveToDb( $sType, $sObjectId, $sStdUrl, $sSeoUrl, $iLang, $iShopId, $blFixed, $sKeywords, $sDescription, $sParams );
00871 }
00872
00883 public function deleteSeoEntry( $sObjectId, $iShopId, $iLang, $sType )
00884 {
00885 $sQ = "delete from oxseo where oxobjectid = '{$sObjectId}' and oxshopid = '{$iShopId}' and oxlang = '{$iLang}' and oxtype = '{$sType}' ";
00886 oxDb::getDb()->execute( $sQ );
00887 }
00888
00899 public function getMetaData( $sObjectId, $sMetaType, $iShopId = null, $iLang = null )
00900 {
00901 $iShopId = ( !isset( $iShopId ) ) ? $this->getConfig()->getShopId():$iShopId;
00902 $iLang = ( !isset( $iLang ) ) ? oxLang::getInstance()->getTplLanguage():$iLang;
00903
00904 return oxDb::getDb()->getOne( "select {$sMetaType} from oxseo where oxobjectid = '{$sObjectId}' and oxshopid = '{$iShopId}' and oxlang = '{$iLang}' order by oxparams" );
00905 }
00906
00920 public function getDynamicUrl( $sStdUrl, $sSeoUrl, $iLang )
00921 {
00922 return $this->_getFullUrl( $this->_getDynamicUri( $sStdUrl, $sSeoUrl, $iLang ) );
00923 }
00924
00933 public function fetchSeoUrl( $sStdUrl, $iLanguage = null )
00934 {
00935 $oDb = oxDb::getDb( true );
00936 $sStdUrl = $oDb->quote( $sStdUrl );
00937 $iLanguage = isset( $iLanguage ) ? $iLanguage : oxLang::getInstance()->getBaseLanguage();
00938
00939 $sSeoUrl = false;
00940
00941 $sQ = "select oxseourl, oxlang from oxseo where oxstdurl = $sStdUrl and oxlang = '$iLanguage' limit 1";
00942 $oRs = $oDb->execute( $sQ );
00943 if ( !$oRs->EOF ) {
00944 $sSeoUrl = $oRs->fields['oxseourl'];
00945 }
00946
00947 return $sSeoUrl;
00948 }
00949 }