Firefox PHP

Module: Twitter new posts

Posted by Brian Moon 
All files from this thread

File Name File Size   Posted by Date  
twitter-1.0.1.tar.gz 2.8 KB open | download Brian Moon 05/03/2008 Read message
twitter-2.0.0.zip 16.4 KB open | download Thomas Seifert 10/13/2010 Read message
Module: Twitter new posts
May 03, 2008 09:50PM
This module sends the subject and URL (via tiny URL) to Twitter. You can then publish the Twitter feed and your users can follow things on Twitter.

Well, this is a quick new release. My copy editor, aka Maurice pointed out some typos.

Brian - Cowboy Ninja Coder - Personal Blog - Twitter



Edited 1 time(s). Last edit at 05/03/2008 10:15PM by Brian Moon.
Attachments:
open | download - twitter-1.0.1.tar.gz (2.8 KB)
Re: Module: Twitter new posts
May 03, 2008 09:51PM
A nice addition to this may be to add some code to grab people's Twitter status and display it somehow in their profile.

Brian - Cowboy Ninja Coder - Personal Blog - Twitter
Re: Module: Twitter new posts
November 06, 2008 02:56AM
Brian,

Thanks much for this module. I'm wondering if there's a way to limit the Twitter posts to threads within a certain forum... For example, I'd like the Twitter posts to be the publicly available ones, but I have an admin only forum from which I don't want Twitter posts. I didn't see anything in the Read Me file for something like this...
Re: Module: Twitter new posts
November 07, 2008 01:46AM
I don't want to take this thread off-topic, but could someone please post a simple paragraph or two explaining the desirability of using Twitter for this purpose? I don't really "get" Twitter you see, and therefore can't currently see what advantage it would have over RSS.

Cheers,

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Module: Twitter new posts
November 07, 2008 02:01AM
I'm not sure it has a real advantage over RSS, but there's a possibility that some people check their Twitter home page and would prefer to be notified that way, rather than RSS. I just think that some people would prefer that option.
Re: Module: Twitter new posts
November 07, 2008 02:10AM
OK, interesting. I'm all for diversity, I was just curious to know if I was missing out on some obvious killer feature of Twitter.

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Module: Twitter new posts
January 16, 2009 08:27PM
For anyone that cares, I've spent some time working on this module to get it to do what I like.

The changes I've made allow you to choose the forums from which tweets are made. I've not made it compatible with any sort of vroot stuff, just forums. Also, the code is probably a little messy, as I'm not really a programmer. :)

Anyway, below are the two files I changed.

settings.php
Language: PHP
  1. <?php
  2.  
  3. // Make sure that this script is loaded from the admin interface.
  4. if (!defined(';PHORUM_ADMIN';)) return;
  5.  
  6. $forum_list_global = phorum_get_forum_info(1,0);
  7.  
  8. // Save settings in case this script is run after posting
  9. // the settings form.
  10. if (count($_POST)) {
  11.  
  12. $settings = array(
  13. "username" => (string)$_POST["username"],
  14. "password" => (string)$_POST["password"],
  15. "new_posts" => (bool)$_POST["new_posts"],
  16. );
  17.  
  18. $settings["forum_list"] = array();
  19. foreach ($_POST["forum_list"] as $v => $k ) {
  20. array_push($settings["forum_list"],$v);
  21. }
  22.  
  23. $PHORUM["mod_twitter"] = $settings;
  24.  
  25. if (!phorum_db_update_settings(array(';mod_twitter';=>$settings))) {
  26. $error = ';Database error while updating settings.';;
  27. } else {
  28. phorum_admin_okmsg(';Settings Updated';);
  29. }
  30. }
  31.  
  32. // We build the settings form by using the PhorumInputForm object.
  33. include_once ';./include/admin/PhorumInputForm.php';;
  34. $frm =& new PhorumInputForm(';';, ';post';, ';Save';);
  35. $frm->hidden(';module';, ';modsettings';);
  36. $frm->hidden(';mod';, ';twitter';);
  37.  
  38. // Here we display an error in case one was set by saving
  39. // the settings before.
  40. if (!empty($error)){
  41. phorum_admin_error($error);
  42. }
  43.  
  44. $frm->addbreak(';Edit settings for the Twitter module';);
  45.  
  46. // Twitter Username
  47. $row = $frm->addrow
  48. ( ';Twitter Username ';,
  49. $frm->text_box
  50. ( ';username';,
  51. $PHORUM[';mod_twitter';][';username';],
  52. 30 ) );
  53. $frm->addhelp
  54. ( $row,
  55. ';Twitter Username';,
  56. "Enter the name you use to log in to Twitter." );
  57.  
  58. // Twitter Password
  59. $row = $frm->addrow
  60. ( ';Twitter Password ';,
  61. $frm->text_box
  62. ( ';password';,
  63. $PHORUM[';mod_twitter';][';password';],
  64. 30 ) );
  65. $frm->addhelp
  66. ( $row,
  67. ';Twitter Password';,
  68. "Enter the password you use to log in to Twitter." );
  69.  
  70. // Send new topics or all posts
  71. $row = $frm->addrow
  72. ( "Type of Posts ",
  73. $frm->select_tag
  74. ( "new_posts",
  75. array( "All Posts", "New Topics" ),
  76. $PHORUM["mod_twitter"]["new_posts"] ) );
  77. $frm->addhelp
  78. ( $row,
  79. ';Type of Posts';,
  80. "Select if you want to send all posts or only new topics to Twitter." );
  81.  
  82. // Select forums from which to send posts
  83.  
  84. $checkboxes = ';';;
  85. foreach ($forum_list_global as $forum_list_id => $forum_list_path) {
  86. $enabled = in_array($forum_list_id,$PHORUM["mod_twitter"]["forum_list"]);
  87. if ($enabled === FALSE)
  88. $enabled = 0;
  89. else
  90. $enabled = 1;
  91. $checkboxes .= $frm->checkbox("forum_list[$forum_list_id]", "1", "", $enabled) . " $forum_list_path<br/>";
  92. }
  93. $frm->addrow("Twitter new posts for which forums?", $checkboxes);
  94.  
  95. // Show settings form
  96. $frm->show();
  97.  
  98. ?>

