• [Mod] Let visitors to chose how to sort images(date,name,..) 5 0 5 1
Currently:  

Author Topic: [Mod] Let visitors to chose how to sort images(date,name,..)  (Read 181489 times)

0 Members and 2 Guests are viewing this topic.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Let visitors to chose how to sort images(date,name,..)
« on: January 29, 2003, 06:57:15 PM »
Just a thought, would be nice let visitors to chose how they want browse pictures sorted by name/date.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Let visitors to chose how to sort images(date,name,..)
« Reply #1 on: January 31, 2003, 02:01:44 AM »
ok, did it myself  :roll:

This version uses sessions (that means, that after each time u open new browser window, it will reset settings to default).
If u want it uses cookies u'll need do some changes that I posted on 3rd page


1. Open /includes/page_header.php
1.1. Find:
Code: [Select]
 "charset" => $lang['charset'],1.2. Add after:
Code: [Select]
 "image_order" => $lang['image_order'],
  "image_sort" => $lang['image_sort'],

1.3. At the end of the file, just before ?> add this code:
A - Sessions based (ones browser window is closed sorting options will be gone)
Code: [Select]
//-----------------------------------------------------
//--- Set Images Sort ---------------------------------
//-----------------------------------------------------
if (isset($HTTP_POST_VARS['imagesorder'])) {
  $imagesorder = $HTTP_POST_VARS['imagesorder'];
  if ($imagesorder) {
    $site_sess->set_session_var("imgs_order", $imagesorder);
    $session_info['imgs_order'] = $imagesorder;
  }
}

if (isset($session_info['imgs_order'])) {
  $config['image_order'] = $session_info['imgs_order'];
}

if (isset($HTTP_POST_VARS['imagessort'])) {
 // $imagessort = intval($HTTP_POST_VARS['imagessort']);
 $imagessort = $HTTP_POST_VARS['imagessort']; //Added 03-11-2003
  if ($imagessort) {
    $site_sess->set_session_var("imgs_sort", $imagessort);
    $session_info['imgs_sort'] = $imagessort;
  }
}

if (isset($session_info['imgs_sort'])) {
  $config['image_sort'] = $session_info['imgs_sort'];
}
//----End Images Sort----------------------------------

//-----------------------------------------------------
//--- Set Images Sort Dropdown ------------------------
//-----------------------------------------------------
  $imgsort_dropdown="\n<select name=\"imagesorder\" class=\"setperpageselect\">\n";
  foreach ($image_order_optionlist as $key => $val) {
    $imgsort_dropdown .= "<option value=\"$key\"";
    if ($config['image_order'] == $key) {
      $imgsort_dropdown .= " selected=\"selected\"";
    }
    $imgsort_dropdown .= ">".$val."</option>\n";
  }
  $imgsort_dropdown .= "</select>\n";
  foreach ($image_sort_optionlist as $key => $val) {
  $imgsort_dropdown .= "<INPUT type=\"radio\" name=\"imagessort\" value=\"$key\"";
  if ($config['image_sort'] == $key) {
      $imgsort_dropdown .= " checked";
  }
  $imgsort_dropdown .= ">".$val."\n";
  }
if ($cat_id != 0) {
  $imgsort_dropdown .= "<input type=\"hidden\" name=\"cat_id\" value=\"".$cat_id."\" />\n";
}
if (isset($show_result) && $show_result == 1) {
  $imgsort_dropdown .= "<input type=\"hidden\" name=\"show_result\" value=\"1\" />\n";
}
$site_template->register_vars("imgsort_dropdown", $imgsort_dropdown);
$imgsort_dropdown_form = $site_template->parse_template("imgsort_dropdown_form");
$site_template->register_vars("imgsort_dropdown_form", $imgsort_dropdown_form);

$site_template->un_register_vars("imgsort_dropdown");
unset($imgsort_dropdown);
unset($imgsort_dropdown_form);
//-----End Images Sort Dropdown------------------------

B - Cookies based (will "remmeber" sorting options even after browser window was closed)
Code: [Select]
//-----------------------------------------------------
//--- Set Images Sort ---------------------------------
//-----------------------------------------------------
if (isset($HTTP_POST_VARS['imagesorder'])) {
  $imagesorder = $HTTP_POST_VARS['imagesorder'];
  if ($imagesorder) {
    $site_sess->set_session_var("imgs_order", $imagesorder);
    $session_info['imgs_order'] = $imagesorder;
  }
}
$cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME : "4images_";
$cookie_order = isset($HTTP_COOKIE_VARS[$cookie_name.'imgs_order']) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name.'imgs_order'])) : $config['image_order'];
$config['image_order'] = (isset($session_info['imgs_order'])) ? $session_info['imgs_order'] : $cookie_order;
$cookie_expire = time() + 60 * 60 * 24 * 90;
setcookie($cookie_name.'imgs_order', serialize($config['image_order']), $cookie_expire, COOKIE_PATH, COOKIE_DOMAIN, COOKIE_SECURE);

