MDL-21694 simplified tinymce string handling
[moodle.git] / lib / editor / tinymce / extra / strings.php
CommitLineData
5ca3c838 1<?php
2
8fd57583 3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * On-the-fly conversion of Moodle lang strings to TinyMCE expected JS format.
20 *
21 * @package moodlecore
22 * @subpackage editor
23 * @copyright 2009 Petr Skoda (http://skodak.org)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
5ca3c838 26
27define('NO_MOODLE_COOKIES', true);
28define('NO_UPGRADE_CHECK', true);
29
30require_once('../../../../config.php');
31
58aa4c08 32$lang = optional_param('elanguage', 'en', PARAM_SAFEDIR);
33$theme = optional_param('etheme', 'advanced', PARAM_SAFEDIR);
5ca3c838 34
1453bf77 35if ($lang === 'en') {
5ca3c838 36 //ok
1453bf77 37} else if (file_exists($CFG->langotherroot .'/'. $lang)) {
3a915b06 38 //$lang = $lang;
5ca3c838 39} else {
3a915b06 40 $lang = 'en';
5ca3c838 41}
42
3518913c 43$string = get_string_manager()->load_component_strings('editor_tinymce', $lang);
5ca3c838 44
45//process the $strings to match expected tinymce lang array stucture
f3920b67 46$result = array();
5ca3c838 47
48foreach ($string as $key=>$value) {
f3920b67 49 $parts = explode(':', $key);
50 if (count($parts) != 2) {
5ca3c838 51 // incorrect string - ignore
52 continue;
53 }
6eca5390 54 $value = str_replace("%%","%",$value); // Unescape % characters
55
f3920b67 56 $result[$parts[0]][$parts[1]] = $value;
5ca3c838 57}
58
5f81eeea 59$output = 'tinyMCE.addI18n({'.$lang.':'.json_encode($result).'});';
5ca3c838 60
61$lifetime = '10'; // TODO: increase later
62@header('Content-type: text/javascript; charset=utf-8');
63@header('Content-length: '.strlen($output));
64@header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
65@header('Cache-control: max-age='.$lifetime);
66@header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .'GMT');
67@header('Pragma: ');
68
69echo $output;