use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
require_once 'include/items.php';
require_once 'mod/share.php';
require_once 'include/enotify.php';
require_once 'include/items.php';
require_once 'mod/share.php';
require_once 'include/enotify.php';
*/
private static function fetchAuthor($xpath, $context, $importer, &$contact, $onlyfetch)
{
*/
private static function fetchAuthor($xpath, $context, $importer, &$contact, $onlyfetch)
{
$author["author-link"] = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue;
$author["author-name"] = $xpath->evaluate('atom:author/atom:name/text()', $context)->item(0)->nodeValue;
$addr = $xpath->evaluate('atom:author/atom:email/text()', $context)->item(0)->nodeValue;
$author["author-link"] = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue;
$author["author-name"] = $xpath->evaluate('atom:author/atom:name/text()', $context)->item(0)->nodeValue;
$addr = $xpath->evaluate('atom:author/atom:email/text()', $context)->item(0)->nodeValue;
- $condition = ["`uid` = ? AND `alias` = ? AND `network` != ?",
- $importer["uid"], $aliaslink, NETWORK_STATUSNET];
- $r = dba::selectOne('contact', [], $condition);
-
- if (DBM::is_result($r)) {
- $found = true;
- if ($r['blocked']) {
- $r['id'] = -1;
- }
- $contact = $r;
- $author["contact-id"] = $r["id"];
- }
+ $condition = ["`uid` = ? AND `alias` = ? AND `network` != ? AND `rel` IN (?, ?)",
+ $importer["uid"], $aliaslink, NETWORK_STATUSNET,
+ CONTACT_IS_SHARING, CONTACT_IS_FRIEND];
+ $contact = dba::selectFirst('contact', [], $condition);
- $condition = ["`uid` = ? AND `nurl` IN (?, ?) AND `network` != ?", $importer["uid"],
- normalise_link($author["author-link"]), normalise_link($aliaslink), NETWORK_STATUSNET];
- $r = dba::selectOne('contact', [], $condition);
-
- if (DBM::is_result($r)) {
- $found = true;
- if ($r['blocked']) {
- $r['id'] = -1;
- }
- $contact = $r;
- $author["contact-id"] = $r["id"];
- }
+ $condition = ["`uid` = ? AND `nurl` IN (?, ?) AND `network` != ? AND `rel` IN (?, ?)",
+ $importer["uid"], normalise_link($author["author-link"]), normalise_link($aliaslink),
+ NETWORK_STATUSNET, CONTACT_IS_SHARING, CONTACT_IS_FRIEND];
+ $contact = dba::selectFirst('contact', [], $condition);
- if (!$found && ($addr != "")) {
- $condition = ["`uid` = ? AND `addr` = ? AND `network` != ?",
- $importer["uid"], $addr, NETWORK_STATUSNET];
- $r = dba::selectOne('contact', [], $condition);
+ if (!DBM::is_result($contact) && ($addr != '')) {
+ $condition = ["`uid` = ? AND `addr` = ? AND `network` != ? AND `rel` IN (?, ?)",
+ $importer["uid"], $addr, NETWORK_STATUSNET,
+ CONTACT_IS_SHARING, CONTACT_IS_FRIEND];
+ $contact = dba::selectFirst('contact', [], $condition);
+ }
$avatars = $xpath->query("atom:author/atom:link[@rel='avatar']", $context);
foreach ($avatars as $avatar) {
$href = "";
$avatars = $xpath->query("atom:author/atom:link[@rel='avatar']", $context);
foreach ($avatars as $avatar) {
$href = "";
$author["owner-avatar"] = $author["author-avatar"];
// Only update the contacts if it is an OStatus contact
$author["owner-avatar"] = $author["author-avatar"];
// Only update the contacts if it is an OStatus contact
- dba::update('contact', $contact, array('id' => $contact["id"]), $current);
+ dba::update('contact', $contact, ['id' => $contact["id"]], $current);
if (!empty($author["author-avatar"]) && ($author["author-avatar"] != $current['avatar'])) {
logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG);
if (!empty($author["author-avatar"]) && ($author["author-avatar"] != $current['avatar'])) {
logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG);
if ($cid) {
$fields = ['url', 'nurl', 'name', 'nick', 'alias', 'about', 'location'];
if ($cid) {
$fields = ['url', 'nurl', 'name', 'nick', 'alias', 'about', 'location'];
'nurl' => normalise_link($author["author-link"]),
'nick' => $contact["nick"], 'alias' => $contact["alias"],
'about' => $contact["about"], 'location' => $contact["location"],
'nurl' => normalise_link($author["author-link"]),
'nick' => $contact["nick"], 'alias' => $contact["alias"],
'about' => $contact["about"], 'location' => $contact["location"],
- dba::update('contact', $fields, array('id' => $cid), $old_contact);
+ dba::update('contact', $fields, ['id' => $cid], $old_contact);
$xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
$xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
$xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
$xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
- foreach ($entries as $entry) {
- // fetch the author
- $author = self::fetchAuthor($xpath, $entry, $importer, $contact, true);
- return $author;
- }
+ // Fetch the first author
+ $authordata = $xpath->query('//author')->item(0);
+ $author = self::fetchAuthor($xpath, $authordata, $importer, $contact, true);
+ return $author;
foreach ($element->attributes as $attributes) {
$attribute[$attributes->name] = $attributes->textContent;
foreach ($element->attributes as $attributes) {
$attribute[$attributes->name] = $attributes->textContent;
private static function process($xml, $importer, &$contact, &$hub, $stored = false, $initialize = true)
{
if ($initialize) {
private static function process($xml, $importer, &$contact, &$hub, $stored = false, $initialize = true)
{
if ($initialize) {
$header["uid"] = $importer["uid"];
$header["network"] = NETWORK_OSTATUS;
$header["type"] = "remote";
$header["uid"] = $importer["uid"];
$header["network"] = NETWORK_OSTATUS;
$header["type"] = "remote";
- if (in_array($item["verb"], array('qvitter-delete-notice', ACTIVITY_DELETE, 'delete'))) {
+ if (in_array($item["verb"], ['qvitter-delete-notice', ACTIVITY_DELETE, 'delete'])) {
// Ignore "Unfavorite" message
logger("Ignore unfavorite message ".print_r($item, true), LOGGER_DEBUG);
continue;
}
// Deletions come with the same uri, so we check for duplicates after processing deletions
// Ignore "Unfavorite" message
logger("Ignore unfavorite message ".print_r($item, true), LOGGER_DEBUG);
continue;
}
// Deletions come with the same uri, so we check for duplicates after processing deletions
- new_follower($importer, $contact, $item, $nickname);
+ Contact::addRelationship($importer, $contact, $item, $nickname);
- lose_follower($importer, $contact, $item, $dummy);
+ Contact::removeFollower($importer, $contact, $item, $dummy);
- if (!in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE))) {
+ if (!in_array($item["verb"], [ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE])) {
if (!$valid) {
// If not, then it depends on this setting
$valid = !Config::get('system', 'ostatus_full_threads');
if (!$valid) {
// If not, then it depends on this setting
$valid = !Config::get('system', 'ostatus_full_threads');
foreach (self::$itemlist as $item) {
if (!empty($item['contact-id']) && in_array($item['verb'], $verbs)) {
$valid = true;
}
}
foreach (self::$itemlist as $item) {
if (!empty($item['contact-id']) && in_array($item['verb'], $verbs)) {
$valid = true;
}
}
- $valid = dba::exists('item', array('uid' => $importer["uid"], 'uri' => self::$itemlist[0]['parent-uri']));
+ $valid = dba::exists('item', ['uid' => $importer["uid"], 'uri' => self::$itemlist[0]['parent-uri']]);
+ if ($valid) {
+ logger("Item with uri ".self::$itemlist[0]["uri"]." belongs to parent ".self::$itemlist[0]['parent-uri']." of user ".$importer["uid"].". It will be imported.", LOGGER_DEBUG);
+ }
if ($found) {
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already exists.", LOGGER_DEBUG);
} elseif ($item['contact-id'] < 0) {
logger("Item with uri ".$item["uri"]." is from a blocked contact.", LOGGER_DEBUG);
} else {
// We are having duplicated entries. Hopefully this solves it.
if ($found) {
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already exists.", LOGGER_DEBUG);
} elseif ($item['contact-id'] < 0) {
logger("Item with uri ".$item["uri"]." is from a blocked contact.", LOGGER_DEBUG);
} else {
// We are having duplicated entries. Hopefully this solves it.
- if (Lock::set('ostatus_process_item_store')) {
- $ret = item_store($item);
- Lock::remove('ostatus_process_item_store');
+ if (Lock::set('ostatus_process_item_insert')) {
+ $ret = Item::insert($item);
+ Lock::remove('ostatus_process_item_insert');
private static function deleteNotice($item)
{
$condition = ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'uri' => $item['uri']];
private static function deleteNotice($item)
{
$condition = ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'uri' => $item['uri']];
- $deleted = dba::selectOne('item', ['id', 'parent-uri'], $condition);
+ $deleted = dba::selectFirst('item', ['id', 'parent-uri'], $condition);
if (!DBM::is_result($deleted)) {
logger('Item from '.$item['author-link'].' with uri '.$item['uri'].' for user '.$item['uid']." wasn't found. We don't delete it. ");
return;
}
if (!DBM::is_result($deleted)) {
logger('Item from '.$item['author-link'].' with uri '.$item['uri'].' for user '.$item['uid']." wasn't found. We don't delete it. ");
return;
}
- // Currently we don't have a central deletion function that we could use in this case
- // The function "item_drop" doesn't work for that case
- dba::update(
- 'item',
- array('deleted' => true, 'title' => '', 'body' => '',
- 'edited' => datetime_convert(), 'changed' => datetime_convert()),
- array('id' => $deleted["id"])
- );
-
- delete_thread($deleted["id"], $deleted["parent-uri"]);
+ Item::deleteById($deleted["id"]);
*/
private static function processPost($xpath, $entry, &$item, $importer)
{
*/
private static function processPost($xpath, $entry, &$item, $importer)
{
$item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue;
if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) || ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
$item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
$item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue;
if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) || ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
$item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
// Mastodon Content Warning
if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
$clear_text = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
// Mastodon Content Warning
if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
$clear_text = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
- if (isset($item["parent-uri"]) && ($related != '')) {
- if (!dba::exists('item', array('uid' => $importer["uid"], 'uri' => $item['parent-uri']))) {
- self::fetchRelated($related, $item["parent-uri"], $importer);
+ if (isset($item["parent-uri"])) {
+ if (!dba::exists('item', ['uid' => $importer["uid"], 'uri' => $item['parent-uri']])) {
+ if ($related != '') {
+ self::fetchRelated($related, $item["parent-uri"], $importer);
+ }
- $conversation_data = z_fetch_url($conversation, false, $redirects, array('accept_content' => 'application/atom+xml, text/html'));
+ $conversation_data = Network::curl($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
foreach ($links as $link) {
$attribute = self::readAttributes($link);
if (($attribute['rel'] == 'alternate') && ($attribute['type'] == 'application/atom+xml')) {
foreach ($links as $link) {
$attribute = self::readAttributes($link);
if (($attribute['rel'] == 'alternate') && ($attribute['type'] == 'application/atom+xml')) {
if (dba::exists('conversation', $condition)) {
logger('Delete deprecated entry for URI '.$conv_data['uri'], LOGGER_DEBUG);
if (dba::exists('conversation', $condition)) {
logger('Delete deprecated entry for URI '.$conv_data['uri'], LOGGER_DEBUG);
- $condition = array('`item-uri` = ? AND `protocol` IN (?, ?)', $self, PROTOCOL_DFRN, PROTOCOL_OSTATUS_SALMON);
+ $condition = ['`item-uri` = ? AND `protocol` IN (?, ?)', $self, PROTOCOL_DFRN, PROTOCOL_OSTATUS_SALMON];
if (dba::exists('conversation', $condition)) {
logger('Conversation '.$item['uri'].' is already stored.', LOGGER_DEBUG);
return;
}
if (dba::exists('conversation', $condition)) {
logger('Conversation '.$item['uri'].' is already stored.', LOGGER_DEBUG);
return;
}
private static function fetchRelated($related, $related_uri, $importer)
{
$condition = ['`item-uri` = ? AND `protocol` IN (?, ?)', $related_uri, PROTOCOL_DFRN, PROTOCOL_OSTATUS_SALMON];
private static function fetchRelated($related, $related_uri, $importer)
{
$condition = ['`item-uri` = ? AND `protocol` IN (?, ?)', $related_uri, PROTOCOL_DFRN, PROTOCOL_OSTATUS_SALMON];
- $conversation = dba::selectOne('conversation', ['source', 'protocol'], $condition);
+ $conversation = dba::selectFirst('conversation', ['source', 'protocol'], $condition);
}
if ($conversation['protocol'] == PROTOCOL_OSTATUS_SALMON) {
logger('Delete invalid cached XML for URI '.$related_uri, LOGGER_DEBUG);
}
if ($conversation['protocol'] == PROTOCOL_OSTATUS_SALMON) {
logger('Delete invalid cached XML for URI '.$related_uri, LOGGER_DEBUG);
- $related_data = z_fetch_url($related, false, $redirects, array('accept_content' => 'application/atom+xml, text/html'));
+ $related_data = Network::curl($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
if ($related_atom['success']) {
logger('Fetched XML for URI '.$related_uri, LOGGER_DEBUG);
if ($related_atom['success']) {
logger('Fetched XML for URI '.$related_uri, LOGGER_DEBUG);
// Workaround for older GNU Social servers
if (($xml == '') && strstr($related, '/notice/')) {
// Workaround for older GNU Social servers
if (($xml == '') && strstr($related, '/notice/')) {
if ($related_atom['success']) {
logger('GNU Social workaround to fetch XML for URI '.$related_uri, LOGGER_DEBUG);
if ($related_atom['success']) {
logger('GNU Social workaround to fetch XML for URI '.$related_uri, LOGGER_DEBUG);
// Even more worse workaround for GNU Social ;-)
if ($xml == '') {
$related_guess = OStatus::convertHref($related_uri);
// Even more worse workaround for GNU Social ;-)
if ($xml == '') {
$related_guess = OStatus::convertHref($related_uri);
- $related_atom = z_fetch_url(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom');
+ $related_atom = Network::curl(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom');
if ($related_atom['success']) {
logger('GNU Social workaround 2 to fetch XML for URI '.$related_uri, LOGGER_DEBUG);
if ($related_atom['success']) {
logger('GNU Social workaround 2 to fetch XML for URI '.$related_uri, LOGGER_DEBUG);
// Finally we take the data that we fetched from "ostatus:conversation"
if ($xml == '') {
$condition = ['item-uri' => $related_uri, 'protocol' => PROTOCOL_SPLITTED_CONV];
// Finally we take the data that we fetched from "ostatus:conversation"
if ($xml == '') {
$condition = ['item-uri' => $related_uri, 'protocol' => PROTOCOL_SPLITTED_CONV];
if (DBM::is_result($conversation)) {
$stored = true;
logger('Got cached XML from conversation for URI '.$related_uri, LOGGER_DEBUG);
if (DBM::is_result($conversation)) {
$stored = true;
logger('Got cached XML from conversation for URI '.$related_uri, LOGGER_DEBUG);
$activityobjects = $xpath->query('activity:object', $entry)->item(0);
if (!is_object($activityobjects)) {
$activityobjects = $xpath->query('activity:object', $entry)->item(0);
if (!is_object($activityobjects)) {
$item["author-link"] = $orig_author["author-link"];
$item["author-avatar"] = $orig_author["author-avatar"];
$item["author-link"] = $orig_author["author-link"];
$item["author-avatar"] = $orig_author["author-avatar"];
$preview = proxy_url($preview, false, PROXY_SIZE_SMALL);
// Is it a local picture? Then make it smaller here
$preview = proxy_url($preview, false, PROXY_SIZE_SMALL);
// Is it a local picture? Then make it smaller here
- $preview = str_replace(array("-0.jpg", "-0.png"), array("-2.jpg", "-2.png"), $preview);
- $preview = str_replace(array("-1.jpg", "-1.png"), array("-2.jpg", "-2.png"), $preview);
+ $preview = str_replace(["-0.jpg", "-0.png"], ["-2.jpg", "-2.png"], $preview);
+ $preview = str_replace(["-1.jpg", "-1.png"], ["-2.jpg", "-2.png"], $preview);
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
$root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
$root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
- case 'activity': $title = t('%s\'s timeline', $owner['name']); break;
- case 'posts' : $title = t('%s\'s posts' , $owner['name']); break;
- case 'comments': $title = t('%s\'s comments', $owner['name']); break;
+ case 'activity': $title = L10n::t('%s\'s timeline', $owner['name']); break;
+ case 'posts' : $title = L10n::t('%s\'s posts' , $owner['name']); break;
+ case 'comments': $title = L10n::t('%s\'s comments', $owner['name']); break;
XML::addElement($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
XML::addElement($doc, $root, "id", System::baseUrl() . "/profile/" . $owner["nick"]);
XML::addElement($doc, $root, "title", $title);
XML::addElement($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], $a->config["sitename"]));
XML::addElement($doc, $root, "logo", $owner["photo"]);
XML::addElement($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
XML::addElement($doc, $root, "id", System::baseUrl() . "/profile/" . $owner["nick"]);
XML::addElement($doc, $root, "title", $title);
XML::addElement($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], $a->config["sitename"]));
XML::addElement($doc, $root, "logo", $owner["photo"]);
- XML::addElement($doc, $root, "updated", datetime_convert("UTC", "UTC", "now", ATOM_TIME));
+ XML::addElement($doc, $root, "updated", DateTimeFormat::utcNow(DateTimeFormat::ATOM));
$author = self::addAuthor($doc, $owner);
$root->appendChild($author);
$author = self::addAuthor($doc, $owner);
$root->appendChild($author);
XML::addElement($doc, $root, "link", "", $attributes);
/// @TODO We have to find out what this is
XML::addElement($doc, $root, "link", "", $attributes);
/// @TODO We have to find out what this is
XML::addElement($doc, $root, "link", "", $attributes);
XML::addElement($doc, $root, "link", "", $attributes);
XML::addElement($doc, $root, "link", "", $attributes);
XML::addElement($doc, $root, "link", "", $attributes);
XML::addElement($doc, $root, "link", "", $attributes);
XML::addElement($doc, $root, "link", "", $attributes);
- $attributes = array("href" => System::baseUrl() . "/api/statuses/user_timeline/" . $owner["nick"] . ".atom",
- "rel" => "self", "type" => "application/atom+xml");
+ $attributes = ["href" => System::baseUrl() . "/api/statuses/user_timeline/" . $owner["nick"] . ".atom",
+ "rel" => "self", "type" => "application/atom+xml"];
XML::addElement($doc, $root, "link", "", $attributes);
XML::addElement($doc, $root, "link", "", $attributes);
+ if ($owner['account-type'] == ACCOUNT_TYPE_COMMUNITY) {
+ $condition = ['uid' => $owner['uid'], 'self' => false, 'pending' => false,
+ 'archive' => false, 'hidden' => false, 'blocked' => false];
+ $members = dba::count('contact', $condition);
+ XML::addElement($doc, $root, "statusnet:group_info", "", ["member_count" => $members]);
+ }
+
public static function hublinks($doc, $root, $nick)
{
$h = System::baseUrl() . '/pubsubhubbub/'.$nick;
public static function hublinks($doc, $root, $nick)
{
$h = System::baseUrl() . '/pubsubhubbub/'.$nick;
- XML::addElement($doc, $root, "link", "", array("href" => $h, "rel" => "hub"));
+ XML::addElement($doc, $root, "link", "", ["href" => $h, "rel" => "hub"]);
"href" => $siteinfo["image"],
"type" => $imgdata["mime"],
"href" => $siteinfo["image"],
"type" => $imgdata["mime"],
XML::addElement($doc, $root, "link", "", $attributes);
break;
case 'video':
XML::addElement($doc, $root, "link", "", $attributes);
break;
case 'video':
"href" => $siteinfo["url"],
"type" => "text/html; charset=UTF-8",
"length" => "",
"href" => $siteinfo["url"],
"type" => "text/html; charset=UTF-8",
"length" => "",
XML::addElement($doc, $root, "link", "", $attributes);
break;
default:
XML::addElement($doc, $root, "link", "", $attributes);
break;
default:
if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo["type"] != "photo") && isset($siteinfo["image"])) {
$imgdata = Image::getInfoFromURL($siteinfo["image"]);
if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo["type"] != "photo") && isset($siteinfo["image"])) {
$imgdata = Image::getInfoFromURL($siteinfo["image"]);
"href" => $siteinfo["image"],
"type" => $imgdata["mime"],
"href" => $siteinfo["image"],
"type" => $imgdata["mime"],
XML::addElement($doc, $root, "link", "", $attributes);
}
XML::addElement($doc, $root, "link", "", $attributes);
}
$matches = false;
$cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches);
if ($cnt) {
$matches = false;
$cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches);
if ($cnt) {
- $r = q("SELECT `homepage`, `publish` FROM `profile` WHERE `uid` = %d AND `is-default` LIMIT 1", intval($owner["uid"]));
- if (DBM::is_result($r)) {
- $profile = $r[0];
- }
+ $profile = dba::selectFirst('profile', ['homepage', 'publish'], ['uid' => $owner['uid'], 'is-default' => true]);
$author = $doc->createElement("author");
XML::addElement($doc, $author, "id", $owner["url"]);
$author = $doc->createElement("author");
XML::addElement($doc, $author, "id", $owner["url"]);
- XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
+ if ($owner['account-type'] == ACCOUNT_TYPE_COMMUNITY) {
+ XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_GROUP);
+ } else {
+ XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
+ }
XML::addElement($doc, $author, "uri", $owner["url"]);
XML::addElement($doc, $author, "name", $owner["nick"]);
XML::addElement($doc, $author, "email", $owner["addr"]);
XML::addElement($doc, $author, "uri", $owner["url"]);
XML::addElement($doc, $author, "name", $owner["nick"]);
XML::addElement($doc, $author, "email", $owner["addr"]);
- XML::addElement($doc, $author, "summary", bbcode($owner["about"], false, false, 7));
+ if ($show_profile) {
+ XML::addElement($doc, $author, "summary", BBCode::convert($owner["about"], false, 7));
+ }
XML::addElement($doc, $author, "link", "", $attributes);
XML::addElement($doc, $author, "link", "", $attributes);
XML::addElement($doc, $author, "link", "", $attributes);
if (isset($owner["thumb"])) {
XML::addElement($doc, $author, "link", "", $attributes);
if (isset($owner["thumb"])) {
XML::addElement($doc, $author, "link", "", $attributes);
}
XML::addElement($doc, $author, "poco:preferredUsername", $owner["nick"]);
XML::addElement($doc, $author, "poco:displayName", $owner["name"]);
XML::addElement($doc, $author, "link", "", $attributes);
}
XML::addElement($doc, $author, "poco:preferredUsername", $owner["nick"]);
XML::addElement($doc, $author, "poco:displayName", $owner["name"]);
- XML::addElement($doc, $author, "poco:note", bbcode($owner["about"], false, false, 7));
+ if ($show_profile) {
+ XML::addElement($doc, $author, "poco:note", BBCode::convert($owner["about"], false, 7));
- if (trim($owner["location"]) != "") {
- $element = $doc->createElement("poco:address");
- XML::addElement($doc, $element, "poco:formatted", $owner["location"]);
- $author->appendChild($element);
+ if (trim($owner["location"]) != "") {
+ $element = $doc->createElement("poco:address");
+ XML::addElement($doc, $element, "poco:formatted", $owner["location"]);
+ $author->appendChild($element);
+ }
- if (trim($profile["homepage"]) != "") {
- $urls = $doc->createElement("poco:urls");
- XML::addElement($doc, $urls, "poco:type", "homepage");
- XML::addElement($doc, $urls, "poco:value", $profile["homepage"]);
- XML::addElement($doc, $urls, "poco:primary", "true");
- $author->appendChild($urls);
- }
+ if (DBM::is_result($profile) && !$show_profile) {
+ if (trim($profile["homepage"]) != "") {
+ $urls = $doc->createElement("poco:urls");
+ XML::addElement($doc, $urls, "poco:type", "homepage");
+ XML::addElement($doc, $urls, "poco:value", $profile["homepage"]);
+ XML::addElement($doc, $urls, "poco:primary", "true");
+ $author->appendChild($urls);
+ }
- if (count($profile)) {
- XML::addElement($doc, $author, "followers", "", array("url" => System::baseUrl()."/viewcontacts/".$owner["nick"]));
- XML::addElement($doc, $author, "statusnet:profile_info", "", array("local_id" => $owner["uid"]));
- }
+ XML::addElement($doc, $author, "followers", "", ["url" => System::baseUrl()."/viewcontacts/".$owner["nick"]]);
+ XML::addElement($doc, $author, "statusnet:profile_info", "", ["local_id" => $owner["uid"]]);
- if ($profile["publish"]) {
- XML::addElement($doc, $author, "mastodon:scope", "public");
+ if ($profile["publish"]) {
+ XML::addElement($doc, $author, "mastodon:scope", "public");
+ }
*/
private static function entry($doc, $item, $owner, $toplevel = false)
{
*/
private static function entry($doc, $item, $owner, $toplevel = false)
{
$repeated_guid = self::getResharedGuid($item);
if ($repeated_guid != "") {
$xml = self::reshareEntry($doc, $item, $owner, $repeated_guid, $toplevel);
$repeated_guid = self::getResharedGuid($item);
if ($repeated_guid != "") {
$xml = self::reshareEntry($doc, $item, $owner, $repeated_guid, $toplevel);
if ($item["verb"] == ACTIVITY_LIKE) {
return self::likeEntry($doc, $item, $owner, $toplevel);
if ($item["verb"] == ACTIVITY_LIKE) {
return self::likeEntry($doc, $item, $owner, $toplevel);
return self::followEntry($doc, $item, $owner, $toplevel);
} else {
return self::noteEntry($doc, $item, $owner, $toplevel);
return self::followEntry($doc, $item, $owner, $toplevel);
} else {
return self::noteEntry($doc, $item, $owner, $toplevel);
$source = $doc->createElement("source");
XML::addElement($doc, $source, "id", $contact["poll"]);
XML::addElement($doc, $source, "title", $contact["name"]);
$source = $doc->createElement("source");
XML::addElement($doc, $source, "id", $contact["poll"]);
XML::addElement($doc, $source, "title", $contact["name"]);
- XML::addElement($doc, $source, "link", "", array("rel" => "alternate", "type" => "text/html", "href" => $contact["alias"]));
- XML::addElement($doc, $source, "link", "", array("rel" => "self", "type" => "application/atom+xml", "href" => $contact["poll"]));
+ XML::addElement($doc, $source, "link", "", ["rel" => "alternate", "type" => "text/html", "href" => $contact["alias"]]);
+ XML::addElement($doc, $source, "link", "", ["rel" => "self", "type" => "application/atom+xml", "href" => $contact["poll"]]);
XML::addElement($doc, $source, "icon", $contact["photo"]);
XML::addElement($doc, $source, "icon", $contact["photo"]);
- XML::addElement($doc, $source, "updated", datetime_convert("UTC", "UTC", $contact["success_update"]."+00:00", ATOM_TIME));
+ XML::addElement($doc, $source, "updated", DateTimeFormat::utc($contact["success_update"]."+00:00", DateTimeFormat::ATOM));
- $title = self::entryHeader($doc, $entry, $owner, $toplevel);
+ $title = self::entryHeader($doc, $entry, $owner, $item, $toplevel);
$r = q(
"SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' AND NOT `private` AND `network` IN ('%s', '%s', '%s') LIMIT 1",
$r = q(
"SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' AND NOT `private` AND `network` IN ('%s', '%s', '%s') LIMIT 1",
self::entryContent($doc, $as_object, $repeated_item, $owner, "", "", false);
self::entryContent($doc, $as_object, $repeated_item, $owner, "", "", false);
- $title = self::entryHeader($doc, $entry, $owner, $toplevel);
+ $title = self::entryHeader($doc, $entry, $owner, $item, $toplevel);
$verb = NAMESPACE_ACTIVITY_SCHEMA."favorite";
self::entryContent($doc, $entry, $item, $owner, "Favorite", $verb, false);
$verb = NAMESPACE_ACTIVITY_SCHEMA."favorite";
self::entryContent($doc, $entry, $item, $owner, "Favorite", $verb, false);
XML::addElement($doc, $object, "id", $contact["alias"]);
XML::addElement($doc, $object, "title", $contact["nick"]);
XML::addElement($doc, $object, "id", $contact["alias"]);
XML::addElement($doc, $object, "title", $contact["nick"]);
XML::addElement($doc, $object, "link", "", $attributes);
XML::addElement($doc, $object, "link", "", $attributes);
XML::addElement($doc, $object, "link", "", $attributes);
XML::addElement($doc, $object, "poco:preferredUsername", $contact["nick"]);
XML::addElement($doc, $object, "link", "", $attributes);
XML::addElement($doc, $object, "poco:preferredUsername", $contact["nick"]);
- self::entryHeader($doc, $entry, $owner, $toplevel);
+ self::entryHeader($doc, $entry, $owner, $item, $toplevel);
self::entryContent($doc, $entry, $item, $owner, $title);
self::entryContent($doc, $entry, $item, $owner, $title);
- $title = self::entryHeader($doc, $entry, $owner, $toplevel);
+ $title = self::entryHeader($doc, $entry, $owner, $item, $toplevel);
XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
- private static function entryHeader($doc, &$entry, $owner, $toplevel)
+ private static function entryHeader($doc, &$entry, $owner, $item, $toplevel)
{
/// @todo Check if this title stuff is really needed (I guess not)
if (!$toplevel) {
$entry = $doc->createElement("entry");
$title = sprintf("New note by %s", $owner["nick"]);
{
/// @todo Check if this title stuff is really needed (I guess not)
if (!$toplevel) {
$entry = $doc->createElement("entry");
$title = sprintf("New note by %s", $owner["nick"]);
+
+ if ($owner['account-type'] == ACCOUNT_TYPE_COMMUNITY) {
+ $contact = self::contactEntry($item['author-link'], $owner);
+ $author = self::addAuthor($doc, $contact, false);
+ $entry->appendChild($author);
+ }
- XML::addElement($doc, $entry, "content", $body, array("type" => "html"));
+ XML::addElement($doc, $entry, "content", $body, ["type" => "html"]);
- XML::addElement($doc, $entry, "link", "", array("rel" => "alternate", "type" => "text/html",
- "href" => System::baseUrl()."/display/".$item["guid"])
+ XML::addElement($doc, $entry, "link", "", ["rel" => "alternate", "type" => "text/html",
+ "href" => System::baseUrl()."/display/".$item["guid"]]
- XML::addElement($doc, $entry, "status_net", "", array("notice_id" => $item["id"]));
+ XML::addElement($doc, $entry, "status_net", "", ["notice_id" => $item["id"]]);
}
XML::addElement($doc, $entry, "activity:verb", $verb);
}
XML::addElement($doc, $entry, "activity:verb", $verb);
- XML::addElement($doc, $entry, "published", datetime_convert("UTC", "UTC", $item["created"]."+00:00", ATOM_TIME));
- XML::addElement($doc, $entry, "updated", datetime_convert("UTC", "UTC", $item["edited"]."+00:00", ATOM_TIME));
+ XML::addElement($doc, $entry, "published", DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM));
+ XML::addElement($doc, $entry, "updated", DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM));
*/
private static function entryFooter($doc, $entry, $item, $owner, $complete = true)
{
*/
private static function entryFooter($doc, $entry, $item, $owner, $complete = true)
{
if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
$parent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `id` = %d", intval($item["parent"]));
if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
$parent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `id` = %d", intval($item["parent"]));
XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes);
XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes);
XML::addElement($doc, $entry, "link", "", $attributes);
}
XML::addElement($doc, $entry, "link", "", $attributes);
}
- XML::addElement($doc, $entry, "link", "", array("rel" => "ostatus:conversation", "href" => $conversation_href));
+ XML::addElement($doc, $entry, "link", "", ["rel" => "ostatus:conversation", "href" => $conversation_href]);
"href" => $conversation_href,
"local_id" => $item["parent"],
"href" => $conversation_href,
"local_id" => $item["parent"],
XML::addElement($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
}
XML::addElement($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
}
foreach ($mentioned as $mention) {
$newmentions[str_replace("http://", "https://", $mention)] = str_replace("http://", "https://", $mention);
$newmentions[str_replace("https://", "http://", $mention)] = str_replace("https://", "http://", $mention);
foreach ($mentioned as $mention) {
$newmentions[str_replace("http://", "https://", $mention)] = str_replace("http://", "https://", $mention);
$newmentions[str_replace("https://", "http://", $mention)] = str_replace("https://", "http://", $mention);
- $r = q(
- "SELECT `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'",
- intval($owner["uid"]),
- dbesc(normalise_link($mention))
- );
- if ($r[0]["forum"] || $r[0]["prv"]) {
+ $condition = ['uid' => $owner['uid'], 'nurl' => normalise_link($mention)];
+ $contact = dba::selectFirst('contact', ['forum', 'prv', 'self', 'contact-type'], $condition);
+ if ($contact["forum"] || $contact["prv"] || ($owner['contact-type'] == ACCOUNT_TYPE_COMMUNITY) ||
+ ($contact['self'] && ($owner['account-type'] == ACCOUNT_TYPE_COMMUNITY))) {
XML::addElement($doc, $entry, "link", "",
XML::addElement($doc, $entry, "link", "",
);
} else {
XML::addElement($doc, $entry, "link", "",
);
} else {
XML::addElement($doc, $entry, "link", "",
+ if ($owner['account-type'] == ACCOUNT_TYPE_COMMUNITY) {
+ XML::addElement($doc, $entry, "link", "", ["rel" => "mentioned",
+ "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/group",
+ "href" => $owner['url']]);
+ }
+
- XML::addElement($doc, $entry, "link", "", array("rel" => "ostatus:attention",
- "href" => "http://activityschema.org/collection/public"));
- XML::addElement($doc, $entry, "link", "", array("rel" => "mentioned",
+ XML::addElement($doc, $entry, "link", "", ["rel" => "ostatus:attention",
+ "href" => "http://activityschema.org/collection/public"]);
+ XML::addElement($doc, $entry, "link", "", ["rel" => "mentioned",
XML::addElement($doc, $entry, "mastodon:scope", "public");
}
if (count($tags)) {
foreach ($tags as $t) {
if ($t[0] != "@") {
XML::addElement($doc, $entry, "mastodon:scope", "public");
}
if (count($tags)) {
foreach ($tags as $t) {
if ($t[0] != "@") {
- XML::addElement($doc, $entry, "category", "", array("term" => $t[2]));
+ XML::addElement($doc, $entry, "category", "", ["term" => $t[2]]);
- "SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`
+ "SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type`
FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
WHERE `contact`.`self` AND `user`.`nickname` = ? LIMIT 1",
$owner_nick
FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
WHERE `contact`.`self` AND `user`.`nickname` = ? LIMIT 1",
$owner_nick
- $check_date = datetime_convert('UTC', 'UTC', $last_update, 'Y-m-d H:i:s');
- $authorid = Contact::getIdForURL($owner["url"], 0);
+ $check_date = DateTimeFormat::utc($last_update);
+ $authorid = Contact::getIdForURL($owner["url"], 0, true);
$items = q(
"SELECT `item`.*, `item`.`id` AS `item_id` FROM `item` USE INDEX (`uid_contactid_created`)
STRAIGHT_JOIN `thread` ON `thread`.`iid` = `item`.`parent`
WHERE `item`.`uid` = %d
$items = q(
"SELECT `item`.*, `item`.`id` AS `item_id` FROM `item` USE INDEX (`uid_contactid_created`)
STRAIGHT_JOIN `thread` ON `thread`.`iid` = `item`.`parent`
WHERE `item`.`uid` = %d
AND `thread`.`network` IN ('%s', '%s')
$sql_extra
ORDER BY `item`.`created` DESC LIMIT %d",
intval($owner["uid"]),
AND `thread`.`network` IN ('%s', '%s')
$sql_extra
ORDER BY `item`.`created` DESC LIMIT %d",
intval($owner["uid"]),
Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR);
logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created, LOGGER_DEBUG);
Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR);
logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created, LOGGER_DEBUG);