برگزیده های پرشین تولز

افزودن فيلدي خاص به جدول كاربران در phpBB

hyper

کاربر تازه وارد
تاریخ عضویت
7 اکتبر 2004
نوشته‌ها
59
لایک‌ها
3
سن
53
با سلام

يكي از مشكلاتي كه بيشتر استفاده كنندگان phpBB دارند اينه كه به فيلدهايي كه به صورت پيش فرض در جدول كاربران ( Users ) تعبيه شده محدود ميباشند

گاه لازمه كه شما فيلد خاصي رو به اين جدول افزوده و بتونيد ازش استفاده كنيد
به عنوان مثال در يك انجمن موبايل ، قطعا خوبه كه شما بتونيد نام گوشي مورد استفاده كاربر رو دريافت و در جاي بخصوصي نمايش بديد و ...

در اين مثال هم من از همين مورد استفاده كردم
فرض رو بر اين ميزاريم كه ميخواهيم فيلدي بنام گوشي موبايل كاربر رو به جدول كاربران افزوده و از اون استفاده كنيم
پر واضحه كه شما ميتونيد به دلخواه خودتون اين فيلد رو تغيير داده و فيلد مورد نظر خودتون رو درج كنيد ...

خوب اين از معجزات opensource است كه خوشبختانه phpBB اونو كاملا در اختيارتون ميزاره !

در اين آموزش ، ابتدا فيلد مورد نظر رو توسط دستور

کد:
ALTER TABLE ......
به جدول كاربران اضافه ميكنيم

سپس گزينه لازم رو در فرم اطلاعات ورودي كاربر اضافه ميكنم
و همچنين از اونجايي كه ادمين بايد بتونه اين اطلاعات رو در قسمت ويرايش اطلاعات كاربر توسط ادمين ويرايش كنه ، قاعدتا اونجا هم درج ميكنيم

حالا براي نمايش دو راه بخصوص داريم :

1. نمايش فيلد مورد نظر در پروفايل كاربر
2. نمايش فيلد مورد نظر در مشخصات كاربر در هنگام نمايش پستها ( زير آواتار )


خوب پس اين مقدمه ميتونيم از دستور العمل زير كه سعي كرده ام اون رو طبق استاندارد مودهاي phpBB بنويسم ، كارمون رو شروع كنيم ...

اميدوارم مورد استفاده قرار بگيره ، فقط اينو بگم كه ساعتها روي اين مود كار كرده ام و خوشبختانه بعد از چندين مورد تست هم مشكلي نداشته است

موفق باشيد ...

کد:
##############################################################
## MOD Title : Add a Custom Field User Data Bank and Show in VIEWTOPIC ...
##
## MOD Author : Cyber ( Hyper )  
##                                               < [email protected] , [email protected] >
##                                               < http://www.pptforum.com >
## MOD Description : Add the Field
##                  
##                              - Mobile Set ( or any field you want ... )  to your Userprofile AND show in viewtopic .
##                  
## MOD Version : [ 1.0.1 ]
##
## MOD Date : 26 June 2005 
##
## Installation Level : [ Intermediate ]
## Installation Time :  [ 20 ] Minutes
## Files To Edit :      [ 11 ] files
##
##             admin/admin_users.php
##             includes/usercp_avatar.php
##             includes/usercp_register.php
##             includes/usercp_viewprofile.php
##             language/lang_english/lang_main.php
##             language/lang_german/lang_main.php
##             templates/subSilver/admin/user_edit_body.tpl
##             templates/subSilver/profile_add_body.tpl
##             templates/subSilver/profile_view_body.tpl
##
##              viewtopic.php
##              templates/subSilver/viewtopic_body.tpl

## Included Files:  n/a
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################
#
#-----[ SQL ]------------------------------------------
#

ALTER TABLE phpbb_users ADD user_mobile VARCHAR(255) AFTER user_interests;


#
#-----[ OPEN ]------------------------------------------
#
language/lang_english/lang_main.php


#
#-----[ FIND ]------------------------------------------
#
?>


#
#-----[ BEFORE, ADD ]------------------------------------------
#
// Add a Custom Field User Data Bank and Show in VIEWTOPIC ...
$lang['mobile'] = 'Mobile Set ';


#
#-----[ OPEN ]------------------------------------------
#
includes/usercp_viewprofile.php


#
#-----[ FIND ]------------------------------------------
#
	'INTERESTS' => ( $profiledata['user_interests'] ) ? $profiledata['user_interests'] : '&nbsp;',


#
#-----[ AFTER, ADD ]------------------------------------------
#
// Add a Custom Field User Data Bank and Show in VIEWTOPIC ...
	'mobile' => ( $profiledata['user_mobile'] ) ? $profiledata['user_mobile'] : '&nbsp;',
	'L_mobile' => $lang['mobile'],


