Elxis CMS Forum
Support => Language => Topic started by: vahid4134 on November 28, 2009, 21:00:31
-
1- download http://iranphp.org/system/files/pdate.php_.tar_.gz and extract.
2- copy pdate.php into includes folder
3- In includes/Core/loader.php after
//Load Elxis Core
require_once($mosConfig_absolute_path.'/includes/Core/elxis.php');
add this
//Persian date
require_once( $mosConfig_absolute_path.'/includes/pdate.php' );
iranphp.org
4- In includes/Core/locale.php change strftime_os method to
static function strftime_os($format, $ts = null) {
if(defined("_DATETYPE") and _DATETYPE=="persian"){
$dateFunction="pdate";
$strftimeFunction="pstrftime";
}
else{
$dateFunction="date";
$strftimeFunction="strftime";
}
if( strtoupper(substr(php_uname(), 0, 3)) == 'WIN' ) {
if (!$ts) { $ts = time(); }
$mapping = array(
'%C' => sprintf("%02d", $dateFunction("Y", $ts) / 100),
'%D' => '%m/%d/%y',
'%e' => sprintf("%' 2d", $dateFunction("j", $ts)),
'%h' => '%b',
'%n' => "\n",
'%r' => date("h:i:s", $ts) . " %p",
'%R' => date("H:i", $ts),
'%t' => "\t",
'%T' => '%H:%M:%S',
'%u' => ($w = $dateFunction("w", $ts)) ? $w : 7
);
$format = str_replace( array_keys($mapping), array_values($mapping), $format );
}
return $strftimeFunction($format, $ts);
}
5- add
define('_DATETYPE','persian');
in language file
-
Thanks vahid,
I will check your contribution and if it is OK we will include it into Elxis core for the 2009.2 release.
-
Thanks
if any problem report me to fix
In joomla persian (jalali) date is support. but elxis is very better
-
for support calendar:
replace calander.zip (from atachment) to includes/js/calander (this file I dont change language file : ex must change calendar-fr.js to calendar-french.js).
in file includes/js/elxis.js change showCalendar function to
function showCalendar(id) {
var el = document.getElementById(id);
if (calendar != null) {
// we already have one created, so just update it.
calendar.hide(); // hide the existing calendar
calendar.parseDate(el.value); // set it to a new date
} else {
// first-time call, create the calendar
var cal = new Calendar(true, null, selected, closeHandler);
cal.setDateType(CalendarDateType);
calendar = cal; // remember the calendar in the global
if(CalendarDateType=="jalali"){
cal.setRange(1340, 1450); // min/max year allowed
}
else{
cal.setRange(1900, 2070); // min/max year allowed
}
calendar.create(); // create a popup calendar
}
calendar.sel = el; // inform it about the input field in use
calendar.showAtElement(el); // show the calendar next to the input field
// catch mousedown on the document
Calendar.addEvent(document, "mousedown", checkCalendar);
return false;
}
in includes/core/elxis.php
change loadCalendar method to
static public function loadCalendar() {
global $mainframe;
if (defined('elxcalincl')) { return; }
define('elxcalincl', 1);
$lng = (defined('_ELXIS_ADMIN')) ? $GLOBALS['alang'] : $GLOBALS['lang'];
$lh = 1;
if (headers_sent() || (ob_get_length() > 0)) { $lh = 0; }
if (!file_exists($mainframe->getCfg('absolute_path').'/includes/js/calendar/lang/calendar-'.$lng.'.js')) { $lng = 'english'; }
$baseurl = $mainframe->getCfg('live_site').'/includes/js/calendar';
if(defined("_DATETYPE") and _DATETYPE=="persian"){
$CalendarDateType="jalali";
}
else{
$CalendarDateType="gregorian";
}
echo '<script type="text/javascript"> var CalendarDateType="'.$CalendarDateType.'"</script>'."\n";
if ($lh === 0) {
echo '<script type="text/javascript">document.write(\'<link rel="stylesheet" type="text/css" media="all" href="'.$baseurl.'/calendar-mos.css" />\');</script>'."\n";
echo '<script type="text/javascript" src="'.$baseurl.'/jalali.js"></script>'."\n";
echo '<script type="text/javascript" src="'.$baseurl.'/calendar.js"></script>'."\n";
echo '<script type="text/javascript" src="'.$baseurl.'/lang/calendar-'.$lng.'.js"></script>'."\n";
} else {
$mainframe->addCustomHeadTag('<link rel="stylesheet" type="text/css" media="all" href="'.$baseurl.'/calendar-mos.css" />');
$mainframe->addCustomHeadTag('<script type="text/javascript" src="'.$baseurl.'/jalali.js"></script>');
$mainframe->addCustomHeadTag('<script type="text/javascript" src="'.$baseurl.'/calendar.js"></script>');
$mainframe->addCustomHeadTag('<script type="text/javascript" src="'.$baseurl.'/lang/calendar-'.$lng.'.js" charset="utf-8"></script>');
}
}
and change mosFormatDate function to
function mosFormatDate($date, $format='', $offset='',$forSave=false) {
global $mosConfig_offset;
if ($format == '') { $format = _GEM_DATE_FORMLC; } //%Y-%m-%d %H:%M:%S
if ($offset == '') { $offset = $mosConfig_offset; }
if ($date && preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})[\s]([0-9]{2}):([0-9]{2}):([0-9]{2})$/", $date, $regs)) {
if(defined("_DATETYPE") and _DATETYPE=="persian" and $forSave){
$date = pmktime( $regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1] );
}
else{
$date = mktime( $regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1] );
}
$date = $date > -1 ? eLOCALE::strftime_os( $format, $date + ($offset*60*60) ,$forSave) : '-';
}
return $date;
}
In includes/Core/locale.php change strftime_os method to
static function strftime_os($format, $ts = null,$forSave=false) {
if(defined("_DATETYPE") and _DATETYPE=="persian" and !$forSave){
$dateFunction="pdate";
$strftimeFunction="pstrftime";
}
else{
$dateFunction="date";
$strftimeFunction="strftime";
}
if( strtoupper(substr(php_uname(), 0, 3)) == 'WIN' ) {
if (!$ts) { $ts = time(); }
$mapping = array(
'%C' => sprintf("%02d", $dateFunction("Y", $ts) / 100),
'%D' => '%m/%d/%y',
'%e' => sprintf("%' 2d", $dateFunction("j", $ts)),
'%h' => '%b',
'%n' => "\n",
'%r' => date("h:i:s", $ts) . " %p",
'%R' => date("H:i", $ts),
'%t' => "\t",
'%T' => '%H:%M:%S',
'%u' => ($w = $dateFunction("w", $ts)) ? $w : 7
);
$format = str_replace( array_keys($mapping), array_values($mapping), $format );
}
return $strftimeFunction($format, $ts);
}
in administrator/components/com_content/admin.content.php
change
$isNew = ( $row->id < 1 );
if ($isNew) {
$row->created = $row->created ? mosFormatDate( $row->created, $adminLanguage->A_CMP_CNT_DROWCRED, -$mainframe->getCfg('offset')) : date( $adminLanguage->A_CMP_CNT_DATEFORMAT );
$row->created_by = $row->created_by ? $row->created_by : $my->id;
} else {
$row->modified = date( $adminLanguage->A_CMP_CNT_DATEFORMAT );
$row->modified_by = $my->id;
$row->created = $row->created ? mosFormatDate( $row->created, $adminLanguage->A_CMP_CNT_DROWCRED, -$mainframe->getCfg('offset')) : date( $adminLanguage->A_CMP_CNT_DATEFORMAT );
$row->created_by = $row->created_by ? $row->created_by : $my->id;
}
to
$isNew = ( $row->id < 1 );
if ($isNew) {
$row->created = $row->created ? mosFormatDate( $row->created, $adminLanguage->A_CMP_CNT_DROWCRED, -$mainframe->getCfg('offset'),true) : date( $adminLanguage->A_CMP_CNT_DATEFORMAT ,true );
$row->created_by = $row->created_by ? $row->created_by : $my->id;
} else {
$row->modified = date( $adminLanguage->A_CMP_CNT_DATEFORMAT );
$row->modified_by = $my->id;
$row->created = $row->created ? mosFormatDate( $row->created, $adminLanguage->A_CMP_CNT_DROWCRED, -$mainframe->getCfg('offset'),true) : date( $adminLanguage->A_CMP_CNT_DATEFORMAT, true );
$row->created_by = $row->created_by ? $row->created_by : $my->id;
}
and change
if (eUTF::utf8_trim( $row->publish_down ) == $adminLanguage->A_CMP_CNT_PBLINEV) {
$row->publish_down = "2060-01-01 00:00:00";
}
to
if (eUTF::utf8_trim( $row->publish_down ) == $adminLanguage->A_CMP_CNT_PBLINEV) {
$row->publish_down = "2060-01-01 00:00:00";
}
else{
$row->publish_down = mosFormatDate($row->publish_down, $adminLanguage->A_CMP_CNT_DROWPUB, -$mainframe->getCfg('offset'),true);
}
in administrator/components/com_users/admin.users.php change
$expdate = ($row->expires == '2060-01-01 00:00:00') ? $adminLanguage->A_NEVER : mosFormatDate($row->expires, _GEM_DATE_FORMLC);
$expdate = ($row->expires == '2060-01-01 00:00:00') ? $adminLanguage->A_NEVER : mosFormatDate($row->expires, _GEM_DATE_FORMLC,true);
[attachment deleted by admin]
-
oh , Why I didn't see this topic :D
currently I converted all dates to Jalali in Persian language ....
Thank you vahid :)
-
For your information:
The upcoming Elxis Nautilus has native Jalali dates support!
-
Yes John , I saw that code
Thank you ;)
-
And not only. It supports automatic conversions from one date system to an other, user preferable timezones (see site dates in your local datetime), world date (see any date as it is/was on any place in the world), and much more. The Elxis core stores are dates in UTC (GMT) and displays them in your preferable timezone/format.