how to integrate htmlpurifier with symfony2? - class

I am trying to integrate htmlpurifier into a symfony2 controller, but symfony2 assumes the class I am trying to instantiate is part of that vary controller, but it is not, it is an included class type frmo the htmlpurifier library.
Is there a way to escape the class name so that symfony2 doesn't look for it in the current namespace?

I suggest to use the bundle version of HTMLPurifier for symfony2
you can found it on gitHub : https://github.com/Exercise/HTMLPurifierBundle
it's pretty easy to install with composer
Require the bundle in your composer.json file:
{
"require": {
"exercise/htmlpurifier-bundle": "*",
}
}
Install the bundle:
$ composer update exercise/htmlpurifier-bundle
Register the bundle app/AppKernel.php :
public function registerBundles()
{
return array(
new Exercise\HTMLPurifierBundle\ExerciseHTMLPurifierBundle(),
// ...
);
}
you can use it as a service in a controller :
$purifier = $this->container->get('exercise_html_purifier.default');
$clean_html = $purifier->purify($dirty_html);
or a filter in a twig template :
{{ text|purify }}
also a Form Data Transformer for the symfony2 form builder
it's all in the docs : https://github.com/Exercise/HTMLPurifierBundle

Oh, just found it.
Instead of
require_once dirname('_FILE_') . '/plugins/htmlpurifier/library/HTMLPurifier.auto.php';
$purifier = new HTMLPurifier();
I should put a leading backslash on the class name
require_once dirname('_FILE_') . '/plugins/htmlpurifier/library/HTMLPurifier.auto.php';
$purifier = new \HTMLPurifier();

Related

Class 'Modules\Media' not found in eval()'d code on line 1 in Laravel after installing laravel-modules by nWidart

I'm using nWidart's laravel-modules for a project. The idea is great but I don't like having the modules directory starting with a capital letter (Modules).
I decided to change the directory name in the configuration file:
/config/modules.php
I kept the namespace as Modules, but I changed path:
return [
'namespace' => 'Modules',
'paths' => [
'modules' => base_path('modules'), // Used to be ('Modules')
]
];
I added this to the composer.json file:
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Modules\\": "modules/"
}
},
Now, I created a Module called Media:
php artisan module:make Media
And also created a model Media:
php artisan module:make-model Media media
My model goes like this:
<?php
namespace Modules\Media\Entities;
use Illuminate\Database\Eloquent\Model;
class Media extends Model{
//
public function categories(){
return $this->belongsToMany( Category::class, 'category_media' );
}
}
Everything works fine, but when I go to tinker
php artisan tinker
And I try to load an Object (which exists) from the database:
$file = \Modules\Media\Entities::find( 1 );
or
$file = Modules\Media\Entities::find( 1 );
or
$file = modules\Media\Entities::find( 1 );
or
$file = \modules\Media\Entities::find( 1 );
I get this error:
PHP Fatal error: Class 'Modules\Media\Entities' not found in eval()'d code on line 1
Any ideas on what might be causing the problem? was it the changeof the directory name? Am I missing something in the composer.json configuration? I have no idea.
After reading my own code, I figured out that I was not referencing the Class, but only the namespace. The correct way to call the Media class was:
$file = \Modules\Media\Entities\Media::find( 1 );
(Notice that this time I end with \Media)
And of course, the result is the expected:
=> Modules\Media\Entities\Media {#857
id: 1,
filename: "my_file.jpg",
properties: "[]",
mime: "image\jpg",
extension: "jpg",
created_at: "2017-05-21 04:37:28",
updated_at: "2017-05-21 04:37:28",
published: 0,
published_at: "2017-05-20 23:37:28",
}

Ionic with ui-router.stateHelper

Is it possiable to use ionic with ui-router.stateHelper
I want to use this for help me working with nested views:
the property children is what I'm looking for.
If its not possible, how can i do something similar, without defining each child state with name: parent.child?
after installing and import im getting the next error:
TypeError: Cannot read property '#' of undefined at updateView (http://localhost:8100/lib/ionic/js/ionic.bundle.js:62199:69)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:62194:9
at invokeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21830:9)
at nodeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21330:11)
at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20721:13)
at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20725:13)
at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20725:13)
at publicLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20596:30)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:14815:27
at Scope.$eval (http://localhost:8100/lib/ionic/js/ionic.bundle.js:29026:28) <ion-nav-view class="view-container" nav-view-transition="ios">
Ok This is working.. I had problem with the indjection.
this is the right way: (im using browserify)
npm install angular-ui-router.statehelper
then in the package.json
under browser:
"angular-ui-router-helper": "./node_modules/angular-ui-router.statehelper/statehelper.min.js"
and under browserify-shim
"browserify-shim": {
"angular": "angular",
"ionic": "ionic",
"angular-ui-router-helper": {
"exports": "angular.module('ui.router.stateHelper')"
}
},
and then in the index.js:
var rootModule = angular.module('AppName', ['ionic',require('angular-ui-router-helper').name]);
Then u can inject the stateHelperProvider to the config method :)

Symfony CMF Media Bundle - Could not load type "cmf_media_image"

I want to use the CMF Media Bundle for image uploads. The Bundle was installed successfully.
routing.xml
cmf_media_file:
resource: "#CmfMediaBundle/Resources/config/routing/file.xml"
cmf_media_image:
resource: "#CmfMediaBundle/Resources/config/routing/image.xml"
AppKernel.php
$bundles = array(
...
new Symfony\Cmf\Bundle\MediaBundle\CmfMediaBundle(),
);
Now I want to add the following code to my form:
$builder
-> add('image', 'cmf_media_image', array('required' => false))
;
But I get an error message:
Could not load type "cmf_media_image"
What did i miss?
Maybe you should declare the template like this (in config.yml) :
twig:
form:
resources:
- 'CmfMediaBundle:Form:fields.html.twig'
see http://symfony.com/doc/current/cmf/bundles/media/form_types.html for more info

Which DoctrineBundle version works with Symfony 2.0.15?

