博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
方维O2O调用UCENTER头像的方法
阅读量:7153 次
发布时间:2019-06-29

本文共 2697 字,大约阅读时间需要 8 分钟。

调用头像:

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

你可能感兴趣的文章
【CF】328 D. Super M
查看>>
Nodejs Guides(二)
查看>>
EL表达式
查看>>
本地计算机 上的 MySQL 服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止。...
查看>>
调用系统拍照
查看>>
Java——IO之常量及路径
查看>>
NSUserDefaults保存应用中的数据
查看>>
用Gvim建立IDE编程环境 (Windows篇)_Nothing is impossible for a willing heart._百度空间...
查看>>
poj 1386 Play on Words
查看>>
到了最后出现败笔
查看>>
Chrome 插件
查看>>
《Effective C#》读书笔记——条目24:用委托实现回调<使用C#表达设计>
查看>>
c++的重载,覆盖与隐藏
查看>>
How to make a combo box with fulltext search autocomplete support?
查看>>
大数据的三个入口
查看>>
void指针
查看>>
基本类型赋值转换规则表
查看>>
hackerrank-knapsack
查看>>
取消word中所有超链接
查看>>
AABB边框、OBB边框、通过比较球包围
查看>>