missus


A PHP class providing a simple API for connecting to an XMPP server.

EDIT [12/18/11] : I do not plan on updating Missus. Actually my programming skills have a bit evolved since I wrote this, and I can't say I'm very proud of how I tried to implement the XMPP protocol here. Plus, PHP is an absolutely terrible language when it comes to real-time communication (some would say it's an absolutely terrible language, period :)) This was a fun project to learn how XMPP works but I don't feel like I should have released it publicly. I know it's been useful to some people, though.

Missus is a PHP class that provides a simple API enabling you to connect to an XMPP server and interact with it. It supports most xmpp servers (including facebook and google talk) and is released under the terms of the LGPL license.

Please note that it still is at an early stage of developpement and may be quite boggus

Feel free to report an issue/contact me or if you ever want to contribute (or if you see spelling/grammar errors as english is not my mother tongue :).

Download

You can download the project from the svn repository : svn checkout https://missus.googlecode.com/svn/trunk/ missus

Some examples

Basic example

```

$bot = new Missus('user', 'pass', 'gmail.com', 'talk.google.com');

$bot = new Missus('user', 'pass', 'chat.facebook.com');

$bot = new Missus('user', 'pass', 'whatever.com');

$bot->logEvents(true);
$bot->connect();
$contacts = $bot->getRoster();

} catch(Exception $e) { die($e->getMessage()); }

?>

Chat contacts :

```

This basic example will log the user into an xmpp server, gets its roster and output all of the contacts it countains. It's pretty simple to understand; if something remains unclear please have a look at the documentation (it comes with the class - check the downloads section). Change the user credentials and run it in your browser, it should output something like this.

Creating an XMPP bot

This can easily be done in a few line of codes, by extending the class and overriding some of Missus default methods, such as onConnect() and onReceivedContent(). ```

!/usr/bin/php

showPresence(); echo "\n-- \o/ Hello ! --\n"; } protected function onReceivedContent() { echo sprintf("\n-- I received this, tell me how to deal with it : \n%s --\n", $this->received); } } try { $bot = new XMPPBot('denis', 'foo', 'localhost'); $bot->logEvents()->setPersistent()->connect(); } catch(Exception $e) { die($e->getMessage()); } ?> ``` This one's aimed to be launched via php command line interface. Via the setPersistent() method, we turn our Missus XMPP client into a bot that remain active after it has been launched. This means it won't disconnect, and will execute onReceivedContent() on every new content sent by the server (as well as onConnect() upon login).

An exemple of customs actions you can define : ``` protected function onReceivedContent() {

$xml = $this->load_xml_string($this->received);
if(!$xml) return; # if couldn't parse anything

# get subscription requests and subscribe back
$subscription_requests_from = $xml->xpath("//presence[@type='subscribe']/@from");
if($subscription_requests_from) foreach($subscription_requests_from as $from) $this->subscribeBack($from);

}

protected function onReceivedMessage($body, $from, $type, $xml) { echo $from .' sent me these kind words : ' . $body . "\n"; }

protected function onUserComposing($from) { echo $from . ' is composing' . "\n"; }

protected function onUserPaused($from) { echo $from . ' stopped composing' . "\n"; } ```

More events hooks are planned for a future version. If you want Missus to support more XEP, just extends it and define its behavior in the onReceivedContent() method.

I also plan to add BOSH support soon. For now that's it, enjoy !

For any question, contact me by mail. You'll find my public PGP Key here.

Project Information

Labels:
xmpp php