openrat-cms

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

commit 81489403d99f65c06a79cff6986d5ffe412faa9d
parent 64debe61654f6503252029b5e3df442e744f6253
Author: Jan Dankert <develop@jandankert.de>
Date:   Sat, 26 Sep 2020 01:41:20 +0200

Refactoring: Removing old require.php files. With class autoloading, they are not necessary any more.

Diffstat:
api/index.php | 4+++-
index.php | 4+++-
modules/cms/Dispatcher.class.php | 5++---
modules/cms/action/TreeAction.class.php | 3++-
modules/cms/api/API.class.php | 2+-
modules/cms/api/require.php | 5-----
modules/cms/base/Common.class.php | 178+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
modules/cms/base/Configuration.class.php | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
modules/cms/base/Language.class.php | 178+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
modules/cms/base/Startup.class.php | 153+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
modules/cms/base/functions/.htaccess | 3---
modules/cms/base/functions/common.inc.php | 179-------------------------------------------------------------------------------
modules/cms/base/functions/language.inc.php | 183-------------------------------------------------------------------------------
modules/cms/base/functions/request.inc.php | 21---------------------
modules/cms/base/init.php | 102-------------------------------------------------------------------------------
modules/cms/base/require.php | 16----------------
modules/cms/generator/filter/LessFilter.class.php | 4++--
modules/cms/macros/macro/SearchIndex.class.php | 2+-
modules/cms/macros/require.php | 1-
modules/cms/ui/UI.class.php | 117-------------------------------------------------------------------------------
modules/cms/ui/action/IndexAction.class.php | 8+++-----
modules/cms/ui/themes/ThemeCompiler.class.php | 6+++---
modules/configuration/configuration.php | 50--------------------------------------------------
modules/configuration/require.php | 3---
modules/editor/codemirror/require.php | 6------
modules/language/require.php | 2--
modules/logger/Logger.class.php | 3++-
modules/logger/require.php | 2--
modules/security/require.php | 2--
modules/template_engine/TemplateCompiler.php | 1-
modules/template_engine/components/html/link/Link.class.php | 3+--
modules/template_engine/require.php | 2--
modules/util/Less.class.php | 41+++++++++++++++++++++++++++++++++++++++++
modules/util/json/JSON.class.php | 22++++++++++++++++++++++
modules/util/require.php | 5-----
modules/wikiparser/require.php | 4----
36 files changed, 658 insertions(+), 725 deletions(-)

