]> git.mxchange.org Git - friendica.git/commitdiff
Create new Post/Share module class
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 4 Nov 2022 17:01:25 +0000 (13:01 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Fri, 4 Nov 2022 17:02:01 +0000 (13:02 -0400)
src/Module/Post/Share.php [new file with mode: 0644]
static/routes.config.php
view/templates/jot-header.tpl
view/theme/frio/templates/jot-header.tpl
view/theme/smoothly/templates/jot-header.tpl

diff --git a/src/Module/Post/Share.php b/src/Module/Post/Share.php
new file mode 100644 (file)
index 0000000..df15dbb
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Post;
+
+use Friendica\App;
+use Friendica\Content;
+use Friendica\Core\L10n;
+use Friendica\Core\Session\Capability\IHandleUserSessions;
+use Friendica\Core\System;
+use Friendica\Model\Item;
+use Friendica\Model\Post;
+use Friendica\Module\Response;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
+
+/**
+ * Generates a share BBCode block for the provided item.
+ *
+ * Only used in Ajax calls
+ */
+class Share extends \Friendica\BaseModule
+{
+       /** @var IHandleUserSessions */
+       private $session;
+       /** @var Content\Item */
+       private $contentItem;
+
+       public function __construct(Content\Item $contentItem, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
+       {
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+               
+               $this->session     = $session;
+               $this->contentItem = $contentItem;
+       }
+
+       protected function rawContent(array $request = [])
+       {
+               $post_id = $this->parameters['post_id'];
+               if (!$post_id || !$this->session->getLocalUserId()) {
+                       System::httpError(403);
+               }
+
+               $item = Post::selectFirst(['private', 'body', 'uri'], ['id' => $post_id]);
+               if (!$item || $item['private'] == Item::PRIVATE) {
+                       System::httpError(404);
+               }
+
+               $shared = $this->contentItem->getSharedPost($item, ['uri']);
+               if ($shared && empty($shared['comment'])) {
+                       $content = '[share]' . $shared['post']['uri'] . '[/share]';
+               } else {
+                       $content = '[share]' . $item['uri'] . '[/share]';
+               }
+
+               System::httpExit($content);
+       }
+}
index 85171d2b7e6dd9ab01bd88cc281abb1fc19736de..3cb1b47e226166e7d5149ee16f3e4d5b9a85ef1f 100644 (file)
@@ -534,6 +534,7 @@ return [
        '/ping'              => [Module\Notifications\Ping::class, [R::GET]],
 
        '/post' => [
+               '/{post_id}/share'                                         => [Module\Post\Share::class,      [R::GET         ]],
                '/{item_id}/tag/add'                                       => [Module\Post\Tag\Add::class,    [        R::POST]],
                '/{item_id}/tag/remove[/{tag_name}]'                       => [Module\Post\Tag\Remove::class, [R::GET, R::POST]],
        ],
index 9b47ed56a71c39d048b9700c2a4c9ba040f30db1..a67f9c3f0c35ef0bdea97a1f6061c5c3cf4b3210 100644 (file)
@@ -141,7 +141,7 @@ function enableOnUser(){
                if ($('#jot-popup').length != 0) $('#jot-popup').show();
 
                $('#like-rotator-' + id).show();
-               $.get('share/' + id, function(data) {
+               $.get('post/' + id + '/share', function(data) {
                        if (!editor) $("#profile-jot-text").val("");
                        initEditor(function(){
                                addeditortext(data);
index 23aa8663fb64652cad55cc3f89a5dd6cf1e7ca17..25a02b9b6095909134bf256fc03f13432ec34e72 100644 (file)
        }
 
        function jotShare(id) {
-               $.get('share/' + id, function(data) {
+               $.get('post/' + id + '/share', function(data) {
                        // remove the former content of the text input
                        $("#profile-jot-text").val("");
                        initEditor(function(){
index a2be0430243334098f532cc140fc8ff619fdbf38..69233b92602661bce395a98397f32e0df4b2773f 100644 (file)
@@ -168,13 +168,13 @@ function enableOnUser(){
 
        function jotShare(id) {
                $('#like-rotator-' + id).show();
-               $.get('share/' + id, function(data) {
-                               if (!editor) $("#profile-jot-text").val("");
-                               initEditor(function(){
-                                       addeditortext(data);
-                                       $('#like-rotator-' + id).hide();
-                                       $(window).scrollTop(0);
-                               });
+               $.get('post/' + id + '/share', function(data) {
+                       if (!editor) $("#profile-jot-text").val("");
+                       initEditor(function(){
+                               addeditortext(data);
+                               $('#like-rotator-' + id).hide();
+                               $(window).scrollTop(0);
+                       });
                });
        }