/**
  * Handle Disable Target
  *
  * @param Integer $id
  * @return Response
  */
 public function disable($id)
 {
     $target = Targets::findOrFail($id);
     $target->watched = 0;
     $target->disabled = 1;
     $target->save();
     return redirect()->back()->with(['status' => 'success', 'message' => 'Target disabled.']);
 }
 /**
  * Register custom Blade composers
  *
  * @return void
  */
 private function bladeComposers()
 {
     /**
      * Master.Private
      */
     view()->composer('master.private', function ($view) {
         /**
          * Provide counts of all Records
          */
         $counts = array();
         $counts['senders'] = Senders::all()->count();
         $counts['targets'] = Targets::all()->count();
         $counts['queue'] = Tweets::inQueue()->count();
         $counts['sent'] = Tweets::areSent()->count();
         $counts['failed'] = Tweets::haveFailed()->count();
         $counts['flagged'] = Tweets::isFlagged()->count();
         $view->with('counts', $counts);
     });
 }
Exemple #3
0
 /**
  * Determine first name of Target or return Handle
  *
  * @param Integer $id
  * @return String
  */
 public function name($id)
 {
     $twitter = new TwitterOAuth(env('CONSUMER_KEY'), env('CONSUMER_SECRET'), env('ACCESS_TOKEN'), env('ACCESS_SECRET'));
     // Get Target Handle
     $target = Targets::find($id);
     $handle = $target->handle;
     // Attempt to get real name from Twitter
     $user = $twitter->get('/users/show', ['screen_name' => $handle]);
     if ($twitter->getLastHttpCode() === 200 && isset($user->name)) {
         $target->object = json_encode($user);
         $target->save();
         // Get first name
         $name = explode(' ', $user->name);
         $fname = $name[0];
         if (ctype_alpha($fname)) {
             $handle = $fname;
         }
     }
     return $handle;
 }
 /**
  * Return the Targets page
  *
  * @return View
  */
 public function getTargets()
 {
     $targets = Targets::all();
     return view('private.targets')->with('targets', $targets);
 }
 /**
  * Send Tweet through Twitter API
  *
  * @return Void
  */
 public function send()
 {
     /**
      * Initiate new Twitter
      */
     $twitter = new TwitterOAuth(env('CONSUMER_KEY'), env('CONSUMER_SECRET'), env('ACCESS_TOKEN'), env('ACCESS_SECRET'));
     /**
      * Get Tweets from Queue
      */
     $tweets = $this->next();
     /**
      * Collate Responses
      */
     $results = array();
     /**
      * Generate Images and Upload/Send each Tweet
      */
     foreach ($tweets as $tweet) {
         // Get Name
         $name = Admin::name($tweet->target);
         // Get Target Handle
         $target = Targets::find($tweet->target);
         $handle = $target->handle;
         // Remove Linebreaks from Message
         $tweet->message_clean = str_replace(array("\r", "\n"), ' ', $tweet->message_clean);
         if (trim($name) != '' && trim($tweet->message_clean != '')) {
             // Generate Image
             Image::setDetails($name, $tweet->message_clean);
             $image = Image::paintImage();
             $details = Image::saveImage($image);
             // Save Tweet with Image URL
             $tweet->image_url = $details['image_url'];
             $tweet->save();
             // The Message
             $hashtag = '#tweetthelove';
             $message = '@' . $handle . ' ' . $tweet->message_clean . ' ' . $hashtag;
             // Upload to Twitter
             $media = $twitter->upload('media/upload', ['media' => $details['image_url']]);
             if (isset($media->media_id_string)) {
                 // Post Tweet
                 $status = $twitter->post('statuses/update', ['status' => $message, 'media_ids' => $media->media_id_string]);
             }
             if ($twitter->getLastHttpCode() === 200) {
                 // Mark as Sent
                 $tweet->sent = 1;
                 $tweet->save();
                 $result = true;
             } else {
                 $tweet->failed = 1;
                 $tweet->save();
                 $result = json_encode($twitter->getLastBody());
             }
         } else {
             $tweet->failed = 1;
             $tweet->save();
             $result = false;
         }
         $results[$tweet->id] = array('status' => $result, 'message' => $message);
     }
     return $results;
 }