]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #8209 from nupplaphil/task/mod_worker
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 31 Jan 2020 23:12:36 +0000 (18:12 -0500)
committerGitHub <noreply@github.com>
Fri, 31 Jan 2020 23:12:36 +0000 (18:12 -0500)
Move mod/worker to src\Module\Worker

53 files changed:
doc/API-Friendica.md
include/api.php
src/Collection/Api/Mastodon/Fields.php [new file with mode: 0644]
src/DI.php
src/Factory/Api/Mastodon/Account.php
src/Factory/Api/Mastodon/Field.php [new file with mode: 0644]
src/Model/Notify.php
src/Module/Admin/Addons/Details.php
src/Module/Admin/Addons/Index.php
src/Module/Admin/Blocklist/Contact.php
src/Module/Admin/Blocklist/Server.php
src/Module/Admin/DBSync.php
src/Module/Admin/Features.php
src/Module/Admin/Federation.php
src/Module/Admin/Item/Delete.php
src/Module/Admin/Item/Source.php
src/Module/Admin/Logs/Settings.php
src/Module/Admin/Logs/View.php
src/Module/Admin/PhpInfo.php
src/Module/Admin/Queue.php
src/Module/Admin/Site.php
src/Module/Admin/Summary.php
src/Module/Admin/Themes/Details.php
src/Module/Admin/Themes/Embed.php
src/Module/Admin/Themes/Index.php
src/Module/Admin/Tos.php
src/Module/Admin/Users.php
src/Module/Api/Friendica/Profile/Show.php [new file with mode: 0644]
src/Module/BaseAdmin.php [new file with mode: 0644]
src/Module/BaseAdminModule.php [deleted file]
src/Module/BaseApi.php
src/Module/BaseSearch.php [new file with mode: 0644]
src/Module/BaseSearchModule.php [deleted file]
src/Module/BaseSettings.php [new file with mode: 0644]
src/Module/BaseSettingsModule.php [deleted file]
src/Module/Notifications/Notification.php
src/Module/Search/Directory.php
src/Module/Search/Index.php
src/Module/Settings/Delegation.php
src/Module/Settings/Profile/Index.php
src/Module/Settings/Profile/Photo/Crop.php
src/Module/Settings/Profile/Photo/Index.php
src/Module/Settings/TwoFactor/AppSpecific.php
src/Module/Settings/TwoFactor/Index.php
src/Module/Settings/TwoFactor/Recovery.php
src/Module/Settings/TwoFactor/Verify.php
src/Module/Settings/UserExport.php
src/Object/Api/Mastodon/Account.php
src/Object/Api/Mastodon/Field.php
src/Object/Api/Mastodon/FollowRequest.php
src/Repository/Notify.php
static/routes.config.php
tests/include/ApiTest.php

index 84467430aea878385a086a05ed06ccd8df24a96d..013dd08f59584ebb349e758d961d99e78e97b978 100644 (file)
@@ -645,11 +645,7 @@ On error:
 
 ### GET api/friendica/profile/show
 
-Returns the [Profile](help/API-Entities#Profile) data of all profiles or a single profile of the authenticated user.
-
-#### Parameters
-
-* `profile_id` (optional): id of the profile to be returned. If omitted all profiles are returned by default.
+Returns the [Profile](help/API-Entities#Profile) data of the authenticated user.
 
 #### Return values
 
@@ -664,6 +660,23 @@ HTTP 403 Forbidden: when no authentication was provided
 HTTP 400 Bad Request: if given profile_id is not in the database or is not assigned to the authenticated user
 
 General description of profile data in API returns:
+- hide_friends: true if friends are hidden
+- profile_photo
+- profile_thumb
+- publish: true if published on the server's local directory
+- net_publish: true if published to global_dir
+- fullname
+- date_of_birth
+- description
+- xmpp
+- homepage
+- address
+- locality
+- region
+- postal_code
+- country
+- pub_keywords
+- custom_fields: list of public custom fields
 
 ---
 
index 3f4d5625b0f8b44f1d4931e141de6cdf33982edf..6f5120691cffe56f9e9ea9de52c763635d40b2cc 100644 (file)
@@ -2906,60 +2906,6 @@ function api_format_items_activities($item, $type = "json")
        return $activities;
 }
 
-
-/**
- * return data from profiles
- *
- * @param array $profile_row array containing data from db table 'profile'
- * @return array
- * @throws InternalServerErrorException
- */
-function api_format_items_profiles($profile_row)
-{
-       $profile = [
-               'profile_id'       => $profile_row['id'],
-               'profile_name'     => $profile_row['profile-name'],
-               'is_default'       => $profile_row['is-default'] ? true : false,
-               'hide_friends'     => $profile_row['hide-friends'] ? true : false,
-               'profile_photo'    => $profile_row['photo'],
-               'profile_thumb'    => $profile_row['thumb'],
-               'publish'          => $profile_row['publish'] ? true : false,
-               'net_publish'      => $profile_row['net-publish'] ? true : false,
-               'description'      => $profile_row['pdesc'],
-               'date_of_birth'    => $profile_row['dob'],
-               'address'          => $profile_row['address'],
-               'city'             => $profile_row['locality'],
-               'region'           => $profile_row['region'],
-               'postal_code'      => $profile_row['postal-code'],
-               'country'          => $profile_row['country-name'],
-               'hometown'         => $profile_row['hometown'],
-               'gender'           => $profile_row['gender'],
-               'marital'          => $profile_row['marital'],
-               'marital_with'     => $profile_row['with'],
-               'marital_since'    => $profile_row['howlong'],
-               'sexual'           => $profile_row['sexual'],
-               'politic'          => $profile_row['politic'],
-               'religion'         => $profile_row['religion'],
-               'public_keywords'  => $profile_row['pub_keywords'],
-               'private_keywords' => $profile_row['prv_keywords'],
-               'likes'            => BBCode::convert(api_clean_plain_items($profile_row['likes'])    , false, 2),
-               'dislikes'         => BBCode::convert(api_clean_plain_items($profile_row['dislikes']) , false, 2),
-               'about'            => BBCode::convert(api_clean_plain_items($profile_row['about'])    , false, 2),
-               'music'            => BBCode::convert(api_clean_plain_items($profile_row['music'])    , false, 2),
-               'book'             => BBCode::convert(api_clean_plain_items($profile_row['book'])     , false, 2),
-               'tv'               => BBCode::convert(api_clean_plain_items($profile_row['tv'])       , false, 2),
-               'film'             => BBCode::convert(api_clean_plain_items($profile_row['film'])     , false, 2),
-               'interest'         => BBCode::convert(api_clean_plain_items($profile_row['interest']) , false, 2),
-               'romance'          => BBCode::convert(api_clean_plain_items($profile_row['romance'])  , false, 2),
-               'work'             => BBCode::convert(api_clean_plain_items($profile_row['work'])     , false, 2),
-               'education'        => BBCode::convert(api_clean_plain_items($profile_row['education']), false, 2),
-               'social_networks'  => BBCode::convert(api_clean_plain_items($profile_row['contact'])  , false, 2),
-               'homepage'         => $profile_row['homepage'],
-               'users'            => null
-       ];
-       return $profile;
-}
-
 /**
  * format items to be returned by api
  *
@@ -5957,11 +5903,11 @@ function api_friendica_notification_seen($type)
        $id = (!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0);
 
        try {
-               $notification = DI::notify()->getByID($id);
-               $notification->setSeen();
+               $notify = DI::notify()->getByID($id);
+               DI::notify()->setSeen(true, $notify);
 
-               if ($notification->otype === Notify::OTYPE_ITEM) {
-                       $item = Item::selectFirstForUser(api_user(), [], ['id' => $notification->iid, 'uid' => api_user()]);
+               if ($notify->otype === Notify::OTYPE_ITEM) {
+                       $item = Item::selectFirstForUser(api_user(), [], ['id' => $notify->iid, 'uid' => api_user()]);
                        if (DBA::isResult($item)) {
                                // we found the item, return it to the user
                                $ret  = api_format_items([$item], $user_info, false, $type);
@@ -5972,7 +5918,9 @@ function api_friendica_notification_seen($type)
                }
                return api_format_data('result', $type, ['result' => "success"]);
        } catch (NotFoundException $e) {
-               throw new BadRequestException('Invalid argument');
+               throw new BadRequestException('Invalid argument', $e);
+       } catch (Exception $e) {
+               throw new InternalServerErrorException('Internal Server exception', $e);
        }
 }
 
@@ -6102,78 +6050,6 @@ function api_friendica_direct_messages_search($type, $box = "")
 /// @TODO move to top of file or somewhere better
 api_register_func('api/friendica/direct_messages_search', 'api_friendica_direct_messages_search', true);
 
-/**
- * return data of all the profiles a user has to the client
- *
- * @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
- * @return string|array
- * @throws BadRequestException
- * @throws ForbiddenException
- * @throws ImagickException
- * @throws InternalServerErrorException
- * @throws UnauthorizedException
- */
-function api_friendica_profile_show($type)
-{
-       $a = DI::app();
-
-       if (api_user() === false) {
-               throw new ForbiddenException();
-       }
-
-       // input params
-       $profile_id = $_REQUEST['profile_id'] ?? 0;
-
-       // retrieve general information about profiles for user
-       $multi_profiles = Feature::isEnabled(api_user(), 'multi_profiles');
-       $directory = DI::config()->get('system', 'directory');
-
-       // get data of the specified profile id or all profiles of the user if not specified
-       if ($profile_id != 0) {
-               $r = Profile::getById(api_user(), $profile_id);
-               // error message if specified gid is not in database
-               if (!DBA::isResult($r)) {
-                       throw new BadRequestException("profile_id not available");
-               }
-       } else {
-               $r = Profile::getListByUser(api_user());
-       }
-       // loop through all returned profiles and retrieve data and users
-       $k = 0;
-       $profiles = [];
-       if (DBA::isResult($r)) {
-               foreach ($r as $rr) {
-                       $profile = api_format_items_profiles($rr);
-
-                       // select all users from contact table, loop and prepare standard return for user data
-                       $users = [];
-                       $nurls = Contact::selectToArray(['id', 'nurl'], ['uid' => api_user(), 'profile-id' => $rr['id']]);
-                       foreach ($nurls as $nurl) {
-                               $user = api_get_user($a, $nurl['nurl']);
-                               ($type == "xml") ? $users[$k++ . ":user"] = $user : $users[] = $user;
-                       }
-                       $profile['users'] = $users;
-
-                       // add prepared profile data to array for final return
-                       if ($type == "xml") {
-                               $profiles[$k++ . ":profile"] = $profile;
-                       } else {
-                               $profiles[] = $profile;
-                       }
-               }
-       }
-
-       // return settings, authenticated user and profiles data
-       $self = DBA::selectFirst('contact', ['nurl'], ['uid' => api_user(), 'self' => true]);
-
-       $result = ['multi_profiles' => $multi_profiles ? true : false,
-                                       'global_dir' => $directory,
-                                       'friendica_owner' => api_get_user($a, $self['nurl']),
-                                       'profiles' => $profiles];
-       return api_format_data("friendica_profiles", $type, ['$result' => $result]);
-}
-api_register_func('api/friendica/profile/show', 'api_friendica_profile_show', true, API_METHOD_GET);
-
 /**
  * Returns a list of saved searches.
  *
diff --git a/src/Collection/Api/Mastodon/Fields.php b/src/Collection/Api/Mastodon/Fields.php
new file mode 100644 (file)
index 0000000..2bc549d
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+namespace Friendica\Collection\Api\Mastodon;
+
+use Friendica\Api\Entity\Mastodon\Field;
+use Friendica\BaseCollection;
+
+class Fields extends BaseCollection
+{
+       /**
+        * @param Field[]  $entities
+        * @param int|null $totalCount
+        */
+       public function __construct(array $entities = [], int $totalCount = null)
+       {
+               parent::__construct($entities);
+
+               $this->totalCount = $totalCount ?? count($entities);
+       }
+}
index 65c82225d54c1f3757283e6781094701cd1b2724..83351d34774bb860536e5cd76fd8c6021ae4370a 100644 (file)
@@ -236,6 +236,14 @@ abstract class DI
                return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
        }
 
