View source
<?php
require_once 'datex_api_classes.inc';
function datex_api_help($path, $arg) {
if ($path == 'admin/config/regional/date-time/datex_api' || $path == 'admin/help#datex_api') {
$output = '<p>';
$output .= t('PHP-Intl is a php library available at !link', array(
'!link' => l(t('Here'), 'http://pecl.php.net/intl'),
));
$output .= '</p>';
if (class_exists('IntlDateFormatter')) {
$output .= t('It is currently available for this Drupal installation environment and can be used.');
}
else {
$output .= t('It is currently NOT available for this Drupal installation environment and enabling this option will not affect the way %module works.', array(
'%module' => 'Datex API',
));
}
$output .= '</p><p>';
$output .= t('You can read more about it at !link', array(
'!link' => l(t('Here'), 'http://www.drupalion.com/blog/123'),
));
$output .= '</p>';
return $output;
}
}
function datex_api_menu() {
$items['admin/config/regional/date-time/datex_api'] = array(
'title' => 'Datex API',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'datex_api_admin_form',
),
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function datex_api_admin_form() {
$options = array(
DATEX_USE_INTL => t('Use PHP-INTL'),
!DATEX_USE_INTL => t('Use datex internal methods.'),
);
$form['datex_api_intl'] = array(
'#type' => 'radios',
'#title' => t('Date conversion method'),
'#default_value' => variable_get('datex_api_intl', 0),
'#description' => t('Which method datex should use. Intl is experimental'),
'#options' => $options,
);
$options = array(
FALSE => t('Do not use widgets'),
TRUE => t('Add widgets'),
);
$form['datex_jquery'] = array(
'#type' => 'radios',
'#title' => t('Use jQuery widgets in forms.'),
'#default_value' => variable_get('datex_jquery', 0),
'#description' => t('If a jQuery date widget should be added to forms, Such as node add/edit form. This option does not affect date module.'),
'#options' => $options,
);
if (!module_exists('libraries')) {
$status = t('Can not use datex jquery, Libraries module is missing.');
$ok = 0;
}
elseif (TRUE) {
$status = t('Can not use datex jquery, Library files are missing from sites/all/libararies.');
$ok = 0;
}
else {
$status = t('Everything is OK and datex widget will work.');
$ok = 1;
}
$form['datex_status'] = array(
'#type' => 'markup',
'#markup' => t('Current datex jquery status: ') . '<h4>' . $status . '</h4>',
);
if (!$ok) {
$form['datex_jquery']['#disabled'] = TRUE;
$form['datex_jquery']['#default_value'] = 0;
}
$options = array();
foreach (language_list() as $lang) {
$options[$lang->language] = $lang->name . '(' . $lang->native . ')';
}
$form['datex_api_enabled_langs'] = array(
'#type' => 'checkboxes',
'#title' => t('Enabled languages'),
'#default_value' => variable_get('datex_api_enabled_langs', array(
'fa' => 'fa',
)),
'#description' => t("Drupal's date will be displayed in Jalali only in selected languages"),
'#options' => $options,
);
return system_settings_form($form);
}
function datex_format($date, $format, $tz = NULL, $use_intl = 'check first', &$intl_args = array()) {
if ($use_intl === 'check first') {
$use_intl == _datex_intl();
}
if (!$tz) {
$tz = drupal_get_user_timezone();
}
return DatexFormatter::format($date, $format, $tz, $use_intl, $intl_args);
}
function datex_date($format, $timestamp = NULL) {
return DatexObjectUtils::date($format, $timestamp);
}
function _datex_intl() {
return variable_get('datex_api_intl', 0);
}
function datex_libraries_info() {
$libraries = array();
$libraries['jquery.datepick'] = array(
'name' => 'jQuery Datepick',
'vendor url' => 'http://keith-wood.name/',
'download url' => 'http://keith-wood.name/datepick.html',
'version callback' => '_datex_jquery_intl_version_callback',
'files' => array(
'js' => array(
'jquery.datepick.min.js',
),
'css' => array(
'ui.datepick.css',
'jquery.datepick.css',
),
),
);
$libraries['jquery.datepick.fa'] = array(
'name' => ' jQuery Datepicker Persian',
'vendor url' => 'http://keith-wood.name/',
'download url' => 'http://keith-wood.name/calendars.html',
'version callback' => '_datex_jquery_intl_version_callback',
'files' => array(
'js' => array(
'jquery.datepicker.fa.js',
),
),
);
$libraries['jquery.dateentry'] = array(
'name' => 'jQuery Date Entry',
'vendor url' => 'http://keith-wood.name/',
'download url' => 'http://keith-wood.name/dateEntry.html',
'version callback' => '_datex_jquery_intl_version_callback',
'files' => array(
'js' => array(
'jquery.dateentry.pack.js',
),
'css' => array(
'jquery.dateentry.css',
),
),
);
$libraries['jquery.dateentry.fa'] = array(
'name' => ' jQuery Datepicker Persian',
'vendor url' => 'http://keith-wood.name/',
'download url' => 'http://keith-wood.name/calendars.html',
'version callback' => '_datex_jquery_intl_version_callback',
'files' => array(
'js' => array(
'jquery.datepicker.fa.js',
),
),
);
$libraries['jquery.timeentry'] = array(
'name' => ' jQuery Time Entry',
'vendor url' => 'http://keith-wood.name/',
'download url' => 'http://keith-wood.name/timeEntry.html',
'version callback' => '_datex_jquery_intl_version_callback',
'files' => array(
'js' => array(
'jquery.timeentry.pack.js',
),
'css' => array(
'jquery.timeentry.css',
),
),
);
$libraries['jquery.timeentry.fa'] = array(
'name' => ' jQuery DateTime Entry Persian',
'vendor url' => 'http://keith-wood.name/',
'download url' => 'http://keith-wood.name/calendars.html',
'version callback' => '_datex_jquery_intl_version_callback',
'files' => array(
'js' => array(
'jquery.timeentry.fa.js',
),
),
);
$libraries['jquery.datetimeentry'] = array(
'name' => ' jQuery DateTime Entry',
'vendor url' => 'http://keith-wood.name/',
'download url' => 'http://keith-wood.name/datetimeEntry.html',
'version callback' => '_datex_jquery_intl_version_callback',
'files' => array(
'js' => array(
'jquery.datetimeentry.min.js',
),
'css' => array(
'jquery.datetimeentry.css',
),
),
);
$libraries['jquery.datetimeentry.fa'] = array(
'name' => ' jQuery DateTime Entry Persian',
'vendor url' => 'http://keith-wood.name/',
'download url' => 'http://keith-wood.name/calendars.html',
'version callback' => '_datex_jquery_intl_version_callback',
'files' => array(
'js' => array(
'jquery.datetimeentry.fa.js',
),
),
);
return $libraries;
}
function _datex_jquery_intl_version_callback() {
return 1;
}
function _datex_jquery_add_libraries($libraries = NULL, $intl = NULL) {
if (!function_exists('libraries_load')) {
return;
}
$intl = $intl === TRUE ? 'fa' : $intl;
if (is_array($libraries)) {
unset($libraries['jquery.calendars']);
foreach ($libraries as $library) {
libraries_load($library);
if ($intl) {
libraries_load($library . ".{$intl}");
}
}
}
elseif (is_string($libraries)) {
libraries_load($libraries);
if ($intl) {
libraries_load($libraries . ".{$intl}");
}
}
}
function _datex_skip_language($language = NULL) {
if (!$language) {
$language = $GLOBALS['language']->language;
}
$enabled_languages = variable_get('datex_api_enabled_langs', array(
'fa' => 'fa',
));
$enabled = isset($enabled_languages[$language]) ? $enabled_languages[$language] : 0;
return $enabled === 0;
}