Browse Source

Introducting Briefs and implement a simple PublishBrief widget

Improve Posts/Briefs cards
Move the Posts/Briefs deletions actions to PostActions
pull/392/head
Timothée Jaussoin 9 years ago
parent
commit
512fe3e276
  1. 5
      app/models/postn/Postn.php
  2. 5
      app/views/news.tpl
  3. 2
      app/views/post.tpl
  4. 12
      app/widgets/Menu/_menu_list.tpl
  5. 46
      app/widgets/Post/Post.php
  6. 4
      app/widgets/Post/_post.tpl
  7. 61
      app/widgets/Post/_post_card.tpl
  8. 61
      app/widgets/PostActions/PostActions.php
  9. 2
      app/widgets/PostActions/_postactions_delete.tpl
  10. 0
      app/widgets/PostActions/postactions.tpl
  11. 30
      app/widgets/Presence/_presence.tpl
  12. 18
      app/widgets/Presence/presence.tpl
  13. 7
      app/widgets/Publish/Publish.php
  14. 0
      app/widgets/PublishBrief/Document sans nom
  15. 41
      app/widgets/PublishBrief/PublishBrief.php
  16. 3
      app/widgets/PublishBrief/locales.ini
  17. 3
      app/widgets/PublishBrief/publishbrief.css
  18. 10
      app/widgets/PublishBrief/publishbrief.js
  19. 41
      app/widgets/PublishBrief/publishbrief.tpl
  20. 6
      src/Movim/Bootstrap.php
  21. 4
      themes/material/css/color.css
  22. 8
      themes/material/css/listn.css

5
app/models/postn/Postn.php

