From 557e430c7d2ce26d55cb64c6fc8905b2ab55f891 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sat, 6 Aug 2016 18:29:38 +0200 Subject: [PATCH 01/16] Reference local URLs in addressee list on notices. --- lib/noticelistitem.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/noticelistitem.php b/lib/noticelistitem.php index a10169e36d..5c7efa5814 100644 --- a/lib/noticelistitem.php +++ b/lib/noticelistitem.php @@ -284,7 +284,7 @@ class NoticeListItem extends Widget $this->out->elementStart('ul', 'addressees'); $first = true; foreach ($pa as $addr) { - $this->out->elementStart('li', 'h-card'); + $this->out->elementStart('li'); $text = $addr['text']; unset($addr['text']); $this->out->element('a', $addr, $text); @@ -302,12 +302,12 @@ class NoticeListItem extends Widget $attentions = $this->getAttentionProfiles(); foreach ($attentions as $attn) { - $class = $attn->isGroup() ? 'group' : 'account'; - $profileurl = $attn->getUri(); - if (common_valid_http_url($profileurl)) { - $class .= ' u-uid'; + if ($attn->isGroup()) { + $class = 'group'; + $profileurl = common_local_url('groupbyid', array('id' => $attn->getGroup()->getID())); } else { - $profileurl = $attn->getUrl(); + $class = 'account'; + $profileurl = common_local_url('userbyid', array('id' => $attn->getID())); } $this->pa[] = array('href' => $profileurl, 'title' => $attn->getNickname(), From fc06c599bc94a82c1f602723032ff2de907f3a58 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Tue, 16 Aug 2016 20:27:41 +0200 Subject: [PATCH 02/16] dbqueuemanager should ignore on no-result-exceptions --- lib/dbqueuemanager.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/dbqueuemanager.php b/lib/dbqueuemanager.php index 4440a4d930..6a2952c28f 100644 --- a/lib/dbqueuemanager.php +++ b/lib/dbqueuemanager.php @@ -95,11 +95,14 @@ class DBQueueManager extends QueueManager } catch (NoQueueHandlerException $e) { $this->noHandlerFound($qi, $rep); return true; + } catch (NoResultException $e) { + $this->_log(LOG_ERR, "[{$qi->transport}:$rep] ".get_class($e).' thrown ('._ve($e->getMessage()).'), ignoring queue_item '._ve($qi->getID())); + $result = true; } catch (AlreadyFulfilledException $e) { - $this->_log(LOG_ERR, "[{$qi->transport}:$rep] AlreadyFulfilledException thrown: {$e->getMessage()}"); + $this->_log(LOG_ERR, "[{$qi->transport}:$rep] ".get_class($e).' thrown ('._ve($e->getMessage()).'), ignoring queue_item '._ve($qi->getID())); $result = true; } catch (Exception $e) { - $this->_log(LOG_ERR, "[{$qi->transport}:$rep] Exception thrown: {$e->getMessage()}"); + $this->_log(LOG_ERR, "[{$qi->transport}:$rep] Exception (".get_class($e).') thrown: '._ve($e->getMessage())); $result = false; } From 4314a286e396358a20e0d8dd1f5138ff04dd827a Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 21 Aug 2016 09:25:16 +0200 Subject: [PATCH 03/16] Less convoluted attachmentlistitem function calls --- lib/attachment.php | 2 +- lib/attachmentlistitem.php | 18 ++++++++---------- lib/inlineattachmentlistitem.php | 10 ++++------ 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/attachment.php b/lib/attachment.php index ac0a32aeb5..d001337dd6 100644 --- a/lib/attachment.php +++ b/lib/attachment.php @@ -35,7 +35,7 @@ if (!defined('GNUSOCIAL')) { exit(1); } */ class Attachment extends AttachmentListItem { - function showLink() { + function showNoticeAttachment() { if (Event::handle('StartShowAttachmentLink', array($this->out, $this->attachment))) { $this->out->elementStart('div', array('id' => 'attachment_view', 'class' => 'h-entry')); diff --git a/lib/attachmentlistitem.php b/lib/attachmentlistitem.php index 934c5f74dd..fe11dbe639 100644 --- a/lib/attachmentlistitem.php +++ b/lib/attachmentlistitem.php @@ -86,28 +86,26 @@ class AttachmentListItem extends Widget } function linkAttr() { - return array('class' => 'attachment', + return array( + 'class' => 'u-url', 'href' => $this->attachment->getAttachmentUrl(), - 'id' => 'attachment-' . $this->attachment->getID(), 'title' => $this->linkTitle()); } - function showLink() { - $this->out->elementStart('a', $this->linkAttr()); - $this->out->element('span', null, $this->linkTitle()); - $this->showRepresentation(); - $this->out->elementEnd('a'); - } - function showNoticeAttachment() { - $this->showLink(); + $this->showRepresentation(); } function showRepresentation() { $enclosure = $this->attachment->getEnclosure(); if (Event::handle('StartShowAttachmentRepresentation', array($this->out, $this->attachment))) { + + $this->out->elementStart('label'); + $this->out->element('a', $this->linkAttr(), $this->title()); + $this->out->elementEnd('label'); + if (!empty($enclosure->mimetype)) { // First, prepare a thumbnail if it exists. $thumb = null; diff --git a/lib/inlineattachmentlistitem.php b/lib/inlineattachmentlistitem.php index 10b9db202b..5c918bb86e 100644 --- a/lib/inlineattachmentlistitem.php +++ b/lib/inlineattachmentlistitem.php @@ -31,11 +31,6 @@ if (!defined('GNUSOCIAL')) { exit(1); } class InlineAttachmentListItem extends AttachmentListItem { - function showLink() { - $this->out->element('a', $this->linkAttr(), $this->title()); - $this->showRepresentation(); - } - /** * start a single notice. * @@ -45,7 +40,10 @@ class InlineAttachmentListItem extends AttachmentListItem { // XXX: RDFa // TODO: add notice_type class e.g., notice_video, notice_image - $this->out->elementStart('li', array('class' => 'inline-attachment')); + $this->out->elementStart('li', + array('class' => 'inline-attachment', + 'id' => 'attachment-' . $this->attachment->getID(), + )); } /** From 1d791f81fa59746b074d33a94a56434cb5b0c4e9 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 21 Aug 2016 09:25:45 +0200 Subject: [PATCH 04/16] Attachment styling --- plugins/Oembed/css/oembed.css | 1 - theme/base/css/display.css | 15 ++++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/Oembed/css/oembed.css b/plugins/Oembed/css/oembed.css index 68227e5dab..9750f02779 100644 --- a/plugins/Oembed/css/oembed.css +++ b/plugins/Oembed/css/oembed.css @@ -2,7 +2,6 @@ float: left; margin-bottom: 1ex; margin-right: 1em; - padding-bottom: 1ex; } .p-author.oembed { diff --git a/theme/base/css/display.css b/theme/base/css/display.css index e87e87fbf8..14200ac60a 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -812,24 +812,29 @@ position:static; .notice.h-entry .attachments { position: relative; margin-bottom: 1em; + list-style-type: none; } -.notice.h-entry .attachments > * { +.notice.h-entry .attachments > li { clear: both; + background-color: #f9f9f9; + border: 1px lightgrey solid; + margin-bottom: 1ex; + padding: 1ex 1ex 0 1ex; + overflow: auto; + text-align: center; + position: relative; } .notice.h-entry .attachments .inline-attachment > * { height: auto; max-width: 100%; } -.notice.h-entry .attachments .inline-attachment > a { +.notice.h-entry .attachments .inline-attachment > label { font-size: 0.8em; line-height: 16px; height: 16px; } -.notice.h-entry .attachments .inline-attachment > img { - display: block; -} #attachments { clear:both; From 6bc00306990d654220a10796a54d1201fa70adec Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 21 Aug 2016 09:36:22 +0200 Subject: [PATCH 05/16] articles accidentally got aligned to center --- theme/base/css/display.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 14200ac60a..837577f4a0 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -826,6 +826,10 @@ position:static; position: relative; } +.notice.h-entry .attachments .inline-attachment > article { + text-align: left; +} + .notice.h-entry .attachments .inline-attachment > * { height: auto; max-width: 100%; From d13883ec868343da9bc6b50d16e704564deb621e Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 21 Aug 2016 18:23:16 +0200 Subject: [PATCH 06/16] Margin for oEmbed article etc. --- theme/base/css/display.css | 1 + 1 file changed, 1 insertion(+) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 837577f4a0..dd007e6972 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -832,6 +832,7 @@ position:static; .notice.h-entry .attachments .inline-attachment > * { height: auto; + margin-bottom: 1ex; max-width: 100%; } .notice.h-entry .attachments .inline-attachment > label { From f7030b538f30a3f96e05009b8c64a65d197f3dd2 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Thu, 25 Aug 2016 11:26:09 +0200 Subject: [PATCH 07/16] neo-quitter display fixes for attachment since layout change --- theme/neo-quitter/css/display.css | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/theme/neo-quitter/css/display.css b/theme/neo-quitter/css/display.css index 0500395514..a5dff1853b 100644 --- a/theme/neo-quitter/css/display.css +++ b/theme/neo-quitter/css/display.css @@ -1193,35 +1193,6 @@ body#outbox #core ul.messages .notice:before { /* notices etc */ -.notice .h-entry { - overflow:visible; -} - -.notice.h-entry .attachments { - clear: both; - margin-top: -16px; - position: relative; - top: 0; - z-index: 1; -} - -.notice .attachments .inline-attachment { - color: transparent; - font-size: 0; - line-height: 0; - list-style: none outside none; - margin-bottom: 0; -} - -.notice .attachments .inline-attachment img { - color: transparent; - font-size: 0; - line-height: 0; - list-style: none outside none; - margin-bottom: 0; - padding-top:20px; -} - #page_notice { clear: both; margin-bottom: 18px; From 3b046ee49dbdee50fbd08e2f2fc79b7cf425258b Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sat, 27 Aug 2016 14:42:28 +0200 Subject: [PATCH 08/16] Shorthand function to check if notice has been repeated. --- classes/Notice.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/classes/Notice.php b/classes/Notice.php index b828678d87..c7b12371e0 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -2627,6 +2627,13 @@ class Notice extends Managed_DataObject return !empty($this->repeat_of); } + public function isRepeated() + { + $n = new Notice(); + $n->repeat_of = $this->getID(); + return $n->find() && $n->N > 0; + } + /** * Get the list of hash tags saved with this notice. * From 27022e7c393e7fe6d3824073b84a3ccecb29f5a7 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sat, 27 Aug 2016 15:00:29 +0200 Subject: [PATCH 09/16] Typing on WebFinger onRouterInitialized handler argument URLMapper $m --- plugins/WebFinger/WebFingerPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/WebFinger/WebFingerPlugin.php b/plugins/WebFinger/WebFingerPlugin.php index 03a8c140b7..d8ddcb1ce2 100644 --- a/plugins/WebFinger/WebFingerPlugin.php +++ b/plugins/WebFinger/WebFingerPlugin.php @@ -35,7 +35,7 @@ class WebFingerPlugin extends Plugin const OAUTH_REQUEST_TOKEN_REL = 'http://apinamespace.org/oauth/request_token'; const OAUTH_AUTHORIZE_REL = 'http://apinamespace.org/oauth/authorize'; - public function onRouterInitialized($m) + public function onRouterInitialized(URLMapper $m) { $m->connect('.well-known/host-meta', array('action' => 'hostmeta')); $m->connect('.well-known/host-meta.:format', From 5a008c37389dfdfc64f17eed8d0b259d3b5aaed6 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sat, 27 Aug 2016 15:06:12 +0200 Subject: [PATCH 10/16] Don't redirect to tag cloud on /tag URL (this is probably just while we pluginify TagCloud) --- actions/tag.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/tag.php b/actions/tag.php index 751e8dcec5..ccd2c7fbe0 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -34,7 +34,7 @@ class TagAction extends ManagedAction $this->tag = common_canonical_tag($taginput); if (empty($this->tag)) { - common_redirect(common_local_url('publictagcloud'), 301); + throw new ClientException(_('No valid tag data.')); } // after common_canonical_tag we have a lowercase, no-specials tag string From a32bfe7d87ae513ae5762db5cde628c87333b5aa Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sat, 27 Aug 2016 15:24:25 +0200 Subject: [PATCH 11/16] TagCloud turned into plugin (performance issues on large installs) --- actions/all.php | 6 -- actions/attachment.php | 4 -- actions/public.php | 6 -- actions/showstream.php | 9 --- lib/groupaction.php | 5 -- lib/publicgroupnav.php | 7 -- lib/router.php | 6 -- plugins/TagCloud/TagCloudPlugin.php | 70 +++++++++++++++++++ .../TagCloud/actions}/publictagcloud.php | 0 .../lib}/attachmenttagcloudsection.php | 0 .../TagCloud/lib}/grouptagcloudsection.php | 0 .../TagCloud/lib}/inboxtagcloudsection.php | 0 .../TagCloud/lib}/personaltagcloudsection.php | 2 +- .../TagCloud/lib}/publictagcloudsection.php | 0 .../lib}/subpeopletagcloudsection.php | 0 .../subscriberspeopleselftagcloudsection.php | 0 .../lib}/subscriberspeopletagcloudsection.php | 0 ...subscriptionspeopleselftagcloudsection.php | 0 .../subscriptionspeopletagcloudsection.php | 0 .../TagCloud/lib}/tagcloudsection.php | 0 20 files changed, 71 insertions(+), 44 deletions(-) create mode 100644 plugins/TagCloud/TagCloudPlugin.php rename {actions => plugins/TagCloud/actions}/publictagcloud.php (100%) rename {lib => plugins/TagCloud/lib}/attachmenttagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/grouptagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/inboxtagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/personaltagcloudsection.php (97%) rename {lib => plugins/TagCloud/lib}/publictagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/subpeopletagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/subscriberspeopleselftagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/subscriberspeopletagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/subscriptionspeopleselftagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/subscriptionspeopletagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/tagcloudsection.php (100%) diff --git a/actions/all.php b/actions/all.php index 19413076b5..84e4dd5305 100644 --- a/actions/all.php +++ b/actions/all.php @@ -170,12 +170,6 @@ class AllAction extends ShowstreamAction } $ibs->show(); } - // XXX: make this a little more convenient - - if (!common_config('performance', 'high')) { - $pop = new InboxTagCloudSection($this, $this->target); - $pop->show(); - } } } diff --git a/actions/attachment.php b/actions/attachment.php index 3ec837a511..3f2ae5c1ce 100644 --- a/actions/attachment.php +++ b/actions/attachment.php @@ -132,9 +132,5 @@ class AttachmentAction extends ManagedAction function showSections() { $ns = new AttachmentNoticeSection($this); $ns->show(); - if (!common_config('performance', 'high')) { - $atcs = new AttachmentTagCloudSection($this); - $atcs->show(); - } } } diff --git a/actions/public.php b/actions/public.php index 000f82cb93..a2958e8806 100644 --- a/actions/public.php +++ b/actions/public.php @@ -86,12 +86,6 @@ class PublicAction extends SitestreamAction $ibs->show(); } - $p = Profile::current(); - - if (!common_config('performance', 'high')) { - $cloud = new PublicTagCloudSection($this); - $cloud->show(); - } $feat = new FeaturedUsersSection($this); $feat->show(); } diff --git a/actions/showstream.php b/actions/showstream.php index 97b21b1286..1e70ecd3ac 100644 --- a/actions/showstream.php +++ b/actions/showstream.php @@ -251,15 +251,6 @@ class ShowstreamAction extends NoticestreamAction $this->elementEnd('div'); } - function showSections() - { - parent::showSections(); - if (!common_config('performance', 'high')) { - $cloud = new PersonalTagCloudSection($this->target, $this); - $cloud->show(); - } - } - function noticeFormOptions() { $options = parent::noticeFormOptions(); diff --git a/lib/groupaction.php b/lib/groupaction.php index 0886460737..31a0b8bc34 100644 --- a/lib/groupaction.php +++ b/lib/groupaction.php @@ -112,11 +112,6 @@ class GroupAction extends Action } $this->showAdmins(); - - if (!common_config('performance', 'high')) { - $cloud = new GroupTagCloudSection($this, $this->group); - $cloud->show(); - } } /** diff --git a/lib/publicgroupnav.php b/lib/publicgroupnav.php index 620a61ddd9..ef342839d8 100644 --- a/lib/publicgroupnav.php +++ b/lib/publicgroupnav.php @@ -77,13 +77,6 @@ class PublicGroupNav extends Menu // TRANS: Menu item title in search group navigation panel. _('User groups'), $this->actionName == 'groups', 'nav_groups'); - if (!common_config('performance', 'high')) { - // TRANS: Menu item in search group navigation panel. - $this->out->menuItem(common_local_url('publictagcloud'), _m('MENU','Recent tags'), - // TRANS: Menu item title in search group navigation panel. - _('Recent tags'), $this->actionName == 'publictagcloud', 'nav_recent-tags'); - } - if (count(common_config('nickname', 'featured')) > 0) { // TRANS: Menu item in search group navigation panel. $this->out->menuItem(common_local_url('featured'), _m('MENU','Featured'), diff --git a/lib/router.php b/lib/router.php index b01c9a7677..cd464d841c 100644 --- a/lib/router.php +++ b/lib/router.php @@ -260,12 +260,6 @@ class Router array('action' => 'userbyid'), array('id' => '[0-9]+')); - if (!common_config('performance', 'high')) { - $m->connect('tags/', array('action' => 'publictagcloud')); - $m->connect('tag/', array('action' => 'publictagcloud')); - $m->connect('tags', array('action' => 'publictagcloud')); - $m->connect('tag', array('action' => 'publictagcloud')); - } $m->connect('tag/:tag/rss', array('action' => 'tagrss'), array('tag' => self::REGEX_TAG)); diff --git a/plugins/TagCloud/TagCloudPlugin.php b/plugins/TagCloud/TagCloudPlugin.php new file mode 100644 index 0000000000..c616be75fd --- /dev/null +++ b/plugins/TagCloud/TagCloudPlugin.php @@ -0,0 +1,70 @@ + + * @copyright 2016 Free Software Foundation, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://gnu.io/social/ + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +class TagCloudPlugin extends Plugin { + + public function onRouterInitialized(URLMapper $m) + { + $m->connect('tags/', array('action' => 'publictagcloud')); + $m->connect('tag/', array('action' => 'publictagcloud')); + $m->connect('tags', array('action' => 'publictagcloud')); + $m->connect('tag', array('action' => 'publictagcloud')); + } + + public function onEndPublicGroupNav(Menu $menu) + { + // TRANS: Menu item in search group navigation panel. + $menu->out->menuItem(common_local_url('publictagcloud'), _m('MENU','Recent tags'), + // TRANS: Menu item title in search group navigation panel. + _('Recent tags'), $menu->actionName === 'publictagcloud', 'nav_recent-tags'); + } + + public function onEndShowSections(Action $action) + { + $cloud = null; + + switch (true) { + case $action instanceof AllAction: + $cloud = new InboxTagCloudSection($action, $action->getTarget()); + break; + case $action instanceof AttachmentAction: + $cloud = new AttachmentTagCloudSection($action); + break; + case $action instanceof PublicAction: + $cloud = new PublicTagCloudSection($action); + break; + case $action instanceof ShowstreamAction: + $cloud = new PersonalTagCloudSection($action, $action->getTarget()); + break; + case $action instanceof GroupAction: + $cloud = new GroupTagCloudSection($action, $action->getGroup()); + } + + if (!is_null($cloud)) { + $cloud->show(); + } + } + + public function onPluginVersion(array &$versions) + { + $versions[] = array('name' => 'TagCloud', + 'version' => GNUSOCIAL_VERSION, + 'author' => 'Mikael Nordfeldth', + 'homepage' => 'https://gnu.io/social', + 'description' => + // TRANS: Plugin description. + _m('Adds tag clouds to stream pages')); + return true; + } +} diff --git a/actions/publictagcloud.php b/plugins/TagCloud/actions/publictagcloud.php similarity index 100% rename from actions/publictagcloud.php rename to plugins/TagCloud/actions/publictagcloud.php diff --git a/lib/attachmenttagcloudsection.php b/plugins/TagCloud/lib/attachmenttagcloudsection.php similarity index 100% rename from lib/attachmenttagcloudsection.php rename to plugins/TagCloud/lib/attachmenttagcloudsection.php diff --git a/lib/grouptagcloudsection.php b/plugins/TagCloud/lib/grouptagcloudsection.php similarity index 100% rename from lib/grouptagcloudsection.php rename to plugins/TagCloud/lib/grouptagcloudsection.php diff --git a/lib/inboxtagcloudsection.php b/plugins/TagCloud/lib/inboxtagcloudsection.php similarity index 100% rename from lib/inboxtagcloudsection.php rename to plugins/TagCloud/lib/inboxtagcloudsection.php diff --git a/lib/personaltagcloudsection.php b/plugins/TagCloud/lib/personaltagcloudsection.php similarity index 97% rename from lib/personaltagcloudsection.php rename to plugins/TagCloud/lib/personaltagcloudsection.php index 46b4661e89..e46aa2d662 100644 --- a/lib/personaltagcloudsection.php +++ b/plugins/TagCloud/lib/personaltagcloudsection.php @@ -42,7 +42,7 @@ class PersonalTagCloudSection extends TagCloudSection { protected $profile = null; - function __construct(Profile $profile, HTMLOutputter $out=null) + function __construct(HTMLOutputter $out, Profile $profile) { parent::__construct($out); $this->profile = $profile; diff --git a/lib/publictagcloudsection.php b/plugins/TagCloud/lib/publictagcloudsection.php similarity index 100% rename from lib/publictagcloudsection.php rename to plugins/TagCloud/lib/publictagcloudsection.php diff --git a/lib/subpeopletagcloudsection.php b/plugins/TagCloud/lib/subpeopletagcloudsection.php similarity index 100% rename from lib/subpeopletagcloudsection.php rename to plugins/TagCloud/lib/subpeopletagcloudsection.php diff --git a/lib/subscriberspeopleselftagcloudsection.php b/plugins/TagCloud/lib/subscriberspeopleselftagcloudsection.php similarity index 100% rename from lib/subscriberspeopleselftagcloudsection.php rename to plugins/TagCloud/lib/subscriberspeopleselftagcloudsection.php diff --git a/lib/subscriberspeopletagcloudsection.php b/plugins/TagCloud/lib/subscriberspeopletagcloudsection.php similarity index 100% rename from lib/subscriberspeopletagcloudsection.php rename to plugins/TagCloud/lib/subscriberspeopletagcloudsection.php diff --git a/lib/subscriptionspeopleselftagcloudsection.php b/plugins/TagCloud/lib/subscriptionspeopleselftagcloudsection.php similarity index 100% rename from lib/subscriptionspeopleselftagcloudsection.php rename to plugins/TagCloud/lib/subscriptionspeopleselftagcloudsection.php diff --git a/lib/subscriptionspeopletagcloudsection.php b/plugins/TagCloud/lib/subscriptionspeopletagcloudsection.php similarity index 100% rename from lib/subscriptionspeopletagcloudsection.php rename to plugins/TagCloud/lib/subscriptionspeopletagcloudsection.php diff --git a/lib/tagcloudsection.php b/plugins/TagCloud/lib/tagcloudsection.php similarity index 100% rename from lib/tagcloudsection.php rename to plugins/TagCloud/lib/tagcloudsection.php From cb5bcf4937a395b26ade87bfff9723fe74204c02 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 28 Aug 2016 00:16:31 +0200 Subject: [PATCH 12/16] bad log constant --- plugins/Oembed/OembedPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/Oembed/OembedPlugin.php b/plugins/Oembed/OembedPlugin.php index 187b4b9819..64e3e8940c 100644 --- a/plugins/Oembed/OembedPlugin.php +++ b/plugins/Oembed/OembedPlugin.php @@ -176,7 +176,7 @@ class OembedPlugin extends Plugin } $file->setTitle($oembed_data->title); } catch (Exception $e) { - common_log(LOG_WARN, sprintf(__METHOD__.': %s thrown when getting oEmbed data: %s', get_class($e), _ve($e->getMessage()))); + common_log(LOG_WARNING, sprintf(__METHOD__.': %s thrown when getting oEmbed data: %s', get_class($e), _ve($e->getMessage()))); return true; } From af6a3aa456c239e5dfc03b5cd34f0192fd4117ac Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 28 Aug 2016 09:34:31 +0200 Subject: [PATCH 13/16] Make Group actions ManagedAction so groupbyid works --- actions/groupbyid.php | 10 +++--- actions/groupmembers.php | 16 +--------- actions/showgroup.php | 68 ++-------------------------------------- lib/groupaction.php | 18 +++++------ lib/profileaction.php | 4 +-- 5 files changed, 18 insertions(+), 98 deletions(-) diff --git a/actions/groupbyid.php b/actions/groupbyid.php index de87ec5c67..ed4ec979a9 100644 --- a/actions/groupbyid.php +++ b/actions/groupbyid.php @@ -42,7 +42,7 @@ if (!defined('GNUSOCIAL')) { exit(1); } * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -class GroupbyidAction extends ManagedAction +class GroupbyidAction extends ShowgroupAction { /** group we're viewing. */ protected $group = null; @@ -55,10 +55,10 @@ class GroupbyidAction extends ManagedAction protected function doPreparation() { $this->group = User_group::getByID($this->arg('id')); - } + $this->target = $this->group->getProfile(); - public function showPage() - { - common_redirect($this->group->homeUrl(), 303); + if ($this->target->isLocal()) { + common_redirect($this->target->getUrl()); + } } } diff --git a/actions/groupmembers.php b/actions/groupmembers.php index 44c4dd6f99..1d2171b27f 100644 --- a/actions/groupmembers.php +++ b/actions/groupmembers.php @@ -27,12 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} - -require_once(INSTALLDIR.'/lib/profilelist.php'); -require_once INSTALLDIR.'/lib/publicgroupnav.php'; +if (!defined('GNUSOCIAL)') { exit(1); } /** * List of group members @@ -52,15 +47,6 @@ class GroupmembersAction extends GroupAction return true; } - protected function prepare(array $args=array()) - { - parent::prepare($args); - - $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; - - return true; - } - function title() { if ($this->page == 1) { diff --git a/actions/showgroup.php b/actions/showgroup.php index 8770e6cc8b..8cc65aa906 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -76,79 +76,15 @@ class ShowgroupAction extends GroupAction } } - /** - * Prepare the action - * - * Reads and validates arguments and instantiates the attributes. - * - * @param array $args $_REQUEST args - * - * @return boolean success flag - */ - protected function prepare(array $args=array()) + public function getStream() { - parent::prepare($args); - - $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; - if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) { $stream = new GroupNoticeStream($this->group, $this->scoped); } else { $stream = new ThreadingGroupNoticeStream($this->group, $this->scoped); } - $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, - NOTICES_PER_PAGE + 1); - - common_set_returnto($this->selfUrl()); - - return true; - } - - /** - * Handle the request - * - * Shows a profile for the group, some controls, and a list of - * group notices. - * - * @return void - */ - protected function handle() - { - parent::handle(); - $this->showPage(); - } - - /** - * Show the page content - * - * Shows a group profile and a list of group notices - */ - function showContent() - { - $this->showGroupNotices(); - } - - /** - * Show the group notices - * - * @return void - */ - function showGroupNotices() - { - if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) { - $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE)); - } else { - $nl = new ThreadedNoticeList($this->notice, $this, $this->scoped); - } - - $cnt = $nl->show(); - - $this->pagination($this->page > 1, - $cnt > NOTICES_PER_PAGE, - $this->page, - 'showgroup', - array('nickname' => $this->group->nickname)); + return $stream; } /** diff --git a/lib/groupaction.php b/lib/groupaction.php index 31a0b8bc34..2fcec360bc 100644 --- a/lib/groupaction.php +++ b/lib/groupaction.php @@ -40,25 +40,23 @@ define('MEMBERS_PER_SECTION', 27); * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -class GroupAction extends Action +class GroupAction extends ShowstreamAction { protected $group; - protected function prepare(array $args=array()) + protected function doPreparation() { - parent::prepare($args); - $nickname_arg = $this->arg('nickname'); $nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname - if ($nickname_arg != $nickname) { + if ($nickname_arg !== $nickname) { $args = array('nickname' => $nickname); if ($this->page != 1) { $args['page'] = $this->page; } - common_redirect(common_local_url('showgroup', $args), 301); + common_redirect(common_local_url($this->getActionName(), $args), 301); } if (!$nickname) { @@ -79,15 +77,16 @@ class GroupAction extends Action } else { common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'"); // TRANS: Client error displayed if no remote group with a given name was found requesting group page. - $this->clientError(_('No such group.'), 404); + throw new ClientException(_('No such group.'), 404); } } $this->group = User_group::getKV('id', $local->group_id); + $this->target = $this->group->getProfile(); if (!$this->group instanceof User_group) { // TRANS: Client error displayed if no local group with a given name was found requesting group page. - $this->clientError(_('No such group.'), 404); + throw new ClientException(_('No such group.'), 404); } } @@ -105,8 +104,7 @@ class GroupAction extends Action function showSections() { $this->showMembers(); - $cur = common_current_user(); - if ($cur && $cur->isAdmin($this->group)) { + if ($this->scoped instanceof Profile && $this->scoped->isAdmin($this->group)) { $this->showPending(); $this->showBlocked(); } diff --git a/lib/profileaction.php b/lib/profileaction.php index 22c960406a..64087cf312 100644 --- a/lib/profileaction.php +++ b/lib/profileaction.php @@ -55,7 +55,7 @@ abstract class ProfileAction extends ManagedAction $nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname - if ($nickname_arg != $nickname) { + if ($nickname_arg !== $nickname) { $args = array('nickname' => $nickname); if ($this->arg('page') && $this->arg('page') != 1) { $args['page'] = $this->arg['page']; @@ -83,7 +83,7 @@ abstract class ProfileAction extends ManagedAction // this will call ->doPreparation() which child classes use to set $this->target parent::prepare($args); - if ($this->target->hasRole(Profile_role::SILENCED) + if ($this->target->isPerson() && $this->target->hasRole(Profile_role::SILENCED) && (!$this->scoped instanceof Profile || !$this->scoped->hasRight(Right::SILENCEUSER))) { throw new ClientException(_('This profile has been silenced by site moderators'), 403); } From e6b3924a5d30e622619fe88fbfef9b6f0b71c200 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Fri, 2 Sep 2016 00:08:17 +0200 Subject: [PATCH 14/16] common_to_alphanumeric added, filtering Notice->source in classic layout --- lib/activityhandlerplugin.php | 5 +++++ lib/noticelistitem.php | 6 ++++-- lib/util.php | 9 +++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/activityhandlerplugin.php b/lib/activityhandlerplugin.php index c06f723a36..9ebcd8a218 100644 --- a/lib/activityhandlerplugin.php +++ b/lib/activityhandlerplugin.php @@ -556,6 +556,11 @@ abstract class ActivityHandlerPlugin extends Plugin if ($nli->notice->scope != 0 && $nli->notice->scope != 1) { $class .= ' limited-scope'; } + try { + $class .= ' notice-source-'.common_to_alphanumeric($this->notice->source); + } 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)); } diff --git a/lib/noticelistitem.php b/lib/noticelistitem.php index 5c7efa5814..1a629cf372 100644 --- a/lib/noticelistitem.php +++ b/lib/noticelistitem.php @@ -229,8 +229,10 @@ class NoticeListItem extends Widget if ($this->notice->scope != 0 && $this->notice->scope != 1) { $class .= ' limited-scope'; } - if (!empty($this->notice->source)) { - $class .= ' notice-source-'.$this->notice->source; + try { + $class .= ' notice-source-'.common_to_alphanumeric($this->notice->source); + } 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, array('class' => $class, diff --git a/lib/util.php b/lib/util.php index 985b3773df..aa0d5bfe76 100644 --- a/lib/util.php +++ b/lib/util.php @@ -581,6 +581,15 @@ function common_canonical_email($email) return $email; } +function common_to_alphanumeric($str) +{ + $filtered = preg_replace('/[^A-Za-z0-9]\s*/', '', $str); + if (strlen($filtered) < 1) { + throw new Exception('Filtered string was zero-length.'); + } + return $filtered; +} + function common_purify($html, array $args=array()) { require_once INSTALLDIR.'/extlib/HTMLPurifier/HTMLPurifier.auto.php'; From 59b93b23e23644a3eb3df1e3275a03f617c2f8e8 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Fri, 2 Sep 2016 00:55:46 +0200 Subject: [PATCH 15/16] Split up source and source_link. Never trust HTML! https://community.highlandarrow.com/notice/269667 or alternatively: https://social.umeahackerspace.se/conversation/495655 --- actions/apisearchatom.php | 16 +++++++-------- classes/Notice.php | 6 +----- lib/apiaction.php | 16 +++++++-------- lib/jsonsearchresultslist.php | 37 +++++++++++++++++++++++------------ 4 files changed, 41 insertions(+), 34 deletions(-) diff --git a/actions/apisearchatom.php b/actions/apisearchatom.php index 3a24b771ea..e82ea39f9f 100644 --- a/actions/apisearchatom.php +++ b/actions/apisearchatom.php @@ -337,21 +337,21 @@ class ApiSearchAtomAction extends ApiPrivateAuthAction // @todo: Here is where we'd put in a link to an atom feed for threads $source = null; + $source_link = null; $ns = $notice->getSource(); if ($ns instanceof Notice_source) { - if (!empty($ns->name) && !empty($ns->url)) { - $source = '' - . htmlspecialchars($ns->name) - . ''; - } else { - $source = $ns->code; + $source = $ns->code; + if (!empty($ns->url)) { + $source_link = $ns->url; + if (!empty($ns->name)) { + $source = $ns->name; + } } } $this->element("twitter:source", null, $source); + $this->element("twitter:source_link", null, $source_link); $this->elementStart('author'); diff --git a/classes/Notice.php b/classes/Notice.php index c7b12371e0..d5a0e5f6d2 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -2123,11 +2123,7 @@ class Notice extends Managed_DataObject if (!empty($ns->url)) { $noticeInfoAttr['source_link'] = $ns->url; if (!empty($ns->name)) { - $noticeInfoAttr['source'] = '' - . htmlspecialchars($ns->name) - . ''; + $noticeInfoAttr['source'] = $ns->name; } } } diff --git a/lib/apiaction.php b/lib/apiaction.php index 6f2f43ab9c..723e589408 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -337,22 +337,22 @@ class ApiAction extends Action $twitter_status['in_reply_to_status_id'] = $in_reply_to; $source = null; + $source_link = null; $ns = $notice->getSource(); if ($ns instanceof Notice_source) { - if (!empty($ns->name) && !empty($ns->url)) { - $source = '' - . htmlspecialchars($ns->name) - . ''; - } else { - $source = $ns->code; + $source = $ns->code; + if (!empty($ns->url)) { + $source_link = $ns->url; + if (!empty($ns->name)) { + $source = $ns->name; + } } } $twitter_status['uri'] = $notice->getUri(); $twitter_status['source'] = $source; + $twitter_status['source_link'] = $source_link; $twitter_status['id'] = intval($notice->id); $replier_profile = null; diff --git a/lib/jsonsearchresultslist.php b/lib/jsonsearchresultslist.php index 0f764a72be..80dc33e323 100644 --- a/lib/jsonsearchresultslist.php +++ b/lib/jsonsearchresultslist.php @@ -184,7 +184,8 @@ class ResultItem var $id; var $from_user_id; var $iso_language_code; - var $source; + var $source = null; + var $source_link = null; var $profile_image_url; var $created_at; @@ -234,7 +235,8 @@ class ResultItem $this->iso_language_code = Profile_prefs::getConfigData($this->profile, 'site', 'language'); - $this->source = $this->getSourceLink($this->notice->source); + // set source and source_link + $this->setSourceData(); $this->profile_image_url = $this->profile->avatarUrl(AVATAR_STREAM_SIZE); @@ -242,34 +244,43 @@ class ResultItem } /** - * Show the source of the notice + * Set the notice's source data (api/app name and URL) * * Either the name (and link) of the API client that posted the notice, - * or one of other other channels. + * or one of other other channels. Uses the local notice object. * - * @param string $source the source of the Notice - * - * @return string a fully rendered source of the Notice + * @return void */ - function getSourceLink($source) + function setSourceData() { - // Gettext translations for the below source types are available. - $source_name = _($source); + $source = null; + $source_link = null; + switch ($source) { case 'web': case 'xmpp': case 'mail': case 'omb': case 'api': + // Gettext translations for the below source types are available. + $source = _($this->notice->source); break; + default: - $ns = Notice_source::getKV($source); + $ns = Notice_source::getKV($this->notice->source); if ($ns instanceof Notice_source) { - $source_name = '' . $ns->name . ''; + $source = $ns->code; + if (!empty($ns->url)) { + $source_link = $ns->url; + if (!empty($ns->name)) { + $source = $ns->name; + } + } } break; } - return $source_name; + $this->source = $source; + $this->source_link = $source_link; } } From 3b9b9331a839fcd4f14b45a09fb8dacba9de86b1 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Fri, 2 Sep 2016 01:07:09 +0200 Subject: [PATCH 16/16] parenthesis fail --- actions/groupmembers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/groupmembers.php b/actions/groupmembers.php index 1d2171b27f..b4c1ec1cd1 100644 --- a/actions/groupmembers.php +++ b/actions/groupmembers.php @@ -27,7 +27,7 @@ * @link http://status.net/ */ -if (!defined('GNUSOCIAL)') { exit(1); } +if (!defined('GNUSOCIAL)')) { exit(1); } /** * List of group members