From fc94cad5f2855d5785adb5e2b1ebc8ad67736e5c Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 8 Nov 2019 06:52:44 +0000 Subject: [PATCH 1/3] Pinned posts now work for visitors in the intended way --- include/conversation.php | 12 +++++++++--- src/Model/Item.php | 24 ++++++++++++++++++++++-- src/Module/Profile.php | 2 +- src/Object/Post.php | 6 ++---- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 724d18dfea..b7f8d91fc4 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -801,10 +801,12 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ /** * Fetch all comments from a query. Additionally set the newest resharer as thread owner. * - * @param $thread_items Database statement with thread posts + * @param array $thread_items Database statement with thread posts + * @param boolean $pinned Is the item pinned? + * * @return array items with parents and comments */ -function conversation_fetch_comments($thread_items) { +function conversation_fetch_comments($thread_items, $pinned) { $comments = []; $parentlines = []; $lineno = 0; @@ -822,6 +824,10 @@ function conversation_fetch_comments($thread_items) { $parentlines[] = $lineno; } + if ($row['gravity'] == GRAVITY_PARENT) { + $row['pinned'] = $pinned; + } + $comments[] = $row; $lineno++; } @@ -872,7 +878,7 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid) $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity']), $condition, $params); - $comments = conversation_fetch_comments($thread_items); + $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false); if (count($comments) != 0) { $items = array_merge($items, $comments); diff --git a/src/Model/Item.php b/src/Model/Item.php index dde33437a5..159fac455b 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -148,11 +148,13 @@ class Item extends BaseObject * * @param integer $uid User ID * @param array $selected Array of selected fields, empty for all + * @param array $condition Array of fields for condition + * @param array $params Array of several parameters * * @return boolean|object * @throws \Exception */ - public static function selectPinned(int $uid, array $selected = []) + public static function selectPinned(int $uid, array $selected = [], array $condition = [], $params = []) { $useritems = DBA::select('user-item', ['iid'], ['uid' => $uid, 'pinned' => true]); if (!DBA::isResult($useritems)) { @@ -165,7 +167,25 @@ class Item extends BaseObject } DBA::close($useritems); - return self::selectThreadForUser($uid, $selected, ['iid' => $pinned]); + if (empty($pinned)) { + return []; + } + + if (empty($condition) || !is_array($condition)) { + $condition = ['iid' => $pinned]; + } else { + reset($condition); + $first_key = key($condition); + if (!is_int($first_key)) { + $condition['iid'] = $pinned; + } else { + $values_string = substr(str_repeat("?, ", count($pinned)), 0, -2); + $condition[0] = '(' . $condition[0] . ") AND `iid` IN (" . $values_string . ")"; + $condition = array_merge($condition, $pinned); + } + } + + return self::selectThreadForUser($uid, $selected, $condition, $params); } /** diff --git a/src/Module/Profile.php b/src/Module/Profile.php index 60dc6aa1b4..aab5918567 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -350,7 +350,7 @@ class Profile extends BaseModule $items = DBA::toArray($items_stmt); if ($pager->getStart() == 0 && !empty($a->profile['profile_uid'])) { - $pinned_items = Item::selectPinned($a->profile['profile_uid'], ['uri']); + $pinned_items = Item::selectPinned($a->profile['profile_uid'], ['uri', 'pinned'], ['true' . $sql_extra]); $pinned = Item::inArray($pinned_items); $items = array_merge($items, $pinned); } diff --git a/src/Object/Post.php b/src/Object/Post.php index f9119ee032..981bf76c7d 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -193,6 +193,8 @@ class Post extends BaseObject if (DBA::isResult($parent)) { $origin = $parent['origin']; } + } elseif ($item['pinned']) { + $pinned = L10n::t('pinned item'); } if ($origin && ($item['id'] != $item['parent']) && ($item['network'] == Protocol::ACTIVITYPUB)) { @@ -288,10 +290,6 @@ class Post extends BaseObject if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) { if ($origin) { - if ($item['pinned']) { - $pinned = L10n::t('pinned item'); - } - $ispinned = ($item['pinned'] ? 'pinned' : 'unpinned'); $pin = [ From 06a4461fc4366164174b8d36ae5f0fa9ffdefd5b Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 8 Nov 2019 10:25:50 +0000 Subject: [PATCH 2/3] Improved icons --- view/theme/duepuntozero/style.css | 4 ++++ view/theme/frio/templates/wall_thread.tpl | 4 ++-- view/theme/smoothly/style.css | 1 + view/theme/vier/templates/wall_thread.tpl | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/view/theme/duepuntozero/style.css b/view/theme/duepuntozero/style.css index 9bad9d3480..3009e36a65 100644 --- a/view/theme/duepuntozero/style.css +++ b/view/theme/duepuntozero/style.css @@ -1162,6 +1162,10 @@ input#dfrn-url { margin-left: 10px; float: left; } +.pin-item { + margin-left: 10px; + float: left; +} .star-item { margin-left: 10px; float: left; diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index 31f13ea379..94955581d1 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -120,8 +120,8 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.pin}}
  • - - + +
  • {{/if}} diff --git a/view/theme/smoothly/style.css b/view/theme/smoothly/style.css index edbd705747..aa9a8e543b 100644 --- a/view/theme/smoothly/style.css +++ b/view/theme/smoothly/style.css @@ -1615,6 +1615,7 @@ ul .sidebar-group-li .icon { margin-right: 20px; } +.pin-item, .star-item, .tag-item { float: left; diff --git a/view/theme/vier/templates/wall_thread.tpl b/view/theme/vier/templates/wall_thread.tpl index c27ec33cdc..169d1b2140 100644 --- a/view/theme/vier/templates/wall_thread.tpl +++ b/view/theme/vier/templates/wall_thread.tpl @@ -124,8 +124,8 @@ {{/if}} {{if $item.pin}} - {{$item.pin.do}} - {{$item.pin.undo}} + {{$item.pin.do}} + {{$item.pin.undo}} {{/if}} {{if $item.star}} {{$item.star.do}} From 5d1ced796b507c4a323c1a5b9dcbe97a41828795 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 8 Nov 2019 18:07:54 +0000 Subject: [PATCH 3/3] Icons do now appear on smoothly and duepuntezero as well --- view/theme/duepuntozero/style.css | 2 ++ view/theme/smoothly/style.css | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/view/theme/duepuntozero/style.css b/view/theme/duepuntozero/style.css index 3009e36a65..bb5a25490e 100644 --- a/view/theme/duepuntozero/style.css +++ b/view/theme/duepuntozero/style.css @@ -3205,6 +3205,8 @@ aside input[type='text'] { .on { background-position: -144px -32px; } .off { background-position: 0px -48px; } +.pinned { background-position: -16px -48px; } +.unpinned { background-position: -32px -48px; } .starred { background-position: -16px -48px; } .unstarred { background-position: -32px -48px; } .tagged { background-position: -48px -48px; } diff --git a/view/theme/smoothly/style.css b/view/theme/smoothly/style.css index aa9a8e543b..ea84f01668 100644 --- a/view/theme/smoothly/style.css +++ b/view/theme/smoothly/style.css @@ -3991,6 +3991,15 @@ margin-left: 0px; height: 20px; background-image: url("images/icons.png"); } +.pinned { + background-image: url("images/star.png"); + repeat: no-repeat; +} +.unpinned { + background-image: url("images/premium.png"); + repeat: no-repeat; +} + .starred { background-image: url("images/star.png"); repeat: no-repeat;