#
#-----[ OPEN ]------------------------------------------
#
includes/usercp_register.php


#
#-----[ FIND ]------------------------------------------
#
$strip_var_list = array('username' => 'username', 'email' => 'email', 'icq' => 'icq', 'aim' => 'aim', 'msn' => 'msn', 'yim' => 'yim', 'website' => 'website', 'location' => 'location', 'occupation' => 'occupation', 'interests' => 'interests');


#
#-----[ IN-LINE FIND ]------------------------------------------
#
'interests'


#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
, 'mobile' => 'mobile'


#
#-----[ FIND (2 times!!)]------------------------------------------
#
$interests = stripslashes($interests);


#
#-----[ AFTER, ADD ]------------------------------------------
#
	// Add a Custom Field User Data Bank and Show in VIEWTOPIC ...
		$mobile = stripslashes($mobile);
		

#
#-----[ FIND ]------------------------------------------
#
$sql = "UPDATE " . USERS_TABLE . "


#
#-----[ IN-LINE FIND ]------------------------------------------
#
$interests) . "'


#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
, user_mobile = '" . str_replace("\'", "''", $mobile) . "'



#
#-----[ FIND ]------------------------------------------
#
$sql = "INSERT INTO " . USERS_TABLE . "	(user_id, username, user_regdate, user_password, user_email, user_icq, user_website,


#
#-----[ IN-LINE FIND ]------------------------------------------
#
 '" . str_replace("\'", "''", $interests) . "',

#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
 '" . str_replace("\'", "''", $mobile) . "',


# 
#-----[ FIND ]---------------------------------------------------
# 
			$sql = "INSERT INTO " . USERS_TABLE . "

#
#-----[ IN-LINE FIND ]------------------------------------------
#
user_interests


#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
, user_mobile

#
#-----[ FIND ]------------------------------------------
#
$interests = $userdata['user_interests'];


#
#-----[ AFTER, ADD ]------------------------------------------
#
// Add a Custom Field User Data Bank and Show in VIEWTOPIC ...
 	$mobile = $userdata['user_mobile'];
	

