Project

General

Profile

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: edit_module_files.php 1455 2011-06-06 14:43:14Z DarkViper $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/edit_module_files.php $
15
 * @lastmodified    $Date: 2011-06-06 16:43:14 +0200 (Mon, 06 Jun 2011) $
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($fileHandle, $css_content)) {
63
				fclose($fileHandle);
64
				$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
65
				exit;
66
			}
67
			fclose($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();
(2-2/3)