Option to automatically add links as attachment via API
This commit is contained in:
parent
d951d49193
commit
4e070f65c7
5 changed files with 786 additions and 764 deletions
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
namespace Friendica\Module\Api\Mastodon;
|
namespace Friendica\Module\Api\Mastodon;
|
||||||
|
|
||||||
|
use Friendica\Content\PageInfo;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Content\Text\Markdown;
|
use Friendica\Content\Text\Markdown;
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
|
@ -37,6 +38,7 @@ use Friendica\Model\User;
|
||||||
use Friendica\Module\BaseApi;
|
use Friendica\Module\BaseApi;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Images;
|
use Friendica\Util\Images;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,6 +129,10 @@ class Statuses extends BaseApi
|
||||||
// The imput is defined as text. So we can use Markdown for some enhancements
|
// The imput is defined as text. So we can use Markdown for some enhancements
|
||||||
$body = Markdown::toBBCode($request['status']);
|
$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 = [];
|
||||||
$item['network'] = Protocol::DFRN;
|
$item['network'] = Protocol::DFRN;
|
||||||
$item['uid'] = $uid;
|
$item['uid'] = $uid;
|
||||||
|
@ -273,7 +279,7 @@ class Statuses extends BaseApi
|
||||||
if (!empty($request['scheduled_at'])) {
|
if (!empty($request['scheduled_at'])) {
|
||||||
$item['guid'] = Item::guid($item, true);
|
$item['guid'] = Item::guid($item, true);
|
||||||
$item['uri'] = Item::newURI($item['guid']);
|
$item['uri'] = Item::newURI($item['guid']);
|
||||||
$id = Post\Delayed::add($item['uri'], $item, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED, $request['scheduled_at']);
|
$id = Post\Delayed::add($item['uri'], $item, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED, DateTimeFormat::utc($request['scheduled_at']));
|
||||||
if (empty($id)) {
|
if (empty($id)) {
|
||||||
DI::mstdnError()->InternalError();
|
DI::mstdnError()->InternalError();
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ class Connectors extends BaseSettings
|
||||||
$this->pconfig->set($this->session->getLocalUserId(), 'system', 'simple_shortening', intval($request['simple_shortening']));
|
$this->pconfig->set($this->session->getLocalUserId(), 'system', 'simple_shortening', intval($request['simple_shortening']));
|
||||||
$this->pconfig->set($this->session->getLocalUserId(), 'system', 'attach_link_title', intval($request['attach_link_title']));
|
$this->pconfig->set($this->session->getLocalUserId(), 'system', 'attach_link_title', intval($request['attach_link_title']));
|
||||||
$this->pconfig->set($this->session->getLocalUserId(), 'system', 'api_spoiler_title', intval($request['api_spoiler_title']));
|
$this->pconfig->set($this->session->getLocalUserId(), 'system', 'api_spoiler_title', intval($request['api_spoiler_title']));
|
||||||
|
$this->pconfig->set($this->session->getLocalUserId(), 'system', 'api_auto_attach', intval($request['api_auto_attach']));
|
||||||
$this->pconfig->set($this->session->getLocalUserId(), 'ostatus', 'legacy_contact', $request['legacy_contact']);
|
$this->pconfig->set($this->session->getLocalUserId(), 'ostatus', 'legacy_contact', $request['legacy_contact']);
|
||||||
} elseif (!empty($request['mail-submit']) && function_exists('imap_open') && !$this->config->get('system', 'imap_disabled')) {
|
} elseif (!empty($request['mail-submit']) && function_exists('imap_open') && !$this->config->get('system', 'imap_disabled')) {
|
||||||
$mail_server = $request['mail_server'] ?? '';
|
$mail_server = $request['mail_server'] ?? '';
|
||||||
|
@ -136,6 +137,7 @@ class Connectors extends BaseSettings
|
||||||
$simple_shortening = intval($this->pconfig->get($this->session->getLocalUserId(), 'system', 'simple_shortening'));
|
$simple_shortening = intval($this->pconfig->get($this->session->getLocalUserId(), 'system', 'simple_shortening'));
|
||||||
$attach_link_title = intval($this->pconfig->get($this->session->getLocalUserId(), 'system', 'attach_link_title'));
|
$attach_link_title = intval($this->pconfig->get($this->session->getLocalUserId(), 'system', 'attach_link_title'));
|
||||||
$api_spoiler_title = intval($this->pconfig->get($this->session->getLocalUserId(), 'system', 'api_spoiler_title', true));
|
$api_spoiler_title = intval($this->pconfig->get($this->session->getLocalUserId(), 'system', 'api_spoiler_title', true));
|
||||||
|
$api_auto_attach = intval($this->pconfig->get($this->session->getLocalUserId(), 'system', 'api_auto_attach', false));
|
||||||
$legacy_contact = $this->pconfig->get($this->session->getLocalUserId(), 'ostatus', 'legacy_contact');
|
$legacy_contact = $this->pconfig->get($this->session->getLocalUserId(), 'ostatus', 'legacy_contact');
|
||||||
|
|
||||||
if (!empty($legacy_contact)) {
|
if (!empty($legacy_contact)) {
|
||||||
|
@ -221,6 +223,7 @@ class Connectors extends BaseSettings
|
||||||
'$simple_shortening' => ['simple_shortening', $this->t('Enable simple text shortening'), $simple_shortening, $this->t('Normally the system shortens posts at the next line feed. If this option is enabled then the system will shorten the text at the maximum character limit.')],
|
'$simple_shortening' => ['simple_shortening', $this->t('Enable simple text shortening'), $simple_shortening, $this->t('Normally the system shortens posts at the next line feed. If this option is enabled then the system will shorten the text at the maximum character limit.')],
|
||||||
'$attach_link_title' => ['attach_link_title', $this->t('Attach the link title'), $attach_link_title, $this->t('When activated, the title of the attached link will be added as a title on posts to Diaspora. This is mostly helpful with "remote-self" contacts that share feed content.')],
|
'$attach_link_title' => ['attach_link_title', $this->t('Attach the link title'), $attach_link_title, $this->t('When activated, the title of the attached link will be added as a title on posts to Diaspora. This is mostly helpful with "remote-self" contacts that share feed content.')],
|
||||||
'$api_spoiler_title' => ['api_spoiler_title', $this->t('API: Use spoiler field as title'), $api_spoiler_title, $this->t('When activated, the "spoiler_text" field in the API will be used for the title on standalone posts. When deactivated it will be used for spoiler text. For comments it will always be used for spoiler text.')],
|
'$api_spoiler_title' => ['api_spoiler_title', $this->t('API: Use spoiler field as title'), $api_spoiler_title, $this->t('When activated, the "spoiler_text" field in the API will be used for the title on standalone posts. When deactivated it will be used for spoiler text. For comments it will always be used for spoiler text.')],
|
||||||
|
'$api_auto_attach' => ['api_auto_attach', $this->t('API: Automatically links at the end of the post as attached posts'), $api_auto_attach, $this->t('When activated, added links at the end of the post react the same way as added links in the web interface.')],
|
||||||
'$legacy_contact' => ['legacy_contact', $this->t('Your legacy ActivityPub/GNU Social account'), $legacy_contact, $this->t('If you enter your old account name from an ActivityPub based system or your GNU Social/Statusnet account name here (in the format user@domain.tld), your contacts will be added automatically. The field will be emptied when done.')],
|
'$legacy_contact' => ['legacy_contact', $this->t('Your legacy ActivityPub/GNU Social account'), $legacy_contact, $this->t('If you enter your old account name from an ActivityPub based system or your GNU Social/Statusnet account name here (in the format user@domain.tld), your contacts will be added automatically. The field will be emptied when done.')],
|
||||||
'$repair_ostatus_url' => 'ostatus/repair',
|
'$repair_ostatus_url' => 'ostatus/repair',
|
||||||
'$repair_ostatus_text' => $this->t('Repair OStatus subscriptions'),
|
'$repair_ostatus_text' => $this->t('Repair OStatus subscriptions'),
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -17,6 +17,7 @@
|
||||||
{{include file="field_checkbox.tpl" field=$simple_shortening}}
|
{{include file="field_checkbox.tpl" field=$simple_shortening}}
|
||||||
{{include file="field_checkbox.tpl" field=$attach_link_title}}
|
{{include file="field_checkbox.tpl" field=$attach_link_title}}
|
||||||
{{include file="field_checkbox.tpl" field=$api_spoiler_title}}
|
{{include file="field_checkbox.tpl" field=$api_spoiler_title}}
|
||||||
|
{{include file="field_checkbox.tpl" field=$api_auto_attach}}
|
||||||
{{include file="field_input.tpl" field=$legacy_contact}}
|
{{include file="field_input.tpl" field=$legacy_contact}}
|
||||||
|
|
||||||
<p><a href="{{$repair_ostatus_url}}">{{$repair_ostatus_text}}</a></p>
|
<p><a href="{{$repair_ostatus_url}}">{{$repair_ostatus_text}}</a></p>
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
|
|
||||||
{{include file="field_checkbox.tpl" field=$api_spoiler_title}}
|
{{include file="field_checkbox.tpl" field=$api_spoiler_title}}
|
||||||
|
|
||||||
|
{{include file="field_checkbox.tpl" field=$api_auto_attach}}
|
||||||
|
|
||||||
{{include file="field_input.tpl" field=$legacy_contact}}
|
{{include file="field_input.tpl" field=$legacy_contact}}
|
||||||
|
|
||||||
<p><a href="{{$repair_ostatus_url}}">{{$repair_ostatus_text}}</a></p>
|
<p><a href="{{$repair_ostatus_url}}">{{$repair_ostatus_text}}</a></p>
|
||||||
|
|
Loading…
Reference in a new issue