openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

commit 4476ceabee5ff656a8c5a09535be012726209faf
parent 722259b87d7e4dbf2660e87e82f845cd323f9e5e
Author: Jan Dankert <develop@jandankert.de>
Date:   Sun, 23 Feb 2020 00:03:40 +0100

Refactoring: Namespaces for modules 'logger' and 'language'

Diffstat:
modules/cms-api/API.class.php | 2+-
modules/cms-core/Dispatcher.class.php | 2+-
modules/cms-core/action/Action.class.php | 2+-
modules/cms-core/action/LoginAction.class.php | 2+-
modules/cms-core/action/PageAction.class.php | 2+-
modules/cms-core/action/StartAction.class.php | 2+-
modules/cms-core/auth/IdentAuth.class.php | 1+
modules/cms-core/auth/LdapAuth.class.php | 1+
modules/cms-core/auth/LdapUserDNAuth.class.php | 1+
modules/cms-core/auth/OpenIdAuth.class.php | 1+
modules/cms-core/auth/RememberAuth.class.php | 1+
modules/cms-core/functions/language.inc.php | 1+
modules/cms-core/functions/request.inc.php | 36+++++++++++++++++++-----------------
modules/cms-core/init.php | 3++-
modules/cms-core/model/Acl.class.php | 2+-
modules/cms-core/model/Element.class.php | 2+-
modules/cms-core/model/File.class.php | 2+-
modules/cms-core/model/Language.class.php | 2+-
modules/cms-core/model/Page.class.php | 6+++---
modules/cms-core/model/Pageelement.class.php | 2+-
modules/cms-core/model/Project.class.php | 14+++++++-------
modules/cms-core/model/Value.class.php | 2+-
modules/cms-macros/MacroRunner.class.php | 1+
modules/cms-publish/Ftp.class.php | 1+
modules/cms-publish/PublishPublic.class.php | 2+-
modules/cms-ui/action/IndexAction.class.php | 2+-
modules/database-update/DbUpdate.class.php | 1+
modules/database/Database.class.php | 2+-
modules/database/Sql.class.php | 236++++++++++++++++++++++++++++++++++++++++----------------------------------------
modules/database/driver/PDODriver.class.php | 2+-
modules/language/require.php | 6------
modules/logger/Logger.class.php | 320++++++++++++++++++++++++++++++++++++++++---------------------------------------
modules/logger/require.php | 4----
modules/template_engine/components/html/link/Link.class.php | 2+-
modules/util/Code.class.php | 2+-
modules/util/Http.class.php | 4++--
modules/util/Ldap.class.php | 2+-
modules/wikiparser/renderer/XhtmlRenderer.class.php | 2+-
modules/wikiparser/renderer/fpdf/Pdf.class.php | 3+++
39 files changed, 344 insertions(+), 337 deletions(-)

