diff --git a/phpmyfaq/admin/header.php b/phpmyfaq/admin/header.php index 0edcc56f40..c04de149a9 100644 --- a/phpmyfaq/admin/header.php +++ b/phpmyfaq/admin/header.php @@ -124,7 +124,8 @@ $secLevelEntries['statistics'] .= $adminHelper->addMenuEntry( PermissionType::STATISTICS_VIEWLOGS->value, 'searchstats', - 'msgAdminElasticsearchStats' + 'msgAdminElasticsearchStats', + 'statistics/search' ); $secLevelEntries['statistics'] .= $adminHelper->addMenuEntry('reports', 'reports', 'ad_menu_reports'); diff --git a/phpmyfaq/admin/index.php b/phpmyfaq/admin/index.php index c5b56a87e7..b31aa37049 100755 --- a/phpmyfaq/admin/index.php +++ b/phpmyfaq/admin/index.php @@ -314,11 +314,6 @@ case 'glossary': require 'glossary.php'; break; - // functions for session administration - case 'truncatesearchterms': - case 'searchstats': - require 'statistics.search.php'; - break; // Reports case 'reportview': case 'reports': diff --git a/phpmyfaq/admin/statistics.search.php b/phpmyfaq/admin/statistics.search.php deleted file mode 100644 index b98f4ecdf1..0000000000 --- a/phpmyfaq/admin/statistics.search.php +++ /dev/null @@ -1,95 +0,0 @@ - - * @author Thorsten Rinne - * @copyright 2003-2024 phpMyFAQ Team - * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 - * @link https://www.phpmyfaq.de - * @since 2003-03-30 - */ - -use phpMyFAQ\Configuration; -use phpMyFAQ\Enums\PermissionType; -use phpMyFAQ\Filter; -use phpMyFAQ\Pagination; -use phpMyFAQ\Search; -use phpMyFAQ\Session\Token; -use phpMyFAQ\Template\Extensions\LanguageCodeTwigExtension; -use phpMyFAQ\Template\TwigWrapper; -use phpMyFAQ\Translation; -use phpMyFAQ\User\CurrentUser; -use Symfony\Component\HttpFoundation\Request; - -if (!defined('IS_VALID_PHPMYFAQ')) { - http_response_code(400); - exit(); -} - -$faqConfig = Configuration::getConfigurationInstance(); -$user = CurrentUser::getCurrentUser($faqConfig); - -$request = Request::createFromGlobals(); - -if ($user->perm->hasPermission($user->getUserId(), PermissionType::STATISTICS_VIEWLOGS->value)) { - $perPage = 10; - $pages = Filter::filterVar($request->query->get('pages'), FILTER_VALIDATE_INT); - $page = Filter::filterVar($request->query->get('page'), FILTER_VALIDATE_INT, 1); - - $search = new Search($faqConfig); - - $twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates'); - $twig->addExtension(new LanguageCodeTwigExtension()); - $template = $twig->loadTemplate('@admin/statistics/search.twig'); - - $searchesCount = $search->getSearchesCount(); - $searchesList = $search->getMostPopularSearches($searchesCount + 1, true); - - if (is_null($pages)) { - $pages = round(((is_countable($searchesList) ? count($searchesList) : 0) + ($perPage / 3)) / $perPage, 0); - } - - $start = ($page - 1) * $perPage; - $end = $start + $perPage; - - $baseUrl = sprintf( - '%sadmin/?action=searchstats&page=%d', - $faqConfig->getDefaultUrl(), - $page - ); - - // Pagination options - $options = [ - 'baseUrl' => $request->getUri(), - 'total' => is_countable($searchesList) ? count($searchesList) : 0, - 'perPage' => $perPage, - 'pageParamName' => 'page', - ]; - $pagination = new Pagination($options); - - $templateVars = [ - 'msgAdminElasticsearchStats' => Translation::get('msgAdminElasticsearchStats'), - 'csrfToken' => Token::getInstance($container->get('session'))->getTokenString('truncate-search-terms'), - 'ad_searchterm_del' => Translation::get('ad_searchterm_del'), - 'ad_searchstats_search_term' => Translation::get('ad_searchstats_search_term'), - 'ad_searchstats_search_term_count' => Translation::get('ad_searchstats_search_term_count'), - 'ad_searchstats_search_term_lang' => Translation::get('ad_searchstats_search_term_lang'), - 'ad_searchstats_search_term_percentage' => Translation::get('ad_searchstats_search_term_percentage'), - 'pagination' => $pagination->render(), - 'searchesCount' => $searchesCount, - 'searchesList' => $searchesList, - 'csrfTokenDelete' => Token::getInstance($container->get('session'))->getTokenString('delete-searchterm'), - 'ad_news_delete' => Translation::get('ad_news_delete'), - ]; - - echo $template->render($templateVars); -} else { - require __DIR__ . '/no-permission.php'; -} diff --git a/phpmyfaq/assets/templates/admin/statistics/search.twig b/phpmyfaq/assets/templates/admin/statistics/search.twig index b6e0e45f07..f5eb3323f6 100644 --- a/phpmyfaq/assets/templates/admin/statistics/search.twig +++ b/phpmyfaq/assets/templates/admin/statistics/search.twig @@ -1,36 +1,39 @@ -
-

