View source
<?php
function calendar_systems_init() {
@(include_once 'PEAR.php');
if (!class_exists('PEAR')) {
require_once dirname(__FILE__) . '/calendar/lib/PEAR.php';
}
require_once dirname(__FILE__) . '/calendar/lib/classesCore.class.inc.php';
require_once dirname(__FILE__) . '/calendar/calendar.class.inc.php';
}
function calendar_systems_get_active_lang() {
if (module_exists('path')) {
$pathAlias = drupal_get_path_alias($_GET['q']);
}
else {
$pathAlias = $_GET['q'];
}
if (preg_match("/(\\/|^)(fa)(\\/|\$)/i", $pathAlias)) {
return 'fa';
}
else {
return 'en';
}
}
function calendar_systems_get_calendar_instance() {
if (calendar_systems_get_active_lang() == 'fa') {
$calendar = cmfcCalendar::factory('v1', array(
'name' => 'iranian',
));
}
else {
$calendar = cmfcCalendar::factory('v1', array(
'name' => 'gregorian',
));
}
return $calendar;
}
function calendar_systems_format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL) {
$calendar = calendar_systems_get_calendar_instance();
if (!isset($timezone)) {
global $user;
if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
$timezone = $user->timezone;
}
else {
$timezone = variable_get('date_default_timezone', 0);
}
}
$timestamp += $timezone;
switch ($type) {
case 'small':
$format = variable_get('date_format_short', 'm/d/Y - H:i');
break;
case 'large':
$format = variable_get('date_format_long', 'l, F j, Y - H:i');
break;
case 'custom':
break;
case 'medium':
default:
$format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
}
$max = strlen($format);
$date = '';
for ($i = 0; $i < $max; $i++) {
$c = $format[$i];
if (strpos('AaDFlM', $c) !== FALSE) {
$date .= t($calendar
->timestampToStr($c, $timestamp));
}
else {
if (strpos('BdgGhHiIjLmnsStTUwWYyz', $c) !== FALSE) {
$date .= $calendar
->timestampToStr($c, $timestamp);
}
else {
if ($c == 'r') {
$date .= calendar_systems_format_date($timestamp - $timezone, 'custom', 'D, d M Y H:i:s O', $timezone);
}
else {
if ($c == 'O') {
$date .= sprintf('%s%02d%02d', $timezone < 0 ? '-' : '+', abs($timezone / 3600), abs($timezone % 3600) / 60);
}
else {
if ($c == 'Z') {
$date .= $timezone;
}
else {
if ($c == '\\') {
$date .= $format[++$i];
}
else {
$date .= $c;
}
}
}
}
}
}
}
return $date;
}
function calendar_systems_form_alter($form_id, &$form) {
if (!empty($form['#post']['date'])) {
$calendar = calendar_systems_get_calendar_instance();
$form['#post']['date'] = $calendar
->strToTimestamp($form['#post']['date']);
$form['#post']['date'] = date('Y-m-d H:i:s', $form['#post']['date']);
}
}