Sequence widget (testing assistance requested)

Discussion corner for Developers of Serendipity.
Post Reply
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Sequence widget (testing assistance requested)

Post by judebert »

We've been examining the category templates plugin for how to handle multiple custom-template categories on a single entry. This led us to the conclusion that we needed to specify the precedence of the custom templates.

Six days and about 24 man-hours later, I've got something neat to show you.

It's a new option type for Serendipity, called 'sequence'. You just add a sequence option to your template or plugin, and it returns the order that the user wants the items to be in. If the user has Javascript, it displays a draggable list, just like the plugin configuration page. If the user doesn't have Javascript, it displays up and down arrows on each entry, just like the plugin configuration page. In fact, I borrowed heavily from the plugin configuration page's code.

Whether JavaScript is enabled or not, the entire form is submitted, and all the plugin or template variables will be set correctly.


How to Use the Sequence Widget/Selector/Type/Whatever

The easiest case is to add an array such as the following to your theme options or plugin introspection:

Code: Select all

    array(
        'var'           => 'category_precedence',
        'name'          => 'Category Precedence',
        'description'   => 'TESTING/UNUSED: The order in which categories will be tested',
        'type'          => 'sequence',
        'items'         => array('cat1', 'cat2', 'cat3'),
    ),

In this case, the items cat1, cat2, and cat3 will be displayed in a draggable list (or, if the user has no Javascript, in a list with up and down arrows). When the user submits changes, you'll get a list with the items in the desired order, separated by commas; for instance, 'cat1,cat3,cat2'.

I recognize that sometimes you won't want to display the actual item IDs themselves. For instance, when we want the user to choose the precedences of categories, we wouldn't want the user's choices to be 1,7,18,24,32; we'd want to show him category names.

To display something different for any item, just modify your array like this:

Code: Select all

    array(
        'var'           => 'category_precedence',
        'name'          => 'Category Precedence',
        'description'   => 'TESTING/UNUSED: The order in which categories will be tested',
        'type'          => 'sequence',
        'items'         => array('1' => array('display' => 'Category 1 Name'),   
                                 '27' => array('display' => 'Category 27 Name'),
                                 '34' => array('display' => 'Category 34 Name'))

In this case, you'll get back the variable 'category_precedence', and it will be saved as "1,34,27" (or whatever order the user wants). However, the user will see a re-orderable list with the items 'Category 1 Name', 'Category 27 Name', and 'Category 34 Name'.

But we're not done yet! Sometimes a displayable name won't be enough. You may want thumbnails to improve the user experience. In that case, just add the 'img' key to your array, with a full URL. (Use serendipity_getTemplateFile() to find an image in the currently-used templates.)

Code: Select all

    array(
        'var'           => 'category_precedence',
        'name'          => 'Category Precedence',
        'description'   => 'TESTING/UNUSED: The order in which categories will be tested',
        'type'          => 'sequence',
        'items'         => array('1' => array('display' => 'This', 'img' => 'http://judebert.com/wasted_youth/classic.gif'),  
                                 '2' => array('display' => 'That', 'img' => serendipity_getTemplateFile('img/minus.png')),
                                 '3' => array('display' => 'The Other', 'img' => serendipity_getTemplateFile('img/plus.png'))                                )
         ),
In this case, the options displayed to the user will be 'This' with my reflective-ball image, 'That' with the minus sign from the default template, and 'The Other' with the plus sign from the default template. What you'll receive is the comma-separated list of IDs, such as '3,2,1'.

You can mix-and-match these styles as much as you want. Any item that doesn't have an 'img' associated with it will get no image. Any item that doesn't have a 'display' associated with it will be displayed using the item ID. You can have display variables for some items and no display variables for other items. It's all good.

I've added the sequence type to the serendipity_event_advtypes plugin v0.5, now committed to the repository. I've tested it with Serendipity 1.2.1 (which is the least it requires), under FireFox 2.0 with Javascript enabled and disabled. I need help testing it in other browsers, and advice on whether this is a good format for inputs.

The aim is to get this into the Serendipity core on the next minor release, so I want to make sure I'm not making any assumptions. Thanks!
Judebert
---
Website | Wishlist | PayPal
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sequence widget (testing assistance requested)

Post by garvinhicking »

Hi!

Do you maybe even have an example plugin using that new config option? :)

I'm also thinking if "items" is the best name for it. Wouldn't be "values" or something like that (which already defines items for dropdown/select boxes) would be the better term, to prohibit adding a new one?

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

Post by Don Chambers »

WOW! I've already switched my localhost to 1.3alpha. Will this work on that branch? Assuming it will, my suggestion would be to work it into the template category plugin - a version available for download from your site, not in svn/cvs. Either that, or a "dummy" plugin that merely demonstrates the functionality since it seems you might have done something like that already just to prove it works.

