From: Hypolite Petovan Date: Mon, 22 Apr 2019 00:46:37 +0000 (-0400) Subject: Move admin/blocklist/contact to src/Module X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=cf885841c8f05055440d3f654f1fbfd4cf6fa102;p=friendica.git Move admin/blocklist/contact to src/Module - Add Module\Admin\ContactBlock\Contact class - Add route for admin/blocklist/contact - Add contact blocklist admin aside menu entry - Move templates/admin/contactblock.tpl to templates/admin/blocklist/contact.tpl in base and frio - Remove admin_page_contactblock and admin_page_contactblock_post from mod/admin.php --- diff --git a/mod/admin.php b/mod/admin.php index 2b9a90b54e..3684e11448 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -114,9 +114,6 @@ function admin_post(App $a) case 'logs': admin_page_logs_post($a); break; - case 'contactblock': - admin_page_contactblock_post($a); - break; case 'blocklist': admin_page_blocklist_post($a); break; @@ -240,9 +237,6 @@ function admin_content(App $a) case 'workerqueue': $o = admin_page_workerqueue($a, false); break; - case 'contactblock': - $o = admin_page_contactblock($a); - break; case 'blocklist': $o = admin_page_blocklist($a); break; @@ -354,88 +348,6 @@ function admin_page_blocklist_post(App $a) return; // NOTREACHED } -/** - * @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) -{ - $contact_url = defaults($_POST, 'contact_url', ''); - $contacts = defaults($_POST, 'contacts', []); - - BaseModule::checkFormSecurityTokenRedirectOnError('/admin/contactblock', 'admin_contactblock'); - - if (!empty($_POST['page_contactblock_block'])) { - $contact_id = Contact::getIdForURL($contact_url); - if ($contact_id) { - Contact::block($contact_id); - notice(L10n::t('The contact has been blocked from the node')); - } else { - notice(L10n::t("Could not find any contact entry for this URL \x28%s\x29", $contact_url)); - } - } - if (!empty($_POST['page_contactblock_unblock'])) { - foreach ($contacts as $uid) { - Contact::unblock($uid); - } - notice(L10n::tt("%s contact unblocked", "%s contacts unblocked", count($contacts))); - } - $a->internalRedirect('admin/contactblock'); - return; // NOTREACHED -} - -/** - * @brief Admin panel for server-wide contact block - * - * @param App $a - * @return string - * @throws \Friendica\Network\HTTPException\InternalServerErrorException - */ -function admin_page_contactblock(App $a) -{ - $condition = ['uid' => 0, 'blocked' => true]; - - $total = DBA::count('contact', $condition); - - $pager = new Pager($a->query_string, 30); - - $statement = DBA::select('contact', [], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]); - - $contacts = DBA::toArray($statement); - - $t = Renderer::getMarkupTemplate('admin/contactblock.tpl'); - $o = Renderer::replaceMacros($t, [ - // strings // - '$title' => L10n::t('Administration'), - '$page' => L10n::t('Remote Contact Blocklist'), - '$description' => L10n::t('This page allows you to prevent any message from a remote contact to reach your node.'), - '$submit' => L10n::t('Block Remote Contact'), - '$select_all' => L10n::t('select all'), - '$select_none' => L10n::t('select none'), - '$block' => L10n::t('Block'), - '$unblock' => L10n::t('Unblock'), - '$no_data' => L10n::t('No remote contact is blocked from this node.'), - - '$h_contacts' => L10n::t('Blocked Remote Contacts'), - '$h_newblock' => L10n::t('Block New Remote Contact'), - '$th_contacts' => [L10n::t('Photo'), L10n::t('Name'), L10n::t('Address'), L10n::t('Profile URL')], - - '$form_security_token' => BaseModule::getFormSecurityToken("admin_contactblock"), - - // values // - '$baseurl' => System::baseUrl(true), - - '$contacts' => $contacts, - '$total_contacts' => L10n::tt('%s total blocked contact', '%s total blocked contacts', $total), - '$paginate' => $pager->renderFull($total), - '$contacturl' => ['contact_url', L10n::t("Profile URL"), '', L10n::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 * diff --git a/src/App/Router.php b/src/App/Router.php index af3f8e717d..71b8ebe7aa 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -124,6 +124,7 @@ class Router $collector->addRoute(['GET', 'POST'], '/addons' , Module\Admin\Addons\Index::class); $collector->addRoute(['GET', 'POST'], '/addons/{addon}' , Module\Admin\Addons\Details::class); + $collector->addRoute(['GET', 'POST'], '/blocklist/contact' , Module\Admin\Blocklist\Contact::class); $collector->addRoute(['GET', 'POST'], '/features' , Module\Admin\Features::class); $collector->addRoute(['GET'] , '/federation' , Module\Admin\Federation::class); diff --git a/src/Module/Admin/Blocklist/Contact.php b/src/Module/Admin/Blocklist/Contact.php new file mode 100644 index 0000000000..69aa0a4738 --- /dev/null +++ b/src/Module/Admin/Blocklist/Contact.php @@ -0,0 +1,89 @@ +internalRedirect('admin/blocklist/contact'); + } + + public static function content() + { + parent::content(); + + $a = self::getApp(); + + $condition = ['uid' => 0, 'blocked' => true]; + + $total = DBA::count('contact', $condition); + + $pager = new Pager($a->query_string, 30); + + $statement = DBA::select('contact', [], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]); + + $contacts = DBA::toArray($statement); + + $t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl'); + $o = Renderer::replaceMacros($t, [ + // strings // + '$title' => L10n::t('Administration'), + '$page' => L10n::t('Remote Contact Blocklist'), + '$description' => L10n::t('This page allows you to prevent any message from a remote contact to reach your node.'), + '$submit' => L10n::t('Block Remote Contact'), + '$select_all' => L10n::t('select all'), + '$select_none' => L10n::t('select none'), + '$block' => L10n::t('Block'), + '$unblock' => L10n::t('Unblock'), + '$no_data' => L10n::t('No remote contact is blocked from this node.'), + + '$h_contacts' => L10n::t('Blocked Remote Contacts'), + '$h_newblock' => L10n::t('Block New Remote Contact'), + '$th_contacts' => [L10n::t('Photo'), L10n::t('Name'), L10n::t('Address'), L10n::t('Profile URL')], + + '$form_security_token' => parent::getFormSecurityToken("admin_contactblock"), + + // values // + '$baseurl' => System::baseUrl(true), + + '$contacts' => $contacts, + '$total_contacts' => L10n::tt('%s total blocked contact', '%s total blocked contacts', $total), + '$paginate' => $pager->renderFull($total), + '$contacturl' => ['contact_url', L10n::t("Profile URL"), '', L10n::t("URL of the remote contact to block.")], + ]); + return $o; + } +} \ No newline at end of file diff --git a/src/Module/BaseAdminModule.php b/src/Module/BaseAdminModule.php index 07f3c07861..31f279bca7 100644 --- a/src/Module/BaseAdminModule.php +++ b/src/Module/BaseAdminModule.php @@ -59,6 +59,9 @@ abstract class BaseAdminModule extends BaseModule 'features' => ['admin/features' , L10n::t('Additional features') , 'features'], 'tos' => ['admin/tos' , L10n::t('Terms of Service') , 'tos'], ]], + 'tools' => [L10n::t('Tools'), [ + 'contactblock' => ['admin/blocklist/contact', L10n::t('Contact Blocklist') , 'contactblock'], + ]], ]; $addons_admin = []; diff --git a/view/templates/admin/blocklist/contact.tpl b/view/templates/admin/blocklist/contact.tpl new file mode 100644 index 0000000000..228ad6903f --- /dev/null +++ b/view/templates/admin/blocklist/contact.tpl @@ -0,0 +1,63 @@ + +
+

