public function deny($id)
 {
     if (\Auth::check()) {
         $admin = \Auth::user();
         $media = SocialMedia::findOrFail($id);
         $media->approved = 'Denied';
         $media->approver_id = $admin->admin_id;
         $media->save();
         return redirect('/admin/pending');
     } else {
         return redirect('/');
     }
 }
Пример #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $url = 'https://api.instagram.com/v1/users/self/media/recent/?access_token=' . env('INSTAGRAM_ACCESS_TOKEN');
     $content = file_get_contents($url);
     $json = json_decode($content, true);
     foreach ($json['data'] as $images) {
         $insta_id = $images['id'];
         $imgUrl = $images['images']['standard_resolution']['url'];
         $description = $images['caption']['text'];
         $datetime_posted = $images['caption']['created_time'];
         $datetime_posted = Carbon::createFromTimestamp($datetime_posted)->toDateTimeString();
         $username = $images['user']['username'];
         $profilePic = $images['user']['profile_picture'];
         $link = $images['link'];
         if (SocialMedia::where('insta_id', $insta_id)->exists() || $description == null) {
             echo "This post already exists";
         } else {
             $insta = new SocialMedia();
             $insta->username = $username;
             $insta->insta_id = $insta_id;
             $insta->profile_pic_url = $profilePic;
             $insta->tweet = 'N/A';
             $insta->caption = $description;
             $insta->message = 'N/A';
             $insta->source = 'Admin-Insta';
             $type = substr($imgUrl, -3);
             if (!file_exists('public/instagrams')) {
                 mkdir('public/instagrams', 0777, true);
             }
             $localUrl = 'public/instagrams/' . $insta_id . '.jpg';
             file_put_contents('public/instagrams/' . $insta_id . '.jpg', file_get_contents($imgUrl));
             $insta->link = $link;
             $insta->resize = 'fit';
             $insta->approved = 'Approved';
             $insta->approver_id = -1;
             $insta->datetime_posted = $datetime_posted;
             $insta->save();
             echo "Saved!";
         }
     }
     runSync();
     // $tag = 'ghsnd';
     // $url = 'https://api.instagram.com/v1/tags/'.$tag.'/media/recent?client_id='.env('INSTAGRAM_CLIENT_ID');
     // $content = file_get_contents($url);
     // $json = json_decode($content, true);
     // foreach($json['data'] as $images) {
     //   $imgUrl = $images['images']['standard_resolution']['url'];
     //   $description = $images['caption']['text'];
     //   $datetime_posted = $images['caption']['created_time'];
     //   $datetime_posted = Carbon::createFromTimestamp($datetime_posted)->toDateTimeString();
     //   $username = $images['caption']['from']['username'];
     //   $profilePic = $images['caption']['from']['profile_picture'];
     //   $link = $images['link'];
     //   if (SocialMedia::where('caption', $description)->exists()) {
     // 	  echo "This post already exists";
     //   }
     //   else {
     // 	$insta = new SocialMedia;
     // 	$insta->username = $username;
     // 	$insta->profile_pic_url = $profilePic;
     // 	$insta->tweet = 'N/A';
     // 	$insta->caption = $description;
     // 	$insta->imgUrl = $imgUrl;
     // 	$insta->message = 'N/A';
     // 	$insta->source = 'Instagram';
     // 	$insta->link = $link;
     // 	$insta->width = 0;
     // 	$insta->height = 0;
     // 	$insta->resize = 'fit';
     // 	$insta->approved = 'Pending';
     // 	$insta->approver_id = -1;
     // 	$insta->datetime_posted = $datetime_posted;
     // 	$insta->save();
     // 	echo "Saved!";
     //   }
     // }
     echo "FINISHED";
 }
