AbandonedCartContent.php
1 year ago
AutomatedLatestContentBlock.php
3 years ago
Button.php
1 year ago
Coupon.php
3 years ago
Divider.php
2 years ago
DynamicProductsBlock.php
11 months ago
Footer.php
2 months ago
Header.php
2 months ago
Image.php
3 years ago
Placeholder.php
4 years ago
Renderer.php
2 months ago
Social.php
2 months ago
Spacer.php
3 years ago
Text.php
2 months ago
index.php
3 years ago
Social.php
50 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Newsletter\Renderer\Blocks; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper; |
| 9 | |
| 10 | class Social { |
| 11 | public function render($element) { |
| 12 | $iconsBlock = ''; |
| 13 | if (is_array($element['icons'])) { |
| 14 | foreach ($element['icons'] as $index => $icon) { |
| 15 | if (!is_array($icon) || empty($icon['image'])) { |
| 16 | continue; |
| 17 | } |
| 18 | |
| 19 | // Width/height typically arrive as CSS strings like "32px"; PHP's lenient string-to-int strips the unit. |
| 20 | $widthRaw = is_scalar($icon['width'] ?? null) ? (string)$icon['width'] : ''; |
| 21 | $heightRaw = is_scalar($icon['height'] ?? null) ? (string)$icon['height'] : ''; |
| 22 | $width = (int)$widthRaw; |
| 23 | $height = (int)$heightRaw; |
| 24 | $link = is_string($icon['link'] ?? null) ? $icon['link'] : ''; |
| 25 | $image = is_string($icon['image']) ? $icon['image'] : ''; |
| 26 | $iconType = is_string($icon['iconType'] ?? null) ? $icon['iconType'] : ''; |
| 27 | $style = 'width:' . $widthRaw . ';height:' . $heightRaw . ';-ms-interpolation-mode:bicubic;border:0;display:inline;outline:none;'; |
| 28 | $iconsBlock .= '<a href="' . EHelper::escapeHtmlLinkAttr($link) . '" style="text-decoration:none!important;" |
| 29 | ><img |
| 30 | src="' . EHelper::escapeHtmlLinkAttr($image) . '" |
| 31 | width="' . $width . '" |
| 32 | height="' . $height . '" |
| 33 | style="' . EHelper::escapeHtmlStyleAttr($style) . '" |
| 34 | alt="' . EHelper::escapeHtmlAttr($iconType) . '" |
| 35 | ></a> '; |
| 36 | } |
| 37 | } |
| 38 | $alignment = isset($element['styles']['block']['textAlign']) ? $element['styles']['block']['textAlign'] : 'center'; |
| 39 | if (!empty($iconsBlock)) { |
| 40 | $template = ' |
| 41 | <tr> |
| 42 | <td class="mailpoet_padded_side mailpoet_padded_vertical" valign="top" align="' . EHelper::escapeHtmlAttr($alignment) . '"> |
| 43 | ' . $iconsBlock . ' |
| 44 | </td> |
| 45 | </tr>'; |
| 46 | return $template; |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 |