diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 7b0276a59b..2b74b9d868 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -449,10 +449,11 @@ public function fallbackUrl($path) $supported_types = $config->get('media.types'); // Check whitelist first, then ensure extension is a valid media type - if (!empty($fallback_types) && !in_array($uri_extension, $fallback_types)) { - return; - } elseif (!array_key_exists($uri_extension, $supported_types)) { - return; + if (!empty($fallback_types) && !\in_array($uri_extension, $fallback_types, true)) { + return false; + } + if (!array_key_exists($uri_extension, $supported_types)) { + return false; } $path_parts = pathinfo($path); diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index e5c230ce9b..59be69b0ef 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -35,7 +35,7 @@ protected function init($page, $defaults) $grav = Grav::instance(); $this->page = $page; - $this->BlockTypes['{'] [] = "TwigTag"; + $this->BlockTypes['{'] [] = 'TwigTag'; $this->special_chars = ['>' => 'gt', '<' => 'lt', '"' => 'quot']; if ($defaults === null) { @@ -56,6 +56,9 @@ protected function init($page, $defaults) * * @param $type * @param $tag + * @param bool $continuable + * @param bool $completable + * @param $index */ public function addBlockType($type, $tag, $continuable = false, $completable = false, $index = null) { @@ -67,7 +70,7 @@ public function addBlockType($type, $tag, $continuable = false, $completable = f $block = &$this->BlockTypes[$type]; } - if (!isset($index)) { + if (null === $index) { $block[] = $tag; } else { array_splice($block, $index, 0, [$tag]); @@ -86,10 +89,11 @@ public function addBlockType($type, $tag, $continuable = false, $completable = f * * @param $type * @param $tag + * @param $index */ public function addInlineType($type, $tag, $index = null) { - if (!isset($index) || !isset($this->InlineTypes[$type])) { + if (null === $index || !isset($this->InlineTypes[$type])) { $this->InlineTypes[$type] [] = $tag; } else { array_splice($this->InlineTypes[$type], $index, 0, [$tag]); @@ -109,7 +113,7 @@ public function addInlineType($type, $tag, $index = null) */ protected function isBlockContinuable($Type) { - $continuable = in_array($Type, $this->continuable_blocks) || method_exists($this, 'block' . $Type . 'Continue'); + $continuable = \in_array($Type, $this->continuable_blocks) || method_exists($this, 'block' . $Type . 'Continue'); return $continuable; } @@ -123,7 +127,7 @@ protected function isBlockContinuable($Type) */ protected function isBlockCompletable($Type) { - $completable = in_array($Type, $this->completable_blocks) || method_exists($this, 'block' . $Type . 'Complete'); + $completable = \in_array($Type, $this->completable_blocks) || method_exists($this, 'block' . $Type . 'Complete'); return $completable; } @@ -157,32 +161,31 @@ public function setSpecialChars($special_chars) /** * Ensure Twig tags are treated as block level items with no
tags + * + * @param array $line + * @return array|null */ - protected function blockTwigTag($Line) + protected function blockTwigTag($line) { - if (preg_match('/(?:{{|{%|{#)(.*)(?:}}|%}|#})/', $Line['body'], $matches)) { - $Block = [ - 'markup' => $Line['body'], - ]; - - return $Block; + if (preg_match('/(?:{{|{%|{#)(.*)(?:}}|%}|#})/', $line['body'], $matches)) { + return ['markup' => $line['body']]; } return null; } - protected function inlineSpecialCharacter($Excerpt) + protected function inlineSpecialCharacter($excerpt) { - if ($Excerpt['text'][0] === '&' && !preg_match('/^?\w+;/', $Excerpt['text'])) { + if ($excerpt['text'][0] === '&' && !preg_match('/^?\w+;/', $excerpt['text'])) { return [ 'markup' => '&', 'extent' => 1, ]; } - if (isset($this->special_chars[$Excerpt['text'][0]])) { + if (isset($this->special_chars[$excerpt['text'][0]])) { return [ - 'markup' => '&' . $this->special_chars[$Excerpt['text'][0]] . ';', + 'markup' => '&' . $this->special_chars[$excerpt['text'][0]] . ';', 'extent' => 1, ]; } @@ -199,11 +202,11 @@ protected function inlineImage($excerpt) $excerpt['extent'] = $excerpt['extent'] + strlen($matches[1]) - 1; return $excerpt; - } else { - $excerpt['type'] = 'image'; - $excerpt = parent::inlineImage($excerpt); } + $excerpt['type'] = 'image'; + $excerpt = parent::inlineImage($excerpt); + // if this is an image process it if (isset($excerpt['element']['attributes']['src'])) { $excerpt = Excerpts::processImageExcerpt($excerpt, $this->page); @@ -228,10 +231,10 @@ protected function inlineLink($excerpt) $excerpt['extent'] = $excerpt['extent'] + strlen($matches[1]) - 1; return $excerpt; - } else { - $excerpt = parent::inlineLink($excerpt); } + $excerpt = parent::inlineLink($excerpt); + // if this is a link if (isset($excerpt['element']['attributes']['href'])) { $excerpt = Excerpts::processLinkExcerpt($excerpt, $this->page, $type); @@ -243,10 +246,10 @@ protected function inlineLink($excerpt) // For extending this class via plugins public function __call($method, $args) { - if (isset($this->$method) === true) { - $func = $this->$method; + if (isset($this->{$method}) === true) { + $func = $this->{$method}; - return call_user_func_array($func, $args); + return \call_user_func_array($func, $args); } return null;