openrat-cms

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

commit 3e439192804e85f22fe4392b6da3351deef9612d
parent 353898e183d331c65614a945d6dac354e0f547fc
Author: Jan Dankert <develop@jandankert.de>
Date:   Sat, 26 Sep 2020 12:20:43 +0200

Refactoring: No global variables like $SESS  any more. All constants are capsulated by classes.

Diffstat:
modules/cms/Dispatcher.class.php | 12+++++-------
modules/cms/action/Action.class.php | 10++--------
modules/cms/action/ElementAction.class.php | 40+++++++++++++++++-----------------------
modules/cms/action/FolderAction.class.php | 6------
modules/cms/action/LanguagelistAction.class.php | 7++++---
modules/cms/action/LoginAction.class.php | 7++-----
modules/cms/action/PageAction.class.php | 2--
modules/cms/action/ProjectAction.class.php | 2--
modules/cms/action/RequestParams.class.php | 17+++++++++--------
modules/cms/action/TemplateAction.class.php | 2--
modules/cms/api/API.class.php | 1-
modules/cms/auth/OpenIdAuth.class.php | 2+-
modules/cms/base/HttpRequest.class.php | 19+++++++++++++++++++
modules/cms/base/HttpResponse.class.php | 11+++++++++++
modules/cms/base/Startup.class.php | 42++++++++++++------------------------------
modules/cms/generator/ValueGenerator.class.php | 3++-
modules/cms/model/BaseObject.class.php | 3---
modules/cms/model/File.class.php | 31-------------------------------
modules/cms/model/Folder.class.php | 8+++++++-
modules/cms/model/Group.class.php | 29+----------------------------
modules/cms/model/Language.class.php | 6++----
modules/cms/model/Model.class.php | 1-
modules/cms/model/Url.class.php | 1-
modules/cms/ui/action/IndexAction.class.php | 9+++++----
modules/cms/ui/themes/default/layout/index.php | 10+++++-----
modules/template_engine/TemplateCompiler.php | 41++++++++++++++++++++++++++++++++++-------
modules/template_engine/components/html/button/Button.class.php | 3++-
modules/template_engine/components/html/image/Image.class.php | 13+++++++------
modules/template_engine/components/html/upload/Upload.class.php | 2+-
modules/template_engine/engine/TemplateEngine.class.php | 17+++--------------
modules/util/Api.class.php | 29++++-------------------------
modules/util/Code.class.php | 3---
modules/util/GlobalFunctions.class.php | 35-----------------------------------
modules/util/Html.class.php | 1-
modules/util/Http.class.php | 4+---
35 files changed, 156 insertions(+), 273 deletions(-)

