Page 1 of 1

Multiple catogories in "Recent Entries" *SOLVED*

Posted: Tue Jan 10, 2006 2:20 pm
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.

Re: Multiple catogories in "Recent Entries"

Posted: Tue Jan 10, 2006 2:39 pm
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

Posted: Tue Jan 10, 2006 3:27 pm
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)) . ')';
        }

Posted: Tue Jan 10, 2006 3:45 pm
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

Posted: Tue Jan 10, 2006 4:05 pm
by garvinhicking
I'll work on that a bit, I might come up with a solution soon.

Regards,
Garvin

Posted: Tue Jan 10, 2006 4:25 pm
by jojje
Plz do so.... most likely you will come up with a better solution than I could do :P

Posted: Tue Jan 10, 2006 4:37 pm
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

Posted: Tue Jan 10, 2006 4:44 pm
by jojje
Perfect :D

Thx alot!!! works exactly as I want

Posted: Tue Jan 10, 2006 5:30 pm
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?

Posted: Tue Jan 10, 2006 5:40 pm
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.

Posted: Wed Jan 11, 2006 1:34 pm
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

Posted: Thu Jan 12, 2006 3:13 am
by judebert
Thanks, Garvin. It's a coding crunch.

I'm thinking abstracting those functions will be good for the theme configurator, too...

Posted: Thu Jan 12, 2006 12:09 pm
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