#
#-----[ FIND ]------------------------------------------
#
display_avatar_gallery($mode, $avatar_category


#
#-----[ IN-LINE FIND ]------------------------------------------
#
$interests


#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
, $mobile


#
#-----[ FIND (2 times!!)]------------------------------------------
#
'INTERESTS' => $interests,


#
#-----[ AFTER, ADD ]------------------------------------------
#
	// Add a Custom Field User Data Bank and Show in VIEWTOPIC ...
		'mobile' => $mobile,
		'L_mobile' => $lang['mobile'],
		
		
#
#-----[ OPEN ]------------------------------------------
#
includes/usercp_avatar.php


#
#-----[ FIND ]------------------------------------------
#
function display_avatar_gallery($mode, &$category


#
#-----[ IN-LINE FIND ]------------------------------------------
#
&$interests


#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
, &$mobile


#
#-----[ FIND ]------------------------------------------
#
$params = array('coppa', 'user_id'


#
#-----[ IN-LINE FIND ]------------------------------------------
#
'dateformat'


#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
, 'mobile'


#
#-----[ OPEN ]------------------------------------------
#
admin/admin_users.php


#
#-----[ FIND ]------------------------------------------
#
$interests = ( !empty($HTTP_POST_VARS['interests']) ) ? trim(strip_tags( $HTTP_POST_VARS['interests'] ) ): ''; 


#
#-----[ AFTER, ADD ]------------------------------------------
#
	// Add a Custom Field User Data Bank and Show in VIEWTOPIC ...
		$mobile = ( !empty($HTTP_POST_VARS['mobile']) ) ? trim(strip_tags( $HTTP_POST_VARS['mobile'] ) ) : ''; 


#
#-----[ FIND (2 Times!!)]------------------------------------------
#
$interests = htmlspecialchars(stripslashes($interests));


#
#-----[ AFTER, ADD ]------------------------------------------
#
	// Add a Custom Field User Data Bank and Show in VIEWTOPIC ...
		$mobile = htmlspecialchars(stripslashes($mobile));


#
#-----[ FIND ]------------------------------------------
#
$sql = "UPDATE " . USERS_TABLE . "


#
#-----[ IN-LINE FIND ]------------------------------------------
#
$interests) . "'


#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
, user_mobile = '" . str_replace("\'", "''", $mobile) . "'

#
#-----[ FIND ]------------------------------------------
#
$interests = htmlspecialchars($this_userdata['user_interests']);


#
#-----[ AFTER, ADD ]------------------------------------------
#
	// Add a Custom Field User Data Bank and Show in VIEWTOPIC ...
		$mobile = htmlspecialchars($this_userdata['user_mobile']);


#
#-----[ FIND ]------------------------------------------
#
$s_hidden_fields .= '<input type="hidden" name="interests" value="' . str_replace("\"", "&quot;", $interests) . '" />';


#
#-----[ AFTER, ADD ]------------------------------------------
#
	// Add a Custom Field User Data Bank and Show in VIEWTOPIC ...
		$s_hidden_fields .= '<input type="hidden" name="mobile" value="' . str_replace("\"", "&quot;", $mobile) . '" />'; 


#
#-----[ FIND ]------------------------------------------
#
'INTERESTS' => $interests,


#
#-----[ AFTER, ADD ]------------------------------------------
#
	// Add a Custom Field User Data Bank and Show in VIEWTOPIC ...
			'mobile' => $mobile, 
			'L_mobile' => $lang['mobile'],



#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/profile_add_body.tpl


#
#-----[ FIND ]------------------------------------------
#
	<tr> 
	  <td class="row1"><span class="gen">{L_INTERESTS}:</span></td>
	  <td class="row2"> 
		<input type="text" class="post"style="width: 200px"  name="interests" size="35" maxlength="150" value="{INTERESTS}" />
	  </td>
	</tr>


#
#-----[ AFTER, ADD ]------------------------------------------
#
<!--  Add a Custom Field User Data Bank and Show in VIEWTOPIC ... -->
	<tr> 
	  <td class="row1"><span class="explaintitle">{L_mobile}:</span></td>
	  <td class="row2"> <input type="text" class="post"style="width: 200px"  name="mobile" size="35" maxlength="250" value="{mobile}"  onKeyDown="FKeyDown();" onkeypress="FKeyPress();" /> </td>
	</tr>

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/profile_view_body.tpl


#
#-----[ FIND ]------------------------------------------
#
		<tr> 
		  <td valign="top" align="right"><span class="gen">{L_INTERESTS}:</span></td>
		  <td> <b><span class="gen">{INTERESTS}</span></b></td>
		</tr>


#
#-----[ AFTER, ADD ]------------------------------------------
#
<!--  Add a Custom Field User Data Bank and Show in VIEWTOPIC ... -->
		<tr> 
		  <td valign="top" align="right" class="explaintitle">{L_mobile}:</td>
		  <td><span class="gen">{mobile}</span></td>
		</tr>


#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/admin/user_edit_body.tpl


#
#-----[ FIND ]------------------------------------------
#
	<tr> 
	  <td class="row1"><span class="gen">{L_INTERESTS}</span></td>
	  <td class="row2"> 
		<input type="text" name="interests" size="35" maxlength="150" value="{INTERESTS}" />
	  </td>
	</tr>


#
#-----[ AFTER, ADD ]------------------------------------------
#
<!--  Add a Custom Field User Data Bank and Show in VIEWTOPIC ... -->
        <tr> 
          <td class="row1"><span class="gen">{L_mobile}</span></td> 
          <td class="row2"> <input class="post" type="text" name="mobile" size="35" maxlength="250" value="{mobile}"  onKeyDown="FKeyDown();" onkeypress="FKeyPress();" /> </td>
         </tr>
         

#
#-----[ OPEN ]------------------------------------------
#
viewtopic.php


#
#-----[ FIND ]------------------------------------------
#
//
// Go ahead and pull all data for this topic
//
$sql = "SELECT u.username, u.user_id, u.user


#
#-----[ IN-LINE FIND ]------------------------------------------
#
pt.bbcode_uid


#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
, u.user_mobile



#
#-----[ FIND ]------------------------------------------
#
	$poster_from = ( $postrow[$i]['user_from'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Location'] . ': ' . $postrow[$i]['user_from'] : '';


#
#-----[ AFTER, ADD ]------------------------------------------
#
	$user_mobile = ( $postrow[$i]['user_mobile'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['mobile'] . ': ' . $postrow[$i]['user_mobile'] : '';


#
#-----[ FIND ]------------------------------------------
#
	'POSTER_FROM' => $poster_from,

#
#-----[ AFTER, ADD ]------------------------------------------
#
	'POSTER_MOBILE' => $user_mobile,


#
#-----[ OPEN ]------------------------------------------
#
viewtopic_body.tpl


#
#-----[ FIND ]------------------------------------------
#
<center>{postrow.POSTER_POSTS}<br />


#
#-----[ AFTER, ADD ]------------------------------------------
#
{postrow.POSTER_MOBILE}<br />



#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM
 
بالا