mirror of
https://github.com/moodle/moodle.git
synced 2025-08-10 03:16:42 +02:00
MDL-33041 (4) Use new system for existing added TinyMCE plugins
AMOS BEGIN MOV [dragmath:dragmath_desc,editor_tinymce],[dragmath_desc,tinymce_dragmath] MOV [dragmath:dragmath_javaneeded,editor_tinymce],[dragmath_javaneeded,tinymce_dragmath] MOV [dragmath:dragmath_title,editor_tinymce],[dragmath_title,tinymce_dragmath] MOV [moodleemoticon:desc,editor_tinymce],[desc,tinymce_moodleemoticon] MOV [moodlenolink:desc,editor_tinymce],[desc,tinymce_moodlenolink] CPY [desc,tinymce_moodleemoticon],[pluginname,tinymce_moodleemoticon] CPY [desc,tinymce_moodlenolink],[pluginname,tinymce_moodlenolink] AMOS END
This commit is contained in:
parent
fae911708e
commit
204903363f
37 changed files with 465 additions and 74 deletions
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Strings for Moodle Media plugin.
|
||||
*
|
||||
* @package tinymce_moodlemedia
|
||||
* @copyright 2012 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['pluginname'] = 'Insert media';
|
48
lib/editor/tinymce/plugins/moodlemedia/lib.php
Normal file
48
lib/editor/tinymce/plugins/moodlemedia/lib.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Plugin for Moodle media (audio/video) insertion dialog.
|
||||
*
|
||||
* @package tinymce_moodlemedia
|
||||
* @copyright 2012 The Open University
|
||||
* @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);
|
||||
|
||||
// Note: We know that the emoticon button has already been added, if it
|
||||
// exists, because I set the sort order higher for this. So, if no
|
||||
// emoticon, add after 'image'.
|
||||
if (!$added) {
|
||||
$this->add_button_after($params, 3, 'moodlemedia', 'image');
|
||||
}
|
||||
|
||||
// Add JS file, which uses default name.
|
||||
$this->add_js_plugin($params);
|
||||
}
|
||||
|
||||
protected function get_sort_order() {
|
||||
return 110;
|
||||
}
|
||||
}
|
62
lib/editor/tinymce/plugins/moodlemedia/preview.php
Normal file
62
lib/editor/tinymce/plugins/moodlemedia/preview.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @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();
|
||||
|
||||
// Now output this file which is super-simple
|
||||
$PAGE->set_pagelayout('embedded');
|
||||
$PAGE->set_url(new moodle_url('/lib/editor/tinymce/tiny_mce/' . $editor->version . '/plugins/moodlemedia/preview.php',
|
||||
array('path' => $path)));
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$PAGE->add_body_class('core_media_preview');
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
$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)) {
|
||||
echo $mediarenderer->embed_url($url);
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
25
lib/editor/tinymce/plugins/moodlemedia/tinymce/css/media.css
Normal file
25
lib/editor/tinymce/plugins/moodlemedia/tinymce/css/media.css
Normal file
|
@ -0,0 +1,25 @@
|
|||
#id, #name, #hspace, #vspace, #class_name, #align { width: 100px }
|
||||
.moodlebutton {
|
||||
font-size: 1.5em;
|
||||
font-weight:bold;
|
||||
padding: 3px 3px 3px 1.5em;
|
||||
border:1px solid #ccc;
|
||||
text-decoration:none;
|
||||
background: url(../../../../../../../../pix/a/search.png) .2em .3em no-repeat;
|
||||
}
|
||||
.moodlebutton:hover {background: #ccc}
|
||||
#hspace, #vspace { width: 50px }
|
||||
#flash_quality, #flash_align, #flash_scale, #flash_salign, #flash_wmode { width: 100px }
|
||||
#flash_base, #flash_flashvars { width: 240px }
|
||||
#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 }
|
||||
#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 }
|
||||
#wmp_balance, #wmp_baseurl, #wmp_captioningid, #wmp_currentmarker, #wmp_currentposition, #wmp_defaultframe, #wmp_playcount, #wmp_rate, #wmp_uimode, #wmp_volume { width: 70px }
|
||||
#rmp_console, #rmp_numloop, #rmp_controls, #rmp_scriptcallbacks { width: 70px }
|
||||
#shockwave_swvolume, #shockwave_swframe, #shockwave_swurl, #shockwave_swstretchvalign, #shockwave_swstretchhalign, #shockwave_swstretchstyle { width: 90px }
|
||||
#qt_qtsrc { width: 200px }
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* @author Dongsheng Cai <dongsheng@moodle.com>
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var each = tinymce.each;
|
||||
|
||||
tinymce.PluginManager.requireLangPack('moodlemedia');
|
||||
|
||||
tinymce.create('tinymce.plugins.MoodlemediaPlugin', {
|
||||
init : function(ed, url) {
|
||||
var t = this;
|
||||
|
||||
t.editor = ed;
|
||||
t.url = url;
|
||||
|
||||
// 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)),
|
||||
inline : 1
|
||||
}, {
|
||||
plugin_url : url
|
||||
});
|
||||
});
|
||||
|
||||
// Register buttons
|
||||
ed.addButton('moodlemedia', {
|
||||
title : 'Moodle Media',
|
||||
image : url + '/img/icon.gif',
|
||||
cmd : 'mceMoodleMedia'});
|
||||
|
||||
},
|
||||
|
||||
_parse : function(s) {
|
||||
return tinymce.util.JSON.parse('{' + s + '}');
|
||||
},
|
||||
|
||||
getInfo : function() {
|
||||
return {
|
||||
longname : 'Moodle media',
|
||||
author : 'Dongsheng Cai <dongsheng@moodle.com>',
|
||||
version : "1.0"
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Register plugin
|
||||
tinymce.PluginManager.add('moodlemedia', tinymce.plugins.MoodlemediaPlugin);
|
||||
})();
|
BIN
lib/editor/tinymce/plugins/moodlemedia/tinymce/img/icon.gif
Normal file
BIN
lib/editor/tinymce/plugins/moodlemedia/tinymce/img/icon.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 910 B |
137
lib/editor/tinymce/plugins/moodlemedia/tinymce/js/media.js
Normal file
137
lib/editor/tinymce/plugins/moodlemedia/tinymce/js/media.js
Normal file
|
@ -0,0 +1,137 @@
|
|||
/**
|
||||
* @author Dongsheng Cai <dongsheng@moodle.com>
|
||||
*/
|
||||
tinyMCEPopup.requireLangPack();
|
||||
|
||||
var oldWidth, oldHeight, ed, url;
|
||||
|
||||
if (url = tinyMCEPopup.getParam("media_external_list_url")) {
|
||||
document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>');
|
||||
}
|
||||
|
||||
function init() {
|
||||
ed = tinyMCEPopup.editor;
|
||||
document.getElementById('filebrowsercontainer').innerHTML = getBrowserHTML('filebrowser','src','media','media');
|
||||
}
|
||||
|
||||
function insertMedia() {
|
||||
var f = document.forms[0];
|
||||
var url = f.filename.value;
|
||||
var linkname = url.substring(url.lastIndexOf('/')+1);
|
||||
var h = '<a href="'+f.src.value+'">'+linkname+'</a>';
|
||||
ed.execCommand('mceInsertContent', false, h);
|
||||
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<fo.length; i++) {
|
||||
c = fo[i].split('=');
|
||||
|
||||
el = c[1].split(',');
|
||||
for (x=0; x<el.length; x++)
|
||||
if (v.indexOf('.' + el[x]) != -1)
|
||||
return c[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
function serializeParameters() {
|
||||
var d = document, f = d.forms[0], s = '';
|
||||
s += getStr(null, 'src');
|
||||
s += 'width:300,';
|
||||
s += 'height:225,';
|
||||
|
||||
// delete the tail comma
|
||||
s = s.length > 0 ? s.substring(0, s.length - 1) : s;
|
||||
|
||||
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;
|
||||
|
||||
if (n == 'src')
|
||||
v = tinyMCEPopup.editor.convertURL(v, 'src', null);
|
||||
|
||||
return ((n == d || v == '') ? '' : n + ":'" + jsEncode(v) + "',");
|
||||
}
|
||||
|
||||
function jsEncode(s) {
|
||||
s = s.replace(new RegExp('\\\\', 'g'), '\\\\');
|
||||
s = s.replace(new RegExp('"', 'g'), '\\"');
|
||||
s = s.replace(new RegExp("'", 'g'), "\\'");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
function generatePreview(c) {
|
||||
var f = document.forms[0], p = document.getElementById('prev'), h = '', cls, pl, n, type, codebase, wp, hp, nw, nh;
|
||||
|
||||
p.innerHTML = '<!-- x --->';
|
||||
var type = getType(f.src.value);
|
||||
var re = new RegExp("(.+)\#(.+)", "i");
|
||||
var result = f.src.value.match(re);
|
||||
if (result) {
|
||||
f.src.value = result[1];
|
||||
f.filename.value = result[2];
|
||||
} else {
|
||||
f.src.value = f.src.value;
|
||||
f.filename.value = f.src.value;
|
||||
}
|
||||
|
||||
// After constrain
|
||||
pl = serializeParameters();
|
||||
if (pl == '') {
|
||||
p.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
pl = tinyMCEPopup.editor.plugins.moodlemedia._parse(pl);
|
||||
|
||||
if (!pl.src) {
|
||||
p.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
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 = '<iframe src="../../..//moodlemedia/preview.php?path=' +
|
||||
draftparams + '" width="100%" height="100%"></iframe>';
|
||||
}
|
||||
|
||||
// I don't know why the HTML comment is there, but leaving it just in case
|
||||
p.innerHTML = "<!-- x --->" + h;
|
||||
}
|
||||
|
||||
tinyMCEPopup.onInit.add(init);
|
|
@ -0,0 +1,58 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>{#media_dlg.title}</title>
|
||||
<script type="text/javascript">
|
||||
// Because there is no relative path to TinyMCE, we have to use JavaScript
|
||||
// to work out correct path from the .js files from TinyMCE. Only files
|
||||
// inside this plugin can be included with relative path (below).
|
||||
var editor_tinymce_include = function(path) {
|
||||
document.write('<script type="text/javascript" src="' +
|
||||
parent.tinyMCE.baseURL + '/' + path + '"></' + 'script>');
|
||||
};
|
||||
editor_tinymce_include('tiny_mce_popup.js');
|
||||
editor_tinymce_include('utils/mctabs.js');
|
||||
editor_tinymce_include('utils/validate.js');
|
||||
editor_tinymce_include('utils/form_utils.js');
|
||||
editor_tinymce_include('utils/editable_selects.js');
|
||||
</script>
|
||||
<script type="text/javascript" src="js/media.js"></script>
|
||||
<link href="css/media.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body style="display: none">
|
||||
<div class="tabs"></div>
|
||||
<form onsubmit="insertMedia();return false;" action="#">
|
||||
<div class="panel_wrapper">
|
||||
<div id="general_panel" class="panel current">
|
||||
<input id="src" name="src" type="hidden" value="" class="mceFocus" onchange="generatePreview();" />
|
||||
<input id="filename" name="filename" type="hidden" value="" />
|
||||
<fieldset>
|
||||
<legend>{#media_dlg.general}</legend>
|
||||
|
||||
<table align="center" border="0" cellpadding="4" cellspacing="0">
|
||||
<tr align="center">
|
||||
<td colspan='2' id="filebrowsercontainer"> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend>{#media_dlg.preview}</legend>
|
||||
<div id="prev"></div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="mceActionPanel">
|
||||
<div style="float: left">
|
||||
<input type="submit" id="insert" name="insert" value="{#insert}" />
|
||||
</div>
|
||||
|
||||
<div style="float: right">
|
||||
<input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
32
lib/editor/tinymce/plugins/moodlemedia/version.php
Normal file
32
lib/editor/tinymce/plugins/moodlemedia/version.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* TinyMCE media insert plugin version details.
|
||||
*
|
||||
* @package tinymce_moodlemedia
|
||||
* @copyright 2012 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2012051701;
|
||||
// Required Moodle version.
|
||||
$plugin->requires = 2011112900;
|
||||
// Full name of the plugin (used for diagnostics).
|
||||
$plugin->component = 'tinymce_moodlemedia';
|
Loading…
Add table
Add a link
Reference in a new issue