Merge branch 'develop' of https://github.com/friendica/friendica into develop

This commit is contained in:
Ralf Thees 2018-10-18 10:42:10 +02:00
commit fdac992b6b
8 changed files with 129 additions and 156 deletions

View file

@ -140,6 +140,10 @@ disable_url_validation = false
; Disable the exposition check against the remote haveibeenpwned API on password change. ; Disable the exposition check against the remote haveibeenpwned API on password change.
disable_password_exposed = false disable_password_exposed = false
; disable_polling (Boolean)
; Disable the polling of DFRN and OStatus contacts through onepoll.php.
disable_polling = false
; dlogfile (Path) ; dlogfile (Path)
; location of the developer log file. ; location of the developer log file.
dlogfile = dlogfile =

View file

@ -1015,11 +1015,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
$profile = $contact["url"]; $profile = $contact["url"];
$alias = $contact["alias"]; $alias = $contact["alias"];
$newname = $contact["nick"]; $newname = defaults($contact, "name", $contact["nick"]);
if (($newname == "") || !in_array($contact["network"], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::TWITTER, Protocol::STATUSNET])) {
$newname = $contact["name"];
}
} }
//if there is an url for this persons profile //if there is an url for this persons profile

View file

@ -859,187 +859,140 @@ class BBCode extends BaseObject
} }
/** /**
* Processes [share] tags * This function converts a [share] block to text according to a provided callback function whose signature is:
* *
* Note: Can produce a [bookmark] tag in the output * function(array $attributes, array $author_contact, string $content, boolean $is_quote_share): string
* *
* @brief Processes [share] tags * Where:
* @param array $share preg_match_callback result array * - $attributes is an array of attributes of the [share] block itself. Missing keys will be completed by the contact
* @param bool|int $simplehtml * data lookup
* @return string * - $author_contact is a contact record array
* - $content is the inner content of the [share] block
* - $is_quote_share indicates whether there's any content before the [share] block
* - Return value is the string that should replace the [share] block in the provided text
*
* This function is intended to be used by addon connector to format a share block like the target network is expecting it.
*
* @param string $text A BBCode string
* @param callable $callback
* @return string The BBCode string with all [share] blocks replaced
*/ */
private static function convertShare($share, $simplehtml) public static function convertShare($text, callable $callback)
{ {
$attributes = $share[2]; $return = preg_replace_callback(
"/(.*?)\[share(.*?)\](.*?)\[\/share\]/ism",
function ($match) use ($callback) {
$attribute_string = $match[2];
$author = ""; $attributes = [];
preg_match("/author='(.*?)'/ism", $attributes, $matches); foreach(['author', 'profile', 'avatar', 'link', 'posted'] as $field) {
if (x($matches, 1)) { preg_match("/$field=(['\"])(.+?)\\1/ism", $attribute_string, $matches);
$author = html_entity_decode($matches[1], ENT_QUOTES, 'UTF-8'); $attributes[$field] = html_entity_decode(defaults($matches, 2, ''), ENT_QUOTES, 'UTF-8');
}
preg_match('/author="(.*?)"/ism', $attributes, $matches);
if (x($matches, 1)) {
$author = $matches[1];
}
$profile = "";
preg_match("/profile='(.*?)'/ism", $attributes, $matches);
if (x($matches, 1)) {
$profile = $matches[1];
}
preg_match('/profile="(.*?)"/ism', $attributes, $matches);
if (x($matches, 1)) {
$profile = $matches[1];
}
$avatar = "";
preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
if (x($matches, 1)) {
$avatar = $matches[1];
}
preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
if (x($matches, 1)) {
$avatar = $matches[1];
}
$link = "";
preg_match("/link='(.*?)'/ism", $attributes, $matches);
if (x($matches, 1)) {
$link = $matches[1];
}
preg_match('/link="(.*?)"/ism', $attributes, $matches);
if (x($matches, 1)) {
$link = $matches[1];
}
$posted = "";
preg_match("/posted='(.*?)'/ism", $attributes, $matches);
if (x($matches, 1)) {
$posted = $matches[1];
}
preg_match('/posted="(.*?)"/ism', $attributes, $matches);
if (x($matches, 1)) {
$posted = $matches[1];
} }
// We only call this so that a previously unknown contact can be added. // We only call this so that a previously unknown contact can be added.
// This is important for the function "Model\Contact::getDetailsByURL()". // This is important for the function "Model\Contact::getDetailsByURL()".
// This function then can fetch an entry from the contact table. // This function then can fetch an entry from the contact table.
Contact::getIdForURL($profile, 0, true); Contact::getIdForURL($attributes['profile'], 0, true);
$data = Contact::getDetailsByURL($profile); $author_contact = Contact::getDetailsByURL($attributes['profile']);
$author_contact['addr'] = defaults($author_contact, 'addr' , Protocol::getAddrFromProfileUrl($attributes['profile']));
if (x($data, "name") && x($data, "addr")) { $attributes['author'] = defaults($author_contact, 'name' , $attributes['author']);
$userid_compact = $data["name"] . " (" . $data["addr"] . ")"; $attributes['avatar'] = defaults($author_contact, 'micro', $attributes['avatar']);
} else { $attributes['profile'] = defaults($author_contact, 'url' , $attributes['profile']);
$userid_compact = Protocol::getAddrFromProfileUrl($profile, $author);
if ($attributes['avatar']) {
$attributes['avatar'] = ProxyUtils::proxifyUrl($attributes['avatar'], false, ProxyUtils::SIZE_THUMB);
} }
if (x($data, "addr")) { return $callback($attributes, $author_contact, $match[3], trim($match[1]) != '');
$userid = $data["addr"]; },
} else { $text
$userid = Protocol::formatMention($profile, $author); );
return $return;
} }
if (x($data, "name")) { /**
$author = $data["name"]; * Default [share] tag conversion callback
} *
* Note: Can produce a [bookmark] tag in the output
if (x($data, "micro")) { *
$avatar = $data["micro"]; * @see BBCode::convertShare()
} * @param array $attributes [share] block attribute values
* @param array $author_contact Contact row of the shared author
$preshare = trim($share[1]); * @param string $content Inner content of the [share] block
if ($preshare != "") { * @param boolean $is_quote_share Whether there is content before the [share] block
$preshare .= "<br />"; * @param integer $simplehtml Mysterious integer value depending on the target network/formatting style
} * @return string
*/
private static function convertShareCallback(array $attributes, array $author_contact, $content, $is_quote_share, $simplehtml)
{
$mention = Protocol::formatMention($attributes['profile'], $attributes['author']);
switch ($simplehtml) { switch ($simplehtml) {
case 1: case 1:
$text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . ' <a href="' . $profile . '">' . $userid . "</a>: <br />»" . $share[3] . "«"; $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' <a href="' . $attributes['profile'] . '">' . $mention . '</a>: </p>' . "\n" . '«' . $content . '»';
break; break;
case 2: case 2:
$text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . ' ' . $userid_compact . ": <br />" . $share[3]; $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ': </p>' . "\n" . $content;
break; break;
case 3: // Diaspora case 3: // Diaspora
$headline = '<b>' . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . $userid . ':</b><br />'; $headline = '<p><b>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . $mention . ':</b></p>' . "\n";
$text = trim($share[1]); if (stripos(normalise_link($attributes['link']), 'http://twitter.com/') === 0) {
$text = ($is_quote_share? '<hr />' : '') . '<p><a href="' . $attributes['link'] . '">' . $attributes['link'] . '</a></p>' . "\n";
if ($text != "") {
$text .= "<hr />";
}
if (stripos(normalise_link($link), 'http://twitter.com/') === 0) {
$text .= '<br /><a href="' . $link . '">' . $link . '</a>';
} else { } else {
$text .= $headline . '<blockquote>' . trim($share[3]) . "</blockquote><br />"; $text = ($is_quote_share? '<hr />' : '') . $headline . '<blockquote>' . trim($content) . '</blockquote>' . "\n";
if ($link != "") { if ($attributes['link'] != '') {
$text .= '<br /><a href="' . $link . '">[l]</a>'; $text .= '<p><a href="' . $attributes['link'] . '">[l]</a></p>' . "\n";
} }
} }
break; break;
case 4: case 4:
$headline = '<br /><b>' . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8'); $headline = '<p><b>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8');
$headline .= L10n::t('<a href="%1$s" target="_blank">%2$s</a> %3$s', $link, $userid, $posted); $headline .= L10n::t('<a href="%1$s" target="_blank">%2$s</a> %3$s', $attributes['link'], $mention, $attributes['posted']);
$headline .= ":</b><br />"; $headline .= ':</b></p>' . "\n";
$text = trim($share[1]); $text = ($is_quote_share? '<hr />' : '') . $headline . '<blockquote class="shared_content">' . trim($content) . '</blockquote>' . "\n";
if ($text != "") {
$text .= "<hr />";
}
$text .= $headline . '<blockquote class="shared_content">' . trim($share[3]) . "</blockquote><br />";
break; break;
case 5: case 5:
$text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . ' ' . $userid_compact . ": <br />" . $share[3]; $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ': </p>' . "\n" . $content;
break; break;
case 7: // statusnet/GNU Social case 7: // statusnet/GNU Social
$text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . " @" . $userid_compact . ": " . $share[3]; $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' @' . $author_contact['addr'] . ': ' . $content . '</p>' . "\n";
break;
case 8: // twitter
$text = $preshare . "RT @" . $userid_compact . ": " . $share[3];
break; break;
case 9: // Google+ case 9: // Google+
$text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . ' ' . $userid_compact . ": <br />" . $share[3]; $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ': </p>' . "\n";
$text .= '<p>' . $content . '</p>' . "\n";
if ($link != "") { if ($attributes['link'] != '') {
$text .= "<br /><br />" . $link; $text .= '<p>' . $attributes['link'] . '</p>';
} }
break; break;
default: default:
// Transforms quoted tweets in rich attachments to avoid nested tweets // Transforms quoted tweets in rich attachments to avoid nested tweets
if (stripos(normalise_link($link), 'http://twitter.com/') === 0 && OEmbed::isAllowedURL($link)) { if (stripos(normalise_link($attributes['link']), 'http://twitter.com/') === 0 && OEmbed::isAllowedURL($attributes['link'])) {
try { try {
$oembed = OEmbed::getHTML($link, $preshare); $text = ($is_quote_share? '<br />' : '') . OEmbed::getHTML($attributes['link']);
} catch (Exception $e) { } catch (Exception $e) {
$oembed = sprintf('[bookmark=%s]%s[/bookmark]', $link, $preshare); $text = ($is_quote_share? '<br />' : '') . sprintf('[bookmark=%s]%s[/bookmark]', $attributes['link'], $content);
} }
$text = $preshare . $oembed;
} else { } else {
$text = trim($share[1]) . "\n"; $text = ($is_quote_share? "\n" : '');
$avatar = ProxyUtils::proxifyUrl($avatar, false, ProxyUtils::SIZE_THUMB);
$tpl = get_markup_template('shared_content.tpl'); $tpl = get_markup_template('shared_content.tpl');
$text .= replace_macros($tpl, [ $text .= replace_macros($tpl, [
'$profile' => $profile, '$profile' => $attributes['profile'],
'$avatar' => $avatar, '$avatar' => $attributes['avatar'],
'$author' => $author, '$author' => $attributes['author'],
'$link' => $link, '$link' => $attributes['link'],
'$posted' => $posted, '$posted' => $attributes['posted'],
'$content' => trim($share[3]) '$content' => trim($content)
]); ]);
} }
break; break;
@ -1621,10 +1574,12 @@ class BBCode extends BaseObject
$text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '<img src="$1" alt="' . L10n::t('Image/photo') . '" />', $text); $text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '<img src="$1" alt="' . L10n::t('Image/photo') . '" />', $text);
// Shared content // Shared content
$text = preg_replace_callback("/(.*?)\[share(.*?)\](.*?)\[\/share\]/ism", $text = self::convertShare(
function ($match) use ($simple_html) { $text,
return self::convertShare($match, $simple_html); function (array $attributes, array $author_contact, $content, $is_quote_share) use ($simple_html) {
}, $text); return self::convertShareCallback($attributes, $author_contact, $content, $is_quote_share, $simple_html);
}
);
$text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '<br/><img src="' .System::baseUrl() . '/images/lock_icon.gif" alt="' . L10n::t('Encrypted content') . '" title="' . L10n::t('Encrypted content') . '" /><br />', $text); $text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '<br/><img src="' .System::baseUrl() . '/images/lock_icon.gif" alt="' . L10n::t('Encrypted content') . '" title="' . L10n::t('Encrypted content') . '" /><br />', $text);
$text = preg_replace("/\[crypt(.*?)\](.*?)\[\/crypt\]/ism", '<br/><img src="' .System::baseUrl() . '/images/lock_icon.gif" alt="' . L10n::t('Encrypted content') . '" title="' . '$1' . ' ' . L10n::t('Encrypted content') . '" /><br />', $text); $text = preg_replace("/\[crypt(.*?)\](.*?)\[\/crypt\]/ism", '<br/><img src="' .System::baseUrl() . '/images/lock_icon.gif" alt="' . L10n::t('Encrypted content') . '" title="' . '$1' . ' ' . L10n::t('Encrypted content') . '" /><br />', $text);

View file

@ -108,6 +108,13 @@ class Protocol
} }
} }
// Mastodon, Pleroma
if (preg_match('=https?://(.+?)/users/(.+)=ism', $profile_url, $matches)
|| preg_match('=https?://(.+?)/@(.+)=ism', $profile_url, $matches)
) {
return self::ACTIVITYPUB;
}
// pumpio (http://host.name/user) // pumpio (http://host.name/user)
if (preg_match('=https?://([\.\w]+)/([\.\w]+)$=ism', $profile_url, $matches)) { if (preg_match('=https?://([\.\w]+)/([\.\w]+)$=ism', $profile_url, $matches)) {
return self::PUMPIO; return self::PUMPIO;

View file

@ -1021,10 +1021,11 @@ class Contact extends BaseObject
* @param integer $uid The user id for the contact (0 = public contact) * @param integer $uid The user id for the contact (0 = public contact)
* @param boolean $no_update Don't update the contact * @param boolean $no_update Don't update the contact
* @param array $default Default value for creating the contact when every else fails * @param array $default Default value for creating the contact when every else fails
* @param boolean $in_loop Internally used variable to prevent an endless loop
* *
* @return integer Contact ID * @return integer Contact ID
*/ */
public static function getIdForURL($url, $uid = 0, $no_update = false, $default = []) public static function getIdForURL($url, $uid = 0, $no_update = false, $default = [], $in_loop = false)
{ {
logger("Get contact data for url " . $url . " and user " . $uid . " - " . System::callstack(), LOGGER_DEBUG); logger("Get contact data for url " . $url . " and user " . $uid . " - " . System::callstack(), LOGGER_DEBUG);
@ -1138,8 +1139,8 @@ class Contact extends BaseObject
} }
} }
if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url)) { if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url) && !$in_loop) {
$contact_id = self::getIdForURL($data["alias"], $uid, true); $contact_id = self::getIdForURL($data["alias"], $uid, true, $default, true);
} }
$url = $data["url"]; $url = $data["url"];

