diff --git a/CHANGELOG_DEV.md b/CHANGELOG_DEV.md index 72c1e3ed02..96b552f26c 100644 --- a/CHANGELOG_DEV.md +++ b/CHANGELOG_DEV.md @@ -1,6 +1,7 @@ 1.10.0-beta.1 (Unreleased) -------------------------- +- Enh #4399: Deep comment link to select and mark comment in content - Enh #4242: More failsave module loading when reading module config - Enh #5197: Default .htaccess - Remove Options +FollowSymLinks - Enh #4495: Allow to lock comments per content diff --git a/protected/humhub/modules/comment/activities/NewComment.php b/protected/humhub/modules/comment/activities/NewComment.php index 415f94815a..0841400383 100644 --- a/protected/humhub/modules/comment/activities/NewComment.php +++ b/protected/humhub/modules/comment/activities/NewComment.php @@ -8,9 +8,11 @@ namespace humhub\modules\comment\activities; +use humhub\modules\comment\models\Comment; use Yii; use humhub\modules\activity\components\BaseActivity; use humhub\modules\activity\interfaces\ConfigurableActivityInterface; +use yii\helpers\Url; /** * NewComment activity @@ -30,6 +32,11 @@ class NewComment extends BaseActivity implements ConfigurableActivityInterface */ public $viewName = "newComment"; + /** + * @var Comment + */ + public $source; + /** * @inheritdoc */ @@ -46,4 +53,12 @@ class NewComment extends BaseActivity implements ConfigurableActivityInterface return Yii::t('CommentModule.base', 'Whenever a new comment was written.'); } + /** + * @inheritdoc + */ + public function getUrl() + { + return Url::to(['/comment/perma', 'id' => $this->source->id], true); + } + } diff --git a/protected/humhub/modules/comment/controllers/PermaController.php b/protected/humhub/modules/comment/controllers/PermaController.php new file mode 100644 index 0000000000..a1363969a7 --- /dev/null +++ b/protected/humhub/modules/comment/controllers/PermaController.php @@ -0,0 +1,44 @@ + $id]); + + if (!$comment || !$comment->canRead()) { + throw new NotFoundHttpException(); + } + + return $this->redirect($comment->content->container->createUrl(null, [ + 'contentId' => $comment->content->id, + 'commentId' => $comment->id, + ])); + } + +} diff --git a/protected/humhub/modules/comment/models/Comment.php b/protected/humhub/modules/comment/models/Comment.php index 83e3ba4e90..e7ccf10d4a 100644 --- a/protected/humhub/modules/comment/models/Comment.php +++ b/protected/humhub/modules/comment/models/Comment.php @@ -201,10 +201,11 @@ class Comment extends ContentAddonActiveRecord implements ContentOwner * @param $model * @param $id * @param int|null $limit when null the default limit will used + * @param int|null $currentCommentId ID of the current Comment which should be visible on the limited result * * @return Comment[] the comments */ - public static function GetCommentsLimited($model, $id, $limit = null) + public static function GetCommentsLimited($model, $id, $limit = null, $currentCommentId = null) { if ($limit === null) { /** @var Module $module */ @@ -220,7 +221,11 @@ class Comment extends ContentAddonActiveRecord implements ContentOwner $query = Comment::find(); $query->offset($commentCount - $limit); - $query->orderBy('created_at ASC'); + if (Comment::findOne(['id' => $currentCommentId])) { + $query->orderBy('`comment`.`id` <= ' . (intval($currentCommentId) + intval($limit) - 1)); + } else { + $query->orderBy('created_at ASC'); + } $query->limit($limit); $query->where(['object_model' => $model, 'object_id' => $id]); $query->joinWith('user'); diff --git a/protected/humhub/modules/comment/resources/js/humhub.comment.js b/protected/humhub/modules/comment/resources/js/humhub.comment.js index d9c43f64ee..d12a2d6a31 100644 --- a/protected/humhub/modules/comment/resources/js/humhub.comment.js +++ b/protected/humhub/modules/comment/resources/js/humhub.comment.js @@ -121,10 +121,12 @@ humhub.module('comment', function (module, require, $) { return Widget.instance(this.$.find('div.humhub-ui-richtext:first')); }; - Comment.prototype.delete = function () { + Comment.prototype.delete = function (evt) { var $form = this.$.parent().siblings('.comment_create'); var hideHr = !this.isNestedComment() && $form.length && !this.$.siblings('.media').length; + this.$.data('content-delete-url', evt.$trigger.data('content-delete-url')); + this.super('delete', {modal: module.config.modal.delteConfirm}).then(function ($confirm) { if ($confirm) { module.log.success('success.delete'); diff --git a/protected/humhub/modules/comment/widgets/Comment.php b/protected/humhub/modules/comment/widgets/Comment.php index 65f4db40d8..9328d34be4 100644 --- a/protected/humhub/modules/comment/widgets/Comment.php +++ b/protected/humhub/modules/comment/widgets/Comment.php @@ -8,7 +8,6 @@ namespace humhub\modules\comment\widgets; -use yii\helpers\Url; use humhub\components\Widget; /** @@ -28,28 +27,26 @@ class Comment extends Widget */ public $justEdited = false; + /** + * @var string Default style class of div wrapper around Comment block + */ + public $defaultClass = 'media'; + + /** + * @var string Additional style class of div wrapper around Comment block + */ + public $additionalClass = ''; + /** * @inheritdoc */ public function run() { - $deleteUrl = Url::to(['/comment/comment/delete', - 'objectModel' => $this->comment->object_model, 'objectId' => $this->comment->object_id, 'id' => $this->comment->id]); - $editUrl = Url::to(['/comment/comment/edit', - 'objectModel' => $this->comment->object_model, 'objectId' => $this->comment->object_id, 'id' => $this->comment->id]); - $loadUrl = Url::to(['/comment/comment/load', - 'objectModel' => $this->comment->object_model, 'objectId' => $this->comment->object_id, 'id' => $this->comment->id]); - return $this->render('comment', [ 'comment' => $this->comment, 'user' => $this->comment->user, - 'justEdited' => $this->justEdited, - 'deleteUrl' => $deleteUrl, - 'editUrl' => $editUrl, - 'loadUrl' => $loadUrl, 'createdAt' => $this->comment->created_at, - 'canEdit' => $this->comment->canEdit(), - 'canDelete' => $this->comment->canDelete(), + 'class' => trim($this->defaultClass . ' ' . $this->additionalClass), ]); } diff --git a/protected/humhub/modules/comment/widgets/CommentControls.php b/protected/humhub/modules/comment/widgets/CommentControls.php new file mode 100644 index 0000000000..10d5234c02 --- /dev/null +++ b/protected/humhub/modules/comment/widgets/CommentControls.php @@ -0,0 +1,95 @@ +initControls(); + } + + public function initControls() + { + $this->addEntry(new MenuLink([ + 'label' => Yii::t('CommentModule.base', 'Permalink'), + 'icon' => 'link', + 'url' => '#', + 'htmlOptions' => [ + 'data-action-click' => 'content.permalink', + 'data-content-permalink' => Url::to(['/comment/perma', 'id' => $this->comment->id], true), + 'data-content-permalink-title' => Yii::t('CommentModule.base', 'Permalink to this comment'), + + ], + 'sortOrder' => 100, + ])); + + if ($this->comment->canEdit()) { + $this->addEntry(new EditLink(['sortOrder' => 200, 'comment' => $this->comment])); + } + + if ($this->comment->canDelete()) { + $deleteUrl = Url::to(['/comment/comment/delete', 'objectModel' => $this->comment->object_model, + 'objectId' => $this->comment->object_id, + 'id' => $this->comment->id, + ]); + + $this->addEntry(new MenuLink([ + 'label' => Yii::t('CommentModule.base', 'Delete'), + 'icon' => 'delete', + 'url' => '#', + 'htmlOptions' => [ + 'data-action-click' => 'delete', + 'data-content-delete-url' => $deleteUrl, + ], + 'sortOrder' => 300, + ])); + } + } + + + /** + * @inheritdoc + */ + public function getAttributes() + { + return [ + 'class' => 'nav nav-pills preferences' + ]; + } + +} diff --git a/protected/humhub/modules/comment/widgets/Comments.php b/protected/humhub/modules/comment/widgets/Comments.php index 12caa88721..b89be422ae 100644 --- a/protected/humhub/modules/comment/widgets/Comments.php +++ b/protected/humhub/modules/comment/widgets/Comments.php @@ -36,11 +36,14 @@ class Comments extends Widget $objectModel = get_class($this->object); $objectId = $this->object->getPrimaryKey(); + $streamQuery = Yii::$app->request->getQueryParam('StreamQuery'); + $currentCommentId = empty($streamQuery['commentId']) ? null : $streamQuery['commentId']; + // Count all Comments $commentCount = CommentModel::GetCommentCount($objectModel, $objectId); $comments = []; if ($commentCount !== 0) { - $comments = CommentModel::GetCommentsLimited($objectModel, $objectId, $module->commentsPreviewMax); + $comments = CommentModel::GetCommentsLimited($objectModel, $objectId, $module->commentsPreviewMax, $currentCommentId); } $isLimited = ($commentCount > $module->commentsPreviewMax); @@ -48,6 +51,7 @@ class Comments extends Widget return $this->render('comments', [ 'object' => $this->object, 'comments' => $comments, + 'currentCommentId' => $currentCommentId, 'objectModel' => $objectModel, 'objectId' => $objectId, 'id' => $this->object->getUniqueId(), diff --git a/protected/humhub/modules/comment/widgets/EditLink.php b/protected/humhub/modules/comment/widgets/EditLink.php new file mode 100644 index 0000000000..aa1f61df68 --- /dev/null +++ b/protected/humhub/modules/comment/widgets/EditLink.php @@ -0,0 +1,53 @@ + $this->comment->object_model, + 'objectId' => $this->comment->object_id, + 'id' => $this->comment->id, + ]); + + $loadUrl = Url::to(['/comment/comment/load', + 'objectModel' => $this->comment->object_model, + 'objectId' => $this->comment->object_id, + 'id' => $this->comment->id, + ]); + + return Html::a(Icon::get('edit') . ' ' . Yii::t('CommentModule.base', 'Edit'), '#', + ['class' => 'comment-edit-link', 'data-action-click' => 'edit', 'data-action-url' => $editUrl]) . + Html::a(Icon::get('edit') . ' ' . Yii::t('CommentModule.base', 'Cancel Edit'), '#', + ['class' => 'comment-cancel-edit-link', 'data-action-click' => 'cancelEdit', 'data-action-url' => $loadUrl, 'style' => 'display:none']); + } + +} diff --git a/protected/humhub/modules/comment/widgets/views/comment.php b/protected/humhub/modules/comment/widgets/views/comment.php index 0fc102c42e..f018a489c1 100644 --- a/protected/humhub/modules/comment/widgets/views/comment.php +++ b/protected/humhub/modules/comment/widgets/views/comment.php @@ -1,72 +1,28 @@ getModule('comment'); - +/* @var $class string */ ?> -