2016-03-15 16:28:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package Widgets
|
|
|
|
*
|
|
|
|
* @file Logout.php
|
|
|
|
* This file is part of MOVIM.
|
|
|
|
*
|
|
|
|
* @brief The little logout widget.
|
|
|
|
*
|
|
|
|
* @author Guillaume Pasquet <etenil@etenilsrealm.nl>
|
|
|
|
*
|
|
|
|
* @version 1.0
|
|
|
|
* @date 20 October 2010
|
|
|
|
*
|
|
|
|
* Copyright (C)2010 MOVIM project
|
|
|
|
*
|
|
|
|
* See COPYING for licensing information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use Moxl\Xec\Action\Presence\Chat;
|
|
|
|
use Moxl\Xec\Action\Presence\Away;
|
|
|
|
use Moxl\Xec\Action\Presence\DND;
|
|
|
|
use Moxl\Xec\Action\Presence\XA;
|
|
|
|
use Moxl\Xec\Action\Presence\Unavailable;
|
|
|
|
use Moxl\Xec\Action\Pubsub\GetItems;
|
|
|
|
use Moxl\Stanza\Stream;
|
|
|
|
use Moxl\Xec\Action\Storage\Get;
|
|
|
|
|
2016-03-29 14:12:33 +02:00
|
|
|
class Presence extends \Movim\Widget\Base
|
2016-03-15 16:28:38 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
function load()
|
|
|
|
{
|
|
|
|
$this->addcss('presence.css');
|
|
|
|
$this->addjs('presence.js');
|
|
|
|
$this->registerEvent('mypresence', 'onMyPresence');
|
2016-03-29 14:12:33 +02:00
|
|
|
$this->registerEvent('session_up', 'onSessionUp');
|
|
|
|
$this->registerEvent('session_down', 'onSessionDown');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSessionUp()
|
|
|
|
{
|
|
|
|
$this->ajaxSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSessionDown()
|
|
|
|
{
|
|
|
|
$p = new Away;
|
|
|
|
$p->request();
|
2016-03-15 16:28:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMyPresence($packet)
|
|
|
|
{
|
|
|
|
$html = $this->preparePresence();
|
|
|
|
RPC::call('movim_fill', 'presence_widget', $html);
|
|
|
|
Notification::append(null, $this->__('status.updated'));
|
|
|
|
RPC::call('Presence.refresh');
|
|
|
|
RPC::call('movim_remove_class', '#presence_widget', 'unfolded');
|
|
|
|
}
|
|
|
|
|
|
|
|
function ajaxSet($form = false)
|
|
|
|
{
|
|
|
|
if($form == false) {
|
|
|
|
// We update the cache with our status and presence
|
|
|
|
$presence = Cache::c('presence');
|
|
|
|
|
|
|
|
$value = $presence['show'];
|
|
|
|
$status = $presence['status'];
|
|
|
|
|
|
|
|
if($presence == null || !isset($presence['show']) || $presence['show'] == '')
|
|
|
|
$value = 'chat';
|
|
|
|
|
|
|
|
if($presence == null|| !isset($presence['status']) || $presence['status'] == '')
|
|
|
|
$status = $this->__('status.online');
|
|
|
|
} else {
|
|
|
|
$status = $form['status'];
|
|
|
|
$value = $form['value'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(in_array($value, array('chat', 'away', 'dnd', 'xa'))) {
|
|
|
|
switch($value) {
|
|
|
|
case 'chat':
|
|
|
|
$p = new Chat;
|
|
|
|
$p->setStatus($status)->request();
|
|
|
|
break;
|
|
|
|
case 'away':
|
|
|
|
$p = new Away;
|
|
|
|
$p->setStatus($status)->request();
|
|
|
|
break;
|
|
|
|
case 'dnd':
|
|
|
|
$p = new DND;
|
|
|
|
$p->setStatus($status)->request();
|
|
|
|
break;
|
|
|
|
case 'xa':
|
|
|
|
$p = new XA;
|
|
|
|
$p->setStatus($status)->request();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Cache::c(
|
|
|
|
'presence',
|
|
|
|
array(
|
|
|
|
'status' => $status,
|
|
|
|
'show' => $value
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ajaxLogout()
|
|
|
|
{
|
|
|
|
$pd = new \Modl\PresenceDAO();
|
2016-03-29 14:12:33 +02:00
|
|
|
$pd->clearPresence();
|
2016-03-15 16:28:38 +01:00
|
|
|
|
2016-04-12 10:29:33 +02:00
|
|
|
$session = \Session::start();
|
2016-03-15 16:28:38 +01:00
|
|
|
$p = new Unavailable;
|
|
|
|
$p->setType('terminate')
|
2016-04-12 10:29:33 +02:00
|
|
|
->setResource($session->get('resource'))
|
|
|
|
->setTo($session->get('jid'))
|
2016-03-15 16:28:38 +01:00
|
|
|
->request();
|
|
|
|
|
|
|
|
Stream::end();
|
|
|
|
}
|
|
|
|
|
2016-04-12 10:29:33 +02:00
|
|
|
function ajaxGetPresence()
|
|
|
|
{
|
|
|
|
$html = $this->preparePresence();
|
|
|
|
RPC::call('movim_fill', 'presence_widget', $html);
|
|
|
|
}
|
|
|
|
|
2016-03-15 16:28:38 +01:00
|
|
|
function ajaxConfigGet() {
|
|
|
|
$s = new Get;
|
|
|
|
$s->setXmlns('movim:prefs')
|
|
|
|
->request();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We get the server capabilities
|
|
|
|
function ajaxServerCapsGet()
|
|
|
|
{
|
2016-04-12 10:29:33 +02:00
|
|
|
$session = \Session::start();
|
2016-03-15 16:28:38 +01:00
|
|
|
$c = new \Moxl\Xec\Action\Disco\Request;
|
2016-04-12 10:29:33 +02:00
|
|
|
$c->setTo($session->get('host'))
|
2016-03-15 16:28:38 +01:00
|
|
|
->request();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We discover the server services
|
|
|
|
function ajaxServerDisco()
|
|
|
|
{
|
2016-04-12 10:29:33 +02:00
|
|
|
$session = \Session::start();
|
2016-03-15 16:28:38 +01:00
|
|
|
$c = new \Moxl\Xec\Action\Disco\Items;
|
2016-04-12 10:29:33 +02:00
|
|
|
$c->setTo($session->get('host'))
|
2016-03-15 16:28:38 +01:00
|
|
|
->request();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We refresh the bookmarks
|
|
|
|
function ajaxBookmarksGet()
|
|
|
|
{
|
2016-04-12 10:29:33 +02:00
|
|
|
$session = \Session::start();
|
2016-03-15 16:28:38 +01:00
|
|
|
$b = new \Moxl\Xec\Action\Bookmark\Get;
|
2016-04-12 10:29:33 +02:00
|
|
|
$b->setTo($session->get('jid'))
|
2016-03-15 16:28:38 +01:00
|
|
|
->request();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We refresh the user (local) configuration
|
|
|
|
function ajaxUserRefresh()
|
|
|
|
{
|
|
|
|
$language = $this->user->getConfig('language');
|
|
|
|
if(isset($language)) {
|
|
|
|
loadLanguage($language);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We refresh our personnal feed
|
|
|
|
function ajaxFeedRefresh()
|
|
|
|
{
|
|
|
|
$r = new GetItems;
|
|
|
|
$r->setTo($this->user->getLogin())
|
|
|
|
->setNode('urn:xmpp:microblog:0')
|
|
|
|
->request();
|
|
|
|
}
|
|
|
|
|
|
|
|
function ajaxOpenDialog()
|
|
|
|
{
|
|
|
|
Dialog::fill($this->preparePresenceList());
|
|
|
|
RPC::call('Presence.refresh');
|
|
|
|
}
|
|
|
|
|
|
|
|
function preparePresence()
|
|
|
|
{
|
2016-04-12 10:29:33 +02:00
|
|
|
$cd = new \Modl\ContactDAO;
|
|
|
|
$pd = new \Modl\PresenceDAO;
|
2016-03-15 16:28:38 +01:00
|
|
|
|
2016-04-12 10:29:33 +02:00
|
|
|
$session = \Session::start();
|
|
|
|
$presence = $pd->getPresence($session->get('jid'), $session->get('resource'));
|
2016-03-15 16:28:38 +01:00
|
|
|
|
|
|
|
$presencetpl = $this->tpl();
|
|
|
|
|
|
|
|
$contact = $cd->get();
|
|
|
|
if($contact == null) {
|
|
|
|
$contact = new \Modl\Contact;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($presence == null) {
|
|
|
|
$presence = new \Modl\Presence;
|
|
|
|
}
|
|
|
|
|
|
|
|
$presencetpl->assign('me', $contact);
|
|
|
|
$presencetpl->assign('presence', $presence);
|
|
|
|
$presencetpl->assign('presencetxt', getPresencesTxt());
|
|
|
|
$presencetpl->assign('dialog', $this->call('ajaxOpenDialog'));
|
|
|
|
|
|
|
|
$html = $presencetpl->draw('_presence', true);
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
function preparePresenceList()
|
|
|
|
{
|
|
|
|
$txt = getPresences();
|
|
|
|
$txts = getPresencesTxt();
|
|
|
|
|
2016-04-12 10:29:33 +02:00
|
|
|
$session = \Session::start();
|
2016-03-15 16:28:38 +01:00
|
|
|
|
|
|
|
$pd = new \Modl\PresenceDAO();
|
2016-04-12 10:29:33 +02:00
|
|
|
$p = $pd->getPresence($session->get('jid'), $session->get('resource'));
|
2016-03-15 16:28:38 +01:00
|
|
|
|
|
|
|
$cd = new \Modl\ContactDAO();
|
2016-04-12 10:29:33 +02:00
|
|
|
$contact = $cd->get($session->get('jid'));
|
2016-03-15 16:28:38 +01:00
|
|
|
if($contact == null) {
|
|
|
|
$contact = new \Modl\Contact;
|
|
|
|
}
|
|
|
|
|
|
|
|
$presencetpl = $this->tpl();
|
|
|
|
|
|
|
|
$presencetpl->assign('contact', $contact);
|
|
|
|
$presencetpl->assign('p', $p);
|
|
|
|
$presencetpl->assign('txt', $txt);
|
|
|
|
$presencetpl->assign('txts', $txts);
|
|
|
|
|
|
|
|
$html = $presencetpl->draw('_presence_list', true);
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
function display()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|