From 54cfbeabc59ed8f11c8651af36bf03b46b1a981d Mon Sep 17 00:00:00 2001 From: omidmottaghi Date: Mon, 24 Oct 2005 18:54:51 +0000 Subject: [PATCH] Archive plugin for Jalali fixed. Some new Jalali functions added and some debugged. --- include/functions.inc.php | 2 +- include/functions_calendars.inc.php | 152 +++++++++++++++++++++++++++- include/plugin_internal.inc.php | 63 +++++++++--- 3 files changed, 196 insertions(+), 21 deletions(-) diff --git a/include/functions.inc.php b/include/functions.inc.php index 88337dd..9d1d4b6 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -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); } } diff --git a/include/functions_calendars.inc.php b/include/functions_calendars.inc.php index 906e0e6..a512019 100644 --- a/include/functions_calendars.inc.php +++ b/include/functions_calendars.inc.php @@ -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 \ No newline at end of file diff --git a/include/plugin_internal.inc.php b/include/plugin_internal.inc.php index 5281f6d..3b33d53 100644 --- a/include/plugin_internal.inc.php +++ b/include/plugin_internal.inc.php @@ -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'); -- 2.39.5