Twitter D6 backport to D5

jaydub - October 3, 2008 - 18:39
Project:Twitter
Version:5.x-1.x-dev
Component:Code
Category:task
Priority:critical
Assigned:jaydub
Status:needs review
Issue tags:post, tabs, twitter
Description

I took the time to backport the current release of the twitter
module as it currently stands for Drupal 6 to Drupal 5. Obviously
this does not make use of Views the way that the d6 version makes
use of Views 2 but otherwise it's pretty much working the same as
a default install of twitter for d6 works.

I volunteer to try and maintain this d5 backport for the time being
if the developers want to add me to CVS for this project. In the
meantime I've attached a tarball of the files for use by others
and for the developer's eyes.

AttachmentSize
twitter5.tar_.gz7.88 KB

#1

millette - October 28, 2008 - 18:00

I'd like to see Drupal 5 still supported too. I tried your version but didn't get far not much time to look at the problem closely yet. I see the general twitter settings under admin, then the twitter tab under my user account, but the latter is empty. Glancing at the code, it seems twitter account info must be entered along with the new content, am I right?

I'll look at this further when I have a moment.

Unrelated, but I'm interested in adding identica/laconica support since that software also makes use of the twitter api. It shouldn't be too hard to make the module support any site using the twitter api. I also spoke to walkah and eaton about it and they were both glad to hear that.

#2

SteveJB - October 29, 2008 - 16:53

Works but even though I set it to post only blog posts to twitter, the twitter modules has all node types checked when I create a new node (eg. page nodes on creation have post to twitter checked even though blog posts are the only posts meant to post to twitter.)

#3

jaydub - November 9, 2008 - 17:11

#2 yeah I just realized that the per node type settings don't work in the d6 version either which I based the backport on. The admin settings are there but there is no implementation of the per node type settings in the hook_form_alter implementation used to add the post to twitter form to node add pages.

I'll roll a new patch which that addition and submit the patch for the d6 version as well.

#1 yes a user that wants to use the drupal twitter module has to enter their twitter account details on their user profile page for the module to do anything.

#4

jaydub - November 9, 2008 - 17:44

Ok I've attached a small patch to the d6 version for checking the node type as well as reposting the tarball of the d5 version from above with the update for checking the node type.

AttachmentSize
twitter.module.patch 740 bytes
twitter5.tar_.gz 7.91 KB

#5

Clint Eagar - November 12, 2008 - 16:09

I just installed the D5 module from post #4 and get this error when trying to add my twitter account.

Fatal error: Call to undefined function drupal_write_record() in /home/xxxxxx/public_html/sites/all/modules/twitter/twitter.inc on line 401

#6

jaydub - November 13, 2008 - 01:52

missed that one from the d6 version...here's a replacement for twitter.inc

Rename this file from twitter.inc.patch to twitter.inc . This is NOT a patch
file but is the whole file. d.o. doesn't let you attach files that don't end
with certain extensions such as gz, patch, diff, etc...

AttachmentSize
twitter.inc_.patch 15.46 KB

#7

jaydub - November 13, 2008 - 13:43

Disregard the file in #7 and use this one instead.

AttachmentSize
twitter.inc_.patch 15.46 KB

#8

cogdog - January 5, 2009 - 05:10

Thanks for the backport effort, but I am running into one problem after another, and am out of ideas. I have enabled creating twitter accounts in my user/roles setting and am trying for now just tweeting from a blog post

Problem #! - the last patch posted has an error on line 401 - it is missing a "}" before the "else" statement

Problem #2 - on a first test, my logs stated there was a missing twitter.js file in the modules/twitter folder. In total guess mode, I uploaded the twitter.js file from the 6.x version

Problem #3 - When I enter a twitter user name /password on the User /edit screen, the account never "sticks"- when I return to this editing page, the fields are blank, so it is looking like the account info is never stored (I have not yet peeked into the database). Statuses are never shown for the twitter tab on my account

Problem #4 - When I publish a new blog post, it says that it posted to Twitter, but the tweet never appears

I'd really like to avoid having to climb down into the code, but am at a wall as our site is not ready yet for 6.x

Thanks for any help, I really need this module!!

Update Not sure what I did (re-uploaded the twitter.inc file) but it is now working. except for problem #3- it still is not showing that an account is entered....

#9

jaydub - January 5, 2009 - 16:47

did you try entering the account details again after you re-added the twitter.inc file?

#10

cogdog - January 7, 2009 - 05:52

