From 38d16493614f67302086c68cdaf1ee641f93f9ee Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 26 Nov 2023 18:39:47 +0200 Subject: [PATCH] add notice on URL request does not match node settings --- src/webui/search.php | 85 ++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/src/webui/search.php b/src/webui/search.php index 7b883b5..7aaec77 100644 --- a/src/webui/search.php +++ b/src/webui/search.php @@ -50,49 +50,56 @@ $q = !empty($_GET['q']) ? trim($_GET['q']) : ''; $p = !empty($_GET['p']) ? (int) $_GET['p'] : 1; // Register new URL by request on enabled -if ($config->webui->search->index->request->url->enabled) +if ($config->webui->search->index->request->url->enabled && filter_var($q, FILTER_VALIDATE_URL)) { - if (filter_var($q, FILTER_VALIDATE_URL) && preg_match($config->webui->search->index->request->url->regex, $q)) + if (preg_match($config->webui->search->index->request->url->regex, $q)) + { + // Prepare URL + $url = $q; + $crc32url = crc32($url); + + // Check URL for exist + $exist = $index->search('@url "' . $url . '"') + ->filter('crc32url', $crc32url) + ->limit(1) + ->get() + ->getTotal(); + + if ($exist) { - // Prepare URL - $url = $q; - $crc32url = crc32($url); - - // Check URL for exist - $exist = $index->search('@url "' . $url . '"') - ->filter('crc32url', $crc32url) - ->limit(1) - ->get() - ->getTotal(); - - if ($exist) - { - /* disable as regular search request possible - $response = sprintf( - _('URL "%s" exists in search index'), - htmlentities($q) - ); - */ - } - - // Add URL - else - { - // @TODO check http code - - $index->addDocument( - [ - 'url' => $url, - 'crc32url' => $crc32url - ] - ); + /* disable as regular search request possible + $response = sprintf( + _('URL "%s" exists in search index'), + htmlentities($q) + ); + */ + } - $response = sprintf( - _('URL "%s" added to the crawl queue!'), - htmlentities($q) - ); - } + // Add URL + else + { + // @TODO check http code + + $index->addDocument( + [ + 'url' => $url, + 'crc32url' => $crc32url + ] + ); + + $response = sprintf( + _('URL "%s" added to the crawl queue!'), + htmlentities($q) + ); } + } + + else { + $response = sprintf( + _('URL "%s" does not match node settings!'), + htmlentities($q) + ); + } } // Extended syntax corrections