Browse Source

- Move the pubsub publish action to a new Widget

- Use it in the groups (not fully enabled yet)
- Remove some old files
- Fix minor issues in the chat
pull/16/head
Jaussoin Timothée 11 years ago
parent
commit
0b9f30a2ee
  1. 6
      app/assets/js/movim_tpl.js
  2. 14
      app/models/presence/Presence.php
  3. 1
      app/views/group.tpl
  4. 1
      app/views/news.tpl
  5. 3
      app/widgets/Chats/Chats.php
  6. 3
      app/widgets/Chats/_chats_add.tpl
  7. 1
      app/widgets/Chats/_chats_add_extend.tpl
  8. 8
      app/widgets/Chats/_chats_item.tpl
  9. 2
      app/widgets/Contact/_contact.tpl
  10. 10
      app/widgets/Group/Group.php
  11. 2
      app/widgets/Group/_group_publish.tpl
  12. 3
      app/widgets/Groups/groups.js
  13. 1
      app/widgets/Menu/Menu.php
  14. 2
      app/widgets/Menu/_menu_add.tpl
  15. 103
      app/widgets/Post/Post.php
  16. 53
      app/widgets/Post/_post_create.tpl
  17. 27
      app/widgets/Post/_post_header_create.tpl
  18. 21
      app/widgets/Post/post.js
  19. 171
      app/widgets/Publish/Publish.php
  20. 54
      app/widgets/Publish/_publish_create.tpl
  21. 0
      app/widgets/Publish/_publish_embed.tpl
  22. 0
      app/widgets/Publish/_publish_gallery.tpl
  23. 45
      app/widgets/Publish/_publish_header.tpl
  24. 0
      app/widgets/Publish/_publish_help.tpl
  25. 0
      app/widgets/Publish/_publish_preview.tpl
  26. 20
      app/widgets/Publish/locales.ini
  27. 21
      app/widgets/Publish/publish.js
  28. 0
      app/widgets/Publish/publish.tpl
  29. 14
      app/widgets/Rooms/_rooms_list.tpl
  30. 35
      linker.php

6
app/assets/js/movim_tpl.js

@ -73,6 +73,12 @@ var MovimTpl = {
//if(inner != null) inner.innerHTML = '';
//else document.querySelector(selector).innerHTML = '';
},
fill : function(selector, html) {
target = document.querySelector(selector);
if(target) {
target.innerHTML = html;
}
},
isPanel : function() {
if(movim_has_class('main section > div:first-child:nth-last-child(2) ~ div', 'enabled')) {
return true;

14
app/models/presence/Presence.php

@ -30,6 +30,9 @@ class Presence extends Model {
protected $mucjid;
protected $mucaffiliation;
protected $mucrole;
// vcard-temp:x:update, not saved in the DB
public $photo = false;
public function __construct() {
$this->_struct = '
@ -118,11 +121,18 @@ class Presence extends Model {
$this->publickey = (string)$c;
break;
case 'http://jabber.org/protocol/muc#user' :
$this->muc = true;
$this->mucjid = cleanJid((string)$c->item->attributes()->jid);
$this->muc = true;
if($c->item->attributes()->jid)
$this->mucjid = cleanJid((string)$c->item->attributes()->jid);
else
$this->mucjid = (string)$stanza->attributes()->from;
$this->mucrole = (string)$c->item->attributes()->role;
$this->mucaffiliation = (string)$c->item->attributes()->affiliation;
break;
case 'vcard-temp:x:update' :
$this->photo = true;
break;
}
}
}

1
app/views/group.tpl

@ -8,5 +8,6 @@
<section>
<?php $this->widget('Groups'); ?>
<?php $this->widget('Group'); ?>
<?php $this->widget('Publish'); ?>
</section>
</main>

1
app/views/news.tpl

@ -10,5 +10,6 @@
<section>
<?php $this->widget('Menu');?>
<?php $this->widget('Post');?>
<?php $this->widget('Publish');?>
</section>
</main>

3
app/widgets/Chats/Chats.php

@ -145,6 +145,7 @@ class Chats extends WidgetCommon
$cd = new \Modl\ContactDAO;
$md = new \modl\MessageDAO();
$cad = new \modl\CapsDAO();
$presencestxt = getPresencesTxt();
@ -154,8 +155,10 @@ class Chats extends WidgetCommon
$view->assign('presence', $presencestxt[$cr->value]);
}
$view->assign('contact', $cr);
$view->assign('caps', $cad->get($cr->node.'#'.$cr->ver));
} else {
$view->assign('contact', $cd->get($jid));
$view->assign('caps', null);
}
$m = $md->getContact($jid, 0, 1);

3
app/widgets/Chats/_chats_add.tpl

@ -3,7 +3,8 @@
<ul class="active" id="add_extend">
<li class="subheader">{$c->__('chats.frequent')}</li>
{loop="$top"}
<li class="condensed" onclick="Chats_ajaxOpen('{$value->jid}'); Dialog.clear()">
<li class="condensed {if="$value->last > 60"} inactive{/if}"
onclick="Chats_ajaxOpen('{$value->jid}'); Dialog.clear()">
{$url = $value->getPhoto('s')}
{if="$url"}
<span class="icon bubble

1
app/widgets/Chats/_chats_add_extend.tpl

@ -1,4 +1,5 @@
<br />
{$group = ''}
{loop="$contacts"}
{if="$group != $value->groupname"}
<li class="subheader">{$value->groupname}</li>

8
app/widgets/Chats/_chats_item.tpl

@ -4,8 +4,16 @@
class="
{if="isset($message)"}condensed{/if}
{if="$contact->last > 60"} inactive{/if}
{if="$caps && in_array($caps->type, array('handheld', 'phone'))"}
action
{/if}
"
title="{$contact->jid}">
{if="$caps && in_array($caps->type, array('handheld', 'phone'))"}
<div class="action">
<i class="md md-smartphone"></i>
</div>
{/if}
<span data-key="chat|{$contact->jid}" class="counter bottom"></span>
{$url = $contact->getPhoto('s')}
{if="$url"}

2
app/widgets/Contact/_contact.tpl

@ -126,7 +126,7 @@
<li class="condensed block">
<span class="icon gray"><i class="md md-format-align-justify"></i></span>
<span>{$c->__('general.about')}</span>
<p>{$contact->description}</p>
<p class="all">{$contact->description}</p>
</li>
{/if}

10
app/widgets/Group/Group.php

@ -42,8 +42,11 @@ class Group extends WidgetCommon
function onItems($packet)
{
$arr = $packet->content;
$this->displayItems($arr['server'], $arr['node']);
list($server, $node) = array_values($packet->content);
$this->displayItems($server, $node);
$this->ajaxGetAffiliations($server, $node);
RPC::call('Group.clearLoad');
RPC::call('MovimTpl.showPanel');
}
@ -68,6 +71,7 @@ class Group extends WidgetCommon
Notification::append(false, $this->__('group.empty'));
$this->ajaxDelete($server, $node, true);
$this->ajaxGetAffiliations($server, $node);
// Display an error message
RPC::call('Group.clearLoad');
}
@ -86,6 +90,8 @@ class Group extends WidgetCommon
if(isset($this->_role)
&& ($this->_role == 'owner' || $this->_role == 'publisher')) {
$view = $this->tpl();
$view->assign('server', $server);
$view->assign('node', $node);
RPC::call('movim_append', 'group_widget', $view->draw('_group_publish', true));
}
}

2
app/widgets/Group/_group_publish.tpl

@ -1,3 +1,3 @@
<a onclick="Group_ajaxPublish()" class="button action color">
<a onclick="Publish_ajaxCreate('{$server}','{$node}')" class="button action color">
<i class="md md-create"></i>
</a>

3
app/widgets/Groups/groups.js

@ -9,7 +9,8 @@ var Groups = {
MovimTpl.scrollPanelTop();
Group_ajaxGetItems(this.dataset.server, this.dataset.node);
Group_ajaxGetMetadata(this.dataset.server, this.dataset.node);
Group_ajaxGetAffiliations(this.dataset.server, this.dataset.node);
//Group_ajaxGetAffiliations(this.dataset.server, this.dataset.node);
//Group_ajaxGetSubscriptions(this.dataset.server, this.dataset.node);
Groups.reset(items);
movim_add_class(this, 'active');
}

