Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Jalali Calendar For Coppermine  (Read 6873 times)

0 Members and 1 Guest are viewing this topic.

Sami

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 3686
  • BMossavari
    • My Project
Jalali Calendar For Coppermine
« on: May 29, 2007, 07:23:52 am »

As subject said with this mod you can convert all [Gregorian] date to Jalali calendar ,

- First Of all take a backup of {gallery-root}/include/functions.inc.php

once again Do not skip this step it's really important to take backup ...

- Now add (Copy & Paste) these lines at the end of functions.inc.php just before ?>
Code: [Select]
/**
 * jdate()
 *
 * Takes Gregorian date from localised_date function
 * and convert it to Jalali calendars by Milad Rastian (miladmovie AT yahoo DOT com)
 * Edited and Moded For Coppermine By B.Mossavari (bmossavarai AT gmail DOT com)
 *
 * @param string $type
 * @param timestamp $maket
 * @return string
 **/

function jdate($type,$maket="now")
{
//set 1 if you want translate number to farsi or if you don't like set 0
$transnumber=1;
///chosse your timezone
$TZhours=0;
$TZminute=0;

if($maket=="now"){
$year=date("Y");
$month=date("m");
$day=date("d");
list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
$maket=jmaketime(date("h")+$TZhours,date("i")+$TZminute,date("s"),$jmonth,$jday,$jyear);
}else{
$maket += $TZhours*3600+$TZminute*60;
$date = date("Y-m-d",$maket);
list( $year, $month, $day ) = preg_split ( '/-/', $date );

list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
}

$need= $maket;
$year=date("Y",$need);
$month=date("m",$need);
$day=date("d",$need);
$i=0;
$result ='';
while($i<strlen($type))
{
$subtype=substr($type,$i,1);
switch ($subtype)
{

case "%":
break;
case "p":
$result1=date("a",$need);
if($result1=="pm") $result.= "&#1576;&#1593;&#1583;&#1575;&#1586;&#1592;&#1607;&#1585;";
else $result.="&#1602;&#1576;&#1604;&#8207;&#1575;&#1586;&#1592;&#1607;&#1585;";
break;

case "a":
$result1=date("a",$need);
if($result1=="pm") $result.= "&#1576;&#46;&#1592;";
else $result.="&#1602;&#46;&#1592;";
break;
case "d":
list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
if($jday<10)$result1="0".$jday;
else $result1=$jday;
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
case "D":
$result1=date("D",$need);
if($result1=="Thu") $result1="&#1662;";
else if($result1=="Sat") $result1="&#1588;";
else if($result1=="Sun") $result1="&#1609;";
else if($result1=="Mon") $result1="&#1583;";
else if($result1=="Tue") $result1="&#1587;";
else if($result1=="Wed") $result1="&#1670;";
else if($result1=="Thu") $result1="&#1662;";
else if($result1=="Fri") $result1="&#1580;";
$result.=$result1;
break;
case"B":
list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
$result.=monthname($jmonth);
break;
case "g":
$result1=date("g",$need);
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
case "G":
$result1=date("G",$need);
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
case "I":
$result1=date("h",$need);
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
case "H":
$result1=date("H",$need);
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
case "i":
$result1=date("i",$need);
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
case "j":
list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
$result1=$jday;
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
case "l":
$result1=date("l",$need);
if($result1=="Saturday") $result1="&#1588;&#1606;&#1576;&#1607;";
else if($result1=="Sunday") $result1="&#1610;&#1603;&#1588;&#1606;&#1576;&#1607;";
else if($result1=="Monday") $result1="&#1583;&#1608;&#1588;&#1606;&#1576;&#1607;";
else if($result1=="Tuesday") $result1="&#1587;&#1607;&#32;&#1588;&#1606;&#1576;&#1607;";
else if($result1=="Wednesday") $result1="&#1670;&#1607;&#1575;&#1585;&#1588;&#1606;&#1576;&#1607;";
else if($result1=="Thursday") $result1="&#1662;&#1606;&#1580;&#1588;&#1606;&#1576;&#1607;";
else if($result1=="Friday") $result1="&#1580;&#1605;&#1593;&#1607;";
$result.=$result1;
break;
case "m":
list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
if($jmonth<10) $result1="0".$jmonth;
else $result1=$jmonth;
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
case "M":
$result1=date("i",$need);
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
case "n":
list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
$result1=$jmonth;
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
case "s":
$result1=date("s",$need);
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
case "S":
$result.="&#1575;&#1605;";
break;
case "t":
$result.=lastday ($month,$day,$year);
break;
case "w":
$result1=date("w",$need);
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
case "y":
list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
$result1=substr($jyear,2,4);
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
case "Y":
list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
$result1=$jyear;
if($transnumber==1) $result.=Convertnumber2farsi($result1);
else $result.=$result1;
break;
default:
$result.=$subtype;
}
$i++;
}
return $result;
}



///Find Day Begining Of Month
function mstart($month,$day,$year)
{
list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
list( $year, $month, $day ) = jalali_to_gregorian($jyear, $jmonth, "1");
$timestamp=mktime(0,0,0,$month,$day,$year);
return date("w",$timestamp);
}

//Find Number Of Days In This Month
function lastday ($month,$day,$year)
{
$lastdayen=date("d",mktime(0,0,0,$month+1,0,$year));
list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
$lastdatep=$jday;
$jday=$jday2;
while($jday2!="1")
{
if($day<$lastdayen)
{
$day++;
list( $jyear, $jmonth, $jday2 ) = gregorian_to_jalali($year, $month, $day);
if($jdate2=="1") break;
if($jdate2!="1") $lastdatep++;
}
else
{
$day=0;
$month++;
if($month==13)
{
$month="1";
$year++;
}
}

}
return $lastdatep-1;
}

