From 0204ffb1fabaea5fdf792bb53a86ce0bf120b155 Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Thu, 9 Jan 2020 19:49:49 +0000 Subject: [PATCH] [NOTICES] Add data-nosnippet attribute for notices by remote profiles --- lib/modules/ActivityHandlerModule.php | 20 ++++++++++++++++---- lib/modules/ActivityHandlerPlugin.php | 18 ++++++++++++++++-- lib/notices/noticelistitem.php | 27 ++++++++++++++++++--------- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/lib/modules/ActivityHandlerModule.php b/lib/modules/ActivityHandlerModule.php index f0a5346c39..597a9dfeb1 100644 --- a/lib/modules/ActivityHandlerModule.php +++ b/lib/modules/ActivityHandlerModule.php @@ -571,7 +571,15 @@ abstract class ActivityHandlerModule extends Module protected function openNoticeListItemElement(NoticeListItem $nli) { + // Build up the attributes + $attrs = []; + + // -> The id $id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id; + $id_decl = "notice-{$id}"; + $attrs['id'] = $id_decl; + + // -> The class $class = 'h-entry notice ' . $this->tag(); if ($nli->notice->scope != 0 && $nli->notice->scope != 1) { $class .= ' limited-scope'; @@ -581,10 +589,14 @@ abstract class ActivityHandlerModule extends Module } catch (Exception $e) { // either source or what we filtered out was a zero-length string } - $nli->out->elementStart( - 'li', - ['class' => $class, 'id' => 'notice-' . $id] - ); + $attrs['class'] = $class; + + // -> Robots + if (!$nli->notice->isLocal()) { + $attrs['data-nosnippet'] = 'true'; + } + + $nli->out->elementStart('li', $attrs); } protected function closeNoticeListItemElement(NoticeListItem $nli) diff --git a/lib/modules/ActivityHandlerPlugin.php b/lib/modules/ActivityHandlerPlugin.php index bd65915c04..29fcd6193a 100644 --- a/lib/modules/ActivityHandlerPlugin.php +++ b/lib/modules/ActivityHandlerPlugin.php @@ -564,7 +564,15 @@ abstract class ActivityHandlerPlugin extends Plugin protected function openNoticeListItemElement(NoticeListItem $nli) { + // Build up the attributes + $attrs = []; + + // -> The id $id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id; + $id_decl = "notice-{$id}"; + $attrs['id'] = $id_decl; + + // -> The class $class = 'h-entry notice ' . $this->tag(); if ($nli->notice->scope != 0 && $nli->notice->scope != 1) { $class .= ' limited-scope'; @@ -574,8 +582,14 @@ abstract class ActivityHandlerPlugin extends Plugin } catch (Exception $e) { // either source or what we filtered out was a zero-length string } - $nli->out->elementStart('li', array('class' => $class, - 'id' => 'notice-' . $id)); + $attrs['class'] = $class; + + // -> Robots + if (!$nli->notice->isLocal()) { + $attrs['data-nosnippet'] = 'true'; + } + + $nli->out->elementStart('li', $attrs); } protected function closeNoticeListItemElement(NoticeListItem $nli) diff --git a/lib/notices/noticelistitem.php b/lib/notices/noticelistitem.php index 90c9d69e1f..fff644413f 100644 --- a/lib/notices/noticelistitem.php +++ b/lib/notices/noticelistitem.php @@ -232,7 +232,16 @@ class NoticeListItem extends Widget public function showStart() { if (Event::handle('StartOpenNoticeListItemElement', [$this])) { + // Build up the attributes + $attrs = []; + + // -> The id $id = (empty($this->repeat)) ? $this->notice->id : $this->repeat->id; + $id_prefix = (strlen($this->id_prefix) ? $this->id_prefix . '-' : ''); + $id_decl = "${id_prefix}notice-${id}"; + $attrs['id'] = $id_decl; + + // -> The class $class = 'h-entry notice'; if ($this->notice->scope != 0 && $this->notice->scope != 1) { $class .= ' limited-scope'; @@ -242,14 +251,14 @@ class NoticeListItem extends Widget } catch (Exception $e) { // either source or what we filtered out was a zero-length string } - $id_prefix = (strlen($this->id_prefix) ? $this->id_prefix . '-' : ''); - $this->out->elementStart( - $this->item_tag, - [ - 'class' => $class, - 'id' => "${id_prefix}notice-${id}", - ] - ); + $attrs['class'] = $class; + + // -> Robots + if (!$this->notice->isLocal()) { + $attrs['data-nosnippet'] = 'true'; + } + + $this->out->elementStart($this->item_tag, $attrs); Event::handle('EndOpenNoticeListItemElement', [$this]); } } @@ -309,7 +318,7 @@ class NoticeListItem extends Widget $this->out->element('a', $addr, $text); $this->out->elementEnd('li'); } - $this->out->elementEnd('ul', 'addressees'); + $this->out->elementEnd('ul'); } }