/** * Get most recent id's for Twitter & Facebook * * @return void */ private function initIds() { $message = new Message(); if (isTwitterLinked()) { $mentionId = $this->twitterContent->newestMentionId(); $directId = $this->twitterContent->newestDirectId(); if ($mentionId) { $message->tweet_id = $mentionId; } if ($directId) { $message->direct_id = $directId; } } if (isFacebookLinked()) { $postId = $this->facebookContent->newestPostId(); $conversationId = $this->facebookContent->newestConversationId(); if ($postId) { $message->fb_post_id = $postId; } if ($conversationId) { $message->fb_private_id = $conversationId; } } $message->post_date = Carbon::now(); $message->save(); $this->log->updateLog('fetching'); }
/** * Update config file with likes * @return void */ public function updateFacebookDashboardStats() { $likes = $this->facebookContent->fetchLikes(); $config = $this->config->first(); $config->facebook_likes = $likes['fan_count']; $config->save(); }
/** * Publish Tweet and/or Facebook post * * @param Request $request * * @return view */ public function publish(Request $request) { $this->validate($request, ['content' => 'required', 'social' => 'required']); $content = rawurlencode($request->input('content')); if (in_array(self::TYPE_TWITTER, $request->input('social'))) { $publishment = $this->twitterContent->publishTweet($content); $this->insertPublishment(self::TYPE_TWITTER, $publishment, $content); } if (in_array(self::TYPE_FACEBOOK, $request->input('social'))) { $publishment = $this->facebookContent->publishPost($content); $this->insertPublishment(self::TYPE_FACEBOOK, $publishment, $content); } return back(); }
/** * Fetch inner comments of facebook * @param datetime $newest * @return void */ private function fetchInnerComments($newest) { $messages = $this->getComments(); foreach ($messages as $key => $message) { $comments = $this->facebookContent->fetchInnerComments($newest, $message['fb_post_id']); if ($comments == null) { continue; } foreach ($comments->data as $key => $comment) { if ($comment->from->id != config('crm-launcher.facebook_credentials.facebook_page_id') && new Datetime(changeFbDateFormat($comment->created_time)) > new Datetime($newest)) { if (!$this->contact->findByFbId($comment->from->id)->exists()) { $contact = $this->contact->createContact('facebook', $comment); } else { $contact = $this->contact->where('facebook_id', $comment->from->id)->first(); } $innerComment = new InnerComment(); $innerComment->fb_reply_id = $message['fb_post_id']; $innerComment->post_date = changeFbDateFormat($comment->created_time); $innerComment->contact_id = $contact->id; if (is_a($message, "Rubenwouters\\CrmLauncher\\Models\\Answer")) { $innerComment->answer_id = $message['id']; } else { if (is_a($message, "Rubenwouters\\CrmLauncher\\Models\\Reaction")) { $innerComment->reaction_id = $message['id']; } else { $innerComment->message_id = $message['id']; } } $innerComment->fb_post_id = $comment->id; $innerComment->message = $comment->message; $innerComment->save(); $this->media->handleMedia($innerComment->id, $comment, 'facebook_innerComment'); } } } }