Merge remote-tracking branch 'upstream/2021.06-rc' into http-input-data

This commit is contained in:
Michael 2021-05-23 20:17:50 +00:00
commit a69e128fe4
18 changed files with 101 additions and 73 deletions

View file

@ -128,6 +128,7 @@ function dfrn_poll_init(App $a)
$_SESSION['visitor_handle'] = $r[0]['addr'];
$_SESSION['visitor_visiting'] = $r[0]['uid'];
$_SESSION['my_url'] = $r[0]['url'];
$_SESSION['remote_comment'] = $r[0]['subscribe'];
Session::setVisitorsContacts();
@ -497,8 +498,10 @@ function dfrn_poll_content(App $a)
$_SESSION['authenticated'] = 1;
$_SESSION['visitor_id'] = $r[0]['id'];
$_SESSION['visitor_home'] = $r[0]['url'];
$_SESSION['visitor_handle'] = $r[0]['addr'];
$_SESSION['visitor_visiting'] = $r[0]['uid'];
$_SESSION['my_url'] = $r[0]['url'];
$_SESSION['remote_comment'] = $r[0]['subscribe'];
Session::setVisitorsContacts();

View file

@ -34,6 +34,7 @@ use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Core\Theme;
use Friendica\Database\Database;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
use Friendica\Network\HTTPException;
@ -464,6 +465,11 @@ class App
if (Core\Session::get('visitor_home') != $_GET["zrl"]) {
Core\Session::set('my_url', $_GET['zrl']);
Core\Session::set('authenticated', 0);
$remote_contact = Contact::getByURL($_GET['zrl'], false, ['subscribe']);
if (!empty($remote_contact['subscribe'])) {
$_SESSION['remote_comment'] = $remote_contact['subscribe'];
}
}
Model\Profile::zrlInit($this);

View file

