mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-08-10 15:14:30 +02:00
Add Monstra from HG Commit 683dcb70c4cc
This commit is contained in:
11
plugins/box/menu/install/menu.manifest.xml
Normal file
11
plugins/box/menu/install/menu.manifest.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root>
|
||||
<plugin_location>plugins/box/menu/menu.plugin.php</plugin_location>
|
||||
<plugin_status>active</plugin_status>
|
||||
<plugin_priority>4</plugin_priority>
|
||||
<plugin_name>Menu</plugin_name>
|
||||
<plugin_description>Menu managment plugin</plugin_description>
|
||||
<plugin_version>1.0.0</plugin_version>
|
||||
<plugin_author>Awilum</plugin_author>
|
||||
<plugin_author_uri>http://monstra.org/</plugin_author_uri>
|
||||
</root>
|
24
plugins/box/menu/languages/en.lang.php
Normal file
24
plugins/box/menu/languages/en.lang.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'menu' => array(
|
||||
'Menu' => 'Menu',
|
||||
'Menu manager' => 'Menu manager',
|
||||
'Edit' => 'Edit',
|
||||
'Name' => 'Name',
|
||||
'Delete' => 'Delete',
|
||||
'Order' => 'Order',
|
||||
'Actions' => 'Actions',
|
||||
'Create new item' => 'Create new item',
|
||||
'New item' => 'New item',
|
||||
'Item name' => 'Item name',
|
||||
'Item order' => 'Item order',
|
||||
'Item target' => 'Item target',
|
||||
'Item link' => 'Item link',
|
||||
'Save' => 'Save',
|
||||
'Edit item' => 'Edit item',
|
||||
'Delete item :name' => 'Delete item :name',
|
||||
'Add page' => 'Add page',
|
||||
'Select page' => 'Select page',
|
||||
)
|
||||
);
|
24
plugins/box/menu/languages/ru.lang.php
Normal file
24
plugins/box/menu/languages/ru.lang.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'menu' => array(
|
||||
'Menu' => 'Меню',
|
||||
'Menu manager' => 'Менеджер меню',
|
||||
'Edit' => 'Редактировать',
|
||||
'Name' => 'Название',
|
||||
'Delete' => 'Удалить',
|
||||
'Order' => 'Порядок',
|
||||
'Actions' => 'Действия',
|
||||
'Create new item' => 'Создать новый пункт меню',
|
||||
'New item' => 'Новый пункт меню',
|
||||
'Item name' => 'Название',
|
||||
'Item order' => 'Порядок',
|
||||
'Item target' => 'Цель',
|
||||
'Item link' => 'Ссылка',
|
||||
'Save' => 'Сохранить',
|
||||
'Edit item' => 'Редактирование пункта меню',
|
||||
'Delete item :name' => 'Удалить пункт меню :name',
|
||||
'Add page' => 'Добавить страницу',
|
||||
'Select page' => 'Выбрать страницу',
|
||||
)
|
||||
);
|
198
plugins/box/menu/menu.admin.php
Normal file
198
plugins/box/menu/menu.admin.php
Normal file
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
// Add plugin navigation link
|
||||
Navigation::add(__('Menu', 'menu'), 'content', 'menu', 3);
|
||||
|
||||
Action::add('admin_header', 'menuAdminHeaders');
|
||||
|
||||
function menuAdminHeaders() {
|
||||
echo ("
|
||||
<script>
|
||||
function addMenuPage(slug, title) {
|
||||
$('input[name=menu_item_link]').val(slug);
|
||||
$('input[name=menu_item_name]').val(title);
|
||||
$('#addMenuPageModal').modal('hide');
|
||||
}
|
||||
</script>
|
||||
");
|
||||
}
|
||||
|
||||
class MenuAdmin extends Backend {
|
||||
|
||||
public static function main() {
|
||||
|
||||
// Get menu table
|
||||
$menu = new Table('menu');
|
||||
|
||||
// Get pages table
|
||||
$pages = new Table('pages');
|
||||
|
||||
// Create target array
|
||||
$menu_item_target_array = array( '' => '',
|
||||
'_blank' => '_blank',
|
||||
'_parent' => '_parent',
|
||||
'_top' => '_top');
|
||||
|
||||
// Create order array
|
||||
$menu_item_order_array = range(0, 20);
|
||||
|
||||
|
||||
// Check for get actions
|
||||
// ---------------------------------------------
|
||||
if (Request::get('action')) {
|
||||
|
||||
// Switch actions
|
||||
// -----------------------------------------
|
||||
switch (Request::get('action')) {
|
||||
|
||||
// Edit menu item
|
||||
// -----------------------------------------
|
||||
case "edit":
|
||||
|
||||
// Select item
|
||||
$item = $menu->select('[id="'.Request::get('item_id').'"]', null);
|
||||
|
||||
$menu_item_name = $item['name'];
|
||||
$menu_item_link = $item['link'];
|
||||
$menu_item_target = $item['target'];
|
||||
$menu_item_order = $item['order'];
|
||||
|
||||
$errors = array();
|
||||
|
||||
// Edit current menu item
|
||||
if (Request::post('menu_add_item')) {
|
||||
|
||||
if (Security::check(Request::post('csrf'))) {
|
||||
|
||||
if (trim(Request::post('menu_item_name')) == '') {
|
||||
|
||||
if (Request::post('menu_item_name')) $menu_item_name = Request::post('menu_item_name'); else $menu_item_name = $item['name'];
|
||||
if (Request::post('menu_item_link')) $menu_item_link = Request::post('menu_item_link'); else $menu_item_link = $item['link'];
|
||||
if (Request::post('menu_item_target')) $menu_item_target = Request::post('menu_item_target'); else $menu_item_target = $item['target'];
|
||||
if (Request::post('menu_item_order')) $menu_item_order = Request::post('menu_item_order'); else $menu_item_order = $item['order'];
|
||||
|
||||
$errors['menu_item_name_empty'] = __('This field should not be empty', 'menu');
|
||||
}
|
||||
|
||||
// Update menu item
|
||||
if (count($errors) == 0) {
|
||||
$menu->update(Request::get('item_id'), array('name' => Request::post('menu_item_name'),
|
||||
'link' => Request::post('menu_item_link'),
|
||||
'target' => Request::post('menu_item_target'),
|
||||
'order' => Request::post('menu_item_order')));
|
||||
|
||||
Request::redirect('index.php?id=menu');
|
||||
}
|
||||
|
||||
} else { die('csrf detected!'); }
|
||||
|
||||
}
|
||||
|
||||
// Display view
|
||||
View::factory('box/menu/views/backend/edit')
|
||||
->assign('menu_item_name', $menu_item_name)
|
||||
->assign('menu_item_link', $menu_item_link)
|
||||
->assign('menu_item_target', $menu_item_target)
|
||||
->assign('menu_item_order', $menu_item_order)
|
||||
->assign('menu_item_target_array', $menu_item_target_array)
|
||||
->assign('menu_item_order_array', $menu_item_order_array)
|
||||
->assign('errors', $errors)
|
||||
->assign('pages_list', $pages->select('[slug!="error404" and parent=""]'))
|
||||
->assign('components_list', MenuAdmin::getComponents())
|
||||
->display();
|
||||
|
||||
|
||||
break;
|
||||
|
||||
// Add menu item
|
||||
// -----------------------------------------
|
||||
case "add":
|
||||
|
||||
$menu_item_name = '';
|
||||
$menu_item_link = '';
|
||||
$menu_item_target = '';
|
||||
$menu_item_order = '';
|
||||
$errors = array();
|
||||
|
||||
// Add new menu item
|
||||
if (Request::post('menu_add_item')) {
|
||||
|
||||
if (Security::check(Request::post('csrf'))) {
|
||||
|
||||
if (trim(Request::post('menu_item_name')) == '') {
|
||||
|
||||
if (Request::post('menu_item_name')) $menu_item_name = Request::post('menu_item_name'); else $menu_item_name = '';
|
||||
if (Request::post('menu_item_link')) $menu_item_link = Request::post('menu_item_link'); else $menu_item_link = '';
|
||||
if (Request::post('menu_item_target')) $menu_item_target = Request::post('menu_item_target'); else $menu_item_target = '';
|
||||
if (Request::post('menu_item_order')) $menu_item_order = Request::post('menu_item_order'); else $menu_item_order = '';
|
||||
|
||||
$errors['menu_item_name_empty'] = __('This field should not be empty', 'menu');
|
||||
}
|
||||
|
||||
// Insert new menu item
|
||||
if (count($errors) == 0) {
|
||||
$menu->insert(array('name' => Request::post('menu_item_name'),
|
||||
'link' => Request::post('menu_item_link'),
|
||||
'target' => Request::post('menu_item_target'),
|
||||
'order' => Request::post('menu_item_order')));
|
||||
|
||||
Request::redirect('index.php?id=menu');
|
||||
}
|
||||
|
||||
} else { die('csrf detected!'); }
|
||||
}
|
||||
|
||||
|
||||
// Display view
|
||||
View::factory('box/menu/views/backend/add')
|
||||
->assign('menu_item_name', $menu_item_name)
|
||||
->assign('menu_item_link', $menu_item_link)
|
||||
->assign('menu_item_target', $menu_item_target)
|
||||
->assign('menu_item_order', $menu_item_order)
|
||||
->assign('menu_item_target_array', $menu_item_target_array)
|
||||
->assign('menu_item_order_array', $menu_item_order_array)
|
||||
->assign('errors', $errors)
|
||||
->assign('pages_list', $pages->select('[slug!="error404" and parent=""]'))
|
||||
->assign('components_list', MenuAdmin::getComponents())
|
||||
->display();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// Delete menu item
|
||||
if (Request::get('delete_item')) {
|
||||
$menu->delete((int)Request::get('delete_item'));
|
||||
}
|
||||
|
||||
// Select all items
|
||||
$items = $menu->select(null, 'all', null, array('id', 'name', 'link', 'target', 'order'), 'order', 'ASC');
|
||||
|
||||
// Display view
|
||||
View::factory('box/menu/views/backend/index')
|
||||
->assign('items', $items)
|
||||
->display();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get components
|
||||
*/
|
||||
protected static function getComponents() {
|
||||
|
||||
$components = array();
|
||||
|
||||
if (count(Plugin::$components) > 0) {
|
||||
foreach (Plugin::$components as $component) {
|
||||
if ($component !== 'pages' && $component !== 'sitemap') $components[] = ucfirst($component);
|
||||
}
|
||||
}
|
||||
|
||||
return $components;
|
||||
}
|
||||
|
||||
}
|
53
plugins/box/menu/menu.plugin.php
Normal file
53
plugins/box/menu/menu.plugin.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Menu plugin
|
||||
*
|
||||
* @package Monstra
|
||||
* @subpackage Plugins
|
||||
* @author Romanenko Sergey / Awilum
|
||||
* @copyright 2012 Romanenko Sergey / Awilum
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// Register plugin
|
||||
Plugin::register( __FILE__,
|
||||
__('Menu', 'menu'),
|
||||
__('Menu manager', 'menu'),
|
||||
'1.0.0',
|
||||
'Awilum',
|
||||
'http://monstra.org/',
|
||||
null,
|
||||
'box');
|
||||
|
||||
|
||||
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) {
|
||||
|
||||
// Include Admin
|
||||
Plugin::admin('menu', 'box');
|
||||
|
||||
}
|
||||
|
||||
|
||||
class Menu {
|
||||
|
||||
public static function get() {
|
||||
|
||||
// Get menu table
|
||||
$menu = new Table('menu');
|
||||
|
||||
// Select all items
|
||||
$items = $menu->select(null, 'all', null, array('id', 'name', 'link', 'target', 'order'), 'order', 'ASC');
|
||||
|
||||
// Display view
|
||||
View::factory('box/menu/views/frontend/index')
|
||||
->assign('items', $items)
|
||||
->assign('uri', Uri::segments())
|
||||
->assign('defpage', Option::get('defaultpage'))
|
||||
->display();
|
||||
|
||||
}
|
||||
|
||||
}
|
62
plugins/box/menu/views/backend/add.view.php
Normal file
62
plugins/box/menu/views/backend/add.view.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<h2><?php echo __('New item', 'menu'); ?></h2>
|
||||
<br />
|
||||
|
||||
<?php echo (Form::open()); ?>
|
||||
|
||||
<?php echo (Form::hidden('csrf', Security::token())); ?>
|
||||
|
||||
<?php if (isset($errors['menu_item_name_empty'])) $error_class = ' error'; else $error_class = ''; ?>
|
||||
|
||||
<a href="javascript:;" style="text-decoration:none; color:#333; border-bottom:1px dashed #333;" data-toggle="modal" onclick="$('#addMenuPageModal').modal('show').width(270);" ><?php echo __('Add page', 'menu'); ?></a><br /><br />
|
||||
|
||||
<?php
|
||||
|
||||
echo Form::label('menu_item_name', __('Item name', 'menu'));
|
||||
echo Form::input('menu_item_name', $menu_item_name, array('class' => 'span6'.$error_class));
|
||||
|
||||
if (isset($errors['menu_item_name_empty'])) echo Html::nbsp(4).'<span class="error">'.$errors['menu_item_name_empty'].'</span>';
|
||||
|
||||
echo (
|
||||
Form::label('menu_item_link', __('Item link', 'menu')).
|
||||
Form::input('menu_item_link', $menu_item_link, array('class' => 'span6'))
|
||||
);
|
||||
?>
|
||||
|
||||
<?php
|
||||
echo (
|
||||
Html::br().
|
||||
Form::label('menu_item_target', __('Item target', 'menu')).
|
||||
Form::select('menu_item_target', $menu_item_target_array, $menu_item_target)
|
||||
);
|
||||
|
||||
echo (
|
||||
Html::br().
|
||||
Form::label('menu_item_order', __('Item order', 'menu')).
|
||||
Form::select('menu_item_order', $menu_item_order_array, $menu_item_order)
|
||||
);
|
||||
|
||||
echo (
|
||||
Html::br(2).
|
||||
Form::submit('menu_add_item', __('Save', 'menu'), array('class' => 'btn')).
|
||||
Form::close()
|
||||
);
|
||||
?>
|
||||
|
||||
<div class="modal hide" id="addMenuPageModal">
|
||||
<div class="modal-header">
|
||||
<a class="close" data-dismiss="modal">×</a>
|
||||
<h3><?php echo __('Select page', 'menu'); ?></h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>
|
||||
<ul class="unstyled">
|
||||
<?php if (count($pages_list) > 0) foreach($pages_list as $page) { ?>
|
||||
<li><a href="javascript:;" onclick="addMenuPage('<?php echo $page['slug']; ?>', '<?php echo $page['title']; ?>');"><?php echo $page['title']; ?></a></li>
|
||||
<?php } ?>
|
||||
<?php if (count($components_list) > 0) foreach($components_list as $component) { ?>
|
||||
<li><a href="javascript:;" onclick="addMenuPage('<?php echo Text::lowercase($component); ?>', '<?php echo __($component); ?>');"><?php echo __($component); ?></a></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
62
plugins/box/menu/views/backend/edit.view.php
Normal file
62
plugins/box/menu/views/backend/edit.view.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<h2><?php echo __('Edit item', 'menu'); ?></h2>
|
||||
<br />
|
||||
|
||||
<?php echo (Form::open()); ?>
|
||||
|
||||
<?php echo (Form::hidden('csrf', Security::token())); ?>
|
||||
|
||||
<?php if (isset($errors['menu_item_name_empty'])) $error_class = ' error'; else $error_class = ''; ?>
|
||||
|
||||
<a href="javascript:;" style="text-decoration:none; color:#333; border-bottom:1px dashed #333;" data-toggle="modal" onclick="$('#addMenuPageModal').modal('show').width(270);" ><?php echo __('Add page', 'menu'); ?></a><br /><br />
|
||||
|
||||
<?php
|
||||
|
||||
echo Form::label('menu_item_name', __('Item name', 'menu'));
|
||||
echo Form::input('menu_item_name', $menu_item_name, array('class' => 'span6'.$error_class));
|
||||
|
||||
if (isset($errors['menu_item_name_empty'])) echo Html::nbsp(4).'<span class="error">'.$errors['menu_item_name_empty'].'</span>';
|
||||
|
||||
echo (
|
||||
Form::label('menu_item_link', __('Item link', 'menu')).
|
||||
Form::input('menu_item_link', $menu_item_link, array('class' => 'span6'))
|
||||
);
|
||||
?>
|
||||
|
||||
<?php
|
||||
echo (
|
||||
Html::br().
|
||||
Form::label('menu_item_target', __('Item target', 'menu')).
|
||||
Form::select('menu_item_target', $menu_item_target_array, $menu_item_target)
|
||||
);
|
||||
|
||||
echo (
|
||||
Html::br().
|
||||
Form::label('menu_item_order', __('Item order', 'menu')).
|
||||
Form::select('menu_item_order', $menu_item_order_array, $menu_item_order)
|
||||
);
|
||||
|
||||
echo (
|
||||
Html::br(2).
|
||||
Form::submit('menu_add_item', __('Save', 'menu'), array('class' => 'btn')).
|
||||
Form::close()
|
||||
);
|
||||
?>
|
||||
|
||||
<div class="modal hide" id="addMenuPageModal">
|
||||
<div class="modal-header">
|
||||
<a class="close" data-dismiss="modal">×</a>
|
||||
<h3><?php echo __('Select page', 'menu'); ?></h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>
|
||||
<ul class="unstyled">
|
||||
<?php if (count($pages_list) > 0) foreach($pages_list as $page) { ?>
|
||||
<li><a href="javascript:;" onclick="addMenuPage('<?php echo $page['slug']; ?>', '<?php echo $page['title']; ?>');"><?php echo $page['title']; ?></a></li>
|
||||
<?php } ?>
|
||||
<?php if (count($components_list) > 0) foreach($components_list as $component) { ?>
|
||||
<li><a href="javascript:;" onclick="addMenuPage('<?php echo Text::lowercase($component); ?>', '<?php echo __($component); ?>');"><?php echo __($component); ?></a></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
51
plugins/box/menu/views/backend/index.view.php
Normal file
51
plugins/box/menu/views/backend/index.view.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<h2><?php echo __('Menu', 'menu'); ?></h2>
|
||||
<br />
|
||||
|
||||
<?php
|
||||
echo (
|
||||
Html::anchor(__('Create new item', 'menu'), 'index.php?id=menu&action=add', array('title' => __('Create new page', 'menu'), 'class' => 'btn btn-small'))
|
||||
);
|
||||
?>
|
||||
|
||||
<br /><br />
|
||||
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<td><?php echo __('Name', 'menu'); ?></td>
|
||||
<td class="span2"><?php echo __('Order', 'menu'); ?></td>
|
||||
<td width="30%"><?php echo __('Actions', 'menu'); ?></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($items as $item) { ?>
|
||||
<?php
|
||||
|
||||
$item['link'] = Html::toText($item['link']);
|
||||
$item['name'] = Html::toText($item['name']);
|
||||
|
||||
$pos = strpos($item['link'], 'http://');
|
||||
if ($pos === false) {
|
||||
$link = Option::get('siteurl').$item['link'];
|
||||
} else {
|
||||
$link = $item['link'];
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<a target="_blank" href="<?php echo $link; ?>"><?php echo $item['name']; ?></a>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo $item['order']; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo Html::anchor(__('Edit', 'menu'), 'index.php?id=menu&action=edit&item_id='.$item['id'], array('class' => 'btn btn-actions')); ?>
|
||||
<?php echo Html::anchor(__('Delete', 'menu'),
|
||||
'index.php?id=menu&delete_item='.$item['id'],
|
||||
array('class' => 'btn btn-actions', 'onclick' => "return confirmDelete('".__('Delete item :name', 'menu', array(':name' => $item['name']))."')"));
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
52
plugins/box/menu/views/frontend/index.view.php
Normal file
52
plugins/box/menu/views/frontend/index.view.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
$anchor_active = '';
|
||||
$li_active = '';
|
||||
$target = '';
|
||||
|
||||
if (count($items) > 0) {
|
||||
foreach ($items as $item) {
|
||||
|
||||
$item['link'] = Html::toText($item['link']);
|
||||
$item['name'] = Html::toText($item['name']);
|
||||
|
||||
$pos = strpos($item['link'], 'http://');
|
||||
if ($pos === false) {
|
||||
$link = Option::get('siteurl').$item['link'];
|
||||
} else {
|
||||
$link = $item['link'];
|
||||
}
|
||||
|
||||
if (isset($uri[1])) {
|
||||
$child_link = explode("/",$item['link']);
|
||||
if (isset($child_link[1])) {
|
||||
if (in_array($child_link[1], $uri)) {
|
||||
$anchor_active = ' class="current" ';
|
||||
$li_active = ' class="active"';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($uri[0]) && $uri[0] !== '') {
|
||||
if (in_array($item['link'], $uri)) {
|
||||
$anchor_active = ' class="current" ';
|
||||
$li_active = ' class="active"';
|
||||
}
|
||||
} else {
|
||||
if ($defpage == trim($item['link'])) {
|
||||
$anchor_active = ' class="current" ';
|
||||
$li_active = ' class="active"';
|
||||
}
|
||||
}
|
||||
|
||||
if (trim($item['target']) !== '') {
|
||||
$target = ' target="'.$item['target'].'" ';
|
||||
}
|
||||
|
||||
echo '<li'.$li_active.'>'.'<a href="'.$link.'"'.$anchor_active.$target.'>'.$item['name'].'</a>'.'</li>';
|
||||
|
||||
$anchor_active = '';
|
||||
$li_active = '';
|
||||
$target = '';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user