]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Install.php
Make BaseModule methods dynamic
[friendica.git] / src / Module / Install.php
index 4b0809e1f99b19ad4ed26fff6b7993fa57df2a27..8f872c683e4421cab608df6d6bbb4e093ddf0706 100644 (file)
@@ -1,17 +1,35 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Module;
 
 use Friendica\App;
 use Friendica\BaseModule;
 use Friendica\Core;
-use Friendica\Core\Config\Cache\ConfigCache;
-use Friendica\Core\L10n;
+use Friendica\Core\Config\ValueObject\Cache;
 use Friendica\Core\Renderer;
+use Friendica\Core\Theme;
 use Friendica\DI;
 use Friendica\Network\HTTPException;
 use Friendica\Util\BasePath;
-use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
 class Install extends BaseModule
@@ -47,7 +65,7 @@ class Install extends BaseModule
         */
        private static $installer;
 
-       public static function init(array $parameters = [])
+       public function init()
        {
                $a = DI::app();
 
@@ -76,7 +94,7 @@ class Install extends BaseModule
                self::$currentWizardStep = ($_POST['pass'] ?? '') ?: self::SYSTEM_CHECK;
        }
 
-       public static function post(array $parameters = [])
+       public function post()
        {
                $a           = DI::app();
                $configCache = $a->getConfigCache();
@@ -144,12 +162,22 @@ class Install extends BaseModule
                                }
 
                                self::$installer->installDatabase($configCache->get('system', 'basepath'));
+                       
+                               // install allowed themes to register theme hooks
+                               // this is same as "Reload active theme" in /admin/themes
+                               $allowed_themes = Theme::getAllowedList();
+                               $allowed_themes = array_unique($allowed_themes);
+                               foreach ($allowed_themes as $theme) {
+                                       Theme::uninstall($theme);
+                                       Theme::install($theme);
+                               }
+                               Theme::setAllowedList($allowed_themes);
 
                                break;
                }
        }
 
-       public static function content(array $parameters = [])
+       public function content(): string
        {
                $a           = DI::app();
                $configCache = $a->getConfigCache();
@@ -168,9 +196,13 @@ class Install extends BaseModule
                                $output .= Renderer::replaceMacros($tpl, [
                                        '$title'       => $install_title,
                                        '$pass'        => DI::l10n()->t('System check'),
+                                       '$required'    => DI::l10n()->t('Required'),
+                                       '$requirement_not_satisfied' => DI::l10n()->t('Requirement not satisfied'),
+                                       '$optional_requirement_not_satisfied' => DI::l10n()->t('Optional requirement not satisfied'),
+                                       '$ok'          => DI::l10n()->t('OK'),
                                        '$checks'      => self::$installer->getChecks(),
                                        '$passed'      => $status,
-                                       '$see_install' => DI::l10n()->t('Please see the file "INSTALL.txt".'),
+                                       '$see_install' => DI::l10n()->t('Please see the file "doc/INSTALL.md".'),
                                        '$next'        => DI::l10n()->t('Next'),
                                        '$reload'      => DI::l10n()->t('Check again'),
                                        '$php_path'    => $php_path,
@@ -197,12 +229,12 @@ class Install extends BaseModule
                                                DI::l10n()->t('Host name'),
                                                $configCache->get('config', 'hostname'),
                                                DI::l10n()->t('Overwrite this field in case the determinated hostname isn\'t right, otherweise leave it as is.'),
-                                               'required'],
+                                               DI::l10n()->t('Required')],
                                        '$basepath'   => ['system-basepath',
                                                DI::l10n()->t("Base path to installation"),
                                                $configCache->get('system', 'basepath'),
                                                DI::l10n()->t("If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot."),
-                                               'required'],
+                                               DI::l10n()->t('Required')],
                                        '$urlpath'    => ['system-urlpath',
                                                DI::l10n()->t('Sub path of the URL'),
                                                $configCache->get('system', 'urlpath'),
@@ -221,7 +253,9 @@ class Install extends BaseModule
                                        '$info_01'    => DI::l10n()->t('In order to install Friendica we need to know how to connect to your database.'),
                                        '$info_02'    => DI::l10n()->t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
                                        '$info_03'    => DI::l10n()->t('The database you specify below should already exist. If it does not, please create it before continuing.'),
-                                       'checks'      => self::$installer->getChecks(),
+                                       '$required'   => DI::l10n()->t('Required'),
+                                       '$requirement_not_satisfied' => DI::l10n()->t('Requirement not satisfied'),
+                                       '$checks'     => self::$installer->getChecks(),
                                        '$hostname'   => $configCache->get('config', 'hostname'),
                                        '$ssl_policy' => $configCache->get('system', 'ssl_policy'),
                                        '$basepath'   => $configCache->get('system', 'basepath'),
@@ -230,23 +264,23 @@ class Install extends BaseModule
                                                DI::l10n()->t('Database Server Name'),
                                                $configCache->get('database', 'hostname'),
                                                '',
-                                               'required'],
+                                               DI::l10n()->t('Required')],
                                        '$dbuser'     => ['database-username',
                                                DI::l10n()->t('Database Login Name'),
                                                $configCache->get('database', 'username'),
                                                '',
-                                               'required',
+                                               DI::l10n()->t('Required'),
                                                'autofocus'],
                                        '$dbpass'     => ['database-password',
                                                DI::l10n()->t('Database Login Password'),
                                                $configCache->get('database', 'password'),
                                                DI::l10n()->t("For security reasons the password must not be empty"),
-                                               'required'],
+                                               DI::l10n()->t('Required')],
                                        '$dbdata'     => ['database-database',
                                                DI::l10n()->t('Database Name'),
                                                $configCache->get('database', 'database'),
                                                '',
-                                               'required'],
+                                               DI::l10n()->t('Required')],
                                        '$lbl_10'     => DI::l10n()->t('Please select a default timezone for your website'),
                                        '$php_path'   => $configCache->get('config', 'php_path'),
                                        '$submit'     => DI::l10n()->t('Submit')
