Code Monkey home page Code Monkey logo

burzum / cakephp-html-purifier Goto Github PK

View Code? Open in Web Editor NEW
43.0 9.0 28.0 952 KB

This is a CakePHP wrapper for the HTML Purifier lib. The plugin includes a trait, a view helper, a behavior and a shell to clean your markup wherever you like, in the view or in the model layer or clean any table and field using the shell.

License: MIT License

PHP 100.00%
cakephp cakephp-wrapper purifier html-purifier sanitization cakephp4 cakephp3 cakephp2 cakephp-plugin

cakephp-html-purifier's Introduction

CakePHP HTML Purifier Plugin

Software License Build Status Scrutinizer Coverage Code Quality

This is a CakePHP wrapper for the HTML Purifier lib.

HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist, it will also make sure your documents are standards compliant, something only achievable with a comprehensive knowledge of W3C's specifications.

The plugin includes a trait, a view helper, a behavior and a shell to clean your markup wherever you like, in the view or in the model layer or clean any table and field using the shell.


  • For CakePHP 2.x use the 1.x version or branch.
  • For CakePHP <=3.5 use the 2.0 version or branch.
  • For CakePHP > 3.5 use the 3.0 version or branch.

Documentation

For documentation, as well as tutorials, see the docs directory of this repository.

Support

For support and feature request, please visit the Support Site.

Contributing to this Plugin

Please feel free to contribute to the plugin with new issues, requests, unit tests and code fixes or new features. If you want to contribute some code, create a feature branch from develop, and send us your pull request. Unit tests for new features and issues detected are mandatory to keep quality high.

License

Copyright 2012 - 2018 Florian Krämer

Licensed under the MIT License. Redistributions of the source code included in this repository must retain the copyright notice found in each file.

cakephp-html-purifier's People

Contributors

admad avatar burzum avatar hacheraw avatar repher avatar septech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cakephp-html-purifier's Issues

Standalone inclusion fails on case-sensitive filesystems

Error message is:

require_once(/var/www/marketplace/Plugin/HtmlPurifier/Vendor/Htmlpurifier-4.4.0-standalone/HTMLPurifier.standalone.php): failed to open stream: No such file or directory [APP/Plugin/HtmlPurifier/Config/bootstrap.php, line 5]

Direct filesystem access:

[vagrant@localhost ~]$ ls /var/www/marketplace/Plugin/HtmlPurifier/Vendor/Htmlpurifier-4.4.0-standalone/HTMLPurifier.standalone.php
ls: cannot access /var/www/marketplace/Plugin/HtmlPurifier/Vendor/Htmlpurifier-4.4.0-standalone/HTMLPurifier.standalone.php: No such file or directory
[vagrant@localhost ~]$ 

Working, with the H in Vendor/Htmlpurifier lowercase'd:

[vagrant@localhost ~]$ ls /var/www/marketplace/Plugin/HtmlPurifier/Vendor/htmlpurifier-4.4.0-standalone/HTMLPurifier.standalone.php
/var/www/marketplace/Plugin/HtmlPurifier/Vendor/htmlpurifier-4.4.0-standalone/HTMLPurifier.standalone.php
[vagrant@localhost ~]$ 

Seems to fix it:

diff --git a/Plugin/HtmlPurifier/Config/bootstrap.php b/Plugin/HtmlPurifier/Config/bootstrap.php
index fda0028..516f96f 100644
--- a/Plugin/HtmlPurifier/Config/bootstrap.php
+++ b/Plugin/HtmlPurifier/Config/bootstrap.php
@@ -2,6 +2,6 @@
 if (Configure::read('HtmlPurifier.standalone') != true) {
        require_once( CakePlugin::path('HtmlPurifier') . 'Vendor' . DS . 'HtmlPurifier' . DS . 'library' . DS . 'HTMLPur
 } else {
-       require_once( CakePlugin::path('HtmlPurifier') . 'Vendor' . DS . 'Htmlpurifier-4.4.0-standalone' . DS . 'HTMLPur
-}
+       require_once( CakePlugin::path('HtmlPurifier') . 'Vendor' . DS . 'htmlpurifier-4.4.0-standalone' . DS . 'HTMLPur
+ }
 App::uses('Purifier', 'HtmlPurifier.Lib');
\ No newline at end of file

Thanks!

Change composer.json to allow PHP8

I'm using CakePHP 4.3 running on PHP8.1 and get no errors/deprecations and everything is working as expected.
The only deprecation I get is using Cake\Console\Shell instead of Commands (they will be removed in CakePHP 5.0)

Could you please update composer.json to something like "php": ">=7.2 <9", so we don't have to use composer update --ignore-platform-reqs

I could to a PR if >=7.2 <9 is good for you.

Thanks!!!

Plugin not loaded?

Hello!
I want to use the Helper, but I can't get it work.

I added this line to the view:
<?= $this->HtmlPurifier->clean($game->title, 'purifierBasicInputConfig') ?>

Controller:
public $helpers = [ 'Burzum/HtmlPurifier.HtmlPurifier' => [ 'config' => 'purifierBasicInputConfig' ] ];

AppController:
Purifier::config('purifierBasicInputConfig', array( 'HTML.AllowedElements' => '', 'Cache.SerializerPath' => ROOT . DS . 'tmp' . DS . 'purifier' ) );

Config:
Plugin::load('Burzum/HtmlPurifier');

When I open the view in the browser I get this:
Error: HtmlPurifierHelper could not be found.
Error: Create the class HtmlPurifierHelper below in file: src\View\Helper\HtmlPurifierHelper.php

Interesting is, that when I load it from one of my plugins it works, but on the base site it doesn't. Also when I load the plugin this way: http://book.cakephp.org/3.0/en/views/helpers.html#configuring-helpers it works. This works also, but I'm getting an error message too: http://book.cakephp.org/3.0/en/views/helpers.html#loading-helpers-on-the-fly
Am I missing something here?

I'm using the latest Cake version: 3.2.11

Can you add a composer.json for installation?

Example might look like this:

{
"name": "burzum/cakephp-html-purifier",
"type": "cakephp-plugin",
"description": "HtmlPurifier plugin for cakePHP",
"license": "proprietary",
"authors": [
{
"name": "NAME",
"email": "EMAIL"
}
],
"minimum-stability": "stable",
"require": {
"php": ">=5.3.0",
"composer/installers": "~1.0"
}
}

Add directories to .gitignore

Can we add all directories that the plugin writes to to .gitignore?

For example Vendor/HtmlPurifier/library/HTMLPurifier/DefinitionCache/Serializer/...

Not sure how to install

I'm new to CakePHP and I'm not quite sure how to install this wrapper. I downloaded a copy of the repository into my downloads folder. I am going to ftp it into my server, but I'm not sure which directory it should go in. Maybe the plugin directory? When I open up the wrapper folder 'cakephp-html-purifier-master' that I downloaded I see a mirror of 7 of the folders I have in app. Do I need to install everything across those 7 folders, or is this a self-contained plugin? Sorry for the newb question. I read the readme but it just said to clone, without specifying where to clone. Thanks.

Table

Hi I have installed this plugin which works well but it always strips out tables tags.
I tried to add table to the AllowedElements but it breaks giving the following error:

Warning (512): Required attribute 'src' in element 'img' was not allowed, which means 'img' will not be allowed either [APP/Plugin/HtmlPurifier/Vendor/HtmlPurifier/library/HTMLPurifier/HTMLDefinition.php, line 305]

I have used your configuration as follow:

$config = HTMLPurifier_Config::createDefault();

$config->set('HTML.AllowedElements', 'a, em, blockquote, table, p, strong, pre, code, span, ul, ol, li, img');
$config->set('HTML.AllowedAttributes', 'a.href, a.title, img.src, img.alt');
$config->set('HTML.AllowedAttributes', "*.style");
$config->set('CSS.AllowedProperties', 'text-decoration');
$config->set('HTML.TidyLevel', 'heavy');
$config->set('HTML.Doctype', 'XHTML 1.0 Transitional');

Purifier::config('HTMLpurifier', $config);

Where do I make mistake?

Thank you in advance

Rudy

Validation rules running HtmlPurifier

Hey!

Do you have a good idea for this problem: i need to filter out all html tags only for validation. If validation runs without problems the tags should be saved.

Maybe your Behaviour may be a good spot for adding some validation rules. But using your Behaviour would cause beforeSave to run. Should we add another Behaviour just for validation functions?

I need this, because I have to count the number of words for some abstract submission form. It would be nice if we could add this kind of filtering to your Plugin somehow.

Bernhard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.