Page 1 of 1

Tweet this topic and/or post

Posted: 01 Nov 2010, 00:01
by tumba25
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 http://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 [url=http://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=880575]andrew55[/url] in [url=http://www.phpbb.com/community/viewtopic.php?f=72&t=1486425]this topic[/url] 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;   &nbsp

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;
}&
nbsp;  &nbsp

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, [url=http://phpbbmodders.net/board/memberlist.php?mode=viewprofile&u=14]bonelifer[/url] created new twitter buttons. Although you can replace them if you so wish :P There's plenty in the internet to choose from :)

Tweet this topic

Posted: 01 Nov 2010, 00:03
by tumba25
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']);   &nbsp

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;
    }
}&
nbsp;  &nbsp


FIND:

Code: Select all

$template->assign_vars(array(   &nbsp

ADD AFTER:

Code: Select all

    'S_TWEET' => $s_tweet,
    'TWEET_TOPIC' => ($s_tweet) ? $tweet : '',   &nbsp


OPEN: includes/acp/acp_language.php
FIND:

Code: Select all

 'button_topic_new', 'button_topic_reply', 'button_issue_new'   &nbsp

IN-LINE ADD AFTER (add on the same line direct after that find):

Code: Select all

, 'button_tweet_topic'   &nbsp


OPEN: includes/acp/acp_styles.php
FIND:

Code: Select all

 'button_topic_new', 'button_topic_reply', 'button_issue_new'   &nbsp

IN-LINE ADD AFTER (add on the same line direct after that find):

Code: Select all

, 'button_tweet_topic'   &nbsp


OPEN: language/en/viewtopic.php
FIND:

Code: Select all

'TOTAL_VOTES'            => 'Total votes',   &nbsp

ADD AFTER:

Code: Select all

    'TWEET_TOPIC' => 'Tweet this topic',   &nbsp


OPEN: language/en/acp/styles.php
FIND:

Code: Select all

'IMG_BUTTON_TOPIC_REPLY'    => 'Reply topic',   &nbsp

ADD AFTER:

Code: Select all

    'IMG_BUTTON_TWEET_TOPIC'    => 'Tweet topic',   &nbsp


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}"); }

Tweet this post

Posted: 01 Nov 2010, 00:04
by tumba25
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(&nbsp;&nbsp;&nbsp;&nbsp

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'];
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Remove&nbsp;search&nbsp;highlight&nbsp;span&nbsp;if&nbsp;post&nbsp;subject&nbsp;contains&nbsp;the&nbsp;search&nbsp;keyword.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$post_subject&nbsp;=&nbsp;str_replace(array('<span&nbsp;class="posthilit">',&nbsp;'</span>'),&nbsp;'',&nbsp;$row['post_subject']);
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$post_subject&nbsp;=&nbsp;htmlspecialchars(urlencode($post_subject&nbsp;.&nbsp;':&nbsp;'));
        $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;
        }
    }&nbsp;&nbsp;&nbsp;&nbsp

ADD AFTER:

Code: Select all

        'TWEET_POST' => ($s_tweet) ? $tweet : '',&nbsp;&nbsp;&nbsp;&nbsp


OPEN: includes/acp/acp_language.php
FIND:

Code: Select all

 'button_topic_new', 'button_topic_reply', 'button_issue_new'&nbsp;&nbsp;&nbsp;&nbsp

IN-LINE ADD AFTER (add on the same line direct after that find):

Code: Select all

, 'button_tweet_post'&nbsp;&nbsp;&nbsp;&nbsp


OPEN: includes/acp/acp_styles.php
FIND:

Code: Select all

 'button_topic_new', 'button_topic_reply', 'button_issue_new'&nbsp;&nbsp;&nbsp;&nbsp

IN-LINE ADD AFTER (add on the same line direct after that find):

Code: Select all

, 'button_tweet_post'&nbsp;&nbsp;&nbsp;&nbsp


OPEN: language/en/viewtopic.php
FIND:

Code: Select all

'TOTAL_VOTES'            => 'Total votes',&nbsp;&nbsp;&nbsp;&nbsp

ADD AFTER:

Code: Select all

    'TWEET_POST' => 'Tweet this post',&nbsp;&nbsp;&nbsp;&nbsp


OPEN: language/en/acp/styles.php
FIND:

Code: Select all

'IMG_BUTTON_TOPIC_REPLY'    => 'Reply topic',&nbsp;&nbsp;&nbsp;&nbsp

ADD AFTER:

Code: Select all

    'IMG_BUTTON_TWEET_POST'        => 'Tweet post',&nbsp;&nbsp;&nbsp;&nbsp


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}"); }

Tweet this topic or post Mod

Posted: 30 Nov 2010, 22:46
by Jaxo
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:

Re: Tweet this topic or post Mod

Posted: 01 Dec 2010, 01:21
by tumba25
[url=http://phpbbmodders.net/board/viewtopic.php?f=118&t=6359]This[/url] 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?

Re: Tweet this topic or post Mod

Posted: 01 Dec 2010, 09:32
by Jaxo
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:

Re: Tweet this topic or post Mod

Posted: 01 Dec 2010, 10:17
by Jaxo
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:

Re: Tweet this topic or post Mod

Posted: 01 Dec 2010, 23:37
by bonelifer
Jaxo wrote:sorry for posting in the wrong place, maybe someone could move the thread or would you like me to repost?


Posts merged.

Re: Tweet this topic and/or post

Posted: 02 Dec 2010, 09:44
by steve
@ 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.

Re: Tweet this topic and/or post

Posted: 30 Apr 2011, 06:27
by z2z
Looks great .. Subsilver version possible?

Re: Tweet this topic and/or post

Posted: 30 Apr 2011, 08:53
by steve
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 21716 times

Refresh template and should be good to go :)

Re: Tweet this topic and/or post

Posted: 03 May 2011, 07:31
by z2z
thanks :D

Button is slightly mismatching .. [img]http://img121.imageshack.us/img121/6578/buttontopicnew.gif[/img] [img]http://img33.imageshack.us/img33/6519/buttontopicreplyn.gif[/img]

Re: Tweet this topic and/or post

Posted: 03 May 2011, 07:58
by steve
This ok,
button_topic_tweet.gif
button_topic_tweet.gif (1.73 KiB) Viewed 21663 times

Re: Tweet this topic and/or post

Posted: 04 May 2011, 08:46
by z2z
thanks & congrats buddy :beer:

Submitted http://phpbbmodders.net/tracker/55 related to this mod .. something to do url encode :?: