diff options
| author | Greg Roach <fisharebest@webtrees.net> | 2019-03-04 11:48:20 +0000 |
|---|---|---|
| committer | Greg Roach <fisharebest@webtrees.net> | 2019-03-04 14:06:41 +0000 |
| commit | d7952a34bc82db471ebc960cb25a37234ddd3514 (patch) | |
| tree | 0bf9dcf558ded0b6a9d65143d5d0d759c0f3e75c | |
| parent | 786e5f36299f8d8f04785e145e537138736c6fa0 (diff) | |
| download | webtrees-d7952a34bc82db471ebc960cb25a37234ddd3514.tar.gz webtrees-d7952a34bc82db471ebc960cb25a37234ddd3514.tar.bz2 webtrees-d7952a34bc82db471ebc960cb25a37234ddd3514.zip | |
Unique stacks should be an opt-in feature
| -rw-r--r-- | app/View.php | 39 | ||||
| -rw-r--r-- | resources/views/statistics/other/chart-setup.phtml | 4 |
2 files changed, 38 insertions, 5 deletions
diff --git a/app/View.php b/app/View.php index 7dcc6554f0..58952708ec 100644 --- a/app/View.php +++ b/app/View.php @@ -18,8 +18,15 @@ declare(strict_types=1); namespace Fisharebest\Webtrees; use Exception; -use function ob_end_clean; use Throwable; +use function array_filter; +use function extract; +use function implode; +use function is_dir; +use function is_file; +use function ob_end_clean; +use function ob_start; +use function sha1; /** * Simple view/template class. @@ -94,6 +101,7 @@ class View public static function push(string $stack) { self::$stack = $stack; + ob_start(); } @@ -105,9 +113,34 @@ class View public static function endpush() { $content = ob_get_clean(); - $hash = sha1($content); - self::$stacks[self::$stack][$hash] = $content; + self::$stacks[self::$stack][] = $content; + } + + /** + * Variant of push that will only add one copy of each item. + * + * @param string $stack + * + * @return void + */ + public static function pushunique(string $stack) + { + self::$stack = $stack; + + ob_start(); + } + + /** + * Variant of push that will only add one copy of each item. + * + * @return void + */ + public static function endpushunique() + { + $content = ob_get_clean(); + + self::$stacks[self::$stack][sha1($content)] = $content; } /** diff --git a/resources/views/statistics/other/chart-setup.phtml b/resources/views/statistics/other/chart-setup.phtml index 694fc2da9e..10cc361b89 100644 --- a/resources/views/statistics/other/chart-setup.phtml +++ b/resources/views/statistics/other/chart-setup.phtml @@ -4,7 +4,7 @@ declare(strict_types=1); use Fisharebest\Webtrees\View; ?> -<?php View::push('javascript') ?> +<?php View::pushunique('javascript') ?> <script src="https://www.gstatic.com/charts/loader.js"></script> <script> @@ -23,4 +23,4 @@ google.charts.load( ); </script> -<?php View::endpush() ?> +<?php View::endpushunique() ?> |
