1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
|
<?php // $Id: editor.php,v 1.14 2006/03/27 14:09:03 moodler Exp $
/// configuration routines for HTMLArea editor
require_once('../config.php');
$currentpage = optional_param('tab', 1, PARAM_INT);
require_login();
if (!isadmin()) {
error("Only admins can access this page");
}
if (($data = data_submitted()) && confirm_sesskey()) {
// do we want default values?
if (isset($data->resettodefaults)) {
if (!(reset_to_defaults($currentpage))) {
error("Editor settings could not be restored!");
}
} else {
if (!(editor_update_config($data, $currentpage))) {
error("Editor settings could not be updated!");
}
}
redirect("$CFG->wwwroot/$CFG->admin/editor.php?tab=$currentpage", get_string("changessaved"), 1);
} else {
// Generate edit form
$inactive = array();
switch ( $currentpage ) {
case 1:
$currenttab = 'htmlarea';
break;
case 2:
$currenttab = 'tinymce';
break;
default:
error("Unknown currentpage: $currentpage");
}
//$url = 'editor.php?tab=';
//$tabrow = array();
//$tabrow[] = new tabobject('htmlarea',$url . '1', 'HTMLArea');
//$tabrow[] = new tabobject('tinymce',$url . '2', 'TinyMCE');
//$tabs = array($tabrow);
$fontlist = editor_convert_to_array($CFG->editorfontlist);
$dicts = editor_get_dictionaries();
$stradmin = get_string("administration");
$strconfiguration = get_string("configuration");
$streditorsettings = get_string("editorsettings");
$streditorsettingshelp = get_string("adminhelpeditorsettings");
print_header("Editor settings","Editor settings",
"<a href=\"index.php\">$stradmin</a> -> ".
"<a href=\"configure.php\">$strconfiguration</a> -> $streditorsettings");
print_heading($streditorsettings);
print_simple_box("<center>$streditorsettingshelp</center>","center","50%");
print("<br />\n");
//print_tabs($tabs, $currenttab, $inactive);
print_simple_box_start("center");
include("editor.html");
print_simple_box_end();
print_footer();
}
/// FUNCTIONS
function editor_convert_to_array ($string) {
/// Converts $CFG->editorfontlist to array
if (empty($string) || !is_string($string)) {
return false;
}
$fonts = array();
$lines = explode(";", $string);
foreach ($lines as $line) {
if (!empty($line)) {
list($fontkey, $fontvalue) = explode(":", $line);
$fonts[$fontkey] = $fontvalue;
}
}
return $fonts;
}
function editor_update_config ($data, $editor) {
/// Updates the editor config values.
if (!is_object($data)) {
return false;
}
switch($editor) {
case 1: // HTMLArea.
// Make array for unwanted characters.
$nochars = array(chr(33),chr(34),chr(35),chr(36),chr(37),
chr(38),chr(39),chr(40),chr(41),chr(42),
chr(43),chr(46),chr(47),chr(58),chr(59),
chr(60),chr(61),chr(62),chr(63),chr(64),
chr(91),chr(92),chr(93),chr(94),chr(95),
chr(96),chr(123),chr(124),chr(125),chr(126));
$fontlist = '';
// make font string
$cnt = count($data->fontname);
for ($i = 0; $i < $cnt; $i++) {
if (!empty($data->fontname[$i])) {
$fontlist .= str_replace($nochars, "", $data->fontname[$i]) .":";
$fontlist .= str_replace($nochars, "", $data->fontnamevalue[$i]) .";";
}
}
// strip last semicolon
$fontlist = substr($fontlist, 0, strlen($fontlist) - 1);
// make array of values to update
$updatedata = array();
$updatedata['htmleditor'] = !empty($data->htmleditor) ? $data->htmleditor : 0;
$updatedata['editorbackgroundcolor'] = !empty($data->backgroundcolor) ? $data->backgroundcolor : "#ffffff";
$updatedata['editorfontfamily'] = !empty($data->fontfamily) ? str_replace($nochars,"",$data->fontfamily) : "Times New Roman, Times";
$updatedata['editorfontsize'] = !empty($data->fontsize) ? $data->fontsize : "";
$updatedata['editorkillword'] = !empty($data->killword) ? $data->killword : 0;
$updatedata['editorspelling'] = !empty($data->spelling) ? $data->spelling : 0;
$updatedata['editorfontlist'] = $fontlist;
$updatedata['editordictionary'] = !empty($data->dictionary) ? $data->dictionary : '';
$updatedata['aspellpath'] = !empty($data->aspellpath) ? $data->aspellpath : '';
$hidebuttons = '';
if (!empty($data->buttons) && is_array($data->buttons)) {
foreach ($data->buttons as $key => $value) {
$hidebuttons .= $key . " ";
}
}
$updatedata['editorhidebuttons'] = trim($hidebuttons);
break;
case 2: // TinyMCE.
$updatedata = array();
$updatedata['htmleditor'] = !empty($data->htmleditor) ? $data->htmleditor : 0;
// Process plugins
if ( !empty($data->tinymceplugins) ) {
foreach ( $data->tinymceplugins as $key => $value ) {
$value = stripslashes(clean_param($value, PARAM_ALPHA));
$data->tinymceplugins[$key] = addslashes($value);
}
}
$updatedata['tinymceplugins'] = !empty($data->tinymceplugins) ? implode(",", $data->tinymceplugins) : '';
$updatedata['tinymcetheme'] = !empty($data->tinymcetheme) ?
clean_param($data->tinymcetheme, PARAM_ALPHA) : '';
$updatedata['tinymcecontentcss'] = !empty($data->tinymcecontentcss) ?
clean_param($data->tinymcecontentcss, PARAM_URL) : '';
$updatedata['tinymcepopupcss'] = !empty($data->tinymcepopupcss) ?
clean_param($data->tinymcepopupcss, PARAM_URL) : '';
$updatedata['tinymceeditorcss'] = !empty($data->tinymceeditorcss) ?
clean_param($data->tinymceeditorcss, PARAM_URL) : '';
break;
}
foreach ($updatedata as $name => $value) {
if (!(set_config($name, $value))) {
return false;
}
}
return true;
}
function reset_to_defaults ($editor) {
/// Reset the values to default
global $CFG;
include_once($CFG->dirroot .'/lib/defaults.php');
$updatedata = array();
switch ( $editor ) {
case 1: // HTMLArea.
$updatedata['editorbackgroundcolor'] = $defaults['editorbackgroundcolor'];
$updatedata['editorfontfamily'] = $defaults['editorfontfamily'];
$updatedata['editorfontsize'] = $defaults['editorfontsize'];
$updatedata['editorkillword'] = $defaults['editorkillword'];
$updatedata['editorspelling'] = $defaults['editorspelling'];
$updatedata['editorfontlist'] = $defaults['editorfontlist'];
$updatedata['editorhidebuttons'] = $defaults['editorhidebuttons'];
$updatedata['editordictionary'] = '';
break;
case 2: // TinyMCE.
$updatedata['tinymceplugins'] = $defaults['tinymceplugins'];
$updatedata['tinymcetheme'] = $defaults['tinymcetheme'];
$updatedata['tinymcecontentcss'] = $defaults['tinymcecontentcss'];
$updatedata['tinymcepopupcss'] = $defaults['tinymcepopupcss'];
$updatedata['tinymceeditorcss'] = $defaults['tinymceeditorcss'];
break;
}
foreach ($updatedata as $name => $value) {
if (!(set_config($name, $value))) {
return false;
}
}
return true;
}
function editor_get_dictionaries () {
/// Get all installed dictionaries in the system
global $CFG;
error_reporting(E_ALL); // for debug, final version shouldn't have this...
clearstatcache();
$strerror = '';
// If aspellpath isn't set don't even bother ;-)
if (empty($CFG->aspellpath)) {
return $strerror = 'Empty aspell path!';
}
// Do we have access to popen function?
if (!function_exists('popen')) {
return $strerror = "Popen function disabled!";
exit;
}
global $CFG;
$cmd = $CFG->aspellpath;
$output = '';
$dictionaries = array();
$dicts = array();
if(!($handle = @popen(escapeshellarg($cmd) .' dump dicts', 'r'))) {
return $strerror = "Couldn't create handle!";
exit;
}
while(!feof($handle)) {
$output .= fread($handle, 1024);
}
@pclose($handle);
$dictionaries = explode(chr(10), $output);
// Get rid of possible empty values
if (is_array($dictionaries)) {
$cnt = count($dictionaries);
for ($i = 0; $i < $cnt; $i++) {
if (!empty($dictionaries[$i])) {
$dicts[] = $dictionaries[$i];
}
}
}
if (count($dicts) >= 1) {
return $dicts;
}
$strerror = "Error! Check your aspell installation!";
return $strerror;
}
function editor_get_tiny_plugins() {
global $CFG;
$plugins = array();
$plugindir = $CFG->libdir .'/editor/tinymce/jscripts/tiny_mce/plugins';
if ( !$fp = opendir($plugindir) ) {
return $plugins;
exit;
}
while ( ($file = readdir($fp)) !== false ) {
if ( preg_match("/^\.+/", $file) ) {
continue;
}
if ( is_dir($plugindir .'/'. $file) ) {
array_push($plugins, $file);
}
}
if ( $fp ) {
closedir($fp);
}
return $plugins;
}
?>
|