Compare commits

...

10 commits

Author SHA1 Message Date
Michael dff48c3295 Bluesky: Basic connector for Bluesky is added 2023-05-21 18:54:02 +00:00
heluecht e91962b0b6 Merge pull request '[various] Ensure probe_detect hook functions don't set the result key with an empty array' (#1382) from MrPetovan/friendica-addons:bug/13080-probe_detect-result into develop
Reviewed-on: friendica/friendica-addons#1382
2023-05-06 12:24:07 +02:00
Hypolite Petovan e0778d2bdd Merge pull request 'use new style of accessing baseUrl' (#1384) from mexon/friendica-addons:mailstream-fix-3 into develop
Reviewed-on: friendica/friendica-addons#1384
2023-05-05 18:46:25 +02:00
Matthew Exon 631bfd83e9 use new style of accessing baseUrl 2023-05-05 18:08:51 +02:00
Hypolite Petovan 4b31588484 Merge pull request 'remove App arguments' (#1383) from mexon/friendica-addons:mailstream-fix-2 into develop
Reviewed-on: friendica/friendica-addons#1383
2023-05-05 17:40:52 +02:00
Matthew Exon 8886c90d1e remove App arguments 2023-05-05 17:36:11 +02:00
Hypolite Petovan f5d8604e59 [twitter] Return null in the probe_detect hook result key on unsuccessful probe
- Add authoritative probe result setting
2023-05-05 00:08:17 -04:00
Hypolite Petovan a0574ab045 [tumblr] Have tumblr_get_contact_by_url return null for unsuccessful probe
- Add result setting for unsuccessful authoritative probe
2023-05-05 00:07:24 -04:00
Hypolite Petovan e1de842ffb Merge pull request '[piwik] updated DE translation' (#1381) from tobias/friendica-addons:20230501-de into develop
Reviewed-on: friendica/friendica-addons#1381
2023-05-01 16:42:03 +02:00
Tobias Diekershoff ca134e9ed3 [piwik] updated DE translation 2023-05-01 10:05:20 +02:00
8 changed files with 506 additions and 38 deletions

378
bluesky/bluesky.php Normal file
View file

@ -0,0 +1,378 @@
<?php
/**
* Name: Bluesky Connector
* Description: Post to Bluesky
* Version: 1.0
* Author: Michael Vogel <https://pirati.ca/profile/heluecht>
*/
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\Plaintext;
use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Util\DateTimeFormat;
function bluesky_install()
{
Hook::register('load_config', __FILE__, 'bluesky_load_config');
Hook::register('hook_fork', __FILE__, 'bluesky_hook_fork');
Hook::register('post_local', __FILE__, 'bluesky_post_local');
Hook::register('notifier_normal', __FILE__, 'bluesky_send');
Hook::register('jot_networks', __FILE__, 'bluesky_jot_nets');
Hook::register('connector_settings', __FILE__, 'bluesky_settings');
Hook::register('connector_settings_post', __FILE__, 'bluesky_settings_post');
}
function bluesky_load_config(ConfigFileManager $loader)
{
DI::app()->getConfigCache()->load($loader->loadAddonConfig('bluesky'), \Friendica\Core\Config\ValueObject\Cache::SOURCE_STATIC);
}
function bluesky_settings(array &$data)
{
if (!DI::userSession()->getLocalUserId()) {
return;
}
$enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'bluesky', 'post') ?? false;
$def_enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'bluesky', 'post_by_default') ?? false;
$host = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'bluesky', 'host') ?: 'https://bsky.social';
$handle = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'bluesky', 'handle');
$did = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'bluesky', 'did');
$username = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'bluesky', 'username');
$t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/bluesky/');
$html = Renderer::replaceMacros($t, [
'$enable' => ['bluesky', DI::l10n()->t('Enable Bluesky Post Addon'), $enabled],
'$bydefault' => ['bluesky_bydefault', DI::l10n()->t('Post to Bluesky by default'), $def_enabled],
'$host' => ['bluesky_host', DI::l10n()->t('Bluesky host'), $host, '', '', '', 'url'],
'$handle' => ['bluesky_handle', DI::l10n()->t('Bluesky handle'), $handle],
'$did' => ['bluesky_did', DI::l10n()->t('Bluesky DID'), $did, DI::l10n()->t('This is the unique identifier. It will be fetched automatically, when the handle is entered.'), '', 'readonly'],
'$username' => ['bluesky_username', DI::l10n()->t('Bluesky app username'), $username, DI::l10n()->t("Please don't add your real username here, but instead create a specific app username and app password in the Bluesky settings.")],
'$password' => ['bluesky_password', DI::l10n()->t('Bluesky app password'), ''],
]);
$data = [
'connector' => 'bluesky',
'title' => DI::l10n()->t('Bluesky Export'),
'image' => 'images/bluesky.jpg',
'enabled' => $enabled,
'html' => $html,
];
}
function bluesky_settings_post(array &$b)
{
if (empty($_POST['bluesky-submit'])) {
return;
}
$old_host = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'bluesky', 'host');
$old_handle = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'bluesky', 'handle');
$old_did = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'bluesky', 'did');
$host = $_POST['bluesky_host'];
$handle = $_POST['bluesky_handle'];
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'bluesky', 'post', intval($_POST['bluesky']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'bluesky', 'post_by_default', intval($_POST['bluesky_bydefault']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'bluesky', 'host', $host);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'bluesky', 'handle', $handle);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'bluesky', 'username', $_POST['bluesky_username']);
if (!empty($_POST['bluesky_password'])) {
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'bluesky', 'app_password', $_POST['bluesky_password']);
}
if (!empty($host) && !empty($handle)) {
if (empty($old_did) || $old_host != $host || $old_handle != $handle) {
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'bluesky', 'did', bluesky_get_did(DI::userSession()->getLocalUserId()));
}
} else {
DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'bluesky', 'did');
}
}
function bluesky_jot_nets(array &$jotnets_fields)
{
if (!DI::userSession()->getLocalUserId()) {
return;
}
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'bluesky', 'post')) {
$jotnets_fields[] = [
'type' => 'checkbox',
'field' => [
'bluesky_enable',
DI::l10n()->t('Post to Bluesky'),
DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'bluesky', 'post_by_default')
]
];
}
}
function bluesky_hook_fork(array &$b)
{
if ($b['name'] != 'notifier_normal') {
return;
}
$post = $b['data'];
if (($post['created'] !== $post['edited']) && !$post['deleted']) {
DI::logger()->info('Editing is not supported by the addon');
$b['execute'] = false;
return;
}
if (!strstr($post['postopts'] ?? '', 'bluesky') || ($post['parent'] != $post['id']) || $post['private']) {
$b['execute'] = false;
return;
}
}
function bluesky_post_local(array &$b)
{
if ($b['edit']) {
return;
}
if (!DI::userSession()->getLocalUserId() || (DI::userSession()->getLocalUserId() != $b['uid'])) {
return;
}
if ($b['private'] || $b['parent']) {
return;
}
$bluesky_post = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'bluesky', 'post'));
$bluesky_enable = (($bluesky_post && !empty($_REQUEST['bluesky_enable'])) ? intval($_REQUEST['bluesky_enable']) : 0);
// if API is used, default to the chosen settings
if ($b['api_source'] && intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'bluesky', 'post_by_default'))) {
$bluesky_enable = 1;
}
if (!$bluesky_enable) {
return;
}
if (strlen($b['postopts'])) {
$b['postopts'] .= ',';
}
$b['postopts'] .= 'bluesky';
}
function bluesky_send(array &$b)
{
if (($b['created'] !== $b['edited']) && !$b['deleted']) {
return;
}
if ($b['gravity'] != Item::GRAVITY_PARENT) {
return;
} elseif ($b['private'] || !strstr($b['postopts'], 'bluesky')) {
return;
}
bluesky_create_post($b);
}
function bluesky_create_post(array $item)
{
$uid = $item['uid'];
$token = bluesky_get_token($uid);
if (empty($token)) {
return;
}
$did = DI::pConfig()->get($uid, 'bluesky', 'did');
$msg = Plaintext::getPost($item, 300, false, BBCode::CONNECTORS);
$parent = $root = [];
foreach ($msg['parts'] as $key => $part) {
$record = [
'text' => $part,
'createdAt' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
'$type' => 'app.bsky.feed.post'
];
if (!empty($root)) {
$record['reply'] = ['root' => $root, 'parent' => $parent];
}
if ($key == count($msg['parts']) - 1) {
$record = bluesky_add_embed($uid, $msg, $record);
}
$post = [
'collection' => 'app.bsky.feed.post',
'repo' => $did,
'record' => $record
];
$parent = bluesky_post($uid, '/xrpc/com.atproto.repo.createRecord', json_encode($post), ['Content-type' => 'application/json', 'Authorization' => ['Bearer ' . $token]]);
if (empty($parent)) {
return;
}
Logger::debug('Posting done', ['return' => $parent]);
if (empty($root)) {
$root = $parent;
}
}
}
function bluesky_add_embed(int $uid, array $msg, array $record): array
{
if (($msg['type'] != 'link') && !empty($msg['images'])) {
$images = [];
foreach ($msg['images'] as $image) {
$photo = Photo::selectFirst(['resource-id'], ['id' => $image['id']]);
$photo = Photo::selectFirst([], ["`resource-id` = ? AND `scale` > ?", $photo['resource-id'], 0], ['order' => ['scale']]);
$blob = bluesky_upload_blob($uid, $photo);
if (!empty($blob)) {
$images[] = ['alt' => $image['description'], 'image' => $blob];
}
}
if (!empty($images)) {
$record['embed'] = ['$type' => 'app.bsky.embed.images', 'images' => $images];
}
} elseif ($msg['type'] == 'link') {
$record['embed'] = [
'$type' => 'app.bsky.embed.external',
'external' => [
'uri' => $msg['url'],
'title' => $msg['title'],
'description' => $msg['description'],
]
];
if (!empty($msg['image'])) {
$photo = Photo::createPhotoForExternalResource($msg['image']);
$blob = bluesky_upload_blob($uid, $photo);
if (!empty($blob)) {
$record['embed']['external']['thumb'] = $blob;
}
}
}
return $record;
}
function bluesky_upload_blob(int $uid, array $photo): ?stdClass
{
$content = Photo::getImageForPhoto($photo);
$data = bluesky_post($uid, '/xrpc/com.atproto.repo.uploadBlob', $content, ['Content-type' => $photo['type'], 'Authorization' => ['Bearer ' . bluesky_get_token($uid)]]);
if (empty($data)) {
return null;
}
Logger::debug('Uploaded blob', ['return' => $data]);
return $data->blob;
}
function bluesky_get_timeline(int $uid)
{
$data = bluesky_get($uid, '/xrpc/app.bsky.feed.getTimeline', HttpClientAccept::JSON, [HttpClientOptions::HEADERS => ['Authorization' => ['Bearer ' . bluesky_get_token($uid)]]]);
if (empty($data)) {
return;
}
// TODO Add Functionality to read the timeline
}
function bluesky_get_did(int $uid): string
{
$data = bluesky_get($uid, '/xrpc/com.atproto.identity.resolveHandle?handle=' . DI::pConfig()->get($uid, 'bluesky', 'handle'));
if (empty($data)) {
return '';
}
Logger::debug('Got DID', ['return' => $data]);
return $data->did;
}
function bluesky_get_token(int $uid): string
{
$token = DI::pConfig()->get($uid, 'bluesky', 'access_token');
$created = DI::pConfig()->get($uid, 'bluesky', 'token_created');
if (empty($token)) {
return bluesky_create_token($uid);
}
if ($created + 300 < time()) {
return bluesky_refresh_token($uid);
}
return $token;
}
function bluesky_refresh_token(int $uid): string
{
$token = DI::pConfig()->get($uid, 'bluesky', 'refresh_token');
$data = bluesky_post($uid, '/xrpc/com.atproto.server.refreshSession', '', ['Authorization' => ['Bearer ' . $token]]);
if (empty($data)) {
return '';
}
Logger::debug('Refreshed token', ['return' => $data]);
DI::pConfig()->set($uid, 'bluesky', 'access_token', $data->accessJwt);
DI::pConfig()->set($uid, 'bluesky', 'refresh_token', $data->refreshJwt);
DI::pConfig()->set($uid, 'bluesky', 'token_created', time());
return $data->accessJwt;
}
function bluesky_create_token(int $uid): string
{
$did = DI::pConfig()->get($uid, 'bluesky', 'did');
$password = DI::pConfig()->get($uid, 'bluesky', 'app_password');
$data = bluesky_post($uid, '/xrpc/com.atproto.server.createSession', json_encode(['identifier' => $did, 'password' => $password]), ['Content-type' => 'application/json']);
if (empty($data)) {
return '';
}
Logger::debug('Created token', ['return' => $data]);
DI::pConfig()->set($uid, 'bluesky', 'access_token', $data->accessJwt);
DI::pConfig()->set($uid, 'bluesky', 'refresh_token', $data->refreshJwt);
DI::pConfig()->set($uid, 'bluesky', 'token_created', time());
return $data->accessJwt;
}
function bluesky_post(int $uid, string $url, string $params, array $headers): ?stdClass
{
try {
$curlResult = DI::httpClient()->post(DI::pConfig()->get($uid, 'bluesky', 'host') . $url, $params, $headers);
} catch (\Exception $e) {
Logger::notice('Exception on post', ['exception' => $e]);
return null;
}
if (!$curlResult->isSuccess()) {
Logger::notice('API Error', ['error' => json_decode($curlResult->getBody()) ?: $curlResult->getBody()]);
return null;
}
return json_decode($curlResult->getBody());
}
function bluesky_get(int $uid, string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ?stdClass
{
try {
$curlResult = DI::httpClient()->get(DI::pConfig()->get($uid, 'bluesky', 'host') . $url, $accept_content, $opts);
} catch (\Exception $e) {
Logger::notice('Exception on get', ['exception' => $e]);
return null;
}
if (!$curlResult->isSuccess()) {
Logger::notice('API Error', ['error' => json_decode($curlResult->getBody()) ?: $curlResult->getBody()]);
return null;
}
return json_decode($curlResult->getBody());
}

View file

@ -0,0 +1,66 @@
# ADDON bluesky
# Copyright (C)
# This file is distributed under the same license as the Friendica bluesky addon package.
#
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-05-21 16:55+0000\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"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: bluesky.php:52
msgid "Enable Bluesky Post Addon"
msgstr ""
#: bluesky.php:53
msgid "Post to Bluesky by default"
msgstr ""
#: bluesky.php:54
msgid "Bluesky host"
msgstr ""
#: bluesky.php:55
msgid "Bluesky handle"
msgstr ""
#: bluesky.php:56
msgid "Bluesky DID"
msgstr ""
#: bluesky.php:56
msgid ""
"This is the unique identifier. It will be fetched automatically, when the "
"handle is entered."
msgstr ""
#: bluesky.php:57
msgid "Bluesky app username"
msgstr ""
#: bluesky.php:57
msgid ""
"Please don't add your real username here, but instead create a specific app "
"username and app password in the Bluesky settings."
msgstr ""
#: bluesky.php:58
msgid "Bluesky app password"
msgstr ""
#: bluesky.php:63
msgid "Bluesky Export"
msgstr ""
#: bluesky.php:113
msgid "Post to Bluesky"
msgstr ""

View file

@ -0,0 +1,7 @@
{{include file="field_checkbox.tpl" field=$enable}}
{{include file="field_checkbox.tpl" field=$bydefault}}
{{include file="field_input.tpl" field=$host}}
{{include file="field_input.tpl" field=$handle}}
{{include file="field_input.tpl" field=$did}}
{{include file="field_input.tpl" field=$username}}
{{include file="field_input.tpl" field=$password}}

View file

@ -66,10 +66,9 @@ function mailstream_module() {}
/**
* Adds an item in "addon features" in the admin menu of the site
*
* @param App $a App object (unused)
* @param string $o HTML form data
*/
function mailstream_addon_admin(App $a, string &$o)
function mailstream_addon_admin(string &$o)
{
$frommail = DI::config()->get('mailstream', 'frommail');
$template = Renderer::getMarkupTemplate('admin.tpl', 'addon/mailstream/');
@ -103,14 +102,14 @@ function mailstream_addon_admin_post()
*/
function mailstream_generate_id(string $uri): string
{
$host = DI::baseUrl()->getHostname();
$host = DI::baseUrl()->getHost();
$resource = hash('md5', $uri);
$message_id = "<" . $resource . "@" . $host . ">";
Logger::debug('mailstream: Generated message ID ' . $message_id . ' for URI ' . $uri);
return $message_id;
}
function mailstream_send_hook(App $a, array $data)
function mailstream_send_hook(array $data)
{
$criteria = array('uid' => $data['uid'], 'contact-id' => $data['contact-id'], 'uri' => $data['uri']);
$item = Post::selectFirst([], $criteria);
@ -138,11 +137,10 @@ function mailstream_send_hook(App $a, array $data)
* mailstream is enabled and the necessary data is available, forks a
* workerqueue item to send the email.
*
* @param App $a App object (unused)
* @param array $item content of the item (may or may not already be stored in the item table)
* @return void
*/
function mailstream_post_hook(App $a, array &$item)
function mailstream_post_hook(array &$item)
{
mailstream_check_version();
@ -414,7 +412,7 @@ function mailstream_send(string $message_id, array $item, array $user): bool
$template = Renderer::getMarkupTemplate('mail.tpl', 'addon/mailstream/');
$mail->AltBody = BBCode::toPlaintext($item['body']);
$item['body'] = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::CONNECTORS);
$item['url'] = DI::baseUrl()->get() . '/display/' . $item['guid'];
$item['url'] = DI::baseUrl() . '/display/' . $item['guid'];
$mail->Body = Renderer::replaceMacros($template, [
'$upstream' => DI::l10n()->t('Upstream'),
'$uri' => DI::l10n()->t('URI'),
@ -480,11 +478,10 @@ function mailstream_convert_table_entries()
/**
* Form for configuring mailstream features for a user
*
* @param App $a App object
* @param array $data Hook data array
* @throws \Friendica\Network\HTTPException\ServiceUnavailableException
*/
function mailstream_addon_settings(App &$a, array &$data)
function mailstream_addon_settings(array &$data)
{
$enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'mailstream', 'enabled');
$address = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'mailstream', 'address');
@ -528,11 +525,10 @@ function mailstream_addon_settings(App &$a, array &$data)
/**
* Process data submitted to user's mailstream features form
* @param App $a
* @param array $post POST data
* @return void
*/
function mailstream_addon_settings_post(App $a, array $post)
function mailstream_addon_settings_post(array $post)
{
if (!DI::userSession()->getLocalUserId() || empty($post['mailstream-submit'])) {
return;

View file

@ -7,15 +7,15 @@
# Andreas H., 2014-2015
# Till Mohr <tmtrfx@till-mohr.de>, 2021
# Tobias Diekershoff <tobias.diekershoff@gmx.net>, 2014
# Tobias Diekershoff <tobias.diekershoff@gmx.net>, 2019
# Tobias Diekershoff <tobias.diekershoff@gmx.net>, 2019,2023
# Ulf Rompe <transifex.com@rompe.org>, 2019
msgid ""
msgstr ""
"Project-Id-Version: friendica\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-02-01 18:15+0100\n"
"POT-Creation-Date: 2023-05-01 07:39+0200\n"
"PO-Revision-Date: 2014-06-23 11:18+0000\n"
"Last-Translator: Till Mohr <tmtrfx@till-mohr.de>, 2021\n"
"Last-Translator: Tobias Diekershoff <tobias.diekershoff@gmx.net>, 2019,2023\n"
"Language-Team: German (http://app.transifex.com/Friendica/friendica/language/de/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -23,13 +23,13 @@ msgstr ""
"Language: de\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: piwik.php:87
#: piwik.php:96
msgid ""
"This website is tracked using the <a href='http://www.matomo.org'>Matomo</a>"
" analytics tool."
msgstr "Diese Website benutzt <a href='http://www.matomo.org'>Matomo</a>, eine Open-Source-Software zur statistischen Auswertung der Besucherzugriffe."
#: piwik.php:90
#: piwik.php:99
#, php-format
msgid ""
"If you do not want that your visits are logged in this way you <a "
@ -37,28 +37,32 @@ msgid ""
"visits of the site</a> (opt-out)."
msgstr "Wenn du nicht willst, dass Deine Besuche auf diese Weise gespeichert werden, kannst du <a href='%s'>ein Cookie setzen</a>. Dann wird Matomo / Piwik dich auf dieser Website nicht mehr verfolgen (opt-out)."
#: piwik.php:97
#: piwik.php:108
msgid "Save Settings"
msgstr "Einstellungen speichern"
#: piwik.php:98
#: piwik.php:109
msgid "Matomo (Piwik) Base URL"
msgstr "Matomo-Basis-URL (Piwik-Basis-URL)"
#: piwik.php:98
#: piwik.php:109
msgid ""
"Absolute path to your Matomo (Piwik) installation. (without protocol "
"(http/s), with trailing slash)"
msgstr "Absoluter Pfad zu deiner Matomo-/Piwik-Installation (ohne \"http://\" oder \"https://\"), mit abschließendem Schrägstrich"
#: piwik.php:99
#: piwik.php:110
msgid "Site ID"
msgstr "Seiten-ID"
#: piwik.php:100
#: piwik.php:111
msgid "Show opt-out cookie link?"
msgstr "Link zum Setzen des Opt-Out-Cookies anzeigen?"
#: piwik.php:101
#: piwik.php:112
msgid "Asynchronous tracking"
msgstr "Asynchrones Tracking"
#: piwik.php:113
msgid "Shortcut path to the script ('/js/' instead of '/piwik.js')"
msgstr "Shortcut Pfad zum Script ('/js/' anstelle von '/piwik.js')"

View file

@ -13,3 +13,4 @@ $a->strings['Absolute path to your Matomo (Piwik) installation. (without protoco
$a->strings['Site ID'] = 'Seiten-ID';
$a->strings['Show opt-out cookie link?'] = 'Link zum Setzen des Opt-Out-Cookies anzeigen?';
$a->strings['Asynchronous tracking'] = 'Asynchrones Tracking';
$a->strings['Shortcut path to the script (\'/js/\' instead of \'/piwik.js\')'] = 'Shortcut Pfad zum Script (\'/js/\' anstelle von \'/piwik.js\')';

View file

@ -79,7 +79,7 @@ function tumblr_check_item_notification(array &$notification_data)
return;
}
$own_user = Contact::selectFirst(['url', 'alias'], ['uid' => $notification_data['uid'], 'poll' => 'tumblr::'.$page]);
$own_user = Contact::selectFirst(['url', 'alias'], ['uid' => $notification_data['uid'], 'poll' => 'tumblr::' . $page]);
if ($own_user) {
$notification_data['profiles'][] = $own_user['url'];
$notification_data['profiles'][] = $own_user['alias'];
@ -99,6 +99,11 @@ function tumblr_probe_detect(array &$hookData)
}
$hookData['result'] = tumblr_get_contact_by_url($hookData['uri']);
// Authoritative probe should set the result even if the probe was unsuccessful
if ($hookData['network'] == Protocol::TUMBLR && empty($hookData['result'])) {
$hookData['result'] = [];
}
}
function tumblr_item_by_link(array &$hookData)
@ -1213,24 +1218,25 @@ function tumblr_enabled_for_user(int $uid)
* Get a contact array from a Tumblr url
*
* @param string $url
* @return array
* @return array|null
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
function tumblr_get_contact_by_url(string $url): array
function tumblr_get_contact_by_url(string $url): ?array
{
$consumer_key = DI::config()->get('tumblr', 'consumer_key');
if (empty($consumer_key)) {
return [];
return null;
}
if (!preg_match('#^https?://tumblr.com/(.+)#', $url, $matches) && !preg_match('#^https?://www\.tumblr.com/(.+)#', $url, $matches) && !preg_match('#^https?://(.+)\.tumblr.com#', $url, $matches)) {
try {
$curlResult = DI::httpClient()->get($url);
} catch (\Exception $e) {
return [];
return null;
}
$html = $curlResult->getBody();
if (empty($html)) {
return [];
return null;
}
$doc = new DOMDocument();
@$doc->loadHTML($html);
@ -1244,7 +1250,7 @@ function tumblr_get_contact_by_url(string $url): array
}
if (empty($blog)) {
return [];
return null;
}
Logger::debug('Update Tumblr blog data', ['url' => $url]);
@ -1253,7 +1259,12 @@ function tumblr_get_contact_by_url(string $url): array
$body = $curlResult->getBody();
$data = json_decode($body);
if (empty($data)) {
return [];
return null;
}
if (is_array($data->response->blog)) {
Logger::warning('Unexpected blog format', ['blog' => $blog, 'data' => $data]);
return null;
}
$baseurl = 'https://tumblr.com';
@ -1276,8 +1287,8 @@ function tumblr_get_contact_by_url(string $url): array
'priority' => 0,
'guid' => $data->response->blog->uuid,
'about' => HTML::toBBCode($data->response->blog->description),
'photo' => $data->response->blog->avatar[0]->url,
'header' => $data->response->blog->theme->header_image_focused,
'photo' => $data->response->blog->avatar[0]->url,
'header' => $data->response->blog->theme->header_image_focused,
];
}

View file

@ -526,7 +526,12 @@ function twitter_probe_detect(array &$hookData)
$user = twitter_fetchuser($nick);
if ($user) {
$hookData['result'] = twitter_user_to_contact($user);
$hookData['result'] = twitter_user_to_contact($user) ?: null;
}
// Authoritative probe should set the result even if the probe was unsuccessful
if ($hookData['network'] == Protocol::TWITTER && empty($hookData['result'])) {
$hookData['result'] = [];
}
}