| 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 |
require_once 'Grid_Anchor.php'; |
| 10 |
|
| 11 |
class Grid_Figure implements Printable { |
| 12 |
public string $id = ''; |
| 13 |
public array $classes = []; |
| 14 |
public array $data = []; |
| 15 |
public array $styles = []; |
| 16 |
public string $video_markup = ''; |
| 17 |
public string $prompter_markup = ''; |
| 18 |
public string $indent = ''; |
| 19 |
|
| 20 |
/** |
| 21 |
* @var Grid_Anchor $anchor |
| 22 |
*/ |
| 23 |
public Grid_Anchor $anchor; |
| 24 |
|
| 25 |
public function html(Base $module, Core_Layout $layout, bool $print = false): string { |
| 26 |
$classes = esc_attr(implode(' ', $this->classes)); |
| 27 |
$style = ''; |
| 28 |
if (!empty($this->styles)) { |
| 29 |
$styles = array_map( |
| 30 |
function (string $key, string $value): string { |
| 31 |
return $key . ': ' . $value; |
| 32 |
}, |
| 33 |
array_keys($this->styles), |
| 34 |
array_values($this->styles) |
| 35 |
); |
| 36 |
|
| 37 |
$style = "style='" . implode('; ', $styles) . "'"; |
| 38 |
} |
| 39 |
|
| 40 |
$data_pieces = array_map( |
| 41 |
function (string $key, string $value): string { |
| 42 |
return $key . '="' . $value . '"'; |
| 43 |
}, |
| 44 |
array_keys($this->data), |
| 45 |
array_values($this->data) |
| 46 |
); |
| 47 |
$data_attributes = implode(' ', $data_pieces); |
| 48 |
|
| 49 |
$id = ''; |
| 50 |
if (!empty($this->id)) { |
| 51 |
$id = "id='" . esc_attr($this->id) . "'"; |
| 52 |
} |
| 53 |
|
| 54 |
$ret = "{$this->indent}\t<figure class='$classes' $id $style $data_attributes>\n"; |
| 55 |
$ret .= $this->video_markup; |
| 56 |
$ret .= $this->anchor->html($module, $layout); |
| 57 |
$ret .= $this->prompter_markup; |
| 58 |
$ret .= $this->indent . "\t</figure>\n"; |
| 59 |
if ($print) { |
| 60 |
echo wp_kses($ret, Photonic::$safe_tags); |
| 61 |
} |
| 62 |
return wp_kses($ret, Photonic::$safe_tags); |
| 63 |
} |
| 64 |
} |
| 65 |
|