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 |
|
|
require_once('globalExceptionHandler.php');
|
37 |
|
|
if(!defined('WB_PATH')) { throw new IllegalFileException(); }
|
38 |
|
|
/* -------------------------------------------------------- */
|
39 |
801
|
doc
|
|
40 |
834
|
doc
|
/*
|
41 |
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
42 |
|
|
FUNCTIONS REQUIRED TO EDIT THE OPTIONAL MODULE CSS FILES
|
43 |
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
44 |
|
|
*/
|
45 |
|
|
|
46 |
801
|
doc
|
// this function checks the validity of the specified module directory
|
47 |
|
|
if(!function_exists('check_module_dir')) {
|
48 |
|
|
function check_module_dir($mod_dir) {
|
49 |
|
|
// check if module directory is formal correct (only characters: "a-z,0-9,_,-")
|
50 |
|
|
if(!preg_match('/^[a-z0-9_-]+$/iD', $mod_dir)) return '';
|
51 |
|
|
// check if the module folder contains the required info.php file
|
52 |
|
|
return (file_exists(WB_PATH .'/modules/' .$mod_dir .'/info.php')) ? $mod_dir : '';
|
53 |
|
|
}
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
// this function checks if the specified optional module file exists
|
57 |
|
|
if (!function_exists('mod_file_exists')) {
|
58 |
|
|
function mod_file_exists($mod_dir, $mod_file='frontend.css') {
|
59 |
|
|
// check if the module file exists
|
60 |
|
|
return file_exists(WB_PATH .'/modules/' .$mod_dir .'/' .$mod_file);
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
// this function displays the "Edit CSS" button in modify.php
|
65 |
|
|
if (!function_exists('edit_module_css')) {
|
66 |
|
|
function edit_module_css($mod_dir) {
|
67 |
810
|
doc
|
global $page_id, $section_id;
|
68 |
1428
|
Luisehahne
|
|
69 |
801
|
doc
|
// check if the required edit_module_css.php file exists
|
70 |
|
|
if(!file_exists(WB_PATH .'/modules/edit_module_files.php')) return;
|
71 |
|
|
|
72 |
|
|
// check if specified module directory is valid
|
73 |
|
|
if(check_module_dir($mod_dir) == '') return;
|
74 |
|
|
|
75 |
|
|
// check if frontend.css or backend.css exist
|
76 |
|
|
$frontend_css = mod_file_exists($mod_dir, 'frontend.css');
|
77 |
|
|
$backend_css = mod_file_exists($mod_dir, 'backend.css');
|
78 |
|
|
|
79 |
|
|
// output the edit CSS submtin button if required
|
80 |
|
|
if($frontend_css || $backend_css) {
|
81 |
810
|
doc
|
// default text used for the edit CSS routines if not defined in the WB core language files
|
82 |
|
|
$edit_css_caption = (isset($GLOBALS['TEXT']['CAP_EDIT_CSS'])) ?$GLOBALS['TEXT']['CAP_EDIT_CSS'] :'Edit CSS';
|
83 |
801
|
doc
|
?>
|
84 |
|
|
<form name="edit_module_file" action="<?php echo WB_URL .'/modules/edit_module_files.php?page_id='.$page_id;?>"
|
85 |
|
|
method="post" style="margin: 0; align:right;">
|
86 |
1069
|
Ruebenwurz
|
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>" />
|
87 |
|
|
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>" />
|
88 |
|
|
<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>" />
|
89 |
1428
|
Luisehahne
|
<input type="hidden" name="edit_file" value="<?php echo ($frontend_css) ? 'frontend.css' : 'backend.css';?>" />
|
90 |
1069
|
Ruebenwurz
|
<input type="hidden" name="action" value="edit" />
|
91 |
|
|
<input type="submit" value="<?php echo $edit_css_caption;?>" class="mod_<?php echo $mod_dir;?>_edit_css" />
|
92 |
801
|
doc
|
</form>
|
93 |
|
|
<?php
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
// this function displays a button to toggle between CSS files (invoked from edit_css.php)
|
99 |
|
|
if (!function_exists('toggle_css_file')) {
|
100 |
|
|
function toggle_css_file($mod_dir, $base_css_file = 'frontend.css') {
|
101 |
|
|
global $page_id, $section_id;
|
102 |
|
|
// check if the required edit_module_css.php file exists
|
103 |
|
|
if(!file_exists(WB_PATH .'/modules/edit_module_files.php')) return;
|
104 |
|
|
|
105 |
|
|
// check if specified module directory is valid
|
106 |
|
|
if(check_module_dir($mod_dir) == '') return;
|
107 |
|
|
|
108 |
|
|
// do sanity check of specified css file
|
109 |
|
|
if(!in_array($base_css_file, array('frontend.css', 'backend.css'))) return;
|
110 |
|
|
|
111 |
|
|
// display button to toggle between the two CSS files: frontend.css, backend.css
|
112 |
|
|
$toggle_file = ($base_css_file == 'frontend.css') ? 'backend.css' : 'frontend.css';
|
113 |
|
|
if(mod_file_exists($mod_dir, $toggle_file)) {
|
114 |
|
|
?>
|
115 |
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;">
|
116 |
1069
|
Ruebenwurz
|
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>" />
|
117 |
|
|
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>" />
|
118 |
|
|
<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>" />
|
119 |
|
|
<input type="hidden" name="edit_file" value="<?php echo $toggle_file; ?>" />
|
120 |
|
|
<input type="hidden" name="action" value="edit" />
|
121 |
|
|
<input type="submit" value="<?php echo ucwords($toggle_file);?>" class="mod_<?php echo $mod_dir;?>_edit_css" />
|
122 |
801
|
doc
|
</form>
|
123 |
|
|
<?php
|
124 |
|
|
}
|
125 |
|
|
}
|
126 |
|
|
}
|
127 |
|
|
|
128 |
834
|
doc
|
/*
|
129 |
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
130 |
|
|
FUNCTIONS WHICH CAN BE USED BY MODULE DEVELOPERS FOR OWN MODULES (E.G. VIEW.PHP, MODIFY.PHP)
|
131 |
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
132 |
|
|
*/
|
133 |
|
|
|
134 |
|
|
// function to obtain the module language file depending on the backend language of the current user
|
135 |
|
|
if (!function_exists('get_module_language_file')) {
|
136 |
|
|
function get_module_language_file($mymod_dir) {
|
137 |
|
|
$mymod_dir = strip_tags($mymod_dir);
|
138 |
|
|
if(file_exists(WB_PATH .'/modules/' .$mymod_dir .'/languages/' .LANGUAGE .'.php')) {
|
139 |
|
|
// a module language file exists for the users backend language
|
140 |
|
|
return (WB_PATH .'/modules/' .$mymod_dir .'/languages/' .LANGUAGE .'.php');
|
141 |
|
|
} else {
|
142 |
|
|
// an English module language file must exist in all multi-lingual modules
|
143 |
|
|
if(file_exists(WB_PATH .'/modules/' .$mymod_dir .'/languages/EN.php')) {
|
144 |
|
|
return (WB_PATH .'/modules/' .$mymod_dir .'/languages/EN.php');
|
145 |
|
|
} else {
|
146 |
|
|
echo '<p><strong>Error: </strong>';
|
147 |
|
|
echo 'Default language file (EN.php) of module "' .htmlentities($mymod_dir) .'" does not exist.</p><br />';
|
148 |
|
|
return false;
|
149 |
|
|
}
|
150 |
|
|
}
|
151 |
|
|
}
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
// function to include module CSS files in <body> (only if WB < 2.6.7 or register_frontend_modfiles('css') not invoked in template)
|
155 |
|
|
if (!function_exists('include_module_css')) {
|
156 |
|
|
function include_module_css($mymod_dir, $css_file) {
|
157 |
|
|
if(!in_array(strtolower($css_file), array('frontend.css', 'backend.css'))) return;
|
158 |
|
|
|
159 |
|
|
if($css_file == 'frontend.css') {
|
160 |
|
|
// check if frontend.css needs to be included into the <body> section
|
161 |
1105
|
Ruebenwurz
|
if(!((!function_exists('register_frontend_modfiles') || !defined('MOD_FRONTEND_CSS_REGISTERED')) &&
|
162 |
834
|
doc
|
file_exists(WB_PATH .'/modules/' .$mymod_dir .'/frontend.css'))) {
|
163 |
|
|
return false;
|
164 |
|
|
}
|
165 |
|
|
} else {
|
166 |
|
|
// check if backend.css needs to be included into the <body> section
|
167 |
|
|
global $admin;
|
168 |
|
|
if(!(!method_exists($admin, 'register_backend_modfiles') && file_exists(WB_PATH .'/modules/' .$mymod_dir .'/backend.css'))) {
|
169 |
|
|
return false;
|
170 |
|
|
}
|
171 |
|
|
}
|
172 |
|
|
// include frontend.css or backend.css into the <body> section
|
173 |
|
|
echo "\n".'<style type="text/css">'."\n";
|
174 |
|
|
include(WB_PATH .'/modules/' .$mymod_dir .'/' .$css_file);
|
175 |
|
|
echo "\n</style>\n";
|
176 |
|
|
return true;
|
177 |
|
|
}
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
// function to check if the optional module Javascript files are loaded into the <head> section
|
181 |
|
|
if (!function_exists('requires_module_js')) {
|
182 |
|
|
function requires_module_js($mymod_dir, $js_file) {
|
183 |
|
|
if(!in_array(strtolower($js_file), array('frontend.js', 'backend.js'))) {
|
184 |
1105
|
Ruebenwurz
|
echo '<strong>Note: </strong>Javascript file "' .htmlentities($js_file) .'"
|
185 |
|
|
specified in module "' .htmlentities($mymod_dir) .'" not valid.';
|
186 |
834
|
doc
|
return false;
|
187 |
|
|
}
|
188 |
1105
|
Ruebenwurz
|
|
189 |
834
|
doc
|
if($js_file == 'frontend.js') {
|
190 |
|
|
// check if frontend.js is included to the <head> section
|
191 |
|
|
if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) {
|
192 |
|
|
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
|
193 |
|
|
<p>This module uses Javascript functions contained in frontend.js of the module.<br />
|
194 |
|
|
Add the code below to the <head> section in the index.php of your template
|
195 |
|
|
to ensure that module frontend.js files are automatically loaded if required.</p>
|
196 |
|
|
<code style="color: #800000;"><?php<br />if(function_exists(\'register_frontend_modfiles\')) { <br />
|
197 |
|
|
register_frontend_modfiles(\'js\');<br />?></code><br />
|
198 |
1105
|
Ruebenwurz
|
<p><strong>Tip:</strong> For WB 2.6.7 copy the code above to the index.php of your template.
|
199 |
|
|
Then open the view.php of the "' .htmlentities($mymod_dir) .'" module and set the variable
|
200 |
|
|
<code>$requires_frontend_js</code> to false. This may do the trick.</p><p>All WB versions below 2.6.7 needs
|
201 |
834
|
doc
|
to be upgraded to work with this module.</p>
|
202 |
|
|
';
|
203 |
|
|
return false;
|
204 |
|
|
}
|
205 |
|
|
} else {
|
206 |
|
|
// check if backend.js is included to the <head> section
|
207 |
|
|
global $admin;
|
208 |
|
|
if(!method_exists($admin, 'register_backend_modfiles') && file_exists(WB_PATH .'/modules/' .$mymod_dir .'/backend.js')) {
|
209 |
|
|
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
|
210 |
|
|
<p>This module uses Javascript functions contained in backend.js of the module.<br />
|
211 |
|
|
You need WB 2.6.7 or higher to ensure that module backend.js files are automatically loaded if required.</p>
|
212 |
|
|
<p>Sorry, you can not use this tool with your WB installation, please upgrade to the latest WB version available.</p><br />
|
213 |
|
|
';
|
214 |
|
|
return false;
|
215 |
|
|
}
|
216 |
|
|
}
|
217 |
|
|
return true;
|
218 |
|
|
}
|
219 |
|
|
}
|
220 |
1105
|
Ruebenwurz
|
// function to check if the optional module Javascript files are loaded into the <body> section
|
221 |
|
|
if (!function_exists('requires_module_body_js')) {
|
222 |
|
|
function requires_module_body_js($mymod_dir, $js_file) {
|
223 |
|
|
if(!in_array(strtolower($js_file), array('frontend_body.js', 'backend_body.js'))) {
|
224 |
|
|
echo '<strong>Note: </strong>Javascript file "' .htmlentities($js_file) .'"
|
225 |
|
|
specified in module "' .htmlentities($mymod_dir) .'" not valid.';
|
226 |
|
|
return false;
|
227 |
|
|
}
|
228 |
834
|
doc
|
|
229 |
1105
|
Ruebenwurz
|
if($js_file == 'frontend_body.js') {
|
230 |
|
|
// check if frontend_body.js is included to the <body> section
|
231 |
|
|
if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) {
|
232 |
|
|
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
|
233 |
|
|
<p>This module uses Javascript functions contained in frontend_body.js of the module.<br />
|
234 |
|
|
Add the code below before to the </body> section in the index.php of your template
|
235 |
|
|
to ensure that module frontend_body.js files are automatically loaded if required.</p>
|
236 |
|
|
<code style="color: #800000;"><?php<br />if(function_exists(\'register_frontend_modfiles_body\')) { <br />
|
237 |
|
|
register_frontend_modfiles_body(\'js\');<br />?></code><br />
|
238 |
|
|
<p><strong>Tip:</strong> For WB 2.6.7 copy the code above to the index.php of your template.
|
239 |
|
|
Then open the view.php of the "' .htmlentities($mymod_dir) .'" module and set the variable
|
240 |
|
|
<code>$requires_frontend_body_js</code> to false. This may do the trick.</p><p>All WB versions below 2.6.7 needs
|
241 |
|
|
to be upgraded to work with this module.</p>
|
242 |
|
|
';
|
243 |
|
|
return false;
|
244 |
|
|
}
|
245 |
|
|
} else {
|
246 |
|
|
// check if backend_body.js is included to the <body> section
|
247 |
|
|
global $admin;
|
248 |
|
|
if(!method_exists($admin, 'register_backend_modfiles_body') && file_exists(WB_PATH .'/modules/' .$mymod_dir .'/backend_body.js')) {
|
249 |
|
|
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
|
250 |
|
|
<p>This module uses Javascript functions contained in backend_body.js of the module.<br />
|
251 |
|
|
You need WB 2.6.7 or higher to ensure that module backend_body.js files are automatically loaded if required.</p>
|
252 |
|
|
<p>Sorry, you can not use this tool with your WB installation, please upgrade to the latest WB version available.</p><br />
|
253 |
|
|
';
|
254 |
|
|
return false;
|
255 |
|
|
}
|
256 |
|
|
}
|
257 |
|
|
return true;
|
258 |
|
|
}
|
259 |
|
|
}
|