00001 <?php
00002
00003
00004
00005
00006
00007
00008 class ConverterHtmlPurifierAutoParagraph extends ConverterHtmlPurifier {
00009
00010
00011
00012
00013
00014
00015 public function encode($value, $params = false) {
00016 if (is_null($value) || $value instanceof DBNull) {
00017 return $value;
00018 }
00019
00020 $input = trim($value);
00021 $input = str_replace("\r", "\n", $input);
00022 $input = preg_replace('|<br.*?>|', "\n", $input);
00023 $input = String::preg_replace('|\n\n+|m', "\n", $input);
00024 $input = str_replace("\n", "\n\n", $input);
00025 $params = array_merge(array(
00026 'AutoFormat.RemoveEmpty' => true,
00027 'AutoFormat.RemoveEmpty.RemoveNbsp' => true,
00028 'AutoFormat.AutoParagraph' => true
00029 ), Arr::force($params, false)
00030 );
00031 $input = parent::encode($input, $params);
00032 $input = String::preg_replace('|\n\n+|m', "\n", $input);
00033 return $input;
00034 }
00035 }