I got tired of having to add more user fields by copying and pasting code each time I wanted to add another custom field. So, I created this mod that allows you to add more Custom Fields through the Config page. An extra field is added to the config page that allows you to select how many fields you want. You can have any number greater than 4, though you might have some problems if you try to add an unreasonable number.
Currently this works for 1.4 only, but with a little work it could easlily be adapted for previous versions.
So let's start from the beginning:
First step:
Add the user_field_num row to the config table in mySQL.
(Note: change <tablePrefix> to the prefix you use for your tables.)
INSERT INTO `<tablePrefix>_config` ( `name` , `value` ) VALUES ('user_field_num', '4');
Now for the code additions:
lang/english.php
I coded for english.php but you can easlily adapt this for any language by changing the values.
Find:
'Custom fields for image description (leave blank if unused)',
array('Field 1 name', 'user_field1_name', 0, 'f=index.htm&as=admin_custom_image&ae=admin_custom_image_end'), //cpg1.4
array('Field 2 name', 'user_field2_name', 0),
array('Field 3 name', 'user_field3_name', 0),
array('Field 4 name', 'user_field4_name', 0),
'Cookies settings',
array('Cookie name', 'cookie_name', 0, 'f=index.htm&as=admin_cookie_name&ae=admin_cookie_name_end'), //cpg1.4
array('Cookie path', 'cookie_path', 0, 'f=index.htm&as=admin_cookie_path&ae=admin_cookie_path_end'), //cpg1.4
'Email settings (usually nothing has to be changed here; leave all fields blank when not sure)', //cpg1.4
array('SMTP Host (when left blank, sendmail will be used)', 'smtp_host', 0, 'f=index.htm&as=admin_email&ae=admin_email_end'), //cpg1.4
array('SMTP Username', 'smtp_username', 0), //cpg1.4
array('SMTP Password', 'smtp_password', 0), //cpg1.4
'Logging and statistics', //cpg1.4
array('Logging mode <a href="#notice3" class="clickable_option">***</a>', 'log_mode', 11, 'f=index.htm&as=admin_logging_log_mode&ae=admin_logging_log_mode_end'), //cpg1.4
array('Log ecards', 'log_ecards', 1, 'f=index.htm&as=admin_general_log_ecards&ae=admin_general_log_ecards_end'), //cpg1.4
array('Keep detailed vote statistics','vote_details',1, 'f=index.htm&as=admin_logging_votedetails&ae=admin_logging_votedetails_end'), //cpg1.4
array('Keep detailed hit statistics','hit_details',1, 'f=index.htm&as=admin_logging_hitdetails&ae=admin_logging_hitdetails_end'), //cpg1.4
'Maintenance settings', //cpg1.4
array('Enable debug mode', 'debug_mode', 9, 'f=index.htm&as=debug_mode&ae=debug_mode_end'), //cpg1.4
array('Display notices in debug mode', 'debug_notice', 1, 'f=index.htm&as=admin_misc_debug_notices&ae=admin_misc_debug_notices_end'), //cpg1.4
array('Gallery is offline', 'offline', 1, 'f=index.htm&as=admin_general_offline&ae=admin_general_offline_end'), //cpg1.4
);
Replace With:
'Number of custom Fields to display',
array('Number of user fields', 'user_field_num', 0, 'f=index.htm&as=admin_custom_image&ae=admin_custom_image_end'),
'Custom fields for image description (leave blank if unused)',
array('Field 1 name', 'user_field1_name', 0, 'f=index.htm&as=admin_custom_image&ae=admin_custom_image_end'), //cpg1.4
array('Field 2 name', 'user_field2_name', 0),
array('Field 3 name', 'user_field3_name', 0),
array('Field 4 name', 'user_field4_name', 0),
);
//let's start the count at 5 since 4 fields have already been declared
for($i = 5; $i <= $CONFIG['user_field_num']; $i++)
{
$lang_admin_data[] = array("Field " . $i . " name", "user_field" . $i . "_name", 0);
}
$lang_admin_data[] = 'Cookies settings';
$lang_admin_data[] = array('Cookie name', 'cookie_name', 0, 'f=index.htm&as=admin_cookie_name&ae=admin_cookie_name_end'); //cpg1.4
$lang_admin_data[] = array('Cookie path', 'cookie_path', 0, 'f=index.htm&as=admin_cookie_path&ae=admin_cookie_path_end'); //cpg1.4
$lang_admin_data[] = 'Email settings (usually nothing has to be changed here; leave all fields blank when not sure)'; //cpg1.4
$lang_admin_data[] = array('SMTP Host (when left blank, sendmail will be used)', 'smtp_host', 0, 'f=index.htm&as=admin_email&ae=admin_email_end'); //cpg1.4
$lang_admin_data[] = array('SMTP Username', 'smtp_username', 0); //cpg1.4
$lang_admin_data[] = array('SMTP Password', 'smtp_password', 0); //cpg1.4
$lang_admin_data[] = 'Logging and statistics'; //cpg1.4
$lang_admin_data[] = array('Logging mode <a href="#notice3" class="clickable_option">***</a>', 'log_mode', 11, 'f=index.htm&as=admin_logging_log_mode&ae=admin_logging_log_mode_end'); //cpg1.4
$lang_admin_data[] = array('Log ecards', 'log_ecards', 1, 'f=index.htm&as=admin_general_log_ecards&ae=admin_general_log_ecards_end'); //cpg1.4
$lang_admin_data[] = array('Keep detailed vote statistics','vote_details',1, 'f=index.htm&as=admin_logging_votedetails&ae=admin_logging_votedetails_end'); //cpg1.4
$lang_admin_data[] = array('Keep detailed hit statistics','hit_details',1, 'f=index.htm&as=admin_logging_hitdetails&ae=admin_logging_hitdetails_end'); //cpg1.4
$lang_admin_data[] = 'Maintenance settings'; //cpg1.4
$lang_admin_data[] = array('Enable debug mode', 'debug_mode', 9, 'f=index.htm&as=debug_mode&ae=debug_mode_end'); //cpg1.4
$lang_admin_data[] = array('Display notices in debug mode', 'debug_notice', 1, 'f=index.htm&as=admin_misc_debug_notices&ae=admin_misc_debug_notices_end'); //cpg1.4
$lang_admin_data[] = array('Gallery is offline', 'offline', 1, 'f=index.htm&as=admin_general_offline&ae=admin_general_offline_end'); //cpg1.4
admin.php
Find:
if ($CONFIG[$element[1]] !== stripslashes($value))
Replace with:
//create field if it does not exist
if (!isset($CONFIG[$element[1]]))
{
cpg_db_query("INSERT INTO {$CONFIG['TABLE_CONFIG']} ( `name` , `value` ) VALUES ('{$element[1]}', '$value')");
$processAnyways = true;
}
if ($CONFIG[$element[1]] !== stripslashes($value) || isset($processAnyways))
include/search.inc.php
Find:
$allowed = array('title', 'caption', 'keywords', 'owner_name', 'filename', 'pic_raw_ip', 'pic_hrd_ip', 'user1', 'user2', 'user3', 'user4');
Replace with:
$allowed = array('title', 'caption', 'keywords', 'owner_name', 'filename', 'pic_raw_ip', 'pic_hrd_ip');
//add user fields to allowed array
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uI = "user" . $i;
$allowed[] = $uI;
}
xp_publish.php
I have not tested this code since I do not use this
Find:
$keywords = '';
Replace all the user vars with:
$userFields = array();
Find:
$result = add_picture($album, $filepath, $picture_name, $position, $title, $caption, $keywords, $user1, $user2, $user3, $user4, $category);
Replace with:
$result = add_picture($album, $filepath, $picture_name, $position, $title, $caption, $keywords, $userFields, $category);
upload.php
Find
// We have incoming placement data. Let's capture it.
$album = (int)$_POST['album'];
$title = addslashes($_POST['title']);
$caption = addslashes($_POST['caption']);
$keywords = addslashes($_POST['keywords']);
Replace all the user vars with:
//add user fields to userFields array
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uI = "user" . $i;
$userFields[] = addslashes($HTTP_POST_VARS[$uI]);
}
Find:
$result = add_picture($album, $filepath, $picture_name, 0,$title, $caption, $keywords, $user1, $user2, $user3, $user4, $category, $raw_ip, $hdr_ip, $movie_wd, $movie_ht);
Replace With:
$result = add_picture($album, $filepath, $picture_name, 0,$title, $caption, $keywords, $userFields, $category, $raw_ip, $hdr_ip, $movie_wd, $movie_ht);
Find:
array($CONFIG['user_field1_name'], 'user1', 0, 255, 1),
array($CONFIG['user_field2_name'], 'user2', 0, 255, 1),
array($CONFIG['user_field3_name'], 'user3', 0, 255, 1),
array($CONFIG['user_field4_name'], 'user4', 0, 255, 1),
);
Replace With:
);
// Check for user defined fields.
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uFN = "user_field". $i . "_name";
$uI = "user" . $i;
if(!empty($CONFIG[$uFN]))
{
$form_array[] = array($CONFIG[$uFN], $uI, 0, 255, 1);
}
}
image_processor.php
Find:
global $user1;
global $user2;
global $user3;
global $user4;
Replace with:
global $userFields;
Find:
print "<input type=\"hidden\" name=\"user1\" value=\"$user1\">";
print "<input type=\"hidden\" name=\"user2\" value=\"$user2\">";
print "<input type=\"hidden\" name=\"user3\" value=\"$user3\">";
print "<input type=\"hidden\" name=\"user4\" value=\"$user4\">";
Replace with:
//print user fields
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$userData = $userFields[$i-1];
print "<input type=\"hidden\" name=\"user$i\" value=\"$userData\">";
}
Find:
$user1 = $HTTP_POST_VARS['$user1'];
$user2 = $HTTP_POST_VARS['$user2'];
$user3 = $HTTP_POST_VARS['$user3'];
$user4 = $HTTP_POST_VARS['$user4'];
Replace With:
//set user fields
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uI = "user" . $i;
$userFields[] = $HTTP_POST_VARS['$uI'];
}
Find:
$user1 = $_POST['$user1'];
$user2 = $_POST['$user2'];
$user3 = $_POST['$user3'];
$user4 = $_POST['$user4'];
Replace With:
//set user fields
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uI = "user" . $i;
$userFields[] = $_POST['$uI'];
}
Find:
print "<input type=\"hidden\" name=\"user1\" value=\"$user1\">";
print "<input type=\"hidden\" name=\"user2\" value=\"$user2\">";
print "<input type=\"hidden\" name=\"user3\" value=\"$user3\">";
print "<input type=\"hidden\" name=\"user4\" value=\"$user4\">";
Replace with:
//print user fields
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$userData = $userFields[$i-1];
print "<input type=\"hidden\" name=\"user$i\" value=\"$userData\">";
}
editpics.php
Find:
$THUMB_ROWSPAN=5;
if ($CONFIG['user_field1_name'] != '') $THUMB_ROWSPAN++;
if ($CONFIG['user_field2_name'] != '') $THUMB_ROWSPAN++;
if ($CONFIG['user_field3_name'] != '') $THUMB_ROWSPAN++;
if ($CONFIG['user_field4_name'] != '') $THUMB_ROWSPAN++;
Replace With:
$THUMB_ROWSPAN=5;
//get rowspan value
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uFN = "user_field" . $i . "_name";
if ($CONFIG[$uFN] != '') $THUMB_ROWSPAN++;
}
Find:
$data = array(
array($lang_editpics_php['pic_info'], '', 3),
array($lang_editpics_php['album'], 'aid', 1),
array($lang_editpics_php['title'], 'title', 0, 255),
array($captionLabel, 'caption', 2, $CONFIG['max_img_desc_length']),
array($lang_editpics_php['keywords'], 'keywords', 0, 255),
array($CONFIG['user_field1_name'], 'user1', 0, 255),
array($CONFIG['user_field2_name'], 'user2', 0, 255),
array($CONFIG['user_field3_name'], 'user3', 0, 255),
array($CONFIG['user_field4_name'], 'user4', 0, 255),
array('', '', 4)
);
Replace With:
$data = array(
array($lang_editpics_php['pic_info'], '', 3),
array($lang_editpics_php['album'], 'aid', 1),
array($lang_editpics_php['title'], 'title', 0, 255),
array($captionLabel, 'caption', 2, $CONFIG['max_img_desc_length']),
array($lang_editpics_php['keywords'], 'keywords', 0, 255),
);
//add user fields to data
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uFN = "user_field" . $i . "_name";
$uI = "user" . $i;
$data[] = array($CONFIG[$uFN], $uI, 0, 255);
}
$data[] = array('', '', 4);
Find:
$user1 = get_post_var('user1', $pid);
$user2 = get_post_var('user2', $pid);
$user3 = get_post_var('user3', $pid);
$user4 = get_post_var('user4', $pid);
Replace With:
//set userFields
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$userFields[] = get_post_var("user$i", $pid);
}
Find:
$update .= ", user1 = '".addslashes($user1)."'";
$update .= ", user2 = '".addslashes($user2)."'";
$update .= ", user3 = '".addslashes($user3)."'";
$update .= ", user4 = '".addslashes($user4)."'";
Replace With:
//add user fields to update
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$update .= ", user$i = '".addslashes($userFields[$i-1])."'";
}
editOnePic.php
Find:
$user1 = $_POST['user1'];
$user2 = $_POST['user2'];
$user3 = $_POST['user3'];
$user4 = $_POST['user4'];
Replace With:
//add user fields to array
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$userFields[]=$_POST["user$i"];
}
Find:
$THUMB_ROWSPAN=6;
if ($CONFIG['user_field1_name'] != '') $THUMB_ROWSPAN++;
if ($CONFIG['user_field2_name'] != '') $THUMB_ROWSPAN++;
if ($CONFIG['user_field3_name'] != '') $THUMB_ROWSPAN++;
if ($CONFIG['user_field4_name'] != '') $THUMB_ROWSPAN++;
Replace With:
$THUMB_ROWSPAN=6;
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
if ($CONFIG["user_field$1_name"] != '') $THUMB_ROWSPAN++;
}
Find:
$update .= ", user1 = '".addslashes($user1)."'";
$update .= ", user2 = '".addslashes($user2)."'";
$update .= ", user3 = '".addslashes($user3)."'";
$update .= ", user4 = '".addslashes($user4)."'";
Replace With:
//add user fields to update
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$update .= ", user$i = '".addslashes($userFields[$i-1])."'";
}
Find:
if ($CONFIG['user_field1_name'] != ''){
echo <<<EOT
<tr>
<td class="tableb" style="white-space: nowrap;">
{$CONFIG['user_field1_name']}
</td>
<td width="100%" class="tableb" valign="top">
<input type="text" style="width: 100%" name="user1" maxlength="255" value="{$CURRENT_PIC['user1']}" class="textinput" />
</td>
</tr>
EOT;
}
if ($CONFIG['user_field2_name'] != ''){
echo <<<EOT
<tr>
<td class="tableb" style="white-space: nowrap;">
{$CONFIG['user_field2_name']}
</td>
<td width="100%" class="tableb" valign="top">
<input type="text" style="width: 100%" name="user2" maxlength="255" value="{$CURRENT_PIC['user2']}" class="textinput" />
</td>
</tr>
EOT;
}if ($CONFIG['user_field3_name'] != ''){
echo <<<EOT
<tr>
<td class="tableb" style="white-space: nowrap;">
{$CONFIG['user_field3_name']}
</td>
<td width="100%" class="tableb" valign="top">
<input type="text" style="width: 100%" name="user3" maxlength="255" value="{$CURRENT_PIC['user3']}" class="textinput" />
</td>
</tr>
EOT;
}if ($CONFIG['user_field4_name'] != ''){
echo <<<EOT
<tr>
<td class="tableb" style="white-space: nowrap;">
{$CONFIG['user_field4_name']}
</td>
<td width="100%" class="tableb" valign="top">
<input type="text" style="width: 100%" name="user4" maxlength="255" value="{$CURRENT_PIC['user4']}" class="textinput" />
</td>
</tr>
EOT;
}
Replace With:
//print out form fields
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uFN = "user_field" . $i . "_name";
$uI = "user" . $i;
if ($CONFIG[$uFN] != ''){
echo <<<EOT
<tr>
<td class="tableb" style="white-space: nowrap;">
{$CONFIG[$uFN]}
</td>
<td width="100%" class="tableb" valign="top">
<input type="text" style="width: 97%" name="$uI" maxlength="255" value="{$CURRENT_PIC[$uI]}" class="textinput" />
</td>
</tr>
EOT;
}
}