+       /**
+        * @return Factory\Api\Mastodon\Field
+        */
+       public static function mstdnField()
+       {
+               return self::$dice->create(Factory\Api\Mastodon\Field::class);
+       }
+
        /**
         * @return Factory\Api\Mastodon\FollowRequest
         */
index 60f9a76e11684739da88f2e15a2e37d0c46a6488..a58f8941efc52abbf72fda945ace2f6711209995 100644 (file)
@@ -4,26 +4,35 @@ namespace Friendica\Factory\Api\Mastodon;
 
 use Friendica\App\BaseURL;
 use Friendica\BaseFactory;
+use Friendica\Collection\Api\Mastodon\Fields;
 use Friendica\Model\APContact;
 use Friendica\Model\Contact;
 use Friendica\Network\HTTPException;
+use Friendica\Repository\PermissionSet;
+use Friendica\Repository\ProfileField;
 use Psr\Log\LoggerInterface;
 
 class Account extends BaseFactory
 {
        /** @var BaseURL */
        protected $baseUrl;
+       /** @var ProfileField */
+       protected $profileField;
+       /** @var Field */
+       protected $mstdnField;
 
-       public function __construct(LoggerInterface $logger, BaseURL $baseURL)
+       public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField)
        {
                parent::__construct($logger);
 
                $this->baseUrl = $baseURL;
+               $this->profileField = $profileField;
+               $this->mstdnField = $mstdnField;
        }
 
        /**
         * @param int $contactId
-        * @param int $uid        User Id
+        * @param int $uid        Public contact (=0) or owner user id
         * @return \Friendica\Object\Api\Mastodon\Account
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
@@ -41,6 +50,24 @@ class Account extends BaseFactory
 
                $apcontact = APContact::getByURL($publicContact['url'], false);
 
-               return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $apcontact, $userContact);
+               return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, new Fields(), $apcontact, $userContact);
+       }
+
+       /**
+        * @param int $userId
+        * @return \Friendica\Object\Api\Mastodon\Account
+        * @throws HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public function createFromUserId(int $userId)
+       {
+               $publicContact = Contact::selectFirst([], ['uid' => $userId, 'self' => true]);
+
+               $profileFields = $this->profileField->select(['uid' => $userId, 'psid' => PermissionSet::PUBLIC]);
+               $fields        = $this->mstdnField->createFromProfileFields($profileFields);
+
+               $apcontact     = APContact::getByURL($publicContact['url'], false);
+
+               return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $fields, $apcontact);
        }
 }
diff --git a/src/Factory/Api/Mastodon/Field.php b/src/Factory/Api/Mastodon/Field.php
new file mode 100644 (file)
index 0000000..10bb269
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+namespace Friendica\Factory\Api\Mastodon;
+
+use Friendica\BaseFactory;
+use Friendica\Collection\Api\Mastodon\Fields;
+use Friendica\Collection\ProfileFields;
+use Friendica\Content\Text\BBCode;
+use Friendica\Model\ProfileField;
+use Friendica\Network\HTTPException;
+
+class Field extends BaseFactory
+{
+       /**
+        * @param ProfileField $profileField
+        * @return \Friendica\Api\Entity\Mastodon\Field
+        * @throws HTTPException\InternalServerErrorException
+        */
+       public function createFromProfileField(ProfileField $profileField)
+       {
+               return new \Friendica\Api\Entity\Mastodon\Field($profileField->label, BBCode::convert($profileField->value, false, 9));
+       }
+
+       /**
+        * @param ProfileFields $profileFields
+        * @return Fields
+        * @throws HTTPException\InternalServerErrorException
+        */
+       public function createFromProfileFields(ProfileFields $profileFields)
+       {
+               $fields = [];
+
+               foreach ($profileFields as $profileField) {
+                       $fields[] = $this->createFromProfileField($profileField);
+               }
+
+               return new Fields($fields);
+       }
+}
index b12eb341b0d188d4adbcdf4f8308e6301925584f..35d72384e89526cb94e362dbd1bbab159db67478 100644 (file)
@@ -2,7 +2,6 @@
 
 namespace Friendica\Model;
 
-use Exception;
 use Friendica\BaseModel;
 use Friendica\Content\Text\BBCode;
 use Friendica\Database\Database;
@@ -50,24 +49,6 @@ class Notify extends BaseModel
                $this->setMsgCache();
        }
 
-       /**
-        * Set the notification as seen
-        *
-        * @param bool $seen true, if seen
-        *
-        * @return bool True, if the seen state could be saved
-        */
-       public function setSeen(bool $seen = true)
-       {
-               $this->seen = $seen;
-               try {
-                       return $this->repo->update($this);
-               } catch (Exception $e) {
-                       $this->logger->warning('Update failed.', ['$this' => $this, 'exception' => $e]);
-                       return false;
-               }
-       }
-
        /**
         * Sets the pre-formatted name (caching)
         */
index ebf87deda42bcf74ad7696c4194b66129cd355ef..94d31b65a6d1676b1c032e110e1c680a858d5cb8 100644 (file)
@@ -6,10 +6,10 @@ use Friendica\Content\Text\Markdown;
 use Friendica\Core\Addon;
 use Friendica\Core\Renderer;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 use Friendica\Util\Strings;
 
