]> git.mjollnir.org Git - s9y.git/commitdiff
Make "archives/" URL properly recognize selected categories.
authorgarvinhicking <garvinhicking>
Wed, 24 Aug 2005 18:39:47 +0000 (18:39 +0000)
committergarvinhicking <garvinhicking>
Wed, 24 Aug 2005 18:39:47 +0000 (18:39 +0000)
Calendar and Archives sidebar plugin also pay strict attention to selected category.
(http://www.s9y.org/forums/viewtopic.php?t=2595)

docs/NEWS
include/functions_entries.inc.php
include/functions_permalinks.inc.php
include/plugin_internal.inc.php
index.php
plugins/serendipity_event_livesearch/serendipity_event_livesearch.php

index 22b92d52e35467374516526c730982f62e461216..b037be835ec1fe5e7bf5f39d9d28a4ac01e3e0fa 100644 (file)
--- 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)
index 23c87ddb7033221df1cf4e5c3c1c468546c470ab..6284b1663d7ac97ae90139f9402ebc071c3a0a04 100644 (file)
@@ -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;
         }
index 4a969a3fe154db70c9805f41ee5358b7c1819adc..7ba11fbf874830ace892791523748c7ef7f11b08 100644 (file)
@@ -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'] . '/(.*)@';
index 2e4bd5379ffaae0aa4bcc8028980550b22e88afd..d032d4f1b32183f44320a784dcffc30323f705d0 100644 (file)
@@ -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 '<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";
     }
 }
 
index 96fc6daf8135ba54fb295f1a09348e65b0b3e2d9..20e50767a45739aa2006ef4c4ab5460ba4e0ba4c 100644 (file)
--- 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]);
index 26df50226a026db571989cb2f26910ed96013b3f..8d5a01ef3ca02d8215ddcd869759f2561b74665a 100644 (file)
@@ -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 '<?xml version="1.0" encoding="utf-8" ?>';
@@ -147,11 +147,12 @@ class serendipity_event_livesearch extends serendipity_event
                                 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;
                     }