MDL-22015 fixed more string_manager encapsulation issues - string format conversion...
[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
15a17d35 35if (!get_string_manager()->translation_exists($lang, false)) {
3a915b06 36 $lang = 'en';
5ca3c838 37}
38
3518913c 39$string = get_string_manager()->load_component_strings('editor_tinymce', $lang);
5ca3c838 40
41//process the $strings to match expected tinymce lang array stucture
f3920b67 42$result = array();
5ca3c838 43
44foreach ($string as $key=>$value) {
f3920b67 45 $parts = explode(':', $key);
46 if (count($parts) != 2) {
5ca3c838 47 // incorrect string - ignore
48 continue;
49 }
6eca5390 50 $value = str_replace("%%","%",$value); // Unescape % characters
51
f3920b67 52 $result[$parts[0]][$parts[1]] = $value;
5ca3c838 53}
54
5f81eeea 55$output = 'tinyMCE.addI18n({'.$lang.':'.json_encode($result).'});';
5ca3c838 56
57$lifetime = '10'; // TODO: increase later
58@header('Content-type: text/javascript; charset=utf-8');
59@header('Content-length: '.strlen($output));
60@header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
61@header('Cache-control: max-age='.$lifetime);
62@header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .'GMT');
63@header('Pragma: ');
64
65echo $output;