Working version of project
This commit is contained in:
parent
0b21896cd5
commit
5411c00ee9
9 changed files with 259 additions and 46 deletions
70
classes/xmpp.php
Normal file
70
classes/xmpp.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
namespace Classes;
|
||||
|
||||
use Norgul\Xmpp\Options;
|
||||
use Norgul\Xmpp\XmppClient;
|
||||
|
||||
class Xmpp extends Core{
|
||||
private $xmpp_options;
|
||||
private $xmpp_client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->xmpp_options = new Options();
|
||||
}
|
||||
|
||||
public function start()
|
||||
{
|
||||
$this->xmpp_options->setHost($this->config->xmpp_server);
|
||||
$this->xmpp_options->setUseTls($this->config->xmpp_tls);
|
||||
$this->xmpp_options->setUsername($this->config->xmpp_username);
|
||||
$this->xmpp_options->setPassword($this->config->xmpp_password);
|
||||
$this->xmpp_client = new XmppClient($this->xmpp_options);
|
||||
}
|
||||
|
||||
public function connect()
|
||||
{
|
||||
$this->xmpp_client->connect();
|
||||
}
|
||||
|
||||
public function sendMessage(string $text)
|
||||
{
|
||||
foreach($this->config->xmpp_recipients as $receipient)
|
||||
{
|
||||
$type = $this->getChatType($receipient['type']);
|
||||
|
||||
if($type === "groupchat") {
|
||||
$this->xmpp_client->send("<presence from='".$this->xmpp_options->bareJid()."/".$this->xmpp_options->getResource()."' to='".$receipient["jid"] . "/" . $receipient["muc_nickname"]. "'><x xmlns='http://jabber.org/protocol/muc'/></presence>");
|
||||
}
|
||||
|
||||
$this->xmpp_client->message->send($text,$receipient['jid'],$type);
|
||||
}
|
||||
}
|
||||
|
||||
private function getChatType(int $type)
|
||||
{
|
||||
if($type === 1)
|
||||
{
|
||||
$return_type = "chat";
|
||||
}
|
||||
elseif($type === 2)
|
||||
{
|
||||
$return_type = "groupchat";
|
||||
}
|
||||
else
|
||||
{
|
||||
$return_type = "chat";
|
||||
}
|
||||
|
||||
return $return_type;
|
||||
}
|
||||
|
||||
public function disconnect()
|
||||
{
|
||||
$this->xmpp_client->disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue