| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +defined('ABSPATH') || die('Restricted Access'); | |
| 4 | + | |
| 3 | 5 | function acym_cmsModal( |
| 4 | 6 | bool $isIframe, |
| 5 | 7 | string $content, |
| 6 | 8 | string $buttonText, |
| @@ -9,21 +11,24 @@ | ||
| 9 | 11 | ?string $identifier = null, |
| 10 | 12 | int $width = 800, |
| 11 | 13 | int $height = 400 |
| 12 | 14 | ): string { |
| 15 | + // Use the WP's thickbox library | |
| 13 | 16 | add_thickbox(); |
| 14 | 17 | |
| 15 | 18 | $class = $isButton ? ' button' : ''; |
| 16 | 19 | |
| 17 | 20 | if ($isIframe) { |
| 18 | - return '<a href="'.$content.'&TB_iframe=true&width='.$width.'&height='.$height.'" class="thickbox'.$class.'">'.acym_translation($buttonText).'</a>'; | |
| 21 | + return '<a href="'.$content.'&TB_iframe=true&width='.$width.'&height='.$height.'" class="thickbox'.esc_attr($class).'">'.esc_html(acym_translation($buttonText)).'</a>'; | |
| 19 | 22 | } else { |
| 20 | 23 | if (empty($identifier)) { |
| 21 | - $identifier = 'identifier_'.rand(1000, 9000); | |
| 24 | + $identifier = 'identifier_'.acym_rand(1000, 9000); | |
| 22 | 25 | } |
| 23 | 26 | |
| 24 | - return '<div id="'.$identifier.'" style="display:none;">'.$content.'</div> | |
| 25 | - <a href="#TB_inline?width='.$width.'&height='.$height.'&inlineId='.$identifier.'" class="thickbox'.$class.'">'.acym_translation($buttonText).'</a>'; | |
| 27 | + return '<div id="'.esc_attr($identifier).'" style="display:none;">'.$content.'</div> | |
| 28 | + <a href="#TB_inline?width='.$width.'&height='.$height.'&inlineId='.esc_attr($identifier).'" class="thickbox'.esc_attr($class).'">'.esc_html( | |
| 29 | + acym_translation($buttonText) | |
| 30 | + ).'</a>'; | |
| 26 | 31 | } |
| 27 | 32 | } |
| 28 | 33 | |
| 29 | 34 | function acym_CMSArticleTitle(int $id): string |
| @@ -44,9 +49,11 @@ | ||
| 44 | 49 | if ($popup) { |
| 45 | 50 | $url .= (strpos($url, '?') ? '&' : '?').acym_noTemplate(); |
| 46 | 51 | $url = acym_frontModal($url, $text, false); |
| 47 | 52 | } else { |
| 48 | - $url = '<a title="'.acym_translation($text, true).'" href="'.acym_escape($url).'" target="_blank">'.acym_translation($text).'</a>'; | |
| 53 | + $url = '<a title="'.acym_translation($text, true).'" href="'.esc_attr($url).'" target="_blank" rel="noopener noreferrer" aria-label="'.esc_attr( | |
| 54 | + acym_translation($text).', '.acym_translation('ACYM_OPENS_NEW_WINDOW') | |
| 55 | + ).'">'.acym_translation($text).'</a>'; | |
| 49 | 56 | } |
| 50 | 57 | |
| 51 | 58 | return $url; |
| 52 | 59 | } |
| @@ -64,8 +71,9 @@ | ||
| 64 | 71 | function acym_cmsCleanHtml(string $html): string |
| 65 | 72 | { |
| 66 | 73 | if (strpos($html, '<!-- wp:') === false) return $html; |
| 67 | 74 | |
| 75 | + // Replace special WP content in inserted posts and pages | |
| 68 | 76 | $elementsToRemove = [ |
| 69 | 77 | 'shortcode', |
| 70 | 78 | 'core-embed/.*', |
| 71 | 79 | 'video .*', |
| @@ -86,9 +94,11 @@ | ||
| 86 | 94 | |
| 87 | 95 | $cleanText = preg_replace(array_keys($replacements), $replacements, $html); |
| 88 | 96 | if (!empty($cleanText)) $html = $cleanText; |
| 89 | 97 | |
| 98 | + // Display the WP content correctly | |
| 90 | 99 | $html .= '<style type="text/css"> |
| 100 | + /* Handle media-text blocks */ | |
| 91 | 101 | .wp-block-media-text { |
| 92 | 102 | display: grid; |
| 93 | 103 | grid-template-rows: auto; |
| 94 | 104 | align-items: center; |
| @@ -104,8 +114,9 @@ | ||
| 104 | 114 | grid-area: media-text-content; |
| 105 | 115 | padding: 0 8%; |
| 106 | 116 | } |
| 107 | 117 | |
| 118 | + /* Handle multi column blocks */ | |
| 108 | 119 | .wp-block-columns { |
| 109 | 120 | display: flex !important; |
| 110 | 121 | flex-wrap: nowrap; |
| 111 | 122 | } |
| @@ -113,20 +124,24 @@ | ||
| 113 | 124 | flex-basis: 100%; |
| 114 | 125 | flex-grow: 0; |
| 115 | 126 | } |
| 116 | 127 | |
| 128 | + /* Handle WP tables */ | |
| 117 | 129 | table.wp-block-table td { |
| 118 | 130 | padding: 1em 1.41575em !important; |
| 119 | 131 | } |
| 120 | 132 | |
| 133 | + /* Handle preformatted content */ | |
| 121 | 134 | .wp-block-preformatted, .wp-block-code, .wp-block-verse { |
| 122 | 135 | padding: 1.618em; |
| 123 | 136 | } |
| 124 | 137 | |
| 138 | + /* Handle download files */ | |
| 125 | 139 | .wp-block-file { |
| 126 | 140 | margin: 20px 0; |
| 127 | 141 | } |
| 128 | 142 | |
| 143 | + /* Handle cover blocks */ | |
| 129 | 144 | .wp-block-cover, .wp-block-cover-image { |
| 130 | 145 | -webkit-box-orient: horizontal; |
| 131 | 146 | -webkit-box-direction: normal; |
| 132 | 147 | -webkit-flex-flow: row wrap; |
| @@ -162,8 +177,9 @@ | ||
| 162 | 177 | color: #fff !important; |
| 163 | 178 | z-index: 1; |
| 164 | 179 | } |
| 165 | 180 | |
| 181 | + /* Handle galleries */ | |
| 166 | 182 | .wp-block-gallery { |
| 167 | 183 | margin: 0 0 1.41575em; |
| 168 | 184 | display: flex; |
| 169 | 185 | flex-wrap: wrap; |