1
0
Fork 0
Dieser Commit ist enthalten in:
Ortwin Pinke 2019-11-04 16:57:28 +01:00 committet von GitHub
Ursprung d41e3b5158
Commit 16ad56ae48
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
41 geänderte Dateien mit 8754 neuen und 0 gelöschten Zeilen

1071
classes/class.modrewrite.php Normale Datei

Datei-Diff unterdrückt, da er zu groß ist Diff laden

Datei anzeigen

@ -0,0 +1,87 @@
<?php
/**
* AMR base Mod Rewrite class
*
* @package plugin
* @subpackage Mod Rewrite
* @version SVN Revision $Rev: 128 $
* @id $Id: class.modrewritebase.php 128 2019-07-03 11:58:28Z oldperl $:
* @author Murat Purc <murat@purc.de>
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
/**
* Abstract base mod rewrite class.
*
* Provides some common features such as common debugging, globals/configuration
* access for childs.
*
* @author Murat Purc <murat@purc.de>
* @package plugin
* @subpackage Mod Rewrite
*/
abstract class ModRewriteBase {
/**
* Initialization, is to call at least once by an child.
* @deprecated
*/
protected static function initialize($clientId) {
}
/**
* Returns enabled state of mod rewrite plugin
*
* @return bool
*/
public static function isEnabled() {
return (self::getConfig('use', 0) == 1) ? true : false;
}
/**
* Sets the enabled state of mod rewrite plugin
*
* @param bool $bEnabled
*/
public static function setEnabled($bEnabled) {
self::setConfig('use', (bool) $bEnabled);
}
/**
* Returns configuration of mod rewrite, content of gobal $cfg['mod_rewrite']
*
* @param string $key Name of configuration key
* @param mixed $default Default value to return as a fallback
* @return mixed Desired value mr configuration, either the full configuration
* or one of the desired subpart
*/
public static function getConfig($key = null, $default = null) {
global $cfg;
if ($key == null) {
return $cfg['mod_rewrite'];
} elseif ((string) $key !== '') {
return (isset($cfg['mod_rewrite'][$key])) ? $cfg['mod_rewrite'][$key] : $default;
} else {
return $default;
}
}
/**
* Sets the configuration of mod rewrite, content of gobal $cfg['mod_rewrite']
*
* @param string $key Name of configuration key
* @param mixed $value The value to set
*/
public static function setConfig($key, $value) {
global $cfg;
$cfg['mod_rewrite'][$key] = $value;
}
}

Datei anzeigen

