forked from friendica/friendica-addons
Compare commits
7 commits
e1de842ffb
...
e91962b0b6
Author | SHA1 | Date | |
---|---|---|---|
heluecht | e91962b0b6 | ||
Hypolite Petovan | e0778d2bdd | ||
631bfd83e9 | |||
Hypolite Petovan | 4b31588484 | ||
8886c90d1e | |||
Hypolite Petovan | f5d8604e59 | ||
Hypolite Petovan | a0574ab045 |
|
@ -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;
|
||||
|
|
|
@ -70,7 +70,7 @@ function tumblr_load_config(ConfigFileManager $loader)
|
|||
|
||||
function tumblr_check_item_notification(array &$notification_data)
|
||||
{
|
||||
if (!tumblr_enabled_for_user($notification_data['uid'])) {
|
||||
if (!tumblr_enabled_for_user($notification_data['uid'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -115,7 +120,7 @@ function tumblr_item_by_link(array &$hookData)
|
|||
if (!preg_match('#^https?://www\.tumblr.com/blog/view/(.+)/(\d+).*#', $hookData['uri'], $matches) && !preg_match('#^https?://www\.tumblr.com/(.+)/(\d+).*#', $hookData['uri'], $matches)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Logger::debug('Found tumblr post', ['url' => $hookData['uri'], 'blog' => $matches[1], 'id' => $matches[2]]);
|
||||
|
||||
$parameters = ['id' => $matches[2], 'reblog_info' => false, 'notes_info' => false, 'npf' => false];
|
||||
|
@ -1201,7 +1206,7 @@ function tumblr_get_blogs(int $uid): array
|
|||
return $blogs;
|
||||
}
|
||||
|
||||
function tumblr_enabled_for_user(int $uid)
|
||||
function tumblr_enabled_for_user(int $uid)
|
||||
{
|
||||
return !empty($uid) && !empty(DI::pConfig()->get($uid, 'tumblr', 'access_token')) &&
|
||||
!empty(DI::pConfig()->get($uid, 'tumblr', 'refresh_token')) &&
|
||||
|
@ -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,7 @@ function tumblr_get_contact_by_url(string $url): array
|
|||
$body = $curlResult->getBody();
|
||||
$data = json_decode($body);
|
||||
if (empty($data)) {
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
|
||||
$baseurl = 'https://tumblr.com';
|
||||
|
@ -1403,13 +1409,13 @@ function tumblr_get_token(int $uid, string $code = ''): string
|
|||
Logger::info('Error fetching token', ['uid' => $uid, 'code' => $code, 'result' => $curlResult->getBody(), 'parameters' => $parameters]);
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
$result = json_decode($curlResult->getBody());
|
||||
if (empty($result)) {
|
||||
Logger::info('Invalid result when updating token', ['uid' => $uid]);
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
$expires_at = time() + $result->expires_in;
|
||||
Logger::debug('Renewed token', ['uid' => $uid, 'expires_at' => date('c', $expires_at)]);
|
||||
}
|
||||
|
|
|
@ -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'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue