From 02bf09aaae79256f95880d1ee0aa9f24ad45d32e Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sun, 13 Mar 2016 11:56:00 +0000 Subject: [PATCH] move egw_htmLawed to api/src/Html/HtmLawed, @Klaus: does mail really need to call that class, cant it use Html::purify? --- api/src/Html.php | 27 +------------------ .../src/Html/HtmLawed.php | 16 ++++++----- .../src/Html}/htmLawed/htmLawed.php | 0 .../src/Html}/htmLawed/htmLawedTest.php | 0 .../src/Html}/htmLawed/htmLawed_README.htm | 0 .../src/Html}/htmLawed/htmLawed_README.txt | 0 .../src/Html}/htmLawed/htmLawed_TESTCASE.txt | 0 mail/inc/class.mail_ui.inc.php | 6 +++-- 8 files changed, 14 insertions(+), 35 deletions(-) rename phpgwapi/inc/class.egw_htmLawed.inc.php => api/src/Html/HtmLawed.php (98%) rename {phpgwapi/inc => api/src/Html}/htmLawed/htmLawed.php (100%) rename {phpgwapi/inc => api/src/Html}/htmLawed/htmLawedTest.php (100%) rename {phpgwapi/inc => api/src/Html}/htmLawed/htmLawed_README.htm (100%) rename {phpgwapi/inc => api/src/Html}/htmLawed/htmLawed_README.txt (100%) rename {phpgwapi/inc => api/src/Html}/htmLawed/htmLawed_TESTCASE.txt (100%) diff --git a/api/src/Html.php b/api/src/Html.php index 1e3db255c8..391e5720e2 100644 --- a/api/src/Html.php +++ b/api/src/Html.php @@ -18,7 +18,6 @@ namespace EGroupware\Api; use egw_framework; // validate_file, includeCSS use egw_ckeditor_config; use egw; // link -use egw_htmLawed; /** * Generates html with methods representing html-tags or higher widgets @@ -1281,30 +1280,6 @@ egw_LAB.wait(function() { */ static function purify($html,$config=null,$spec=array(),$_force=false) { - $defaultConfig = array('valid_xhtml'=>1,'safe'=>1); - - if (empty($html)) return $html; // no need to process further - if (!empty($config) && is_string($config)) - { - //error_log(__METHOD__.__LINE__.$config); - $config = json_decode($config,true); - if (is_null($config)) error_log(__METHOD__.__LINE__." decoding of config failed; standard will be applied"); - } - - // User preferences - $font = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font']; - $font_size = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font_size']; - - // Check for "blank" = just user preference span - for some reason we can't match on the entity, so approximate - $regex = '#^.?$#us'; - if(preg_match($regex,$html)) - { - return ''; - } - $htmLawed = new egw_htmLawed(); - if (is_array($config) && $_force===false) $config = array_merge($defaultConfig, $config); - if (empty($config)) $config = $defaultConfig; - //error_log(__METHOD__.__LINE__.array2string($config)); - return $htmLawed->egw_htmLawed($html,$config,$spec); + return Html\HtmLawed::purify($html, $config, $spec, $_force); } } diff --git a/phpgwapi/inc/class.egw_htmLawed.inc.php b/api/src/Html/HtmLawed.php similarity index 98% rename from phpgwapi/inc/class.egw_htmLawed.inc.php rename to api/src/Html/HtmLawed.php index 4bfd4ce27f..58020891e7 100644 --- a/phpgwapi/inc/class.egw_htmLawed.inc.php +++ b/api/src/Html/HtmLawed.php @@ -5,19 +5,21 @@ * @link http://www.egroupware.org * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @package api - * @subpackage htmLawed + * @subpackage html * @author Klaus Leithoff * @version $Id$ */ -require_once(EGW_API_INC.'/htmLawed/htmLawed.php'); +namespace EGroupware\Api\Html; + +require_once(__DIR__.'/htmLawed/htmLawed.php'); /** * This class does NOT use anything EGroupware specific, it just calls htmLawed and supports autoloading * while matching egw namespace requirements. It also provides (as a non class function ) a hook_tag function * to do further tag / attribute validation */ -class egw_htmLawed +class HtmLawed { /** * config options see constructor @@ -95,14 +97,14 @@ class egw_htmLawed } /** - * egw_htmlLawed + * Run htmLawed * * @param varchar $html2check =text input Text to check * @param mixed $Config = text or array * @param mixed $Spec =text or array; The '$spec' argument can be used to disallow an otherwise legal attribute for an element * @return varchar cleaned/fixed html */ - function egw_htmLawed($html2check, $Config=null, $Spec=array()) + function run($html2check, $Config=null, $Spec=array()) { //error_log(__METHOD__.__LINE__.' Input:'.$html2check); if (is_array($Config) && is_array($this->Configuration)) $Config = array_merge($this->Configuration, $Config); @@ -207,11 +209,11 @@ class egw_htmLawed { return ''; } - $htmLawed = new egw_htmLawed(); + $htmLawed = new HtmLawed(); if (is_array($config) && $_force===false) $config = array_merge($defaultConfig, $config); if (empty($config)) $config = $defaultConfig; //error_log(__METHOD__.__LINE__.array2string($config)); - return $htmLawed->egw_htmLawed($html,$config,$spec); + return $htmLawed->run($html,$config,$spec); } } diff --git a/phpgwapi/inc/htmLawed/htmLawed.php b/api/src/Html/htmLawed/htmLawed.php similarity index 100% rename from phpgwapi/inc/htmLawed/htmLawed.php rename to api/src/Html/htmLawed/htmLawed.php diff --git a/phpgwapi/inc/htmLawed/htmLawedTest.php b/api/src/Html/htmLawed/htmLawedTest.php similarity index 100% rename from phpgwapi/inc/htmLawed/htmLawedTest.php rename to api/src/Html/htmLawed/htmLawedTest.php diff --git a/phpgwapi/inc/htmLawed/htmLawed_README.htm b/api/src/Html/htmLawed/htmLawed_README.htm similarity index 100% rename from phpgwapi/inc/htmLawed/htmLawed_README.htm rename to api/src/Html/htmLawed/htmLawed_README.htm diff --git a/phpgwapi/inc/htmLawed/htmLawed_README.txt b/api/src/Html/htmLawed/htmLawed_README.txt similarity index 100% rename from phpgwapi/inc/htmLawed/htmLawed_README.txt rename to api/src/Html/htmLawed/htmLawed_README.txt diff --git a/phpgwapi/inc/htmLawed/htmLawed_TESTCASE.txt b/api/src/Html/htmLawed/htmLawed_TESTCASE.txt similarity index 100% rename from phpgwapi/inc/htmLawed/htmLawed_TESTCASE.txt rename to api/src/Html/htmLawed/htmLawed_TESTCASE.txt diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index 1f78e1b39d..44a49968fd 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -10,6 +10,8 @@ * @version $Id$ */ +use EGroupware\Api; + /** * Mail User Interface * @@ -2948,11 +2950,11 @@ $filter['before']= date("d-M-Y", $cutoffdate2); $hasOther = true; $newBody = $matches[2]; } - $htmLawed = new egw_htmLawed(); + $htmLawed = new Api\Html\HtmLawed(); // the next line should not be needed, but produces better results on HTML 2 Text conversion, // as we switched off HTMLaweds tidy functionality $newBody = str_replace(array('&','

',"
 
",'
 
'),array('&','
','
','
'),$newBody); - $newBody = $htmLawed->egw_htmLawed($newBody,mail_bo::$htmLawed_config); + $newBody = $htmLawed->run($newBody,mail_bo::$htmLawed_config); if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3]; $alreadyHtmlLawed=true; }