/** * 文件上传 * @param array $files 要上传的文件列表(通常是$_FILES数组) * @param array $setting 文件上传配置 * @param string $driver 上传驱动名称 * @param array $config 上传驱动配置 * @return array 文件上传成功后的信息 */ public function upload($files, $setting, $driver = 'Local', $config = null) { /* 上传文件 */ $setting['callback'] = array($this, 'isFile'); $setting['removeTrash'] = array($this, 'removeTrash'); $Upload = new Upload($setting, $driver, $config); foreach ($files as $key => $file) { $ext = strtolower($file['ext']); if (in_array($ext, array('jpg', 'jpeg', 'bmp', 'png'))) { hook('dealPicture', $file['tmp_name']); } } $info = $Upload->upload($files); if ($info) { //文件上传成功,记录文件信息 foreach ($info as $key => &$value) { /* 已经存在文件记录 */ if (isset($value['id']) && is_numeric($value['id'])) { continue; } /* 记录文件信息 */ if (strtolower($driver) == 'sae') { $value['path'] = $config['rootPath'] . 'Picture/' . $value['savepath'] . $value['savename']; //在模板里的url路径 } else { if (strtolower($driver) == 'qiniu') { $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename']; } elseif (strtolower($driver) != 'local') { $value['path'] = $value['url']; } else { $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename']; //在模板里的url路径 } } $value['type'] = strtolower($driver); if ($this->create($value) && ($id = $this->add())) { $value['id'] = $id; } else { //TODO: 文件上传成功,但是记录文件信息失败,需记录日志 unset($info[$key]); } } foreach ($info as &$t_info) { if ($t_info['type'] == 'local') { $t_info['path'] = fixAttachUrl($t_info['path']); } else { $t_info['path'] = $t_info['path']; } } /* dump(getRootUrl()); dump($info); exit;*/ return $info; //文件上传成功 } else { $this->error = $Upload->getError(); return false; } }
public function friendLink($param) { $list = D('Addons://SuperLinks/SuperLinks')->linkList(); foreach ($list['picture'] as &$img) { $img['path'] = fixAttachUrl($img['path']); } $this->assign('list', $list); $this->assign('link', $param); $this->display('widget'); }
public function imageSlider($param) { $config = $this->getConfig(); if ($config['images']) { $images = M("Picture")->field('id,path')->where("id in ({$config['images']})")->select(); $this->assign('urls', explode("\r\n", $config['url'])); foreach ($images as &$img) { $img['path'] = fixAttachUrl($img['path']); } unset($img); $this->assign('images', $images); $config['imgWidth'] = $config['imgWidth'] + 8; $config['imgHeight'] = $config['imgHeight'] + 8; $this->assign('config', $config); $this->display('content'); } }
/** * 文件上传 * @param array $files 要上传的文件列表(通常是$_FILES数组) * @param array $setting 文件上传配置 * @param string $driver 上传驱动名称 * @param array $config 上传驱动配置 * @return array 文件上传成功后的信息 */ public function upload($files, $setting, $driver = 'Local', $config = null) { /* 上传文件 */ $setting['callback'] = array($this, 'isFile'); $setting['removeTrash'] = array($this, 'removeTrash'); $Upload = new Upload($setting, $driver, $config); $info = $Upload->upload($files); if ($info) { //文件上传成功,记录文件信息 foreach ($info as $key => &$value) { /* 已经存在文件记录 */ if (isset($value['id']) && is_numeric($value['id'])) { continue; } /* 记录文件信息 */ if (strtolower($driver) == 'sae') { $value['path'] = $config['rootPath'] . 'Picture/' . $value['savepath'] . $value['savename']; //在模板里的url路径 } else { $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename']; //在模板里的url路径 } if ($this->create($value) && ($id = $this->add())) { $value['id'] = $id; } else { //TODO: 文件上传成功,但是记录文件信息失败,需记录日志 unset($info[$key]); } } foreach ($info as $key => $t_info) { $info[$key]['path'] = fixAttachUrl($t_info['path']); } return $info; //文件上传成功 } else { // $this->error = $Upload->getError(); return false; } }
/** * 获取文档封面图片 * @param int $cover_id * @param string $field * @return 完整的数据 或者 指定的$field字段值 * @author huajie <*****@*****.**> */ function get_cover($cover_id, $field = null) { if (empty($cover_id)) { return false; } $picture = M('Picture')->where(array('status' => 1))->getById($cover_id); if (is_bool(strpos($picture['path'], 'http://'))) { $picture['path'] = fixAttachUrl($picture['path']); } return empty($field) ? $picture : $picture[$field]; }
/** * 支持的字段有 * member表中的所有字段,ucenter_member表中的所有字段 * 等级:title * 头像:avatar32 avatar64 avatar128 avatar256 avatar512 * 个人中心地址:space_url * 认证图标:icons_html * * @param $fields array|string 如果是数组,则返回数组。如果不是数组,则返回对应的值 * @param null $uid * @return array|null */ function query_user($fields, $uid = null) { //如果fields不是数组,则返回值也不是数组 if (!is_array($fields)) { $result = query_user(array($fields), $uid); return $result[$fields]; } //默认获取自己的资料 $uid = $uid ? $uid : is_login(); if (!$uid) { return null; } //获取两张用户表格中的所有字段 $homeModel = M('Member'); $ucenterModel = M('UcenterMember'); $homeFields = $homeModel->getDbFields(); $ucenterFields = $ucenterModel->getDbFields(); //分析每个表格分别要读取哪些字段 $avatarFields = array('avatar32', 'avatar64', 'avatar128', 'avatar256', 'avatar512'); $avatarFields = array_intersect($avatarFields, $fields); $homeFields = array_intersect($homeFields, $fields); $ucenterFields = array_intersect($ucenterFields, $fields); //查询需要的字段 $homeResult = array(); $ucenterResult = array(); if ($homeFields) { $homeResult = D('Home/Member')->where(array('uid' => $uid))->field($homeFields)->find(); } if ($ucenterFields) { $model = D('User/UcenterMember'); $ucenterResult = $model->where(array('id' => $uid))->field($ucenterFields)->find(); } //读取头像数据 $result = array(); $avatarAddon = new \Addons\Avatar\AvatarAddon(); foreach ($avatarFields as $e) { $avatarSize = intval(substr($e, 6)); $avatarUrl = $avatarAddon->getAvatarPath($uid, $avatarSize); $result[$e] = $avatarUrl; } //读取等级数据 if (in_array('title', $fields)) { $titleModel = D('Usercenter/Title'); $title = $titleModel->getTitle($uid); $result['title'] = $title; } if (in_array('supportnum', $fields)) { $result['supportnum']; } if (in_array('commentnum', $fields)) { $result['commentnum']; } if (in_array('allartnum', $fields)) { $artnum = M('Article')->where(array('uid' => $uid))->count(); $result['allartnum'] = empty($artnum) ? 0 : $artnum; } if (in_array('artnum', $fields)) { $artnum = M('Article')->where(array('uid' => $uid, 'status' => 1))->count(); $result['artnum'] = empty($artnum) ? 0 : $artnum; } if (in_array('focusnum', $fields)) { $mapfocusnum['id'] = $uid; $mapfocusnum['type'] = 0; $result['focusnum'] = D('Focus')->where($mapfocusnum)->count(); } if (in_array('scartnum', $fields)) { $mapscartnum['id'] = $uid; $mapscartnum['type'] = 1; $result['scartnum'] = D('Focus')->where($mapscartnum)->count(); } if (in_array('tagfocusnum', $fields)) { $maptagfocusnum['id'] = $uid; $maptagfocusnum['type'] = 2; $result['tagfocusnum'] = D('Focus')->where($maptagfocusnum)->count(); } if (in_array('zan', $fields)) { $zannum = M('Article')->where(array('uid' => $uid))->sum('ding'); $result['zan'] = empty($zannum) ? 0 : $zannum; } //读取用户名拼音 if (in_array('pinyin', $fields)) { $result['pinyin'] = D('Pinyin')->pinYin($result['nickname']); } //获取个人中心地址 $spaceUrlResult = array(); if (in_array('space_url', $fields)) { $result['space_url'] = CSU('/userart/' . $uid, 'Ucenter/userart', array('uid' => $uid)); } $ucenterResult['nickname'] = op_t($ucenterResult['nickname']); //获取昵称链接 if (in_array('space_link', $fields)) { $result['space_link'] = '<a ucard="' . $uid . '" href="' . CSU('/userart/' . $uid, 'Ucenter/userart', array('uid' => $uid)) . '">' . $ucenterResult['nickname'] . '</a>'; } //获取用户头衔链接 if (in_array('rank_link', $fields)) { $rank_List = D('rank_user')->where('uid=' . $uid)->select(); $num = 0; foreach ($rank_List as &$val) { $rank = D('rank')->where('id=' . $val['rank_id'])->find(); $val['title'] = $rank['title']; $val['logo_url'] = fixAttachUrl(D('picture')->where('id=' . $rank['logo'])->getField('path')); if ($val['is_show']) { $num = 1; } } if ($rank_List) { $rank_List[0]['num'] = $num; $result['rank_link'] = $rank_List; } else { $result['rank_link'] = array(); } } if (in_array('signature', $fields)) { $result['signature'] = D('Home/Member')->where(array('uid' => $uid))->field($homeFields)->getField('signature'); if ($result['signature'] == null) { $result['signature'] = '暂无个人签名'; } } //获取用户认证图标 if (in_array('icons_html', $fields)) { //判断是否有手机图标 $static = C('TMPL_PARSE_STRING.__STATIC__'); $iconUrls = array(); $user = query_user(array('mobile'), $uid); if ($user['mobile']) { $iconUrls[] = "{$static}/images/mobile-bind.png"; } //生成结果 $result['icons_html'] = '<span class="usercenter-verify-icon-list">'; foreach ($iconUrls as $e) { $result['icons_html'] .= "<img src=\"{$e}\" title=\"对方已绑定手机\"/>"; } $result['icons_html'] .= '</span>'; } //粉丝数、关注数 if (in_array('fensi', $fields)) { $mapfensi['rowid'] = $uid; $mapfensi['type'] = 0; $result['fensi'] = D('Focus')->where($mapfensi)->count(); } //↑↑↑ 新增字段应该写在在这行注释以上 ↑↑↑ //合并结果,不包括缓存 $result = array_merge($ucenterResult, $homeResult, $spaceUrlResult, $result); //返回结果 return $result; }
/** * 支持的字段有 * member表中的所有字段,ucenter_member表中的所有字段 * 等级:title * 头像:avatar32 avatar64 avatar128 avatar256 avatar512 * 个人中心地址:space_url * 认证图标:icons_html * * @param $fields array|string 如果是数组,则返回数组。如果不是数组,则返回对应的值 * @param null $uid * @return array|null */ function query_user($fields = null, $uid = null) { if ($fields === null) { $fields = array('nickname', 'space_url', 'avatar64', 'avatar128', 'uid'); } //如果fields不是数组,则返回值也不是数组 if (!is_array($fields)) { $result = query_user(array($fields), $uid); return $result[$fields]; } if (in_array('score', $fields)) { $fields[] = 'score1'; } //默认获取自己的资料 $uid = $uid ? $uid : is_login(); if (!$uid) { return null; } //查询缓存,过滤掉已缓存的字段 $cachedFields = array(); $cacheResult = array(); foreach ($fields as $field) { if (in_array($field, array('icons_html', 'title', 'score'))) { continue; } $cache = read_query_user_cache($uid, $field); if (!empty($cache)) { $cacheResult[$field] = $cache; $cachedFields[] = $field; } } //去除已经缓存的字段 $fields = array_diff($fields, $cachedFields); //获取两张用户表格中的所有字段 $homeModel = M('Member'); $ucenterModel = UCenterMember(); $homeFields = $homeModel->getDbFields(); $ucenterFields = $ucenterModel->getDbFields(); //分析每个表格分别要读取哪些字段 $avatarFields = array('avatar32', 'avatar64', 'avatar128', 'avatar256', 'avatar512'); $avatarFields = array_intersect($avatarFields, $fields); $homeFields = array_intersect($homeFields, $fields); $ucenterFields = array_intersect($ucenterFields, $fields); //查询需要的字段 $homeResult = array(); $ucenterResult = array(); if ($homeFields) { $homeResult = D('Home/Member')->where(array('uid' => $uid))->field($homeFields)->find(); } if ($ucenterFields) { $model = UCenterMember(); $ucenterResult = $model->where(array('id' => $uid))->field($ucenterFields)->find(); } //读取头像数据 $result = array(); $avatarObject = new \Ucenter\Widget\UploadAvatarWidget(); foreach ($avatarFields as $e) { $avatarSize = intval(substr($e, 6)); $avatarUrl = $avatarObject->getAvatar($uid, $avatarSize); $check = file_exists('./api/uc_login.lock'); if ($check) { include_once './api/uc_client/client.php'; $avatarUrl = UC_API . '/avatar.php?uid=' . $uid . '&size=big'; } $result[$e] = $avatarUrl; } //读取等级数据 if (in_array('title', $fields)) { $titleModel = D('Ucenter/Title'); $title = $titleModel->getTitle($uid); $result['title'] = $title; } //读取用户名拼音 if (in_array('pinyin', $fields)) { $result['pinyin'] = D('Pinyin')->pinYin($result['nickname']); } //获取个人中心地址 $spaceUrlResult = array(); if (in_array('space_url', $fields)) { $result['space_url'] = U('Ucenter/Index/index', array('uid' => $uid)); } if (in_array('nickname', $fields)) { $ucenterResult['nickname'] = op_t($ucenterResult['nickname']); } //获取昵称链接 if (in_array('space_link', $fields)) { if (!$ucenterResult['nickname']) { $res = query_user(array('nickname'), $uid); $ucenterResult['nickname'] = $res['nickname']; } $result['space_link'] = '<a ucard="' . $uid . '" target="_blank" href="' . U('Ucenter/Index/index', array('uid' => $uid)) . '">' . $ucenterResult['nickname'] . '</a>'; } //获取用户头衔链接 if (in_array('rank_link', $fields)) { $rank_List = D('rank_user')->where(array('uid' => $uid, 'status' => 1))->select(); $num = 0; foreach ($rank_List as &$val) { $rank = D('rank')->where('id=' . $val['rank_id'])->find(); $val['title'] = $rank['title']; $val['logo_url'] = fixAttachUrl(D('picture')->where('id=' . $rank['logo'])->getField('path')); if ($val['is_show']) { $num = 1; } } if ($rank_List) { $rank_List[0]['num'] = $num; $result['rank_link'] = $rank_List; } else { $result['rank_link'] = array(); } } //获取用户认证图标 if (in_array('icons_html', $fields)) { //判断是否有手机图标 $static = C('TMPL_PARSE_STRING.__STATIC__'); $iconUrls = array(); $user = query_user(array('mobile'), $uid); if ($user['mobile']) { $iconUrls[] = "{$static}/oneplus/images/mobile-bind.png"; } //生成结果 $result['icons_html'] = '<span class="usercenter-verify-icon-list">'; foreach ($iconUrls as $e) { $result['icons_html'] .= "<img src=\"{$e}\" title=\"对方已绑定手机\"/>"; } $result['icons_html'] .= '</span>'; } //expand_info:用户扩展字段信息 if (in_array('expand_info', $fields)) { $map['status'] = 1; $field_group = D('field_group')->where($map)->select(); $field_group_ids = array_column($field_group, 'id'); $map['profile_group_id'] = array('in', $field_group_ids); $fields_list = D('field_setting')->where($map)->getField('id,field_name,form_type,visiable'); $fields_list = array_combine(array_column($fields_list, 'field_name'), $fields_list); $map_field['uid'] = $uid; foreach ($fields_list as $key => $val) { $map_field['field_id'] = $val['id']; $field_data = D('field')->where($map_field)->getField('field_data'); if ($field_data == null || $field_data == '') { unset($fields_list[$key]); } else { if ($val['form_type'] == "checkbox") { $field_data = explode('|', $field_data); } $fields_list[$key]['data'] = $field_data; } } $result['expand_info'] = $fields_list; } //粉丝数、关注数、微博数 if (in_array('fans', $fields)) { $result['fans'] = D('Follow')->where('follow_who=' . $uid)->count(); } if (in_array('following', $fields)) { $result['following'] = D('Follow')->where('who_follow=' . $uid)->count(); } //是否关注、是否被关注 if (in_array('is_following', $fields)) { $follow = D('Follow')->where(array('who_follow' => get_uid(), 'follow_who' => $uid))->find(); $result['is_following'] = $follow ? true : false; } if (in_array('is_followed', $fields)) { $follow = D('Follow')->where(array('who_follow' => $uid, 'follow_who' => get_uid()))->find(); $result['is_followed'] = $follow ? true : false; } //TODO 在此加入扩展字段的处理钩子 //↑↑↑ 新增字段应该写在在这行注释以上 ↑↑↑ //合并结果,不包括缓存 $result = array_merge($ucenterResult, $homeResult, $spaceUrlResult, $result); //写入缓存 foreach ($result as $field => $value) { if (in_array($field, array('icons_html', 'title', 'score', 'tox_money'))) { continue; } if (!in_array($field, array('rank_link', 'icons_html', 'space_link', 'expand_info'))) { $value = str_replace('"', '', op_t($value)); } $result[$field] = $value; write_query_user_cache($uid, $field, str_replace('"', '', $value)); } //合并结果,包括缓存 $result = array_merge($result, $cacheResult); $result['score'] = $result['score1']; //返回结果 return $result; }
/** * @param $fields * @param $uid * @param $val * @param $result * @return array */ public function getRankLink($fields, $uid, $val, $result) { //获取用户头衔链接 if (in_array('rank_link', $fields)) { $rank_List = D('rank_user')->where(array('uid' => $uid, 'status' => 1))->select(); $num = 0; foreach ($rank_List as &$val) { $rank = M('rank')->where('id=' . $val['rank_id'])->find(); $val['title'] = $rank['title']; $val['logo_url'] = fixAttachUrl(M('picture')->where('id=' . $rank['logo'])->field('path')->getField('path')); if ($val['is_show']) { $num = 1; } } if ($rank_List) { $rank_List[0]['num'] = $num; $result['rank_link'] = $rank_List; return array($val, $result); } else { $result['rank_link'] = array(); return array($val, $result); } } return array($val, $result); }