//translate number of month to name of month
function monthname($month)
{

    if($month=="01") return "&#1601;&#1585;&#1608;&#1585;&#1583;&#1610;&#1606;";

    if($month=="02") return "&#1575;&#1585;&#1583;&#1610;&#1576;&#1607;&#1588;&#1578;";

    if($month=="03") return "&#1582;&#1585;&#1583;&#1575;&#1583;";

    if($month=="04") return  "&#1578;&#1610;&#1585;";

    if($month=="05") return "&#1605;&#1585;&#1583;&#1575;&#1583;";

    if($month=="06") return "&#1588;&#1607;&#1585;&#1610;&#1608;&#1585;";

    if($month=="07") return "&#1605;&#1607;&#1585;";

    if($month=="08") return "&#1570;&#1576;&#1575;&#1606;";

    if($month=="09") return "&#1570;&#1584;&#1585;";

    if($month=="10") return "&#1583;&#1610;";

    if($month=="11") return "&#1576;&#1607;&#1605;&#1606;";

    if($month=="12") return "&#1575;&#1587;&#1601;&#1606;&#1583;";
}

////here convert to  number in persian
function Convertnumber2farsi($srting)
{
$num0="&#1776;";
$num1="&#1777;";
$num2="&#1778;";
$num3="&#1779;";
$num4="&#1780;";
$num5="&#1781;";
$num6="&#1782;";
$num7="&#1783;";
$num8="&#1784;";
$num9="&#1785;";

$stringtemp="";
$len=strlen($srting);
for($sub=0;$sub<$len;$sub++)
{
if(substr($srting,$sub,1)=="0")$stringtemp.=$num0;
elseif(substr($srting,$sub,1)=="1")$stringtemp.=$num1;
elseif(substr($srting,$sub,1)=="2")$stringtemp.=$num2;
elseif(substr($srting,$sub,1)=="3")$stringtemp.=$num3;
elseif(substr($srting,$sub,1)=="4")$stringtemp.=$num4;
elseif(substr($srting,$sub,1)=="5")$stringtemp.=$num5;
elseif(substr($srting,$sub,1)=="6")$stringtemp.=$num6;
elseif(substr($srting,$sub,1)=="7")$stringtemp.=$num7;
elseif(substr($srting,$sub,1)=="8")$stringtemp.=$num8;
elseif(substr($srting,$sub,1)=="9")$stringtemp.=$num9;
else $stringtemp.=substr($srting,$sub,1);

}
return   $stringtemp;

}///end conver to number in persian

function div($a,$b) {
    return (int) ($a / $b);
}

/**
 * gregorian_to_jalali ()
 *
 * Convert Gregorian to Jalali calendars
 * Copyright (C) 2000  Roozbeh Pournader and Mohammad Toossi
 *
 * @param int $g_y
 * @param int $g_m
 * @param int $g_d
 * @return array
 **/

function gregorian_to_jalali ($g_y, $g_m, $g_d)
{
    $g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    $j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);     
   


   

   $gy = $g_y-1600;
   $gm = $g_m-1;
   $gd = $g_d-1;

   $g_day_no = 365*$gy+div($gy+3,4)-div($gy+99,100)+div($gy+399,400);

   for ($i=0; $i < $gm; ++$i)
      $g_day_no += $g_days_in_month[$i];
   if ($gm>1 && (($gy%4==0 && $gy%100!=0) || ($gy%400==0)))
      /* leap and after Feb */
      $g_day_no++;
   $g_day_no += $gd;

   $j_day_no = $g_day_no-79;

   $j_np = div($j_day_no, 12053); /* 12053 = 365*33 + 32/4 */
   $j_day_no = $j_day_no % 12053;

   $jy = 979+33*$j_np+4*div($j_day_no,1461); /* 1461 = 365*4 + 4/4 */

   $j_day_no %= 1461;

   if ($j_day_no >= 366) {
      $jy += div($j_day_no-1, 365);
      $j_day_no = ($j_day_no-1)%365;
   }

   for ($i = 0; $i < 11 && $j_day_no >= $j_days_in_month[$i]; ++$i)
      $j_day_no -= $j_days_in_month[$i];
   $jm = $i+1;
   $jd = $j_day_no+1;

   return array($jy, $jm, $jd);
}

- Finally you need to change localised_date function
go to line #366 and find this function and change it with this:
Code: [Select]
function localised_date($timestamp = -1, $datefmt)
{
    global $lang_month, $lang_day_of_week, $CONFIG;

    $timestamp = localised_timestamp($timestamp);
if($CONFIG['lang'] == 'persian'){ // Jalali calendar mod
return jdate($datefmt,$timestamp);// Jalali calendar mod

}else{
    $date = ereg_replace('%[aA]', $lang_day_of_week[(int)strftime('%w', $timestamp)], $datefmt);
    $date = ereg_replace('%[bB]', $lang_month[(int)strftime('%m', $timestamp)-1], $date);

    return strftime($date, $timestamp);
}
}
You can add your desire language to if statement
this mod add jalali calender for persian language by default

« Last Edit: May 29, 2007, 08:22:54 am by GauGau »
Logged
‍I don't answer to PM with support question
Please post your issue to related board
Pages: [1]   Go Up
 

Page created in 0.02 seconds with 20 queries.