Пример #3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     //actual account
     $settings = array('oauth_access_token' => env('TWITTER_ACCESS_TOKEN'), 'oauth_access_token_secret' => env('TWITTER_ACCESS_TOKEN_SECRET'), 'consumer_key' => env('TWITTER_CONSUMER_KEY'), 'consumer_secret' => env('TWITTER_CONSUMER_SECRET'));
     $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
     $getField = 'screenname=ghchsnd';
     $requestMethod = 'GET';
     $twitter = new TwitterAPIExchange($settings);
     $content = $twitter->setGetfield($getField)->buildOauth($url, $requestMethod)->performRequest();
     $json = json_decode($content, true);
     var_dump($json);
     foreach ($json as $tweet_info) {
         $tweet = $tweet_info['text'];
         $datetime_posted = $tweet_info['created_at'];
         $date = explode(' ', $datetime_posted);
         $month = date('m', strtotime($date[1]));
         $day = $date[2];
         $year = $date[5];
         $time = $date[3];
         $datetime = Carbon::createFromFormat('Y-m-d H:i:s', $year . "-" . $month . "-" . $day . " " . $time, 'UTC');
         $datetime = $datetime->setTimezone('America/Los_Angeles');
         $username = $tweet_info['user']['screen_name'];
         $profile_img = $tweet_info['user']['profile_image_url'];
         $link = $imgUrl = $resize = 'N/A';
         // if (!file_exists('public/tweets')) {
         //   mkdir('public/tweets', 0777, true);
         // }
         // $localUrl = 'public/tweets/'.$insta_id.'.jpg';
         // file_put_contents('public/tweets/'.$insta_id.'.jpg', file_get_contents($imgUrl));
         if (isset($tweet_info['entities']['media'][0]['expanded_url'])) {
             $link = $tweet_info['entities']['media'][0]['expanded_url'];
         }
         if (isset($tweet_info['entities']['media'][0]['media_url_https'])) {
             $imgUrl = $tweet_info['entities']['media'][0]['media_url_https'];
         }
         if (isset($tweet_info['entities']['media'][0]['sizes']['large']['resize'])) {
             $resize = $tweet_info['entities']['media'][0]['sizes']['large']['resize'];
         }
         if ($username != 'ghchsnd' || SocialMedia::where('tweet', $tweet)->exists()) {
             echo "This post already exists";
         } else {
             $newTweet = new SocialMedia();
             $newTweet->username = $username;
             $newTweet->profile_pic_url = $profile_img;
             $newTweet->tweet = $tweet;
             $newTweet->caption = 'N/A';
             $newTweet->message = 'N/A';
             $newTweet->link = $link;
             $newTweet->source = 'Admin-Twitter';
             $newTweet->approved = 'Approved';
             $newTweet->approver_id = -1;
             $newTweet->datetime_posted = $datetime;
             $newTweet->save();
             echo "Saved!";
         }
     }
     //hashtag
     $settings = array('oauth_access_token' => env('TWITTER_ACCESS_TOKEN'), 'oauth_access_token_secret' => env('TWITTER_ACCESS_TOKEN_SECRET'), 'consumer_key' => env('TWITTER_CONSUMER_KEY'), 'consumer_secret' => env('TWITTER_CONSUMER_SECRET'));
     $url = 'https://api.twitter.com/1.1/search/tweets.json';
     $getField = 'q=%23ghsnd&result_type=recent';
     $requestMethod = 'GET';
     $twitter = new TwitterAPIExchange($settings);
     $content = $twitter->setGetfield($getField)->buildOauth($url, $requestMethod)->performRequest();
     $json = json_decode($content, true);
     foreach ($json['statuses'] as $tweet_info) {
         $tweet = $tweet_info['text'];
         $datetime_posted = $tweet_info['created_at'];
         $date = explode(' ', $datetime_posted);
         $month = date('m', strtotime($date[1]));
         $day = $date[2];
         $year = $date[5];
         $time = $date[3];
         $datetime = Carbon::createFromFormat('Y-m-d H:i:s', $year . "-" . $month . "-" . $day . " " . $time, 'UTC');
         $datetime = $datetime->setTimezone('America/Los_Angeles');
         $username = $tweet_info['user']['screen_name'];
         $profile_img = $tweet_info['user']['profile_image_url'];
         $link = $imgUrl = $resize = 'N/A';
         $height = $width = -1;
         if (isset($tweet_info['entities']['media'][0]['expanded_url'])) {
             $link = $tweet_info['entities']['media'][0]['expanded_url'];
         }
         if (isset($tweet_info['entities']['media'][0]['media_url_https'])) {
             $imgUrl = $tweet_info['entities']['media'][0]['media_url_https'];
         }
         if (isset($tweet_info['entities']['media'][0]['sizes']['large']['h'])) {
             $height = $tweet_info['entities']['media'][0]['sizes']['large']['h'];
         }
         if (isset($tweet_info['entities']['media'][0]['sizes']['large']['w'])) {
             $width = $tweet_info['entities']['media'][0]['sizes']['large']['w'];
         }
         if (isset($tweet_info['entities']['media'][0]['sizes']['large']['resize'])) {
             $resize = $tweet_info['entities']['media'][0]['sizes']['large']['resize'];
         }
         if (SocialMedia::where('tweet', $tweet)->exists()) {
             echo "This post already exists";
         } else {
             $newTweet = new SocialMedia();
             $newTweet->username = $username;
             $newTweet->profile_pic_url = $profile_img;
             $newTweet->tweet = $tweet;
             $newTweet->caption = 'N/A';
             $newTweet->message = 'N/A';
             $newTweet->imgUrl = $imgUrl;
             $newTweet->link = $link;
             $newTweet->width = $width;
             $newTweet->height = $height;
             $newTweet->source = 'Twitter';
             $newTweet->approved = 'Pending';
             $newTweet->approver_id = -1;
             $newTweet->datetime_posted = $datetime;
             $newTweet->save();
             echo "Saved!";
         }
     }
     echo "FINISHED";
 }
Пример #4
0
 public function saveMemberSocialIds($siteArr, $useAvatarFromSocialSite, $memberId)
 {
     $socialIdSiteArr = SocialMedia::getSocialSiteIdArr();
     DB::beginTransaction();
     // delete existing relationships in table
     DB::table('member_social_ids')->where('member_id', $memberId)->delete();
     // save new
     if (count($siteArr) > 0) {
         $valuesArr = array();
         foreach ($siteArr as $site => $arr) {
             $site = trim($site);
             $siteId = trim($arr['id']);
             if ($siteId == '' || $site == '' || !isset($socialIdSiteArr[$site])) {
                 continue;
             }
             $avatarSrc = isset($arr['avatar_src']) ? $arr['avatar_src'] : '';
             $primaryAvatar = 0;
             if ($useAvatarFromSocialSite == $site) {
                 $primaryAvatar = 1;
             }
             $valuesArr[] = array('member_id' => $memberId, 'social_site' => $site, 'member_social_id' => $siteId, 'disabled' => $arr['disabled'], 'primary_avatar' => $primaryAvatar, 'avatar' => $avatarSrc);
         }
         if (count($valuesArr) > 0) {
             DB::table('member_social_ids')->insert($valuesArr);
         }
         DB::commit();
     }
 }
Пример #5
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     if (\Auth::check()) {
         $post = SocialMedia::findOrFail($id);
         $post->message = $request->input('content');
         $post->approver_id = \Auth::user()->admin_id;
         $post->save();
         $request->session()->flash('edited-post', 'Post Edited.');
         $posts = DB::table('social_media')->orderBy('datetime_posted', 'asc')->where('source', 'Admin-Post')->get();
         return view('auth.edit', ['admin' => \Auth::user(), 'posts' => $posts]);
     } else {
         return redirect('admin/login');
     }
 }