1
0
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:
Awilum
2012-09-25 19:09:50 +03:00
parent d2db42b2bb
commit 4a5fea5f5b
251 changed files with 35026 additions and 0 deletions

View File

@@ -0,0 +1,139 @@
<?php
Navigation::add(__('Blocks', 'blocks'), 'content', 'blocks', 2);
class BlocksAdmin extends Backend {
/**
* Blocks admin function
*/
public static function main() {
// Init vars
$blocks_path = STORAGE . DS . 'blocks' . DS;
$blocks_list = array();
$errors = array();
// Check for get actions
// -------------------------------------
if (Request::get('action')) {
// Switch actions
// -------------------------------------
switch (Request::get('action')) {
// Add block
// -------------------------------------
case "add_block":
if (Request::post('add_blocks') || Request::post('add_blocks_and_exit')) {
if (Security::check(Request::post('csrf'))) {
if (trim(Request::post('name')) == '') $errors['blocks_empty_name'] = __('This field should not be empty', 'blocks');
if (file_exists($blocks_path.Security::safeName(Request::post('name')).'.block.html')) $errors['blocks_exists'] = __('This block already exists', 'blocks');
if (count($errors) == 0) {
// Save block
File::setContent($blocks_path.Security::safeName(Request::post('name')).'.block.html', XML::safe(Request::post('editor')));
Notification::set('success', __('Your changes to the block <i>:name</i> have been saved.', 'blocks', array(':name' => Security::safeName(Request::post('name')))));
if (Request::post('add_blocks_and_exit')) {
Request::redirect('index.php?id=blocks');
} else {
Request::redirect('index.php?id=blocks&action=edit_block&filename='.Security::safeName(Request::post('name')));
}
}
} else { die('csrf detected!'); }
}
// Save fields
if (Request::post('name')) $name = Request::post('name'); else $name = '';
if (Request::post('editor')) $content = Request::post('editor'); else $content = '';
// Display view
View::factory('box/blocks/views/backend/add')
->assign('content', $content)
->assign('name', $name)
->assign('errors', $errors)
->display();
break;
// Edit block
// -------------------------------------
case "edit_block":
// Save current block action
if (Request::post('edit_blocks') || Request::post('edit_blocks_and_exit') ) {
if (Security::check(Request::post('csrf'))) {
if (trim(Request::post('name')) == '') $errors['blocks_empty_name'] = __('This field should not be empty', 'blocks');
if ((file_exists($blocks_path.Security::safeName(Request::post('name')).'.block.html')) and (Security::safeName(Request::post('blocks_old_name')) !== Security::safeName(Request::post('name')))) $errors['blocks_exists'] = __('This block already exists', 'blocks');
// Save fields
if (Request::post('editor')) $content = Request::post('editor'); else $content = '';
if (count($errors) == 0) {
$block_old_filename = $blocks_path.Request::post('blocks_old_name').'.block.html';
$block_new_filename = $blocks_path.Security::safeName(Request::post('name')).'.block.html';
if ( ! empty($block_old_filename)) {
if ($block_old_filename !== $block_new_filename) {
rename($block_old_filename, $block_new_filename);
$save_filename = $block_new_filename;
} else {
$save_filename = $block_new_filename;
}
} else {
$save_filename = $block_new_filename;
}
// Save block
File::setContent($save_filename, XML::safe(Request::post('editor')));
Notification::set('success', __('Your changes to the block <i>:name</i> have been saved.', 'blocks', array(':name' => basename($save_filename, '.block.html'))));
if (Request::post('edit_blocks_and_exit')) {
Request::redirect('index.php?id=blocks');
} else {
Request::redirect('index.php?id=blocks&action=edit_block&filename='.Security::safeName(Request::post('name')));
}
}
} else { die('csrf detected!'); }
}
if (Request::post('name')) $name = Request::post('name'); else $name = File::name(Request::get('filename'));
if (Request::post('editor')) $content = Request::post('editor'); else $content = File::getContent($blocks_path.Request::get('filename').'.block.html');
// Display view
View::factory('box/blocks/views/backend/edit')
->assign('content', Text::toHtml($content))
->assign('name', $name)
->assign('errors', $errors)
->display();
break;
case "delete_block":
File::delete($blocks_path.Request::get('filename').'.block.html');
Notification::set('success', __('Block <i>:name</i> deleted', 'blocks', array(':name' => File::name(Request::get('filename')))));
Request::redirect('index.php?id=blocks');
break;
}
} else {
// Get blocks
$blocks_list = File::scan($blocks_path, '.block.html');
// Display view
View::factory('box/blocks/views/backend/index')
->assign('blocks_list', $blocks_list)
->display();
}
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Blocks plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Blocks', 'blocks'),
__('Blocks manager plugin', 'blocks'),
'1.0.0',
'Awilum',
'http://monstra.org/',
null,
'box');
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor'))) {
// Include Admin
Plugin::admin('blocks', 'box');
}
// Add shortcode {block get="blockname"}
Shortcode::add('block', 'Block::_content');
class Block {
/**
* Get block
*
* @param string $name Block file name
*/
public static function get($name) {
return Block::_content(array('get' => $name));
}
/**
* Returns block content for shortcode {block get="blockname"}
*
* @param array $attributes block filename
*/
public static function _content($attributes) {
if (isset($attributes['get'])) $name = (string)$attributes['get']; else $name = '';
$block_path = STORAGE . DS . 'blocks' . DS . $name . '.block.html';
if (File::exists($block_path)) {
ob_start();
include $block_path;
$block_contents = ob_get_contents();
ob_end_clean();
return Filter::apply('content', Text::toHtml($block_contents));
} else {
if (Session::exists('admin') && Session::get('admin') == true) {
return __('<b>Block <u>:name</u> is not found!</b>', 'blocks', array(':name' => $name));
}
}
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<plugin_location>plugins/box/blocks/blocks.plugin.php</plugin_location>
<plugin_frontend>yes</plugin_frontend>
<plugin_backend>yes</plugin_backend>
<plugin_status>active</plugin_status>
<plugin_priority>6</plugin_priority>
<plugin_name>Blocks</plugin_name>
<plugin_description>Blocks manager 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>

View File

@@ -0,0 +1,25 @@
<?php
return array(
'blocks' => array(
'Blocks' => 'Blocks',
'Blocks manager' => 'Blocks manager',
'Delete' => 'Delete',
'Edit' => 'Edit',
'Name' => 'Name',
'Create new block' => 'Create new block',
'New block' => 'New block',
'Edit block' => 'Edit block',
'Save' => 'Save',
'Save and exit' => 'Save and exit',
'Actions' => 'Actions',
'This field should not be empty' => 'This field should not be empty',
'This block already exists' => 'This block already exists',
'This block does not exist' => 'This block does not exist',
'Delete block: :block' => 'Delete block: :block',
'Block content' => 'Block content',
'Block <i>:name</i> deleted' => 'Block <i>:name</i> deleted',
'Your changes to the block <i>:name</i> have been saved.' => 'Your changes to the block <i>:name</i> have been saved.',
'Delete block: :block' => 'Delete block: :block',
)
);

View File

@@ -0,0 +1,25 @@
<?php
return array(
'blocks' => array(
'Blocks' => 'Блоки',
'Blocks manager' => 'Менеджер блоков',
'Delete' => 'Удалить',
'Edit' => 'Редактировать',
'New block' => 'Новый блок',
'Create new block' => 'Создать новый блок',
'Name' => 'Название',
'Edit block' => 'Редактирование блока',
'Save' => 'Сохранить',
'Actions' => 'Действия',
'Save and exit' => 'Сохранить и выйти',
'This field should not be empty' => 'Это поле не должно быть пустым',
'This block already exists' => 'Такой блок уже существует',
'This block does not exist' => 'Такого блока не существует',
'Delete block: :block' => 'Удалить блок: :block',
'Block content' => 'Содержимое блока',
'Block <i>:name</i> deleted' => 'Сниппет <i>:name</i> удален',
'Your changes to the block <i>:name</i> have been saved.' => 'Ваши изменения к блоку <i>:name</i> были сохранены.',
'Delete block: :block' => 'Удалить блок: :block',
)
);

View File

@@ -0,0 +1,36 @@
<h2><?php echo __('New block', 'blocks'); ?></h2>
<br />
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php if (isset($errors['blocks_empty_name']) or isset($errors['blocks_exists'])) $error_class = 'error'; else $error_class = ''; ?>
<?php echo (Form::open()); ?>
<?php echo (Form::hidden('csrf', Security::token())); ?>
<?php echo (Form::label('name', __('Name', 'blocks'))); ?>
<?php echo (Form::input('name', $name, array('class' => 'span5'))); ?>
<?php
if (isset($errors['blocks_empty_name'])) echo '&nbsp;&nbsp;&nbsp;<span style="color:red">'.$errors['blocks_empty_name'].'</span>';
if (isset($errors['blocks_exists'])) echo '&nbsp;&nbsp;&nbsp;<span style="color:red">'.$errors['blocks_exists'].'</span>';
?>
<br /><br />
<?php
Action::run('admin_editor', array(Html::toText($content)));
echo (
Html::br().
Form::submit('add_blocks_and_exit', __('Save and exit', 'blocks'), array('class' => 'btn')).Html::nbsp(2).
Form::submit('add_blocks', __('Save', 'blocks'), array('class' => 'btn')).
Form::close()
);
?>

View File

@@ -0,0 +1,44 @@
<h2><?php echo __('Edit block', 'blocks'); ?></h2>
<br />
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php
if ($content !== null) {
if (isset($errors['blocks_empty_name']) or isset($errors['blocks_exists'])) $error_class = 'error'; else $error_class = '';
echo (Form::open());
echo (Form::hidden('csrf', Security::token()));
echo (Form::hidden('blocks_old_name', Request::get('filename')));
?>
<?php echo (Form::label('name', __('Name', 'blocks'))); ?>
<?php echo (Form::input('name', $name, array('class' => 'span5'))); ?>
<?php
if (isset($errors['blocks_empty_name'])) echo '&nbsp;&nbsp;&nbsp;<span style="color:red">'.$errors['blocks_empty_name'].'</span>';
if (isset($errors['blocks_exists'])) echo '&nbsp;&nbsp;&nbsp;<span style="color:red">'.$errors['blocks_exists'].'</span>';
?>
<br /><br />
<?php
Action::run('admin_editor', array(Html::toText($content)));
echo (
Html::br().
Form::submit('edit_blocks_and_exit', __('Save and exit', 'blocks'), array('class' => 'btn default')).Html::nbsp(2).
Form::submit('edit_blocks', __('Save', 'blocks'), array('class' => 'btn default')). Html::nbsp().
Form::close()
);
} else {
echo '<div class="message-error">'.__('This block does not exist', 'blocks').'</div>';
}
?>

View File

@@ -0,0 +1,34 @@
<h2><?php echo __('Blocks', 'blocks'); ?></h2>
<br />
<?php if(Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php
echo (
Html::anchor(__('Create new block', 'blocks'), 'index.php?id=blocks&action=add_block', array('title' => __('Create new block', 'blocks'), 'class' => 'btn default btn-small')). Html::nbsp(3)
);
?>
<br /><br />
<!-- Blocks_list -->
<table class="table table-bordered">
<thead>
<tr><td><?php echo __('Blocks', 'blocks'); ?></td><td width="30%"><?php echo __('Actions', 'blocks'); ?></td></tr>
</thead>
<tbody>
<?php if (count($blocks_list) != 0) foreach ($blocks_list as $block) { ?>
<tr>
<td><?php echo basename($block, '.block.html'); ?></td>
<td>
<?php echo Html::anchor(__('Edit', 'blocks'), 'index.php?id=blocks&action=edit_block&filename='.basename($block, '.block.html'), array('class' => 'btn btn-actions')); ?>
<?php echo Html::anchor(__('Delete', 'blocks'),
'index.php?id=blocks&action=delete_block&filename='.basename($block, '.block.html'),
array('class' => 'btn btn-actions', 'onclick' => "return confirmDelete('".__('Delete block: :block', 'blocks', array(':block' => basename($block, '.block.html')))."')"));
?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<!-- /Blocks_list -->