Fix deprecation warnings
[lorea:beechat.git] / start.php
1 <?php
2         /**
3          * Beechat
4          * 
5          * @package beechat
6          * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
7          * @author Beechannels <contact@beechannels.com>
8          * @copyright Beechannels 2007-2010
9          * @link http://beechannels.com/
10          */
11
12         GLOBAL $CONFIG;
13         
14         function beechat_create_group($event, $object_type, $object)
15         {
16                 elgg_load_library('elgg:beechat');
17                 ejabberd_create_group($object);
18         }
19
20         function beechat_delete_group($event, $object_type, $object)
21         {
22                 elgg_load_library('elgg:beechat');
23                 ejabberd_destroy_group($object);
24         }
25
26         function beechat_member_add($event, $object_type, $object)
27         {
28                 if ($object->relationship === "member") {
29                         elgg_load_library('elgg:beechat');
30                         $user = get_entity($object->guid_one);
31                         $group = get_entity($object->guid_two);
32                         $room = new EjabberdMucRoom($group);
33                         $room->addMember($user);
34                 }
35         }
36
37         function beechat_member_delete($event, $object_type, $object)
38         {
39                 if ($object->relationship === "member") {
40                         elgg_load_library('elgg:beechat');
41                         $user = get_entity($object->guid_one);
42                         $group = get_entity($object->guid_two);
43                         $room = new EjabberdMucRoom($group);
44                         $room->setAffiliation($user, "none");
45                 }
46         }
47
48         function beechat_init()
49         {
50                 $pluginspath = elgg_get_plugins_path();
51                 elgg_register_library('elgg:beechat', $pluginspath . 'beechat/lib/beechat.php');
52
53                 elgg_register_event_handler('pagesetup', 'system', 'beechat_pagesetup');
54                 // group actions disabled for now
55                 /*if (elgg_get_plugin_setting("groupdomain", "beechat")) {
56                         register_elgg_event_handler('create', 'group', 'beechat_create_group');
57                         register_elgg_event_handler('delete', 'group', 'beechat_delete_group');
58                 }
59                 register_elgg_event_handler('create', 'member', 'beechat_member_add');
60                 register_elgg_event_handler('delete', 'relationship', 'beechat_member_delete');*/
61
62
63                 $actions_path = $pluginspath . 'beechat/actions/';
64                 //elgg_register_action('beechat/join_groupchat', $actions_path . 'join_groupchat.php');
65                 //elgg_register_action('beechat/leave_groupchat', $actions_path . 'leave_groupchat.php');
66                 elgg_register_action('beechat/get_statuses', $actions_path . 'get_statuses.php');
67                 elgg_register_action('beechat/get_icons', $actions_path . 'get_icons.php');
68                 elgg_register_action('beechat/get_details', $actions_path . 'get_details.php');
69                 elgg_register_action('beechat/get_connection', $actions_path . 'get_connection.php');
70                 elgg_register_action('beechat/get_state', $actions_path . 'get_state.php');
71                 elgg_register_action('beechat/save_state', $actions_path . 'save_state.php');
72
73                 /*register_elgg_event_handler('create', 'friendrequest', 'beechat_xmpp_add_friendx');
74                 #register_plugin_hook('action', 'friends/add', 'beechat_xmpp_add_friend', 1000);
75                 register_plugin_hook('river_update', 'river_update', 'beechat_xmpp_approve_friendx');
76                 register_plugin_hook('river_update_foreign', 'river_update', 'beechat_xmpp_approve_friendx');
77                 #register_plugin_hook('action', 'friendrequest/approve', 'beechat_xmpp_approve_friend', 1000);
78
79
80                 register_plugin_hook('action', 'friendrequest/decline', 'beechat_xmpp_decline_friend', 1000);
81                 register_plugin_hook('action', 'friends/remove', 'beechat_xmpp_remove_friend', 1000);*/
82
83                 // new friend sync
84                 elgg_register_event_handler('delete', 'friend', array('BeechatSync', 'onFriendDelete'));
85                 elgg_register_event_handler('create', 'friendrequest', array('BeechatSync', 'onFriendCreate'));
86                 elgg_register_event_handler('delete', 'friendrequest', array('BeechatSync', 'onFriendDelete'));
87
88
89         
90                 elgg_extend_view('js/initialise_elgg', 'js/json2.js');
91                 elgg_extend_view('js/initialise_elgg', 'js/jquery.cookie.min.js');
92                 elgg_extend_view('js/initialise_elgg', 'js/jquery.scrollTo-min.js');
93                 elgg_extend_view('js/initialise_elgg', 'js/jquery.serialScroll-min.js');
94                 elgg_extend_view('js/initialise_elgg', 'js/b64.js');
95                 elgg_extend_view('js/initialise_elgg', 'js/sha1.js');
96                 elgg_extend_view('js/initialise_elgg', 'js/md5.js');
97                 elgg_extend_view('js/initialise_elgg', 'js/strophe.min.js');
98                 elgg_extend_view('js/initialise_elgg', 'js/strophe.muc.js');
99                 elgg_extend_view('js/initialise_elgg', 'js/jquery.tools.min.js');
100                 elgg_extend_view('css', 'beechat/screen.css');
101                 elgg_extend_view('js/initialise_elgg', 'beechat/beechat.js');
102                 elgg_extend_view('page/elements/head', 'beechat/beechat.userjs');
103                 
104                 elgg_extend_view('page/elements/foot', 'beechat/beechat');
105
106                 $domain = elgg_get_plugin_setting("domain", "beechat");
107                 //$group_domain = elgg_get_plugin_setting("groupdomain", "beechat");
108                 /*$dbname = elgg_get_plugin_setting("dbname", "beechat");
109                 $dbhost = elgg_get_plugin_setting("dbhost", "beechat");
110                 $dbuser = elgg_get_plugin_setting("dbuser", "beechat");
111                 $dbpassword = elgg_get_plugin_setting("dbpassword", "beechat");*/
112
113                 global $CONFIG;
114                 $CONFIG->chatsettings['domain'] = $domain;
115                 //$CONFIG->chatsettings['groupdomain'] = $group_domain;
116
117                 register_notification_handler('xmpp', 'beechat_notifications');
118         //      register_plugin_hook('notify:entity:message','object','beechat_notifications_msg');
119         }
120
121         function beechat_notifications($from, $to, $subject, $topic, $params = array()) {
122                 ejabberd_send_chat($to, "<div>".$topic."</div>");
123         }
124
125
126         function beechat_friendly_title($title) {
127                 // need this because otherwise seems elgg
128                 // gets in some problem trying to call the view
129                 //$title = iconv('UTF-8', 'ASCII//TRANSLIT', $title);
130                 $title = preg_replace("/[^\w ]/","",$title);
131                 $title = str_replace(" ","-",$title);
132                 $title = str_replace("--","-",$title);
133                 $title = trim($title);
134                 $title = strtolower($title);
135                 return $title;
136         }
137
138         function beechat_pagesetup()
139         {
140                 global $CONFIG;
141                 /*if (get_context() == 'group_profile' && isloggedin()) {
142                         if (get_plugin_setting("groupdomain", "beechat")) {
143                                 $user = get_loggedin_user();
144                                 $group = page_owner_entity();
145                                 if (!$group || !($group instanceof ElggGroup))
146                                         return;
147                                 if ($user->chatenabled && get_plugin_setting("groupdomain", "beechat")) {
148                                         if ($group->isPublicMembership() || $group->isMember($user))
149                                         add_submenu_item(elgg_echo('beechat:chatroom'), "javascript:g_beechat_user.joinRoom('".beechat_friendly_title($group->name)."@".$CONFIG->chatsettings['groupdomain']."', '".$group->guid."')");
150                                 }
151                         }
152                 }
153                 else*/if (elgg_get_context() == 'settings' && elgg_is_logged_in()) {
154                         if (get_loggedin_user()->chatenabled) {
155                                 add_submenu_item(elgg_echo('beechat:disablechat'), $CONFIG->wwwroot . "mod/beechat/disablechat.php");
156                         }
157                         else
158                                 add_submenu_item(elgg_echo('beechat:enablechat'), $CONFIG->wwwroot . "mod/beechat/enablechat.php");
159                 }
160         }
161
162
163         function ejabberd_send_chat($user, $body) { // $user adds $friend
164                 $from = 'notify@'.get_plugin_setting("domain", "beechat").'/net';
165                 if ($user->alias) {
166                         
167                 }
168                 elgg_load_library('elgg:beechat');
169                 $to = ejabberd_getjid($user, true);
170                 //xmlrpc_set_type(&$body, "base64"); 
171                 $param = array("body" => $body,
172                                 "from" => $from,
173                                 "to" => $to);
174                 ejabberd_xmlrpc_command('send_html_message', $param);
175         }
176
177
178
179
180 elgg_register_event_handler('init', 'system', 'beechat_init');
181 ?>