PublicController.php
1.6 KB
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
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace app\user\controller;
use cmf\controller\HomeBaseController;
use app\user\model\UserModel;
use think\Validate;
class PublicController extends HomeBaseController
{
// 用户头像api
public function avatar()
{
$id = $this->request->param("id", 0, "intval");
$user = UserModel::get($id);
$avatar = '';
if (!empty($user)) {
$avatar = cmf_get_user_avatar_url($user['avatar']);
if (strpos($avatar, "/") === 0) {
$avatar = $this->request->domain() . $avatar;
}
}
if (empty($avatar)) {
$cdnSettings = cmf_get_option('cdn_settings');
if (empty($cdnSettings['cdn_static_root'])) {
$avatar = $this->request->domain() . "/static/images/headicon.png";
} else {
$cdnStaticRoot = rtrim($cdnSettings['cdn_static_root'], '/');
$avatar = $cdnStaticRoot . "/static/images/headicon.png";
}
}
return redirect($avatar);
}
}