Author Topic: [Mod] Valid file extension for Upload, separate for every Category  (Read 11187 times)

0 Members and 1 Guest are viewing this topic.

Rembrandt

  • Guest
Hi!

Valid file extension for Upload, separate for every Category.

with this modification you can set the valid file extension for upload, seperate for every category.

1.) copy the file "install_mediatypes.php" from the attachment in your root and call it to.

2.) search in admin/categories.php section: ($action == "savecat")

$cat_order 
= (isset($HTTP_POST_VARS['cat_order'])) ? intval($HTTP_POST_VARS['cat_order']) : 0;

insert below:

//############# Allowed Mediatypes in Categories ###############
  
$cat_mediatypes un_htmlspecialchars(trim($HTTP_POST_VARS['cat_mediatypes']));
//############# Allowed Mediatypes in Categories ###############

search:

    $sql 
"INSERT INTO ".CATEGORIES_TABLE."
            (cat_name, cat_description, cat_parent_id, cat_order, cat_mediatypes, 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, '$cat_mediatypes', $auth_viewcat$auth_viewimage$auth_download$auth_upload$auth_directupload$auth_vote$auth_sendpostcard$auth_readcomment$auth_postcomment)";
    
$result $site_db->query($sql);

and replace:

    $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)";
    
$result $site_db->query($sql);


2.1) search in admin/categories.php section: ($action == "addcat")

$permission_headline 
$lang['permissions'];

insert above:

//############## Allowed Mediatypes in Categories ###############
  
show_input_row($lang['cat_mediatypes'], "cat_mediatypes"""$textinput_size);
//############## Allowed Mediatypes in Categories ###############

search:

    $sql 
"SELECT cat_name, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
            FROM "
.CATEGORIES_TABLE."
            WHERE cat_id = 
$cat_parent_id";
    
$row $site_db->query_firstrow($sql);

and replace:

    $sql 
"SELECT cat_name, cat_mediatypes, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
            FROM "
.CATEGORIES_TABLE."
            WHERE cat_id = 
$cat_parent_id";
    
$row $site_db->query_firstrow($sql);

search:

$permission_headline 
.= "<span class=\"smalltext\"><br>".$lang['permissions_inherited']." (".format_text($row['cat_name'], 2).")</span>";

insert below:

//############## Allowed Mediatypes in Categories ###############
  
show_input_row($lang['cat_mediatypes'], "cat_mediatypes"$row['cat_mediatypes'], $textinput_size);
//############## Allowed Mediatypes in Categories ###############


2.2) search in admin/categories.php section: ($action == "updatecat")

$cat_order 
= (isset($HTTP_POST_VARS['cat_order'])) ? intval($HTTP_POST_VARS['cat_order']) : 0;

insert below:

//############### Allowed Mediatypes in Categories ###############
  
$cat_mediatypes un_htmlspecialchars(trim($HTTP_POST_VARS['cat_mediatypes']));
//############### Allowed Mediatypes in Categories ###############

search:

    $sql 
"UPDATE ".CATEGORIES_TABLE."
            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
            WHERE cat_id = 
$cat_id";
    
$result $site_db->query($sql);

and replace:

    $sql 
"UPDATE ".CATEGORIES_TABLE."
            SET cat_name = '
$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_order = $cat_order, cat_mediatypes = '$cat_mediatypes', 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
            WHERE cat_id = 
$cat_id";
    
$result $site_db->query($sql);


2.3) search in admin/categories.php section: ($action == "editcat")

  $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
          FROM "
.CATEGORIES_TABLE."
          WHERE cat_id = 
$cat_id";
  
$cat_row $site_db->query_firstrow($sql);

and replace:

  $sql 
"SELECT cat_name, cat_description, cat_parent_id, cat_hits, cat_order, cat_mediatypes, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
          FROM "
.CATEGORIES_TABLE."
          WHERE cat_id = 
$cat_id";
  
$cat_row $site_db->query_firstrow($sql);

search:

show_input_row
($lang['field_hits'], "cat_hits"$cat_row['cat_hits'], 5);

insert below:

//################ Allowed Mediatypes in Categories ###############
  
show_input_row($lang['cat_mediatypes'], "cat_mediatypes"$cat_row['cat_mediatypes'], $textinput_size);
//################ Allowed Mediatypes in Categories ###############


3.) search in includes/upload.php:

  
function set_allowed_filetypes() {
    global 
$config;

and replace:

  
function set_allowed_filetypes() {
    global 
$config,$cat_cache,$cat_id;

search:

$this
->accepted_extensions['media'] = $config['allowed_mediatypes_array'];

and replace:

   $allowed_mediatypes 
= (!empty($cat_cache[$cat_id]['cat_mediatypes'])) ? explode(",",$cat_cache[$cat_id]['cat_mediatypes']) : $config['allowed_mediatypes_array'];
   
$this->accepted_extensions['media'] = $allowed_mediatypes;


4.) search in lang/your lang/admin.php:

//--- Categories --------------------------------------
//-----------------------------------------------------

(deutsch:)

//############# Allowed Mediatypes in Categories ###############
$lang['cat_mediatypes'] = "Erlaubte Dateitypen<br><span class=\"smalltext\">Durch ein Komma getrennt, ohne Leerzeichen.</span>";
//############# Allowed Mediatypes in Categories ###############

(english)

//############# Allowed Mediatypes in Categories ###############
$lang['cat_mediatypes'] = "Valid file extensions<br /><span class=\"smalltext\">Delimit with comma, not with spaces..</span>";
//############# Allowed Mediatypes in Categories ###############


5.) search in member.php:

