]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #6209 from MrPetovan/task/move-config-to-php-array
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Sat, 29 Dec 2018 10:43:55 +0000 (11:43 +0100)
committerGitHub <noreply@github.com>
Sat, 29 Dec 2018 10:43:55 +0000 (11:43 +0100)
Remove util/ folder

131 files changed:
bin/auth_ejabberd.php
bin/console.php
bin/daemon.php
bin/worker.php
boot.php
composer.json
composer.lock
config/dbstructure.config.php
include/api.php
include/items.php
include/text.php
index.php
mod/acl.php
mod/admin.php
mod/allfriends.php
mod/attach.php
mod/bookmarklet.php
mod/common.php
mod/community.php
mod/dfrn_confirm.php
mod/dfrn_notify.php
mod/dfrn_poll.php
mod/dfrn_request.php
mod/display.php
mod/events.php
mod/feedtest.php
mod/filer.php
mod/item.php
mod/like.php
mod/lostpass.php
mod/manage.php
mod/match.php
mod/message.php
mod/msearch.php
mod/network.php
mod/nodeinfo.php
mod/notes.php
mod/parse_url.php
mod/photos.php
mod/phpinfo.php
mod/ping.php
mod/poke.php
mod/profile.php
mod/pubsub.php
mod/register.php
mod/regmod.php
mod/removeme.php
mod/salmon.php
mod/search.php
mod/subthread.php
mod/tagger.php
mod/videos.php
src/App.php
src/BaseObject.php
src/Content/ForumManager.php
src/Content/Nav.php
src/Content/OEmbed.php
src/Content/Pager.php
src/Content/Widget.php
src/Content/Widget/CalendarExport.php
src/Content/Widget/TagCloud.php
src/Core/Config.php
src/Core/Config/JITConfigAdapter.php
src/Core/Config/JITPConfigAdapter.php
src/Core/Config/PreloadConfigAdapter.php
src/Core/Config/PreloadPConfigAdapter.php
src/Core/Console/AutomaticInstallation.php
src/Core/Console/DatabaseStructure.php
src/Core/Console/GlobalCommunitySilence.php
src/Core/Console/Maintenance.php
src/Core/Installer.php
src/Core/L10n.php
src/Core/NotificationsManager.php
src/Core/PConfig.php
src/Core/Session/CacheSessionHandler.php
src/Core/Session/DatabaseSessionHandler.php
src/Core/Theme.php
src/Core/UserImport.php
src/Core/Worker.php
src/Database/DBA.php
src/Database/DBStructure.php
src/Database/PostUpdate.php
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/ItemContent.php
src/Model/ItemURI.php
src/Model/Mail.php
src/Model/PermissionSet.php
src/Model/Photo.php
src/Model/Process.php
src/Model/Profile.php
src/Model/PushSubscriber.php
src/Model/Queue.php
src/Model/Term.php
src/Model/User.php
src/Module/Hashtag.php
src/Module/Login.php
src/Module/Logout.php
src/Network/FKOAuthDataStore.php
src/Network/Probe.php
src/Object/Post.php
src/Object/Thread.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Protocol/Feed.php
src/Protocol/OStatus.php
src/Protocol/PortableContact.php
src/Util/ExAuth.php
src/Util/ParseUrl.php
src/Util/Temporal.php
src/Worker/Cron.php
src/Worker/CronJobs.php
src/Worker/DBClean.php
src/Worker/Delivery.php
src/Worker/Expire.php
src/Worker/Notifier.php
src/Worker/OnePoll.php
src/Worker/PubSubPublish.php
src/Worker/Queue.php
src/Worker/RemoveContact.php
src/Worker/RemoveUser.php
src/Worker/SpoolPost.php
tests/src/Core/InstallerTest.php
tests/src/Network/CurlResultTest.php
update.php
view/theme/frio/php/scheme.php

index 1f03b94af90017fb164221b2d6eab38a5d391aa9..e8a7b4963f629b8b9c31c4ca09c5d5e866776171 100755 (executable)
@@ -49,8 +49,7 @@ $directory = realpath($directory . DIRECTORY_SEPARATOR . "..");
 
 chdir($directory);
 
-require_once "boot.php";
-require_once "include/dba.php";
+require dirname(__DIR__) . '/vendor/autoload.php';
 
 $a = new App(dirname(__DIR__));
 
index 9c25279d37222a77acb62a186b556761251dd6f6..c39df953f287b0873748816638cd09475b82c5da 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env php
 <?php
 
-include_once dirname(__DIR__) . '/boot.php';
+require dirname(__DIR__) . '/vendor/autoload.php';
 
 $a = new Friendica\App(dirname(__DIR__));
 \Friendica\BaseObject::setApp($a);
index 9df8b8957ac4701e3973b1168946f87f90f1d5bf..e60e32b19ec0900caf57450c0d7c09794d69d2d3 100755 (executable)
@@ -30,8 +30,7 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
        chdir($directory);
 }
 
-require_once "boot.php";
-require_once "include/dba.php";
+require dirname(__DIR__) . '/vendor/autoload.php';
 
 $a = new App(dirname(__DIR__));
 
index 9ae2f68b3e6ae8a0fbe994b6fe47bf834aee2bb2..78b6da5857343598d81ce0825196d40fc4004b44 100755 (executable)
@@ -26,7 +26,7 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
        chdir($directory);
 }
 
-require_once "boot.php";
+require dirname(__DIR__) . '/vendor/autoload.php';
 
 $a = new App(dirname(__DIR__));
 
index 222011f6b76d7dc0ad2bb440c328437daf61bb5e..eb8176b83de8bb936ad51a87cee85212456438aa 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -17,8 +17,6 @@
  * easily as email does today.
  */
 
-require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
-
 use Friendica\App;
 use Friendica\BaseObject;
 use Friendica\Core\Addon;
@@ -35,8 +33,6 @@ use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
 use Friendica\Util\DateTimeFormat;
 
-require_once 'include/text.php';
-
 define('FRIENDICA_PLATFORM',     'Friendica');
 define('FRIENDICA_CODENAME',     'The Tazmans Flax-lily');
 define('FRIENDICA_VERSION',      '2018.12-rc');
