| @@ -1,46 +1,65 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -function acym_cmsModal($isIframe, $content, $buttonText, $isButton, $identifier = null, $width = '800', $height = '400') | |
| 4 | -{ | |
| 3 | +defined('ABSPATH') || die('Restricted Access'); | |
| 4 | + | |
| 5 | +function acym_cmsModal( | |
| 6 | + bool $isIframe, | |
| 7 | + string $content, | |
| 8 | + string $buttonText, | |
| 9 | + bool $isButton, | |
| 10 | + string $modalTitle, | |
| 11 | + ?string $identifier = null, | |
| 12 | + int $width = 800, | |
| 13 | + int $height = 400 | |
| 14 | +): string { | |
| 15 | + // Use the WP's thickbox library | |
| 5 | 16 | add_thickbox(); |
| 6 | 17 | |
| 7 | 18 | $class = $isButton ? ' button' : ''; |
| 8 | 19 | |
| 9 | 20 | if ($isIframe) { |
| 10 | - 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>'; | |
| 11 | 22 | } else { |
| 12 | 23 | if (empty($identifier)) { |
| 13 | - $identifier = 'identifier_'.rand(1000, 9000); | |
| 24 | + $identifier = 'identifier_'.acym_rand(1000, 9000); | |
| 14 | 25 | } |
| 15 | 26 | |
| 16 | - return '<div id="'.$identifier.'" style="display:none;">'.$content.'</div> | |
| 17 | - <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>'; | |
| 18 | 31 | } |
| 19 | 32 | } |
| 20 | 33 | |
| 21 | -function acym_CMSArticleTitle($id) | |
| 34 | +function acym_CMSArticleTitle(int $id): string | |
| 22 | 35 | { |
| 23 | - return acym_loadResult('SELECT post_title FROM #__posts WHERE ID = '.intval($id)); | |
| 36 | + $title = acym_loadResult('SELECT post_title FROM #__posts WHERE ID = '.intval($id)); | |
| 37 | + | |
| 38 | + return empty($title) ? '' : $title; | |
| 24 | 39 | } |
| 25 | 40 | |
| 26 | -function acym_getArticleURL($id, $popup, $text) | |
| 41 | +function acym_getArticleURL(int $id, bool $popup, string $text): string | |
| 27 | 42 | { |
| 28 | - if (empty($id)) return ''; | |
| 43 | + if (empty($id)) { | |
| 44 | + return ''; | |
| 45 | + } | |
| 29 | 46 | |
| 30 | 47 | $url = get_permalink($id); |
| 31 | 48 | |
| 32 | - if ($popup == 1) { | |
| 49 | + if ($popup) { | |
| 33 | 50 | $url .= (strpos($url, '?') ? '&' : '?').acym_noTemplate(); |
| 34 | 51 | $url = acym_frontModal($url, $text, false); |
| 35 | 52 | } else { |
| 36 | - $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>'; | |
| 37 | 56 | } |
| 38 | 57 | |
| 39 | 58 | return $url; |
| 40 | 59 | } |
| 41 | 60 | |
| 42 | -function acym_articleSelectionPage() | |
| 61 | +function acym_articleSelectionPage(): string | |
| 43 | 62 | { |
| 44 | 63 | return admin_url('admin-ajax.php').'?action=acymailing_router&page=acymailing_configuration&ctrl=configuration&task=getarticles&'.acym_getFormToken(); |
| 45 | 64 | } |
| 46 | 65 | |
| @@ -48,12 +67,13 @@ | ||
| 48 | 67 | { |
| 49 | 68 | return ACYM_OVERRIDES.$ctrl.DS.$view.'.php'; |
| 50 | 69 | } |
| 51 | 70 | |
| 52 | -function acym_cmsCleanHtml($html) | |
| 71 | +function acym_cmsCleanHtml(string $html): string | |
| 53 | 72 | { |
| 54 | 73 | if (strpos($html, '<!-- wp:') === false) return $html; |
| 55 | 74 | |
| 75 | + // Replace special WP content in inserted posts and pages | |
| 56 | 76 | $elementsToRemove = [ |
| 57 | 77 | 'shortcode', |
| 58 | 78 | 'core-embed/.*', |
| 59 | 79 | 'video .*', |
| @@ -74,9 +94,11 @@ | ||
| 74 | 94 | |
| 75 | 95 | $cleanText = preg_replace(array_keys($replacements), $replacements, $html); |
| 76 | 96 | if (!empty($cleanText)) $html = $cleanText; |
| 77 | 97 | |
| 98 | + // Display the WP content correctly | |
| 78 | 99 | $html .= '<style type="text/css"> |
| 100 | + /* Handle media-text blocks */ | |
| 79 | 101 | .wp-block-media-text { |
| 80 | 102 | display: grid; |
| 81 | 103 | grid-template-rows: auto; |
| 82 | 104 | align-items: center; |
| @@ -92,8 +114,9 @@ | ||
| 92 | 114 | grid-area: media-text-content; |
| 93 | 115 | padding: 0 8%; |
| 94 | 116 | } |
| 95 | 117 | |
| 118 | + /* Handle multi column blocks */ | |
| 96 | 119 | .wp-block-columns { |
| 97 | 120 | display: flex !important; |
| 98 | 121 | flex-wrap: nowrap; |
| 99 | 122 | } |
| @@ -101,20 +124,24 @@ | ||
| 101 | 124 | flex-basis: 100%; |
| 102 | 125 | flex-grow: 0; |
| 103 | 126 | } |
| 104 | 127 | |
| 128 | + /* Handle WP tables */ | |
| 105 | 129 | table.wp-block-table td { |
| 106 | 130 | padding: 1em 1.41575em !important; |
| 107 | 131 | } |
| 108 | 132 | |
| 133 | + /* Handle preformatted content */ | |
| 109 | 134 | .wp-block-preformatted, .wp-block-code, .wp-block-verse { |
| 110 | 135 | padding: 1.618em; |
| 111 | 136 | } |
| 112 | 137 | |
| 138 | + /* Handle download files */ | |
| 113 | 139 | .wp-block-file { |
| 114 | 140 | margin: 20px 0; |
| 115 | 141 | } |
| 116 | 142 | |
| 143 | + /* Handle cover blocks */ | |
| 117 | 144 | .wp-block-cover, .wp-block-cover-image { |
| 118 | 145 | -webkit-box-orient: horizontal; |
| 119 | 146 | -webkit-box-direction: normal; |
| 120 | 147 | -webkit-flex-flow: row wrap; |
| @@ -150,8 +177,9 @@ | ||
| 150 | 177 | color: #fff !important; |
| 151 | 178 | z-index: 1; |
| 152 | 179 | } |
| 153 | 180 | |
| 181 | + /* Handle galleries */ | |
| 154 | 182 | .wp-block-gallery { |
| 155 | 183 | margin: 0 0 1.41575em; |
| 156 | 184 | display: flex; |
| 157 | 185 | flex-wrap: wrap; |
| @@ -166,14 +194,14 @@ | ||
| 166 | 194 | |
| 167 | 195 | return $html; |
| 168 | 196 | } |
| 169 | 197 | |
| 170 | -function acym_getAlias($name) | |
| 198 | +function acym_getAlias(string $name): string | |
| 171 | 199 | { |
| 172 | 200 | return sanitize_title_with_dashes(remove_accents($name)); |
| 173 | 201 | } |
| 174 | 202 | |
| 175 | -function acym_getAllPages() | |
| 203 | +function acym_getAllPages(): array | |
| 176 | 204 | { |
| 177 | 205 | $allPges = get_pages(); |
| 178 | 206 | if (empty($allPges)) return []; |
| 179 | 207 | |
| @@ -185,9 +213,9 @@ | ||
| 185 | 213 | |
| 186 | 214 | return $return; |
| 187 | 215 | } |
| 188 | 216 | |
| 189 | -function acym_getArticles($search) | |
| 217 | +function acym_getArticles(string $search): array | |
| 190 | 218 | { |
| 191 | 219 | $return = []; |
| 192 | 220 | |
| 193 | 221 | $search_results = new WP_Query( |
| @@ -209,9 +237,9 @@ | ||
| 209 | 237 | |
| 210 | 238 | return $return; |
| 211 | 239 | } |
| 212 | 240 | |
| 213 | -function acym_getArticleById($id) | |
| 241 | +function acym_getArticleById(int $id): array | |
| 214 | 242 | { |
| 215 | 243 | $post = get_post($id); |
| 216 | 244 | |
| 217 | 245 | if (empty($post)) return []; |