diff --git a/api/index.php b/api/index.php @@ -2,10 +2,12 @@ // Excecuting the CMS application programming interface (API) require('../modules/autoload.php'); -require('../modules/cms/base/require.php'); require('../modules/cms/ui/require.php'); use cms\api\API; +use cms\base\Startup; + +Startup::initialize(); try { // Cookie-Path: Actual path without '/api'. diff --git a/index.php b/index.php @@ -1,11 +1,13 @@ <?php // Excecuting the CMS user interface (UI) require('modules/autoload.php'); -require('modules/cms/base/require.php'); require('modules/cms/ui/require.php'); +use cms\base\Startup; use cms\ui\UI; +Startup::initialize(); + try { UI::execute(); diff --git a/modules/cms/Dispatcher.class.php b/modules/cms/Dispatcher.class.php @@ -17,6 +17,7 @@ use logger\Logger; use LogicException; use util\exception\UIException; use util\exception\SecurityException; +use util\json\JSON; use util\Session; @@ -50,8 +51,6 @@ class Dispatcher global $conf; $conf = Session::getConfig(); - require_once(__DIR__.'/../configuration/configuration.php'); - define('PRODUCTION', Conf()->is('production',true)); define('DEVELOPMENT', !PRODUCTION); @@ -544,7 +543,7 @@ class Dispatcher $date = explode(" ",$micro_date); $filename = $dir.'/'.$auditConfig->get('prefix','audit' ).'-'.date('c',$date[1]).'-'.$date[0].'.json'; - $json = new \JSON(); + $json = new JSON(); $user = Session::getUser(); $data = array( diff --git a/modules/cms/action/TreeAction.class.php b/modules/cms/action/TreeAction.class.php @@ -12,6 +12,7 @@ use cms\model\Project; use cms\model\Template; use cms\model\User; use cms\model\Value; +use util\json\JSON; use util\Tree; use cms\model\Language; use cms\model\Model; @@ -279,7 +280,7 @@ class TreeAction extends BaseAction private function outputTreeBranch($branch ) { - $json = new \JSON(); + $json = new JSON(); echo '<ul class="or-navtree-list">'; foreach( $branch as $b ) diff --git a/modules/cms/api/API.class.php b/modules/cms/api/API.class.php @@ -7,11 +7,11 @@ use cms\action\RequestParams; use cms\Dispatcher; use Exception; use util\Http; -use JSON; use logger\Logger; use ObjectNotFoundException; use util\exception\UIException; use util\exception\SecurityException; +use util\json\JSON; use util\XML; define('CMS_API_REQ_PARAM_SUBACTION', 'subaction'); diff --git a/modules/cms/api/require.php b/modules/cms/api/require.php @@ -1,5 +0,0 @@ -<?php - -require_once(__DIR__ . "/../base/require.php"); - -require_once(__DIR__ . "/API.class.php"); diff --git a/modules/cms/base/Common.class.php b/modules/cms/base/Common.class.php @@ -0,0 +1,177 @@ +<?php + + +use util\Session; + +class Common +{ + + public static function registerFunctions() + { + + /** + * F�gt einen Slash ("/") an das Ende an, sofern nicht bereits vorhanden. + * + * @param String $pfad + * @return Pfad mit angeh�ngtem Slash. + */ + function slashify($pfad) + { + if (substr($pfad, -1, 1) == '/') + return $pfad; + else + return $pfad . '/'; + } + + function convertToXmlAttribute($value) + { + return utf8_encode(htmlspecialchars($value)); + } + + + /** + * Ermittelt die aktuelle Systemzeit als Unix-Timestamp.<br> + * Unix-Timestamp ist immer bezogen auf GMT. + * - + * @return Unix-Timestamp der aktuellen Zeit + */ + function now() + { + return time(); + } + + + /** + * Erzeugt f�r eine Zahl eine Schreibweise mit Vorzeichen.<br> + * '-2' bleibt '-2'<br> + * '2' wird zu '+2'<br> + */ + function vorzeichen($nr) + { + return intval($nr) < 0 ? $nr : '+' . $nr; + } + + + /** + * Stellt fest, ob das System in einem schreibgeschuetzten Zustand ist. + * + * @return boolean true, falls schreibgeschuetzt, sonst false + */ + function readonly() + { + // Gesamtes CMS ist readonly. + if (config('security', 'readonly')) + return true; + + // Aktuelle Datenbankverbindung ist readonly. + $db = db(); + if (isset($db->conf['readonly']) && $db->conf['readonly']) + return true; + + return false; + } + + + /** + * Generiert aus der Session-Id einen Token. + * @return Token + */ + function token() + { + return substr(session_id(), -10); + } + + + /** + * Ermittelt, ob der Wert 'true' oder 'false' entspricht. + * + * Anders als beim PHP-Cast auf boolean wird hier auch die + * Zeichenkette 'true' als wahr betrachtet. + * + * @param val mixed + * @return boolean + */ + function istrue($val) + { + if (is_bool($val)) + return $val; + elseif (is_numeric($val)) + return $val != 0; + elseif (is_string($val)) + return $val == 'true' || $val == 'yes' || $val == '1'; + else + return false; + } + + + /** + * Erzeugt einen Link auf die OpenRat-lokale CSS-Datei + * @param $name Name der Style-Konfiguration. Default: 'default'. + */ + function css_link($name = 'default') + { + global $conf; + + // Falls Style-Konfiguration unbekannt, dann Fallback auf default. + if (!isset($conf['style'][$name])) + $name = $conf['interface']['style']['default']; + + + return encode_array($conf['style'][$name]); + } + + + /** + * Encodiert ein Array für eine URL. + * + * @param $args URL-Parameter + */ + function encode_array($args) + { + if (!is_array($args)) + return ''; + + $out = array(); + + foreach ($args as $name => $value) + $out[] = $name . '=' . urlencode($value); + + return implode('&', $out); + } + + + function not($var) + { + return !$var; + } + + /** + * Liefert die Datenbankverbindung fuer die aktuelle Sitzung. + * + * @return \database\Database + * @deprecated use db() + */ + function db_connection() + { + + return db(); + } + + /** + * Liefert die Datenbankverbindung fuer die aktuelle Sitzung. + * + * @return \database\Database + */ + function db() + { + + $db = Session::getDatabase(); + + if (!is_object($db)) + throw new RuntimeException('no database available'); + + return $db; + } + } + +}+ \ No newline at end of file diff --git a/modules/cms/base/Configuration.class.php b/modules/cms/base/Configuration.class.php @@ -0,0 +1,63 @@ +<?php + + + + +use configuration\Config; + +class Configuration { + + public static function registerFunctions() + { + + + /* + * Liest einen Schluessel aus der Konfiguration + * + * @return String, leer falls Schluessel nicht vorhanden + */ + function config($part1 = null, $part2 = null, $part3 = null, $part4 = null) + { + global $conf; + + if ($part1 == null) + return new configuration\Config($conf); + + if ($part2 == null) + if (isset($conf[$part1])) + return $conf[$part1]; + else + return ''; + + if ($part3 == null) + if (isset($conf[$part1][$part2])) + return $conf[$part1][$part2]; + else + return ''; + + if ($part4 == null) + if (isset($conf[$part1][$part2][$part3])) + return $conf[$part1][$part2][$part3]; + else + return ''; + + if (isset($conf[$part1][$part2][$part3][$part4])) + return $conf[$part1][$part2][$part3][$part4]; + else + return ''; + } + + + /** + * @return Config + */ + function Conf() + { + + global $conf; + return new Config($conf); + + } + + } +} diff --git a/modules/cms/base/Language.class.php b/modules/cms/base/Language.class.php @@ -0,0 +1,177 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2012 Jan Dankert, cms@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. + +use logger\Logger; +use util\text\variables\VariableResolver; + +class Language +{ + public static function registerFunctions() + { + + /** + * Diese Funktion stellt ein Wort in der eingestellten + * Sprache zur Verfuegung. + * + * @var String Name der Sprachvariablen + * @var Array Liste (Assoziatives Array) von Variablen + * + * @package openrat.functions + */ + function lang($textVar, $vars = array()) + { + global $conf; + $lang = $conf['language']; + + $text = strtoupper($textVar); + + // Abfrage, ob Textvariable vorhanden ist + if (isset($lang[$text])) { + $text = $lang[$text]; + + // Fill in variables + if ($vars) { + $resolver = new VariableResolver(); + + // Resolve variable + $resolver->addDefaultResolver(function ($var) use ($vars) { + return @$vars[$var]; + }); + + $text = $resolver->resolveVariables($text); + } + + return $text; + } + + // Wenn Textvariable nicht vorhanden ist, dann als letzten Ausweg nur den Variablennamen zurueckgeben + Logger::warn('Message-Key not found: ' . $textVar); + return ('?' . $textVar . '?'); + } + + + /** + * Diese Funktion stellt ein Wort in der eingestellten + * Sprache zur Verfuegung. Sonderzeichen werden als HTML maskiert. + * + * @param $key + * @return unknown_type + * @package openrat.functions + * @var String Name der Sprachvariablen + * @var Array Liste (Assoziatives Array) von Variablen + * + */ + function langHtml($key, $vars = array()) + { + + return encodeHtml(lang($key, $vars)); + } + + /** + * Ersetzt alle Zeichen mit dem Ordinalwert > 127 mit einer HTML-Maskierung. + * + * @return String + */ + function encodeHtml($text) + { + return translateutf8tohtml($text); + } + + function escapeHtml($text) + { + return translateutf8tohtml(htmlentities($text)); + } + + + // Source: http://de.php.net/manual/de/function.htmlentities.php#96648 + // Thx to silverbeat! + // When using UTF-8 as a charset, htmlentities will only convert 1-byte and 2-byte characters. + // Use this function if you also want to convert 3-byte and 4-byte characters: + // converts a UTF8-string into HTML entities + function translateutf8tohtml($txt) + { + //$txt = html_entity_decode($txt); + $txt2 = ''; + for ($i = 0; $i < strlen($txt); $i++) { + $o = ord($txt{$i}); + if ($o < 128) { + // 0..127: raw + $txt2 .= $txt{$i}; + } else { + $o1 = 0; + $o2 = 0; + $o3 = 0; + if ($i < strlen($txt) - 1) $o1 = ord($txt{$i + 1}); + if ($i < strlen($txt) - 2) $o2 = ord($txt{$i + 2}); + if ($i < strlen($txt) - 3) $o3 = ord($txt{$i + 3}); + $hexval = 0; + if ($o >= 0xc0 && $o < 0xc2) { + // INVALID --- should never occur: 2-byte UTF-8 although value < 128 + $hexval = $o1; + $i++; + } elseif ($o >= 0xc2 && $o < 0xe0 && $o1 >= 0x80) { + // 194..223: 2-byte UTF-8 + $hexval |= ($o & 0x1f) << 6; // 1. byte: five bits of 1. char + $hexval |= ($o1 & 0x3f); // 2. byte: six bits of 2. char + $i++; + } elseif ($o >= 0xe0 && $o < 0xf0 && $o1 >= 0x80 && $o2 >= 0x80) { + // 224..239: 3-byte UTF-8 + $hexval |= ($o & 0x0f) << 12; // 1. byte: four bits of 1. char + $hexval |= ($o1 & 0x3f) << 6; // 2.+3. byte: six bits of 2.+3. char + $hexval |= ($o2 & 0x3f); + $i += 2; + } elseif ($o >= 0xf0 && $o < 0xf4 && $o1 >= 0x80) { + // 240..244: 4-byte UTF-8 + $hexval |= ($o & 0x07) << 18; // 1. byte: three bits of 1. char + $hexval |= ($o1 & 0x3f) << 12; // 2.-4. byte: six bits of 2.-4. char + $hexval |= ($o2 & 0x3f) << 6; + $hexval |= ($o3 & 0x3f); + $i += 3; + } else { + // don't know ... just encode + $hexval = $o; + } + $hexstring = dechex($hexval); + if (strlen($hexstring) % 2) $hexstring = '0' . $hexstring; + $txt2 .= '&#x' . $hexstring . ';'; + } + } + $result = $txt2; + + return $result; + } + + + /** + * Diese Funktion prueft, ob ein Sprachelement vorhanden ist + * + * @var String Name der Sprachvariablen + * + * @package openrat.functions + */ + function hasLang($text) + { + $text = strtoupper($text); + + global $conf; + $lang = $conf['language']; + + return isset($lang[$text]); + } + } +}+ \ No newline at end of file diff --git a/modules/cms/base/Startup.class.php b/modules/cms/base/Startup.class.php @@ -0,0 +1,153 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2009 Jan Dankert, cms@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; version 2. +// +// 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 cms\base; + +use ErrorException; +use logger\Logger; +use util\exception\ValidationException; + +class Startup { + + const MIN_VERSION = '5.4'; + + /** + * Initialize. + */ + public static function initialize() + { + self::checkPHPVersion(); + self::securityCheck(); + self::setErrorHandler(); + self::setConstants(); + self::createRequest(); + + require __DIR__.'/Language.class.php'; + require __DIR__.'/Common.class.php'; + require __DIR__.'/Configuration.class.php'; + \Language::registerFunctions(); + \Common::registerFunctions(); + \Configuration::registerFunctions(); + } + + public static function checkPHPVersion() + { + if (version_compare(phpversion(), self::MIN_VERSION, "<")) + throw new ErrorException('This version of PHP ' . phpversion() . ' is not supported any more. Minimum required: ' . self::MIN_VERSION); + } + + + public static function setConstants() { + + define('PHP_EXT', 'php'); + + define('IMG_EXT', '.gif'); + define('IMG_ICON_EXT', '.png'); + + require(__DIR__ . '/version.php'); + define('OR_TITLE', 'OpenRat CMS'); + + define('CMS_ROOT_DIR', __DIR__ . '/../../../'); + + define('OR_MODULES_DIR', __DIR__ . '/../../'); + define('OR_DYNAMICCLASSES_DIR', OR_MODULES_DIR . 'cms/macros/macro/'); + define('OR_SERVICECLASSES_DIR', OR_MODULES_DIR . 'util/'); + define('OR_AUTHCLASSES_DIR', OR_MODULES_DIR . 'cms/auth/'); + define('OR_TMP_DIR', CMS_ROOT_DIR . 'tmp/'); + + define('START_TIME', time()); + define('REQUEST_ID', 'req0'); // Nicht mehr notwendig, kann entfallen. + +// Must be relative to HTML-Path! + define('OR_HTML_MODULES_DIR', './modules/'); + define('OR_THEMES_DIR', OR_HTML_MODULES_DIR . 'cms/ui/themes/'); + } + + + public static function setErrorHandler() { + + /** + * Wandelt jeden Fehler in eine ErrorException um. + */ + $exceptionErrorHandler = function ($severity, $message, $file, $line) { + if ( !(error_reporting() & $severity) ) + { + // Dieser Fehlercode ist nicht in error_reporting enthalten + return; + } + throw new ErrorException($message, 0, $severity, $file, $line); + }; + + set_error_handler($exceptionErrorHandler); + + + /** + * Ermöglicht das Loggen von Fatal-Errors. + */ + $fatalHandler = function() { + + $error = error_get_last(); + + if( !is_null($error) ) + { + $errno = $error["type"]; + $errfile = $error["file"]; + $errline = $error["line"]; + $errstr = $error["message"]; + + $message = 'Error '.$errno .' '. $errstr.' in '. $errfile.':'. $errline; + if(class_exists('logger\Logger')) + Logger::error( $message); + else + { + error_log($message); + } + + // It is not possibile to throw an exception out of a shutdown function! + // PHP will exit the request directly after executing this method, so a + // Exception would never reach a caller. + } + + }; + + register_shutdown_function( $fatalHandler ); + + } + + + public static function securityCheck() + { + // 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!"); + } + + + public static function createRequest() + { + // TODO: We should use $_REQUEST everywhere. + global $REQ; + $REQ = array_merge($_GET, $_POST); + } +} diff --git a/modules/cms/base/functions/.htaccess b/modules/cms/base/functions/.htaccess @@ -1,2 +0,0 @@ -order deny,allow -deny from all- \ No newline at end of file diff --git a/modules/cms/base/functions/common.inc.php b/modules/cms/base/functions/common.inc.php @@ -1,178 +0,0 @@ -<?php - -use util\Session; - - -/** - * F�gt einen Slash ("/") an das Ende an, sofern nicht bereits vorhanden. - * - * @param String $pfad - * @return Pfad mit angeh�ngtem Slash. - */ -function slashify($pfad) -{ - if ( substr($pfad,-1,1) == '/') - return $pfad; - else - return $pfad.'/'; -} - -function convertToXmlAttribute( $value ) -{ - return utf8_encode( htmlspecialchars( $value ) ) ; -} - - -/** - * Ermittelt die aktuelle Systemzeit als Unix-Timestamp.<br> - * Unix-Timestamp ist immer bezogen auf GMT. - * - - * @return Unix-Timestamp der aktuellen Zeit - */ -function now() -{ - return time(); -} - - - -/** - * Erzeugt f�r eine Zahl eine Schreibweise mit Vorzeichen.<br> - * '-2' bleibt '-2'<br> - * '2' wird zu '+2'<br> - */ -function vorzeichen( $nr ) -{ - return intval($nr)<0 ? $nr : '+'.$nr; -} - - - -/** - * Stellt fest, ob das System in einem schreibgeschuetzten Zustand ist. - * - * @return boolean true, falls schreibgeschuetzt, sonst false - */ -function readonly() -{ - // Gesamtes CMS ist readonly. - if ( config('security','readonly') ) - return true; - - // Aktuelle Datenbankverbindung ist readonly. - $db = db(); - if ( isset($db->conf['readonly']) && $db->conf['readonly'] ) - return true; - - return false; -} - - - - - -/** - * Generiert aus der Session-Id einen Token. - * @return Token - */ -function token() -{ - return substr(session_id(),-10); -} - - -/** - * Ermittelt, ob der Wert 'true' oder 'false' entspricht. - * - * Anders als beim PHP-Cast auf boolean wird hier auch die - * Zeichenkette 'true' als wahr betrachtet. - * - * @param val mixed - * @return boolean - */ -function istrue( $val ) -{ - if ( is_bool($val) ) - return $val; - elseif( is_numeric($val) ) - return $val != 0; - elseif( is_string($val) ) - return $val == 'true' || $val == 'yes' || $val == '1'; - else - return false; -} - - - -/** - * Erzeugt einen Link auf die OpenRat-lokale CSS-Datei - * @param $name Name der Style-Konfiguration. Default: 'default'. - */ -function css_link( $name='default' ) -{ - global $conf; - - // Falls Style-Konfiguration unbekannt, dann Fallback auf default. - if ( ! isset($conf['style'][$name])) - $name = $conf['interface']['style']['default']; - - - return encode_array($conf['style'][$name]); -} - - -/** - * Encodiert ein Array für eine URL. - * - * @param $args URL-Parameter - */ -function encode_array( $args ) -{ - if ( !is_array($args) ) - return ''; - - $out = array(); - - foreach( $args as $name => $value ) - $out[] = $name.'='.urlencode($value); - - return implode('&',$out); -} - - -function not($var) { - return !$var; -} - -/** - * Liefert die Datenbankverbindung fuer die aktuelle Sitzung. - * - * @return \database\Database - * @deprecated use db() - */ -function db_connection() -{ - - return db(); -} - -/** - * Liefert die Datenbankverbindung fuer die aktuelle Sitzung. - * - * @return \database\Database - */ -function db() -{ - - $db = Session::getDatabase(); - - if ( ! is_object($db)) - throw new RuntimeException('no database available'); - - return $db; -} - - - - -?>- \ No newline at end of file diff --git a/modules/cms/base/functions/language.inc.php b/modules/cms/base/functions/language.inc.php @@ -1,182 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2012 Jan Dankert, cms@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. -use logger\Logger; -use util\ArrayUtils; -use util\text\variables\VariableResolver; - - -/** - * Diese Funktion stellt ein Wort in der eingestellten - * Sprache zur Verfuegung. - * - * @var String Name der Sprachvariablen - * @var Array Liste (Assoziatives Array) von Variablen - * - * @package openrat.functions - */ -function lang( $textVar,$vars = array() ) -{ - global $conf; - $lang = $conf['language']; - - $text = strtoupper($textVar); - - // Abfrage, ob Textvariable vorhanden ist - if ( isset( $lang[$text] ) ) - { - $text = $lang[$text]; - - // Fill in variables - if ( $vars ) - { - $resolver = new VariableResolver(); - - // Resolve variable - $resolver->addDefaultResolver(function ($var) use ($vars) { - return @$vars[$var]; - }); - - $text = $resolver->resolveVariables( $text ); - } - - return $text; - } - - // Wenn Textvariable nicht vorhanden ist, dann als letzten Ausweg nur den Variablennamen zurueckgeben - Logger::warn('Message-Key not found: '.$textVar); - return( '?'.$textVar.'?' ); -} - - - - -/** - * Diese Funktion stellt ein Wort in der eingestellten - * Sprache zur Verfuegung. Sonderzeichen werden als HTML maskiert. - * - * @var String Name der Sprachvariablen - * @var Array Liste (Assoziatives Array) von Variablen - * - * @package openrat.functions - * @param $key - * @return unknown_type - */ -function langHtml( $key,$vars = array() ) { - - return encodeHtml( lang($key,$vars) ); -} - -/** - * Ersetzt alle Zeichen mit dem Ordinalwert > 127 mit einer HTML-Maskierung. - * - * @return String - */ -function encodeHtml($text) -{ - return translateutf8tohtml($text); -} -function escapeHtml($text) -{ - return translateutf8tohtml( htmlentities( $text ) ); -} - - - - -// Source: http://de.php.net/manual/de/function.htmlentities.php#96648 -// Thx to silverbeat! -// When using UTF-8 as a charset, htmlentities will only convert 1-byte and 2-byte characters. -// Use this function if you also want to convert 3-byte and 4-byte characters: -// converts a UTF8-string into HTML entities - function translateutf8tohtml($txt) { - //$txt = html_entity_decode($txt); - $txt2 = ''; - for ($i=0;$i<strlen($txt);$i++) { - $o = ord($txt{$i}); - if ($o<128) { - // 0..127: raw - $txt2 .= $txt{$i}; - } else { - $o1 = 0; - $o2 = 0; - $o3 = 0; - if ($i<strlen($txt)-1) $o1 = ord($txt{$i+1}); - if ($i<strlen($txt)-2) $o2 = ord($txt{$i+2}); - if ($i<strlen($txt)-3) $o3 = ord($txt{$i+3}); - $hexval = 0; - if ($o>=0xc0 && $o<0xc2) { - // INVALID --- should never occur: 2-byte UTF-8 although value < 128 - $hexval = $o1; - $i++; - } elseif ($o>=0xc2 && $o<0xe0 && $o1>=0x80) { - // 194..223: 2-byte UTF-8 - $hexval |= ($o & 0x1f) << 6; // 1. byte: five bits of 1. char - $hexval |= ($o1 & 0x3f); // 2. byte: six bits of 2. char - $i++; - } elseif ($o>=0xe0 && $o<0xf0 && $o1>=0x80 && $o2>=0x80) { - // 224..239: 3-byte UTF-8 - $hexval |= ($o & 0x0f) << 12; // 1. byte: four bits of 1. char - $hexval |= ($o1 & 0x3f) << 6; // 2.+3. byte: six bits of 2.+3. char - $hexval |= ($o2 & 0x3f); - $i += 2; - } elseif ($o>=0xf0 && $o<0xf4 && $o1>=0x80) { - // 240..244: 4-byte UTF-8 - $hexval |= ($o & 0x07) << 18; // 1. byte: three bits of 1. char - $hexval |= ($o1 & 0x3f) << 12; // 2.-4. byte: six bits of 2.-4. char - $hexval |= ($o2 & 0x3f) << 6; - $hexval |= ($o3 & 0x3f); - $i += 3; - } else { - // don't know ... just encode - $hexval = $o; - } - $hexstring = dechex($hexval); - if (strlen($hexstring)%2) $hexstring = '0' . $hexstring; - $txt2 .= '&#x' . $hexstring . ';'; - } - } - $result = $txt2; - - return $result; - } - - - - - - - -/** - * Diese Funktion prueft, ob ein Sprachelement vorhanden ist - * - * @var String Name der Sprachvariablen - * - * @package openrat.functions - */ -function hasLang( $text ) -{ - $text = strtoupper($text); - - global $conf; - $lang = $conf['language']; - - return isset( $lang[$text] ); -} - - -?>- \ No newline at end of file diff --git a/modules/cms/base/functions/request.inc.php b/modules/cms/base/functions/request.inc.php @@ -1,20 +0,0 @@ -<?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/base/init.php b/modules/cms/base/init.php @@ -1,101 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2009 Jan Dankert, cms@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; version 2. -// -// 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. - -use logger\Logger; -use util\exception\ValidationException; - -define('MIN_VERSION','5.4'); - -if ( version_compare(phpversion(),MIN_VERSION,"<") ) - throw new ValidationException('This version of PHP is not supported any more. Minimum required: '.MIN_VERSION); - - -define('PHP_EXT' ,'php' ); - -define('IMG_EXT' ,'.gif' ); -define('IMG_ICON_EXT' ,'.png' ); - -require(__DIR__ . '/version.php'); -define('OR_TITLE' ,'OpenRat CMS'); - -define( 'CMS_ROOT_DIR', __DIR__ . '/../../../'); - -define('OR_MODULES_DIR' , __DIR__ . '/../../'); -define('OR_DYNAMICCLASSES_DIR',OR_MODULES_DIR.'cms/macros/macro/' ); -define('OR_SERVICECLASSES_DIR',OR_MODULES_DIR.'util/' ); -define('OR_AUTHCLASSES_DIR' ,OR_MODULES_DIR.'cms/auth/' ); -define('OR_TMP_DIR' ,CMS_ROOT_DIR.'tmp/' ); - -define('START_TIME' ,time() ); -define('REQUEST_ID' ,'req0' ); // Nicht mehr notwendig, kann entfallen. - -// Must be relative to HTML-Path! -define('OR_HTML_MODULES_DIR' ,'./modules/' ); -define('OR_THEMES_DIR' ,OR_HTML_MODULES_DIR.'cms/ui/themes/'); - - - -/** - * Wandelt jeden Fehler in eine ErrorException um. - */ -function exception_error_handler($severity, $message, $file, $line) { - if ( !(error_reporting() & $severity) ) - { - // Dieser Fehlercode ist nicht in error_reporting enthalten - return; - } - throw new ErrorException($message, 0, $severity, $file, $line); -} - -set_error_handler("exception_error_handler"); - - -/** - * Ermöglicht das Loggen von Fatal-Errors. - */ -function fatal_handler() { - - $error = error_get_last(); - - if( !is_null($error) ) - { - $errno = $error["type"]; - $errfile = $error["file"]; - $errline = $error["line"]; - $errstr = $error["message"]; - - $message = 'Error '.$errno .' '. $errstr.' in '. $errfile.':'. $errline; - if(class_exists('logger\Logger')) - Logger::error( $message); - else - { - error_log($message); - } - - // It is not possibile to throw an exception out of a shutdown function! - // PHP will exit the request directly after executing this method, so a - // Exception would never reach a caller. - //throw new ErrorException($errstr, $errno, 1, $errfile, $errline); - } - -} - -register_shutdown_function( "fatal_handler"); - - - -?>- \ No newline at end of file diff --git a/modules/cms/base/require.php b/modules/cms/base/require.php @@ -1,16 +0,0 @@ -<?php - -require_once(__DIR__ . '/../../util/require.php'); -require_once(__DIR__ . '/../../configuration/require.php'); -require_once(__DIR__ . '/../../wikiparser/require.php'); -require_once(__DIR__ . '/../../logger/require.php'); -require_once(__DIR__ . '/../../language/require.php'); - -// Helper functions... -require_once(__DIR__ . "/functions/common.inc.php"); -require_once(__DIR__ . "/functions/language.inc.php"); -require_once(__DIR__ . "/functions/request.inc.php"); - - -require_once(__DIR__ . '/init.php'); - diff --git a/modules/cms/generator/filter/LessFilter.class.php b/modules/cms/generator/filter/LessFilter.class.php @@ -4,7 +4,7 @@ namespace cms\generator\filter; -use \Less_Parser; +use util\Less; class LessFilter extends AbstractFilter { @@ -15,7 +15,7 @@ class LessFilter extends AbstractFilter public function filter($value) { - $parser = new Less_Parser(array( + $parser = new Less(array( 'sourceMap' => $this->sourceMap, 'indentation' => $this->indentation, 'outputSourceFiles' => false, diff --git a/modules/cms/macros/macro/SearchIndex.class.php b/modules/cms/macros/macro/SearchIndex.class.php @@ -7,7 +7,7 @@ use cms\model\Element; use cms\model\Folder; use cms\model\Page; use cms\model\Project; -use JSON; +use util\json\JSON; use util\Macro; diff --git a/modules/cms/macros/require.php b/modules/cms/macros/require.php @@ -1 +0,0 @@ -<?php diff --git a/modules/cms/ui/UI.class.php b/modules/cms/ui/UI.class.php @@ -133,121 +133,4 @@ class UI } - public static function updateProduction() - { - self::updateProductionCSS(); - self::updateProductionJS(); - } - - private static function updateProductionCSS() - { - $productionCSSFile = __DIR__ . 'cms-ui/themes/default/production/combined.min.css'; - - $css = self::getCSSFiles(); - //$css[] = OR_HTML_MODULES_DIR . 'editor/codemirror/lib/codemirror'; - - // Komponentenbasiertes CSS - - $modified = false; - foreach ($css as $cssF) - { - $lessFile = $cssF . '.less'; - $cssFile = $cssF . '.css'; - $cssMinFile = $cssF . '.min.css'; - - if (! is_file($lessFile)) - { - Logger::warn("Stylesheet not found: $lessFile"); - continue; - } - elseif (! is_file($cssFile) || ! is_writable($cssFile)) - { - Logger::warn("Stylesheet output file not found or not writable: $cssFile"); - continue; - } - elseif (! is_file($cssMinFile) || ! is_writable($cssMinFile)) - { - Logger::warn("Stylesheet output file not found or not writable: $cssMinFile"); - continue; - } - else - { - if (filemtime($lessFile) > filemtime($cssMinFile)) - { - // LESS-Source wurde geändert, CSS-Version muss aktualisiert werden. - $modified = true; - - // Den absoluten Pfad zur LESS-Datei ermitteln. Dieser wird vom LESS-Parser für den korrekten Link - // auf die LESS-Datei in der Sourcemap benötigt. - $pfx = substr(realpath($lessFile),0,0-strlen(basename($lessFile))); - - $parser = new Less_Parser(array( - 'sourceMap' => true, - 'indentation' => ' ', - 'outputSourceFiles' => false, - 'sourceMapBasepath' => $pfx - )); - - - $parser->parseFile( ltrim($lessFile,'./') ); - $source = $parser->getCss(); - - file_put_contents($cssFile, $source); - - $parser = new Less_Parser(array( - 'compress' => true, - 'sourceMap' => false, - 'indentation' => '' - )); - $parser->parseFile($lessFile); - $source = $parser->getCss(); - - - file_put_contents($cssMinFile, $source); - } - - $outFiles[] = $cssFile; - } - } - - if ($modified) - { - if ( !is_writable($productionCSSFile)) - { - Logger::warn('not writable: '.$productionCSSFile); - } - else - { - file_put_contents($productionCSSFile,''); - foreach ($css as $cssF) - { - $cssMinFile = $cssF . '.min.css'; - if ( is_file($cssMinFile)) - file_put_contents($productionCSSFile,file_get_contents($cssMinFile),FILE_APPEND); - } - } - } - - } - - private static function updateProductionJS() - { - } - - /** - * @return array - */ - private static function getCSSFiles() - { - $css = array(); - $css[] = OR_THEMES_DIR . 'default/css/openrat-ui'; - $css[] = OR_THEMES_DIR . 'default/css/openrat-workbench'; - - foreach (TemplateEngineInfo::getLESSFiles() as $lessFile) - { - $css[] = OR_HTML_MODULES_DIR . 'template_engine/components/html/' . $lessFile . '/' . $lessFile; - } - - return $css; - } } diff --git a/modules/cms/ui/action/IndexAction.class.php b/modules/cms/ui/action/IndexAction.class.php @@ -8,15 +8,13 @@ use cms\model\Project; use cms\model\User; use cms\model\Value; use Exception; -use JSON; use language\Messages; -use util\JSqueeze; -use \Less_Parser; +use util\json\JSON; use logger\Logger; +use util\Less; use util\UIUtils; use ObjectNotFoundException; use util\Session; -use template_engine\TemplateEngineInfo; /** @@ -198,7 +196,7 @@ class IndexAction extends Action { try { - $parser = new Less_Parser(array( + $parser = new Less(array( 'sourceMap' => DEVELOPMENT, 'indentation' => ' ', 'outputSourceFiles' => false diff --git a/modules/cms/ui/themes/ThemeCompiler.class.php b/modules/cms/ui/themes/ThemeCompiler.class.php @@ -5,7 +5,7 @@ namespace cms\ui\themes; use util\JSqueeze; use logger\Logger; use template_engine\TemplateEngineInfo; -use \Less_Parser; +use util\Less; require (__DIR__.'/../../../util/require.php'); @@ -80,7 +80,7 @@ class ThemeCompiler // auf die LESS-Datei in der Sourcemap benötigt. $pfx = substr(realpath($lessFile),0,0-strlen(basename($lessFile))); - $parser = new Less_Parser(array( + $parser = new Less(array( 'sourceMap' => true, 'indentation' => ' ', 'outputSourceFiles' => false, @@ -93,7 +93,7 @@ class ThemeCompiler file_put_contents($combinedCssFile, $source."\n",FILE_APPEND); - $parser = new Less_Parser(array( + $parser = new Less(array( 'compress' => true, 'sourceMap' => false, 'indentation' => '' diff --git a/modules/configuration/configuration.php b/modules/configuration/configuration.php @@ -1,50 +0,0 @@ -<?php - - -/* - * Liest einen Schluessel aus der Konfiguration - * - * @return String, leer falls Schluessel nicht vorhanden - */ -function config( $part1=null,$part2=null,$part3=null,$part4=null ) -{ - global $conf; - - if ( $part1==null ) - return new configuration\Config( $conf ); - - if ( $part2 == null) - if ( isset($conf[$part1])) - return $conf[$part1]; - else - return ''; - - if ( $part3 == null) - if ( isset($conf[$part1][$part2])) - return $conf[$part1][$part2]; - else - return ''; - - if ( $part4 == null) - if ( isset($conf[$part1][$part2][$part3])) - return $conf[$part1][$part2][$part3]; - else - return ''; - - if ( isset($conf[$part1][$part2][$part3][$part4])) - return $conf[$part1][$part2][$part3][$part4]; - else - return ''; -} - - -/** - * @return \configuration\Config - */ -function Conf() { - - global $conf; - return new configuration\Config( $conf ); - -} - diff --git a/modules/configuration/require.php b/modules/configuration/require.php @@ -1,3 +0,0 @@ -<?php - -require_once(__DIR__ . "/configuration.php"); diff --git a/modules/editor/codemirror/require.php b/modules/editor/codemirror/require.php @@ -1,5 +0,0 @@ -<?php - -// Includes are done via JS - -?>- \ No newline at end of file diff --git a/modules/language/require.php b/modules/language/require.php @@ -1,2 +0,0 @@ -<?php - diff --git a/modules/logger/Logger.class.php b/modules/logger/Logger.class.php @@ -3,6 +3,7 @@ namespace logger; use Exception; +use util\json\JSON; use util\Text; /** @@ -174,7 +175,7 @@ class Logger break; case self::OUTPUT_JSON: - $json = new \JSON(); + $json = new JSON(); $text = $json->encode( $values ); $text = str_replace("\n", "", $text); break; diff --git a/modules/logger/require.php b/modules/logger/require.php @@ -1,2 +0,0 @@ -<?php - diff --git a/modules/security/require.php b/modules/security/require.php @@ -1,2 +0,0 @@ -<?php - diff --git a/modules/template_engine/TemplateCompiler.php b/modules/template_engine/TemplateCompiler.php @@ -17,7 +17,6 @@ $dir = __DIR__ . '/../../modules/cms/ui/themes/default/html/views'; require(__DIR__.'/../util/require.php'); require(__DIR__.'/../template_engine/require.php'); -require(__DIR__.'/../cms/base/require.php'); echo "Searching in $dir\n"; diff --git a/modules/template_engine/components/html/link/Link.class.php b/modules/template_engine/components/html/link/Link.class.php @@ -2,10 +2,9 @@ namespace template_engine\components; -use util\Html; -use JSON; use template_engine\components\html\Component; use template_engine\element\CMSElement; +use util\json\JSON; /** * Erzeugt einen HTML-Link. diff --git a/modules/template_engine/require.php b/modules/template_engine/require.php @@ -1,2 +0,0 @@ -<?php - diff --git a/modules/util/Less.class.php b/modules/util/Less.class.php @@ -0,0 +1,40 @@ +<?php + + +namespace util; + +require __DIR__.'/Less.php'; + +/** + * Wrapper for 3rd-party Less parser. + */ +class Less +{ + + private $less; + + + public function __construct( $var ) + { + $this->less = new \Less_Parser( $var ); + } + + + public function parse( $str, $file_uri = null ) + { + $this->less->parse($str, $file_uri); + } + public function parseFile( $filename, $uri_root = '', $returnRoot = false ) + { + $this->less->parseFile( $filename, $uri_root, $returnRoot ); + } + public function ModifyVars( $var ) + { + $this->less->ModifyVars($var ); + } + public function getCss() + { + return $this->less->getCss(); + } + +}+ \ No newline at end of file diff --git a/modules/util/json/JSON.class.php b/modules/util/json/JSON.class.php @@ -0,0 +1,21 @@ +<?php + + +namespace util\json; + +require(__DIR__.'/../JSON.class.php'); + +/** + * JSON Wrapper. + */ +class JSON +{ + public function encode($var) { + $json = new \JSON(); + return $json->encode($var); + } + public function decode($var) { + $json = new \JSON(); + return $json->decode($var); + } +}+ \ No newline at end of file diff --git a/modules/util/require.php b/modules/util/require.php @@ -1,5 +0,0 @@ -<?php - - -require_once( __DIR__.'/'.'JSON.class.php' ); -require_once( __DIR__.'/'.'Less.php' ); diff --git a/modules/wikiparser/require.php b/modules/wikiparser/require.php @@ -1,3 +0,0 @@ -<?php - -// nothing to do. All classes are loaded by autoloading.- \ No newline at end of file