index 2f12d076d4e5a35d465d65354ce87a916cd86eef..1d7348d84a7b784c0f614af687a0221731de0449 100644 (file)
@@ -14,6 +14,7 @@
        },
        "require": {
                "php": ">=5.6.1",
+               "ext-curl": "*",
                "ext-dom": "*",
                "ext-json": "*",
                "ext-xml": "*",
                },
                "psr-0": {
                        "": "library/"
-               }
+               },
+               "files": [
+                       "include/conversation.php",
+                       "include/dba.php",
+                       "include/enotify.php",
+                       "include/items.php",
+                       "include/text.php",
+                       "boot.php"
+               ]
        },
        "config": {
                "autoloader-suffix": "Friendica",
index d0ce1c4e72db0d2bc2d4d418dc7d6cdc3b8b9b38..5d46466d86fe638d50c241c459bb582f8dce7e01 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "11efc727fd6cae00c1230616e31ad2a2",
+    "content-hash": "9e0c66963fa451c1c317569c89c1b278",
     "packages": [
         {
             "name": "asika/simple-console",
     "prefer-lowest": false,
     "platform": {
         "php": ">=5.6.1",
+        "ext-curl": "*",
         "ext-dom": "*",
         "ext-json": "*",
         "ext-xml": "*"
index ca34936065c30097f53bd253e1290e0d85603812..61f0780dc4419ad79d4a5422088af56535965c13 100644 (file)
@@ -34,7 +34,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1291);
+       define('DB_UPDATE_VERSION', 1292);
 }
 
 return [
@@ -1059,6 +1059,7 @@ return [
                "indexes" => [
                        "PRIMARY" => ["id"],
                        "uid_is-default" => ["uid", "is-default"],
+                       "pub_keywords" => ["FULLTEXT", "pub_keywords"],
                ]
        ],
        "profile_check" => [
index 20b3844cd5cc93d7a96cf03f1b1f96a34a5920e7..ddcb8c8dcdb3fad71da3cb3e5152b225d68a88d2 100644 (file)
@@ -46,7 +46,6 @@ use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'include/conversation.php';
 require_once 'mod/share.php';
 require_once 'mod/item.php';
 require_once 'mod/wall_upload.php';
index b4793b888f3fb6a531852560a54650a749524c15..ddec2231d83cbf01eda4052e04e7e19ae793d0d5 100644 (file)
@@ -24,10 +24,7 @@ use Friendica\Util\ParseUrl;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
-require_once 'include/text.php';
 require_once 'mod/share.php';
-require_once 'include/enotify.php';
-
 function add_page_info_data(array $data, $no_photos = false)
 {
        Addon::callHooks('page_info_data', $data);
index ee83345c09954bc3cb351441ac6a3ff03e561149..ff9fa5511a0158c2867d8445a08a83c382664c5d 100644 (file)
@@ -30,8 +30,6 @@ use Friendica\Util\Strings;
 use Friendica\Util\XML;
 use Friendica\Content\Text\HTML;
 
-require_once "include/conversation.php";
-
 /**
  * Turn user/group ACLs stored as angle bracketed text into arrays
  *
index 43bfd3800e684429dcf82196d3b5f76d9cf96220..efcfe439246d5187c542b3a42f8263788bdd3f6d 100644 (file)
--- a/index.php
+++ b/index.php
@@ -4,12 +4,10 @@
  * Friendica
  */
 
-use Friendica\App;
-
-require_once 'boot.php';
+require __DIR__ . '/vendor/autoload.php';
 
 // We assume that the index.php is called by a frontend process
 // The value is set to "true" by default in App
-$a = new App(__DIR__, false);
+$a = new Friendica\App(__DIR__, false);
 
 $a->runFrontend();
index 86eafe29028db053ed55d380db8869fa982ffb15..e91919265b350e51b1ec3808b0b527723390edae 100644 (file)
@@ -14,8 +14,6 @@ use Friendica\Model\Item;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
 
-require_once 'include/dba.php';
-
 function acl_content(App $a)
 {
        if (!local_user()) {
index eab2e722674439eba8822d2dc0016a30531a7d16..b906ad7d0557613856214e78d2fc8ed9302e823f 100644 (file)
@@ -33,10 +33,6 @@ use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
-require_once 'include/enotify.php';
-require_once 'include/text.php';
-require_once 'include/items.php';
-
 /**
  * @brief Process send data from the admin panels subpages
  *
index 7a39c481db50786353d255bce8e61f1e5491d716..ceb32e6c1898dcefe2b2cc768c15ff609f5a9ef4 100644 (file)
@@ -15,8 +15,6 @@ use Friendica\Module;
 use Friendica\Util\Proxy as ProxyUtils;
 
 
-require_once 'include/dba.php';
-
 function allfriends_content(App $a)
 {
        $o = '';
index 9ca701ba356ebde93865136b15dd19ef927d33b0..cf2c8cc6dd55d68191fb94d639dce31e7158f3bd 100644 (file)
@@ -8,8 +8,6 @@ use Friendica\Core\L10n;
 use Friendica\Database\DBA;
 use Friendica\Util\Security;
 
-require_once 'include/dba.php';
-
 function attach_init(App $a)
 {
        if ($a->argc != 2) {
index d9c2f52f821d0a449c7a24b116fd0f36358ae4dd..be3e1fd33670e1a5638b3f42a55a6fe9fd9ea2c8 100644 (file)
@@ -11,9 +11,6 @@ use Friendica\Core\System;
 use Friendica\Module\Login;
 use Friendica\Util\Strings;
 
-require_once 'include/conversation.php';
-require_once 'include/items.php';
-
 function bookmarklet_init()
 {
        $_GET["mode"] = "minimal";
index c93edf3b3097666b60dc4e8770f70f10dbef0809..1c4032f11f411e49fbe0d6e81a8598cad21b827d 100644 (file)
@@ -14,8 +14,6 @@ use Friendica\Module;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
 
-require_once 'include/dba.php';
-
 function common_content(App $a)
 {
        $o = '';
index 36668817323c2357e0c5c1cf09748cc2f3c26a1c..063e1c693eafcd5d9d5a49d0b0f9b0eecd67d981 100644 (file)
@@ -93,8 +93,6 @@ function community_content(App $a, $update = 0)
                }
        }
 
-       require_once 'include/conversation.php';
-
        if (!$update) {
                $tabs = [];
 
index 6f365c5315bf99aa3a35deaa08ea40fe1ca7bf7c..c78cf45e721e9cd36f9f2b5d32cf8efec3ea39f7 100644 (file)
@@ -36,9 +36,6 @@ use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'include/enotify.php';
-require_once 'include/items.php';
-
 function dfrn_confirm_post(App $a, $handsfree = null)
 {
        $node = null;
index 51576b3b4ec7dec6be551b53d9e5b75f8cd54128..b911a27e219d9f9fe22cff16eeff4c8e28cf9f4c 100644 (file)
@@ -16,8 +16,6 @@ use Friendica\Protocol\DFRN;
 use Friendica\Protocol\Diaspora;
 use Friendica\Util\Strings;
 
-require_once 'include/items.php';
-
 function dfrn_notify_post(App $a) {
        Logger::log(__function__, Logger::TRACE);
 
index acc279be264d77bb4710f2a84674fc6f66f67936..6b2016886db462274ad9da07712f11de6505c43b 100644 (file)
@@ -17,8 +17,6 @@ use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'include/items.php';
-
 function dfrn_poll_init(App $a)
 {
        Login::sessionAuth();
index 0e24accc013855f307e70b8c5ddcf1249ad58aa7..15e11c3dab33029f99eca968da730d2ad91c5b8e 100644 (file)
@@ -30,8 +30,6 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 
-require_once 'include/enotify.php';
-
 function dfrn_request_init(App $a)
 {
        if ($a->argc > 1) {
index 2a4d2abf43b6d1971db094cffcaba8a65e969f13..a616fc8cc343022dcdbe7b0240f14795157cf8c5 100644 (file)
@@ -214,8 +214,6 @@ function display_content(App $a, $update = false, $update_uid = 0)
                return;
        }
 
-       require_once 'include/conversation.php';
-
        $o = '';
 
        if ($update) {
@@ -291,8 +289,8 @@ function display_content(App $a, $update = false, $update_uid = 0)
 
        $parent = Item::selectFirst(['uid'], ['uri' => $item_parent_uri, 'wall' => true]);
        if (DBA::isResult($parent)) {
-               $a->profile['uid'] = $parent['uid'];
-               $a->profile['profile_uid'] = $parent['uid'];
+               $a->profile['uid'] = defaults($a->profile, 'uid', $parent['uid']);
+               $a->profile['profile_uid'] = defaults($a->profile, 'profile_uid', $parent['uid']);
                $is_remote_contact = Contact::isFollower(remote_user(), $a->profile['profile_uid']);
        }
 
index cb91fae35147ad36480722ae8756b3940e0fe6ee..a54260c435ef95ca3f73413c1184ab80a0861835 100644 (file)
@@ -22,8 +22,6 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
-require_once 'include/items.php';
-
 function events_init(App $a)
 {
        if (!local_user()) {
index edb75aefc160cb1eb6d57da709a28cf62c5d6100..8508b93e47002089a400a9eb86d7b48d3d7bc227 100644 (file)
@@ -12,10 +12,6 @@ use Friendica\Model\Contact;
 use Friendica\Protocol\Feed;
 use Friendica\Util\Network;
 
-require_once 'boot.php';
-require_once 'include/dba.php';
-require_once 'include/text.php';
-
 function feedtest_content(App $a)
 {
        if (!local_user()) {
index 3508079400411a50f15495a0c9d3c86108d1a78b..4580dc6f67fd8a8e5051aac6e21129afc0288437 100644 (file)
@@ -10,8 +10,6 @@ use Friendica\Core\Renderer;
 use Friendica\Model\FileTag;
 use Friendica\Util\XML;
 
-require_once 'include/items.php';
-
 function filer_content(App $a)
 {
        if (! local_user()) {
index cc801df57c1b62ce0d0878332807c3449c9109b2..02a61ebefcac10981788834848ef471878293c4e 100644 (file)
@@ -38,10 +38,6 @@ use Friendica\Util\Emailer;
 use Friendica\Util\Security;
 use Friendica\Util\Strings;
 
-require_once 'include/enotify.php';
-require_once 'include/text.php';
-require_once 'include/items.php';
-
 function item_post(App $a) {
        if (!local_user() && !remote_user()) {
                return 0;
@@ -668,7 +664,6 @@ function item_post(App $a) {
 
        // preview mode - prepare the body for display and send it via json
        if ($preview) {
-               require_once 'include/conversation.php';
                // We set the datarray ID to -1 because in preview mode the dataray
                // doesn't have an ID.
                $datarray["id"] = -1;
index 5ea30a3ffef985ba5d8cc27d4f091588f173341a..7ce7b1a1b912b9b1341db081e20aa6c67f766216 100644 (file)
@@ -5,8 +5,6 @@ use Friendica\Core\System;
 use Friendica\Model\Item;
 use Friendica\Util\Strings;
 
-require_once 'include/items.php';
-
 function like_content(App $a) {
        if (!local_user() && !remote_user()) {
                return false;
index 42a1764bf93a4561cbcb7e1d266b31fa858d0314..39209af951ed6574334bfb1f52e50d8610f313ab 100644 (file)
@@ -13,10 +13,6 @@ use Friendica\Model\User;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
 
-require_once 'boot.php';
-require_once 'include/enotify.php';
-require_once 'include/text.php';
-
 function lostpass_post(App $a)
 {
        $loginame = Strings::escapeTags(trim($_POST['login-name']));
index b42b990aad404796b82b0f1480037273feb7539d..4d0b65de1533e480dab6d1764910f5b440d9ac86 100644 (file)
@@ -10,8 +10,6 @@ use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 
-require_once "include/text.php";
-
 function manage_post(App $a) {
 
        if (! local_user()) {
index 0ec753466267a738fd626ba922abecafec02332b..451821f9f1285a0969ee3ed5841cd5483166d0cd 100644 (file)
@@ -12,11 +12,9 @@ use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
+use Friendica\Model\Profile;
 use Friendica\Util\Network;
 use Friendica\Util\Proxy as ProxyUtils;
-use Friendica\Util\Strings;
-
-require_once 'include/text.php';
 
 /**
  * @brief Controller for /match.
@@ -26,13 +24,12 @@ require_once 'include/text.php';
  *
  * @param App $a App
  *
- * @return void|string
+ * @return string
  */
 function match_content(App $a)
 {
-       $o = '';
-       if (! local_user()) {
-               return;
+       if (!local_user()) {
+               return '';
        }
 
        $a->page['aside'] .= Widget::findPeople();
@@ -40,91 +37,102 @@ function match_content(App $a)
 
        $_SESSION['return_path'] = $a->cmd;
 
-       $r = q(
-               "SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
-               intval(local_user())
-       );
-       if (! DBA::isResult($r)) {
-               return;
+       $profile = Profile::getByUID(local_user());
+
+       if (!DBA::isResult($profile)) {
+               return '';
        }
-       if (! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) {
+       if (!$profile['pub_keywords'] && (!$profile['prv_keywords'])) {
                notice(L10n::t('No keywords to match. Please add keywords to your default profile.') . EOL);
-               return;
+               return '';
        }
 
        $params = [];
-       $tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']);
+       $tags = trim($profile['pub_keywords'] . ' ' . $profile['prv_keywords']);
 
-       if ($tags) {
-               $pager = new Pager($a->query_string);
+       $params['s'] = $tags;
+       $params['n'] = 100;
 
-               $params['s'] = $tags;
-               if ($pager->getPage() != 1) {
-                       $params['p'] = $pager->getPage();
-               }
+       if (strlen(Config::get('system', 'directory'))) {
+               $host = get_server();
+       } else {
+               $host = System::baseUrl();
+       }
 
-               if (strlen(Config::get('system', 'directory'))) {
-                       $x = Network::post(get_server().'/msearch', $params)->getBody();
-               } else {
-                       $x = Network::post(System::baseUrl() . '/msearch', $params)->getBody();
-               }
+       $msearch_json = Network::post($host . '/msearch', $params)->getBody();
 
-               $j = json_decode($x);
-
-               if (count($j->results)) {
-                       $pager->setItemsPerPage($j->items_page);
-
-                       $id = 0;
-
-                       foreach ($j->results as $jj) {
-                               $match_nurl = Strings::normaliseLink($jj->url);
-                               $match = q(
-                                       "SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
-                                       intval(local_user()),
-                                       DBA::escape($match_nurl)
-                               );
-
-                               if (!count($match)) {
-                                       $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
-                                       $connlnk = System::baseUrl() . '/follow/?url=' . $jj->url;
-                                       $photo_menu = [
-                                               'profile' => [L10n::t("View Profile"), Contact::magicLink($jj->url)],
-                                               'follow' => [L10n::t("Connect/Follow"), $connlnk]
-                                       ];
-
-                                       $contact_details = Contact::getDetailsByURL($jj->url, local_user());
-
-                                       $entry = [
-                                               'url' => Contact::magicLink($jj->url),
-                                               'itemurl' => defaults($contact_details, 'addr', $jj->url),
-                                               'name' => $jj->name,
-                                               'details'       => defaults($contact_details, 'location', ''),
-                                               'tags'          => defaults($contact_details, 'keywords', ''),
-                                               'about'         => defaults($contact_details, 'about', ''),
-                                               'account_type'  => Contact::getAccountType($contact_details),
-                                               'thumb' => ProxyUtils::proxifyUrl($jj->photo, false, ProxyUtils::SIZE_THUMB),
-                                               'inttxt' => ' ' . L10n::t('is interested in:'),
-                                               'conntxt' => L10n::t('Connect'),
-                                               'connlnk' => $connlnk,
-                                               'img_hover' => $jj->tags,
-                                               'photo_menu' => $photo_menu,
-                                               'id' => ++$id,
-                                       ];
-                                       $entries[] = $entry;
-                               }
-                       }
+       $msearch = json_decode($msearch_json);
+
+       $start = defaults($_GET, 'start', 0);
+       $entries = [];
+       $paginate = '';
 
-                       $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
+       if (!empty($msearch->results)) {
+               for ($i = $start;count($entries) < 10 && $i < $msearch->total; $i++) {
+                       $profile = $msearch->results[$i];
 
-                       $o .= Renderer::replaceMacros($tpl, [
-                               '$title'    => L10n::t('Profile Match'),
-                               '$contacts' => $entries,
-                               '$paginate' => $pager->renderFull($j->total)
-                       ]);
-               } else {
-                       info(L10n::t('No matches') . EOL);
+                       // Already known contact
+                       if (Contact::getIdForURL($profile->url, local_user(), true)) {
+                               continue;
+                       }
+
+                       // Workaround for wrong directory photo URL
+                       $profile->photo = str_replace('http:///photo/', get_server() . '/photo/', $profile->photo);
+
+                       $connlnk = System::baseUrl() . '/follow/?url=' . $profile->url;
+                       $photo_menu = [
+                               'profile' => [L10n::t("View Profile"), Contact::magicLink($profile->url)],
+                               'follow' => [L10n::t("Connect/Follow"), $connlnk]
+                       ];
+
+                       $contact_details = Contact::getDetailsByURL($profile->url, 0);
+
+                       $entry = [
+                               'url'          => Contact::magicLink($profile->url),
+                               'itemurl'      => defaults($contact_details, 'addr', $profile->url),
+                               'name'         => $profile->name,
+                               'details'      => defaults($contact_details, 'location', ''),
+                               'tags'         => defaults($contact_details, 'keywords', ''),
+                               'about'        => defaults($contact_details, 'about', ''),
+                               'account_type' => Contact::getAccountType($contact_details),
+                               'thumb'        => ProxyUtils::proxifyUrl($profile->photo, false, ProxyUtils::SIZE_THUMB),
+                               'conntxt'      => L10n::t('Connect'),
+                               'connlnk'      => $connlnk,
+                               'img_hover'    => $profile->tags,
+                               'photo_menu'   => $photo_menu,
+                               'id'           => $i,
+                       ];
+                       $entries[] = $entry;
                }
+
+               $data = [
+                       'class' => 'pager',
+                       'first' => [
+                               'url'   => 'match',
+                               'text'  => L10n::t('first'),
+                               'class' => 'previous' . ($start == 0 ? 'disabled' : '')
+                       ],
+                       'next'  => [
+                               'url'   => 'match?start=' . $i,
+                               'text'  => L10n::t('next'),
+                               'class' =>  'next' . ($i >= $msearch->total ? ' disabled' : '')
+                       ]
+               ];
+
+               $tpl = Renderer::getMarkupTemplate('paginate.tpl');
+               $paginate = Renderer::replaceMacros($tpl, ['pager' => $data]);
        }
 
+       if (empty($entries)) {
+               info(L10n::t('No matches') . EOL);
+       }
+
+       $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
+       $o = Renderer::replaceMacros($tpl, [
+               '$title'    => L10n::t('Profile Match'),
+               '$contacts' => $entries,
+               '$paginate' => $paginate
+       ]);
+
        return $o;
 }
index d0993698b7507f9905a11dd90934719e2fd2455d..9ef55fbfe83bf4f7eb478593e2a02f9159c91163 100644 (file)
@@ -21,8 +21,6 @@ use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
-require_once 'include/conversation.php';
-
 function message_init(App $a)
 {
        $tabs = '';
index d3477b0d59127e490c2bc683c70cdd839fc26473..64c6ce3cf8a0c2f5a2ad9dfebbb8463b321c2aac 100644 (file)
@@ -4,45 +4,64 @@ use Friendica\App;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 
-function msearch_post(App $a) {
+function msearch_post(App $a)
+{
+       $search = defaults($_POST, 's', '');
+       $perpage  = intval(defaults($_POST, 'n', 80));
+       $page     = intval(defaults($_POST, 'p', 1));
+       $startrec = ($page - 1) * $perpage;
 
-       $perpage = (($_POST['n']) ? $_POST['n'] : 80);
-       $page = (($_POST['p']) ? intval($_POST['p'] - 1) : 0);
-       $startrec = (($page+1) * $perpage) - $perpage;
+       $total = 0;
+       $results = [];
 
-       $search = $_POST['s'];
-       if(! strlen($search))
-               killme();
+       if (!strlen($search)) {
+               $output = ['total' => 0, 'items_page' => $perpage, 'page' => $page, 'results' => $results];
+               echo json_encode($output);
+               exit();
+       }
 
-       $r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `user`.`hidewall` = 0 AND MATCH `pub_keywords` AGAINST ('%s') ",
-               DBA::escape($search)
+       $count_stmt = DBA::p(
+               "SELECT COUNT(*) AS `total`
+                       FROM `profile`
+                       JOIN `user` ON `user`.`uid` = `profile`.`uid`
+                       WHERE `is-default` = 1
+                       AND `user`.`hidewall` = 0
+                       AND MATCH(`pub_keywords`) AGAINST (?)",
+               $search
        );
 
-       if (DBA::isResult($r))
-               $total = $r[0]['total'];
+       if (DBA::isResult($count_stmt)) {
+               $row = DBA::fetch($count_stmt);
+               $total = $row['total'];
+       }
 
-       $results = [];
+       DBA::close($count_stmt);
 
-       $r = q("SELECT `pub_keywords`, `username`, `nickname`, `user`.`uid` FROM `user` LEFT JOIN `profile` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `user`.`hidewall` = 0 AND MATCH `pub_keywords` AGAINST ('%s') LIMIT %d , %d ",
-               DBA::escape($search),
-               intval($startrec),
-               intval($perpage)
+       $search_stmt = DBA::p(
+               "SELECT `pub_keywords`, `username`, `nickname`, `user`.`uid`
+                       FROM `user`
+                       JOIN `profile` ON `user`.`uid` = `profile`.`uid`
+                       WHERE `is-default` = 1
+                       AND `user`.`hidewall` = 0
+                       AND MATCH(`pub_keywords`) AGAINST (?)
+                       LIMIT ?, ?",
+               $search,
+               $startrec,
+               $perpage
        );
 
-       if (DBA::isResult($r)) {
-               foreach($r as $rr)
-                       $results[] = [
-                               'name' => $rr['name'],
-                               'url' => System::baseUrl() . '/profile/' . $rr['nickname'],
-                               'photo' => System::baseUrl() . '/photo/avatar/' . $rr['uid'] . '.jpg',
-                               'tags' => str_replace([',','  '],[' ',' '],$rr['pub_keywords'])
-                       ];
+       while($search_result = DBA::fetch($search_stmt)) {
+               $results[] = [
+                       'name'  => $search_result['name'],
+                       'url'   => System::baseUrl() . '/profile/' . $search_result['nickname'],
+                       'photo' => System::baseUrl() . '/photo/avatar/' . $search_result['uid'] . '.jpg',
+                       'tags'  => str_replace([',', '  '], [' ', ' '], $search_result['pub_keywords'])
+               ];
        }
 
-       $output = ['total' => $total, 'items_page' => $perpage, 'page' => $page + 1, 'results' => $results];
+       $output = ['total' => $total, 'items_page' => $perpage, 'page' => $page, 'results' => $results];
 
        echo json_encode($output);
 
-       killme();
-
+       exit();
 }
index 6a4413b54e88d355ca5977d223f934a6b141cd03..29a340afdc240c6d8b3c1c786f1c2af388f5674b 100644 (file)
@@ -30,9 +30,6 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
 
-require_once 'include/conversation.php';
-require_once 'include/items.php';
-
 function network_init(App $a)
 {
        if (!local_user()) {
index ca4a622fbb8e7afd78d334c99960e2c065e5155f..d1df2170406a6754a3a7d0202d5d4e61f794fa10 100644 (file)
@@ -12,8 +12,6 @@ use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Util\Network;
-require_once 'include/dba.php';
-
 function nodeinfo_wellknown(App $a) {
        $nodeinfo = ['links' => [['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
                                        'href' => System::baseUrl().'/nodeinfo/1.0']]];
index 90afa16ca537db09b91ff69759803eace473a952..6ecc819240ff67d817f27dc9ee91c7aa540d61ec 100644 (file)
@@ -34,8 +34,6 @@ function notes_content(App $a, $update = false)
                return;
        }
 
-       require_once 'include/conversation.php';
-
        $o = Profile::getTabs($a, true);
 
        if (!$update) {
index 07f319fdca69e8ab2372b29b1302a81d1c97398c..02fbfa1b7db07a5e63c37eea9211fbf88222fc8f 100644 (file)
@@ -15,8 +15,6 @@ use Friendica\Core\Logger;
 use Friendica\Util\Network;
 use Friendica\Util\ParseUrl;
 
-require_once 'include/items.php';
-
 function parse_url_content(App $a)
 {
        $text = null;
index d1dffd4d058ef8ab892005fffb696546725aef6c..05943352ba327b3aa2a3bfb04cd552807ae8e275 100644 (file)
@@ -34,8 +34,6 @@ use Friendica\Util\Temporal;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'include/items.php';
-
 function photos_init(App $a) {
 
        if ($a->argc > 1) {
@@ -946,8 +944,6 @@ function photos_content(App $a)
                return;
        }
 
-       require_once 'include/conversation.php';
-
        if (empty($a->data['user'])) {
                notice(L10n::t('No photos selected') . EOL);
                return;
index ec2897dc6dee33f5036d814281aac51bbb30dfb3..0155609abd6434c16595c60e748e9bc798437046 100644 (file)
@@ -3,8 +3,6 @@
  * @file mod/phpinfo.php
  */
 
-require_once 'boot.php';
-
 function phpinfo_content()
 {
        if (!is_site_admin()) {
index 40700f36f862c70486e949a5f2a9d826fb3758c6..b315ecf4b97a1ec597330e864621bf1aec046d28 100644 (file)
@@ -22,8 +22,6 @@ use Friendica\Util\Temporal;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\XML;
 
-require_once 'include/enotify.php';
-
 /**
  * @brief Outputs the counts and the lists of various notifications
  *
index f1bad7742b5ebedb6810920a37e171b05d732eca..fb1fae85d6727db111a98371171417d8b85bbebf 100644 (file)
@@ -25,8 +25,6 @@ use Friendica\Model\Item;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'include/items.php';
-
 function poke_init(App $a)
 {
        if (!local_user()) {
index 87ad9a9e97e3211e918574ff5fcbb1c384682c7d..51f8ca7534124f8174747d60cfd5a93fa7cca19e 100644 (file)
@@ -127,9 +127,6 @@ function profile_content(App $a, $update = 0)
                return Login::form();
        }
 
-       require_once 'include/conversation.php';
-       require_once 'include/items.php';
-
        $groups = [];
        $remote_cid = null;
 
index cd2f21dd67904907cc73646688442e1e14c4498f..8d6e81a68523e6e862661130205322eb5c5225dc 100644 (file)
@@ -9,8 +9,6 @@ use Friendica\Protocol\OStatus;
 use Friendica\Util\Strings;
 use Friendica\Core\System;
 
-require_once 'include/items.php';
-
 function hub_return($valid, $body)
 {
        if ($valid) {
index 03d4cb02f66196600c0ae6cdb98a14dfd522e3f3..b13ec225098837ea33d39ccba714ea81cf71eb4c 100644 (file)
@@ -18,8 +18,6 @@ use Friendica\Model;
 use Friendica\Module\Tos;
 use Friendica\Util\Strings;
 
-require_once 'include/enotify.php';
-
 function register_post(App $a)
 {
        BaseModule::checkFormSecurityTokenRedirectOnError('/register', 'register');
index a7aebf6b0a4ebfd9bf8580653842b21e637f63cc..a772a78ce77e6b4ccdf9f2cc09317572b0defcbc 100644 (file)
@@ -13,8 +13,6 @@ use Friendica\Model\Register;
 use Friendica\Model\User;
 use Friendica\Module\Login;
 
-require_once 'include/enotify.php';
-
 function user_allow($hash)
 {
        $a = get_app();
index 19bf0bc8515ba094091cdec26e7bbf2dcd90a296..741a67598a2745b575ff2e8deaa704a6c8d112ed 100644 (file)
@@ -12,8 +12,6 @@ use Friendica\Database\DBA;
 use Friendica\Model\User;
 use Friendica\Util\Strings;
 
-require_once 'include/enotify.php';
-
 function removeme_post(App $a)
 {
        if (!local_user()) {
index 02339c7779fb07643d48104bf4130cf1e73a67bb..eef25107626ac6754339780bbd995c5a61e6aeb9 100644 (file)
@@ -14,8 +14,6 @@ use Friendica\Protocol\Salmon;
 use Friendica\Util\Crypto;
 use Friendica\Util\Strings;
 
-require_once 'include/items.php';
-
 function salmon_post(App $a, $xml = '') {
 
        if (empty($xml)) {
index b40fe07157f233f3b3825a0ed3675e3e2c51e9f0..2cdfd6e12826cdbb81e39e0b1871a77d0942ffd0 100644 (file)
@@ -18,7 +18,6 @@ use Friendica\Database\DBA;
 use Friendica\Model\Item;
 use Friendica\Util\Strings;
 
-require_once 'include/conversation.php';
 require_once 'mod/dirfind.php';
 
 function search_saved_searches() {
index 90ab5a3aabbddf46c0db8d1f26ea98655ee3c7fe..bd7fee534e81b1fb80dfda60405da38f60f40055 100644 (file)
@@ -13,8 +13,6 @@ use Friendica\Util\Security;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'include/items.php';
-
 function subthread_content(App $a) {
 
        if (!local_user() && !remote_user()) {
index f8979ae6cac05f102f7be5cc4423675b1b25fbf5..78133a9e1823a30498262e811269eee948c910e0 100644 (file)
@@ -13,8 +13,6 @@ use Friendica\Model\Item;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'include/items.php';
-
 function tagger_content(App $a) {
 
        if (!local_user() && !remote_user()) {
index 9e64321f3ed52d2bc295c9cbcfa0b1af54405f32..d8aac1821045ee20877a9bdd3949dcd87e11a9ba 100644 (file)
@@ -18,8 +18,6 @@ use Friendica\Model\Profile;
 use Friendica\Protocol\DFRN;
 use Friendica\Util\Security;
 
-require_once 'include/items.php';
-
 function videos_init(App $a)
 {
        if ($a->argc > 1) {
@@ -195,8 +193,6 @@ function videos_content(App $a)
                return;
        }
 
-       require_once 'include/conversation.php';
-
        if (empty($a->data['user'])) {
                notice(L10n::t('No videos selected') . EOL );
                return;
index 261c3e74cb6f970701ae11281c929905470a3fbd..57d61d04bb32eca58dacf912a886b54ea1870645 100644 (file)
@@ -11,9 +11,6 @@ use Exception;
 use Friendica\Database\DBA;
 use Friendica\Network\HTTPException\InternalServerErrorException;
 
-require_once 'boot.php';
-require_once 'include/text.php';
-
 /**
  *
  * class: App
index d006c249defde79fc07243794a13d61ade733a8e..33ed67754674b34731bef4eab345df47be755468 100644 (file)
@@ -4,8 +4,6 @@
  */
 namespace Friendica;
 
-require_once 'boot.php';
-
 /**
  * Basic object
  *
index 7b947359a6521a246b1ebcba64e3f35f4ffb0f9d..ac745c50ff672655ea5b16be8c68cf1c9202d3e8 100644 (file)
@@ -15,8 +15,6 @@ use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Util\Proxy as ProxyUtils;
 
-require_once 'include/dba.php';
-
 /**
  * @brief This class handles methods related to the forum functionality
  */
index 5166d5848e1463ba1dd8eb424339e2ce3ba67339..81985ed5ba5a612ff030f47289e9344565a85884 100644 (file)
@@ -15,9 +15,6 @@ use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
 
-require_once 'boot.php';
-require_once 'include/text.php';
-
 class Nav
 {
        private static $selected = [
index 6eb11c7b3b2041c4a1fc40e009bdc86334eb3317..243b2d949d9c3c2e1bc91ecdd384b3ebedbdf33b 100644 (file)
@@ -23,8 +23,6 @@ use Friendica\Util\ParseUrl;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
 
-require_once 'include/dba.php';
-
 /**
  * Handles all OEmbed content fetching and replacement
  *
index 098d8e87960d4c828511cbdff5e897b770558cd6..0a1766fe593ad225caa0d6555d202572d8650291 100644 (file)
@@ -169,7 +169,7 @@ class Pager
                        'next'  => [
                                'url'   => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
                                'text'  => L10n::t('older'),
-                               'class' =>  'next' . ($displayedItemCount <= 0 ? ' disabled' : '')
+                               'class' =>  'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '')
                        ]
                ];
 
index d4d4ff54949ae974ffad4c05b33f9f60fd88eea8..2a11cc59195a269efa2748ec484e3ba9b0c905eb 100644 (file)
@@ -21,9 +21,6 @@ use Friendica\Model\Profile;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'boot.php';
-require_once 'include/dba.php';
-
 class Widget
 {
        /**
index e8bec0b95a451211e97ed2b5373bb099dc63dc5b..7bfa73c60762beb061c102e4a1b9b0c41edc8153 100644 (file)
@@ -10,9 +10,6 @@ use Friendica\Content\Feature;
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
 
-require_once 'boot.php';
-require_once 'include/text.php';
-
 /**
  * TagCloud widget
  *
index 23aac19eb79a2a0c7c9ad6cfaf5a14b77898776e..f214ba799951d882196ee57fb9d4ae00be729cb4 100644 (file)
@@ -13,8 +13,6 @@ use Friendica\Database\DBA;
 use Friendica\Model\Item;
 use Friendica\Util\Security;
 
-require_once 'include/dba.php';
-
 /**
  * TagCloud widget
  *
index a07bbd31c9130fa76ad0bd9ae8dfe808ce191498..f191c10a0e3cab93a6be7d0eb0c4afec16719ce7 100644 (file)
@@ -12,8 +12,6 @@ use Friendica\App;
 use Friendica\BaseObject;
 use Friendica\Core\Config;
 
-require_once 'include/dba.php';
-
 /**
  * @brief Arbitrary system configuration storage
  *
index 2018f583d610c6d466c62245c732fec81f1c04cc..ed5f1a3f673ed0b623af7182972335143181c0e7 100644 (file)
@@ -4,8 +4,6 @@ namespace Friendica\Core\Config;
 use Friendica\BaseObject;
 use Friendica\Database\DBA;
 
-require_once 'include/dba.php';
-
 /**
  * JustInTime Configuration Adapter
  *
index 512004b50835199f0cd15ad4164046ef47239a7f..bdaca407ffa583f88aa0c5c36a2dcf0fb4275471 100644 (file)
@@ -4,8 +4,6 @@ namespace Friendica\Core\Config;
 use Friendica\BaseObject;
 use Friendica\Database\DBA;
 
-require_once 'include/dba.php';
-
 /**
  * JustInTime User Configuration Adapter
  *
index 67cf30845c3ff1e10d24876e15e495b2db45263b..ac59d945580ca6d6e55ffebda4fdff8a042a5c4a 100644 (file)
@@ -6,8 +6,6 @@ use Exception;
 use Friendica\BaseObject;
 use Friendica\Database\DBA;
 
-require_once 'include/dba.php';
-
 /**
  * Preload Configuration Adapter
  *
index ebccb018bce6a85eb0776fd525cff8bdadbb68f6..6658efa3f67f571e2d1c93f60aa17bb67392a8ba 100644 (file)
@@ -6,8 +6,6 @@ use Exception;
 use Friendica\BaseObject;
 use Friendica\Database\DBA;
 
-require_once 'include/dba.php';
-
 /**
  * Preload User Configuration Adapter
  *
index e6065dfb877d2a1cecc2eb6da2bc3311456c8c98..c2f9df383b23182a5a145014fe76b447dbfc9141 100644 (file)
@@ -11,8 +11,6 @@ use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use RuntimeException;
 
-require_once 'include/dba.php';
-
 class AutomaticInstallation extends Console
 {
        protected function getHelp()
index f3badc1969062485aa758744d28834fe8f7daeee..47e6af5eb1f508efa63a41d6ffca59e3c0c7cff0 100644 (file)
@@ -8,9 +8,6 @@ use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use RuntimeException;
 
-require_once 'boot.php';
-require_once 'include/dba.php';
-
 /**
  * @brief Performs database updates from the command line
  *
index 01413cab13ffe05bd4d93beb846f380abc942c3a..a1753ede258dc749be9ce9d48c73fe6d0bfd1703 100644 (file)
@@ -8,8 +8,6 @@ use Friendica\Network\Probe;
 use Friendica\Util\Strings;
 use RuntimeException;
 
-require_once 'include/text.php';
-
 /**
  * @brief tool to silence accounts on the global community page
  *
index c8214b16140b967b62279062552fc907f74681af..0cb0da9c60e01596a4f457e72d443d599746d08e 100644 (file)
@@ -4,9 +4,6 @@ namespace Friendica\Core\Console;
 
 use Friendica\Core;
 
-require_once 'boot.php';
-require_once 'include/dba.php';
-
 /**
  * @brief Sets maintenance mode for this node
  *
index 4c30c94b04ec274d1780abdbe6395804e8723f9a..15bcb76f4921f1e10103176d9f4c0721b521598c 100644 (file)
@@ -585,7 +585,6 @@ class Installer
         */
        public function checkDB($dbhost, $dbuser, $dbpass, $dbdata)
        {
-               require_once 'include/dba.php';
                if (!DBA::connect($dbhost, $dbuser, $dbpass, $dbdata)) {
                        $this->addCheck(L10n::t('Could not connect to database.'), false, true, '');
 
index 1283f872841ba41b945344de5c0a1144d72b1632..aa36c2e4f9865768eacc571be7640be1b560e780 100644 (file)
@@ -10,9 +10,6 @@ use Friendica\Core\Addon;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
 
-require_once 'boot.php';
-require_once 'include/dba.php';
-
 /**
  * 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").
index d11fea03a1b017533474c9287a8a3fe3b56005ba..5a2efe297be17b44b29cb4696f74cb8822b9ec2c 100644 (file)
@@ -19,8 +19,6 @@ use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Temporal;
 use Friendica\Util\XML;
 
-require_once 'include/dba.php';
-
 /**
  * @brief Methods for read and write notifications from/to database
  *  or for formatting notifications
index 2080f716ceb5cfac2b329108cd004535210ecfa3..752d919199cdc88a2cb7ea86d9f08bbd878da586 100644 (file)
@@ -11,8 +11,6 @@ namespace Friendica\Core;
 use Friendica\App;
 use Friendica\BaseObject;
 
-require_once 'include/dba.php';
-
 /**
  * @brief Management of user configuration storage
  * Note:
index 1baf111e93ef60bcd0b04d7846ebf82b69932808..08490818cec448fc2ec9092928a04c9d1028e7fe 100644 (file)
@@ -8,9 +8,6 @@ use Friendica\Core\Logger;
 use Friendica\Core\Session;
 use SessionHandlerInterface;
 
-require_once 'boot.php';
-require_once 'include/text.php';
-
 /**
  * SessionHandler using Friendica Cache
  *
index c4f23b1bfc6424dc3beba1947b0133768b9ea3f2..1c3da6eb3a6f56186919d668f26dbe29f1111b0b 100644 (file)
@@ -8,10 +8,6 @@ use Friendica\Core\Session;
 use Friendica\Database\DBA;
 use SessionHandlerInterface;
 
-require_once 'boot.php';
-require_once 'include/dba.php';
-require_once 'include/text.php';
-
 /**
  * SessionHandler using database
  *
index e5026904b8cef7936d4c2af75fe0ce600d8445c2..1524c29bacfe2a8cd878f51ad01e2944d88839d5 100644 (file)
@@ -9,8 +9,6 @@ namespace Friendica\Core;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
 
-require_once 'boot.php';
-
 /**
  * Some functions to handle themes
  */
index 70d93b0cc0900fbc67272a934bccbe48f6a636e0..59ab7af4aa832cdc7249c5c0bdccd4382b8d847e 100644 (file)
@@ -13,8 +13,6 @@ use Friendica\Model\Photo;
 use Friendica\Object\Image;
 use Friendica\Util\Strings;
 
-require_once "include/dba.php";
-
 /**
  * @brief UserImport class
  */
index f3736d2573f7e10fbe4f934b42d434577380e7e3..2c811e3bdab75ac961fb8c58be9bd00e3f0ef1c1 100644 (file)
@@ -11,8 +11,6 @@ use Friendica\Model\Process;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 
-require_once 'include/dba.php';
-
 /**
  * @file src/Core/Worker.php
  *
index af0c25d0dd749c34e0e48142148e390f7357a69c..f1c0ead6afb186e4dc7dd8a532d7cc08809a8e17 100644 (file)
@@ -16,8 +16,6 @@ use PDO;
 use PDOException;
 use PDOStatement;
 
-require_once 'include/dba.php';
-
 /**
  * @class MySQL database class
  *
index 92666edb89b78c42cfa3bb80bf48e701cb99ef91..3043ae132235b76de62239ffbc9a1fdb442fe959 100644 (file)
@@ -2,6 +2,7 @@
 /**
  * @file src/Database/DBStructure.php
  */
+
 namespace Friendica\Database;
 
 use Exception;
@@ -11,11 +12,6 @@ use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Util\DateTimeFormat;
 
-require_once 'boot.php';
-require_once 'include/dba.php';
-require_once 'include/enotify.php';
-require_once 'include/text.php';
-
 /**
  * @brief This class contain functions for the database management
  *
@@ -27,6 +23,9 @@ class DBStructure
        const UPDATE_SUCCESSFUL  = 1; // Database check was successful
        const UPDATE_FAILED      = 2; // Database check failed
 
+       const RENAME_COLUMN      = 0;
+       const RENAME_PRIMARY_KEY = 1;
+
        /**
         * Database structure definition loaded from config/dbstructure.config.php
         *
@@ -37,18 +36,19 @@ class DBStructure
        /*
         * Converts all tables from MyISAM to InnoDB
         */
-       public static function convertToInnoDB() {
+       public static function convertToInnoDB()
+       {
                $r = q("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `engine` = 'MyISAM' AND `table_schema` = '%s'",
                        DBA::escape(DBA::databaseName()));
 
                if (!DBA::isResult($r)) {
-                       echo L10n::t('There are no tables on MyISAM.')."\n";
+                       echo L10n::t('There are no tables on MyISAM.') . "\n";
                        return;
                }
 
                foreach ($r AS $table) {
                        $sql = sprintf("ALTER TABLE `%s` engine=InnoDB;", DBA::escape($table['TABLE_NAME']));
-                       echo $sql."\n";
+                       echo $sql . "\n";
 
                        $result = DBA::e($sql);
                        if (!DBA::isResult($result)) {
@@ -57,103 +57,189 @@ class DBStructure
                }
        }
 
-       private static function tableStructure($table) {
-               $structures = q("DESCRIBE `%s`", $table);
+       /**
+        * @brief Print out database error messages
+        *
+        * @param string $message Message to be added to the error message
+        *
+        * @return string Error message
+        */
+       private static function printUpdateError($message)
+       {
+               echo L10n::t("\nError %d occurred during database update:\n%s\n",
+                       DBA::errorNo(), DBA::errorMessage());
 
-               $full_columns = q("SHOW FULL COLUMNS FROM `%s`", $table);
+               return L10n::t('Errors encountered performing database changes: ') . $message . EOL;
+       }
 
-               $indexes = q("SHOW INDEX FROM `%s`", $table);
+       public static function printStructure()
+       {
+               $database = self::definition(false);
 
-               $table_status = q("SHOW TABLE STATUS WHERE `name` = '%s'", $table);
+               echo "-- ------------------------------------------\n";
+               echo "-- " . FRIENDICA_PLATFORM . " " . FRIENDICA_VERSION . " (" . FRIENDICA_CODENAME, ")\n";
+               echo "-- DB_UPDATE_VERSION " . DB_UPDATE_VERSION . "\n";
+               echo "-- ------------------------------------------\n\n\n";
+               foreach ($database AS $name => $structure) {
+                       echo "--\n";
+                       echo "-- TABLE $name\n";
+                       echo "--\n";
+                       self::createTable($name, $structure, true, false);
 
-               if (DBA::isResult($table_status)) {
-                       $table_status = $table_status[0];
-               } else {
-                       $table_status = [];
+                       echo "\n";
                }
+       }
 
-               $fielddata = [];
-               $indexdata = [];
+       /**
+        * Loads the database structure definition from the config/dbstructure.config.php file.
+        * On first pass, defines DB_UPDATE_VERSION constant.
+        *
+        * @see config/dbstructure.config.php
+        * @param boolean $with_addons_structure Whether to tack on addons additional tables
+        * @return array
+        * @throws Exception
+        */
+       public static function definition($with_addons_structure = true)
+       {
+               if (!self::$definition) {
+                       $a = \Friendica\BaseObject::getApp();
 
-               if (DBA::isResult($indexes)) {
-                       foreach ($indexes AS $index) {
-                               if ($index['Key_name'] != 'PRIMARY' && $index['Non_unique'] == '0' && !isset($indexdata[$index["Key_name"]])) {
-                                       $indexdata[$index["Key_name"]] = ['UNIQUE'];
-                               }
+                       $filename = $a->getBasePath() . '/config/dbstructure.config.php';
 
-                               $column = $index["Column_name"];
+                       if (!is_readable($filename)) {
+                               throw new Exception('Missing database structure config file config/dbstructure.config.php');
+                       }
 
-                               if ($index["Sub_part"] != "") {
-                                       $column .= "(".$index["Sub_part"].")";
-                               }
+                       $definition = require $filename;
 
-                               $indexdata[$index["Key_name"]][] = $column;
+                       if (!$definition) {
+                               throw new Exception('Corrupted database structure config file config/dbstructure.config.php');
                        }
+
+                       self::$definition = $definition;
+               } else {
+                       $definition = self::$definition;
                }
-               if (DBA::isResult($structures)) {
-                       foreach ($structures AS $field) {
-                               // Replace the default size values so that we don't have to define them
-                               $search = ['tinyint(1)', 'tinyint(3) unsigned', 'tinyint(4)', 'smallint(5) unsigned', 'smallint(6)', 'mediumint(8) unsigned', 'mediumint(9)', 'bigint(20)', 'int(10) unsigned', 'int(11)'];
-                               $replace = ['boolean', 'tinyint unsigned', 'tinyint', 'smallint unsigned', 'smallint', 'mediumint unsigned', 'mediumint', 'bigint', 'int unsigned', 'int'];
-                               $field["Type"] = str_replace($search, $replace, $field["Type"]);
 
-                               $fielddata[$field["Field"]]["type"] = $field["Type"];
-                               if ($field["Null"] == "NO") {
-                                       $fielddata[$field["Field"]]["not null"] = true;
-                               }
+               if ($with_addons_structure) {
+                       Hook::callAll('dbstructure_definition', $definition);
+               }
 
-                               if (isset($field["Default"])) {
-                                       $fielddata[$field["Field"]]["default"] = $field["Default"];
-                               }
+               return $definition;
+       }
 
-                               if ($field["Extra"] != "") {
-                                       $fielddata[$field["Field"]]["extra"] = $field["Extra"];
-                               }
+       private static function createTable($name, $structure, $verbose, $action)
+       {
+               $r = true;
 
-                               if ($field["Key"] == "PRI") {
-                                       $fielddata[$field["Field"]]["primary"] = true;
-                               }
+               $engine = "";
+               $comment = "";
+               $sql_rows = [];
+               $primary_keys = [];
+               foreach ($structure["fields"] AS $fieldname => $field) {
+                       $sql_rows[] = "`" . DBA::escape($fieldname) . "` " . self::FieldCommand($field);
+                       if (!empty($field['primary'])) {
+                               $primary_keys[] = $fieldname;
                        }
                }
-               if (DBA::isResult($full_columns)) {
-                       foreach ($full_columns AS $column) {
-                               $fielddata[$column["Field"]]["Collation"] = $column["Collation"];
-                               $fielddata[$column["Field"]]["comment"] = $column["Comment"];
+
+               if (!empty($structure["indexes"])) {
+                       foreach ($structure["indexes"] AS $indexname => $fieldnames) {
+                               $sql_index = self::createIndex($indexname, $fieldnames, "");
+                               if (!is_null($sql_index)) {
+                                       $sql_rows[] = $sql_index;
+                               }
                        }
                }
 
-               return ["fields" => $fielddata, "indexes" => $indexdata, "table_status" => $table_status];
+               if (isset($structure["engine"])) {
+                       $engine = " ENGINE=" . $structure["engine"];
+               }
+
+               if (isset($structure["comment"])) {
+                       $comment = " COMMENT='" . DBA::escape($structure["comment"]) . "'";
+               }
+
+               $sql = implode(",\n\t", $sql_rows);
+
+               $sql = sprintf("CREATE TABLE IF NOT EXISTS `%s` (\n\t", DBA::escape($name)) . $sql .
+                       "\n)" . $engine . " DEFAULT COLLATE utf8mb4_general_ci" . $comment;
+               if ($verbose) {
+                       echo $sql . ";\n";
+               }
+
+               if ($action) {
+                       $r = DBA::e($sql);
+               }
+
+               return $r;
        }
 
-       public static function printStructure() {
-               $database = self::definition(false);
+       private static function FieldCommand($parameters, $create = true)
+       {
+               $fieldstruct = $parameters["type"];
 
-               echo "-- ------------------------------------------\n";
-               echo "-- ".FRIENDICA_PLATFORM." ".FRIENDICA_VERSION." (".FRIENDICA_CODENAME,")\n";
-               echo "-- DB_UPDATE_VERSION ".DB_UPDATE_VERSION."\n";
-               echo "-- ------------------------------------------\n\n\n";
-               foreach ($database AS $name => $structure) {
-                       echo "--\n";
-                       echo "-- TABLE $name\n";
-                       echo "--\n";
-                       self::createTable($name, $structure, true, false);
+               if (isset($parameters["Collation"])) {
+                       $fieldstruct .= " COLLATE " . $parameters["Collation"];
+               }
 
-                       echo "\n";
+               if (isset($parameters["not null"])) {
+                       $fieldstruct .= " NOT NULL";
+               }
+
+               if (isset($parameters["default"])) {
+                       if (strpos(strtolower($parameters["type"]), "int") !== false) {
+                               $fieldstruct .= " DEFAULT " . $parameters["default"];
+                       } else {
+                               $fieldstruct .= " DEFAULT '" . $parameters["default"] . "'";
+                       }
+               }
+               if (isset($parameters["extra"])) {
+                       $fieldstruct .= " " . $parameters["extra"];
+               }
+
+               if (isset($parameters["comment"])) {
+                       $fieldstruct .= " COMMENT '" . DBA::escape($parameters["comment"]) . "'";
                }
+
+               /*if (($parameters["primary"] != "") && $create)
+                       $fieldstruct .= " PRIMARY KEY";*/
+
+               return ($fieldstruct);
        }
 
-       /**
-        * @brief Print out database error messages
-        *
-        * @param string $message Message to be added to the error message
-        *
-        * @return string Error message
-        */
-       private static function printUpdateError($message) {
-               echo L10n::t("\nError %d occurred during database update:\n%s\n",
-                       DBA::errorNo(), DBA::errorMessage());
+       private static function createIndex($indexname, $fieldnames, $method = "ADD")
+       {
+               $method = strtoupper(trim($method));
+               if ($method != "" && $method != "ADD") {
+                       throw new Exception("Invalid parameter 'method' in self::createIndex(): '$method'");
+               }
+
+               if (in_array($fieldnames[0], ["UNIQUE", "FULLTEXT"])) {
+                       $index_type = array_shift($fieldnames);
+                       $method .= " " . $index_type;
+               }
+
+               $names = "";
+               foreach ($fieldnames AS $fieldname) {
+                       if ($names != "") {
+                               $names .= ",";
+                       }
+
+                       if (preg_match('|(.+)\((\d+)\)|', $fieldname, $matches)) {
+                               $names .= "`" . DBA::escape($matches[1]) . "`(" . intval($matches[2]) . ")";
+                       } else {
+                               $names .= "`" . DBA::escape($fieldname) . "`";
+                       }
+               }
+
+               if ($indexname == "PRIMARY") {
+                       return sprintf("%s PRIMARY KEY(%s)", $method, $names);
+               }
+
 
-               return L10n::t('Errors encountered performing database changes: ').$message.EOL;
+               $sql = sprintf("%s INDEX `%s` (%s)", $method, DBA::escape($indexname), $names);
+               return ($sql);
        }
 
        /**
@@ -166,10 +252,11 @@ class DBStructure
         * @param array $definition An array of the definition tables
         * @return string Empty string if the update is successful, error messages otherwise
         */
-       public static function update($verbose, $action, $install = false, array $tables = null, array $definition = null) {
+       public static function update($verbose, $action, $install = false, array $tables = null, array $definition = null)
+       {
                if ($action && !$install) {
                        Config::set('system', 'maintenance', 1);
-                       Config::set('system', 'maintenance_reason', L10n::t('%s: Database update', DateTimeFormat::utcNow().' '.date('e')));
+                       Config::set('system', 'maintenance_reason', L10n::t('%s: Database update', DateTimeFormat::utcNow() . ' ' . date('e')));
                }
 
                $errors = '';
@@ -221,16 +308,16 @@ class DBStructure
                        } else {
                                foreach ($structure["indexes"] AS $indexname => $fieldnames) {
                                        if (isset($database[$name]["indexes"][$indexname])) {
-                                               $current_index_definition = implode(",",$database[$name]["indexes"][$indexname]);
+                                               $current_index_definition = implode(",", $database[$name]["indexes"][$indexname]);
                                        } else {
                                                $current_index_definition = "__NOT_SET__";
                                        }
-                                       $new_index_definition = implode(",",$fieldnames);
+                                       $new_index_definition = implode(",", $fieldnames);
                                        if ($current_index_definition != $new_index_definition) {
                                                if ($fieldnames[0] == "UNIQUE") {
                                                        $is_unique = true;
                                                        if ($ignore == "") {
-                                                               $temp_name = "temp-".$name;
+                                                               $temp_name = "temp-" . $name;
                                                        }
                                                }
                                        }
@@ -242,29 +329,29 @@ class DBStructure
                                 * and index name doesn't start with "local_"
                                 */
                                foreach ($database[$name]["indexes"] as $indexname => $fieldnames) {
-                                       $current_index_definition = implode(",",$fieldnames);
+                                       $current_index_definition = implode(",", $fieldnames);
                                        if (isset($structure["indexes"][$indexname])) {
-                                               $new_index_definition = implode(",",$structure["indexes"][$indexname]);
+                                               $new_index_definition = implode(",", $structure["indexes"][$indexname]);
                                        } else {
                                                $new_index_definition = "__NOT_SET__";
                                        }
                                        if ($current_index_definition != $new_index_definition && substr($indexname, 0, 6) != 'local_') {
-                                               $sql2=self::dropIndex($indexname);
+                                               $sql2 = self::dropIndex($indexname);
                                                if ($sql3 == "") {
-                                                       $sql3 = "ALTER".$ignore." TABLE `".$temp_name."` ".$sql2;
+                                                       $sql3 = "ALTER" . $ignore . " TABLE `" . $temp_name . "` " . $sql2;
                                                } else {
-                                                       $sql3 .= ", ".$sql2;
+                                                       $sql3 .= ", " . $sql2;
                                                }
                                        }
                                }
                                // Compare the field structure field by field
                                foreach ($structure["fields"] AS $fieldname => $parameters) {
                                        if (!isset($database[$name]["fields"][$fieldname])) {
-                                               $sql2=self::addTableField($fieldname, $parameters);
+                                               $sql2 = self::addTableField($fieldname, $parameters);
                                                if ($sql3 == "") {
-                                                       $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
+                                                       $sql3 = "ALTER" . $ignore . " TABLE `" . $temp_name . "` " . $sql2;
                                                } else {
-                                                       $sql3 .= ", ".$sql2;
+                                                       $sql3 .= ", " . $sql2;
                                                }
                                        } else {
                                                // Compare the field definition
@@ -289,9 +376,9 @@ class DBStructure
                                                if ($current_field_definition != $new_field_definition) {
                                                        $sql2 = self::modifyTableField($fieldname, $parameters);
                                                        if ($sql3 == "") {
-                                                               $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
+                                                               $sql3 = "ALTER" . $ignore . " TABLE `" . $temp_name . "` " . $sql2;
                                                        } else {
-                                                               $sql3 .= ", ".$sql2;
+                                                               $sql3 .= ", " . $sql2;
                                                        }
                                                }
                                        }
@@ -306,23 +393,21 @@ class DBStructure
                        if (!$is_new_table) {
                                foreach ($structure["indexes"] AS $indexname => $fieldnames) {
                                        if (isset($database[$name]["indexes"][$indexname])) {
-                                               $current_index_definition = implode(",",$database[$name]["indexes"][$indexname]);
+                                               $current_index_definition = implode(",", $database[$name]["indexes"][$indexname]);
                                        } else {
                                                $current_index_definition = "__NOT_SET__";
                                        }
-                                       $new_index_definition = implode(",",$fieldnames);
+                                       $new_index_definition = implode(",", $fieldnames);
                                        if ($current_index_definition != $new_index_definition) {
                                                $sql2 = self::createIndex($indexname, $fieldnames);
 
                                                // Fetch the "group by" fields for unique indexes
-                                               if ($fieldnames[0] == "UNIQUE") {
-                                                       $group_by = self::groupBy($indexname, $fieldnames);
-                                               }
+                                               $group_by = self::groupBy($fieldnames);
                                                if ($sql2 != "") {
                                                        if ($sql3 == "") {
-                                                               $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
+                                                               $sql3 = "ALTER" . $ignore . " TABLE `" . $temp_name . "` " . $sql2;
                                                        } else {
-                                                               $sql3 .= ", ".$sql2;
+                                                               $sql3 .= ", " . $sql2;
                                                        }
                                                }
                                        }
@@ -331,24 +416,24 @@ class DBStructure
                                if (isset($database[$name]["table_status"]["Comment"])) {
                                        $structurecomment = defaults($structure, "comment", "");
                                        if ($database[$name]["table_status"]["Comment"] != $structurecomment) {
-                                               $sql2 = "COMMENT = '".DBA::escape($structurecomment)."'";
+                                               $sql2 = "COMMENT = '" . DBA::escape($structurecomment) . "'";
 
                                                if ($sql3 == "") {
-                                                       $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
+                                                       $sql3 = "ALTER" . $ignore . " TABLE `" . $temp_name . "` " . $sql2;
                                                } else {
-                                                       $sql3 .= ", ".$sql2;
+                                                       $sql3 .= ", " . $sql2;
                                                }
                                        }
                                }
 
                                if (isset($database[$name]["table_status"]["Engine"]) && isset($structure['engine'])) {
                                        if ($database[$name]["table_status"]["Engine"] != $structure['engine']) {
-                                               $sql2 = "ENGINE = '".DBA::escape($structure['engine'])."'";
+                                               $sql2 = "ENGINE = '" . DBA::escape($structure['engine']) . "'";
 
                                                if ($sql3 == "") {
-                                                       $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
+                                                       $sql3 = "ALTER" . $ignore . " TABLE `" . $temp_name . "` " . $sql2;
                                                } else {
-                                                       $sql3 .= ", ".$sql2;
+                                                       $sql3 .= ", " . $sql2;
                                                }
                                        }
                                }
@@ -358,9 +443,9 @@ class DBStructure
                                                $sql2 = "DEFAULT COLLATE utf8mb4_general_ci";
 
                                                if ($sql3 == "") {
-                                                       $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
+                                                       $sql3 = "ALTER" . $ignore . " TABLE `" . $temp_name . "` " . $sql2;
                                                } else {
-                                                       $sql3 .= ", ".$sql2;
+                                                       $sql3 .= ", " . $sql2;
                                                }
                                        }
                                }
@@ -385,9 +470,9 @@ class DBStructure
                                        if ($field_definition['Collation'] != $parameters['Collation']) {
                                                $sql2 = self::modifyTableField($fieldname, $parameters);
                                                if (($sql3 == "") || (substr($sql3, -2, 2) == "; ")) {
-                                                       $sql3 .= "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
+                                                       $sql3 .= "ALTER" . $ignore . " TABLE `" . $temp_name . "` " . $sql2;
                                                } else {
-                                                       $sql3 .= ", ".$sql2;
+                                                       $sql3 .= ", " . $sql2;
                                                }
                                        }
                                }
@@ -412,27 +497,27 @@ class DBStructure
                                                if ($ignore != "") {
                                                        echo "SET session old_alter_table=1;\n";
                                                } else {
-                                                       echo "DROP TABLE IF EXISTS `".$temp_name."`;\n";
-                                                       echo "CREATE TABLE `".$temp_name."` LIKE `".$name."`;\n";
+                                                       echo "DROP TABLE IF EXISTS `" . $temp_name . "`;\n";
+                                                       echo "CREATE TABLE `" . $temp_name . "` LIKE `" . $name . "`;\n";
                                                }
                                        }
 
-                                       echo $sql3."\n";
+                                       echo $sql3 . "\n";
 
                                        if ($is_unique && ($temp_name != $name)) {
                                                if ($ignore != "") {
                                                        echo "SET session old_alter_table=0;\n";
                                                } else {
-                                                       echo "INSERT INTO `".$temp_name."` SELECT ".DBA::anyValueFallback($field_list)." FROM `".$name."`".$group_by.";\n";
-                                                       echo "DROP TABLE `".$name."`;\n";
-                                                       echo "RENAME TABLE `".$temp_name."` TO `".$name."`;\n";
+                                                       echo "INSERT INTO `" . $temp_name . "` SELECT " . DBA::anyValueFallback($field_list) . " FROM `" . $name . "`" . $group_by . ";\n";
+                                                       echo "DROP TABLE `" . $name . "`;\n";
+                                                       echo "RENAME TABLE `" . $temp_name . "` TO `" . $name . "`;\n";
                                                }
                                        }
                                }
 
                                if ($action) {
                                        if (!$install) {
-                                               Config::set('system', 'maintenance_reason', L10n::t('%s: updating %s table.', DateTimeFormat::utcNow().' '.date('e'), $name));
+                                               Config::set('system', 'maintenance_reason', L10n::t('%s: updating %s table.', DateTimeFormat::utcNow() . ' ' . date('e'), $name));
                                        }
 
                                        // Ensure index conversion to unique removes duplicates
@@ -440,13 +525,13 @@ class DBStructure
                                                if ($ignore != "") {
                                                        DBA::e("SET session old_alter_table=1;");
                                                } else {
-                                                       $r = DBA::e("DROP TABLE IF EXISTS `".$temp_name."`;");
+                                                       $r = DBA::e("DROP TABLE IF EXISTS `" . $temp_name . "`;");
                                                        if (!DBA::isResult($r)) {
                                                                $errors .= self::printUpdateError($sql3);
                                                                return $errors;
                                                        }
 
-                                                       $r = DBA::e("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
+                                                       $r = DBA::e("CREATE TABLE `" . $temp_name . "` LIKE `" . $name . "`;");
                                                        if (!DBA::isResult($r)) {
                                                                $errors .= self::printUpdateError($sql3);
                                                                return $errors;
@@ -462,17 +547,17 @@ class DBStructure
                                                if ($ignore != "") {
                                                        DBA::e("SET session old_alter_table=0;");
                                                } else {
-                                                       $r = DBA::e("INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";");
+                                                       $r = DBA::e("INSERT INTO `" . $temp_name . "` SELECT " . $field_list . " FROM `" . $name . "`" . $group_by . ";");
                                                        if (!DBA::isResult($r)) {
                                                                $errors .= self::printUpdateError($sql3);
                                                                return $errors;
                                                        }
-                                                       $r = DBA::e("DROP TABLE `".$name."`;");
+                                                       $r = DBA::e("DROP TABLE `" . $name . "`;");
                                                        if (!DBA::isResult($r)) {
                                                                $errors .= self::printUpdateError($sql3);
                                                                return $errors;
                                                        }
-                                                       $r = DBA::e("RENAME TABLE `".$temp_name."` TO `".$name."`;");
+                                                       $r = DBA::e("RENAME TABLE `" . $temp_name . "` TO `" . $name . "`;");
                                                        if (!DBA::isResult($r)) {
                                                                $errors .= self::printUpdateError($sql3);
                                                                return $errors;
@@ -497,133 +582,105 @@ class DBStructure
                return $errors;
        }
 
-       private static function FieldCommand($parameters, $create = true) {
-               $fieldstruct = $parameters["type"];
+       private static function tableStructure($table)
+       {
+               $structures = q("DESCRIBE `%s`", $table);
 
-               if (isset($parameters["Collation"])) {
-                       $fieldstruct .= " COLLATE ".$parameters["Collation"];
-               }
+               $full_columns = q("SHOW FULL COLUMNS FROM `%s`", $table);
 
-               if (isset($parameters["not null"])) {
-                       $fieldstruct .= " NOT NULL";
-               }
+               $indexes = q("SHOW INDEX FROM `%s`", $table);
 
-               if (isset($parameters["default"])) {
-                       if (strpos(strtolower($parameters["type"]),"int")!==false) {
-                               $fieldstruct .= " DEFAULT ".$parameters["default"];
-                       } else {
-                               $fieldstruct .= " DEFAULT '".$parameters["default"]."'";
-                       }
-               }
-               if (isset($parameters["extra"])) {
-                       $fieldstruct .= " ".$parameters["extra"];
-               }
+               $table_status = q("SHOW TABLE STATUS WHERE `name` = '%s'", $table);
 
-               if (isset($parameters["comment"])) {
-                       $fieldstruct .= " COMMENT '".DBA::escape($parameters["comment"])."'";
+               if (DBA::isResult($table_status)) {
+                       $table_status = $table_status[0];
+               } else {
+                       $table_status = [];
                }
 
-               /*if (($parameters["primary"] != "") && $create)
-                       $fieldstruct .= " PRIMARY KEY";*/
+               $fielddata = [];
+               $indexdata = [];
 
-               return($fieldstruct);
-       }
+               if (DBA::isResult($indexes)) {
+                       foreach ($indexes AS $index) {
+                               if ($index["Key_name"] != "PRIMARY" && $index["Non_unique"] == "0" && !isset($indexdata[$index["Key_name"]])) {
+                                       $indexdata[$index["Key_name"]] = ["UNIQUE"];
+                               }
 
-       private static function createTable($name, $structure, $verbose, $action) {
-               $r = true;
+                               if ($index["Index_type"] == "FULLTEXT" && !isset($indexdata[$index["Key_name"]])) {
+                                       $indexdata[$index["Key_name"]] = ["FULLTEXT"];
+                               }
 
-               $engine = "";
-               $comment = "";
-               $sql_rows = [];
-               $primary_keys = [];
-               foreach ($structure["fields"] AS $fieldname => $field) {
-                       $sql_rows[] = "`".DBA::escape($fieldname)."` ".self::FieldCommand($field);
-                       if (!empty($field['primary'])) {
-                               $primary_keys[] = $fieldname;
-                       }
-               }
+                               $column = $index["Column_name"];
 
-               if (!empty($structure["indexes"])) {
-                       foreach ($structure["indexes"] AS $indexname => $fieldnames) {
-                               $sql_index = self::createIndex($indexname, $fieldnames, "");
-                               if (!is_null($sql_index)) {
-                                       $sql_rows[] = $sql_index;
+                               if ($index["Sub_part"] != "") {
+                                       $column .= "(" . $index["Sub_part"] . ")";
                                }
+
+                               $indexdata[$index["Key_name"]][] = $column;
                        }
                }
+               if (DBA::isResult($structures)) {
+                       foreach ($structures AS $field) {
+                               // Replace the default size values so that we don't have to define them
+                               $search = ['tinyint(1)', 'tinyint(3) unsigned', 'tinyint(4)', 'smallint(5) unsigned', 'smallint(6)', 'mediumint(8) unsigned', 'mediumint(9)', 'bigint(20)', 'int(10) unsigned', 'int(11)'];
+                               $replace = ['boolean', 'tinyint unsigned', 'tinyint', 'smallint unsigned', 'smallint', 'mediumint unsigned', 'mediumint', 'bigint', 'int unsigned', 'int'];
+                               $field["Type"] = str_replace($search, $replace, $field["Type"]);
 
-               if (isset($structure["engine"])) {
-                       $engine = " ENGINE=" . $structure["engine"];
-               }
+                               $fielddata[$field["Field"]]["type"] = $field["Type"];
+                               if ($field["Null"] == "NO") {
+                                       $fielddata[$field["Field"]]["not null"] = true;
+                               }
 
-               if (isset($structure["comment"])) {
-                       $comment = " COMMENT='" . DBA::escape($structure["comment"]) . "'";
-               }
+                               if (isset($field["Default"])) {
+                                       $fielddata[$field["Field"]]["default"] = $field["Default"];
+                               }
 
-               $sql = implode(",\n\t", $sql_rows);
+                               if ($field["Extra"] != "") {
+                                       $fielddata[$field["Field"]]["extra"] = $field["Extra"];
+                               }
 
-               $sql = sprintf("CREATE TABLE IF NOT EXISTS `%s` (\n\t", DBA::escape($name)).$sql.
-                               "\n)" . $engine . " DEFAULT COLLATE utf8mb4_general_ci" . $comment;
-               if ($verbose) {
-                       echo $sql.";\n";
+                               if ($field["Key"] == "PRI") {
+                                       $fielddata[$field["Field"]]["primary"] = true;
+                               }
+                       }
                }
-
-               if ($action) {
-                       $r = DBA::e($sql);
+               if (DBA::isResult($full_columns)) {
+                       foreach ($full_columns AS $column) {
+                               $fielddata[$column["Field"]]["Collation"] = $column["Collation"];
+                               $fielddata[$column["Field"]]["comment"] = $column["Comment"];
+                       }
                }
 
-               return $r;
-       }
-
-       private static function addTableField($fieldname, $parameters) {
-               $sql = sprintf("ADD `%s` %s", DBA::escape($fieldname), self::FieldCommand($parameters));
-               return($sql);
-       }
-
-       private static function modifyTableField($fieldname, $parameters) {
-               $sql = sprintf("MODIFY `%s` %s", DBA::escape($fieldname), self::FieldCommand($parameters, false));
-               return($sql);
+               return ["fields" => $fielddata, "indexes" => $indexdata, "table_status" => $table_status];
        }
 
-       private static function dropIndex($indexname) {
+       private static function dropIndex($indexname)
+       {
                $sql = sprintf("DROP INDEX `%s`", DBA::escape($indexname));
-               return($sql);
+               return ($sql);
        }
 
-       private static function createIndex($indexname, $fieldnames, $method = "ADD") {
-               $method = strtoupper(trim($method));
-               if ($method!="" && $method!="ADD") {
-                       throw new Exception("Invalid parameter 'method' in self::createIndex(): '$method'");
-               }
-
-               if ($fieldnames[0] == "UNIQUE") {
-                       array_shift($fieldnames);
-                       $method .= ' UNIQUE';
-               }
-
-               $names = "";
-               foreach ($fieldnames AS $fieldname) {
-                       if ($names != "") {
-                               $names .= ",";
-                       }
-
-                       if (preg_match('|(.+)\((\d+)\)|', $fieldname, $matches)) {
-                               $names .= "`".DBA::escape($matches[1])."`(".intval($matches[2]).")";
-                       } else {
-                               $names .= "`".DBA::escape($fieldname)."`";
-                       }
-               }
-
-               if ($indexname == "PRIMARY") {
-                       return sprintf("%s PRIMARY KEY(%s)", $method, $names);
-               }
-
+       private static function addTableField($fieldname, $parameters)
+       {
+               $sql = sprintf("ADD `%s` %s", DBA::escape($fieldname), self::FieldCommand($parameters));
+               return ($sql);
+       }
 
-               $sql = sprintf("%s INDEX `%s` (%s)", $method, DBA::escape($indexname), $names);
-               return($sql);
+       private static function modifyTableField($fieldname, $parameters)
+       {
+               $sql = sprintf("MODIFY `%s` %s", DBA::escape($fieldname), self::FieldCommand($parameters, false));
+               return ($sql);
        }
 
-       private static function groupBy($indexname, $fieldnames) {
+       /**
+        * Constructs a GROUP BY clause from a UNIQUE index definition.
+        *
+        * @param array $fieldnames
+        * @return string
+        */
+       private static function groupBy(array $fieldnames)
+       {
                if ($fieldnames[0] != "UNIQUE") {
                        return "";
                }
@@ -637,9 +694,9 @@ class DBStructure
                        }
 
                        if (preg_match('|(.+)\((\d+)\)|', $fieldname, $matches)) {
-                               $names .= "`".DBA::escape($matches[1])."`";
+                               $names .= "`" . DBA::escape($matches[1]) . "`";
                        } else {
-                               $names .= "`".DBA::escape($fieldname)."`";
+                               $names .= "`" . DBA::escape($fieldname) . "`";
                        }
                }
 
@@ -648,28 +705,62 @@ class DBStructure
        }
 
        /**
-        *      Check if a table exists
+        * Renames columns or the primary key of a table
         *
-        * @param string $table Table name
+        * @todo You cannot rename a primary key if "auto increment" is set
+        *
+        * @param string $table            Table name
+        * @param array  $columns          Columns Syntax for Rename: [ $old1 => [ $new1, $type1 ], $old2 => [ $new2, $type2 ], ... ] )
+        *                                 Syntax for Primary Key: [ $col1, $col2, ...] )
+        * @param int    $type             The type of renaming (Default is Column)
+        *
+        * @return boolean Was the renaming successful?
         *
-        * @return boolean Does the table exist?
         */
-       public static function existsTable($table)
+       public static function rename($table, $columns, $type = self::RENAME_COLUMN)
        {
-               if (empty($table)) {
+               if (empty($table) || empty($columns)) {
+                       return false;
+               }
+
+               if (!is_array($columns)) {
                        return false;
                }
 
                $table = DBA::escape($table);
 
-               $sql = "SHOW TABLES LIKE '" . $table . "';";
+               $sql = "ALTER TABLE `" . $table . "`";
+               switch ($type) {
+                       case self::RENAME_COLUMN:
+                               if (!self::existsColumn($table, array_keys($columns))) {
+                                       return false;
+                               }
+                               $sql .= implode(',', array_map(
+                                       function ($to, $from) {
+                                               return " CHANGE `" . $from . "` `" . $to[0] . "` " . $to[1];
+                                       },
+                                       $columns,
+                                       array_keys($columns)
+                               ));
+                               break;
+                       case self::RENAME_PRIMARY_KEY:
+                               if (!self::existsColumn($table, $columns)) {
+                                       return false;
+                               }
+                               $sql .= " DROP PRIMARY KEY, ADD PRIMARY KEY(`" . implode('`, `', $columns) . "`)";
+                               break;
+                       default:
+                               return false;
+               }
+
+               $sql .= ";";
 
                $stmt = DBA::p($sql);
 
                if (is_bool($stmt)) {
                        $retval = $stmt;
                } else {
-                       $retval = (DBA::numRows($stmt) > 0);
+                       $retval = true;
                }
 
                DBA::close($stmt);
@@ -678,14 +769,15 @@ class DBStructure
        }
 
        /**
-        *      Check if the columns of the table exists
+        *    Check if the columns of the table exists
         *
         * @param string $table   Table name
         * @param array  $columns Columns to check ( Syntax: [ $col1, $col2, .. ] )
         *
         * @return boolean Does the table exist?
         */
-       public static function existsColumn($table, $columns = []) {
+       public static function existsColumn($table, $columns = [])
+       {
                if (empty($table)) {
                        return false;
                }
@@ -717,106 +809,33 @@ class DBStructure
                return true;
        }
 
-       const RENAME_COLUMN = 0;
-       const RENAME_PRIMARY_KEY = 1;
-
        /**
-        * Renames columns or the primary key of a table
-        * @todo You cannot rename a primary key if "auto increment" is set
-        *
-        * @param string $table    Table name
-        * @param array  $columns  Columns Syntax for Rename: [ $old1 => [ $new1, $type1 ], $old2 => [ $new2, $type2 ], ... ] )
-        *                                 Syntax for Primary Key: [ $col1, $col2, ...] )
-        * @param int    $type     The type of renaming (Default is Column)
+        *    Check if a table exists
         *
-        * @return boolean Was the renaming successful?
+        * @param string $table Table name
         *
+        * @return boolean Does the table exist?
         */
-       public static function rename($table, $columns, $type = self::RENAME_COLUMN) {
-               if (empty($table) || empty($columns)) {
-                       return false;
-               }
-
-               if (!is_array($columns)) {
+       public static function existsTable($table)
+       {
+               if (empty($table)) {
                        return false;
                }
 
                $table = DBA::escape($table);
 
-               $sql = "ALTER TABLE `" . $table . "`";
-               switch ($type) {
-                       case self::RENAME_COLUMN:
-                               if (!self::existsColumn($table, array_keys($columns))) {
-                                       return false;
-                               }
-                               $sql .= implode(',', array_map(
-                                       function ($to, $from) {
-                                               return " CHANGE `" . $from . "` `" . $to[0] . "` " . $to[1];
-                                       },
-                                       $columns,
-                                       array_keys($columns)
-                               ));
-                               break;
-                       case self::RENAME_PRIMARY_KEY:
-                               if (!self::existsColumn($table, $columns)) {
-                                       return false;
-                               }
-                               $sql .= " DROP PRIMARY KEY, ADD PRIMARY KEY(`" . implode('`, `', $columns) . "`)";
-                               break;
-                       default:
-                               return false;
-               }
-
-               $sql .= ";";
+               $sql = "SHOW TABLES LIKE '" . $table . "';";
 
                $stmt = DBA::p($sql);
 
                if (is_bool($stmt)) {
                        $retval = $stmt;
                } else {
-                       $retval = true;
+                       $retval = (DBA::numRows($stmt) > 0);
                }
 
                DBA::close($stmt);
 
                return $retval;
        }
-
-       /**
-        * Loads the database structure definition from the config/dbstructure.config.php file.
-        * On first pass, defines DB_UPDATE_VERSION constant.
-        *
-        * @see config/dbstructure.config.php
-        * @param boolean $with_addons_structure Whether to tack on addons additional tables
-        * @return array
-        * @throws Exception
-        */
-       public static function definition($with_addons_structure = true)
-       {
-               if (!self::$definition) {
-                       $a = \Friendica\BaseObject::getApp();
-
-                       $filename = $a->getBasePath() . '/config/dbstructure.config.php';
-
-                       if (!is_readable($filename)) {
-                               throw new Exception('Missing database structure config file config/dbstructure.config.php');
-                       }
-
-                       $definition = require $filename;
-
-                       if (!$definition) {
-                               throw new Exception('Corrupted database structure config file config/dbstructure.config.php');
-                       }
-
-                       self::$definition = $definition;
-               } else {
-                       $definition = self::$definition;
-               }
-
-               if ($with_addons_structure) {
-                       Hook::callAll('dbstructure_definition', $definition);
-               }
-
-               return $definition;
-       }
 }
index 94c02013e719804f83340e4c069fd5b887d98b32..9329e31cac1bf53174ae69e5be64774853b852aa 100644 (file)
@@ -13,8 +13,6 @@ use Friendica\Model\ItemURI;
 use Friendica\Model\PermissionSet;
 use Friendica\Database\DBA;
 
-require_once 'include/dba.php';
-
 /**
  * Post update functions
  */
index c306b3e007af9758bbe1b4198ecd4cbf69492550..bbaf6dad627753021927baf8f2135ae8e82cad6c 100644 (file)
@@ -16,8 +16,6 @@ use Friendica\Util\JsonLD;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
 
-require_once 'boot.php';
-
 class APContact extends BaseObject
 {
        /**
index 5894814ea6c0e58dddda35b8c2272b779f5c27a5..4a63a6b49a5084d695ff91bf23a05c8350e13bcd 100644 (file)
@@ -27,10 +27,6 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 
-require_once 'boot.php';
-require_once 'include/dba.php';
-require_once 'include/text.php';
-
 /**
  * @brief functions for interacting with a contact
  */
@@ -1376,8 +1372,6 @@ class Contact extends BaseObject
        {
                $a = self::getApp();
 
-               require_once 'include/conversation.php';
-
                $cid = Self::getIdForURL($contact_url);
 
                $contact = DBA::selectFirst('contact', ['contact-type', 'network'], ['id' => $cid]);
index 159cd2f20f23a221e3eedc862f0a05439291f5c3..b8e55e5b961a349e10b4dee8b1a3412eb9d13f2e 100644 (file)
@@ -10,8 +10,6 @@ use Friendica\Core\Protocol;
 use Friendica\Database\DBA;
 use Friendica\Util\DateTimeFormat;
 
-require_once "include/dba.php";
-
 class Conversation
 {
        /*
index d25f2a151ab8f90af1d17846808ea021635868bc..ce77ee7a9376bf51a39d8822f6d26af422b64ed4 100644 (file)
@@ -19,10 +19,6 @@ use Friendica\Util\Map;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'boot.php';
-require_once 'include/dba.php';
-require_once 'include/items.php';
-
 /**
  * @brief functions for interacting with the event database table
  */
index 44d1edecd78c5dcdf2cec638600e7e8993ee4178..c3d58aae74330f7395b9c3a0b47a4bb50d11cdc9 100644 (file)
@@ -19,8 +19,6 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 
-require_once 'include/dba.php';
-
 /**
  * @brief This class handles GlobalContact related functions
  */
index 5424b77dcfaec483ed3365e92e7ec82ff5226650..9a4fc23407b28e3d65a7e74fe3aab386fcaf349b 100644 (file)
@@ -12,10 +12,6 @@ use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\Util\Security;
 
-require_once 'boot.php';
-require_once 'include/dba.php';
-require_once 'include/text.php';
-
 /**
  * @brief functions for interacting with the group database table
  */
index 9acff3bfa8490bb5241162ed0d4784af5e1f0c7b..939ee43bf4f45b9dfda722969ac6c76960572fa4 100644 (file)
@@ -36,10 +36,6 @@ use Friendica\Util\Security;
 use Friendica\Util\Strings;
 use Text_LanguageDetect;
 
-require_once 'boot.php';
-require_once 'include/items.php';
-require_once 'include/text.php';
-
 class Item extends BaseObject
 {
        // Posting types, inspired by https://www.w3.org/TR/activitystreams-vocabulary/#object-types
index c51f471d8585b4d84fb7fdbb582adebd8fef4785..25ae6b84241e3cc4fac78e77dd3f24402527f6ae 100644 (file)
@@ -11,10 +11,6 @@ use Friendica\Content\Text;
 use Friendica\Core\PConfig;
 use Friendica\Core\Protocol;
 
-require_once 'boot.php';
-require_once 'include/items.php';
-require_once 'include/text.php';
-
 class ItemContent extends BaseObject
 {
        /**
index 452f7e57c8e3838d3da43e97878a8e12734c27ed..56e9e1caaeb7c1c7f8a779b6d59a295bdda6b932 100644 (file)
@@ -9,8 +9,6 @@ namespace Friendica\Model;
 use Friendica\BaseObject;
 use Friendica\Database\DBA;
 
-require_once 'boot.php';
-
 class ItemURI extends BaseObject
 {
        /**
index 815b0051d9df1ff0b5cc7ef2d2c3eea09fb85053..ec02311078bafea52dab1c45a70871b89ec90bbd 100644 (file)
@@ -13,8 +13,6 @@ use Friendica\Database\DBA;
 use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
 
-require_once 'include/dba.php';
-
 /**
  * Class to handle private messages
  */
index 6506c70940529859de991fa0f97da487f38eb6f3..ab6c46afb24ddf5c383dfd1dcfeac73da5957584 100644 (file)
@@ -7,8 +7,6 @@ namespace Friendica\Model;
 use Friendica\BaseObject;
 use Friendica\Database\DBA;
 
-require_once 'include/dba.php';
-
 /**
  * @brief functions for interacting with the permission set of an object (item, photo, event, ...)
  */
index a87730087f3a024934edd24c60f69a09692175e6..4a9e11c55472deb4123d375dbcdf8c80284185ef 100644 (file)
@@ -16,8 +16,6 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Security;
 
-require_once 'include/dba.php';
-
 /**
  * Class to handle photo dabatase table
  */
index 40f0c52bdb4e361b9a3ef8f5d8bd57e890cf9b8c..4d50ecd4ebc180b7f4993d3e223fb43b685e9f90 100644 (file)
@@ -8,8 +8,6 @@ use Friendica\BaseObject;
 use Friendica\Database\DBA;
 use Friendica\Util\DateTimeFormat;
 
-require_once 'include/dba.php';
-
 /**
  * @brief functions for interacting with a process
  */
index 132f9f33449f81a76f175e70840c0eee12a6fbfe..bd455bc6ba4ca4898bf736b85c245d31d6fe5b05 100644 (file)
@@ -28,8 +28,6 @@ use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
-require_once 'include/dba.php';
-
 class Profile
 {
        /**
index 44495daeefb4b1b66c251326bf4d8813f325a68b..fb34bb55f43c2c02f78207462ee2f26dedd9d0bd 100644 (file)
@@ -9,8 +9,6 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Util\DateTimeFormat;
 
-require_once 'include/dba.php';
-
 class PushSubscriber
 {
        /**
index 7ffc64bf9e56af603d438882218e805c418c4dfc..b2c002574c9f871426a9019cc4c7b951c93396d5 100644 (file)
@@ -9,8 +9,6 @@ use Friendica\Core\Logger;
 use Friendica\Database\DBA;
 use Friendica\Util\DateTimeFormat;
 
-require_once 'include/dba.php';
-
 class Queue
 {
        /**
index 0d44acd2c988958237e35beb3b7343e4bc5964c0..7f494fc4afb84c7ef7fac6ef08cfa4cde5f796f3 100644 (file)
@@ -7,10 +7,6 @@ namespace Friendica\Model;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 
-require_once 'boot.php';
-require_once 'include/conversation.php';
-require_once 'include/dba.php';
-
 class Term
 {
        public static function tagTextFromItemId($itemid)
index a6a9fc95253efb6d64abd2eb4a30bf08ca1788dd..c71ae475e9699499af33637b69ff4ada45930eca 100644 (file)
@@ -24,10 +24,6 @@ use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use LightOpenID;
 
-require_once 'boot.php';
-require_once 'include/dba.php';
-require_once 'include/enotify.php';
-require_once 'include/text.php';
 /**
  * @brief This class handles User related functions
  */
index 4d091835292e25f69da1ca972a80063c58d06b70..411da5ce5eafd0300b0a1d38eb318d59acb53792 100644 (file)
@@ -9,9 +9,6 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Util\Strings;
 
-require_once 'include/dba.php';
-require_once 'include/text.php';
-
 /**
  * Hashtag module.
  */
index 82d70498281fc6547a6e7a79520c6bca96793c8b..b312a7879dbc90ae525f1b7ee9edba2ed7c963e1 100644 (file)
@@ -20,9 +20,6 @@ use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use LightOpenID;
 
-require_once 'boot.php';
-require_once 'include/text.php';
-
 /**
  * Login module
  *
index f212a894029cd6e9279e41e1dd520ef8f56c68a6..7024fc110ac3081d3e92202cbde0489c4ee75bb7 100644 (file)
@@ -10,8 +10,6 @@ use Friendica\Core\Authentication;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
 
-require_once 'boot.php';
-
 /**
  * Logout module
  *
index 44e14f2156b0cc6267ba5f307ffb094c3242260f..276ba2fcbe74e9ddaa7b42d7f01677dff696dbe3 100644 (file)
@@ -19,8 +19,6 @@ use OAuthToken;
 define('REQUEST_TOKEN_DURATION', 300);
 define('ACCESS_TOKEN_DURATION', 31536000);
 
-require_once 'include/dba.php';
-
 /**
  * @brief OAuthDataStore class
  */
index b4e297afa2096b9aac07dd5ddcf51bfbcede087c..f61eed4192231b29cdd3e2c153bfc8308fbc0a46 100644 (file)
@@ -28,8 +28,6 @@ use Friendica\Util\Strings;
 use Friendica\Util\XML;
 use DomXPath;
 
-require_once 'include/dba.php';
-
 /**
  * @brief This class contain functions for probing URL
  *
index 1ca1e222ebe92a2c3e3394395bdad02e57ed14af..dd2628d3ee7ed01825a2a10d02bd48ed4a710f32 100644 (file)
@@ -24,11 +24,6 @@ use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
-require_once 'include/dba.php';
-require_once 'include/text.php';
-require_once 'boot.php';
-require_once 'include/conversation.php';
-
 /**
  * An item
  */
index b6d92e743c823b40c9b07f93930d53a159ecedb3..0068fa2fb9d7ac81ddadd78f409a45207b07fb49 100644 (file)
@@ -10,9 +10,6 @@ use Friendica\Core\Protocol;
 use Friendica\Object\Post;
 use Friendica\Util\Security;
 
-require_once 'boot.php';
-require_once 'include/text.php';
-
 /**
  * A list of threads
  *
index 7c807b921e22cad9ff923fed1def135bd8b9918a..c3366f5bcca571049338d33a9df20227e0d4e6e7 100644 (file)
@@ -37,12 +37,6 @@ use Friendica\Util\XML;
 use HTMLPurifier;
 use HTMLPurifier_Config;
 
-require_once 'boot.php';
-require_once 'include/dba.php';
-require_once "include/enotify.php";
-require_once "include/items.php";
-require_once "include/text.php";
-
 /**
  * @brief This class contain functions to create and send DFRN XML files
  */
index 38d9deb7f8371b0b13815aee93a4db16bbf13eff..64009581b5e2dea80f6e6c808766624e753cb98f 100644 (file)
@@ -38,9 +38,6 @@ use Friendica\Util\Strings;
 use Friendica\Util\XML;
 use SimpleXMLElement;
 
-require_once 'include/dba.php';
-require_once 'include/items.php';
-
 /**
  * @brief This class contain functions to create and send Diaspora XML files
  *
index 5939e5ce1a929b96c00f0fc21b642acab4856106..67e5412e25110d301abfdadc15181789373e6b4e 100644 (file)
@@ -17,9 +17,6 @@ use Friendica\Model\Item;
 use Friendica\Util\Network;
 use Friendica\Util\XML;
 
-require_once 'include/dba.php';
-require_once 'include/items.php';
-
 /**
  * @brief This class contain functions to import feeds
  *
index 361d333b40f2a208f4422401711dc3d110f89d75..1a6f748d1698cf4b0a30e840d744da9588fd1a9b 100644 (file)
@@ -29,10 +29,7 @@ use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'include/dba.php';
-require_once 'include/items.php';
 require_once 'mod/share.php';
-require_once 'include/enotify.php';
 require_once 'include/api.php';
 
 /**
index fb7b9d7bab5798fb706a14b383b072b7b49304a2..3300b1d7abe28ce040caa1ebfea001308b56362a 100644 (file)
@@ -26,8 +26,6 @@ use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'include/dba.php';
-
 class PortableContact
 {
        /**
index 8d38b336612e8ed736e2e32d9dfbec37f251c426..aa163f6a9e28c52488a222c42fdb42b81f5f3427 100644 (file)
@@ -39,8 +39,6 @@ use Friendica\Core\PConfig;
 use Friendica\Database\DBA;
 use Friendica\Model\User;
 
-require_once 'include/dba.php';
-
 class ExAuth
 {
        private $bDebug;
index 1188214200cdc7d7971f65737886b0591008530e..062a809b6a9d74c7a6c52ba1676b11bec9d5eafb 100644 (file)
@@ -14,8 +14,6 @@ use Friendica\Database\DBA;
 use Friendica\Object\Image;
 use Friendica\Util\Strings;
 
-require_once 'include/dba.php';
-
 /**
  * @brief Class with methods for extracting certain content from an url
  */
@@ -184,11 +182,10 @@ class ParseUrl
                        $charset = trim(trim(trim(array_pop($matches)), ';,'));
                }
 
-               if ($charset == '') {
-                       $charset = 'utf-8';
-               }
+               if ($charset && strtoupper($charset) != 'UTF-8') {
+                       // See https://github.com/friendica/friendica/issues/5470#issuecomment-418351211
+                       $charset = str_ireplace('latin-1', 'latin1', $charset);
 
-               if (($charset != '') && (strtoupper($charset) != 'UTF-8')) {
                        Logger::log('detected charset ' . $charset, Logger::DEBUG);
                        $body = iconv($charset, 'UTF-8//TRANSLIT', $body);
                }
index 44b9601164fadd92bb194ddc04759c7b87800291..d121d59770657dc8e3b59a1efceef22567921a3b 100644 (file)
@@ -14,9 +14,6 @@ use Friendica\Core\PConfig;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 
-require_once 'boot.php';
-require_once 'include/text.php';
-
 /**
  * @brief Temporal class
  */
index 9b8eb1cfec8b11aa1be350f7522cf350b60193c7..0e4b40bf66e3a300da6e2761da40bc601b704324 100644 (file)
@@ -15,8 +15,6 @@ use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Util\DateTimeFormat;
 
-require_once 'include/dba.php';
-
 class Cron
 {
        public static function execute($parameter = '', $generation = 0)
index 164b1cf4d203747739b2e603073b134a906ba8e1..b13afffd9acb8a6449a65928aa60ea06192f4818 100644 (file)
@@ -20,7 +20,6 @@ use Friendica\Network\Probe;
 use Friendica\Protocol\PortableContact;
 use Friendica\Util\Proxy as ProxyUtils;
 
-require_once 'include/dba.php';
 require_once 'mod/nodeinfo.php';
 
 class CronJobs
index a722fa23b667188d39517f05e86465a7380d7d17..67f073b10fd1f78239c8b9045d5cc08f3cd2fc86 100644 (file)
@@ -11,8 +11,6 @@ use Friendica\Core\Logger;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 
-require_once 'include/dba.php';
-
 class DBClean {
        public static function execute($stage = 0) {
 
index 0d56bfa5d1117bec4fab2a65beb39a0d972dabde..459660f4ea795f1492107df8eda54890b8769392 100644 (file)
@@ -21,8 +21,6 @@ use Friendica\Protocol\Email;
 use Friendica\Util\Strings;
 use Friendica\Util\Network;
 
-require_once 'include/items.php';
-
 class Delivery extends BaseObject
 {
        const MAIL          = 'mail';
index 21e873502ba1add6c95a555eab7b3e96b4699d16..cb6bdbacbc9306f3de610b5819fc2ff438eba0e7 100644 (file)
@@ -14,16 +14,12 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model\Item;
 
-require_once 'include/dba.php';
-
 class Expire
 {
        public static function execute($param = '', $hook_function = '')
        {
                $a = BaseObject::getApp();
 
-               require_once 'include/items.php';
-
                Hook::loadHooks();
 
                if ($param == 'delete') {
index 00ad1543d62f0322e2852fdf44038ed9593dbf29..d82e294d95ae2eccee8afd9bd7b08cac0da39dcc 100644 (file)
@@ -24,9 +24,6 @@ use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Protocol\Salmon;
 
-require_once 'include/dba.php';
-require_once 'include/items.php';
-
 /*
  * The notifier is typically called with:
  *
index f254596720fb56aa1757b4ab64935fbf520b937d..0579bfa24505f8979dd6fd5534cf32f5950bbdb2 100644 (file)
@@ -21,16 +21,12 @@ use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'include/dba.php';
-
 class OnePoll
 {
        public static function execute($contact_id = 0, $command = '')
        {
                $a = BaseObject::getApp();
 
-               require_once 'include/items.php';
-
                Logger::log('start');
 
                $manual_id  = 0;
index 801bdc888065e6b6fe2075803e9bcdbfeab9dd11..9f5fcdcc5fed056de4f709d5cb6437faf4214445 100644 (file)
@@ -13,8 +13,6 @@ use Friendica\Model\PushSubscriber;
 use Friendica\Protocol\OStatus;
 use Friendica\Util\Network;
 
-require_once 'include/items.php';
-
 class PubSubPublish
 {
        public static function execute($pubsubpublish_id = 0)
index 8dc34a594a1eda8a035d2a505b87a5c2b8b2026d..7ba18ae1c2347a487344a7bdc1f449732d30272e 100644 (file)
@@ -20,9 +20,6 @@ use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\PortableContact;
 use Friendica\Protocol\Salmon;
 
-require_once 'include/dba.php';
-require_once 'include/items.php';
-
 class Queue
 {
        public static function execute($queue_id = 0)
index 2e3f16db3e99da80512b85d80cf98b163f18b4f4..00027dca40a2e46dd2b78352a274885634ff0519 100644 (file)
@@ -9,8 +9,6 @@ use Friendica\Database\DBA;
 use Friendica\Core\Protocol;
 use Friendica\Model\Item;
 
-require_once 'include/dba.php';
-
 class RemoveContact {
        public static function execute($id) {
 
index 10ede55763d47ea2071866fdd6de59acac32239a..c7179a4e3d6546c462ad800d90d92259446cfa48 100644 (file)
@@ -8,8 +8,6 @@ namespace Friendica\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model\Item;
 
-require_once 'include/dba.php';
-
 class RemoveUser {
        public static function execute($uid)
        {
index 2efd77d553779d3cc2fa3f759ba8e6466389a818..bb01deace1b64af5f3bf4c2a560bb10f2f1c17d2 100644 (file)
@@ -9,8 +9,6 @@ use Friendica\Core\Config;
 use Friendica\Core\Logger;
 use Friendica\Model\Item;
 
-require_once "include/items.php";
-
 class SpoolPost {
        public static function execute() {
                $path = get_spoolpath();
index 3d7effe52b0dc26d5952353fd172bdd695564dfb..564c2562a877ca37c8f1db3700a565b958b5cc52 100644 (file)
@@ -253,9 +253,6 @@ class InstallerTest extends MockedTest
                // Mocking that we can use CURL
                $this->setFunctions(['curl_init' => true]);
 
-               // needed because of "normalise_link"
-               require_once __DIR__ . '/../../../include/text.php';
-
                $install = new Installer();
 
                $this->assertFalse($install->checkHtAccess('https://test'));
index 13a14d985eef931a1783c6462865604eca52ca24..775c4179f3a7139f5891cf5f86ff0520f7e7d9bb 100644 (file)
@@ -7,14 +7,6 @@ use PHPUnit\Framework\TestCase;
 
 class CurlResultTest extends TestCase
 {
-       public function setUp()
-       {
-               parent::setUp();
-
-               require_once __DIR__.'/../../../boot.php';
-               require_once __DIR__.'/../../../include/text.php';
-       }
-
        /**
         * @small
         */
index 41b6fa96f2eb18c687393269591d5738b57e2f1a..22d1809fea8ef75e4cc8af9f96043c255e420dbf 100644 (file)
@@ -12,8 +12,6 @@ use Friendica\Model\Item;
 use Friendica\Model\User;
 use Friendica\Util\DateTimeFormat;
 
-require_once 'include/dba.php';
-
 /**
  *
  * update.php - automatic system update
index 05829bb21f122aede7bcac2f60a5369dd5134ee0..ddce673105e473320879d57b2ae066746f0753e5 100644 (file)
@@ -19,8 +19,6 @@
  */
 use Friendica\Core\PConfig;
 
-require_once 'boot.php';
-
 function get_scheme_info($scheme)
 {
        $theme = get_app()->getCurrentTheme();