コード例 #1
0
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         InstagramPost::create([]);
     }
 }
コード例 #2
0
 public function validate()
 {
     $result = parent::validate();
     if (isset($this->record['moderated'])) {
         $prepend = 'Instagram_';
         $imagePrepend = 'ImageData_';
         foreach ($this->record as $key => $val) {
             if (strpos($key, $prepend) !== false) {
                 if ($val == 'approve' || $val == 'reject') {
                     $id = substr($key, strlen($prepend));
                     $post = new InstagramPost();
                     $post->MediaID = $id;
                     $post->Approved = $val == 'approve';
                     $post->ImageData = $this->record['ImageData_' . $id];
                     $post->write();
                 }
             }
         }
     }
     if (!$this->MediaID) {
         $result->error('<script>document.getElementById("Form_ItemEditForm_error").style.display="none";window.location.reload();</script>');
     }
     return $result;
 }
コード例 #3
0
 protected function getMostRecent()
 {
     return InstagramPost::get()->sort("Posted DESC")->First();
 }
 public function updatePosts($objectID = '')
 {
     $is = new InstagramService($this);
     $minID = $this->MinID;
     $update = false;
     switch ($this->Type) {
         case "tag":
             if (empty($objectID)) {
                 $objectID = $this->HashTag;
             }
             $update = $is->tagsRecent($objectID, null, $minID);
             if ($update) {
                 $this->MinID = $update->pagination->min_tag_id;
             }
             break;
         case "user":
             if (empty($objectID)) {
                 $objectID = 'self';
             }
             $update = $is->getUserRecent($objectID, null, null, null, $minID);
             if ($update) {
                 $this->MinID = $update->data[0]->created_time;
             }
             break;
     }
     $callbackFunc = (string) Config::inst()->get('Instagram', 'postReceivedCallback');
     if ($update) {
         $this->write();
         foreach ($update->data as $img) {
             if (isset($img->id)) {
                 $p = InstagramPost::get()->Filter(array('PostID' => $img->id));
                 if ($p->Count() == 0) {
                     $p = new InstagramPost();
                 } else {
                     $p = $p->first();
                 }
                 if (!empty($img->tags)) {
                     $p->setTags($img->tags);
                 }
                 $p->Caption = $img->caption->text;
                 $p->Link = $img->link;
                 $p->Posted = $img->created_time;
                 $p->ImageURL = $img->images->standard_resolution->url;
                 $p->PostID = $img->id;
                 $p->Processed = false;
                 $p->OrigMessage = json_encode($img);
                 $p->Type = "Instagram";
                 $p->CommentCount = $img->comments->count;
                 $p->LikeCount = $img->likes->count;
                 $p->SubscriptionID = $this->ID;
                 $p->write();
                 if (!empty($callbackFunc)) {
                     $p->{$callbackFunc}();
                 }
             }
         }
         return true;
     } else {
         return false;
     }
 }