Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - trez

Pages: 1 [2] 3 4 5 6 ... 41
16
I am just wondering, if 4images supporting that? (I searched the whole site but didn't find any related topic)

For example, you have an image, with an additional image field (image_camera) with a value (for example) of "Canon". 

Then in details, we could use {if image_camera == "Canon"} some information {endif} witch will display the information only if image_camera is "Canon".
Hope you got the example.

So is 4images supporting this and I just don't see/find it?



17
Thank's V@no, that works like a charm! : )


18
V@no,

I am trying to add something to that wonderful mod. I have a custom field named "user_karma". What I am trying to achieve is to update that field depending on how a comment is being rated. For example if someone rates my comment up i get +10 karma, when someone votes it down i get -10.

like "SET user_karma=user_karma+10 WHERE user_id = $user_id";".

I guess I have to modify the function "if ($action == "ratingset")". Can you give me some advise?


19
Well they are not in the members profile, that was the main goal. More people are browsing profiles than adding an image to favorites. I am not saying that that method is perfect, but it works for me ;)

20
Guys,

it's just a theoretical example, not a how-to. Maybe I haqd to use an other example because you are right v@no, when a whole lightbox gets deleted we have queries again. Anyway ;)

Rembrandt, it's better then the first code I posted but it uses again a query. The purpose of this topic is to use less queries : )

21
I used 4images on a heavy visited site (almost 25.000 active members), and almost 50 MOD's here from the forum. If you are installing MOD's there will be at some point serious speed and load issues, no matter what.

If you are just about to launch your 4images website, than this thread can really help you avoid sped problems in near future. If you are already using 4images, and have issues than applying my way would be a little more difficult (but not impossible) for sure.

This is just a starter, I will update this thread every few weeks with more details.


1) Avoid *count anywhere you can!

A lot of mods are using this, mainly for paging and user statistics. Okay, we can't get rid of the paging, but we can do something about the statistics.
For example, you want to show how much images a user has in his lightbox. If we use the *count method we would use something like this in our member.php

Quote
    $sql = "SELECT *
         FROM ".LIGHTBOXES_TABLE."
         WHERE ".get_user_table_field("", "user_id")." = ".$user_row['user_id'];
     $user_lightbox_info = $site_db->query_firstrow($sql);
     $num_rows_all = 0;
     if (!empty($user_lightbox_info['lightbox_image_ids'])) {
     $image_id_sql = str_replace(" ", ",", trim($user_lightbox_info['lightbox_image_ids']));
     $sql = "SELECT COUNT(image_id) AS images
          FROM ".IMAGES_TABLE."
          WHERE image_active = 1 AND image_id IN ($image_id_sql)";
     $result = $site_db->query_firstrow($sql);
     $num_rows_all = $result['images'];
    }

Basically, this query searches every entry in your lightbox-table for a specific user_id. On every profile visit! On every member! Imagine having 100.000 entries in your lightbox table - server load will rise to 20-30, even on a dedicated machine.

So that example gives us two choices to solve the problem:

1) Using cache
2) Using smarter coding

Using the cache is okay, but that really doesn't solve the queries since they are generated once every X minutes/hours/days.

Okay, so a smarter approach would be to create a field (INT9) in your members table, and let's say calling it "user_count_lightbox". That field will contain the value of ... yes, the total count value of images that user has in his lightbox.

So, in order to get a correct value, we have to add a sql everywhere where the lightbox is being updated or modified so that every time the user adds/removes an image from his lightbox the count in the table field we created adds 1 or subtracts 1.

So in this example we have to add some code in functions.php , in the function "function add_to_lightbox($id) {".

It looks now like this:

Code: [Select]
function add_to_lightbox($id) {

  global $user_info, $site_db;
  $id = intval($id);
  if (!$id) {
    return false;
  }
 
  $lightbox_ids = $user_info['lightbox_image_ids'];
  $lightbox_array = explode(" ", $lightbox_ids);
  if (!in_array($id, $lightbox_array)) {
    $lightbox_ids .= " ".$id;
  }
  $user_info['lightbox_image_ids'] = trim($lightbox_ids);
  $user_info['lightbox_lastaction'] = time();
 
  $sql = "UPDATE ".LIGHTBOXES_TABLE."
          SET lightbox_lastaction = ".$user_info['lightbox_lastaction'].", lightbox_image_ids = '".$user_info['lightbox_image_ids']."'
          WHERE user_id = ".$user_info['user_id'];


//thats our code  
   $site_db->query($sql);  
    $sql = "UPDATE ".USERS_TABLE."
      SET user_count_lightbox=user_count_lightbox+1 WHERE user_id = ".$user_info['user_id'];
//end
 
 
return ($site_db->query($sql)) ? 1 : 0;

}


For the next function we have to be more careful, because we are subtracting, so the line would look like this:

Code: [Select]
    $sql = "UPDATE ".USERS_TABLE."
      SET user_count_lightbox=user_count_lightbox-1 WHERE user_count_lightbox> 0 AND user_id = ".$user_info['user_id'];


The only thing left would be registering our new field in the member.php like this

Code: [Select]
"user_count_lightbox" => $user_row['user_count_lightbox'],

And now we can use the tag {user_count_lightbox} to show how much pictures someone has without counting them every time the profile is being opened
That will save a lot of resources, and your site will load faster.

That example can be appended on almost every mod that uses "counting on the fly". Just think while you are installing it.

That's for now, I hope this is of some help since it's critical if you expect a lot of visitors. 

22
@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 #

23
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 ;)



24
It's a great MOD, but will get performance problems (if you are not using your own cache). This post is for people with performance problems.
I removed the paging (since when you click on "show all images by XXX" it shows you all images with paging anyway). And I get rid of all the $row calculations,
since it really slows down anything (not just here, I would suggest you get rid of it anywhere).

So the best solution to solve performance problems is placing your thumbnails into <div> containers like this:

1. The modified PHP

Code: [Select]
//-----------------------------------------------------
//--- START Show user images in profile ---------------
//-----------------------------------------------------


$sql3 = "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 c.cat_id = i.cat_id AND i.user_id = $user_id AND i.cat_id NOT IN (".get_auth_cat_sql("auth_viewcat", "NOTIN").")
        ORDER BY i.image_date DESC
        LIMIT 5";

$result = $site_db->query($sql3);
$num_rows = $site_db->get_numrows($result);

if (!$num_rows)  {
  $user_profile_images .= $lang['no_new_images'];
}
else  {
  while ($image_row = $site_db->fetch_array($result)){
    show_image($image_row);
    $user_profile_images .= $site_template->parse_template("thumbnail_bit_profile");
  } // end while
} // end else


$site_template->register_vars("user_profile_images", $user_profile_images);
$site_template->register_vars("lang_user_profile_images", $lang['user_profile_images']);
unset($user_profile_images);
//-----------------------------------------------------
//--- END Show user images in profile -----------------
//-----------------------------------------------------

Less code --> Less Queries --> More performance

Then create a thumbnail_bit_profile with <div>'s
(just an example)

Code: [Select]
<div style="float: left; padding-left: 32px; padding-bottom: 20px;">
<div style="width: 210px; border: 1px solid #dddddd; padding: 1px;">
<div class="imgteaser">
<a href="details.php?image_id={image_id}&mode=search"><img src="data/thumbnails/{cat_id}/{thumbnail_file_name}" width="210" height="210">
</a>
</div>
</div>
</div>

and finally use {user_profile_images} inside a table in your member_profile.html










25
Yepp, working now ;)

PS: Where to send you a six-pack of Heinecken?  8)


26
Hey,

thanks for your help on such short notice. I included the code snippet, image upload works, but there is no resize of the userpic image.
That's how it looks like:

Code: [Select]
      {
        $userpic = $HTTP_POST_VARS['userpic'] = $userpic_new = $userpic_name;
        if ($user_info['userpic'] != $userpic_name && file_exists($userpics_dir.$user_info['userpic']))
        {
          @unlink($userpics_dir.$user_info['userpic']);
        }
        if (!function_exists(init_convert_options))
        {
          require(ROOT_PATH.'includes/image_utils.php');
        }
        $image_info = getimagesize($userpic_file);
        $convert_options = init_convert_options();
        if (($image_info[0] > $config['userpic_width'] || $image_info[1] > $config['userpic_height']))
        {
          $image_info = @getimagesize($src);
          if ($image_info)
  $wh = get_width_height($config['userpic_width'], $image_info[0], $image_info[1], 1);
          if ($convert_options['convert_error'] || !$wh || (!$convert_options['convert_error'] && !resize_image_gd_thumb($userpic_file, $userpic_file, 85, $wh['width'], $wh['height'])))
          {
            if ($image_info[0] > $config['userpic_width'])
            {
              $error[] = $lang['invalid_image_width'];
            }
            if ($image_info[1] > $config['userpic_height'])
            {
              $error[] = $lang['invalid_image_height'];
            }
          }
        }
      }

