Tutorial.Custom profile fields
From phpBB Development Wiki
Contents |
Utilizing each Custom Profile Field
Posted by Sniper_E in
Utilizing each Custom Profile Field and STG topics (in Sep 28, 2007).
I have been working with the and trying to figure it out. (with no luck)
I've read a lot of topics on this at .com and in area51. I have not seen an answer to what I was looking for.
Here, I will show you how I was able to utilize and control the different custom profile fields we've added to our sites.
How to Control The different Custom Profile Fields
This is the section of the viewtopic_body.html which we are all having problems to get to work like we want it to.
<!-- IF postrow.S_PROFILE_FIELD1 -->
<!-- Use a construct like this to include admin defined profile fields. Replace FIELD1 with the name of your field. -->
<br /><b>{postrow.PROFILE_FIELD1_NAME}:</b> {postrow.PROFILE_FIELD1_VALUE}
<!-- ENDIF -->I have side stepped that section above and utilized/customized the <!-- BEGIN custom_fields --> to get what we wanted. Highway of Life and Handyman have 3 custom profile fields they use on our STG site.
[*]Favorite Team [*]Gender [*]Real Name
Watch how each custom profile field was sectioned off and called for individually in this code I have setup on our styles.
OPEN
styles/prosilver/template/viewtopic_body.html
FIND
<!-- BEGIN custom_fields -->
<dd><strong>{postrow.custom_fields.PROFILE_FIELD_NAME}:</strong> {postrow.custom_fields.PROFILE_FIELD_VALUE}</dd>
<!-- END custom_fields -->REPLACE WITH
<!-- BEGIN custom_fields -->
<!-- IF postrow.custom_fields.PROFILE_FIELD_NAME eq "Favorite Team" -->
<dd><strong>{postrow.custom_fields.PROFILE_FIELD_NAME}:</strong> {postrow.custom_fields.PROFILE_FIELD_VALUE}</dd>
<!-- ENDIF -->
<!-- IF postrow.custom_fields.PROFILE_FIELD_NAME eq "Gender" -->
<dd><strong>{postrow.custom_fields.PROFILE_FIELD_NAME}:</strong> {postrow.custom_fields.PROFILE_FIELD_VALUE}</dd>
<!-- ENDIF -->
<!-- END custom_fields -->OPEN
styles/subsilver2/template/viewtopic_body.html
FIND
<!-- BEGIN custom_fields -->
<br /><b>{postrow.custom_fields.PROFILE_FIELD_NAME}:</b> {postrow.custom_fields.PROFILE_FIELD_VALUE}
<!-- END custom_fields -->REPLACE WITH
<!-- BEGIN custom_fields -->
<!-- IF postrow.custom_fields.PROFILE_FIELD_NAME eq "Favorite Team" -->
<b>{postrow.custom_fields.PROFILE_FIELD_NAME}:</b> {postrow.custom_fields.PROFILE_FIELD_VALUE}<br />
<!-- ENDIF -->
<!-- IF postrow.custom_fields.PROFILE_FIELD_NAME eq "Gender" -->
<b>{postrow.custom_fields.PROFILE_FIELD_NAME}:</b> {postrow.custom_fields.PROFILE_FIELD_VALUE}<br />
<!-- ENDIF -->
<!-- END custom_fields -->
See how I'm calling for each specific custom profile field and placing each one where I want it in my page?
You can place each field you've added anywhere in your page that you want it.
Now for the 3rd custom profile field, "Real Name" I want this field further up the page under the username.
For prosilver
FIND
<dt>
<!-- IF postrow.POSTER_AVATAR -->
<!-- IF postrow.U_POST_AUTHOR --><a href="{postrow.U_POST_AUTHOR}">{postrow.POSTER_AVATAR}</a><!-- ELSE -->{postrow.POSTER_AVATAR}<!-- ENDIF --><br />
<!-- ENDIF -->
<!-- IF not postrow.U_POST_AUTHOR --><strong>{postrow.POST_AUTHOR_FULL}</strong><!-- ELSE -->{postrow.POST_AUTHOR_FULL}<!-- ENDIF -->
</dt>REPLACE WITH
<dt>
<!-- IF postrow.POSTER_AVATAR -->
<!-- IF postrow.U_POST_AUTHOR --><a href="{postrow.U_POST_AUTHOR}">{postrow.POSTER_AVATAR}</a><!-- ELSE -->{postrow.POSTER_AVATAR}<!-- ENDIF --><br />
<!-- ENDIF -->
<!-- IF not postrow.U_POST_AUTHOR --><strong>{postrow.POST_AUTHOR_FULL}</strong><!-- ELSE -->{postrow.POST_AUTHOR_FULL}<!-- ENDIF -->
<!-- BEGIN custom_fields -->
<!-- IF postrow.custom_fields.PROFILE_FIELD_NAME eq "Real Name" -->
<b class="postauthor"<!-- IF postrow.POST_AUTHOR_COLOUR --> style="color: {postrow.POST_AUTHOR_COLOUR}"<!-- ENDIF -->><i>{postrow.custom_fields.PROFILE_FIELD_VALUE}</i></b>
<!-- ENDIF -->
<!-- END custom_fields -->
</dt>For subsilver2
FIND
<!-- IF postrow.ONLINE_IMG -->
REPLACE WITH
<!-- BEGIN custom_fields -->
<!-- IF postrow.custom_fields.PROFILE_FIELD_NAME eq "Real Name" -->
<tr>
<td align="center" nowrap="nowrap"><b class="postauthor"<!-- IF postrow.POST_AUTHOR_COLOUR --> style="color: {postrow.POST_AUTHOR_COLOUR}"<!-- ENDIF -->><i>{postrow.custom_fields.PROFILE_FIELD_VALUE}</i></b></td>
</tr>
<!-- ENDIF -->
<!-- END custom_fields -->
<!-- IF postrow.ONLINE_IMG -->I also worked with a couple of guys here who used a "Clan Site" custom profile field for their users. But, they didn't want the url which a user entered in to show up in that profile field. They wanted an image (a button) to be there that would link them to the url address.
Watch how this works with an image.... which we couldn't do before.
FIND
<!-- BEGIN custom_fields -->
<br /><b>{postrow.custom_fields.PROFILE_FIELD_NAME}:</b> {postrow.custom_fields.PROFILE_FIELD_VALUE}
<!-- END custom_fields -->REPLACE WITH
<!-- BEGIN custom_fields -->
<!-- IF postrow.custom_fields.PROFILE_FIELD_NAME eq "Clan Site" -->
<b>{postrow.custom_fields.PROFILE_FIELD_NAME}:</b> <a href="{postrow.custom_fields.PROFILE_FIELD_VALUE}"><img src="{T_IMAGESET_PATH}/en/icon_contact_www.gif" alt="{postrow.custom_fields.PROFILE_FIELD_VALUE}" title="{postrow.custom_fields.PROFILE_FIELD_VALUE}"></a>
<!-- ENDIF -->
<!-- END custom_fields -->Then to make your image clickable....
OPEN
/phpBB3/includes/functions_profile_fields.php
FIND
$value = make_clickable($value);
REPLACE WITH
// $value = make_clickable($value);
Hope this helps out all those who have been battling this along with me.
How to Hide one of the Custom Profile Fields in
..
viewtopic_body.html
..
memberlist_view.html
..
UCP - User control panel
..
How to Show the Custom Profile Fields in Other Pages
memberlist_body.html
overall_header.html
In order to show custom profile fields in overall_header.html, we need to add php codes to a file. So, we can add to includes/function.php While adding mood icon of Simple Mood mod to overall_header by using custom profile fields, I copied custom profile field codes from memberlist.php and modified them to use as a second custom profile field2. If we don't rename the second cpf, due to added codes in functions.php cpf fields values appear twice in member profiles and topic pages. So, we rename as custom_fields2, thus they will be seen once upon our selection.
Here is how I utilized to custom profile field view in overall_header. The user will his custom profile field value at overall_header.html
OPEN
/phpBB3/includes/functions.php
FIND
// The following assigns all _common_ variables that may be used at any point in a template.
ADD BEFORE
$profile_fields = array();
if ($config['load_cpf_viewprofile'])//viewprofile custom profile view should be enabled, because it will controll this cpf
{
include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
$cp = new custom_profile();
$profile_fields = $cp->generate_profile_fields_template('grab', $user->data['user_id']);
$profile_fields = (isset($profile_fields[$user->data['user_id']])) ? $cp->generate_profile_fields_template('show', false, $profile_fields[$user->data['user_id']]) : array();
}
To control, enabel-disable this field, we should add a differen config value to database. In this method, $config['load_cpf_viewprofile'] member_profile_cpf switch control this added cpf entry.
FIND
'T_STYLESHEET_NAME' => $user->theme['theme_name'],
ADD AFTER
'S_CUSTOM_FIELDS2' => (isset($profile_fields['row']) && sizeof($profile_fields['row'])) ? true : false,
FIND
// application/xhtml+xml not used because of IE
ADD BEFORE
if (!empty($profile_fields['row']))
{
$template->assign_vars($profile_fields['row']);
}
if (!empty($profile_fields['blockrow']))
{
foreach ($profile_fields['blockrow'] as $field_data)
{
$template->assign_block_vars('custom_fields2', $field_data);
}
}
OPEN
/phpBB3/styles/prosilver/template/overall_header.html
FIND
<!-- IF U_PRINT_PM --><li class="rightside"><a href="{U_PRINT_PM}" title="{L_PRINT_PM}" accesskey="p" class="print">{L_PRINT_PM}</a></li><!-- ENDIF -->ADD AFTER
<!-- BEGIN custom_fields2 --><dt>{custom_fields2.PROFILE_FIELD_NAME}:</dt> <dd>{custom_fields2.PROFILE_FIELD_VALUE}</dd><!-- END custom_fields2 -->Instead of the above edit in overall_header.html, we can prefer showing only one custom profile seen in overall_header. So, we shall do the edits below instead.
Considering
Field name/title presented to the user: Mood
FIND
<!-- IF U_PRINT_PM --><li class="rightside"><a href="{U_PRINT_PM}" title="{L_PRINT_PM}" accesskey="p" class="print">{L_PRINT_PM}</a></li><!-- ENDIF -->ADD AFTER
<!-- BEGIN custom_fields2 -->
<!-- IF custom_fields2.PROFILE_FIELD_NAME eq "Mood" -->
<dt>{custom_fields2.PROFILE_FIELD_NAME}:</dt> <dd>{custom_fields2.PROFILE_FIELD_VALUE}</dd>
<!-- ENDIF -->
<!-- END custom_fields2 -->External pages
..
List of Mods improving Custom Profile fields features
.. Those mods may referred to find sample codes in install.xml.
See Also

