4 * Description: Embedded XMPP (Jabber) client
6 * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
9 function xmpp_install() {
10 register_hook('page_end', 'addon/xmpp/xmpp.php', 'xmpp_script');
11 register_hook('logged_in', 'addon/xmpp/xmpp.php', 'xmpp_login');
14 function xmpp_uninstall() {
15 unregister_hook('page_end', 'addon/xmpp/xmpp.php', 'xmpp_script');
16 unregister_hook('logged_in', 'addon/xmpp/xmpp.php', 'xmpp_login');
19 function xmpp_login($a,$b) {
20 if (!$_SESSION["allow_api"]) {
21 $password = substr(random_string(),0,16);
22 set_pconfig(local_user(), "xmpp", "password", $password);
26 function xmpp_plugin_admin(&$a, &$o){
27 $t = get_markup_template("admin.tpl", "addon/xmpp/");
29 $o = replace_macros($t, array(
30 '$submit' => t('Save Settings'),
31 '$bosh_proxy' => array('bosh_proxy', t('BOSH proxy'), get_config('xmpp', 'bosh_proxy'), ''),
32 '$central_userbase' => array('central_userbase', t('Use central userbase'), get_config('xmpp', 'central_userbase'), t('If enabled, users will automatically login to an ejabberd server that has to be installed on this machine with synchronized credentials via the "auth_ejabberd.php" script.')),
36 function xmpp_plugin_admin_post(&$a){
37 $bosh_proxy = ((x($_POST,'bosh_proxy')) ? trim($_POST['bosh_proxy']) : '');
38 $central_userbase = ((x($_POST,'central_userbase')) ? intval($_POST['central_userbase']) : false);
39 set_config('xmpp','bosh_proxy',$bosh_proxy);
40 set_config('xmpp','central_userbase',$central_userbase);
41 info( t('Settings updated.'). EOL );
44 function xmpp_script(&$a,&$s) {
49 function xmpp_converse(&$a,&$s) {
53 if ($_GET["mode"] == "minimal")
56 if ($a->is_mobile || $a->is_tablet)
59 $a->page['htmlhead'] .= '<link type="text/css" rel="stylesheet" media="screen" href="addon/xmpp/converse/css/converse.css" />'."\n";
60 $a->page['htmlhead'] .= '<script src="addon/xmpp/converse/builds/converse.min.js"></script>'."\n";
62 $bosh_proxy = get_config("xmpp", "bosh_proxy");
64 if (get_config("xmpp", "central_userbase")) {
65 $password = get_pconfig(local_user(), "xmpp", "password");
67 if ($password == "") {
68 $password = substr(random_string(),0,16);
69 set_pconfig(local_user(), "xmpp", "password", $password);
72 $jid = $a->user["nickname"]."@".$a->get_hostname()."/converse-".substr(random_string(),0,5);;
74 $auto_login = "auto_login: true,
75 authentication: 'login',
77 password: '$password',
79 auto_list_rooms: true,";
83 if (in_array($a->argv[0], array("manage", "logout")))
84 $additional_commands = "converse.user.logout();\n";
86 $additional_commands = "";
89 //$on_ready = "converse.rooms.open(['support@conference.pirati.ca']);\n";
91 // converse.contacts.add('ike@jabber.piratenpartei.de');
93 $initialize = "converse.initialize({
94 bosh_service_url: '$bosh_proxy',
96 message_carbons: false,
97 forward_messages: false,
99 sounds_path: 'addon/xmpp/converse/sounds/',
100 roster_groups: false,
101 show_controlbox_by_default: false,
103 allow_contact_removal: false,
104 allow_registration: false,
105 hide_offline_users: true,
106 allow_chat_pending_contacts: false,
107 allow_dragresize: true,
110 csi_waiting_time: 300,
111 auto_reconnect: true,
113 xhr_user_search: false
116 $a->page['htmlhead'] .= "<script>
117 require(['converse'], function (converse) {
119 converse.listen.on('ready', function (event) {
127 function xmpp_jappix(&$a,&$s) {
131 if ($_GET["mode"] == "minimal")
134 $bosh_proxy = get_config("xmpp", "bosh_proxy");
136 if (get_config("xmpp", "central_userbase")) {
137 $password = get_pconfig(local_user(), "xmpp", "password");
139 if ($password == "") {
140 $password = substr(random_string(),0,16);
141 set_pconfig(local_user(), "xmpp", "password", $password);
144 $user = $a->user["nickname"];
145 $domain = $a->get_hostname();
147 $auto_login = "auto_login: true,
148 authentication: 'login',
150 password: '$password',
151 allow_logout: false,";
155 //$a->page['htmlhead'] .= "<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>";
157 $a->page['htmlhead'] .= "<script type='text/javascript' src='addon/xmpp/jappix/javascripts/mini.js'></script>
158 <script type='text/javascript'>
159 jQuery(document).ready(function() {
160 JAPPIX_STATIC = 'addon/xmpp/jappix/';
161 HOST_BOSH = '$bosh_proxy'
166 password: '$password',