| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 //$Id: calendar_ical_admin.inc,v 1.1.2.2 2008/10/02 20:23:49 karens Exp $ 3 /** 4 * @file 5 * Setup and admin functions. 6 * 7 * Moved to a separate file so they're not parsed when not needed. 8 */ 9 /** 10 * Setup Calendar feeds. 11 * 12 * @todo - control of the stripe color is not yet implemented. 13 */ 14 function _calendar_ical_setup_form($view_name) { 15 require_once('./'. drupal_get_path('module', 'date_api') .'/date_api_ical.inc'); 16 17 $form = array(); 18 $view = views_get_view($view_name); 19 20 $period = drupal_map_assoc(array(0, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'); 21 $form['calendar_ical_expire_'. $view->name] = array( 22 '#type' => 'select', '#title' => t('Expire iCal cache'), 23 '#default_value' => variable_get('calendar_ical_expire_'. $view->name, 9676800), '#options' => $period, 24 '#description' => t('iCal feeds are cached to improve performance. Set an expiration time for cached feeds.') 25 ); 26 27 $empty_feed = array(0 => array('name' => '', 'url' => '', 'type' => 'ical', 'stripe' => 0)); 28 $form[$view->name] = array( 29 '#type' => 'fieldset', 30 '#title' => t('iCal Feeds'), 31 '#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.'), 32 '#collapsible' => TRUE, 33 '#collapsed' => FALSE, 34 '#tree' => TRUE, 35 ); 36 37 // One empty input form will be added after any existing items. 38 $view_feeds = array_merge((array) variable_get('calendar_feeds_'. $view->name, $empty_feed), $empty_feed); 39 foreach ($view_feeds as $delta => $feed) { 40 $form[$view->name][$delta] = array( 41 'type' => array( 42 '#title' => t('Feed type'), 43 '#type' => 'hidden', 44 '#value' => 'ical', 45 ), 46 'name' => array( 47 '#title' => t('Name'), 48 '#type' => 'textfield', 49 '#default_value' => $feed['name'], 50 '#description' => t('The name of a feed to include in this calendar.'), 51 ), 52 'url' => array( 53 '#title' => t('Url'), 54 '#type' => 'textarea', 55 '#rows' => 2, 56 '#default_value' => $feed['url'], 57 '#description' => t("The external feed url or internal file path and name. Change 'webcal://' to 'http://'."), 58 ), 59 'calendar_colorpicker' => array( 60 '#type' => 'calendar_colorpicker', 61 '#title' => t('Stripe color'), 62 ), 63 'stripe' => array( 64 '#type' => 'calendar_colorfield', 65 '#default_value' => isset($feed['stripe']) ? $feed['stripe'] : '#ffffff', 66 '#calendar_colorpicker' => $view_name .'-'. $delta .'-calendar-colorpicker', 67 '#description' => t("The hex color value (like #ffffff) to use for this feed's calendar stripe."), 68 ), 69 ); 70 } 71 $form['view_name'] = array( 72 '#type' => 'hidden', 73 '#value' => $view->name, 74 ); 75 $form['submit'] = array( 76 '#type' => 'submit', 77 '#value' => t('Submit'), 78 ); 79 return $form; 80 } 81 82 /** 83 * Save requested values. 84 */ 85 function calendar_ical_setup_form_submit($form_id, $form_values) { 86 $view_name = $form_values['view_name']; 87 foreach ($form_values as $value_name => $value) { 88 if ($value_name == 'calendar_ical_expire_'. $view_name) { 89 variable_set('calendar_ical_expire_'. $view_name, $value); 90 } 91 elseif (is_array($value)) { 92 foreach ($value as $delta => $item) { 93 // Don't save empty values. 94 if (trim($item['url']) == '' || trim($item['name']) == '') { 95 unset($value[$delta]); 96 } 97 else { 98 // Replace 'webcal' protocol with http protocol. 99 $item['url'] = str_replace('webcal:', 'http:', $item['url']); 100 // Don't save invalid urls. 101 $events = date_ical_import($item['url']); 102 if (!is_array($events)) { 103 unset($value[$delta]); 104 } 105 else { 106 $value[$delta]['url'] = $item['url']; 107 } 108 109 } 110 } 111 variable_set('calendar_feeds_'. $value_name, $value); 112 } 113 } 114 cache_clear_all('calendar_feeds_'. $view->name, calendar_ical_cache(), TRUE); 115 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |