- **htmlVersion**: html version of the message
- **textVersion**: text only version of the message
- **additionalMailHeader**: additions to the smtp mail header
+- **sent**: default false, if set to true in the hook, the default mailer will be skipped.
### emailer_send
Called before calling PHP's `mail()`.
- **subject**
- **body**
- **headers**
+- **sent**: default false, if set to true in the hook, the default mailer will be skipped.
### load_config
Called during `App` initialization to allow addons to load their own configuration file(s) with `App::loadConfigFile()`.
'name' => $contact["name"],
'screen_name' => (($contact['nick']) ? $contact['nick'] : $contact['name']),
'location' => ($contact["location"] != "") ? $contact["location"] : ContactSelector::networkToName($contact['network'], $contact['url']),
- 'description' => $contact["about"],
+ 'description' => HTML::toPlaintext(BBCode::toPlaintext($contact["about"])),
'profile_image_url' => $contact["micro"],
'profile_image_url_https' => $contact["micro"],
'profile_image_url_profile_size' => $contact["thumb"],
'name' => (($uinfo[0]['name']) ? $uinfo[0]['name'] : $uinfo[0]['nick']),
'screen_name' => (($uinfo[0]['nick']) ? $uinfo[0]['nick'] : $uinfo[0]['name']),
'location' => $location,
- 'description' => $description,
+ 'description' => HTML::toPlaintext(BBCode::toPlaintext($description)),
'profile_image_url' => $uinfo[0]['micro'],
'profile_image_url_https' => $uinfo[0]['micro'],
'profile_image_url_profile_size' => $uinfo[0]["thumb"],
function api_get_last_status($ownerId, $uid)
{
$condition = [
- 'owner-id' => $ownerId,
+ 'author-id'=> $ownerId,
'uid' => $uid,
'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
'private' => false
/**
* @file mod/uexport.php
*/
+
use Friendica\App;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
+use Friendica\Database\DBStructure;
function uexport_init(App $a) {
+ /// @todo Don't forget to move this global field as static field in src/Modules
+ global $dbStructure;
+
if (!local_user()) {
exit();
}
require_once("mod/settings.php");
settings_init($a);
+
+ $dbStructure = DBStructure::definition($a->getBasePath());
}
function uexport_content(App $a) {
}
function _uexport_multirow($query) {
+ global $dbStructure;
+
+ preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match);
+ $table = $match[1];
+
$result = [];
$r = q($query);
if (DBA::isResult($r)) {
foreach ($r as $rr) {
$p = [];
foreach ($rr as $k => $v) {
- $p[$k] = $v;
+ switch ($dbStructure[$table]['fields'][$k]['type']) {
+ case 'datetime':
+ $p[$k] = $v ?? DBA::NULL_DATETIME;
+ break;
+ default:
+ $p[$k] = $v;
+ break;
+ }
}
$result[] = $p;
}
}
function _uexport_row($query) {
+ global $dbStructure;
+
+ preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match);
+ $table = $match[1];
+
$result = [];
$r = q($query);
if (DBA::isResult($r)) {
+
foreach ($r as $rr) {
foreach ($rr as $k => $v) {
- $result[$k] = $v;
+ switch ($dbStructure[$table]['fields'][$k]['type']) {
+ case 'datetime':
+ $result[$k] = $v ?? DBA::NULL_DATETIME;
+ break;
+ default:
+ $result[$k] = $v;
+ break;
+ }
}
}
}
$tableColumns = DBStructure::getColumns($table);
$tcols = [];
+ $ttype = [];
// get a plain array of column names
foreach ($tableColumns as $tcol) {
$tcols[] = $tcol['Field'];
+ $ttype[$tcol['Field']] = $tcol['Type'];
}
// remove inexistent columns
foreach ($arr as $icol => $ival) {
if (!in_array($icol, $tcols)) {
unset($arr[$icol]);
+ continue;
+ }
+
+ if ($ttype[$icol] === 'datetime') {
+ $arr[$icol] = $ival ?? DBA::NULL_DATETIME;
}
}
}
'to_email' => $user['email'],
'uid' => $user['uid'],
'item' => $msg,
- 'parent' => $msg['parent-uri'],
+ 'parent' => 0,
'source_name' => $msg['from-name'],
'source_link' => $msg['from-url'],
'source_photo' => $msg['from-photo'],
Item::delete(['uri' => $activity['object_id'], 'owner-id' => $owner]);
}
+ /**
+ * Prepare the item array for an activity
+ *
+ * @param array $activity Activity array
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ public static function addTag($activity)
+ {
+ if (empty($activity['object_content']) || empty($activity['object_id'])) {
+ return;
+ }
+
+ foreach ($activity['receiver'] as $receiver) {
+ $item = Item::selectFirst(['id', 'tag', 'origin', 'author-link'], ['uri' => $activity['target_id'], 'uid' => $receiver]);
+ if (!DBA::isResult($item)) {
+ // We don't fetch missing content for this purpose
+ continue;
+ }
+
+ if (($item['author-link'] != $activity['actor']) && !$item['origin']) {
+ Logger::info('Not origin, not from the author, skipping update', ['id' => $item['id'], 'author' => $item['author-link'], 'actor' => $activity['actor']]);
+ continue;
+ }
+
+ // To-Do:
+ // - Check if "blocktag" is set
+ // - Check if actor is a contact
+
+ if (!stristr($item['tag'], trim($activity['object_content']))) {
+ $tag = $item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . $activity['object_id'] . ']'. $activity['object_content'] . '[/url]';
+ Item::update(['tag' => $tag], ['id' => $item['id']]);
+ Logger::info('Tagged item', ['id' => $item['id'], 'tag' => $activity['object_content'], 'uri' => $activity['target_id'], 'actor' => $activity['actor']]);
+ }
+ }
+ }
+
/**
* Prepare the item array for an activity
*
$object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id');
$object_data['object_id'] = $object_id;
$object_data['object_type'] = ''; // Since we don't fetch the object, we don't know the type
+ } elseif (in_array($type, ['as:Add'])) {
+ $object_data = [];
+ $object_data['id'] = JsonLD::fetchElement($activity, '@id');
+ $object_data['target_id'] = JsonLD::fetchElement($activity, 'as:target', '@id');
+ $object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
+ $object_data['object_type'] = JsonLD::fetchElement($activity['as:object'], '@type');
+ $object_data['object_content'] = JsonLD::fetchElement($activity['as:object'], 'as:content', '@type');
} else {
$object_data = [];
$object_data['id'] = JsonLD::fetchElement($activity, '@id');
}
break;
+ case 'as:Add':
+ if ($object_data['object_type'] == 'as:tag') {
+ ActivityPub\Processor::addTag($object_data);
+ }
+ break;
+
case 'as:Announce':
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
$profile = APContact::getByURL($object_data['actor']);
*/
private static function getRelayContact($server_url)
{
- $fields = ['batch', 'id', 'name', 'network', 'archive', 'blocked'];
+ $fields = ['batch', 'id', 'name', 'network', 'protocol', 'archive', 'blocked'];
// Fetch the relay contact
$condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url),
* @return bool
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function send($params)
+ public static function send(array $params)
{
+ $params['sent'] = false;
+
Hook::callAll('emailer_send_prepare', $params);
+ if ($params['sent']) {
+ return true;
+ }
+
$email_textonly = false;
if (!empty($params['uid'])) {
$email_textonly = PConfig::get($params['uid'], "system", "email_textonly");
'subject' => $messageSubject,
'body' => $multipartMessageBody,
'headers' => $messageHeader,
- 'parameters' => $sendmail_params
+ 'parameters' => $sendmail_params,
+ 'sent' => false,
];
Hook::callAll("emailer_send", $hookdata);
+ if ($hookdata['sent']) {
+ return true;
+ }
+
$res = mail(
$hookdata['to'],
$hookdata['subject'],