| 1 | <?php
 | 
  
    | 2 | /**
 | 
  
    | 3 |  *
 | 
  
    | 4 |  * @category        backend
 | 
  
    | 5 |  * @package         modules
 | 
  
    | 6 |  * @author          WebsiteBaker Project
 | 
  
    | 7 |  * @copyright       2004-2009, Ryan Djurovich
 | 
  
    | 8 |  * @copyright       2009-2010, 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 4.3.4 and higher
 | 
  
    | 13 |  * @version         $Id: edit_module_files.php 1289 2010-02-10 15:13:21Z kweitzel $
 | 
  
    | 14 |  * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/trunk/wb/modules/edit_module_files.php $
 | 
  
    | 15 |  * @lastmodified    $Date: 2010-02-10 16:13:21 +0100 (Wed, 10 Feb 2010) $
 | 
  
    | 16 |  *
 | 
  
    | 17 |  */
 | 
  
    | 18 | 
 | 
  
    | 19 | // prevent this file from being accessed directly
 | 
  
    | 20 | if(!(isset($_POST['page_id']) && isset($_POST['section_id']) && isset($_POST['action'])
 | 
  
    | 21 | 	&& isset($_POST['mod_dir'])  && isset($_POST['edit_file']))) die(header('Location: index.php'));
 | 
  
    | 22 | 
 | 
  
    | 23 | // include configuration file and admin wrapper script
 | 
  
    | 24 | require('../config.php');
 | 
  
    | 25 | 
 | 
  
    | 26 | // include the and admin wrapper script
 | 
  
    | 27 | require(WB_PATH.'/modules/admin.php');
 | 
  
    | 28 | 
 | 
  
    | 29 | // leave if the required module.functions.php file does not exist
 | 
  
    | 30 | if(!file_exists(WB_PATH .'/framework/module.functions.php')) {
 | 
  
    | 31 | 	echo 'The required file: /framework/module.functions.php is missing - script stopped.';
 | 
  
    | 32 | 	die;
 | 
  
    | 33 | }
 | 
  
    | 34 | 
 | 
  
    | 35 | echo (function_exists('registerEditArea')) ? registerEditArea('code_area', 'css', false) : 'none';
 | 
  
    | 36 | 
 | 
  
    | 37 | // set default text output if varibles are not defined in the global WB language files
 | 
  
    | 38 | $HEADING_CSS_FILE = (isset($GLOBALS['TEXT']['HEADING_CSS_FILE'])) ?$GLOBALS['TEXT']['HEADING_CSS_FILE'] :'Actual module file: ';
 | 
  
    | 39 | $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.';
 | 
  
    | 40 | 
 | 
  
    | 41 | // include functions to edit the optional module CSS files (frontend.css, backend.css)
 | 
  
    | 42 | require_once(WB_PATH .'/framework/module.functions.php');
 | 
  
    | 43 | 
 | 
  
    | 44 | // check if the module directory is valid
 | 
  
    | 45 | $mod_dir = check_module_dir($_POST['mod_dir']);
 | 
  
    | 46 | if($mod_dir == '')
 | 
  
    | 47 | {
 | 
  
    | 48 | 	echo 'The specified module directory is invalid - script stopped.';
 | 
  
    | 49 | 	die;
 | 
  
    | 50 | };
 | 
  
    | 51 | 
 | 
  
    | 52 | // check if action is: save or edit
 | 
  
    | 53 | if($_POST['action'] == 'save' && mod_file_exists($mod_dir, $_POST['edit_file'])) {
 | 
  
    | 54 | 	/** 
 | 
  
    | 55 | 		SAVE THE UPDATED CONTENTS TO THE CSS FILE
 | 
  
    | 56 | 	*/
 | 
  
    | 57 | 	$css_content = '';
 | 
  
    | 58 | 	if (isset($_POST['css_data']) && strlen($_POST['css_data']) > 0) {
 | 
  
    | 59 | 		$css_content = stripslashes($_POST['css_data']);
 | 
  
    | 60 | 	}
 | 
  
    | 61 | 
 | 
  
    | 62 | 	$bytes = 0;
 | 
  
    | 63 | 	if ($css_content != '')
 | 
  
    | 64 |     {
 | 
  
    | 65 | 		// open the module CSS file for writting
 | 
  
    | 66 | 		$mod_file = @fopen(WB_PATH .'/modules/' .$mod_dir .'/' .$_POST['edit_file'], 'wb');
 | 
  
    | 67 | 		// write new content to the module CSS file
 | 
  
    | 68 | 		$bytes = @fwrite($mod_file, $css_content);
 | 
  
    | 69 | 		// close the file
 | 
  
    | 70 | 		@fclose($mod_file);
 | 
  
    | 71 | 	}
 | 
  
    | 72 | 
 | 
  
    | 73 | 	// write out status message
 | 
  
    | 74 | 	if($bytes == 0 )
 | 
  
    | 75 |     {
 | 
  
    | 76 | 		$admin->print_error($TEXT['ERROR'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
 | 
  
    | 77 | 	} else {
 | 
  
    | 78 | 		$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
 | 
  
    | 79 | 	}
 | 
  
    | 80 | 
 | 
  
    | 81 | 
 | 
  
    | 82 | } else {
 | 
  
    | 83 | 	/** 
 | 
  
    | 84 | 		MODIFY CONTENTS OF THE CSS FILE VIA TEXT AREA 
 | 
  
    | 85 | 	*/
 | 
  
    | 86 | 	// check if module backend.css file needs to be included into the <body>
 | 
  
    | 87 | 	if((!method_exists($admin, 'register_backend_modfiles') || !isset($_GET['page_id']))
 | 
  
    | 88 | 			&& file_exists(WB_PATH .'/modules/'.$mod_dir.'/backend.css')) {
 | 
  
    | 89 | 		echo '<style type="text/css">';
 | 
  
    | 90 | 		include(WB_PATH .'/modules/' .$mod_dir .'/backend.css');
 | 
  
    | 91 | 		echo "\n</style>\n";
 | 
  
    | 92 | 	}
 | 
  
    | 93 | 
 | 
  
    | 94 | 	// check which module file to edit (frontend.css, backend.css or '')
 | 
  
    | 95 | 	$css_file = (in_array($_POST['edit_file'], array('frontend.css', 'backend.css'))) ? $_POST['edit_file'] : '';
 | 
  
    | 96 | 
 | 
  
    | 97 | 	// display output
 | 
  
    | 98 | 	if($css_file == '')
 | 
  
    | 99 |     {
 | 
  
    | 100 | 		// no valid module file to edit; display error message and backlink to modify.php
 | 
  
    | 101 | 		echo "<h2>Nothing to edit</h2>";
 | 
  
    | 102 | 		echo "<p>No valid module file exists for this module.</p>";
 | 
  
    | 103 | 		$output  = "<a href=\"#\" onclick=\"javascript: window.location = '";
 | 
  
    | 104 | 		$output .= ADMIN_URL ."/pages/modify.php?page_id=" .$page_id ."'\">back</a>";
 | 
  
    | 105 | 		echo $output;
 | 
  
    | 106 | 	
 | 
  
    | 107 | 	} else {
 | 
  
    | 108 | 		// store content of the module file in variable
 | 
  
    | 109 | 		$css_content = @file_get_contents(WB_PATH .'/modules/' .$mod_dir .'/' .$css_file);
 | 
  
    | 110 | 		// write out heading
 | 
  
    | 111 | 		echo '<h2>' .$HEADING_CSS_FILE .'"' .$css_file .'"</h2>';
 | 
  
    | 112 | 		// include button to switch between frontend.css and backend.css (only shown if both files exists)
 | 
  
    | 113 | 		toggle_css_file($mod_dir, $css_file); 
 | 
  
    | 114 | 		echo '<p>' .$TXT_EDIT_CSS_FILE .'</p>';
 | 
  
    | 115 | 
 | 
  
    | 116 | 		// output content of module file to textareas
 | 
  
    | 117 | 	?>
 | 
  
    | 118 | 		<form name="edit_module_file" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" style="margin: 0;">
 | 
  
    | 119 | 	  	<input type="hidden" name="page_id" value="<?php echo $page_id; ?>" />
 | 
  
    | 120 | 	  	<input type="hidden" name="section_id" value="<?php echo $section_id; ?>" />
 | 
  
    | 121 | 	  	<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>" />
 | 
  
    | 122 | 		<input type="hidden" name="edit_file" value="<?php echo $css_file; ?>" />
 | 
  
    | 123 | 	  	<input type="hidden" name="action" value="save" />
 | 
  
    | 124 | 		<textarea id="code_area" name="css_data" cols="115" rows="25" wrap="VIRTUAL" style="margin:2px;width:100%;"><?php
 | 
  
    | 125 | 			echo htmlspecialchars($css_content); ?>
 | 
  
    | 126 | 		</textarea>
 | 
  
    | 127 | <?php
 | 
  
    | 128 | 
 | 
  
    | 129 | ?>
 | 
  
    | 130 |   			<table cellpadding="0" cellspacing="0" border="0" width="100%">
 | 
  
    | 131 |   			<tr>
 | 
  
    | 132 |     			<td class="left">
 | 
  
    | 133 |  				<input name="save" type="submit" value="<?php echo $TEXT['SAVE'];?>" style="width: 100px; margin-top: 5px;" />
 | 
  
    | 134 |     			</td>
 | 
  
    | 135 |   				<td class="right">
 | 
  
    | 136 |       			<input type="button" value="<?php echo $TEXT['CANCEL']; ?>"
 | 
  
    | 137 | 						onclick="javascript: window.location = '<?php echo ADMIN_URL;?>/pages/modify.php?page_id=<?php echo $page_id; ?>';"
 | 
  
    | 138 | 						style="width: 100px; margin-top: 5px;" />
 | 
  
    | 139 |   				</td>
 | 
  
    | 140 |   			</tr>
 | 
  
    | 141 |   			</table>
 | 
  
    | 142 | 		</form>
 | 
  
    | 143 | 		<?php 
 | 
  
    | 144 | 	}
 | 
  
    | 145 | }
 | 
  
    | 146 | 
 | 
  
    | 147 | // Print admin footer
 | 
  
    | 148 | $admin->print_footer();
 | 
  
    | 149 | 
 | 
  
    | 150 | ?>
 |