Esempio n. 1
0
 /**
  * Parse user array
  *
  * @param array $array
  *
  * @return \Evolution7\SocialApi\Entity\Post
  */
 public function parsePostArray($array)
 {
     // Create User
     if (!is_null($array) && array_key_exists('user', $array)) {
         $user = $this->parseUserArray($this->getArrayValue('user', $array));
     } else {
         $user = null;
     }
     // Create Post
     $post = new Post();
     $post->setPlatform(Config::PLATFORM_TWITTER);
     if (!is_null($user)) {
         $post->setUser($user);
     }
     $post->setId($this->getArrayValue('id_str', $array));
     $post->setCreated(new \DateTime($this->getArrayValue('created_at', $array)));
     $post->setBody($this->getArrayValue('text', $array));
     if (!is_null($user)) {
         $post->setUrl('https://twitter.com/' . $user->getHandle() . '/status/' . $post->getId());
     }
     $mediaUrl = $this->getArrayValue(array('entities', 'media', 0, 'media_url'), $array);
     if (!is_null($mediaUrl)) {
         $post->setMediaUrl(str_replace(array('http://', 'https://'), '//', $mediaUrl));
     }
     $this->posts[$post->getId()] = $post;
     return $post;
 }
Esempio n. 2
0
 /**
  * Parse user array
  *
  * @param array $array
  *
  * @return \Evolution7\SocialApi\Entity\Post
  */
 public function parsePostArray($array)
 {
     // Create User
     if (!is_null($array) && array_key_exists('user', $array)) {
         $user = $this->parseUserArray($this->getArrayValue('user', $array));
     } else {
         $user = null;
     }
     // Create Post
     $post = new Post();
     $post->setPlatform(Config::PLATFORM_INSTAGRAM);
     if (!is_null($user)) {
         $post->setUser($user);
     }
     $post->setId($this->getArrayValue('id', $array));
     $post->setCreated(new \DateTime(date(DATE_ISO8601, $array['created_time'])));
     if (is_array($this->getArrayValue('caption', $array))) {
         $post->setBody($array['caption']['text']);
     } else {
         $post->setBody($array['caption']);
     }
     $post->setUrl($this->getArrayValue('link', $array));
     $post->setMediaType($this->getArrayValue('type', $array));
     $mediaUrl = $this->getArrayValue(array($post->getMediaType() . 's', 'standard_resolution', 'url'), $array);
     if (!is_null($mediaUrl)) {
         $post->setMediaUrl(str_replace(array('http://', 'https://'), '//', $mediaUrl));
     }
     $this->posts[$post->getId()] = $post;
     return $post;
 }