1<?php 2/** 3 * @package tikiwiki 4 */ 5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 6// 7// All Rights Reserved. See copyright.txt for details and a complete list of authors. 8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 9// $Id$ 10 11$inputConfiguration = [ 12 [ 'staticKeyFilters' => [ 13 'data' => 'none', 14 ]], 15]; 16 17include_once("tiki-setup.php"); 18$csslib = TikiLib::lib('css'); 19$themelib = TikiLib::lib('theme'); 20$access->check_feature('feature_editcss'); 21$access->check_permission('tiki_p_create_css'); 22 23//selecting the theme 24if (! empty($_SESSION['try_theme']) && ! isset($_REQUEST['theme'])) { 25 $theme = $_SESSION['try_theme']; 26} elseif (! isset($_REQUEST['theme'])) { 27 $theme = ''; 28} else { 29 $theme = $_REQUEST['theme']; 30} 31$themeOptionName = $themelib->extract_theme_and_option($theme); 32$theme_name = $themeOptionName[0]; 33$theme_option_name = $themeOptionName[1]; 34$file = $themelib->get_theme_css($theme_name, $theme_option_name); 35$smarty->assign('file', $file); 36 37if (! empty($_REQUEST['edit'])) { 38 check_ticket('edit-css'); 39 if (($data = file_get_contents($file)) === false) { 40 $smarty->assign('msg', tra('The specified file does not exist')); 41 $smarty->display('error.tpl'); 42 die; 43 } 44 $action = 'edit'; 45} elseif (! empty($_REQUEST['save']) || ! empty($_REQUEST['save_and_view'])) { 46 check_ticket('edit-css'); 47 if (file_exists($file)) { 48 $stat = stat($file); 49 $mod = $stat['mode'] & 0666; 50 } else { 51 $mod = null; 52 } 53 $fp = fopen($file, "w"); 54 if (! $fp) { 55 $smarty->assign('msg', tra("You do not have permission to write the css file") . " $file"); 56 $smarty->display("error.tpl"); 57 die; 58 } 59 60 fwrite($fp, $_REQUEST['data']); 61 fclose($fp); 62 if ($mod !== null) { 63 chmod($file, $mod); 64 } 65 66 if (! empty($_REQUEST['save_and_view'])) { 67 $action = 'view'; 68 header("location: tiki-edit_css.php?theme=$theme"); 69 } else { 70 $action = 'edit'; 71 header("location: tiki-edit_css.php?theme=$theme&edit=" . tra('Edit') . ""); 72 } 73 $data = ''; 74} else { 75 $action = 'view'; 76 $data = ''; 77} 78 79$smarty->assign('action', $action); 80$smarty->assign('data', $data); 81 82if (! empty($theme)) { 83 $cssfile = $themelib->get_theme_css($theme_name, $theme_option_name); 84 $smarty->assign('writable', file_exists($cssfile) ? is_writable($cssfile) : is_writable(dirname($cssfile))); 85 $cssdata = $csslib->browse_css($cssfile); 86 if ((! $cssdata["error"]) and is_array($cssdata["content"])) { 87 $parsedcss = $csslib->parse_css($cssdata["content"]); 88 } else { 89 $parsedcss = $cssdata["error"]; 90 } 91 $smarty->assign('css', $parsedcss); 92} 93 94if (! empty($_REQUEST['try'])) { 95 $_SESSION['try_theme'] = $theme; 96 header("location: tiki-edit_css.php?theme=$theme"); 97} 98 99if (! empty($_SESSION['try_theme'])) { 100 $try_active = true; 101 $smarty->assign('try_active', $try_active); 102 list($try_theme, $try_theme_option) = $themelib->extract_theme_and_option($_SESSION['try_theme']); 103 $smarty->assign('try_theme', $try_theme); 104 $smarty->assign('try_theme_option', $try_theme_option); 105} 106 107if (! empty($_REQUEST['cancel_try'])) { 108 $_SESSION['try_theme'] = ''; 109 header("location: tiki-edit_css.php?theme=$theme"); 110} 111$smarty->assign('theme', $theme); 112$themes = $themelib->list_themes_and_options(); 113$smarty->assign('themes', $themes); 114 115ask_ticket('edit-css'); 116 117// disallow robots to index page: 118$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW'); 119 120$smarty->assign('mid', 'tiki-edit_css.tpl'); 121$smarty->display("tiki.tpl"); 122