]> git.mxchange.org Git - friendica.git/blobdiff - mod/admin.php
BBCode - fixed syntax error
[friendica.git] / mod / admin.php
index c0ad281d3b5e3a1ee9998751734d35e2103a7d7b..cc2256b73dd37ba36585f1cb78c4a16e0fa0e963 100644 (file)
@@ -19,12 +19,14 @@ use Friendica\Core\System;
 use Friendica\Core\Theme;
 use Friendica\Core\Update;
 use Friendica\Core\Worker;
+use Friendica\Core\StorageManager;
 use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\Register;
 use Friendica\Model\User;
+use Friendica\Module;
 use Friendica\Module\Login;
 use Friendica\Module\Tos;
 use Friendica\Util\Arrays;
@@ -32,6 +34,24 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
+use Psr\Log\LogLevel;
+
+/**
+ * Sets the current theme for theme settings pages.
+ *
+ * This needs to be done before the post() or content() methods are called.
+ *
+ * @param App $a
+ */
+function admin_init(App $a)
+{
+       if ($a->argc > 2 && $a->argv[1] == 'themes') {
+               $theme = $a->argv[2];
+               if (is_file("view/theme/$theme/config.php")) {
+                       $a->setCurrentTheme($theme);
+               }
+       }
+}
 
 /**
  * @brief Process send data from the admin panels subpages
@@ -44,7 +64,8 @@ use Friendica\Util\Temporal;
  * return the HTML for the pages of the admin panel.
  *
  * @param App $a
- *
+ * @throws ImagickException
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_post(App $a)
 {
@@ -89,15 +110,8 @@ function admin_post(App $a)
 
                                $theme = $a->argv[2];
                                if (is_file("view/theme/$theme/config.php")) {
-                                       $a->setCurrentTheme($theme);
-
-                                       require_once "view/theme/$theme/theme.php";
                                        require_once "view/theme/$theme/config.php";
 
-                                       $init = $theme . '_init';
-                                       if (function_exists($init)) {
-                                               $init($a);
-                                       }
                                        if (function_exists('theme_admin_post')) {
                                                theme_admin_post($a);
                                        }
@@ -150,6 +164,7 @@ function admin_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_content(App $a)
 {
@@ -290,8 +305,7 @@ function admin_content(App $a)
 
        if ($a->isAjax()) {
                echo $o;
-               killme();
-               return '';
+               exit();
        } else {
                return $o;
        }
@@ -302,6 +316,7 @@ function admin_content(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_tos(App $a)
 {
@@ -324,6 +339,7 @@ function admin_page_tos(App $a)
  * @brief Process send data from Admin TOS Page
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_tos_post(App $a)
 {
@@ -356,6 +372,7 @@ function admin_page_tos_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_blocklist(App $a)
 {
@@ -396,6 +413,7 @@ function admin_page_blocklist(App $a)
  * @brief Process send data from Admin Blocklist Page
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_blocklist_post(App $a)
 {
@@ -440,6 +458,8 @@ function admin_page_blocklist_post(App $a)
  * @brief Process data send by the contact block admin page
  *
  * @param App $a
+ * @throws ImagickException
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_contactblock_post(App $a)
 {
@@ -472,6 +492,7 @@ function admin_page_contactblock_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_contactblock(App $a)
 {
@@ -524,6 +545,7 @@ function admin_page_contactblock(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_deleteitem(App $a)
 {
@@ -548,6 +570,7 @@ function admin_page_deleteitem(App $a)
  * URLs like the full /display URL to make the process more easy for the admin.
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_deleteitem_post(App $a)
 {
@@ -587,6 +610,7 @@ function admin_page_deleteitem_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_federation(App $a)
 {
@@ -773,6 +797,7 @@ function admin_page_federation(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_queue(App $a)
 {
@@ -815,7 +840,9 @@ function admin_page_queue(App $a)
  * The returned string holds the content of the page.
  *
  * @param App $a
+ * @param     $deferred
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_workerqueue(App $a, $deferred)
 {
@@ -865,6 +892,7 @@ function admin_page_workerqueue(App $a, $deferred)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_summary(App $a)
 {
@@ -983,6 +1011,7 @@ function admin_page_summary(App $a)
  * @brief Process send data from Admin Site Page
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_site_post(App $a)
 {
@@ -1161,6 +1190,43 @@ function admin_page_site_post(App $a)
        $relay_user_tags   = !empty($_POST['relay_user_tags']);
        $active_panel      = (!empty($_POST['active_panel'])      ? "#" . Strings::escapeTags(trim($_POST['active_panel'])) : '');
 
+       /**
+        * @var $storagebackend \Friendica\Model\Storage\IStorage
+        */
+       $storagebackend    = Strings::escapeTags(trim(defaults($_POST, 'storagebackend', '')));
+       StorageManager::setBackend($storagebackend);
+
+       // save storage backend form
+       if (!is_null($storagebackend) && $storagebackend != "") {
+               $storage_opts = $storagebackend::getOptions();
+               $storage_form_prefix=preg_replace('|[^a-zA-Z0-9]|' ,'', $storagebackend);
+               $storage_opts_data = [];
+               foreach($storage_opts as $name => $info) {
+                       $fieldname = $storage_form_prefix . '_' . $name;
+                       switch ($info[0]) { // type
+                               case 'checkbox':
+                               case 'yesno':
+                                       $value = !empty($_POST[$fieldname]);
+                                       break;
+                               default:
+                                       $value = defaults($_POST, $fieldname, '');
+                       }
+                       $storage_opts_data[$name] = $value;
+               }
+               unset($name);
+               unset($info);
+       
+               $storage_form_errors = $storagebackend::saveOptions($storage_opts_data);
+               if (count($storage_form_errors)) {
+                       foreach($storage_form_errors as $name => $err) {
+                               notice('Storage backend, ' . $storage_opts[$name][1] . ': ' . $err);
+                       }
+                       $a->internalRedirect('admin/site' . $active_panel);
+               }
+       }
+
+       
+
        // Has the directory url changed? If yes, then resubmit the existing profiles there
        if ($global_directory != Config::get('system', 'directory') && ($global_directory != '')) {
                Config::set('system', 'directory', $global_directory);
@@ -1234,7 +1300,7 @@ function admin_page_site_post(App $a)
                Config::set('system', 'banner', $banner);
        }
 
