Redirect back to referer if available, ensuring that only site URLs
are allowed to avoid phishing.  If it's an AJAX request render the
comment in it's new state

@param Comment $comment
@return DBHTMLText|HTTPResponse|false
185398
private function renderChangedCommentState($comment)
    {
        $referer = $this->request->getHeader('Referer');

        // Render comment using AJAX
        if ($this->request->isAjax()) {
            return $comment->renderWith('Includes/CommentsInterface_singlecomment');
        }

        // Redirect to either the comment or start of the page
        if (empty($referer)) {
            return $this->redirectBack();
        }

        // Redirect to the comment, but check for phishing
        $url = $referer . '#comment-' . $comment->ID;
        // absolute redirection URLs not located on this site may cause phishing
        if (Director::is_site_url($url)) {
            return $this->redirect($url);
        }

        return false;
    }
1181151
public function fromComment($comment, $context = null)
    {
        if ($context === null) {
            $context = new Context(['comment' => $comment]);
        } else {
            $context->comment = $comment;
        }
        try {
            self::$context = $context;
            if ($context->is('annotations') === false) {
                $context->annotations = [];
            }
            $comment = preg_replace_callback(
                '/^[\t ]*\*[\t ]+/m',
                function ($match) {
                    // Replace leading tabs with spaces.
                    // Workaround for http://www.doctrine-project.org/jira/browse/DCOM-255
                    return str_replace("\t", ' ', $match[0]);
                },
                $comment
            );
            $annotations = $this->docParser->parse($comment, $context);
            self::$context = null;
            return $annotations;
        } catch (Exception $e) {
            self::$context = null;
            if (preg_match('/^(.+) at position ([0-9]+) in ' . preg_quote((string)$context, '/') . '\.$/', $e->getMessage(), $matches)) {
                $errorMessage = $matches[1];
                $errorPos = (int)$matches[2];
                $atPos = strpos($comment, '@');
                $context->line += substr_count($comment, "\n", 0, $atPos + $errorPos);
                $lines = explode("\n", substr($comment, $atPos, $errorPos));
                $context->character = strlen(array_pop($lines)) + 1; // position starts at 0 character starts at 1
                Logger::warning(new Exception($errorMessage . ' in ' . $context, $e->getCode(), $e));
            } else {
                Logger::warning($e);
            }
            return [];
        }
    }
722637
private function stripDocComment(string $comment): string
    {
        $comment = trim(preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]{0,1}(.*)?#u', '$1', $comment));

        // reg ex above is not able to remove */ from a single line docblock
        if (substr($comment, -2) === '*/') {
            $comment = trim(substr($comment, 0, -2));
        }

        return str_replace(["\r\n", "\r"], "\n", $comment);
    }
106301
public function add($comment)
    {
        if (is_array($comment)) {
            $this->collection[] = new Comment($comment);
        } elseif (is_object($comment) && $comment instanceof Comment) {
            $this->collection[] = $comment;
        }

        return $this;
    }
145621
public function renderComment(Event $event, $comment, $options = [])
    {
        $View = $event->subject();
        $html = $View->element('Comment.render_comment', compact('comment', 'options'));

        return $html;
    }
1303783
public function addComment($user, string $comment) : Comment
    {
        return $this->comments()->create([
            'user_id' => $user->id,
            'comment' => $comment,
        ]);
    }
1169836
public function setComment(\Innova\CollecticielBundle\Entity\Comment $comment)
    {
        $this->comment = $comment;

        return $this;
    }
117007
public function update(Request $request, Comment $comment)
    {
        $attributes = $request->validate([
            'text' => 'required'
        ]);

        tap($comment)
            ->update($attributes)
            ->clearMentions()
            ->mention($request->mentions);

        return back();
    }