You were assuming right, I have added the code for those thumbnails

I tried this too, but I assume it's wrong because I get sql errors:

Code: [Select]
        $image_info = getimagesize($userpic_file);
        $convert_options = init_convert_options();

          if ($image_info)
  $wh = get_width_height($config['userpic_width'], $image_info[0], $image_info[1], 1);
          if ($convert_options['convert_error'] || !$wh || (!$convert_options['convert_error'] && !resize_image_gd_thumb($userpic_file, $userpic_file, 85, $wh['width'], $wh['height'])))
          {
            if ($image_info[0] > $config['userpic_width'])
            {
              $error[] = $lang['invalid_image_width'];
            }
            if ($image_info[1] > $config['userpic_height'])
            {
              $error[] = $lang['invalid_image_height'];
            }
          }


EDIT:

Replacing $image_info = @getimagesize($src); with $image_info = @getimagesize($userpic_file); shows me an error in the "resize_image_gd_thumb()". But I guess I am one step closer now.




27
mmmm what about step 10?

Did it. Or maybe the beer was too much, anyway I got it working now ;)

V@no, can we crop the image to a fixed size, rather then resize only the longest side? That was requested before in this thread.

Example: I set 200x200 px in the admin panel, and the uploaded pictures are all 200x200 px (Like in this modification for thumbnails ?

I tried to play around to do it myself, but didn't manage it. Hope you can help, again. Beer is on me ;)











28
Well,

this is getting kind of a diary. Anyway, i implemented yesterday my own
MOD [MOD] - Image Preview in Upload [AJAX] [IE/FF/Opera/Chrome] into the site design.
I have many additional image fields. So I did a multi-step upload form, with the image preview being "sticky" on the
right and it look's now like this:

------------HOVER on customized Browse button

------------HOVER on the "next page / continue submission" link

--------------- last page of the form


Making such a form is easy - You just need to make 3 hidden div's (for a 3-step form) and a simple javascript
pagination to control the visibility. I don't think there is a need for a MOD like this, but I will post the code I used if someone is interested.

PS: The image on the right site is sticky the whole time, because it's in a different div. Here's the logic:

Code: [Select]
<table>
  <tr>
     <td width="50%">
          <form>
              <div id=1>
                   your form 1 page
              </div>
              <div id=2>
                   your form 2 page
               </div>
              <div id=pagination></div>
       </td>
       <td width="50%">
           your preview image div
       </td>
     </tr>
</table>


Anyway, just tell me if you need some real code example.

29
@mawenzi, hab den post redaktiert und ein *.gif eingefuegt. Pfad ist korrekt wenn man den Anweisungen folgt ;)

Am Anfang dachte ich auch es wie V@no zum machen, sprich nur JavaScript ohne AJAX usw, hat aber leider nur in Chrome und FF geklappt. Ich hoffe mal dass dies ne Dauerloesung ist, vieleicht kann es ja mal jemand mit Safari und IE7 probieren, muesste aber klappen.


30
Hey there,

Ever choose an image to upload, fill in all the fields, send the form and realize you took the wrong picture? Yeah, it's a pain in the ***.
Well, use this MOD and your user's will be happy to get a preview of the image they choose to upload. Best thing is, it happens via AJAX and it's compatible
with all modern browsers.

What: This MOD displays the image a user chooses to upload below the "browse" button via AJAX $_Post, without sending the form.
Tested with: 4images 1.7.10 with Firefox 3.X, Chrome 14.X, Opera 11.52, Internet Explorer 8

So let's get this party started.


STEP 1

Create a folder named "preview" in your 4images/data/ directory (4images/data/preview) and CHMOD it to 777




STEP 2

open notepad and insert:

Code: [Select]
<?php
$upload_dir 
'data/preview/'
$preview_url 'http://yourdomain.com/4images/data/preview/';
$filename'';
$result 'ERROR';
$result_msg '';
$allowed_image = array ('image/gif''image/jpeg''image/jpg''image/pjpeg','image/png');
define('PICTURE_SIZE_ALLOWED'2242880); // bytes

if (isset($_FILES['media_file'])) 
{
 if (
$_FILES['media_file']['error'] == UPLOAD_ERR_OK)  
 {
 if (
in_array($_FILES['media_file']['type'], $allowed_image)) {
 if(
filesize($_FILES['media_file']['tmp_name']) <= PICTURE_SIZE_ALLOWED
 {
 
$filename $_FILES['media_file']['name'];
 
move_uploaded_file($_FILES['media_file']['tmp_name'], $upload_dir.$filename);

//phpclamav clamscan for scanning viruses
//passthru('clamscan -d /var/lib/clamav --no-summary '.$upload_dir.$filename, $virus_msg); //scan virus
$virus_msg 'OK'//assume clamav returing OK.
if ($virus_msg != 'OK') {
unlink($upload_dir.$filename);
$result_msg $filename." : ".FILE_VIRUS_AFFECTED;
$result_msg '<font color=red>'.$result_msg.'</font>';
$filename '';
}else {
// main action -- move uploaded file to $upload_dir
$result 'OK';
}
}else {
$filesize filesize($_FILES['media_file']['tmp_name']);
$filetype $_FILES['media_file']['type'];
$result_msg PICTURE_SIZE;
}
}else {
$result_msg SELECT_IMAGE;
}
}
elseif (
$_FILES['media_file']['error'] == UPLOAD_ERR_INI_SIZE)
$result_msg 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
else
$result_msg 'Unknown error';
}

// This is a PHP code outputing Javascript code.
echo '<script language="JavaScript" type="text/javascript">'."\n";
echo 
'var parDoc = window.parent.document;';
if (
$result == 'OK') {
echo 
'parDoc.getElementById("picture_error").innerHTML =  "";';
}
else {
echo 
"parDoc.getElementById('picture_error').innerHTML = '".$result_msg."';";
}

if(
$filename != '') {
echo 
"parDoc.getElementById('picture_preview').innerHTML = '<img src=\'$preview_url$filename\' id=\'preview_picture_tag\' name=\'preview_picture_tag\' width=\'100\' />';";
}

echo 
"\n".'</script>';
exit(); 
// do not go futher

?>


save the file as previewimage.php and upload it to your 4images installation root (like yoursite.com/4images/previewimage.php)



STEP 3

open previewimage.php

find:

Code: [Select]
$preview_url = 'http://yourdomain.com/4images/data/preview/';

and change the path corresponding to your installation

save previewimage.php


STEP 4

open your_template/header.html

find:
Code: [Select]
{if has_rss}


insert above
Code: [Select]
<script>
function ajaxFileUpload(upload_field)
{
// Checking file type
var re_text = /\.jpg|\.gif|\.jpeg/i;
var filename = upload_field.value;
if (filename.search(re_text) == -1) {
alert("File should be either jpg or gif or jpeg");
upload_field.form.reset();
return false;
}
document.getElementById('picture_preview').innerHTML = '<div><img src="progressbar.gif" border="0" /></div>';
upload_field.form.action = 'previewimage.php';
upload_field.form.target = 'upload_iframe';
upload_field.form.submit();
upload_field.form.action = '';
upload_field.form.target = '';
return true;
}
</script>

save your_template/header.html


STEP 5

open your_template/member_uploadform.html

find:
Code: [Select]
<form method="post" action="{url_member}" enctype="multipart/form-data" onsubmit="uploadbutton.disabled=true;">


add above
Code: [Select]
<!-- iframe used for ajax file upload-->
<!-- debug: change it to style="display:block" -->
<iframe name="upload_iframe" id="upload_iframe" style="display:none;"></iframe>
<!-- iframe used for ajax file upload-->


find:
Code: [Select]
<input type="file" name="media_file" class="input" /><br />


replace with:
Code: [Select]
 <input type="file" name="media_file" id="picture" class="input" onchange="return ajaxFileUpload(this);" /><br />
 <span id="picture_error"></span>
 <div id="picture_preview"></div>


save your_template/member_uploadform.html


STEP 6



save this image and upload it to your root directory (yoursite.com/4images/progressbar.gif)


THATS IT ;)

Now, when you choose an image it have to look like this:





TWEAKS

1) You can edit the image size displayed in the previewimage.php (find "width=\'100\')
2) Empty once a week the folder "/preview" or do a cron-job to empty it


Viel Spass

Georgi, aka treZ

Pages: 1 [2] 3 4 5 6 ... 41