Page 1 of 1

Evidence of multiple categories selected?

Posted: Tue Jan 26, 2016 1:41 am
by Don Chambers
Scenario: sidebar category plugin is configured to allow visitor to view entries from multiple categories via checkboxes.

Question: What evidence exists of the selected categories?

My test: In a test site, I selected my 1st and 3rd categories. While the entries for both categories are correctly shown, I cannot find any variable that contains the name of both categories... What I see is only the lowest category ID (ie, 1 - and not 3):

$category is "1" (first category).
$category_info is an array containing everything about category 1. Does not contain anything about category 3.
$head_title is "Category One" (my name for cat 1)

I had never tried to show anything within a template when multiple categories were selected, so perhaps this never worked, or perhaps it has not worked in a very long time. It is not super important, but thought I would ask anyway.

Re: Evidence of multiple categories selected?

Posted: Mon Feb 01, 2016 4:29 pm
by garvinhicking
Don Chambers wrote:Scenario: sidebar category plugin is configured to allow visitor to view entries from multiple categories via checkboxes.
I believe, onli just removed that feature in s9y 2.1+ so you might not really want to rely on this multi-category selection. Correct me if I'm wrong (onli) if I am confusing things.
Question: What evidence exists of the selected categories?
The URL should get a POST or GET request with the category id's concateneated, i.e. "7-11-13".

Regards,
Garvin

Re: Evidence of multiple categories selected?

Posted: Mon Feb 01, 2016 5:56 pm
by onli
I remember checking this earlier: I removed the multi-author option because it was broken. Multi-category I restored later (though I'm not sure whether I just left in the broken code or whether I really fixed it).

Re: Evidence of multiple categories selected?

Posted: Tue Feb 02, 2016 4:20 am
by Don Chambers
I just cloned the latest snapshot, and here are my observations of the category sidebar plugin:

1) "Allow visitors to display multiple categories at once?" is still an option, and seems to function correctly. I can see no evidence of multiple categories selected in the results.... the only category info shown via {debug} is the lowest category ID number.

2) There is an option (as there has always been) labeled "Show a link to "All categories"? The option always shows in the sidebar plugin, regardless of whether set to true or false. The url resulting from this selection is baseurl/index.php?frontpage?frontpage. That final "frontpage" seems a bit unnecessary, no?

Also, the description for this option "CATEGORY_PLUGIN_SHOWALL_DESC" is missing.

Re: Evidence of multiple categories selected?

Posted: Tue Feb 02, 2016 6:17 pm
by Timbalu
Thanks for comming up with that, Don!
I also had in my mind that this removement commit https://github.com/s9y/Serendipity/comm ... 6188a1079c was at least, ... lets say "suspicious".

Now I remembered to give it a try.

Using the "old" Serendipity index.php file and the "old plugin_authors" plugin, it works as expected. (Did not try with the mentioned multicat yet, though. Edit: Now id did!)

So... Why removing? You should fix that, onli!

index

Code: Select all

@@ -64,10 +64,22 @@ if (preg_match(PAT_APPROVE, $uri, $res) && $serendipity['serendipityAuthedUser']
 } else {
     define('DATA_COMMENT_APPROVED', false);
     define('DATA_TRACKBACK_APPROVED', false);
 }
 
+if (isset($serendipity['POST']['isMultiCat']) && is_array($serendipity['POST']['multiCat'])) {
+    $is_multicat = true;
+} else {
+    $is_multicat = false;
+}
+
+if (isset($serendipity['POST']['isMultiAuth']) && is_array($serendipity['POST']['multiAuth'])) {
+    $is_multiauth = true;
+} else {
+    $is_multiauth = false;
+}
+
 if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range']) && is_numeric($serendipity['GET']['range'])) {
     serveArchives();
 } else if (preg_match(PAT_PERMALINK, $uri, $matches) ||
            preg_match(PAT_COMMENTSUB, $uri, $matches) ||
            isset($serendipity['GET']['id']) ||
@@ -82,15 +94,14 @@ if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range
 } else if (preg_match(PAT_ADMIN, $uri)) {
     gotoAdmin();
     exit;
 } else if (preg_match(PAT_ARCHIVE, $uri)) {
     serveArchive();
-} else if ((isset($serendipity['POST']['isMultiCat']) && is_array($serendipity['POST']['multiCat'])) ||
-            preg_match(PAT_PERMALINK_CATEGORIES, $uri, $matches)) {
-    serveCategory($matches);
-} else if (preg_match(PAT_PERMALINK_AUTHORS, $uri, $matches)) {
-    serveAuthorPage($matches);
+} else if ($is_multicat || preg_match(PAT_PERMALINK_CATEGORIES, $uri, $matches)) {
+    serveCategory($matches, $is_multicat);
+} else if ($is_multiauth || preg_match(PAT_PERMALINK_AUTHORS, $uri, $matches)) {
+    serveAuthorPage($matches, $is_multiauth);
 } else if (preg_match(PAT_SEARCH, $uri, $matches)) {
     serveSearch();
 } elseif (preg_match(PAT_CSS, $uri, $matches)) {
     serveCSS($matches[1]);
     exit;
routing

Code: Select all

@@ -187,23 +187,34 @@ function serveSearch() {
     $serendipity['GET']['action']     = 'search';
     $serendipity['GET']['searchTerm'] = urldecode(serendipity_specialchars(strip_tags(implode(' ', $search))));
     include(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
 }
 
-function serveAuthorPage($matches) {
+function serveAuthorPage($matches, $is_multiauth=false) {
     global $serendipity;
     $serendipity['view'] = 'authors';
-    $serendipity['GET']['viewAuthor'] = $matches[1];
+    if ($is_multiauth) {
+        $serendipity['GET']['viewAuthor'] = implode(';', $serendipity['POST']['multiAuth']);
+        $serendipity['uriArguments'][]    = PATH_AUTHORS;
+        $serendipity['uriArguments'][]    = serendipity_db_escape_string($serendipity['GET']['viewAuthor']) . '-multi';
+    } elseif (empty($matches[1]) && preg_match('@/([0-9;]+)@', $uri, $multimatch)) {
+        $is_multiauth = true;
+        $serendipity['GET']['viewAuthor'] = $multimatch[1];
+    } else {
+        $serendipity['GET']['viewAuthor'] = $matches[1];
+    }
 
     $serendipity['GET']['action'] = 'read';
 
     locateHiddenVariables($serendipity['uriArguments']);
 
 
-    $matches[1] = serendipity_searchPermalink($serendipity['permalinkAuthorStructure'], implode('/', $serendipity['uriArguments']), $matches[1], 'author');
-    $serendipity['GET']['viewAuthor'] = $matches[1];
-    $serendipity['GET']['action'] = 'read';
+    if (!$is_multiauth) {
+        $matches[1] = serendipity_searchPermalink($serendipity['permalinkAuthorStructure'], implode('/', $serendipity['uriArguments']), $matches[1], 'author');
+        $serendipity['GET']['viewAuthor'] = $matches[1];
+        $serendipity['GET']['action'] = 'read';
+    }
 
     $uInfo = serendipity_fetchUsers($serendipity['GET']['viewAuthor']);
 
     if (!is_array($uInfo)) {
         $serendipity['view'] = '404';
@@ -216,16 +227,15 @@ function serveAuthorPage($matches) {
     }
 
     include(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
 }
 
-function serveCategory($matches) {
+function serveCategory($matches, $is_multicat=false) {
     global $serendipity;
     $serendipity['view'] = 'categories';
     $uri = $_SERVER['REQUEST_URI'];
 
-    $is_multicat = (isset($serendipity['POST']['isMultiCat']) && is_array($serendipity['POST']['multiCat']));
     if ($is_multicat) {
         $serendipity['GET']['category'] = implode(';', $serendipity['POST']['multiCat']);
         $serendipity['uriArguments'][]  = PATH_CATEGORIES;
         $serendipity['uriArguments'][]  = serendipity_db_escape_string($serendipity['GET']['category']) . '-multi';
     } elseif (preg_match('@/([0-9;]+)@', $uri, $multimatch)) {
and revert the authors plugin removes.

Still having some questions to the removement of weeks args (did you test this?) and the locateHiddenVariables($serendipity['uriArguments']); without being $_args = ...

Re: Evidence of multiple categories selected?

Posted: Tue Feb 02, 2016 7:23 pm
by onli
multi-author != multi-category. The one I removed was broken in 1.x as well.

Re: Evidence of multiple categories selected?

Posted: Tue Feb 02, 2016 7:29 pm
by Timbalu
Yes, but related. MultiAuthor is the serendipity_plugin_authors Plugin. Nothing broken.
If you acticate it for the frontend sidebar (before your removements in it), you are able to select entries by authors or multiAuthors, like suggested in the diffs.

Re: Evidence of multiple categories selected?

Posted: Tue Feb 02, 2016 8:06 pm
by Timbalu
I also managed to re-add the "by week" archive (#serendipity_plugin_archives) option again.

Code: Select all

function serveArchives() {
    global $serendipity;
    $serendipity['view'] = 'archives';

    $_args = locateHiddenVariables($serendipity['uriArguments']);

+    foreach ($_args AS $k => $v){ 
+        if ($v[0] == 'W') { /* Week */
+            $week = substr($v, 1);
+            if (is_numeric($week)) {
+                unset($_args[$k]);
+            }
+        }
+    }

    /* We must always *assume* that Year, Month and Day are the first 3 arguments */
    list(,$year, $month, $day) = $_args;

    if ($year == "archives") {
        unset($year);
    }


Re: Evidence of multiple categories selected?

Posted: Tue Feb 02, 2016 8:20 pm
by Timbalu
and we will have to use this in the same function adding the "!isset($month)".

Code: Select all

    if ((isset($month) && !is_numeric($month)) || !isset($month)) {
        $month = date('m');
    }

Re: Evidence of multiple categories selected?

Posted: Tue Feb 02, 2016 9:07 pm
by Timbalu
Don, the all categories link is set, when you use that option.
But I found a style.css restriction which removes the view. In my template it looked like

Code: Select all

#contactform .serendipity_commentDirection, .category_link_all a {
    display: none;
}
Better check your template for something like this and remove

Code: Select all

, .category_link_all a
:)

The cat link works correct here, eg "http://example.org/s9y/index.php?frontpage".

Re: Evidence of multiple categories selected?

Posted: Tue Feb 02, 2016 9:45 pm
by Don Chambers
Timbalu wrote:Don, the all categories link is set, when you use that option.
What do you mean by that?
Timbalu wrote:But I found a style.css restriction which removes the view. In my template it looked like

Code: Select all

#contactform .serendipity_commentDirection, .category_link_all a {
    display: none;
}
Better check your template for something like this and remove

Code: Select all

, .category_link_all a
:)

The cat link works correct here, eg "http://example.org/s9y/index.php?frontpage".
I have no such styles in my stylesheet.

Re: Evidence of multiple categories selected?

Posted: Sun Feb 07, 2016 5:28 pm
by Timbalu
Don Chambers wrote:What do you mean by that?
It is - when set - placed successfully in the markup of the frontend sidebar.
And if you can find it there, and it does not show up as a link, it is probably disabled by CSS.