AimPlugin.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2009, StatusNet, Inc.
  5. *
  6. * Send and receive notices using the AIM network
  7. *
  8. * PHP version 5
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category IM
  24. * @package StatusNet
  25. * @author Craig Andrews <candrews@integralblue.com>
  26. * @copyright 2009 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. // We bundle the phptoclib library...
  36. set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/phptoclib');
  37. /**
  38. * Plugin for AIM
  39. *
  40. * @category Plugin
  41. * @package StatusNet
  42. * @author Craig Andrews <candrews@integralblue.com>
  43. * @copyright 2009 StatusNet, Inc.
  44. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  45. * @link http://status.net/
  46. */
  47. class AimPlugin extends ImPlugin
  48. {
  49. public $user = null;
  50. public $password = null;
  51. public $publicFeed = array();
  52. public $transport = 'aim';
  53. function getDisplayName()
  54. {
  55. // TRANS: Display name.
  56. return _m('AIM');
  57. }
  58. function normalize($screenname)
  59. {
  60. $screenname = str_replace(" ","", $screenname);
  61. return strtolower($screenname);
  62. }
  63. function daemonScreenname()
  64. {
  65. return $this->user;
  66. }
  67. function validate($screenname)
  68. {
  69. if(preg_match('/^[a-z]\w{2,15}$/i', $screenname)) {
  70. return true;
  71. }else{
  72. return false;
  73. }
  74. }
  75. /**
  76. * Load related modules when needed
  77. *
  78. * @param string $cls Name of the class to be loaded
  79. *
  80. * @return boolean hook value; true means continue processing, false means stop.
  81. */
  82. function onAutoload($cls)
  83. {
  84. $dir = dirname(__FILE__);
  85. switch ($cls)
  86. {
  87. case 'Aim':
  88. require_once(INSTALLDIR.'/plugins/Aim/extlib/phptoclib/aimclassw.php');
  89. return false;
  90. }
  91. return parent::onAutoload($cls);
  92. }
  93. function onStartImDaemonIoManagers(&$classes)
  94. {
  95. parent::onStartImDaemonIoManagers($classes);
  96. $classes[] = new AimManager($this); // handles sending/receiving
  97. return true;
  98. }
  99. function microiduri($screenname)
  100. {
  101. return 'aim:' . $screenname;
  102. }
  103. function sendMessage($screenname, $body)
  104. {
  105. $this->fake_aim->sendIm($screenname, $body);
  106. $this->enqueueOutgoingRaw($this->fake_aim->would_be_sent);
  107. return true;
  108. }
  109. /**
  110. * Accept a queued input message.
  111. *
  112. * @return true if processing completed, false if message should be reprocessed
  113. */
  114. function receiveRawMessage($message)
  115. {
  116. $info=Aim::getMessageInfo($message);
  117. $from = $info['from'];
  118. $user = $this->getUser($from);
  119. $notice_text = $info['message'];
  120. $this->handleIncoming($from, $notice_text);
  121. return true;
  122. }
  123. function initialize(){
  124. if(!isset($this->user)){
  125. // TRANS: Exception thrown in AIM plugin when user has not been specified.
  126. throw new Exception(_m('Must specify a user.'));
  127. }
  128. if(!isset($this->password)){
  129. // TRANS: Exception thrown in AIM plugin when password has not been specified.
  130. throw new Exception(_m('Must specify a password.'));
  131. }
  132. $this->fake_aim = new Fake_Aim($this->user,$this->password,4);
  133. return true;
  134. }
  135. function onPluginVersion(&$versions)
  136. {
  137. $versions[] = array('name' => 'AIM',
  138. 'version' => GNUSOCIAL_VERSION,
  139. 'author' => 'Craig Andrews',
  140. 'homepage' => 'http://status.net/wiki/Plugin:AIM',
  141. 'rawdescription' =>
  142. // TRANS: Plugin description.
  143. _m('The AIM plugin allows users to send and receive notices over the AIM network.'));
  144. return true;
  145. }
  146. }