TemplateLayouts
11 months ago
AirTable.php
1 year ago
Boomplay.php
1 year ago
Calendly.php
2 years ago
Canva.php
1 year ago
FITE.php
1 year ago
GettyImages.php
11 months ago
Giphy.php
2 years ago
GitHub.php
3 years ago
GoogleDocs.php
2 years ago
GoogleDrive.php
2 years ago
GoogleMaps.php
2 years ago
GooglePhotos.php
11 months ago
Gumroad.php
2 years ago
InstagramFeed.php
11 months ago
LinkedIn.php
2 years ago
Meetup.php
11 months ago
NRKRadio.php
2 years ago
OneDrive.php
1 year ago
OpenSea.php
11 months ago
SelfHosted.php
2 years ago
Spreaker.php
1 year ago
TikTok.php
2 years ago
Twitch.php
2 years ago
Wrapper.php
3 years ago
X.php
2 years ago
Youtube.php
11 months ago
index.html
7 years ago
Meetup.php
302 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Meetup.php |
| 4 | * |
| 5 | * @package Embera |
| 6 | * @author Michael Pratt <yo@michael-pratt.com> |
| 7 | * @link http://www.michael-pratt.com/ |
| 8 | * |
| 9 | * For the full copyright and license information, please view the LICENSE |
| 10 | * file that was distributed with this source code. |
| 11 | */ |
| 12 | |
| 13 | namespace EmbedPress\Providers; |
| 14 | |
| 15 | use Embera\Provider\ProviderAdapter; |
| 16 | use Embera\Provider\ProviderInterface; |
| 17 | use Embera\Url; |
| 18 | |
| 19 | (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed."); |
| 20 | |
| 21 | /** |
| 22 | * Meetup Provider |
| 23 | * @link https://meetup.com |
| 24 | */ |
| 25 | class Meetup extends ProviderAdapter implements ProviderInterface |
| 26 | { |
| 27 | /** inline {@inheritdoc} */ |
| 28 | protected $shouldSendRequest = false; |
| 29 | /** inline {@inheritdoc} */ |
| 30 | protected $endpoint = 'https://api.meetup.com/oembed?format=json'; |
| 31 | |
| 32 | /** inline {@inheritdoc} */ |
| 33 | protected static $hosts = [ |
| 34 | 'meetup.com' |
| 35 | ]; |
| 36 | |
| 37 | /** inline {@inheritdoc} */ |
| 38 | protected $httpsSupport = true; |
| 39 | |
| 40 | /** inline {@inheritdoc} */ |
| 41 | protected $responsiveSupport = true; |
| 42 | |
| 43 | /** inline {@inheritdoc} */ |
| 44 | public function validateUrl(Url $url) |
| 45 | { |
| 46 | return (bool) ( |
| 47 | preg_match('~meetup\.com/(?:.+)~i', (string) $url) || |
| 48 | preg_match('~meetu\.ps/(?:\w+)/?$~i', (string) $url) |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | /** inline {@inheritdoc} */ |
| 53 | public function normalizeUrl(Url $url) |
| 54 | { |
| 55 | $url->convertToHttps(); |
| 56 | $url->removeQueryString(); |
| 57 | |
| 58 | return $url; |
| 59 | } |
| 60 | |
| 61 | public function getStaticResponse() { |
| 62 | $meetup_website = 'https://meetup.com'; |
| 63 | $response = []; |
| 64 | $response['type'] = 'rich'; |
| 65 | $response['provider_name'] = 'Meetup'; |
| 66 | $response['provider_url'] = $meetup_website; |
| 67 | $response['url'] = $this->getUrl(); |
| 68 | $hash = 'mu_'.md5( $this->getUrl()); |
| 69 | $filename = wp_get_upload_dir()['basedir'] ."/embedpress/$hash.txt"; |
| 70 | add_filter('safe_style_css', [$this, 'safe_style_css']); |
| 71 | $allowed_protocols = wp_allowed_protocols(); |
| 72 | $allowed_protocols[] = 'data'; |
| 73 | |
| 74 | if (file_exists( $filename) ) { |
| 75 | $response['html'] = file_get_contents( $filename); |
| 76 | return $response; |
| 77 | }else{ |
| 78 | $t = wp_remote_get( $this->getUrl() , ['timeout'=>10]); |
| 79 | if ( !is_wp_error( $t) ) { |
| 80 | if ( $meetup_page_content = wp_remote_retrieve_body( $t) ) { |
| 81 | $dom = str_get_html($meetup_page_content); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | if ( empty( $dom) || !is_object( $dom) ) { |
| 88 | $response['html'] = $this->getUrl(); |
| 89 | return $response; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | // Event info |
| 94 | $header_dom = $dom->find('div[data-event-label="top"]', 0); |
| 95 | $body_dom = $dom->find('div[data-event-label="body"]', 0); |
| 96 | $event_location_info = $dom->find( 'div[data-event-label="info"] .sticky', 0); |
| 97 | if(empty($header_dom) || empty($body_dom) || empty($event_location_info)){ |
| 98 | return []; |
| 99 | } |
| 100 | $dewqijm = $event_location_info->find('.dewqijm', 0)->find('span', 0); |
| 101 | if(!empty($dewqijm)){ |
| 102 | $img = $dewqijm->find('noscript', 0)->innertext(); |
| 103 | $dewqijm->removeChild($dewqijm->find('img', 1)); |
| 104 | $dewqijm->find('noscript', 0)->remove(); |
| 105 | $dewqijm->outertext = $dewqijm->makeup() . $dewqijm->innertext . $img . '</span>'; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | $date = $this->embedpress_get_markup_from_node( $header_dom->find( 'time', 0) ); |
| 110 | $title = $this->embedpress_get_markup_from_node($header_dom->find('h1', 0)); |
| 111 | $emrv9za = $body_dom->find('div.emrv9za', 0); |
| 112 | $picture = $emrv9za->find('picture[data-testid="event-description-image"]', 0); |
| 113 | if(!empty($picture) && $picture->find('img', 0)){ |
| 114 | if($picture->find('noscript', 0)){ |
| 115 | $picture->find('img', 0)->remove(); |
| 116 | $img = $picture->find('noscript', 0)->innertext(); |
| 117 | $img = str_replace('/_next/image/', 'https://www.meetup.com/_next/image/', $img); |
| 118 | $picture->find('noscript', 0)->remove(); |
| 119 | $span = $picture->find('div', 0)->find('span', 0); |
| 120 | $span->outertext = $span->makeup() . $span->innertext . $img . '</span>'; |
| 121 | } |
| 122 | else{ |
| 123 | $img = $picture->find('img', 0); |
| 124 | $src = $img->src; |
| 125 | if($src && strpos($src, '/_next/image/') === 0){ |
| 126 | $img->src = 'https://www.meetup.com' . $img->src; |
| 127 | } |
| 128 | else if(strpos($src, '//') === false && $srcset = $img->srcset){ |
| 129 | $img->src = $this->getLargestImage($srcset); |
| 130 | if(strpos($img->src, '//') === false){ |
| 131 | $img->src = 'https://www.meetup.com' . $img->src; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | $content = $this->embedpress_get_markup_from_node( $emrv9za ) ; |
| 138 | |
| 139 | |
| 140 | |
| 141 | $host_info = $header_dom->find('a[data-event-label="hosted-by"]', 0); |
| 142 | ob_start(); |
| 143 | echo $host_info; |
| 144 | $host_info = ob_get_clean(); |
| 145 | |
| 146 | |
| 147 | ob_start(); |
| 148 | echo $event_location_info; |
| 149 | $event_location_info = ob_get_clean(); |
| 150 | |
| 151 | ob_start(); |
| 152 | ?> |
| 153 | <article class="embedpress-event"> |
| 154 | <header class="ep-event-header"> |
| 155 | <!--Date--> |
| 156 | <span class="ep-event--date"><?php echo esc_html( $date); ?></span> |
| 157 | <!--Event Title --> |
| 158 | <a class="ep-event-link" href="<?php echo esc_url( $this->getUrl()); ?>" target="_blank"> |
| 159 | <h1 class="ep-event--title"><?php echo esc_html( $title); ?></h1> |
| 160 | </a> |
| 161 | <!-- Event Host --> |
| 162 | <div class="ep-event--host"> |
| 163 | <?php echo wp_kses_post( $host_info );?> |
| 164 | </div> |
| 165 | </header> |
| 166 | |
| 167 | <section class="ep-event-content"> |
| 168 | <div class="ep-event--description"> |
| 169 | <?php echo wp_kses_post( $content );?> |
| 170 | </div> |
| 171 | </section> |
| 172 | |
| 173 | <aside> |
| 174 | <?php echo wp_kses( $event_location_info, 'post', $allowed_protocols); ?> |
| 175 | </aside> |
| 176 | |
| 177 | </article> |
| 178 | |
| 179 | <style> |
| 180 | .embedpress-event a, |
| 181 | .embedpress-event button { |
| 182 | text-decoration: none !important; |
| 183 | |
| 184 | } |
| 185 | .ep-event-header { |
| 186 | text-align: left; |
| 187 | } |
| 188 | .ep-event-header .ep-event--host .flex { |
| 189 | display: flex; |
| 190 | align-items: center; |
| 191 | gap: 12px; |
| 192 | } |
| 193 | |
| 194 | .ep-event-header .ep-event--host .flex div { |
| 195 | line-height: 1.3 !important; |
| 196 | } |
| 197 | .ep-event-header .ep-event--host img { |
| 198 | border-radius: 50%; |
| 199 | } |
| 200 | .ep-event-content { |
| 201 | text-align: left; |
| 202 | } |
| 203 | |
| 204 | .ep-event-content h2 { |
| 205 | font-size: 22px; |
| 206 | margin: 10px 0; |
| 207 | } |
| 208 | .embedpress-event aside .sticky { |
| 209 | display: flex; |
| 210 | gap: 30px; |
| 211 | text-align: left; |
| 212 | line-height: 1.3 !important; |
| 213 | } |
| 214 | .embedpress-event aside .sticky .hidden { |
| 215 | display: block; |
| 216 | } |
| 217 | .embedpress-event aside .sticky .hidden, |
| 218 | .embedpress-event aside .sticky .hidden + div { |
| 219 | flex: 0 0 calc(50% - 15px); |
| 220 | } |
| 221 | .embedpress-event aside .sticky .hidden .flex { |
| 222 | gap: 8px; |
| 223 | } |
| 224 | .embedpress-event aside .sticky .hidden .flex button { |
| 225 | background: transparent; |
| 226 | padding: 3px; |
| 227 | border: 0; |
| 228 | outline: none; |
| 229 | box-shadow: none; |
| 230 | } |
| 231 | /* .ep-event-header a { |
| 232 | font-size: 0; |
| 233 | } */ |
| 234 | /* .ep-event-header a div { |
| 235 | font-size: 0; |
| 236 | } |
| 237 | .ep-event-header > a > div > div { |
| 238 | border-raidus: 50%; |
| 239 | overflow: hidden; |
| 240 | } */ |
| 241 | </style> |
| 242 | |
| 243 | <?php |
| 244 | $event_output = ob_get_clean(); |
| 245 | file_put_contents( $filename, $event_output); |
| 246 | embedpress_schedule_cache_cleanup(); |
| 247 | $response['html'] = $event_output; |
| 248 | remove_filter('safe_style_css', [$this, 'safe_style_css']); |
| 249 | return $response; |
| 250 | } |
| 251 | |
| 252 | public function safe_style_css($styles){ |
| 253 | $styles[] = 'position'; |
| 254 | $styles[] = 'display'; |
| 255 | $styles[] = 'opacity'; |
| 256 | $styles[] = 'box-sizing'; |
| 257 | $styles[] = 'left'; |
| 258 | $styles[] = 'bottom'; |
| 259 | $styles[] = 'right'; |
| 260 | $styles[] = 'top'; |
| 261 | return $styles; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * It checks for data in the node before returning. |
| 266 | * |
| 267 | * @param \simple_html_dom_node $node |
| 268 | * @param string $method |
| 269 | * @param string $attr_name |
| 270 | * |
| 271 | * @return string it returns data from the node if found or empty strings otherwise. |
| 272 | */ |
| 273 | public function embedpress_get_markup_from_node( $node, $method='innertext', $attr_name=''){ |
| 274 | if ( !empty( $node) && is_object( $node) ) { |
| 275 | if ( !empty( $attr_name) ) { |
| 276 | return $node->getAttribute( $attr_name ); |
| 277 | } |
| 278 | if ( !empty( $method) && method_exists( $node, $method) ) { |
| 279 | return $node->{$method}(); |
| 280 | } |
| 281 | return ''; |
| 282 | } |
| 283 | return ''; |
| 284 | } |
| 285 | |
| 286 | function getLargestImage($srcsetString){ |
| 287 | $images = array(); |
| 288 | // split on comma |
| 289 | $srcsetArray = explode(",", $srcsetString); |
| 290 | foreach($srcsetArray as $srcString){ |
| 291 | // split on whitespace - optional descriptor |
| 292 | $imgArray = explode(" ", trim($srcString)); |
| 293 | // cast w or x descriptor as an Integer |
| 294 | $images[(int)$imgArray[1]] = $imgArray[0]; |
| 295 | } |
| 296 | // find the max |
| 297 | $maxIndex = max(array_keys($images)); |
| 298 | return $images[$maxIndex]; |
| 299 | } |
| 300 | |
| 301 | } |
| 302 |