[ABD]AutoTwitter Topics (with short URL)

Any abandoned MODs will be moved to this forum.

WARNING: MODs in this forum are not currently being supported or maintained by the original MOD author. Proceed at your own risk.
Forum rules
IMPORTANT: MOD Development Forum rules

WARNING: MODs in this forum are not currently being supported nor updated by the original MOD author. Proceed at your own risk.
User avatar
waxxie
Registered User
Posts: 119
Joined: Fri Oct 16, 2009 5:21 pm

[ABD]AutoTwitter Topics (with short URL)

Post by waxxie »

Modification Name: AutoTwitter Topics
Author: waxxie

Modification Description:: Auto post new topics to twitter
Supported phpBB Version:: 3.05, 3.06
Current CODE Mod Version:: 0.5 (12.08.09)

Current AutoMod Mod Version:: 1.0.1 (01.14.2010)
Initial release of the AutoMod version of AutoTwitter Topics is available here.

Requirements: server with CURL enabled and account on http://bit.ly
Features: optional ignore certain forums, tiny url support via http://Bit.ly and customizations (below Modification Instructions), twitter service status error checking

Version 0.1:: (11.05.09) Project posted
Version 0.2:: (11.13.09) Version 0.2 introduces short URL's via http://Bit.ly. In order to use the short URL, you must create an account there, it is completely free. Once you have an account, login and visit your account page, from there on the left side you will see your "API Login" and "API Key", which you need to enter below.
Version 0.3:: (11.14.09) Fixed typo.
Version 0.4:: (11.24.09) Ignore forums is easier now.

Whats New In This Version:: Version 0.5 adds twitter service status error checking. Which means no more error logs when twitter service goes down, as it usually does quite often... Just the postToTwitter function was updated in this version.


Modification Instructions:

Code: Select all

OPEN:
include/functions_posting.php

FIND:
$forum_notification = ($mode == 'post') ? true : false;

AFTER ADD:
        $my_url = "http://mywebsite.com"; //Change to your URL
        $ignore_forums = array('1', '2', '3', '4'); // Forums to ignore
	if($mode == 'post'){
		if (!in_array($forum_id, $ignore_forums))
                 {  
			$msg = substr($topic_title, 0, 80).'... '.getSmallLink($my_url .'/viewtopic.php?t='.$topic_id);
			postToTwitter($msg);
		  }
    }

FIND AT END OF FILE:
?>

BEFORE ADD:
function postToTwitter($message){
    $username='username'; //Change this to your username
    $password='password'; //Change this to your password
    // GET the API url via web authentication
    // add 'status' param to send a message to Twitter

    $host = "http://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($message)));

	$api_page = 'http://twitter.com/users/show/'.$username;
	$xml = file_get_contents ( $api_page );
	if(($xml=file_get_contents($api_page))==true){
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $host);
		curl_setopt($ch, CURLOPT_VERBOSE, 1);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
		curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
		curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
		curl_setopt($ch, CURLOPT_POST, 1);
		// Go for it!!!
		$result = curl_exec($ch);
		// close curl
		curl_close($ch);
	}else{
		// twitter is down!
	}
}
function getSmallLink($longurl){
	// Bit.ly API Login
	$myLogin = "YOUR_API_LOGIN_GOES_HERE";
	// Bit.ly API Key
	$myApi = "YOUR_API_KEY_GOES_HERE";

	// Bit.ly
	$url = "http://api.bit.ly/shorten?version=2.0.1&longUrl=$longurl&login=$myLogin&apiKey=$myApi&format=json&history=1";
	
	$s = curl_init();
	curl_setopt($s,CURLOPT_URL, $url);
	curl_setopt($s,CURLOPT_HEADER,false);
	curl_setopt($s,CURLOPT_RETURNTRANSFER,1);
	$result = curl_exec($s);
	curl_close( $s );
	
	$obj = json_decode($result, true);
	return $obj["results"]["$longurl"]["shortUrl"];
}
Customizations: First mod/code release, excuse the noobness. Mods feel free to move or beat with a stick.
Last edited by Sam on Wed Jul 14, 2010 9:36 pm, edited 23 times in total.
Reason: Marked mod as abandoned, if the original poster wishes to continue this, please PM any MOD team member to have it unlocked.
Peter77sx
Registered User
Posts: 3260
Joined: Wed Nov 09, 2005 2:51 pm

Re: [DEV]AutoTwitter Topics

Post by Peter77sx »

Posts just the topic title, or a little bit of what was posted also? that would be a neat request.. :)
drixie
Registered User
Posts: 76
Joined: Mon Apr 23, 2007 12:12 am

Re: [DEV]AutoTwitter Topics

Post by drixie »

You cannot post a little bit of what was posted because Twitter is just 140 chars.

I'll prefer a bit.ly integration or any other url shortener that adds the url of the topic to the tweet.
Peter77sx
Registered User
Posts: 3260
Joined: Wed Nov 09, 2005 2:51 pm

Re: [DEV]AutoTwitter Topics

Post by Peter77sx »

drixie wrote:You cannot post a little bit of what was posted because Twitter is just 140 chars.
I'm aware of that. :)
drixie
Registered User
Posts: 76
Joined: Mon Apr 23, 2007 12:12 am

