Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: rhyshah
- * Date: 7/27/16
- * Time: 6:50 PM
- */
- use Freemig\Social\Repositories\FriendRepository;
- use Freemig\Social\Models\Friend;
- use Freemig\Social\Models\FriendGroup;
- use Freemig\Social\Models\FriendRequest;
- use Freemig\Profile\Models\User;
- use Freemig\Profile\Repositories\UserRepository;
- if (!function_exists('getUserInfo')) {
- /**
- * Get / set the specified configuration value.
- *
- * If an array is passed as the key, we will assume you want to set an array of values.
- *
- * @param array|string $key
- * @param mixed $default
- * @return mixed
- */
- function getUserInfo($userId = null)
- {
- if (is_null($userId)) {
- return false;
- }
- $user = new \Freemig\Profile\Repositories\UserRepository(new \Freemig\Profile\Models\User());
- return $user->getUserById($userId);
- }
- }
- if (!function_exists('thisUser')) {
- /**
- * Get / set the specified configuration value.
- *
- * If an array is passed as the key, we will assume you want to set an array of values.
- *
- * @param array|string $key
- * @param mixed $default
- * @return mixed
- */
- function thisUser()
- {
- $userInfo = [
- 'id' => session('userId'),
- 'username' => session('username'),
- 'avatar' => session('profileAvatar')
- ];
- return $userInfo;
- }
- }
- function getProfileCompleteness($userId = null)
- {
- if (is_null($userId)) {
- return false;
- }
- return 0;
- }
- function getTotalCredit($userId = null)
- {
- if (is_null($userId)) {
- return false;
- }
- return 0;
- }
- function get_new_post_template_params($postId)
- {
- $p = new \Freemig\Social\Repositories\PostRepository(new \Freemig\Social\Models\Post(), new \Freemig\Social\Models\Comment());
- $c = new \Freemig\Social\Repositories\CommentRepository(new \Freemig\Social\Models\Comment());
- $l = new \Freemig\Social\Repositories\LikeRepository(new \Freemig\Social\Models\Like());
- $s = new \Freemig\Social\Repositories\ShareRepository(new \Freemig\Social\Models\Share());
- $pf = new \Freemig\Profile\Repositories\UserRepository(new \Freemig\Profile\Models\User());
- //$pg = new PageRepo(new page_category, new pageInfo,new freemigBlog,new freemigEvent,new pageSettings, new pageUser, new PageFriend, new pagesMediaFile());
- $v = $p->getSinglePostByPostId($postId)->toArray();
- $data['post'] = $p->formatPost($v);
- $data['post']['attributes'] = json_decode($v['attributes'], true);
- $data['post']['userInfo'] = $pf->getUserByIdMinimum($v['user_id']);
- /*if($data['post']['owner_type']=='1' && $data['post']['by_owner'] =='1') {
- $data['post']['userInfo'] = $pf->getUserByIdMinimum($v['user_id']);
- }
- else if($data['post']['owner_type']=='1' && $data['post']['by_owner'] =='0') {
- $data['post']['userInfo'] = $pf->getUserByIdMinimum($v['friends_id']);
- }
- else if($data['post']['owner_type']=='2' && $data['post']['by_owner'] =='1') {
- $data['post']['userInfo'] = $pf->getUserByIdMinimum($v['user_id']);
- }
- else if($data['post']['owner_type']=='2' && $data['post']['by_owner'] =='0') {
- $data['post']['userInfo'] = $pg->singlePageInfoShow($v['friends_id']);
- }*/
- $created_at = '';
- $create_at_format = formatDateTime($data['post']['created_at']);
- if ($create_at_format['diff'] < 21) {
- $created_at = $create_at_format['diffForHumans'];
- } else {
- $created_at = $create_at_format['format'];
- }
- $updated_at = '';
- $updated_at_format = formatDateTime($data['post']['updated_at']);
- if ($updated_at_format['diff'] < 21) {
- $updated_at = $updated_at_format['diffForHumans'];
- } else {
- $updated_at = $updated_at_format['format'];
- }
- $data['post']['created_at'] = $created_at;
- $data['post']['updated_at'] = $updated_at;
- $data['comments'] = $c->getPostComments($v['id']);
- $data['likes'] = $l->getPostLikes($v['id']);
- $shares = $s->getPostSharesCustomized($v['id']); //dump($data['shares']);
- $data['shares'] = $shares[0];
- $data['share_more'] = ($shares[0] > 5) ? ($shares[0] - 5) : 0;
- $data['sharedProfiles'] = $shares[1];
- return $data;
- }
- function get_comment_template_html($commentId)
- {
- $mComment = new \Freemig\Social\Models\Comment();
- $rUser = new \Freemig\Profile\Repositories\UserRepository(new \Freemig\Profile\Models\User());
- $rProfile = new \Freemig\Profile\Repositories\ProfileRepository(new \Freemig\Profile\Models\Profile());
- $contentInfo = $mComment->where(['id' => $commentId])->get()->toArray();
- $c = new \Freemig\Social\Repositories\CommentRepository(new \Freemig\Social\Models\Comment());
- $created_at = '';
- $create_at_format = formatDateTime($contentInfo[0]['created_at']);;
- if ($create_at_format['diff'] < 21) {
- $created_at = $create_at_format['diffForHumans'];
- } else {
- $created_at = $create_at_format['format'];
- }
- $updated_at = '';
- $updated_at_format = formatDateTime($contentInfo[0]['updated_at']);
- if ($create_at_format['diff'] < 21) {
- $updated_at = $updated_at_format['diffForHumans'];
- } else {
- $updated_at = $updated_at_format['format'];
- }
- $data['originator'] = $rUser->getUserByIdMinimum(Session::get('userId'));
- $data['oriProfileInfo'] = $rProfile->getProfileMinimum(Session::get('userId'));
- $data['content'] = $contentInfo[0];
- $data['content']['created_at'] = $created_at;
- $data['content']['updated_at'] = $updated_at;
- $data['content']['likeCount'] = 0;
- $data['content']['replyCount'] = 0;
- $data['content']['dislikeCount'] = 0;
- $data['session_user'] = session('userId');
- if (count($contentInfo[0]['parent_post_id']) > 0 && !empty($contentInfo[0]['parent_post_id'])) {
- $html = array(
- 'data' => $data,
- 'type' => 'replyComment'
- );
- // $html = \View::make('svrs-handlebars.reply_comment_single',$data)->render();
- } else {
- $html = array(
- 'data' => $data,
- 'type' => 'comment'
- );
- // $html = \View::make('svrs-handlebars.comment_single',$data)->render();
- }
- return $html;
- }
- function getChatWidget()
- {
- $rFriends = new \Freemig\Social\Repositories\FriendRepository(new \Freemig\Social\Models\Friend(), new \Freemig\Social\Models\FriendRequest(), new \Freemig\Social\Models\FriendGroup());
- $users = $rFriends->getFriendsDistinctbyGroups(\Session::get('userId'));
- $pf = new \Freemig\Profile\Repositories\UserRepository(new \Freemig\Profile\Models\User());
- $onlineUsers = [];
- foreach ($users as $k => $v) {
- $onlineUsers[] = $pf->getUserByIdMinimum($v['friend_id']);
- }
- $html = \View::make('common.gadget.onlineChat', ['users' => $onlineUsers, 'user' => $pf->getUserByIdMinimum(\Session::get('userId'))])->render();
- return $html;
- }
- function formatDateTime($input_date)
- {
- $formated_date = [];
- $parsed_date = \Carbon\Carbon::parse($input_date);
- $formated_date['format'] = $parsed_date->format('d M Y H:i A');
- $formated_date['diff'] = $parsed_date->diffInHours(\Carbon\Carbon::now(), false);
- $formated_date['diffForHumans'] = $parsed_date->diffForHumans();
- return $formated_date;
- }
- function formatDate($input_date)
- {
- $formated_date = [];
- $parsed_date = \Carbon\Carbon::parse($input_date);
- $formated_date['format'] = $parsed_date->format('d M, Y');
- $formated_date['diff'] = $parsed_date->diffInHours(\Carbon\Carbon::now(), false);
- $formated_date['diffForHumans'] = $parsed_date->diffForHumans();
- return $formated_date;
- }
- function suggest($type)
- {
- switch ($type) {
- case 'user':
- $mUser = new \Freemig\Profile\Models\User();
- $users = $mUser->all()->toArray();
- $rv = [];
- foreach ($users as $user) {
- unset($user['password']);
- $pf = new \Freemig\Profile\Repositories\UserRepository(new \Freemig\Profile\Models\User());
- $user['mprofile'] = $pf->getUserByIdMinimum($user['id']);
- $rv[] = $user;
- }
- return $rv;
- break;
- case 'user':
- break;
- }
- }
- function suggest_mysql($type)
- {
- switch ($type) {
- case 'user':
- $rv = [];
- $friends = new \Freemig\Social\Models\Friend();
- $notIn = $friends->where('user_id', '=', \Session::get('userId'))->where('connection_type', 1)->get(['friend_id']);
- $notIn[] = \Session::get('userId');
- $users = \Freemig\Profile\Models\User::whereNotIn('id', $notIn)->where('is_active', '=', 1)->get()->toArray();
- foreach ($users as $u) {
- unset($u['password']);
- $rv[] = $u;
- }
- return $rv;
- break;
- case 'user':
- break;
- }
- }
- function suggest_es($q)
- {
- $input = $q;
- $searchParams['index'] = env('APP_ENV');
- $searchParams['type'] = $input['t'];
- $searchParams['size'] = 50;
- if (isset($input['q'])) {
- switch ($input['q']) {
- case 'all':
- $searchParams['body'] = json_decode('{"query":{"bool":{"must":[{"match_all":{}}],"must_not":[],"should":[]}},"from":0,"size":10}', true);
- break;
- default;
- $searchParams['body']['query']['multi_match']['query'] = $input['q'];
- if ($input['t'] == 'places') {
- $searchParams['body']['query']['multi_match']['fields'] = ['name', 'location'];
- } else {
- $searchParams['body']['query']['multi_match']['fields'] = ['username', 'first_name', 'last_name', 'email'];
- }
- break;
- }
- }
- if (isset($input['e'])) {
- $e = explode(',', $input['e']);
- $searchParams['body'] = json_decode('{"query":{"bool":{"must":[],"must_not","should":[{"match_all":{}}]}},"from":0,"size":10,"sort":[],"aggs":{}}', true);
- $searchParams['body']['query']['bool']['must_not'][] = ['term' => ['id' => $e[0]]];
- //$searchParams['body']['query']['bool']['must_not'][] = ['term'=>$e[1]];
- }
- //dd($searchParams);
- $s = new \Freemig\Search\Facades\Search();
- $res = $s->find($searchParams);
- return $res['hits']['hits'];
- }
- function recommand($params)
- {
- $input = $params;
- $searchParams['index'] = env('APP_ENV');
- $searchParams['size'] = 50;
- if (isset($input['t'])) {
- switch ($input['t']) {
- case 'all':
- break;
- default;
- $searchParams['type'] = $input['t'];
- break;
- }
- }
- //dd($searchParams);
- $searchParams['body'] = json_decode('
- {"query":{"bool":{"must":[{"match_all":{}}],"must_not":[],"should":[]}},"from":0,"size":10}'
- , true);
- // dd($searchParams['body']);
- $s = new \Freemig\Search\Facades\Search();
- $res = $s->find($searchParams);
- return $res['hits']['hits'];
- }
- function notInYouMayKnowUser($params){
- $userId = session('userId');
- $friendsRepo = new FriendRepository(new Friend(),new FriendRequest(), new FriendGroup());
- $usersFriends = array_flatten($friendsRepo->getAllDobFriendsIdArray($userId));
- $ids = array();
- foreach ($usersFriends as $u){
- $ids[] = array(
- 'term' => array('id'=>$u),
- );
- }
- $ids = json_encode($ids,1);
- $input = $params;
- $searchParams['index'] = env('APP_ENV');
- $searchParams['size'] = 50;
- if (isset($input['t'])) {
- switch ($input['t']) {
- case 'all':
- break;
- default;
- $searchParams['type'] = $input['t'];
- break;
- }
- }
- $searchParams['body'] = json_decode('{"query":{"bool":{"must":[{"match_all":{}}],"must_not":'.$ids.',"should":[]}},"from":0,"size":10}', true);
- $s = new \Freemig\Search\Facades\Search();
- $res = $s->find($searchParams);
- return $res['hits']['hits'];
- }
- function getShareUsers($postId)
- {
- }
- function getFriendsForProfile($userId)
- {
- $friendsRepo = new FriendRepository(new Friend(), new FriendRequest(), new FriendGroup());
- $userRepo = new UserRepository(new User());
- $sessionUserFriends = array_flatten($friendsRepo->getSessionUserFriendsId());
- $profileUsersFriends = array_flatten($friendsRepo->getAllFriendsIdArray($userId));
- // $intersect = array_intersect($sessionUserFriends,$profileUsersFriends);
- $connections = [];
- $common_friends = [];
- foreach ($profileUsersFriends as $f) {
- $connections[] = $userRepo->getUserByIdMinimum($f);
- if (in_array($f, $sessionUserFriends)) {
- $common_friends[] = $userRepo->getUserByIdMinimum($f);
- }
- }
- $total_friend = count($connections);
- $total_common = count($common_friends);
- $data['connection'] = [
- 'friends' => ($total_friend > 8) ? array_slice($connections, 0, 8) : $connections,
- 'common_friends' => ($total_common > 8) ? array_slice($common_friends, 0, 8) : $common_friends,
- 'follower' => $friendsRepo->getFollowers($userId),
- 'following' => $friendsRepo->getFollowing($userId),
- ];
- $data['total_common'] = $total_common;
- $data['total_friend'] = $total_friend;
- return $data['total_friend'];
- }
- function simpleAuth($params, $req)
- {
- $validator = \Validator::make($params, [
- 'username' => 'required',
- 'password' => 'required'
- ], trans('auth.errors.messages'));
- if ($validator->fails()) {
- if($params['value_pass_for_capcha']>2){
- return $this->renderResponse(['status' => '6000', 'errors' => $validator->messages()]);
- }else{
- return $this->renderResponse(['status' => '5000', 'errors' => $validator->messages()]);
- }
- } else {
- $password = $params['password'];
- $cred = ['username' => $params['username'], 'password' => $password, 'is_active' => '1'];
- $AuthProvider = new \App\Authentication\AuthProvider();
- $isUser = $AuthProvider->isUser($cred);
- if ($isUser) {
- $isActiveUser = $AuthProvider->isActiveUser($cred);
- if (count($isActiveUser) > 0) {
- $userInfo = $AuthProvider->retrieveByCredentials($cred);
- if (count($userInfo) > 0) {
- if ($AuthProvider->validateCredentials($userInfo, $cred)) {
- $req->session()->set('isAuth', true);
- $req->session()->set('userId', $userInfo->id);
- $req->session()->set('username', $userInfo->username);
- $req->session()->set('userType', $userInfo->user_type);
- $req->session()->set('profileAvatar', $userInfo->profile_avatar);
- $req->session()->set('full_name', $userInfo->first_name . ' ' . $userInfo->last_name);
- $req->session()->set('totalFriend',getFriendsForProfile($userInfo->id));
- //subscribe to push notification channel
- $url = env('PN_SERVER') . '?&';
- curlReq($url, 'GET', ['c' => $req->session()->get('username'), 'm' => 'subscribe']);
- return ['status' => '2000', 'data' => ['userId' => $userInfo->id, 'username' => $userInfo->username]];
- } else {
- return ['status' => '5000', 'errors' => ['global' => trans('auth.errors.invalid')]];
- }
- } else {
- return ['status' => '5000', 'errors' => ['global' => trans('auth.errors.invalid')]];
- }
- } else {
- $link = \App::getLocale() . '/signup-successful';
- return ['status' => '5000', 'errors' => ['notActiveUser' => trans('auth.errors.inactive'), 'link'=> $link]];
- }
- }
- else {
- return ['status' => '5000', 'errors' => ['global' => trans('auth.errors.invalid')]];
- }
- }
- }
- function curlReq($url,$method='GET',$data=[]){
- $query = http_build_query($data);
- $ch = curl_init();
- if($method=='GET') {
- curl_setopt($ch, CURLOPT_URL, $url.$query);
- } else {
- curl_setopt($ch, CURLOPT_URL, $url);
- }
- curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
- if($method=='POST') {
- curl_setopt($ch,CURLOPT_POST, count($data));
- curl_setopt($ch,CURLOPT_POSTFIELDS, $query);
- }
- //execute post
- $result = curl_exec($ch);
- //close connection
- curl_close($ch);
- return $result;
- }
- function pn($type,$originator,$content)
- {
- // insert into redis as notification
- $data['pnType'] = $type;
- $data['originator'] = $originator;
- $data['content'] = $content;
- //Push Notification
- $pn = new Notification();
- $pn->insert(\Session::get('userId'), $data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement