Evidence of multiple categories selected?

Discussion corner for Developers of Serendipity.
Post Reply
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Evidence of multiple categories selected?

Post 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.
=Don=
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Evidence of multiple categories selected?

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
onli
Regular
Posts: 2822
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Evidence of multiple categories selected?

Post 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).
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Evidence of multiple categories selected?

Post 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.
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Evidence of multiple categories selected?

Post 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 = ...
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
onli
Regular
Posts: 2822
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Evidence of multiple categories selected?

Post by onli »

multi-author != multi-category. The one I removed was broken in 1.x as well.
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Evidence of multiple categories selected?

Post 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.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Evidence of multiple categories selected?

Post 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);
    }

Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Evidence of multiple categories selected?

Post 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');
    }
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Evidence of multiple categories selected?

Post 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".
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Evidence of multiple categories selected?

Post 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.
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Evidence of multiple categories selected?

Post 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.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Post Reply