[WIP] Simple Twitter mod (beta testing)

Started by Suki, March 10, 2011, 07:37:29 PM

Previous topic - Next topic

Suki

Hi, I'm building a simple post-to-twitter  mod,  its pretty much finished  but the problem is the redirect topics, I do not want the mod publish those topics on twitter, I tried strpos()


global $modSettings, $scripturl, $sourcedir, $txt;

// does the topic its a redirect topic?
$mystring = $msgOptions['subject'];
$findme   = $txt['moved'];
$pos = strpos($mystring, $findme);

if (empty($modSettings['simple_twitter_enable']) || $pos === true)
return;  // twitter mod is disable or its a redirect topic, so just return...



I tried $pos === false  $pos === 0   $pos > 0  $pos < 0  $pos == 0 with no luck

the problem is I haven't found a way to check if $msgOptions['subject'] contains $txt['moved']
(I'm assuming $msgOptions['subject'] does contain $txt['moved'] )   or is there another way to check if a topic its a redirect topic?

thanks

Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Matthew K.

Try adding this:
die ('<pre>'. print_r($msgOptions). '</pre>');I don't remember off the top of my head what $msgOptions contains. What does it return?

Kays

Quote
or is there another way to check if a topic its a redirect topic?

If you can, check the message icon. For moved topics it's moved.gif

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Arantor

The icon column doesn't have an extension but you can just search for 'moved' in that column to see if it's a redirect or not.

Suki

thanks Kays that solved the issue :)


ℓαвяα∂σσ∂ℓє-360   $msgOptions  contains info from a message, either to create a new message or to get the info from the last one created,  I was interested in $msgOptions['subject']   (the title of the message)  when a redirect topic is created it has $txt['moved']  (MOVED)  at the beginning, I wasn't sure if  $msgOptions['subject'] already included $txt['moved'] at the time I was manipulating it or if its added later.

I'm using integrate_create_topic   to post the message to twitter, in this case $msgOptions['subject'] will contain the title of the topic, heres the complete function:

<?php
function 
SimpleTwitter($msgOptions$topicOptions$posterOptions){

global $modSettings$scripturl$sourcedir$txt;

// does the topic its a redirect topic?


if (empty($modSettings['simple_twitter_enable']) || $msgOptions['icon'] == 'moved')
return;  // twitter mod is disable or its a redirect topic, so just return...
  
else{

// get the boards where the mod will NOT work.
if(!empty($modSettings['simple_twitter_board_enable']) && !empty($modSettings['simple_twitter_boards']))
$boards_denied explode(',',$modSettings['simple_twitter_boards']);
else $boards_denied = array();

  
if(!in_array($topicOptions['board'], $boards_denied)){
$twt_message utf8_decode($msgOptions['subject']);
$twturl_url $scripturl '?topic=' $topicOptions['id'] . '.0';
$twt_key $modSettings['simple_twitter_bit_ly_key'];
$twt_login $modSettings['simple_twitter_bit_ly_username'];

//Lets use the bit.ly API to short the url shall we?
if(!empty($modSettings['simple_twitter_use_bitly']) && !empty($modSettings['simple_twitter_bit_ly_username']) && !empty($modSettings['simple_twitter_bit_ly_key'])){

// MAS is trying to learn OOP so be nice with her ok?
class Bitly {
var $path;
var $user;
var $key;
function Bitly ($_user$_key) {
$this->path "http://api.bit.ly/v3/";
$this->user $_user;
$this->key $_key;
}
function shorten($url) {
$temp $this->path.'shorten?login='.$this->user.'&apiKey='.$this->key.'&uri='.$url.'&format=txt';

// lets use curl if avaliable...
if(function_exists('curl_init')){

$sesion curl_init();   
curl_setopt $sesionCURLOPT_URL$temp ); 
curl_setopt $sesionCURLOPT_RETURNTRANSFER); 
$data curl_exec $sesion ); 
curl_close$sesion );

}
else
$data file_get_contents($temp);

return $data;
}

}

$bitly = new Bitly("$twt_login""$twt_key");
$urlmin $bitly->shorten("$twturl_url");
$twturl $urlmin

}

else
$twturl $twturl_url;


// we need Abraham's Oauth PHP library 
require_once($sourcedir '/twitteroauth/twitteroauth.php'); 

define('_CONSUMER_KEY',$modSettings['simple_twitter_consumer_key']); 
define('_CONSUMER_SECRET',$modSettings['simple_twitter_consumer_secret']);  
define('_OAUTH_TOKEN',$modSettings['simple_twitter_oauth_token']); 
define('_OAUTH_TOKEN_SECRET',$modSettings['simple_twitter_oauth_token_secret']); 
  
        
// Prepare the message, very simple, will be enhanced in future releases me hopes...
        
