Merge branch 'friendica:develop' into mastodon-api-reshare-fixes

This commit is contained in:
Hank G 2023-08-13 15:42:22 -04:00 committed by GitHub
commit 09a612670a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
116 changed files with 829 additions and 680 deletions

View file

@ -76,16 +76,9 @@ class Statuses extends BaseApi
throw new HTTPException\NotFoundException('Item with URI ID ' . $this->parameters['id'] . ' not found for user ' . $uid . '.');
}
// The imput is defined as text. So we can use Markdown for some enhancements
$body = Markdown::toBBCode($request['status']);
if (DI::pConfig()->get($uid, 'system', 'api_auto_attach', false) && preg_match("/\[url=[^\[\]]*\](.*)\[\/url\]\z/ism", $body, $matches)) {
$body = preg_replace("/\[url=[^\[\]]*\].*\[\/url\]\z/ism", PageInfo::getFooterFromUrl($matches[1]), $body);
}
$item['title'] = '';
$item['uid'] = $post['uid'];
$item['body'] = $body;
$item['body'] = $this->formatStatus($request['status'], $uid);
$item['network'] = $post['network'];
$item['gravity'] = $post['gravity'];
$item['verb'] = $post['verb'];
@ -190,13 +183,6 @@ class Statuses extends BaseApi
$owner = User::getOwnerDataById($uid);
// The imput is defined as text. So we can use Markdown for some enhancements
$body = Markdown::toBBCode($request['status']);
if (DI::pConfig()->get($uid, 'system', 'api_auto_attach', false) && preg_match("/\[url=[^\[\]]*\](.*)\[\/url\]\z/ism", $body, $matches)) {
$body = preg_replace("/\[url=[^\[\]]*\].*\[\/url\]\z/ism", PageInfo::getFooterFromUrl($matches[1]), $body);
}
$item = [];
$item['network'] = Protocol::DFRN;
$item['uid'] = $uid;
@ -204,7 +190,7 @@ class Statuses extends BaseApi
$item['contact-id'] = $owner['id'];
$item['author-id'] = $item['owner-id'] = Contact::getPublicIdByUserId($uid);
$item['title'] = '';
$item['body'] = $body;
$item['body'] = $this->formatStatus($request['status'], $uid);
$item['app'] = $this->getApp();
switch ($request['visibility']) {
@ -415,4 +401,28 @@ class Statuses extends BaseApi
}
return $item;
}
/**
* Format the status via Markdown and a link description if enabled for this user
*
* @param string $status
* @param integer $uid
* @return string
*/
private function formatStatus(string $status, int $uid): string
{
// The input is defined as text. So we can use Markdown for some enhancements
$status = Markdown::toBBCode($status);
if (!DI::pConfig()->get($uid, 'system', 'api_auto_attach', false)) {
return $status;
}
$status = BBCode::expandVideoLinks($status);
if (preg_match("/\[url=[^\[\]]*\](.*)\[\/url\]\z/ism", $status, $matches)) {
$status = preg_replace("/\[url=[^\[\]]*\].*\[\/url\]\z/ism", PageInfo::getFooterFromUrl($matches[1]), $status);
}
return $status;
}
}

View file

@ -82,12 +82,12 @@ abstract class BaseModeration extends BaseModule
}
}
if (!$this->app->isSiteAdmin()) {
throw new HTTPException\ForbiddenException($this->t('You don\'t have access to administration pages.'));
if (!$this->session->isModerator()) {
throw new HTTPException\ForbiddenException($this->t('You don\'t have access to moderation pages.'));
}
if ($this->session->getSubManagedUserId()) {
throw new HTTPException\ForbiddenException($this->t('Submanaged account can\'t access the administration pages. Please log back in as the main account.'));
throw new HTTPException\ForbiddenException($this->t('Submanaged account can\'t access the moderation pages. Please log back in as the main account.'));
}
}

View file

@ -283,10 +283,10 @@ class Profile extends BaseModule
$localRelationship->fetchFurtherInformation,
$this->t('Fetch information like preview pictures, title and teaser from the feed item. You can activate this if the feed doesn\'t contain much text. Keywords are taken from the meta header in the feed item and are posted as hash tags.'),
[
'0' => $this->t('Disabled'),
'1' => $this->t('Fetch information'),
'3' => $this->t('Fetch keywords'),
'2' => $this->t('Fetch information and keywords')
Entity\LocalRelationship::FFI_NONE => $this->t('Disabled'),
Entity\LocalRelationship::FFI_INFORMATION => $this->t('Fetch information'),
Entity\LocalRelationship::FFI_KEYWORD => $this->t('Fetch keywords'),
Entity\LocalRelationship::FFI_BOTH => $this->t('Fetch information and keywords')
]
];
}
@ -394,7 +394,7 @@ class Profile extends BaseModule
'$remote_self' => [
'remote_self',
$this->t('Mirror postings from this contact'),
$localRelationship->isRemoteSelf,
$localRelationship->remoteSelf,
$this->t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
$remote_self_options
],

View file

@ -26,7 +26,7 @@ use Friendica\BaseModule;
use Friendica\Core\Addon;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hook;
use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs;
use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Capability\IHandleUserSessions;
@ -94,8 +94,7 @@ class Friendica extends BaseModule
$blockList = $this->config->get('system', 'blocklist') ?? [];
$register_policy_int = $this->config->get('config', 'register_policy');
if (!empty($blockList) && ($register_policy_int !== Register::CLOSED || $this->session->isAuthenticated())) {
if (!empty($blockList) && ($this->config->get('blocklist', 'public') || $this->session->isAuthenticated())) {
$blocked = [
'title' => $this->t('On this server the following remote servers are blocked.'),
'header' => [

View file

@ -88,10 +88,6 @@ class NodeInfo110 extends BaseModule
$nodeinfo['metadata']['services'] = $nodeinfo['services'];
if (Addon::isEnabled('twitter')) {
$nodeinfo['metadata']['services']['inbound'][] = 'twitter';
}
$nodeinfo['metadata']['explicitContent'] = $this->config->get('system', 'explicit_content', false) == true;
$this->response->setType(ICanCreateResponses::TYPE_JSON);

View file

@ -72,10 +72,6 @@ class NodeInfo120 extends BaseModule
$nodeinfo['protocols'][] = 'ostatus';
}
if (Addon::isEnabled('twitter')) {
$nodeinfo['services']['inbound'][] = 'twitter';
}
$nodeinfo['services']['inbound'][] = 'atom1.0';
$nodeinfo['services']['inbound'][] = 'rss2.0';
$nodeinfo['services']['outbound'][] = 'atom1.0';

View file

@ -71,10 +71,6 @@ class NodeInfo210 extends BaseModule
$nodeinfo['protocols'][] = 'ostatus';
}
if (Addon::isEnabled('twitter')) {
$nodeinfo['services']['inbound'][] = 'twitter';
}
$nodeinfo['services']['inbound'][] = 'atom1.0';
$nodeinfo['services']['inbound'][] = 'rss2.0';
$nodeinfo['services']['outbound'][] = 'atom1.0';

View file

@ -52,6 +52,7 @@ use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Profiler;
use Friendica\Util\Strings;
use GuzzleHttp\Psr7\Uri;
use Psr\Log\LoggerInterface;
@ -174,7 +175,7 @@ class Ping extends BaseModule
$myurl = $this->session->getMyUrl();
$mail_count = $this->database->count('mail', ["`uid` = ? AND NOT `seen` AND `from-url` != ?", $this->session->getLocalUserId(), $myurl]);
if (intval($this->config->get('config', 'register_policy')) === Register::APPROVE && $this->app->isSiteAdmin()) {
if (intval($this->config->get('config', 'register_policy')) === Register::APPROVE && $this->session->isSiteAdmin()) {
$registrations = \Friendica\Model\Register::getPending();
$register_count = count($registrations);
}
@ -296,8 +297,8 @@ class Ping extends BaseModule
$data['notifications'] = $navNotifications;
$data['sysmsgs'] = [
'notice' => $this->systemMessages->flushNotices(),
'info' => $this->systemMessages->flushInfos(),
'notice' => array_map([Strings::class, 'escapeHtml'], $this->systemMessages->flushNotices()),
'info' => array_map([Strings::class, 'escapeHtml'], $this->systemMessages->flushInfos()),
];
if (isset($_GET['callback'])) {

View file

@ -103,10 +103,10 @@ class Conversations extends BaseProfile
$this->page['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
}
$this->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $this->baseUrl . '/dfrn_poll/' . $this->parameters['nickname'] . '" title="DFRN: ' . $this->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
$this->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $this->baseUrl . '/feed/' . $this->parameters['nickname'] . '/" title="' . $this->t('%s\'s posts', $profile['name']) . '"/>' . "\n";
$this->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $this->baseUrl . '/feed/' . $this->parameters['nickname'] . '/comments" title="' . $this->t('%s\'s comments', $profile['name']) . '"/>' . "\n";
$this->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $this->baseUrl . '/feed/' . $this->parameters['nickname'] . '/activity" title="' . $this->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
$this->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $this->baseUrl . '/dfrn_poll/' . $this->parameters['nickname'] . '" title="DFRN: ' . $this->t('%s\'s timeline', Strings::escapeHtml($profile['name'])) . '"/>' . "\n";
$this->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $this->baseUrl . '/feed/' . $this->parameters['nickname'] . '/" title="' . $this->t('%s\'s posts', Strings::escapeHtml($profile['name'])) . '"/>' . "\n";
$this->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $this->baseUrl . '/feed/' . $this->parameters['nickname'] . '/comments" title="' . $this->t('%s\'s comments', Strings::escapeHtml($profile['name'])) . '"/>' . "\n";
$this->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $this->baseUrl . '/feed/' . $this->parameters['nickname'] . '/activity" title="' . $this->t('%s\'s timeline', Strings::escapeHtml($profile['name'])) . '"/>' . "\n";
$category = $datequery = $datequery2 = '';

View file

@ -45,6 +45,11 @@ class RobotsTxt extends BaseModule
foreach ($allDisallowed as $disallowed) {
echo 'Disallow: ' . $disallowed . PHP_EOL;
}
echo PHP_EOL;
echo 'User-agent: ChatGPT-User' . PHP_EOL;
echo 'Disallow: /' . PHP_EOL;
System::exit();
}
}

View file

@ -173,7 +173,7 @@ class Index extends BaseSearch
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
if ($tag) {
Logger::info('Start tag search.', ['q' => $search]);
Logger::info('Start tag search.', ['q' => $search, 'start' => $pager->getStart(), 'items' => $pager->getItemsPerPage(), 'last' => $last_uriid]);
$uriids = Tag::getURIIdListByTag($search, DI::userSession()->getLocalUserId(), $pager->getStart(), $pager->getItemsPerPage(), $last_uriid);
$count = Tag::countByTag($search, DI::userSession()->getLocalUserId());
} else {
@ -185,7 +185,7 @@ class Index extends BaseSearch
if (!empty($uriids)) {
$condition = ["(`uid` = ? OR (`uid` = ? AND NOT `global`))", 0, DI::userSession()->getLocalUserId()];
$condition = DBA::mergeConditions($condition, ['uri-id' => $uriids]);
$params = ['order' => ['id' => true]];
$params = ['order' => ['uri-id' => true]];
$items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), Item::DISPLAY_FIELDLIST, $condition, $params));
}

