1 |
801
|
doc
|
<?php
|
2 |
|
|
|
3 |
|
|
// $Id$
|
4 |
|
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
|
|
Copyright (C) 2004-2008, 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 the 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 |
|
|
*/
|
32 |
|
|
|
33 |
|
|
// prevent this file from being accessed directly
|
34 |
|
|
if(!defined('WB_PATH')) die(header('Location: index.php'));
|
35 |
|
|
|
36 |
|
|
// this function checks the validity of the specified module directory
|
37 |
|
|
if(!function_exists('check_module_dir')) {
|
38 |
|
|
function check_module_dir($mod_dir) {
|
39 |
|
|
// check if module directory is formal correct (only characters: "a-z,0-9,_,-")
|
40 |
|
|
if(!preg_match('/^[a-z0-9_-]+$/iD', $mod_dir)) return '';
|
41 |
|
|
// check if the module folder contains the required info.php file
|
42 |
|
|
return (file_exists(WB_PATH .'/modules/' .$mod_dir .'/info.php')) ? $mod_dir : '';
|
43 |
|
|
}
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
// this function checks if the specified optional module file exists
|
47 |
|
|
if (!function_exists('mod_file_exists')) {
|
48 |
|
|
function mod_file_exists($mod_dir, $mod_file='frontend.css') {
|
49 |
|
|
// check if the module file exists
|
50 |
|
|
return file_exists(WB_PATH .'/modules/' .$mod_dir .'/' .$mod_file);
|
51 |
|
|
}
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
// this function displays the "Edit CSS" button in modify.php
|
55 |
|
|
if (!function_exists('edit_module_css')) {
|
56 |
|
|
function edit_module_css($mod_dir) {
|
57 |
810
|
doc
|
global $page_id, $section_id;
|
58 |
|
|
|
59 |
801
|
doc
|
// check if the required edit_module_css.php file exists
|
60 |
|
|
if(!file_exists(WB_PATH .'/modules/edit_module_files.php')) return;
|
61 |
|
|
|
62 |
|
|
// check if specified module directory is valid
|
63 |
|
|
if(check_module_dir($mod_dir) == '') return;
|
64 |
|
|
|
65 |
|
|
// check if frontend.css or backend.css exist
|
66 |
|
|
$frontend_css = mod_file_exists($mod_dir, 'frontend.css');
|
67 |
|
|
$backend_css = mod_file_exists($mod_dir, 'backend.css');
|
68 |
|
|
|
69 |
|
|
// output the edit CSS submtin button if required
|
70 |
|
|
if($frontend_css || $backend_css) {
|
71 |
810
|
doc
|
// default text used for the edit CSS routines if not defined in the WB core language files
|
72 |
|
|
$edit_css_caption = (isset($GLOBALS['TEXT']['CAP_EDIT_CSS'])) ?$GLOBALS['TEXT']['CAP_EDIT_CSS'] :'Edit CSS';
|
73 |
801
|
doc
|
?>
|
74 |
|
|
<form name="edit_module_file" action="<?php echo WB_URL .'/modules/edit_module_files.php?page_id='.$page_id;?>"
|
75 |
|
|
method="post" style="margin: 0; align:right;">
|
76 |
|
|
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
|
77 |
|
|
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
|
78 |
|
|
<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>">
|
79 |
|
|
<input type="hidden" name="edit_file" value="<?php echo ($frontend_css) ?'frontend.css' : 'backend.css';?>">
|
80 |
|
|
<input type="hidden" name="action" value="edit">
|
81 |
810
|
doc
|
<input type="submit" value="<?php echo $edit_css_caption;?>" class="mod_<?php echo $mod_dir;?>_edit_css">
|
82 |
801
|
doc
|
</form>
|
83 |
|
|
<?php
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
// this function displays a button to toggle between CSS files (invoked from edit_css.php)
|
89 |
|
|
if (!function_exists('toggle_css_file')) {
|
90 |
|
|
function toggle_css_file($mod_dir, $base_css_file = 'frontend.css') {
|
91 |
|
|
global $page_id, $section_id;
|
92 |
|
|
// check if the required edit_module_css.php file exists
|
93 |
|
|
if(!file_exists(WB_PATH .'/modules/edit_module_files.php')) return;
|
94 |
|
|
|
95 |
|
|
// check if specified module directory is valid
|
96 |
|
|
if(check_module_dir($mod_dir) == '') return;
|
97 |
|
|
|
98 |
|
|
// do sanity check of specified css file
|
99 |
|
|
if(!in_array($base_css_file, array('frontend.css', 'backend.css'))) return;
|
100 |
|
|
|
101 |
|
|
// display button to toggle between the two CSS files: frontend.css, backend.css
|
102 |
|
|
$toggle_file = ($base_css_file == 'frontend.css') ? 'backend.css' : 'frontend.css';
|
103 |
|
|
if(mod_file_exists($mod_dir, $toggle_file)) {
|
104 |
|
|
?>
|
105 |
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;">
|
106 |
801
|
doc
|
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
|
107 |
|
|
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
|
108 |
|
|
<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>">
|
109 |
|
|
<input type="hidden" name="edit_file" value="<?php echo $toggle_file; ?>">
|
110 |
|
|
<input type="hidden" name="action" value="edit">
|
111 |
|
|
<input type="submit" value="<?php echo ucwords($toggle_file);?>" class="mod_<?php echo $mod_dir;?>_edit_css">
|
112 |
|
|
</form>
|
113 |
|
|
<?php
|
114 |
|
|
}
|
115 |
|
|
}
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
?>
|