Skip to content

Commit f17e5b0

Browse files
author
pedro_morgan
committed
Tidied up app.inc.php
* now php5 class * Inctroducted $_loaded_modules class var to silence "undefined property" error * Cleaned code to PEAR standards
1 parent 0922332 commit f17e5b0

File tree

1 file changed

+130
-135
lines changed

1 file changed

+130
-135
lines changed

interface/lib/app.inc.php

Lines changed: 130 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -27,94 +27,91 @@
2727
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
*/
2929

30-
ob_start("ob_gzhandler");
30+
ob_start('ob_gzhandler');
3131

3232
class app {
3333

34-
var $_language_inc = 0;
35-
var $_wb;
36-
37-
function app() {
38-
39-
global $conf;
40-
41-
if($conf["start_db"] == true) {
42-
$this->load('db_'.$conf["db_type"]);
43-
$this->db = new db;
44-
}
45-
46-
if($conf["start_session"] == true) {
47-
session_start();
48-
$_SESSION["s"]['id'] = session_id();
49-
if($_SESSION["s"]["theme"] == '') $_SESSION["s"]['theme'] = $conf['theme'];
50-
if($_SESSION["s"]["language"] == '') $_SESSION["s"]['language'] = $conf['language'];
51-
}
52-
53-
}
54-
55-
function uses($classes) {
56-
global $conf;
57-
58-
$cl = explode(',',$classes);
59-
if(is_array($cl)) {
60-
foreach($cl as $classname) {
61-
if(!is_object($this->$classname)) {
62-
include_once($conf['classpath'] . "/".$classname.".inc.php");
63-
$this->$classname = new $classname;
64-
}
65-
}
66-
}
67-
68-
}
69-
70-
function load($files) {
71-
72-
global $conf;
73-
$fl = explode(',',$files);
74-
if(is_array($fl)) {
75-
foreach($fl as $file) {
76-
include_once($conf['classpath'] . "/".$file.".inc.php");
77-
}
78-
}
79-
80-
}
81-
82-
/*
83-
0 = DEBUG
84-
1 = WARNING
85-
2 = ERROR
86-
*/
87-
88-
function log($msg, $priority = 0) {
89-
90-
if($priority >= $conf["log_priority"]) {
91-
if (is_writable($conf["log_file"])) {
92-
93-
if (!$fp = fopen ($conf["log_file"], "a")) {
94-
$this->error("Logfile konnte nicht geöffnet werden.");
95-
}
96-
if (!fwrite($fp, date("d.m.Y-H:i")." - ". $msg."\r\n")) {
97-
$this->error("Schreiben in Logfile nicht möglich.");
98-
}
99-
fclose($fp);
100-
101-
} else {
102-
$this->error("Logfile ist nicht beschreibbar.");
103-
}
104-
} // if
105-
} // func
106-
107-
/*
108-
0 = DEBUG
109-
1 = WARNING
110-
2 = ERROR
111-
*/
112-
113-
function error($msg, $next_link = '', $stop = true, $priority = 1) {
114-
//$this->uses("error");
115-
//$this->error->message($msg, $priority);
116-
if($stop == true){
117-
$msg = '<html>
34+
private $_language_inc = 0;
35+
private $_wb;
36+
private $_loaded_classes = array();
37+
38+
public function __construct() {
39+
global $conf;
40+
41+
if($conf['start_db'] == true) {
42+
$this->load('db_'.$conf['db_type']);
43+
$this->db = new db;
44+
}
45+
46+
if($conf['start_session'] == true) {
47+
session_start();
48+
$_SESSION['s']['id'] = session_id();
49+
if(!isset($_SESSION['s']['theme']) || $_SESSION['s']['theme'] == ''){
50+
$_SESSION['s']['theme'] = $conf['theme'];
51+
}
52+
if($_SESSION['s']['language'] == '') $_SESSION['s']['language'] = $conf['language'];
53+
}
54+
}
55+
56+
public function uses($classes) {
57+
global $conf;
58+
59+
$cl = explode(',',$classes);
60+
if(is_array($cl)) {
61+
foreach($cl as $classname){
62+
if(!array_key_exists($classname, $this->_loaded_classes)){
63+
include_once($conf['classpath'] . '/'.$classname.'.inc.php');
64+
$this->$classname = new $classname;
65+
$this->_loaded_classes[$classname] = true;
66+
}
67+
}
68+
}
69+
}
70+
71+
public function load($files) {
72+
global $conf;
73+
74+
$fl = explode(',',$files);
75+
if(is_array($fl)) {
76+
foreach($fl as $file) {
77+
include_once($conf['classpath'] . '/'.$file.'.inc.php');
78+
}
79+
}
80+
}
81+
82+
/*
83+
0 = DEBUG
84+
1 = WARNING
85+
2 = ERROR
86+
*/
87+
public function log($msg, $priority = 0) {
88+
global $conf;
89+
90+
if($priority >= $conf['log_priority']) {
91+
if (is_writable($conf['log_file'])) {
92+
if (!$fp = fopen ($conf['log_file'], 'a')) {
93+
$this->error('Logfile konnte nicht ge�ffnet werden.');
94+
}
95+
if (!fwrite($fp, date('d.m.Y-H:i').' - '. $msg."\r\n")) {
96+
$this->error('Schreiben in Logfile nicht m�glich.');
97+
}
98+
fclose($fp);
99+
} else {
100+
$this->error('Logfile ist nicht beschreibbar.');
101+
}
102+
}
103+
}
104+
105+
/*
106+
0 = DEBUG
107+
1 = WARNING
108+
2 = ERROR
109+
*/
110+
public function error($msg, $next_link = '', $stop = true, $priority = 1) {
111+
//$this->uses("error");
112+
//$this->error->message($msg, $priority);
113+
if($stop == true){
114+
$msg = '<html>
118115
<head>
119116
<title>Error</title>
120117
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
@@ -125,63 +122,61 @@ function error($msg, $next_link = '', $stop = true, $priority = 1) {
125122
<table width="100%" border="0" cellspacing="0" cellpadding="2">
126123
<tr>
127124
<td class="error"><b>Error:</b><br>'.$msg;
128-
if($next_link != "") $msg .= '<a href="'.$next_link.'">Next</a><br>';
129-
$msg .= '</td>
125+
if($next_link != "") $msg .= '<a href="'.$next_link.'">Next</a><br>';
126+
$msg .= '</td>
130127
</tr>
131128
</table>
132129
</body>
133130
</html>';
134-
die($msg);
135-
} else {
136-
echo $msg;
137-
if($next_link != "") echo "<a href='$next_link'>Next</a>";
138-
}
139-
}
140-
141-
function lng($text)
142-
{
143-
global $conf;
144-
if($this->_language_inc != 1) {
145-
// loading global and module Wordbook
146-
@include_once($conf["rootpath"]."/lib/lang/".$_SESSION["s"]["language"].".lng");
147-
@include_once($conf["rootpath"]."/web/".$_SESSION["s"]["module"]["name"]."/lib/lang/".$_SESSION["s"]["language"].".lng");
148-
$this->_wb = $wb;
149-
$this->_language_inc = 1;
150-
}
151-
152-
if(!empty($this->_wb[$text])) {
153-
$text = $this->_wb[$text];
154-
}
155-
156-
return $text;
157-
}
158-
159-
function tpl_defaults() {
160-
global $conf;
161-
162-
$this->tpl->setVar('theme',$_SESSION["s"]["theme"]);
163-
$this->tpl->setVar('phpsessid',session_id());
164-
$this->tpl->setVar('html_content_encoding',$conf["html_content_encoding"]);
165-
if($conf["logo"] != '' && @is_file($conf["logo"])){
166-
$this->tpl->setVar('logo', '<img src="'.$conf["logo"].'" border="0" alt="">');
167-
} else {
168-
$this->tpl->setVar('logo', '&nbsp;');
169-
}
170-
$this->tpl->setVar('app_title',$conf["app_title"]);
171-
$this->tpl->setVar('delete_confirmation',$this->lng('delete_confirmation'));
172-
$this->tpl->setVar('app_module',$_SESSION["s"]["module"]["name"]);
173-
if($_SESSION["s"]["user"]["typ"] == 'admin') {
174-
$this->tpl->setVar('is_admin',1);
175-
}
176-
177-
}
178-
179-
}
131+
die($msg);
132+
} else {
133+
echo $msg;
134+
if($next_link != '') echo "<a href='$next_link'>Next</a>";
135+
}
136+
}
137+
138+
public function lng($text){
139+
global $conf;
140+
141+
if($this->_language_inc != 1) {
142+
//* loading global and module Wordbook
143+
@include_once($conf['rootpath'].'/lib/lang/'.$_SESSION['s']['language'].'.lng');
144+
@include_once($conf['rootpath'].'/web/'.$_SESSION['s']['module']['name'].'/lib/lang/'.$_SESSION['s']['language'].'.lng');
145+
$this->_wb = $wb;
146+
$this->_language_inc = 1;
147+
}
148+
149+
if(!empty($this->_wb[$text])) {
150+
$text = $this->_wb[$text];
151+
}
152+
153+
return $text;
154+
}
155+
156+
public function tpl_defaults() {
157+
global $conf;
158+
159+
$this->tpl->setVar('theme',$_SESSION['s']['theme']);
160+
$this->tpl->setVar('phpsessid',session_id());
161+
$this->tpl->setVar('html_content_encoding',$conf['html_content_encoding']);
162+
if($conf['logo'] != '' && @is_file($conf['logo'])){
163+
$this->tpl->setVar('logo', '<img src="'.$conf['logo'].'" border="0" alt="">');
164+
} else {
165+
$this->tpl->setVar('logo', '&nbsp;');
166+
}
167+
$this->tpl->setVar('app_title',$conf["app_title"]);
168+
$this->tpl->setVar('delete_confirmation',$this->lng('delete_confirmation'));
169+
$this->tpl->setVar('app_module',$_SESSION['s']['module']['name']);
170+
if(isset($_SESSION['s']['user']) && $_SESSION['s']['user']['typ'] == 'admin') {
171+
$this->tpl->setVar('is_admin',1);
172+
}
173+
}
174+
175+
} // end class
180176

181177
/*
182178
Initialize application (app) object
183179
*/
184-
185-
$app = new app;
180+
$app = new app(); // new app($conf);
186181

187182
?>

0 commit comments

Comments
 (0)