Properties/Templates of categories with >1 categories

Creating and modifying plugins.
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

I've just completed a Serendipity widget that allows the user to specify the order of a list of items. It even allows the template or plugin designer to specify an alternate display name and a thumbnail image for each item.

If we like this sequence widget, I can modify the category templates plugin to use it as the precedence for the categories.
Judebert
---
Website | Wishlist | PayPal
tpost
Regular
Posts: 77
Joined: Fri Sep 21, 2007 1:45 am

Post by tpost »

Hi judebert,

Love what you have done with this plugin!
Just one question, say a user clicks on an "author" in a post.

i.e. "Posted by (AUTHOR)" part... is it possible to specify which category that author resides in?

Right now it defaults to the top level category.

Let me know if I am not making any sense!

Thanks!
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

At the moment, no. We'd need to extend the categorytemplates plugin for that, I expect.

When you click on an author, it takes you to an overview page. Articles there could appear in multiple categories, so we don't apply any particular category or template to the page.

If we did assign templates to authors, we'd have an additional problem once you clicked on one of the entries: should we assign the author template or the category template? How could we tell?
Judebert
---
Website | Wishlist | PayPal
tpost
Regular
Posts: 77
Joined: Fri Sep 21, 2007 1:45 am

Re:

Post by tpost »

Sorry to bump an old post.

But I have to revisit an old issue regarding clicking on the "author" name on a blog post with the "Properties/Templates of Categories" plugin installed.

One of our "category" blogs is going to have multiple authors, so we'll need to have the ability to see an archive for posts made by a certain author.

Is there any way this can be accomplished with the "Properties/Templates of Categories" plugin.

I'm going to address judebert's concerns from the post above:
judebert wrote:When you click on an author, it takes you to an overview page. Articles there could appear in multiple categories, so we don't apply any particular category or template to the page.
What if the author only posts in one category? Would this make things easy?
judebert wrote:If we did assign templates to authors, we'd have an additional problem once you clicked on one of the entries: should we assign the author template or the category template? How could we tell?
I think the category template should take preference. The author template shouldn't even be a "template" really.

Let me know if this is possible... thanks for reading!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Re:

Post by garvinhicking »

Hi!

You can view postings by authors, but as judebert mentioned, the plugin does not apply any category style to it.

You could try to deduce the category into which this authors posts, but the plugin does not have that code yet.

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/
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Re: Properties/Templates of categories with >1 categories

Post by judebert »

So what you've got is a blog where each author posts to his own category? And what you want is to link the author's name to his category overview?

I can imagine a plugin that would overwrite the entry's $link_author to point it at a specific category. All you'd have to do is hook frontend_display:html:per_entry and overwrite $entry['link_author'] with a call to serendipity_categoryURL and the appropriate category data.

You could also do this in the entries.tpl. Where you see $entries.link_author, you'd simply substitute the appropriate category link instead. For instance, if the category names exactly match the author names, this should do it:

Code: Select all

{foreach  from=$entry.categories item="cat"}
  {if $cat.category_name == $entry.author}
    {assign var='author_cat_link' value=$cat.category_link}
  {/if}
{/foreach}
  {$CONST.POSTED_BY} <a href="{if $author_cat_link}{$author_cat_link}{else}{$entry.author_link}{/if}">{$entry.author}</a>
That should be reasonably robust. It finds the author's category's link, and uses it for the author name. If no such link is assigned to this entry, it uses the normal author link instead.

Incidentally, this is another possible use for Garvin's new template hooks. The template could hook the frontend_display:html:per_entry and substitute the author link instead. Then your Smarty wouldn't be so confusing to newbies. In your template's config.inc.php, add this function:

Code: Select all

function serendipity_plugin_api_event_hook($event, &$bag, &$eventData, $addData = null) {
    global $serendipity;

    switch($event) {
        case 'frontend_display:html:per_entry':
            // Search the categories to find the one for this author
            $query = "SELECT
                         c.categoryid,
                         c.category_name,
                         c.category_description
                    FROM {$serendipity['dbPrefix']}category AS c, {$serendipity['dbPrefix']}authors AS a
                   WHERE a.realname = c.category_name;

            $cat =& serendipity_db_query($query);
            if (!is_array($cat)) {
                $entry['author_link'] = serendipity_categoryURL($cat[0]);
            }
            break;
    }

    return true;
}


Of course, you could change the "WHERE" portion to match how your categories are set up. A full-fledged plugin would allow you to manually set up an arbitrary correlation between authors and categories, but I'm only up to a quick template plugin right now.

ANYway. Two quick code snippets and one plugin suggestion to make the author links point to an associated category. I hope one of these will fit your needs.
Judebert
---
Website | Wishlist | PayPal
tpost
Regular
Posts: 77
Joined: Fri Sep 21, 2007 1:45 am

Re: Re:

Post by tpost »

garvinhicking wrote:You can view postings by authors, but as judebert mentioned, the plugin does not apply any category style to it.
I should have been more specific with regards to the plugins I am using.

