Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2427
Modified Files:
Tag: branch-smarty
serendipity_functions.inc.php
Log Message:
- Convert the archive to Smarty, which includes partial rewrite
- Change graphic for graph to something that goes with the theme
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.419.2.36
retrieving revision 1.419.2.37
diff -u -d -r1.419.2.36 -r1.419.2.37
--- serendipity_functions.inc.php 28 Sep 2004 11:00:40 -0000 1.419.2.36
+++ serendipity_functions.inc.php 1 Oct 2004 18:32:42 -0000 1.419.2.37
@@ -3105,105 +3105,56 @@
}
}
-/*
-* Amount of posts for given year & month
-*/
-function serendipity_postAmount($year, $month) {
- global $serendipity;
-
- $s = mktime(0, 0, 0, $month, 1, $year);
- $e = mktime(23, 59, 59, $month, date('t', $s), $year);
- $querystring = "SELECT count(id) FROM {$serendipity['dbPrefix']}entries WHERE isdraft = 'false' AND timestamp >= $s AND timestamp <= $e";
- $query = serendipity_db_query($querystring);
-
- return $query[0][0];
-}
-
-/*
-* Print the archive
-*/
function serendipity_printArchives() {
global $serendipity;
- echo '<div class="serendipity_date">' . ARCHIVES . '</div>';
-
$f = serendipity_db_query("SELECT timestamp FROM {$serendipity['dbPrefix']}entries ORDER BY timestamp ASC LIMIT 1");
- $lastYear = date('Y', $f[0][0]);
- $lastMonth= date('m', $f[0]);
- $currYear = date('Y');
- $max = 0;
+ $lastYear = date('Y', $f[0][0]);
+ $lastMonth = date('m', $f[0][0]);
+ $thisYear = date('Y');
+ $thisMonth = date('m');
+ $max = 0;
- while($currYear >= $lastYear) {
- // echo "<h2>$currYear</h2><div class='serendipity_entry'>";
- for($x=1; $x<13; $x++) {
- $entries = serendipity_postAmount($currYear, $x);
- if ($entries > 0) {
- $a = "<a href='". serendipity_archiveDateUrl($currYear . sprintf('%02s', $x)) . '\'>';
- $b = '</a>';
- $c = "<a href='". serendipity_archiveDateUrl($currYear . sprintf('%02s', $x), true) . '\'>';
- $d = "<a href='". serendipity_archiveDateUrl($currYear . sprintf('%02s', $x)) . '\'>';
- } else {
- $a = $c = '<span style="color: #CDCDCD">';
- $b = $d = '</span>';
- }
+ $output = array();
+ for ( $y = $thisYear; $y >= $lastYear; $y--) {
+ $output[$y]['year'] = $y;
+ for( $m=12; $m>=1; $m-- ) {
- if ($x <= date('m') || $currYear < date('Y')) {
- $out[$currYear][$x] = array($entries, $a, $b, $c, $d);
+ /* If the month we are checking are in the future, we drop it */
+ if ( $m > $thisMonth && $y == $thisYear ) {
+ continue;
}
- if ($entries > $max) {
- $max = $entries;
+ /* If the month is lower than the lowest month containing entries, we're done */
+ if ( $m < $lastMonth && $y <= $lastYear ) {
+ break;
}
- }
- // echo "</div>";
- $currYear--;
- }
- if (!$max) {
- return;
- }
-
- $barwidth = 40;
- $fac = $barwidth/$max;
-?>
-<table cellspacing="0" width="500">
-<?php
- foreach($out as $year => $months) {
-?>
- <tr>
- <td colspan="6"><h2><?php echo $year; ?></h2></td>
- </tr>
-<?php
- for($y=12; $y>0; $y--) {
- if (isset($months[$y]) && $months[$y]) {
- $time = mktime(0,0,0, $y+1, 0, $year);
-?>
- <tr>
- <td>
- <img src="<?php echo serendipity_getTemplateFile('img/graph_bar_horisontal.png') ?>" height="10" width="<?php echo ceil($months[$y][0]*$fac); ?>" hspace="0" vspace="0" alt="" /><img src="<?php echo serendipity_getTemplateFile('img/blank.png') ?>" height="10" width="<?php echo ($barwidth-ceil($months[$y][0]*$fac)); ?>" hspace="0" vspace="0" alt="" />
- </td>
- <td>
- <?php echo $months[$y][1] . serendipity_formatTime('%B', $time) . $months[$y][2]; ?>
- </td>
- <td>
- <?php echo $months[$y][0] . ' ' . ENTRIES; ?>
- </td>
-
- <td>
- (<?php echo $months[$y][1] . VIEW_FULL . $months[$y][2]; ?>)
- </td>
+ $s = mktime(0, 0, 0, $m, 1, $y);
+ $e = mktime(23, 59, 59, $m, date('t', $s), $y);
+ $entries = serendipity_db_query("SELECT count(id) FROM {$serendipity['dbPrefix']}entries
+ WHERE isdraft = 'false'
+ AND timestamp >= $s
+ AND timestamp <= $e");
+ $entry_count = $entries[0][0];
- <td>
- (<?php echo $months[$y][3] . VIEW_TOPICS . $months[$y][4]; ?>)
- </td>
- </tr>
-<?php
+ /* A silly hack to get the maximum amount of entries per month */
+ if ( $entry_count > $max ) {
+ $max = $entry_count;
}
+
+ $data = array();
+ $data['entry_count'] = $entry_count;
+ $data['link'] = serendipity_archiveDateUrl($y . sprintf('%02s', $m));
+ $data['link_summary'] = serendipity_archiveDateUrl($y . sprintf('%02s', $m), true);
+ $data['date'] = $s;
+ $output[$y]['months'][] = $data;
}
}
-?>
-</table>
-<?php
+ $serendipity['smarty']->assign(array('archives' => $output,
+ 'max_entries' => $max));
+
+ serendipity_smarty_fetch('ARCHIVES', 'entries_archives.tpl', true);
}
function serendipity_xhtml_target($target)
@@ -3335,4 +3286,4 @@
define("serendipity_FUNCTIONS_LOADED", true);
/* vim: set sts=4 ts=4 expandtab : */
-?>
\ No newline at end of file
+?>
|