Skip to content

Commit

Permalink
"MDL-20602, add support for FILE_INTERNAL and FILE_EXTERNAL"
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongsheng Cai committed Nov 2, 2009
1 parent 95b320e commit 41076c5
Show file tree
Hide file tree
Showing 21 changed files with 164 additions and 118 deletions.
3 changes: 3 additions & 0 deletions repository/alfresco/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,8 @@ public static function plugin_init() {
return true;
}
}
public function supported_returntypes() {
return FILE_INTERNAL | FILE_EXTERNAL;
}
}

3 changes: 3 additions & 0 deletions repository/boxnet/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,8 @@ public function type_config_form(&$mform) {
$mform->addRule('api_key', $strrequired, 'required', null, 'client');
$mform->addElement('static', null, '', get_string('information','repository_boxnet'));
}
public function supported_returntypes() {
return FILE_INTERNAL | FILE_EXTERNAL;
}
}

5 changes: 4 additions & 1 deletion repository/draft/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function get_listing($path = '/', $page = '') {
* @param string $itemid
* @return string the location of the file
*/
public function get_file($fid, $title = '', $itemid = '') {
public function move_to_draft($fid, $title = '', $itemid = '') {
global $USER;
$ret = array();
$browser = get_file_browser();
Expand All @@ -100,5 +100,8 @@ public function get_file($fid, $title = '', $itemid = '') {
public function get_name(){
return get_string('repositoryname', 'repository_draft');;
}
public function supported_returntypes() {
return (FILE_INTERNAL | FILE_EXTERNAL);
}
}

3 changes: 3 additions & 0 deletions repository/filesystem/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,7 @@ public function instance_config_form(&$mform) {
}
$mform->addElement('static', null, '', get_string('information','repository_filesystem'));
}
public function supported_returntypes() {
return FILE_INTERNAL;
}
}
3 changes: 3 additions & 0 deletions repository/flickr/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,7 @@ public static function get_type_option_names() {
public function supported_filetypes() {
return array('web_image');
}
public function supported_returntypes() {
return (FILE_INTERNAL | FILE_EXTERNAL);
}
}
8 changes: 1 addition & 7 deletions repository/flickr_public/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ function __construct($img) {
default:
break;
}
if (empty($this->image)) {
throw new moodle_exception('invalidimage');
}
$this->width = imagesx($this->image);
$this->height = imagesy($this->image);
}
Expand Down Expand Up @@ -103,10 +100,7 @@ function resize($w, $h, $use_resize = true) {
return $this;
}

