You are here

function calendar_ical_setup_form_submit in Calendar 5

Same name and namespace in other branches
  1. 5.2 calendar_ical_admin.inc \calendar_ical_setup_form_submit()
  2. 6.2 calendar_ical/calendar_ical_admin.inc \calendar_ical_setup_form_submit()
  3. 7 calendar_ical/calendar_ical_admin.inc \calendar_ical_setup_form_submit()
  4. 7.2 calendar_ical/calendar_ical_admin.inc \calendar_ical_setup_form_submit()

Save requested values.

File

./calendar_ical.module, line 164
Adds ical functionality to Calendar.

Code

function calendar_ical_setup_form_submit($form_id, $form_values) {
  calendar_ical_load_date_ical();
  $view_name = $form_values['view_name'];
  foreach ($form_values as $value_name => $value) {
    if ($value_name == 'calendar_ical_expire_' . $view_name) {
      variable_set('calendar_ical_expire_' . $view_name, $value);
    }
    elseif (is_array($value)) {
      foreach ($value as $delta => $item) {

        // Don't save empty values.
        if (trim($item['url']) == '' || trim($item['name']) == '') {
          unset($value[$delta]);
        }
        else {

          // Replace 'webcal' protocol with http protocol.
          $item['url'] = str_replace('webcal:', 'http:', $item['url']);

          // Don't save invalid urls.
          $events = date_ical_import($item['url']);
          if (!is_array($events)) {
            unset($value[$delta]);
          }
          else {
            $value[$delta]['url'] = $item['url'];
          }
        }
      }
      variable_set('calendar_feeds_' . $value_name, $value);
    }
  }
  cache_clear_all('calendar_feeds_' . $view->name, calendar_ical_cache(), TRUE);
}