Пример #1
0
 public function getDeleteProvider($provider)
 {
     if (isset($provider) && Auth::check()) {
         $user = Auth::user();
         if ($user->default_provider == $provider) {
             return Redirect::to('konto')->with('alert', array('type' => 'error', 'content' => 'Nie możesz usunąć domyślnego połączenia!'));
         }
         if ($user->provider->count() == 1) {
             return Redirect::to('konto')->with('alert', array('type' => 'error', 'content' => 'Nie możesz usunąć tego połączenia!'));
         }
         SocialProvider::where('user_id', '=', $user->id)->where('provider', '=', $provider)->delete();
         return Redirect::to('konto')->with('alert', array('type' => 'success', 'content' => 'Połączenie usunięte!'));
     }
 }
Пример #2
0
 public function showBoard($id)
 {
     $posts = array();
     $client = new \GuzzleHttp\Client();
     $count = 0;
     $board = Board::find($id);
     $hashtag = $board->hashtag;
     $config = $board->config()->first();
     $instagramKey = Config::get('laravel-social::providers.instagram.client_id');
     $googleKey = 'AIzaSyDiywW3UvpbQ5aR7f_8tLVgNCzui7Gq6ek';
     $postCount = 20;
     $googleToken = '';
     $instagramNextMaxId = '';
     $instagramMinTagId = '';
     $twitterMaxId = '';
     $twitterSinceId = '';
     $facebookSinceId = '';
     $facebookUntilId = '';
     $vineSinceId = '';
     $googleSinceId = '';
     if ($config->has_insta != -1) {
         if (Auth::check()) {
             $user = Auth::user();
             $provider = SocialProvider::where('user_id', '=', $user->id)->where('provider', '=', 'instagram')->first();
             if (is_null($provider)) {
                 $instagram = $client->get('https://api.instagram.com/v1/tags/' . $hashtag . '/media/recent?count=' . $postCount . '&client_id=' . $instagramKey);
             } else {
                 $token = $provider->access_token;
                 $instagram = $client->get('https://api.instagram.com/v1/tags/' . $hashtag . '/media/recent?count=' . $postCount . '&access_token=' . $token);
             }
         } else {
             $provider = SocialProvider::where('user_id', '=', $config->user_id)->where('provider', '=', 'instagram')->first();
             if (is_null($provider)) {
                 $instagram = $client->get('https://api.instagram.com/v1/tags/' . $hashtag . '/media/recent?count=' . $postCount . '&client_id=' . $instagramKey);
             } else {
                 $token = $provider->access_token;
                 $instagram = $client->get('https://api.instagram.com/v1/tags/' . $hashtag . '/media/recent?count=' . $postCount . '&access_token=' . $token);
             }
         }
         if ($instagram->getStatusCode() == 200) {
             $instagramData = $instagram->json();
             foreach ($instagramData['data'] as $data) {
                 if (strpos($data['caption']['text'], $hashtag) !== false) {
                     $post['user_id'] = $data['caption']['from']['id'];
                     $post['username'] = $data['caption']['from']['username'];
                     $post['url'] = $data['link'];
                     $str = $data['caption']['text'];
                     $str = preg_replace('/@([\\w-]+)/i', '', $str);
                     // #@
                     $post['caption'] = $str;
                     $post['post_id'] = $data['id'];
                     $post['vendor'] = 'instagram';
                     $post['user_img_url'] = $data['caption']['from']['profile_picture'];
                     $post['date_created'] = date("m-d-y H:i:s", $data['created_time']);
                     if (isset($data['images']) && !isset($data['videos'])) {
                         $post['img_url'] = $data['images']['standard_resolution']['url'];
                         $post['post_type'] = 'image';
                     } else {
                         if (isset($data['videos'])) {
                             //	dd($data['videos']);
                             $post['img_url'] = $data['images']['standard_resolution']['url'];
                             $post['embed'] = $data['videos']['standard_resolution']['url'];
                             $post['post_type'] = 'video';
                         }
                     }
                     array_push($posts, $post);
                     $count++;
                 }
             }
             if (isset($instagramData['pagination']['next_max_id'])) {
                 $instagramNextMaxId = $instagramData['pagination']['next_max_id'];
             }
             if (isset($instagramData['pagination']['min_tag_id'])) {
                 $instagramMinTagId = $instagramData['pagination']['min_tag_id'];
             }
         }
     }
     if ($config->has_fb == 9999) {
         $facebook = Facebook::api('/search?type=post&limit=' . $postCount . '&q=%23' . $hashtag);
         if ($facebook) {
             foreach ($facebook['data'] as $post) {
                 $post['vendor'] = 'facebook';
                 $post['post_id'] = $post['id'];
                 //$post['url'] = $post['link'];
                 $post['user_id'] = $post['from']['id'];
                 $post['username'] = $post['from']['name'];
                 $post['user_img_url'] = 'https://graph.facebook.com/' . $post['from']['id'] . '/picture?type=small';
                 if ($post['type'] == 'photo') {
                     $post['img_url'] = $post['picture'];
                     $post['post_type'] = 'image';
                 } else {
                     if ($post['type'] == 'video' && isset($post['picture'])) {
                         $post['post_type'] = 'video';
                         $post['img_url'] = $post['picture'];
                         $post['embed'] = $post['link'];
                     } else {
                         $post['post_type'] = 'text';
                     }
                 }
                 if (isset($post['message'])) {
                     $post['caption'] = $post['message'];
                 }
                 $post['date_created'] = $post['created_time'];
                 array_push($posts, $post);
                 $count++;
             }
             if (isset($facebook['paging'])) {
                 if (isset($facebook['paging']['previous'])) {
                     $prev = $facebook['paging']['previous'];
                     parse_str($prev, $arr);
                     $facebookSinceId = $arr['since'];
                 }
                 if (isset($facebook['paging']['next'])) {
                     $next = $facebook['paging']['next'];
                     parse_str($next, $arr);
                     $facebookUntilId = $arr['until'];
                 }
             }
         }
     }
     if ($config->has_tw != -1) {
         $first = true;
         $twitter = Twitter::getSearch(array('q' => '#' . $hashtag, 'include_entities' => 1, 'result_type' => 'recent', 'count' => $postCount));
         if ($twitter) {
             foreach ($twitter->statuses as $tweet) {
                 if (substr($tweet->text, 0, 2) !== "RT") {
                     if ($first) {
                         $twitterSinceId = $tweet->id . '';
                         $first = false;
                     }
                     $post['vendor'] = 'twitter';
                     $post['post_id'] = $tweet->id;
                     $post['user_id'] = $tweet->user->id;
                     $post['username'] = $tweet->user->screen_name;
                     $post['user_img_url'] = $tweet->user->profile_image_url;
                     if (isset($tweet->entities->media)) {
                         $post['img_url'] = $tweet->entities->media[0]->media_url;
                         $post['post_type'] = 'image';
                     } else {
                         $post['post_type'] = 'text';
                     }
                     $str = $tweet->text;
                     $str = preg_replace('/@([\\w-]+)/i', '', $str);
                     $post['caption'] = $str;
                     $post['date_created'] = date("m-d-y H:i:s", strtotime($tweet->created_at));
                     array_push($posts, $post);
                     $count++;
                 }
             }
             if (isset($twitter->search_metadata->next_results)) {
                 $next = $twitter->search_metadata->next_results;
                 parse_str($next, $arr);
                 $twitterMaxId = $arr['?max_id'];
             } else {
                 $twitterMaxId = '';
             }
         }
     }
     if ($config->has_google != -1) {
         $first = true;
         $google = $client->get('https://www.googleapis.com/plus/v1/activities?maxResults=2&query=' . $hashtag . '&key=' . $googleKey);
         if ($google->getStatusCode() == 200) {
             $data = $google->json();
             foreach ($data['items'] as $item) {
                 if ($first) {
                     $googleSinceId = $item['id'] . '';
                     $first = false;
                 }
                 $post['vendor'] = 'google-plus';
                 $post['post_id'] = $item['id'];
                 $post['user_id'] = $item['actor']['id'];
                 $post['username'] = $item['actor']['displayName'];
                 $post['date_created'] = $item['published'];
                 $post['user_img_url'] = $item['actor']['image']['url'];
                 $post['post_type'] = 'text';
                 if (isset($item['object']['attachments'][0]['objectType'])) {
                     if ($item['object']['attachments'][0]['objectType'] == 'photo') {
                         $post['img_url'] = $item['object']['attachments'][0]['fullImage']['url'];
                         $post['post_type'] = 'image';
                     }
                     if ($item['object']['attachments'][0]['objectType'] == 'video') {
                         $post['img_url'] = $item['object']['attachments'][0]['image']['url'];
                         $post['post_type'] = 'video';
                         $post['embed'] = $item['object']['attachments'][0]['url'];
                     }
                     if ($item['object']['attachments'][0]['objectType'] == 'article') {
                         if (isset($item['object']['attachments'][0]['fullImage']['url'])) {
                             $post['img_url'] = $item['object']['attachments'][0]['fullImage']['url'];
                         }
                         $post['post_type'] = 'article';
                         $post['article_url'] = $item['object']['attachments'][0]['url'];
                     }
                 } else {
                     $post['post_type'] = 'text';
                 }
                 $post['caption'] = $item['title'];
                 $post['url'] = $item['url'];
                 array_push($posts, $post);
                 $count++;
             }
             if (isset($data['nextPageToken'])) {
                 $googleToken = $data['nextPageToken'];
             }
         }
     }
     if ($config->has_vine != -1) {
         $vine = $client->get('https://api.vineapp.com/timelines/tags/' . $hashtag . '?limit=5');
         $vineCount = 0;
         $first = true;
         if ($vine->getStatusCode() == 200) {
             $data = $vine->json();
             if ($data['data']['count'] !== 0) {
                 foreach ($data['data']['records'] as $item) {
                     if ($first) {
                         $vineSinceId = $item['postId'] . '';
                         $first = false;
                     }
                     $post['vendor'] = 'vine';
                     $post['post_id'] = $item['postId'];
                     $post['user_id'] = $item['userId'];
                     $post['username'] = $item['username'];
                     $post['date_created'] = Carbon::parse($item['created'])->addHours(2);
                     $post['user_img_url'] = $item['avatarUrl'];
                     $post['img_url'] = $item['thumbnailUrl'];
                     $post['post_type'] = 'video';
                     $post['url'] = $item['permalinkUrl'];
                     $post['embed'] = $item['videoLowURL'];
                     $post['caption'] = $item['description'];
                     array_push($posts, $post);
                     $count++;
                     $vineCount++;
                     if ($vineCount == 5) {
                         break;
                     }
                 }
             }
         }
     }
     if ($count > 0) {
         $html = $this->postsToHtml($posts, $board->id, true);
         return Response::json(array('posts' => $html, 'endpoints' => array('google_token' => $googleToken, 'google_since_id' => $googleSinceId, 'twitter_max_id' => $twitterMaxId, 'twitter_since_id' => $twitterSinceId, 'instagram_max_id' => $instagramNextMaxId, 'instagram_min_tag' => $instagramMinTagId, 'facebook_until_id' => $facebookUntilId, 'facebook_since_id' => $facebookSinceId, 'vine_since_id' => $vineSinceId), 'count' => $count));
     } else {
         return Response::json(array('message' => 'No posts'));
     }
 }