]> git.mxchange.org Git - friendica.git/commitdiff
We can now pin our own posts
authorMichael <heluecht@pirati.ca>
Thu, 7 Nov 2019 05:39:15 +0000 (05:39 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 7 Nov 2019 05:39:15 +0000 (05:39 +0000)
database.sql
src/Model/Item.php
src/Object/Post.php
static/dbstructure.config.php
static/routes.config.php
view/js/main.js
view/templates/wall_thread.tpl
view/theme/frio/templates/wall_thread.tpl
view/theme/quattro/templates/wall_thread.tpl
view/theme/smoothly/templates/wall_thread.tpl
view/theme/vier/templates/wall_thread.tpl

index d42f61f902ac7f5651d6cf8207a952c0f9384da4..e80c5cda221667780d3dd4d06fc9990809a437b3 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
--- Friendica 2019.09-rc (Dalmatian Bellflower)
--- DB_UPDATE_VERSION 1322
+-- Friendica 2019.12-dev (Dalmatian Bellflower)
+-- DB_UPDATE_VERSION 1324
 -- ------------------------------------------
 
 
@@ -1281,6 +1281,7 @@ CREATE TABLE IF NOT EXISTS `user-item` (
        `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
        `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide an item from the user',
        `ignored` boolean COMMENT 'Ignore this thread if set',
+       `pinned` boolean COMMENT 'The item is pinned on the profile page',
         PRIMARY KEY(`uid`,`iid`)
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific item data';
 
index 9501c8e5d240519caed3781703baaa95e3a2e0bf..882aa6444b1e37a6c2f82a50350acbce86ea2123 100644 (file)
@@ -58,7 +58,7 @@ class Item extends BaseObject
                'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
                'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'owner-network',
                'contact-id', 'contact-uid', 'contact-link', 'contact-name', 'contact-avatar',
-               'writable', 'self', 'cid', 'alias',
+               'writable', 'self', 'cid', 'alias', 'pinned',
                'event-id', 'event-created', 'event-edited', 'event-start', 'event-finish',
                'event-summary', 'event-desc', 'event-location', 'event-type',
                'event-nofinish', 'event-adjust', 'event-ignore', 'event-id',
@@ -114,6 +114,35 @@ class Item extends BaseObject
                return self::$legacy_mode;
        }
 
+       /**
+        * Set the pinned state of an item
+        * 
+        * @param integer $iid    Item ID
+        * @param integer $uid    User ID
+        * @param boolean $pinned Pinned state
+        */
+       public static function setPinned(int $iid, int $uid, bool $pinned)
+       {
+               DBA::update('user-item', ['pinned' => $pinned], ['iid' => $iid, 'uid' => $uid], true);
+       }
+
+       /**
+        * Get the pinned state
+        * 
+        * @param integer $iid Item ID
+        * @param integer $uid User ID
+        * 
+        * @return boolean pinned state
+        */
+       public static function getPinned(int $iid, int $uid)
+       {
+               $useritem = DBA::selectFirst('user-item', ['pinned'], ['iid' => $iid, 'uid' => $uid]);
+               if (!DBA::isResult($useritem)) {
+                       return false;
+               }
+               return (bool)$useritem['pinned'];
+       }
+
        /**
         * @brief returns an activity index from an activity string
         *
@@ -585,7 +614,7 @@ class Item extends BaseObject
                        'iaid' => 'internal-iaid'];
 
                if ($usermode) {
-                       $fields['user-item'] = ['ignored' => 'internal-user-ignored'];
+                       $fields['user-item'] = ['pinned', 'ignored' => 'internal-user-ignored'];
                }
 
                $fields['item-activity'] = ['activity', 'activity' => 'internal-activity'];
index babf24e0d6ccd1c1f24ee32fe55de6b65808b534..f3c607ee64411d5cc84c934a6a0348ddc67b99fc 100644 (file)
@@ -140,8 +140,10 @@ class Post extends BaseObject
                $sparkle = '';
                $buttons = '';
                $dropping = false;
+               $pin = false;
                $star = false;
                $ignore = false;
+               $ispinned = "unpinned";
                $isstarred = "unstarred";
                $indent = '';
                $shiny = '';
@@ -284,6 +286,19 @@ class Post extends BaseObject
                                }
 
                                if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) {
+                                       if ($origin) {
+                                               $ispinned = ($item['pinned'] ? 'pinned' : 'unpinned');
+
+                                               $pin = [
+                                                       'do'        => L10n::t('pin'),
+                                                       'undo'      => L10n::t('unpin'),
+                                                       'toggle'    => L10n::t('toggle pin status'),
+                                                       'classdo'   => $item['pinned'] ? 'hidden' : '',
+                                                       'classundo' => $item['pinned'] ? '' : 'hidden',
+                                                       'pinned'   => L10n::t('pinned'),
+                                               ];
+                                       }
+
                                        $isstarred = (($item['starred']) ? "starred" : "unstarred");
 
                                        $star = [
@@ -407,6 +422,8 @@ class Post extends BaseObject
                        'owner_name'      => $owner_name_e,
                        'plink'           => Item::getPlink($item),
                        'edpost'          => $edpost,
+                       'ispinned'        => $ispinned,
+                       'pin'             => $pin,
                        'isstarred'       => $isstarred,
                        'star'            => $star,
                        'ignore'          => $ignore,
index 53f8a8ed44b8b1a3a36b8e057ec5bfcadedb5b7a..65e0b26a6a4bafb1951015f275d50bc450b41cbb 100755 (executable)
@@ -34,7 +34,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1323);
+       define('DB_UPDATE_VERSION', 1324);
 }
 
 return [
@@ -1384,7 +1384,8 @@ return [
                        "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["item" => "id"], "comment" => "Item id"],
                        "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["user" => "uid"], "comment" => "User id"],
                        "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marker to hide an item from the user"],
-                       "ignored" => ["type" => "boolean", "comment" => "Ignore this thread if set"]
+                       "ignored" => ["type" => "boolean", "comment" => "Ignore this thread if set"],
+                       "pinned" => ["type" => "boolean", "comment" => "The item is pinned on the profile page"]
                ],
                "indexes" => [
                        "PRIMARY" => ["uid", "iid"]
index 1f2fe0ad1b98727e4bf1a58d5e8e2656b2cf38ef..339860afe636588723491aca074d94b0fa5dea39 100644 (file)
@@ -179,8 +179,9 @@ return [
                '/{type}/{customize}/{name}' => [Module\Photo::class, [R::GET]],
        ],
 
-       '/pretheme' => [Module\ThemeDetails::class, [R::GET]],
-       '/probe'    => [Module\Debug\Probe::class,  [R::GET]],
+       '/pinned/{item:\d+}' => [Module\Pinned::class,       [R::GET]],
+       '/pretheme'          => [Module\ThemeDetails::class, [R::GET]],
+       '/probe'             => [Module\Debug\Probe::class,  [R::GET]],
 
        '/profile' => [
                '/{nickname}'                                                 => [Module\Profile::class,          [R::GET]],
index 40db7c2a13cfb2b9d6223004a0f5815f8ef42c0e..94644c5dfd2c3467d796b6449f71959cb8e89d6e 100644 (file)
@@ -626,6 +626,25 @@ function dostar(ident) {
        });
 }
 
+function dopin(ident) {
+       ident = ident.toString();
+       $('#like-rotator-' + ident).show();
+       $.get('pinned/' + ident, function(data) {
+               if (data.match(/1/)) {
+                       $('#pinned-' + ident).addClass('pinned');
+                       $('#pinned-' + ident).removeClass('unpinned');
+                       $('#pin-' + ident).addClass('hidden');
+                       $('#unpin-' + ident).removeClass('hidden');
+               } else {
+                       $('#pinned-' + ident).addClass('unpinned');
+                       $('#pinned-' + ident).removeClass('pinned');
+                       $('#pin-' + ident).removeClass('hidden');
+                       $('#unpin-' + ident).addClass('hidden');
+               }
+               $('#like-rotator-' + ident).hide();
+       });
+}
+
 function doignore(ident) {
        ident = ident.toString();
        $('#like-rotator-' + ident).show();
index a4834062c02070c755653506a859023b83bbbf3d..001bdaebb42774a5b45651d7577b31736b168795 100644 (file)
@@ -90,6 +90,9 @@
                                <a class="editpost icon pencil" href="{{$item.edpost.0}}" title="{{$item.edpost.1}}"></a>
                        {{/if}}
 
+                       {{if $item.pin}}
+                       <a href="#" id="pinned-{{$item.id}}" onclick="dopin({{$item.id}}); return false;" class="pin-item icon {{$item.ispinned}}" title="{{$item.pin.toggle}}"></a>
+                       {{/if}}
                        {{if $item.star}}
                        <a href="#" id="starred-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="star-item icon {{$item.isstarred}}" title="{{$item.star.toggle}}"></a>
                        {{/if}}
index 9d8d47355c04cc21753ab5ea21d588dc21b41e2f..cffe1087bd14820f6d4185049e8291f916ba044e 100644 (file)
@@ -118,6 +118,13 @@ as the value of $top_child_total (this is done at the end of this file)
                                        </li>
                                        {{/if}}
 
+                                       {{if $item.pin}}
+                                       <li role="menuitem">
+                                               <button type="button" id="pin-{{$item.id}}" onclick="dopin({{$item.id}});" class="btn-link {{$item.pin.classdo}}" title="{{$item.pin.do}}"><i class="fa fa-check-square-o" aria-hidden="true"></i>&nbsp;{{$item.pin.do}}</button>
+                                               <button type="button" id="unpin-{{$item.id}}" onclick="dopin({{$item.id}});" class="btn-link {{$item.pin.classundo}}" title="{{$item.pin.undo}}"><i class="fa fa-check-square" aria-hidden="true"></i>&nbsp;{{$item.pin.undo}}</button>
+                                       </li>
+                                       {{/if}}
+
                                        {{if $item.star}}
                                        <li role="menuitem">
                                                <button type="button" id="star-{{$item.id}}" onclick="dostar({{$item.id}});" class="btn-link {{$item.star.classdo}}" title="{{$item.star.do}}"><i class="fa fa-star-o" aria-hidden="true"></i>&nbsp;{{$item.star.do}}</button>
index bfb903c7b81d6b465d288008f75324a80f7c6b1b..c3d65000219c6c1a04a7addd54313d8317264716 100644 (file)
                        </div>
 
                        <div class="wall-item-actions-social">
+                       {{if $item.pin}}
+                               <a href="#" id="pin-{{$item.id}}" onclick="dopin({{$item.id}}); return false;"  class="{{$item.pin.classdo}}"  title="{{$item.pin.do}}">{{$item.pin.do}}</a>
+                               <a href="#" id="unpin-{{$item.id}}" onclick="dopin({{$item.id}}); return false;"  class="{{$item.pin.classundo}}"  title="{{$item.pin.undo}}">{{$item.pin.undo}}</a>
+                       {{/if}}
                        {{if $item.star}}
                                <a href="#" id="star-{{$item.id}}" onclick="dostar({{$item.id}}); return false;"  class="{{$item.star.classdo}}"  title="{{$item.star.do}}">{{$item.star.do}}</a>
                                <a href="#" id="unstar-{{$item.id}}" onclick="dostar({{$item.id}}); return false;"  class="{{$item.star.classundo}}"  title="{{$item.star.undo}}">{{$item.star.undo}}</a>
index a4616d9c4ceeeba6711155bc1f7c97d34dec8fe2..7b56c9130fa6aca6c406842c72171a1e2b1f13d7 100644 (file)
                        </div>
                        {{/if}}
 
+                       {{if $item.pin}}
+                       <a href="#" id="pinned-{{$item.id}}" onclick="dopin({{$item.id}}); return false;" class="pin-item icon {{$item.ispinned}}" title="{{$item.pin.toggle}}"></a>
+                       {{/if}}
                        {{if $item.star}}
                        <a href="#" id="starred-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="star-item icon {{$item.isstarred}}" title="{{$item.star.toggle}}"></a>
                        {{/if}}
index eb9c2fe5759f4eb6dac0fd3cd692f14a84056580..1d432ea45306ee0c71b11bae94b47ac26f2c7250 100644 (file)
                            {{/if}}
                        {{/if}}
 
+                       {{if $item.pin}}
+                               <a role="button" id="pin-{{$item.id}}" onclick="dopin({{$item.id}}); return false;"  class="{{$item.pin.classdo}}" title="{{$item.pin.do}}"><i class="icon-pin icon-large"><span class="sr-only">{{$item.pin.do}}</span></i></a>
+                               <a role="button" id="unpin-{{$item.id}}" onclick="dopin({{$item.id}}); return false;"  class="{{$item.pin.classundo}}"  title="{{$item.pin.undo}}"><i class="icon-pin-empty icon-large"><span class="sr-only">{{$item.pin.undo}}</span></i></a>
+                       {{/if}}
                        {{if $item.star}}
                                <a role="button" id="star-{{$item.id}}" onclick="dostar({{$item.id}}); return false;"  class="{{$item.star.classdo}}" title="{{$item.star.do}}"><i class="icon-star icon-large"><span class="sr-only">{{$item.star.do}}</span></i></a>
                                <a role="button" id="unstar-{{$item.id}}" onclick="dostar({{$item.id}}); return false;"  class="{{$item.star.classundo}}"  title="{{$item.star.undo}}"><i class="icon-star-empty icon-large"><span class="sr-only">{{$item.star.undo}}</span></i></a>