Content last modified Tuesday 24 August 2021
hop to #bottom
Categories:
Author:
ezee
About It:
Rate it:
  • Helpful?
  • 1 Yes
  • 0 No
Flag it:

If you'd like to provide updated information and do not have access to directly edit, please contact the site admin; thanks!

Custom fields for files

I updated to RC3 and love the file support, but I was missing one thing: custom fields for additional informations like file author. So today I tried to implement it and it works good for me. I decided to share this hack with people who are new to php or who have no time to do it themselves.

This hack changes the table structure of txp_file and the following files:
include/txp_file.php
publish/taghandlers.php
lib/admin_config.php
lang/your_lang.txt (optional)

It is recommended to backup your database and these files.

The hack will only work with RC3 (because there’s no file support without it ;)).

Modifying the structure of txp_file
Open your phpmyadmin, select your textpattern databas and click on SQL. Now insert the following into the textarea:

ALTER TABLE `txp_file` ADD `custom_1` VARCHAR( 255 ) NOT NULL ,
ADD `custom_2` VARCHAR( 255 ) NOT NULL ,
ADD `custom_3` VARCHAR( 255 ) NOT NULL ,
ADD `custom_4` VARCHAR( 255 ) NOT NULL ,
ADD `custom_5` VARCHAR( 255 ) NOT NULL ,
ADD `custom_6` VARCHAR( 255 ) NOT NULL ,
ADD `custom_7` VARCHAR( 255 ) NOT NULL ,
ADD `custom_8` VARCHAR( 255 ) NOT NULL ,
ADD `custom_9` VARCHAR( 255 ) NOT NULL ,
ADD `custom_10` VARCHAR( 255 ) NOT NULL ;

Click on OK.

Modifying include/txp_file.php
Open include/txp_file.php.

