mirror of
https://github.com/danpros/htmly.git
synced 2026-04-20 12:36:23 +05:30
Add clear index button
This commit is contained in:
parent
529cb62ae5
commit
e9589b1dc2
3 changed files with 46 additions and 7 deletions
|
|
@ -55,3 +55,5 @@ echo '<a href="' . site_url() .'admin/search">Back to search index</a>';
|
|||
|
||||
// Redir
|
||||
echo '<script language="javascript">window.location.href = "' .site_url() . 'admin/search"</script>';
|
||||
|
||||
?>
|
||||
|
|
@ -54,6 +54,26 @@
|
|||
<?php endif; ?>
|
||||
<input type="hidden" name="search_index" value="<?php print_r(htmlspecialchars(json_encode($search_index)));?>">
|
||||
</form>
|
||||
<?php } else {
|
||||
echo count(get_blog_posts()) . ' published posts has been indexed!';
|
||||
} ?>
|
||||
<?php } else {?>
|
||||
<script>
|
||||
$(function() {
|
||||
|
||||
var data = 'content/data/search.json';
|
||||
$("#clearButton").click(function(){
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '<?php echo site_url();?>admin/search',
|
||||
dataType: 'json',
|
||||
data: {'json': data},
|
||||
success: function (response) {
|
||||
alert(response.message);
|
||||
location.reload();
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
<p><?php echo count(get_blog_posts()); ?> published posts has been indexed!</p>
|
||||
<p><button class="btn btn-primary" id="clearButton">Clear Search Index</button></p>
|
||||
<?php } ?>
|
||||
|
|
@ -1785,6 +1785,23 @@ get('/admin/search', function () {
|
|||
}
|
||||
});
|
||||
|
||||
post('/admin/search', function () {
|
||||
|
||||
if (login()) {
|
||||
$user = $_SESSION[site_url()]['user'];
|
||||
$role = user('role', $user);
|
||||
if ($role === 'editor' || $role === 'admin') {
|
||||
$json = $_REQUEST['json'];
|
||||
if ($json == 'content/data/search.json') {
|
||||
unlink($json);
|
||||
}
|
||||
echo json_encode(array(
|
||||
'message' => 'Search Index cleared successfully!',
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
post('/admin/search/reindex', function () {
|
||||
|
||||
if (login()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue