Author Topic: last images viewed  (Read 13009 times)

0 Members and 1 Guest are viewing this topic.

Offline skidpics

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
last images viewed
« on: October 09, 2007, 05:47:43 AM »
How can I add last viewed images to the main page?  Is there a variable for this, is so, what is it?  I can use the random bloack and change the variable to display the last image viewed...

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: last images viewed
« Reply #1 on: October 09, 2007, 09:14:49 AM »
a short tutorial ... ;)

... you need a additional_image_field (try forum search) for image_date_lastview ...
... in detail.php you need a query to put the current date in this image field ( e.g. like the image counter in details.php ) ...
... and then you can use a similar code for lastview images as for new images ... like in index.php / home.html (use a copy)...
... but in index.php you must change to ... ORDER BY i.image_date_lastview ...
... and instead of all $new_images in your new code of index.php you must use ... $lastview_images ...
... in home.html you can use then {lastview_images} ...
Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: last images viewed
« Reply #2 on: October 10, 2007, 02:12:07 AM »
I like. :)

In index.php file,

find:

Quote
$site_template->register_vars("new_images", $new_images);
unset($new_images);

add after:

Code: [Select]
//-----------------------------------------------------
//--- Last viewed images ------------------------------
//-----------------------------------------------------

$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 c.cat_id = i.cat_id AND i.image_active = 1 AND (i.cat_id NOT IN (".get_auth_cat_sql("auth_viewimage", "NOTIN").", ".get_auth_cat_sql("auth_viewcat", "NOTIN")."))
        ORDER BY i.image_date_lastview DESC
        LIMIT 1
       
        ";
       
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);

