Project

General

Profile

« Previous | Next » 

Revision 1449

Added by DarkViper over 13 years ago

cleanup some code in edit_module_files.php

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12

  
13 13
------------------------------------- 2.8.2 -------------------------------------
14
07 May-2011 Build 1449 Werner v.d.Decken(DarkViper)
15
! cleanup some code in edit_module_files.php
14 16
07 May-2011 Build 1448 Dietmar Woellbrink (Luisehahne)
15 17
# secure fix edit_module_files.php
16 18
# fix wb_wrapper_edit_area.php
branches/2.8.x/wb/admin/interface/version.php
52 52

  
53 53
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
54 54
if(!defined('VERSION')) define('VERSION', '2.8.2.RC5');
55
if(!defined('REVISION')) define('REVISION', '1448');
55
if(!defined('REVISION')) define('REVISION', '1449');
56 56

  
57 57
?>
branches/2.8.x/wb/modules/edit_module_files.php
1
<?php
2
/**
3
 *
4
 * @category        backend
5
 * @package         modules
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18

  
19
// include required libraries
20
// include configuration file
21
	require('../config.php');
22
// include edit area wrapper script
23
	require_once(WB_PATH.'/include/editarea/wb_wrapper_edit_area.php');
24
// include the admin wrapper script
25
	require(WB_PATH.'/modules/admin.php');
26
// include functions to edit the optional module CSS files (frontend.css, backend.css)
27
	require_once(WB_PATH.'/framework/module.functions.php');
28

  
29
	$page_id = (isset($_REQUEST['page_id']) ? intval($_REQUEST['page_id']) : 0  );
30
	$section_id = (isset($_POST['section_id']) ? intval($_POST['section_id']) : 0  );
31
	$_action = (isset($_POST['action']) ? strtolower($_POST['action']) : '');
32
	$_action = ($_action != 'save' ? 'edit' : 'save');
33
	$mod_dir = (isset($_POST['mod_dir']) ? $_POST['mod_dir'] : '');
34
	$_edit_file = (isset($_POST['edit_file']) ? $_POST['edit_file'] : '');
35
//check if given mod_dir + edit_file is valid path/file
36
	$_realpath = realpath(WB_PATH.'/modules/'.$mod_dir.'/'.$_edit_file);
37
	if($_realpath){
38
	// realpath is a valid path, now test if it's inside WB_PATH
39
		$_realpath = str_replace('\\','/', $_realpath);
40
		$_fileValid = (strpos($_realpath, (str_replace('\\','/', WB_PATH))) !== false);
41
	}
42
// check if all needed args are valid 
43
	if(!$page_id || !$section_id || !$_realpath || !$_fileValid) {
44
		die('Invalid arguments passed - script stopped.');
45
	}
46

  
47
	// echo registerEditArea('code_area', 'css');
48
	echo (function_exists('registerEditArea')) ? registerEditArea('code_area', 'css') : 'none';
49
// set default text output if varibles are not defined in the global WB language files
50
	if(!isset($TEXT['HEADING_CSS_FILE'])) { $TEXT['HEADING_CSS_FILE'] = 'Actual module file: '; }
51
	if(!isset($TEXT['TXT_EDIT_CSS_FILE'])) { $TEXT['TXT_EDIT_CSS_FILE'] = 'Edit the CSS definitions in the textarea below.'; }
52

  
53
// check if action is: save or edit
54
	if($_action == 'save' && mod_file_exists($mod_dir, $_edit_file)) {
55
	// SAVE THE UPDATED CONTENTS TO THE CSS FILE
56
		$css_content = '';
57
		if (isset($_POST['css_data']) && strlen($_POST['css_data']) > 0) {
58
			$css_content = stripslashes($_POST['css_data']);
59
		}
60
		$bytes = 0;
61
		if ($css_content != '') {
62
		// open the module CSS file for writting
63
			$mod_file = @fopen(WB_PATH .'/modules/' .$mod_dir .'/' .$_edit_file, 'wb');
64
		// write new content to the module CSS file
65
			$bytes = @fwrite($mod_file, $css_content);
66
		// close the file
67
			@fclose($mod_file);
68
		}
69
		// write out status message
70
		if($bytes == 0 ) {
71
			$admin->print_error($TEXT['ERROR'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
72
		} else {
73
			$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
74
		}
75
	} else {
76
	// MODIFY CONTENTS OF THE CSS FILE VIA TEXT AREA
77
	// check if module backend.css file needs to be included into the <body>
78
		if((!method_exists($admin, 'register_backend_modfiles') || !$page_id)
79
				&& file_exists(WB_PATH .'/modules/'.$mod_dir.'/backend.css')) {
80
			echo '<style type="text/css">';
81
			include(WB_PATH .'/modules/' .$mod_dir .'/backend.css');
82
			echo "\n</style>\n";
83
		}
84
	// check which module file to edit (frontend.css, backend.css or '')
85
		$css_file = (in_array($_edit_file, array('frontend.css', 'backend.css'))) ? $_edit_file : '';
86

  
87
	// display output
88
		if($css_file == '')	{
89
		// no valid module file to edit; display error message and backlink to modify.php
90
			echo "<h2>Nothing to edit</h2>";
91
			echo "<p>No valid module file exists for this module.</p>";
92
			$output  = "<a href=\"#\" onclick=\"javascript: window.location = '";
93
			$output .= ADMIN_URL ."/pages/modify.php?page_id=" .$page_id ."'\">back</a>";
94
			echo $output;
95
		} else {
96
		// store content of the module file in variable
97
		$css_content = @file_get_contents(WB_PATH .'/modules/' .$mod_dir .'/' .$css_file);
98
		// write out heading
99
		echo '<h2>' .$TEXT['HEADING_CSS_FILE'] .'"' .$css_file .'"</h2>';
100
		// include button to switch between frontend.css and backend.css (only shown if both files exists)
101
		toggle_css_file($mod_dir, $css_file);
102
		echo '<p>'.$TEXT['TXT_EDIT_CSS_FILE'].'</p>';
103

  
104
		// output content of module file to textareas
105
	  ?><form name="edit_module_file" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post" style="margin: 0;">
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 $css_file; ?>" />
110
	  	<input type="hidden" name="action" value="save" />
111
		<textarea id="code_area" name="css_data" cols="100" rows="25" wrap="VIRTUAL" style="margin:2px;width:100%;">
112
		<?php echo htmlspecialchars($css_content); ?>
113
		</textarea>
114
  			<table cellpadding="0" cellspacing="0" border="0" width="100%">
115
  			<tr>
116
    			<td class="left">
117
 				<input name="save" type="submit" value="<?php echo $TEXT['SAVE'];?>" style="width: 100px; margin-top: 5px;" />
118
    			</td>
119
  				<td class="right">
120
      			<input type="button" value="<?php echo $TEXT['CANCEL']; ?>"
121
						onclick="javascript: window.location = '<?php echo ADMIN_URL;?>/pages/modify.php?page_id=<?php echo $page_id; ?>';"
122
						style="width: 100px; margin-top: 5px;" />
123
  				</td>
124
  			</tr>
125
  			</table>
126
		</form>
127
<?php 
128
	}
129
}
130
// Print admin footer
131
$admin->print_footer();
1
<?php
2
/**
3
 *
4
 * @category        backend
5
 * @package         modules
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18

  
19
// include required libraries
20
// include configuration file
21
	require('../config.php');
22
// include edit area wrapper script
23
	require_once(WB_PATH.'/include/editarea/wb_wrapper_edit_area.php');
24
// include the admin wrapper script
25
	require(WB_PATH.'/modules/admin.php');
26
// include functions to edit the optional module CSS files (frontend.css, backend.css)
27
	require_once(WB_PATH.'/framework/module.functions.php');
28

  
29
	$page_id = (isset($_REQUEST['page_id']) ? intval($_REQUEST['page_id']) : 0  );
30
	$section_id = (isset($_POST['section_id']) ? intval($_POST['section_id']) : 0  );
31
	$_action = (isset($_POST['action']) ? strtolower($_POST['action']) : '');
32
	$_action = ($_action != 'save' ? 'edit' : 'save');
33
	$mod_dir = (isset($_POST['mod_dir']) ? $_POST['mod_dir'] : '');
34
	$_edit_file = (isset($_POST['edit_file']) ? $_POST['edit_file'] : '');
35
//check if given mod_dir + edit_file is valid path/file
36
	$_realpath = realpath(WB_PATH.'/modules/'.$mod_dir.'/'.$_edit_file);
37
	if($_realpath){
38
	// realpath is a valid path, now test if it's inside WB_PATH
39
		$_realpath = str_replace('\\','/', $_realpath);
40
		$_fileValid = (strpos($_realpath, (str_replace('\\','/', WB_PATH))) !== false);
41
	}
42
// check if all needed args are valid 
43
	if(!$page_id || !$section_id || !$_realpath || !$_fileValid) {
44
		die('Invalid arguments passed - script stopped.');
45
	}
46

  
47
	// echo registerEditArea('code_area', 'css');
48
	echo (function_exists('registerEditArea')) ? registerEditArea('code_area', 'css') : 'none';
49
// set default text output if varibles are not defined in the global WB language files
50
	if(!isset($TEXT['HEADING_CSS_FILE'])) { $TEXT['HEADING_CSS_FILE'] = 'Actual module file: '; }
51
	if(!isset($TEXT['TXT_EDIT_CSS_FILE'])) { $TEXT['TXT_EDIT_CSS_FILE'] = 'Edit the CSS definitions in the textarea below.'; }
52

  
53
// check if action is: save or edit
54
	if($_action == 'save') {
55
	// SAVE THE UPDATED CONTENTS TO THE CSS FILE
56
		$css_content = '';
57
		if (isset($_POST['css_data']) && strlen($_POST['css_data']) > 0) {
58
			$css_content = stripslashes($_POST['css_data']);
59
		}
60
		$modFileName = WB_PATH .'/modules/' .$mod_dir .'/' .$_edit_file;
61
		if(($fileHandle = fopen($modFileName, 'wb'))) {
62
			if(fwrite($mod_file, $css_content)) {
63
				close($fileHandle);
64
				$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
65
				exit;
66
			}
67
			close($fileHandle);
68
		}
69
		$admin->print_error($TEXT['ERROR'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
70
		exit;
71
	} else {
72
	// MODIFY CONTENTS OF THE CSS FILE VIA TEXT AREA
73
	// check which module file to edit (frontend.css, backend.css or '')
74
		$css_file = (in_array($_edit_file, array('frontend.css', 'backend.css'))) ? $_edit_file : '';
75

  
76
	// display output
77
		if($css_file == '')	{
78
		// no valid module file to edit; display error message and backlink to modify.php
79
			echo "<h2>Nothing to edit</h2>";
80
			echo "<p>No valid module file exists for this module.</p>";
81
			$output  = "<a href=\"#\" onclick=\"javascript: window.location = '";
82
			$output .= ADMIN_URL ."/pages/modify.php?page_id=" .$page_id ."'\">back</a>";
83
			echo $output;
84
		} else {
85
		// store content of the module file in variable
86
		$css_content = @file_get_contents(WB_PATH .'/modules/' .$mod_dir .'/' .$css_file);
87
		// write out heading
88
		echo '<h2>' .$TEXT['HEADING_CSS_FILE'] .'"' .$css_file .'"</h2>';
89
		// include button to switch between frontend.css and backend.css (only shown if both files exists)
90
		toggle_css_file($mod_dir, $css_file);
91
		echo '<p>'.$TEXT['TXT_EDIT_CSS_FILE'].'</p>';
92

  
93
		// output content of module file to textareas
94
	  ?><form name="edit_module_file" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post" style="margin: 0;">
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 $css_file; ?>" />
99
	  	<input type="hidden" name="action" value="save" />
100
		<textarea id="code_area" name="css_data" cols="100" rows="25" wrap="VIRTUAL" style="margin:2px;width:100%;">
101
		<?php echo htmlspecialchars($css_content); ?>
102
		</textarea>
103
  			<table cellpadding="0" cellspacing="0" border="0" width="100%">
104
  			<tr>
105
    			<td class="left">
106
 				<input name="save" type="submit" value="<?php echo $TEXT['SAVE'];?>" style="width: 100px; margin-top: 5px;" />
107
    			</td>
108
  				<td class="right">
109
      			<input type="button" value="<?php echo $TEXT['CANCEL']; ?>"
110
						onclick="javascript: window.location = '<?php echo ADMIN_URL;?>/pages/modify.php?page_id=<?php echo $page_id; ?>';"
111
						style="width: 100px; margin-top: 5px;" />
112
  				</td>
113
  			</tr>
114
  			</table>
115
		</form>
116
<?php 
117
	}
118
}
119
// Print admin footer
120
$admin->print_footer();

Also available in: Unified diff