Yep, it happens every time I enter the account details; they never stick. The swapping of the twitter.inc file was on my dev server- I moved the clean files to my production server and it happens there. Am trying to follow the logic of the account fetching part to see where it is losing data. Is it meant to populate the form fields with default values of an existing account?

#11

jaydub - January 7, 2009 - 06:05

are you able to check your logfiles for any possible PHP errors? It could be that there is a problem but if you have error reporting turned off or only shown in the logfiles that you are missing something. If you have the watchdog enabled maybe check that after trying again to see if any PHP errors show up.

I don't have any trouble myself but it's been awhile since I checked this out again. I'll try to remove my account and re-enter again to see that is stores ok.

#12

jaydub - January 7, 2009 - 14:05

I just checked again and was able to remove my account and re-add it back successfully.

If anyone else following this issue can chime in if they have trouble...

#13

jaydub - January 7, 2009 - 14:06

and it should go without saying but the account info you enter if for your Twitter account. If you don't enter the proper username/password then it won't work either.

#14

cogdog - January 11, 2009 - 19:19

Thanks for the efforts. Per your questions:

* There are no PHP errors, checked the apache error logs
* There is no problem entering the account information, it is all being correctly registered in the database tables for this module- I can see all the accounts, and the tweets are properly displayed for the account. There is, at least on my site, some problems with the part of the code that display the accounts.
* Account information is verified; I tested by giving wrong information, and it caught that error

I am an experienced PHP developers but still new at the drupal structure. I traced the steps with a lot of outputting of variable values and var_dumps of arrays. I finally got the display to work, with a bit of ugliness. What I found:

* twitter.module line 31: not sure why an array of a user id is passed; I just changed it to:

'callback arguments' => $user->uid

* twitter.inc function twitter_get_user_accounts : simplified from arrays of a single id integer to

function twitter_get_user_accounts($uid, $only_with_passwords = FALSE) {
  $sql = "SELECT ta.*, tu.uid, tu.password, tu.import FROM {twitter_user} tu LEFT JOIN {twitter_account} ta ON (tu.screen_name = ta.screen_name) WHERE tu.uid = $uid";
  if ($only_with_passwords) {
    $sql .= " AND tu.password IS NOT NULL";
  }
  $results = db_query($sql);
 
  $accounts = array();
  while ($account = db_fetch_array($results)) {
    $accounts[$account['screen_name']] = $account;
  }
  return $accounts;
}

* The biggest mystery makes no sense but I confirmed it 5 times. In twitter_pages.inc function twitter_user_settings gets a correct value for the array of twitter accounts $twitter_accounts, but when it was passed to function twitter_account_list_form this value ended up as NULL. I could not make any sense of it, and ONLY got the display to list accounts by instead making this a global variable. It is an ugly way

I appreciate the efforts, and now at least my users when they create accounts will see them as listed.

#15

jaydub - January 12, 2009 - 03:30

Regarding some of your comments:

* twitter.module line 31: not sure why an array of a user id is passed; I just changed it to:

The arguments must be in an array. See: http://api.drupal.org/api/function/hook_menu/5
specifically: "callback arguments": An array of arguments to pass to the callback function. "

* twitter.inc function twitter_get_user_accounts : simplified from arrays of a single id integer to

This portion of the code is from the original authors and has not been changed for d5. The change you've made is not needed and in fact not the 'Drupal way'. The original code uses a placeholder for the user id (int) of %d. The array of the user id is passed to the query function and the %d is replaced with the value.

This is the standard Drupal query method. See: http://api.drupal.org/api/function/db_query/5
specifically: User-supplied arguments to the query should be passed in as separate parameters so that they can be properly escaped to avoid SQL injection attacks.

NOW that being said, I did find a couple problems that I think I've resolved. They were due to subtle changes in the port from the d6 version to d5 that were overlooked.

Please try using the attached files and reserve the two changes you made that are referenced above. Just remove the .txt extension to use.

AttachmentSize
twitter.module.txt 7.43 KB
twitter.pages_.inc_.txt 7.01 KB

#16

cogdog - January 15, 2009 - 06:46

Thanks so much, your changes work perfectly in my D5 sites!

I am still learning the "drupal way" and was just hacking to get the code to work. Very much appreciate the quick responses.

#17

Boinng - January 23, 2009 - 11:29
Status:needs review» active

Thanks for all the work backporting, it's a shame 5.x isn't getting better support - I've installed this with the various patches above and it seems to be working for the most part (I can add my twitter account, have my tweets on my profile page, and send a tweet when creating a new story etc.

The biggest problem so far is that enabling the module for posting from any new content (eg story, forum topic, blog etc) seems to break the "create content" form's javascript for anyone who does NOT have their Twitter account setup (IE gives the "Done with errors" message, and the various options links dont work). I know very little about JS, but what appears to be happening is the twitter.js file is loading whether the user uses Twitter or not - if they do, then all form elements work fine, but if they don't then the JS doesn't tie up with the form and it all gets broken. Does that make any sense, and is their a simple fix, or is this something peculiar with my site?

#18

cogdog - February 2, 2009 - 14:44

I cannot replicate what you describe in my site; on my test account that has not set up a twitter account, all of my content creation forms work w/o error in Firefox and MSIE.

That likely does not help you identify your problem, but it seems at least from my one site to be something about yours.

#19

adub - February 23, 2009 - 22:36

Couldn't get it to work and hacked around found a couple of things:
1. Passwords hadn't been stored (possibly because I set the accounts up with an early version here)
2. this section at line 140 twitter.inc twitter_set_status() - needs to be removed/commented out:


  if (!empty($source)) {
    $data .= "&source=". urlencode($source);
  }

I also changed the functionality to post to the currently logged in user's twitter account rather than the author's - so for example an editor of a multi-author blog can post selected items to a twitter account for that blog (e.g. for a magazine site etc.):