{{$title}} - {{$page}}

+

{{$description nofilter}}

+
+ + +

{{$h_contacts}}

+ {{if $contacts}} + + + + + {{foreach $th_contacts as $th}} + + {{/foreach}} + + + + + {{foreach $contacts as $contact}} + + + + + + + + {{/foreach}} + +
+ {{$th}} +
{{$contact.nickname}}{{$contact.name}}{{$contact.addr}}{{$contact.url}}
+

{{$select_all}} | {{$select_none}}

+ {{$paginate nofilter}} +
+ {{else}} +

{{$no_data}}

+ {{/if}} +
+ +

{{$h_newblock}}

+
+ + + + + + + +
{{include file="field_input.tpl" field=$contacturl}}
+
+
+
diff --git a/view/templates/admin/contactblock.tpl b/view/templates/admin/contactblock.tpl deleted file mode 100644 index f454938627..0000000000 --- a/view/templates/admin/contactblock.tpl +++ /dev/null @@ -1,63 +0,0 @@ - -
-

{{$title}} - {{$page}}

-

{{$description nofilter}}

-
- - -

{{$h_contacts}}

- {{if $contacts}} - - - - - {{foreach $th_contacts as $th}} - - {{/foreach}} - - - - - {{foreach $contacts as $contact}} - - - - - - - - {{/foreach}} - -
- {{$th}} -
{{$contact.nickname}}{{$contact.name}}{{$contact.addr}}{{$contact.url}}
-