-       if ($info == "") {
+       if (empty($info)) {
                Config::delete('config', 'info');
        } else {
                Config::set('config', 'info', $info);
@@ -1353,6 +1419,7 @@ function admin_page_site_post(App $a)
  *
  * @param  App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_site(App $a)
 {
@@ -1444,9 +1511,9 @@ function admin_page_site(App $a)
 
        /* Register policy */
        $register_choices = [
-               REGISTER_CLOSED => L10n::t("Closed"),
-               REGISTER_APPROVE => L10n::t("Requires approval"),
-               REGISTER_OPEN => L10n::t("Open")
+               Module\Register::CLOSED => L10n::t("Closed"),
+               Module\Register::APPROVE => L10n::t("Requires approval"),
+               Module\Register::OPEN => L10n::t("Open")
        ];
 
        $ssl_choices = [
@@ -1472,6 +1539,36 @@ function admin_page_site(App $a)
                $optimize_max_tablesize = -1;
        }
 
+       /* storage backend */
+       $storage_backends = StorageManager::listBackends();
+       /**
+        * @var $storage_current_backend \Friendica\Model\Storage\IStorage
+        */
+       $storage_current_backend = StorageManager::getBackend();
+
+       $storage_backends_choices = [
+               '' => L10n::t('None')
+       ];
+       foreach($storage_backends as $name=>$class) {
+               $storage_backends_choices[$class] = $name;
+       }
+       unset($storage_backends);
+
+       // build storage config form,
+       $storage_form_prefix=preg_replace('|[^a-zA-Z0-9]|' ,'', $storage_current_backend);
+       
+       $storage_form = [];
+       if (!is_null($storage_current_backend) && $storage_current_backend != "") {
+               foreach($storage_current_backend::getOptions() as $name => $info) {
+                       $type = $info[0];
+                       $info[0] = $storage_form_prefix . '_' . $name;
+                       $info['type'] = $type;
+                       $info['field'] = 'field_' . $type . '.tpl';
+                       $storage_form[$name] = $info;
+               }
+       }
+
+
        $t = Renderer::getMarkupTemplate('admin/site.tpl');
        return Renderer::replaceMacros($t, [
                '$title'             => L10n::t('Administration'),
@@ -1505,6 +1602,9 @@ function admin_page_site(App $a)
                '$force_ssl'        => ['force_ssl', L10n::t("Force SSL"), Config::get('system', 'force_ssl'), L10n::t("Force all Non-SSL requests to SSL - Attention: on some systems it could lead to endless loops.")],
                '$hide_help'        => ['hide_help', L10n::t("Hide help entry from navigation menu"), Config::get('system', 'hide_help'), L10n::t("Hides the menu entry for the Help pages from the navigation menu. You can still access it calling /help directly.")],
                '$singleuser'       => ['singleuser', L10n::t("Single user instance"), Config::get('system', 'singleuser', '---'), L10n::t("Make this instance multi-user or single-user for the named user"), $user_names],
+
+               '$storagebackend'   => ['storagebackend', L10n::t("File storage backend"), $storage_current_backend, L10n::t('Backend used to store uploaded files data'), $storage_backends_choices],
+               '$storageform'      => $storage_form,
                '$maximagesize'     => ['maximagesize', L10n::t("Maximum image size"), Config::get('system', 'maximagesize'), L10n::t("Maximum size in bytes of uploaded images. Default is 0, which means no limits.")],
                '$maximagelength'   => ['maximagelength', L10n::t("Maximum image length"), Config::get('system', 'max_image_length'), L10n::t("Maximum length in pixels of the longest side of uploaded images. Default is -1, which means no limits.")],
                '$jpegimagequality' => ['jpegimagequality', L10n::t("JPEG image quality"), Config::get('system', 'jpeg_quality'), L10n::t("Uploaded JPEGS will be saved at this quality setting [0-100]. Default is 100, which is full quality.")],
@@ -1603,7 +1703,8 @@ function admin_page_site(App $a)
  *
  * @param App $a
  * @return string
- * */
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
 function admin_page_dbsync(App $a)
 {
        $o = '';
@@ -1693,6 +1794,7 @@ function admin_page_dbsync(App $a)
  * @brief Process data send by Users admin page
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_users_post(App $a)
 {
@@ -1752,7 +1854,7 @@ function admin_page_users_post(App $a)
                        Thank you and welcome to %4$s.'));
 
                $preamble = sprintf($preamble, $user['username'], Config::get('config', 'sitename'));
-               $body = sprintf($body, System::baseUrl(), $user['email'], $result['password'], Config::get('config', 'sitename'));
+               $body = sprintf($body, System::baseUrl(), $user['nickname'], $result['password'], Config::get('config', 'sitename'));
 
                notification([
                        'type'     => SYSTEM_EMAIL,
@@ -1810,6 +1912,7 @@ function admin_page_users_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_users(App $a)
 {
@@ -1887,17 +1990,18 @@ function admin_page_users(App $a)
        $adminlist = explode(",", str_replace(" ", "", Config::get('config', 'admin_email')));
        $_setup_users = function ($e) use ($adminlist) {
                $page_types = [
-                       Contact::PAGE_NORMAL    => L10n::t('Normal Account Page'),
-                       Contact::PAGE_SOAPBOX   => L10n::t('Soapbox Page'),
-                       Contact::PAGE_COMMUNITY => L10n::t('Public Forum'),
-                       Contact::PAGE_FREELOVE  => L10n::t('Automatic Friend Page'),
-                       Contact::PAGE_PRVGROUP  => L10n::t('Private Forum')
+                       User::PAGE_FLAGS_NORMAL    => L10n::t('Normal Account Page'),
+                       User::PAGE_FLAGS_SOAPBOX   => L10n::t('Soapbox Page'),
+                       User::PAGE_FLAGS_COMMUNITY => L10n::t('Public Forum'),
+                       User::PAGE_FLAGS_FREELOVE  => L10n::t('Automatic Friend Page'),
+                       User::PAGE_FLAGS_PRVGROUP  => L10n::t('Private Forum')
                ];
                $account_types = [
-                       Contact::ACCOUNT_TYPE_PERSON       => L10n::t('Personal Page'),
-                       Contact::ACCOUNT_TYPE_ORGANISATION => L10n::t('Organisation Page'),
-                       Contact::ACCOUNT_TYPE_NEWS         => L10n::t('News Page'),
-                       Contact::ACCOUNT_TYPE_COMMUNITY    => L10n::t('Community Forum')
+                       User::ACCOUNT_TYPE_PERSON       => L10n::t('Personal Page'),
+                       User::ACCOUNT_TYPE_ORGANISATION => L10n::t('Organisation Page'),
+                       User::ACCOUNT_TYPE_NEWS         => L10n::t('News Page'),
+                       User::ACCOUNT_TYPE_COMMUNITY    => L10n::t('Community Forum'),
+                       User::ACCOUNT_TYPE_RELAY        => L10n::t('Relay'),
                ];
 
                $e['page_flags_raw'] = $e['page-flags'];
@@ -2008,6 +2112,7 @@ function admin_page_users(App $a)
  * @param App   $a
  * @param array $addons_admin A list of admin addon names
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_addons(App $a, array $addons_admin)
 {
@@ -2213,6 +2318,7 @@ function rebuild_theme_table($themes)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_themes(App $a)
 {
@@ -2306,16 +2412,8 @@ function admin_page_themes(App $a)
 
                $admin_form = '';
                if (is_file("view/theme/$theme/config.php")) {
-                       $a->setCurrentTheme($theme);
-
-                       require_once "view/theme/$theme/theme.php";
                        require_once "view/theme/$theme/config.php";
 
-                       $init = $theme . "_init";
-                       if (function_exists($init)) {
-                               $init($a);
-                       }
-
                        if (function_exists('theme_admin')) {
                                $admin_form = theme_admin($a);
                        }
@@ -2391,6 +2489,7 @@ function admin_page_themes(App $a)
  * @brief Prosesses data send by Logs admin page
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_logs_post(App $a)
 {
@@ -2399,7 +2498,7 @@ function admin_page_logs_post(App $a)
 
                $logfile   = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : '');
                $debugging = !empty($_POST['debugging']);
-               $loglevel  = (!empty($_POST['loglevel']) ? intval(trim($_POST['loglevel'])) : 0);
+               $loglevel  = defaults($_POST, 'loglevel', LogLevel::ERROR);
 
                Config::set('system', 'logfile', $logfile);
                Config::set('system', 'debugging', $debugging);
@@ -2426,16 +2525,16 @@ function admin_page_logs_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_logs(App $a)
 {
        $log_choices = [
-               Logger::WARNING => 'Warning',
-               Logger::INFO    => 'Info',
-               Logger::TRACE   => 'Trace',
-               Logger::DEBUG   => 'Debug',
-               Logger::DATA    => 'Data',
-               Logger::ALL     => 'All'
+               LogLevel::ERROR   => 'Error',
+               LogLevel::WARNING => 'Warning',
+               LogLevel::NOTICE  => 'Notice',
+               LogLevel::INFO    => 'Info',
+               LogLevel::DEBUG   => 'Debug',
        ];
 
        if (ini_get('log_errors')) {
@@ -2482,6 +2581,7 @@ function admin_page_logs(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_viewlogs(App $a)
 {
@@ -2525,6 +2625,7 @@ function admin_page_viewlogs(App $a)
  * @brief Prosesses data send by the features admin page
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_features_post(App $a)
 {
@@ -2572,6 +2673,7 @@ function admin_page_features_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_features(App $a)
 {