Improved checks when adding contacts
authorMichael <heluecht@pirati.ca>
Thu, 25 Mar 2021 05:45:16 +0000 (05:45 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 25 Mar 2021 05:45:16 +0000 (05:45 +0000)
mod/settings.php
src/Model/Contact.php

index c11ac37..414894e 100644 (file)
@@ -229,7 +229,7 @@ function settings_post(App $a)
                                notice(DI::l10n()->t('Contact CSV file upload error'));
                        } else {
                                $csvArray = array_map('str_getcsv', file($_FILES['importcontact-filename']['tmp_name']));
-                               Logger::info('Import started', ['lines' => count($csvArray)]);
+                               Logger::notice('Import started', ['lines' => count($csvArray)]);
                                // import contacts
                                foreach ($csvArray as $csvRow) {
                                        // The 1st row may, or may not contain the headers of the table
@@ -237,18 +237,20 @@ function settings_post(App $a)
                                        // or the handle of the account, therefore we check for either
                                        // "http" or "@" to be present in the string.
                                        // All other fields from the row will be ignored
-                                       if ((strpos($csvRow[0],'@') !== false) || (strpos($csvRow[0],'http') !== false)) {
+                                       if ((strpos($csvRow[0],'@') !== false) || in_array(parse_url($csvRow[0], PHP_URL_SCHEME), ['http', 'https'])) {
                                                Worker::add(PRIORITY_LOW, 'AddContact', $_SESSION['uid'], $csvRow[0]);
+                                       } else {
+                                               Logger::notice('Invalid account', ['url' => $csvRow[0]]);
                                        }
                                }
-                               Logger::info('Import done');
+                               Logger::notice('Import done');
 
                                info(DI::l10n()->t('Importing Contacts done'));
                                // delete temp file
                                unlink($_FILES['importcontact-filename']['tmp_name']);
                        }
                } else {
-                       Logger::info('Import triggered, but no import file was found.');
+                       Logger::notice('Import triggered, but no import file was found.');
                }
 
                return;
index b0b5fcc..c6e3a4c 100644 (file)
@@ -2821,6 +2821,9 @@ class Contact
                $count = 0;
 
                foreach ($urls as $url) {
+                       if (empty($url) || !is_string($url)) {
+                               continue;
+                       }
                        $contact = self::getByURL($url, false, ['id', 'updated']);
                        if (empty($contact['id'])) {
                                Worker::add(PRIORITY_LOW, 'AddContact', 0, $url);