Originally posted by / Author:
V@no----- [ Overview ] ----- This mod will alow your members upload their photo that will be displayed in their profile.
----- [ Changed Files ] -----
member.php
includes/db_field_definitions.php
lang/<yourlanguage>/main.php
lang/<yourlanguage>/admin.php
admin/settings.php
admin/users.php
templates/<yourtemplate>/member_editprofile.html
templates/<yourtemplate>/member_profile.html [/color]
----- [ New Files ]----- userpic_install.php ----- [ New Folder ] ----- data/userpic/----- [ Installation ] ----- Step 1 Open
member.php Find:
"user_homepage_button" => $user_homepage_button,
Insert
above:
//User Pic
"userpic_img" => ($config['userpic'] && $user_row['userpic']) ? ROOT_PATH."data/userpic/".$user_row['userpic'] : "",
//End User Pic
Step 1.1 Find:
if (!$error && $user_email != $user_info['user_email'] && $user_info['user_level'] != ADMIN && $config['account_activation'] != 0) {
Insert
above:
// Upload User Pic
$userpic = $userpic_new = "";
if (!$error && $config['userpic'])
{
$userpics_dir = ROOT_PATH."data/userpic/";
if (!empty($HTTP_POST_FILES['userpic_file']['tmp_name']) && $HTTP_POST_FILES['userpic_file']['tmp_name'] != "none")
{
if (isset($HTTP_COOKIE_VARS['userpic_file']) || isset($HTTP_POST_VARS['userpic_file']) || isset($HTTP_GET_VARS['userpic_file'])) {
die("Security violation");
}
if (!function_exists("is_uploaded_file")) {
function is_uploaded_file($file_name) {
if (!$tmp_file = @get_cfg_var('upload_tmp_dir')) {
$tmp_file = tempnam('','');
$deleted = @unlink($tmp_file);
$tmp_file = dirname($tmp_file);
}
$tmp_file .= '/'.basename($file_name);
return (ereg_replace('/+', '/', $tmp_file) == $file_name) ? 1 : 0;
}
function move_uploaded_file($file_name, $destination) {
return (is_uploaded_file($file_name)) ? ((copy($file_name, $destination)) ? 1 : 0) : 0;
}
}
$error = array();
$extensions = array(
"jpg",
"jpeg",
"gif",
"png"
);
$mime_types = array();
$mime_type_match = array();
include_once(ROOT_PATH.'includes/upload_definitions.php');
foreach($extensions as $val)
$mime_types = array_merge($mime_types, $mime_type_match[$val]);
$mime_types = array_unique($mime_types);
$userpic_ext = strtolower(substr(strrchr($HTTP_POST_FILES['userpic_file']['name'],"."), 1));
$userpic_mime = $HTTP_POST_FILES['userpic_file']['type'];
if (!in_array($userpic_mime, $mime_types) || !in_array($userpic_ext, $extensions))
{
$error[] = $lang['invalid_file_type']. " (".$userpic_ext.", ".$HTTP_POST_FILES['userpic_file']['type'].")";
}
if ($HTTP_POST_FILES['userpic_file']['size'] > $config['userpic_size'] * 1024)
{
$error[] = $lang['invalid_file_size'];
}
if (empty($error))
{
$userpic_name = $user_info['user_id'].".".$userpic_ext;
$userpic_file = $userpics_dir.$userpic_name;
if (file_exists($userpic_file))
{
unlink($userpic_file);
}
if (!move_uploaded_file($HTTP_POST_FILES['userpic_file']['tmp_name'], $userpic_file))
{
$error[] = $lang['file_copy_error'];
}
else
{
@chmod($userpic_file, CHMOD_FILES);
}
}
if (empty($error))
{
$userpic = $HTTP_POST_VARS['userpic'] = $userpic_new = $userpic_name;
if ($user_info['userpic'] != $userpic_name && file_exists($userpics_dir.$user_info['userpic']))
{
@unlink($userpics_dir.$user_info['userpic']);
}
if (!function_exists(init_convert_options))
{
require(ROOT_PATH.'includes/image_utils.php');
}
$image_info = getimagesize($userpic_file);
$convert_options = init_convert_options();
if (($image_info[0] > $config['userpic_width'] || $image_info[1] > $config['userpic_height']))
{
if ($convert_options['convert_error'] || (!$convert_options['convert_error'] && !resize_image($userpic_file, 85, $config['userpic_width'], 1, $config['userpic_height'])))
{
if ($image_info[0] > $config['userpic_width'])
{
$error[] = $lang['invalid_image_width'];
}
if ($image_info[1] > $config['userpic_height'])
{
$error[] = $lang['invalid_image_height'];
}
}
}
}
if (!empty($error))
{
$msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$HTTP_POST_FILES['userpic_file']['name']."</b><br />";
foreach ($error as $val) {
$msg .= "<b>".$HTTP_POST_FILES['userpic_file']['name'].":</b> ".$val."<br />";
}
$HTTP_POST_VARS['userpic'] = $user_info['userpic'];
}
}
else
{
if (isset($HTTP_POST_VARS['userpic_del']) && $HTTP_POST_VARS['userpic_del'])
{
@unlink($userpics_dir.$user_info['userpic']);
$HTTP_POST_VARS['userpic'] = $userpic = "";
$userpic_new = 1;
}
}
}
// End Upload User Pic
Step 1.2 Find:
"user_showemail_yes" => $user_showemail_yes,
Insert
above:
//User Pic
"userpic_allowed" => $config['userpic'],
"userpic_img" => ($user_info['userpic']) ? ROOT_PATH."data/userpic/".$user_info['userpic'] : "",
"lang_userpic_del" => $lang['userpic_del'],
"lang_userpic_upload" => preg_replace("/".$site_template->start."userpic_max_size".$site_template->end."/siU", $config['userpic_size']." ".$lang['kb'], preg_replace("/".$site_template->start."userpic_max_width".$site_template->end."/siU", $config['userpic_width'], preg_replace("/".$site_template->start."userpic_max_height".$site_template->end."/siU", $config['userpic_height'], $lang['userpic_upload']))),
"userpic_max_width" => $config['userpic_width'],
"userpic_max_height" => $config['userpic_height'],
"userpic_max_size" => $config['userpic_size']." ".$lang['kb'],
//End User Pic
Step 2 Open
includes/db_field_definitions.php At the end,
above closing
?> insert:
$additional_user_fields['userpic'] = array($lang['userpic'], "text", 0);
Step 3Open
lang/<yourlanguage>/main.php At the end,
above closing
?> insert:
//-----------------------------------------------------
//--- User Pic ----------------------------------------
//-----------------------------------------------------
$lang['userpic'] = "Personal picture";
$lang['userpic_del'] = "Remove";
$lang['userpic_upload'] = "Maximum image size: {userpic_max_size}.<br />Image larger {userpic_max_width}x{userpic_max_height} will be resized";
$lang['file_copy_error'] = "Copy error. Please check the directory permissions.";
//--- End User Pic ------------------------------------
Step 4Open
lang/<yourlanguage>/admin.phpAt the end,
above closing
?> insert:
//User Pic
/*-- Setting-Group Member Personal Photo --*/
$setting_group['memberpersonalphoto']="Personal Picture";
$setting['userpic'] = "Activate";
$setting['userpic_size'] = "Max. image size in KB";
$setting['userpic_width'] = "Max. image width in pixel";
$setting['userpic_height'] = "Max. image height in pixel";
//End User Pic
Step 5Open
admin/settings.phpFind:
show_form_footer($lang['save_changes'], "", 2);
Insert
above:
//User Pic
show_table_separator($setting_group['memberpersonalphoto'], 2, "setting_group_memberpersonalphoto");
show_setting_row("userpic", "radio");
show_setting_row("userpic_width");
show_setting_row("userpic_height");
show_setting_row("userpic_size");
//End User Pic
Step 6Open
templates/<yourtemplate>/member_editprofile.htmlFind:
<form method="post" action="{url_member}">
Replace it with:
<form method="post" action="{url_member}" enctype="multipart/form-data">
or just make sure that
enctype="multipart/form-data" is present inside the <form> tag.
Step 6.1Find:
<tr>
<td class="row2"><b>{lang_icq}</b></td>
<td class="row2"><input type="text" name="user_icq" size="30" value="{user_icq}" class="input" /></td>
</tr>
Insert
below:
{if userpic_allowed}
<tr>
<td class="row1" valign="top"><b>{lang_userpic}</b>
<SPAN class="smalltext">
<br />
<B>{lang_userpic_upload}</B>
</SPAN>
</td>
<td class="row1">
<INPUT type="file" name="userpic_file" size="30" class="input" /><br />
{if userpic_img}<img src="{userpic_img}"><br /><input type="checkbox" name="userpic_del" value="1"> {lang_userpic_del}{endif userpic_img}
</TD>
</TR>
{endif userpic_allowed}
(ofcourse u can add it anywhere u want in this file)
Step 7 updated 28.6.2006 Open
templates/<yourtemplate>/member_profile.html Find:
<tr>
<td class="row2"><b>{lang_icq}</b></td>
<td class="row2">{if user_icq}<a href="http://wwp.icq.com/scripts/search.dll?to={user_icq}">{user_icq}</a> (<b>{user_icq_status}</b>){endif user_icq}</td>
</tr>
Replace with:
<tr>
<td class="row2"><b>{lang_icq}</b></td>
<td class="row2">{if user_icq}<a href="http://www.icq.com/people/about_me.php?uin={user_icq}">{user_icq}</a> (<b>{user_icq_status}</b>){endif user_icq}</td>
</tr>
{if userpic_img}
<tr>
<td class="row1" valign="top"><b>{lang_userpic}</b></td>
<td class="row1"><img src="{userpic_img}"></td>
</tr>
{endif userpic_img}
Step 8 Create a new folder:
data/userpic/ Set CHMOD 777 (unix systems only) and make sure its writible by your webserver.
Step 9 Download
this package, extract it and upload to your 4images root directory, then execute it by typing in your browser:
http://<your_site_address_and_path_to_your_4images>/userpic_install.php Follow the instructions.
Or u can update your database manualy by executing this MySQL query:
ALTER TABLE `4images_users` ADD `userpic` varchar(255) NOT NULL default '';
INSERT INTO `4images_settings` ( `setting_name` , `setting_value` ) VALUES ('userpic', '1');
INSERT INTO `4images_settings` ( `setting_name` , `setting_value` ) VALUES ('userpic_size', '500');
INSERT INTO `4images_settings` ( `setting_name` , `setting_value` ) VALUES ('userpic_width', '200');
INSERT INTO `4images_settings` ( `setting_name` , `setting_value` ) VALUES ('userpic_height', '200');
Step 10Step 10 and 11 required if your would like display members photos on their images details page (details.php)
Open
details.phpFind:
$additional_sql = "";
Insert
below:
if (!empty($additional_user_fields)) {
foreach ($additional_user_fields as $key => $val) {
$additional_sql .= ", u.".$key;
}
}
(if this block of code is already present in details.php, then u dont need doublicate it
)
Step 11Open
includes/functions.phpFind:
if (!empty($additional_image_fields)) {
Insert
above:
if (!empty($additional_user_fields)) {
$additional_field_array = array();
foreach ($additional_user_fields as $key => $val) {
if ($key != "userpic" || ($key == "userpic" && $config['userpic']))
{
$additional_field_array[$key] = (!empty($image_row[$key])) ? format_text($image_row[$key], 1) : REPLACE_EMPTY;
$additional_field_array['lang_'.$key] = $val[0];
}
}
if (!empty($additional_field_array)) {
$site_template->register_vars($additional_field_array);
}
}
Now you can use
{userpic} in details.html template.
Step 12This steps 12 - 13 are required if you would like show members photos in their comments.
Open
details.phpFind:
$sql = "SELECT c.comment_id, c.image_id, c.user_id, c.user_name AS comment_user_name, c.comment_headline, c.comment_text, c.comment_ip, c.comment_date".get_user_table_field(", u.", "user_level").get_user_table_field(", u.", "user_name").get_user_table_field(", u.", "user_email").get_user_table_field(", u.", "user_showemail").get_user_table_field(", u.", "user_invisible").get_user_table_field(", u.", "user_joindate").get_user_table_field(", u.", "user_lastaction").get_user_table_field(", u.", "user_comments").get_user_table_field(", u.", "user_homepage").get_user_table_field(", u.", "user_icq")."
Replace it with:
$sql = "SELECT c.comment_id, c.image_id, c.user_id, c.user_name AS comment_user_name, c.comment_headline, c.comment_text, c.comment_ip, c.comment_date".get_user_table_field(", u.", "user_level").get_user_table_field(", u.", "user_name").get_user_table_field(", u.", "user_email").get_user_table_field(", u.", "user_showemail").get_user_table_field(", u.", "user_invisible").get_user_table_field(", u.", "user_joindate").get_user_table_field(", u.", "user_lastaction").get_user_table_field(", u.", "user_comments").get_user_table_field(", u.", "user_homepage").get_user_table_field(", u.", "user_icq").", u.userpic
Step 12.1Find:
"comment_user_ip" => $comment_user_ip,
Insert
below:
"comment_userpic" => ($config['userpic'] && $comment_row[$i]['userpic']) ? ROOT_PATH."data/userpic/".$comment_row[$i]['userpic'] : "",
Step 13Insert in
templates/<your_template>/comment_bit.html (whereever u want the member's pic to be displayed. Design is your job
)
{if comment_userpic} <img src="{comment_userpic}">{endif comment_userpic}
Step 14In
admin/users.php find:
$sql = "SELECT ".get_user_table_field("", "user_id").get_user_table_field(", ", "user_name")."
FROM ".USERS_TABLE."
WHERE ".get_user_table_field("", "user_id")." IN ($user_ids)";
$user_result = $site_db->query($sql);
$image_ids_sql = "";
while ($user_row = $site_db->fetch_array($user_result)) {
$user_id = $user_row[$user_table_fields['user_id']];
$user_name = $user_row[$user_table_fields['user_name']];Replace with:
$sql = "SELECT ".get_user_table_field("", "user_id").get_user_table_field(", ", "user_name").", userpic
FROM ".USERS_TABLE."
WHERE ".get_user_table_field("", "user_id")." IN ($user_ids)";
$user_result = $site_db->query($sql);
$image_ids_sql = "";
while ($user_row = $site_db->fetch_array($user_result)) {
$user_id = $user_row[$user_table_fields['user_id']];
$user_name = $user_row[$user_table_fields['user_name']];
if ($user_row['userpic'] && file_exists(ROOT_PATH."data/userpic/".$user_row['userpic']) && is_file(ROOT_PATH."data/userpic/".$user_row['userpic']))
{
unlink(ROOT_PATH."data/userpic/".$user_row['userpic']);
}
----- [ Addons ] ----- [/list]
----- [ Version History ] ----- 1.1.3 (2011-10-23)
- Updated step 1.1, 4 and 5
1.1.2 - Added Step 14 that deletes user personal photos when user is deleted.
(Thanks to alekinna)1.1.1 - Fixed some tags not being displayed in the edit profile (redo Step 1.2)
1.1 - Added optional Steps 10 - 13
1.0 - Original release