Firefox PHP

Country On Registration Module?

Posted by CyberOne 
Country On Registration Module?
December 25, 2007 10:38PM
Hello, I am new to the phorum system and have just recently started to play around with it while making some different templates and familiarizing myself with the system thought the use of modules. I have come across a couple of phroum systems with a module or hack to allow users to choose a country upon registration and later place a flag of their chosen country in their profile and beside their username in posts. I am not sure if maybe i missed this module while i was looking or if it is a customized mod for those forums.

Would appreciate any information about this and if its a custom mod any ideas or support in the development of it would be greatly appreciated.

thank you.
Re: Country On Registration Module?
December 26, 2007 06:50AM
It is not a published mod as far as I can remember. This is probably done by adding a custom profile field in the admin for the country and by adding code to the register, control center and user profile templates to set and display the country.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Country On Registration Module?
December 26, 2007 05:01PM
Hello, I have worked on the country hack and thanks to the information you provided I was able to get a jump start on it.
I am still new to the template system and structure of phroum and for this reason I was not able to create a module for it but have tried to explain everything that I did as clearly as possible for other people to follow along and maybe if they would like to lend a hand in its development in cleaning it up and making sure it can be released as a mod/hack it would be great. Currently it successfully displays a flag of the country selected in the user profile. Once I have gotten a grasp at the template system I will try and added it to the read.php in order for the flag to appear in posts as well.

Hopefully this is a good start for this hack and if anyone wishes to contribute feel free to modify it or clean it up in order to improve it. Below is the installation file I have begun to create for it and I will try to attach the flag images if everything looks good. I have also posted this thread as the support link for the hack so if anybody has any problems with it post here and remember this is just a beta version so make sure to back up all your files.

# 
#-----[ NAVIGATE TO YOUR ADMINISTRATIVE PANEL ]--------------------------------------------- 
# 

Go to User/Groups -> Custom profiles -> and create a custom profile field named 'country'

#
#-----[ OPEN ]---------------------------------------------
#
./templates/yourtemplate/cc_usersettings.tpl
Note: If you use more then one template in your forums make sure to redo this step on all of them.
#
#-----[ FIND ]-------------------------------------
#
      {IF PROFILE->USERPROFILE}
        <tr>
          <td nowrap="nowrap">{LANG->RealName}:&nbsp;</td>
          <td><input type="text" name="real_name" size="30" value="{PROFILE->real_name}" /></td>
        </tr>
#
#-----[ AFTER ADD ]-------------------------------------
#
		<tr>
          <td nowrap="nowrap">{LANG->Country}:&nbsp;</td>
          <td>
		<?php 

		function country_select($default, $select_name = "country")
		{
		$phorumpath = './';
		$country=array();
		$countrydir = opendir($phorumpath . 'images/flags/');
		    while ($file = readdir($countrydir)) { 
				if ($file != "." && $file != "..") {
					$filename = $file;
					$displayname = trim(str_replace(".gif", "", $filename));
					$country[$displayname] = $displayname;
		        }
		    }
		   closedir($countrydir);
		   	
		   	@asort($country);
			@reset($country);

			$country_select = '<select name="' . $select_name . '">';
			while ( list($displayname, $filename) = @each($country) )
			{
				$selected = ( strtolower($default) == strtolower($filename) ) ? ' selected="selected"' : '';
				$country_select .= '<option value="' . $displayname . '"' . $selected . '>' . ucwords($displayname) . '</option>';
			}
			$country_select .= '</select>';

			return $country_select;
		}

		echo country_select();
		?>
		 </td>
        </tr>
NOTE: should be before the closing {/IF} of the {IF PROFILE->USERPROFILE}.
#
#-----[ OPEN ]-------------------------------------
#
./templates/yourtemplate/cc_start.tpl
#
#-----[ FIND ]-------------------------------------
#
    <tr>
      <td>{LANG->Username}:</td>
      <td>{PROFILE->username}</td>
    </tr>
    <tr>
      <td>{LANG->RealName}:</td>
      <td>{PROFILE->real_name}</td>
    </tr>

#
#-----[ AFTER ADD ]-------------------------------------
#
 <tr>
      <td>{LANG->COUNTRY}:</td>
      <td>{PROFILE->country}&nbsp; <img src="./images/flags/{PROFILE->country}.gif" border="0"></td>
 </tr>
#
#-----[ OPEN ]-------------------------------------
#
 include/lang/english.php 
 
#
#-----[ FIND ]-------------------------------------
#
"ConfirmReportMessage"  =>      "Are you sure you want to report this post?",

#
#-----[ AFTER ADD]-------------------------------------
#
	"COUNTRY"               =>      "Country",
	"Country"               =>      "Please select your country",
		
#
#-----[ END OF MOD SAVE AND CLOSE ALL FILES ]-------------------------------------
#
If any errors occured please either undo the installation or delete and replace your original files. 


