@@ -839,13 +839,14 @@ public static function draftfile_exists($itemid, $filepath, $filename) {
839
839
}
840
840
841
841
/**
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
843
843
*
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()}
845
846
* @return stored_file|null
846
847
*/
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 );
849
850
$ fs = get_file_storage ();
850
851
return $ fs ->get_file ($ params ['contextid ' ], $ params ['component ' ], $ params ['filearea ' ],
851
852
$ params ['itemid ' ], $ params ['filepath ' ], $ params ['filename ' ]);
@@ -857,13 +858,14 @@ public static function get_moodle_file($source) {
857
858
* This is checked when user tries to pick the file from repository to deal with
858
859
* potential parameter substitutions is request
859
860
*
860
- * @param string $source
861
+ * @param string $source source of the file, returned by repository as 'source' and received back from user (not cleaned)
861
862
* @return bool whether the file is accessible by current user
862
863
*/
863
864
public function file_is_accessible ($ source ) {
864
865
if ($ this ->has_moodle_files ()) {
866
+ $ reference = $ this ->get_file_reference ($ source );
865
867
try {
866
- $ params = file_storage::unpack_reference ($ source , true );
868
+ $ params = file_storage::unpack_reference ($ reference , true );
867
869
} catch (file_reference_exception $ e ) {
868
870
return false ;
869
871
}
@@ -1376,12 +1378,13 @@ public function cache_file_by_reference($reference, $storedfile) {
1376
1378
* again to another file area (also as a copy or as a reference), the value of
1377
1379
* files.source is copied.
1378
1380
*
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)
1380
1382
* @return string|null
1381
1383
*/
1382
1384
public function get_file_source_info ($ source ) {
1383
1385
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 );
1385
1388
}
1386
1389
return $ source ;
1387
1390
}
@@ -1662,11 +1665,11 @@ public static function display_instances_list($context, $typename = null) {
1662
1665
/**
1663
1666
* Prepare file reference information
1664
1667
*
1665
- * @param string $source
1668
+ * @param string $source source of the file, returned by repository as 'source' and received back from user (not cleaned)
1666
1669
* @return string file referece
1667
1670
*/
1668
1671
public function get_file_reference ($ source ) {
1669
- if ($ this -> has_moodle_files () && ( $ this ->supported_returntypes () & FILE_REFERENCE )) {
1672
+ if ($ source && $ this ->has_moodle_files ( )) {
1670
1673
$ params = file_storage::unpack_reference ($ source );
1671
1674
if (!is_array ($ params )) {
1672
1675
throw new repository_exception ('invalidparams ' , 'repository ' );
0 commit comments