2015-08-03 11:35:01 +02:00
|
|
|
<?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\Pubsub\PostDelete;
|
2015-12-15 11:54:49 +01:00
|
|
|
use Moxl\Xec\Action\Pubsub\GetItem;
|
2015-08-03 11:35:01 +02:00
|
|
|
use Moxl\Xec\Action\Microblog\CommentsGet;
|
|
|
|
use Moxl\Xec\Action\Microblog\CommentCreateNode;
|
|
|
|
use Moxl\Xec\Action\Microblog\CommentPublish;
|
|
|
|
use \Michelf\Markdown;
|
|
|
|
use Respect\Validation\Validator;
|
|
|
|
|
|
|
|
class Post extends WidgetBase
|
|
|
|
{
|
|
|
|
function load()
|
|
|
|
{
|
|
|
|
$this->addjs('post.js');
|
|
|
|
$this->registerEvent('microblog_commentsget_handle', 'onComments');
|
|
|
|
$this->registerEvent('microblog_commentpublish_handle', 'onCommentPublished');
|
|
|
|
$this->registerEvent('microblog_commentsget_error', 'onCommentsError');
|
|
|
|
$this->registerEvent('pubsub_postpublish_handle', 'onPublish');
|
|
|
|
$this->registerEvent('pubsub_postdelete_handle', 'onDelete');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onPublish($packet)
|
|
|
|
{
|
|
|
|
Notification::append(false, $this->__('post.published'));
|
|
|
|
$this->ajaxClear();
|
|
|
|
RPC::call('MovimTpl.hidePanel');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onCommentPublished($packet)
|
|
|
|
{
|
|
|
|
Notification::append(false, $this->__('post.comment_published'));
|
|
|
|
$this->onComments($packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDelete()
|
|
|
|
{
|
|
|
|
Notification::append(false, $this->__('post.deleted'));
|
|
|
|
$this->ajaxClear();
|
|
|
|
RPC::call('MovimTpl.hidePanel');
|
|
|
|
RPC::call('Menu_ajaxGetAll');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onComments($packet)
|
|
|
|
{
|
|
|
|
list($server, $node, $id) = array_values($packet->content);
|
|
|
|
|
|
|
|
$p = new \Modl\ContactPostn();
|
|
|
|
$p->nodeid = $id;
|
|
|
|
|
|
|
|
$pd = new \Modl\PostnDAO();
|
|
|
|
$comments = $pd->getComments($p);
|
|
|
|
|
|
|
|
$view = $this->tpl();
|
|
|
|
$view->assign('comments', $comments);
|
|
|
|
$view->assign('server', $server);
|
|
|
|
$view->assign('node', $node);
|
|
|
|
$view->assign('id', $id);
|
|
|
|
|
|
|
|
$html = $view->draw('_post_comments', true);
|
|
|
|
RPC::call('movim_fill', 'comments', $html);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onCommentsError($packet)
|
|
|
|
{
|
|
|
|
$view = $this->tpl();
|
|
|
|
$html = $view->draw('_post_comments_error', true);
|
|
|
|
RPC::call('movim_fill', 'comments', $html);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ajaxClear()
|
|
|
|
{
|
|
|
|
RPC::call('movim_fill', 'post_widget', $this->prepareEmpty());
|
|
|
|
RPC::call('Menu.refresh');
|
|
|
|
//RPC::call('Menu_ajaxGetAll');
|
|
|
|
}
|
|
|
|
|
|
|
|
function ajaxGetPost($id)
|
|
|
|
{
|
2015-12-15 11:54:49 +01:00
|
|
|
$pd = new \Modl\PostnDAO;
|
|
|
|
$p = $pd->getItem($id);
|
|
|
|
|
|
|
|
$gi = new GetItem;
|
|
|
|
$gi->setTo($p->origin)
|
|
|
|
->setNode($p->node)
|
|
|
|
->setId($p->nodeid)
|
|
|
|
->request();
|
|
|
|
|
|
|
|
$html = $this->preparePost($p);
|
2015-08-03 11:35:01 +02:00
|
|
|
|
|
|
|
RPC::call('movim_fill', 'post_widget', $html);
|
2015-12-21 22:59:03 +01:00
|
|
|
RPC::call('MovimTpl.scrollHeaders');
|
2015-08-03 11:35:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 ajaxDeleteConfirm($to, $node, $id) {
|
|
|
|
$p = new PostDelete;
|
|
|
|
$p->setTo($to)
|
|
|
|
->setNode($node)
|
|
|
|
->setId($id)
|
|
|
|
->request();
|
|
|
|
}
|
|
|
|
|
|
|
|
function ajaxGetComments($jid, $id)
|
|
|
|
{
|
|
|
|
$pd = new \Modl\PostnDAO();
|
|
|
|
$pd->deleteNode($jid, "urn:xmpp:microblog:0:comments/".$id);
|
|
|
|
|
|
|
|
$c = new CommentsGet;
|
|
|
|
$c->setTo($jid)
|
|
|
|
->setId($id)
|
|
|
|
->request();
|
|
|
|
}
|
|
|
|
|
|
|
|
function ajaxPublishComment($form, $to, $node, $id)
|
|
|
|
{
|
|
|
|
$comment = trim($form->comment->value);
|
|
|
|
|
2015-12-15 11:54:49 +01:00
|
|
|
$validate_comment = Validator::stringType()->notEmpty();
|
|
|
|
$validate_id = Validator::stringType()->length(6, 128)->noWhitespace();
|
2015-08-03 11:35:01 +02:00
|
|
|
|
|
|
|
if(!$validate_comment->validate($comment)
|
|
|
|
|| !$validate_id->validate($id)) return;
|
|
|
|
|
|
|
|
$cp = new CommentPublish;
|
|
|
|
$cp->setTo($to)
|
|
|
|
->setFrom($this->user->getLogin())
|
|
|
|
->setParentId($id)
|
|
|
|
->setContent(htmlspecialchars(rawurldecode($comment)))
|
|
|
|
->request();
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareEmpty()
|
|
|
|
{
|
|
|
|
$view = $this->tpl();
|
|
|
|
|
|
|
|
$nd = new \modl\PostnDAO();
|
|
|
|
$view = $this->tpl();
|
2015-08-19 11:28:28 +02:00
|
|
|
$view->assign('posts', $nd->getLastPublished(0, 10));
|
2015-08-03 11:35:01 +02:00
|
|
|
|
|
|
|
return $view->draw('_post_empty', true);
|
|
|
|
}
|
|
|
|
|
2015-12-15 11:54:49 +01:00
|
|
|
function preparePost($p, $external = false, $public = false)
|
2015-08-03 11:35:01 +02:00
|
|
|
{
|
|
|
|
$view = $this->tpl();
|
|
|
|
|
|
|
|
if(isset($p)) {
|
2015-12-15 11:54:49 +01:00
|
|
|
if(isset($p->commentplace) && !$external) {
|
2015-08-03 11:35:01 +02:00
|
|
|
$this->ajaxGetComments($p->commentplace, $p->nodeid);
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->assign('recycled', false);
|
2015-12-15 11:54:49 +01:00
|
|
|
$view->assign('external', $external);
|
|
|
|
$view->assign('public', $public);
|
2015-08-03 11:35:01 +02:00
|
|
|
|
|
|
|
// Is it a recycled post ?
|
|
|
|
if($p->getContact()->jid
|
|
|
|
&& $p->node == 'urn:xmpp:microblog:0'
|
|
|
|
&& ($p->origin != $p->getContact()->jid)) {
|
|
|
|
$cd = new \Modl\ContactDAO;
|
|
|
|
$view->assign('recycled', $cd->get($p->origin));
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->assign('post', $p);
|
|
|
|
$view->assign('attachements', $p->getAttachements());
|
|
|
|
return $view->draw('_post', true);
|
2015-12-15 11:54:49 +01:00
|
|
|
} elseif(!$external) {
|
2015-08-03 11:35:01 +02:00
|
|
|
return $this->prepareEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ajaxTogglePrivacy($id) {
|
2015-12-15 11:54:49 +01:00
|
|
|
$validate = Validator::stringType()->length(6, 128);
|
2015-08-03 11:35:01 +02:00
|
|
|
|
|
|
|
if(!$validate->validate($id))
|
|
|
|
return;
|
|
|
|
|
|
|
|
$pd = new \Modl\PrivacyDAO();
|
|
|
|
$p = $pd->get($id);
|
|
|
|
|
|
|
|
$pd = new \Modl\PostnDAO;
|
|
|
|
$po = $pd->getItem($id);
|
|
|
|
|
2015-08-19 11:28:28 +02:00
|
|
|
if($po->isMine()) {
|
|
|
|
if($po->privacy == 1) {
|
2015-11-13 13:37:39 +01:00
|
|
|
Notification::append(false, $this->__('post.public_no'));
|
2015-08-19 11:28:28 +02:00
|
|
|
\Modl\Privacy::set($id, 0);
|
|
|
|
}
|
|
|
|
if($po->privacy == 0) {
|
2015-11-13 13:37:39 +01:00
|
|
|
Notification::append(false, $this->__('post.public_yes'));
|
2015-08-19 11:28:28 +02:00
|
|
|
\Modl\Privacy::set($id, 1);
|
|
|
|
}
|
2015-08-03 11:35:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-15 11:54:49 +01:00
|
|
|
function getComments($post)
|
|
|
|
{
|
|
|
|
$pd = new \Modl\PostnDAO();
|
|
|
|
return $pd->getComments($post);
|
|
|
|
}
|
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
function display()
|
|
|
|
{
|
2015-12-15 11:54:49 +01:00
|
|
|
$validate_nodeid = Validator::stringType()->length(10, 100);
|
2015-08-03 11:35:01 +02:00
|
|
|
|
|
|
|
$this->view->assign('nodeid', false);
|
|
|
|
if($validate_nodeid->validate($this->get('n'))) {
|
|
|
|
$this->view->assign('nodeid', $this->get('n'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|