/** * Test for Post::__toString() */ public function testToString() { $post = new Post(); $post->setHeadline('Hello World!'); $postToString = (string) $post; $this->assertEquals('Hello World!', $postToString); }
/** * @param \stdClass|array $socialPost * * @return Post */ protected function getMappedPostObject($socialPost) { $post = new Post(); if (!isset($socialPost->message)) { return false; } $post->setProvider($this->providerName); $post->setPostId($socialPost->id); $userDetails = json_decode(file_get_contents("https://graph.facebook.com/" . $socialPost->from->id . '?access_token=' . $this->api->getAccessToken())); $post->setAuthorUsername($userDetails->username); $post->setAuthorName($socialPost->from->name); $post->setAuthorFile('https://graph.facebook.com/' . $socialPost->from->id . '/picture' . '?access_token=' . $this->api->getAccessToken()); $post->setHeadline(strip_tags($socialPost->message)); $message = $this->getFormattedTextFromPost($socialPost); $post->setBody($message); if (isset($socialPost->picture) && !empty($socialPost->picture)) { // A picture is set, use the original url as a backup $post->setFile($socialPost->picture); // If there is an object_id, then the original file may be available, so check for that one if (isset($socialPost->object_id)) { $imageDetails = json_decode(file_get_contents("https://graph.facebook.com/" . $socialPost->object_id . '?access_token=' . $this->api->getAccessToken())); if (isset($imageDetails->images[0]->source)) { $post->setFile($imageDetails->images[0]->source); } } else { // Check if it is an external image, if so, use the original one. $pictureUrlData = parse_url($socialPost->picture); if (preg_match('#^fbexternal#', $pictureUrlData['host']) === 1) { parse_str($pictureUrlData['query'], $pictureUrlQueryData); if (isset($pictureUrlQueryData['url'])) { $post->setFile($pictureUrlQueryData['url']); } } } } $post->setLink('https://www.facebook.com/' . $socialPost->id); $post->setPublishAt(new \DateTime($socialPost->created_time)); $post->setIsActive(true); return $post; }
/** * @param \stdClass|array $socialPost * * @return Post */ protected function getMappedPostObject($socialPost) { $post = new Post(); $post->setProvider($this->providerName); $post->setPostId($socialPost['id_str']); $post->setAuthorUsername($socialPost['user']['screen_name']); $post->setAuthorName($socialPost['user']['name']); $post->setAuthorFile($socialPost['user']['profile_image_url']); $text = $this->getFormattedTextFromPost($socialPost); $post->setHeadline(strip_tags($socialPost['text'])); $post->setBody($text); if (isset($socialPost['entities']['media'][0])) { $post->setFile($socialPost['entities']['media'][0]['media_url']); } $post->setLink('https://twitter.com/' . $socialPost['user']['screen_name'] . '/status/' . $socialPost['id_str']); $post->setPublishAt(new \DateTime($socialPost['created_at'])); $post->setIsActive(true); return $post; }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { for ($ctr = 0; $ctr < 10; $ctr++) { $post = new Post(); $post->setHeadline('A very interesting social feed post ' . $ctr); $post->setProvider(array_rand(array('facebook', 'twitter', 'instagram'))); $post->setAuthorName('Author name'); $post->setAuthorUsername('Author username'); $post->setAuthorFile('author-file.jpg'); $post->setBody('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur posuere orci eu mi fermentum pulvinar. Curabitur laoreet, mi ac dictum mattis.'); $post->setIsActive(true); $post->setPostId('123abc' . $ctr); $post->setPublishAt(new \DateTime()); $manager->persist($post); $manager->flush(); } }
/** * @param \stdClass|array $socialPost * * @return Post */ protected function getMappedPostObject($socialPost) { $post = new Post(); $socialPost = $socialPost->getData(); if (!isset($socialPost->caption->text)) { return false; } $post->setProvider($this->providerName); $post->setPostId($socialPost->id); $post->setAuthorUsername($socialPost->user->username); $post->setAuthorName($socialPost->user->full_name); $post->setAuthorFile($socialPost->user->profile_picture); $post->setHeadline(strip_tags($socialPost->caption->text)); $text = $this->getFormattedTextFromPost($socialPost); $post->setBody($text); $post->setFile($socialPost->images->standard_resolution->url); $post->setLink($socialPost->link); $publishAt = new \DateTime(); $publishAt->setTimestamp($socialPost->created_time); $post->setPublishAt($publishAt); $post->setIsActive(true); return $post; }