Project

General

Profile

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
		global $page_id, $section_id, $CAP_EDIT_CSS;
58
		// check if the required edit_module_css.php file exists
59
		if(!file_exists(WB_PATH .'/modules/edit_module_files.php')) return;
60
61
		// check if specified module directory is valid
62
		if(check_module_dir($mod_dir) == '') return;
63
64
		// check if frontend.css or backend.css exist
65
		$frontend_css = mod_file_exists($mod_dir, 'frontend.css');
66
		$backend_css = mod_file_exists($mod_dir, 'backend.css');
67
68
		// output the edit CSS submtin button if required
69
		if($frontend_css || $backend_css) {
70
			// default text used for the edit CSS routines if not defined in the modules language file
71
			if(!isset($CAP_EDIT_CSS)) $CAP_EDIT_CSS	= 'Edit CSS';
72
			?>
73
			<form name="edit_module_file" action="<?php echo WB_URL .'/modules/edit_module_files.php?page_id='.$page_id;?>"
74
				method="post" style="margin: 0; align:right;">
75
				<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
76
				<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
77
				<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>">
78
				<input type="hidden" name="edit_file" value="<?php echo ($frontend_css) ?'frontend.css' : 'backend.css';?>">
79
				<input type="hidden" name="action" value="edit">
80
				<input type="submit" value="<?php echo $CAP_EDIT_CSS;?>" class="mod_<?php echo $mod_dir;?>_edit_css">
81
			</form>
82
			<?php
83
    }
84
  }
85
}
86
87
// this function displays a button to toggle between CSS files (invoked from edit_css.php)
88
if (!function_exists('toggle_css_file')) {
89
	function toggle_css_file($mod_dir, $base_css_file = 'frontend.css') {
90
		global $page_id, $section_id;
91
		// check if the required edit_module_css.php file exists
92
		if(!file_exists(WB_PATH .'/modules/edit_module_files.php')) return;
93
94
		// check if specified module directory is valid
95
		if(check_module_dir($mod_dir) == '') return;
96
97
		// do sanity check of specified css file
98
		if(!in_array($base_css_file, array('frontend.css', 'backend.css'))) return;
99
100
		// display button to toggle between the two CSS files: frontend.css, backend.css
101
		$toggle_file = ($base_css_file == 'frontend.css') ? 'backend.css' : 'frontend.css';
102
		if(mod_file_exists($mod_dir, $toggle_file)) {
103
			?>
104
			<form name="toggle_module_file" action="<?php echo WB_URL .'/modules/edit_module_files.php?page_id='.$page_id;?>"
105
				method="post" style="margin: 0; align:right;">
106
				<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
?>