I can envision how this might work with setting priority with the template category plugin, but I am having a difficult time trying to see where else it could be utilized. Do you have other specific ideas?

Actually - I do have one. I have requested changes to the avatar plugin, and Grischa has been making those changes. The plugin has the ability to fetch from 4 different sources, and they are in priority order. So maybe he can find a use for this...... but I would still like to think there are more uses than that.
=Don=
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Post by Don Chambers »

Another idea...... Garvin was helping me with something else a few weeks back, and I thought that part of what we were discussing could be incorporated here as well. I had asked about setting a template option by choosing from a list of available categories, rather than hard coding each category... so perhaps that could be useful in this scenario as well.

Easier to post the question and Garvin's response, rather than a link to the discussion:
garvinhicking wrote:Hi Don!
Don Chambers wrote:As long as we are on the subject, how could I select, from a drop down list, a category id# and set it to a template option variable?
This should work something like that (config.inc.php snippet):

Code: Select all

...
if ($serendipity['GET']['adminModule'] == 'templates') {
  $all_cats = serendipity_fetchCategories('all');
  $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED);
  $catsel = array();
  foreach($all_cats AS $cat) {
    $catsel[$cat['categoryid']] = str_repeat(' ', $cat['depth']) . $cat['category_name'];
  }
}

...

$template_config = array(
 ...
    array(
      'var'           => 'specialcat',
      'name'          => 'Category',
      'type'          => 'select',
      'default'       => '',
      'select_values' => $catsel
    )
...
);
...
Then you should have a {$template_option.specialcat} smarty variable.

Regards,
Garvin
=Don=
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Actually, the serendipity_event_advtypes plugin uses it, twice. Just to demonstrate how it works. It has no effect on the operation of the plugin, but it does display a couple of sequence widgets so you can play around with them and verify their function.

It should work on 1.3a, and in fact on almost any version of Serendipity. I don't think it even requires PHP5, although I could easily be mistaken on that item. However, since I removed the media widget, I figured it should be bumped to require a version of s9y that already included the media widget.

I'd be happy to change it to "values" instead of "items". That still makes sense, and I think consistency is important.

I don't know about the selection of values from a list. I considered making it possible to drag between two lists, one of which is "enabled" and the other of which is "disabled", but that wasn't really what I was looking for. Besides, a multi-select does that job well enough.

I haven't really thought much about where else it might be useful. Perhaps you could define a list of languages, and they could be tried in order? Or the same for a list of ping services. Your favorite weather sites, ad services, shoutcast stations?

Oooh! Which order to check services for spam filters or CAPTCHAs.

I don't know exactly how widespread the use of the sequence widget will be, but I figured that if I can come up with one use (category templates), there will be others.
Judebert
---
Website | Wishlist | PayPal
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Post by Don Chambers »

Since I am using your modifications for the category templates plugin, that is one I would be more than willing to help you test if you want to implement this there.
=Don=
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Okay, I've changed the configuration name from "items" to "values" and checked it in.
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!

My first check of that plugin seems to work perfectly fine. I'd really like to put that code into serendipity 1.3-alpha. Bump the version number to 1.3-alpha2.

Maybe the advtypes can keep this special item until 1.3 is released, and you could re-add the "media" item for backwards compatibility again to that plugin? Because currently, 1.1 users who upgrade to the new plugin will loose the media selection, I don't think this is required?

Then, IMHO the templatecategories plugin could be enhanced to use that sequence item, by checking for the 1.3-alpha2 or higher version. For lower versions, the current code would be used (without sequencing).

Great, great work. I love that drag+drop stuff there. Also I can't currently think of any requirements for this, but I'm sure in the future this will proove very useful.

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 »

Oh, I was afraid something like that might happen. Can the 1.1 users actually update to the new advtypes, since I made it require 1.2? I was hoping that would stop them.

I'll put the media stuff back in if it would actually cut them off.

I can also add this to the 1.3-alpha, if that's the current trunk.

It'll take me a little while, though; my wife just got her biopsy. I'm taking care of her today and tomorrow.
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!

If they already have that plugin installed, they can upgrade, yes. Requirements are AFAIR only evaluated upon first-time install.

Basically, functionality should never be removed from plugins for BC reasons. It would also mean, if a security bugfix is required in the plugin, that people could never upgrade to the latest version.

Many thanks!

Best wishes to your wife!

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 »

That makes perfect sense. I must've been sleep-deprived when I took the media type out.

I'll replace it and get a new copy in as soon as I can.
Judebert
---
Website | Wishlist | PayPal
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Post by Don Chambers »

Where ya at on this Jude?
=Don=
Post Reply