4images Forum & Community
4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: skidpics 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...
-
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} ...
-
I like. :)
In index.php file,
find:
$site_template->register_vars("new_images", $new_images);
unset($new_images);
add after:
//-----------------------------------------------------
//--- 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> ";
$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&".URL_IMAGE_ID."=".$image_row['image_id'])."\">".$lang['edit']."</a> ";
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&".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 \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 ?>:
$lang['last_viewed_images'] = "Last viewed images";
$lang['no_lastviewed_images'] = "No last viewed images";
// Step 3
In details.php file,
find:
show_image($image_row, $mode, 0, 1);
add after:
// 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:
ORDER BY ".$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort'];
$in_mode = 1;
add after:
// 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:
"lang_new_images" => $lang['new_images'],
add after:
"lang_last_viewed_images" => $lang['last_viewed_images'],
// Step 5
In includes/your_template/home.html file,
find:
<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:
{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:
ALTER TABLE " . IMAGES_TABLE . "
ADD image_date_lastview VARCHAR(32) NOT NULL DEFAULT ''
replace " . IMAGES_TABLE . " with your real images table (with prefix). ;)
-
My index file entry is throwing it off - making it not work, nor anything showing. I entered the following as stated:
//-----------------------------------------------------
//--- 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> ";
$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&".URL_IMAGE_ID."=".$image_row['image_id'])."\">".$lang['edit']."</a> ";
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&".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 \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?
-
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..
-
In my code, you can edit the LIMIT:
LIMIT 1
Change 1 to the value you want.
-
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?
-
Awesome Thunderstrijk! nice work! :wink:
How can I add it to the details.html and categorie.html?
-
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
-
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!
-
.. Can anybody help?
sicher :) (attachment)
mfg Andi
-
Klasse! Danke! :wink: