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