View file

@ -25,7 +25,7 @@ use Friendica\App;
use Friendica\BaseModule;
use Friendica\Core\Addon;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs;
use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Network\HTTPException\NotFoundException;
@ -38,7 +38,7 @@ class Statistics extends BaseModule
protected $config;
/** @var IManageKeyValuePairs */
protected $keyValue;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, IManageKeyValuePairs $keyValue, Response $response, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
@ -59,7 +59,7 @@ class Statistics extends BaseModule
/// @todo mark the "service" addons and load them dynamically here
$services = [
'appnet' => Addon::isEnabled('appnet'),
'buffer' => Addon::isEnabled('buffer'),
'bluesky' => Addon::isEnabled('bluesky'),
'dreamwidth' => Addon::isEnabled('dreamwidth'),
'gnusocial' => Addon::isEnabled('gnusocial'),
'libertree' => Addon::isEnabled('libertree'),

View file

@ -21,32 +21,43 @@
namespace Friendica\Module;
use Friendica\App;
use Friendica\BaseModule;
use Friendica\DI;
use Friendica\Core\L10n;
use Friendica\Core\Session\Capability\IHandleSessions;
use Friendica\Core\System;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Util;
use GuzzleHttp\Psr7\Uri;
use Psr\Log\LoggerInterface;
/**
* Toggles the mobile view (on/off)
*/
class ToggleMobile extends BaseModule
{
protected function content(array $request = []): string
/** @var IHandleSessions */
private $session;
public function __construct(IHandleSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Util\Profiler $profiler, Response $response, array $server, array $parameters = [])
{
$a = DI::app();
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
if (isset($_GET['off'])) {
$_SESSION['show-mobile'] = false;
} else {
$_SESSION['show-mobile'] = true;
$this->session = $session;
}
protected function rawContent(array $request = [])
{
$address = $request['address'] ?? '' ?: $this->baseUrl;
$uri = new Uri($address);
if (!$this->baseUrl->isLocalUri($uri)) {
throw new BadRequestException();
}
if (isset($_GET['address'])) {
$address = $_GET['address'];
} else {
$address = '';
}
$this->session->set('show-mobile', !isset($request['off']));
$a->redirect($address);
return '';
System::externalRedirect((string)$uri);
}
}