From 689340508cd79be356aebfb472f0305cb9f1303c Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Fri, 30 Dec 2005 17:32:50 +0000 Subject: [PATCH] fix date conversions --- include/functions_entries.inc.php | 4 ++ include/plugin_internal.inc.php | 81 +++++++++++++++---------------- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/include/functions_entries.inc.php b/include/functions_entries.inc.php index 49e52c9..d258e5a 100644 --- a/include/functions_entries.inc.php +++ b/include/functions_entries.inc.php @@ -1325,12 +1325,14 @@ function serendipity_printArchives() { $lastMonth = date('m', serendipity_serverOffsetHour($f[0][0])); $thisYear = date('Y', serendipity_serverOffsetHour()); $thisMonth = date('m', serendipity_serverOffsetHour()); + break; 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()); + break; } $max = 0; @@ -1362,10 +1364,12 @@ function serendipity_printArchives() { 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); + break; 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); + break; } $entries = serendipity_db_query("SELECT count(id) diff --git a/include/plugin_internal.inc.php b/include/plugin_internal.inc.php index 0ecdbee..3ee2356 100644 --- a/include/plugin_internal.inc.php +++ b/include/plugin_internal.inc.php @@ -85,21 +85,21 @@ class serendipity_calendar_plugin extends serendipity_plugin { case 'gregorian': // How many days does the month have? $ts = strtotime($year . '-' . sprintf('%02d', $month) . '-01'); - $now = serendipity_serverOffsetHour(time(), true); + $now = serendipity_serverOffsetHour(time()); $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 ){ + if( isset($jd) && $jd ){ list ( $gy, $gm, $gd ) = j2g ($jy, $jm, $jd); }elseif( isset($jm) && $jm ){ list ( $gy, $gm, $gd ) = j2g ( $jy, $jm, 1); @@ -108,30 +108,30 @@ class serendipity_calendar_plugin extends serendipity_plugin { $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); + $now = serendipity_serverOffsetHour(time()); $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]; - + // 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; @@ -157,7 +157,7 @@ class serendipity_calendar_plugin extends serendipity_plugin { $nextMonth = 1; $nextYear = $year+1; } - + // 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) { @@ -203,7 +203,7 @@ class serendipity_calendar_plugin extends serendipity_plugin { } $rows = serendipity_db_query($querystring); - + switch($serendipity['calendar']) { default: case 'gregorian': @@ -218,7 +218,7 @@ class serendipity_calendar_plugin extends serendipity_plugin { $today_month = date('m', $now); $today_year = date('Y', $now); break; - + case 'jalali-utf8': $activeDays = array(); if (is_array($rows)) { @@ -231,9 +231,9 @@ class serendipity_calendar_plugin extends serendipity_plugin { $today_month = jalali_date_utf('m', $now); $today_year = jalali_date_utf('Y', $now); break; - + } // end switch - + $externalevents = array(); if (serendipity_db_bool($this->get_config('enableExtEvents', false))) { serendipity_plugin_api::hook_event('frontend_calendar', $externalevents, array('Month' => $month, 'Year' => $year, @@ -243,7 +243,6 @@ class serendipity_calendar_plugin extends serendipity_plugin { // Print the calendar $currDay = 1; $nrOfRows = ceil(($nrOfDays+$firstDayWeekDay)/7); - for ($x = 0; $x < 6; $x++) { // Break out if we are out of days if ($currDay > $nrOfDays) { @@ -254,7 +253,7 @@ class serendipity_calendar_plugin extends serendipity_plugin { $cellProps = array(); $printDay = ''; $link = ''; - + if ($x == 0) { $cellProps['FirstRow'] = 1; } @@ -267,11 +266,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_day == $currDay && $today_month == $month && $today_year == $year) { $cellProps['Today'] = 1; } @@ -301,15 +300,15 @@ 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) . $add_query), @@ -317,7 +316,7 @@ class serendipity_calendar_plugin extends serendipity_plugin { 'minScroll' => $minmax[0]['min'], 'maxScroll' => $minmax[0]['max'])); echo serendipity_smarty_fetch('CALENDAR', 'plugin_calendar.tpl'); - + } // end function } // end class @@ -407,9 +406,9 @@ 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' : switch($serendipity['calendar']) { @@ -498,7 +497,7 @@ class serendipity_topreferrers_plugin extends serendipity_plugin { $propbag->add('description', ARCHIVE_FREQUENCY_DESC); $propbag->add('default', 7); break; - + case 'use_links': $propbag->add('type', 'tristate'); $propbag->add('name', INSTALL_TOP_AS_LINKS); @@ -564,7 +563,7 @@ class serendipity_topexits_plugin extends serendipity_plugin { $propbag->add('description', ARCHIVE_FREQUENCY_DESC); $propbag->add('default', 7); break; - + case 'use_links': $propbag->add('type', 'tristate'); $propbag->add('name', INSTALL_TOP_AS_LINKS); @@ -1177,10 +1176,10 @@ class serendipity_html_nugget_plugin extends serendipity_plugin { } else { echo $this->get_config('content'); } - + if (serendipity_userLoggedIn()) { $is_plugin_owner = ($this->serendipity_owner == $serendipity['authorid'] || serendipity_checkPermission('adminPluginsMaintainOthers')); - + if ($is_plugin_owner) { echo '
' . EDIT . '
'; } @@ -1213,7 +1212,7 @@ class serendipity_categories_plugin extends serendipity_plugin { $propbag->add('description', TITLE_FOR_NUGGET); $propbag->add('default', CATEGORIES); break; - + case 'authorid': $row_authors = serendipity_db_query("SELECT realname, authorid FROM {$serendipity['dbPrefix']}authors"); $authors = array('all' => ALL_AUTHORS); @@ -1232,8 +1231,8 @@ class serendipity_categories_plugin extends serendipity_plugin { case 'parent_base': $categories = array('all' => ALL_CATEGORIES); - $cats = serendipity_fetchCategories(); - + $cats = serendipity_fetchCategories(); + if (is_array($cats)) { $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED); foreach($cats as $cat) { @@ -1351,7 +1350,7 @@ class serendipity_categories_plugin extends serendipity_plugin { $cat_count[$cat['categoryid']] = $cat['postings']; } } - + } $html = ''; @@ -1392,7 +1391,7 @@ class serendipity_categories_plugin extends serendipity_plugin { } } } - + // Hide parents outside of our tree if ($hide_parallel && $serendipity['GET']['category']) { if ($hidedepth == 0 && $cat['parentid'] != $serendipity['GET']['category'] && $cat['categoryid'] != $serendipity['GET']['category']) { @@ -1412,7 +1411,7 @@ class serendipity_categories_plugin extends serendipity_plugin { $categories[$cid]['feedCategoryURL'] = serendipity_feedCategoryURL($cat, 'serendipityHTTPPath'); $categories[$cid]['categoryURL'] = serendipity_categoryURL($cat, 'serendipityHTTPPath'); $categories[$cid]['paddingPx'] = $cat['depth']*6; - + if (!empty($cat_count[$cat['categoryid']])) { $categories[$cid]['true_category_name'] = $cat['category_name']; $categories[$cid]['category_name'] .= ' (' . $cat_count[$cat['categoryid']] . ')'; @@ -1420,11 +1419,11 @@ class serendipity_categories_plugin extends serendipity_plugin { if (!$smarty) { $html .= '
'; - + if ($is_form) { $html .= ''; } - + if ( !empty($image) ) { $html .= 'XML '; } @@ -1441,7 +1440,7 @@ class serendipity_categories_plugin extends serendipity_plugin { if (!$smarty) { $html .= sprintf( '
%s', - + $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'], ALL_CATEGORIES, ALL_CATEGORIES -- 2.39.5