View file

@ -63,7 +63,13 @@ class ActivityPub
return false; return false;
} }
return json_decode($curlResult->getBody(), true); $content = json_decode($curlResult->getBody(), true);
if (empty($content) || !is_array($content)) {
return false;
}
return $content;
} }
/** /**

View file

@ -272,7 +272,7 @@ class Processor
$activity['cc'] = defaults($object, 'cc', []); $activity['cc'] = defaults($object, 'cc', []);
$activity['actor'] = $child['author']; $activity['actor'] = $child['author'];
$activity['object'] = $object; $activity['object'] = $object;
$activity['published'] = $object['published']; $activity['published'] = defaults($object, 'published', $child['published']);
$activity['type'] = 'Create'; $activity['type'] = 'Create';
$ldactivity = JsonLD::compact($activity); $ldactivity = JsonLD::compact($activity);

View file

@ -148,6 +148,10 @@ class OnePoll
} }
} }
if (!in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) && Config::get('system', 'disable_polling')) {
return;
}
if ($importer_uid == 0) { if ($importer_uid == 0) {
logger('Ignore public contacts'); logger('Ignore public contacts');
@ -345,7 +349,7 @@ class OnePoll
} elseif ($contact['network'] === Protocol::MAIL) { } elseif ($contact['network'] === Protocol::MAIL) {
logger("Mail: Fetching for ".$contact['addr'], LOGGER_DEBUG); logger("Mail: Fetching for ".$contact['addr'], LOGGER_DEBUG);
$mail_disabled = ((function_exists('imap_open') && (! Config::get('system', 'imap_disabled'))) ? 0 : 1); $mail_disabled = ((function_exists('imap_open') && !Config::get('system', 'imap_disabled')) ? 0 : 1);
if ($mail_disabled) { if ($mail_disabled) {
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
@ -541,7 +545,7 @@ class OnePoll
if ($datarray['parent-uri'] === $datarray['uri']) { if ($datarray['parent-uri'] === $datarray['uri']) {
$datarray['private'] = 1; $datarray['private'] = 1;
} }
if (($contact['network'] === Protocol::MAIL) && (!PConfig::get($importer_uid, 'system', 'allow_public_email_replies'))) { if (($contact['network'] === Protocol::MAIL) && !PConfig::get($importer_uid, 'system', 'allow_public_email_replies')) {
$datarray['private'] = 1; $datarray['private'] = 1;
$datarray['allow_cid'] = '<' . $contact['id'] . '>'; $datarray['allow_cid'] = '<' . $contact['id'] . '>';
} }