From: garvinhicking Date: Fri, 13 Jan 2006 12:56:07 +0000 (+0000) Subject: * RFE #1387997 - Show amount of entries per archive period (archive X-Git-Tag: 1.0~172 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=19cab60bdc376f7101ef8b1f7aeba809dc729504;p=s9y.git * RFE #1387997 - Show amount of entries per archive period (archive sidebar plugin). Side-effect are some new additions to the serendipity_fetchEntries() function call for further abstraction. (garvinhicking) --- diff --git a/docs/NEWS b/docs/NEWS index 8d6427e..c5d1e21 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,11 @@ Version 1.0 () ------------------------------------------------------------------------ + * RFE #1387997 - Show amount of entries per archive period (archive + sidebar plugin). Side-effect are some new additions to the + serendipity_fetchEntries() function call for further abstraction. + (garvinhicking) + * Add new plugin hook "backend_http_request" which passes PEAR HTTP_Request options to plugins for modification. $addData contains the source of where a request is being made (garvinhicking) diff --git a/include/functions_entries.inc.php b/include/functions_entries.inc.php index 9e71f79..84e1bb1 100644 --- a/include/functions_entries.inc.php +++ b/include/functions_entries.inc.php @@ -179,9 +179,12 @@ function serendipity_fetchEntryCategories($entryid) { * @param string Can contain any SQL code to inject into the central SQL statement for fetching the entry * @param boolean If set to TRUE, all entries will be fetched from scratch and any caching is ignored * @param boolean If set to TRUE, all sticky entries will NOT be fetched. + * @param string Can contain a SQL statement on which keys to select. Plugins can also set this, pay attention! + * @param string Can contain a SQL statement on how to group the query. Plugins can also set this, pay attention! + * @param string If set to "array", the array of entries will be returned. "flat-array" will only return the articles without their entryproperties. "single" will only return a 1-dimensional array. "query" will only return the used SQL. * @return array Holds the super-array of all entries with all additional information */ -function serendipity_fetchEntries($range = null, $full = true, $limit = '', $fetchDrafts = false, $modified_since = false, $orderby = 'timestamp DESC', $filter_sql = '', $noCache = false, $noSticky = false) { +function serendipity_fetchEntries($range = null, $full = true, $limit = '', $fetchDrafts = false, $modified_since = false, $orderby = 'timestamp DESC', $filter_sql = '', $noCache = false, $noSticky = false, $select_key = null, $group_by = null, $returncode = 'array') { global $serendipity; $cond = array(); @@ -228,11 +231,11 @@ function serendipity_fetchEntries($range = null, $full = true, $limit = '', $fet $endts = serendipity_serverOffsetHour(mktime(0, 0, 0, $month, ($day == 0 ? 1 : $day), $year), true); - $cond['and'] = " WHERE timestamp >= $startts AND timestamp <= $endts"; + $cond['and'] = " WHERE e.timestamp >= $startts AND e.timestamp <= $endts"; } elseif (is_array($range) && count($range)==2) { $startts = serendipity_serverOffsetHour((int)$range[0], true); $endts = serendipity_serverOffsetHour((int)$range[1], true); - $cond['and'] = " WHERE timestamp >= $startts AND timestamp <= $endts"; + $cond['and'] = " WHERE e.timestamp >= $startts AND e.timestamp <= $endts"; } else { if ($modified_since) { $unix_modified = strtotime($modified_since); @@ -292,9 +295,9 @@ function serendipity_fetchEntries($range = null, $full = true, $limit = '', $fet if (!isset($serendipity['GET']['adminModule']) && !serendipity_db_bool($serendipity['showFutureEntries'])) { if (!empty($cond['and'])) { - $cond['and'] .= " AND e.timestamp <= '" . time() . "'"; + $cond['and'] .= " AND e.timestamp <= " . time(); } else { - $cond['and'] = "WHERE e.timestamp <= '" . time() . "'"; + $cond['and'] = "WHERE e.timestamp <= " . time(); } } @@ -315,6 +318,29 @@ function serendipity_fetchEntries($range = null, $full = true, $limit = '', $fet $group = 'GROUP BY e.id'; $distinct = ''; } + + if (!is_null($group_by)) { + $group = $group_by; + } + + if (is_null($select_key)) { + $select_key = "$distinct + {$cond['addkey']} + + e.id, + e.title, + e.timestamp, + e.comments, + e.exflag, + e.authorid, + e.trackbacks, + e.isdraft, + e.allow_comments, + e.last_modified, + + a.realname AS author, + a.email"; + } serendipity_ACL_SQL($cond); @@ -331,38 +357,28 @@ function serendipity_fetchEntries($range = null, $full = true, $limit = '', $fet {$cond['joins']} {$cond['and']}"; - $query = "SELECT $distinct - {$cond['addkey']} - - e.id, - e.title, - e.timestamp, - e.comments, - e.exflag, - e.authorid, - e.trackbacks, - e.isdraft, - e.allow_comments, - e.last_modified, - - a.realname AS author, - a.email - - $body - {$serendipity['fullCountQuery']} - $group - ORDER BY {$cond['orderby']} - $limit"; + $query = "SELECT $select_key + $body + {$serendipity['fullCountQuery']} + $group + ORDER BY {$cond['orderby']} + $limit"; // DEBUG: // die($query); - $ret = serendipity_db_query($query, false, 'assoc'); + $fetch_single = ($returncode == 'single' ? true: false); + + if ($returncode == 'query') { + return $query; + } + + $ret = serendipity_db_query($query, $fetch_single, 'assoc'); if (is_string($ret)) { die("Query failed: $ret"); } - if (is_array($ret)) { + if (is_array($ret) && $returncode == 'array') { // The article's query LIMIT operates on a flattened entries layer so that // an article having 5 associated categories won't count as 5 entries. // But to store the expanded list of categories, we need to send a new diff --git a/include/plugin_internal.inc.php b/include/plugin_internal.inc.php index 3ee2356..66f861e 100644 --- a/include/plugin_internal.inc.php +++ b/include/plugin_internal.inc.php @@ -361,7 +361,7 @@ class serendipity_archives_plugin extends serendipity_plugin { $propbag->add('stackable', true); $propbag->add('author', 'Serendipity Team'); $propbag->add('version', '1.0'); - $propbag->add('configuration', array('frequency', 'count')); + $propbag->add('configuration', array('frequency', 'count', 'show_count')); $propbag->add('groups', array('FRONTEND_VIEWS')); } @@ -383,6 +383,13 @@ class serendipity_archives_plugin extends serendipity_plugin { $propbag->add('default', 'months'); break; + case 'show_count': + $propbag->add('type', 'boolean'); + $propbag->add('name', CATEGORY_PLUGIN_SHOWCOUNT); + $propbag->add('description', ''); + $propbag->add('default', false); + break; + default: return false; } @@ -395,7 +402,7 @@ class serendipity_archives_plugin extends serendipity_plugin { $title = $this->title; - $ts = mktime(0, 0, 0); + $ts = mktime(0, 0, 0, date('m'), 1); require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; @@ -406,10 +413,12 @@ class serendipity_archives_plugin extends serendipity_plugin { } $max_x = $this->get_config('count', 3); + $show_count = serendipity_db_bool($this->get_config('show_count', false)); + $freq = $this->get_config('frequency', 'months'); for($x = 0; $x < $max_x; $x++) { - - switch($this->get_config('frequency', 'months')) { + $current_ts = $ts; + switch($freq) { case 'months' : switch($serendipity['calendar']) { default: @@ -458,7 +467,44 @@ class serendipity_archives_plugin extends serendipity_plugin { } $link = serendipity_rewriteURL(PATH_ARCHIVES . '/' . $linkStamp . $add_query . '.html', 'serendipityHTTPPath'); - echo '' . $ts_title . '
' . "\n"; + $html_count = ''; + if ($show_count) { + switch($freq) { + case 'months': + $end_ts = $current_ts + (date('t', $current_ts) * 24 * 60 * 60) - 1; + break; + case 'weeks': + $end_ts = $current_ts + (7 * 24 * 60 * 60) - 1; + break; + case 'days': + $end_ts = $current_ts + (24 * 60 * 60) - 1; + break; + } + + $ec = serendipity_fetchEntries( + array($current_ts, $end_ts), + false, + '', + false, + false, + 'timestamp DESC', + '', + false, + true, + 'count(e.id) AS orderkey', + '', + 'single' + ); + + if (is_array($ec)) { + if (empty($ec['orderkey'])) { + $ec['orderkey'] = '0'; + } + $html_count .= ' (' . $ec['orderkey'] . ')'; + } + } + + echo '' . $ts_title . $html_count . '
' . "\n"; }