Fixes to Profile Extra Fields Module v0.2 and Extended Profile Module v0.1

Register an Account
Pligg Chat Room
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-16-2008, 07:29 PM
redwine's Avatar
Pligg Donor
Pligg Version: 9.8
Pligg Template: custom templat
 
Join Date: Jul 2007
Location: Canada
Posts: 216
Two modules are provided with Pligg to facilitate extending the user profile fields. We owe a big thank you to Ashdigg and Andrew Egenes (gen3ric) to whom goes all the credit.
  1. Profile Extra Fields Module v0.2, packaged with the Pligg CMS (Created by: AshDigg) ** we miss him. Where is he? **. The functionality of this module is to take whatever extra fields defined in the second module and display them in the “Modify profile” template /templates/yourtemplate/profile_center.tpl.
  2. Extended Profile Module v0.1, that requires the above module to work (Created by: Andrew Egenes and outlined in this thread http://forums.pligg.com/pligg-modules/11360-extended-user-profile-v0-1-almost-done-need-help.html). The functionality of this module is supposed to display the extra fields in the “user profile” template template /templates/yourtemplate/user_center.tpl (the public viewable profile). I hope that Andrew’s module will find its way to the core of the new version.
Andrew created the module and got stuck on the part that displays the user’s info. He offered the module freely and asked for assistance to display the user’s info in this thread http://forums.pligg.com/pligg-modules/11360-extended-user-profile-v0-1-almost-done-need-help.html

While I have contributed to this thread by providing some guidelines on how to add extra fields, etc. I did it without going through the code of the module (my bad!); therefore my contribution is insignificant and null because I explained how to manually add extra fields, which defeats the purpose of Andrew’s module and it does not really help his intentions to provide easy means to lift the burden of manually adding new fields to the profile.

I am correcting my shortcomings by providing a complete fix and improvement to both modules.

I volunteered, yesterday, to help a fellow Pligger add new fields using the above mentioned two modules. While I was going through the code, I have noticed that Profile Extra Fields Module v0.2 does only provide for fields that are <input type="text">. Furthermore, I discovered what is missing from Andrew’s module to display the user’s info.

Let’s start with the latter, Andrew’s module.

1. A module system hook to fill the smarty variables in the /libs/user.php was missing. These variables are needed to pass the info to the appropriate templates. To fix this issue:

Open /libs/user.php and look for the “function fill_smarty(” and add the following code right below it:

Code:
 
function fill_smarty($main_smarty, $stats = 1){
// add this code
// module system hook
$vars = '';
check_actions('profile_show', $vars);
Save and close.

2. The /modules/profiles/templates/profile_extend.tpl used the incorrect method to fetch the variables that are passed by /modules/users_extra_fields/users_extra_fields_main.php. I completely changed the code in this template file and commented every chunk of code to understand how it is processing the variables.

The issue with the Profile Extra Fields Module v0.2 is that it does only provide for fields that are <input type="text">. To rectify this problem, I have created new template files to ensure that all type of fields are addressed and processed (I.e. textarea, radio buttons, select options, and input text).

The new created templates (in /modules/users_extra_fields/templates) are for:
  • Type Select Options
    • Countries, it include 245 entries (according to Wikipedia)
    • State/Province for the United States and Canada
    • Years, from 1900 t0 2008
    • Months by name, January to December
    • Months by number, 01 to 12
    • Day of the month, 01 to 31
    • Days of the week, Monday to Sunday
    • Gender, Male / Female
    • Cars, sedan, sports, convertible, etc.
    • Smoking, Non-smoking
    • Age, from 15 to 99
    • Marital status
  • Type textarea:
    • Bio
  • Type radio buttons
Sample subscription to emails. Of course, you will have to add the appropriate code to send emails to the subscribers. You can use some of my posts in http://forums.pligg.com/pligg-mods/12550-email-admin-story-submission.html and http://forums.pligg.com/core-development/4917-mail-there-new-comment-your-story.html to have an idea on how to start.

I also have created a file /modules/profiles/ready select options.txt which contains ready code for the above mentioned select options for you to use any where you need to put some or all of them in HTML pages.

**** See the tutorial in the next post. ****
Reply With Quote
  #2 (permalink)  
Old 09-16-2008, 08:09 PM
redwine's Avatar
Pligg Donor
Pligg Version: 9.8
Pligg Template: custom templat
 
Join Date: Jul 2007
Location: Canada
Posts: 216
Tutorial on how to use the two templates:

First, you have to download the new Profile Extra Fields Module v0.2 from this post and copy it to /modules/users_extra_fields folder, replacing all the existing files.

If you haven’t downloaded Andrew’s module Extended Profile Module v0.1, download the new modified one from this post and
  • Unzip them to the /modules folder.
  • Because you don’t want to have fields created in the users table that you will not use, open /modules/profiles/profiles_settings.php and check to see if you want all the fields. Delete the block of fields that you don’t need, or add new fields using the existing ones as samples. Make sure when you add new fields to put the personal info fields at the top to keep the fields grouped together when displayed in the profile.
  • Open /modules/profiles/profiles_install.php and delete the lines representing the fields that you deleted in step 2 or, add new lines for the fields that were added in step 2. This file is to create the fields in the users table in the database.
  • For every field you create that is other than input type text, you have to add an entry (using the already existing code) to the /modules/users_extra_fields/profile_center_fields.tpl and /modules/users_extra_fields/users_extra_fields_init.php (SEE example below)
  • Login to the admin panel and go to “Modules Management” and install it
  • Place {checkActionsTpl location=”tpl_show_extra_profile”} where you want the extended fields to display in /templates/yourtemplate/user_center.tpl. Normally, it should be placed within the <div id=”personal_info”> right before the closing </fieldset> as follows:
Code:
</table>
{checkActionsTpl location=”tpl_show_extra_profile”}
</fieldset>
All the fields that are other than input type text are commented and numbered in the corresponding files (tpl and php) for an easy maintenance.

Every block of code in the modules files is well commented to help understand what to do and what it does.

Example on deleting fields (we are only dealing here with fields that are not input type text):

Let’s say you don’t want to use the “Habits” field:
  • Open /modules/profiles/profiles_settings.php
  • Delete or comment the block of code labeled // field ** 4 **
  • Open /modules/profiles/profiles_install.php
  • Delete or comment the block of code labeled // field ** 4 **
  • Open /modules/users_extra_fields/profile_center_fields.tpl
  • Delete or comment the block of code labeled // field ** 4 **
  • Open /modules/users_extra_fields/users_extra_fields_init.php
  • Delete or comment the block of code labeled // field ** 4 **
If you want to add new fields (we are only dealing here with fields that are not input type text) let’s say a select option to select the day of the week:

The template is already created (in /modules/users_extra_fields/templates)
  • Open /modules/profiles/profiles_settings.php
  • Add this block of code where you want:
Code:
 
$users_extra_fields_field[]=array(
'name' => 'user_dayofweek',
'show_to_user' => true,
'show_to_user_text' => 'Day of week:',
'show_to_admin' => true,
'editby_user' => true,
'editby_admin' => true
);
  • Open /modules/profiles/profiles_install.php
  • Add :
Code:
$module_info['db_add_field'][]=array('users', 'user_dayofweek', 'VARCHAR',  16, '', 0, '');
 
Open /modules/users_extra_fields/profile_center_fields.tpl
5. Add this code anywhere after an existing code for select options (don’t worry you will see that it’s easy because it is well laid out and commented:

Code:
{elseif $users_extra_fields_field[fields].show_to_user_text eq 'Day of week:'}
{checkActionsTpl location="tpl_show_extra_profile_dayofweek"} 

6. Open /modules/users_extra_fields/users_extra_fields_init.php
  • Look for these lines:
// ***********************************************
// call the extended profile display templates
// we add a module_add_action_tpl for every tpl file we create
// ***********************************************
Add this code right after:
Code:
// to load the Day of the week template 
module_add_action_tpl('tpl_show_extra_profile_dayofweek', users_extra_fields_tpl_path . 'profile_extend_dayofweek.tpl');
If you want to add a new field that does not have a ready template like adding University/College dropdown menu, follow these steps:
  • Open your favorite text editor and create the select option code:
Code:
<td>
 <select  name="{$users_extra_fields_field[fields].name}" id="{$users_extra_fields_field[fields].name}">
  <option value='' {if $users_extra_fields_field[fields].value eq ""} selected="selected"{/if}>University/College</option>
  <option value='University of Ottawa' {if $users_extra_fields_field[fields].value eq "University of Ottawa"} selected="selected"{/if}>University of Ottawa</option>
  <option value='Carleton Unversity' {if $users_extra_fields_field[fields].value eq "Carleton Unversity"} selected="selected"{/if}>Carleton Unversity</option>
  <option value='Algonquin College' {if $users_extra_fields_field[fields].value eq "Algonquin College"} selected="selected"{/if}>Algonquin College</option>
  <option value='La Cité collégiale' {if $users_extra_fields_field[fields].value eq "La Cité collégiale"} selected="selected"{/if}>La Cité collégiale</option>
  <option value='Herzing College' {if $users_extra_fields_field[fields].value eq "Herzing College"} selected="selected"{/if}>Herzing College</option>
 </select>
</td>
Save it as /modules/users_extra_fields/templates/profile_extend_university.tpl
Follow steps 1 to 8 as outlined above.

NOTE that whenever you add a field as outlined in the steps above, you have to uninstall the module Extended Profile Module v0.1 from the admin panel and reinstall it again for the fields to be created in the users table.
Attached Files
File Type: zip users_extra_fields.zip (15.8 KB, 82 views)
File Type: zip profiles.zip (10.8 KB, 81 views)
Reply With Quote
  #3 (permalink)  
Old 10-18-2008, 07:33 AM
New Pligger
Pligg Version: 9.9.5
 
Join Date: Sep 2008
Posts: 4
Hello,

Your hook is quite useful and may benefits to other module developers. You may ask a pligg staffer to add it in the svn with a generic name, such as "smarty_filling".

This will ensure that your module users won't have it broken when updating pligg, too.
Reply With Quote
  #4 (permalink)  
Old 10-18-2008, 10:28 AM
chuckroast's Avatar
Pligg Developer/Coder/Designer
Pligg Version: SVN
Pligg Template: Galleria
 
Join Date: Jun 2006
Posts: 3,835
Thanks Redwine, great addition. This was added to the svn.


Download the full Pligg Module Pack





Reply With Quote
  #5 (permalink)  
Old 11-04-2009, 04:19 PM
raghhav's Avatar
Casual Pligger
Pligg Version: 1.0.3
Pligg Template: Wison - Combin
 
Join Date: Oct 2009
Location: Mumbai
Posts: 74
Hi RedWine,

Though am using 1.0.1 and having this in-built modules even after enabling the module still the extra fields are not working. could you suggest me some ways for the same.
Reply With Quote
  #6 (permalink)  
Old 12-28-2009, 03:24 AM
raghhav's Avatar
Casual Pligger
Pligg Version: 1.0.3
Pligg Template: Wison - Combin
 
Join Date: Oct 2009
Location: Mumbai
Posts: 74
have upgraded to 1.0.3b still profile extra fields are not working. As chuckroast said that it has been included in svn then why it is not working.

Should I follow redwine's tutorial to make it run, please developers, reply to this one,
Reply With Quote
  #7 (permalink)  
Old 12-28-2009, 10:36 AM
chuckroast's Avatar
Pligg Developer/Coder/Designer
Pligg Version: SVN
Pligg Template: Galleria
 
Join Date: Jun 2006
Posts: 3,835
How do you think they don't work?
Just activating it won't do anything.
Profile extra fields used by other modules.


Download the full Pligg Module Pack





Reply With Quote
  #8 (permalink)  
Old 12-28-2009, 04:54 PM
raghhav's Avatar
Casual Pligger
Pligg Version: 1.0.3
Pligg Template: Wison - Combin
 
Join Date: Oct 2009
Location: Mumbai
Posts: 74
which are the other modules which i need to enable,

Are you talking about redwine's attachment modules?
Reply With Quote
  #9 (permalink)  
Old 01-04-2010, 07:06 PM
New Pligger
Pligg Version: 1.0RC4
 
Join Date: Apr 2007
Posts: 16
Hi Guys, I wanted to use this for my module but found that asking the user to then upload files around other modules so that my module would work seemed messy and prone to error. So I made some changes that I would like you to include into this module. The changes allow other modules to actually specify a custom template_path and template to use for a custom field. It only requires modifying one file, but then allows other modules to define their own custom templates for custom profile fields.

at line 105 in profile_center_fields.tpl add the following code:

Code:
{*================================*}
{* Custom to see if a custom template has been added to the field and load the related template *}
{* Also checks to see if a custom template_path has been specified for the template *}
{*================================*}
{elseif $users_extra_fields_field[fields].template neq ''}
    {if $users_extra_fields_field[fields].template_path neq '' }
        {include file=$users_extra_fields_field[fields].template_path.'profile_extend_'.$users_extra_fields_field[fields].template.'.tpl'  users_extra_fields_field[fields]=$users_extra_fields_field[fields] field=$users_extra_fields_field[fields]}
    {else}
        {include file=$users_extra_fields_tpl_path.'profile_extend_'.$users_extra_fields_field[fields].template.'.tpl'  users_extra_fields_field[fields]=$users_extra_fields_field[fields] field=$users_extra_fields_field[fields]}
    {/if}
This allows me to call either templates in the module/users_extra_fields/templates folder or templates defined in my own custom folder. The reason why i pass both the field and users_extra_fields_field[fields] to the template is so that it doesnt break any of your existing templates should i wish to call them via this method.



Then I can leverage this code from my own module by doing the following:

1: I define my custom field in mymodule_install.php exactly the same as before, eg:
Code:
  $module_info['db_add_field'][]=array('users', ''my_foo_field', 'TINYINT',  1, "UNSIGNED", 0, '1');
2: Then in my own mymodule_settings.php file I add the following code just as before, however notice the two new fields template and template_path
Code:
define("mymodule_user_fields_templates_path",  "../modules/mymodule/user_fields_templates/");

$users_extra_fields_field[]=array(
	'name' => 'my_foo_field',
	'show_to_user_text' => 'Do you want to enable foo?',
	'show_to_user' => true,
	'show_to_admin' => false,
	'editby_user' => true,
	'editby_admin' => true,
	'template' => 'yes_no',
	'template_path' => mymodule_user_fields_templates_path,
	);
3: The last part to this is of course to add my own custom template for a field to display on the user profile page. So in the modules/mymodule/user_fields_templates/ directory I define my own field template: profile_extended_yes_no.tpl
Code:
{*================================*}
{* Custom user field that shows a 1 as Yes and either a 0 or anything else as No *}
{*================================*}
<td>
	<select  name="{$field.name}" id="{$field.name}">
		{if $field.value eq "1"}
            <option value='1' selected="selected">Yes</option>
            <option value='0'>No</option>        
        {else}
            <option value='1'>Yes</option>
            <option value='0' selected="selected">No</option>            
        {/if}
	</select>
</td>

What do you think? cool??? It definitely seems better to allow other modules to create custom fields without the user having to copy and modify files in other modules. I have attached a copy of the profile_center_fields.tpl file.

cheers.
Attached Files
File Type: tpl profile_center_fields.tpl (5.8 KB, 30 views)
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extended User Profile v0.1 - Almost Done, Need Help gen3ric Questions and Comments 32 11-04-2009 03:48 PM
How to link Extra fields in Profile to pull information from user table in database pliggnewbie Questions and Comments 0 04-12-2007 01:59 AM


Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Make a donation to support Pligg CMS development