I've spent days now trying to sort out my deps in Symfony 2.0.15. I can't find a compatible list of bundles and I've been chasing commits around github trying to follow a chain of non-BC changes to get a list of versions that works for me. Eventually I chose to give up and upgraded to composer, only to find that some of the Doctrine core requires Symfony 2.1, yet some of the other Doctrine bundles require Symfony <2.1 and eventually I gave up on that as well.
Can someone with the following Bundles installed please let me know what stable versions they are using from their deps.lock?
[symfony]
git=http://github.com/symfony/symfony.git
version=v2.0.15
[twig]
git=http://github.com/fabpot/Twig.git
version=v1.8.2
[monolog]
git=http://github.com/Seldaek/monolog.git
version=1.0.2
[doctrine-common]
git=http://github.com/doctrine/common.git
version=2.1.4
[doctrine-dbal]
git=http://github.com/doctrine/dbal.git
version=2.1.7
[doctrine]
git=http://github.com/doctrine/doctrine2.git
version=2.1.7
[swiftmailer]
git=http://github.com/swiftmailer/swiftmailer.git
version=v4.1.7
[assetic]
git=http://github.com/kriswallsmith/assetic.git
version=cc2e9adb744df0704a5357adc1cf9287c427420f
[twig-extensions]
git=http://github.com/fabpot/Twig-extensions.git
[metadata]
git=http://github.com/schmittjoh/metadata.git
version=1.0.0
[SensioFrameworkExtraBundle]
git=http://github.com/sensio/SensioFrameworkExtraBundle.git
target=/bundles/Sensio/Bundle/FrameworkExtraBundle
version=origin/2.0
[JMSSecurityExtraBundle]
git=http://github.com/schmittjoh/JMSSecurityExtraBundle.git
target=/bundles/JMS/SecurityExtraBundle
version=origin/1.0.x
[SensioDistributionBundle]
git=http://github.com/sensio/SensioDistributionBundle.git
target=/bundles/Sensio/Bundle/DistributionBundle
version=origin/2.0
[SensioGeneratorBundle]
git=http://github.com/sensio/SensioGeneratorBundle.git
target=/bundles/Sensio/Bundle/GeneratorBundle
version=origin/2.0
[AsseticBundle]
git=http://github.com/symfony/AsseticBundle.git
target=/bundles/Symfony/Bundle/AsseticBundle
version=v1.0.1
[doctrine-mongodb]
git=http://github.com/doctrine/mongodb.git
[doctrine-mongodb-odm]
git=http://github.com/doctrine/mongodb-odm.git
[DoctrineMongoDBBundle]
git=http://github.com/doctrine/DoctrineMongoDBBundle.git
target=/bundles/Symfony/Bundle/DoctrineMongoDBBundle
version=v2.0.1
[DoctrineMigrationsBundle]
git=https://github.com/doctrine/DoctrineMigrationsBundle.git
target=/bundles/Symfony/Bundle/DoctrineMigrationsBundle
version=origin/2.0
[doctrine-migrations]
git=http://github.com/doctrine/migrations.git
[doctrine-fixtures]
git=http://github.com/doctrine/data-fixtures.git
[DoctrineFixturesBundle]
git=https://github.com/doctrine/DoctrineFixturesBundle.git
target=/bundles/Symfony/Bundle/DoctrineFixturesBundle
version=origin/2.0
[DoctrineBundle]
git=http://github.com/doctrine/DoctrineBundle.git
target=/bundles/Doctrine/Bundle/DoctrineBundle
[FOSJsRoutingBundle]
git=http://github.com/FriendsOfSymfony/FOSJsRoutingBundle.git
target=/bundles/FOS/JsRoutingBundle
[GedmoDoctrineExtensions]
git=http://github.com/l3pp4rd/DoctrineExtensions.git
target=/gedmo-doctrine-extensions
[StofDoctrineExtensionsBundle]
git=http://github.com/stof/StofDoctrineExtensionsBundle.git
target=/bundles/Stof/DoctrineExtensionsBundle
With these combinations I get a constant set of errors due to classes not existing or renamed methods, which I then look up in the github repositories and try to fix to a commit/tag which resolves this error, only to get another set of errors because of other classes not existing or renamed methods. I can't go back to the stable state I had a few weeks ago because of the namespace changes to the Doctrine organisation - (#see What happened to Doctrine's Symfony Bundle repos?)
Alternatively I don't mind switching to composer; heres the composer.json that I tried, but doesn't work
{
"require": {
"symfony/symfony" : "v2.0.15",
"symfony/doctrine-bridge": "2.1.x-dev",
"doctrine/common" : "2.1.4",
"doctrine/orm" : "2.1.6",
"symfony/finder" : "v2.0.15",
"symfony/assetic-bundle" : "2.0.x-dev",
"twig/extensions" : "dev-master",
"jms/security-extra-bundle" : "1.0.x",
"sensio/framework-extra-bundle" : "2.0.x-dev",
"sensio/distribution-bundle" : "2.0.x-dev",
"sensio/generator-bundle" : "2.0.x-dev",
"doctrine/doctrine-bundle": "v1.0.0-beta1",
"doctrine/mongodb-odm-bundle": "v2.0.1",
},
"autoload": {
"psr-0": {
"Oh": "src/"
}
}
}
Whenever I try to fix dependencies in the composer.json I seem to get in a cycle of upgrading and degrading the same packages over and over again but always getting the error "Your requirements could not be solved to an installable set of packages.". If someone could provide me with their composer.json setup using Symfony 2.0.15 with the Doctrine,MongoDB,DoctrineFixtures and DoctrineMigrations bundles I'd be most grateful.
Here's part of my working composer configuration:
{
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.0.15",
"doctrine/orm": "2.1.7",
"twig/extensions": "*",
"symfony/assetic-bundle": "2.0.x-dev",
"sensio/generator-bundle": "2.0.*",
"sensio/framework-extra-bundle": "2.0.*",
"jms/security-extra-bundle": "1.0.*",
"stof/doctrine-extensions-bundle": "*",
"doctrine/doctrine-migrations-bundle": "2.0.*"
}
}
I'm not using ODM though.

How to specify default module in Zend Framework?

By default Zend Framework specifies "default" module is the default module of application. Now I want my "frontend" module is the default module in my app. How can I do this?
In your config file
resources.frontController.defaultModule = "frontend"
See http://framework.zend.com/manual/en/zend.application.available-resources.html#zend.application.available-resources.frontcontroller
Update
You cannot "rename" the default module. If you're only interested in changing the URL structure, use custom routes. For example
resources.router.routes.frontend.route = "frontend/:controller/:action/*"
resources.router.routes.frontend.defaults.module = "default"
This works for me (application.ini):
resources.frontController.defaultControllerName = "index"
resources.frontController.defaultAction = "index"
resources.frontController.defaultModule = "yourModule"
resources.modules[] = ""