View source
<?php
if (!defined('AC_ISODATE')) {
define('AC_ISODATE', 'Y-m-d');
}
define('AC_ALLOCATION_TYPE_FULLDAY', 'day');
define('AC_ALLOCATION_TYPE_OVERNIGHT', 'night');
define('AC_DATE_DISPLAY', 'l j F Y');
define('AC_DATE_ENTRY', 'Y-n-j');
define('AC_DATE_MONTH_CAPTION', 'F Y');
module_load_include('inc', 'availability_calendar', 'availability_calendar.field');
function availability_calendar_views_api() {
return array(
'api' => '3.0',
'path' => drupal_get_path('module', 'availability_calendar') . '/views',
);
}
function availability_calendar_init() {
drupal_add_css(drupal_get_path('module', 'availability_calendar') . '/availability_calendar.base.css', array(
'every_page' => TRUE,
));
$file = 'public://availability_calendar/availability_calendar.css';
if (is_readable($file)) {
drupal_add_css($file, array(
'every_page' => TRUE,
));
}
}
function availability_calendar_permission() {
return array(
'administer availability calendar' => array(
'title' => t('Administer the Availability Calendar field'),
'description' => t('Define the site wide states that can be used by Availability Calendar fields.'),
),
'style availability calendar' => array(
'title' => t('Define styles for the Availability Calendar field'),
'description' => t('Define a number of styles for Availability Calendar fields via the UI'),
),
);
}
function availability_calendar_menu() {
$items = array();
$items['admin/config/content/availability-calendar'] = array(
'title' => 'Availability Calendar',
'description' => 'Configure site-wide settings for availability calendar fields.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'availability_calendar_admin_settings',
),
'access arguments' => array(
'administer availability calendar',
),
'file' => 'availability_calendar.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
$items['admin/config/content/availability-calendar/settings'] = array(
'title' => 'Site-wide settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/config/content/availability-calendar/styling'] = array(
'title' => 'Styling',
'description' => 'Define CSS styles for availability calendar fields.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'availability_calendar_styles',
),
'access arguments' => array(
'style availability calendar',
),
'file' => 'availability_calendar.styles.inc',
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function availability_calendar_theme() {
$file = 'availability_calendar.theme.inc';
$theme_hook_info = array(
'file' => $file,
'variables' => array(
'cid' => NULL,
'cvid' => NULL,
'name' => '',
'year' => 0,
'month' => 0,
'settings' => array(),
'states' => array(),
'availability' => array(),
),
);
return array(
'availability_calendar' => $theme_hook_info,
'availability_calendar_colorbox' => $theme_hook_info,
'availability_calendar_viewport' => $theme_hook_info,
'availability_calendar_months' => $theme_hook_info,
'availability_calendar_month' => $theme_hook_info,
'availability_calendar_viewport_button' => array(
'file' => $file,
'variables' => array(
'direction' => 'forward',
'scroll' => 6,
),
),
'availability_calendar_key' => array(
'file' => $file,
'variables' => array(
'states_to_show' => array(),
),
),
);
}
function availability_calendar_date_format_types() {
return array(
'availability_calendar_date_display' => t('Availability Calendar date display'),
'availability_calendar_date_entry' => t('Availability Calendar date entry'),
'availability_calendar_month_caption' => t('Availability Calendar month caption'),
);
}
function availability_calendar_date_formats() {
$formats = array();
$formats[] = array(
'type' => 'availability_calendar_date_display',
'format' => AC_DATE_DISPLAY,
'locales' => array(),
);
$formats[] = array(
'type' => 'availability_calendar_date_display',
'format' => 'l F j, Y',
'locales' => array(
'en-us',
),
);
$formats[] = array(
'type' => 'availability_calendar_date_entry',
'format' => AC_DATE_ENTRY,
'locales' => array(),
);
$formats[] = array(
'type' => 'availability_calendar_date_entry',
'format' => 'Y/n/j',
'locales' => array(
'en-ca',
'fr-ca',
'no-no',
'sv-se',
),
);
$formats[] = array(
'type' => 'availability_calendar_date_entry',
'format' => 'j-n-Y',
'locales' => array(
'nl-nl',
),
);
$formats[] = array(
'type' => 'availability_calendar_date_entry',
'format' => 'j/n/Y',
'locales' => array(
'en-gb',
'en-hk',
'en-ie',
'el-gr',
'es-es',
'fr-be',
'fr-fr',
'fr-lu',
'it-it',
'nl-be',
'pt-pt',
),
);
$formats[] = array(
'type' => 'availability_calendar_date_entry',
'format' => 'j.n.Y',
'locales' => array(
'de-ch',
'de-de',
'de-lu',
'fi-fi',
'fr-ch',
'is-is',
'pl-pl',
'ro-ro',
'ru-ru',
),
);
$formats[] = array(
'type' => 'availability_calendar_date_entry',
'format' => 'n/j/Y',
'locales' => array(
'en-us',
),
);
$formats[] = array(
'type' => 'availability_calendar_month_caption',
'format' => AC_DATE_MONTH_CAPTION,
'locales' => array(),
);
return $formats;
}
function availability_calendar_block_info() {
$blocks = array(
'key' => array(
'info' => t('Availability Calendar Key'),
'cache' => DRUPAL_CACHE_GLOBAL,
),
);
return $blocks;
}
function availability_calendar_block_configure($delta = '') {
module_load_include('inc', 'availability_calendar', 'availability_calendar');
$form = array();
if ($delta == 'key') {
$form['availability_calendar_block_states_to_show'] = array(
'#type' => 'checkboxes',
'#title' => t('States to show'),
'#description' => t('Check the availability states that are to be shown in the key.') . ' ' . t('Checking no states at all will allow all states.'),
'#default_value' => variable_get('availability_calendar_block_states_to_show', array()),
'#options' => availability_calendar_get_states('label'),
);
}
return $form;
}
function availability_calendar_block_save($delta = '', $edit = array()) {
if ($delta == 'key') {
variable_set('availability_calendar_block_states_to_show', $edit['availability_calendar_block_states_to_show']);
}
}
function availability_calendar_block_view($delta = '') {
$block = array();
if ($delta == 'key') {
$block['subject'] = t('Availability Key');
$block['content'] = array(
'#theme' => 'availability_calendar_key',
'#states_to_show' => variable_get('availability_calendar_block_states_to_show', array()),
);
}
return $block;
}
function availability_calendar_js_alter(&$javascript) {
if (function_exists('availability_calendar_handler_filter_availability_js_alter')) {
availability_calendar_handler_filter_availability_js_alter($javascript);
}
}
function availability_calendar_i18n_sync_availability_calendar_field($entity_type, $entity, $field, $instance, $langcode, &$items, $source_entity, $source_language) {
$field_name = $instance['field_name'];
$existing_items = field_get_items($entity_type, $entity, $instance['field_name'], $langcode);
$existing_calendars = array();
if ($existing_items !== FALSE) {
foreach ($existing_items as $calendar) {
$existing_calendars[$calendar['cid']] = $calendar;
}
}
$property = 'name';
foreach ($items as &$calendar) {
if (array_key_exists($calendar['cid'], $existing_calendars)) {
if (!empty($existing_calendars[$calendar['cid']][$property])) {
$calendar[$property] = $existing_calendars[$calendar['cid']][$property];
}
}
}
}