From: omidmottaghi Date: Mon, 4 Jul 2005 13:55:59 +0000 (+0000) Subject: Jalali Date included X-Git-Tag: 0.9~342 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=238cb80d39af1704254bf996a64d473553f034bf;p=s9y.git Jalali Date included --- diff --git a/include/plugin_internal.inc.php b/include/plugin_internal.inc.php index dc28dcb..e343917 100644 --- a/include/plugin_internal.inc.php +++ b/include/plugin_internal.inc.php @@ -72,12 +72,56 @@ class serendipity_calendar_plugin extends serendipity_plugin { $month = 1; } - // How many days does the month have? - $ts = strtotime($year . '-' . sprintf('%02d', $month) . '-01'); - $now = serendipity_serverOffsetHour(time(), true); - $nrOfDays = date('t', $ts); - $firstDayWeekDay = date('w', $ts); - + switch($serendipity['calendar']) { + default: + case 'gregorian': + // How many days does the month have? + $ts = strtotime($year . '-' . sprintf('%02d', $month) . '-01'); + $now = serendipity_serverOffsetHour(time(), true); + $nrOfDays = date('t', $ts); + $firstDayWeekDay = date('w', $ts); + $firstts = $ts; + $endts = mktime(0, 0, 0, $month + 1, 1, $year); + + break; + + case 'jalali-utf8': + + require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; + + list(,$jy, $jm, $jd) = $serendipity['uriArguments']; + + if( isset($jd) && $jd ) list ( $gy, $gm, $gd ) = j2g ($jy, $jm, $jd); + else if( isset($jm) && $jm ) list ( $gy, $gm, $gd ) = j2g ( $jy, $jm, 1); + else{ + $gy = $year; + $gm = $month; + $gd = (int) date('d'); + } + + list ( $year, $month, $day ) = g2j ($gy, $gm, $gd); + + // 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); + $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]; + + // Calculate first timestamp of the month + list ($firstgy, $firstgm, $firstgd ) = j2g ( $year, $month, 1); + $firstts = mktime (0, 0, 0, $firstgm, $firstgd, $firstgy); + + // Calculate first Jalali day, week day name + $firstDayWeekDay = date('w', $firstts); + + // Calculate end timestamp of the month + list ( $end_year, $end_month, $end_day ) = j2g ($year, $month+1, 1); + $endts = mktime(0, 0, 0, $end_month, $end_day, $end_year); + break; + } // end switch + // Calculate the first day of the week, based on the beginning of the week ($bow) if ($bow > $firstDayWeekDay) { $firstDayWeekDay = $firstDayWeekDay + 7 - $bow; @@ -103,9 +147,7 @@ class serendipity_calendar_plugin extends serendipity_plugin { $nextMonth = 1; $nextYear = $year+1; } - - $endts = mktime(0, 0, 0, $month + 1, 1, $year); - + // Get first and last entry $minmax = serendipity_db_query("SELECT MAX(timestamp) AS max, MIN(timestamp) AS min FROM {$serendipity['dbPrefix']}entries"); if (!is_array($minmax) || !is_array($minmax[0]) || $minmax[0]['min'] < 1 || $minmax[0]['max'] < 1) { @@ -122,7 +164,7 @@ class serendipity_calendar_plugin extends serendipity_plugin { $add_query = ''; $base_query = ''; $cond = array(); - $cond['and'] = "WHERE e.timestamp >= " . serendipity_serverOffsetHour($ts, true) . " + $cond['and'] = "WHERE e.timestamp >= " . serendipity_serverOffsetHour($firstts, true) . " AND e.timestamp <= " . serendipity_serverOffsetHour($endts, true) . " " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . time() : '') . " AND e.isdraft = 'false'"; @@ -151,21 +193,41 @@ class serendipity_calendar_plugin extends serendipity_plugin { } $rows = serendipity_db_query($querystring); - - $activeDays = array(); - if (is_array($rows)) { - foreach ($rows as $row) { - $row['timestamp'] = serendipity_serverOffsetHour($row['timestamp']); - $activeDays[date('j', $row['timestamp'])] = $row['timestamp']; - } - } - + + switch($serendipity['calendar']) { + default: + case 'gregorian': + $activeDays = array(); + if (is_array($rows)) { + foreach ($rows as $row) { + $row['timestamp'] = serendipity_serverOffsetHour($row['timestamp']); + $activeDays[date('j', $row['timestamp'])] = $row['timestamp']; + } + } + $today_day = date('j', $now); + $today_month = date('m', $now); + $today_year = date('Y', $now); + break; + + case 'jalali-utf8': + $activeDays = array(); + if (is_array($rows)) { + foreach ($rows as $row) { + $row['timestamp'] = serendipity_serverOffsetHour($row['timestamp']); + $activeDays[(int) calendar_jalali_utf('%d', $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); + break; + + } // end switch + // Print the calendar $currDay = 1; $nrOfRows = ceil(($nrOfDays+$firstDayWeekDay)/7); - $today_day = date('j', $now); - $today_month = date('m', $now); - $today_year = date('Y', $now); + for ($x = 0; $x < 6; $x++) { // Break out if we are out of days if ($currDay > $nrOfDays) { @@ -176,7 +238,7 @@ class serendipity_calendar_plugin extends serendipity_plugin { $cellProps = array(); $printDay = ''; $link = ''; - + if ($x == 0) { $cellProps['FirstRow'] = 1; } @@ -189,10 +251,11 @@ class serendipity_calendar_plugin extends serendipity_plugin { if ($x == $nrOfRows-1) { $cellProps['LastRow'] = 1; } - + // If it's not a blank day, we print the day if (($x > 0 || $y >= $firstDayWeekDay) && $currDay <= $nrOfDays) { $printDay = $currDay; + if ($today_year == $year && $today_month == $month && $today_day == $currDay) { $cellProps['Today'] = 1; } @@ -207,23 +270,23 @@ class serendipity_calendar_plugin extends serendipity_plugin { 'classes' => implode(' ', array_keys($cellProps))); } // end for } // end for - + $serendipity['smarty']->assign('plugin_calendar_weeks', $smartyRows); - - + $dow = array(); for ($i = 1; $i <= 7; $i++) { $dow[] = array('date' => mktime(0, 0, 0, 3, $bow + $i - 1, 2004)); } $serendipity['smarty']->assign('plugin_calendar_dow', $dow); - + $serendipity['smarty']->assign('plugin_calendar_head', array('month_date' => $ts, - 'uri_previous' => serendipity_archiveDateUrl(sprintf('%04d/%02d', $previousYear, $previousMonth). $add_query), - 'uri_month' => serendipity_archiveDateUrl(sprintf('%04d/%02d', $year, $month)), - 'uri_next' => serendipity_archiveDateUrl(sprintf('%04d/%02d',$nextYear, $nextMonth) . $add_query), - 'minScroll' => $minmax[0]['min'], - 'maxScroll' => $minmax[0]['max'])); + 'uri_previous' => serendipity_archiveDateUrl(sprintf('%04d/%02d', $previousYear, $previousMonth). $add_query), + 'uri_month' => serendipity_archiveDateUrl(sprintf('%04d/%02d', $year, $month)), + 'uri_next' => serendipity_archiveDateUrl(sprintf('%04d/%02d',$nextYear, $nextMonth) . $add_query), + 'minScroll' => $minmax[0]['min'], + 'maxScroll' => $minmax[0]['max'])); echo serendipity_smarty_fetch('CALENDAR', 'plugin_calendar.tpl'); + } // end function } // end class