@ -0,0 +1,678 @@
<?php
/**
* AMR controller class
*
* @package plugin
* @subpackage Mod Rewrite
* @version SVN Revision $Rev: 128 $
* @id $Id: class.modrewritecontroller.php 128 2019-07-03 11:58:28Z oldperl $:
* @author Murat Purc <murat@purc.de>
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
/**
* Mod Rewrite controller class. Extracts url parts and sets some necessary globals like:
* - $idart
* - $idcat
* - $client
* - $changeclient
* - $lang
* - $changelang
*
* @author Murat Purc <murat@purc.de>
* @package plugin
* @subpackage Mod Rewrite
*/
class ModRewriteController extends ModRewriteBase {
// Error constants
const ERROR_CLIENT = 1;
const ERROR_LANGUAGE = 2;
const ERROR_CATEGORY = 3;
const ERROR_ARTICLE = 4;
const ERROR_POST_VALIDATION = 5;
const FRONT_CONTENT = 'front_content.php';
/**
* Extracted request uri path parts by path separator '/'
*
* @var array
*/
private $_aParts;
/**
* Extracted article name from request uri
*
* @var string
*/
private $_sArtName;
/**
* Remaining path for path resolver (see $GLOBALS['path'])
*
* @var string
*/
private $_sPath;
/**
* Incomming URL
*
* @var string
*/
private $_sIncommingUrl;
/**
* Resolved URL
*
* @var string
*/
private $_sResolvedUrl;
/**
* Client id used by this class
*
* @var int
*/
private $_iClientMR;
/**
* Language id used by this class
*
* @var int
*/
private $_iLangMR;
/**
* Flag about occured errors
*
* @var bool
*/
private $_bError = false;
/**
* One of ERROR_* constants or 0
*
* @var int
*/
private $_iError = 0;
/**
* Flag about found routing definition
*
* @var bool
*/
private $_bRoutingFound = false;
/**
* Constructor, sets several properties.
*
* @param string $incommingUrl Incomming URL
*/
public function __construct($incommingUrl) {
// CON-1266 make incomming URL lowercase if option "URLS to
// lowercase" is set
if (1 == $this->getConfig('use_lowercase_uri')) {
$incommingUrl = strtolower($incommingUrl);
}
$this->_sIncommingUrl = $incommingUrl;
$this->_aParts = array();
$this->_sArtName = '';
}
/**
* Getter for overwritten client id (see $GLOBALS['client'])
*
* @return int Client id
*/
public function getClient() {
return $GLOBALS['client'];
}
/**
* Getter for overwritten change client id (see $GLOBALS['changeclient'])
*
* @return int Change client id
*/
public function getChangeClient() {
return $GLOBALS['changeclient'];
}
/**
* Getter for article id (see $GLOBALS['idart'])
*
* @return int Article id
*/
public function getIdArt() {
return $GLOBALS['idart'];
}
/**
* Getter for category id (see $GLOBALS['idcat'])
*
* @return int Category id
*/
public function getIdCat() {
return $GLOBALS['idcat'];
}
/**
* Getter for language id (see $GLOBALS['lang'])
*
* @return int Language id
*/
public function getLang() {
return $GLOBALS['lang'];
}
/**
* Getter for change language id (see $GLOBALS['changelang'])
*
* @return int Change language id
*/
public function getChangeLang() {
return $GLOBALS['changelang'];
}
/**
* Getter for path (see $GLOBALS['path'])
*
* @return string Path, used by path resolver
*/
public function getPath() {
return $this->_sPath;
}
/**
* Getter for resolved url
*
* @return string Resolved url
*/
public function getResolvedUrl() {
return $this->_sResolvedUrl;
}
/**
* Returns a flag about found routing definition
*
* return bool Flag about found routing
*/
public function getRoutingFoundState() {
return $this->_bRoutingFound;
}
/**
* Getter for occured error state
*
* @return bool Flag for occured error
*/
public function errorOccured() {
return $this->_bError;
}
/**
* Getter for occured error state
*
* @return int Numeric error code
*/
public function getError() {
return $this->_iError;
}
/**
* Main function to call for mod rewrite related preprocessing jobs.
*
* Executes some private functions to extract request URI and to set needed membervariables
* (client, language, article id, category id, etc.)
*/
public function execute() {
if (parent::isEnabled() == false) {
return;
}
$this->_extractRequestUri();
$this->_initializeClientId();
$this->_setClientId();
mr_loadConfiguration($this->_iClientMR);
$this->_setLanguageId();
// second call after setting client and language
$this->_extractRequestUri(true);
$this->_setPathresolverSetting();
$this->_setIdart();
ModRewriteDebugger::add($this->_aParts, 'ModRewriteController::execute() _setIdart');
$this->_postValidation();
}
/**
* Extracts request URI and sets member variables $this->_sArtName and $this->_aParts
*
* @param bool $secondCall Flag about second call of this function, is needed
* to re extract url if a routing definition was found
*/
private function _extractRequestUri($secondCall = false) {
global $client;
// get REQUEST_URI
$requestUri = $_SERVER['REQUEST_URI'];
// CON-1266 make request URL lowercase if option "URLS to
// lowercase" is set
if (1 == $this->getConfig('use_lowercase_uri')) {
$requestUri = strtolower($requestUri);
}
// check for defined rootdir
if (parent::getConfig('rootdir') !== '/' && strpos($requestUri, $this->_sIncommingUrl) === 0) {
$this->_sIncommingUrl = str_replace(parent::getConfig('rootdir'), '/', $this->_sIncommingUrl);
}
$aUrlComponents = $this->_parseUrl($this->_sIncommingUrl);
if (isset($aUrlComponents['path'])) {
if (parent::getConfig('rootdir') !== '/' && strpos($aUrlComponents['path'], parent::getConfig('rootdir')) === 0) {
$aUrlComponents['path'] = str_replace(parent::getConfig('rootdir'), '/', $aUrlComponents['path']);
}
if ($secondCall == true) {
// @todo: implement real redirect of old front_content.php style urls
// check for routing definition
$routings = parent::getConfig('routing');
if (is_array($routings) && isset($routings[$aUrlComponents['path']])) {
$aUrlComponents['path'] = $routings[$aUrlComponents['path']];
if (strpos($aUrlComponents['path'], self::FRONT_CONTENT) !== false) {
// routing destination contains front_content.php
$this->_bRoutingFound = true;
// set client language, if not set before
mr_setClientLanguageId($client);
//rebuild URL
$url = mr_buildNewUrl($aUrlComponents['path']);
$aUrlComponents = $this->_parseUrl($url);
// add query parameter to superglobal _GET
if (isset($aUrlComponents['query'])) {
$vars = null;
parse_str($aUrlComponents['query'], $vars);
$_GET = array_merge($_GET, $vars);
}
$this->_aParts = array();
}
} else {
return;
}
}
$aPaths = explode('/', $aUrlComponents['path']);
foreach ($aPaths as $p => $item) {
if (!empty($item)) {
// pathinfo would also work
$arr = explode('.', $item);
$count = count($arr);
if ($count > 0 && '.' . strtolower($arr[$count - 1]) == parent::getConfig('file_extension')) {
array_pop($arr);
$this->_sArtName = trim(implode('.', $arr));
} else {
$this->_aParts[] = $item;
}
}
}
if ($secondCall == true) {
// reprocess extracting client and language
$this->_setClientId();
mr_loadConfiguration($this->_iClientMR);
$this->_setLanguageId();
}
}
ModRewriteDebugger::add($this->_aParts, 'ModRewriteController::_extractRequestUri() $this->_aParts');
// loop parts array and remove existing 'front_content.php'
if ($this->_hasPartArrayItems()) {
foreach ($this->_aParts as $p => $item) {
if ($item == self::FRONT_CONTENT) {
unset($this->_aParts[$p]);
}
}
}
}
/**
* Tries to initialize the client id.
* This is required to load the proper plugin configuration for current client.
*/
private function _initializeClientId() {
global $client, $changeclient, $load_client;
$iClient = (isset($client) && (int) $client > 0) ? $client : 0;
$iChangeClient = (isset($changeclient) && (int) $changeclient > 0) ? $changeclient : 0;
$iLoadClient = (isset($load_client) && (int) $load_client > 0) ? $load_client : 0;
$this->_iClientMR = 0;
if ($iClient > 0 && $iChangeClient == 0) {
$this->_iClientMR = $iClient;
} elseif ($iChangeClient > 0) {
$this->_iClientMR = $iChangeClient;
} else {
$this->_iClientMR = $iLoadClient;
}
if ((int) $this->_iClientMR > 0) {
// set global client variable
$client = (int) $this->_iClientMR;
}
}
/**
* Tries to initialize the language id.
*/
private function _initializeLanguageId() {
global $lang, $changelang, $load_lang;
$iLang = (isset($lang) && (int) $lang > 0) ? $lang : 0;
$iChangeLang = (isset($changelang) && (int) $changelang > 0) ? $changelang : 0;
$iLoadLang = (isset($load_lang) && (int) $load_lang > 0) ? $load_lang : 0;
$this->_iLangMR = 0;
if ($iLang > 0 && $iChangeLang == 0) {
$this->_iLangMR = $iLang;
} elseif ($iChangeLang > 0) {
$this->_iLangMR = $iChangeLang;
} else {
$this->_iLangMR = $iLoadLang;
}
if ((int) $this->_iLangMR > 0) {
// set global lang variable
$lang = (int) $this->_iLangMR;
}
}
/**
* Detects client id from given url
*/
private function _setClientId() {
global $client;
if ($this->_bError) {
return;
} elseif ($this->_isRootRequest()) {
// request to root
return;
} elseif (parent::getConfig('use_client') !== 1) {
return;
}
if (parent::getConfig('use_client_name') == 1) {
$detectedClientId = (int) ModRewrite::getClientId(array_shift($this->_aParts));
} else {
$detectedClientId = (int) array_shift($this->_aParts);
if ($detectedClientId > 0 && !ModRewrite::languageIdExists($detectedClientId)) {
$detectedClientId = 0;
}
}
if ($detectedClientId > 0) {
// overwrite existing client variables
$this->_iClientMR = $detectedClientId;
$client = $detectedClientId;
} else {
$this->_setError(self::ERROR_CLIENT);
}
}
/**
* Sets language id
*/
private function _setLanguageId() {
global $lang;
if ($this->_bError) {
return;
} elseif ($this->_isRootRequest()) {
// request to root
return;
} elseif (parent::getConfig('use_language') !== 1) {
return;
}
if (parent::getConfig('use_language_name') == 1) {
// thanks to Nicolas Dickinson for multi Client/Language BugFix
$languageName = array_shift($this->_aParts);
$detectedLanguageId = (int) ModRewrite::getLanguageId($languageName, $this->_iClientMR);
} else {
$detectedLanguageId = (int) array_shift($this->_aParts);
if ($detectedLanguageId > 0 && !ModRewrite::clientIdExists($detectedLanguageId)) {
$detectedLanguageId = 0;
}
}
if ($detectedLanguageId > 0) {
// overwrite existing language variables
$this->_iLangMR = $detectedLanguageId;
$lang = $detectedLanguageId;
} else {
$this->_setError(self::ERROR_LANGUAGE);
}
}
/**
* Sets path resolver and category id
*/
private function _setPathresolverSetting() {
global $client, $lang, $load_lang, $idcat;
if ($this->_bError) {
return;
} elseif (!$this->_hasPartArrayItems()) {
return;
}
$this->_sPath = '/' . implode('/', $this->_aParts) . '/';
if (!isset($lang) || (int) $lang <= 0) {
if ((int) $load_lang > 0) {
// load_client is set in frontend/config.php
$lang = (int) $load_lang;
} else {
// get client id from table
cInclude('classes', 'contenido/class.clientslang.php');
$clCol = new cApiClientLanguageCollection();
$clCol->setWhere('idclient', $client);
$clCol->query();
if ($clItem = $clCol->next()) {
$lang = $clItem->get('idlang');
}
}
}
$idcat = (int) ModRewrite::getCatIdByUrlPath($this->_sPath);
if ($idcat == 0) {
// category couldn't resolved
$this->_setError(self::ERROR_CATEGORY);
$idcat = null;
} else {
// unset $this->_sPath if $idcat could set, otherwhise it would be resolved again.
unset($this->_sPath);
}
ModRewriteDebugger::add($idcat, 'ModRewriteController->_setPathresolverSetting $idcat');
ModRewriteDebugger::add($this->_sPath, 'ModRewriteController->_setPathresolverSetting $this->_sPath');
}
/**
* Sets article id
*/
private function _setIdart() {
global $idcat, $idart, $lang;
if ($this->_bError) {
return;
} else if ($this->_isRootRequest()) {
return;
}
$iIdCat = (isset($idcat) && (int) $idcat > 0) ? $idcat : 0;
$iIdArt = (isset($idart) && (int) $idart > 0) ? $idart : 0;
$detectedIdart = 0;
$defaultStartArtName = parent::getConfig('default_startart_name');
$currArtName = $this->_sArtName;
// startarticle name in url
if (parent::getConfig('add_startart_name_to_url') && !empty($currArtName)) {
if ($currArtName == $defaultStartArtName) {
// stored articlename is the default one, remove it ModRewrite::getArtIdByWebsafeName()
// will find the real article name
$currArtName = '';
}
}
// Last check, before detecting article id
if ($iIdCat == 0 && $iIdArt == 0 && empty($currArtName)) {
// no idcat, idart and article name
// must be a request to root or with language name and/or client name part!
return;
}
if ($iIdCat > 0 && $iIdArt == 0 && !empty($currArtName)) {
// existing idcat with no idart and with article name
$detectedIdart = (int) ModRewrite::getArtIdByWebsafeName($currArtName, $iIdCat, $lang);
} elseif ($iIdCat > 0 && $iIdArt == 0 && empty($currArtName)) {
if (parent::getConfig('add_startart_name_to_url') && ($currArtName == '' || $defaultStartArtName == '' || $defaultStartArtName == $this->_sArtName)) {
// existing idcat without idart and without article name or with default start article name
cInclude('classes', 'class.article.php');
$artColl = new ArticleCollection(array('idcat' => $idcat, 'start' => 1));
if ($artItem = $artColl->startArticle()) {
$detectedIdart = (int) $artItem->get('idart');
}
}
} elseif ($iIdCat == 0 && $iIdArt == 0 && !empty($currArtName)) {
// no idcat and idart but article name
$detectedIdart = (int) ModRewrite::getArtIdByWebsafeName($currArtName, $iIdCat, $lang);
}
if ($detectedIdart > 0) {
$idart = $detectedIdart;
} elseif (!empty($currArtName)) {
$this->_setError(self::ERROR_ARTICLE);
}
ModRewriteDebugger::add($detectedIdart, 'ModRewriteController->_setIdart $detectedIdart');
}
/**
* Does post validation of the extracted data.
*
* One main goal of this function is to prevent duplicated content, which could happen, if
* the configuration 'startfromroot' is activated.
*/
private function _postValidation() {
global $idcat, $idart, $client;
if ($this->_bError || $this->_bRoutingFound || !$this->_hasPartArrayItems()) {
return;
}
if (parent::getConfig('startfromroot') == 1 && parent::getConfig('prevent_duplicated_content') == 1) {
// prevention of duplicated content if '/firstcat/' is directly requested!
$idcat = (isset($idcat) && (int) $idcat > 0) ? $idcat : null;
$idart = (isset($idart) && (int) $idart > 0) ? $idart : null;
// compose new parameter
$param = '';
if ($idcat) {
$param .= 'idcat=' . (int) $idcat;
}
if ($idart) {
$param .= ($param !== '') ? '&idart=' . (int) $idart : 'idart=' . (int) $idart;
}
if ($param == '') {
return;
}
// set client language, if not set before
mr_setClientLanguageId($client);
//rebuild url
$url = mr_buildNewUrl(self::FRONT_CONTENT . '?' . $param);
$aUrlComponents = @parse_url($this->_sIncommingUrl);
$incommingUrl = (isset($aUrlComponents['path'])) ? $aUrlComponents['path'] : '';
ModRewriteDebugger::add($url, 'ModRewriteController->_postValidation validate url');
ModRewriteDebugger::add($incommingUrl, 'ModRewriteController->_postValidation incommingUrl');
// now the new generated uri should be identical with the request uri
if ($incommingUrl !== $url) {
$this->_setError(self::ERROR_POST_VALIDATION);
$idcat = null;
}
}
}
/**
* Parses the url using defined separators
*
* @param string $url Incoming url
* @return string Parsed url
*/
private function _parseUrl($url) {
$this->_sResolvedUrl = $url;
$oMrUrlUtil = ModRewriteUrlUtil::getInstance();
$url = $oMrUrlUtil->toContenidoUrl($url);
return @parse_url($url);
}
/**
* Returns state of parts property.
*
* @return bool True if $this->_aParts propery contains items
*/
private function _hasPartArrayItems() {
return (!empty($this->_aParts));
}
/**
* Checks if current request was a root request.
*
* @return bool
*/
private function _isRootRequest() {
return ($this->_sIncommingUrl == '/' || $this->_sIncommingUrl == '');
}
/**
* Sets error code and error flag (everything greater than 0 is an error)
* @param int $errCode
*/
private function _setError($errCode) {
$this->_iError = (int) $errCode;
$this->_bError = ((int) $errCode > 0);
}
}

