Browse Source

- Add the comment publish feature

pull/16/head
Jaussoin Timothée 11 years ago
parent
commit
ab98103c78
  1. 27
      app/widgets/Post/Post.php
  2. 23
      app/widgets/Post/_post_comments.tpl
  3. 2
      app/widgets/Post/_post_comments_error.tpl
  4. 7
      app/widgets/Post/locales.ini
  5. 5
      app/widgets/Post/post.css
  6. 4
      app/widgets/WidgetCommon/WidgetCommon.php
  7. 5
      locales/locales.ini

27
app/widgets/Post/Post.php

@ -22,6 +22,7 @@ use Moxl\Xec\Action\Pubsub\PostPublish;
use Moxl\Xec\Action\Pubsub\PostDelete;
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;
@ -31,6 +32,7 @@ class Post extends WidgetCommon
{
$this->addcss('post.css');
$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');
@ -50,6 +52,12 @@ class Post extends WidgetCommon
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'));
@ -70,6 +78,7 @@ class Post extends WidgetCommon
$view = $this->tpl();
$view->assign('comments', $comments);
$view->assign('id', $nodeid);
$html = $view->draw('_post_comments', true);
RPC::call('movim_fill', 'comments', $html);
}
@ -185,6 +194,24 @@ class Post extends WidgetCommon
->request();
}
function ajaxPublishComment($form, $id)
{
$comment = trim($form->comment->value);
$validate_comment = Validator::string()->notEmpty();
$validate_id = Validator::string()->length(6, 128)->noWhitespace();
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 ajaxEmbedTest($url)
{
if($url == '') {

23
app/widgets/Post/_post_comments.tpl

@ -1,5 +1,8 @@
<ul class="divided spaced middle">
<li class="subheader">{$c->__('post.comments')}</li>
<li class="subheader">
{$c->__('post.comments')}
<span class="info">{$comments|count}</span>
</li>
{loop="$comments"}
<li class="condensed">
<a href="{$c->route('contact', $value->getContact()->jid)}">
@ -25,4 +28,22 @@
</p>
</li>
{/loop}
<li class="action">
<div class="action" onclick="Post_ajaxPublishComment(movim_form_to_json('comment'),'{$id}')">
<i class="md md-send"></i>
</div>
<span class="icon gray">
<i class="md md-comment"></i>
</span>
<form name="comment">
<div>
<textarea
onkeyup="movim_textarea_autoheight(this);"
name="comment"
placeholder="{$c->__('field.type_here')}"
></textarea>
<label for="comment">{$c->__('post.comment_add')}</label>
</div>
</form>
</li>
</ul>

2
app/widgets/Post/_post_comments_error.tpl

@ -4,7 +4,7 @@
<i class="md md-comment"></i>
</span>
<span>
{$c->__('post.no_comments')}
{$c->__('post.comments_disabled')}
</span>
</li>
</ul>

7
app/widgets/Post/locales.ini

@ -1,6 +1,4 @@
post.news_feed = 'News Feed'
post.comments = 'Comments'
post.no_comments = 'Comments disabled'
post.placeholder = 'Discover and register to the groups you are interested in'
post.preview = 'Preview'
post.help = 'Help'
@ -28,3 +26,8 @@ post.blog_remove = 'Post removed from your blog'
[delete]
post.delete_title = 'Delete this post'
post.delete_text = 'You are going to delete this post, please confirm your action'
[comment]
post.comments = 'Comments'
post.comments_disabled = 'Comments disabled'
post.comment_published = 'Comment published'

5
app/widgets/Post/post.css

@ -1,3 +1,8 @@
form[name=post] article section {
padding: 0;
}
#comments li.action div.action:hover {
cursor: pointer;
color: #333;
}

4
app/widgets/WidgetCommon/WidgetCommon.php

@ -611,7 +611,7 @@ class WidgetCommon extends WidgetBase {
->setId($id)
->request();
}
/*
function ajaxPublishComment($to, $id, $content) {
if($content != '') {
$p = new CommentPublish;
@ -622,7 +622,7 @@ class WidgetCommon extends WidgetBase {
->request();
}
}
*/
function ajaxDeletePost($to, $node, $id) {
$p = new PostDelete;
$p->setTo($to)

5
locales/locales.ini

@ -262,7 +262,7 @@ post.by = 'by'
post.geolocalisation = 'Geolocalisation'
post.email = 'email'
post.empty = 'No content'
post.no_comments = 'No comments'
post.no_comments = 'No comments yet'
post.no_comments_stream = 'No comments stream'
post.no_load = 'Your feed cannot be loaded.'
post.older = 'Get older posts'
@ -282,3 +282,6 @@ post.default_title = 'Contact publication'
[api]
api.error = 'The API is not reachable, try again later'
[field]
field.type_here = 'Type here'
Loading…
Cancel
Save