Author Topic: [MOD] Public Member Lightboxes - The easy way ;)  (Read 4030 times)

0 Members and 1 Guest are viewing this topic.

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
[MOD] Public Member Lightboxes - The easy way ;)
« on: October 24, 2011, 06:59:44 PM »
Okay, I needed a fast and easy way to make pictures that users put in their lightboxes available for other users browsing their profile (via textlink).
Since on my site everything is public I don't need to bother my users with 100's of options.

If you need a more complex MOD where users can show/hide/create lightboxes, I suggest using V@no's [MOD] Multi-Lightboxes v1.03.2

Tested with 1.7.10

I didn't use $lang files, but if you want them you should be familiar how to add them if you are using 4images with MOD's.

PS: Modified @ 25.10.2011 due to security reasons (thx to V@no) - Please update your code if you installed the MOD


----------------------------------------------------------------------------------------------------------------------------------------------------------------
Okay, put that beer aside for a moment and tell your wife to cook you something tasty, while you follow my steps ;)


STEP 1

open notepad, and insert this:

Code: [Select]
<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: lightbox.php                                         *
 *        Copyright: (C) 2002-2011 Jan Sorgalla                           *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.7.10                                               *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) f&#1100;r weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/

$templates_used 'lightbox_member,thumbnail_member_lightbox_bit';
$main_template 'lightbox_member';

define('GET_CACHES'1);
define('ROOT_PATH''./');
define('MAIN_SCRIPT'__FILE__);
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');
$user_access get_permission();
include(
ROOT_PATH.'includes/page_header.php');


//-----------------------------------------------------
//--- Show Images -------------------------------------
//-----------------------------------------------------
$imgtable_width ceil((intval($config['image_table_width'])) / $config['image_cells']);
if ((
substr($config['image_table_width'], -1)) == "%") {
  
$imgtable_width .= "%";
}

  if (isset(
$HTTP_GET_VARS[URL_USER_ID]) || isset($HTTP_POST_VARS[URL_USER_ID])) {
    
$user_id = (isset($HTTP_GET_VARS[URL_USER_ID])) ? intval($HTTP_GET_VARS[URL_USER_ID]) : intval($HTTP_POST_VARS[URL_USER_ID]);
    if (!
$user_id) {
      
$user_id GUEST;
    }
  }



      
