@@ -1655,12 +1655,32 @@ public static function display_instances_list($context, $typename = null) {
1655
1655
* Prepare file reference information
1656
1656
*
1657
1657
* @param string $source source of the file, returned by repository as 'source' and received back from user (not cleaned)
1658
- * @return string file referece
1658
+ * @return string file reference, ready to be stored
1659
1659
*/
1660
1660
public function get_file_reference ($ source ) {
1661
1661
if ($ source && $ this ->has_moodle_files ()) {
1662
- $ params = file_storage::unpack_reference ($ source );
1663
- if (!is_array ($ params )) {
1662
+ $ params = @json_decode (base64_decode ($ source ), true );
1663
+ if (!$ params && !in_array ($ this ->get_typename (), array ('recent ' , 'user ' , 'local ' , 'coursefiles ' ))) {
1664
+ // IMPORTANT! Since default format for moodle files was changed in the minor release as a security fix
1665
+ // we maintain an old code here in order not to break 3rd party repositories that deal
1666
+ // with moodle files. Repositories are strongly encouraged to be upgraded, see MDL-45616.
1667
+ // In Moodle 2.8 this fallback will be removed.
1668
+ $ params = file_storage::unpack_reference ($ source , true );
1669
+ return file_storage::pack_reference ($ params );
1670
+ }
1671
+ if (!is_array ($ params ) || empty ($ params ['contextid ' ])) {
1672
+ throw new repository_exception ('invalidparams ' , 'repository ' );
1673
+ }
1674
+ $ params = array (
1675
+ 'component ' => empty ($ params ['component ' ]) ? '' : clean_param ($ params ['component ' ], PARAM_COMPONENT ),
1676
+ 'filearea ' => empty ($ params ['filearea ' ]) ? '' : clean_param ($ params ['filearea ' ], PARAM_AREA ),
1677
+ 'itemid ' => empty ($ params ['itemid ' ]) ? 0 : clean_param ($ params ['itemid ' ], PARAM_INT ),
1678
+ 'filename ' => empty ($ params ['filename ' ]) ? null : clean_param ($ params ['filename ' ], PARAM_FILE ),
1679
+ 'filepath ' => empty ($ params ['filepath ' ]) ? null : clean_param ($ params ['filepath ' ], PARAM_PATH ),
1680
+ 'contextid ' => clean_param ($ params ['contextid ' ], PARAM_INT )
1681
+ );
1682
+ // Check if context exists.
1683
+ if (!context::instance_by_id ($ params ['contextid ' ], IGNORE_MISSING )) {
1664
1684
throw new repository_exception ('invalidparams ' , 'repository ' );
1665
1685
}
1666
1686
return file_storage::pack_reference ($ params );
0 commit comments