twitter.php
Language: PHP
  1. <?php
  2.  
  3. function mod_twitter_url(){
  4. global $PHORUM;
  5.  
  6. $PHORUM["DATA"]["URL"]["TWITTER"] = "http://www.twitter.com/".$PHORUM["mod_twitter"]["username"];
  7. }
  8.  
  9. function mod_twitter_posts($message){
  10.  
  11. global $PHORUM;
  12.  
  13. if( ($PHORUM["mod_twitter"]["new_posts"]==0 || $message["parent_id"]==0) && in_array($message[';forum_id';],$PHORUM["mod_twitter"]["forum_list"]) ){
  14.  
  15. // Format the read URL.
  16. $url = phorum_get_url(
  17. PHORUM_FOREIGN_READ_URL,
  18. $message[';forum_id';], $message[';thread';], $message[';message_id';]
  19. );
  20.  
  21. // Strip auth data from the URL, if availble.
  22. if (isset($_POST[PHORUM_SESSION_LONG_TERM])) {
  23. $url = preg_replace(
  24. ';!,?'; . PHORUM_SESSION_LONG_TERM.';='; .
  25. urlencode($_POST[PHORUM_SESSION_LONG_TERM]).';!';,
  26. ';';, $url
  27. );
  28. }
  29.  
  30. // fetch a tiny URL.
  31. $ch = curl_init();
  32. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  33. curl_setopt($ch, CURLOPT_POST, TRUE);
  34. curl_setopt($ch, CURLOPT_POSTFIELDS, ';url=';.urlencode($url));
  35. curl_setopt($ch, CURLOPT_URL, ';http://tinyurl.com/api-create.php';);
  36. $response = curl_exec($ch);
  37. if ($response && preg_match(';!http://tinyurl\.com/\w+!';, $response)) {
  38. $url = $response;
  39. }
  40. curl_close($ch);
  41.  
  42. $status = urlencode($message["subject"]." ".$url);
  43.  
  44. $curl_handle = curl_init();
  45. curl_setopt($curl_handle,CURLOPT_URL,"http://twitter.com/statuses/update.json");
  46. curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
  47. curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
  48. curl_setopt($curl_handle,CURLOPT_POST,1);
  49. curl_setopt($curl_handle,CURLOPT_POSTFIELDS,"status=$status");
  50. curl_setopt($curl_handle,CURLOPT_USERPWD, $PHORUM["mod_twitter"]["username"].":".$PHORUM["mod_twitter"]["password"]);
  51. $buffer = curl_exec($curl_handle);
  52. curl_close($curl_handle);
  53.  
  54. }
  55.  
  56. return $message;
  57.  
  58. }
  59.  
  60. ?>

It appears to work as I intended it for now. Just figured I'd throw this out there in case anyone else wanted this feature and it can be cleaned up and worked into the official plugin, if desired.



Edited 2 time(s). Last edit at 01/16/2009 08:47PM by rtetzloff.
Re: Module: Twitter new posts
May 18, 2009 11:05PM
Anyone have any thoughts on what I could be doing wrong (except for the obvious wrong name or password). The modules all kick in and I have it configured, but no posts ever show up on the twitter page.


I'm trying to run this on 5.1.16a, you think it's necessary to upgrade to 5.2?
Re: Module: Twitter new posts
May 19, 2009 10:22AM
The module was written with 5.2 and not tested on 5.1, so it would be an option to at least test that out. You could setup a test 5.2 Phorum with that module to see if that would work for you. If the module doesn't work in your test-5.2 either, then some more investigation is needed to see what causes the issue.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Module: Twitter new posts
May 20, 2009 06:48PM
Yep, needed 5.2. Users are having a fit, but such is change.
Sorry, only registered users may post in this forum.

Click here to login