recode mr urlstack class
Dieser Commit ist enthalten in:
Ursprung
38166a22fe
Commit
e282fbe015
1 geänderte Dateien mit 44 neuen und 83 gelöschten Zeilen
|
@ -1,54 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AMR url stack class
|
* File:
|
||||||
|
* class.modrewriteurlstack.php
|
||||||
*
|
*
|
||||||
* @package plugin
|
* ModRewrite url stack class
|
||||||
* @subpackage Mod Rewrite
|
*
|
||||||
* @version SVN Revision $Rev: 128 $
|
* @category ConLite
|
||||||
* @id $Id: class.modrewriteurlstack.php 128 2019-07-03 11:58:28Z oldperl $:
|
* @package Plugin
|
||||||
* @author Murat Purc <murat@purc.de>
|
* @subpackage ModRewrite
|
||||||
* @copyright four for business AG <www.4fb.de>
|
* @since 2.1.3
|
||||||
* @license http://www.contenido.org/license/LIZENZ.txt
|
* @author Ortwin Pinke <o.pinke@conlite.org>
|
||||||
* @link http://www.4fb.de
|
* @copyright (c) 2022, conlite.org
|
||||||
* @link http://www.contenido.org
|
* @license http://www.gnu.de/documents/gpl.en.html GPL v3 (english version)
|
||||||
|
* @license http://www.gnu.de/documents/gpl.de.html GPL v3 (deutsche Version)
|
||||||
|
* @link http://www.conlite.org ConLite.org
|
||||||
|
*
|
||||||
|
* based on former AMR class by Murat Purc <murat@purc.de> for CONTENIDO 4.8.x
|
||||||
*/
|
*/
|
||||||
if (!defined('CON_FRAMEWORK')) {
|
if (!defined('CON_FRAMEWORK')) {
|
||||||
die('Illegal call');
|
die('Illegal call');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Mod rewrite url stack class. Provides features to collect urls and to get the
|
|
||||||
* pretty path and names of categories/articles at one go.
|
|
||||||
*
|
|
||||||
* Main goal of this class is to collect urls and to get the urlpath and urlname
|
|
||||||
* of the related categories/articles at one go. This will reduce the queries
|
|
||||||
* against the database.
|
|
||||||
* Therefore the full advantage will be taken by rewriting the urls at codeoutput
|
|
||||||
* in front_content.php, where you will be able to collect all urls at once...
|
|
||||||
*
|
|
||||||
* Usage:
|
|
||||||
* <code>
|
|
||||||
* // get the instance
|
|
||||||
* $oMRUrlStack = ModRewriteUrlStack::getInstance();
|
|
||||||
*
|
|
||||||
* // add several urls to fill the stack
|
|
||||||
* $oMRUrlStack->add('front_content.php?idcat=123');
|
|
||||||
* $oMRUrlStack->add('front_content.php?idart=321');
|
|
||||||
* $oMRUrlStack->add('front_content.php?idcatart=213');
|
|
||||||
* $oMRUrlStack->add('front_content.php?idcatlang=213');
|
|
||||||
* $oMRUrlStack->add('front_content.php?idartlang=312');
|
|
||||||
*
|
|
||||||
* // now the first call will get the pretty path and names from database at one go
|
|
||||||
* $aPrettyParts = $oMRUrlStack->getPrettyUrlParts('front_content.php?idcat=123');
|
|
||||||
* echo $aPrettyParts['urlpath']; // something like 'Main-category-name/Category-name/Another-category-name/'
|
|
||||||
* echo $aPrettyParts['urlname']; // something like 'Name-of-an-article'
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* @author Murat Purc <murat@purc.de>
|
|
||||||
* @package plugin
|
|
||||||
* @subpackage Mod Rewrite
|
|
||||||
*/
|
|
||||||
class ModRewriteUrlStack {
|
class ModRewriteUrlStack {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +28,7 @@ class ModRewriteUrlStack {
|
||||||
*
|
*
|
||||||
* @var ModRewriteUrlStack
|
* @var ModRewriteUrlStack
|
||||||
*/
|
*/
|
||||||
private static $_instance;
|
private static $_oInstance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database object
|
* Database object
|
||||||
|
@ -106,10 +78,9 @@ class ModRewriteUrlStack {
|
||||||
* Constructor, sets some properties.
|
* Constructor, sets some properties.
|
||||||
*/
|
*/
|
||||||
private function __construct() {
|
private function __construct() {
|
||||||
global $cfg, $lang;
|
$this->_oDb = cRegistry::getDb();
|
||||||
$this->_oDb = new DB_Contenido();
|
$this->_aTab = cRegistry::getConfigValue('tab');
|
||||||
$this->_aTab = $cfg['tab'];
|
$this->_idLang = cRegistry::getLanguageId();
|
||||||
$this->_idLang = $lang;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,10 +89,10 @@ class ModRewriteUrlStack {
|
||||||
* @return ModRewriteUrlStack
|
* @return ModRewriteUrlStack
|
||||||
*/
|
*/
|
||||||
public static function getInstance() {
|
public static function getInstance() {
|
||||||
if (self::$_instance == null) {
|
if (self::$_oInstance == null) {
|
||||||
self::$_instance = new ModRewriteUrlStack();
|
self::$_oInstance = new ModRewriteUrlStack();
|
||||||
}
|
}
|
||||||
return self::$_instance;
|
return self::$_oInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -238,33 +209,26 @@ class ModRewriteUrlStack {
|
||||||
* @return type
|
* @return type
|
||||||
*/
|
*/
|
||||||
private function _chunkSetPrettyUrlParts($sStackId) {
|
private function _chunkSetPrettyUrlParts($sStackId) {
|
||||||
// collect stack parameter to get urlpath and urlname
|
if (!isset($this->_aStack[$sStackId]) || isset($this->_aStack[$sStackId]['urlpath'])) {
|
||||||
$aStack = array();
|
return;
|
||||||
foreach ($this->_aStack as $stackId => $item) {
|
|
||||||
if (!isset($item['urlpath'])) {
|
|
||||||
// pretty url is to create
|
|
||||||
$aStack[$stackId] = $item;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$aStack = [];
|
||||||
|
$aStack[$sStackId] = $this->_aStack[$sStackId];
|
||||||
|
|
||||||
// now, it's time to compose the where clause of the query
|
// now, it's time to compose the where clause of the query
|
||||||
$sWhere = '';
|
$sWhere = '';
|
||||||
foreach ($aStack as $stackId => $item) {
|
$aP = $this->_aStack[$sStackId]['params'];
|
||||||
|
if ((int) mr_arrayValue($aP, 'idart') > 0) {
|
||||||
if ($stackId == $sStackId) {
|
$sWhere .= '(al.idart = ' . $aP['idart'] . ' AND al.idlang = ' . $aP['lang'] . ') OR ';
|
||||||
$aP = $item['params'];
|
} elseif ((int) mr_arrayValue($aP, 'idartlang') > 0) {
|
||||||
if ((int) mr_arrayValue($aP, 'idart') > 0) {
|
$sWhere .= '(al.idartlang = ' . $aP['idartlang'] . ') OR ';
|
||||||
$sWhere .= '(al.idart = ' . $aP['idart'] . ' AND al.idlang = ' . $aP['lang'] . ') OR ';
|
} elseif ((int) mr_arrayValue($aP, 'idcat') > 0) {
|
||||||
} elseif ((int) mr_arrayValue($aP, 'idartlang') > 0) {
|
$sWhere .= '(cl.idcat = ' . $aP['idcat'] . ' AND cl.idlang = ' . $aP['lang'] . ' AND cl.startidartlang = al.idartlang) OR ';
|
||||||
$sWhere .= '(al.idartlang = ' . $aP['idartlang'] . ') OR ';
|
} elseif ((int) mr_arrayValue($aP, 'idcatart') > 0) {
|
||||||
} elseif ((int) mr_arrayValue($aP, 'idcat') > 0) {
|
$sWhere .= '(ca.idcatart = ' . $aP['idcatart'] . ' AND ca.idart = al.idart AND al.idlang = ' . $aP['lang'] . ') OR ';
|
||||||
$sWhere .= '(cl.idcat = ' . $aP['idcat'] . ' AND cl.idlang = ' . $aP['lang'] . ' AND cl.startidartlang = al.idartlang) OR ';
|
} elseif ((int) mr_arrayValue($aP, 'idcatlang') > 0) {
|
||||||
} elseif ((int) mr_arrayValue($aP, 'idcatart') > 0) {
|
$sWhere .= '(cl.idcatlang = ' . $aP['idcatlang'] . ' AND cl.startidartlang = al.idartlang) OR ';
|
||||||
$sWhere .= '(ca.idcatart = ' . $aP['idcatart'] . ' AND ca.idart = al.idart AND al.idlang = ' . $aP['lang'] . ') OR ';
|
|
||||||
} elseif ((int) mr_arrayValue($aP, 'idcatlang') > 0) {
|
|
||||||
$sWhere .= '(cl.idcatlang = ' . $aP['idcatlang'] . ' AND cl.startidartlang = al.idartlang) OR ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($sWhere == '') {
|
if ($sWhere == '') {
|
||||||
return;
|
return;
|
||||||
|
@ -287,7 +251,7 @@ WHERE
|
||||||
SQL;
|
SQL;
|
||||||
ModRewriteDebugger::add($sql, 'ModRewriteUrlStack->_chunkSetPrettyUrlParts() $sql');
|
ModRewriteDebugger::add($sql, 'ModRewriteUrlStack->_chunkSetPrettyUrlParts() $sql');
|
||||||
|
|
||||||
$aNewStack = array();
|
$aNewStack = [];
|
||||||
|
|
||||||
// create array of fields, which are to reduce step by step from record set below
|
// create array of fields, which are to reduce step by step from record set below
|
||||||
$aFields = array('', 'idart', 'idartlang', 'idcatart', 'idcat');
|
$aFields = array('', 'idart', 'idartlang', 'idcatart', 'idcat');
|
||||||
|
@ -302,18 +266,15 @@ SQL;
|
||||||
// reduce existing field
|
// reduce existing field
|
||||||
unset($aRS[$field]);
|
unset($aRS[$field]);
|
||||||
}
|
}
|
||||||
$rsStackID = $this->_makeStackId($aRS);
|
|
||||||
if (isset($aStack[$rsStackID])) {
|
// matching stack entry found, add urlpath and urlname to the new stack
|
||||||
// matching stack entry found, add urlpath and urlname to the new stack
|
$aNewStack[$sStackId]['urlpath'] = $aRS['urlpath'];
|
||||||
$aNewStack[$rsStackID]['urlpath'] = $aRS['urlpath'];
|
$aNewStack[$sStackId]['urlname'] = $aRS['urlname'];
|
||||||
$aNewStack[$rsStackID]['urlname'] = $aRS['urlname'];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ModRewriteDebugger::add($aNewStack, 'ModRewriteUrlStack->_chunkSetPrettyUrlParts() $aNewStack');
|
ModRewriteDebugger::add($aNewStack, 'ModRewriteUrlStack->_chunkSetPrettyUrlParts() $aNewStack');
|
||||||
ModRewriteDebugger::add($this->_aStack, 'ModRewriteUrlStack->_chunkSetPrettyUrlParts() $this->_aStack');
|
ModRewriteDebugger::add($this->_aStack, 'ModRewriteUrlStack->_chunkSetPrettyUrlParts() $this->_aStack');
|
||||||
|
|
||||||
$this->_aStack = array_merge($this->_aStack, $aNewStack);
|
$this->_aStack = array_merge($this->_aStack, $aNewStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
Laden …
In neuem Issue referenzieren