Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RSVP formatting #42

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,35 +136,37 @@ function registerEventHooks()
// Push RSVPs to Facebook
Idno::site()->addEventHook('post/rsvp/facebook', function (\Idno\Core\Event $event) {
Idno::site()->logging()->debug("publishing RSVP to Facebook");

$eventdata = $event->data();
if ($this->hasFacebook()) {
$object = $eventdata['object'];
$facebookAPI = $this->getFacebookAPI($eventdata['syndication_account']);
$name = $this->getDisplayName($eventdata['syndication_account']);
if (!empty($facebookAPI)) {

$eventdata = $event->data();
$object = $eventdata['object'];
$facebookAPI = $this->getFacebookAPI($eventdata['syndication_account']);
$name = $this->getDisplayName($eventdata['syndication_account']);
if ($facebookAPI) {

$eventRegex = '#https?://(?:www\.|m\.)?facebook.com/events/(\d+)/?#';
$eventUrl = $this->possePostDiscovery($object->inreplyto, $eventRegex);

if ($eventUrl && preg_match($eventRegex, $eventUrl, $matches)) {
$eventId = $matches[1];

$endpoint = false;
if ($object->rsvp === 'yes') {
$endpoint = "/$eventId/attending";
} else if ($object->rsvp === 'no') {
$endpoint = "/$eventId/declined";
} else if ($object->rsvp === 'maybe') {
$endpoint = "/$eventId/maybe";
}
$eventRegex = '#https?://(?:www\.|m\.)?facebook.com/events/(\d+)/?#';
$eventUrl = $this->possePostDiscovery($object->inreplyto, $eventRegex);

if ($eventUrl && preg_match($eventRegex, $eventUrl, $matches)) {
$eventId = $matches[1];

$endpoint = false;
if ($object->rsvp === 'yes') {
$endpoint = "/$eventId/attending";
} else if ($object->rsvp === 'no') {
$endpoint = "/$eventId/declined";
} else if ($object->rsvp === 'maybe') {
$endpoint = "/$eventId/maybe";
}

if ($endpoint) {
Idno::site()->logging()->debug("publishing rsvp to Facebook on $endpoint");
$response = $facebookAPI->api($endpoint, 'POST');
Idno::site()->logging()->debug("publish response from Facebook", ['response' => $response]);
if ($endpoint) {
Idno::site()->logging()->debug("publishing rsvp to Facebook on $endpoint");
$response = $facebookAPI->api($endpoint, 'POST');
Idno::site()->logging()->debug("publish response from Facebook", ['response' => $response]);
}
}
}
}
}
});

// Push "media" to Facebook
Expand Down Expand Up @@ -379,7 +381,7 @@ function warmFacebookCache($url)
}

/**
* Can the current user use Twitter?
* Can the current user use Facebook?
* @return bool
*/
function hasFacebook()
Expand Down