]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Msn/MsnPlugin.php
6737e727abe9aa488b02009c3e0ba9b1a1903577
[quix0rs-gnu-social.git] / plugins / Msn / MsnPlugin.php
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
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36 // We bundle the phptoclib library...
37 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/phptoclib');
38
39 /**
40  * Plugin for AIM
41  *
42  * @category  Plugin
43  * @package   StatusNet
44  * @author    Craig Andrews <candrews@integralblue.com>
45  * @copyright 2009 StatusNet, Inc.
46  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
47  * @link      http://status.net/
48  */
49
50 class MsnPlugin extends ImPlugin
51 {
52     public $user =  null;
53     public $password = null;
54     public $publicFeed = array();
55
56     public $transport = 'msnim';
57
58     function getDisplayName()
59     {
60         return _m('MSN');
61     }
62
63     function normalize($screenname)
64     {
65                 $screenname = str_replace(" ","", $screenname);
66         return strtolower($screenname);
67     }
68
69     function daemon_screenname()
70     {
71         return $this->user;
72     }
73
74     function validate($screenname)
75     {
76         if(preg_match('/^[a-z]\w{2,15}$/i', $screenname)) {
77             return true;
78         }else{
79             return false;
80         }
81     }
82
83     /**
84      * Load related modules when needed
85      *
86      * @param string $cls Name of the class to be loaded
87      *
88      * @return boolean hook value; true means continue processing, false means stop.
89      */
90     function onAutoload($cls)
91     {
92         $dir = dirname(__FILE__);
93
94         switch ($cls)
95         {
96         case 'Msn':
97             require_once(INSTALLDIR.'/plugins/Msn/extlib/phpmsnclass/msn.class.php');
98             return false;
99         case 'MsnManager':
100             include_once $dir . '/'.strtolower($cls).'.php';
101             return false;
102         case 'Fake_Msn':
103             include_once $dir . '/'. $cls .'.php';
104             return false;
105         default:
106             return true;
107         }
108     }
109
110     function onStartImDaemonIoManagers(&$classes)
111     {
112         parent::onStartImDaemonIoManagers(&$classes);
113         $classes[] = new MsnManager($this); // handles sending/receiving
114         return true;
115     }
116
117     function microiduri($screenname)
118     {
119         return 'msnim:' . $screenname;    
120     }
121
122     function send_message($screenname, $body)
123     {
124         //$this->fake_aim->sendIm($screenname, $body);
125             //$this->enqueue_outgoing_raw($this->fake_aim->would_be_sent);
126             $this->enqueue_outgoing_raw(array($screenname, $body));
127         return true;
128     }
129
130     /**
131      * Accept a queued input message.
132      *
133      * @return true if processing completed, false if message should be reprocessed
134      */
135     function receive_raw_message($message)
136     {
137         $info=Aim::getMessageInfo($message);
138         $from = $info['from'];
139         $user = $this->get_user($from);
140         $notice_text = $info['message'];
141
142         $this->handle_incoming($from, $notice_text);
143
144         return true;
145     }
146
147     function initialize(){
148         if(!isset($this->user)){
149             throw new Exception("must specify a user");
150         }
151         if(!isset($this->password)){
152             throw new Exception("must specify a password");
153         }
154         if(!isset($this->nickname)) {
155             throw new Exception("must specify a nickname");
156         }
157
158         $this->fake_msn = new Fake_Msn($this->user,$this->password,4);
159         return true;
160     }
161
162     function onPluginVersion(&$versions)
163     {
164         $versions[] = array('name' => 'MSN',
165                             'version' => STATUSNET_VERSION,
166                             'author' => 'Luke Fitzgerald',
167                             'homepage' => 'http://status.net/wiki/Plugin:MSN',
168                             'rawdescription' =>
169                             _m('The MSN plugin allows users to send and receive notices over the MSN network.'));
170         return true;
171     }
172 }
173