$sql "SELECT u.*, l.*
              FROM ("
.USERS_TABLE." u, ".LIGHTBOXES_TABLE." l)
              WHERE u.user_id='
$user_id' AND l.user_id='$user_id' ";
  $user_info_id $site_db->query_firstrow($sql);  

if (!empty(
$user_info_id['lightbox_image_ids']))  {
  
$image_id_sql str_replace(" "", "trim($user_info_id['lightbox_image_ids']));
  
$sql "SELECT COUNT(image_id) AS images
          FROM "
.IMAGES_TABLE."
          WHERE image_active = 1 AND image_id IN (
$image_id_sql) AND cat_id NOT IN (".get_auth_cat_sql("auth_viewcat""NOTIN").")";
  
$result $site_db->query_firstrow($sql);
  
$num_rows_all $result['images'];
}

$link_arg $site_sess->url(ROOT_PATH."lightbox_member.php?user_id=$user_id"); 
include(
ROOT_PATH.'includes/paging.php');
$getpaging = new Paging($page$perpage$num_rows_all$link_arg);
$offset $getpaging->get_offset();
$site_template->register_vars(array(
  
"paging" => $getpaging->get_paging(),
  
"paging_stats" => $getpaging->get_paging_stats()
));

if (
$num_rows_all) {

  
$sql "SELECT COUNT(image_id) AS images
          FROM "
.IMAGES_TABLE."
          WHERE image_active = 1 AND image_id IN (
$image_id_sql) AND cat_id NOT IN (".get_auth_cat_sql("auth_download""NOTIN").")";
  
$result $site_db->query_firstrow($sql);
  
$download_allowed intval($result['images']) > 0;

  
$additional_sql "";
  if (!empty(
$additional_image_fields)) {
    foreach (
$additional_image_fields as $key => $val) {
      
$additional_sql .= ", i.".$key;
    }
  }
  
$sql "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.""user_name")."
          FROM ("
.IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
          LEFT JOIN "
.USERS_TABLE." u ON (".get_user_table_field("u.""user_id")." = i.user_id)
          WHERE i.image_active = 1 AND i.image_id IN (
$image_id_sql) AND c.cat_id = i.cat_id AND i.cat_id NOT IN (".get_auth_cat_sql("auth_viewcat""NOTIN").")
          ORDER BY i."
.$config['image_order']." ".$config['image_sort'].", i.image_id ".$config['image_sort']."
          LIMIT 
$offset$perpage";
  
$result $site_db->query($sql);
  
$num_rows $site_db->get_numrows($result);
}

if (!
$num_rows)  {
  
$thumbnails "";
  
$msg .= ($msg != "") ? "<p>".$lang['lightbox_no_images'] : $lang['lightbox_no_images'];
}
else {
  
$user_info_id $user_id;
  
$thumbnails "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\">\n";
  
$count 0;
  
$bgcounter 0;
  while (
$image_row $site_db->fetch_array($result)) {
    if (!
$download_allowed && check_permission("auth_download"$image_row['cat_id'])) {
      
$download_allowed true;
    }

    if (
$count == 0) {

      
$row_bg_number = ($bgcounter++ % == 0) ? 2;
      
$thumbnails .= "<tr class=\"imagerow".$row_bg_number."\">\n";
  
   $site_template->register_vars(array(
"huhu" => $user_info_id,  
)); 
  
  
    }
    
$thumbnails .= "<td width=\"".$imgtable_width."\" valign=\"top\">\n";

    
show_image($image_row"lightbox");
    
$thumbnails .= $site_template->parse_template("thumbnail_lightbox_member_bit");
    
$thumbnails .= "\n</td>\n";

    
$count++;
    if (
$count == $config['image_cells']) {
      
$thumbnails .= "</tr>\n";
      
$count 0;
    }
  } 
// end while
  
if ($count 0)  {
    
$leftover = ($config['image_cells'] - $count);
    if (
$leftover >= 1) {
      for (
$i 0$i $leftover$i++){
        
$thumbnails .= "<td width=\"".$imgtable_width."\">\n&nbsp;\n</td>\n";
      }
      
$thumbnails .= "</tr>\n";
    }
  }
  
$thumbnails .= "</table>\n";
 
// end else

$site_template->register_vars(array(
  
"thumbnails" => $thumbnails,  
));
unset(
$thumbnails);

//-----------------------------------------------------
//--- Clickstream -------------------------------------
//-----------------------------------------------------
$clickstream "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'].$lang['lightbox']."</span>";

//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------



$site_template->register_vars(array(
  
"msg" => $msg,
  
"clickstream" => $clickstream
  
"lang_lightbox" => $lang['lightbox'],
));

$site_template->print_template($site_template->parse_template($main_template));
include(
ROOT_PATH.'includes/page_footer.php');
?>



save it as lightbox_member.php and upload it to your 4images root folder



STEP 2

open notepad, and insert this:

Code: [Select]
<!-- you wish detail page in a small javascript open window, use {thumbnail_openwindow} -->
<a href="details.php?image_id={image_id}&mode=member_lightbox&user_id={huhu}"><img src="data/thumbnails/{cat_id}/{thumbnail_file_name}" width="" height="" border="0"></a>
<br />
<b>{image_name}</b> {if image_is_new}<sup class="new">{lang_new}</sup>{endif image_is_new} ({user_name_link})
<br />
<a href="{cat_url}">{cat_name}</a><br />
{if allow_comments}{lang_comments} {image_comments}{endif allow_comments}<br />
{lightbox_button}

save it as thumbnail_lightbox_member_bit.html and upload it to your 4images template folder



STEP 3

open notepad and insert this:

Code: [Select]
{header}
<table width="960" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tablehead">
        <tr>
          <td width="100%" colspan="4"><table cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td width="6"><img src="{template_url}/images/header_top_left.gif" width="6" height="6" alt="" /></td>
        <td width="100%"><img src="{template_url}/images/header_top.gif" width="100%" height="6" alt="" /></td>
<td width="6"><img src="{template_url}/images/header_top_right.gif" width="6" height="6" alt="" /></td>
    </tr>
</table>
</td>
        </tr>
        <tr>
          <td width="6"><img src="{template_url}/images/header_left.gif" width="6" height="60" alt="" /></td>
          <td width="100%"><img src="{template_url}/images/header_logo.gif" width="405" height="60" alt="" /></td>
          <td width="225" align="right">
            <form method="post" action="{url_search}">
              <table border="0" cellspacing="0" cellpadding="1">
                <tr>
                  <td>
                    <input type="text" name="search_keywords" size="15" class="searchinput" />
                  </td>
                  <td>
                    <input type="submit" value="{lang_search}" class="button" name="submit" />
                  </td>
                </tr>
                <tr valign="top">
                  <td colspan="2"><a href="{url_search}" class="smalltext">{lang_advanced_search}</a></td>
                </tr>
              </table>
            </form>
          </td>
          <td align="right" width="6"><img src="{template_url}/images/header_right.gif" width="6" height="60" alt="" /></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td class="bordercolor">
      <table width="100%" border="0" cellspacing="1" cellpadding="0">
        <tr>
          <td class="tablebgcolor">
            <table width="100%" border="0" cellspacing="1" cellpadding="0">
              <tr>
                <td class="navbar" height="23">
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><img src="{template_url}/images/spacer.gif" width="4" height="4" alt="" />{clickstream}</td>
                      <td align="right">
<a href="{url_top_images}"><b>{lang_top_images}</b></a>&nbsp;
<a href="{url_new_images}"><b>{lang_new_images}</b></a>&nbsp;
 </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="150" class="row2" valign="top">
                  <table width="150" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="head2" height="20"><img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" />{lang_registered_user}</td>
                    </tr>
                    <tr>
                      <td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
                    </tr>
                    <tr>
                      <td align="center" class="row1">{user_box} </td>
                    </tr>
                    <tr>
                      <td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
                    </tr>
                  </table>
 {if random_image}
                  <table width="150" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="head2" height="20"> <img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" />{lang_random_image}</td>
                    </tr>
                    <tr>
                      <td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
                    </tr>
                    <tr>
                      <td align="center" class="row1">
   <br />
                        {random_image}
<br />
                        <br />
                      </td>
                    </tr>
                    <tr>
                      <td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
                    </tr>
                  </table>
 {endif random_image}
                </td>
                <td width="1" class="bordercolor" valign="top"><img src="{template_url}/images/spacer.gif" width="1" height="1" alt="" /></td>
                <td width="18" valign="top"><img src="{template_url}/images/spacer.gif" width="18" height="18" alt="" /></td>
                <td width="100%" valign="top"><br />
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><b class="title">{lang_lightbox}</b></td>

                    </tr>
                  </table>
                  <hr size="1" />
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>
   {paging_stats}

 </td>
                    </tr>
                  </table>
                  <br />
                  {if msg}<b>{msg}</b><br /><br />{endif msg}
 {if thumbnails}
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="head1">{thumbnails}</td>
                    </tr>
                  </table>
                  {endif thumbnails}
                  <br />
 {paging}
                  <br />
 <br />
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>{category_dropdown_form}</td>
                      <td align="right">{setperpage_dropdown_form}</td>
                    </tr>
                  </table>
                  <p>&nbsp;</p>
                </td>
                <td width="20" valign="top"><img src="{template_url}/images/spacer.gif" width="19" height="19" alt="" /></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tablebottom">
        <tr>
          <td width="6" nowrap><img src="{template_url}/images/footer_left.gif" width="6" height="19" alt="" /></td>
          <td width="100%"></td>
          <td width="6" nowrap><img src="{template_url}/images/footer_right.gif" width="6" height="19" alt="" /></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
{footer}

save it as lightbox_member.html and upload it to your 4images template folder



STEP 4

open details.php

find:
Code: [Select]
elseif ($mode == "search") {


insert above
Code: [Select]
// mod member lightbox easy way
if ($mode == "member_lightbox") {

  if (isset($HTTP_GET_VARS[URL_USER_ID]) || isset($HTTP_POST_VARS[URL_USER_ID])) {
    $user_id = (isset($HTTP_GET_VARS[URL_USER_ID])) ? intval($HTTP_GET_VARS[URL_USER_ID]) : intval($HTTP_POST_VARS[URL_USER_ID]);
    if (!$user_id) {
      $user_id = GUEST;
    }
  }


$huhu= $user_id;

      $sql = "SELECT u.*, l.*
              FROM (".USERS_TABLE." u, ".LIGHTBOXES_TABLE." l)
              WHERE u.user_id = $user_id AND l.user_id = $user_id ";
      $user_info_id = $site_db->query_firstrow($sql);

  if (!empty($user_info_id['lightbox_image_ids'])) {
    $image_id_sql = str_replace(" ", ", ", trim($user_info_id['lightbox_image_ids']));
    $sql = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
            FROM ".IMAGES_TABLE."
            WHERE image_active = 1 AND image_id IN ($image_id_sql) AND (cat_id NOT IN (".get_auth_cat_sql("auth_viewimage", "NOTIN").", ".get_auth_cat_sql("auth_viewcat", "NOTIN")."))
            ORDER BY ".$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort'];
    $in_mode = 1;
  }
}
// mod member lightbox easy way


find:
Code: [Select]
$next_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$next_image_id.((!empty($mode)) ? "&amp;mode=".$mode : ""));


replace with:
Code: [Select]
// member lightbox easy way
 if ($mode == "member_lightbox") {
    $next_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$next_image_id.((!empty($mode)) ? "&amp;mode=".$mode : "")."&user_id=$huhu");
}
 else {
$next_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$next_image_id.((!empty($mode)) ? "&amp;mode=".$mode : ""));
}
 // member lightbox easy way



