diff --git a/app/Post.php b/app/Post.php index 9cc89c8ea..d31d212a7 100644 --- a/app/Post.php +++ b/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 - ]); - }*/ } diff --git a/app/widgets/Communities/Communities.php b/app/widgets/Communities/Communities.php index 6b745d3e9..c2e743d97 100644 --- a/app/widgets/Communities/Communities.php +++ b/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') diff --git a/app/widgets/CommunityPosts/CommunityPosts.php b/app/widgets/CommunityPosts/CommunityPosts.php index 5020ec52b..8ad98a8d0 100644 --- a/app/widgets/CommunityPosts/CommunityPosts.php +++ b/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); diff --git a/app/widgets/ContactDiscoPosts/ContactDiscoPosts.php b/app/widgets/ContactDiscoPosts/ContactDiscoPosts.php index 913d4722f..704f37b5c 100644 --- a/app/widgets/ContactDiscoPosts/ContactDiscoPosts.php +++ b/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(); diff --git a/app/widgets/NewsNav/NewsNav.php b/app/widgets/NewsNav/NewsNav.php index 61dcbc4c7..110ba7176 100644 --- a/app/widgets/NewsNav/NewsNav.php +++ b/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') { diff --git a/app/widgets/Post/Post.php b/app/widgets/Post/Post.php index 1972382aa..b94b06c9d 100644 --- a/app/widgets/Post/Post.php +++ b/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); } diff --git a/app/widgets/Post/_post_card.tpl b/app/widgets/Post/_post_card.tpl index 404957442..fa1ebe036 100644 --- a/app/widgets/Post/_post_card.tpl +++ b/app/widgets/Post/_post_card.tpl @@ -118,7 +118,6 @@ {/if} {$c->preparePostReply($post)} - {$c->preparePostLinks($post)}
{$reply->title}
-{$reply->getContent()|html_entity_decode|stripTags}
-- {if="$reply->isMicroblog()"} - {$reply->contact->truename} - {else} - {$reply->node} - {/if} - - {$reply->published|strtotime|prepareDate:true,true} + {else} + + -
-{$reply->title}
+{$reply->getContent()|html_entity_decode|stripTags}
++ {if="$reply->isMicroblog()"} + {$reply->contact->truename} + {else} + {$reply->node} + {/if} + + {$reply->published|strtotime|prepareDate:true,true} -
{$c->__('post.serveral_deleted')}
-{$c->__('post.original_deleted')}
+