• [MOD] Category Image v1.0.2 4 0 5 1
Currently:  

Author Topic: [MOD] Category Image v1.0.2  (Read 392957 times)

0 Members and 1 Guest are viewing this topic.

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
[MOD] Category Image v1.0.2
« on: March 20, 2005, 09:14:38 PM »
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:
Code: [Select]
  $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:
Quote
, c.cat_image

after u've changed it, the line should looks something like this:
Quote
$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:
Code: [Select]
  $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:
Quote
, cat_image

after u changed it, the line should looks something like this:
Quote
$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:
Code: [Select]
  $auth_postcomment = $HTTP_POST_VARS['auth_postcomment'];
Insert below each line:
Code: [Select]
//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:
Code: [Select]
    $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:
Code: [Select]
    $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.2
Find:
Code: [Select]
            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:
Code: [Select]
            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.3
Find:
Code: [Select]
            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:
Code: [Select]
            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:
Code: [Select]
  $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:
Code: [Select]
  $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.3
Find:
Code: [Select]
  $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:
Code: [Select]
  $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:
Code: [Select]
  show_form_footer($lang['save_changes'], $lang['reset'], 2, $lang['back']);
Insert above:
Code: [Select]
// 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>&nbsp;<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."\">&nbsp;$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!):
Code: [Select]
  $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:
Code: [Select]
  $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:
Code: [Select]
  $cat_image = "";Insert below:
Code: [Select]
  $result = $cat_row;


Step 3
Open includes/functions.php
Find:
Code: [Select]
    if (defined("SHOW_RANDOM_IMAGE") && SHOW_RANDOM_IMAGE == 0 || defined("SHOW_RANDOM_CAT_IMAGE") && SHOW_RANDOM_CAT_IMAGE == 0) {
Insert above:
Code: [Select]
    $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:
Code: [Select]
{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 script
Unpack 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
« Last Edit: December 11, 2008, 11:45:50 PM by V@no »
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)

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: [MOD] Category Image v1.0.2
« Reply #1 on: April 04, 2005, 09:59:58 PM »
Hi V@no I have install this mod and it works great!! but I have a question ... when I select and image to be the category image it show its thumbnail and the thumbnail of my gallery are 140 x 140 and that is too big for a category image is there any way to show a smaller one? I could upload a small pic a put that one but i don't wanr that the user see that one

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: [MOD] Category Image v1.0.2
« Reply #2 on: April 04, 2005, 10:03:47 PM »
I'm stupid I just realized how to do it :):)
Code: [Select]
{if cat_image}<img src="{cat_image}" width="33" height="33">{endif cat_image}

Offline Vincent

  • 4images Moderator
  • Addicted member
  • *****
  • Posts: 1.195
    • View Profile
    • www.foto-kocher.com
Re: [MOD] Category Image v1.0.2
« Reply #3 on: April 10, 2005, 10:15:42 PM »
and how to do to have random categorie image?

vincent
Beati pauperi spiritus

4images 1.7 // My Installed Mods


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] Category Image v1.0.2
« Reply #4 on: April 10, 2005, 10:20:23 PM »
u dont need this mod, just uncomment
Code: [Select]
      <!-- {if random_cat_image_file}<a href="{cat_url}"><img src="{random_cat_image_file}" border="1"></a>{endif random_cat_image_file}  --> in category_bit.html template.
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)

Offline Vincent

  • 4images Moderator
  • Addicted member
  • *****
  • Posts: 1.195
    • View Profile
    • www.foto-kocher.com
Re: [MOD] Category Image v1.0.2
« Reply #5 on: April 11, 2005, 02:17:24 PM »
 :lol: @V@no

 :lol:  thanks V@no it works -   :? but what could i do if there is no picture in a category only in the subcategorie?

sincerly
vincent
Beati pauperi spiritus

4images 1.7 // My Installed Mods


Offline vpoint88

  • Pre-Newbie
  • Posts: 1
    • View Profile
Re: [MOD] Category Image v1.0.2
« Reply #6 on: April 12, 2005, 11:30:23 AM »
V@no Thank You :D

I fund this mod for a longtime.
Now I can made it.
you see this is doing ....http://vpcdavid.idv.tw

Thank you again. :P

Offline Vincent

  • 4images Moderator
  • Addicted member
  • *****
  • Posts: 1.195
    • View Profile
    • www.foto-kocher.com
Re: [MOD] Category Image v1.0.2
« Reply #7 on: April 12, 2005, 12:27:45 PM »
Hello

asking again
Quote
but what could i do if there is no picture in a category only in the subcategorie?

Vincent
Beati pauperi spiritus

4images 1.7 // My Installed Mods


Offline karimun

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • http://www.at6pm.com
Re: [MOD] Category Image v1.0.2
« Reply #8 on: April 14, 2005, 07:25:06 PM »
Hi V@no - right now your mod displays the thumbnail of the selected image. Is it possible to change it to have the image itself displayed?

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] Category Image v1.0.2
« Reply #9 on: April 15, 2005, 12:00:07 AM »
display where? :?
@Vincent, your question is not belong to this mod, please start a new topic or something.
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)

Offline max.cady

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: [MOD] Category Image v1.0.2
« Reply #10 on: May 09, 2005, 08:29:49 PM »
Hi, this is an interesting mod. What i am not quite sure about is ... how can I add an image as category image but don't want it to show up as regular image in the categories?

If I understand it right the category image has to be an image in the specific category.

And I have the same question as karimun .. if I define an image as category image not the image itself appears as category image but its thumbnail and I would have to adjust the thumbnail size to the category image size. Is this the right way to go or have I overlooked something?

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] Category Image v1.0.2
« Reply #11 on: May 10, 2005, 01:05:18 AM »
Hi, this is an interesting mod. What i am not quite sure about is ... how can I add an image as category image but don't want it to show up as regular image in the categories?
you are looking for another mod then ;)
http://www.4homepages.de/forum/index.php?topic=3589.0
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)

Offline max.cady

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: [MOD] Category Image v1.0.2
« Reply #12 on: May 10, 2005, 06:28:43 AM »
Hi V@no, thanks so much ... this is exactly what I was looking for.
What a great source this forum is. You guys are the best ...  :mrgreen:

Offline ganeshcp

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: [MOD] Category Image v1.0.2
« Reply #13 on: May 12, 2005, 12:36:23 PM »
u dont need this mod, just uncomment
Code: [Select]
      <!-- {if random_cat_image_file}<a href="{cat_url}"><img src="{random_cat_image_file}" border="1"></a>{endif random_cat_image_file}  --> in category_bit.html template.

hey i tried do that but nothing happens!  the variable is not parsed i guess coz of the if statement. which means its empty.....

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] Category Image v1.0.2
« Reply #14 on: May 12, 2005, 02:27:02 PM »
hey i tried do that but nothing happens! the variable is not parsed i guess coz of the if statement. which means its empty.....

random_cat_image must be enabled in includes/constants.php
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)