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/article/diaspora', $article_function);
// TODO
// Push "media" to Diaspora
\Idno\Core\site()->addEventHook('post/media/diaspora', function (\Idno\Core\Event $event) {
$eventdata = $event->data();
$object = $eventdata['object'];
if ($this->hasFacebook()) {
if (!empty($eventdata['syndication_account'])) {
$facebookAPI = $this->connect($eventdata['syndication_account']);
} else {
$facebookAPI = $this->connect();
}
if (!empty($facebookAPI)) {
$result = $facebookAPI->api('/'.$this->endpoint.'/feed', 'POST',
array(
'link' => $object->getURL(),
'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();
if ($this->hasDiaspora()) {
$diasporaAPI = new DiasporaAPI(\Idno\Core\site()->session()->currentUser()->diaspora['diaspora_pod']);
$diasporaAPI->login(\Idno\Core\site()->session()->currentUser()->diaspora['diaspora_username'], \Idno\Core\site()->session()->currentUser()->diaspora['diaspora_password']);
if (!empty($diasporaAPI)) {
$message = strip_tags($object->getTitle()) . "\n\n" . strip_tags($object->getDescription());
try {
$diasporaAPI->post($message, 'KnownDiaspora');
} catch (\Exception $e) {
error_log('There was a problem posting to Diaspora: ' . $e->getMessage());
\Idno\Core\site()->session()->addMessage('There was a problem posting to Diaspora: ' . $e->getMessage());
}
}
}