From 1d94557373e0771b24a7b2fcaffc0b8861c9c8a1 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Thu, 18 Jul 2013 14:29:13 +1000 Subject: [PATCH] MDL-28019 Added plugin repository_areafiles --- lib/pluginlib.php | 2 +- repository/areafiles/db/access.php | 36 +++++ repository/areafiles/db/install.php | 34 +++++ .../lang/en/repository_areafiles.php | 28 ++++ repository/areafiles/lib.php | 135 ++++++++++++++++++ repository/areafiles/pix/icon.gif | Bin 0 -> 136 bytes repository/areafiles/version.php | 29 ++++ 7 files changed, 263 insertions(+), 1 deletion(-) create mode 100644 repository/areafiles/db/access.php create mode 100644 repository/areafiles/db/install.php create mode 100644 repository/areafiles/lang/en/repository_areafiles.php create mode 100644 repository/areafiles/lib.php create mode 100644 repository/areafiles/pix/icon.gif create mode 100644 repository/areafiles/version.php diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 70c977eb316..c877372cf11 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -810,7 +810,7 @@ class plugin_manager { ), 'repository' => array( - 'alfresco', 'boxnet', 'coursefiles', 'dropbox', 'equella', 'filesystem', + 'alfresco', 'areafiles', 'boxnet', 'coursefiles', 'dropbox', 'equella', 'filesystem', 'flickr', 'flickr_public', 'googledocs', 'local', 'merlot', 'picasa', 'recent', 'skydrive', 's3', 'upload', 'url', 'user', 'webdav', 'wikimedia', 'youtube' diff --git a/repository/areafiles/db/access.php b/repository/areafiles/db/access.php new file mode 100644 index 00000000000..24f7bf46efe --- /dev/null +++ b/repository/areafiles/db/access.php @@ -0,0 +1,36 @@ +. + +/** + * Plugin capabilities for repository_areafiles + * + * @package repository_areafiles + * @copyright 2013 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$capabilities = array( + + 'repository/areafiles:view' => array( + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'archetypes' => array( + 'user' => CAP_ALLOW + ) + ) +); diff --git a/repository/areafiles/db/install.php b/repository/areafiles/db/install.php new file mode 100644 index 00000000000..bfb6e4ea2b6 --- /dev/null +++ b/repository/areafiles/db/install.php @@ -0,0 +1,34 @@ +. + +/** + * Creating a default instance of areafiles repository on install + * + * @package repository_areafiles + * @copyright 2013 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +function xmldb_repository_areafiles_install() { + global $CFG; + $result = true; + require_once($CFG->dirroot.'/repository/lib.php'); + $areafiles_plugin = new repository_type('areafiles', array(), true); + if(!$id = $areafiles_plugin->create(true)) { + $result = false; + } + return $result; +} diff --git a/repository/areafiles/lang/en/repository_areafiles.php b/repository/areafiles/lang/en/repository_areafiles.php new file mode 100644 index 00000000000..2e946e07521 --- /dev/null +++ b/repository/areafiles/lang/en/repository_areafiles.php @@ -0,0 +1,28 @@ +. + +/** + * Strings for component 'repository_areafiles' + * + * @package repository_areafiles + * @copyright 2013 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['areafiles:view'] = 'View repository Embedded files'; +$string['configplugin'] = 'Configuration for repository Embedded files'; +$string['pluginname_help'] = 'Files embedded in the current text editor'; +$string['pluginname'] = 'Embedded files'; diff --git a/repository/areafiles/lib.php b/repository/areafiles/lib.php new file mode 100644 index 00000000000..bce6e3895f4 --- /dev/null +++ b/repository/areafiles/lib.php @@ -0,0 +1,135 @@ +. + +/** + * Class repository_areafiles + * + * @package repository_areafiles + * @copyright 2013 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->dirroot . '/repository/lib.php'); + +/** + * Main class responsible for files listing in repostiory_areafiles + * + * @package repository_areafiles + * @copyright 2013 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class repository_areafiles extends repository { + /** + * Areafiles plugin doesn't require login, so list all files + * + * @return mixed + */ + public function print_login() { + return $this->get_listing(); + } + + /** + * Get file listing + * + * @param string $path + * @param string $path not used by this plugin + * @return mixed + */ + public function get_listing($path = '', $page = '') { + global $USER, $OUTPUT; + $itemid = optional_param('itemid', 0, PARAM_INT); + $env = optional_param('env', 'filepicker', PARAM_ALPHA); + $ret = array( + 'dynload' => true, + 'nosearch' => true, + 'nologin' => true, + 'list' => array(), + ); + if (empty($itemid) || $env !== 'editor') { + return $ret; + } + + // In the most cases files embedded in textarea do not have subfolders. Do not show path by default. + $retpath = array(array('name' => get_string('files'), 'path' => '')); + if (!empty($path)) { + $pathchunks = preg_split('|/|', trim($path, '/')); + foreach ($pathchunks as $i => $chunk) { + $retpath[] = array( + 'name' => $chunk, + 'path' => '/'. join('/', array_slice($pathchunks, 0, $i + 1)). '/' + ); + } + $ret['path'] = $retpath; // Show path if already inside subfolder. + } + + $context = context_user::instance($USER->id); + $fs = get_file_storage(); + $files = $fs->get_directory_files($context->id, 'user', 'draft', $itemid, + empty($path) ? '/' : $path, false, true); + foreach ($files as $file) { + if ($file->is_directory()) { + $node = array( + 'title' => basename($file->get_filepath()), + 'path' => $file->get_filepath(), + 'children' => array(), + 'datemodified' => $file->get_timemodified(), + 'datecreated' => $file->get_timecreated(), + 'icon' => $OUTPUT->pix_url(file_folder_icon(24))->out(false), + 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false) + ); + $ret['list'][] = $node; + $ret['path'] = $retpath; // Show path if subfolders exist. + continue; + } + $fileurl = moodle_url::make_draftfile_url($itemid, $file->get_filepath(), $file->get_filename()); + $node = array( + 'title' => $file->get_filename(), + 'size' => $file->get_filesize(), + 'source' => $fileurl->out(), + 'datemodified' => $file->get_timemodified(), + 'datecreated' => $file->get_timecreated(), + 'author' => $file->get_author(), + 'license' => $file->get_license(), + 'isref' => $file->is_external_file(), + 'icon' => $OUTPUT->pix_url(file_file_icon($file, 24))->out(false), + 'thumbnail' => $OUTPUT->pix_url(file_file_icon($file, 90))->out(false) + ); + if ($file->get_status() == 666) { + $node['originalmissing'] = true; + } + if ($imageinfo = $file->get_imageinfo()) { + $node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $file->get_timemodified())); + $node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified())); + $node['image_width'] = $imageinfo['width']; + $node['image_height'] = $imageinfo['height']; + } + $ret['list'][] = $node; + } + $ret['list'] = array_filter($ret['list'], array($this, 'filter')); + return $ret; + } + + /** + * This plugin only can return link + * + * @return int + */ + public function supported_returntypes() { + return FILE_EXTERNAL; + } +} \ No newline at end of file diff --git a/repository/areafiles/pix/icon.gif b/repository/areafiles/pix/icon.gif new file mode 100644 index 0000000000000000000000000000000000000000..47264984e6a0b8a7351fa01d4a45f7097c47f14d GIT binary patch literal 136 zcmV;30C)dKNk%w1VGsZi0HOu}|NsBY%*-=0Gk}1A{{R5Mz`+0i{{R30A^8LW000I6 zEC2ui01yBW0009`Xu8z-jF92 q%ZAfwc%6U}Xe4!rMWJ%K4DL)=>k&w;HnG`eWlXLZW$5%Q0RTJM$u_3| literal 0 HcmV?d00001 diff --git a/repository/areafiles/version.php b/repository/areafiles/version.php new file mode 100644 index 00000000000..fb7ec4d8a03 --- /dev/null +++ b/repository/areafiles/version.php @@ -0,0 +1,29 @@ +. + +/** + * Version information for plugin repository_areafiles + * + * @package repository_areafiles + * @copyright 2013 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->version = 2013061200; // The current plugin version (Date: YYYYMMDDXX) +$plugin->requires = 2012062500; // Requires this Moodle version (Moodle 2.3 - 2.5) +$plugin->component = 'repository_areafiles'; // Full name of the plugin (used for diagnostics)