diff --git a/.gitignore b/.gitignore index e588ffdc..a91cd306 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ -Tests/vendor/* -Tests/cache/* -Tests/logs/* +/composer.phar +/composer.lock +/vendor +/Tests/Resources/cache +/Tests/Resources/logs diff --git a/.travis.yml b/.travis.yml index cba85d7b..2aabfdb1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,18 @@ language: php -php: 5.3 + +php: + - 5.3 + - 5.4 + +env: + - SYMFONY_VERSION="2.3.*" + +before_script: + - composer require --no-update symfony/framework-bundle:${SYMFONY_VERSION} + - composer install --dev --prefer-source + script: phpunit + notifications: email: - trsteel88@gmail.com diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 89dadfa7..2128d1ae 100755 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -29,7 +29,7 @@ public function getConfigTreeBuilder() ->children() ->variableNode('transformers') ->defaultValue(array( - 'strip_js', 'strip_css', 'strip_comments' + //'html_purifier' )) ->info("Default data transformers for the submitted html.") ->end() diff --git a/Form/Transformer/StripCSS.php b/Form/Transformer/StripCSS.php deleted file mode 100644 index fd0c721b..00000000 --- a/Form/Transformer/StripCSS.php +++ /dev/null @@ -1,24 +0,0 @@ -]*>(.*?)<\/style>/is', '', $data) ?: null; - } -} \ No newline at end of file diff --git a/Form/Transformer/StripComments.php b/Form/Transformer/StripComments.php deleted file mode 100644 index bde89354..00000000 --- a/Form/Transformer/StripComments.php +++ /dev/null @@ -1,24 +0,0 @@ -/is', '', $data) ?: null; - } -} \ No newline at end of file diff --git a/Form/Transformer/StripJS.php b/Form/Transformer/StripJS.php deleted file mode 100644 index 47033a6b..00000000 --- a/Form/Transformer/StripJS.php +++ /dev/null @@ -1,24 +0,0 @@ -]*>(.*?)<\/script>/is', '', $data) ?: null; - } -} \ No newline at end of file diff --git a/README.md b/README.md index 1310674e..7bc59ad7 100644 --- a/README.md +++ b/README.md @@ -14,18 +14,9 @@ 6. Configure data transformers ### Step 1: Add TrsteelCkeditorBundle to your composer.json -```js -{ - "require": { - "Trsteel/ckeditor-bundle": "1.1.*@dev" - } -} -``` - -and update your project dependencies: ```bash -php composer.phar update Trsteel/ckeditor-bundle +php composer.phar require Trsteel/ckeditor-bundle 1.3.* ``` ### Step 2: Enable the bundle @@ -38,6 +29,7 @@ public function registerBundles() $bundles = array( // ... new Trsteel\CkeditorBundle\TrsteelCkeditorBundle(), + new Exercise\HTMLPurifierBundle\ExerciseHTMLPurifierBundle(), ); } ``` @@ -61,7 +53,7 @@ An example configuration: ```yaml trsteel_ckeditor: class: Trsteel\CkeditorBundle\Form\Type\CkeditorType - transformers: ['strip_js', 'strip_css', 'strip_comments'] + transformers: ['html_purifier'] toolbar: ['document', 'clipboard', 'editing', '/', 'basicstyles', 'paragraph', 'links', '/', 'insert', 'styles', 'tools'] toolbar_groups: document: ['Source','-','Save','-','Templates'] @@ -108,7 +100,7 @@ Example form: $form = $this->createFormBuilder($post) ->add('title', 'text') ->add('content', 'ckeditor', array( - 'transformers' => array('strip_js', 'strip_css', 'strip_comments'), + 'transformers' => array('html_purifier'), 'toolbar' => array('document','basicstyles'), 'toolbar_groups' => array( 'document' => array('Source') @@ -138,13 +130,7 @@ Note: All parameters from config.yml can be overwritten in a form (excluding 'cl Data transformers will automatically update the html content when the form is processed. -This bundle comes with several built-in transformers. - -**strip_js:** Strips all javascript from the posted data - -**strip_css:** Strips all css from the posted data - -**strip_comments:** Strips all comments from html eg. +The bundle comes with a html purifier transformer thanks to https://github.com/Exercise/HTMLPurifierBundle If you do not want any transformers enabled you should disable them by: diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 4c30f708..5b5baa47 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -1,27 +1,13 @@ -parameters: -# trsteel_ckeditor.example.class: Trsteel\CkeditorBundle\Example - services: -# trsteel_ckeditor.example: -# class: %trsteel_ckeditor.example.class% -# arguments: [@service_id, "plain_value", %parameter%] trsteel_ckeditor.form.type: class: %trsteel_ckeditor.form.type.class% + arguments: [@service_container] tags: - { name: form.type, alias: ckeditor } - arguments: [ @service_container ] - - trsteel_ckeditor.transformer.strip_js: - class: Trsteel\CkeditorBundle\Form\Transformer\StripJS - tags: - - { name: trsteel_ckeditor.transformer, alias: strip_js } - - trsteel_ckeditor.transformer.strip_css: - class: Trsteel\CkeditorBundle\Form\Transformer\StripCSS - tags: - - { name: trsteel_ckeditor.transformer, alias: strip_css } - trsteel_ckeditor.transformer.strip_comments: - class: Trsteel\CkeditorBundle\Form\Transformer\StripComments + trsteel_ckeditor.transformer.html_purifier: + class: Exercise\HTMLPurifierBundle\Form\HTMLPurifierTransformer + public: false + arguments: [@exercise_html_purifier.default] tags: - - { name: trsteel_ckeditor.transformer, alias: strip_comments } \ No newline at end of file + - { name: trsteel_ckeditor.transformer, alias: html_purifier } diff --git a/Resources/doc/transformers.md b/Resources/doc/transformers.md index 54ec977d..71a9399f 100644 --- a/Resources/doc/transformers.md +++ b/Resources/doc/transformers.md @@ -71,4 +71,4 @@ $form = $this->createFormBuilder($post) ; ``` -Note: If you override the transformers value none of the default transformers will be including (eg strip_js, strip_css etc) +Note: If you override the transformers value none of the default transformers will be including (eg html_purifier) diff --git a/Tests/AppKernel.php b/Tests/AppKernel.php new file mode 100644 index 00000000..cd3d410a --- /dev/null +++ b/Tests/AppKernel.php @@ -0,0 +1,31 @@ +load(__DIR__.'/Resources/config/config.yml'); + } +} \ No newline at end of file diff --git a/Tests/Form/CkeditorTypeTest.php b/Tests/Form/CkeditorTypeTest.php index efdc5205..a4a34e2a 100755 --- a/Tests/Form/CkeditorTypeTest.php +++ b/Tests/Form/CkeditorTypeTest.php @@ -2,12 +2,10 @@ namespace Trsteel\CkeditorBundle\Tests\Form; -use Symfony\Component\Form\Tests\Extension\Core\Type\TypeTestCase; +use Symfony\Component\Form\Test\TypeTestCase; use Symfony\Component\Form\Forms; use Trsteel\CkeditorBundle\Form\Type\CkeditorType; -use Trsteel\CkeditorBundle\Form\Transformer\StripJS; -use Trsteel\CkeditorBundle\Form\Transformer\StripCSS; -use Trsteel\CkeditorBundle\Form\Transformer\StripComments; +use Trsteel\CkeditorBundle\Tests\AppKernel; class CkeditorTypeTest extends TypeTestCase { @@ -16,7 +14,7 @@ class CkeditorTypeTest extends TypeTestCase public static function setUpBeforeClass() { - self::$kernel = new \AppKernel('dev', true); + self::$kernel = new AppKernel('dev', true); self::$kernel->boot(); self::$container = self::$kernel->getContainer(); @@ -33,10 +31,6 @@ public function setUp() $ckeditorType = new CkeditorType($this->get('service_container')); - $ckeditorType->addTransformer(new StripJS(), 'strip_js'); - $ckeditorType->addTransformer(new StripCSS(), 'strip_css'); - $ckeditorType->addTransformer(new StripComments(), 'strip_comments'); - $this->factory = Forms::createFormFactoryBuilder() ->addType($ckeditorType) ->getFormFactory(); diff --git a/Tests/config.yml b/Tests/Resources/config/config.yml similarity index 100% rename from Tests/config.yml rename to Tests/Resources/config/config.yml diff --git a/Tests/autoload.php.dist b/Tests/autoload.php.dist deleted file mode 100644 index a1ac1c72..00000000 --- a/Tests/autoload.php.dist +++ /dev/null @@ -1,50 +0,0 @@ -registerNamespaces(array( - 'Symfony\\Tests' => $vendorDir.'/symfony/tests', - 'Symfony' => $vendorDir.'/symfony/src', -)); - -$loader->registerPrefixes(array( - 'Twig_' => __DIR__.'/vendor/twig/lib', -)); - -$loader->register(); - -spl_autoload_register(function($class) { - $class = ltrim($class, '\\'); - if (0 === strpos($class, 'Trsteel\CkeditorBundle\\')) { - $file = __DIR__.'/../'.str_replace('\\', '/', substr($class, strlen('Trsteel\CkeditorBundle\\'))).'.php'; - if (file_exists($file)) { - require $file; - } - } -}); - -use Symfony\Component\HttpKernel\Kernel; -use Symfony\Component\Config\Loader\LoaderInterface; - -class AppKernel extends Kernel -{ - public function registerBundles() - { - $bundles = array( - new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), - new Symfony\Bundle\TwigBundle\TwigBundle(), - new Trsteel\CkeditorBundle\TrsteelCkeditorBundle(), - ); - - return $bundles; - } - - public function registerContainerConfiguration(LoaderInterface $loader) - { - $loader->load(__DIR__.'/config.yml'); - } -} diff --git a/Tests/bin/vendors b/Tests/bin/vendors deleted file mode 100644 index 21690193..00000000 --- a/Tests/bin/vendors +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env php - Installing/Updating $name\n"; - - $installDir = $vendorDir.'/'.$name; - if (!is_dir($installDir)) { - system(sprintf('git clone -q %s %s', escapeshellarg($url), escapeshellarg($installDir))); - } - - system(sprintf('cd %s && git fetch -q origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev))); -} diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 78af9316..991ea439 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -1,9 +1,3 @@ =5.3.0", "symfony/framework-bundle": "2.*,<2.4", "symfony/form": ">=2.1,<2.4-dev", - "twig/twig": ">=1.1,<2.0-dev" - + "twig/twig": ">=1.1,<2.0-dev", + "exercise/htmlpurifier-bundle": "dev-master" + }, + "require-dev": { + "symfony/twig-bundle": "2.*,<2.4", + "symfony/yaml": "~2.0" }, "autoload": { "psr-0": { "Trsteel\\CkeditorBundle": "" } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a82c257d..32bb279b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ ./Tests - ./Tests/vendor @@ -18,8 +17,8 @@ ./Resources ./Tests + ./vendor -