openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 11572a2550e6524f429fb5e985723813f920a6b3
parent f5dca318f8f04efd5b0a16a782ba1fb74391855f
Author: Jan Dankert <devnull@localhost>
Date:   Fri,  8 Dec 2017 21:43:56 +0100

Nur kleine Optimierungen im PHPDOC.

Diffstat:
action/Action.class.php | 19++++++++++---------
action/LoginAction.class.php | 435++++++++++++++++++++++++++++++++++++++++---------------------------------------
util/Html.class.php | 28++++++++++++++--------------
util/Session.class.php | 132+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
util/Text.class.php | 397+++++++++++++++++++++++++++++++++++++++----------------------------------------
5 files changed, 520 insertions(+), 491 deletions(-)

diff --git a/action/Action.class.php b/action/Action.class.php @@ -75,18 +75,19 @@ use \LogicException; class Action { public $db; - private $templateVars = Array(); public $actionName; public $subActionName; public $actionClassName; - public $writable; + public $publishing; public $refresh; + protected $templateVars = Array(); + /** * Aktuell angemeldeter Benutzer.<br> - * Wird ind er Funktion "init()" gesetzt. + * Wird in der Funktion "init()" gesetzt. * * @var Object Benutzer */ @@ -147,7 +148,7 @@ use \LogicException; /** * Setzt eine Session-Variable * - * @param Sring $varName Schl�ssel + * @param string $varName Schluessel * @param mixed $value Inhalt * @return mixed */ @@ -288,7 +289,7 @@ use \LogicException; /** * Setzt eine Liste von Variablen f�r die Oberfl�che. * - * @param Array $varList Assoziatives Array + * @param array $varList Assoziatives Array */ protected function setTemplateVars($varList) { @@ -325,8 +326,8 @@ use \LogicException; * @param String $name Name des Objektes, zu dem diese Meldung geh�rt. * @param String $text Textschl�ssel der Fehlermeldung (optional) * @param String $status Einer der Werte OR_NOTICE_(OK|WARN|ERROR) - * @param Array $vars Variablen f�r den Textschl�ssel - * @param Array $log Weitere Hinweistexte f�r diese Meldung. + * @param array $vars Variablen f�r den Textschl�ssel + * @param array $log Weitere Hinweistexte f�r diese Meldung. */ protected function addNotice($type, $name, $text, $status = OR_NOTICE_OK, $vars = array(), $log = array()) { @@ -631,7 +632,7 @@ use \LogicException; /** - * @param max Anzahl der Sekunden, die die Seite im Browsercache bleiben darf + * @param $max int max Anzahl der Sekunden, die die Seite im Browsercache bleiben darf */ protected function maxAge($max = 3600) { @@ -771,7 +772,7 @@ use \LogicException; public function getErrorField() { - return $fieldName; + return $this->fieldName; } } diff --git a/action/LoginAction.class.php b/action/LoginAction.class.php @@ -14,17 +14,17 @@ use cms\model\Language; use cms\model\Model; -use database\Database; -use DB; -use DbUpdate; -use Exception; -use Http; -use InternalAuth; -use Logger; -use ObjectNotFoundException; -use OpenRatException; +use \database\Database; +use \DB; +use \DbUpdate; +use \Exception; +use \Http; +use \InternalAuth; +use \Logger; +use \ObjectNotFoundException; +use \OpenRatException; use \security\Password; -use Session; +use \Session; use \Html; use \Mail; use \Text; @@ -91,10 +91,10 @@ class LoginAction extends Action } - - /** - * Prueft, ob der Parameter 'dbid' übergeben wurde. - */ + /** + * Prueft, ob der Parameter 'dbid' übergeben wurde. + * @throws OpenRatException + */ function checkForDb() { global $conf; @@ -105,8 +105,10 @@ class LoginAction extends Action } - - function setDefaultDb() + /** + * @throws OpenRatException + */ + function setDefaultDb() { if ( $this->hasRequestVar(REQ_PARAM_DATABASE_ID) ) { @@ -121,15 +123,23 @@ class LoginAction extends Action $dbid = $conf['database']['default']; } - + $this->setDb( $dbid ); } - - private function checkLogin( $name,$pw,$pw1,$pw2 ) + /** + * Führt ein Login durch. + * @param $name string Benutzername + * @param $pw string Password + * @param $pw1 string new Password + * @param $pw2 string new Password repeated + * @return bool + * @throws ObjectNotFoundException + */ + private function checkLogin($name, $pw, $pw1, $pw2 ) { - Logger::debug( "login user $name" ); + Logger::debug( "Login user: '$name'.'" ); global $conf; global $SESS; @@ -217,211 +227,212 @@ class LoginAction extends Action } + /** + * Anzeigen der Loginmaske. + * + * Es wird nur die Loginmaske angezeigt. + * @throws OpenRatException + */ + function loginView() + { + // Hier nie "304 not modified" setzen, da sonst keine + // Login-Fehlermeldung erscheinen kann. + global $conf; - /** - * Anzeigen der Loginmaske. - * - * Es wird nur die Loginmaske angezeigt. - * Hier nie "304 not modified" setzen, da sonst keine - * Login-Fehlermeldung erscheinen kann - */ - function loginView() - { - global $conf; - - $sso = $conf['security']['sso']; - $ssl = $conf['security']['ssl']; - - $ssl_trust = false; - $ssl_user_var = ''; - extract( $ssl, EXTR_PREFIX_ALL, 'ssl' ); - - if ( $sso['enable'] ) - { - $authid = $this->getRequestVar( $sso['auth_param_name']); - - if ( empty( $authid) ) - Http::notAuthorized( 'no authorization data (no auth-id)'); - - if ( $sso['auth_param_serialized'] ) - $authid = unserialize( $authid ); - - $purl = parse_url($sso['url']); - // Verbindung zu URL herstellen. - $errno=0; $errstr=''; - $fp = fsockopen ($purl['host'],80, $errno, $errstr, 30); - if ( !$fp ) - { - echo "Connection failed: $errstr ($errno)"; - } - else - { - $http_get = $purl['path']; - if ( !empty($purl['query']) ) - $http_get .= '?'.$purl['query']; + $sso = $conf['security']['sso']; + $ssl = $conf['security']['ssl']; + + $ssl_trust = false; + $ssl_user_var = ''; + extract( $ssl, EXTR_PREFIX_ALL, 'ssl' ); + + if ( $sso['enable'] ) + { + $authid = $this->getRequestVar( $sso['auth_param_name']); + + if ( empty( $authid) ) + Http::notAuthorized( 'no authorization data (no auth-id)'); + + if ( $sso['auth_param_serialized'] ) + $authid = unserialize( $authid ); + + $purl = parse_url($sso['url']); + // Verbindung zu URL herstellen. + $errno=0; $errstr=''; + $fp = fsockopen ($purl['host'],80, $errno, $errstr, 30); + if ( !$fp ) + { + echo "Connection failed: $errstr ($errno)"; + } + else + { + $http_get = $purl['path']; + if ( !empty($purl['query']) ) + $http_get .= '?'.$purl['query']; + + $header = array(); + + $header[] = "GET $http_get HTTP/1.0"; + $header[] ="Host: ".$purl['host']; + $header[] = "User-Agent: Mozilla/5.0 (OpenRat CMS Single Sign-on Check)"; + $header[] = "Connection: Close"; + + if ( $sso['cookie'] ) + { + $cookie = 'Cookie: '; + if ( is_array($authid)) + foreach( $authid as $cookiename=>$cookievalue) + $cookie .= $cookiename.'='.$cookievalue."; "; + else + $cookie .= $sso['cookie_name'].'='.$authid; + + $header[] = $cookie; + } - $header = array(); - - $header[] = "GET $http_get HTTP/1.0"; - $header[] ="Host: ".$purl['host']; - $header[] = "User-Agent: Mozilla/5.0 (OpenRat CMS Single Sign-on Check)"; - $header[] = "Connection: Close"; - - if ( $sso['cookie'] ) - { - $cookie = 'Cookie: '; - if ( is_array($authid)) - foreach( $authid as $cookiename=>$cookievalue) - $cookie .= $cookiename.'='.$cookievalue."; "; - else - $cookie .= $sso['cookie_name'].'='.$authid; - - $header[] = $cookie; - } - // Html::debug($header); - fputs ($fp, implode("\r\n",$header)."\r\n\r\n"); - - $inhalt=array(); - while (!feof($fp)) { - $inhalt[] = fgets($fp,128); - } - fclose($fp); - - $html = implode('',$inhalt); + fputs ($fp, implode("\r\n",$header)."\r\n\r\n"); + + $inhalt=array(); + while (!feof($fp)) { + $inhalt[] = fgets($fp,128); + } + fclose($fp); + + $html = implode('',$inhalt); // Html::debug($html); - if ( !preg_match($sso['expect_regexp'],$html) ) - Http::notAuthorized('auth failed'); - $treffer=0; - if ( !preg_match($sso['username_regexp'],$html,$treffer) ) - Http::notAuthorized('auth failed'); - if ( !isset($treffer[1]) ) - Http::notAuthorized('authorization failed'); - - $username = $treffer[1]; - + if ( !preg_match($sso['expect_regexp'],$html) ) + Http::notAuthorized('auth failed'); + $treffer=0; + if ( !preg_match($sso['username_regexp'],$html,$treffer) ) + Http::notAuthorized('auth failed'); + if ( !isset($treffer[1]) ) + Http::notAuthorized('authorization failed'); + + $username = $treffer[1]; + // Html::debug( $treffer ); - $this->setDefaultDb(); + $this->setDefaultDb(); - $user = User::loadWithName( $username ); - - if ( ! $user->isValid( )) - Http::notAuthorized('authorization failed: user not found: '.$username); - - $user->setCurrent(); + $user = User::loadWithName( $username ); - $this->callSubAction('show'); - } - } + if ( ! $user->isValid( )) + Http::notAuthorized('authorization failed: user not found: '.$username); - elseif ( $ssl_trust ) - { - if ( empty($ssl_user_var) ) - Http::serverError( 'please set environment variable name in ssl-configuration.' ); + $user->setCurrent(); - $username = getenv( $ssl_user_var ); + $this->callSubAction('show'); + } + } - if ( empty($username) ) - Http::notAuthorized( 'no username in client certificate ('.$ssl_user_var.') (or there is no client certificate...?)' ); - - $this->setDefaultDb(); + elseif ( $ssl_trust ) + { + if ( empty($ssl_user_var) ) + Http::serverError( 'please set environment variable name in ssl-configuration.' ); - $user = User::loadWithName( $username ); + $username = getenv( $ssl_user_var ); - if ( !$user->isValid() ) - Http::serverError( 'unknown username: '.$username ); + if ( empty($username) ) + Http::notAuthorized( 'no username in client certificate ('.$ssl_user_var.') (or there is no client certificate...?)' ); - $user->setCurrent(); + $this->setDefaultDb(); - $this->callSubAction('show'); - } - - foreach( $conf['database'] as $dbid => $dbconf ) - { - if ( is_array($dbconf) && $dbconf['enabled'] ) - $dbids[$dbid] = array('key' => $dbid, - 'value' => empty($dbconf['name'])?$dbid:Text::maxLength($dbconf['name']), - 'title' => @$dbconf['description'] ); - } - - - if ( empty($dbids) ) - $this->addNotice('','','no_database_configuration',OR_NOTICE_WARN); - - if ( !isset($this->templateVars['login_name']) && isset($_COOKIE['or_username']) ) - $this->setTemplateVar('login_name',$_COOKIE['or_username']); - - if ( !isset($this->templateVars['login_name']) ) - $this->setTemplateVar('login_name',@$conf['security']['default']['username']); + $user = User::loadWithName( $username ); - if ( @$this->templateVars['login_name']== @$conf['security']['default']['username']) - $this->setTemplateVar('login_password',@$conf['security']['default']['password']); + if ( !$user->isValid() ) + Http::serverError( 'unknown username: '.$username ); - $this->setTemplateVar( 'dbids',$dbids ); - - $db = Session::getDatabase(); - if ( is_object($db) ) - $this->setTemplateVar('actdbid',$db->id); - elseif( isset($this->templateVars['actid']) ) - ; - elseif ( isset($_COOKIE['or_dbid']) && isset($dbids[$_COOKIE['or_dbid']]) ) - // DB-Id aus dem Cookie lesen. - $this->setTemplateVar('actdbid',$_COOKIE['or_dbid'] ); - else - $this->setTemplateVar('actdbid',$conf['login']['default-database']); + $user->setCurrent(); + $this->callSubAction('show'); + } - // Den Benutzernamen aus dem Client-Zertifikat lesen und in die Loginmaske eintragen. - $ssl_user_var = $conf['security']['ssl']['client_cert_dn_env']; - if ( !empty($ssl_user_var) ) - { - $username = getenv( $ssl_user_var ); + foreach( $conf['database'] as $dbid => $dbconf ) + { + if ( is_array($dbconf) && $dbconf['enabled'] ) + $dbids[$dbid] = array('key' => $dbid, + 'value' => empty($dbconf['name'])?$dbid:Text::maxLength($dbconf['name']), + 'title' => @$dbconf['description'] ); + } + + + if ( empty($dbids) ) + $this->addNotice('','','no_database_configuration',OR_NOTICE_WARN); + + if ( !isset($this->templateVars['login_name']) && isset($_COOKIE['or_username']) ) + $this->setTemplateVar('login_name',$_COOKIE['or_username']); + + if ( !isset($this->templateVars['login_name']) ) + $this->setTemplateVar('login_name',@$conf['security']['default']['username']); + + if ( @$this->templateVars['login_name']== @$conf['security']['default']['username']) + $this->setTemplateVar('login_password',@$conf['security']['default']['password']); + + $this->setTemplateVar( 'dbids',$dbids ); + + $db = Session::getDatabase(); + if ( is_object($db) ) + $this->setTemplateVar('actdbid',$db->id); + elseif( isset($this->templateVars['actid']) ) + ; + elseif ( isset($_COOKIE['or_dbid']) && isset($dbids[$_COOKIE['or_dbid']]) ) + // DB-Id aus dem Cookie lesen. + $this->setTemplateVar('actdbid',$_COOKIE['or_dbid'] ); + else + $this->setTemplateVar('actdbid',$conf['login']['default-database']); + + + // Den Benutzernamen aus dem Client-Zertifikat lesen und in die Loginmaske eintragen. + $ssl_user_var = $conf['security']['ssl']['client_cert_dn_env']; + if ( !empty($ssl_user_var) ) + { + $username = getenv( $ssl_user_var ); + + if ( empty($username) ) + { + // Nothing to do. + // if user has no valid client cert he could not access this form. + } + else { - if ( empty($username) ) - { - // Nothing to do. - // if user has no valid client cert he could not access this form. - } - else { - // Benutzername ist in Eingabemaske unver�nderlich $this->setTemplateVar('force_username',$username); - } - - } + } - $this->setTemplateVar('objectid' ,$this->getRequestVar('objectid' ,OR_FILTER_NUMBER) ); - $this->setTemplateVar('projectid' ,$this->getRequestVar('projectid' ,OR_FILTER_NUMBER) ); - $this->setTemplateVar('modelid' ,$this->getRequestVar('modelid' ,OR_FILTER_NUMBER) ); - $this->setTemplateVar('languageid',$this->getRequestVar('languageid',OR_FILTER_NUMBER) ); - - $this->setTemplateVar('register' ,$conf['login' ]['register' ]); - $this->setTemplateVar('send_password',$conf['login' ]['send_password']); - - // Versuchen, einen Benutzernamen zu ermitteln, der im Eingabeformular vorausgewählt wird. - $modules = explode(',',$conf['security']['modules']['preselect']); - - $username = ''; - foreach( $modules as $module) - { - Logger::debug('Preselecting module: '.$module); - $moduleClass = $module.'Auth'; - $auth = new $moduleClass; - $username = $auth->username(); - - if ( !empty($username) ) - { - Logger::debug('Preselecting User '.$username); - break; // Benutzername gefunden. - } - } - - $this->setTemplateVar('login_name',$username); - } - - - - /** + } + + $this->setTemplateVar('objectid' ,$this->getRequestVar('objectid' ,OR_FILTER_NUMBER) ); + $this->setTemplateVar('projectid' ,$this->getRequestVar('projectid' ,OR_FILTER_NUMBER) ); + $this->setTemplateVar('modelid' ,$this->getRequestVar('modelid' ,OR_FILTER_NUMBER) ); + $this->setTemplateVar('languageid',$this->getRequestVar('languageid',OR_FILTER_NUMBER) ); + + $this->setTemplateVar('register' ,$conf['login' ]['register' ]); + $this->setTemplateVar('send_password',$conf['login' ]['send_password']); + + // Versuchen, einen Benutzernamen zu ermitteln, der im Eingabeformular vorausgewählt wird. + $modules = explode(',',$conf['security']['modules']['preselect']); + + $username = ''; + foreach( $modules as $module) + { + Logger::debug('Preselecting module: '.$module); + $moduleClass = $module.'Auth'; + /** @var \Auth $auth */ + $auth = new $moduleClass; + $username = $auth->username(); + + if ( !empty($username) ) + { + Logger::debug('Preselecting User '.$username); + break; // Benutzername gefunden. + } + } + + $this->setTemplateVar('login_name',$username); + } + + + + /** * Anzeigen der Loginmaske. * * Es wird nur die Loginmaske angezeigt. @@ -431,7 +442,7 @@ class LoginAction extends Action function openidView() { global $conf; - + foreach( $conf['database'] as $dbname=>$dbconf ) { if ( is_array($dbconf) && $dbconf['enabled'] ) @@ -439,7 +450,7 @@ class LoginAction extends Action 'value'=>Text::maxLength($dbconf['description']), 'title'=>$dbconf['description'].(isset($dbconf['host'])?' ('.$dbconf['host'].')':'') ); } - + $openid_provider = array(); foreach( explode(',',$conf['security']['openid']['provider']['name']) as $provider ) $openid_provider[$provider] = config('security','openid','provider.'.$provider.'.name'); @@ -447,17 +458,17 @@ class LoginAction extends Action $this->setTemplateVar('openid_user_identity',config('security','openid','user_identity')); //$this->setTemplateVar('openid_provider','identity'); - + if ( empty($dbids) ) $this->addNotice('','','no_database_configuration',OR_NOTICE_WARN); - + if ( !isset($_COOKIE['or_username']) ) $this->setTemplateVar('login_name',$_COOKIE['or_username']); else $this->setTemplateVar('login_name',$conf['security']['default']['username']); $this->setTemplateVar( 'dbids',$dbids ); - + $db = Session::getDatabase(); if ( is_object($db) ) $this->setTemplateVar('actdbid',$db->id); @@ -468,12 +479,12 @@ class LoginAction extends Action $this->setTemplateVar('projectid' ,$this->getRequestVar('projectid' ,OR_FILTER_NUMBER) ); $this->setTemplateVar('modelid' ,$this->getRequestVar('modelid' ,OR_FILTER_NUMBER) ); $this->setTemplateVar('languageid',$this->getRequestVar('languageid',OR_FILTER_NUMBER) ); - + } - - /** + + /** * Erzeugt ein Projekt-Auswahlmenue. */ function projectmenu() @@ -831,7 +842,7 @@ class LoginAction extends Action catch (ObjectNotFoundException $e) { // Gruppe fehlt. Anlegen? - if ( config('ldap','authorize','auto_add' ) + if ( config('ldap','authorize','auto_add' ) ) { // Die Gruppe in der OpenRat-Datenbank hinzufuegen. $g = new Group(); diff --git a/util/Html.class.php b/util/Html.class.php @@ -26,7 +26,7 @@ */ class Html { - function error( $field ) + public static function error( $field ) { global $inputErrors; @@ -39,7 +39,7 @@ class Html /** * Ausgabe eines Variablenwertes.<br> */ - function debug( $wert, $text='' ) + public static function debug( $wert, $text='' ) { echo "<strong>DEBUG: $text (".gettype($wert).")</strong><br/>"; echo "<pre>"; @@ -51,12 +51,12 @@ class Html /** * Erzeugt eine relative Url innerhalb von Openrat * - * @param Aktion, die aufgerufen werden soll - * @param Unteraktion, die innerhalb der Aktion aufgerufen werden soll - * @param Id fuer diesen Aufruf - * @param Weitere beliebige Parameter + * @param string Aktion, die aufgerufen werden soll + * @param string Unteraktion, die innerhalb der Aktion aufgerufen werden soll + * @param int Id fuer diesen Aufruf + * @param array Weitere beliebige Parameter */ - function url( $action,$subaction='',$id='',$params=array() ) + public static function url( $action,$subaction='',$id='',$params=array() ) { if ( intval($id)==0 ) $id='-'; @@ -147,7 +147,7 @@ class Html - function complete_tag($tagname,$attributes) + public static function complete_tag($tagname,$attributes) { $text = '<'.$tagname; foreach( $attributes as $attribute_name=>$attribute_value ) @@ -156,10 +156,10 @@ class Html $text .= ' />'; return $text; } - - - function open_tag($tagname,$attributes) + + + public static function open_tag($tagname,$attributes) { $text = '<'.$tagname; foreach( $attributes as $attribute_name=>$attribute_value ) @@ -168,9 +168,9 @@ class Html $text .= '>'; return $text; } - - - function close_tag($tagname) + + + public static function close_tag($tagname) { return '</'.$tagname.'>'; } diff --git a/util/Session.class.php b/util/Session.class.php @@ -18,6 +18,8 @@ // PHP-Versionsunabhaengiges Array fuer die Session-Variablen ermitteln +use cms\model\User; + if (isset($_SESSION)) $SESS = &$_SESSION; else $SESS = &$HTTP_SESSION_VARS; @@ -48,7 +50,7 @@ else $FILES = &$HTTP_POST_FILES; class Session { - function get( $var ) + public static function get( $var ) { global $SESS; if ( isset($SESS['ors_'.$var]) ) @@ -56,150 +58,168 @@ class Session else return ''; } - - function set( $var,$value ) + + public static function set( $var,$value ) { global $SESS; $SESS[ 'ors_'.$var ] = $value; - } - + } - function getConfig() + /** + * @return array + */ + public static function getConfig() { return Session::get('config'); } - - function setConfig( $var ) + + public static function setConfig( $var ) { Session::set('config',$var); - } - + } - function getProjectModel() + /** + * @return \cms\model\Model + */ + public static function getProjectModel() { return Session::get('project_model'); } - - function setProjectModel( $var ) + + public static function setProjectModel( $var ) { Session::set('project_model',$var); - } - + } - function getProjectLanguage() + /** + * @return \cms\model\Language + */ + public static function getProjectLanguage() { return Session::get('project_language'); } - - function setProjectLanguage( $var ) + + public static function setProjectLanguage( $var ) { Session::set('project_language',$var); - } + } - function getObject() + public static function getObject() { return Session::get('object'); } - - function setObject( $var ) + + public static function setObject( $var ) { Session::set('object',$var); - } - + } - function getFolder() + /** + * @return \cms\model\Folder + */ + public static function getFolder() { return Session::get('folder'); } - - function setFolder( $var ) + + public static function setFolder( $var ) { Session::set('folder',$var); - } + } - function getTree() + public static function getTree() { return Session::get('tree'); } - - function setTree( $var ) + + public static function setTree( $var ) { Session::set('tree',$var); } - function getElement() + public static function getElement() { return Session::get('element'); } - - function setElement( $var ) + + public static function setElement( $var ) { Session::set('element',$var); - } - + } - function getProject() + /** + * @return \cms\model\Project + */ + public static function getProject() { return Session::get('project'); } - - function setProject( $var ) + + public static function setProject( $var ) { Session::set('project',$var); - } - + } - function getUser() + /** + * @return User + */ + public static function getUser() { return Session::get('userObject'); } - function setUser( $var ) + public static function setUser( $var ) { Session::set('userObject',$var); } - - - function getDatabase() + + + /** + * @return \database\Database + */ + public static function getDatabase() { return Session::get('database'); } - function setDatabase( $var ) + public static function setDatabase( $var ) { Session::set('database',$var); } - - - function getSubaction() + + + /** + * @return string + */ + public static function getSubaction() { return Session::get('subaction'); } - function setSubaction( $var ) + public static function setSubaction( $var ) { Session::set('subaction',$var); } - - - function getClipboard() + + + public static function getClipboard() { return Session::get('clipboard'); } - function setClipboard( $var ) + public static function setClipboard( $var ) { Session::set('clipboard',$var); } @@ -213,7 +233,7 @@ class Session * Nach Aufruf dieser Methode sind keine Session-Zugriffe ueber diese Klasse mehr * moeglich. */ - function close() + public static function close() { session_write_close(); } diff --git a/util/Text.class.php b/util/Text.class.php @@ -1,133 +1,133 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002 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. - - -/** - * Nuetzliche Funktionen fuer das Bearbeiten von Texten/Zeichenketten - * @author $Author$ - * @version $Revision$ - * @package openrat.services - */ -class Text -{ - /** - * - * @param unknown $key - * @param unknown $text - * @return string|unknown - */ - function accessKey( $key, $text ) - { - $pos = strpos(strtolower($text),strtolower($key)); - - if ( $pos !== false ) - return substr($text,0,max($pos,0)).'<span class="accesskey">'.substr($text,$pos,1).'</span>'.substr($text,$pos+1); - else - return $text; - } - - /** - * Alias fuer Methode maxLength() - * - * @deprecated use maxlength() ! - */ - function maxLaenge( $laenge,$text ) - { - return Text::maxLength($text,$laenge); - } - - - /** - * Einen Text auf eine bestimmte Laenge begrenzen. - * - * Ist der Text zu lang, so wird abgeschnitten und - * eine Zeichenkette angehaengt. - * - * @param String Text, der zu begrenzen ist - * @param Integer maximale Laenge des Textes (optional) - * @param Text, der an gekuerzten Text angehangen wird (optional) - */ - function maxLength( $text,$laenge=20,$append='...',$where=STR_PAD_RIGHT ) - { - if ( strlen($text) > $laenge ) - { - if ( $where == STR_PAD_RIGHT ) - $text = substr($text,0,$laenge).$append; - elseif ( $where == STR_PAD_BOTH ) - $text = substr($text,0,$laenge/2).$append.substr($text,strlen($text)-($laenge/2)); - } - - return $text; - } - - - /** - * Umwandeln von BB-Code in Wiki-Textauszeichnungen - * - * @param text zu bearbeitender Text - * - * @return String Ausgabe - */ - function bbCode2Wiki( $inhalt ) - { - $inhalt = preg_replace('/\[b\]([^\[]*)\[\/b\]/i' , '*\\1*' ,$inhalt); - $inhalt = preg_replace('/\[i\]([^\[]*)\[\/i\]/i' , '_\\1_' ,$inhalt); - $inhalt = preg_replace('/\[code\]([^\[]*)\[\/code\]/i' , '=\\1=' ,$inhalt); - - $inhalt = preg_replace('/\[url\]([^\[]*)\[\/url\]/i' ,'"\\1"->"\\1"' ,$inhalt); - $inhalt = preg_replace('/\[url=([^\[]*)\]([^\[]*)\[\/url\]/i' ,'"\\2"->"\\1"' ,$inhalt); - - return $inhalt; - } - - - /** - * Umwandeln von einfachen HTML-Befehlen in Wiki-Textauszeichnungen - * - * @param text zu bearbeitender Text - * - * @return String Ausgabe - */ - function Html2Wiki( $inhalt ) - { - $inhalt = preg_replace('/<b(.*)>(.*)<\/b>/i','*\\2*' ,$inhalt); - $inhalt = preg_replace('/<i(.*)>(.*)<\/i>/i','_\\2_' ,$inhalt); - $inhalt = preg_replace('/<a(.*)href="(.*)">(.*)<\/a>/i','"\\3"->"\\2"' ,$inhalt); - - return $inhalt; - } - - - /** - * HTML-Entitaeten fuer HTML-Tags verwenden - * - * @param String Text, in dem HTML-Tags umgewandelt werden sollen - * @return String Ausgabe - */ - function encodeHtml( $inhalt ) - { - //$inhalt = str_replace('&','&amp;',$inhalt); - $inhalt = str_replace('"','&quot;',$inhalt); - $inhalt = str_replace('<','&lt;' ,$inhalt); - $inhalt = str_replace('>','&gt;' ,$inhalt); - - return $inhalt; - } +<?php +// OpenRat Content Management System +// Copyright (C) 2002 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. + + +/** + * Nuetzliche Funktionen fuer das Bearbeiten von Texten/Zeichenketten + * @author $Author$ + * @version $Revision$ + * @package openrat.services + */ +class Text +{ + /** + * + * @param unknown $key + * @param unknown $text + * @return string|unknown + */ + public static function accessKey( $key, $text ) + { + $pos = strpos(strtolower($text),strtolower($key)); + + if ( $pos !== false ) + return substr($text,0,max($pos,0)).'<span class="accesskey">'.substr($text,$pos,1).'</span>'.substr($text,$pos+1); + else + return $text; + } + + /** + * Alias fuer Methode maxLength() + * + * @deprecated use maxlength() ! + */ + public static function maxLaenge( $laenge,$text ) + { + return Text::maxLength($text,$laenge); + } + + + /** + * Einen Text auf eine bestimmte Laenge begrenzen. + * + * Ist der Text zu lang, so wird abgeschnitten und + * eine Zeichenkette angehaengt. + * + * @param String Text, der zu begrenzen ist + * @param Integer maximale Laenge des Textes (optional) + * @param Text, der an gekuerzten Text angehangen wird (optional) + */ + public static function maxLength( $text,$laenge=20,$append='...',$where=STR_PAD_RIGHT ) + { + if ( strlen($text) > $laenge ) + { + if ( $where == STR_PAD_RIGHT ) + $text = substr($text,0,$laenge).$append; + elseif ( $where == STR_PAD_BOTH ) + $text = substr($text,0,$laenge/2).$append.substr($text,strlen($text)-($laenge/2)); + } + + return $text; + } + + + /** + * Umwandeln von BB-Code in Wiki-Textauszeichnungen + * + * @param text zu bearbeitender Text + * + * @return String Ausgabe + */ + public static function bbCode2Wiki( $inhalt ) + { + $inhalt = preg_replace('/\[b\]([^\[]*)\[\/b\]/i' , '*\\1*' ,$inhalt); + $inhalt = preg_replace('/\[i\]([^\[]*)\[\/i\]/i' , '_\\1_' ,$inhalt); + $inhalt = preg_replace('/\[code\]([^\[]*)\[\/code\]/i' , '=\\1=' ,$inhalt); + + $inhalt = preg_replace('/\[url\]([^\[]*)\[\/url\]/i' ,'"\\1"->"\\1"' ,$inhalt); + $inhalt = preg_replace('/\[url=([^\[]*)\]([^\[]*)\[\/url\]/i' ,'"\\2"->"\\1"' ,$inhalt); + + return $inhalt; + } + + + /** + * Umwandeln von einfachen HTML-Befehlen in Wiki-Textauszeichnungen + * + * @param text zu bearbeitender Text + * + * @return String Ausgabe + */ + public static function Html2Wiki( $inhalt ) + { + $inhalt = preg_replace('/<b(.*)>(.*)<\/b>/i','*\\2*' ,$inhalt); + $inhalt = preg_replace('/<i(.*)>(.*)<\/i>/i','_\\2_' ,$inhalt); + $inhalt = preg_replace('/<a(.*)href="(.*)">(.*)<\/a>/i','"\\3"->"\\2"' ,$inhalt); + + return $inhalt; + } + + + /** + * HTML-Entitaeten fuer HTML-Tags verwenden + * + * @param String Text, in dem HTML-Tags umgewandelt werden sollen + * @return String Ausgabe + */ + public static function encodeHtml( $inhalt ) + { + //$inhalt = str_replace('&','&amp;',$inhalt); + $inhalt = str_replace('"','&quot;',$inhalt); + $inhalt = str_replace('<','&lt;' ,$inhalt); + $inhalt = str_replace('>','&gt;' ,$inhalt); + + return $inhalt; + } @@ -135,7 +135,7 @@ class Text * Ersetzt Sonderzeichen durch HTML-�quivalente.<br> * Z.B. Ersetzt "(c)" durch "&copy;". */ - function replaceHtmlChars( $text ) + public static function replaceHtmlChars( $text ) { global $conf; @@ -150,16 +150,16 @@ class Text - /** - * HTML-Entitaeten fuer HTML-Tags verwenden - * - * @param String Text, in dem HTML-Tags umgewandelt werden sollen - * @return String Ausgabe - */ - function encodeHtmlSpecialChars( $inhalt ) - { - return Text::replaceHtmlChars( $inhalt ); - } + /** + * HTML-Entitaeten fuer HTML-Tags verwenden + * + * @param String Text, in dem HTML-Tags umgewandelt werden sollen + * @return String Ausgabe + */ + public static function encodeHtmlSpecialChars( $inhalt ) + { + return Text::replaceHtmlChars( $inhalt ); + } @@ -167,7 +167,7 @@ class Text * Vergleicht 2 Text-Arrays und ermittelt eine Darstellung der Unterschiede * */ - function diff( $from_text,$to_text ) + public static function diff( $from_text,$to_text ) { // Zaehler pro Textarray $pos_from = -1; @@ -336,60 +336,58 @@ class Text } return( array($from_out,$to_out) ); - } - - - /** - * Entfernt einen Text-Bereich aus einer Zeichenkette.<br> - * Es wird angegeben, von wo bis wo entfernt werden soll. - * - * @param $text Text, aus dem entfernt wird - * @param $von der Text, AB dem entfernt wird - * @param $bis der Text, BIS ZU DEM entfernt wird - * @return String Text - */ - function entferneVonBis($text,$von,$bis) - { - $beg = strpos($text,$von); - $end = strpos($text,$bis); - if ( $beg!==false && $end !==false ) - $text = substr($text,0,$beg).substr($text,$end+strlen($bis)); - return $text; - } - - - /** - * Saeubert eine Zeichenkette. - * - * Es werden ungueltige Zeichen aus einer Zeichenkette entfernt. Es wird mit einer Whitelist - * gearbeitet, d.h. die erlaubten Zeichen werden angegeben. - * - * @param $eingabe Die Eingabe-Zeichenkette, aus der ungueltige Zeichen entfernt werden sollen. - * @param $erlaubt Die erlaubten Zeichen (eine "White-List") - * @return String die aufgeräumte Zeichenkette - */ - function clean( $eingabe, $erlaubt ) - { - $first = strtr( $eingabe, $erlaubt, str_repeat("\x01", strlen($erlaubt)) ); - $second = strtr( $eingabe, $first , str_repeat("\x00", strlen($first )) ); - return str_replace("\x00",'',$second); - } - - - - function parseOID( $text ) - { - $oids = array(); - $treffer = array(); - - preg_match_all('/\"([^\"]*)__OID__([0-9]+)__([^\"]*)\"/', $text, $treffer,PREG_SET_ORDER); - - foreach( $treffer as $t ) - $oids[$t[2]] = $t[0]; - - return $oids; - } -} - - -?>- \ No newline at end of file + } + + + /** + * Entfernt einen Text-Bereich aus einer Zeichenkette.<br> + * Es wird angegeben, von wo bis wo entfernt werden soll. + * + * @param $text Text, aus dem entfernt wird + * @param $von der Text, AB dem entfernt wird + * @param $bis der Text, BIS ZU DEM entfernt wird + * @return String Text + */ + public static function entferneVonBis($text,$von,$bis) + { + $beg = strpos($text,$von); + $end = strpos($text,$bis); + if ( $beg!==false && $end !==false ) + $text = substr($text,0,$beg).substr($text,$end+strlen($bis)); + return $text; + } + + + /** + * Saeubert eine Zeichenkette. + * + * Es werden ungueltige Zeichen aus einer Zeichenkette entfernt. Es wird mit einer Whitelist + * gearbeitet, d.h. die erlaubten Zeichen werden angegeben. + * + * @param $eingabe Die Eingabe-Zeichenkette, aus der ungueltige Zeichen entfernt werden sollen. + * @param $erlaubt Die erlaubten Zeichen (eine "White-List") + * @return String die aufgeräumte Zeichenkette + */ + public static function clean( $eingabe, $erlaubt ) + { + $first = strtr( $eingabe, $erlaubt, str_repeat("\x01", strlen($erlaubt)) ); + $second = strtr( $eingabe, $first , str_repeat("\x00", strlen($first )) ); + return str_replace("\x00",'',$second); + } + + + + public static function parseOID( $text ) + { + $oids = array(); + $treffer = array(); + + preg_match_all('/\"([^\"]*)__OID__([0-9]+)__([^\"]*)\"/', $text, $treffer,PREG_SET_ORDER); + + foreach( $treffer as $t ) + $oids[$t[2]] = $t[0]; + + return $oids; + } +} +