In this patch:
1. added/modified a couple functions to flickr.inc and flickr.module that were being rewritten over and over in all the different modules.
2. made flickr_block.module use our API instead of flickr_request.

I still need to look at flickr_filter, flickr_sets and flickr_tags to make sure the code is clean in those.

PLEASE TEST, BECAUSE I DIDN'T HAVE TIME TO :0

Comments

drewish’s picture

Status: Needs review » Needs work

i don't know what you mean about flickr_tags and flickr_sets... they're not in CVS...

you're calling flickr_get_photos() but it's not defined anywhere.
so don't go committing anything you don't have time to test, that's how i got us such a nice queue full of issues ;)

as part of this issue, i'd like to rename flickr_error() to flickr_request_has_error() or something more descriptive.

drewish’s picture

also as per the drupal coding style, you need to put spaces around = and =>.

andrewlevine’s picture

Status: Needs work » Needs review
StatusFileSize
new8.4 KB

i don't know what you mean about flickr_tags and flickr_sets... they're not in CVS...

Those are 2 modules that I wrote and submitted patches for. They were never committed and are out of date now, but IMHO when I get them working again they should be committed so we can get some testing from the community.

so don't go committing anything you don't have time to test

sorry to waste your time, I just wanted to get it in the queue in case I had no time to get back to it.

OK so the newest patch:

  • is a working version of the patch above (i tested it)
  • changes flickr_error to flickr_request_has_error
  • puts spaces around =>...but I didn't see where there wasn't spaces around an =
  • fixes the broken photosets block by adding a theme_flickr_block_photoset

Oh...and I checked flickr_filter and didn't find any API stuff that needed changing.

drewish’s picture

Status: Needs review » Needs work

gotcha on those other two modules, for some reason i thought they'd been committed. don't worry about time wasting, it's good to see improvements.

i guess it was existing code that had missing spaces around ='s.

i'm not sure how i feel about having the userid parsing code in flickr_photos_get(), it seems like it should be in a separate function since we'll need it several places. we should always pass a nsid to flickr_photos_get().

one thing i did notice that's not related to this patch is flickr_photos_get(). i don't really like the way it takes tags as a separate parameter. it seems to me it'd be better if all that went through a single arguments array.

andrewlevine’s picture

I actually agreed with you on that point 2 months ago...dejavu : http://drupal.org/node/116533

Let's get that committed and I'll rework this one.

The reason it takes tags as a separate array is so you don't have to worry about the flickr tags input syntax and implode them yourself. I personally don't care one way or another so I'll change that if you want.

drewish’s picture

sweet. i jsut committed that other patch. there's still some wonk but it was a good move in the right direction. i'd be into moving that tag exploding code out to the caller. if it gets used in multiple places then we can make it into a helper function.

andrewlevine’s picture

Since we're moving so much code out of flickr_photos_get, I think we should turn it into a regularish flickr API call wrapper (flickr_photos_search in flickr.inc).

It would be something like this:

function flickr_photos_search($nsid, $page = 1, $other_args = array()){
  $args = array (
    'user_id' => $nsid,
    'page' => $page,
  );

  //set per_page to flickr module default if it is not specified in $other_args
  if (!isset($other_args['per_page'])) {
    $args['per_page'] = variable_get('flickr_photos_per_page', 20);
  }

    return flickr_request('flickr.photos.search', array_merge($args, $other_args));
}

What do you think?

andrewlevine’s picture

Status: Needs work » Needs review
StatusFileSize
new11 KB

I really like how this patch is shaping up. I think it's RTBC now. Here is a list of everything this patch does:

  • Renames flickr_error to flickr_request_has_error
  • Adds flickr_is_nsid and flickr_get_nsid
  • Takes most of the stuff out of flickr_photos_get and make it flick_photos_search in flickr.inc
  • Create a tag handling function to turn an array into request args. (Not currently used but will be in flickr_tags)
  • Deletes module specific theme_photoset and adds theme_flickr_photoset_preview which is used by both block and filter
  • Change flickr_block and flickr.module to use our shiny improved API (thereby fixing just about everything that was broken)
drewish’s picture

i agree, this is looking like a really good set of changes.

reading the code i realized that flickr_request_has_error() should be flickr_response_has_error() because we're checking the result not the request. how about simplifying it to:

function flickr_response_has_error($response) {
  return (array_key_exists('stat', $response) && $response['stat'] == 'ok');
}

i wouldn't remove theme_flickr_filter_photoset() unless you also remove theme_flickr_filter_photo(). i think they should be able to override the filter theme functions separately from the regular photo theme functions. maybe it'd make sense to just have them pass the call along to theme_flickr_photoset_preview and theme_flickr_photo so there's a default implementation.

also, what are your thoughts on my comment on #136542 in terms of checking for errors and returning the relevant array member in our API wrapper functions?

andrewlevine’s picture

StatusFileSize
new12.12 KB

reading the code i realized that flickr_request_has_error() should be flickr_response_has_error() because we're checking the result not the request. how about simplifying it to:

I changed the name and simplified the function. Please make sure to check its logic because unless I'm more tired than I think I am, the logic in your snippet is incorrect.

maybe it'd make sense to just have them pass the call along to theme_flickr_photoset_preview and theme_flickr_photo so there's a default implementation.

Agreed, it's in the new patch.

also, what are your thoughts on my comment on #136542 in terms of checking for errors and returning the relevant array member in our API wrapper functions?

Yes. But lets get this patch committed first since it is getting big.

drewish’s picture

Status: Needs review » Reviewed & tested by the community

hehe, you're right. i'd dropped the !

function flickr_response_has_error($response) {
  return !(array_key_exists('stat', $response) || $response['stat'] != 'ok');
}

i remove the _preview from the photoset theme functions. since we pass in the full photoset they can theme it how ever they like. i also removed some parameters that were never being passed in.

if you're happy with this then lets commit it. as you said there's plenty of other stuff we need to get in once this is done.

drewish’s picture

StatusFileSize
new11.49 KB

oh, here's my patch

andrewlevine’s picture

This function really doesn't like you, I think you meant this:

function flickr_response_has_error($response) {
  return !(array_key_exists('stat', $response) && $response['stat'] == 'ok');
}

Can you re-roll and then I will test and commit?

drewish’s picture

StatusFileSize
new12.87 KB

doh. well here's a re-roll. i was using the flickr filter to do the testing and realized that the messages could use a little cleaning. we'll end up deleting them in the next set of changes but at least they'll be right until then.

andrewlevine’s picture

Status: Reviewed & tested by the community » Fixed

committed! i'll open another issue for the wrapper function changes we're making.

Anonymous’s picture

Status: Fixed » Closed (fixed)