2015-08-03 11:35:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modl;
|
|
|
|
|
|
|
|
class Presence extends Model {
|
|
|
|
protected $id;
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
protected $session;
|
|
|
|
protected $jid;
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
// General presence informations
|
|
|
|
protected $resource;
|
|
|
|
protected $value;
|
|
|
|
protected $priority;
|
|
|
|
protected $status;
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
// Client Informations
|
|
|
|
protected $node;
|
|
|
|
protected $ver;
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
// Delay - XEP 0203
|
|
|
|
protected $delay;
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
// Last Activity - XEP 0256
|
|
|
|
protected $last;
|
|
|
|
|
|
|
|
// Current Jabber OpenPGP Usage - XEP-0027
|
|
|
|
protected $publickey;
|
|
|
|
protected $muc;
|
|
|
|
protected $mucjid;
|
|
|
|
protected $mucaffiliation;
|
|
|
|
protected $mucrole;
|
|
|
|
|
|
|
|
// vcard-temp:x:update, not saved in the DB
|
|
|
|
public $photo = false;
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
public function __construct() {
|
|
|
|
$this->_struct = '
|
|
|
|
{
|
2015-09-10 15:41:45 +02:00
|
|
|
"id" :
|
2016-02-25 11:28:01 +01:00
|
|
|
{"type":"string", "size":64, "mandatory":true },
|
2015-09-10 15:41:45 +02:00
|
|
|
"session" :
|
2016-02-25 11:28:01 +01:00
|
|
|
{"type":"string", "size":64, "key":true },
|
2015-09-10 15:41:45 +02:00
|
|
|
"jid" :
|
2016-02-25 11:28:01 +01:00
|
|
|
{"type":"string", "size":64, "key":true },
|
2015-09-10 15:41:45 +02:00
|
|
|
"resource" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"string", "size":64, "key":true },
|
2015-09-10 15:41:45 +02:00
|
|
|
"value" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"int", "size":11, "mandatory":true },
|
2015-09-10 15:41:45 +02:00
|
|
|
"priority" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"int", "size":11 },
|
2015-09-10 15:41:45 +02:00
|
|
|
"status" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"text"},
|
2015-09-10 15:41:45 +02:00
|
|
|
"node" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"string", "size":128 },
|
2015-09-10 15:41:45 +02:00
|
|
|
"ver" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"string", "size":128 },
|
2015-09-10 15:41:45 +02:00
|
|
|
"delay" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"date"},
|
2015-09-10 15:41:45 +02:00
|
|
|
"last" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"int", "size":11 },
|
2015-09-10 15:41:45 +02:00
|
|
|
"publickey" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"text"},
|
2015-09-10 15:41:45 +02:00
|
|
|
"muc" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"int", "size":1 },
|
2015-09-10 15:41:45 +02:00
|
|
|
"mucjid" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"string", "size":64 },
|
2015-09-10 15:41:45 +02:00
|
|
|
"mucaffiliation" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"string", "size":32 },
|
2015-09-10 15:41:45 +02:00
|
|
|
"mucrole" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"string", "size":32 }
|
|
|
|
}';
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
parent::__construct();
|
|
|
|
}
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
public function setPresence($stanza) {
|
|
|
|
$jid = explode('/',(string)$stanza->attributes()->from);
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
if($stanza->attributes()->to)
|
|
|
|
$to = current(explode('/',(string)$stanza->attributes()->to));
|
|
|
|
else
|
|
|
|
$to = $jid[0];
|
|
|
|
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('session', $to);
|
|
|
|
$this->__set('jid', $jid[0]);
|
2015-08-03 11:35:01 +02:00
|
|
|
if(isset($jid[1]))
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('resource', $jid[1]);
|
2015-08-03 11:35:01 +02:00
|
|
|
else
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('resource', 'default');
|
|
|
|
|
|
|
|
$this->__set('status', (string)$stanza->status);
|
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
if($stanza->c) {
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('node', (string)$stanza->c->attributes()->node);
|
|
|
|
$this->__set('ver', (string)$stanza->c->attributes()->ver);
|
2015-08-03 11:35:01 +02:00
|
|
|
}
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
if($stanza->priority)
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('priority', (string)$stanza->priority);
|
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
if((string)$stanza->attributes()->type == 'error') {
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('value', 6);
|
2015-08-03 11:35:01 +02:00
|
|
|
} elseif((string)$stanza->attributes()->type == 'unavailable') {
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('value', 5);
|
2015-08-03 11:35:01 +02:00
|
|
|
} elseif((string)$stanza->show == 'away') {
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('value', 2);
|
2015-08-03 11:35:01 +02:00
|
|
|
} elseif((string)$stanza->show == 'dnd') {
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('value', 3);
|
2015-08-03 11:35:01 +02:00
|
|
|
} elseif((string)$stanza->show == 'xa') {
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('value', 4);
|
2015-08-03 11:35:01 +02:00
|
|
|
} else {
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('value', 1);
|
2015-08-03 11:35:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Specific XEP
|
|
|
|
if($stanza->x) {
|
|
|
|
foreach($stanza->children() as $name => $c) {
|
|
|
|
switch($c->attributes()->xmlns) {
|
|
|
|
case 'jabber:x:signed' :
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('publickey', (string)$c);
|
2015-08-03 11:35:01 +02:00
|
|
|
break;
|
|
|
|
case 'http://jabber.org/protocol/muc#user' :
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('muc ', true);
|
2015-08-03 11:35:01 +02:00
|
|
|
if($c->item->attributes()->jid)
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('mucjid', cleanJid((string)$c->item->attributes()->jid));
|
2015-08-03 11:35:01 +02:00
|
|
|
else
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('mucjid', (string)$stanza->attributes()->from);
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('mucrole', (string)$c->item->attributes()->role);
|
|
|
|
$this->__set('mucaffiliation', (string)$c->item->attributes()->affiliation);
|
2015-08-03 11:35:01 +02:00
|
|
|
break;
|
|
|
|
case 'vcard-temp:x:update' :
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('photo', true);
|
2015-08-03 11:35:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
if($stanza->delay) {
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('delay',
|
2015-08-03 11:35:01 +02:00
|
|
|
gmdate(
|
2015-09-10 15:41:45 +02:00
|
|
|
'Y-m-d H:i:s',
|
2015-08-03 11:35:01 +02:00
|
|
|
strtotime(
|
|
|
|
(string)$stanza->delay->attributes()->stamp
|
|
|
|
)
|
|
|
|
)
|
2015-09-10 15:41:45 +02:00
|
|
|
);
|
2015-08-03 11:35:01 +02:00
|
|
|
}
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
if($stanza->query) {
|
2015-09-10 15:41:45 +02:00
|
|
|
$this->__set('last', (int)$stanza->query->attributes()->seconds);
|
2015-08-03 11:35:01 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
public function getPresence() {
|
|
|
|
$txt = array(
|
|
|
|
1 => 'online',
|
|
|
|
2 => 'away',
|
|
|
|
3 => 'dnd',
|
|
|
|
4 => 'xa',
|
|
|
|
5 => 'offline',
|
|
|
|
6 => 'server_error'
|
|
|
|
);
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
$arr = array();
|
|
|
|
$arr['jid'] = $this->jid;
|
|
|
|
$arr['resource'] = $this->resource;
|
|
|
|
$arr['presence'] = $this->value;
|
|
|
|
$arr['presence_txt'] = $txt[$this->value];
|
|
|
|
$arr['priority'] = $this->priority;
|
|
|
|
$arr['status'] = $this->status;
|
|
|
|
$arr['node'] = $this->node;
|
|
|
|
$arr['ver'] = $this->ver;
|
2015-09-10 15:41:45 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
return $arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isChatroom() {
|
|
|
|
if(filter_var($this->jid, FILTER_VALIDATE_EMAIL))
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|