1
0
mirror of https://github.com/monstra-cms/monstra.git synced 2025-08-05 04:37:51 +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,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<plugin_location>plugins/box/snippets/snippets.plugin.php</plugin_location>
<plugin_status>active</plugin_status>
<plugin_priority>6</plugin_priority>
<plugin_name>Snippets</plugin_name>
<plugin_description>Snippets 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(
'snippets' => array(
'Snippets' => 'Snippets',
'Snippets manager' => 'Snippets manager',
'Actions' => 'Actions',
'Delete' => 'Delete',
'Edit' => 'Edit',
'Name' => 'Name',
'Create new snippet' => 'Create new snippet',
'New snippet' => 'New snippet',
'Edit snippet' => 'Edit snippet',
'Save' => 'Save',
'Save and exit' => 'Save and exit',
'This field should not be empty' => 'This field should not be empty',
'This snippet already exists' => 'This snippet already exists',
'This snippet does not exist' => 'This snippet does not exist',
'Delete snippet: :snippet' => 'Delete snippet: :snippet',
'Snippet content' => 'Snippet content',
'Snippet <i>:name</i> deleted' => 'Snippet <i>:name</i> deleted',
'Your changes to the snippet <i>:name</i> have been saved.' => 'Your changes to the snippet <i>:name</i> have been saved.',
'Delete snippet: :snippet' => 'Delete snippet: :snippet',
)
);

View File

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

View File

@@ -0,0 +1,135 @@
<?php
Navigation::add(__('Snippets', 'snippets'), 'extends', 'snippets', 3);
class SnippetsAdmin extends Backend {
/**
* Snippets admin function
*/
public static function main() {
// Init vars
$snippets_path = STORAGE . DS . 'snippets' . DS;
$snippets_list = array();
$errors = array();
// Check for get actions
// -------------------------------------
if (Request::get('action')) {
// Switch actions
// -------------------------------------
switch (Request::get('action')) {
// Add snippet
// -------------------------------------
case "add_snippet":
if (Request::post('add_snippets') || Request::post('add_snippets_and_exit')) {
if (Security::check(Request::post('csrf'))) {
if (trim(Request::post('name')) == '') $errors['snippets_empty_name'] = __('This field should not be empty', 'snippets');
if (file_exists($snippets_path.Security::safeName(Request::post('name')).'.snippet.php')) $errors['snippets_exists'] = __('This snippet already exists', 'snippets');
if (count($errors) == 0) {
// Save snippet
File::setContent($snippets_path.Security::safeName(Request::post('name')).'.snippet.php', Request::post('content'));
Notification::set('success', __('Your changes to the snippet <i>:name</i> have been saved.', 'snippets', array(':name' => Security::safeName(Request::post('name')))));
if (Request::post('add_snippets_and_exit')) {
Request::redirect('index.php?id=snippets');
} else {
Request::redirect('index.php?id=snippets&action=edit_snippet&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('content')) $content = Request::post('content'); else $content = '';
// Display view
View::factory('box/snippets/views/backend/add')
->assign('content', $content)
->assign('name', $name)
->assign('errors', $errors)
->display();
break;
// Edit snippet
// -------------------------------------
case "edit_snippet":
// Save current snippet action
if (Request::post('edit_snippets') || Request::post('edit_snippets_and_exit') ) {
if (Security::check(Request::post('csrf'))) {
if (trim(Request::post('name')) == '') $errors['snippets_empty_name'] = __('This field should not be empty', 'snippets');
if ((file_exists($snippets_path.Security::safeName(Request::post('name')).'.snippet.php')) and (Security::safeName(Request::post('snippets_old_name')) !== Security::safeName(Request::post('name')))) $errors['snippets_exists'] = __('This snippet already exists', 'snippets');
// Save fields
if (Request::post('content')) $content = Request::post('content'); else $content = '';
if (count($errors) == 0) {
$snippet_old_filename = $snippets_path.Request::post('snippets_old_name').'.snippet.php';
$snippet_new_filename = $snippets_path.Security::safeName(Request::post('name')).'.snippet.php';
if ( ! empty($snippet_old_filename)) {
if ($snippet_old_filename !== $snippet_new_filename) {
rename($snippet_old_filename, $snippet_new_filename);
$save_filename = $snippet_new_filename;
} else {
$save_filename = $snippet_new_filename;
}
} else {
$save_filename = $snippet_new_filename;
}
// Save snippet
File::setContent($save_filename, Request::post('content'));
Notification::set('success', __('Your changes to the snippet <i>:name</i> have been saved.', 'snippets', array(':name' => basename($save_filename, '.snippet.php'))));
if (Request::post('edit_snippets_and_exit')) {
Request::redirect('index.php?id=snippets');
} else {
Request::redirect('index.php?id=snippets&action=edit_snippet&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'));
$content = File::getContent($snippets_path.Request::get('filename').'.snippet.php');
// Display view
View::factory('box/snippets/views/backend/edit')
->assign('content', $content)
->assign('name', $name)
->assign('errors', $errors)
->display();
break;
case "delete_snippet":
File::delete($snippets_path.Request::get('filename').'.snippet.php');
Notification::set('success', __('Snippet <i>:name</i> deleted', 'snippets', array(':name' => File::name(Request::get('filename')))));
Request::redirect('index.php?id=snippets');
break;
}
} else {
// Get snippets
$snippets_list = File::scan($snippets_path, '.snippet.php');
// Display view
View::factory('box/snippets/views/backend/index')
->assign('snippets_list', $snippets_list)
->display();
}
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Snippets plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Snippets', 'snippets'),
__('Snippets manager plugin', 'snippets'),
'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('snippets', 'box');
}
// Add shortcode {snippet get="snippetname"}
Shortcode::add('snippet', 'Snippet::_content');
class Snippet {
/**
* Get snippet
*
* @param string $name Snippet file name
*/
public static function get($name) {
return Snippet::_content(array('get' => $name));
}
/**
* Returns snippet content for shortcode {snippet get="snippetname"}
*
* @param array $attributes snippet filename
*/
public static function _content($attributes) {
if (isset($attributes['get'])) $name = (string)$attributes['get']; else $name = '';
$snippet_path = STORAGE . DS . 'snippets' . DS . $name . '.snippet.php';
if (File::exists($snippet_path)) {
ob_start();
include $snippet_path;
$snippet_contents = ob_get_contents();
ob_end_clean();
return $snippet_contents;
} else {
if (Session::exists('admin') && Session::get('admin') == true) {
return __('<b>Snippet <u>:name</u> is not found!</b>', 'snippets', array(':name' => $name));
}
}
}
}

View File

@@ -0,0 +1,36 @@
<h2><?php echo __('New snippet', 'snippets'); ?></h2>
<br />
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php if (isset($errors['snippets_empty_name']) or isset($errors['snippets_exists'])) $error_class = 'error'; else $error_class = ''; ?>
<?php echo (Form::open(null, array('class' => 'form-horizontal'))); ?>
<?php echo (Form::hidden('csrf', Security::token())); ?>
<?php echo (Form::label('name', __('Name', 'snippets'))); ?>
<div class="input-append">
<?php echo (Form::input('name', $name, array('class' => 'input-xlarge'))); ?><span class="add-on">.snippet.php</span>
</div>
<?php
if (isset($errors['snippets_empty_name'])) echo '&nbsp;&nbsp;&nbsp;<span style="color:red">'.$errors['snippets_empty_name'].'</span>';
if (isset($errors['snippets_exists'])) echo '&nbsp;&nbsp;&nbsp;<span style="color:red">'.$errors['snippets_exists'].'</span>';
?>
<?php
echo (
Html::br(2).
Form::label('content', __('Snippet content', 'snippets')).
Form::textarea('content', $content, array('style' => 'width:100%;height:400px;', 'class'=>'source-editor')).
Html::br(2).
Form::submit('add_snippets_and_exit', __('Save and exit', 'snippets'), array('class' => 'btn')).Html::nbsp(2).
Form::submit('add_snippets', __('Save', 'snippets'), array('class' => 'btn')).
Form::close()
);
?>

View File

@@ -0,0 +1,46 @@
<h2><?php echo __('Edit snippet', 'snippets'); ?></h2>
<br />
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php
if ($content !== null) {
if (isset($errors['snippets_empty_name']) or isset($errors['snippets_exists'])) $error_class = 'error'; else $error_class = '';
echo (Form::open(null, array('class' => 'form-horizontal')));
echo (Form::hidden('csrf', Security::token()));
echo (Form::hidden('snippets_old_name', Request::get('filename')));
?>
<?php echo (Form::label('name', __('Name', 'snippets'))); ?>
<div class="input-append">
<?php echo (Form::input('name', $name, array('class' => 'input-xlarge'))); ?><span class="add-on">.snippet.php</span>
</div>
<?php
if (isset($errors['snippets_empty_name'])) echo '&nbsp;&nbsp;&nbsp;<span style="color:red">'.$errors['snippets_empty_name'].'</span>';
if (isset($errors['snippets_exists'])) echo '&nbsp;&nbsp;&nbsp;<span style="color:red">'.$errors['snippets_exists'].'</span>';
?>
<?php
echo (
Html::br(2).
Form::label('content', __('Snippet content', 'snippets')).
Form::textarea('content', Html::toText($content), array('style' => 'width:100%;height:400px;', 'class' => 'source-editor')).
Html::br(2).
Form::submit('edit_snippets_and_exit', __('Save and exit', 'snippets'), array('class' => 'btn default')).Html::nbsp(2).
Form::submit('edit_snippets', __('Save', 'snippets'), array('class' => 'btn default')). Html::nbsp().
Form::close()
);
} else {
echo '<div class="message-error">'.__('This snippet does not exist').'</div>';
}
?>

View File

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