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
// DEFINE LANGUAGE DEPENDING OUTPUTS FOR THE EDIT CSS PART
27 562 Ruebenwurz
$lang_dir = WB_PATH .'/modules/' .basename(dirname(__FILE__)) .'/languages/';
28
if(file_exists($lang_dir .LANGUAGE .'.php')) {
29
	// try to include custom language file if exists
30
	require_once($lang_dir .LANGUAGE .'.php');
31
} elseif(file_exists($lang_dir .'EN.php')) {
32
	// try to include default module language file
33
	require_once($lang_dir .'EN.php');
34
}
35
36
// set defaults if output varibles are not set in the languages files
37
if(!isset($CAP_EDIT_CSS)) $CAP_EDIT_CSS	= 'Edit CSS';
38
if(!isset($CAP_TOGGLE_CSS)) $CAP_TOGGLE_CSS	= 'Switch to ';
39
if(!isset($HEADING_CSS_FILE))	$HEADING_CSS_FILE = 'Actual module file: ';
40
if(!isset($TXT_EDIT_CSS_FILE)) $TXT_EDIT_CSS_FILE = 'Edit the CSS definitions in the textarea below.';
41
42
// this function checks if the specified optional module file exists
43
if (!function_exists('mod_file_exists')) {
44
	function mod_file_exists($mod_file='frontend.css') {
45
		// extract the module directory
46
		$mod_dir = basename(dirname(__FILE__)) .'/' .$mod_file;
47
		return file_exists(WB_PATH .'/modules/' .$mod_dir);
48
	}
49
}
50
51
// this function displays a "Edit CSS" button in modify.php
52
// if the optional module files (module.css, module.js) if exists
53
if (!function_exists('css_edit')) {
54
	function css_edit() {
55
		global $page_id, $section_id, $CAP_EDIT_CSS;
56
		// extract the module directory
57
		$mod_dir = basename(dirname(__FILE__));
58
		$frontend_css = mod_file_exists('frontend.css');
59
		$backend_css = mod_file_exists('backend.css');
60
		if($frontend_css || $backend_css) {
61
			// display link to edit the optional CSS module files
62
			$file = $frontend_css ? 'frontend.css' : 'backend.css';
63
			$output  = '<div class="mod_' .$mod_dir .'_edit_css"><a href="' .WB_URL .'/modules/' .$mod_dir .'/edit_css.php';
64
			$output .= '?page_id=' .$page_id .'&section_id=' .$section_id .'&edit_file=' .$file .'">';
65
			$output .= $CAP_EDIT_CSS .'</a></div>';
66
			echo $output;
67
		}
68
	}
69
}
70
71
// this function returns a secure module file from $_GET['edit_file']
72
if (!function_exists('edit_mod_file')) {
73
	function edit_mod_file() {
74
		$allowed_files = array('frontend.css', 'backend.css');
75
		if(isset($_GET['edit_file']) && in_array($_GET['edit_file'], $allowed_files)) {
76
			return $_GET['edit_file'];
77
		} elseif(mod_file_exists('frontend.css')) {
78
			return 'frontend.css';
79
		} elseif(mod_file_exists('backend_css')) {
80
			return 'backend.css';
81
		} else {
82
			return '';
83
		}
84
	}
85
}
86
87
// this function displays a button to toggle between the optional module CSS files
88
// function is invoked from edit_css.php file
89
if (!function_exists('toggle_css_file')) {
90
	function toggle_css_file($base_css_file = 'frontend.css') {
91
		$allowed_mod_files = array('frontend.css', 'backend.css');
92
		if(!in_array($base_css_file, $allowed_mod_files)) return;
93
		global $page_id, $section_id, $CAP_TOGGLE_CSS;
94
		// extract the module directory
95
		$mod_dir = basename(dirname(__FILE__));
96
		$toggle_file = ($base_css_file == 'frontend.css') ? 'backend.css' : 'frontend.css';
97
		if(mod_file_exists($toggle_file)) {
98
			// display button to toggle between the two CSS files: frontend.css, backend.css
99
			$output  = '<div class="mod_' .$mod_dir .'_edit_css"><a href="' .WB_URL .'/modules/' .$mod_dir .'/edit_css.php';
100
			$output .= '?page_id=' .$page_id .'&section_id=' .$section_id .'&edit_file=' .$toggle_file .'">';
101
			$output .= $CAP_TOGGLE_CSS .$toggle_file .'</a></div>';
102
			echo $output;
103
		}
104
	}
105
}
106
107
?>