方维O2O调用UCENTER头像的方法

调用头像:

app/lib/common.php:

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
//获取用户头像的文件名
function  get_user_avatar( $id , $type )
{
     if ( file_exists (APP_ROOT_PATH. "public/uc_config.php" ))
     {
         require_once  APP_ROOT_PATH. "public/uc_config.php" ;
     }
     if (app_conf( "INTEGRATE_CODE" )== 'Ucenter' )
     {
         $uid  $GLOBALS [ 'db' ]->getOne( "select integrate_id from " .DB_PREFIX. "user where id=" . $id );
         return  UC_API. "/avatar.php?uid=" . $uid . "&size=" . $type ;
     }
     $uid  = sprintf( "%09d" $id );
     $dir1  substr ( $uid , 0, 3);
     $dir2  substr ( $uid , 3, 2);
     $dir3  substr ( $uid , 5, 2);
     $path  $dir1 . '/' . $dir2 . '/' . $dir3 ;
                 
     $id  str_pad ( $id , 2,  "0" , STR_PAD_LEFT); 
     $id  substr ( $id ,-2);
     $avatar_file  = APP_ROOT. "/public/avatar/" . $path . "/" . $id . "virtual_avatar_" . $type . ".jpg" ;
     $avatar_check_file  = APP_ROOT_PATH. "public/avatar/" . $path . "/" . $id . "virtual_avatar_" . $type . ".jpg" ;
     if ( file_exists ( $avatar_check_file ))
     return  $avatar_file ;
     else
     return  APP_ROOT. "/public/avatar/noavatar_" . $type . ".gif" ;
     //@file_put_contents($avatar_check_file,@file_get_contents(APP_ROOT_PATH."public/avatar/noavatar_".$type.".gif"));
}

也就是增加检测uc_config.php是否存在及是否启用ucenter的判定,如果启用了ucenter则返回ucenter的头像地址,未启用ucenter的正常使用方维O2O头像。

 

修改头像:

app/tpl/fanwe/inc/uc/uc_account_index.html:

1
< img  id = "avatar"  src = "{function name=" get_user_avatar" uid=$user_info.id  type = "big" }" />

前加入以下代码:

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
<?php
     //使用UCENTER的头像上传(整个UCENTER系统使用同一头像)
     if ( file_exists (APP_ROOT_PATH. "public/uc_config.php" ))
     {
         require_once  APP_ROOT_PATH. "public/uc_config.php" ;
     }
     if (app_conf( "INTEGRATE_CODE" )== 'Ucenter' )
     {
         if ( file_exists (APP_ROOT_PATH. "uc_client/client.php" ))
         {
             require_once  APP_ROOT_PATH. "uc_client/client.php" ;
             $uid  $GLOBALS [ 'db' ]->getOne( "select integrate_id from " .DB_PREFIX. "user where id=" . $this ->_var[ 'user_info' ][ 'id' ]);
             echo  "<div style='display:none;' id='uc_avatar'>" .uc_avatar( $uid ). "</div>" ;
             $this ->_var[ 'is_uc_avatar' ] = 1;
             ?>
             <script type= "text/javascript" >
             function  updateavatar(){
                 window.location.reload();
            
             function  uc_avatar(){
                 $.weeboxs.open( '#uc_avatar' ,{contentType: 'ajax' ,showButton:false,title: '修改头像' ,width:480,type: 'wee' });
             }
             </script>
             <?php
         }
     }
?>

并修改

1
< label  class = "fileupload"  onclick = "upd_file(this,'avatar_file',{$user_info.id});" >

为:

1
< label  class = "fileupload"  onclick = "{if $is_uc_avatar eq 1}uc_avatar();return false;{else}upd_file(this,'avatar_file',{$user_info.id});{/if}" >

即可。

启用ucenter即将个人中心上传头像按钮修改为ucenter的头像上传,不启用ucenter则使用方维O2O头像上传功能。

转载于:https://www.cnblogs.com/murongshuai/p/4626073.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值