Skip to content

Commit

Permalink
MDL-36526 calendar: Convert webcal:// to http://
Browse files Browse the repository at this point in the history
Curl doesn't understand webcal, so needs to use http. Also fixed some
php warnings spotted during testing.
  • Loading branch information
danpoltawski committed Nov 15, 2012
1 parent 391678f commit b34e885
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions calendar/managesubscriptions_form.php
Expand Up @@ -104,22 +104,38 @@ public function definition() {
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
$url = $data['url'];
if (empty($url) && empty($data['importfile'])) {

if (empty($data['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) {
} else if (!empty($data['url'])) {
if (clean_param($data['url'], PARAM_URL) !== $data['url']) {
$errors['url'] = get_string('invalidurl', 'error');
}
}
return $errors;
}

public function definition_after_data() {
$mform =& $this->_form;

$mform->applyFilter('url', 'calendar_addsubscription_form::strip_webcal');
}

/**
* Replace webcal:// urls with http:// as
* curl does not understand this protocol
*
* @param string @url url to examine
* @return string url with webcal:// replaced
*/
public static function strip_webcal($url) {
if (strpos($url, 'webcal://') === 0) {
$url = str_replace('webcal://', 'http://', $url);
}
return $url;
}
}

0 comments on commit b34e885

Please sign in to comment.