mirror of
https://github.com/danpros/htmly.git
synced 2026-04-17 11:16:00 +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 } ?>
|
||||
|
|
@ -1742,7 +1742,7 @@ get('/admin/search', function () {
|
|||
|
||||
render('search', array(
|
||||
'title' => generate_title('is_default', i18n('Search')),
|
||||
'heading' => i18n('Search') . ' Index',
|
||||
'heading' => i18n('Search') . ' Index',
|
||||
'description' => safe_html(strip_tags(blog_description())),
|
||||
'canonical' => site_url(),
|
||||
'metatags' => generate_meta(null, null),
|
||||
|
|
@ -1785,12 +1785,29 @@ 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()) {
|
||||
$user = $_SESSION[site_url()]['user'];
|
||||
$role = user('role', $user);
|
||||
$search = json_decode(htmlspecialchars_decode($_POST['search_index']));
|
||||
$search = json_decode(htmlspecialchars_decode($_POST['search_index']));
|
||||
config('views.root', 'system/admin/views');
|
||||
if ($role === 'editor' || $role === 'admin' && config('fulltext.search') == "true") {
|
||||
render('search-reindex', array(
|
||||
|
|
@ -1799,12 +1816,12 @@ post('/admin/search/reindex', function () {
|
|||
'canonical' => site_url(),
|
||||
'metatags' => generate_meta(null, null),
|
||||
'type' => 'is_admin-search',
|
||||
'search' => $search,
|
||||
'search' => $search,
|
||||
'is_admin' => true,
|
||||
'bodyclass' => 'admin-search',
|
||||
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> » ' . i18n('Search')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue