[903] | 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 | $this->jabber->username = $_SESSION['phpgw_info']['jabberit_messenger']['user']; |
---|
| 25 | $this->jabber->password = $_SESSION['phpgw_info']['jabberit_messenger']['passwd']; |
---|
| 26 | $this->jabber->server = $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit']; |
---|
| 27 | $this->jabber->resource = "JABADD"; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | private final function connect() |
---|
| 31 | { |
---|
| 32 | if(!$this->jabber->Connect()) |
---|
| 33 | { |
---|
| 34 | $this->error = "No Connect"; |
---|
| 35 | return false; |
---|
| 36 | } |
---|
| 37 | if(!$this->jabber->SendAuth()) |
---|
| 38 | { |
---|
| 39 | $this->error = "No Auth"; |
---|
| 40 | return false; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | return true; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | private final function disconnect() |
---|
| 47 | { |
---|
| 48 | |
---|
| 49 | $this->jabber->Disconnect(); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | public final function AddNewContact($pNewUser) |
---|
| 53 | { |
---|
| 54 | $this->connect(); |
---|
| 55 | $jid = $pNewUser['uid']."@". $this->jabber->server; |
---|
| 56 | $id = 'add_user'.time(); |
---|
| 57 | $name = $pNewUser['name']; |
---|
| 58 | $group = $pNewUser['group']; |
---|
| 59 | |
---|
| 60 | if($this->jabber->RosterAddUser($jid,$id,$name,$group)) |
---|
| 61 | { |
---|
| 62 | $_SESSION['phpgw_info']['jabberit_messenger']['groups_user'][] = $group; |
---|
| 63 | $_SESSION['phpgw_info']['jabberit_messenger']['groups_user'] = array_unique($_SESSION['phpgw_info']['jabberit_messenger']['groups_user']); |
---|
| 64 | |
---|
| 65 | if($this->jabber->Subscribe($jid)) |
---|
| 66 | return true; |
---|
| 67 | } |
---|
| 68 | else |
---|
| 69 | { |
---|
| 70 | return false; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | $this->disconnect(); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | public final function getGroupsJabber() |
---|
| 77 | { |
---|
| 78 | $groups = array(); |
---|
| 79 | $return = ''; |
---|
| 80 | |
---|
| 81 | if(!isset($_SESSION['phpgw_info']['jabberit_messenger']['groups_user'])) |
---|
| 82 | { |
---|
| 83 | $this->connect(); |
---|
| 84 | $groups = $this->jabber->RosterGroups(); |
---|
| 85 | $this->disconnect(); |
---|
| 86 | |
---|
| 87 | $groups = array_unique($groups); |
---|
| 88 | $_SESSION['phpgw_info']['jabberit_messenger']['groups_user'] = $groups; |
---|
| 89 | |
---|
| 90 | }else |
---|
| 91 | $groups = $_SESSION['phpgw_info']['jabberit_messenger']['groups_user']; |
---|
| 92 | |
---|
| 93 | natcasesort($groups); |
---|
| 94 | |
---|
| 95 | foreach($groups as $tmp) |
---|
| 96 | $return .= $tmp . ";"; |
---|
| 97 | |
---|
| 98 | if( trim($return) != '' ) |
---|
| 99 | $return = substr( $return, 0, strlen($return)-1 ); |
---|
| 100 | |
---|
| 101 | return $return; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | ?> |
---|