diff --git a/lib/editor/tinymce/plugins/moodlemedia/lang/en/tinymce_moodlemedia.php b/lib/editor/tinymce/plugins/moodlemedia/lang/en/tinymce_moodlemedia.php index 541f1bc832813..256432c7dd74f 100644 --- a/lib/editor/tinymce/plugins/moodlemedia/lang/en/tinymce_moodlemedia.php +++ b/lib/editor/tinymce/plugins/moodlemedia/lang/en/tinymce_moodlemedia.php @@ -22,4 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['nopreview'] = 'Can not preview media.'; $string['pluginname'] = 'Insert media'; + +/* All lang strings used from TinyMCE JavaScript code must be named 'pluginname:stringname', no need to create langs/en_dlg.js */ +$string['moodlemedia:desc'] = 'Insert Moodle media'; diff --git a/lib/editor/tinymce/plugins/moodlemedia/lib.php b/lib/editor/tinymce/plugins/moodlemedia/lib.php index 5b8036469f165..5669f477a14eb 100644 --- a/lib/editor/tinymce/plugins/moodlemedia/lib.php +++ b/lib/editor/tinymce/plugins/moodlemedia/lib.php @@ -19,14 +19,13 @@ /** * Plugin for Moodle media (audio/video) insertion dialog. * - * @package tinymce_moodlemedia + * @package tinymce_moodlemedia * @copyright 2012 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class tinymce_moodlemedia extends editor_tinymce_plugin { protected function update_init_params(array &$params, context $context, array $options = null) { - global $OUTPUT; // Add button after emoticon button in advancedbuttons3. $added = $this->add_button_after($params, 3, 'moodlemedia', 'moodleemoticon', false); diff --git a/lib/editor/tinymce/plugins/moodlemedia/preview.php b/lib/editor/tinymce/plugins/moodlemedia/preview.php index 9f336ccd725b6..a98464a357a1b 100644 --- a/lib/editor/tinymce/plugins/moodlemedia/preview.php +++ b/lib/editor/tinymce/plugins/moodlemedia/preview.php @@ -18,28 +18,23 @@ * Provides A/V preview features for the TinyMCE editor Moodle Media plugin. * The preview is included in an iframe within the popup dialog. * - * @package tinymce_moodlemedia + * @package tinymce_moodlemedia * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require(dirname(__FILE__) . '/../../../../../config.php'); require_once($CFG->libdir . '/filelib.php'); -require_once($CFG->libdir . '/editorlib.php'); -require_once($CFG->libdir . '/editor/tinymce/lib.php'); -// Must be logged in -require_login(); - -// Require path to draftfile.php file -$path = required_param('path', PARAM_PATH); - -$editor = new tinymce_texteditor(); +// Decode the url - it can not be passed around unencoded because security filters might block it. +$media = required_param('media', PARAM_RAW); +$media = base64_decode($media); +$url = clean_param($media, PARAM_URL); +$url = new moodle_url($url); // Now output this file which is super-simple $PAGE->set_pagelayout('embedded'); -$PAGE->set_url(new moodle_url('/lib/editor/tinymce/plugins/moodlemedia/preview.php', - array('path' => $path))); +$PAGE->set_url(new moodle_url('/lib/editor/tinymce/plugins/moodlemedia/preview.php')); $PAGE->set_context(context_system::instance()); $PAGE->add_body_class('core_media_preview'); @@ -47,16 +42,11 @@ $mediarenderer = $PAGE->get_renderer('core', 'media'); -$path = '/'.trim($path, '/'); - -if (empty($CFG->slasharguments)) { - $url = new moodle_url('/draftfile.php', array('file'=>$path)); -} else { - $url = new moodle_url('/draftfile.php'); - $url->set_slashargument($path); -} -if ($mediarenderer->can_embed_url($url)) { +if (isloggedin() and !isguestuser() and $mediarenderer->can_embed_url($url)) { + require_sesskey(); echo $mediarenderer->embed_url($url); +} else { + print_string('nopreview', 'tinymce_moodlemedia'); } echo $OUTPUT->footer(); diff --git a/lib/editor/tinymce/plugins/moodlemedia/tinymce/css/media.css b/lib/editor/tinymce/plugins/moodlemedia/tinymce/css/media.css index d298a547ac678..290a7fee26bb9 100644 --- a/lib/editor/tinymce/plugins/moodlemedia/tinymce/css/media.css +++ b/lib/editor/tinymce/plugins/moodlemedia/tinymce/css/media.css @@ -14,8 +14,11 @@ #width, #height { width: 40px } #src, #media_type { width: 250px } #class { width: 120px } -#prev {margin: 0; border: 1px solid black; width: 380px; height: 230px; overflow: hidden } -.panel_wrapper div.current { height: 390px; overflow: auto } +#prev {margin: 0; border: 1px solid black; width: 430px; height: 330px; overflow: hidden } +.panel_wrapper div.current { height: 410px} +.panel_wrapper {border-top-style: solid} +.panel_wrapper {border-top-width: 1px} +.panel_wrapper {border-top-color: rgb(145, 155, 156)} #flash_options, #shockwave_options, #qt_options, #wmp_options, #rmp_options { display: none } .mceAddSelectValue { background-color: #DDDDDD } #qt_starttime, #qt_endtime, #qt_fov, #qt_href, #qt_moveid, #qt_moviename, #qt_node, #qt_pan, #qt_qtsrc, #qt_qtsrcchokespeed, #qt_target, #qt_tilt, #qt_urlsubstituten, #qt_volume { width: 70px } diff --git a/lib/editor/tinymce/plugins/moodlemedia/tinymce/editor_plugin.js b/lib/editor/tinymce/plugins/moodlemedia/tinymce/editor_plugin.js index ba4f72d39ca67..647cd6ee68529 100644 --- a/lib/editor/tinymce/plugins/moodlemedia/tinymce/editor_plugin.js +++ b/lib/editor/tinymce/plugins/moodlemedia/tinymce/editor_plugin.js @@ -14,21 +14,21 @@ t.editor = ed; t.url = url; - // Register commands + // Register commands. ed.addCommand('mceMoodleMedia', function() { ed.windowManager.open({ file : url + '/moodlemedia.htm', - width : 430 + parseInt(ed.getLang('media.delta_width', 0)), - height : 470 + parseInt(ed.getLang('media.delta_height', 0)), + width : 480 + parseInt(ed.getLang('media.delta_width', 0)), + height : 480 + parseInt(ed.getLang('media.delta_height', 0)), inline : 1 }, { plugin_url : url }); }); - // Register buttons + // Register buttons. ed.addButton('moodlemedia', { - title : 'Moodle Media', + title : 'moodlemedia.desc', image : url + '/img/icon.gif', cmd : 'mceMoodleMedia'}); @@ -48,6 +48,6 @@ }); - // Register plugin + // Register plugin. tinymce.PluginManager.add('moodlemedia', tinymce.plugins.MoodlemediaPlugin); })(); diff --git a/lib/editor/tinymce/plugins/moodlemedia/tinymce/js/media.js b/lib/editor/tinymce/plugins/moodlemedia/tinymce/js/media.js index 8c39ca7b86a8a..b55cd85475403 100644 --- a/lib/editor/tinymce/plugins/moodlemedia/tinymce/js/media.js +++ b/lib/editor/tinymce/plugins/moodlemedia/tinymce/js/media.js @@ -1,9 +1,10 @@ /** * @author Dongsheng Cai */ -tinyMCEPopup.requireLangPack(); -var oldWidth, oldHeight, ed, url; +// No need to require lang packs in moodle plugins. + +var ed, url; if (url = tinyMCEPopup.getParam("media_external_list_url")) { document.write(''); @@ -23,43 +24,9 @@ function insertMedia() { tinyMCEPopup.close(); } -function getType(v) { - var fo, i, c, el, x, f = document.forms[0]; - - fo = ed.getParam("media_types", "flash=swf;flv=flv;shockwave=dcr;qt=mov,qt,mpg,mp3,mp4,mpeg;shockwave=dcr;wmp=avi,wmv,wm,asf,asx,wmx,wvx;rmp=rm,ra,ram").split(';'); - - // YouTube - if (v.match(/watch\?v=(.+)(.*)/)) { - f.src.value = 'http://www.youtube.com/v/' + v.match(/v=(.*)(.*)/)[0].split('=')[1]; - return 'flash'; - } else if (v.match(/v\/(.+)(.*)/)) { - return 'flash'; - } - - // Google video - if (v.indexOf('http://video.google.com/videoplay?docid=') == 0) { - f.src.value = 'http://video.google.com/googleplayer.swf?docId=' + v.substring('http://video.google.com/videoplay?docid='.length) + '&hl=en'; - return 'flash'; - } - - for (i=0; i 0 ? s.substring(0, s.length - 1) : s; @@ -67,7 +34,6 @@ function serializeParameters() { return s; } - function getStr(p, n, d) { var e = document.forms[0].elements[(p != null ? p + "_" : "") + n]; var v = e.type == "hidden" ? e.value : e.options[e.selectedIndex].value; @@ -87,10 +53,9 @@ function jsEncode(s) { } function generatePreview(c) { - var f = document.forms[0], p = document.getElementById('prev'), h = '', cls, pl, n, type, codebase, wp, hp, nw, nh; + var f = document.forms[0], p = document.getElementById('prev'); p.innerHTML = ''; - var type = getType(f.src.value); var re = new RegExp("(.+)\#(.+)", "i"); var result = f.src.value.match(re); if (result) { @@ -102,12 +67,11 @@ function generatePreview(c) { } // After constrain - pl = serializeParameters(); + var pl = serializeParameters(); if (pl == '') { p.innerHTML = ''; return; } - pl = tinyMCEPopup.editor.plugins.moodlemedia._parse(pl); if (!pl.src) { @@ -116,22 +80,67 @@ function generatePreview(c) { } pl.src = tinyMCEPopup.editor.documentBaseURI.toAbsolute(pl.src); - pl.width = !pl.width ? 100 : pl.width; - pl.height = !pl.height ? 100 : pl.height; - pl.id = !pl.id ? 'moodlemediaid' : pl.id; - pl.name = !pl.name ? 'moodlemedianame' : pl.name; - pl.align = !pl.align ? '' : pl.align; - - // Avoid annoying warning about insecure items - if (!tinymce.isIE || document.location.protocol != 'https:') { - // Include all the draftfile params after the ? - var draftparams = pl.src.toString().replace(/^.*\/draftfile.php\//, ''); - h = ''; - } - // I don't know why the HTML comment is there, but leaving it just in case - p.innerHTML = "" + h; + // NOTE: Do not try to prevent https security popups here - users would get them later on real page anyway! + + // We can not include URL directly in parameters because some security filters might block it. + p.innerHTML = ''; +} + +function encode64(input) { + /* + CryptoMX Tools + Copyright (C) 2004 - 2006 Derek Buitenhuis + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + var output = ""; + var chr1, chr2, chr3 = ""; + var enc1, enc2, enc3, enc4 = ""; + var i = 0; + + do { + chr1 = input.charCodeAt(i++); + chr2 = input.charCodeAt(i++); + chr3 = input.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if (isNaN(chr2)) { + enc3 = enc4 = 64; + } else if (isNaN(chr3)) { + enc4 = 64; + } + + output = output + + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ""; + enc1 = enc2 = enc3 = enc4 = ""; + } while (i < input.length); + + return output; } tinyMCEPopup.onInit.add(init); diff --git a/lib/editor/tinymce/plugins/moodlemedia/tinymce/moodlemedia.htm b/lib/editor/tinymce/plugins/moodlemedia/tinymce/moodlemedia.htm index 4cdef4e807e69..b9a80ad10a7b9 100644 --- a/lib/editor/tinymce/plugins/moodlemedia/tinymce/moodlemedia.htm +++ b/lib/editor/tinymce/plugins/moodlemedia/tinymce/moodlemedia.htm @@ -1,7 +1,8 @@ - - + + - {#media_dlg.title} + + {#moodlemedia.desc}