mirror of
https://github.com/YGGverse/Yo.git
synced 2025-02-05 11:24:20 +00:00
add register new URL by request option
This commit is contained in:
parent
57c137ac49
commit
4aadb7f642
@ -20,6 +20,19 @@
|
|||||||
"pagination":
|
"pagination":
|
||||||
{
|
{
|
||||||
"limit":20
|
"limit":20
|
||||||
|
},
|
||||||
|
"search":
|
||||||
|
{
|
||||||
|
"index":
|
||||||
|
{
|
||||||
|
"request":
|
||||||
|
{
|
||||||
|
"url":{
|
||||||
|
"enabled":false,
|
||||||
|
"regex":"/.*/ui"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cli":
|
"cli":
|
||||||
|
@ -66,12 +66,67 @@ $placeholder = plural(
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$response = false;
|
||||||
|
|
||||||
// Request
|
// Request
|
||||||
$q = !empty($_GET['q']) ? $_GET['q'] : '';
|
$q = !empty($_GET['q']) ? $_GET['q'] : '';
|
||||||
$p = !empty($_GET['p']) ? (int) $_GET['p'] : 1;
|
$p = !empty($_GET['p']) ? (int) $_GET['p'] : 1;
|
||||||
|
|
||||||
// Check URL for exist
|
// Register new URL by request on enabled
|
||||||
$results = $index->search($q)
|
if ($config->webui->search->index->request->url->enabled)
|
||||||
|
{
|
||||||
|
if (filter_var($q, FILTER_VALIDATE_URL) && preg_match($config->webui->search->index->request->url->regex, $q))
|
||||||
|
{
|
||||||
|
$url = trim($q);
|
||||||
|
|
||||||
|
// Check URL for exist
|
||||||
|
$exist = $index->search('@url "' . trim($url) . '"')
|
||||||
|
->limit(1)
|
||||||
|
->get()
|
||||||
|
->getTotal();
|
||||||
|
|
||||||
|
if ($exist)
|
||||||
|
{
|
||||||
|
/* disable as regular search request possible
|
||||||
|
$response = sprintf(
|
||||||
|
_('URL "%s" exists in search index'),
|
||||||
|
htmlentities($url)
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add URL
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$index->addDocument(
|
||||||
|
[
|
||||||
|
'url' => trim($url)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = sprintf(
|
||||||
|
_('URL "%s" added to the crawl queue!'),
|
||||||
|
htmlentities($url)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extended syntax corrections
|
||||||
|
$query = trim($q);
|
||||||
|
|
||||||
|
if (filter_var($q, FILTER_VALIDATE_URL))
|
||||||
|
{
|
||||||
|
$query = '@url "' . $q . '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false === strpos($q, '"'))
|
||||||
|
{
|
||||||
|
$query = '"' . $q . '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search request begin
|
||||||
|
$results = $index->search($query)
|
||||||
->offset($p * $config->webui->pagination->limit - $config->webui->pagination->limit)
|
->offset($p * $config->webui->pagination->limit - $config->webui->pagination->limit)
|
||||||
->limit($config->webui->pagination->limit)
|
->limit($config->webui->pagination->limit)
|
||||||
->get();
|
->get();
|
||||||
@ -257,6 +312,9 @@ $results = $index->search($q)
|
|||||||
</form>
|
</form>
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
|
<?php if ($response) { ?>
|
||||||
|
<div><?php echo $response ?></div>
|
||||||
|
<?php } ?>
|
||||||
<?php if ($results->getTotal()) { ?>
|
<?php if ($results->getTotal()) { ?>
|
||||||
<?php foreach ($results as $result) { ?>
|
<?php foreach ($results as $result) { ?>
|
||||||
<div>
|
<div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user