Tweet this topic and/or post

Post your MODs, receive and provide feedback!
Topics in this forum are not for MOD support, they are for giving the author feedback.
Forum rules
The topics in this forum are not for general MOD support, they are for giving the MOD author some feedback, ideas and bug reports.

Tweet this topic and/or post

Postby tumba25 » 01 Nov 2010, 00:01

This was originally posted by Kenny at 6 String MODs, I rewrote the codes and separated them to three posts. The first contains code used by both topic and post tweets. The second is for tweeting topics and the third for tweeting posts.

This thing is submitted to the MODDB at www.phpbb.com for validation.

Twitter seems to be getting more popular and I myself have found myself delving into the api's a few times already. This little snippet is a request from andrew55 in this topic on phpbb.com.

Simple enough - as per the topic title, this snippet allows you to tweet this topic. If you're not logged in when you click the link, simply log in and you'll redirected with the tweet still kept (not done by me, you can thank twitter devs for that ;)

For a demo, check these very forums. I have it here ^_^

OPEN: viewtopic.php
FIND:
Code: Select all
$voted_id = (sizeof($voted_id) > 1) ? array_unique($voted_id) : $voted_id; 

ADD AFTER:
Code: Select all
if ($auth->acl_get_list(ANONYMOUS, 'f_read', $forum_id))
{
    $s_tweet = true;
    $topic_url = generate_board_url() . '/viewtopic.' . $phpEx . '?t=' . $topic_id;
    $hashtag = htmlspecialchars(urlencode('#phpBBModders'));
}
else
{
    $s_tweet = false;
}
 

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 own account :P


Note that you need to refresh both your themes and imagesets after doing these changes.

And just for you lot, bonelifer created new twitter buttons. Although you can replace them if you so wish :P There's plenty in the internet to choose from :)
Attachments
tweet_topic-1.0.0.zip
(38.56 KiB) Downloaded 73 times
User avatar
tumba25
Administrator
Administrator
 
Posts: 877
Joined: 24 Oct 2007, 13:10
Location: Kokkola, Finland.
Real name: Jari Kanerva

Tweet this topic

Postby tumba25 » 01 Nov 2010, 00:03

This post contains edits for tweeting topics. You will also need the code from the first post.

OPEN: viewtopic.php
FIND:
Code: Select all
$topic_data['topic_title'] = censor_text($topic_data['topic_title']); 

ADD AFTER:
Code: Select all
// Make sure the tweet is no more than 140 chars.
if ($s_tweet)
{
    $strlen = strlen(htmlspecialchars(urlencode($topic_data['topic_title'] . ': ')) . $topic_url . ' ' . $hashtag);
    if ($strlen > 140)
    {
        $chars = 140 - strlen(': ' . $topic_url . ' ' . $hashtag);
        $tweet = truncate_string($topic_data['topic_title'], $chars, 255, true, '');
        $tweet .= ': ' . $topic_url . ' ' . $hashtag;
    }
    else
    
{
        $tweet = htmlspecialchars(urlencode($topic_data['topic_title'] . ' ')) . $topic_url . ' ' . $hashtag;
    }
}
 


