aboutsummaryrefslogtreecommitdiff
path: root/start.php
blob: 4e4e4bb4083579555bd33201780be3991cda5ba9 (plain)
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
181
182
183
184
<?php
	/**
	 * Beechat
	 * 
	 * @package beechat
	 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
	 * @author Beechannels <contact@beechannels.com>
	 * @copyright Beechannels 2007-2010
	 * @link http://beechannels.com/
	 */

	GLOBAL $CONFIG;
	
	function beechat_create_group($event, $object_type, $object)
	{
		elgg_load_library('elgg:beechat');
		ejabberd_create_group($object);
	}

	function beechat_delete_group($event, $object_type, $object)
	{
		elgg_load_library('elgg:beechat');
		ejabberd_destroy_group($object);
	}

	function beechat_member_add($event, $object_type, $object)
        {
		if ($object->relationship === "member") {
			elgg_load_library('elgg:beechat');
			$user = get_entity($object->guid_one);
			$group = get_entity($object->guid_two);
			$room = new EjabberdMucRoom($group);
			$room->addMember($user);
		}
        }

	function beechat_member_delete($event, $object_type, $object)
        {
		if ($object->relationship === "member") {
			elgg_load_library('elgg:beechat');
			$user = get_entity($object->guid_one);
			$group = get_entity($object->guid_two);
			$room = new EjabberdMucRoom($group);
			$room->setAffiliation($user, "none");
		}
        }

	function beechat_init()
	{
		$pluginspath = elgg_get_plugins_path();
		elgg_register_library('elgg:beechat', $pluginspath . 'beechat/lib/beechat.php');

		elgg_register_event_handler('pagesetup', 'system', 'beechat_pagesetup');
		// group actions disabled for now
		/*if (elgg_get_plugin_setting("groupdomain", "beechat")) {
			register_elgg_event_handler('create', 'group', 'beechat_create_group');
			register_elgg_event_handler('delete', 'group', 'beechat_delete_group');
		}
		register_elgg_event_handler('create', 'member', 'beechat_member_add');
		register_elgg_event_handler('delete', 'relationship', 'beechat_member_delete');*/


		$actions_path = $pluginspath . 'beechat/actions/';
		//elgg_register_action('beechat/join_groupchat', $actions_path . 'join_groupchat.php');
		//elgg_register_action('beechat/leave_groupchat', $actions_path . 'leave_groupchat.php');
		elgg_register_action('beechat/get_statuses', $actions_path . 'get_statuses.php');
		elgg_register_action('beechat/get_icons', $actions_path . 'get_icons.php');
		elgg_register_action('beechat/get_details', $actions_path . 'get_details.php');
		elgg_register_action('beechat/get_connection', $actions_path . 'get_connection.php');
		elgg_register_action('beechat/get_state', $actions_path . 'get_state.php');
		elgg_register_action('beechat/save_state', $actions_path . 'save_state.php');

		/*register_elgg_event_handler('create', 'friendrequest', 'beechat_xmpp_add_friendx');
		#register_plugin_hook('action', 'friends/add', 'beechat_xmpp_add_friend', 1000);
		register_plugin_hook('river_update', 'river_update', 'beechat_xmpp_approve_friendx');
		register_plugin_hook('river_update_foreign', 'river_update', 'beechat_xmpp_approve_friendx');
		#register_plugin_hook('action', 'friendrequest/approve', 'beechat_xmpp_approve_friend', 1000);


		register_plugin_hook('action', 'friendrequest/decline', 'beechat_xmpp_decline_friend', 1000);
		register_plugin_hook('action', 'friends/remove', 'beechat_xmpp_remove_friend', 1000);*/

		// new friend sync
		elgg_register_event_handler('delete', 'friend', array('BeechatSync', 'onFriendDelete'));
	        //elgg_register_event_handler('create', 'friendrequest', array('BeechatSync', 'onFriendCreate'));
        	elgg_register_event_handler('delete', 'friendrequest', array('BeechatSync', 'onFriendDelete'));


	
		elgg_extend_view('js/initialise_elgg', 'js/json2.js');
		elgg_extend_view('js/initialise_elgg', 'js/jquery.cookie.min.js');
		elgg_extend_view('js/initialise_elgg', 'js/jquery.scrollTo-min.js');
		elgg_extend_view('js/initialise_elgg', 'js/jquery.serialScroll-min.js');
		elgg_extend_view('js/initialise_elgg', 'js/b64.js');
		elgg_extend_view('js/initialise_elgg', 'js/sha1.js');
		elgg_extend_view('js/initialise_elgg', 'js/md5.js');
		elgg_extend_view('js/initialise_elgg', 'js/strophe.min.js');
		elgg_extend_view('js/initialise_elgg', 'js/strophe.muc.js');
		elgg_extend_view('js/initialise_elgg', 'js/jquery.tools.min.js');
		elgg_extend_view('css', 'beechat/screen.css');
		elgg_extend_view('js/initialise_elgg', 'beechat/beechat.js');
		elgg_extend_view('page/elements/head', 'beechat/beechat.userjs');
		
		elgg_extend_view('page/elements/foot', 'beechat/beechat');

		$domain = elgg_get_plugin_setting("domain", "beechat");
		//$group_domain = elgg_get_plugin_setting("groupdomain", "beechat");
		/*$dbname = elgg_get_plugin_setting("dbname", "beechat");
		$dbhost = elgg_get_plugin_setting("dbhost", "beechat");
		$dbuser = elgg_get_plugin_setting("dbuser", "beechat");
		$dbpassword = elgg_get_plugin_setting("dbpassword", "beechat");*/

		global $CONFIG;
		$CONFIG->chatsettings['domain'] = $domain;
		//$CONFIG->chatsettings['groupdomain'] = $group_domain;

		register_notification_handler('xmpp', 'beechat_notifications');
	//	register_plugin_hook('notify:entity:message','object','beechat_notifications_msg');
	}

	function beechat_notifications($from, $to, $subject, $topic, $params = array()) {
		ejabberd_send_chat($to, "<div>".$topic."</div>");
	}


	function beechat_friendly_title($title) {
		// need this because otherwise seems elgg
		// gets in some problem trying to call the view
		//$title = iconv('UTF-8', 'ASCII//TRANSLIT', $title);
		$title = preg_replace("/[^\w ]/","",$title);
		$title = str_replace(" ","-",$title);
		$title = str_replace("--","-",$title);
		$title = trim($title);
		$title = strtolower($title);
		return $title;
	}

	function beechat_pagesetup()
	{
		global $CONFIG;
		/*if (elgg_get_context() == 'group_profile' && elgg_is_logged_in()) {
			if (elgg_get_plugin_setting("groupdomain", "beechat")) {
				$user = elgg_get_logged_in_user_entity();
				$group = elgg_get_page_owner_entity();
				if (!$group || !($group instanceof ElggGroup))
					return;
				if ($user->chatenabled && elgg_get_plugin_setting("groupdomain", "beechat")) {
					if ($group->isPublicMembership() || $group->isMember($user)) {
						$item = new ElggMenuItem('chatroom', elgg_echo('beechat:chatroom'), "javascript:g_beechat_user.joinRoom('".beechat_friendly_title($group->name)."@".$CONFIG->chatsettings['groupdomain']."', '".$group->guid."')");
						elgg_register_menu_item('page', 'item');
					}
				}
			}
		}
		else*/if (elgg_get_context() == 'settings' && elgg_is_logged_in()) {
			$is_enabled = elgg_get_logged_in_user_entity()->chatenabled;
			$action = $is_enabled ? 'disable' : 'enable';
			elgg_register_menu_item('page', array(
				'name' => 'beechat',
				'text'=> elgg_echo("beechat:{$action}chat"),
				'href' => $CONFIG->wwwroot . "mod/beechat/{$action}chat.php",
			));
		}
	}


	function ejabberd_send_chat($user, $body) { // $user adds $friend
		$from = 'notify@'.elgg_get_plugin_setting("domain", "beechat").'/net';
		if ($user->alias) {
			
		}
		elgg_load_library('elgg:beechat');
		$to = ejabberd_getjid($user, true);
                //xmlrpc_set_type(&$body, "base64"); 
		$param = array("body" => $body,
				"from" => $from,
				"to" => $to);
		ejabberd_xmlrpc_command('send_html_message', $param);
	}




elgg_register_event_handler('init', 'system', 'beechat_init');