diff --git a/lib/boxlib.php b/lib/boxlib.php index e1e8387516a49..a647223209906 100644 --- a/lib/boxlib.php +++ b/lib/boxlib.php @@ -188,29 +188,6 @@ function getfiletree($path, $params = array()) { return $ret; } - /** - * Get box.net file info - * - * @param string $fileid - * @return string|null - */ - function get_file_info($fileid) { - $this->_clearErrors(); - $params = array(); - $params['action'] = 'get_file_info'; - $params['file_id'] = $fileid; - $params['auth_token'] = $this->auth_token; - $params['api_key'] = $this->api_key; - $http = new curl(array('debug'=>$this->debug, 'cache'=>true, 'module_cache'=>'repository')); - $xml = $http->get($this->_box_api_url, $params); - $o = simplexml_load_string(trim($xml)); - if ($o->status == 's_get_file_info') { - return $o->info; - } else { - return null; - } - } - /** * @param array $sax * @param array $tree Passed by reference diff --git a/lib/filelib.php b/lib/filelib.php index d9501552c389b..62a21df96bc58 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -770,7 +770,6 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea $newhashes = array(); foreach ($draftfiles as $file) { $newhash = $fs->get_pathname_hash($contextid, $component, $filearea, $itemid, $file->get_filepath(), $file->get_filename()); - file_restore_source_field_from_draft_file($file); $newhashes[$newhash] = $file; } $filecount = 0; @@ -791,6 +790,7 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea continue; } + file_restore_source_field_from_draft_file($newfile); // Replaced file content if ($oldfile->get_contenthash() != $newfile->get_contenthash()) { $oldfile->replace_content_with($newfile); diff --git a/repository/boxnet/lib.php b/repository/boxnet/lib.php index f6ac9fb99b562..d4102d3d3f0dc 100644 --- a/repository/boxnet/lib.php +++ b/repository/boxnet/lib.php @@ -293,23 +293,6 @@ public function get_reference_details($reference) { return $this->get_name() . ': ' . $reference; } - /** - * Return the source information - * - * @param stdClass $url - * @return string|null - */ - public function get_file_source_info($url) { - $array = explode('/', $url); - $fileid = array_pop($array); - $fileinfo = $this->boxclient->get_file_info($fileid); - if (!empty($fileinfo)) { - return 'Box:' . (string)$fileinfo->file_name; - } else { - return $url; - } - } - /** * Repository method to serve file * diff --git a/repository/dropbox/lib.php b/repository/dropbox/lib.php index c9960e45cfd6b..e454615a067c2 100644 --- a/repository/dropbox/lib.php +++ b/repository/dropbox/lib.php @@ -414,16 +414,6 @@ public function get_reference_details($reference) { return $this->get_name() . ': ' . $ref->path; } - /** - * Return the source information - * - * @param stdClass $filepath - * @return string|null - */ - public function get_file_source_info($filepath) { - return 'Dropbox:' . $filepath; - } - /** * Repository method to serve file * diff --git a/repository/filesystem/lib.php b/repository/filesystem/lib.php index e0d9c098a15fc..58eddbe121e38 100644 --- a/repository/filesystem/lib.php +++ b/repository/filesystem/lib.php @@ -152,16 +152,6 @@ public function get_file($file, $title = '') { return array('path'=>$file, 'url'=>''); } - /** - * Return the source information - * - * @param stdClass $filepath - * @return string|null - */ - public function get_file_source_info($filepath) { - return $filepath; - } - public function logout() { return true; } diff --git a/repository/flickr/lib.php b/repository/flickr/lib.php index 688663899a382..b54ad931f2763 100644 --- a/repository/flickr/lib.php +++ b/repository/flickr/lib.php @@ -222,13 +222,9 @@ public function get_listing($path = '', $page = '') { return $this->search('', $page); } - /** - * Return photo url by given photo id - * @param string $photoid - * @return string - */ - private function build_photo_url($photoid) { - $result = $this->flickr->photos_getSizes($photoid); + public function get_link($photo_id) { + global $CFG; + $result = $this->flickr->photos_getSizes($photo_id); $url = ''; if(!empty($result[4])) { $url = $result[4]['source']; @@ -240,18 +236,23 @@ private function build_photo_url($photoid) { return $url; } - public function get_link($photoid) { - return $this->build_photo_url($photoid); - } - /** * - * @param string $photoid + * @param string $photo_id * @param string $file * @return string */ - public function get_file($photoid, $file = '') { - $url = $this->build_photo_url($photoid); + public function get_file($photo_id, $file = '') { + global $CFG; + $result = $this->flickr->photos_getSizes($photo_id); + $url = ''; + if(!empty($result[4])) { + $url = $result[4]['source']; + } elseif(!empty($result[3])) { + $url = $result[3]['source']; + } elseif(!empty($result[2])) { + $url = $result[2]['source']; + } $path = $this->prepare_file($file); $fp = fopen($path, 'w'); $c = new curl; @@ -314,14 +315,4 @@ public function supported_filetypes() { public function supported_returntypes() { return (FILE_INTERNAL | FILE_EXTERNAL); } - - /** - * Return the source information - * - * @param string $photoid - * @return string|null - */ - public function get_file_source_info($photoid) { - return $this->build_photo_url($photoid); - } } diff --git a/repository/flickr_public/lib.php b/repository/flickr_public/lib.php index 083e4c72e37a5..d422483a8f5e3 100644 --- a/repository/flickr_public/lib.php +++ b/repository/flickr_public/lib.php @@ -396,13 +396,9 @@ public function print_search() { return $str; } - /** - * Return photo url by given photo id - * @param string $photoid - * @return string - */ - private function build_photo_url($photoid) { - $result = $this->flickr->photos_getSizes($photoid); + public function get_link($photo_id) { + global $CFG; + $result = $this->flickr->photos_getSizes($photo_id); $url = ''; if(!empty($result[4])) { $url = $result[4]['source']; @@ -414,27 +410,23 @@ private function build_photo_url($photoid) { return $url; } - public function get_link($photoid) { - return $this->build_photo_id($photoid); - } - /** * * @global object $CFG - * @param string $photoid + * @param string $photo_id * @param string $file * @return string */ - public function get_file($photoid, $file = '') { + public function get_file($photo_id, $file = '') { global $CFG; - $info = $this->flickr->photos_getInfo($photoid); + $info = $this->flickr->photos_getInfo($photo_id); if ($info['owner']['realname']) { $author = $info['owner']['realname']; } else { $author = $info['owner']['username']; } $copyright = get_string('author', 'repository') . ': ' . $author; - $result = $this->flickr->photos_getSizes($photoid); + $result = $this->flickr->photos_getSizes($photo_id); // download link $source = ''; // flickr photo page @@ -525,14 +517,4 @@ public function supported_filetypes() { public function supported_returntypes() { return (FILE_INTERNAL | FILE_EXTERNAL); } - - /** - * Return the source information - * - * @param string $photoid photo id - * @return string|null - */ - public function get_file_source_info($photoid) { - return $this->build_photo_url($photoid); - } } diff --git a/repository/lib.php b/repository/lib.php index ce968a18fc5cd..8b8d586ebb431 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -1159,16 +1159,6 @@ public function get_file_by_reference($reference) { return null; } - /** - * Return the source information - * - * @param stdClass $url - * @return string|null - */ - public function get_file_source_info($url) { - return $url; - } - /** * Move file from download folder to file pool using FILE API * @@ -2226,25 +2216,6 @@ public static function sync_external_file(stored_file $file) { return true; } - - /** - * Build draft file's source field - * - * {@link file_restore_source_field_from_draft_file()} - * XXX: This is a hack for file manager (MDL-28666) - * For newly created draft files we have to construct - * source filed in php serialized data format. - * File manager needs to know the original file information before copying - * to draft area, so we append these information in mdl_files.source field - * - * @param string $source - * @return string serialised source field - */ - public static function build_source_field($source) { - $sourcefield = new stdClass; - $sourcefield->source = $source; - return serialize($sourcefield); - } } /** diff --git a/repository/repository_ajax.php b/repository/repository_ajax.php index 45f0662c3c73b..3c064121497e8 100644 --- a/repository/repository_ajax.php +++ b/repository/repository_ajax.php @@ -265,11 +265,6 @@ $event['existingfile']->filename = $saveas_filename; $event['existingfile']->url = moodle_url::make_draftfile_url($itemid, $saveas_path, $saveas_filename)->out();; } else { - - // {@link repository::build_source_field()} - $sourcefield = $repo->get_file_source_info($source); - $record->source = $repo::build_source_field($sourcefield); - $storedfile = $fs->create_file_from_reference($record, $repo_id, $reference); $event = array( 'url'=>moodle_url::make_draftfile_url($storedfile->get_itemid(), $storedfile->get_filepath(), $storedfile->get_filename())->out(), @@ -307,9 +302,14 @@ throw new file_exception('maxbytes'); } - // {@link repository::build_source_field()} - $sourcefield = $repo->get_file_source_info($source); - $record->source = $repo::build_source_field($sourcefield); + // {@link file_restore_source_field_from_draft_file()} + $sourcefield = ''; + if (!empty($downloadedfile['url'])) { + $source = new stdClass; + $source->source = $downloadedfile['url']; + $sourcefield = serialize($source); + } + $record->source = $sourcefield; $info = repository::move_to_filepool($downloadedfile['path'], $record); if (empty($info)) { diff --git a/repository/s3/lib.php b/repository/s3/lib.php index 55586200c08b7..2479050597c7e 100644 --- a/repository/s3/lib.php +++ b/repository/s3/lib.php @@ -119,16 +119,6 @@ public function get_file($filepath, $file = '') { return array('path'=>$path); } - /** - * Return the source information - * - * @param stdClass $filepath - * @return string - */ - public function get_file_source_info($filepath) { - return 'Amazon S3:' . $filepath; - } - /** * S3 doesn't require login * diff --git a/repository/upload/lib.php b/repository/upload/lib.php index cf023dd10b42a..a307ab6228d62 100644 --- a/repository/upload/lib.php +++ b/repository/upload/lib.php @@ -143,9 +143,6 @@ public function process_upload($saveas_filename, $maxbytes, $types = '*', $savep self::antivir_scan_file($_FILES[$elname]['tmp_name'], $_FILES[$elname]['name'], true); @chmod($_FILES[$elname]['tmp_name'], $permissions); - // {@link repository::build_source_field()} - $record->source = self::build_source_field($_FILES[$elname]['name']); - if (empty($saveas_filename)) { $record->filename = clean_param($_FILES[$elname]['name'], PARAM_FILE); } else { @@ -189,6 +186,7 @@ public function process_upload($saveas_filename, $maxbytes, $types = '*', $savep } $record->contextid = $context->id; $record->userid = $USER->id; + $record->source = ''; if (repository::draftfile_exists($record->itemid, $record->filepath, $record->filename)) { $existingfilename = $record->filename; diff --git a/repository/url/lib.php b/repository/url/lib.php index 20725c81f2354..16f2eb07ae559 100644 --- a/repository/url/lib.php +++ b/repository/url/lib.php @@ -217,15 +217,5 @@ public function guess_filename($url, $type) { public function supported_returntypes() { return (FILE_INTERNAL | FILE_EXTERNAL); } - - /** - * Return the source information - * - * @param stdClass $url - * @return string|null - */ - public function get_file_source_info($url) { - return $url; - } } diff --git a/repository/wikimedia/lib.php b/repository/wikimedia/lib.php index cc4bf2be7961e..50d85562873a0 100644 --- a/repository/wikimedia/lib.php +++ b/repository/wikimedia/lib.php @@ -127,14 +127,4 @@ public function logout() { public function supported_returntypes() { return (FILE_INTERNAL | FILE_EXTERNAL); } - - /** - * Return the source information - * - * @param stdClass $url - * @return string|null - */ - public function get_file_source_info($url) { - return $url; - } }