From e02c10a58938718bc6345ee64bbb19914abbf472 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Fri, 1 Jan 2016 18:40:11 +0100 Subject: [PATCH] common_render_content doesn't require a Profile now --- classes/Notice.php | 4 +++- lib/dofollowlistitem.php | 6 +----- lib/noticelistitem.php | 7 +------ lib/util.php | 9 +++++---- plugins/QnA/actions/qnanewanswer.php | 9 +-------- plugins/Xmpp/XmppPlugin.php | 8 ++------ scripts/fixup_hashtags.php | 4 +++- scripts/upgrade.php | 4 +++- 8 files changed, 19 insertions(+), 32 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index e53ce8f77b..06edceddab 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -621,7 +621,9 @@ class Notice extends Managed_DataObject if (!empty($rendered)) { $notice->rendered = $rendered; } else { - $notice->rendered = common_render_content($final, $notice); + $notice->rendered = common_render_content($final, + $notice->getProfile(), + $notice->hasParent() ? $notice->getParent() : null); } if (empty($verb)) { diff --git a/lib/dofollowlistitem.php b/lib/dofollowlistitem.php index f3e2420677..f65f7b4cbb 100644 --- a/lib/dofollowlistitem.php +++ b/lib/dofollowlistitem.php @@ -68,11 +68,7 @@ class DoFollowListItem extends NoticeListItem // FIXME: URL, image, video, audio $this->out->elementStart('article', array('class' => 'e-content')); - if (!empty($this->notice->rendered)) { - $html = $this->notice->rendered; - } else { - $html = common_render_content($this->notice->content, $this->notice); - } + $html = $this->notice->getRendered(); if (common_config('nofollow', 'external') == 'sometimes') { // remove the nofollow part diff --git a/lib/noticelistitem.php b/lib/noticelistitem.php index 8c27ae4e84..52dcbc1f67 100644 --- a/lib/noticelistitem.php +++ b/lib/noticelistitem.php @@ -343,13 +343,8 @@ class NoticeListItem extends Widget if (Event::handle('StartShowNoticeContent', array($this->notice, $this->out, $this->out->getScoped()))) { if ($this->maxchars > 0 && mb_strlen($this->notice->content) > $this->maxchars) { $this->out->text(mb_substr($this->notice->content, 0, $this->maxchars) . '[…]'); - } elseif ($this->notice->rendered) { - $this->out->raw($this->notice->rendered); } else { - // XXX: may be some uncooked notices in the DB, - // we cook them right now. This should probably disappear in future - // versions (>> 0.4.x) - $this->out->raw(common_render_content($this->notice->content, $this->notice)); + $this->out->raw($this->notice->getRendered()); } Event::handle('EndShowNoticeContent', array($this->notice, $this->out, $this->out->getScoped())); } diff --git a/lib/util.php b/lib/util.php index 6e01860ee2..3b5bb2de08 100644 --- a/lib/util.php +++ b/lib/util.php @@ -606,14 +606,15 @@ function common_remove_unicode_formatting($text) /** * Partial notice markup rendering step: build links to !group references. * - * @param string $text partially rendered HTML - * @param Notice $notice in whose context we're working + * @param string $text partially rendered HTML + * @param Profile $author the Profile that is composing the current notice + * @param Notice $parent the Notice this is sent in reply to, if any * @return string partially rendered HTML */ -function common_render_content($text, Notice $notice) +function common_render_content($text, Profile $author, Notice $parent=null) { $text = common_render_text($text); - $text = common_linkify_mentions($text, $notice->getProfile(), $notice->hasParent() ? $notice->getParent() : null); + $text = common_linkify_mentions($text, $author, $parent); return $text; } diff --git a/plugins/QnA/actions/qnanewanswer.php b/plugins/QnA/actions/qnanewanswer.php index 94561a1548..0cdaa62f19 100644 --- a/plugins/QnA/actions/qnanewanswer.php +++ b/plugins/QnA/actions/qnanewanswer.php @@ -327,14 +327,7 @@ class NoticeAnswerListItem extends NoticeListItem function showContent() { $this->out->elementStart('p', array('class' => 'e-content answer-content')); - if ($this->notice->rendered) { - $this->out->raw($this->notice->rendered); - } else { - // XXX: may be some uncooked notices in the DB, - // we cook them right now. This should probably disappear in future - // versions (>> 0.4.x) - $this->out->raw(common_render_content($this->notice->content, $this->notice)); - } + $this->out->raw($this->notice->getRendered()); if (!empty($this->answer)) { $form = new QnashowanswerForm($this->out, $this->answer); diff --git a/plugins/Xmpp/XmppPlugin.php b/plugins/Xmpp/XmppPlugin.php index 8c700bae8b..6867eb093e 100644 --- a/plugins/Xmpp/XmppPlugin.php +++ b/plugins/Xmpp/XmppPlugin.php @@ -355,12 +355,8 @@ class XmppPlugin extends ImPlugin // Parent notice was probably deleted. $xs->text(": "); } - if (!empty($notice->rendered)) { - $notice->rendered = str_replace("\t", "", $notice->rendered); - $xs->raw($notice->rendered); - } else { - $xs->raw(common_render_content($notice->content, $notice)); - } + // FIXME: Why do we replace \t with ''? is it just to make it pretty? shouldn't whitespace be handled well...? + $xs->raw(str_replace("\t", "", $notice->getRendered())); $xs->text(" "); $xs->element('a', array( 'href'=>common_local_url('conversation', diff --git a/scripts/fixup_hashtags.php b/scripts/fixup_hashtags.php index ac6522f3d9..b5cdb76498 100755 --- a/scripts/fixup_hashtags.php +++ b/scripts/fixup_hashtags.php @@ -39,7 +39,9 @@ while ($notice->fetch()) { common_log(LOG_INFO, 'Getting tags for notice #' . $notice->id); $notice->saveTags(); $original = clone($notice); - $notice->rendered = common_render_content($notice->content, $notice); + $notice->rendered = common_render_content($notice->content, + $notice->getProfile(), + $notice->hasParent() ? $notice->getParent() : null); $result = $notice->update($original); if (!$result) { common_log_db_error($notice, 'UPDATE', __FILE__); diff --git a/scripts/upgrade.php b/scripts/upgrade.php index d2bc403b5e..977cb1b5bd 100755 --- a/scripts/upgrade.php +++ b/scripts/upgrade.php @@ -105,7 +105,9 @@ function fixupNoticeRendered() while ($notice->fetch()) { $original = clone($notice); - $notice->rendered = common_render_content($notice->content, $notice); + $notice->rendered = common_render_content($notice->content, + $notice->getProfile(), + $notice->hasParent() ? $notice->getParent() : null); $notice->update($original); }