Skip to content
Snippets Groups Projects
Commit 09b41861 authored by Jared Hancock's avatar Jared Hancock
Browse files

Create ThreadBody class to keep track of text type

This will be helpful to keep track of whether a text is html or text and
provide a way to convert it exactly once.
parent e0c7e4b6
No related branches found
No related tags found
No related merge requests found
......@@ -871,12 +871,17 @@ Class ThreadEntry {
&& $cfg->stripQuotedReply()
&& ($tag=$cfg->getReplySeparator())
&& strpos($vars['body'], $tag))
// TODO: Move this to the ThreadBody class
if((list($msg) = explode($tag, $vars['body'], 2)) && trim($msg))
$vars['body'] = $msg;
if (!$cfg->isHtmlThreadEnabled()) {
if ($vars['body'] instanceof ThreadBody) {
$vars['body'] = $vars['body']->convertTo('html');
}
elseif (!$cfg->isHtmlThreadEnabled()) {
// Data in the database is assumed to be HTML, change special
// plain text XML characters
// XXX: Why isn't `title` always scrubbed?
$vars['title'] = Format::htmlchars($vars['title']);
$vars['body'] = sprintf('<pre>%s</pre>',
Format::htmlchars($vars['body']));
......@@ -1123,4 +1128,49 @@ class Note extends ThreadEntry {
)?$n:null;
}
}
class ThreadBody /* extends SplString */ {
private static $types = array('text', 'html');
var $body;
var $type;
function __construct($body, $type='text') {
$type = strtolower($type);
if (!in_array($type, static::$types))
throw new Exception($type.': Unsupported ThreadBody type');
$this->body = $text;
$this->type = $type;
}
function convertTo($type) {
if ($type === $this->type)
return $this;
$conv = $this->type . ':' . strtolower($type);
switch ($conv) {
case 'text:html':
return new ThreadBody(sprintf('<pre>%s</pre>',
Format::htmlchars($this->body)), $type);
case 'html:text':
return new ThreadBody(Format::html2text($this->body), $type);
}
}
function __toString() {
return $this->body;
}
}
class TextThreadBody extends ThreadBody {
function __construct($body) {
parent::__construct($body, 'text');
}
}
class HtmlThreadBody extends ThreadBody {
function __construct($body) {
parent::__contruct($body, 'html');
}
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment