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
Button.php
96 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 | use MailPoet\Newsletter\Renderer\StylesHelper; |
| 10 | |
| 11 | class Button { |
| 12 | public function render($element, $columnBaseWidth) { |
| 13 | $originalWidth = $this->getOriginalWidth($element, $columnBaseWidth); |
| 14 | $element['styles']['block']['width'] = $this->calculateWidth($element, $columnBaseWidth); |
| 15 | $styles = 'display:block;text-decoration:none;text-align:center;' . StylesHelper::getBlockStyles($element, $exclude = ['textAlign']); |
| 16 | $styles = EHelper::escapeHtmlStyleAttr($styles); |
| 17 | $template = ' |
| 18 | <tr> |
| 19 | <td class="mailpoet_padded_vertical mailpoet_padded_side" valign="top"> |
| 20 | <div> |
| 21 | <table width="100%" cellpadding="0" cellspacing="0" border="0" style="border-spacing:0;mso-table-lspace:0;mso-table-rspace:0;"> |
| 22 | <tr> |
| 23 | <td class="mailpoet_button-container" style="text-align:' . $element['styles']['block']['textAlign'] . ';"><!--[if mso]> |
| 24 | <v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" |
| 25 | href="' . EHelper::escapeHtmlLinkAttr($element['url']) . '" |
| 26 | style="height:' . EHelper::escapeHtmlStyleAttr($element['styles']['block']['lineHeight']) . '; |
| 27 | width:' . EHelper::escapeHtmlStyleAttr($element['styles']['block']['width']) . '; |
| 28 | v-text-anchor:middle;" |
| 29 | arcsize="' . round((int)$element['styles']['block']['borderRadius'] / ((int)$element['styles']['block']['lineHeight'] ?: 1) * 100) . '%" |
| 30 | strokeweight="' . EHelper::escapeHtmlAttr($element['styles']['block']['borderWidth']) . '" |
| 31 | strokecolor="' . EHelper::escapeHtmlAttr($element['styles']['block']['borderColor']) . '" |
| 32 | fillcolor="' . EHelper::escapeHtmlAttr($element['styles']['block']['backgroundColor']) . '"> |
| 33 | <w:anchorlock/> |
| 34 | <center style="color:' . EHelper::escapeHtmlStyleAttr($element['styles']['block']['fontColor']) . '; |
| 35 | font-family:' . EHelper::escapeHtmlStyleAttr($element['styles']['block']['fontFamily']) . '; |
| 36 | font-size:' . EHelper::escapeHtmlStyleAttr($element['styles']['block']['fontSize']) . '; |
| 37 | font-weight:bold;">' . EHelper::escapeHtmlText($element['text']) . ' |
| 38 | </center> |
| 39 | </v:roundrect> |
| 40 | <![endif]--> |
| 41 | <!--[if !mso]><!-- --> |
| 42 | <table |
| 43 | border="0" |
| 44 | cellspacing="0" |
| 45 | cellpadding="0" |
| 46 | role="presentation" |
| 47 | style="display:inline-block;border-collapse:separate;mso-table-lspace:0;mso-table-rspace:0;width:' . EHelper::escapeHtmlStyleAttr($originalWidth) . '" |
| 48 | width="' . EHelper::escapeHtmlStyleAttr($originalWidth) . '" |
| 49 | > |
| 50 | <tr> |
| 51 | <td class="mailpoet_table_button" |
| 52 | valign="middle" |
| 53 | role="presentation" |
| 54 | style="mso-table-lspace: 0;mso-table-rspace: 0;' . $styles . '" |
| 55 | > |
| 56 | <a class="mailpoet_button" style=" |
| 57 | text-decoration: none; |
| 58 | display: block; |
| 59 | line-height: ' . EHelper::escapeHtmlStyleAttr($element['styles']['block']['lineHeight']) . '; |
| 60 | color: ' . EHelper::escapeHtmlStyleAttr($element['styles']['block']['fontColor']) . '; |
| 61 | " href="' . EHelper::escapeHtmlLinkAttr($element['url']) . '" target="_blank">' . EHelper::escapeHtmlText($element['text']) . '</a> |
| 62 | </td> |
| 63 | </tr> |
| 64 | </table> |
| 65 | <!--<![endif]--> |
| 66 | </td> |
| 67 | </tr> |
| 68 | </table> |
| 69 | </div> |
| 70 | </td> |
| 71 | </tr>'; |
| 72 | return $template; |
| 73 | } |
| 74 | |
| 75 | public function getOriginalWidth($element, $columnBaseWidth): string { |
| 76 | $columnWidth = $columnBaseWidth - (StylesHelper::$paddingWidth * 2); |
| 77 | $originalWidth = (int)$element['styles']['block']['width']; |
| 78 | $originalWidth = ($originalWidth > $columnWidth) ? |
| 79 | $columnWidth : |
| 80 | $originalWidth; |
| 81 | |
| 82 | return $originalWidth . 'px'; |
| 83 | } |
| 84 | |
| 85 | public function calculateWidth($element, $columnBaseWidth): string { |
| 86 | $columnWidth = $columnBaseWidth - (StylesHelper::$paddingWidth * 2); |
| 87 | $borderWidth = (int)$element['styles']['block']['borderWidth']; |
| 88 | $buttonWidth = (int)$element['styles']['block']['width']; |
| 89 | $buttonWidth = ($buttonWidth > $columnWidth) ? |
| 90 | $columnWidth : |
| 91 | $buttonWidth; |
| 92 | $buttonWidth = $buttonWidth - (2 * $borderWidth) . 'px'; |
| 93 | return $buttonWidth; |
| 94 | } |
| 95 | } |
| 96 |