Search for: $form = ''; (Line #200).
Add after:

// custom fields for files (hack by ezee)
if($customf_1_set) 
$customfields  = custField(  1, $customf_1_set,  $custom_1 ); 
if($customf_2_set) 
$customfields .= custField(  2, $customf_2_set,  $custom_2 ); 
if($customf_3_set) 
$customfields .= custField(  3, $customf_3_set,  $custom_3 ); 
if($customf_4_set) 
$customfields .= custField(  4, $customf_4_set,  $custom_4 ); 
if($customf_5_set) 
$customfields .= custField(  5, $customf_5_set,  $custom_5 ); 
if($customf_6_set) 
$customfields .= custField(  6, $customf_6_set,  $custom_6 ); 
if($customf_7_set) 
$customfields .= custField(  7, $customf_7_set,  $custom_7 ); 
if($customf_8_set) 
$customfields .= custField(  8, $customf_8_set,  $custom_8 ); 
if($customf_9_set) 
$customfields .= custField(  9, $customf_9_set,  $custom_9 ); 
if($customf_10_set) 
$customfields .= custField( 10, $customf_10_set, $custom_10 );

Search for:

graf(gTxt('description').br.text_area('description','100','400',$description)) .
(Line #231)
Add after: $customfields . // custom fields for files

Search for: hInput('description',$description). (line #254)
Add after: $customfields . // custom fields for files

Search for:

extract(doSlash(gpsa(array('id','filename','category','description',
(line #423)
Add after:
'custom_1', 'custom_2', 'custom_3', 'custom_4', 'custom_5', 'custom_6', 'custom_7', 'custom_8', 'custom_9', 'custom_10'

Should now look like this:
extract(doSlash(gpsa(array('id','filename','category','description', 'custom_1', 'custom_2', 'custom_3', 'custom_4', 'custom_5', 'custom_6', 'custom_7', 'custom_8', 'custom_9', 'custom_10'))));

Search for: description = '$description'" (line #459)
Replace with:

description = '$description',
custom_1    = '$custom_1',
custom_2    = '$custom_2',
custom_3    = '$custom_3',
custom_4    = '$custom_4',
custom_5    = '$custom_5',
custom_6    = '$custom_6',
custom_7    = '$custom_7',
custom_8    = '$custom_8',
custom_9    = '$custom_9',
custom_10   = '$custom_10'"

Search for:

?>
(end of file)
Add before:
// ——————————————————————————————-
	function custField($num,$field,$content) 
	{
		if(gTxt(‘customf_’.$num)) $field = gTxt(‘customf_’.$num);

return graf($field . br . fInput(‘text’, ‘custom_’.$num, $content,‘edit’)); }

Save and close file.

Modifying publish/taghandlers.php
Open publish/taghandlers.php.

Search for: $out = str_replace("<txp:file_download_description />", $finfo['description'], $out); (line #1318)
Add after:

// custom fields for files (hack by ezee)
$out = str_replace("<txp:file_download_custom1 />", $finfo['custom_1'], $out);
$out = str_replace("<txp:file_download_custom2 />", $finfo['custom_2'], $out);
$out = str_replace("<txp:file_download_custom3 />", $finfo['custom_3'], $out);
$out = str_replace("<txp:file_download_custom4 />", $finfo['custom_4'], $out);
$out = str_replace("<txp:file_download_custom5 />", $finfo['custom_5'], $out);
$out = str_replace("<txp:file_download_custom6 />", $finfo['custom_6'], $out);
$out = str_replace("<txp:file_download_custom7 />", $finfo['custom_7'], $out);
$out = str_replace("<txp:file_download_custom8 />", $finfo['custom_8'], $out);
$out = str_replace("<txp:file_download_custom9 />", $finfo['custom_9'], $out);
$out = str_replace("<txp:file_download_custom10 />", $finfo['custom_10'], $out);

Search for: 'modified' => 0 (line #1366)
Replace with:

'modified' => 0,
'custom_1' => '',
'custom_2' => '',
'custom_3' => '',
'custom_4' => '',
'custom_5' => '',
'custom_6' => '',
'custom_7' => '',
'custom_8' => '',
'custom_9' => '',
'custom_10' => ''

Search for: $result['downloads'] = $downloads; (line #1387)
Add after:

// custom fields for files (hack by ezee)
$result['custom_1'] = $custom_1;
$result['custom_2'] = $custom_2;
$result['custom_3'] = $custom_3;
$result['custom_4'] = $custom_4;
$result['custom_5'] = $custom_5;
$result['custom_6'] = $custom_6;
$result['custom_7'] = $custom_7;
$result['custom_8'] = $custom_8;
$result['custom_9'] = $custom_9;
$result['custom_10'] = $custom_10;

Save and close file.

Modifying lib/admin_config.php
Open lib/admin_config.php.

Search for: 'custom_10_set' => '', (line #129)
Add after:

// -------------------------------------------------------------
// use custom fields for files - must be in 'quotes', and 
// must contain no spaces (hack by ezee)
		
	'customf_1_set'                => 'Author'',
	'customf_2_set'                => 'AuthorEmail',
	'customf_3_set'                => '',
	'customf_4_set'                => '',
	'customf_5_set'                => '',
	'customf_6_set'                => '',
	'customf_7_set'                => '',
	'customf_8_set'                => '',
	'customf_9_set'                => '',
	'customf_10_set'               => '',

Here you can set your custom fields for files.

Save and close file.

Modiyfying lang/your_lang.txt (optional)
In order to display the fields (in textpattern admin) with a different title than set in admin_config.php, you can add the following line to your language file (de-de.txtfor example ;)):

customf_1 => Author of file
customf_2 => Author Email
customf_3 => unset
customf_4 => unset
customf_5 => unset
customf_6 => unset
customf_7 => unset
customf_8 => unset
customf_9 => unset
customf_10=> unset

The hack will first look for titles in the language file.

How to show the custom fields on my site
Just use <txp:file_download_custom1 /> (replace the 1 with the number of the custom field you want to display).

So that’s it. I hope I didn’t forget any of my changes. Looks quite complicated but it’s just search and add or replace ;).

Looking forward to every comment and feedback. :)

Article Request Count:
Initially released:
2005-04-04
Posted here:
05 Apr 2005

You know you want to visit the Archives.
Published with Textpattern