赞
踩
ECSHOP实现会员头像功能,评论显示会员头像功能。ECSHOP几年没更新了,功能上实在不尽人意,几乎绝大部分的商城网站都有了会员头像功能,但是ECSHOP却没有。得益于ECSHOP的开源,自然有大神二次开发实现了这个功能,一流资源网免费分享出来。
修改的步骤比较多,要耐心一点,一定记得先备份。
一流资源网已经在ECSHOP2.7.3版测试成功了。
教程开始:
后台 SQL查询里运行以下代码:
1
|
ALTER
TABLE
`ecs_users`
ADD
`avatar`
VARCHAR
( 255 )
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NOT
NULL
DEFAULT
''
|
打开 themes\default\user_clips.dwt
查找:
1
2
|
<!-- *用户中心默认显示页面 start-->
<!-- {
if
$action
eq
'default'
} -->
|
在这两行代码后面合适位置加入以下代码:
1
2
3
4
5
6
7
8
9
10
11
12
|
<style>
.avtar .img a{display:none;width:72px;height:23px;background:url(images/change_avtar.gif);position:absolute;margin-left:44px;margin-top:93px}
.avtar .hover a{display:block}
.Left .img{border:1px solid #d0d0d0;margin-bottom:5px}
.Left .img,.Left .img img{width:120px;height:120px}
</style>
<div
class
=
"Left avtar"
style=
"float:left;width:122px;text-align:center;"
>
<div onmouseout=
"this.className='img'"
onmouseover=
"this.className='img hover'"
class
=
"img"
>
<a title=
"修改我的头像"
href=
"user.php?act=profile"
class
=
"red"
></a>
<img src=
"{if $info.avatar}{$info.avatar}{else}images/avatar.gif{/if}"
>
</div>
</div>
|
打开 themes\default\user_transaction.dwt
查找:
1
2
|
<!-- 用户信息界面 start-->
<!--{
if
$action
eq
'profile'
}-->
|
在这两行代码后面找到:
1
|
<form name=
"formEdit"
action=
"user.php"
method=
"post"
onSubmit=
"return userEdit()"
>
|
修改成:
1
2
|
<form name=
"formEdit"
action=
"user.php"
method=
"post"
onSubmit=
"return userEdit()"
enctype=
"multipart/form-data"
>
<input type=
"hidden"
name=
"MAX_FILE_SIZE"
value=
"1097152"
/><!-- 1M图片上传大小设置 -->
|
再找到 submit 提交之前加入:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
<tr>
<td width=
"28%"
align=
"right"
bgcolor=
"#FFFFFF"
>会员头像:</td>
<td width=
"72%"
align=
"left"
bgcolor=
"#FFFFFF"
>
<div style=
"width:50%;float:left;"
>
<input id=
"avatar"
type=
"file"
size=
"40"
value=
""
name=
"avatar"
>
<br/>
<span style=
"color:#FF0000"
> 图片像素最佳为55px * 55px,<br/>大小不得超过1M</span>
</div>
<div style=
"width:50%;float:left;"
>
<img src=
"{if $profile.avatar}{$profile.avatar}{else}images/avatar.gif{/if}"
alt=
""
width=
"55"
height=
"55"
>
</div>
</td>
</tr><tr>
<td width=
"28%"
align=
"right"
bgcolor=
"#FFFFFF"
>会员头像:</td>
<td width=
"72%"
align=
"left"
bgcolor=
"#FFFFFF"
>
<div style=
"width:50%;float:left;"
>
<input id=
"avatar"
type=
"file"
size=
"40"
value=
""
name=
"avatar"
>
<br/>
<span style=
"color:#FF0000"
> 图片像素最佳为55px * 55px,<br/>大小不得超过1M</span>
</div>
<div style=
"width:50%;float:left;"
>
<img src=
"{if $profile.avatar}{$profile.avatar}{else}images/avatar.gif{/if}"
alt=
""
width=
"55"
height=
"55"
>
</div>
</td>
</tr>
|
打开根目录下 user.php 文件
查找:
1
|
require
(dirname(
__FILE__
) .
'/includes/init.php'
);
|
在下面新增一行加入以下代码:
1
2
3
|
include_once
(ROOT_PATH .
'/includes/cls_image.php'
);
//会员头像 by neo
$image
=
new
cls_image(
$_CFG
[
'bgcolor'
]);
//会员头像 by neo
$allow_suffix
=
array
(
'gif'
,
'jpg'
,
'png'
,
'jpeg'
,
'bmp'
);
//会员头像 by neo
|
继续查找:
1
|
/* 更新用户扩展字段的数据 */
|
在上面加入代码:
1
|
$avatar
= isset(
$_POST
[
'avatar'
]) ?
$_POST
[
'avatar'
] :
''
;
//会员头像 by neo
|
继续查找:
1
2
3
4
|
if
(!
empty
(
$mobile_phone
) && !preg_match(
'/^[\d-\s]+$/'
,
$mobile_phone
))
{
show_message(
$_LANG
[
'passport_js'
][
'mobile_phone_invalid'
]);
}
|
在下面加入代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/* 检查图片:如果有错误,检查尺寸是否超过最大值;否则,检查文件类型 */
if
(isset(
$_FILES
[
'avatar'
][
'error'
]))
// php 4.2 版本才支持 error
{
// 最大上传文件大小
$php_maxsize
=
ini_get
(
'upload_max_filesize'
);
$htm_maxsize
=
'1M'
;
// 会员头像
if
(
$_FILES
[
'avatar'
][
'error'
] == 0)
{
if
(!
$image
->check_img_type(
$_FILES
[
'avatar'
][
'type'
]))
{
show_message(
"图片格式不正确!"
);
}
}
elseif
(
$_FILES
[
'avatar'
][
'error'
] == 1)
{
show_message(sprintf(
'图片文件太大了(最大值:1M),无法上传。'
,
$php_maxsize
),
$_LANG
[
'profile_lnk'
],
'user.php?act=profile'
,
'info'
);
}
elseif
(
$_FILES
[
'avatar'
][
'error'
] == 2)
{
show_message(sprintf(
'图片文件太大了(最大值:1M),无法上传。'
,
$htm_maxsize
),
$_LANG
[
'profile_lnk'
],
'user.php?act=profile'
,
'info'
);
}
}
/* 4.1版本 */
else
{
// 会员头像
if
(
$_FILES
[
'avatar'
][
'tmp_name'
] !=
'none'
)
{
if
(!
$image
->check_img_type(
$_FILES
[
'avatar'
][
'type'
]))
{
show_message(
"图片格式不正确!"
);
}
}
}
//会员头像 by neo
if
(!
empty
(
$_FILES
[
'avatar'
][
'name'
]))
{
/* 更新会员头像之前先删除旧的头像 */
$sql
=
"SELECT avatar "
.
" FROM "
.
$GLOBALS
[
'ecs'
]->table(
'users'
) .
" WHERE user_id = '$user_id'"
;
$row
=
$GLOBALS
[
'db'
]->getRow(
$sql
);
if
(
$row
[
'avatar'
] !=
''
)
{
@unlink(
$row
[
'avatar'
]);
}
$img_name
=
$user_id
.
'.'
.
end
(
explode
(
'.'
,
$_FILES
[
'avatar'
][
'name'
]));
$target
= ROOT_PATH . DATA_DIR .
'/avatar/'
;
$original_img
=
$image
->upload_image(
$_FILES
[
'avatar'
],
'avatar'
,
$img_name
);
// 原始图片
$avatar
=
$image
->make_thumb(
$original_img
, 55, 55,
$target
);
if
(
$avatar
=== false)
{
show_message(
"图片保存出错!"
);
}
}
|
1
2
3
4
5
6
7
|
$profile
=
array
(
'user_id'
=>
$user_id
,
'email'
=> isset(
$_POST
[
'email'
]) ? trim(
$_POST
[
'email'
]) :
''
,
'sex'
=> isset(
$_POST
[
'sex'
]) ?
intval
(
$_POST
[
'sex'
]) : 0,
'birthday'
=>
$birthday
,
'other'
=> isset(
$other
) ?
$other
:
array
()
);
|
修改成:
1
2
3
4
5
6
7
8
|
$profile
=
array
(
'user_id'
=>
$user_id
,
'email'
=> isset(
$_POST
[
'email'
]) ? trim(
$_POST
[
'email'
]) :
''
,
'sex'
=> isset(
$_POST
[
'sex'
]) ?
intval
(
$_POST
[
'sex'
]) : 0,
'birthday'
=>
$birthday
,
'avatar'
=>
$avatar
,
//会员头像 by neo
'other'
=> isset(
$other
) ?
$other
:
array
()
);
|
打开根目下 /includes/lib_clips.php
查找:
1
2
3
4
5
|
function
get_user_default(
$user_id
)
{
$user_bonus
= get_user_bonus();
$sql
=
"SELECT pay_points, user_money, credit_line, last_login, is_validated FROM "
.
$GLOBALS
[
'ecs'
]->table(
'users'
).
" WHERE user_id = '$user_id'"
;
|
替换成:
1
2
3
4
5
|
function
get_user_default(
$user_id
)
{
$user_bonus
= get_user_bonus();
//会员头像 by neo
$sql
=
"SELECT pay_points, user_money, credit_line, last_login, is_validated, avatar FROM "
.
$GLOBALS
[
'ecs'
]->table(
'users'
).
" WHERE user_id = '$user_id'"
;
|
继续在后面找到:
1
|
$info
=
array
();
|
在下面一行加入:
1
|
$info
[
'avatar'
] =
$row
[
'avatar'
];
//会员头像 by neo
|
打开 includes\lib_transaction.php 文件
找到:
1
|
if
(!
$GLOBALS
[
'user'
]->edit_user(
$cfg
))
|
在前面一行增加:
1
2
3
4
5
|
//会员头像
if
(!
empty
(
$profile
[
'avatar'
]))
{
$cfg
[
'avatar'
] =
$profile
[
'avatar'
];
}
|
继续查找:
1
2
3
4
5
6
7
8
9
10
|
function
get_profile(
$user_id
)
{
global
$user
;
/* 会员帐号信息 */
$info
=
array
();
$infos
=
array
();
$sql
=
"SELECT user_name, birthday, sex, question, answer, rank_points, pay_points,user_money, user_rank,"
.
" msn, qq, office_phone, home_phone, mobile_phone, passwd_question, passwd_answer "
.
"FROM "
.
$GLOBALS
[
'ecs'
]->table(
'users'
) .
" WHERE user_id = '$user_id'"
;
|
修改为:
1
2
3
4
5
6
7
8
9
10
|
function
get_profile(
$user_id
)
{
global
$user
;
/* 会员帐号信息 */
$info
=
array
();
$infos
=
array
();
$sql
=
"SELECT user_name, birthday, sex, question, answer, rank_points, pay_points,user_money, user_rank,"
.
" msn, qq, office_phone, home_phone, mobile_phone, passwd_question, passwd_answer, avatar "
.
//会员头像 by neo
"FROM "
.
$GLOBALS
[
'ecs'
]->table(
'users'
) .
" WHERE user_id = '$user_id'"
;
|
继续查找:
1
|
$info
[
'birthday'
] = isset(
$infos
[
'birthday'
]) ?
$infos
[
'birthday'
] :
''
;
|
在下面加入:
1
|
$info
[
'avatar'
] = isset(
$infos
[
'avatar'
]) ?
$infos
[
'avatar'
] :
''
;
//会员头像 by neo
|
打开 includes\modules\integrates\integrate.php
查找:
1
|
var
$error
= 0;
|
下面一行加入:
1
2
|
/* 会员头像 by neo */
var
$field_avatar
=
''
;
|
继续查找:
1
2
3
4
|
if
((!
empty
(
$cfg
[
'bday'
])) &&
$this
->field_bday !=
'NULL'
)
{
$values
[] =
$this
->field_bday .
"='"
.
$cfg
['bday
'] . "'
";
}
|
在下面一行加入:
1
2
3
4
5
|
//会员头像 by neo
if
((!
empty
(
$cfg
[
'avatar'
])) &&
$this
->field_avatar !=
'NULL'
)
{
$values
[] =
$this
->field_avatar .
"='"
.
$cfg
['avatar
'] . "'
";
}
|
打开 includes\modules\integrates\ecshop.php
查找:
1
|
$this
->field_reg_date =
'reg_time'
;
|
下面一行加入:
1
|
$this
->field_avatar =
'avatar'
;
//会员头像 by neo
|
至此,前台显示及上传就OK了!
打开 includes/lib_main.php 找到
1
|
function
assign_comment(
$id
,
$type
,
$page
= 1)
|
在该函数里面找到:
1
2
3
|
$sql
=
'SELECT * FROM '
.
$GLOBALS
[
'ecs'
]->table(
'comment'
) .
" WHERE id_value = '$id' AND comment_type = '$type' AND status = 1 AND parent_id = 0"
.
' ORDER BY comment_id DESC'
;
|
修改成:
1
2
3
|
$sql
=
'SELECT c.*,u.avatar FROM '
.
$GLOBALS
[
'ecs'
]->table(
'comment'
) .
' as c left join '
.
$GLOBALS
[
'ecs'
]->table(
'users'
) .
" as u on c.user_id = u.user_id WHERE c.id_value = '$id' AND c.comment_type = '$type' AND c.status = 1 AND c.parent_id = 0"
.
' ORDER BY c.comment_id DESC'
;
//会员头像 by neo
|
继续查找:
1
|
$arr
[
$row
[
'comment_id'
]][
'add_time'
] = local_date(
$GLOBALS
[
'_CFG'
][
'time_format'
],
$row
[
'add_time'
]);
|
在下面一行加入:
1
|
$arr
[
$row
[
'comment_id'
]][
'avatar'
] =
$row
[
'avatar'
];
//会员头像 by neo
|
评论模板调用方法:
打开 themes/default/library/comments_list.lbi
查找:
1
|
<!-- {
foreach
from=
$comments
item=comment} -->
|
在foreach内容下面合适位置使用以下代码中用头像:
1
2
3
|
<p style=
"width:60px;height:60px;float:left;"
>
<img style=
"position:absolute;left:0;top:3px;width:55px;height:55px;"
src=
"<!-- {if $comment.avatar} -->{$comment.avatar}<!-- {else} -->images/avatar.gif<!-- {/if} -->"
>
</p>
|
有会员头像就显示,没有头像就调用默认的头像。
默认的头像目录为:/images/avatar.gif
将制作好的默认头像图片上传到这个目录即可,附件中也有提供!
最终效果:
后台修改部分,如果不需要后台修改修改会员头像可以不用修改。
打开 admin\templates\user_info.htm
查找:
1
|
<form method=
"post"
action=
"users.php"
name=
"theForm"
onsubmit=
"return validate()"
>
|
修改为:
1
2
|
<form method=
"post"
action=
"users.php"
name=
"theForm"
onsubmit=
"return validate()"
enctype=
"multipart/form-data"
>
<input type=
"hidden"
name=
"MAX_FILE_SIZE"
value=
"1097152"
/><!-- 1M图片上传大小设置 -->
|
继续查找:
1
2
3
4
|
<tr>
<td
class
=
"label"
>{
$lang
.email}:</td>
<td><input type=
"text"
name=
"email"
maxlength=
"60"
size=
"40"
value=
"{$user.email}"
/>{
$lang
.require_field}</td>
</tr>
|
在后面一行加入:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<tr>
<td width=
"28%"
align=
"right"
class
=
"label"
>会员头像:</td>
<td width=
"72%"
align=
"left"
bgcolor=
"#FFFFFF"
>
<div style=
"width:50%;float:left;"
>
<input id=
"avatar"
type=
"file"
size=
"40"
value=
""
name=
"avatar"
>
<br/>
<span style=
"color:#FF0000"
> 图片像素最佳为55px * 55px,<br/>大小不得超过1M</span>
</div>
<div style=
"width:50%;float:left;"
>
<img src=
"../{if $user.avatar}{$user.avatar}{else}images/avatar.gif{/if}"
alt=
""
width=
"55"
height=
"55"
>
</div>
</td>
</tr>
|
打开 admin\users.php
找到头部的
1
|
require
(dirname(
__FILE__
) .
'/includes/init.php'
);
|
在下面一行加入:
1
2
3
|
include_once
(ROOT_PATH .
'/includes/cls_image.php'
);
//会员头像 by neo
$image
=
new
cls_image(
$_CFG
[
'bgcolor'
]);
//会员头像 by neo
$allow_suffix
=
array
(
'gif'
,
'jpg'
,
'png'
,
'jpeg'
,
'bmp'
);
//会员头像 by neo
|
继续查找:
1
2
|
$sql
= "SELECT u.user_id, u.sex, u.birthday, u.pay_points, u.rank_points, u.user_rank , u.user_money, u.frozen_money, u.credit_line, u.parent_id, u2.user_name
as
parent_username, u.qq, u.msn,
u.office_phone, u.home_phone, u.mobile_phone".
|
修改为:
1
2
|
$sql
= "SELECT u.user_id, u.sex, u.birthday, u.pay_points, u.rank_points, u.user_rank , u.user_money, u.frozen_money, u.credit_line, u.parent_id, u2.user_name
as
parent_username, u.qq, u.msn,
u.office_phone, u.home_phone, u.mobile_phone, u.avatar".
//会员头像 by neo
|
继续查找:
1
|
$user
[
'mobile_phone'
] =
$row
[
'mobile_phone'
];
|
在后面一行加入:
1
|
$user
[
'avatar'
] =
$row
[
'avatar'
];
//会员头像 by neo
|
这样,后台编辑会员 就能看到会员的头像了。接下来,处理后台修改会员头像的提交逻辑处理
继续查找:
1
|
elseif
(
$_REQUEST
[
'act'
] ==
'update'
)
|
找到下面的:
1
|
$credit_line
=
empty
(
$_POST
[
'credit_line'
]) ? 0 :
floatval
(
$_POST
[
'credit_line'
]);
|
在下面一行加入:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
$user_id
=
empty
(
$_POST
[
'id'
]) ?
''
: trim(
$_POST
[
'id'
]);
//会员头像 by neo
/* 检查图片:如果有错误,检查尺寸是否超过最大值;否则,检查文件类型 */
if
(isset(
$_FILES
[
'avatar'
][
'error'
]))
// php 4.2 版本才支持 error
{
// 最大上传文件大小
$php_maxsize
=
ini_get
(
'upload_max_filesize'
);
$htm_maxsize
=
'1M'
;
// 会员头像
if
(
$_FILES
[
'avatar'
][
'error'
] == 0)
{
if
(!
$image
->check_img_type(
$_FILES
[
'avatar'
][
'type'
]))
{
sys_msg(
"图片格式不正确!"
, 1,
array
(), false);
}
}
elseif
(
$_FILES
[
'avatar'
][
'error'
] == 1)
{
sys_msg(sprintf(
'图片文件太大了(最大值:1M),无法上传。'
,
$php_maxsize
), 1,
array
(), false);
}
elseif
(
$_FILES
[
'avatar'
][
'error'
] == 2)
{
sys_msg(sprintf(
'图片文件太大了(最大值:1M),无法上传。'
,
$htm_maxsize
), 1,
array
(), false);
}
}
/* 4.1版本 */
else
{
// 会员头像
if
(
$_FILES
[
'avatar'
][
'tmp_name'
] !=
'none'
)
{
if
(!
$image
->check_img_type(
$_FILES
[
'avatar'
][
'type'
]))
{
sys_msg(
"图片格式不正确!"
);
}
}
}
//会员头像 by neo
if
(!
empty
(
$_FILES
[
'avatar'
][
'name'
]))
{
/* 更新会员头像之前先删除旧的头像 */
$sql
=
"SELECT avatar "
.
" FROM "
.
$GLOBALS
[
'ecs'
]->table(
'users'
) .
" WHERE user_id = '$user_id'"
;
$row
=
$GLOBALS
[
'db'
]->getRow(
$sql
);
if
(
$row
[
'avatar'
] !=
''
)
{
@unlink(
'../'
.
$row
[
'avatar'
]);
}
$img_name
=
$user_id
.
'.'
.
end
(
explode
(
'.'
,
$_FILES
[
'avatar'
][
'name'
]));
$target
= ROOT_PATH . DATA_DIR .
'/avatar/'
;
$original_img
=
$image
->upload_image(
$_FILES
[
'avatar'
],
'avatar'
,
$img_name
);
// 原始图片
$avatar
=
$image
->make_thumb(
'../'
.
$original_img
, 55, 55,
$target
);
if
(
$avatar
=== false)
{
sys_msg(
"图片保存出错!"
);
}
}
|
继续查找:
1
|
if
(!
$users
->edit_user(
array
(
'username'
=>
$username
,
'password'
=>
$password
,
'email'
=>
$email
,
'gender'
=>
$sex
,
'bday'
=>
$birthday
), 1))
|
修改为:
1
|
if
(!
$users
->edit_user(
array
(
'username'
=>
$username
,
'password'
=>
$password
,
'email'
=>
$email
,
'gender'
=>
$sex
,
'bday'
=>
$birthday
,
'avatar'
=>
$avatar
), 1))
//会员头像 by neo
|
OK,全部搞定!
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。