方维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头像上传功能。