* @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();
$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);
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();
}
}
$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);
{$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
$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'));
}
$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;
}
$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';
}
$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:
}
$link = serendipity_rewriteURL(PATH_ARCHIVES . '/' . $linkStamp . $add_query . '.html', 'serendipityHTTPPath');
- echo '<a href="' . $link . '" title="' . $ts_title . '">' . $ts_title . '</a><br />' . "\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 '<a href="' . $link . '" title="' . $ts_title . '">' . $ts_title . $html_count . '</a><br />' . "\n";
}