From cc7a0aa4fb2d6c8efd5c78df7d68328c9f8d4d32 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 1 Feb 2016 13:55:36 +0100 Subject: [PATCH] [ticket/14492] Use guzzle for submitting data to stats service PHPBB3-14492 --- phpBB/adm/style/acp_help_phpbb.html | 8 +++++ phpBB/includes/acp/acp_help_phpbb.php | 43 ++++++++++++++++++++++++++- phpBB/language/en/acp/common.php | 1 + 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/phpBB/adm/style/acp_help_phpbb.html b/phpBB/adm/style/acp_help_phpbb.html index 347d39af86..cbbe42e8c7 100644 --- a/phpBB/adm/style/acp_help_phpbb.html +++ b/phpBB/adm/style/acp_help_phpbb.html @@ -4,6 +4,7 @@

{L_ACP_HELP_PHPBB}

+

Send statistics

@@ -47,6 +48,13 @@
Enable
+
+

+ +

+ {S_FORM_TOKEN} +
+
diff --git a/phpBB/includes/acp/acp_help_phpbb.php b/phpBB/includes/acp/acp_help_phpbb.php index 2ac90eee48..c981cf79df 100644 --- a/phpBB/includes/acp/acp_help_phpbb.php +++ b/phpBB/includes/acp/acp_help_phpbb.php @@ -25,7 +25,7 @@ class acp_help_phpbb function main($id, $mode) { - global $config, $template, $phpbb_admin_path, $phpbb_root_path, $phpEx; + global $config, $request, $template, $user, $phpbb_admin_path, $phpbb_root_path, $phpEx; if (!class_exists('phpbb_questionnaire_data_collector')) { @@ -37,6 +37,22 @@ class acp_help_phpbb $this->tpl_name = 'acp_help_phpbb'; $this->page_title = 'ACP_HELP_PHPBB'; + $submit = ($request->is_set_post('submit')) ? true : false; + + $form_key = 'acp_help_phpbb'; + add_form_key($form_key); + $error = array(); + + if ($submit && !check_form_key($form_key)) + { + $error[] = $user->lang['FORM_INVALID']; + } + // Do not write values if there is an error + if (sizeof($error)) + { + $submit = false; + } + // generate a unique id if necessary if (!isset($config['questionnaire_unique_id'])) { @@ -55,6 +71,31 @@ class acp_help_phpbb $collector->add_data_provider(new phpbb_questionnaire_system_data_provider()); $collector->add_data_provider(new phpbb_questionnaire_phpbb_data_provider($config)); + if ($submit) + { + $client = new \Guzzle\Http\Client( + $this->u_action, + array( + 'timeout' => 6, + 'connect_timeout' => 6, + ) + ); + + $collect_request = $client->post($collect_url, [], [ + 'systemdata' => $collector->get_data_for_form(), + ]); + + $response = $collect_request->send(); + if ($response->isSuccessful()) + { + trigger_error($user->lang('THANKS_SEND_STATISTICS') . adm_back_link($this->u_action)); + } + else + { + trigger_error($user->lang('FAIL_SEND_STATISTICS') . adm_back_link($this->u_action)); + } + } + $template->assign_vars(array( 'U_COLLECT_STATS' => $collect_url, 'RAW_DATA' => $collector->get_data_for_form(), diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index a233547c7e..592021624b 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -486,6 +486,7 @@ $lang = array_merge($lang, array( 'SEND_STATISTICS_LONG' => 'Send statistical information', 'SHOW_STATISTICS' => 'Show details', 'THANKS_SEND_STATISTICS' => 'Thank you for submitting your information.', + 'FAIL_SEND_STATISTICS' => 'phpBB was unable to send statistics', 'EXPLAIN_ENABLE_VIGLINK' => 'Viglink is a non-invasive third-party service that will monetize existing links posted by users of your forum. When visitors click on those existing links and perform certain actions, such as shopping, the merchants pay VigLink a commission, of which a share is donated to the phpBB project. By agreeing to enable VigLink and donating proceeds to the phpBB project, you are supporting our open source organization and ensuring our continued financial security.

You can change these settings at any time in VigLink settings panel.', ));