]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #7199 from MrPetovan/bug/7171-filer-network
authorPhilipp <admin+Github@philipp.info>
Wed, 29 May 2019 05:03:44 +0000 (07:03 +0200)
committerGitHub <noreply@github.com>
Wed, 29 May 2019 05:03:44 +0000 (07:03 +0200)
Allow commas in saved folder names

doc/Addons.md
include/api.php
mod/uexport.php
src/Core/UserImport.php
src/Model/Mail.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/Diaspora.php
src/Util/Emailer.php

index 858d64355f5fc33a3149679cdb2cbfd6eb48e2fc..47d16085a1216595c44914695fb4d122014ed62e 100644 (file)
@@ -358,6 +358,7 @@ Called from `Emailer::send()` before building the mime message.
 - **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()`.
@@ -367,6 +368,7 @@ 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()`.
index 0ca0bf838c983179e219b883dcfc3cf1c7aa19dc..0fab1f47c164e02a64e944494827ae2c6d8467c5 100644 (file)
@@ -611,7 +611,7 @@ function api_get_user(App $a, $contact_id = null)
                                '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"],
@@ -690,7 +690,7 @@ function api_get_user(App $a, $contact_id = null)
                '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"],
@@ -1271,7 +1271,7 @@ function api_status_show($type, $item_id)
 function api_get_last_status($ownerId, $uid)
 {
        $condition = [
-               'owner-id' => $ownerId,
+               'author-id'=> $ownerId,
                'uid'      => $uid,
                'gravity'  => [GRAVITY_PARENT, GRAVITY_COMMENT],
                'private'  => false
index c91309e74c37fec9eb4077a25dda78defc6da4ca..dfeb25abd7bacf446d4d0e1e6bc68d91c018a780 100644 (file)
@@ -2,20 +2,27 @@
 /**
  * @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) {
@@ -55,13 +62,25 @@ 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;
                }
@@ -70,12 +89,25 @@ function _uexport_multirow($query) {
 }
 
 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;
+                               }
                        }
                }
        }
index 0a4223fecdf5f45241051631dcb23a0c5d10aab2..97a6e6028e3b4905e341506a5f4d540ccbbd219d 100644 (file)
@@ -39,14 +39,21 @@ class UserImport
                $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;
                        }
                }
        }
index a9e57812ac6f07fe82776c578dfa77baabdc9f8d..9bdb6e1a10bdd91895dd6fcdf91f020b71e248f9 100644 (file)
@@ -72,7 +72,7 @@ class Mail
                        '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'],
index fd84f494e2d597f172269b64e5790d1a5e4c420a..9eb1506a2878deba0a71064205f189732960087d 100644 (file)
@@ -198,6 +198,43 @@ class Processor
                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
         *
index 74d939275225c186b2066a6e5ac8612f18efeae1..97bd7dc7e76a05007c6c9c8103138aa816314bb9 100644 (file)
@@ -226,6 +226,13 @@ class Receiver
                        $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');
@@ -366,6 +373,12 @@ class Receiver
                                }
                                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']);
index 7bf0acbc49852a627d1301fed09dacdf9a988d79..98b0d4d3ded25040de91d757c8e9737ec7a4deb8 100644 (file)
@@ -144,7 +144,7 @@ class Diaspora
         */
        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),
index 6a19e8e4587c929b80c0cf1895f187ad5383f033..4310046c234411b1f6fd6907f8613a4075ebc7c3 100644 (file)
@@ -32,10 +32,16 @@ class Emailer
         * @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");
@@ -87,11 +93,16 @@ class Emailer
                        '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'],