1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category framewotk
|
5
|
* @package backend admin
|
6
|
* @author Ryan Djurovich, WebsiteBaker Project
|
7
|
* @copyright 2009-2012, WebsiteBaker Org. e.V.
|
8
|
* @link http://www.websitebaker2.org/
|
9
|
* @license http://www.gnu.org/licenses/gpl.html
|
10
|
* @platform WebsiteBaker 2.8.x
|
11
|
* @requirements PHP 5.2.2 and higher
|
12
|
* @version $Id: class.admin.php 1730 2012-08-31 01:41:24Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/class.admin.php $
|
14
|
* @lastmodified $Date: 2012-08-31 03:41:24 +0200 (Fri, 31 Aug 2012) $
|
15
|
*
|
16
|
*/
|
17
|
/* -------------------------------------------------------- */
|
18
|
// Must include code to stop this file being accessed directly
|
19
|
if(!defined('WB_PATH')) {
|
20
|
require_once(dirname(__FILE__).'/globalExceptionHandler.php');
|
21
|
throw new IllegalFileException();
|
22
|
}
|
23
|
/* -------------------------------------------------------- */
|
24
|
require_once(WB_PATH.'/framework/class.wb.php');
|
25
|
|
26
|
// Get WB version
|
27
|
require_once(ADMIN_PATH.'/interface/version.php');
|
28
|
|
29
|
// Include EditArea wrapper functions
|
30
|
// require_once(WB_PATH . '/include/editarea/wb_wrapper_edit_area.php');
|
31
|
//require_once(WB_PATH . '/framework/SecureForm.php');
|
32
|
|
33
|
|
34
|
/**
|
35
|
* admin
|
36
|
*
|
37
|
* @package
|
38
|
* @copyright
|
39
|
* @version 2012
|
40
|
* @access public
|
41
|
*/
|
42
|
class admin extends wb {
|
43
|
// Authenticate user then auto print the header
|
44
|
/**
|
45
|
* admin::__construct()
|
46
|
*
|
47
|
* @param string $section_name
|
48
|
* @param string $section_permission
|
49
|
* @param bool $auto_header
|
50
|
* @param bool $auto_auth
|
51
|
* @return void
|
52
|
*/
|
53
|
public function __construct($section_name= '##skip##', $section_permission = 'start', $auto_header = true, $auto_auth = true)
|
54
|
{
|
55
|
parent::__construct(SecureForm::BACKEND);
|
56
|
if( $section_name != '##skip##' )
|
57
|
{
|
58
|
global $database, $MESSAGE;
|
59
|
// Specify the current applications name
|
60
|
$this->section_name = $section_name;
|
61
|
$this->section_permission = $section_permission;
|
62
|
// Authenticate the user for this application
|
63
|
if($auto_auth == true)
|
64
|
{
|
65
|
// First check if the user is logged-in
|
66
|
if($this->is_authenticated() == false)
|
67
|
{
|
68
|
header('Location: '.ADMIN_URL.'/login/index.php');
|
69
|
exit(0);
|
70
|
}
|
71
|
|
72
|
// Now check if they are allowed in this section
|
73
|
if($this->get_permission($section_permission) == false) {
|
74
|
die($MESSAGE['ADMIN_INSUFFICIENT_PRIVELLIGES']);
|
75
|
}
|
76
|
}
|
77
|
|
78
|
// Check if the backend language is also the selected language. If not, send headers again.
|
79
|
$sql = 'SELECT `language` FROM `'.TABLE_PREFIX.'users` ';
|
80
|
$sql .= 'WHERE `user_id`='.(int)$this->get_user_id();
|
81
|
$get_user_language = @$database->query($sql);
|
82
|
$user_language = ($get_user_language) ? $get_user_language->fetchRow() : '';
|
83
|
// prevent infinite loop if language file is not XX.php (e.g. DE_du.php)
|
84
|
$user_language = substr($user_language[0],0,2);
|
85
|
// obtain the admin folder (e.g. /admin)
|
86
|
$admin_folder = str_replace(WB_PATH, '', ADMIN_PATH);
|
87
|
if((LANGUAGE != $user_language) && file_exists(WB_PATH .'/languages/' .$user_language .'.php')
|
88
|
&& strpos($_SERVER['PHP_SELF'],$admin_folder.'/') !== false) {
|
89
|
// check if page_id is set
|
90
|
$page_id_url = (isset($_GET['page_id'])) ? '&page_id=' .(int) $_GET['page_id'] : '';
|
91
|
$section_id_url = (isset($_GET['section_id'])) ? '§ion_id=' .(int) $_GET['section_id'] : '';
|
92
|
if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { // check if there is an query-string
|
93
|
header('Location: '.$_SERVER['PHP_SELF'] .'?lang='.$user_language .$page_id_url .$section_id_url.'&'.$_SERVER['QUERY_STRING']);
|
94
|
} else {
|
95
|
header('Location: '.$_SERVER['PHP_SELF'] .'?lang='.$user_language .$page_id_url .$section_id_url);
|
96
|
}
|
97
|
exit();
|
98
|
}
|
99
|
|
100
|
// Auto header code
|
101
|
if($auto_header == true) {
|
102
|
$this->print_header();
|
103
|
}
|
104
|
}
|
105
|
}
|
106
|
|
107
|
// Print the admin header
|
108
|
/**
|
109
|
* admin::print_header()
|
110
|
*
|
111
|
* @param string $body_tags
|
112
|
* @return void
|
113
|
*/
|
114
|
function print_header($body_tags = '')
|
115
|
{
|
116
|
// Get vars from the language file
|
117
|
global $MENU, $MESSAGE, $TEXT;
|
118
|
// Connect to database and get website title
|
119
|
global $database;
|
120
|
// $GLOBALS['FTAN'] = $this->getFTAN();
|
121
|
$this->createFTAN();
|
122
|
$sql = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` WHERE `name`=\'website_title\'';
|
123
|
$get_title = $database->query($sql);
|
124
|
$title = $get_title->fetchRow();
|
125
|
// Setup template object, parse vars to it, then parse it
|
126
|
$header_template = new Template(dirname($this->correct_theme_source('header.htt')) );
|
127
|
$header_template->set_file('page', 'header.htt');
|
128
|
$header_template->set_block('page', 'header_block', 'header');
|
129
|
if(defined('DEFAULT_CHARSET')) {
|
130
|
$charset=DEFAULT_CHARSET;
|
131
|
} else {
|
132
|
$charset='utf-8';
|
133
|
}
|
134
|
|
135
|
// work out the URL for the 'View menu' link in the WB backend
|
136
|
// if the page_id is set, show this page otherwise show the root directory of WB
|
137
|
$view_url = WB_URL;
|
138
|
if(isset($_GET['page_id'])) {
|
139
|
// extract page link from the database
|
140
|
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` ';
|
141
|
$sql .= 'WHERE `page_id`='.intval($_GET['page_id']);
|
142
|
$result = @$database->query($sql);
|
143
|
$row = @$result->fetchRow();
|
144
|
if($row) $view_url .= PAGES_DIRECTORY .$row['link']. PAGE_EXTENSION;
|
145
|
}
|
146
|
$sServerAdress = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1';
|
147
|
$header_template->set_var( array(
|
148
|
'SECTION_FORGOT' => $MENU['FORGOT'],
|
149
|
'SECTION_NAME' => $MENU['LOGIN'],
|
150
|
'BODY_TAGS' => $body_tags,
|
151
|
'WEBSITE_TITLE' => ($title['value']),
|
152
|
'TEXT_ADMINISTRATION' => $TEXT['ADMINISTRATION'],
|
153
|
'CURRENT_USER' => $MESSAGE['START_CURRENT_USER'],
|
154
|
'DISPLAY_NAME' => $this->get_display_name(),
|
155
|
'CHARSET' => $charset,
|
156
|
//'LANGUAGE' => strtolower(LANGUAGE),
|
157
|
'LANGUAGE' => LANGUAGE,
|
158
|
'VERSION' => VERSION,
|
159
|
'SP' => (defined('SP') ? SP : ''),
|
160
|
'REVISION' => REVISION,
|
161
|
'SERVER_ADDR' => ((int)$this->get_user_id()==1 ? $sServerAdress : ''),
|
162
|
'WB_URL' => WB_URL,
|
163
|
'ADMIN_URL' => ADMIN_URL,
|
164
|
'THEME_URL' => THEME_URL,
|
165
|
'START_URL' => ADMIN_URL.'/index.php',
|
166
|
'START_CLASS' => 'start',
|
167
|
'TITLE_START' => $TEXT['READ_MORE'],
|
168
|
'TITLE_VIEW' => $TEXT['WEBSITE'],
|
169
|
'TITLE_HELP' => $MENU['HELP'],
|
170
|
'URL_VIEW' => $view_url,
|
171
|
'TITLE_LOGOUT' => $MENU['LOGIN'],
|
172
|
'LOGIN_DISPLAY_HIDDEN' => !$this->is_authenticated() ? 'hidden' : '',
|
173
|
'LOGIN_DISPLAY_NONE' => !$this->is_authenticated() ? 'none' : '',
|
174
|
'LOGIN_LINK' => $_SERVER['SCRIPT_NAME'],
|
175
|
'LOGIN_ICON' => 'login',
|
176
|
'START_ICON' => 'blank',
|
177
|
'URL_HELP' => 'http://www.websitebaker.org/',
|
178
|
'BACKEND_MODULE_CSS' => $this->register_backend_modfiles('css'), // adds backend.css
|
179
|
'BACKEND_MODULE_JS' => $this->register_backend_modfiles('js') // adds backend.js
|
180
|
)
|
181
|
);
|
182
|
|
183
|
// Create the menu
|
184
|
if(!$this->is_authenticated())
|
185
|
{
|
186
|
$header_template->set_var('STYLE', 'login');
|
187
|
$menu = array(
|
188
|
// array('http://www.websitebaker.org/', '_blank', 'WebsiteBaker Home', 'help', 0),
|
189
|
// array($view_url, '_blank', $TEXT['FRONTEND'], '', 0),
|
190
|
// array(ADMIN_URL.'/login/index.php', '', $MENU['LOGIN'], '', 0)
|
191
|
);
|
192
|
} else {
|
193
|
$header_template->set_var('STYLE', 'start');
|
194
|
$header_template->set_var( array(
|
195
|
'SECTION_NAME' => $MENU[strtoupper($this->section_name)],
|
196
|
'TITLE_LOGOUT' => $MENU['LOGOUT'],
|
197
|
'LOGIN_DISPLAY_NONE' => '',
|
198
|
'START_ICON' => 'home',
|
199
|
'LOGIN_ICON' => 'logout',
|
200
|
'LOGIN_LINK' => ADMIN_URL.'/logout/index.php',
|
201
|
'TITLE_START' => $MENU['START']
|
202
|
)
|
203
|
);
|
204
|
// @array ( $url, $target, $title, $page_permission, $ppermission_required )
|
205
|
$menu = array(
|
206
|
// array(ADMIN_URL.'/index.php', '', $MENU['START'], 'start', 1 ),
|
207
|
array(ADMIN_URL.'/pages/index.php', '', $MENU['PAGES'], 'pages', 1),
|
208
|
// array($view_url, '_blank', $MENU['FRONTEND'], 'pages', 1),
|
209
|
array(ADMIN_URL.'/media/index.php', '', $MENU['MEDIA'], 'media', 1),
|
210
|
array(ADMIN_URL.'/addons/index.php', '', $MENU['ADDONS'], 'addons', 1),
|
211
|
array(ADMIN_URL.'/preferences/index.php', '', $MENU['PREFERENCES'], 'preferences', 1),
|
212
|
array(ADMIN_URL.'/settings/index.php', '', $MENU['SETTINGS'], 'settings', 1),
|
213
|
array(ADMIN_URL.'/admintools/index.php', '', $MENU['ADMINTOOLS'], 'admintools', 1),
|
214
|
array(ADMIN_URL.'/access/index.php', '', $MENU['ACCESS'], 'access', 1),
|
215
|
// array('http://www.websitebaker.org/', '_blank', 'WebsiteBaker Home', '', 0),
|
216
|
// array(ADMIN_URL.'/logout/index.php', '', $MENU['LOGOUT'], '', 0)
|
217
|
|
218
|
);
|
219
|
}
|
220
|
|
221
|
$header_template->set_block('header_block', 'linkBlock', 'link');
|
222
|
foreach($menu AS $menu_item)
|
223
|
{
|
224
|
$link = $menu_item[0];
|
225
|
$target = ($menu_item[1] == '') ? '_self' : $menu_item[1];
|
226
|
$title = $menu_item[2];
|
227
|
$permission_title = $menu_item[3];
|
228
|
$required = $menu_item[4];
|
229
|
$replace_old = array(ADMIN_URL, WB_URL, '/', 'index.php');
|
230
|
if($required == false || ($this->is_authenticated() && $this->get_link_permission($permission_title)) )
|
231
|
{
|
232
|
$header_template->set_var('LINK', $link);
|
233
|
$header_template->set_var('TARGET', $target);
|
234
|
// If link is the current section apply a class name
|
235
|
if($permission_title == strtolower($this->section_name)) {
|
236
|
$header_template->set_var('CLASS', $menu_item[3] . ' current');
|
237
|
$header_template->set_var('STYLE', $menu_item[3] );
|
238
|
} else {
|
239
|
$header_template->set_var('CLASS', $menu_item[3] );
|
240
|
}
|
241
|
$header_template->set_var('TITLE', $title);
|
242
|
// Print link
|
243
|
$header_template->parse('link', 'linkBlock', true);
|
244
|
}
|
245
|
}
|
246
|
$header_template->parse('header', 'header_block', false);
|
247
|
$header_template->pparse('output', 'page');
|
248
|
unset($header_template);
|
249
|
}
|
250
|
|
251
|
// Print the admin footer
|
252
|
function print_footer($activateJsAdmin = false) {
|
253
|
global $database,$starttime,$iPhpDeclaredClasses;
|
254
|
// include the required file for Javascript admin
|
255
|
if($activateJsAdmin != false) {
|
256
|
if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php')){
|
257
|
@include_once(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
|
258
|
}
|
259
|
}
|
260
|
|
261
|
// Setup template object, parse vars to it, then parse it
|
262
|
$footer_template = new Template(dirname($this->correct_theme_source('footer.htt')));
|
263
|
$footer_template->set_file('page', 'footer.htt');
|
264
|
$footer_template->set_block('page', 'footer_block', 'header');
|
265
|
$footer_template->set_var(array(
|
266
|
'BACKEND_BODY_MODULE_JS' => $this->register_backend_modfiles_body('js'),
|
267
|
'WB_URL' => WB_URL,
|
268
|
'ADMIN_URL' => ADMIN_URL,
|
269
|
'THEME_URL' => THEME_URL,
|
270
|
) );
|
271
|
|
272
|
$footer_template->set_block('footer_block', 'show_debug_block', 'show_debug');
|
273
|
|
274
|
$bDebug = (defined('DEBUG') ? DEBUG : false);
|
275
|
$bDevInfo = (defined('DEV_INFOS') && (DEV_INFOS == true) && (1 == $this->get_user_id()) ? true : false);
|
276
|
// if( $debug && (1 == $this->get_user_id()))
|
277
|
if( $bDevInfo )
|
278
|
{
|
279
|
|
280
|
$footer_template->set_var('MEMORY', number_format(memory_get_peak_usage(true), 0, ',', '.').' Byte' );
|
281
|
// $footer_template->set_var('MEMORY', number_format(memory_get_usage(true), 0, ',', '.').' Byte' );
|
282
|
$footer_template->set_var('QUERIES', $database->getQueryCount );
|
283
|
// $footer_template->set_var('QUERIES', 'disabled' );
|
284
|
$included_files = get_included_files();
|
285
|
$footer_template->set_var('INCLUDES', sizeof($included_files) );
|
286
|
$included_classes = get_declared_classes();
|
287
|
$footer_template->set_var('CLASSES', sizeof($included_classes)-$iPhpDeclaredClasses );
|
288
|
|
289
|
$sum_classes = 0;
|
290
|
$sum_filesize = 0;
|
291
|
$footer_template->set_block('show_debug_block', 'show_block_list', 'show_list');
|
292
|
$footer_template->set_block('show_block_list', 'include_block_list', 'include_list');
|
293
|
// $bDebug = true; for testing
|
294
|
foreach($included_files as $filename)
|
295
|
{
|
296
|
if(!is_readable($filename)) { continue; }
|
297
|
if($bDebug)
|
298
|
{
|
299
|
$footer_template->set_var('INCLUDES_ARRAY', str_replace(WB_PATH, '',$filename) );
|
300
|
$footer_template->set_var('FILESIZE', number_format(filesize($filename), 0, ',', '.').' Byte');
|
301
|
$footer_template->parse('include_list', 'include_block_list', true);
|
302
|
}
|
303
|
$sum_filesize += filesize($filename);
|
304
|
}
|
305
|
$footer_template->parse('show_list', 'show_block_list', true);
|
306
|
|
307
|
$endtime = array_sum(explode(" ",microtime()));
|
308
|
$iEndTime = $endtime;
|
309
|
$iStartTime = $starttime;
|
310
|
if(!$bDebug)
|
311
|
{
|
312
|
$footer_template->parse('show_list', '');
|
313
|
$footer_template->parse('include_list', '');
|
314
|
}
|
315
|
|
316
|
$footer_template->set_var('FILESIZE', ini_get('memory_limit'));
|
317
|
$footer_template->set_var('TXT_SUM_FILESIZE', 'Summary size of included files: ');
|
318
|
$footer_template->set_var('SUM_FILESIZE', number_format($sum_filesize, 0, ',', '.').' Byte');
|
319
|
$footer_template->set_var('SUM_CLASSES', number_format($sum_classes, 0, ',', '.').' Byte');
|
320
|
$footer_template->set_var('PAGE_LOAD_TIME', round($iEndTime-$iStartTime,3 ));
|
321
|
$footer_template->set_var('DUMP_CLASSES', '<pre>'.var_export($included_classes,true).'</pre>');
|
322
|
|
323
|
$footer_template->parse('show_debug', 'show_debug_block', true);
|
324
|
} else {
|
325
|
$footer_template->parse('show_debug', '');
|
326
|
$footer_template->parse('show_list', '');
|
327
|
|
328
|
}
|
329
|
$footer_template->parse('header', 'footer_block', false);
|
330
|
$footer_template->pparse('output', 'page');
|
331
|
unset($footer_template);
|
332
|
}
|
333
|
|
334
|
// Return a system permission
|
335
|
function get_permission($name, $type = 'system') {
|
336
|
|
337
|
// Append to permission type
|
338
|
$type .= '_permissions';
|
339
|
// Check if we have a section to check for
|
340
|
if($name == 'start') {
|
341
|
return true;
|
342
|
} else {
|
343
|
// Set system permissions var
|
344
|
$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
|
345
|
// Set module permissions var
|
346
|
$module_permissions = $this->get_session('MODULE_PERMISSIONS');
|
347
|
// Set template permissions var
|
348
|
$template_permissions = $this->get_session('TEMPLATE_PERMISSIONS');
|
349
|
// Return true if system perm = 1
|
350
|
if (isset($$type) && is_array($$type) && is_numeric(array_search($name, $$type))) {
|
351
|
if($type == 'system_permissions') {
|
352
|
return true;
|
353
|
} else {
|
354
|
return false;
|
355
|
}
|
356
|
} else {
|
357
|
if($type == 'system_permissions') {
|
358
|
return false;
|
359
|
} else {
|
360
|
return true;
|
361
|
}
|
362
|
}
|
363
|
}
|
364
|
|
365
|
}
|
366
|
|
367
|
function get_user_details($user_id) {
|
368
|
global $database;
|
369
|
$retval = array('username'=>'unknown','display_name'=>'Unknown','email'=>'');
|
370
|
$sql = 'SELECT `username`,`display_name`,`email` ';
|
371
|
$sql .= 'FROM `'.TABLE_PREFIX.'users` ';
|
372
|
$sql .= 'WHERE `user_id`='.(int)$user_id;
|
373
|
if( ($resUsers = $database->query($sql)) ) {
|
374
|
if( ($recUser = $resUsers->fetchRow()) ) {
|
375
|
$retval = $recUser;
|
376
|
}
|
377
|
}
|
378
|
return $retval;
|
379
|
}
|
380
|
|
381
|
//
|
382
|
function get_section_details( $section_id, $backLink = 'index.php' ) {
|
383
|
global $database, $TEXT;
|
384
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'sections` ';
|
385
|
$sql .= 'WHERE `section_id`='.intval($section_id);
|
386
|
if(($resSection = $database->query($sql))){
|
387
|
if(!($recSection = $resSection->fetchRow())) {
|
388
|
$this->print_header();
|
389
|
$this->print_error($TEXT['SECTION'].' '.$TEXT['NOT_FOUND'], $backLink, true);
|
390
|
}
|
391
|
} else {
|
392
|
$this->print_header();
|
393
|
$this->print_error($database->get_error(), $backLink, true);
|
394
|
}
|
395
|
return $recSection;
|
396
|
}
|
397
|
|
398
|
function get_page_details( $page_id, $backLink = 'index.php' ) {
|
399
|
global $database, $TEXT;
|
400
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` ';
|
401
|
$sql .= 'WHERE `page_id`='.intval($page_id);
|
402
|
if(($resPages = $database->query($sql))){
|
403
|
if(!($recPage = $resPages->fetchRow())) {
|
404
|
$this->print_header();
|
405
|
$this->print_error($TEXT['PAGE'].' '.$TEXT['NOT_FOUND'], $backLink, true);
|
406
|
}
|
407
|
} else {
|
408
|
$this->print_header();
|
409
|
$this->print_error($database->get_error(), $backLink, true);
|
410
|
}
|
411
|
return $recPage;
|
412
|
}
|
413
|
|
414
|
function get_page_permission($page,$action='admin') {
|
415
|
if($action != 'viewing') { $action = 'admin'; }
|
416
|
$action_groups = $action.'_groups';
|
417
|
$action_users = $action.'_users';
|
418
|
$groups = $users = '0';
|
419
|
if(is_array($page)) {
|
420
|
$groups = $page[$action_groups];
|
421
|
$users = $page[$action_users];
|
422
|
} else {
|
423
|
global $database;
|
424
|
$sql = 'SELECT `'.$action_groups.'`,`'.$action_users.'` ';
|
425
|
$sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
|
426
|
$sql .= 'WHERE `page_id`='.(int)$page;
|
427
|
if( ($res = $database->query($sql)) ) {
|
428
|
if( ($rec = $res->fetchRow()) ) {
|
429
|
$groups = $rec[$action_groups];
|
430
|
$users = $rec[$action_users];
|
431
|
}
|
432
|
}
|
433
|
}
|
434
|
return ($this->ami_group_member($groups) || $this->is_group_match($this->get_user_id(), $users));
|
435
|
}
|
436
|
|
437
|
// Returns a system permission for a menu link
|
438
|
function get_link_permission($title) {
|
439
|
$title = str_replace('_blank', '', $title);
|
440
|
$title = strtolower($title);
|
441
|
// Set system permissions var
|
442
|
$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
|
443
|
// Set module permissions var
|
444
|
$module_permissions = $this->get_session('MODULE_PERMISSIONS');
|
445
|
if($title == 'start') {
|
446
|
return true;
|
447
|
} else {
|
448
|
// Return true if system perm = 1
|
449
|
if(is_numeric(array_search($title, $system_permissions))) {
|
450
|
return true;
|
451
|
} else {
|
452
|
return false;
|
453
|
}
|
454
|
}
|
455
|
}
|
456
|
|
457
|
// Function to add optional module Javascript or CSS stylesheets into the <body> section of the backend
|
458
|
function register_backend_modfiles_body($file_id="js")
|
459
|
{
|
460
|
// sanity check of parameter passed to the function
|
461
|
$file_id = strtolower($file_id);
|
462
|
if($file_id !== "javascript" && $file_id !== "js")
|
463
|
{
|
464
|
return;
|
465
|
}
|
466
|
global $database;
|
467
|
$body_links = "";
|
468
|
// define default baselink and filename for optional module javascript and stylesheet files
|
469
|
if($file_id == "js") {
|
470
|
$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend_body.js" type="text/javascript"></script>';
|
471
|
$base_file = "backend_body.js";
|
472
|
}
|
473
|
// check if backend_body.js files needs to be included to the <body></body> section of the backend
|
474
|
if(isset($_GET['tool']))
|
475
|
{
|
476
|
// check if displayed page contains a installed admin tool
|
477
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
|
478
|
$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\''.addslashes($_GET['tool']).'\'';
|
479
|
$result = $database->query($sql);
|
480
|
if($result->numRows())
|
481
|
{
|
482
|
// check if admin tool directory contains a backend_body.js file to include
|
483
|
$tool = $result->fetchRow();
|
484
|
if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file"))
|
485
|
{
|
486
|
// return link to the backend_body.js file
|
487
|
return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link);
|
488
|
}
|
489
|
}
|
490
|
} elseif(isset($_GET['page_id']) or isset($_POST['page_id']))
|
491
|
{
|
492
|
// check if displayed page in the backend contains a page module
|
493
|
if (isset($_GET['page_id']))
|
494
|
{
|
495
|
$page_id = (int) addslashes($_GET['page_id']);
|
496
|
} else {
|
497
|
$page_id = (int) addslashes($_POST['page_id']);
|
498
|
}
|
499
|
// gather information for all models embedded on actual page
|
500
|
$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
|
501
|
$query_modules = $database->query($sql);
|
502
|
while($row = $query_modules->fetchRow()) {
|
503
|
// check if page module directory contains a backend_body.js file
|
504
|
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
|
505
|
// create link with backend_body.js source for the current module
|
506
|
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
|
507
|
// ensure that backend_body.js is only added once per module type
|
508
|
if(strpos($body_links, $tmp_link) === false) {
|
509
|
$body_links .= $tmp_link ."\n";
|
510
|
}
|
511
|
}
|
512
|
}
|
513
|
// write out links with all external module javascript/CSS files, remove last line feed
|
514
|
return rtrim($body_links);
|
515
|
}
|
516
|
}
|
517
|
|
518
|
|
519
|
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the backend
|
520
|
function register_backend_modfiles($file_id="css") {
|
521
|
// sanity check of parameter passed to the function
|
522
|
$file_id = strtolower($file_id);
|
523
|
if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") {
|
524
|
return;
|
525
|
}
|
526
|
|
527
|
global $database;
|
528
|
// define default baselink and filename for optional module javascript and stylesheet files
|
529
|
$head_links = "";
|
530
|
if($file_id == "css") {
|
531
|
$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.css"';
|
532
|
$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
|
533
|
$base_file = "backend.css";
|
534
|
} else {
|
535
|
$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.js" type="text/javascript"></script>';
|
536
|
$base_file = "backend.js";
|
537
|
}
|
538
|
|
539
|
// check if backend.js or backend.css files needs to be included to the <head></head> section of the backend
|
540
|
if(isset($_GET['tool'])) {
|
541
|
// check if displayed page contains a installed admin tool
|
542
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
|
543
|
$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\''.addslashes($_GET['tool']).'\'';
|
544
|
$result = $database->query($sql);
|
545
|
if($result->numRows()) {
|
546
|
// check if admin tool directory contains a backend.js or backend.css file to include
|
547
|
$tool = $result->fetchRow();
|
548
|
if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file")) {
|
549
|
// return link to the backend.js or backend.css file
|
550
|
return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link);
|
551
|
}
|
552
|
}
|
553
|
} elseif(isset($_GET['page_id']) || isset($_POST['page_id'])) {
|
554
|
// check if displayed page in the backend contains a page module
|
555
|
if (isset($_GET['page_id'])) {
|
556
|
$page_id = (int)$_GET['page_id'];
|
557
|
} else {
|
558
|
$page_id = (int)$_POST['page_id'];
|
559
|
}
|
560
|
|
561
|
// gather information for all models embedded on actual page
|
562
|
$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
|
563
|
$query_modules = $database->query($sql);
|
564
|
|
565
|
while($row = $query_modules->fetchRow()) {
|
566
|
// check if page module directory contains a backend.js or backend.css file
|
567
|
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
|
568
|
// create link with backend.js or backend.css source for the current module
|
569
|
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
|
570
|
// ensure that backend.js or backend.css is only added once per module type
|
571
|
if(strpos($head_links, $tmp_link) === false) {
|
572
|
$head_links .= $tmp_link ."\n";
|
573
|
}
|
574
|
}
|
575
|
}
|
576
|
// write out links with all external module javascript/CSS files, remove last line feed
|
577
|
return rtrim($head_links);
|
578
|
}
|
579
|
}
|
580
|
}
|