zenphoto forums » General Zenphoto Discussion

Set custom sort order from GET

(7 posts)
  • Started 10 months ago by amucklow
  • Latest reply from sbillard

Tags:

  1. amucklow

    Member
    Joined: Sep '06
    Posts: 46

    Hello

    Is it possible to do something like this (using a custom GET() function)?

    if (GET('sort')) {
    $sort = GET('sort');
    setOption('gallery_sorttype', $sort, false);
    }

    The GET() function is getting the key from the URL, and the option is updating on page refresh - this I can see via print_r(getOptionList());, BUT the order of the images doesn't change. Do I need to do something else, like clear memory?

    Posted 10 months ago #
  2. Zenphoto development team
    acrylian

    Developer
    Joined: Jul '07
    Posts: 13,356

    Albums may have their own sortorder set which overrides the global one. So you need to set the album one directly. Some options cannot be set temparily and need to be really saved to work (last parameter to true). I am not sure right now if this is one of these. If the option is of course useless if you want users to change that.

    Btw, you don't need a custom get funtion, the variable $_GET['sort'] is available if you append something to the url like &sort=<yoursortorder>. (That's php basics btw).

    Don't forget to read the Forum rules and usage resources
    Posted 10 months ago #
  3. Zenphoto development team
    sbillard

    Chief Developer
    Joined: May '07
    Posts: 9,768

    Sort order can also be overridden in the various function calls, for instance next_image().

    Don't forget to read the Forum rules and usage resources
    Posted 10 months ago #
  4. amucklow

    Member
    Joined: Sep '06
    Posts: 46

    Thanks - so just for others' benefit what I have now is:

    if ($_GET['sort']) {
        $sort = $_GET['sort'];
    }
    
    while (next_album(true, $sort)):
    <insert_loop>
    endwhile;
    Posted 10 months ago #
  5. Zenphoto development team
    sbillard

    Chief Developer
    Joined: May '07
    Posts: 9,768

    Just a small warning on this. If the sort passed is somehow not valid it may cause an error. Hackers often pass garbage strings to try to sus out a security hole. Something to think about.

    Don't forget to read the Forum rules and usage resources
    Posted 10 months ago #
  6. amucklow

    Member
    Joined: Sep '06
    Posts: 46

    OK - but I guess I could do a custom getSort() function that checked the sort against a list of pre-defined strings, 'name', 'id', 'date' etc.

    Posted 10 months ago #
  7. Zenphoto development team
    sbillard

    Chief Developer
    Joined: May '07
    Posts: 9,768

    Sounds like a good idea.

    Don't forget to read the Forum rules and usage resources
    Posted 10 months ago #

RSS feed for this topic

Reply

You must log in to post.