00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 define('PHP_EXT' ,'php' );
00031 require_once( "functions/common.inc.".PHP_EXT );
00032
00033 define('IMG_EXT' ,'.gif' );
00034 define('IMG_ICON_EXT' ,'.png' );
00035 define('MAX_FOLDER_DEPTH',5 );
00036
00037 define('OR_VERSION' ,'0.9-2' );
00038 define('OR_TITLE' ,'OpenRat CMS');
00039
00040 define('OR_TYPE_PAGE' ,'page' );
00041 define('OR_TYPE_FILE' ,'file' );
00042 define('OR_TYPE_LINK' ,'link' );
00043 define('OR_TYPE_FOLDER','folder');
00044
00045 define('OR_ACTIONCLASSES_DIR' ,'./actionClasses/' );
00046 define('OR_FORMCLASSES_DIR' ,'./formClasses/' );
00047 define('OR_OBJECTCLASSES_DIR' ,'./objectClasses/' );
00048 define('OR_SERVICECLASSES_DIR','./serviceClasses/' );
00049 define('OR_LANGUAGE_DIR' ,'./language/' );
00050 define('OR_DBCLASSES_DIR' ,'./db/' );
00051 define('OR_DYNAMICCLASSES_DIR','./dynamicClasses/' );
00052 define('OR_TEXTCLASSES_DIR' ,'./textClasses/' );
00053 define('OR_PREFERENCES_DIR' ,defined('OR_EXT_CONFIG_DIR')?OR_EXT_CONFIG_DIR:'./config/');
00054 define('OR_CONFIG_DIR' ,OR_PREFERENCES_DIR );
00055 define('OR_THEMES_DIR' ,'./themes/' );
00056 define('OR_THEMES_EXT_DIR' ,defined('OR_BASE_URL')?slashify(OR_BASE_URL).'themes/':OR_THEMES_DIR);
00057 define('OR_TMP_DIR' ,'./tmp/' );
00058 define('OR_CONTROLLER_FILE' ,defined('OR_EXT_CONTROLLER_FILE')?OR_EXT_CONTROLLER_FILE:'do');
00059 define('START_TIME' ,time() );
00060
00061 define('REQ_PARAM_ACTION' ,'action' );
00062 define('REQ_PARAM_SUBACTION' ,'subaction' );
00063 define('REQ_PARAM_TARGETSUBACTION','targetSubAction');
00064 define('REQ_PARAM_ID' ,'id' );
00065 define('REQ_PARAM_OBJECT_ID' ,'objectid' );
00066 define('REQ_PARAM_LANGUAGE_ID' ,'languageid' );
00067 define('REQ_PARAM_MODEL_ID' ,'modelid' );
00068 define('REQ_PARAM_PROJECT_ID' ,'projectid' );
00069 define('REQ_PARAM_ELEMENT_ID' ,'elementid' );
00070 define('REQ_PARAM_TEMPLATE_ID' ,'templateid' );
00071 define('REQ_PARAM_DATABASE_ID' ,'dbid' );
00072
00073 require_once( "functions/request.inc.php" );
00074
00075
00076 require_once( OR_SERVICECLASSES_DIR."include.inc.".PHP_EXT );
00077 require_once( OR_OBJECTCLASSES_DIR ."include.inc.".PHP_EXT );
00078 require_once( OR_TEXTCLASSES_DIR ."include.inc.".PHP_EXT );
00079
00080
00081 require_once( OR_DBCLASSES_DIR."db.class.php" );
00082 require_once( OR_DBCLASSES_DIR."postgresql.class.php" );
00083 require_once( OR_DBCLASSES_DIR."mysql.class.php" );
00084
00085
00086 session_start();
00087 require_once( OR_SERVICECLASSES_DIR."Session.class.".PHP_EXT );
00088
00089
00090
00091 $conf = Session::getConfig();
00092
00093
00094
00095 if ( !is_array( $conf ) || isset($REQ['reload']) )
00096 {
00097 $prefs = new Preferences();
00098 $conf = $prefs->load();
00099 $conf['action'] = $prefs->load(OR_ACTIONCLASSES_DIR);
00100
00101
00102
00103 if ( $conf['i18n']['use_http'] )
00104
00105 $languages = Http::getLanguages();
00106 else
00107
00108 $languages = array();
00109
00110
00111
00112
00113 $languages[] = $conf['i18n']['default'];
00114 $available = explode(',',$conf['i18n']['available']);
00115
00116 foreach( $languages as $l )
00117 {
00118 if ( !in_array($l,$available) )
00119 continue;
00120
00121
00122 $langFile = OR_LANGUAGE_DIR.$l.'.ini.'.PHP_EXT;
00123
00124 if ( !file_exists( $langFile ) )
00125 Http::serverError("File does not exist: ".$langFile);
00126
00127 $conf['language'] = parse_ini_file( $langFile );
00128 $conf['language']['language_code'] = $l;
00129 break;
00130 }
00131
00132
00133 if ( !isset($conf['language']) )
00134 Http::serverError('no language found! (languages='.implode(',',$languages).')' );
00135
00136
00137
00138 Session::setConfig( $conf );
00139 }
00140
00141 if ( !empty($conf['security']['umask']) )
00142 umask( octdec($conf['security']['umask']) );
00143
00144 if ( !empty($conf['interface']['timeout']) )
00145 set_time_limit( intval($conf['interface']['timeout']) );
00146
00147 define('FILE_SEP',$conf['interface']['file_separator']);
00148
00149 define('TEMPLATE_DIR',OR_THEMES_DIR.$conf['interface']['theme'].'/templates');
00150 define('CSS_DIR' ,OR_THEMES_DIR.$conf['interface']['theme'].'/css' );
00151 define('IMAGE_DIR' ,OR_THEMES_DIR.$conf['interface']['theme'].'/images' );
00152
00153 require_once( OR_SERVICECLASSES_DIR."Logger.class.".PHP_EXT );
00154 require_once( "functions/config.inc.php" );
00155 require_once( "functions/language.inc.".PHP_EXT );
00156 require_once( "functions/theme.inc.".PHP_EXT );
00157 require_once( "functions/db.inc.".PHP_EXT );
00158
00159 header( 'Content-Type: text/html; charset='.lang('CHARSET') );
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 $db = Session::getDatabase();
00182 if ( is_object( $db ) )
00183 {
00184 $ok = $db->connect();
00185 if ( !$ok )
00186 Http::sendStatus('503','Service Unavailable','Database is not available: '.$db->error);
00187
00188 Session::setDatabase( $db );
00189 }
00190
00191 if ( !empty($REQ[REQ_PARAM_ACTION]) )
00192 $action = $REQ[REQ_PARAM_ACTION];
00193 else $action = 'index';
00194
00195 Session::set('action',$action);
00196
00197 if ( !empty( $REQ[REQ_PARAM_SUBACTION] ) )
00198 $subaction = $REQ[REQ_PARAM_SUBACTION];
00199 else
00200 {
00201 $sl = Session::getSubaction();
00202 if ( is_array($sl) && isset($sl[$action]) )
00203 $subaction = $sl[$action];
00204 else
00205 $subaction = '';
00206 }
00207
00208 $actionClassName = strtoupper(substr($action,0,1)).substr($action,1).'Action';
00209
00210 if ( !isset($conf['action'][$actionClassName]) )
00211 Http::serverError("Action '$action' is undefined.");
00212
00213 require( OR_ACTIONCLASSES_DIR.'/Action.class.php' );
00214 require( OR_ACTIONCLASSES_DIR.'/ObjectAction.class.php' );
00215 require( OR_ACTIONCLASSES_DIR.'/'.$actionClassName.'.class.php' );
00216
00217
00218 $do = new $actionClassName;
00219 $do->init();
00220 $do->actionClassName = $actionClassName;
00221 $do->actionName = $action;
00222
00223
00224 $do->actionConfig = $conf['action'][$actionClassName];
00225
00226 if ( $subaction == '' )
00227 $subaction = $do->actionConfig['default']['goto'];
00228
00229 if ( !isset($do->actionConfig[$subaction]) )
00230 {
00231 Logger::warn( "Action $action has no configured method named $subaction");
00232 Http::serverError("Action '$action' has no accessable method '$subaction'.");
00233 exit;
00234 }
00235
00236 $subactionConfig = $do->actionConfig[$subaction];
00237
00238
00239
00240 if ( !isset($subactionConfig['guest']) || !$subactionConfig['guest'] )
00241 if ( !is_object($do->currentUser) )
00242 {
00243 Http::notAuthorized( lang('SESSION_EXPIRED') );
00244 exit;
00245 }
00246
00247
00248 if ( isset($do->actionConfig['admin']) && $do->actionConfig['admin'] )
00249 if ( !$do->currentUser->isAdmin )
00250 {
00251 Http::notAuthorized( lang('SESSION_EXPIRED') );
00252 exit;
00253 }
00254
00255
00256
00257 if ( isset($do->actionConfig[$subaction]['menu']) || isset($do->actionConfig[$subaction]['direct']) )
00258 {
00259 $sl = Session::getSubaction();
00260 if ( !is_array($sl))
00261 $sl = array();
00262 $sl[$action] = $subaction;
00263 Session::setSubaction( $sl );
00264 }
00265
00266 $do->subActionName = $subaction;
00267
00268
00269 if ( isset($do->actionConfig[$do->subActionName]['alias']) )
00270 {
00271 $subaction = $do->actionConfig[$do->subActionName]['alias'];
00272
00273 }
00274
00275
00276
00277 $do->$subaction();
00278
00279
00280 if ( isset($do->actionConfig[$do->subActionName]['goto']) )
00281 {
00282 if ( $conf['interface']['redirect'] )
00283 {
00284 $subActionName = $do->actionConfig[$do->subActionName]['goto'];
00285 header( 'HTTP/1.0 303 See other');
00286
00287 header( 'Location: '.Html::url($action,$do->actionConfig[$do->subActionName]['goto'],$do->getRequestId()) );
00288 exit;
00289 }
00290
00291 $subActionName = $do->actionConfig[$do->subActionName]['goto'];
00292 $do->subActionName = $subActionName;
00293 $subaction = $subActionName;
00294
00295
00296 if ( isset($do->actionConfig[$do->subActionName]['alias']) )
00297 {
00298 $subaction = $do->actionConfig[$do->subActionName]['alias'];
00299 }
00300
00301 Logger::trace("controller is calling next subaction '$subaction'");
00302 $do->$subaction();
00303 }
00304
00305 $do->setMenu();
00306 $do->forward();
00307
00308
00309 ?>