From 0f85245d5a3987d04b6f70b9e57c85396274b27c Mon Sep 17 00:00:00 2001 From: omidmottaghi Date: Sat, 24 Dec 2005 12:58:35 +0000 Subject: [PATCH] calendar and recent entries for Persian calendar updated --- include/functions_calendars.inc.php | 9 +++- include/functions_entries.inc.php | 32 ++++++++--- index.php | 82 ++++++++++++++++++----------- 3 files changed, 85 insertions(+), 38 deletions(-) diff --git a/include/functions_calendars.inc.php b/include/functions_calendars.inc.php index fe34802..e347b5f 100644 --- a/include/functions_calendars.inc.php +++ b/include/functions_calendars.inc.php @@ -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; diff --git a/include/functions_entries.inc.php b/include/functions_entries.inc.php index d64fd89..1dd1030 100644 --- a/include/functions_entries.inc.php +++ b/include/functions_entries.inc.php @@ -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 diff --git a/index.php b/index.php index a9b1faa..424a73a 100644 --- 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') { -- 2.39.5