From: garvinhicking Date: Wed, 24 Aug 2005 18:39:47 +0000 (+0000) Subject: Make "archives/" URL properly recognize selected categories. X-Git-Tag: 0.9~182 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c6aba1ee3ed85ae1166cfea5740dfed7720b7a1c;p=s9y.git Make "archives/" URL properly recognize selected categories. Calendar and Archives sidebar plugin also pay strict attention to selected category. (http://www.s9y.org/forums/viewtopic.php?t=2595) --- diff --git a/docs/NEWS b/docs/NEWS index 22b92d5..b037be8 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,11 @@ 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) diff --git a/include/functions_entries.inc.php b/include/functions_entries.inc.php index 23c87dd..6284b16 100644 --- a/include/functions_entries.inc.php +++ b/include/functions_entries.inc.php @@ -1782,6 +1782,14 @@ function serendipity_printArchives() { $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; @@ -1799,11 +1807,19 @@ function serendipity_printArchives() { $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 */ @@ -1813,8 +1829,8 @@ function serendipity_printArchives() { $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; } diff --git a/include/functions_permalinks.inc.php b/include/functions_permalinks.inc.php index 4a969a3..7ba11fb 100644 --- a/include/functions_permalinks.inc.php +++ b/include/functions_permalinks.inc.php @@ -209,7 +209,7 @@ function &serendipity_permalinkPatterns($return = false) { $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'] . '/(.*)@'; diff --git a/include/plugin_internal.inc.php b/include/plugin_internal.inc.php index 2e4bd53..d032d4f 100644 --- a/include/plugin_internal.inc.php +++ b/include/plugin_internal.inc.php @@ -180,7 +180,7 @@ class serendipity_calendar_plugin extends serendipity_plugin { 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, @@ -305,7 +305,7 @@ class serendipity_calendar_plugin extends serendipity_plugin { $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'])); @@ -376,6 +376,7 @@ class serendipity_archives_plugin extends serendipity_plugin { $propbag->add('description', ARCHIVE_FREQUENCY_DESC); $propbag->add('default', 'months'); break; + default: return false; } @@ -390,7 +391,14 @@ class serendipity_archives_plugin extends serendipity_plugin { $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' : @@ -409,14 +417,14 @@ class serendipity_archives_plugin extends serendipity_plugin { $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 '' . $ts_title . '
' . "\n"; } echo '' . RECENT . '
' . "\n"; - echo '' . OLDER . ''. "\n"; + echo '' . OLDER . ''. "\n"; } } diff --git a/index.php b/index.php index 96fc6da..20e5076 100644 --- a/index.php +++ b/index.php @@ -274,6 +274,22 @@ if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range 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]); diff --git a/plugins/serendipity_event_livesearch/serendipity_event_livesearch.php b/plugins/serendipity_event_livesearch/serendipity_event_livesearch.php index 26df502..8d5a01e 100644 --- a/plugins/serendipity_event_livesearch/serendipity_event_livesearch.php +++ b/plugins/serendipity_event_livesearch/serendipity_event_livesearch.php @@ -137,7 +137,7 @@ class serendipity_event_livesearch extends serendipity_event 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 ''; @@ -147,11 +147,12 @@ class serendipity_event_livesearch extends serendipity_event foreach($res AS $id => $entry) { echo '
' . htmlspecialchars($entry['title']) . '
'; } - echo ''; } else { echo '
' . print_r($res, true) . '
'; } + echo ''; + break; }