MDL-47084 forum: New moodle_url method make_webservice_pluginfile_url

This commit is contained in:
Juan Leyva
2014-10-03 16:34:48 +02:00
parent 694bf0c74b
commit da1be050bc
3 changed files with 35 additions and 15 deletions
+26
View File
@@ -730,6 +730,32 @@ class moodle_url {
}
}
/**
* Factory method for creation of url pointing to plugin file.
* This method is the same that make_pluginfile_url but pointing to the webservice pluginfile.php script.
* It should be used only in external functions.
*
* @since 2.8
* @param int $contextid
* @param string $component
* @param string $area
* @param int $itemid
* @param string $pathname
* @param string $filename
* @param bool $forcedownload
* @return moodle_url
*/
public static function make_webservice_pluginfile_url($contextid, $component, $area, $itemid, $pathname, $filename,
$forcedownload = false) {
global $CFG;
$urlbase = "$CFG->httpswwwroot/webservice/pluginfile.php";
if ($itemid === null) {
return self::make_file_url($urlbase, "/$contextid/$component/$area".$pathname.$filename, $forcedownload);
} else {
return self::make_file_url($urlbase, "/$contextid/$component/$area/$itemid".$pathname.$filename, $forcedownload);
}
}
/**
* Factory method for creation of url pointing to draft file of current user.
*
+5 -7
View File
@@ -473,11 +473,8 @@ class mod_forum_external extends external_api {
$user->id = $post->userid;
$user = username_load_fields_from_object($user, $post);
$post->userfullname = fullname($user, $canviewfullname);
$post->userpictureurl = moodle_url::make_pluginfile_url(
context_user::instance($user->id)->id, 'user', 'icon', null, '/', 'f1');
// Fix the pluginfile.php link.
$post->userpictureurl = str_replace("pluginfile.php", "webservice/pluginfile.php",
$post->userpictureurl);
$post->userpictureurl = moodle_url::make_webservice_pluginfile_url(
context_user::instance($user->id)->id, 'user', 'icon', null, '/', 'f1')->out(false);
// Rewrite embedded images URLs.
list($post->message, $post->messageformat) =
@@ -491,12 +488,13 @@ class mod_forum_external extends external_api {
if ($files = $fs->get_area_files($modcontext->id, 'mod_forum', 'attachment', $post->id, "filename", false)) {
foreach ($files as $file) {
$filename = $file->get_filename();
$fileurl = moodle_url::make_webservice_pluginfile_url(
$modcontext->id, 'mod_forum', 'attachment', $post->id, '/', $filename);
$post->attachments[] = array(
'filename' => $filename,
'mimetype' => $file->get_mimetype(),
'fileurl' => file_encode_url($CFG->wwwroot.'/webservice/pluginfile.php',
'/'.$modcontext->id.'/mod_forum/attachment/'.$post->id.'/'.$filename)
'fileurl' => $fileurl->out(false)
);
}
}
+4 -8
View File
@@ -465,10 +465,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'warnings' => array(),
);
$userpictureurl = moodle_url::make_pluginfile_url(
context_user::instance($discussion1reply2->userid)->id, 'user', 'icon', null, '/', 'f1');
// Fix the pluginfile.php link.
$userpictureurl = str_replace("pluginfile.php", "webservice/pluginfile.php", $userpictureurl);
$userpictureurl = moodle_url::make_webservice_pluginfile_url(
context_user::instance($discussion1reply2->userid)->id, 'user', 'icon', null, '/', 'f1')->out(false);
$expectedposts['posts'][] = array(
'id' => $discussion1reply2->id,
@@ -493,10 +491,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'userpictureurl' => $userpictureurl
);
$userpictureurl = moodle_url::make_pluginfile_url(
context_user::instance($discussion1reply1->userid)->id, 'user', 'icon', null, '/', 'f1');
// Fix the pluginfile.php link.
$userpictureurl = str_replace("pluginfile.php", "webservice/pluginfile.php", $userpictureurl);
$userpictureurl = moodle_url::make_webservice_pluginfile_url(
context_user::instance($discussion1reply1->userid)->id, 'user', 'icon', null, '/', 'f1')->out(false);
$expectedposts['posts'][] = array(
'id' => $discussion1reply1->id,