Set up freepik-labs/dompurify on php xampp - php

I have been trying to set up free-pik-labs/dompurify on a php project and it just does not work. Can anyone help me?
I installed it with composer to my project's local directory and ran the code below:
require_once '../vendor/autoload.php';
use FreepikLabs\DomPurify\Purifier;
$process = new Purifier;
// Output will look like <svg><g></g></svg>
$sanitized = $process->clean('<svg><g onload="alert(\'test\')"></g>', [
'USE_PROFILES' => [
'svg' => true
]
]);
and I get this error

Related

Ckeditor 5 file uploading adapter error

I'm using ckeditor classic 5, and i'm trying to upload images in it. I downloaded php lib Ckfinder3 php connector, set config.
When i'm trying to load image i have a massage: Cannot upload file *filename*.
Interesting moment, that they are fisically loaded on server: i can view it in directory, that set in my config file and this files are correct:
/var/www/projectfiles/downloadfiles/
The next step i'm check permission and groups: it's www-data 0777.
What can be a reason? Can you give some advice or solution?
Thanks!
UPD: init function
ClassicEditor
.create( document.querySelector( '#material_preview' ), {
ckfinder: {
uploadUrl: '/ckfinder/connector/?command=QuickUpload&type=Images'
}
} )
.catch( error => {
console.error( error );
} );
php config:
$config['authentication'] = function () {
return true;
};
$config['backends']['default'] = array(
'name' => 'default',
'adapter' => 'local',
'baseUrl' => 'http://files.project.com/downloadfiles/',
'root' => '/var/www/projectfiles/downloadfiles/',
'chmodFiles' => 0777,
'chmodFolders' => 0777,
'filesystemEncoding' => 'UTF-8'
);
The connector path looks invalid. For PHP it should be something like:
'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files'
Please have a look at CKEditor integration examples in CKFinder demo: https://ckeditor.com/docs/ckfinder/demo/ckfinder3/samples/ckeditor.html
Finally i got it!
The connector path is valid. The problem was in cache folder's permisson in laravel. Be glad if it helps you.

yii2 jasper on basic template

I've followed step by step instructions from JasperReports for yii2.
Installed JDK 1.8 on my Debian 8
Setted up mysql connector's classpath in /etc/profile
Added chrmorandi/yii2-jasper to my composer and updated
I guess php exec() function is enabled because the following test in any view resolves successfuly ...
<? echo exec('whoami'); ?>
chromandi is now under /vendors
java -version says 1.8.0_111
$CLASHPATH points to /usr/share/mysql-connector-java/mysql-connector-java-5.1.40-bin.jar
configuration is so ...
'components' => [
'jasper' => [
'class' => 'chrmorandi\jasper',
'db' => [
'host' => 'localhost',
'port' => 3306,
'driver' => 'mysql',
'dbname' => 'acme',
'username' => 'acme',
'password' => 'acme'
]
],
...
]
I added a controller like this ...
<?php
namespace app\controllers;
use Yii;
use chrmorandi\Jasper;
class EstadisticasController extends \yii\web\Controller {
public function actionIndex() {
// Set alias for sample directory
Yii::setAlias('example', '#vendor/chrmorandi/yii2-jasper/examples');
/* #var $jasper Jasper */
$jasper = Yii::$app->jasper;
// Compile a JRXML to Jasper
$jasper->compile(Yii::getAlias('#example') . '/hello_world.jrxml')->execute();
// Process a Jasper file to PDF and RTF (you can use directly the .jrxml)
$jasper->process(Yii::getAlias('#example') . '/hello_world.jasper', [
'php_version' => 'xxx'
], [
'pdf',
'rtf'
], false, false)->execute();
// List the parameters from a Jasper file.
$array = $jasper->listParameters(Yii::getAlias('#example') . '/hello_world.jasper')->execute();
// return pdf file
Yii::$app->response->sendFile(Yii::getAlias('#example') . '/hello_world.pdf');
}
}
and tested http://www.acme.es/estadisticas/index that is supposed to be a built-in example.
Now it comes the problem. It complains about
$jasper = Yii::$app->jasper;
line. The output says
ReflectionException Class chrmorandi\jasper does not exist
Anyone facing this issue? There is no much info about jasper on Yii. Any help would be welcome.
Thank you.
Finally the solution was changing
$jasper = Yii::$app->jasper;
to
$jasper = new \chrmorandi\jasper\Jasper();
Don't know why in the yii2-jasper documentation is setted so if it does not work. Anyway you can make it work following my above compilation.
As the
use chrmorandi\Jasper
is not working properly
You will have to change Jasper.php setting in the init function this
$componentes = Yii::$app->components;
$this->db = $componentes['jasper']['db'];
to make it work.
Editing under vendors is not something I want to do. In order to prevent these fixes I moved from chrmorandi's extension (until its improvement) to cossou/jasperphp extension.
So far the cossou's extension reaches all my goals.
I hope this helps somebody.

Class 'GoogleSession' not found when using composer

I'm using the google-trends library and installed it with composer
composer update jonasva/google-trends
my composer.json:
{
"require": {
"jonasva/google-trends": "dev-master"
}
}
I included the file start.php in the main folder:
require __DIR__ . '/vendor/autoload.php';
$config = [
'email' => 'myemail#gmail.com',
'password' => 'mypass',
];
$session = (new GoogleSession($config))->authenticate();
$response = (new GoogleTrendsRequest($session))
->setDateRange(new \DateTime('2014-02-01'), new \DateTime()) // date range, if not passed, the past year will be used by default
->setLocation('BE') // For location Belgium
->getTopQueries() // cid (top queries)
->send(); //execute the request
$data = $response->getTermsObjects(); // return an array of GoogleTrendsTerm objects
But I get
Fatal error: Class 'GoogleSession' not found in
Should I include files other than vendor/autoload.php?
The author conveniently didn't mention the fact that the actual fully qualified class name is Jonasva\GoogleTrends\GoogleSession.
use Jonasva\GoogleTrends\GoogleSession; at the top of your file.
Check the source code of the library to figure out such information.
You have to use FQDN. Namespace + Classname
$session = (new Jonasva\GoogleTrends\GoogleSession($config))->authenticate();

How to run console command in yii2 from web