$mensaje $twt_message.'  '.$twturl;

    

  
// Lets connect with our twitter app 
function getConnectionWithAccessToken(){ 
$connection = new TwitterOAuth(_CONSUMER_KEY_CONSUMER_SECRET,_OAUTH_TOKEN_OAUTH_TOKEN_SECRET); 
return $connection

// Make the connection
$connection getConnectionWithAccessToken(); 
//Publish the message and url on twitter! 
$twitter=$connection->post('statuses/update', array('status' =>utf8_encode($mensaje))); 
}

        }
}
?>




thanks Arantor, I did only used "moved"  :)
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Suki

#5
well its pretty much finished, but I would like to test it out before I send it to the mod site, it has been running with no issues on my site for the last two weeks but since my site isn't very active I can't properly test it, so  I would like to ask you guys or any other user if you can give it a try and test it out a little bit.

its for 2.0 RC4 and RC5 only, it does not modify any file :)
you will have to create a twitter app, there's instructions on the mod's settings or you can use this guide

any error, suggestion, new feature, code improvement or any comments would be appreciated ^^

my concern right now is that post made by users with twitter accounts are the only ones who got posted on twitter,  but this past week   topics made by users who don't have a twitter account are also posted, so if anyone can confirm that all the topics are posted to twitter, regardless if they have an account or not,  that will be great :)

regular users, please don't use this mod in a live site,  it probably have bugs or issues,   this mod will be available in the mod site onces it gets stable enough for a release, also  this topic isn't mean to be for support  ;)


thanks.



edit, attachment removed.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Matthew K.


Suki

Quote from: ℓαвяα∂σσ∂ℓє-360 on March 11, 2011, 09:34:09 AM
I'll check it out, very original name ;)

actually it isn't original at all :P  a lot of mods have "simple"  as a prefix, I couldn't find a better name :P

ok, this didn't had the attention I was expecting :P    I think its safe to send it to the mod site,  I have plenty of time before the mod is approved to test and find major issues  :)  although it doesn't need to have major issues, its a very simple mod, just a couple of functions, some hooks and some files.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Matthew K.


Masterd


Soulmaster

#10
hey :) installed your mod ( 2.0 rc5 ) put al the nessesary code's in it but he's not posting.

call me stupid :) got the browser and not the client in the api :) fixed it

www.bliksemdetectie.nl and on twitter http://twitter.com/bliksemdetect

but .. he's not showing the url to the topic :( is this a mod problem or a problem on my site ?
check out my lightning site

Suki

please, as I said in previous post:

Quote from: Miss All Sunday on March 11, 2011, 09:29:39 AM

regular users, please don't use this mod in a live site,  it probably have bugs or issues,   this mod will be available in the mod site onces it gets stable enough for a release, also  this topic isn't mean to be for support  ;)


thanks.


the customize team is reviewing this mod, once it gets the approval feel free to ask for support in the mod's  support topic.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Soulmaster

well i think it's a problem on my site because the twittermod from smfhacks is doing the same thing, not showing the url to the post
check out my lightning site

Suki

is your site open to guest?    does the title of the post is very long?   remember, twitter has a 140 characters limit. 

I don't know how the twittermod from smfhacks work,   but on my mod you can you use the bit-ly aPI to short the urls,  but in order to use it yu will need to create an account in bit.ly to get your user key,  did you enable that feature?
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Soulmaster

Quote from: Miss All Sunday on March 28, 2011, 12:22:49 PM
is your site open to guest?    does the title of the post is very long?   remember, twitter has a 140 characters limit. 

I don't know how the twittermod from smfhacks work,   but on my mod you can you use the bit-ly aPI to short the urls,  but in order to use it yu will need to create an account in bit.ly to get your user key,  did you enable that feature?

well,it worked. But after the upgrade tot rc5 it's not working anymore both are missing the url in the twitterpost. I'm using bit-ly .

But there are more problems on my site i can't fix.  so i'm now using some rssfeed post for twitter.

i'm not clever enough to fix this
check out my lightning site

Suki

well I cannot help if I don't know any more details.

after the upgrade. did you reinstall the mod?
any error on your error log? 

did you put all twitter keys and tokens?
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Soulmaster

Quote from: Paris Hilton on March 29, 2011, 08:30:45 AM
well I cannot help if I don't know any more details.

after the upgrade. did you reinstall the mod?
Yes
Quote
any error on your error log? 
No
Quote

did you put all twitter keys and tokens?
Yes , it is publicing the topic on twitter but not the url to the topic
check out my lightning site

Suki

are you using the bit.ly  option?

if so, did you create a bit.ly username and get a key?
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Soulmaster

Quote from: Paris Hilton on April 01, 2011, 10:15:03 AM
are you using the bit.ly  option?

if so, did you create a bit.ly username and get a key?

yep i have a bit.ly account
check out my lightning site

Suki

did you enable the option then?   did you put your user name and key correctly in the settings?


have you try disable the bit.ly option?


please be more specific with your answers and try to answer everything I ask.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Advertisement: