]> git.mxchange.org Git - friendica.git/blobdiff - mod/admin.php
Merge pull request #4005 from zeroadam/Features-#3878
[friendica.git] / mod / admin.php
index cdcd688f2dd2236feac7731ff8c3e2860080089c..29e10bda8301088be9b97f74c196008b69d3b69a 100644 (file)
@@ -1,16 +1,17 @@
 <?php
-
 /**
  * @file mod/admin.php
  *
  * @brief Friendica admin
  */
 use Friendica\App;
+use Friendica\Content\Feature;
 use Friendica\Core\System;
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Model\User;
+use Friendica\Object\Contact;
 
 require_once 'include/enotify.php';
 require_once 'include/text.php';
@@ -31,8 +32,6 @@ require_once 'include/items.php';
  */
 function admin_post(App $a)
 {
-
-
        if (!is_site_admin()) {
                return;
        }
@@ -117,6 +116,9 @@ function admin_post(App $a)
                        case 'dbsync':
                                admin_page_dbsync_post($a);
                                break;
+                       case 'contactblock':
+                               admin_page_contactblock_post($a);
+                               break;
                        case 'blocklist':
                                admin_page_blocklist_post($a);
                                break;
@@ -149,7 +151,6 @@ function admin_post(App $a)
  */
 function admin_content(App $a)
 {
-
        if (!is_site_admin()) {
                return login(false);
        }
@@ -164,7 +165,7 @@ function admin_content(App $a)
        //      apc_delete($toDelete);
        //}
        // Header stuff
-       $a->page['htmlhead'] .= replace_macros(get_markup_template('admin_settings_head.tpl'), array());
+       $a->page['htmlhead'] .= replace_macros(get_markup_template('admin/settings_head.tpl'), array());
 
        /*
         * Side bar links
@@ -180,6 +181,7 @@ function admin_content(App $a)
                'features'     => array("admin/features/"    , t("Additional features")  , "features"),
                'dbsync'       => array("admin/dbsync/"      , t('DB updates')           , "dbsync"),
                'queue'        => array("admin/queue/"       , t('Inspect Queue')        , "queue"),
+               'contactblock' => array("admin/contactblock/", t('Contact Blocklist')    , "contactblock"),
                'blocklist'    => array("admin/blocklist/"   , t('Server Blocklist')     , "blocklist"),
                'federation'   => array("admin/federation/"  , t('Federation Statistics'), "federation"),
                'deleteitem'   => array("admin/deleteitem/"  , t('Delete Item')          , 'deleteitem'),
@@ -201,7 +203,7 @@ function admin_content(App $a)
        $aside_tools['diagnostics_probe'] = array('probe/', t('probe address'), 'probe');
        $aside_tools['diagnostics_webfinger'] = array('webfinger/', t('check webfinger'), 'webfinger');
 
-       $t = get_markup_template("admin_aside.tpl");
+       $t = get_markup_template('admin/aside.tpl');
        $a->page['aside'] .= replace_macros($t, array(
                '$admin' => $aside_tools,
                '$subpages' => $aside_sub,
@@ -213,11 +215,7 @@ function admin_content(App $a)
                '$admurl' => "admin/"
        ));
 
-
-
-       /*
-        * Page content
-        */
+       // Page content
        $o = '';
        // urls
        if ($a->argc > 1) {
@@ -252,6 +250,9 @@ function admin_content(App $a)
                        case 'federation':
                                $o = admin_page_federation($a);
                                break;
+                       case 'contactblock':
+                               $o = admin_page_contactblock($a);
+                               break;
                        case 'blocklist':
                                $o = admin_page_blocklist($a);
                                break;
@@ -298,7 +299,7 @@ function admin_page_blocklist(App $a)
                        );
                }
        }
