Author Topic: TOP 10 by lightbox  (Read 9846 times)

0 Members and 1 Guest are viewing this topic.

Offline Matthias70

  • Full Member
  • ***
  • Posts: 199
    • View Profile
    • Bildergalerie
TOP 10 by lightbox
« on: July 25, 2005, 08:30:46 PM »
Hi,
in my top images-site I have
top 10 by votes
top 10 by rating
top 10 by hits
top 10 by downloads
top 10 by postcards

Demo: http://www.gpaed.de/bildergalerie/top.php?

Is ist possible to include somthing like TOP 10 BY LIGHTBOX?
Means the pictures users have in their lightbox are counted and sorted to a top 10...

Matthias
« Last Edit: February 13, 2006, 08:04:59 PM by Matthias70 »

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: TOP 10 by lightbox
« Reply #1 on: July 28, 2005, 01:40:00 AM »
Its a tricky one and will eat as much of server resources (if not more) as the default top.php does...other words it will be twice slower. The speed will depend on how many members you have and how many images they have in their lightboxes.

Step 1
Open top.php
Find:
Code: [Select]
$site_template->register_vars($register_array);Insert above:
Code: [Select]
// Lightboxes
$sql = "SELECT lightbox_image_ids
        FROM ".USERS_TABLE." u
        LEFT JOIN ".LIGHTBOXES_TABLE." l ON (l.user_id = u.user_id)
        WHERE user_level >= ".USER;
$result = $site_db->query($sql);
$lightbox_array = array();
while ($row = $site_db->fetch_array($result))
{
  $row['lightbox_image_ids'] = trim($row['lightbox_image_ids']);
  if (!empty($row['lightbox_image_ids']))
  {
    $image_ids = explode(" ", $row['lightbox_image_ids']);
    foreach ($image_ids as $key)
    {
      $lightbox_array[$key] = isset($lightbox_array[$key]) ? $lightbox_array[$key] + 1 : 1;
    }
  }
}
arsort($lightbox_array);
$top_list = array();
if (!empty($lightbox_array))
{
  $ids = implode(",", array_keys($lightbox_array));
  $cat_match_sql = ($cat_id && check_permission("auth_viewcat", $cat_id)) ? " AND i.cat_id = '$cat_id' " : "";
  $cat_id_sql = get_auth_cat_sql("auth_viewcat", "NOTIN");
  $sql = "SELECT i.image_id, i.user_id, i.cat_id, i.image_name, i.image_thumb_file, i.image_media_file, u.user_name
          FROM ".IMAGES_TABLE." i
          LEFT JOIN ".USERS_TABLE." u ON (u.user_id = i.user_id)
          WHERE i.image_active = 1 AND i.image_id IN ($ids) AND i.cat_id NOT IN ($cat_id_sql)$cat_match_sql
          ORDER BY FIELD(i.image_id,$ids), i.image_name
          LIMIT 10";
  $result = $site_db->query($sql);
  $i = 1;
  while ($row = $site_db->fetch_array($result))
  {
    $top_list[$i] = $row;
    $i++;
  }
}
$site_db->free_result();
for ($i = 1; $i <= 10; $i++)
{
  if (isset($top_list[$i]))
  {
    if (!check_media_type($top_list[$i]['image_thumb_file']))
    {
      $thumb_file = ICON_PATH."/404.gif";
    }
    else
    {
      if (!get_file_path($top_list[$i]['image_thumb_file'], "thumb", $top_list[$i]['cat_id'], 0, 0))
      {
        $thumb_file = ICON_PATH."/".get_file_extension($top_list[$i]['image_media_file']).".gif";
      }
      else
      {
        $thumb_file = (is_remote($top_list[$i]['image_thumb_file'])) ? $top_list[$i]['image_thumb_file'] : get_file_path($top_list[$i]['image_thumb_file'], "thumb", $top_list[$i]['cat_id'], 0, 1);
      }
    }
    $dimension = 48;
    if ($thumb_info = getimagesize($thumb_file))
    {
      $width = $thumb_info[0];
      $height = $thumb_info[1];
      $ratio = $width / $height;
      if ($ratio > 1)
      {
        $new_width = $dimension;
        $new_height = floor(($dimension/$width) * $height);
      }
      else
      {
        $new_width = floor(($dimension/$height) * $width);
        $new_height = $dimension;
      }
    }
    else
    {
      $new_width = $new_height = $dimension;
    }
    $register_array['image_lightbox_'.$i] = (check_permission("auth_viewimage", $top_list[$i]['cat_id'])) ? "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$top_list[$i]['image_id'])."\">".htmlspecialchars($top_list[$i]['image_name'])."</a>" : htmlspecialchars($top_list[$i]['image_name']);
    $register_array['image_lightbox_openwindow_'.$i] = (check_permission("auth_viewimage", $top_list[$i]['cat_id'])) ? "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$top_list[$i]['image_id'])."\" onclick=\"opendetailwindow()\" target=\"detailwindow\">".htmlspecialchars($top_list[$i]['image_name'])."</a>" : htmlspecialchars($top_list[$i]['image_name']);
    $register_array['image_lightbox_thumb_'.$i] = (check_permission("auth_viewimage", $top_list[$i]['cat_id'])) ? "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$top_list[$i]['image_id'])."\"><img src=\"".$thumb_file."\" width=\"$new_width\" height=\"$new_height\" border=\"1\" align=\"center\" alt=\"".htmlspecialchars($top_list[$i]['image_name'])."\" /></a>" : "<img src=\"".$thumb_file."\" width=\"$new_width\" height=\"$new_height\" border=\"1\" align=\"center\" alt=\"".htmlspecialchars($top_list[$i]['image_name'])." />";
    if (isset($top_list[$i][$user_table_fields['user_name']]) && $top_list[$i]['user_id'] != GUEST)
    {
      $user_profile_link = (!empty($url_show_profile)) ? preg_replace("/{user_id}/", $top_list[$i]['user_id'], $url_show_profile) : ROOT_PATH."member.php?action=showprofile&amp;".URL_USER_ID."=".$top_list[$i]['user_id'];
      $register_array['image_lightbox_user_'.$i] = "<a href=\"".$site_sess->url($user_profile_link)."\">".htmlspecialchars($top_list[$i][$user_table_fields['user_name']])."</a>";
    }
    else
    {
      $register_array['image_lightbox_user_'.$i] = $lang['userlevel_guest'];
    }
    $register_array['image_lightbox_cat_'.$i] = "<a href=\"".$site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$top_list[$i]['cat_id'])."\">".htmlspecialchars($cat_cache[$top_list[$i]['cat_id']]['cat_name'])."</a>";
    $register_array['image_lightbox_number_'.$i] = "<b>".$lightbox_array[$top_list[$i]['image_id']]."</b>";
  }
  else
  {
    $register_array['image_lightbox_'.$i] = "--";
    $register_array['image_lightbox_user_'.$i] = "--";
    $register_array['image_lightbox_cat_'.$i] = "--";
    $register_array['image_lightbox_number_'.$i] = "--";
  }
}
$register_array['lang_top_image_lightbox'] = $lang['top_image_lightbox'];
//end Lightboxes

