Browse Source

Fix Post reply

Fix NSFW filtering
pull/617/head
Timothée Jaussoin 8 years ago
parent
commit
e5912c7b81
  1. 41
      app/Post.php
  2. 1
      app/widgets/Communities/Communities.php
  3. 2
      app/widgets/CommunityPosts/CommunityPosts.php
  4. 1
      app/widgets/ContactDiscoPosts/ContactDiscoPosts.php
  5. 4
      app/widgets/NewsNav/NewsNav.php
  6. 19
      app/widgets/Post/Post.php
  7. 1
      app/widgets/Post/_post_card.tpl
  8. 94
      app/widgets/Post/_post_reply.tpl
  9. 7
      database/migrations/20180402145559_create_posts_table.php

41
app/Post.php

@ -75,7 +75,7 @@ class Post extends Model
$configuration = Configuration::findOrNew(1);
if ($configuration->restrictsuggestions) {
$query->orWhereIn('id', function($query) {
$query->whereIn('id', function($query) {
$host = \App\User::me()->session->host;
$query->select('id')
->from('posts')
@ -85,6 +85,15 @@ class Post extends Model
}
}
public function scopeRestrictNSFW($query)
{
$query->where('nsfw', false);
if (\App\User::me()->nsfw) {
$query->orWhere('nsfw', true);
}
}
protected function withContactsScope($query)
{
return $query->orWhereIn('server', function($query) {
@ -355,13 +364,9 @@ class Post extends Model
if ($entry->entry->{'in-reply-to'}) {
$href = (string)$entry->entry->{'in-reply-to'}->attributes()->href;
$arr = explode(';', $href);
$reply = [
'server' => substr($arr[0], 5, -1),
'node' => substr($arr[1], 5),
'nodeid' => substr($arr[2], 5)
];
$this->reply = $reply;
$this->replyserver = substr($arr[0], 5, -1);
$this->replynode = substr($arr[1], 5);
$this->replynodeid = substr($arr[2], 5);
}
$extra = false;
@ -624,7 +629,7 @@ class Post extends Model
public function isReply()
{
return isset($this->reply);
return isset($this->replynodeid);
}
public function isLike()
@ -674,11 +679,12 @@ class Post extends Model
public function getReply()
{
if (!$this->reply) return;
if (!$this->replynodeid) return;
$reply = $this->reply;
$pd = new \Modl\PostnDAO;
return $pd->get($reply['server'], $reply['node'], $reply['nodeid']);
return \App\Post::where('server', $this->replyserver)
->where('node', $this->replynode)
->where('nodeid', $this->replynodeid)
->first();
}
public function countComments()
@ -700,14 +706,5 @@ class Post extends Model
{
return false;
}
/*public function countReplies()
{
return $pd->countReplies([
'server' => $this->server,
'node' => $this->node,
'nodeid' => $this->nodeid
]);
}*/
}

1
app/widgets/Communities/Communities.php

@ -24,6 +24,7 @@ class Communities extends \Movim\Widget\Base
$posts = \App\Post::withoutComments()
->restrictToCommunities()
->restrictNSFW()
->orderBy('published', 'desc')
->orderBy('server', 'desc')
->orderBy('node', 'desc')

2
app/widgets/CommunityPosts/CommunityPosts.php

@ -138,7 +138,7 @@ class CommunityPosts extends \Movim\Widget\Base
$nsfwMessage = false;
if (User::me()->nsfw == false) {
if ($this->user->nsfw == false) {
foreach ($posts as $key => $post) {
if ($post->nsfw) {
$posts->forget($key);

1
app/widgets/ContactDiscoPosts/ContactDiscoPosts.php

@ -23,6 +23,7 @@ class ContactDiscoPosts extends \Movim\Widget\Base
$blogs = \App\Post::restrictToMicroblog()
->restrictUserHost()
->restrictNSFW()
->where('open', true)
->orderBy('published', 'desc')
->get();

4
app/widgets/NewsNav/NewsNav.php

@ -10,9 +10,10 @@ class NewsNav extends Base
public function display()
{
$blogs = \App\Post::where('open', true)
->restrictToMicroblog()
->orderBy('published', 'desc')
->restrictToMicroblog()
->restrictUserHost()
->restrictNSFW()
->take(6)
->get()
->shuffle();
@ -23,6 +24,7 @@ class NewsNav extends Base
->orderBy('published', 'desc')
->restrictToCommunities()
->restrictUserHost()
->restrictNSFW()
->take(6);
if ($this->get('s') && $this->get('s') != 'subscriptions') {

19
app/widgets/Post/Post.php

@ -80,18 +80,13 @@ class Post extends \Movim\Widget\Base
$this->rpc('MovimTpl.fill', '#post_widget.'.cleanupId($p->nodeid), $html);
$this->rpc('MovimUtils.enhanceArticlesContent');
// If the post is a reply but we don't have the serveral
// If the post is a reply but we don't have the original
if ($p->isReply() && !$p->getReply()) {
$reply = $p->reply;
$gi = new GetItem;
$gi->setTo($reply['server'])
->setNode($reply['node'])
->setId($reply['nodeid'])
->setAskReply([
'server' => $p->server,
'node' => $p->node,
'nodeid' => $p->nodeid])
$gi->setTo($p->replyserver)
->setNode($p->replynode)
->setId($p->replynodeid)
->setAskReply($p->id)
->request();
}
@ -238,8 +233,10 @@ class Post extends \Movim\Widget\Base
public function preparePostReply(\App\Post $post)
{
if (!$post->isReply()) return '';
$view = $this->tpl();
$view->assign('post', $post);
$view->assign('reply', $post->getReply());
return $view->draw('_post_reply', true);
}

1
app/widgets/Post/_post_card.tpl

@ -118,7 +118,6 @@
{/if}
{$c->preparePostReply($post)}
{$c->preparePostLinks($post)}
<li>

94
app/widgets/Post/_post_reply.tpl

@ -1,54 +1,50 @@
{if="$post->isReply()"}
<hr />
{$reply = $post->getReply()}
{if="$reply"}
<ul class="list thick active recessed"
onclick="MovimUtils.reload('{$c->route('post', [$reply->server, $reply->node, $reply->nodeid])}')">
<li>
{if="$reply->picture"}
<span
class="primary icon bubble color white"
style="background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0.3) 100%), url({$reply->picture});">
<hr />
{if="$reply != null"}
<ul class="list thick active recessed"
onclick="MovimUtils.reload('{$c->route('post', [$reply->server, $reply->node, $reply->nodeid])}')">
<li>
{if="$reply->picture"}
<span
class="primary icon bubble color white"
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-share"></i>
</span>
{elseif="$reply->isMicroblog()"}
{$url = $reply->contact->getPhoto('l')}
{if="$url"}
<span class="primary icon bubble 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-share"></i>
</span>
{elseif="$reply->isMicroblog()"}
{$url = $reply->contact->getPhoto('l')}
{if="$url"}
<span class="primary icon bubble 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-share"></i>
</span>
{else}
<span class="primary icon bubble color {$reply->contact->jid|stringToColor}">
<i class="zmdi zmdi-share"></i>
</span>
{/if}
{/if}
<span class="control icon gray">
<i class="zmdi zmdi-chevron-right"></i>
</span>
<p class="normal line">{$reply->title}</p>
<p>{$reply->getContent()|html_entity_decode|stripTags}</p>
<p>
{if="$reply->isMicroblog()"}
<i class="zmdi zmdi-account"></i> {$reply->contact->truename}
{else}
<i class="zmdi zmdi-pages"></i> {$reply->node}
{/if}
<span class="info">
{$reply->published|strtotime|prepareDate:true,true}
{else}
<span class="primary icon bubble color {$reply->contact->jid|stringToColor}">
<i class="zmdi zmdi-share"></i>
</span>
</p>
</li>
</ul>
{else}
<ul class="list thick active faded">
<li>
<span class="primary icon gray">
<i class="zmdi zmdi-mail-reply"></i>
{/if}
{/if}
<span class="control icon gray">
<i class="zmdi zmdi-chevron-right"></i>
</span>
<p class="normal line">{$reply->title}</p>
<p>{$reply->getContent()|html_entity_decode|stripTags}</p>
<p>
{if="$reply->isMicroblog()"}
<i class="zmdi zmdi-account"></i> {$reply->contact->truename}
{else}
<i class="zmdi zmdi-pages"></i> {$reply->node}
{/if}
<span class="info">
{$reply->published|strtotime|prepareDate:true,true}
</span>
<p class="line normal">{$c->__('post.serveral_deleted')}</p>
</li>
</ul>
{/if}
</p>
</li>
</ul>
{else}
<ul class="list thick active faded">
<li>
<span class="primary icon gray">
<i class="zmdi zmdi-mail-reply"></i>
</span>
<p class="line normal">{$c->__('post.original_deleted')}</p>
</li>
</ul>
{/if}

7
database/migrations/20180402145559_create_posts_table.php

@ -23,7 +23,11 @@ class CreatePostsTable extends Migration
$table->string('commentserver', 64)->nullable();
$table->string('commentnodeid', 192)->nullable();
$table->integer('parent_id')->nullable();
$table->integer('parent_id')->index()->nullable();
$table->string('replyserver', 64)->nullable();
$table->string('replynode', 256)->nullable();
$table->string('replynodeid', 192)->nullable();
$table->boolean('open')->default(false);
$table->boolean('nsfw')->default(false);
@ -32,7 +36,6 @@ class CreatePostsTable extends Migration
$table->datetime('published')->nullable();
$table->datetime('updated')->nullable();
$table->datetime('delay')->nullable();
$table->text('reply')->nullable();
$table->timestamps();

Loading…
Cancel
Save