if (isset($HTTP_POST_VARS['imagessort'])) {
   $imagessort = $HTTP_POST_VARS['imagessort'];
  if ($imagessort) {
    $site_sess->set_session_var("imgs_sort", $imagessort);
    $session_info['imgs_sort'] = $imagessort;
  }
}

$cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME : "4images_";
$cookie_sort = isset($HTTP_COOKIE_VARS[$cookie_name.'imgs_sort']) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name.'imgs_sort'])) : $config['image_sort'];
$config['image_sort'] = (isset($session_info['imgs_sort'])) ? $session_info['imgs_sort'] : $cookie_sort;
$cookie_expire = time() + 60 * 60 * 24 * 90;
setcookie($cookie_name.'imgs_sort', serialize($config['image_sort']), $cookie_expire, COOKIE_PATH, COOKIE_DOMAIN, COOKIE_SECURE);
//----End Images Sort----------------------------------

//-----------------------------------------------------
//--- Set Images Sort Dropdown ------------------------
//-----------------------------------------------------
  $imgsort_dropdown="\n<select name=\"imagesorder\" class=\"setperpageselect\">\n";
  foreach ($image_order_optionlist as $key => $val) {
    $imgsort_dropdown .= "<option value=\"$key\"";
    if ($config['image_order'] == $key) {
      $imgsort_dropdown .= " selected=\"selected\"";
    }
    $imgsort_dropdown .= ">".$val."</option>\n";
  }
  $imgsort_dropdown .= "</select>\n";
  foreach ($image_sort_optionlist as $key => $val) {
  $imgsort_dropdown .= "<INPUT type=\"radio\" name=\"imagessort\" value=\"$key\"";
  if ($config['image_sort'] == $key) {
      $imgsort_dropdown .= " checked";
  }
  $imgsort_dropdown .= ">".$val."\n";
  }
if ($cat_id != 0) {
  $imgsort_dropdown .= "<input type=\"hidden\" name=\"cat_id\" value=\"".$cat_id."\" />\n";
}
if (isset($show_result) && $show_result == 1) {
  $imgsort_dropdown .= "<input type=\"hidden\" name=\"show_result\" value=\"1\" />\n";
}
$site_template->register_vars("imgsort_dropdown", $imgsort_dropdown);
$imgsort_dropdown_form = $site_template->parse_template("imgsort_dropdown_form");
$site_template->register_vars("imgsort_dropdown_form", $imgsort_dropdown_form);

$site_template->un_register_vars("imgsort_dropdown");
unset($imgsort_dropdown);
unset($imgsort_dropdown_form);
//-----End Images Sort Dropdown------------------------


2. Open /lang/YOURLANGUAGE/main.php
2.1. Add at the end of the file, just before ?> this code:
Code: [Select]
//--------------Images Sort-------------------------
//---This was taken from /lang/YOURLANG/admin.php---
//--------------------------------------------------
$lang['image_order'] = "Sort images by";
$image_order_optionlist = array(
  "image_name"      => "Name",
  "image_date"      => "Date",
  "image_downloads" => "Downloads",
  "image_votes"     => "Votes",
  "image_rating"    => "Rating",
  "image_hits"      => "Hits"
);
$lang['image_sort'] = "Ascending/Descending";
$image_sort_optionlist = array(
  "ASC"  => "Ascending",
  "DESC" => "Descending"
);

3. Create a template and save it as imgsort_dropdown_form.html with this code:
Code: [Select]
<TABLE border="0" cellspacing="0" cellpadding="0">
<FORM method="post" action="{self}">
<TR>
<TD nowrap>{image_order}&nbsp;</TD>
<TD nowrap>
{imgsort_dropdown}&nbsp;
<INPUT type="submit" value="{lang_go}" class="button" name="submit" /></TD>
</TR>
</FORM>
</TABLE>


Now u can insert in any templates {imgsort_dropdown_form} in the place u want show "sort images by" sellect.

U can see it in action (its on the bottom):
http://gallery.vano.org/c6
« Last Edit: October 18, 2009, 09:48:42 PM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline deviator

  • Newbie
  • *
  • Posts: 28
    • View Profile
[Mod] Let visitors to chose how to sort images(date,name,..)
« Reply #2 on: January 31, 2003, 09:40:35 PM »
WOW man, it works very well .... thanks ;)

check it out @ http://faithfulangels.com and select a category!

