]> git.mxchange.org Git - friendica.git/blobdiff - mod/admin.php
Merge pull request #4005 from zeroadam/Features-#3878
[friendica.git] / mod / admin.php
index de981bb9003a4652ec39c719278bf7eb95696079..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;
@@ -179,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'),
@@ -247,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;
@@ -359,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
  *
@@ -1193,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),
@@ -1380,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']);
@@ -2207,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) {
@@ -2252,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();