Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-04-03 13:06:57

ezee
New Member
From: Germany
Registered: 2005-04-03
Posts: 7
Website

Hack: custom fields for files

UPDATED now working correctly :)

Hello there. 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 NOT NULL ,
ADD `custom_2` VARCHAR NOT NULL ,
ADD `custom_3` VARCHAR NOT NULL ,
ADD `custom_4` VARCHAR NOT NULL ,
ADD `custom_5` VARCHAR NOT NULL ,
ADD `custom_6` VARCHAR NOT NULL ,
ADD `custom_7` VARCHAR NOT NULL ,
ADD `custom_8` VARCHAR NOT NULL ,
ADD `custom_9` VARCHAR NOT NULL ,
ADD `custom_10` VARCHAR 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. :)

Last edited by ezee (2005-04-04 14:32:02)

Offline

#2 2005-04-03 13:13:49

ezee
New Member
From: Germany
Registered: 2005-04-03
Posts: 7
Website

Re: Hack: custom fields for files

Can now edit my posts again. See above for updated source. :)

Last edited by ezee (2005-04-04 14:32:56)

Offline

#3 2005-04-03 13:16:41

ezee
New Member
From: Germany
Registered: 2005-04-03
Posts: 7
Website

Re: Hack: custom fields for files

Can now edit my posts again. See above for updated source. :)

Sorry for that mess…

Last edited by ezee (2005-04-04 14:33:11)

Offline

#4 2005-04-03 14:33:55

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: Hack: custom fields for files

With big interest I am reading what you document,I have not attempet yet to test this hack but it sounds to open up possibilities.
What I’d like to know is ,on which revision number did you do this.
I just tested the 255 yesterday,and it still gives me some error message when I have clean URL enabled.(problem with existence of .htaccess if there is any)
Does it work with clean URL mode?

regards,marios


⌃ ⇧ < ⌃ ⇧ >

Offline

#5 2005-04-03 14:56:51

ezee
New Member
From: Germany
Registered: 2005-04-03
Posts: 7
Website

Re: Hack: custom fields for files

I’m not quite sure which revision number I have :D. Downloaded RC3 um… on tuesday I think.

The URL mode doesn’t affect the hack. :)

Offline

#6 2005-04-09 01:53:04

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: Hack: custom fields for files

I still didn’t have time to test this,but soon,soon I’ll give it a try


⌃ ⇧ < ⌃ ⇧ >

Offline

#7 2005-04-09 05:48:11

Manfre
Plugin Author
From: North Carolina
Registered: 2004-05-22
Posts: 588
Website

Re: Hack: custom fields for files

ezee, I recommend that you get a fresh copy of the latest textpattern from SVN, apply your changes, and then create a patch for people to download. It’s safe to assume that everyone using rc3 is capable of applying the patch, since they needed to use SVN to get rc3.

Offline

#8 2005-12-11 19:33:02

semanio
Member
Registered: 2005-10-18
Posts: 20

Re: Hack: custom fields for files

would it be possible to make this a plugin now or is this too complicated to go with that structure?

Offline

#9 2006-06-28 09:54:21

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: Hack: custom fields for files

ezee wrote:

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);

another day, another dusty thread… :)

I realise this mod may be a bit out of date now but I’m all backed up and trying it anyway… it just might save my day.
I’m using Textpattern version: 4.0.3 (r1188) – the RC versioning confuses me so I’m not sure if this is a problem (how do you know which RC you’re using?)

I made it through the database changes and the changes to txp_file.php seemed ok, but when I get to this bit I’m stuck cos taghandlers.php has clearly changed plenty since this mod was written. There’s nothing like <code>$out = str_replace(“<txp:file_download_description />”, $finfo[‘description’], $out);</code> in there. I can see the functions for files at the bottom, but can’t work out how to implement this change.

Can anyone suggest how to do it? Or should I forget I ever started?

Offline

#10 2006-06-28 10:53:43

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: Hack: custom fields for files

…the RC versioning confuses me so I’m not sure if this is a problem (how do you know which RC you’re using?)

You’re not using one. RC is short for “Release Candidate”, which means that whatever software is trying to iron out the final bugs before calling it the stable version. The last RC candidate was buried months ago, replaced with 4.0 stable.

The change with the line you can’t find, won’t be do-able without more modifications now. The lib/admin_config.php changes likely won’t work, privileges are handled by the database now. The lang/your_lang.txt changes, you’d need to make those, then upload the file inside the manage languages page, in the prefs tab.

Last edited by Mary (2006-06-28 10:54:03)

Offline

#11 2006-06-28 10:57:49

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: Hack: custom fields for files

I guess I should abandon this one then – I’m out of my depth!
too bad… do you know of any other ways to achieve the same thing?

Offline

#12 2006-06-28 11:14:32

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: Hack: custom fields for files

It’s possible to do, but not documented by anyone, as far as I know.

Offline

Board footer

Powered by FluxBB