FIND:
Code: Select all
$template->assign_vars(array( 

ADD AFTER:
Code: Select all
    'S_TWEET' => $s_tweet,
    'TWEET_TOPIC' => ($s_tweet) ? $tweet : '', 


OPEN: includes/acp/acp_language.php
FIND:
Code: Select all
 'button_topic_new', 'button_topic_reply', 'button_issue_new' 

IN-LINE ADD AFTER (add on the same line direct after that find):
Code: Select all
, 'button_tweet_topic' 


OPEN: includes/acp/acp_styles.php
FIND:
Code: Select all
 'button_topic_new', 'button_topic_reply', 'button_issue_new' 

IN-LINE ADD AFTER (add on the same line direct after that find):
Code: Select all
, 'button_tweet_topic' 


OPEN: language/en/viewtopic.php
FIND:
Code: Select all
'TOTAL_VOTES'            => 'Total votes', 

ADD AFTER:
Code: Select all
    'TWEET_TOPIC' => 'Tweet this topic', 


OPEN: language/en/acp/styles.php
FIND:
Code: Select all
'IMG_BUTTON_TOPIC_REPLY'    => 'Reply topic', 

ADD AFTER:
Code: Select all
    'IMG_BUTTON_TWEET_TOPIC'    => 'Tweet topic', 


OPEN: styles/{your_style}/imageset/en/imageset.cfg
FIND:
Code: Select all
img_button_topic_reply = button_topic_reply.gif*25*96

ADD AFTER:
Code: Select all
img_button_tweet_topic = button_tweet_topic.gif*25*96
You need to change the file name and its dimensions if you don't use our buttons


OPEN: styles/{your_style}/template/viewtopic_body.html
FIND:
Code: Select all
      <div class="<!-- IF S_IS_LOCKED -->locked-icon<!-- ELSE -->reply-icon<!-- ENDIF -->"><a href="{U_POST_REPLY_TOPIC}" title="<!-- IF S_IS_LOCKED -->{L_TOPIC_LOCKED}<!-- ELSE -->{L_POST_REPLY}<!-- ENDIF -->"><span></span><!-- IF S_IS_LOCKED -->{L_TOPIC_LOCKED_SHORT}<!-- ELSE -->{L_POST_REPLY}<!-- ENDIF --></a></div>
   <!-- ENDIF -->

ADD AFTER:
Code: Select all
   <!-- IF not S_IS_BOT and S_TWEET --><div class="tweet-topic"><a href="http://twitter.com/home?status={TWEET_TOPIC}" title="{L_TWEET_TOPIC}"><span></span>{L_TWEET_TOPIC}</a></div><!-- ENDIF -->


OPEN: styles/{your_style}/theme/buttons.css
FIND:
Code: Select all
.reply-icon span   { background: transparent none 0 0 no-repeat; }

ADD AFTER:
Code: Select all
.tweet-topic span   { background: transparent none 0 0 no-repeat; }


FIND:
Code: Select all
.buttons div.reply-icon      { width: {IMG_BUTTON_TOPIC_REPLY_WIDTH}px; height: {IMG_BUTTON_TOPIC_REPLY_HEIGHT}px; }

ADD AFTER:
Code: Select all
.buttons div.tweet-topic      { width: {IMG_BUTTON_TWEET_TOPIC_WIDTH}px; height: {IMG_BUTTON_TWEET_TOPIC_HEIGHT}px; }


OPEN: styles/{your_style}/theme/colours.css
FIND:
Code: Select all
.reply-icon span   { background-image: url("{IMG_BUTTON_TOPIC_REPLY_SRC}"); }

ADD AFTER:
Code: Select all
.tweet-topic span   { background-image: url("{IMG_BUTTON_TWEET_TOPIC_SRC}"); }
Attachments
button_tweet_topic.gif
button_tweet_topic.gif (1.55 KiB) Viewed 4969 times
User avatar
tumba25
Administrator
Administrator
 
Posts: 877
Joined: 24 Oct 2007, 13:10
Location: Kokkola, Finland.
Real name: Jari Kanerva

Tweet this post

Postby tumba25 » 01 Nov 2010, 00:04

This post contains edits for tweeting posts. You will also need the code from the first post.

OPEN: viewtopic.php
FIND:
Code: Select all
$postrow = array( 

ADD BEFORE:
Code: Select all
    // Make sure the tweet is no more than 140 chars.
    if ($s_tweet)
    {
        $post_url = $topic_url . '%23p' . $row['post_id'];
        
// Remove search highlight span if post subject contains the search keyword.
        
$post_subject str_replace(array('<span class="posthilit">''</span>'), ''$row['post_subject']);
        
$post_subject htmlspecialchars(urlencode($post_subject ': '));
        $strlen = strlen($post_subject . truncate_string($row['post_text'], 60, 255, true, '... ') . $post_url);
        if ($strlen > 140)
        {
            // Check that the post subject is not making this to long already.
            $strlen = strlen($post_subject . $post_url);
            if ($strlen > 140)
            {
                $chars = 140 - strlen(': ' . $post_url);
                $tweet = truncate_string($row['post_subject'], $chars, 255, true, '');
                $tweet .= ': ' . $post_url;
            }
            else
            
{
                $chars = 140 - strlen($post_subject . ': ' . $post_url);
                $tweet = truncate_string($row['post_text'], $chars, 255, true, '');
                $tweet = $post_subject . $tweet . ': ' . $post_url;
            }
        }
        else
        
{
            $tweet = $post_subject . truncate_string($row['post_text'], 60, 255, true, '... ') . $post_url;
        }
    } 

ADD AFTER:
Code: Select all
        'TWEET_POST' => ($s_tweet) ? $tweet : '', 


OPEN: includes/acp/acp_language.php
FIND:
Code: Select all
 'button_topic_new', 'button_topic_reply', 'button_issue_new' 

IN-LINE ADD AFTER (add on the same line direct after that find):
Code: Select all
, 'button_tweet_post' 


OPEN: includes/acp/acp_styles.php
FIND:
Code: Select all
 'button_topic_new', 'button_topic_reply', 'button_issue_new' 

IN-LINE ADD AFTER (add on the same line direct after that find):
Code: Select all
, 'button_tweet_post' 


OPEN: language/en/viewtopic.php
FIND:
Code: Select all
'TOTAL_VOTES'            => 'Total votes', 

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


OPEN: language/en/acp/styles.php
FIND:
Code: Select all
'IMG_BUTTON_TOPIC_REPLY'    => 'Reply topic', 

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


OPEN: styles/{your_style}/imageset/en/imageset.cfg
FIND:
Code: Select all
img_icon_post_quote = icon_post_quote.gif*20*54

ADD AFTER:
Code: Select all
img_button_tweet_post = button_tweet_post.gif*20*54
You need to change the file name and its dimensions if you don't use our buttons


OPEN: styles/{your_style}/template/viewtopic_body.html
FIND:
Code: Select all
<!-- IF postrow.U_INFO --><li class="info-icon"><a href="{postrow.U_INFO}" title="{L_INFORMATION}"><span>{L_INFORMATION}</span></a></li><!-- ENDIF -->

ADD AFTER:
Code: Select all
               <!-- IF not S_IS_BOT and S_TWEET --><li class="tweet-post"><a href="http://twitter.com/home?status={postrow.TWEET_POST}" title="{L_TWEET_POST}"><span>{L_TWEET_POST}</span></a></li><!-- ENDIF -->


OPEN: styles/{your_style}/theme/buttons.css
FIND:
Code: Select all
.quote-icon, .quote-icon a      { background: none top left no-repeat; }

ADD AFTER:
Code: Select all
.tweet-post, .tweet-post a      { background: none top left no-repeat; }


FIND:
Code: Select all
ul.profile-icons li.quote-icon   { width: {IMG_ICON_POST_QUOTE_WIDTH}px; height: {IMG_ICON_POST_QUOTE_HEIGHT}px; }

ADD AFTER:
Code: Select all
ul.profile-icons li.tweet-post   { width: {IMG_BUTTON_TWEET_POST_WIDTH}px; height: {IMG_BUTTON_TWEET_POST_HEIGHT}px; }


OPEN: styles/{your_style}/theme/colours.css
FIND:
Code: Select all
.quote-icon, .quote-icon a      { background-image: url("{IMG_ICON_POST_QUOTE_SRC}"); }

ADD AFTER:
Code: Select all
.tweet-post, .tweet-post a      { background-image: url("{IMG_BUTTON_TWEET_POST_SRC}"); }
Attachments
button_tweet_post.gif
button_tweet_post.gif (765 Bytes) Viewed 4969 times
Last edited by tumba25 on 04 May 2011, 10:25, edited 1 time in total.
Reason: Fixed bug.
User avatar
tumba25
Administrator
Administrator
 
Posts: 877
Joined: 24 Oct 2007, 13:10
Location: Kokkola, Finland.
Real name: Jari Kanerva

Tweet this topic or post Mod

Postby Jaxo » 30 Nov 2010, 22:46

Hello all, i installed the Tweet this topic or post Mod. I have a question with a prob i cannot figure out.

The mod is installed and is working but not correctly,.. When i tweet some posts it works fine but with others it does not, .. it sends the wrong web address to twitter resulting it "the requested topic does not exist" when somebody clicks the link. here is an example of a link that did not work

on site:
Code: Select all
http://cccam-exchange.co.uk/viewtopic.php?f=146&p=3408#p3408

on twitter:
Code: Select all
http://cccam-exchange.co.uk/viewtopic.php?t=0 #phpBBModders


This appears to be happening on more threads then working ones :? :?

I have also noticed that the same think is happening on this site when i try to tweet a post/ thread, Any ideas whats wrong?

thanks in advance + thanks for the mod :beer:
Jaxo
New member
New member
 
Posts: 4
Joined: 30 Nov 2010, 22:42

Re: Tweet this topic or post Mod

Postby tumba25 » 01 Dec 2010, 01:21

This would be to correct place to ask for support for that MOD.
First it seems like you have missed some edits since #phpBBModders are shown in your tweets. Can you tell us where on this site that happens?
User avatar
tumba25
Administrator
Administrator
 
Posts: 877
Joined: 24 Oct 2007, 13:10
Location: Kokkola, Finland.
Real name: Jari Kanerva

Re: Tweet this topic or post Mod

Postby Jaxo » 01 Dec 2010, 09:32

sorry for posting in the wrong place, maybe someone could move the thread or would you like me to repost?

The mod was installed with automod and all file edits where correct accordining to it. I did have to do some manual edits also as I have a few different themes installed on the site however the problem is happening accross all my themes and not just the ones i did myself... It is also happening on this site when I try to tweet as a test so im thinking it may be a twittter issue more than anything else??

here is a few examples:

on my site the address is:
Code: Select all
http://cccam-exchange.co.uk/viewtopic.php?f=138&p=5800#p5800


when I tweet this page the address it put to twitter is:
Code: Select all
http://cccam-exchange.co.uk/viewtopic.php?t=0 #phpBBModders


and again on this page:
Code: Select all
http://cccam-exchange.co.uk/viewtopic.php?f=168&p=6688#p6688


it puts the link on twitter as:
Code: Select all
http://cccam-exchange.co.uk/viewtopic.php?t=0 #phpBBModders


Now for the strange thing, .... the same thing is also happening when I try to tweet something from this site. This very page for example
Code: Select all
http://phpbbmodders.net/board/viewtopic.php?f=23&t=6438&p=26745#p26745


appears on my twitter as
Code: Select all
http://phpbbmodders.net/board/viewtopic.php?t=6438 #phpBBModders


So I do not think there is anything wrong with my install as the same thing is happening when I try to tweet from this site, I think it is more an issue with the mod or else twitter. Any advice I am greatful for as I would really like to get this mod working. My twitter page is http://twitter.com/CCcamExchange.

I will leave a few incorrect tweets up so somebody can have a look.

Thanks :beer:
Jaxo
New member
New member
 
Posts: 4
Joined: 30 Nov 2010, 22:42

Re: Tweet this topic or post Mod

Postby Jaxo » 01 Dec 2010, 10:17

I am having a look around my site trying to fix this and think this line in viewtopic may be causing the prob

Code: Select all
$topic_url = generate_board_url() . '/viewtopic.' . $phpEx . '?t=' . $topic_id;


(im know nothing about code btw so this is only a guess) but it appears to me that the generate url is only generating the topic id, but when i look at my threads the also have an F= and P=, Not just T= and it appears to be these parts that is missing from my tweets, what would the F & P =?? is this forum id and post ID?

Its a stab in the dark here as I really dont know code :oops:
Jaxo
New member
New member
 
Posts: 4
Joined: 30 Nov 2010, 22:42

Re: Tweet this topic or post Mod

Postby bonelifer » 01 Dec 2010, 23:37

Jaxo wrote:sorry for posting in the wrong place, maybe someone could move the thread or would you like me to repost?


Posts merged.
User avatar
bonelifer
Moderator Team Leader
Moderator Team Leader
 
Posts: 1479
Joined: 24 Jun 2006, 17:48
Location: htpc.MythBuntu
Real name: William

Re: Tweet this topic and/or post

Postby Steve© » 02 Dec 2010, 09:44

@ jaxo I tested this.

doesnt look like you changed this line as per instructed in the first post.

Code: Select all
    $hashtag = htmlspecialchars(urlencode('#phpBBModders'));

Change #phpBBModders to what ever you like.
Hello!
User avatar
Steve©
New member
New member
 
Posts: 22
Joined: 16 Jul 2010, 19:51
Location: UK! up north.
Real name: Steve

Re: Tweet this topic and/or post

Postby z2z » 30 Apr 2011, 06:27

Looks great .. Subsilver version possible?
z2z
New member
New member
 
Posts: 8
Joined: 12 Mar 2008, 06:48

Re: Tweet this topic and/or post

Postby Steve© » 30 Apr 2011, 08:53

z2z wrote:Looks great .. Subsilver version possible?


Open: subsilver2/template/viewtopic_body.html

find:
Code: Select all
         <!-- IF S_DISPLAY_POST_INFO --><a href="{U_POST_NEW_TOPIC}">{POST_IMG}</a>&nbsp;<!-- ENDIF -->

before add:
Code: Select all
         <!-- IF S_TWEET --><a href="http://twitter.com/home?status={postrow.TWEET_POST}" title="{L_TWEET_POST}"><img src="{T_IMAGESET_LANG_PATH}/button_topic_tweet.gif" alt="{L_TWEET_POST}" /></a><!-- ENDIF -->      

find:
Code: Select all
         <!-- IF S_DISPLAY_POST_INFO --><a href="{U_POST_NEW_TOPIC}">{POST_IMG}</a>&nbsp;<!-- ENDIF -->

before add:
Code: Select all
         <!-- IF S_TWEET --><a href="http://twitter.com/home?status={postrow.TWEET_POST}" title="{L_TWEET_POST}"><img src="{T_IMAGESET_LANG_PATH}/button_topic_tweet.gif" alt="{L_TWEET_POST}" /></a><!-- ENDIF -->      

Upload this image to your subsilver2/imageset/en/ folder.

button_topic_tweet.gif
button_topic_tweet.gif (1.81 KiB) Viewed 4542 times

Refresh template and should be good to go :)
Hello!
User avatar
Steve©
New member
New member
 
Posts: 22
Joined: 16 Jul 2010, 19:51
Location: UK! up north.
Real name: Steve

Re: Tweet this topic and/or post

Postby z2z » 03 May 2011, 07:31

thanks :D

Button is slightly mismatching .. Image Image
z2z
New member
New member
 
Posts: 8
Joined: 12 Mar 2008, 06:48

Re: Tweet this topic and/or post

Postby Steve© » 03 May 2011, 07:58

This ok,
button_topic_tweet.gif
button_topic_tweet.gif (1.73 KiB) Viewed 4489 times
Hello!
User avatar
Steve©
New member
New member
 
Posts: 22
Joined: 16 Jul 2010, 19:51
Location: UK! up north.
Real name: Steve

Re: Tweet this topic and/or post

Postby z2z » 04 May 2011, 08:46

thanks & congrats buddy :beer:

Submitted http://phpbbmodders.net/tracker/55 related to this mod .. something to do url encode :?:
z2z
New member
New member
 
Posts: 8
Joined: 12 Mar 2008, 06:48


Return to MOD Feedback

Who is online

Users browsing this forum: No registered users and 1 guest