@@ -839,13 +839,14 @@ public static function draftfile_exists($itemid, $filepath, $filename) {
839839 }
840840
841841 /**
842- * Parses the 'source' returned by moodle repositories and returns an instance of stored_file
842+ * Parses the moodle file reference and returns an instance of stored_file
843843 *
844- * @param string $source
844+ * @param string $reference reference to the moodle internal file as retruned by
845+ * {@link repository::get_file_reference()} or {@link file_storage::pack_reference()}
845846 * @return stored_file|null
846847 */
847- public static function get_moodle_file ($ source ) {
848- $ params = file_storage::unpack_reference ($ source , true );
848+ public static function get_moodle_file ($ reference ) {
849+ $ params = file_storage::unpack_reference ($ reference , true );
849850 $ fs = get_file_storage ();
850851 return $ fs ->get_file ($ params ['contextid ' ], $ params ['component ' ], $ params ['filearea ' ],
851852 $ params ['itemid ' ], $ params ['filepath ' ], $ params ['filename ' ]);
@@ -857,13 +858,14 @@ public static function get_moodle_file($source) {
857858 * This is checked when user tries to pick the file from repository to deal with
858859 * potential parameter substitutions is request
859860 *
860- * @param string $source
861+ * @param string $source source of the file, returned by repository as 'source' and received back from user (not cleaned)
861862 * @return bool whether the file is accessible by current user
862863 */
863864 public function file_is_accessible ($ source ) {
864865 if ($ this ->has_moodle_files ()) {
866+ $ reference = $ this ->get_file_reference ($ source );
865867 try {
866- $ params = file_storage::unpack_reference ($ source , true );
868+ $ params = file_storage::unpack_reference ($ reference , true );
867869 } catch (file_reference_exception $ e ) {
868870 return false ;
869871 }
@@ -1376,12 +1378,13 @@ public function cache_file_by_reference($reference, $storedfile) {
13761378 * again to another file area (also as a copy or as a reference), the value of
13771379 * files.source is copied.
13781380 *
1379- * @param string $source the value that repository returned in listing as 'source'
1381+ * @param string $source source of the file, returned by repository as 'source' and received back from user (not cleaned)
13801382 * @return string|null
13811383 */
13821384 public function get_file_source_info ($ source ) {
13831385 if ($ this ->has_moodle_files ()) {
1384- return $ this ->get_reference_details ($ source , 0 );
1386+ $ reference = $ this ->get_file_reference ($ source );
1387+ return $ this ->get_reference_details ($ reference , 0 );
13851388 }
13861389 return $ source ;
13871390 }
@@ -1662,11 +1665,11 @@ public static function display_instances_list($context, $typename = null) {
16621665 /**
16631666 * Prepare file reference information
16641667 *
1665- * @param string $source
1668+ * @param string $source source of the file, returned by repository as 'source' and received back from user (not cleaned)
16661669 * @return string file referece
16671670 */
16681671 public function get_file_reference ($ source ) {
1669- if ($ this -> has_moodle_files () && ( $ this ->supported_returntypes () & FILE_REFERENCE )) {
1672+ if ($ source && $ this ->has_moodle_files ( )) {
16701673 $ params = file_storage::unpack_reference ($ source );
16711674 if (!is_array ($ params )) {
16721675 throw new repository_exception ('invalidparams ' , 'repository ' );
0 commit comments