{{$select_all}} | {{$select_none}}

- {{$paginate nofilter}} -
- {{else}} -

{{$no_data}}

- {{/if}} -
- -

{{$h_newblock}}

-
- - - - - - - -
{{include file="field_input.tpl" field=$contacturl}}
-
-
-
diff --git a/view/theme/frio/templates/admin/blocklist/contact.tpl b/view/theme/frio/templates/admin/blocklist/contact.tpl new file mode 100644 index 0000000000..53fde9aefb --- /dev/null +++ b/view/theme/frio/templates/admin/blocklist/contact.tpl @@ -0,0 +1,105 @@ + + + +
+

{{$title}} - {{$page}}

+

{{$description nofilter}}

+ + {{* We organize the settings in collapsable panel-groups *}} +
+ {{* The form for entering user profile which should be blocked *}} +
+ + +
+
+ + + {{include file="field_input.tpl" field=$contacturl}} + +
+ +
+
+
+
+
+ + {{* The list of blocked user profiles with the possibility to unblock them *}} +
+ + +
+
+ + + {{if $contacts}} + + + + + {{foreach $th_contacts as $th}} + + {{/foreach}} + + + + + {{foreach $contacts as $contact}} + + + + + + + {{/foreach}} + + + + + + + +
+ {{$th}} +
+
+ + +
+
{{$contact.nickname}}{{$contact.name}}{{$contact.url}}
+ {{* Checkbox to select all blocked contacts *}} +
+ + +
+
+ {{$total_contacts}} +
+ +
+
+
+ + {{$paginate nofilter}} + + {{else}} +

{{$no_data}}

+ {{/if}} +
+
+
+
+
diff --git a/view/theme/frio/templates/admin/contactblock.tpl b/view/theme/frio/templates/admin/contactblock.tpl deleted file mode 100644 index 7d187aac8e..0000000000 --- a/view/theme/frio/templates/admin/contactblock.tpl +++ /dev/null @@ -1,105 +0,0 @@ - - - -
-

{{$title}} - {{$page}}

-

{{$description nofilter}}

- - {{* We organize the settings in collapsable panel-groups *}} -
- {{* The form for entering user profile which should be blocked *}} -
- - -
-
- - - {{include file="field_input.tpl" field=$contacturl}} - -
- -
-
-
-
-
- - {{* The list of blocked user profiles with the possibility to unblock them *}} -
- - -
-
- - - {{if $contacts}} - - - - - {{foreach $th_contacts as $th}} - - {{/foreach}} - - - - - {{foreach $contacts as $contact}} - - - - - - - {{/foreach}} - - - - - - - -
- {{$th}} -
-
- - -
-
{{$contact.nickname}}{{$contact.name}}{{$contact.url}}
- {{* Checkbox to select all blocked contacts *}} -
- - -
-
- {{$total_contacts}} -
- -
-
-
- - {{$paginate nofilter}} - - {{else}} -

{{$no_data}}

- {{/if}} -
-
-
-
-