Project

General

Profile

1
<?php
2
/*
3
*
4
*                       About WebsiteBaker
5
*
6
* Website Baker is a PHP-based Content Management System (CMS)
7
* designed with one goal in mind: to enable its users to produce websites
8
* with ease.
9
*
10
*                       LICENSE INFORMATION
11
*
12
* WebsiteBaker is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; either version 2
15
* of the License, or (at your option) any later version.
16
*
17
* WebsiteBaker is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
* See the GNU General Public License for more details.
21
*
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
*
26
*                   WebsiteBaker Extra Information
27
*
28
*
29
*/
30
/**
31
 *
32
 * @category        backend
33
 * @package         modules
34
 * @author          WebsiteBaker Project
35
 * @copyright       2004-2009, Ryan Djurovich
36
 * @copyright       2009-2010, Website Baker Org. e.V.
37
 * @link			http://www.websitebaker2.org/
38
 * @license         http://www.gnu.org/licenses/gpl.html
39
 * @platform        WebsiteBaker 2.8.x
40
 * @requirements    PHP 4.3.4 and higher
41
 * @version         $Id: edit_module_files.php 1274 2010-01-24 13:55:18Z Luisehahne $
42
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/edit_module_files.php $
43
 * @lastmodified    $Date: 2010-01-24 14:55:18 +0100 (Sun, 24 Jan 2010) $
44
 *
45
*/
46

    
47
// prevent this file from being accessed directly
48
if(!(isset($_POST['page_id']) && isset($_POST['section_id']) && isset($_POST['action'])
49
	&& isset($_POST['mod_dir'])  && isset($_POST['edit_file']))) die(header('Location: index.php'));
50

    
51
// include configuration file and admin wrapper script
52
require('../config.php');
53

    
54
// include the and admin wrapper script
55
require(WB_PATH.'/modules/admin.php');
56

    
57
// leave if the required module.functions.php file does not exist
58
if(!file_exists(WB_PATH .'/framework/module.functions.php')) {
59
	echo 'The required file: /framework/module.functions.php is missing - script stopped.';
60
	die;
61
}
62

    
63
echo (function_exists('registerEditArea')) ? registerEditArea('code_area', 'css', false) : 'none';
64

    
65
// set default text output if varibles are not defined in the global WB language files
66
$HEADING_CSS_FILE = (isset($GLOBALS['TEXT']['HEADING_CSS_FILE'])) ?$GLOBALS['TEXT']['HEADING_CSS_FILE'] :'Actual module file: ';
67
$TXT_EDIT_CSS_FILE = (isset($GLOBALS['TEXT']['TXT_EDIT_CSS_FILE'])) ?$GLOBALS['TEXT']['TXT_EDIT_CSS_FILE'] :'Edit the CSS definitions in the textarea below.';
68

    
69
// include functions to edit the optional module CSS files (frontend.css, backend.css)
70
require_once(WB_PATH .'/framework/module.functions.php');
71

    
72
// check if the module directory is valid
73
$mod_dir = check_module_dir($_POST['mod_dir']);
74
if($mod_dir == '')
75
{
76
	echo 'The specified module directory is invalid - script stopped.';
77
	die;
78
};
79

    
80
// check if action is: save or edit
81
if($_POST['action'] == 'save' && mod_file_exists($mod_dir, $_POST['edit_file'])) {
82
	/** 
83
		SAVE THE UPDATED CONTENTS TO THE CSS FILE
84
	*/
85
	$css_content = '';
86
	if (isset($_POST['css_data']) && strlen($_POST['css_data']) > 0) {
87
		$css_content = stripslashes($_POST['css_data']);
88
	}
89

    
90
	$bytes = 0;
91
	if ($css_content != '')
92
    {
93
		// open the module CSS file for writting
94
		$mod_file = @fopen(WB_PATH .'/modules/' .$mod_dir .'/' .$_POST['edit_file'], 'wb');
95
		// write new content to the module CSS file
96
		$bytes = @fwrite($mod_file, $css_content);
97
		// close the file
98
		@fclose($mod_file);
99
	}
100

    
101
	// write out status message
102
	if($bytes == 0 )
103
    {
104
		$admin->print_error($TEXT['ERROR'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
105
	} else {
106
		$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
107
	}
108

    
109

    
110
} else {
111
	/** 
112
		MODIFY CONTENTS OF THE CSS FILE VIA TEXT AREA 
113
	*/
114
	// check if module backend.css file needs to be included into the <body>
115
	if((!method_exists($admin, 'register_backend_modfiles') || !isset($_GET['page_id']))
116
			&& file_exists(WB_PATH .'/modules/'.$mod_dir.'/backend.css')) {
117
		echo '<style type="text/css">';
118
		include(WB_PATH .'/modules/' .$mod_dir .'/backend.css');
119
		echo "\n</style>\n";
120
	}
121

    
122
	// check which module file to edit (frontend.css, backend.css or '')
123
	$css_file = (in_array($_POST['edit_file'], array('frontend.css', 'backend.css'))) ? $_POST['edit_file'] : '';
124

    
125
	// display output
126
	if($css_file == '')
127
    {
128
		// no valid module file to edit; display error message and backlink to modify.php
129
		echo "<h2>Nothing to edit</h2>";
130
		echo "<p>No valid module file exists for this module.</p>";
131
		$output  = "<a href=\"#\" onclick=\"javascript: window.location = '";
132
		$output .= ADMIN_URL ."/pages/modify.php?page_id=" .$page_id ."'\">back</a>";
133
		echo $output;
134
	
135
	} else {
136
		// store content of the module file in variable
137
		$css_content = @file_get_contents(WB_PATH .'/modules/' .$mod_dir .'/' .$css_file);
138
		// write out heading
139
		echo '<h2>' .$HEADING_CSS_FILE .'"' .$css_file .'"</h2>';
140
		// include button to switch between frontend.css and backend.css (only shown if both files exists)
141
		toggle_css_file($mod_dir, $css_file); 
142
		echo '<p>' .$TXT_EDIT_CSS_FILE .'</p>';
143

    
144
		// output content of module file to textareas
145
	?>
146
		<form name="edit_module_file" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" style="margin: 0;">
147
	  	<input type="hidden" name="page_id" value="<?php echo $page_id; ?>" />
148
	  	<input type="hidden" name="section_id" value="<?php echo $section_id; ?>" />
149
	  	<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>" />
150
		<input type="hidden" name="edit_file" value="<?php echo $css_file; ?>" />
151
	  	<input type="hidden" name="action" value="save" />
152
		<textarea id="code_area" name="css_data" cols="115" rows="25" wrap="VIRTUAL" style="margin:2px;width:100%;"><?php
153
			echo htmlspecialchars($css_content); ?>
154
		</textarea>
155
<?php
156

    
157
?>
158
  			<table cellpadding="0" cellspacing="0" border="0" width="100%">
159
  			<tr>
160
    			<td class="left">
161
 				<input name="save" type="submit" value="<?php echo $TEXT['SAVE'];?>" style="width: 100px; margin-top: 5px;" />
162
    			</td>
163
  				<td class="right">
164
      			<input type="button" value="<?php echo $TEXT['CANCEL']; ?>"
165
						onclick="javascript: window.location = '<?php echo ADMIN_URL;?>/pages/modify.php?page_id=<?php echo $page_id; ?>';"
166
						style="width: 100px; margin-top: 5px;" />
167
  				</td>
168
  			</tr>
169
  			</table>
170
		</form>
171
		<?php 
172
	}
173
}
174

    
175
// Print admin footer
176
$admin->print_footer();
177

    
178
?>
(2-2/3)