]> git.mjollnir.org Git - s9y.git/commitdiff
calendar and recent entries for Persian calendar updated
authoromidmottaghi <omidmottaghi>
Sat, 24 Dec 2005 12:58:35 +0000 (12:58 +0000)
committeromidmottaghi <omidmottaghi>
Sat, 24 Dec 2005 12:58:35 +0000 (12:58 +0000)
include/functions_calendars.inc.php
include/functions_entries.inc.php
index.php

index fe3480276a32fcc64a8dc2f08bc631b48fb68794..e347b5f955ab2fd78e6fde43fc6ac1bf9a879ba0 100644 (file)
@@ -268,6 +268,9 @@ function jalali_date_utf($format, $timestamp) {
     
     list($jy, $jm, $jd, $j_all_days) = g2j($g_y, $g_m, $g_d);
     
+    $j_days_in_month = array(0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
+    if(($g_y % 4) == 3) $j_days_in_month[12]++;
+    
     $j_month_name = array('', 'فروردین', 'اردیبهشت', 'خرداد', 'تیر',
             'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند');
     $j_week_name = array('Saturday' => 'شنبه',
@@ -302,6 +305,9 @@ function jalali_date_utf($format, $timestamp) {
                 case 'd':
                     if($jd<10) $output_str.='0'.$jd; else $output_str.=$jd;
                     break;
+                case 'j':
+                    $output_str.=$jd;
+                    break;
                 case 'D':
                 case 'S':
                     $output_str.=$j_week_name[date('D', $timestamp)];
@@ -328,7 +334,8 @@ function jalali_date_utf($format, $timestamp) {
                     break;
                 case 'n':
                     $output_str.=$jm;
-                case 't': // incomplete
+                case 't':
+                    $output_str.=$j_days_in_month[$jm];
                     break;
                 case 'L': // incomplete
                     break;
index d64fd89cf34c70cb96361800b07ba675853076d5..1dd10302695ec783d59bc60f0a7fe08bf602dd38 100644 (file)
@@ -1319,11 +1319,21 @@ function serendipity_printArchives() {
     global $serendipity;
 
     $f = serendipity_db_query("SELECT timestamp FROM {$serendipity['dbPrefix']}entries ORDER BY timestamp ASC LIMIT 1");
-    $lastYear   = date('Y', serendipity_serverOffsetHour($f[0][0]));
-    $lastMonth  = date('m', serendipity_serverOffsetHour($f[0][0]));
-    $thisYear   = date('Y', serendipity_serverOffsetHour());
-    $thisMonth  = date('m', serendipity_serverOffsetHour());
-    $max        = 0;
+    switch($serendipity['calendar']) {
+        case 'gregorian':
+        default:
+            $lastYear   = date('Y', serendipity_serverOffsetHour($f[0][0]));
+            $lastMonth  = date('m', serendipity_serverOffsetHour($f[0][0]));
+            $thisYear   = date('Y', serendipity_serverOffsetHour());
+            $thisMonth  = date('m', serendipity_serverOffsetHour());
+        case 'jalali-utf8':
+            require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php';
+            $lastYear   = jalali_date_utf('Y', serendipity_serverOffsetHour($f[0][0]));
+            $lastMonth  = jalali_date_utf('m', serendipity_serverOffsetHour($f[0][0]));
+            $thisYear   = jalali_date_utf('Y', serendipity_serverOffsetHour());
+            $thisMonth  = jalali_date_utf('m', serendipity_serverOffsetHour());
+    }
+    $max = 0;
 
     if (isset($serendipity['GET']['category'])) {
         $cat_sql = serendipity_getMultiCategoriesSQL($serendipity['GET']['category']);
@@ -1348,8 +1358,16 @@ function serendipity_printArchives() {
                 break;
             }
 
-            $s = serendipity_serverOffsetHour(mktime(0, 0, 0, $m, 1, $y), true);
-            $e = serendipity_serverOffsetHour(mktime(23, 59, 59, $m, date('t', $s), $y), true);
+            switch($serendipity['calendar']) {
+                case 'gregorian':
+                default:
+                    $s = serendipity_serverOffsetHour(mktime(0, 0, 0, $m, 1, $y), true);
+                    $e = serendipity_serverOffsetHour(mktime(23, 59, 59, $m, date('t', $s), $y), true);
+                case 'jalali-utf8':
+                    require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php';
+                    $s = serendipity_serverOffsetHour(jalali_mktime(0, 0, 0, $m, 1, $y), true);
+                    $e = serendipity_serverOffsetHour(jalali_mktime(23, 59, 59, $m, date('t', $s), $y), true);
+            }
 
             $entries = serendipity_db_query("SELECT count(id)
                                                FROM {$serendipity['dbPrefix']}entries e
index a9b1faa21c62d102fdcf42e64c163e56c234e37e..424a73a493274fab234616808bc5e776c59c4d2d 100644 (file)
--- a/index.php
+++ b/index.php
@@ -128,50 +128,72 @@ if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range
         case 'gregorian':
         default:
             $gday = 1;
+            
+            if ($week) {
+                $tm = strtotime('+ '. ($week-2) .' WEEKS monday', mktime(0, 0, 0, 1, 1, $year));
+                $ts = mktime(0, 0, 0, date('m', $tm), date('j', $tm), $year);
+                $te = mktime(23, 59, 59, date('m', $tm), date('j', $tm)+7, $year);
+                $date = serendipity_formatTime(WEEK .' '. $week .', %Y', $ts, false);
+            } else {
+                if ($day) {
+                    $ts = mktime(0, 0, 0, $month, $day, $year);
+                    $te = mktime(23, 59, 59, $month, $day, $year);
+                    $date = serendipity_formatTime(DATE_FORMAT_ENTRY, $ts, false);
+                } else {
+                    $ts = mktime(0, 0, 0, $month, $gday, $year);
+                    if (!isset($gday2)) {
+                        $gday2 = date('t', $ts);
+                    }
+                    $te = mktime(23, 59, 59, $month, $gday2, $year);
+                    $date = serendipity_formatTime('%B %Y', $ts, false);
+                }
+            }
             break;
         
         case 'jalali-utf8':
             require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php';
-            $j_days_in_month = array(0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
-            $gday            = 1;
-            
+            $gday = 1;
             if ($week) {
-                list( $year, $month, $day ) = j2g($year, $month, $day);
+                --$week;
+                $week *= 7;
+                ++$week;
+                $day = $week;
+                
+                // convert day number of year to day number of month AND month number of year
+                $j_days_in_month = array(0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
+                if(($g_y % 4) == 3) $j_days_in_month[12]++;
+                
+                for($i=1; isset($j_days_in_month[$i]); ++$i){
+                    if(($day-$j_days_in_month[$i])>0){
+                        $day -= $j_days_in_month[$i];
+                    }else{
+                        break;
+                    }
+                }
+                
+                $tm = jalali_mktime(0, 0, 0, $i, $day, $year);
+                $ts = jalali_mktime(0, 0, 0, jalali_date_utf('m', $tm), jalali_date_utf('j', $tm), $year);
+                $te = jalali_mktime(23, 59, 59, jalali_date_utf('m', $tm), jalali_date_utf('j', $tm)+7, $year);
+                $date = serendipity_formatTime(WEEK .' '. $week .'، %Y', $ts, false);
             } else {
                 if ($day) {
-                    list( $year, $month, $day ) = j2g($year, $month, $day);
+                    $ts = jalali_mktime(0, 0, 0, $month, $day, $year);
+                    $te = jalali_mktime(23, 59, 59, $month, $day, $year);
+                    $date = serendipity_formatTime(DATE_FORMAT_ENTRY, $ts, false);
                 } else {
-                    if ($year % 4 == 3 && $month == 12){
-                        $nrOfDays = list( $year, $month, $gday ) = j2g($year, $month, $j_days_in_month[(int)$month]+1);
-                    }else{
-                        list( $year, $month, $gday ) = j2g($year, $month, $j_days_in_month[(int)$month]);
+                    $ts = jalali_mktime(0, 0, 0, $month, $gday, $year);
+                    if (!isset($gday2)) {
+                        $gday2 = jalali_date_utf('t', $ts);
                     }
-                    $gday2 = $gday;
+                    $te = jalali_mktime(23, 59, 59, $month, $gday2, $year);
+                    $date = serendipity_formatTime('%B %Y', $ts, false);
                 }
             }
+            
+            list($year, $month, $day) = j2g ($year, $month, $day);
             break;
     }
 
-    if ($week) {
-        $tm = strtotime('+ '. ($week-2) .' WEEKS monday', mktime(0, 0, 0, 1, 1, $year));
-        $ts = mktime(0, 0, 0, date('m', $tm), date('j', $tm), $year);
-        $te = mktime(23, 59, 59, date('m', $tm), date('j', $tm)+7, $year);
-        $date = serendipity_formatTime(WEEK .' '. $week .', %Y', $ts, false);
-    } else {
-        if ($day) {
-            $ts = mktime(0, 0, 0, $month, $day, $year);
-            $te = mktime(23, 59, 59, $month, $day, $year);
-            $date = serendipity_formatTime(DATE_FORMAT_ENTRY, $ts, false);
-        } else {
-            $ts = mktime(0, 0, 0, $month, $gday, $year);
-            if (!isset($gday2)) {
-                $gday2 = date('t', $ts);
-            }
-            $te = mktime(23, 59, 59, $month, $gday2, $year);
-            $date = serendipity_formatTime('%B %Y', $ts, false);
-        }
-    }
-
     $serendipity['range'] = array($ts, $te);
 
     if ($serendipity['GET']['action'] == 'read') {