@ -127,8 +127,8 @@ class TagCloud
private static function tagCalc(array $arr)
{
$tags = [];
$min = 1e9;
$max = -1e9;
$min = 1000000000.0;
$max = -1000000000.0;
$x = 0;
if (!$arr) {
@ -145,7 +145,7 @@ class TagCloud
}
usort($tags, 'self::tagsSort');
$range = max(.01, $max - $min) * 1.0001;
$range = max(0.01, $max - $min) * 1.0001;
for ($x = 0; $x < count($tags); $x ++) {
$tags[$x][2] = 1 + floor(9 * ($tags[$x][1] - $min) / $range);

View file

@ -465,7 +465,7 @@ class Installer
$status = $this->checkFunction('proc_open',
DI::l10n()->t('Program execution functions'),
DI::l10n()->t('Error: Program execution functions required but not enabled.'),
DI::l10n()->t('Error: Program execution functions (proc_open) required but not enabled.'),
true
);
$returnVal = $returnVal ? $status : false;

View file

@ -2739,9 +2739,10 @@ class Item
*
* @param string $body
* @param string $url
* @param int $type
* @return bool
*/
public static function containsLink(string $body, string $url)
public static function containsLink(string $body, string $url, int $type = 0)
{
// Make sure that for example site parameters aren't used when testing if the link is contained in the body
$urlparts = parse_url($url);
@ -2749,6 +2750,12 @@ class Item
unset($urlparts['fragment']);
$url = Network::unparseURL($urlparts);
// Remove media links to only search in embedded content
// @todo Check images for image link, audio for audio links, ...
if (in_array($type, [Post\Media::AUDIO, Post\Media::VIDEO, Post\Media::IMAGE])) {
$body = preg_replace("/\[url=[^\[\]]*\](.*)\[\/url\]/Usi", ' $1 ', $body);
}
if (strpos($body, $url)) {
return true;
}
@ -2777,7 +2784,7 @@ class Item
// @todo In the future we should make a single for the template engine with all media in it. This allows more flexibilty.
foreach ($attachments['visual'] as $attachment) {
if (self::containsLink($item['body'], $attachment['url'])) {
if (self::containsLink($item['body'], $attachment['url'], $attachment['type'])) {
continue;
}
@ -2955,7 +2962,7 @@ class Item
// @todo Use a template
$rendered = BBCode::convertAttachment('', BBCode::INTERNAL, false, $data);
} elseif (!self::containsLink($content, $data['url'])) {
} elseif (!self::containsLink($content, $data['url'], Post\Media::HTML)) {
$rendered = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/link.tpl'), [
'$url' => $data['url'],
'$title' => $data['title'],

View file

@ -36,15 +36,14 @@ use Friendica\Worker\Delivery;
class Mail
{
/**
* Insert received private message
* Insert private message
*
* @param array $msg
* @param bool $notifiction
* @return int|boolean Message ID or false on error
*/
public static function insert($msg)
public static function insert($msg, $notifiction = true)
{
$user = User::getById($msg['uid']);
if (!isset($msg['reply'])) {
$msg['reply'] = DBA::exists('mail', ['parent-uri' => $msg['parent-uri']]);
}
@ -63,6 +62,10 @@ class Mail
$msg['created'] = (!empty($msg['created']) ? DateTimeFormat::utc($msg['created']) : DateTimeFormat::utcNow());
$msg['author-id'] = Contact::getIdForURL($msg['from-url'], 0, false);
$msg['uri-id'] = ItemURI::insert(['uri' => $msg['uri'], 'guid' => $msg['guid']]);
$msg['parent-uri-id'] = ItemURI::getIdByURI($msg['parent-uri']);
DBA::lock('mail');
if (DBA::exists('mail', ['uri' => $msg['uri'], 'uid' => $msg['uid']])) {
@ -71,12 +74,8 @@ class Mail
return false;
}
$msg['author-id'] = Contact::getIdForURL($msg['from-url'], 0, false);
$msg['uri-id'] = ItemURI::insert(['uri' => $msg['uri'], 'guid' => $msg['guid']]);
$msg['parent-uri-id'] = ItemURI::getIdByURI($msg['parent-uri']);
if ($msg['reply']) {
$reply = DBA::selectFirst('mail', ['uri', 'uri-id'], ['parent-uri' => $mail['parent-uri'], 'reply' => false]);
$reply = DBA::selectFirst('mail', ['uri', 'uri-id'], ['parent-uri' => $msg['parent-uri'], 'reply' => false]);
$msg['thr-parent'] = $reply['uri'];
$msg['thr-parent-id'] = $reply['uri-id'];
@ -95,19 +94,22 @@ class Mail
DBA::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $msg['convid']]);
}
// send notifications.
$notif_params = [
'type' => Notification\Type::MAIL,
'otype' => Notification\ObjectType::MAIL,
'verb' => Activity::POST,
'uid' => $user['uid'],
'cid' => $msg['contact-id'],
'link' => DI::baseUrl() . '/message/' . $msg['id'],
];
if ($notifiction) {
$user = User::getById($msg['uid']);
// send notifications.
$notif_params = [
'type' => Notification\Type::MAIL,
'otype' => Notification\ObjectType::MAIL,
'verb' => Activity::POST,
'uid' => $user['uid'],
'cid' => $msg['contact-id'],
'link' => DI::baseUrl() . '/message/' . $msg['id'],
];
notification($notif_params);
notification($notif_params);
Logger::info('Mail is processed, notification was sent.', ['id' => $msg['id'], 'uri' => $msg['uri']]);
Logger::info('Mail is processed, notification was sent.', ['id' => $msg['id'], 'uri' => $msg['uri']]);
}
return $msg['id'];
}
@ -195,9 +197,7 @@ class Mail
$replyto = $convuri;
}
$post_id = null;
$success = DBA::insert(
'mail',
$post_id = self::insert(
[
'uid' => local_user(),
'guid' => $guid,
@ -214,13 +214,9 @@ class Mail
'uri' => $uri,
'parent-uri' => $replyto,
'created' => DateTimeFormat::utcNow()
]
], false
);
if ($success) {
$post_id = DBA::lastInsertId();
}
/**
*
* When a photo was uploaded into the message using the (profile wall) ajax
@ -301,8 +297,7 @@ class Mail
return -4;
}
DBA::insert(
'mail',
self::insert(
[
'uid' => $recipient['uid'],
'guid' => $guid,
@ -320,7 +315,7 @@ class Mail
'parent-uri' => $me['url'],
'created' => DateTimeFormat::utcNow(),
'unknown' => 1
]
], false
);
return 0;

View file

@ -351,7 +351,7 @@ class Media
foreach ($attachments as $attachment) {
// Only store attachments that are part of the unshared body
if (strpos($unshared_body, $attachment['url']) !== false) {
if (Item::containsLink($unshared_body, $attachment['url'], $attachment['type'])) {
self::insert($attachment);
}
}
@ -600,7 +600,7 @@ class Media
$body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body);
foreach (self::getByURIId($uriid, [self::IMAGE, self::AUDIO, self::VIDEO]) as $media) {
if (Item::containsLink($body, $media['url'])) {
if (Item::containsLink($body, $media['url'], $media['type'])) {
continue;
}

View file

@ -41,6 +41,8 @@ class PublicTimeline extends BaseApi
*/
public static function rawContent(array $parameters = [])
{
$uid = self::getCurrentUserID();
$request = self::getRequest([
'local' => false, // Show only local statuses? Defaults to false.
'remote' => false, // Show only remote statuses? Defaults to false.
@ -88,7 +90,12 @@ class PublicTimeline extends BaseApi
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]);
}
$items = Post::selectForUser(0, ['uri-id', 'uid'], $condition, $params);
if (!empty($uid)) {
$condition = DBA::mergeConditions($condition,
["NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `parent-author-id` AND (`blocked` OR `ignored`))", $uid]);
}
$items = Post::selectForUser($uid, ['uri-id', 'uid'], $condition, $params);
$statuses = [];
while ($item = Post::fetch($items)) {

View file

@ -70,7 +70,7 @@ class HTTPRequest implements IHTTPRequest
*
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function get(string $url, array $opts = [], int &$redirects = 0)
public function get(string $url, array $opts = [], &$redirects = 0)
{
$stamp1 = microtime(true);
@ -222,7 +222,7 @@ class HTTPRequest implements IHTTPRequest
*
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function post(string $url, $params, array $headers = [], int $timeout = 0, int &$redirects = 0)
public function post(string $url, $params, array $headers = [], int $timeout = 0, &$redirects = 0)
{
$stamp1 = microtime(true);
@ -447,7 +447,7 @@ class HTTPRequest implements IHTTPRequest
*
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function fetch(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0)
public function fetch(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '', &$redirects = 0)
{
$ret = $this->fetchFull($url, $timeout, $accept_content, $cookiejar, $redirects);
@ -461,7 +461,7 @@ class HTTPRequest implements IHTTPRequest
*
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function fetchFull(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0)
public function fetchFull(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '', &$redirects = 0)
{
return $this->get(
$url,

View file

@ -114,7 +114,12 @@ class Status extends BaseDataTransferObject
$this->visibility = $visibility[$item['private']];
$languages = json_decode($item['language'], true);
$this->language = is_array($languages) ? array_key_first($languages) : null;
if (is_array($languages)) {
reset($languages);
$this->language = key($languages);
} else {
$this->language = null;
}
$this->uri = $item['uri'];
$this->url = $item['plink'] ?? null;

View file

@ -401,9 +401,13 @@ class Post
}
// Fetching of Diaspora posts doesn't always work. There are issues with reshares and possibly comments
if (($item['network'] != Protocol::DIASPORA) && empty($comment) && !empty(Session::get('remote_comment'))) {
if (!local_user() && ($item['network'] != Protocol::DIASPORA) && !empty(Session::get('remote_comment'))) {
$remote_comment = [DI::l10n()->t('Comment this item on your system'), DI::l10n()->t('Remote comment'),
str_replace('{uri}', urlencode($item['uri']), Session::get('remote_comment'))];
// Ensure to either display the remote comment or the local activities
$buttons = [];
$comment_html = '';
} else {
$remote_comment = '';
}

View file

@ -103,7 +103,7 @@ class InstallerTest extends MockedTest
$this->mockL10nT('File Information PHP module', 1);
$this->mockL10nT('Error: File Information PHP module required but not installed.', 1);
$this->mockL10nT('Program execution functions', 1);
$this->mockL10nT('Error: Program execution functions required but not enabled.', 1);
$this->mockL10nT('Error: Program execution functions (proc_open) required but not enabled.', 1);
}
private function assertCheckExist($position, $title, $help, $status, $required, $assertionArray)
@ -248,7 +248,7 @@ class InstallerTest extends MockedTest
self::assertFalse($install->checkFunctions());
self::assertCheckExist(9,
'Program execution functions',
'Error: Program execution functions required but not enabled.',
'Error: Program execution functions (proc_open) required but not enabled.',
false,
true,
$install->getChecks());

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2021.06-rc\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-05-21 18:18+0000\n"
"POT-Creation-Date: 2021-05-23 07:49+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -1117,11 +1117,11 @@ msgstr ""
msgid "Invalid profile URL."
msgstr ""
#: mod/dfrn_request.php:355 src/Model/Contact.php:2159
#: mod/dfrn_request.php:355 src/Model/Contact.php:2164
msgid "Disallowed profile URL."
msgstr ""
#: mod/dfrn_request.php:361 src/Model/Contact.php:2164
#: mod/dfrn_request.php:361 src/Model/Contact.php:2169
#: src/Module/Friendica.php:80
msgid "Blocked domain"
msgstr ""
@ -4072,7 +4072,8 @@ msgid "Program execution functions"
msgstr ""
#: src/Core/Installer.php:468
msgid "Error: Program execution functions required but not enabled."
msgid ""
"Error: Program execution functions (proc_open) required but not enabled."
msgstr ""
#: src/Core/Installer.php:474
@ -4645,60 +4646,60 @@ msgstr ""
msgid "Forum"
msgstr ""
#: src/Model/Contact.php:2169
#: src/Model/Contact.php:2174
msgid "Connect URL missing."
msgstr ""
#: src/Model/Contact.php:2178
#: src/Model/Contact.php:2183
msgid ""
"The contact could not be added. Please check the relevant network "
"credentials in your Settings -> Social Networks page."
msgstr ""
#: src/Model/Contact.php:2219
#: src/Model/Contact.php:2224
msgid ""
"This site is not configured to allow communications with other networks."
msgstr ""
#: src/Model/Contact.php:2220 src/Model/Contact.php:2233
#: src/Model/Contact.php:2225 src/Model/Contact.php:2238
msgid "No compatible communication protocols or feeds were discovered."
msgstr ""
#: src/Model/Contact.php:2231
#: src/Model/Contact.php:2236
msgid "The profile address specified does not provide adequate information."
msgstr ""
#: src/Model/Contact.php:2236
#: src/Model/Contact.php:2241
msgid "An author or name was not found."
msgstr ""
#: src/Model/Contact.php:2239
#: src/Model/Contact.php:2244
msgid "No browser URL could be matched to this address."
msgstr ""
#: src/Model/Contact.php:2242
#: src/Model/Contact.php:2247
msgid ""
"Unable to match @-style Identity Address with a known protocol or email "
"contact."
msgstr ""
#: src/Model/Contact.php:2243
#: src/Model/Contact.php:2248
msgid "Use mailto: in front of address to force email check."
msgstr ""
#: src/Model/Contact.php:2249
#: src/Model/Contact.php:2254
msgid ""
"The profile address specified belongs to a network which has been disabled "
"on this site."
msgstr ""
#: src/Model/Contact.php:2254
#: src/Model/Contact.php:2259
msgid ""
"Limited profile. This person will be unable to receive direct/personal "
"notifications from you."
msgstr ""
#: src/Model/Contact.php:2313
#: src/Model/Contact.php:2318
msgid "Unable to retrieve contact information."
msgstr ""
@ -4845,7 +4846,7 @@ msgstr ""
msgid "View on separate page"
msgstr ""
#: src/Model/Mail.php:120 src/Model/Mail.php:258
#: src/Model/Mail.php:134 src/Model/Mail.php:272
msgid "[no subject]"
msgstr ""