Revision 1457
Added by Dietmar almost 13 years ago
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') { |
|
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(); |
|
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 functions to edit the optional module CSS files (frontend.css, backend.css) |
|
25 |
require_once(WB_PATH.'/framework/module.functions.php'); |
|
26 |
// $admin_header = false; |
|
27 |
// Tells script to update when this page was last updated |
|
28 |
$update_when_modified = false; |
|
29 |
// show the info banner |
|
30 |
$print_info_banner = true; |
|
31 |
// Include WB admin wrapper script |
|
32 |
require(WB_PATH.'/modules/admin.php'); |
|
33 |
/* |
|
34 |
$page_id = (isset($_REQUEST['page_id']) ? intval($_REQUEST['page_id']) : 0 ); |
|
35 |
$section_id = (isset($_POST['section_id']) ? intval($_POST['section_id']) : 0 ); |
|
36 |
*/ |
|
37 |
$_action = (isset($_POST['action']) ? strtolower($_POST['action']) : ''); |
|
38 |
$_action = ($_action != 'save' ? 'edit' : 'save'); |
|
39 |
$mod_dir = (isset($_POST['mod_dir']) ? $_POST['mod_dir'] : ''); |
|
40 |
$_edit_file = (isset($_POST['edit_file']) ? $_POST['edit_file'] : ''); |
|
41 |
//check if given mod_dir + edit_file is valid path/file |
|
42 |
$_realpath = realpath(WB_PATH.'/modules/'.$mod_dir.'/'.$_edit_file); |
|
43 |
if($_realpath){ |
|
44 |
// realpath is a valid path, now test if it's inside WB_PATH |
|
45 |
$_realpath = str_replace('\\','/', $_realpath); |
|
46 |
$_fileValid = (strpos($_realpath, (str_replace('\\','/', WB_PATH))) !== false); |
|
47 |
} |
|
48 |
// check if all needed args are valid |
|
49 |
if(!$page_id || !$section_id || !$_realpath || !$_fileValid) { |
|
50 |
die('Invalid arguments passed - script stopped.'); |
|
51 |
} |
|
52 |
|
|
53 |
// echo registerEditArea('code_area', 'css'); |
|
54 |
echo (function_exists('registerEditArea')) ? registerEditArea('code_area', 'css') : 'none'; |
|
55 |
// set default text output if varibles are not defined in the global WB language files |
|
56 |
if(!isset($TEXT['HEADING_CSS_FILE'])) { $TEXT['HEADING_CSS_FILE'] = 'Actual module file: '; } |
|
57 |
if(!isset($TEXT['TXT_EDIT_CSS_FILE'])) { $TEXT['TXT_EDIT_CSS_FILE'] = 'Edit the CSS definitions in the textarea below.'; } |
|
58 |
|
|
59 |
// check if action is: save or edit |
|
60 |
if($_action == 'save') { |
|
61 |
// SAVE THE UPDATED CONTENTS TO THE CSS FILE |
|
62 |
$css_content = ''; |
|
63 |
if (isset($_POST['css_data']) && strlen($_POST['css_data']) > 0) { |
|
64 |
$css_content = stripslashes($_POST['css_data']); |
|
65 |
} |
|
66 |
$modFileName = WB_PATH .'/modules/' .$mod_dir .'/' .$_edit_file; |
|
67 |
if(($fileHandle = fopen($modFileName, 'wb'))) { |
|
68 |
if(fwrite($fileHandle, $css_content)) { |
|
69 |
fclose($fileHandle); |
|
70 |
$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id); |
|
71 |
exit; |
|
72 |
} |
|
73 |
fclose($fileHandle); |
|
74 |
} |
|
75 |
$admin->print_error($TEXT['ERROR'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id); |
|
76 |
exit; |
|
77 |
} else { |
|
78 |
// MODIFY CONTENTS OF THE CSS FILE VIA TEXT AREA |
|
79 |
// check which module file to edit (frontend.css, backend.css or '') |
|
80 |
$css_file = (in_array($_edit_file, array('frontend.css', 'backend.css'))) ? $_edit_file : ''; |
|
81 |
|
|
82 |
// display output |
|
83 |
if($css_file == '') { |
|
84 |
// no valid module file to edit; display error message and backlink to modify.php |
|
85 |
echo "<h2>Nothing to edit</h2>"; |
|
86 |
echo "<p>No valid module file exists for this module.</p>"; |
|
87 |
$output = "<a href=\"#\" onclick=\"javascript: window.location = '"; |
|
88 |
$output .= ADMIN_URL ."/pages/modify.php?page_id=" .$page_id ."'\">back</a>"; |
|
89 |
echo $output; |
|
90 |
} else { |
|
91 |
// store content of the module file in variable |
|
92 |
$css_content = @file_get_contents(WB_PATH .'/modules/' .$mod_dir .'/' .$css_file); |
|
93 |
// write out heading |
|
94 |
echo '<h2>' .$TEXT['HEADING_CSS_FILE'] .'"' .$css_file .'"</h2>'; |
|
95 |
// include button to switch between frontend.css and backend.css (only shown if both files exists) |
|
96 |
toggle_css_file($mod_dir, $css_file); |
|
97 |
echo '<p>'.$TEXT['TXT_EDIT_CSS_FILE'].'</p>'; |
|
98 |
|
|
99 |
// output content of module file to textareas |
|
100 |
?><form name="edit_module_file" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post" style="margin: 0;"> |
|
101 |
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>" /> |
|
102 |
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>" /> |
|
103 |
<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>" /> |
|
104 |
<input type="hidden" name="edit_file" value="<?php echo $css_file; ?>" /> |
|
105 |
<input type="hidden" name="action" value="save" /> |
|
106 |
<textarea id="code_area" name="css_data" cols="100" rows="25" wrap="VIRTUAL" style="margin:2px;width:100%;"> |
|
107 |
<?php echo htmlspecialchars($css_content); ?> |
|
108 |
</textarea> |
|
109 |
<table cellpadding="0" cellspacing="0" border="0" width="100%"> |
|
110 |
<tr> |
|
111 |
<td class="left"> |
|
112 |
<input name="save" type="submit" value="<?php echo $TEXT['SAVE'];?>" style="width: 100px; margin-top: 5px;" /> |
|
113 |
</td> |
|
114 |
<td class="right"> |
|
115 |
<input type="button" value="<?php echo $TEXT['CANCEL']; ?>" |
|
116 |
onclick="javascript: window.location = '<?php echo ADMIN_URL;?>/pages/modify.php?page_id=<?php echo $page_id; ?>';" |
|
117 |
style="width: 100px; margin-top: 5px;" /> |
|
118 |
</td> |
|
119 |
</tr> |
|
120 |
</table> |
|
121 |
</form> |
|
122 |
<?php |
|
123 |
} |
|
124 |
} |
|
125 |
// Print admin footer |
|
126 |
$admin->print_footer(); |
Also available in: Unified diff
Preparing 2.8.2 stable, last tests