$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);
-
- // Calculate the first day of the week, based on the beginning of the week ($bow)
- if ($bow > $firstDayWeekDay) {
- $firstDayWeekDay = $firstDayWeekDay + 7 - $bow;
- } elseif ( $bow < $firstDayWeekDay ) {
- $firstDayWeekDay = $firstDayWeekDay - $bow;
- } else {
- $firstDayWeekDay = 0;
- }
-
- // Calculate the number of next/previous month
- if ($month > 1) {
- $previousMonth = $month-1;
- $previousYear = $year;
- } else {
- $previousMonth = 12;
- $previousYear = $year-1;
- }
-
- if ($month < 12) {
- $nextMonth = $month+1;
- $nextYear = $year;
- } else {
- $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) {
- // If no entry is available yet, allow scrolling a year back and forth
- $minmax = array(
- '0' => array(
- 'min' => mktime(0, 0, 0, 1, 1, date('Y', $now) - 1),
- 'max' => mktime(0, 0, 0, 1, 1, date('Y', $now) + 1)
- )
- );
- }
-
- // Find out about diary entries
- $add_query = '';
- $base_query = '';
- $cond = array();
- $cond['and'] = "WHERE e.timestamp >= " . serendipity_serverOffsetHour($ts, true) . "
- AND e.timestamp <= " . serendipity_serverOffsetHour($endts, true) . "
- " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . time() : '') . "
- AND e.isdraft = 'false'";
-
- serendipity_plugin_api::hook_event('frontend_fetchentries', $cond, array('noCache' => false, 'noSticky' => false));
-
- if (isset($serendipity['GET']['category'])) {
- $base_query = 'C' . $serendipity['GET']['category'];
- $add_query = '/' . $base_query;
- $querystring = "SELECT timestamp
- FROM {$serendipity['dbPrefix']}category c,
- {$serendipity['dbPrefix']}entrycat ec,
- {$serendipity['dbPrefix']}entries e
- {$cond['joins']}
- {$cond['and']}
- AND e.id = ec.entryid
- AND c.categoryid = ec.categoryid
- AND (" . serendipity_getMultiCategoriesSQL($serendipity['GET']['category']) . ")";
- }
-
- if (!isset($querystring)) {
- $querystring = "SELECT id, timestamp
- FROM {$serendipity['dbPrefix']}entries e
- {$cond['joins']}
- {$cond['and']}";
- }
-
- $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'];
- }
- }
-
- // 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) {
+ 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);
+
+ // Calculate the first day of the week, based on the beginning of the week ($bow)
+ if ($bow > $firstDayWeekDay) {
+ $firstDayWeekDay = $firstDayWeekDay + 7 - $bow;
+ } elseif ( $bow < $firstDayWeekDay ) {
+ $firstDayWeekDay = $firstDayWeekDay - $bow;
+ } else {
+ $firstDayWeekDay = 0;
+ }
+
+ // Calculate the number of next/previous month
+ if ($month > 1) {
+ $previousMonth = $month-1;
+ $previousYear = $year;
+ } else {
+ $previousMonth = 12;
+ $previousYear = $year-1;
+ }
+
+ if ($month < 12) {
+ $nextMonth = $month+1;
+ $nextYear = $year;
+ } else {
+ $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) {
+ // If no entry is available yet, allow scrolling a year back and forth
+ $minmax = array(
+ '0' => array(
+ 'min' => mktime(0, 0, 0, 1, 1, date('Y', $now) - 1),
+ 'max' => mktime(0, 0, 0, 1, 1, date('Y', $now) + 1)
+ )
+ );
+ }
+
+ // Find out about diary entries
+ $add_query = '';
+ $base_query = '';
+ $cond = array();
+ $cond['and'] = "WHERE e.timestamp >= " . serendipity_serverOffsetHour($ts, true) . "
+ AND e.timestamp <= " . serendipity_serverOffsetHour($endts, true) . "
+ " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . time() : '') . "
+ AND e.isdraft = 'false'";
+
+ serendipity_plugin_api::hook_event('frontend_fetchentries', $cond, array('noCache' => false, 'noSticky' => false));
+
+ if (isset($serendipity['GET']['category'])) {
+ $base_query = 'C' . $serendipity['GET']['category'];
+ $add_query = '/' . $base_query;
+ $querystring = "SELECT timestamp
+ FROM {$serendipity['dbPrefix']}category c,
+ {$serendipity['dbPrefix']}entrycat ec,
+ {$serendipity['dbPrefix']}entries e
+ {$cond['joins']}
+ {$cond['and']}
+ AND e.id = ec.entryid
+ AND c.categoryid = ec.categoryid
+ AND (" . serendipity_getMultiCategoriesSQL($serendipity['GET']['category']) . ")";
+ }
+
+ if (!isset($querystring)) {
+ $querystring = "SELECT id, timestamp
+ FROM {$serendipity['dbPrefix']}entries e
+ {$cond['joins']}
+ {$cond['and']}";
+ }
+
+ $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'];
+ }
+ }
+
+ // 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) {
+ break;
+ }
+ // Prepare row
+ for ($y = 0; $y < 7; $y++) {
+ $cellProps = array();
+ $printDay = '';
+ $link = '';
+
+ if ($x == 0) {
+ $cellProps['FirstRow'] = 1;
+ }
+ if ($y == 0) {
+ $cellProps['FirstInRow'] = 1;
+ }
+ if ($y == 6) {
+ $cellProps['LastInRow'] = 1;
+ }
+ 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;
+ }
+ if (isset($activeDays[$currDay]) && $activeDays[$currDay] > 1) {
+ $cellProps['Active'] = 1;
+ $cellProps['Link'] = serendipity_archiveDateUrl(sprintf('%4d/%02d/%02d', $year, $month, $currDay) . $add_query );
+ }
+ $currDay++;
+ }
+ $smartyRows[$x]['days'][] = array('name' => $printDay,
+ 'properties' => $cellProps,
+ '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']));
+ echo serendipity_smarty_fetch('CALENDAR', 'plugin_calendar.tpl');
break;
- }
- // Prepare row
- for ($y = 0; $y < 7; $y++) {
- $cellProps = array();
- $printDay = '';
- $link = '';
-
- if ($x == 0) {
- $cellProps['FirstRow'] = 1;
+
+ 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');
}
- if ($y == 0) {
- $cellProps['FirstInRow'] = 1;
+
+ if(!$jy || !$jm || !$jd) list ( $jy, $jm, $jd ) = g2j ($gy, $gm, $gd);
+
+ // Calculate first Jalali day, week day name
+ list ($first_gy, $first_gm, $first_gd ) = j2g ( $jy, $jm, 1);
+ $first_ts = mktime (0, 0, 0, $first_gm, $first_gd, $first_gy);
+
+ // 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);
+ $firstDayWeekDay = date('w', $first_ts);
+ $j_days_in_month = array(0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
+ if ($jy%4 == 3 && $nrOfDays == 12) $nrOfDays = $j_days_in_month[(int)$nrOfDays]+1;
+ else $nrOfDays = $j_days_in_month[(int)$nrOfDays];
+
+ // Calculate the first day of the week, based on the beginning of the week ($bow)
+ if ($bow > $firstDayWeekDay) {
+ $firstDayWeekDay = $firstDayWeekDay + 7 - $bow;
+ } elseif ( $bow < $firstDayWeekDay ) {
+ $firstDayWeekDay = $firstDayWeekDay - $bow;
+ } else {
+ $firstDayWeekDay = 0;
}
- if ($y == 6) {
- $cellProps['LastInRow'] = 1;
+
+ // Calculate the number of next/previous month
+ if ($jm > 1) {
+ $previousMonth = $jm-1;
+ $previousYear = $jy;
+ } else {
+ $previousMonth = 12;
+ $previousYear = $jy-1;
}
- if ($x == $nrOfRows-1) {
- $cellProps['LastRow'] = 1;
+
+ if ($jm < 12) {
+ $nextMonth = $jm+1;
+ $nextYear = $jy;
+ } else {
+ $nextMonth = 1;
+ $nextYear = $jy+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;
+
+ list ( $year, $month, $day ) = j2g ($jy, $jm+1, 1);
+ $endts = mktime(0, 0, 0, $month, $day, $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) {
+ // If no entry is available yet, allow scrolling a year back and forth
+ $minmax = array(
+ '0' => array(
+ 'min' => mktime(0, 0, 0, 1, 1, date('Y', $now) - 1),
+ 'max' => mktime(0, 0, 0, 1, 1, date('Y', $now) + 1)
+ )
+ );
+ }
+
+ // Find out about diary entries
+ $add_query = '';
+ $base_query = '';
+ $cond = array();
+ $cond['and'] = "WHERE e.timestamp >= " . serendipity_serverOffsetHour($first_ts, true) . "
+ AND e.timestamp <= " . serendipity_serverOffsetHour($endts, true) . "
+ " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . time() : '') . "
+ AND e.isdraft = 'false'";
+
+ serendipity_plugin_api::hook_event('frontend_fetchentries', $cond, array('noCache' => false, 'noSticky' => false));
+
+ if (isset($serendipity['GET']['category'])) {
+ $base_query = 'C' . $serendipity['GET']['category'];
+ $add_query = '/' . $base_query;
+ $querystring = "SELECT timestamp
+ FROM {$serendipity['dbPrefix']}category c,
+ {$serendipity['dbPrefix']}entrycat ec,
+ {$serendipity['dbPrefix']}entries e
+ {$cond['joins']}
+ {$cond['and']}
+ AND e.id = ec.entryid
+ AND c.categoryid = ec.categoryid
+ AND (" . serendipity_getMultiCategoriesSQL($serendipity['GET']['category']) . ")";
+ }
+
+ if (!isset($querystring)) {
+ $querystring = "SELECT id, timestamp
+ FROM {$serendipity['dbPrefix']}entries e
+ {$cond['joins']}
+ {$cond['and']}";
+ }
+
+ $rows = serendipity_db_query($querystring);
+
+ $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'];
}
- if (isset($activeDays[$currDay]) && $activeDays[$currDay] > 1) {
- $cellProps['Active'] = 1;
- $cellProps['Link'] = serendipity_archiveDateUrl(sprintf('%4d/%02d/%02d', $year, $month, $currDay) . $add_query );
+ }
+
+ // Print the calendar
+ $currDay = 1;
+ $nrOfRows = ceil(($nrOfDays+$firstDayWeekDay)/7);
+ $today_day = calendar_jalali_utf('%e', $now);
+ $today_month = calendar_jalali_utf('%m', $now);
+ $today_year = calendar_jalali_utf('%Y', $now);
+ for ($x = 0; $x < 6; $x++) {
+ // Break out if we are out of days
+ if ($currDay > $nrOfDays) {
+ break;
}
- $currDay++;
+ // Prepare row
+ for ($y = 0; $y < 7; $y++) {
+ $cellProps = array();
+ $printDay = '';
+ $link = '';
+
+ if ($x == 0) {
+ $cellProps['FirstRow'] = 1;
+ }
+ if ($y == 0) {
+ $cellProps['FirstInRow'] = 1;
+ }
+ if ($y == 6) {
+ $cellProps['LastInRow'] = 1;
+ }
+ 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 == $jy && $today_month == $jm && $today_day == $currDay) {
+ $cellProps['Today'] = 1;
+ }
+ if (isset($activeDays[$currDay]) && $activeDays[$currDay] > 1) {
+ $cellProps['Active'] = 1;
+ $cellProps['Link'] = serendipity_archiveDateUrl(sprintf('%4d/%02d/%02d', $jy, $jm, $currDay) . $add_query );
+ }
+ $currDay++;
+ }
+ $smartyRows[$x]['days'][] = array('name' => $printDay,
+ 'properties' => $cellProps,
+ '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));
}
- $smartyRows[$x]['days'][] = array('name' => $printDay,
- 'properties' => $cellProps,
- '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']));
- echo serendipity_smarty_fetch('CALENDAR', 'plugin_calendar.tpl');
+ $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', $jy, $jm)),
+ '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');
+ break;
+ } // end switch
} // end function
} // end class