public function run($request)
 {
     echo "Facebook posts are being synced...\n";
     FacebookAPI::inst()->syncPosts();
     echo FacebookPost::get()->count() . " posts have been synced.\n\n";
     echo "Facebook timeline pics are being synced...\n";
     FacebookAPI::inst()->syncPics();
     echo FacebookTimelinePic::get()->count() . " pics have been synced.\n\n";
     echo "Facebook sync done!\n";
 }
示例#2
0
 private function parsePost($entry)
 {
     $post = new FacebookPost();
     $post->setID($entry['id']);
     $post->setAuthor($entry['from']['id']);
     $post->setCreated(new DateTime($entry['created_time']));
     if (!empty($entry['message'])) {
         $post->setBody($entry['message']);
     }
     if (isset($entry['likes'])) {
         $post->setLikeCount($entry['likes']['count']);
     }
     switch ($entry['type']) {
         case 'photo':
             if (isset($entry['source'])) {
                 $post->addImage($entry['source']);
             } elseif (preg_match("/^(.*)_s\\.jpg\$/", $entry['picture'], $bits)) {
                 $post->addImage($bits[1] . '_n.jpg');
             } else {
                 $post->addImage($entry['picture']);
             }
             break;
         case 'link':
         case 'video':
         case 'status':
             break;
         default:
             throw new KurogoDataException("Unhandled facebook type " . $entry['type']);
     }
     return $post;
 }
 /**
  * Publish a post to user wall
  * @param FacebookPost $post
  * @return bool
  */
 public function post($post)
 {
     $post->to = $this->id;
     return $post->publish();
 }
 /**
  * Gets timeline posts. Suitable for usage in templates.
  * @param int $limit
  * @param bool|false $fromAPI
  * @param bool|false $forceSync
  * @return ArrayList|DataList|SS_Limitable
  */
 public function getPosts($limit = 100, $fromAPI = false, $forceSync = false)
 {
     if ($fromAPI) {
         $posts = $this->requestPosts($limit, true);
     }
     if ($forceSync) {
         $this->syncPosts($limit);
     }
     if (!FacebookPost::get() && !$fromAPI) {
         $this->syncPosts($limit);
     }
     if (!$fromAPI) {
         $posts = FacebookPost::get()->limit($limit);
     }
     return $posts;
 }