init files
Dieser Commit ist enthalten in:
Ursprung
d41e3b5158
Commit
16ad56ae48
41 geänderte Dateien mit 8754 neuen und 0 gelöschten Zeilen
426
classes/controller/class.modrewrite_content_controller.php
Normale Datei
426
classes/controller/class.modrewrite_content_controller.php
Normale Datei
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
143
classes/controller/class.modrewrite_contentexpert_controller.php
Normale Datei
143
classes/controller/class.modrewrite_contentexpert_controller.php
Normale Datei
|
|
@ -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ü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ückgesetzt');
|
||||
}
|
||||
|
||||
}
|
||||
176
classes/controller/class.modrewrite_contenttest_controller.php
Normale Datei
176
classes/controller/class.modrewrite_contenttest_controller.php
Normale Datei
|
|
@ -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 -> ' . $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;
|
||||
}
|
||||
|
||||
}
|
||||
226
classes/controller/class.modrewrite_controller_abstract.php
Normale Datei
226
classes/controller/class.modrewrite_controller_abstract.php
Normale Datei
|
|
@ -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>';
|
||||
}
|
||||
|
||||
}
|
||||
Laden …
Tabelle hinzufügen
Einen Link hinzufügen
In neuem Issue referenzieren