code style & install-403 fix

This commit is contained in:
Philipp Holzer 2019-04-14 14:05:48 +02:00
parent d579d9e1d0
commit 58c9566c3d
No known key found for this signature in database
GPG Key ID: 517BE60E2CE5C8A5
6 changed files with 138 additions and 133 deletions

View File

@ -139,7 +139,7 @@ class App
} }
/** /**
* Returns the current config of this nodde * Returns the current config of this node
* *
* @return Configuration * @return Configuration
*/ */

View File

@ -40,7 +40,7 @@ Options
-P|--dbpass <password> The password of the mysql/mariadb database login (env MYSQL_PASSWORD) -P|--dbpass <password> The password of the mysql/mariadb database login (env MYSQL_PASSWORD)
-U|--url <url> The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL) -U|--url <url> The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL)
-B|--phppath <php_path> The path of the PHP binary (env FRIENDICA_PHP_PATH) -B|--phppath <php_path> The path of the PHP binary (env FRIENDICA_PHP_PATH)
-b|--basepath <base_path> The basepath of Friendica(env FRIENDICA_BASE_PATH) -b|--basepath <base_path> The basepath of Friendica (env FRIENDICA_BASE_PATH)
-t|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ) -t|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
-L|--lang <language> The language of Friendica (env FRIENDICA_LANG) -L|--lang <language> The language of Friendica (env FRIENDICA_LANG)

View File

@ -249,8 +249,9 @@ class Installer
$help .= L10n::t("If you don't have a command line version of PHP installed on your server, you will not be able to run the background processing. See <a href='https://github.com/friendica/friendica/blob/master/doc/Install.md#set-up-the-worker'>'Setup the worker'</a>") . EOL; $help .= L10n::t("If you don't have a command line version of PHP installed on your server, you will not be able to run the background processing. See <a href='https://github.com/friendica/friendica/blob/master/doc/Install.md#set-up-the-worker'>'Setup the worker'</a>") . EOL;
$help .= EOL . EOL; $help .= EOL . EOL;
$tpl = Renderer::getMarkupTemplate('field_input.tpl'); $tpl = Renderer::getMarkupTemplate('field_input.tpl');
/// @todo Separate backend Installer class and presentation layer/view
$help .= Renderer::replaceMacros($tpl, [ $help .= Renderer::replaceMacros($tpl, [
'$field' => ['config.php_path', L10n::t('PHP executable path'), $phppath, L10n::t('Enter full path to php executable. You can leave this blank to continue the installation.')], '$field' => ['config-php_path', L10n::t('PHP executable path'), $phppath, L10n::t('Enter full path to php executable. You can leave this blank to continue the installation.')],
]); ]);
$phppath = ""; $phppath = "";
} }

View File