Datei anzeigen

@ -0,0 +1,88 @@
<?php
/**
* AMR debugger class
*
* @package plugin
* @subpackage Mod Rewrite
* @version SVN Revision $Rev: 128 $
* @id $Id: class.modrewritedebugger.php 128 2019-07-03 11:58:28Z oldperl $:
* @author Murat Purc <murat@purc.de>
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
/**
* Mod rewrite debugger class.
*
* @author Murat Purc <murat@purc.de>
* @package plugin
* @subpackage Mod Rewrite
*/
class ModRewriteDebugger {
/**
* Flag to enable debugger
* @var bool
*/
protected static $_bEnabled = false;
/**
* Enable debugger setter.
* @param bool $bEnabled
*/
public static function setEnabled($bEnabled) {
self::$_bEnabled = (bool) $bEnabled;
}
/**
* Adds variable to debugger.
* Wrapper for <code>DebuggerFactory::getDebugger('visible_adv')</code>.
*
* @param mixed $mVar The variable to dump
* @param string $sLabel Describtion for passed $mVar
*/
public static function add($mVar, $sLabel = '') {
if (!self::$_bEnabled) {
return;
}
DebuggerFactory::getDebugger('visible_adv')->add($mVar, $sLabel);
}
/**
* Returns output of all added variables to debug.
* @return string
*/
public static function getAll() {
if (!self::$_bEnabled) {
return '';
}
ob_start();
DebuggerFactory::getDebugger('visible_adv')->showAll();
$output = ob_get_contents();
ob_end_clean();
return $output;
}
/**
* Logs variable to debugger.
* Wrapper for <code>cDebug::getDebugger(cDebug::DEBUGGER_FILE)</code>.
*
* @param mixed $mVar The variable to log the contents
* @param string $sLabel Describtion for passed $mVar
*/
public static function log($mVar, $sLabel = '') {
if (!self::$_bEnabled) {
return;
}
DebuggerFactory::getDebugger('file')->show($mVar, $sLabel);
}
}

Datei anzeigen

@ -0,0 +1,300 @@
<?php
/**
* AMR test class
*
* @package plugin
* @subpackage Mod Rewrite
* @version SVN Revision $Rev: 128 $
* @id $Id: class.modrewritetest.php 128 2019-07-03 11:58:28Z oldperl $:
* @author Murat Purc <murat@purc.de>
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
/**
* Mod rewrite test class.
*
* @author Murat Purc <murat@purc.de>
* @package plugin
* @subpackage Mod Rewrite
*/
class ModRewriteTest {
/**
* Global $cfg array
* @var array
*/
protected $_aCfg;
/**
* Global $cfg['tab'] array
* @var array
*/
protected $_aCfgTab;
/**
* Max items to process
* @var int
*/
protected $_iMaxItems;
/**
* Actual resolved url
* @var string
*/
protected $_sResolvedUrl;
/**
* Routing found flag
* @var bool
*/
protected $_bRoutingFound = false;
/**
* Constuctor
* @param int $maxItems Max items (urls to articles/categories) to process
*/
public function __construct($maxItems) {
global $cfg;
$this->_aCfg = & $cfg;
$this->_aCfgTab = & $cfg['tab'];
$this->_iMaxItems = $maxItems;
}
/**
* Returns resolved URL
*
* @return bool Resolved URL
*/
public function getResolvedUrl() {
return $this->_sResolvedUrl;
}
/**
* Returns flagz about found routing
*
* @return bool
*/
public function getRoutingFoundState() {
return $this->_bRoutingFound;
}
/**
* Fetchs full structure of the installation (categories and articles) and returns it back.
*
* @param int $idclient Client id
* @param int $idlang Language id
* @return array Full structure as follows
* <code>
* $arr[idcat] = Category dataset
* $arr[idcat]['articles'][idart] = Article dataset
* </code>
*/
public function fetchFullStructure($idclient = null, $idlang = null) {
global $client, $lang;
$db = new DB_Contenido();
$db2 = new DB_Contenido();
if (!$idclient || (int) $idclient == 0) {
$idclient = $client;
}
if (!$idlang || (int) $idlang == 0) {
$idlang = $lang;
}
$aTab = $this->_aCfgTab;
$aStruct = array();
$sql = "SELECT
*
FROM
" . $aTab['cat_tree'] . " AS a,
" . $aTab['cat_lang'] . " AS b,
" . $aTab['cat'] . " AS c
WHERE
a.idcat = b.idcat AND
c.idcat = a.idcat AND
c.idclient = '" . $idclient . "' AND
b.idlang = '" . $idlang . "'
ORDER BY
a.idtree";
$db->query($sql);
$counter = 0;
while ($db->next_record()) {
if (++$counter == $this->_iMaxItems) {
break; // break this loop
}
$idcat = $db->f('idcat');
$aStruct[$idcat] = $db->Record;
$aStruct[$idcat]['articles'] = array();
$sql2 = "SELECT
*
FROM
" . $aTab['cat_art'] . " AS a,
" . $aTab['art'] . " AS b,
" . $aTab['art_lang'] . " AS c
WHERE
a.idcat = '" . $idcat . "' AND
b.idart = a.idart AND
c.idart = a.idart AND
c.idlang = '" . $idlang . "' AND
b.idclient = '" . $idclient . "'
ORDER BY
c.title ASC";
$db2->query($sql2);
while ($db2->next_record()) {
$idart = $db2->f('idart');
$aStruct[$idcat]['articles'][$idart] = $db2->Record;
if (++$counter == $this->_iMaxItems) {
break 2; // break this and also superior loop
}
}
}
return $aStruct;
}
/**
* Creates an URL using passed data.
*
* The result is used to generate seo urls...
*
* @param array $arr Assoziative array with some data as follows:
* <code>
* $arr['idcat']
* $arr['idart']
* $arr['idcatart']
* $arr['idartlang']
* </code>
* @param string $type Either 'c' or 'a' (category or article). If set to
* 'c' only the parameter idcat will be added to the URL
*/
public function composeURL($arr, $type) {
$type = ($type == 'a') ? 'a' : 'c';
$param = array();
if ($type == 'c') {
$param[] = 'idcat=' . $arr['idcat'];
} else {
if (mr_getRequest('idart')) {
$param[] = 'idart=' . $arr['idart'];
}
if (mr_getRequest('idcat')) {
$param[] = 'idcat=' . $arr['idcat'];
}
if (mr_getRequest('idcatart')) {
$param[] = 'idcatart=' . $arr['idcatart'];
}
if (mr_getRequest('idartlang')) {
$param[] = 'idartlang=' . $arr['idartlang'];
}
}
$param[] = 'foo=bar';
return 'front_content.php?' . implode('&amp;', $param);
}
/**
* Resolves variables of an page (idcat, idart, idclient, idlang, etc.) by
* processing passed url using ModRewriteController
*
* @param string $url Url to resolve
* @return array Assoziative array with resolved data
*/
public function resolveUrl($url) {
// some globals to reset
$aGlobs = array(
'mr_preprocessedPageError', 'idart', 'idcat'
);
foreach ($aGlobs as $p => $k) {
if (isset($GLOBALS[$k])) {
unset($GLOBALS[$k]);
}
}
$aReturn = array();
// create an mod rewrite controller instance and execute processing
$oMRController = new ModRewriteController($url);
$oMRController->execute();
if ($oMRController->errorOccured()) {
// an error occured (idcat and or idart couldn't catched by controller)
$aReturn['mr_preprocessedPageError'] = 1;
$aReturn['error'] = $oMRController->getError();
$this->_sResolvedUrl = '';
$this->_bRoutingFound = false;
} else {
// set some global variables
$this->_sResolvedUrl = $oMRController->getResolvedUrl();
$this->_bRoutingFound = $oMRController->getRoutingFoundState();
if ($oMRController->getClient()) {
$aReturn['client'] = $oMRController->getClient();
}
if ($oMRController->getChangeClient()) {
$aReturn['changeclient'] = $oMRController->getChangeClient();
}
if ($oMRController->getLang()) {
$aReturn['lang'] = $oMRController->getLang();
}
if ($oMRController->getChangeLang()) {
$aReturn['changelang'] = $oMRController->getChangeLang();
}
if ($oMRController->getIdArt()) {
$aReturn['idart'] = $oMRController->getIdArt();
}
if ($oMRController->getIdCat()) {
$aReturn['idcat'] = $oMRController->getIdCat();
}
if ($oMRController->getPath()) {
$aReturn['path'] = $oMRController->getPath();
}
}
return $aReturn;
}
/**
* Creates a readable string from passed resolved data array.
*
* @param array Assoziative array with resolved data
* @return string Readable resolved data
*/
public function getReadableResolvedData(array $data) {
// compose resolved string
$ret = '';
foreach ($data as $k => $v) {
$ret .= $k . '=' . $v . '; ';
}
$ret = substr($ret, 0, strlen($ret) - 2);
return $ret;
}
}

Datei anzeigen