Re: [DEV]AutoTwitter Topics

Post by drixie »

Of course, I know you are aware. Just reminding ya' ;) . What I really meant was there's no amount of thread text you can cram into the tweet that will make sense as long as the topic and shortened URL are still there.
User avatar
darkonia
Registered User
Posts: 1901
Joined: Tue May 13, 2008 1:10 pm
Location: Munich, Germany
Contact:

Re: [DEV]AutoTwitter Topics

Post by darkonia »

it make sense for only display the topic title...
MMOG-Heaven - Das Gaming Portal
Community bedeutet Gleichgesinnte finden - MMOG-Heaven ist Deine Community! Von Spielern für Spieler bietet Dir dieses Portal genau das, was ein Spieler braucht. Bleibe ständig informiert, finde die neuesten MMORPGs, oder suche die frischesten News aus der Welt des Online Gamings - dieses und vieles mehr erwartet Dich auf MMOG-Heaven.
User avatar
waxxie
Registered User
Posts: 119
Joined: Fri Oct 16, 2009 5:21 pm

Re: [DEV]AutoTwitter Topics (with short URL)

Post by waxxie »

Mod updated to v0.2

Now include short url support for http://bit.ly

:ugeek:
User avatar
waxxie
Registered User
Posts: 119
Joined: Fri Oct 16, 2009 5:21 pm

Re: [RC]AutoTwitter Topics (with short URL)

Post by waxxie »

Mod updated to v0.3
Just changed a typ0 for $my_url in

Code: Select all

$msg = substr($topic_title, 0, 80).'... '.getSmallLink($my_url .'/viewtopic.php?t='.$topic_id);
Enjoy!
Peter77sx
Registered User
Posts: 3260
Joined: Wed Nov 09, 2005 2:51 pm

Re: [RC]AutoTwitter Topics (with short URL)

Post by Peter77sx »

How about if I wanted to add 10 forums to the ignore list, use commas?

Also, do i have to use Bit.ly? I want my site name to be on the link I post on Twitter :) .
User avatar
waxxie
Registered User
Posts: 119
Joined: Fri Oct 16, 2009 5:21 pm

Customization: Not use Bit.ly url shortening service

Post by waxxie »

Customization: Not use Bit.ly url shortening service

change the following to not use bit.ly:

Code: Select all

FIND:
$msg = substr($topic_title, 0, 80).'... '.getSmallLink($my_url .'/viewtopic.php?t='.$topic_id);

REPLACE WITH:
$msg = substr($topic_title, 0, 80).'... '.$my_url .'/viewtopic.php?t='.$topic_id;
Enjoy!
Last edited by waxxie on Thu Jan 07, 2010 2:51 am, edited 2 times in total.
User avatar
stickerboy
Former Team Member
Posts: 7349
Joined: Mon Mar 29, 2004 2:27 pm
Location: Airdrie, UK (127.0.0.1)
Name: Kenny Cameron
Contact:

Re: [RC]AutoTwitter Topics (with short URL)

Post by stickerboy »

Peter77sx wrote:How about if I wanted to add 10 forums to the ignore list, use commas?.
If you want to use 10 forum id's, it might be better to stick them in an array and check it. Shorter and neater :)

Code: Select all

$ignore_forums = array('1', '2', '3', '4', 'x', 'x');

if (in_array($forum_id, $ignore_forums))
{
// code
}
I'm a web-designing code-decrypting tech-support musician
|| Twitter || Flickr || phpBB Snippets ||
Formerly known as cherokee red
User avatar
waxxie
Registered User
Posts: 119
Joined: Fri Oct 16, 2009 5:21 pm

Re: [RC]AutoTwitter Topics (with short URL)

Post by waxxie »

Updated to v0.4

:D
Night-Star
Registered User
Posts: 11
Joined: Fri May 08, 2009 4:20 pm

Re: [RC]AutoTwitter Topics (with short URL)

Post by Night-Star »

Hello

Thank you for your wonderful module, it's work fine with me

but I wan ask you how I can active it for new reply ?

it worked for new post only , I want add the new reply to twitter also

please any idea for this ?

thank you
Rawaf
User avatar
waxxie
Registered User
Posts: 119
Joined: Fri Oct 16, 2009 5:21 pm

Re: [RC]AutoTwitter Topics (with short URL)

Post by waxxie »

Customization: Also show replies to topics

Code: Select all

FIND:
if($mode == 'post')

CHANGE TO:
if($mode == 'post' || $mode == 'reply')
enjoy!
Last edited by waxxie on Tue Dec 08, 2009 7:58 pm, edited 1 time in total.
Night-Star
Registered User
Posts: 11
Joined: Fri May 08, 2009 4:20 pm

Re: [RC]AutoTwitter Topics (with short URL)

Post by Night-Star »

waxxie wrote: sure, just change the following line

Code: Select all
FIND:
if($mode == 'post')

CHANGE TO:
if($mode == 'post' || $mode == 'reply')

Thank you for your fast support

It's work fine :)
Locked

Return to “[3.0.x] Abandoned MODs”