Author Topic: [MOD-HELP] Icons for each category with admin control  (Read 31836 times)

0 Members and 1 Guest are viewing this topic.

Offline marcelocamargo

  • Pre-Newbie
  • Posts: 5
    • View Profile
    • http://www.marcelocamargo.com.br
[MOD-HELP] Icons for each category with admin control
« on: March 09, 2003, 09:38:33 PM »
Hello friends,

Firstly, sorry about my english...


1. I need to add a icon for each category. At here, easy  :D
2. The icon must be added or edited in panel control, by admin
3. It's like to submit a thumbnail from image, but in this case, the thumbnail will be linked to category, and must appear in "category_bit.html" like:

Code: [Select]


{if category_with_icon}
 <a href="{cat_url}"><img src="{cat_icon}"></a>
{endif category_with_icon}



How could I make this mod?
Anybody help me?

Thanks for all...

(V)arcelo Camargo
marcelo@marcelocamargo.com.br
Itapetininga - SP - Brasil

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-HELP] Icons for each category with admin control
« Reply #1 on: March 09, 2003, 09:44:09 PM »
if u have a little PHP knowlege I could try explain how it can be done.
like, for the beginning, I'd use one extra (new) field in the 4images_categories table, to store "icon" information for each category.
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 marcelocamargo

  • Pre-Newbie
  • Posts: 5
    • View Profile
    • http://www.marcelocamargo.com.br
First step, OK!
« Reply #2 on: March 09, 2003, 10:43:25 PM »
Hello V@ano,


Yes... I have PHP knowlege...

The new field "icon" was added in 4images_categories table...
Now, the next step is to modify control panel, in "Add category" and "Edit category".

I will try to make this alone, but maybe I need your help :-)

Thank you...

(V)arcelo Camargo
marcelo@marcelocamargo.com.br
Itapetininga - São Paulo - Brasil

Offline marcelocamargo

  • Pre-Newbie
  • Posts: 5
    • View Profile
    • http://www.marcelocamargo.com.br
First attempt
« Reply #3 on: March 10, 2003, 01:08:36 AM »
Hello friends,

This is my first attempt to make this modification...

See below all carried through alterations:

1. Objective

The objective of this modification is to leave the option to the administrator of the system to attribute an icon to a category. This resource is not obligator, and is the criterion of the administrator to use it or not.

2. Modifications in the Database

2.1. Modify the table 4_images_categories, adding to the new field cat_icon

SQL Command:
Code: [Select]
ALTER TABLE 'database_name'.'4images_categories' ADD 'cat_icon' VARCHAR(255);

3. Modifications in files

3.1. Modifications in file "admin/categories.php"

