commit 2b9c728e626b9e123ba21668a76eb4b657f073f7
parent f9194cdb9a9a887627bc6802c353b54af5809860
Author: Jan Dankert <devnull@localhost>
Date: Sat, 30 Dec 2017 01:14:25 +0100
Dateien mit Hilfsmethoden nach cms-core verschoben und tlw. aufgeräumt.
Diffstat:
8 files changed, 387 insertions(+), 393 deletions(-)
diff --git a/functions/.htaccess b/functions/.htaccess
@@ -1,2 +0,0 @@
-order deny,allow
-deny from all-
\ No newline at end of file
diff --git a/functions/common.inc.php b/functions/common.inc.php
@@ -1,173 +0,0 @@
-<?php
-
-
-/**
- * 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()
-{
- global $conf;
-
- // Gesamtes CMS ist readonly.
- if ( config('security','readonly') )
- return true;
-
- // Aktuelle Datenbankverbindung ist readonly.
- $db = Session::getDatabase();
- if ( isset($db->conf['readonly']) && $db->conf['readonly'] )
- return true;
-
- return false;
-}
-
-
-
-/*
- * Liest einen Schluessel aus der Konfiguration
- *
- * @return String, leer falls Schluessel nicht vorhanden
- */
-function config( $part1,$part2=null,$part3=null )
-{
- global $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 ( isset($conf[$part1][$part2][$part3]))
- return $conf[$part1][$part2][$part3];
- else
- return '';
-}
-
-
-/**
- * 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;
-}
-
-?>-
\ No newline at end of file
diff --git a/functions/language.inc.php b/functions/language.inc.php
@@ -1,176 +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.
-
-
-/**
- * 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] ) && substr($text,0,9)=='GLOBAL_' )
- $text = substr($text,7);
-
- // Abfrage, ob Textvariable vorhanden ist
- if ( !isset( $lang[$text] ))
- $text = 'GLOBAL_'.$text;
-
- // Abfrage, ob Textvariable vorhanden ist
- if ( isset( $lang[$text] ) )
- {
- $text = $lang[$text];
-
- // Fuellen der Variablen im Text
- foreach( $vars as $var=>$value )
- $text = str_replace('{'.$var.'}',$value,$text);
-
- str_replace("''",'"',$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);
-}
-
-
-
-
-// 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/functions/request.inc.php b/functions/request.inc.php
@@ -1,38 +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.
-
-$REQ = array_merge($_GET,$_POST);
-
-// Zur Sicherheit:
-// Falls REGISTER_GLOBALS aktiviert ist, dann alle REQUEST-Variablen aus dem
-// globalen G�ltigkeitsraum entfernen.
-if ( ini_get('register_globals') )
-{
- foreach( $REQ as $reqVar=>$reqValue )
- unset( $$reqVar );
-}
-
-if ( get_magic_quotes_gpc() == 1 )
-{
- foreach( $REQ as $p=>$v )
- if ( !is_array($v) )
- $REQ[$p] = stripslashes($v);
-}
-
-
-?>-
\ No newline at end of file
diff --git a/modules/cms-core/functions/.htaccess b/modules/cms-core/functions/.htaccess
@@ -0,0 +1,2 @@
+order deny,allow
+deny from all+
\ No newline at end of file
diff --git a/modules/cms-core/functions/common.inc.php b/modules/cms-core/functions/common.inc.php
@@ -0,0 +1,187 @@
+<?php
+
+
+/**
+ * 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()
+{
+ global $conf;
+
+ // Gesamtes CMS ist readonly.
+ if ( config('security','readonly') )
+ return true;
+
+ // Aktuelle Datenbankverbindung ist readonly.
+ $db = Session::getDatabase();
+ if ( isset($db->conf['readonly']) && $db->conf['readonly'] )
+ return true;
+
+ return false;
+}
+
+
+
+/*
+ * Liest einen Schluessel aus der Konfiguration
+ *
+ * @return String, leer falls Schluessel nicht vorhanden
+ */
+function config( $part1,$part2=null,$part3=null )
+{
+ global $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 ( isset($conf[$part1][$part2][$part3]))
+ return $conf[$part1][$part2][$part3];
+ else
+ return '';
+}
+
+
+/**
+ * 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
+ */
+function db_connection()
+{
+
+ return Session::getDatabase();
+}
+
+
+
+
+?>+
\ No newline at end of file
diff --git a/modules/cms-core/functions/language.inc.php b/modules/cms-core/functions/language.inc.php
@@ -0,0 +1,176 @@
+<?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.
+
+
+/**
+ * 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] ) && substr($text,0,9)=='GLOBAL_' )
+ $text = substr($text,7);
+
+ // Abfrage, ob Textvariable vorhanden ist
+ if ( !isset( $lang[$text] ))
+ $text = 'GLOBAL_'.$text;
+
+ // Abfrage, ob Textvariable vorhanden ist
+ if ( isset( $lang[$text] ) )
+ {
+ $text = $lang[$text];
+
+ // Fuellen der Variablen im Text
+ foreach( $vars as $var=>$value )
+ $text = str_replace('{'.$var.'}',$value,$text);
+
+ str_replace("''",'"',$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);
+}
+
+
+
+
+// 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-core/functions/request.inc.php b/modules/cms-core/functions/request.inc.php
@@ -0,0 +1,18 @@
+<?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!");
+
+
+?>+
\ No newline at end of file