This mod will let admin set an image to be showed as a category image instead of folder icon in the categories list.
--------- [ Changed Files ] -------- global.php
admin/categories.php
admin/images.php (optional)
includes/functions.php
templates/<your template>/category_bit.html ---------- [ New files ] ----------- catimage_install.php---------- [ Installation ] -----------Before you do each step, scroll down and make sure that there is no exclusive for you 4images version changes. If there no version specifyed, then it means its for any 4images version.
If you see "For 4images v1.7" then it means only for v1.7, scroll down and look for the changes needed for your version. In some cases there are two separate changes for v1.7 and v1.7.1 for instance, but your version is v1.7.3, then you should do the changes for the closest to your version (in this example it would be v1.7.1)
Step 1 Open
global.php For 4images v1.7 Find:
$sql = "SELECT c.cat_id, c.cat_name, c.cat_description, c.cat_parent_id, c.cat_hits, c.cat_order, c.auth_viewcat, c.auth_viewimage, c.auth_download, c.auth_upload, c.auth_directupload, c.auth_vote, c.auth_sendpostcard, c.auth_readcomment, c.auth_postcomment, COUNT(i.image_id) AS new_images
At the end of that line (!) add:
, c.cat_image
after u've changed it, the line should looks something like this:
$sql = "SELECT c.cat_id, c.cat_name, c.cat_description, c.cat_parent_id, c.cat_hits, c.cat_order, c.auth_viewcat, c.auth_viewimage, c.auth_download, c.auth_upload, c.auth_directupload, c.auth_vote, c.auth_sendpostcard, c.auth_readcomment, c.auth_postcomment, COUNT(i.image_id) AS new_images, c.cat_image
For 4images v1.7.1 Find:
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
At the end of that line (!) add:
, cat_image
after u changed it, the line should looks something like this:
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, cat_image
Step 2 Open
admin/categories.php Find two (2) times:
$auth_postcomment = $HTTP_POST_VARS['auth_postcomment'];
Insert
below each line:
//Category Image
$cat_image = (isset($HTTP_POST_VARS['cat_image']) && intval($HTTP_POST_VARS['cat_image'])) ? intval($HTTP_POST_VARS['cat_image']) : 0;
//End Category Image
Step 2.1 Find:
$sql = "INSERT INTO ".CATEGORIES_TABLE."
(cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment)
VALUES
('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcomment)";
Replace with:
$sql = "INSERT INTO ".CATEGORIES_TABLE."
(cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, cat_image)
VALUES
('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcomment, $cat_image)";
Step 2.2 4images v1.7-1.7.2Find:
SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment
Replace with:
SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment, cat_image = $cat_image
4images v1.7.3Find:
SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_order = $cat_order, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment
Replace with:
SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_order = $cat_order, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment, cat_image = $cat_image
Step 2.3 Find:
$sql = "SELECT cat_name, cat_description, cat_parent_id, cat_hits, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
Replace with:
$sql = "SELECT cat_name, cat_description, cat_parent_id, cat_hits, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, cat_image
4images v1.7.3Find:
$sql = "SELECT cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
Replace with:
$sql = "SELECT cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, cat_image
Step 2.4 Find:
show_form_footer($lang['save_changes'], $lang['reset'], 2, $lang['back']);
Insert
above:
// Category image
$cat_image = "";
if ($result['cat_image'])
{
$sql = "SELECT image_id, image_media_file, image_thumb_file, image_name, cat_id
FROM ".IMAGES_TABLE."
WHERE image_id = ".$result['cat_image'];
if ($image_row = $site_db->query_firstrow($sql))
{
if (!get_file_path($image_row['image_thumb_file'], "thumb", $image_row['cat_id'], 0, 0))
{
$cat_image = ICON_PATH."/".get_file_extension($image_row['image_media_file']).".gif";
}
else
{
$cat_image = get_file_path($image_row['image_thumb_file'], "thumb", $image_row['cat_id'], 0, 1);
}
$file_info = @getimagesize($cat_image);
$dim = 50;
$width = $file_info[0];
$height = $file_info[1];
if ($width && $height) {
if ($width > $dim || $height > $dim) {
@$ratio = $width / $height;
if ($ratio > 1) {
$new_width = $dim;
$new_height = round(($dim/$width) * $height);
}else {
$new_width = round(($dim/$height) * $width);
$new_height = $dim;
}
}else{
$new_width = $width;
$new_height = $height;
}
}else{
$new_width = $dim;
$new_height = $dim;
}
$cat_image = "<a href=\"".$site_sess->url(ROOT_PATH."details.php?image_id=".$result['cat_image'])."\" target=\"_blank\"><img src=\"".$cat_image."\" width=\"".$new_width."\" height=\"".$new_height."\"></a> <a href=\"".$site_sess->url(ROOT_PATH."details.php?image_id=".$result['cat_image'])."\" target=\"_blank\">".$image_row['image_name']."</a>";
}
}
$value = $result['cat_image'];
if (isset($HTTP_POST_VARS['cat_image'])/* && $value == ""*/) {
$value = stripslashes($HTTP_POST_VARS['cat_image']);
}
echo "<tr class=\"".get_row_bg()."\">\n<td><p class=\"rowtitle\">Category image</p></td>\n<td><p><input type=\"text\" size=\"5\" name=\"cat_image\" value=\"".$value."\"> $cat_image</p></td>\n</tr>\n";
//End Category image
Step 2.5 Find
(in 4images v1.7.2 and above there are two instances of this line, find and replace both!):
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
Replace with:
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, cat_image
Step 2.6 (added 2006-03-13)This step only needed for
4images v1.7.2 (or maybe newer)! (thanks to
roger13 for this find)
Find:
$cat_image = "";
Insert
below:
$result = $cat_row;
Step 3 Open
includes/functions.php Find:
if (defined("SHOW_RANDOM_IMAGE") && SHOW_RANDOM_IMAGE == 0 || defined("SHOW_RANDOM_CAT_IMAGE") && SHOW_RANDOM_CAT_IMAGE == 0) {
Insert
above:
$cat_image = "";
if ($cat_cache[$category_id]['cat_image'])
{
$sql = "SELECT image_id, image_media_file, image_thumb_file, cat_id
FROM ".IMAGES_TABLE."
WHERE image_id = ".$cat_cache[$category_id]['cat_image'];
if ($image_row = $site_db->query_firstrow($sql))
{
if (!get_file_path($image_row['image_thumb_file'], "thumb", $image_row['cat_id'], 0, 0))
{
$cat_image = ICON_PATH."/".get_file_extension($image_row['image_media_file']).".gif";
}
else
{
$cat_image = get_file_path($image_row['image_thumb_file'], "thumb", $image_row['cat_id'], 0, 1);
}
}
}
$site_template->register_vars("cat_image", $cat_image);
Step 4 Open
templates/<your template>/category_bit.html Insert where u want the image to be displayed:
{if cat_image}<img src="{cat_image}">{endif cat_image}
Note that it will not display anything if no category image was set.
Step 5 Download
database update scriptUnpack it and upload the
catimage_install.php file into your 4images root dir. Then start the updater by typing in your browser:
http://<your site address>/<path to 4images>/catimage_install.php Step 6 (optional)
For a better experience I'd suggest u install
this mod as well (v3.5 or newer).
------- [ How to use it ] ------- First method: Go to ACP (Admin Control Panel) -> Edit categories -> edit a cegory.
There u should see a new field where u can manualy enter image ID which u want to use as "Category Image". If any image previously was selected, its ID and thumb with image name should be present there.
Second method: Do
Step 6 Then got to ACP -> Edit images -> find an image -> edit.
In the single image edit screen (not the group image edit!) at the bottom, u sould see a new option "Category Image (yes/no)" simply select "yes" to set that image as "Category Image".
Also if any image was previousle set as "Category Image" u should see its thumbnail and image name.
------- [ Extra ] --------- If u wish to show something else if no "Category Image" was set, then u'll need
this (for 4images v1.7) or
this (for 4images v1.7.1) mod. Then in category_bit.html template u can use
{ifno cat_image} and
{endifno cat_image} in
Step 4
Edit :- 17.12.2007 : editing of the formating of this post by mawenzi