/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function testLoadJson(Request $request) { // return dd($request->all()); if (User::isSuperAdmin()) { $clients = Client::with(['getAdvertiser' => function ($q) { $q->select(DB::raw('*,count(client_id) as client_count'))->groupBy('client_id'); }])->get(); } else { $usr_comp = $this->user_company(); $clients = Client::with(['getAdvertiser' => function ($q) { $q->select(DB::raw('*,count(client_id) as client_count'))->groupBy('client_id'); }])->whereIn('user_id', $usr_comp)->get(); } $result = ''; foreach ($clients as $index) { if (count($index->getAdvertiser) > 0) { $index->setAttribute('advertiser', $index->getAdvertiser[0]->client_count); } else { $index->setAttribute('advertiser', '0'); } $action = "<a class='btn' href='" . url('/client/cl' . $index->id . '/edit') . "'>\n <img src='" . cdn('img/edit_16x16.png') . "' /> </a> |"; if (in_array('ADD_EDIT_ADVERTISER', $this->permission)) { $action .= "<a class='btn txt-color-white' href='" . url('client/cl' . $index->id . '/advertiser/add') . "'><img src='" . cdn('img/plus_16x16.png') . "'' /></a>"; } $index->setAttribute('action', $action); if ($index->status == 'Active') { $index->status = "<div class=\"switcher\"><input id=\"client{$index->id}\" onchange=\"ChangeStatus(`client`,`{$index->id}`)\" type=\"checkbox\" checked hidden><label for=\"client{$index->id}\"></label></div>"; } elseif ($index->status == 'Inactive') { $index->status = "<div class=\"switcher\"><input id=\"client{{$index->id}}\" onchange=\"ChangeStatus(`client`,`{$index->id}`)\" type=\"checkbox\" hidden><label for=\"client{$index->id}\"></label></div>"; } } return json_encode($clients); }
/** * show image and if not exist show a no-avatar.png * @param string $image * @param string $pathConfig */ function showAvatarImage($image, $pathConfig = '') { if ($image) { $image = Config::get($pathConfig) . $image; } else { $image = Config::get('app.image.no-avatar'); } return cdn($image); }
/** * Present a link to the user gravatar. */ public function gravatar($size = 80) { if (Config::get('app.url_static')) { //Using Qiniu image processing service. return cdn('uploads/avatars/' . $this->avatar) . "?imageView2/1/w/{$size}/h/{$size}"; } $github_id = $this->github_id; $domainNumber = rand(0, 3); return "https://avatars{$domainNumber}.githubusercontent.com/u/{$github_id}?v=2&s={$size}"; }
/** * Transform the \User entity. * * @param \User $model * * @return array */ public function transformData($model) { $user = array_only($model->toArray(), User::$includable); if ($model->getAttribute('avatar')) { $user['avatar'] = starts_with($model->avatar, 'http') ? $model->avatar : cdn('uploads/avatars/' . $model->avatar); } if ($model->getAttribute('links')) { $user['links'] = ['replies_web_view' => route('users.replies.web_view', $model->id)]; } return $user; }
function cached_asset(string $asset) : string { $realPath = public_path($asset); if (!file_exists($realPath)) { throw new InvalidArgumentException('File not found at ' . $realPath); } $hash = sprintf("%u", crc32(md5_file($realPath))); $extension = pathinfo($realPath, PATHINFO_EXTENSION); $stripped = substr($asset, 0, -(strlen($extension) + 1)); $path = implode('.', [$stripped, $hash, $extension]); return cdn($path); }
/** * 获取指定视频的相关信息 * * @param array $map * 查询条件 * @return array 指定视频的相关信息 */ private function _getMemberInfo($map, $field = "*") { $member = $this->where($map)->field($field)->find(); $avatarModel = D('Avatar'); $avatar = $avatarModel->getAvatar($member['uid']); if ($avatar) { $member['avatar'] = $avatar; } else { $member['avatar'] = cdn('default/avatar.jpg'); } S('member_info_' . $member['uid'], $member, 86400); return $member; }
/** * Present a link to the user gravatar. */ public function gravatar($size = 80) { if (Config::get('app.url_static')) { //Using Qiniu image processing service. return cdn('uploads/avatars/' . $this->avatar) . "?imageView2/1/w/{$size}/h/{$size}"; } if ($this->avatar == 'def_avatars.png') { $randnum = rand(0, 10); $randnum = sprintf("%02d", $randnum); $strAvatar = "Default/" . $randnum . "_avatar_max.jpg"; // $userid=$this->id; $User = User::findOrFail($this->id); $User->avatar = $strAvatar; $User->save(); return cdn('uploads/avatars/' . $strAvatar) . "?imageView2/1/w/{$size}/h/{$size}"; } return cdn('uploads/avatars/' . $this->avatar) . "?imageView2/1/w/{$size}/h/{$size}"; }
public function testLoadJson(Request $request) { // return dd($request->all()); if (User::isSuperAdmin()) { $company = Company::get(); } if ($company) { $result = ''; foreach ($company as $index) { $action = "<a class='btn' href='" . url('/company/' . $index->id . '/edit') . "'>\n <img src='" . cdn('img/edit_16x16.png') . "' /> </a> "; $index->setAttribute('action', $action); if ($index->status == 'Active') { $index->status = "<div class=\"switcher\"><input id=\"company{$index->id}\" onchange=\"ChangeStatus(`company`,`{$index->id}`)\" type=\"checkbox\" checked hidden><label for=\"company{$index->id}\"></label></div>"; } elseif ($index->status == 'Inactive') { $index->status = "<div class=\"switcher\"><input id=\"company{$index->id}\" onchange=\"ChangeStatus(`company`,`{$index->id}`)\" type=\"checkbox\" hidden><label for=\"company{$index->id}\"></label></div>"; } } return json_encode($company); } }
public function LoadJson(Request $request) { // return dd($request->all()); if (Auth::check()) { if (User::isSuperAdmin()) { $inventory = Inventory::get(); foreach ($inventory as $index) { $action = "<a class='btn' href='" . url('/inventory/' . $index->id . '/edit') . "'><img src='" . cdn('img/edit_16x16.png') . "'/></a>"; $index->setAttribute('action', $action); if ($index->status == 'Active') { $index->status = "<div class=\"switcher\"><input id=\"inventory{$index->id}\" onchange=\"ChangeStatus(`inventory`,`{$index->id}`)\" type=\"checkbox\" checked hidden><label for=\"inventory{$index->id}\"></label></div>"; } elseif ($index->status == 'Inactive') { $index->status = "<div class=\"switcher\"><input id=\"inventory{$index->id}\" onchange=\"ChangeStatus(`inventory`,`{$index->id}`)\" type=\"checkbox\" hidden><label for=\"inventory{$index->id}\"></label></div>"; } } return json_encode($inventory); } return Redirect::back()->withErrors(['success' => false, 'msg' => "You don't have permission"]); } return Redirect::to('/user/login'); }
public function initData() { DB::table('links')->truncate(); $links = [['title' => 'Ruby China', 'cover' => cdn('assets/images/friends/ruby-china.png'), 'link' => 'https://ruby-china.org'], ['title' => 'Golang 中国', 'cover' => cdn('assets/images/friends/golangcn.png'), 'link' => 'http://golangtc.com/'], ['title' => 'CNode:Node.js 中文社区', 'cover' => cdn('assets/images/friends/cnodejs.png'), 'link' => 'http://cnodejs.org/'], ['title' => 'F2E - 前端技术社区', 'cover' => cdn('assets/images/friends/f2e.png'), 'link' => 'http://f2e.im/']]; DB::table('links')->insert($links); }
public function avatar() { return cdn('uploads/avatars/' . $this->getWrappedObject()->avatar); }
/** * 支持的字段有 * 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; } //查询缓存,过滤掉已缓存的字段 $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 = M('UcenterMember'); $homeFields = $homeModel->getDbFields(); $ucenterFields = $ucenterModel->getDbFields(); $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(); //读取头像数据 if (in_array('avatar', $fields)) { $avatarModel = D('Home/Avatar'); $avatar = $avatarModel->getAvatar($uid); if ($avatar) { $result['avatar'] = $avatar; } else { $result['avatar'] = cdn('default/avatar.jpg'); } } //读取等级数据 if (in_array('title', $fields)) { $titleModel = D('Usercenter/Title'); $title = $titleModel->getTitle($uid); $result['title'] = $title; } //读取用户名拼音 if (in_array('pinyin', $fields)) { $result['pinyin'] = D('Pinyin')->pinYin($result['username']); } //获取个人中心地址 $spaceUrlResult = array(); if (in_array('space_url', $fields)) { $result['space_url'] = U('UserCenter/Index/index', array('uid' => $uid)); } //获取昵称链接 if (in_array('space_link', $fields)) { $result['space_link'] = '<a ucard="' . $uid . '" href="' . U('UserCenter/Index/index', array('uid' => $uid)) . '">' . $ucenterResult['username'] . '</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'] = getRootUrl() . 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>'; } //粉丝数、关注数、微博数 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('weibocount', $fields)) { $result['weibocount'] = D('Weibo')->where('uid=' . $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; } //↑↑↑ 新增字段应该写在在这行注释以上 ↑↑↑ //合并结果,不包括缓存 $result = array_merge($ucenterResult, $homeResult, $spaceUrlResult, $result); //写入缓存 foreach ($result as $field => $value) { if (in_array($field, array('icons_html', 'title', 'score'))) { continue; } if (!in_array($field, array('rank_link', 'icons_html', 'space_link'))) { $value = str_replace('"', '', op_t($value)); } $result[$field] = $value; write_query_user_cache($uid, $field, str_replace('"', '', $value)); } //合并结果,包括缓存 $result = array_merge($result, $cacheResult); //返回结果 return $result; }
public function uploadImage() { if ($file = \Request::file('file')) { $allowed_extensions = ["png", "jpg", "gif"]; if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) { return ['error' => 'You may only upload png, jpg or gif.']; } $fileName = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension() ?: 'png'; $folderName = '/uploads/images/' . date('Y', time()) . '/'; $destinationPath = public_path() . $folderName; $safeName = uniqid() . '.' . $extension; $file->move($destinationPath, $safeName); $filePath = $folderName . $safeName; $cdnPath = cdn($filePath); return ['filename' => $cdnPath]; } else { return ['error' => 'Error while uploading file']; } }
function requireJS($scripts, $dom) { // loop through the scripts foreach ($scripts as $name => $group) { //$first = current($group); $attr = $this->groupAttributes($group); // signature of file/group //$md5 = ( !empty( $attr['data']['md5'] ) ) ? $attr['data']['md5'] : false; // get file of the group if ($attr['data']['minify']) { $file = $GLOBALS['client']['require']['baseUrl'] . $name; //$file .= ( $md5 ) ? ".". $md5 .".min.js" : ".min.js"; $file .= ".js"; $file = cdn($file); } else { $file = $attr["src"]; } // if (!$attr['data']['require']) { // render a standard script tag $script = $dom->createElement('script'); $script->setAttribute("type", "text/javascript"); $script->setAttribute("src", $file); $script->setAttribute("defer", "defer"); // add the new script in the dom $dom = $this->updateDom($script, $dom); } else { // check the require parameters... if (!empty($attr['data']['path'])) { $name = $attr['data']['path']; } elseif ($attr['data']['minify']) { //$name = $name .".min"; //$name = $name; } // if there is a signature we'll have to create a new path for the group //if ( $md5 ){ // $GLOBALS['client']['require']['paths'][$name] = substr( $file, 0, -3); //} // push the name of the groups as the dependency array_push($GLOBALS['client']['require']['deps'], $name); if (!empty($attr['data']['path'])) { $GLOBALS['client']['require']['paths'][$attr['data']['path']] = substr($attr['src'], 0, -3); } // add the shim, if any if (!empty($attr['data']['deps'])) { $GLOBALS['client']['require']['shim'][$name] = is_array($attr['data']['deps']) ? $attr['data']['deps'] : array($attr['data']['deps']); } } } // return the DOM object return $dom; }