You are here

function _calendar_ical_setup_form in Calendar 7

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

Setup Calendar feeds.

@todo - control of the stripe color is not yet implemented.

File

calendar_ical/calendar_ical_admin.inc, line 15
Setup and admin functions.

Code

function _calendar_ical_setup_form($view_name) {
  module_load_include('inc', 'date_api', 'date_api_ical');
  $form = array();
  $view = views_get_view($view_name);
  $period = drupal_map_assoc(array(
    0,
    3600,
    10800,
    21600,
    32400,
    43200,
    86400,
    172800,
    259200,
    604800,
    1209600,
    2419200,
    4838400,
    9676800,
  ), 'format_interval');
  $form['calendar_ical_expire_' . $view->name] = array(
    '#type' => 'select',
    '#title' => t('Expire iCal cache'),
    '#default_value' => variable_get('calendar_ical_expire_' . $view->name, 9676800),
    '#options' => $period,
    '#description' => t('iCal feeds are cached to improve performance. Set an expiration time for cached feeds.'),
  );
  $empty_feed = array(
    0 => array(
      'name' => '',
      'url' => '',
      'type' => 'ical',
      'stripe' => 0,
    ),
  );
  $form[$view->name] = array(
    '#type' => 'fieldset',
    '#title' => t('iCal Feeds'),
    '#description' => t('Use this section to set up iCal feeds that should be displayed in this calendar. They will be shown along with any internal items that match the calendar criteria.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  );

  // One empty input form will be added after any existing items.
  $view_feeds = array_merge((array) variable_get('calendar_feeds_' . $view->name, $empty_feed), $empty_feed);
  foreach ($view_feeds as $delta => $feed) {
    $form[$view->name][$delta] = array(
      'type' => array(
        '#title' => t('Feed type'),
        '#type' => 'hidden',
        '#value' => 'ical',
      ),
      'name' => array(
        '#title' => t('Name'),
        '#type' => 'textfield',
        '#default_value' => $feed['name'],
        '#description' => t('The name of a feed to include in this calendar.'),
      ),
      'url' => array(
        '#title' => t('Url'),
        '#type' => 'textarea',
        '#rows' => 2,
        '#default_value' => $feed['url'],
        '#description' => t("The external feed url or internal file path and name. Change 'webcal://' to 'http://'."),
      ),
      'calendar_colorpicker' => array(
        '#type' => 'calendar_colorpicker',
        '#title' => t('Stripe color'),
      ),
      'stripe' => array(
        '#type' => 'calendar_colorfield',
        '#default_value' => isset($feed['stripe']) ? $feed['stripe'] : '#ffffff',
        '#calendar_colorpicker' => $view_name . '-' . $delta . '-calendar-colorpicker',
        '#description' => t("The hex color value (like #ffffff) to use for this feed's calendar stripe."),
      ),
    );
  }
  $form['view_name'] = array(
    '#type' => 'hidden',
    '#value' => $view->name,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}