-class Details extends BaseAdminModule
+class Details extends BaseAdmin
 {
        public static function post(array $parameters = [])
        {
index 634bd08c702b08284b46f51a293759f67346b8cc..74bd61b5fd8892cead049b9de4cdc6ae2b6d1d59 100644 (file)
@@ -5,9 +5,9 @@ namespace Friendica\Module\Admin\Addons;
 use Friendica\Core\Addon;
 use Friendica\Core\Renderer;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 
-class Index extends BaseAdminModule
+class Index extends BaseAdmin
 {
        public static function content(array $parameters = [])
        {
index 8eaf418a85fa10351df2f0938bbd4302ba4a4991..871a7ea7471e6bc068e93264306a8b10ad4c16b7 100644 (file)
@@ -6,10 +6,10 @@ use Friendica\Content\Pager;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 use Friendica\Model;
 
-class Contact extends BaseAdminModule
+class Contact extends BaseAdmin
 {
        public static function post(array $parameters = [])
        {
index 6c07885993b1c54d5aab2c5a57f2ffa0c1c2bc14..971b890474097ddcf55210bda6c2f78d49917e41 100644 (file)
@@ -4,10 +4,10 @@ namespace Friendica\Module\Admin\Blocklist;
 
 use Friendica\Core\Renderer;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 use Friendica\Util\Strings;
 
-class Server extends BaseAdminModule
+class Server extends BaseAdmin
 {
        public static function post(array $parameters = [])
        {
index c342db93b426bde2641533e39d9716e85407f189..eb7c84c9bac2a0f611ffa8967d9c36ca9f228f30 100644 (file)
@@ -7,9 +7,9 @@ use Friendica\Core\Update;
 use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 
-class DBSync extends BaseAdminModule
+class DBSync extends BaseAdmin
 {
        public static function content(array $parameters = [])
        {
index ed5abec95a1daecd7e0cac23692cd007d4d79d5a..5e1c3df20eaeecc4155853844b7e6a43fe921812 100644 (file)
@@ -5,9 +5,9 @@ namespace Friendica\Module\Admin;
 use Friendica\Content\Feature;
 use Friendica\Core\Renderer;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 
-class Features extends BaseAdminModule
+class Features extends BaseAdmin
 {
        public static function post(array $parameters = [])
        {
index 0d83cc41a1e2507337158a4dbd2b9b333feae2a3..f5e38f0d2d672a064db994a98ab496c1150bd078 100644 (file)
@@ -5,9 +5,9 @@ namespace Friendica\Module\Admin;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 
-class Federation extends BaseAdminModule
+class Federation extends BaseAdmin
 {
        public static function content(array $parameters = [])
        {
index 1d7e459a2755f10629c516b46d711ccb5aef9c39..424fef2b5233aab5c52fa25914a0b9bdf6250101 100644 (file)
@@ -5,10 +5,10 @@ namespace Friendica\Module\Admin\Item;
 use Friendica\Core\Renderer;
 use Friendica\DI;
 use Friendica\Model\Item;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 use Friendica\Util\Strings;
 
-class Delete extends BaseAdminModule
+class Delete extends BaseAdmin
 {
        public static function post(array $parameters = [])
        {
index d4666b27f854922473dacaec17f4f90ed8b06ee4..a3f6dd0c55757bac2f1f06cf02308d192307ed6a 100644 (file)
@@ -5,12 +5,12 @@ namespace Friendica\Module\Admin\Item;
 use Friendica\Core\Renderer;
 use Friendica\DI;
 use Friendica\Model;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 
 /**
  * @author Hypolite Petovan <mrpetovan@gmail.com>
  */
-class Source extends BaseAdminModule
+class Source extends BaseAdmin
 
 {
        public static function content(array $parameters = [])
index 6b3f2027dc18e5d32cdf0045bce820b878408ab4..b8e588cd7d15308a3560504fbdbafa82e1d1191d 100644 (file)
@@ -4,11 +4,11 @@ namespace Friendica\Module\Admin\Logs;
 
 use Friendica\Core\Renderer;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 use Friendica\Util\Strings;
 use Psr\Log\LogLevel;
 
-class Settings extends BaseAdminModule
+class Settings extends BaseAdmin
 {
        public static function post(array $parameters = [])
        {
index a6607829de50aff6381e9fa7d1321f2b263a5922..dc2274ce7a2997dd55a9780ae3342fa015495100 100644 (file)
@@ -4,10 +4,10 @@ namespace Friendica\Module\Admin\Logs;
 
 use Friendica\Core\Renderer;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 use Friendica\Util\Strings;
 
-class View extends BaseAdminModule
+class View extends BaseAdmin
 {
        public static function content(array $parameters = [])
        {
index 3ac7421816bdbd59f4a70bd758dda5d0c9d65092..465962eb7109051fc0e015b05b072f5830692f59 100644 (file)
@@ -2,9 +2,9 @@
 
 namespace Friendica\Module\Admin;
 
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 
-class PhpInfo extends BaseAdminModule
+class PhpInfo extends BaseAdmin
 {
        public static function rawContent(array $parameters = [])
        {
index a9295f6f929841adc377a4ef76850d474bfc0ae3..59912fc6c9ca83a3b875d88f3cc1aa37540e228c 100644 (file)
@@ -5,7 +5,7 @@ namespace Friendica\Module\Admin;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 use Friendica\Util\Arrays;
 use Friendica\Util\DateTimeFormat;
 
@@ -17,7 +17,7 @@ use Friendica\Util\DateTimeFormat;
  *
  * @return string
  */
-class Queue extends BaseAdminModule
+class Queue extends BaseAdmin
 {
        public static function content(array $parameters = [])
        {
index 131ebb88ef5146cff40a619ce1158b9d845d0d0c..7cb3a9b8f7f07443d2d4c1cd3cde855eaf726d27 100644 (file)
@@ -9,7 +9,7 @@ use Friendica\Core\Theme;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 use Friendica\Module\Register;
 use Friendica\Protocol\PortableContact;
 use Friendica\Util\BasePath;
@@ -18,7 +18,7 @@ use Friendica\Worker\Delivery;
 
 require_once __DIR__ . '/../../../boot.php';
 
-class Site extends BaseAdminModule
+class Site extends BaseAdmin
 {
        public static function post(array $parameters = [])
        {
index 234a49b410d4591fb163e9de3e148499e643623a..4c424a059c45f4d55a6ce05af40787fb4054848d 100644 (file)
@@ -11,13 +11,13 @@ use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use Friendica\DI;
 use Friendica\Model\Register;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Util\ConfigFileLoader;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 
-class Summary extends BaseAdminModule
+class Summary extends BaseAdmin
 {
        public static function content(array $parameters = [])
        {
index f1263e6ca90d2dae90955b6271f253c1e37ebffe..a1617954f10bf5d8b99e4e349f26a214553fb4ae 100644 (file)
@@ -6,10 +6,10 @@ use Friendica\Content\Text\Markdown;
 use Friendica\Core\Renderer;
 use Friendica\Core\Theme;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 use Friendica\Util\Strings;
 
-class Details extends BaseAdminModule
+class Details extends BaseAdmin
 {
        public static function post(array $parameters = [])
        {
index 00d4de6953ee3bc84adcfa78137d5bb099718249..50ecff9322c42387794bed12dc44465e76f1eb3d 100644 (file)
@@ -4,10 +4,10 @@ namespace Friendica\Module\Admin\Themes;
 
 use Friendica\Core\Renderer;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 use Friendica\Util\Strings;
 
-class Embed extends BaseAdminModule
+class Embed extends BaseAdmin
 {
        public static function init(array $parameters = [])
        {
index c6c86b0a9992fc982c426ff0252f836c67707e4d..4c73a36de87d7bf7f6d69f7f8594dfb6ddc81ec4 100644 (file)
@@ -5,10 +5,10 @@ namespace Friendica\Module\Admin\Themes;
 use Friendica\Core\Renderer;
 use Friendica\Core\Theme;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 use Friendica\Util\Strings;
 
-class Index extends BaseAdminModule
+class Index extends BaseAdmin
 {
        public static function content(array $parameters = [])
        {
index 4c4f31b655751c3781939ffb809f2722979cf257..b89887dae8b3fbe97e2d869049c5451f7e70dcf0 100644 (file)
@@ -4,9 +4,9 @@ namespace Friendica\Module\Admin;
 
 use Friendica\Core\Renderer;
 use Friendica\DI;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 
-class Tos extends BaseAdminModule
+class Tos extends BaseAdmin
 {
        public static function post(array $parameters = [])
        {
index c4a30abd65ebe627c2ee6b5c67e910e58958ab2c..0498a80da12d5c1a88060bb49d6a187187b3c3e6 100644 (file)
@@ -8,11 +8,11 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Register;
 use Friendica\Model\User;
-use Friendica\Module\BaseAdminModule;
+use Friendica\Module\BaseAdmin;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
-class Users extends BaseAdminModule
+class Users extends BaseAdmin
 {
        public static function post(array $parameters = [])
        {
diff --git a/src/Module/Api/Friendica/Profile/Show.php b/src/Module/Api/Friendica/Profile/Show.php
new file mode 100644 (file)
index 0000000..2c50c53
--- /dev/null
@@ -0,0 +1,114 @@
+<?php
+
+namespace Friendica\Module\Api\Friendica\Profile;
+
+use Friendica\Collection\ProfileFields;
+use Friendica\Content\Text\BBCode;
+use Friendica\DI;
+use Friendica\Model\Contact;
+use Friendica\Model\Profile;
+use Friendica\Module\BaseApi;
+use Friendica\Network\HTTPException;
+use Friendica\Repository\PermissionSet;
+
+/**
+ * API endpoint: /api/friendica/profile/show
+ */
+class Show extends BaseApi
+{
+       public static function rawContent(array $parameters = [])
+       {
+               if (self::login() === false) {
+                       throw new HTTPException\ForbiddenException();
+               }
+
+               // retrieve general information about profiles for user
+               $directory = DI::config()->get('system', 'directory');
+
+               $profile = Profile::getByUID(self::$current_user_id);
+               
+               $profileFields = DI::profileField()->select(['uid' => self::$current_user_id, 'psid' => PermissionSet::PUBLIC]);
+
+               $profile = self::formatProfile($profile, $profileFields);
+
+               $profiles = [];
+               if (self::$format == 'xml') {
+                       $profiles['0:profile'] = $profile;
+               } else {
+                       $profiles[] = $profile;
+               }
+
+               // return settings, authenticated user and profiles data
+               $self = Contact::selectFirst(['nurl'], ['uid' => self::$current_user_id, 'self' => true]);
+
+               $result = [
+                       'multi_profiles' => false,
+                       'global_dir' => $directory,
+                       'friendica_owner' => self::getUser($self['nurl']),
+                       'profiles' => $profiles
+               ];
+
+               echo self::format('friendica_profiles', ['$result' => $result]);
+               exit;
+       }
+
+       /**
+        * @param array         $profile_row array containing data from db table 'profile'
+        * @param ProfileFields $profileFields
+        * @return array
+        * @throws HTTPException\InternalServerErrorException
+        */
+       private static function formatProfile($profile_row, ProfileFields $profileFields)
+       {
+               $custom_fields = [];
+               foreach ($profileFields as $profileField) {
+                       $custom_fields[] = [
+                               'label' => $profileField->label,
+                               'value' => BBCode::convert($profileField->value, false, 2),
+                       ];
+               }
+
+               return [
+                       'profile_id'       => $profile_row['id'],
+                       'profile_name'     => null,
+                       'is_default'       => null,
+                       'hide_friends'     => $profile_row['hide-friends'] ? true : false,
+                       'profile_photo'    => $profile_row['photo'],
+                       'profile_thumb'    => $profile_row['thumb'],
+                       'publish'          => $profile_row['publish'] ? true : false,
+                       'net_publish'      => $profile_row['net-publish'] ? true : false,
+                       'description'      => $profile_row['pdesc'],
+                       'date_of_birth'    => $profile_row['dob'],
+                       'address'          => $profile_row['address'],
+                       'city'             => $profile_row['locality'],
+                       'region'           => $profile_row['region'],
+                       'postal_code'      => $profile_row['postal-code'],
+                       'country'          => $profile_row['country-name'],
+                       'hometown'         => null,
+                       'gender'           => null,
+                       'marital'          => null,
+                       'marital_with'     => null,
+                       'marital_since'    => null,
+                       'sexual'           => null,
+                       'politic'          => null,
+                       'religion'         => null,
+                       'public_keywords'  => $profile_row['pub_keywords'],
+                       'private_keywords' => $profile_row['prv_keywords'],
+                       'likes'            => null,
+                       'dislikes'         => null,
+                       'about'            => null,
+                       'music'            => null,
+                       'book'             => null,
+                       'tv'               => null,
+                       'film'             => null,
+                       'interest'         => null,
+                       'romance'          => null,
+                       'work'             => null,
+                       'education'        => null,
+                       'social_networks'  => null,
+                       'homepage'         => $profile_row['homepage'],
+                       'users'            => [],
+                       'custom_fields'    => $custom_fields,
+               ];
+       }
+}
diff --git a/src/Module/BaseAdmin.php b/src/Module/BaseAdmin.php
new file mode 100644 (file)
index 0000000..b776c8b
--- /dev/null
@@ -0,0 +1,120 @@
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Core\Addon;
+use Friendica\Core\Renderer;
+use Friendica\Core\Session;
+use Friendica\DI;
+use Friendica\Network\HTTPException\ForbiddenException;
+
+require_once 'boot.php';
+
+/**
+ * This abstract module is meant to be extended by all modules that are reserved to administrator users.
+ *
+ * It performs a blanket permission check in all the module methods as long as the relevant `parent::method()` is
+ * called in the inheriting module.
+ *
+ * Additionally, it puts together the administration page aside with all the administration links.
+ *
+ * @package Friendica\Module
+ */
+abstract class BaseAdmin extends BaseModule
+{
+       public static function post(array $parameters = [])
+       {
+               if (!is_site_admin()) {
+                       return;
+               }
+
+               // do not allow a page manager to access the admin panel at all.
+               if (!empty($_SESSION['submanage'])) {
+                       return;
+               }
+       }
+
+       public static function rawContent(array $parameters = [])
+       {
+               if (!is_site_admin()) {
+                       return '';
+               }
+
+               if (!empty($_SESSION['submanage'])) {
+                       return '';
+               }
+
+               return '';
+       }
+
+       public static function content(array $parameters = [])
+       {
+               if (!is_site_admin()) {
+                       notice(DI::l10n()->t('Please login to continue.'));
+                       Session::set('return_path', DI::args()->getQueryString());
+                       DI::baseUrl()->redirect('login');
+               }
+
+               if (!empty($_SESSION['submanage'])) {
+                       throw new ForbiddenException(DI::l10n()->t('Submanaged account can\'t access the administation pages. Please log back in as the master account.'));
+               }
+
+               // Header stuff
+               DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/settings_head.tpl'), []);
+
+               /*
+                * Side bar links
+                */
+
+               // array(url, name, extra css classes)
+               // not part of $aside to make the template more adjustable
+               $aside_sub = [
+                       'information' => [DI::l10n()->t('Information'), [
+                               'overview'     => ['admin'             , DI::l10n()->t('Overview')                , 'overview'],
+                               'federation'   => ['admin/federation'  , DI::l10n()->t('Federation Statistics')   , 'federation']
+                       ]],
+                       'configuration' => [DI::l10n()->t('Configuration'), [
+                               'site'         => ['admin/site'        , DI::l10n()->t('Site')                    , 'site'],
+                               'users'        => ['admin/users'       , DI::l10n()->t('Users')                   , 'users'],
+                               'addons'       => ['admin/addons'      , DI::l10n()->t('Addons')                  , 'addons'],
+                               'themes'       => ['admin/themes'      , DI::l10n()->t('Themes')                  , 'themes'],
+                               'features'     => ['admin/features'    , DI::l10n()->t('Additional features')     , 'features'],
+                               'tos'          => ['admin/tos'         , DI::l10n()->t('Terms of Service')        , 'tos'],
+                       ]],
+                       'database' => [DI::l10n()->t('Database'), [
+                               'dbsync'       => ['admin/dbsync'      , DI::l10n()->t('DB updates')              , 'dbsync'],
+                               'deferred'     => ['admin/queue/deferred', DI::l10n()->t('Inspect Deferred Workers'), 'deferred'],
+                               'workerqueue'  => ['admin/queue'       , DI::l10n()->t('Inspect worker Queue')    , 'workerqueue'],
+                       ]],
+                       'tools' => [DI::l10n()->t('Tools'), [
+                               'contactblock' => ['admin/blocklist/contact', DI::l10n()->t('Contact Blocklist')  , 'contactblock'],
+                               'blocklist'    => ['admin/blocklist/server' , DI::l10n()->t('Server Blocklist')   , 'blocklist'],
+                               'deleteitem'   => ['admin/item/delete' , DI::l10n()->t('Delete Item')             , 'deleteitem'],
+                       ]],
+                       'logs' => [DI::l10n()->t('Logs'), [
+                               'logsconfig'   => ['admin/logs/', DI::l10n()->t('Logs')                           , 'logs'],
+                               'logsview'     => ['admin/logs/view'    , DI::l10n()->t('View Logs')              , 'viewlogs'],
+                       ]],
+                       'diagnostics' => [DI::l10n()->t('Diagnostics'), [
+                               'phpinfo'      => ['admin/phpinfo'           , DI::l10n()->t('PHP Info')          , 'phpinfo'],
+                               'probe'        => ['probe'             , DI::l10n()->t('probe address')           , 'probe'],
+                               'webfinger'    => ['webfinger'         , DI::l10n()->t('check webfinger')         , 'webfinger'],
+                               'itemsource'   => ['admin/item/source' , DI::l10n()->t('Item Source')             , 'itemsource'],
+                               'babel'        => ['babel'             , DI::l10n()->t('Babel')                   , 'babel'],
+                       ]],
+               ];
+
+               $t = Renderer::getMarkupTemplate('admin/aside.tpl');
+               DI::page()['aside'] .= Renderer::replaceMacros($t, [
+                       '$admin' => ['addons_admin' => Addon::getAdminList()],
+                       '$subpages' => $aside_sub,
+                       '$admtxt' => DI::l10n()->t('Admin'),
+                       '$plugadmtxt' => DI::l10n()->t('Addon Features'),
+                       '$h_pending' => DI::l10n()->t('User registrations waiting for confirmation'),
+                       '$admurl' => 'admin/'
+               ]);
+
+               return '';
+       }
+}
diff --git a/src/Module/BaseAdminModule.php b/src/Module/BaseAdminModule.php
deleted file mode 100644 (file)
index f0cfb0c..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-<?php
-
-namespace Friendica\Module;
-
-use Friendica\BaseModule;
-use Friendica\Core\Addon;
-use Friendica\Core\Renderer;
-use Friendica\Core\Session;
-use Friendica\DI;
-use Friendica\Network\HTTPException\ForbiddenException;
-
-require_once 'boot.php';
-
-/**
- * This abstract module is meant to be extended by all modules that are reserved to administrator users.
- *
- * It performs a blanket permission check in all the module methods as long as the relevant `parent::method()` is
- * called in the inheriting module.
- *
- * Additionally, it puts together the administration page aside with all the administration links.
- *
- * @package Friendica\Module
- */
-abstract class BaseAdminModule extends BaseModule
-{
-       public static function post(array $parameters = [])
-       {
-               if (!is_site_admin()) {
-                       return;
-               }
-
-               // do not allow a page manager to access the admin panel at all.
-               if (!empty($_SESSION['submanage'])) {
-                       return;
-               }
-       }
-
-       public static function rawContent(array $parameters = [])
-       {
-               if (!is_site_admin()) {
-                       return '';
-               }
-
-               if (!empty($_SESSION['submanage'])) {
-                       return '';
-               }
-
-               return '';
-       }
-
-       public static function content(array $parameters = [])
-       {
-               if (!is_site_admin()) {
-                       notice(DI::l10n()->t('Please login to continue.'));
-                       Session::set('return_path', DI::args()->getQueryString());
-                       DI::baseUrl()->redirect('login');
-               }
-
-               if (!empty($_SESSION['submanage'])) {
-                       throw new ForbiddenException(DI::l10n()->t('Submanaged account can\'t access the administation pages. Please log back in as the master account.'));
-               }
-
-               // Header stuff
-               DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/settings_head.tpl'), []);
-
-               /*
-                * Side bar links
-                */
-
-               // array(url, name, extra css classes)
-               // not part of $aside to make the template more adjustable
-               $aside_sub = [
-                       'information' => [DI::l10n()->t('Information'), [
-                               'overview'     => ['admin'             , DI::l10n()->t('Overview')                , 'overview'],
-                               'federation'   => ['admin/federation'  , DI::l10n()->t('Federation Statistics')   , 'federation']
-                       ]],
-                       'configuration' => [DI::l10n()->t('Configuration'), [
-                               'site'         => ['admin/site'        , DI::l10n()->t('Site')                    , 'site'],
-                               'users'        => ['admin/users'       , DI::l10n()->t('Users')                   , 'users'],
-                               'addons'       => ['admin/addons'      , DI::l10n()->t('Addons')                  , 'addons'],
-                               'themes'       => ['admin/themes'      , DI::l10n()->t('Themes')                  , 'themes'],
-                               'features'     => ['admin/features'    , DI::l10n()->t('Additional features')     , 'features'],
-                               'tos'          => ['admin/tos'         , DI::l10n()->t('Terms of Service')        , 'tos'],
-                       ]],
-                       'database' => [DI::l10n()->t('Database'), [
-                               'dbsync'       => ['admin/dbsync'      , DI::l10n()->t('DB updates')              , 'dbsync'],
-                               'deferred'     => ['admin/queue/deferred', DI::l10n()->t('Inspect Deferred Workers'), 'deferred'],
-                               'workerqueue'  => ['admin/queue'       , DI::l10n()->t('Inspect worker Queue')    , 'workerqueue'],
-                       ]],
-                       'tools' => [DI::l10n()->t('Tools'), [
-                               'contactblock' => ['admin/blocklist/contact', DI::l10n()->t('Contact Blocklist')  , 'contactblock'],
-                               'blocklist'    => ['admin/blocklist/server' , DI::l10n()->t('Server Blocklist')   , 'blocklist'],
-                               'deleteitem'   => ['admin/item/delete' , DI::l10n()->t('Delete Item')             , 'deleteitem'],
-                       ]],
-                       'logs' => [DI::l10n()->t('Logs'), [
-                               'logsconfig'   => ['admin/logs/', DI::l10n()->t('Logs')                           , 'logs'],
-                               'logsview'     => ['admin/logs/view'    , DI::l10n()->t('View Logs')              , 'viewlogs'],
-                       ]],
-                       'diagnostics' => [DI::l10n()->t('Diagnostics'), [
-                               'phpinfo'      => ['admin/phpinfo'           , DI::l10n()->t('PHP Info')          , 'phpinfo'],
-                               'probe'        => ['probe'             , DI::l10n()->t('probe address')           , 'probe'],
-                               'webfinger'    => ['webfinger'         , DI::l10n()->t('check webfinger')         , 'webfinger'],
-                               'itemsource'   => ['admin/item/source' , DI::l10n()->t('Item Source')             , 'itemsource'],
-                               'babel'        => ['babel'             , DI::l10n()->t('Babel')                   , 'babel'],
-                       ]],
-               ];
-
-               $t = Renderer::getMarkupTemplate('admin/aside.tpl');
-               DI::page()['aside'] .= Renderer::replaceMacros($t, [
-                       '$admin' => ['addons_admin' => Addon::getAdminList()],
-                       '$subpages' => $aside_sub,
-                       '$admtxt' => DI::l10n()->t('Admin'),
-                       '$plugadmtxt' => DI::l10n()->t('Addon Features'),
-                       '$h_pending' => DI::l10n()->t('User registrations waiting for confirmation'),
-                       '$admurl' => 'admin/'
-               ]);
-
-               return '';
-       }
-}
index 81814bb0d497cb5e6870728d433a43a7aca83dd4..543293872db877db068378a984f5098fb82cc9c8 100644 (file)
@@ -87,20 +87,53 @@ class BaseApi extends BaseModule
                return api_get_user(DI::app(), $contact_id);
        }
 
-       protected static function format($root_element, $data)
+       /**
+        * Formats the data according to the data type
+        *
+        * @param string $root_element
+        * @param array $data An array with a single element containing the returned result
+        * @return false|string
+        */
+       protected static function format(string $root_element, array $data)
        {
+               $return = api_format_data($root_element, self::$format, $data);
+
                switch (self::$format) {
-                       case "atom":
-                       case "rss":
                        case "xml":
-                               $ret = api_create_xml($data, $root_element);
+                               header("Content-Type: text/xml");
                                break;
                        case "json":
-                       default:
-                               $ret = $data;
+                               header("Content-Type: application/json");
+                               if (!empty($return)) {
+                                       $json = json_encode(end($return));
+                                       if (!empty($_GET['callback'])) {
+                                               $json = $_GET['callback'] . "(" . $json . ")";
+                                       }
+                                       $return = $json;
+                               }
+                               break;
+                       case "rss":
+                               header("Content-Type: application/rss+xml");
+                               $return  = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $return;
+                               break;
+                       case "atom":
+                               header("Content-Type: application/atom+xml");
+                               $return = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $return;
                                break;
                }
+               
+               return $return;
+       }
 
-               return $ret;
+       /**
+        * Creates the XML from a JSON style array
+        *
+        * @param $data
+        * @param $root_element
+        * @return string
+        */
+       protected static function createXml($data, $root_element)
+       {
+               return api_create_xml($data, $root_element);
        }
 }
diff --git a/src/Module/BaseSearch.php b/src/Module/BaseSearch.php
new file mode 100644 (file)
index 0000000..26b3ea6
--- /dev/null
@@ -0,0 +1,166 @@
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Content\ContactSelector;
+use Friendica\Content\Pager;
+use Friendica\Core\Renderer;
+use Friendica\Core\Search;
+use Friendica\DI;
+use Friendica\Model;
+use Friendica\Network\HTTPException;
+use Friendica\Object\Search\ContactResult;
+use Friendica\Object\Search\ResultList;
+use Friendica\Util\Proxy as ProxyUtils;
+
+/**
+ * Base class for search modules
+ */
+class BaseSearch extends BaseModule
+{
+       /**
+        * Performs a contact search with an optional prefix
+        *
+        * @param string $search Search query
+        * @param string $prefix A optional prefix (e.g. @ or !) for searching
+        *
+        * @return string
+        * @throws HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public static function performContactSearch($search, $prefix = '')
+       {
+               $a      = DI::app();
+               $config = DI::config();
+
+               $type = Search::TYPE_ALL;
+
+               $localSearch = $config->get('system', 'poco_local_search');
+
+               $search = $prefix . $search;
+
+               if (!$search) {
+                       return '';
+               }
+
+               $header = '';
+
+               if (strpos($search, '@') === 0) {
+                       $search  = substr($search, 1);
+                       $type    = Search::TYPE_PEOPLE;
+                       $header  = DI::l10n()->t('People Search - %s', $search);
+
+                       if (strrpos($search, '@') > 0) {
+                               $results = Search::getContactsFromProbe($search);
+                       }
+               }
+
+               if (strpos($search, '!') === 0) {
+                       $search = substr($search, 1);
+                       $type   = Search::TYPE_FORUM;
+                       $header = DI::l10n()->t('Forum Search - %s', $search);
+               }
+
+               $args = DI::args();
+               $pager = new Pager($args->getQueryString());
+
+               if ($localSearch && empty($results)) {
+                       $pager->setItemsPerPage(80);
+                       $results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage());
+               } elseif (strlen($config->get('system', 'directory')) && empty($results)) {
+                       $results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage());
+                       $pager->setItemsPerPage($results->getItemsPage());
+               }
+
+               return self::printResult($results, $pager, $header);
+       }
+
+       /**
+        * Prints a human readable search result
+        *
+        * @param ResultList $results
+        * @param Pager      $pager
+        * @param string     $header
+        *
+        * @return string The result
+        * @throws HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       protected static function printResult(ResultList $results, Pager $pager, $header = '')
+       {
+               if ($results->getTotal() == 0) {
+                       info(DI::l10n()->t('No matches'));
+                       return '';
+               }
+
+               $id      = 0;
+               $entries = [];
+               foreach ($results->getResults() as $result) {
+
+                       // in case the result is a contact result, add a contact-specific entry
+                       if ($result instanceof ContactResult) {
+
+                               $alt_text    = '';
+                               $location    = '';
+                               $about       = '';
+                               $accountType = '';
+                               $photo_menu  = [];
+
+                               // If We already know this contact then don't show the "connect" button
+                               if ($result->getCid() > 0 || $result->getPCid() > 0) {
+                                       $connLink = "";
+                                       $connTxt  = "";
+                                       $contact  = Model\Contact::getById(
+                                               ($result->getCid() > 0) ? $result->getCid() : $result->getPCid()
+                                       );
+
+                                       if (!empty($contact)) {
+                                               $photo_menu  = Model\Contact::photoMenu($contact);
+                                               $details     = Contact::getContactTemplateVars($contact);
+                                               $alt_text    = $details['alt_text'];
+                                               $location    = $contact['location'];
+                                               $about       = $contact['about'];
+                                               $accountType = Model\Contact::getAccountType($contact);
+                                       } else {
+                                               $photo_menu = [];
+                                       }
+                               } else {
+                                       $connLink = DI::baseUrl()->get() . '/follow/?url=' . $result->getUrl();
+                                       $connTxt  = DI::l10n()->t('Connect');
+
+                                       $photo_menu['profile'] = [DI::l10n()->t("View Profile"), Model\Contact::magicLink($result->getUrl())];
+                                       $photo_menu['follow']  = [DI::l10n()->t("Connect/Follow"), $connLink];
+                               }
+
+                               $photo = str_replace("http:///photo/", Search::getGlobalDirectory() . "/photo/", $result->getPhoto());
+
+                               $entry     = [
+                                       'alt_text'     => $alt_text,
+                                       'url'          => Model\Contact::magicLink($result->getUrl()),
+                                       'itemurl'      => $result->getItem(),
+                                       'name'         => $result->getName(),
+                                       'thumb'        => ProxyUtils::proxifyUrl($photo, false, ProxyUtils::SIZE_THUMB),
+                                       'img_hover'    => $result->getTags(),
+                                       'conntxt'      => $connTxt,
+                                       'connlnk'      => $connLink,
+                                       'photo_menu'   => $photo_menu,
+                                       'details'      => $location,
+                                       'tags'         => $result->getTags(),
+                                       'about'        => $about,
+                                       'account_type' => $accountType,
+                                       'network'      => ContactSelector::networkToName($result->getNetwork(), $result->getUrl()),
+                                       'id'           => ++$id,
+                               ];
+                               $entries[] = $entry;
+                       }
+               }
+
+               $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
+               return Renderer::replaceMacros($tpl, [
+                       'title'     => $header,
+                       '$contacts' => $entries,
+                       '$paginate' => $pager->renderFull($results->getTotal()),
+               ]);
+       }
+}
diff --git a/src/Module/BaseSearchModule.php b/src/Module/BaseSearchModule.php
deleted file mode 100644 (file)
index 42bb943..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-<?php
-
-namespace Friendica\Module;
-
-use Friendica\BaseModule;
-use Friendica\Content\ContactSelector;
-use Friendica\Content\Pager;
-use Friendica\Core\Renderer;
-use Friendica\Core\Search;
-use Friendica\DI;
-use Friendica\Model;
-use Friendica\Network\HTTPException;
-use Friendica\Object\Search\ContactResult;
-use Friendica\Object\Search\ResultList;
-use Friendica\Util\Proxy as ProxyUtils;
-
-/**
- * Base class for search modules
- */
-class BaseSearchModule extends BaseModule
-{
-       /**
-        * Performs a contact search with an optional prefix
-        *
-        * @param string $search Search query
-        * @param string $prefix A optional prefix (e.g. @ or !) for searching
-        *
-        * @return string
-        * @throws HTTPException\InternalServerErrorException
-        * @throws \ImagickException
-        */
-       public static function performContactSearch($search, $prefix = '')
-       {
-               $a      = DI::app();
-               $config = DI::config();
-
-               $type = Search::TYPE_ALL;
-
-               $localSearch = $config->get('system', 'poco_local_search');
-
-               $search = $prefix . $search;
-
-               if (!$search) {
-                       return '';
-               }
-
-               $header = '';
-
-               if (strpos($search, '@') === 0) {
-                       $search  = substr($search, 1);
-                       $type    = Search::TYPE_PEOPLE;
-                       $header  = DI::l10n()->t('People Search - %s', $search);
-
-                       if (strrpos($search, '@') > 0) {
-                               $results = Search::getContactsFromProbe($search);
-                       }
-               }
-
-               if (strpos($search, '!') === 0) {
-                       $search = substr($search, 1);
-                       $type   = Search::TYPE_FORUM;
-                       $header = DI::l10n()->t('Forum Search - %s', $search);
-               }
-
-               $args = DI::args();
-               $pager = new Pager($args->getQueryString());
-
-               if ($localSearch && empty($results)) {
-                       $pager->setItemsPerPage(80);
-                       $results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage());
-               } elseif (strlen($config->get('system', 'directory')) && empty($results)) {
-                       $results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage());
-                       $pager->setItemsPerPage($results->getItemsPage());
-               }
-
-               return self::printResult($results, $pager, $header);
-       }
-
-       /**
-        * Prints a human readable search result
-        *
-        * @param ResultList $results
-        * @param Pager      $pager
-        * @param string     $header
-        *
-        * @return string The result
-        * @throws HTTPException\InternalServerErrorException
-        * @throws \ImagickException
-        */
-       protected static function printResult(ResultList $results, Pager $pager, $header = '')
-       {
-               if ($results->getTotal() == 0) {
-                       info(DI::l10n()->t('No matches'));
-                       return '';
-               }
-
-               $id      = 0;
-               $entries = [];
-               foreach ($results->getResults() as $result) {
-
-                       // in case the result is a contact result, add a contact-specific entry
-                       if ($result instanceof ContactResult) {
-
-                               $alt_text    = '';
-                               $location    = '';
-                               $about       = '';
-                               $accountType = '';
-                               $photo_menu  = [];
-
-                               // If We already know this contact then don't show the "connect" button
-                               if ($result->getCid() > 0 || $result->getPCid() > 0) {
-                                       $connLink = "";
-                                       $connTxt  = "";
-                                       $contact  = Model\Contact::getById(
-                                               ($result->getCid() > 0) ? $result->getCid() : $result->getPCid()
-                                       );
-
-                                       if (!empty($contact)) {
-                                               $photo_menu  = Model\Contact::photoMenu($contact);
-                                               $details     = Contact::getContactTemplateVars($contact);
-                                               $alt_text    = $details['alt_text'];
-                                               $location    = $contact['location'];
-                                               $about       = $contact['about'];
-                                               $accountType = Model\Contact::getAccountType($contact);
-                                       } else {
-                                               $photo_menu = [];
-                                       }
-                               } else {
-                                       $connLink = DI::baseUrl()->get() . '/follow/?url=' . $result->getUrl();
-                                       $connTxt  = DI::l10n()->t('Connect');
-
-                                       $photo_menu['profile'] = [DI::l10n()->t("View Profile"), Model\Contact::magicLink($result->getUrl())];
-                                       $photo_menu['follow']  = [DI::l10n()->t("Connect/Follow"), $connLink];
-                               }
-
-                               $photo = str_replace("http:///photo/", Search::getGlobalDirectory() . "/photo/", $result->getPhoto());
-
-                               $entry     = [
-                                       'alt_text'     => $alt_text,
-                                       'url'          => Model\Contact::magicLink($result->getUrl()),
-                                       'itemurl'      => $result->getItem(),
-                                       'name'         => $result->getName(),
-                                       'thumb'        => ProxyUtils::proxifyUrl($photo, false, ProxyUtils::SIZE_THUMB),
-                                       'img_hover'    => $result->getTags(),
-                                       'conntxt'      => $connTxt,
-                                       'connlnk'      => $connLink,
-                                       'photo_menu'   => $photo_menu,
-                                       'details'      => $location,
-                                       'tags'         => $result->getTags(),
-                                       'about'        => $about,
-                                       'account_type' => $accountType,
-                                       'network'      => ContactSelector::networkToName($result->getNetwork(), $result->getUrl()),
-                                       'id'           => ++$id,
-                               ];
-                               $entries[] = $entry;
-                       }
-               }
-
-               $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
-               return Renderer::replaceMacros($tpl, [
-                       'title'     => $header,
-                       '$contacts' => $entries,
-                       '$paginate' => $pager->renderFull($results->getTotal()),
-               ]);
-       }
-}
diff --git a/src/Module/BaseSettings.php b/src/Module/BaseSettings.php
new file mode 100644 (file)
index 0000000..d4652cc
--- /dev/null
@@ -0,0 +1,110 @@
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Content\Feature;
+use Friendica\Core\Renderer;
+use Friendica\DI;
+
+class BaseSettings extends BaseModule
+{
+       public static function content(array $parameters = [])
+       {
+               $a = DI::app();
+
+               $tpl = Renderer::getMarkupTemplate('settings/head.tpl');
+               DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
+                       '$ispublic' => DI::l10n()->t('everybody')
+               ]);
+
+               $tabs = [];
+
+               $tabs[] = [
+                       'label' => DI::l10n()->t('Account'),
+                       'url' => 'settings',
+                       'selected' => (($a->argc == 1) && ($a->argv[0] === 'settings') ? 'active' : ''),
+                       'accesskey' => 'o',
+               ];
+
+               $tabs[] = [
+                       'label' => DI::l10n()->t('Two-factor authentication'),
+                       'url' => 'settings/2fa',
+                       'selected' => (($a->argc > 1) && ($a->argv[1] === '2fa') ? 'active' : ''),
+                       'accesskey' => 'o',
+               ];
+
+               $tabs[] = [
+                       'label' => DI::l10n()->t('Profile'),
+                       'url' => 'settings/profile',
+                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'profile') ? 'active' : ''),
+                       'accesskey' => 'p',
+               ];
+
+               if (Feature::get()) {
+                       $tabs[] = [
+                               'label' => DI::l10n()->t('Additional features'),
+                               'url' => 'settings/features',
+                               'selected' => (($a->argc > 1) && ($a->argv[1] === 'features') ? 'active' : ''),
+                               'accesskey' => 't',
+                       ];
+               }
+
+               $tabs[] = [
+                       'label' => DI::l10n()->t('Display'),
+                       'url' => 'settings/display',
+                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'display') ? 'active' : ''),
+                       'accesskey' => 'i',
+               ];
+
+               $tabs[] = [
+                       'label' => DI::l10n()->t('Social Networks'),
+                       'url' => 'settings/connectors',
+                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'connectors') ? 'active' : ''),
+                       'accesskey' => 'w',
+               ];
+
+               $tabs[] = [
+                       'label' => DI::l10n()->t('Addons'),
+                       'url' => 'settings/addon',
+                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'addon') ? 'active' : ''),
+                       'accesskey' => 'l',
+               ];
+
+               $tabs[] = [
+                       'label' => DI::l10n()->t('Delegations'),
+                       'url' => 'settings/delegation',
+                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'delegation') ? 'active' : ''),
+                       'accesskey' => 'd',
+               ];
+
+               $tabs[] = [
+                       'label' => DI::l10n()->t('Connected apps'),
+                       'url' => 'settings/oauth',
+                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'oauth') ? 'active' : ''),
+                       'accesskey' => 'b',
+               ];
+
+               $tabs[] = [
+                       'label' => DI::l10n()->t('Export personal data'),
+                       'url' => 'settings/userexport',
+                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'userexport') ? 'active' : ''),
+                       'accesskey' => 'e',
+               ];
+
+               $tabs[] = [
+                       'label' => DI::l10n()->t('Remove account'),
+                       'url' => 'removeme',
+                       'selected' => (($a->argc == 1) && ($a->argv[0] === 'removeme') ? 'active' : ''),
+                       'accesskey' => 'r',
+               ];
+
+
+               $tabtpl = Renderer::getMarkupTemplate("generic_links_widget.tpl");
+               DI::page()['aside'] = Renderer::replaceMacros($tabtpl, [
+                       '$title' => DI::l10n()->t('Settings'),
+                       '$class' => 'settings-widget',
+                       '$items' => $tabs,
+               ]);
+       }
+}
diff --git a/src/Module/BaseSettingsModule.php b/src/Module/BaseSettingsModule.php
deleted file mode 100644 (file)
index 225f5ed..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-
-namespace Friendica\Module;
-
-use Friendica\BaseModule;
-use Friendica\Content\Feature;
-use Friendica\Core\Renderer;
-use Friendica\DI;
-
-class BaseSettingsModule extends BaseModule
-{
-       public static function content(array $parameters = [])
-       {
-               $a = DI::app();
-
-               $tpl = Renderer::getMarkupTemplate('settings/head.tpl');
-               DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
-                       '$ispublic' => DI::l10n()->t('everybody')
-               ]);
-
-               $tabs = [];
-
-               $tabs[] = [
-                       'label' => DI::l10n()->t('Account'),
-                       'url' => 'settings',
-                       'selected' => (($a->argc == 1) && ($a->argv[0] === 'settings') ? 'active' : ''),
-                       'accesskey' => 'o',
-               ];
-
-               $tabs[] = [
-                       'label' => DI::l10n()->t('Two-factor authentication'),
-                       'url' => 'settings/2fa',
-                       'selected' => (($a->argc > 1) && ($a->argv[1] === '2fa') ? 'active' : ''),
-                       'accesskey' => 'o',
-               ];
-
-               $tabs[] = [
-                       'label' => DI::l10n()->t('Profile'),
-                       'url' => 'settings/profile',
-                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'profile') ? 'active' : ''),
-                       'accesskey' => 'p',
-               ];
-
-               if (Feature::get()) {
-                       $tabs[] = [
-                               'label' => DI::l10n()->t('Additional features'),
-                               'url' => 'settings/features',
-                               'selected' => (($a->argc > 1) && ($a->argv[1] === 'features') ? 'active' : ''),
-                               'accesskey' => 't',
-                       ];
-               }
-
-               $tabs[] = [
-                       'label' => DI::l10n()->t('Display'),
-                       'url' => 'settings/display',
-                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'display') ? 'active' : ''),
-                       'accesskey' => 'i',
-               ];
-
-               $tabs[] = [
-                       'label' => DI::l10n()->t('Social Networks'),
-                       'url' => 'settings/connectors',
-                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'connectors') ? 'active' : ''),
-                       'accesskey' => 'w',
-               ];
-
-               $tabs[] = [
-                       'label' => DI::l10n()->t('Addons'),
-                       'url' => 'settings/addon',
-                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'addon') ? 'active' : ''),
-                       'accesskey' => 'l',
-               ];
-
-               $tabs[] = [
-                       'label' => DI::l10n()->t('Delegations'),
-                       'url' => 'settings/delegation',
-                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'delegation') ? 'active' : ''),
-                       'accesskey' => 'd',
-               ];
-
-               $tabs[] = [
-                       'label' => DI::l10n()->t('Connected apps'),
-                       'url' => 'settings/oauth',
-                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'oauth') ? 'active' : ''),
-                       'accesskey' => 'b',
-               ];
-
-               $tabs[] = [
-                       'label' => DI::l10n()->t('Export personal data'),
-                       'url' => 'settings/userexport',
-                       'selected' => (($a->argc > 1) && ($a->argv[1] === 'userexport') ? 'active' : ''),
-                       'accesskey' => 'e',
-               ];
-
-               $tabs[] = [
-                       'label' => DI::l10n()->t('Remove account'),
-                       'url' => 'removeme',
-                       'selected' => (($a->argc == 1) && ($a->argv[0] === 'removeme') ? 'active' : ''),
-                       'accesskey' => 'r',
-               ];
-
-
-               $tabtpl = Renderer::getMarkupTemplate("generic_links_widget.tpl");
-               DI::page()['aside'] = Renderer::replaceMacros($tabtpl, [
-                       '$title' => DI::l10n()->t('Settings'),
-                       '$class' => 'settings-widget',
-                       '$items' => $tabs,
-               ]);
-       }
-}
index 6df58374eccc2973d8ca3fc9b4060cd6a6c5c1c9..34ab3d5acea5d345cd89cf21fe2ccc4f92dc2f91 100644 (file)
@@ -44,8 +44,8 @@ class Notification extends BaseModule
                // @TODO: Replace with parameter from router
                if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
                        try {
-                               $success = DI::notify()->setAllSeen();
-                       }catch (\Exception $e) {
+                               $success = DI::notify()->setSeen();
+                       } catch (\Exception $e) {
                                DI::logger()->warning('set all seen failed.', ['exception' => $e]);
                                $success = false;
                        }
@@ -66,11 +66,11 @@ class Notification extends BaseModule
 
                if ($request_id) {
                        try {
-                               $notification = DI::notify()->getByID($request_id);
-                               $notification->setSeen();
+                               $notify = DI::notify()->getByID($request_id);
+                               DI::notify()->setSeen(true, $notify);
 
-                               if (!empty($notification->link)) {
-                                       System::externalRedirect($notification->link);
+                               if (!empty($notify->link)) {
+                                       System::externalRedirect($notify->link);
                                }
 
                        } catch (HTTPException\NotFoundException $e) {
@@ -83,4 +83,3 @@ class Notification extends BaseModule
                DI::baseUrl()->redirect('notifications/system');
        }
 }
-
index 84dd4c2dda7dd7bd900085dcce642fe22a85798a..0540914f594af09df337ed14d3cc46bdb08e4c5d 100644 (file)
@@ -4,14 +4,14 @@ namespace Friendica\Module\Search;
 
 use Friendica\Content\Widget;
 use Friendica\DI;
-use Friendica\Module\BaseSearchModule;
+use Friendica\Module\BaseSearch;
 use Friendica\Module\Security\Login;
 use Friendica\Util\Strings;
 
 /**
  * Directory search module
  */
-class Directory extends BaseSearchModule
+class Directory extends BaseSearch
 {
        public static function content(array $parameters = [])
        {
index 69646fd1bd0a6bf0c8631993832093e205157b12..1f8bfe4bc2459a3275bbafcc385ebacfb4904fa0 100644 (file)
@@ -15,11 +15,11 @@ use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\Term;
-use Friendica\Module\BaseSearchModule;
+use Friendica\Module\BaseSearch;
 use Friendica\Network\HTTPException;
 use Friendica\Util\Strings;
 
-class Index extends BaseSearchModule
+class Index extends BaseSearch
 {
        public static function content(array $parameters = [])
        {
index d7f49e6a907cec48f0868e8ad4d97f855b06ecb8..c6d587d908cc7f2a7d434df28e0818354e07711d 100644 (file)
@@ -8,14 +8,14 @@ use Friendica\Core\Session;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\User;
-use Friendica\Module\BaseSettingsModule;
+use Friendica\Module\BaseSettings;
 use Friendica\Network\HTTPException;
 use Friendica\Util\Strings;
 
 /**
  * Account delegation settings module
  */
-class Delegation extends BaseSettingsModule
+class Delegation extends BaseSettings
 {
        public static function post(array $parameters = [])
        {
index b0eb194edd8d99e9932f1c4ec0551bd470ef8a6d..ea9b41866a1831ea68b54fe9451d1a5e5f1d8756 100644 (file)
@@ -16,14 +16,14 @@ use Friendica\Model\GContact;
 use Friendica\Model\Profile;
 use Friendica\Model\ProfileField;
 use Friendica\Model\User;
-use Friendica\Module\BaseSettingsModule;
+use Friendica\Module\BaseSettings;
 use Friendica\Module\Security\Login;
 use Friendica\Network\HTTPException;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
-class Index extends BaseSettingsModule
+class Index extends BaseSettings
 {
        public static function post(array $parameters = [])
        {
index 738e3fcb2aa04762b8618b0b68f7033fc4715d76..1ae828d2a2407319e3dc10188f8caa92cd1c6405 100644 (file)
@@ -9,10 +9,10 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Photo;
-use Friendica\Module\BaseSettingsModule;
+use Friendica\Module\BaseSettings;
 use Friendica\Network\HTTPException;
 
-class Crop extends BaseSettingsModule
+class Crop extends BaseSettings
 {
        public static function post(array $parameters = [])
        {
index 9d2648abd8a63ebb1c27f77e93fa7925d7a066ef..97171f7aa926c5e2cbb7f19910624b573c1f33f2 100644 (file)
@@ -8,13 +8,13 @@ use Friendica\Core\Session;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Photo;
-use Friendica\Module\BaseSettingsModule;
+use Friendica\Module\BaseSettings;
 use Friendica\Network\HTTPException;
 use Friendica\Object\Image;
 use Friendica\Util\Images;
 use Friendica\Util\Strings;
 
-class Index extends BaseSettingsModule
+class Index extends BaseSettings
 {
        public static function post(array $parameters = [])
        {
index 6a8821e5f7715adfbde4e9d16350f298c9d9b05a..c2e24e8b48ce35578c31fd8fef9e59efb3c6f4ba 100644 (file)
@@ -5,7 +5,7 @@ namespace Friendica\Module\Settings\TwoFactor;
 use Friendica\Core\Renderer;
 use Friendica\DI;
 use Friendica\Model\TwoFactor\AppSpecificPassword;
-use Friendica\Module\BaseSettingsModule;
+use Friendica\Module\BaseSettings;
 use Friendica\Module\Security\Login;
 
 /**
@@ -13,7 +13,7 @@ use Friendica\Module\Security\Login;
  *
  * @package Friendica\Module\TwoFactor
  */
-class AppSpecific extends BaseSettingsModule
+class AppSpecific extends BaseSettings
 {
        private static $appSpecificPassword = null;
 
index ab3400801eb86bf5fae13ef3e698d0ace8df7b77..0c021d4211e329977b44c6186b6e1630bffacc26 100644 (file)
@@ -8,11 +8,11 @@ use Friendica\DI;
 use Friendica\Model\TwoFactor\AppSpecificPassword;
 use Friendica\Model\TwoFactor\RecoveryCode;
 use Friendica\Model\User;
-use Friendica\Module\BaseSettingsModule;
+use Friendica\Module\BaseSettings;
 use Friendica\Module\Security\Login;
 use PragmaRX\Google2FA\Google2FA;
 
-class Index extends BaseSettingsModule
+class Index extends BaseSettings
 {
        public static function post(array $parameters = [])
        {
index 18c372c53c59ff96e52174b3411633b32ef80e9f..089283d3324d7cd1627479e1521797418a250450 100644 (file)
@@ -5,7 +5,7 @@ namespace Friendica\Module\Settings\TwoFactor;
 use Friendica\Core\Renderer;
 use Friendica\DI;
 use Friendica\Model\TwoFactor\RecoveryCode;
-use Friendica\Module\BaseSettingsModule;
+use Friendica\Module\BaseSettings;
 use Friendica\Module\Security\Login;
 
 /**
@@ -13,7 +13,7 @@ use Friendica\Module\Security\Login;
  *
  * @package Friendica\Module\TwoFactor
  */
-class Recovery extends BaseSettingsModule
+class Recovery extends BaseSettings
 {
        public static function init(array $parameters = [])
        {
index 2eae0300aee375fd1e33c2beea62b7c5b9f3c4bc..d832dd622b60ce808bf907fdaafbbba2cb1f858d 100644 (file)
@@ -9,7 +9,7 @@ use BaconQrCode\Writer;
 use Friendica\Core\Renderer;
 use Friendica\Core\Session;
 use Friendica\DI;
-use Friendica\Module\BaseSettingsModule;
+use Friendica\Module\BaseSettings;
 use Friendica\Module\Security\Login;
 use PragmaRX\Google2FA\Google2FA;
 
@@ -18,7 +18,7 @@ use PragmaRX\Google2FA\Google2FA;
  *
  * @package Friendica\Module\TwoFactor\Settings
  */
-class Verify extends BaseSettingsModule
+class Verify extends BaseSettings
 {
        public static function init(array $parameters = [])
        {
index 8d04e853602a34da754928e95fb4c43a7bfde77f..a1ea50353dc630798d6798d8072c6a12ae907321 100644 (file)
@@ -11,12 +11,12 @@ use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use Friendica\DI;
-use Friendica\Module\BaseSettingsModule;
+use Friendica\Module\BaseSettings;
 
 /**
  * Module to export user data
  **/
-class UserExport extends BaseSettingsModule
+class UserExport extends BaseSettings
 {
        /**
         * Handle the request to export data.
index 38eefee3df1df8565ac86b5e599be5ba90490b88..a5f401a0f3ed57ef86842a26a57985f335280942 100644 (file)
@@ -4,6 +4,7 @@ namespace Friendica\Object\Api\Mastodon;
 
 use Friendica\App\BaseURL;
 use Friendica\BaseEntity;
+use Friendica\Collection\Api\Mastodon\Fields;
 use Friendica\Content\Text\BBCode;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
@@ -70,7 +71,7 @@ class Account extends BaseEntity
         * @param array   $userContact   Optional full contact table record with uid != 0
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public function __construct(BaseURL $baseUrl, array $publicContact, array $apcontact = [], array $userContact = [])
+       public function __construct(BaseURL $baseUrl, array $publicContact, Fields $fields, array $apcontact = [], array $userContact = [])
        {
                $this->id              = $publicContact['id'];
                $this->username        = $publicContact['nick'];
@@ -94,7 +95,7 @@ class Account extends BaseEntity
                // No custom emojis per account in Friendica
                $this->emojis          = [];
                // No metadata fields in Friendica
-               $this->fields          = [];
+               $this->fields          = $fields->getArrayCopy();
                $this->bot             = ($publicContact['contact-type'] == Contact::TYPE_NEWS);
                $this->group           = ($publicContact['contact-type'] == Contact::TYPE_COMMUNITY);
                $this->discoverable    = !$publicContact['unsearchable'];
index 07cd2e501b011518fdf72707b0bea28ec88eb05f..a32eae04a21fff675a3e76140f3f2fdc2bd5b34e 100644 (file)
@@ -7,7 +7,7 @@ use Friendica\BaseEntity;
 /**
  * Class Field
  *
- * @see https://docs.joinmastodon.org/api/entities/#field
+ * @see https://docs.joinmastodon.org/entities/field/
  */
 class Field extends BaseEntity
 {
@@ -17,4 +17,12 @@ class Field extends BaseEntity
        protected $value;
        /** @var string (Datetime)*/
        protected $verified_at;
+
+       public function __construct(string $name, string $value)
+       {
+               $this->name = $name;
+               $this->value = $value;
+               // Link verification unsupported
+               $this->verified_at = null;
+       }
 }
index ed72f07d5416b0f1fe26f082bcc5ec15a4dc839e..2e1257d3e4a05ba48c90acfc21e2a1b7e283fb0c 100644 (file)
@@ -3,6 +3,7 @@
 namespace Friendica\Object\Api\Mastodon;
 
 use Friendica\App\BaseURL;
+use Friendica\Collection\Api\Mastodon\Fields;
 
 /**
  * Virtual entity to separate Accounts from Follow Requests.
@@ -24,7 +25,7 @@ class FollowRequest extends Account
         */
        public function __construct(BaseURL $baseUrl, int $introduction_id, array $publicContact, array $apcontact = [], array $userContact = [])
        {
-               parent::__construct($baseUrl, $publicContact, $apcontact, $userContact);
+               parent::__construct($baseUrl, $publicContact, new Fields(), $apcontact, $userContact);
 
                $this->id = $introduction_id;
        }
index 8c71fc289a1bd830b08515db4b16e1ef0e57896f..b53bd844113f6e0001d1655917610b68527032f2 100644 (file)
@@ -7,6 +7,7 @@ use Friendica\BaseRepository;
 use Friendica\Core\Hook;
 use Friendica\Model;
 use Friendica\Collection;
+use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Network\HTTPException\NotFoundException;
 use Friendica\Util\DateTimeFormat;
 
@@ -52,14 +53,28 @@ class Notify extends BaseRepository
        }
 
        /**
-        * {@inheritDoc}
+        * Set seen state of notifications of the local_user()
+        *
+        * @param bool         $seen   optional true or false. default true
+        * @param Model\Notify $notify optional a notify, which should be set seen (including his parents)
         *
         * @return bool true on success, false on error
+        *
         * @throws Exception
         */
-       public function setAllSeen(bool $seen = true)
+       public function setSeen(bool $seen = true, Model\Notify $notify = null)
        {
-               return $this->dba->update('notify', ['seen' => $seen], ['uid' => local_user()]);
+               if (empty($notify)) {
+                       $conditions = ['uid' => local_user()];
+               } else {
+                       $conditions = ['(`link` = ? OR (`parent` != 0 AND `parent` = ? AND `otype` = ?)) AND `uid` = ?',
+                               $notify->link,
+                               $notify->parent,
+                               $notify->otype,
+                               local_user()];
+               }
+
+               return $this->dba->update('notify', ['seen' => $seen], $conditions);
        }
 
        /**
@@ -67,12 +82,12 @@ class Notify extends BaseRepository
         *
         * @return Model\Notify|false
         *
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws InternalServerErrorException
         * @throws Exception
         */
        public function insert(array $fields)
        {
-               $fields['date']  = DateTimeFormat::utcNow();
+               $fields['date'] = DateTimeFormat::utcNow();
 
                Hook::callAll('enotify_store', $fields);
 
index 2eca8e1a6caa81ff86ae5604aa1b96b682283d65..9d360b35ddad82ab67d62acf1f275283798d7f7e 100644 (file)
@@ -35,6 +35,9 @@ return [
                        '/instance'                          => [Module\Api\Mastodon\Instance::class,       [R::GET         ]],
                        '/instance/peers'                    => [Module\Api\Mastodon\Instance\Peers::class, [R::GET         ]],
                ],
+               '/friendica' => [
+                       '/profile/show'                      => [Module\Api\Friendica\Profile\Show::class , [R::GET         ]],
+               ],
        ],
 
        '/admin'               => [
index 3ef64b3171653664f93e0abe2b9f3833099afc03..145619a75daac87f31a5488f46a18d31a96138a6 100644 (file)
@@ -19,6 +19,7 @@ use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Network\HTTPException;
 use Friendica\Test\Util\Database\StaticDatabase;
+use Friendica\Util\Temporal;
 use Monolog\Handler\TestHandler;
 
 require_once __DIR__ . '/../../include/api.php';
@@ -2488,102 +2489,6 @@ class ApiTest extends DatabaseTest
                $this->assertArrayHasKey('friendica:attendmaybe', $result);
        }
 
-       /**
-        * Test the api_format_items_profiles() function.
-        *
-        * @return void
-        */
-       public function testApiFormatItemsProfiles()
-       {
-               $profile_row = [
-                       'id'           => 'profile_id',
-                       'profile-name' => 'profile_name',
-                       'is-default'   => true,
-                       'hide-friends' => true,
-                       'photo'        => 'profile_photo',
-                       'thumb'        => 'profile_thumb',
-                       'publish'      => true,
-                       'net-publish'  => true,
-                       'pdesc'        => 'description',
-                       'dob'          => 'date_of_birth',
-                       'address'      => 'address',
-                       'locality'     => 'city',
-                       'region'       => 'region',
-                       'postal-code'  => 'postal_code',
-                       'country-name' => 'country',
-                       'hometown'     => 'hometown',
-                       'gender'       => 'gender',
-                       'marital'      => 'marital',
-                       'with'         => 'marital_with',
-                       'howlong'      => 'marital_since',
-                       'sexual'       => 'sexual',
-                       'politic'      => 'politic',
-                       'religion'     => 'religion',
-                       'pub_keywords' => 'public_keywords',
-                       'prv_keywords' => 'private_keywords',
-
-                       'likes'     => 'likes',
-                       'dislikes'  => 'dislikes',
-                       'about'     => 'about',
-                       'music'     => 'music',
-                       'book'      => 'book',
-                       'tv'        => 'tv',
-                       'film'      => 'film',
-                       'interest'  => 'interest',
-                       'romance'   => 'romance',
-                       'work'      => 'work',
-                       'education' => 'education',
-                       'contact'   => 'social_networks',
-                       'homepage'  => 'homepage'
-               ];
-               $result      = api_format_items_profiles($profile_row);
-               $this->assertEquals(
-                       [
-                               'profile_id'       => 'profile_id',
-                               'profile_name'     => 'profile_name',
-                               'is_default'       => true,
-                               'hide_friends'     => true,
-                               'profile_photo'    => 'profile_photo',
-                               'profile_thumb'    => 'profile_thumb',
-                               'publish'          => true,
-                               'net_publish'      => true,
-                               'description'      => 'description',
-                               'date_of_birth'    => 'date_of_birth',
-                               'address'          => 'address',
-                               'city'             => 'city',
-                               'region'           => 'region',
-                               'postal_code'      => 'postal_code',
-                               'country'          => 'country',
-                               'hometown'         => 'hometown',
-                               'gender'           => 'gender',
-                               'marital'          => 'marital',
-                               'marital_with'     => 'marital_with',
-                               'marital_since'    => 'marital_since',
-                               'sexual'           => 'sexual',
-                               'politic'          => 'politic',
-                               'religion'         => 'religion',
-                               'public_keywords'  => 'public_keywords',
-                               'private_keywords' => 'private_keywords',
-
-                               'likes'           => 'likes',
-                               'dislikes'        => 'dislikes',
-                               'about'           => 'about',
-                               'music'           => 'music',
-                               'book'            => 'book',
-                               'tv'              => 'tv',
-                               'film'            => 'film',
-                               'interest'        => 'interest',
-                               'romance'         => 'romance',
-                               'work'            => 'work',
-                               'education'       => 'education',
-                               'social_networks' => 'social_networks',
-                               'homepage'        => 'homepage',
-                               'users'           => null
-                       ],
-                       $result
-               );
-       }
-
        /**
         * Test the api_format_items() function.
         *
@@ -3940,10 +3845,11 @@ class ApiTest extends DatabaseTest
                $this->app->argv = ['api', 'friendica', 'notification'];
                $this->app->argc = count($this->app->argv);
                $result          = api_friendica_notification('xml');
+               $dateRel = Temporal::getRelativeDate('2020-01-01 12:12:02');
                $assertXml=<<<XML
 <?xml version="1.0"?>
 <notes>
-  <note id="1" hash="" type="8" name="Reply to" url="http://localhost/display/1" photo="http://localhost/" date="2020-01-01 12:12:02" msg="A test reply from an item" uid="42" link="http://localhost/notification/1" iid="4" parent="0" seen="0" verb="" otype="item" name_cache="" msg_cache="A test reply from an item" timestamp="1577880722" date_rel="4 weeks ago" msg_html="A test reply from an item" msg_plain="A test reply from an item"/>
+  <note id="1" hash="" type="8" name="Reply to" url="http://localhost/display/1" photo="http://localhost/" date="2020-01-01 12:12:02" msg="A test reply from an item" uid="42" link="http://localhost/notification/1" iid="4" parent="0" seen="0" verb="" otype="item" name_cache="" msg_cache="A test reply from an item" timestamp="1577880722" date_rel="{$dateRel}" msg_html="A test reply from an item" msg_plain="A test reply from an item"/>
 </notes>
 XML;
                $this->assertXmlStringEqualsXmlString($assertXml, $result);
@@ -3992,58 +3898,6 @@ XML;
                $this->markTestIncomplete();
        }
 
-       /**
-        * Test the api_friendica_profile_show() function.
-        *
-        * @return void
-        */
-       public function testApiFriendicaProfileShow()
-       {
-               $result = api_friendica_profile_show('json');
-               // We can't use assertSelfUser() here because the user object is missing some properties.
-               $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
-               $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
-               $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
-               $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
-               $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
-               $this->assertTrue($result['$result']['friendica_owner']['verified']);
-               $this->assertFalse($result['$result']['multi_profiles']);
-       }
-
-       /**
-        * Test the api_friendica_profile_show() function with a profile ID.
-        *
-        * @return void
-        */
-       public function testApiFriendicaProfileShowWithProfileId()
-       {
-               $this->markTestIncomplete('We need to add a dataset for this.');
-       }
-
-       /**
-        * Test the api_friendica_profile_show() function with a wrong profile ID.
-        *
-        * @return void
-        * @expectedException Friendica\Network\HTTPException\BadRequestException
-        */
-       public function testApiFriendicaProfileShowWithWrongProfileId()
-       {
-               $_REQUEST['profile_id'] = 666;
-               api_friendica_profile_show('json');
-       }
-
-       /**
-        * Test the api_friendica_profile_show() function without an authenticated user.
-        *
-        * @return void
-        * @expectedException Friendica\Network\HTTPException\ForbiddenException
-        */
-       public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
-       {
-               $_SESSION['authenticated'] = false;
-               api_friendica_profile_show('json');
-       }
-
        /**
         * Test the api_saved_searches_list() function.
         *