public static function updateInstagramPosts()
 {
     $lastInstagramPost = \SocialPost::type('instagram')->latest('published_at')->get()->first();
     $lastInstagramPostTimestamp = $lastInstagramPost ? strtotime($lastInstagramPost->published_at) : 0;
     $clientId = Config::get('laravel-social-feeder::instagramCredentials.clientId');
     $userId = Config::get('laravel-social-feeder::instagramCredentials.userId');
     $url = 'https://api.instagram.com/v1/users/' . $userId . '/media/recent?count=5&client_id=' . $clientId;
     $json = file_get_contents($url);
     $obj = json_decode($json);
     $postsData = $obj->data;
     foreach ($postsData as $post) {
         if ($post->caption->created_time <= $lastInstagramPostTimestamp) {
             continue;
         }
         $newPostData = array('type' => 'instagram', 'social_id' => $post->caption->id, 'url' => $post->link, 'text' => $post->caption->text, 'image_url' => $post->images->standard_resolution->url, 'show_on_page' => 1, 'published_at' => date('Y-m-d H:i:s', $post->caption->created_time));
         $newPostEntity = new \SocialPost();
         $newPostEntity->fill($newPostData)->save();
     }
     return true;
 }
Example #2
0
<?php

require_once "{$docRoot}/inc/render.php";
require_once "{$docRoot}/inc/class.social.php";
require_once "{$docRoot}/source/data/add.php";
$LS->init();
$privacy = isset($_POST['privacy']) ? $_POST['privacy'] : "";
if ($_P && ($privacy == "pub" || $privacy == "fri" || $privacy == "meo")) {
    $post = $_POST['post'];
    /* Check if post contains any characters and not just white spaces */
    if ($post == '' || !preg_match("/[^\\s]/", $post)) {
        /* Show a JSON Format Error Message */
        $OP->ser("Post Can't be empty", "", "json");
    }
    $withoutMarkup = $OP->reverseMarkup($post);
    $SocialPost = new SocialPost($who);
    /* Social Posting if requested */
    if (isset($_POST['twitter'])) {
        $SocialPost->postToTwitter($withoutMarkup, $who);
    }
    if (isset($_POST['facebook'])) {
        $SocialPost->postToFacebook($withoutMarkup, $who, $privacy);
    }
    $imgURL = false;
    /* Upload image if exists */
    if (isset($_FILES['upload']) && $_FILES['upload']['tmp_name'] != "") {
        $imgURL = upload(curUser, false, $_FILES['upload']);
        if ($imgURL == "extensionNotSupported") {
            $OP->ser("Image not supported", "The image you uploaded is not supported. Try another image", "json");
        }
    }