@@ -255,11 +289,12 @@ class Install extends BaseModule
 
                        case self::SITE_SETTINGS:
                                /* Installed langs */
-                               $lang_choices = L10n::getAvailableLanguages();
+                               $lang_choices = DI::l10n()->getAvailableLanguages();
 
                                $tpl    = Renderer::getMarkupTemplate('install_settings.tpl');
                                $output .= Renderer::replaceMacros($tpl, [
                                        '$title'      => $install_title,
+                                       '$required'   => DI::l10n()->t('Required'),
                                        '$checks'     => self::$installer->getChecks(),
                                        '$pass'       => DI::l10n()->t('Site settings'),
                                        '$hostname'   => $configCache->get('config', 'hostname'),
@@ -274,7 +309,7 @@ class Install extends BaseModule
                                                DI::l10n()->t('Site administrator email address'),
                                                $configCache->get('config', 'admin_email'),
                                                DI::l10n()->t('Your account email address must match this in order to use the web admin panel.'),
-                                               'required', 'autofocus', 'email'],
+                                               DI::l10n()->t('Required'), 'autofocus', 'email'],
                                        '$timezone'   => Temporal::getTimezoneField('system-default_timezone',
                                                DI::l10n()->t('Please select a default timezone for your website'),
                                                $configCache->get('system', 'default_timezone'),
@@ -300,10 +335,12 @@ class Install extends BaseModule
 
                                $tpl    = Renderer::getMarkupTemplate('install_finished.tpl');
                                $output .= Renderer::replaceMacros($tpl, [
-                                       '$title'  => $install_title,
-                                       '$checks' => self::$installer->getChecks(),
-                                       '$pass'   => DI::l10n()->t('Installation finished'),
-                                       '$text'   => $db_return_text . self::whatNext(),
+                                       '$title'    => $install_title,
+                                       '$required' => DI::l10n()->t('Required'),
+                                       '$requirement_not_satisfied' => DI::l10n()->t('Requirement not satisfied'),
+                                       '$checks'   => self::$installer->getChecks(),
+                                       '$pass'     => DI::l10n()->t('Installation finished'),
+                                       '$text'     => $db_return_text . self::whatNext(),
                                ]);
 
                                break;
@@ -324,7 +361,7 @@ class Install extends BaseModule
                return
                        DI::l10n()->t('<h1>What next</h1>')
                        . "<p>" . DI::l10n()->t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.')
-                       . DI::l10n()->t('Please see the file "INSTALL.txt".')
+                       . DI::l10n()->t('Please see the file "doc/INSTALL.md".')
                        . "</p><p>"
                        . DI::l10n()->t('Go to your new Friendica node <a href="%s/register">registration page</a> and register as new user. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.', $baseurl)
                        . "</p>";
@@ -333,19 +370,17 @@ class Install extends BaseModule
        /**
         * Checks the $_POST settings and updates the config Cache for it
         *
-        * @param ConfigCache $configCache The current config cache
-        * @param array       $post        The $_POST data
-        * @param string      $cat         The category of the setting
-        * @param string      $key         The key of the setting
-        * @param null|string $default     The default value
+        * @param \Friendica\Core\Config\ValueObject\Cache $configCache The current config cache
+        * @param array                                    $post        The $_POST data
+        * @param string                                   $cat         The category of the setting
+        * @param string                                   $key         The key of the setting
+        * @param null|string                              $default     The default value
         */
-       private static function checkSetting(ConfigCache $configCache, array $post, $cat, $key, $default = null)
+       private static function checkSetting(Cache $configCache, array $post, $cat, $key, $default = null)
        {
                $configCache->set($cat, $key,
-                       Strings::escapeTags(
-                               trim(($post[sprintf('%s-%s', $cat, $key)] ?? '') ?:
-                                               ($default ?? $configCache->get($cat, $key))
-                               )
+                       trim(($post[sprintf('%s-%s', $cat, $key)] ?? '') ?:
+                                       ($default ?? $configCache->get($cat, $key))
                        )
                );
        }