1 |
2
|
Manuela
|
<?php
|
2 |
|
|
|
3 |
|
|
// $Id$
|
4 |
|
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
|
|
Copyright (C) 2004-2009, Ryan Djurovich
|
9 |
|
|
|
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 |
|
|
This file contains routines to edit the optional module files: frontend.css and backend.css
|
28 |
|
|
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 |
|
|
Then simply call the function edit_css('your_module_directory') - that�s it
|
31 |
|
|
NOTE: Some functions were added for module developers to make the creation of own module easier
|
32 |
|
|
*/
|
33 |
|
|
|
34 |
|
|
/* -------------------------------------------------------- */
|
35 |
|
|
// Must include code to stop this file being accessed directly
|
36 |
|
|
if(!defined('WB_PATH')) {
|
37 |
|
|
require_once(dirname(__FILE__).'/globalExceptionHandler.php');
|
38 |
|
|
throw new IllegalFileException();
|
39 |
|
|
}
|
40 |
|
|
/* -------------------------------------------------------- */
|
41 |
|
|
|
42 |
|
|
/*
|
43 |
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
44 |
|
|
FUNCTIONS REQUIRED TO EDIT THE OPTIONAL MODULE CSS FILES
|
45 |
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
46 |
|
|
*/
|
47 |
|
|
|
48 |
|
|
// 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 |
|
|
global $page_id, $section_id, $admin;
|
70 |
|
|
|
71 |
|
|
// 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 |
|
|
// 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 |
|
|
?>
|
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; text-align:right;">
|
88 |
|
|
<?php echo $admin->getFTAN();?>
|
89 |
|
|
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>" />
|
90 |
|
|
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>" />
|
91 |
|
|
<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>" />
|
92 |
|
|
<input type="hidden" name="edit_file" value="<?php echo ($frontend_css) ? 'frontend.css' : 'backend.css';?>" />
|
93 |
|
|
<input type="hidden" name="action" value="edit" />
|
94 |
|
|
<input type="submit" value="<?php echo $edit_css_caption;?>" class="mod_<?php echo $mod_dir;?>_edit_css" />
|
95 |
|
|
</form>
|
96 |
|
|
<?php
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
// this function displays a button to toggle between CSS files (invoked from edit_css.php)
|
102 |
|
|
if (!function_exists('toggle_css_file')) {
|
103 |
|
|
function toggle_css_file($mod_dir, $base_css_file = 'frontend.css') {
|
104 |
|
|
global $page_id, $section_id, $admin;
|
105 |
|
|
// check if the required edit_module_css.php file exists
|
106 |
|
|
if(!file_exists(WB_PATH .'/modules/edit_module_files.php')) return;
|
107 |
|
|
|
108 |
|
|
// check if specified module directory is valid
|
109 |
|
|
if(check_module_dir($mod_dir) == '') return;
|
110 |
|
|
|
111 |
|
|
// do sanity check of specified css file
|
112 |
|
|
if(!in_array($base_css_file, array('frontend.css', 'backend.css'))) return;
|
113 |
|
|
|
114 |
|
|
// display button to toggle between the two CSS files: frontend.css, backend.css
|
115 |
|
|
$toggle_file = ($base_css_file == 'frontend.css') ? 'backend.css' : 'frontend.css';
|
116 |
|
|
if(mod_file_exists($mod_dir, $toggle_file)) {
|
117 |
|
|
?>
|
118 |
|
|
<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;">
|
119 |
|
|
<?php echo $admin->getFTAN();?>
|
120 |
|
|
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>" />
|
121 |
|
|
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>" />
|
122 |
|
|
<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>" />
|
123 |
|
|
<input type="hidden" name="edit_file" value="<?php echo $toggle_file; ?>" />
|
124 |
|
|
<input type="hidden" name="action" value="edit" />
|
125 |
|
|
<input type="submit" value="<?php echo ucwords($toggle_file);?>" class="mod_<?php echo $mod_dir;?>_edit_css" />
|
126 |
|
|
</form>
|
127 |
|
|
<?php
|
128 |
|
|
}
|
129 |
|
|
}
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
/*
|
133 |
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
134 |
|
|
FUNCTIONS WHICH CAN BE USED BY MODULE DEVELOPERS FOR OWN MODULES (E.G. VIEW.PHP, MODIFY.PHP)
|
135 |
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
136 |
|
|
*/
|
137 |
|
|
|
138 |
|
|
// function to obtain the module language file depending on the backend language of the current user
|
139 |
|
|
if (!function_exists('get_module_language_file')) {
|
140 |
|
|
function get_module_language_file($mymod_dir) {
|
141 |
|
|
$mymod_dir = strip_tags($mymod_dir);
|
142 |
|
|
if(file_exists(WB_PATH .'/modules/' .$mymod_dir .'/languages/' .LANGUAGE .'.php')) {
|
143 |
|
|
// a module language file exists for the users backend language
|
144 |
|
|
return (WB_PATH .'/modules/' .$mymod_dir .'/languages/' .LANGUAGE .'.php');
|
145 |
|
|
} else {
|
146 |
|
|
// an English module language file must exist in all multi-lingual modules
|
147 |
|
|
if(file_exists(WB_PATH .'/modules/' .$mymod_dir .'/languages/EN.php')) {
|
148 |
|
|
return (WB_PATH .'/modules/' .$mymod_dir .'/languages/EN.php');
|
149 |
|
|
} else {
|
150 |
|
|
echo '<p><strong>Error: </strong>';
|
151 |
|
|
echo 'Default language file (EN.php) of module "' .htmlentities($mymod_dir) .'" does not exist.</p><br />';
|
152 |
|
|
return false;
|
153 |
|
|
}
|
154 |
|
|
}
|
155 |
|
|
}
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
// function to include module CSS files in <body> (only if WB < 2.6.7 or register_frontend_modfiles('css') not invoked in template)
|
159 |
|
|
if (!function_exists('include_module_css')) {
|
160 |
|
|
function include_module_css($mymod_dir, $css_file) {
|
161 |
|
|
if(!in_array(strtolower($css_file), array('frontend.css', 'backend.css'))) return;
|
162 |
|
|
|
163 |
|
|
if($css_file == 'frontend.css') {
|
164 |
|
|
// check if frontend.css needs to be included into the <body> section
|
165 |
|
|
if(!((!function_exists('register_frontend_modfiles') || !defined('MOD_FRONTEND_CSS_REGISTERED')) &&
|
166 |
|
|
file_exists(WB_PATH .'/modules/' .$mymod_dir .'/frontend.css'))) {
|
167 |
|
|
return false;
|
168 |
|
|
}
|
169 |
|
|
} else {
|
170 |
|
|
// check if backend.css needs to be included into the <body> section
|
171 |
|
|
global $admin;
|
172 |
|
|
if(!(!method_exists($admin, 'register_backend_modfiles') && file_exists(WB_PATH .'/modules/' .$mymod_dir .'/backend.css'))) {
|
173 |
|
|
return false;
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
|
|
// include frontend.css or backend.css into the <body> section
|
177 |
|
|
echo "\n".'<style type="text/css">'."\n";
|
178 |
|
|
include(WB_PATH .'/modules/' .$mymod_dir .'/' .$css_file);
|
179 |
|
|
echo "\n</style>\n";
|
180 |
|
|
return true;
|
181 |
|
|
}
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
// function to check if the optional module Javascript files are loaded into the <head> section
|
185 |
|
|
if (!function_exists('requires_module_js')) {
|
186 |
|
|
function requires_module_js($mymod_dir, $js_file) {
|
187 |
|
|
if(!in_array(strtolower($js_file), array('frontend.js', 'backend.js'))) {
|
188 |
|
|
echo '<strong>Note: </strong>Javascript file "' .htmlentities($js_file) .'"
|
189 |
|
|
specified in module "' .htmlentities($mymod_dir) .'" not valid.';
|
190 |
|
|
return false;
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
if($js_file == 'frontend.js') {
|
194 |
|
|
// check if frontend.js is included to the <head> section
|
195 |
|
|
if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) {
|
196 |
|
|
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
|
197 |
|
|
<p>This module uses Javascript functions contained in frontend.js of the module.<br />
|
198 |
|
|
Add the code below to the <head> section in the index.php of your template
|
199 |
|
|
to ensure that module frontend.js files are automatically loaded if required.</p>
|
200 |
|
|
<code style="color: #800000;"><?php<br />if(function_exists(\'register_frontend_modfiles\')) { <br />
|
201 |
|
|
register_frontend_modfiles(\'js\');<br />?></code><br />
|
202 |
|
|
<p><strong>Tip:</strong> For WB 2.6.7 copy the code above to the index.php of your template.
|
203 |
|
|
Then open the view.php of the "' .htmlentities($mymod_dir) .'" module and set the variable
|
204 |
|
|
<code>$requires_frontend_js</code> to false. This may do the trick.</p><p>All WB versions below 2.6.7 needs
|
205 |
|
|
to be upgraded to work with this module.</p>
|
206 |
|
|
';
|
207 |
|
|
return false;
|
208 |
|
|
}
|
209 |
|
|
} else {
|
210 |
|
|
// check if backend.js is included to the <head> section
|
211 |
|
|
global $admin;
|
212 |
|
|
if(!method_exists($admin, 'register_backend_modfiles') && file_exists(WB_PATH .'/modules/' .$mymod_dir .'/backend.js')) {
|
213 |
|
|
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
|
214 |
|
|
<p>This module uses Javascript functions contained in backend.js of the module.<br />
|
215 |
|
|
You need WB 2.6.7 or higher to ensure that module backend.js files are automatically loaded if required.</p>
|
216 |
|
|
<p>Sorry, you can not use this tool with your WB installation, please upgrade to the latest WB version available.</p><br />
|
217 |
|
|
';
|
218 |
|
|
return false;
|
219 |
|
|
}
|
220 |
|
|
}
|
221 |
|
|
return true;
|
222 |
|
|
}
|
223 |
|
|
}
|
224 |
|
|
// function to check if the optional module Javascript files are loaded into the <body> section
|
225 |
|
|
if (!function_exists('requires_module_body_js')) {
|
226 |
|
|
function requires_module_body_js($mymod_dir, $js_file) {
|
227 |
|
|
if(!in_array(strtolower($js_file), array('frontend_body.js', 'backend_body.js'))) {
|
228 |
|
|
echo '<strong>Note: </strong>Javascript file "' .htmlentities($js_file) .'"
|
229 |
|
|
specified in module "' .htmlentities($mymod_dir) .'" not valid.';
|
230 |
|
|
return false;
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
if($js_file == 'frontend_body.js') {
|
234 |
|
|
// check if frontend_body.js is included to the <body> section
|
235 |
|
|
if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) {
|
236 |
|
|
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
|
237 |
|
|
<p>This module uses Javascript functions contained in frontend_body.js of the module.<br />
|
238 |
|
|
Add the code below before to the </body> section in the index.php of your template
|
239 |
|
|
to ensure that module frontend_body.js files are automatically loaded if required.</p>
|
240 |
|
|
<code style="color: #800000;"><?php<br />if(function_exists(\'register_frontend_modfiles_body\')) { <br />
|
241 |
|
|
register_frontend_modfiles_body(\'js\');<br />?></code><br />
|
242 |
|
|
<p><strong>Tip:</strong> For WB 2.6.7 copy the code above to the index.php of your template.
|
243 |
|
|
Then open the view.php of the "' .htmlentities($mymod_dir) .'" module and set the variable
|
244 |
|
|
<code>$requires_frontend_body_js</code> to false. This may do the trick.</p><p>All WB versions below 2.6.7 needs
|
245 |
|
|
to be upgraded to work with this module.</p>
|
246 |
|
|
';
|
247 |
|
|
return false;
|
248 |
|
|
}
|
249 |
|
|
} else {
|
250 |
|
|
// check if backend_body.js is included to the <body> section
|
251 |
|
|
global $admin;
|
252 |
|
|
if(!method_exists($admin, 'register_backend_modfiles_body') && file_exists(WB_PATH .'/modules/' .$mymod_dir .'/backend_body.js')) {
|
253 |
|
|
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
|
254 |
|
|
<p>This module uses Javascript functions contained in backend_body.js of the module.<br />
|
255 |
|
|
You need WB 2.6.7 or higher to ensure that module backend_body.js files are automatically loaded if required.</p>
|
256 |
|
|
<p>Sorry, you can not use this tool with your WB installation, please upgrade to the latest WB version available.</p><br />
|
257 |
|
|
';
|
258 |
|
|
return false;
|
259 |
|
|
}
|
260 |
|
|
}
|
261 |
|
|
return true;
|
262 |
|
|
}
|
263 |
|
|
}
|