377698
public function getCommentAuthorLink(Comment $comment)
    {
        if (!$user = $comment->getUser()) {
            if ((!$authorUrl = $comment->getAuthorUrl()) || !preg_match('/^http(s)?:\/\/.+$/', $authorUrl)) {
                return $comment->getAuthor();
            }

            return sprintf('<a href="%s" rel="nofollow" target="_new">%s</a>', $authorUrl, $comment->getAuthor());
        }

        if ((!$userUrl = $user->getUrl()) || !preg_match('/^http(s)?:\/\/.+$/', $userUrl)) {
            return $user->getDisplayName();
        }

        return sprintf('<a href="%s" rel="nofollow" target="_new">%s</a>', $userUrl, $user->getDisplayName());
    }
251162
public function edit(Comment $comment)
    {
        $this->authorize($comment);

        pageinfo([
            'title' => __('comments.edit_page'),
            'robots' => 'noindex,follow',
        ]);

        return $this->makeResponse('edit', compact('comment'));
    }
557968
public function remove(Comment $comment)
    {
        $comment->delete();

        Alert::info(__('Comment was removed'));

        return redirect()->route('platform.systems.comments');
    }
1046903
public function addComment($comment)
    {
        if (is_string($comment)) {
            $comment = Placeholder::replaceCommentPlaceholders($comment, true);

            $this->comments[] = $comment;
        } else {
            throw new \InvalidArgumentException(
                "Invalid type '" . gettype($comment). "' for argument 'comment' given."
            );
        }

        return $this;
    }
11549
public function hasAccessToComment($commentID)
    {

        $this->isLoggedIn();

        $userid = $this->di->get("session")->get("userid");
        $comment = new Comment();
        $comment->setDb($this->di->get("db"));
        $user = new User();
        $user->setDb($this->di->get("db"));

        $user->find("id", $userid);
        $comment->find("id", $commentID);

        if (($comment->user_id == $userid) || $this->isAdmin()) {
            return true;
        }
        $this->di->get("response")->redirect("user");
        return false;
    }
1188776
public function addComment($comment)
    {
        if(Yii::$app->params['commentNeedApproval'])
            $comment->status = Comment::STATUS_PENDING;
        else
            $comment->status = Comment::STATUS_APPROVED;
        // set model and parent_id (parent model ID)
        $comment->model = self::COMMENT_FOR;
        $comment->parent_id = $this->id;
        $comment->user_id = \Yii::$app->user->id;
        if($comment->thread == '-')
            // set new thread
            $comment->thread = time() . uniqid();
        else
            // unmark previous comment
            Yii::$app->db->createCommand("UPDATE {{%comment}} SET last=0 WHERE thread='{$comment->thread}' AND last=1")->execute();
        // mark only last comment in a thread
        $comment->last = 1;
        if($comment->save()) {
            if(Yii::$app->params['notifyResponsibleAboutComment'])
                $comment->trigger(Comment::EVENT_JUST_ADDED);
            $comment->content = '';
            return true;
        } else
            return false;
    }
1344796
function newComment($post_id, array $comment)
    {
        $params = array(1, $this->username, $this->password, $post_id, $comment);

        return $this->sendRequest('wp.newComment', $params);
    }
1067563
public static function create($comment)
    {
        // If numeric, create the comment
        if (is_numeric($comment)) {
            // Retrieve the transient
            $transientKey = sprintf('WPMVC\Models\Comment(%d)', $comment);
            $storedData = get_transient($transientKey);
            // If the transient doesn't yet exist, query for it!
            if ($storedData === false) {
                // Retrieve the comment object
                $comment = get_comment(intval($comment));
                // Store the transient
                set_transient($transientKey, $comment, $this->transientTimeout);
            } else {
                $comment = $storedData;
            }
        } elseif (is_array($comment)) {
            // Convert array into object
            $comment = (object) $comment;
        }
        return new static($comment);
    }
481732
public function save(Comment $comment, Request $request)
    {
        $comment
            ->fill($request->get('comment'))
            ->save();

        Alert::info(__('Comment was saved'));

        return redirect()->route('platform.systems.comments');
    }