-       $t = get_markup_template("admin_blocklist.tpl");
+       $t = get_markup_template('admin/blocklist.tpl');
        return replace_macros($t, array(
                '$title' => t('Administration'),
                '$page' => t('Server Blocklist'),
@@ -364,6 +365,86 @@ function admin_page_blocklist_post(App $a)
        return; // NOTREACHED
 }
 
+/**
+ * @brief Process data send by the contact block admin page
+ *
+ * @param App $a
+ */
+function admin_page_contactblock_post(App $a)
+{
+       $contact_url = x($_POST, 'contact_url') ? $_POST['contact_url'] : '';
+       $contacts    = x($_POST, 'contacts')    ? $_POST['contacts']    : [];
+
+       check_form_security_token_redirectOnErr('/admin/contactblock', 'admin_contactblock');
+
+       if (x($_POST, 'page_contactblock_block')) {
+               $contact_id = Contact::getIdForURL($contact_url, 0);
+               if ($contact_id) {
+                       Contact::block($contact_id);
+                       notice(t('The contact has been blocked from the node'));
+               } else {
+                       notice(t('Could not find any contact entry for this URL (%s)', $contact_url));
+               }
+       }
+       if (x($_POST, 'page_contactblock_unblock')) {
+               foreach ($contacts as $uid) {
+                       Contact::unblock($uid);
+               }
+               notice(tt("%s contact unblocked", "%s contacts unblocked", count($contacts)));
+       }
+       goaway('admin/contactblock');
+       return; // NOTREACHED
+}
+
+/**
+ * @brief Admin panel for server-wide contact block
+ *
+ * @param App $a
+ * @return string
+ */
+function admin_page_contactblock(App $a)
+{
+       $condition = ['uid' => 0, 'blocked' => true];
+
+       $total = dba::count('contact', $condition);
+
+       $a->set_pager_total($total);
+       $a->set_pager_itemspage(30);
+
+       $statement = dba::select('contact', [], $condition, ['limit' => [$a->pager['start'], $a->pager['itemspage']]]);
+
+       $contacts = dba::inArray($statement);
+
+       $t = get_markup_template('admin/contactblock.tpl');
+       $o = replace_macros($t, array(
+               // strings //
+               '$title'       => t('Administration'),
+               '$page'        => t('Remote Contact Blocklist'),
+               '$description' => t('This page allows you to prevent any message from a remote contact to reach your node.'),
+               '$submit'      => t('Block Remote Contact'),
+               '$select_all'  => t('select all'),
+               '$select_none' => t('select none'),
+               '$block'       => t('Block'),
+               '$unblock'     => t('Unblock'),
+               '$no_data'     => t('No remote contact is blocked from this node.'),
+
+               '$h_contacts'  => t('Blocked Remote Contacts'),
+               '$h_newblock'  => t('Block New Remote Contact'),
+               '$th_contacts' => [t('Photo'), t('Name'), t('Address'), t('Profile URL')],
+
+               '$form_security_token' => get_form_security_token("admin_contactblock"),
+
+               // values //
+               '$baseurl'    => System::baseUrl(true),
+
+               '$contacts'   => $contacts,
+               '$total_contacts' => tt('%s total blocked contact', '%s total blocked contacts', $total),
+               '$paginate'   => paginate($a),
+               '$contacturl' => ['contact_url', t("Profile URL"), '', t("URL of the remote contact to block.")],
+       ));
+       return $o;
+}
+
 /**
  * @brief Subpage where the admin can delete an item from their node given the GUID
  *
@@ -376,7 +457,7 @@ function admin_page_blocklist_post(App $a)
  */
 function admin_page_deleteitem(App $a)
 {
-       $t = get_markup_template("admin_deleteitem.tpl");
+       $t = get_markup_template('admin/deleteitem.tpl');
 
        return replace_macros($t, array(
                '$title' => t('Administration'),
@@ -557,7 +638,7 @@ function admin_page_federation(App $a)
        $hint = t('The <em>Auto Discovered Contact Directory</em> feature is not enabled, it will improve the data displayed here.');
 
        // load the template, replace the macros and return the page content
-       $t = get_markup_template("admin_federation.tpl");
+       $t = get_markup_template('admin/federation.tpl');
        return replace_macros($t, array(
                '$title' => t('Administration'),
                '$page' => t('Federation Statistics'),
@@ -592,7 +673,7 @@ function admin_page_queue(App $a)
                        WHERE `c`.`id` = `q`.`cid`
                        ORDER BY `q`.`cid`, `q`.`created`;");
 
-       $t = get_markup_template("admin_queue.tpl");
+       $t = get_markup_template('admin/queue.tpl');
        return replace_macros($t, array(
                '$title' => t('Administration'),
                '$page' => t('Inspect Queue'),
@@ -689,7 +770,7 @@ function admin_page_summary(App $a)
        $queues = array('label' => t('Message queues'), 'queue' => $queue, 'workerq' => $workerqueue);
 
 
-       $t = get_markup_template("admin_summary.tpl");
+       $t = get_markup_template('admin/summary.tpl');
        return replace_macros($t, array(
                '$title' => t('Administration'),
                '$page' => t('Summary'),
@@ -1176,7 +1257,7 @@ function admin_page_site(App $a)
                $optimize_max_tablesize = 100;
        }
 
-       $t = get_markup_template("admin_site.tpl");
+       $t = get_markup_template('admin/site.tpl');
        return replace_macros($t, array(
                '$title' => t('Administration'),
                '$page' => t('Site'),
@@ -1198,7 +1279,7 @@ function admin_page_site(App $a)
                '$banner'               => array('banner', t("Banner/Logo"), $banner, ""),
                '$shortcut_icon'        => array('shortcut_icon', t("Shortcut icon"), Config::get('system','shortcut_icon'),  t("Link to an icon that will be used for browsers.")),
                '$touch_icon'           => array('touch_icon', t("Touch icon"), Config::get('system','touch_icon'),  t("Link to an icon that will be used for tablets and mobiles.")),
-               '$info'                 => array('info', t('Additional Info'), $info, sprintf(t('For public servers: you can add additional information here that will be listed at %s/siteinfo.'), get_server())),
+               '$info'                 => array('info', t('Additional Info'), $info, sprintf(t('For public servers: you can add additional information here that will be listed at %s/servers.'), get_server())),
                '$language'             => array('language', t("System language"), Config::get('system','language'), "", $lang_choices),
                '$theme'                => array('theme', t("System theme"), Config::get('system','theme'), t("Default system theme - may be over-ridden by user profiles - <a href='#' id='cnftheme'>change theme settings</a>"), $theme_choices),
                '$theme_mobile'         => array('theme_mobile', t("Mobile system theme"), Config::get('system', 'mobile-theme', '---'), t("Theme for mobile devices"), $theme_choices_mobile),
@@ -1385,9 +1466,7 @@ function admin_page_users_post(App $a)
        check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
 
        if (!($nu_name === "") && !($nu_email === "") && !($nu_nickname === "")) {
-               require_once 'include/user.php';
-
-               $result = create_user(array('username' => $nu_name, 'email' => $nu_email,
+               $result = User::create(array('username' => $nu_name, 'email' => $nu_email,
                        'nickname' => $nu_nickname, 'verified' => 1, 'language' => $nu_language));
                if (!$result['success']) {
                        notice($result['message']);
@@ -1605,7 +1684,7 @@ function admin_page_users(App $a)
        $th_users = array_map(null, array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account')), $valid_orders
        );
 
-       $t = get_markup_template("admin_users.tpl");
+       $t = get_markup_template('admin/users.tpl');
        $o = replace_macros($t, array(
                // strings //
                '$title' => t('Administration'),
@@ -1724,7 +1803,7 @@ function admin_page_plugins(App $a)
                        $func($a, $admin_form);
                }
 
-               $t = get_markup_template("admin_plugins_details.tpl");
+               $t = get_markup_template('admin/plugins_details.tpl');
 
                return replace_macros($t, array(
                        '$title' => t('Administration'),
@@ -1785,7 +1864,7 @@ function admin_page_plugins(App $a)
                }
        }
 
-       $t = get_markup_template("admin_plugins.tpl");
+       $t = get_markup_template('admin/plugins.tpl');
        return replace_macros($t, array(
                '$title' => t('Administration'),
                '$page' => t('Plugins'),
@@ -2001,7 +2080,7 @@ function admin_page_themes(App $a)
                        $screenshot = null;
                }
 
-               $t = get_markup_template("admin_plugins_details.tpl");
+               $t = get_markup_template('admin/plugins_details.tpl');
                return replace_macros($t, array(
                        '$title' => t('Administration'),
                        '$page' => t('Themes'),
@@ -2050,7 +2129,7 @@ function admin_page_themes(App $a)
                }
        }
 
-       $t = get_markup_template("admin_plugins.tpl");
+       $t = get_markup_template('admin/plugins.tpl');
        return replace_macros($t, array(
                '$title'               => t('Administration'),
                '$page'                => t('Themes'),
@@ -2123,7 +2202,7 @@ function admin_page_logs(App $a)
                $phplogenabled = t('PHP log currently disabled.');
        }
 
-       $t = get_markup_template("admin_logs.tpl");
+       $t = get_markup_template('admin/logs.tpl');
 
        return replace_macros($t, array(
                '$title' => t('Administration'),
@@ -2164,7 +2243,7 @@ function admin_page_logs(App $a)
  */
 function admin_page_viewlogs(App $a)
 {
-       $t = get_markup_template("admin_viewlogs.tpl");
+       $t = get_markup_template('admin/viewlogs.tpl');
        $f = Config::get('system', 'logfile');
        $data = '';
 
@@ -2212,7 +2291,7 @@ function admin_page_features_post(App $a)
        logger('postvars: ' . print_r($_POST, true), LOGGER_DATA);
 
        $arr = array();
-       $features = get_features(false);
+       $features = Feature::get(false);
 
        foreach ($features as $fname => $fdata) {
                foreach (array_slice($fdata, 1) as $f) {
@@ -2257,7 +2336,7 @@ function admin_page_features(App $a)
 {
        if ((argc() > 1) && (argv(1) === 'features')) {
                $arr = array();
-               $features = get_features(false);
+               $features = Feature::get(false);
 
                foreach ($features as $fname => $fdata) {
                        $arr[$fname] = array();
@@ -2271,7 +2350,7 @@ function admin_page_features(App $a)
                        }
                }
 
-               $tpl = get_markup_template("admin_settings_features.tpl");
+               $tpl = get_markup_template('admin/settings_features.tpl');
                $o .= replace_macros($tpl, array(
                        '$form_security_token' => get_form_security_token("admin_manage_features"),
                        '$title' => t('Manage Additional Features'),