Offline IngoT

  • Newbie
  • *
  • Posts: 49
    • View Profile
[Mod] Let visitors to chose how to sort images(date,name,..)
« Reply #3 on: January 31, 2003, 10:36:32 PM »

Offline MrWante

  • Newbie
  • *
  • Posts: 11
    • View Profile
Great! :)
« Reply #4 on: February 04, 2003, 02:58:18 PM »
I was thinking of another sort (thing) that could be useful!
How about having an option in the edit category where you could decide the default sort that category is sorted as...

And also, an adition, sorting by image_id would also be nice... so you can have the orignal upload order...
And finally, sorting by filename, not just by image name.... (which can be changed)...

Don't these ideas make sense...???

Anyway.. I know I sure would like to see it implemented, and I am sure others would find it useful too!

Anyway, great work V@no...
Your name sure do pop up here alot! :D

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Suggestion
« Reply #5 on: February 04, 2003, 08:06:12 PM »
It would be perfect if someone could ehance this already nice mod to store the sort criteria in the database against the user table.  That way the last selected sort method could be used on return visits and it would persist across PCs.  Either that or store the info in a cookie.

Thanks V@no

Offline Ernesto Taseffa

  • Full Member
  • ***
  • Posts: 151
    • View Profile
[Mod] Let visitors to chose how to sort images(date,name,..)
« Reply #6 on: February 25, 2003, 07:28:06 PM »
.
« Last Edit: August 09, 2009, 01:46:01 AM by Ernesto Taseffa »

Offline helluvaguy

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
[Mod] Let visitors to chose how to sort images(date,name,..)
« Reply #7 on: February 25, 2003, 08:07:35 PM »
Simply put the tag {imgsort_dropdown_form} in every template where you want it to appear, like search.html, category.html, and so forth.

Just put this tag within the HTML code so it is visible where you like, above or below the thumbnails or maybe even between the category-dropdown-menu and the picture per page drop-down-menu.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Suggestion
« Reply #8 on: February 26, 2003, 12:31:33 AM »
Quote from: Chris
It would be perfect if someone could ehance this already nice mod to store the sort criteria in the database against the user table.  That way the last selected sort method could be used on return visits and it would persist across PCs.  Either that or store the info in a cookie.

Thanks V@no

yes, I like this idea, but I'd like have your guys appinium, how this should work. I mean, right now my idea do it this way:

1. user can select from his control panel (profile edit) how he want sort images and how many images per page by default (whenever he closed browser and then come back).
and when he browse the site, he still has chose of image sorting, that works temporary, untill he close/open browser (just like right now, original code of this mod stay as it is and needs just little addon to it)

2. or do u want changing images sorting not from "edit user profile" will be saved directly in the database? (this case whole mod needs to be rewriten)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline helluvaguy

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
[Mod] Let visitors to chose how to sort images(date,name,..)
« Reply #9 on: February 26, 2003, 12:47:55 AM »
I would prefer solution #2, because i use the gallery integrated into a phpBB2 forum, where the users access the user-profil from the phpBB2 and not the one from 4images.

Besides i think it would be much easier for most users to just change it without going to the user profil, eventhough it would mean a lot more work to programm it that way.

But you asked for opinons and this it mine... :)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Let visitors to chose how to sort images(date,name,..)
« Reply #10 on: February 26, 2003, 01:01:15 AM »
yes, thx. (couple more opinions and I'll start work on it ;) )

P.S. dont forget, that sort images options will still be available as it is now, it just wont be saved in the database.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline dune

  • Newbie
  • *
  • Posts: 15
    • View Profile
[Mod] Let visitors to chose how to sort images(date,name,..)
« Reply #11 on: February 26, 2003, 05:13:03 PM »
i think it would be quite nice for users to have this as a profile option. it would also be useful to keep it in thumbnail pages display so that they don't have to go to their control panel each time they would want to change the order...

Offline Ernesto Taseffa

  • Full Member
  • ***
  • Posts: 151
    • View Profile
[Mod] Let visitors to chose how to sort images(date,name,..)
« Reply #12 on: February 26, 2003, 05:34:38 PM »
.
« Last Edit: August 09, 2009, 01:48:37 AM by Ernesto Taseffa »

Offline tradertt

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
[Mod] Let visitors to chose how to sort images(date,name,..)
« Reply #13 on: February 27, 2003, 01:05:46 AM »
I would prefer option 2 too ...

Offline tradertt

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
[Mod] Let visitors to chose how to sort images(date,name,..)
« Reply #14 on: February 27, 2003, 12:42:41 PM »
Can it sort by username too?  Sometimes people may want to see what a user has posted.... Kindly let me know what to add thank you :D


GREAT MOD !!