srEscape = $escape; $this->srPrefix = $content; return $this; } /** * @param string $text - text to show * @param int $thresholdLength - mb_character length that triggers the collapsible behavior; choose experimentally * @param string $maxHeight - max height CSS value (e.g. 8em) */ public function __construct($text, $thresholdLength, $maxHeight) { $this->text = $text; $this->collapsing = mb_strlen($text) > $thresholdLength; $this->maxHeight = $maxHeight; } private function processText($t) { $out = e($t); $out = str_replace("\r\n", "\n", $out); $out = '

'.str_replace("\n\n", "

". '

', $out).'

'; $out = nl2br($out); $out = preg_replace_callback('#\b((https?://|ftp://|mailto:)[^\s]+)#i', function($m) { $href = $m[1]; $text = $href; if (strpos($text, 'mailto:') === 0) { $text = str_replace('mailto:', '', $text); } return "".e($text).""; }, $out); return $out; } public function render() { $content = $this->processText($this->text); $prefix = ''; if ($this->srPrefix) { $prefix = ''. ($this->srEscape ? e($this->srPrefix) : $this->srPrefix). ' '; } if ($this->collapsing) { return '
' . $prefix . $content . '
'; } else { return $prefix.'
' . $prefix . $content . '
'; } } public function __toString() { return (string) $this->render(); } }