diff --git fullcalendar.install fullcalendar.install index a503ae2..7699236 100644 --- fullcalendar.install +++ fullcalendar.install @@ -37,7 +37,7 @@ } /** - * Implementation of hook_uninstall(). + * Implements hook_uninstall(). */ function fullcalendar_uninstall() { variable_del('fullcalendar_path'); diff --git fullcalendar.module fullcalendar.module index 1bcdffa..b8bd220 100644 --- fullcalendar.module +++ fullcalendar.module @@ -189,9 +189,6 @@ 'left' => $vars['options']['header']['fc_left'], 'center' => $vars['options']['header']['fc_center'], 'right' => $vars['options']['header']['fc_right'], - 'year' => $vars['options']['defaults']['fc_year'], - 'month' => $vars['options']['defaults']['fc_month'], - 'day' => $vars['options']['defaults']['fc_day'], 'agenda' => $vars['options']['times']['fc_timeformat'], 'clock' => $vars['options']['times']['fc_clock'], 'monthNames' => array_values(date_month_names(TRUE)), @@ -204,6 +201,13 @@ 'monthString' => t('Month'), 'todayString' => t('Today'), ); + + if($vars['options']['times']['fc_default_date']) { + $settings['year'] = $vars['options']['times']['fc_date']['year']; + $settings['month'] = $vars['options']['times']['fc_date']['month']; + $settings['day'] = $vars['options']['times']['fc_date']['day']; + } + drupal_add_library('fullcalendar', 'fullcalendar'); drupal_add_js(array('fullcalendar' => $settings), 'setting'); drupal_add_js(drupal_get_path('module', 'fullcalendar') . '/fullcalendar.views.js'); @@ -214,10 +218,11 @@ */ function template_preprocess_views_view_node_fullcalendar(&$vars) { $entity_type = 'node'; - if (isset($vars['view']->empty_text)) { - $vars['empty_text'] = $vars['view']->empty_text; - return; - } + + // Fetch the available fields in this view. + $fields = $vars['view']->display_handler->get_field_labels(); + + // Get the node and return if not found or empty. $nid = $vars['row']->{$vars['field_alias']}; if (!is_numeric($nid)) { return; @@ -230,49 +235,52 @@ // Allow resize/drag/drop of an event if user has proper permissions. $node->editable = _fullcalendar_update_access($node); $node->class = theme('fullcalendar_classname', array('node' => $node)); + + // Prepare structures. $vars['node'] = $node; $vars['data'] = array(); // Contains the start, end & allDay values. + + // Default url. $node->url = 'node/' . $nid; - if ($url_field = $vars['options']['fullcalendar_url_field']) { - if ($url_field = field_get_items('node', $node, $url_field)) { - $vars['url'] = $url_field[0]['value']; + + // Fetch custom title if needed. + if(!empty($vars['options']['fullcalendar_custom_title'])) { + $title_field_as_entity = $vars['options']['fullcalendar_title_field']; + $title_field = $fields[$title_field_as_entity]; + $language = field_language($entity_type, $node, $title_field); + $title_field_value = $node->{$title_field}[$language][0]['value']; + if (!empty($title_field_value)) { + $node->title = $title_field_value; } } - $title_field = $vars['options']['fullcalendar_title_field']; - if (!empty($title_field) && !empty($node->{$title_field}[0]['value'])) { - $node->title = $node->{$title_field}[0]['value']; + // Fetch custom url if needed. + if(!empty($vars['options']['fullcalendar_custom_url'])) { + $url_field_as_entity = $vars['options']['fullcalendar_url_field']; + $url_field = $fields[$url_field_as_entity]; + $language = field_language($entity_type, $node, $url_field); + $url_field_value = $node->{$url_field}[$language][0]['value']; + if (!empty($url_field_value)) { + $node->url = $url_field_value; + } } - $display_field = fullcalendar_date_fields($node); - $field_names = trim(strip_tags($vars['options']['fullcalendar_date_fields'])); - if (!empty($field_names)) { - foreach (explode("\n", $field_names) as $field_name) { - $field_name = trim(strip_tags($field_name)); - if (($field_name == 'created') || ($field_name == 'changed')) { - $attributes = _fullcalendar_set_display_times($entity_type, $node, $field_name); + + // Get the date fields from this node. + $display_field = fullcalendar_date_fields($fields); + + // Iterate through all available fields. + foreach ($display_field as $field_name => $field) { + $instance = field_info_instance($entity_type, $field_name, $node->type); + $items = field_get_items($entity_type, $node, $field_name); + // Filter fields without value + if(!empty($items)) { + foreach ($items as $index => $item) { + $attributes = _fullcalendar_set_display_times($entity_type, $node, $field_name, $instance, $field, $item); $vars['data'][] = theme('fullcalendar_link', - array('node' => $node, 'attributes' => $attributes, 'index' => 0) + array('node' => $node, 'attributes' => $attributes, 'index' => $index) ); - $display_field = array(); - break; } - // If a date_type field exists - if (isset($display_field[$field_name])) { - $display_field = array($field_name => $display_field[$field_name]); - break; - } - } - } - // Iterate through available fields, using the first one found. - foreach ($display_field as $field_name => $field) { - $instance = field_info_instance($entity_type, $field_name, $node->type); - foreach (field_get_items($entity_type, $node, $field_name) as $index => $item) { - $attributes = _fullcalendar_set_display_times($entity_type, $node, $field_name, $instance, $field, $item); - $vars['data'][] = theme('fullcalendar_link', - array('node' => $node, 'attributes' => $attributes, 'index' => $index) - ); } - break; } } @@ -360,21 +368,14 @@ } /** - * Find all date fields in this instance. + * Filters the date fields. * - * Field type is not in the $field array we get from - * field_info_instances(), we need to call - * field_info_field() to find that. + * @param $view_fields + * Array of possible date fields. */ -function fullcalendar_date_fields($entity, $entity_type = 'node') { - $bundle = ''; - switch ($entity_type) { - case 'node': - $bundle = $entity->type; - break; - } +function fullcalendar_date_fields($view_fields) { $fields = array(); - foreach (array_keys(field_info_instances($entity_type, $bundle)) as $field_name) { + foreach($view_fields as $entity_name => $field_name) { $field = field_info_field($field_name); if (in_array($field['type'], array('date', 'datestamp', 'datetime'))) { $fields[$field_name] = $field; diff --git fullcalendar.views.inc fullcalendar.views.inc index 161df80..7c80807 100644 --- fullcalendar.views.inc +++ fullcalendar.views.inc @@ -52,12 +52,12 @@ ), 'row' => array( 'fullcalendar_node' => array( - 'title' => t('Node - FullCalendar'), + 'title' => t('Fields - FullCalendar'), 'help' => t('For use with FullCalendar style'), 'handler' => 'views_plugin_node_fullcalendar', 'theme' => 'views_view_node_fullcalendar', 'theme path' => $path, - 'uses fields' => FALSE, + 'uses fields' => TRUE, 'uses options' => TRUE, 'type' => 'normal', ), diff --git views_plugin_node_fullcalendar.inc views_plugin_node_fullcalendar.inc index cc70b02..d582b5f 100644 --- views_plugin_node_fullcalendar.inc +++ views_plugin_node_fullcalendar.inc @@ -19,30 +19,43 @@ function option_definition() { $options = parent::option_definition(); $options['fullcalendar_url_field'] = array('default' => ''); - $options['fullcalendar_date_fields'] = array('default' => ''); $options['fullcalendar_title_field'] = array('default' => ''); + $options['fullcalendar_custom_url'] = array('default' => FALSE); + $options['fullcalendar_custom_title'] = array('default' => FALSE); return $options; } function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); - $form['fullcalendar_date_fields'] = array( - '#type' => 'textarea', - '#title' => t('Date Fields'), - '#default_value' => $this->options['fullcalendar_date_fields'], - '#description' => t('Normally this plugin uses the first node field that is either a date or a datetime field type. However, if you wish to override this behavior, please enter the names of the fields to use instead. For example "field_scheduled_for". Enter one per line. They will be searched in the order listed. Enter "created" or "changed" to use the respective node timestamps.'), + $field_options = $this->display->handler->get_field_labels(); + + $form['fullcalendar_custom_title'] = array( + '#type' => 'checkbox', + '#title' => t('Use a custom event title'), + '#default_value' => $this->options['fullcalendar_custom_title'], ); $form['fullcalendar_title_field'] = array( - '#type' => 'textfield', + '#type' => 'select', '#title' => t('Title Field'), + '#options' => $field_options, '#default_value' => $this->options['fullcalendar_title_field'], - '#description' => t('The title of the event to be displayed. If blank, the node title will be used. For example: "field_event_title".'), + '#description' => t('Choose the field with the custom title.'), + '#process' => array('form_process_select','ctools_dependent_process'), + '#dependency' => array('edit-row-options-fullcalendar-custom-title' => array(1)), + ); + $form['fullcalendar_custom_url'] = array( + '#type' => 'checkbox', + '#title' => t('Use a custom event redirect url'), + '#default_value' => $this->options['fullcalendar_custom_url'], ); $form['fullcalendar_url_field'] = array( - '#type' => 'textfield', + '#type' => 'select', '#title' => t('URL Field'), + '#options' => $field_options, '#default_value' => $this->options['fullcalendar_url_field'], - '#description' => t('If the calendar items should not link directly to the node, enter the name of the cck field to use for the url instead. For example: "field_url".'), + '#description' => t('Choose the field with the custom link.'), + '#process' => array('ctools_dependent_process'), + '#dependency' => array('edit-row-options-fullcalendar-custom-url' => array(1)), ); } diff --git views_plugin_style_fullcalendar.inc views_plugin_style_fullcalendar.inc index 1672753..1a20159 100644 --- views_plugin_style_fullcalendar.inc +++ views_plugin_style_fullcalendar.inc @@ -29,17 +29,16 @@ 'fc_right' => array('default' => 'month agendaWeek agendaDay'), ), ); - $options['defaults'] = array( - 'contains' => array( - 'fc_year' => array('default' => ''), - 'fc_month' => array('default' => ''), - 'fc_day' => array('default' => ''), - ), - ); $options['times'] = array( 'contains' => array( 'fc_timeformat' => array('default' => 'h:mm{ - h:mm}'), 'fc_clock' => array('default' => FALSE), + 'fc_default_date' => array('default' => FALSE), + 'fc_date' => array('default' => array( + 'year' => '', + 'month' => '', + 'day' => '', + )), ), ); return $options; @@ -49,7 +48,6 @@ $form['display'] = array( '#type' => 'fieldset', '#title' => t('Display settings'), - '#description' => 'Blank values will use the current day, month, or year.', '#attributes' => array( 'class' => 'clear-block', ), @@ -64,20 +62,19 @@ 'agendaDay' => 'Day (Agenda)', 'basicDay' => 'Day (Basic)', ), + '#description' => l(t('More info'), 'http://arshaw.com/fullcalendar/docs/views/Available_Views', array('attributes' => array('target' => '_blank'))), '#default_value' => $this->options['display']['fc_view'], - '#description' => l(t('Default timespan displayed.'), 'http://arshaw.com/fullcalendar/docs/views/Available_Views', array('attributes' => array('target' => '_blank'))), '#prefix' => '
', '#suffix' => '
', ); $form['display']['fc_firstday'] = array( '#type' => 'select', - '#title' => t('First day'), + '#title' => t('Week starts on'), '#options' => array( - '0' => 'Sunday', - '1' => 'Monday', + '0' => t('Sunday'), + '1' => t('Monday'), ), - '#default_value' => $this->options['display']['fc_firstday'], - '#description' => l(t('The day each week begins.'), 'http://arshaw.com/fullcalendar/docs/display/firstDay', array('attributes' => array('target' => '_blank'))), + '#default_value' => t($this->options['display']['fc_firstday']), '#prefix' => '
', '#suffix' => '
', ); @@ -90,21 +87,21 @@ 'variable' => 'Variable', ), '#default_value' => $this->options['display']['fc_weekmode'], - '#description' => l(t('Number of weeks displayed.'), 'http://arshaw.com/fullcalendar/docs/display/weekMode', array('attributes' => array('target' => '_blank'))), + '#description' => l(t('More info'), 'http://arshaw.com/fullcalendar/docs/display/weekMode', array('attributes' => array('target' => '_blank'))), '#prefix' => '
', '#suffix' => '
', ); $form['header'] = array( '#type' => 'fieldset', - '#title' => t('Header elements'), - '#description' => l(t('Buttons and title to be shown in header.'), 'http://arshaw.com/fullcalendar/docs/display/header', array('attributes' => array('target' => '_blank'))), + '#title' => t('Header settings'), + '#description' => l(t('More info'), 'http://arshaw.com/fullcalendar/docs/display/header', array('attributes' => array('target' => '_blank'))), '#attributes' => array( 'class' => 'clear-block', ), ); $form['header']['fc_left'] = array( '#type' => 'textfield', - '#title' => t('Left header'), + '#title' => t('Left'), '#default_value' => $this->options['header']['fc_left'], '#prefix' => '
', '#suffix' => '
', @@ -112,7 +109,7 @@ ); $form['header']['fc_center'] = array( '#type' => 'textfield', - '#title' => t('Center header'), + '#title' => t('Center'), '#default_value' => $this->options['header']['fc_center'], '#prefix' => '
', '#suffix' => '
', @@ -120,51 +117,15 @@ ); $form['header']['fc_right'] = array( '#type' => 'textfield', - '#title' => t('Right header'), + '#title' => t('Right'), '#default_value' => $this->options['header']['fc_right'], '#prefix' => '
', '#suffix' => '
', '#size' => '30', - ); - $form['defaults'] = array( - '#type' => 'fieldset', - '#title' => t('Default values'), - '#description' => 'Blank values will use the current day, month, or year.', - '#attributes' => array( - 'class' => 'clear-block', - ), - ); - $form['defaults']['fc_year'] = array( - '#type' => 'textfield', - '#title' => t('Year'), - '#default_value' => $this->options['defaults']['fc_year'], - '#description' => t('Full 4 digits.'), - '#prefix' => '
', - '#suffix' => '
', - '#size' => '20', - ); - $form['defaults']['fc_month'] = array( - '#type' => 'textfield', - '#title' => t('Month'), - '#default_value' => $this->options['defaults']['fc_month'], - '#description' => t('No leading zeros.'), - '#prefix' => '
', - '#suffix' => '
', - '#size' => '20', - ); - $form['defaults']['fc_day'] = array( - '#type' => 'textfield', - '#title' => t('Day'), - '#default_value' => $this->options['defaults']['fc_day'], - '#description' => t('No leading zeros.'), - '#prefix' => '
', - '#suffix' => '
', - '#size' => '20', ); $form['times'] = array( '#type' => 'fieldset', - '#title' => t('Time display'), - '#description' => l(t('Formatting options for time.'), 'http://arshaw.com/fullcalendar/docs/utilities/formatDate', array('attributes' => array('target' => '_blank'))), + '#title' => t('Time/date settings'), '#attributes' => array( 'class' => 'clear-block', ), @@ -172,19 +133,32 @@ $form['times']['fc_timeformat'] = array( '#type' => 'textfield', '#title' => t('Time format'), + '#description' => l(t('More info'), 'http://arshaw.com/fullcalendar/docs/utilities/formatDate', array('attributes' => array('target' => '_blank'))), '#default_value' => $this->options['times']['fc_timeformat'], - '#description' => 'Format of time display on each event.', ); $form['times']['fc_clock'] = array( '#type' => 'checkbox', '#title' => t('Use 24 hour display'), '#default_value' => $this->options['times']['fc_clock'], - '#description' => 'Use 24 display (ignores custom time format).', + ); + $form['times']['fc_default_date'] = array( + '#type' => 'checkbox', + '#title' => t('Use a custom default date'), + '#default_value' => $this->options['times']['fc_default_date'], + ); + $form['times']['fc_date'] = array( + '#type' => 'date', + '#title' => t('Custom default date'), + '#default_value' => $this->options['times']['fc_date'], + + '#prefix' => '
', + '#suffix' => '
', + '#process' => array('form_process_date', 'ctools_dependent_process'), + '#dependency' => array('edit-style-options-times-fc-default-date' => array(1)), ); $form['modules'] = array( '#type' => 'fieldset', - '#title' => t('Module integration'), - '#description' => 'Settings for integration with other modules.', + '#title' => t('Visual settings'), '#attributes' => array( 'class' => 'clear-block', ), @@ -193,13 +167,13 @@ '#type' => 'checkbox', '#title' => t('Use jQuery UI Theme'), '#default_value' => $this->options['modules']['fc_theme'], - '#description' => t('If checked, the calendar will use any loaded jQuery UI themes.'), ); - $form['modules']['fc_url_colorbox'] = array( - '#type' => 'checkbox', - '#title' => t('Open events in colorbox'), - '#default_value' => $this->options['modules']['fc_url_colorbox'], - '#description' => t('If checked, each event will open in colorbox (if it is installed).'), - ); + if(module_exists('colorbox')) { + $form['modules']['fc_url_colorbox'] = array( + '#type' => 'checkbox', + '#title' => t('Open events in colorbox'), + '#default_value' => $this->options['modules']['fc_url_colorbox'], + ); + } } }