Example #1
0
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);
                }
            }
        }
    }
}
Example #2
0
function wpinstaroll_photosbytagtable_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');
    if (empty($app_id) || empty($app_secret) || empty($user_access_token) || empty($search_tag)) {
        $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.<br/><br/>Note: the "Search Tag" field but be filled, for this panel to work!</strong></p>';
    } else {
        print '<h3>Instagram tag: ' . $search_tag . '</h3>';
        // show all photos or only user photos with specified search tag (checked)?
        $show_useronly = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_show_useronly_photos_by_tag');
        if ($show_useronly != 'show_useronly_by_tag') {
            $is_checked_useronly = '';
        } else {
            $is_checked_useronly = 'checked="checked" ';
        }
        $show_published = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_show_published_photos');
        if ($show_published != 'dont_show_published') {
            $is_checked = 'checked="checked" ';
        } else {
            $is_checked = '';
        }
        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&nbsp;<input type="checkbox" ' . $is_checked_useronly . 'name="show_useronly" id="show_useronly_tagpanel" value="yes" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>' . '<span class="show_published_pics_check">Show already selected Instagram photos&nbsp;<input type="checkbox" ' . $is_checked . 'name="show_already_published" id="show_already_published_tagpanel" value="yes" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>' . '<a class="button-primary" id="Instagram_tagphotosupdate" href="#">Update view</a></span></p>';
        $tag_feed = wpinstaroll_getInstagramPhotosWithTag($search_tag);
        $published_ids = array();
        if ($show_published == 'dont_show_published') {
            $published_ids = wpinstaroll_getInstagramPublishedPhotosIDs();
        }
        if ($tag_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 = $tag_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 />&nbsp;</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 />&nbsp;</td>';
                    print '<td class="insta_likes_count">' . $element->likes->count . '<br />&nbsp;</td>';
                    print '<td class="insta_comments_count">' . $element->comments->count . '<br />&nbsp;</td>';
                    print '<td class="insta_description">' . $element->caption->text . '<br />&nbsp;</td>';
                    print '<td class="insta_timestamp">' . date('Y-n-j H:i', $element->created_time) . '<br />&nbsp;</td>';
                    print '<td class="insta_username">' . $element->user->username . '<br />&nbsp;</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
}