西部数码主机 | 阿里云主机| 虚拟主机 | 服务器 | 返回乐道官网
当前位置: 主页 > php教程 > ecshop教程 >

ecshop开发上传与评论显示会员头像(2)

时间:2016-04-26 22:01来源:未知 作者:好模板 点击:
第六步: 打开 includes\lib_transaction.php 文件 找到: if (!$GLOBALS[user]-edit_user($cfg)) 在前面一行增加: //会员头像if (!empty($profile[avatar])){ $cfg[avatar] = $profile[ava

第六步:

打开 includes\lib_transaction.php 文件

找到:

if (!$GLOBALS['user']->edit_user($cfg))

在前面一行增加:

//会员头像
if (!empty($profile['avatar']))
{
    $cfg['avatar'] = $profile['avatar'];
}

继续查找:

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'";

修改为:

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'";

继续查找:

$info['birthday']    = isset($infos['birthday']) ? $infos['birthday'] : '';

在下面加入:

$info['avatar']      = isset($infos['avatar']) ? $infos['avatar'] : '';//会员头像 by neo

第七步:

打开 includes\modules\integrates\integrate.php

查找:

var $error          = 0;

下面一行加入:

/* 会员头像 by neo */
var $field_avatar = '';

继续查找:

if ((!empty($cfg['bday'])) && $this->field_bday != 'NULL')
{
    $values[] = $this->field_bday . "='" . $cfg['bday'] . "'";
}

在下面一行加入:

//会员头像 by neo
if ((!empty($cfg['avatar'])) && $this->field_avatar != 'NULL')
{
    $values[] = $this->field_avatar . "='" . $cfg['avatar'] . "'";
}

第八步:

打开 includes\modules\integrates\ecshop.php

查找:

$this->field_reg_date = 'reg_time';

下面一行加入:

$this->field_avatar = 'avatar';//会员头像 by neo

至此,前台显示及上传就OK了!

评论加入头像显示

打开 includes/lib_main.php 找到

function assign_comment($id, $type, $page = 1)

在该函数里面找到:

$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';

修改成:

$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

继续查找:

$arr[$row['comment_id']]['add_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);

在下面一行加入:

$arr[$row['comment_id']]['avatar']     = $row['avatar'];//会员头像 by neo

评论模板调用方法:

打开 themes/default/library/comments_list.lbi

查找:

<!-- {foreach from=$comments item=comment} -->

在foreach内容下面合适位置使用以下代码中用头像:

<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

查找:

<form method="post" action="users.php" name="theForm" onsubmit="return validate()">

修改为:

<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图片上传大小设置 -->

继续查找:

<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>

在后面一行加入:

<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

找到头部的 

require(dirname(__FILE__) . '/includes/init.php');

在下面一行加入:

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

继续查找:

$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".

修改为:

$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

继续查找:

$user['mobile_phone']   = $row['mobile_phone'];

在后面一行加入:

$user['avatar']           = $row['avatar'];//会员头像 by neo

这样,后台编辑会员 就能看到会员的头像了。接下来,处理后台修改会员头像的提交逻辑处理

继续查找:

elseif ($_REQUEST['act'] == 'update')

找到下面的:

$credit_line = empty($_POST['credit_line']) ? 0 : floatval($_POST['credit_line']);

在下面一行加入:

$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("图片保存出错!");
        }
    }

继续查找:

if (!$users->edit_user(array('username'=>$username, 'password'=>$password, 'email'=>$email, 'gender'=>$sex, 'bday'=>$birthday ), 1))

修改为:

if (!$users->edit_user(array('username'=>$username, 'password'=>$password, 'email'=>$email, 'gender'=>$sex, 'bday'=>$birthday, 'avatar'=>$avatar ), 1))//会员头像 by neo

OK,全部搞定

(责任编辑:好模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
热点内容