-
Notifications
You must be signed in to change notification settings - Fork 8
/
start.php
180 lines (141 loc) · 6.03 KB
/
start.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
/**
* Beechat
*
* @package beechat
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Beechannels <[email protected]>
* @copyright Beechannels 2007-2010
* @link http://beechannels.com/
*/
GLOBAL $CONFIG;
function beechat_init()
{
GLOBAL $CONFIG;
register_translations($CONFIG->pluginspath . "beechat/languages/");
register_elgg_event_handler('pagesetup', 'system', 'beechat_pagesetup');
register_action('beechat/get_statuses', false, $CONFIG->pluginspath . 'beechat/actions/get_statuses.php');
register_action('beechat/get_icons', false, $CONFIG->pluginspath . 'beechat/actions/get_icons.php');
register_action('beechat/get_details', false, $CONFIG->pluginspath . 'beechat/actions/get_details.php');
register_action('beechat/get_connection', false, $CONFIG->pluginspath . 'beechat/actions/get_connection.php');
register_action('beechat/get_state', false, $CONFIG->pluginspath . 'beechat/actions/get_state.php');
register_action('beechat/save_state', false, $CONFIG->pluginspath . 'beechat/actions/save_state.php');
register_plugin_hook('action', 'friends/add', 'beechat_xmpp_add_friend');
register_plugin_hook('action', 'friends/remove', 'beechat_xmpp_remove_friend');
extend_view('js/initialise_elgg', 'js/json2.js');
extend_view('js/initialise_elgg', 'js/jquery.cookie.min.js');
extend_view('js/initialise_elgg', 'js/jquery.scrollTo-min.js');
extend_view('js/initialise_elgg', 'js/jquery.serialScroll-min.js');
extend_view('js/initialise_elgg', 'js/b64.js');
extend_view('js/initialise_elgg', 'js/sha1.js');
extend_view('js/initialise_elgg', 'js/md5.js');
extend_view('js/initialise_elgg', 'js/strophe.min.js');
extend_view('js/initialise_elgg', 'js/jquery.tools.min.js');
extend_view('css', 'beechat/screen.css');
extend_view('js/initialise_elgg', 'beechat/beechat.js');
extend_view('metatags', 'beechat/beechat.userjs');
extend_view('footer/analytics', 'beechat/beechat');
$domain = get_plugin_setting("domain", "beechat");
$dbname = get_plugin_setting("dbname", "beechat");
$dbhost = get_plugin_setting("dbhost", "beechat");
$dbuser = get_plugin_setting("dbuser", "beechat");
$dbpassword = get_plugin_setting("dbpassword", "beechat");
$CONFIG->chatsettings['domain'] = $domain;
$CONFIG->chatsettings['dbname'] = $dbname;
$CONFIG->chatsettings['dbhost'] = $dbhost;
$CONFIG->chatsettings['dbuser'] = $dbuser;
$CONFIG->chatsettings['dbpassword'] = $dbpassword;
}
function beechat_pagesetup()
{
global $CONFIG;
if (get_context() == 'settings' && isloggedin()) {
if (get_loggedin_user()->chatenabled) {
add_submenu_item(elgg_echo('beechat:disablechat'), $CONFIG->wwwroot . "mod/beechat/disablechat.php");
}
else
add_submenu_item(elgg_echo('beechat:enablechat'), $CONFIG->wwwroot . "mod/beechat/enablechat.php");
}
}
function beechat_xmpp_add_friend($hook, $entity_type, $returnvalue, $params)
{
GLOBAL $SESSION;
GLOBAL $CONFIG;
$jabber_domain = $CONFIG->chatsettings['domain'];
$dbname = $CONFIG->chatsettings['dbname'];
$dbhost = $CONFIG->chatsettings['dbhost'];
$dsn_ejabberd = "mysql:dbname={$dbname};host={$dbhost}";
$user = $CONFIG->chatsettings['dbuser'];
$password = $CONFIG->chatsettings['dbpassword'];
$friend_guid = get_input('friend', 0);
if (!$friend_guid || !$friend = get_entity($friend_guid))
return (false);
try
{
$dbh_ejabberd = new PDO($dsn_ejabberd, $user, $password);
$dbh_ejabberd->beginTransaction();
$sql = 'INSERT INTO rosterusers (username, jid, nick, subscription, ask, server, type) VALUES (?, ?, ?, ?, ?, ?, ?);';
$sth_ejabberd = $dbh_ejabberd->prepare($sql);
$username = $SESSION->offsetGet('user')->username;
$jid = $friend->username . '@' . $jabber_domain;
$nick = $friend->name;
$subscription = 'B';
$ask = 'N';
$server = 'N';
$type = 'item';
$sth_ejabberd->execute(array($username, $jid, $nick, $subscription, $ask, $server, $type));
$sql = 'INSERT INTO rosterusers (username, jid, nick, subscription, ask, server, type) VALUES (?, ?, ?, ?, ?, ?, ?);';
$sth_ejabberd = $dbh_ejabberd->prepare($sql);
$username = $friend->username;
$jid = $SESSION->offsetGet('user')->username . '@' . $jabber_domain;
$nick = $SESSION->offsetGet('user')->name;
$sth_ejabberd->execute(array($username, $jid, $nick, $subscription, $ask, $server, $type));
$dbh_ejabberd->commit();
$dbh_ejabberd = null;
}
catch (PDOException $e)
{
error_log('beechat_xmpp_add_friend: ' . $e->getMessage());
$dbh_ejabberd->rollBack();
return (false);
}
return $return_value;
}
function beechat_xmpp_remove_friend($hook, $entity_type, $returnvalue, $params)
{
GLOBAL $SESSION;
GLOBAL $CONFIG;
$jabber_domain = $CONFIG->chatsettings['domain'];
$dbname = $CONFIG->chatsettings['dbname'];
$dbhost = $CONFIG->chatsettings['dbhost'];
$dsn_ejabberd = "mysql:dbname={$dbname};host={$dbhost}";
$user = $CONFIG->chatsettings['dbuser'];
$password = $CONFIG->chatsettings['dbpassword'];
if (!$friend = get_entity(get_input('friend', 0)))
return (false);
try {
$dbh_ejabberd = new PDO($dsn_ejabberd, $user, $password);
$dbh_ejabberd->beginTransaction();
$sql = 'DELETE FROM rosterusers WHERE username = ? AND jid = ?;';
$sth_ejabberd = $dbh_ejabberd->prepare($sql);
$username = $SESSION->offsetGet('user')->username;
$jid = $friend->username . '@' . $jabber_domain;
$sth_ejabberd->execute(array($username, $jid));
$sql = 'DELETE FROM rosterusers WHERE username = ? AND jid = ?;';
$sth_ejabberd = $dbh_ejabberd->prepare($sql);
$username = $friend->username;
$jid = $SESSION->offsetGet('user')->username . '@' . $jabber_domain;
$sth_ejabberd->execute(array($username, $jid));
$dbh_ejabberd->commit();
$dbh_ejabberd = null;
}
catch (PDOException $e)
{
error_log('beechat_xmpp_remove_friend: ' . $e->getMessage());
$dbh_ejabberd->rollBack();
return (false);
}
return $return_value;
}
register_elgg_event_handler('init', 'system', 'beechat_init');
?>