From ead084693499934c467ca6a9c396367ac661dd61 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Fri, 15 Apr 2016 06:28:05 -0400 Subject: [PATCH] Plugin API: Add html2text hook (backport from master) --- program/include/rcmail.php | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-) diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 53aeb90..a6a61a3 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -2322,6 +2322,39 @@ return file_get_contents($name, false); } + /** + * Converts HTML content into plain text + * + * @param string $html HTML content + * @param array $options Conversion parameters (width, links, charset) + * + * @return string Plain text + */ + public function html2text($html, $options = array()) + { + $default_options = array( + 'links' => true, + 'width' => 75, + 'body' => $html, + 'charset' => RCUBE_CHARSET, + ); + + $options = array_merge($default_options, (array) $options); + + // Plugins may want to modify HTML in another/additional way + $options = $this->plugins->exec_hook('html2text', $options); + + // Convert to text + if (!$options['abort']) { + $converter = new rcube_html2text($options['body'], + false, $options['links'], $options['width'], $options['charset']); + + $options['body'] = rtrim($converter->get_text()); + } + + return $options['body']; + } + /************************************************************************ ********* Deprecated methods (to be removed) ********* -- Gitblit v1.9.1