function saveas($imagepath='') {
if (empty($imagepath)) {
$imagepath = $this->imagepath;
}
function saveas($imagepath) {
switch($this->info['mime']) {
case 'image/jpeg':
return imagejpeg($this->image, $imagepath);
Expand Down
11 changes: 9 additions & 2 deletions repository/flickr_public/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,13 @@ public function get_file($photo_id, $file = '') {
$c->download(array(array('url'=>$url, 'file'=>$fp)));

$watermark = get_config('flickr_public', 'watermark');
if (!empty($watermark)) {
if ($watermark === 'on') {
$img = new moodle_image($path);
$img->watermark($url, array(10,10), array('ttf'=>true, 'fontsize'=>9))->saveas($path);
$pathinfo = pathinfo($path);
$newpath = $pathinfo['dirname'] . '/wm_' . $pathinfo['basename'];
$img->watermark($url, array(10,10), array('ttf'=>true, 'fontsize'=>9))->saveas($newpath);
unlink($path);
$path = $newpath;
}
return $path;
}
Expand Down Expand Up @@ -451,4 +455,7 @@ public static function plugin_init() {
public function supported_filetypes() {
return array('web_image');
}
public function supported_returntypes() {
return (FILE_INTERNAL | FILE_EXTERNAL);
}
}
11 changes: 7 additions & 4 deletions repository/googledocs/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ public function get_file($url, $file) {
$gdocs->download_file($url, $fp);

return $path;
}
}

public function supported_filetypes() {
return array('document');
}
public function supported_filetypes() {
return array('document');
}
public function supported_returntypes() {
return FILE_INTERNAL;
}
}
//Icon from: http://www.iconspedia.com/icon/google-2706.html
67 changes: 30 additions & 37 deletions repository/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once($CFG->libdir . '/filelib.php');
require_once($CFG->libdir . '/formslib.php');

define('FILE_EXTERNAL', 1);
define('FILE_INTERNAL', 2);


// File picker javascript code

/**
Expand Down Expand Up @@ -398,7 +403,7 @@ public function delete() {
global $DB;

//delete all instances of this type
$instances = repository::get_instances(array(),null,false,$this->_typename);
$instances = repository::get_instances(array(), null, false, $this->_typename);
foreach ($instances as $instance) {
$instance->delete();
}
Expand Down Expand Up @@ -444,6 +449,7 @@ abstract class repository {
public $context;
public $options;
public $readonly;
public $returntypes;

/**
* Return a type for a given type name.
Expand Down Expand Up @@ -569,7 +575,7 @@ public static function get_editable_types($context = null) {
* @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 = '*', $returnvalue = '*') {
public static function get_instances($contexts=array(), $userid = null, $onlyvisible = true, $type=null, $accepted_types = '*', $returntypes = 3) {
global $DB, $CFG, $USER;

$params = array();
Expand Down Expand Up @@ -637,13 +643,12 @@ public static function get_instances($contexts=array(), $userid = null, $onlyvis
}
}
}
if ($returnvalue !== '*' and $repository->supported_return_value() !== '*') {
$tmp = $repository->supported_return_value();
if ($tmp != $returnvalue) {
if ($returnvalue == 'link' && $repository->supported_external_link()) {
} else {
$is_supported = false;
}
if ($returntypes !== 3 and $repository->supported_returntypes() !== 3) {
$type = $repository->supported_returntypes();
if ($type & $returntypes) {
//
} else {
$is_supported = false;
}
}
if (!$onlyvisible || ($repository->is_visible() && !$repository->disabled)) {
Expand Down Expand Up @@ -1014,7 +1019,7 @@ public static function display_instances_list($context, $typename = null) {
//instances of a type, even if this type is not visible. In course/user context we
//want to display only visible instances, but for every type types. The repository::get_instances()
//third parameter displays only visible type.
$instances = repository::get_instances(array($context),null,!$admin,$typename);
$instances = repository::get_instances(array($context), null, !$admin, $typename);
$instancesnumber = count($instances);
$alreadyplugins = array();

Expand Down Expand Up @@ -1111,6 +1116,7 @@ public function __construct($repositoryid, $contextid = SITEID, $options = array
$this->options[$n] = $v;
}
$this->name = $this->get_name();
$this->returntypes = $this->supported_returntypes();
$this->super_called = true;
}

Expand Down Expand Up @@ -1148,15 +1154,11 @@ public function prepare_file($filename) {
*/
public function get_file($url, $filename = '') {
global $CFG;
if (!empty($CFG->repositoryuseexternallink) && $this->supported_external_link()) {
return $url;
} else {
$path = $this->prepare_file($filename);
$fp = fopen($path, 'w');
$c = new curl;
$c->download(array(array('url'=>$url, 'file'=>$fp)));
return $path;
}
$path = $this->prepare_file($filename);
$fp = fopen($path, 'w');
$c = new curl;
$c->download(array(array('url'=>$url, 'file'=>$fp)));
return $path;
}

/**
Expand Down Expand Up @@ -1214,17 +1216,8 @@ public function supported_filetypes() {
* does it return a file url or a item_id
* @return string
*/
public function supported_return_value() {
// return 'link';
// return 'ref_id';
return 'ref_id';
}
/**
* does it return a file url or a item_id
* @return string
*/
public function supported_external_link() {
return false;
public function supported_returntypes() {
return (FILE_INTERNAL | FILE_EXTERNAL);
}

/**
Expand Down Expand Up @@ -1781,10 +1774,10 @@ function repository_head_setup() {
* @param object $context the context
* @param string $id unique id for every file picker
* @param string $accepted_filetypes
* @param string $returnvalue the return value of file picker
* @param string $returntypes the return value of file picker
* @return array
*/
function repository_get_client($context, $id = '', $accepted_filetypes = '*', $returnvalue = '*') {
function repository_get_client($context, $id = '', $accepted_filetypes = '*', $returntypes = 3) {
global $CFG, $USER, $PAGE, $OUTPUT;

$ft = new file_type_to_ext();
Expand Down Expand Up @@ -1856,8 +1849,8 @@ function repository_get_client($context, $id = '', $accepted_filetypes = '*', $
<script type="text/javascript">
var fp_lang = $lang;
var fp_config = $options;
file_extensions.image = $image_file_ext;
file_extensions.media = $video_file_ext;
MOODLE.repository.extensions.image = $image_file_ext;
MOODLE.repository.extensions.media = $video_file_ext;
</script>
EOD;

Expand All @@ -1872,17 +1865,17 @@ function repository_get_client($context, $id = '', $accepted_filetypes = '*', $
if (is_array($accepted_filetypes) && in_array('*', $accepted_filetypes)) {
$accepted_filetypes = '*';
}
$repos = repository::get_instances(array($user_context, $context, get_system_context()), null, true, null, $accepted_filetypes, $returnvalue);
$repos = repository::get_instances(array($user_context, $context, get_system_context()), null, true, null, $accepted_filetypes, $returntypes);

// print repository instances listing
$js .= <<<EOD
<script type="text/javascript">
repository_listing['$id'] = [];
MOODLE.repository.listing['$id'] = [];
EOD;
foreach ($repos as $repo) {
$meta = $repo->get_meta();
$js .= "\r\n";
$js .= 'repository_listing[\''.$id.'\']['.$meta->id.']='.json_encode($meta).';';
$js .= 'MOODLE.repository.listing[\''.$id.'\']['.$meta->id.']='.json_encode($meta).';';
$js .= "\n";
}
$js .= "\r\n";
Expand Down
5 changes: 4 additions & 1 deletion repository/local/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function get_listing($encodedpath = '', $page = '') {
* @return array The metainfo of file
* @see curl package
*/
public function get_file($encoded, $title = '', $itemid = '', $save_path = '/') {
public function move_to_draft($encoded, $title = '', $itemid = '', $save_path = '/') {
global $USER, $DB;
$ret = array();

Expand Down Expand Up @@ -158,5 +158,8 @@ public function get_file($encoded, $title = '', $itemid = '', $save_path = '/')
public function get_name(){
return get_string('repositoryname', 'repository_local');;
}
public function supported_returntypes() {
return FILE_INTERNAL;
}
}

3 changes: 3 additions & 0 deletions repository/mahara/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,8 @@ public static function get_instance_option_names() {
///the administrator just need to set a peer
return array('peer');
}
public function supported_returntypes() {
return FILE_INTERNAL;
}
}

3 changes: 3 additions & 0 deletions repository/picasa/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public function get_name(){
public function supported_filetypes() {
return array('web_image');
}
public function supported_returntypes() {
return (FILE_INTERNAL | FILE_EXTERNAL);
}
}

// Icon for this plugin retrieved from http://www.iconspedia.com/icon/picasa-2711.html
Expand Down
3 changes: 3 additions & 0 deletions repository/remotemoodle/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,8 @@ public static function get_instance_option_names() {
///the administrator just need to set a peer
return array('peer');
}
public function supported_returntypes() {
return FILE_INTERNAL;
}
}

Loading

0 comments on commit 41076c5

Please sign in to comment.