Файловый менеджер - Редактировать - /home/easybachat/hisabat365.com/4a7891/purifier.tar
Ðазад
src/PurifierServiceProvider.php 0000644 00000003014 15060221126 0012656 0 ustar 00 <?php namespace Mews\Purifier; use Illuminate\Container\Container; use Illuminate\Foundation\Application as LaravelApplication; use Illuminate\Support\ServiceProvider; use Laravel\Lumen\Application as LumenApplication; class PurifierServiceProvider extends ServiceProvider { /** * Indicates if loading of the provider is deferred. * * @var bool */ protected $defer = true; /** * Boot the service provider. * * @return null */ public function boot() { if ($this->app instanceof LaravelApplication) { $this->publishes([$this->getConfigSource() => config_path('purifier.php')]); } elseif ($this->app instanceof LumenApplication) { $this->app->configure('purifier'); } } /** * Get the config source. * * @return string */ protected function getConfigSource() { return realpath(__DIR__.'/../config/purifier.php'); } /** * Register the service provider. * * @return void */ public function register() { $this->mergeConfigFrom($this->getConfigSource(), 'purifier'); $this->app->singleton('purifier', function (Container $app) { return new Purifier($app['files'], $app['config']); }); $this->app->alias('purifier', Purifier::class); } /** * Get the services provided by the provider. * * @return array */ public function provides() { return ['purifier']; } } src/Facades/Purifier.php 0000644 00000000511 15060221126 0011147 0 ustar 00 <?php namespace Mews\Purifier\Facades; use Illuminate\Support\Facades\Facade; /** * @method static mixed clean($dirty, $config = null, \Closure $postCreateConfigHook = null) * @see \Mews\Purifier */ class Purifier extends Facade { protected static function getFacadeAccessor() { return 'purifier'; } } src/helpers.php 0000644 00000000231 15060221126 0007475 0 ustar 00 <?php if (!function_exists('clean')) { function clean($dirty, $config = null) { return app('purifier')->clean($dirty, $config); } } src/Purifier.php 0000644 00000021150 15060221126 0007623 0 ustar 00 <?php namespace Mews\Purifier; /** * Laravel 5 HTMLPurifier package * * @copyright Copyright (c) 2015 MeWebStudio * @version 2.0.0 * @author Muharrem ERİN * @contact me@mewebstudio.com * @web http://www.mewebstudio.com * @date 2014-04-02 * @license MIT */ use Exception; use HTMLPurifier; use HTMLPurifier_Config; use HTMLPurifier_HTMLDefinition; use Illuminate\Contracts\Config\Repository; use Illuminate\Filesystem\Filesystem; class Purifier { /** * @var Filesystem */ protected $files; /** * @var Repository */ protected $config; /** * @var HTMLPurifier */ protected $purifier; /** * Constructor * * @param Filesystem $files * @param Repository $config * @throws Exception */ public function __construct(Filesystem $files, Repository $config) { $this->files = $files; $this->config = $config; $this->setUp(); } /** * Setup * * @throws Exception */ private function setUp() { if (!$this->config->has('purifier')) { throw new Exception('Configuration parameters not loaded!'); } $this->checkCacheDirectory(); // Create a new configuration object $config = $this->getConfig(); // Create HTMLPurifier object $this->purifier = new HTMLPurifier($config); } /** * Add a custom definition * * @see http://htmlpurifier.org/docs/enduser-customize.html * @param array $definitionConfig * @param HTMLPurifier_Config $configObject Defaults to using default config * * @return HTMLPurifier_Config $configObject */ private function addCustomDefinition(array $definitionConfig, HTMLPurifier_Config $configObject = null) { if (!$configObject) { $configObject = HTMLPurifier_Config::createDefault(); $configObject->loadArray($this->getConfig()); } // Setup the custom definition $configObject->set('HTML.DefinitionID', $definitionConfig['id']); $configObject->set('HTML.DefinitionRev', $definitionConfig['rev']); // Enable debug mode if (!isset($definitionConfig['debug']) || $definitionConfig['debug']) { $configObject->set('Cache.DefinitionImpl', null); } // Start configuring the definition if ($def = $configObject->maybeGetRawHTMLDefinition()) { // Create the definition attributes if (!empty($definitionConfig['attributes'])) { $this->addCustomAttributes($definitionConfig['attributes'], $def); } // Create the definition elements if (!empty($definitionConfig['elements'])) { $this->addCustomElements($definitionConfig['elements'], $def); } } return $configObject; } /** * Add provided attributes to the provided definition * * @param array $attributes * @param HTMLPurifier_HTMLDefinition $definition * * @return HTMLPurifier_HTMLDefinition $definition */ private function addCustomAttributes(array $attributes, HTMLPurifier_HTMLDefinition $definition) { foreach ($attributes as $attribute) { // Get configuration of attribute $required = !empty($attribute[3]) ? true : false; $onElement = $attribute[0]; $attrName = $required ? $attribute[1] . '*' : $attribute[1]; $validValues = $attribute[2]; if ($onElement === '*') { $def = $validValues; if (is_string($validValues)) { $def = new $validValues(); } if ($def instanceof \HTMLPurifier_AttrDef) { $definition->info_global_attr[$attrName] = $def; } continue; } if (class_exists($validValues)) { $validValues = new $validValues(); } $definition->addAttribute($onElement, $attrName, $validValues); } return $definition; } /** * Add provided elements to the provided definition * * @param array $elements * @param HTMLPurifier_HTMLDefinition $definition * * @return HTMLPurifier_HTMLDefinition $definition */ private function addCustomElements(array $elements, HTMLPurifier_HTMLDefinition $definition) { foreach ($elements as $element) { // Get configuration of element $name = $element[0]; $contentSet = $element[1]; $allowedChildren = $element[2]; $attributeCollection = $element[3]; $attributes = isset($element[4]) ? $element[4] : null; if (!empty($attributes)) { $definition->addElement($name, $contentSet, $allowedChildren, $attributeCollection, $attributes); } else { $definition->addElement($name, $contentSet, $allowedChildren, $attributeCollection); } } } /** * Check/Create cache directory */ private function checkCacheDirectory() { $cachePath = $this->config->get('purifier.cachePath'); if ($cachePath) { $this->files->makeDirectory( $cachePath, $this->config->get('purifier.cacheFileMode', 0755), true, true ); } } /** * @param array<string, mixed>|string|null $config * * @return mixed|null */ protected function getConfig($config = null) { // Create a new configuration object $configObject = HTMLPurifier_Config::createDefault(); // Allow configuration to be modified if (! $this->config->get('purifier.finalize')) { $configObject->autoFinalize = false; } // Set default config $defaultConfig = []; $defaultConfig['Core.Encoding'] = $this->config->get('purifier.encoding'); $defaultConfig['Cache.SerializerPath'] = $this->config->get('purifier.cachePath'); $defaultConfig['Cache.SerializerPermissions'] = $this->config->get('purifier.cacheFileMode', 0755); if (! $config) { $config = $this->config->get('purifier.settings.default'); } elseif (is_string($config)) { $config = $this->config->get('purifier.settings.' . $config); } if (! is_array($config)) { $config = []; } // Merge configurations $config = $defaultConfig + $config; // Load to Purifier config $configObject->loadArray($config); // Load custom definition if set if ($definitionConfig = $this->config->get('purifier.settings.custom_definition')) { $this->addCustomDefinition($definitionConfig, $configObject); } // Load custom elements if set if ($elements = $this->config->get('purifier.settings.custom_elements')) { if ($def = $configObject->maybeGetRawHTMLDefinition()) { $this->addCustomElements($elements, $def); } } // Load custom attributes if set if ($attributes = $this->config->get('purifier.settings.custom_attributes')) { if ($def = $configObject->maybeGetRawHTMLDefinition()) { $this->addCustomAttributes($attributes, $def); } } return $configObject; } /** * @param $dirty * @param array<string, mixed>|string|null $config * @param \Closure|null $postCreateConfigHook * @return mixed */ public function clean($dirty, $config = null, \Closure $postCreateConfigHook = null) { if (is_array($dirty)) { return array_map(function ($item) use ($config) { return $this->clean($item, $config); }, $dirty); } $configObject = null; if ($config !== null) { $configObject = $this->getConfig($config); if ($postCreateConfigHook !== null) { $postCreateConfigHook->call($this, $configObject); } } //If $dirty is not an explicit string, bypass purification assuming configuration allows this $ignoreNonStrings = $this->config->get('purifier.ignoreNonStrings', false); $stringTest = is_string($dirty); if($stringTest === false && $ignoreNonStrings === true) { return $dirty; } return $this->purifier->purify($dirty, $configObject); } /** * Get HTMLPurifier instance. * * @return \HTMLPurifier */ public function getInstance() { return $this->purifier; } } src/Casts/CleanHtmlInput.php 0000644 00000001574 15060221126 0012012 0 ustar 00 <?php namespace Mews\Purifier\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class CleanHtmlInput implements CastsAttributes { use WithConfig; /** * Cast the given value. Does not clean the HTML. * * @param \Illuminate\Database\Eloquent\Model $model * @param string $key * @param mixed $value * @param array $attributes * @return array */ public function get($model, $key, $value, $attributes) { return $value; } /** * Prepare the given value for storage by cleaning the HTML. * * @param \Illuminate\Database\Eloquent\Model $model * @param string $key * @param array $value * @param array $attributes * @return string */ public function set($model, $key, $value, $attributes) { return clean($value, $this->config); } } src/Casts/CleanHtmlOutput.php 0000644 00000001577 15060221126 0012216 0 ustar 00 <?php namespace Mews\Purifier\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class CleanHtmlOutput implements CastsAttributes { use WithConfig; /** * Clean the HTML when casting the given value. * * @param \Illuminate\Database\Eloquent\Model $model * @param string $key * @param mixed $value * @param array $attributes * @return array */ public function get($model, $key, $value, $attributes) { return clean($value, $this->config); } /** * Prepare the given value for storage. Does not clean the HTML. * * @param \Illuminate\Database\Eloquent\Model $model * @param string $key * @param array $value * @param array $attributes * @return string */ public function set($model, $key, $value, $attributes) { return $value; } } src/Casts/CleanHtml.php 0000644 00000001613 15060221126 0010764 0 ustar 00 <?php namespace Mews\Purifier\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class CleanHtml implements CastsAttributes { use WithConfig; /** * Clean the HTML when casting the given value. * * @param \Illuminate\Database\Eloquent\Model $model * @param string $key * @param mixed $value * @param array $attributes * @return array */ public function get($model, $key, $value, $attributes) { return clean($value, $this->config); } /** * Prepare the given value for storage by cleaning the HTML. * * @param \Illuminate\Database\Eloquent\Model $model * @param string $key * @param array $value * @param array $attributes * @return string */ public function set($model, $key, $value, $attributes) { return clean($value, $this->config); } } src/Casts/WithConfig.php 0000644 00000000323 15060221126 0011153 0 ustar 00 <?php namespace Mews\Purifier\Casts; trait WithConfig { /** * @var mixed */ protected $config; public function __construct($config = null) { $this->config = $config; } } phpunit.xml 0000755 00000001643 15060221126 0006757 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="false" backupStaticAttributes="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" failOnRisky="true" failOnWarning="true" processIsolation="false" stopOnError="false" stopOnFailure="false" verbose="true" > <testsuites> <testsuite name="Laravel Purifier Test Suite"> <directory suffix="Test.php">./tests</directory> </testsuite> </testsuites> <filter> <whitelist processUncoveredFilesFromWhitelist="true"> <directory suffix=".php">./src</directory> </whitelist> </filter> </phpunit>