Fix qcomment addon
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 9 Sep 2020 20:49:03 +0000 (16:49 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 9 Sep 2020 20:49:03 +0000 (16:49 -0400)
- Initialize $qcomment template variable everywhere it is expected
- Remove addon Javascript from core head template

mod/photos.php
src/Object/Post.php
view/templates/head.tpl

index 65e8651..f078473 100644 (file)
@@ -25,6 +25,7 @@ use Friendica\Content\Nav;
 use Friendica\Content\Pager;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\ACL;
+use Friendica\Core\Addon;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
@@ -1378,6 +1379,16 @@ function photos_content(App $a)
 
                        if (!DBA::isResult($items)) {
                                if (($can_post || Security::canWriteToUserWall($owner_uid))) {
+                                       /*
+                                        * Hmmm, code depending on the presence of a particular addon?
+                                        * This should be better if done by a hook
+                                        */
+                                       $qcomment = null;
+                                       if (Addon::isEnabled('qcomment')) {
+                                               $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
+                                               $qcomment = $words ? explode("\n", $words) : [];
+                                       }
+
                                        $comments .= Renderer::replaceMacros($cmnt_tpl, [
                                                '$return_path' => '',
                                                '$jsreload' => $return_path,
@@ -1392,7 +1403,7 @@ function photos_content(App $a)
                                                '$preview' => DI::l10n()->t('Preview'),
                                                '$loading' => DI::l10n()->t('Loading...'),
                                                '$sourceapp' => DI::l10n()->t($a->sourcename),
-                                               '$ww' => '',
+                                               '$qcomment' => $qcomment,
                                                '$rand_num' => Crypto::randomDigits(12)
                                        ]);
                                }
@@ -1425,6 +1436,16 @@ function photos_content(App $a)
                                }
 
                                if (($can_post || Security::canWriteToUserWall($owner_uid))) {
+                                       /*
+                                        * Hmmm, code depending on the presence of a particular addon?
+                                        * This should be better if done by a hook
+                                        */
+                                       $qcomment = null;
+                                       if (Addon::isEnabled('qcomment')) {
+                                               $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
+                                               $qcomment = $words ? explode("\n", $words) : [];
+                                       }
+
                                        $comments .= Renderer::replaceMacros($cmnt_tpl,[
                                                '$return_path' => '',
                                                '$jsreload' => $return_path,
@@ -1438,7 +1459,7 @@ function photos_content(App $a)
                                                '$submit' => DI::l10n()->t('Submit'),
                                                '$preview' => DI::l10n()->t('Preview'),
                                                '$sourceapp' => DI::l10n()->t($a->sourcename),
-                                               '$ww' => '',
+                                               '$qcomment' => $qcomment,
                                                '$rand_num' => Crypto::randomDigits(12)
                                        ]);
                                }
@@ -1488,6 +1509,16 @@ function photos_content(App $a)
                                        ]);
 
                                        if (($can_post || Security::canWriteToUserWall($owner_uid))) {
+                                               /*
+                                                * Hmmm, code depending on the presence of a particular addon?
+                                                * This should be better if done by a hook
+                                                */
+                                               $qcomment = null;
+                                               if (Addon::isEnabled('qcomment')) {
+                                                       $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
+                                                       $qcomment = $words ? explode("\n", $words) : [];
+                                               }
+
                                                $comments .= Renderer::replaceMacros($cmnt_tpl, [
                                                        '$return_path' => '',
                                                        '$jsreload' => $return_path,
@@ -1501,7 +1532,7 @@ function photos_content(App $a)
                                                        '$submit' => DI::l10n()->t('Submit'),
                                                        '$preview' => DI::l10n()->t('Preview'),
                                                        '$sourceapp' => DI::l10n()->t($a->sourcename),
-                                                       '$ww' => '',
+                                                       '$qcomment' => $qcomment,
                                                        '$rand_num' => Crypto::randomDigits(12)
                                                ]);
                                        }
index 071652b..d9f0d44 100644 (file)
@@ -905,21 +905,16 @@ class Post
 
                $comment_box = '';
                $conv = $this->getThread();
-               $ww = '';
-               if (($conv->getMode() === 'network') && $this->isWallToWall()) {
-                       $ww = 'ww';
-               }
 
                if ($conv->isWritable() && $this->isWritable()) {
-                       $qcomment = null;
-
                        /*
                         * Hmmm, code depending on the presence of a particular addon?
                         * This should be better if done by a hook
                         */
+                       $qcomment = null;
                        if (Addon::isEnabled('qcomment')) {
-                               $qc = ((local_user()) ? DI::pConfig()->get(local_user(), 'qcomment', 'words') : null);
-                               $qcomment = (($qc) ? explode("\n", $qc) : null);
+                               $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
+                               $qcomment = $words ? explode("\n", $words) : [];
                        }
 
                        // Fetch the user id from the parent when the owner user is empty
@@ -961,7 +956,6 @@ class Post
                                '$preview'     => DI::l10n()->t('Preview'),
                                '$indent'      => $indent,
                                '$sourceapp'   => DI::l10n()->t($a->sourcename),
-                               '$ww'          => $conv->getMode() === 'network' ? $ww : '',
                                '$rand_num'    => Crypto::randomDigits(12)
                        ]);
                }
index 707cdf7..69980b6 100644 (file)
                $("#comment-edit-text-" + id).val(tmpStr + ins);
        }
 
-       function qCommentInsert(obj,id) {
-               var tmpStr = $("#comment-edit-text-" + id).val();
-               if (tmpStr == "") {
-                       $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
-                       $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
-                       openMenu("comment-edit-submit-wrapper-" + id);
-               }
-               var ins = $(obj).val();
-               ins = ins.replace("&lt;","<");
-               ins = ins.replace("&gt;",">");
-               ins = ins.replace("&amp;","&");
-               ins = ins.replace("&quot;","\"");
-               $("#comment-edit-text-" + id).val(tmpStr + ins);
-               $(obj).val("");
-       }
-
        function showHideCommentBox(id) {
                if ($("#comment-edit-form-" + id).is(":visible")) {
                        $("#comment-edit-form-" + id).hide();