enjitqueuehandler.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2008, 2009, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('STATUSNET') && !defined('LACONICA')) {
  20. exit(1);
  21. }
  22. /**
  23. * Queue handler for watching new notices and posting to enjit.
  24. * @todo FIXME: Is this actually being used/functional atm?
  25. */
  26. class EnjitQueueHandler extends QueueHandler
  27. {
  28. function transport()
  29. {
  30. return 'enjit';
  31. }
  32. function handle($notice)
  33. {
  34. $profile = Profile::getKV($notice->profile_id);
  35. $this->log(LOG_INFO, "Posting Notice ".$notice->id." from ".$profile->nickname);
  36. if ( ! $notice->is_local ) {
  37. $this->log(LOG_INFO, "Skipping remote notice");
  38. return "skipped";
  39. }
  40. #
  41. // Build an Atom message from the notice
  42. #
  43. $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
  44. $msg = $profile->nickname . ': ' . $notice->content;
  45. $atom = "<entry xmlns='http://www.w3.org/2005/Atom'>\n";
  46. $atom .= "<apisource>".common_config('enjit','source')."</apisource>\n";
  47. $atom .= "<source>\n";
  48. $atom .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n";
  49. $atom .= "<link href='" . $profile->profileurl . "'/>\n";
  50. $atom .= "<link rel='self' type='application/rss+xml' href='" . common_local_url('userrss', array('nickname' => $profile->nickname)) . "'/>\n";
  51. $atom .= "<author><name>" . $profile->nickname . "</name></author>\n";
  52. $atom .= "<icon>" . $profile->avatarUrl(AVATAR_PROFILE_SIZE) . "</icon>\n";
  53. $atom .= "</source>\n";
  54. $atom .= "<title>" . htmlspecialchars($msg) . "</title>\n";
  55. $atom .= "<summary>" . htmlspecialchars($msg) . "</summary>\n";
  56. $atom .= "<link rel='alternate' href='" . $noticeurl . "' />\n";
  57. $atom .= "<id>". $notice->uri . "</id>\n";
  58. $atom .= "<published>".common_date_w3dtf($notice->created)."</published>\n";
  59. $atom .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n";
  60. $atom .= "</entry>\n";
  61. $url = common_config('enjit', 'apiurl') . "/submit/". common_config('enjit','apikey');
  62. $data = array(
  63. 'msg' => $atom,
  64. );
  65. #
  66. // POST the message to $config['enjit']['apiurl']
  67. #
  68. $request = HTTPClient::start();
  69. $response = $request->post($url, null, $data);
  70. return $response->isOk();
  71. }
  72. }