noobIOSCoder / xmpphp

Automatically exported from code.google.com/p/xmpphp
0 stars 0 forks source link

My add-ons for xmpp.php #56

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
    /**
    * Retrieves JID stats (XEP-0039)
    * 
    */

    public function getSstats($address) {
        $id = $this->getID();
        $this->addIdHandler($id, 'sstats_get_handler');

        $to = htmlspecialchars($address);
        $type = 'get';
        $out = "<iq to='$to' id='$id' type='$type'>"
          ."<query xmlns=\"http://jabber.org/protocol/stats\">"
          ."<stat name=\"time/uptime\" />"
          ."<stat name=\"users/online\" />"
          ."<stat name=\"users/total\" />"
          ."<stat name=\"bandwidth/packets-in\" />"
          ."<stat name=\"bandwidth/packets-out\" />"
          ."</query>"
          ."</iq>";
        $this->send($out);
    }

    protected function sstats_get_handler($xml) {
        $sstats_array = array();

        $sstats = $xml->sub('query');

        $c = 0;
        foreach ($sstats->subs as $sub)
        {
            //echo $sub->attr['name'].$sub->attrs['value'].$sub->attrs['units']."\n";
            $sstats_array[$c]['name'] = $sub->attrs['name'];
            $sstats_array[$c]['value'] =
($sub->attrs['value'])?($sub->attrs['value']):("0");
            $sstats_array[$c]['units'] = $sub->attrs['units'];
            $c++;
        }

        $this->event('sstats', $sstats_array);
    }

    /**
    * Retrieves JID's software(and stuff) version (XEP-0092)
    *
    */

    public function getSversion($address) {
        $id = $this->getID();
        $this->addIdHandler($id, 'sversion_get_handler');

        $to = htmlspecialchars($address);
        $type = 'get';
        $out = "<iq to='$address' id='$id' type='$type'>"
          ."<query xmlns='jabber:iq:version'/>"
          ."</iq>";
        $this->send($out);
    }

    protected function sversion_get_handler($xml) {
        $sversion_array = array();

        $sversion = $xml->sub('query');

        $sversion_array['software'] = $sversion->subs[0]->data;
        $sversion_array['version'] = $sversion->subs[1]->data;
        $sversion_array['os'] = $sversion->subs[2]->data;

        $this->event('sversion', $sversion_array);
    }

    /**
    * Retrieves Disco Features (XEP-0030)
    *
    */

    public function getSfeatures($address) {
        $id = $this->getID();
        $this->addIdHandler($id, 'sfeatures_get_handler');

        $to = htmlspecialchars($address);
        $type = 'get';
        $out = "<iq to='$address' id='$id' type='$type'>"
          ."<query xmlns='http://jabber.org/protocol/disco#info'/>"
          ."</iq>";
        $this->send($out);
    }

    protected function sfeatures_get_handler($xml) {
        $sfeatures_array = array();

        $sfeatures = $xml->sub('query');

        $stfe = $sfeatures->subs;
        foreach($stfe as $st)
        {
            if($st->name == "feature") 
            {
            $sfeatures_array[] = $st->attrs['var'];
            }
        }

        $this->event('sfeatures', $sfeatures_array);
    }

Original issue reported on code.google.com by xdersd on 16 Jun 2009 at 3:08