From 713bdb4bd96e4959ffe748e88f53ed5d400133a1 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 8 Mar 2018 19:47:18 +0000 Subject: [PATCH 01/24] Improved reshare behaviour for DFRN posts --- src/Protocol/Diaspora.php | 43 ++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 0055f8d9b..c3a485e91 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -2642,7 +2642,7 @@ class Diaspora * * @return array The fetched item */ - private static function originalItem($guid, $orig_author, $author) + public static function originalItem($guid, $orig_author) { // Do we already have this item? $r = q( @@ -2736,7 +2736,7 @@ class Diaspora return true; } - $original_item = self::originalItem($root_guid, $root_author, $author); + $original_item = self::originalItem($root_guid, $root_author); if (!$original_item) { return false; } @@ -3451,24 +3451,21 @@ class Diaspora // Skip if it isn't a pure repeated messages // Does it start with a share? if ((strpos($body, "[share") > 0) && $complete) { - return(false); + return false; } // Does it end with a share? if (strlen($body) > (strrpos($body, "[/share]") + 8)) { - return(false); + return false; } $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism", "$1", $body); // Skip if there is no shared message in there if ($body == $attributes) { - return(false); + return false; } // If we don't do the complete check we quit here - if (!$complete) { - return true; - } $guid = ""; preg_match("/guid='(.*?)'/ism", $attributes, $matches); @@ -3481,7 +3478,7 @@ class Diaspora $guid = $matches[1]; } - if ($guid != "") { + if (($guid != "") && $complete) { $r = q( "SELECT `contact-id` FROM `item` WHERE `guid` = '%s' AND `network` IN ('%s', '%s') LIMIT 1", dbesc($guid), @@ -3492,7 +3489,7 @@ class Diaspora $ret= []; $ret["root_handle"] = self::handleFromContact($r[0]["contact-id"]); $ret["root_guid"] = $guid; - return($ret); + return $ret; } } @@ -3509,28 +3506,22 @@ class Diaspora $ret= []; - $ret["root_handle"] = preg_replace("=https?://(.*)/u/(.*)=ism", "$2@$1", $profile); - if (($ret["root_handle"] == $profile) || ($ret["root_handle"] == "")) { - return(false); + if ($profile != "") { + if (Contact::getIdForURL($profile)) { + $author = Contact::getDetailsByURL($profile); + $ret["root_handle"] = $author['addr']; + } } - $link = ""; - preg_match("/link='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") { - $link = $matches[1]; + if (!empty($guid)) { + $ret["root_guid"] = $guid; } - preg_match('/link="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") { - $link = $matches[1]; + if (empty($ret) && !$complete) { + return true; } - $ret["root_guid"] = preg_replace("=https?://(.*)/posts/(.*)=ism", "$2", $link); - if (($ret["root_guid"] == $link) || (trim($ret["root_guid"]) == "")) { - return(false); - } - - return($ret); + return $ret; } /** From 03748ddd6464bdc636ee8ff404d4f6f5380f5df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= Date: Mon, 16 Apr 2018 10:57:27 +0200 Subject: [PATCH 02/24] [FEATURE] Install Script: Add first version --- auto_install.php | 164 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 auto_install.php diff --git a/auto_install.php b/auto_install.php new file mode 100644 index 000000000..ef30d1912 --- /dev/null +++ b/auto_install.php @@ -0,0 +1,164 @@ +config['php_path'])) { + check_php($app->config['php_path'], $checks); + } else { + die(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n"); + } + + echo " NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n"; + + return $checks; +} + +function run_database_check() +{ + global $db_host; + global $db_user; + global $db_pass; + global $db_data; + + $result = array( + 'title' => 'MySQL Connection', + 'required' => true, + 'status' => true, + 'help' => '', + ); + + if (!dba::connect($db_host, $db_user, $db_pass, $db_data, true)) { + $result['status'] = false; + $result['help'] = 'Failed, please check your MySQL settings and credentials.'; + } + + return $result; +} From 791071a1c640d04d79c2770d3f7f730a3048df96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= Date: Mon, 16 Apr 2018 14:56:02 +0200 Subject: [PATCH 03/24] [CLEANUP] Code: Remove function --- auto_install.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/auto_install.php b/auto_install.php index ef30d1912..bc418d688 100644 --- a/auto_install.php +++ b/auto_install.php @@ -13,7 +13,9 @@ if (file_exists('.htconfig.php') && filesize('.htconfig.php')) { } // Remove die from config file -copy_config_file(); +$fileContent = file_get_contents('./htconfig.php'); +$fileContent = str_replace('die', '//die', $fileContent); +file_put_contents('.htautoinstall.php', $fileContent); require_once 'boot.php'; require_once 'mod/install.php'; @@ -109,13 +111,6 @@ echo " Complete!\n\n"; echo "\nInstallation is finished\n"; -function copy_config_file() -{ - $fileContent = file_get_contents('./htconfig.php'); - $fileContent = str_replace('die', '//die', $fileContent); - file_put_contents('.htautoinstall.php', $fileContent); -} - /** * @param App $app * @return array From cc40dcf83cbaa953ca6878aeabf25c96549593a7 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Apr 2018 23:28:05 -0400 Subject: [PATCH 04/24] Add dbstructure_definition hook call --- src/Database/DBStructure.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 67c8d7b8a..bccd70372 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -1803,6 +1803,8 @@ class DBStructure ] ]; + \Friendica\Core\Addon::callHooks('dbstructure_definition', $database); + return $database; } } From 54b75026fce057829f65eb194fb1ff231b2fbf78 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Apr 2018 23:28:51 -0400 Subject: [PATCH 05/24] Add header support for security token check --- include/security.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/include/security.php b/include/security.php index af424df26..b13a507cf 100644 --- a/include/security.php +++ b/include/security.php @@ -405,12 +405,21 @@ function get_form_security_token($typename = '') function check_form_security_token($typename = '', $formname = 'form_security_token') { - if (!x($_REQUEST, $formname)) { - return false; + $hash = null; + + if (!empty($_REQUEST[$formname])) { + /// @TODO Careful, not secured! + $hash = $_REQUEST[$formname]; } - /// @TODO Careful, not secured! - $hash = $_REQUEST[$formname]; + if (!empty($_SERVER['HTTP_X_CSRF_TOKEN'])) { + /// @TODO Careful, not secured! + $hash = $_SERVER['HTTP_X_CSRF_TOKEN']; + } + + if (empty($hash)) { + return false; + } $max_livetime = 10800; // 3 hours From 17a0cc4f3dafadf97b45b69f742130d7b4ae3e87 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 14 Apr 2018 17:54:16 -0400 Subject: [PATCH 06/24] Add Model\Term::populateTagsFromItem method --- src/Model/Term.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/Model/Term.php b/src/Model/Term.php index d950d1d5f..03f19197a 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -9,6 +9,7 @@ use Friendica\Database\DBM; use dba; require_once 'boot.php'; +require_once 'include/conversation.php'; require_once 'include/dba.php'; class Term @@ -168,4 +169,56 @@ class Term } } } + + /** + * Sorts an item's tags into mentions, hashtags and other tags. Generate personalized URLs by user and modify the + * provided item's body with them. + * + * @param array $item + * @return array + */ + public static function populateTagsFromItem(&$item) + { + $return = [ + 'tags' => [], + 'hashtags' => [], + 'mentions' => [], + ]; + + $searchpath = System::baseUrl() . "/search?tag="; + + $taglist = dba::select( + 'term', + ['type', 'term', 'url'], + ["`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION], + ['order' => ['tid']] + ); + + while ($tag = dba::fetch($taglist)) { + if ($tag["url"] == "") { + $tag["url"] = $searchpath . strtolower($tag["term"]); + } + + $orig_tag = $tag["url"]; + + $tag["url"] = best_link_url($item, $sp, $tag["url"]); + + if ($tag["type"] == TERM_HASHTAG) { + if ($orig_tag != $tag["url"]) { + $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']); + } + + $return['hashtags'][] = "#" . $tag["term"] . ""; + $prefix = "#"; + } elseif ($tag["type"] == TERM_MENTION) { + $return['mentions'][] = "@" . $tag["term"] . ""; + $prefix = "@"; + } + + $return['tags'][] = $prefix . "" . $tag["term"] . ""; + } + dba::close($taglist); + + return $return; + } } From 98f64ed8242d3f3b270ad90cdc7a658a6bdca067 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 14 Apr 2018 17:55:07 -0400 Subject: [PATCH 07/24] Replace duplicate behaviors by Model\Term::populateTagsFromItem - Replaced in include/conversation - Replaced in include/text --- include/conversation.php | 34 ++++------------------------------ include/text.php | 40 ++++------------------------------------ 2 files changed, 8 insertions(+), 66 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 8a2887d6b..41f10959b 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -668,33 +668,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order = $profile_name = $item['author-link']; } - $tags = []; - $hashtags = []; - $mentions = []; - - $searchpath = System::baseUrl()."/search?tag="; - - $taglist = dba::select('term', ['type', 'term', 'url'], - ["`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION], - ['order' => ['tid']]); - - while ($tag = dba::fetch($taglist)) { - if ($tag["url"] == "") { - $tag["url"] = $searchpath . strtolower($tag["term"]); - } - - $tag["url"] = best_link_url($item, $sp, $tag["url"]); - - if ($tag["type"] == TERM_HASHTAG) { - $hashtags[] = "#" . $tag["term"] . ""; - $prefix = "#"; - } elseif ($tag["type"] == TERM_MENTION) { - $mentions[] = "@" . $tag["term"] . ""; - $prefix = "@"; - } - $tags[] = $prefix."" . $tag["term"] . ""; - } - dba::close($taglist); + $tags = \Friendica\Model\Term::populateTagsFromItem($item); $sp = false; $profile_link = best_link_url($item, $sp); @@ -764,9 +738,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order = } $body_e = $body; - $tags_e = $tags; - $hashtags_e = $hashtags; - $mentions_e = $mentions; + $tags_e = $tags['tags']; + $hashtags_e = $tags['hashtags']; + $mentions_e = $tags['mentions']; $location_e = $location; $owner_name_e = $owner_name; diff --git a/include/text.php b/include/text.php index ee8a213ff..2ec017caf 100644 --- a/include/text.php +++ b/include/text.php @@ -1234,12 +1234,6 @@ function prepare_body(array &$item, $attach = false, $is_preview = false) $a = get_app(); Addon::callHooks('prepare_body_init', $item); - $searchpath = System::baseUrl() . "/search?tag="; - - $tags = []; - $hashtags = []; - $mentions = []; - // In order to provide theme developers more possibilities, event items // are treated differently. if ($item['object-type'] === ACTIVITY_OBJ_EVENT && isset($item['event-id'])) { @@ -1247,37 +1241,11 @@ function prepare_body(array &$item, $attach = false, $is_preview = false) return $ev; } - $taglist = dba::p("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = ? AND `oid` = ? AND `type` IN (?, ?) ORDER BY `tid`", - intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION)); + $tags = \Friendica\Model\Term::populateTagsFromItem($item); - while ($tag = dba::fetch($taglist)) { - if ($tag["url"] == "") { - $tag["url"] = $searchpath . strtolower($tag["term"]); - } - - $orig_tag = $tag["url"]; - - $tag["url"] = best_link_url($item, $sp, $tag["url"]); - - if ($tag["type"] == TERM_HASHTAG) { - if ($orig_tag != $tag["url"]) { - $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']); - } - - $hashtags[] = "#" . $tag["term"] . ""; - $prefix = "#"; - } elseif ($tag["type"] == TERM_MENTION) { - $mentions[] = "@" . $tag["term"] . ""; - $prefix = "@"; - } - - $tags[] = $prefix . "" . $tag["term"] . ""; - } - dba::close($taglist); - - $item['tags'] = $tags; - $item['hashtags'] = $hashtags; - $item['mentions'] = $mentions; + $item['tags'] = $tags['tags']; + $item['hashtags'] = $tags['hashtags']; + $item['mentions'] = $tags['mentions']; // Compile eventual content filter reasons $filter_reasons = []; From 188158274cdb79c84c7e9c163a52a593179cbc12 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 17 Apr 2018 19:56:47 -0400 Subject: [PATCH 08/24] [Composer] Add bower-asset/vue dependency --- composer.json | 1 + composer.lock | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 52b4f2c86..5cb33e67d 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,7 @@ "bower-asset/base64": "^1.0", "bower-asset/Chart-js": "^2.7", "bower-asset/perfect-scrollbar": "^0.6", + "bower-asset/vue": "^2.5", "npm-asset/jquery": "^2.0", "npm-asset/jquery-colorbox": "^1.6", "npm-asset/jquery-datetimepicker": "^2.4.0", diff --git a/composer.lock b/composer.lock index 28199f4f5..34362cb1b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "12b8df66213734281765cb6e2c5a786e", + "content-hash": "96062c2020a40f14b52e5e91c79995a7", "packages": [ { "name": "asika/simple-console", @@ -133,6 +133,22 @@ "description": "Minimalistic but perfect custom scrollbar plugin", "time": "2017-01-10T01:04:09+00:00" }, + { + "name": "bower-asset/vue", + "version": "v2.5.16", + "source": { + "type": "git", + "url": "https://github.com/vuejs/vue.git", + "reference": "25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vuejs/vue/zipball/25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6", + "reference": "25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6", + "shasum": "" + }, + "type": "bower-asset-library" + }, { "name": "divineomega/password_exposed", "version": "v2.5.1", From f99af007aef66670535a7ac41fe0bc37dea74401 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 18 Apr 2018 04:59:33 +0000 Subject: [PATCH 09/24] Replaced queries --- src/Protocol/Diaspora.php | 58 +++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 6c47aadc7..733cdf743 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -2747,32 +2747,30 @@ class Diaspora public static function originalItem($guid, $orig_author) { // Do we already have this item? - $r = q( - "SELECT `body`, `tag`, `app`, `created`, `object-type`, `uri`, `guid`, - `author-name`, `author-link`, `author-avatar` - FROM `item` WHERE `guid` = '%s' AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1", - dbesc($guid) - ); + $fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid', + 'author-name', 'author-link', 'author-avatar']; + $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false]; + $item = dba::selectfirst('item', $fields, $condition); - if (DBM::is_result($r)) { + if (DBM::is_result($item)) { logger("reshared message ".$guid." already exists on system."); // Maybe it is already a reshared item? // Then refetch the content, if it is a reshare from a reshare. // If it is a reshared post from another network then reformat to avoid display problems with two share elements - if (self::isReshare($r[0]["body"], true)) { + if (self::isReshare($item["body"], true)) { $r = []; - } elseif (self::isReshare($r[0]["body"], false) || strstr($r[0]["body"], "[share")) { - $r[0]["body"] = Markdown::toBBCode(BBCode::toMarkdown($r[0]["body"])); + } elseif (self::isReshare($item["body"], false) || strstr($item["body"], "[share")) { + $item["body"] = Markdown::toBBCode(BBCode::toMarkdown($item["body"])); - $r[0]["body"] = self::replacePeopleGuid($r[0]["body"], $r[0]["author-link"]); + $item["body"] = self::replacePeopleGuid($item["body"], $item["author-link"]); // Add OEmbed and other information to the body - $r[0]["body"] = add_page_info_to_body($r[0]["body"], false, true); + $item["body"] = add_page_info_to_body($item["body"], false, true); - return $r[0]; + return $item; } else { - return $r[0]; + return $item; } } @@ -2788,21 +2786,19 @@ class Diaspora } if ($item_id) { - $r = q( - "SELECT `body`, `tag`, `app`, `created`, `object-type`, `uri`, `guid`, - `author-name`, `author-link`, `author-avatar` - FROM `item` WHERE `id` = %d AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1", - intval($item_id) - ); + $fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid', + 'author-name', 'author-link', 'author-avatar']; + $condition = ['id' => $item_id, 'visible' => true, 'deleted' => false]; + $item = dba::selectfirst('item', $fields, $condition); - if (DBM::is_result($r)) { + if (DBM::is_result($item)) { // If it is a reshared post from another network then reformat to avoid display problems with two share elements - if (self::isReshare($r[0]["body"], false)) { - $r[0]["body"] = Markdown::toBBCode(BBCode::toMarkdown($r[0]["body"])); - $r[0]["body"] = self::replacePeopleGuid($r[0]["body"], $r[0]["author-link"]); + if (self::isReshare($item["body"], false)) { + $item["body"] = Markdown::toBBCode(BBCode::toMarkdown($item["body"])); + $item["body"] = self::replacePeopleGuid($item["body"], $item["author-link"]); } - return $r[0]; + return $item; } } } @@ -3584,15 +3580,11 @@ class Diaspora } if (($guid != "") && $complete) { - $r = q( - "SELECT `contact-id` FROM `item` WHERE `guid` = '%s' AND `network` IN ('%s', '%s') LIMIT 1", - dbesc($guid), - NETWORK_DFRN, - NETWORK_DIASPORA - ); - if ($r) { + $condition = ['guid' => $guid, 'network' => [NETWORK_DFRN, NETWORK_DIASPORA]]; + $item = dba::selectFirst('item', ['contact-id'], $condition); + if (DBM::is_result($item)) { $ret= []; - $ret["root_handle"] = self::handleFromContact($r[0]["contact-id"]); + $ret["root_handle"] = self::handleFromContact($item["contact-id"]); $ret["root_guid"] = $guid; return $ret; } From 96d8591b95e10fda6dee639d222c3368ec9a0e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Wed, 18 Apr 2018 11:40:16 +0200 Subject: [PATCH 10/24] [TASK] Remove auto_install.php --- auto_install.php | 159 ----------------------------------------------- 1 file changed, 159 deletions(-) delete mode 100644 auto_install.php diff --git a/auto_install.php b/auto_install.php deleted file mode 100644 index bc418d688..000000000 --- a/auto_install.php +++ /dev/null @@ -1,159 +0,0 @@ -config['php_path'])) { - check_php($app->config['php_path'], $checks); - } else { - die(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n"); - } - - echo " NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n"; - - return $checks; -} - -function run_database_check() -{ - global $db_host; - global $db_user; - global $db_pass; - global $db_data; - - $result = array( - 'title' => 'MySQL Connection', - 'required' => true, - 'status' => true, - 'help' => '', - ); - - if (!dba::connect($db_host, $db_user, $db_pass, $db_data, true)) { - $result['status'] = false; - $result['help'] = 'Failed, please check your MySQL settings and credentials.'; - } - - return $result; -} From 1d552b5e66b3ece7e539432d0d2c462708b86c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Wed, 18 Apr 2018 11:43:23 +0200 Subject: [PATCH 11/24] [TASK] Install script: Add installation class --- src/Core/Console/AutomaticInstallation.php | 181 +++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 src/Core/Console/AutomaticInstallation.php diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php new file mode 100644 index 000000000..a847b4a1b --- /dev/null +++ b/src/Core/Console/AutomaticInstallation.php @@ -0,0 +1,181 @@ +output("Initializing setup...\n"); + + $a = get_app(); + $db_host = ''; + $db_user = ''; + $db_pass = ''; + $db_data = ''; + require_once '.htautoinstall.php'; + + $this->output(" Complete!\n\n"); + + // Check basic setup + $this->output("Checking basic setup...\n"); + + $checkResults = []; + $checkResults['basic'] = $this->runBasicChecks($a); + $errorMessage = $this->extractErrors($checkResults['basic']); + + if ($errorMessage !== '') { + die($errorMessage); + } + + $this->output(" Complete!\n\n"); + + // Check database connection + $this->output("Checking database...\n"); + + $checkResults['db'] = array(); + $checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data); + $errorMessage = $this->extractErrors($checkResults['db']); + + if ($errorMessage !== '') { + die($errorMessage); + } + + $this->output(" Complete!\n\n"); + + // Install database + $this->output("Inserting data into database...\n"); + + $checkResults['data'] = load_database(); + + if ($checkResults['data'] !== '') { + die("ERROR: DB Database creation error. Is the DB empty?\n"); + } + + $this->output(" Complete!\n\n"); + + // Copy config file + $this->output("Saving config file...\n"); + if (!copy('.htautoinstall.php', '.htconfig.php')) { + die("ERROR: Saving config file failed. Please copy .htautoinstall.php to .htconfig.php manually.\n"); + } + $this->output(" Complete!\n\n"); + $this->output("\nInstallation is finished\n"); + + return 0; + } + + /** + * @param App $app + * @return array + */ + public function runBasicChecks($app) + { + $checks = []; + + check_funcs($checks); + check_imagik($checks); + check_htconfig($checks); + check_smarty3($checks); + check_keys($checks); + + if (!empty($app->config['php_path'])) { + check_php($app->config['php_path'], $checks); + } else { + die(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n"); + } + + $this->output(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n"); + + return $checks; + } + + /** + * @param $db_host + * @param $db_user + * @param $db_pass + * @param $db_data + * @return array + */ + public function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data) + { + $result = array( + 'title' => 'MySQL Connection', + 'required' => true, + 'status' => true, + 'help' => '', + ); + + + if (!dba::connect($db_host, $db_user, $db_pass, $db_data, true)) { + $result['status'] = false; + $result['help'] = 'Failed, please check your MySQL settings and credentials.'; + } + + return $result; + } + + /** + * @param array $results + * @return string + */ + public function extractErrors($results) + { + $errorMessage = ''; + $allChecksRequired = $this->getOption('a') !== null; + + foreach ($results as $result) { + if (($allChecksRequired || $result['required'] === true) && $result['status'] === false) { + $errorMessage .= "--------\n"; + $errorMessage .= $result['title'] . ': ' . $result['help'] . "\n"; + } + } + + return $errorMessage; + } + + /** + * @param string $text + */ + public function output($text) + { + $debugInfo = $this->getOption('v') !== null; + if ($debugInfo) { + echo $text; + } + } +} From d53e64a583d3cc3ed81ff43095b631a132ea52f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Wed, 18 Apr 2018 11:46:27 +0200 Subject: [PATCH 12/24] [TASK] Install Script: Register installation class --- src/Core/Console.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Core/Console.php b/src/Core/Console.php index a1143ae1d..fa69ad968 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -21,6 +21,7 @@ class Console extends \Asika\SimpleConsole\Console 'extract' => __NAMESPACE__ . '\Console\Extract', 'globalcommunityblock' => __NAMESPACE__ . '\Console\GlobalCommunityBlock', 'globalcommunitysilence' => __NAMESPACE__ . '\Console\GlobalCommunitySilence', + 'install' => __NAMESPACE__ . '\Console\AutomaticInstallation', 'maintenance' => __NAMESPACE__ . '\Console\Maintenance', 'newpassword' => __NAMESPACE__ . '\Console\NewPassword', 'php2po' => __NAMESPACE__ . '\Console\PhpToPo', @@ -42,6 +43,7 @@ Commands: globalcommunityblock Block remote profile from interacting with this node globalcommunitysilence Silence remote profile from global community page help Show help about a command, e.g (bin/console help config) + install Starts automatic installation of friendica based on values from htconfig.php maintenance Set maintenance mode for this node newpassword Set a new password for a given user php2po Generate a messages.po file from a strings.php file From 7b7ca71bf6b96ea45a201b4562d35a51f6ed5cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Wed, 18 Apr 2018 14:20:21 +0200 Subject: [PATCH 13/24] [TASK] Auto install: Rename script command --- src/Core/Console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Console.php b/src/Core/Console.php index fa69ad968..36614ad55 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -21,7 +21,7 @@ class Console extends \Asika\SimpleConsole\Console 'extract' => __NAMESPACE__ . '\Console\Extract', 'globalcommunityblock' => __NAMESPACE__ . '\Console\GlobalCommunityBlock', 'globalcommunitysilence' => __NAMESPACE__ . '\Console\GlobalCommunitySilence', - 'install' => __NAMESPACE__ . '\Console\AutomaticInstallation', + 'autoinstall' => __NAMESPACE__ . '\Console\AutomaticInstallation', 'maintenance' => __NAMESPACE__ . '\Console\Maintenance', 'newpassword' => __NAMESPACE__ . '\Console\NewPassword', 'php2po' => __NAMESPACE__ . '\Console\PhpToPo', From 24626f5fd20d076025e1c49d1dc59580ffca9834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Wed, 18 Apr 2018 14:21:40 +0200 Subject: [PATCH 14/24] [TASK] Auto install: Rename script command --- src/Core/Console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Console.php b/src/Core/Console.php index 36614ad55..82c485179 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -43,7 +43,7 @@ Commands: globalcommunityblock Block remote profile from interacting with this node globalcommunitysilence Silence remote profile from global community page help Show help about a command, e.g (bin/console help config) - install Starts automatic installation of friendica based on values from htconfig.php + autoinstall Starts automatic installation of friendica based on values from htconfig.php maintenance Set maintenance mode for this node newpassword Set a new password for a given user php2po Generate a messages.po file from a strings.php file From 457b86711d47236dcabafdbdf83a9d44ccecf4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Wed, 18 Apr 2018 14:30:42 +0200 Subject: [PATCH 15/24] [TASK] Auto install: Rework class --- src/Core/Console/AutomaticInstallation.php | 66 ++++++++-------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index a847b4a1b..5df99c1e9 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -16,11 +16,7 @@ class AutomaticInstallation extends Console return <<output("Initializing setup...\n"); + $this->out("Initializing setup...\n"); $a = get_app(); $db_host = ''; $db_user = ''; $db_pass = ''; $db_data = ''; - require_once '.htautoinstall.php'; + require_once 'htconfig.php'; - $this->output(" Complete!\n\n"); + $this->out(" Complete!\n\n"); // Check basic setup - $this->output("Checking basic setup...\n"); + $this->out("Checking basic setup...\n"); $checkResults = []; $checkResults['basic'] = $this->runBasicChecks($a); $errorMessage = $this->extractErrors($checkResults['basic']); if ($errorMessage !== '') { - die($errorMessage); + throw new \RuntimeException($errorMessage); } - $this->output(" Complete!\n\n"); + $this->out(" Complete!\n\n"); // Check database connection - $this->output("Checking database...\n"); + $this->out("Checking database...\n"); $checkResults['db'] = array(); $checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data); $errorMessage = $this->extractErrors($checkResults['db']); if ($errorMessage !== '') { - die($errorMessage); + throw new \RuntimeException($errorMessage); } - $this->output(" Complete!\n\n"); + $this->out(" Complete!\n\n"); // Install database - $this->output("Inserting data into database...\n"); + $this->out("Inserting data into database...\n"); $checkResults['data'] = load_database(); if ($checkResults['data'] !== '') { - die("ERROR: DB Database creation error. Is the DB empty?\n"); + throw new \RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n"); } - $this->output(" Complete!\n\n"); + $this->out(" Complete!\n\n"); // Copy config file - $this->output("Saving config file...\n"); - if (!copy('.htautoinstall.php', '.htconfig.php')) { - die("ERROR: Saving config file failed. Please copy .htautoinstall.php to .htconfig.php manually.\n"); + $this->out("Saving config file...\n"); + if (!copy('htconfig.php', '.htconfig.php')) { + throw new \RuntimeException("ERROR: Saving config file failed. Please copy .htautoinstall.php to .htconfig.php manually.\n"); } - $this->output(" Complete!\n\n"); - $this->output("\nInstallation is finished\n"); + $this->out(" Complete!\n\n"); + $this->out("\nInstallation is finished\n"); return 0; } @@ -103,7 +94,7 @@ HELP; * @param App $app * @return array */ - public function runBasicChecks($app) + private function runBasicChecks($app) { $checks = []; @@ -116,10 +107,10 @@ HELP; if (!empty($app->config['php_path'])) { check_php($app->config['php_path'], $checks); } else { - die(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n"); + throw new \RuntimeException(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n"); } - $this->output(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n"); + $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n"); return $checks; } @@ -131,7 +122,7 @@ HELP; * @param $db_data * @return array */ - public function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data) + private function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data) { $result = array( 'title' => 'MySQL Connection', @@ -153,7 +144,7 @@ HELP; * @param array $results * @return string */ - public function extractErrors($results) + private function extractErrors($results) { $errorMessage = ''; $allChecksRequired = $this->getOption('a') !== null; @@ -167,15 +158,4 @@ HELP; return $errorMessage; } - - /** - * @param string $text - */ - public function output($text) - { - $debugInfo = $this->getOption('v') !== null; - if ($debugInfo) { - echo $text; - } - } } From 1017e244cae7cb1cfce46fe0d4fdc43fb117885e Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Wed, 18 Apr 2018 17:52:34 +0200 Subject: [PATCH 16/24] Frio: add template for admin/users --- view/theme/frio/templates/admin/users.tpl | 273 ++++++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 view/theme/frio/templates/admin/users.tpl diff --git a/view/theme/frio/templates/admin/users.tpl b/view/theme/frio/templates/admin/users.tpl new file mode 100644 index 000000000..5ab002573 --- /dev/null +++ b/view/theme/frio/templates/admin/users.tpl @@ -0,0 +1,273 @@ + + + + +
+

{{$title}} - {{$page}}

+
+ +
+ + + + +
+

{{$h_pending}}

+ + {{if $pending}} + + + + {{foreach $th_pending as $th}}{{/foreach}} + + + + + + {{foreach $pending as $u}} + + + + + + + + + + + + {{/foreach}} + +
{{$th}} + + +
{{$u.created}}{{$u.name}}{{$u.email}} + + +
{{$pendingnotetext}}{{$u.note}}
+ + {{else}} +
{{$no_pending}}
+ {{/if}} +
+ + +
+

{{$h_users}}

+ {{if $users}} + + + + + + {{foreach $th_users as $k=>$th}} + {{if $k < 2 || $order_users == $th.1 || ($k==5 && !in_array($order_users,[$th_users.2.1, $th_users.3.1, $th_users.4.1])) }} + + {{/if}} + {{/foreach}} + + + + + + {{foreach $users as $u}} + + + + + {{if $order_users == $th_users.2.1}} + + {{/if}} + + {{if $order_users == $th_users.3.1}} + + {{/if}} + + {{if $order_users == $th_users.4.1}} + + {{/if}} + + {{if !in_array($order_users,[$th_users.2.1, $th_users.3.1, $th_users.4.1]) }} + + {{/if}} + + {{else}} +   + {{/if}} + + + + + + + + {{/foreach}} + +
+ + {{if $order_users == $th.1}} + {{if $order_direction_users == "+"}} + ↓ + {{else}} + ↑ + {{/if}} + {{else}} + ↕ + {{/if}} + {{$th.0}} + + + +
{{$u.name}}{{$u.email}}{{$u.register_date}}{{$u.lastitem_date}}{{$u.page_flags}} {{if $u.is_admin}}({{$siteadmin}}){{/if}} {{if $u.account_expired}}({{$accountexpired}}){{/if}} + {{if $u.is_deletable}} + + +
+ + {{else}} +
NO USERS?!?
+ {{/if}} +
+ + + +
+ + + + + + + {{if $deleted}} +
+

{{$h_deleted}}

+ + + + + {{foreach $th_deleted as $k=>$th}} + {{if in_array($k,[0,1,5])}} + + {{/if}} + {{/foreach}} + + + + {{foreach $deleted as $u}} + + + + + + + {{/foreach}} + +
{{$th}}
{{$u.name}}{{$u.email}}{{$u.deleted}}
+
+{{/if}} + + + + +
+ + +
+

{{$h_newuser}}

+
+ {{include file="field_input.tpl" field=$newusername}} + {{include file="field_input.tpl" field=$newusernickname}} + {{include file="field_input.tpl" field=$newuseremail}} +
+ + From 362654abf06ed2974d2ce5878011ecf1fe05e203 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Wed, 18 Apr 2018 19:44:10 +0200 Subject: [PATCH 17/24] Fix indentation --- view/theme/frio/templates/admin/users.tpl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/view/theme/frio/templates/admin/users.tpl b/view/theme/frio/templates/admin/users.tpl index 5ab002573..f648cb748 100644 --- a/view/theme/frio/templates/admin/users.tpl +++ b/view/theme/frio/templates/admin/users.tpl @@ -1,4 +1,3 @@ -