00001 <?php
00002
00003
00004
00005
00006
00007
00008 class ConverterHtml implements IConverter {
00009 public function encode($value, $params = false) {
00010 $value = $this->decode($value);
00011 $value = str_replace("\r", "\n", $value);
00012
00013 $arr_paragraphs = explode("\n", $value);
00014 $c = count($arr_paragraphs);
00015 $arr_result = array();
00016 for($i = 0; $i < $c; $i++) {
00017 $tmp = trim($arr_paragraphs[$i]);
00018 if (empty($tmp)) {
00019 continue;
00020 }
00021
00022 $arr_result[] = $this->process_paragraph($tmp, $params);
00023 }
00024 $ret = implode("\n", $arr_result);
00025 $ret = String::preg_replace('| +|', ' ', $ret);
00026 return $ret;
00027 }
00028
00029
00030
00031
00032
00033
00034
00035 protected function process_paragraph($text, $params) {
00036 return html::tag('p', String::escape($text));
00037 }
00038
00039 public function decode($value, $params = false) {
00040
00041
00042 $value = str_replace('</p>', "</p>\n", $value);
00043 $value = preg_replace('@<br.*?>@', "\n", $value);
00044 $value = String::unescape($value);
00045 return strip_tags($value);
00046 }
00047 }