In twitter.module twitter_nodeapi()

      if (!empty($node->status) && !empty($node->twitter) && !empty($node->twitter['post'])) {
+     global $user;
+        $twitter_accounts = twitter_get_user_accounts($user->uid, TRUE);
-        $twitter_accounts = twitter_get_user_accounts($node->uid, TRUE);
        $replacements = array('!title' => $node->title,

#20

duckjerk - February 24, 2009 - 14:25

I am having the same issue as cogdog but mine still doesn't seem to work. I my accounts don't seem to stick this is what my account page looks like. Thanks for your help.

AttachmentSize
twitter_prob.gif 8.74 KB

#21

jaydub - February 24, 2009 - 18:28

Regarding #19, why did you need to make the change you outlined in 2)??

As for the other change you made in twitter_nodeapi(), that's up to you. The D5 backport is meant to reflect what is in the D6 module only. But if it works for your needs then go for it!

#22

adub - February 25, 2009 - 10:45

@jaydub It didn't appear on twitter with that code in but did when I commented it out. I didn't dig in to find out why so this is just a bit of hacking but might be a starting point if anyone else has the same problem.

#23

FatPitchFinancials - March 9, 2009 - 12:46

Thanks for backporting this module to Drupal 5. I ran into two issues after installing the latest version of this backport.
1. The profile Twitter tab does not appear publicly. It seems to only be visible to the user that added the Twitter account. I would like my users to browse each other's tweets. How do I do that?
2. The output of the Tweets page does not have hyperlinks or @names hyperlinked. I noticed in the module code there is a function that is suppose to do this, but it doesn't appear to be working.

On a positive note, when new nodes are added, the titles and urls are posted to Twitter. However, I had to change the default tweet format, since it enclosed the !url in parentheses link (!url) and that trailing ) would get added to the link and cause it to break. I suggest changing the default in the next version of this module to leave out the problematic parentheses.

Finally, has anyone tried to integrate this with Views 1. I would really like to create a page displaying the latest tweets of all the users on my site. Thanks.

#24

sinmao - March 11, 2009 - 13:41

I can't find the twitter login/pw anywhere in the user profile page (user/1/edit). I have twitter checked for authenticated users in user roles section too. Applied the latest version on post #15. I renamed "twitter.pages_.inc_.txt" to "twitter.pages.inc". Is that right?

#25

SimonV - March 18, 2009 - 18:07

Same issue as above. I see the Twitter tab, but I see nothing after I click that tab. I had a db error when I first went to that page and had to create the tables manually.

#26

funana - March 21, 2009 - 21:39

@sinmao you probably forgot to put all needed files into the /twitter module folder.

I repacked all needed files into the attached archive. Works like a charm on my D5 site.

How do we get it to work with Views now? Would be great to use the tweets in Views!

AttachmentSize
twitter.tar_.gz 13.42 KB

#27

funana - March 21, 2009 - 23:13

1. The profile Twitter tab does not appear publicly. It seems to only be visible to the user that added the Twitter account. I would like my users to browse each other's tweets. How do I do that?

Yeah, that's something I miss too. Tried to add 'access' => user_access('access content'), but did not work...

2. The output of the Tweets page does not have hyperlinks or @names hyperlinked. I noticed in the module code there is a function that is suppose to do this, but it doesn't appear to be working.

Wohaa, that would be a great feature! How to fix this?

#28

webchick - March 22, 2009 - 02:21
Status:active» needs review

Marking needs review, since this is a patch.

#29

mdowsett - March 24, 2009 - 05:26

the tarball in #26 worked for me....but only after knowing to go to user/1/edit/twitter to enter my Twitter account info. There was no additional tab in my user edit page to get to it.

Is it just me (my theme?) or is it a bug for every one? My general users would have no idea to go there to add their Twitter account info...

#30

mdowsett - March 24, 2009 - 05:29

I switched my theme back to Garland and I couldn't get to it either....must be a bug then.

#31

jasonflenniken - March 25, 2009 - 05:32

the hyperlinks are implemented as a filter hook.

make sure you go to site config->input filters, and for any enabled filters go into their config and make sure the 2 twitter filters defined there are checked/enabled.

#32

joachim - May 7, 2009 - 11:18

Tried the tarball in #26.

- as mentioned above, 'user/UID/edit/twitter', doesn't show as a tab. This happens if profile module isn't installed or if there is only one profile field category. See line 835 of user.module. We should really add $category['name'] == 'account' as a MENU_DEFAULT_LOCAL_TASK
- also, I don't understand the UI here once an account has been entered. The form below the listed account is blank -- does that mean that entering a username here adds a second account? If so, how do I change the username of the existing one? Or can I only delete it?
- You're missing a hook_update_N, or documentation to say that the module needs to be reinstalled... I had previously installed the 5-dev version and that doesn't create any tables, so once I unpacked the files from the tarball I got error messages about tables.
- 'title' => t('Twitter setup'), -- 'setup' is redundant here. We're in the configuration menu already.
- there is no way for an admin user to set up a twitter account for someone else, because of the way hook_menu checks the user id. I don't know if this is a missing feature in 6 too though -- but I know a site admin is bound to say to me "I have a user who can't set his twitter account up and I can't get in to do it for him"
- hook_form_alter: only require twitter.inc if we need to do something.
- twitter_link_filter: I don't think it's good form to call this once with defaults and once without. Defaults should be a null case, rather than something that has meaning like filtering the @usernames. THough again, 6 might do this, I don't know.

Works nicely once set up.
Minor fixes needed but it would be nice if a maintainer could commit this and then we can submit minor patches.

#33

joachim - May 7, 2009 - 13:42

Here's an updated version of that zip with a few fixes I've made:

- set page title when editing an account (otherwise for an account not your own, you just get "user".
- fix tabs not showing when profile module not installed or has no categories.
- allow admins to edit twitter settings of other accounts.
- the side-effect is that this also allows tweets of other users to be seen in the user account tabs. I don't know if that's desirable or not, but a simple access check can restore current behaviour where you can only see your own tweets.

AttachmentSize
twitter-D5-33.zip 15.29 KB

#34

joachim - May 7, 2009 - 13:58

One fix to the above:

The call to get the twitter_add_account form should be:

$output .= drupal_get_form('twitter_add_account', NULL, $account);

for reasons I can't fathom... seems that the 2nd param gets eaten somewhere and the form builder only sees param 3.

Also, a bug: trying to add a twitter account that doesn't exist produces LOTS of ugly XML error messages. It should instead just give a human-readable warning.

#35

twirlingsky - May 27, 2009 - 00:03

subscribing

#36

plan9 - June 12, 2009 - 11:50

Just wanted to say thanks to everyone who's contributed to this backport,
great work guys - and it's good to see 5.x still being supported.

There are lot's of us still unable to make the leap to 6

Keep up the good work!!!

G

#37

lunarbear - June 15, 2009 - 11:16

subscribing

#38

moonray - June 24, 2009 - 17:48

Did anyone backport the twitpocalypse patch yet?

#39

ambereyes - June 24, 2009 - 22:39

subscribe

#40

moonray - June 24, 2009 - 23:16

Here's an updated version with the "twitpocalypse" patch.

AttachmentSize
twitter.zip 40.11 KB

#41

moonray - June 24, 2009 - 23:30

Sorry, use this archive instead.
It differs slightly from #33. There is also an additional block which adds a feed from the twitter feed of user 1. This can be used if you want to have a twitter feed displayed on your site as the "official" twitter feed.

If you want just the "twitpocalypse" fixes, all you need is the updated twitter.inc file and the updated twitter.install file.

AttachmentSize
twitter.zip 39.63 KB

#42

Taliesan - July 1, 2009 - 22:47

NVM - Found what I was after.

#43

funana - July 7, 2009 - 03:44

Thank you very much moonray. Very appreciated. Keeping the D5 version alive :)

#44

taqwa - July 10, 2009 - 02:18

subscribing. love you guys...

#45

taqwa - July 10, 2009 - 02:48

I installed the version from #41 on my site. Here are the issues I'm currently having:

1) I created a brand new twitter account. I then signed in as a user on my site (not admin) and visited the edit/twitter page. After entering the twitter account info the image under the name field fails to load.

2) I disabled importing tweets from the admin account through the Twitter setup page. However, for my non admin user, import is checked by default. I think it makes more sense for that option to disappear when importing is disabled. On my site I would like for users to only be able to post their submissions as tweets.

3) I don't see the option for a user to enable posting his or her submission on twitter. I thought it was an access control issue but all I see on that page is "Add Twitter account". Ideally, I think this option should be on the edit/twitter page.

Thanks for the hard work you guys have put into this so far. I imagine the issues I'm bringing up are simple tweaks/explanations for those of you who are already familiar with this module. If not, I'll take a dive into the code and see if I can figure out what's going on.

#46

joachim - July 10, 2009 - 08:09
Priority:normal» critical

Could either of the maintainers either commit one of the above patches or appoint someone to maintain the D5 branch please? It's starting to get too complicated keeping track of the changes.

#47

sinasalek - July 17, 2009 - 15:15

Subscribed...

#48

wflorian - August 2, 2009 - 07:54

Like Joachim already said: Could one of the maintainer commit the above patches to the D5 brach please?

Everybody else: Thank you for keeping up the work on the D5 release of this module!

#49

sinasalek - August 3, 2009 - 09:39

Yes, please commit it.

#50

dandaman - August 11, 2009 - 20:16

Folks, the current status says "needs review". If you have adequately reviewed and tested the code, I believe it is protocol to change it to "reviewed and tested by the community". That may be what the current developers are expecting to see before they come in, review the issue and the code and then commit the code.

I may be wanting to use this code for a client on 5.x, so I may be reviewing the code myself if you don't get to it. Thanks!

#51

plan9 - August 16, 2009 - 22:00

I'm getting cron killed by these errors:

SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /var/www/vhosts/site.net/httpdocs/sites/all/modules/twitter/twitter.inc on line 439.

Can we please have this fix in the D5 backport? http://drupal.org/node/550154

Thanks

G

#52

joachim - August 16, 2009 - 22:08

> Folks, the current status says "needs review". If you have adequately reviewed and tested the code, I believe it is protocol to change it to "reviewed and tested by the community".

Every module maintainer has their own view of how much testing is enough for a patch. I wouldn't want to presume.

It would be nice to get some sort of sign of life from the maintainers. Both are active in Drupal, but perhaps this module has fallen down their list of priorities. Perhaps someone could ping them on IRC? Or perhaps one of the above commenters could volunteer to maintain the D5 branch?

#53

plan9 - August 17, 2009 - 13:00

The patch here appears to fix the SimpleXMLElement errors: http://drupal.org/node/475924#comment-1796718 I added the lines manually and the errors have stopped.

#54

plan9 - August 18, 2009 - 13:24

The SimpleXMLElement errors patch doesn't work.

#55

funana - September 7, 2009 - 18:00

SimpleXMLElement errors patch doesn't work, seems to be a problem with watchdog. How to in D5?

Edit: Sorry, had a typo in code, applied and works. At least the cron runs without errors.

#56

joachim - September 8, 2009 - 11:49

I've requested a maintainer be appointed for the 5 branch: http://drupal.org/node/571414
any volunteers?

#57

dhroople - October 11, 2009 - 14:30

Here is the 5 version It is not able to post to twitter ?

AttachmentSize
twitter_p.zip 36.9 KB

#58

dhroople - October 14, 2009 - 08:47

Soloution needed for above

#59

plan9 - October 29, 2009 - 17:38

I also confirm that this backport has stopped working. I'm using the version posted with comment #41 and tweets are no longer posted. What a shame :(

Recently upgraded to Drupal 5.20 maybe this has relevance?

#60

dhroople - November 6, 2009 - 12:02

Here is the modified version of twitter 5 from #57. It is able to post on twitter but the problem is that only from user 1. Other users post are not posted to twitter. Please provide the soloution and revert back the version to community to get it work better.

#61

dhroople - November 6, 2009 - 12:05

this is the attachment for above

AttachmentSize
twitter_mod.zip 18.48 KB
 
 

Drupal is a registered trademark of Dries Buytaert.