Project

General

Profile

1 562 Ruebenwurz
<?php
2
3
// $Id$
4
5
######################################################################################################################
6
#
7
#	PURPOSE OF THIS FILE:
8
#	This file contains the routines required to edit the optional module files: frontend.css and backend.css.
9
# Nothing needs to be changed in this file. Keep it as is.
10
#
11
#	INVOKED BY:
12
#	This file should be invoked by clicking on a text link shown in modify.php.
13
#
14
######################################################################################################################
15
16
/**
17
  Module developed for the Open Source Content Management System Website Baker (http://websitebaker.org)
18
  Copyright (C) year, Authors name
19
  Contact me: author(at)domain.xxx, http://authorwebsite.xxx
20
21
  This module is free software. You can redistribute it and/or modify it
22
  under the terms of the GNU General Public License  - version 2 or later,
23
  as published by the Free Software Foundation: http://www.gnu.org/licenses/gpl.html.
24
25
  This module is distributed in the hope that it will be useful,
26
  but WITHOUT ANY WARRANTY; without even the implied warranty of
27
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
  GNU General Public License for more details.
29
**/
30
31
// include configuration file and admin wrapper script
32
require('../../config.php');
33
require(WB_PATH.'/modules/admin.php');
34
35
// include functions to edit the optional module CSS files (frontend.css, backend.css)
36
require_once('css.functions.php');
37
38
// check if action is: save or edit
39
if(isset($_GET['action']) && $_GET['action'] == 'save' && isset($_POST['edit_file']) && mod_file_exists($_POST['edit_file'])) {
40
	/**
41
	SAVE THE UPDATED CONTENTS TO THE CSS FILE
42
	*/
43
	$css_content = '';
44
	if(isset($_POST['css_codepress']) && strlen($_POST['css_codepress']) > 0) {
45
		// if Javascript is enabled, take contents from hidden field: css_codepress
46
		$css_content = stripslashes($_POST['css_codepress']);
47
	} elseif(isset($_POST['css_data']) && strlen($_POST['css_data']) > 0) {
48
		// if Javascript is disabled, take contens from textarea: css_data
49
		$css_content = stripslashes($_POST['css_data']);
50
	}
51
52
	$bytes = 0;
53
	if ($css_content != '') {
54
		// open the module CSS file for writting
55
		$mod_file = @fopen(dirname(__FILE__) .'/' .$_POST['edit_file'], "wb");
56
		// write new content to the module CSS file
57
		$bytes = @fwrite($mod_file, $css_content);
58
		// close the file
59
		@fclose($mod_file);
60
	}
61
62
	// write out status message
63
	if($bytes == 0 ) {
64
		$admin->print_error($TEXT['ERROR'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
65
	} else {
66
		$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
67
	}
68
69
} else {
70
	/**
71
	MODIFY CONTENTS OF THE CSS FILE VIA TEXT AREA
72
	*/
73
74
	// check which module file to edit (frontend.css, backend.css or '')
75
	$css_file = '';
76
	if(isset($_GET['edit_file'])) $css_file = edit_mod_file($_GET['edit_file']);
77
78
	// display output
79
	if($css_file == '') {
80
		// no valid module file to edit; display error message and backlink to modify.php
81
		echo "<h2>Nothing to edit</h2>";
82
		echo "<p>No valid module file exists for this module.</p>";
83
		$output  = "<a href=\"#\" onclick=\"javascript: window.location = '";
84
		$output .= ADMIN_URL ."/pages/modify.php?page_id=" .$page_id ."'\">back</a>";
85
		echo $output;
86
	} else {
87
		// store content of the module file in variable
88
		$css_content = @file_get_contents(dirname(__FILE__) .'/' .$css_file);
89
		// output content of module file to textareas
90
		?>
91
92
		<form name="edit_module_file" action="<?php echo $_SERVER['PHP_SELF'] .'?action=save';?>" method="post" style="margin: 0;">
93
			<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
94
			<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
95
			<input type="hidden" name="css_codepress" value="" />
96
			<input type="hidden" name="edit_file" value="<?php echo $css_file; ?>" />
97
98
			<h2><?php echo $HEADING_CSS_FILE .'"' .$css_file; ?>"</h2>
99
			<?php
100
				// include the toggle button to switch between frontend.css and backend.css (if both files exists)
101
				toggle_css_file($css_file);
102
			?>
103
104
			<p><?php echo $TXT_EDIT_CSS_FILE; ?></p>
105
106
			<textarea name="css_data" id="css_data" class="codepress css" cols="115" rows="25" wrap="VIRTUAL" style="margin:2px;"><?php echo $css_content; ?></textarea>
107
108
			<table cellpadding="0" cellspacing="0" border="0" width="100%">
109
				<tr>
110
					<td align="left">
111
						<input name="save" type="submit" value="<?php echo $TEXT['SAVE'];?>" onclick="javascript: css_codepress.value = css_data.getCode();" style="width: 100px; margin-top: 5px;" />
112
					</td>
113
					<td align="right">
114
						<input type="button" value="<?php echo $TEXT['CANCEL']; ?>"	onclick="javascript: window.location = '<?php echo ADMIN_URL;?>/pages/modify.php?page_id=<?php echo $page_id; ?>';"	style="width: 100px; margin-top: 5px;" />
115
					</td>
116
				</tr>
117
			</table>
118
		</form>
119
	<?php
120
	}
121
}
122
123
// Print admin footer
124
$admin->print_footer();
125
126
?>