From 4065f713820c92e629292c7b4208742f26cabc88 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 9 Sep 2020 16:49:03 -0400 Subject: [PATCH] Fix qcomment addon - Initialize $qcomment template variable everywhere it is expected - Remove addon Javascript from core head template --- mod/photos.php | 37 ++++++++++++++++++++++++++++++++++--- src/Object/Post.php | 12 +++--------- view/templates/head.tpl | 16 ---------------- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index 65e8651b20..f078473a95 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -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) ]); } diff --git a/src/Object/Post.php b/src/Object/Post.php index 071652b5e4..d9f0d44d67 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -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) ]); } diff --git a/view/templates/head.tpl b/view/templates/head.tpl index 707cdf79f0..69980b652b 100644 --- a/view/templates/head.tpl +++ b/view/templates/head.tpl @@ -129,22 +129,6 @@ $("#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("<","<"); - ins = ins.replace(">",">"); - ins = ins.replace("&","&"); - ins = ins.replace(""","\""); - $("#comment-edit-text-" + id).val(tmpStr + ins); - $(obj).val(""); - } - function showHideCommentBox(id) { if ($("#comment-edit-form-" + id).is(":visible")) { $("#comment-edit-form-" + id).hide();