phpBB.com     phpBB Academy     phpBB Modders     phpBB Weekly     ktuk     phpBB Hacks     Vlad Studio  

Tweet this post

Sends a link to a forum post to Twitter. Hashtags, post content and ShortURL's are optional

Not enough for a full proper MOD, but too useful not to share
Forum rules
Please read over our forum guidelines

Tweet this post

Postby kenny » 13 Mar 2009, 21:18

Following on from my "Tweet this topic" snippet, I thought I would carry on an release the "Tweet this post" snippet. I think you'll be able to guess what this does ;) Uses almost the same code as the other snippet.

Again, for a demo check these forums. I have it here ^_^
demo removed for performance reasons

OPEN: viewtopic.php
FIND:
Code: Select all
        $s_first_unread = $first_unread = true;
    } 

Code: Select all

    
// Tweet This Post
    $hashtag        = ' #phpBB #6StringMODs'; 

Comment:
Feel free to change your hashtags to whatever your feel like - your own sitename perhaps. It would also be nice to tweet this topic/post/page via your won account :P
Code: Select all
        'S_HAS_ATTACHMENTS'    => (!empty($attachments[$row['post_id']])) ? true : false, 

BEFORE ADD:
Code: Select all
        'TWEET_POST'        => urlencode('Read This: ') . generate_board_url() . "/viewtopic.$phpEx?f=$forum_id%26t=$topic_id%23p{$row['post_id']}" . htmlspecialchars(urlencode($hashtag)), 

OPEN: language/en/viewtopic.php
FIND:
Code: Select all
   'SUBMIT_VOTE'         => 'Submit vote',

AFTER ADD:
Code: Select all
   'TWEET_POST'         => 'Tweet this post',

OPEN: styles/prosilver/template/viewtopic_body.html
FIND:
Code: Select all
</h3>

BEFORE ADD:
Code: Select all
<span class="tweet-link"><a href="http://twitter.com/home?status={TWEET_POST}" class="tweet-link" title="{L_TWEET_POST}"></a></span>

Comment:
If you have already installed "Tweet this topic", then you can skip the next 2 steps and go straight to purging your cache

OPEN: styles/prosilver/theme/colours.css
FIND:
Code: Select all
a.right:hover {
   color: #5E7BAA;
}

AFTER ADD:
Code: Select all
.tweet-link a {
   float: left;
   background-image: url("{T_THEME_PATH}/images/twitter-logo.png");
   padding-left:18px;
   height: 18px;
   background-repeat: no-repeat;
   position: absolute;
}

Twitter logo - download/file.php?id=73

ps. I'm still working on the CSS issues with IE :oops:
Last edited by kenny on 27 Aug 2009, 09:09, edited 9 times in total.
Reason: Updated code to include hashtags & fixed Copy/Paste Fail :P
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

Donate to 6 String MODs
If you like any of the work that I do here, please consider donating.
click the image on the left for a list of some of the advantages of donating



Tweet this post

Postby kenny » 14 Mar 2009, 00:39

IE / other browser bugs fixed, thanks to Raimon's post here
Code in 1st post updated 8-)
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

Tweet this post

Postby kenny » 21 Mar 2009, 17:52

kenny wrote:Tweet this page :geek:
Using the same logic, you can add the TinyURL() function to this MOD :)
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

Tweet this post

Postby kenny » 21 Mar 2009, 20:14

Had a little request for this addition, which you can easily modify to your needs.
Basically it allows you add some of the post itself to the tweet :)

Replace
Code: Select all
        'TWEET_POST'        => urlencode("{$row['post_subject']}: ") . truncate_string($row['post_text'], 60, 255, true, '...') . generate_board_url() . "/viewtopic.$phpEx?f=$forum_id%26t=$topic_id%23p{$row['post_id']}", 

I added the phpbb truncate_string() function.
A little info on the params for those who aren't sure:

Code: Select all
truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = true, $append = '') 

Truncates string while retaining special characters if going over the max length
The default max length is 60 at the moment
The maximum storage length is there to fit the string within the given length. The string may be further truncated due to html entities.
For example: string given is 'a "quote"' (length: 9), would be a stored as 'a &quot;quote&quot;' (length: 19)

param: string $string The text to truncate to the given length. String is specialchared.
param: int $max_length Maximum length of string (multibyte character count as 1 char / Html entity count as 1 char)
param: int $max_store_length Maximum character length of string (multibyte character count as 1 char / Html entity count as entity chars).
param: bool $allow_reply Allow Re: in front of string
param: string $append String to be appended[/code]
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

Tweet this post

Postby kenny » 19 May 2009, 21:31

I have found a small bug in this snippet. I will attempt to fix it, but this might not come for a few days. Basically, if you have any kind of BBCode in the 1st few characters of the post, it will break the tweet. An example can be found in this post
The URL ends up as:

http://twitter.com/home?status=Last+Post+Subject+w%2F+Trim%3A+@[url=http
&#58;//twitter&#46;com/13thoughts:182izk6j]13th...http://tinyurl.com/o9eyf9


Smilies would also break this. If anyone can post a fix before I can, please feel free to do so. It will be very much appreciated. I will do my best to try and resolve this though :)
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

Tweet this post

Postby kenny » 21 May 2009, 15:51

Thanks to [phpbb]Erik Frèrejean[/phpbb] from the phpBB Support Team, I have managed to find a fix for the issue. I stripped out the bbcode from the text that was being sent to the tweet. phpBB has a built in function for stripping bbcode, but it doesn't return the text, so I duplicated it and made it return. Maybe not the best way to do it, but it works.

Here is the fix:

Comment:
#
#-----[ OPEN ]------------------------------------------
#
includes/functions_content.php
#
#-----[ FIND ]------------------------------------------
#
Code: Select all
/**
* For display of custom parsed text on user-facing pages

#
#-----[ BEFORE, ADD ]------------------------------------------
#
Code: Select all
/**
* Modified version of the previous function to strip bbcode from a post and return the plain text.
* This code is for the "Tweet This Post" MOD by cherokee red (kenny^).
* 6 String MODs - http://www.sixstringmods.co.uk
*/
function stripr_bbcode($text, $uid = '')
{
    if (!$uid)
    {
        $uid = '[0-9a-z]{5,}';
    }

    $text = preg_replace("#\[\/?[a-z0-9\*\+\-]+(?:=(?:&quot;.*&quot;|[^\]]*))?(?::[a-z])?(\:$uid)\]#", ' ', $text);

    $match = get_preg_expression('bbcode_htm');
    $replace = array('\1', '\1', '\2', '\1', '', '');

    $text = preg_replace($match, $replace, $text);
    return $text;
}
 

#
#-----[ OPEN ]------------------------------------------
#
viewtopic.php
#
#-----[ FIND ]------------------------------------------
#
Code: Select all
        $s_first_unread = $first_unread = true;
    } 

#
#-----[ AFTER, ADD ]------------------------------------------
#
Code: Select all
    // Tweet This Post
    $clean_text     = stripr_bbcode($row['post_text'], $row['bbcode_uid']);
    $hashtag        = " #phpBB #6StringMODs"; 

#
#-----[ FIND ]------------------------------------------
#
Code: Select all
            'TWEET_POST'        => urlencode("{$row['post_subject']}: ") . truncate_string($row['post_text'], 60, 255, true, '...') . generate_board_url() . "/viewtopic.$phpEx?f=$forum_id%26t=$topic_id%23p{$row['post_id']}",  

#
#-----[ REPLACE WITH ]------------------------------------------
#
Code: Select all
        'TWEET_POST'        => urlencode("{$row['post_subject']}: ") . truncate_string($clean_text, 60, 255, true, '...') . generate_board_url() . "/viewtopic.$phpEx?f=$forum_id%26t=$topic_id%23p{$row['post_id']}" . $hashtag,
 

If you haven't already, definitely think about implementing the TinyURL function into this snippet. It will at least save you a few characters in your tweet :)
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

Tweet this post

Postby kenny » 27 May 2009, 21:09

Fixed a small bug in the implementation of the hashtag.
You can find the fix here - bugs.php?p=1&t=11
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

Tweet this post

Postby rdean » 10 Aug 2009, 02:00

It doesn't look like urlencode is being passed to the html body ...

The code results like this --

Code: Select all
span class="tweet-link"><a href="http://twitter.com/home?status=" class="tweet-link" title="Tweet this post"></a></span></h3>


I've attached a screen shot of what I'm talking about .. can you assist?

Clipboard01.jpg
User avatar
rdean
Registered User
Registered User
 
Posts: 5
Joined: 10 Aug 2009, 01:53

Tweet this post

Postby kenny » 11 Aug 2009, 18:17

Hi, can you post me the code that you added into viewtopic.php. It's working fine on my site (although I have some custom modifications made to it). It may be a simple typo on your or even my own part :)
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

Tweet this post

Postby rdean » 11 Aug 2009, 19:35

Sure -- here's what I have in viewtopic

Code: Select all
   $s_first_unread = false;
   if (!$first_unread && $post_unread)
   {
      $s_first_unread = $first_unread = true;
   }


    // Tweet This Post
    $clean_text     = stripr_bbcode($row['post_text'], $row['bbcode_uid']);
    $hashtag        = " #phpBB #SurvivalOnlineUS";

   //
   $postrow = array(
      'POST_AUTHOR_FULL'      => get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
      'POST_AUTHOR_COLOUR'   => get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
      'POST_AUTHOR'         => get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
      'U_POST_AUTHOR'         => get_username_string('profile', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),

   


Code: Select all
      'TWEET_POST'      => urlencode("{$row['post_subject']}: ") . truncate_string($clean_text, 60, 255, true, ' ...') . TinyURL(generate_board_url() . "/viewtopic.$phpEx?f=$forum_id%26t=$topic_id%23p{$row['post_id']}") . htmlspecialchars(urlencode($hashtag)), 


- Ron
Last edited by rdean on 11 Aug 2009, 20:15, edited 1 time in total.
User avatar
rdean
Registered User
Registered User
 
Posts: 5
Joined: 10 Aug 2009, 01:53

Next



Return to Code Snippets

Who is online

Google [Bot]


cron