+ protected function roster_iq_handler($xml) {
+ $status = "result";
+ $xmlroster = $xml->sub('query');
+ foreach($xmlroster->subs as $item) {
+ $groups = array();
+ if ($item->name == 'item') {
+ $jid = $item->attrs['jid']; //REQUIRED
+ $name = $item->attrs['name']; //MAY
+ $subscription = $item->attrs['subscription'];
+ foreach($item->subs as $subitem) {
+ if ($subitem->name == 'group') {
+ $groups[] = $subitem->data;
+ }
+ }
+ $contacts[] = array($jid, $subscription, $name, $groups); //Store for action if no errors happen
+ } else {
+ $status = "error";
+ }
+ }
+ if ($status == "result") { //No errors, add contacts
+ foreach($contacts as $contact) {
+ $this->roster->addContact($contact[0], $contact[1], $contact[2], $contact[3]);
+ }
+ }
+ if ($xml->attrs['type'] == 'set') {
+ $this->send("<iq type=\"reply\" id=\"{$xml->attrs['id']}\" to=\"{$xml->attrs['from']}\" />");
+ }