Skip to content

Commit

Permalink
Merge branch 'MDL-36526-master' of git://github.com/ankitagarwal/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Nov 15, 2012
2 parents a3f3ea2 + 12927e5 commit 211f815
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions calendar/managesubscriptions_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function definition() {

// 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'));
Expand Down Expand Up @@ -103,12 +104,21 @@ public function definition() {
*/
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;
}
Expand Down

0 comments on commit 211f815

Please sign in to comment.