Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Grav\Common; use Closure; use Grav\Common\Assets\Pipeline; use Grav\Commo..

Decoded Output download

<?php
 namespace Grav\Common; use Closure; use Grav\Common\Assets\Pipeline; use Grav\Common\Assets\Traits\LegacyAssetsTrait; use Grav\Common\Assets\Traits\TestingAssetsTrait; use Grav\Common\Config\Config; use Grav\Framework\Object\PropertyObject; use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator; use function array_slice; use function call_user_func_array; use function func_get_args; use function is_array; class Assets extends PropertyObject { use TestingAssetsTrait; use LegacyAssetsTrait; const LINK = "link"; const CSS = "css"; const JS = "js"; const JS_MODULE = "js_module"; const LINK_COLLECTION = "assets_link"; const CSS_COLLECTION = "assets_css"; const JS_COLLECTION = "assets_js"; const JS_MODULE_COLLECTION = "assets_js_module"; const LINK_TYPE = Assets\Link::class; const CSS_TYPE = Assets\Css::class; const JS_TYPE = Assets\Js::class; const JS_MODULE_TYPE = Assets\JsModule::class; const INLINE_CSS_TYPE = Assets\InlineCss::class; const INLINE_JS_TYPE = Assets\InlineJs::class; const INLINE_JS_MODULE_TYPE = Assets\InlineJsModule::class; const DEFAULT_REGEX = "/.\.(css|js)$/i"; const CSS_REGEX = "/.\.css$/i"; const JS_REGEX = "/.\.js$/i"; const JS_MODULE_REGEX = "/.\.mjs$/i"; protected $assets_dir; protected $assets_url; protected $assets_link = array(); protected $assets_css = array(); protected $assets_js = array(); protected $assets_js_module = array(); protected $css_pipeline; protected $css_pipeline_include_externals; protected $css_pipeline_before_excludes; protected $js_pipeline; protected $js_pipeline_include_externals; protected $js_pipeline_before_excludes; protected $js_module_pipeline; protected $js_module_pipeline_include_externals; protected $js_module_pipeline_before_excludes; protected $pipeline_options = array(); protected $fetch_command; protected $autoload; protected $enable_asset_timestamp; protected $collections; protected $timestamp; protected $order = array(); public function init() { $grav = Grav::instance(); $config = $grav["config"]; $asset_config = (array) $config->get("system.assets"); $locator = $grav["locator"]; $this->assets_dir = $locator->findResource("asset://"); $this->assets_url = $locator->findResource("asset://", false); $this->config($asset_config); foreach ((array) $this->collections as $name => $collection) { $this->registerCollection($name, (array) $collection); } } public function config(array $config) { foreach ($config as $key => $value) { if ($this->hasProperty($key)) { $this->setProperty($key, $value); } elseif (Utils::startsWith($key, "css_") || Utils::startsWith($key, "js_")) { $this->pipeline_options[$key] = $value; } } if ($this->enable_asset_timestamp) { $this->timestamp = Grav::instance()["cache"]->getKey(); } return $this; } public function add($asset) { if (!$asset) { return $this; } $args = func_get_args(); if (is_array($asset)) { foreach ($asset as $index => $location) { $params = array_slice($args, 1); if (is_array($location)) { $params = array_shift($params); if (is_numeric($params)) { $params = array("priority" => $params); } $params = array(array_replace_recursive(array(), $location, $params)); $location = $index; } $params = array_merge(array($location), $params); call_user_func_array(array($this, "add"), $params); } } elseif (isset($this->collections[$asset])) { array_shift($args); $args = array_merge(array($this->collections[$asset]), $args); call_user_func_array(array($this, "add"), $args); } else { $path = parse_url($asset, PHP_URL_PATH); $extension = $path ? Utils::pathinfo($path, PATHINFO_EXTENSION) : ''; if ($extension !== '') { $extension = strtolower($extension); if ($extension === "css") { call_user_func_array(array($this, "addCss"), $args); } elseif ($extension === "js") { call_user_func_array(array($this, "addJs"), $args); } elseif ($extension === "mjs") { call_user_func_array(array($this, "addJsModule"), $args); } } } return $this; } protected function addType($collection, $type, $asset, $options) { if (is_array($asset)) { foreach ($asset as $index => $location) { $assetOptions = $options; if (is_array($location)) { $assetOptions = array_replace_recursive(array(), $options, $location); $location = $index; } $this->addType($collection, $type, $location, $assetOptions); } return $this; } if ($this->isValidType($type) && isset($this->collections[$asset])) { $this->addType($collection, $type, $this->collections[$asset], $options); return $this; } if (isset($options["pipeline"])) { if ($options["pipeline"] === false) { $exclude_type = $this->getBaseType($type); $excludes = strtolower($exclude_type . "_pipeline_before_excludes"); if ($this->{$excludes}) { $default = "after"; } else { $default = "before"; } $options["position"] = $options["position"] ?? $default; } unset($options["pipeline"]); } $timestamp_override = $options["timestamp"] ?? true; if (filter_var($timestamp_override, FILTER_VALIDATE_BOOLEAN)) { $options["timestamp"] = $this->timestamp; } else { $options["timestamp"] = null; } $group = $options["group"] ?? "head"; $position = $options["position"] ?? "pipeline"; $orderKey = "{$type}|{$group}|{$position}"; if (!isset($this->order[$orderKey])) { $this->order[$orderKey] = 0; } $options["order"] = $this->order[$orderKey]++; $asset_object = new $type(); if ($asset_object->init($asset, $options)) { $this->{$collection[md5($asset)]} = $asset_object; } return $this; } public function addLink($asset) { return $this->addType($this::LINK_COLLECTION, $this::LINK_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::LINK_TYPE)); } public function addCss($asset) { return $this->addType($this::CSS_COLLECTION, $this::CSS_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::CSS_TYPE)); } public function addInlineCss($asset) { return $this->addType($this::CSS_COLLECTION, $this::INLINE_CSS_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::INLINE_CSS_TYPE)); } public function addJs($asset) { return $this->addType($this::JS_COLLECTION, $this::JS_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::JS_TYPE)); } public function addInlineJs($asset) { return $this->addType($this::JS_COLLECTION, $this::INLINE_JS_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::INLINE_JS_TYPE)); } public function addJsModule($asset) { return $this->addType($this::JS_MODULE_COLLECTION, $this::JS_MODULE_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::JS_MODULE_TYPE)); } public function addInlineJsModule($asset) { return $this->addType($this::JS_MODULE_COLLECTION, $this::INLINE_JS_MODULE_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::INLINE_JS_MODULE_TYPE)); } public function registerCollection($collectionName, array $assets, $overwrite = false) { if ($overwrite || !isset($this->collections[$collectionName])) { $this->collections[$collectionName] = $assets; } return $this; } protected function filterAssets($assets, $key, $value, $sort = false) { $results = array_filter($assets, function ($asset) use($key, $value) { if ($key === "position" && $value === "pipeline") { $type = $asset->getType(); if ($type === "jsmodule") { $type = "js_module"; } if ($asset->getRemote() && $this->{strtolower($type) . "_pipeline_include_externals"} === false && $asset["position"] === "pipeline") { if ($this->{strtolower($type) . "_pipeline_before_excludes"}) { $asset->setPosition("after"); } else { $asset->setPosition("before"); } return false; } } if ($asset[$key] === $value) { return true; } return false; }); if ($sort && !empty($results)) { $results = $this->sortAssets($results); } return $results; } protected function sortAssets($assets) { uasort($assets, static function ($a, $b) { return $b["priority"] <=> $a["priority"] ?: $a["order"] <=> $b["order"]; }); return $assets; } public function render($type, $group = "head", $attributes = array()) { $before_output = ''; $pipeline_output = ''; $after_output = ''; $assets = "assets_" . $type; $pipeline_enabled = $type . "_pipeline"; $render_pipeline = "render" . ucfirst($type); $group_assets = $this->filterAssets($this->{$assets}, "group", $group); $pipeline_assets = $this->filterAssets($group_assets, "position", "pipeline", true); $before_assets = $this->filterAssets($group_assets, "position", "before", true); $after_assets = $this->filterAssets($group_assets, "position", "after", true); if ($this->{$pipeline_enabled} ?? false) { $options = array_merge($this->pipeline_options, array("timestamp" => $this->timestamp)); $pipeline = new Pipeline($options); $pipeline_output = $pipeline->{$render_pipeline}($pipeline_assets, $group, $attributes); } else { foreach ($pipeline_assets as $asset) { $pipeline_output .= $asset->render(); } } foreach ($before_assets as $asset) { $before_output .= $asset->render(); } foreach ($after_assets as $asset) { $after_output .= $asset->render(); } return $before_output . $pipeline_output . $after_output; } public function css($group = "head", $attributes = array(), $include_link = true) { $output = ''; if ($include_link) { $output = $this->link($group, $attributes); } $output .= $this->render(self::CSS, $group, $attributes); return $output; } public function link($group = "head", $attributes = array()) { return $this->render(self::LINK, $group, $attributes); } public function js($group = "head", $attributes = array(), $include_js_module = true) { $output = $this->render(self::JS, $group, $attributes); if ($include_js_module) { $output .= $this->jsModule($group, $attributes); } return $output; } public function jsModule($group = "head", $attributes = array()) { return $this->render(self::JS_MODULE, $group, $attributes); } public function all($group = "head", $attributes = array()) { $output = $this->css($group, $attributes, false); $output .= $this->link($group, $attributes); $output .= $this->js($group, $attributes, false); $output .= $this->jsModule($group, $attributes); return $output; } protected function isValidType($type) { return in_array($type, array(self::CSS_TYPE, self::JS_TYPE, self::JS_MODULE_TYPE)); } protected function getBaseType($type) { switch ($type) { case $this::JS_TYPE: case $this::INLINE_JS_TYPE: $base_type = $this::JS; break; case $this::JS_MODULE_TYPE: case $this::INLINE_JS_MODULE_TYPE: $base_type = $this::JS_MODULE; break; default: $base_type = $this::CSS; } return $base_type; } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace Grav\Common; use Closure; use Grav\Common\Assets\Pipeline; use Grav\Common\Assets\Traits\LegacyAssetsTrait; use Grav\Common\Assets\Traits\TestingAssetsTrait; use Grav\Common\Config\Config; use Grav\Framework\Object\PropertyObject; use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator; use function array_slice; use function call_user_func_array; use function func_get_args; use function is_array; class Assets extends PropertyObject { use TestingAssetsTrait; use LegacyAssetsTrait; const LINK = "\154\x69\156\153"; const CSS = "\143\163\x73"; const JS = "\152\163"; const JS_MODULE = "\x6a\x73\137\x6d\157\144\x75\x6c\145"; const LINK_COLLECTION = "\141\x73\x73\x65\x74\x73\137\154\x69\156\153"; const CSS_COLLECTION = "\141\x73\163\145\x74\163\137\143\163\x73"; const JS_COLLECTION = "\x61\x73\x73\145\164\x73\137\152\x73"; const JS_MODULE_COLLECTION = "\x61\163\163\x65\x74\163\x5f\x6a\x73\137\x6d\x6f\x64\165\x6c\145"; const LINK_TYPE = Assets\Link::class; const CSS_TYPE = Assets\Css::class; const JS_TYPE = Assets\Js::class; const JS_MODULE_TYPE = Assets\JsModule::class; const INLINE_CSS_TYPE = Assets\InlineCss::class; const INLINE_JS_TYPE = Assets\InlineJs::class; const INLINE_JS_MODULE_TYPE = Assets\InlineJsModule::class; const DEFAULT_REGEX = "\x2f\56\x5c\x2e\x28\143\163\x73\174\152\x73\x29\x24\x2f\x69"; const CSS_REGEX = "\57\56\134\x2e\143\x73\x73\44\x2f\151"; const JS_REGEX = "\57\56\x5c\56\x6a\x73\x24\57\151"; const JS_MODULE_REGEX = "\x2f\56\x5c\x2e\x6d\152\x73\x24\x2f\x69"; protected $assets_dir; protected $assets_url; protected $assets_link = array(); protected $assets_css = array(); protected $assets_js = array(); protected $assets_js_module = array(); protected $css_pipeline; protected $css_pipeline_include_externals; protected $css_pipeline_before_excludes; protected $js_pipeline; protected $js_pipeline_include_externals; protected $js_pipeline_before_excludes; protected $js_module_pipeline; protected $js_module_pipeline_include_externals; protected $js_module_pipeline_before_excludes; protected $pipeline_options = array(); protected $fetch_command; protected $autoload; protected $enable_asset_timestamp; protected $collections; protected $timestamp; protected $order = array(); public function init() { $grav = Grav::instance(); $config = $grav["\x63\x6f\156\x66\x69\147"]; $asset_config = (array) $config->get("\163\x79\163\x74\145\155\x2e\141\x73\x73\x65\164\x73"); $locator = $grav["\154\x6f\143\x61\164\x6f\x72"]; $this->assets_dir = $locator->findResource("\141\163\x73\145\x74\x3a\57\57"); $this->assets_url = $locator->findResource("\x61\163\163\145\x74\72\x2f\x2f", false); $this->config($asset_config); foreach ((array) $this->collections as $name => $collection) { $this->registerCollection($name, (array) $collection); } } public function config(array $config) { foreach ($config as $key => $value) { if ($this->hasProperty($key)) { $this->setProperty($key, $value); } elseif (Utils::startsWith($key, "\143\163\163\137") || Utils::startsWith($key, "\x6a\163\x5f")) { $this->pipeline_options[$key] = $value; } } if ($this->enable_asset_timestamp) { $this->timestamp = Grav::instance()["\x63\141\143\x68\x65"]->getKey(); } return $this; } public function add($asset) { if (!$asset) { return $this; } $args = func_get_args(); if (is_array($asset)) { foreach ($asset as $index => $location) { $params = array_slice($args, 1); if (is_array($location)) { $params = array_shift($params); if (is_numeric($params)) { $params = array("\160\x72\x69\157\162\x69\x74\171" => $params); } $params = array(array_replace_recursive(array(), $location, $params)); $location = $index; } $params = array_merge(array($location), $params); call_user_func_array(array($this, "\x61\x64\x64"), $params); } } elseif (isset($this->collections[$asset])) { array_shift($args); $args = array_merge(array($this->collections[$asset]), $args); call_user_func_array(array($this, "\x61\x64\144"), $args); } else { $path = parse_url($asset, PHP_URL_PATH); $extension = $path ? Utils::pathinfo($path, PATHINFO_EXTENSION) : ''; if ($extension !== '') { $extension = strtolower($extension); if ($extension === "\143\x73\x73") { call_user_func_array(array($this, "\141\144\144\x43\163\163"), $args); } elseif ($extension === "\x6a\x73") { call_user_func_array(array($this, "\x61\x64\x64\x4a\163"), $args); } elseif ($extension === "\x6d\x6a\163") { call_user_func_array(array($this, "\141\144\x64\x4a\163\115\x6f\x64\x75\x6c\145"), $args); } } } return $this; } protected function addType($collection, $type, $asset, $options) { if (is_array($asset)) { foreach ($asset as $index => $location) { $assetOptions = $options; if (is_array($location)) { $assetOptions = array_replace_recursive(array(), $options, $location); $location = $index; } $this->addType($collection, $type, $location, $assetOptions); } return $this; } if ($this->isValidType($type) && isset($this->collections[$asset])) { $this->addType($collection, $type, $this->collections[$asset], $options); return $this; } if (isset($options["\x70\151\x70\145\154\151\x6e\145"])) { if ($options["\x70\151\x70\145\x6c\151\x6e\145"] === false) { $exclude_type = $this->getBaseType($type); $excludes = strtolower($exclude_type . "\137\160\151\x70\x65\x6c\x69\x6e\x65\x5f\x62\x65\x66\x6f\x72\145\137\x65\x78\143\x6c\165\144\145\163"); if ($this->{$excludes}) { $default = "\x61\x66\164\x65\x72"; } else { $default = "\x62\x65\146\x6f\x72\x65"; } $options["\x70\157\x73\x69\164\x69\157\156"] = $options["\x70\x6f\163\x69\x74\x69\157\x6e"] ?? $default; } unset($options["\x70\151\x70\x65\154\x69\x6e\145"]); } $timestamp_override = $options["\164\151\x6d\145\x73\x74\x61\155\x70"] ?? true; if (filter_var($timestamp_override, FILTER_VALIDATE_BOOLEAN)) { $options["\164\x69\155\x65\x73\x74\141\155\160"] = $this->timestamp; } else { $options["\164\x69\155\x65\163\x74\141\x6d\160"] = null; } $group = $options["\147\x72\x6f\165\160"] ?? "\x68\145\141\144"; $position = $options["\x70\157\163\151\x74\x69\x6f\156"] ?? "\160\151\x70\x65\x6c\151\156\x65"; $orderKey = "{$type}\x7c{$group}\174{$position}"; if (!isset($this->order[$orderKey])) { $this->order[$orderKey] = 0; } $options["\157\162\x64\x65\x72"] = $this->order[$orderKey]++; $asset_object = new $type(); if ($asset_object->init($asset, $options)) { $this->{$collection[md5($asset)]} = $asset_object; } return $this; } public function addLink($asset) { return $this->addType($this::LINK_COLLECTION, $this::LINK_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::LINK_TYPE)); } public function addCss($asset) { return $this->addType($this::CSS_COLLECTION, $this::CSS_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::CSS_TYPE)); } public function addInlineCss($asset) { return $this->addType($this::CSS_COLLECTION, $this::INLINE_CSS_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::INLINE_CSS_TYPE)); } public function addJs($asset) { return $this->addType($this::JS_COLLECTION, $this::JS_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::JS_TYPE)); } public function addInlineJs($asset) { return $this->addType($this::JS_COLLECTION, $this::INLINE_JS_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::INLINE_JS_TYPE)); } public function addJsModule($asset) { return $this->addType($this::JS_MODULE_COLLECTION, $this::JS_MODULE_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::JS_MODULE_TYPE)); } public function addInlineJsModule($asset) { return $this->addType($this::JS_MODULE_COLLECTION, $this::INLINE_JS_MODULE_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::INLINE_JS_MODULE_TYPE)); } public function registerCollection($collectionName, array $assets, $overwrite = false) { if ($overwrite || !isset($this->collections[$collectionName])) { $this->collections[$collectionName] = $assets; } return $this; } protected function filterAssets($assets, $key, $value, $sort = false) { $results = array_filter($assets, function ($asset) use($key, $value) { if ($key === "\160\x6f\x73\x69\164\151\x6f\x6e" && $value === "\x70\151\x70\145\154\x69\156\x65") { $type = $asset->getType(); if ($type === "\x6a\163\155\x6f\144\x75\x6c\145") { $type = "\x6a\x73\137\x6d\157\144\165\x6c\x65"; } if ($asset->getRemote() && $this->{strtolower($type) . "\x5f\x70\151\160\x65\x6c\151\x6e\x65\137\151\x6e\x63\x6c\165\144\x65\x5f\x65\170\x74\x65\x72\x6e\x61\x6c\x73"} === false && $asset["\x70\157\163\x69\164\151\x6f\x6e"] === "\x70\151\x70\145\154\151\156\x65") { if ($this->{strtolower($type) . "\x5f\x70\151\x70\145\x6c\x69\x6e\145\137\142\x65\146\157\x72\145\x5f\145\x78\143\x6c\165\x64\145\163"}) { $asset->setPosition("\141\x66\x74\x65\162"); } else { $asset->setPosition("\142\145\x66\x6f\162\145"); } return false; } } if ($asset[$key] === $value) { return true; } return false; }); if ($sort && !empty($results)) { $results = $this->sortAssets($results); } return $results; } protected function sortAssets($assets) { uasort($assets, static function ($a, $b) { return $b["\160\162\151\157\162\x69\164\171"] <=> $a["\160\x72\x69\157\162\151\x74\x79"] ?: $a["\157\x72\x64\145\162"] <=> $b["\x6f\x72\x64\x65\x72"]; }); return $assets; } public function render($type, $group = "\x68\145\141\144", $attributes = array()) { $before_output = ''; $pipeline_output = ''; $after_output = ''; $assets = "\141\x73\x73\x65\x74\x73\137" . $type; $pipeline_enabled = $type . "\137\x70\x69\160\x65\154\x69\156\x65"; $render_pipeline = "\162\x65\156\x64\x65\x72" . ucfirst($type); $group_assets = $this->filterAssets($this->{$assets}, "\x67\162\157\165\160", $group); $pipeline_assets = $this->filterAssets($group_assets, "\x70\157\163\x69\164\x69\157\156", "\x70\x69\160\x65\154\151\x6e\145", true); $before_assets = $this->filterAssets($group_assets, "\x70\157\163\151\164\151\157\x6e", "\x62\x65\146\157\x72\x65", true); $after_assets = $this->filterAssets($group_assets, "\x70\x6f\x73\x69\x74\151\x6f\x6e", "\x61\x66\164\x65\162", true); if ($this->{$pipeline_enabled} ?? false) { $options = array_merge($this->pipeline_options, array("\x74\151\x6d\145\x73\164\x61\155\x70" => $this->timestamp)); $pipeline = new Pipeline($options); $pipeline_output = $pipeline->{$render_pipeline}($pipeline_assets, $group, $attributes); } else { foreach ($pipeline_assets as $asset) { $pipeline_output .= $asset->render(); } } foreach ($before_assets as $asset) { $before_output .= $asset->render(); } foreach ($after_assets as $asset) { $after_output .= $asset->render(); } return $before_output . $pipeline_output . $after_output; } public function css($group = "\150\x65\141\x64", $attributes = array(), $include_link = true) { $output = ''; if ($include_link) { $output = $this->link($group, $attributes); } $output .= $this->render(self::CSS, $group, $attributes); return $output; } public function link($group = "\x68\145\x61\144", $attributes = array()) { return $this->render(self::LINK, $group, $attributes); } public function js($group = "\x68\x65\x61\x64", $attributes = array(), $include_js_module = true) { $output = $this->render(self::JS, $group, $attributes); if ($include_js_module) { $output .= $this->jsModule($group, $attributes); } return $output; } public function jsModule($group = "\150\145\141\x64", $attributes = array()) { return $this->render(self::JS_MODULE, $group, $attributes); } public function all($group = "\x68\x65\x61\144", $attributes = array()) { $output = $this->css($group, $attributes, false); $output .= $this->link($group, $attributes); $output .= $this->js($group, $attributes, false); $output .= $this->jsModule($group, $attributes); return $output; } protected function isValidType($type) { return in_array($type, array(self::CSS_TYPE, self::JS_TYPE, self::JS_MODULE_TYPE)); } protected function getBaseType($type) { switch ($type) { case $this::JS_TYPE: case $this::INLINE_JS_TYPE: $base_type = $this::JS; break; case $this::JS_MODULE_TYPE: case $this::INLINE_JS_MODULE_TYPE: $base_type = $this::JS_MODULE; break; default: $base_type = $this::CSS; } return $base_type; } }

Function Calls

None

Variables

None

Stats

MD5 fc30c296dd1527dc03da22ac9629ae7f
Eval Count 0
Decode Time 85 ms