Calendar and Archives sidebar plugin also pay strict attention to selected category.
(http://www.s9y.org/forums/viewtopic.php?t=2595)
Version 0.9 ()
------------------------------------------------------------------------
+ * Make "/archive" view also recognize selected category. Sidebar
+ archive and calendar plugins also pay strict attention to which
+ category is selected. Helps "semi-multiple" blogs based on categories
+ a lot. (garvinhicking)
+
* Make media insertion dialog remember settings (via Cookies) and
insert return of the media database on cursor position.
(garvinhicking)
$thisMonth = date('m', serendipity_serverOffsetHour());
$max = 0;
+ if (isset($serendipity['GET']['category'])) {
+ $cat_sql = serendipity_getMultiCategoriesSQL($serendipity['GET']['category']);
+ $cat_get = '/C' . (int)$serendipity['GET']['category'];
+ } else {
+ $cat_sql = '';
+ $cat_get = '';
+ }
+
$output = array();
for ($y = $thisYear; $y >= $lastYear; $y--) {
$output[$y]['year'] = $y;
$s = serendipity_serverOffsetHour(mktime(0, 0, 0, $m, 1, $y), true);
$e = serendipity_serverOffsetHour(mktime(23, 59, 59, $m, date('t', $s), $y), true);
- $entries = serendipity_db_query("SELECT count(id) FROM {$serendipity['dbPrefix']}entries
- WHERE isdraft = 'false'
- AND timestamp >= $s
- AND timestamp <= $e
- " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND timestamp <= " . time() : ''));
+
+ $entries = serendipity_db_query("SELECT count(id)
+ FROM {$serendipity['dbPrefix']}entries e
+ LEFT JOIN {$serendipity['dbPrefix']}entrycat ec
+ ON e.id = ec.entryid
+ LEFT JOIN {$serendipity['dbPrefix']}category c
+ ON ec.categoryid = c.categoryid
+ WHERE isdraft = 'false'
+ AND timestamp >= $s
+ AND timestamp <= $e "
+ . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND timestamp <= " . time() : '')
+ . (!empty($cat_sql) ? ' AND ' . $cat_sql : '')
+ );
$entry_count = $entries[0][0];
/* A silly hack to get the maximum amount of entries per month */
$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['link'] = serendipity_archiveDateUrl($y . '/'. sprintf('%02s', $m) . $cat_get);
+ $data['link_summary'] = serendipity_archiveDateUrl($y . '/'. sprintf('%02s', $m) . $cat_get, true);
$data['date'] = $s;
$output[$y]['months'][] = $data;
}
$PAT['ARCHIVES'] = '@/' . $serendipity['permalinkArchivesPath'].'([/A-Za-z0-9]+)\.html@';
$PAT['FEEDS'] = '@/' . $serendipity['permalinkFeedsPath'].'/@';
$PAT['ADMIN'] = '@/(' . $serendipity['permalinkAdminPath'] . '|entries)(/.+)?@';
- $PAT['ARCHIVE'] = '@/' . $serendipity['permalinkArchivePath'].'$@';
+ $PAT['ARCHIVE'] = '@/' . $serendipity['permalinkArchivePath'] . '/?@';
$PAT['CATEGORIES'] = '@/' . $serendipity['permalinkCategoriesPath'].'/([0-9;]+)@';
$PAT['PLUGIN'] = '@/(' . $serendipity['permalinkPluginPath'] . '|plugin)/(.*)@';
$PAT['SEARCH'] = '@/' . $serendipity['permalinkSearchPath'] . '/(.*)@';
serendipity_plugin_api::hook_event('frontend_fetchentries', $cond, array('noCache' => false, 'noSticky' => false));
if (isset($serendipity['GET']['category'])) {
- $base_query = 'C' . $serendipity['GET']['category'];
+ $base_query = 'C' . (int)$serendipity['GET']['category'];
$add_query = '/' . $base_query;
$querystring = "SELECT timestamp
FROM {$serendipity['dbPrefix']}category c,
$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_month' => serendipity_archiveDateUrl(sprintf('%04d/%02d', $year, $month) . $add_query),
'uri_next' => serendipity_archiveDateUrl(sprintf('%04d/%02d',$nextYear, $nextMonth) . $add_query),
'minScroll' => $minmax[0]['min'],
'maxScroll' => $minmax[0]['max']));
$propbag->add('description', ARCHIVE_FREQUENCY_DESC);
$propbag->add('default', 'months');
break;
+
default:
return false;
}
$ts = mktime(0, 0, 0);
- for($x = 0; $x < $this->get_config('count', 3); $x++) {
+ $add_query = '';
+ if (isset($serendipity['GET']['category'])) {
+ $base_query = 'C' . (int)$serendipity['GET']['category'];
+ $add_query = '/' . $base_query;
+ }
+
+ $max_x = $this->get_config('count', 3);
+ for($x = 0; $x < $max_x; $x++) {
switch($this->get_config('frequency', 'months')) {
case 'months' :
$ts = mktime(0, 0, 0, date('m', $ts), date('d', $ts)-1, date('Y', $ts)); // Must be last in 'case' statement
break;
}
- $link = serendipity_rewriteURL(PATH_ARCHIVES.'/' . $linkStamp . '.html', 'serendipityHTTPPath');
+ $link = serendipity_rewriteURL(PATH_ARCHIVES . '/' . $linkStamp . $add_query . '.html', 'serendipityHTTPPath');
echo '<a href="' . $link . '" title="' . $ts_title . '">' . $ts_title . '</a><br />' . "\n";
}
echo '<a href="'. $serendipity['serendipityHTTPPath'] .'">' . RECENT . '</a><br />' . "\n";
- echo '<a href="'. serendipity_rewriteURL(PATH_ARCHIVE) .'">' . OLDER . '</a>'. "\n";
+ echo '<a href="'. serendipity_rewriteURL(PATH_ARCHIVE . $add_query) .'">' . OLDER . '</a>'. "\n";
}
}
exit;
} else if (preg_match(PAT_ARCHIVE, $uri)) {
$serendipity['GET']['action'] = 'archives';
+ $_args = $serendipity['uriArguments'];
+ /* Attempt to locate hidden variables within the URI */
+ foreach ($_args as $k => $v){
+ if ($v == PATH_ARCHIVE) {
+ continue;
+ }
+
+ if ($v{0} == 'C') { /* category */
+ $cat = substr($v, 1);
+ if (is_numeric($cat)) {
+ $serendipity['GET']['category'] = $cat;
+ unset($_args[$k]);
+ }
+ }
+ }
+
include_once(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
} else if (preg_match(PAT_PLUGIN, $uri, $matches)) {
serendipity_plugin_api::hook_event('external_plugin', $matches[2]);
break;
case 'ls':
- header('X-Search: ' . preg_replace('@[^a-z0-9 \.\-_]@i', '', $_REQUEST['s']));
+ // header('X-Search: ' . htmlspecialchars($eventData) . ' leads to ' . preg_replace('@[^a-z0-9 \.\-_]@i', '', $_REQUEST['s']));
$res = serendipity_searchEntries($_REQUEST['s']);
echo '<?xml version="1.0" encoding="utf-8" ?>';
foreach($res AS $id => $entry) {
echo '<div class="serendipity_livesearch_row"><a href="' . serendipity_archiveURL($entry['id'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])) . '">' . htmlspecialchars($entry['title']) . '</a></div>';
}
- echo '</div>';
} else {
echo '<div class="serendipity_livesearch_row">' . print_r($res, true) . '</div>';
}
+ echo '</div>';
+
break;
}