public function __construct() { if (Agent::isMobile()) { $this->_vista = 'mobile'; } else { $this->_vista = 'index'; } $this->_imagesInstagram = array(); $this->_imagesTwitter = array(); $instagram = new instagram(array('apiKey' => '09fd60952ea742d5abb761b6c6a137aa', 'apiSecret' => 'ee25063e91e74d6c9f257be054a44ec3', 'apiCallback' => 'http://viernesdezapatillas.pe/')); $tagInstagram = 'viernesdezapatillas'; $numphotosInstagram = 15; $media = $instagram->getTagMedia($tagInstagram, $auth = false, array('count' => $numphotosInstagram)); $response = json_decode(json_encode($media)); foreach ($response->data as $data) { $this->_imagesInstagram[] = $data->images->thumbnail->url; } $max_id = 0; $totalTweets = 15; $responset = Twitter::getSearch(array('q' => '#viernesdezapatillas since:2015-07-01 filter:images', 'count' => $totalTweets, 'max_id' => $max_id, 'since_id' => 0)); foreach ($responset->statuses as $tweet) { foreach ($tweet->entities->media as $url) { $this->_imagesTwitter[] = $url->media_url; // . ':thumb'; } } }
/* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ use GrahamCampbell\Markdown\Facades\Markdown; Route::get('/original', function () { return view('inicio-original'); }); Route::get('/twitter/{hashtag}', function ($hashtag) { $twitters = Twitter::getSearch(['q' => $hashtag, 'count' => 50]); $sentimientos = ['negative', 'positive', 'neutral']; $twitters_array = $twitters->statuses; foreach ($twitters_array as $twitter) { $traduccion = TranslateClient::translate('es', 'en', $twitter->text); $sentimiento = SentimentAnalysis::decision($traduccion); $sentimientos[] = $sentimiento; } $sentimiento_twitter = array_count_values($sentimientos); return view('twitter', compact('sentimiento_twitter', 'twitters_array', 'hashtag')); }); Route::get('/sentimiento/{text}', function ($text) { $traduccion = TranslateClient::translate('es', 'en', $text); return SentimentAnalysis::decision($traduccion); }); Route::get('/colaboradores', function () {
}); /** * Registers the GET route to the codezero/twitter package test page. */ Route::get('/twitter/codezero', function () { $config = __DIR__ . '/../../config/twitter.php'; $twitter = new CodeZero\Twitter\Twitter($config); $tweets = $twitter->searchTweets('taylorswift', 50); dump($tweets); return 'codezero/twitter'; }); /** * Registers the GET route to the thujohn/twitter package test page. */ Route::get('/twitter/thujohn', function () { $search_results = Twitter::getSearch(['q' => 'taylorswift', 'lang' => 'en', 'result_type' => 'popular']); dump($search_results); echo '<h1>Tweets</h1>'; foreach ($search_results->statuses as $tweet) { // $info = Oembed::cache(Twitter::linkTweet($tweet), []); // echo $info->code; echo '<iframe class="twitter-tweet" '; echo ' src="http://twitframe.com/show?url=', urlencode(Twitter::linkTweet($tweet)), '"'; echo ' frameborder="0"'; echo ' height="480">'; echo '</iframe>'; // echo Twitter::linkify($tweet), // '<br/><a href=', // Twitter::linkTweet($tweet), '>', // Carbon\Carbon::createFromFormat('D M d H:i:s P Y', // $tweet->created_at),
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')); } }
/** * Searches Twitter for the specified $hashtag. * * @example array($tweet1, $tweet2, $tweet3) * @param string $term hashtag term to search for * @return array|object */ protected function searchTwitter($term) { $search_results = \Twitter::getSearch(['q' => $term, 'lang' => 'en', 'result_type' => 'popular', 'count' => 30]); return $search_results->statuses; }