Search for:
Code: [Select]
if ($action == "addcat") {
  if ($msg != "") {
    printf("<b>%s</b>\n", $msg);
  }

  show_form_header("categories.php", "savecat");
  show_table_header($lang['nav_categories_add'], 2);
  show_input_row($lang['field_category_name'], "cat_name", "", $textinput_size);


Add below:
Code: [Select]
 show_upload_row($lang['thumb'], "thumb_file", "<br /><span class=smalltext>".$lang['allowed_mediatypes_desc']." jpg, gif, png</span>");

Search for:
Code: [Select]
if ($action == "savecat") {
  $error = array();
  $cat_name = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_name']));
  $cat_description = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_description']));
  $cat_parent_id = intval($HTTP_POST_VARS['cat_parent_id']);
  $cat_order = (isset($HTTP_POST_VARS['cat_order'])) ? intval($HTTP_POST_VARS['cat_order']) : 0;

  $auth_viewcat = $HTTP_POST_VARS['auth_viewcat'];
  $auth_viewimage = $HTTP_POST_VARS['auth_viewimage'];
  $auth_download = $HTTP_POST_VARS['auth_download'];
  $auth_upload = $HTTP_POST_VARS['auth_upload'];
  $auth_directupload = $HTTP_POST_VARS['auth_directupload'];
  $auth_vote = $HTTP_POST_VARS['auth_vote'];
  $auth_sendpostcard = $HTTP_POST_VARS['auth_sendpostcard'];
  $auth_readcomment = $HTTP_POST_VARS['auth_readcomment'];
  $auth_postcomment = $HTTP_POST_VARS['auth_postcomment'];

  if ($cat_name == "") {
    $error['cat_name'] = 1;
  }


Change to:
Code: [Select]
if ($action == "savecat") {
  $error = array();
  $cat_name = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_name']));
  $cat_description = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_description']));
  $cat_parent_id = intval($HTTP_POST_VARS['cat_parent_id']);
  $cat_order = (isset($HTTP_POST_VARS['cat_order'])) ? intval($HTTP_POST_VARS['cat_order']) : 0;

  $auth_viewcat = $HTTP_POST_VARS['auth_viewcat'];
  $auth_viewimage = $HTTP_POST_VARS['auth_viewimage'];
  $auth_download = $HTTP_POST_VARS['auth_download'];
  $auth_upload = $HTTP_POST_VARS['auth_upload'];
  $auth_directupload = $HTTP_POST_VARS['auth_directupload'];
  $auth_vote = $HTTP_POST_VARS['auth_vote'];
  $auth_sendpostcard = $HTTP_POST_VARS['auth_sendpostcard'];
  $auth_readcomment = $HTTP_POST_VARS['auth_readcomment'];
  $auth_postcomment = $HTTP_POST_VARS['auth_postcomment'];
  $thumb_file_name = trim($HTTP_POST_VARS['thumb_file']);

  if ($cat_name == "") {
    $error['cat_name'] = 1;
  }

  //Upload Thumbnail if exists
  $thumb_file = "thumb_file";
  $remote_thumb_file = trim($HTTP_POST_VARS['remote_thumb_file']);
  $new_thumb_name = "";
  if (!empty($HTTP_POST_FILES[$thumb_file]['tmp_name']) && $HTTP_POST_FILES[$thumb_file]['tmp_name'] != "none" && !$uploaderror) {
    $new_thumb_name = $site_upload->upload_file($thumb_file, "thumb",0, basename($new_name));
    if (!$new_thumb_name) {
      $log[] = "<b>".$lang['thumb_upload_error'].": ".$HTTP_POST_FILES[$thumb_file]['name']."</b><br />".$site_upload->get_upload_errors();
      @unlink(THUMB_CAT_PATH."/".$new_name);
      $log[] = $lang['error_image_deleted'];
      $uploaderror = 1;
    }
    else {
      $log[] = "<b>".$lang['thumb_upload_success'].": ".$new_thumb_name."</b>";
    }
  }
  else {
    $new_thumb_name = $remote_thumb_file;
  }


Search for:
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)";


Change to:
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_icon)
            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, '$thumb_file_name')";



3.2. Modifications in file "includes/contants.php"

Search for:
Code: [Select]
define('MEDIA_DIR', 'data/media');
define('THUMB_DIR', 'data/thumbnails');
define('MEDIA_TEMP_DIR', 'data/tmp_media');
define('THUMB_TEMP_DIR', 'data/tmp_thumbnails');
define('DATABASE_DIR', 'data/database');
define('TEMPLATE_DIR', 'templates');


Add below:
Code: [Select]
define('THUMB_CAT', 'data/icons');

3.3. Modifications in file "/global.php"

Search for:
Code: [Select]
define('MEDIA_PATH', ROOT_PATH.MEDIA_DIR);
define('THUMB_PATH', ROOT_PATH.THUMB_DIR);
define('MEDIA_TEMP_PATH', ROOT_PATH.MEDIA_TEMP_DIR);
define('THUMB_TEMP_PATH', ROOT_PATH.THUMB_TEMP_DIR);
define('TEMPLATE_PATH', ROOT_PATH.TEMPLATE_DIR."/".$config['template_dir']);
define('ICON_PATH', ROOT_PATH.TEMPLATE_DIR."/".$config['template_dir']."/icons");


Add below:
Code: [Select]
define('THUMB_CAT_PATH', ROOT_PATH.THUMB_CAT);


4. Bugs

4.1. The file is not being sent for the folder
4.2. In the field "cat_icon" is being saved the local name of file. Example: "C:\WINDOWS\DESKTOP\TEST\test.jpg"



