@@ -17,20 +17,24 @@ discard block |
||
| 17 | 17 | $arr1_length = count($array1); |
| 18 | 18 | $arr2_length = count($array2); |
| 19 | 19 | |
| 20 | - for ($i = 0; $i < $arr1_length; ++$i) { |
|
| 21 | - if ($i >= $arr2_length) { |
|
| 20 | + for ($i = 0; $i < $arr1_length; ++$i) |
|
| 21 | + { |
|
| 22 | + if ($i >= $arr2_length) |
|
| 23 | + { |
|
| 22 | 24 | break; |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | $rhs = self::safe_get($array1, $i); |
| 26 | 28 | $lhs = self::safe_get($array2, $i); |
| 27 | 29 | |
| 28 | - if (empty($rhs)) { |
|
| 30 | + if (empty($rhs)) |
|
| 31 | + { |
|
| 29 | 32 | $result[] = $lhs; |
| 30 | 33 | |
| 31 | 34 | continue; |
| 32 | 35 | } |
| 33 | - if (empty($lhs)) { |
|
| 36 | + if (empty($lhs)) |
|
| 37 | + { |
|
| 34 | 38 | $result[] = $rhs; |
| 35 | 39 | |
| 36 | 40 | continue; |
@@ -39,10 +43,14 @@ discard block |
||
| 39 | 43 | $result[] = self::safe_get($array1, $i) . $glue . self::safe_get($array2, $i); |
| 40 | 44 | } |
| 41 | 45 | |
| 42 | - if (!$strict) { |
|
| 43 | - if ($arr2_length > $arr1_length) { |
|
| 46 | + if (!$strict) |
|
| 47 | + { |
|
| 48 | + if ($arr2_length > $arr1_length) |
|
| 49 | + { |
|
| 44 | 50 | $result = array_merge($result, array_slice($array2, $arr1_length)); |
| 45 | - } else { |
|
| 51 | + } |
|
| 52 | + else |
|
| 53 | + { |
|
| 46 | 54 | $result = array_merge($result, array_slice($array1, $arr2_length)); |
| 47 | 55 | } |
| 48 | 56 | } |
@@ -30,8 +30,10 @@ |
||
| 30 | 30 | $pieces = mb_split((string)$separator, (string)$value); |
| 31 | 31 | mb_regex_encoding($previous); |
| 32 | 32 | |
| 33 | - foreach ($pieces as $piece) { |
|
| 34 | - while (!$preserve && mb_strlen((string)$piece, $env->getCharset()) > $length) { |
|
| 33 | + foreach ($pieces as $piece) |
|
| 34 | + { |
|
| 35 | + while (!$preserve && mb_strlen((string)$piece, $env->getCharset()) > $length) |
|
| 36 | + { |
|
| 35 | 37 | $sentences[] = mb_substr((string)$piece, 0, $length, $env->getCharset()); |
| 36 | 38 | $piece = mb_substr((string)$piece, $length, 2048, $env->getCharset()); |
| 37 | 39 | } |
@@ -16,16 +16,21 @@ |
||
| 16 | 16 | { |
| 17 | 17 | $arr = []; |
| 18 | 18 | |
| 19 | - foreach ($array as $key => $item) { |
|
| 19 | + foreach ($array as $key => $item) |
|
| 20 | + { |
|
| 20 | 21 | $groupBy = __::get($item, $sortKey); |
| 21 | 22 | |
| 22 | - if ($groupBy === null) { |
|
| 23 | + if ($groupBy === null) |
|
| 24 | + { |
|
| 23 | 25 | continue; |
| 24 | 26 | } |
| 25 | 27 | |
| 26 | - if (is_bool($groupBy)) { |
|
| 28 | + if (is_bool($groupBy)) |
|
| 29 | + { |
|
| 27 | 30 | $groupBy = $groupBy ? 'true' : 'false'; |
| 28 | - } elseif (!is_scalar($groupBy)) { |
|
| 31 | + } |
|
| 32 | + elseif (!is_scalar($groupBy)) |
|
| 33 | + { |
|
| 29 | 34 | trigger_error('You cannot group by a non-scalar value', E_USER_WARNING); |
| 30 | 35 | |
| 31 | 36 | continue; |
@@ -22,10 +22,13 @@ |
||
| 22 | 22 | { |
| 23 | 23 | public function __invoke(Twig_Environment $env, $value, $length = 30, $preserve = false, $separator = '...') |
| 24 | 24 | { |
| 25 | - if (mb_strlen((string)$value, $env->getCharset()) > $length) { |
|
| 26 | - if ($preserve) { |
|
| 25 | + if (mb_strlen((string)$value, $env->getCharset()) > $length) |
|
| 26 | + { |
|
| 27 | + if ($preserve) |
|
| 28 | + { |
|
| 27 | 29 | // If breakpoint is on the last word, return the value without separator. |
| 28 | - if (($breakpoint = mb_strpos((string)$value, ' ', $length, $env->getCharset())) === false) { |
|
| 30 | + if (($breakpoint = mb_strpos((string)$value, ' ', $length, $env->getCharset())) === false) |
|
| 31 | + { |
|
| 29 | 32 | return $value; |
| 30 | 33 | } |
| 31 | 34 | |
@@ -21,7 +21,8 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public function __invoke(Environment $env, $assetPath, $absolute = false, $params = []): string |
| 23 | 23 | { |
| 24 | - if ($this->isExternalUrl($assetPath)) { |
|
| 24 | + if ($this->isExternalUrl($assetPath)) |
|
| 25 | + { |
|
| 25 | 26 | return $assetPath; |
| 26 | 27 | } |
| 27 | 28 | |
@@ -46,11 +47,13 @@ discard block |
||
| 46 | 47 | { |
| 47 | 48 | $url = '/'; |
| 48 | 49 | |
| 49 | - if (!$absolute) { |
|
| 50 | + if (!$absolute) |
|
| 51 | + { |
|
| 50 | 52 | return $url; |
| 51 | 53 | } |
| 52 | 54 | |
| 53 | - if (isset($this->site['url'])) { |
|
| 55 | + if (isset($this->site['url'])) |
|
| 56 | + { |
|
| 54 | 57 | $url = $this->site['url']; |
| 55 | 58 | } |
| 56 | 59 | |
@@ -61,9 +64,12 @@ discard block |
||
| 61 | 64 | { |
| 62 | 65 | $base = ''; |
| 63 | 66 | |
| 64 | - if (isset($this->site['baseurl'])) { |
|
| 67 | + if (isset($this->site['baseurl'])) |
|
| 68 | + { |
|
| 65 | 69 | $base = $this->site['baseurl']; |
| 66 | - } elseif (isset($this->site['base'])) { |
|
| 70 | + } |
|
| 71 | + elseif (isset($this->site['base'])) |
|
| 72 | + { |
|
| 67 | 73 | $base = $this->site['base']; |
| 68 | 74 | } |
| 69 | 75 | |
@@ -72,16 +78,20 @@ discard block |
||
| 72 | 78 | |
| 73 | 79 | private function guessAssetPath($assetPath, $params): string |
| 74 | 80 | { |
| 75 | - if ($assetPath instanceof JailedDocument && $assetPath->_coreInstanceOf(RepeaterPageView::class)) { |
|
| 81 | + if ($assetPath instanceof JailedDocument && $assetPath->_coreInstanceOf(RepeaterPageView::class)) |
|
| 82 | + { |
|
| 76 | 83 | return ($link = $assetPath->_getPermalinkWhere($params)) ? $link : '/'; |
| 77 | 84 | } |
| 78 | - if (is_array($assetPath) || ($assetPath instanceof ArrayAccess)) { |
|
| 85 | + if (is_array($assetPath) || ($assetPath instanceof ArrayAccess)) |
|
| 86 | + { |
|
| 79 | 87 | return $assetPath['permalink'] ?? '/'; |
| 80 | 88 | } |
| 81 | - if (is_null($assetPath)) { |
|
| 89 | + if (is_null($assetPath)) |
|
| 90 | + { |
|
| 82 | 91 | return '/'; |
| 83 | 92 | } |
| 84 | - if ($assetPath instanceof SplFileInfo) { |
|
| 93 | + if ($assetPath instanceof SplFileInfo) |
|
| 94 | + { |
|
| 85 | 95 | return str_replace(Service::getWorkingDirectory(), '', $assetPath); |
| 86 | 96 | } |
| 87 | 97 | |
@@ -99,7 +109,8 @@ discard block |
||
| 99 | 109 | */ |
| 100 | 110 | private function isExternalUrl(mixed $str): bool |
| 101 | 111 | { |
| 102 | - if (!is_string($str)) { |
|
| 112 | + if (!is_string($str)) |
|
| 113 | + { |
|
| 103 | 114 | return false; |
| 104 | 115 | } |
| 105 | 116 | |
@@ -113,8 +124,10 @@ discard block |
||
| 113 | 124 | { |
| 114 | 125 | $paths = []; |
| 115 | 126 | |
| 116 | - foreach (func_get_args() as $arg) { |
|
| 117 | - if ($arg !== '') { |
|
| 127 | + foreach (func_get_args() as $arg) |
|
| 128 | + { |
|
| 129 | + if ($arg !== '') |
|
| 130 | + { |
|
| 118 | 131 | $paths[] = $arg; |
| 119 | 132 | } |
| 120 | 133 | } |
@@ -45,8 +45,10 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | $results = []; |
| 47 | 47 | |
| 48 | - foreach ($array as $item) { |
|
| 49 | - if ($this->compare($item, $key, $comparison, $value)) { |
|
| 48 | + foreach ($array as $item) |
|
| 49 | + { |
|
| 50 | + if ($this->compare($item, $key, $comparison, $value)) |
|
| 51 | + { |
|
| 50 | 52 | $results[] = $item; |
| 51 | 53 | } |
| 52 | 54 | } |
@@ -71,13 +73,15 @@ discard block |
||
| 71 | 73 | */ |
| 72 | 74 | private function compare(mixed $item, string $key, string $comparison, mixed $value): bool |
| 73 | 75 | { |
| 74 | - if ($this->compareNullValues($item, $key, $comparison, $value)) { |
|
| 76 | + if ($this->compareNullValues($item, $key, $comparison, $value)) |
|
| 77 | + { |
|
| 75 | 78 | return true; |
| 76 | 79 | } |
| 77 | 80 | |
| 78 | 81 | $lhsValue = __::get($item, $key); |
| 79 | 82 | |
| 80 | - if ($lhsValue === null) { |
|
| 83 | + if ($lhsValue === null) |
|
| 84 | + { |
|
| 81 | 85 | return false; |
| 82 | 86 | } |
| 83 | 87 | |
@@ -94,15 +98,19 @@ discard block |
||
| 94 | 98 | */ |
| 95 | 99 | private function compareNullValues($item, $key, $operator, mixed $value): bool |
| 96 | 100 | { |
| 97 | - if ($operator !== '==' && $operator !== '!=') { |
|
| 101 | + if ($operator !== '==' && $operator !== '!=') |
|
| 102 | + { |
|
| 98 | 103 | return false; |
| 99 | 104 | } |
| 100 | 105 | |
| 101 | - if (!__::has($item, $key)) { |
|
| 102 | - if ($operator === '==' && $value === null) { |
|
| 106 | + if (!__::has($item, $key)) |
|
| 107 | + { |
|
| 108 | + if ($operator === '==' && $value === null) |
|
| 109 | + { |
|
| 103 | 110 | return true; |
| 104 | 111 | } |
| 105 | - if ($operator === '!=' && $value !== null) { |
|
| 112 | + if ($operator === '!=' && $value !== null) |
|
| 113 | + { |
|
| 106 | 114 | return true; |
| 107 | 115 | } |
| 108 | 116 | } |
@@ -138,7 +146,8 @@ discard block |
||
| 138 | 146 | |
| 139 | 147 | private function containsCaseInsensitive($haystack, $needle): bool |
| 140 | 148 | { |
| 141 | - if (is_array($haystack)) { |
|
| 149 | + if (is_array($haystack)) |
|
| 150 | + { |
|
| 142 | 151 | $downCase = array_combine(array_map('strtolower', $haystack), $haystack); |
| 143 | 152 | |
| 144 | 153 | return isset($downCase[strtolower((string)$needle)]); |
@@ -25,7 +25,8 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function __invoke($html, $id = null, $class = null, $hMin = 1, $hMax = 6): string |
| 27 | 27 | { |
| 28 | - if (!function_exists('simplexml_load_string')) { |
|
| 28 | + if (!function_exists('simplexml_load_string')) |
|
| 29 | + { |
|
| 29 | 30 | trigger_error('XML support is not available with the current PHP installation.', E_USER_WARNING); |
| 30 | 31 | |
| 31 | 32 | return ''; |
@@ -38,24 +39,35 @@ discard block |
||
| 38 | 39 | $curr = $last = 0; |
| 39 | 40 | |
| 40 | 41 | /** @var DOMElement $heading */ |
| 41 | - foreach ($headings as $index => $heading) { |
|
| 42 | - if ($heading->attributes->getNamedItem('id') === null) { |
|
| 42 | + foreach ($headings as $index => $heading) |
|
| 43 | + { |
|
| 44 | + if ($heading->attributes->getNamedItem('id') === null) |
|
| 45 | + { |
|
| 43 | 46 | continue; |
| 44 | 47 | } |
| 45 | 48 | |
| 46 | 49 | sscanf($heading->tagName, 'h%u', $curr); |
| 47 | 50 | |
| 48 | - if (!($hMin <= $curr && $curr <= $hMax)) { |
|
| 51 | + if (!($hMin <= $curr && $curr <= $hMax)) |
|
| 52 | + { |
|
| 49 | 53 | continue; |
| 50 | 54 | } |
| 51 | 55 | |
| 52 | 56 | $headingID = $heading->attributes->getNamedItem('id'); |
| 53 | 57 | |
| 54 | - if ($curr > $last) { // If the current level is greater than the last level indent one level |
|
| 58 | + if ($curr > $last) |
|
| 59 | + { |
|
| 60 | +// If the current level is greater than the last level indent one level |
|
| 55 | 61 | $toc .= '<ul>'; |
| 56 | - } elseif ($curr < $last) { // If the current level is less than the last level go up appropriate amount. |
|
| 62 | + } |
|
| 63 | + elseif ($curr < $last) |
|
| 64 | + { |
|
| 65 | +// If the current level is less than the last level go up appropriate amount. |
|
| 57 | 66 | $toc .= str_repeat('</li></ul>', $last - $curr) . '</li>'; |
| 58 | - } else { // If the current level is equal to the last. |
|
| 67 | + } |
|
| 68 | + else |
|
| 69 | + { |
|
| 70 | +// If the current level is equal to the last. |
|
| 59 | 71 | $toc .= '</li>'; |
| 60 | 72 | } |
| 61 | 73 | |
@@ -65,14 +77,17 @@ discard block |
||
| 65 | 77 | |
| 66 | 78 | $toc .= str_repeat('</li></ul>', $last - ($hMin - 1)); |
| 67 | 79 | |
| 68 | - if ($id !== null || $class !== null) { |
|
| 80 | + if ($id !== null || $class !== null) |
|
| 81 | + { |
|
| 69 | 82 | $attributes = []; |
| 70 | 83 | |
| 71 | - if ($id !== null) { |
|
| 84 | + if ($id !== null) |
|
| 85 | + { |
|
| 72 | 86 | $attributes[] = sprintf('id="%s"', $id); |
| 73 | 87 | } |
| 74 | 88 | |
| 75 | - if ($class !== null) { |
|
| 89 | + if ($class !== null) |
|
| 90 | + { |
|
| 76 | 91 | $attributes[] = sprintf('class="%s"', $class); |
| 77 | 92 | } |
| 78 | 93 | |
@@ -54,9 +54,12 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function createTemplate($templateContent): TemplateInterface |
| 56 | 56 | { |
| 57 | - try { |
|
| 57 | + try |
|
| 58 | + { |
|
| 58 | 59 | $template = $this->twig->createTemplate($templateContent); |
| 59 | - } catch (Error $e) { |
|
| 60 | + } |
|
| 61 | + catch (Error $e) |
|
| 62 | + { |
|
| 60 | 63 | throw new TwigError($e); |
| 61 | 64 | } |
| 62 | 65 | |
@@ -89,7 +92,8 @@ discard block |
||
| 89 | 92 | |
| 90 | 93 | preg_match_all($regex, $bodyContent, $results); |
| 91 | 94 | |
| 92 | - if (empty($results[1])) { |
|
| 95 | + if (empty($results[1])) |
|
| 96 | + { |
|
| 93 | 97 | return []; |
| 94 | 98 | } |
| 95 | 99 | |
@@ -32,10 +32,14 @@ discard block |
||
| 32 | 32 | $theme = $configuration->getTheme(); |
| 33 | 33 | |
| 34 | 34 | // Only load a theme if one is specified and actually exists |
| 35 | - if ($theme !== null) { |
|
| 36 | - try { |
|
| 35 | + if ($theme !== null) |
|
| 36 | + { |
|
| 37 | + try |
|
| 38 | + { |
|
| 37 | 39 | $loader->addPath(fs::absolutePath('_themes', $theme), 'theme'); |
| 38 | - } catch (LoaderError $e) { |
|
| 40 | + } |
|
| 41 | + catch (LoaderError $e) |
|
| 42 | + { |
|
| 39 | 43 | $logger->error('The following theme could not be loaded: {theme}', [ |
| 40 | 44 | 'theme' => $theme, |
| 41 | 45 | ]); |
@@ -53,12 +57,14 @@ discard block |
||
| 53 | 57 | |
| 54 | 58 | $profiler = null; |
| 55 | 59 | |
| 56 | - if (Service::hasRunTimeFlag(RuntimeStatus::IN_PROFILE_MODE)) { |
|
| 60 | + if (Service::hasRunTimeFlag(RuntimeStatus::IN_PROFILE_MODE)) |
|
| 61 | + { |
|
| 57 | 62 | $profiler = new Profile(); |
| 58 | 63 | $twig->addExtension(new ProfilerExtension($profiler)); |
| 59 | 64 | } |
| 60 | 65 | |
| 61 | - if ($configuration->isDebug()) { |
|
| 66 | + if ($configuration->isDebug()) |
|
| 67 | + { |
|
| 62 | 68 | $twig->addExtension(new DebugExtension()); |
| 63 | 69 | $twig->enableDebug(); |
| 64 | 70 | } |