예제 #1
0
 function jid_exists($jid)
 {
     foreach ($this->nicks as $nick => $data) {
         //	    debugmsg("$nick ('$jid' == '".$data['jid']."')\n");
         if (xmpp_compare_jid($data['jid'], $jid)) {
             return $nick;
         }
     }
     return false;
 }
예제 #2
0
function xmpp_presence_to_all($nick, $room, $forcenick = '', $type = '', $options = array())
{
    global $ircdata, $xmppparams;
    $result = '';
    //    if ($nick) {
    if (!($jid = to_utf($ircdata->nicks[from_utf($nick)]['jid']))) {
        $jid = $nick . '@' . $xmppparams['componentname'] . '/irc';
    }
    //    } else $jid = $forcenick;
    xmpp_normalize_room($room);
    $addstatus = array();
    $newobj = new CXMLTag('presence', array('from' => $room . '@' . $xmppparams['componentname'] . ($nick ? '/' . $nick : '')));
    if ($type) {
        $newobj->attribs['type'] = $type;
    }
    $xtag = new CXMLTag('x', array('xmlns' => FEAT_MUC . '#user'));
    $affiliation = 'none';
    switch ($type) {
        case 'unavailable':
            $role = 'none';
            break;
        case 'newmode':
            $role = xmpp_get_role($nick, $room);
            unset($newobj->attribs['type']);
            break;
        case 'newnick':
            $newobj->attribs['type'] = 'unavailable';
            $addstatus[] = '303';
            $role = xmpp_get_role($nick, $room);
            break;
        case 'role':
            $role = $options['role'];
            unset($newobj->attribs['type']);
            break;
        case 'kick':
            $newobj->attribs['type'] = 'unavailable';
            $addstatus[] = '307';
            $role = 'none';
            $actorjid = xmpp_bare_jid(to_utf($ircdata->nicks[from_utf($options['actor'])]['jid']));
            if (!$actorjid) {
                $actorjid = $options['actor'] . '@' . $xmppparams['componentname'];
            }
            break;
        case 'ban':
            $newobj->attribs['type'] = 'unavailable';
            $addstatus[] = '301';
            $role = 'none';
            $affiliation = 'outcast';
            $actorjid = xmpp_bare_jid(to_utf($ircdata->nicks[from_utf($options['actor'])]['jid']));
            if (!$actorjid) {
                $actorjid = $options['actor'] . '@' . $xmppparams['componentname'];
            }
            break;
        default:
            $role = xmpp_get_role($nick, $room);
            if ($forcenick) {
                $newobj->attribs['from'] = $room . '@' . $xmppparams['componentname'] . '/' . $forcenick;
            }
    }
    foreach ($ircdata->channels[from_utf($room)]['nicks'] as $ircnick => $data) {
        // Skip non-jabber users
        if (!$ircdata->nicks[$ircnick]['jid']) {
            continue;
        }
        $newobj->attribs['to'] = to_utf($ircdata->nicks[$ircnick]['jid']);
        $itemtag = new CXMLTag('item', array('affiliation' => $affiliation, 'jid' => $jid, 'role' => $role));
        if ($type == 'newnick') {
            $itemtag->attribs['nick'] = $forcenick;
        }
        //	if (($type != 'ban') && isset($options['reason'])) $itemtag->subtags[] = new CXMLTag('reason',array(),$options['reason']);
        //	if (($type != 'ban') && isset($options['actor'])) $itemtag->subtags[] = new CXMLTag('actor',array('jid'=>$actorjid));
        $xtag->subtags = array($itemtag);
        if (xmpp_compare_jid($jid, $newobj->attribs['to'])) {
            $xtag->subtags[] = new CXMLTag('status', array('code' => '110'));
            if (!$type) {
                $xtag->subtags[] = new CXMLTag('status', array('code' => '100'));
            }
            if ($forcenick && !$type) {
                $xtag->subtags[] = new CXMLTag('status', array('code' => '210'));
            }
            //	    if (in_array('307',$addstatus) &&
            //	    if (($type = 'ban') && isset($options['reason'])) $itemtag->subtags[] = new CXMLTag('reason',array(),$options['reason']);
            //	    if (($type = 'ban') && isset($options['actor'])) $itemtag->subtags[] = new CXMLTag('actor',array('jid'=>$actorjid));
        }
        if (isset($options['reason'])) {
            $itemtag->subtags[] = new CXMLTag('reason', array(), $options['reason']);
        }
        if (isset($options['actor'])) {
            $itemtag->subtags[] = new CXMLTag('actor', array('jid' => $actorjid));
        }
        foreach ($addstatus as $status) {
            $xtag->subtags[] = new CXMLTag('status', array('code' => $status));
        }
        $newobj->subtags = array($xtag);
        if (isset($options['status'])) {
            $newobj->subtags[] = new CXMLTag('status', array(), $options['status']);
        }
        $result .= $newobj->toString();
        //."\n\n";
    }
    return $result;
}