├── pix └── icon.gif ├── README.md ├── lang └── en │ └── repository_areafiles.php ├── db ├── access.php └── install.php ├── version.php └── lib.php /pix/icon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-repository_areafiles/master/pix/icon.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | "Embedded files" (repository_areafiles) plugin allows to re-use the files 2 | embedded in the current text area. 3 | 4 | By default it can be accessed by all users but admin is able to limit it. 5 | 6 | To install: copy folder areafiles to /repository/, login as admin and 7 | run upgrade script. 8 | 9 | To use: Open any form with textarea in HTML mode, insert an image using 10 | filepicker as usual. Click "insert/edit image" again and in filepicker window 11 | select repository "Embedded files". The list of all files used in this textarea 12 | will appear and user can re-use any of them. 13 | 14 | You can insert media and/or links to other files as well. Note that files in 15 | filepicker are always filtered by the accepted file types (for example when 16 | you add an image you will only see images even when other files present in area). -------------------------------------------------------------------------------- /lang/en/repository_areafiles.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Strings for component 'repository_areafiles' 19 | * 20 | * @package repository_areafiles 21 | * @copyright 2013 Marina Glancy 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | $string['areafiles:view'] = 'View repository Embedded files'; 26 | $string['configplugin'] = 'Configuration for repository Embedded files'; 27 | $string['pluginname_help'] = 'Files embedded in the current text editor'; 28 | $string['pluginname'] = 'Embedded files'; 29 | -------------------------------------------------------------------------------- /db/access.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Plugin capabilities for repository_areafiles 19 | * 20 | * @package repository_areafiles 21 | * @copyright 2013 Marina Glancy 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | $capabilities = array( 28 | 29 | 'repository/areafiles:view' => array( 30 | 'captype' => 'read', 31 | 'contextlevel' => CONTEXT_MODULE, 32 | 'archetypes' => array( 33 | 'user' => CAP_ALLOW 34 | ) 35 | ) 36 | ); 37 | -------------------------------------------------------------------------------- /db/install.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Creating a default instance of areafiles repository on install 19 | * 20 | * @package repository_areafiles 21 | * @copyright 2013 Marina Glancy 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | function xmldb_repository_areafiles_install() { 26 | global $CFG; 27 | $result = true; 28 | require_once($CFG->dirroot.'/repository/lib.php'); 29 | $areafiles_plugin = new repository_type('areafiles', array(), true); 30 | if(!$id = $areafiles_plugin->create(true)) { 31 | $result = false; 32 | } 33 | return $result; 34 | } 35 | -------------------------------------------------------------------------------- /version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version information for plugin repository_areafiles 19 | * 20 | * @package repository_areafiles 21 | * @copyright 2013 Marina Glancy 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | $plugin->version = 2013061200; // The current plugin version (Date: YYYYMMDDXX) 28 | $plugin->requires = 2012062500; // Requires this Moodle version (Moodle 2.3 - 2.5) 29 | $plugin->release = "1.1 for M2.3+"; 30 | $plugin->maturity = MATURITY_STABLE; 31 | $plugin->component = 'repository_areafiles'; // Full name of the plugin (used for diagnostics) 32 | -------------------------------------------------------------------------------- /lib.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Class repository_areafiles 19 | * 20 | * @package repository_areafiles 21 | * @copyright 2013 Marina Glancy 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | require_once($CFG->dirroot . '/repository/lib.php'); 28 | 29 | /** 30 | * Main class responsible for files listing in repostiory_areafiles 31 | * 32 | * @package repository_areafiles 33 | * @copyright 2013 Marina Glancy 34 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 | */ 36 | class repository_areafiles extends repository { 37 | /** 38 | * Areafiles plugin doesn't require login, so list all files 39 | * 40 | * @return mixed 41 | */ 42 | public function print_login() { 43 | return $this->get_listing(); 44 | } 45 | 46 | /** 47 | * Get file listing 48 | * 49 | * @param string $path 50 | * @param string $path not used by this plugin 51 | * @return mixed 52 | */ 53 | public function get_listing($path = '', $page = '') { 54 | global $USER, $OUTPUT; 55 | $itemid = optional_param('itemid', 0, PARAM_INT); 56 | $env = optional_param('env', 'filepicker', PARAM_ALPHA); 57 | $ret = array( 58 | 'dynload' => true, 59 | 'nosearch' => true, 60 | 'nologin' => true, 61 | 'list' => array(), 62 | ); 63 | if (empty($itemid) || $env !== 'editor') { 64 | return $ret; 65 | } 66 | 67 | $context = context_user::instance($USER->id); 68 | $fs = get_file_storage(); 69 | $files = $fs->get_directory_files($context->id, 'user', 'draft', $itemid, '/'); 70 | foreach ($files as $file) { 71 | if ($file->is_directory()) { 72 | // Files embedded in texteditor do not support subfolders 73 | continue; 74 | } 75 | $fileurl = moodle_url::make_draftfile_url($itemid, $file->get_filepath(), $file->get_filename()); 76 | $node = array( 77 | 'title' => $file->get_filename(), 78 | 'size' => $file->get_filesize(), 79 | 'source' => $fileurl->out(), 80 | 'datemodified' => $file->get_timemodified(), 81 | 'datecreated' => $file->get_timecreated(), 82 | 'author' => $file->get_author(), 83 | 'license' => $file->get_license(), 84 | 'isref' => $file->is_external_file(), 85 | 'icon' => $OUTPUT->pix_url(file_file_icon($file, 24))->out(false), 86 | 'thumbnail' => $OUTPUT->pix_url(file_file_icon($file, 90))->out(false) 87 | ); 88 | if ($file->get_status() == 666) { 89 | $node['originalmissing'] = true; 90 | } 91 | if ($imageinfo = $file->get_imageinfo()) { 92 | $node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $file->get_timemodified())); 93 | $node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified())); 94 | $node['image_width'] = $imageinfo['width']; 95 | $node['image_height'] = $imageinfo['height']; 96 | } 97 | $ret['list'][] = $node; 98 | } 99 | $ret['list'] = array_filter($ret['list'], array($this, 'filter')); 100 | return $ret; 101 | } 102 | 103 | /** 104 | * This plugin only can return link 105 | * 106 | * @return int 107 | */ 108 | public function supported_returntypes() { 109 | return FILE_EXTERNAL; 110 | } 111 | } --------------------------------------------------------------------------------