/** * Store a Facebook Page post into our database * * @param $fb_id * @param $content * @param $url * @param $timePosted * @param null $imageSource * @return FacebookPost */ public function storePost($fb_id, $content, $url, $timePosted, $imageSource = null) { $fbPost = new FacebookPost(); $fbPost->FBID = $fb_id; $fbPost->Content = $content; $fbPost->TimePosted = $timePosted; $fbPost->URL = $url; if ($imageSource) { $fbPost->ImageSource = $imageSource; } $fbPost->write(); return $fbPost; }
/** * Initiate the service and copy new posts to our database */ public function process() { $this->fbService = new FBPageFeedService(); $storedPosts = $this->fbService->getStoredPosts(); $posts = $this->fbService->getPostsFromFacebook(); $inserted = 0; foreach ($posts as $i => $post) { if (!isset($post['FBID'])) { break; } $existingPost = FacebookPost::get()->filter('URL', $post['URL'])->first(); if ($existingPost) { break; } else { if (isset($post['source'])) { $imageSource = $post['source']; } else { $imageSource = null; } $this->fbService->storePost($post['FBID'], $post['Content'], $post['URL'], $post['TimePosted'], $imageSource); $inserted++; } } echo 'Stored ' . $inserted . ' new posts.'; }