Set custom sort order from GET

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?

Comments

  • acrylian Administrator, Developer
    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).
  • Sort order can also be overridden in the various function calls, for instance `next_image()`.
  • Thanks - so just for others' benefit what I have now is:

    `
    if ($_GET['sort']) {
    $sort = $_GET['sort'];
    }

    while (next_album(true, $sort)):

    endwhile;
    `
  • 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.
  • 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.
  • Sounds like a good idea.
Sign In or Register to comment.