common_render_content doesn't require a Profile now

This commit is contained in:
Mikael Nordfeldth 2016-01-01 18:40:11 +01:00
parent 54325e266f
commit e02c10a589
8 changed files with 19 additions and 32 deletions

View File

@ -621,7 +621,9 @@ class Notice extends Managed_DataObject
if (!empty($rendered)) { if (!empty($rendered)) {
$notice->rendered = $rendered; $notice->rendered = $rendered;
} else { } else {
$notice->rendered = common_render_content($final, $notice); $notice->rendered = common_render_content($final,
$notice->getProfile(),
$notice->hasParent() ? $notice->getParent() : null);
} }
if (empty($verb)) { if (empty($verb)) {

View File

@ -68,11 +68,7 @@ class DoFollowListItem extends NoticeListItem
// FIXME: URL, image, video, audio // FIXME: URL, image, video, audio
$this->out->elementStart('article', array('class' => 'e-content')); $this->out->elementStart('article', array('class' => 'e-content'));
if (!empty($this->notice->rendered)) { $html = $this->notice->getRendered();
$html = $this->notice->rendered;
} else {
$html = common_render_content($this->notice->content, $this->notice);
}
if (common_config('nofollow', 'external') == 'sometimes') { if (common_config('nofollow', 'external') == 'sometimes') {
// remove the nofollow part // remove the nofollow part

View File

@ -343,13 +343,8 @@ class NoticeListItem extends Widget
if (Event::handle('StartShowNoticeContent', array($this->notice, $this->out, $this->out->getScoped()))) { if (Event::handle('StartShowNoticeContent', array($this->notice, $this->out, $this->out->getScoped()))) {
if ($this->maxchars > 0 && mb_strlen($this->notice->content) > $this->maxchars) { if ($this->maxchars > 0 && mb_strlen($this->notice->content) > $this->maxchars) {
$this->out->text(mb_substr($this->notice->content, 0, $this->maxchars) . '[…]'); $this->out->text(mb_substr($this->notice->content, 0, $this->maxchars) . '[…]');
} elseif ($this->notice->rendered) {
$this->out->raw($this->notice->rendered);
} else { } else {
// XXX: may be some uncooked notices in the DB, $this->out->raw($this->notice->getRendered());
// 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));
} }
Event::handle('EndShowNoticeContent', array($this->notice, $this->out, $this->out->getScoped())); Event::handle('EndShowNoticeContent', array($this->notice, $this->out, $this->out->getScoped()));
} }

View File

@ -606,14 +606,15 @@ function common_remove_unicode_formatting($text)
/** /**
* Partial notice markup rendering step: build links to !group references. * Partial notice markup rendering step: build links to !group references.
* *
* @param string $text partially rendered HTML * @param string $text partially rendered HTML
* @param Notice $notice in whose context we're working * @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 * @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_render_text($text);
$text = common_linkify_mentions($text, $notice->getProfile(), $notice->hasParent() ? $notice->getParent() : null); $text = common_linkify_mentions($text, $author, $parent);
return $text; return $text;
} }

View File

@ -327,14 +327,7 @@ class NoticeAnswerListItem extends NoticeListItem
function showContent() function showContent()
{ {
$this->out->elementStart('p', array('class' => 'e-content answer-content')); $this->out->elementStart('p', array('class' => 'e-content answer-content'));
if ($this->notice->rendered) { $this->out->raw($this->notice->getRendered());
$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));
}
if (!empty($this->answer)) { if (!empty($this->answer)) {
$form = new QnashowanswerForm($this->out, $this->answer); $form = new QnashowanswerForm($this->out, $this->answer);

View File

@ -355,12 +355,8 @@ class XmppPlugin extends ImPlugin
// Parent notice was probably deleted. // Parent notice was probably deleted.
$xs->text(": "); $xs->text(": ");
} }
if (!empty($notice->rendered)) { // FIXME: Why do we replace \t with ''? is it just to make it pretty? shouldn't whitespace be handled well...?
$notice->rendered = str_replace("\t", "", $notice->rendered); $xs->raw(str_replace("\t", "", $notice->getRendered()));
$xs->raw($notice->rendered);
} else {
$xs->raw(common_render_content($notice->content, $notice));
}
$xs->text(" "); $xs->text(" ");
$xs->element('a', array( $xs->element('a', array(
'href'=>common_local_url('conversation', 'href'=>common_local_url('conversation',

View File

@ -39,7 +39,9 @@ while ($notice->fetch()) {
common_log(LOG_INFO, 'Getting tags for notice #' . $notice->id); common_log(LOG_INFO, 'Getting tags for notice #' . $notice->id);
$notice->saveTags(); $notice->saveTags();
$original = clone($notice); $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); $result = $notice->update($original);
if (!$result) { if (!$result) {
common_log_db_error($notice, 'UPDATE', __FILE__); common_log_db_error($notice, 'UPDATE', __FILE__);

View File

@ -105,7 +105,9 @@ function fixupNoticeRendered()
while ($notice->fetch()) { while ($notice->fetch()) {
$original = clone($notice); $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); $notice->update($original);
} }