Archive plugin for Jalali fixed.
authoromidmottaghi <omidmottaghi>
Mon, 24 Oct 2005 18:54:51 +0000 (18:54 +0000)
committeromidmottaghi <omidmottaghi>
Mon, 24 Oct 2005 18:54:51 +0000 (18:54 +0000)
Some new Jalali functions added and some debugged.

include/functions.inc.php
include/functions_calendars.inc.php
include/plugin_internal.inc.php

index 88337ddcf1d825a37b5c2e950cccc67072bdd9e7..9d1d4b6507802a9563f5ee5d235596f91568a8cb 100644 (file)
@@ -63,7 +63,7 @@ function serendipity_strftime($format, $timestamp = null, $useOffset = true) {
             }
 
             require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php';
-            return calendar_jalali_utf($format, $timestamp);
+            return jalali_strftime_utf($format, $timestamp);
     }
 }
 
index 906e0e6307940b40ad9034b4e8bd434004ef343d..a512019a469c94f9c2bc7bf28965bbd2b53f014d 100644 (file)
@@ -89,7 +89,7 @@ function j2g($j_y, $j_m, $j_d){
 }
     
 // Jalali UTF Calendar code by Omid Mottaghi
-function calendar_jalali_utf($format, $timestamp) {
+function jalali_strftime_utf($format, $timestamp) {
     
     $g_d=date('j', $timestamp);
     $g_m=date('n', $timestamp);
@@ -141,7 +141,7 @@ function calendar_jalali_utf($format, $timestamp) {
                     $output_str.=$j_month_name[$jm];
                     break;
                 case 'c':
-                    $output_str.=calendar_jalali_utf('%m/%d/%y %I:%M:%S', $timestamp);
+                    $output_str.=jalali_strftime_utf('%y/%m/%d %I:%M:%S', $timestamp);
                     break;
                 case 'C':
                     $output_str.=floor($jy/100);
@@ -150,7 +150,7 @@ function calendar_jalali_utf($format, $timestamp) {
                     if($jd<10) $output_str.='0'.$jd; else $output_str.=$jd;
                     break;
                 case 'D':
-                    $output_str.=$jm.'/'.$jd.'/'.$jy;
+                    $output_str.=$jy.'/'.$jm.'/'.$jd;
                     break;
                 case 'e':
                     if($jd<10) $output_str.=' '.$jd; else $output_str.=$jd;
@@ -196,10 +196,10 @@ function calendar_jalali_utf($format, $timestamp) {
                     $output_str.=$j_week_number[date('D', $timestamp)];
                     break;
                 case 'x':
-                    $output_str.=calendar_jalali_utf('%m/%d/%y', $timestamp);
+                    $output_str.=jalali_strftime_utf('%y/%m/%d', $timestamp);
                     break;
                 case 'X':
-                    $output_str.=calendar_jalali_utf('%I:%M:%S', $timestamp);
+                    $output_str.=jalali_strftime_utf('%I:%M:%S', $timestamp);
                     break;
                 case 'g':
                 case 'y':
@@ -224,4 +224,146 @@ function calendar_jalali_utf($format, $timestamp) {
     
     return $output_str;
 }
+
+// Jalali UTF Calendar code by Omid Mottaghi
+function jalali_date_utf($format, $timestamp) {
+    
+    $g_d=date('j', $timestamp);
+    $g_m=date('n', $timestamp);
+    $g_y=date('Y', $timestamp);
+    
+    list($jy, $jm, $jd, $j_all_days) = g2j($g_y, $g_m, $g_d);
+    
+    $j_month_name = array('', 'فروردین', 'اردیبهشت', 'خرداد', 'تیر',
+            'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند');
+    $j_week_name = array('Saturday' => 'شنبه',
+                        'Sunday' => 'یک شنبه',
+                        'Monday' => 'دوشنبه',
+                        'Tuesday' => 'سه شنبه',
+                        'Wednesday' => 'چهارشنبه',
+                        'Thursday' => 'پنج شنبه',
+                        'Friday' => 'جمعه',
+                        'Sat' => 'ش',
+                        'Sun' => 'ی',
+                        'Mon' => 'د',
+                        'Tue' => 'س',
+                        'Wed' => 'چ',
+                        'Thu' => 'پ',
+                        'Fri' => 'ج');
+    $j_week_number = array('Sat' => '1',
+                           'Sun' => '2',
+                           'Mon' => '3',
+                           'Tue' => '4',
+                           'Wed' => '5',
+                           'Thu' => '6',
+                           'Fri' => '7');
+    
+    // calculate string
+    $output_str='';
+    
+    for ($i=0; $i<strlen($format); $i++){
+        
+        if($format[$i]!='\\'){
+            switch($format[$i]){
+                case 'd':
+                    if($jd<10) $output_str.='0'.$jd; else $output_str.=$jd;
+                    break;
+                case 'D':
+                case 'S':
+                    $output_str.=$j_week_name[date('D', $timestamp)];
+                    break;
+                case 'l':
+                    $output_str.=$j_week_name[date('l', $timestamp)];
+                    break;
+                case 'w':
+                case 'N':
+                    $output_str.=$j_week_number[date('D', $timestamp)];
+                    break;
+                case 'z':
+                    $output_str.=sprintf("%03d", $j_all_days);
+                    break;
+                case 'W':
+                    $output_str.=floor(($j_all_days+1)/7);
+                    break;
+                case 'F':
+                case 'M':
+                    $output_str.=$j_month_name[$jm];
+                    break;
+                case 'm':
+                    if($jm<10) $output_str.='0'.$jm; else $output_str.=$jm;
+                    break;
+                case 'n':
+                    $output_str.=$jm;
+                case 't': // incomplete
+                    break;
+                case 'L': // incomplete
+                    break;
+                case 'o':
+                case 'Y':
+                    $output_str.=$jy;
+                    break;
+                case 'y':
+                    $output_str.=$jy-(floor($jy/100)*100);
+                    break;
+                case 'a':
+                case 'A':
+                    if(date('a', $timestamp)=='pm') $output_str.='بعد از ظهر'; else $output_str.='قبل از ظهر';
+                    break;
+                case 'B':
+                    $output_str.=date('a', $timestamp);
+                    break;
+                case 'g':
+                    $output_str.=date('g', $timestamp);
+                    break;
+                case 'G':
+                    $output_str.=date('G', $timestamp);
+                    break;
+                case 'h':
+                    $output_str.=date('h', $timestamp);
+                    break;
+                case 'H':
+                    $output_str.=date('H', $timestamp);
+                    break;
+                case 'i':
+                    $output_str.=date('i', $timestamp);
+                    break;
+                case 's':
+                    $output_str.=date('s', $timestamp);
+                    break;
+                case 'I':
+                    $output_str.=date('I', $timestamp);
+                    break;
+                case 'O':
+                    $output_str.=date('O', $timestamp);
+                    break;
+                case 'Z':
+                    $output_str.=date('Z', $timestamp);
+                    break;
+                case 'c':
+                    $output_str.=date('d-m-Y\TH:i:sO', $timestamp);
+                    break;
+                case 'r':
+                    $output_str.=date('D، j F Y H:i:s O', $timestamp);
+                    break;
+                case 'U':
+                    $output_str.=date('U', $timestamp);
+                    break;
+                default:
+                    $output_str.=$format[$i];
+                    break;
+            }
+        }else{
+            $i++;
+            $output_str.=$format[$i];
+        }
+    }
+    
+    return $output_str;
+}
+
+// Jalali UTF Calendar code by Omid Mottaghi
+function jalali_mktime($hour=0, $min=0, $sec=0, $mon=1, $day=1, $year=1970, $is_dst=-1){
+    list($year, $mon, $day)=j2g($year, $mon, $day);
+    return mktime($hour, $min, $sec, $mon, $day, $year, $is_dst);
+}
 ?>
\ No newline at end of file
index 5281f6d40d14572b9e7a3d7fe9858a31a344c82d..3b33d534ead9369ecfd2e6ae6617151c78a9fbff 100644 (file)
@@ -112,7 +112,7 @@ class serendipity_calendar_plugin extends serendipity_plugin {
                 // How many days does the month have?
                 $ts              = strtotime($gy . '-' . sprintf('%02d', $gm) . '-' . sprintf('%02d', $gd));
                 $now             = serendipity_serverOffsetHour(time(), true);
-                $nrOfDays = calendar_jalali_utf('%m', $ts);
+                $nrOfDays = jalali_strftime_utf('%m', $ts);
                 $j_days_in_month = array(0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
                 if ($year%4 == 3 && $nrOfDays == 12) $nrOfDays = $j_days_in_month[(int)$nrOfDays]+1;
                 else $nrOfDays = $j_days_in_month[(int)$nrOfDays];
@@ -222,12 +222,12 @@ class serendipity_calendar_plugin extends serendipity_plugin {
                 if (is_array($rows)) {
                     foreach ($rows as $row) {
                         $row['timestamp'] = serendipity_serverOffsetHour($row['timestamp']);
-                        $activeDays[(int) calendar_jalali_utf('%d', $row['timestamp'])] = $row['timestamp'];
+                        $activeDays[(int) jalali_date_utf('j', $row['timestamp'])] = $row['timestamp'];
                     }
                 }
-                $today_day   = calendar_jalali_utf('%e', $now);
-                $today_month = calendar_jalali_utf('%m', $now);
-                $today_year  = calendar_jalali_utf('%Y', $now);
+                $today_day   = jalali_date_utf('j', $now);
+                $today_month = jalali_date_utf('m', $now);
+                $today_year  = jalali_date_utf('Y', $now);
                 break;
             
         } // end switch
@@ -391,6 +391,8 @@ class serendipity_archives_plugin extends serendipity_plugin {
 
         $ts = mktime(0, 0, 0);
 
+        require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php';
+
         $add_query = '';
         if (isset($serendipity['GET']['category'])) {
             $base_query   = 'C' . (int)$serendipity['GET']['category'];
@@ -398,23 +400,54 @@ class serendipity_archives_plugin extends serendipity_plugin {
         }
 
         $max_x = $this->get_config('count', 3);
+        
         for($x = 0; $x < $max_x; $x++) {
-
+            
             switch($this->get_config('frequency', 'months')) {
                 case 'months' :
-                    $linkStamp = date('Y/m', $ts);
-                    $ts_title = serendipity_formatTime("%B %Y", $ts, false);
-                    $ts = mktime(0, 0, 0, date('m', $ts)-1, 1, date('Y', $ts)); // Must be last in 'case' statement
+                    switch($serendipity['calendar']) {
+                        default:
+                        case 'gregorian':
+                            $linkStamp = date('Y/m', $ts);
+                            $ts_title = serendipity_formatTime("%B %Y", $ts, false);
+                            $ts = mktime(0, 0, 0, date('m', $ts)-1, 1, date('Y', $ts)); // Must be last in 'case' statement
+                            break;
+                        case 'jalali-utf8':
+                            $linkStamp = jalali_date_utf('Y/m', $ts);
+                            $ts_title = serendipity_formatTime("%B %Y", $ts, false);
+                            $ts = jalali_mktime(0, 0, 0, jalali_date_utf('m', $ts)-1, 1, jalali_date_utf('Y', $ts)); // Must be last in 'case' statement
+                            break;
+                    }
                     break;
                 case 'weeks' :
-                    $linkStamp = date('Y/\WW', $ts);
-                    $ts_title = WEEK . ' '. date('W, Y', $ts);
-                    $ts = mktime(0, 0, 0, date('m', $ts), date('d', $ts)-7, date('Y', $ts));
+                    switch($serendipity['calendar']) {
+                        default:
+                        case 'gregorian':
+                            $linkStamp = date('Y/\WW', $ts);
+                            $ts_title = WEEK . ' '. date('W, Y', $ts);
+                            $ts = mktime(0, 0, 0, date('m', $ts), date('d', $ts)-7, date('Y', $ts));
+                            break;
+                        case 'jalali-utf8':
+                            $linkStamp = jalali_date_utf('Y/\WW', $ts);
+                            $ts_title = WEEK . ' '. jalali_date_utf('W، Y', $ts);
+                            $ts = jalali_mktime(0, 0, 0, jalali_date_utf('m', $ts), jalali_date_utf('d', $ts)-7, jalali_date_utf('Y', $ts));
+                            break;
+                    }
                     break;
                 case 'days' :
-                    $linkStamp = date('Y/m/d', $ts);
-                    $ts_title = serendipity_formatTime("%B %e. %Y", $ts, false);
-                    $ts = mktime(0, 0, 0, date('m', $ts), date('d', $ts)-1, date('Y', $ts)); // Must be last in 'case' statement
+                    switch($serendipity['calendar']) {
+                        default:
+                        case 'gregorian':
+                            $linkStamp = date('Y/m/d', $ts);
+                            $ts_title = serendipity_formatTime("%B %e. %Y", $ts, false);
+                            $ts = mktime(0, 0, 0, date('m', $ts), date('d', $ts)-1, date('Y', $ts)); // Must be last in 'case' statement
+                            break;
+                        case 'jalali-utf8':
+                            $linkStamp = jalali_date_utf('Y/m/d', $ts);
+                            $ts_title = serendipity_formatTime("%e %B %Y", $ts, false);
+                            $ts = jalali_mktime(0, 0, 0, jalali_date_utf('m', $ts), jalali_date_utf('d', $ts)-1, jalali_date_utf('Y', $ts)); // Must be last in 'case' statement
+                            break;
+                    }
                     break;
             }
             $link = serendipity_rewriteURL(PATH_ARCHIVES . '/' . $linkStamp . $add_query . '.html', 'serendipityHTTPPath');