MDL-36526 calendar: calender ical import should allow webcal:// protocols

This commit is contained in:
Ankit Agarwal 2012-11-13 13:54:23 +08:00
parent 8ccaa296fa
commit 12927e568b

View File

@ -58,7 +58,8 @@ class calendar_addsubscription_form extends moodleform {
// URL.
$mform->addElement('text', 'url', get_string('importfromurl', 'calendar'), array('maxsize' => '255', 'size' => '50'));
$mform->setType('url', PARAM_URL);
// Cannot set as PARAM_URL since we need to allow webcal:// protocol.
$mform->setType('url', PARAM_RAW);
// Import file
$mform->addElement('filepicker', 'importfile', get_string('importfromfile', 'calendar'));
@ -103,12 +104,21 @@ class calendar_addsubscription_form extends moodleform {
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
if (empty($data['url']) && empty($data['importfile'])) {
$url = $data['url'];
if (empty($url) && empty($data['importfile'])) {
if (!empty($data['importfrom']) && $data['importfrom'] == CALENDAR_IMPORT_FROM_FILE) {
$errors['importfile'] = get_string('errorrequiredurlorfile', 'calendar');
} else {
$errors['url'] = get_string('errorrequiredurlorfile', 'calendar');
}
} elseif (!empty($url)) {
// Url is webcal protocol which is not accepted by PARAM_URL.
if (stripos($url, "webcal://") === 0) {
$url = substr($url, strlen("webcal://"));
}
if (clean_param($url, PARAM_URL) !== $url) {
$errors['url'] = get_string('invalidurl', 'error');
}
}
return $errors;
}