find:
Code: [Select]
$prev_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$prev_image_id.((!empty($mode)) ? "&amp;mode=".$mode : ""));


replace with:
Code: [Select]
// member lightbox easy way
 if ($mode == "member_lightbox") {
    $prev_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$prev_image_id.((!empty($mode)) ? "&amp;mode=".$mode : "")."&user_id=$huhu");
}
 else {
$prev_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$prev_image_id.((!empty($mode)) ? "&amp;mode=".$mode : ""));
}
 // member lightbox easy way


save it.

Thats it. You can now use linking to lightbox images, for example in member_profile.html

Code: [Select]
<a href="lightbox_member.php?user_id={user_id}">Show lightbox of {user_name}</a>



PS: Change the html files to suit your site design.
PPS:  I will extend this little MOD if there are any requests

PPPS: Yes, get that beer again on the table ;)


« Last Edit: October 25, 2011, 10:59:12 AM by trez »

Offline Sunny C.

  • Addicted member
  • ******
  • Posts: 1.806
  • I ♥ 4I
    • View Profile
Re: [MOD] Public Member Lightboxes - The easy way ;)
« Reply #1 on: October 24, 2011, 09:25:23 PM »
Thank you!!

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: [MOD] Public Member Lightboxes - The easy way ;)
« Reply #2 on: October 25, 2011, 05:21:45 AM »
Thank you for sharing this mod with only two* steps


Hmmm I see some security issue - never use $_GET/$_POST/etc global variables! 4images uses "old" type ($HTTP_GET_VARS) for a reason - they are filtered and secured.
You also could simplify the process instead of using "user=" use "user_id=" this way it will automatically gets filtered and secured and available via $user_id variable.
And finally, the step 4.1/4.2 could be simplified by adding two lines below the line that needs to be found instead of replacing it, for example:
Code: [Select]
$next_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$next_image_id.((!empty($mode)) ? "&amp;mode=".$mode : ""));
 // member lightbox easy way
 if ($mode == "member_lightbox")
    $next_image_url .= "&amp;user=" . $huhu;




* local joke - a mail was bounced back because on the address was written "123 sixteenth avenue" instead of "123 16th avenue"
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)

Rembrandt

  • Guest
Re: [MOD] Public Member Lightboxes - The easy way ;)
« Reply #3 on: October 25, 2011, 05:39:26 AM »
Hi!
for compatible MySQL v5, search in step 1.) and 4.) :
FROM ".USERS_TABLE." u".LIGHTBOXES_TABLE." l


and repalce:
FROM (".USERS_TABLE." u".LIGHTBOXES_TABLE." l)


here can you read more:  http://www.4homepages.de/forum/index.php?topic=22668.0

mfg Andi

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: [MOD] Public Member Lightboxes - The easy way ;)
« Reply #4 on: October 25, 2011, 10:26:23 AM »
@Andi: I updated the code, thanks

V@no: Updated everything and replaced [$get] with $HTTP_GET_VARS. Hope code is secure now, thanks for your input. You saved a lot of users from sqj-injections ha ha : )

PS: Nice joke, steps now in #
« Last Edit: October 25, 2011, 10:58:09 AM by trez »