1
app/widgets/Menu/Menu.php

@ -136,6 +136,7 @@ class Menu extends WidgetCommon
if($page == 0 || $page == ""){
$view = $this->tpl();
$view->assign('to', $this->user->getLogin());
$html .= $view->draw('_menu_add', true);
}

2
app/widgets/Menu/_menu_add.tpl

@ -1,3 +1,3 @@
<a onclick="Post_ajaxCreate(); MovimTpl.showPanel();" class="button action color red">
<a onclick="Publish_ajaxCreate('{$to}', 'urn:xmpp:microblog:0'); MovimTpl.showPanel();" class="button action color red">
<i class="md md-create"></i>
</a>

103
app/widgets/Post/Post.php

@ -41,13 +41,6 @@ class Post extends WidgetCommon
function onPublish($packet)
{
list($to, $node, $id) = array_values($packet->content);
$cn = new CommentCreateNode;
$cn->setTo($to)
->setParentId($id)
->request();
Notification::append(false, $this->__('post.published'));
$this->ajaxClear();
RPC::call('MovimTpl.hidePanel');
@ -107,69 +100,6 @@ class Post extends WidgetCommon
RPC::call('movim_fill', 'post_widget', $html);
}
function ajaxCreate()
{
$view = $this->tpl();
$view->assign('to', $this->user->getLogin());
RPC::call('movim_fill', 'post_widget', $view->draw('_post_create', true));
$view = $this->tpl();
Header::fill($view->draw('_post_header_create', true));
RPC::call('Post.setEmbed');
}
function ajaxPreview($form)
{
if($form->content->value != '') {
$view = $this->tpl();
$view->assign('content', Markdown::defaultTransform($form->content->value));
Dialog::fill($view->draw('_post_preview', true), true);
} else {
Notification::append(false, $this->__('post.no_content_preview'));
}
}
function ajaxHelp()
{
$view = $this->tpl();
Dialog::fill($view->draw('_post_help', true), true);
}
function ajaxPublish($form)
{
if($form->content->value != '') {
$content = Markdown::defaultTransform($form->content->value);
$p = new PostPublish;
$p->setFrom($this->user->getLogin())
->setTo($form->to->value)
->setNode($form->node->value);
//->setLocation($geo)
//->enableComments()
if($form->title->value != '') {
$p->setTitle($form->title->value);
}
if($form->embed->value != '' && filter_var($form->embed->value, FILTER_VALIDATE_URL)) {
$embed = Embed\Embed::create($form->embed->value);
$content .= $this->prepareEmbed($embed);
$p->setLink($form->embed->value);
if($embed->type == 'photo') {
$key = key($embed->images);
$p->setImage($embed->images[0]['value'], $embed->title, $embed->images[0]['mime']);
}
}
$p->setContentHtml(rawurldecode($content))
->request();
} else {
Notification::append(false, $this->__('post.no_content'));
}
}
function ajaxDelete($to, $node, $id)
{
$view = $this->tpl();
@ -215,39 +145,6 @@ class Post extends WidgetCommon
->request();
}
function ajaxEmbedTest($url)
{
if($url == '') {
return;
} elseif(!filter_var($url, FILTER_VALIDATE_URL)) {
Notification::append(false, $this->__('post.valid_url'));
return;
}
$embed = Embed\Embed::create($url);
$html = $this->prepareEmbed($embed);
if($embed->type == 'photo') {
RPC::call('movim_fill', 'gallery', $this->prepareGallery($embed));
}
RPC::call('movim_fill', 'preview', $html);
}
function prepareGallery($embed)
{
$view = $this->tpl();
$view->assign('embed', $embed);
return $view->draw('_post_gallery', true);
}
function prepareEmbed($embed)
{
$view = $this->tpl();
$view->assign('embed', $embed);
return $view->draw('_post_embed', true);
}
function prepareEmpty()
{
$view = $this->tpl();

53
app/widgets/Post/_post_create.tpl

@ -1,53 +0,0 @@
<form name="post" class="padded_top_bottom">
<input type="hidden" name="to" value="{$to}">
<input type="hidden" name="node" value="urn:xmpp:microblog:0">
<div>
<input type="text" name="title" placeholder="{$c->__('post.title')}">
<label for="title">{$c->__('post.title')}</label>
</div>
<div>
<textarea name="content" placeholder="{$c->__('post.content')}" onkeyup="movim_textarea_autoheight(this);"></textarea>
<label for="content">{$c->__('post.content')}</label>
</div>
<div>
<input
type="url"
name="embed"
placeholder="http://myawesomewebsite.com/ or http://mynicepictureurl.com/"
onPaste="var e=this; setTimeout(function(){Post_ajaxEmbedTest(e.value);}, 4);"
>
<label for="embed">{$c->__('post.link')}</label>
<ul class="middle flex active">
<li class="subheader">{$c->__('post.embed_tip')}</li>
<a class="block" target="_blank" href="http://imgur.com/">
<li class="block action">
<div class="action">
<i class="md md-chevron-right"></i>
</div>
<span class="bubble icon">
<img src="https://userecho.com/s/logos/2015/2015.png">
</span>
Imgur
</li>
</a>
<a class="block" target="_blank" href="https://www.flickr.com/">
<li class="action">
<div class="action">
<i class="md md-chevron-right"></i>
</div>
<span class="bubble icon">
<img src="https://www.flickr.com/apple-touch-icon.png">
</span>
Flickr
</li>
</a>
</ul>
<article>
<section>
<content id="preview"></content>
</section>
</article>
<div id="gallery"></div>
</div>
</form>

27
app/widgets/Post/_post_header_create.tpl

@ -1,27 +0,0 @@
<div>
<span class="on_desktop icon"><i class="md md-view-list"></i></span>
<h2>{$c->__('page.news')}</h2>
</div>
<div>
<div class="return active r3" onclick="MovimTpl.hidePanel(); Post_ajaxClear();">
<span id="back" class="icon" ><i class="md md-arrow-back"></i></span>
<h2>{$c->__('post.new')}</h2>
</div>
<ul class="active">
<li onclick="Post_ajaxHelp()">
<span class="icon">
<i class="md md-help"></i>
</span>
</li>
<li onclick="Post_ajaxPreview(movim_form_to_json('post'))">
<span class="icon">
<i class="md md-remove-red-eye"></i>
</span>
</li>
<li onclick="Post_ajaxPublish(movim_form_to_json('post'))">
<span class="icon">
<i class="md md-send"></i>
</span>
</li>
</ul>
</div>

21
app/widgets/Post/post.js

@ -1,21 +0,0 @@
var Post = {
init: function() {
if(localStorage.getItem('share_url')) {
Post_ajaxCreate();
MovimTpl.showPanel();
}
},
setEmbed: function() {
if(localStorage.getItem('share_url')) {
var embed = document.querySelector('input[name=embed]');
embed.value = localStorage.getItem('share_url');
embed.onpaste();
localStorage.removeItem('share_url');
}
}
}
MovimWebsocket.attach(function() {
Post.init();
});

171
app/widgets/Publish/Publish.php

@ -0,0 +1,171 @@
<?php
/**
* @package Widgets
*
* @file Post.php
* This file is part of Movim.
*
* @brief The Post visualisation widget
*
* @author Jaussoin Timothée <edhelas_at_movim_dot_com>
*
* @version 1.0
* @date 1 december 2014
*
* Copyright (C)2014 MOVIM project
*
* See COPYING for licensing information.
*/
use Moxl\Xec\Action\Pubsub\PostPublish;
use Moxl\Xec\Action\Microblog\CommentCreateNode;
use \Michelf\Markdown;
use Respect\Validation\Validator;
class Publish extends WidgetCommon
{
function load()
{
$this->addjs('publish.js');
$this->registerEvent('pubsub_publishpublish_handle', 'onPublish');
}
function onPublish($packet)
{
list($to, $node, $id) = array_values($packet->content);
// Only for the microblog for the moment
if($node == 'urn:xmpp:microblog:0') {
$cn = new CommentCreateNode;
$cn->setTo($to)
->setParentId($id)
->request();
}
}
function ajaxCreateBlog()
{
$this->ajaxCreate($this->user->getLogin(), 'urn:xmpp:microblog:0');
}
function ajaxCreate($server, $node)
{
if(!$this->validateServerNode($server, $node)) return;
$view = $this->tpl();
$view->assign('to', $server);
$view->assign('node', $node);
RPC::call('MovimTpl.fill', 'main section > div:nth-child(2)', $view->draw('_publish_create', true));
$pd = new \Modl\ItemDAO;
$item = $pd->getItem($server, $node);
$view = $this->tpl();
$view->assign('item', $item);
$view->assign('server', $server);
$view->assign('node', $node);
Header::fill($view->draw('_publish_header', true));
RPC::call('Publish.setEmbed');
}
function ajaxPreview($form)
{
if($form->content->value != '') {
$view = $this->tpl();
$view->assign('content', Markdown::defaultTransform($form->content->value));
Dialog::fill($view->draw('_publish_preview', true), true);
} else {
Notification::append(false, $this->__('publish.no_content_preview'));
}
}
function ajaxHelp()
{
$view = $this->tpl();
Dialog::fill($view->draw('_publish_help', true), true);
}
function ajaxPublish($form)
{
if($form->content->value != '') {
$content = Markdown::defaultTransform($form->content->value);
$p = new PostPublish;
$p->setFrom($this->user->getLogin())
->setTo($form->to->value)
->setNode($form->node->value);
//->setLocation($geo)
//->enableComments()
if($form->title->value != '') {
$p->setTitle($form->title->value);
}
if($form->embed->value != '' && filter_var($form->embed->value, FILTER_VALIDATE_URL)) {
$embed = Embed\Embed::create($form->embed->value);
$content .= $this->prepareEmbed($embed);
$p->setLink($form->embed->value);
if($embed->type == 'photo') {
$key = key($embed->images);
$p->setImage($embed->images[0]['value'], $embed->title, $embed->images[0]['mime']);
}
}
$p->setContentHtml(rawurldecode($content))
->request();
} else {
Notification::append(false, $this->__('publish.no_content'));
}
}
function ajaxEmbedTest($url)
{
if($url == '') {
return;
} elseif(!filter_var($url, FILTER_VALIDATE_URL)) {
Notification::append(false, $this->__('publish.valid_url'));
return;
}
$embed = Embed\Embed::create($url);
$html = $this->prepareEmbed($embed);
if($embed->type == 'photo') {
RPC::call('movim_fill', 'gallery', $this->prepareGallery($embed));
}
RPC::call('movim_fill', 'preview', $html);
}
function prepareEmbed($embed)
{
$view = $this->tpl();
$view->assign('embed', $embed);
return $view->draw('_publish_embed', true);
}
function prepareGallery($embed)
{
$view = $this->tpl();
$view->assign('embed', $embed);
return $view->draw('_publish_gallery', true);
}
private function validateServerNode($server, $node)
{
$validate_server = Validator::string()->noWhitespace()->length(6, 40);
$validate_node = Validator::string()->length(3, 100);
if(!$validate_server->validate($server)
|| !$validate_node->validate($node)
) return false;
else return true;
}
function display()
{
}
}

54
app/widgets/Publish/_publish_create.tpl

@ -0,0 +1,54 @@
<form name="post" class="padded_top_bottom">
<input type="hidden" name="to" value="{$to}">
<input type="hidden" name="node" value="{$node}">
<div>
<input type="text" name="title" placeholder="{$c->__('post.title')}">
<label for="title">{$c->__('post.title')}</label>
</div>
<div>
<textarea name="content" placeholder="{$c->__('post.content')}" onkeyup="movim_textarea_autoheight(this);"></textarea>
<label for="content">{$c->__('post.content')}</label>
</div>
<div>
<input
type="url"
name="embed"
placeholder="http://myawesomewebsite.com/ or http://mynicepictureurl.com/"
onPaste="var e=this; setTimeout(function(){Publish_ajaxEmbedTest(e.value);}, 4);"
>
<label for="embed">{$c->__('post.link')}</label>
<article>
<section>
<content id="preview"></content>
</section>
</article>
<div id="gallery"></div>
</div>
<ul class="middle flex active">
<li class="subheader">{$c->__('post.embed_tip')}</li>
<a class="block" target="_blank" href="http://imgur.com/">
<li class="block action">
<div class="action">
<i class="md md-chevron-right"></i>
</div>
<span class="bubble icon">
<img src="https://userecho.com/s/logos/2015/2015.png">
</span>
Imgur
</li>
</a>
<a class="block" target="_blank" href="https://www.flickr.com/">
<li class="action">
<div class="action">
<i class="md md-chevron-right"></i>
</div>
<span class="bubble icon">
<img src="https://www.flickr.com/apple-touch-icon.png">
</span>
Flickr
</li>
</a>
</ul>
</form>

0
app/widgets/Post/_post_embed.tpl → app/widgets/Publish/_publish_embed.tpl

0
app/widgets/Post/_post_gallery.tpl → app/widgets/Publish/_publish_gallery.tpl

45
app/widgets/Publish/_publish_header.tpl

@ -0,0 +1,45 @@
<div>
<span class="on_desktop icon"><i class="md md-create"></i></span>
<h2>{$c->__('publish.title')}</h2>
</div>
<div>
<div class="return active r3 condensed"
onclick="
if(typeof Post_ajaxClear === 'function') {
Post_ajaxClear();
Header_ajaxReset('news');
} else {
Group_ajaxGetItems('{$server}', '{$node}');
}">
<span id="back" class="icon" ><i class="md md-arrow-back"></i></span>
<h2>{$c->__('publish.new')}</h2>
<h4>
{if="$item != null"}
{if="$item->name"}
{$item->name}
{else}
{$item->node}
{/if}
{else}
{$c->__('page.blog')}
{/if}
</h4>
</div>
<ul class="active">
<li onclick="Publish_ajaxHelp()">
<span class="icon">
<i class="md md-help"></i>
</span>
</li>
<li onclick="Publish_ajaxPreview(movim_form_to_json('post'))">
<span class="icon">
<i class="md md-remove-red-eye"></i>
</span>
</li>
<li onclick="Publish_ajaxPublish(movim_form_to_json('post'))">
<span class="icon">
<i class="md md-send"></i>
</span>
</li>
</ul>
</div>

0
app/widgets/Post/_post_help.tpl → app/widgets/Publish/_publish_help.tpl

0
app/widgets/Post/_post_preview.tpl → app/widgets/Publish/_publish_preview.tpl

20
app/widgets/Publish/locales.ini

@ -0,0 +1,20 @@
post.news_feed = 'News Feed'
post.placeholder = 'Discover and register to the groups you are interested in'
post.preview = 'Preview'
post.help = 'Help'
post.help_more = 'More help'
post.help_manual = 'Markdown syntax manual'
post.title = 'Title'
post.content = 'Content'
post.link = 'Link'
post.tags = 'Tags'
publish.valid_url = 'Please enter a valid url'
publish.no_content_preview = 'No content to preview'
publish.no_content = 'No content'
post.published = 'Post published'
post.deleted = 'Post deleted'
post.gallery = 'This picture will be added to your gallery'
post.hot = "What's Hot"
publish.new = 'New post'
publish.title = 'Publish'
post.embed_tip = 'You can also use services like Imgur or Flickr to host your picture and paste the link here.'

21
app/widgets/Publish/publish.js

@ -0,0 +1,21 @@
var Publish = {
init: function() {
if(localStorage.getItem('share_url')) {
Publish_ajaxCreateBlog();
MovimTpl.showPanel();
}
},
setEmbed: function() {
if(localStorage.getItem('share_url')) {
var embed = document.querySelector('input[name=embed]');
embed.value = localStorage.getItem('share_url');
embed.onpaste();
localStorage.removeItem('share_url');
}
}
}
MovimWebsocket.attach(function() {
Publish.init();
});

0
app/widgets/Publish/publish.tpl

14
app/widgets/Rooms/_rooms_list.tpl

@ -4,7 +4,11 @@
<ul>
{$presence = getPresencesTxt()}
{loop="$list"}
<li class="action {if="$value->status"}condensed{/if}" title="{$value->resource}">
<li class="
action
{if="$value->last > 60"} inactive{/if}
{if="$value->status"}condensed{/if}"
title="{$value->resource}">
{$url = $value->getPhoto('s')}
{if="$url"}
<span class="icon bubble status {$presence[$value->value]}">
@ -20,7 +24,13 @@
<i class="md md-beenhere"></i>
</div>
{/if}
<span>{$value->resource}</span>
{if="$value->mucjid && strpos($value->mucjid, '/') == false"}
<a href="{$c->route('contact', $value->mucjid)}">
<span>{$value->resource}</span>
</a>
{else}
<span>{$value->resource}</span>
{/if}
{if="$value->status"}
<p class="wrap">{$value->status}</p>
{/if}

35
linker.php

@ -69,6 +69,11 @@ $stdin_behaviour = function ($data) use (/*&*/&$conn, $loop, &$buffer, &$connect
$msg = json_encode(\RPC::commit());
\RPC::clear();
if(!empty($msg)) {
echo base64_encode(gzcompress($msg, 9))."";
#fwrite(STDERR, colorize($msg, 'yellow')." : ".colorize('sent to the browser', 'green')."\n");
}
$xml = \Moxl\API::commit();
\Moxl\API::clear();
@ -77,11 +82,6 @@ $stdin_behaviour = function ($data) use (/*&*/&$conn, $loop, &$buffer, &$connect
$conn->send(trim($xml));
#fwrite(STDERR, colorize(trim($xml), 'yellow')." : ".colorize('sent to XMPP', 'green')."\n");
}
if(!empty($msg)) {
echo base64_encode(gzcompress($msg, 9))."";
#fwrite(STDERR, colorize($msg, 'yellow')." : ".colorize('sent to the browser', 'green')."\n");
}
}
//if(isset($conn)) $conn->resume();
@ -99,7 +99,7 @@ $xmpp_behaviour = function (Ratchet\Client\WebSocket $stream) use (&$conn, $loop
$stdin->removeAllListeners('data');
$stdin->on('data', $stdin_behaviour);
//$conn->bufferSize = 4096*4;
$conn->bufferSize = 4096*4;
$conn->on('message', function($message) use (&$conn, $loop, $parser/*, $stream*/) {
//$conn->pause();
@ -125,6 +125,7 @@ $xmpp_behaviour = function (Ratchet\Client\WebSocket $stream) use (&$conn, $loop
if(!$parser->parse($message)) {
fwrite(STDERR, colorize(getenv('sid'), 'yellow')." ".$parser->getError()."\n");
}
//\Moxl\Xec\Handler::handleStanza($message);
if($restart) {
@ -133,14 +134,6 @@ $xmpp_behaviour = function (Ratchet\Client\WebSocket $stream) use (&$conn, $loop
$restart = false;
}
$msg = \RPC::commit();
\RPC::clear();
if(!empty($msg)) {
echo base64_encode(gzcompress(json_encode($msg), 9))."";
#fwrite(STDERR, colorize($msg.' '.strlen($msg), 'yellow')." : ".colorize('sent to browser', 'green')."\n");
}
$xml = \Moxl\API::commit();
\Moxl\API::clear();
@ -150,19 +143,27 @@ $xmpp_behaviour = function (Ratchet\Client\WebSocket $stream) use (&$conn, $loop
#fwrite(STDERR, colorize(trim($xml), 'yellow')." : ".colorize('sent to XMPP', 'green')."\n");
}
$loop->tick();
$msg = \RPC::commit();
\RPC::clear();
if(!empty($msg)) {
echo base64_encode(gzcompress(json_encode($msg), 9))."";
#fwrite(STDERR, colorize($msg.' '.strlen($msg), 'yellow')." : ".colorize('sent to browser', 'green')."\n");
}
//$loop->tick();
}
//$conn->resume();
});
$conn->on('error', function($msg) use ($conn, $loop) {
fwrite(STDERR, colorize($msg, 'red')." : ".colorize('error', 'green')."\n");
#fwrite(STDERR, colorize(serialize($msg), 'red')." : ".colorize('error', 'green')."\n");
$loop->stop();
});
$conn->on('close', function($msg) use ($conn, $loop) {
fwrite(STDERR, colorize($msg, 'red')." : ".colorize('closed', 'green')."\n");
#fwrite(STDERR, colorize(serialize($msg), 'red')." : ".colorize('closed', 'green')."\n");
$loop->stop();
});

Loading…
Cancel
Save