Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author FeliceMente

    (@felicemente)

    Thanx for the feedback.

    At the moment filtering by tag the pics on the user stream is not possible, but, togheter with this (http://wordpress.org/support/topic/plugin-wp-instaroll-you-need-to-configure-message-persists), could maybe be added in a later release.

    Thread Starter vitious

    (@vitious)

    Thank you for the quick reply.
    I’ve tried that code modifiactions, they’re working fine and now I’m wondering if there’s a way in the meanwhile to modify that call in order to include also a tag endpoint? That would be a temporary solution obviously, I haven’t dug into the api that much.

    Thread Starter vitious

    (@vitious)

    Just a quick update.
    I’m working on a filter for the output of the json_decode inside wpinstaroll_getInstagramUserStream that only displays results if a tag criteria is matched (reading $photo_data->data->tags). So far no luck.
    Am I going in the right direction or is this approach wrong?
    Forgive me, I’m just learning this.
    Thanks again

    Plugin Author FeliceMente

    (@felicemente)

    There’s no Instagram API for doing this (filter by user + tag) directly, so I think there are two approches:

    – getting the user stream, reading $photo_data->data->tags (it’s an array), then see if the chosen tag is present or not (and maybe use a regex for fine-tuning the search)

    – using the other API, getting the stream based on the chosen tag and then checking for the ID ($element->user->id) against your user id (get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX.’_instagram_user_userid’))

    Thread Starter vitious

    (@vitious)

    Hi there,
    I was considering the same approaches. For testing purposes I modified the first API (userStream), the code below filters correctly for the passed tag (#exampleofpassedtag). Now I’m restoring the API to it’s original status and working on modifying the second (PhotosWithTag), because I think the right way to do it is panel->choose tag and let the API assume by default you are the user to filter by. I’ll let you know. Meanwhile, thanks again for your work and, of course, any suggestion or correction is more than welcome.

    // *** INSTAGRAM API ***
    
    // gets Instagram stream for current logged user (contains pics sent only by the user*)
    
    function wpinstaroll_getInstagramUserStream()
    {
    	$accessToken = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX.'_instagram_user_accesstoken');
    
    	if (empty($accessToken))
    		return null;
    
    	// API: http://instagr.am/developer/endpoints/users/
    	//$file_contents = @file_get_contents(WP_ROLL_INSTAGRAM_USER_STREAM_URLBASE.$accessToken);
    
    	// old code contained pictures sent both by users and his friends
    	//$file_contents = @curl_file_get_contents(WP_ROLL_INSTAGRAM_USER_STREAM_URLBASE.$accessToken);
    
    	// *modified: retrieves only photos by instagram userid fetched from db stored during authorization
    	// see: http://wordpress.org/support/topic/plugin-wp-instaroll-you-need-to-configure-message-persists
    
    	$instagram_user_id = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX.'_instagram_user_userid');
    	$file_contents = @curl_file_get_contents('https://api.instagram.com/v1/users/'.$instagram_user_id.'/media/recent/?access_token='.$accessToken);
    
    	if (empty($file_contents))
    		return null;
    
    	// first of all decode the stream
    	$photo_data = json_decode($file_contents);
    
    	// declare a function that searches for a a tag and, if present, returns true
    	function test_tags($test_me)
    	{
    		$tag_array = $test_me->tags;
    		foreach ($tag_array as $tag_check)
    		{
    			if ($tag_check==="exampleofpassedtag")
    				return true;
    			else
    				return false;
    		}
    	}
    
    	// filter the data array with the test function
    	$photo_data_array = $photo_data->data;
    	$photo_data->data = array_filter($photo_data_array, "test_tags");
    
    	// proceed as before with the filtered $photo_data
    
    	// add photo data (if new) to local db
    	wpinstaroll_updateLocalDBWithNewPhotos($photo_data);
    
    	return $photo_data;
    
    }
    Thread Starter vitious

    (@vitious)

    Here it is, the second API. Now in the second tab there are only pictures by current user with the panel-choosen tag.

    // gets Instagram pics corresponding to passed hashtag
    // testing a filter by userid
    
    function wpinstaroll_getInstagramPhotosWithTag($tag)
    {
    	if (empty($tag))
    		return null;
    
    	$accessToken = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX.'_instagram_user_accesstoken');
    
    	if (empty($accessToken))
    		return null;
    
    	// API: http://instagr.am/developer/endpoints/tags/
    	//$file_contents = file_get_contents(WP_ROLL_INSTAGRAM_STREAM_BYTAG_URL_A.$tag.WP_ROLL_INSTAGRAM_STREAM_BYTAG_URL_B.$accessToken);
    	$file_contents = @curl_file_get_contents(WP_ROLL_INSTAGRAM_STREAM_BYTAG_URL_A.$tag.WP_ROLL_INSTAGRAM_STREAM_BYTAG_URL_B.$accessToken);
    
    	if (empty($file_contents))
    		return null;
    
    	$photo_data = json_decode($file_contents);
    
    	// declare a function that checks against userid
    	function test_id($test_var)
    	{
    		$id = $test_var->user->id;
    		if ($id === get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX.'_instagram_user_userid'))
    			return true;
    		else
    			return false;
    	}
    
    	// filter the data array with the test function
    	$photo_data_array = $photo_data->data;
    	$photo_data->data = array_filter($photo_data_array, "test_id");
    
    	// proceed as before with the filtered $photo_data
    	// add photo data (if new) to local db
    	wpinstaroll_updateLocalDBWithNewPhotos($photo_data);
    
    	return $photo_data;
    
    }

    Plugin Author FeliceMente

    (@felicemente)

    Nice!
    That’s surely a thing that can be added in the next release (maybe, as for this request http://wordpress.org/support/topic/plugin-wp-instaroll-you-need-to-configure-message-persists, with a checkbox in the second tab, for switching betwing tag only mode and tag+user mode).

    Do you think it’s a good way of presenting this possibility?

    Thread Starter vitious

    (@vitious)

    Yes, checkbox is the way in my opinion, a third tab would be confusing.
    First tab: user stream with a checkbox for user-only photos.
    Second tab: chosen tag stream with a checkbox for user-only photos.

    OT:
    If you’re in the process of releasing a new version, consider also this
    feature: I’ve added to your wpinstaroll_createpostfromphoto function, in the $post_args array, ‘tags_input’ => ‘add_this_tag’. Adds a custom tag to the post. It could be taken from a box in the settings but I haven’t modified the settings since I’ll be only using one tag.

    As always, thanks.

    Plugin Author FeliceMente

    (@felicemente)

    Good suggestion, and easy to add.

    Thanx! πŸ™‚

    Plugin Author FeliceMente

    (@felicemente)

    Both suggestions have been added to the upcoming 1.1 release of the plugin!

    Thread Starter vitious

    (@vitious)

    That’s great news, looking forward to it. Thanks.

    Plugin Author FeliceMente

    (@felicemente)

    Version 1.1 is out but, while using it, I noticed that implementing, for tab stream, the user filter, just by taking the tag stream and checking the id, can result in no photos showed is there are many photos by other people that are newer that the user ones, so… version 1.1.1 of the plugin will use a different version of the function, implementing the other method I suggested in this thread.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Plugin: WP-Instaroll] Filter by user and hashtag’ is closed to new replies.