mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
"MDL-21170, major update to filepicker, complete rewrote filepicker javascript code to use YUI3, need furthur polish"
This commit is contained in:
parent
deb7a013ae
commit
99eaca9d3d
@ -117,6 +117,7 @@ $string['submit'] = 'Submit';
|
||||
$string['sync'] = 'Sync';
|
||||
$string['title'] = 'Choose a file...';
|
||||
$string['thumbview'] = 'View as icons';
|
||||
$string['iconview'] = 'View as icons';
|
||||
$string['typenotvisible'] = 'Type not visible';
|
||||
$string['updown'] = 'Display order';
|
||||
$string['upload'] = 'Upload this file';
|
||||
|
@ -166,6 +166,8 @@ class page_requirements_manager {
|
||||
$this->yui2_lib('dom'); // needs to be migrated to YUI3 before we release 2.0
|
||||
$this->yui2_lib('container'); // needs to be migrated to YUI3 before we release 2.0
|
||||
$this->yui2_lib('connection'); // needs to be migrated to YUI3 before we release 2.0
|
||||
// File Picker use this module loading YUI2 widgets
|
||||
$this->yui2_lib('yuiloader'); // needs to be migrated to YUI3 before we release 2.0
|
||||
|
||||
$this->string_for_js('confirmation', 'admin');
|
||||
$this->string_for_js('cancel', 'moodle');
|
||||
@ -603,14 +605,22 @@ class page_requirements_manager {
|
||||
|
||||
$ondomreadyjs = $this->get_javascript_code(self::WHEN_ON_DOM_READY, ' ');
|
||||
|
||||
$pathtofilepicker = $CFG->httpswwwroot.'/repository/filepicker.js';
|
||||
|
||||
$js .= <<<EOD
|
||||
Y = YUI({
|
||||
base: moodle_cfg.yui3loaderBase
|
||||
}).use('node-base', function(Y) {
|
||||
Y.on('domready', function() {
|
||||
$ondomreadyjs
|
||||
\n
|
||||
Y = YUI({
|
||||
base: moodle_cfg.yui3loaderBase,
|
||||
combine: true,
|
||||
comboBase: moodle_cfg.yui3loaderComboBase,
|
||||
modules: {
|
||||
'filepicker':{fullpath:'$pathtofilepicker', 'requires':['base', 'node', 'json', 'async-queue', 'io']}
|
||||
}
|
||||
}).use('node-base', function(Y) {
|
||||
Y.on('domready', function() {
|
||||
$ondomreadyjs
|
||||
});
|
||||
});
|
||||
});
|
||||
EOD;
|
||||
|
||||
$output .= ajax_generate_script_tag($js);
|
||||
|
@ -47,12 +47,23 @@ function mce_saveOnSubmit(id) {
|
||||
};
|
||||
}
|
||||
|
||||
function mce_moodlefilemanager(field_name, url, type, win) {
|
||||
var client_id = id2clientid[tinyMCE.selectedInstance.editorId];
|
||||
var picker = document.createElement('DIV');
|
||||
picker.className = "file-picker";
|
||||
picker.id = 'file-picker-'+client_id;
|
||||
document.body.appendChild(picker);
|
||||
var el = win.document.getElementById(field_name);
|
||||
open_filepicker(client_id, {"env":"editor","target":el,"filetype":type, "savepath":"/"});
|
||||
var editor_filepickers = {};
|
||||
var editor_options = {};
|
||||
function editor_filepicker_callback(args) {
|
||||
}
|
||||
function editor_init_filepicker(editorid, options) {
|
||||
editor_options[editorid] = options;
|
||||
}
|
||||
function mce_moodlefilemanager(target_id, url, type, win) {
|
||||
Y.use("filepicker", function (Y) {
|
||||
var editor_id = tinyMCE.selectedInstance.editorId;
|
||||
var options = editor_options[editor_id];
|
||||
var client_id = options.client_id;
|
||||
options.formcallback = editor_filepicker_callback;
|
||||
options.editor_target = win.document.getElementById(target_id);
|
||||
if (!editor_filepickers[client_id]) {
|
||||
editor_filepickers[client_id] = new Y.filepicker(options);
|
||||
}
|
||||
editor_filepickers[client_id].show();
|
||||
});
|
||||
}
|
||||
|
@ -2229,7 +2229,7 @@ class curl {
|
||||
// sends as part of the HTTP header (note this is recursive,
|
||||
// PHP will follow as many "Location: " headers that it is sent,
|
||||
// unless CURLOPT_MAXREDIRS is set).
|
||||
$this->options['CURLOPT_FOLLOWLOCATION'] = 1;
|
||||
//$this->options['CURLOPT_FOLLOWLOCATION'] = 1;
|
||||
$this->options['CURLOPT_MAXREDIRS'] = 10;
|
||||
$this->options['CURLOPT_ENCODING'] = '';
|
||||
// TRUE to return the transfer as a string of the return
|
||||
@ -2764,7 +2764,7 @@ class curl_cache {
|
||||
* @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_type_to_ext {
|
||||
class filetype_parser {
|
||||
/**
|
||||
* Check file_types.mm file, setup variables
|
||||
*
|
||||
@ -2826,7 +2826,10 @@ class file_type_to_ext {
|
||||
* @param array $types
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_file_ext($types) {
|
||||
public function get_extensions($types) {
|
||||
if (!is_array($types)) {
|
||||
$types = array($types);
|
||||
}
|
||||
$this->result = array();
|
||||
if ((is_array($types) && in_array('*', $types)) ||
|
||||
$types == '*' || empty($types)) {
|
||||
@ -2848,7 +2851,7 @@ class file_type_to_ext {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
exit('Failed to open test.xml.');
|
||||
exit('Failed to open file');
|
||||
}
|
||||
return $this->result;
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
|
||||
protected $_values = array('text'=>null, 'format'=>null, 'itemid'=>null);
|
||||
|
||||
function MoodleQuickForm_editor($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
|
||||
global $CFG;
|
||||
global $CFG, $PAGE;
|
||||
$PAGE->requires->js('lib/form/filepicker.js');
|
||||
|
||||
$options = (array)$options;
|
||||
foreach ($options as $name=>$value) {
|
||||
@ -35,7 +36,6 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
|
||||
$this->_options['trusted'] = trusttext_trusted($this->_options['context']);
|
||||
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
|
||||
repository_head_setup();
|
||||
editors_head_setup();
|
||||
}
|
||||
|
||||
@ -114,6 +114,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
|
||||
|
||||
function toHtml() {
|
||||
global $CFG, $COURSE, $PAGE;
|
||||
require_once($CFG->dirroot.'/repository/lib.php');
|
||||
|
||||
if ($this->_flagFrozen) {
|
||||
return $this->getFrozenHtml();
|
||||
@ -177,13 +178,25 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
|
||||
$str .= '<object type="text/html" data="'.$editorurl.'" height="160" width="600" style="border:1px solid #000">Error</object>'; // TODO: localise, fix styles, etc.
|
||||
$str .= '</div>';
|
||||
|
||||
require_once($CFG->dirroot.'/repository/lib.php');
|
||||
$client_id = uniqid();
|
||||
$repojs = repository_get_client($ctx, $client_id, array('image', 'video', 'media'), (FILE_EXTERNAL | FILE_INTERNAL));
|
||||
|
||||
$str .= $repojs;
|
||||
$str .= $PAGE->requires->js_function_call('id2_add_clientid', array($id, $client_id))->asap();
|
||||
$str .= $PAGE->requires->js_function_call('id2_add_itemid', array($id, $draftitemid))->asap();
|
||||
$args = new stdclass;
|
||||
// need these three to filter repositories list
|
||||
$args->accepted_types = array('image', 'video', 'media');
|
||||
$args->return_types = (FILE_INTERNAL | FILE_EXTERNAL);
|
||||
$args->context = $ctx;
|
||||
$args->env = 'filepicker';
|
||||
|
||||
$options = initialise_filepicker($args);
|
||||
|
||||
$options->client_id = $client_id;
|
||||
$options->maxbytes = $this->_options['maxbytes'];
|
||||
$options->maxfiles = 1;
|
||||
$options->env = 'editor';
|
||||
|
||||
//$PAGE->requires->js_function_call('id2_add_clientid', array($id, $client_id))->on_dom_ready();
|
||||
//$PAGE->requires->js_function_call('id2_add_itemid', array($id, $draftitemid))->on_dom_ready();
|
||||
$PAGE->requires->js_function_call('editor_init_filepicker', array($id, $options))->on_dom_ready();
|
||||
|
||||
if ($editor->supports_repositories()) {
|
||||
$str .= $PAGE->requires->js_function_call('destroy_item', array("{$id}_filemanager"))->asap();
|
||||
|
@ -88,6 +88,23 @@ function filemanager_callback(params) {
|
||||
}
|
||||
}
|
||||
|
||||
var fm_filepickers = {};
|
||||
function fp_filepicker_callback(params) {
|
||||
var html = '<a href="'+params['file']+'">'+params['title']+'</a>';
|
||||
document.getElementById('file_info_'+params['client_id']).innerHTML = html;
|
||||
}
|
||||
|
||||
function fm_init_filepicker(id, options) {
|
||||
Y.use("filepicker", function (Y) {
|
||||
options.formcallback = filemanager_callback;
|
||||
if (!pickers[options.client_id]) {
|
||||
fm_filepickers[options.client_id] = new Y.filepicker(options);
|
||||
}
|
||||
Y.one('#'+id).on('click', function(e, client_id) {
|
||||
fm_filepickers[options.client_id].show();
|
||||
}, this, options.client_id);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Setup options to launch file picker.
|
||||
* Fired by add file button.
|
||||
|
@ -27,19 +27,14 @@ global $CFG;
|
||||
|
||||
require_once('HTML/QuickForm/element.php');
|
||||
require_once($CFG->dirroot.'/lib/filelib.php');
|
||||
require_once("$CFG->dirroot/repository/lib.php");
|
||||
|
||||
class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
public $_helpbutton = '';
|
||||
protected $_options = array('mainfile'=>'', 'subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>-1, 'filetypes'=>'*', 'returntypes'=>FILE_INTERNAL);
|
||||
protected $_options = array('mainfile'=>'', 'subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
|
||||
|
||||
function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
|
||||
global $CFG, $PAGE;
|
||||
require_once("$CFG->dirroot/repository/lib.php");
|
||||
|
||||
// has to require these js files before head
|
||||
$PAGE->requires->yui2_lib('menu');
|
||||
$PAGE->requires->yui2_lib('connection');
|
||||
$PAGE->requires->yui2_lib('json');
|
||||
|
||||
$options = (array)$options;
|
||||
foreach ($options as $name=>$value) {
|
||||
@ -51,8 +46,8 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
|
||||
}
|
||||
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
|
||||
repository_head_setup();
|
||||
$PAGE->requires->js('repository/filepicker.js');
|
||||
$PAGE->requires->js('lib/form/filemanager.js');
|
||||
}
|
||||
|
||||
function setName($name) {
|
||||
@ -130,12 +125,14 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
$subdirs = $this->_options['subdirs'];
|
||||
$maxbytes = $this->_options['maxbytes'];
|
||||
$draftitemid = $this->getValue();
|
||||
$accepted_types = $this->_options['accepted_types'];
|
||||
|
||||
// language strings
|
||||
$straddfile = get_string('add', 'repository') . '...';
|
||||
$strmakedir = get_string('makeafolder', 'moodle');
|
||||
$strdownload = get_string('downloadfolder', 'repository');
|
||||
|
||||
|
||||
$PAGE->requires->string_for_js('loading', 'repository');
|
||||
$PAGE->requires->string_for_js('nomorefiles', 'repository');
|
||||
$PAGE->requires->string_for_js('confirmdeletefile', 'repository');
|
||||
@ -168,17 +165,22 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
|
||||
$draftareainfo = file_get_draft_area_info($draftitemid);
|
||||
$filecount = $draftareainfo['filecount'];
|
||||
|
||||
if ($COURSE->id == SITEID) {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
} else {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
|
||||
}
|
||||
|
||||
$client_id = uniqid();
|
||||
|
||||
$args = new stdclass;
|
||||
// need these three to filter repositories list
|
||||
$args->accepted_types = $accepted_types;
|
||||
$args->return_types = $this->_options['return_types'];
|
||||
$args->context = $PAGE->context;
|
||||
$args->env = 'filemanager';
|
||||
|
||||
$filepicker_options = initialise_filepicker($args);
|
||||
|
||||
$filepicker_options->client_id = $client_id;
|
||||
$filepicker_options->maxbytes = $this->_options['maxbytes'];
|
||||
$filepicker_options->maxfiles = $this->_options['maxfiles'];
|
||||
|
||||
// Generate file picker
|
||||
$repojs = repository_get_client($context, $client_id, $this->_options['filetypes'], $this->_options['returntypes']);
|
||||
$result = new stdclass;
|
||||
|
||||
$options = file_get_draft_area_files($draftitemid);
|
||||
@ -192,11 +194,9 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
$options->target = $id;
|
||||
|
||||
$html = $this->_getTabs();
|
||||
$html .= $repojs;
|
||||
|
||||
if (empty($CFG->filemanagerjsloaded)) {
|
||||
$PAGE->requires->js('lib/form/filemanager.js');
|
||||
$CFG->filemanagerjsloaded = true;
|
||||
if (empty($CFG->filemanagertemplateloaded)) {
|
||||
$CFG->filemanagertemplateloaded = true;
|
||||
// print html template
|
||||
$html .= <<<FMHTML
|
||||
<div id="fm-template" style="display:none"><div class="fm-file-menu">___action___</div> <div class="fm-file-name">___fullname___</div></div>
|
||||
@ -212,7 +212,6 @@ FMHTML;
|
||||
<a href="###" id="btncrt-{$client_id}">{$strmakedir}</a>
|
||||
<a href="###" id="btndwn-{$client_id}">{$strdownload}</a>
|
||||
</div>
|
||||
|
||||
<div class="filemanager-container" id="filemanager-{$client_id}">
|
||||
<ul id="draftfiles-{$client_id}">
|
||||
<li>Loading...</li>
|
||||
@ -221,16 +220,17 @@ FMHTML;
|
||||
</div>
|
||||
FMHTML;
|
||||
// non-javascript file manager, will be destroied automatically if javascript is enabled.
|
||||
$html .= '<div id="nonjs-filemanager-'.$client_id.'">';
|
||||
$editorurl = "$CFG->wwwroot/repository/filepicker.php?env=filemanager&action=embedded&itemid=$draftitemid&subdirs=/&maxbytes=$options->maxbytes&ctx_id=".$context->id;
|
||||
$html .= '<object type="text/html" data="'.$editorurl.'" height="160" width="600" style="border:1px solid #000">Error</object>';
|
||||
$html .= '</div>';
|
||||
$editorurl = "$CFG->wwwroot/repository/filepicker.php?env=filemanager&action=embedded&itemid=$draftitemid&subdirs=/&maxbytes=$options->maxbytes&ctx_id=".$PAGE->context->id;
|
||||
$html .= <<<NONJS
|
||||
<div id="nonjs-filemanager-$client_id">';
|
||||
<object type="text/html" data="$editorurl" height="160" width="600" style="border:1px solid #000">Error</object>';
|
||||
</div>
|
||||
NONJS;
|
||||
|
||||
$html .= $PAGE->requires->js_function_call('destroy_item', array("nonjs-filemanager-{$client_id}"))->asap();
|
||||
$html .= $PAGE->requires->js_function_call('show_item', array("filemanager-wrapper-{$client_id}"))->asap();
|
||||
$PAGE->requires->js_function_call('destroy_item', array("nonjs-filemanager-{$client_id}"))->on_dom_ready();
|
||||
$PAGE->requires->js_function_call('show_item', array("filemanager-wrapper-{$client_id}"))->on_dom_ready();
|
||||
$PAGE->requires->js_function_call('launch_filemanager', array($client_id, $options))->on_dom_ready();
|
||||
|
||||
$PAGE->requires->js_function_call('fm_init_filepicker', array('btnadd-'.$client_id, $filepicker_options))->on_dom_ready();
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,24 +1,17 @@
|
||||
function filepicker_callback(params) {
|
||||
var html = '<a href="'+params['url']+'">'+params['file']+'</a>';
|
||||
// TODO: support delete the draft file
|
||||
var pickers = {};
|
||||
function fp_filepicker_callback(params) {
|
||||
var html = '<a href="'+params['file']+'">'+params['title']+'</a>';
|
||||
document.getElementById('file_info_'+params['client_id']).innerHTML = html;
|
||||
}
|
||||
|
||||
// launch file picker from filepicker element
|
||||
function launch_filepicker(id, client_id, itemid) {
|
||||
var picker = document.createElement('DIV');
|
||||
picker.id = 'file-picker-'+client_id;
|
||||
picker.className = 'file-picker';
|
||||
document.body.appendChild(picker);
|
||||
var el=document.getElementById(id);
|
||||
var params = {};
|
||||
params.env = 'filepicker';
|
||||
params.itemid = itemid;
|
||||
params.maxbytes = filepicker.maxbytes;
|
||||
params.maxfiles = filepicker.maxfiles;
|
||||
params.savepath = '/';
|
||||
params.target = el;
|
||||
params.callback = filepicker_callback;
|
||||
var fp = open_filepicker(client_id, params);
|
||||
return false;
|
||||
function fp_init_filepicker(id, options) {
|
||||
Y.use("filepicker", function (Y) {
|
||||
options.formcallback = fp_filepicker_callback;
|
||||
if (!pickers[options.client_id]) {
|
||||
pickers[options.client_id] = new Y.filepicker(options);
|
||||
}
|
||||
Y.one('#'+id).on('click', function(e, client_id) {
|
||||
pickers[options.client_id].show();
|
||||
}, this, options.client_id);
|
||||
});
|
||||
}
|
||||
|
@ -15,11 +15,10 @@ require_once($CFG->dirroot.'/repository/lib.php');
|
||||
*/
|
||||
class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
|
||||
public $_helpbutton = '';
|
||||
protected $_options = array('maxbytes'=>0, 'filetypes'=>'*', 'returntypes'=>FILE_INTERNAL);
|
||||
protected $_options = array('maxbytes'=>0, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
|
||||
|
||||
function MoodleQuickForm_filepicker($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
|
||||
global $CFG;
|
||||
require_once("$CFG->dirroot/repository/lib.php");
|
||||
|
||||
$options = (array)$options;
|
||||
foreach ($options as $name=>$value) {
|
||||
@ -31,8 +30,6 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
|
||||
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
|
||||
}
|
||||
parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
|
||||
|
||||
repository_head_setup();
|
||||
}
|
||||
|
||||
function setHelpButton($helpbuttonargs, $function='helpbutton') {
|
||||
@ -81,31 +78,46 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
|
||||
} else {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
|
||||
}
|
||||
|
||||
$client_id = uniqid();
|
||||
$repojs = repository_get_client($context, $client_id, $this->_options['filetypes'], $this->_options['returntypes']);
|
||||
$PAGE->requires->data_for_js('filepicker', array('maxbytes'=>$this->_options['maxbytes'],'maxfiles'=>1));
|
||||
$PAGE->requires->js('lib/form/filepicker.js');
|
||||
|
||||
$args = new stdclass;
|
||||
// need these three to filter repositories list
|
||||
$args->accepted_types = $this->_options['accepted_types']?$this->_options['accepted_types']:'*';
|
||||
$args->return_types = FILE_INTERNAL;
|
||||
$args->context = $PAGE->context;
|
||||
$args->env = 'filepicker';
|
||||
|
||||
$options = initialise_filepicker($args);
|
||||
|
||||
$options->client_id = $client_id;
|
||||
$options->maxbytes = $this->_options['maxbytes'];
|
||||
$options->maxfiles = 1;
|
||||
|
||||
$id = $this->_attributes['id'];
|
||||
$elname = $this->_attributes['name'];
|
||||
|
||||
$str = $this->_getTabs();
|
||||
$str .= '<input type="hidden" name="'.$elname.'" id="'.$id.'" '.$draftvalue.' />';
|
||||
$str .= $repojs;
|
||||
|
||||
$str .= <<<EOD
|
||||
<div id="filepicker-wrapper-{$client_id}" style="display:none">
|
||||
<div class="filemanager-toolbar">
|
||||
<a href="###" onclick="return launch_filepicker('$id', '$client_id', '$draftitemid')">$straddfile</a>
|
||||
<a href="###" id="filepicker-button-{$client_id}">$straddfile</a>
|
||||
</div>
|
||||
<div id="file_info_{$client_id}" class="mdl-left">$currentfile</div>
|
||||
</div>
|
||||
<!-- non javascript file picker -->
|
||||
<noscript>
|
||||
<object type="text/html" id="nonjs-filepicker-{$client_id}" data="{$CFG->httpswwwroot}/repository/filepicker.php?env=filepicker&action=embedded&itemid={$draftitemid}&ctx_id=$context->id" height="300" width="800" style="border:1px solid #000">Error</object>
|
||||
<object type="text/html" id="nonjs-filepicker-{$client_id}" data="{$CFG->httpswwwroot}/repository/filepicker.php?env=filepicker&action=embedded&itemid={$draftitemid}&ctx_id=$context->id" height="300" width="800" style="border:1px solid #000">
|
||||
Moodle File Picker
|
||||
</object>
|
||||
</noscript>
|
||||
EOD;
|
||||
$str .= $PAGE->requires->js_function_call('destroy_item', array("nonjs-filepicker-{$client_id}"))->asap();
|
||||
$str .= $PAGE->requires->js_function_call('show_item', array("filepicker-wrapper-{$client_id}"))->asap();
|
||||
$PAGE->requires->js_function_call('fp_init_filepicker', array('filepicker-button-'.$client_id, $options))->on_dom_ready();
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Miscellaneous core Javascript functions for Moodle
|
||||
|
||||
// Global instance of YUI3
|
||||
var Y = null;
|
||||
function popupchecker(msg) {
|
||||
var testwindow = window.open('', '', 'width=1,height=1,left=0,top=0,scrollbars=no');
|
||||
if (!testwindow) {
|
||||
@ -2051,4 +2052,4 @@ blocks.dock.item.prototype.show = blocks.dock.abstract_item_class.
|
||||
blocks.dock.item.prototype.hide = blocks.dock.abstract_item_class.hide;
|
||||
blocks.dock.item.prototype.resize_panel = blocks.dock.abstract_item_class.resize_panel;
|
||||
|
||||
///////////////// END OF BLOCKS CODE \\\\\\\\\\\\\\\\\\\\\\
|
||||
///////////////// END OF BLOCKS CODE \\\\\\\\\\\\\\\\\\\\\\
|
||||
|
@ -173,7 +173,7 @@ class repository_boxnet extends repository {
|
||||
'date'=>$filedates[$n],
|
||||
'source'=>'http://box.net/api/1.0/download/'
|
||||
.$this->auth_token.'/'.$fileids[$n],
|
||||
'thumbnail' => $OUTPUT->pix_url(file_extension_icon($v, 32)));
|
||||
'thumbnail' => $OUTPUT->pix_url(file_extension_icon($v, 32))->out());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1086
repository/filepicker.js
Normal file
1086
repository/filepicker.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -15,6 +15,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
require_once($CFG->libdir.'/flickrlib.php');
|
||||
require_once(dirname(__FILE__) . '/image.php');
|
||||
|
||||
/**
|
||||
* repository_flickr_public class
|
||||
* This one is used to create public repository
|
||||
@ -28,13 +32,6 @@
|
||||
* @author Dongsheng Cai <dongsheng@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once($CFG->libdir.'/flickrlib.php');
|
||||
require_once(dirname(__FILE__) . '/image.php');
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class repository_flickr_public extends repository {
|
||||
private $flickr;
|
||||
public $photos;
|
||||
@ -49,12 +46,12 @@ class repository_flickr_public extends repository {
|
||||
set_config('api_key', trim($options['api_key']), 'flickr_public');
|
||||
}
|
||||
unset($options['api_key']);
|
||||
$ret = parent::set_option($options);
|
||||
return $ret;
|
||||
return parent::set_option($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* get api_key from config table
|
||||
*
|
||||
* @param string $config
|
||||
* @return mixed
|
||||
*/
|
||||
@ -64,12 +61,12 @@ class repository_flickr_public extends repository {
|
||||
} else {
|
||||
$options['api_key'] = trim(get_config('flickr_public', 'api_key'));
|
||||
}
|
||||
$options = parent::get_option($config);
|
||||
return $options;
|
||||
return parent::get_option($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* is global_search available?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function global_search() {
|
||||
@ -81,8 +78,10 @@ class repository_flickr_public extends repository {
|
||||
}
|
||||
|
||||
/**
|
||||
* constructor method
|
||||
*
|
||||
* @global object $CFG
|
||||
* @global object $SESSION
|
||||
* @param int $repositoryid
|
||||
* @param int $context
|
||||
* @param array $options
|
||||
@ -123,6 +122,7 @@ class repository_flickr_public extends repository {
|
||||
}
|
||||
|
||||
/**
|
||||
* construct login form
|
||||
*
|
||||
* @param boolean $ajax
|
||||
* @return array
|
||||
@ -193,8 +193,9 @@ class repository_flickr_public extends repository {
|
||||
}
|
||||
|
||||
/**
|
||||
* destroy session
|
||||
*
|
||||
* @return <type>
|
||||
* @return object
|
||||
*/
|
||||
public function logout() {
|
||||
global $SESSION;
|
||||
@ -205,13 +206,18 @@ class repository_flickr_public extends repository {
|
||||
}
|
||||
|
||||
/**
|
||||
* search images on flickr
|
||||
*
|
||||
* @param <type> $search_text
|
||||
* @return <type>
|
||||
* @param string $search_text
|
||||
* @return array
|
||||
*/
|
||||
public function search($search_text) {
|
||||
public function search($search_text, $page = 1) {
|
||||
global $SESSION;
|
||||
$ret = array();
|
||||
if (empty($page)) {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if (!empty($this->flickr_account)) {
|
||||
$people = $this->flickr->people_findByEmail($this->flickr_account);
|
||||
$this->nsid = $people['nsid'];
|
||||
@ -228,12 +234,7 @@ class repository_flickr_public extends repository {
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
$is_paging = optional_param('search_paging', '', PARAM_RAW);
|
||||
if (!empty($is_paging)) {
|
||||
$page = optional_param('p', '', PARAM_INT);
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
// including all licenses by default
|
||||
$licenses = array(1=>1, 2, 3, 4, 5, 6, 7);
|
||||
|
||||
@ -291,10 +292,11 @@ class repository_flickr_public extends repository {
|
||||
}
|
||||
|
||||
/**
|
||||
* return an image list
|
||||
*
|
||||
* @param string $path
|
||||
* @param int $page
|
||||
* @return <type>
|
||||
* @return array
|
||||
*/
|
||||
public function get_listing($path = '', $page = 1) {
|
||||
$people = $this->flickr->people_findByEmail($this->flickr_account);
|
||||
@ -306,10 +308,11 @@ class repository_flickr_public extends repository {
|
||||
}
|
||||
|
||||
/**
|
||||
* build an image list
|
||||
*
|
||||
* @param <type> $photos
|
||||
* @param <type> $page
|
||||
* @return <type>
|
||||
* @param array $photos
|
||||
* @param int $page
|
||||
* @return array
|
||||
*/
|
||||
private function build_list($photos, $page = 1, &$ret) {
|
||||
if (!empty($this->nsid)) {
|
||||
@ -414,7 +417,7 @@ class repository_flickr_public extends repository {
|
||||
|
||||
/**
|
||||
* Add Instance settings input to Moodle form
|
||||
* @param <type> $
|
||||
* @param object $mform
|
||||
*/
|
||||
public function instance_config_form(&$mform) {
|
||||
$mform->addElement('text', 'email_address', get_string('emailaddress', 'repository_flickr_public'));
|
||||
@ -423,7 +426,7 @@ class repository_flickr_public extends repository {
|
||||
|
||||
/**
|
||||
* Names of the instance settings
|
||||
* @return <type>
|
||||
* @return array
|
||||
*/
|
||||
public static function get_instance_option_names() {
|
||||
return array('email_address');
|
||||
@ -431,7 +434,7 @@ class repository_flickr_public extends repository {
|
||||
|
||||
/**
|
||||
* Add Plugin settings input to Moodle form
|
||||
* @param <type> $
|
||||
* @param object $mform
|
||||
*/
|
||||
public function type_config_form(&$mform) {
|
||||
$api_key = get_config('flickr_public', 'api_key');
|
||||
@ -451,7 +454,7 @@ class repository_flickr_public extends repository {
|
||||
|
||||
/**
|
||||
* Names of the plugin settings
|
||||
* @return <type>
|
||||
* @return array
|
||||
*/
|
||||
public static function get_type_option_names() {
|
||||
return array('api_key', 'watermark');
|
||||
|
@ -598,7 +598,6 @@ abstract class repository {
|
||||
* @param string $type a type name to retrieve
|
||||
* @return array repository instances
|
||||
*/
|
||||
//public static function get_instances($contexts=array(), $userid = null, $onlyvisible = true, $type=null, $accepted_types = '*', $returntypes = 3) {
|
||||
public static function get_instances($args = array()) {
|
||||
global $DB, $CFG, $USER;
|
||||
|
||||
@ -616,7 +615,6 @@ abstract class repository {
|
||||
|
||||
$onlyvisible = isset($args['onlyvisible']) ? $args['onlyvisible'] : true;
|
||||
$type = isset($args['type']) ? $args['type'] : null;
|
||||
$acceptedtypes = isset($args['accepted_types']) ? $args['accepted_types'] : '*';
|
||||
$returntypes = isset($args['returntypes']) ? $args['returntypes'] : 3;
|
||||
|
||||
$params = array();
|
||||
@ -657,7 +655,8 @@ abstract class repository {
|
||||
}
|
||||
|
||||
$repositories = array();
|
||||
$ft = new file_type_to_ext();
|
||||
$ft = new filetype_parser();
|
||||
$accepted_types = $args['accepted_types'];
|
||||
foreach ($records as $record) {
|
||||
if (!file_exists($CFG->dirroot . '/repository/'. $record->repositorytype.'/repository.class.php')) {
|
||||
continue;
|
||||
@ -668,7 +667,6 @@ abstract class repository {
|
||||
$options['type'] = $record->repositorytype;
|
||||
$options['typeid'] = $record->typeid;
|
||||
// tell instance what file types will be accepted by file picker
|
||||
$options['accepted_types'] = $ft->get_file_ext($acceptedtypes);
|
||||
$classname = 'repository_' . $record->repositorytype;
|
||||
|
||||
$repository = new $classname($record->id, $record->contextid, $options, $record->readonly);
|
||||
@ -680,13 +678,13 @@ abstract class repository {
|
||||
debugging('parent::__construct must be called by '.$record->repositorytype.' plugin.');
|
||||
} else {
|
||||
// check mimetypes
|
||||
if ($acceptedtypes !== '*' and $repository->supported_filetypes() !== '*') {
|
||||
$acceptedtypes = $ft->get_file_ext($acceptedtypes);
|
||||
$supported_filetypes = $ft->get_file_ext($repository->supported_filetypes());
|
||||
if ($accepted_types !== '*' and $repository->supported_filetypes() !== '*') {
|
||||
$accepted_types = $ft->get_extensions($accepted_types);
|
||||
$supported_filetypes = $ft->get_extensions($repository->supported_filetypes());
|
||||
|
||||
$is_supported = false;
|
||||
foreach ($supported_filetypes as $type) {
|
||||
if (in_array($type, $acceptedtypes)) {
|
||||
if (in_array($type, $accepted_types)) {
|
||||
$is_supported = true;
|
||||
}
|
||||
}
|
||||
@ -711,7 +709,7 @@ abstract class repository {
|
||||
$capability = has_capability('repository/'.$record->repositorytype.':view', get_system_context());
|
||||
}
|
||||
if ($is_supported && $capability) {
|
||||
$repositories[] = $repository;
|
||||
$repositories[$repository->id] = $repository;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -794,13 +792,13 @@ abstract class repository {
|
||||
* @global object $DB
|
||||
* @global object $CFG
|
||||
* @global object $USER
|
||||
* @param string $path file path in download folder
|
||||
* @param string $filepath file path in download folder
|
||||
* @param string $name file name
|
||||
* @param integer $itemid item id to identify a file in filepool
|
||||
* @param string $filearea file area
|
||||
* @return array information of file in file pool
|
||||
*/
|
||||
public static function move_to_filepool($path, $name, $itemid, $filepath = '/', $filearea = 'user_draft') {
|
||||
public static function move_to_filepool($thefile, $name, $itemid, $filepath = '/', $filearea = 'user_draft') {
|
||||
global $DB, $CFG, $USER, $OUTPUT;
|
||||
if ($filepath !== '/') {
|
||||
$filepath = trim($filepath, '/');
|
||||
@ -816,7 +814,7 @@ abstract class repository {
|
||||
$entry->timecreated = $now;
|
||||
$entry->timemodified = $now;
|
||||
$entry->userid = $USER->id;
|
||||
$entry->mimetype = mimeinfo('type', $path);
|
||||
$entry->mimetype = mimeinfo('type', $thefile);
|
||||
if(is_numeric($itemid)) {
|
||||
$entry->itemid = $itemid;
|
||||
} else {
|
||||
@ -827,18 +825,18 @@ abstract class repository {
|
||||
if ($existingfile = $fs->get_file($context->id, $filearea, $itemid, $filepath, $name)) {
|
||||
$existingfile->delete();
|
||||
}
|
||||
if ($file = $fs->create_file_from_pathname($entry, $path)) {
|
||||
if ($file = $fs->create_file_from_pathname($entry, $thefile)) {
|
||||
if (empty($CFG->repository_no_delete)) {
|
||||
$delete = unlink($path);
|
||||
$delete = unlink($thefile);
|
||||
unset($CFG->repository_no_delete);
|
||||
}
|
||||
$ret = $browser->get_file_info($context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
|
||||
if(!empty($ret)) {
|
||||
$fileinfo = $browser->get_file_info($context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
|
||||
if(!empty($fileinfo)) {
|
||||
return array(
|
||||
'url'=>$ret->get_url(),
|
||||
'url'=>$fileinfo->get_url(),
|
||||
'id'=>$file->get_itemid(),
|
||||
'file'=>$file->get_filename(),
|
||||
'icon' => $OUTPUT->pix_url(file_extension_icon($path, 32))
|
||||
'icon' => $OUTPUT->pix_url(file_extension_icon($thefile, 32))
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
@ -1234,14 +1232,13 @@ abstract class repository {
|
||||
*/
|
||||
final public function get_meta() {
|
||||
global $CFG;
|
||||
$ft = new file_type_to_ext;
|
||||
$ft = new filetype_parser;
|
||||
$meta = new stdclass;
|
||||
$meta->id = $this->id;
|
||||
$meta->name = $this->get_name();
|
||||
$meta->type = $this->options['type'];
|
||||
$meta->icon = $CFG->httpswwwroot.'/repository/'.$meta->type.'/icon.png';
|
||||
$meta->supported_types = $ft->get_file_ext($this->supported_filetypes());
|
||||
$meta->accepted_types = $this->options['accepted_types'];
|
||||
$meta->supported_types = $ft->get_extensions($this->supported_filetypes());
|
||||
$meta->return_types = $this->supported_returntypes();
|
||||
return $meta;
|
||||
}
|
||||
@ -1420,8 +1417,8 @@ abstract class repository {
|
||||
public function filter(&$value) {
|
||||
$pass = false;
|
||||
$accepted_types = optional_param('accepted_types', '', PARAM_RAW);
|
||||
$ft = new file_type_to_ext;
|
||||
$ext = $ft->get_file_ext($this->supported_filetypes());
|
||||
$ft = new filetype_parser;
|
||||
$ext = $ft->get_extensions($this->supported_filetypes());
|
||||
if (isset($value['children'])) {
|
||||
$pass = true;
|
||||
if (!empty($value['children'])) {
|
||||
@ -1753,161 +1750,90 @@ function repository_setup_default_plugins() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads file picker Javascript files
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function repository_head_setup() {
|
||||
global $PAGE;
|
||||
|
||||
$PAGE->requires->yui2_lib('yahoo');
|
||||
$PAGE->requires->yui2_lib('dom');
|
||||
$PAGE->requires->yui2_lib('element');
|
||||
$PAGE->requires->yui2_lib('event');
|
||||
$PAGE->requires->yui2_lib('json');
|
||||
$PAGE->requires->yui2_lib('treeview');
|
||||
$PAGE->requires->yui2_lib('dragdrop');
|
||||
$PAGE->requires->yui2_lib('container');
|
||||
$PAGE->requires->yui2_lib('resize');
|
||||
$PAGE->requires->yui2_lib('layout');
|
||||
$PAGE->requires->yui2_lib('connection');
|
||||
$PAGE->requires->yui2_lib('button');
|
||||
$PAGE->requires->yui2_lib('selector');
|
||||
|
||||
//TODO: remove the ->in_head() once we refactor the inline script tags in repo code
|
||||
$PAGE->requires->js('repository/repository.src.js')->in_head();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return javascript to create file picker to browse repositories
|
||||
*
|
||||
* @global object $CFG
|
||||
* @global object $USER
|
||||
* @global object $PAGE
|
||||
* @global object $OUTPUT
|
||||
* @param object $context the context
|
||||
* @param string $id unique id for every file picker
|
||||
* @param string $accepted_filetypes
|
||||
* @param string $returntypes the return value of file picker
|
||||
* @return string
|
||||
*/
|
||||
function repository_get_client($context, $id = '', $accepted_filetypes = '*', $returntypes = 3) {
|
||||
function initialise_filepicker($args) {
|
||||
global $CFG, $USER, $PAGE, $OUTPUT;
|
||||
|
||||
$ft = new file_type_to_ext();
|
||||
$image_file_ext = json_encode($ft->get_file_ext(array('image')));
|
||||
$video_file_ext = json_encode($ft->get_file_ext(array('video')));
|
||||
$accepted_file_ext = json_encode($ft->get_file_ext($accepted_filetypes));
|
||||
|
||||
$js = '';
|
||||
if (!isset($CFG->filepickerjsloaded)) {
|
||||
$lang = array();
|
||||
$lang['title'] = get_string('title', 'repository');
|
||||
$lang['preview'] = get_string('preview', 'repository');
|
||||
$lang['add'] = get_string('add', 'repository');
|
||||
$lang['back'] = get_string('back', 'repository');
|
||||
$lang['cancel'] = get_string('cancel');
|
||||
$lang['close'] = get_string('close', 'repository');
|
||||
$lang['ccache'] = get_string('cleancache', 'repository');
|
||||
$lang['copying'] = get_string('copying', 'repository');
|
||||
$lang['downbtn'] = get_string('getfile', 'repository');
|
||||
$lang['download'] = get_string('downloadsucc', 'repository');
|
||||
$lang['date'] = get_string('date', 'repository').': ';
|
||||
$lang['error'] = get_string('error', 'repository');
|
||||
$lang['emptylist'] = get_string('emptylist', 'repository');
|
||||
$lang['filenotnull'] = get_string('filenotnull', 'repository');
|
||||
$lang['federatedsearch'] = get_string('federatedsearch', 'repository');
|
||||
$lang['help'] = get_string('help');
|
||||
$lang['refresh'] = get_string('refresh', 'repository');
|
||||
$lang['invalidjson'] = get_string('invalidjson', 'repository');
|
||||
$lang['listview'] = get_string('listview', 'repository');
|
||||
$lang['linkexternal'] = get_string('linkexternal', 'repository');
|
||||
$lang['login'] = get_string('login', 'repository');
|
||||
$lang['logout'] = get_string('logout', 'repository');
|
||||
$lang['loading'] = get_string('loading', 'repository');
|
||||
$lang['thumbview'] = get_string('thumbview', 'repository');
|
||||
$lang['title'] = get_string('title', 'repository');
|
||||
$lang['noresult'] = get_string('noresult', 'repository');
|
||||
$lang['mgr'] = get_string('manageurl', 'repository');
|
||||
$lang['noenter'] = get_string('noenter', 'repository');
|
||||
$lang['save'] = get_string('save', 'repository');
|
||||
$lang['saveas'] = get_string('saveas', 'repository').': ';
|
||||
$lang['saved'] = get_string('saved', 'repository');
|
||||
$lang['saving'] = get_string('saving', 'repository');
|
||||
$lang['size'] = get_string('size', 'repository').': ';
|
||||
$lang['sync'] = get_string('sync', 'repository');
|
||||
$lang['search'] = get_string('search', 'repository');
|
||||
$lang['searching'] = get_string('searching', 'repository');
|
||||
$lang['submit'] = get_string('submit', 'repository');
|
||||
$lang['preview'] = get_string('preview', 'repository');
|
||||
$lang['popup'] = get_string('popup', 'repository');
|
||||
$lang['upload'] = get_string('upload', 'repository').'...';
|
||||
$lang['uploading'] = get_string('uploading', 'repository');
|
||||
$lang['xhtml'] = get_string('xhtmlerror', 'repository');
|
||||
$lang = json_encode($lang);
|
||||
|
||||
$options = array();
|
||||
$sys_context = get_system_context();
|
||||
$options['contextid'] = $sys_context->id;
|
||||
$externallink = (int)get_config(null, 'repositoryallowexternallinks');
|
||||
if (empty($externallink)) {
|
||||
$options['externallink'] = false;
|
||||
} else {
|
||||
$options['externallink'] = true;
|
||||
}
|
||||
$options['icons']['loading'] = $OUTPUT->pix_url('i/loading');
|
||||
$options['icons']['logout'] = $OUTPUT->pix_url('a/logout');
|
||||
$options['icons']['help'] = $OUTPUT->pix_url('a/help');
|
||||
$options['icons']['progressbar'] = $OUTPUT->pix_url('i/progressbar');
|
||||
$options['icons']['search'] = $OUTPUT->pix_url('a/search');
|
||||
$options['icons']['setting'] = $OUTPUT->pix_url('a/setting');
|
||||
$options['icons']['refresh'] = $OUTPUT->pix_url('a/refresh');
|
||||
$options = json_encode($options);
|
||||
// fp_config includes filepicker options
|
||||
|
||||
$accepted_file_ext = json_encode($ft->get_file_ext($accepted_filetypes));
|
||||
$js .= <<<EOD
|
||||
<script type="text/javascript">
|
||||
var fp_lang = $lang;
|
||||
var fp_config = $options;
|
||||
MOODLE.repository.extensions.image = $image_file_ext;
|
||||
MOODLE.repository.extensions.media = $video_file_ext;
|
||||
</script>
|
||||
EOD;
|
||||
|
||||
$CFG->filepickerjsloaded = true;
|
||||
$ft = new filetype_parser();
|
||||
if (empty($args->context)) {
|
||||
$context = $PAGE->context;
|
||||
} else {
|
||||
// if yui and repository javascript libs are loaded
|
||||
$js = '';
|
||||
$context = $args->context;
|
||||
}
|
||||
$return = new stdclass;
|
||||
|
||||
$PAGE->requires->string_for_js('loading', 'repository');
|
||||
$PAGE->requires->string_for_js('title', 'repository');
|
||||
$PAGE->requires->string_for_js('preview', 'repository');
|
||||
$PAGE->requires->string_for_js('add', 'repository');
|
||||
$PAGE->requires->string_for_js('back', 'repository');
|
||||
$PAGE->requires->string_for_js('cancel', 'moodle');
|
||||
$PAGE->requires->string_for_js('close', 'repository');
|
||||
$PAGE->requires->string_for_js('cleancache', 'repository');
|
||||
$PAGE->requires->string_for_js('copying', 'repository');
|
||||
$PAGE->requires->string_for_js('getfile', 'repository');
|
||||
$PAGE->requires->string_for_js('downloadsucc', 'repository');
|
||||
$PAGE->requires->string_for_js('date', 'repository').': ';
|
||||
$PAGE->requires->string_for_js('error', 'repository');
|
||||
$PAGE->requires->string_for_js('emptylist', 'repository');
|
||||
$PAGE->requires->string_for_js('filenotnull', 'repository');
|
||||
$PAGE->requires->string_for_js('federatedsearch', 'repository');
|
||||
$PAGE->requires->string_for_js('help', 'moodle');
|
||||
$PAGE->requires->string_for_js('refresh', 'repository');
|
||||
$PAGE->requires->string_for_js('invalidjson', 'repository');
|
||||
$PAGE->requires->string_for_js('listview', 'repository');
|
||||
$PAGE->requires->string_for_js('linkexternal', 'repository');
|
||||
$PAGE->requires->string_for_js('login', 'repository');
|
||||
$PAGE->requires->string_for_js('logout', 'repository');
|
||||
$PAGE->requires->string_for_js('loading', 'repository');
|
||||
$PAGE->requires->string_for_js('iconview', 'repository');
|
||||
$PAGE->requires->string_for_js('title', 'repository');
|
||||
$PAGE->requires->string_for_js('noresult', 'repository');
|
||||
$PAGE->requires->string_for_js('manageurl', 'repository');
|
||||
$PAGE->requires->string_for_js('noenter', 'repository');
|
||||
$PAGE->requires->string_for_js('save', 'repository');
|
||||
$PAGE->requires->string_for_js('saveas', 'repository').': ';
|
||||
$PAGE->requires->string_for_js('saved', 'repository');
|
||||
$PAGE->requires->string_for_js('saving', 'repository');
|
||||
$PAGE->requires->string_for_js('size', 'repository').': ';
|
||||
$PAGE->requires->string_for_js('sync', 'repository');
|
||||
$PAGE->requires->string_for_js('search', 'repository');
|
||||
$PAGE->requires->string_for_js('searching', 'repository');
|
||||
$PAGE->requires->string_for_js('submit', 'repository');
|
||||
$PAGE->requires->string_for_js('preview', 'repository');
|
||||
$PAGE->requires->string_for_js('popup', 'repository');
|
||||
$PAGE->requires->string_for_js('upload', 'repository').'...';
|
||||
$PAGE->requires->string_for_js('uploading', 'repository');
|
||||
$PAGE->requires->string_for_js('xhtmlerror', 'repository');
|
||||
|
||||
// print instances listing
|
||||
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
if (is_array($accepted_filetypes) && in_array('*', $accepted_filetypes)) {
|
||||
$accepted_filetypes = '*';
|
||||
}
|
||||
$params = array();
|
||||
$params['context'] = array($user_context, get_system_context());
|
||||
$params['currentcontext'] = $context;
|
||||
$params['accepted_types'] = $accepted_filetypes;
|
||||
$params['returntypes'] = $returntypes;
|
||||
$repos = repository::get_instances($params);
|
||||
|
||||
// print repository instances listing
|
||||
$js .= <<<EOD
|
||||
<script type="text/javascript">
|
||||
MOODLE.repository.listing['$id'] = [];
|
||||
EOD;
|
||||
foreach ($repos as $repo) {
|
||||
$meta = $repo->get_meta();
|
||||
$js .= "\r\n";
|
||||
$js .= 'MOODLE.repository.listing[\''.$id.'\']['.$meta->id.']='.json_encode($meta).';';
|
||||
$js .= "\n";
|
||||
}
|
||||
$js .= "\r\n";
|
||||
$js .= "</script>";
|
||||
$externallink = (int)get_config(null, 'repositoryallowexternallinks');
|
||||
$repositories = repository::get_instances(array(
|
||||
'context'=>array($user_context, get_system_context()),
|
||||
'currentcontext'=> $context,
|
||||
'accepted_types'=>$args->accepted_types
|
||||
));
|
||||
|
||||
return $js;
|
||||
$return->repositories = array();
|
||||
|
||||
if (empty($externallink)) {
|
||||
$return->externallink = false;
|
||||
} else {
|
||||
$return->externallink = true;
|
||||
}
|
||||
|
||||
$return->pix = array();
|
||||
$return->pix['loading'] = $OUTPUT->pix_url('i/loading')->out();
|
||||
$return->pix['logout'] = $OUTPUT->pix_url('a/logout')->out();
|
||||
$return->pix['help'] = $OUTPUT->pix_url('a/help')->out();
|
||||
$return->pix['progressbar'] = $OUTPUT->pix_url('i/progressbar')->out();
|
||||
$return->pix['search'] = $OUTPUT->pix_url('a/search')->out();
|
||||
$return->pix['setting'] = $OUTPUT->pix_url('a/setting')->out();
|
||||
$return->pix['refresh'] = $OUTPUT->pix_url('a/refresh')->out();
|
||||
// provided by form element
|
||||
$return->accepted_types = $ft->get_extensions($args->accepted_types);
|
||||
foreach ($repositories as $repository) {
|
||||
$meta = $repository->get_meta();
|
||||
$return->repositories[$repository->id] = $meta;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -29,10 +29,12 @@
|
||||
require_once('../config.php');
|
||||
require_once('../lib/filelib.php');
|
||||
require_once('lib.php');
|
||||
|
||||
require_login();
|
||||
|
||||
/// Parameters
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
$repo_id = optional_param('repo_id', 1, PARAM_INT); // repository ID
|
||||
$callback = optional_param('callback', '', PARAM_CLEANHTML);
|
||||
$client_id = optional_param('client_id', SITEID, PARAM_RAW); // client ID
|
||||
$contextid = optional_param('ctx_id', SITEID, PARAM_INT); // context ID
|
||||
@ -41,12 +43,11 @@
|
||||
$itemid = optional_param('itemid', '', PARAM_INT);
|
||||
$title = optional_param('title', '', PARAM_FILE); // new file name
|
||||
$page = optional_param('page', '', PARAM_RAW); // page
|
||||
$repo_id = optional_param('repo_id', 1, PARAM_INT); // repository ID
|
||||
$maxbytes = optional_param('maxbytes', -1, PARAM_INT); // repository ID
|
||||
$req_path = optional_param('p', '', PARAM_RAW); // path
|
||||
$save_path = optional_param('savepath', '/', PARAM_PATH);
|
||||
$search_text = optional_param('s', '', PARAM_CLEANHTML);
|
||||
$link_external = optional_param('link_external', '', PARAM_ALPHA);
|
||||
$linkexternal = optional_param('linkexternal', '', PARAM_ALPHA);
|
||||
|
||||
/// Headers to make it not cacheable
|
||||
header("Cache-Control: no-cache, must-revalidate");
|
||||
@ -135,7 +136,7 @@
|
||||
<html><head>
|
||||
<script type="text/javascript">
|
||||
if(window.opener){
|
||||
window.opener.repository_callback($repo_id);
|
||||
active_filepicker.list();
|
||||
window.close();
|
||||
} else {
|
||||
alert("{$strhttpsbug }");
|
||||
@ -143,7 +144,7 @@ if(window.opener){
|
||||
</script>
|
||||
<body>
|
||||
<noscript>
|
||||
{$strrefreshnonjs}
|
||||
{$strrefreshnonjs}
|
||||
</noscript>
|
||||
</body>
|
||||
</html>
|
||||
@ -156,6 +157,7 @@ EOD;
|
||||
/// These actions all occur on the currently active repository instance
|
||||
switch ($action) {
|
||||
case 'sign':
|
||||
case 'signin':
|
||||
case 'list':
|
||||
if ($repo->check_login()) {
|
||||
try {
|
||||
@ -195,10 +197,10 @@ EOD;
|
||||
break;
|
||||
case 'search':
|
||||
try {
|
||||
$search_result = $repo->search($search_text);
|
||||
$search_result['search_result'] = true;
|
||||
$search_result = $repo->search($search_text, (int)$page);
|
||||
$search_result['client_id'] = $client_id;
|
||||
$search_result['repo_id'] = $repo_id;
|
||||
$search_result['search_result'] = true;
|
||||
echo json_encode($search_result);
|
||||
} catch (repository_exception $e) {
|
||||
$err->e = $e->getMessage();
|
||||
@ -232,14 +234,13 @@ EOD;
|
||||
// allow external links in url element all the time
|
||||
$allowexternallink = ($allowexternallink || ($env == 'url'));
|
||||
|
||||
if ($allowexternallink and $link_external === 'yes' and ($repo->supported_returntypes() || FILE_EXTERNAL)) {
|
||||
if ($allowexternallink and $linkexternal === 'yes' and ($repo->supported_returntypes() || FILE_EXTERNAL)) {
|
||||
try {
|
||||
$link = $repo->get_link($file);
|
||||
} catch (repository_exception $e){
|
||||
}
|
||||
$info = array();
|
||||
$info['client_id'] = $client_id;
|
||||
$info['file'] = $title;
|
||||
$info['filename'] = $title;
|
||||
$info['type'] = 'link';
|
||||
$info['url'] = $link;
|
||||
die(json_encode($info));
|
||||
@ -255,7 +256,9 @@ EOD;
|
||||
throw new file_exception('maxbytes');
|
||||
}
|
||||
$info = repository::move_to_filepool($filepath, $title, $itemid, $save_path);
|
||||
$info['client_id'] = $client_id;
|
||||
if (empty($info)) {
|
||||
$info['e'] = get_string('error', 'moodle');
|
||||
}
|
||||
echo json_encode($info);
|
||||
} catch (repository_exception $e){
|
||||
$err->e = $e->getMessage();
|
||||
|
Loading…
x
Reference in New Issue
Block a user