Skip to content
Permalink
Browse files

feat: rebuild homepage meetup feed with public ical feed

Meetup deprecated all their public APIs :-(
  • Loading branch information...
themightychris committed Aug 28, 2019
1 parent 2308e43 commit 41b686c8f5c8c83e1dbac314849e42dab3959ed4
@@ -0,0 +1,3 @@
[holomapping]
root = "src"
files = "*.php"
@@ -0,0 +1,3 @@
[holosource]
url = "https://github.com/OzzyCzech/icalparser.git"
ref = "refs/heads/master"
@@ -1,16 +1,34 @@
{template meetup event headingLevel=h3 showRsvp=true}
{$endTime = $event.time + $event.duration}
<article class="event card">
<div class="card-body">
<{$headingLevel} class="event-title">{$event.name}</{$headingLevel}>
<{$headingLevel} class="event-title">{$event.title|escape}</{$headingLevel}>

<p class="event-meta">
<time datetime="{$event.time/1000|date_format:'%Y-%m-%dT%G:%M'}">{$event.time/1000|date_format:"%A, %b %e <br> %l:%M%P"}</time>–<time datetime="{$endTime.time/1000|date_format:'%Y-%m-%dT%G:%M'}">{$endTime/1000|date_format:"%l:%M%P"}</time>
&#32;@&nbsp;<a href="http://maps.google.com/?q={$event.venue.address_1},%20{$event.venue.zip}">{$event.venue.name}</a>
{strip}
<time datetime="{$event.time_start->getTimestamp()|date_format:'%Y-%m-%dT%G:%M'}">
{$event.time_start->getTimestamp()|date_format:"%A, %b %e <br> %l:%M%P"}
</time>
<time datetime="{$event.time_end->getTimestamp()|date_format:'%Y-%m-%dT%G:%M'}">
{$event.time_end->getTimestamp()|date_format:"%l:%M%P"}
</time>
&#32;@&nbsp;
<a target="_blank" href="http://maps.google.com/?q={$event.location.name|escape:url},{$event.location.address|escape:url}">
{$event.location.name|default:$event.location.address|escape}
</a>
{/strip}
</p>

{if $showRsvp}
<p><a href="{$event.event_url}">{sprintf(_("RSVP @ %s"), parse_url($event.event_url, $.const.PHP_URL_HOST))}</a> {if $event.yes_rsvp_count}({_("%s so far")|sprintf:$event.yes_rsvp_count}){/if}</p>
<p>
<a href="{$event.url|escape}">
{sprintf(_("RSVP @ %s"), parse_url($event.url, $.const.PHP_URL_HOST))}
</a>
{if $event.yes_rsvp_count}
{* not currently available in the data :'( *}
({_("%s so far")|sprintf:$event.yes_rsvp_count})
{/if}
</p>
{/if}
</div>
</article>
@@ -0,0 +1,77 @@
<?php
namespace Emergence\Meetup;
use Cache;
use om\IcalParser;
class Connector extends \Emergence\Connectors\AbstractConnector
{
public static $groupSlug;
public static $feedCacheTime = 60;
public static function getUpcomingEvents()
{
$groupSlug = static::$groupSlug;
if (!$groupSlug) {
return [];
}
$cacheKey = "meetup/{$groupSlug}/events";
$events = Cache::fetch($cacheKey);
if ($events === null) {
// cached failure
throw new Exception('meetup feed unavailable');
} elseif ($events === false) {
$cal = new IcalParser();
$cal->parseFile("https://www.meetup.com/{$groupSlug}/events/ical/");
$events = [];
foreach ($cal->getSortedEvents() as $event) {
$matches = null;
$events[] = [
'id' => preg_match('/^event_(?P<id>\d+)@meetup\\.com$/', $event['UID'], $matches)
? $matches['id']
: $event['UID'],
'url' => $event['URL'],
'title' => $event['SUMMARY'],
'description' => $event['DESCRIPTION'],
'location' => preg_match('/^(?P<name>.+) \((?P<address>.+)\)$/', $event['LOCATION'], $matches)
? [ 'name' => $matches['name'], 'address' => $matches['address'] ]
: [ 'name' => '', 'address' => $event['LOCATION'] ],
'time_start' => $event['DTSTART'],
'time_end' => $event['DTEND'],
'ical' => $event
];
}
Cache::store($cacheKey, $events, static::$feedCacheTime);
}
return $events;
}
public static function getUpcomingEvents_Atom()
{
$groupSlug = static::$groupSlug;
if (!$groupSlug) {
return [];
}
$xml = simplexml_load_file("https://www.meetup.com/{$groupSlug}/events/atom/");
$events = [];
foreach ($xml->entry as $event) {
$events[] = [
'id' => (string)$event->id,
'name' => (string)$event->title,
'description' => (string)$event->content,
'url' => (string)$event->link['href']
];
}
return $events;
}
}
@@ -0,0 +1,9 @@
<?php
/**
* The name of your Meetup group as formatted in the URL
*
* The example value is for https://meetup.com/Code-for-Philly
*/
// Emergence\Meetup\Connector::$groupSlug = 'Code-for-Philly';
@@ -1,31 +1,29 @@
<?php
// compile home page data
$now = time() * 1000;
$now = new DateTime();
$pageData = array();
// meetups
try {
$meetups = RemoteSystems\Meetup::getEvents();
$meetups = Emergence\Meetup\Connector::getUpcomingEvents();
$nextMeetup = array_shift($meetups);
// detect if meetup is happening right now
if($nextMeetup && $nextMeetup['time'] < $now) {
// - use ?next_meetup_now=1 to test feature before any event
if(
($nextMeetup && $nextMeetup['time_start'] < $now)
|| !empty($_GET['next_meetup_now'])
) {
$currentMeetup = $nextMeetup;
$nextMeetup = array_shift($meetups);
}
// TODO: delete this!
elseif(!empty($_GET['force_current'])) {
$currentMeetup = $nextMeetup;
}
if($currentMeetup) {
$currentMeetup['checkins'] = Laddr\MemberCheckin::getAllForMeetupByProject($currentMeetup['id']);
}
$pageData['currentMeetup'] = $currentMeetup;
$pageData['nextMeetup'] = $nextMeetup;
$pageData['futureMeetups'] = $meetups;
@@ -38,7 +36,7 @@
if (!$pageData['activity'] = Cache::fetch('home-activity')) {
$existingTables = \DB::allValues('table_name', 'SELECT table_name FROM information_schema.TABLES WHERE TABLE_SCHEMA = SCHEMA()');
$activityQueries = [];
if (in_array(Emergence\CMS\AbstractContent::$tableName, $existingTables)) {
$activityQueries[] = sprintf(
'SELECT'

0 comments on commit 41b686c

Please sign in to comment.
You can’t perform that action at this time.