| @@ -1,0 +1,251 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 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 | |
| 16 | + add_thickbox(); | |
| 17 | + | |
| 18 | + $class = $isButton ? ' button' : ''; | |
| 19 | + | |
| 20 | + if ($isIframe) { | |
| 21 | + return '<a href="'.$content.'&TB_iframe=true&width='.$width.'&height='.$height.'" class="thickbox'.esc_attr($class).'">'.esc_html(acym_translation($buttonText)).'</a>'; | |
| 22 | + } else { | |
| 23 | + if (empty($identifier)) { | |
| 24 | + $identifier = 'identifier_'.acym_rand(1000, 9000); | |
| 25 | + } | |
| 26 | + | |
| 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>'; | |
| 31 | + } | |
| 32 | +} | |
| 33 | + | |
| 34 | +function acym_CMSArticleTitle(int $id): string | |
| 35 | +{ | |
| 36 | + $title = acym_loadResult('SELECT post_title FROM #__posts WHERE ID = '.intval($id)); | |
| 37 | + | |
| 38 | + return empty($title) ? '' : $title; | |
| 39 | +} | |
| 40 | + | |
| 41 | +function acym_getArticleURL(int $id, bool $popup, string $text): string | |
| 42 | +{ | |
| 43 | + if (empty($id)) { | |
| 44 | + return ''; | |
| 45 | + } | |
| 46 | + | |
| 47 | + $url = get_permalink($id); | |
| 48 | + | |
| 49 | + if ($popup) { | |
| 50 | + $url .= (strpos($url, '?') ? '&' : '?').acym_noTemplate(); | |
| 51 | + $url = acym_frontModal($url, $text, false); | |
| 52 | + } else { | |
| 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>'; | |
| 56 | + } | |
| 57 | + | |
| 58 | + return $url; | |
| 59 | +} | |
| 60 | + | |
| 61 | +function acym_articleSelectionPage(): string | |
| 62 | +{ | |
| 63 | + return admin_url('admin-ajax.php').'?action=acymailing_router&page=acymailing_configuration&ctrl=configuration&task=getarticles&'.acym_getFormToken(); | |
| 64 | +} | |
| 65 | + | |
| 66 | +function acym_getPageOverride(string $ctrl, string $view, bool $forceBackend = false): string | |
| 67 | +{ | |
| 68 | + return ACYM_OVERRIDES.$ctrl.DS.$view.'.php'; | |
| 69 | +} | |
| 70 | + | |
| 71 | +function acym_cmsCleanHtml(string $html): string | |
| 72 | +{ | |
| 73 | + if (strpos($html, '<!-- wp:') === false) return $html; | |
| 74 | + | |
| 75 | + // Replace special WP content in inserted posts and pages | |
| 76 | + $elementsToRemove = [ | |
| 77 | + 'shortcode', | |
| 78 | + 'core-embed/.*', | |
| 79 | + 'video .*', | |
| 80 | + 'audio .*', | |
| 81 | + ]; | |
| 82 | + | |
| 83 | + $replacements = [ | |
| 84 | + '#<!-- wp:core-embed/vimeo.*"url":"([^"]+)".+<!-- /wp:core-embed/vimeo -->#Uis' => '{vimeo}$1{/vimeo}', | |
| 85 | + '#<!-- wp:core-embed/youtube.*"url":"([^"]+)".+<!-- /wp:core-embed/youtube -->#Uis' => '{youtube}$1{/youtube}', | |
| 86 | + '#<!-- wp:embed .*"url":"([^"]+)".+"providerNameSlug":"vimeo".+<!-- /wp:embed -->#Uis' => '{vimeo}$1{/vimeo}', | |
| 87 | + '#<!-- wp:embed .*"url":"([^"]+)".+"providerNameSlug":"youtube".+<!-- /wp:embed -->#Uis' => '{youtube}$1{/youtube}', | |
| 88 | + '#<a [^>]*wp-block-file__button[^>]*>[^<]*</a>#Uis' => '', | |
| 89 | + ]; | |
| 90 | + | |
| 91 | + foreach ($elementsToRemove as $oneElement) { | |
| 92 | + $replacements['#<!-- wp:'.$oneElement.' -->.*<!-- /wp:'.$oneElement.' -->#Uis'] = ''; | |
| 93 | + } | |
| 94 | + | |
| 95 | + $cleanText = preg_replace(array_keys($replacements), $replacements, $html); | |
| 96 | + if (!empty($cleanText)) $html = $cleanText; | |
| 97 | + | |
| 98 | + // Display the WP content correctly | |
| 99 | + $html .= '<style type="text/css"> | |
| 100 | + /* Handle media-text blocks */ | |
| 101 | + .wp-block-media-text { | |
| 102 | + display: grid; | |
| 103 | + grid-template-rows: auto; | |
| 104 | + align-items: center; | |
| 105 | + grid-template-areas: "media-text-media media-text-content"; | |
| 106 | + grid-template-columns: 50% auto; | |
| 107 | + } | |
| 108 | + .wp-block-media-text .wp-block-media-text__media { | |
| 109 | + grid-area: media-text-media; | |
| 110 | + margin: 0; | |
| 111 | + } | |
| 112 | + .wp-block-media-text .wp-block-media-text__content { | |
| 113 | + word-break: break-word; | |
| 114 | + grid-area: media-text-content; | |
| 115 | + padding: 0 8%; | |
| 116 | + } | |
| 117 | + | |
| 118 | + /* Handle multi column blocks */ | |
| 119 | + .wp-block-columns { | |
| 120 | + display: flex !important; | |
| 121 | + flex-wrap: nowrap; | |
| 122 | + } | |
| 123 | + .wp-block-columns .wp-block-column { | |
| 124 | + flex-basis: 100%; | |
| 125 | + flex-grow: 0; | |
| 126 | + } | |
| 127 | + | |
| 128 | + /* Handle WP tables */ | |
| 129 | + table.wp-block-table td { | |
| 130 | + padding: 1em 1.41575em !important; | |
| 131 | + } | |
| 132 | + | |
| 133 | + /* Handle preformatted content */ | |
| 134 | + .wp-block-preformatted, .wp-block-code, .wp-block-verse { | |
| 135 | + padding: 1.618em; | |
| 136 | + } | |
| 137 | + | |
| 138 | + /* Handle download files */ | |
| 139 | + .wp-block-file { | |
| 140 | + margin: 20px 0; | |
| 141 | + } | |
| 142 | + | |
| 143 | + /* Handle cover blocks */ | |
| 144 | + .wp-block-cover, .wp-block-cover-image { | |
| 145 | + -webkit-box-orient: horizontal; | |
| 146 | + -webkit-box-direction: normal; | |
| 147 | + -webkit-flex-flow: row wrap; | |
| 148 | + flex-flow: row wrap; | |
| 149 | + position: relative; | |
| 150 | + background-color: #000; | |
| 151 | + background-size: cover; | |
| 152 | + background-position: 50%; | |
| 153 | + min-height: 430px; | |
| 154 | + width: 100%; | |
| 155 | + margin: 0 0 1.5em; | |
| 156 | + display: flex; | |
| 157 | + justify-content: center; | |
| 158 | + align-items: center; | |
| 159 | + overflow: hidden; | |
| 160 | + } | |
| 161 | + .wp-block-cover-image.has-background-dim:before, .wp-block-cover.has-background-dim:before { | |
| 162 | + content: ""; | |
| 163 | + position: absolute; | |
| 164 | + top: 0; | |
| 165 | + left: 0; | |
| 166 | + bottom: 0; | |
| 167 | + right: 0; | |
| 168 | + background-color: inherit; | |
| 169 | + opacity: .5; | |
| 170 | + z-index: 1; | |
| 171 | + } | |
| 172 | + .wp-block-cover p { | |
| 173 | + font-size: 1.618em; | |
| 174 | + font-weight: 300; | |
| 175 | + line-height: 1.618; | |
| 176 | + padding: 1em; | |
| 177 | + color: #fff !important; | |
| 178 | + z-index: 1; | |
| 179 | + } | |
| 180 | + | |
| 181 | + /* Handle galleries */ | |
| 182 | + .wp-block-gallery { | |
| 183 | + margin: 0 0 1.41575em; | |
| 184 | + display: flex; | |
| 185 | + flex-wrap: wrap; | |
| 186 | + list-style-type: none; | |
| 187 | + padding: 0; | |
| 188 | + } | |
| 189 | + .blocks-gallery-item { | |
| 190 | + margin-left: auto; | |
| 191 | + margin-right: auto; | |
| 192 | + } | |
| 193 | + </style>'; | |
| 194 | + | |
| 195 | + return $html; | |
| 196 | +} | |
| 197 | + | |
| 198 | +function acym_getAlias(string $name): string | |
| 199 | +{ | |
| 200 | + return sanitize_title_with_dashes(remove_accents($name)); | |
| 201 | +} | |
| 202 | + | |
| 203 | +function acym_getAllPages(): array | |
| 204 | +{ | |
| 205 | + $allPges = get_pages(); | |
| 206 | + if (empty($allPges)) return []; | |
| 207 | + | |
| 208 | + $return = []; | |
| 209 | + | |
| 210 | + foreach ($allPges as $page) { | |
| 211 | + $return[$page->ID] = $page->post_title; | |
| 212 | + } | |
| 213 | + | |
| 214 | + return $return; | |
| 215 | +} | |
| 216 | + | |
| 217 | +function acym_getArticles(string $search): array | |
| 218 | +{ | |
| 219 | + $return = []; | |
| 220 | + | |
| 221 | + $search_results = new WP_Query( | |
| 222 | + [ | |
| 223 | + 's' => $search, | |
| 224 | + 'post_status' => 'publish', | |
| 225 | + 'ignore_sticky_posts' => 1, | |
| 226 | + 'post_type' => ['page', 'post'], | |
| 227 | + 'posts_per_page' => 20, | |
| 228 | + ] | |
| 229 | + ); | |
| 230 | + | |
| 231 | + if ($search_results->have_posts()) { | |
| 232 | + while ($search_results->have_posts()) { | |
| 233 | + $search_results->the_post(); | |
| 234 | + $return[] = [$search_results->post->ID, $search_results->post->post_title]; | |
| 235 | + } | |
| 236 | + } | |
| 237 | + | |
| 238 | + return $return; | |
| 239 | +} | |
| 240 | + | |
| 241 | +function acym_getArticleById(int $id): array | |
| 242 | +{ | |
| 243 | + $post = get_post($id); | |
| 244 | + | |
| 245 | + if (empty($post)) return []; | |
| 246 | + | |
| 247 | + return [ | |
| 248 | + 'id' => $post->ID, | |
| 249 | + 'title' => $post->post_title, | |
| 250 | + ]; | |
| 251 | +} | |