- - {{ msgAdminElasticsearchStats }} -

-
-
- +{% extends '@admin/index.twig' %} + +{% block content %} +
+

+ + {{ msgAdminElasticsearchStats }} +

+
+
+ +
-
-
-
- - - - - - - - - - - - - - - - +
+
+
{{ ad_searchstats_search_term }}{{ ad_searchstats_search_term_count }}{{ ad_searchstats_search_term_lang }}{{ ad_searchstats_search_term_percentage }} 
{{ pagination | raw }}
+ + + + + + + + + + + + + + + {% for searchItem in searchesList %} {% set num = searchItem.number / searchesCount * 100 %} @@ -50,7 +53,8 @@ {% endfor %} - -
{{ ad_searchstats_search_term }}{{ ad_searchstats_search_term_count }}{{ ad_searchstats_search_term_lang }}{{ ad_searchstats_search_term_percentage }} 
{{ pagination | raw }}
+ + +
-
+{% endblock %} diff --git a/phpmyfaq/src/admin-routes.php b/phpmyfaq/src/admin-routes.php index 2a774a0f33..82015bc520 100644 --- a/phpmyfaq/src/admin-routes.php +++ b/phpmyfaq/src/admin-routes.php @@ -27,6 +27,7 @@ use phpMyFAQ\Controller\Administration\PasswordChangeController; use phpMyFAQ\Controller\Administration\RatingController; use phpMyFAQ\Controller\Administration\SessionKeepAliveController; +use phpMyFAQ\Controller\Administration\StatisticsSearchController; use phpMyFAQ\Controller\Administration\StatisticsSessionsController; use phpMyFAQ\Controller\Administration\StopWordsController; use phpMyFAQ\Controller\Administration\SystemInformationController; @@ -158,6 +159,11 @@ 'controller' => [RatingController::class, 'index'], 'methods' => 'GET' ], + 'admin.statistics.search' => [ + 'path' => '/statistics/search', + 'controller' => [StatisticsSearchController::class, 'index'], + 'methods' => 'GET' + ], 'admin.statistics.sessions' => [ 'path' => '/statistics/sessions', 'controller' => [StatisticsSessionsController::class, 'index'], diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Administration/AbstractAdministrationController.php b/phpmyfaq/src/phpMyFAQ/Controller/Administration/AbstractAdministrationController.php index 9bbf5bf3e7..2ae8efcd92 100644 --- a/phpmyfaq/src/phpMyFAQ/Controller/Administration/AbstractAdministrationController.php +++ b/phpmyfaq/src/phpMyFAQ/Controller/Administration/AbstractAdministrationController.php @@ -140,7 +140,8 @@ protected function getHeader(Request $request): array $secLevelEntries['statistics'] .= $adminHelper->addMenuEntry( PermissionType::STATISTICS_VIEWLOGS->value, 'searchstats', - 'msgAdminElasticsearchStats' + 'msgAdminElasticsearchStats', + 'statistics/search' ); $secLevelEntries['statistics'] .= $adminHelper->addMenuEntry('reports', 'reports', 'ad_menu_reports'); @@ -269,7 +270,9 @@ protected function getHeader(Request $request): array case 'admin.statistics.admin-log': case 'admin.statistics.ratings': case 'admin.statistics.sessions': - case 'admin.statistics.session': + case 'admin.statistics.session.day': + case 'admin.statistics.session.id': + case 'admin.statistics.search': $statisticsPage = true; break; case 'admin.export': diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Administration/AdminLogController.php b/phpmyfaq/src/phpMyFAQ/Controller/Administration/AdminLogController.php index d2cb80adac..487b022525 100644 --- a/phpmyfaq/src/phpMyFAQ/Controller/Administration/AdminLogController.php +++ b/phpmyfaq/src/phpMyFAQ/Controller/Administration/AdminLogController.php @@ -35,11 +35,9 @@ public function index(Request $request): Response $itemsPerPage = 15; $page = Filter::filterVar($request->get('page'), FILTER_VALIDATE_INT, 1); - $baseUrl = sprintf('./statistics/admin-log?page=%d', $page); - // Pagination options $options = [ - 'baseUrl' => $baseUrl, + 'baseUrl' => $request->getUri(), 'total' => $adminLog->getNumberOfEntries(), 'perPage' => $itemsPerPage, 'pageParamName' => 'page', @@ -48,9 +46,6 @@ public function index(Request $request): Response $loggingData = $adminLog->getAll(); - $totalItems = count($loggingData); - $totalPages = ceil($totalItems / $itemsPerPage); - $offset = ($page - 1) * $itemsPerPage; $currentItems = array_slice($loggingData, $offset, $itemsPerPage); diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Administration/StatisticsSearchController.php b/phpmyfaq/src/phpMyFAQ/Controller/Administration/StatisticsSearchController.php new file mode 100644 index 0000000000..1a76503def --- /dev/null +++ b/phpmyfaq/src/phpMyFAQ/Controller/Administration/StatisticsSearchController.php @@ -0,0 +1,69 @@ +userHasPermission(PermissionType::STATISTICS_VIEWLOGS); + + $perPage = 10; + + $search = $this->container->get('phpmyfaq.search'); + $session = $this->container->get('session'); + + $searchesCount = $search->getSearchesCount(); + $searchesList = $search->getMostPopularSearches($searchesCount + 1, true); + + // Pagination options + $options = [ + 'baseUrl' => $request->getUri(), + 'total' => is_countable($searchesList) ? count($searchesList) : 0, + 'perPage' => $perPage, + 'pageParamName' => 'page', + ]; + $pagination = new Pagination($options); + + $this->addExtension(new LanguageCodeTwigExtension()); + return $this->render( + '@admin/statistics/search.twig', + [ + ... $this->getHeader($request), + ... $this->getFooter(), + 'msgAdminElasticsearchStats' => Translation::get('msgAdminElasticsearchStats'), + 'csrfToken' => Token::getInstance($session)->getTokenString('truncate-search-terms'), + 'ad_searchterm_del' => Translation::get('ad_searchterm_del'), + 'ad_searchstats_search_term' => Translation::get('ad_searchstats_search_term'), + 'ad_searchstats_search_term_count' => Translation::get('ad_searchstats_search_term_count'), + 'ad_searchstats_search_term_lang' => Translation::get('ad_searchstats_search_term_lang'), + 'ad_searchstats_search_term_percentage' => Translation::get('ad_searchstats_search_term_percentage'), + 'pagination' => $pagination->render(), + 'searchesCount' => $searchesCount, + 'searchesList' => $searchesList, + 'csrfTokenDelete' => Token::getInstance($session)->getTokenString('delete-searchterm'), + 'ad_news_delete' => Translation::get('ad_news_delete'), + ] + ); + } +}