Step 2
Open lang/<your language>/main.php
At the end, just above closing ?> insert:
Code: [Select]
$lang['top_image_lightbox'] = "Top 10 images added in lightboxes";
Step 3
Open templates/<your template>/top.html
Copy/Paste the block that displays downloads or other top 10 results
then replace all words downloads in your new block with lightbox

That's it.
P.S. this addon also supports [MOD] Toplist altered ;)
P.P.S. No "Lightbox for guest" is supported and never will, because its impossible to do ;)
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 Matthias70

  • Full Member
  • ***
  • Posts: 199
    • View Profile
    • Bildergalerie
Re: TOP 10 by lightbox
« Reply #2 on: July 28, 2005, 03:56:03 PM »
Wow V@no,
that was fast  8O

Your script for Top 10 Lightbox works perfect.

Demo: http://www.gpaed.de/bildergalerie/top.php?

Thank you very much.
Matthias

Offline TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: TOP 10 by lightbox
« Reply #3 on: December 25, 2005, 10:22:22 PM »
On top.php file,

find :

Quote

$user_profile_link = (!empty($url_show_profile)) ? preg_replace("/{user_id}/", $top_list[$i]['user_id'], $url_show_profile) : ROOT_PATH."member.php?action=showprofile&amp;".URL_USER_ID."=".$top_list[$i]['user_id'];


replace with :

Code: [Select]

$user_profile_link = (!empty($url_show_profile)) ? str_replace("{user_id}", $top_list[$i]['user_id'], $url_show_profile) : ROOT_PATH."member.php?action=showprofile&amp;".URL_USER_ID."=".$top_list[$i]['user_id'];


Merry Christmas.

Offline Matthias70

  • Full Member
  • ***
  • Posts: 199
    • View Profile
    • Bildergalerie
Re: TOP 10 by lightbox
« Reply #4 on: December 27, 2005, 06:00:43 PM »
On top.php file,

find :

Quote

$user_profile_link = (!empty($url_show_profile)) ? preg_replace("/{user_id}/", $top_list[$i]['user_id'], $url_show_profile) : ROOT_PATH."member.php?action=showprofile&".URL_USER_ID."=".$top_list[$i]['user_id'];


replace with :

Code: [Select]

$user_profile_link = (!empty($url_show_profile)) ? str_replace("{user_id}", $top_list[$i]['user_id'], $url_show_profile) : $site_sess->url(ROOT_PATH."member.php?action=showprofile&".URL_USER_ID."=".$top_list[$i]['user_id']);


Merry Christmas.

Hi the oracle,
is this answer for me?? ;-)
Matthias

Offline TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: TOP 10 by lightbox
« Reply #5 on: December 27, 2005, 06:03:46 PM »
Quote

is this answer for me??


If you have the $user_name_link string right below (or any related name that will call the $user_profile_link string above) then it is safe to put it like this :

Quote

$user_profile_link = (!empty($url_show_profile)) ? str_replace("{user_id}", $top_list[$i]['user_id'], $url_show_profile) : ROOT_PATH."member.php?action=showprofile&".URL_USER_ID."=".$top_list[$i]['user_id'];


Recall : Only if you have a relative string which already calls the $user_profile_link with $site_sess->url.

I'm sure glad you asked though. ;)

Here's more info on this :

http://www.4homepages.de/forum/index.php?topic=10897.0

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: TOP 10 by lightbox
« Reply #6 on: December 28, 2005, 01:25:53 AM »
TheOracle, if you dont mind, would you please edit the topics you've replyed with this "fix" and remove the replys where the changes are not necesery? To avoid confusion.
Like in this code the changes you've showed are not needed, because $user_profile_link variable being parsed through url() function later on.

Thank you.
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 TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: TOP 10 by lightbox
« Reply #7 on: December 28, 2005, 01:49:51 AM »
It would seems I forgot to edit one of my earlier posts on this page. It has just been corrected now.