| 1 |
<?php |
| 2 |
|
| 3 |
namespace Photonic_Plugin\Components; |
| 4 |
|
| 5 |
use Photonic_Plugin\Core\Photonic; |
| 6 |
use Photonic_Plugin\Layouts\Core_Layout; |
| 7 |
use Photonic_Plugin\Platforms\Base; |
| 8 |
|
| 9 |
class Collection implements Printable { |
| 10 |
/** |
| 11 |
* @var Header|null $header |
| 12 |
*/ |
| 13 |
public ?Header $header = null; |
| 14 |
|
| 15 |
/** |
| 16 |
* @var Album_List|null $album_list |
| 17 |
*/ |
| 18 |
public ?Album_List $album_list = null; |
| 19 |
|
| 20 |
/** |
| 21 |
* @var array |
| 22 |
*/ |
| 23 |
public array $collections = []; |
| 24 |
|
| 25 |
public string $indent = ''; |
| 26 |
public bool $strip_top_level = false; // Specifically for Flickr, when you do lazy loading |
| 27 |
|
| 28 |
/** |
| 29 |
* {@inheritDoc} - a Collection |
| 30 |
*/ |
| 31 |
public function html(Base $module, Core_Layout $layout, $print = false): string { |
| 32 |
$start = empty($this->strip_top_level) ? $this->indent . "<div class='photonic-tree'>\n" : ''; |
| 33 |
$out = $start; |
| 34 |
|
| 35 |
if (!empty($this->header)) { |
| 36 |
$out .= $this->header->html($module, $layout); |
| 37 |
} |
| 38 |
|
| 39 |
if (!empty($this->album_list)) { |
| 40 |
$out .= $this->album_list->html($module, $layout); |
| 41 |
} |
| 42 |
|
| 43 |
if (!empty($this->collections)) { |
| 44 |
/** @var Printable|string $collection */ |
| 45 |
foreach ($this->collections as $collection) { |
| 46 |
if (is_a($collection, 'Photonic_Plugin\Components\Printable')) { |
| 47 |
$out .= $collection->html($module, $layout); |
| 48 |
} |
| 49 |
else { |
| 50 |
$out .= $collection; |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
if ($out !== $start && !$this->strip_top_level) { |
| 56 |
$out .= $this->indent . "</div>\n"; |
| 57 |
} |
| 58 |
|
| 59 |
if ($print) { |
| 60 |
echo wp_kses($out, Photonic::$safe_tags); |
| 61 |
} |
| 62 |
return wp_kses($out, Photonic::$safe_tags); |
| 63 |
} |
| 64 |
} |
| 65 |
|