function onStartNoticeSave($notice) { // Only run this on local notices if ($notice->isLocal()) { $text = $notice->content; // From /lib/util.php::common_render_text // We don't want to call it directly since we don't want to // run common_linkify() on the text $text = common_remove_unicode_formatting($text); $text = preg_replace('/[\\x{0}-\\x{8}\\x{b}-\\x{c}\\x{e}-\\x{19}]/', '', $text); $text = common_replace_urls_callback($text, 'common_linkify'); // Link #hashtags $rendered = preg_replace_callback('/(^|\\"\\;|\'|\\(|\\[|\\{|\\s+)#([\\pL\\pN_\\-\\.]{1,64})/u', function ($m) { return "{$m[1]}#" . common_tag_link($m[2]); }, $text); // Link @mentions, !mentions, @#mentions $rendered = common_linkify_mentions($rendered, $notice->getProfile(), $notice->hasParent() ? $notice->getParent() : null); // Prevent leading #hashtags from becoming headers by adding a backslash // before the "#", telling markdown to leave it alone // $repl_rendered = preg_replace('/^#[\pL\pN_\-\.]{1,64}/u', 'replaced!', $rendered); $repl_rendered = preg_replace('/^#<span class="tag">/u', '\\\\\\0', $rendered); // Only use the replaced value from above if it returned a success if ($rendered !== null) { $rendered = $repl_rendered; } // handle Markdown link forms in order not to convert doubly. $rendered = preg_replace('/\\[([^]]+)\\]\\((<a [^>]+>)([^<]+)<\\/a>\\)/u', '\\2\\1</a>', $rendered); // Convert Markdown to HTML $notice->rendered = \Michelf\Markdown::defaultTransform($rendered); } return true; }
function onStartNoticeSave($notice) { $text = common_strip_html($this->br2nl($notice->rendered), true, true); // Only run this on local notices if ($notice->isLocal()) { $rendered = $this->render_text($text); // Some types of notices do not have the hasParent() method, but they're not notices we are interested in if (method_exists($notice, 'hasParent')) { // Link @mentions, !mentions, @#mentions $rendered = common_linkify_mentions($rendered, $notice->getProfile(), $notice->hasParent() ? $notice->getParent() : null); } // Prevent leading #hashtags from becoming headers by adding a backslash // before the "#", telling markdown to leave it alone $repl_rendered = preg_replace('/^#<span class="tag">/u', '\\\\\\0', $rendered); // Only use the replaced value from above if it returned a success if ($rendered !== null) { $rendered = $repl_rendered; } // handle Markdown link forms in order not to convert doubly. $rendered = preg_replace('/\\[([^]]+)\\]\\((<a [^>]+>)([^<]+)<\\/a>\\)/u', '\\2\\1</a>', $rendered); // Convert Markdown to HTML // TODO: Abstract the parser so we can call the same method regardless of lib switch ($this->parser) { case 'gfm': // Composer require __DIR__ . '/vendor/autoload.php'; $this->parser = new \cebe\markdown\GithubMarkdown(); $rendered = $this->parser->parse($rendered); break; default: $this->parser = new \Michelf\Markdown(); $rendered = $this->parser->defaultTransform($rendered); } $notice->rendered = common_purify($this->fix_whitespace($rendered)); } return true; }
function common_render_content($text, $notice) { $r = common_render_text($text); $id = $notice->profile_id; $r = common_linkify_mentions($r, $notice); $r = preg_replace('/(^|[\\s\\.\\,\\:\\;]+)!([A-Za-z0-9]{1,64})/eu', "'\\1!'.common_group_link({$id}, '\\2')", $r); return $r; }
/** * 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 * @return string partially rendered HTML */ function common_render_content($text, $notice) { $r = common_render_text($text); $id = $notice->profile_id; $r = common_linkify_mentions($r, $notice); $r = preg_replace('/(^|[\\s\\.\\,\\:\\;]+)!(' . Nickname::DISPLAY_FMT . ')/e', "'\\1!'.common_group_link({$id}, '\\2')", $r); return $r; }
/** * Partial notice markup rendering step: build links to !group references. * * @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, Profile $author, Notice $parent = null) { $text = common_render_text($text); $text = common_linkify_mentions($text, $author, $parent); return $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 * @return string partially rendered HTML */ function common_render_content($text, Notice $notice) { $text = common_render_text($text); $text = common_linkify_mentions($text, $notice); return $text; }