@ -15,17 +15,17 @@ use Friendica\Render\ITemplateEngine;
*/ */
class Renderer extends BaseObject class Renderer extends BaseObject
{ {
/** /**
* @brief An array of registered template engines ('name'=>'class name') * @brief An array of registered template engines ('name'=>'class name')
*/ */
public static $template_engines = []; public static $template_engines = [];
/** /**
* @brief An array of instanced template engines ('name'=>'instance') * @brief An array of instanced template engines ('name'=>'instance')
*/ */
public static $template_engine_instance = []; public static $template_engine_instance = [];
/** /**
* @brief An array for all theme-controllable parameters * @brief An array for all theme-controllable parameters
* *
* Mostly unimplemented yet. Only options 'template_engine' and * Mostly unimplemented yet. Only options 'template_engine' and
@ -39,15 +39,15 @@ class Renderer extends BaseObject
'stylesheet' => '', 'stylesheet' => '',
'template_engine' => 'smarty3', 'template_engine' => 'smarty3',
]; ];
private static $ldelim = [ private static $ldelim = [
'internal' => '', 'internal' => '',
'smarty3' => '{{' 'smarty3' => '{{'
]; ];
private static $rdelim = [ private static $rdelim = [
'internal' => '', 'internal' => '',
'smarty3' => '}}' 'smarty3' => '}}'
]; ];
/** /**
* @brief This is our template processor * @brief This is our template processor
@ -59,28 +59,28 @@ class Renderer extends BaseObject
* @return string substituted string * @return string substituted string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function replaceMacros($s, $vars, $overwriteURL = true) public static function replaceMacros($s, $vars, $overwriteURL = true)
{ {
$stamp1 = microtime(true); $stamp1 = microtime(true);
$a = self::getApp(); $a = self::getApp();
// pass $baseurl to all templates // pass $baseurl to all templates
if ($overwriteURL) { if ($overwriteURL) {
$vars['$baseurl'] = System::baseUrl(); $vars['$baseurl'] = System::baseUrl();
} }
$t = self::getTemplateEngine(); $t = self::getTemplateEngine();
try { try {
$output = $t->replaceMacros($s, $vars); $output = $t->replaceMacros($s, $vars);
} catch (Exception $e) { } catch (Exception $e) {
echo "<pre><b>" . __FUNCTION__ . "</b>: " . $e->getMessage() . "</pre>"; echo "<pre><b>" . __FUNCTION__ . "</b>: " . $e->getMessage() . "</pre>";
exit(); exit();
} }
$a->getProfiler()->saveTimestamp($stamp1, "rendering", System::callstack()); $a->getProfiler()->saveTimestamp($stamp1, "rendering", System::callstack());
return $output; return $output;
} }
/** /**
* @brief Load a given template $s * @brief Load a given template $s
@ -91,35 +91,35 @@ class Renderer extends BaseObject
* @return string template. * @return string template.
* @throws Exception * @throws Exception
*/ */
public static function getMarkupTemplate($s, $root = '') public static function getMarkupTemplate($s, $root = '')
{ {
$stamp1 = microtime(true); $stamp1 = microtime(true);
$a = self::getApp(); $a = self::getApp();
$t = self::getTemplateEngine(); $t = self::getTemplateEngine();
try { try {
$template = $t->getTemplateFile($s, $root); $template = $t->getTemplateFile($s, $root);
} catch (Exception $e) { } catch (Exception $e) {
echo "<pre><b>" . __FUNCTION__ . "</b>: " . $e->getMessage() . "</pre>"; echo "<pre><b>" . __FUNCTION__ . "</b>: " . $e->getMessage() . "</pre>";
exit(); exit();
} }
$a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack());
return $template; return $template;
} }
/** /**
* @brief Register template engine class * @brief Register template engine class
* *
* @param string $class * @param string $class
*/ */
public static function registerTemplateEngine($class) public static function registerTemplateEngine($class)
{ {
$v = get_class_vars($class); $v = get_class_vars($class);
if (!empty($v['name'])) if (!empty($v['name']))
{ {
$name = $v['name']; $name = $v['name'];
self::$template_engines[$name] = $class; self::$template_engines[$name] = $class;
} else { } else {
@ -153,9 +153,9 @@ class Renderer extends BaseObject
echo "template engine <tt>$template_engine</tt> is not registered!\n"; echo "template engine <tt>$template_engine</tt> is not registered!\n";
exit(); exit();
} }
/** /**
* @brief Returns the active template engine. * @brief Returns the active template engine.
* *
* @return string the active template engine * @return string the active template engine
@ -175,7 +175,7 @@ class Renderer extends BaseObject
self::$theme['template_engine'] = $engine; self::$theme['template_engine'] = $engine;
} }
/** /**
* Gets the right delimiter for a template engine * Gets the right delimiter for a template engine
* *
* Currently: * Currently:

View File

@ -28,7 +28,7 @@ class Install extends BaseModule
*/ */
const DATABASE_CONFIG = 3; const DATABASE_CONFIG = 3;
/** /**
* Step four - Adapat site settings * Step four - Adapt site settings
*/ */
const SITE_SETTINGS = 4; const SITE_SETTINGS = 4;
/** /**
@ -50,6 +50,10 @@ class Install extends BaseModule
{ {
$a = self::getApp(); $a = self::getApp();
if (!$a->getMode()->isInstall()) {
Core\System::httpExit(403);
}
// route: install/testrwrite // route: install/testrwrite
// $baseurl/install/testrwrite to test if rewrite in .htaccess is working // $baseurl/install/testrwrite to test if rewrite in .htaccess is working
if ($a->getArgumentValue(1, '') == 'testrewrite') { if ($a->getArgumentValue(1, '') == 'testrewrite') {
@ -160,15 +164,15 @@ class Install extends BaseModule
$tpl = Renderer::getMarkupTemplate('install_checks.tpl'); $tpl = Renderer::getMarkupTemplate('install_checks.tpl');
$output .= Renderer::replaceMacros($tpl, [ $output .= Renderer::replaceMacros($tpl, [
'$title' => $install_title, '$title' => $install_title,
'$pass' => L10n::t('System check'), '$pass' => L10n::t('System check'),
'$checks' => self::$installer->getChecks(), '$checks' => self::$installer->getChecks(),
'$passed' => $status, '$passed' => $status,
'$see_install' => L10n::t('Please see the file "INSTALL.txt".'), '$see_install' => L10n::t('Please see the file "INSTALL.txt".'),
'$next' => L10n::t('Next'), '$next' => L10n::t('Next'),
'$reload' => L10n::t('Check again'), '$reload' => L10n::t('Check again'),
'$php_path' => $php_path, '$php_path' => $php_path,
'$baseurl' => $a->getBaseURL() '$baseurl' => $a->getBaseURL()
]); ]);
break; break;
@ -184,25 +188,25 @@ class Install extends BaseModule
'$title' => $install_title, '$title' => $install_title,
'$pass' => L10n::t('Base settings'), '$pass' => L10n::t('Base settings'),
'$ssl_policy' => ['system-ssl_policy', '$ssl_policy' => ['system-ssl_policy',
L10n::t("SSL link policy"), L10n::t("SSL link policy"),
$configCache->get('system', 'ssl_policy'), $configCache->get('system', 'ssl_policy'),
L10n::t("Determines whether generated links should be forced to use SSL"), L10n::t("Determines whether generated links should be forced to use SSL"),
$ssl_choices], $ssl_choices],
'$hostname' => ['config-hostname', '$hostname' => ['config-hostname',
L10n::t('Host name'), L10n::t('Host name'),
$configCache->get('config', 'hostname'), $configCache->get('config', 'hostname'),
L10n::t('Overwrite this field in case the determinated hostname isn\'t right, otherweise leave it as is.'), L10n::t('Overwrite this field in case the determinated hostname isn\'t right, otherweise leave it as is.'),
'required'], 'required'],
'$basepath' => ['system-basepath', '$basepath' => ['system-basepath',
L10n::t("Base path to installation"), L10n::t("Base path to installation"),
$configCache->get('system', 'basepath'), $configCache->get('system', 'basepath'),
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."), 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'], 'required'],
'$urlpath' => ['system-urlpath', '$urlpath' => ['system-urlpath',
L10n::t('Sub path of the URL'), L10n::t('Sub path of the URL'),
$configCache->get('system', 'urlpath'), $configCache->get('system', 'urlpath'),
L10n::t('Overwrite this field in case the sub path determination isn\'t right, otherwise leave it as is. Leaving this field blank means the installation is at the base URL without sub path.'), L10n::t('Overwrite this field in case the sub path determination isn\'t right, otherwise leave it as is. Leaving this field blank means the installation is at the base URL without sub path.'),
''], ''],
'$baseurl' => $a->getBaseURL(), '$baseurl' => $a->getBaseURL(),
'$php_path' => $configCache->get('config', 'php_path'), '$php_path' => $configCache->get('config', 'php_path'),
'$submit' => L10n::t('Submit'), '$submit' => L10n::t('Submit'),
@ -212,41 +216,41 @@ class Install extends BaseModule
case self::DATABASE_CONFIG: case self::DATABASE_CONFIG:
$tpl = Renderer::getMarkupTemplate('install_db.tpl'); $tpl = Renderer::getMarkupTemplate('install_db.tpl');
$output .= Renderer::replaceMacros($tpl, [ $output .= Renderer::replaceMacros($tpl, [
'$title' => $install_title, '$title' => $install_title,
'$pass' => L10n::t('Database connection'), '$pass' => L10n::t('Database connection'),
'$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'), '$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'),
'$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'), '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
'$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'), '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'),
'checks' => self::$installer->getChecks(), 'checks' => self::$installer->getChecks(),
'$hostname' => $configCache->get('config', 'hostname'), '$hostname' => $configCache->get('config', 'hostname'),
'$ssl_policy' => $configCache->get('system', 'ssl_policy'), '$ssl_policy' => $configCache->get('system', 'ssl_policy'),
'$basepath' => $configCache->get('system', 'basepath'), '$basepath' => $configCache->get('system', 'basepath'),
'$urlpath' => $configCache->get('system', 'urlpath'), '$urlpath' => $configCache->get('system', 'urlpath'),
'$dbhost' => ['database-hostname', '$dbhost' => ['database-hostname',
L10n::t('Database Server Name'), L10n::t('Database Server Name'),
$configCache->get('database', 'hostname'), $configCache->get('database', 'hostname'),
'', '',
'required'], 'required'],
'$dbuser' => ['database-username', '$dbuser ' => ['database-username',
L10n::t('Database Login Name'), L10n::t('Database Login Name'),
$configCache->get('database', 'username'), $configCache->get('database', 'username'),
'', '',
'required', 'required',
'autofocus'], 'autofocus'],
'$dbpass' => ['database-password', '$dbpass' => ['database-password',
L10n::t('Database Login Password'), L10n::t('Database Login Password'),
$configCache->get('database', 'password'), $configCache->get('database', 'password'),
L10n::t("For security reasons the password must not be empty"), L10n::t("For security reasons the password must not be empty"),
'required'], 'required'],
'$dbdata' => ['database-database', '$dbdata' => ['database-database',
L10n::t('Database Name'), L10n::t('Database Name'),
$configCache->get('database', 'database'), $configCache->get('database', 'database'),
'', '',
'required'], 'required'],
'$lbl_10' => L10n::t('Please select a default timezone for your website'), '$lbl_10' => L10n::t('Please select a default timezone for your website'),
'$baseurl' => $a->getBaseURL(), '$baseurl' => $a->getBaseURL(),
'$php_path' => $configCache->get('config', 'php_path'), '$php_path' => $configCache->get('config', 'php_path'),
'$submit' => L10n::t('Submit') '$submit' => L10n::t('Submit')
]); ]);
break; break;
@ -256,34 +260,34 @@ class Install extends BaseModule
$tpl = Renderer::getMarkupTemplate('install_settings.tpl'); $tpl = Renderer::getMarkupTemplate('install_settings.tpl');
$output .= Renderer::replaceMacros($tpl, [ $output .= Renderer::replaceMacros($tpl, [
'$title' => $install_title, '$title' => $install_title,
'$checks' => self::$installer->getChecks(), '$checks' => self::$installer->getChecks(),
'$pass' => L10n::t('Site settings'), '$pass' => L10n::t('Site settings'),
'$hostname' => $configCache->get('config', 'hostname'), '$hostname' => $configCache->get('config', 'hostname'),
'$ssl_policy' => $configCache->get('system', 'ssl_policy'), '$ssl_policy' => $configCache->get('system', 'ssl_policy'),
'$basepath' => $configCache->get('system', 'basepath'), '$basepath' => $configCache->get('system', 'basepath'),
'$urlpath' => $configCache->get('system', 'urlpath'), '$urlpath' => $configCache->get('system', 'urlpath'),
'$dbhost' => $configCache->get('database', 'hostname'), '$dbhost' => $configCache->get('database', 'hostname'),
'$dbuser' => $configCache->get('database', 'username'), '$dbuser' => $configCache->get('database', 'username'),
'$dbpass' => $configCache->get('database', 'password'), '$dbpass' => $configCache->get('database', 'password'),
'$dbdata' => $configCache->get('database', 'database'), '$dbdata' => $configCache->get('database', 'database'),
'$adminmail' => ['config-admin_email', '$adminmail' => ['config-admin_email',
L10n::t('Site administrator email address'), L10n::t('Site administrator email address'),
$configCache->get('config', 'admin_email'), $configCache->get('config', 'admin_email'),
L10n::t('Your account email address must match this in order to use the web admin panel.'), L10n::t('Your account email address must match this in order to use the web admin panel.'),
'required', 'autofocus', 'email'], 'required', 'autofocus', 'email'],
'$timezone' => Temporal::getTimezoneField('system-default_timezone', '$timezone' => Temporal::getTimezoneField('system-default_timezone',
L10n::t('Please select a default timezone for your website'), L10n::t('Please select a default timezone for your website'),
$configCache->get('system', 'default_timezone'), $configCache->get('system', 'default_timezone'),
''), ''),
'$language' => ['system-language', '$language' => ['system-language',
L10n::t('System Language:'), L10n::t('System Language:'),
$configCache->get('system', 'language'), $configCache->get('system', 'language'),
L10n::t('Set the default language for your Friendica installation interface and to send emails.'), L10n::t('Set the default language for your Friendica installation interface and to send emails.'),
$lang_choices], $lang_choices],
'$baseurl' => $a->getBaseURL(), '$baseurl' => $a->getBaseURL(),
'$php_path' => $configCache->get('config', 'php_path'), '$php_path' => $configCache->get('config', 'php_path'),
'$submit' => L10n::t('Submit') '$submit' => L10n::t('Submit')
]); ]);
break; break;

View File

@ -607,7 +607,7 @@ Options
-P|--dbpass <password> The password of the mysql/mariadb database login (env MYSQL_PASSWORD) -P|--dbpass <password> The password of the mysql/mariadb database login (env MYSQL_PASSWORD)
-U|--url <url> The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL) -U|--url <url> The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL)
-B|--phppath <php_path> The path of the PHP binary (env FRIENDICA_PHP_PATH) -B|--phppath <php_path> The path of the PHP binary (env FRIENDICA_PHP_PATH)
-b|--basepath <base_path> The basepath of Friendica(env FRIENDICA_BASE_PATH) -b|--basepath <base_path> The basepath of Friendica (env FRIENDICA_BASE_PATH)
-t|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ) -t|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
-L|--lang <language> The language of Friendica (env FRIENDICA_LANG) -L|--lang <language> The language of Friendica (env FRIENDICA_LANG)