I actually cannot see posts by author because I am using the "Properties/Templates of Categories" plugin with the "Start Page Category" plugin. I can only see author posts in the "Start Page Category".

If I click on any other "category" blog's author name, I get the "No entries to print" message because I am guessing Serendipity is looking for the category blog author's post in the "Start Page Category", which, of course, do not exist.

The same problem exists when I try to access S9Y's author RSS feed. It looks for author posts in the "Start Page Category"...

Any way around this?
judebert wrote:So what you've got is a blog where each author posts to his own category? And what you want is to link the author's name to his category overview?
I should have mentioned that one of the categories will feature two or more authors. Therein lies the problem.

The thing I would need is to somehow have the "Start Page Category" plugin work harmoniously with the "Properties/Templates of Categories" plugin. This would probably solve the missing author postings, but not the styling of them.

I guess that's the main problem.

Any creative workarounds :?:
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Re: Properties/Templates of categories with >1 categories

Post by judebert »

I'm having a little trouble visualizing the problem. If you could provide a URL for us to look at, I'm sure it would help straighten things out.
Judebert
---
Website | Wishlist | PayPal
tpost
Regular
Posts: 77
Joined: Fri Sep 21, 2007 1:45 am

Re: Properties/Templates of categories with >1 categories

Post by tpost »

No problem, judebert.

Start page category blog - PipStop

Code: Select all

http://www.tradingmetro.com/blog/
Example of a secondary "category" blog - Forex Weekly Report

Code: Select all

http://www.tradingmetro.com/fxweeklyreport
---

I have disabled the author link for the secondary "category" blogs because they print zero entries. But you can go directly to an author page via URL.

Start page category author link:

Code: Select all

http://www.tradingmetro.com/blog/authors/Samuel-Araki.html
-This works as expected

Secondary "category" blog author link:

Code: Select all

http://www.tradingmetro.com/blog/authors/Pierre-Charlebois.html
-As you can see, this prints zero entries and is using the "Start Page Category" template because S9Y is looking for entries made in the "Start Page Category", and not in any other category.
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Re: Properties/Templates of categories with >1 categories

Post by judebert »

Now it makes perfect sense! Thanks for the links.

I first tried a different author, and his page printed "no entries" as well. (I was thinking that possible accented characters in the first author's name might be causing a problem.) It looks like you're the only author that Serendipity is willing to admit might have entries.

I started to step through the code in the category templates plugin and the Serendipity core, but then I realized you're using a pretty old Serendipity version. Anything I find now might not match your files. Heck, the problem might even have been fixed already.

I'd recommend upgrading to the latest Serendipity stable. At this point, I believe that's 1.4.1. I realize this is a live site, and commercial to boot; you might want to make a copy on a subdomain of your server, just to make sure everything goes well. We've made the process as painless as possible, but sometimes passwords get lost, or memory limits are exceeded. This is a case where caution is warranted.

In fact, before you upgrade your main site, make a backup. Both the files and the database. Import the database to your subdomain site, just to make sure it's a good backup. Then upgrade your main site and see if the problem persists.

I'll be happy to continue helping out, but I don't think there's much I can do with the older Serendipity release.
Judebert
---
Website | Wishlist | PayPal
tpost
Regular
Posts: 77
Joined: Fri Sep 21, 2007 1:45 am

Re: Properties/Templates of categories with >1 categories

Post by tpost »

Thanks for the info, judebert.

Will try upgrading S9Y on our development server and see what happens.
This will probably be on Monday though since it's Good Friday ;)

I appreciate your help! Have a great weekend.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Properties/Templates of categories with >1 categories

Post by garvinhicking »

HI!

Much more important than the s9y core would be the most recent startcat plugin. I actually think that the startcat plugin enforces the default category also on author views, so the pluign would need modification to detect whether Author-View is enabled, and do not enable category restriction in that case...

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/
tpost
Regular
Posts: 77
Joined: Fri Sep 21, 2007 1:45 am

Re: Properties/Templates of categories with >1 categories

Post by tpost »

We upgraded to s9y 1.4.1 and tested the category blogs.
Still the same result as before.

Garvin is right; modification needs to be done to the "startcat" plugin in order for s9y to detect an author view.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Properties/Templates of categories with >1 categories

Post by garvinhicking »

Hi!

Just a quick test. IF you edit the serendipity_event_startcat file and search this:

Code: Select all

                    if (!empty($serendipity['GET']['adminModule'])) {
                        return true;
                    }
and add this after it:

Code: Select all

if (!empty($serendipity['GET']['viewAuthor'])) {
  return true;
}
It should bail out and not apply a category restriction...

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/
tpost
Regular
Posts: 77
Joined: Fri Sep 21, 2007 1:45 am

Re: Properties/Templates of categories with >1 categories

Post by tpost »

Hi Garvin,

I've applied your fix for the "startcat" plugin and tested it.
No go! :(

Any other ideas?
Post Reply