1 | <?php |
---|
2 | /***************************************************************************\ |
---|
3 | * Expresso - Expresso Messenger * |
---|
4 | * - Alexandre Correia / Rodrigo Souza * |
---|
5 | * - JETI - http://jeti-im.org/ * |
---|
6 | * ------------------------------------------------------------------------- * |
---|
7 | * This program is free software; you can redistribute it and/or modify it * |
---|
8 | * under the terms of the GNU General Public License as published by the * |
---|
9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
10 | * option) any later version. * |
---|
11 | \***************************************************************************/ |
---|
12 | |
---|
13 | require_once "class.jabber.inc.php"; |
---|
14 | |
---|
15 | class ujabber |
---|
16 | { |
---|
17 | private $jabber; |
---|
18 | private $error; |
---|
19 | |
---|
20 | function __construct() |
---|
21 | { |
---|
22 | |
---|
23 | $this->jabber = new Jabber(); |
---|
24 | |
---|
25 | $organization = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['attributes_org_ldap_jabberit']); |
---|
26 | $organization_user = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn']; |
---|
27 | $organization_user = substr($organization_user, strpos($organization_user,"ou=") + 3 , strlen($organization_user)); |
---|
28 | $organization_user = substr($organization_user, 0, strpos($organization_user, ",")); |
---|
29 | |
---|
30 | // Default para autenticação é o UID; |
---|
31 | $uid = $_SESSION['phpgw_info']['jabberit_messenger']['user']; |
---|
32 | |
---|
33 | if(is_array($organization)) |
---|
34 | { |
---|
35 | foreach($organization as $attr) |
---|
36 | { |
---|
37 | $tmp = explode(";",$attr); |
---|
38 | if( strtolower(trim($tmp[0])) == strtolower(trim($organization_user))) |
---|
39 | { |
---|
40 | switch(strtolower(trim($tmp[1]))) |
---|
41 | { |
---|
42 | case "mail" : |
---|
43 | $uid = $_SESSION['phpgw_info']['jabberit_messenger']['mail']; |
---|
44 | $uid = substr($uid,0,strpos($uid,"@")); |
---|
45 | break; |
---|
46 | |
---|
47 | case "description" : |
---|
48 | // SERPRO |
---|
49 | // parte antes do arroba; |
---|
50 | // Informe aqui a parte da sessão correspondente; |
---|
51 | $uid = "description"; |
---|
52 | break; |
---|
53 | } |
---|
54 | } |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | $this->jabber->username = $uid; |
---|
59 | $this->jabber->password = $_SESSION['phpgw_info']['jabberit_messenger']['passwd']; |
---|
60 | $this->jabber->server = $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit']; |
---|
61 | $this->jabber->resource = "JABADD"; |
---|
62 | } |
---|
63 | |
---|
64 | private final function connect() |
---|
65 | { |
---|
66 | if(!$this->jabber->Connect()) |
---|
67 | { |
---|
68 | $this->error = "No Connect"; |
---|
69 | return false; |
---|
70 | } |
---|
71 | if(!$this->jabber->SendAuth()) |
---|
72 | { |
---|
73 | $this->error = "No Auth"; |
---|
74 | return false; |
---|
75 | } |
---|
76 | |
---|
77 | return true; |
---|
78 | } |
---|
79 | |
---|
80 | private final function disconnect() |
---|
81 | { |
---|
82 | |
---|
83 | $this->jabber->Disconnect(); |
---|
84 | } |
---|
85 | |
---|
86 | public final function AddNewContact($pNewUser) |
---|
87 | { |
---|
88 | $this->connect(); |
---|
89 | $jid = $pNewUser['uid']."@". $this->jabber->server; |
---|
90 | $id = 'add_user'.time(); |
---|
91 | $name = $pNewUser['name']; |
---|
92 | $group = $pNewUser['group']; |
---|
93 | |
---|
94 | if($this->jabber->RosterAddUser($jid,$id,$name,$group)) |
---|
95 | { |
---|
96 | $_SESSION['phpgw_info']['jabberit_messenger']['groups_user'][] = $group; |
---|
97 | $_SESSION['phpgw_info']['jabberit_messenger']['groups_user'] = array_unique($_SESSION['phpgw_info']['jabberit_messenger']['groups_user']); |
---|
98 | |
---|
99 | if($this->jabber->Subscribe($jid)) |
---|
100 | { |
---|
101 | $this->disconnect(); |
---|
102 | return true; |
---|
103 | } |
---|
104 | } |
---|
105 | else |
---|
106 | { |
---|
107 | $this->disconnect(); |
---|
108 | return false; |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | } |
---|
113 | |
---|
114 | public final function getGroupsJabber() |
---|
115 | { |
---|
116 | $groups = array(); |
---|
117 | $return = ''; |
---|
118 | |
---|
119 | if(!isset($_SESSION['phpgw_info']['jabberit_messenger']['groups_user'])) |
---|
120 | { |
---|
121 | $this->connect(); |
---|
122 | $groups = $this->jabber->RosterGroups(); |
---|
123 | $this->disconnect(); |
---|
124 | |
---|
125 | $groups = array_unique($groups); |
---|
126 | $_SESSION['phpgw_info']['jabberit_messenger']['groups_user'] = $groups; |
---|
127 | |
---|
128 | }else |
---|
129 | $groups = $_SESSION['phpgw_info']['jabberit_messenger']['groups_user']; |
---|
130 | |
---|
131 | natcasesort($groups); |
---|
132 | |
---|
133 | foreach($groups as $tmp) |
---|
134 | $return .= $tmp . ";"; |
---|
135 | |
---|
136 | if( trim($return) != '' ) |
---|
137 | $return = substr( $return, 0, strlen($return)-1 ); |
---|
138 | |
---|
139 | return $return; |
---|
140 | } |
---|
141 | } |
---|
142 | ?> |
---|