@@ -828,13 +828,14 @@ public static function draftfile_exists($itemid, $filepath, $filename) {
828
828
}
829
829
830
830
/**
831
- * Parses the 'source' returned by moodle repositories and returns an instance of stored_file
831
+ * Parses the moodle file reference and returns an instance of stored_file
832
832
*
833
- * @param string $source
833
+ * @param string $reference reference to the moodle internal file as retruned by
834
+ * {@link repository::get_file_reference()} or {@link file_storage::pack_reference()}
834
835
* @return stored_file|null
835
836
*/
836
- public static function get_moodle_file ($ source ) {
837
- $ params = file_storage::unpack_reference ($ source , true );
837
+ public static function get_moodle_file ($ reference ) {
838
+ $ params = file_storage::unpack_reference ($ reference , true );
838
839
$ fs = get_file_storage ();
839
840
return $ fs ->get_file ($ params ['contextid ' ], $ params ['component ' ], $ params ['filearea ' ],
840
841
$ params ['itemid ' ], $ params ['filepath ' ], $ params ['filename ' ]);
@@ -846,13 +847,14 @@ public static function get_moodle_file($source) {
846
847
* This is checked when user tries to pick the file from repository to deal with
847
848
* potential parameter substitutions is request
848
849
*
849
- * @param string $source
850
+ * @param string $source source of the file, returned by repository as 'source' and received back from user (not cleaned)
850
851
* @return bool whether the file is accessible by current user
851
852
*/
852
853
public function file_is_accessible ($ source ) {
853
854
if ($ this ->has_moodle_files ()) {
855
+ $ reference = $ this ->get_file_reference ($ source );
854
856
try {
855
- $ params = file_storage::unpack_reference ($ source , true );
857
+ $ params = file_storage::unpack_reference ($ reference , true );
856
858
} catch (file_reference_exception $ e ) {
857
859
return false ;
858
860
}
@@ -1365,12 +1367,13 @@ public function cache_file_by_reference($reference, $storedfile) {
1365
1367
* again to another file area (also as a copy or as a reference), the value of
1366
1368
* files.source is copied.
1367
1369
*
1368
- * @param string $source the value that repository returned in listing as 'source'
1370
+ * @param string $source source of the file, returned by repository as 'source' and received back from user (not cleaned)
1369
1371
* @return string|null
1370
1372
*/
1371
1373
public function get_file_source_info ($ source ) {
1372
1374
if ($ this ->has_moodle_files ()) {
1373
- return $ this ->get_reference_details ($ source , 0 );
1375
+ $ reference = $ this ->get_file_reference ($ source );
1376
+ return $ this ->get_reference_details ($ reference , 0 );
1374
1377
}
1375
1378
return $ source ;
1376
1379
}
@@ -1651,11 +1654,11 @@ public static function display_instances_list($context, $typename = null) {
1651
1654
/**
1652
1655
* Prepare file reference information
1653
1656
*
1654
- * @param string $source
1657
+ * @param string $source source of the file, returned by repository as 'source' and received back from user (not cleaned)
1655
1658
* @return string file referece
1656
1659
*/
1657
1660
public function get_file_reference ($ source ) {
1658
- if ($ this -> has_moodle_files () && ( $ this ->supported_returntypes () & FILE_REFERENCE )) {
1661
+ if ($ source && $ this ->has_moodle_files ( )) {
1659
1662
$ params = file_storage::unpack_reference ($ source );
1660
1663
if (!is_array ($ params )) {
1661
1664
throw new repository_exception ('invalidparams ' , 'repository ' );
0 commit comments