2015-08-03 11:35:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Syndication extends WidgetBase
|
|
|
|
{
|
|
|
|
function load()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function display()
|
|
|
|
{
|
|
|
|
ob_clean();
|
|
|
|
|
2015-09-22 08:18:52 +02:00
|
|
|
$pd = new \modl\PostnDAO();
|
|
|
|
$cd = new \modl\ContactDAO();
|
|
|
|
$id = new \Modl\ItemDAO;
|
|
|
|
|
|
|
|
if(!$this->get('s')) {
|
2015-08-03 11:35:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-22 08:18:52 +02:00
|
|
|
$from = $this->get('s');
|
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
if(filter_var($from, FILTER_VALIDATE_EMAIL)) {
|
|
|
|
$node = 'urn:xmpp:microblog:0';
|
2015-09-22 08:18:52 +02:00
|
|
|
$contact = $cd->get($from);
|
|
|
|
} elseif(!$this->get('n')) {
|
2015-08-03 11:35:01 +02:00
|
|
|
return;
|
2015-09-22 08:18:52 +02:00
|
|
|
} else {
|
|
|
|
$node = $this->get('n');
|
|
|
|
$item = $id->getItem($from, $node);
|
2015-08-03 11:35:01 +02:00
|
|
|
}
|
2015-08-19 11:28:28 +02:00
|
|
|
|
2015-11-13 13:37:39 +01:00
|
|
|
$messages = $pd->getPublic($from, $node, 0, 20);
|
2015-09-22 08:18:52 +02:00
|
|
|
header("Content-Type: application/atom+xml; charset=UTF-8");
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2015-09-22 08:18:52 +02:00
|
|
|
$dom = new \DOMDocument('1.0', 'UTF-8');
|
|
|
|
$dom->formatOutput = true;
|
|
|
|
$feed = $dom->createElementNS('http://www.w3.org/2005/Atom', 'feed');
|
|
|
|
$dom->appendChild($feed);
|
2015-08-19 11:28:28 +02:00
|
|
|
|
2015-09-22 08:18:52 +02:00
|
|
|
$feed->appendChild($dom->createElement('updated', date('c')));
|
|
|
|
|
|
|
|
$feed->appendChild($self = $dom->createElement('link'));
|
|
|
|
$self->setAttribute('rel', 'self');
|
|
|
|
|
|
|
|
if($contact != null) {
|
|
|
|
$feed->appendChild($dom->createElement('title', __('feed.title', $contact->getTrueName())));
|
|
|
|
|
|
|
|
$feed->appendChild($author = $dom->createElement('author'));
|
|
|
|
$author->appendChild($dom->createElement('name', $contact->getTrueName()));
|
|
|
|
$author->appendChild($dom->createElement('uri', Route::urlize('blog',array($from))));
|
|
|
|
|
|
|
|
$feed->appendChild($dom->createElement('logo', $contact->getPhoto('xl')));
|
|
|
|
|
|
|
|
$self->setAttribute('href', Route::urlize('feed',array($server)));
|
2015-08-03 11:35:01 +02:00
|
|
|
}
|
2015-08-19 11:28:28 +02:00
|
|
|
|
2015-09-22 08:18:52 +02:00
|
|
|
if($item != null) {
|
|
|
|
if($item->name) {
|
|
|
|
$feed->appendChild($dom->createElement('title', $item->name));
|
|
|
|
} else {
|
|
|
|
$feed->appendChild($dom->createElement('title', $item->node));
|
|
|
|
}
|
|
|
|
|
|
|
|
if($item->description) {
|
|
|
|
$feed->appendChild($dom->createElement('subtitle', $item->description));
|
|
|
|
} else {
|
|
|
|
$feed->appendChild($dom->createElement('subtitle', $item->server));
|
|
|
|
}
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2015-09-22 08:18:52 +02:00
|
|
|
$self->setAttribute('href', Route::urlize('feed',array($server, $node)));
|
2015-08-03 11:35:01 +02:00
|
|
|
}
|
2015-08-19 11:28:28 +02:00
|
|
|
|
2015-09-22 08:18:52 +02:00
|
|
|
$feed->appendChild($generator = $dom->createElement('generator', 'Movim'));
|
|
|
|
$generator->setAttribute('uri', 'https://movim.eu');
|
|
|
|
$generator->setAttribute('version', APP_VERSION);
|
2015-08-19 11:28:28 +02:00
|
|
|
|
2015-09-22 08:18:52 +02:00
|
|
|
foreach($messages as $message) {
|
|
|
|
$feed->appendChild($entry = $dom->createElement('entry'));
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2015-09-22 08:18:52 +02:00
|
|
|
if($message->title) {
|
|
|
|
$entry->appendChild($dom->createElement('title', $message->title));
|
|
|
|
} else {
|
|
|
|
$entry->appendChild($dom->createElement('title', __('post.default_title')));
|
|
|
|
}
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2015-09-22 08:18:52 +02:00
|
|
|
$entry->appendChild($dom->createElement('id', $message->getUUID()));
|
|
|
|
$entry->appendChild($dom->createElement('updated', date('c', strtotime($message->updated))));
|
|
|
|
|
|
|
|
$entry->appendChild($content = $dom->createElement('content'));
|
|
|
|
$content->appendChild($div = $dom->createElementNS('http://www.w3.org/1999/xhtml', 'div'));
|
|
|
|
$content->setAttribute('type', 'xhtml');
|
|
|
|
|
|
|
|
$f = $dom->createDocumentFragment();
|
|
|
|
$f->appendXML($message->contentcleaned);
|
|
|
|
$div->appendChild($f);
|
|
|
|
|
|
|
|
$attachements = $message->getAttachements();
|
|
|
|
|
|
|
|
if(isset($attachements['pictures'])) {
|
|
|
|
foreach($attachements['pictures'] as $value) {
|
|
|
|
$entry->appendChild($link = $dom->createElement('link'));
|
|
|
|
$link->setAttribute('rel', 'enclosure');
|
|
|
|
$link->setAttribute('type', $value['type']);
|
|
|
|
$link->setAttribute('href', $value['href']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($attachements['files'])) {
|
|
|
|
foreach($attachements['files'] as $value) {
|
|
|
|
$entry->appendChild($link = $dom->createElement('link'));
|
|
|
|
$link->setAttribute('rel', 'enclosure');
|
|
|
|
$link->setAttribute('type', $value['type']);
|
|
|
|
$link->setAttribute('href', $value['href']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($attachements['links'])) {
|
2015-12-21 22:59:03 +01:00
|
|
|
foreach($attachements['links'] as $value) {
|
2015-09-22 08:18:52 +02:00
|
|
|
$entry->appendChild($link = $dom->createElement('link'));
|
|
|
|
$link->setAttribute('rel', 'alternate');
|
|
|
|
$link->setAttribute('href', $value['href']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $dom->saveXML();
|
|
|
|
exit;
|
2015-08-03 11:35:01 +02:00
|
|
|
}
|
|
|
|
}
|