Project

General

Profile

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