I have created a console command in console/controllers with SuggestionController .
If i run command like php yii suggestions, its working.
I want to know how to execute console command from web without any extensions of yii2.
It can be done much simpler
$oldApp = \Yii::$app;
new \yii\console\Application([
'id' => 'Command runner',
'basePath' => '#app',
'components' => [
'db' => $oldApp->db,
],
);
\Yii::$app->runAction('migrate/up', ['migrationPath' => '#yii/rbac/migrations/', 'interactive' => false]);
\Yii:$app = $oldApp;
Github LINK
As of Yii2 - 2.0.11.2 advanced app -- this works
First let's make sure controller and namespace correct. In this case frontend app accessing console application import method()
In console\controllers\FhirController
Set the alias to be available in the console\config\main.php [OPTIONAL]
'aliases' => [
'#common' => dirname(__DIR__),
'#frontend' => dirname(dirname(__DIR__)) . '/frontend',
'#backend' => dirname(dirname(__DIR__)) . '/backend',
'#console' => dirname(dirname(__DIR__)) . '/console',
],
Finally from the frontend view, make the call like this:
In this case, calling the controller route fhir then method import()
$consoleController = new console\controllers\FhirController('fhir', Yii::$app);
$consoleController->runAction('import');
On a site I'm overhauling, I have a need for a background task, that can be toggled via an action, which requires that I can also find its pid using ps. After much googling and almost as much swearing, I pieced together the solution.
# First change to (already-calculated) correct dir:
chdir($strPath);
# Now execute with nohup, directed to dev/null, and crucially with & at end, to run async:
$output = shell_exec("nohup php yii <console controller>/<action> > /dev/null &");
Yes, I understand that shell_exec should be used with extreme caution, thanks.
This is way I found and used some time ago to run yii console controller/action (I used this for run migrations from web).
In your web controller action:
// default console commands outputs to STDOUT
// so this needs to be declared for wep app
if (! defined('STDOUT')) {
define('STDOUT', fopen('/tmp/stdout', 'w'));
}
$consoleController = new \yii\console\controllers\SuggestionController;
$consoleController->runAction('your action eg. index');
/**
* open the STDOUT output file for reading
*
* #var $message collects the resulting messages of the migrate command to be displayed in a view
*/
$handle = fopen('/tmp/stdout', 'r');
$message = '';
while (($buffer = fgets($handle, 4096)) !== false) {
$message .= $buffer . "\n";
}
fclose($handle);
return $message;
You can either exec() your command ´´´php yii suggestions´´´ but this may result in permission issues with the webserver user.
The better way is to use a ConsoleRunner extension, e.g. yii2-console-runner or yii2-console-runner-extension which do the job control job a little bit more sophisticated and more secure with popen().
Always be aware of code injections when executing exec() and the like!
I think this is the simplest solution:
$controller = new SuggestionController(Yii::$app->controller->id, Yii::$app);
$controller->actionSuggestions();
yii2 call console command from web or api .
my controller name :
UnitController
in folder
console/controllers
my action name :
actionUnitDesc
if(!defined('STDIN')) define('STDIN', fopen('php://stdin', 'rb'));
if(!defined('STDOUT')) define('STDOUT', fopen('php://stdout', 'wb'));
if(!defined('STDERR')) define('STDERR', fopen('php://stderr', 'wb'));
$consoleController = new \console\controllers\UnitController('unit', Yii::$app);
$consoleController->runAction('unit-des');

Fatal error HelperSet not found when setting up Doctrine Console (with CodeIgniter)

I've got a problem setting up Doctrine with CodeIgniter. When running the following error is coming up:
Fatal error: Class 'Symfony\Component\Console\Helper\HelperSet' not found in /Applications/MAMP/htdocs/CodeIgniter-2.2.1/application/doctrine.php on line 21
The folder structure looks like this
/application/
/application/doctrine.php
/application/libraries/
/application/libraries/Doctrine/
/application/libraries/Doctrine/Common
/application/libraries/Doctrine/DBAL
/application/libraries/Doctrine/ORM
/application/libraries/Doctrine/Symfony
/application/libraries/Doctrine/Doctrine.php
/application/libraries/Doctrine/index.html
This is the line 21
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));
Cannot find out what is the problem..
Followed this tutorial: http://wildlyinaccurate.com/integrating-doctrine-2-with-codeigniter-2/
update This is my doctrine.php in the application folder
<?php
define('APPPATH', dirname(__FILE__) . '/');
define('BASEPATH', APPPATH . '/../system/');
define('ENVIRONMENT', 'development');
chdir(APPPATH);
require __DIR__ . '/libraries/Doctrine.php';
foreach ($GLOBALS as $helperSetCandidate) {
if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) {
$helperSet = $helperSetCandidate;
break;
}
}
$doctrine = new Doctrine;
$em = $doctrine->em;
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));
\Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet);
Just downloaded github version and without any extra settings everything seems to be ok.
Check if the HelperSet.php file exists in Doctrine/Symfony/Component/Console/Helper directory, and add these lines to Doctrine.php in libraries directory (you have to register Symfony classes):
$symfonyClassLoader = new ClassLoader('Symfony', APPPATH.'your_path_to/Doctrine');
$symfonyClassLoader->register();
This GitHub repository is for CodeIgniter 2, don't use it.
Try this tutorial, it works fine for me, even for CI 3.

Categories