Multiple catogories in "Recent Entries" *SOLVED*

Creating and modifying plugins.
Post Reply
jojje
Regular
Posts: 41
Joined: Thu Dec 08, 2005 4:09 pm
Location: Sweden
Contact:

Multiple catogories in "Recent Entries" *SOLVED*

Post by jojje »

Is is possible to modify the plugin recent entries so one could show new entries from 2 categories?

As it is now, one can show from one category or all.
Last edited by jojje on Tue Jan 10, 2006 4:45 pm, edited 1 time in total.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Multiple catogories in "Recent Entries"

Post by garvinhicking »

That would be a bit harder to implement within the configuration screen.

But it would be very easy by adjusting the PHP code of the plugin and creating your own custom plugin for that.

Best 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/
jojje
Regular
Posts: 41
Joined: Thu Dec 08, 2005 4:09 pm
Location: Sweden
Contact:

Post by jojje »

ok, watched the code and I don´t really know what to edit. The plugin show_entries looks a lot easier to modiefy for me, it already has a function to add selected categories.

Or perhaps someone can give me a hint?
This is the code for selecting category:

Code: Select all

case 'category':
                $cats    = serendipity_fetchCategories($serendipity['authorid']);
                if (!is_array($cats)) {
                    return false;
                }

                $catlist = serendipity_generateCategoryList($cats, array(0), 4);
                $tmp_select_cats = explode('@@@', $catlist);

                if (!is_array($tmp_select_cats)) {
                    return false;
                }

                $select_cats = array();
                $select_cats['none'] = ALL_CATEGORIES;
                foreach($tmp_select_cats as $cidx => $tmp_select_cat) {
                    $select_cat = explode('|||', $tmp_select_cat);
                    if (!empty($select_cat[0]) && !empty($select_cat[1])) {
                        $select_cats[$select_cat[0]] = $select_cat[1];
                    }
                }

                $propbag->add('type',          'select');
                $propbag->add('select_values', $select_cats);
                $propbag->add('name',          CATEGORY);
                $propbag->add('description',   CATEGORIES_TO_FETCH);
                $propbag->add('default',       'none');
                break;
or should one make the adjustment here:

Code: Select all

function generate_content(&$title) {
        global $serendipity;

        $number         = $this->get_config('number');
        $dateformat     = $this->get_config('dateformat');
        $category       = $this->get_config('category', 'none');
        $title          = $this->get_config('title', $this->title);
        $number_from_sw = $this->get_config('number_from');

        $sql_join   = '';
        $sql_where  = '';
        if ($category != 'none' && is_numeric($category)) {
            $sql_join = 'LEFT OUTER JOIN ' . $serendipity['dbPrefix'] . 'entrycat AS ec ON id = ec.entryid
                         LEFT OUTER JOIN ' . $serendipity['dbPrefix'] . 'category AS c  ON ec.categoryid = c.categoryid';
            $sql_where = ' AND (c.category_left BETWEEN ' . implode(' AND ', serendipity_fetchCategoryRange($category)) . ')';
        }
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Serendipity doesn't havge a "multiselect" option type, which is why the implementation would be so difficult. You would need another GUI element to represent how to treat a multi selection, or immitate the solution other plugins have for multi-selects...

So, yes. The place you need to look at is the lower portion of the code.

Let's say you submit "13;15;18" as $category (by making the select dropdown an input field).

Then you need to modify the code below to use multiuple $categories within the "BETWEEN" statement, by using foreach loops and concatenating the SQL.

Code: Select all

        if ($category != 'none') {
            $categories = explode(';', $category);
            $sql_join = 'LEFT OUTER JOIN ' . $serendipity['dbPrefix'] . 'entrycat AS ec ON id = ec.entryid
                         LEFT OUTER JOIN ' . $serendipity['dbPrefix'] . 'category AS c  ON ec.categoryid = c.categoryid';
            $sql_where = ' AND (c.category_left BETWEEN ' . implode(' AND ', serendipity_fetchCategoryRange($category)) . ')';
        }
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/
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

I'll work on that a bit, I might come up with a solution soon.

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/
jojje
Regular
Posts: 41
Joined: Thu Dec 08, 2005 4:09 pm
Location: Sweden
Contact:

Post by jojje »

Plz do so.... most likely you will come up with a better solution than I could do :P
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Please have a look at this Patch I just committed to SVN:

http://svn.berlios.de/viewcvs/serendipi ... 2&view=rev

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/
jojje
Regular
Posts: 41
Joined: Thu Dec 08, 2005 4:09 pm
Location: Sweden
Contact:

Post by jojje »

Perfect :D

Thx alot!!! works exactly as I want
jojje
Regular
Posts: 41
Joined: Thu Dec 08, 2005 4:09 pm
Location: Sweden
Contact:

Post by jojje »

BTW... is this something that is going to be added to the latest update of s9y alpha2 or do I in the future have to edit these files again?
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

AAARRGH! I spent DAYS coding a multiselect for the newscategory plugin, and now you've gone and made it a standard feature!

Sometimes it hurts when good stuff happens.

Great job, Garvin. I only wish I had thought of it.

Incidentally, I'm sorry I'm so slow lately. I'm preparing for a big test event at work. I'll still be here whenever I can, but it's definitely taking a back seat to my primary source of income.
Judebert
---
Website | Wishlist | PayPal
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hey judebert! Sorry that I didn't help you out earlier with that :-)

I just abstracted the plugin configuration a bit more (in 1.0 alpha) so that some other functions will be usable by plugins in the future.

Good luck with your big test event!

Best 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:

Post by judebert »

Thanks, Garvin. It's a coding crunch.

I'm thinking abstracting those functions will be good for the theme configurator, too...
Judebert
---
Website | Wishlist | PayPal
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi Judebert!
I'm thinking abstracting those functions will be good for the theme configurator, too...
That's what I was thinking of, too. Actually this was my main reason to do abstraction. *g*

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/
Post Reply