]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #6013 from JonnyTischbein/issue_comment_media_link_prompt
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 24 Oct 2018 16:17:58 +0000 (12:17 -0400)
committerGitHub <noreply@github.com>
Wed, 24 Oct 2018 16:17:58 +0000 (12:17 -0400)
[frio] Add media / link prompt in comments

166 files changed:
bin/worker.php
boot.php
config/config.ini.php
config/dbstructure.json [deleted file]
config/dbstructure.php [new file with mode: 0644]
config/settings.ini.php
doc/Addons.md
doc/Developers-Intro.md
doc/api.md
doc/de/Addons.md
images/person-300.jpg [new file with mode: 0644]
include/api.php
include/conversation.php
include/enotify.php
include/items.php
include/security.php [deleted file]
index.php
mod/admin.php
mod/api.php
mod/apps.php
mod/attach.php
mod/cal.php
mod/common.php
mod/community.php
mod/crepair.php
mod/delegate.php
mod/dfrn_confirm.php
mod/dfrn_poll.php
mod/dfrn_request.php
mod/display.php
mod/editpost.php
mod/events.php
mod/filer.php
mod/filerm.php
mod/follow.php
mod/friendica.php
mod/group.php
mod/home.php
mod/ignored.php
mod/invite.php
mod/item.php
mod/like.php
mod/lostpass.php
mod/manage.php
mod/match.php
mod/message.php
mod/network.php
mod/nogroup.php
mod/notes.php
mod/notice.php
mod/notifications.php
mod/notify.php
mod/openid.php
mod/ostatus_subscribe.php
mod/parse_url.php
mod/photo.php
mod/photos.php
mod/ping.php
mod/poke.php
mod/profile.php
mod/profile_photo.php
mod/profiles.php
mod/pubsub.php
mod/randprof.php
mod/redir.php
mod/register.php
mod/regmod.php
mod/removeme.php
mod/repair_ostatus.php
mod/search.php
mod/settings.php
mod/starred.php
mod/subthread.php
mod/suggest.php
mod/tagger.php
mod/tagrm.php
mod/toggle_mobile.php
mod/unfollow.php
mod/videos.php
mod/wallmessage.php
src/App.php
src/BaseModule.php
src/Content/Nav.php
src/Content/OEmbed.php
src/Content/Text/BBCode.php
src/Content/Widget/TagCloud.php
src/Core/Addon.php
src/Core/Authentication.php [new file with mode: 0644]
src/Core/Console/Maintenance.php
src/Core/Hook.php [new file with mode: 0644]
src/Core/Install.php
src/Core/L10n.php
src/Core/NotificationsManager.php
src/Core/Protocol.php
src/Core/System.php
src/Core/UserImport.php
src/Core/Worker.php
src/Database/DBA.php
src/Database/DBStructure.php
src/LegacyModule.php [new file with mode: 0644]
src/Model/APContact.php
src/Model/Contact.php
src/Model/Conversation.php
src/Model/Event.php
src/Model/GContact.php
src/Model/Group.php
src/Model/Item.php
src/Model/Photo.php
src/Model/Profile.php
src/Model/PushSubscriber.php
src/Model/Register.php [new file with mode: 0644]
src/Model/User.php
src/Module/Acctlink.php
src/Module/Contact.php
src/Module/Itemsource.php [new file with mode: 0644]
src/Module/Login.php
src/Module/Logout.php
src/Module/Magic.php
src/Module/Objects.php
src/Module/Proxy.php
src/Module/Tos.php
src/Network/Probe.php
src/Object/Thread.php
src/Protocol/ActivityPub.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/ActivityPub/Transmitter.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Protocol/OStatus.php
src/Protocol/PortableContact.php
src/Util/HTTPSignature.php
src/Util/JsonLD.php
src/Util/Network.php
src/Util/ParseUrl.php
src/Util/Proxy.php
src/Util/Security.php [new file with mode: 0644]
src/Util/Temporal.php
src/Worker/APDelivery.php
src/Worker/Cron.php
src/Worker/CronJobs.php
src/Worker/DBClean.php
src/Worker/Delivery.php
src/Worker/DiscoverPoCo.php
src/Worker/Expire.php
src/Worker/ForkHook.php
src/Worker/Notifier.php
src/Worker/OnePoll.php
src/Worker/Queue.php
src/Worker/RemoveContact.php
src/Worker/RemoveUser.php
tests/ApiTest.php
tests/DatabaseTest.php
tests/Util/VFSTrait.php
tests/src/Core/Console/AutomaticInstallationConsoleTest.php
tests/src/Core/InstallTest.php
tests/src/Core/SystemTest.php
update.php
view/templates/admin/summary.tpl
view/templates/contact_edit.tpl
view/templates/debug/itemsource.tpl [new file with mode: 0644]
view/theme/frio/css/style.css
view/theme/frio/templates/admin/summary.tpl
view/theme/frio/templates/contact_edit.tpl
view/theme/frio/templates/credits.tpl [new file with mode: 0644]
view/theme/vier/templates/contact_edit.tpl

index cb09a4929da9fe0c445baca4361445902687531f..d5cd1f6b4b7cc56492e770a3f53d51214d11acfa 100755 (executable)
@@ -4,12 +4,9 @@
  * @file bin/worker.php
  * @brief Starts the background processing
  */
-
 use Friendica\App;
-use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
-use Friendica\Core\L10n;
 
 // Get options
 $shortopts = 'sn';
@@ -20,10 +17,10 @@ $options = getopt($shortopts, $longopts);
 if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
        $directory = dirname($_SERVER["argv"][0]);
 
-       if (substr($directory, 0, 1) != "/") {
-               $directory = $_SERVER["PWD"]."/".$directory;
+       if (substr($directory, 0, 1) != '/') {
+               $directory = $_SERVER["PWD"] . '/' . $directory;
        }
-       $directory = realpath($directory."/..");
+       $directory = realpath($directory . '/..');
 
        chdir($directory);
 }
@@ -32,23 +29,16 @@ require_once "boot.php";
 
 $a = new App(dirname(__DIR__));
 
-Config::load();
-
-$lang = L10n::getBrowserLanguage();
-L10n::loadTranslationTable($lang);
-
 // Check the database structure and possibly fixes it
 check_db(true);
 
 // Quit when in maintenance
-if (Config::get('system', 'maintenance', false, true)) {
+if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) {
        return;
 }
 
 $a->setBaseURL(Config::get('system', 'url'));
 
-Addon::loadHooks();
-
 $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options);
 
 if ($spawn) {
@@ -63,5 +53,3 @@ Worker::processQueue($run_cron);
 Worker::unclaimProcess();
 
 Worker::endProcess();
-
-killme();
index ea1b273f2e8f24fac000e355ce1293ee1bcab174..7fb87ca4eb4391d9c5086c7eefdcf0b2e105b7a1 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -41,7 +41,6 @@ define('FRIENDICA_PLATFORM',     'Friendica');
 define('FRIENDICA_CODENAME',     'The Tazmans Flax-lily');
 define('FRIENDICA_VERSION',      '2018.12-dev');
 define('DFRN_PROTOCOL_VERSION',  '2.23');
-define('DB_UPDATE_VERSION',      1287);
 define('NEW_UPDATE_ROUTINE_VERSION', 1170);
 
 /**
@@ -121,24 +120,6 @@ define('LOGGER_DATA',            4);
 define('LOGGER_ALL',             5);
 /* @}*/
 
-/**
- * @name Cache
- * @deprecated since version 3.6
- * @see Cache
- *
- * Cache levels
- * @{
- */
-define('CACHE_MONTH',            Cache::MONTH);
-define('CACHE_WEEK',             Cache::WEEK);
-define('CACHE_DAY',              Cache::DAY);
-define('CACHE_HOUR',             Cache::HOUR);
-define('CACHE_HALF_HOUR',        Cache::HALF_HOUR);
-define('CACHE_QUARTER_HOUR',     Cache::QUARTER_HOUR);
-define('CACHE_FIVE_MINUTES',     Cache::FIVE_MINUTES);
-define('CACHE_MINUTE',           Cache::MINUTE);
-/* @}*/
-
 /**
  * @name Register
  *
@@ -212,11 +193,6 @@ $netgroup_ids = [
  */
 define('MAX_LIKERS',    75);
 
-/**
- * Communication timeout
- */
-define('ZCURL_TIMEOUT', (-1));
-
 /**
  * @name Notify
  *
@@ -368,11 +344,6 @@ define('SR_SCOPE_ALL',  'all');
 define('SR_SCOPE_TAGS', 'tags');
 /* @}*/
 
-/**
- * Lowest possible date time value
- */
-define('NULL_DATE', '0001-01-01 00:00:00');
-
 // Normally this constant is defined - but not if "pcntl" isn't installed
 if (!defined("SIGTERM")) {
        define("SIGTERM", 15);
@@ -502,29 +473,6 @@ function check_db($via_worker)
        }
 }
 
-/**
- * Sets the base url for use in cmdline programs which don't have
- * $_SERVER variables
- *
- * @param object $a App
- */
-function check_url(App $a)
-{
-       $url = Config::get('system', 'url');
-
-       // if the url isn't set or the stored url is radically different
-       // than the currently visited url, store the current value accordingly.
-       // "Radically different" ignores common variations such as http vs https
-       // and www.example.com vs example.com.
-       // We will only change the url to an ip address if there is no existing setting
-
-       if (empty($url) || (!link_compare($url, System::baseUrl())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $a->getHostName()))) {
-               Config::set('system', 'url', System::baseUrl());
-       }
-
-       return;
-}
-
 /**
  * @brief Automatic database updates
  * @param object $a App
@@ -644,21 +592,6 @@ function killme()
        exit();
 }
 
-/**
- * @brief Redirect to another URL and terminate this process.
- */
-function goaway($path)
-{
-       if (strstr(normalise_link($path), 'http://')) {
-               $url = $path;
-       } else {
-               $url = System::baseUrl() . '/' . ltrim($path, '/');
-       }
-
-       header("Location: $url");
-       killme();
-}
-
 /**
  * @brief Returns the user id of locally logged in user or false.
  *
index 8274399843e14380216462f4234afb8d694fbb00..3031d7d5047acd600318f07ecf2b48532c8e8279 100644 (file)
@@ -121,9 +121,14 @@ db_loglimit_index_high = 0
 
 ; dbclean_expire_conversation (Integer)
 ; When DBClean is enabled, any entry in the conversation table will be deleted after this many days.
-; These data are normally needed only for debugging purposes and they are safe to delete.
+: This data is used for ActivityPub, so it shouldn't be lower than the average duration of a discussion.
 dbclean_expire_conversation = 90
 
+; dbclean-expire-limit (Integer)
+; This defines the number of items that are to be deleted in a single call.
+; Reduce this value when you are getting memory issues.
+dbclean-expire-limit = 1000
+
 ; diaspora_test (Boolean)
 ; For development only. Disables the message transfer.
 diaspora_test = false
@@ -140,6 +145,10 @@ disable_url_validation = false
 ; Disable the exposition check against the remote haveibeenpwned API on password change.
 disable_password_exposed = false
 
+; disable_polling (Boolean)
+; Disable the polling of DFRN and OStatus contacts through onepoll.php.
+disable_polling = false
+
 ; dlogfile (Path)
 ; location of the developer log file.
 dlogfile =
@@ -360,6 +369,18 @@ throttle_limit_month = 0
 ; For instance if your URL is 'http://example.com/directory/subdirectory', set urlpath to 'directory/subdirectory'.
 urlpath =
 
+; username_min_length (Integer)
+; The minimum character length a username can be.
+; This length is check once the username has been trimmed and multiple spaces have been collapsed into one.
+; Minimum for this config value is 1. Maximum is 64 as the resulting profile URL mustn't be longer than 255 chars.
+username_min_length = 3
+
+; username_max_length (Integer)
+; The maximum character length a username can be.
+; This length is check once the username has been trimmed and multiple spaces have been collapsed into one.
+; Minimum for this config value is 1. Maximum is 64 as the resulting profile URL mustn't be longer than 255 chars.
+username_max_length = 48
+
 ; worker_cooldown (Integer)
 ; Cooldown period in seconds after each worker function call.
 worker_cooldown = 0
diff --git a/config/dbstructure.json b/config/dbstructure.json
deleted file mode 100644 (file)
index 51cb3ce..0000000
+++ /dev/null
@@ -1,1323 +0,0 @@
-{
-       "addon": {
-               "comment": "registered addons",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": ""},
-                       "name": {"type": "varchar(50)", "not null": "1", "default": "", "comment": "addon base (file)name"},
-                       "version": {"type": "varchar(50)", "not null": "1", "default": "", "comment": "currently unused"},
-                       "installed": {"type": "boolean", "not null": "1", "default": "0", "comment": "currently always 1"},
-                       "hidden": {"type": "boolean", "not null": "1", "default": "0", "comment": "currently unused"},
-                       "timestamp": {"type": "int unsigned", "not null": "1", "default": "0", "comment": "file timestamp to check for reloads"},
-                       "plugin_admin": {"type": "boolean", "not null": "1", "default": "0", "comment": "1 = has admin config, 0 = has no admin config"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "name": ["UNIQUE", "name"]
-               }
-       },
-       "apcontact": {
-               "comment": "ActivityPub compatible contacts - used in the ActivityPub implementation",
-               "fields": {
-                       "url": {"type": "varbinary(255)", "not null": "1", "primary": "1", "comment": "URL of the contact"},
-                       "uuid": {"type": "varchar(255)", "comment": ""},
-                       "type": {"type": "varchar(20)", "not null": "1", "comment": ""},
-                       "following": {"type": "varchar(255)", "comment": ""},
-                       "followers": {"type": "varchar(255)", "comment": ""},
-                       "inbox": {"type": "varchar(255)", "not null": "1", "comment": ""},
-                       "outbox": {"type": "varchar(255)", "comment": ""},
-                       "sharedinbox": {"type": "varchar(255)", "comment": ""},
-                       "nick": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "name": {"type": "varchar(255)", "comment": ""},
-                       "about": {"type": "text", "comment": ""},
-                       "photo": {"type": "varchar(255)", "comment": ""},
-                       "addr": {"type": "varchar(255)", "comment": ""},
-                       "alias": {"type": "varchar(255)", "comment": ""},
-                       "pubkey": {"type": "text", "comment": ""},
-                       "baseurl": {"type": "varchar(255)", "comment": "baseurl of the ap contact"},
-                       "updated": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""}
-
-               },
-               "indexes": {
-                       "PRIMARY": ["url"],
-                       "addr": ["addr(32)"],
-                       "url": ["followers(190)"]
-               }
-       },
-       "attach": {
-               "comment": "file attachments",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "generated index"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "Owner User id"},
-                       "hash": {"type": "varchar(64)", "not null": "1", "default": "", "comment": "hash"},
-                       "filename": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "filename of original"},
-                       "filetype": {"type": "varchar(64)", "not null": "1", "default": "", "comment": "mimetype"},
-                       "filesize": {"type": "int unsigned", "not null": "1", "default": "0", "comment": "size in bytes"},
-                       "data": {"type": "longblob", "not null": "1", "comment": "file data"},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "creation time"},
-                       "edited": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "last edit time"},
-                       "allow_cid": {"type": "mediumtext", "comment": "Access Control - list of allowed contact.id '<19><78>"},
-                       "allow_gid": {"type": "mediumtext", "comment": "Access Control - list of allowed groups"},
-                       "deny_cid": {"type": "mediumtext", "comment": "Access Control - list of denied contact.id"},
-                       "deny_gid": {"type": "mediumtext", "comment": "Access Control - list of denied groups"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"]
-               }
-       },
-       "auth_codes": {
-               "comment": "OAuth usage",
-               "fields": {
-                       "id": {"type": "varchar(40)", "not null": "1", "primary": "1", "comment": ""},
-                       "client_id": {"type": "varchar(20)", "not null": "1", "default": "", "relation": {"clients": "client_id"}, "comment": ""},
-                       "redirect_uri": {"type": "varchar(200)", "not null": "1", "default": "", "comment": ""},
-                       "expires": {"type": "int", "not null": "1", "default": "0", "comment": ""},
-                       "scope": {"type": "varchar(250)", "not null": "1", "default": "", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"]
-               }
-       },
-       "cache": {
-               "comment": "Stores temporary data",
-               "fields": {
-                       "k": {"type": "varbinary(255)", "not null": "1", "primary": "1", "comment": "cache key"},
-                       "v": {"type": "mediumtext", "comment": "cached serialized value"},
-                       "expires": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "datetime of cache expiration"},
-                       "updated": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "datetime of cache insertion"}
-               },
-               "indexes": {
-                       "PRIMARY": ["k"],
-                       "k_expires": ["k", "expires"]
-               }
-       },
-       "challenge": {
-               "comment": "",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "challenge": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "dfrn-id": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "expire": {"type": "int unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "type": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "last_update": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"]
-               }
-       },
-       "clients": {
-               "comment": "OAuth usage",
-               "fields": {
-                       "client_id": {"type": "varchar(20)", "not null": "1", "primary": "1", "comment": ""},
-                       "pw": {"type": "varchar(20)", "not null": "1", "default": "", "comment": ""},
-                       "redirect_uri": {"type": "varchar(200)", "not null": "1", "default": "", "comment": ""},
-                       "name": {"type": "text", "comment": ""},
-                       "icon": {"type": "text", "comment": ""},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"}
-               },
-               "indexes": {
-                       "PRIMARY": ["client_id"]
-               }
-       },
-       "config": {
-               "comment": "main configuration storage",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": ""},
-                       "cat": {"type": "varbinary(50)", "not null": "1", "default": "", "comment": ""},
-                       "k": {"type": "varbinary(50)", "not null": "1", "default": "", "comment": ""},
-                       "v": {"type": "mediumtext", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "cat_k": ["UNIQUE", "cat", "k"]
-               }
-       },
-       "contact": {
-               "comment": "contact table",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "Owner User id"},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "self": {"type": "boolean", "not null": "1", "default": "0", "comment": "1 if the contact is the user him/her self"},
-                       "remote_self": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "rel": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": "The kind of the relation between the user and the contact"},
-                       "duplex": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "network": {"type": "char(4)", "not null": "1", "default": "", "comment": "Network protocol of the contact"},
-                       "name": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "Name that this contact is known by"},
-                       "nick": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "Nick- and user name of the contact"},
-                       "location": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "about": {"type": "text", "comment": ""},
-                       "keywords": {"type": "text", "comment": "public keywords (interests) of the contact"},
-                       "gender": {"type": "varchar(32)", "not null": "1", "default": "", "comment": ""},
-                       "xmpp": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "attag": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "avatar": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "photo": {"type": "varchar(255)", "default": "", "comment": "Link to the profile photo of the contact"},
-                       "thumb": {"type": "varchar(255)", "default": "", "comment": "Link to the profile photo (thumb size)"},
-                       "micro": {"type": "varchar(255)", "default": "", "comment": "Link to the profile photo (micro size)"},
-                       "site-pubkey": {"type": "text", "comment": ""},
-                       "issued-id": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "dfrn-id": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "url": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "nurl": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "addr": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "alias": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "pubkey": {"type": "text", "comment": "RSA public key 4096 bit"},
-                       "prvkey": {"type": "text", "comment": "RSA private key 4096 bit"},
-                       "batch": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "request": {"type": "varchar(255)", "comment": ""},
-                       "notify": {"type": "varchar(255)", "comment": ""},
-                       "poll": {"type": "varchar(255)", "comment": ""},
-                       "confirm": {"type": "varchar(255)", "comment": ""},
-                       "poco": {"type": "varchar(255)", "comment": ""},
-                       "aes_allow": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "ret-aes": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "usehub": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "subhub": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "hub-verify": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "last-update": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Date of the last try to update the contact info"},
-                       "success_update": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Date of the last successful contact update"},
-                       "failure_update": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Date of the last failed update"},
-                       "name-date": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "uri-date": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "avatar-date": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "term-date": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "last-item": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "date of the last post"},
-                       "priority": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "blocked": {"type": "boolean", "not null": "1", "default": "1", "comment": ""},
-                       "readonly": {"type": "boolean", "not null": "1", "default": "0", "comment": "posts of the contact are readonly"},
-                       "writable": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "forum": {"type": "boolean", "not null": "1", "default": "0", "comment": "contact is a forum"},
-                       "prv": {"type": "boolean", "not null": "1", "default": "0", "comment": "contact is a private group"},
-                       "contact-type": {"type": "tinyint", "not null": "1", "default": "0", "comment": ""},
-                       "hidden": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "archive": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "pending": {"type": "boolean", "not null": "1", "default": "1", "comment": ""},
-                       "deleted": {"type": "boolean", "not null": "1", "default": "0", "comment": "Contact has been deleted"},
-                       "rating": {"type": "tinyint", "not null": "1", "default": "0", "comment": ""},
-                       "reason": {"type": "text", "comment": ""},
-                       "closeness": {"type": "tinyint unsigned", "not null": "1", "default": "99", "comment": ""},
-                       "info": {"type": "mediumtext", "comment": ""},
-                       "profile-id": {"type": "int unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "bdyear": {"type": "varchar(4)", "not null": "1", "default": "", "comment": ""},
-                       "bd": {"type": "date", "not null": "1", "default": "0001-01-01", "comment": ""},
-                       "notify_new_posts": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "fetch_further_information": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "ffi_keyword_blacklist": {"type": "text", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uid_name": ["uid", "name(190)"],
-                       "self_uid": ["self", "uid"],
-                       "alias_uid": ["alias(32)", "uid"],
-                       "pending_uid": ["pending", "uid"],
-                       "blocked_uid": ["blocked", "uid"],
-                       "uid_rel_network_poll": ["uid", "rel", "network", "poll(64)", "archive"],
-                       "uid_network_batch": ["uid", "network", "batch(64)"],
-                       "addr_uid": ["addr(32)", "uid"],
-                       "nurl_uid": ["nurl(32)", "uid"],
-                       "nick_uid": ["nick(32)", "uid"],
-                       "dfrn-id": ["dfrn-id(64)"],
-                       "issued-id": ["issued-id(64)"]
-               }
-       },
-       "conv": {
-               "comment": "private messages",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "guid": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "A unique identifier for this conversation"},
-                       "recips": {"type": "text", "comment": "sender_handle;recipient_handle"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "Owner User id"},
-                       "creator": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "handle of creator"},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "creation timestamp"},
-                       "updated": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "edited timestamp"},
-                       "subject": {"type": "text", "comment": "subject of initial message"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uid": ["uid"]
-               }
-       },
-       "conversation": {
-               "comment": "Raw data and structure information for messages",
-               "fields": {
-                       "item-uri": {"type": "varbinary(255)", "not null": "1", "primary": "1", "comment": "Original URI of the item - unrelated to the table with the same name"},
-                       "reply-to-uri": {"type": "varbinary(255)", "not null": "1", "default": "", "comment": "URI to which this item is a reply"},
-                       "conversation-uri": {"type": "varbinary(255)", "not null": "1", "default": "", "comment": "GNU Social conversation URI"},
-                       "conversation-href": {"type": "varbinary(255)", "not null": "1", "default": "", "comment": "GNU Social conversation link"},
-                       "protocol": {"type": "tinyint unsigned", "not null": "1", "default": "255", "comment": "The protocol of the item"},
-                       "source": {"type": "mediumtext", "comment": "Original source"},
-                       "received": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Receiving date"}
-               },
-               "indexes": {
-                       "PRIMARY": ["item-uri"],
-                       "conversation-uri": ["conversation-uri"],
-                       "received": ["received"]
-               }
-       },
-       "diaspora-interaction": {
-               "comment": "Signed Diaspora Interaction",
-               "fields": {
-                       "uri-id": {"type": "int unsigned", "not null": "1", "primary": "1", "relation": {"item-uri": "id"}, "comment": "Id of the item-uri table entry that contains the item uri"},
-                       "interaction": {"type": "mediumtext", "comment": "The Diaspora interaction"}
-               },
-               "indexes": {
-                       "PRIMARY": ["uri-id"]
-               }
-       },
-       "event": {
-               "comment": "Events",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "guid": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "Owner User id"},
-                       "cid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": "contact_id (ID of the contact in contact table)"},
-                       "uri": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "creation time"},
-                       "edited": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "last edit time"},
-                       "start": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "event start time"},
-                       "finish": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "event end time"},
-                       "summary": {"type": "text", "comment": "short description or title of the event"},
-                       "desc": {"type": "text", "comment": "event description"},
-                       "location": {"type": "text", "comment": "event location"},
-                       "type": {"type": "varchar(20)", "not null": "1", "default": "", "comment": "event or birthday"},
-                       "nofinish": {"type": "boolean", "not null": "1", "default": "0", "comment": "if event does have no end this is 1"},
-                       "adjust": {"type": "boolean", "not null": "1", "default": "1", "comment": "adjust to timezone of the recipient (0 or 1)"},
-                       "ignore": {"type": "boolean", "not null": "1", "default": "0", "comment": "0 or 1"},
-                       "allow_cid": {"type": "mediumtext", "comment": "Access Control - list of allowed contact.id '<19><78>'"},
-                       "allow_gid": {"type": "mediumtext", "comment": "Access Control - list of allowed groups"},
-                       "deny_cid": {"type": "mediumtext", "comment": "Access Control - list of denied contact.id"},
-                       "deny_gid": {"type": "mediumtext", "comment": "Access Control - list of denied groups"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uid_start": ["uid", "start"]
-               }
-       },
-       "fcontact": {
-               "comment": "Diaspora compatible contacts - used in the Diaspora implementation",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "guid": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "unique id"},
-                       "url": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "name": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "photo": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "request": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "nick": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "addr": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "batch": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "notify": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "poll": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "confirm": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "priority": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "network": {"type": "char(4)", "not null": "1", "default": "", "comment": ""},
-                       "alias": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "pubkey": {"type": "text", "comment": ""},
-                       "updated": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "addr": ["addr(32)"],
-                       "url": ["UNIQUE", "url(190)"]
-               }
-       },
-       "fsuggest": {
-               "comment": "friend suggestion stuff",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": ""},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"},
-                       "cid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": ""},
-                       "name": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "url": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "request": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "photo": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "note": {"type": "text", "comment": ""},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"]
-               }
-       },
-       "gcign": {
-               "comment": "contacts ignored by friend suggestions",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "Local User id"},
-                       "gcid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"gcontact": "id"}, "comment": "gcontact.id of ignored contact"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uid": ["uid"],
-                       "gcid": ["gcid"]
-               }
-       },
-       "gcontact": {
-               "comment": "global contacts",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "name": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "Name that this contact is known by"},
-                       "nick": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "Nick- and user name of the contact"},
-                       "url": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "Link to the contacts profile page"},
-                       "nurl": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "photo": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "Link to the profile photo"},
-                       "connect": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "updated": {"type": "datetime", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "last_contact": {"type": "datetime", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "last_failure": {"type": "datetime", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "location": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "about": {"type": "text", "comment": ""},
-                       "keywords": {"type": "text", "comment": "puplic keywords (interests)"},
-                       "gender": {"type": "varchar(32)", "not null": "1", "default": "", "comment": ""},
-                       "birthday": {"type": "varchar(32)", "not null": "1", "default": "0001-01-01", "comment": ""},
-                       "community": {"type": "boolean", "not null": "1", "default": "0", "comment": "1 if contact is forum account"},
-                       "contact-type": {"type": "tinyint", "not null": "1", "default": "-1", "comment": ""},
-                       "hide": {"type": "boolean", "not null": "1", "default": "0", "comment": "1 = should be hidden from search"},
-                       "nsfw": {"type": "boolean", "not null": "1", "default": "0", "comment": "1 = contact posts nsfw content"},
-                       "network": {"type": "char(4)", "not null": "1", "default": "", "comment": "social network protocol"},
-                       "addr": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "notify": {"type": "varchar(255)", "comment": ""},
-                       "alias": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "generation": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "server_url": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "baseurl of the contacts server"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "nurl": ["UNIQUE", "nurl(190)"],
-                       "name": ["name(64)"],
-                       "nick": ["nick(32)"],
-                       "addr": ["addr(64)"],
-                       "hide_network_updated": ["hide", "network", "updated"],
-                       "updated": ["updated"]
-               }
-       },
-       "glink": {
-               "comment": "'friends of friends' linkages derived from poco",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "cid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": ""},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"},
-                       "gcid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"gcontact": "id"}, "comment": ""},
-                       "zcid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"gcontact": "id"}, "comment": ""},
-                       "updated": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "cid_uid_gcid_zcid": ["UNIQUE", "cid", "uid", "gcid", "zcid"],
-                       "gcid": ["gcid"]
-               }
-       },
-       "group": {
-               "comment": "privacy groups, group info",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "Owner User id"},
-                       "visible": {"type": "boolean", "not null": "1", "default": "0", "comment": "1 indicates the member list is not private"},
-                       "deleted": {"type": "boolean", "not null": "1", "default": "0", "comment": "1 indicates the group has been deleted"},
-                       "name": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "human readable name of group"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uid": ["uid"]
-               }
-       },
-       "group_member": {
-               "comment": "privacy groups, member info",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "gid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"group": "id"}, "comment": "groups.id of the associated group"},
-                       "contact-id": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": "contact.id of the member assigned to the associated group"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "contactid": ["contact-id"],
-                       "gid_contactid": ["UNIQUE", "gid", "contact-id"]
-               }
-       },
-       "gserver": {
-               "comment": "Global servers",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "url": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "nurl": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "version": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "site_name": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "info": {"type": "text", "comment": ""},
-                       "register_policy": {"type": "tinyint", "not null": "1", "default": "0", "comment": ""},
-                       "registered-users": {"type": "int unsigned", "not null": "1", "default": "0", "comment": "Number of registered users"},
-                       "poco": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "noscrape": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "network": {"type": "char(4)", "not null": "1", "default": "", "comment": ""},
-                       "platform": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "relay-subscribe": {"type": "boolean", "not null": "1", "default": "0", "comment": "Has the server subscribed to the relay system"},
-                       "relay-scope": {"type": "varchar(10)", "not null": "1", "default": "", "comment": "The scope of messages that the server wants to get"},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "last_poco_query": {"type": "datetime", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "last_contact": {"type": "datetime", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "last_failure": {"type": "datetime", "default": "0001-01-01 00:00:00", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "nurl": ["UNIQUE", "nurl(190)"]
-               }
-       },
-       "gserver-tag": {
-               "comment": "Tags that the server has subscribed",
-               "fields": {
-                       "gserver-id": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"gserver": "id"}, "primary": "1", "comment": "The id of the gserver"},
-                       "tag": {"type": "varchar(100)", "not null": "1", "default": "", "primary": "1", "comment": "Tag that the server has subscribed"}
-               },
-               "indexes": {
-                       "PRIMARY": ["gserver-id", "tag"],
-                       "tag": ["tag"]
-               }
-       },
-       "hook": {
-               "comment": "addon hook registry",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "hook": {"type": "varbinary(100)", "not null": "1", "default": "", "comment": "name of hook"},
-                       "file": {"type": "varbinary(200)", "not null": "1", "default": "", "comment": "relative filename of hook handler"},
-                       "function": {"type": "varbinary(200)", "not null": "1", "default": "", "comment": "function name of hook handler"},
-                       "priority": {"type": "smallint unsigned", "not null": "1", "default": "0", "comment": "not yet implemented - can be used to sort conflicts in hook handling by calling handlers in priority order"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "hook_file_function": ["UNIQUE", "hook", "file", "function"]
-               }
-       },
-       "intro": {
-               "comment": "",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"},
-                       "fid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"fcontact": "id"}, "comment": ""},
-                       "contact-id": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": ""},
-                       "knowyou": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "duplex": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "note": {"type": "text", "comment": ""},
-                       "hash": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "datetime": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "blocked": {"type": "boolean", "not null": "1", "default": "1", "comment": ""},
-                       "ignore": {"type": "boolean", "not null": "1", "default": "0", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"]
-               }
-       },
-       "item": {
-               "comment": "Structure for all posts",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "relation": {"thread": "iid"}},
-                       "guid": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "A unique identifier for this item"},
-                       "uri": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "uri-id": {"type": "int unsigned", "relation": {"item-uri": "id"}, "comment": "Id of the item-uri table entry that contains the item uri"},
-                       "uri-hash": {"type": "varchar(80)", "not null": "1", "default": "", "comment": "RIPEMD-128 hash from uri"},
-                       "parent": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"item": "id"}, "comment": "item.id of the parent to this item if it is a reply of some form; otherwise this must be set to the id of this item"},
-                       "parent-uri": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "uri of the parent to this item"},
-                       "parent-uri-id": {"type": "int unsigned", "relation": {"item-uri": "id"}, "comment": "Id of the item-uri table that contains the parent uri"},
-                       "thr-parent": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "If the parent of this item is not the top-level item in the conversation, the uri of the immediate parent; otherwise set to parent-uri"},
-                       "thr-parent-id": {"type": "int unsigned", "relation": {"item-uri": "id"}, "comment": "Id of the item-uri table that contains the thread parent uri"},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Creation timestamp."},
-                       "edited": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Date of last edit (default is created)"},
-                       "commented": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Date of last comment/reply to this item"},
-                       "received": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "datetime"},
-                       "changed": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Date that something in the conversation changed, indicating clients should fetch the conversation again"},
-                       "gravity": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "network": {"type": "char(4)", "not null": "1", "default": "", "comment": "Network from where the item comes from"},
-                       "owner-id": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": "Link to the contact table with uid=0 of the owner of this item"},
-                       "author-id": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": "Link to the contact table with uid=0 of the author of this item"},
-                       "icid": {"type": "int unsigned", "relation": {"item-content": "id"}, "comment": "Id of the item-content table entry that contains the whole item content"},
-                       "iaid": {"type": "int unsigned", "relation": {"item-activity": "id"}, "comment": "Id of the item-activity table entry that contains the activity data"},
-                       "extid": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "post-type": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": "Post type (personal note, bookmark, ...)"},
-                       "global": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "private": {"type": "boolean", "not null": "1", "default": "0", "comment": "distribution is restricted"},
-                       "visible": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "moderated": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "deleted": {"type": "boolean", "not null": "1", "default": "0", "comment": "item has been deleted"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "Owner id which owns this copy of the item"},
-                       "contact-id": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": "contact.id"},
-                       "wall": {"type": "boolean", "not null": "1", "default": "0", "comment": "This item was posted to the wall of uid"},
-                       "origin": {"type": "boolean", "not null": "1", "default": "0", "comment": "item originated at this site"},
-                       "pubmail": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "starred": {"type": "boolean", "not null": "1", "default": "0", "comment": "item has been favourited"},
-                       "unseen": {"type": "boolean", "not null": "1", "default": "1", "comment": "item has not been seen"},
-                       "mention": {"type": "boolean", "not null": "1", "default": "0", "comment": "The owner of this item was mentioned in it"},
-                       "forum_mode": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "psid": {"type": "int unsigned", "relation": {"permissionset": "id"}, "comment": "ID of the permission set of this post"},
-                       "resource-id": {"type": "varchar(32)", "not null": "1", "default": "", "comment": "Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type"},
-                       "event-id": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"event": "id"}, "comment": "Used to link to the event.id"},
-                       "attach": {"type": "mediumtext", "comment": "JSON structure representing attachments to this item"},
-                       "allow_cid": {"type": "mediumtext", "comment": "Deprecated"},
-                       "allow_gid": {"type": "mediumtext", "comment": "Deprecated"},
-                       "deny_cid": {"type": "mediumtext", "comment": "Deprecated"},
-                       "deny_gid": {"type": "mediumtext", "comment": "Deprecated"},
-                       "postopts": {"type": "text", "comment": "Deprecated"},
-                       "inform": {"type": "mediumtext", "comment": "Deprecated"},
-                       "type": {"type": "varchar(20)", "comment": "Deprecated"},
-                       "bookmark": {"type": "boolean", "comment": "Deprecated"},
-                       "file": {"type": "mediumtext", "comment": "Deprecated"},
-                       "location": {"type": "varchar(255)", "comment": "Deprecated"},
-                       "coord": {"type": "varchar(255)", "comment": "Deprecated"},
-                       "tag": {"type": "mediumtext", "comment": "Deprecated"},
-                       "plink": {"type": "varchar(255)", "comment": "Deprecated"},
-                       "title": {"type": "varchar(255)", "comment": "Deprecated"},
-                       "content-warning": {"type": "varchar(255)", "comment": "Deprecated"},
-                       "body": {"type": "mediumtext", "comment": "Deprecated"},
-                       "app": {"type": "varchar(255)", "comment": "Deprecated"},
-                       "verb": {"type": "varchar(100)", "comment": "Deprecated"},
-                       "object-type": {"type": "varchar(100)", "comment": "Deprecated"},
-                       "object": {"type": "text", "comment": "Deprecated"},
-                       "target-type": {"type": "varchar(100)", "comment": "Deprecated"},
-                       "target": {"type": "text", "comment": "Deprecated"},
-                       "author-name": {"type": "varchar(255)", "comment": "Deprecated"},
-                       "author-link": {"type": "varchar(255)", "comment": "Deprecated"},
-                       "author-avatar": {"type": "varchar(255)", "comment": "Deprecated"},
-                       "owner-name": {"type": "varchar(255)", "comment": "Deprecated"},
-                       "owner-link": {"type": "varchar(255)", "comment": "Deprecated"},
-                       "owner-avatar": {"type": "varchar(255)", "comment": "Deprecated"},
-                       "rendered-hash": {"type": "varchar(32)", "comment": "Deprecated"},
-                       "rendered-html": {"type": "mediumtext", "comment": "Deprecated"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "guid": ["guid(191)"],
-                       "uri": ["uri(191)"],
-                       "parent": ["parent"],
-                       "parent-uri": ["parent-uri(191)"],
-                       "extid": ["extid(191)"],
-                       "uid_id": ["uid", "id"],
-                       "uid_contactid_id": ["uid", "contact-id", "id"],
-                       "uid_created": ["uid", "created"],
-                       "uid_commented": ["uid", "commented"],
-                       "uid_unseen_contactid": ["uid", "unseen", "contact-id"],
-                       "uid_network_received": ["uid", "network", "received"],
-                       "uid_network_commented": ["uid", "network", "commented"],
-                       "uid_thrparent": ["uid", "thr-parent(190)"],
-                       "uid_parenturi": ["uid", "parent-uri(190)"],
-                       "uid_contactid_created": ["uid", "contact-id", "created"],
-                       "authorid_created": ["author-id", "created"],
-                       "ownerid": ["owner-id"],
-                       "uid_uri": ["uid", "uri(190)"],
-                       "resource-id": ["resource-id"],
-                       "deleted_changed": ["deleted", "changed"],
-                       "uid_wall_changed": ["uid", "wall", "changed"],
-                       "uid_eventid": ["uid", "event-id"],
-                       "icid": ["icid"],
-                       "iaid": ["iaid"],
-                       "psid_wall": ["psid", "wall"]
-               }
-       },
-       "item-activity": {
-               "comment": "Activities for items",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "relation": {"thread": "iid"}},
-                       "uri": {"type": "varchar(255)", "comment": ""},
-                       "uri-id": {"type": "int unsigned", "relation": {"item-uri": "id"}, "comment": "Id of the item-uri table entry that contains the item uri"},
-                       "uri-hash": {"type": "varchar(80)", "not null": "1", "default": "", "comment": "RIPEMD-128 hash from uri"},
-                       "activity": {"type": "smallint unsigned", "not null": "1", "default": "0", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uri-hash": ["UNIQUE", "uri-hash"],
-                       "uri": ["uri(191)"]
-               }
-       },
-       "item-content": {
-               "comment": "Content for all posts",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "relation": {"thread": "iid"}},
-                       "uri": {"type": "varchar(255)", "comment": ""},
-                       "uri-id": {"type": "int unsigned", "relation": {"item-uri": "id"}, "comment": "Id of the item-uri table entry that contains the item uri"},
-                       "uri-plink-hash": {"type": "varchar(80)", "not null": "1", "default": "", "comment": "RIPEMD-128 hash from uri"},
-                       "title": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "item title"},
-                       "content-warning": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "body": {"type": "mediumtext", "comment": "item body content"},
-                       "location": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "text location where this item originated"},
-                       "coord": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "longitude/latitude pair representing location where this item originated"},
-                       "language": {"type": "text", "comment": "Language information about this post"},
-                       "app": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "application which generated this item"},
-                       "rendered-hash": {"type": "varchar(32)", "not null": "1", "default": "", "comment": ""},
-                       "rendered-html": {"type": "mediumtext", "comment": "item.body converted to html"},
-                       "object-type": {"type": "varchar(100)", "not null": "1", "default": "", "comment": "ActivityStreams object type"},
-                       "object": {"type": "text", "comment": "JSON encoded object structure unless it is an implied object (normal post)"},
-                       "target-type": {"type": "varchar(100)", "not null": "1", "default": "", "comment": "ActivityStreams target type if applicable (URI)"},
-                       "target": {"type": "text", "comment": "JSON encoded target structure if used"},
-                       "plink": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "permalink or URL to a displayable copy of the message at its source"},
-                       "verb": {"type": "varchar(100)", "not null": "1", "default": "", "comment": "ActivityStreams verb"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uri-plink-hash": ["UNIQUE", "uri-plink-hash"],
-                       "uri": ["uri(191)"]
-               }
-       },
-       "item-delivery-data": {
-               "comment": "Delivery data for items",
-               "fields": {
-                       "iid": {"type": "int unsigned", "not null": "1", "primary": "1", "relation": {"item": "id"}, "comment": "Item id"},
-                       "postopts": {"type": "text", "comment": "External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery"},
-                       "inform": {"type": "mediumtext", "comment": "Additional receivers of the linked item"}
-               },
-               "indexes": {
-                       "PRIMARY": ["iid"]
-               }
-       },
-       "item-uri": {
-               "comment": "URI and GUID for items",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1"},
-                       "uri": {"type": "varbinary(255)", "not null": "1", "comment": "URI of an item"},
-                       "guid": {"type": "varbinary(255)", "comment": "A unique identifier for an item"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uri": ["UNIQUE", "uri"],
-                       "guid": ["guid"]
-               }
-       },
-       "locks": {
-               "comment": "",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "name": {"type": "varchar(128)", "not null": "1", "default": "", "comment": ""},
-                       "locked": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "pid": {"type": "int unsigned", "not null": "1", "default": "0", "comment": "Process ID"},
-                       "expires": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "datetime of cache expiration"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "name_expires": ["name", "expires"]
-               }
-       },
-       "mail": {
-               "comment": "private messages",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "Owner User id"},
-                       "guid": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "A unique identifier for this private message"},
-                       "from-name": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "name of the sender"},
-                       "from-photo": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "contact photo link of the sender"},
-                       "from-url": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "profile linke of the sender"},
-                       "contact-id": {"type": "varchar(255)", "not null": "1", "default": "", "relation": {"contact": "id"}, "comment": "contact.id"},
-                       "convid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"conv": "id"}, "comment": "conv.id"},
-                       "title": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "body": {"type": "mediumtext", "comment": ""},
-                       "seen": {"type": "boolean", "not null": "1", "default": "0", "comment": "if message visited it is 1"},
-                       "reply": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "replied": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "unknown": {"type": "boolean", "not null": "1", "default": "0", "comment": "if sender not in the contact table this is 1"},
-                       "uri": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "parent-uri": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "creation time of the private message"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uid_seen": ["uid", "seen"],
-                       "convid": ["convid"],
-                       "uri": ["uri(64)"],
-                       "parent-uri": ["parent-uri(64)"],
-                       "contactid": ["contact-id(32)"]
-               }
-       },
-       "mailacct": {
-               "comment": "Mail account data for fetching mails",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"},
-                       "server": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "port": {"type": "smallint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "ssltype": {"type": "varchar(16)", "not null": "1", "default": "", "comment": ""},
-                       "mailbox": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "user": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "pass": {"type": "text", "comment": ""},
-                       "reply_to": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "action": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "movetofolder": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "pubmail": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "last_check": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"]
-               }
-       },
-       "manage": {
-               "comment": "table of accounts that can manage each other",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"},
-                       "mid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uid_mid": ["UNIQUE", "uid", "mid"]
-               }
-       },
-       "notify": {
-               "comment": "notifications",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "hash": {"type": "varchar(64)", "not null": "1", "default": "", "comment": ""},
-                       "type": {"type": "smallint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "name": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "url": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "photo": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "date": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "msg": {"type": "mediumtext", "comment": ""},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "Owner User id"},
-                       "link": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "iid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"item": "id"}, "comment": "item.id"},
-                       "parent": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"item": "id"}, "comment": ""},
-                       "seen": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "verb": {"type": "varchar(100)", "not null": "1", "default": "", "comment": ""},
-                       "otype": {"type": "varchar(10)", "not null": "1", "default": "", "comment": ""},
-                       "name_cache": {"type": "tinytext", "comment": "Cached bbcode parsing of name"},
-                       "msg_cache": {"type": "mediumtext", "comment": "Cached bbcode parsing of msg"}
-                       },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "hash_uid": ["hash", "uid"],
-                       "seen_uid_date": ["seen", "uid", "date"],
-                       "uid_date": ["uid", "date"],
-                       "uid_type_link": ["uid", "type", "link(190)"]
-               }
-       },
-       "notify-threads": {
-               "comment": "",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "notify-id": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"notify": "id"}, "comment": ""},
-                       "master-parent-item": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"item": "id"}, "comment": ""},
-                       "parent-item": {"type": "int unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "receiver-uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"]
-               }
-       },
-       "oembed": {
-               "comment": "cache for OEmbed queries",
-               "fields": {
-                       "url": {"type": "varbinary(255)", "not null": "1", "primary": "1", "comment": "page url"},
-                       "maxwidth": {"type": "mediumint unsigned", "not null": "1", "primary": "1", "comment": "Maximum width passed to Oembed"},
-                       "content": {"type": "mediumtext", "comment": "OEmbed data of the page"},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "datetime of creation"}
-               },
-               "indexes": {
-                       "PRIMARY": ["url", "maxwidth"],
-                       "created": ["created"]
-               }
-       },
-       "openwebauth-token": {
-               "comment": "Store OpenWebAuth token to verify contacts",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"},
-                       "type": {"type": "varchar(32)", "not null": "1", "default": "", "comment": "Verify type"},
-                       "token": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "A generated token"},
-                       "meta": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "datetime of creation"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"]
-               }
-       },
-       "parsed_url": {
-               "comment": "cache for 'parse_url' queries",
-               "fields": {
-                       "url": {"type": "varbinary(255)", "not null": "1", "primary": "1", "comment": "page url"},
-                       "guessing": {"type": "boolean", "not null": "1", "default": "0", "primary": "1", "comment": "is the 'guessing' mode active?"},
-                       "oembed": {"type": "boolean", "not null": "1", "default": "0", "primary": "1", "comment": "is the data the result of oembed?"},
-                       "content": {"type": "mediumtext", "comment": "page data"},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "datetime of creation"}
-               },
-               "indexes": {
-                       "PRIMARY": ["url", "guessing", "oembed"],
-                       "created": ["created"]
-               }
-       },
-       "participation": {
-               "comment": "Storage for participation messages from Diaspora",
-               "fields": {
-                       "iid": {"type": "int unsigned", "not null": "1", "primary": "1", "relation": {"item": "id"}, "comment": ""},
-                       "server": {"type": "varchar(60)", "not null": "1", "primary": "1", "comment": ""},
-                       "cid": {"type": "int unsigned", "not null": "1", "relation": {"contact": "id"}, "comment": ""},
-                       "fid": {"type": "int unsigned", "not null": "1", "relation": {"fcontact": "id"}, "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["iid", "server"]
-                       }
-               },
-       "pconfig": {
-               "comment": "personal (per user) configuration storage",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": ""},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"},
-                       "cat": {"type": "varbinary(50)", "not null": "1", "default": "", "comment": ""},
-                       "k": {"type": "varbinary(100)", "not null": "1", "default": "", "comment": ""},
-                       "v": {"type": "mediumtext", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uid_cat_k": ["UNIQUE", "uid", "cat", "k"]
-               }
-       },
-       "permissionset": {
-               "comment": "",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "Owner id of this permission set"},
-                       "allow_cid": {"type": "mediumtext", "comment": "Access Control - list of allowed contact.id '<19><78>'"},
-                       "allow_gid": {"type": "mediumtext", "comment": "Access Control - list of allowed groups"},
-                       "deny_cid": {"type": "mediumtext", "comment": "Access Control - list of denied contact.id"},
-                       "deny_gid": {"type": "mediumtext", "comment": "Access Control - list of denied groups"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uid_allow_cid_allow_gid_deny_cid_deny_gid": ["allow_cid(50)", "allow_gid(30)", "deny_cid(50)", "deny_gid(30)"]
-               }
-       },
-       "photo": {
-               "comment": "photo storage",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "Owner User id"},
-                       "contact-id": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": "contact.id"},
-                       "guid": {"type": "char(16)", "not null": "1", "default": "", "comment": "A unique identifier for this photo"},
-                       "resource-id": {"type": "char(32)", "not null": "1", "default": "", "comment": ""},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "creation date"},
-                       "edited": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "last edited date"},
-                       "title": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "desc": {"type": "text", "comment": ""},
-                       "album": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "The name of the album to which the photo belongs"},
-                       "filename": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "type": {"type": "varchar(30)", "not null": "1", "default": "image/jpeg"},
-                       "height": {"type": "smallint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "width": {"type": "smallint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "datasize": {"type": "int unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "data": {"type": "mediumblob", "not null": "1", "comment": ""},
-                       "scale": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "profile": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "allow_cid": {"type": "mediumtext", "comment": "Access Control - list of allowed contact.id '<19><78>'"},
-                       "allow_gid": {"type": "mediumtext", "comment": "Access Control - list of allowed groups"},
-                       "deny_cid": {"type": "mediumtext", "comment": "Access Control - list of denied contact.id"},
-                       "deny_gid": {"type": "mediumtext", "comment": "Access Control - list of denied groups"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "contactid": ["contact-id"],
-                       "uid_contactid": ["uid", "contact-id"],
-                       "uid_profile": ["uid", "profile"],
-                       "uid_album_scale_created": ["uid", "album(32)", "scale", "created"],
-                       "uid_album_resource-id_created": ["uid", "album(32)", "resource-id", "created"],
-                       "resource-id": ["resource-id"]
-               }
-       },
-       "poll": {
-               "comment": "Currently unused table for storing poll results",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": ""},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"},
-                       "q0": {"type": "text", "comment": ""},
-                       "q1": {"type": "text", "comment": ""},
-                       "q2": {"type": "text", "comment": ""},
-                       "q3": {"type": "text", "comment": ""},
-                       "q4": {"type": "text", "comment": ""},
-                       "q5": {"type": "text", "comment": ""},
-                       "q6": {"type": "text", "comment": ""},
-                       "q7": {"type": "text", "comment": ""},
-                       "q8": {"type": "text", "comment": ""},
-                       "q9": {"type": "text", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uid": ["uid"]
-               }
-       },
-       "poll_result": {
-               "comment": "data for polls - currently unused",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "poll_id": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"poll": "id"}},
-                       "choice": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "poll_id": ["poll_id"]
-               }
-       },
-       "process": {
-               "comment": "Currently running system processes",
-               "fields": {
-                       "pid": {"type": "int unsigned", "not null": "1", "primary": "1", "comment": ""},
-                       "command": {"type": "varbinary(32)", "not null": "1", "default": "", "comment": ""},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["pid"],
-                       "command": ["command"]
-               }
-       },
-       "profile": {
-               "comment": "user profiles data",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "Owner User id"},
-                       "profile-name": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "Name of the profile"},
-                       "is-default": {"type": "boolean", "not null": "1", "default": "0", "comment": "Mark this profile as default profile"},
-                       "hide-friends": {"type": "boolean", "not null": "1", "default": "0", "comment": "Hide friend list from viewers of this profile"},
-                       "name": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "pdesc": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "Title or description"},
-                       "dob": {"type": "varchar(32)", "not null": "1", "default": "0000-00-00", "comment": "Day of birth"},
-                       "address": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "locality": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "region": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "postal-code": {"type": "varchar(32)", "not null": "1", "default": "", "comment": ""},
-                       "country-name": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "hometown": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "gender": {"type": "varchar(32)", "not null": "1", "default": "", "comment": ""},
-                       "marital": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "with": {"type": "text", "comment": ""},
-                       "howlong": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "sexual": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "politic": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "religion": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "pub_keywords": {"type": "text", "comment": ""},
-                       "prv_keywords": {"type": "text", "comment": ""},
-                       "likes": {"type": "text", "comment": ""},
-                       "dislikes": {"type": "text", "comment": ""},
-                       "about": {"type": "text", "comment": ""},
-                       "summary": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "music": {"type": "text", "comment": ""},
-                       "book": {"type": "text", "comment": ""},
-                       "tv": {"type": "text", "comment": ""},
-                       "film": {"type": "text", "comment": ""},
-                       "interest": {"type": "text", "comment": ""},
-                       "romance": {"type": "text", "comment": ""},
-                       "work": {"type": "text", "comment": ""},
-                       "education": {"type": "text", "comment": ""},
-                       "contact": {"type": "text", "comment": ""},
-                       "homepage": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "xmpp": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "photo": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "thumb": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "publish": {"type": "boolean", "not null": "1", "default": "0", "comment": "publish default profile in local directory"},
-                       "net-publish": {"type": "boolean", "not null": "1", "default": "0", "comment": "publish profile in global directory"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uid_is-default": ["uid", "is-default"]
-               }
-       },
-       "profile_check": {
-               "comment": "DFRN remote auth use",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"},
-                       "cid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": "contact.id"},
-                       "dfrn_id": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "sec": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "expire": {"type": "int unsigned", "not null": "1", "default": "0", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"]
-               }
-       },
-       "push_subscriber": {
-               "comment": "Used for OStatus: Contains feed subscribers",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"},
-                       "callback_url": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "topic": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "nickname": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "push": {"type": "tinyint", "not null": "1", "default": "0", "comment": "Retrial counter"},
-                       "last_update": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Date of last successful trial"},
-                       "next_try": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Next retrial date"},
-                       "renewed": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Date of last subscription renewal"},
-                       "secret": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "next_try": ["next_try"]
-               }
-       },
-       "queue": {
-               "comment": "Queue for messages that couldn't be delivered",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "cid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": "Message receiver"},
-                       "network": {"type": "char(4)", "not null": "1", "default": "", "comment": "Receiver's network"},
-                       "guid": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "Unique GUID of the message"},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Date, when the message was created"},
-                       "last": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Date of last trial"},
-                       "next": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Next retrial date"},
-                       "retrial": {"type": "tinyint", "not null": "1", "default": "0", "comment": "Retrial counter"},
-                       "content": {"type": "mediumtext", "comment": ""},
-                       "batch": {"type": "boolean", "not null": "1", "default": "0", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "last": ["last"],
-                       "next": ["next"]
-               }
-       },
-       "register": {
-               "comment": "registrations requiring admin approval",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "hash": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"},
-                       "password": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "language": {"type": "varchar(16)", "not null": "1", "default": "", "comment": ""},
-                       "note": {"type": "text", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"]
-               }
-       },
-       "search": {
-               "comment": "",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"},
-                       "term": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "uid": ["uid"]
-               }
-       },
-       "session": {
-               "comment": "web session storage",
-               "fields": {
-                       "id": {"type": "bigint unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "sid": {"type": "varbinary(255)", "not null": "1", "default": "", "comment": ""},
-                       "data": {"type": "text", "comment": ""},
-                       "expire": {"type": "int unsigned", "not null": "1", "default": "0", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "sid": ["sid(64)"],
-                       "expire": ["expire"]
-               }
-       },
-       "sign": {
-               "comment": "Diaspora signatures",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "iid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"item": "id"}, "comment": "item.id"},
-                       "signed_text": {"type": "mediumtext", "comment": ""},
-                       "signature": {"type": "text", "comment": ""},
-                       "signer": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "iid": ["UNIQUE", "iid"]
-               }
-       },
-       "term": {
-               "comment": "item taxonomy (categories, tags, etc.) table",
-               "fields": {
-                       "tid": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": ""},
-                       "oid": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"item": "id"}, "comment": ""},
-                       "otype": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "type": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "term": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "url": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "guid": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "received": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "global": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"}
-               },
-               "indexes": {
-                       "PRIMARY": ["tid"],
-                       "oid_otype_type_term": ["oid", "otype", "type", "term(32)"],
-                       "uid_otype_type_term_global_created": ["uid", "otype", "type", "term(32)", "global", "created"],
-                       "uid_otype_type_url": ["uid", "otype", "type", "url(64)"],
-                       "guid": ["guid(64)"]
-               }
-       },
-       "thread": {
-               "comment": "Thread related data",
-               "fields": {
-                       "iid": {"type": "int unsigned", "not null": "1", "default": "0", "primary": "1", "relation": {"item": "id"}, "comment": "sequential ID"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"},
-                       "contact-id": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": ""},
-                       "owner-id": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": "Item owner"},
-                       "author-id": {"type": "int unsigned", "not null": "1", "default": "0", "relation": {"contact": "id"}, "comment": "Item author"},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "edited": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "commented": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "received": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "changed": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""},
-                       "wall": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "private": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "pubmail": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "moderated": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "visible": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "starred": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "ignored": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "post-type": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": "Post type (personal note, bookmark, ...)"},
-                       "unseen": {"type": "boolean", "not null": "1", "default": "1", "comment": ""},
-                       "deleted": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "origin": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "forum_mode": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "mention": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "network": {"type": "char(4)", "not null": "1", "default": "", "comment": ""},
-                       "bookmark": {"type": "boolean", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["iid"],
-                       "uid_network_commented": ["uid", "network", "commented"],
-                       "uid_network_created": ["uid", "network", "created"],
-                       "uid_contactid_commented": ["uid", "contact-id", "commented"],
-                       "uid_contactid_created": ["uid", "contact-id", "created"],
-                       "contactid": ["contact-id"],
-                       "ownerid": ["owner-id"],
-                       "authorid": ["author-id"],
-                       "uid_created": ["uid", "created"],
-                       "uid_commented": ["uid", "commented"],
-                       "uid_wall_created": ["uid", "wall", "created"],
-                       "private_wall_origin_commented": ["private", "wall", "origin", "commented"]
-               }
-       },
-       "tokens": {
-               "comment": "OAuth usage",
-               "fields": {
-                       "id": {"type": "varchar(40)", "not null": "1", "primary": "1", "comment": ""},
-                       "secret": {"type": "text", "comment": ""},
-                       "client_id": {"type": "varchar(20)", "not null": "1", "default": "", "relation": {"clients": "client_id"}},
-                       "expires": {"type": "int", "not null": "1", "default": "0", "comment": ""},
-                       "scope": {"type": "varchar(200)", "not null": "1", "default": "", "comment": ""},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "User id"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"]
-               }
-       },
-       "user": {
-               "comment": "The local users",
-               "fields": {
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "parent-uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "relation": {"user": "uid"}, "comment": "The parent user that has full control about this user"},
-                       "guid": {"type": "varchar(64)", "not null": "1", "default": "", "comment": "A unique identifier for this user"},
-                       "username": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "Name that this user is known by"},
-                       "password": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "encrypted password"},
-                       "legacy_password": {"type": "boolean", "not null": "1", "default": "0", "comment": "Is the password hash double-hashed?"},
-                       "nickname": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "nick- and user name"},
-                       "email": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "the users email address"},
-                       "openid": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""},
-                       "timezone": {"type": "varchar(128)", "not null": "1", "default": "", "comment": "PHP-legal timezone"},
-                       "language": {"type": "varchar(32)", "not null": "1", "default": "en", "comment": "default language"},
-                       "register_date": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "timestamp of registration"},
-                       "login_date": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "timestamp of last login"},
-                       "default-location": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "Default for item.location"},
-                       "allow_location": {"type": "boolean", "not null": "1", "default": "0", "comment": "1 allows to display the location"},
-                       "theme": {"type": "varchar(255)", "not null": "1", "default": "", "comment": "user theme preference"},
-                       "pubkey": {"type": "text", "comment": "RSA public key 4096 bit"},
-                       "prvkey": {"type": "text", "comment": "RSA private key 4096 bit"},
-                       "spubkey": {"type": "text", "comment": ""},
-                       "sprvkey": {"type": "text", "comment": ""},
-                       "verified": {"type": "boolean", "not null": "1", "default": "0", "comment": "user is verified through email"},
-                       "blocked": {"type": "boolean", "not null": "1", "default": "0", "comment": "1 for user is blocked"},
-                       "blockwall": {"type": "boolean", "not null": "1", "default": "0", "comment": "Prohibit contacts to post to the profile page of the user"},
-                       "hidewall": {"type": "boolean", "not null": "1", "default": "0", "comment": "Hide profile details from unkown viewers"},
-                       "blocktags": {"type": "boolean", "not null": "1", "default": "0", "comment": "Prohibit contacts to tag the post of this user"},
-                       "unkmail": {"type": "boolean", "not null": "1", "default": "0", "comment": "Permit unknown people to send private mails to this user"},
-                       "cntunkmail": {"type": "int unsigned", "not null": "1", "default": "10", "comment": ""},
-                       "notify-flags": {"type": "smallint unsigned", "not null": "1", "default": "65535", "comment": "email notification options"},
-                       "page-flags": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": "page/profile type"},
-                       "account-type": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "prvnets": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "pwdreset": {"type": "varchar(255)", "comment": "Password reset request token"},
-                       "pwdreset_time": {"type": "datetime", "comment": "Timestamp of the last password reset request"},
-                       "maxreq": {"type": "int unsigned", "not null": "1", "default": "10", "comment": ""},
-                       "expire": {"type": "int unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "account_removed": {"type": "boolean", "not null": "1", "default": "0", "comment": "if 1 the account is removed"},
-                       "account_expired": {"type": "boolean", "not null": "1", "default": "0", "comment": ""},
-                       "account_expires_on": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "timestamp when account expires and will be deleted"},
-                       "expire_notification_sent": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "timestamp of last warning of account expiration"},
-                       "def_gid": {"type": "int unsigned", "not null": "1", "default": "0", "comment": ""},
-                       "allow_cid": {"type": "mediumtext", "comment": "default permission for this user"},
-                       "allow_gid": {"type": "mediumtext", "comment": "default permission for this user"},
-                       "deny_cid": {"type": "mediumtext", "comment": "default permission for this user"},
-                       "deny_gid": {"type": "mediumtext", "comment": "default permission for this user"},
-                       "openidserver": {"type": "text", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["uid"],
-                       "nickname": ["nickname(32)"]
-               }
-       },
-       "userd": {
-               "comment": "Deleted usernames",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "sequential ID"},
-                       "username": {"type": "varchar(255)", "not null": "1", "comment": ""}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "username": ["username(32)"]
-               }
-       },
-       "user-contact": {
-               "comment": "User specific public contact data",
-               "fields": {
-                       "cid": {"type": "int unsigned", "not null": "1", "default": "0", "primary": "1", "relation": {"contact": "id"}, "comment": "Contact id of the linked public contact"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "primary": "1", "relation": {"user": "uid"}, "comment": "User id"},
-                       "blocked": {"type": "boolean", "comment": "Contact is completely blocked for this user"},
-                       "ignored": {"type": "boolean", "comment": "Posts from this contact are ignored"},
-                       "collapsed": {"type": "boolean", "comment": "Posts from this contact are collapsed"}
-               },
-               "indexes": {
-                       "PRIMARY": ["uid", "cid"]
-               }
-       },
-       "user-item": {
-               "comment": "User specific item data",
-               "fields": {
-                       "iid": {"type": "int unsigned", "not null": "1", "default": "0", "primary": "1", "relation": {"item": "id"}, "comment": "Item id"},
-                       "uid": {"type": "mediumint unsigned", "not null": "1", "default": "0", "primary": "1", "relation": {"user": "uid"}, "comment": "User id"},
-                       "hidden": {"type": "boolean", "not null": "1", "default": "0", "comment": "Marker to hide an item from the user"},
-                       "ignored": {"type": "boolean", "comment": "Ignore this thread if set"}
-               },
-               "indexes": {
-                       "PRIMARY": ["uid", "iid"]
-               }
-       },
-       "worker-ipc": {
-               "comment": "Inter process communication between the frontend and the worker",
-               "fields": {
-                       "key": {"type": "int", "not null": "1", "primary": "1", "comment": ""},
-                       "jobs": {"type": "boolean", "comment": "Flag for outstanding jobs"}
-               },
-               "indexes": {
-                       "PRIMARY": ["key"]
-               },
-               "engine": "MEMORY"
-       },
-       "workerqueue": {
-               "comment": "Background tasks queue entries",
-               "fields": {
-                       "id": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "Auto incremented worker task id"},
-                       "parameter": {"type": "mediumblob", "comment": "Task command"},
-                       "priority": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": "Task priority"},
-                       "created": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Creation date"},
-                       "pid": {"type": "int unsigned", "not null": "1", "default": "0", "comment": "Process id of the worker"},
-                       "executed": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Execution date"},
-                       "next_try": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Next retrial date"},
-                       "retrial": {"type": "tinyint", "not null": "1", "default": "0", "comment": "Retrial counter"},
-                       "done": {"type": "boolean", "not null": "1", "default": "0", "comment": "Marked 1 when the task was done - will be deleted later"}
-               },
-               "indexes": {
-                       "PRIMARY": ["id"],
-                       "pid": ["pid"],
-                       "parameter": ["parameter(64)"],
-                       "priority_created_next_try": ["priority", "created", "next_try"],
-                       "done_executed_next_try": ["done", "executed", "next_try"]
-               }
-       }
-}
diff --git a/config/dbstructure.php b/config/dbstructure.php
new file mode 100644 (file)
index 0000000..96f90fb
--- /dev/null
@@ -0,0 +1,1374 @@
+<?php
+
+/* Main database structure configuration file.
+ *
+ * Here are described all the tables, fields and indexes Friendica needs to work.
+ *
+ * Syntax (braces indicate optionale values):
+ * "<table name>" => [
+ *     "comment" => "Description of the table",
+ *     "fields" => [
+ *             "<field name>" => [
+ *                     "type" => "<field type>{(<field size>)} <unsigned>",
+ *                     "not null" => 0|1,
+ *                     {"extra" => "auto_increment",}
+ *                     {"default" => "<default value>",}
+ *                     {"default" => NULL_DATE,} (for datetime fields)
+ *                     {"primary" => "1",}
+ *                     {"relation" => ["<foreign key table name>" => "<foreign key field name>"],}
+ *                     "comment" => "Description of the fields"
+ *             ],
+ *             ...
+ *     ],
+ *     "indexes" => [
+ *             "PRIMARY" => ["<primary key field name>", ...],
+ *             "<index name>" => [{"UNIQUE",} "<field name>{(<key size>)}", ...]
+ *             ...
+ *     ],
+ * ],
+ *
+ * If you need to make any change, make sure to increment the DB_UPDATE_VERSION constant value below.
+ *
+ */
+
+use Friendica\Database\DBA;
+
+if (!defined('DB_UPDATE_VERSION')) {
+       define('DB_UPDATE_VERSION', 1289);
+}
+
+return [
+       "addon" => [
+               "comment" => "registered addons",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
+                       "name" => ["type" => "varchar(50)", "not null" => "1", "default" => "", "comment" => "addon base (file)name"],
+                       "version" => ["type" => "varchar(50)", "not null" => "1", "default" => "", "comment" => "currently unused"],
+                       "installed" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "currently always 1"],
+                       "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "currently unused"],
+                       "timestamp" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "file timestamp to check for reloads"],
+                       "plugin_admin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 = has admin config, 0 = has no admin config"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "name" => ["UNIQUE", "name"],
+               ]
+       ],
+       "apcontact" => [
+               "comment" => "ActivityPub compatible contacts - used in the ActivityPub implementation",
+               "fields" => [
+                       "url" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "URL of the contact"],
+                       "uuid" => ["type" => "varchar(255)", "comment" => ""],
+                       "type" => ["type" => "varchar(20)", "not null" => "1", "comment" => ""],
+                       "following" => ["type" => "varchar(255)", "comment" => ""],
+                       "followers" => ["type" => "varchar(255)", "comment" => ""],
+                       "inbox" => ["type" => "varchar(255)", "not null" => "1", "comment" => ""],
+                       "outbox" => ["type" => "varchar(255)", "comment" => ""],
+                       "sharedinbox" => ["type" => "varchar(255)", "comment" => ""],
+                       "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "name" => ["type" => "varchar(255)", "comment" => ""],
+                       "about" => ["type" => "text", "comment" => ""],
+                       "photo" => ["type" => "varchar(255)", "comment" => ""],
+                       "addr" => ["type" => "varchar(255)", "comment" => ""],
+                       "alias" => ["type" => "varchar(255)", "comment" => ""],
+                       "pubkey" => ["type" => "text", "comment" => ""],
+                       "baseurl" => ["type" => "varchar(255)", "comment" => "baseurl of the ap contact"],
+                       "updated" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""]
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["url"],
+                       "addr" => ["addr(32)"],
+                       "alias" => ["alias(190)"],
+                       "url" => ["followers(190)"]
+               ]
+       ],
+       "attach" => [
+               "comment" => "file attachments",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "generated index"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
+                       "hash" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "hash"],
+                       "filename" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "filename of original"],
+                       "filetype" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "mimetype"],
+                       "filesize" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "size in bytes"],
+                       "data" => ["type" => "longblob", "not null" => "1", "comment" => "file data"],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "creation time"],
+                       "edited" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "last edit time"],
+                       "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>"],
+                       "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
+                       "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
+                       "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+               ]
+       ],
+       "auth_codes" => [
+               "comment" => "OAuth usage",
+               "fields" => [
+                       "id" => ["type" => "varchar(40)", "not null" => "1", "primary" => "1", "comment" => ""],
+                       "client_id" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "relation" => ["clients" => "client_id"],
+                               "comment" => ""],
+                       "redirect_uri" => ["type" => "varchar(200)", "not null" => "1", "default" => "", "comment" => ""],
+                       "expires" => ["type" => "int", "not null" => "1", "default" => "0", "comment" => ""],
+                       "scope" => ["type" => "varchar(250)", "not null" => "1", "default" => "", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+               ]
+       ],
+       "cache" => [
+               "comment" => "Stores temporary data",
+               "fields" => [
+                       "k" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "cache key"],
+                       "v" => ["type" => "mediumtext", "comment" => "cached serialized value"],
+                       "expires" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime of cache expiration"],
+                       "updated" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime of cache insertion"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["k"],
+                       "k_expires" => ["k", "expires"],
+               ]
+       ],
+       "challenge" => [
+               "comment" => "",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "challenge" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "dfrn-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "type" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "last_update" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+               ]
+       ],
+       "clients" => [
+               "comment" => "OAuth usage",
+               "fields" => [
+                       "client_id" => ["type" => "varchar(20)", "not null" => "1", "primary" => "1", "comment" => ""],
+                       "pw" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => ""],
+                       "redirect_uri" => ["type" => "varchar(200)", "not null" => "1", "default" => "", "comment" => ""],
+                       "name" => ["type" => "text", "comment" => ""],
+                       "icon" => ["type" => "text", "comment" => ""],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["client_id"],
+               ]
+       ],
+       "config" => [
+               "comment" => "main configuration storage",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
+                       "cat" => ["type" => "varbinary(50)", "not null" => "1", "default" => "", "comment" => ""],
+                       "k" => ["type" => "varbinary(50)", "not null" => "1", "default" => "", "comment" => ""],
+                       "v" => ["type" => "mediumtext", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "cat_k" => ["UNIQUE", "cat", "k"],
+               ]
+       ],
+       "contact" => [
+               "comment" => "contact table",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "self" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 if the contact is the user him/her self"],
+                       "remote_self" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "rel" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "The kind of the relation between the user and the contact"],
+                       "duplex" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network protocol of the contact"],
+                       "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this contact is known by"],
+                       "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Nick- and user name of the contact"],
+                       "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "about" => ["type" => "text", "comment" => ""],
+                       "keywords" => ["type" => "text", "comment" => "public keywords (interests) of the contact"],
+                       "gender" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
+                       "xmpp" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "attag" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "avatar" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "photo" => ["type" => "varchar(255)", "default" => "", "comment" => "Link to the profile photo of the contact"],
+                       "thumb" => ["type" => "varchar(255)", "default" => "", "comment" => "Link to the profile photo (thumb size)"],
+                       "micro" => ["type" => "varchar(255)", "default" => "", "comment" => "Link to the profile photo (micro size)"],
+                       "site-pubkey" => ["type" => "text", "comment" => ""],
+                       "issued-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "dfrn-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "nurl" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "addr" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "alias" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "pubkey" => ["type" => "text", "comment" => "RSA public key 4096 bit"],
+                       "prvkey" => ["type" => "text", "comment" => "RSA private key 4096 bit"],
+                       "batch" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "request" => ["type" => "varchar(255)", "comment" => ""],
+                       "notify" => ["type" => "varchar(255)", "comment" => ""],
+                       "poll" => ["type" => "varchar(255)", "comment" => ""],
+                       "confirm" => ["type" => "varchar(255)", "comment" => ""],
+                       "poco" => ["type" => "varchar(255)", "comment" => ""],
+                       "aes_allow" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "ret-aes" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "usehub" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "subhub" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "hub-verify" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "last-update" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of the last try to update the contact info"],
+                       "success_update" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of the last successful contact update"],
+                       "failure_update" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of the last failed update"],
+                       "name-date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "uri-date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "avatar-date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "term-date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "last-item" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "date of the last post"],
+                       "priority" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "blocked" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
+                       "readonly" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "posts of the contact are readonly"],
+                       "writable" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "forum" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "contact is a forum"],
+                       "prv" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "contact is a private group"],
+                       "contact-type" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => ""],
+                       "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "archive" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "pending" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
+                       "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Contact has been deleted"],
+                       "rating" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => ""],
+                       "reason" => ["type" => "text", "comment" => ""],
+                       "closeness" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "99", "comment" => ""],
+                       "info" => ["type" => "mediumtext", "comment" => ""],
+                       "profile-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "bdyear" => ["type" => "varchar(4)", "not null" => "1", "default" => "", "comment" => ""],
+                       "bd" => ["type" => "date", "not null" => "1", "default" => DBA::NULL_DATE, "comment" => ""],
+                       "notify_new_posts" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "fetch_further_information" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "ffi_keyword_blacklist" => ["type" => "text", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uid_name" => ["uid", "name(190)"],
+                       "self_uid" => ["self", "uid"],
+                       "alias_uid" => ["alias(32)", "uid"],
+                       "pending_uid" => ["pending", "uid"],
+                       "blocked_uid" => ["blocked", "uid"],
+                       "uid_rel_network_poll" => ["uid", "rel", "network", "poll(64)", "archive"],
+                       "uid_network_batch" => ["uid", "network", "batch(64)"],
+                       "addr_uid" => ["addr(32)", "uid"],
+                       "nurl_uid" => ["nurl(32)", "uid"],
+                       "nick_uid" => ["nick(32)", "uid"],
+                       "dfrn-id" => ["dfrn-id(64)"],
+                       "issued-id" => ["issued-id(64)"],
+               ]
+       ],
+       "conv" => [
+               "comment" => "private messages",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this conversation"],
+                       "recips" => ["type" => "text", "comment" => "sender_handle;recipient_handle"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
+                       "creator" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "handle of creator"],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "creation timestamp"],
+                       "updated" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "edited timestamp"],
+                       "subject" => ["type" => "text", "comment" => "subject of initial message"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uid" => ["uid"],
+               ]
+       ],
+       "conversation" => [
+               "comment" => "Raw data and structure information for messages",
+               "fields" => [
+                       "item-uri" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "Original URI of the item - unrelated to the table with the same name"],
+                       "reply-to-uri" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => "URI to which this item is a reply"],
+                       "conversation-uri" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => "GNU Social conversation URI"],
+                       "conversation-href" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => "GNU Social conversation link"],
+                       "protocol" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "255", "comment" => "The protocol of the item"],
+                       "source" => ["type" => "mediumtext", "comment" => "Original source"],
+                       "received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Receiving date"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["item-uri"],
+                       "conversation-uri" => ["conversation-uri"],
+                       "received" => ["received"],
+               ]
+       ],
+       "diaspora-interaction" => [
+               "comment" => "Signed Diaspora Interaction",
+               "fields" => [
+                       "uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
+                       "interaction" => ["type" => "mediumtext", "comment" => "The Diaspora interaction"]
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["uri-id"]
+               ]
+       ],
+       "event" => [
+               "comment" => "Events",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
+                       "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact_id (ID of the contact in contact table)"],
+                       "uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "creation time"],
+                       "edited" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "last edit time"],
+                       "start" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "event start time"],
+                       "finish" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "event end time"],
+                       "summary" => ["type" => "text", "comment" => "short description or title of the event"],
+                       "desc" => ["type" => "text", "comment" => "event description"],
+                       "location" => ["type" => "text", "comment" => "event location"],
+                       "type" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => "event or birthday"],
+                       "nofinish" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if event does have no end this is 1"],
+                       "adjust" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "adjust to timezone of the recipient (0 or 1)"],
+                       "ignore" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "0 or 1"],
+                       "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
+                       "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
+                       "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
+                       "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uid_start" => ["uid", "start"],
+               ]
+       ],
+       "fcontact" => [
+               "comment" => "Diaspora compatible contacts - used in the Diaspora implementation",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "unique id"],
+                       "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "request" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "addr" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "batch" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "notify" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "poll" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "confirm" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "priority" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
+                       "alias" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "pubkey" => ["type" => "text", "comment" => ""],
+                       "updated" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "addr" => ["addr(32)"],
+                       "url" => ["UNIQUE", "url(190)"],
+               ]
+       ],
+       "fsuggest" => [
+               "comment" => "friend suggestion stuff",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
+                       "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "request" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "note" => ["type" => "text", "comment" => ""],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+               ]
+       ],
+       "gcign" => [
+               "comment" => "contacts ignored by friend suggestions",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Local User id"],
+                       "gcid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gcontact" => "id"], "comment" => "gcontact.id of ignored contact"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uid" => ["uid"],
+                       "gcid" => ["gcid"],
+               ]
+       ],
+       "gcontact" => [
+               "comment" => "global contacts",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this contact is known by"],
+                       "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Nick- and user name of the contact"],
+                       "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the contacts profile page"],
+                       "nurl" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the profile photo"],
+                       "connect" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "updated" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "last_contact" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "last_failure" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "about" => ["type" => "text", "comment" => ""],
+                       "keywords" => ["type" => "text", "comment" => "puplic keywords (interests)"],
+                       "gender" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
+                       "birthday" => ["type" => "varchar(32)", "not null" => "1", "default" => DBA::NULL_DATE, "comment" => ""],
+                       "community" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 if contact is forum account"],
+                       "contact-type" => ["type" => "tinyint", "not null" => "1", "default" => "-1", "comment" => ""],
+                       "hide" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 = should be hidden from search"],
+                       "nsfw" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 = contact posts nsfw content"],
+                       "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "social network protocol"],
+                       "addr" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "notify" => ["type" => "varchar(255)", "comment" => ""],
+                       "alias" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "generation" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "server_url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "baseurl of the contacts server"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "nurl" => ["UNIQUE", "nurl(190)"],
+                       "name" => ["name(64)"],
+                       "nick" => ["nick(32)"],
+                       "addr" => ["addr(64)"],
+                       "hide_network_updated" => ["hide", "network", "updated"],
+                       "updated" => ["updated"],
+               ]
+       ],
+       "glink" => [
+               "comment" => "'friends of friends' linkages derived from poco",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "gcid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gcontact" => "id"], "comment" => ""],
+                       "zcid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gcontact" => "id"], "comment" => ""],
+                       "updated" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "cid_uid_gcid_zcid" => ["UNIQUE", "cid", "uid", "gcid", "zcid"],
+                       "gcid" => ["gcid"],
+               ]
+       ],
+       "group" => [
+               "comment" => "privacy groups, group info",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
+                       "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 indicates the member list is not private"],
+                       "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 indicates the group has been deleted"],
+                       "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "human readable name of group"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uid" => ["uid"],
+               ]
+       ],
+       "group_member" => [
+               "comment" => "privacy groups, member info",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "gid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["group" => "id"], "comment" => "groups.id of the associated group"],
+                       "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id of the member assigned to the associated group"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "contactid" => ["contact-id"],
+                       "gid_contactid" => ["UNIQUE", "gid", "contact-id"],
+               ]
+       ],
+       "gserver" => [
+               "comment" => "Global servers",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "nurl" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "version" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "site_name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "info" => ["type" => "text", "comment" => ""],
+                       "register_policy" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => ""],
+                       "registered-users" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "Number of registered users"],
+                       "poco" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "noscrape" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
+                       "platform" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "relay-subscribe" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Has the server subscribed to the relay system"],
+                       "relay-scope" => ["type" => "varchar(10)", "not null" => "1", "default" => "", "comment" => "The scope of messages that the server wants to get"],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "last_poco_query" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "last_contact" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "last_failure" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "nurl" => ["UNIQUE", "nurl(190)"],
+               ]
+       ],
+       "gserver-tag" => [
+               "comment" => "Tags that the server has subscribed",
+               "fields" => [
+                       "gserver-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gserver" => "id"], "primary" => "1",
+                               "comment" => "The id of the gserver"],
+                       "tag" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "primary" => "1", "comment" => "Tag that the server has subscribed"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["gserver-id", "tag"],
+                       "tag" => ["tag"],
+               ]
+       ],
+       "hook" => [
+               "comment" => "addon hook registry",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "hook" => ["type" => "varbinary(100)", "not null" => "1", "default" => "", "comment" => "name of hook"],
+                       "file" => ["type" => "varbinary(200)", "not null" => "1", "default" => "", "comment" => "relative filename of hook handler"],
+                       "function" => ["type" => "varbinary(200)", "not null" => "1", "default" => "", "comment" => "function name of hook handler"],
+                       "priority" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => "not yet implemented - can be used to sort conflicts in hook handling by calling handlers in priority order"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "hook_file_function" => ["UNIQUE", "hook", "file", "function"],
+               ]
+       ],
+       "intro" => [
+               "comment" => "",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "fid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["fcontact" => "id"], "comment" => ""],
+                       "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
+                       "knowyou" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "duplex" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "note" => ["type" => "text", "comment" => ""],
+                       "hash" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "datetime" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "blocked" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
+                       "ignore" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+               ]
+       ],
+       "item" => [
+               "comment" => "Structure for all posts",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => ["thread" => "iid"]],
+                       "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this item"],
+                       "uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "uri-id" => ["type" => "int unsigned", "relation" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
+                       "uri-hash" => ["type" => "varchar(80)", "not null" => "1", "default" => "", "comment" => "RIPEMD-128 hash from uri"],
+                       "parent" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => "item.id of the parent to this item if it is a reply of some form; otherwise this must be set to the id of this item"],
+                       "parent-uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "uri of the parent to this item"],
+                       "parent-uri-id" => ["type" => "int unsigned", "relation" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the parent uri"],
+                       "thr-parent" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "If the parent of this item is not the top-level item in the conversation, the uri of the immediate parent; otherwise set to parent-uri"],
+                       "thr-parent-id" => ["type" => "int unsigned", "relation" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the thread parent uri"],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Creation timestamp."],
+                       "edited" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of last edit (default is created)"],
+                       "commented" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of last comment/reply to this item"],
+                       "received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime"],
+                       "changed" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date that something in the conversation changed, indicating clients should fetch the conversation again"],
+                       "gravity" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network from where the item comes from"],
+                       "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Link to the contact table with uid=0 of the owner of this item"],
+                       "author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Link to the contact table with uid=0 of the author of this item"],
+                       "icid" => ["type" => "int unsigned", "relation" => ["item-content" => "id"], "comment" => "Id of the item-content table entry that contains the whole item content"],
+                       "iaid" => ["type" => "int unsigned", "relation" => ["item-activity" => "id"], "comment" => "Id of the item-activity table entry that contains the activity data"],
+                       "extid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
+                       "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "private" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "distribution is restricted"],
+                       "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been deleted"],
+                       // User specific fields. Eventually they will move to user-item
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"],
+                       "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id"],
+                       "wall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "This item was posted to the wall of uid"],
+                       "origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item originated at this site"],
+                       "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been favourited"],
+                       "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "item has not been seen"],
+                       "mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "The owner of this item was mentioned in it"],
+                       "forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "psid" => ["type" => "int unsigned", "relation" => ["permissionset" => "id"], "comment" => "ID of the permission set of this post"],
+                       // It has to be decided whether these fields belong to the user or the structure
+                       "resource-id" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type"],
+                       "event-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
+                       // Could possibly be replaced by the "attach" table?
+                       "attach" => ["type" => "mediumtext", "comment" => "JSON structure representing attachments to this item"],
+                       // Deprecated fields. Will be removed in upcoming versions
+                       "allow_cid" => ["type" => "mediumtext", "comment" => "Deprecated"],
+                       "allow_gid" => ["type" => "mediumtext", "comment" => "Deprecated"],
+                       "deny_cid" => ["type" => "mediumtext", "comment" => "Deprecated"],
+                       "deny_gid" => ["type" => "mediumtext", "comment" => "Deprecated"],
+                       "postopts" => ["type" => "text", "comment" => "Deprecated"],
+                       "inform" => ["type" => "mediumtext", "comment" => "Deprecated"],
+                       "type" => ["type" => "varchar(20)", "comment" => "Deprecated"],
+                       "bookmark" => ["type" => "boolean", "comment" => "Deprecated"],
+                       "file" => ["type" => "mediumtext", "comment" => "Deprecated"],
+                       "location" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                       "coord" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                       "tag" => ["type" => "mediumtext", "comment" => "Deprecated"],
+                       "plink" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                       "title" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                       "content-warning" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                       "body" => ["type" => "mediumtext", "comment" => "Deprecated"],
+                       "app" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                       "verb" => ["type" => "varchar(100)", "comment" => "Deprecated"],
+                       "object-type" => ["type" => "varchar(100)", "comment" => "Deprecated"],
+                       "object" => ["type" => "text", "comment" => "Deprecated"],
+                       "target-type" => ["type" => "varchar(100)", "comment" => "Deprecated"],
+                       "target" => ["type" => "text", "comment" => "Deprecated"],
+                       "author-name" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                       "author-link" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                       "author-avatar" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                       "owner-name" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                       "owner-link" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                       "owner-avatar" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                       "rendered-hash" => ["type" => "varchar(32)", "comment" => "Deprecated"],
+                       "rendered-html" => ["type" => "mediumtext", "comment" => "Deprecated"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "guid" => ["guid(191)"],
+                       "uri" => ["uri(191)"],
+                       "parent" => ["parent"],
+                       "parent-uri" => ["parent-uri(191)"],
+                       "extid" => ["extid(191)"],
+                       "uid_id" => ["uid", "id"],
+                       "uid_contactid_id" => ["uid", "contact-id", "id"],
+                       "uid_created" => ["uid", "created"],
+                       "uid_commented" => ["uid", "commented"],
+                       "uid_unseen_contactid" => ["uid", "unseen", "contact-id"],
+                       "uid_network_received" => ["uid", "network", "received"],
+                       "uid_network_commented" => ["uid", "network", "commented"],
+                       "uid_thrparent" => ["uid", "thr-parent(190)"],
+                       "uid_parenturi" => ["uid", "parent-uri(190)"],
+                       "uid_contactid_created" => ["uid", "contact-id", "created"],
+                       "authorid_created" => ["author-id", "created"],
+                       "ownerid" => ["owner-id"],
+                       "uid_uri" => ["uid", "uri(190)"],
+                       "resource-id" => ["resource-id"],
+                       "deleted_changed" => ["deleted", "changed"],
+                       "uid_wall_changed" => ["uid", "wall", "changed"],
+                       "uid_eventid" => ["uid", "event-id"],
+                       "icid" => ["icid"],
+                       "iaid" => ["iaid"],
+                       "psid_wall" => ["psid", "wall"],
+               ]
+       ],
+       "item-activity" => [
+               "comment" => "Activities for items",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => ["thread" => "iid"]],
+                       "uri" => ["type" => "varchar(255)", "comment" => ""],
+                       "uri-id" => ["type" => "int unsigned", "relation" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
+                       "uri-hash" => ["type" => "varchar(80)", "not null" => "1", "default" => "", "comment" => "RIPEMD-128 hash from uri"],
+                       "activity" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""]
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uri-hash" => ["UNIQUE", "uri-hash"],
+                       "uri" => ["uri(191)"],
+                       "uri-id" => ["uri-id"]
+               ]
+       ],
+       "item-content" => [
+               "comment" => "Content for all posts",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => ["thread" => "iid"]],
+                       "uri" => ["type" => "varchar(255)", "comment" => ""],
+                       "uri-id" => ["type" => "int unsigned", "relation" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
+                       "uri-plink-hash" => ["type" => "varchar(80)", "not null" => "1", "default" => "", "comment" => "RIPEMD-128 hash from uri"],
+                       "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "item title"],
+                       "content-warning" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "body" => ["type" => "mediumtext", "comment" => "item body content"],
+                       "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "text location where this item originated"],
+                       "coord" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "longitude/latitude pair representing location where this item originated"],
+                       "language" => ["type" => "text", "comment" => "Language information about this post"],
+                       "app" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "application which generated this item"],
+                       "rendered-hash" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
+                       "rendered-html" => ["type" => "mediumtext", "comment" => "item.body converted to html"],
+                       "object-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams object type"],
+                       "object" => ["type" => "text", "comment" => "JSON encoded object structure unless it is an implied object (normal post)"],
+                       "target-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams target type if applicable (URI)"],
+                       "target" => ["type" => "text", "comment" => "JSON encoded target structure if used"],
+                       "plink" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "permalink or URL to a displayable copy of the message at its source"],
+                       "verb" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams verb"]
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uri-plink-hash" => ["UNIQUE", "uri-plink-hash"],
+                       "uri" => ["uri(191)"],
+                       "uri-id" => ["uri-id"]
+               ]
+       ],
+       "item-delivery-data" => [
+               "comment" => "Delivery data for items",
+               "fields" => [
+                       "iid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item" => "id"], "comment" => "Item id"],
+                       "postopts" => ["type" => "text", "comment" => "External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery"],
+                       "inform" => ["type" => "mediumtext", "comment" => "Additional receivers of the linked item"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["iid"],
+               ]
+       ],
+       "item-uri" => [
+               "comment" => "URI and GUID for items",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"],
+                       "uri" => ["type" => "varbinary(255)", "not null" => "1", "comment" => "URI of an item"],
+                       "guid" => ["type" => "varbinary(255)", "comment" => "A unique identifier for an item"]
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uri" => ["UNIQUE", "uri"],
+                       "guid" => ["guid"]
+               ]
+       ],
+       "locks" => [
+               "comment" => "",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "name" => ["type" => "varchar(128)", "not null" => "1", "default" => "", "comment" => ""],
+                       "locked" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "pid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "Process ID"],
+                       "expires" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime of cache expiration"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "name_expires" => ["name", "expires"]
+               ]
+       ],
+       "mail" => [
+               "comment" => "private messages",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
+                       "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this private message"],
+                       "from-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "name of the sender"],
+                       "from-photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "contact photo link of the sender"],
+                       "from-url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "profile linke of the sender"],
+                       "contact-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "relation" => ["contact" => "id"], "comment" => "contact.id"],
+                       "convid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["conv" => "id"], "comment" => "conv.id"],
+                       "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "body" => ["type" => "mediumtext", "comment" => ""],
+                       "seen" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if message visited it is 1"],
+                       "reply" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "replied" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "unknown" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if sender not in the contact table this is 1"],
+                       "uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "parent-uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "creation time of the private message"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uid_seen" => ["uid", "seen"],
+                       "convid" => ["convid"],
+                       "uri" => ["uri(64)"],
+                       "parent-uri" => ["parent-uri(64)"],
+                       "contactid" => ["contact-id(32)"],
+               ]
+       ],
+       "mailacct" => [
+               "comment" => "Mail account data for fetching mails",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "server" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "port" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "ssltype" => ["type" => "varchar(16)", "not null" => "1", "default" => "", "comment" => ""],
+                       "mailbox" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "user" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "pass" => ["type" => "text", "comment" => ""],
+                       "reply_to" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "action" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "movetofolder" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "last_check" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+               ]
+       ],
+       "manage" => [
+               "comment" => "table of accounts that can manage each other",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "mid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uid_mid" => ["UNIQUE", "uid", "mid"],
+               ]
+       ],
+       "notify" => [
+               "comment" => "notifications",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "hash" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => ""],
+                       "type" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "msg" => ["type" => "mediumtext", "comment" => ""],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
+                       "link" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => "item.id"],
+                       "parent" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => ""],
+                       "seen" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "verb" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => ""],
+                       "otype" => ["type" => "varchar(10)", "not null" => "1", "default" => "", "comment" => ""],
+                       "name_cache" => ["type" => "tinytext", "comment" => "Cached bbcode parsing of name"],
+                       "msg_cache" => ["type" => "mediumtext", "comment" => "Cached bbcode parsing of msg"]
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "hash_uid" => ["hash", "uid"],
+                       "seen_uid_date" => ["seen", "uid", "date"],
+                       "uid_date" => ["uid", "date"],
+                       "uid_type_link" => ["uid", "type", "link(190)"],
+               ]
+       ],
+       "notify-threads" => [
+               "comment" => "",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "notify-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["notify" => "id"], "comment" => ""],
+                       "master-parent-item" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"],
+                               "comment" => ""],
+                       "parent-item" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "receiver-uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"],
+                               "comment" => "User id"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+               ]
+       ],
+       "oembed" => [
+               "comment" => "cache for OEmbed queries",
+               "fields" => [
+                       "url" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "page url"],
+                       "maxwidth" => ["type" => "mediumint unsigned", "not null" => "1", "primary" => "1", "comment" => "Maximum width passed to Oembed"],
+                       "content" => ["type" => "mediumtext", "comment" => "OEmbed data of the page"],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime of creation"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["url", "maxwidth"],
+                       "created" => ["created"],
+               ]
+       ],
+       "openwebauth-token" => [
+               "comment" => "Store OpenWebAuth token to verify contacts",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "type" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Verify type"],
+                       "token" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A generated token"],
+                       "meta" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime of creation"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+               ]
+       ],
+       "parsed_url" => [
+               "comment" => "cache for 'parse_url' queries",
+               "fields" => [
+                       "url" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "page url"],
+                       "guessing" => ["type" => "boolean", "not null" => "1", "default" => "0", "primary" => "1", "comment" => "is the 'guessing' mode active?"],
+                       "oembed" => ["type" => "boolean", "not null" => "1", "default" => "0", "primary" => "1", "comment" => "is the data the result of oembed?"],
+                       "content" => ["type" => "mediumtext", "comment" => "page data"],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime of creation"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["url", "guessing", "oembed"],
+                       "created" => ["created"],
+               ]
+       ],
+       "participation" => [
+               "comment" => "Storage for participation messages from Diaspora",
+               "fields" => [
+                       "iid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item" => "id"], "comment" => ""],
+                       "server" => ["type" => "varchar(60)", "not null" => "1", "primary" => "1", "comment" => ""],
+                       "cid" => ["type" => "int unsigned", "not null" => "1", "relation" => ["contact" => "id"], "comment" => ""],
+                       "fid" => ["type" => "int unsigned", "not null" => "1", "relation" => ["fcontact" => "id"], "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["iid", "server"]
+               ]
+       ],
+       "pconfig" => [
+               "comment" => "personal (per user) configuration storage",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "cat" => ["type" => "varbinary(50)", "not null" => "1", "default" => "", "comment" => ""],
+                       "k" => ["type" => "varbinary(100)", "not null" => "1", "default" => "", "comment" => ""],
+                       "v" => ["type" => "mediumtext", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uid_cat_k" => ["UNIQUE", "uid", "cat", "k"],
+               ]
+       ],
+       "permissionset" => [
+               "comment" => "",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner id of this permission set"],
+                       "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
+                       "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
+                       "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
+                       "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uid_allow_cid_allow_gid_deny_cid_deny_gid" => ["allow_cid(50)", "allow_gid(30)", "deny_cid(50)", "deny_gid(30)"],
+               ]
+       ],
+       "photo" => [
+               "comment" => "photo storage",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
+                       "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id"],
+                       "guid" => ["type" => "char(16)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this photo"],
+                       "resource-id" => ["type" => "char(32)", "not null" => "1", "default" => "", "comment" => ""],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "creation date"],
+                       "edited" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "last edited date"],
+                       "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "desc" => ["type" => "text", "comment" => ""],
+                       "album" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "The name of the album to which the photo belongs"],
+                       "filename" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "type" => ["type" => "varchar(30)", "not null" => "1", "default" => "image/jpeg"],
+                       "height" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "width" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "datasize" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "data" => ["type" => "mediumblob", "not null" => "1", "comment" => ""],
+                       "scale" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "profile" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
+                       "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
+                       "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
+                       "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "contactid" => ["contact-id"],
+                       "uid_contactid" => ["uid", "contact-id"],
+                       "uid_profile" => ["uid", "profile"],
+                       "uid_album_scale_created" => ["uid", "album(32)", "scale", "created"],
+                       "uid_album_resource-id_created" => ["uid", "album(32)", "resource-id", "created"],
+                       "resource-id" => ["resource-id"],
+               ]
+       ],
+       "poll" => [
+               "comment" => "Currently unused table for storing poll results",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "q0" => ["type" => "text", "comment" => ""],
+                       "q1" => ["type" => "text", "comment" => ""],
+                       "q2" => ["type" => "text", "comment" => ""],
+                       "q3" => ["type" => "text", "comment" => ""],
+                       "q4" => ["type" => "text", "comment" => ""],
+                       "q5" => ["type" => "text", "comment" => ""],
+                       "q6" => ["type" => "text", "comment" => ""],
+                       "q7" => ["type" => "text", "comment" => ""],
+                       "q8" => ["type" => "text", "comment" => ""],
+                       "q9" => ["type" => "text", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uid" => ["uid"],
+               ]
+       ],
+       "poll_result" => [
+               "comment" => "data for polls - currently unused",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "poll_id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["poll" => "id"]],
+                       "choice" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "poll_id" => ["poll_id"],
+               ]
+       ],
+       "process" => [
+               "comment" => "Currently running system processes",
+               "fields" => [
+                       "pid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "comment" => ""],
+                       "command" => ["type" => "varbinary(32)", "not null" => "1", "default" => "", "comment" => ""],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["pid"],
+                       "command" => ["command"],
+               ]
+       ],
+       "profile" => [
+               "comment" => "user profiles data",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
+                       "profile-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name of the profile"],
+                       "is-default" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Mark this profile as default profile"],
+                       "hide-friends" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Hide friend list from viewers of this profile"],
+                       "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "pdesc" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Title or description"],
+                       "dob" => ["type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00", "comment" => "Day of birth"],
+                       "address" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "locality" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "region" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "postal-code" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
+                       "country-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "hometown" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "gender" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
+                       "marital" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "with" => ["type" => "text", "comment" => ""],
+                       "howlong" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "sexual" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "politic" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "religion" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "pub_keywords" => ["type" => "text", "comment" => ""],
+                       "prv_keywords" => ["type" => "text", "comment" => ""],
+                       "likes" => ["type" => "text", "comment" => ""],
+                       "dislikes" => ["type" => "text", "comment" => ""],
+                       "about" => ["type" => "text", "comment" => ""],
+                       "summary" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "music" => ["type" => "text", "comment" => ""],
+                       "book" => ["type" => "text", "comment" => ""],
+                       "tv" => ["type" => "text", "comment" => ""],
+                       "film" => ["type" => "text", "comment" => ""],
+                       "interest" => ["type" => "text", "comment" => ""],
+                       "romance" => ["type" => "text", "comment" => ""],
+                       "work" => ["type" => "text", "comment" => ""],
+                       "education" => ["type" => "text", "comment" => ""],
+                       "contact" => ["type" => "text", "comment" => ""],
+                       "homepage" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "xmpp" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "thumb" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "publish" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "publish default profile in local directory"],
+                       "net-publish" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "publish profile in global directory"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uid_is-default" => ["uid", "is-default"],
+               ]
+       ],
+       "profile_check" => [
+               "comment" => "DFRN remote auth use",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id"],
+                       "dfrn_id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "sec" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+               ]
+       ],
+       "push_subscriber" => [
+               "comment" => "Used for OStatus: Contains feed subscribers",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "callback_url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "topic" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "nickname" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "push" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Retrial counter"],
+                       "last_update" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of last successful trial"],
+                       "next_try" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Next retrial date"],
+                       "renewed" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of last subscription renewal"],
+                       "secret" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "next_try" => ["next_try"],
+               ]
+       ],
+       "queue" => [
+               "comment" => "Queue for messages that couldn't be delivered",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Message receiver"],
+                       "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Receiver's network"],
+                       "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Unique GUID of the message"],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date, when the message was created"],
+                       "last" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of last trial"],
+                       "next" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Next retrial date"],
+                       "retrial" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Retrial counter"],
+                       "content" => ["type" => "mediumtext", "comment" => ""],
+                       "batch" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "last" => ["last"],
+                       "next" => ["next"],
+               ]
+       ],
+       "register" => [
+               "comment" => "registrations requiring admin approval",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "hash" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "password" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "language" => ["type" => "varchar(16)", "not null" => "1", "default" => "", "comment" => ""],
+                       "note" => ["type" => "text", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+               ]
+       ],
+       "search" => [
+               "comment" => "",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "term" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "uid" => ["uid"],
+               ]
+       ],
+       "session" => [
+               "comment" => "web session storage",
+               "fields" => [
+                       "id" => ["type" => "bigint unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "sid" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "data" => ["type" => "text", "comment" => ""],
+                       "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "sid" => ["sid(64)"],
+                       "expire" => ["expire"],
+               ]
+       ],
+       "sign" => [
+               "comment" => "Diaspora signatures",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => "item.id"],
+                       "signed_text" => ["type" => "mediumtext", "comment" => ""],
+                       "signature" => ["type" => "text", "comment" => ""],
+                       "signer" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "iid" => ["UNIQUE", "iid"],
+               ]
+       ],
+       "term" => [
+               "comment" => "item taxonomy (categories, tags, etc.) table",
+               "fields" => [
+                       "tid" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
+                       "oid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => ""],
+                       "otype" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "term" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["tid"],
+                       "oid_otype_type_term" => ["oid", "otype", "type", "term(32)"],
+                       "uid_otype_type_term_global_created" => ["uid", "otype", "type", "term(32)", "global", "created"],
+                       "uid_otype_type_url" => ["uid", "otype", "type", "url(64)"],
+                       "guid" => ["guid(64)"],
+               ]
+       ],
+       "thread" => [
+               "comment" => "Thread related data",
+               "fields" => [
+                       "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["item" => "id"],
+                               "comment" => "sequential ID"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
+                       "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Item owner"],
+                       "author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Item author"],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "edited" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "commented" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "changed" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "wall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "private" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "ignored" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
+                       "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
+                       "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
+                       "bookmark" => ["type" => "boolean", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["iid"],
+                       "uid_network_commented" => ["uid", "network", "commented"],
+                       "uid_network_created" => ["uid", "network", "created"],
+                       "uid_contactid_commented" => ["uid", "contact-id", "commented"],
+                       "uid_contactid_created" => ["uid", "contact-id", "created"],
+                       "contactid" => ["contact-id"],
+                       "ownerid" => ["owner-id"],
+                       "authorid" => ["author-id"],
+                       "uid_created" => ["uid", "created"],
+                       "uid_commented" => ["uid", "commented"],
+                       "uid_wall_created" => ["uid", "wall", "created"],
+                       "private_wall_origin_commented" => ["private", "wall", "origin", "commented"],
+               ]
+       ],
+       "tokens" => [
+               "comment" => "OAuth usage",
+               "fields" => [
+                       "id" => ["type" => "varchar(40)", "not null" => "1", "primary" => "1", "comment" => ""],
+                       "secret" => ["type" => "text", "comment" => ""],
+                       "client_id" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "relation" => ["clients" => "client_id"]],
+                       "expires" => ["type" => "int", "not null" => "1", "default" => "0", "comment" => ""],
+                       "scope" => ["type" => "varchar(200)", "not null" => "1", "default" => "", "comment" => ""],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+               ]
+       ],
+       "user" => [
+               "comment" => "The local users",
+               "fields" => [
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "parent-uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"],
+                               "comment" => "The parent user that has full control about this user"],
+                       "guid" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this user"],
+                       "username" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this user is known by"],
+                       "password" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "encrypted password"],
+                       "legacy_password" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Is the password hash double-hashed?"],
+                       "nickname" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "nick- and user name"],
+                       "email" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "the users email address"],
+                       "openid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                       "timezone" => ["type" => "varchar(128)", "not null" => "1", "default" => "", "comment" => "PHP-legal timezone"],
+                       "language" => ["type" => "varchar(32)", "not null" => "1", "default" => "en", "comment" => "default language"],
+                       "register_date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp of registration"],
+                       "login_date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp of last login"],
+                       "default-location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Default for item.location"],
+                       "allow_location" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 allows to display the location"],
+                       "theme" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "user theme preference"],
+                       "pubkey" => ["type" => "text", "comment" => "RSA public key 4096 bit"],
+                       "prvkey" => ["type" => "text", "comment" => "RSA private key 4096 bit"],
+                       "spubkey" => ["type" => "text", "comment" => ""],
+                       "sprvkey" => ["type" => "text", "comment" => ""],
+                       "verified" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "user is verified through email"],
+                       "blocked" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 for user is blocked"],
+                       "blockwall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Prohibit contacts to post to the profile page of the user"],
+                       "hidewall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Hide profile details from unkown viewers"],
+                       "blocktags" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Prohibit contacts to tag the post of this user"],
+                       "unkmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Permit unknown people to send private mails to this user"],
+                       "cntunkmail" => ["type" => "int unsigned", "not null" => "1", "default" => "10", "comment" => ""],
+                       "notify-flags" => ["type" => "smallint unsigned", "not null" => "1", "default" => "65535", "comment" => "email notification options"],
+                       "page-flags" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "page/profile type"],
+                       "account-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "prvnets" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "pwdreset" => ["type" => "varchar(255)", "comment" => "Password reset request token"],
+                       "pwdreset_time" => ["type" => "datetime", "comment" => "Timestamp of the last password reset request"],
+                       "maxreq" => ["type" => "int unsigned", "not null" => "1", "default" => "10", "comment" => ""],
+                       "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "account_removed" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if 1 the account is removed"],
+                       "account_expired" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "account_expires_on" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp when account expires and will be deleted"],
+                       "expire_notification_sent" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp of last warning of account expiration"],
+                       "def_gid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "allow_cid" => ["type" => "mediumtext", "comment" => "default permission for this user"],
+                       "allow_gid" => ["type" => "mediumtext", "comment" => "default permission for this user"],
+                       "deny_cid" => ["type" => "mediumtext", "comment" => "default permission for this user"],
+                       "deny_gid" => ["type" => "mediumtext", "comment" => "default permission for this user"],
+                       "openidserver" => ["type" => "text", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["uid"],
+                       "nickname" => ["nickname(32)"],
+               ]
+       ],
+       "userd" => [
+               "comment" => "Deleted usernames",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                       "username" => ["type" => "varchar(255)", "not null" => "1", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "username" => ["username(32)"],
+               ]
+       ],
+       "user-contact" => [
+               "comment" => "User specific public contact data",
+               "fields" => [
+                       "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["contact" => "id"], "comment" => "Contact id of the linked public contact"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "blocked" => ["type" => "boolean", "comment" => "Contact is completely blocked for this user"],
+                       "ignored" => ["type" => "boolean", "comment" => "Posts from this contact are ignored"],
+                       "collapsed" => ["type" => "boolean", "comment" => "Posts from this contact are collapsed"]
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["uid", "cid"]
+               ]
+       ],
+       "user-item" => [
+               "comment" => "User specific item data",
+               "fields" => [
+                       "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["item" => "id"], "comment" => "Item id"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["user" => "uid"], "comment" => "User id"],
+                       "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marker to hide an item from the user"],
+                       "ignored" => ["type" => "boolean", "comment" => "Ignore this thread if set"]
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["uid", "iid"]
+               ]
+       ],
+       "worker-ipc" => [
+               "comment" => "Inter process communication between the frontend and the worker",
+               "fields" => [
+                       "key" => ["type" => "int", "not null" => "1", "primary" => "1", "comment" => ""],
+                       "jobs" => ["type" => "boolean", "comment" => "Flag for outstanding jobs"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["key"],
+               ],
+               "engine" => "MEMORY",
+       ],
+       "workerqueue" => [
+               "comment" => "Background tasks queue entries",
+               "fields" => [
+                       "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "Auto incremented worker task id"],
+                       "parameter" => ["type" => "mediumblob", "comment" => "Task command"],
+                       "priority" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Task priority"],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Creation date"],
+                       "pid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "Process id of the worker"],
+                       "executed" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Execution date"],
+                       "next_try" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Next retrial date"],
+                       "retrial" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Retrial counter"],
+                       "done" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marked 1 when the task was done - will be deleted later"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["id"],
+                       "pid" => ["pid"],
+                       "parameter" => ["parameter(64)"],
+                       "priority_created_next_try" => ["priority", "created", "next_try"],
+                       "done_executed_next_try" => ["done", "executed", "next_try"]
+               ]
+       ]
+];
index 353b1fa1f444a25d83ac31f95a09b0aa150ee310..02482c8af8931fc81a112bbd13273d3b6e43c366 100644 (file)
@@ -92,6 +92,10 @@ optimize_max_tablesize = -1
 ; Set to 0 to disable, 2 to enable, 1 is deprecated but wont need mcrypt.
 rino_encrypt = 2
 
+; temppath (String)
+; Custom temporary file directory
+temppath =
+
 ; theme (String)
 ; System theme name.
 theme = vier
index 011bca0737a6f96a2c4f6667c49cdd9d8f9129b9..f7dfcc870c72ca56a877df3503969ec37e743694 100644 (file)
@@ -450,10 +450,6 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep-
     Addon::callHooks('item_photo_menu', $args);
     Addon::callHooks('jot_tool', $jotplugins);
 
-### include/security.php
-
-    Addon::callHooks('logged_in', $a->user);
-
 ### include/text.php
 
     Addon::callHooks('contact_block_end', $arr);
@@ -693,6 +689,11 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep-
     Addon::callHooks($a->module.'_post_'.$selname, $o);
     Addon::callHooks('jot_networks', $jotnets);
 
+### src/Core/Authentication.php
+
+    Addon::callHooks('logged_in', $a->user);
+
+
 ### src/Core/Worker.php
 
     Addon::callHooks("proc_run", $arr);
index 5deaf98ff0608edbb2a85b08716fd276ca6dd1c9..228d2fcf03836cccc35321c17b53257dd9919379 100644 (file)
@@ -149,7 +149,7 @@ As Friendica is using a [Twitter/GNU Social compatible API](help/api) any of the
 Furthermore there are several client projects, especially for use with Friendica.
 If you are interested in improving those clients, please contact the developers of the clients directly.
 
-* Android / LinageOS: **Friendiqa** [src](https://github.com/LubuWest/Friendiqa) developed by [Marco R](https://freunde.ma-nic.de/profile/marco)
+* Android / LinageOS: **Friendiqa** [src](https://git.friendi.ca/lubuwest/Friendiqa)/[Google Play](https://play.google.com/store/apps/details?id=org.qtproject.friendiqa) developed by [Marco R](https://freunde.ma-nic.de/profile/marco)
 * iOS: *currently no client*
 * SailfishOS: **Friendiy** [src](https://kirgroup.com/projects/fabrixxm/harbour-friendly) - developed by [Fabio](https://kirgroup.com/profile/fabrixxm/?tab=profile)
 * Windows: **Friendica Mobile** for Windows versions [before 8.1](http://windowsphone.com/s?appid=e3257730-c9cf-4935-9620-5261e3505c67) and [Windows 10](https://www.microsoft.com/store/apps/9nblggh0fhmn) - developed by [Gerhard Seeber](http://mozartweg.dyndns.org/friendica/profile/gerhard/?tab=profile)
index 07813b6a7715c243f91f06cd4dc19e974e88552d..2715f44462ea2392e7cc20ddde78362df97ac74d 100644 (file)
@@ -1061,7 +1061,7 @@ possibile scale value are:
 * 1: image with or height at <= 640
 * 2: image with or height at <= 320
 * 3: thumbnail 160x160
-* 4: Profile image at 175x175
+* 4: Profile image at 300x300
 * 5: Profile image at 80x80
 * 6: Profile image at 48x48
 
index ce9af37781331528f23a87f464a1fac8fbbc7536..eb825c0729479341aba7545f020fdce0a4a5e0a8 100644 (file)
@@ -226,10 +226,6 @@ Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 01-Ap
     Addon::callHooks('item_photo_menu', $args);
     Addon::callHooks('jot_tool', $jotplugins);
 
-### include/security.php
-
-    Addon::callHooks('logged_in', $a->user);
-
 ### include/text.php
 
     Addon::callHooks('contact_block_end', $arr);
@@ -426,6 +422,10 @@ Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 01-Ap
     Addon::callHooks('page_header', $a->page['nav']);
     Addon::callHooks('nav_info', $nav);
 
+### src/Core/Authentication.php
+
+    Addon::callHooks('logged_in', $a->user);
+
 ### src/Worker/Directory.php
 
     Addon::callHooks('globaldir_update', $arr);
diff --git a/images/person-300.jpg b/images/person-300.jpg
new file mode 100644 (file)
index 0000000..8173082
Binary files /dev/null and b/images/person-300.jpg differ
index ff763e98855c36bb0199fbc86ab7ce67b992a0c0..86f2e3b2a4f3d775a1ba0913668e126ad999fd1a 100644 (file)
@@ -12,6 +12,7 @@ use Friendica\Content\Feature;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
 use Friendica\Core\Addon;
+use Friendica\Core\Authentication;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\NotificationsManager;
@@ -46,7 +47,6 @@ use Friendica\Util\XML;
 require_once 'include/conversation.php';
 require_once 'mod/share.php';
 require_once 'mod/item.php';
-require_once 'include/security.php';
 require_once 'mod/wall_upload.php';
 
 define('API_METHOD_ANY', '*');
@@ -242,7 +242,7 @@ function api_login(App $a)
                throw new UnauthorizedException("This API requires login");
        }
 
-       authenticate_success($record);
+       Authentication::setAuthenticatedSessionForUser($record);
 
        $_SESSION["allow_api"] = true;
 
@@ -1335,9 +1335,9 @@ function api_status_show($type, $item_id = 0)
                }
 
                if ($status_info["source"] == 'web') {
-                       $status_info["source"] = ContactSelector::networkToName($lastwall['network'], $user_info['url']);
-               } elseif (ContactSelector::networkToName($lastwall['network'], $user_info['url']) != $status_info["source"]) {
-                       $status_info["source"] = trim($status_info["source"].' ('.ContactSelector::networkToName($lastwall['network'], $user_info['url']).')');
+                       $status_info["source"] = ContactSelector::networkToName($lastwall['network'], $lastwall['author-link']);
+               } elseif (ContactSelector::networkToName($lastwall['network'], $lastwall['author-link']) != $status_info["source"]) {
+                       $status_info["source"] = trim($status_info["source"].' ('.ContactSelector::networkToName($lastwall['network'], $lastwall['author-link']).')');
                }
 
                // "uid" and "self" are only needed for some internal stuff, so remove it from here
@@ -1410,11 +1410,11 @@ function api_users_show($type)
                }
 
                if ($user_info["status"]["source"] == 'web') {
-                       $user_info["status"]["source"] = ContactSelector::networkToName($lastwall['network'], $user_info['url']);
+                       $user_info["status"]["source"] = ContactSelector::networkToName($lastwall['network'], $lastwall['author-link']);
                }
 
                if (ContactSelector::networkToName($lastwall['network'], $user_info['url']) != $user_info["status"]["source"]) {
-                       $user_info["status"]["source"] = trim($user_info["status"]["source"] . ' (' . ContactSelector::networkToName($lastwall['network'], $user_info['url']) . ')');
+                       $user_info["status"]["source"] = trim($user_info["status"]["source"] . ' (' . ContactSelector::networkToName($lastwall['network'], $lastwall['author-link']) . ')');
                }
        }
 
@@ -2912,9 +2912,9 @@ function api_format_items($r, $user_info, $filter_user = false, $type = "json")
                }
 
                if ($status["source"] == 'web') {
-                       $status["source"] = ContactSelector::networkToName($item['network'], $user_info['url']);
-               } elseif (ContactSelector::networkToName($item['network'], $user_info['url']) != $status["source"]) {
-                       $status["source"] = trim($status["source"].' ('.ContactSelector::networkToName($item['network'], $user_info['url']).')');
+                       $status["source"] = ContactSelector::networkToName($item['network'], $item['author-link']);
+               } elseif (ContactSelector::networkToName($item['network'], $item['author-link']) != $status["source"]) {
+                       $status["source"] = trim($status["source"].' ('.ContactSelector::networkToName($item['network'], $item['author-link']).')');
                }
 
                if ($item["id"] == $item["parent"]) {
@@ -4556,11 +4556,11 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
                // upload profile image (scales 4, 5, 6)
                logger("photo upload: starting new profile image upload", LOGGER_DEBUG);
 
-               if ($width > 175 || $height > 175) {
-                       $Image->scaleDown(175);
+               if ($width > 300 || $height > 300) {
+                       $Image->scaleDown(300);
                        $r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 4, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
                        if (!$r) {
-                               logger("photo upload: profile image upload with scale 4 (175x175) failed");
+                               logger("photo upload: profile image upload with scale 4 (300x300) failed");
                        }
                }
 
@@ -4809,7 +4809,8 @@ function api_friendica_remoteauth()
 
        logger($contact['name'] . ' ' . $sec, LOGGER_DEBUG);
        $dest = ($url ? '&destination_url=' . $url : '');
-       goaway(
+
+       System::externalRedirect(
                $contact['poll'] . '?dfrn_id=' . $dfrn_id
                . '&dfrn_version=' . DFRN_PROTOCOL_VERSION
                . '&type=profile&sec=' . $sec . $dest
index 0362e9a4459f1d9730e13f4148b37cc6fb84660d..4a05c916ba777b6397e0c3e3127a013c65414c04 100644 (file)
@@ -353,7 +353,8 @@ function localize_item(&$item)
        $author = ['uid' => 0, 'id' => $item['author-id'],
                'network' => $item['author-network'], 'url' => $item['author-link']];
 
-       if (!empty($item['plink'])) {
+       // Only create a redirection to a magic link when logged in
+       if (!empty($item['plink']) && (local_user() || remote_user())) {
                $item['plink'] = Contact::magicLinkbyContact($author, $item['plink']);
        }
 }
@@ -533,7 +534,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
        $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
 
        if (!$update) {
-               $_SESSION['return_url'] = $a->query_string;
+               $_SESSION['return_path'] = $a->query_string;
        }
 
        $cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview];
@@ -853,8 +854,8 @@ function item_photo_menu($item) {
 
        if ($cid && !$item['self']) {
                $poke_link = 'poke/?f=&c=' . $cid;
-               $contact_url = 'contacts/' . $cid;
-               $posts_link = 'contacts/' . $cid . '/posts';
+               $contact_url = 'contact/' . $cid;
+               $posts_link = 'contact/' . $cid . '/posts';
 
                if (in_array($network, [Protocol::DFRN, Protocol::DIASPORA])) {
                        $pm_url = 'message/new/' . $cid;
index d8e5614c171034ae4270eb5d38bceaddb765400b..5665f485f457f7754fee59570f82a689abac87d1 100644 (file)
@@ -84,7 +84,7 @@ function notification($params)
        // with $params['show_in_notification_page'] == false, the notification isn't inserted into
        // the database, and an email is sent if applicable.
        // default, if not specified: true
-       $show_in_notification_page = ((x($params, 'show_in_notification_page')) ? $params['show_in_notification_page']:true);
+       $show_in_notification_page = isset($params['show_in_notification_page']) ? $params['show_in_notification_page'] : true;
 
        $additional_mail_header = "";
        $additional_mail_header .= "Precedence: list\n";
@@ -134,6 +134,7 @@ function notification($params)
                $thread = Item::selectFirstThreadForUser($params['uid'] ,['ignored'], ['iid' => $parent_id]);
                if (DBA::isResult($thread) && $thread["ignored"]) {
                        logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG);
+                       L10n::popLang();
                        return;
                }
 
@@ -628,6 +629,7 @@ function notification($params)
                        '$content_allowed'      => $content_allowed,
                ]);
 
+               L10n::popLang();
                // use the Emailer class to send the message
                return Emailer::send(
                        [
@@ -643,6 +645,7 @@ function notification($params)
                );
        }
 
+       L10n::popLang();
        return false;
 }
 
index 27a7db767b4d16c6ee8a8a8a57abc02507524a27..54ae7a82ce88757f6a96949316b4e6266b5ce0aa 100644 (file)
@@ -354,7 +354,7 @@ function drop_item($id)
 
        if (!DBA::isResult($item)) {
                notice(L10n::t('Item not found.') . EOL);
-               goaway('/network');
+               $a->internalRedirect('network');
        }
 
        if ($item['deleted']) {
@@ -401,17 +401,17 @@ function drop_item($id)
                }
                // Now check how the user responded to the confirmation query
                if (!empty($_REQUEST['canceled'])) {
-                       goaway('/display/' . $item['guid']);
+                       $a->internalRedirect('display/' . $item['guid']);
                }
 
                // delete the item
                Item::deleteForUser(['id' => $item['id']], local_user());
 
-               goaway('/network');
+               $a->internalRedirect('network');
                //NOTREACHED
        } else {
                notice(L10n::t('Permission denied.') . EOL);
-               goaway('/display/' . $item['guid']);
+               $a->internalRedirect('display/' . $item['guid']);
                //NOTREACHED
        }
 }
diff --git a/include/security.php b/include/security.php
deleted file mode 100644 (file)
index 2063bdd..0000000
+++ /dev/null
@@ -1,457 +0,0 @@
-<?php
-/**
- * @file include/security.php
- */
-
-use Friendica\Core\Addon;
-use Friendica\Core\Config;
-use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
-use Friendica\Core\System;
-use Friendica\Database\DBA;
-use Friendica\Model\Contact;
-use Friendica\Model\Group;
-use Friendica\Util\DateTimeFormat;
-use Friendica\Model\PermissionSet;
-
-/**
- * @brief Calculate the hash that is needed for the "Friendica" cookie
- *
- * @param array $user Record from "user" table
- *
- * @return string Hashed data
- */
-function cookie_hash($user)
-{
-       return(hash("sha256", Config::get("system", "site_prvkey") .
-                       $user["prvkey"] .
-                       $user["password"]));
-}
-
-/**
- * @brief Set the "Friendica" cookie
- *
- * @param int $time
- * @param array $user Record from "user" table
- */
-function new_cookie($time, $user = [])
-{
-       if ($time != 0) {
-               $time = $time + time();
-       }
-
-       if ($user) {
-               $value = json_encode(["uid" => $user["uid"],
-                       "hash" => cookie_hash($user),
-                       "ip" => defaults($_SERVER, 'REMOTE_ADDR', '0.0.0.0')]);
-       } else {
-               $value = "";
-       }
-
-       setcookie("Friendica", $value, $time, "/", "", (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL), true);
-}
-
-/**
- * @brief Sets the provided user's authenticated session
- *
- * @todo Should be moved to Friendica\Core\Session once it's created
- *
- * @param type $user_record
- * @param type $login_initial
- * @param type $interactive
- * @param type $login_refresh
- */
-function authenticate_success($user_record, $login_initial = false, $interactive = false, $login_refresh = false)
-{
-       $a = get_app();
-
-       $_SESSION['uid'] = $user_record['uid'];
-       $_SESSION['theme'] = $user_record['theme'];
-       $_SESSION['mobile-theme'] = PConfig::get($user_record['uid'], 'system', 'mobile_theme');
-       $_SESSION['authenticated'] = 1;
-       $_SESSION['page_flags'] = $user_record['page-flags'];
-       $_SESSION['my_url'] = System::baseUrl() . '/profile/' . $user_record['nickname'];
-       $_SESSION['my_address'] = $user_record['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
-       $_SESSION['addr'] = defaults($_SERVER, 'REMOTE_ADDR', '0.0.0.0');
-
-       $a->user = $user_record;
-
-       if ($interactive) {
-               if ($a->user['login_date'] <= NULL_DATE) {
-                       $_SESSION['return_url'] = 'profile_photo/new';
-                       $a->module = 'profile_photo';
-                       info(L10n::t("Welcome ") . $a->user['username'] . EOL);
-                       info(L10n::t('Please upload a profile photo.') . EOL);
-               } else {
-                       info(L10n::t("Welcome back ") . $a->user['username'] . EOL);
-               }
-       }
-
-       $member_since = strtotime($a->user['register_date']);
-       if (time() < ($member_since + ( 60 * 60 * 24 * 14))) {
-               $_SESSION['new_member'] = true;
-       } else {
-               $_SESSION['new_member'] = false;
-       }
-       if (strlen($a->user['timezone'])) {
-               date_default_timezone_set($a->user['timezone']);
-               $a->timezone = $a->user['timezone'];
-       }
-
-       $master_record = $a->user;
-
-       if ((x($_SESSION, 'submanage')) && intval($_SESSION['submanage'])) {
-               $user = DBA::selectFirst('user', [], ['uid' => $_SESSION['submanage']]);
-               if (DBA::isResult($user)) {
-                       $master_record = $user;
-               }
-       }
-
-       if ($master_record['parent-uid'] == 0) {
-               // First add our own entry
-               $a->identities = [['uid' => $master_record['uid'],
-                               'username' => $master_record['username'],
-                               'nickname' => $master_record['nickname']]];
-
-               // Then add all the children
-               $r = DBA::select('user', ['uid', 'username', 'nickname'],
-                       ['parent-uid' => $master_record['uid'], 'account_removed' => false]);
-               if (DBA::isResult($r)) {
-                       $a->identities = array_merge($a->identities, DBA::toArray($r));
-               }
-       } else {
-               // Just ensure that the array is always defined
-               $a->identities = [];
-
-               // First entry is our parent
-               $r = DBA::select('user', ['uid', 'username', 'nickname'],
-                       ['uid' => $master_record['parent-uid'], 'account_removed' => false]);
-               if (DBA::isResult($r)) {
-                       $a->identities = DBA::toArray($r);
-               }
-
-               // Then add all siblings
-               $r = DBA::select('user', ['uid', 'username', 'nickname'],
-                       ['parent-uid' => $master_record['parent-uid'], 'account_removed' => false]);
-               if (DBA::isResult($r)) {
-                       $a->identities = array_merge($a->identities, DBA::toArray($r));
-               }
-       }
-
-       $r = DBA::p("SELECT `user`.`uid`, `user`.`username`, `user`.`nickname`
-               FROM `manage`
-               INNER JOIN `user` ON `manage`.`mid` = `user`.`uid`
-               WHERE `user`.`account_removed` = 0 AND `manage`.`uid` = ?",
-               $master_record['uid']
-       );
-       if (DBA::isResult($r)) {
-               $a->identities = array_merge($a->identities, DBA::toArray($r));
-       }
-
-       if ($login_initial) {
-               logger('auth_identities: ' . print_r($a->identities, true), LOGGER_DEBUG);
-       }
-       if ($login_refresh) {
-               logger('auth_identities refresh: ' . print_r($a->identities, true), LOGGER_DEBUG);
-       }
-
-       $contact = DBA::selectFirst('contact', [], ['uid' => $_SESSION['uid'], 'self' => true]);
-       if (DBA::isResult($contact)) {
-               $a->contact = $contact;
-               $a->cid = $contact['id'];
-               $_SESSION['cid'] = $a->cid;
-       }
-
-       header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] . '"');
-
-       if ($login_initial || $login_refresh) {
-               DBA::update('user', ['login_date' => DateTimeFormat::utcNow()], ['uid' => $_SESSION['uid']]);
-
-               // Set the login date for all identities of the user
-               DBA::update('user', ['login_date' => DateTimeFormat::utcNow()],
-                       ['parent-uid' => $master_record['uid'], 'account_removed' => false]);
-       }
-
-       if ($login_initial) {
-               /*
-                * If the user specified to remember the authentication, then set a cookie
-                * that expires after one week (the default is when the browser is closed).
-                * The cookie will be renewed automatically.
-                * The week ensures that sessions will expire after some inactivity.
-                */
-               if (!empty($_SESSION['remember'])) {
-                       logger('Injecting cookie for remembered user ' . $a->user['nickname']);
-                       new_cookie(604800, $user_record);
-                       unset($_SESSION['remember']);
-               }
-       }
-
-       if ($login_initial) {
-               Addon::callHooks('logged_in', $a->user);
-
-               if (($a->module !== 'home') && isset($_SESSION['return_url'])) {
-                       goaway(System::baseUrl() . '/' . $_SESSION['return_url']);
-               }
-       }
-}
-
-function can_write_wall($owner)
-{
-       static $verified = 0;
-
-       if (!local_user() && !remote_user()) {
-               return false;
-       }
-
-       $uid = local_user();
-       if ($uid == $owner) {
-               return true;
-       }
-
-       if (local_user() && ($owner == 0)) {
-               return true;
-       }
-
-       if (remote_user()) {
-               // use remembered decision and avoid a DB lookup for each and every display item
-               // DO NOT use this function if there are going to be multiple owners
-               // We have a contact-id for an authenticated remote user, this block determines if the contact
-               // belongs to this page owner, and has the necessary permissions to post content
-
-               if ($verified === 2) {
-                       return true;
-               } elseif ($verified === 1) {
-                       return false;
-               } else {
-                       $cid = 0;
-
-                       if (!empty($_SESSION['remote'])) {
-                               foreach ($_SESSION['remote'] as $visitor) {
-                                       if ($visitor['uid'] == $owner) {
-                                               $cid = $visitor['cid'];
-                                               break;
-                                       }
-                               }
-                       }
-
-                       if (!$cid) {
-                               return false;
-                       }
-
-                       $r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` INNER JOIN `user` on `user`.`uid` = `contact`.`uid`
-                               WHERE `contact`.`uid` = %d AND `contact`.`id` = %d AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
-                               AND `user`.`blockwall` = 0 AND `readonly` = 0  AND ( `contact`.`rel` IN ( %d , %d ) OR `user`.`page-flags` = %d ) LIMIT 1",
-                               intval($owner),
-                               intval($cid),
-                               intval(Contact::SHARING),
-                               intval(Contact::FRIEND),
-                               intval(Contact::PAGE_COMMUNITY)
-                       );
-
-                       if (DBA::isResult($r)) {
-                               $verified = 2;
-                               return true;
-                       } else {
-                               $verified = 1;
-                       }
-               }
-       }
-
-       return false;
-}
-
-/// @TODO $groups should be array
-function permissions_sql($owner_id, $remote_verified = false, $groups = null)
-{
-       $local_user = local_user();
-       $remote_user = remote_user();
-
-       /**
-        * Construct permissions
-        *
-        * default permissions - anonymous user
-        */
-       $sql = " AND allow_cid = ''
-                        AND allow_gid = ''
-                        AND deny_cid  = ''
-                        AND deny_gid  = ''
-       ";
-
-       /**
-        * Profile owner - everything is visible
-        */
-       if ($local_user && $local_user == $owner_id) {
-               $sql = '';
-       /**
-        * Authenticated visitor. Unless pre-verified,
-        * check that the contact belongs to this $owner_id
-        * and load the groups the visitor belongs to.
-        * If pre-verified, the caller is expected to have already
-        * done this and passed the groups into this function.
-        */
-       } elseif ($remote_user) {
-               /*
-                * Authenticated visitor. Unless pre-verified,
-                * check that the contact belongs to this $owner_id
-                * and load the groups the visitor belongs to.
-                * If pre-verified, the caller is expected to have already
-                * done this and passed the groups into this function.
-                */
-
-               if (!$remote_verified) {
-                       if (DBA::exists('contact', ['id' => $remote_user, 'uid' => $owner_id, 'blocked' => false])) {
-                               $remote_verified = true;
-                               $groups = Group::getIdsByContactId($remote_user);
-                       }
-               }
-
-               if ($remote_verified) {
-                       $gs = '<<>>'; // should be impossible to match
-
-                       if (is_array($groups)) {
-                               foreach ($groups as $g) {
-                                       $gs .= '|<' . intval($g) . '>';
-                               }
-                       }
-
-                       $sql = sprintf(
-                               " AND ( NOT (deny_cid REGEXP '<%d>' OR deny_gid REGEXP '%s')
-                                 AND ( allow_cid REGEXP '<%d>' OR allow_gid REGEXP '%s' OR ( allow_cid = '' AND allow_gid = '') )
-                                 )
-                               ",
-                               intval($remote_user),
-                               DBA::escape($gs),
-                               intval($remote_user),
-                               DBA::escape($gs)
-                       );
-               }
-       }
-       return $sql;
-}
-
-function item_permissions_sql($owner_id, $remote_verified = false, $groups = null)
-{
-       $local_user = local_user();
-       $remote_user = remote_user();
-
-       /*
-        * Construct permissions
-        *
-        * default permissions - anonymous user
-        */
-       $sql = " AND NOT `item`.`private`";
-
-       // Profile owner - everything is visible
-       if ($local_user && ($local_user == $owner_id)) {
-               $sql = '';
-       } elseif ($remote_user) {
-               /*
-                * Authenticated visitor. Unless pre-verified,
-                * check that the contact belongs to this $owner_id
-                * and load the groups the visitor belongs to.
-                * If pre-verified, the caller is expected to have already
-                * done this and passed the groups into this function.
-                */
-               $set = PermissionSet::get($owner_id, $remote_user, $groups);
-
-               if (!empty($set)) {
-                       $sql_set = " OR (`item`.`private` IN (1,2) AND `item`.`wall` AND `item`.`psid` IN (" . implode(',', $set) . "))";
-               } else {
-                       $sql_set = '';
-               }
-
-               $sql = " AND (NOT `item`.`private`" . $sql_set . ")";
-       }
-
-       return $sql;
-}
-
-/*
- * Functions used to protect against Cross-Site Request Forgery
- * The security token has to base on at least one value that an attacker can't know - here it's the session ID and the private key.
- * In this implementation, a security token is reusable (if the user submits a form, goes back and resubmits the form, maybe with small changes;
- * or if the security token is used for ajax-calls that happen several times), but only valid for a certain amout of time (3hours).
- * The "typename" seperates the security tokens of different types of forms. This could be relevant in the following case:
- *    A security token is used to protekt a link from CSRF (e.g. the "delete this profile"-link).
- *    If the new page contains by any chance external elements, then the used security token is exposed by the referrer.
- *    Actually, important actions should not be triggered by Links / GET-Requests at all, but somethimes they still are,
- *    so this mechanism brings in some damage control (the attacker would be able to forge a request to a form of this type, but not to forms of other types).
- */
-function get_form_security_token($typename = '')
-{
-       $a = get_app();
-
-       $timestamp = time();
-       $sec_hash = hash('whirlpool', $a->user['guid'] . $a->user['prvkey'] . session_id() . $timestamp . $typename);
-
-       return $timestamp . '.' . $sec_hash;
-}
-
-function check_form_security_token($typename = '', $formname = 'form_security_token')
-{
-       $hash = null;
-
-       if (!empty($_REQUEST[$formname])) {
-               /// @TODO Careful, not secured!
-               $hash = $_REQUEST[$formname];
-       }
-
-       if (!empty($_SERVER['HTTP_X_CSRF_TOKEN'])) {
-               /// @TODO Careful, not secured!
-               $hash = $_SERVER['HTTP_X_CSRF_TOKEN'];
-       }
-
-       if (empty($hash)) {
-               return false;
-       }
-
-       $max_livetime = 10800; // 3 hours
-
-       $a = get_app();
-
-       $x = explode('.', $hash);
-       if (time() > (IntVal($x[0]) + $max_livetime)) {
-               return false;
-       }
-
-       $sec_hash = hash('whirlpool', $a->user['guid'] . $a->user['prvkey'] . session_id() . $x[0] . $typename);
-
-       return ($sec_hash == $x[1]);
-}
-
-function check_form_security_std_err_msg()
-{
-       return L10n::t("The form security token was not correct. This probably happened because the form has been opened for too long \x28>3 hours\x29 before submitting it.") . EOL;
-}
-
-function check_form_security_token_redirectOnErr($err_redirect, $typename = '', $formname = 'form_security_token')
-{
-       if (!check_form_security_token($typename, $formname)) {
-               $a = get_app();
-               logger('check_form_security_token failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
-               logger('check_form_security_token failed: _REQUEST data: ' . print_r($_REQUEST, true), LOGGER_DATA);
-               notice(check_form_security_std_err_msg());
-               goaway(System::baseUrl() . $err_redirect);
-       }
-}
-
-function check_form_security_token_ForbiddenOnErr($typename = '', $formname = 'form_security_token')
-{
-       if (!check_form_security_token($typename, $formname)) {
-               $a = get_app();
-               logger('check_form_security_token failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
-               logger('check_form_security_token failed: _REQUEST data: ' . print_r($_REQUEST, true), LOGGER_DATA);
-               header('HTTP/1.1 403 Forbidden');
-               killme();
-       }
-}
-
-/**
- * @brief Kills the "Friendica" cookie and all session data
- */
-function nuke_session()
-{
-       new_cookie(-3600); // make sure cookie is deleted on browser close, as a security measure
-       session_unset();
-       session_destroy();
-}
index 6ab405c632a3f092db5914db9f146f6f457b7ab1..43bfd3800e684429dcf82196d3b5f76d9cf96220 100644 (file)
--- a/index.php
+++ b/index.php
  * Friendica
  */
 
-/**
- * Bootstrap the application
- */
-
 use Friendica\App;
-use Friendica\Content\Nav;
-use Friendica\Core\Addon;
-use Friendica\Core\Config;
-use Friendica\Core\L10n;
-use Friendica\Core\Session;
-use Friendica\Core\System;
-use Friendica\Core\Theme;
-use Friendica\Core\Worker;
-use Friendica\Database\DBA;
-use Friendica\Model\Profile;
-use Friendica\Module\Login;
 
 require_once 'boot.php';
 
 // We assume that the index.php is called by a frontend process
-// The value is set to "true" by default in boot.php
+// The value is set to "true" by default in App
 $a = new App(__DIR__, false);
 
-/**
- * Try to open the database;
- */
-
-require_once "include/dba.php";
-
-// Missing DB connection: ERROR
-if ($a->getMode()->has(App\Mode::LOCALCONFIGPRESENT) && !$a->getMode()->has(App\Mode::DBAVAILABLE)) {
-       System::httpExit(500, ['title' => 'Error 500 - Internal Server Error', 'description' => 'Apologies but the website is unavailable at the moment.']);
-}
-
-// Max Load Average reached: ERROR
-if ($a->isMaxProcessesReached() || $a->isMaxLoadReached()) {
-       header('Retry-After: 120');
-       header('Refresh: 120; url=' . System::baseUrl() . "/" . $a->query_string);
-
-       System::httpExit(503, ['title' => 'Error 503 - Service Temporarily Unavailable', 'description' => 'System is currently overloaded. Please try again later.']);
-}
-
-if (strstr($a->query_string, '.well-known/host-meta') && ($a->query_string != '.well-known/host-meta')) {
-       System::httpExit(404);
-}
-
-if (!$a->getMode()->isInstall()) {
-       if (Config::get('system', 'force_ssl') && ($a->getScheme() == "http")
-               && (intval(Config::get('system', 'ssl_policy')) == SSL_POLICY_FULL)
-               && (substr(System::baseUrl(), 0, 8) == "https://")
-               && ($_SERVER['REQUEST_METHOD'] == 'GET')) {
-               header("HTTP/1.1 302 Moved Temporarily");
-               header("Location: " . System::baseUrl() . "/" . $a->query_string);
-               exit();
-       }
-
-       Config::init();
-       Session::init();
-       Addon::loadHooks();
-       Addon::callHooks('init_1');
-}
-
-$lang = L10n::getBrowserLanguage();
-
-L10n::loadTranslationTable($lang);
-
-/**
- * Important stuff we always need to do.
- *
- * The order of these may be important so use caution if you think they're all
- * intertwingled with no logical order and decide to sort it out. Some of the
- * dependencies have changed, but at least at one time in the recent past - the
- * order was critical to everything working properly
- */
-
-// Exclude the backend processes from the session management
-if (!$a->isBackend()) {
-       $stamp1 = microtime(true);
-       session_start();
-       $a->saveTimestamp($stamp1, "parser");
-} else {
-       $_SESSION = [];
-       Worker::executeIfIdle();
-}
-
-/**
- * Language was set earlier, but we can over-ride it in the session.
- * We have to do it here because the session was just now opened.
- */
-if (!empty($_SESSION['authenticated']) && empty($_SESSION['language'])) {
-       $_SESSION['language'] = $lang;
-       // we haven't loaded user data yet, but we need user language
-       if (!empty($_SESSION['uid'])) {
-               $user = DBA::selectFirst('user', ['language'], ['uid' => $_SESSION['uid']]);
-               if (DBA::isResult($user)) {
-                       $_SESSION['language'] = $user['language'];
-               }
-       }
-}
-
-if (!empty($_SESSION['language']) && $_SESSION['language'] !== $lang) {
-       $lang = $_SESSION['language'];
-       L10n::loadTranslationTable($lang);
-}
-
-if (!empty($_GET['zrl']) && $a->getMode()->isNormal()) {
-       $a->query_string = Profile::stripZrls($a->query_string);
-       if (!local_user()) {
-               // Only continue when the given profile link seems valid
-               // Valid profile links contain a path with "/profile/" and no query parameters
-               if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "") &&
-                       strstr(parse_url($_GET['zrl'], PHP_URL_PATH), "/profile/")) {
-                       if (defaults($_SESSION, "visitor_home", "") != $_GET["zrl"]) {
-                               $_SESSION['my_url'] = $_GET['zrl'];
-                               $_SESSION['authenticated'] = 0;
-                       }
-                       Profile::zrlInit($a);
-               } else {
-                       // Someone came with an invalid parameter, maybe as a DDoS attempt
-                       // We simply stop processing here
-                       logger("Invalid ZRL parameter " . $_GET['zrl'], LOGGER_DEBUG);
-                       header('HTTP/1.1 403 Forbidden');
-                       echo "<h1>403 Forbidden</h1>";
-                       exit();
-               }
-       }
-}
-
-if (!empty($_GET['owt']) && $a->getMode()->isNormal()) {
-       $token = $_GET['owt'];
-       $a->query_string = Profile::stripQueryParam($a->query_string, 'owt');
-       Profile::openWebAuthInit($token);
-}
-
-/**
- * For Mozilla auth manager - still needs sorting, and this might conflict with LRDD header.
- * Apache/PHP lumps the Link: headers into one - and other services might not be able to parse it
- * this way. There's a PHP flag to link the headers because by default this will over-write any other
- * link header.
- *
- * What we really need to do is output the raw headers ourselves so we can keep them separate.
- */
-
-// header('Link: <' . System::baseUrl() . '/amcd>; rel="acct-mgmt";');
-
-Login::sessionAuth();
-
-if (empty($_SESSION['authenticated'])) {
-       header('X-Account-Management-Status: none');
-}
-
-$_SESSION['sysmsg']       = defaults($_SESSION, 'sysmsg'      , []);
-$_SESSION['sysmsg_info']  = defaults($_SESSION, 'sysmsg_info' , []);
-$_SESSION['last_updated'] = defaults($_SESSION, 'last_updated', []);
-
-/*
- * check_config() is responsible for running update scripts. These automatically
- * update the DB schema whenever we push a new one out. It also checks to see if
- * any addons have been added or removed and reacts accordingly.
- */
-
-// in install mode, any url loads install module
-// but we need "view" module for stylesheet
-if ($a->getMode()->isInstall() && $a->module != 'view') {
-       $a->module = 'install';
-} elseif (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED) && $a->module != 'view') {
-       $a->module = 'maintenance';
-} else {
-       check_url($a);
-       check_db(false);
-       Addon::check();
-}
-
-Nav::setSelected('nothing');
-
-//Don't populate apps_menu if apps are private
-$privateapps = Config::get('config', 'private_addons');
-if ((local_user()) || (! $privateapps === "1")) {
-       $arr = ['app_menu' => $a->apps];
-
-       Addon::callHooks('app_menu', $arr);
-
-       $a->apps = $arr['app_menu'];
-}
-
-/**
- * We have already parsed the server path into $a->argc and $a->argv
- *
- * $a->argv[0] is our module name. We will load the file mod/{$a->argv[0]}.php
- * and use it for handling our URL request.
- * The module file contains a few functions that we call in various circumstances
- * and in the following order:
- *
- * "module"_init
- * "module"_post (only called if there are $_POST variables)
- * "module"_afterpost
- * "module"_content - the string return of this function contains our page body
- *
- * Modules which emit other serialisations besides HTML (XML,JSON, etc.) should do
- * so within the module init and/or post functions and then invoke killme() to terminate
- * further processing.
- */
-if (strlen($a->module)) {
-
-       /**
-        * We will always have a module name.
-        * First see if we have an addon which is masquerading as a module.
-        */
-
-       // Compatibility with the Android Diaspora client
-       if ($a->module == 'stream') {
-               goaway('network?f=&order=post');
-       }
-
-       if ($a->module == 'conversations') {
-               goaway('message');
-       }
-
-       if ($a->module == 'commented') {
-               goaway('network?f=&order=comment');
-       }
-
-       if ($a->module == 'liked') {
-               goaway('network?f=&order=comment');
-       }
-
-       if ($a->module == 'activity') {
-               goaway('network/?f=&conv=1');
-       }
-
-       if (($a->module == 'status_messages') && ($a->cmd == 'status_messages/new')) {
-               goaway('bookmarklet');
-       }
-
-       if (($a->module == 'user') && ($a->cmd == 'user/edit')) {
-               goaway('settings');
-       }
-
-       if (($a->module == 'tag_followings') && ($a->cmd == 'tag_followings/manage')) {
-               goaway('search');
-       }
-
-       // Compatibility with the Firefox App
-       if (($a->module == "users") && ($a->cmd == "users/sign_in")) {
-               $a->module = "login";
-       }
-
-       $privateapps = Config::get('config', 'private_addons');
-
-       if (is_array($a->addons) && in_array($a->module, $a->addons) && file_exists("addon/{$a->module}/{$a->module}.php")) {
-               //Check if module is an app and if public access to apps is allowed or not
-               if ((!local_user()) && Addon::isApp($a->module) && $privateapps === "1") {
-                       info(L10n::t("You must be logged in to use addons. "));
-               } else {
-                       include_once "addon/{$a->module}/{$a->module}.php";
-                       if (function_exists($a->module . '_module')) {
-                               $a->module_loaded = true;
-                       }
-               }
-       }
-
-       // Controller class routing
-       if (! $a->module_loaded && class_exists('Friendica\\Module\\' . ucfirst($a->module))) {
-               $a->module_class = 'Friendica\\Module\\' . ucfirst($a->module);
-               $a->module_loaded = true;
-       }
-
-       /**
-        * If not, next look for a 'standard' program module in the 'mod' directory
-        */
-
-       if (! $a->module_loaded && file_exists("mod/{$a->module}.php")) {
-               include_once "mod/{$a->module}.php";
-               $a->module_loaded = true;
-       }
-
-       /**
-        * The URL provided does not resolve to a valid module.
-        *
-        * On Dreamhost sites, quite often things go wrong for no apparent reason and they send us to '/internal_error.html'.
-        * We don't like doing this, but as it occasionally accounts for 10-20% or more of all site traffic -
-        * we are going to trap this and redirect back to the requested page. As long as you don't have a critical error on your page
-        * this will often succeed and eventually do the right thing.
-        *
-        * Otherwise we are going to emit a 404 not found.
-        */
-
-       if (! $a->module_loaded) {
-               // Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit.
-               if (!empty($_SERVER['QUERY_STRING']) && preg_match('/{[0-9]}/', $_SERVER['QUERY_STRING']) !== 0) {
-                       killme();
-               }
-
-               if (!empty($_SERVER['QUERY_STRING']) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
-                       logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI']);
-                       goaway(System::baseUrl() . $_SERVER['REQUEST_URI']);
-               }
-
-               logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG);
-               header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . L10n::t('Not Found'));
-               $tpl = get_markup_template("404.tpl");
-               $a->page['content'] = replace_macros($tpl, [
-                       '$message' =>  L10n::t('Page not found.')
-               ]);
-       }
-}
-
-/**
- * Load current theme info
- */
-$theme_info_file = 'view/theme/' . $a->getCurrentTheme() . '/theme.php';
-if (file_exists($theme_info_file)) {
-       require_once $theme_info_file;
-}
-
-
-/* initialise content region */
-
-if ($a->getMode()->isNormal()) {
-       Addon::callHooks('page_content_top', $a->page['content']);
-}
-
-/**
- * Call module functions
- */
-
-if ($a->module_loaded) {
-       $a->page['page_title'] = $a->module;
-       $placeholder = '';
-
-       Addon::callHooks($a->module . '_mod_init', $placeholder);
-
-       if ($a->module_class) {
-               call_user_func([$a->module_class, 'init']);
-       } else if (function_exists($a->module . '_init')) {
-               $func = $a->module . '_init';
-               $func($a);
-       }
-
-       // "rawContent" is especially meant for technical endpoints.
-       // This endpoint doesn't need any theme initialization or other comparable stuff.
-       if (!$a->error && $a->module_class) {
-               call_user_func([$a->module_class, 'rawContent']);
-       }
-
-       if (function_exists(str_replace('-', '_', $a->getCurrentTheme()) . '_init')) {
-               $func = str_replace('-', '_', $a->getCurrentTheme()) . '_init';
-               $func($a);
-       }
-
-       if (! $a->error && $_SERVER['REQUEST_METHOD'] === 'POST') {
-               Addon::callHooks($a->module . '_mod_post', $_POST);
-               if ($a->module_class) {
-                       call_user_func([$a->module_class, 'post']);
-               } else if (function_exists($a->module . '_post')) {
-                       $func = $a->module . '_post';
-                       $func($a);
-               }
-       }
-
-       if (! $a->error) {
-               Addon::callHooks($a->module . '_mod_afterpost', $placeholder);
-               if ($a->module_class) {
-                       call_user_func([$a->module_class, 'afterpost']);
-               } else if (function_exists($a->module . '_afterpost')) {
-                       $func = $a->module . '_afterpost';
-                       $func($a);
-               }
-       }
-
-       if (! $a->error) {
-               $arr = ['content' => $a->page['content']];
-               Addon::callHooks($a->module . '_mod_content', $arr);
-               $a->page['content'] = $arr['content'];
-               if ($a->module_class) {
-                       $arr = ['content' => call_user_func([$a->module_class, 'content'])];
-               } else if (function_exists($a->module . '_content')) {
-                       $func = $a->module . '_content';
-                       $arr = ['content' => $func($a)];
-               }
-               Addon::callHooks($a->module . '_mod_aftercontent', $arr);
-               $a->page['content'] .= $arr['content'];
-       }
-
-       if (function_exists(str_replace('-', '_', $a->getCurrentTheme()) . '_content_loaded')) {
-               $func = str_replace('-', '_', $a->getCurrentTheme()) . '_content_loaded';
-               $func($a);
-       }
-}
-
-/*
- * Create the page head after setting the language
- * and getting any auth credentials.
- *
- * Moved init_pagehead() and init_page_end() to after
- * all the module functions have executed so that all
- * theme choices made by the modules can take effect.
- */
-
-$a->initHead();
-
-/*
- * Build the page ending -- this is stuff that goes right before
- * the closing </body> tag
- */
-$a->initFooter();
-
-/*
- * now that we've been through the module content, see if the page reported
- * a permission problem and if so, a 403 response would seem to be in order.
- */
-if (stristr(implode("", $_SESSION['sysmsg']), L10n::t('Permission denied'))) {
-       header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . L10n::t('Permission denied.'));
-}
-
-/*
- * Report anything which needs to be communicated in the notification area (before the main body)
- */
-Addon::callHooks('page_end', $a->page['content']);
-
-/*
- * Add the navigation (menu) template
- */
-if ($a->module != 'install' && $a->module != 'maintenance') {
-       Nav::build($a);
-}
-
-/**
- * Build the page - now that we have all the components
- */
-if (isset($_GET["mode"]) && (($_GET["mode"] == "raw") || ($_GET["mode"] == "minimal"))) {
-       $doc = new DOMDocument();
-
-       $target = new DOMDocument();
-       $target->loadXML("<root></root>");
-
-       $content = mb_convert_encoding($a->page["content"], 'HTML-ENTITIES', "UTF-8");
-
-       /// @TODO one day, kill those error-surpressing @ stuff, or PHP should ban it
-       @$doc->loadHTML($content);
-
-       $xpath = new DOMXPath($doc);
-
-       $list = $xpath->query("//*[contains(@id,'tread-wrapper-')]");  /* */
-
-       foreach ($list as $item) {
-               $item = $target->importNode($item, true);
-
-               // And then append it to the target
-               $target->documentElement->appendChild($item);
-       }
-}
-
-if (isset($_GET["mode"]) && ($_GET["mode"] == "raw")) {
-       header("Content-type: text/html; charset=utf-8");
-
-       echo substr($target->saveHTML(), 6, -8);
-
-       exit();
-}
-
-$page    = $a->page;
-$profile = $a->profile;
-
-header("X-Friendica-Version: " . FRIENDICA_VERSION);
-header("Content-type: text/html; charset=utf-8");
-
-if (Config::get('system', 'hsts') && (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL)) {
-       header("Strict-Transport-Security: max-age=31536000");
-}
-
-// Some security stuff
-header('X-Content-Type-Options: nosniff');
-header('X-XSS-Protection: 1; mode=block');
-header('X-Permitted-Cross-Domain-Policies: none');
-header('X-Frame-Options: sameorigin');
-
-// Things like embedded OSM maps don't work, when this is enabled
-// header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; connect-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'; img-src 'self' https: data:; media-src 'self' https:; child-src 'self' https:; object-src 'none'");
-
-/*
- * We use $_GET["mode"] for special page templates. So we will check if we have
- * to load another page template than the default one.
- * The page templates are located in /view/php/ or in the theme directory.
- */
-if (isset($_GET["mode"])) {
-       $template = Theme::getPathForFile($_GET["mode"] . '.php');
-}
-
-// If there is no page template use the default page template
-if (empty($template)) {
-       $template = Theme::getPathForFile("default.php");
-}
-
-/// @TODO Looks unsafe (remote-inclusion), is maybe not but Theme::getPathForFile() uses file_exists() but does not escape anything
-require_once $template;
+$a->runFrontend();
index b02db73bdd9bdf76468881ae6164c3fc8b185279..c50927e97cfd397ef16ae43b0da7575b14a49f8b 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 use Friendica\App;
+use Friendica\BaseModule;
 use Friendica\Content\Feature;
 use Friendica\Content\Text\Markdown;
 use Friendica\Core\Addon;
@@ -18,13 +19,14 @@ use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
+use Friendica\Model\Register;
 use Friendica\Model\User;
 use Friendica\Module\Login;
 use Friendica\Module\Tos;
 use Friendica\Util\Arrays;
 use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Temporal;
 use Friendica\Util\Network;
+use Friendica\Util\Temporal;
 
 require_once 'include/enotify.php';
 require_once 'include/text.php';
@@ -33,11 +35,11 @@ require_once 'include/items.php';
 /**
  * @brief Process send data from the admin panels subpages
  *
- * This function acts as relais for processing the data send from the subpages
+ * This function acts as relay for processing the data send from the subpages
  * of the admin panel. Depending on the 1st parameter of the url (argv[1])
  * specialized functions are called to process the data from the subpages.
  *
- * The function itself does not return anything, but the subsequencely function
+ * The function itself does not return anything, but the subsequently function
  * return the HTML for the pages of the admin panel.
  *
  * @param App $a
@@ -80,7 +82,7 @@ function admin_post(App $a)
                                        if ($a->isAjax()) {
                                                return;
                                        }
-                                       goaway('admin/');
+                                       $a->internalRedirect('admin/');
                                        return;
                                }
 
@@ -133,7 +135,7 @@ function admin_post(App $a)
                }
        }
 
-       goaway($return_path);
+       $a->internalRedirect($return_path);
        return; // NOTREACHED
 }
 
@@ -179,32 +181,33 @@ function admin_content(App $a)
        // array(url, name, extra css classes)
        // not part of $aside to make the template more adjustable
        $aside_sub = [
-               'information' => [ L10n::t('Information'), [
-                       "overview" => ["admin/", L10n::t("Overview"), "overview" ],
-                       'federation'   => ["admin/federation/"  , L10n::t('Federation Statistics'), "federation"] ]],
-               'configuration' => [ L10n::t('Configuration'), [
-                       'site'         => ["admin/site/"        , L10n::t("Site")                 , "site"],
-                       'users'        => ["admin/users/"       , L10n::t("Users")                , "users"],
-                       'addons'       => ["admin/addons/"      , L10n::t("Addons")               , "addons"],
-                       'themes'       => ["admin/themes/"      , L10n::t("Themes")               , "themes"],
-                       'features'     => ["admin/features/"    , L10n::t("Additional features")  , "features"],
-                       'tos'          => ["admin/tos/"         , L10n::t("Terms of Service")     , "tos"] ]],
-               'database' => [ L10n::t('Database'), [
-                       'dbsync'       => ["admin/dbsync/"      , L10n::t('DB updates')           , "dbsync"],
-                       'queue'        => ["admin/queue/"       , L10n::t('Inspect Queue')        , "queue"],
-                       'workerqueue'  => ["admin/workerqueue/" , L10n::t('Inspect worker Queue') , "workerqueue"] ]],
-               'tools' => [ L10n::t('Tools'), [
-                       'contactblock' => ["admin/contactblock/", L10n::t('Contact Blocklist')    , "contactblock"],
-                       'blocklist'    => ["admin/blocklist/"   , L10n::t('Server Blocklist')     , "blocklist"],
-                       'deleteitem'   => ["admin/deleteitem/"  , L10n::t('Delete Item')          , 'deleteitem'], ]],
-               "logs" => [ L10n::t("Logs"), [
-                       "logsconfig" => ["admin/logs/", L10n::t("Logs"), "logs"],
-                       "logsview" => ["admin/viewlogs/", L10n::t("View Logs"), 'viewlogs']
+               'information' => [L10n::t('Information'), [
+                       'overview' => ['admin/', L10n::t('Overview'), 'overview'],
+                       'federation'   => ['admin/federation/'  , L10n::t('Federation Statistics'), 'federation']]],
+               'configuration' => [L10n::t('Configuration'), [
+                       'site'         => ['admin/site/'        , L10n::t('Site')                    , 'site'],
+                       'users'        => ['admin/users/'       , L10n::t('Users')                   , 'users'],
+                       'addons'       => ['admin/addons/'      , L10n::t('Addons')                  , 'addons'],
+                       'themes'       => ['admin/themes/'      , L10n::t('Themes')                  , 'themes'],
+                       'features'     => ['admin/features/'    , L10n::t('Additional features')     , 'features'],
+                       'tos'          => ['admin/tos/'         , L10n::t('Terms of Service')        , 'tos']]],
+               'database' => [L10n::t('Database'), [
+                       'dbsync'       => ['admin/dbsync/'      , L10n::t('DB updates')              , 'dbsync'],
+                       'queue'        => ['admin/queue/'       , L10n::t('Inspect Queue')           , 'queue'],
+                       'deferred'     => ['admin/deferred/'    , L10n::t('Inspect Deferred Workers'), 'deferred'],
+                       'workerqueue'  => ['admin/workerqueue/' , L10n::t('Inspect worker Queue')    , 'workerqueue']]],
+               'tools' => [L10n::t('Tools'), [
+                       'contactblock' => ['admin/contactblock/', L10n::t('Contact Blocklist')       , 'contactblock'],
+                       'blocklist'    => ['admin/blocklist/'   , L10n::t('Server Blocklist')        , 'blocklist'],
+                       'deleteitem'   => ['admin/deleteitem/'  , L10n::t('Delete Item')             , 'deleteitem'],]],
+               'logs' => [L10n::t('Logs'), [
+                       'logsconfig' => ['admin/logs/', L10n::t('Logs'), 'logs'],
+                       'logsview' => ['admin/viewlogs/', L10n::t('View Logs'), 'viewlogs']
                ]],
-               "diagnostics" => [ L10n::t("Diagnostics"), [
-                       "phpinfo" => ['phpinfo/', L10n::t('PHP Info'), 'phpinfo'],
-                       "probe" => ['probe/', L10n::t('probe address'), 'probe'],
-                       "webfinger" =>['webfinger/', L10n::t('check webfinger'), 'webfinger']
+               'diagnostics' => [L10n::t('Diagnostics'), [
+                       'phpinfo' => ['phpinfo/', L10n::t('PHP Info'), 'phpinfo'],
+                       'probe' => ['probe/', L10n::t('probe address'), 'probe'],
+                       'webfinger' =>['webfinger/', L10n::t('check webfinger'), 'webfinger']
                ]]
        ];
 
@@ -212,11 +215,12 @@ function admin_content(App $a)
 
        $r = q("SELECT `name` FROM `addon` WHERE `plugin_admin` = 1 ORDER BY `name`");
        $aside_tools['addons_admin'] = [];
+       $addons_admin = [];
        foreach ($r as $h) {
                $addon = $h['name'];
                $aside_tools['addons_admin'][] = ["admin/addons/" . $addon, $addon, "addon"];
                // temp addons with admin
-               $a->addons_admin[] = $addon;
+               $addons_admin[] = $addon;
        }
 
        $t = get_markup_template('admin/aside.tpl');
@@ -241,7 +245,7 @@ function admin_content(App $a)
                                $o = admin_page_users($a);
                                break;
                        case 'addons':
-                               $o = admin_page_addons($a);
+                               $o = admin_page_addons($a, $addons_admin);
                                break;
                        case 'themes':
                                $o = admin_page_themes($a);
@@ -261,8 +265,11 @@ function admin_content(App $a)
                        case 'queue':
                                $o = admin_page_queue($a);
                                break;
+                       case 'deferred':
+                               $o = admin_page_workerqueue($a, true);
+                               break;
                        case 'workerqueue':
-                               $o = admin_page_workerqueue($a);
+                               $o = admin_page_workerqueue($a, false);
                                break;
                        case 'federation':
                                $o = admin_page_federation($a);
@@ -313,7 +320,7 @@ function admin_page_tos(App $a)
                '$preview' => L10n::t('Privacy Statement Preview'),
                '$privtext' => $tos->privacy_complete,
                '$tostext' => ['tostext', L10n::t('The Terms of Service'), Config::get('system', 'tostext'), L10n::t('Enter the Terms of Service for your node here. You can use BBCode. Headers of sections should be [h2] and below.')],
-               '$form_security_token' => get_form_security_token("admin_tos"),
+               '$form_security_token' => BaseModule::getFormSecurityToken("admin_tos"),
                '$submit' => L10n::t('Save Settings'),
        ]);
 }
@@ -324,7 +331,7 @@ function admin_page_tos(App $a)
  */
 function admin_page_tos_post(App $a)
 {
-       check_form_security_token_redirectOnErr('/admin/tos', 'admin_tos');
+       BaseModule::checkFormSecurityTokenRedirectOnError('/admin/tos', 'admin_tos');
 
        if (!x($_POST, "page_tos")) {
                return;
@@ -338,7 +345,7 @@ function admin_page_tos_post(App $a)
        Config::set('system', 'tosprivstatement', $displayprivstatement);
        Config::set('system', 'tostext', $tostext);
 
-       goaway('admin/tos');
+       $a->internalRedirect('admin/tos');
 
        return; // NOTREACHED
 }
@@ -384,7 +391,7 @@ function admin_page_blocklist(App $a)
                '$entries' => $blocklistform,
                '$baseurl' => System::baseUrl(true),
                '$confirm_delete' => L10n::t('Delete entry from blocklist?'),
-               '$form_security_token' => get_form_security_token("admin_blocklist")
+               '$form_security_token' => BaseModule::getFormSecurityToken("admin_blocklist")
        ]);
 }
 
@@ -399,7 +406,7 @@ function admin_page_blocklist_post(App $a)
                return;
        }
 
-       check_form_security_token_redirectOnErr('/admin/blocklist', 'admin_blocklist');
+       BaseModule::checkFormSecurityTokenRedirectOnError('/admin/blocklist', 'admin_blocklist');
 
        if (x($_POST['page_blocklist_save'])) {
                //  Add new item to blocklist
@@ -427,7 +434,7 @@ function admin_page_blocklist_post(App $a)
                Config::set('system', 'blocklist', $blocklist);
                info(L10n::t('Site blocklist updated.') . EOL);
        }
-       goaway('admin/blocklist');
+       $a->internalRedirect('admin/blocklist');
 
        return; // NOTREACHED
 }
@@ -442,7 +449,7 @@ function admin_page_contactblock_post(App $a)
        $contact_url = x($_POST, 'contact_url') ? $_POST['contact_url'] : '';
        $contacts    = x($_POST, 'contacts')    ? $_POST['contacts']    : [];
 
-       check_form_security_token_redirectOnErr('/admin/contactblock', 'admin_contactblock');
+       BaseModule::checkFormSecurityTokenRedirectOnError('/admin/contactblock', 'admin_contactblock');
 
        if (x($_POST, 'page_contactblock_block')) {
                $contact_id = Contact::getIdForURL($contact_url);
@@ -459,7 +466,7 @@ function admin_page_contactblock_post(App $a)
                }
                notice(L10n::tt("%s contact unblocked", "%s contacts unblocked", count($contacts)));
        }
-       goaway('admin/contactblock');
+       $a->internalRedirect('admin/contactblock');
        return; // NOTREACHED
 }
 
@@ -499,7 +506,7 @@ function admin_page_contactblock(App $a)
                '$h_newblock'  => L10n::t('Block New Remote Contact'),
                '$th_contacts' => [L10n::t('Photo'), L10n::t('Name'), L10n::t('Address'), L10n::t('Profile URL')],
 
-               '$form_security_token' => get_form_security_token("admin_contactblock"),
+               '$form_security_token' => BaseModule::getFormSecurityToken("admin_contactblock"),
 
                // values //
                '$baseurl'    => System::baseUrl(true),
@@ -534,7 +541,7 @@ function admin_page_deleteitem(App $a)
                '$intro2' => L10n::t('You need to know the GUID of the item. You can find it e.g. by looking at the display URL. The last part of http://example.com/display/123456 is the GUID, here 123456.'),
                '$deleteitemguid' => ['deleteitemguid', L10n::t("GUID"), '', L10n::t("The GUID of the item you want to delete."), 'required', 'autofocus'],
                '$baseurl' => System::baseUrl(),
-               '$form_security_token' => get_form_security_token("admin_deleteitem")
+               '$form_security_token' => BaseModule::getFormSecurityToken("admin_deleteitem")
        ]);
 }
 
@@ -552,7 +559,7 @@ function admin_page_deleteitem_post(App $a)
                return;
        }
 
-       check_form_security_token_redirectOnErr('/admin/deleteitem/', 'admin_deleteitem');
+       BaseModule::checkFormSecurityTokenRedirectOnError('/admin/deleteitem/', 'admin_deleteitem');
 
        if (x($_POST['page_deleteitem_submit'])) {
                $guid = trim(notags($_POST['deleteitemguid']));
@@ -567,7 +574,7 @@ function admin_page_deleteitem_post(App $a)
        }
 
        info(L10n::t('Item marked for deletion.') . EOL);
-       goaway('admin/deleteitem');
+       $a->internalRedirect('admin/deleteitem');
        return; // NOTREACHED
 }
 
@@ -787,10 +794,20 @@ function admin_page_queue(App $a)
  * @param App $a
  * @return string
  */
-function admin_page_workerqueue(App $a)
+function admin_page_workerqueue(App $a, $deferred)
 {
        // get jobs from the workerqueue table
-       $entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], ['done' => 0], ['order'=> ['priority']]);
+       if ($deferred) {
+               $condition = ["NOT `done` AND `next_try` > ?", DateTimeFormat::utcNow()];
+               $sub_title = L10n::t('Inspect Deferred Worker Queue');
+               $info = L10n::t("This page lists the deferred worker jobs. This are jobs that couldn't be executed at the first time.");
+       } else {
+               $condition = ["NOT `done` AND `next_try` < ?", DateTimeFormat::utcNow()];
+               $sub_title = L10n::t('Inspect Worker Queue');
+               $info = L10n::t('This page lists the currently queued worker jobs. These jobs are handled by the worker cronjob you\'ve set up during install.');
+       }
+
+       $entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], $condition, ['order'=> ['priority']]);
 
        $r = [];
        while ($entry = DBA::fetch($entries)) {
@@ -804,13 +821,13 @@ function admin_page_workerqueue(App $a)
        $t = get_markup_template('admin/workerqueue.tpl');
        return replace_macros($t, [
                '$title' => L10n::t('Administration'),
-               '$page' => L10n::t('Inspect Worker Queue'),
+               '$page' => $sub_title,
                '$count' => count($r),
                '$id_header' => L10n::t('ID'),
                '$param_header' => L10n::t('Job Parameters'),
                '$created_header' => L10n::t('Created'),
                '$prio_header' => L10n::t('Priority'),
-               '$info' => L10n::t('This page lists the currently queued worker jobs. These jobs are handled by the worker cronjob you\'ve set up during install.'),
+               '$info' => $info,
                '$entries' => $r,
        ]);
 }
@@ -895,27 +912,28 @@ function admin_page_summary(App $a)
 
        logger('accounts: ' . print_r($accounts, true), LOGGER_DATA);
 
-       $r = q("SELECT COUNT(`id`) AS `count` FROM `register`");
-       $pending = $r[0]['count'];
+       $pending = Register::getPendingCount();
 
-       $r = q("SELECT COUNT(*) AS `total` FROM `queue` WHERE 1");
-       $queue = (($r) ? $r[0]['total'] : 0);
+       $queue = DBA::count('queue', []);
 
-       $r = q("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE NOT `done`");
-       $workerqueue = (($r) ? $r[0]['total'] : 0);
+       $deferred = DBA::count('workerqueue', ["`executed` <= ? AND NOT `done` AND `next_try` > ?",
+               DBA::NULL_DATETIME, DateTimeFormat::utcNow()]);
+
+       $workerqueue = DBA::count('workerqueue', ["`executed` <= ? AND NOT `done` AND `next_try` < ?",
+               DBA::NULL_DATETIME, DateTimeFormat::utcNow()]);
 
        // We can do better, but this is a quick queue status
 
-       $queues = ['label' => L10n::t('Message queues'), 'queue' => $queue, 'workerq' => $workerqueue];
+       $queues = ['label' => L10n::t('Message queues'), 'queue' => $queue, 'deferred' => $deferred, 'workerq' => $workerqueue];
 
 
        $r = q("SHOW variables LIKE 'max_allowed_packet'");
        $max_allowed_packet = (($r) ? $r[0]['Value'] : 0);
 
-       $server_settings = ['label' => L10n::t('Server Settings'), 
-                               'php' => ['upload_max_filesize' => ini_get('upload_max_filesize'), 
-                                                 'post_max_size' => ini_get('post_max_size'), 
-                                                 'memory_limit' => ini_get('memory_limit')], 
+       $server_settings = ['label' => L10n::t('Server Settings'),
+                               'php' => ['upload_max_filesize' => ini_get('upload_max_filesize'),
+                                                 'post_max_size' => ini_get('post_max_size'),
+                                                 'memory_limit' => ini_get('memory_limit')],
                                'mysql' => ['max_allowed_packet' => $max_allowed_packet]];
 
        $t = get_markup_template('admin/summary.tpl');
@@ -931,7 +949,7 @@ function admin_page_summary(App $a)
                '$platform' => FRIENDICA_PLATFORM,
                '$codename' => FRIENDICA_CODENAME,
                '$build' => Config::get('system', 'build'),
-               '$addons' => [L10n::t('Active addons'), $a->addons],
+               '$addons' => [L10n::t('Active addons'), Addon::getEnabledList()],
                '$serversettings' => $server_settings,
                '$showwarning' => $showwarning,
                '$warningtext' => $warningtext
@@ -945,7 +963,7 @@ function admin_page_summary(App $a)
  */
 function admin_page_site_post(App $a)
 {
-       check_form_security_token_redirectOnErr('/admin/site', 'admin_site');
+       BaseModule::checkFormSecurityTokenRedirectOnError('/admin/site', 'admin_site');
 
        if (!empty($_POST['republish_directory'])) {
                Worker::add(PRIORITY_LOW, 'Directory');
@@ -964,7 +982,7 @@ function admin_page_site_post(App $a)
                $parsed = @parse_url($new_url);
                if (!is_array($parsed) || !x($parsed, 'host') || !x($parsed, 'scheme')) {
                        notice(L10n::t("Can not parse base url. Must have at least <scheme>://<domain>"));
-                       goaway('admin/site');
+                       $a->internalRedirect('admin/site');
                }
 
                /* steps:
@@ -972,13 +990,13 @@ function admin_page_site_post(App $a)
                 * send relocate for every local user
                 * */
 
-               $old_url = System::baseUrl(true);
+               $old_url = $a->getBaseURL(true);
 
                // Generate host names for relocation the addresses in the format user@address.tld
                $new_host = str_replace("http://", "@", normalise_link($new_url));
                $old_host = str_replace("http://", "@", normalise_link($old_url));
 
-               function update_table($table_name, $fields, $old_url, $new_url)
+               function update_table(App $a, $table_name, $fields, $old_url, $new_url)
                {
                        $dbold = DBA::escape($old_url);
                        $dbnew = DBA::escape($new_url);
@@ -994,20 +1012,20 @@ function admin_page_site_post(App $a)
 
                        if (!DBA::isResult($r)) {
                                notice("Failed updating '$table_name': " . DBA::errorMessage());
-                               goaway('admin/site');
+                               $a->internalRedirect('admin/site');
                        }
                }
                // update tables
                // update profile links in the format "http://server.tld"
-               update_table("profile", ['photo', 'thumb'], $old_url, $new_url);
-               update_table("term", ['url'], $old_url, $new_url);
-               update_table("contact", ['photo', 'thumb', 'micro', 'url', 'nurl', 'alias', 'request', 'notify', 'poll', 'confirm', 'poco', 'avatar'], $old_url, $new_url);
-               update_table("gcontact", ['url', 'nurl', 'photo', 'server_url', 'notify', 'alias'], $old_url, $new_url);
-               update_table("item", ['owner-link', 'author-link', 'body', 'plink', 'tag'], $old_url, $new_url);
+               update_table($a, "profile", ['photo', 'thumb'], $old_url, $new_url);
+               update_table($a, "term", ['url'], $old_url, $new_url);
+               update_table($a, "contact", ['photo', 'thumb', 'micro', 'url', 'nurl', 'alias', 'request', 'notify', 'poll', 'confirm', 'poco', 'avatar'], $old_url, $new_url);
+               update_table($a, "gcontact", ['url', 'nurl', 'photo', 'server_url', 'notify', 'alias'], $old_url, $new_url);
+               update_table($a, "item", ['owner-link', 'author-link', 'body', 'plink', 'tag'], $old_url, $new_url);
 
                // update profile addresses in the format "user@server.tld"
-               update_table("contact", ['addr'], $old_host, $new_host);
-               update_table("gcontact", ['connect', 'addr'], $old_host, $new_host);
+               update_table($a, "contact", ['addr'], $old_host, $new_host);
+               update_table($a, "gcontact", ['connect', 'addr'], $old_host, $new_host);
 
                // update config
                Config::set('system', 'hostname', parse_url($new_url,  PHP_URL_HOST));
@@ -1023,7 +1041,7 @@ function admin_page_site_post(App $a)
 
                info("Relocation started. Could take a while to complete.");
 
-               goaway('admin/site');
+               $a->internalRedirect('admin/site');
        }
        // end relocate
 
@@ -1297,7 +1315,7 @@ function admin_page_site_post(App $a)
        Config::set('system', 'rino_encrypt', $rino);
 
        info(L10n::t('Site settings updated.') . EOL);
-       goaway('admin/site');
+       $a->internalRedirect('admin/site');
        return; // NOTREACHED
 }
 
@@ -1541,7 +1559,7 @@ function admin_page_site(App $a)
                '$relay_server_tags'    => ['relay_server_tags', L10n::t("Server tags"), Config::get('system','relay_server_tags'), L10n::t("Comma separated list of tags for the 'tags' subscription.")],
                '$relay_user_tags'      => ['relay_user_tags', L10n::t("Allow user tags"), Config::get('system', 'relay_user_tags', true), L10n::t("If enabled, the tags from the saved searches will used for the 'tags' subscription in addition to the 'relay_server_tags'.")],
 
-               '$form_security_token'  => get_form_security_token("admin_site"),
+               '$form_security_token'  => BaseModule::getFormSecurityToken("admin_site"),
                '$relocate_button'      => L10n::t('Start Relocation'),
        ]);
 }
@@ -1569,7 +1587,7 @@ function admin_page_dbsync(App $a)
                        Config::set('system', 'build', intval($curr) + 1);
                }
                info(L10n::t('Update has been marked successful') . EOL);
-               goaway('admin/dbsync');
+               $a->internalRedirect('admin/dbsync');
        }
 
        if (($a->argc > 2) && (intval($a->argv[2]) || ($a->argv[2] === 'check'))) {
@@ -1656,7 +1674,7 @@ function admin_page_users_post(App $a)
        $nu_email    = defaults($_POST, 'new_user_email'   , '');
        $nu_language = Config::get('system', 'language');
 
-       check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
+       BaseModule::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users');
 
        if (!($nu_name === "") && !($nu_email === "") && !($nu_nickname === "")) {
                try {
@@ -1744,7 +1762,7 @@ function admin_page_users_post(App $a)
                        user_deny($hash);
                }
        }
-       goaway('admin/users');
+       $a->internalRedirect('admin/users');
        return; // NOTREACHED
 }
 
@@ -1767,19 +1785,19 @@ function admin_page_users(App $a)
                $user = DBA::selectFirst('user', ['username', 'blocked'], ['uid' => $uid]);
                if (!DBA::isResult($user)) {
                        notice('User not found' . EOL);
-                       goaway('admin/users');
+                       $a->internalRedirect('admin/users');
                        return ''; // NOTREACHED
                }
                switch ($a->argv[2]) {
                        case "delete":
-                               check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
+                               BaseModule::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users', 't');
                                // delete user
                                User::remove($uid);
 
                                notice(L10n::t("User '%s' deleted", $user['username']) . EOL);
                                break;
                        case "block":
-                               check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
+                               BaseModule::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users', 't');
                                q("UPDATE `user` SET `blocked` = %d WHERE `uid` = %s",
                                        intval(1 - $user['blocked']),
                                        intval($uid)
@@ -1787,16 +1805,12 @@ function admin_page_users(App $a)
                                notice(sprintf(($user['blocked'] ? L10n::t("User '%s' unblocked") : L10n::t("User '%s' blocked")), $user['username']) . EOL);
                                break;
                }
-               goaway('admin/users');
+               $a->internalRedirect('admin/users');
                return ''; // NOTREACHED
        }
 
        /* get pending */
-       $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
-                                FROM `register`
-                                INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
-                                INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;");
-
+       $pending = Register::getPending();
 
        /* get users */
        $total = q("SELECT COUNT(*) AS `total` FROM `user` WHERE 1");
@@ -1930,7 +1944,7 @@ function admin_page_users(App $a)
                '$confirm_delete_multi' => L10n::t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'),
                '$confirm_delete' => L10n::t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'),
 
-               '$form_security_token' => get_form_security_token("admin_users"),
+               '$form_security_token' => BaseModule::getFormSecurityToken("admin_users"),
 
                // values //
                '$baseurl' => System::baseUrl(true),
@@ -1959,10 +1973,11 @@ function admin_page_users(App $a)
  *
  * The returned string returned hulds the HTML code of the page.
  *
- * @param App $a
+ * @param App   $a
+ * @param array $addons_admin A list of admin addon names
  * @return string
  */
-function admin_page_addons(App $a)
+function admin_page_addons(App $a, array $addons_admin)
 {
        /*
         * Single addon
@@ -1974,27 +1989,25 @@ function admin_page_addons(App $a)
                        return '';
                }
 
-               if (x($_GET, "a") && $_GET['a'] == "t") {
-                       check_form_security_token_redirectOnErr('/admin/addons', 'admin_themes', 't');
+               if (defaults($_GET, 'a', '') == "t") {
+                       BaseModule::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_themes', 't');
 
                        // Toggle addon status
-                       $idx = array_search($addon, $a->addons);
-                       if ($idx !== false) {
-                               unset($a->addons[$idx]);
+                       if (Addon::isEnabled($addon)) {
                                Addon::uninstall($addon);
                                info(L10n::t("Addon %s disabled.", $addon));
                        } else {
-                               $a->addons[] = $addon;
                                Addon::install($addon);
                                info(L10n::t("Addon %s enabled.", $addon));
                        }
-                       Config::set("system", "addon", implode(", ", $a->addons));
-                       goaway('admin/addons');
+
+                       Addon::saveEnabledList();
+                       $a->internalRedirect('admin/addons');
                        return ''; // NOTREACHED
                }
 
                // display addon details
-               if (in_array($addon, $a->addons)) {
+               if (Addon::isEnabled($addon)) {
                        $status = "on";
                        $action = L10n::t("Disable");
                } else {
@@ -2010,7 +2023,7 @@ function admin_page_addons(App $a)
                }
 
                $admin_form = "";
-               if (in_array($addon, $a->addons_admin)) {
+               if (in_array($addon, $addons_admin)) {
                        require_once "addon/$addon/$addon.php";
                        $func = $addon . '_addon_admin';
                        $func($a, $admin_form);
@@ -2023,7 +2036,7 @@ function admin_page_addons(App $a)
                        '$page' => L10n::t('Addons'),
                        '$toggle' => L10n::t('Toggle'),
                        '$settings' => L10n::t('Settings'),
-                       '$baseurl' => System::baseUrl(true),
+                       '$baseurl' => $a->getBaseURL(true),
 
                        '$addon' => $addon,
                        '$status' => $status,
@@ -2037,7 +2050,7 @@ function admin_page_addons(App $a)
                        '$screenshot' => '',
                        '$readme' => $readme,
 
-                       '$form_security_token' => get_form_security_token("admin_themes"),
+                       '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"),
                ]);
        }
 
@@ -2045,10 +2058,10 @@ function admin_page_addons(App $a)
         * List addons
         */
        if (x($_GET, "a") && $_GET['a'] == "r") {
-               check_form_security_token_redirectOnErr(System::baseUrl() . '/admin/addons', 'admin_themes', 't');
+               BaseModule::checkFormSecurityTokenRedirectOnError($a->getBaseURL() . '/admin/addons', 'admin_themes', 't');
                Addon::reload();
                info("Addons reloaded");
-               goaway(System::baseUrl() . '/admin/addons');
+               $a->internalRedirect('admin/addons');
        }
 
        $addons = [];
@@ -2061,7 +2074,7 @@ function admin_page_addons(App $a)
                                $show_addon = true;
 
                                // If the addon is unsupported, then only show it, when it is enabled
-                               if ((strtolower($info["status"]) == "unsupported") && !in_array($id, $a->addons)) {
+                               if ((strtolower($info["status"]) == "unsupported") && !Addon::isEnabled($id)) {
                                        $show_addon = false;
                                }
 
@@ -2071,7 +2084,7 @@ function admin_page_addons(App $a)
                                }
 
                                if ($show_addon) {
-                                       $addons[] = [$id, (in_array($id, $a->addons) ? "on" : "off"), $info];
+                                       $addons[] = [$id, (Addon::isEnabled($id) ? "on" : "off"), $info];
                                }
                        }
                }
@@ -2088,7 +2101,7 @@ function admin_page_addons(App $a)
                '$addons' => $addons,
                '$pcount' => count($addons),
                '$noplugshint' => L10n::t('There are currently no addons available on your node. You can find the official addon repository at %1$s and might find other interesting addons in the open addon registry at %2$s', 'https://github.com/friendica/friendica-addons', 'http://addons.friendi.ca'),
-               '$form_security_token' => get_form_security_token("admin_themes"),
+               '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"),
        ]);
 }
 
@@ -2223,7 +2236,7 @@ function admin_page_themes(App $a)
                }
 
                if (x($_GET, "a") && $_GET['a'] == "t") {
-                       check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't');
+                       BaseModule::checkFormSecurityTokenRedirectOnError('/admin/themes', 'admin_themes', 't');
 
                        // Toggle theme status
 
@@ -2238,7 +2251,7 @@ function admin_page_themes(App $a)
                        }
 
                        Config::set('system', 'allowed_themes', $s);
-                       goaway('admin/themes');
+                       $a->internalRedirect('admin/themes');
                        return ''; // NOTREACHED
                }
 
@@ -2305,13 +2318,13 @@ function admin_page_themes(App $a)
                        '$screenshot' => $screenshot,
                        '$readme' => $readme,
 
-                       '$form_security_token' => get_form_security_token("admin_themes"),
+                       '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"),
                ]);
        }
 
        // reload active themes
        if (x($_GET, "a") && $_GET['a'] == "r") {
-               check_form_security_token_redirectOnErr(System::baseUrl() . '/admin/themes', 'admin_themes', 't');
+               BaseModule::checkFormSecurityTokenRedirectOnError(System::baseUrl() . '/admin/themes', 'admin_themes', 't');
                foreach ($themes as $th) {
                        if ($th['allowed']) {
                                Theme::uninstall($th['name']);
@@ -2319,7 +2332,7 @@ function admin_page_themes(App $a)
                        }
                }
                info("Themes reloaded");
-               goaway(System::baseUrl() . '/admin/themes');
+               $a->internalRedirect('admin/themes');
        }
 
        /*
@@ -2344,7 +2357,7 @@ function admin_page_themes(App $a)
                '$noplugshint'         => L10n::t('No themes found on the system. They should be placed in %1$s', '<code>/view/themes</code>'),
                '$experimental'        => L10n::t('[Experimental]'),
                '$unsupported'         => L10n::t('[Unsupported]'),
-               '$form_security_token' => get_form_security_token("admin_themes"),
+               '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"),
        ]);
 }
 
@@ -2356,7 +2369,7 @@ function admin_page_themes(App $a)
 function admin_page_logs_post(App $a)
 {
        if (x($_POST, "page_logs")) {
-               check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');
 
                $logfile   = ((x($_POST,'logfile'))   ? notags(trim($_POST['logfile']))  : '');
                $debugging = ((x($_POST,'debugging')) ? true                             : false);
@@ -2368,7 +2381,7 @@ function admin_page_logs_post(App $a)
        }
 
        info(L10n::t("Log settings updated."));
-       goaway('admin/logs');
+       $a->internalRedirect('admin/logs');
        return; // NOTREACHED
 }
 
@@ -2418,7 +2431,7 @@ function admin_page_logs(App $a)
                '$debugging' => ['debugging', L10n::t("Enable Debugging"), Config::get('system', 'debugging'), ""],
                '$logfile' => ['logfile', L10n::t("Log file"), Config::get('system', 'logfile'), L10n::t("Must be writable by web server. Relative to your Friendica top-level directory.")],
                '$loglevel' => ['loglevel', L10n::t("Log level"), Config::get('system', 'loglevel'), "", $log_choices],
-               '$form_security_token' => get_form_security_token("admin_logs"),
+               '$form_security_token' => BaseModule::getFormSecurityToken("admin_logs"),
                '$phpheader' => L10n::t("PHP logging"),
                '$phphint' => L10n::t("To temporarily enable logging of PHP errors and warnings you can prepend the following to the index.php file of your installation. The filename set in the 'error_log' line is relative to the friendica top-level directory and must be writeable by the web server. The option '1' for 'log_errors' and 'display_errors' is to enable these options, set to '0' to disable them."),
                '$phplogcode' => "error_reporting(E_ERROR | E_WARNING | E_PARSE);\nini_set('error_log','php.out');\nini_set('log_errors','1');\nini_set('display_errors', '1');",
@@ -2489,7 +2502,7 @@ function admin_page_viewlogs(App $a)
  */
 function admin_page_features_post(App $a)
 {
-       check_form_security_token_redirectOnErr('/admin/features', 'admin_manage_features');
+       BaseModule::checkFormSecurityTokenRedirectOnError('/admin/features', 'admin_manage_features');
 
        logger('postvars: ' . print_r($_POST, true), LOGGER_DATA);
 
@@ -2516,7 +2529,7 @@ function admin_page_features_post(App $a)
                }
        }
 
-       goaway('admin/features');
+       $a->internalRedirect('admin/features');
        return; // NOTREACHED
 }
 
@@ -2554,7 +2567,7 @@ function admin_page_features(App $a)
 
                $tpl = get_markup_template('admin/settings_features.tpl');
                $o = replace_macros($tpl, [
-                       '$form_security_token' => get_form_security_token("admin_manage_features"),
+                       '$form_security_token' => BaseModule::getFormSecurityToken("admin_manage_features"),
                        '$title' => L10n::t('Manage Additional Features'),
                        '$features' => $arr,
                        '$submit' => L10n::t('Save Settings'),
index e978461655071c7774390b7d89dfe3d675ca0899..716b484461aeff250e902a856a040da6e1ddbec7 100644 (file)
@@ -5,6 +5,7 @@
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
+use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Module\Login;
 
@@ -76,7 +77,7 @@ function api_content(App $a)
                                if (strstr($consumer->callback_url, $glue)) {
                                        $glue = "?";
                                }
-                               goaway($consumer->callback_url . $glue . "oauth_token=" . OAuthUtil::urlencode_rfc3986($params['oauth_token']) . "&oauth_verifier=" . OAuthUtil::urlencode_rfc3986($verifier));
+                               $a->internalRedirect($consumer->callback_url . $glue . 'oauth_token=' . OAuthUtil::urlencode_rfc3986($params['oauth_token']) . '&oauth_verifier=' . OAuthUtil::urlencode_rfc3986($verifier));
                                killme();
                        }
 
index 85a3d9fe26cda9a87ad0dd790cdf921265f71fa6..80138f78dc9654d1c959dfcd0f9614d38e790c82 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * @file mod/apps.php
  */
-use Friendica\App;
+use Friendica\Content\Nav;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 
-function apps_content(App $a)
+function apps_content()
 {
        $privateaddons = Config::get('config', 'private_addons');
        if ($privateaddons === "1") {
@@ -18,13 +18,15 @@ function apps_content(App $a)
 
        $title = L10n::t('Applications');
 
-       if (count($a->apps) == 0) {
+       $apps = Nav::getAppMenu();
+
+       if (count($apps) == 0) {
                notice(L10n::t('No installed applications.') . EOL);
        }
 
        $tpl = get_markup_template('apps.tpl');
        return replace_macros($tpl, [
                '$title' => $title,
-               '$apps' => $a->apps,
+               '$apps'  => $apps,
        ]);
 }
index 99f0fc46000bdb54c6ef74678a53779bb3a64a1c..9ca701ba356ebde93865136b15dd19ef927d33b0 100644 (file)
@@ -6,9 +6,9 @@
 use Friendica\App;
 use Friendica\Core\L10n;
 use Friendica\Database\DBA;
+use Friendica\Util\Security;
 
 require_once 'include/dba.php';
-require_once 'include/security.php';
 
 function attach_init(App $a)
 {
@@ -27,7 +27,7 @@ function attach_init(App $a)
                return;
        }
 
-       $sql_extra = permissions_sql($r['uid']);
+       $sql_extra = Security::getPermissionsSQLByUserId($r['uid']);
 
        // Now we'll see if we can access the attachment
 
index ae1060c47ad5d36a1a76e774857ffd6c4f25e939..6f483acc163478853847b72c36b343bccb0117d4 100644 (file)
@@ -17,10 +17,12 @@ use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Event;
 use Friendica\Model\Group;
+use Friendica\Model\Item;
 use Friendica\Model\Profile;
 use Friendica\Protocol\DFRN;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Temporal;
+use Friendica\Util\Security;
 
 function cal_init(App $a)
 {
@@ -141,7 +143,7 @@ function cal_content(App $a)
        }
 
        // get the permissions
-       $sql_perms = item_permissions_sql($owner_uid, $remote_contact, $groups);
+       $sql_perms = Item::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
        // we only want to have the events of the profile owner
        $sql_extra = " AND `event`.`cid` = 0 " . $sql_perms;
 
@@ -299,7 +301,7 @@ function cal_content(App $a)
                // Respect the export feature setting for all other /cal pages if it's not the own profile
                if ((local_user() !== intval($owner_uid)) && !Feature::isEnabled($owner_uid, "export_calendar")) {
                        notice(L10n::t('Permission denied.') . EOL);
-                       goaway('cal/' . $nick);
+                       $a->internalRedirect('cal/' . $nick);
                }
 
                // Get the export data by uid
@@ -320,7 +322,7 @@ function cal_content(App $a)
                                $return_path = "cal/" . $nick;
                        }
 
-                       goaway($return_path);
+                       $a->internalRedirect($return_path);
                }
 
                // If nothing went wrong we can echo the export content
index 25a6aef17a5cc602833514148f2be7e20639af88..0b51f20d73334190c45d98d2af1a7be86084618f 100644 (file)
@@ -48,9 +48,9 @@ function common_content(App $a)
 
                if (DBA::isResult($contact)) {
                        $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"), [
-                               '$name' => htmlentities($contact['name']),
+                               '$name'  => htmlentities($contact['name']),
                                '$photo' => $contact['photo'],
-                               'url' => 'contacts/' . $cid
+                               'url'    => 'contact/' . $cid
                        ]);
 
                        if (!x($a->page, 'aside')) {
index d1432b7bbbf5c19dbd780a6f7eecbc59e7123063..0eaccc0db0306ead6ead5241690d2f37e524408c 100644 (file)
@@ -11,6 +11,7 @@ use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
+use Friendica\Model\Item;
 
 function community_init(App $a)
 {
@@ -90,7 +91,6 @@ function community_content(App $a, $update = 0)
                }
        }
 
-       require_once 'include/security.php';
        require_once 'include/conversation.php';
 
        if (!$update) {
@@ -227,19 +227,12 @@ function community_getitems($start, $itemspage, $content, $accounttype)
                return DBA::toArray($r);
        } elseif ($content == 'global') {
                if (!is_null($accounttype)) {
-                       $sql_accounttype = " AND `owner`.`contact-type` = ?";
-                       $values = [$accounttype, $start, $itemspage];
+                       $condition = ["`uid` = ? AND `owner`.`contact-type` = ?", 0, $accounttype];
                } else {
-                       $sql_accounttype = "";
-                       $values = [$start, $itemspage];
+                       $condition = ['uid' => 0];
                }
 
-               $r = DBA::p("SELECT `uri` FROM `thread`
-                               INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
-                               INNER JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
-                               INNER JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id`
-                               WHERE `thread`.`uid` = 0 AND NOT `author`.`hidden` AND NOT `author`.`blocked` $sql_accounttype
-                               ORDER BY `thread`.`commented` DESC LIMIT ?, ?", $values);
+               $r = Item::selectThreadForUser(0, ['uri'], $condition, ['order' => ['commented' => true], 'limit' => [$start, $itemspage]]);
                return DBA::toArray($r);
        }
 
index 13885cb49106adc94b44a2f1d60dd4a50c5e9cdd..1cf562d64cae885e45fd9e07f3939b3041e40224 100644 (file)
@@ -114,7 +114,7 @@ function crepair_content(App $a)
        $warning = L10n::t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact may stop working.');
        $info = L10n::t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
 
-       $returnaddr = "contacts/$cid";
+       $returnaddr = "contact/$cid";
 
        $allow_remote_self = Config::get('system', 'allow_users_remote_self');
 
index ed4f854377109c6c4466487ec6ab9f34eedb0eff..e38ce058e57305d4eca69a7f484e54a59b3baf2e 100644 (file)
@@ -4,11 +4,13 @@
  */
 
 use Friendica\App;
+use Friendica\BaseModule;
 use Friendica\Core\L10n;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\User;
+use Friendica\Util\Security;
 
 require_once 'mod/settings.php';
 
@@ -28,7 +30,7 @@ function delegate_post(App $a)
                return;
        }
 
-       check_form_security_token_redirectOnErr('/delegate', 'delegate');
+       BaseModule::checkFormSecurityTokenRedirectOnError('/delegate', 'delegate');
 
        $parent_uid = defaults($_POST, 'parent_user', 0);
        $parent_password = defaults($_POST, 'parent_password', '');
@@ -60,7 +62,7 @@ function delegate_content(App $a)
        if ($a->argc > 2 && $a->argv[1] === 'add' && intval($a->argv[2])) {
                // delegated admins can view but not change delegation permissions
                if (x($_SESSION, 'submanage')) {
-                       goaway(System::baseUrl() . '/delegate');
+                       $a->internalRedirect('delegate');
                }
 
                $user_id = $a->argv[2];
@@ -75,17 +77,17 @@ function delegate_content(App $a)
                                DBA::insert('manage', ['uid' => $user_id, 'mid' => local_user()]);
                        }
                }
-               goaway(System::baseUrl() . '/delegate');
+               $a->internalRedirect('delegate');
        }
 
        if ($a->argc > 2 && $a->argv[1] === 'remove' && intval($a->argv[2])) {
                // delegated admins can view but not change delegation permissions
                if (x($_SESSION, 'submanage')) {
-                       goaway(System::baseUrl() . '/delegate');
+                       $a->internalRedirect('delegate');
                }
 
                DBA::delete('manage', ['uid' => $a->argv[2], 'mid' => local_user()]);
-               goaway(System::baseUrl() . '/delegate');
+               $a->internalRedirect('delegate');
        }
 
        // find everybody that currently has delegated management to this account/page
@@ -162,7 +164,7 @@ function delegate_content(App $a)
        }
 
        $o = replace_macros(get_markup_template('delegate.tpl'), [
-               '$form_security_token' => get_form_security_token('delegate'),
+               '$form_security_token' => BaseModule::getFormSecurityToken('delegate'),
                '$parent_header' => L10n::t('Parent User'),
                '$parent_user' => $parent_user,
                '$parent_password' => $parent_password,
index 48ce3c6aa65684bfe6b47e7ba1794e8709327fb6..c4110596648d15421514bd5be595eaa93a6ad067 100644 (file)
@@ -400,7 +400,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
                // Let's send our user to the contact editor in case they want to
                // do anything special with this new friend.
                if ($handsfree === null) {
-                       goaway(System::baseUrl() . '/contact/' . intval($contact_id));
+                       $a->internalRedirect('contact/' . intval($contact_id));
                } else {
                        return;
                }
@@ -537,7 +537,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
                if (DBA::isResult($contact)) {
                        $photo = $contact['photo'];
                } else {
-                       $photo = System::baseUrl() . '/images/person-175.jpg';
+                       $photo = System::baseUrl() . '/images/person-300.jpg';
                }
 
                Contact::updateAvatar($photo, $local_uid, $dfrn_record);
@@ -620,6 +620,6 @@ function dfrn_confirm_post(App $a, $handsfree = null)
        }
 
        // somebody arrived here by mistake or they are fishing. Send them to the homepage.
-       goaway(System::baseUrl());
+       $a->internalRedirect();
        // NOTREACHED
 }
index af597d76ff7a6c55d3be3b29a5fc77c5f9ee62fb..354cf6b4caafcfb608a53eb7f4d31247c3a72b97 100644 (file)
@@ -90,7 +90,7 @@ function dfrn_poll_init(App $a)
                                $my_id = '0:' . $dfrn_id;
                                break;
                        default:
-                               goaway(System::baseUrl());
+                               $a->internalRedirect();
                                break; // NOTREACHED
                }
 
@@ -109,7 +109,7 @@ function dfrn_poll_init(App $a)
                        if (strlen($s)) {
                                $xml = XML::parseString($s);
 
-                               if ((int) $xml->status === 1) {
+                               if ((int)$xml->status === 1) {
                                        $_SESSION['authenticated'] = 1;
                                        if (!x($_SESSION, 'remote')) {
                                                $_SESSION['remote'] = [];
@@ -135,10 +135,15 @@ function dfrn_poll_init(App $a)
                                        );
                                }
                        }
-                       $profile = $r[0]['nickname'];
-                       goaway((strlen($destination_url)) ? $destination_url : System::baseUrl() . '/profile/' . $profile);
+
+                       $profile = (count($r) > 0 && isset($r[0]['nickname']) ? $r[0]['nickname'] : '');
+                       if (!empty($destination_url)) {
+                               System::externalRedirect($destination_url);
+                       } else {
+                               $a->internalRedirect('profile/' . $profile);
+                       }
                }
-               goaway(System::baseUrl());
+               $a->internalRedirect();
        }
 
        if ($type === 'profile-check' && $dfrn_version < 2.2) {
@@ -325,7 +330,7 @@ function dfrn_poll_post(App $a)
                        $my_id = '0:' . $dfrn_id;
                        break;
                default:
-                       goaway(System::baseUrl());
+                       $a->internalRedirect();
                        break; // NOTREACHED
        }
 
@@ -446,7 +451,7 @@ function dfrn_poll_content(App $a)
                                $my_id = '0:' . $dfrn_id;
                                break;
                        default:
-                               goaway(System::baseUrl());
+                               $a->internalRedirect();
                                break; // NOTREACHED
                }
 
@@ -505,25 +510,6 @@ function dfrn_poll_content(App $a)
                                ])->getBody();
                        }
 
-                       $profile = ((DBA::isResult($r) && $r[0]['nickname']) ? $r[0]['nickname'] : $nickname);
-
-                       switch ($destination_url) {
-                               case 'profile':
-                                       $dest = System::baseUrl() . '/profile/' . $profile . '?f=&tab=profile';
-                                       break;
-                               case 'photos':
-                                       $dest = System::baseUrl() . '/photos/' . $profile;
-                                       break;
-                               case 'status':
-                               case '':
-                                       $dest = System::baseUrl() . '/profile/' . $profile;
-                                       break;
-                               default:
-                                       $appendix = (strstr($destination_url, '?') ? '&f=&redir=1' : '?f=&redir=1');
-                                       $dest = $destination_url . $appendix;
-                                       break;
-                       }
-
                        logger("dfrn_poll: sec profile: " . $s, LOGGER_DATA);
 
                        if (strlen($s) && strstr($s, '<?xml')) {
@@ -557,10 +543,26 @@ function dfrn_poll_content(App $a)
                                                DBA::escape($session_id)
                                        );
                                }
+                       }
+
+                       $profile = ((DBA::isResult($r) && $r[0]['nickname']) ? $r[0]['nickname'] : $nickname);
 
-                               goaway($dest);
+                       switch ($destination_url) {
+                               case 'profile':
+                                       $a->internalRedirect('profile/' . $profile . '?f=&tab=profile');
+                                       break;
+                               case 'photos':
+                                       $a->internalRedirect('photos/' . $profile);
+                                       break;
+                               case 'status':
+                               case '':
+                                       $a->internalRedirect('profile/' . $profile);
+                                       break;
+                               default:
+                                       $appendix = (strstr($destination_url, '?') ? '&f=&redir=1' : '?f=&redir=1');
+                                       System::externalRedirect($destination_url . $appendix);
+                                       break;
                        }
-                       goaway($dest);
                        // NOTREACHED
                } else {
                        // XML reply
index 67db2c6285cdd1776657f8e7174203da8c2510e4..141e5e5aca64e3d3af6aea352d160782dd279151 100644 (file)
@@ -62,7 +62,7 @@ function dfrn_request_post(App $a)
        }
 
        if (x($_POST, 'cancel')) {
-               goaway(System::baseUrl());
+               $a->internalRedirect();
        }
 
        /*
@@ -173,9 +173,9 @@ function dfrn_request_post(App $a)
                                                Contact::updateAvatar($photo, local_user(), $r[0]["id"], true);
                                        }
 
-                                       $forwardurl = System::baseUrl() . "/contact/" . $r[0]['id'];
+                                       $forward_path = "contact/" . $r[0]['id'];
                                } else {
-                                       $forwardurl = System::baseUrl() . "/contact";
+                                       $forward_path = "contact";
                                }
 
                                // Allow the blocked remote notification to complete
@@ -188,14 +188,14 @@ function dfrn_request_post(App $a)
                                }
 
                                // (ignore reply, nothing we can do it failed)
-                               goaway($forwardurl);
+                               $a->internalRedirect($forward_path);
                                return; // NOTREACHED
                        }
                }
 
                // invalid/bogus request
                notice(L10n::t('Unrecoverable protocol error.') . EOL);
-               goaway(System::baseUrl());
+               $a->internalRedirect();
                return; // NOTREACHED
        }
 
@@ -331,19 +331,19 @@ function dfrn_request_post(App $a)
                                $url = Network::isUrlValid($url);
                                if (!$url) {
                                        notice(L10n::t('Invalid profile URL.') . EOL);
-                                       goaway(System::baseUrl() . '/' . $a->cmd);
+                                       $a->internalRedirect($a->cmd);
                                        return; // NOTREACHED
                                }
 
                                if (!Network::isUrlAllowed($url)) {
                                        notice(L10n::t('Disallowed profile URL.') . EOL);
-                                       goaway(System::baseUrl() . '/' . $a->cmd);
+                                       $a->internalRedirect($a->cmd);
                                        return; // NOTREACHED
                                }
 
                                if (Network::isUrlBlocked($url)) {
                                        notice(L10n::t('Blocked domain') . EOL);
-                                       goaway(System::baseUrl() . '/' . $a->cmd);
+                                       $a->internalRedirect($a->cmd);
                                        return; // NOTREACHED
                                }
 
@@ -351,7 +351,7 @@ function dfrn_request_post(App $a)
 
                                if (!count($parms)) {
                                        notice(L10n::t('Profile location is not valid or does not contain profile information.') . EOL);
-                                       goaway(System::baseUrl() . '/' . $a->cmd);
+                                       $a->internalRedirect($a->cmd);
                                } else {
                                        if (!x($parms, 'fn')) {
                                                notice(L10n::t('Warning: profile location has no identifiable owner name.') . EOL);
@@ -433,10 +433,10 @@ function dfrn_request_post(App $a)
                        }
 
                        // "Homecoming" - send the requestor back to their site to record the introduction.
-                       $dfrn_url = bin2hex(System::baseUrl() . '/profile/' . $nickname);
+                       $dfrn_url = bin2hex($a->getBaseURL() . '/profile/' . $nickname);
                        $aes_allow = ((function_exists('openssl_encrypt')) ? 1 : 0);
 
-                       goaway($parms['dfrn-request'] . "?dfrn_url=$dfrn_url"
+                       System::externalRedirect($parms['dfrn-request'] . "?dfrn_url=$dfrn_url"
                                . '&dfrn_version=' . DFRN_PROTOCOL_VERSION
                                . '&confirm_key=' . $hash
                                . (($aes_allow) ? "&aes_allow=1" : "")
@@ -459,11 +459,11 @@ function dfrn_request_post(App $a)
 
                                $uri = urlencode($uri);
                        } else {
-                               $uri = System::baseUrl() . '/profile/' . $nickname;
+                               $uri = 'profile/' . $nickname;
                        }
 
                        $url = str_replace('{uri}', $uri, $url);
-                       goaway($url);
+                       System::externalRedirect($url);
                        // NOTREACHED
                        // END $network != Protocol::PHANTOM
                } else {
index a03b918372efd61636961fbbf488f486aec18ddc..38cdfe41d35d90c7f7fc8b399433482a119b02da 100644 (file)
@@ -18,6 +18,7 @@ use Friendica\Model\Item;
 use Friendica\Model\Profile;
 use Friendica\Protocol\DFRN;
 use Friendica\Protocol\ActivityPub;
+use Friendica\Util\Security;
 
 function display_init(App $a)
 {
@@ -78,7 +79,7 @@ function display_init(App $a)
        }
 
        if (ActivityPub::isRequest()) {
-               goaway(str_replace('display/', 'objects/', $a->query_string));
+               $a->internalRedirect(str_replace('display/', 'objects/', $a->query_string));
        }
 
        if ($item["id"] != $item["parent"]) {
@@ -200,7 +201,6 @@ function display_content(App $a, $update = false, $update_uid = 0)
                return;
        }
 
-       require_once 'include/security.php';
        require_once 'include/conversation.php';
 
        $o = '';
@@ -325,7 +325,7 @@ function display_content(App $a, $update = false, $update_uid = 0)
                $o .= status_editor($a, $x, 0, true);
        }
 
-       $sql_extra = item_permissions_sql($a->profile['uid'], $is_remote_contact, $groups);
+       $sql_extra = Item::getPermissionsSQLByUserId($a->profile['uid'], $is_remote_contact, $groups);
 
        if (local_user() && (local_user() == $a->profile['uid'])) {
                $condition = ['parent-uri' => $item_parent_uri, 'uid' => local_user(), 'unseen' => true];
index d6493b3c0c1a8aa34f4d9c547ca1688fe3ca8759..780145ed3f72d885791cc6f6be7c1a3bfbe574d3 100644 (file)
@@ -21,20 +21,14 @@ function editpost_content(App $a)
        }
 
        $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
-       $return_url = (($a->argc > 2) ? base64_decode($a->argv[2]) : '');
 
        if (!$post_id) {
                notice(L10n::t('Item not found') . EOL);
                return;
        }
 
-       // Fallback to SESSION return_path
-       if (empty($return_url)) {
-               $return_url = $_SESSION['return_url'];
-       }
-
        $fields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
-               'type', 'body', 'title', 'file', 'wall', 'post-type'];
+               'type', 'body', 'title', 'file', 'wall', 'post-type', 'guid'];
 
        $item = Item::selectFirstForUser(local_user(), $fields, ['id' => $post_id, 'uid' => local_user()]);
 
@@ -92,7 +86,7 @@ function editpost_content(App $a)
 
        $o .= replace_macros($tpl, [
                '$is_edit' => true,
-               '$return_path' => $return_url,
+               '$return_path' => '/display/' . $item['guid'],
                '$action' => 'item',
                '$share' => L10n::t('Save'),
                '$upload' => L10n::t('Upload photo'),
index d6ad97eac67910c0671a3678853f04b80280742a..81ab79c722e09c895ea752608bc33a94df0f7e3a 100644 (file)
@@ -15,9 +15,9 @@ use Friendica\Database\DBA;
 use Friendica\Model\Event;
 use Friendica\Model\Item;
 use Friendica\Model\Profile;
+use Friendica\Module\Login;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Temporal;
-use Friendica\Module\Login;
 
 require_once 'include/items.php';
 
@@ -66,8 +66,8 @@ function events_post(App $a)
        // The default setting for the `private` field in event_store() is false, so mirror that
        $private_event = false;
 
-       $start  = NULL_DATE;
-       $finish = NULL_DATE;
+       $start  = DBA::NULL_DATETIME;
+       $finish = DBA::NULL_DATETIME;
 
        if ($start_text) {
                $start = $start_text;
@@ -100,7 +100,7 @@ function events_post(App $a)
        $type     = 'event';
 
        $action = ($event_id == '') ? 'new' : "event/" . $event_id;
-       $onerror_url = System::baseUrl() . "/events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish";
+       $onerror_path = "events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish";
 
        if (strcmp($finish, $start) < 0 && !$nofinish) {
                notice(L10n::t('Event can not end before it has started.') . EOL);
@@ -108,16 +108,16 @@ function events_post(App $a)
                        echo L10n::t('Event can not end before it has started.');
                        killme();
                }
-               goaway($onerror_url);
+               $a->internalRedirect($onerror_path);
        }
 
-       if (!$summary || ($start === NULL_DATE)) {
+       if (!$summary || ($start === DBA::NULL_DATETIME)) {
                notice(L10n::t('Event title and start time are required.') . EOL);
                if (intval($_REQUEST['preview'])) {
                        echo L10n::t('Event title and start time are required.');
                        killme();
                }
-               goaway($onerror_url);
+               $a->internalRedirect($onerror_path);
        }
 
        $share = intval(defaults($_POST, 'share', 0));
@@ -187,7 +187,7 @@ function events_post(App $a)
                Worker::add(PRIORITY_HIGH, "Notifier", "event", $item_id);
        }
 
-       goaway('/events');
+       $a->internalRedirect('events');
 }
 
 function events_content(App $a)
@@ -198,7 +198,7 @@ function events_content(App $a)
        }
 
        if ($a->argc == 1) {
-               $_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd;
+               $_SESSION['return_path'] = $a->cmd;
        }
 
        if (($a->argc > 2) && ($a->argv[1] === 'ignore') && intval($a->argv[2])) {
@@ -577,6 +577,6 @@ function events_content(App $a)
                        info(L10n::t('Event removed') . EOL);
                }
 
-               goaway(System::baseUrl() . '/events');
+               $a->internalRedirect('events');
        }
 }
index 9b0017322c993e229f2253703e83d7bcc6ae99fd..d8c89f8554d71cd952d06c66428f9fccec982919 100644 (file)
@@ -6,7 +6,6 @@ use Friendica\App;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 
-require_once 'include/security.php';
 require_once 'include/items.php';
 
 function filer_content(App $a)
index 7fb978ae6952e8aeebfeccdbc7c517163481f50e..733d67b593fdcaff4c7737955262bb63e724cb30 100644 (file)
@@ -25,7 +25,7 @@ function filerm_content(App $a) {
                file_tag_unsave_file(local_user(),$item_id,$term, $category);
        }
 
-       //goaway('/network');
+       //$a->internalRedirect('network');
 
        killme();
 }
index 04c279c5b6ab707f5995aa0c229e412613082d50..adc3fcc3bd5125465e4c3a0720053869360f8cfb 100644 (file)
@@ -20,12 +20,12 @@ function follow_post(App $a)
        }
 
        if (isset($_REQUEST['cancel'])) {
-               goaway('contacts');
+               $a->internalRedirect('contacts');
        }
 
        $uid = local_user();
        $url = notags(trim($_REQUEST['url']));
-       $return_url = 'contacts';
+       $return_path = 'contacts';
 
        // Makes the connection request for friendica contacts easier
        // This is just a precaution if maybe this page is called somewhere directly via POST
@@ -37,24 +37,24 @@ function follow_post(App $a)
                if ($result['message']) {
                        notice($result['message']);
                }
-               goaway($return_url);
+               $a->internalRedirect($return_path);
        } elseif ($result['cid']) {
-               goaway('contacts/' . $result['cid']);
+               $a->internalRedirect('contact/' . $result['cid']);
        }
 
        info(L10n::t('The contact could not be added.'));
 
-       goaway($return_url);
+       $a->internalRedirect($return_path);
        // NOTREACHED
 }
 
 function follow_content(App $a)
 {
-       $return_url = 'contacts';
+       $return_path = 'contacts';
 
        if (!local_user()) {
                notice(L10n::t('Permission denied.'));
-               goaway($return_url);
+               $a->internalRedirect($return_path);
                // NOTREACHED
        }
 
@@ -74,7 +74,7 @@ function follow_content(App $a)
                if ($r[0]['pending']) {
                        notice(L10n::t('You already added this contact.'));
                        $submit = '';
-                       //goaway($_SESSION['return_url']);
+                       //$a->internalRedirect($_SESSION['return_path']);
                        // NOTREACHED
                }
        }
@@ -84,21 +84,21 @@ function follow_content(App $a)
        if (($ret['network'] == Protocol::DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
                notice(L10n::t("Diaspora support isn't enabled. Contact can't be added."));
                $submit = '';
-               //goaway($_SESSION['return_url']);
+               //$a->internalRedirect($_SESSION['return_path']);
                // NOTREACHED
        }
 
        if (($ret['network'] == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
                notice(L10n::t("OStatus support is disabled. Contact can't be added."));
                $submit = '';
-               //goaway($_SESSION['return_url']);
+               //$a->internalRedirect($_SESSION['return_path']);
                // NOTREACHED
        }
 
        if ($ret['network'] == Protocol::PHANTOM) {
                notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
                $submit = '';
-               //goaway($_SESSION['return_url']);
+               //$a->internalRedirect($_SESSION['return_path']);
                // NOTREACHED
        }
 
@@ -118,7 +118,7 @@ function follow_content(App $a)
 
        if (!$r) {
                notice(L10n::t('Permission denied.'));
-               goaway($return_url);
+               $a->internalRedirect($return_path);
                // NOTREACHED
        }
 
index f2cb5c50b6fe1b55f9ad07053da15d1d2dcc03c0..bf3f7942f9eae3f4d8088f52a36ed2a49174ade3 100644 (file)
@@ -31,15 +31,7 @@ function friendica_init(App $a)
                        $admin = false;
                }
 
-               $visible_addons = [];
-               if (is_array($a->addons) && count($a->addons)) {
-                       $r = q("SELECT * FROM `addon` WHERE `hidden` = 0");
-                       if (DBA::isResult($r)) {
-                               foreach ($r as $rr) {
-                                       $visible_addons[] = $rr['name'];
-                               }
-                       }
-               }
+               $visible_addons = Addon::getVisibleList();
 
                Config::load('feature_lock');
                $locked_features = [];
@@ -91,16 +83,7 @@ function friendica_content(App $a)
        $o .= L10n::t('Suggestions, praise, etc. - please email "info" at "friendi - dot - ca');
        $o .= '</p>' . PHP_EOL;
 
-       $visible_addons = [];
-       if (is_array($a->addons) && count($a->addons)) {
-               $r = q("SELECT * FROM `addon` WHERE `hidden` = 0");
-               if (DBA::isResult($r)) {
-                       foreach ($r as $rr) {
-                               $visible_addons[] = $rr['name'];
-                       }
-               }
-       }
-
+       $visible_addons = Addon::getVisibleList();
        if (count($visible_addons)) {
                $o .= '<p>' . L10n::t('Installed addons/apps:') . '</p>' . PHP_EOL;
                $sorted = $visible_addons;
index f8fefc78f9e96cf91ac481f713ea956b8568df77..404448ebb77008b9175365c583ea452432823b0b 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 use Friendica\App;
+use Friendica\BaseModule;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
@@ -13,6 +14,7 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model;
 use Friendica\Module;
+use Friendica\Util\Security;
 
 function group_init(App $a) {
        if (local_user()) {
@@ -28,7 +30,7 @@ function group_post(App $a) {
        }
 
        if (($a->argc == 2) && ($a->argv[1] === 'new')) {
-               check_form_security_token_redirectOnErr('/group/new', 'group_edit');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/group/new', 'group_edit');
 
                $name = notags(trim($_POST['groupname']));
                $r = Model\Group::create(local_user(), $name);
@@ -36,17 +38,17 @@ function group_post(App $a) {
                        info(L10n::t('Group created.') . EOL);
                        $r = Model\Group::getIdByName(local_user(), $name);
                        if ($r) {
-                               goaway(System::baseUrl() . '/group/' . $r);
+                               $a->internalRedirect('group/' . $r);
                        }
                } else {
                        notice(L10n::t('Could not create group.') . EOL);
                }
-               goaway(System::baseUrl() . '/group');
+               $a->internalRedirect('group');
                return; // NOTREACHED
        }
 
        if (($a->argc == 2) && intval($a->argv[1])) {
-               check_form_security_token_redirectOnErr('/group', 'group_edit');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/group', 'group_edit');
 
                $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                        intval($a->argv[1]),
@@ -54,7 +56,7 @@ function group_post(App $a) {
                );
                if (!DBA::isResult($r)) {
                        notice(L10n::t('Group not found.') . EOL);
-                       goaway(System::baseUrl() . '/contact');
+                       $a->internalRedirect('contact');
                        return; // NOTREACHED
                }
                $group = $r[0];
@@ -86,7 +88,7 @@ function group_content(App $a) {
 
        // With no group number provided we jump to the unassigned contacts as a starting point
        if ($a->argc == 1) {
-               goaway('group/none');
+               $a->internalRedirect('group/none');
        }
 
        // Switch to text mode interface if we have more than 'n' contacts or group members
@@ -107,7 +109,7 @@ function group_content(App $a) {
                        '$title' => L10n::t('Create a group of contacts/friends.'),
                        '$gname' => ['groupname', L10n::t('Group Name: '), '', ''],
                        '$gid' => 'new',
-                       '$form_security_token' => get_form_security_token("group_edit"),
+                       '$form_security_token' => BaseModule::getFormSecurityToken("group_edit"),
                ]);
 
 
@@ -137,7 +139,7 @@ function group_content(App $a) {
 
 
        if (($a->argc == 3) && ($a->argv[1] === 'drop')) {
-               check_form_security_token_redirectOnErr('/group', 'group_drop', 't');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/group', 'group_drop', 't');
 
                if (intval($a->argv[2])) {
                        $r = q("SELECT `name` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@@ -157,12 +159,12 @@ function group_content(App $a) {
                                notice(L10n::t('Unable to remove group.') . EOL);
                        }
                }
-               goaway(System::baseUrl() . '/group');
+               $a->internalRedirect('group');
                // NOTREACHED
        }
 
        if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
-               check_form_security_token_ForbiddenOnErr('group_member_change', 't');
+               BaseModule::checkFormSecurityTokenForbiddenOnError('group_member_change', 't');
 
                $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1",
                        intval($a->argv[2]),
@@ -181,7 +183,7 @@ function group_content(App $a) {
 
                if (!DBA::isResult($r)) {
                        notice(L10n::t('Group not found.') . EOL);
-                       goaway(System::baseUrl() . '/contact');
+                       $a->internalRedirect('contact');
                }
 
                $group = $r[0];
@@ -216,7 +218,7 @@ function group_content(App $a) {
                $drop_txt = replace_macros($drop_tpl, [
                        '$id' => $group['id'],
                        '$delete' => L10n::t('Delete Group'),
-                       '$form_security_token' => get_form_security_token("group_drop"),
+                       '$form_security_token' => BaseModule::getFormSecurityToken("group_drop"),
                ]);
 
 
@@ -225,7 +227,7 @@ function group_content(App $a) {
                        '$gname' => ['groupname', L10n::t('Group Name: '), $group['name'], ''],
                        '$gid' => $group['id'],
                        '$drop' => $drop_txt,
-                       '$form_security_token' => get_form_security_token('group_edit'),
+                       '$form_security_token' => BaseModule::getFormSecurityToken('group_edit'),
                        '$edit_name' => L10n::t('Edit Group Name'),
                        '$editable' => 1,
                ];
@@ -244,7 +246,7 @@ function group_content(App $a) {
                'contacts' => [],
        ];
 
-       $sec_token = addslashes(get_form_security_token('group_member_change'));
+       $sec_token = addslashes(BaseModule::getFormSecurityToken('group_member_change'));
 
        // Format the data of the group members
        foreach ($members as $member) {
index 33d736a4e1cba2793efd62c8e576a90135f5740f..bf5b5d27fffa2fc5627f961e3391518392822cfd 100644 (file)
@@ -16,11 +16,11 @@ function home_init(App $a) {
        Addon::callHooks('home_init',$ret);
 
        if (local_user() && ($a->user['nickname'])) {
-               goaway(System::baseUrl()."/network");
+               $a->internalRedirect('network');
        }
 
        if (strlen(Config::get('system','singleuser'))) {
-               goaway(System::baseUrl()."/profile/" . Config::get('system','singleuser'));
+               $a->internalRedirect('profile/' . Config::get('system','singleuser'));
        }
 
 }}
index 8502874ce537ee04e01e2854e65aa05e08c887eb..4f14119fef876d792e9b3f1e684139a09fb9812f 100644 (file)
@@ -43,7 +43,7 @@ function ignored_init(App $a)
                        $rand = "?$rand";
                }
 
-               goaway(System::baseUrl() . "/" . $return_path . $rand);
+               $a->internalRedirect($return_path . $rand);
        }
 
        // the json doesn't really matter, it will either be 0 or 1
index 2a98d19ffcffaf5d3e3c660252e7f304d8d9572b..7f479157f81afbf93d0a7463c7d0d9a4dbc99fd6 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 use Friendica\App;
+use Friendica\BaseModule;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
@@ -14,6 +15,7 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Protocol\Email;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Security;
 
 function invite_post(App $a)
 {
@@ -22,7 +24,7 @@ function invite_post(App $a)
                return;
        }
 
-       check_form_security_token_redirectOnErr('/', 'send_invite');
+       BaseModule::checkFormSecurityTokenRedirectOnError('/', 'send_invite');
 
        $max_invites = intval(Config::get('system', 'max_invites'));
        if (! $max_invites) {
@@ -58,14 +60,9 @@ function invite_post(App $a)
                }
 
                if ($invitation_only && ($invites_remaining || is_site_admin())) {
-                       $code = autoname(8) . srand(1000, 9999);
+                       $code = Friendica\Model\Register::createForInvitation();
                        $nmessage = str_replace('$invite_code', $code, $message);
 
-                       $r = q("INSERT INTO `register` (`hash`,`created`) VALUES ('%s', '%s') ",
-                               DBA::escape($code),
-                               DBA::escape(DateTimeFormat::utcNow())
-                       );
-
                        if (! is_site_admin()) {
                                $invites_remaining --;
                                if ($invites_remaining >= 0) {
@@ -144,7 +141,7 @@ function invite_content(App $a) {
        }
 
        $o = replace_macros($tpl, [
-               '$form_security_token' => get_form_security_token("send_invite"),
+               '$form_security_token' => BaseModule::getFormSecurityToken("send_invite"),
                '$title'               => L10n::t('Send invitations'),
                '$recipients'          => ['recipients', L10n::t('Enter email addresses, one per line:')],
                '$message'             => ['message', L10n::t('Your message:'),L10n::t('You are cordially invited to join me and other close friends on Friendica - and help us to create a better social web.') . "\r\n" . "\r\n"
index 053a00c977ba77f45482aebe52dda7c86154c102..cd64b70f85568598f0a2c0202961d3178b33f639 100644 (file)
@@ -32,6 +32,7 @@ use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\Email;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Emailer;
+use Friendica\Util\Security;
 
 require_once 'include/enotify.php';
 require_once 'include/text.php';
@@ -42,8 +43,6 @@ function item_post(App $a) {
                return 0;
        }
 
-       require_once 'include/security.php';
-
        $uid = local_user();
 
        if (!empty($_REQUEST['dropitems'])) {
@@ -116,7 +115,7 @@ function item_post(App $a) {
                if (!DBA::isResult($parent_item)) {
                        notice(L10n::t('Unable to locate original post.') . EOL);
                        if (!empty($_REQUEST['return'])) {
-                               goaway($return_path);
+                               $a->internalRedirect($return_path);
                        }
                        killme();
                }
@@ -162,11 +161,11 @@ function item_post(App $a) {
        $allow_comment = local_user() && ($profile_uid == 0) && $parent && in_array($parent_item['network'], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]);
 
        // Now check that valid personal details have been provided
-       if (!can_write_wall($profile_uid) && !$allow_comment) {
+       if (!Security::canWriteToUserWall($profile_uid) && !$allow_comment) {
                notice(L10n::t('Permission denied.') . EOL) ;
 
                if (!empty($_REQUEST['return'])) {
-                       goaway($return_path);
+                       $a->internalRedirect($return_path);
                }
 
                killme();
@@ -284,7 +283,7 @@ function item_post(App $a) {
                        }
                        info(L10n::t('Empty post discarded.') . EOL);
                        if (!empty($_REQUEST['return'])) {
-                               goaway($return_path);
+                               $a->internalRedirect($return_path);
                        }
                        killme();
                }
@@ -679,7 +678,7 @@ function item_post(App $a) {
        if (!empty($datarray['cancel'])) {
                logger('mod_item: post cancelled by addon.');
                if ($return_path) {
-                       goaway($return_path);
+                       $a->internalRedirect($return_path);
                }
 
                $json = ['cancel' => 1];
@@ -715,7 +714,7 @@ function item_post(App $a) {
 
                if (!empty($_REQUEST['return']) && strlen($return_path)) {
                        logger('return: ' . $return_path);
-                       goaway($return_path);
+                       $a->internalRedirect($return_path);
                }
                killme();
        } else {
@@ -730,14 +729,14 @@ function item_post(App $a) {
 
        if (!$post_id) {
                logger("Item wasn't stored.");
-               goaway($return_path);
+               $a->internalRedirect($return_path);
        }
 
        $datarray = Item::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]);
 
        if (!DBA::isResult($datarray)) {
                logger("Item with id ".$post_id." couldn't be fetched.");
-               goaway($return_path);
+               $a->internalRedirect($return_path);
        }
 
        // update filetags in pconfig
@@ -845,13 +844,14 @@ function item_post(App $a) {
 function item_post_return($baseurl, $api_source, $return_path)
 {
        // figure out how to return, depending on from whence we came
+    $a = get_app();
 
        if ($api_source) {
                return;
        }
 
        if ($return_path) {
-               goaway($return_path);
+               $a->internalRedirect($return_path);
        }
 
        $json = ['success' => 1];
@@ -871,8 +871,6 @@ function item_content(App $a)
                return;
        }
 
-       require_once 'include/security.php';
-
        $o = '';
 
        if (($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
@@ -1015,11 +1013,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
 
                        $profile = $contact["url"];
                        $alias   = $contact["alias"];
-                       $newname = $contact["nick"];
-
-                       if (($newname == "") || !in_array($contact["network"], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::TWITTER, Protocol::STATUSNET])) {
-                               $newname = $contact["name"];
-                       }
+                       $newname = defaults($contact, "name", $contact["nick"]);
                }
 
                //if there is an url for this persons profile
index 957fe5fc42ee107b9dafcb22c5c9b35a727567d6..296e563bf466127fa77e86838f9d0de39497459f 100644 (file)
@@ -4,7 +4,6 @@ use Friendica\App;
 use Friendica\Core\System;
 use Friendica\Model\Item;
 
-require_once 'include/security.php';
 require_once 'include/items.php';
 
 function like_content(App $a) {
@@ -29,7 +28,7 @@ function like_content(App $a) {
        // See if we've been passed a return path to redirect to
        $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
 
-       like_content_return(System::baseUrl(), $return_path);
+       like_content_return($a, $return_path);
        killme(); // NOTREACHED
 }
 
@@ -37,7 +36,7 @@ function like_content(App $a) {
 // Decide how to return. If we were called with a 'return' argument,
 // then redirect back to the calling page. If not, just quietly end
 
-function like_content_return($baseurl, $return_path) {
+function like_content_return(App $a, $return_path) {
        if ($return_path) {
                $rand = '_=' . time();
                if (strpos($return_path, '?')) {
@@ -46,7 +45,7 @@ function like_content_return($baseurl, $return_path) {
                        $rand = "?$rand";
                }
 
-               goaway($baseurl . "/" . $return_path . $rand);
+               $a->internalRedirect($return_path . $rand);
        }
 
        killme();
index 166da25fc24b56b494ac60eea109dcf40e8725a0..9cde1c9ff4a637edf2398b99efe62c50c7bffd02 100644 (file)
@@ -19,14 +19,14 @@ function lostpass_post(App $a)
 {
        $loginame = notags(trim($_POST['login-name']));
        if (!$loginame) {
-               goaway(System::baseUrl());
+               $a->internalRedirect();
        }
 
        $condition = ['(`email` = ? OR `nickname` = ?) AND `verified` = 1 AND `blocked` = 0', $loginame, $loginame];
        $user = DBA::selectFirst('user', ['uid', 'username', 'email', 'language'], $condition);
        if (!DBA::isResult($user)) {
                notice(L10n::t('No valid account found.') . EOL);
-               goaway(System::baseUrl());
+               $a->internalRedirect();
        }
 
        $pwdreset_token = autoname(12) . mt_rand(1000, 9999);
@@ -78,7 +78,7 @@ function lostpass_post(App $a)
                'body'     => $body
        ]);
 
-       goaway(System::baseUrl());
+       $a->internalRedirect();
 }
 
 function lostpass_content(App $a)
index f81afb09a6e30e18ca2ba0bcecd23151adb2a7da..b98fcac6f747bae0c58254b5aa2348dfd0f86d81 100644 (file)
@@ -3,6 +3,7 @@
  * @file mod/manage.php
  */
 use Friendica\App;
+use Friendica\Core\Authentication;
 use Friendica\Core\Addon;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
@@ -98,7 +99,7 @@ function manage_post(App $a) {
        unset($_SESSION['theme']);
        unset($_SESSION['mobile-theme']);
        unset($_SESSION['page_flags']);
-       unset($_SESSION['return_url']);
+       unset($_SESSION['return_path']);
        if (x($_SESSION, 'submanage')) {
                unset($_SESSION['submanage']);
        }
@@ -109,8 +110,7 @@ function manage_post(App $a) {
                unset($_SESSION['sysmsg_info']);
        }
 
-       require_once('include/security.php');
-       authenticate_success($r[0], true, true);
+       Authentication::setAuthenticatedSessionForUser($r[0], true, true);
 
        if ($limited_id) {
                $_SESSION['submanage'] = $original_id;
@@ -119,7 +119,7 @@ function manage_post(App $a) {
        $ret = [];
        Addon::callHooks('home_init',$ret);
 
-       goaway( System::baseUrl() . "/profile/" . $a->user['nickname'] );
+       $a->internalRedirect('profile/' . $a->user['nickname'] );
        // NOTREACHED
 }
 
index 7e805d5baf4c4d9272e462f5c62a7a365bfd8549..b299619940e670385d4c54f3794d8ff25a5a9c32 100644 (file)
@@ -35,7 +35,7 @@ function match_content(App $a)
        $a->page['aside'] .= Widget::findPeople();
        $a->page['aside'] .= Widget::follow();
 
-       $_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd;
+       $_SESSION['return_path'] = $a->cmd;
 
        $r = q(
                "SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
index f9c5c29ec773a934f3795453c8c6a15b257848f3..8a04f9abef7499f6abaa4ee3f3e04d736cb147f9 100644 (file)
@@ -87,7 +87,7 @@ function message_post(App $a)
                $a->argc = 2;
                $a->argv[1] = 'new';
        } else {
-               goaway($a->cmd . '/' . $ret);
+               $a->internalRedirect($a->cmd . '/' . $ret);
        }
 }
 
@@ -155,7 +155,7 @@ function message_content(App $a)
 
                // Now check how the user responded to the confirmation query
                if (!empty($_REQUEST['canceled'])) {
-                       goaway('/message');
+                       $a->internalRedirect('message');
                }
 
                $cmd = $a->argv[1];
@@ -163,7 +163,7 @@ function message_content(App $a)
                        $message = DBA::selectFirst('mail', ['convid'], ['id' => $a->argv[2], 'uid' => local_user()]);
                        if(!DBA::isResult($message)){
                                info(L10n::t('Conversation not found.') . EOL);
-                               goaway('/message');
+                               $a->internalRedirect('message');
                        }
 
                        if (DBA::delete('mail', ['id' => $a->argv[2], 'uid' => local_user()])) {
@@ -173,10 +173,10 @@ function message_content(App $a)
                        $conversation = DBA::selectFirst('mail', ['id'], ['convid' => $message['convid'], 'uid' => local_user()]);
                        if(!DBA::isResult($conversation)){
                                info(L10n::t('Conversation removed.') . EOL);
-                               goaway('/message');
+                               $a->internalRedirect('message');
                        }
 
-                       goaway('/message/' . $conversation['id'] );
+                       $a->internalRedirect('message/' . $conversation['id'] );
                } else {
                        $r = q("SELECT `parent-uri`,`convid` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                                intval($a->argv[2]),
@@ -190,7 +190,7 @@ function message_content(App $a)
                                        info(L10n::t('Conversation removed.') . EOL);
                                }
                        }
-                       goaway('/message' );
+                       $a->internalRedirect('message');
                }
        }
 
@@ -265,7 +265,7 @@ function message_content(App $a)
        }
 
 
-       $_SESSION['return_url'] = $a->query_string;
+       $_SESSION['return_path'] = $a->query_string;
 
        if ($a->argc == 1) {
 
index fb0093849e1ef4b618641c51bf33de99cb65c905..b697cb3a63ae706b44d5df36e2757de31cd8a84f 100644 (file)
@@ -38,7 +38,7 @@ function network_init(App $a)
        $search = (x($_GET, 'search') ? escape_tags($_GET['search']) : '');
 
        if (($search != '') && !empty($_GET['submit'])) {
-               goaway('search?search=' . urlencode($search));
+               $a->internalRedirect('search?search=' . urlencode($search));
        }
 
        if (x($_GET, 'save')) {
@@ -140,7 +140,7 @@ function network_init(App $a)
 
                        $redir_url = ($net_queries ? $net_baseurl . '?' . $net_queries : $net_baseurl);
 
-                       goaway(System::baseUrl() . $redir_url);
+                       $a->internalRedirect($redir_url);
                }
        }
 
@@ -618,7 +618,7 @@ function networkThreadedView(App $a, $update, $parent)
                                killme();
                        }
                        notice(L10n::t('No such group') . EOL);
-                       goaway('network/0');
+                       $a->internalRedirect('network/0');
                        // NOTREACHED
                }
 
@@ -672,7 +672,7 @@ function networkThreadedView(App $a, $update, $parent)
                        }
                } else {
                        notice(L10n::t('Invalid contact.') . EOL);
-                       goaway('network');
+                       $a->internalRedirect('network');
                        // NOTREACHED
                }
        }
index 18681d7683c619c91ab0faa7f0af03a5e515f7c0..438c4ff4406bc4a472136b241ec4c411f7784e38 100644 (file)
@@ -24,5 +24,5 @@ function nogroup_content(App $a)
                return '';
        }
 
-       goaway(System::baseUrl() . '/group/none');
+       $a->internalRedirect('group/none');
 }
index da8352966e721e3f2c7698dc51668efa33db5967..55a92f8e64f674fc34716f0d656d174f238f7ea1 100644 (file)
@@ -33,7 +33,6 @@ function notes_content(App $a, $update = false)
                return;
        }
 
-       require_once 'include/security.php';
        require_once 'include/conversation.php';
 
        $o = Profile::getTabs($a, true);
index 133fd22fce242024001ac4015c193998411c9d6f..b40f0ee69cf5bfd9fef800f27c19181b1a5f011f 100644 (file)
@@ -15,8 +15,7 @@ function notice_init(App $a)
        $r = q("SELECT `user`.`nickname` FROM `user` LEFT JOIN `item` ON `item`.`uid` = `user`.`uid` WHERE `item`.`id` = %d", intval($id));
        if (DBA::isResult($r)) {
                $nick = $r[0]['nickname'];
-               $url = System::baseUrl() . "/display/$nick/$id";
-               goaway($url);
+               $a->internalRedirect('display/' . $nick . '/' . $id);
        } else {
                $a->error = 404;
                notice(L10n::t('Item not found.') . EOL);
index 1885f96447c9f7e54276cd059bd26cddcaa2482c..d5cfbf276da2a02245ce24077b1cf03cf1e3521a 100644 (file)
@@ -17,7 +17,7 @@ use Friendica\Module\Login;
 function notifications_post(App $a)
 {
        if (!local_user()) {
-               goaway(System::baseUrl());
+               $a->internalRedirect();
        }
 
        $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
@@ -52,12 +52,12 @@ function notifications_post(App $a)
                                        'self' => false, 'blocked' => true, 'pending' => true];
                                DBA::delete('contact', $condition);
                        }
-                       goaway('notifications/intros');
+                       $a->internalRedirect('notifications/intros');
                }
 
                if ($_POST['submit'] == L10n::t('Ignore')) {
                        DBA::update('intro', ['ignore' => true], ['id' => $intro_id]);
-                       goaway('notifications/intros');
+                       $a->internalRedirect('notifications/intros');
                }
        }
 }
index a277e59813ecb53a11907a2a7e9736a609408cdb..6ec36d8f99f7fe387a77df94c049a9c908e52931 100644 (file)
@@ -37,10 +37,10 @@ function notify_init(App $a)
                                }
                        }
 
-                       goaway($note['link']);
+                       System::externalRedirect($note['link']);
                }
 
-               goaway(System::baseUrl(true));
+               $a->internalRedirect();
        }
 
        if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') {
index 63b29684b3c5eded4a1fa651470a76ee192dc8b5..93a07a4b43523d1fffb355a7e7a70a5026bf874a 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 use Friendica\App;
+use Friendica\Core\Authentication;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
@@ -13,7 +14,7 @@ function openid_content(App $a) {
 
        $noid = Config::get('system','no_openid');
        if($noid)
-               goaway(System::baseUrl());
+               $a->internalRedirect();
 
        logger('mod_openid ' . print_r($_REQUEST,true), LOGGER_DATA);
 
@@ -27,7 +28,7 @@ function openid_content(App $a) {
 
                        if(! strlen($authid)) {
                                logger(L10n::t('OpenID protocol error. No ID returned.') . EOL);
-                               goaway(System::baseUrl());
+                               $a->internalRedirect();
                        }
 
                        // NOTE: we search both for normalised and non-normalised form of $authid
@@ -50,13 +51,12 @@ function openid_content(App $a) {
 
                                unset($_SESSION['openid']);
 
-                               require_once('include/security.php');
-                               authenticate_success($r[0],true,true);
+                               Authentication::setAuthenticatedSessionForUser($r[0],true,true);
 
                                // just in case there was no return url set
                                // and we fell through
 
-                               goaway(System::baseUrl());
+                               $a->internalRedirect();
                        }
 
                        // Successful OpenID login - but we can't match it to an existing account.
@@ -64,7 +64,7 @@ function openid_content(App $a) {
 
                        if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) {
                                notice(L10n::t('Account not found and OpenID registration is not permitted on this site.') . EOL);
-                               goaway(System::baseUrl());
+                               $a->internalRedirect();
                        }
 
                        unset($_SESSION['register']);
@@ -108,12 +108,12 @@ function openid_content(App $a) {
 
                        $args .= '&openid_url=' . urlencode(notags(trim($authid)));
 
-                       goaway(System::baseUrl() . '/register?' . $args);
+                       $a->internalRedirect('register?' . $args);
 
                        // NOTREACHED
                }
        }
        notice(L10n::t('Login failed.') . EOL);
-       goaway(System::baseUrl());
+       $a->internalRedirect();
        // NOTREACHED
 }
index 7012ecd4bcc58f35e3cf9aba74050270e1eed1fd..7fce9d0b690c9d9dab224fcb18d4db5ae38419d5 100644 (file)
@@ -15,7 +15,7 @@ function ostatus_subscribe_content(App $a) {
 
        if (! local_user()) {
                notice(L10n::t('Permission denied.') . EOL);
-               goaway('/ostatus_subscribe');
+               $a->internalRedirect('ostatus_subscribe');
                // NOTREACHED
        }
 
index 331ebf2629edb0ff74a58f5628d815a31a0f53fb..f35c584feb3bf66a623c72efb4d7fae4ae9596dc 100644 (file)
@@ -73,6 +73,7 @@ function parse_url_content(App $a)
                                $hdrs[$k] = $v;
                        }
                }
+               $type = null;
                if (array_key_exists('Content-Type', $hdrs)) {
                        $type = $hdrs['Content-Type'];
                }
index b1dd9a5c3a3c60863c5fb71b5c7fc2f194016581..54418f730d09e1789208dd78447bb9d0376359c6 100644 (file)
@@ -6,8 +6,7 @@
 use Friendica\App;
 use Friendica\Database\DBA;
 use Friendica\Object\Image;
-
-require_once 'include/security.php';
+use Friendica\Util\Security;
 
 function photo_init(App $a)
 {
@@ -52,7 +51,7 @@ function photo_init(App $a)
                exit;
        }
 
-       $default = 'images/person-175.jpg';
+       $default = 'images/person-300.jpg';
        $public = true;
 
        if (isset($type)) {
@@ -111,7 +110,7 @@ function photo_init(App $a)
                        intval($resolution)
                );
                if (DBA::isResult($r)) {
-                       $sql_extra = permissions_sql($r[0]['uid']);
+                       $sql_extra = Security::getPermissionsSQLByUserId($r[0]['uid']);
 
                        // Now we'll see if we can access the photo
                        $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` <= %d $sql_extra ORDER BY scale DESC LIMIT 1",
@@ -138,7 +137,7 @@ function photo_init(App $a)
                if (isset($resolution)) {
                        switch ($resolution) {
                                case 4:
-                                       $data = file_get_contents('images/person-175.jpg');
+                                       $data = file_get_contents('images/person-300.jpg');
                                        $mimetype = 'image/jpeg';
                                        break;
                                case 5:
index 259209ed4041ede16cf179b0c688030eaf10d4a8..ef6428d7ab563309dbfcb835553ff116cd1e245f 100644 (file)
@@ -26,9 +26,9 @@ use Friendica\Protocol\DFRN;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Map;
 use Friendica\Util\Temporal;
+use Friendica\Util\Security;
 
 require_once 'include/items.php';
-require_once 'include/security.php';
 
 function photos_init(App $a) {
 
@@ -196,7 +196,7 @@ function photos_post(App $a)
                $album = hex2bin($a->argv[3]);
 
                if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
-                       goaway($_SESSION['photo_return']);
+                       $a->internalRedirect($_SESSION['photo_return']);
                        return; // NOTREACHED
                }
 
@@ -207,13 +207,13 @@ function photos_post(App $a)
 
                if (!DBA::isResult($r)) {
                        notice(L10n::t('Album not found.') . EOL);
-                       goaway($_SESSION['photo_return']);
+                       $a->internalRedirect($_SESSION['photo_return']);
                        return; // NOTREACHED
                }
 
                // Check if the user has responded to a delete confirmation query
                if (!empty($_REQUEST['canceled'])) {
-                       goaway($_SESSION['photo_return']);
+                       $a->internalRedirect($_SESSION['photo_return']);
                }
 
                // RENAME photo album
@@ -227,8 +227,7 @@ function photos_post(App $a)
                        // Update the photo albums cache
                        Photo::clearAlbumCache($page_owner_uid);
 
-                       $newurl = System::baseUrl() . '/photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum);
-                       goaway($newurl);
+                       $a->internalRedirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum));
                        return; // NOTREACHED
                }
 
@@ -281,7 +280,7 @@ function photos_post(App $a)
                                        $res[] = "'" . DBA::escape($rr['rid']) . "'" ;
                                }
                        } else {
-                               goaway($_SESSION['photo_return']);
+                               $a->internalRedirect($_SESSION['photo_return']);
                                return; // NOTREACHED
                        }
 
@@ -299,14 +298,14 @@ function photos_post(App $a)
                        Photo::clearAlbumCache($page_owner_uid);
                }
 
-               goaway('photos/' . $a->data['user']['nickname']);
+               $a->internalRedirect('photos/' . $a->data['user']['nickname']);
                return; // NOTREACHED
        }
 
 
        // Check if the user has responded to a delete confirmation query for a single photo
        if ($a->argc > 2 && !empty($_REQUEST['canceled'])) {
-               goaway($_SESSION['photo_return']);
+               $a->internalRedirect($_SESSION['photo_return']);
        }
 
        if ($a->argc > 2 && defaults($_POST, 'delete', '') === L10n::t('Delete Photo')) {
@@ -356,7 +355,7 @@ function photos_post(App $a)
                        Photo::clearAlbumCache($page_owner_uid);
                }
 
-               goaway('photos/' . $a->data['user']['nickname']);
+               $a->internalRedirect('photos/' . $a->data['user']['nickname']);
                return; // NOTREACHED
        }
 
@@ -697,7 +696,7 @@ function photos_post(App $a)
                                }
                        }
                }
-               goaway($_SESSION['photo_return']);
+               $a->internalRedirect($_SESSION['photo_return']);
                return; // NOTREACHED
        }
 
@@ -928,7 +927,7 @@ function photos_post(App $a)
        // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
        // if they do not wish to be redirected
 
-       goaway($_SESSION['photo_return']);
+       $a->internalRedirect($_SESSION['photo_return']);
        // NOTREACHED
 }
 
@@ -948,7 +947,6 @@ function photos_content(App $a)
                return;
        }
 
-       require_once 'include/security.php';
        require_once 'include/conversation.php';
 
        if (empty($a->data['user'])) {
@@ -1053,7 +1051,7 @@ function photos_content(App $a)
                return;
        }
 
-       $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
+       $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
 
        $o = "";
 
@@ -1471,9 +1469,9 @@ function photos_content(App $a)
                if (count($linked_items)) {
                        $cmnt_tpl = get_markup_template('comment_item.tpl');
                        $tpl = get_markup_template('photo_item.tpl');
-                       $return_url = $a->cmd;
+                       $return_path = $a->cmd;
 
-                       if ($can_post || can_write_wall($owner_uid)) {
+                       if ($can_post || Security::canWriteToUserWall($owner_uid)) {
                                $like_tpl = get_markup_template('like_noshare.tpl');
                                $likebuttons = replace_macros($like_tpl, [
                                        '$id' => $link_item['id'],
@@ -1485,10 +1483,10 @@ function photos_content(App $a)
                        }
 
                        if (!DBA::isResult($items)) {
-                               if (($can_post || can_write_wall($owner_uid))) {
+                               if (($can_post || Security::canWriteToUserWall($owner_uid))) {
                                        $comments .= replace_macros($cmnt_tpl, [
                                                '$return_path' => '',
-                                               '$jsreload' => $return_url,
+                                               '$jsreload' => $return_path,
                                                '$id' => $link_item['id'],
                                                '$parent' => $link_item['id'],
                                                '$profile_uid' =>  $owner_uid,
@@ -1524,10 +1522,10 @@ function photos_content(App $a)
                                        $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
                                }
 
-                               if (($can_post || can_write_wall($owner_uid))) {
+                               if (($can_post || Security::canWriteToUserWall($owner_uid))) {
                                        $comments .= replace_macros($cmnt_tpl,[
                                                '$return_path' => '',
-                                               '$jsreload' => $return_url,
+                                               '$jsreload' => $return_path,
                                                '$id' => $link_item['id'],
                                                '$parent' => $link_item['id'],
                                                '$profile_uid' =>  $owner_uid,
@@ -1584,10 +1582,10 @@ function photos_content(App $a)
                                                '$comment' => $comment
                                        ]);
 
-                                       if (($can_post || can_write_wall($owner_uid))) {
+                                       if (($can_post || Security::canWriteToUserWall($owner_uid))) {
                                                $comments .= replace_macros($cmnt_tpl, [
                                                        '$return_path' => '',
-                                                       '$jsreload' => $return_url,
+                                                       '$jsreload' => $return_path,
                                                        '$id' => $item['item_id'],
                                                        '$parent' => $item['parent'],
                                                        '$profile_uid' =>  $owner_uid,
index ff0139f28f9d3b405f0b148ccf694b8ba03f0171..6f5b5b4a9828aeed4a79c628f6e0213f2cafb3ec 100644 (file)
@@ -202,11 +202,7 @@ function ping_init(App $a)
                $mail_count = count($mails);
 
                if (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE && is_site_admin()) {
-                       $regs = q(
-                               "SELECT `contact`.`name`, `contact`.`url`, `contact`.`micro`, `register`.`created`
-                               FROM `contact` RIGHT JOIN `register` ON `register`.`uid` = `contact`.`uid`
-                               WHERE `contact`.`self` = 1"
-                       );
+                       $regs = Friendica\Model\Register::getPending();
 
                        if (DBA::isResult($regs)) {
                                $register_count = count($regs);
@@ -225,7 +221,7 @@ function ping_init(App $a)
                                DBA::escape(DateTimeFormat::utcNow())
                        );
                        if (DBA::isResult($ev)) {
-                               Cache::set($cachekey, $ev, CACHE_HOUR);
+                               Cache::set($cachekey, $ev, Cache::HOUR);
                        }
                }
 
index 6ebb8632c18b3a24bc229b2c300fc1a8e346e97f..80d476005c06aa526350f48ac81d6a5173f2831d 100644 (file)
@@ -21,7 +21,6 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model\Item;
 
-require_once 'include/security.php';
 require_once 'include/items.php';
 
 function poke_init(App $a)
index aa284d1669a0184a1e6fdf05c84074d76e02ce46..6f0ab9e077af456aa9b7eec2fa4af27923450536 100644 (file)
@@ -20,6 +20,7 @@ use Friendica\Model\Profile;
 use Friendica\Module\Login;
 use Friendica\Protocol\DFRN;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Security;
 use Friendica\Protocol\ActivityPub;
 
 function profile_init(App $a)
@@ -33,7 +34,7 @@ function profile_init(App $a)
        } else {
                $r = q("SELECT `nickname` FROM `user` WHERE `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 ORDER BY RAND() LIMIT 1");
                if (DBA::isResult($r)) {
-                       goaway(System::baseUrl() . '/profile/' . $r[0]['nickname']);
+                       $a->internalRedirect('profile/' . $r[0]['nickname']);
                } else {
                        logger('profile error: mod_profile ' . $a->query_string, LOGGER_DEBUG);
                        notice(L10n::t('Requested profile is not available.') . EOL);
@@ -130,7 +131,6 @@ function profile_content(App $a, $update = 0)
                return Login::form();
        }
 
-       require_once 'include/security.php';
        require_once 'include/conversation.php';
        require_once 'include/items.php';
 
@@ -210,7 +210,7 @@ function profile_content(App $a, $update = 0)
                $a->page['aside'] .= Widget::categories(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], (!empty($category) ? xmlify($category) : ''));
                $a->page['aside'] .= Widget::tagCloud();
 
-               if (can_write_wall($a->profile['profile_uid'])) {
+               if (Security::canWriteToUserWall($a->profile['profile_uid'])) {
                        $x = [
                                'is_owner' => $is_owner,
                                'allow_location' => ($is_owner || $commvisitor) && $a->profile['allow_location'],
@@ -234,7 +234,7 @@ function profile_content(App $a, $update = 0)
 
 
        // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
-       $sql_extra = item_permissions_sql($a->profile['profile_uid'], $remote_contact, $groups);
+       $sql_extra = Item::getPermissionsSQLByUserId($a->profile['profile_uid'], $remote_contact, $groups);
        $sql_extra2 = '';
 
        if ($update) {
index 984ebfed6f39fc27bfa6bc157d903e5be905953a..da45226fe02bbc20f983774eac313f21a5e5c946 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 use Friendica\App;
+use Friendica\BaseModule;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
@@ -13,6 +14,7 @@ use Friendica\Model\Contact;
 use Friendica\Model\Photo;
 use Friendica\Model\Profile;
 use Friendica\Object\Image;
+use Friendica\Util\Security;
 
 function profile_photo_init(App $a)
 {
@@ -30,7 +32,7 @@ function profile_photo_post(App $a)
                return;
        }
 
-       check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
+       BaseModule::checkFormSecurityTokenRedirectOnError('/profile_photo', 'profile_photo');
 
        if (!empty($_POST['cropfinal']) && $_POST['cropfinal'] == 1) {
 
@@ -72,19 +74,19 @@ function profile_photo_post(App $a)
                $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = %d LIMIT 1", DBA::escape($image_id),
                        DBA::escape(local_user()), intval($scale));
 
-               $url = System::baseUrl() . '/profile/' . $a->user['nickname'];
+               $path = 'profile/' . $a->user['nickname'];
                if (DBA::isResult($r)) {
                        $base_image = $r[0];
 
                        $Image = new Image($base_image['data'], $base_image['type']);
                        if ($Image->isValid()) {
-                               $Image->crop(175, $srcX, $srcY, $srcW, $srcH);
+                               $Image->crop(300, $srcX, $srcY, $srcW, $srcH);
 
                                $r = Photo::store($Image, local_user(), 0, $base_image['resource-id'], $base_image['filename'],
                                                L10n::t('Profile Photos'), 4, $is_default_profile);
 
                                if ($r === false) {
-                                       notice(L10n::t('Image size reduction [%s] failed.', "175") . EOL);
+                                       notice(L10n::t('Image size reduction [%s] failed.', "300") . EOL);
                                }
 
                                $Image->scaleDown(80);
@@ -123,8 +125,8 @@ function profile_photo_post(App $a)
 
                                info(L10n::t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL);
                                // Update global directory in background
-                               if ($url && strlen(Config::get('system', 'directory'))) {
-                                       Worker::add(PRIORITY_LOW, "Directory", $url);
+                               if ($path && strlen(Config::get('system', 'directory'))) {
+                                       Worker::add(PRIORITY_LOW, "Directory", $a->getBaseURL() . '/' . $path);
                                }
 
                                Worker::add(PRIORITY_LOW, 'ProfileUpdate', local_user());
@@ -133,7 +135,7 @@ function profile_photo_post(App $a)
                        }
                }
 
-               goaway($url);
+               $a->internalRedirect($path);
                return; // NOTREACHED
        }
 
@@ -166,7 +168,7 @@ function profile_photo_post(App $a)
        @unlink($src);
 
        $imagecrop = profile_photo_crop_ui_head($a, $ph);
-       goaway(System::baseUrl() . '/profile_photo/use/' . $imagecrop['hash']);
+       $a->internalRedirect('profile_photo/use/' . $imagecrop['hash']);
 }
 
 function profile_photo_content(App $a)
@@ -186,7 +188,7 @@ function profile_photo_content(App $a)
        $imagecrop = [];
 
        if (isset($a->argv[1]) && $a->argv[1] == 'use' && $a->argc >= 3) {
-               // check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
+               // BaseModule::checkFormSecurityTokenRedirectOnError('/profile_photo', 'profile_photo');
 
                $resource_id = $a->argv[2];
                //die(":".local_user());
@@ -223,7 +225,7 @@ function profile_photo_content(App $a)
                                Worker::add(PRIORITY_LOW, "Directory", $url);
                        }
 
-                       goaway(System::baseUrl() . '/profile/' . $a->user['nickname']);
+                       $a->internalRedirect('profile/' . $a->user['nickname']);
                        return; // NOTREACHED
                }
                $ph = new Image($r[0]['data'], $r[0]['type']);
@@ -246,7 +248,7 @@ function profile_photo_content(App $a)
                        '$title' => L10n::t('Upload Profile Photo'),
                        '$submit' => L10n::t('Upload'),
                        '$profiles' => $profiles,
-                       '$form_security_token' => get_form_security_token("profile_photo"),
+                       '$form_security_token' => BaseModule::getFormSecurityToken("profile_photo"),
                        '$select' => sprintf('%s %s', L10n::t('or'),
                                ($newuser) ? '<a href="' . System::baseUrl() . '">' . L10n::t('skip this step') . '</a>' : '<a href="' . System::baseUrl() . '/photos/' . $a->user['nickname'] . '">' . L10n::t('select a photo from your photo albums') . '</a>')
                ]);
@@ -263,7 +265,7 @@ function profile_photo_content(App $a)
                        '$image_url' => System::baseUrl() . '/photo/' . $filename,
                        '$title'     => L10n::t('Crop Image'),
                        '$desc'      => L10n::t('Please adjust the image cropping for optimum viewing.'),
-                       '$form_security_token' => get_form_security_token("profile_photo"),
+                       '$form_security_token' => BaseModule::getFormSecurityToken("profile_photo"),
                        '$done'      => L10n::t('Done Editing')
                ]);
                return $o;
@@ -286,7 +288,7 @@ function profile_photo_crop_ui_head(App $a, Image $image)
        $height = $image->getHeight();
 
        if ($width < 175 || $height < 175) {
-               $image->scaleUp(200);
+               $image->scaleUp(300);
                $width = $image->getWidth();
                $height = $image->getHeight();
        }
index 3e6bd1cb0d0ff29bacf720540dcf125cd2132e1c..a4a49ec785ad1b4e5dfda67a1430bff5adfec849 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 use Friendica\App;
+use Friendica\BaseModule;
 use Friendica\Content\ContactSelector;
 use Friendica\Content\Feature;
 use Friendica\Content\Nav;
@@ -17,10 +18,10 @@ use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
 use Friendica\Model\Profile;
+use Friendica\Module\Login;
 use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Temporal;
-use Friendica\Module\Login;
 
 function profiles_init(App $a) {
 
@@ -37,11 +38,11 @@ function profiles_init(App $a) {
                );
                if (! DBA::isResult($r)) {
                        notice(L10n::t('Profile not found.') . EOL);
-                       goaway('profiles');
+                       $a->internalRedirect('profiles');
                        return; // NOTREACHED
                }
 
-               check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/profiles', 'profile_drop', 't');
 
                // move every contact using this profile as their default to the user default
 
@@ -58,13 +59,13 @@ function profiles_init(App $a) {
                        info(L10n::t('Profile deleted.').EOL);
                }
 
-               goaway('profiles');
+               $a->internalRedirect('profiles');
                return; // NOTREACHED
        }
 
        if (($a->argc > 1) && ($a->argv[1] === 'new')) {
 
-               check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/profiles', 'profile_new', 't');
 
                $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
                        intval(local_user()));
@@ -92,15 +93,15 @@ function profiles_init(App $a) {
 
                info(L10n::t('New profile created.') . EOL);
                if (DBA::isResult($r3) && count($r3) == 1) {
-                       goaway('profiles/' . $r3[0]['id']);
+                       $a->internalRedirect('profiles/' . $r3[0]['id']);
                }
 
-               goaway('profiles');
+               $a->internalRedirect('profiles');
        }
 
        if (($a->argc > 2) && ($a->argv[1] === 'clone')) {
 
-               check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/profiles', 'profile_clone', 't');
 
                $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
                        intval(local_user()));
@@ -131,10 +132,10 @@ function profiles_init(App $a) {
                );
                info(L10n::t('New profile created.') . EOL);
                if ((DBA::isResult($r3)) && (count($r3) == 1)) {
-                       goaway('profiles/'.$r3[0]['id']);
+                       $a->internalRedirect('profiles/'.$r3[0]['id']);
                }
 
-               goaway('profiles');
+               $a->internalRedirect('profiles');
 
                return; // NOTREACHED
        }
@@ -195,7 +196,7 @@ function profiles_post(App $a) {
                        return;
                }
 
-               check_form_security_token_redirectOnErr('/profiles', 'profile_edit');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/profiles', 'profile_edit');
 
                $is_default = (($orig[0]['is-default']) ? 1 : 0);
 
@@ -251,7 +252,7 @@ function profiles_post(App $a) {
                $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
 
                if (! strlen($howlong)) {
-                       $howlong = NULL_DATE;
+                       $howlong = DBA::NULL_DATETIME;
                } else {
                        $howlong = DateTimeFormat::convert($howlong, 'UTC', date_default_timezone_get());
                }
@@ -565,10 +566,10 @@ function profiles_content(App $a) {
                        ],
 
                        '$multi_profiles'               => Feature::isEnabled(local_user(), 'multi_profiles'),
-                       '$form_security_token'          => get_form_security_token("profile_edit"),
-                       '$form_security_token_photo'    => get_form_security_token("profile_photo"),
-                       '$profile_clone_link'           => ((Feature::isEnabled(local_user(), 'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone") : ""),
-                       '$profile_drop_link'            => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
+                       '$form_security_token'          => BaseModule::getFormSecurityToken("profile_edit"),
+                       '$form_security_token_photo'    => BaseModule::getFormSecurityToken("profile_photo"),
+                       '$profile_clone_link'           => ((Feature::isEnabled(local_user(), 'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . BaseModule::getFormSecurityToken("profile_clone") : ""),
+                       '$profile_drop_link'            => 'profiles/drop/' . $r[0]['id'] . '?t=' . BaseModule::getFormSecurityToken("profile_drop"),
 
                        '$profile_action' => L10n::t('Profile Actions'),
                        '$banner'       => L10n::t('Edit Profile Details'),
@@ -618,7 +619,7 @@ function profiles_content(App $a) {
                        '$gender' => ContactSelector::gender($r[0]['gender']),
                        '$marital' => ['selector' => ContactSelector::maritalStatus($r[0]['marital']), 'value' => $r[0]['marital']],
                        '$with' => ['with', L10n::t("Who: \x28if applicable\x29"), strip_tags($r[0]['with']), L10n::t('Examples: cathy123, Cathy Williams, cathy@example.com')],
-                       '$howlong' => ['howlong', L10n::t('Since [date]:'), ($r[0]['howlong'] <= NULL_DATE ? '' : DateTimeFormat::local($r[0]['howlong']))],
+                       '$howlong' => ['howlong', L10n::t('Since [date]:'), ($r[0]['howlong'] <= DBA::NULL_DATETIME ? '' : DateTimeFormat::local($r[0]['howlong']))],
                        '$sexual' => ['selector' => ContactSelector::sexualPreference($r[0]['sexual']), 'value' => $r[0]['sexual']],
                        '$about' => ['about', L10n::t('Tell us about yourself...'), $r[0]['about']],
                        '$xmpp' => ['xmpp', L10n::t("XMPP \x28Jabber\x29 address:"), $r[0]['xmpp'], L10n::t("The XMPP address will be propagated to your contacts so that they can follow you.")],
@@ -653,7 +654,7 @@ function profiles_content(App $a) {
                        );
                        if (DBA::isResult($r)) {
                                //Go to the default profile.
-                               goaway('profiles/' . $r[0]['id']);
+                               $a->internalRedirect('profiles/' . $r[0]['id']);
                        }
                }
 
@@ -681,7 +682,7 @@ function profiles_content(App $a) {
                                '$header'      => L10n::t('Edit/Manage Profiles'),
                                '$chg_photo'   => L10n::t('Change profile photo'),
                                '$cr_new'      => L10n::t('Create New Profile'),
-                               '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new"),
+                               '$cr_new_link' => 'profiles/new?t=' . BaseModule::getFormSecurityToken("profile_new"),
                                '$profiles'    => $profiles
                        ]);
                }
index bc284a4eb2f92e531bb926e53730b284672ffb8a..f4c7e311cae263e2efa242fa9297514a5b38d96f 100644 (file)
@@ -6,8 +6,7 @@ use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Protocol\OStatus;
 
-require_once('include/security.php');
-require_once('include/items.php');
+require_once 'include/items.php';
 
 function hub_return($valid, $body)
 {
index 18bcb236f8a98504e94acbe860b41c2d2ee82e08..055b3dcbe8650b9d86d725085045dea48e78b2ae 100644 (file)
@@ -13,8 +13,14 @@ function randprof_init(App $a)
        $x = GContact::getRandomUrl();
 
        if ($x) {
-               goaway(Contact::magicLink($x));
+               $link = Contact::magicLink($x);
+               // @TODO making the return of magicLink save to use either externalRedirect or internalRedirect
+               if (filter_var($link, FILTER_VALIDATE_URL)) {
+                       System::externalRedirect($link);
+               } else {
+                       $a->internalRedirect($link);
+               }
        }
 
-       goaway(System::baseUrl() . '/profile');
+       $a->internalRedirect('profile');
 }
index e989ad015a83045b5f98ce9e202e416bce03731a..ad42bc8abc18954052017e7dccb799a528a9d4ea 100644 (file)
@@ -27,7 +27,7 @@ function redir_init(App $a) {
                $contact = DBA::selectFirst('contact', $fields, ['id' => $cid, 'uid' => [0, local_user()]]);
                if (!DBA::isResult($contact)) {
                        notice(L10n::t('Contact not found.'));
-                       goaway(System::baseUrl());
+                       $a->internalRedirect();
                }
 
                $contact_url = $contact['url'];
@@ -36,7 +36,7 @@ function redir_init(App $a) {
                        || (!local_user() && !remote_user()) // Visitors (not logged in or not remotes) can't authenticate.
                        || (!empty($a->contact['id']) && $a->contact['id'] == $cid)) // Local user is already authenticated.
                {
-                       goaway($url != '' ? $url : $contact_url);
+                       System::externalRedirect(defaults($url, $contact_url));
                }
 
                if ($contact['uid'] == 0 && local_user()) {
@@ -50,14 +50,14 @@ function redir_init(App $a) {
 
                        if (!empty($a->contact['id']) && $a->contact['id'] == $cid) {
                                // Local user is already authenticated.
-                               $target_url = $url != '' ? $url : $contact_url;
+                               $target_url = defaults($url, $contact_url);
                                logger($contact['name'] . " is already authenticated. Redirecting to " . $target_url, LOGGER_DEBUG);
-                               goaway($target_url);
+                               System::externalRedirect($target_url);
                        }
                }
 
                if (remote_user()) {
-                       $host = substr(System::baseUrl() . ($a->getURLPath() ? '/' . $a->getURLPath() : ''), strpos(System::baseUrl(), '://') + 3);
+                       $host = substr($a->getBaseURL() . ($a->getURLPath() ? '/' . $a->getURLPath() : ''), strpos($a->getBaseURL(), '://') + 3);
                        $remotehost = substr($contact['addr'], strpos($contact['addr'], '@') + 1);
 
                        // On a local instance we have to check if the local user has already authenticated
@@ -71,9 +71,9 @@ function redir_init(App $a) {
                                foreach ($_SESSION['remote'] as $v) {
                                        if ($v['uid'] == $_SESSION['visitor_visiting'] && $v['cid'] == $_SESSION['visitor_id']) {
                                                // Remote user is already authenticated.
-                                               $target_url = $url != '' ? $url : $contact_url;
+                                               $target_url = defaults($url, $contact_url);
                                                logger($contact['name'] . " is already authenticated. Redirecting to " . $target_url, LOGGER_DEBUG);
-                                               goaway($target_url);
+                                               System::externalRedirect($target_url);
                                        }
                                }
                        }
@@ -102,11 +102,11 @@ function redir_init(App $a) {
 
                        $dest = (!empty($url) ? '&destination_url=' . $url : '');
 
-                       goaway($contact['poll'] . '?dfrn_id=' . $dfrn_id
+                       System::externalRedirect($contact['poll'] . '?dfrn_id=' . $dfrn_id
                                . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest . $quiet);
                }
 
-               $url = $url != '' ? $url : $contact_url;
+               $url = defaults($url, $contact_url);
        }
 
        // If we don't have a connected contact, redirect with
@@ -121,9 +121,9 @@ function redir_init(App $a) {
                }
 
                logger('redirecting to ' . $url, LOGGER_DEBUG);
-               goaway($url);
+               System::externalRedirect($url);
        }
 
        notice(L10n::t('Contact not found.'));
-       goaway(System::baseUrl());
+       $a->internalRedirect();
 }
index 454062d89b6c90c874f7511a1acd8d0ca003fc93..0a139ad7523afd9e580393183f8d6fdce06a4304 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 use Friendica\App;
+use Friendica\BaseModule;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
@@ -11,16 +12,14 @@ use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
-use Friendica\Database\DBA;
-use Friendica\Model\User;
+use Friendica\Model;
 use Friendica\Module\Tos;
-use Friendica\Util\DateTimeFormat;
 
 require_once 'include/enotify.php';
 
 function register_post(App $a)
 {
-       check_form_security_token_redirectOnErr('/register', 'register');
+       BaseModule::checkFormSecurityTokenRedirectOnError('/register', 'register');
 
        $verified = 0;
        $blocked  = 1;
@@ -64,10 +63,10 @@ function register_post(App $a)
 
        $arr['blocked'] = $blocked;
        $arr['verified'] = $verified;
-       $arr['language'] = L10n::getBrowserLanguage();
+       $arr['language'] = L10n::detectLanguage();
 
        try {
-               $result = User::create($arr);
+               $result = Model\User::create($arr);
        } catch (Exception $e) {
                notice($e->getMessage());
                return;
@@ -76,7 +75,7 @@ function register_post(App $a)
        $user = $result['user'];
 
        if ($netpublish && intval(Config::get('config', 'register_policy')) !== REGISTER_APPROVE) {
-               $url = System::baseUrl() . '/profile/' . $user['nickname'];
+               $url = $a->getBaseUrl() . '/profile/' . $user['nickname'];
                Worker::add(PRIORITY_LOW, "Directory", $url);
        }
 
@@ -86,18 +85,22 @@ function register_post(App $a)
 
        if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN) {
                if ($using_invites && $invite_id) {
-                       q("delete * from register where hash = '%s' limit 1", DBA::escape($invite_id));
+                       Model\Register::deleteByHash($invite_id);
                        PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
                }
 
                // Only send a password mail when the password wasn't manually provided
                if (!x($_POST, 'password1') || !x($_POST, 'confirm')) {
-                       $res = User::sendRegisterOpenEmail(
-                                       $user['email'], Config::get('config', 'sitename'), System::baseUrl(), $user['username'], $result['password'], $user);
+                       $res = Model\User::sendRegisterOpenEmail(
+                               $user,
+                               Config::get('config', 'sitename'),
+                               $a->getBaseUrl(),
+                               $result['password']
+                       );
 
                        if ($res) {
                                info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL);
-                               goaway(System::baseUrl());
+                               $a->internalRedirect();
                        } else {
                                notice(
                                        L10n::t('Failed to send email message. Here your accout details:<br> login: %s<br> password: %s<br><br>You can change your password after login.',
@@ -108,27 +111,19 @@ function register_post(App $a)
                        }
                } else {
                        info(L10n::t('Registration successful.') . EOL);
-                       goaway(System::baseUrl());
+                       $a->internalRedirect();
                }
        } elseif (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE) {
                if (!strlen(Config::get('config', 'admin_email'))) {
                        notice(L10n::t('Your registration can not be processed.') . EOL);
-                       goaway(System::baseUrl());
+                       $a->internalRedirect();
                }
 
-               $hash = random_string();
-               $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
-                       DBA::escape($hash),
-                       DBA::escape(DateTimeFormat::utcNow()),
-                       intval($user['uid']),
-                       DBA::escape($result['password']),
-                       DBA::escape(Config::get('system', 'language')),
-                       DBA::escape($_POST['permonlybox'])
-               );
+               Model\Register::createForApproval($user['uid'], Config::get('system', 'language'), $_POST['permonlybox']);
 
                // invite system
                if ($using_invites && $invite_id) {
-                       q("DELETE * FROM `register` WHERE `hash` = '%s' LIMIT 1", DBA::escape($invite_id));
+                       Model\Register::deleteByHash($invite_id);
                        PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
                }
 
@@ -146,9 +141,9 @@ function register_post(App $a)
                                'source_name'  => $user['username'],
                                'source_mail'  => $user['email'],
                                'source_nick'  => $user['nickname'],
-                               'source_link'  => System::baseUrl() . "/admin/users/",
-                               'link'         => System::baseUrl() . "/admin/users/",
-                               'source_photo' => System::baseUrl() . "/photo/avatar/" . $user['uid'] . ".jpg",
+                               'source_link'  => $a->getBaseUrl() . "/admin/users/",
+                               'link'         => $a->getBaseUrl() . "/admin/users/",
+                               'source_photo' => $a->getBaseUrl() . "/photo/avatar/" . $user['uid'] . ".jpg",
                                'to_email'     => $admin['email'],
                                'uid'          => $admin['uid'],
                                'language'     => $admin['language'] ? $admin['language'] : 'en',
@@ -156,11 +151,15 @@ function register_post(App $a)
                        ]);
                }
                // send notification to the user, that the registration is pending
-               User::sendRegisterPendingEmail(
-                       $user['email'], Config::get('config', 'sitename'), $user['username']);
+               Model\User::sendRegisterPendingEmail(
+                       $user,
+                       Config::get('config', 'sitename'),
+                       $a->getBaseURL(),
+                       $result['password']
+               );
 
                info(L10n::t('Your registration is pending approval by the site owner.') . EOL);
-               goaway(System::baseUrl());
+               $a->internalRedirect();
        }
 
        return;
@@ -291,7 +290,7 @@ function register_content(App $a)
                '$showprivstatement' => Config::get('system', 'tosprivstatement'),
                '$privstatement' => $tos->privacy_complete,
                '$baseurl'   => System::baseurl(),
-               '$form_security_token' => get_form_security_token("register"),
+               '$form_security_token' => BaseModule::getFormSecurityToken("register"),
                '$explicit_content' => Config::get('system', 'explicit_content', false),
                '$explicit_content_note' => L10n::t('Note: This node explicitly contains adult content')
        ]);
index 11d8eee412eadd013fb2b0197b825803db8baa2c..a7aebf6b0a4ebfd9bf8580653842b21e637f63cc 100644 (file)
@@ -9,6 +9,7 @@ use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
+use Friendica\Model\Register;
 use Friendica\Model\User;
 use Friendica\Module\Login;
 
@@ -18,51 +19,35 @@ function user_allow($hash)
 {
        $a = get_app();
 
-       $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
-               DBA::escape($hash)
-       );
-
-
+       $register = Register::getByHash($hash);
        if (!DBA::isResult($register)) {
                return false;
        }
 
-       $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
-               intval($register[0]['uid'])
-       );
-
+       $user = User::getById($register['uid']);
        if (!DBA::isResult($user)) {
-               killme();
+               exit();
        }
 
-       $r = q("DELETE FROM `register` WHERE `hash` = '%s'",
-               DBA::escape($register[0]['hash'])
-       );
+       Register::deleteByHash($hash);
 
+       DBA::update('user', ['blocked' => false, 'verified' => true], ['uid' => $register['uid']]);
 
-       $r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d",
-               intval($register[0]['uid'])
-       );
+       $profile = DBA::selectFirst('profile', ['net-publish'], ['uid' => $register['uid'], 'is-default' => true]);
 
-       $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default` = 1",
-               intval($user[0]['uid'])
-       );
-       if (DBA::isResult($r) && $r[0]['net-publish']) {
-               $url = System::baseUrl() . '/profile/' . $user[0]['nickname'];
-               if ($url && strlen(Config::get('system', 'directory'))) {
-                       Worker::add(PRIORITY_LOW, "Directory", $url);
-               }
+       if (DBA::isResult($profile) && $profile['net-publish'] && Config::get('system', 'directory')) {
+               $url = System::baseUrl() . '/profile/' . $user['nickname'];
+               Worker::add(PRIORITY_LOW, "Directory", $url);
        }
 
-       L10n::pushLang($register[0]['language']);
+       L10n::pushLang($register['language']);
 
        $res = User::sendRegisterOpenEmail(
-               $user[0]['email'],
+               $user,
                Config::get('config', 'sitename'),
-               System::baseUrl(),
-               $user[0]['username'],
-               $register[0]['password'],
-               $user[0]);
+               $a->getBaseUrl(),
+               defaults($register, 'password', 'Sent in a previous email')
+       );
 
        L10n::popLang();
 
@@ -77,22 +62,21 @@ function user_allow($hash)
 // allowed to have friends on this system
 function user_deny($hash)
 {
-       $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
-               DBA::escape($hash)
-       );
-
+       $register = Register::getByHash($hash);
        if (!DBA::isResult($register)) {
                return false;
        }
 
-       $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
-               intval($register[0]['uid'])
-       );
+       $user = User::getById($register['uid']);
+       if (!DBA::isResult($user)) {
+               exit();
+       }
+
+       DBA::delete('user', ['uid' => $register['uid']]);
 
-       DBA::delete('user', ['uid' => $register[0]['uid']]);
-       DBA::delete('register', ['hash' => $register[0]['hash']]);
+       Register::deleteByHash($register['hash']);
 
-       notice(L10n::t('Registration revoked for %s', $user[0]['username']) . EOL);
+       notice(L10n::t('Registration revoked for %s', $user['username']) . EOL);
        return true;
 }
 
@@ -100,17 +84,16 @@ function regmod_content(App $a)
 {
        if (!local_user()) {
                info(L10n::t('Please login.') . EOL);
-               $o = '<br /><br />' . Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 0 : 1);
-               return $o;
+               return Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 0 : 1);
        }
 
-       if ((!is_site_admin()) || (x($_SESSION, 'submanage') && intval($_SESSION['submanage']))) {
+       if (!is_site_admin() || !empty($_SESSION['submanage'])) {
                notice(L10n::t('Permission denied.') . EOL);
                return '';
        }
 
        if ($a->argc != 3) {
-               killme();
+               exit();
        }
 
        $cmd = $a->argv[1];
@@ -118,13 +101,11 @@ function regmod_content(App $a)
 
        if ($cmd === 'deny') {
                user_deny($hash);
-               goaway(System::baseUrl() . "/admin/users/");
-               killme();
+               $a->internalRedirect('admin/users/');
        }
 
        if ($cmd === 'allow') {
                user_allow($hash);
-               goaway(System::baseUrl() . "/admin/users/");
-               killme();
+               $a->internalRedirect('admin/users/');
        }
 }
index b386ec12f5ccabd09280900a32fc0a3b1139c7d1..86d46a177b26fc31a5f0bee87ce0dadacef8a1cf 100644 (file)
@@ -64,7 +64,7 @@ function removeme_post(App $a)
 function removeme_content(App $a)
 {
        if (!local_user()) {
-               goaway(System::baseUrl());
+               $a->internalRedirect();
        }
 
        $hash = random_string();
@@ -76,7 +76,7 @@ function removeme_content(App $a)
 
        $tpl = get_markup_template('removeme.tpl');
        $o = replace_macros($tpl, [
-               '$basedir' => System::baseUrl(),
+               '$basedir' => $a->getBaseURL(),
                '$hash' => $hash,
                '$title' => L10n::t('Remove My Account'),
                '$desc' => L10n::t('This will completely remove your account. Once this has been done it is not recoverable.'),
index 4499220817449b83684020ca1da731e3a6d170e9..3a3ce42067f0af5ec6db0e4e3bee6a56e06463df 100644 (file)
@@ -14,7 +14,7 @@ function repair_ostatus_content(App $a) {
 
        if (! local_user()) {
                notice(L10n::t('Permission denied.') . EOL);
-               goaway('/ostatus_repair');
+               $a->internalRedirect('ostatus_repair');
                // NOTREACHED
        }
 
index 64336e3487b0e78e34d304d37a86304e9b7d2630..80b1c184ff9e1b6129c2ecf524fe6180dcd4a31a 100644 (file)
@@ -13,7 +13,6 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Item;
 
-require_once 'include/security.php';
 require_once 'include/conversation.php';
 require_once 'mod/dirfind.php';
 
@@ -137,9 +136,9 @@ function search_content(App $a) {
                                                        "description" => L10n::t("Only one search per minute is permitted for not logged in users.")]);
                                killme();
                        }
-                       Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => $resultdata->accesses + 1]), CACHE_HOUR);
+                       Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => $resultdata->accesses + 1]), Cache::HOUR);
                } else
-                       Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => 1]), CACHE_HOUR);
+                       Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => 1]), Cache::HOUR);
        }
 
        Nav::setSelected('search');
index 5632193e3bddcf4255713060a28ac05e2d98bbd8..52c5f42cf08bb3c59420a515a2199fcfb7f8626c 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 use Friendica\App;
+use Friendica\BaseModule;
 use Friendica\Content\Feature;
 use Friendica\Content\Nav;
 use Friendica\Core\ACL;
@@ -19,10 +20,10 @@ use Friendica\Model\Contact;
 use Friendica\Model\GContact;
 use Friendica\Model\Group;
 use Friendica\Model\User;
+use Friendica\Module\Login;
 use Friendica\Protocol\Email;
 use Friendica\Util\Network;
 use Friendica\Util\Temporal;
-use Friendica\Module\Login;
 
 function get_theme_config_file($theme)
 {
@@ -154,16 +155,16 @@ function settings_post(App $a)
        $old_page_flags = $a->user['page-flags'];
 
        if (($a->argc > 1) && ($a->argv[1] === 'oauth') && x($_POST, 'remove')) {
-               check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/settings/oauth', 'settings_oauth');
 
                $key = $_POST['remove'];
                DBA::delete('tokens', ['id' => $key, 'uid' => local_user()]);
-               goaway(System::baseUrl(true)."/settings/oauth/");
+               $a->internalRedirect('settings/oauth/', true);
                return;
        }
 
        if (($a->argc > 2) && ($a->argv[1] === 'oauth')  && ($a->argv[2] === 'edit'||($a->argv[2] === 'add')) && x($_POST, 'submit')) {
-               check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/settings/oauth', 'settings_oauth');
 
                $name     = defaults($_POST, 'name'    , '');
                $key      = defaults($_POST, 'key'     , '');
@@ -204,19 +205,19 @@ function settings_post(App $a)
                                );
                        }
                }
-               goaway(System::baseUrl(true)."/settings/oauth/");
+               $a->internalRedirect('settings/oauth/', true);
                return;
        }
 
        if (($a->argc > 1) && ($a->argv[1] == 'addon')) {
-               check_form_security_token_redirectOnErr('/settings/addon', 'settings_addon');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/settings/addon', 'settings_addon');
 
                Addon::callHooks('addon_settings_post', $_POST);
                return;
        }
 
        if (($a->argc > 1) && ($a->argv[1] == 'connectors')) {
-               check_form_security_token_redirectOnErr('/settings/connectors', 'settings_connectors');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/settings/connectors', 'settings_connectors');
 
                if (x($_POST, 'general-submit')) {
                        PConfig::set(local_user(), 'system', 'disable_cw', intval($_POST['disable_cw']));
@@ -298,7 +299,7 @@ function settings_post(App $a)
        }
 
        if (($a->argc > 1) && ($a->argv[1] === 'features')) {
-               check_form_security_token_redirectOnErr('/settings/features', 'settings_features');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/settings/features', 'settings_features');
                foreach ($_POST as $k => $v) {
                        if (strpos($k, 'feature_') === 0) {
                                PConfig::set(local_user(), 'feature', substr($k, 8), ((intval($v)) ? 1 : 0));
@@ -309,7 +310,7 @@ function settings_post(App $a)
        }
 
        if (($a->argc > 1) && ($a->argv[1] === 'display')) {
-               check_form_security_token_redirectOnErr('/settings/display', 'settings_display');
+               BaseModule::checkFormSecurityTokenRedirectOnError('/settings/display', 'settings_display');
 
                $theme             = x($_POST, 'theme')             ? notags(trim($_POST['theme']))        : $a->user['theme'];
                $mobile_theme      = x($_POST, 'mobile_theme')      ? notags(trim($_POST['mobile_theme'])) : '';
@@ -369,16 +370,16 @@ function settings_post(App $a)
                );
 
                Addon::callHooks('display_settings_post', $_POST);
-               goaway('settings/display');
+               $a->internalRedirect('settings/display');
                return; // NOTREACHED
        }
 
-       check_form_security_token_redirectOnErr('/settings', 'settings');
+       BaseModule::checkFormSecurityTokenRedirectOnError('/settings', 'settings');
 
        if (x($_POST,'resend_relocate')) {
                Worker::add(PRIORITY_HIGH, 'Notifier', 'relocate', local_user());
                info(L10n::t("Relocate message has been send to your contacts"));
-               goaway('settings');
+               $a->internalRedirect('settings');
        }
 
        Addon::callHooks('settings_post', $_POST);
@@ -647,7 +648,7 @@ function settings_post(App $a)
        // Update the global contact for the user
        GContact::updateForUser(local_user());
 
-       goaway('settings');
+       $a->internalRedirect('settings');
        return; // NOTREACHED
 }
 
@@ -671,7 +672,7 @@ function settings_content(App $a)
                if (($a->argc > 2) && ($a->argv[2] === 'add')) {
                        $tpl = get_markup_template('settings/oauth_edit.tpl');
                        $o .= replace_macros($tpl, [
-                               '$form_security_token' => get_form_security_token("settings_oauth"),
+                               '$form_security_token' => BaseModule::getFormSecurityToken("settings_oauth"),
                                '$title'        => L10n::t('Add application'),
                                '$submit'       => L10n::t('Save Settings'),
                                '$cancel'       => L10n::t('Cancel'),
@@ -697,7 +698,7 @@ function settings_content(App $a)
 
                        $tpl = get_markup_template('settings/oauth_edit.tpl');
                        $o .= replace_macros($tpl, [
-                               '$form_security_token' => get_form_security_token("settings_oauth"),
+                               '$form_security_token' => BaseModule::getFormSecurityToken("settings_oauth"),
                                '$title'        => L10n::t('Add application'),
                                '$submit'       => L10n::t('Update'),
                                '$cancel'       => L10n::t('Cancel'),
@@ -711,10 +712,10 @@ function settings_content(App $a)
                }
 
                if (($a->argc > 3) && ($a->argv[2] === 'delete')) {
-                       check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth', 't');
+                       BaseModule::checkFormSecurityTokenRedirectOnError('/settings/oauth', 'settings_oauth', 't');
 
                        DBA::delete('clients', ['client_id' => $a->argv[3], 'uid' => local_user()]);
-                       goaway(System::baseUrl(true)."/settings/oauth/");
+                       $a->internalRedirect('settings/oauth/', true);
                        return;
                }
 
@@ -729,8 +730,8 @@ function settings_content(App $a)
 
                $tpl = get_markup_template('settings/oauth.tpl');
                $o .= replace_macros($tpl, [
-                       '$form_security_token' => get_form_security_token("settings_oauth"),
-                       '$baseurl'      => System::baseUrl(true),
+                       '$form_security_token' => BaseModule::getFormSecurityToken("settings_oauth"),
+                       '$baseurl'      => $a->getBaseURL(true),
                        '$title'        => L10n::t('Connected Apps'),
                        '$add'          => L10n::t('Add application'),
                        '$edit'         => L10n::t('Edit'),
@@ -756,7 +757,7 @@ function settings_content(App $a)
 
                $tpl = get_markup_template('settings/addons.tpl');
                $o .= replace_macros($tpl, [
-                       '$form_security_token' => get_form_security_token("settings_addon"),
+                       '$form_security_token' => BaseModule::getFormSecurityToken("settings_addon"),
                        '$title'        => L10n::t('Addon Settings'),
                        '$settings_addons' => $settings_addons
                ]);
@@ -777,7 +778,7 @@ function settings_content(App $a)
 
                $tpl = get_markup_template('settings/features.tpl');
                $o .= replace_macros($tpl, [
-                       '$form_security_token' => get_form_security_token("settings_features"),
+                       '$form_security_token' => BaseModule::getFormSecurityToken("settings_features"),
                        '$title'               => L10n::t('Additional Features'),
                        '$features'            => $arr,
                        '$submit'              => L10n::t('Save Settings'),
@@ -793,7 +794,7 @@ function settings_content(App $a)
                $legacy_contact            = PConfig::get(local_user(), 'ostatus', 'legacy_contact');
 
                if (x($legacy_contact)) {
-                       /// @todo Isn't it supposed to be a goaway() call?
+                       /// @todo Isn't it supposed to be a $a->internalRedirect() call?
                        $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL=' . System::baseUrl().'/ostatus_subscribe?url=' . urlencode($legacy_contact) . '">';
                }
 
@@ -828,7 +829,7 @@ function settings_content(App $a)
                $mail_pubmail      = ((DBA::isResult($r)) ? $r[0]['pubmail'] : 0);
                $mail_action       = ((DBA::isResult($r)) ? $r[0]['action'] : 0);
                $mail_movetofolder = ((DBA::isResult($r)) ? $r[0]['movetofolder'] : '');
-               $mail_chk          = ((DBA::isResult($r)) ? $r[0]['last_check'] : NULL_DATE);
+               $mail_chk          = ((DBA::isResult($r)) ? $r[0]['last_check'] : DBA::NULL_DATETIME);
 
 
                $tpl = get_markup_template('settings/connectors.tpl');
@@ -836,7 +837,7 @@ function settings_content(App $a)
                $mail_disabled_message = (($mail_disabled) ? L10n::t('Email access is disabled on this site.') : '');
 
                $o .= replace_macros($tpl, [
-                       '$form_security_token' => get_form_security_token("settings_connectors"),
+                       '$form_security_token' => BaseModule::getFormSecurityToken("settings_connectors"),
 
                        '$title'        => L10n::t('Social Networks'),
 
@@ -956,7 +957,7 @@ function settings_content(App $a)
                $tpl = get_markup_template('settings/display.tpl');
                $o = replace_macros($tpl, [
                        '$ptitle'       => L10n::t('Display Settings'),
-                       '$form_security_token' => get_form_security_token("settings_display"),
+                       '$form_security_token' => BaseModule::getFormSecurityToken("settings_display"),
                        '$submit'       => L10n::t('Save Settings'),
                        '$baseurl' => System::baseUrl(true),
                        '$uid' => local_user(),
@@ -1185,7 +1186,7 @@ function settings_content(App $a)
                '$submit'       => L10n::t('Save Settings'),
                '$baseurl' => System::baseUrl(true),
                '$uid' => local_user(),
-               '$form_security_token' => get_form_security_token("settings"),
+               '$form_security_token' => BaseModule::getFormSecurityToken("settings"),
                '$nickname_block' => $prof_addr,
 
                '$h_pass'       => L10n::t('Password Settings'),
index e75a09674082bfb432114371f9962302ba07bf6c..9b46b522bb9df752a78963da88b4427ea787a626 100644 (file)
@@ -42,7 +42,7 @@ function starred_init(App $a) {
                        $rand = "?$rand";
                }
 
-               goaway(System::baseUrl() . "/" . $return_path . $rand);
+               $a->internalRedirect($return_path . $rand);
        }
 
        // the json doesn't really matter, it will either be 0 or 1
index 105cf60feb7f1e3d3a3ba458c3b37625a149f29c..0082021df575c8376fa27c56b4885d6ab735ddf7 100644 (file)
@@ -8,8 +8,8 @@ use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Item;
+use Friendica\Util\Security;
 
-require_once 'include/security.php';
 require_once 'include/items.php';
 
 function subthread_content(App $a) {
@@ -32,7 +32,7 @@ function subthread_content(App $a) {
 
        $owner_uid = $item['uid'];
 
-       if (!can_write_wall($owner_uid)) {
+       if (!Security::canWriteToUserWall($owner_uid)) {
                return;
        }
 
index 81030842dcdf4dc220d05518e51a6fe2b157600f..1e33cb66024e9d811a3711bb31ef12d2d7c758d0 100644 (file)
@@ -62,7 +62,7 @@ function suggest_content(App $a)
                return;
        }
 
-       $_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd;
+       $_SESSION['return_path'] = $a->cmd;
 
        $a->page['aside'] .= Widget::findPeople();
        $a->page['aside'] .= Widget::follow();
index fd79d54150df6d60defe34a7b88f7616d278ad86..f661968f35a9b01c8b42b1bc1a0b4ffc2b53ea31 100644 (file)
@@ -10,7 +10,6 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model\Item;
 
-require_once 'include/security.php';
 require_once 'include/items.php';
 
 function tagger_content(App $a) {
index db0b765799ba7ab9582e9e1b9b4ac2cf9f450be3..105cc0b3d55467b867a5f8b1a3081b4cd698fcba 100644 (file)
@@ -13,11 +13,11 @@ use Friendica\Model\Item;
 function tagrm_post(App $a)
 {
        if (!local_user()) {
-               goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
+               $a->internalRedirect($_SESSION['photo_return']);
        }
 
        if (x($_POST,'submit') && ($_POST['submit'] === L10n::t('Cancel'))) {
-               goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
+               $a->internalRedirect($_SESSION['photo_return']);
        }
 
        $tag =  (x($_POST,'tag')  ? hex2bin(notags(trim($_POST['tag']))) : '');
@@ -25,7 +25,7 @@ function tagrm_post(App $a)
 
        $item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]);
        if (!DBA::isResult($item)) {
-               goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
+               $a->internalRedirect($_SESSION['photo_return']);
        }
 
        $arr = explode(',', $item['tag']);
@@ -41,7 +41,7 @@ function tagrm_post(App $a)
        Item::update(['tag' => $tag_str], ['id' => $item_id]);
 
        info(L10n::t('Tag removed') . EOL );
-       goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
+       $a->internalRedirect($_SESSION['photo_return']);
 
        // NOTREACHED
 }
@@ -53,25 +53,25 @@ function tagrm_content(App $a)
        $o = '';
 
        if (!local_user()) {
-               goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
+               $a->internalRedirect($_SESSION['photo_return']);
                // NOTREACHED
        }
 
        $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
        if (!$item_id) {
-               goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
+               $a->internalRedirect($_SESSION['photo_return']);
                // NOTREACHED
        }
 
        $item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]);
        if (!DBA::isResult($item)) {
-               goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
+               $a->internalRedirect($_SESSION['photo_return']);
        }
 
        $arr = explode(',', $item['tag']);
 
        if (!count($arr)) {
-               goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
+               $a->internalRedirect($_SESSION['photo_return']);
        }
 
        $o .= '<h3>' . L10n::t('Remove Item Tag') . '</h3>';
index 2449de4aa217e3e85d5a0440b09c9fa47a0f630f..388c40891a80b2d64419e96daf6d775f1bd82361 100644 (file)
@@ -14,8 +14,8 @@ function toggle_mobile_init(App $a) {
        if (isset($_GET['address'])) {
                $address = $_GET['address'];
        } else {
-               $address = System::baseUrl();
+               $address = '';
        }
 
-       goaway($address);
+       System::externalRedirect($address);
 }
index 9b0e206904bad703e608d2a460d993a72f39909c..2a60322f02d9b2d9043822e8cdaf9c26a8024d70 100644 (file)
@@ -12,13 +12,13 @@ use Friendica\Model\Contact;
 use Friendica\Model\Profile;
 use Friendica\Model\User;
 
-function unfollow_post()
+function unfollow_post(App $a)
 {
-       $return_url = 'contacts';
+       $return_path = 'contacts';
 
        if (!local_user()) {
                notice(L10n::t('Permission denied.'));
-               goaway('/login');
+               $a->internalRedirect('login');
                // NOTREACHED
        }
 
@@ -32,17 +32,17 @@ function unfollow_post()
 
        if (!DBA::isResult($contact)) {
                notice(L10n::t("You aren't following this contact."));
-               goaway($return_url);
+               $a->internalRedirect($return_path);
                // NOTREACHED
        }
 
        if (!empty($_REQUEST['cancel'])) {
-               goaway($return_url . '/' . $contact['id']);
+               $a->internalRedirect($return_path . '/' . $contact['id']);
        }
 
        if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
                notice(L10n::t('Unfollowing is currently not supported by your network.'));
-               goaway($return_url . '/' . $contact['id']);
+               $a->internalRedirect($return_path . '/' . $contact['id']);
                // NOTREACHED
        }
 
@@ -59,21 +59,21 @@ function unfollow_post()
                $return_path = 'contacts';
        } else {
                DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
-               $return_path = 'contacts/' . $contact['id'];
+               $return_path = 'contact/' . $contact['id'];
        }
 
        info(L10n::t('Contact unfollowed'));
-       goaway($return_path);
+       $a->internalRedirect($return_path);
        // NOTREACHED
 }
 
 function unfollow_content(App $a)
 {
-       $return_url = 'contacts';
+       $return_path = 'contacts';
 
        if (!local_user()) {
                notice(L10n::t('Permission denied.'));
-               goaway('/login');
+               $a->internalRedirect('login');
                // NOTREACHED
        }
 
@@ -88,13 +88,13 @@ function unfollow_content(App $a)
 
        if (!DBA::isResult($contact)) {
                notice(L10n::t("You aren't following this contact."));
-               goaway($return_url);
+               $a->internalRedirect($return_path);
                // NOTREACHED
        }
 
        if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
                notice(L10n::t('Unfollowing is currently not supported by your network.'));
-               goaway('contacts/' . $contact['id']);
+               $a->internalRedirect('contact/' . $contact['id']);
                // NOTREACHED
        }
 
@@ -105,7 +105,7 @@ function unfollow_content(App $a)
 
        if (!DBA::isResult($self)) {
                notice(L10n::t('Permission denied.'));
-               goaway($return_url);
+               $a->internalRedirect($return_path);
                // NOTREACHED
        }
 
index e52c78cab11f794a0b5f2e4fdd7ab30dfd35c2a0..521201394b24aeb37e5bc11f9674af7c9c2552c4 100644 (file)
@@ -14,9 +14,9 @@ use Friendica\Model\Group;
 use Friendica\Model\Item;
 use Friendica\Model\Profile;
 use Friendica\Protocol\DFRN;
+use Friendica\Util\Security;
 
 require_once 'include/items.php';
-require_once 'include/security.php';
 
 function videos_init(App $a)
 {
@@ -60,7 +60,7 @@ function videos_init(App $a)
                ]);
 
                /// @TODO Old-lost code?
-               /*$sql_extra = permissions_sql($a->data['user']['uid']);
+               /*$sql_extra = Security::getPermissionsSQLByUserId($a->data['user']['uid']);
 
                $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
                        intval($a->data['user']['uid'])
@@ -115,14 +115,14 @@ function videos_post(App $a)
        $owner_uid = $a->data['user']['uid'];
 
        if (local_user() != $owner_uid) {
-               goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
+               $a->internalRedirect('videos/' . $a->data['user']['nickname']);
        }
 
        if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
                // Check if we should do HTML-based delete confirmation
                if (empty($_REQUEST['confirm'])) {
                        if (!empty($_REQUEST['canceled'])) {
-                               goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
+                               $a->internalRedirect('videos/' . $a->data['user']['nickname']);
                        }
 
                        $drop_url = $a->query_string;
@@ -169,11 +169,11 @@ function videos_post(App $a)
                        }
                }
 
-               goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
+               $a->internalRedirect('videos/' . $a->data['user']['nickname']);
                return; // NOTREACHED
        }
 
-       goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
+       $a->internalRedirect('videos/' . $a->data['user']['nickname']);
 }
 
 function videos_content(App $a)
@@ -193,7 +193,6 @@ function videos_content(App $a)
                return;
        }
 
-       require_once 'include/security.php';
        require_once 'include/conversation.php';
 
        if (empty($a->data['user'])) {
@@ -302,7 +301,7 @@ function videos_content(App $a)
                return;
        }
 
-       $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
+       $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
 
        $o = "";
 
index 5e08420ecb109f6cd16767574f51815982038c9e..dcec6ef9c67ac9c0edb0e3191dc4c2fc8bb6d4db 100644 (file)
@@ -69,7 +69,7 @@ function wallmessage_post(App $a) {
                        info(L10n::t('Message sent.') . EOL);
        }
 
-       goaway('profile/'.$user['nickname']);
+       $a->internalRedirect('profile/'.$user['nickname']);
 }
 
 
index 97c193b3b7f4937ec68fe62fc390dd1787ba04d2..f24a4cffa4fc946862499b5c3391384a6b628f93 100644 (file)
@@ -5,16 +5,13 @@
 namespace Friendica;
 
 use Detection\MobileDetect;
+use DOMDocument;
+use DOMXPath;
 use Exception;
-use Friendica\Core\Config;
-use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
-use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Network\HTTPException\InternalServerErrorException;
 
 require_once 'boot.php';
-require_once 'include/dba.php';
 require_once 'include/text.php';
 
 /**
@@ -53,20 +50,14 @@ class App
        public $argv;
        public $argc;
        public $module;
-       public $strings;
-       public $hooks = [];
        public $timezone;
        public $interactive = true;
-       public $addons;
-       public $addons_admin = [];
-       public $apps = [];
        public $identities;
        public $is_mobile = false;
        public $is_tablet = false;
        public $performance = [];
        public $callstack = [];
        public $theme_info = [];
-       public $nav_sel;
        public $category;
        // Allow themes to control internal parameters
        // by changing App values in theme.php
@@ -120,7 +111,7 @@ class App
         * Inclusion is done in App->initHead().
         * The path can be absolute or relative to the Friendica installation base folder.
         *
-        * @see App->initHead()
+        * @see initHead()
         *
         * @param string $path
         */
@@ -136,7 +127,7 @@ class App
         * Inclusion is done in App->initFooter().
         * The path can be absolute or relative to the Friendica installation base folder.
         *
-        * @see App->initFooter()
+        * @see initFooter()
         *
         * @param string $path
         */
@@ -187,12 +178,12 @@ class App
        /**
         * @brief App constructor.
         *
-        * @param string $basePath Path to the app base folder
-        * @param bool $backend true, if the call is from backend, otherwise set to true (Default true)
+        * @param string $basePath  Path to the app base folder
+        * @param bool   $isBackend Whether it is used for backend or frontend (Default true=backend)
         *
         * @throws Exception if the Basepath is not usable
         */
-       public function __construct($basePath, $backend = true)
+       public function __construct($basePath, $isBackend = true)
        {
                if (!static::isDirectoryUsable($basePath, false)) {
                        throw new Exception('Basepath ' . $basePath . ' isn\'t usable.');
@@ -201,7 +192,7 @@ class App
                BaseObject::setApp($this);
 
                $this->basePath = rtrim($basePath, DIRECTORY_SEPARATOR);
-               $this->checkBackend($backend);
+               $this->checkBackend($isBackend);
                $this->checkFriendicaApp();
 
                $this->performance['start'] = microtime(true);
@@ -236,20 +227,20 @@ class App
 
                $this->scheme = 'http';
 
-               if ((x($_SERVER, 'HTTPS') && $_SERVER['HTTPS']) ||
-                       (x($_SERVER, 'HTTP_FORWARDED') && preg_match('/proto=https/', $_SERVER['HTTP_FORWARDED'])) ||
-                       (x($_SERVER, 'HTTP_X_FORWARDED_PROTO') && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ||
-                       (x($_SERVER, 'HTTP_X_FORWARDED_SSL') && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') ||
-                       (x($_SERVER, 'FRONT_END_HTTPS') && $_SERVER['FRONT_END_HTTPS'] == 'on') ||
-                       (x($_SERVER, 'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) // XXX: reasonable assumption, but isn't this hardcoding too much?
+               if (!empty($_SERVER['HTTPS']) ||
+                       !empty($_SERVER['HTTP_FORWARDED']) && preg_match('/proto=https/', $_SERVER['HTTP_FORWARDED']) ||
+                       !empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ||
+                       !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on' ||
+                       !empty($_SERVER['FRONT_END_HTTPS']) && $_SERVER['FRONT_END_HTTPS'] == 'on' ||
+                       !empty($_SERVER['SERVER_PORT']) && (intval($_SERVER['SERVER_PORT']) == 443) // XXX: reasonable assumption, but isn't this hardcoding too much?
                ) {
                        $this->scheme = 'https';
                }
 
-               if (x($_SERVER, 'SERVER_NAME')) {
+               if (!empty($_SERVER['SERVER_NAME'])) {
                        $this->hostname = $_SERVER['SERVER_NAME'];
 
-                       if (x($_SERVER, 'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
+                       if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
                                $this->hostname .= ':' . $_SERVER['SERVER_PORT'];
                        }
                }
@@ -260,9 +251,9 @@ class App
                        . $this->getBasePath(). DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR
                        . $this->getBasePath());
 
-               if ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 9) === 'pagename=') {
+               if (!empty($_SERVER['QUERY_STRING']) && strpos($_SERVER['QUERY_STRING'], 'pagename=') === 0) {
                        $this->query_string = substr($_SERVER['QUERY_STRING'], 9);
-               } elseif ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 2) === 'q=') {
+               } elseif (!empty($_SERVER['QUERY_STRING']) && strpos($_SERVER['QUERY_STRING'], 'q=') === 0) {
                        $this->query_string = substr($_SERVER['QUERY_STRING'], 2);
                }
 
@@ -313,7 +304,7 @@ class App
                }
 
                // See if there is any page number information, and initialise pagination
-               $this->pager['page'] = ((x($_GET, 'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1);
+               $this->pager['page'] = !empty($_GET['page']) && intval($_GET['page']) > 0 ? intval($_GET['page']) : 1;
                $this->pager['itemspage'] = 50;
                $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
 
@@ -363,30 +354,19 @@ class App
 
                $this->determineURLPath();
 
-               Config::load();
+               Core\Config::load();
 
                if ($this->getMode()->has(App\Mode::DBAVAILABLE)) {
-                       Core\Addon::loadHooks();
+                       Core\Hook::loadHooks();
 
                        $this->loadAddonConfig();
                }
 
                $this->loadDefaultTimezone();
 
-               $this->page = [
-                       'aside' => '',
-                       'bottom' => '',
-                       'content' => '',
-                       'footer' => '',
-                       'htmlhead' => '',
-                       'nav' => '',
-                       'page_title' => '',
-                       'right_aside' => '',
-                       'template' => '',
-                       'title' => ''
-               ];
+               Core\L10n::init();
 
-               $this->process_id = System::processID('log');
+               $this->process_id = Core\System::processID('log');
        }
 
        /**
@@ -593,7 +573,11 @@ class App
 
                $stamp1 = microtime(true);
 
-               DBA::connect($db_host, $db_user, $db_pass, $db_data, $charset);
+               if (DBA::connect($db_host, $db_user, $db_pass, $db_data, $charset)) {
+                       // Loads DB_UPDATE_VERSION constant
+                       Database\DBStructure::definition(false);
+               }
+
                unset($db_host, $db_user, $db_pass, $db_data, $charset);
 
                $this->saveTimestamp($stamp1, 'network');
@@ -612,14 +596,14 @@ class App
                $basepath = $this->basePath;
 
                if (!$basepath) {
-                       $basepath = Config::get('system', 'basepath');
+                       $basepath = Core\Config::get('system', 'basepath');
                }
 
-               if (!$basepath && x($_SERVER, 'DOCUMENT_ROOT')) {
+               if (!$basepath && !empty($_SERVER['DOCUMENT_ROOT'])) {
                        $basepath = $_SERVER['DOCUMENT_ROOT'];
                }
 
-               if (!$basepath && x($_SERVER, 'PWD')) {
+               if (!$basepath && !empty($_SERVER['PWD'])) {
                        $basepath = $_SERVER['PWD'];
                }
 
@@ -670,14 +654,14 @@ class App
        {
                $scheme = $this->scheme;
 
-               if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) {
+               if (Core\Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) {
                        $scheme = 'https';
                }
 
                //      Basically, we have $ssl = true on any links which can only be seen by a logged in user
                //      (and also the login link). Anything seen by an outsider will have it turned off.
 
-               if (Config::get('system', 'ssl_policy') == SSL_POLICY_SELFSIGN) {
+               if (Core\Config::get('system', 'ssl_policy') == SSL_POLICY_SELFSIGN) {
                        if ($ssl) {
                                $scheme = 'https';
                        } else {
@@ -685,8 +669,8 @@ class App
                        }
                }
 
-               if (Config::get('config', 'hostname') != '') {
-                       $this->hostname = Config::get('config', 'hostname');
+               if (Core\Config::get('config', 'hostname') != '') {
+                       $this->hostname = Core\Config::get('config', 'hostname');
                }
 
                return $scheme . '://' . $this->hostname . (!empty($this->getURLPath()) ? '/' . $this->getURLPath() : '' );
@@ -704,7 +688,7 @@ class App
                $parsed = @parse_url($url);
                $hostname = '';
 
-               if (x($parsed)) {
+               if (!empty($parsed)) {
                        if (!empty($parsed['scheme'])) {
                                $this->scheme = $parsed['scheme'];
                        }
@@ -713,10 +697,10 @@ class App
                                $hostname = $parsed['host'];
                        }
 
-                       if (x($parsed, 'port')) {
+                       if (!empty($parsed['port'])) {
                                $hostname .= ':' . $parsed['port'];
                        }
-                       if (x($parsed, 'path')) {
+                       if (!empty($parsed['path'])) {
                                $this->urlPath = trim($parsed['path'], '\\/');
                        }
 
@@ -724,8 +708,8 @@ class App
                                include $this->getBasePath() . DIRECTORY_SEPARATOR . '.htpreconfig.php';
                        }
 
-                       if (Config::get('config', 'hostname') != '') {
-                               $this->hostname = Config::get('config', 'hostname');
+                       if (Core\Config::get('config', 'hostname') != '') {
+                               $this->hostname = Core\Config::get('config', 'hostname');
                        }
 
                        if (!isset($this->hostname) || ($this->hostname == '')) {
@@ -736,8 +720,8 @@ class App
 
        public function getHostName()
        {
-               if (Config::get('config', 'hostname') != '') {
-                       $this->hostname = Config::get('config', 'hostname');
+               if (Core\Config::get('config', 'hostname') != '') {
+                       $this->hostname = Core\Config::get('config', 'hostname');
                }
 
                return $this->hostname;
@@ -777,7 +761,7 @@ class App
         */
        public function initHead()
        {
-               $interval = ((local_user()) ? PConfig::get(local_user(), 'system', 'update_interval') : 40000);
+               $interval = ((local_user()) ? Core\PConfig::get(local_user(), 'system', 'update_interval') : 40000);
 
                // If the update is 'deactivated' set it to the highest integer number (~24 days)
                if ($interval < 0) {
@@ -804,12 +788,12 @@ class App
 
                $this->registerStylesheet($stylesheet);
 
-               $shortcut_icon = Config::get('system', 'shortcut_icon');
+               $shortcut_icon = Core\Config::get('system', 'shortcut_icon');
                if ($shortcut_icon == '') {
                        $shortcut_icon = 'images/friendica-32.png';
                }
 
-               $touch_icon = Config::get('system', 'touch_icon');
+               $touch_icon = Core\Config::get('system', 'touch_icon');
                if ($touch_icon == '') {
                        $touch_icon = 'images/friendica-128.png';
                }
@@ -828,14 +812,14 @@ class App
                        '$baseurl'         => $this->getBaseURL(),
                        '$local_user'      => local_user(),
                        '$generator'       => 'Friendica' . ' ' . FRIENDICA_VERSION,
-                       '$delitem'         => L10n::t('Delete this item?'),
-                       '$showmore'        => L10n::t('show more'),
-                       '$showfewer'       => L10n::t('show fewer'),
+                       '$delitem'         => Core\L10n::t('Delete this item?'),
+                       '$showmore'        => Core\L10n::t('show more'),
+                       '$showfewer'       => Core\L10n::t('show fewer'),
                        '$update_interval' => $interval,
                        '$shortcut_icon'   => $shortcut_icon,
                        '$touch_icon'      => $touch_icon,
                        '$infinite_scroll' => $infinite_scroll,
-                       '$block_public'    => intval(Config::get('system', 'block_public')),
+                       '$block_public'    => intval(Core\Config::get('system', 'block_public')),
                        '$stylesheets'     => $this->stylesheets,
                ]) . $this->page['htmlhead'];
        }
@@ -916,7 +900,7 @@ class App
        private function registerTemplateEngine($class)
        {
                $v = get_class_vars($class);
-               if (x($v, 'name')) {
+               if (!empty($v['name'])) {
                        $name = $v['name'];
                        $this->template_engines[$name] = $class;
                } else {
@@ -935,10 +919,7 @@ class App
         */
        public function getTemplateEngine()
        {
-               $template_engine = 'smarty3';
-               if (x($this->theme, 'template_engine')) {
-                       $template_engine = $this->theme['template_engine'];
-               }
+               $template_engine = defaults($this->theme, 'template_engine', 'smarty3');
 
                if (isset($this->template_engines[$template_engine])) {
                        if (isset($this->template_engine_instance[$template_engine])) {
@@ -952,7 +933,7 @@ class App
                }
 
                echo "template engine <tt>$template_engine</tt> is not registered!\n";
-               killme();
+               exit();
        }
 
        /**
@@ -1030,7 +1011,7 @@ class App
                $this->performance[$value] += (float) $duration;
                $this->performance['marktime'] += (float) $duration;
 
-               $callstack = System::callstack();
+               $callstack = Core\System::callstack();
 
                if (!isset($this->callstack[$value][$callstack])) {
                        // Prevent ugly E_NOTICE
@@ -1138,13 +1119,13 @@ class App
                 *
                if ($this->is_backend()) {
                        $process = 'backend';
-                       $max_processes = Config::get('system', 'max_processes_backend');
+                       $max_processes = Core\Config::get('system', 'max_processes_backend');
                        if (intval($max_processes) == 0) {
                                $max_processes = 5;
                        }
                } else {
                        $process = 'frontend';
-                       $max_processes = Config::get('system', 'max_processes_frontend');
+                       $max_processes = Core\Config::get('system', 'max_processes_frontend');
                        if (intval($max_processes) == 0) {
                                $max_processes = 20;
                        }
@@ -1170,7 +1151,7 @@ class App
         */
        public function isMinMemoryReached()
        {
-               $min_memory = Config::get('system', 'min_memory', 0);
+               $min_memory = Core\Config::get('system', 'min_memory', 0);
                if ($min_memory == 0) {
                        return false;
                }
@@ -1216,19 +1197,19 @@ class App
        {
                if ($this->isBackend()) {
                        $process = 'backend';
-                       $maxsysload = intval(Config::get('system', 'maxloadavg'));
+                       $maxsysload = intval(Core\Config::get('system', 'maxloadavg'));
                        if ($maxsysload < 1) {
                                $maxsysload = 50;
                        }
                } else {
                        $process = 'frontend';
-                       $maxsysload = intval(Config::get('system', 'maxloadavg_frontend'));
+                       $maxsysload = intval(Core\Config::get('system', 'maxloadavg_frontend'));
                        if ($maxsysload < 1) {
                                $maxsysload = 50;
                        }
                }
 
-               $load = System::currentLoad();
+               $load = Core\System::currentLoad();
                if ($load) {
                        if (intval($load) > $maxsysload) {
                                logger('system: load ' . $load . ' for ' . $process . ' tasks (' . $maxsysload . ') too high.');
@@ -1480,7 +1461,7 @@ class App
         */
        public function getSenderEmailAddress()
        {
-               $sender_email = Config::get('config', 'sender_email');
+               $sender_email = Core\Config::get('config', 'sender_email');
                if (empty($sender_email)) {
                        $hostname = $this->getHostName();
                        if (strpos($hostname, ':')) {
@@ -1519,15 +1500,15 @@ class App
         */
        private function computeCurrentTheme()
        {
-               $system_theme = Config::get('system', 'theme');
+               $system_theme = Core\Config::get('system', 'theme');
                if (!$system_theme) {
-                       throw new Exception(L10n::t('No system theme config value set.'));
+                       throw new Exception(Core\L10n::t('No system theme config value set.'));
                }
 
                // Sane default
                $this->currentTheme = $system_theme;
 
-               $allowed_themes = explode(',', Config::get('system', 'allowed_themes', $system_theme));
+               $allowed_themes = explode(',', Core\Config::get('system', 'allowed_themes', $system_theme));
 
                $page_theme = null;
                // Find the theme that belongs to the user whose stuff we are looking at
@@ -1535,7 +1516,7 @@ class App
                        // Allow folks to override user themes and always use their own on their own site.
                        // This works only if the user is on the same server
                        $user = DBA::selectFirst('user', ['theme'], ['uid' => $this->profile_uid]);
-                       if (DBA::isResult($user) && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
+                       if (DBA::isResult($user) && !Core\PConfig::get(local_user(), 'system', 'always_my_theme')) {
                                $page_theme = $user['theme'];
                        }
                }
@@ -1544,7 +1525,7 @@ class App
 
                // Specific mobile theme override
                if (($this->is_mobile || $this->is_tablet) && Core\Session::get('show-mobile', true)) {
-                       $system_mobile_theme = Config::get('system', 'mobile-theme');
+                       $system_mobile_theme = Core\Config::get('system', 'mobile-theme');
                        $user_mobile_theme = Core\Session::get('mobile-theme', $system_mobile_theme);
 
                        // --- means same mobile theme as desktop
@@ -1607,4 +1588,422 @@ class App
 
                return $default;
        }
+
+       /**
+        * Sets the base url for use in cmdline programs which don't have
+        * $_SERVER variables
+        */
+       public function checkURL()
+       {
+               $url = Core\Config::get('system', 'url');
+
+               // if the url isn't set or the stored url is radically different
+               // than the currently visited url, store the current value accordingly.
+               // "Radically different" ignores common variations such as http vs https
+               // and www.example.com vs example.com.
+               // We will only change the url to an ip address if there is no existing setting
+
+               if (empty($url) || (!link_compare($url, $this->getBaseURL())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $this->getHostName()))) {
+                       Core\Config::set('system', 'url', $this->getBaseURL());
+               }
+       }
+
+       /**
+        * Frontend App script
+        *
+        * The App object behaves like a container and a dispatcher at the same time, including a representation of the
+        * request and a representation of the response.
+        *
+        * This probably should change to limit the size of this monster method.
+        */
+       public function runFrontend()
+       {
+               // Missing DB connection: ERROR
+               if ($this->getMode()->has(App\Mode::LOCALCONFIGPRESENT) && !$this->getMode()->has(App\Mode::DBAVAILABLE)) {
+                       Core\System::httpExit(500, ['title' => 'Error 500 - Internal Server Error', 'description' => 'Apologies but the website is unavailable at the moment.']);
+               }
+
+               // Max Load Average reached: ERROR
+               if ($this->isMaxProcessesReached() || $this->isMaxLoadReached()) {
+                       header('Retry-After: 120');
+                       header('Refresh: 120; url=' . $this->getBaseURL() . "/" . $this->query_string);
+
+                       Core\System::httpExit(503, ['title' => 'Error 503 - Service Temporarily Unavailable', 'description' => 'Core\System is currently overloaded. Please try again later.']);
+               }
+
+               if (strstr($this->query_string, '.well-known/host-meta') && ($this->query_string != '.well-known/host-meta')) {
+                       Core\System::httpExit(404);
+               }
+
+               if (!$this->getMode()->isInstall()) {
+                       // Force SSL redirection
+                       if (Core\Config::get('system', 'force_ssl') && ($this->getScheme() == "http")
+                               && intval(Core\Config::get('system', 'ssl_policy')) == SSL_POLICY_FULL
+                               && strpos($this->getBaseURL(), 'https://') === 0
+                               && $_SERVER['REQUEST_METHOD'] == 'GET') {
+                               header('HTTP/1.1 302 Moved Temporarily');
+                               header('Location: ' . $this->getBaseURL() . '/' . $this->query_string);
+                               exit();
+                       }
+
+                       Core\Session::init();
+                       Core\Addon::callHooks('init_1');
+               }
+
+               // Exclude the backend processes from the session management
+               if (!$this->isBackend()) {
+                       $stamp1 = microtime(true);
+                       session_start();
+                       $this->saveTimestamp($stamp1, 'parser');
+                       Core\L10n::setSessionVariable();
+                       Core\L10n::setLangFromSession();
+               } else {
+                       $_SESSION = [];
+                       Core\Worker::executeIfIdle();
+               }
+
+               // ZRL
+               if (!empty($_GET['zrl']) && $this->getMode()->isNormal()) {
+                       $this->query_string = Model\Profile::stripZrls($this->query_string);
+                       if (!local_user()) {
+                               // Only continue when the given profile link seems valid
+                               // Valid profile links contain a path with "/profile/" and no query parameters
+                               if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "") &&
+                                       strstr(parse_url($_GET['zrl'], PHP_URL_PATH), "/profile/")) {
+                                       if (defaults($_SESSION, "visitor_home", "") != $_GET["zrl"]) {
+                                               $_SESSION['my_url'] = $_GET['zrl'];
+                                               $_SESSION['authenticated'] = 0;
+                                       }
+                                       Model\Profile::zrlInit($this);
+                               } else {
+                                       // Someone came with an invalid parameter, maybe as a DDoS attempt
+                                       // We simply stop processing here
+                                       logger("Invalid ZRL parameter " . $_GET['zrl'], LOGGER_DEBUG);
+                                       Core\System::httpExit(403, ['title' => '403 Forbidden']);
+                               }
+                       }
+               }
+
+               if (!empty($_GET['owt']) && $this->getMode()->isNormal()) {
+                       $token = $_GET['owt'];
+                       $this->query_string = Model\Profile::stripQueryParam($this->query_string, 'owt');
+                       Model\Profile::openWebAuthInit($token);
+               }
+
+               Module\Login::sessionAuth();
+
+               if (empty($_SESSION['authenticated'])) {
+                       header('X-Account-Management-Status: none');
+               }
+
+               $_SESSION['sysmsg']       = defaults($_SESSION, 'sysmsg'      , []);
+               $_SESSION['sysmsg_info']  = defaults($_SESSION, 'sysmsg_info' , []);
+               $_SESSION['last_updated'] = defaults($_SESSION, 'last_updated', []);
+
+               /*
+                * check_config() is responsible for running update scripts. These automatically
+                * update the DB schema whenever we push a new one out. It also checks to see if
+                * any addons have been added or removed and reacts accordingly.
+                */
+
+               // in install mode, any url loads install module
+               // but we need "view" module for stylesheet
+               if ($this->getMode()->isInstall() && $this->module != 'view') {
+                       $this->module = 'install';
+               } elseif (!$this->getMode()->has(App\Mode::MAINTENANCEDISABLED) && $this->module != 'view') {
+                       $this->module = 'maintenance';
+               } else {
+                       $this->checkURL();
+                       check_db(false);
+                       Core\Addon::loadAddons();
+                       Core\Hook::loadHooks();
+               }
+
+               $this->page = [
+                       'aside' => '',
+                       'bottom' => '',
+                       'content' => '',
+                       'footer' => '',
+                       'htmlhead' => '',
+                       'nav' => '',
+                       'page_title' => '',
+                       'right_aside' => '',
+                       'template' => '',
+                       'title' => ''
+               ];
+
+               if (strlen($this->module)) {
+                       // Compatibility with the Android Diaspora client
+                       if ($this->module == 'stream') {
+                               $this->internalRedirect('network?f=&order=post');
+                       }
+
+                       if ($this->module == 'conversations') {
+                               $this->internalRedirect('message');
+                       }
+
+                       if ($this->module == 'commented') {
+                               $this->internalRedirect('network?f=&order=comment');
+                       }
+
+                       if ($this->module == 'liked') {
+                               $this->internalRedirect('network?f=&order=comment');
+                       }
+
+                       if ($this->module == 'activity') {
+                               $this->internalRedirect('network/?f=&conv=1');
+                       }
+
+                       if (($this->module == 'status_messages') && ($this->cmd == 'status_messages/new')) {
+                               $this->internalRedirect('bookmarklet');
+                       }
+
+                       if (($this->module == 'user') && ($this->cmd == 'user/edit')) {
+                               $this->internalRedirect('settings');
+                       }
+
+                       if (($this->module == 'tag_followings') && ($this->cmd == 'tag_followings/manage')) {
+                               $this->internalRedirect('search');
+                       }
+
+                       // Compatibility with the Firefox App
+                       if (($this->module == "users") && ($this->cmd == "users/sign_in")) {
+                               $this->module = "login";
+                       }
+
+                       $privateapps = Core\Config::get('config', 'private_addons', false);
+                       if (Core\Addon::isEnabled($this->module) && file_exists("addon/{$this->module}/{$this->module}.php")) {
+                               //Check if module is an app and if public access to apps is allowed or not
+                               if ((!local_user()) && Core\Hook::isAddonApp($this->module) && $privateapps) {
+                                       info(Core\L10n::t("You must be logged in to use addons. "));
+                               } else {
+                                       include_once "addon/{$this->module}/{$this->module}.php";
+                                       if (function_exists($this->module . '_module')) {
+                                               LegacyModule::setModuleFile("addon/{$this->module}/{$this->module}.php");
+                                               $this->module_class = 'Friendica\\LegacyModule';
+                                               $this->module_loaded = true;
+                                       }
+                               }
+                       }
+
+                       // Controller class routing
+                       if (! $this->module_loaded && class_exists('Friendica\\Module\\' . ucfirst($this->module))) {
+                               $this->module_class = 'Friendica\\Module\\' . ucfirst($this->module);
+                               $this->module_loaded = true;
+                       }
+
+                       /* If not, next look for a 'standard' program module in the 'mod' directory
+                        * We emulate a Module class through the LegacyModule class
+                        */
+                       if (! $this->module_loaded && file_exists("mod/{$this->module}.php")) {
+                               LegacyModule::setModuleFile("mod/{$this->module}.php");
+                               $this->module_class = 'Friendica\\LegacyModule';
+                               $this->module_loaded = true;
+                       }
+
+                       /* The URL provided does not resolve to a valid module.
+                        *
+                        * On Dreamhost sites, quite often things go wrong for no apparent reason and they send us to '/internal_error.html'.
+                        * We don't like doing this, but as it occasionally accounts for 10-20% or more of all site traffic -
+                        * we are going to trap this and redirect back to the requested page. As long as you don't have a critical error on your page
+                        * this will often succeed and eventually do the right thing.
+                        *
+                        * Otherwise we are going to emit a 404 not found.
+                        */
+                       if (! $this->module_loaded) {
+                               // Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit.
+                               if (!empty($_SERVER['QUERY_STRING']) && preg_match('/{[0-9]}/', $_SERVER['QUERY_STRING']) !== 0) {
+                                       exit();
+                               }
+
+                               if (!empty($_SERVER['QUERY_STRING']) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
+                                       logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI']);
+                                       $this->internalRedirect($_SERVER['REQUEST_URI']);
+                               }
+
+                               logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG);
+
+                               header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . Core\L10n::t('Not Found'));
+                               $tpl = get_markup_template("404.tpl");
+                               $this->page['content'] = replace_macros($tpl, [
+                                       '$message' =>  Core\L10n::t('Page not found.')
+                               ]);
+                       }
+               }
+
+               // Load current theme info
+               $theme_info_file = 'view/theme/' . $this->getCurrentTheme() . '/theme.php';
+               if (file_exists($theme_info_file)) {
+                       require_once $theme_info_file;
+               }
+
+               // initialise content region
+               if ($this->getMode()->isNormal()) {
+                       Core\Addon::callHooks('page_content_top', $this->page['content']);
+               }
+
+               // Call module functions
+               if ($this->module_loaded) {
+                       $this->page['page_title'] = $this->module;
+                       $placeholder = '';
+
+                       Core\Addon::callHooks($this->module . '_mod_init', $placeholder);
+
+                       call_user_func([$this->module_class, 'init']);
+
+                       // "rawContent" is especially meant for technical endpoints.
+                       // This endpoint doesn't need any theme initialization or other comparable stuff.
+                       if (!$this->error) {
+                               call_user_func([$this->module_class, 'rawContent']);
+                       }
+
+                       if (function_exists(str_replace('-', '_', $this->getCurrentTheme()) . '_init')) {
+                               $func = str_replace('-', '_', $this->getCurrentTheme()) . '_init';
+                               $func($this);
+                       }
+
+                       if (! $this->error && $_SERVER['REQUEST_METHOD'] === 'POST') {
+                               Core\Addon::callHooks($this->module . '_mod_post', $_POST);
+                               call_user_func([$this->module_class, 'post']);
+                       }
+
+                       if (! $this->error) {
+                               Core\Addon::callHooks($this->module . '_mod_afterpost', $placeholder);
+                               call_user_func([$this->module_class, 'afterpost']);
+                       }
+
+                       if (! $this->error) {
+                               $arr = ['content' => $this->page['content']];
+                               Core\Addon::callHooks($this->module . '_mod_content', $arr);
+                               $this->page['content'] = $arr['content'];
+                               $arr = ['content' => call_user_func([$this->module_class, 'content'])];
+                               Core\Addon::callHooks($this->module . '_mod_aftercontent', $arr);
+                               $this->page['content'] .= $arr['content'];
+                       }
+
+                       if (function_exists(str_replace('-', '_', $this->getCurrentTheme()) . '_content_loaded')) {
+                               $func = str_replace('-', '_', $this->getCurrentTheme()) . '_content_loaded';
+                               $func($this);
+                       }
+               }
+
+               /* Create the page head after setting the language
+                * and getting any auth credentials.
+                *
+                * Moved initHead() and initFooter() to after
+                * all the module functions have executed so that all
+                * theme choices made by the modules can take effect.
+                */
+               $this->initHead();
+
+               /* Build the page ending -- this is stuff that goes right before
+                * the closing </body> tag
+                */
+               $this->initFooter();
+
+               /* now that we've been through the module content, see if the page reported
+                * a permission problem and if so, a 403 response would seem to be in order.
+                */
+               if (stristr(implode("", $_SESSION['sysmsg']), Core\L10n::t('Permission denied'))) {
+                       header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . Core\L10n::t('Permission denied.'));
+               }
+
+               // Report anything which needs to be communicated in the notification area (before the main body)
+               Core\Addon::callHooks('page_end', $this->page['content']);
+
+               // Add the navigation (menu) template
+               if ($this->module != 'install' && $this->module != 'maintenance') {
+                       $this->page['htmlhead'] .= replace_macros(get_markup_template('nav_head.tpl'), []);
+                       $this->page['nav']       = Content\Nav::build($this);
+               }
+
+               // Build the page - now that we have all the components
+               if (isset($_GET["mode"]) && (($_GET["mode"] == "raw") || ($_GET["mode"] == "minimal"))) {
+                       $doc = new DOMDocument();
+
+                       $target = new DOMDocument();
+                       $target->loadXML("<root></root>");
+
+                       $content = mb_convert_encoding($this->page["content"], 'HTML-ENTITIES', "UTF-8");
+
+                       /// @TODO one day, kill those error-surpressing @ stuff, or PHP should ban it
+                       @$doc->loadHTML($content);
+
+                       $xpath = new DOMXPath($doc);
+
+                       $list = $xpath->query("//*[contains(@id,'tread-wrapper-')]");  /* */
+
+                       foreach ($list as $item) {
+                               $item = $target->importNode($item, true);
+
+                               // And then append it to the target
+                               $target->documentElement->appendChild($item);
+                       }
+               }
+
+               if (isset($_GET["mode"]) && ($_GET["mode"] == "raw")) {
+                       header("Content-type: text/html; charset=utf-8");
+
+                       echo substr($target->saveHTML(), 6, -8);
+
+                       exit();
+               }
+
+               $page    = $this->page;
+               $profile = $this->profile;
+
+               header("X-Friendica-Version: " . FRIENDICA_VERSION);
+               header("Content-type: text/html; charset=utf-8");
+
+               if (Core\Config::get('system', 'hsts') && (Core\Config::get('system', 'ssl_policy') == SSL_POLICY_FULL)) {
+                       header("Strict-Transport-Security: max-age=31536000");
+               }
+
+               // Some security stuff
+               header('X-Content-Type-Options: nosniff');
+               header('X-XSS-Protection: 1; mode=block');
+               header('X-Permitted-Cross-Domain-Policies: none');
+               header('X-Frame-Options: sameorigin');
+
+               // Things like embedded OSM maps don't work, when this is enabled
+               // header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; connect-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'; img-src 'self' https: data:; media-src 'self' https:; child-src 'self' https:; object-src 'none'");
+
+               /* We use $_GET["mode"] for special page templates. So we will check if we have
+                * to load another page template than the default one.
+                * The page templates are located in /view/php/ or in the theme directory.
+                */
+               if (isset($_GET["mode"])) {
+                       $template = Core\Theme::getPathForFile($_GET["mode"] . '.php');
+               }
+
+               // If there is no page template use the default page template
+               if (empty($template)) {
+                       $template = Core\Theme::getPathForFile("default.php");
+               }
+
+               // Theme templates expect $a as an App instance
+               $a = $this;
+
+               /// @TODO Looks unsafe (remote-inclusion), is maybe not but Core\Theme::getPathForFile() uses file_exists() but does not escape anything
+               require_once $template;
+       }
+
+       /**
+        * Redirects to another module relative to the current Friendica base.
+        * If you want to redirect to a external URL, use System::externalRedirectTo()
+        *
+        * @param string $toUrl The destination URL (Default is empty, which is the default page of the Friendica node)
+        * @param bool $ssl if true, base URL will try to get called with https:// (works just for relative paths)
+        *
+        * @throws InternalServerErrorException In Case the given URL is not relative to the Friendica node
+        */
+       public function internalRedirect($toUrl = '', $ssl = false)
+       {
+               if (filter_var($toUrl, FILTER_VALIDATE_URL)) {
+                       throw new InternalServerErrorException("'$toUrl is not a relative path, please use System::externalRedirectTo");
+               }
+
+               $redirectTo = $this->getBaseURL($ssl) . '/' . ltrim($toUrl, '/');
+               Core\System::externalRedirect($redirectTo);
+       }
 }
index 1da9397a7833da42e8ab778f8268544c02344f17..522f0b783fa0f3fa2bcddd7801330ed8b2a118da 100644 (file)
@@ -2,6 +2,9 @@
 
 namespace Friendica;
 
+use Friendica\Core\L10n;
+use Friendica\Core\System;
+
 /**
  * All modules in Friendica should extend BaseModule, although not all modules
  * need to extend all the methods described here
@@ -57,7 +60,8 @@ abstract class BaseModule extends BaseObject
         */
        public static function post()
        {
-               // goaway('module');
+               // $a = self::getApp();
+               // $a->internalRedirect('module');
        }
 
        /**
@@ -69,4 +73,84 @@ abstract class BaseModule extends BaseObject
        {
 
        }
+
+       /*
+        * Functions used to protect against Cross-Site Request Forgery
+        * The security token has to base on at least one value that an attacker can't know - here it's the session ID and the private key.
+        * In this implementation, a security token is reusable (if the user submits a form, goes back and resubmits the form, maybe with small changes;
+        * or if the security token is used for ajax-calls that happen several times), but only valid for a certain amout of time (3hours).
+        * The "typename" seperates the security tokens of different types of forms. This could be relevant in the following case:
+        *    A security token is used to protekt a link from CSRF (e.g. the "delete this profile"-link).
+        *    If the new page contains by any chance external elements, then the used security token is exposed by the referrer.
+        *    Actually, important actions should not be triggered by Links / GET-Requests at all, but somethimes they still are,
+        *    so this mechanism brings in some damage control (the attacker would be able to forge a request to a form of this type, but not to forms of other types).
+        */
+       public static function getFormSecurityToken($typename = '')
+       {
+               $a = get_app();
+
+               $timestamp = time();
+               $sec_hash = hash('whirlpool', $a->user['guid'] . $a->user['prvkey'] . session_id() . $timestamp . $typename);
+
+               return $timestamp . '.' . $sec_hash;
+       }
+
+       public static function checkFormSecurityToken($typename = '', $formname = 'form_security_token')
+       {
+               $hash = null;
+
+               if (!empty($_REQUEST[$formname])) {
+                       /// @TODO Careful, not secured!
+                       $hash = $_REQUEST[$formname];
+               }
+
+               if (!empty($_SERVER['HTTP_X_CSRF_TOKEN'])) {
+                       /// @TODO Careful, not secured!
+                       $hash = $_SERVER['HTTP_X_CSRF_TOKEN'];
+               }
+
+               if (empty($hash)) {
+                       return false;
+               }
+
+               $max_livetime = 10800; // 3 hours
+
+               $a = get_app();
+
+               $x = explode('.', $hash);
+               if (time() > (IntVal($x[0]) + $max_livetime)) {
+                       return false;
+               }
+
+               $sec_hash = hash('whirlpool', $a->user['guid'] . $a->user['prvkey'] . session_id() . $x[0] . $typename);
+
+               return ($sec_hash == $x[1]);
+       }
+
+       public static function getFormSecurityStandardErrorMessage()
+       {
+               return L10n::t("The form security token was not correct. This probably happened because the form has been opened for too long \x28>3 hours\x29 before submitting it.") . EOL;
+       }
+
+       public static function checkFormSecurityTokenRedirectOnError($err_redirect, $typename = '', $formname = 'form_security_token')
+       {
+               if (!self::checkFormSecurityToken($typename, $formname)) {
+                       $a = get_app();
+                       logger('checkFormSecurityToken failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
+                       logger('checkFormSecurityToken failed: _REQUEST data: ' . print_r($_REQUEST, true), LOGGER_DATA);
+                       notice(self::getFormSecurityStandardErrorMessage());
+                       $a->internalRedirect($err_redirect);
+               }
+       }
+
+       public static function checkFormSecurityTokenForbiddenOnError($typename = '', $formname = 'form_security_token')
+       {
+               if (!self::checkFormSecurityToken($typename, $formname)) {
+                       $a = get_app();
+                       logger('checkFormSecurityToken failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
+                       logger('checkFormSecurityToken failed: _REQUEST data: ' . print_r($_REQUEST, true), LOGGER_DATA);
+                       header('HTTP/1.1 403 Forbidden');
+                       killme();
+               }
+       }
 }
index 4f6f4ae0b905adc3832da6e8abf56db386922ff3..8289825eade47587a67017f7bcee64be49542134 100644 (file)
@@ -15,50 +15,102 @@ use Friendica\Model\Contact;
 use Friendica\Model\Profile;
 
 require_once 'boot.php';
-require_once 'dba.php';
 require_once 'include/text.php';
 
 class Nav
 {
+       private static $selected = [
+               'global'    => null,
+               'community' => null,
+               'network'   => null,
+               'home'      => null,
+               'profiles'  => null,
+               'introductions' => null,
+               'notifications' => null,
+               'messages'  => null,
+               'directory' => null,
+               'settings'  => null,
+               'contacts'  => null,
+               'manage'    => null,
+               'events'    => null,
+               'register'  => null
+       ];
+
+       /**
+        * An array of HTML links provided by addons providing a module via the app_menu hook
+        *
+        * @var array
+        */
+       private static $app_menu = null;
+
+       /**
+        * Set a menu item in navbar as selected
+        */
+       public static function setSelected($item)
+       {
+               self::$selected[$item] = 'selected';
+       }
+
        /**
         * Build page header and site navigation bars
         */
        public static function build(App $a)
        {
-               if (!(x($a->page, 'nav'))) {
-                       $a->page['nav'] = '';
-               }
-
-               $a->page['htmlhead'] .= replace_macros(get_markup_template('nav_head.tpl'), []);
-
-               /*
-                * Placeholder div for popup panel
-                */
-
-               $a->page['nav'] .= '<div id="panel" style="display: none;"></div>' ;
+               // Placeholder div for popup panel
+               $nav = '<div id="panel" style="display: none;"></div>' ;
 
                $nav_info = self::getInfo($a);
 
-               /*
-                * Build the page
-                */
-
                $tpl = get_markup_template('nav.tpl');
 
-               $a->page['nav'] .= replace_macros($tpl, [
-                       '$baseurl' => System::baseUrl(),
+               $nav .= replace_macros($tpl, [
+                       '$baseurl'      => System::baseUrl(),
                        '$sitelocation' => $nav_info['sitelocation'],
-                       '$nav' => $nav_info['nav'],
-                       '$banner' => $nav_info['banner'],
+                       '$nav'          => $nav_info['nav'],
+                       '$banner'       => $nav_info['banner'],
                        '$emptynotifications' => L10n::t('Nothing new here'),
-                       '$userinfo' => $nav_info['userinfo'],
-                       '$sel' =>  $a->nav_sel,
-                       '$apps' => $a->apps,
+                       '$userinfo'     => $nav_info['userinfo'],
+                       '$sel'          => self::$selected,
+                       '$apps'         => self::getAppMenu(),
                        '$clear_notifs' => L10n::t('Clear notifications'),
-                       '$search_hint' => L10n::t('@name, !forum, #tags, content')
+                       '$search_hint'  => L10n::t('@name, !forum, #tags, content')
                ]);
 
-               Addon::callHooks('page_header', $a->page['nav']);
+               Addon::callHooks('page_header', $nav);
+
+               return $nav;
+       }
+
+       /**
+        * Returns the addon app menu
+        *
+        * @return array
+        */
+       public static function getAppMenu()
+       {
+               if (is_null(self::$app_menu)) {
+                       self::populateAppMenu();
+               }
+
+               return self::$app_menu;
+       }
+
+       /**
+        * Fills the apps static variable with apps that require a menu
+        */
+       private static function populateAppMenu()
+       {
+               self::$app_menu = [];
+
+               //Don't populate apps_menu if apps are private
+               $privateapps = Config::get('config', 'private_addons', false);
+               if (local_user() || !$privateapps) {
+                       $arr = ['app_menu' => self::$app_menu];
+
+                       Addon::callHooks('app_menu', $arr);
+
+                       self::$app_menu = $arr['app_menu'];
+               }
        }
 
        /**
@@ -134,7 +186,7 @@ class Nav
                        $nav['help'] = [$help_url, L10n::t('Help'), '', L10n::t('Help and documentation')];
                }
 
-               if (count($a->apps) > 0) {
+               if (count(self::getAppMenu()) > 0) {
                        $nav['apps'] = ['apps', L10n::t('Apps'), '', L10n::t('Addon applications, utilities, games')];
                }
 
@@ -235,29 +287,4 @@ class Nav
                        'userinfo' => $userinfo,
                ];
        }
-
-       /**
-        * Set a menu item in navbar as selected
-        */
-       public static function setSelected($item)
-       {
-               $a = get_app();
-               $a->nav_sel = [
-                       'global'        => null,
-                       'community'     => null,
-                       'network'       => null,
-                       'home'          => null,
-                       'profiles'      => null,
-                       'introductions' => null,
-                       'notifications' => null,
-                       'messages'      => null,
-                       'directory'     => null,
-                       'settings'      => null,
-                       'contacts'      => null,
-                       'manage'        => null,
-                       'events'        => null,
-                       'register'      => null
-               ];
-               $a->nav_sel[$item] = 'selected';
-       }
 }
index 116120ab552474c4dfe3e8132ea995bb76716293..cfe9468ad57a58a0f893b0fb9d16522aa59e60fc 100644 (file)
@@ -120,9 +120,9 @@ class OEmbed
                                        'content' => $json_string,
                                        'created' => DateTimeFormat::utcNow()
                                ], true);
-                               $cache_ttl = CACHE_DAY;
+                               $cache_ttl = Cache::DAY;
                        } else {
-                               $cache_ttl = CACHE_FIVE_MINUTES;
+                               $cache_ttl = Cache::FIVE_MINUTES;
                        }
 
                        Cache::set($cache_key, $json_string, $cache_ttl);
index c903ee6945790fcd96e85c476af168c4ff124c91..be2054067b25b68a9a898e9f732a524390cd11db 100644 (file)
@@ -859,187 +859,140 @@ class BBCode extends BaseObject
        }
 
        /**
-        * Processes [share] tags
+        * This function converts a [share] block to text according to a provided callback function whose signature is:
         *
-        * Note: Can produce a [bookmark] tag in the output
+        * function(array $attributes, array $author_contact, string $content, boolean $is_quote_share): string
         *
-        * @brief Processes [share] tags
-        * @param array    $share      preg_match_callback result array
-        * @param bool|int $simplehtml
-        * @return string
+        * Where:
+        * - $attributes is an array of attributes of the [share] block itself. Missing keys will be completed by the contact
+        * data lookup
+        * - $author_contact is a contact record array
+        * - $content is the inner content of the [share] block
+        * - $is_quote_share indicates whether there's any content before the [share] block
+        * - Return value is the string that should replace the [share] block in the provided text
+        *
+        * This function is intended to be used by addon connector to format a share block like the target network is expecting it.
+        *
+        * @param  string   $text     A BBCode string
+        * @param  callable $callback
+        * @return string The BBCode string with all [share] blocks replaced
         */
-       private static function convertShare($share, $simplehtml)
+       public static function convertShare($text, callable $callback)
        {
-               $attributes = $share[2];
-
-               $author = "";
-               preg_match("/author='(.*?)'/ism", $attributes, $matches);
-               if (x($matches, 1)) {
-                       $author = html_entity_decode($matches[1], ENT_QUOTES, 'UTF-8');
-               }
-
-               preg_match('/author="(.*?)"/ism', $attributes, $matches);
-               if (x($matches, 1)) {
-                       $author = $matches[1];
-               }
-
-               $profile = "";
-               preg_match("/profile='(.*?)'/ism", $attributes, $matches);
-               if (x($matches, 1)) {
-                       $profile = $matches[1];
-               }
-
-               preg_match('/profile="(.*?)"/ism', $attributes, $matches);
-               if (x($matches, 1)) {
-                       $profile = $matches[1];
-               }
-
-               $avatar = "";
-               preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
-               if (x($matches, 1)) {
-                       $avatar = $matches[1];
-               }
-
-               preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
-               if (x($matches, 1)) {
-                       $avatar = $matches[1];
-               }
-
-               $link = "";
-               preg_match("/link='(.*?)'/ism", $attributes, $matches);
-               if (x($matches, 1)) {
-                       $link = $matches[1];
-               }
-
-               preg_match('/link="(.*?)"/ism', $attributes, $matches);
-               if (x($matches, 1)) {
-                       $link = $matches[1];
-               }
-
-               $posted = "";
-
-               preg_match("/posted='(.*?)'/ism", $attributes, $matches);
-               if (x($matches, 1)) {
-                       $posted = $matches[1];
-               }
-
-               preg_match('/posted="(.*?)"/ism', $attributes, $matches);
-               if (x($matches, 1)) {
-                       $posted = $matches[1];
-               }
+               $return = preg_replace_callback(
+                       "/(.*?)\[share(.*?)\](.*?)\[\/share\]/ism",
+                       function ($match) use ($callback) {
+                               $attribute_string = $match[2];
+
+                               $attributes = [];
+                               foreach(['author', 'profile', 'avatar', 'link', 'posted'] as $field) {
+                                       preg_match("/$field=(['\"])(.+?)\\1/ism", $attribute_string, $matches);
+                                       $attributes[$field] = html_entity_decode(defaults($matches, 2, ''), ENT_QUOTES, 'UTF-8');
+                               }
 
-               // We only call this so that a previously unknown contact can be added.
-               // This is important for the function "Model\Contact::getDetailsByURL()".
-               // This function then can fetch an entry from the contact table.
-               Contact::getIdForURL($profile, 0, true);
+                               // We only call this so that a previously unknown contact can be added.
+                               // This is important for the function "Model\Contact::getDetailsByURL()".
+                               // This function then can fetch an entry from the contact table.
+                               Contact::getIdForURL($attributes['profile'], 0, true);
 
-               $data = Contact::getDetailsByURL($profile);
+                               $author_contact = Contact::getDetailsByURL($attributes['profile']);
+                               $author_contact['addr'] = defaults($author_contact, 'addr' , Protocol::getAddrFromProfileUrl($attributes['profile']));
 
-               if (x($data, "name") && x($data, "addr")) {
-                       $userid_compact = $data["name"] . " (" . $data["addr"] . ")";
-               } else {
-                       $userid_compact = Protocol::getAddrFromProfileUrl($profile, $author);
-               }
+                               $attributes['author']   = defaults($author_contact, 'name' , $attributes['author']);
+                               $attributes['avatar']   = defaults($author_contact, 'micro', $attributes['avatar']);
+                               $attributes['profile']  = defaults($author_contact, 'url'  , $attributes['profile']);
 
-               if (x($data, "addr")) {
-                       $userid = $data["addr"];
-               } else {
-                       $userid = Protocol::formatMention($profile, $author);
-               }
+                               if ($attributes['avatar']) {
+                                       $attributes['avatar'] = ProxyUtils::proxifyUrl($attributes['avatar'], false, ProxyUtils::SIZE_THUMB);
+                               }
 
-               if (x($data, "name")) {
-                       $author = $data["name"];
-               }
+                               return $match[1] . $callback($attributes, $author_contact, $match[3], trim($match[1]) != '');
+                       },
+                       $text
+               );
 
-               if (x($data, "micro")) {
-                       $avatar = $data["micro"];
-               }
+               return $return;
+       }
 
-               $preshare = trim($share[1]);
-               if ($preshare != "") {
-                       $preshare .= "<br />";
-               }
+       /**
+        * Default [share] tag conversion callback
+        *
+        * Note: Can produce a [bookmark] tag in the output
+        *
+        * @see BBCode::convertShare()
+        * @param array   $attributes     [share] block attribute values
+        * @param array   $author_contact Contact row of the shared author
+        * @param string  $content        Inner content of the [share] block
+        * @param boolean $is_quote_share Whether there is content before the [share] block
+        * @param integer $simplehtml     Mysterious integer value depending on the target network/formatting style
+        * @return string
+        */
+       private static function convertShareCallback(array $attributes, array $author_contact, $content, $is_quote_share, $simplehtml)
+       {
+               $mention = Protocol::formatMention($attributes['profile'], $attributes['author']);
 
                switch ($simplehtml) {
                        case 1:
-                               $text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . ' <a href="' . $profile . '">' . $userid . "</a>: <br />»" . $share[3] . "«";
+                               $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' <a href="' . $attributes['profile'] . '">' . $mention . '</a>: </p>' . "\n" . '«' . $content . '»';
                                break;
                        case 2:
-                               $text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . ' ' . $userid_compact . ": <br />" . $share[3];
+                               $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ': </p>' . "\n" . $content;
                                break;
                        case 3: // Diaspora
-                               $headline = '<b>' . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . $userid . ':</b><br />';
-
-                               $text = trim($share[1]);
-
-                               if ($text != "") {
-                                       $text .= "<hr />";
-                               }
+                               $headline = '<p><b>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . $mention . ':</b></p>' . "\n";
 
-                               if (stripos(normalise_link($link), 'http://twitter.com/') === 0) {
-                                       $text .= '<br /><a href="' . $link . '">' . $link . '</a>';
+                               if (stripos(normalise_link($attributes['link']), 'http://twitter.com/') === 0) {
+                                       $text = ($is_quote_share? '<hr />' : '') . '<p><a href="' . $attributes['link'] . '">' . $attributes['link'] . '</a></p>' . "\n";
                                } else {
-                                       $text .= $headline . '<blockquote>' . trim($share[3]) . "</blockquote><br />";
+                                       $text = ($is_quote_share? '<hr />' : '') . $headline . '<blockquote>' . trim($content) . '</blockquote>' . "\n";
 
-                                       if ($link != "") {
-                                               $text .= '<br /><a href="' . $link . '">[l]</a>';
+                                       if ($attributes['link'] != '') {
+                                               $text .= '<p><a href="' . $attributes['link'] . '">[l]</a></p>' . "\n";
                                        }
                                }
 
                                break;
                        case 4:
-                               $headline = '<br /><b>' . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8');
-                               $headline .= L10n::t('<a href="%1$s" target="_blank">%2$s</a> %3$s', $link, $userid, $posted);
-                               $headline .= ":</b><br />";
+                               $headline = '<p><b>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8');
+                               $headline .= L10n::t('<a href="%1$s" target="_blank">%2$s</a> %3$s', $attributes['link'], $mention, $attributes['posted']);
+                               $headline .= ':</b></p>' . "\n";
 
-                               $text = trim($share[1]);
-
-                               if ($text != "") {
-                                       $text .= "<hr />";
-                               }
-
-                               $text .= $headline . '<blockquote class="shared_content">' . trim($share[3]) . "</blockquote><br />";
+                               $text = ($is_quote_share? '<hr />' : '') . $headline . '<blockquote class="shared_content">' . trim($content) . '</blockquote>' . "\n";
 
                                break;
                        case 5:
-                               $text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . ' ' . $userid_compact . ": <br />" . $share[3];
+                               $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ': </p>' . "\n" . $content;
                                break;
                        case 7: // statusnet/GNU Social
-                               $text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . " @" . $userid_compact . ": " . $share[3];
-                               break;
-                       case 8: // twitter
-                               $text = $preshare . "RT @" . $userid_compact . ": " . $share[3];
+                               $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' @' . $author_contact['addr'] . ': ' . $content . '</p>' . "\n";
                                break;
                        case 9: // Google+
-                               $text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . ' ' . $userid_compact . ": <br />" . $share[3];
+                               $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ': </p>' . "\n";
+                               $text .= '<p>' . $content . '</p>' . "\n";
 
-                               if ($link != "") {
-                                       $text .= "<br /><br />" . $link;
+                               if ($attributes['link'] != '') {
+                                       $text .= '<p>' . $attributes['link'] . '</p>';
                                }
                                break;
                        default:
                                // Transforms quoted tweets in rich attachments to avoid nested tweets
-                               if (stripos(normalise_link($link), 'http://twitter.com/') === 0 && OEmbed::isAllowedURL($link)) {
+                               if (stripos(normalise_link($attributes['link']), 'http://twitter.com/') === 0 && OEmbed::isAllowedURL($attributes['link'])) {
                                        try {
-                                               $oembed = OEmbed::getHTML($link, $preshare);
+                                               $text = ($is_quote_share? '<br />' : '') . OEmbed::getHTML($attributes['link']);
                                        } catch (Exception $e) {
-                                               $oembed = sprintf('[bookmark=%s]%s[/bookmark]', $link, $preshare);
+                                               $text = ($is_quote_share? '<br />' : '') . sprintf('[bookmark=%s]%s[/bookmark]', $attributes['link'], $content);
                                        }
-
-                                       $text = $preshare . $oembed;
                                } else {
-                                       $text = trim($share[1]) . "\n";
-
-                                       $avatar = ProxyUtils::proxifyUrl($avatar, false, ProxyUtils::SIZE_THUMB);
+                                       $text = ($is_quote_share? "\n" : '');
 
                                        $tpl = get_markup_template('shared_content.tpl');
                                        $text .= replace_macros($tpl, [
-                                               '$profile' => $profile,
-                                               '$avatar' => $avatar,
-                                               '$author' => $author,
-                                               '$link' => $link,
-                                               '$posted' => $posted,
-                                               '$content' => trim($share[3])
+                                               '$profile' => $attributes['profile'],
+                                               '$avatar'  => $attributes['avatar'],
+                                               '$author'  => $attributes['author'],
+                                               '$link'    => $attributes['link'],
+                                               '$posted'  => $attributes['posted'],
+                                               '$content' => trim($content)
                                        ]);
                                }
                                break;
@@ -1366,7 +1319,7 @@ class BBCode extends BaseObject
 
                // Handle Diaspora posts
                $text = preg_replace_callback(
-                       "&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi",
+                       "&\[url=/?posts/([^\[\]]*)\](.*)\[\/url\]&Usi",
                        function ($match) {
                                return "[url=" . System::baseUrl() . "/display/" . $match[1] . "]" . $match[2] . "[/url]";
                        }, $text
@@ -1621,10 +1574,12 @@ class BBCode extends BaseObject
                $text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '<img src="$1" alt="' . L10n::t('Image/photo') . '" />', $text);
 
                // Shared content
-               $text = preg_replace_callback("/(.*?)\[share(.*?)\](.*?)\[\/share\]/ism",
-                       function ($match) use ($simple_html) {
-                               return self::convertShare($match, $simple_html);
-                       }, $text);
+               $text = self::convertShare(
+                       $text,
+                       function (array $attributes, array $author_contact, $content, $is_quote_share) use ($simple_html) {
+                               return self::convertShareCallback($attributes, $author_contact, $content, $is_quote_share, $simple_html);
+                       }
+               );
 
                $text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '<br/><img src="' .System::baseUrl() . '/images/lock_icon.gif" alt="' . L10n::t('Encrypted content') . '" title="' . L10n::t('Encrypted content') . '" /><br />', $text);
                $text = preg_replace("/\[crypt(.*?)\](.*?)\[\/crypt\]/ism", '<br/><img src="' .System::baseUrl() . '/images/lock_icon.gif" alt="' . L10n::t('Encrypted content') . '" title="' . '$1' . ' ' . L10n::t('Encrypted content') . '" /><br />', $text);
index 71872830cbb6c52cf12f746e134dfb113916e5c9..309f9a5bdb4e53ad97fce9dfa6929a7b047aea74 100644 (file)
@@ -9,9 +9,10 @@ namespace Friendica\Content\Widget;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\Model\Item;
+use Friendica\Util\Security;
 
 require_once 'include/dba.php';
-require_once 'include/security.php';
 
 /**
  * TagCloud widget
@@ -73,7 +74,7 @@ class TagCloud
         */
        private static function tagadelic($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HASHTAG)
        {
-               $sql_options = item_permissions_sql($uid);
+               $sql_options = Item::getPermissionsSQLByUserId($uid);
                $limit = $count ? sprintf('LIMIT %d', intval($count)) : '';
 
                if ($flags) {
index d2f89ce279de91867fe1edf9de53c3a8c8514620..c3f559c7087720ae972df14c341039f718045f58 100644 (file)
@@ -8,15 +8,20 @@ use Friendica\App;
 use Friendica\BaseObject;
 use Friendica\Database\DBA;
 
-require_once 'include/dba.php';
-
 /**
  * Some functions to handle addons
  */
 class Addon extends BaseObject
 {
        /**
-        * @brief Synchronise addons:
+        * List of the names of enabled addons
+        *
+        * @var array
+        */
+       private static $addons = [];
+
+       /**
+        * @brief Synchronize addons:
         *
         * system.addon contains a comma-separated list of names
         * of addons which are used on this system.
@@ -27,15 +32,13 @@ class Addon extends BaseObject
         * call the install procedure and add it to the database.
         *
         */
-       public static function check()
+       public static function loadAddons()
        {
-               $a = self::getApp();
+               $installed_addons = [];
 
                $r = DBA::select('addon', [], ['installed' => 1]);
                if (DBA::isResult($r)) {
-                       $installed = DBA::toArray($r);
-               } else {
-                       $installed = [];
+                       $installed_addons = DBA::toArray($r);
                }
 
                $addons = Config::get('system', 'addon');
@@ -45,31 +48,23 @@ class Addon extends BaseObject
                        $addons_arr = explode(',', str_replace(' ', '', $addons));
                }
 
-               $a->addons = $addons_arr;
+               self::$addons = $addons_arr;
 
                $installed_arr = [];
 
-               if (count($installed)) {
-                       foreach ($installed as $i) {
-                               if (!in_array($i['name'], $addons_arr)) {
-                                       self::uninstall($i['name']);
-                               } else {
-                                       $installed_arr[] = $i['name'];
-                               }
+               foreach ($installed_addons as $addon) {
+                       if (!self::isEnabled($addon['name'])) {
+                               self::uninstall($addon['name']);
+                       } else {
+                               $installed_arr[] = $addon['name'];
                        }
                }
 
-               if (count($addons_arr)) {
-                       foreach ($addons_arr as $p) {
-                               if (!in_array($p, $installed_arr)) {
-                                       self::install($p);
-                               }
+               foreach (self::$addons as $p) {
+                       if (!in_array($p, $installed_arr)) {
+                               self::install($p);
                        }
                }
-
-               self::loadHooks();
-
-               return;
        }
 
        /**
@@ -88,6 +83,8 @@ class Addon extends BaseObject
                        $func = $addon . '_uninstall';
                        $func();
                }
+
+               unset(self::$addons[$idx]);
        }
 
        /**
@@ -110,10 +107,10 @@ class Addon extends BaseObject
                        $func = $addon . '_install';
                        $func();
 
-                       $addon_admin = (function_exists($addon."_addon_admin") ? 1 : 0);
+                       $addon_admin = (function_exists($addon . "_addon_admin") ? 1 : 0);
 
                        DBA::insert('addon', ['name' => $addon, 'installed' => true,
-                                               'timestamp' => $t, 'plugin_admin' => $addon_admin]);
+                               'timestamp' => $t, 'plugin_admin' => $addon_admin]);
 
                        // we can add the following with the previous SQL
                        // once most site tables have been updated.
@@ -122,6 +119,10 @@ class Addon extends BaseObject
                        if (file_exists('addon/' . $addon . '/.hidden')) {
                                DBA::update('addon', ['hidden' => true], ['name' => $addon]);
                        }
+
+                       if (!self::isEnabled($addon)) {
+                               self::$addons[] = $addon;
+                       }
                        return true;
                } else {
                        logger("Addons: FAILED installing " . $addon);
@@ -174,165 +175,6 @@ class Addon extends BaseObject
                }
        }
 
-       /**
-        * @brief check if addon is enabled
-        *
-        * @param string $addon
-        * @return boolean
-        */
-       public static function isEnabled($addon)
-       {
-               return DBA::exists('addon', ['installed' => true, 'name' => $addon]);
-       }
-
-
-       /**
-        * @brief registers a hook.
-        *
-        * @param string $hook the name of the hook
-        * @param string $file the name of the file that hooks into
-        * @param string $function the name of the function that the hook will call
-        * @param int $priority A priority (defaults to 0)
-        * @return mixed|bool
-        */
-       public static function registerHook($hook, $file, $function, $priority = 0)
-       {
-               $file = str_replace(self::getApp()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
-
-               $condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
-               $exists = DBA::exists('hook', $condition);
-               if ($exists) {
-                       return true;
-               }
-
-               $r = DBA::insert('hook', ['hook' => $hook, 'file' => $file, 'function' => $function, 'priority' => $priority]);
-
-               return $r;
-       }
-
-       /**
-        * @brief unregisters a hook.
-        *
-        * @param string $hook the name of the hook
-        * @param string $file the name of the file that hooks into
-        * @param string $function the name of the function that the hook called
-        * @return array
-        */
-       public static function unregisterHook($hook, $file, $function)
-       {
-               $relative_file = str_replace(self::getApp()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
-
-               // This here is only needed for fixing a problem that existed on the develop branch
-               $condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
-               DBA::delete('hook', $condition);
-
-               $condition = ['hook' => $hook, 'file' => $relative_file, 'function' => $function];
-               $r = DBA::delete('hook', $condition);
-               return $r;
-       }
-
-       /**
-        * Load hooks
-        */
-       public static function loadHooks()
-       {
-               $a = self::getApp();
-               $a->hooks = [];
-               $r = DBA::select('hook', ['hook', 'file', 'function'], [], ['order' => ['priority' => 'desc', 'file']]);
-
-               while ($rr = DBA::fetch($r)) {
-                       if (! array_key_exists($rr['hook'], $a->hooks)) {
-                               $a->hooks[$rr['hook']] = [];
-                       }
-                       $a->hooks[$rr['hook']][] = [$rr['file'],$rr['function']];
-               }
-               DBA::close($r);
-       }
-
-       /**
-        * @brief Forks a hook.
-        *
-        * Use this function when you want to fork a hook via the worker.
-        *
-        * @param string $name of the hook to call
-        * @param string|array $data to transmit to the callback handler
-        */
-       public static function forkHooks($priority, $name, $data = null)
-       {
-               $a = self::getApp();
-
-               if (is_array($a->hooks) && array_key_exists($name, $a->hooks)) {
-                       foreach ($a->hooks[$name] as $hook) {
-                               Worker::add($priority, 'ForkHook', $name, $hook, $data);
-                       }
-               }
-       }
-
-       /**
-        * @brief Calls a hook.
-        *
-        * Use this function when you want to be able to allow a hook to manipulate
-        * the provided data.
-        *
-        * @param string $name of the hook to call
-        * @param string|array &$data to transmit to the callback handler
-        */
-       public static function callHooks($name, &$data = null)
-       {
-               $a = self::getApp();
-
-               if (is_array($a->hooks) && array_key_exists($name, $a->hooks)) {
-                       foreach ($a->hooks[$name] as $hook) {
-                               self::callSingleHook($a, $name, $hook, $data);
-                       }
-               }
-       }
-
-       /**
-        * @brief Calls a single hook.
-        *
-        * @param App $a
-        * @param string         $name of the hook to call
-        * @param array          $hook Hook data
-        * @param string|array   &$data to transmit to the callback handler
-        */
-       public static function callSingleHook(App $a, $name, $hook, &$data = null)
-       {
-               // Don't run a theme's hook if the user isn't using the theme
-               if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/' . $a->getCurrentTheme()) === false) {
-                       return;
-               }
-
-               @include_once($hook[0]);
-               if (function_exists($hook[1])) {
-                       $func = $hook[1];
-                       $func($a, $data);
-               } else {
-                       // remove orphan hooks
-                       $condition = ['hook' => $name, 'file' => $hook[0], 'function' => $hook[1]];
-                       DBA::delete('hook', $condition, ['cascade' => false]);
-               }
-       }
-
-       /**
-        * check if an app_menu hook exist for addon $name.
-        * Return true if the addon is an app
-        */
-       public static function isApp($name)
-       {
-               $a = self::getApp();
-
-               if (is_array($a->hooks) && (array_key_exists('app_menu', $a->hooks))) {
-                       foreach ($a->hooks['app_menu'] as $hook) {
-                               if ($hook[0] == 'addon/'.$name.'/'.$name.'.php') {
-                                       return true;
-                               }
-                       }
-               }
-
-               return false;
-       }
-
        /**
         * @brief Parse addon comment in search of addon infos.
         *
@@ -401,4 +243,97 @@ class Addon extends BaseObject
                }
                return $info;
        }
+
+       /**
+        * Checks if the provided addon is enabled
+        *
+        * @param string $addon
+        * @return boolean
+        */
+       public static function isEnabled($addon)
+       {
+               return in_array($addon, self::$addons);
+       }
+
+       /**
+        * Returns a list of the enabled addon names
+        *
+        * @return array
+        */
+       public static function getEnabledList()
+       {
+               return self::$addons;
+       }
+
+       /**
+        * Saves the current enabled addon list in the system.addon config key
+        *
+        * @return boolean
+        */
+       public static function saveEnabledList()
+       {
+               return Config::set("system", "addon", implode(", ", self::$addons));
+       }
+
+       /**
+        * Returns the list of non-hidden enabled addon names
+        *
+        * @return array
+        */
+       public static function getVisibleList()
+       {
+               $visible_addons = [];
+               $stmt = DBA::select('addon', ['name'], ['hidden' => false, 'installed' => true]);
+               if (DBA::isResult($stmt)) {
+                       foreach (DBA::toArray($stmt) as $addon) {
+                               $visible_addons[] = $addon['name'];
+                       }
+               }
+
+               return $visible_addons;
+       }
+
+       /**
+        * Shim of Hook::register left for backward compatibility purpose.
+        *
+        * @see Hook::register
+        * @deprecated since version 2018.12
+        * @param string $hook     the name of the hook
+        * @param string $file     the name of the file that hooks into
+        * @param string $function the name of the function that the hook will call
+        * @param int    $priority A priority (defaults to 0)
+        * @return mixed|bool
+        */
+       public static function registerHook($hook, $file, $function, $priority = 0)
+       {
+               return Hook::register($hook, $file, $function, $priority);
+       }
+
+       /**
+        * Shim of Hook::unregister left for backward compatibility purpose.
+        *
+        * @see Hook::unregister
+        * @deprecated since version 2018.12
+        * @param string $hook     the name of the hook
+        * @param string $file     the name of the file that hooks into
+        * @param string $function the name of the function that the hook called
+        * @return boolean
+        */
+       public static function unregisterHook($hook, $file, $function)
+       {
+               return Hook::unregister($hook, $file, $function);
+       }
+
+       /**
+        * Shim of Hook::callAll left for backward-compatibility purpose.
+        *
+        * @see Hook::callAll
+        * @deprecated since version 2018.12
+        * @param string       $name  of the hook to call
+        * @param string|array &$data to transmit to the callback handler
+        */
+       public static function callHooks($name, &$data = null)
+       {
+               Hook::callAll($name, $data);
+       }
 }
diff --git a/src/Core/Authentication.php b/src/Core/Authentication.php
new file mode 100644 (file)
index 0000000..5371cc9
--- /dev/null
@@ -0,0 +1,212 @@
+<?php
+/**
+ * @file /src/Core/Authentication.php
+ */
+
+namespace Friendica\Core;
+
+use Friendica\BaseObject;
+use Friendica\Core\Addon;
+use Friendica\Core\Config;
+use Friendica\Core\L10n;
+use Friendica\Core\PConfig;
+use Friendica\Database\DBA;
+use Friendica\Util\DateTimeFormat;
+
+/**
+* Handle Authentification, Session and Cookies
+*/
+class Authentication extends BaseObject
+{
+       /**
+        * @brief Calculate the hash that is needed for the "Friendica" cookie
+        *
+        * @param array $user Record from "user" table
+        *
+        * @return string Hashed data
+        */
+       public static function getCookieHashForUser($user)
+       {
+               return(hash("sha256", Config::get("system", "site_prvkey") .
+                               $user["prvkey"] .
+                               $user["password"]));
+       }
+
+       /**
+        * @brief Set the "Friendica" cookie
+        *
+        * @param int $time
+        * @param array $user Record from "user" table
+        */
+       public static  function setCookie($time, $user = [])
+       {
+               if ($time != 0) {
+                       $time = $time + time();
+               }
+
+               if ($user) {
+                       $value = json_encode(["uid" => $user["uid"],
+                               "hash" => self::getCookieHashForUser($user),
+                               "ip" => defaults($_SERVER, 'REMOTE_ADDR', '0.0.0.0')]);
+               } else {
+                       $value = "";
+               }
+
+               setcookie("Friendica", $value, $time, "/", "", (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL), true);
+       }
+
+       /**
+        * @brief Sets the provided user's authenticated session
+        *
+        * @todo Should be moved to Friendica\Core\Session once it's created
+        *
+        * @param type $user_record
+        * @param type $login_initial
+        * @param type $interactive
+        * @param type $login_refresh
+        */
+       public static function setAuthenticatedSessionForUser($user_record, $login_initial = false, $interactive = false, $login_refresh = false)
+       {
+               $a = self::getApp();
+
+               $_SESSION['uid'] = $user_record['uid'];
+               $_SESSION['theme'] = $user_record['theme'];
+               $_SESSION['mobile-theme'] = PConfig::get($user_record['uid'], 'system', 'mobile_theme');
+               $_SESSION['authenticated'] = 1;
+               $_SESSION['page_flags'] = $user_record['page-flags'];
+               $_SESSION['my_url'] = $a->getbaseUrl() . '/profile/' . $user_record['nickname'];
+               $_SESSION['my_address'] = $user_record['nickname'] . '@' . substr($a->getbaseUrl(), strpos($a->getbaseUrl(), '://') + 3);
+               $_SESSION['addr'] = defaults($_SERVER, 'REMOTE_ADDR', '0.0.0.0');
+
+               $a->user = $user_record;
+
+               if ($interactive) {
+                       if ($a->user['login_date'] <= DBA::NULL_DATETIME) {
+                               $_SESSION['return_path'] = 'profile_photo/new';
+                               $a->module = 'profile_photo';
+                               info(L10n::t("Welcome ") . $a->user['username'] . EOL);
+                               info(L10n::t('Please upload a profile photo.') . EOL);
+                       } else {
+                               info(L10n::t("Welcome back ") . $a->user['username'] . EOL);
+                       }
+               }
+
+               $member_since = strtotime($a->user['register_date']);
+               if (time() < ($member_since + ( 60 * 60 * 24 * 14))) {
+                       $_SESSION['new_member'] = true;
+               } else {
+                       $_SESSION['new_member'] = false;
+               }
+               if (strlen($a->user['timezone'])) {
+                       date_default_timezone_set($a->user['timezone']);
+                       $a->timezone = $a->user['timezone'];
+               }
+
+               $master_record = $a->user;
+
+               if ((x($_SESSION, 'submanage')) && intval($_SESSION['submanage'])) {
+                       $user = DBA::selectFirst('user', [], ['uid' => $_SESSION['submanage']]);
+                       if (DBA::isResult($user)) {
+                               $master_record = $user;
+                       }
+               }
+
+               if ($master_record['parent-uid'] == 0) {
+                       // First add our own entry
+                       $a->identities = [['uid' => $master_record['uid'],
+                                       'username' => $master_record['username'],
+                                       'nickname' => $master_record['nickname']]];
+
+                       // Then add all the children
+                       $r = DBA::select('user', ['uid', 'username', 'nickname'],
+                               ['parent-uid' => $master_record['uid'], 'account_removed' => false]);
+                       if (DBA::isResult($r)) {
+                               $a->identities = array_merge($a->identities, DBA::toArray($r));
+                       }
+               } else {
+                       // Just ensure that the array is always defined
+                       $a->identities = [];
+
+                       // First entry is our parent
+                       $r = DBA::select('user', ['uid', 'username', 'nickname'],
+                               ['uid' => $master_record['parent-uid'], 'account_removed' => false]);
+                       if (DBA::isResult($r)) {
+                               $a->identities = DBA::toArray($r);
+                       }
+
+                       // Then add all siblings
+                       $r = DBA::select('user', ['uid', 'username', 'nickname'],
+                               ['parent-uid' => $master_record['parent-uid'], 'account_removed' => false]);
+                       if (DBA::isResult($r)) {
+                               $a->identities = array_merge($a->identities, DBA::toArray($r));
+                       }
+               }
+
+               $r = DBA::p("SELECT `user`.`uid`, `user`.`username`, `user`.`nickname`
+                       FROM `manage`
+                       INNER JOIN `user` ON `manage`.`mid` = `user`.`uid`
+                       WHERE `user`.`account_removed` = 0 AND `manage`.`uid` = ?",
+                       $master_record['uid']
+               );
+               if (DBA::isResult($r)) {
+                       $a->identities = array_merge($a->identities, DBA::toArray($r));
+               }
+
+               if ($login_initial) {
+                       logger('auth_identities: ' . print_r($a->identities, true), LOGGER_DEBUG);
+               }
+               if ($login_refresh) {
+                       logger('auth_identities refresh: ' . print_r($a->identities, true), LOGGER_DEBUG);
+               }
+
+               $contact = DBA::selectFirst('contact', [], ['uid' => $_SESSION['uid'], 'self' => true]);
+               if (DBA::isResult($contact)) {
+                       $a->contact = $contact;
+                       $a->cid = $contact['id'];
+                       $_SESSION['cid'] = $a->cid;
+               }
+
+               header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] . '"');
+
+               if ($login_initial || $login_refresh) {
+                       DBA::update('user', ['login_date' => DateTimeFormat::utcNow()], ['uid' => $_SESSION['uid']]);
+
+                       // Set the login date for all identities of the user
+                       DBA::update('user', ['login_date' => DateTimeFormat::utcNow()],
+                               ['parent-uid' => $master_record['uid'], 'account_removed' => false]);
+               }
+
+               if ($login_initial) {
+                       /*
+                        * If the user specified to remember the authentication, then set a cookie
+                        * that expires after one week (the default is when the browser is closed).
+                        * The cookie will be renewed automatically.
+                        * The week ensures that sessions will expire after some inactivity.
+                        */
+                       if (!empty($_SESSION['remember'])) {
+                               logger('Injecting cookie for remembered user ' . $a->user['nickname']);
+                               self::setCookie(604800, $user_record);
+                               unset($_SESSION['remember']);
+                       }
+               }
+
+               if ($login_initial) {
+                       Addon::callHooks('logged_in', $a->user);
+
+                       if (($a->module !== 'home') && isset($_SESSION['return_path'])) {
+                               $a->internalRedirect($_SESSION['return_path']);
+                       }
+               }
+       }
+
+       /**
+        * @brief Kills the "Friendica" cookie and all session data
+        */
+       public static function deleteSession()
+       {
+               self::setCookie(-3600); // make sure cookie is deleted on browser close, as a security measure
+               session_unset();
+               session_destroy();
+       }
+}
+
index 212edabcc1db21a9965203875fe9d76097fbf689..c8214b16140b967b62279062552fc907f74681af 100644 (file)
@@ -68,11 +68,6 @@ HELP;
                        throw new \RuntimeException('Database isn\'t ready or populated yet');
                }
 
-               Core\Config::load();
-
-               $lang = Core\L10n::getBrowserLanguage();
-               Core\L10n::loadTranslationTable($lang);
-
                $enabled = intval($this->getArgument(0));
 
                Core\Config::set('system', 'maintenance', $enabled);
diff --git a/src/Core/Hook.php b/src/Core/Hook.php
new file mode 100644 (file)
index 0000000..85ed98e
--- /dev/null
@@ -0,0 +1,191 @@
+<?php
+/**
+ * @file src/Core/Hook.php
+ */
+namespace Friendica\Core;
+
+use Friendica\App;
+use Friendica\BaseObject;
+use Friendica\Database\DBA;
+
+/**
+ * Some functions to handle hooks
+ */
+class Hook extends BaseObject
+{
+       /**
+        * Array of registered hooks
+        *
+        * Format:
+        * [
+        *              ["<hook name>"] => [
+        *                      0 => "<hook file>",
+        *                      1 => "<hook function name>"
+        *              ],
+        *              ...
+        * ]
+        *
+        * @var array
+        */
+       private static $hooks = [];
+
+       /**
+        * Load hooks
+        */
+       public static function loadHooks()
+       {
+               self::$hooks = [];
+               $stmt = DBA::select('hook', ['hook', 'file', 'function'], [], ['order' => ['priority' => 'desc', 'file']]);
+
+               while ($hook = DBA::fetch($stmt)) {
+                       if (!array_key_exists($hook['hook'], self::$hooks)) {
+                               self::$hooks[$hook['hook']] = [];
+                       }
+                       self::$hooks[$hook['hook']][] = [$hook['file'], $hook['function']];
+               }
+               DBA::close($stmt);
+       }
+
+       /**
+        * Registers a hook.
+        *
+        * @param string $hook     the name of the hook
+        * @param string $file     the name of the file that hooks into
+        * @param string $function the name of the function that the hook will call
+        * @param int    $priority A priority (defaults to 0)
+        * @return mixed|bool
+        */
+       public static function register($hook, $file, $function, $priority = 0)
+       {
+               $file = str_replace(self::getApp()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
+
+               $condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
+               if (DBA::exists('hook', $condition)) {
+                       return true;
+               }
+
+               $result = DBA::insert('hook', ['hook' => $hook, 'file' => $file, 'function' => $function, 'priority' => $priority]);
+
+               return $result;
+       }
+
+       /**
+        * Unregisters a hook.
+        *
+        * @param string $hook     the name of the hook
+        * @param string $file     the name of the file that hooks into
+        * @param string $function the name of the function that the hook called
+        * @return boolean
+        */
+       public static function unregister($hook, $file, $function)
+       {
+               $relative_file = str_replace(self::getApp()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
+
+               // This here is only needed for fixing a problem that existed on the develop branch
+               $condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
+               DBA::delete('hook', $condition);
+
+               $condition = ['hook' => $hook, 'file' => $relative_file, 'function' => $function];
+               $result = DBA::delete('hook', $condition);
+               return $result;
+       }
+
+       /**
+        * Returns the list of callbacks for a single hook
+        *
+        * @param  string $name Name of the hook
+        * @return array
+        */
+       public static function getByName($name)
+       {
+               $return = [];
+
+               if (isset(self::$hooks[$name])) {
+                       $return = self::$hooks[$name];
+               }
+
+               return $return;
+       }
+
+       /**
+        * @brief Forks a hook.
+        *
+        * Use this function when you want to fork a hook via the worker.
+        *
+        * @param integer $priority of the hook
+        * @param string  $name     of the hook to call
+        * @param mixed   $data     to transmit to the callback handler
+        */
+       public static function fork($priority, $name, $data = null)
+       {
+               if (array_key_exists($name, self::$hooks)) {
+                       foreach (self::$hooks[$name] as $hook) {
+                               Worker::add($priority, 'ForkHook', $name, $hook, $data);
+                       }
+               }
+       }
+
+       /**
+        * @brief Calls a hook.
+        *
+        * Use this function when you want to be able to allow a hook to manipulate
+        * the provided data.
+        *
+        * @param string       $name  of the hook to call
+        * @param string|array &$data to transmit to the callback handler
+        */
+       public static function callAll($name, &$data = null)
+       {
+               if (array_key_exists($name, self::$hooks)) {
+                       foreach (self::$hooks[$name] as $hook) {
+                               self::callSingle(self::getApp(), $name, $hook, $data);
+                       }
+               }
+       }
+
+       /**
+        * @brief Calls a single hook.
+        *
+        * @param App $a
+        * @param string         $name of the hook to call
+        * @param array          $hook Hook data
+        * @param string|array   &$data to transmit to the callback handler
+        */
+       public static function callSingle(App $a, $name, $hook, &$data = null)
+       {
+               // Don't run a theme's hook if the user isn't using the theme
+               if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/' . $a->getCurrentTheme()) === false) {
+                       return;
+               }
+
+               @include_once($hook[0]);
+               if (function_exists($hook[1])) {
+                       $func = $hook[1];
+                       $func($a, $data);
+               } else {
+                       // remove orphan hooks
+                       $condition = ['hook' => $name, 'file' => $hook[0], 'function' => $hook[1]];
+                       DBA::delete('hook', $condition, ['cascade' => false]);
+               }
+       }
+
+       /**
+        * Checks if an app_menu hook exist for the provided addon name.
+        * Return true if the addon is an app
+        *
+        * @param string $name Name of the addon
+        * @return boolean
+        */
+       public static function isAddonApp($name)
+       {
+               if (array_key_exists('app_menu', self::$hooks)) {
+                       foreach (self::$hooks['app_menu'] as $hook) {
+                               if ($hook[0] == 'addon/' . $name . '/' . $name . '.php') {
+                                       return true;
+                               }
+                       }
+               }
+
+               return false;
+       }
+}
index daf90b9fff65de12b2620d9e2815a5c349e171dd..448f77c010b179c0f9bd5d379ef0913ab5e0082f 100644 (file)
@@ -97,6 +97,7 @@ class Install
         * - Creates `config/local.ini.php`
         * - Installs Database Structure
         *
+        * @param string        $phppath        Path to the PHP-Binary (optional, if not set e.g. 'php' or '/usr/bin/php')
         * @param string        $urlpath        Path based on the URL of Friendica (e.g. '/friendica')
         * @param string        $dbhost         Hostname/IP of the Friendica Database
         * @param string        $dbuser         Username of the Database connection credentials
@@ -106,7 +107,6 @@ class Install
         * @param string        $language       2-letter ISO 639-1 code (eg. 'en')
         * @param string        $adminmail      Mail-Adress of the administrator
         * @param string        $basepath   The basepath of Friendica
-        * @param string        $phpath         Path to the PHP-Binary (optional, if not set e.g. 'php' or '/usr/bin/php')
         *
         * @return bool|string true if the config was created, the text if something went wrong
         */
index 542590646d4b21e11a77beda055a62a0f666fe25..45b70e06258663bb1e7abb8ee784c37863d4ee95 100644 (file)
@@ -12,19 +12,90 @@ require_once 'boot.php';
 require_once 'include/dba.php';
 
 /**
- * Provide Languange, Translation, and Localisation functions to the application
- * Localisation can be referred to by the numeronym L10N (as in: "L", followed by ten more letters, and then "N").
+ * Provide Language, Translation, and Localization functions to the application
+ * Localization can be referred to by the numeronym L10N (as in: "L", followed by ten more letters, and then "N").
  */
 class L10n extends BaseObject
 {
        /**
-        * @brief get the prefered language from the HTTP_ACCEPT_LANGUAGE header
+        * A string indicating the current language used for translation:
+        * - Two-letter ISO 639-1 code.
+        * - Two-letter ISO 639-1 code + dash + Two-letter ISO 3166-1 alpha-2 country code.
+        * @var string
         */
-       public static function getBrowserLanguage()
+       private static $lang = '';
+       /**
+        * A language code saved for later after pushLang() has been called.
+        *
+        * @var string
+        */
+       private static $langSave = '';
+
+       /**
+        * An array of translation strings whose key is the neutral english message.
+        *
+        * @var array
+        */
+       private static $strings = [];
+       /**
+        * An array of translation strings saved for later after pushLang() has been called.
+        *
+        * @var array
+        */
+       private static $stringsSave = [];
+
+       /**
+        * Detects the language and sets the translation table
+        */
+       public static function init()
+       {
+               $lang = self::detectLanguage();
+               self::loadTranslationTable($lang);
+       }
+
+       /**
+        * Returns the current language code
+        *
+        * @return string Language code
+        */
+       public static function getCurrentLang()
+       {
+               return self::$lang;
+       }
+
+       /**
+        * Sets the language session variable
+        */
+       public static function setSessionVariable()
+       {
+               if (!empty($_SESSION['authenticated']) && empty($_SESSION['language'])) {
+                       $_SESSION['language'] = self::$lang;
+                       // we haven't loaded user data yet, but we need user language
+                       if (!empty($_SESSION['uid'])) {
+                               $user = DBA::selectFirst('user', ['language'], ['uid' => $_SESSION['uid']]);
+                               if (DBA::isResult($user)) {
+                                       $_SESSION['language'] = $user['language'];
+                               }
+                       }
+               }
+       }
+
+       public static function setLangFromSession()
+       {
+               if (!empty($_SESSION['language']) && $_SESSION['language'] !== self::$lang) {
+                       self::loadTranslationTable($_SESSION['language']);
+               }
+       }
+
+       /**
+        * @brief Returns the preferred language from the HTTP_ACCEPT_LANGUAGE header
+        * @return string The two-letter language code
+        */
+       public static function detectLanguage()
        {
                $lang_list = [];
 
-               if (x($_SERVER, 'HTTP_ACCEPT_LANGUAGE')) {
+               if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                        // break up string into pieces (languages and q factors)
                        preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
 
@@ -59,58 +130,69 @@ class L10n extends BaseObject
        }
 
        /**
-        * @param string $language language
+        * This function should be called before formatting messages in a specific target language
+        * different from the current user/system language.
+        *
+        * It saves the current translation strings in a separate variable and loads new translations strings.
+        *
+        * If called repeatedly, it won't save the translation strings again, just load the new ones.
+        *
+        * @see popLang()
+        * @brief Stores the current language strings and load a different language.
+        * @param string $lang Language code
         */
-       public static function pushLang($language)
+       public static function pushLang($lang)
        {
-               $a = self::getApp();
-
-               $a->langsave = Config::get('system', 'language');
+               if (!self::$lang) {
+                       self::init();
+               }
 
-               if ($language === $a->langsave) {
+               if ($lang === self::$lang) {
                        return;
                }
 
-               if (isset($a->strings) && count($a->strings)) {
-                       $a->stringsave = $a->strings;
+               if (!self::$langSave) {
+                       self::$langSave = self::$lang;
+                       self::$stringsSave = self::$strings;
                }
-               $a->strings = [];
-               self::loadTranslationTable($language);
-               Config::set('system', 'language', $language);
+
+               self::loadTranslationTable($lang);
        }
 
        /**
-        * Pop language off the top of the stack
+        * Restores the original user/system language after having used pushLang()
         */
        public static function popLang()
        {
-               $a = self::getApp();
-
-               if (Config::get('system', 'language') === $a->langsave) {
+               if (!self::$langSave) {
                        return;
                }
 
-               if (isset($a->stringsave)) {
-                       $a->strings = $a->stringsave;
-               } else {
-                       $a->strings = [];
-               }
+               self::$strings = self::$stringsSave;
+               self::$lang = self::$langSave;
 
-               Config::set('system', 'language', $a->langsave);
+               self::$stringsSave = [];
+               self::$langSave = '';
        }
 
        /**
-        * load string translation table for alternate language
+        * Loads string translation table
+        *
+        * First addon strings are loaded, then globals
         *
-        * first addon strings are loaded, then globals
+        * Uses an App object shim since all the strings files refer to $a->strings
         *
         * @param string $lang language code to load
         */
-       public static function loadTranslationTable($lang)
+       private static function loadTranslationTable($lang)
        {
-               $a = self::getApp();
+               if ($lang === self::$lang) {
+                       return;
+               }
 
+               $a = new \stdClass();
                $a->strings = [];
+
                // load enabled addons strings
                $addons = DBA::select('addon', ['name'], ['installed' => true]);
                while ($p = DBA::fetch($addons)) {
@@ -123,6 +205,11 @@ class L10n extends BaseObject
                if (file_exists("view/lang/$lang/strings.php")) {
                        include "view/lang/$lang/strings.php";
                }
+
+               self::$lang = $lang;
+               self::$strings = $a->strings;
+
+               unset($a);
        }
 
        /**
@@ -143,14 +230,16 @@ class L10n extends BaseObject
         */
        public static function t($s, ...$vars)
        {
-               $a = self::getApp();
-
                if (empty($s)) {
                        return '';
                }
 
-               if (x($a->strings, $s)) {
-                       $t = $a->strings[$s];
+               if (!self::$lang) {
+                       self::init();
+               }
+
+               if (!empty(self::$strings[$s])) {
+                       $t = self::$strings[$s];
                        $s = is_array($t) ? $t[0] : $t;
                }
 
@@ -181,18 +270,18 @@ class L10n extends BaseObject
         */
        public static function tt($singular, $plural, $count)
        {
-               $a = self::getApp();
-
                if (!is_numeric($count)) {
                        logger('Non numeric count called by ' . System::callstack(20));
                }
 
-               $lang = Config::get('system', 'language');
+               if (!self::$lang) {
+                       self::init();
+               }
 
-               if (!empty($a->strings[$singular])) {
-                       $t = $a->strings[$singular];
+               if (!empty(self::$strings[$singular])) {
+                       $t = self::$strings[$singular];
                        if (is_array($t)) {
-                               $plural_function = 'string_plural_select_' . str_replace('-', '_', $lang);
+                               $plural_function = 'string_plural_select_' . str_replace('-', '_', self::$lang);
                                if (function_exists($plural_function)) {
                                        $i = $plural_function($count);
                                } else {
@@ -227,8 +316,6 @@ class L10n extends BaseObject
                return $n != 1;
        }
 
-
-
        /**
         * @brief Return installed languages codes as associative array
         *
index fb77605730b1069501c751c382a4f2ee46448cfe..9250bc2e5b46dd7f266eff4a99e00f145550fb5a 100644 (file)
@@ -642,7 +642,7 @@ class NotificationsManager extends BaseObject
                                        'madeby_zrl' => Contact::magicLink($it['url']),
                                        'madeby_addr' => $it['addr'],
                                        'contact_id' => $it['contact-id'],
-                                       'photo' => ((x($it, 'fphoto')) ? ProxyUtils::proxifyUrl($it['fphoto'], false, ProxyUtils::SIZE_SMALL) : "images/person-175.jpg"),
+                                       'photo' => ((x($it, 'fphoto')) ? ProxyUtils::proxifyUrl($it['fphoto'], false, ProxyUtils::SIZE_SMALL) : "images/person-300.jpg"),
                                        'name' => $it['fname'],
                                        'url' => $it['furl'],
                                        'zrl' => Contact::magicLink($it['furl']),
@@ -674,7 +674,7 @@ class NotificationsManager extends BaseObject
                                        'uid' => $_SESSION['uid'],
                                        'intro_id' => $it['intro_id'],
                                        'contact_id' => $it['contact-id'],
-                                       'photo' => ((x($it, 'photo')) ? ProxyUtils::proxifyUrl($it['photo'], false, ProxyUtils::SIZE_SMALL) : "images/person-175.jpg"),
+                                       'photo' => ((x($it, 'photo')) ? ProxyUtils::proxifyUrl($it['photo'], false, ProxyUtils::SIZE_SMALL) : "images/person-300.jpg"),
                                        'name' => $it['name'],
                                        'location' => BBCode::convert($it['glocation'], false),
                                        'about' => BBCode::convert($it['gabout'], false),
index d41250a68643eb2db0ff91cff4bf7f996b9c4d2c..949e2350c3be85ceb72f93d0ad756cb8d2936b84 100644 (file)
@@ -108,6 +108,13 @@ class Protocol
                        }
                }
 
+               // Mastodon, Pleroma
+               if (preg_match('=https?://(.+?)/users/(.+)=ism', $profile_url, $matches)
+                       || preg_match('=https?://(.+?)/@(.+)=ism', $profile_url, $matches)
+               ) {
+                       return self::ACTIVITYPUB;
+               }
+
                // pumpio (http://host.name/user)
                if (preg_match('=https?://([\.\w]+)/([\.\w]+)$=ism', $profile_url, $matches)) {
                        return self::PUMPIO;
index 5b5fac82f01b520e4f31e86e70904932d719a709..6079d9e22855d922a3072f9b06804725b5012872 100644 (file)
@@ -5,6 +5,7 @@
 namespace Friendica\Core;
 
 use Friendica\BaseObject;
+use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Util\XML;
 
 /**
@@ -142,7 +143,7 @@ class System extends BaseObject
                                '$description' => defaults($description, 'description', '')]);
                }
 
-               killme();
+               exit();
        }
 
        /**
@@ -236,10 +237,26 @@ class System extends BaseObject
                return max($load_arr[0], $load_arr[1]);
        }
 
+       /**
+        * Redirects to an external URL (fully qualified URL)
+        * If you want to route relative to the current Friendica base, use App->internalRedirect()
+        *
+        * @param string $url The new Location to redirect
+        * @throws InternalServerErrorException If the URL is not fully qualified
+        */
+       public static function externalRedirect($url)
+       {
+               if (!filter_var($url, FILTER_VALIDATE_URL)) {
+                       throw new InternalServerErrorException("'$url' is not a fully qualified URL, please use App->internalRedirect() instead");
+               }
+
+               header("Location: $url");
+               exit();
+       }
+
        /// @todo Move the following functions from boot.php
        /*
        function killme()
-       function goaway($s)
        function local_user()
        function public_contact()
        function remote_user()
index e62084049e3240baed70bd218babf683686f048f..18aabec08a07c800be2b7d74195a36fd5ff867b3 100644 (file)
@@ -180,7 +180,7 @@ class UserImport
                        }
                        if ($contact['uid'] == $olduid && $contact['self'] == '0') {
                                // set contacts 'avatar-date' to NULL_DATE to let worker to update urls
-                               $contact["avatar-date"] = NULL_DATE;
+                               $contact["avatar-date"] = DBA::NULL_DATETIME;
 
                                switch ($contact['network']) {
                                        case Protocol::DFRN:
@@ -272,6 +272,6 @@ class UserImport
                Worker::add(PRIORITY_HIGH, 'Notifier', 'relocate', $newuid);
 
                info(L10n::t("Done. You can now login with your username and password"));
-               goaway(System::baseUrl() . "/login");
+               $a->internalRedirect('login');
        }
 }
index 723cd809da44d3230721afd1eb4e06cf5a17ffb7..a3c5884604debd24cb73125f031b52c4f0b93311 100644 (file)
@@ -4,11 +4,11 @@
  */
 namespace Friendica\Core;
 
+use Friendica\BaseObject;
 use Friendica\Database\DBA;
 use Friendica\Model\Process;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
-use Friendica\BaseObject;
 
 require_once 'include/dba.php';
 
@@ -146,6 +146,17 @@ class Worker
                logger("Couldn't select a workerqueue entry, quitting process " . getmypid() . ".", LOGGER_DEBUG);
        }
 
+       /**
+        * @brief Returns the number of deferred entries in the worker queue
+        *
+        * @return integer Number of deferred entries in the worker queue
+        */
+       private static function deferredEntries()
+       {
+               return DBA::count('workerqueue', ["`executed` <= ? AND NOT `done` AND `next_try` > ?",
+                       DBA::NULL_DATETIME, DateTimeFormat::utcNow()]);
+       }
+
        /**
         * @brief Returns the number of non executed entries in the worker queue
         *
@@ -154,7 +165,7 @@ class Worker
        private static function totalEntries()
        {
                return DBA::count('workerqueue', ["`executed` <= ? AND NOT `done` AND `next_try` < ?",
-                       NULL_DATE, DateTimeFormat::utcNow()]);
+                       DBA::NULL_DATETIME, DateTimeFormat::utcNow()]);
        }
 
        /**
@@ -164,7 +175,7 @@ class Worker
         */
        private static function highestPriority()
        {
-               $condition = ["`executed` <= ? AND NOT `done` AND `next_try` < ?", NULL_DATE, DateTimeFormat::utcNow()];
+               $condition = ["`executed` <= ? AND NOT `done` AND `next_try` < ?", DBA::NULL_DATETIME, DateTimeFormat::utcNow()];
                $workerqueue = DBA::selectFirst('workerqueue', ['priority'], $condition, ['order' => ['priority']]);
                if (DBA::isResult($workerqueue)) {
                        return $workerqueue["priority"];
@@ -183,7 +194,7 @@ class Worker
        private static function processWithPriorityActive($priority)
        {
                $condition = ["`priority` <= ? AND `executed` > ? AND NOT `done` AND `next_try` < ?",
-                       $priority, NULL_DATE, DateTimeFormat::utcNow()];
+                       $priority, DBA::NULL_DATETIME, DateTimeFormat::utcNow()];
                return DBA::exists('workerqueue', $condition);
        }
 
@@ -243,7 +254,9 @@ class Worker
                        self::execFunction($queue, $include, $argv, true);
 
                        $stamp = (float)microtime(true);
-                       if (DBA::update('workerqueue', ['done' => true], ['id' => $queue['id']])) {
+
+                       $condition = ["`id` = ? AND `next_try` < ?", $queue['id'], DateTimeFormat::utcNow()];
+                       if (DBA::update('workerqueue', ['done' => true], $condition)) {
                                Config::set('system', 'last_worker_execution', DateTimeFormat::utcNow());
                        }
                        self::$db_duration = (microtime(true) - $stamp);
@@ -553,7 +566,7 @@ class Worker
                $entries = DBA::select(
                        'workerqueue',
                        ['id', 'pid', 'executed', 'priority', 'parameter'],
-                       ['`executed` > ? AND NOT `done` AND `pid` != 0', NULL_DATE],
+                       ['`executed` > ? AND NOT `done` AND `pid` != 0', DBA::NULL_DATETIME],
                        ['order' => ['priority', 'created']]
                );
 
@@ -561,7 +574,7 @@ class Worker
                        if (!posix_kill($entry["pid"], 0)) {
                                DBA::update(
                                        'workerqueue',
-                                       ['executed' => NULL_DATE, 'pid' => 0],
+                                       ['executed' => DBA::NULL_DATETIME, 'pid' => 0],
                                        ['id' => $entry["id"]]
                                );
                        } else {
@@ -597,7 +610,7 @@ class Worker
                                        }
                                        DBA::update(
                                                'workerqueue',
-                                               ['executed' => NULL_DATE, 'created' => DateTimeFormat::utcNow(), 'priority' => $new_priority, 'pid' => 0],
+                                               ['executed' => DBA::NULL_DATETIME, 'created' => DateTimeFormat::utcNow(), 'priority' => $new_priority, 'pid' => 0],
                                                ['id' => $entry["id"]]
                                        );
                                } else {
@@ -677,6 +690,7 @@ class Worker
                        }
 
                        $entries = self::totalEntries();
+                       $deferred = self::deferredEntries();
 
                        if (Config::get("system", "worker_fastlane", false) && ($queues > 0) && ($entries > 0) && ($active >= $queues)) {
                                $top_priority = self::highestPriority();
@@ -688,7 +702,7 @@ class Worker
                                }
                        }
 
-                       logger("Load: ".$load."/".$maxsysload." - processes: ".$active."/".$entries.$processlist." - maximum: ".$queues."/".$maxqueues, LOGGER_DEBUG);
+                       logger("Load: " . $load ."/" . $maxsysload . " - processes: " . $deferred . "/" . $active . "/" . $entries . $processlist . " - maximum: " . $queues . "/" . $maxqueues, LOGGER_DEBUG);
 
                        // Are there fewer workers running as possible? Then fork a new one.
                        if (!Config::get("system", "worker_dont_fork", false) && ($queues > ($active + 1)) && ($entries > 1)) {
@@ -795,13 +809,14 @@ class Worker
                $queue_length = Config::get('system', 'worker_fetch_limit', 1);
                $lower_job_limit = $worker_queues * $queue_length * 2;
                $jobs = self::totalEntries();
+               $deferred = self::deferredEntries();
 
                // Now do some magic
                $exponent = 2;
                $slope = $queue_length / pow($lower_job_limit, $exponent);
                $limit = min($queue_length, ceil($slope * pow($jobs, $exponent)));
 
-               logger('Total: '.$jobs.' - Maximum: '.$queue_length.' - jobs per queue: '.$limit, LOGGER_DEBUG);
+               logger('Deferred: ' . $deferred . ' - Total: ' . $jobs . ' - Maximum: ' . $queue_length . ' - jobs per queue: ' . $limit, LOGGER_DEBUG);
                $ids = [];
                if (self::passingSlow($highest_priority)) {
                        // Are there waiting processes with a higher priority than the currently highest?
@@ -809,7 +824,7 @@ class Worker
                                'workerqueue',
                                ['id'],
                                ["`executed` <= ? AND `priority` < ? AND NOT `done` AND `next_try` < ?",
-                               NULL_DATE, $highest_priority, DateTimeFormat::utcNow()],
+                               DBA::NULL_DATETIME, $highest_priority, DateTimeFormat::utcNow()],
                                ['limit' => $limit, 'order' => ['priority', 'created']]
                        );
 
@@ -826,7 +841,7 @@ class Worker
                                        'workerqueue',
                                        ['id'],
                                        ["`executed` <= ? AND `priority` > ? AND NOT `done` AND `next_try` < ?",
-                                       NULL_DATE, $highest_priority, DateTimeFormat::utcNow()],
+                                       DBA::NULL_DATETIME, $highest_priority, DateTimeFormat::utcNow()],
                                        ['limit' => $limit, 'order' => ['priority', 'created']]
                                );
 
@@ -846,7 +861,7 @@ class Worker
                                'workerqueue',
                                ['id'],
                                ["`executed` <= ? AND NOT `done` AND `next_try` < ?",
-                               NULL_DATE, DateTimeFormat::utcNow()],
+                               DBA::NULL_DATETIME, DateTimeFormat::utcNow()],
                                ['limit' => $limit, 'order' => ['priority', 'created']]
                        );
 
@@ -912,7 +927,7 @@ class Worker
        {
                $mypid = getmypid();
 
-               DBA::update('workerqueue', ['executed' => NULL_DATE, 'pid' => 0], ['pid' => $mypid, 'done' => false]);
+               DBA::update('workerqueue', ['executed' => DBA::NULL_DATETIME, 'pid' => 0], ['pid' => $mypid, 'done' => false]);
        }
 
        /**
@@ -1137,8 +1152,8 @@ class Worker
                $id = $queue['id'];
 
                if ($retrial > 14) {
-                       logger('Id ' . $id . ' had been tried 14 times, it will be deleted now.', LOGGER_DEBUG);
-                       DBA::delete('workerqueue', ['id' => $id]);
+                       logger('Id ' . $id . ' had been tried 14 times. We stop now.', LOGGER_DEBUG);
+                       return;
                }
 
                // Calculate the delay until the next trial
@@ -1147,7 +1162,7 @@ class Worker
 
                logger('Defer execution ' . $retrial . ' of id ' . $id . ' to ' . $next, LOGGER_DEBUG);
 
-               $fields = ['retrial' => $retrial + 1, 'next_try' => $next, 'executed' => NULL_DATE, 'pid' => 0];
+               $fields = ['retrial' => $retrial + 1, 'next_try' => $next, 'executed' => DBA::NULL_DATETIME, 'pid' => 0];
                DBA::update('workerqueue', $fields, ['id' => $id]);
        }
 
index c33fa2152fb5aebfd5b9ad84ac04ed4dd3d57776..6249537c06d7661c7f286e9e4bdf6c38b9fc25d0 100644 (file)
@@ -24,6 +24,15 @@ require_once 'include/dba.php';
  */
 class DBA
 {
+       /**
+        * Lowest possible date value
+        */
+       const NULL_DATE     = '0001-01-01';
+       /**
+        * Lowest possible datetime value
+        */
+       const NULL_DATETIME = '0001-01-01 00:00:00';
+
        public static $connected = false;
 
        private static $server_info = '';
@@ -821,7 +830,7 @@ class DBA
         * @param array $param parameter array
         * @param bool $on_duplicate_update Do an update on a duplicate entry
         *
-        * @return boolean was the insert successfull?
+        * @return boolean was the insert successful?
         */
        public static function insert($table, $param, $on_duplicate_update = false) {
 
index f8fc1651c140ece8dffd8385f65097bdf1561638..9abae944ae0e873d8b67a065a95f49fc2f49a07c 100644 (file)
@@ -5,8 +5,8 @@
 namespace Friendica\Database;
 
 use Exception;
-use Friendica\Core\Addon;
 use Friendica\Core\Config;
+use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Util\DateTimeFormat;
 
@@ -22,6 +22,13 @@ require_once 'include/text.php';
  */
 class DBStructure
 {
+       /**
+        * Database structure definition loaded from config/dbstructure.php
+        *
+        * @var array
+        */
+       private static $definition = [];
+
        /*
         * Converts all tables from MyISAM to InnoDB
         */
@@ -77,10 +84,9 @@ class DBStructure
                                The friendica developers released update %s recently,
                                but when I tried to install it, something went terribly wrong.
                                This needs to be fixed soon and I can't do it alone. Please contact a
-                               friendica developer if you can not help me on your own. My database might be invalid."));
-                       $body = L10n::t("The error message is\n[pre]%s[/pre]");
-                       $preamble = sprintf($preamble, $update_id);
-                       $body = sprintf($body, $error_message);
+                               friendica developer if you can not help me on your own. My database might be invalid.",
+                               $update_id));
+                       $body = L10n::t("The error message is\n[pre]%s[/pre]", $error_message);
 
                        notification([
                                'uid'      => $admin['uid'],
@@ -90,6 +96,7 @@ class DBStructure
                                'body'     => $body,
                                'language' => $lang]
                        );
+                       L10n::popLang();
                }
 
                //try the logger
@@ -166,7 +173,7 @@ class DBStructure
        }
 
        public static function printStructure() {
-               $database = self::definition();
+               $database = self::definition(false);
 
                echo "-- ------------------------------------------\n";
                echo "-- ".FRIENDICA_PLATFORM." ".FRIENDICA_VERSION." (".FRIENDICA_CODENAME,")\n";
@@ -822,43 +829,40 @@ class DBStructure
        }
 
        /**
-        * Loads the database structure definition from the /config/dbstructure.json file
-        *
-        * Expected format:
-        * "table_name": {
-        *   "comment": "meaningful table comment",
-        *   "fields": {
-        *     "field_name1": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "meaningful field comment"},
-        *     "field_name2": {"type": "varchar(50)", "not null": "1", "default": "", "comment": "meaningful field comment"},
-        *   },
-        *   "indexes": {
-        *     "PRIMARY": ["field_name1"],
-        *     "name": ["UNIQUE", "field_name2"]
-        *   }
-        * }
+        * Loads the database structure definition from the config/dbstructure.php file.
+        * On first pass, defines DB_UPDATE_VERSION constant.
         *
+        * @see config/dbstructure.php
+        * @param boolean $with_addons_structure Whether to tack on addons additional tables
         * @return array
         * @throws Exception
         */
-       public static function definition() {
-               $a = \Friendica\BaseObject::getApp();
+       public static function definition($with_addons_structure = true)
+       {
+               if (!self::$definition) {
+                       $a = \Friendica\BaseObject::getApp();
 
-               $filename = $a->getBasePath() . '/config/dbstructure.json';
+                       $filename = $a->getBasePath() . '/config/dbstructure.php';
 
-               if (!is_readable($filename)) {
-                       throw new Exception('Missing database structure config file config/dbstructure.json');
-               }
+                       if (!is_readable($filename)) {
+                               throw new Exception('Missing database structure config file config/dbstructure.php');
+                       }
 
-               $json = file_get_contents($filename);
+                       $definition = require $filename;
 
-               $database = json_decode($json, true);
+                       if (!$definition) {
+                               throw new Exception('Corrupted database structure config file config/dbstructure.php');
+                       }
 
-               if (!$database) {
-                       throw new Exception('Corrupted database structure config file config/dbstructure.json');
+                       self::$definition = $definition;
+               } else {
+                       $definition = self::$definition;
                }
 
-               Addon::callHooks('dbstructure_definition', $database);
+               if ($with_addons_structure) {
+                       Hook::callAll('dbstructure_definition', $definition);
+               }
 
-               return $database;
+               return $definition;
        }
 }
diff --git a/src/LegacyModule.php b/src/LegacyModule.php
new file mode 100644 (file)
index 0000000..737101b
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+
+namespace Friendica;
+
+/**
+ * This mock module enable class encapsulation of legacy global function modules.
+ * After having provided the module file name, all the methods will behave like a normal Module class.
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class LegacyModule extends BaseModule
+{
+       /**
+        * The module name, which is the name of the file (without the .php suffix)
+        * It's used to check for existence of the module functions.
+        *
+        * @var string
+        */
+       private static $moduleName = '';
+
+       /**
+        * The only method that needs to be called, with the module/addon file name.
+        *
+        * @param string $file_path
+        */
+       public static function setModuleFile($file_path)
+       {
+               if (!is_readable($file_path)) {
+                       throw new Exception(Core\L10n::t('Legacy module file not found: %s', $file_path));
+               }
+
+               self::$moduleName = basename($file_path, '.php');
+
+               require_once $file_path;
+       }
+
+       public static function init()
+       {
+               self::runModuleFunction('init');
+       }
+
+       public static function content()
+       {
+               return self::runModuleFunction('content');
+       }
+
+       public static function post()
+       {
+               self::runModuleFunction('post');
+       }
+
+       public static function afterpost()
+       {
+               self::runModuleFunction('afterpost');
+       }
+
+       /**
+        * Runs the module function designated by the provided suffix if it exists, the BaseModule method otherwise
+        *
+        * @param string $function_suffix
+        * @return string
+        */
+       private static function runModuleFunction($function_suffix)
+       {
+               $function_name = static::$moduleName . '_' . $function_suffix;
+
+               if (\function_exists($function_name)) {
+                       return $function_name(self::getApp());
+               } else {
+                       return parent::{$function_suffix}();
+               }
+       }
+}
index 4593e0377b1de25f3d707231e294f89245a4f3c9..72c644ab9ac0d15302d321f4ca0489f4c19c50a0 100644 (file)
@@ -99,32 +99,55 @@ class APContact extends BaseObject
                }
 
                $data = ActivityPub::fetchContent($url);
-
-               if (empty($data) || empty($data['id']) || empty($data['inbox'])) {
+               if (empty($data)) {
                        return false;
                }
 
+               $compacted = JsonLD::compact($data);
+
                $apcontact = [];
-               $apcontact['url'] = $data['id'];
-               $apcontact['uuid'] = defaults($data, 'diaspora:guid', null);
-               $apcontact['type'] = defaults($data, 'type', null);
-               $apcontact['following'] = defaults($data, 'following', null);
-               $apcontact['followers'] = defaults($data, 'followers', null);
-               $apcontact['inbox'] = defaults($data, 'inbox', null);
-               $apcontact['outbox'] = defaults($data, 'outbox', null);
-               $apcontact['sharedinbox'] = JsonLD::fetchElement($data, 'endpoints', 'sharedInbox');
-               $apcontact['nick'] = defaults($data, 'preferredUsername', null);
-               $apcontact['name'] = defaults($data, 'name', $apcontact['nick']);
-               $apcontact['about'] = HTML::toBBCode(defaults($data, 'summary', ''));
-               $apcontact['photo'] = JsonLD::fetchElement($data, 'icon', 'url');
-               $apcontact['alias'] = JsonLD::fetchElement($data, 'url', 'href');
+               $apcontact['url'] = $compacted['@id'];
+               $apcontact['uuid'] = JsonLD::fetchElement($compacted, 'diaspora:guid');
+               $apcontact['type'] = str_replace('as:', '', JsonLD::fetchElement($compacted, '@type'));
+               $apcontact['following'] = JsonLD::fetchElement($compacted, 'as:following', '@id');
+               $apcontact['followers'] = JsonLD::fetchElement($compacted, 'as:followers', '@id');
+               $apcontact['inbox'] = JsonLD::fetchElement($compacted, 'ldp:inbox', '@id');
+               $apcontact['outbox'] = JsonLD::fetchElement($compacted, 'as:outbox', '@id');
+
+               $apcontact['sharedinbox'] = '';
+               if (!empty($compacted['as:endpoints'])) {
+                       $apcontact['sharedinbox'] = JsonLD::fetchElement($compacted['as:endpoints'], 'as:sharedInbox', '@id');
+               }
+
+               $apcontact['nick'] = JsonLD::fetchElement($compacted, 'as:preferredUsername');
+               $apcontact['name'] = JsonLD::fetchElement($compacted, 'as:name');
+
+               if (empty($apcontact['name'])) {
+                       $apcontact['name'] = $apcontact['nick'];
+               }
+
+               $apcontact['about'] = HTML::toBBCode(JsonLD::fetchElement($compacted, 'as:summary'));
+
+               $apcontact['photo'] = JsonLD::fetchElement($compacted, 'as:icon', '@id');
+               if (is_array($apcontact['photo'])) {
+                       $apcontact['photo'] = JsonLD::fetchElement($compacted['as:icon'], 'as:url', '@id');
+               }
+
+               $apcontact['alias'] = JsonLD::fetchElement($compacted, 'as:url', '@id');
+               if (is_array($apcontact['alias'])) {
+                       $apcontact['alias'] = JsonLD::fetchElement($compacted['as:url'], 'as:href', '@id');
+               }
+
+               if (empty($apcontact['url']) || empty($apcontact['inbox'])) {
+                       return false;
+               }
 
                $parts = parse_url($apcontact['url']);
                unset($parts['scheme']);
                unset($parts['path']);
                $apcontact['addr'] = $apcontact['nick'] . '@' . str_replace('//', '', Network::unparseURL($parts));
 
-               $apcontact['pubkey'] = trim(JsonLD::fetchElement($data, 'publicKey', 'publicKeyPem'));
+               $apcontact['pubkey'] = trim(JsonLD::fetchElement($compacted, 'w3id:publicKey', 'w3id:publicKeyPem'));
 
                // To-Do
                // manuallyApprovesFollowers
index 4588bb7129d3e4f2f4ad8936e177f5d133422f29..fdb49ac1331379b3bfd2a9d8c6a84c35409ab79a 100644 (file)
@@ -8,7 +8,6 @@ use Friendica\BaseObject;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
@@ -17,8 +16,8 @@ use Friendica\Model\Profile;
 use Friendica\Network\Probe;
 use Friendica\Object\Image;
 use Friendica\Protocol\ActivityPub;
-use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\DFRN;
+use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Protocol\PortableContact;
 use Friendica\Protocol\Salmon;
@@ -466,7 +465,7 @@ class Contact extends BaseObject
                        $fields['micro'] = $prefix . '6' . $suffix;
                } else {
                        // We hadn't found a photo entry, so we use the default avatar
-                       $fields['photo'] = System::baseUrl() . '/images/person-175.jpg';
+                       $fields['photo'] = System::baseUrl() . '/images/person-300.jpg';
                        $fields['thumb'] = System::baseUrl() . '/images/person-80.jpg';
                        $fields['micro'] = System::baseUrl() . '/images/person-48.jpg';
                }
@@ -594,9 +593,9 @@ class Contact extends BaseObject
                        return;
                }
 
-               if ($contact['term-date'] <= NULL_DATE) {
+               if ($contact['term-date'] <= DBA::NULL_DATETIME) {
                        DBA::update('contact', ['term-date' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
-                       DBA::update('contact', ['term-date' => DateTimeFormat::utcNow()], ['`nurl` = ? AND `term-date` <= ? AND NOT `self`', normalise_link($contact['url']), NULL_DATE]);
+                       DBA::update('contact', ['term-date' => DateTimeFormat::utcNow()], ['`nurl` = ? AND `term-date` <= ? AND NOT `self`', normalise_link($contact['url']), DBA::NULL_DATETIME]);
                } else {
                        /* @todo
                         * We really should send a notification to the owner after 2-3 weeks
@@ -629,7 +628,7 @@ class Contact extends BaseObject
         */
        public static function unmarkForArchival(array $contact)
        {
-               $condition = ['`id` = ? AND (`term-date` > ? OR `archive`)', $contact['id'], NULL_DATE];
+               $condition = ['`id` = ? AND (`term-date` > ? OR `archive`)', $contact['id'], DBA::NULL_DATETIME];
                $exists = DBA::exists('contact', $condition);
 
                // We don't need to update, we never marked this contact for archival
@@ -646,7 +645,7 @@ class Contact extends BaseObject
                }
 
                // It's a miracle. Our dead contact has inexplicably come back to life.
-               $fields = ['term-date' => NULL_DATE, 'archive' => false];
+               $fields = ['term-date' => DBA::NULL_DATETIME, 'archive' => false];
                DBA::update('contact', $fields, ['id' => $contact['id']]);
                DBA::update('contact', $fields, ['nurl' => normalise_link($contact['url'])]);
 
@@ -1021,10 +1020,11 @@ class Contact extends BaseObject
         * @param integer $uid       The user id for the contact (0 = public contact)
         * @param boolean $no_update Don't update the contact
         * @param array   $default   Default value for creating the contact when every else fails
+        * @param boolean $in_loop   Internally used variable to prevent an endless loop
         *
         * @return integer Contact ID
         */
-       public static function getIdForURL($url, $uid = 0, $no_update = false, $default = [])
+       public static function getIdForURL($url, $uid = 0, $no_update = false, $default = [], $in_loop = false)
        {
                logger("Get contact data for url " . $url . " and user " . $uid . " - " . System::callstack(), LOGGER_DEBUG);
 
@@ -1138,8 +1138,8 @@ class Contact extends BaseObject
                        }
                }
 
-               if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url)) {
-                       $contact_id = self::getIdForURL($data["alias"], $uid, true);
+               if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url) && !$in_loop) {
+                       $contact_id = self::getIdForURL($data["alias"], $uid, true, $default, true);
                }
 
                $url = $data["url"];
@@ -1638,7 +1638,7 @@ class Contact extends BaseObject
                                        $myaddr = bin2hex($a->user['nickname'] . '@' . $a->getHostName());
                                }
 
-                               goaway($ret['request'] . "&addr=$myaddr");
+                               $a->internalRedirect($ret['request'] . "&addr=$myaddr");
 
                                // NOTREACHED
                        }
@@ -2023,8 +2023,10 @@ class Contact extends BaseObject
        /**
         * @brief Returns a magic link to authenticate remote visitors
         *
+        * @todo check if the return is either a fully qualified URL or a relative path to Friendica basedir
+        *
         * @param string $contact_url The address of the target contact profile
-        * @param integer $url An url that we will be redirected to after the authentication
+        * @param string $url An url that we will be redirected to after the authentication
         *
         * @return string with "redir" link
         */
@@ -2057,7 +2059,7 @@ class Contact extends BaseObject
         * @brief Returns a magic link to authenticate remote visitors
         *
         * @param array $contact The contact array with "uid", "network" and "url"
-        * @param integer $url An url that we will be redirected to after the authentication
+        * @param string $url An url that we will be redirected to after the authentication
         *
         * @return string with "redir" link
         */
index be1eaf2295582a7e1bb1e0777cd7410a63e56f83..25075dcfbe41cbdab375d0c964c74c62fddd9d3f 100644 (file)
@@ -26,6 +26,11 @@ class Conversation
        const PARCEL_TWITTER            = 67;
        const PARCEL_UNKNOWN            = 255;
 
+       public static function getByItemUri($item_uri)
+       {
+               return DBA::selectFirst('conversation', [], ['item-uri' => $item_uri]);
+       }
+
        /**
         * @brief Store the conversation data
         *
index 452017e69d3a04bcfbd2269d851b1db69340f9ee..e9a4d4b3fd7d1792f5f44e3bb1c1208dc3f6a85e 100644 (file)
@@ -257,10 +257,10 @@ class Event extends BaseObject
 
                $event['created']   = DateTimeFormat::utc(defaults($arr, 'created'  , 'now'));
                $event['edited']    = DateTimeFormat::utc(defaults($arr, 'edited'   , 'now'));
-               $event['start']     = DateTimeFormat::utc(defaults($arr, 'start'    , NULL_DATE));
-               $event['finish']    = DateTimeFormat::utc(defaults($arr, 'finish'   , NULL_DATE));
-               if ($event['finish'] < NULL_DATE) {
-                       $event['finish'] = NULL_DATE;
+               $event['start']     = DateTimeFormat::utc(defaults($arr, 'start'    , DBA::NULL_DATETIME));
+               $event['finish']    = DateTimeFormat::utc(defaults($arr, 'finish'   , DBA::NULL_DATETIME));
+               if ($event['finish'] < DBA::NULL_DATETIME) {
+                       $event['finish'] = DBA::NULL_DATETIME;
                }
                $private = intval(defaults($arr, 'private', 0));
 
index 26cb11175c5b48573f638ec1d7e3eec9bb8a2e42..cc7775377924fb1b69882c44e7c79a30d3928367 100644 (file)
@@ -176,7 +176,7 @@ class GContact
                        if (!isset($gcontact['network']) && ($gcnt["network"] != Protocol::STATUSNET)) {
                                $gcontact['network'] = $gcnt["network"];
                        }
-                       if ($gcontact['updated'] <= NULL_DATE) {
+                       if ($gcontact['updated'] <= DBA::NULL_DATETIME) {
                                $gcontact['updated'] = $gcnt["updated"];
                        }
                        if (!isset($gcontact['server_url']) && (normalise_link($gcnt["server_url"]) != normalise_link($gcnt["url"]))) {
@@ -457,7 +457,7 @@ class GContact
                        intval($uid),
                        intval($uid),
                        intval($uid),
-                       DBA::escape(NULL_DATE),
+                       DBA::NULL_DATETIME,
                        $sql_network,
                        intval($start),
                        intval($limit)
@@ -468,7 +468,7 @@ class GContact
                        * Uncommented because the result of the queries are to big to store it in the cache.
                        * We need to decide if we want to change the db column type or if we want to delete it.
                        */
-                       //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $r, CACHE_FIVE_MINUTES);
+                       //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $r, Cache::FIVE_MINUTES);
 
                        return $r;
                }
@@ -486,7 +486,7 @@ class GContact
                        intval($uid),
                        intval($uid),
                        intval($uid),
-                       DBA::escape(NULL_DATE),
+                       DBA::NULL_DATETIME,
                        $sql_network,
                        intval($start),
                        intval($limit)
@@ -509,7 +509,7 @@ class GContact
                * Uncommented because the result of the queries are to big to store it in the cache.
                * We need to decide if we want to change the db column type or if we want to delete it.
                */
-               //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $list, CACHE_FIVE_MINUTES);
+               //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $list, Cache::FIVE_MINUTES);
                return $list;
        }
 
@@ -995,7 +995,7 @@ class GContact
                                                "addr" => $user->nickname."@".$hostname,
                                                "nick" => $user->nickname,
                                                "network" => Protocol::OSTATUS,
-                                               "photo" => System::baseUrl()."/images/person-175.jpg"];
+                                               "photo" => System::baseUrl()."/images/person-300.jpg"];
 
                                if (isset($user->bio)) {
                                        $contact["about"] = $user->bio;
index e313842e4143677afceb1f143dddb18eff3a0c31..4d0bd87e6a71c2a8119f44a975b1ba3d5f397136 100644 (file)
@@ -4,9 +4,11 @@
  */
 namespace Friendica\Model;
 
+use Friendica\BaseModule;
 use Friendica\BaseObject;
 use Friendica\Core\L10n;
 use Friendica\Database\DBA;
+use Friendica\Util\Security;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
@@ -409,7 +411,7 @@ class Group extends BaseObject
                        '$createtext' => L10n::t('Create a new group'),
                        '$creategroup' => L10n::t('Group Name: '),
                        '$editgroupstext' => L10n::t('Edit groups'),
-                       '$form_security_token' => get_form_security_token('group_edit'),
+                       '$form_security_token' => BaseModule::getFormSecurityToken('group_edit'),
                ]);
 
 
index 824e240cc36e54edcf7377889a80878ecfbb35d8..1c0b11db4aae80c6b3db9c5e2782b08940b96e46 100644 (file)
@@ -24,6 +24,7 @@ use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\XML;
+use Friendica\Util\Security;
 use Text_LanguageDetect;
 
 require_once 'boot.php';
@@ -80,7 +81,7 @@ class Item extends BaseObject
        // All fields in the item table
        const ITEM_FIELDLIST = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent', 'guid',
                        'contact-id', 'type', 'wall', 'gravity', 'extid', 'icid', 'iaid', 'psid',
-                       'uri-hash', 'created', 'edited', 'commented', 'received', 'changed', 'verb',
+                       'created', 'edited', 'commented', 'received', 'changed', 'verb',
                        'postopts', 'plink', 'resource-id', 'event-id', 'tag', 'attach', 'inform',
                        'file', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type',
                        'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
@@ -380,7 +381,7 @@ class Item extends BaseObject
                        $usermode = true;
                }
 
-               $fields = self::fieldlist($selected, $usermode);
+               $fields = self::fieldlist($usermode);
 
                $select_fields = self::constructSelectFields($fields, $selected);
 
@@ -487,7 +488,7 @@ class Item extends BaseObject
                        $usermode = true;
                }
 
-               $fields = self::fieldlist($selected, $usermode);
+               $fields = self::fieldlist($usermode);
 
                $fields['thread'] = ['mention', 'ignored', 'iid'];
 
@@ -523,13 +524,13 @@ class Item extends BaseObject
         *
         * @return array field list
         */
-       private static function fieldlist($selected, $usermode)
+       private static function fieldlist($usermode)
        {
                $fields = [];
 
                $fields['item'] = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent', 'guid',
                        'contact-id', 'owner-id', 'author-id', 'type', 'wall', 'gravity', 'extid',
-                       'created', 'edited', 'commented', 'received', 'changed', 'psid', 'uri-hash',
+                       'created', 'edited', 'commented', 'received', 'changed', 'psid',
                        'resource-id', 'event-id', 'tag', 'attach', 'post-type', 'file',
                        'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
                        'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global',
@@ -665,11 +666,11 @@ class Item extends BaseObject
                }
 
                if (strpos($sql_commands, "`item-activity`.") !== false) {
-                       $joins .= " LEFT JOIN `item-activity` ON `item-activity`.`id` = `item`.`iaid`";
+                       $joins .= " LEFT JOIN `item-activity` ON `item-activity`.`uri-id` = `item`.`uri-id`";
                }
 
                if (strpos($sql_commands, "`item-content`.") !== false) {
-                       $joins .= " LEFT JOIN `item-content` ON `item-content`.`id` = `item`.`icid`";
+                       $joins .= " LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id`";
                }
 
                if (strpos($sql_commands, "`item-delivery-data`.") !== false) {
@@ -765,19 +766,6 @@ class Item extends BaseObject
                return $query;
        }
 
-       /**
-        * @brief Generate a server unique item hash for linking between the item tables
-        *
-        * @param string $uri     Item URI
-        * @param date   $created Item creation date
-        *
-        * @return string the item hash
-        */
-       private static function itemHash($uri, $created)
-       {
-               return round(strtotime($created) / 100) . hash('ripemd128', $uri);
-       }
-
        /**
         * @brief Update existing item entries
         *
@@ -803,7 +791,7 @@ class Item extends BaseObject
                // We cannot simply expand the condition to check for origin entries
                // The condition needn't to be a simple array but could be a complex condition.
                // And we have to execute this query before the update to ensure to fetch the same data.
-               $items = DBA::select('item', ['id', 'origin', 'uri', 'created', 'uri-hash', 'iaid', 'icid', 'tag', 'file'], $condition);
+               $items = DBA::select('item', ['id', 'origin', 'uri', 'uri-id', 'iaid', 'icid', 'tag', 'file'], $condition);
 
                $content_fields = [];
                foreach (array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST) as $field) {
@@ -858,34 +846,11 @@ class Item extends BaseObject
                $rows = DBA::affectedRows();
 
                while ($item = DBA::fetch($items)) {
-
-                       // This part here can safely be removed when the legacy fields in the item had been removed
-                       if (empty($item['uri-hash']) && !empty($item['uri']) && !empty($item['created'])) {
-
-                               // Fetch the uri-hash from an existing item entry if there is one
-                               $item_condition = ["`uri` = ? AND `uri-hash` != ''", $item['uri']];
-                               $existing = DBA::selectfirst('item', ['uri-hash'], $item_condition);
-                               if (DBA::isResult($existing)) {
-                                       $item['uri-hash'] = $existing['uri-hash'];
-                               } else {
-                                       $item['uri-hash'] = self::itemHash($item['uri'], $item['created']);
-                               }
-
-                               DBA::update('item', ['uri-hash' => $item['uri-hash']], ['id' => $item['id']]);
-                               DBA::update('item-activity', ['uri-hash' => $item['uri-hash']], ["`uri` = ? AND `uri-hash` = ''", $item['uri']]);
-                               DBA::update('item-content', ['uri-plink-hash' => $item['uri-hash']], ["`uri` = ? AND `uri-plink-hash` = ''", $item['uri']]);
-                       }
-
                        if (!empty($item['iaid']) || (!empty($content_fields['verb']) && (self::activityToIndex($content_fields['verb']) >= 0))) {
-                               if (!empty($item['iaid'])) {
-                                       $update_condition = ['id' => $item['iaid']];
-                               } else {
-                                       $update_condition = ['uri-hash' => $item['uri-hash']];
-                               }
-                               self::updateActivity($content_fields, $update_condition);
+                               self::updateActivity($content_fields, ['uri-id' => $item['uri-id']]);
 
                                if (empty($item['iaid'])) {
-                                       $item_activity = DBA::selectFirst('item-activity', ['id'], ['uri-hash' => $item['uri-hash']]);
+                                       $item_activity = DBA::selectFirst('item-activity', ['id'], ['uri-id' => $item['uri-id']]);
                                        if (DBA::isResult($item_activity)) {
                                                $item_fields = ['iaid' => $item_activity['id'], 'icid' => null];
                                                foreach (self::MIXED_CONTENT_FIELDLIST as $field) {
@@ -909,15 +874,10 @@ class Item extends BaseObject
                                        }
                                }
                        } else {
-                               if (!empty($item['icid'])) {
-                                       $update_condition = ['id' => $item['icid']];
-                               } else {
-                                       $update_condition = ['uri-plink-hash' => $item['uri-hash']];
-                               }
-                               self::updateContent($content_fields, $update_condition);
+                               self::updateContent($content_fields, ['uri-id' => $item['uri-id']]);
 
                                if (empty($item['icid'])) {
-                                       $item_content = DBA::selectFirst('item-content', [], ['uri-plink-hash' => $item['uri-hash']]);
+                                       $item_content = DBA::selectFirst('item-content', [], ['uri-id' => $item['uri-id']]);
                                        if (DBA::isResult($item_content)) {
                                                $item_fields = ['icid' => $item_content['id']];
                                                // Clear all fields in the item table that have a content in the item-content table
@@ -1380,13 +1340,6 @@ class Item extends BaseObject
                        }
                }
 
-               // Ensure to always have the same creation date.
-               $existing = self::selectfirst(['created', 'uri-hash'], ['uri' => $item['uri']]);
-               if (DBA::isResult($existing)) {
-                       $item['created'] = $existing['created'];
-                       $item['uri-hash'] = $existing['uri-hash'];
-               }
-
                $item['wall']          = intval(defaults($item, 'wall', 0));
                $item['extid']         = trim(defaults($item, 'extid', ''));
                $item['author-name']   = trim(defaults($item, 'author-name', ''));
@@ -1429,9 +1382,6 @@ class Item extends BaseObject
                $item['inform']        = trim(defaults($item, 'inform', ''));
                $item['file']          = trim(defaults($item, 'file', ''));
 
-               // Unique identifier to be linked against item-activities and item-content
-               $item['uri-hash']      = defaults($item, 'uri-hash', self::itemHash($item['uri'], $item['created']));
-
                // When there is no content then we don't post it
                if ($item['body'].$item['title'] == '') {
                        logger('No body, no title.');
@@ -1927,8 +1877,7 @@ class Item extends BaseObject
                        return false;
                }
 
-               $fields = ['uri' => $item['uri'], 'activity' => $activity_index,
-                       'uri-hash' => $item['uri-hash'], 'uri-id' => $item['uri-id']];
+               $fields = ['activity' => $activity_index, 'uri-hash' => (string)$item['uri-id'], 'uri-id' => $item['uri-id']];
 
                // We just remove everything that is content
                foreach (array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST) as $field) {
@@ -1942,7 +1891,7 @@ class Item extends BaseObject
                }
 
                // Do we already have this content?
-               $item_activity = DBA::selectFirst('item-activity', ['id'], ['uri-hash' => $item['uri-hash']]);
+               $item_activity = DBA::selectFirst('item-activity', ['id'], ['uri-id' => $item['uri-id']]);
                if (DBA::isResult($item_activity)) {
                        $item['iaid'] = $item_activity['id'];
                        logger('Fetched activity for URI ' . $item['uri'] . ' (' . $item['iaid'] . ')');
@@ -1968,8 +1917,7 @@ class Item extends BaseObject
         */
        private static function insertContent(&$item)
        {
-               $fields = ['uri' => $item['uri'], 'uri-plink-hash' => $item['uri-hash'],
-                       'uri-id' => $item['uri-id']];
+               $fields = ['uri-plink-hash' => (string)$item['uri-id'], 'uri-id' => $item['uri-id']];
 
                foreach (array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST) as $field) {
                        if (isset($item[$field])) {
@@ -1985,7 +1933,7 @@ class Item extends BaseObject
                }
 
                // Do we already have this content?
-               $item_content = DBA::selectFirst('item-content', ['id'], ['uri-plink-hash' => $item['uri-hash']]);
+               $item_content = DBA::selectFirst('item-content', ['id'], ['uri-id' => $item['uri-id']]);
                if (DBA::isResult($item_content)) {
                        $item['icid'] = $item_content['id'];
                        logger('Fetched content for URI ' . $item['uri'] . ' (' . $item['icid'] . ')');
@@ -3060,7 +3008,7 @@ class Item extends BaseObject
                        $uid = local_user();
                }
 
-               if (!can_write_wall($uid)) {
+               if (!Security::canWriteToUserWall($uid)) {
                        logger('like: unable to write on wall ' . $uid);
                        return false;
                }
@@ -3246,4 +3194,41 @@ class Item extends BaseObject
                        }
                }
        }
+
+       public static function getPermissionsSQLByUserId($owner_id, $remote_verified = false, $groups = null)
+       {
+               $local_user = local_user();
+               $remote_user = remote_user();
+
+               /*
+                * Construct permissions
+                *
+                * default permissions - anonymous user
+                */
+               $sql = " AND NOT `item`.`private`";
+
+               // Profile owner - everything is visible
+               if ($local_user && ($local_user == $owner_id)) {
+                       $sql = '';
+               } elseif ($remote_user) {
+                       /*
+                        * Authenticated visitor. Unless pre-verified,
+                        * check that the contact belongs to this $owner_id
+                        * and load the groups the visitor belongs to.
+                        * If pre-verified, the caller is expected to have already
+                        * done this and passed the groups into this function.
+                        */
+                       $set = PermissionSet::get($owner_id, $remote_user, $groups);
+
+                       if (!empty($set)) {
+                               $sql_set = " OR (`item`.`private` IN (1,2) AND `item`.`wall` AND `item`.`psid` IN (" . implode(',', $set) . "))";
+                       } else {
+                               $sql_set = '';
+                       }
+
+                       $sql = " AND (NOT `item`.`private`" . $sql_set . ")";
+               }
+
+               return $sql;
+       }
 }
index e64158e175ced54a67d79fecf190be2965c561b5..a9b4c0fb736fd139957518921de46f03cac308d5 100644 (file)
@@ -14,6 +14,7 @@ use Friendica\Database\DBA;
 use Friendica\Object\Image;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
+use Friendica\Util\Security;
 
 require_once 'include/dba.php';
 
@@ -114,7 +115,7 @@ class Photo
                $type = Image::guessType($image_url, true);
                $Image = new Image($img_str, $type);
                if ($Image->isValid()) {
-                       $Image->scaleToSquare(175);
+                       $Image->scaleToSquare(300);
 
                        $r = self::store($Image, $uid, $cid, $hash, $filename, 'Contact Photos', 4);
 
@@ -171,7 +172,7 @@ class Photo
                }
 
                if ($photo_failure) {
-                       $image_url = System::baseUrl() . '/images/person-175.jpg';
+                       $image_url = System::baseUrl() . '/images/person-300.jpg';
                        $thumb = System::baseUrl() . '/images/person-80.jpg';
                        $micro = System::baseUrl() . '/images/person-48.jpg';
                }
@@ -226,7 +227,7 @@ class Photo
         */
        public static function getAlbums($uid, $update = false)
        {
-               $sql_extra = permissions_sql($uid);
+               $sql_extra = Security::getPermissionsSQLByUserId($uid);
 
                $key = "photo_albums:".$uid.":".local_user().":".remote_user();
                $albums = Cache::get($key);
@@ -252,7 +253,7 @@ class Photo
                                        DBA::escape(L10n::t('Contact Photos'))
                                );
                        }
-                       Cache::set($key, $albums, CACHE_DAY);
+                       Cache::set($key, $albums, Cache::DAY);
                }
                return $albums;
        }
@@ -264,7 +265,7 @@ class Photo
        public static function clearAlbumCache($uid)
        {
                $key = "photo_albums:".$uid.":".local_user().":".remote_user();
-               Cache::set($key, null, CACHE_DAY);
+               Cache::set($key, null, Cache::DAY);
        }
 
        /**
index 1f0773cd18c5998d6aac26b945a98071d6826967..53b98fb625ab636b6ae1bdc479663437c84b8876 100644 (file)
@@ -577,7 +577,7 @@ class Profile
                        );
                        if (DBA::isResult($s)) {
                                $r = DBA::toArray($s);
-                               Cache::set($cachekey, $r, CACHE_HOUR);
+                               Cache::set($cachekey, $r, Cache::HOUR);
                        }
                }
 
@@ -774,7 +774,7 @@ class Profile
                                $profile['marital']['with'] = $a->profile['with'];
                        }
 
-                       if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
+                       if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= DBA::NULL_DATETIME) {
                                $profile['howlong'] = Temporal::getRelativeDate($a->profile['howlong'], L10n::t('for %1$d %2$s'));
                        }
 
@@ -1037,7 +1037,7 @@ class Profile
                        logger('URL ' . $my_url . ' already tried to authenticate.', LOGGER_DEBUG);
                        return;
                } else {
-                       Cache::set($cachekey, true, CACHE_MINUTE);
+                       Cache::set($cachekey, true, Cache::MINUTE);
                }
 
                logger('Not authenticated. Invoking reverse magic-auth for ' . $my_url, LOGGER_DEBUG);
@@ -1047,7 +1047,7 @@ class Profile
                // Try to avoid recursion - but send them home to do a proper magic auth.
                $query = str_replace(array('?zrl=', '&zid='), array('?rzrl=', '&rzrl='), $a->query_string);
                // The other instance needs to know where to redirect.
-               $dest = urlencode(System::baseUrl() . '/' . $query);
+               $dest = urlencode($a->getBaseURL() . '/' . $query);
 
                // We need to extract the basebath from the profile url
                // to redirect the visitors '/magic' module.
@@ -1055,14 +1055,14 @@ class Profile
                $urlarr = explode('/profile/', $contact['url']);
                $basepath = $urlarr[0];
 
-               if ($basepath != System::baseUrl() && !strstr($dest, '/magic') && !strstr($dest, '/rmagic')) {
+               if ($basepath != $a->getBaseURL() && !strstr($dest, '/magic') && !strstr($dest, '/rmagic')) {
                        $magic_path = $basepath . '/magic' . '?f=&owa=1&dest=' . $dest;
 
                        // We have to check if the remote server does understand /magic without invoking something
                        $serverret = Network::curl($basepath . '/magic');
                        if ($serverret->isSuccess()) {
                                logger('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path, LOGGER_DEBUG);
-                               goaway($magic_path);
+                               System::externalRedirect($magic_path);
                        }
                }
        }
index 9680d359d09637c1007a302b46f3d36d221b4827..e024878a5821d7f33d6777ec581501e3ba5d2abb 100644 (file)
@@ -21,7 +21,7 @@ class PushSubscriber
        public static function publishFeed($uid, $default_priority = PRIORITY_HIGH)
        {
                $condition = ['push' => 0, 'uid' => $uid];
-               DBA::update('push_subscriber', ['push' => 1, 'next_try' => NULL_DATE], $condition);
+               DBA::update('push_subscriber', ['push' => 1, 'next_try' => DBA::NULL_DATETIME], $condition);
 
                self::requeue($default_priority);
        }
@@ -114,10 +114,10 @@ class PushSubscriber
                        $days = round((time() -  strtotime($subscriber['renewed'])) / (60 * 60 * 24));
 
                        if ($days > 60) {
-                               DBA::update('push_subscriber', ['push' => -1, 'next_try' => NULL_DATE], ['id' => $id]);
+                               DBA::update('push_subscriber', ['push' => -1, 'next_try' => DBA::NULL_DATETIME], ['id' => $id]);
                                logger('Delivery error: Subscription ' . $subscriber['callback_url'] . ' for ' . $subscriber['nickname'] . ' is marked as ended.', LOGGER_DEBUG);
                        } else {
-                               DBA::update('push_subscriber', ['push' => 0, 'next_try' => NULL_DATE], ['id' => $id]);
+                               DBA::update('push_subscriber', ['push' => 0, 'next_try' => DBA::NULL_DATETIME], ['id' => $id]);
                                logger('Delivery error: Giving up ' . $subscriber['callback_url'] . ' for ' . $subscriber['nickname'] . ' for now.', LOGGER_DEBUG);
                        }
                } else {
@@ -146,7 +146,7 @@ class PushSubscriber
                }
 
                // set last_update to the 'created' date of the last item, and reset push=0
-               $fields = ['push' => 0, 'next_try' => NULL_DATE, 'last_update' => $last_update];
+               $fields = ['push' => 0, 'next_try' => DBA::NULL_DATETIME, 'last_update' => $last_update];
                DBA::update('push_subscriber', $fields, ['id' => $id]);
                logger('Subscriber ' . $subscriber['callback_url'] . ' for ' . $subscriber['nickname'] . ' is marked as vital', LOGGER_DEBUG);
        }
diff --git a/src/Model/Register.php b/src/Model/Register.php
new file mode 100644 (file)
index 0000000..e54db87
--- /dev/null
@@ -0,0 +1,131 @@
+<?php
+
+/**
+ * @file src/Model/Register.php
+ */
+namespace Friendica\Model;
+
+use Friendica\Database\DBA;
+use Friendica\Util\DateTimeFormat;
+
+/**
+ * Class interacting with the register database table
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class Register
+{
+       /**
+        * Return the list of pending registrations
+        *
+        * @return array
+        */
+       public static function getPending()
+       {
+               $stmt = DBA::p(
+                       "SELECT `register`.*, `contact`.`name`, `user`.`email`
+                       FROM `register`
+                       INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
+                       INNER JOIN `user` ON `register`.`uid` = `user`.`uid`"
+               );
+
+               return DBA::toArray($stmt);
+       }
+
+       /**
+        * Returns the pending registration count
+        *
+        * @return int
+        */
+       public static function getPendingCount()
+       {
+               $register = DBA::fetchFirst(
+                       "SELECT COUNT(*) AS `count`
+                       FROM `register`
+                       INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` AND `contact`.`self`"
+               );
+
+               return $register['count'];
+       }
+
+       /**
+        * Returns the register record associated with the provided hash
+        *
+        * @param  string $hash
+        * @return array
+        */
+       public static function getByHash($hash)
+       {
+               return DBA::selectFirst('register', [], ['hash' => $hash]);
+       }
+
+       /**
+        * Returns true if a register record exists with the provided hash
+        *
+        * @param  string  $hash
+        * @return boolean
+        */
+       public static function existsByHash($hash)
+       {
+               return DBA::exists('register', ['hash' => $hash]);
+       }
+
+       /**
+        * Creates a register record for an invitation and returns the auto-generated code for it
+        *
+        * @return string
+        */
+       public static function createForInvitation()
+       {
+               $code = autoname(8) . srand(1000, 9999);
+
+               $fields = [
+                       'hash' => $code,
+                       'created' => DateTimeFormat::utcNow()
+               ];
+
+               DBA::insert('register', $fields);
+
+               return $code;
+       }
+
+       /**
+        * Creates a register record for approval and returns the success of the database insert
+        * Checks for the existence of the provided user id
+        *
+        * @param  integer $uid      The ID of the user needing approval
+        * @param  string  $language The registration language
+        * @param  string  $note     An additional message from the user
+        * @return boolean
+        */
+       public static function createForApproval($uid, $language, $note = '')
+       {
+               $hash = random_string();
+
+               if (!User::exists($uid)) {
+                       return false;
+               }
+
+               $fields = [
+                       'hash'     => $hash,
+                       'created'  => DateTimeFormat::utcNow(),
+                       'uid'      => $uid,
+                       'password' => '', // Obsolete, slated for deletion
+                       'language' => $language,
+                       'note'     => $note
+               ];
+
+               return DBA::insert('register', $fields);
+       }
+
+       /**
+        * Deletes a register record by the provided hash and returns the success of the database deletion
+        *
+        * @param  string  $hash
+        * @return boolean
+        */
+       public static function deleteByHash($hash)
+       {
+               return DBA::delete('register', ['hash' => $hash]);
+       }
+}
index b8b694de87194a6bd6e143c9672c4b49782e9e2d..bdea5e28f0dfe1863e02041443dd259886fafc1f 100644 (file)
@@ -5,7 +5,7 @@
  */
 namespace Friendica\Model;
 
-use DivineOmega\PasswordExposed\PasswordStatus;
+use DivineOmega\PasswordExposed;
 use Exception;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
@@ -20,7 +20,6 @@ use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use LightOpenID;
-use function password_exposed;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
@@ -32,9 +31,29 @@ require_once 'include/text.php';
 class User
 {
        /**
-        * @brief Returns the user id of a given profile url
+        * Returns true if a user record exists with the provided id
         *
-        * @param string $profile
+        * @param  integer $uid
+        * @return boolean
+        */
+       public static function exists($uid)
+       {
+               return DBA::exists('user', ['uid' => $uid]);
+       }
+
+       /**
+        * @param  integer       $uid
+        * @return array|boolean User record if it exists, false otherwise
+        */
+       public static function getById($uid)
+       {
+               return DBA::selectFirst('user', [], ['uid' => $uid]);
+       }
+
+       /**
+        * @brief Returns the user id of a given profile URL
+        *
+        * @param string $url
         *
         * @return integer user id
         */
@@ -260,7 +279,14 @@ class User
         */
        public static function isPasswordExposed($password)
        {
-               return password_exposed($password) === PasswordStatus::EXPOSED;
+               $cache = new \DivineOmega\DOFileCachePSR6\CacheItemPool();
+               $cache->changeConfig([
+                       'cacheDirectory' => get_temppath() . '/password-exposed-cache/',
+               ]);
+
+               $PasswordExposedCHecker = new PasswordExposed\PasswordExposedChecker(null, $cache);
+
+               return $PasswordExposedCHecker->passwordExposed($password) === PasswordExposed\PasswordStatus::EXPOSED;
        }
 
        /**
@@ -401,7 +427,7 @@ class User
                                throw new Exception(L10n::t('An invitation is required.'));
                        }
 
-                       if (!DBA::exists('register', ['hash' => $invite_id])) {
+                       if (!Register::existsByHash($invite_id)) {
                                throw new Exception(L10n::t('Invitation could not be verified.'));
                        }
                }
@@ -424,7 +450,7 @@ class User
                                } catch (Exception $e) {
                                        throw new Exception(L10n::t('We encountered a problem while logging in with the OpenID you provided. Please check the correct spelling of the ID.') . EOL . EOL . L10n::t('The error message was:') . $e->getMessage(), 0, $e);
                                }
-                               goaway($authurl);
+                               System::externalRedirect($authurl);
                                // NOTREACHED
                        }
 
@@ -440,19 +466,30 @@ class User
                // collapse multiple spaces in name
                $username = preg_replace('/ +/', ' ', $username);
 
-               if (mb_strlen($username) > 48) {
-                       throw new Exception(L10n::t('Please use a shorter name.'));
+               $username_min_length = max(1, min(64, intval(Config::get('system', 'username_min_length', 3))));
+               $username_max_length = max(1, min(64, intval(Config::get('system', 'username_max_length', 48))));
+
+               if ($username_min_length > $username_max_length) {
+                       logger(L10n::t('system.username_min_length (%s) and system.username_max_length (%s) are excluding each other, swapping values.', $username_min_length, $username_max_length), LOGGER_WARNING);
+                       $tmp = $username_min_length;
+                       $username_min_length = $username_max_length;
+                       $username_max_length = $tmp;
+               }
+
+               if (mb_strlen($username) < $username_min_length) {
+                       throw new Exception(L10n::tt('Username should be at least %s character.', 'Username should be at least %s characters.', $username_min_length));
                }
-               if (mb_strlen($username) < 3) {
-                       throw new Exception(L10n::t('Name too short.'));
+
+               if (mb_strlen($username) > $username_max_length) {
+                       throw new Exception(L10n::tt('Username should be at most %s character.', 'Username should be at most %s characters.', $username_max_length));
                }
 
                // So now we are just looking for a space in the full name.
                $loose_reg = Config::get('system', 'no_regfullname');
                if (!$loose_reg) {
                        $username = mb_convert_case($username, MB_CASE_TITLE, 'UTF-8');
-                       if (!strpos($username, ' ')) {
-                               throw new Exception(L10n::t("That doesn't appear to be your full \x28First Last\x29 name."));
+                       if (strpos($username, ' ') === false) {
+                               throw new Exception(L10n::t("That doesn't appear to be your full (First Last) name."));
                        }
                }
 
@@ -605,7 +642,7 @@ class User
 
                        $Image = new Image($img_str, $type);
                        if ($Image->isValid()) {
-                               $Image->scaleToSquare(175);
+                               $Image->scaleToSquare(300);
 
                                $hash = Photo::newResource();
 
@@ -644,27 +681,36 @@ class User
        }
 
        /**
-        * @brief Sends pending registration confiÅ•mation email
+        * @brief Sends pending registration confirmation email
         *
-        * @param string $email
+        * @param array  $user     User record array
         * @param string $sitename
-        * @param string $username
+        * @param string $siteurl
+        * @param string $password Plaintext password
         * @return NULL|boolean from notification() and email() inherited
         */
-       public static function sendRegisterPendingEmail($email, $sitename, $username)
+       public static function sendRegisterPendingEmail($user, $sitename, $siteurl, $password)
        {
                $body = deindent(L10n::t('
                        Dear %1$s,
                                Thank you for registering at %2$s. Your account is pending for approval by the administrator.
-               '));
 
-               $body = sprintf($body, $username, $sitename);
+                       Your login details are as follows:
+
+                       Site Location:  %3$s
+                       Login Name:             %4$s
+                       Password:               %5$s
+               ',
+                       $user['username'], $sitename, $siteurl, $user['nickname'], $password
+               ));
 
                return notification([
-                       'type' => SYSTEM_EMAIL,
-                       'to_email' => $email,
-                       'subject'=> L10n::t('Registration at %s', $sitename),
-                       'body' => $body]);
+                       'type'     => SYSTEM_EMAIL,
+                       'uid'      => $user['uid'],
+                       'to_email' => $user['email'],
+                       'subject'  => L10n::t('Registration at %s', $sitename),
+                       'body'     => $body
+               ]);
        }
 
        /**
@@ -672,19 +718,20 @@ class User
         *
         * It's here as a function because the mail is sent from different parts
         *
-        * @param string $email
+        * @param array  $user     User record array
         * @param string $sitename
         * @param string $siteurl
-        * @param string $username
-        * @param string $password
+        * @param string $password Plaintext password
         * @return NULL|boolean from notification() and email() inherited
         */
-       public static function sendRegisterOpenEmail($email, $sitename, $siteurl, $username, $password, $user)
+       public static function sendRegisterOpenEmail($user, $sitename, $siteurl, $password)
        {
                $preamble = deindent(L10n::t('
                        Dear %1$s,
                                Thank you for registering at %2$s. Your account has been created.
-               '));
+               ',
+                       $preamble, $user['username'], $sitename
+               ));
                $body = deindent(L10n::t('
                        The login details are as follows:
 
@@ -711,19 +758,19 @@ class User
 
                        If you ever want to delete your account, you can do so at %3$s/removeme
 
-                       Thank you and welcome to %2$s.'));
-
-               $preamble = sprintf($preamble, $username, $sitename);
-               $body = sprintf($body, $email, $sitename, $siteurl, $username, $password);
+                       Thank you and welcome to %2$s.',
+                       $user['email'], $sitename, $siteurl, $user['username'], $password
+               ));
 
                return notification([
-                       'uid' => $user['uid'],
+                       'uid'      => $user['uid'],
                        'language' => $user['language'],
-                       'type' => SYSTEM_EMAIL,
-                       'to_email' => $email,
-                       'subject'=> L10n::t('Registration details for %s', $sitename),
-                       'preamble'=> $preamble,
-                       'body' => $body]);
+                       'type'     => SYSTEM_EMAIL,
+                       'to_email' => $user['email'],
+                       'subject'  => L10n::t('Registration details for %s', $sitename),
+                       'preamble' => $preamble,
+                       'body'     => $body
+               ]);
        }
 
        /**
@@ -736,6 +783,8 @@ class User
                        return;
                }
 
+               $a = get_app();
+
                logger('Removing user: ' . $uid);
 
                $user = DBA::selectFirst('user', [], ['uid' => $uid]);
@@ -760,7 +809,7 @@ class User
                if ($uid == local_user()) {
                        unset($_SESSION['authenticated']);
                        unset($_SESSION['uid']);
-                       goaway(System::baseUrl());
+                       $a->internalRedirect();
                }
        }
 }
index 29aa99140c5316948c5035d791b26ebb712dc805..692e905914472081306002f19ef6ac74fb258b06 100644 (file)
@@ -4,6 +4,7 @@ namespace Friendica\Module;
 
 use Friendica\BaseModule;
 use Friendica\Network\Probe;
+use Friendica\Core\System;
 
 /**
  * Redirects to another URL based on the parameter 'addr'
@@ -18,7 +19,7 @@ class Acctlink extends BaseModule
                        $url = defaults(Probe::uri(trim($addr)), 'url', false);
 
                        if ($url) {
-                               goaway($url);
+                               System::externalRedirect($url);
                                exit();
                        }
                }
index 0eb912e00a7b962d5c5f13bfcedc623d643f4f19..fb0bf0edeeab4341cd84b67a0a74c8ba88104264 100644 (file)
@@ -8,6 +8,7 @@ use Friendica\Content\ContactSelector;
 use Friendica\Content\Nav;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Widget;
+use Friendica\Core\ACL;
 use Friendica\Core\Addon;
 use Friendica\Core\L10n;
 use Friendica\Core\Protocol;
@@ -15,11 +16,10 @@ use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model;
+use Friendica\Module\Login;
 use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Proxy as ProxyUtils;
-use Friendica\Core\ACL;
-use Friendica\Module\Login;
 
 /**
  *  Manages and show Contacts and their content
@@ -66,9 +66,9 @@ class Contact extends BaseModule
                if (DBA::isResult($contact)) {
                        if ($contact['self']) {
                                if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) {
-                                       goaway('profile/' . $contact['nick']);
+                                       $a->internalRedirect('profile/' . $contact['nick']);
                                } else {
-                                       goaway('profile/' . $contact['nick'] . '?tab=profile');
+                                       $a->internalRedirect('profile/' . $contact['nick'] . '?tab=profile');
                                }
                        }
 
@@ -168,7 +168,7 @@ class Contact extends BaseModule
                        info(L10n::tt('%d contact edited.', '%d contacts edited.', $count_actions));
                }
 
-               goaway('contact');
+               $a->internalRedirect('contact');
        }
 
        public static function post()
@@ -191,7 +191,7 @@ class Contact extends BaseModule
 
                if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
                        notice(L10n::t('Could not access contact record.') . EOL);
-                       goaway('contact');
+                       $a->internalRedirect('contact');
                        return; // NOTREACHED
                }
 
@@ -374,19 +374,19 @@ class Contact extends BaseModule
                        $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false]);
                        if (!DBA::isResult($orig_record)) {
                                notice(L10n::t('Could not access contact record.') . EOL);
-                               goaway('contact');
+                               $a->internalRedirect('contact');
                                return; // NOTREACHED
                        }
 
                        if ($cmd === 'update' && ($orig_record['uid'] != 0)) {
                                self::updateContactFromPoll($contact_id);
-                               goaway('contact/' . $contact_id);
+                               $a->internalRedirect('contact/' . $contact_id);
                                // NOTREACHED
                        }
 
                        if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) {
                                self::updateContactFromProbe($contact_id);
-                               goaway('crepair/' . $contact_id);
+                               $a->internalRedirect('crepair/' . $contact_id);
                                // NOTREACHED
                        }
 
@@ -396,7 +396,7 @@ class Contact extends BaseModule
                                $blocked = Model\Contact::isBlockedByUser($contact_id, local_user());
                                info(($blocked ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL);
 
-                               goaway('contact/' . $contact_id);
+                               $a->internalRedirect('contact/' . $contact_id);
                                return; // NOTREACHED
                        }
 
@@ -406,7 +406,7 @@ class Contact extends BaseModule
                                $ignored = Model\Contact::isIgnoredByUser($contact_id, local_user());
                                info(($ignored ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL);
 
-                               goaway('contact/' . $contact_id);
+                               $a->internalRedirect('contact/' . $contact_id);
                                return; // NOTREACHED
                        }
 
@@ -417,7 +417,7 @@ class Contact extends BaseModule
                                        info((($archived) ? L10n::t('Contact has been archived') : L10n::t('Contact has been unarchived')) . EOL);
                                }
 
-                               goaway('contact/' . $contact_id);
+                               $a->internalRedirect('contact/' . $contact_id);
                                return; // NOTREACHED
                        }
 
@@ -451,13 +451,13 @@ class Contact extends BaseModule
                                }
                                // Now check how the user responded to the confirmation query
                                if (!empty($_REQUEST['canceled'])) {
-                                       goaway('contact');
+                                       $a->internalRedirect('contact');
                                }
 
                                self::dropContact($orig_record);
                                info(L10n::t('Contact has been removed.') . EOL);
 
-                               goaway('contact');
+                               $a->internalRedirect('contact');
                                return; // NOTREACHED
                        }
                        if ($cmd === 'posts') {
@@ -468,7 +468,7 @@ class Contact extends BaseModule
                        }
                }
 
-               $_SESSION['return_url'] = $a->query_string;
+               $_SESSION['return_path'] = $a->query_string;
 
                if (!empty($a->data['contact']) && is_array($a->data['contact'])) {
                        $contact_id = $a->data['contact']['id'];
@@ -522,9 +522,9 @@ class Contact extends BaseModule
 
                        $insecure = L10n::t('Private communications are not available for this contact.');
 
-                       $last_update = (($contact['last-update'] <= NULL_DATE) ? L10n::t('Never') : DateTimeFormat::local($contact['last-update'], 'D, j M Y, g:i A'));
+                       $last_update = (($contact['last-update'] <= DBA::NULL_DATETIME) ? L10n::t('Never') : DateTimeFormat::local($contact['last-update'], 'D, j M Y, g:i A'));
 
-                       if ($contact['last-update'] > NULL_DATE) {
+                       if ($contact['last-update'] > DBA::NULL_DATETIME) {
                                $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? L10n::t('(Update was successful)') : L10n::t('(Update was not successful)'));
                        }
                        $lblsuggest = (($contact['network'] === Protocol::DFRN) ? L10n::t('Suggest friends') : '');
@@ -536,7 +536,7 @@ class Contact extends BaseModule
                        // tabs
                        $tab_str = self::getTabsHTML($a, $contact, 3);
 
-                       $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < DateTimeFormat::utcNow()) ? L10n::t('Communications lost with this contact!') : '');
+                       $lost_contact = (($contact['archive'] && $contact['term-date'] > DBA::NULL_DATETIME && $contact['term-date'] < DateTimeFormat::utcNow()) ? L10n::t('Communications lost with this contact!') : '');
 
                        $fetch_further_information = null;
                        if ($contact['network'] == Protocol::FEED) {
diff --git a/src/Module/Itemsource.php b/src/Module/Itemsource.php
new file mode 100644 (file)
index 0000000..bcbd557
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\Core\L10n;
+use Friendica\Model;
+
+/**
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class Itemsource extends \Friendica\BaseModule
+{
+       public static function content()
+       {
+               if (!is_site_admin()) {
+                       return;
+               }
+
+               $source = '';
+               $item_uri = '';
+               if (!empty($_REQUEST['guid'])) {
+                       $item = Model\Item::selectFirst([], ['guid' => $_REQUEST['guid']]);
+
+                       $conversation = Model\Conversation::getByItemUri($item['uri']);
+
+                       $item_uri = $item['uri'];
+                       $source = htmlspecialchars($conversation['source']);
+               }
+
+               $tpl = get_markup_template('debug/itemsource.tpl');
+               $o = replace_macros($tpl, [
+                       '$guid'          => ['guid', L10n::t('Item Guid'), htmlentities(defaults($_REQUEST, 'guid', '')), ''],
+                       '$source'        => $source,
+                       '$item_uri'      => $item_uri
+               ]);
+
+               return $o;
+       }
+}
index 15505a38be61295c8118d9b449a4da51b2daed7b..df918c44c8ed0aee91af7e6e2b774486f4e287f8 100644 (file)
@@ -7,8 +7,10 @@ namespace Friendica\Module;
 use Exception;
 use Friendica\BaseModule;
 use Friendica\Core\Addon;
+use Friendica\Core\Authentication;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
+use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\User;
 use Friendica\Util\DateTimeFormat;
@@ -16,7 +18,6 @@ use Friendica\Util\Network;
 use LightOpenID;
 
 require_once 'boot.php';
-require_once 'include/security.php';
 require_once 'include/text.php';
 
 /**
@@ -39,17 +40,17 @@ class Login extends BaseModule
                }
 
                if (local_user()) {
-                       goaway(self::getApp()->getBaseURL());
+                       $a->internalRedirect();
                }
 
-               return self::form($_SESSION['return_url'], intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED);
+               return self::form($_SESSION['return_path'], intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED);
        }
 
        public static function post()
        {
-               $return_url = $_SESSION['return_url'];
+               $return_path = $_SESSION['return_path'];
                session_unset();
-               $_SESSION['return_url'] = $return_url;
+               $_SESSION['return_path'] = $return_path;
                
                // OpenId Login
                if (
@@ -83,22 +84,23 @@ class Login extends BaseModule
        {
                $noid = Config::get('system', 'no_openid');
 
+               $a = self::getApp();
+
                // if it's an email address or doesn't resolve to a URL, fail.
                if ($noid || strpos($openid_url, '@') || !Network::isUrlValid($openid_url)) {
                        notice(L10n::t('Login failed.') . EOL);
-                       goaway(self::getApp()->getBaseURL());
+                       $a->internalRedirect();
                        // NOTREACHED
                }
 
                // Otherwise it's probably an openid.
                try {
-                       $a = get_app();
                        $openid = new LightOpenID($a->getHostName());
                        $openid->identity = $openid_url;
                        $_SESSION['openid'] = $openid_url;
                        $_SESSION['remember'] = $remember;
-                       $openid->returnUrl = self::getApp()->getBaseURL(true) . '/openid';
-                       goaway($openid->authUrl());
+                       $openid->returnUrl = $a->getBaseURL(true) . '/openid';
+                       System::externalRedirect($openid->authUrl());
                } catch (Exception $e) {
                        notice(L10n::t('We encountered a problem while logging in with the OpenID you provided. Please check the correct spelling of the ID.') . '<br /><br >' . L10n::t('The error message was:') . ' ' . $e->getMessage());
                }
@@ -122,6 +124,8 @@ class Login extends BaseModule
                        'user_record' => null
                ];
 
+               $a = self::getApp();
+
                /*
                 * An addon indicates successful login by setting 'authenticated' to non-zero value and returning a user record
                 * Addons should never set 'authenticated' except to indicate success - as hooks may be chained
@@ -144,26 +148,26 @@ class Login extends BaseModule
                } catch (Exception $e) {
                        logger('authenticate: failed login attempt: ' . notags($username) . ' from IP ' . $_SERVER['REMOTE_ADDR']);
                        info('Login failed. Please check your credentials.' . EOL);
-                       goaway('/');
+                       $a->internalRedirect();
                }
 
                if (!$remember) {
-                       new_cookie(0); // 0 means delete on browser exit
+                       Authentication::setCookie(0); // 0 means delete on browser exit
                }
 
                // if we haven't failed up this point, log them in.
                $_SESSION['remember'] = $remember;
                $_SESSION['last_login_date'] = DateTimeFormat::utcNow();
-               authenticate_success($record, true, true);
+               Authentication::setAuthenticatedSessionForUser($record, true, true);
 
-               if (x($_SESSION, 'return_url')) {
-                       $return_url = $_SESSION['return_url'];
-                       unset($_SESSION['return_url']);
+               if (x($_SESSION, 'return_path')) {
+                       $return_path = $_SESSION['return_path'];
+                       unset($_SESSION['return_path']);
                } else {
-                       $return_url = '';
+                       $return_path = '';
                }
 
-               goaway($return_url);
+               $a->internalRedirect($return_path);
        }
 
        /**
@@ -173,6 +177,8 @@ class Login extends BaseModule
         */
        public static function sessionAuth()
        {
+               $a = self::getApp();
+
                // When the "Friendica" cookie is set, take the value to authenticate and renew the cookie.
                if (isset($_COOKIE["Friendica"])) {
                        $data = json_decode($_COOKIE["Friendica"]);
@@ -188,21 +194,21 @@ class Login extends BaseModule
                                        ]
                                );
                                if (DBA::isResult($user)) {
-                                       if ($data->hash != cookie_hash($user)) {
+                                       if ($data->hash != Authentication::getCookieHashForUser($user)) {
                                                logger("Hash for user " . $data->uid . " doesn't fit.");
-                                               nuke_session();
-                                               goaway(self::getApp()->getBaseURL());
+                                               Authentication::deleteSession();
+                                               $a->internalRedirect();
                                        }
 
                                        // Renew the cookie
                                        // Expires after 7 days by default,
                                        // can be set via system.auth_cookie_lifetime
                                        $authcookiedays = Config::get('system', 'auth_cookie_lifetime', 7);
-                                       new_cookie($authcookiedays * 24 * 60 * 60, $user);
+                                       Authentication::setCookie($authcookiedays * 24 * 60 * 60, $user);
 
                                        // Do the authentification if not done by now
                                        if (!isset($_SESSION) || !isset($_SESSION['authenticated'])) {
-                                               authenticate_success($user);
+                                               Authentication::setAuthenticatedSessionForUser($user);
 
                                                if (Config::get('system', 'paranoia')) {
                                                        $_SESSION['addr'] = $data->ip;
@@ -227,8 +233,8 @@ class Login extends BaseModule
                                if ($check && ($_SESSION['addr'] != $_SERVER['REMOTE_ADDR'])) {
                                        logger('Session address changed. Paranoid setting in effect, blocking session. ' .
                                                $_SESSION['addr'] . ' != ' . $_SERVER['REMOTE_ADDR']);
-                                       nuke_session();
-                                       goaway(self::getApp()->getBaseURL());
+                                       Authentication::deleteSession();
+                                       $a->internalRedirect();
                                }
 
                                $user = DBA::selectFirst('user', [],
@@ -241,8 +247,8 @@ class Login extends BaseModule
                                        ]
                                );
                                if (!DBA::isResult($user)) {
-                                       nuke_session();
-                                       goaway(self::getApp()->getBaseURL());
+                                       Authentication::deleteSession();
+                                       $a->internalRedirect();
                                }
 
                                // Make sure to refresh the last login time for the user if the user
@@ -255,7 +261,7 @@ class Login extends BaseModule
                                        $_SESSION['last_login_date'] = DateTimeFormat::utcNow();
                                        $login_refresh = true;
                                }
-                               authenticate_success($user, false, false, $login_refresh);
+                               Authentication::setAuthenticatedSessionForUser($user, false, false, $login_refresh);
                        }
                }
        }
@@ -263,7 +269,7 @@ class Login extends BaseModule
        /**
         * @brief Wrapper for adding a login box.
         *
-        * @param string $return_url The url relative to the base the user should be sent
+        * @param string $return_path The path relative to the base the user should be sent
         *                                                       back to after login completes
         * @param bool $register If $register == true provide a registration link.
         *                                               This will most always depend on the value of config.register_policy.
@@ -273,7 +279,7 @@ class Login extends BaseModule
         *
         * @hooks 'login_hook' string $o
         */
-       public static function form($return_url = null, $register = false, $hiddens = [])
+       public static function form($return_path = null, $register = false, $hiddens = [])
        {
                $a = self::getApp();
                $o = '';
@@ -287,8 +293,8 @@ class Login extends BaseModule
 
                $noid = Config::get('system', 'no_openid');
 
-               if (is_null($return_url)) {
-                       $return_url = $a->query_string;
+               if (is_null($return_path)) {
+                       $return_path = $a->query_string;
                }
 
                if (local_user()) {
@@ -302,7 +308,7 @@ class Login extends BaseModule
                        );
 
                        $tpl = get_markup_template('login.tpl');
-                       $_SESSION['return_url'] = $return_url;
+                       $_SESSION['return_path'] = $return_path;
                }
 
                $o .= replace_macros(
index cbfd245f302f47f276cff27f8ee1ab1e192d0459..f212a894029cd6e9279e41e1dd520ef8f56c68a6 100644 (file)
@@ -6,10 +6,11 @@ namespace Friendica\Module;
 
 use Friendica\BaseModule;
 use Friendica\Core\Addon;
+use Friendica\Core\Authentication;
 use Friendica\Core\L10n;
+use Friendica\Core\System;
 
 require_once 'boot.php';
-require_once 'include/security.php';
 
 /**
  * Logout module
@@ -24,8 +25,8 @@ class Logout extends BaseModule
        public static function init()
        {
                Addon::callHooks("logging_out");
-               nuke_session();
+               Authentication::deleteSession();
                info(L10n::t('Logged out.') . EOL);
-               goaway(self::getApp()->getBaseURL());
+               self::getApp()->internalRedirect();
        }
 }
index 768fe69ebbedb94e410f2d6de19e8ba9e55d82ba..1d7cb715e1c4e26eecd481a19afa782185102f25 100644 (file)
@@ -7,6 +7,7 @@ namespace Friendica\Module;
 use Friendica\BaseModule;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
+use Friendica\Core\System;
 use Friendica\Util\HTTPSignature;
 use Friendica\Util\Network;
 
@@ -41,9 +42,13 @@ class Magic extends BaseModule
 
                if (!$cid) {
                        logger('No contact record found: ' . print_r($_REQUEST, true), LOGGER_DEBUG);
-                       goaway($dest);
+                       // @TODO Finding a more elegant possibility to redirect to either internal or external URL
+                       if (filter_var($dest, FILTER_VALIDATE_URL)) {
+                               System::externalRedirect($dest);
+                       } else {
+                               $a->internalRedirect($dest);
+                       }
                }
-
                $contact = DBA::selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]);
 
                // Redirect if the contact is already authenticated on this site.
@@ -55,7 +60,7 @@ class Magic extends BaseModule
                        }
 
                        logger('Contact is already authenticated', LOGGER_DEBUG);
-                       goaway($dest);
+                       System::externalRedirect($dest);
                }
 
                if (local_user()) {
@@ -99,10 +104,10 @@ class Magic extends BaseModule
                                                $x = strpbrk($dest, '?&');
                                                $args = (($x) ? '&owt=' . $token : '?f=&owt=' . $token);
 
-                                               goaway($dest . $args);
+                                               System::externalRedirect($dest . $args);
                                        }
                                }
-                               goaway($dest);
+                               System::externalRedirect($dest);
                        }
                }
 
@@ -111,6 +116,11 @@ class Magic extends BaseModule
                        return $ret;
                }
 
-               goaway($dest);
+               // @TODO Finding a more elegant possibility to redirect to either internal or external URL
+               if (filter_var($dest, FILTER_VALIDATE_URL)) {
+                       System::externalRedirect($dest);
+               } else {
+                       $a->internalRedirect($dest);
+               }
        }
 }
index ba9dace2e567295d825c908e364a6cf533a5e561..d51d5785a5b42f1b1518b92dfeb8aff0b7a739b1 100644 (file)
@@ -24,7 +24,7 @@ class Objects extends BaseModule
                }
 
                if (!ActivityPub::isRequest()) {
-                       goaway(str_replace('objects/', 'display/', $a->query_string));
+                       $a->internalRedirect(str_replace('objects/', 'display/', $a->query_string));
                }
 
                $item = Item::selectFirst(['id'], ['guid' => $a->argv[1], 'wall' => true, 'private' => false]);
index 776dcccb35b63276ed4be75bcf1b1f89a52423f1..29e0f4f52f4903c151419133d661a8a4335f9507 100644 (file)
@@ -17,8 +17,6 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Proxy as ProxyUtils;
 
-require_once 'include/security.php';
-
 /**
  * @brief Module Proxy
  */
@@ -105,7 +103,7 @@ class Proxy extends BaseModule
                                $sizetype = ':thumb';
                                $url = substr($url, 0, -6);
                        } elseif (substr($url, -6) == ':small') {
-                               $size = 175;
+                               $size = 300;
                                $url = substr($url, 0, -6);
                                $sizetype = ':small';
                        } elseif (substr($url, -7) == ':medium') {
index e8a152b5078f28577d1dd77a8914e6cc6d2456af..db8b55885ae2829aedb3754daf947106f275dc43 100644 (file)
@@ -49,7 +49,7 @@ class Tos extends BaseModule
        public static function init()
        {
                if (strlen(Config::get('system','singleuser'))) {
-                       goaway(System::baseUrl()."/profile/" . Config::get('system','singleuser'));
+                       self::getApp()->internalRedirect('profile/' . Config::get('system','singleuser'));
                }
        }
        /**
index 23b97a5cd060346da07652fc810e74d9cb9377fd..f892c3a5ccfc16cc69e027e5e57eb71923a2a60a 100644 (file)
@@ -348,7 +348,7 @@ class Probe
                if (x($data, "photo")) {
                        $data["baseurl"] = Network::getUrlMatch(normalise_link(defaults($data, "baseurl", "")), normalise_link($data["photo"]));
                } else {
-                       $data["photo"] = System::baseUrl().'/images/person-175.jpg';
+                       $data["photo"] = System::baseUrl().'/images/person-300.jpg';
                }
 
                if (empty($data["name"])) {
@@ -381,7 +381,7 @@ class Probe
 
                // Only store into the cache if the value seems to be valid
                if (!in_array($data['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
-                       Cache::set("Probe::uri:".$network.":".$uri, $data, CACHE_DAY);
+                       Cache::set("Probe::uri:".$network.":".$uri, $data, Cache::DAY);
 
                        /// @todo temporary fix - we need a real contact update function that updates only changing fields
                        /// The biggest problem is the avatar picture that could have a reduced image size.
index cd055ee5ebfa4e17eb4cf963219afaca2bfabdd2..08c04f546f3b6f93973073e100061b8ee000456d 100644 (file)
@@ -7,6 +7,7 @@ namespace Friendica\Object;
 use Friendica\BaseObject;
 use Friendica\Core\Protocol;
 use Friendica\Object\Post;
+use Friendica\Util\Security;
 
 require_once 'boot.php';
 require_once 'include/text.php';
@@ -61,11 +62,11 @@ class Thread extends BaseObject
                                break;
                        case 'profile':
                                $this->profile_owner = $a->profile['profile_uid'];
-                               $this->writable = can_write_wall($this->profile_owner);
+                               $this->writable = Security::canWriteToUserWall($this->profile_owner);
                                break;
                        case 'display':
                                $this->profile_owner = $a->profile['uid'];
-                               $this->writable = can_write_wall($this->profile_owner) || $writable;
+                               $this->writable = Security::canWriteToUserWall($this->profile_owner) || $writable;
                                break;
                        case 'community':
                                $this->profile_owner = 0;
index 0af8ee5e3545a157c96178eeb8455150eadefe10..23eb861721279a4a66a454306696d7b0c0342ddc 100644 (file)
@@ -63,7 +63,13 @@ class ActivityPub
                        return false;
                }
 
-               return json_decode($curlResult->getBody(), true);
+               $content = json_decode($curlResult->getBody(), true);
+
+               if (empty($content) || !is_array($content)) {
+                       return false;
+               }
+
+               return $content;
        }
 
        /**
index c481423a675c495349ad2d27c7d56f8009cbd5a9..8a80bd2beae2131a37e7deabdbb314746e553271 100644 (file)
@@ -17,10 +17,7 @@ use Friendica\Core\Config;
 use Friendica\Protocol\ActivityPub;
 
 /**
- * ActivityPub Protocol class
- *
- * To-Do:
- * - Store Diaspora signature
+ * ActivityPub Processor Protocol class
  */
 class Processor
 {
@@ -272,7 +269,7 @@ class Processor
                $activity['cc'] = defaults($object, 'cc', []);
                $activity['actor'] = $child['author'];
                $activity['object'] = $object;
-               $activity['published'] = $object['published'];
+               $activity['published'] = defaults($object, 'published', $child['published']);
                $activity['type'] = 'Create';
 
                $ldactivity = JsonLD::compact($activity);
index 04da5fa596ea0858a6468a154eac71fba2b33833..4341c14a3f42b544e927229f6090fd83945d72b1 100644 (file)
@@ -419,8 +419,9 @@ class Receiver
                                }
 
                                if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) {
+                                       $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
                                        $condition = ['nurl' => normalise_link($actor), 'rel' => [Contact::SHARING, Contact::FRIEND],
-                                               'network' => Protocol::ACTIVITYPUB, 'archive' => false, 'pending' => false];
+                                               'network' => $networks, 'archive' => false, 'pending' => false];
                                        $contacts = DBA::select('contact', ['uid'], $condition);
                                        while ($contact = DBA::fetch($contacts)) {
                                                if ($contact['uid'] != 0) {
@@ -461,7 +462,7 @@ class Receiver
 
                logger('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' to ActivityPub');
 
-               $photo = $profile['photo'];
+               $photo = defaults($profile, 'photo', null);
                unset($profile['photo']);
                unset($profile['baseurl']);
 
@@ -478,7 +479,7 @@ class Receiver
        }
 
        /**
-        * 
+        *
         *
         * @param $receivers
         * @param $actor
@@ -503,12 +504,12 @@ class Receiver
        }
 
        /**
-        * 
+        *
         *
         * @param $object_data
         * @param array $activity
         *
-        * @return 
+        * @return
         */
        private static function addActivityFields($object_data, $activity)
        {
index 9ddcc1d7933c7a3e5b936650903b924533f5a245..b0e6cd362955f5a3e7f029577c4604e6f07f070c 100644 (file)
@@ -39,9 +39,6 @@ require_once 'include/api.php';
  *
  * Complicated object types:
  * - Undo Announce
- *
- * General:
- * - Queueing unsucessful deliveries
  */
 class Transmitter
 {
@@ -289,7 +286,7 @@ class Transmitter
 
                        foreach ($activity[$element] as $receiver) {
                                if ($receiver == $profile['followers'] && !empty($item_profile['followers'])) {
-                                       $receiver = $item_profile['followers'];
+                                       $permissions[$element][] = $item_profile['followers'];
                                }
                                if (!in_array($receiver, $exclude)) {
                                        $permissions[$element][] = $receiver;
@@ -308,6 +305,12 @@ class Transmitter
         */
        private static function createPermissionBlockForItem($item)
        {
+               // Will be activated in a later step
+               // $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
+
+               // For now only send to these contacts:
+               $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
+
                $data = ['to' => [], 'cc' => []];
 
                $data = array_merge($data, self::fetchPermissionBlockFromConversation($item));
@@ -316,8 +319,6 @@ class Transmitter
 
                $terms = Term::tagArrayFromItemId($item['id'], TERM_MENTION);
 
-               $contacts[$item['author-link']] = $item['author-link'];
-
                if (!$item['private']) {
                        $data['to'][] = ActivityPub::PUBLIC_COLLECTION;
                        if (!empty($actor_profile['followers'])) {
@@ -326,13 +327,8 @@ class Transmitter
 
                        foreach ($terms as $term) {
                                $profile = APContact::getByURL($term['url'], false);
-                               if (!empty($profile) && empty($contacts[$profile['url']])) {
+                               if (!empty($profile)) {
                                        $data['to'][] = $profile['url'];
-                                       $contacts[$profile['url']] = $profile['url'];
-
-                                       if (($key = array_search($profile['url'], $data['cc'])) !== false) {
-                                               unset($data['cc'][$key]);
-                                       }
                                }
                        }
                } else {
@@ -343,21 +339,17 @@ class Transmitter
                        foreach ($terms as $term) {
                                $cid = Contact::getIdForURL($term['url'], $item['uid']);
                                if (!empty($cid) && in_array($cid, $receiver_list)) {
-                                       $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]);
-                                       $data['to'][] = $contact['url'];
-                                       $contacts[$contact['url']] = $contact['url'];
-
-                                       if (($key = array_search($profile['url'], $data['cc'])) !== false) {
-                                               unset($data['cc'][$key]);
+                                       $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => $networks]);
+                                       if (DBA::isResult($contact) && !empty($profile = APContact::getByURL($contact['url'], false))) {
+                                               $data['to'][] = $profile['url'];
                                        }
                                }
                        }
 
                        foreach ($receiver_list as $receiver) {
-                               $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]);
-                               if (empty($contacts[$contact['url']])) {
-                                       $data['cc'][] = $contact['url'];
-                                       $contacts[$contact['url']] = $contact['url'];
+                               $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => $networks]);
+                               if (DBA::isResult($contact) && !empty($profile = APContact::getByURL($contact['url'], false))) {
+                                       $data['cc'][] = $profile['url'];
                                }
                        }
                }
@@ -370,32 +362,28 @@ class Transmitter
                        }
 
                        $profile = APContact::getByURL($parent['author-link'], false);
-                       if (!empty($profile) && ($parent['uri'] == $item['thr-parent'])) {
-                               $data['to'][] = $profile['url'];
-                               $contacts[$profile['url']] = $profile['url'];
-
-                               if (($key = array_search($profile['url'], $data['cc'])) !== false) {
-                                       unset($data['cc'][$key]);
+                       if (!empty($profile)) {
+                               if ($parent['uri'] == $item['thr-parent']) {
+                                       $data['to'][] = $profile['url'];
+                               } else {
+                                       $data['cc'][] = $profile['url'];
                                }
                        }
 
-                       if (!empty($profile) && empty($contacts[$profile['url']])) {
-                               $data['cc'][] = $profile['url'];
-                               $contacts[$profile['url']] = $profile['url'];
-                       }
-
                        if ($item['gravity'] != GRAVITY_PARENT) {
                                continue;
                        }
 
                        $profile = APContact::getByURL($parent['owner-link'], false);
-                       if (!empty($profile) && empty($contacts[$profile['url']])) {
+                       if (!empty($profile)) {
                                $data['cc'][] = $profile['url'];
-                               $contacts[$profile['url']] = $profile['url'];
                        }
                }
                DBA::close($parents);
 
+               $data['to'] = array_unique($data['to']);
+               $data['cc'] = array_unique($data['cc']);
+
                if (($key = array_search($item['author-link'], $data['to'])) !== false) {
                        unset($data['to'][$key]);
                }
@@ -404,30 +392,50 @@ class Transmitter
                        unset($data['cc'][$key]);
                }
 
-               return ['to' => array_values(array_unique($data['to'])), 'cc' => array_values(array_unique($data['cc']))];
+               foreach ($data['to'] as $to) {
+                       if (($key = array_search($to, $data['cc'])) !== false) {
+                               unset($data['cc'][$key]);
+                       }
+               }
+
+               return ['to' => array_values($data['to']), 'cc' => array_values($data['cc'])];
        }
 
        /**
         * Fetches a list of inboxes of followers of a given user
         *
         * @param integer $uid User ID
+        * @param boolean $personal fetch personal inboxes
         *
         * @return array of follower inboxes
         */
-       public static function fetchTargetInboxesforUser($uid)
+       public static function fetchTargetInboxesforUser($uid, $personal = false)
        {
                $inboxes = [];
 
-               $condition = ['uid' => $uid, 'network' => Protocol::ACTIVITYPUB, 'archive' => false, 'pending' => false];
+               // Will be activated in a later step
+               // $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
+
+               // For now only send to these contacts:
+               $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
+
+               $condition = ['uid' => $uid, 'network' => $networks, 'archive' => false, 'pending' => false];
 
                if (!empty($uid)) {
                        $condition['rel'] = [Contact::FOLLOWER, Contact::FRIEND];
                }
 
-               $contacts = DBA::select('contact', ['notify', 'batch'], $condition);
+               $contacts = DBA::select('contact', ['url'], $condition);
                while ($contact = DBA::fetch($contacts)) {
-                       $contact = defaults($contact, 'batch', $contact['notify']);
-                       $inboxes[$contact] = $contact;
+                       $profile = APContact::getByURL($contact['url'], false);
+                       if (!empty($profile)) {
+                               if (empty($profile['sharedinbox']) || $personal) {
+                                       $target = $profile['inbox'];
+                               } else {
+                                       $target = $profile['sharedinbox'];
+                               }
+                               $inboxes[$target] = $target;
+                       }
                }
                DBA::close($contacts);
 
@@ -439,10 +447,11 @@ class Transmitter
         *
         * @param array $item
         * @param integer $uid User ID
+        * @param boolean $personal fetch personal inboxes
         *
         * @return array with inboxes
         */
-       public static function fetchTargetInboxes($item, $uid)
+       public static function fetchTargetInboxes($item, $uid, $personal = false)
        {
                $permissions = self::createPermissionBlockForItem($item);
                if (empty($permissions)) {
@@ -452,9 +461,9 @@ class Transmitter
                $inboxes = [];
 
                if ($item['gravity'] == GRAVITY_ACTIVITY) {
-                       $item_profile = APContact::getByURL($item['author-link']);
+                       $item_profile = APContact::getByURL($item['author-link'], false);
                } else {
-                       $item_profile = APContact::getByURL($item['owner-link']);
+                       $item_profile = APContact::getByURL($item['owner-link'], false);
                }
 
                foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
@@ -464,11 +473,15 @@ class Transmitter
 
                        foreach ($permissions[$element] as $receiver) {
                                if ($receiver == $item_profile['followers']) {
-                                       $inboxes = self::fetchTargetInboxesforUser($uid);
+                                       $inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal));
                                } else {
-                                       $profile = APContact::getByURL($receiver);
+                                       $profile = APContact::getByURL($receiver, false);
                                        if (!empty($profile)) {
-                                               $target = defaults($profile, 'sharedinbox', $profile['inbox']);
+                                               if (empty($profile['sharedinbox']) || $personal) {
+                                                       $target = $profile['inbox'];
+                                               } else {
+                                                       $target = $profile['sharedinbox'];
+                                               }
                                                $inboxes[$target] = $target;
                                        }
                                }
@@ -529,7 +542,7 @@ class Transmitter
 
                $data = ActivityPub\Transmitter::createActivityFromItem($item_id);
 
-               Cache::set($cachekey, $data, CACHE_QUARTER_HOUR);
+               Cache::set($cachekey, $data, Cache::QUARTER_HOUR);
                return $data;
        }
 
@@ -743,6 +756,26 @@ class Transmitter
                return $attachments;
        }
 
+        /**
+        * @brief Callback function to replace a Friendica style mention in a mention that is used on AP
+        *
+        * @param array $match Matching values for the callback
+        * @return string Replaced mention
+        */
+       private static function mentionCallback($match)
+       {
+               if (empty($match[1])) {
+                       return;
+               }
+
+               $data = Contact::getDetailsByURL($match[1]);
+               if (empty($data) || empty($data['nick'])) {
+                       return;
+               }
+
+               return '@[url=' . $data['url'] . ']' . $data['nick'] . '[/url]';
+       }
+
        /**
         * Remove image elements and replaces them with links to the image
         *
@@ -851,6 +884,9 @@ class Transmitter
                        $body = self::removePictures($body);
                }
 
+               $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
+               $body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body);
+
                $data['content'] = BBCode::convert($body, false, 7);
                $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"];
 
@@ -897,6 +933,8 @@ class Transmitter
         * @param integer $uid User ID
         * @param string $inbox Target inbox
         * @param integer $suggestion_id Suggestion ID
+        *
+        * @return boolean was the transmission successful?
         */
        public static function sendContactSuggestion($uid, $inbox, $suggestion_id)
        {
@@ -918,7 +956,7 @@ class Transmitter
                $signed = LDSignature::sign($data, $owner);
 
                logger('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
-               HTTPSignature::transmit($signed, $inbox, $uid);
+               return HTTPSignature::transmit($signed, $inbox, $uid);
        }
 
        /**
@@ -926,6 +964,8 @@ class Transmitter
         *
         * @param integer $uid User ID
         * @param string $inbox Target inbox
+        *
+        * @return boolean was the transmission successful?
         */
        public static function sendProfileDeletion($uid, $inbox)
        {
@@ -945,7 +985,7 @@ class Transmitter
                $signed = LDSignature::sign($data, $owner);
 
                logger('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
-               HTTPSignature::transmit($signed, $inbox, $uid);
+               return HTTPSignature::transmit($signed, $inbox, $uid);
        }
 
        /**
@@ -953,6 +993,8 @@ class Transmitter
         *
         * @param integer $uid User ID
         * @param string $inbox Target inbox
+        *
+        * @return boolean was the transmission successful?
         */
        public static function sendProfileUpdate($uid, $inbox)
        {
@@ -972,7 +1014,7 @@ class Transmitter
                $signed = LDSignature::sign($data, $owner);
 
                logger('Deliver profile update for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
-               HTTPSignature::transmit($signed, $inbox, $uid);
+               return HTTPSignature::transmit($signed, $inbox, $uid);
        }
 
        /**
index f92d1401dfe49f7c5365217f35a1fa1cabfd507d..1dcc1197a5d3ae70cc614700ac2fbb1fe89a0212 100644 (file)
@@ -216,7 +216,6 @@ class DFRN
                        }
 
                        $contact = $r[0];
-                       include_once 'include/security.php';
 
                        $set = PermissionSet::get($owner_id, $contact['id']);
 
@@ -647,7 +646,7 @@ class DFRN
                XML::addElement($doc, $author, "dfrn:handle", $owner["addr"], $attributes);
 
                $attributes = ["rel" => "photo", "type" => "image/jpeg",
-                                       "media:width" => 175, "media:height" => 175, "href" => $owner['photo']];
+                                       "media:width" => 300, "media:height" => 300, "href" => $owner['photo']];
 
                if (!$public || !$hidewall) {
                        $attributes["dfrn:updated"] = $picdate;
@@ -3038,7 +3037,7 @@ class DFRN
 
                        logger('auto_redir: ' . $r[0]['name'] . ' ' . $sec, LOGGER_DEBUG);
                        $dest = (($url) ? '&destination_url=' . $url : '');
-                       goaway($r[0]['poll'] . '?dfrn_id=' . $dfrn_id
+                       System::externalRedirect($r[0]['poll'] . '?dfrn_id=' . $dfrn_id
                                . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest);
                }
 
index 00f4e1702d643779c6930f494dacc0b71882db62..1a8054aad51757a0103d633a0b79b24c4596f3a4 100644 (file)
@@ -949,6 +949,7 @@ class Diaspora
                                $person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'addr' => $handle]);
                                if (!DBA::isResult($person)) {
                                        $person = $r;
+                                       $person['id'] = 0;
                                }
                        }
                }
@@ -1199,7 +1200,7 @@ class Diaspora
                );
 
                preg_replace_callback(
-                       "&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi",
+                       "&\[url=/?posts/([^\[\]]*)\](.*)\[\/url\]&Usi",
                        function ($match) use ($item) {
                                self::fetchGuidSub($match, $item);
                        },
@@ -3204,7 +3205,7 @@ class Diaspora
                logger("Send participation for ".$item["guid"]." by ".$author, LOGGER_DEBUG);
 
                // It doesn't matter what we store, we only want to avoid sending repeated notifications for the same item
-               Cache::set($cachekey, $item["guid"], CACHE_QUARTER_HOUR);
+               Cache::set($cachekey, $item["guid"], Cache::QUARTER_HOUR);
 
                return self::buildAndTransmit($owner, $contact, "participation", $message);
        }
@@ -3429,12 +3430,9 @@ class Diaspora
                /// @todo - establish "all day" events in Friendica
                $eventdata["all_day"] = "false";
 
-               if (!$event['adjust']) {
+               $eventdata['timezone'] = 'UTC';
+               if (!$event['adjust'] && $user['timezone']) {
                        $eventdata['timezone'] = $user['timezone'];
-
-                       if ($eventdata['timezone'] == "") {
-                               $eventdata['timezone'] = 'UTC';
-                       }
                }
 
                if ($event['start']) {
@@ -3577,7 +3575,7 @@ class Diaspora
 
                $msg = ["type" => $type, "message" => $message];
 
-               Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR);
+               Cache::set($cachekey, $msg, Cache::QUARTER_HOUR);
 
                return $msg;
        }
@@ -3704,7 +3702,7 @@ class Diaspora
                        $comment['thread_parent_guid'] = self::getGuidFromUri($item['thr-parent'], $item['uid']);
                }
 
-               Cache::set($cachekey, $comment, CACHE_QUARTER_HOUR);
+               Cache::set($cachekey, $comment, Cache::QUARTER_HOUR);
 
                return($comment);
        }
index f589d3827f0bbc5ad85cf699df7cdb5552fa29f5..fb78d2ebbe59633943b9142c1c243b2a1f38c42b 100644 (file)
@@ -1450,8 +1450,8 @@ class OStatus
                $attributes = [
                                "rel" => "avatar",
                                "type" => "image/jpeg", // To-Do?
-                               "media:width" => 175,
-                               "media:height" => 175,
+                               "media:width" => 300,
+                               "media:height" => 300,
                                "href" => $owner["photo"]];
                XML::addElement($doc, $author, "link", "", $attributes);
 
@@ -1769,8 +1769,8 @@ class OStatus
                $attributes = [
                                "rel" => "avatar",
                                "type" => "image/jpeg", // To-Do?
-                               "media:width" => 175,
-                               "media:height" => 175,
+                               "media:width" => 300,
+                               "media:height" => 300,
                                "href" => $contact["photo"]];
                XML::addElement($doc, $object, "link", "", $attributes);
 
@@ -2210,7 +2210,7 @@ class OStatus
                $feeddata = trim($doc->saveXML());
 
                $msg = ['feed' => $feeddata, 'last_update' => $last_update];
-               Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR);
+               Cache::set($cachekey, $msg, Cache::QUARTER_HOUR);
 
                logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created, LOGGER_DEBUG);
 
index 0e4d58d1c19348f67aa2af88510bcd2aa265c908..bb7ccd564aa166bf8b08f7405b6d60d56bc82299 100644 (file)
@@ -113,7 +113,7 @@ class PortableContact
                        $connect_url = '';
                        $name = '';
                        $network = '';
-                       $updated = NULL_DATE;
+                       $updated = DBA::NULL_DATETIME;
                        $location = '';
                        $about = '';
                        $keywords = '';
@@ -317,7 +317,7 @@ class PortableContact
 
                $contact = ["url" => $profile];
 
-               if ($gcontacts[0]["created"] <= NULL_DATE) {
+               if ($gcontacts[0]["created"] <= DBA::NULL_DATETIME) {
                        $contact['created'] = DateTimeFormat::utcNow();
                }
 
@@ -522,7 +522,7 @@ class PortableContact
                // Maybe there aren't any entries. Then check if it is a valid feed
                if ($last_updated == "") {
                        if ($xpath->query('/atom:feed')->length > 0) {
-                               $last_updated = NULL_DATE;
+                               $last_updated = DBA::NULL_DATETIME;
                        }
                }
 
@@ -931,7 +931,7 @@ class PortableContact
 
                $gserver = DBA::selectFirst('gserver', [], ['nurl' => normalise_link($server_url)]);
                if (DBA::isResult($gserver)) {
-                       if ($gserver["created"] <= NULL_DATE) {
+                       if ($gserver["created"] <= DBA::NULL_DATETIME) {
                                $fields = ['created' => DateTimeFormat::utcNow()];
                                $condition = ['nurl' => normalise_link($server_url)];
                                DBA::update('gserver', $fields, $condition);
@@ -954,12 +954,12 @@ class PortableContact
 
                        // See discussion under https://forum.friendi.ca/display/0b6b25a8135aabc37a5a0f5684081633
                        // It can happen that a zero date is in the database, but storing it again is forbidden.
-                       if ($last_contact < NULL_DATE) {
-                               $last_contact = NULL_DATE;
+                       if ($last_contact < DBA::NULL_DATETIME) {
+                               $last_contact = DBA::NULL_DATETIME;
                        }
 
-                       if ($last_failure < NULL_DATE) {
-                               $last_failure = NULL_DATE;
+                       if ($last_failure < DBA::NULL_DATETIME) {
+                               $last_failure = DBA::NULL_DATETIME;
                        }
 
                        if (!$force && !self::updateNeeded($gserver["created"], "", $last_failure, $last_contact)) {
@@ -976,8 +976,8 @@ class PortableContact
                        $register_policy = -1;
                        $registered_users = 0;
 
-                       $last_contact = NULL_DATE;
-                       $last_failure = NULL_DATE;
+                       $last_contact = DBA::NULL_DATETIME;
+                       $last_failure = DBA::NULL_DATETIME;
                }
                logger("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$gserver["created"]." Failure: ".$last_failure." Contact: ".$last_contact, LOGGER_DEBUG);
 
@@ -1794,7 +1794,7 @@ class PortableContact
                        $connect_url = '';
                        $name = '';
                        $network = '';
-                       $updated = NULL_DATE;
+                       $updated = DBA::NULL_DATETIME;
                        $location = '';
                        $about = '';
                        $keywords = '';
index 503cbff0ade45b0af04c35d039380f28ff267cbc..1d2e7d9f76b6a692e15c7453397c914e012c6593 100644 (file)
@@ -272,9 +272,11 @@ class HTTPSignature
        /**
         * @brief Transmit given data to a target for a user
         *
-        * @param $data
-        * @param $target
-        * @param $uid
+        * @param array $data Data that is about to be send
+        * @param string $target The URL of the inbox
+        * @param integer $uid User id of the sender
+        *
+        * @return boolean Was the transmission successful?
         */
        public static function transmit($data, $target, $uid)
        {
@@ -303,8 +305,11 @@ class HTTPSignature
                $headers[] = 'Content-Type: application/activity+json';
 
                $postResult = Network::post($target, $content, $headers);
+               $return_code = $postResult->getReturnCode();
+
+               logger('Transmit to ' . $target . ' returned ' . $return_code);
 
-               logger('Transmit to ' . $target . ' returned ' . $postResult->getReturnCode());
+               return ($return_code >= 200) && ($return_code <= 299);
        }
 
        /**
index 5380c3c542734bb613aa4238fc960d8a755ceb4a..793f5e9d1280c727cd9dba8782c07ac8fd1a7225 100644 (file)
@@ -43,7 +43,7 @@ class JsonLD
                }
 
                $data = jsonld_default_document_loader($url);
-               Cache::set('documentLoader:' . $url, $data, CACHE_DAY);
+               Cache::set('documentLoader:' . $url, $data, Cache::DAY);
                return $data;
        }
 
@@ -88,7 +88,7 @@ class JsonLD
                        'ostatus' => (object)['@id' => 'http://ostatus.org#', '@type' => '@id'],
                        'diaspora' => (object)['@id' => 'https://diasporafoundation.org/ns/', '@type' => '@id'],
                        'dc' => (object)['@id' => 'http://purl.org/dc/terms/', '@type' => '@id'],
-                       'uuid' => (object)['@id' => 'http://schema.org/identifier', '@type' => '@id']];
+                       'ldp' => (object)['@id' => 'http://www.w3.org/ns/ldp#', '@type' => '@id']];
 
                $jsonobj = json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
 
index 1038fa3f0430fd9f89af68f0f827404fa809c0e5..3b27a0550a5615a1dadbdf137cffdd6e3c91f9f1 100644 (file)
@@ -516,7 +516,7 @@ class Network
 
        public static function lookupAvatarByEmail($email)
        {
-               $avatar['size'] = 175;
+               $avatar['size'] = 300;
                $avatar['email'] = $email;
                $avatar['url'] = '';
                $avatar['success'] = false;
@@ -524,7 +524,7 @@ class Network
                Addon::callHooks('avatar_lookup', $avatar);
 
                if (! $avatar['success']) {
-                       $avatar['url'] = System::baseUrl() . '/images/person-175.jpg';
+                       $avatar['url'] = System::baseUrl() . '/images/person-300.jpg';
                }
 
                logger('Avatar: ' . $avatar['email'] . ' ' . $avatar['url'], LOGGER_DEBUG);
index f2a5eccd395247956c9e39a4e22c037d9c0567fa..24089b9cbd2a92bb33c22fe4e41ee3b501987cff 100644 (file)
@@ -141,7 +141,7 @@ class ParseUrl
                }
 
                // If the file is too large then exit
-               if ($curlResult->getInfo()['download_content_length'] > 1000000) {
+               if (defaults($curlResult->getInfo(), 'download_content_length', 0) > 1000000) {
                        return $siteinfo;
                }
 
index 0bb7537f78bda42a52edb9535d43a4eea453ab7a..8478ce868af103794aad2ba1c534fc929dff3a57 100644 (file)
@@ -7,8 +7,6 @@ use Friendica\BaseObject;
 use Friendica\Core\Config;
 use Friendica\Core\System;
 
-require_once 'include/security.php';
-
 /**
  * @brief Proxy utilities class
  */
diff --git a/src/Util/Security.php b/src/Util/Security.php
new file mode 100644 (file)
index 0000000..11059c0
--- /dev/null
@@ -0,0 +1,155 @@
+<?php
+/**
+ * @file /src/Util/Security.php
+ */
+
+namespace Friendica\Util;
+
+use Friendica\BaseObject;
+use Friendica\Database\DBA;
+use Friendica\Model\Contact;
+use Friendica\Model\Group;
+use Friendica\Core\L10n;
+use Friendica\Model\PermissionSet;
+use Friendica\Core\System;
+
+/**
+ * Secures that User is allow to do requests
+ */
+class Security extends BaseObject
+{
+       public static function canWriteToUserWall($owner)
+       {
+               static $verified = 0;
+
+               if (!local_user() && !remote_user()) {
+                       return false;
+               }
+
+               $uid = local_user();
+               if ($uid == $owner) {
+                       return true;
+               }
+
+               if (local_user() && ($owner == 0)) {
+                       return true;
+               }
+
+               if (remote_user()) {
+                       // use remembered decision and avoid a DB lookup for each and every display item
+                       // DO NOT use this function if there are going to be multiple owners
+                       // We have a contact-id for an authenticated remote user, this block determines if the contact
+                       // belongs to this page owner, and has the necessary permissions to post content
+
+                       if ($verified === 2) {
+                               return true;
+                       } elseif ($verified === 1) {
+                               return false;
+                       } else {
+                               $cid = 0;
+
+                               if (!empty($_SESSION['remote'])) {
+                                       foreach ($_SESSION['remote'] as $visitor) {
+                                               if ($visitor['uid'] == $owner) {
+                                                       $cid = $visitor['cid'];
+                                                       break;
+                                               }
+                                       }
+                               }
+
+                               if (!$cid) {
+                                       return false;
+                               }
+
+                               $r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` INNER JOIN `user` on `user`.`uid` = `contact`.`uid`
+                                       WHERE `contact`.`uid` = %d AND `contact`.`id` = %d AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
+                                       AND `user`.`blockwall` = 0 AND `readonly` = 0  AND ( `contact`.`rel` IN ( %d , %d ) OR `user`.`page-flags` = %d ) LIMIT 1",
+                                       intval($owner),
+                                       intval($cid),
+                                       intval(Contact::SHARING),
+                                       intval(Contact::FRIEND),
+                                       intval(Contact::PAGE_COMMUNITY)
+                               );
+
+                               if (DBA::isResult($r)) {
+                                       $verified = 2;
+                                       return true;
+                               } else {
+                                       $verified = 1;
+                               }
+                       }
+               }
+
+               return false;
+       }
+
+       /// @TODO $groups should be array
+       public static function getPermissionsSQLByUserId($owner_id, $remote_verified = false, $groups = null)
+       {
+               $local_user = local_user();
+               $remote_user = remote_user();
+
+               /*
+                * Construct permissions
+                *
+                * default permissions - anonymous user
+                */
+               $sql = " AND allow_cid = ''
+                                AND allow_gid = ''
+                                AND deny_cid  = ''
+                                AND deny_gid  = ''
+               ";
+
+               /*
+                * Profile owner - everything is visible
+                */
+               if ($local_user && $local_user == $owner_id) {
+                       $sql = '';
+               /*
+                * Authenticated visitor. Unless pre-verified,
+                * check that the contact belongs to this $owner_id
+                * and load the groups the visitor belongs to.
+                * If pre-verified, the caller is expected to have already
+                * done this and passed the groups into this function.
+                */
+               } elseif ($remote_user) {
+                       /*
+                        * Authenticated visitor. Unless pre-verified,
+                        * check that the contact belongs to this $owner_id
+                        * and load the groups the visitor belongs to.
+                        * If pre-verified, the caller is expected to have already
+                        * done this and passed the groups into this function.
+                        */
+
+                       if (!$remote_verified) {
+                               if (DBA::exists('contact', ['id' => $remote_user, 'uid' => $owner_id, 'blocked' => false])) {
+                                       $remote_verified = true;
+                                       $groups = Group::getIdsByContactId($remote_user);
+                               }
+                       }
+
+                       if ($remote_verified) {
+                               $gs = '<<>>'; // should be impossible to match
+
+                               if (is_array($groups)) {
+                                       foreach ($groups as $g) {
+                                               $gs .= '|<' . intval($g) . '>';
+                                       }
+                               }
+
+                               $sql = sprintf(
+                                       " AND ( NOT (deny_cid REGEXP '<%d>' OR deny_gid REGEXP '%s')
+                                         AND ( allow_cid REGEXP '<%d>' OR allow_gid REGEXP '%s' OR ( allow_cid = '' AND allow_gid = '') )
+                                         )
+                                       ",
+                                       intval($remote_user),
+                                       DBA::escape($gs),
+                                       intval($remote_user),
+                                       DBA::escape($gs)
+                               );
+                       }
+               }
+               return $sql;
+       }
+
+}
index 696721e458c2d906f978f33fecda176fbe6d7938..bc7639b3b740f102b2f6b32e162413c1e961f7ca 100644 (file)
@@ -11,6 +11,7 @@ use DateTimeZone;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
+use Friendica\Database\DBA;
 
 require_once 'boot.php';
 require_once 'include/text.php';
@@ -217,13 +218,13 @@ class Temporal
                // First day of the week (0 = Sunday)
                $firstDay = PConfig::get(local_user(), 'system', 'first_day_of_week', 0);
 
-               $lang = substr(L10n::getBrowserLanguage(), 0, 2);
+               $lang = substr(L10n::getCurrentLang(), 0, 2);
 
                // Check if the detected language is supported by the picker
                if (!in_array($lang,
                                ["ar", "ro", "id", "bg", "fa", "ru", "uk", "en", "el", "de", "nl", "tr", "fr", "es", "th", "pl", "pt", "ch", "se", "kr",
                                "it", "da", "no", "ja", "vi", "sl", "cs", "hu"])) {
-                       $lang = Config::get('system', 'language', 'en');
+                       $lang = 'en';
                }
 
                $o = '';
@@ -290,7 +291,7 @@ class Temporal
 
                $abs = strtotime($localtime);
 
-               if (is_null($posted_date) || $posted_date <= NULL_DATE || $abs === false) {
+               if (is_null($posted_date) || $posted_date <= DBA::NULL_DATETIME || $abs === false) {
                        return L10n::t('never');
                }
 
index 7b1ad760557022e3144c5d03382cabfe53ed6ada..b952249fed11a120066de84a8fd27e382520ded0 100644 (file)
@@ -7,6 +7,7 @@ namespace Friendica\Worker;
 use Friendica\BaseObject;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Model\Item;
+use Friendica\Core\Worker;
 use Friendica\Util\HTTPSignature;
 
 class APDelivery extends BaseObject
@@ -23,19 +24,25 @@ class APDelivery extends BaseObject
        {
                logger('Invoked: ' . $cmd . ': ' . $item_id . ' to ' . $inbox, LOGGER_DEBUG);
 
+               $success = true;
+
                if ($cmd == Delivery::MAIL) {
                } elseif ($cmd == Delivery::SUGGESTION) {
-                       ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $item_id);
+                       $success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $item_id);
                } elseif ($cmd == Delivery::RELOCATION) {
                } elseif ($cmd == Delivery::REMOVAL) {
-                       ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox);
+                       $success = ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox);
                } elseif ($cmd == Delivery::PROFILEUPDATE) {
-                       ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox);
+                       $success = ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox);
                } else {
                        $data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
                        if (!empty($data)) {
-                               HTTPSignature::transmit($data, $inbox, $uid);
+                               $success = HTTPSignature::transmit($data, $inbox, $uid);
                        }
                }
+
+               if (!$success) {
+                       Worker::defer();
+               }
        }
 }
index b6dd896cd77e9770c54354e62a92caeaee8f6ddc..9510063337f5da31756ed3a5c1613976c7256a28 100644 (file)
@@ -7,6 +7,7 @@ namespace Friendica\Worker;
 use Friendica\BaseObject;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
+use Friendica\Core\Hook;
 use Friendica\Core\Protocol;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
@@ -45,7 +46,7 @@ class Cron
                logger('cron: start');
 
                // Fork the cron jobs in separate parts to avoid problems when one of them is crashing
-               Addon::forkHooks($a->queue['priority'], "cron");
+               Hook::fork($a->queue['priority'], "cron");
 
                // run queue delivery process in the background
                Worker::add(PRIORITY_NEGLIGIBLE, "Queue");
@@ -203,7 +204,7 @@ class Cron
                foreach ($contacts as $contact) {
 
                        if ($manual_id) {
-                               $contact['last-update'] = NULL_DATE;
+                               $contact['last-update'] = DBA::NULL_DATETIME;
                        }
 
                        // Friendica and OStatus are checked once a day
index bd34449729392f575ad53169dc1750cb590ce5ad..a564bd0b0d19cca39f6bc0d010bbe145b2d304b8 100644 (file)
@@ -108,7 +108,7 @@ class CronJobs
        private static function expireAndRemoveUsers()
        {
                // expire any expired regular accounts. Don't expire forums.
-               $condition = ["NOT `account_expired` AND `account_expires_on` > ? AND `account_expires_on` < UTC_TIMESTAMP() AND `page-flags` = 0", NULL_DATE];
+               $condition = ["NOT `account_expired` AND `account_expires_on` > ? AND `account_expires_on` < UTC_TIMESTAMP() AND `page-flags` = 0", DBA::NULL_DATETIME];
                DBA::update('user', ['account_expired' => true], $condition);
 
                // Remove any freshly expired account
index ca0da954c010ff08c51f3e1876ae13383b2ba620..dba9cfd4c61894a86c0fc35861ff986f94a8c67b 100644 (file)
@@ -63,7 +63,7 @@ class DBClean {
                $count = 0;
 
                // We split the deletion in many small tasks
-               $limit = 1000;
+               $limit = Config::get('system', 'dbclean-expire-limit', 1000);
 
                // Get the expire days for step 8 and 9
                $days = Config::get('system', 'dbclean-expire-days', 0);
@@ -275,7 +275,7 @@ class DBClean {
                                                                        OR (`item`.`file` != '') OR (`item`.`event-id` != '')
                                                                        OR (`item`.`attach` != '') OR `item`.`wall` OR `item`.`origin`)
                                                                        AND `item`.`parent` = `thread`.`iid`)
-                                       ORDER BY `thread`.`iid` LIMIT 1000", $days, $last_id);
+                                       ORDER BY `thread`.`iid` LIMIT ?", $days, $last_id, $limit);
                        $count = DBA::numRows($r);
                        if ($count > 0) {
                                logger("found expired threads: ".$count);
index f2951cce1ff2bf13deb7aec6e112f16bfcb655f8..4feb341b372debd8f2c13ab81480cca763dbd792 100644 (file)
@@ -39,13 +39,13 @@ class Delivery extends BaseObject
                $followup = false;
                $public_message = false;
 
+               $items = [];
                if ($cmd == self::MAIL) {
                        $target_item = DBA::selectFirst('mail', [], ['id' => $item_id]);
                        if (!DBA::isResult($target_item)) {
                                return;
                        }
                        $uid = $target_item['uid'];
-                       $items = [];
                } elseif ($cmd == self::SUGGESTION) {
                        $target_item = DBA::selectFirst('fsuggest', [], ['id' => $item_id]);
                        if (!DBA::isResult($target_item)) {
@@ -54,6 +54,7 @@ class Delivery extends BaseObject
                        $uid = $target_item['uid'];
                } elseif ($cmd == self::RELOCATION) {
                        $uid = $item_id;
+                       $target_item = [];
                } else {
                        $item = Item::selectFirst(['parent'], ['id' => $item_id]);
                        if (!DBA::isResult($item) || empty($item['parent'])) {
@@ -65,7 +66,6 @@ class Delivery extends BaseObject
                        $params = ['order' => ['id']];
                        $itemdata = Item::select([], $condition, $params);
 
-                       $items = [];
                        while ($item = Item::fetch($itemdata)) {
                                if ($item['id'] == $parent_id) {
                                        $parent = $item;
index 497684497fbd4cc778558cc7627626a5bc5c1ce6..c1583888c72ecb8b3efb13725b323ab79fe867d6 100644 (file)
@@ -258,7 +258,7 @@ class DiscoverPoCo
                                }
                        }
                }
-               Cache::set("dirsearch:".$search, time(), CACHE_DAY);
+               Cache::set("dirsearch:".$search, time(), Cache::DAY);
        }
 
        /**
index b6096b5849405d11b2f68fec6a81c245157a44ad..de2133bdc804f4bff06017e57a2357980702cca0 100644 (file)
@@ -7,8 +7,8 @@
 namespace Friendica\Worker;
 
 use Friendica\BaseObject;
-use Friendica\Core\Addon;
 use Friendica\Core\Config;
+use Friendica\Core\Hook;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model\Item;
@@ -17,13 +17,13 @@ require_once 'include/dba.php';
 
 class Expire
 {
-       public static function execute($param = '', $hook_name = '')
+       public static function execute($param = '', $hook_function = '')
        {
                $a = BaseObject::getApp();
 
                require_once 'include/items.php';
 
-               Addon::loadHooks();
+               Hook::loadHooks();
 
                if ($param == 'delete') {
                        logger('Delete expired items', LOGGER_DEBUG);
@@ -62,11 +62,11 @@ class Expire
                                logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - done ', LOGGER_DEBUG);
                        }
                        return;
-               } elseif (!empty($hook_name) && ($param == 'hook') && is_array($a->hooks) && array_key_exists("expire", $a->hooks)) {
-                       foreach ($a->hooks["expire"] as $hook) {
-                               if ($hook[1] == $hook_name) {
+               } elseif ($param == 'hook' && !empty($hook_function)) {
+                       foreach (Hook::getByName('expire') as $hook) {
+                               if ($hook[1] == $hook_function) {
                                        logger("Calling expire hook '" . $hook[1] . "'", LOGGER_DEBUG);
-                                       Addon::callSingleHook($a, $hook_name, $hook, $data);
+                                       Hook::callSingle($a, 'expire', $hook, $data);
                                }
                        }
                        return;
@@ -86,13 +86,10 @@ class Expire
                DBA::close($r);
 
                logger('expire: calling hooks');
-
-               if (is_array($a->hooks) && array_key_exists('expire', $a->hooks)) {
-                       foreach ($a->hooks['expire'] as $hook) {
-                               logger("Calling expire hook for '" . $hook[1] . "'", LOGGER_DEBUG);
-                               Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
-                                               'Expire', 'hook', $hook[1]);
-                       }
+               foreach (Hook::getByName('expire') as $hook) {
+                       logger("Calling expire hook for '" . $hook[1] . "'", LOGGER_DEBUG);
+                       Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
+                                       'Expire', 'hook', $hook[1]);
                }
 
                logger('expire: end');
index 3654bdd3cad173aae526a244adfa91a76330cf9c..586d1496e685331a2442c471190aed3f45a0a44e 100644 (file)
@@ -5,7 +5,7 @@
 
 namespace Friendica\Worker;
 
-use Friendica\Core\Addon;
+use Friendica\Core\Hook;
 
 Class ForkHook
 {
@@ -13,6 +13,6 @@ Class ForkHook
        {
                $a = \Friendica\BaseObject::getApp();
 
-               Addon::callSingleHook($a, $name, $hook, $data);
+               Hook::callSingle($a, $name, $hook, $data);
        }
 }
index ad33c3245d4be9d33e1381cb9d1cb00b40851842..31000a26f29e3eb88d737e160032e1b365181ee6 100644 (file)
@@ -7,10 +7,12 @@ namespace Friendica\Worker;
 use Friendica\BaseObject;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
+use Friendica\Core\Hook;
 use Friendica\Core\Protocol;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
+use Friendica\Model\Conversation;
 use Friendica\Model\Group;
 use Friendica\Model\Item;
 use Friendica\Model\PushSubscriber;
@@ -20,7 +22,6 @@ use Friendica\Protocol\ActivityPub;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Protocol\Salmon;
-use Friendica\Model\Conversation;
 
 require_once 'include/dba.php';
 require_once 'include/items.php';
@@ -501,7 +502,7 @@ class Notifier
                logger('notifier: calling hooks for ' . $cmd . ' ' . $item_id, LOGGER_DEBUG);
 
                if ($normal_mode) {
-                       Addon::forkHooks($a->queue['priority'], 'notifier_normal', $target_item);
+                       Hook::fork($a->queue['priority'], 'notifier_normal', $target_item);
                }
 
                Addon::callHooks('notifier_end',$target_item);
@@ -512,6 +513,7 @@ class Notifier
        private static function activityPubDelivery($a, $cmd, $item_id, $uid, $target_item, $parent)
        {
                $inboxes = [];
+               $personal = false;
 
                if ($target_item['origin']) {
                        $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid);
@@ -520,11 +522,14 @@ class Notifier
                        logger('Remote item ' . $item_id . ' with URL ' . $target_item['uri'] . ' is no AP post. It will not be distributed.', LOGGER_DEBUG);
                        return;
                } else {
+                       // Remote items are transmitted via the personal inboxes.
+                       // Doing so ensures that the dedicated receiver will get the message.
+                       $personal = true;
                        logger('Remote item ' . $item_id . ' with URL ' . $target_item['uri'] . ' will be distributed.', LOGGER_DEBUG);
                }
 
                if ($parent['origin']) {
-                       $parent_inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid);
+                       $parent_inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid, $personal);
                        $inboxes = array_merge($inboxes, $parent_inboxes);
                }
 
index 0066a04aedd06c7136576506d1e6695c3cd445f1..5227c7983d58f98433ee046d6c4d7108bae17428 100644 (file)
@@ -12,8 +12,8 @@ use Friendica\Core\Protocol;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
-use Friendica\Protocol\Email;
 use Friendica\Protocol\ActivityPub;
+use Friendica\Protocol\Email;
 use Friendica\Protocol\PortableContact;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
@@ -121,7 +121,7 @@ class OnePoll
                        $hub_update = false;
                }
 
-               $last_update = (($contact['last-update'] <= NULL_DATE)
+               $last_update = (($contact['last-update'] <= DBA::NULL_DATETIME)
                        ? DateTimeFormat::utc('now - 7 days', DateTimeFormat::ATOM)
                        : DateTimeFormat::utc($contact['last-update'], DateTimeFormat::ATOM)
                );
@@ -148,6 +148,10 @@ class OnePoll
                        }
                }
 
+               if (!in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) && Config::get('system', 'disable_polling')) {
+                       return;
+               }
+
                if ($importer_uid == 0) {
                        logger('Ignore public contacts');
 
@@ -248,7 +252,7 @@ class OnePoll
                                self::updateContact($contact, $fields);
 
                                Contact::markForArchival($contact);
-                       } elseif ($contact['term-date'] > NULL_DATE) {
+                       } elseif ($contact['term-date'] > DBA::NULL_DATETIME) {
                                logger("$url back from the dead - removing mark for death");
                                Contact::unmarkForArchival($contact);
                        }
@@ -345,7 +349,7 @@ class OnePoll
                } elseif ($contact['network'] === Protocol::MAIL) {
                        logger("Mail: Fetching for ".$contact['addr'], LOGGER_DEBUG);
 
-                       $mail_disabled = ((function_exists('imap_open') && (! Config::get('system', 'imap_disabled'))) ? 0 : 1);
+                       $mail_disabled = ((function_exists('imap_open') && !Config::get('system', 'imap_disabled')) ? 0 : 1);
                        if ($mail_disabled) {
                                // set the last-update so we don't keep polling
                                DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
@@ -541,7 +545,7 @@ class OnePoll
                                                        if ($datarray['parent-uri'] === $datarray['uri']) {
                                                                $datarray['private'] = 1;
                                                        }
-                                                       if (($contact['network'] === Protocol::MAIL) && (!PConfig::get($importer_uid, 'system', 'allow_public_email_replies'))) {
+                                                       if (($contact['network'] === Protocol::MAIL) && !PConfig::get($importer_uid, 'system', 'allow_public_email_replies')) {
                                                                $datarray['private'] = 1;
                                                                $datarray['allow_cid'] = '<' . $contact['id'] . '>';
                                                        }
index b27a776c7a9e65b7a62a93208a2db98f52699ea9..6cad9ac53f8d8ecb00bcde5dbc2028da1bda3122 100644 (file)
@@ -87,7 +87,7 @@ class Queue
                                        logger("Check server " . $server . " (" . $contact["network"] . ")");
 
                                        $vital = PortableContact::checkServer($server, $contact["network"], true);
-                                       Cache::set($cachekey_server . $server, $vital, CACHE_MINUTE);
+                                       Cache::set($cachekey_server . $server, $vital, Cache::MINUTE);
                                }
 
                                if (!is_null($vital) && !$vital) {
@@ -119,7 +119,7 @@ class Queue
                                        QueueModel::removeItem($q_item['id']);
                                } else {
                                        QueueModel::updateTime($q_item['id']);
-                                       Cache::set($cachekey_deadguy . $contact['notify'], true, CACHE_MINUTE);
+                                       Cache::set($cachekey_deadguy . $contact['notify'], true, Cache::MINUTE);
                                }
                                break;
 
@@ -129,7 +129,7 @@ class Queue
 
                                if ($deliver_status == -1) {
                                        QueueModel::updateTime($q_item['id']);
-                                       Cache::set($cachekey_deadguy . $contact['notify'], true, CACHE_MINUTE);
+                                       Cache::set($cachekey_deadguy . $contact['notify'], true, Cache::MINUTE);
                                } else {
                                        QueueModel::removeItem($q_item['id']);
                                }
@@ -144,7 +144,7 @@ class Queue
                                        QueueModel::removeItem($q_item['id']);
                                } else {
                                        QueueModel::updateTime($q_item['id']);
-                                       Cache::set($cachekey_deadguy . $contact['notify'], true, CACHE_MINUTE);
+                                       Cache::set($cachekey_deadguy . $contact['notify'], true, Cache::MINUTE);
                                }
                                break;
 
index 8f986eab11559c18630315429dd783910dfa9205..2e3f16db3e99da80512b85d80cf98b163f18b4f4 100644 (file)
@@ -7,6 +7,7 @@ namespace Friendica\Worker;
 
 use Friendica\Database\DBA;
 use Friendica\Core\Protocol;
+use Friendica\Model\Item;
 
 require_once 'include/dba.php';
 
@@ -15,12 +16,21 @@ class RemoveContact {
 
                // Only delete if the contact is to be deleted
                $condition = ['network' => Protocol::PHANTOM, 'id' => $id];
-               $r = DBA::exists('contact', $condition);
-               if (!DBA::isResult($r)) {
+               $contact = DBA::selectFirst('contact', ['uid'], $condition);
+               if (!DBA::isResult($contact)) {
                        return;
                }
 
                // Now we delete the contact and all depending tables
+               $condition = ['uid' => $contact['uid'], 'contact-id' => $id];
+               do {
+                       $items = Item::select(['id'], $condition, ['limit' => 100]);
+                       while ($item = Item::fetch($items)) {
+                               DBA::delete('item', ['id' => $item['id']]);
+                       }
+                       DBA::close($items);
+               } while (Item::exists($condition));
+
                DBA::delete('contact', ['id' => $id]);
        }
 }
index dfa5ccc097c7e9ea14c2c6f66d8488e22ab2e710..d8966e5a491f661c10bf536e799c60dd206f4b53 100644 (file)
@@ -20,6 +20,13 @@ class RemoveUser {
                }
 
                // Now we delete all user items
-               Item::delete(['uid' => $uid], PRIORITY_LOW);
+               $condition = ['uid' => $uid, 'deleted' => false];
+               do {
+                       $items = Item::select(['id'], $condition, ['limit' => 100]);
+                       while ($item = Item::fetch($items)) {
+                               Item::deleteById($item['id'], PRIORITY_LOW);
+                       }
+                       DBA::close($items);
+               } while (Item::exists($condition));
        }
 }
index 11c61f9fbb40a46990838ddbd6534d58ad4e1b6b..c509c7d2a4233b3ea69ab5b7a6d823246ae357da 100644 (file)
@@ -12,6 +12,8 @@ use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Network\HTTPException;
 
+require_once __DIR__ . '/../include/api.php';
+
 /**
  * Tests for the API functions.
  *
@@ -20,7 +22,6 @@ use Friendica\Network\HTTPException;
  */
 class ApiTest extends DatabaseTest
 {
-
        /**
         * Create variables used by tests.
         */
@@ -28,7 +29,7 @@ class ApiTest extends DatabaseTest
        {
                parent::setUp();
 
-               require_once __DIR__.'/../include/api.php';
+               $this->app = BaseObject::getApp();
 
                // User data that the test database is populated with
                $this->selfUser = [
@@ -60,6 +61,10 @@ class ApiTest extends DatabaseTest
                        'uid' => $this->selfUser['id']
                ];
 
+               Config::set('system', 'url', 'http://localhost');
+               Config::set('system', 'hostname', 'localhost');
+               Config::set('system', 'worker_dont_fork', true);
+
                // Default config
                Config::set('config', 'hostname', 'localhost');
                Config::set('system', 'throttle_limit_day', 100);
@@ -3374,7 +3379,7 @@ class ApiTest extends DatabaseTest
         */
        public function testApiFriendicaRemoteauthWithCorrectUrl()
        {
-               $this->markTestIncomplete("We can't use an assertion here because of goaway().");
+               $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
                $_GET['url'] = 'url';
                $_GET['c_url'] = $this->selfUser['nurl'];
                api_friendica_remoteauth();
index acd0b7ac184d1adbe8a563f1754869103961754c..ec1eb290d10b8b4584f3c63c42ca24963c5aa8b5 100644 (file)
@@ -14,6 +14,8 @@ use PHPUnit\DbUnit\TestCaseTrait;
 use PHPUnit\Framework\TestCase;
 use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
 
+require_once __DIR__ . '/../boot.php';
+
 /**
  * Abstract class used by tests that need a database.
  */
@@ -21,21 +23,6 @@ abstract class DatabaseTest extends TestCase
 {
        use TestCaseTrait;
 
-       /**
-        * @var App The Friendica App
-        */
-       protected $app;
-
-       protected function setUp()
-       {
-               // Reusable App object
-               $this->app = BaseObject::getApp();
-
-               Config::set('system', 'url', 'http://localhost');
-               Config::set('system', 'hostname', 'localhost');
-               Config::set('system', 'worker_dont_fork', true);
-       }
-
        /**
         * Get database connection.
         *
@@ -53,6 +40,11 @@ abstract class DatabaseTest extends TestCase
                        $this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
                }
 
+               DBA::connect(getenv('MYSQL_HOST'),
+                       getenv('MYSQL_USERNAME'),
+                       getenv('MYSQL_PASSWORD'),
+                       getenv('MYSQL_DATABASE'));
+
                if (!DBA::connected()) {
                        $this->markTestSkipped('Could not connect to the database.');
                }
index b0e7a3a60434c678d734382efcd5e4c76f2418cf..d51ba5b6a5ebab9b21f004b2335286232c8c9f18 100644 (file)
@@ -26,7 +26,7 @@ trait VFSTrait
                $this->setConfigFile('config.ini.php');
                $this->setConfigFile('settings.ini.php');
                $this->setConfigFile('local.ini.php');
-               $this->setConfigFile('dbstructure.json');
+               $this->setConfigFile('dbstructure.php');
        }
 
        protected function setConfigFile($filename)
index 290d3ed0428dce6fe98f3725387441cc51d66560..ce67cc9993c8540c4ea3bcbf93f8d613ac43a74a 100644 (file)
@@ -193,10 +193,10 @@ CONF;
                $this->assertConfig('database', 'database', $this->db_data);
                $this->assertConfig('config', 'admin_email', 'admin@friendica.local');
                $this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
-               $this->assertConfig('system', 'language', 'de');
+               // TODO language changes back to en
+               //$this->assertConfig('system', 'language', 'de');
        }
 
-
        /**
         * @medium
         */
@@ -218,8 +218,9 @@ CONF;
                $this->assertConfig('database', 'database', '');
                $this->assertConfig('config', 'admin_email', 'admin@friendica.local');
                $this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
-               $this->assertConfig('system', 'language', 'de');
                $this->assertConfig('system', 'urlpath', '/friendica');
+               // TODO language changes back to en
+               //$this->assertConfig('system', 'language', 'de');
        }
 
        /**
@@ -264,15 +265,20 @@ CONF;
                $this->assertConfig('database', 'database', $this->db_data);
                $this->assertConfig('config', 'admin_email', 'admin@friendica.local');
                $this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
-               $this->assertConfig('system', 'language', 'de');
                $this->assertConfig('system', 'urlpath', '/friendica');
+               // TODO language changes back to en
+               //$this->assertConfig('system', 'language', 'de');
        }
 
        /**
         * @runTestsInSeparateProcesses
+        * @preserveGlobalState disabled
         */
        public function testNoDatabaseConnection()
        {
+               // TODO DBA mocking for whole console tests make this test work again
+               $this->markTestSkipped('DBA is already loaded, we have to mock the whole App to make it work');
+
                $dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
                $dbaMock
                        ->shouldReceive('connected')
index da92a0e0fb26d8defe3ee3748fe4ef2cba9b9883..9d3672c54230c812a74c076ecabf5f78e33486ff 100644 (file)
@@ -6,6 +6,10 @@ namespace Friendica\Core;
 use Friendica\Test\Util\VFSTrait;
 use PHPUnit\Framework\TestCase;
 
+/**
+ * @runTestsInSeparateProcesses
+ * @preserveGlobalState disabled
+ */
 class InstallTest extends TestCase
 {
        use VFSTrait;
@@ -46,9 +50,26 @@ class InstallTest extends TestCase
                };
        }
 
+       /**
+        * Replaces class_exist results with given mocks
+        *
+        * @param array $classes a list from class names and their results
+        */
+       private function setClasses($classes)
+       {
+               global $phpMock;
+               $phpMock['class_exists'] = function($class) use ($classes) {
+                       foreach ($classes as $name => $value) {
+                               if ($class == $name) {
+                                       return $value;
+                               }
+                       }
+                       return '__phpunit_continue__';
+               };
+       }
+
        /**
         * @small
-        * @runInSeparateProcess
         */
        public function testCheckKeys()
        {
@@ -63,7 +84,6 @@ class InstallTest extends TestCase
 
        /**
         * @small
-        * @runInSeparateProcess
         */
        public function testCheckFunctions()
        {
@@ -141,7 +161,6 @@ class InstallTest extends TestCase
 
        /**
         * @small
-        * @runInSeparateProcess
         */
        public function testCheckLocalIni()
        {
@@ -160,7 +179,6 @@ class InstallTest extends TestCase
 
        /**
         * @small
-        * @runInSeparateProcess
         */
        public function testCheckHtAccessFail()
        {
@@ -201,7 +219,6 @@ class InstallTest extends TestCase
 
        /**
         * @small
-        * @runInSeparateProcess
         */
        public function testCheckHtAccessWork()
        {
@@ -241,7 +258,6 @@ class InstallTest extends TestCase
 
        /**
         * @small
-        * @runInSeparateProcess
         */
        public function testImagick()
        {
@@ -250,10 +266,13 @@ class InstallTest extends TestCase
                        ->shouldReceive('supportedTypes')
                        ->andReturn(['image/gif' => 'gif']);
 
+               $this->setClasses(['Imagick' => true]);
+
                $install = new Install();
 
                // even there is no supported type, Imagick should return true (because it is not required)
                $this->assertTrue($install->checkImagick());
+
                $this->assertCheckExist(1,
                        L10n::t('ImageMagick supports GIF'),
                        '',
@@ -264,7 +283,6 @@ class InstallTest extends TestCase
 
        /**
         * @small
-        * @runInSeparateProcess
         */
        public function testImagickNotFound()
        {
@@ -273,6 +291,8 @@ class InstallTest extends TestCase
                        ->shouldReceive('supportedTypes')
                        ->andReturn([]);
 
+               $this->setClasses(['Imagick' => true]);
+
                $install = new Install();
 
                // even there is no supported type, Imagick should return true (because it is not required)
@@ -284,6 +304,22 @@ class InstallTest extends TestCase
                        false,
                        $install->getChecks());
        }
+
+       public function testImagickNotInstalled()
+       {
+               $this->setClasses(['Imagick' => false]);
+
+               $install = new Install();
+
+               // even there is no supported type, Imagick should return true (because it is not required)
+               $this->assertTrue($install->checkImagick());
+               $this->assertCheckExist(0,
+                       L10n::t('ImageMagick PHP extension is not installed'),
+                       '',
+                       false,
+                       false,
+                       $install->getChecks());
+       }
 }
 
 /**
@@ -304,3 +340,15 @@ function function_exists($function_name)
        }
        return call_user_func_array('\function_exists', func_get_args());
 }
+
+function class_exists($class_name)
+{
+       global $phpMock;
+       if (isset($phpMock['class_exists'])) {
+               $result = call_user_func_array($phpMock['class_exists'], func_get_args());
+               if ($result !== '__phpunit_continue__') {
+                       return $result;
+               }
+       }
+       return call_user_func_array('\class_exists', func_get_args());
+}
index b85bce44cb87df88d750c7ad386461230a47ab98..6b0781198a52ee828121771141c9f3cf4f4ac014 100644 (file)
@@ -34,4 +34,4 @@ class SystemTest extends TestCase
                $guid = System::createGUID(23, 'test');
                $this->assertGuid($guid, 23, 'test');
        }
-}
\ No newline at end of file
+}
index 56f285f2df9037f8f2dc405258f7bd51f495554b..6a0ed1af205af8312297bc9f0c2ed06495f143e7 100644 (file)
@@ -20,7 +20,7 @@ require_once 'include/dba.php';
  * This function is responsible for doing post update changes to the data
  * (not the structure) in the database.
  *
- * Database structure changes are done in src/Database/DBStructure.php
+ * Database structure changes are done in config/dbstructure.php
  *
  * If there is a need for a post process to a structure change, update this file
  * by adding a new function at the end with the number of the new DB_UPDATE_VERSION.
@@ -31,8 +31,8 @@ require_once 'include/dba.php';
  * You are currently on version 4711 and you are preparing changes that demand an update script.
  *
  * 1. Create a function "update_4712()" here in the update.php
- * 2. Apply the needed structural changes in src/Database/DBStructure.php
- * 3. Set DB_UPDATE_VERSION in boot.php to 4712.
+ * 2. Apply the needed structural changes in config/dbStructure.php
+ * 3. Set DB_UPDATE_VERSION in config/dbstructure.php to 4712.
  *
  * If you need to run a script before the database update, name the function "pre_update_4712()"
  */
@@ -246,3 +246,12 @@ function update_1278() {
 
        return UPDATE_SUCCESS;
 }
+
+function update_1288() {
+       // Updates missing `uri-id` values
+
+       DBA::e("UPDATE `item-activity` INNER JOIN `item` ON `item`.`iaid` = `item-activity`.`id` SET `item-activity`.`uri-id` = `item`.`uri-id` WHERE `item-activity`.`uri-id` IS NULL OR `item-activity`.`uri-id` = 0");
+       DBA::e("UPDATE `item-content` INNER JOIN `item` ON `item`.`icid` = `item-content`.`id` SET `item-content`.`uri-id` = `item`.`uri-id` WHERE `item-content`.`uri-id` IS NULL OR `item-content`.`uri-id` = 0");
+
+       return UPDATE_SUCCESS;
+}
index 202fd43b3e52ab065647f65d96a7b5eb6daec480..298097f792b6e64fc5ee3e286f3d44a5050a107e 100644 (file)
@@ -11,7 +11,7 @@
 
        <dl>
                <dt>{{$queues.label}}</dt>
-               <dd><a href="{{$baseurl}}/admin/queue">{{$queues.queue}}</a> - <a href="{{$baseurl}}/admin/workerqueue">{{$queues.workerq}}</a></dd>
+               <dd><a href="{{$baseurl}}/admin/queue">{{$queues.queue}}</a> - <a href="{{$baseurl}}/admin/deferred">{{$queues.deferred}} - <a href="{{$baseurl}}/admin/workerqueue">{{$queues.workerq}}</a></dd>
        </dl>
        <dl>
                <dt>{{$pending.0}}</dt>
index 344ee296a2056f244c3992c2341b38957cda5fd5..b4c34f74e2ca3a08f7ca52207837f963f0143856 100644 (file)
@@ -5,7 +5,7 @@
 
 
        <div id="contact-edit-nav-wrapper" >
-               <form action="contacts/{{$contact_id}}" method="post" >
+               <form action="contact/{{$contact_id}}" method="post" >
                        <div id="contact-edit-links">
                                <div id="contact-edit-status-wrapper">
                                        <span id="contact-edit-contact-status">{{$contact_status}}</span>
diff --git a/view/templates/debug/itemsource.tpl b/view/templates/debug/itemsource.tpl
new file mode 100644 (file)
index 0000000..377409e
--- /dev/null
@@ -0,0 +1,28 @@
+<h2>Item Source</h2>
+<form action="itemsource" method="get" class="panel panel-default">
+       <div class="panel-body">
+               <div class="form-group">
+                       {{include file="field_input.tpl" field=$guid}}
+               </div>
+               <p><button type="submit" class="btn btn-primary">Submit</button></p>
+       </div>
+</form>
+
+{{if $source}}
+<div class="itemsource-results">
+       <div class="panel panel-default">
+               <div class="panel-heading">
+                       <h3 class="panel-title">Item URI</h3>
+               </div>
+               <div class="panel-body">
+                       {{$item_uri}}
+               </div>
+       </div>
+       <div class="panel panel-default">
+               <div class="panel-heading">
+                       <h3 class="panel-title">Source</h3>
+               </div>
+               <pre><code class="language-php">{{$source}}</code></pre>
+       </div>
+</div>
+{{/if}}
index c563dd121a87bc6c680d775e388985f1e381b279..5fa84abdfe2a48d4a20f961cf77c837b8dbef80a 100644 (file)
@@ -1489,6 +1489,9 @@ section #jotOpen {
 .fbrowser.image .photo-album-image-wrapper {
     box-shadow: 2px 2px 5px 0px rgba(0, 0, 0, 0.2);
 }
+.fbrowser.image .photo-album-image-wrapper .caption {
+    pointer-events: none;
+}
 .fbrowser .profile-rotator-wrapper {
     min-height: 200px;
 }
index 3c33f92fdbe5dd03cc398861807e1e13144715e5..66afda721b24fdfcf6fc0f84e49d39a4bee1b8c9 100644 (file)
@@ -14,7 +14,7 @@
                {{* The work queues short statistic. *}}
                <div id="admin-summary-queues" class="col-lg-12 col-md-12 col-sm-12 col-xs-12 admin-summary">
                        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 admin-summary-label-name text-muted">{{$queues.label}}</div>
-                       <div class="col-lg-8 col-md-8 col-sm-8 col-xs-12 admin-summary-entry"><a href="{{$baseurl}}/admin/queue">{{$queues.queue}}</a> - <a href="{{$baseurl}}/admin/workerqueue">{{$queues.workerq}}</a></div>
+                       <div class="col-lg-8 col-md-8 col-sm-8 col-xs-12 admin-summary-entry"><a href="{{$baseurl}}/admin/queue">{{$queues.queue}}</a> - <a href="{{$baseurl}}/admin/deferred">{{$queues.deferred}} - <a href="{{$baseurl}}/admin/workerqueue">{{$queues.workerq}}</a></div>
                </div>
 
                {{* Number of pending registrations. *}}
index 4c12948dcef1b3d88d6d5b9e3385bd322b10e1b0..04426eeb12aa5b799d2cc2af2e1b1ae141d0c245 100644 (file)
@@ -9,7 +9,7 @@
 
 
                <div id="contact-edit-content-wrapper">
-                       <form action="contacts/{{$contact_id}}" method="post" >
+                       <form action="contact/{{$contact_id}}" method="post" >
 
                                {{* This is the Action menu where contact related actions like 'ignore', 'hide' can be performed *}}
                                <ul id="contact-edit-actions" class="nav nav-pills preferences">
diff --git a/view/theme/frio/templates/credits.tpl b/view/theme/frio/templates/credits.tpl
new file mode 100644 (file)
index 0000000..5e5aeec
--- /dev/null
@@ -0,0 +1,11 @@
+<div id="credits" class="generic-page-wrapper">
+        {{include file="section_title.tpl"}}
+        <p>{{$thanks}}</p>
+
+        <ul class="credits">
+                {{foreach $names as $name}}
+                 <li>{{$name}}</li>
+                {{/foreach}}
+        </ul>
+        <div class="clear"></div>
+</div>
index 63069a772138a48ecddaf8cd9bcae3496bd45938..9014be1d252356f5ee5d435ec8548d3cb98fbf6b 100644 (file)
@@ -6,7 +6,7 @@
 
 
        <div id="contact-edit-nav-wrapper" >
-               <form action="contacts/{{$contact_id}}" method="post" >
+               <form action="contact/{{$contact_id}}" method="post" >
                        <div id="contact-edit-links">
                                <div id="contact-edit-status-wrapper">
                                        <span id="contact-edit-contact-status">{{$contact_status}}</span>