diff --git a/modules/cms/Dispatcher.class.php b/modules/cms/Dispatcher.class.php @@ -13,6 +13,7 @@ use cms\base\DefaultConfig; use configuration\ConfigurationLoader; use database\Database; use cms\update\Update; +use modules\cms\base\HttpRequest; use util\Http; use logger\Logger; use LogicException; @@ -157,9 +158,8 @@ class Dispatcher private function checkPostToken() { - global $REQ; - if (\cms\base\Configuration::config('security', 'use_post_token') && $_SERVER['REQUEST_METHOD'] == 'POST' && @$REQ[REQ_PARAM_TOKEN] != Session::token()) { - Logger::error('Token mismatch: Needed ' . Session::token() . ' but got ' . Logger::sanitizeInput(@$REQ[REQ_PARAM_TOKEN]) . '. Maybe an attacker?'); + if (\cms\base\Configuration::config('security', 'use_post_token') && $this->request->isAction && $this->request->getToken() != Session::token()) { + Logger::error('Token mismatch: Needed ' . Session::token() . ' but got ' . Logger::sanitizeInput($this->request->getToken()) . '. Maybe an attacker?'); throw new SecurityException("Token mismatch"); } } @@ -176,8 +176,7 @@ class Dispatcher // Wenn Logfile relativ angegeben wurde, dann muss dies relativ zum Root der Anwendung sein. if ( !empty($logFile) && $logFile[0] != '/' ) - $logFile = CMS_ROOT_DIR . $logFile; - //$logFile = __DIR__.'/../../'.$logFile; + $logFile = __DIR__ . '/../../' . $logFile; Logger::$messageFormat = $logConfig['format']; Logger::$filename = $logFile; @@ -275,7 +274,6 @@ class Dispatcher */ private function callActionMethod() { - global $REQ; $actionClassName = ucfirst($this->request->action) . 'Action'; $actionClassNameWithNamespace = 'cms\\action\\' . $actionClassName; @@ -313,7 +311,7 @@ class Dispatcher if ( ! $this->request->isAction && $this->request->action != 'index' ) Session::close(); - Logger::debug("Dispatcher executing {$this->request->action}/{$this->request->method}/" . @$REQ[REQ_PARAM_ID].' -> '.$actionClassName.'#'.$subactionMethodName.'()'); + Logger::debug("Dispatcher executing {$this->request->action}/{$this->request->method}/" . $this->request->getRequestId().' -> '.$actionClassName.'#'.$subactionMethodName.'()'); try { diff --git a/modules/cms/action/Action.class.php b/modules/cms/action/Action.class.php @@ -100,11 +100,7 @@ namespace cms\action { */ protected function getSessionVar($varName) { - global $SESS; - - if (!isset($SESS[$varName])) - return ''; - else return $SESS[$varName]; + return Session::get($varName); } @@ -117,9 +113,7 @@ namespace cms\action { */ protected function setSessionVar($varName, $value) { - global $SESS; - - $SESS[$varName] = $value; + Session::set($varName,$value); } diff --git a/modules/cms/action/ElementAction.class.php b/modules/cms/action/ElementAction.class.php @@ -419,39 +419,33 @@ class ElementAction extends BaseAction case Element::ELEMENT_TYPE_DYNAMIC: - $className = $this->element->subtype; - $fileName = OR_DYNAMICCLASSES_DIR.'/'.$className.'.class.'.PHP_EXT; + $className = '\\cms\\macros\\macro\\'.ucfirst($this->element->subtype); $description = ''; $paramList = array(); $parameters = array(); - if ( is_file( $fileName ) ) - { - require( $fileName ); - - if ( class_exists($className) ) - { - $dynEl = new $className; + if ( class_exists($className) ) + { + $dynEl = new $className; - $description = $dynEl->description; + $description = $dynEl->description; - $old = $this->element->getDynamicParameters(); + $old = $this->element->getDynamicParameters(); - $reflect = new ReflectionClass($dynEl); - $props = $reflect->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); - foreach( get_object_vars($dynEl) as $paramName=>$paramValue ) - { - $paramList[$paramName] = print_r( $paramValue, true); + $reflect = new ReflectionClass($dynEl); + $props = $reflect->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); + foreach( get_object_vars($dynEl) as $paramName=>$paramValue ) + { + $paramList[$paramName] = print_r( $paramValue, true); - if ( @$old[$paramName] ) - $parameters[$paramName] = $old[$paramName]; - else - $parameters[$paramName] = $paramValue; - } + if ( @$old[$paramName] ) + $parameters[$paramName] = $old[$paramName]; + else + $parameters[$paramName] = $paramValue; + } - } - } + } $this->setTemplateVar('dynamic_class_description',$description ); $this->setTemplateVar('dynamic_class_parameters' ,$paramList ); diff --git a/modules/cms/action/FolderAction.class.php b/modules/cms/action/FolderAction.class.php @@ -997,8 +997,6 @@ class FolderAction extends ObjectAction */ public function editView() { - global $conf_php; - if ( ! $this->folder->isRoot ) $this->setTemplateVar('parentid',$this->folder->parentid); @@ -1057,8 +1055,6 @@ class FolderAction extends ObjectAction */ public function contentView() { - global $conf_php; - if ( ! $this->folder->isRoot ) $this->setTemplateVar('up_url',Html::url('folder','show',$this->folder->parentid)); @@ -1214,8 +1210,6 @@ class FolderAction extends ObjectAction */ public function orderView() { - global $conf_php; - $list = array(); $last_objectid = 0; diff --git a/modules/cms/action/LanguagelistAction.class.php b/modules/cms/action/LanguagelistAction.class.php @@ -2,6 +2,7 @@ namespace cms\action; +use cms\base\Configuration; use cms\model\Language; @@ -107,8 +108,7 @@ class LanguagelistAction extends BaseAction */ function addView() { - $conf = \cms\base\Configuration::rawConfig(); - $countryList = $conf['countries']; + $countryList = Configuration::subset('countries')->getConfig(); foreach( $this->project->getLanguageIds() as $id ) { @@ -119,7 +119,8 @@ class LanguagelistAction extends BaseAction unset( $countryList[$l->isoCode] ); } - asort( $countryList ); + asort( $countryList ); + $this->setTemplateVar('isocodes' ,$countryList ); $this->setTemplateVar('isocode' ,'' ); } diff --git a/modules/cms/action/LoginAction.class.php b/modules/cms/action/LoginAction.class.php @@ -73,9 +73,8 @@ class LoginAction extends BaseAction Logger::debug( "Login user: '$name'.'" ); $conf = \cms\base\Configuration::rawConfig(); - global $SESS; - - unset( $SESS['user'] ); + + Session::setUser(null); $db = \cms\base\DB::get(); @@ -1058,8 +1057,6 @@ class LoginAction extends BaseAction function show() { $conf = \cms\base\Configuration::rawConfig(); - global $PHP_AUTH_USER; - global $PHP_AUTH_PW; $user = Session::getUser(); // Gast-Login diff --git a/modules/cms/action/PageAction.class.php b/modules/cms/action/PageAction.class.php @@ -548,8 +548,6 @@ class PageAction extends ObjectAction */ function formView() { - global $conf_php; - $list = array(); foreach( $this->page->values as $id=>$value ) diff --git a/modules/cms/action/ProjectAction.class.php b/modules/cms/action/ProjectAction.class.php @@ -122,8 +122,6 @@ class ProjectAction extends BaseAction */ function listingView() { - global $conf_php; - // Projekte ermitteln $list = array(); diff --git a/modules/cms/action/RequestParams.class.php b/modules/cms/action/RequestParams.class.php @@ -86,12 +86,10 @@ namespace cms\action { if($varName == REQ_PARAM_SUBACTION) return $this->method; - global $REQ; - - if (!isset($REQ[$varName])) + if (!isset($_REQUEST[$varName])) return ''; - return $this->cleanText( $REQ[$varName], $transcode ); + return $this->cleanText( $_REQUEST[$varName], $transcode ); } @@ -145,9 +143,7 @@ namespace cms\action { */ public function hasRequestVar($varName) { - global $REQ; - - return (isset($REQ[$varName]) && (!empty($REQ[$varName]) || $REQ[$varName] == '0')); + return (isset($_REQUEST[$varName]) && (!empty($_REQUEST[$varName]) || $_REQUEST[$varName] == '0')); } @@ -199,5 +195,10 @@ namespace cms\action { { return $this->getRequestVar(REQ_PARAM_PROJECT_ID,OR_FILTER_NUMBER); } - } + + public function getToken() + { + return $this->getRequestVar(REQ_PARAM_TOKEN,OR_FILTER_ALPHANUM); + } + } } \ No newline at end of file diff --git a/modules/cms/action/TemplateAction.class.php b/modules/cms/action/TemplateAction.class.php @@ -548,8 +548,6 @@ class TemplateAction extends BaseAction // function listingView() { - global $conf_php; - $list = array(); $project = new Project( $this->template->projectid ); diff --git a/modules/cms/api/API.class.php b/modules/cms/api/API.class.php @@ -110,7 +110,6 @@ class API break; case CMS_API_OUTPUT_XML: - require_once(OR_SERVICECLASSES_DIR . "XML.class." . PHP_EXT); $xml = new XML(); $xml->root = 'server'; // Name des XML-root-Elementes header('Content-Type: application/xml; charset=UTF-8'); diff --git a/modules/cms/auth/OpenIdAuth.class.php b/modules/cms/auth/OpenIdAuth.class.php @@ -220,7 +220,7 @@ class OpenIdAuth implements Auth $trustRoot = $server; $redirHttp->requestParameter['openid.trust_root'] = FileUtils::slashify($trustRoot); - $redirHttp->requestParameter['openid.return_to'] = FileUtils::slashify($server) . 'openid.' . PHP_EXT; + $redirHttp->requestParameter['openid.return_to'] = FileUtils::slashify($server) . 'openid.php'; // FIXME url //$redirHttp->requestParameter['openid.realm' ] = slashify($server).'openid.'.PHP_EXT; $redirHttp->requestParameter['openid.assoc_handle'] = $this->handle; diff --git a/modules/cms/base/HttpRequest.class.php b/modules/cms/base/HttpRequest.class.php @@ -0,0 +1,18 @@ +<?php + + +namespace modules\cms\base; + + +class HttpRequest +{ + + public static function isPost() { + + return $_SERVER['REQUEST_METHOD'] == 'POST'; + } + + public static function getToken() { + return $_REQUEST['REQUEST_METHOD'] == 'POST'; + } +}+ \ No newline at end of file diff --git a/modules/cms/base/HttpResponse.class.php b/modules/cms/base/HttpResponse.class.php @@ -0,0 +1,10 @@ +<?php + + +namespace modules\cms\base; + + +class HttpResponse +{ + +}+ \ No newline at end of file diff --git a/modules/cms/base/Startup.class.php b/modules/cms/base/Startup.class.php @@ -23,7 +23,13 @@ use util\exception\ValidationException; class Startup { - const MIN_VERSION = '5.4'; + const MIN_VERSION = '5.4'; // minimum required PHP version. + + const IMG_EXT = '.gif'; + const IMG_ICON_EXT = '.png'; + + const HTML_MODULES_DIR = './modules/'; + const THEMES_DIR = './modules/cms/ui/themes/'; /** * Initialize. @@ -34,7 +40,6 @@ class Startup { self::securityCheck(); self::setErrorHandler(); self::setConstants(); - self::createRequest(); } public static function checkPHPVersion() @@ -46,28 +51,9 @@ class Startup { 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/'); + define('OR_TITLE' , 'OpenRat CMS'); + define('START_TIME', time()); // The start time of the script. } @@ -122,6 +108,9 @@ class Startup { } + /** + * Check for some stupid security impacts. + */ public static function securityCheck() { // REGISTER_GLOBALS @@ -137,13 +126,6 @@ class Startup { } - public static function createRequest() - { - // TODO: We should use $_REQUEST everywhere. - global $REQ; - $REQ = array_merge($_GET, $_POST); - } - /** * Stellt fest, ob das System in einem schreibgeschuetzten Zustand ist. diff --git a/modules/cms/generator/ValueGenerator.class.php b/modules/cms/generator/ValueGenerator.class.php @@ -6,6 +6,7 @@ namespace cms\generator; use cms\base\Configuration as C; use cms\base\DB; +use cms\base\Startup; use cms\macros\MacroRunner; use cms\model\BaseObject; use cms\model\Element; @@ -1006,7 +1007,7 @@ class ValueGenerator extends BaseGenerator if ( $this->context->pageContext->scheme == Producer::SCHEME_PREVIEW && $element->withIcon && $page->isHtml() ) { // Anklickbaren Link voranstellen. - $iconLink = '<a href="javascript:parent.openNewAction(\''.$element->name.'\',\'pageelement\',\''.$page->objectid.'_'.$element->elementid.'\');" title="'.$element->desc.'"><img src="'.OR_THEMES_DIR.$conf['interface']['theme'].'/images/icon_el_'.$element->type.IMG_ICON_EXT.'" border="0" align="left"></a>'; + $iconLink = '<a href="javascript:parent.openNewAction(\''.$element->name.'\',\'pageelement\',\''.$page->objectid.'_'.$element->elementid.'\');" title="'.$element->desc.'"><img src="'.Startup::THEMES_DIR.$conf['interface']['theme'].'/images/icon_el_'.$element->type.Startup::IMG_ICON_EXT.'" border="0" align="left"></a>'; $inhalt = $iconLink.$inhalt; } diff --git a/modules/cms/model/BaseObject.class.php b/modules/cms/model/BaseObject.class.php @@ -240,8 +240,6 @@ class BaseObject extends ModelBase */ function __construct($objectid = '') { - global $SESS; - if ( is_numeric($objectid) ) { $this->objectid = $objectid; @@ -710,7 +708,6 @@ SQL */ function objectLoadRaw() { - global $SESS; $db = \cms\base\DB::get(); $sql = $db->sql('SELECT * FROM {{object}}'. diff --git a/modules/cms/model/File.class.php b/modules/cms/model/File.class.php @@ -104,37 +104,6 @@ class File extends BaseObject /** - * @deprecated - */ - function getFileObjectIdsByExtension( $extension ) - { - global $SESS; - $db = \cms\base\DB::get(); - - $sqlquery = 'SELECT * FROM {{object}} '; - - if ( $extension != '' ) - { - $sqlquery .= " WHERE extension='"; - - $ext = explode(',',$extension); - $sqlquery .= implode( "' OR extension='",$ext ); - $sqlquery .= "' AND typeid=".BaseObject::TYPEID_FILE." AND projectid={projectid}"; - } - else - { - $sqlquery .= " WHERE typeid=".BaseObject::TYPEID_FILE." AND projectid={projectid}"; - } - - $sql = $db->sql( $sqlquery ); - $sql->setInt( 'projectid',$SESS['projectid'] ); - - return $sql->getCol(); - } - - - - /** * Es werden Objekte zu einer Dateierweiterung ermittelt * * @param String Dateierweiterung ohne fuehrenden Punkt (z.B. 'jpeg') diff --git a/modules/cms/model/Folder.class.php b/modules/cms/model/Folder.class.php @@ -358,7 +358,13 @@ class Folder extends BaseObject } - // Rechte f?r diesen Ordner hinzuf?gen + + /** + * Rechte f?r diesen Ordner hinzuf?gen. + * @param $rights + * @param bool $inherit + * @deprecated unused? bad code. + */ function addrights( $rights,$inherit = true ) { global $SESS; diff --git a/modules/cms/model/Group.class.php b/modules/cms/model/Group.class.php @@ -17,6 +17,7 @@ namespace cms\model; // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use cms\base\DB as Db; +use util\Session; /** @@ -251,7 +252,6 @@ class Group extends ModelBase // Alle Berechtigungen ermitteln function getRights() { - global $SESS,$conf_php; $db = \cms\base\DB::get(); $var = array(); @@ -282,7 +282,6 @@ class Group extends ModelBase $folder->load(); $var[$projectid]['rights'][$aclid] = $acl; $var[$projectid]['rights'][$aclid]['foldername'] = implode(' &raquo; ',$folder->parentfolder( false,true )); - $var[$projectid]['rights'][$aclid]['delete_url'] = 'user.'.$conf_php.'?useraction=delright&aclid='.$aclid; } $sql = $db->sql( 'SELECT id FROM {{folder}}'. @@ -305,34 +304,8 @@ class Group extends ModelBase return $var; } - - // Berechtigung der Gruppe hinzufuegen - function addRight( $data ) - { - global $REQ,$SESS; - $db = \cms\base\DB::get(); - - $sql = $db->sql('INSERT INTO {{acl}} '. - '(userid,groupid,folderid,`read`,`write`,`create`,`delete`,publish) '. - 'VALUES({userid},{groupid},{folderid},{read},{write},{create},{delete},{publish})'); - - $sql->setNull('userid'); - $sql->setInt ('groupid',$this->groupid); - $sql->setInt ('projectid',$SESS['projectid']); - $sql->setInt ('folderid',$data['folderid']); - - $sql->setInt ('read' ,$data['read' ]); - $sql->setInt ('write' ,$data['write' ]); - $sql->setInt ('create' ,$data['create' ]); - $sql->setInt ('delete' ,$data['delete' ]); - $sql->setInt ('publish',$data['publish']); - - // Datenbankabfrage ausf?hren - $sql->query(); - } - /** * Ermitteln aller Berechtigungen dieser Gruppe.<br> * Diese Daten werden auf der Gruppenseite in der Administration angezeigt. diff --git a/modules/cms/model/Language.class.php b/modules/cms/model/Language.class.php @@ -16,6 +16,7 @@ namespace cms\model; // 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 cms\base\Configuration; use cms\base\DB as Db; @@ -140,8 +141,6 @@ class Language extends ModelBase */ function add( $isocode='' ) { - global $SESS; - global $iso; $db = \cms\base\DB::get(); if ( $isocode != '' ) @@ -150,7 +149,7 @@ class Language extends ModelBase $isocode = str_replace('_','',$isocode); $this->isocode = $isocode; - $codes = \util\GlobalFunctions::getIsoCodes(); + $codes = Configuration::subset('countries')->getConfig(); $this->name = $codes[ $isocode ]; } @@ -173,7 +172,6 @@ class Language extends ModelBase // Diese Sprache als 'default' markieren. function setDefault() { - global $SESS; $db = \cms\base\DB::get(); // Zuerst alle auf nicht-Standard setzen diff --git a/modules/cms/model/Model.class.php b/modules/cms/model/Model.class.php @@ -154,7 +154,6 @@ class Model extends ModelBase // Diese Sprache als 'default' markieren. function setDefault() { - global $SESS; $db = \cms\base\DB::get(); // Zuerst alle auf nicht-Standard setzen diff --git a/modules/cms/model/Url.class.php b/modules/cms/model/Url.class.php @@ -62,7 +62,6 @@ class Url extends BaseObject public function save() { - global $SESS; $db = \cms\base\DB::get(); $sql = $db->sql('UPDATE {{url}} SET '. diff --git a/modules/cms/ui/action/IndexAction.class.php b/modules/cms/ui/action/IndexAction.class.php @@ -3,6 +3,7 @@ namespace cms\action; use cms\auth\Auth; +use cms\base\Startup; use cms\model\BaseObject; use cms\model\Project; use cms\model\User; @@ -168,14 +169,14 @@ class IndexAction extends Action private function getCSSFiles() { return array( - OR_THEMES_DIR . 'default/style/openrat'.(PRODUCTION?'.min':'').'.css' + Startup::THEMES_DIR . 'default/style/openrat'.(PRODUCTION?'.min':'').'.css' ); } public function themestyleView() { - $themeLessFile = OR_THEMES_DIR . 'default/style/theme/openrat-theme.less'; + $themeLessFile = Startup::THEMES_DIR . 'default/style/theme/openrat-theme.less'; $this->lastModified(filemtime($themeLessFile)); header('Content-Type: text/css'); @@ -188,7 +189,7 @@ class IndexAction extends Action private function getThemeCSS() { // Je Theme die Theme-CSS-Datei ausgeben. - $lessFile = OR_THEMES_DIR . 'default/style/theme/openrat-theme.less'; + $lessFile = Startup::THEMES_DIR . 'default/style/theme/openrat-theme.less'; $css = ''; @@ -235,7 +236,7 @@ class IndexAction extends Action private function getJSFiles() { return array( - OR_THEMES_DIR . 'default/script/openrat'.(PRODUCTION?'.min':'').'.js' + Startup::THEMES_DIR . 'default/script/openrat'.(PRODUCTION?'.min':'').'.js' ); } diff --git a/modules/cms/ui/themes/default/layout/index.php b/modules/cms/ui/themes/default/layout/index.php @@ -1,5 +1,5 @@ <?php - use util\Html;extract($output); + use cms\base\Startup;use util\Html;extract($output); if (!defined('OR_VERSION')) die('Forbidden'); if (!headers_sent()) header('Content-Type: text/html; charset=UTF-8') ?><!DOCTYPE html> @@ -16,7 +16,7 @@ <meta name="robots" content="noindex,nofollow" > <?php foreach( $jsFiles as $jsFile ) { ?> <script src="<?php echo $jsFile ?>" defer></script> <?php } ?> - <link rel="stylesheet" type="text/css" href="<?php echo OR_HTML_MODULES_DIR . 'editor/codemirror/lib/codemirror.css' ?>" /> + <link rel="stylesheet" type="text/css" href="<?php echo Startup::HTML_MODULES_DIR . 'editor/codemirror/lib/codemirror.css' ?>" /> <?php foreach( $cssFiles as $cssFile) { ?> <link rel="stylesheet" type="text/css" href="<?php echo $cssFile ?>" /> <?php } ?> <link rel="stylesheet" type="text/css" href="<?php echo Html::url('index','themestyle',0,array('embed'=>'1')) ?>" /> @@ -66,9 +66,9 @@ <!-- <div class="view-toolbar"> - <img src="<?php echo OR_THEMES_DIR ?>/default/images/icon/menu/fullscreen.svg" class="image-icon on-normalscreen toolbar-action-fullscreen" /> - <img src="<?php echo OR_THEMES_DIR ?>/default/images/icon/menu/fullscreen_exit.svg" class="image-icon on-fullscreen toolbar-action-exit-fullscreen" /> - <img src="<?php echo OR_THEMES_DIR ?>/default/images/icon/menu/refresh.svg" class="image-icon toolbar-action-refresh" /> + <img src="<?php echo Startup::THEMES_DIR ?>/default/images/icon/menu/fullscreen.svg" class="image-icon on-normalscreen toolbar-action-fullscreen" /> + <img src="<?php echo Startup::THEMES_DIR ?>/default/images/icon/menu/fullscreen_exit.svg" class="image-icon on-fullscreen toolbar-action-exit-fullscreen" /> + <img src="<?php echo Startup::THEMES_DIR ?>/default/images/icon/menu/refresh.svg" class="image-icon toolbar-action-refresh" /> </div> --> diff --git a/modules/template_engine/TemplateCompiler.php b/modules/template_engine/TemplateCompiler.php @@ -14,21 +14,48 @@ use util\FileUtils; \cms\base\Startup::initialize(); -$dir = __DIR__ . '/../../modules/cms/ui/themes/default/html/views'; +$searchDir = __DIR__ . '/../../modules/cms/ui/themes/default/html/views'; -echo "Searching in $dir\n"; +echo "Searching in $searchDir\n"; $count = 0; -foreach(FileUtils::readDir( $dir ) as $action ) + +spl_autoload_register( + +/** + * Loads component classes. + * + * @param $className Class name + * @return void + */ + function ($className) { + + if ( substr($className,-9) == 'Component') + { + $pos = strrpos($className, '\\'); + $className = substr($className, $pos + 1); + + $componentName = substr($className,0,-9 ); + + $c = __DIR__.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'html'.DIRECTORY_SEPARATOR.strtolower($componentName).DIRECTORY_SEPARATOR.$componentName.'.class.php'; + + if ( is_file($c) ) + require($c); + } + },true,true +); + + +foreach(FileUtils::readDir( $searchDir ) as $action ) { - if ( !is_dir($dir.'/'.$action ) ) + if ( !is_dir($searchDir.'/'.$action ) ) continue; echo "Action: $action\n"; - foreach(FileUtils::readDir( $dir.'/'.$action ) as $file ) + foreach(FileUtils::readDir( $searchDir.'/'.$action ) as $file ) { if ( substr($file,-12 ) == '.tpl.src.xml' ) { @@ -36,8 +63,8 @@ foreach(FileUtils::readDir( $dir ) as $action ) $method = substr($file, 0,-12 ); echo "\tMethod $method\n"; - $templateFile = $dir.'/'.$action.'/'.$file; - $outFile = $dir.'/'.$action.'/'.$method.'.php'; + $templateFile = $searchDir.'/'.$action.'/'.$file; + $outFile = $searchDir.'/'.$action.'/'.$method.'.php'; $engine = new TemplateEngine(); diff --git a/modules/template_engine/components/html/button/Button.class.php b/modules/template_engine/components/html/button/Button.class.php @@ -2,6 +2,7 @@ namespace template_engine\components; +use cms\base\Startup; use template_engine\components\html\Component; use template_engine\element\Element; @@ -34,7 +35,7 @@ HTML; if (! empty($this->src)) { $this->type = 'image'; - $this->tmp_src = $image_dir . 'icon_' . $this->src . IMG_ICON_EXT; + $this->tmp_src = $image_dir . 'icon_' . $this->src . Startup::IMG_ICON_EXT; } else { diff --git a/modules/template_engine/components/html/image/Image.class.php b/modules/template_engine/components/html/image/Image.class.php @@ -2,6 +2,7 @@ namespace template_engine\components; +use cms\base\Startup; use template_engine\components\html\Component; use template_engine\element\CMSElement; @@ -51,19 +52,19 @@ class ImageComponent extends Component } elseif ( $this->type ) { - $file = OR_THEMES_DIR.'default/images/icon_'.$this->type.IMG_ICON_EXT; + $file = Startup::THEMES_DIR.'default/images/icon_'.$this->type.Startup::IMG_ICON_EXT; } elseif ( $this->icon ) { - $file = OR_THEMES_DIR.'default/images/icon/'.$this->icon.IMG_ICON_EXT; + $file = Startup::THEMES_DIR.'default/images/icon/'.$this->icon.Startup::IMG_ICON_EXT; } elseif ( $this->notice ) { - $file = OR_THEMES_DIR.'default/images/notice_'.$this->notice.IMG_ICON_EXT; + $file = Startup::THEMES_DIR.'default/images/notice_'.$this->notice.Startup::IMG_ICON_EXT; } elseif ( $this->tree ) { - $file = OR_THEMES_DIR.'default/images/tree_'.$this->tree.IMG_EXT; + $file = Startup::THEMES_DIR.'default/images/tree_'.$this->tree.Startup::IMG_EXT; } elseif ( $this->url ) { @@ -71,11 +72,11 @@ class ImageComponent extends Component } elseif ( $this->fileext ) { - $file = OR_THEMES_DIR.'default/images/icon/'.$this->fileext; + $file = Startup::THEMES_DIR.'default/images/icon/'.$this->fileext; } elseif ( $this->file ) { - $file = OR_THEMES_DIR.'default/images/icon/'.$this->file.IMG_ICON_EXT; + $file = Startup::THEMES_DIR.'default/images/icon/'.$this->file.Startup::IMG_ICON_EXT; } if ( $this->class ) diff --git a/modules/template_engine/components/html/upload/Upload.class.php b/modules/template_engine/components/html/upload/Upload.class.php @@ -23,7 +23,7 @@ class UploadComponent extends Component if ( $this->multiple ) $input->addAttribute( 'multiple','multiple' ); - $input->addAttribute('id',REQUEST_ID.'_'.$this->name); + //$input->addAttribute('id',REQUEST_ID.'_'.$this->name); $input->addAttribute('name',$this->name); $input->addAttribute('size',$this->size); diff --git a/modules/template_engine/engine/TemplateEngine.class.php b/modules/template_engine/engine/TemplateEngine.class.php @@ -33,14 +33,6 @@ class TemplateEngine const CSS_PREFIX = 'or-'; - - /** - * Erzeugt einen Templateparser. - */ - public function __construct() - { - } - /** * Compile the template. * From a XML source file we are generating a PHP file. @@ -140,14 +132,11 @@ class TemplateEngine } $className = ucfirst($tag); - $classFilename = dirname(__FILE__).'/../components/'.$this->renderType."/$tag/$className.class." . PHP_EXT; - - if (!is_file($classFilename)) - throw new LogicException("Component Class File '$classFilename' does not exist." ); + $className = 'template_engine\components\\'.$className.'Component'; - require_once ($classFilename); + if ( !class_exists($className )) + throw new LogicException("Component class ".$className.' does not exist'); - $className = 'template_engine\components\\'.$className .'Component'; /* @var $component Component */ $component = new $className(); $component->setDepth($depth+1); diff --git a/modules/util/Api.class.php b/modules/util/Api.class.php @@ -25,9 +25,7 @@ use cms\model\Project; * Service-Klasse fuer allgemeine Interface-Methoden. Insbesondere * in Code-Elementen kann und soll auf diese Methoden zurueckgegriffen * werden. - * @author $Author$ - * @version $Revision$ - * @package openrat.services + * @deprecated use Macro methods. */ class Api { @@ -42,9 +40,7 @@ class Api function pageid() { - echo 'WARNING: pageid() deprecated!<br>'; - global $SESS; - return $SESS['objectid']; + throw new \LogicException( 'WARNING: pageid() deprecated!'); } function getObjectId() @@ -63,30 +59,13 @@ class Api return $project::getRootObjectId(); } + function folderid() { - global $SESS; - return $SESS['folderid']; + throw new \LogicException('folderid() impossible to call, information does not exist'); } - function execute($code) - { - global $conf_tmpdir; - $code = "<?php\n" . $code . "\n?>"; - - $tmp = $conf_tmpdir . '/' . md5(microtime()) . '.tmp'; - $f = fopen($tmp, 'w'); - fwrite($f, $code); - fclose($f); - - require($tmp); // Ausfuehren des temporaeren PHP-Codes - - unlink($tmp); - $inhalt = Api::getOutput(); - $this->output($inhalt); - } - function delOutput() { $this->output = ''; diff --git a/modules/util/Code.class.php b/modules/util/Code.class.php @@ -22,9 +22,6 @@ use logger\Logger; use util\Macro; /** - * @author $Author$ - * @version $Revision$ - * @package openrat.services */ class Code extends Macro { diff --git a/modules/util/GlobalFunctions.class.php b/modules/util/GlobalFunctions.class.php @@ -1,35 +0,0 @@ -<?php - -namespace util; -/** - * Bereitstellen von globalen Funktionen - * @author $Author$ - * @version $Revision$ - * @package openrat.services - */ -class GlobalFunctions -{ - public static function getIsoCodes() - { - global $conf_php; - - $iso = parse_ini_file('./language/lang.ini.' . $conf_php); - asort($iso); - return $iso; - } - - - public static function lang($text) - { - global $SESS; - $text = strtoupper($text); - - if (isset($SESS['lang'][$text])) { - return $SESS['lang'][$text]; - } else { - return ('?' . $text . '?'); - } - } - - -} diff --git a/modules/util/Html.class.php b/modules/util/Html.class.php @@ -84,7 +84,6 @@ class Html // if ( $id != '' ) // $id = '.'.$id; } else { - global $view; $params[REQ_PARAM_ACTION] = $action; $params[REQ_PARAM_SUBACTION] = $subaction; $params[REQ_PARAM_ID] = $id; diff --git a/modules/util/Http.class.php b/modules/util/Http.class.php @@ -348,10 +348,8 @@ class Http */ public static function getLanguages() { - global $HTTP_SERVER_VARS; - $languages = array(); - $http_languages = @$HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE']; + $http_languages = @$_SERVER['HTTP_ACCEPT_LANGUAGE']; foreach (explode(',', $http_languages) as $l) { list($part) = explode(';', $l); // Priorit�ten ignorieren. $languages[] = trim($part);