"allowed_media_types" => str_replace(",",", ",$config['allowed_mediatypes']),

and replace:

"allowed_media_types" => (!empty($cat_cache[$cat_id]['cat_mediatypes'])) ? "<b class=\"new\">".str_replace(",",", ",$cat_cache[$cat_id]['cat_mediatypes'])."</b>" str_replace(",",", ",$config['allowed_mediatypes']),


6.) search in global.php:

  $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
          FROM "
.CATEGORIES_TABLE."
          ORDER BY "
.$config['cat_order']." " .$config['cat_sort'];
  
$result $site_db->query($sql);

and replace:

  $sql 
"SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order,cat_mediatypes, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
          FROM "
.CATEGORIES_TABLE."
          ORDER BY "
.$config['cat_order']." " .$config['cat_sort'];
  
$result $site_db->query($sql);



mfg Andi
« Last Edit: April 19, 2011, 02:23:00 PM by Rembrandt »

Offline Warrior

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
    • Lawrence Family History
Re: [Mod] Valid file extension for Upload, separate for every Category
« Reply #1 on: April 19, 2011, 07:30:22 AM »
It's not showing up in the Add Category, but does in the Edit Category.

I did notice this is:

From the Add Category section of your code
Code: [Select]
//############## Allowed Mediatypes in Categories ###############
  show_input_row($lang['cat_mediatypes'], "cat_mediatypes", $row['cat_mediatypes'], $textinput_size);
//############## Allowed Mediatypes in Categories ###############

is different than this:

From the Category of your code
Code: [Select]
//################ Allowed Mediatypes in Categories ###############
  show_input_row($lang['cat_mediatypes'], "cat_mediatypes", $cat_row['cat_mediatypes'], $textinput_size);
//################ Allowed Mediatypes in Categories ###############

I tried using the second code where the first one is, and it still didn't show up.

I also notice two of your code entries in your #2 (the second search/replace code in step 2) post are backwards :D

Rembrandt

  • Guest
Re: [Mod] Valid file extension for Upload, separate for every Category
« Reply #2 on: April 19, 2011, 07:47:30 AM »
oops, i forgot a row.
i have edit step 2.1)

Offline Warrior

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
    • Lawrence Family History
Re: [Mod] Valid file extension for Upload, separate for every Category
« Reply #3 on: April 19, 2011, 07:59:46 AM »
That fixed it! Thanks. Have set some permissions and will do some testing.

Looks great so far!

EDIT:

Ok... the permissions are NOT working.

It seems the main Settings are over-riding the Category settings. Yet if I remove the main settings, then NO images will show up at all.

I had a main cat set for youtube,avi,flv,mp4 I then set a sub-cat for mpg only.

I then tried to upload a jpg (ie, none of the "allowed" category formats) yet it still uploaded! I did this as both a regular member and visitor status.

I have checked my database, and the entries ARE there for the category file types.

I am wondering if there is yet another piece of code that needs edited, maybe in the upload.php or member.php file (other than the code posted)?
« Last Edit: April 19, 2011, 09:46:53 AM by Warrior »

Rembrandt

  • Guest
Re: [Mod] Valid file extension for Upload, separate for every Category
« Reply #4 on: April 19, 2011, 02:25:32 PM »
sorry, I forgot something again.  :oops:

update step 3.)

Offline Warrior

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
    • Lawrence Family History
Re: [Mod] Valid file extension for Upload, separate for every Category
« Reply #5 on: April 19, 2011, 06:01:07 PM »
That, sir, did the trick. Thank you very much!

One thing users will need to keep in mind- The main settings file types MUST BE KEPT and MATCH what you put in the category file types (only once overall though, ie I put mpg into the master list, and have two categories that can upload mpg. I do not need to add mpg twice to the master list).

The reason is so they will show up. If you remove the file type from the main settings, then it shows the file cannot be found, so leave the "master" list intact with what types you want to allow. Much easier this way than to try and re-code the entire 4images script  :lol:

This categories thing DOES make it so only certain types can be uploaded into certain categories though, which is EXCELLENT! You can leave a TOP category blank, and have the sub-cats upload certain types of files.

Example: I have a top category named "Videos". Since I do not want any files uploaded to the top category, I can leave the file types blank for that category. I then have two sub-cats (SciFi videos and Music videos) under that top category. I set each of them for different file types, and those two categories will upload only what I set it for.