3 * StatusNet - the distributed open-source microblogging tool
\r
4 * Copyright (C) 2009, StatusNet, Inc.
\r
6 * Send and receive notices using the MSN network
\r
10 * This program is free software: you can redistribute it and/or modify
\r
11 * it under the terms of the GNU Affero General Public License as published by
\r
12 * the Free Software Foundation, either version 3 of the License, or
\r
13 * (at your option) any later version.
\r
15 * This program is distributed in the hope that it will be useful,
\r
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
18 * GNU Affero General Public License for more details.
\r
20 * You should have received a copy of the GNU Affero General Public License
\r
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
24 * @package StatusNet
\r
25 * @author Luke Fitzgerald <lw.fitzgerald@googlemail.com>
\r
26 * @copyright 2010 StatusNet, Inc.
\r
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
\r
28 * @link http://status.net/
\r
31 if (!defined('STATUSNET')) {
\r
32 // This check helps protect against security problems;
\r
33 // your code file can't be executed directly from the web.
\r
36 // We bundle the phpmsnclass library...
\r
37 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/phpmsnclass');
\r
43 * @package StatusNet
\r
44 * @author Luke Fitzgerald <lw.fitzgerald@googlemail.com>
\r
45 * @copyright 2010 StatusNet, Inc.
\r
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
\r
47 * @link http://status.net/
\r
50 class MsnPlugin extends ImPlugin {
\r
51 public $user = null;
\r
52 public $password = null;
\r
53 public $nickname = null;
\r
54 public $transport = 'msn';
\r
57 * Get the internationalized/translated display name of this IM service
\r
59 * @return string Name of service
\r
61 public function getDisplayName() {
\r
66 * Normalize a screenname for comparison
\r
68 * @param string $screenname screenname to normalize
\r
69 * @return string an equivalent screenname in normalized form
\r
71 public function normalize($screenname) {
\r
72 $screenname = str_replace(" ","", $screenname);
\r
73 return strtolower($screenname);
\r
77 * Get the screenname of the daemon that sends and receives messages
\r
79 * @return string Screenname
\r
81 public function daemon_screenname() {
\r
86 * Validate (ensure the validity of) a screenname
\r
88 * @param string $screenname screenname to validate
\r
91 public function validate($screenname) {
\r
92 return Validate::email($screenname, common_config('email', 'check_domain'));
\r
96 * Load related modules when needed
\r
98 * @param string $cls Name of the class to be loaded
\r
99 * @return boolean hook value; true means continue processing, false means stop.
\r
101 public function onAutoload($cls) {
\r
102 $dir = dirname(__FILE__);
\r
106 require_once(INSTALLDIR.'/plugins/Msn/extlib/phpmsnclass/msn.class.php');
\r
109 include_once $dir . '/'.strtolower($cls).'.php';
\r
117 * Start manager on daemon start
\r
121 public function onStartImDaemonIoManagers(&$classes) {
\r
122 parent::onStartImDaemonIoManagers(&$classes);
\r
123 $classes[] = new MsnManager($this); // handles sending/receiving
\r
128 * Get a microid URI for the given screenname
\r
130 * @param string $screenname
\r
131 * @return string microid URI
\r
133 public function microiduri($screenname) {
\r
134 return 'msnim:' . $screenname;
\r
138 * Send a message to a given screenname
\r
140 * @param string $screenname Screenname to send to
\r
141 * @param string $body Text to send
\r
142 * @return boolean success value
\r
144 public function send_message($screenname, $body) {
\r
145 $this->enqueue_outgoing_raw(array('to' => $screenname, 'message' => $body));
\r
150 * Accept a queued input message.
\r
152 * @param array $data Data
\r
153 * @return true if processing completed, false if message should be reprocessed
\r
155 public function receive_raw_message($data) {
\r
156 $this->handle_incoming($data['sender'], $data['message']);
\r
161 * Initialize plugin
\r
165 public function initialize() {
\r
166 if (!isset($this->user)) {
\r
167 throw new Exception("Must specify a user");
\r
169 if (!isset($this->password)) {
\r
170 throw new Exception("Must specify a password");
\r
172 if (!isset($this->nickname)) {
\r
173 throw new Exception("Must specify a nickname");
\r
180 * Get plugin information
\r
182 * @param array $versions array to insert information into
\r
185 public function onPluginVersion(&$versions) {
\r
186 $versions[] = array(
\r
188 'version' => STATUSNET_VERSION,
\r
189 'author' => 'Luke Fitzgerald',
\r
190 'homepage' => 'http://status.net/wiki/Plugin:MSN',
\r
191 'rawdescription' =>
\r
192 _m('The MSN plugin allows users to send and receive notices over the MSN network.')
\r