Browse Source

- Edit the chatroom subject

- Add/Delete a group
- Manage the browsers with a new session hash in the database
- Some CSS fixs
pull/16/head
Jaussoin Timothée 11 years ago
parent
commit
51fd41ebcb
  1. 4
      app/models/message/MessageDAO.php
  2. 22
      app/models/presence/PresenceDAO.php
  3. 3
      app/models/sessionx/Sessionx.php
  4. 25
      app/models/sessionx/SessionxDAO.php
  5. 53
      app/widgets/Chat/Chat.php
  6. 17
      app/widgets/Chat/_chat_header_room.tpl
  7. 21
      app/widgets/Chat/_chat_subject.tpl
  8. 7
      app/widgets/Chat/chat.js
  9. 2
      app/widgets/Chat/locales.ini
  10. 30
      app/widgets/Group/Group.php
  11. 18
      app/widgets/Group/_group_delete.tpl
  12. 3
      app/widgets/Group/_group_header.tpl
  13. 2
      app/widgets/Group/locales.ini
  14. 62
      app/widgets/Groups/Groups.php
  15. 21
      app/widgets/Groups/_groups_add.tpl
  16. 3
      app/widgets/Groups/_groups_server.tpl
  17. 5
      app/widgets/Groups/locales.ini
  18. 5
      app/widgets/Login/Login.php
  19. 8
      app/widgets/Login/login.js
  20. 2
      app/widgets/Post/_post_comments_error.tpl
  21. 2
      app/widgets/Rooms/Rooms.php
  22. 2
      app/widgets/Rooms/_rooms_remove.tpl
  23. 10
      system/Sessionx.php
  24. 2
      themes/material/css/list.css
  25. 8
      themes/material/css/style.css

4
app/models/message/MessageDAO.php

@ -98,7 +98,9 @@ class MessageDAO extends SQL {
$this->_sql = '
select * from message
where jidfrom = :jidfrom
and subject != \'\'';
and subject != \'\'
order by published desc
limit 1';
$this->prepare(
'Message',

22
app/models/presence/PresenceDAO.php

@ -122,8 +122,7 @@ class PresenceDAO extends SQL {
$this->prepare('Presence');
return $this->run('Presence');
}
function getPresence($jid, $resource) {
$this->_sql = '
select * from presence
@ -143,6 +142,25 @@ class PresenceDAO extends SQL {
return $this->run('Presence', 'item');
}
function getMyPresenceRoom($jid) {
$this->_sql = '
select * from presence
where
session = :session
and jid = :jid
and mucjid = :session';
$this->prepare(
'Presence',
array(
'session' => $this->_user,
'jid' => $jid,
)
);
return $this->run('Presence', 'item');
}
function getJid($jid) {
$this->_sql = '

3
app/models/sessionx/Sessionx.php

@ -6,6 +6,7 @@ class Sessionx extends Model {
public $session;
public $username;
public $password;
public $hash;
public $resource;
public $rid;
public $sid;
@ -28,6 +29,8 @@ class Sessionx extends Model {
{"type":"string", "size":64 },
"password" :
{"type":"string", "size":64 },
"hash" :
{"type":"string", "size":128 },
"resource" :
{"type":"string", "size":64 },
"rid" :

25
app/models/sessionx/SessionxDAO.php

@ -8,7 +8,8 @@ class SessionxDAO extends SQL {
update sessionx
set username = :username,
password = :password,
resource = :resource,
hash = :hash,
resource = :resource,
rid = :rid,
sid = :sid,
id = :id,
@ -28,7 +29,8 @@ class SessionxDAO extends SQL {
'session' => $s->session,
'username' => $s->username,
'password' => $s->password,
'resource' => $s->resource,
'hash' => $s->hash,
'resource' => $s->resource,
'rid' => $s->rid,
'sid' => $s->sid,
'id' => $s->id,
@ -51,6 +53,7 @@ class SessionxDAO extends SQL {
(session,
username,
password,
hash,
resource,
rid,
sid,
@ -67,6 +70,7 @@ class SessionxDAO extends SQL {
(:session,
:username,
:password,
:hash,
:resource,
:rid,
:sid,
@ -86,6 +90,7 @@ class SessionxDAO extends SQL {
'session' => $s->session,
'username' => $s->username,
'password' => $s->password,
'hash' => $s->hash,
'resource' => $s->resource,
'rid' => $s->rid,
'sid' => $s->sid,
@ -142,6 +147,22 @@ class SessionxDAO extends SQL {
return $this->run('Sessionx', 'item');
}
function getHash($hash) {
$this->_sql = '
select * from sessionx
where
hash = :hash';
$this->prepare(
'Sessionx',
array(
'hash' => $hash
)
);
return $this->run('Sessionx', 'item');
}
function getId($session) {
$this->_sql = '
select id from sessionx

53
app/widgets/Chat/Chat.php

@ -6,6 +6,7 @@ use Moxl\Xec\Action\Message\Publish;
use Moxl\Xec\Action\Muc\GetConfig;
use Moxl\Xec\Action\Muc\SetConfig;
use Moxl\Xec\Action\Muc\SetSubject;
use Respect\Validation\Validator;
@ -21,9 +22,10 @@ class Chat extends WidgetCommon
$this->registerEvent('composing', 'onComposing');
$this->registerEvent('paused', 'onPaused');
$this->registerEvent('gone', 'onGone');
$this->registerEvent('conference_subject', 'onConferenceSubject');
$this->registerEvent('subject', 'onConferenceSubject');
$this->registerEvent('muc_getconfig_handle', 'onRoomConfig');
$this->registerEvent('muc_setconfig_handle', 'onRoomConfigSaved');
//$this->registerEvent('muc_setsubject_handle', 'onRoomSubjectChanged');
//$this->registerEvent('presence', 'onPresence');
}
@ -104,9 +106,9 @@ class Chat extends WidgetCommon
$this->setState($array, $this->__('message.gone'));
}
function onConferenceSubject($message)
function onConferenceSubject($packet)
{
$header = $this->prepareHeaderRoom($message->jidfrom);
$header = $this->prepareHeaderRoom($packet->content->jidfrom);
Header::fill($header);
}
@ -129,7 +131,12 @@ class Chat extends WidgetCommon
{
Notification::append(false, $this->__('chatroom.config_saved'));
}
/*
function onRoomSubjectChanged($packet)
{
Notification::append(false, $this->__('chatroom.suject_changed'));
}
*/
private function setState($array, $message)
{
list($from, $to) = $array;
@ -319,6 +326,40 @@ class Chat extends WidgetCommon
->request();
}
/**
* @brief Get the subject form of a chatroom
*/
function ajaxGetSubject($room)
{
if(!$this->validateJid($room)) return;
$view = $this->tpl();
$md = new \Modl\MessageDAO;
$s = $md->getRoomSubject($room);
$view->assign('room', $room);
$view->assign('subject', $s);
Dialog::fill($view->draw('_chat_subject', true));
}
/**
* @brief Change the subject of a chatroom
*/
function ajaxSetSubject($room, $form)
{
if(!$this->validateJid($room)) return;
$validate_subject = Validator::string()->length(0, 200);
if(!$validate_subject->validate($form->subject->value)) return;
$p = new SetSubject;
$p->setTo($room)
->setSubject($form->subject->value)
->request();
}
/**
* @brief Prepare the contact header
*
@ -358,8 +399,12 @@ class Chat extends WidgetCommon
$cd = new \Modl\ConferenceDAO;
$c = $cd->get($room);
$pd = new \Modl\PresenceDAO;
$p = $pd->getMyPresenceRoom($room);
$view->assign('room', $room);
$view->assign('subject', $s);
$view->assign('presence', $p);
$view->assign('conference', $c);
return $view->draw('_chat_header_room', true);

17
app/widgets/Chat/_chat_header_room.tpl

@ -37,11 +37,16 @@
<li onclick="Rooms_ajaxList('{$room}')">
<span>{$c->__('chatroom.members')}</span>
</li>
<li onclick="Rooms_ajaxRemoveConfirm('{$room}')">
<span>{$c->__('button.delete')}</span>
</li>
<li onclick="Chat_ajaxGetRoomConfig('{$room}')">
<span>{$c->__('chatroom.config')}</span>
</li>
{if="$presence->mucrole == 'moderator'"}
<li onclick="Rooms_ajaxRemoveConfirm('{$room}')">
<span>{$c->__('button.delete')}</span>
</li>
<li onclick="Chat_ajaxGetRoomConfig('{$room}')">
<span>{$c->__('chatroom.config')}</span>
</li>
<li onclick="Chat_ajaxGetSubject('{$room}')">
<span>{$c->__('chatroom.subject')}</span>
</li>
{/if}
</ul>
</div>

21
app/widgets/Chat/_chat_subject.tpl

@ -0,0 +1,21 @@
<section>
<form name="changesubject">
<h3>{$c->__('chatroom.subject')}</h3>
<div>
<textarea name="subject" placeholder="{$c->__('chatroom.subject')}">{$subject->subject}</textarea>
<label for="subject">{$c->__('chatroom.subject')}</label>
</div>
</section>
<div>
<a class="button flat" onclick="Dialog.clear()">
{$c->__('button.close')}
</a>
<a
class="button flat"
onclick="Chat_ajaxSetSubject('{$room}', movim_form_to_json('changesubject')); Dialog.clear();">
{$c->__('button.save')}
</a>
</div>
</div>

7
app/widgets/Chat/chat.js

@ -54,12 +54,19 @@ var Chat = {
if(message.type == 'groupchat') {
bubble = Chat.room;
id = message.jidfrom + '_conversation';
if(message.body.match(/^\/me/)) {
bubble.querySelector('div').className = 'quote';
message.body = message.body.substr(4);
}
bubble.querySelector('div').innerHTML = message.body;
bubble.querySelector('span.info').innerHTML = message.published;
bubble.querySelector('span.user').className = 'user ' + message.color;
bubble.querySelector('span.user').innerHTML = message.resource;
movim_append(id, bubble.outerHTML);
bubble.querySelector('div').className = '';
} else {
if(message.session == message.jidfrom) {
bubble = Chat.right;

2
app/widgets/Chat/locales.ini

@ -17,3 +17,5 @@ chatroom.connected = 'Connected to the chatroom'
chatroom.disconnected = 'Disconnected from the chatroom'
chatroom.config = 'Configuration'
chatroom.config_saved = 'Configuration saved'
chatroom.subject = 'Subject'
chatroom.subject_changed= 'Subject changed'

30
app/widgets/Group/Group.php

@ -10,6 +10,8 @@ use Moxl\Xec\Action\Pubsub\Unsubscribe;
use Moxl\Xec\Action\Pubsub\GetConfig;
use Moxl\Xec\Action\Pubsub\SetConfig;
use Moxl\Xec\Action\Pubsub\Delete;
use Respect\Validation\Validator;
class Group extends WidgetCommon
@ -29,6 +31,8 @@ class Group extends WidgetCommon
$this->registerEvent('pubsub_getaffiliations_handle', 'onAffiliations');
$this->registerEvent('pubsub_getsubscriptions_handle', 'onSubscriptions');
$this->registerEvent('pubsub_delete_handle', 'onDelete');
$this->registerEvent('pubsub_getconfig_handle', 'onConfig');
$this->registerEvent('pubsub_setconfig_handle', 'onConfigSaved');
$this->registerEvent('bookmark_set_handle', 'onBookmark');
@ -43,6 +47,11 @@ class Group extends WidgetCommon
RPC::call('MovimTpl.showPanel');
}
function onDelete($packet)
{
$this->ajaxClear();
}
function onBookmark()
{
$this->ajaxClear();
@ -161,6 +170,27 @@ class Group extends WidgetCommon
RPC::call('movim_fill', 'group_widget', $html);
}
function ajaxDelete($server, $node)
{
if(!$this->validateServerNode($server, $node)) return;
$view = $this->tpl();
$view->assign('server', $server);
$view->assign('node', $node);
Dialog::fill($view->draw('_group_delete', true));
}
function ajaxDeleteConfirm($server, $node)
{
if(!$this->validateServerNode($server, $node)) return;
$d = new Delete;
$d->setTo($server)->setNode($node)
->request();
}
function ajaxGetMetadata($server, $node)
{
if(!$this->validateServerNode($server, $node)) return;

18
app/widgets/Group/_group_delete.tpl

@ -0,0 +1,18 @@
<section>
<h3>{$c->__('group.delete_title')}</h3>
<br />
<h4 class="gray">{$c->__('group.delete_text')}</h4>
<br />
<h4 class="gray">{$node}</h4>
</section>
<div class="no_bar">
<a onclick="Dialog.clear()" class="button flat">
{$c->__('button.cancel')}
</a>
<a
name="submit"
class="button flat"
onclick="Group_ajaxDeleteConfirm('{$server}', '{$node}'); Dialog.clear()">
{$c->__('button.remove')}
</a>
</div>

3
app/widgets/Group/_group_header.tpl

@ -57,6 +57,9 @@
<li onclick="Group_ajaxGetSubscriptions('{$item->server}', '{$item->node}')">
<span>{$c->__('group.subscriptions')}</span>
</li>
<li onclick="Group_ajaxDelete('{$item->server}', '{$item->node}')">
<span>{$c->__('button.delete')}</span>
</li>
</ul>
{/if}
</div>

2
app/widgets/Group/locales.ini

@ -10,6 +10,8 @@ group.empty_title = 'Groups'
group.empty_text = 'Discover, follow and share'
group.empty = 'Something bad happened to this group'
group.config_saved = 'Group configuration saved'
group.delete_title = 'Delete the group'
group.delete_text = 'You are going to delete the following group. Please confirm your action.'
group.configuration = 'Configuration'
group.subscriptions = 'Subscriptions'

62
app/widgets/Groups/Groups.php

@ -3,6 +3,7 @@
use Moxl\Xec\Action\Pubsub\GetItems;
use Moxl\Xec\Action\Pubsub\DiscoItems;
use Respect\Validation\Validator;
use Moxl\Xec\Action\Pubsub\Create;
class Groups extends WidgetCommon
{
@ -12,6 +13,8 @@ class Groups extends WidgetCommon
{
$this->registerEvent('pubsub_discoitems_handle', 'onDisco');
$this->registerEvent('pubsub_discoitems_error', 'onDiscoError');
$this->registerEvent('pubsub_create_handle', 'onCreate');
$this->registerEvent('pubsub_delete_handle', 'onDelete');
$this->addjs('groups.js');
}
@ -21,6 +24,22 @@ class Groups extends WidgetCommon
$this->displayServer($server);
}
function onCreate($packet)
{
Notification::append(null, $this->__('groups.created'));
list($server, $node) = array_values($packet->content);
$this->ajaxDisco($server);
}
function onDelete($packet)
{
Notification::append(null, $this->__('groups.deleted'));
list($server, $node) = array_values($packet->content);
$this->displayServer($server);
}
function onDiscoError($packet)
{
// Display a nice error
@ -47,17 +66,39 @@ class Groups extends WidgetCommon
function ajaxDisco($server)
{
$validate_server = Validator::string()->noWhitespace()->length(6, 40);
if(!$validate_server->validate($server)) return;
if(!$this->validateServer($server)) return;
$r = new DiscoItems;
$r->setTo($server)->request();
}
function ajaxAdd($server)
{
if(!$this->validateServer($server)) return;
$view = $this->tpl();
$view->assign('server', $server);
Dialog::fill($view->draw('_groups_add', true));
}
function ajaxAddConfirm($server, $form)
{
if(!$this->validateServer($server)) return;
$validate_name = Validator::string()->length(6, 80);
if(!$validate_name->validate($form->name->value)) return;
$uri = stringToUri($form->name->value);
$c = new Create;
$c->setTo($server)->setNode($uri)->setData($form->name->value)
->request();
}
private function displayServer($server)
{
$validate_server = Validator::string()->noWhitespace()->length(6, 40);
if(!$validate_server->validate($server)) return;
if(!$this->validateServer($server)) return;
$html = $this->prepareServer($server);
@ -108,6 +149,17 @@ class Groups extends WidgetCommon
}
return $servers;
}
/**
* @brief Validate the server
*
* @param string $server
*/
private function validateServer($server)
{
$validate_server = Validator::string()->noWhitespace()->length(6, 40);
if(!$validate_server->validate($server)) return false;
else return true;
}
function display()
{

21
app/widgets/Groups/_groups_add.tpl

@ -0,0 +1,21 @@
<section>
<form name="groupadd">
<h3>{$c->__('groups.add')}</h3>
<div>
<input name="name" placeholder="{$c->__('groups.name_example')}" type="text" required />
<label for="name">{$c->__('groups.name')}</label>
</div>
</section>
<div>
<a class="button flat" onclick="Dialog.clear()">
{$c->__('button.close')}
</a>
<a
class="button flat"
onclick="Groups_ajaxAddConfirm('{$server}', movim_form_to_json('groupadd')); Dialog.clear();">
{$c->__('button.add')}
</a>
</div>
</div>

3
app/widgets/Groups/_groups_server.tpl

@ -37,3 +37,6 @@
</li>
{/loop}
</ul>
<a onclick="Groups_ajaxAdd('{$server}')" class="button action color">
<i class="md md-add"></i>
</a>

5
app/widgets/Groups/locales.ini

@ -3,6 +3,11 @@ groups.contact_post = 'Contact post'
groups.empty_text1 = "You don't have any subscriptions yet, select a group server above to start exploring."
groups.empty_text2 = "Subscribe to your favorite feeds by bookmarking them."
groups.subscriptions = 'My Subscriptions'
groups.add = 'Create a new Group'
groups.name = 'Group name'
groups.name_example = 'My Little Pony - Fan Club'
groups.created = 'Group created successfully'
groups.deleted = 'Group deleted successfully'
groups.sub = '%s subscribers'
groups.num = '%s posts'

5
app/widgets/Login/Login.php

@ -188,9 +188,12 @@ class Login extends WidgetBase
// We check if we already have an open session
$sd = new \Modl\SessionxDAO;
$here = $sd->checkConnected($username, $host);
//$here = $sd->checkConnected($username, $host);
$here = $sd->getHash(sha1($username.$password.$host));
if($here) {
RPC::call('Login.setCookie', $here->session);
RPC::call('movim_redirect', Route::urlize('main'));
$this->showErrorBlock('conflict');
return;
}

8
app/widgets/Login/login.js

@ -122,8 +122,14 @@ var Login = {
Login.rememberSession(jid);
localStorage.postStart = 1;
movim_reload(url);
}
},
/**
* @brief Set the Movim cookie
*/
setCookie : function(value) {
document.cookie = 'MOVIM_SESSION_ID='+value;
}
}
MovimWebsocket.attach(function()

2
app/widgets/Post/_post_comments_error.tpl

@ -1,4 +1,4 @@
<ul class="thin">
<ul class="middle">
<li>
<span class="icon gray">
<i class="md md-comment"></i>

2
app/widgets/Rooms/Rooms.php

@ -131,7 +131,7 @@ class Rooms extends WidgetCommon
}
/**
* @brief Display the add room form
* @brief Confirm the room add
*/
function ajaxChatroomAdd($form)
{

2
app/widgets/Rooms/_rooms_remove.tpl

@ -12,7 +12,7 @@
<a
name="submit"
class="button flat"
onclick="Rooms_ajaxRemove('{$room}'); Dialog.clear()">
onclick="Rooms_ajaxExit('{$room}'); Rooms_ajaxRemove('{$room}'); Dialog.clear()">
{$c->__('button.remove')}
</a>
</div>

10
system/Sessionx.php

@ -30,6 +30,7 @@ class Sessionx {
private $_user;
private $_password;
private $_resource;
private $_hash;
private $_sid;
private $_url;
private $_port;
@ -79,7 +80,8 @@ class Sessionx {
$s->session = self::$_sessionid;
$s->username = $this->_user;
$s->password = $this->_password;
$s->resource = $this->_resource;
$s->hash = sha1($this->_user.$this->password.$this->host);
$s->resource = $this->_resource;
$s->rid = $this->_rid;
$s->sid = $this->_sid;
$s->id = $this->_id;
@ -104,7 +106,7 @@ class Sessionx {
$this->_domain = $domain;
$this->_user = $user;
$this->_password = $pass;
$this->_resource = 'moxl'.\generateKey(6);
$this->_resource = 'moxl'.\generateKey(6);
$this->_start = date(DATE_ISO8601);
$this->_rid = rand(1, 2048);
@ -122,7 +124,8 @@ class Sessionx {
if(isset($session)) {
$this->_user = $session->username;
$this->_password = $session->password;
$this->_resource = $session->resource;
$this->_hash = $session->hash;
$this->_resource = $session->resource;
$this->_rid = $session->rid;
$this->_sid = $session->sid;
$this->_id = $session->id;
@ -156,6 +159,7 @@ class Sessionx {
'domain',
'user',
'password',
'hash',
'start')
)
) {

2
themes/material/css/list.css

@ -221,7 +221,7 @@ ul li div.bubble div {
display: inline;
}
ul li div.bubble.quote {
ul li div.quote {
font-style: italic;
}

8
themes/material/css/style.css

@ -296,6 +296,12 @@ main > header > div > .return {
box-sizing: border-box;
}
main > header > div > form.return {
display: block;
padding-right: 0;
padding-left: 9rem;
}
/* Not very beautiful… */
main > header > div > .return.condensed > h2 {
line-height: 3.5rem;
@ -309,7 +315,7 @@ main > header > div > .return > h4 {
font-size: 1.75rem;
}
main > header > div > .return.r1 { max-width: calc(100% + 2rem); }
main > header > div > .return.r1 { max-width: calc(100% + 3rem); }
main > header > div > .return.r2 { max-width: calc(100% - 5rem); }
main > header > div > .return.r3 { max-width: calc(100% - 12rem); }

Loading…
Cancel
Save