I've had to write a patch to support displaying of tweets images in a view. The patch provides a new views field "Photo 1" and some new checkboxes in settings for the message text views field:

  • Replace urls with their long version
  • Remove media urls

The latter is intended to remove the URL to the photo in a tweet if adding the photo tio the view.

If it's useful I'll have a look at reproducing it in 7.x branch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hughworm’s picture

hughworm’s picture

You can see it in action in all it's glory at www.gethooked.co.uk.

hughworm’s picture

Revised patch.

Yorgg’s picture

Can you help port this to the 7.x branch?

recrit’s picture

Version: 6.x-5.0 » 7.x-5.x-dev
Issue summary: View changes
FileSize
4.25 KB

The attached patch is applied to 7.x-5.x. It only addresses storage and loading of the entities.

The patch adds the following:
* entities field to the twitter table
* views field handler for the first image attached to the tweet
* updates to loading and saving tweets to serialize and unserialize

juampynr’s picture

  1. +++ b/twitter.inc
    @@ -138,8 +138,14 @@ function twitter_load_authenticated_accounts() {
    +  if ($row && isset($row->entities) && is_string($row->entities)) {
    

    We could just do if (!empty($row->entities) && (is_string($row->entities)) {

  2. +++ b/twitter.install
    @@ -427,3 +434,18 @@ function twitter_update_7500() {
    +function twitter_update_7501() {
    
    @@ -109,6 +109,13 @@ function twitter_schema() {
    +        'serialize' => TRUE,
    

    Misssing &$sandbox argument here.

  3. +++ b/twitter_views_field_handlers.inc
    @@ -163,3 +163,32 @@ class twitter_views_handler_field_formatted_tweet extends views_handler_field {
    +      elseif (is_object($values->twitter_entities)) {
    

    Why could it be an object or a string? Shouldn't it always be just a string to be deserialized?

  4. +++ b/twitter_views_field_handlers.inc
    @@ -163,3 +163,32 @@ class twitter_views_handler_field_formatted_tweet extends views_handler_field {
    +      if (isset($entities->media) && is_array($entities->media)) {
    

    If we use !empty() instead of isset() we also check that the array contains values.

juampynr’s picture

Status: Needs review » Needs work

Reopening.

recrit’s picture

I can re-roll with:
* Update function adding &$sandbox,
* Simplifying with !empty()

The is_object() check was in case it was already unserialized. The thinking was more of a handler like the entity field hander where the object would be loaded upfront with twitter_status_load(). Since this is not the case this check could be removed.

recrit’s picture

Status: Needs work » Needs review
FileSize
4.19 KB

updated patch per requests in #6 and applied to the latest 7.x-5.x.

juampynr’s picture

  1. +++ b/twitter.inc
    @@ -138,8 +138,14 @@ function twitter_load_authenticated_accounts() {
    +  if ($row && isset($row->entities) && is_string($row->entities)) {
    

    Is this correct? I did not know that fetchObject() would return an "entities" property.

  2. +++ b/twitter.views.inc
    @@ -157,6 +157,16 @@ function twitter_views_data() {
    +  $data['twitter']['tweet_first_image'] = array(
    

    Why "first" ?

juampynr’s picture

Based on https://support.twitter.com/articles/20156423-posting-photos-on-twitter, only one photo can be uploaded to Twitter.

juampynr’s picture

Status: Needs review » Fixed

Made the following changes and committed it:

  • Changed field name from first image to just image.
  • Added an option to the field so a size can be chosen out of the ones that Twitter offer.
  • Simplified conditions to check if the entities field has content.
  • Added a missing step to extract the entities from the object returned by Twitter into TwitterStatus class.

http://drupalcode.org/project/twitter.git/commit/3bac2d7

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

capellic’s picture

Status: Closed (fixed) » Needs work

Sorry if reopening this issue is the wrong course of action. I just downloaded "7.x-5.x-dev", ran update.php, and saw the the Image field appear as an option. Problem is that the image doesn't display at all -- only the empty DIV wrappers. Also, I can't select the Image field as a conditional. (I want to only show tweets that have a photo.) Am I downloading the right version? Thanks.

Baysaa’s picture

@capellic I've got same issue with the 7.x-5.x-dev version. However go to the commit log at #12 and you can see the diff there. Copy it, make it into a patch and apply it to 7.x-5.8 and run update.php and it works.

recrit’s picture

@juampy: Regarding "first image", Twitter allows up to 4 images to be uploaded per articlet that referenced: https://support.twitter.com/articles/20156423-posting-photos-on-twitter.
A possible improvement would to update the help text to state "The first image attached to the tweet.".

Dr Trichome’s picture

@baysaa I successfully applied the patch to 7.x-5.8, ran drush updb, enabled the twitter:image in views, and ran cron. I can see an empty label (image:), but still no images are being pulled in from twitter. I have "formatted tweet" enabled in views, and everything else is there, just not the image associated with the tweet. What should I try next?

DamienMcKenna’s picture

Version: 7.x-5.x-dev » 7.x-6.x-dev
Status: Needs work » Patch (to be ported)

Needs to be ported to the 7.x-6.x branch.

DamienMcKenna’s picture

Danny Englander’s picture

I am experiencing the same issue as #14 & #17 above, an image label but no image. (also ran drush updb successfully). This is from the latest dev 5.x. I have a native twitter image uploaded to Twitter and rendered using their image service. I am not sure I understand the comment in #15, make a patch to apply to something that's already been committed to dev on top of that? In my local git, I see all the changes in dev that were in the patch.

erald’s picture

I have the same issue applied the patch from #12 ran update deleted the account readied it and pulled again via cron but no images there.
Added the twitter image to the view
>> never mind I had to activate the mentions it is working perfectly
sorry for the spamming

DamienMcKenna’s picture

Version: 7.x-6.x-dev » 7.x-5.x-dev
Status: Patch (to be ported) » Needs work

Lets go back to 7.x-5.x and fix it, then see about porting it to 7.x-6.x and 6.x-5.x.

DamienMcKenna’s picture

DamienMcKenna’s picture

Images are working ok for me with the current 7.x-5.x-dev release:
Works for me?

DamienMcKenna’s picture

The images are not being displayed in the 6.x-5.x branch, and I don't have an installation of the 7.x-6.x branch - anyone able to confirm the problem?

DamienMcKenna’s picture

Yes, so the 'entities' system needs to be ported to both the 6.x-5.x and 7.x-6.x branches. There's also an 'extended_entities' structure in the tweet JSON object, it may be worthwhile storing that too, just to have it, which would then also need to be ported to 7.x-5.x.

DamienMcKenna’s picture

Taking this off the rota for the next releases.

DamienMcKenna’s picture

Version: 7.x-5.x-dev » 7.x-6.x-dev
tescometro’s picture

Apologies if, but did this get added to any release for 6.x ? Or is it planned to?

Thanks for the module (using 6.x 5.3), working well, just the images would be extra nice!

DamienMcKenna’s picture

@tescometro: No, sorry, the functionality needs to be backported to 6.x-5.x.

homebrewruss’s picture

For anyone one using the latest 7.x-5.x dev version but struggling to get images to display. Make sure you uninstall any versions of the Twitter module you already have installed from the database before re-installing the latest dev version.
Images should then work fine.

DamienMcKenna’s picture

@homebrewruss: You shouldn't have to uninstall to make it work - if anyone's having a problem getting it to work then please open an issue and I'll see if I can help fix the problem.

DamienMcKenna’s picture

Status: Needs work » Patch (to be ported)

This needs to be ported.

kevineinarsson’s picture

Status: Patch (to be ported) » Needs review
FileSize
5.93 KB

Attached is a patch ported for 7.x-6.x. Also updated the tweet template to show the field with hardcoded sizes (small image linked to large).

kevineinarsson’s picture

Got an extra unserialize in there... fixed

kevineinarsson’s picture

Ok, I'm quite tired and I messed up again... forgot adding in another line. Next time I won't be lazy and actually check out the repo into the server on which I'm working and not have it on my local machine... :)

This patch also fixes an issue where arrays were being serialized twice while storing into the database.

Also removed the hard-linking of the tweet image to the full size image in the template. It seems unneccessary to force and can easily be added back in for those who want it.

Status: Needs review » Needs work

The last submitted patch, 36: twitter-tweet-photos-d7-1936598-36.patch, failed testing.

kevineinarsson’s picture

Jeez... I had fat fingered a paranthesis in the last patch. This will hopefully be my last attempt at submitting the same patch. ;) Let's try this again.

kevineinarsson’s picture

Baysaa’s picture

DamienMcKenna’s picture

Title: Add support for tweet images » Add support for displaying tweet images