diff --git a/modules/cms-api/API.class.php b/modules/cms-api/API.class.php @@ -8,7 +8,7 @@ use cms\Dispatcher; use Exception; use util\Http; use JSON; -use Logger; +use logger\Logger; use ObjectNotFoundException; use util\exception\OpenRatException; use util\exception\SecurityException; diff --git a/modules/cms-core/Dispatcher.class.php b/modules/cms-core/Dispatcher.class.php @@ -12,7 +12,7 @@ use ConfigurationLoader; use database\Database; use DbUpdate; use util\Http; -use Logger; +use logger\Logger; use LogicException; use util\exception\OpenRatException; use util\exception\SecurityException; diff --git a/modules/cms-core/action/Action.class.php b/modules/cms-core/action/Action.class.php @@ -20,7 +20,7 @@ namespace cms\action { use cms\model\User; use util\Html; use util\Session; - use \Logger; + use logger\Logger; use util\Http; use util\Text; diff --git a/modules/cms-core/action/LoginAction.class.php b/modules/cms-core/action/LoginAction.class.php @@ -20,7 +20,7 @@ use \DbUpdate; use \Exception; use util\Http; use \InternalAuth; -use \Logger; +use logger\Logger; use \ObjectNotFoundException; use util\exception\OpenRatException; use \security\Password; diff --git a/modules/cms-core/action/PageAction.class.php b/modules/cms-core/action/PageAction.class.php @@ -16,7 +16,7 @@ use cms\publish\PublishPreview; use cms\publish\PublishPublic; use util\Html; use util\Http; -use Logger; +use logger\Logger; use util\Session; diff --git a/modules/cms-core/action/StartAction.class.php b/modules/cms-core/action/StartAction.class.php @@ -14,7 +14,7 @@ use cms\model\Model; use database\Database; use util\Http; -use Logger; +use logger\Logger; use \security\Password; use util\Session; use util\Html; diff --git a/modules/cms-core/auth/IdentAuth.class.php b/modules/cms-core/auth/IdentAuth.class.php @@ -1,5 +1,6 @@ <?php +use logger\Logger; use util\Http; /** diff --git a/modules/cms-core/auth/LdapAuth.class.php b/modules/cms-core/auth/LdapAuth.class.php @@ -1,5 +1,6 @@ <?php +use logger\Logger; use util\Ldap; class LdapAuth implements Auth diff --git a/modules/cms-core/auth/LdapUserDNAuth.class.php b/modules/cms-core/auth/LdapUserDNAuth.class.php @@ -1,5 +1,6 @@ <?php +use logger\Logger; use util\Ldap; /** diff --git a/modules/cms-core/auth/OpenIdAuth.class.php b/modules/cms-core/auth/OpenIdAuth.class.php @@ -1,5 +1,6 @@ <?php +use logger\Logger; use util\Http; diff --git a/modules/cms-core/auth/RememberAuth.class.php b/modules/cms-core/auth/RememberAuth.class.php @@ -2,6 +2,7 @@ use database\Database; use cms\model\User; +use logger\Logger; /** * Authentifizierung mit einem Login-Token. diff --git a/modules/cms-core/functions/language.inc.php b/modules/cms-core/functions/language.inc.php @@ -15,6 +15,7 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +use logger\Logger; /** diff --git a/modules/cms-core/functions/request.inc.php b/modules/cms-core/functions/request.inc.php @@ -1,18 +1,20 @@ -<?php - -// TODO: We should use $_REQUEST everywhere. -$REQ = array_merge($_GET,$_POST); - -// REGISTER_GLOBALS -// This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0. -if ( ini_get('register_globals') ) - Logger::warn("REGISTER_GLOBALS is active. For security reasons: DO NOT USE THIS!"); - -// MAGIC_QUOTES -// This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0. -// always returns FALSE as of PHP 5.4.0. -if ( get_magic_quotes_gpc() == 1 ) - Logger::warn("MAGIC_QUOTES is active. For security reasons: DO NOT USE THIS!"); - - +<?php + +// TODO: We should use $_REQUEST everywhere. +use logger\Logger; + +$REQ = array_merge($_GET,$_POST); + +// REGISTER_GLOBALS +// This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0. +if ( ini_get('register_globals') ) + Logger::warn("REGISTER_GLOBALS is active. For security reasons: DO NOT USE THIS!"); + +// MAGIC_QUOTES +// This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0. +// always returns FALSE as of PHP 5.4.0. +if ( get_magic_quotes_gpc() == 1 ) + Logger::warn("MAGIC_QUOTES is active. For security reasons: DO NOT USE THIS!"); + + ?> \ No newline at end of file diff --git a/modules/cms-core/init.php b/modules/cms-core/init.php @@ -15,6 +15,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +use logger\Logger; use util\exception\ValidationException; define('MIN_VERSION','5.4'); @@ -78,7 +79,7 @@ function fatal_handler() { $errstr = $error["message"]; $message = 'Error '.$errno .' '. $errstr.' in '. $errfile.':'. $errline; - if(class_exists('Logger')) + if(class_exists('logger\Logger')) Logger::error( $message); else { diff --git a/modules/cms-core/model/Acl.class.php b/modules/cms-core/model/Acl.class.php @@ -348,7 +348,7 @@ class Acl extends ModelBase $this->mask += self::ACL_GRANT *intval($this->grant ); $this->mask += self::ACL_TRANSMIT *intval($this->transmit ); - \Logger::trace('mask of acl '.$this->aclid.': '.$this->mask ); + \logger\Logger::trace('mask of acl '.$this->aclid.': '.$this->mask ); return $this->mask; } diff --git a/modules/cms-core/model/Element.class.php b/modules/cms-core/model/Element.class.php @@ -3,7 +3,7 @@ namespace cms\model; use util\ArrayUtils; -use Logger; +use logger\Logger; /** * Diese Objektklasse stellt ein Element das. diff --git a/modules/cms-core/model/File.class.php b/modules/cms-core/model/File.class.php @@ -26,7 +26,7 @@ use cms\publish\PublishPublic; use cms\publish\PublishShow; use util\JSqueeze; use \Less_Parser; -use Logger; +use logger\Logger; use util\cache\FileCache; define('OR_FILE_DEFAULT_MIMETYPE','application/octet-stream'); diff --git a/modules/cms-core/model/Language.class.php b/modules/cms-core/model/Language.class.php @@ -53,7 +53,7 @@ class Language extends ModelBase if ( !$locale_ok ) // Hat nicht geklappt. Entweder ist das Mapping falsch oder die locale ist // nicht korrekt installiert. - \Logger::warn("Could not set locale '$locale', please check with 'locale -a' if it is installaled correctly"); + \logger\Logger::warn("Could not set locale '$locale', please check with 'locale -a' if it is installaled correctly"); } else { diff --git a/modules/cms-core/model/Page.class.php b/modules/cms-core/model/Page.class.php @@ -19,7 +19,7 @@ namespace cms\model; use util\Mustache; use cms\publish\PublishPreview;use cms\publish\PublishPublic; use http\Exception\RuntimeException; -use Logger; +use logger\Logger; use util\cache\FileCache; @@ -337,7 +337,7 @@ SQL if ( !isset($replaceElementMap[$oldElementId]) || intval($replaceElementMap[$oldElementId]) < 1 ) { - \Logger::debug( 'deleting value of elementid '.$oldElementId ); + \logger\Logger::debug( 'deleting value of elementid '.$oldElementId ); $sql = $db->sql('DELETE FROM {{value}}'. ' WHERE pageid={pageid}'. ' AND elementid={elementid}' ); @@ -350,7 +350,7 @@ SQL { $newElementId = intval($replaceElementMap[$oldElementId]); - \Logger::debug( 'updating elementid '.$oldElementId.' -> '.$newElementId ); + \logger\Logger::debug( 'updating elementid '.$oldElementId.' -> '.$newElementId ); $sql = $db->sql('UPDATE {{value}}'. ' SET elementid ={newelementid}'. ' WHERE pageid ={pageid}'. diff --git a/modules/cms-core/model/Pageelement.class.php b/modules/cms-core/model/Pageelement.class.php @@ -18,7 +18,7 @@ namespace cms\model; // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use cms\mustache\Mustache; use cms\publish\PublishPreview;use cms\publish\PublishPublic; -use Logger; +use logger\Logger; use util\cache\FileCache; diff --git a/modules/cms-core/model/Project.class.php b/modules/cms-core/model/Project.class.php @@ -332,7 +332,7 @@ SQL } catch( \Exception $e ) { - \Logger::warn('Project '.$this->projectid.' has not a root folder'."\n".$e->getTraceAsString()); + \logger\Logger::warn('Project '.$this->projectid.' has not a root folder'."\n".$e->getTraceAsString()); } } @@ -564,7 +564,7 @@ EOF if ( count( $idList ) > 1 ) { - \Logger::warn('Inconsistence found: Reference circle project<->template<->templatemodel<->projectmodel<->project is not consistent.'); + \logger\Logger::warn('Inconsistence found: Reference circle project<->template<->templatemodel<->projectmodel<->project is not consistent.'); $this->log[] = 'Inconsistence found: Reference circle project<->template<->templatemodel<->projectmodel<->project is not consistent.'; } @@ -599,7 +599,7 @@ EOF */ public function copy( $dbid_destination,$name='' ) { - \Logger::debug( 'Copying project '.$this->name.' to database '.$dbid_destination ); + \logger\Logger::debug( 'Copying project '.$this->name.' to database '.$dbid_destination ); global $conf; $zeit = date('Y-m-d\TH:i:sO'); @@ -680,7 +680,7 @@ EOF foreach( $ids as $tabelle=>$data ) { - \Logger::debug( 'Copying table '.$tabelle.' ...' ); + \logger\Logger::debug( 'Copying table '.$tabelle.' ...' ); $mapping[$tabelle] = array(); $idcolumn = $data['primary_key']; @@ -706,7 +706,7 @@ EOF foreach( $stmt->getCol() as $srcid ) { - \Logger::debug('Id '.$srcid.' of table '.$tabelle); + \logger\Logger::debug('Id '.$srcid.' of table '.$tabelle); $mapping[$tabelle][$srcid] = ++$nextid; $stmt = $db_src->sql( 'SELECT * FROM {t_'.$tabelle.'} WHERE id={id}'); @@ -719,7 +719,7 @@ EOF // Fremdschl�sselbeziehungen auf neue IDn korrigieren. foreach( $data['foreign_keys'] as $fkey_column=>$target_tabelle) { - \Logger::debug($fkey_column.' '.$target_tabelle.' '.$row[$fkey_column]); + \logger\Logger::debug($fkey_column.' '.$target_tabelle.' '.$row[$fkey_column]); if ( intval($row[$fkey_column]) != 0 ) $row[$fkey_column] = $mapping[$target_tabelle][$row[$fkey_column]]; @@ -793,7 +793,7 @@ EOF } } - \Logger::debug( 'Finished copying project' ); + \logger\Logger::debug( 'Finished copying project' ); $db_dest->commit(); } diff --git a/modules/cms-core/model/Value.class.php b/modules/cms-core/model/Value.class.php @@ -4,7 +4,7 @@ use util\ArrayUtils; use cms\publish\Publish; use MacroRunner; use \ObjectNotFoundException; -use \Logger; +use logger\Logger; use util\Text; use util\Html; use util\Http; diff --git a/modules/cms-macros/MacroRunner.class.php b/modules/cms-macros/MacroRunner.class.php @@ -4,6 +4,7 @@ use cms\model\Element; use cms\model\Template; use cms\model\Value; +use logger\Logger; use util\ArrayUtils; use util\exception\OpenRatException; use util\VariableResolver; diff --git a/modules/cms-publish/Ftp.class.php b/modules/cms-publish/Ftp.class.php @@ -15,6 +15,7 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +use logger\Logger; use util\exception\OpenRatException; diff --git a/modules/cms-publish/PublishPublic.class.php b/modules/cms-publish/PublishPublic.class.php @@ -11,7 +11,7 @@ use cms\model\Project; use cms\model\Url; use util\FileUtils; use Ftp; -use Logger; +use logger\Logger; use util\exception\OpenRatException; use util\Session; diff --git a/modules/cms-ui/action/IndexAction.class.php b/modules/cms-ui/action/IndexAction.class.php @@ -11,7 +11,7 @@ use Exception; use JSON; use util\JSqueeze; use \Less_Parser; -use Logger; +use logger\Logger; use util\UIUtils; use ObjectNotFoundException; use util\Session; diff --git a/modules/database-update/DbUpdate.class.php b/modules/database-update/DbUpdate.class.php @@ -1,6 +1,7 @@ <?php use database\Database; +use logger\Logger; class DbUpdate diff --git a/modules/database/Database.class.php b/modules/database/Database.class.php @@ -18,7 +18,7 @@ namespace database; use database\driver\PDODriver; -use Logger; +use logger\Logger; use RuntimeException; /** diff --git a/modules/database/Sql.class.php b/modules/database/Sql.class.php @@ -1,119 +1,119 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2006 Jan Dankert, jandankert@jandankert.de -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -namespace database; -use Logger; -use LogicException; - -/** - * SQL-Anweisung.<br> - * <br> - * Darstellen eines SQL-Statements incl. Methoden zum Fuellen von - * Platzhaltern im SQL-Befehl.<br> - * <br> - * Beispiel<br> - * <pre> - * // Neues Objekt erzeugen mit SQL-Anweisung - * $stmt = $db->sql('SELECT * FROM xy WHERE id={uid} AND name={name}'); - * - * // Parameter f�llen - * $stmt->setInt ('uid' ,1 ); - * $stmt->setString('name','peter'); - * - * // Fertige SQL-Anweisung verwenden - * $stmt->execute(); - * </pre> - * <br> - * Ziele dieser Klasse sind:<br> - * - Schreiben einfacher SQL-Anweisungen ohne Stringverarbeitung<br> - * - Verhindern von SQL-Injection.<br> - * <br> - * - * @author Jan Dankert, $Author$ - * @version $Revision$ - * @package openrat.services - */ - -class Sql -{ - /** - * SQL-Anweisung. - * @type string - */ - var $query; - - /** - * Ein 1-dimensionales Array mit den Positionen der Parameter.<br> - * <br> - * Beispiel:<br> - * <pre> - * - * Array - * ( - * [lid] => 16 - * [oid] => 24 - * ) - * </pre> - */ - public $param = array(); - - - /** - * Erzeugt ein SQL-Objekt und analysiert die SQL-Anfrage. - * @param string $query SQL-Query - */ - public function __construct( $query = '' ) - { - $this->parseSourceQuery( $query ); - } - - - /** - * Die SQL-Anfrage wird auf Parameter untersucht. - */ - private function parseSourceQuery( $query ) - { - Logger::trace( "SQL-query:\n$query" ); - - while( true ) // Schleife wird solange durchlaufen, solange Parameter gefunden werden. - { - $posKlLinks = strpos($query,'{'); - $posKlRechts = strpos($query,'}'); - - if ( $posKlLinks === false || $posKlRechts === false ) - break; // Schleife abbrechen, wenn kein Parameter mehr gefunden wird. - - $nameParam = substr($query,$posKlLinks+1,$posKlRechts-$posKlLinks-1); // Name Parameter - - if ( isset($this->param[$nameParam ])) - throw new LogicException( "The named parameter '$nameParam'' is used more than one time in the SQL query:\n$query" ); - - $this->param[$nameParam] = $posKlLinks; - - $query = substr($query,0,$posKlLinks).substr($query,$posKlRechts+1); - } - - $this->query = $query; - - } - - -} - - +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2006 Jan Dankert, jandankert@jandankert.de +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +namespace database; +use logger\Logger; +use LogicException; + +/** + * SQL-Anweisung.<br> + * <br> + * Darstellen eines SQL-Statements incl. Methoden zum Fuellen von + * Platzhaltern im SQL-Befehl.<br> + * <br> + * Beispiel<br> + * <pre> + * // Neues Objekt erzeugen mit SQL-Anweisung + * $stmt = $db->sql('SELECT * FROM xy WHERE id={uid} AND name={name}'); + * + * // Parameter f�llen + * $stmt->setInt ('uid' ,1 ); + * $stmt->setString('name','peter'); + * + * // Fertige SQL-Anweisung verwenden + * $stmt->execute(); + * </pre> + * <br> + * Ziele dieser Klasse sind:<br> + * - Schreiben einfacher SQL-Anweisungen ohne Stringverarbeitung<br> + * - Verhindern von SQL-Injection.<br> + * <br> + * + * @author Jan Dankert, $Author$ + * @version $Revision$ + * @package openrat.services + */ + +class Sql +{ + /** + * SQL-Anweisung. + * @type string + */ + var $query; + + /** + * Ein 1-dimensionales Array mit den Positionen der Parameter.<br> + * <br> + * Beispiel:<br> + * <pre> + * + * Array + * ( + * [lid] => 16 + * [oid] => 24 + * ) + * </pre> + */ + public $param = array(); + + + /** + * Erzeugt ein SQL-Objekt und analysiert die SQL-Anfrage. + * @param string $query SQL-Query + */ + public function __construct( $query = '' ) + { + $this->parseSourceQuery( $query ); + } + + + /** + * Die SQL-Anfrage wird auf Parameter untersucht. + */ + private function parseSourceQuery( $query ) + { + Logger::trace( "SQL-query:\n$query" ); + + while( true ) // Schleife wird solange durchlaufen, solange Parameter gefunden werden. + { + $posKlLinks = strpos($query,'{'); + $posKlRechts = strpos($query,'}'); + + if ( $posKlLinks === false || $posKlRechts === false ) + break; // Schleife abbrechen, wenn kein Parameter mehr gefunden wird. + + $nameParam = substr($query,$posKlLinks+1,$posKlRechts-$posKlLinks-1); // Name Parameter + + if ( isset($this->param[$nameParam ])) + throw new LogicException( "The named parameter '$nameParam'' is used more than one time in the SQL query:\n$query" ); + + $this->param[$nameParam] = $posKlLinks; + + $query = substr($query,0,$posKlLinks).substr($query,$posKlRechts+1); + } + + $this->query = $query; + + } + + +} + + ?> \ No newline at end of file diff --git a/modules/database/driver/PDODriver.class.php b/modules/database/driver/PDODriver.class.php @@ -21,7 +21,7 @@ namespace database\driver; use database\Sql; -use \Logger; +use logger\Logger; use \PDO; use \PDOException; use PDOStatement; diff --git a/modules/language/require.php b/modules/language/require.php @@ -1,7 +1,2 @@ <?php -include(__DIR__ . "/Language.class.php"); -include(__DIR__ . '/../util/Spyc.class.php'); - - -?>- \ No newline at end of file diff --git a/modules/logger/Logger.class.php b/modules/logger/Logger.class.php @@ -1,160 +1,162 @@ -<?php - - -define('LOGGER_LOG_TRACE', 5); -define('LOGGER_LOG_DEBUG', 4); -define('LOGGER_LOG_INFO', 3); -define('LOGGER_LOG_WARN', 2); -define('LOGGER_LOG_ERROR', 1); - -/** - * Schreiben eines Eintrages in die Logdatei. - * - * @author Jan Dankert - */ -class Logger -{ - public static $level = LOGGER_LOG_ERROR; - public static $filename = null; - - public static $messageFormat = '%time %level %host %text'; - public static $dateFormat = 'M j H:i:s'; - public static $nsLookup = false; - public static $messageCallback; - - public static function init() - { - - } - - - /** - * Schreiben einer Trace-Meldung in die Logdatei - * - * @param string message Log-Text - */ - public static function trace($message) - { - if (Logger::$level >= LOGGER_LOG_TRACE) - Logger::doLog(LOGGER_LOG_TRACE, $message); - } - - - /** - * Schreiben einer Debug-Meldung in die Logdatei - * - * @param string message Log-Text - */ - public static function debug($message) - { - if (Logger::$level >= LOGGER_LOG_DEBUG) - Logger::doLog(LOGGER_LOG_DEBUG, $message); - } - - - /** - * Schreiben einer Information in die Logdatei - * - * @param string message Log-Text - */ - public static function info($message) - { - if (Logger::$level >= LOGGER_LOG_INFO) - Logger::doLog(LOGGER_LOG_INFO, $message); - } - - - /** - * Schreiben einer Warnung in die Logdatei - * - * @param string message Log-Text - */ - public static function warn($message) - { - if (Logger::$level >= LOGGER_LOG_WARN) - Logger::doLog(LOGGER_LOG_WARN, $message); - } - - - /** - * Schreiben einer normalen Fehlermeldung in die Logdatei - * - * @param string message Log-Text - */ - public static function error($message) - { - if (Logger::$level >= LOGGER_LOG_ERROR) - Logger::doLog(LOGGER_LOG_ERROR, $message); - } - - - /** - * Schreiben der Meldung in die Logdatei - * - * @param string facility Schwere dieses Logdatei-Eintrages (z.B. warning) - * @param string message Log-Text - * @access private - */ - private static function doLog($facility, $message) - { - if ($facility == LOGGER_LOG_ERROR) - $thisLevel = 'ERROR'; - elseif ($facility == LOGGER_LOG_WARN) - $thisLevel = 'WARN'; - elseif ($facility == LOGGER_LOG_INFO) - $thisLevel = 'INFO'; - elseif ($facility == LOGGER_LOG_DEBUG) - $thisLevel = 'DEBUG'; - elseif ($facility == LOGGER_LOG_TRACE) - $thisLevel = 'TRACE'; - - - // Ersetzen von Variablen - if (Logger::$nsLookup) - $vars['host'] = gethostbyaddr(getenv('REMOTE_ADDR')); - else - $vars['host'] = getenv('REMOTE_ADDR'); - - if (isset(Logger::$messageCallback)) - { - $cb = Logger::$messageCallback; - $vars += $cb(); - } - - $vars['level'] = str_pad($thisLevel, 5); - $vars['agent'] = getenv('HTTP_USER_AGENT'); - $vars['time'] = date(Logger::$dateFormat); - if ( $message instanceof Exception ) - $message = $message->getTraceAsString(); - $vars['text'] = $message; - - $text = Logger::$messageFormat; - - // Variablen ersetzen. - foreach ($vars as $key => $value) { - $text = str_replace('%' . $key, $value,$text); - } - - // Mehrzeilige Meldungen werden um 1 Spalte eingerueckt, um sie maschinell - // erkennen und auswerten zu koennen. - $text = str_replace("\n", "\n ", $text); - - if (isset(Logger::$filename)) { - - if (!is_writable(Logger::$filename)) { - - error_log('logfile ' . Logger::$filename . ' is not writable'); - error_log($text . "\n"); - } else { - // Schreiben in Logdatei - error_log($text . "\n", 3, Logger::$filename); - } - } - - // ERROR- und WARN-Meldungen immer zusätzlich in das Error-Log schreiben. - if (Logger::$level <= LOGGER_LOG_WARN) - error_log($text . "\n"); - } -} - +<?php + + +namespace logger; +use Exception; + +define('LOGGER_LOG_TRACE', 5); +define('LOGGER_LOG_DEBUG', 4); +define('LOGGER_LOG_INFO', 3); +define('LOGGER_LOG_WARN', 2); +define('LOGGER_LOG_ERROR', 1); + +/** + * Schreiben eines Eintrages in die Logdatei. + * + * @author Jan Dankert + */ +class Logger +{ + public static $level = LOGGER_LOG_ERROR; + public static $filename = null; + + public static $messageFormat = '%time %level %host %text'; + public static $dateFormat = 'M j H:i:s'; + public static $nsLookup = false; + public static $messageCallback; + + public static function init() + { + + } + + + /** + * Schreiben einer Trace-Meldung in die Logdatei + * + * @param string message Log-Text + */ + public static function trace($message) + { + if (Logger::$level >= LOGGER_LOG_TRACE) + Logger::doLog(LOGGER_LOG_TRACE, $message); + } + + + /** + * Schreiben einer Debug-Meldung in die Logdatei + * + * @param string message Log-Text + */ + public static function debug($message) + { + if (Logger::$level >= LOGGER_LOG_DEBUG) + Logger::doLog(LOGGER_LOG_DEBUG, $message); + } + + + /** + * Schreiben einer Information in die Logdatei + * + * @param string message Log-Text + */ + public static function info($message) + { + if (Logger::$level >= LOGGER_LOG_INFO) + Logger::doLog(LOGGER_LOG_INFO, $message); + } + + + /** + * Schreiben einer Warnung in die Logdatei + * + * @param string message Log-Text + */ + public static function warn($message) + { + if (Logger::$level >= LOGGER_LOG_WARN) + Logger::doLog(LOGGER_LOG_WARN, $message); + } + + + /** + * Schreiben einer normalen Fehlermeldung in die Logdatei + * + * @param string message Log-Text + */ + public static function error($message) + { + if (Logger::$level >= LOGGER_LOG_ERROR) + Logger::doLog(LOGGER_LOG_ERROR, $message); + } + + + /** + * Schreiben der Meldung in die Logdatei + * + * @param string facility Schwere dieses Logdatei-Eintrages (z.B. warning) + * @param string message Log-Text + * @access private + */ + private static function doLog($facility, $message) + { + if ($facility == LOGGER_LOG_ERROR) + $thisLevel = 'ERROR'; + elseif ($facility == LOGGER_LOG_WARN) + $thisLevel = 'WARN'; + elseif ($facility == LOGGER_LOG_INFO) + $thisLevel = 'INFO'; + elseif ($facility == LOGGER_LOG_DEBUG) + $thisLevel = 'DEBUG'; + elseif ($facility == LOGGER_LOG_TRACE) + $thisLevel = 'TRACE'; + + + // Ersetzen von Variablen + if (Logger::$nsLookup) + $vars['host'] = gethostbyaddr(getenv('REMOTE_ADDR')); + else + $vars['host'] = getenv('REMOTE_ADDR'); + + if (isset(Logger::$messageCallback)) { + $cb = Logger::$messageCallback; + $vars += $cb(); + } + + $vars['level'] = str_pad($thisLevel, 5); + $vars['agent'] = getenv('HTTP_USER_AGENT'); + $vars['time'] = date(Logger::$dateFormat); + if ($message instanceof Exception) + $message = $message->getTraceAsString(); + $vars['text'] = $message; + + $text = Logger::$messageFormat; + + // Variablen ersetzen. + foreach ($vars as $key => $value) { + $text = str_replace('%' . $key, $value, $text); + } + + // Mehrzeilige Meldungen werden um 1 Spalte eingerueckt, um sie maschinell + // erkennen und auswerten zu koennen. + $text = str_replace("\n", "\n ", $text); + + if (isset(Logger::$filename)) { + + if (!is_writable(Logger::$filename)) { + + error_log('logfile ' . Logger::$filename . ' is not writable'); + error_log($text . "\n"); + } else { + // Schreiben in Logdatei + error_log($text . "\n", 3, Logger::$filename); + } + } + + // ERROR- und WARN-Meldungen immer zusätzlich in das Error-Log schreiben. + if (Logger::$level <= LOGGER_LOG_WARN) + error_log($text . "\n"); + } +} + ?> \ No newline at end of file diff --git a/modules/logger/require.php b/modules/logger/require.php @@ -1,5 +1,2 @@ <?php -include( __DIR__.'/Logger.class.php'); - -?>- \ No newline at end of file diff --git a/modules/template_engine/components/html/link/Link.class.php b/modules/template_engine/components/html/link/Link.class.php @@ -2,7 +2,7 @@ namespace template_engine\components; -use Html; +use util\Html; use JSON; use template_engine\components\html\Component; use template_engine\element\CMSElement; diff --git a/modules/util/Code.class.php b/modules/util/Code.class.php @@ -18,7 +18,7 @@ namespace util; use util\FileUtils; -use Logger; +use logger\Logger; use util\Macro; /** diff --git a/modules/util/Http.class.php b/modules/util/Http.class.php @@ -18,7 +18,7 @@ namespace util; -use Logger; +use logger\Logger; use withPraefixQuestionMark; /** @@ -399,7 +399,7 @@ class Http $db->rollback(); } - if (class_exists('Logger')) + if (class_exists('logger\Logger')) Logger::warn($message . "\n" . $reason); Http::sendStatus(501, 'Internal Server Error', $message, $reason); diff --git a/modules/util/Ldap.class.php b/modules/util/Ldap.class.php @@ -17,7 +17,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. namespace util; -use Logger; +use logger\Logger; use LogicException; use RuntimeException; diff --git a/modules/wikiparser/renderer/XhtmlRenderer.class.php b/modules/wikiparser/renderer/XhtmlRenderer.class.php @@ -8,7 +8,7 @@ use File; use Geshi; use wikiparser\model\LineBreakElement; use wikiparser\model\LinkElement; -use Logger; +use logger\Logger; use wikiparser\model\RawElement; use util\Text; use wikiparser\model\TextElement; diff --git a/modules/wikiparser/renderer/fpdf/Pdf.class.php b/modules/wikiparser/renderer/fpdf/Pdf.class.php @@ -3,6 +3,9 @@ /* * */ + +use logger\Logger; + class Pdf extends FPDF { /*