mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-07-31 02:10:37 +02:00
Pages Plugin: expand improvments #27. and fixed delete action
This commit is contained in:
@@ -1,10 +1,63 @@
|
||||
<?php
|
||||
|
||||
|
||||
Navigation::add(__('Pages', 'pages'), 'content', 'pages', 1);
|
||||
|
||||
|
||||
Action::add('admin_header', 'PagesAdmin::_themeHeaders');
|
||||
Action::add('admin_pre_render','PagesAdmin::_pageExpandAjax');
|
||||
|
||||
class PagesAdmin extends Backend {
|
||||
|
||||
|
||||
/**
|
||||
* Pages tables
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public static $pages = null;
|
||||
|
||||
|
||||
/**
|
||||
* _pageExpandAjax
|
||||
*/
|
||||
public static function _pageExpandAjax() {
|
||||
if (Request::post('slug')) {
|
||||
$pages = new Table('pages');
|
||||
$pages->updateWhere('[slug="'.Request::post('slug').'"]', array('expand' => Request::post('expand')));
|
||||
Request::shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* _themeHeaders
|
||||
*/
|
||||
public static function _themeHeaders() {
|
||||
echo ('<script>
|
||||
function pageExpand(slug, expand) {
|
||||
$.ajax({
|
||||
type:"post",
|
||||
data:"slug="+slug+"&expand="+expand,
|
||||
url: "'.Option::get('siteurl').'admin/index.php?id=pages"
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$(".parent").click(function() {
|
||||
if ($(this).html() == "-") {
|
||||
$(\'[rel="children_\' + $(this).attr(\'rel\')+\'"]\').hide();
|
||||
$(this).html("+");
|
||||
pageExpand($(this).attr("rel"), "1");
|
||||
} else {
|
||||
$(\'[rel="children_\' + $(this).attr(\'rel\')+\'"]\').show();
|
||||
$(this).html("-");
|
||||
pageExpand($(this).attr("rel"), "0");
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pages admin function
|
||||
@@ -19,6 +72,8 @@
|
||||
$errors = array();
|
||||
|
||||
$pages = new Table('pages');
|
||||
PagesAdmin::$pages = $pages;
|
||||
|
||||
$users = new Table('users');
|
||||
|
||||
$user = $users->select('[id='.Session::get('user_id').']', null);
|
||||
@@ -428,7 +483,12 @@
|
||||
|
||||
// Delete page and update <parent> fields
|
||||
if ($pages->deleteWhere('[slug="'.$page['slug'].'" ]')) {
|
||||
$pages->updateWhere('[parent="'.$page['slug'].'"]', array('parent' => ''));
|
||||
|
||||
$_pages = $pages->select('[parent="'.$page['slug'].'"]', 'all');
|
||||
foreach($_pages as $_page) {
|
||||
$pages->updateWhere('[slug="'.$_page['slug'].'"]', array('parent' => ''));
|
||||
}
|
||||
|
||||
File::delete(STORAGE . DS . 'pages' . DS . $page['id'] . '.page.txt');
|
||||
Notification::set('success', __('Page <i>:page</i> deleted', 'pages', array(':page' => Html::toText($page['title']))));
|
||||
}
|
||||
@@ -458,7 +518,7 @@
|
||||
$count = 0;
|
||||
|
||||
// Get pages
|
||||
$pages_list = $pages->select(null, 'all', null, array('slug', 'title', 'status', 'date', 'author', 'parent'));
|
||||
$pages_list = $pages->select(null, 'all', null, array('slug', 'title', 'status', 'date', 'author', 'expand', 'parent'));
|
||||
|
||||
// Loop
|
||||
foreach ($pages_list as $page) {
|
||||
@@ -468,6 +528,7 @@
|
||||
$pages_array[$count]['status'] = $status_array[$page['status']];
|
||||
$pages_array[$count]['date'] = $page['date'];
|
||||
$pages_array[$count]['author'] = $page['author'];
|
||||
$pages_array[$count]['expand'] = $page['expand'];
|
||||
$pages_array[$count]['slug'] = $page['slug'];
|
||||
|
||||
if (isset($page['parent'])) {
|
||||
|
@@ -18,6 +18,7 @@
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<td width="3%"></td>
|
||||
<td><?php echo __('Name', 'pages'); ?></td>
|
||||
<td><?php echo __('Author', 'pages'); ?></td>
|
||||
<td><?php echo __('Status', 'pages'); ?></td>
|
||||
@@ -32,12 +33,28 @@
|
||||
if ($page['parent'] != '') { $dash = Html::arrow('right').' '; } else { $dash = ""; }
|
||||
?>
|
||||
<?php if ($page['slug'] != 'error404') { ?>
|
||||
<tr>
|
||||
<?php
|
||||
$expand = PagesAdmin::$pages->select('[slug="'.(string)$page['parent'].'"]', null);
|
||||
if ($page['parent'] !== '' && isset($expand['expand']) && $expand['expand'] == '1') { $visibility = 'style="display:none;"'; } else { $visibility = ''; }
|
||||
?>
|
||||
<tr <?php echo $visibility; ?> <?php if(trim($page['parent']) !== '') {?> rel="children_<?php echo $page['parent']; ?>" <?php } ?>>
|
||||
<td>
|
||||
<?php
|
||||
if (count(PagesAdmin::$pages->select('[parent="'.(string)$page['slug'].'"]', 'all')) > 0) {
|
||||
if (isset($page['expand']) && $page['expand'] == '1') {
|
||||
echo '<a href="javascript:;" class="btn-expand parent" rel="'.$page['slug'].'">+</a>';
|
||||
} else {
|
||||
echo '<a href="javascript:;" class="btn-expand parent" rel="'.$page['slug'].'">-</a>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$parent = (trim($page['parent']) == '') ? '' : $page['parent'].'/';
|
||||
$_parent = (trim($page['parent']) == '') ? '' : $page['parent'];
|
||||
$parent = (trim($page['parent']) == '') ? '' : $page['parent'].'/';
|
||||
echo (trim($page['parent']) == '') ? '' : ' ';
|
||||
echo $dash.Html::anchor(Html::toText($page['title']), $site_url.$parent.$page['slug'], array('target' => '_blank'));
|
||||
echo $dash.Html::anchor(Html::toText($page['title']), $site_url.$parent.$page['slug'], array('target' => '_blank', 'rel' => 'children_'.$_parent));
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
@@ -68,6 +85,7 @@
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
<?php
|
||||
}
|
||||
|
Reference in New Issue
Block a user