@@ -799,13 +799,14 @@ public static function draftfile_exists($itemid, $filepath, $filename) {
799
799
}
800
800
801
801
/**
802
- * Parses the 'source' returned by moodle repositories and returns an instance of stored_file
802
+ * Parses the moodle file reference and returns an instance of stored_file
803
803
*
804
- * @param string $source
804
+ * @param string $reference reference to the moodle internal file as retruned by
805
+ * {@link repository::get_file_reference()} or {@link file_storage::pack_reference()}
805
806
* @return stored_file|null
806
807
*/
807
- public static function get_moodle_file ($ source ) {
808
- $ params = file_storage::unpack_reference ($ source , true );
808
+ public static function get_moodle_file ($ reference ) {
809
+ $ params = file_storage::unpack_reference ($ reference , true );
809
810
$ fs = get_file_storage ();
810
811
return $ fs ->get_file ($ params ['contextid ' ], $ params ['component ' ], $ params ['filearea ' ],
811
812
$ params ['itemid ' ], $ params ['filepath ' ], $ params ['filename ' ]);
@@ -817,13 +818,14 @@ public static function get_moodle_file($source) {
817
818
* This is checked when user tries to pick the file from repository to deal with
818
819
* potential parameter substitutions is request
819
820
*
820
- * @param string $source
821
+ * @param string $source source of the file, returned by repository as 'source' and received back from user (not cleaned)
821
822
* @return bool whether the file is accessible by current user
822
823
*/
823
824
public function file_is_accessible ($ source ) {
824
825
if ($ this ->has_moodle_files ()) {
826
+ $ reference = $ this ->get_file_reference ($ source );
825
827
try {
826
- $ params = file_storage::unpack_reference ($ source , true );
828
+ $ params = file_storage::unpack_reference ($ reference , true );
827
829
} catch (file_reference_exception $ e ) {
828
830
return false ;
829
831
}
@@ -1401,12 +1403,13 @@ public function get_file_by_reference($reference) {
1401
1403
* again to another file area (also as a copy or as a reference), the value of
1402
1404
* files.source is copied.
1403
1405
*
1404
- * @param string $source the value that repository returned in listing as 'source'
1406
+ * @param string $source source of the file, returned by repository as 'source' and received back from user (not cleaned)
1405
1407
* @return string|null
1406
1408
*/
1407
1409
public function get_file_source_info ($ source ) {
1408
1410
if ($ this ->has_moodle_files ()) {
1409
- return $ this ->get_reference_details ($ source , 0 );
1411
+ $ reference = $ this ->get_file_reference ($ source );
1412
+ return $ this ->get_reference_details ($ reference , 0 );
1410
1413
}
1411
1414
return $ source ;
1412
1415
}
@@ -1687,11 +1690,11 @@ public static function display_instances_list($context, $typename = null) {
1687
1690
/**
1688
1691
* Prepare file reference information
1689
1692
*
1690
- * @param string $source
1693
+ * @param string $source source of the file, returned by repository as 'source' and received back from user (not cleaned)
1691
1694
* @return string file referece
1692
1695
*/
1693
1696
public function get_file_reference ($ source ) {
1694
- if ($ this -> has_moodle_files () && ( $ this ->supported_returntypes () & FILE_REFERENCE )) {
1697
+ if ($ source && $ this ->has_moodle_files ( )) {
1695
1698
$ params = file_storage::unpack_reference ($ source );
1696
1699
if (!is_array ($ params )) {
1697
1700
throw new repository_exception ('invalidparams ' , 'repository ' );
0 commit comments