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 $a->page['htmlhead'] .= '<link type="text/css" rel="stylesheet" media="screen" href="addon/xmpp/converse/css/converse.css" />'."\n";
57 $a->page['htmlhead'] .= '<script src="addon/xmpp/converse/builds/converse.min.js"></script>'."\n";
59 $bosh_proxy = get_config("xmpp", "bosh_proxy");
61 if (get_config("xmpp", "central_userbase")) {
62 $password = get_pconfig(local_user(), "xmpp", "password");
64 if ($password == "") {
65 $password = substr(random_string(),0,16);
66 set_pconfig(local_user(), "xmpp", "password", $password);
69 $jid = $a->user["nickname"]."@".$a->get_hostname()."/converse-".substr(random_string(),0,5);;
71 $auto_login = "auto_login: true,
72 authentication: 'login',
74 password: '$password',
76 auto_list_rooms: true,";
80 if (in_array($a->argv[0], array("manage", "logout")))
81 $additional_commands = "converse.user.logout();\n";
83 $additional_commands = "";
86 //$on_ready = "converse.rooms.open(['support@conference.pirati.ca']);\n";
88 // converse.contacts.add('ike@jabber.piratenpartei.de');
90 $initialize = "converse.initialize({
91 bosh_service_url: '$bosh_proxy',
93 message_carbons: false,
94 forward_messages: false,
96 sounds_path: 'addon/xmpp/converse/sounds/',
98 show_controlbox_by_default: false,
100 allow_contact_removal: false,
101 allow_registration: false,
102 hide_offline_users: true,
103 allow_chat_pending_contacts: false,
104 allow_dragresize: true,
107 csi_waiting_time: 300,
108 auto_reconnect: true,
110 xhr_user_search: false
113 $a->page['htmlhead'] .= "<script>
114 require(['converse'], function (converse) {
116 converse.listen.on('ready', function (event) {
124 function xmpp_jappix(&$a,&$s) {
128 if ($_GET["mode"] == "minimal")
131 $bosh_proxy = get_config("xmpp", "bosh_proxy");
133 if (get_config("xmpp", "central_userbase")) {
134 $password = get_pconfig(local_user(), "xmpp", "password");
136 if ($password == "") {
137 $password = substr(random_string(),0,16);
138 set_pconfig(local_user(), "xmpp", "password", $password);
141 $user = $a->user["nickname"];
142 $domain = $a->get_hostname();
144 $auto_login = "auto_login: true,
145 authentication: 'login',
147 password: '$password',
148 allow_logout: false,";
152 //$a->page['htmlhead'] .= "<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>";
154 $a->page['htmlhead'] .= "<script type='text/javascript' src='addon/xmpp/jappix/javascripts/mini.js'></script>
155 <script type='text/javascript'>
156 jQuery(document).ready(function() {
157 JAPPIX_STATIC = 'addon/xmpp/jappix/';
158 HOST_BOSH = '$bosh_proxy'
163 password: '$password',