move egw_htmLawed to api/src/Html/HtmLawed, @Klaus: does mail really need to call that class, cant it use Html::purify?

This commit is contained in:
Ralf Becker 2016-03-13 11:56:00 +00:00
parent 85695f0d41
commit 02bf09aaae
8 changed files with 14 additions and 35 deletions

View File

@ -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 = '#^<span style="font-family:'.$font.';font-size:'.$font_size.';">.?</span>$#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);
}
}

View File

@ -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 <kl-AT-stylite.de>
* @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);
}
}

View File

@ -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('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$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;
}