| 1 | 560 | Ruebenwurz | <?php
 | 
      
        | 2 |  |  | 
 | 
      
        | 3 |  |  | // $Id$
 | 
      
        | 4 |  |  | 
 | 
      
        | 5 |  |  | ######################################################################################################################
 | 
      
        | 6 |  |  | #
 | 
      
        | 7 |  |  | #	PURPOSE OF THIS FILE:
 | 
      
        | 8 |  |  | #	This file contains functions to edit the module CSS files (frontend.css and backend.css)
 | 
      
        | 9 |  |  | #
 | 
      
        | 10 |  |  | #	INVOKED BY:
 | 
      
        | 11 |  |  | # 	This file is invoked when a user clicks on the edit CSS button in the modify.php file
 | 
      
        | 12 |  |  | #
 | 
      
        | 13 |  |  | ######################################################################################################################
 | 
      
        | 14 |  |  | 
 | 
      
        | 15 |  |  | /**
 | 
      
        | 16 |  |  |   Module developed for the Open Source Content Management System Website Baker (http://websitebaker.org)
 | 
      
        | 17 |  |  |   Copyright (C) year, Authors name
 | 
      
        | 18 |  |  |   Contact me: author(at)domain.xxx, http://authorwebsite.xxx
 | 
      
        | 19 |  |  | 
 | 
      
        | 20 |  |  |   This module is free software. You can redistribute it and/or modify it
 | 
      
        | 21 |  |  |   under the terms of the GNU General Public License  - version 2 or later,
 | 
      
        | 22 |  |  |   as published by the Free Software Foundation: http://www.gnu.org/licenses/gpl.html.
 | 
      
        | 23 |  |  | 
 | 
      
        | 24 |  |  |   This module is distributed in the hope that it will be useful,
 | 
      
        | 25 |  |  |   but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
      
        | 26 |  |  |   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
      
        | 27 |  |  |   GNU General Public License for more details.
 | 
      
        | 28 |  |  | **/
 | 
      
        | 29 |  |  | 
 | 
      
        | 30 |  |  | // prevent this file from being accesses directly
 | 
      
        | 31 |  |  | if(defined('WB_PATH') == false) {
 | 
      
        | 32 |  |  | 	exit("Cannot access this file directly");
 | 
      
        | 33 |  |  | }
 | 
      
        | 34 |  |  | 
 | 
      
        | 35 |  |  | /**
 | 
      
        | 36 |  |  | DEFINE LANGUAGE DEPENDING OUTPUTS FOR THE EDIT CSS PART
 | 
      
        | 37 |  |  | */
 | 
      
        | 38 |  |  | $lang_dir = WB_PATH .'/modules/' .basename(dirname(__FILE__)) .'/languages/';
 | 
      
        | 39 |  |  | if(file_exists($lang_dir .LANGUAGE .'.php')) {
 | 
      
        | 40 |  |  | 	// try to include custom language file if exists
 | 
      
        | 41 |  |  | 	require_once($lang_dir .LANGUAGE .'.php');
 | 
      
        | 42 |  |  | } elseif(file_exists($lang_dir .'EN.php')) {
 | 
      
        | 43 |  |  | 	// try to include default module language file
 | 
      
        | 44 |  |  | 	require_once($lang_dir .'EN.php');
 | 
      
        | 45 |  |  | }
 | 
      
        | 46 |  |  | 
 | 
      
        | 47 |  |  | // set defaults if output varibles are not set in the languages files
 | 
      
        | 48 |  |  | if(!isset($CAP_EDIT_CSS)) $CAP_EDIT_CSS	= 'Edit CSS';
 | 
      
        | 49 |  |  | if(!isset($CAP_TOGGLE_CSS)) $CAP_TOGGLE_CSS	= 'Switch to ';
 | 
      
        | 50 |  |  | if(!isset($HEADING_CSS_FILE))	$HEADING_CSS_FILE = 'Actual module file: ';
 | 
      
        | 51 |  |  | if(!isset($TXT_EDIT_CSS_FILE)) $TXT_EDIT_CSS_FILE = 'Edit the CSS definitions in the textarea below.';
 | 
      
        | 52 |  |  | 
 | 
      
        | 53 |  |  | // this function checks if the specified optional module file exists
 | 
      
        | 54 |  |  | if (!function_exists('mod_file_exists')) {
 | 
      
        | 55 |  |  | 	function mod_file_exists($mod_file='frontend.css') {
 | 
      
        | 56 |  |  | 		// extract the module directory
 | 
      
        | 57 |  |  | 		$mod_dir = basename(dirname(__FILE__)) .'/' .$mod_file;
 | 
      
        | 58 |  |  | 		return file_exists(WB_PATH .'/modules/' .$mod_dir);
 | 
      
        | 59 |  |  | 	}
 | 
      
        | 60 |  |  | }
 | 
      
        | 61 |  |  | 
 | 
      
        | 62 |  |  | // this function displays a "Edit CSS" button in modify.php
 | 
      
        | 63 |  |  | // if the optional module files (module.css, module.js) if exists
 | 
      
        | 64 |  |  | if (!function_exists('css_edit')) {
 | 
      
        | 65 |  |  | 	function css_edit() {
 | 
      
        | 66 |  |  | 		global $page_id, $section_id, $CAP_EDIT_CSS;
 | 
      
        | 67 |  |  | 		// extract the module directory
 | 
      
        | 68 |  |  | 		$mod_dir = basename(dirname(__FILE__));
 | 
      
        | 69 |  |  | 		$frontend_css = mod_file_exists('frontend.css');
 | 
      
        | 70 |  |  | 		$backend_css = mod_file_exists('backend.css');
 | 
      
        | 71 |  |  | 		if($frontend_css || $backend_css) {
 | 
      
        | 72 |  |  | 			// display link to edit the optional CSS module files
 | 
      
        | 73 |  |  | 			$file = $frontend_css ? 'frontend.css' : 'backend.css';
 | 
      
        | 74 |  |  | 			$output  = '<div class="mod_' .$mod_dir .'_edit_css"><a href="' .WB_URL .'/modules/' .$mod_dir .'/edit_css.php';
 | 
      
        | 75 |  |  | 			$output .= '?page_id=' .$page_id .'§ion_id=' .$section_id .'&edit_file=' .$file .'">';
 | 
      
        | 76 |  |  | 			$output .= $CAP_EDIT_CSS .'</a></div>';
 | 
      
        | 77 |  |  | 			echo $output;
 | 
      
        | 78 |  |  | 		}
 | 
      
        | 79 |  |  | 	}
 | 
      
        | 80 |  |  | }
 | 
      
        | 81 |  |  | 
 | 
      
        | 82 |  |  | // this function returns a secure module file from $_GET['edit_file']
 | 
      
        | 83 |  |  | if (!function_exists('edit_mod_file')) {
 | 
      
        | 84 |  |  | 	function edit_mod_file() {
 | 
      
        | 85 |  |  | 		$allowed_files = array('frontend.css', 'backend.css');
 | 
      
        | 86 |  |  | 		if(isset($_GET['edit_file']) && in_array($_GET['edit_file'], $allowed_files)) {
 | 
      
        | 87 |  |  | 			return $_GET['edit_file'];
 | 
      
        | 88 |  |  | 		} elseif(mod_file_exists('frontend.css')) {
 | 
      
        | 89 |  |  | 			return 'frontend.css';
 | 
      
        | 90 |  |  | 		} elseif(mod_file_exists('backend_css')) {
 | 
      
        | 91 |  |  | 			return 'backend.css';
 | 
      
        | 92 |  |  | 		} else {
 | 
      
        | 93 |  |  | 			return '';
 | 
      
        | 94 |  |  | 		}
 | 
      
        | 95 |  |  | 	}
 | 
      
        | 96 |  |  | }
 | 
      
        | 97 |  |  | 
 | 
      
        | 98 |  |  | // this function displays a button to toggle between the optional module CSS files
 | 
      
        | 99 |  |  | // function is invoked from edit_css.php file
 | 
      
        | 100 |  |  | if (!function_exists('toggle_css_file')) {
 | 
      
        | 101 |  |  | 	function toggle_css_file($base_css_file = 'frontend.css') {
 | 
      
        | 102 |  |  | 		$allowed_mod_files = array('frontend.css', 'backend.css');
 | 
      
        | 103 |  |  | 		if(!in_array($base_css_file, $allowed_mod_files)) return;
 | 
      
        | 104 |  |  | 		global $page_id, $section_id, $CAP_TOGGLE_CSS;
 | 
      
        | 105 |  |  | 		// extract the module directory
 | 
      
        | 106 |  |  | 		$mod_dir = basename(dirname(__FILE__));
 | 
      
        | 107 |  |  | 		$toggle_file = ($base_css_file == 'frontend.css') ? 'backend.css' : 'frontend.css';
 | 
      
        | 108 |  |  | 		if(mod_file_exists($toggle_file)) {
 | 
      
        | 109 |  |  | 			// display button to toggle between the two CSS files: frontend.css, backend.css
 | 
      
        | 110 |  |  | 			$output  = '<div class="mod_' .$mod_dir .'_edit_css"><a href="' .WB_URL .'/modules/' .$mod_dir .'/edit_css.php';
 | 
      
        | 111 |  |  | 			$output .= '?page_id=' .$page_id .'§ion_id=' .$section_id .'&edit_file=' .$toggle_file .'">';
 | 
      
        | 112 |  |  | 			$output .= $CAP_TOGGLE_CSS .$toggle_file .'</a></div>';
 | 
      
        | 113 |  |  | 			echo $output;
 | 
      
        | 114 |  |  | 		}
 | 
      
        | 115 |  |  | 	}
 | 
      
        | 116 |  |  | }
 | 
      
        | 117 |  |  | 
 | 
      
        | 118 |  |  | ?>
 |