Re: Country On Registration Module?
December 26, 2007 06:30PM
Just a couple of notes on the mod from above:
The
$phorumpath = './';
has to be replaced with your actual directory phorum path or you will receive an error when you place this online. Work around this would be to grab the http_path from the phorum settings table unless there is already a preloaded way to get phorums directory path? I have looked in the phorumdblayer documentation but cant seem to find anything to this effect. Until this is fixed I suggest that this hack only be tried on a localhost setting.
Re: Country On Registration Module?
December 26, 2007 07:17PM
All Phorum code is run from the Phorum install dir. This is true for core scripts, templates, modules, etc. So you can safely asume that "./" is the Phorum directory at all times.

If you need a http reference to a Phorum file, then use http_path. This is a setting as you already found out. All settings are loaded into the $PHORUM global variable. So the http_path is always available as $GLOBALS['PHORUM']['http_path']. If you already include common.php or are running from a Phorum script which already included is for you, then there's no need to explicitly grab this from the database.

For your custom profile field, maybe you can add some pointers about the required field size. Also, make sure that the use of HTML is disabled for your field to prevent XSS hacks.

You add some strings to the main language file. That can be problematic for easy upgrading. Better write a really simple mod for adding extra language strings. It would only need a "hook: lang|" in the info.txt to let Phorum load the module's language file. Take a look at an extisting module for a language example. Later on, you could put things like the custom profile field creation and interface components in the module as well, but I guess that is something to grow into. The way in which you handled it now, seems okay to me too.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Country On Registration Module?
December 27, 2007 10:18AM
Yeah, what you have written there is a phpBB style "module". aka a hack of the code that makes upgrading a bear. Better to write a module for all non-template things and then explain the template changes needed for the template. Templates can safely be added to as they are always customized by the end user.

Brian - Cowboy Ninja Coder - Personal Blog - Twitter
Re: Country On Registration Module?
December 27, 2007 07:45PM
Yup I have more of a phpbb setup background and have only come across phorum very recently so I apologize about the style of it at the moment. For now I just thought I would put up what I had been doing to get some feedback so thanks for all the comments :) Right now I am just implementing the basic functionality of it so the end result is successful but once I get more used to the phorum modularity format I will try making it into a module or if anyone else wants to take it and run with it that would also work. Some edits on the country_select function to solve some bugs that I ran into when I tried it in an online server is to make some changes when sending the drop down menu to the template. The new code is found below and I am now working on displaying the flags in the forums beside the name of the poster. Once i get this I will post the rest of the changes and begin making it into a module.

	  <?php 
// Function for creating flag drop down list 
function country_select($default, $select_name = "country")
{
	$phorumpath = './';
	$country	=array();
	$countrydir = opendir($phorumpath . 'images/flags/');
    while ($file = readdir($countrydir)) { 
		if ($file != "." && $file != "..") {
			$filename = $file;
			$displayname = trim(str_replace(".gif", "", $filename));
			$country[$displayname] = $displayname;
        }
    }
	closedir($countrydir);
   	
	@asort($country);
	@reset($country);

	$country_select = '<select name="' . $select_name . '">';
	while ( list($displayname, $filename) = @each($country) )
	{
		$selected = ( strtolower($default) == strtolower($filename) ) ? ' selected="selected"' : '';
		$country_select .= '<option value="' . $displayname . '"' . $selected . '>' . ucwords($displayname) . '</option>';
	}
	$country_select .= '</select>';

	return $country_select;
}


$xxx = '';
$yyy = 'country';

echo country_select($xxx, $yyy);
?>

Also, is there a place where I can attach the flag folder of images in order for others to download and play around with it if they want?

Thanks.
Re: Country On Registration Module?
December 28, 2007 05:09AM
You could use the "Phorum Hacks" forum for that, as long as the code is not a wrapped up module.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Country On Registration Module?
February 21, 2008 01:12PM
I'll start to implement this straight away
Re: Country On Registration Module?
February 21, 2008 01:51PM
just a quick change to the usersettings.tpl to make it fit better with emerald.

Quote

<Br>
<dt>{LANG->Country}:&nbsp;</dt>
<dd>
<?php
// Function for creating flag drop down list
function country_select($default, $select_name = "country")
{
$phorumpath = './';
$country =array();
$countrydir = opendir($phorumpath . 'images/flags/');
while ($file = readdir($countrydir)) {
if ($file != "." && $file != "..") {
$filename = $file;
$displayname = trim(str_replace(".png", "", $filename));
$country[$displayname] = $displayname;
}
}
closedir($countrydir);

@asort($country);
@reset($country);

$country_select = '<select name="' . $select_name . '">';
while ( list($displayname, $filename) = @each($country) )
{
$selected = ( strtolower($default) == strtolower($filename) ) ? ' selected="selected"' : '';
$country_select .= '<option value="' . $displayname . '"' . $selected . '>' . ucwords($displayname) . '</option>';
}
$country_select .= '</select>';

return $country_select;
}


$xxx = '';
$yyy = 'country';

echo country_select($xxx, $yyy);
?>
</dd>

Now I just need to think of a good way to add this to people's posts.
Sorry, only registered users may post in this forum.

Click here to login