Media attachment working

This commit is contained in:
Phyks 2015-01-19 00:08:24 +01:00
parent 747d0d6f94
commit 9065c899c1

View File

@ -81,28 +81,20 @@
\Idno\Core\site()->addEventHook('post/rsvp/diaspora', $article_function); \Idno\Core\site()->addEventHook('post/rsvp/diaspora', $article_function);
\Idno\Core\site()->addEventHook('post/article/diaspora', $article_function); \Idno\Core\site()->addEventHook('post/article/diaspora', $article_function);
// TODO
// Push "media" to Diaspora // Push "media" to Diaspora
\Idno\Core\site()->addEventHook('post/media/diaspora', function (\Idno\Core\Event $event) { \Idno\Core\site()->addEventHook('post/media/diaspora', function (\Idno\Core\Event $event) {
$eventdata = $event->data(); $eventdata = $event->data();
$object = $eventdata['object']; $object = $eventdata['object'];
if ($this->hasFacebook()) { if ($this->hasDiaspora()) {
if (!empty($eventdata['syndication_account'])) { $diasporaAPI = new DiasporaAPI(\Idno\Core\site()->session()->currentUser()->diaspora['diaspora_pod']);
$facebookAPI = $this->connect($eventdata['syndication_account']); $diasporaAPI->login(\Idno\Core\site()->session()->currentUser()->diaspora['diaspora_username'], \Idno\Core\site()->session()->currentUser()->diaspora['diaspora_password']);
} else { if (!empty($diasporaAPI)) {
$facebookAPI = $this->connect(); $message = strip_tags($object->getTitle()) . "\n\n" . strip_tags($object->getDescription());
} try {
if (!empty($facebookAPI)) { $diasporaAPI->post($message, 'KnownDiaspora');
$result = $facebookAPI->api('/'.$this->endpoint.'/feed', 'POST', } catch (\Exception $e) {
array( error_log('There was a problem posting to Diaspora: ' . $e->getMessage());
'link' => $object->getURL(), \Idno\Core\site()->session()->addMessage('There was a problem posting to Diaspora: ' . $e->getMessage());
'message' => $object->getTitle(),
'actions' => json_encode([['name' => 'See Original', 'link' => $object->getURL()]]),
));
if (!empty($result['id'])) {
$result['id'] = str_replace('_', '/posts/', $result['id']);
$object->setPosseLink('facebook', 'https://facebook.com/' . $result['id']);
$object->save();
} }
} }
} }