function wpinstaroll_automatic_post_creation() { // check for plugin requirements (without echoing error messages, just logging them) if (!wpinstaroll_check_requirements()) { wp_die(''); } $InstagramClientID = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_app_id'); $InstagramClientSecret = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_app_secret'); $user_access_token = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_user_accesstoken'); $search_tag = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_search_tag'); $scheduled_publication_period = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_scheduled_publication_period'); $scheduled_publication_stream = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_scheduled_publication_stream'); // is Instagram properly configured? // // if not, first reset event scheduling settings and removes event schedulation, then simply exits if (empty($InstagramClientID) || empty($InstagramClientSecret) || empty($user_access_token) || empty($scheduled_publication_period) || empty($scheduled_publication_stream)) { wpinstaroll_remove_scheduled_event(); update_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_scheduled_publication_period', 'never'); exit; } // inclusion of functions included only when opening WordPress backend require_once 'wp-admin/includes/admin.php'; // force current user to user with id == 1 (that should be an admin) wp_set_current_user(1); // retrieval of photos and post creation for new ones // user stream if ($scheduled_publication_stream == 'user' || $scheduled_publication_stream == 'user_tag') { $photoStream = wpinstaroll_getInstagramUserStream(); $data = $photoStream->data; if ($data) { // reverse the array, so that oldest photos are processed first $data = array_reverse($data); // ids of already published photos $published_ids = wpinstaroll_getInstagramPublishedPhotosIDs(); // scan the stream and publish new photos foreach ($data as $element) { // if the photo has not been published yet if (!in_array($element->id, $published_ids)) { wpinstaroll_createpostfromphoto($element->id, $element->images->standard_resolution->url, $element->link, $element->caption->text, $element->user->username, $element->user->id); } } } } // tag stream - only in this case, we check for search tag presence if (($scheduled_publication_stream == 'tag' || $scheduled_publication_stream == 'user_tag') && !empty($search_tag)) { $photoStream = wpinstaroll_getInstagramPhotosWithTag($search_tag); $data = $photoStream->data; if ($data) { $data = array_reverse($data); $published_ids = wpinstaroll_getInstagramPublishedPhotosIDs(); foreach ($data as $element) { if (!in_array($element->id, $published_ids)) { wpinstaroll_createpostfromphoto($element->id, $element->images->standard_resolution->url, $element->link, $element->caption->text, $element->user->username, $element->user->id); } } } } }
function wpinstaroll_photosbyusertable_ajax() { $app_id = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_app_id'); $app_secret = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_app_secret'); $user_access_token = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_user_accesstoken'); $search_tag = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_search_tag'); $instagram_username = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_user_username'); if (empty($app_id) || empty($app_secret) || empty($user_access_token)) { $instagram_settings_page = get_bloginfo('wpurl') . '/wp-admin/options-general.php?page=' . WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_menu'; print '<p><strong>You need to configure Instagram access from the <a href="' . $instagram_settings_page . '">Instagram Settings</a> panel inside the Settings menu.</strong></p>'; } else { print '<h3>Instagram stream for user: '******'</h3>'; // show user stream (user + friends photos) or only user photos (checked)? $show_useronly = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_show_useronly_photos'); if ($show_useronly != 'show_useronly') { $is_checked_useronly = ''; } else { $is_checked_useronly = 'checked="checked" '; } // don't show already selected photos, or show them (checked)? $show_published = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_show_published_photos'); if ($show_published != 'dont_show_published') { $is_checked_published = 'checked="checked" '; } else { $is_checked_published = ''; } print '<p><a class="button-primary" href="' . wpinstaroll_getInstagramGeneratedDraftPosts() . '">Go to Instagram draft posts</a>' . '<span class="top_right_buttons">' . '<span class="show_useronly_pics_check">Show only user Instagram photos (no friends) <input type="checkbox" ' . $is_checked_useronly . 'name="show_useronly" id="show_useronly_userpanel" value="yes" /> </span>' . '<span class="show_published_pics_check">Show already selected Instagram photos <input type="checkbox" ' . $is_checked_published . 'name="show_already_published" id="show_already_published_userpanel" value="yes" /> </span>' . '<a class="button-primary" id="Instagram_userphotosupdate" href="#">Update view</a></span></p>'; $user_feed = wpinstaroll_getInstagramUserStream(); $published_ids = array(); if ($show_published == 'dont_show_published') { $published_ids = wpinstaroll_getInstagramPublishedPhotosIDs(); } if ($user_feed) { ?> <div id="InstagramPhotosTable"> <table class="wp-list-table widefat fixed posts"> <thead> <tr> <th style="width: 165px;">Picture</th> <th style="width: 140px;">ID</th> <th style="width: 120px;">Tags</th> <th style="width: 34px;">Likes</th> <th style="width: 84px;">Comments</th> <th>Caption</th> <th style="width: 110px;">Creation time</th> <th style="width: 120px;">Author</th> <th style="width: 90px;">Action</th> </tr> </thead> <tbody> <?php $data = $user_feed->data; foreach ($data as $element) { // don't show this pic if it has already been published and 'show_published' flag is set to 'dont_show_published' if (!($show_published == 'dont_show_published' && in_array($element->id, $published_ids))) { print '<tr class="alternate author-self status-publish format-default iedit">'; print '<td class="insta_image"><a href="' . $element->link . '" target="_blank"><img src="' . $element->images->thumbnail->url . '" alt="" data-fullimageurl="' . $element->images->standard_resolution->url . '" /></a></td>'; print '<td class="insta_id">' . $element->id . '<br /> </td>'; $tags_string = ''; $tags = $element->tags; $tags_counter = 0; foreach ($tags as $tag) { if ($tags_counter++ > 0) { $tags_string .= ', '; } $tags_string .= $tag; } print '<td class="insta_tags">' . $tags_string . '<br /> </td>'; print '<td class="insta_likes_count">' . $element->likes->count . '<br /> </td>'; print '<td class="insta_comments_count">' . $element->comments->count . '<br /> </td>'; print '<td class="insta_description">' . $element->caption->text . '<br /> </td>'; print '<td class="insta_timestamp">' . date('Y-n-j H:i', $element->created_time) . '<br /> </td>'; print '<td class="insta_username">' . $element->user->username . '<br /> </td>'; print '<td class="insta_createpost"><a href="#" id="create_wp_post_' . $element->id . '" class="button-secondary ' . WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_createpost_action">Create post</a></td>'; print '</tr>'; } } ?> </tbody> </table> </div> <?php } } exit; // accessible with URL: // http://[HOST]/wp-admin/admin-ajax.php?action=wpinstaroll_photosbytagtable }