This is mainly useful for groups users and public photo albums.
For example to get the most interesting public photos of the Eiffel Tower using Flickr Filter:
[flickr-user:id=public, size=q, num=8, location=48.85837/2.294481/0.5, filter=interesting]
location=48.85837/2.294481/0.5 (lon/lat/radius (in km))
URL: https://api.flickr.com/services/rest/?method=flickr.photos.search&api_ke...
After we can also add two blocks that dynamically grab a Geofield from the node to display photos from that location:
- Flickr: Node author photos with location from node
- Flickr: Public photos with location from node
It has the same fields as the 'Flickr: Node author photos optionally tagged as term from node' block, plus:
- Minimum amount of images to find (see below). Can also be set to 0. (integer)
- Smallest radius (in km). If the indicated minimum amount of images is found, results from within this circle are used.
- Times to double the radius if not enough results are found (integer). Irrelevant if the minimum amount is set to 0.
- Show nearest images first (checkbox). If not, the results will be mixed.
Comments
Comment #1
lolandese CreditAttribution: lolandese commentedComment #2
lolandese CreditAttribution: lolandese commentedComment #3
lolandese CreditAttribution: lolandese commentedA first shot. Not ready for review. Only posting to save the work done so far.
Comment #4
lolandese CreditAttribution: lolandese commentedAlthough not completed, above patch gives the desired result already.
Comment #5
AgentJay CreditAttribution: AgentJay commentedI'm getting:
Fatal error: Call to undefined function dsm() in /sites/all/modules/flickr/filter/flickr_filter.module on line 249
Indeed there does not seem to be dsm function, but it is referred to twice in the patch. commenting out the lines seems to do the trick.
I will attempt to add the bbox option as well using this as a guide.
Thanks!
Comment #6
lolandese CreditAttribution: lolandese commentedThe dsm() or dpm() functions are used to display some info about objects or variables for developing purpose. Enabling https://www.drupal.org/project/devel makes those functions available.
Comment #7
bogdog400 CreditAttribution: bogdog400 commentedThis looks promising. But I can't see the new blocks:
Flickr: Node author photos with location from node
Flickr: Public photos with location from node
Do I need to add them myself?
(I applied the patch by changing to directory sites/all/modules/flickr and then executing patch -p1 <*.patch)
Comment #8
lolandese CreditAttribution: lolandese commentedHi,
The dynamic context sensitive blocks are on the wishlist as a next step. First implementation as found in the patch only applies on Flickr Filter. The Eiffel Tower example is working. For now you can even create blocks that include a Flickr Filter, but it will show static content (one or more specific locations). Just put the example tag in a new block.
Beware. For now Devel should be enabled and it breaks some other parts of the Flickr module, so consider it experimental (not ready for a production site). I'll try to fix this ASAP.
Thanks for testing.
Comment #9
bogdog400 CreditAttribution: bogdog400 commentedYes, I got the Eiffel Tower to work. It's impressive. Thanks very much.
Let me know when you get the dynamic search running. It shouldn't be hard to snarf the lon/lat out of the Location field.
Comment #10
lolandese CreditAttribution: lolandese commentedAfter applying attached patch
results in
Comment #12
lolandese CreditAttribution: lolandese commentedFixed for Flickr Filter.
Comment #13
lolandese CreditAttribution: lolandese commentedFrom the issue description:
TODO
Comment #14
lolandese CreditAttribution: lolandese commentedComment #15
bogdog400 CreditAttribution: bogdog400 commentedThanks. This looks great. Is it hard to snarf the node's location dynamically?
Comment #16
lolandese CreditAttribution: lolandese commentedIt is similar to the patch at https://www.drupal.org/node/2024133#comment-8728979, but instead of using a taxonomy field it should use a Geofield.
Feel free to work on it. Patches are always committed with attribution. I will review almost instantly.
If not, I will get onto it, but I am a bit busy until Christmas.
Comment #17
bogdog400 CreditAttribution: bogdog400 commentedThanks very much. This was a big help. I'm using the Location module with GMap so I'm able to get the field by just using $node->location[].
BTW, any advice on handling caching? It seems like the block is cached and if I change nodes, the old one still appears. I would like to cache it based upon the dynamic location. So if I go to a new node, it goes out to flickr again. But if I go back to the old node, it would be good to cache block.
Let me know if you have any thoughts of the best way to handle this.
Comment #18
lolandese CreditAttribution: lolandese commentedYes. Of course also the Location field could be used as a source for the latitude and longitude. I guess a simple number field could hold the radius if there is the need to vary this parameter per content. If not, it could be set in the block configuration.
The block caching mechanism as introduced in https://www.drupal.org/node/2227669#comment-8654119 uses the functions cache_get and cache_set. The first parameter $cid (the cache ID) is used as a unique key for a block. If it contains the 'location', it uses a separate cache for each location. Maybe easier is to use the 'nid' as the block displays only once for each node, but should be unique per node.
I see now that somehow the above mentioned patch did not go completely into http://cgit.drupalcode.org/flickr/tree/block/flickr_block.module. I have to check if this is the case, if something went wrong there and what the implications are for our block caching.EDIT: All fine. Some part has moved to flickr.inc into the _flickr_album function. TODO: Write some lines on the caching mechanism in the module's developer documentation.Comment #19
bogdog400 CreditAttribution: bogdog400 commentedThere seems to be three layers of caching:
* Inside _flickr_album
* Inside flickr_request
* Somewhere I haven't found.
Fascinating.
And there is definitely some abuse of the function parameters. I'm not sure why $delta is used so many ways. (Except for backwards compatibility.)
Comment #20
lolandese CreditAttribution: lolandese commentedCorrect.
Ah, yes. I probably moved it there to have it only in one place, but forgot about it. All fine.
So you could use cache_get that uses the nid there inside $cid, but only in case we use a 'dynamic' block that changes on every node. Maybe it's better to implement the block caching once the rest is working?
Yes, we didn't want to break blocks on an existing site when they upgrade the Flickr module. In D8 we'll probably make one dynamic block that contains all configuration settings combined. The new block system will give the site builder the possibility to use it multiple times, even on the same page.
Comment #21
bogdog400 CreditAttribution: bogdog400 commentedI've adapted the caching inside _flickr_album and flickr_request, but I still see caching from Drupal. Once a filter block is constructed, it won't change. If I clear the cache and then load 2 or 3 nodes simulataneously, they'll all load with different blocks. But once the first one is complete, all nodes after that will contain an incorrect block.
I can't figure out where this caching occurs. It seems to be going on deep inside Drupal. Even when I install the module Block Cache Alter, I can't get anything to change. Once a Flickr filter block is computed, it sticks there until the cache is cleared. There aren't even any calls to the _flickr_album routine at all.
Comment #22
lolandese CreditAttribution: lolandese commentedJust to clarify, as I understand from the line above you create a new block through admin/structure/block/add and use a text filter that contains the Flickr Filter, right?
You can create blocks with Flickr content that way, but it will be hard to make their content dynamic depending on the node that is on the same page as the block.
If you create a block from inside the module's code as done in the patch mentioned in #16, the module's own caching mechanism kicks in. From function _flickr_album() in flickr.inc on line 502:
This piece of code is called each time you render a programmatic created Flickr block, using the unique $cid caching key, resulting in context sensitive blocks. It is not called when rendering a "Drupal system created" block containing a text filter. The text filter that you put in a block's text field uses the same piece of code, but it is called only when saving the block. That version remains in the block until the site cache is cleared.
Let me know if what I described is indeed your case or not.
Comment #23
bogdog400 CreditAttribution: bogdog400 commentedYup, you're right. I'm just using the text filter mechanism. It was pretty simple to rewrite the filter code to grab the location from the node. But when I played with the caching, it became clear that Drupal wasn't calling the filter code very often. Once the block was built for the first time, Drupal kept it in its own cache. It doesn't seem to call the module code after that.
Your insight about the plugin-created block is useful. I'll play around with that. Then we'll see if that avoids this caching issue.
Comment #24
bogdog400 CreditAttribution: bogdog400 commentedBTW, do you know another way to change the caching properties of the blocks defined by the Drupal system? I've tried "Block Cache Alter" but it doesn't seem to do what I expect.
Comment #25
lolandese CreditAttribution: lolandese commentedI guess the problem is that the Flick content is in a text field within the block that is generated on block save or after clearing the cache. Excluding a block from being cached probably does not cover this case as it does not clear the cache actively for the block but only prevents the block from being cached. Note: This might be not true.
You could try the CacheExclude module on the pages with the blocks that you want to target. If I understood right, it concerns all page content, including the blocks.
Personally I would not sacrifice site performance just to solve this problem. The proper solution I have already given and is not too difficult. A possible approach:
Comment #26
bogdog400 CreditAttribution: bogdog400 commentedThanks. I'll take a look at this next week. You've got a deep understanding of the caching structure of Drupal.
Comment #27
bogdog400 CreditAttribution: bogdog400 commentedDo I want to make the new block cache globally? Here's what I have:
Doesn't this make more sense if the flickr search will be tied to the location field of the node?
Comment #28
lolandese CreditAttribution: lolandese commentedProbably yes. I have to study https://api.drupal.org/api/drupal/includes%21common.inc/group/block_cach.... I wonder even if it is still used.
Feel free to fill me in on this one.
Comment #29
lolandese CreditAttribution: lolandese commentedLogic tells us that the module now handles it's own cache for all blocks that use function call _flickr_album() through flickr_block_view(). We should run a test using DRUPAL_CACHE_CUSTOM for those and see the impact. Probably none as the cache gets overridden anyway by cache_get()?
It is probably a remainder of the old code base.
Comment #30
bogdog400 CreditAttribution: bogdog400 commentedThat setting for DRUPAL_CACHE_PER_PAGE seems to work fairly well. It's behaving as I expect-- and it's easy to test since the Flickr call takes a bit of time. So the impact of the caching is obvious.
Comment #31
lolandese CreditAttribution: lolandese commentedBack to the new Flickr Filter functionality.
The example tag in the text filter tips (
[flickr-user:id=public, size=q, num=5,location=48.85837/2.294481/0.2,filter=interesting]
) currently provokes the following error:Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1566 of /home/martin/www/brown/includes/bootstrap.inc).
As is was working properly before, this is due to a probably temporary Flickr API bug that we just reported at https://www.flickr.com/groups/api/discuss/72157649006719348/.
Nevertheless we will build a safety catch in case
$place_name = $place_id['places']['place'][0]['name']
returns an array instead of the usual string.Comment #32
lolandese CreditAttribution: lolandese commentedSafety catch patch.
Comment #34
lolandese CreditAttribution: lolandese commentedComment #35
lolandese CreditAttribution: lolandese commentedSetting back to active to implement static and dynamic location based Flickr blocks.
Comment #36
lolandese CreditAttribution: lolandese commentedAdditional feature request:
Block 'Flickr photos near you optionally tagged as term from node'
For example an article tagged with 'graffiti' would automatically show a block titled 'Most interesting Flickr photos tagged graffiti near you (Asnières-sur-Seine, Île-de-France, France)'.
HTML5 Geolocation transparently asks the browser for the user's current location. Works great on Chrome and smartphones with GPS. It is part of the Geofield module.
Comment #37
lolandese CreditAttribution: lolandese commentedComment #38
lolandese CreditAttribution: lolandese commentedAttached patch adds dynamic block grabbing the location from a geofield. The radius is auto expanding until the required number of results are found.
TO DO:
Comment #39
lolandese CreditAttribution: lolandese commentedCommit candidate.
To see if to integrate before commit or open new issues for:
Comment #40
lolandese CreditAttribution: lolandese commentedAdded support for the Location module.
Opened a new issue for the additional feature request: #2438241: New block 'Flickr photos near you optionally tagged as term from node'
TO DO:
Comment #41
lolandese CreditAttribution: lolandese commentedComment #43
lolandese CreditAttribution: lolandese commentedComment #44
bogdog400 CreditAttribution: bogdog400 commentedThanks very much. I'll give it a spin.