Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename internal HtmLawed, reduce CS diff and upgrade it #32

Merged
merged 9 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Editor/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use DataTables\Database;
use DataTables\Database\Query;
use DataTables\Editor;
use DataTables\HtmLawed\Htmlaw;
use DataTables\HtmLawed\HtmLawedVanillaWrapper;

/**
* Field definitions for the DataTables Editor.
Expand Down Expand Up @@ -843,15 +843,15 @@ public function xssSafety($val)
foreach ($val as $individual) {
$res[] = $xss ?
$xss($individual) :
Htmlaw::filter($individual);
HtmLawedVanillaWrapper::filter($individual);
}

return $res;
}

return $xss ?
$xss($val) :
Htmlaw::filter($val);
HtmLawedVanillaWrapper::filter($val);
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Expand Down
1,594 changes: 1,594 additions & 0 deletions HtmLawed/HtmLawed.php

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions HtmLawed/HtmLawedVanillaWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

// Downloaded from https://github.com/vanilla/htmlawed/blob/v2.2.15/src/Htmlawed.php
// with the following modifications:
// 1. add `DataTables\HtmLawed` namespace
// 2. rename class name from `Htmlawed` to `HtmLawedVanillaWrapper`
// 3. readd PHP 5.3 support - change `[]` array constructor syntax to `array()`
// 4. remove https://github.com/vanilla/htmlawed/blob/v2.2.15/src/Htmlawed.php#L45 line
// 5. update `htmLawed` call on https://github.com/vanilla/htmlawed/blob/v2.2.15/src/Htmlawed.php#L59 line to `HtmLawed::hl`
// 6. add missing `string` type to phpdoc on https://github.com/vanilla/htmlawed/blob/v2.2.15/src/Htmlawed.php#L66 line

/**
* @author Todd Burry <[email protected]>
* @copyright 2009-2014 Vanilla Forums Inc.
* @license LGPL-3.0
*/

namespace DataTables\HtmLawed;

/**
* A class wrapper for the htmLawed library.
*/
class HtmLawedVanillaWrapper {
/// Methods ///

public static $defaultConfig = array(
'anti_link_spam' => array('`.`', ''),
'balance' => 1,
'cdata' => 3,
'safe' => 1,
'comment' => 1,
'css_expression' => 0,
'deny_attribute' => 'on*,style',
'direct_list_nest' => 1,
'elements' => '*-applet-button-form-input-textarea-iframe-script-style-embed-object',
'keep_bad' => 0,
'schemes' => 'classid:clsid; href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; style: nil; *:file, http, https', // clsid allowed in class
'unique_ids' => 0,
'valid_xhtml' => 0,
);

public static $defaultSpec = array(
'object=-classid-type, -codebase',
'embed=type(oneof=application/x-shockwave-flash)'
);

/**
* Filters a string of html with the htmLawed library.
*
* @param string $html The text to filter.
* @param array|null $config Config settings for the array.
* @param string|array|null $spec A specification to further limit the allowed attribute values in the html.
* @return string Returns the filtered html.
* @see http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/htmLawed_README.htm
*/
public static function filter($html, array $config = null, $spec = null) {
if ($config === null) {
$config = self::$defaultConfig;
}

if (isset($config['spec']) && !$spec) {
$spec = $config['spec'];
}

if ($spec === null) {
$spec = static::$defaultSpec;
}

return HtmLawed::hl($html, $config, $spec);
}


/**
* Filter a string of html so that it can be put into an rss feed.
*
* @param string $html The html text to fitlter.
* @return string Returns the filtered html.
* @see Htmlawed::filter().
*/
public static function filterRSS($html) {
$config = array(
'anti_link_spam' => array('`.`', ''),
'comment' => 1,
'cdata' => 3,
'css_expression' => 1,
'deny_attribute' => 'on*,style,class',
'elements' => '*-applet-form-input-textarea-iframe-script-style-object-embed-comment-link-listing-meta-noscript-plaintext-xmp',
'keep_bad' => 0,
'schemes' => 'classid:clsid; href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; style: nil; *:file, http, https', // clsid allowed in class
'valid_xhtml' => 1,
'balance' => 1
);
$spec = static::$defaultSpec;

$result = static::filter($html, $config, $spec);

return $result;
}
}
118 changes: 0 additions & 118 deletions HtmLawed/Htmlaw.php

This file was deleted.

Loading