@ -479,6 +479,11 @@ class Postn extends Model
return (strlen($this->contentcleaned) < 700);
}
public function isBrief()
{
return ($this->content == '');
}
public function isNSFW()
{
return (current(explode('.', $this->origin)) == 'nsfw');

5
app/views/news.tpl

@ -5,6 +5,8 @@
<?php $this->widget('Search');?>
<?php $this->widget('Onboarding');?>
<?php $this->widget('PostActions');?>
<nav class="color dark">
<?php $this->widget('Presence');?>
<?php $this->widget('Navigation');?>
@ -16,6 +18,9 @@
<?php $this->widget('Notifs');?>
<?php $this->widget('NewsNav');?>
</aside>
<div>
<?php $this->widget('PublishBrief');?>
<?php $this->widget('Menu');?>
</div>
</section>
</main>

2
app/views/post.tpl

@ -4,6 +4,8 @@
<?php $this->widget('Upload');?>
<?php $this->widget('Search');?>
<?php $this->widget('PostActions');?>
<nav class="color dark">
<?php $this->widget('Presence');?>
<?php $this->widget('Navigation');?>

12
app/widgets/Menu/_menu_list.tpl

@ -1,17 +1,5 @@
{if="$page == 0"}
<header>
<ul class="list middle list card shadow active">
<br />
<li class="block">
<span id="menu" class="primary on_mobile icon active gray" onclick="MovimTpl.toggleMenu()">
<i class="zmdi zmdi-menu"></i>
</span>
<span class="primary on_desktop icon gray">
<i class="zmdi zmdi-edit"></i>
</span>
<p onclick="MovimUtils.redirect('{$c->route('publish')}')" class="normal">{$c->__('menu.add_post')}</p>
</li>
</ul>
<ul class="tabs wide">
<li {if="$type == 'all'"}class="active"{/if}>
<a href="#" onclick="Menu_ajaxGetAll()">{$c->__('menu.all')}</a>

46
app/widgets/Post/Post.php

@ -1,8 +1,6 @@
<?php
use Moxl\Xec\Action\Pubsub\PostPublish;
use Moxl\Xec\Action\Pubsub\PostDelete;
use Moxl\Xec\Action\Pubsub\Delete;
use Moxl\Xec\Action\Pubsub\GetItem;
use Moxl\Xec\Action\Microblog\CommentsGet;
use Moxl\Xec\Action\Microblog\CommentPublish;
@ -17,8 +15,6 @@ class Post extends \Movim\Widget\Base
$this->registerEvent('microblog_commentsget_handle', 'onComments');
$this->registerEvent('microblog_commentpublish_handle', 'onCommentPublished');
$this->registerEvent('microblog_commentsget_error', 'onCommentsError');
$this->registerEvent('pubsub_postdelete_handle', 'onDelete');
$this->registerEvent('pubsub_postdelete', 'onDelete');
$this->registerEvent('pubsub_getitem_handle', 'onHandle');
}
@ -47,24 +43,6 @@ class Post extends \Movim\Widget\Base
$this->onComments($packet);
}
function onDelete($packet)
{
list($server, $node, $id) = array_values($packet->content);
if(substr($node, 0, 29) == 'urn:xmpp:microblog:0:comments') {
Notification::append(false, $this->__('post.comment_deleted'));
$this->ajaxGetComments($server, substr($node, 30));
} else {
Notification::append(false, $this->__('post.deleted'));
if($node == 'urn:xmpp:microblog:0') {
$this->rpc('MovimUtils.redirect', $this->route('news'));
} else {
$this->rpc('MovimUtils.redirect', $this->route('community', [$server, $node]));
}
}
}
function onComments($packet)
{
list($server, $node, $id) = array_values($packet->content);
@ -145,17 +123,6 @@ class Post extends \Movim\Widget\Base
}
}
function ajaxDelete($to, $node, $id)
{
$view = $this->tpl();
$view->assign('to', $to);
$view->assign('node', $node);
$view->assign('id', $id);
Dialog::fill($view->draw('_post_delete', true));
}
function ajaxShare($origin, $node, $id)
{
$pd = new \Modl\PostnDAO;
@ -166,19 +133,6 @@ class Post extends \Movim\Widget\Base
}
}
function ajaxDeleteConfirm($to, $node, $id) {
$p = new PostDelete;
$p->setTo($to)
->setNode($node)
->setId($id)
->request();
$p = new Delete;
$p->setTo($to)
->setNode('urn:xmpp:microblog:0:comments/'.$id)
->request();
}
function ajaxGetComments($jid, $id)
{
$pd = new \Modl\PostnDAO();

4
app/widgets/Post/_post.tpl

@ -27,7 +27,9 @@
<i class="zmdi zmdi-edit"></i>
</span>
{/if}
<span class="control icon active gray" onclick="Post_ajaxDelete('{$post->origin}', '{$post->node}', '{$post->nodeid}')" title="{$c->__('button.delete')}">
<span class="control icon active gray"
onclick="PostActions_ajaxDelete('{$post->origin}', '{$post->node}', '{$post->nodeid}')"
title="{$c->__('button.delete')}">
<i class="zmdi zmdi-delete"></i>
</span>
{/if}

61
app/widgets/Post/_post_card.tpl

@ -26,7 +26,13 @@
</span>
{/if}
<p class="normal">{$post->title}</p>
{if="!$post->isBrief()"}
<p class="normal">
{$post->title}
</p>
{else}
<p></p>
{/if}
<p>
{if="$post->isMicroblog()"}
<a href="{$c->route('contact', $post->getContact()->jid)}">
@ -45,12 +51,16 @@
– <i class="zmdi zmdi-edit"></i> {$post->updated|strtotime|prepareDate:true,true}
{/if}
</p>
{if="$post->isBrief()"}
<p class="normal">
{$post->title|addUrls}
</p>
{/if}
</li>
</ul>
<ul class="list">
{if="!$post->isBrief()"}
<li class="active">
<p>
</p>
<p>
<section {if="!$post->isShort()"}class="limited"{/if}>
{if="$post->isReply()"}
@ -64,6 +74,17 @@
style="background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0.3) 100%), url({$reply->picture});">
<i class="zmdi zmdi-mail-reply"></i>
</span>
{elseif="$reply->isMicroblog()"}
{$url = $reply->getContact()->getPhoto('l')}
{if="$url"}
<span class="primary icon thumb color white" style="background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0.3) 100%), url({$url});">
<i class="zmdi zmdi-mail-reply"></i>
</span>
{else}
<span class="primary icon thumb color {$reply->getContact()->jid|stringToColor}">
<i class="zmdi zmdi-mail-reply"></i>
</span>
{/if}
{/if}
<p class="line">{$reply->title}</p>
<p>{$reply->contentcleaned|html_entity_decode|stripTags}</p>
@ -110,25 +131,28 @@
<section>
</p>
</li>
{/if}
<li>
<p class="normal center">
<a class="button flat" href="{$c->route('post', [$post->origin, $post->node, $post->nodeid])}">
<i class="zmdi zmdi-plus"></i> {$c->__('post.more')}
</a>
</p>
<p class="normal">
<a class="button flat gray" href="{$c->route('post', [$post->origin, $post->node, $post->nodeid])}">
{$post->countLikes()} <i class="zmdi zmdi-favorite-outline"></i>
</a>
<a class="button flat gray" href="{$c->route('post', [$post->origin, $post->node, $post->nodeid])}">
{$post->countComments()} <i class="zmdi zmdi-comment-outline"></i>
</a>
{if="!$post->isBrief()"}
<a class="button flat oppose" href="{$c->route('post', [$post->origin, $post->node, $post->nodeid])}">
<i class="zmdi zmdi-plus"></i> {$c->__('post.more')}
</a>
{/if}
{if="!$post->isBrief()"}
<a class="button flat gray" href="{$c->route('post', [$post->origin, $post->node, $post->nodeid])}">
{$post->countLikes()} <i class="zmdi zmdi-favorite-outline"></i>
</a>
<a class="button flat gray" href="{$c->route('post', [$post->origin, $post->node, $post->nodeid])}">
{$post->countComments()} <i class="zmdi zmdi-comment-outline"></i>
</a>
{/if}
<a class="button flat gray" href="{$c->route('publish', [$post->origin, $post->node, $post->nodeid, 'share'])}">
<i class="zmdi zmdi-share"></i>
<i class="zmdi zmdi-mail-reply"></i>
</a>
{if="$post->isPublic()"}
<a class="button flat gray" target="_blank" href="{$post->getPublicUrl()}">
<a class="button flat gray on_desktop" target="_blank" href="{$post->getPublicUrl()}">
<i title="{$c->__('menu.public')}" class="zmdi zmdi-portable-wifi"></i>
</a>
{/if}
@ -141,9 +165,10 @@
<i class="zmdi zmdi-edit"></i>
</a>
{/if}
<a class="button flat gray oppose"
<a class="button flat oppose gray"
href="#"
onclick="Post_ajaxDelete('{$post->origin}', '{$post->node}', '{$post->nodeid}')"
onclick="PostActions_ajaxDelete('{$post->origin}', '{$post->node}', '{$post->nodeid}')"
title="{$c->__('button.delete')}">
<i class="zmdi zmdi-delete"></i>
</a>

61
app/widgets/PostActions/PostActions.php

@ -0,0 +1,61 @@
<?php
use Moxl\Xec\Action\Pubsub\PostDelete;
use Moxl\Xec\Action\Pubsub\Delete;
class PostActions extends \Movim\Widget\Base
{
function load()
{
$this->registerEvent('pubsub_postdelete_handle', 'onDelete');
$this->registerEvent('pubsub_postdelete', 'onDelete');
}
function onDelete($packet)
{
list($server, $node, $id) = array_values($packet->content);
if(substr($node, 0, 29) == 'urn:xmpp:microblog:0:comments') {
Notification::append(false, $this->__('post.comment_deleted'));
$this->ajaxGetComments($server, substr($node, 30));
} else {
Notification::append(false, $this->__('post.deleted'));
if($node == 'urn:xmpp:microblog:0') {
$this->rpc('MovimUtils.redirect', $this->route('news'));
} else {
$this->rpc('MovimUtils.redirect', $this->route('community', [$server, $node]));
}
}
}
function ajaxDelete($to, $node, $id)
{
$view = $this->tpl();
$view->assign('to', $to);
$view->assign('node', $node);
$view->assign('id', $id);
Dialog::fill($view->draw('_postactions_delete', true));
}
function ajaxDeleteConfirm($to, $node, $id)
{
$p = new PostDelete;
$p->setTo($to)
->setNode($node)
->setId($id)
->request();
$p = new Delete;
$p->setTo($to)
->setNode('urn:xmpp:microblog:0:comments/'.$id)
->request();
}
function display()
{
}
}

2
app/widgets/Post/_post_delete.tpl → app/widgets/PostActions/_postactions_delete.tpl

@ -10,7 +10,7 @@
<button
name="submit"
class="button flat"
onclick="Post_ajaxDeleteConfirm('{$to}', '{$node}', '{$id}'); Dialog_ajaxClear()">
onclick="PostActions_ajaxDeleteConfirm('{$to}', '{$node}', '{$id}'); Dialog_ajaxClear()">
{$c->__('button.delete')}
</button>
</div>

0
app/widgets/PostActions/postactions.tpl

30
app/widgets/Presence/_presence.tpl

@ -1,15 +1,17 @@
<li>
{$url = $me->getPhoto('s')}
{if="$url"}
<span
class="primary icon bubble status {if="$presence->value != null"}{$presencetxt[$presence->value]}{/if}"
style="background-image: url({$me->getPhoto('s')})">
</span>
{else}
<span class="primary icon bubble color {$me->jid|stringToColor} status {if="$presence->value != null"}{$presencetxt[$presence->value]}{/if}">
<i class="zmdi zmdi-account"></i>
</span>
{/if}
<a href="{$c->route('contact', $me->jid)}">
<li>
{$url = $me->getPhoto('s')}
{if="$url"}
<span
class="primary icon bubble status {if="$presence->value != null"}{$presencetxt[$presence->value]}{/if}"
style="background-image: url({$me->getPhoto('s')})">
</span>
{else}
<span class="primary icon bubble color {$me->jid|stringToColor} status {if="$presence->value != null"}{$presencetxt[$presence->value]}{/if}">
<i class="zmdi zmdi-account"></i>
</span>
{/if}
<p class="line bold normal">{$me->getTrueName()}</p>
</li>
<p class="line bold normal">{$me->getTrueName()}</p>
</li>
</a>

18
app/widgets/Presence/presence.tpl

@ -1,11 +1,9 @@
<ul class="list active thick" dir="ltr">
<a href="{$c->route('conf')}" id="presence_widget">
<li>
<span class="primary icon bubble color status">
<i class="zmdi zmdi-account"></i>
</span>
<p class="line bold"><br /></p>
<p class="line"><br /></p>
</li>
</a>
<ul class="list active thick" id="presence_widget" dir="ltr">
<li>
<span class="primary icon bubble color status">
<i class="zmdi zmdi-account"></i>
</span>
<p class="line bold"><br /></p>
<p class="line"><br /></p>
</li>
</ul>

7
app/widgets/Publish/Publish.php

@ -24,9 +24,9 @@ class Publish extends \Movim\Widget\Base
{
Notification::append(false, $this->__('post.published'));
list($to, $node, $id, $repost) = array_values($packet->content);
list($to, $node, $id, $repost, $comments) = array_values($packet->content);
if(!$repost) {
if(!$repost && $comments) {
$this->ajaxCreateComments($to, $id);
}
@ -220,8 +220,6 @@ class Publish extends \Movim\Widget\Base
->setNode($form->node->value);
//->setLocation($geo)
$p->enableComments();
$content = $content_xhtml = '';
if(Validator::stringType()->notEmpty()->validate(trim($form->content->value))) {
@ -278,6 +276,7 @@ class Publish extends \Movim\Widget\Base
}
if($content != '') {
$p->enableComments();
$p->setContent(htmlspecialchars($content));
}

0
app/widgets/PublishBrief/Document sans nom

41
app/widgets/PublishBrief/PublishBrief.php

@ -0,0 +1,41 @@
<?php
use Moxl\Xec\Action\Pubsub\PostPublish;
use Movim\Session;
use Respect\Validation\Validator;
class PublishBrief extends \Movim\Widget\Base
{
function load()
{
$this->addjs('publishbrief.js');
$this->addcss('publishbrief.css');
}
function ajaxPublish($form)
{
$this->rpc('PublishBrief.disableSend');
if(Validator::stringType()->notEmpty()->validate(trim($form->title->value))) {
$p = new PostPublish;
$p->setFrom($this->user->getLogin())
->setTo($this->user->getLogin())
->setTitle(htmlspecialchars($form->title->value))
->setNode('urn:xmpp:microblog:0');
if($form->open->value === true) {
$p->isOpen();
}
$p->request();
} else {
$this->rpc('PublishBrief.enableSend');
}
}
function display()
{
}
}

3
app/widgets/PublishBrief/locales.ini

@ -0,0 +1,3 @@
[publishbrief]
placeholder = "What's new?"
post = Write a post

3
app/widgets/PublishBrief/publishbrief.css

@ -0,0 +1,3 @@
header#publishbrief form > div textarea {
padding-top: 1rem;
}

10
app/widgets/PublishBrief/publishbrief.js

@ -0,0 +1,10 @@
var Publish = {
enableSend: function() {
MovimUtils.removeClass('#button_send', 'disabled');
},
disableSend: function() {
MovimUtils.addClass('#button_send', 'disabled');
}
}

41
app/widgets/PublishBrief/publishbrief.tpl

@ -0,0 +1,41 @@
<header id="publishbrief" class="card shadow">
<ul class="block list">
<li>
<span id="menu" class="primary on_mobile icon bubble active gray" onclick="MovimTpl.toggleMenu()">
<i class="zmdi zmdi-menu"></i>
</span>
<span class="primary on_desktop icon bubble gray">
<i class="zmdi zmdi-edit"></i>
</span>
<span class="control icon gray active" onclick="PublishBrief_ajaxPublish(MovimUtils.formToJson('brief'));">
<i class="zmdi zmdi-mail-send"></i>
</span>
<form onsubmit="return false;" name="brief">
<div>
<textarea
name="title"
id="title"
rows="1"
onkeyup="MovimUtils.textareaAutoheight(this);"
placeholder="{$c->__('publishbrief.placeholder')}"
type="text"></textarea>
</div>
</form>
</li>
<li>
<span class="primary"></span>
<p class="normal">
<a class="button flat gray disabled" href="#">
<i class="zmdi zmdi-image"></i>
</a>
<a class="button flat gray disabled" href="#">
<i class="zmdi zmdi-link"></i>
</a>
<a class="button flat gray oppose" href="{$c->route('publish')}">
{$c->__('publishbrief.post')} <i class="zmdi zmdi-format-align-left"></i>
</a>
</p>
</li>
</ul>
</header>

6
src/Movim/Bootstrap.php

@ -337,9 +337,9 @@ class Bootstrap
'Communities','CommunityAffiliations','CommunityConfig','CommunityData',
'CommunityHeader','CommunityPosts','CommunitiesServer','Chat','Chats',
'Config','Contact','Dialog','Drawer','Header','Init','Login',
'LoginAnonymous','Menu','Notifs','Invitations','Post','Presence',
'Publish','Rooms','Roster','Stickers','Upload','Vcard4', 'Visio',
'VisioLink'];
'LoginAnonymous','Menu','Notifs','Invitations','Post','PostActions',
'Presence','Publish','Rooms','Roster','Stickers','Upload','Vcard4',
'Visio','VisioLink'];
}
/**

4
themes/material/css/color.css

@ -87,8 +87,8 @@ form textarea:focus:invalid + label {
color: #F44336;
}
ul.list li > p:nth-last-of-type(3) + p,
ul.list li > p:nth-last-of-type(2) + p {
ul.list li > p:nth-last-of-type(3) + p:not(.normal),
ul.list li > p:nth-last-of-type(2) + p:not(.normal) {
color: rgba(0, 0, 0, 0.60);
}

8
themes/material/css/listn.css

@ -132,6 +132,10 @@ ul.list li > p.normal {
font-size: 2rem;
}
ul.list li > p:nth-last-of-type(2) + p.normal {
margin-top: 1rem;
}
ul.list li > p.bold {
font-weight: bold;
}
@ -146,8 +150,8 @@ ul.list li > p:nth-last-of-type(2) {
font-size: 2rem;
}
ul.list li > p:nth-last-of-type(3) + p,
ul.list li > p:nth-last-of-type(2) + p {
ul.list li > p:nth-last-of-type(3) + p:not(.normal),
ul.list li > p:nth-last-of-type(2) + p:not(.normal) {
line-height: 2.5rem;
font-size: 1.75rem;
max-height: 7.5rem;

Loading…
Cancel
Save