if (!$num_rows)  {

  $last_viewed_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
  $last_viewed_images .= $lang['no_lastviewed_images'];
  $last_viewed_images .= "</td></tr></table>";
}
else {

  $last_viewed_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\">";
  $count = 0;
  $bgcounter = 0;
  $admin_links = ""; 
  while ($image_row = $site_db->fetch_array($result)){
    if ($count == 0) {
      $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
      $last_viewed_images .= "<tr class=\"imagerow".$row_bg_number."\">\n";     
    }
   
    $is_image_owner = ($image_row['user_id'] > USER_AWAITING && $user_info['user_id'] == $image_row['user_id']) ? 1 : 0;
    if ($user_info['user_level'] == ADMIN) {
        $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=editimage&image_id=".$image_row['image_id']))."\" target=\"_blank\">".$lang['edit']."</a>&nbsp;";
        $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=removeimage&image_id=".$image_row['image_id']))."\" target=\"_blank\">".$lang['delete']."</a>";       
    } elseif ($is_image_owner) {
        $admin_links .= ($config['user_edit_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editimage&amp;".URL_IMAGE_ID."=".$image_row['image_id'])."\">".$lang['edit']."</a>&nbsp;";
        $admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&amp;".URL_IMAGE_ID."=".$image_row['image_id'])."\">".$lang['delete']."</a>";
        unset ($is_image_owner);
    }
    $last_viewed_images .= "<td width=\"".$imgtable_width."\" valign=\"top\">" . ((isset($admin_links)) ? $admin_links  : "") . "\n";

    show_image($image_row);
   
    $last_viewed_images .= $site_template->parse_template("thumbnail_bit");
    $last_viewed_images .= "\n</td>\n";
    $count++;
    if ($count == $config['image_cells']) {
      $last_viewed_images .= "</tr>\n";
      $count = 0;
    }
    unset ($admin_links);
  } // end while

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

$site_template->register_vars("last_viewed_images", $last_viewed_images);
unset($last_viewed_images);

// Step 2

In lang/english/main.php file,

add on top of ?>:

Code: [Select]
$lang['last_viewed_images'] = "Last viewed images";
$lang['no_lastviewed_images'] = "No last viewed images";

// Step 3

In details.php file,

find:

Quote
show_image($image_row, $mode, 0, 1);

add after:

Code: [Select]
// Last viewed images.
$site_db->query("UPDATE " . IMAGES_TABLE . " SET image_date_lastview = '" . time() . "' WHERE image_id = " . $image_row['image_id'] . " AND cat_id = " . $image_row['cat_id'] . " AND user_id = " . $image_row['user_id']);

find:

Quote
ORDER BY ".$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort'];
    $in_mode = 1;

add after:

Code: [Select]
// Last viewed images.
    $site_db->query("UPDATE " . IMAGES_TABLE . " SET image_date_lastview = '" . time() . "' WHERE image_id = " . $image_row['image_id'] . " AND cat_id = " . $image_row['cat_id'] . " AND user_id = " . $image_row['user_id']);

// Step 4

In includes/page_header.php file,

find:

Quote
"lang_new_images" => $lang['new_images'],

add after:

Code: [Select]
"lang_last_viewed_images" => $lang['last_viewed_images'],

// Step 5

In includes/your_template/home.html file,

find:

Quote
<table width="450" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="head1">
                        <table width="100%" border="0" cellspacing="0" cellpadding="4">
                          <tr>
                            <td class="head1" valign="top">{lang_new_images}</td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                    <tr>
                      <td class="head1">{new_images}</td>
                    </tr>                             
                  </table>
                  <br />

add after:

Code: [Select]
                  {if last_viewed_images}
  <table width="450" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="head1">
                        <table width="100%" border="0" cellspacing="0" cellpadding="4">
                          <tr>
                            <td class="head1" valign="top">{lang_last_viewed_images}</td>
                          </tr>
                        </table>
                      </td>
                    </tr>
    <tr>
                      <td class="head1">{last_viewed_images}</td>
                    </tr>
                  </table>
  <br />
  {endif last_viewed_images}

// Step 6

In phpmyadmin SQL query, add:

Code: [Select]
ALTER TABLE " . IMAGES_TABLE . "
ADD image_date_lastview VARCHAR(32) NOT NULL DEFAULT ''

replace " . IMAGES_TABLE . " with your real images table (with prefix). ;)
« Last Edit: October 10, 2007, 04:09:29 AM by thunderstrike »
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline skidpics

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: last images viewed
« Reply #3 on: October 10, 2007, 05:47:10 AM »
My index file entry is throwing it off - making it not work, nor anything showing.  I entered the following as stated:

Quote
//-----------------------------------------------------
//--- Last viewed images ------------------------------
//-----------------------------------------------------

$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." i,  ".CATEGORIES." c)
        LEFT JOIN ".USERS." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE c.cat_id = i.cat_id AND i.image_active = 1 AND (i.cat_id NOT IN (".get_auth_cat_sql("auth_viewimage", "NOTIN").", ".get_auth_cat_sql("auth_viewcat", "NOTIN")."))
        ORDER BY i.image_date_lastview DESC
        LIMIT 1

        ";

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

if (!$num_rows)  {

  $last_viewed_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
  $last_viewed_images .= $lang['no_lastviewed_images'];
  $last_viewed_images .= "</td></tr></table>";
}
else {

  $last_viewed_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\">";
  $count = 0;
  $bgcounter = 0;
  $admin_links = "";
  while ($image_row = $site_db->fetch_array($result)){
    if ($count == 0) {
      $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
      $last_viewed_images .= "<tr class=\"imagerow".$row_bg_number."\">\n";
    }

    $is_image_owner = ($image_row['user_id'] > USER_AWAITING && $user_info['user_id'] == $image_row['user_id']) ? 1 : 0;
    if ($user_info['user_level'] == ADMIN) {
        $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=editimage&image_id=".$image_row['image_id']))."\" target=\"_blank\">".$lang['edit']."</a>&nbsp;";
        $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=removeimage&image_id=".$image_row['image_id']))."\" target=\"_blank\">".$lang['delete']."</a>";
    } elseif ($is_image_owner) {
        $admin_links .= ($config['user_edit_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editimage&amp;".URL_IMAGE_ID."=".$image_row['image_id'])."\">".$lang['edit']."</a>&nbsp;";
        $admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&amp;".URL_IMAGE_ID."=".$image_row['image_id'])."\">".$lang['delete']."</a>";
        unset ($is_image_owner);
    }
    $last_viewed_images .= "<td width=\"".$imgtable_width."\" valign=\"top\">" . ((isset($admin_links)) ? $admin_links  : "") . "\n";

    show_image($image_row);

    $last_viewed_images .= $site_template->parse_template("thumbnail_bit");
    $last_viewed_images .= "\n</td>\n";
    $count++;
    if ($count == $config['image_cells']) {
      $last_viewed_images .= "</tr>\n";
      $count = 0;
    }
    unset ($admin_links);
  } // end while

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

$site_template->register_vars("last_viewed_images", $last_viewed_images);
unset($last_viewed_images);

I am assuming I change the database settings above as they are in bold: image table, categories and users??

In my phpmyadmin listing, I have 4images_images, 4images_categories and 4images_users showing on the right column.  Am I to use the 4images prefix, or cut that off, since that is the actual DB name?

Offline skidpics

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: last images viewed
« Reply #4 on: October 10, 2007, 06:41:31 AM »
Got it figured out - I just compared the code to the random block I have running - leave the table fields as they are listed in the index.php file.

How many last image views are there supposed to be?  I am just showing one..

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: last images viewed
« Reply #5 on: October 10, 2007, 12:58:15 PM »
In my code, you can edit the LIMIT:

Quote
LIMIT 1

Change 1 to the value you want.
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline skidpics

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: last images viewed
« Reply #6 on: October 10, 2007, 03:11:22 PM »
Thunderstrike, you seriously rock!  Thanks soooo Much!!!

How's it going on getting that template for installing plugins globally, rather than editing all the code?

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: last images viewed
« Reply #7 on: October 23, 2007, 03:09:57 PM »
Awesome Thunderstrijk! nice work! :wink:

How can I add it to the details.html and categorie.html?

Offline Catastropholus

  • Pre-Newbie
  • Posts: 1
    • View Profile
Re: last images viewed
« Reply #8 on: April 30, 2010, 10:48:40 AM »
Hi all,
i have just installed this mod and it works great, thanks a lot for that!  8)
One more question though: i would like to have the user's IP address shown below the last viewed pictures as well (visible to admin only), how can i achieve that?
Thank you in advance,
Martin

Offline www.katzen.ag

  • Jr. Member
  • **
  • Posts: 75
  • KatzenAG - das grosse Katzenportal im Internet
    • View Profile
    • KatzenAG - das grosse Katzenportal im Internet
Re: last images viewed
« Reply #9 on: August 08, 2010, 12:00:22 AM »
Question to step 6:
I don't know how to add a field via myphpadmin. Most of the mods has got a install file. Can anybody help?

Thank you!

KatzenAG - das grosse Katzenportal im Internet

Rembrandt

  • Guest
Re: last images viewed
« Reply #10 on: August 08, 2010, 05:45:01 AM »
.. Can anybody help?

sicher  :)  (attachment)

mfg Andi

Offline www.katzen.ag

  • Jr. Member
  • **
  • Posts: 75
  • KatzenAG - das grosse Katzenportal im Internet
    • View Profile
    • KatzenAG - das grosse Katzenportal im Internet
Re: last images viewed
« Reply #11 on: August 08, 2010, 10:48:53 AM »
Klasse! Danke! :wink:
KatzenAG - das grosse Katzenportal im Internet