@ -0,0 +1,314 @@
<?php
/**
* AMR url stack class
*
* @package plugin
* @subpackage Mod Rewrite
* @version SVN Revision $Rev: 128 $
* @id $Id: class.modrewriteurlstack.php 128 2019-07-03 11:58:28Z oldperl $:
* @author Murat Purc <murat@purc.de>
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
*/
if (!defined('CON_FRAMEWORK')) {
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 {
/**
* Self instance
*
* @var ModRewriteUrlStack
*/
private static $_instance;
/**
* Database object
*
* @var DB_Contenido
*/
private $_oDb;
/**
* Array for urls
*
* @var array
*/
private $_aUrls = array();
/**
* Url stack array
*
* @var array
*/
private $_aStack = array();
/**
* CONTENIDO related parameter array
*
* @var array
*/
private $_aConParams = array(
'idcat' => 1, 'idart' => 1, 'lang' => 1, 'idcatlang' => 1, 'idcatart' => 1, 'idartlang' => 1
);
/**
* Database tables array
*
* @var array
*/
private $_aTab;
/**
* Language id
*
* @var int
*/
private $_idLang;
/**
* Constructor, sets some properties.
*/
private function __construct() {
global $cfg, $lang;
$this->_oDb = new DB_Contenido();
$this->_aTab = $cfg['tab'];
$this->_idLang = $lang;
}
/**
* Returns a instance of ModRewriteUrlStack (singleton implementation)
*
* @return ModRewriteUrlStack
*/
public static function getInstance() {
if (self::$_instance == null) {
self::$_instance = new ModRewriteUrlStack();
}
return self::$_instance;
}
/**
* Adds an url to the stack
*
* @param string Url, like front_content.php?idcat=123...
*/
public function add($url) {
$url = ModRewrite::urlPreClean($url);
if (isset($this->_aUrls[$url])) {
return;
}
$aUrl = $this->_extractUrl($url);
// cleanup parameter
foreach ($aUrl['params'] as $p => $v) {
if (!isset($this->_aConParams[$p])) {
unset($aUrl['params'][$p]);
} else {
$aUrl['params'][$p] = (int) $v;
}
}
// add language id, if not available
if ((int) mr_arrayValue($aUrl['params'], 'lang') == 0) {
$aUrl['params']['lang'] = $this->_idLang;
}
$sStackId = $this->_makeStackId($aUrl['params']);
$this->_aUrls[$url] = $sStackId;
$this->_aStack[$sStackId] = array('params' => $aUrl['params']);
}
/**
* Returns the pretty urlparts (only category path an article name) of the
* desired url.
*
* @param string Url, like front_content.php?idcat=123...
* @return array Assoziative array like
* <code>
* $arr['urlpath']
* $arr['urlname']
* </code>
*/
public function getPrettyUrlParts($url) {
$url = ModRewrite::urlPreClean($url);
if (!isset($this->_aUrls[$url])) {
$this->add($url);
}
$sStackId = $this->_aUrls[$url];
if (!isset($this->_aStack[$sStackId]['urlpath'])) {
$this->_chunkSetPrettyUrlParts();
}
$aPretty = array(
'urlpath' => $this->_aStack[$sStackId]['urlpath'],
'urlname' => $this->_aStack[$sStackId]['urlname']
);
return $aPretty;
}
/**
* Extracts passed url using parse_urla and adds also the 'params' array to it
*
* @param string Url, like front_content.php?idcat=123...
* @return array Components containing result of parse_url with additional
* 'params' array
*/
private function _extractUrl($url) {
$aUrl = @parse_url($url);
if (isset($aUrl['query'])) {
$aUrl['query'] = str_replace('&amp;', '&', $aUrl['query']);
parse_str($aUrl['query'], $aUrl['params']);
}
if (!isset($aUrl['params']) && !is_array($aUrl['params'])) {
$aUrl['params'] = array();
}
return $aUrl;
}
/**
* Extracts article or category related parameter from passed params array
* and generates an identifier.
*
* @param array $aParams Parameter array
* @return string Composed stack id
*/
private function _makeStackId(array $aParams) {
# idcatart
if ((int) mr_arrayValue($aParams, 'idart') > 0) {
$sStackId = 'idart_' . $aParams['idart'] . '_lang_' . $aParams['lang'];
} elseif ((int) mr_arrayValue($aParams, 'idartlang') > 0) {
$sStackId = 'idartlang_' . $aParams['idartlang'];
} elseif ((int) mr_arrayValue($aParams, 'idcatart') > 0) {
$sStackId = 'idcatart_' . $aParams['idcatart'] . '_lang_' . $aParams['lang'];
} elseif ((int) mr_arrayValue($aParams, 'idcat') > 0) {
$sStackId = 'idcat_' . $aParams['idcat'] . '_lang_' . $aParams['lang'];
} elseif ((int) mr_arrayValue($aParams, 'idcatlang') > 0) {
$sStackId = 'idcatlang_' . $aParams['idcatlang'];
} else {
$sStackId = 'lang_' . $aParams['lang'];
}
return $sStackId;
}
/**
* Main function to get the urlparts of urls.
*
* Composes the query by looping thru stored but non processed urls, executes
* the query and adds the (urlpath and urlname) result to the stack.
*/
private function _chunkSetPrettyUrlParts() {
// collect stack parameter to get urlpath and urlname
$aStack = array();
foreach ($this->_aStack as $stackId => $item) {
if (!isset($item['urlpath'])) {
// pretty url is to create
$aStack[$stackId] = $item;
}
}
// now, it's time to compose the where clause of the query
$sWhere = '';
foreach ($aStack as $stackId => $item) {
$aP = $item['params'];
if ((int) mr_arrayValue($aP, 'idart') > 0) {
$sWhere .= '(al.idart = ' . $aP['idart'] . ' AND al.idlang = ' . $aP['lang'] . ') OR ';
} elseif ((int) mr_arrayValue($aP, 'idartlang') > 0) {
$sWhere .= '(al.idartlang = ' . $aP['idartlang'] . ') OR ';
} elseif ((int) mr_arrayValue($aP, 'idcat') > 0) {
$sWhere .= '(cl.idcat = ' . $aP['idcat'] . ' AND cl.idlang = ' . $aP['lang'] . ' AND cl.startidartlang = al.idartlang) OR ';
} elseif ((int) mr_arrayValue($aP, 'idcatart') > 0) {
$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 == '') {
return;
}
$sWhere = substr($sWhere, 0, -4);
$sWhere = str_replace(' OR ', " OR \n", $sWhere);
// compose query and execute it
$sql = <<<SQL
SELECT
al.idartlang, al.idart, al.idlang as lang, al.urlname, cl.idcatlang, cl.idcat,
cl.urlpath, ca.idcatart
FROM
{$this->_aTab['art_lang']} AS al, {$this->_aTab['cat_lang']} AS cl, {$this->_aTab['cat_art']} AS ca
WHERE
al.idart = ca.idart AND
ca.idcat = cl.idcat AND
al.idlang = cl.idlang AND
( $sWhere )
SQL;
ModRewriteDebugger::add($sql, 'ModRewriteUrlStack->_chunkSetPrettyUrlParts() $sql');
$aNewStack = array();
// create array of fields, which are to reduce step by step from record set below
$aFields = array('', 'idart', 'idartlang', 'idcatart', 'idcat');
$this->_oDb->query($sql);
while ($this->_oDb->next_record()) {
$aRS = $this->_oDb->Record;
// loop thru fields array
foreach ($aFields as $field) {
if (isset($aRS[$field])) {
// reduce existing field
unset($aRS[$field]);
}
$rsStackID = $this->_makeStackId($aRS);
if (isset($aStack[$rsStackID])) {
// matching stack entry found, add urlpath and urlname to the new stack
$aNewStack[$rsStackID]['urlpath'] = $aRS['urlpath'];
$aNewStack[$rsStackID]['urlname'] = $aRS['urlname'];
break;
}
}
}
ModRewriteDebugger::add($aNewStack, 'ModRewriteUrlStack->_chunkSetPrettyUrlParts() $aNewStack');
// merge stack data
$this->_aStack = array_merge($this->_aStack, $aNewStack);
}
}

Datei anzeigen

@ -0,0 +1,306 @@
<?php
/**
* AMR url utility class
*
* @package plugin
* @subpackage Mod Rewrite
* @version SVN Revision $Rev: 128 $
* @id $Id: class.modrewriteurlutil.php 128 2019-07-03 11:58:28Z oldperl $:
* @author Murat Purc <murat@purc.de>
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
/**
* Mod Rewrite url utility class. Handles convertion of Urls from CONTENIDO core
* based url composition pattern to AMR (Advanced Mod Rewrite) url composition
* pattern and vice versa.
*
* @author Murat Purc <murat@purc.de>
* @package plugin
* @subpackage Mod Rewrite
*/
class ModRewriteUrlUtil extends ModRewriteBase {
/**
* Self instance (singleton implementation)
* @var ModRewriteUrlUtil
*/
private static $_instance;
/**
* CONTENIDO category word separator
* @var string
*/
private $_catWordSep = '-';
/**
* AMR category word separator
* @var string
*/
private $_mrCatWordSep;
/**
* CONTENIDO category separator
* @var string
*/
private $_catSep = '/';
/**
* AMR category separator
* @var string
*/
private $_mrCatSep;
/**
* CONTENIDO article separator
* @var string
*/
private $_artSep = '/';
/**
* AMR article separator
* @var string
*/
private $_mrArtSep;
/**
* CONTENIDO article word separator
* @var string
*/
private $_artWordSep = '-';
/**
* AMR article word separator
* @var string
*/
private $_mrArtWordSep;
/**
* AMR extension used for articlenames (e. g. .html)
* @var string
*/
private $_mrExt;
/**
* Constructor, sets some AMR configuration related properties
*/
private function __construct() {
$aCfg = parent::getConfig();
$this->_mrCatWordSep = $aCfg['category_word_seperator'];
$this->_mrCatSep = $aCfg['category_seperator'];
$this->_mrArtSep = $aCfg['article_seperator'];
$this->_mrArtWordSep = $aCfg['article_word_seperator'];
$this->_mrExt = $aCfg['file_extension'];
}
/**
* Prevent cloning
*/
private function __clone() {
}
/**
* Returns self instance (singleton pattern)
* @return ModRewriteUrlUtil
*/
public static function getInstance() {
if (self::$_instance == null) {
self::$_instance = new ModRewriteUrlUtil();
}
return self::$_instance;
}
/**
* Converts passed AMR url path to CONTENIDO url path.
*
* @param string $urlPath AMR url path
* @return string CONTENIDO url path
*/
public function toContenidoUrlPath($urlPath) {
$newUrlPath = $this->_toUrlPath(
$urlPath, $this->_mrCatSep, $this->_catSep, $this->_mrCatWordSep, $this->_catWordSep, $this->_mrArtSep, $this->_artSep
);
return $newUrlPath;
}
/**
* Converts passed CONTENIDO url path to AMR url path.
*
* @param string $urlPath CONTENIDO url path
* @return string AMR url path
*/
public function toModRewriteUrlPath($urlPath) {
$newUrlPath = $this->_toUrlPath(
$urlPath, $this->_catSep, $this->_mrCatSep, $this->_catWordSep, $this->_mrCatWordSep, $this->_artSep, $this->_mrArtSep
);
return $newUrlPath;
}
/**
* Converts passed url path to a another url path (CONTENIDO to AMR and vice versa).
*
* @param string $urlPath Source url path
* @param string $fromCatSep Source category seperator
* @param string $toCatSep Destination category seperator
* @param string $fromCatWordSep Source category word seperator
* @param string $toCatWordSep Destination category word seperator
* @param string $fromArtSep Source article seperator
* @param string $toArtSep Destination article seperator
* @return string Destination url path
*/
private function _toUrlPath($urlPath, $fromCatSep, $toCatSep, $fromCatWordSep, $toCatWordSep, $fromArtSep, $toArtSep) {
if ((string) $urlPath == '') {
return $urlPath;
}
if (substr($urlPath, -1) == $fromArtSep) {
$urlPath = substr($urlPath, 0, -1) . '{TAS}';
}
// pre replace category word seperator and category seperator
$urlPath = str_replace($fromCatWordSep, '{CWS}', $urlPath);
$urlPath = str_replace($fromCatSep, '{CS}', $urlPath);
// replace category word seperator
$urlPath = str_replace('{CWS}', $toCatWordSep, $urlPath);
$urlPath = str_replace('{CS}', $toCatSep, $urlPath);
$urlPath = str_replace('{TAS}', $toArtSep, $urlPath);
return $urlPath;
}
/**
* Converts passed AMR url name to CONTENIDO url name.
*
* @param string $urlName AMR url name
* @return string CONTENIDO url name
*/
public function toContenidoUrlName($urlName) {
$newUrlName = $this->_toUrlName($urlName, $this->_mrArtWordSep, $this->_artWordSep);
return $newUrlName;
}
/**
* Converts passed CONTENIDO url name to AMR url name.
*
* @param string $urlName CONTENIDO url name
* @return string AMR url name
*/
public function toModRewriteUrlName($urlName) {
$newUrlName = $this->_toUrlName($urlName, $this->_artWordSep, $this->_mrArtWordSep);
return $newUrlName;
}
/**
* Converts passed url name to a another url name (CONTENIDO to AMR and vice versa).
*
* @param string $urlName Source url name
* @param string $fromArtWordSep Source article word seperator
* @param string $toArtWordSep Destination article word seperator
* @return string Destination url name
*/
private function _toUrlName($urlName, $fromArtWordSep, $toArtWordSep) {
if ((string) $urlName == '') {
return $urlName;
}
$urlName = str_replace($this->_mrExt, '{EXT}', $urlName);
// replace article word seperator
$urlName = str_replace($fromArtWordSep, $toArtWordSep, $urlName);
$urlName = str_replace('{EXT}', $this->_mrExt, $urlName);
return $urlName;
}
/**
* Converts passed AMR url to CONTENIDO url.
*
* @param string $url AMR url
* @return string CONTENIDO url
*/
public function toContenidoUrl($url) {
if (strpos($url, $this->_mrExt) === false) {
$newUrl = $this->toContenidoUrlPath($url);
} else {
// replace category word and article word seperator
$path = substr($url, 0, strrpos($url, $this->_mrArtSep) + 1);
$name = substr($url, strrpos($url, $this->_mrArtSep) + 1);
$newUrl = $this->toContenidoUrlPath($path) . $this->toContenidoUrlName($name);
}
return $newUrl;
}
/**
* Converts passed AMR url to CONTENIDO url.
*
* @param string $url AMR url
* @return string CONTENIDO url
*/
public function toModRewriteUrl($url) {
if (strpos($url, $this->_mrExt) === false) {
$newUrl = $this->toModRewriteUrlPath($url);
} else {
// replace category word and article word seperator
$path = substr($url, 0, strrpos($url, $this->_artSep) + 1);
$name = substr($url, strrpos($url, $this->_artSep) + 1);
$newUrl = $this->toModRewriteUrlPath($path) . $this->toModRewriteUrlName($name);
}
return $newUrl;
}
/**
* Converts passed url to a another url (CONTENIDO to AMR and vice versa).
*
* @param string $url Source url
* @param string $fromCatSep Source category seperator
* @param string $toCatSep Destination category seperator
* @param string $fromCatWordSep Source category word seperator
* @param string $toCatWordSep Destination category word seperator
* @param string $fromArtSep Source article seperator
* @param string $toArtSep Destination article seperator
* @param string $fromArtWordSep Source article word seperator
* @param string $toArtWordSep Destination article word seperator
* @return string Destination url
*
* @deprecated No more used, is to delete
*/
private function _toUrl($url, $fromCatSep, $toCatSep, $fromCatWordSep, $toCatWordSep, $fromArtSep, $toArtSep, $fromArtWordSep, $toArtWordSep) {
if ((string) $url == '') {
return $url;
}
$url = str_replace($this->_mrExt, '{EXT}', $url);
// replace category seperator
$url = str_replace($fromCatSep, $toCatSep, $url);
// replace article seperator
$url = str_replace($fromArtSep, $toArtSep, $url);
$url = str_replace('{EXT}', $this->_mrExt, $url);
if (strpos($url, $this->_mrExt) === false) {
// no articlename, replace category word seperator
$url = str_replace($fromCatWordSep, $toCatWordSep, $url);
} else {
// replace category word and article word seperator
$path = str_replace($fromCatWordSep, $toCatWordSep, substr($url, 0, strrpos($url, $toArtSep) + 1));
$file = str_replace($fromArtWordSep, $toArtWordSep, substr($url, strrpos($url, $toArtSep) + 1));
$url = $path . $file;
}
return $url;
}
}

Datei anzeigen

@ -0,0 +1,426 @@
<?php
/**
* AMR Content controller class
*
* @package plugin
* @subpackage Mod Rewrite
* @version SVN Revision $Rev: 128 $
* @id $Id: class.modrewrite_content_controller.php 128 2019-07-03 11:58:28Z oldperl $:
* @author Murat Purc <murat@purc.de>
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
/**
* Content controller for general settings.
*
* @author Murat Purc <murat@purc.de>
* @package plugin
* @subpackage Mod Rewrite
*/
class ModRewrite_ContentController extends ModRewrite_ControllerAbstract {
/**
* Index action
*/
public function indexAction() {
// donut
$this->_doChecks();
}
/**
* Save settings action
*/
public function saveAction() {
$bDebug = $this->getProperty('bDebug');
$aSeparator = $this->getProperty('aSeparator');
$aWordSeparator = $this->getProperty('aWordSeparator');
$routingSeparator = $this->getProperty('routingSeparator');
$bError = false;
$aMR = array();
$request = (count($_POST) > 0) ? $_POST : $_GET;
mr_requestCleanup($request);
// use mod_rewrite
if (mr_arrayValue($request, 'use') == 1) {
$this->_oView->use_chk = ' checked="checked"';
$aMR['mod_rewrite']['use'] = 1;
} else {
$this->_oView->use_chk = '';
$aMR['mod_rewrite']['use'] = 0;
}
// root dir
if (mr_arrayValue($request, 'rootdir', '') !== '') {
if (!preg_match('/^[a-zA-Z0-9\-_\/\.]*$/', $request['rootdir'])) {
$sMsg = i18n("The root directory has a invalid format, alowed are the chars [a-zA-Z0-9\-_\/\.]", "mod_rewrite");
$this->_oView->rootdir_error = $this->_notifyBox('error', $sMsg);
$bError = true;
} elseif (!is_dir($_SERVER['DOCUMENT_ROOT'] . $request['rootdir'])) {
if (mr_arrayValue($request, 'checkrootdir') == 1) {
// root dir check is enabled, this results in error
$sMsg = i18n("The specified directory '%s' does not exists", "mod_rewrite");
$sMsg = sprintf($sMsg, $_SERVER['DOCUMENT_ROOT'] . $request['rootdir']);
$this->_oView->rootdir_error = $this->_notifyBox('error', $sMsg);
$bError = true;
} else {
// root dir check ist disabled, take over the setting and
// output a warning.
$sMsg = i18n("The specified directory '%s' does not exists in DOCUMENT_ROOT '%s'. This could happen, if clients DOCUMENT_ROOT differs from CONTENIDO backends DOCUMENT_ROOT. However, the setting will be taken over because of disabled check.", "mod_rewrite");
$sMsg = sprintf($sMsg, $request['rootdir'], $_SERVER['DOCUMENT_ROOT']);
$this->_oView->rootdir_error = $this->_notifyBox('warning', $sMsg);
}
}
$this->_oView->rootdir = conHtmlentities($request['rootdir']);
$aMR['mod_rewrite']['rootdir'] = $request['rootdir'];
}
// root dir check
if (mr_arrayValue($request, 'checkrootdir') == 1) {
$this->_oView->checkrootdir_chk = ' checked="checked"';
$aMR['mod_rewrite']['checkrootdir'] = 1;
} else {
$this->_oView->checkrootdir_chk = '';
$aMR['mod_rewrite']['checkrootdir'] = 0;
}
// start from root
if (mr_arrayValue($request, 'startfromroot') == 1) {
$this->_oView->startfromroot_chk = ' checked="checked"';
$aMR['mod_rewrite']['startfromroot'] = 1;
} else {
$this->_oView->startfromroot_chk = '';
$aMR['mod_rewrite']['startfromroot'] = 0;
}
// prevent duplicated content
if (mr_arrayValue($request, 'prevent_duplicated_content') == 1) {
$this->_oView->prevent_duplicated_content_chk = ' checked="checked"';
$aMR['mod_rewrite']['prevent_duplicated_content'] = 1;
} else {
$this->_oView->prevent_duplicated_content_chk = '';
$aMR['mod_rewrite']['prevent_duplicated_content'] = 0;
}
// language settings
if (mr_arrayValue($request, 'use_language') == 1) {
$this->_oView->use_language_chk = ' checked="checked"';
$this->_oView->use_language_name_disabled = '';
$aMR['mod_rewrite']['use_language'] = 1;
if (mr_arrayValue($request, 'use_language_name') == 1) {
$this->_oView->use_language_name_chk = ' checked="checked"';
$aMR['mod_rewrite']['use_language_name'] = 1;
} else {
$this->_oView->use_language_name_chk = '';
$aMR['mod_rewrite']['use_language_name'] = 0;
}
} else {
$this->_oView->use_language_chk = '';
$this->_oView->use_language_name_chk = '';
$this->_oView->use_language_name_disabled = ' disabled="disabled"';
$aMR['mod_rewrite']['use_language'] = 0;
$aMR['mod_rewrite']['use_language_name'] = 0;
}
// client settings
if (mr_arrayValue($request, 'use_client') == 1) {
$this->_oView->use_client_chk = ' checked="checked"';
$this->_oView->use_client_name_disabled = '';
$aMR['mod_rewrite']['use_client'] = 1;
if (mr_arrayValue($request, 'use_client_name') == 1) {
$this->_oView->use_client_name_chk = ' checked="checked"';
$aMR['mod_rewrite']['use_client_name'] = 1;
} else {
$this->_oView->use_client_name_chk = '';
$aMR['mod_rewrite']['use_client_name'] = 0;
}
} else {
$this->_oView->use_client_chk = '';
$this->_oView->use_client_name_chk = '';
$this->_oView->use_client_name_disabled = ' disabled="disabled"';
$aMR['mod_rewrite']['use_client'] = 0;
$aMR['mod_rewrite']['use_client_name'] = 0;
}
// use lowercase uri
if (mr_arrayValue($request, 'use_lowercase_uri') == 1) {
$this->_oView->use_lowercase_uri_chk = ' checked="checked"';
$aMR['mod_rewrite']['use_lowercase_uri'] = 1;
} else {
$this->_oView->use_lowercase_uri_chk = '';
$aMR['mod_rewrite']['use_lowercase_uri'] = 0;
}
$this->_oView->category_separator_attrib = '';
$this->_oView->category_word_separator_attrib = '';
$this->_oView->article_separator_attrib = '';
$this->_oView->article_word_separator_attrib = '';
$separatorPattern = $aSeparator['pattern'];
$separatorInfo = $aSeparator['info'];
$wordSeparatorPattern = $aSeparator['pattern'];
$wordSeparatorInfo = $aSeparator['info'];
$categorySeperator = mr_arrayValue($request, 'category_seperator', '');
$categoryWordSeperator = mr_arrayValue($request, 'category_word_seperator', '');
$articleSeperator = mr_arrayValue($request, 'article_seperator', '');
$articleWordSeperator = mr_arrayValue($request, 'article_word_seperator', '');
// category seperator
if ($categorySeperator == '') {
$sMsg = i18n("Please specify separator (%s) for category", "mod_rewrite");
$sMsg = sprintf($sMsg, $separatorInfo);
$this->_oView->category_separator_error = $this->_notifyBox('error', $sMsg);
$bError = true;
} elseif (!preg_match($separatorPattern, $categorySeperator)) {
$sMsg = i18n("Invalid separator for category, allowed one of following characters: %s", "mod_rewrite");
$sMsg = sprintf($sMsg, $separatorInfo);
$this->_oView->category_separator_error = $this->_notifyBox('error', $sMsg);
$bError = true;
// category word seperator
} elseif ($categoryWordSeperator == '') {
$sMsg = i18n("Please specify separator (%s) for category words", "mod_rewrite");
$sMsg = sprintf($sMsg, $wordSeparatorInfo);
$this->_oView->category_word_separator_error = $this->_notifyBox('error', $sMsg);
$bError = true;
} elseif (!preg_match($wordSeparatorPattern, $categoryWordSeperator)) {
$sMsg = i18n("Invalid separator for category words, allowed one of following characters: %s", "mod_rewrite");
$sMsg = sprintf($sMsg, $wordSeparatorInfo);
$this->_oView->category_word_separator_error = $this->_notifyBox('error', $sMsg);
$bError = true;
// article seperator
} elseif ($articleSeperator == '') {
$sMsg = i18n("Please specify separator (%s) for article", "mod_rewrite");
$sMsg = sprintf($sMsg, $separatorInfo);
$this->_oView->article_separator_error = $this->_notifyBox('error', $sMsg);
$bError = true;
} elseif (!preg_match($separatorPattern, $articleSeperator)) {
$sMsg = i18n("Invalid separator for article, allowed is one of following characters: %s", "mod_rewrite");
$sMsg = sprintf($sMsg, $separatorInfo);
$this->_oView->article_separator_error = $this->_notifyBox('error', $sMsg);
$bError = true;
// article word seperator
} elseif ($articleWordSeperator == '') {
$sMsg = i18n("Please specify separator (%s) for article words", "mod_rewrite");
$sMsg = sprintf($sMsg, $wordSeparatorInfo);
$this->_oView->article_word_separator_error = $this->_notifyBox('error', $sMsg);
$bError = true;
} elseif (!preg_match($wordSeparatorPattern, $articleWordSeperator)) {
$sMsg = i18n("Invalid separator for article words, allowed is one of following characters: %s", "mod_rewrite");
$sMsg = sprintf($sMsg, $wordSeparatorInfo);
$this->_oView->article_word_separator_error = $this->_notifyBox('error', $sMsg);
$bError = true;
// category_seperator - category_word_seperator
} elseif ($categorySeperator == $categoryWordSeperator) {
$sMsg = i18n("Separator for category and category words must not be identical", "mod_rewrite");
$this->_oView->category_separator_error = $this->_notifyBox('error', $sMsg);
$bError = true;
// category_seperator - article_word_seperator
} elseif ($categorySeperator == $articleWordSeperator) {
$sMsg = i18n("Separator for category and article words must not be identical", "mod_rewrite");
$this->_oView->category_separator_error = $this->_notifyBox('error', $sMsg);
$bError = true;
// article_seperator - article_word_seperator
} elseif ($articleSeperator == $articleWordSeperator) {
$sMsg = i18n("Separator for category-article and article words must not be identical", "mod_rewrite");
$this->_oView->article_separator_error = $this->_notifyBox('error', $sMsg);
$bError = true;
}
$this->_oView->category_separator = conHtmlentities($categorySeperator);
$aMR['mod_rewrite']['category_seperator'] = $categorySeperator;
$this->_oView->category_word_separator = conHtmlentities($categoryWordSeperator);
$aMR['mod_rewrite']['category_word_seperator'] = $categoryWordSeperator;
$this->_oView->article_separator = conHtmlentities($articleSeperator);
$aMR['mod_rewrite']['article_seperator'] = $articleSeperator;
$this->_oView->article_word_separator = conHtmlentities($articleWordSeperator);
$aMR['mod_rewrite']['article_word_seperator'] = $articleWordSeperator;
// file extension
if (mr_arrayValue($request, 'file_extension', '') !== '') {
if (!preg_match('/^\.([a-zA-Z0-9\-_\/])*$/', $request['file_extension'])) {
$sMsg = i18n("The file extension has a invalid format, allowed are the chars \.([a-zA-Z0-9\-_\/])", "mod_rewrite");
$this->_oView->file_extension_error = $this->_notifyBox('error', $sMsg);
$bError = true;
}
$this->_oView->file_extension = conHtmlentities($request['file_extension']);
$aMR['mod_rewrite']['file_extension'] = $request['file_extension'];
} else {
$this->_oView->file_extension = '.html';
$aMR['mod_rewrite']['file_extension'] = '.html';
}
// category resolve min percentage
if (isset($request['category_resolve_min_percentage'])) {
if (!is_numeric($request['category_resolve_min_percentage'])) {
$sMsg = i18n("Value has to be numeric.", "mod_rewrite");
$this->_oView->category_resolve_min_percentage_error = $this->_notifyBox('error', $sMsg);
$bError = true;
} elseif ($request['category_resolve_min_percentage'] < 0 || $request['category_resolve_min_percentage'] > 100) {
$sMsg = i18n("Value has to be between 0 an 100.", "mod_rewrite");
$this->_oView->category_resolve_min_percentage_error = $this->_notifyBox('error', $sMsg);
$bError = true;
}
$this->_oView->category_resolve_min_percentage = $request['category_resolve_min_percentage'];
$aMR['mod_rewrite']['category_resolve_min_percentage'] = $request['category_resolve_min_percentage'];
} else {
$this->_oView->category_resolve_min_percentage = '75';
$aMR['mod_rewrite']['category_resolve_min_percentage'] = '75';
}
// add start article name to url
if (mr_arrayValue($request, 'add_startart_name_to_url') == 1) {
$this->_oView->add_startart_name_to_url_chk = ' checked="checked"';
$aMR['mod_rewrite']['add_startart_name_to_url'] = 1;
if (mr_arrayValue($request, 'add_startart_name_to_url', '') !== '') {
if (!preg_match('/^[a-zA-Z0-9\-_\/\.]*$/', $request['default_startart_name'])) {
$sMsg = i18n("The article name has a invalid format, allowed are the chars /^[a-zA-Z0-9\-_\/\.]*$/", "mod_rewrite");
$this->_oView->add_startart_name_to_url_error = $this->_notifyBox('error', $sMsg);
$bError = true;
}
$this->_oView->default_startart_name = conHtmlentities($request['default_startart_name']);
$aMR['mod_rewrite']['default_startart_name'] = $request['default_startart_name'];
} else {
$this->_oView->default_startart_name = '';
$aMR['mod_rewrite']['default_startart_name'] = '';
}
} else {
$this->_oView->add_startart_name_to_url_chk = '';
$aMR['mod_rewrite']['add_startart_name_to_url'] = 0;
$this->_oView->default_startart_name = '';
$aMR['mod_rewrite']['default_startart_name'] = '';
}
// rewrite urls at
if (mr_arrayValue($request, 'rewrite_urls_at') == 'congeneratecode') {
$this->_oView->rewrite_urls_at_congeneratecode_chk = ' checked="checked"';
$this->_oView->rewrite_urls_at_front_content_output_chk = '';
$aMR['mod_rewrite']['rewrite_urls_at_congeneratecode'] = 1;
$aMR['mod_rewrite']['rewrite_urls_at_front_content_output'] = 0;
} else {
$this->_oView->rewrite_urls_at_congeneratecode_chk = '';
$this->_oView->rewrite_urls_at_front_content_output_chk = ' checked="checked"';
$aMR['mod_rewrite']['rewrite_urls_at_congeneratecode'] = 0;
$aMR['mod_rewrite']['rewrite_urls_at_front_content_output'] = 1;
}
// routing
if (isset($request['rewrite_routing'])) {
$aRouting = array();
$items = explode("\n", $request['rewrite_routing']);
foreach ($items as $p => $v) {
$routingDef = explode($routingSeparator, $v);
if (count($routingDef) !== 2) {
continue;
}
$routingDef[0] = trim($routingDef[0]);
$routingDef[1] = trim($routingDef[1]);
if ($routingDef[0] == '') {
continue;
}
$aRouting[$routingDef[0]] = $routingDef[1];
}
$this->_oView->rewrite_routing = conHtmlentities($request['rewrite_routing']);
$aMR['mod_rewrite']['routing'] = $aRouting;
} else {
$this->_oView->rewrite_routing = '';
$aMR['mod_rewrite']['routing'] = array();
}
// redirect invalid article to errorsite
if (isset($request['redirect_invalid_article_to_errorsite'])) {
$this->_oView->redirect_invalid_article_to_errorsite_chk = ' checked="checked"';
$aMR['mod_rewrite']['redirect_invalid_article_to_errorsite'] = 1;
} else {
$this->_oView->redirect_invalid_article_to_errorsite_chk = '';
$aMR['mod_rewrite']['redirect_invalid_article_to_errorsite'] = 0;
}
if ($bError) {
$sMsg = i18n("Please check your input", "mod_rewrite");
$this->_oView->content_before .= $this->_notifyBox('error', $sMsg);
return;
}
if ($bDebug == true) {
echo $this->_notifyBox('info', 'Debug');
echo '<pre class="example">';
print_r($aMR['mod_rewrite']);
echo '</pre>';
$sMsg = i18n("Configuration has <b>not</b> been saved, because of enabled debugging", "mod_rewrite");
echo $this->_notifyBox('info', $sMsg);
return;
}
$bSeparatorModified = $this->_separatorModified($aMR['mod_rewrite']);
if (mr_setConfiguration($this->_client, $aMR)) {
$sMsg = i18n("Configuration has been saved", "mod_rewrite");
if ($bSeparatorModified) {
mr_loadConfiguration($this->_client, true);
}
$this->_oView->content_before .= $this->_notifyBox('info', $sMsg);
} else {
$sMsg = i18n("Configuration could not saved. Please check write permissions for %s ", "mod_rewrite");
$sMsg = sprintf($sMsg, $options['key']);
$this->_oView->content_before .= $this->_notifyBox('error', $sMsg);
}
}
/**
* Checks, if any sseparators setting is modified or not
* @param array $aNewCfg New configuration send by requests.
* @return bool
*/
protected function _separatorModified($aNewCfg) {
$aCfg = ModRewrite::getConfig();
if ($aCfg['category_seperator'] != $aNewCfg['category_seperator']) {
return true;
} elseif ($aCfg['category_word_seperator'] != $aNewCfg['category_word_seperator']) {
return true;
} elseif ($aCfg['article_seperator'] != $aNewCfg['article_seperator']) {
return true;
} elseif ($aCfg['article_word_seperator'] != $aNewCfg['article_word_seperator']) {
return true;
}
return false;
}
/**
* Does some checks like 'is_start_compatible' check.
* Adds notifications, if something will went wrong...
*/
protected function _doChecks() {
// Check for not supported '$cfg["is_start_compatible"] = true;' mode
if (!empty($this->_cfg['is_start_compatible']) && true === $this->_cfg['is_start_compatible']) {
$sMsg = i18n("Your Contenido installation runs with the setting 'is_start_compatible'. This plugin will not work properly in this mode.<br />Please check following topic in Contenido forum to change this:<br /><br /><a href='http://forum.contenido.org/viewtopic.php?t=32530' class='blue' target='_blank'>is_start_compatible auf neue Version umstellen</a>", "mod_rewrite");
$this->_oView->content_before .= $this->_notifyBox('warning', $sMsg);
}
// Check for empty urlpath entries in cat_lang table
$db = new DB_Contenido();
$sql = "SELECT idcatlang FROM " . $this->_cfg['tab']['cat_lang'] . " WHERE urlpath = ''";
if ($db->query($sql) && $db->next_record()) {
$sMsg = i18n("It seems as if some categories don't have a set 'urlpath' entry in the database. Please reset empty aliases in %sFunctions%s area.", "mod_rewrite");
$sMsg = sprintf($sMsg, '<a href="main.php?area=mod_rewrite_expert&frame=4&contenido=' . $this->_oView->sessid . '&idclient=' . $this->_client . '" onclick="parent.right_top.sub.clicked(parent.right_top.document.getElementById(\'c_1\').firstChild);">', '</a>');
$this->_oView->content_before .= $this->_notifyBox('warning', $sMsg);
}
}
}

Datei anzeigen

@ -0,0 +1,143 @@
<?php
/**
* AMR Content expert controller class
*
* @package plugin
* @subpackage Mod Rewrite
* @version SVN Revision $Rev: 128 $
* @id $Id: class.modrewrite_contentexpert_controller.php 128 2019-07-03 11:58:28Z oldperl $:
* @author Murat Purc <murat@purc.de>
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
/**
* Content expert controller for expert settings/actions.
*
* @author Murat Purc <murat@purc.de>
* @package plugin
* @subpackage Mod Rewrite
*/
class ModRewrite_ContentExpertController extends ModRewrite_ControllerAbstract {
/**
* Path to restrictive htaccess file
* @var string
*/
protected $_htaccessRestrictive = '';
/**
* Path to simple htaccess file
* @var string
*/
protected $_htaccessSimple = '';
/**
* Initializer method, sets the paths to htaccess files
*/
public function init() {
$this->_oView->content_before = '';
$pluginPath = $this->_cfg['path']['contenido'] . $this->_cfg['path']['plugins'] . 'mod_rewrite/';
$this->_htaccessRestrictive = $pluginPath . 'files/htaccess_restrictive.txt';
$this->_htaccessSimple = $pluginPath . 'files/htaccess_simple.txt';
}
/**
* Index action
*/
public function indexAction() {
}
/**
* Copy htaccess action
*/
public function copyHtaccessAction() {
$type = $this->_getParam('htaccesstype');
$copy = $this->_getParam('copy');
if ($type != 'restrictive' && $type != 'simple') {
return;
} elseif ($copy != 'contenido' && $copy != 'cms') {
return;
}
$aInfo = $this->getProperty('htaccessInfo');
if ($aInfo['has_htaccess']) {
$this->_oView->content_before = $this->_notifyBox('info', 'Die .htaccess existiert bereits im Contenido-/ oder Mandantenverzeichnis, daher wird es nicht kopiert');
return;
}
if ($type == 'restrictive') {
$source = $this->_htaccessRestrictive;
} else {
$source = $this->_htaccessSimple;
}
if ($copy == 'contenido') {
$dest = $aInfo['contenido_full_path'] . '.htaccess';
} else {
$dest = $aInfo['client_full_path'] . '.htaccess';
}
if (!$result = @copy($source, $dest)) {
$this->_oView->content_before = $this->_notifyBox('info', 'Die .htaccess konnte nicht von ' . $source . ' nach ' . $dest . ' kopiert werden!');
return;
}
$msg = 'Die .htaccess wurde erfolgreich nach ' . str_replace('.htaccess', '', $dest) . ' kopiert';
$this->_oView->content_before = $this->_notifyBox('info', $msg);
}
/**
* Download htaccess action
*/
public function downloadHtaccessAction() {
$type = $this->_getParam('htaccesstype');
if ($type != 'restrictive' && $type != 'simple') {
return;
}
if ($type == 'restrictive') {
$source = $this->_htaccessRestrictive;
} else {
$source = $this->_htaccessSimple;
}
$this->_oView->content = file_get_contents($source);
header('Content-Type: text/plain');
header('Etag: ' . md5(mt_rand()));
header('Content-Disposition: attachment; filename="' . $type . '.htaccess"');
$this->render('{CONTENT}');
}
/**
* Reset aliases action
*/
public function resetAction() {
// recreate all aliases
ModRewrite::recreateAliases(false);
$this->_oView->content_before = $this->_notifyBox('info', 'Alle Aliase wurden zur&uuml;ckgesetzt');
}
/**
* Reset only empty aliases action
*/
public function resetEmptyAction() {
// recreate only empty aliases
ModRewrite::recreateAliases(true);
$this->_oView->content_before = $this->_notifyBox('info', 'Nur leere Aliase wurden zur&uuml;ckgesetzt');
}
}

Datei anzeigen

@ -0,0 +1,176 @@
<?php
/**
* AMR test controller
*
* @package plugin
* @subpackage Mod Rewrite
* @version SVN Revision $Rev: 128 $
* @id $Id: class.modrewrite_contenttest_controller.php 128 2019-07-03 11:58:28Z oldperl $:
* @author Murat Purc <murat@purc.de>
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
/**
* Content controller to run tests.
*
* @author Murat Purc <murat@purc.de>
* @package plugin
* @subpackage Mod Rewrite
*/
class ModRewrite_ContentTestController extends ModRewrite_ControllerAbstract {
/**
* Number of max items to process
* @var int
*/
protected $_iMaxItems = 0;
/**
* Initializer method, sets some view variables
*/
public function init() {
$this->_oView->content = '';
$this->_oView->form_idart_chk = ($this->_getParam('idart')) ? ' checked="checked"' : '';
$this->_oView->form_idcat_chk = ($this->_getParam('idcat')) ? ' checked="checked"' : '';
$this->_oView->form_idcatart_chk = ($this->_getParam('idcatart')) ? ' checked="checked"' : '';
$this->_oView->form_idartlang_chk = ($this->_getParam('idartlang')) ? ' checked="checked"' : '';
$this->_oView->form_maxitems = (int) $this->_getParam('maxitems', 200);
$this->_iMaxItems = $this->_oView->form_maxitems;
}
/**
* Index action
*/
public function indexAction() {
$this->_oView->content = '';
}
/**
* Test action
*/
public function testAction() {
$this->_oView->content = '';
// Array for testcases
$aTests = array();
// Instance of mr test
$oMRTest = new ModRewriteTest($this->_iMaxItems);
$startTime = getmicrotime();
// Fetch complete CONTENIDO page structure
$aStruct = $oMRTest->fetchFullStructure();
ModRewriteDebugger::add($aStruct, 'mr_test.php $aStruct');
// Loop through the structure and compose testcases
foreach ($aStruct as $idcat => $aCat) {
// category
$aTests[] = array(
'url' => $oMRTest->composeURL($aCat, 'c'),
'level' => $aCat['level'],
'name' => $aCat['name']
);
foreach ($aCat['articles'] as $idart => $aArt) {
// articles
$aTests[] = array(
'url' => $oMRTest->composeURL($aArt, 'a'),
'level' => $aCat['level'],
'name' => $aCat['name'] . ' :: ' . $aArt['title']
);
}
}
// compose content
$this->_oView->content = '<pre>';
$oMRUrlStack = ModRewriteUrlStack::getInstance();
// first loop to add urls to mr url stack
foreach ($aTests as $p => $v) {
$oMRUrlStack->add($v['url']);
}
$successCounter = 0;
$failCounter = 0;
// second loop to do the rest
foreach ($aTests as $p => $v) {
$url = mr_buildNewUrl($v['url']);
$arr = $oMRTest->resolveUrl($url);
$error = '';
$resUrl = $oMRTest->getResolvedUrl();
$color = 'green';
if ($url !== $resUrl) {
if ($oMRTest->getRoutingFoundState()) {
$successCounter++;
$resUrl = 'route to -&gt; ' . $resUrl;
} else {
$color = 'red';
$failCounter++;
}
} else {
$successCounter++;
}
// @todo: translate
if (isset($arr['error'])) {
switch ($arr['error']) {
case ModRewriteController::ERROR_CLIENT:
$error = 'client';
break;
case ModRewriteController::ERROR_LANGUAGE:
$error = 'language';
break;
case ModRewriteController::ERROR_CATEGORY:
$error = 'category';
break;
case ModRewriteController::ERROR_ARTICLE:
$error = 'article';
break;
case ModRewriteController::ERROR_POST_VALIDATION:
$error = 'validation';
break;
}
}
$pref = str_repeat(' ', $v['level']);
// render resolve information for current item
$itemTpl = $this->_oView->lng_result_item_tpl;
$itemTpl = str_replace('{pref}', $pref, $itemTpl);
$itemTpl = str_replace('{name}', $v['name'], $itemTpl);
$itemTpl = str_replace('{url_in}', $v['url'], $itemTpl);
$itemTpl = str_replace('{url_out}', $url, $itemTpl);
$itemTpl = str_replace('{color}', $color, $itemTpl);
$itemTpl = str_replace('{url_res}', $resUrl, $itemTpl);
$itemTpl = str_replace('{err}', $error, $itemTpl);
$itemTpl = str_replace('{data}', $oMRTest->getReadableResolvedData($arr), $itemTpl);
$this->_oView->content .= "\n" . $itemTpl . "\n";
}
$this->_oView->content .= '</pre>';
$totalTime = sprintf('%.4f', (getmicrotime() - $startTime));
// render information about current test
$msg = $this->_oView->lng_result_message_tpl;
$msg = str_replace('{time}', $totalTime, $msg);
$msg = str_replace('{num_urls}', ($successCounter + $failCounter), $msg);
$msg = str_replace('{num_success}', $successCounter, $msg);
$msg = str_replace('{num_fail}', $failCounter, $msg);
$this->_oView->content = $msg . $this->_oView->content;
}
}

Datei anzeigen

@ -0,0 +1,226 @@
<?php
/**
* AMR abstract controller class
*
* @package plugin
* @subpackage Mod Rewrite
* @version SVN Revision $Rev: 128 $
* @id $Id: class.modrewrite_controller_abstract.php 128 2019-07-03 11:58:28Z oldperl $:
* @author Murat Purc <murat@purc.de>
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
/**
* Abstract controller for all concrete mod_rewrite controller implementations.
*
* @author Murat Purc <murat@purc.de>
* @package plugin
* @subpackage Mod Rewrite
*/
abstract class ModRewrite_ControllerAbstract {
/**
* View object, holds all view variables
* @var stdClass
*/
protected $_oView;
/**
* Global CONTENIDO $cfg variable
* @var array
*/
protected $_cfg;
/**
* Global CONTENIDO $client variable (client id)
* @var int
*/
protected $_client;
/**
* Global CONTENIDO $area variable (area name/id)
* @var int|string
*/
protected $_area;
/**
* Global CONTENIDO $action variable (send by request)
* @var string
*/
protected $_action;
/**
* Global CONTENIDO $frame variable (current frame in backend)
* @var int
*/
protected $_frame;
/**
* Global CONTENIDO $contenido variable (session id)
* @var string
*/
protected $_contenido;
/**
* Template file or template string to render
* @var string
*/
protected $_template = null;
/**
* Additional properties list
* @var array
*/
protected $_properties = array();
/**
* Debug flag
* @var bool
*/
protected $_debug = false;
/**
* Constructor, sets some properties by assigning global variables to them.
*/
public function __construct() {
global $cfg, $client, $area, $action, $frame, $contenido, $sess;
$this->_oView = new stdClass();
$this->_cfg = $cfg;
$this->_area = $area;
$this->_action = $action;
$this->_frame = $frame;
$this->_client = $client;
$this->_contenido = $contenido;
$this->_oView->area = $this->_area;
$this->_oView->frame = $this->_frame;
$this->_oView->contenido = $this->_contenido;
$this->_oView->sessid = $sess->id;
$this->_oView->lng_more_informations = i18n("More informations", "mod_rewrite");
$this->init();
}
/**
* Initializer method, could be overwritten by childs.
* This method will be invoked in constructor of ModRewrite_ControllerAbstract.
*/
public function init() {
}
/**
* View property setter.
* @param object $oView
*/
public function setView($oView) {
if (is_object($oView)) {
$this->_oView = $oView;
}
}
/**
* View property getter.
* @return object
*/
public function getView() {
return $this->_oView;
}
/**
* Property setter.
* @param string $key
* @param mixed $value
*/
public function setProperty($key, $value) {
$this->_properties[$key] = $value;
}
/**
* Property getter.
* @param string $key
* @param mixed $default
* @return mixed
*/
public function getProperty($key, $default = null) {
return (isset($this->_properties[$key])) ? $this->_properties[$key] : $default;
}
/**
* Template setter.
* @param string $sTemplate Either full path and name of template file or a template string.
*/
public function setTemplate($sTemplate) {
$this->_template = $sTemplate;
}
/**
* Template getter.
* @return string
*/
public function getTemplate() {
return $this->_template;
}
/**
* Renders template by replacing all view variables in template.
* @param string Either full path and name of template file or a template string.
* If not passed, previous set template will be used.
* @throws Exception if no template is set
* @return string
*/
public function render($template = null) {
if ($template == null) {
$template = $this->_template;
}
if ($template == null) {
throw new Exception('Missing template to render.');
}
$oTpl = new Template();
foreach ($this->_oView as $k => $v) {
$oTpl->set('s', strtoupper($k), $v);
}
$oTpl->generate($template, 0, 0);
}
/**
* Returns parameter from request, the order is:
* - Return from $_GET, if found
* - Return from $_POST, if found
*
* @param string $key
* @param mixed $default The default value
* @return mixed
*/
protected function _getParam($key, $default = null) {
if (isset($_GET[$key])) {
return $_GET[$key];
} elseif (isset($_POST[$key])) {
return $_POST[$key];
} else {
return $default;
}
}
/**
* Returns rendered notification markup by using global $notification variable.
* @param string $type One of cGuiNotification::LEVEL_* constants
* @param string $msg The message to display
* @return string
*/
protected function _notifyBox($type, $msg) {
global $notification;
return $notification->returnNotification($type, $msg) . '<br>';
}
}