Please... Anybody help me!
Thanks for all :-)

(V)arcelo Camargo
marcelo@marcelocamargo.com.br
Itapetininga - São Paulo - Brasil

Offline OpenGL

  • Newbie
  • *
  • Posts: 15
    • View Profile
[MOD-HELP] Icons for each category with admin control
« Reply #4 on: March 20, 2003, 08:11:47 AM »
every one have any idea ?...
I think this is good idea.... please help him...

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: First attempt
« Reply #5 on: March 20, 2003, 08:31:57 AM »
Quote from: marcelocamargo
4. Bugs

4.1. The file is not being sent for the folder

The reason it does that, because u need special attributies/instructions in the <FORM> I dont know exactly what could be wrong (I didnt install this mod) but try:
in /admin/categories.php find:
Code: [Select]
 show_form_header("categories.php", "savecat");
Replace with:
Code: [Select]
 show_form_header("categories.php", "savecat", "", 1);
it might will solve 4.2 bug as well :wink:
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 fabio

  • Newbie
  • *
  • Posts: 36
    • View Profile
[MOD-HELP] Icons for each category with admin control
« Reply #6 on: April 04, 2003, 01:22:00 PM »
i`m trying to display an icon in my top level categories but with no luck


did anyone manage to get this to work ?
i get this error


Fatal error: Call to a member function on a non-object in c:\easyphp\www\site\modules\4images\admin\categories.php on line 409

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-HELP] Icons for each category with admin control
« Reply #7 on: April 04, 2003, 07:03:38 PM »
Quote from: fabio

Fatal error: Call to a member function on a non-object in c:\easyphp\www\site\modules\4images\admin\categories.php on line 409

and what do u have at line 409 ?
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 fabio

  • Newbie
  • *
  • Posts: 36
    • View Profile
[MOD-HELP] Icons for each category with admin control
« Reply #8 on: April 04, 2003, 07:42:01 PM »
if (!empty($HTTP_POST_FILES[$thumb_file]['tmp_name']) && $HTTP_POST_FILES[$thumb_file]['tmp_name'] != "none" && !$uploaderror) {
$new_thumb_name = $site_upload->upload_file($thumb_file, "thumb",0, basename($new_name));


the error occurs when i create a new category and define an icon for it

without the modifications in this thread it works ok

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-HELP] Icons for each category with admin control
« Reply #9 on: April 04, 2003, 08:53:30 PM »
try to add this:
Code: [Select]
include(ROOT_PATH.'includes/upload.php');
$site_upload = new Upload();

just before
Code: [Select]
$new_thumb_name = $site_upload->upload_file($thumb_file, "thumb",0, basename($new_name));
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 fabio

  • Newbie
  • *
  • Posts: 36
    • View Profile
[MOD-HELP] Icons for each category with admin control
« Reply #10 on: April 04, 2003, 10:25:25 PM »
thanks

this removed the error

but ......

the icon name isn`t appended to the db!
the field is 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
[MOD-HELP] Icons for each category with admin control
« Reply #11 on: April 04, 2003, 10:47:15 PM »
one more try ;)
in the step 3.1. in last changes find: $auth_postcomment, '$thumb_file_name')";
try to change to: $auth_postcomment, '$new_thumb_name')";
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 fabio

  • Newbie
  • *
  • Posts: 36
    • View Profile
[MOD-HELP] Icons for each category with admin control
« Reply #12 on: April 04, 2003, 11:08:47 PM »
ok ;-) file name appended !!

thanks a lot

i`ll fix some minor errors and i`ll post the alterations later!

Offline poffet

  • Newbie
  • *
  • Posts: 11
    • View Profile
[MOD-HELP] Icons for each category with admin control
« Reply #13 on: April 06, 2003, 04:58:19 PM »
Hi every body !

When this wonderfull MOD will be OK ?

It's exactly what I'm looking for !

Thanks for your job fabio !

Offline fabio

  • Newbie
  • *
  • Posts: 36
    • View Profile
[MOD-HELP] Icons for each category with admin control
« Reply #14 on: April 06, 2003, 08:43:46 PM »
it`s working ok .. just follow the instructions in this thread