1 |
801
|
doc
|
<?php
|
2 |
|
|
|
3 |
|
|
// $Id$
|
4 |
|
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
915
|
Ruebenwurz
|
Copyright (C) 2004-2009, Ryan Djurovich
|
9 |
801
|
doc
|
|
10 |
|
|
Website Baker is free software; you can redistribute it and/or modify
|
11 |
|
|
it under the terms of the GNU General Public License as published by
|
12 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
(at your option) any later version.
|
14 |
|
|
|
15 |
|
|
Website Baker is distributed in the hope that it will be useful,
|
16 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
GNU General Public License for more details.
|
19 |
|
|
|
20 |
|
|
You should have received a copy of the GNU General Public License
|
21 |
|
|
along with Website Baker; if not, write to the Free Software
|
22 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
|
24 |
|
|
*/
|
25 |
|
|
|
26 |
|
|
/**
|
27 |
834
|
doc
|
This file contains routines to edit the optional module files: frontend.css and backend.css
|
28 |
801
|
doc
|
Mechanism was introduced with WB 2.7 to provide a global solution for all modules
|
29 |
|
|
To use this function, include this file from your module (e.g. from modify.php)
|
30 |
1495
|
DarkViper
|
Then simply call the function edit_css('your_module_directory') - that�s it
|
31 |
834
|
doc
|
NOTE: Some functions were added for module developers to make the creation of own module easier
|
32 |
801
|
doc
|
*/
|
33 |
|
|
|
34 |
1496
|
DarkViper
|
/* -------------------------------------------------------- */
|
35 |
|
|
// Must include code to stop this file being accessed directly
|
36 |
1499
|
DarkViper
|
if(!defined('WB_PATH')) {
|
37 |
|
|
require_once(dirname(__FILE__).'/globalExceptionHandler.php');
|
38 |
|
|
throw new IllegalFileException();
|
39 |
|
|
}
|
40 |
1496
|
DarkViper
|
/* -------------------------------------------------------- */
|
41 |
801
|
doc
|
|
42 |
834
|
doc
|
/*
|
43 |
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
44 |
|
|
FUNCTIONS REQUIRED TO EDIT THE OPTIONAL MODULE CSS FILES
|
45 |
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
46 |
|
|
*/
|
47 |
|
|
|
48 |
801
|
doc
|
// this function checks the validity of the specified module directory
|
49 |
|
|
if(!function_exists('check_module_dir')) {
|
50 |
|
|
function check_module_dir($mod_dir) {
|
51 |
|
|
// check if module directory is formal correct (only characters: "a-z,0-9,_,-")
|
52 |
|
|
if(!preg_match('/^[a-z0-9_-]+$/iD', $mod_dir)) return '';
|
53 |
|
|
// check if the module folder contains the required info.php file
|
54 |
|
|
return (file_exists(WB_PATH .'/modules/' .$mod_dir .'/info.php')) ? $mod_dir : '';
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
// this function checks if the specified optional module file exists
|
59 |
|
|
if (!function_exists('mod_file_exists')) {
|
60 |
|
|
function mod_file_exists($mod_dir, $mod_file='frontend.css') {
|
61 |
|
|
// check if the module file exists
|
62 |
|
|
return file_exists(WB_PATH .'/modules/' .$mod_dir .'/' .$mod_file);
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
// this function displays the "Edit CSS" button in modify.php
|
67 |
|
|
if (!function_exists('edit_module_css')) {
|
68 |
|
|
function edit_module_css($mod_dir) {
|
69 |
810
|
doc
|
global $page_id, $section_id;
|
70 |
1428
|
Luisehahne
|
|
71 |
801
|
doc
|
// check if the required edit_module_css.php file exists
|
72 |
|
|
if(!file_exists(WB_PATH .'/modules/edit_module_files.php')) return;
|
73 |
|
|
|
74 |
|
|
// check if specified module directory is valid
|
75 |
|
|
if(check_module_dir($mod_dir) == '') return;
|
76 |
|
|
|
77 |
|
|
// check if frontend.css or backend.css exist
|
78 |
|
|
$frontend_css = mod_file_exists($mod_dir, 'frontend.css');
|
79 |
|
|
$backend_css = mod_file_exists($mod_dir, 'backend.css');
|
80 |
|
|
|
81 |
|
|
// output the edit CSS submtin button if required
|
82 |
|
|
if($frontend_css || $backend_css) {
|
83 |
810
|
doc
|
// default text used for the edit CSS routines if not defined in the WB core language files
|
84 |
|
|
$edit_css_caption = (isset($GLOBALS['TEXT']['CAP_EDIT_CSS'])) ?$GLOBALS['TEXT']['CAP_EDIT_CSS'] :'Edit CSS';
|
85 |
801
|
doc
|
?>
|
86 |
|
|
<form name="edit_module_file" action="<?php echo WB_URL .'/modules/edit_module_files.php?page_id='.$page_id;?>"
|
87 |
|
|
method="post" style="margin: 0; align:right;">
|
88 |
1069
|
Ruebenwurz
|
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>" />
|
89 |
|
|
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>" />
|
90 |
|
|
<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>" />
|
91 |
1428
|
Luisehahne
|
<input type="hidden" name="edit_file" value="<?php echo ($frontend_css) ? 'frontend.css' : 'backend.css';?>" />
|
92 |
1069
|
Ruebenwurz
|
<input type="hidden" name="action" value="edit" />
|
93 |
|
|
<input type="submit" value="<?php echo $edit_css_caption;?>" class="mod_<?php echo $mod_dir;?>_edit_css" />
|
94 |
801
|
doc
|
</form>
|
95 |
|
|
<?php
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
// this function displays a button to toggle between CSS files (invoked from edit_css.php)
|
101 |
|
|
if (!function_exists('toggle_css_file')) {
|
102 |
|
|
function toggle_css_file($mod_dir, $base_css_file = 'frontend.css') {
|
103 |
|
|
global $page_id, $section_id;
|
104 |
|
|
// check if the required edit_module_css.php file exists
|
105 |
|
|
if(!file_exists(WB_PATH .'/modules/edit_module_files.php')) return;
|
106 |
|
|
|
107 |
|
|
// check if specified module directory is valid
|
108 |
|
|
if(check_module_dir($mod_dir) == '') return;
|
109 |
|
|
|
110 |
|
|
// do sanity check of specified css file
|
111 |
|
|
if(!in_array($base_css_file, array('frontend.css', 'backend.css'))) return;
|
112 |
|
|
|
113 |
|
|
// display button to toggle between the two CSS files: frontend.css, backend.css
|
114 |
|
|
$toggle_file = ($base_css_file == 'frontend.css') ? 'backend.css' : 'frontend.css';
|
115 |
|
|
if(mod_file_exists($mod_dir, $toggle_file)) {
|
116 |
|
|
?>
|
117 |
806
|
Ruebenwurz
|
<form name="toggle_module_file" action="<?php echo WB_URL .'/modules/edit_module_files.php?page_id='.$page_id;?>" method="post" style="margin: 0; align:right;">
|
118 |
1069
|
Ruebenwurz
|
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>" />
|
119 |
|
|
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>" />
|
120 |
|
|
<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>" />
|
121 |
|
|
<input type="hidden" name="edit_file" value="<?php echo $toggle_file; ?>" />
|
122 |
|
|
<input type="hidden" name="action" value="edit" />
|
123 |
|
|
<input type="submit" value="<?php echo ucwords($toggle_file);?>" class="mod_<?php echo $mod_dir;?>_edit_css" />
|
124 |
801
|
doc
|
</form>
|
125 |
|
|
<?php
|
126 |
|
|
}
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
|
130 |
834
|
doc
|
/*
|
131 |
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
132 |
|
|
FUNCTIONS WHICH CAN BE USED BY MODULE DEVELOPERS FOR OWN MODULES (E.G. VIEW.PHP, MODIFY.PHP)
|
133 |
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
134 |
|
|
*/
|
135 |
|
|
|
136 |
|
|
// function to obtain the module language file depending on the backend language of the current user
|
137 |
|
|
if (!function_exists('get_module_language_file')) {
|
138 |
|
|
function get_module_language_file($mymod_dir) {
|
139 |
|
|
$mymod_dir = strip_tags($mymod_dir);
|
140 |
|
|
if(file_exists(WB_PATH .'/modules/' .$mymod_dir .'/languages/' .LANGUAGE .'.php')) {
|
141 |
|
|
// a module language file exists for the users backend language
|
142 |
|
|
return (WB_PATH .'/modules/' .$mymod_dir .'/languages/' .LANGUAGE .'.php');
|
143 |
|
|
} else {
|
144 |
|
|
// an English module language file must exist in all multi-lingual modules
|
145 |
|
|
if(file_exists(WB_PATH .'/modules/' .$mymod_dir .'/languages/EN.php')) {
|
146 |
|
|
return (WB_PATH .'/modules/' .$mymod_dir .'/languages/EN.php');
|
147 |
|
|
} else {
|
148 |
|
|
echo '<p><strong>Error: </strong>';
|
149 |
|
|
echo 'Default language file (EN.php) of module "' .htmlentities($mymod_dir) .'" does not exist.</p><br />';
|
150 |
|
|
return false;
|
151 |
|
|
}
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
// function to include module CSS files in <body> (only if WB < 2.6.7 or register_frontend_modfiles('css') not invoked in template)
|
157 |
|
|
if (!function_exists('include_module_css')) {
|
158 |
|
|
function include_module_css($mymod_dir, $css_file) {
|
159 |
|
|
if(!in_array(strtolower($css_file), array('frontend.css', 'backend.css'))) return;
|
160 |
|
|
|
161 |
|
|
if($css_file == 'frontend.css') {
|
162 |
|
|
// check if frontend.css needs to be included into the <body> section
|
163 |
1105
|
Ruebenwurz
|
if(!((!function_exists('register_frontend_modfiles') || !defined('MOD_FRONTEND_CSS_REGISTERED')) &&
|
164 |
834
|
doc
|
file_exists(WB_PATH .'/modules/' .$mymod_dir .'/frontend.css'))) {
|
165 |
|
|
return false;
|
166 |
|
|
}
|
167 |
|
|
} else {
|
168 |
|
|
// check if backend.css needs to be included into the <body> section
|
169 |
|
|
global $admin;
|
170 |
|
|
if(!(!method_exists($admin, 'register_backend_modfiles') && file_exists(WB_PATH .'/modules/' .$mymod_dir .'/backend.css'))) {
|
171 |
|
|
return false;
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
|
|
// include frontend.css or backend.css into the <body> section
|
175 |
|
|
echo "\n".'<style type="text/css">'."\n";
|
176 |
|
|
include(WB_PATH .'/modules/' .$mymod_dir .'/' .$css_file);
|
177 |
|
|
echo "\n</style>\n";
|
178 |
|
|
return true;
|
179 |
|
|
}
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
// function to check if the optional module Javascript files are loaded into the <head> section
|
183 |
|
|
if (!function_exists('requires_module_js')) {
|
184 |
|
|
function requires_module_js($mymod_dir, $js_file) {
|
185 |
|
|
if(!in_array(strtolower($js_file), array('frontend.js', 'backend.js'))) {
|
186 |
1105
|
Ruebenwurz
|
echo '<strong>Note: </strong>Javascript file "' .htmlentities($js_file) .'"
|
187 |
|
|
specified in module "' .htmlentities($mymod_dir) .'" not valid.';
|
188 |
834
|
doc
|
return false;
|
189 |
|
|
}
|
190 |
1105
|
Ruebenwurz
|
|
191 |
834
|
doc
|
if($js_file == 'frontend.js') {
|
192 |
|
|
// check if frontend.js is included to the <head> section
|
193 |
|
|
if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) {
|
194 |
|
|
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
|
195 |
|
|
<p>This module uses Javascript functions contained in frontend.js of the module.<br />
|
196 |
|
|
Add the code below to the <head> section in the index.php of your template
|
197 |
|
|
to ensure that module frontend.js files are automatically loaded if required.</p>
|
198 |
|
|
<code style="color: #800000;"><?php<br />if(function_exists(\'register_frontend_modfiles\')) { <br />
|
199 |
|
|
register_frontend_modfiles(\'js\');<br />?></code><br />
|
200 |
1105
|
Ruebenwurz
|
<p><strong>Tip:</strong> For WB 2.6.7 copy the code above to the index.php of your template.
|
201 |
|
|
Then open the view.php of the "' .htmlentities($mymod_dir) .'" module and set the variable
|
202 |
|
|
<code>$requires_frontend_js</code> to false. This may do the trick.</p><p>All WB versions below 2.6.7 needs
|
203 |
834
|
doc
|
to be upgraded to work with this module.</p>
|
204 |
|
|
';
|
205 |
|
|
return false;
|
206 |
|
|
}
|
207 |
|
|
} else {
|
208 |
|
|
// check if backend.js is included to the <head> section
|
209 |
|
|
global $admin;
|
210 |
|
|
if(!method_exists($admin, 'register_backend_modfiles') && file_exists(WB_PATH .'/modules/' .$mymod_dir .'/backend.js')) {
|
211 |
|
|
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
|
212 |
|
|
<p>This module uses Javascript functions contained in backend.js of the module.<br />
|
213 |
|
|
You need WB 2.6.7 or higher to ensure that module backend.js files are automatically loaded if required.</p>
|
214 |
|
|
<p>Sorry, you can not use this tool with your WB installation, please upgrade to the latest WB version available.</p><br />
|
215 |
|
|
';
|
216 |
|
|
return false;
|
217 |
|
|
}
|
218 |
|
|
}
|
219 |
|
|
return true;
|
220 |
|
|
}
|
221 |
|
|
}
|
222 |
1105
|
Ruebenwurz
|
// function to check if the optional module Javascript files are loaded into the <body> section
|
223 |
|
|
if (!function_exists('requires_module_body_js')) {
|
224 |
|
|
function requires_module_body_js($mymod_dir, $js_file) {
|
225 |
|
|
if(!in_array(strtolower($js_file), array('frontend_body.js', 'backend_body.js'))) {
|
226 |
|
|
echo '<strong>Note: </strong>Javascript file "' .htmlentities($js_file) .'"
|
227 |
|
|
specified in module "' .htmlentities($mymod_dir) .'" not valid.';
|
228 |
|
|
return false;
|
229 |
|
|
}
|
230 |
834
|
doc
|
|
231 |
1105
|
Ruebenwurz
|
if($js_file == 'frontend_body.js') {
|
232 |
|
|
// check if frontend_body.js is included to the <body> section
|
233 |
|
|
if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) {
|
234 |
|
|
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
|
235 |
|
|
<p>This module uses Javascript functions contained in frontend_body.js of the module.<br />
|
236 |
|
|
Add the code below before to the </body> section in the index.php of your template
|
237 |
|
|
to ensure that module frontend_body.js files are automatically loaded if required.</p>
|
238 |
|
|
<code style="color: #800000;"><?php<br />if(function_exists(\'register_frontend_modfiles_body\')) { <br />
|
239 |
|
|
register_frontend_modfiles_body(\'js\');<br />?></code><br />
|
240 |
|
|
<p><strong>Tip:</strong> For WB 2.6.7 copy the code above to the index.php of your template.
|
241 |
|
|
Then open the view.php of the "' .htmlentities($mymod_dir) .'" module and set the variable
|
242 |
|
|
<code>$requires_frontend_body_js</code> to false. This may do the trick.</p><p>All WB versions below 2.6.7 needs
|
243 |
|
|
to be upgraded to work with this module.</p>
|
244 |
|
|
';
|
245 |
|
|
return false;
|
246 |
|
|
}
|
247 |
|
|
} else {
|
248 |
|
|
// check if backend_body.js is included to the <body> section
|
249 |
|
|
global $admin;
|
250 |
|
|
if(!method_exists($admin, 'register_backend_modfiles_body') && file_exists(WB_PATH .'/modules/' .$mymod_dir .'/backend_body.js')) {
|
251 |
|
|
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
|
252 |
|
|
<p>This module uses Javascript functions contained in backend_body.js of the module.<br />
|
253 |
|
|
You need WB 2.6.7 or higher to ensure that module backend_body.js files are automatically loaded if required.</p>
|
254 |
|
|
<p>Sorry, you can not use this tool with your WB installation, please upgrade to the latest WB version available.</p><br />
|
255 |
|
|
';
|
256 |
|
|
return false;
|
257 |
|
|
}
|
258 |
|
|
}
|
259 |
|
|
return true;
|
260 |
|
|
}
|
261 |
|
|
}
|