Long entries crosspost working
This commit is contained in:
parent
3f0f556a80
commit
eec1c00781
33
Main.php
33
Main.php
@ -32,7 +32,6 @@
|
|||||||
$eventdata = $event->data();
|
$eventdata = $event->data();
|
||||||
$object = $eventdata['object'];
|
$object = $eventdata['object'];
|
||||||
if ($this->hasDiaspora()) {
|
if ($this->hasDiaspora()) {
|
||||||
$object = $eventdata['object'];
|
|
||||||
$diasporaAPI = new DiasporaAPI(\Idno\Core\site()->session()->currentUser()->diaspora['diaspora_pod']);
|
$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']);
|
$diasporaAPI->login(\Idno\Core\site()->session()->currentUser()->diaspora['diaspora_username'], \Idno\Core\site()->session()->currentUser()->diaspora['diaspora_password']);
|
||||||
if (!empty($diasporaAPI)) {
|
if (!empty($diasporaAPI)) {
|
||||||
@ -45,11 +44,7 @@
|
|||||||
|
|
||||||
if (!empty($message) && substr($message, 0, 1) != '@') {
|
if (!empty($message) && substr($message, 0, 1) != '@') {
|
||||||
try {
|
try {
|
||||||
$result = $diasporaAPI->post($message, 'KnownDiaspora');
|
$diasporaAPI->post($message, 'KnownDiaspora');
|
||||||
if (!empty($result['id'])) {
|
|
||||||
$result['id'] = str_replace('_', '/posts/', $result['id']);
|
|
||||||
$object->save();
|
|
||||||
}
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
error_log('There was a problem posting to Diaspora: ' . $e->getMessage());
|
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());
|
\Idno\Core\site()->session()->addMessage('There was a problem posting to Diaspora: ' . $e->getMessage());
|
||||||
@ -63,28 +58,16 @@
|
|||||||
\Idno\Core\site()->addEventHook('post/note/diaspora', $notes_function);
|
\Idno\Core\site()->addEventHook('post/note/diaspora', $notes_function);
|
||||||
\Idno\Core\site()->addEventHook('post/bookmark/diaspora', $notes_function);
|
\Idno\Core\site()->addEventHook('post/bookmark/diaspora', $notes_function);
|
||||||
|
|
||||||
// TODO
|
|
||||||
$article_function = function (\Idno\Core\Event $event) {
|
$article_function = 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 = $object->getTitle();
|
||||||
}
|
$message .= "\n\n(<a href=\"http://" . $object->getShortURL(true, false) . "\">" . $object->getShortURL(true, false) . "</a>)";
|
||||||
if (!empty($facebookAPI)) {
|
$diasporaAPI->post($message, 'KnownDiaspora');
|
||||||
$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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user