name = 'Tests'; $this->defaultTask = 'listing'; $this->testClass = new TestClass(); } private function getNumberOfElementsToDisplay() { $selectValue = Security::getVar('int', 'acyc_element_per_page', $this->config->get('listing_element_page', self::DEFAULT_ELEMENTS_PER_PAGE)); $this->config->save(['listing_element_page' => $selectValue]); return $selectValue; } public function listing() { $this->layout = 'listing'; $data = [ 'per_page' => $this->getNumberOfElementsToDisplay(), 'search' => $this->getVarFiltersListing('string', 'search', ''), 'page' => $this->getVarFiltersListing('int', self::PAGINATION_NAME, 1), 'current_status' => $this->getVarFiltersListing('string', 'status', ''), 'ordering' => $this->getVarFiltersListing('string', 'tests_ordering', 'date'), 'orderingSortOrder' => $this->getVarFiltersListing('string', 'tests_ordering_sort_order', 'desc'), ]; $this->prepareBlockReasons($data); $this->prepareTestsElements($data); $this->preparePagination($data); $this->prepareTexts($data); $this->prepareStatus($data); $this->displayInfoInProgress(); $this->breadcrumb[__('Tests', 'acychecker')] = Url::completeLink('tests'); $this->display($data); } private function prepareBlockReasons(&$data) { $tooltipService = new TooltipService(); $data['tooltipService'] = $tooltipService; $data['block_reasons'] = [ 'domain_not_exists' => __('Domain doesn\'t exist', 'acychecker'), 'invalid_smtp' => __('Invalid SMTP', 'acychecker'), 'free_domain' => __('Free', 'acychecker'), 'accept_all' => __('Accept all', 'acychecker'), 'disposable' => __('Disposable', 'acychecker'), 'role_based' => __('Role email', 'acychecker'), ]; } private function prepareTestsElements(&$data) { $data['offset'] = ($data['page'] - 1) * $data['per_page']; $results = $this->testClass->getMatchingElements($data); $data = array_merge($data, $results); } private function preparePagination(&$data) { $data['pagination'] = new PaginationService($data['page'], $data['total'], $data['per_page'], self::PAGINATION_NAME); } private function prepareTexts(&$data) { $data['test_result_texts'] = [ 'not_existing' => __('Not existing', 'acychecker'), 'risky' => __('Risky', 'acychecker'), 'possible' => __('Possible', 'acychecker'), 'valid' => __('Valid', 'acychecker'), ]; } private function prepareStatus(&$data) { $data['status'] = [ 'all' => [ 'text' => __('All', 'acychecker'), 'number' => $this->testClass->getStepNumber('all', $data), ], 'finished' => [ 'text' => __('Finished', 'acychecker'), 'number' => $this->testClass->getStepNumber('finished', $data), ], 'in_progress' => [ 'text' => __('In progress', 'acychecker'), 'number' => $this->testClass->getStepNumber('in_progress', $data), ], 'pending' => [ 'text' => __('Pending', 'acychecker'), 'number' => $this->testClass->getStepNumber('pending', $data), ], 'failed' => [ 'text' => __('Failed', 'acychecker'), 'number' => $this->testClass->getStepNumber('failed', $data), ], ]; $testClass = new TestClass(); $data['statuses'] = $testClass->getStatusLabels(); } public function displayInfoInProgress() { $tests = $this->config->get('urls_results_batch', '[]'); $tests = json_decode($tests, true); if (!empty($tests)) { $nbBatchs = count($tests); Message::enqueueMessage(sprintf(__('You currently have tests in progress (composed of %s batches). Results will be available soon.', 'acychecker'), $nbBatchs), 'info'); } } public function doexport() { $separator = '","'; $eol = "\r\n"; $before = '"'; $after = '"'; error_reporting(E_ALL); @ini_set('display_errors', 1); $columns = Database::loadResultArray('SHOW COLUMNS FROM #__acyc_test'); $testClass = new TestClass(); $elements = $testClass->getAll(); $stepLabels = $testClass->getStatusLabels(); if (empty($elements)) { // Remove noheader in url $completeLink = rtrim(Url::completeLink('tests', false, true), '&noheader=1'); Message::enqueueMessage(__('No data found to export', 'acychecker'), 'warning'); Router::redirect($completeLink); } // We replace the raw_results by the email suggestions if any $rawPos = array_search('raw_result', $columns); $columns = array_replace($columns, [$rawPos => ApiService::API_TEST_KEY_DOMAIN_SUGGESTIONS]); // We don't export the batch_id column $batchPos = array_search('batch_id', $columns); unset($columns[$batchPos]); $lines = []; $lines[] = $before.implode($separator, $columns).$after; foreach ($elements as $oneElement) { $line = []; $oneElement->current_step = $stepLabels[$oneElement->current_step]; foreach ($columns as $oneColumn) { if ($oneColumn === ApiService::API_TEST_KEY_DOMAIN_SUGGESTIONS && !empty($oneElement->raw_result)) { $rawResult = json_decode($oneElement->raw_result, true); if (empty($rawResult[ApiService::API_TEST_KEY_DOMAIN_SUGGESTIONS])) { $oneElement->$oneColumn = ''; } else { $oneElement->$oneColumn = implode(',', $rawResult[ApiService::API_TEST_KEY_DOMAIN_SUGGESTIONS]); } } $line[] = htmlspecialchars($oneElement->$oneColumn, ENT_QUOTES); } $lines[] = $before.implode($separator, $line).$after; } $final = implode($eol, $lines); @ob_get_clean(); $filename = 'export_acychecker_'.date('Y-m-d'); HttpService::setDownloadHeaders($filename); echo $final; exit; } public function doExportBlockedUser() { $separator = '","'; $eol = "\r\n"; $before = '"'; $after = '"'; error_reporting(E_ALL); @ini_set('display_errors', 1); $columns = Database::loadResultArray('SHOW COLUMNS FROM #__acyc_block_history'); $blockUserClass = new BlockUserClass(); $elements = $blockUserClass->getAll(); if (empty($elements)) { // Remove noheader in url $completeLink = rtrim(Url::completeLink('tests', false, true), '&noheader=1'); Message::enqueueMessage(__('No data found to export', 'acychecker'), 'warning'); Router::redirect($completeLink); } $lines = []; $lines[] = $before.implode($separator, $columns).$after; foreach ($elements as $oneElement) { $line = []; foreach ($columns as $oneColumn) { $line[] = htmlspecialchars($oneElement->$oneColumn, ENT_QUOTES); } $lines[] = $before.implode($separator, $line).$after; } $final = implode($eol, $lines); @ob_get_clean(); $filename = 'export_acychecker_blocked_users'.date('Y-m-d'); HttpService::setDownloadHeaders($filename); echo $final; exit; } public function clearTested() { $testClass = new TestClass(); $testClass->deleteAllTested(); $this->listing(); } public function cancelPending() { $testClass = new TestClass(); $testClass->deletePending(); $this->listing(); } }