Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display pictures in twitter feed? #51

Closed
vinhdizzo opened this issue May 3, 2016 · 13 comments
Closed

Display pictures in twitter feed? #51

vinhdizzo opened this issue May 3, 2016 · 13 comments

Comments

@vinhdizzo
Copy link
Contributor

Hi,

Is there an option to display pictures as opposed to the twitter url to the picture in the twitter feed generated by tweetledee? Thanks.

@chrissimpkins
Copy link
Collaborator

Does this closed issue address your question?

#29

@vinhdizzo
Copy link
Contributor Author

Thanks for pointing to the thread, but I'm not sure how to incorporate it. For reference, I'm using tweedledee's homerss.php. Where do I put

if(isset($currentitem['entities']['media'][0]['media_url'])):
    $picurl = $currentitem['entities']['media'][0]['media_url'];
endif;  

? That gives the url. How do I get it to display the image? Thanks for your help.

@chrissimpkins
Copy link
Collaborator

chrissimpkins commented May 4, 2016

Let's give this a shot.

Revise Parsed Data in the Individual Tweets

Replace this block:

                if (isset($currentitem['retweeted_status'])) :
                    $avatar = $currentitem['retweeted_status']['user']['profile_image_url'];
                    $rt = '&nbsp;&nbsp;&nbsp;&nbsp;[<em style="font-size:smaller;">Retweeted by ' . $currentitem['user']['screen_name'] . ' <a href=\'http://twitter.com/' . $currentitem['user']['screen_name'] . '\'>@' . $currentitem['user']['screen_name'] . '</a></em>]';
                    $tweeter =  $currentitem['retweeted_status']['user']['screen_name'];
                    $fullname = $currentitem['retweeted_status']['user']['name'];
                    $tweetTitle = $currentitem['retweeted_status']['text'];
                else :
                    $avatar = $currentitem['user']['profile_image_url'];
                    $rt = '';
                    $tweeter = $currentitem['user']['screen_name'];
                    $fullname = $currentitem['user']['name'];
                    $tweetTitle = $currentitem['text'];          
               endif;

with this:

                if (isset($currentitem['retweeted_status'])) :
                    $avatar = $currentitem['retweeted_status']['user']['profile_image_url'];
                    $rt = '&nbsp;&nbsp;&nbsp;&nbsp;[<em style="font-size:smaller;">Retweeted by ' . $currentitem['user']['screen_name'] . ' <a href=\'http://twitter.com/' . $currentitem['user']['screen_name'] . '\'>@' . $currentitem['user']['screen_name'] . '</a></em>]';
                    $tweeter =  $currentitem['retweeted_status']['user']['screen_name'];
                    $fullname = $currentitem['retweeted_status']['user']['name'];
                    $tweetTitle = $currentitem['retweeted_status']['text'];
                else :
                    $avatar = $currentitem['user']['profile_image_url'];
                    $rt = '';
                    $tweeter = $currentitem['user']['screen_name'];
                    $fullname = $currentitem['user']['name'];
                    $tweetTitle = $currentitem['text'];
                    if(isset($currentitem['entities']['media'][0]['media_url'])):
                        $picurl = $currentitem['entities']['media'][0]['media_url'];
                    endif;                
               endif;

Update CDATA Section

Replace this block:

<description>
                    <![CDATA[
                        <div style='float:left;margin: 0 6px 6px 0;'>
                            <a href='https://twitter.com/<?php echo $twitterName ?>/statuses/<?php echo $currentitem['id_str']; ?>' border=0 target='blank'>
                                <img src='<?php echo $avatar; ?>' border=0 />
                            </a>
                        </div>
                        <strong><?php echo $fullname; ?></strong> <a href='https://twitter.com/<?php echo $tweeter; ?>' target='blank'>@<?php echo $tweeter;?></a><?php echo $rt ?><br />
                        <?php echo $parsedTweet; ?>
                    ]]>
</description>

with this:

<description>
                    <![CDATA[
                        <div style='float:left;margin: 0 6px 6px 0;'>
                            <a href='https://twitter.com/<?php echo $twitterName ?>/statuses/<?php echo $currentitem['id_str']; ?>' border=0 target='blank'>
                                <img src='<?php echo $avatar; ?>' border=0 />
                            </a>
                        </div>

                        <strong><?php echo $fullname; ?></strong> <a href='https://twitter.com/<?php echo $tweeter; ?>' target='blank'>@<?php echo $tweeter;?></a><?php echo $rt ?><br />
                        <?php echo $parsedTweet; ?>
                        if(isset($currentitem['entities']['media'][0]['media_url'])):
                            <img src='<?php echo $picurl; ?>' border=0 />
                        endif;
                    ]]>
</description>

@vinhdizzo
Copy link
Contributor Author

Thanks Chris. I made the modifications. For tweets with images, it does display the image. However, the if(isset($currentitem['entities']['media'][0]['media_url'])): line is also displayed in the tweet:

<item>
<title>
[drob] Against data-driven decision making https://t.co/iImaOqwvHm
</title>
<pubDate>Wed, 04 May 2016 13:00:18 +0000</pubDate>
<link>
https://twitter.com/vinhdizzo/statuses/727845306952499200
</link>
<guid isPermaLink="false">727845306952499200</guid>
<description>
<![CDATA[
<div style='float:left;margin: 0 6px 6px 0;'> <a href='https://twitter.com/vinhdizzo/statuses/727845306952499200' border=0 target='blank'> <img src='http://pbs.twimg.com/profile_images/777175344/David_Robinson_normal.jpg' border=0 /> </a> </div> <strong>David Robinson</strong> <a href='https://twitter.com/drob' target='blank'>@drob</a><br /> Against data-driven decision making <a href="https://t.co/iImaOqwvHm" target="blank">pic.twitter.com/iImaOqwvHm</a> if(isset($currentitem['entities']['media'][0]['media_url'])): <img src='http://pbs.twimg.com/media/ChnTcy9WEAIKkGr.jpg' border=0 /> endif;
]]>
</description>
</item>

As a matter of fact, this line gets pasted in all tweets, even if there is no image.

@chrissimpkins
Copy link
Collaborator

My fault. We are rendering raw php. It's been awhile since I tackled any PHP code. For the second codeblock, try this instead:

<description>
                    <![CDATA[
                        <div style='float:left;margin: 0 6px 6px 0;'>
                            <a href='https://twitter.com/<?php echo $twitterName ?>/statuses/<?php echo $currentitem['id_str']; ?>' border=0 target='blank'>
                                <img src='<?php echo $avatar; ?>' border=0 />
                            </a>
                        </div>

                        <strong><?php echo $fullname; ?></strong> <a href='https://twitter.com/<?php echo $tweeter; ?>' target='blank'>@<?php echo $tweeter;?></a><?php echo $rt ?><br />
                        <?php echo $parsedTweet; ?>
                        <?php if(isset($currentitem['entities']['media'][0]['media_url'])):
                            <img src='<?php echo $picurl; ?>' border=0 />
                        endif; ?>
                    ]]>
</description>

Note that we are wrapping the if(isset... in php tags. Let me know if this does the trick.

@vinhdizzo
Copy link
Contributor Author

No worries. I inspected the code and modified it as:

<?php if(isset($currentitem['entities']['media'][0]['media_url'])): ?>
<img src='<?php echo $picurl; ?>' border=0 />
<?php endif; ?>

which worked for me.

Will you be rolling this into all the php files in master or will you be leaving this as a hack for the user? Thanks.

@chrissimpkins
Copy link
Collaborator

How are you reading the RSS feed? Mind verifying that there are no issues in those tweets without images?

Let's consider merging this in for everyone. Welcome to pull request it if you would like to contribute it.

@vinhdizzo
Copy link
Contributor Author

I'm using tiny tiny RSS to read the feed.

Yes, tweets without image works fine.

I've never done a pull request, but I'll give it a try, perhaps later this week? Thanks for your help.

@chrissimpkins
Copy link
Collaborator

Is this your first contribution to an open source project? If so, that is fantastic! If you're interested let's definitely get you through your first pull request so that you can see how simple it is to participate in collaborative development.

Do you know how to use git?

@vinhdizzo
Copy link
Contributor Author

I know the basics of git. I've contributed to open source projects via diff files or describing changes via text, just never via a pull request. I think I could figure it out ;)

@chrissimpkins
Copy link
Collaborator

  1. Click fork button on this repo (top right)
  2. Pull the forked repository in your account locally
  3. Make changes
  4. Push local commits back to your remote branch
  5. Click Pull Request button on the GitHub page for your forked repo. It will be available after you push your changes.

Look forward to it!

vinhdizzo added a commit to vinhdizzo/tweetledee that referenced this issue May 5, 2016
@vinhdizzo
Copy link
Contributor Author

OK, I modified 10 files of the form *rss*.php and submitted a pull request. Hope this works out. Thanks!

@chrissimpkins
Copy link
Collaborator

@vinhdizzo Merged and added you to the contributors list on the home page of our documentation:

http://chrissimpkins.github.io/tweetledee/index.html

Thanks for this PR! When/if I get around to modifying the variables, I will poke you to see if you are still interested in testing it. This will work just fine for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants