1
0
mirror of https://github.com/monstra-cms/monstra.git synced 2025-08-12 08:04:10 +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

1
plugins/.htaccess Normal file
View File

@@ -0,0 +1 @@
Deny from all

View File

@@ -0,0 +1,60 @@
<?php
class BackupAdmin extends Backend {
/**
* Backup admin
*/
public static function main() {
$backups_path = ROOT . DS . 'backups';
$backups_list = array();
// Create backup
// -------------------------------------
if (Request::post('create_backup')) {
@set_time_limit(0);
@ini_set("memory_limit", "512M");
$zip = Zip::factory();
// Add storage folder
$zip->readDir(STORAGE . DS, false);
// Add public folder
if (Request::post('add_public_folder')) $zip->readDir(ROOT . DS . 'public' . DS, false);
// Add plugins folder
if (Request::post('add_plugins_folder')) $zip->readDir(PLUGINS . DS, false);
$zip->archive($backups_path . DS . Date::format(time(), "Y-m-d-H-i-s").'.zip');
}
// Delete backup
// -------------------------------------
if (Request::get('sub_id') == 'backup') {
if (Request::get('delete_file')) {
File::delete($backups_path . DS . Request::get('delete_file'));
Request::redirect(Option::get('siteurl').'admin/index.php?id=backup');
}
}
// Download backup
// -------------------------------------
if (Request::get('download')) {
File::download('../backups/'.Request::get('download'));
}
// Get backup list
$backups_list = File::scan($backups_path, '.zip');
// Display view
View::factory('box/backup/views/backend/index')
->assign('backups_list', $backups_list)
->display();
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Backup plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Backup', 'backup'),
__('Backup manager', 'backup'),
'1.0.0',
'Awilum',
'http://monstra.org/',
null,
'box');
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) {
Navigation::add(__('Backups', 'backup'), 'system', 'backup', 3);
// Include Backup Admin
Plugin::admin('backup', 'box');
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<plugin_location>plugins/box/backup/backup.plugin.php</plugin_location>
<plugin_status>active</plugin_status>
<plugin_priority>8</plugin_priority>
<plugin_name>Backup</plugin_name>
<plugin_description>Backup 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,17 @@
<?php
return array(
'backup' => array(
'Backups' => 'Backups',
'Backup date' => 'Backup date',
'Create backup' => 'Create backup',
'Delete' => 'Delete',
'storage' => 'storage',
'public' => 'public',
'plugins' => 'plugins',
'Size' => 'Size',
'Actions' => 'Actions',
'Delete backup: :backup' => 'Delete backup: :backup',
'Creating...' => 'Creating...',
)
);

View File

@@ -0,0 +1,17 @@
<?php
return array(
'backup' => array(
'Backups' => 'Бекапы',
'Backup date' => 'Бекап',
'Create backup' => 'Сделать бекап',
'Delete' => 'Удалить',
'storage' => 'данные',
'public' => 'публичная',
'plugins' => 'плагины',
'Size' => 'Размер',
'Actions' => 'Действия',
'Delete backup: :backup' => 'Удалить бекап: :backup',
'Creating...' => 'Создание...',
)
);

View File

@@ -0,0 +1,48 @@
<h2><?php echo __('Backups', 'backup'); ?></h2>
<br />
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<script>
$().ready(function(){$('[name=create_backup]').click(function(){$(this).button('loading');});});
</script>
<?php
echo (
Form::open() .
Form::checkbox('add_storage_folder', null, true, array('disabled' => 'disabled')) . ' ' . __('storage', 'backup') . ' ' . Html::nbsp(2) .
Form::checkbox('add_public_folder') . ' ' . __('public', 'backup') . ' ' . Html::nbsp(2) .
Form::checkbox('add_plugins_folder') . ' ' . __('plugins', 'backup') . ' ' . Html::nbsp(2) .
Form::submit('create_backup', __('Create backup', 'backup'), array('class' => 'btn default btn-small', 'data-loading-text' => __('Creating...', 'backup'))).
Form::close()
);
?>
<!-- Backup_list -->
<table class="table table-bordered">
<thead>
<tr>
<td><?php echo __('Backup date', 'backup'); ?></td>
<td><?php echo __('Size', 'backup'); ?></td>
<td width="30%"><?php echo __('Actions', 'backup'); ?></td>
</tr>
</thead>
<tbody>
<?php if (count($backups_list) > 0) rsort($backups_list); foreach ($backups_list as $backup) { ?>
<tr>
<td>
<?php $name = strtotime(str_replace('-', '', basename($backup, '.zip'))); ?>
<?php echo Html::anchor(Date::format($name, 'F jS, Y - g:i A'), Option::get('siteurl').'admin/index.php?id=backup&download='.$backup); ?>
</td>
<td><?php echo Number::byteFormat(filesize(ROOT . DS . 'backups' . DS . $backup)); ?></td>
<td>
<?php echo Html::anchor(__('Delete', 'backup'),
'index.php?id=system&sub_id=backup&delete_file='.$backup,
array('class' => 'btn btn-actions', 'onclick' => "return confirmDelete('".__('Delete backup: :backup', 'backup', array(':backup' => Date::format($name, 'F jS, Y - g:i A')))."')"));
?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<!-- /Backup_list -->

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 -->

View File

@@ -0,0 +1,43 @@
<?php
/**
* Editor plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Editor', 'editor'),
__('Editor plugin', 'editor'),
'1.0.0',
'Awilum',
'http://monstra.org/',
null,
'box');
// Add action
Action::add('admin_editor', 'Editor::render', 10, array());
/**
* Editor class
*/
class Editor {
/**
* Render editor
*
* @param string $val editor data
*/
public static function render($val = null) {
echo ('<div id="editor_panel"></div><div><textarea id="editor_area" name="editor" style="width:100%; height:320px;">'.$val.'</textarea></div>');
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<plugin_location>plugins/box/editor/editor.plugin.php</plugin_location>
<plugin_status>active</plugin_status>
<plugin_priority>1</plugin_priority>
<plugin_name>Editor</plugin_name>
<plugin_description>Editor 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,8 @@
<?php
return array(
'Editor' => array(
'Editor' => 'Editor',
'Editor plugin' => 'Editor plugin',
)
);

View File

@@ -0,0 +1,8 @@
<?php
return array(
'Editor' => array(
'Editor' => 'Редактор',
'Editor plugin' => 'Редактор плагин',
)
);

View File

@@ -0,0 +1,146 @@
<?php
Navigation::add(__('Files', 'filesmanager'), 'content', 'filesmanager', 2);
class FilesmanagerAdmin extends Backend {
/**
* Main function
*/
public static function main() {
// Array of forbidden types
$forbidden_types = array('php', 'htaccess', 'html', 'htm', 'empty');
// Array of image types
$image_types = array('jpg', 'png', 'bmp', 'gif', 'tif');
// Get Site url
$site_url = Option::get('siteurl');
// Init vars
if (Request::get('path')) $path = Request::get('path'); else $path = 'uploads/';
// Add slash if not exists
if (substr($path, -1, 1) != '/') {
$path .= '/';
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
}
// Upload corectly!
if ($path == 'uploads' || $path == 'uploads//') {
$path = 'uploads/';
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
}
// Only 'uploads' folder!
if (strpos($path, 'uploads') === false) {
$path = 'uploads/';
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
}
// Set default path value if path is empty
if ($path == '') {
$path = 'uploads/';
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
}
$files_path = ROOT . DS . 'public' . DS . $path;
$files_list = array();
$current = explode('/', $path);
// Get information about current path
$_list = FilesmanagerAdmin::fdir($files_path);
$files_list = array();
// Get files
if (isset($_list['files'])) {
foreach ($_list['files'] as $files) {
$files_list[] = $files;
}
}
$dir_list = array();
// Get dirs
if (isset($_list['dirs'])) {
foreach ($_list['dirs'] as $dirs) {
if (strpos($dirs, '.') === false) $dir_list[] = $dirs;
}
}
// Delete file
// -------------------------------------
if (Request::get('id') == 'filesmanager') {
if (Request::get('delete_file')) {
File::delete($files_path.Request::get('delete_file'));
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
}
}
// Delete dir
// -------------------------------------
if (Request::get('id') == 'filesmanager') {
if (Request::get('delete_dir')) {
Dir::delete($files_path.Request::get('delete_dir'));
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
}
}
// Upload file
// -------------------------------------
if (Request::post('upload_file')) {
if ($_FILES['file']) {
if ( ! in_array(File::ext($_FILES['file']['name']), $forbidden_types)) {
move_uploaded_file($_FILES['file']['tmp_name'], $files_path.Security::safeName(basename($_FILES['file']['name'], File::ext($_FILES['file']['name'])), '-', true).'.'.File::ext($_FILES['file']['name']));
Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$path);
}
}
}
// Display view
View::factory('box/filesmanager/views/backend/index')
->assign('path', $path)
->assign('current', $current)
->assign('files_list', $files_list)
->assign('dir_list', $dir_list)
->assign('forbidden_types', $forbidden_types)
->assign('image_types', $image_types)
->assign('site_url', $site_url)
->assign('files_path', $files_path)
->display();
}
/**
* Get directories and files in current path
*/
protected static function fdir($dir, $type = null) {
$files = array();
$c = 0;
$_dir = $dir;
if (is_dir($dir)) {
$dir = opendir ($dir);
while (false !== ($file = readdir($dir))) {
if (($file !=".") && ($file !="..")) {
$c++;
if (is_dir($_dir.$file)) {
$files['dirs'][$c] = $file;
} else {
$files['files'][$c] = $file;
}
}
}
closedir($dir);
return $files;
} else {
return false;
}
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Files manager plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Files manager', 'filesmanager'),
__('Files manager', 'filesmanager'),
'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('filesmanager', 'box');
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<plugin_location>plugins/box/filesmanager/filesmanager.plugin.php</plugin_location>
<plugin_status>active</plugin_status>
<plugin_priority>2</plugin_priority>
<plugin_name>FilesManager</plugin_name>
<plugin_description>Simple file manger for Monstra</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,17 @@
<?php
return array(
'filesmanager' => array(
'Files' => 'Files',
'Files manager' => 'Files manager',
'Name' => 'Name',
'Actions' => 'Actions',
'Delete' => 'Delete',
'Upload' => 'Upload',
'directory' => 'directory',
'Delete directory: :dir' => 'Delete directory: :dir',
'Delete file: :file' => 'Delete file :file',
'Extension' => 'Extension',
'Size' => 'Size',
)
);

View File

@@ -0,0 +1,17 @@
<?php
return array(
'filesmanager' => array(
'Files' => 'Файлы',
'Files manager' => 'Менеджер файлов',
'Name' => 'Название',
'Actions' => 'Действия',
'Delete' => 'Удалить',
'Upload' => 'Загрузить',
'directory' => 'директория',
'Delete directory: :dir' => 'Удалить директорию: :dir',
'Delete file: :file' => 'Удалить файл :file',
'Extension' => 'Расширение',
'Size' => 'Размер',
)
);

View File

@@ -0,0 +1,80 @@
<h2><?php echo __('Files', 'filesmanager'); ?></h2>
<br />
<!-- Filesmanager_upload_files -->
<?php
echo (
Form::open(null, array('enctype' => 'multipart/form-data')).
Form::input('file', null, array('type' => 'file', 'size' => '25')).Html::br().
Form::submit('upload_file', __('Upload', 'filesmanager'), array('class' => 'btn default btn-small')).
Form::close()
)
?>
<!-- /Filesmanager_upload_files -->
<!-- Filesmanger_path -->
<ul class="breadcrumb">
<?php
$path_parts = explode ('/',$path);
$s = '';
foreach ($path_parts as $p) {
$s .= $p.'/';
if($p == $current[count($current)-2]) $active = ' class="active"'; else $active = '';
echo '<span class="divider">/<span> <li'.$active.'><a href="index.php?id=filesmanager&path='.$s.'">'.$p.'</a></li>';
}
?>
</ul>
<!-- /Filesmanger_path -->
<table class="table table-bordered">
<thead>
<tr>
<td><?php echo __('Name', 'filesmanager'); ?></td>
<td><?php echo __('Extension', 'filesmanager'); ?></td>
<td><?php echo __('Size', 'filesmanager'); ?></td>
<td width="30%"><?php echo __('Actions', 'filesmanager'); ?></td>
</tr>
</thead>
<tbody>
<?php if (isset($dir_list)) foreach ($dir_list as $dir) { ?>
<tr>
<td>
<b><?php echo Html::anchor($dir, 'index.php?id=filesmanager&path='.$path.$dir.'/'); ?></b>
</td>
<td>
</td>
<td>
<?php echo Number::byteFormat(Dir::size(UPLOADS . DS . $dir)); ?>
</td>
<td>
<?php echo Html::anchor(__('Delete', 'filesmanager'),
'index.php?id=filesmanager&delete_dir='.$dir.'&path='.$path,
array('class' => 'btn', 'onclick' => "return confirmDelete('".__('Delete directory: :dir', 'filesmanager', array(':dir' => $dir))."')"));
?>
</td>
</tr>
<?php } ?>
<?php if (isset($files_list)) foreach ($files_list as $file) { $ext = File::ext($file); ?>
<?php if ( ! in_array($ext, $forbidden_types)) { ?>
<tr>
<td>
<?php echo Html::anchor(File::name($file), $site_url.'public' . DS .$path.$file, array('target'=>'_blank'));?>
</td>
<td>
<?php echo $ext; ?>
</td>
<td>
<?php echo Number::byteFormat(filesize($files_path. DS .$file)); ?>
</td>
<td>
<?php echo Html::anchor(__('Delete', 'filesmanager'),
'index.php?id=filesmanager&delete_file='.$file.'&path='.$path,
array('class' => 'btn btn-actions', 'onclick' => "return confirmDelete('".__('Delete file: :file', 'filesmanager', array(':file' => $file))."')"));
?>
</td>
</tr>
<?php } } ?>
</tbody>
</table>

View File

@@ -0,0 +1,20 @@
<?php
Navigation::add(__('Information', 'information'), 'system', 'information', 5);
class InformationAdmin extends Backend {
/**
* Information main function
*/
public static function main() {
// Display view
View::factory('box/information/views/backend/index')->display();
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Information plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Information', 'information'),
__('Information plugin', 'information'),
'1.0.0',
'Awilum',
'http://monstra.org/',
null,
'box');
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) {
// Include Information Admin
Plugin::Admin('information', 'box');
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<plugin_location>plugins/box/information/information.plugin.php</plugin_location>
<plugin_status>active</plugin_status>
<plugin_priority>7</plugin_priority>
<plugin_name>Information</plugin_name>
<plugin_description>Information plugin</plugin_description>
<plugin_version>1.0.0</plugin_version>
<plugin_author>Awilum</plugin_author>
<plugin_author_uri>http://awilum.webdevart.ru/</plugin_author_uri>
</root>

View File

@@ -0,0 +1,27 @@
<?php
return array(
'information' => array(
'Information' => 'Information',
'Debuging' => 'Debuging',
'Name' => 'Name',
'Value' => 'Value',
'Security' => 'Security',
'System' => 'System',
'on' => 'on',
'off'=> 'off',
'System version' => 'System version',
'System version ID' => 'System version ID',
'Security check results' => 'Security check results',
'The configuration file has been found to be writable. We would advise you to remove all write permissions on defines.php on production systems.' =>
'The configuration file has been found to be writable. We would advise you to remove all write permissions on defines.php on production systems.',
'The Monstra core directory (":path") and/or files underneath it has been found to be writable. We would advise you to remove all write permissions. <br/>You can do this on unix systems with: <code>chmod -R a-w :path</code>' =>
'The Monstra core directory (":path") and/or files underneath it has been found to be writable. We would advise you to remove all write permissions. <br/>You can do this on unix systems with: <code>chmod -R a-w :path</code>',
'The Monstra .htaccess file has been found to be writable. We would advise you to remove all write permissions. <br/>You can do this on unix systems with: <code>chmod a-w :path</code>' =>
'The Monstra .htaccess file has been found to be writable. We would advise you to remove all write permissions. <br/>You can do this on unix systems with: <code>chmod a-w :path</code>',
'The Monstra index.php file has been found to be writable. We would advise you to remove all write permissions. <br/>You can do this on unix systems with: <code>chmod a-w :path</code>' =>
'The Monstra index.php file has been found to be writable. We would advise you to remove all write permissions. <br/>You can do this on unix systems with: <code>chmod a-w :path</code>',
'Due to the type and amount of information an error might give intruders when Core::$environment = Core::DEVELOPMENT, we strongly advise setting Core::PRODUCTION in production systems.',
'Due to the type and amount of information an error might give intruders when Core::$environment = Core::DEVELOPMENT, we strongly advise setting Core::PRODUCTION in production systems.',
)
);

View File

@@ -0,0 +1,27 @@
<?php
return array(
'information' => array(
'Information' => 'Информация',
'Debuging' => 'Дебагинг',
'Name' => 'Название',
'Value' => 'Значение',
'Security' => 'Безопасность',
'System' => 'Система',
'on' => 'включен',
'off'=> 'выключен',
'System version' => 'Версия системы',
'System version ID' => 'Версия системы ID',
'Security check results' => 'Результаты проверки безопасности',
'The configuration file has been found to be writable. We would advise you to remove all write permissions on defines.php on production systems.' =>
'Конфигурационный файл доступен для записи. Мы рекомендуем вам удалить права записи на файл defines.php на живом сайте.',
'The Monstra core directory (":path") and/or files underneath it has been found to be writable. We would advise you to remove all write permissions. <br/>You can do this on unix systems with: <code>chmod -R a-w :path</code>' =>
'Директория Monstra (":path") доступна для записи. Мы рекомендуем вам удалить права записи на директорию (":path") на живом сайте. <br/> Вы можете сделать это на UNIX системах так: <code>chmod -R a-w :path</code>',
'The Monstra .htaccess file has been found to be writable. We would advise you to remove all write permissions. <br/>You can do this on unix systems with: <code>chmod a-w :path</code>' =>
'Главный .htaccess доступен для записи. Мы рекомендуем вам удалить права записи на главный .htaccess файл. <br/> Вы можете сделать это на UNIX системах так: <code>chmod -R a-w :path</code>',
'The Monstra index.php file has been found to be writable. We would advise you to remove all write permissions. <br/>You can do this on unix systems with: <code>chmod a-w :path</code>' =>
'Главный index.php файл доступен для записи. Мы рекомендуем вам удалить права записи на главный index.php файл. <br/> Вы можете сделать это на UNIX системах так: <code>chmod -R a-w :path</code>',
'Due to the type and amount of information an error might give intruders when Core::$environment = Core::DEVELOPMENT, we strongly advise setting Core::PRODUCTION in production systems.' =>
'Система работает в режиме Core::DEVELOPMENT Мы рекомендуем вам установить режим Core::PRODUCTION на живом сайте.',
)
);

View File

@@ -0,0 +1,89 @@
<h2><?php echo __('Information', 'information'); ?></h2>
<br />
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active"><a href="#system" data-toggle="tab"><?php echo __('System', 'information'); ?></a></li>
<li><a href="#security" data-toggle="tab"><?php echo __('Security', 'information'); ?></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="system">
<table class="table table-bordered">
<thead>
<tr>
<td><?php echo __('Name', 'information'); ?></td>
<td><?php echo __('Value', 'information'); ?></td>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo __('System version', 'information'); ?></td>
<td><?php echo MONSTRA_VERSION; ?></td>
</tr>
<tr>
<td><?php echo __('System version ID', 'information'); ?></td>
<td><?php echo MONSTRA_VERSION_ID; ?></td>
</tr>
<tr>
<td><?php echo __('GZIP', 'information'); ?></td>
<td><?php if (MONSTRA_GZIP) { echo __('on', 'information'); } else { echo __('off', 'information'); } ?></td>
</tr>
<tr>
<td><?php echo __('Debuging', 'information'); ?></td>
<td><?php if (Core::$environment == Core::DEVELOPMENT) { echo __('on', 'information'); } else { echo __('off', 'information'); } ?></td>
</tr>
</tbody>
</table>
</div>
<div class="tab-pane" id="security">
<?php clearstatcache(); ?>
<table class="table table-bordered">
<thead>
<tr>
<td colspan="2"><?php echo __('Security check results', 'information'); ?></td>
</tr>
</thead>
<tbody>
<?php if (File::writable(BOOT . DS . 'defines.php')) { ?>
<tr>
<td><span class="badge badge-error" style="padding-left:5px; padding-right:5px;"><b>!</b></span> </td>
<td><?php echo __('The configuration file has been found to be writable. We would advise you to remove all write permissions on defines.php on production systems.', 'information'); ?></td>
</tr>
<?php } ?>
<?php if (File::writable(MONSTRA . DS)) { ?>
<tr>
<td><span class="badge badge-error" style="padding-left:5px; padding-right:5px;"><b>!</b></span> </td>
<td><?php echo __('The Monstra core directory (":path") and/or files underneath it has been found to be writable. We would advise you to remove all write permissions. <br/>You can do this on unix systems with: <code>chmod -R a-w :path</code>', 'information', array(':path' => MONSTRA . DS)); ?></td>
</tr>
<?php } ?>
<?php if (File::writable(ROOT . DS . '.htaccess')) { ?>
<tr>
<td><span class="badge badge-error" style="padding-left:5px; padding-right:5px;"><b>!</b></span> </td>
<td><?php echo __('The Monstra .htaccess file has been found to be writable. We would advise you to remove all write permissions. <br/>You can do this on unix systems with: <code>chmod a-w :path</code>', 'information', array(':path' => ROOT . DS . '.htaccess')); ?></td>
</tr>
<?php } ?>
<?php if (File::writable(ROOT . DS . 'index.php')) { ?>
<tr>
<td><span class="badge badge-error" style="padding-left:5px; padding-right:5px;"><b>!</b></span> </td>
<td><?php echo __('The Monstra index.php file has been found to be writable. We would advise you to remove all write permissions. <br/>You can do this on unix systems with: <code>chmod a-w :path</code>', 'information', array(':path' => ROOT . DS . 'index.php')); ?></td>
</tr>
<?php } ?>
<?php if (Core::$environment == Core::DEVELOPMENT) { ?>
<tr>
<td><span class="badge badge-warning" style="padding-left:5px; padding-right:5px;"><b>!</b></span> </td>
<td><?php echo __('Due to the type and amount of information an error might give intruders when Core::$environment = Core::DEVELOPMENT, we strongly advise setting Core::PRODUCTION in production systems.', 'information'); ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>

View 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>

View 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',
)
);

View 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' => 'Выбрать страницу',
)
);

View 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;
}
}

View 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();
}
}

View 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>

View 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>

View 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>

View 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 = '';
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<plugin_location>plugins/box/pages/pages.plugin.php</plugin_location>
<plugin_status>active</plugin_status>
<plugin_priority>1</plugin_priority>
<plugin_name>Pages</plugin_name>
<plugin_description>Pages 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>

View File

@@ -0,0 +1,47 @@
<?php
return array(
'pages' => array(
'Pages' => 'Pages',
'Pages manager' => 'Pages manager',
'Content' => 'Content',
'Create new page' => 'Create new page',
'New page' => 'New page',
'Edit page' => 'Edit page',
'Date' => 'Date',
'Clone' => 'Clone',
'Edit' => 'Edit',
'Delete' => 'Delete',
'Delete page: :page' => 'Delete page: :page',
'Title' => 'Title',
'Name' => 'Name',
'Author' => 'Author',
'Name (slug)' => 'Name (slug)',
'Description' => 'Description',
'Keywords' => 'Keywords',
'Parent' => 'Parent',
'Template' => 'Template',
'Year' => 'Year',
'Day' => 'day',
'Month' => 'Month',
'Hour' => 'Hour',
'Minute' => 'Minute',
'Second' => 'Second',
'This field should not be empty' => 'This field should not be empty',
'This page already exists' => 'This page already exists',
'Extra' => 'Extra',
'Save' => 'Save',
'Save and exit' => 'Save and exit',
'Your changes to the page <i>:page</i> have been saved.' => 'Your changes to the page <i> :page </i> have been saved.',
'The page <i>:page</i> cloned.' => 'The page <i>:page</i> cloned.',
'Status' => 'Status',
'Actions' => 'Actions',
'Add' => 'Add',
'Published' => 'Published',
'Draft' => 'Draft',
'Published on' => 'Published on',
'Edit 404 page' => 'Edit 404 page',
'Page <i>:page</i> deleted' => 'Page <i>:page</i> deleted',
'Search Engines Robots' => 'Search Engines Robots',
)
);

View File

@@ -0,0 +1,47 @@
<?php
return array(
'pages' => array(
'Pages' => 'Страницы',
'Pages manager' => 'Менеджер страниц',
'Content' => 'Контент',
'Create new page' => 'Создать новую страницу',
'New page' => 'Новая страница',
'Edit page' => 'Редактирование страницы',
'Date' => 'Дата',
'Clone' => 'Клонировать',
'Edit' => 'Редактировать',
'Delete' => 'Удалить',
'Delete page: :page' => 'Удалить страницу: :page',
'Title' => 'Заголовок',
'Name' => 'Название',
'Author' => 'Автор',
'Name (slug)' => 'Название (slug)',
'Description' => 'Описание',
'Keywords' => 'Ключевые слова',
'Parent' => 'Родитель',
'Template' => 'Шаблон',
'Year' => 'Год',
'Day' => 'День',
'Month' => 'Месяц',
'Hours' => 'Час',
'Minute' => 'Минута',
'Second' => 'Секунда',
'This field should not be empty' => 'Это поле не должно быть пустым',
'This page already exists' => 'Такая страница уже существует',
'Extra' => 'Дополнительно',
'Save' => 'Сохранить',
'Save and exit' => 'Сохранить и выйти',
'Your changes to the page <i>:page</i> have been saved.' => 'Ваши изменения к странице <i>:page</i> были сохранены.',
'The page <i>:page</i> cloned.' => 'Страница <i>:page</i> клонирована.',
'Status' => 'Статус',
'Actions' => 'Действия',
'Add' => 'Добавить',
'Published' => 'Опубликовано',
'Draft' => 'Черновик',
'Published on' => 'Опубликовано',
'Edit 404 page' => 'Редактировать страницу 404',
'Page <i>:page</i> deleted' => 'Страница <i>:page</i> удалена',
'Search Engines Robots' => 'Поисковые роботы',
),
);

View File

@@ -0,0 +1,499 @@
<?php
Navigation::add(__('Pages', 'pages'), 'content', 'pages', 1);
class PagesAdmin extends Backend {
/**
* Pages admin function
*/
public static function main() {
$current_theme = Option::get('theme_site_name');
$site_url = Option::get('siteurl');
$templates_path = THEMES_SITE;
$errors = array();
$pages = new Table('pages');
$users = new Table('users');
$user = $users->select('[id='.Session::get('user_id').']', null);
$user['firstname'] = Html::toText($user['firstname']);
$user['lastname'] = Html::toText($user['lastname']);
// Page author
if (isset($user['firstname']) && trim($user['firstname']) !== '') {
if (trim($user['lastname']) !== '') $lastname = ' '.$user['lastname']; else $lastname = '';
$author = $user['firstname'] . $lastname;
} else {
$author = Session::get('user_login');
}
// Status array
$status_array = array('published' => __('Published', 'pages'),
'draft' => __('Draft', 'pages'));
// Check for get actions
// ---------------------------------------------
if (Request::get('action')) {
// Switch actions
// -----------------------------------------
switch (Request::get('action')) {
// Clone page
// -------------------------------------
case "clone_page":
// Generate rand page name
$rand_page_name = Request::get('name').'_clone_'.date("Ymd_His");
// Get original page
$orig_page = $pages->select('[slug="'.Request::get('name').'"]', null);
// Clone page
if($pages->insert(array('slug' => $rand_page_name,
'template' => $orig_page['template'],
'parent' => $orig_page['parent'],
'robots_index' => $orig_page['robots_index'],
'robots_follow'=> $orig_page['robots_follow'],
'status' => $orig_page['status'],
'title' => $rand_page_name,
'description' => $orig_page['description'],
'keywords' => $orig_page['keywords'],
'date' => $orig_page['date'],
'author' => $orig_page['author']))) {
// Get cloned page ID
$last_id = $pages->lastId();
// Save cloned page content
File::setContent(STORAGE . DS . 'pages' . DS . $last_id . '.page.txt',
File::getContent(STORAGE . DS . 'pages' . DS . $orig_page['id'] . '.page.txt'));
// Send notification
Notification::set('success', __('The page <i>:page</i> cloned.', 'pages', array(':page' => Security::safeName(Request::get('name'), '-', true))));
}
// Run add extra actions
Action::run('admin_pages_action_clone');
// Redirect
Request::redirect('index.php?id=pages');
break;
// Add page
// -------------------------------------
case "add_page":
// Add page
if (Request::post('add_page') || Request::post('add_page_and_exit')) {
if (Security::check(Request::post('csrf'))) {
// Get pages parent
if (Request::post('pages') == '0') {
$parent_page = '';
} else {
$parent_page = Request::post('pages');
}
// Validate
//--------------
if (trim(Request::post('page_name')) == '') $errors['pages_empty_name'] = __('This field should not be empty', 'pages');
$page = $pages->select('[slug="'.Security::safeName(Request::post('page_name'), '-', true).'"]');
if (count($page) != 0) $errors['pages_exists'] = __('This page already exists', 'pages');
if (trim(Request::post('page_title')) == '') $errors['pages_empty_title'] = __('This field should not be empty', 'pages');
// Generate date
$date = mktime(Request::post('hour'),
Request::post('minute'),
Request::post('second'),
Request::post('month'),
Request::post('day'),
Request::post('year'));
if (Request::post('robots_index')) $robots_index = 'noindex'; else $robots_index = 'index';
if (Request::post('robots_follow')) $robots_follow = 'nofollow'; else $robots_follow = 'follow';
// If no errors then try to save
if (count($errors) == 0) {
// Insert new page
if($pages->insert(array('slug' => Security::safeName(Request::post('page_name'), '-', true),
'template' => Request::post('templates'),
'parent' => $parent_page,
'status' => Request::post('status'),
'robots_index' => $robots_index,
'robots_follow'=> $robots_follow,
'title' => Request::post('page_title'),
'description' => Request::post('page_description'),
'keywords' => Request::post('page_keywords'),
'date' => $date,
'author' => $author))) {
// Get inserted page ID
$last_id = $pages->lastId();
// Save content
File::setContent(STORAGE . DS . 'pages' . DS . $last_id . '.page.txt', XML::safe(Request::post('editor')));
// Send notification
Notification::set('success', __('Your changes to the page <i>:page</i> have been saved.', 'pages', array(':page' => Security::safeName(Request::post('page_title'), '-', true))));
}
// Run add extra actions
Action::run('admin_pages_action_add');
// Redirect
if (Request::post('add_page_and_exit')) {
Request::redirect('index.php?id=pages');
} else {
Request::redirect('index.php?id=pages&action=edit_page&name='.Security::safeName(Request::post('page_name'), '-', true));
}
}
} else { die('csrf detected!'); }
}
// Get all pages
$pages_list = $pages->select('[slug!="error404" and parent=""]');
$pages_array[] = '-none-';
foreach ($pages_list as $page) {
$pages_array[$page['slug']] = $page['title'];
}
// Get all templates
$templates_list = File::scan($templates_path, '.template.php');
foreach ($templates_list as $file) {
$templates_array[basename($file, '.template.php')] = basename($file, '.template.php');
}
// Save fields
if (Request::post('pages')) $parent_page = Request::post('pages'); else $parent_page = '';
if (Request::post('page_name')) $post_name = Request::post('page_name'); else $post_name = '';
if (Request::post('page_title')) $post_title = Request::post('page_title'); else $post_title = '';
if (Request::post('page_keywords')) $post_keywords = Request::post('page_keywords'); else $post_keywords = '';
if (Request::post('page_description')) $post_description = Request::post('page_description'); else $post_description = '';
if (Request::post('editor')) $post_content = Request::post('editor'); else $post_content = '';
if (Request::post('templates')) $post_template = Request::post('templates'); else $post_template = 'index';
if (Request::post('robots_index')) $post_robots_index = true; else $post_robots_index = false;
if (Request::post('robots_follow')) $post_robots_follow = true; else $post_robots_follow = false;
if (Request::post('parent_page')) {
$post_template = Request::post('pages');
} else {
if(Request::get('parent_page')) {
$parent_page = trim(Request::get('parent_page'));
}
}
//--------------
// Generate date
$date = explode('-', Date::format(time(), 'Y-m-d-H-i-s'));
// Display view
View::factory('box/pages/views/backend/add')
->assign('post_name', $post_name)
->assign('post_title', $post_title)
->assign('post_description', $post_description)
->assign('post_keywords', $post_keywords)
->assign('post_content', $post_content)
->assign('pages_array', $pages_array)
->assign('parent_page', $parent_page)
->assign('templates_array', $templates_array)
->assign('post_template', $post_template)
->assign('status_array', $status_array)
->assign('date', $date)
->assign('post_robots_index', $post_robots_index)
->assign('post_robots_follow', $post_robots_follow)
->assign('errors', $errors)
->display();
break;
// Edit page
// -------------------------------------
case "edit_page":
if (Request::post('edit_page') || Request::post('edit_page_and_exit')) {
if (Security::check(Request::post('csrf'))) {
// Get pages parent
if (Request::post('pages') == '0') {
$parent_page = '';
} else {
$parent_page = Request::post('pages');
}
// Save field
$post_parent = Request::post('pages');
// Validate
//--------------
if (trim(Request::post('page_name')) == '') $errors['pages_empty_name'] = __('This field should not be empty', 'pages');
$_page = $pages->select('[slug="'.Security::safeName(Request::post('page_name'), '-', true).'"]');
if ((count($_page) != 0) and (Security::safeName(Request::post('page_old_name'), '-', true) !== Security::safeName(Request::post('page_name'), '-', true))) $errors['pages_exists'] = __('This page already exists', 'pages');
if (trim(Request::post('page_title')) == '') $errors['pages_empty_title'] = __('This field should not be empty', 'pages');
// Save fields
if (Request::post('page_name')) $post_name = Request::post('page_name'); else $post_name = '';
if (Request::post('page_title')) $post_title = Request::post('page_title'); else $post_title = '';
if (Request::post('page_keywords')) $post_keywords = Request::post('page_keywords'); else $post_keywords = '';
if (Request::post('page_description')) $post_description = Request::post('page_description'); else $post_description = '';
if (Request::post('editor')) $post_content = Request::post('editor'); else $post_content = '';
if (Request::post('templates')) $post_template = Request::post('templates'); else $post_template = 'index';
if (Request::post('robots_index')) $post_robots_index = true; else $post_robots_index = false;
if (Request::post('robots_follow')) $post_robots_follow = true; else $post_robots_follow = false;
//--------------
// Generate date
$date = mktime(Request::post('hour'),
Request::post('minute'),
Request::post('second'),
Request::post('month'),
Request::post('day'),
Request::post('year'));
if (Request::post('robots_index')) $robots_index = 'noindex'; else $robots_index = 'index';
if (Request::post('robots_follow')) $robots_follow = 'nofollow'; else $robots_follow = 'follow';
if (count($errors) == 0) {
// Update parents in all childrens
if ((Security::safeName(Request::post('page_name'), '-', true)) !== (Security::safeName(Request::post('page_old_name'), '-', true)) and (Request::post('old_parent') == '')) {
$pages->updateWhere('[parent="'.Request::get('name').'"]', array('parent' => Text::translitIt(trim(Request::post('page_name')))));
if ($pages->updateWhere('[slug="'.Request::get('name').'"]',
array('slug' => Security::safeName(Request::post('page_name'), '-', true),
'template' => Request::post('templates'),
'parent' => $parent_page,
'title' => Request::post('page_title'),
'description' => Request::post('page_description'),
'keywords' => Request::post('page_keywords'),
'robots_index' => $robots_index,
'robots_follow'=> $robots_follow,
'status' => Request::post('status'),
'date' => $date,
'author' => $author))) {
File::setContent(STORAGE . DS . 'pages' . DS . Request::post('page_id') . '.page.txt', XML::safe(Request::post('editor')));
Notification::set('success', __('Your changes to the page <i>:page</i> have been saved.', 'pages', array(':page' => Security::safeName(Request::post('page_title'), '-', true))));
}
// Run edit extra actions
Action::run('admin_pages_action_edit');
} else {
if ($pages->updateWhere('[slug="'.Request::get('name').'"]',
array('slug' => Security::safeName(Request::post('page_name'), '-', true),
'template' => Request::post('templates'),
'parent' => $parent_page,
'title' => Request::post('page_title'),
'description' => Request::post('page_description'),
'keywords' => Request::post('page_keywords'),
'robots_index' => $robots_index,
'robots_follow'=> $robots_follow,
'status' => Request::post('status'),
'date' => $date,
'author' => $author))) {
File::setContent(STORAGE . DS . 'pages' . DS . Request::post('page_id') . '.page.txt', XML::safe(Request::post('editor')));
Notification::set('success', __('Your changes to the page <i>:page</i> have been saved.', 'pages', array(':page' => Security::safeName(Request::post('page_title'), '-', true))));
}
// Run edit extra actions
Action::run('admin_pages_action_edit');
}
// Redirect
if (Request::post('edit_page_and_exit')) {
Request::redirect('index.php?id=pages');
} else {
Request::redirect('index.php?id=pages&action=edit_page&name='.Security::safeName(Request::post('page_name'), '-', true));
}
}
} else { die('csrf detected!'); }
}
// Get all pages
$pages_list = $pages->select();
$pages_array[] = '-none-';
// Foreach pages find page whithout parent
foreach ($pages_list as $page) {
if (isset($page['parent'])) {
$c_p = $page['parent'];
} else {
$c_p = '';
}
if ($c_p == '') {
// error404 is system "constant" and no child for it
if ($page['slug'] !== 'error404' && $page['slug'] !== Request::get('name')) {
$pages_array[$page['slug']] = $page['title'];
}
}
}
// Get all templates
$templates_list = File::scan($templates_path,'.template.php');
foreach ($templates_list as $file) {
$templates_array[basename($file,'.template.php')] = basename($file, '.template.php');
}
$page = $pages->select('[slug="'.Request::get('name').'"]', null);
if ($page) {
$page_content = File::getContent(STORAGE . DS . 'pages' . DS . $page['id'] . '.page.txt');
// Safe fields or load fields
if (Request::post('page_name')) $slug_to_edit = Request::post('page_name'); else $slug_to_edit = $page['slug'];
if (Request::post('page_title')) $title_to_edit = Request::post('page_title'); else $title_to_edit = $page['title'];
if (Request::post('page_description')) $description_to_edit = Request::post('page_description'); else $description_to_edit = $page['description'];
if (Request::post('page_keywords')) $keywords_to_edit = Request::post('page_keywords'); else $keywords_to_edit = $page['keywords'];
if (Request::post('editor')) $to_edit = Request::post('editor'); else $to_edit = Text::toHtml($page_content);
if (Request::post('robots_index')) $post_robots_index = true; else if ($page['robots_index'] == 'noindex') $post_robots_index = true; else $post_robots_index = false;
if (Request::post('robots_follow')) $post_robots_follow = true; else if ($page['robots_follow'] == 'nofollow') $post_robots_follow = true; else $post_robots_follow = false;
if (Request::post('pages')) {
// Get pages parent
if (post('pages') == '-none-') {
$parent_page = '';
} else {
$parent_page = Request::post('pages');
}
// Save field
$parent_page = Request::post('pages');
} else {
$parent_page = $page['parent'];
}
if (Request::post('templates')) $template = Request::post('templates'); else $template = $page['template'];
if (Request::post('status')) $status = Request::post('status'); else $status = $page['status'];
$date = explode('-', Date::format($page['date'],'Y-m-d-H-i-s'));
// Display view
View::factory('box/pages/views/backend/edit')
->assign('slug_to_edit', $slug_to_edit)
->assign('title_to_edit', $title_to_edit)
->assign('description_to_edit', $description_to_edit)
->assign('keywords_to_edit', $keywords_to_edit)
->assign('page', $page)
->assign('to_edit', $to_edit)
->assign('pages_array', $pages_array)
->assign('parent_page', $parent_page)
->assign('templates_array', $templates_array)
->assign('template', $template)
->assign('status_array', $status_array)
->assign('status', $status)
->assign('date', $date)
->assign('post_robots_index', $post_robots_index)
->assign('post_robots_follow', $post_robots_follow)
->assign('errors', $errors)
->display();
}
break;
// Delete page
// -------------------------------------
case "delete_page":
// Error 404 page can not be removed
if (Request::get('name') !== 'error404') {
// Get page title, delete page and update <parent> fields
$page = $pages->select('[slug="'.Request::get('name').'"]', null);
if ($pages->deleteWhere('[slug="'.Request::get('name').'" ]')) {
$pages->updateWhere('[parent="'.Request::get('name').'"]', 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']))));
}
// Run delete extra actions
Action::run('admin_pages_action_delete');
// Redirect
Request::redirect('index.php?id=pages');
}
break;
}
// Its mean that you can add your own actions for this plugin
Action::run('admin_pages_extra_actions');
} else { // Load main template
$pages_list = $pages->select(null, 'all', null, array('slug', 'title', 'status', 'date', 'author', 'parent'));
$pages_array = array();
$count = 0;
foreach ($pages_list as $page) {
$pages_array[$count]['title'] = $page['title'];
$pages_array[$count]['parent'] = $page['parent'];
$pages_array[$count]['status'] = $status_array[$page['status']];
$pages_array[$count]['date'] = $page['date'];
$pages_array[$count]['author'] = $page['author'];
$pages_array[$count]['slug'] = $page['slug'];
if (isset($page['parent'])) {
$c_p = $page['parent'];
} else {
$c_p = '';
}
if ($c_p != '') {
$_page = $pages->select('[slug="'.$page['parent'].'"]', null);
if (isset($_page['title'])) {
$_title = $_page['title'];
} else {
$_title = '';
}
$pages_array[$count]['sort'] = $_title . ' ' . $page['title'];
} else {
$pages_array[$count]['sort'] = $page['title'];
}
$_title = '';
$count++;
}
// Sort pages
$pages = Arr::subvalSort($pages_array, 'sort');
// Display view
View::factory('box/pages/views/backend/index')
->assign('pages', $pages)
->assign('site_url', $site_url)
->display();
}
}
}

View File

@@ -0,0 +1,392 @@
<?php
/**
* Pages plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Pages' , 'pages'),
__('Pages manager', 'pages'),
'1.0.0',
'Awilum',
'http://monstra.org/',
'pages',
'box');
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor'))) {
// Include Admin
Plugin::Admin('pages', 'box');
}
class Pages extends Frontend {
/**
* Current page data
*
* @var object
*/
public static $page = null;
/**
* Pages tables
*
* @var object
*/
public static $pages = null;
/**
* Requested page
*
* @var string
*/
public static $requested_page = null;
/**
* Main function
*/
public static function main() {
if (BACKEND == false) {
$pages = new Table('pages');
Pages::$pages = $pages;
$page = Pages::pageLoader();
Pages::$page = $page;
}
}
/**
* Page loader
*
* @param boolean $return_data data
* @return array
*/
public static function pageLoader($return_data = true) {
$requested_page = Pages::lowLoader(Uri::segments());
Pages::$requested_page = $requested_page;
return Pages::$pages->select('[slug="'.$requested_page.'"]', null);
}
/**
* Load current page
*
* @global string $defpage default page
* @param array $data uri
* @return string
*/
public static function lowLoader($data) {
$defpage = Option::get('defaultpage');
// If data count 2 then it has Parent/Child
if (count($data) >= 2) {
// If exists parent file
if (count(Pages::$pages->select('[slug="'.$data[0].'"]')) !== 0) {
// Get child file and get parent page name
$child_page = Pages::$pages->select('[slug="'.$data[1].'"]', null);
// If child page parent is not empty then get his parent
if (count($child_page) == 0) {
$c_p = '';
} else {
if ($child_page['parent'] != '') {
$c_p = $child_page['parent'];
} else {
$c_p = '';
}
}
// Check is child_parent -> request parent
if ($c_p == $data[0]) {
// Checking only for the parent and one child, the remaining issue 404
if (count($data) < 3) {
$id = $data[1]; // Get real request page
} else {
$id = 'error404';
Response::status(404);
}
} else {
$id = 'error404';
Response::status(404);
}
} else {
$id = 'error404';
Response::status(404);
}
} else { // Only parent page come
if(empty($data[0])) {
$id = $defpage;
} else {
// Get current page
$current_page = Pages::$pages->select('[slug="'.$data[0].'"]', null);
if (count($current_page) != 0) {
if ($current_page['parent'] != '') {
$c_p = $current_page['parent'];
} else {
$c_p = '';
}
} else {
$c_p = '';
}
// Check if this page has parent
if ($c_p !== '') {
if ($c_p == $data[0]) {
if (count(Pages::$pages->select('[slug="'.$data[0].'"]', null)) != 0) {
if (($current_page['status'] == 'published') or (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor')))) {
$id = $data[0];
} else {
$id = 'error404';
Response::status(404);
}
} else {
$id = 'error404';
Response::status(404);
}
} else {
$id = 'error404';
Response::status(404);
}
} else {
if (count(Pages::$pages->select('[slug="'.$data[0].'"]', null)) != 0) {
if (($current_page['status'] == 'published') or (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor')))) {
$id = $data[0];
} else {
$id = 'error404';
Response::status(404);
}
} else {
$id = 'error404';
Response::status(404);
}
}
}
}
// Return page name/id to load
return $id;
}
/**
* Get pages template
*
* @return string
*/
public static function template() {
if (Pages::$page['template'] == '') return 'index'; else return Pages::$page['template'];
}
/**
* Get pages contents
*
* @return string
*/
public static function content() {
return Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . Pages::$page['id'] . '.page.txt'));
}
/**
* Get pages title
*
* <code>
* echo Page::title();
* </code>
*
* @return string
*/
public static function title() {
return Pages::$page['title'];
}
/**
* Get pages Description
*
* <code>
* echo Page::description();
* </code>
*
* @return string
*/
public static function description() {
return Pages::$page['description'];
}
/**
* Get pages Keywords
*
* <code>
* echo Page::keywords();
* </code>
*
* @return string
*/
public static function keywords() {
return Pages::$page['keywords'];
}
}
class Page extends Pages {
/**
* Get date of current page
*
* <code>
* echo Page::date();
* </code>
*
* @return string
*/
public static function date() {
return Date::format(Pages::$page['date'], 'Y-m-d');
}
/**
* Get author of current page
*
* <code>
* echo Page::author();
* </code>
*
* @return string
*/
public static function author() {
return Pages::$page['author'];
}
/**
* Get children pages for a specific parent page
*
* <code>
* $pages = Page::children('page');
* </code>
*
* @param string $parent Parent page
* @return array
*/
public static function children($parent) {
return Pages::$pages->select('[parent="'.(string)$parent.'"]', 'all');
}
/**
* Get the available children pages for requested page.
*
* <code>
* echo Page::available();
* </code>
*
*/
public static function available() {
$pages = Pages::$pages->select('[parent="'.Pages::$requested_page.'"]', 'all');
// Display view
View::factory('box/pages/views/frontend/available_pages')
->assign('pages', $pages)
->display();
}
/**
* Get page breadcrumbs
*
* <code>
* echo Page::breadcrumbs();
* </code>
*
*/
public static function breadcrumbs() {
$current_page = Pages::$requested_page;
if ($current_page !== 'error404') {
$page = Pages::$pages->select('[slug="'.$current_page.'"]', null);
if (trim($page['parent']) !== '') {
$parent = true;
$parent_page = Pages::$pages->select('[slug="'.$page['parent'].'"]', null);
} else {
$parent = false;
}
// Display view
View::factory('box/pages/views/frontend/breadcrumbs')
->assign('current_page', $current_page)
->assign('page', $page)
->assign('parent', $parent)
->assign('parent_page', $parent_page)
->display();
}
}
/**
* Get page url
*
* <code>
* echo Page::url();
* </code>
*
*/
public static function url() {
return Option::get('siteurl').Pages::$page['slug'];
}
/**
* Get page slug
*
* <code>
* echo Page::slug();
* </code>
*
*/
public static function slug() {
return Pages::$page['slug'];
}
/**
* Get page meta robots
*
* <code>
* echo Page::robots();
* </code>
*
*/
public static function robots() {
return (Pages::$page !== null) ? Pages::$page['robots_index'].', '.Pages::$page['robots_follow'] : '';
}
}

View File

@@ -0,0 +1,133 @@
<div class="row-fluid">
<div class="span12">
<h2><?php echo __('New page', 'pages'); ?></h2>
<br />
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php if (isset($errors['pages_empty_name']) or isset($errors['pages_exists'])) $error_class1 = 'error'; else $error_class1 = ''; ?>
<?php if (isset($errors['pages_empty_title'])) $error_class2 = 'error'; else $error_class2 = ''; ?>
<?php
echo (
Form::open(null, array('class' => 'form-horizontal'))
);
?>
<?php echo (Form::hidden('csrf', Security::token())); ?>
<?php
echo (
Form::label('page_name', __('Name (slug)', 'pages'))
);
?>
<?php
echo (
Form::input('page_name', $post_name, array('class' => 'span6'))
);
if (isset($errors['pages_empty_name'])) echo Html::nbsp(3).'<span style="color:red">'.$errors['pages_empty_name'].'</span>';
if (isset($errors['pages_exists'])) echo Html::nbsp(3).'<span style="color:red">'.$errors['pages_exists'].'</span>';
?>
<?php
echo (
Html::br(2).
Form::label('page_title', __('Title', 'pages'))
);
?>
<?php
echo (
Form::input('page_title', $post_title, array('class' => 'span6'))
);
if (isset($errors['pages_empty_title'])) echo Html::nbsp(3).'<span style="color:red">'.$errors['pages_empty_title'].'</span>';
?>
<?php
echo (
Html::br(2).
Form::label('page_description', __('Description', 'pages')).
Form::input('page_description', $post_description, array('class' => 'span8')).
Html::br(2).
Form::label('page_keywords', __('Keywords', 'pages')).
Form::input('page_keywords', $post_keywords, array('class' => 'span8'))
);
?>
<br /><br />
<?php Action::run('admin_editor', array(Html::toText($post_content))); ?>
<br />
<div class="row-fluid">
<div class="span4">
<?php
echo (
Form::label('pages', __('Parent', 'pages')).
Form::select('pages', $pages_array, $parent_page)
);
?>
</div>
<div class="span4">
<?php
echo (
Form::label('templates', __('Template', 'pages')).
Form::select('templates', $templates_array, $post_template)
);
?>
</div>
<div class="span4">
<?php
echo (
Form::label('status', __('Status', 'pages')).
Form::select('status', $status_array, 'published')
);
?>
</div>
</div>
<hr>
<div class="row-fluid">
<div class="span8">
<?php
echo (
Form::label(__('Published on', 'pages'), __('Published on', 'pages')).
Form::input('year', $date[0], array('class' => 'input-mini')). ' ' .
Form::input('month', $date[1], array('class' => 'input-mini')). ' ' .
Form::input('day', $date[2], array('class' => 'input-mini')). ' <span style="color:gray;">@</span> '.
Form::input('minute', $date[3], array('class' => 'input-mini')). ' : '.
Form::input('second', $date[4], array('class' => 'input-mini'))
);
?>
</div>
<div class="span3">
<?php
echo (
Form::label('robots', __('Search Engines Robots', 'pages')).
'no Index'.Html::nbsp().Form::checkbox('robots_index', 'index', $post_robots_index).Html::nbsp(2).
'no Follow'.Html::nbsp().Form::checkbox('robots_follow', 'follow', $post_robots_follow)
);
?>
</div>
</div>
<hr>
<?php
echo (
Form::submit('add_page_and_exit', __('Save and exit', 'pages'), array('class' => 'btn')).Html::nbsp(2).
Form::submit('add_page', __('Save', 'pages'), array('class' => 'btn')).
Form::close()
);
?>
</div>
</div>

View File

@@ -0,0 +1,171 @@
<div class="row-fluid">
<div class="span12">
<h2>
<?php
if (Request::get('name') == 'error404') {
echo __('Edit 404 page', 'pages');
} else {
echo __('Edit page', 'pages');
}
?>
</h2>
<br />
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php if (isset($errors['pages_empty_name'])) $error_class1 = 'error'; else $error_class1 = ''; ?>
<?php if (isset($errors['pages_exists'])) $error_class1 = 'error'; else $error_class1 = ''; ?>
<?php if (isset($errors['pages_empty_title'])) $error_class2 = 'error'; else $error_class2 = ''; ?>
<?php
echo (
Form::open(null, array('class' => 'form-horizontal'))
);
?>
<?php echo (Form::hidden('csrf', Security::token())); ?>
<?php
echo (
Form::hidden('page_old_name', Request::get('name'))
);
if (Request::get('name') !== 'error404') {
echo (
Form::label('page_name', __('Name (slug)', 'pages'))
);
}
?>
<?php
if (Request::get('name') == 'error404') {
echo Form::hidden('page_name', $slug_to_edit);
} else {
echo (
Form::input('page_name', $slug_to_edit, array('class' => 'span6'))
);
}
if (isset($errors['pages_empty_name'])) echo Html::nbsp(3).'<span style="color:red">'.$errors['pages_empty_name'].'</span>';
if (isset($errors['pages_exists'])) echo Html::nbsp(3).'<span style="color:red">'.$errors['pages_exists'].'</span>';
?>
<?php
echo (
Html::br(2).
Form::label('page_title', __('Title', 'pages'))
);
?>
<?php
echo (
Form::input('page_title', $title_to_edit, array('class' => 'span6'))
);
if (isset($errors['pages_empty_title'])) echo Html::nbsp(3).'<span style="color:red">'.$errors['pages_empty_title'].'</span>';
?>
<?php
echo (
Html::br(2).
Form::label('page_description', __('Description', 'pages')).
Form::input('page_description', $description_to_edit, array('class' => 'span8')).
Html::br(2).
Form::label('page_keywords', __('Keywords', 'pages')).
Form::input('page_keywords', $keywords_to_edit, array('class' => 'span8')).
Form::hidden('old_parent', $page['parent']).
Form::hidden('page_id', $page['id'])
);
?>
<br /><br />
<?php Action::run('admin_editor', array(Html::toText($to_edit))); ?>
<br />
<div class="row-fluid">
<?php
if (Request::get('name') == 'error404') {
echo Form::hidden('pages', $parent_page);
} else {
?>
<div class="span4">
<?php
echo (
Form::label('pages', __('Parent', 'pages')).
Form::select('pages', $pages_array, $parent_page)
);
?>
</div>
<?php } ?>
<?php if (Request::get('name') != 'error404') { ?>
<div class="span4">
<?php } else { ?>
<div>
<?php } ?>
<?php
echo (
Form::label('templates', __('Template', 'pages')).
Form::select('templates', $templates_array, $template)
);
?>
</div>
<?php
if(Request::get('name') == 'error404') {
echo Form::hidden('status', $status);
} else {
?>
<div class="span4">
<?php
echo (
Form::label('status', __('Status', 'pages')).
Form::select('status', $status_array, $status)
);
?>
</div>
<?php } ?>
</div>
<hr>
<div class="row-fluid">
<div class="span8">
<?php
echo (
Form::label(__('Published on', 'pages'), __('Published on', 'pages')).
Form::input('year', $date[0], array('class' => 'input-mini')). ' ' .
Form::input('month', $date[1], array('class' => 'input-mini')). ' ' .
Form::input('day', $date[2], array('class' => 'input-mini')). ' @ '.
Form::input('minute', $date[3], array('class' => 'input-mini')). ' : '.
Form::input('second', $date[4], array('class' => 'input-mini'))
);
?>
</div>
<div class="span3">
<?php
echo (
Form::label('robots', __('Search Engines Robots', 'pages')).
'no Index'.Html::nbsp().Form::checkbox('robots_index', 'index', $post_robots_index).Html::nbsp(2).
'no Follow'.Html::nbsp().Form::checkbox('robots_follow', 'follow', $post_robots_follow)
);
?>
</div>
</div>
<hr>
<?php
echo (
Form::submit('edit_page_and_exit', __('Save and exit', 'pages'), array('class' => 'btn')).Html::nbsp(2).
Form::submit('edit_page', __('Save', 'pages'), array('class' => 'btn')).
Form::close()
);
?>
</div>
</div>

View File

@@ -0,0 +1,91 @@
<div class="row-fluid">
<div class="span12">
<h2><?php echo __('Pages', 'pages'); ?></h2>
<br />
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php
echo (
Html::anchor(__('Create new page', 'pages'), 'index.php?id=pages&action=add_page', array('title' => __('Create new page', 'pages'), 'class' => 'btn default btn-small')). Html::nbsp(3).
Html::anchor(__('Edit 404 page', 'pages'), 'index.php?id=pages&action=edit_page&name=error404', array('title' => __('Create new page', 'pages'), 'class' => 'btn default btn-small'))
);
?>
<br /><br />
<table class="table table-bordered">
<thead>
<tr>
<td><?php echo __('Name', 'pages'); ?></td>
<td><?php echo __('Author', 'pages'); ?></td>
<td><?php echo __('Status', 'pages'); ?></td>
<td><?php echo __('Date', 'pages'); ?></td>
<td width="40%"><?php echo __('Actions', 'pages'); ?></td>
</tr>
</thead>
<tbody>
<?php
if (count($pages) != 0) {
foreach ($pages as $page) {
if ($page['parent'] != '') { $dash = Html::arrow('right').'&nbsp;&nbsp;'; } else { $dash = ""; }
?>
<?php if ($page['parent'] == '') $parent_style=''; else $parent_style = ''; ?>
<?php if ($page['slug'] != 'error404') { ?>
<tr>
<td>
<?php
if ($page['parent'] != '') {
$parent = $page['parent'].'/';
} else {
$parent = '';
}
?>
<?php
if ($page['parent'] != '') echo '&nbsp;';
?>
<?php echo $dash.Html::anchor(Html::toText($page['title']), $site_url.$parent.$page['slug'], array('target' => '_blank')); ?>
</td>
<td>
<?php echo $page['author']; ?>
</td>
<td>
<?php echo $page['status']; ?>
</td>
<td>
<?php echo Date::format($page['date'], "j.n.Y"); ?>
</td>
<td>
<div class="btn-toolbar">
<div class="btn-group">
<?php echo Html::anchor(__('Edit', 'pages'), 'index.php?id=pages&action=edit_page&name='.$page['slug'], array('class' => 'btn btn-actions')); ?>
<a class="btn dropdown-toggle btn-actions" data-toggle="dropdown" href="#" style="font-family:arial;"><span class="caret"></span></a>
<ul class="dropdown-menu">
<?php if ($page['parent'] == '') { ?>
<li><a href="index.php?id=pages&action=add_page&parent_page=<?php echo $page['slug']; ?>" title="<?php echo __('Create new page', 'pages'); ?>"><?php echo __('Add', 'pages'); ?></a></li>
<?php } ?>
<li><?php echo Html::anchor(__('Clone', 'pages'), 'index.php?id=pages&action=clone_page&name='.$page['slug'], array('title' => __('Clone', 'pages'))); ?></li>
</ul>
<?php echo Html::anchor(__('Delete', 'pages'),
'index.php?id=pages&action=delete_page&name='.$page['slug'],
array('class' => 'btn btn-actions btn-actions-default', 'onclick' => "return confirmDelete('".__("Delete page: :page", 'pages', array(':page' => Html::toText($page['title'])))."')"));
?>
</div>
</div>
</td>
</tr>
<?php } ?>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>

View File

@@ -0,0 +1,5 @@
<ul>
<?php foreach ($pages as $page) { ?>
<li><a href="<?php echo $page['parent'].'/'.$page['slug']; ?>"><?php echo $page['title']; ?></a></li>
<?php } ?>
</ul>

View File

@@ -0,0 +1,5 @@
<?php if ($parent) { ?>
<a href="<?php echo Site::url().$page['parent']; ?>"><?php echo $parent_page['title']; ?></a>&nbsp;<span>&rarr;</span>&nbsp;<a href="<?php echo Site::url().$page['parent'].'/'.$page['slug']; ?>"><?php echo $page['title']; ?></a>
<?php } else { ?>
<a href="<?php echo Site::url().$page['slug']; ?>"><?php echo $page['title']; ?></a>
<?php } ?>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<plugin_location>plugins/box/plugins/plugins.plugin.php</plugin_location>
<plugin_status>active</plugin_status>
<plugin_priority>2</plugin_priority>
<plugin_name>Plugins</plugin_name>
<plugin_description>Plugins 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,20 @@
<?php
return array(
'plugins' => array(
'Plugins' => 'Plugins',
'Name' => 'Name',
'Actions' => 'Actions',
'Description' => 'Description',
'Installed' => 'Installed',
'Install New' => 'Install New',
'Delete' => 'Delete',
'Delete plugin :plugin' => 'Delete plugin :plugin',
'This plugins does not exist' => 'This plugins does not exist',
'Version' => 'Version',
'Author' => 'Author',
'Get More Plugins' => 'Get More Plugins',
'Install' => 'Install',
'Uninstall' => 'Uninstall',
)
);

View File

@@ -0,0 +1,20 @@
<?php
return array(
'plugins' => array(
'Plugins' => 'Плагины',
'Installed' => 'Установленные',
'Install New' => 'Установить новые',
'Actions' => 'Действия',
'Name' => 'Название',
'Description' => 'Описание',
'Delete' => 'Удалить',
'Delete plugin :plugin' => 'Удалить плагин :plugin',
'This plugins does not exist' => 'Такой плагин не существует',
'Version' => 'Версия',
'Author' => 'Автор',
'Get More Plugins' => 'Скачать другие плагины',
'Install' => 'Установить',
'Uninstall' => 'Удалить',
)
);

View File

@@ -0,0 +1,127 @@
<?php if ( ! defined('MONSTRA_ACCESS')) exit('No direct script access allowed');
// Add plugin navigation link
Navigation::add(__('Plugins', 'plugins'), 'extends', 'plugins', 1);
class PluginsAdmin extends Backend {
/**
* Plugins admin
*/
public static function main() {
// Get siteurl
$site_url = Option::get('siteurl');
// Get installed plugin from $plugins array
$installed_plugins = Plugin::$plugins;
// Get installed users plugins
$_users_plugins = array();
foreach (Plugin::$plugins as $plugin) {
if ($plugin['privilege'] !== 'box') $_users_plugins[] = $plugin['id'];
}
// Get plugins table
$plugins = new Table('plugins');
// Delete plugin
// -------------------------------------
if (Request::get('delete_plugin')) {
// Nobody cant remove box plugins
if ($installed_plugins[Text::lowercase(str_replace("Plugin", "", Request::get('delete_plugin')))]['privilege'] !== 'box') {
// Run plugin uninstaller file
$plugin_name = Request::get('delete_plugin');
if (File::exists(PLUGINS . DS . $plugin_name . DS .'install' . DS . $plugin_name . '.uninstall.php')) {
include PLUGINS . DS . $plugin_name . DS . 'install' . DS . $plugin_name . '.uninstall.php';
}
// Clean i18n cache
Cache::clean('i18n');
// Delete plugin form plugins table
$plugins->deleteWhere('[name="'.Request::get('delete_plugin').'"]');
Request::redirect('index.php?id=plugins');
}
}
// Install new plugin
// -------------------------------------
if (Request::get('install')) {
// Load plugin install xml file
$plugin_xml = XML::loadFile(PLUGINS . DS . basename(Text::lowercase(Request::get('install')), '.manifest.xml') . DS . 'install' . DS . Request::get('install'));
// Add plugin to plugins table
$plugins->insert(array('name' => basename(Request::get('install'), '.manifest.xml'),
'location' => (string)$plugin_xml->plugin_location,
'status' => (string)$plugin_xml->plugin_status,
'priority' => (int)$plugin_xml->plugin_priority));
// Clean i18n cache
Cache::clean('i18n');
// Run plugin installer file
$plugin_name = str_replace(array("Plugin", ".manifest.xml"), "", Request::get('install'));
if (File::exists(PLUGINS . DS .basename(Text::lowercase(Request::get('install')), '.manifest.xml') . DS . 'install' . DS .$plugin_name . '.install.php')) {
include PLUGINS . DS . basename(Text::lowercase(Request::get('install')), '.manifest.xml') . DS . 'install' . DS . $plugin_name . '.install.php';
}
Request::redirect('index.php?id=plugins');
}
// Delete plugin from server
// -------------------------------------
if (Request::get('delete_plugin_from_server')) {
Dir::delete(PLUGINS . DS . basename(Request::get('delete_plugin_from_server'), '.manifest.xml'));
Request::redirect('index.php?id=plugins');
}
// Installed plugins
$plugins_installed = array();
// New plugins
$plugins_new = array();
// Plugins to install
$plugins_to_intall = array();
// Scan plugins directory for .manifest.xml
$plugins_new = File::scan(PLUGINS, '.manifest.xml');
// Get installed plugins from plugins table
$plugins_installed = $plugins->select(null, 'all', null, array('location', 'priority'), 'priority', 'ASC');
// Update $plugins_installed array. extract plugins names
foreach ($plugins_installed as $plg) {
$_plg[] = basename($plg['location'], 'plugin.php').'manifest.xml';
}
// Diff
$plugins_to_install = array_diff($plugins_new, $_plg);
// Create array of plugins to install
$count = 0;
foreach ($plugins_to_install as $plugin) {
$plg_path = PLUGINS . DS . Text::lowercase(basename($plugin, '.manifest.xml')) . DS . 'install' . DS . $plugin;
if (file_exists($plg_path)) {
$plugins_to_intall[$count]['path'] = $plg_path;
$plugins_to_intall[$count]['plugin'] = $plugin;
$count++;
}
}
// Draw template
View::factory('box/plugins/views/backend/index')
->assign('installed_plugins', $installed_plugins)
->assign('plugins_to_intall', $plugins_to_intall)
->assign('_users_plugins', $_users_plugins)
->display();
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Plugins manger plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Plugins', 'plugins'),
__('Plugins manager', 'plugins'),
'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('plugins', 'box');
}

View File

@@ -0,0 +1,99 @@
<h2><?php echo __('Plugins', 'plugins'); ?></h2>
<br />
<div class="tabbable">
<!-- Plugins_tabs -->
<ul class="nav nav-tabs">
<li class="active"><a href="#installed" data-toggle="tab"><?php echo __('Installed', 'plugins'); ?></a></li>
<li><a href="#installnew" data-toggle="tab"><?php echo __('Install New', 'plugins'); ?> <?php if(count($plugins_to_intall) > 0) { ?><span class="badge"><?php echo count($plugins_to_intall); ?></span><?php } ?></a></li>
<li><a href="http://monstra.org" target="_blank"><?php echo __('Get More Plugins', 'plugins'); ?></a></li>
</ul>
<!-- /Plugins_tabs -->
<div class="tab-content">
<div class="tab-pane active" id="installed">
<table class="table table-bordered">
<thead>
<tr>
<td><?php echo __('Name', 'plugins'); ?></td>
<td><?php echo __('Description', 'plugins'); ?></td>
<td><?php echo __('Author', 'plugins'); ?></td>
<td><?php echo __('Version', 'plugins'); ?></td>
<td width="30%"><?php echo __('Actions', 'plugins'); ?></td>
</tr>
</thead>
<tbody>
<?php foreach ($installed_plugins as $plugin) { if ($plugin['privilege'] !== 'box') { ?>
<tr>
<td>
<?php echo $plugin['title']; ?>
</td>
<td>
<?php echo $plugin['description']; ?>
</td>
<td>
<a target="_blank" href="<?php echo $plugin['author_uri']; ?>"><?php echo $plugin['author']; ?></a>
</td>
<td>
<?php echo $plugin['version']; ?>
</td>
<td>
<?php echo Html::anchor(__('Uninstall', 'plugins'),
'index.php?id=plugins&delete_plugin='.$plugin['id'],
array('class' => 'btn btn-actions', 'onclick' => "return confirmDelete('".__('Delete plugin :plugin', 'plugins', array(':plugin' => $plugin['id']))."')"));
?>
</td>
</tr>
<?php } } ?>
</tbody>
</table>
</div>
<div class="tab-pane" id="installnew">
<table class="table table-bordered">
<thead>
<tr>
<td><?php echo __('Name', 'plugins'); ?></td>
<td><?php echo __('Description', 'plugins'); ?></td>
<td><?php echo __('Author', 'plugins'); ?></td>
<td><?php echo __('Version', 'plugins'); ?></td>
<td width="30%"><?php echo __('Actions', 'plugins'); ?></td>
</tr>
</thead>
<tbody>
<?php foreach ($plugins_to_intall as $plug) { $plugin_xml = XML::loadFile($plug['path']); ?>
<tr>
<td>
<?php echo $plugin_xml->plugin_name; ?>
</td>
<td>
<?php echo $plugin_xml->plugin_description; ?>
</td>
<td>
<a href="<?php echo $plugin_xml->plugin_author_uri; ?>"><?php echo $plugin_xml->plugin_author; ?></a>
</td>
<td>
<?php echo $plugin_xml->plugin_version; ?>
</td>
<td>
<?php echo Html::anchor(__('Install', 'plugins'), 'index.php?id=plugins&install='.$plug['plugin'], array('class' => 'btn btn-actions')); ?>
<?php echo Html::anchor(__('Delete', 'plugins'),
'index.php?id=plugins&delete_plugin_from_server='.Text::lowercase(basename($plug['path'],'.manifest.xml')),
array('class' => 'btn btn-actions', 'onclick' => "return confirmDelete('".__('Delete plugin :plugin', 'plugins', array(':plugin' => Text::lowercase(basename($plug['path'],'.manifest.xml'))) )."')"));
?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!-- /Plugins_to_install_list -->
</div>
</div>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<plugin_location>plugins/box/sitemap/sitemap.plugin.php</plugin_location>
<plugin_status>active</plugin_status>
<plugin_priority>10</plugin_priority>
<plugin_name>Sitemap</plugin_name>
<plugin_description>Show sitemap</plugin_description>
<plugin_version>1.0.0</plugin_version>
<plugin_author>Awilum</plugin_author>
<plugin_author_uri>http://awilum.webdevart.ru/</plugin_author_uri>
</root>

View File

@@ -0,0 +1,7 @@
<?php
return array(
'sitemap' => array(
'Sitemap' => 'Sitemap',
)
);

View File

@@ -0,0 +1,7 @@
<?php
return array(
'sitemap' => array(
'Sitemap' => 'Карта сайта',
)
);

View File

@@ -0,0 +1,160 @@
<?php
/**
* Sitemap plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Sitemap', 'sitemap'),
__('Sitemap plugin', 'sitemap'),
'1.0.0',
'Awilum',
'http://monstra.org/',
'sitemap',
'box');
Action::add('admin_pages_action_add', 'Sitemap::create');
Action::add('admin_pages_action_edit', 'Sitemap::create');
Action::add('admin_pages_action_clone', 'Sitemap::create');
Action::add('admin_pages_action_delete', 'Sitemap::create');
class Sitemap extends Frontend {
/**
* Sitemap Title
*
* @return string
*/
public static function title() {
return __('Sitemap', 'sitemap');
}
/**
* Sitemap template
*/
public static function template() {
return 'index';
}
/**
* Get sitemap content
*/
public static function content() {
// Get pages table
$pages = new Table('pages');
$pages_list = $pages->select('[slug!="error404" and status="published"]');
$pages_array = array();
$count = 0;
foreach ($pages_list as $page) {
$pages_array[$count]['title'] = Html::toText($page['title']);
$pages_array[$count]['parent'] = $page['parent'];
$pages_array[$count]['date'] = $page['date'];
$pages_array[$count]['author'] = $page['author'];
$pages_array[$count]['slug'] = $page['slug'];
if (isset($page['parent'])) {
$c_p = $page['parent'];
} else {
$c_p = '';
}
if ($c_p != '') {
$_page = $pages->select('[slug="'.$page['parent'].'"]', null);
if (isset($_page['title'])) {
$_title = $_page['title'];
} else {
$_title = '';
}
$pages_array[$count]['sort'] = $_title . ' ' . $page['title'];
} else {
$pages_array[$count]['sort'] = $page['title'];
}
$_title = '';
$count++;
}
// Sort pages
$_pages_list = Arr::subvalSort($pages_array, 'sort');
// Display view
return View::factory('box/sitemap/views/frontend/index')
->assign('pages_list', $_pages_list)
->assign('components', Sitemap::getComponents())
->render();
}
/**
* Create sitemap
*/
public static function create() {
// Get pages table
$pages = new Table('pages');
// Get pages list
$pages_list = $pages->select('[slug!="error404" and status="published"]');
// Create sitemap content
$map = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
$map .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
foreach ($pages_list as $page) {
if ($page['parent'] != '') { $parent = $page['parent'].'/'; } else { $parent = ''; }
$map .= "\t".'<url>'."\n\t\t".'<loc>'.Option::get('siteurl').$parent.$page['slug'].'</loc>'."\n\t\t".'<lastmod>'.date("Y-m-d", (int)$page['date']).'</lastmod>'."\n\t\t".'<changefreq>weekly</changefreq>'."\n\t\t".'<priority>1.0</priority>'."\n\t".'</url>'."\n";
}
// Get list of components
$components = Sitemap::getComponents();
// Add components to sitemap
if (count($components) > 0) {
foreach ($components as $component) {
$map .= "\t".'<url>'."\n\t\t".'<loc>'.Option::get('siteurl').Text::lowercase($component).'</loc>'."\n\t\t".'<lastmod>'.date("Y-m-d", time()).'</lastmod>'."\n\t\t".'<changefreq>weekly</changefreq>'."\n\t\t".'<priority>1.0</priority>'."\n\t".'</url>'."\n";
}
}
// Close sitemap
$map .= '</urlset>';
// Save sitemap
return File::setContent(ROOT . DS . 'sitemap.xml', $map);
}
/**
* 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;
}
}

View File

@@ -0,0 +1,28 @@
<h3><?php echo __('Sitemap', 'sitemap'); ?></h3>
<br />
<ul>
<?php
// Display pages
if (count($pages_list) > 0) {
foreach ($pages_list as $page) {
if (trim($page['parent']) !== '') $parent = $page['parent'].'/'; else $parent = '';
if (trim($page['parent']) !== '') { echo '<ul>'; }
echo '<li><a href="'.Option::get('siteurl').$parent.$page['slug'].'" target="_blank">'.$page['title'].'</a></li>';
if (trim($page['parent']) !== '') { echo '</ul>'; }
}
if (count($components) == 0) { echo '<ul>'; }
}
// Display components
if (count($components) > 0) {
if (count($pages_list) == 0) { echo '<ul>'; }
foreach ($components as $component) {
echo '<li><a href="'.Option::get('siteurl').Text::lowercase($component).'" target="_blank">'.__($component).'</a></li>';
}
echo '</ul>';
}
?>
</ul>

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 -->

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<plugin_location>plugins/box/system/system.plugin.php</plugin_location>
<plugin_status>active</plugin_status>
<plugin_priority>4</plugin_priority>
<plugin_name>System</plugin_name>
<plugin_description>Monstra System 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,79 @@
<?php
return array(
'system' => array(
'System' => 'System',
'Published a new version of the :monstra' => 'Published a new version of the :monstra',
'Sitemap created' => 'Sitemap created',
'Create sitemap' => 'Create sitemap',
'on' => 'on',
'off'=> 'off',
'Site url' => 'Site url',
'Maintenance Mode' => 'Maintenance Mode',
'Maintenance Mode On' => 'Maintenance Mode On',
'Maintenance Mode Off' => 'Maintenance Mode Off',
'Site settings' => 'Site settings',
'System settings' => 'System settings',
'Site name' => 'Site name',
'Site description' => 'Site description',
'Site keywords' => 'Site keywords',
'Site slogan' => 'Site slogan',
'Default page' => 'Default page',
'Time zone' => 'Time zone',
'Language' => 'Language',
'Save' => 'Save',
'Site' => 'Site',
'System version' => 'System version',
'System version ID' => 'System version ID',
'GZIP' => 'GZIP',
'Debugging' => 'Debugging',
'Plugin API' => 'Plugin API',
'Plugins active' => 'Plugins active',
'Actions registered' => 'Actions registered',
'Filters registered' => 'Filters registered',
'logout' => 'logout',
'site' => 'site',
'Core' => 'Core',
'Delete temporary files' => 'Delete temporary files',
'Download the latest version' => 'Download the latest version',
'Powered by' => 'Powered by',
'Administration' => 'Administration',
'Settings' => 'Settings',
'Temporary files deleted' => 'Temporary files deleted',
'Extends' => 'Extends',
'View site' => 'View site',
'Welcome, :username' => 'Welcome, :username',
'Reset Password' => 'Reset Password',
'< Back to Website' => '< Back to Website',
'Forgot your password? >' => 'Forgot your password? >',
'Administration >' => 'Administration >',
'Send New Password' => 'Send New Password',
'This user does not exist' => 'This user does not exist',
'Version' => 'Version',
'Install script writable' => 'Install script writable',
'Install script not writable' => 'Install script not writable',
'Directory: <b> :dir </b> writable' => 'Directory: <b> :dir </b> writable',
'Directory: <b> :dir </b> not writable' => 'Directory: <b> :dir </b> not writable',
'PHP Version' => 'PHP Version',
'Module DOM is installed' => 'Module DOM is installed',
'Module DOM is required' => 'Module DOM is required',
'Module Mod Rewrite is installed' => 'Module Mod Rewrite is installed',
'Module SimpleXML is installed' => 'Module SimpleXML is installed',
'PHP 5.2 or greater is required' => 'PHP 5.2 or greater is required',
'Apache Mod Rewrite is required' => 'Apache Mod Rewrite is required',
'SimpleXML module is required' => 'SimpleXML module is required',
'Field "Site name" is empty' => 'Field "Site name" is empty',
'Field "Email" is empty' => 'Field "Email" is empty',
'Field "Username" is empty' => 'Field "Username" is empty',
'Field "Password" is empty' => 'Field "Password" is empty',
'Field "Site url" is empty' => 'Field "Site url" is empty',
'Email not valid' => 'Email not valid',
'Install' => 'Install',
'...Monstra says...' => '...Monstra says...',
'Sitemap file writable' => 'Sitemap file writable',
'Sitemap file not writable' => 'Sitemap file not writable',
'Main .htaccess file writable' => 'Main .htaccess file writable',
'Main .htaccess file not writable' => 'Main .htaccess file not writable',
)
);

View File

@@ -0,0 +1,80 @@
<?php
return array(
'system' => array(
'System' => 'Система',
'Published a new version of the :monstra' => 'Опубликована новая версия :monstra',
'Sitemap created' => 'Карта сайта создана',
'Create sitemap' => 'Создать карту сайта',
'on' => 'включен',
'off'=> 'выключен',
'Site url' => 'Адрес сайта',
'Maintenance Mode' => 'Техническое обслуживание',
'Maintenance Mode On' => 'Поставить на тех.обслуживание',
'Maintenance Mode Off' => 'Снять с тех.обслуживания',
'Site settings' => 'Настройки сайта',
'System settings' => 'Настройки системы',
'Site name' => 'Название сайта',
'Site description' => 'Описание сайта',
'Site keywords' => 'Ключевые слова сайта',
'Site slogan' => 'Слоган сайта',
'Default page' => 'Страница по умолчанию',
'Time zone' => 'Временная зона',
'Language' => 'Язык',
'Save' => 'Сохранить',
'Site' => 'Сайт',
'System version' => 'Версия системы ID',
'System version ID' => 'Версия системы ID',
'GZIP' => 'Cжатие GZIP',
'Debugging' => 'Дебаггинг',
'Plugin API' => 'Plugin API',
'Plugins active' => 'Подключенные плагины',
'Actions registered' => 'Зарегистрированные эыкшены',
'Filters registered' => 'Скачать последнюю версию',
'logout' => 'выход',
'site' => 'Сайт',
'Core' => 'Ядро',
'Delete temporary files' => 'Удалить временные файлы',
'Download the latest version' => 'Скачать последнюю версию',
'Powered by' => 'Работает на',
'Administration' => 'Администрирование',
'Settings' => 'Настройки',
'Temporary files deleted' => 'Временные файлы удалены',
'Extends' => 'Расширения',
'View site' => 'Сайт',
'Welcome, :username' => 'Добро пожаловать, :username',
'Reset Password' => 'Сброс пароля',
'< Back to Website' => '< Обратно на сайт',
'Forgot your password? >' => 'Забыли пароль ? >',
'Administration >' => 'Администрирование >',
'Send New Password' => 'Выслать новый пароль',
'This user does not exist' => 'Нет такого пользователя',
'Version' => 'Версия',
'Install script writable' => 'Установочный скрипт доступен для записи',
'Install script not writable' => 'Установочный скрипт не доступен для записи',
'Directory: <b> :dir </b> writable' => 'Директория <b> :dir </b> доступна для записи',
'Directory: <b> :dir </b> not writable' => 'Директория <b> :dir </b> не доступна для записи',
'PHP Version' => 'Версия PHP',
'Module DOM is installed' => 'Модуль DOM установлен',
'Module DOM is required' => 'Требуется DOM модуль',
'Module Mod Rewrite is installed' => 'Модуль Mod Rewrite установлен',
'Module SimpleXML is installed' => 'Модуль SimpleXML установлен',
'PHP 5.2 or greater is required' => 'PHP 5.2 или высше',
'Apache Mod Rewrite is required' => 'Требуется Apache Mod Rewrite',
'SimpleXML module is required' => 'Требуется SimpleXML модуль',
'Field "Site name" is empty' => 'Поле "Название сайта" пустое',
'Field "Email" is empty' => 'Поле "Емейл" пустое',
'Field "Username" is empty' => 'Поле "Имя пользователя" пустое',
'Field "Password" is empty' => 'Поле "Пароль" пустое',
'Field "Site url" is empty' => 'Поле "Адрес сайта" пустое',
'Email not valid' => 'Емейл невалидный',
'Install' => 'Установить',
'...Monstra says...' => '...Monstra говорит...',
'Sitemap file writable' => 'Карта сайта доступна для записи',
'Sitemap file not writable' => 'Карта сайта не доступна для записи',
'Main .htaccess file writable' => 'Главный .htaccess файл доступен для записи',
'Main .htaccess file not writable' => 'Главный .htaccess файл не доступен для записи',
)
);

View File

@@ -0,0 +1,159 @@
<?php
// Add Monstra check action
if (CHECK_MONSTRA_VERSION) {
Action::add('admin_post_template', 'checkMonstraVersion', 9999);
}
/**
* Check Monstra version
*/
function checkMonstraVersion() {
echo ('
<script type="text/javascript">
$.getJSON("http://monstra.org/api/basic.php?jsoncallback=?",
function(data){
var current_monstra_version_id = '.MONSTRA_VERSION_ID.';
var api_monstra_version_id = data.version_id;
if (current_monstra_version_id < api_monstra_version_id) {
$("#update-monstra").addClass("alert").html("'.__("Published a new version of the :monstra", "system", array(":monstra" => "<a target='_blank' href='http://monstra.org/download'>Monstra</a>")).'");
}
}
);
</script>
');
}
class SystemAdmin extends Backend {
/**
* System plugin admin
*/
public static function main() {
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) {
$filters = Filter::$filters;
$plugins = Plugin::$plugins;
$components = Plugin::$components;
$actions = Action::$actions;
// Get pages table
$pages = new Table('pages');
// Get system timezone
$system_timezone = Option::get('timezone');
// Get languages files
$language_files = File::scan('../plugins/box/system/languages/', '.lang.php');
foreach ($language_files as $language) {
$parts = explode('.', $language);
$l = $parts[0];
$languages_array[$l] = $l;
}
// Get all pages
$pages_array = array();
$pages_list = $pages->select('[slug!="error404" and parent=""]');
foreach ($pages_list as $page) {
$pages_array[$page['slug']] = Html::toText($page['title']);
}
// Create Sitemap
// -------------------------------------
if (Request::get('sitemap')) {
if ('create' == Request::get('sitemap')) {
Notification::set('success', __('Sitemap created', 'system'));
Sitemap::create();
Request::redirect('index.php?id=system');
}
}
// Delete temporary files
// -------------------------------------
if (Request::get('temporary_files')) {
if ('delete' == Request::get('temporary_files')) {
$namespaces = Dir::scan(CACHE);
if (count($namespaces) > 0) {
foreach ($namespaces as $namespace) {
Dir::delete(CACHE . DS . $namespace);
}
}
$files = File::scan(MINIFY, array('css','js','php'));
if (count($files) > 0) {
foreach ($files as $file) {
File::delete(MINIFY . DS . $file);
}
}
if (count(File::scan(MINIFY, array('css', 'js', 'php'))) == 0 && count(Dir::scan(CACHE)) == 0) {
Notification::set('success', __('Temporary files deleted', 'system'));
Request::redirect('index.php?id=system');
}
}
}
// Set maintenance state on or off
// -------------------------------------
if (Request::get('maintenance')) {
if ('on' == Request::get('maintenance')) {
Option::update('maintenance_status', 'on');
Request::redirect('index.php?id=system');
}
if ('off' == Request::get('maintenance')) {
Option::update('maintenance_status', 'off');
Request::redirect('index.php?id=system');
}
}
// Edit settings
// -------------------------------------
if (Request::post('edit_settings')) {
if (Security::check(Request::post('csrf'))) {
// Add trailing slashes
$_site_url = Request::post('system_url');
if ($_site_url[strlen($_site_url)-1] !== '/') {
$_site_url = $_site_url.'/';
}
Option::update(array('sitename' => Request::post('site_name'),
'keywords' => Request::post('site_keywords'),
'description' => Request::post('site_description'),
'slogan' => Request::post('site_slogan'),
'defaultpage' => Request::post('site_default_page'),
'siteurl' => $_site_url,
'timezone' => Request::post('system_timezone'),
'language' => Request::post('system_language'),
'maintenance_message' => Request::post('site_maintenance_message')));
Notification::set('success', __('Your changes have been saved.', 'system'));
Request::redirect('index.php?id=system');
} else { die('csrf detected!'); }
}
// Its mean that you can add your own actions for this plugin
Action::run('admin_system_extra_actions');
// Display view
View::factory('box/system/views/backend/index')
->assign('pages_array', $pages_array)
->assign('languages_array', $languages_array)
->display();
} else {
Request::redirect('index.php?id=users&action=edit&user_id='.Session::get('user_id'));
}
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* System plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('System', 'system'),
__('System plugin', 'system'),
'1.0.0',
'Awilum',
'http://monstra.org/',
null,
'box');
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor'))) {
// Admin top navigation
Navigation::add(__('Welcome, :username', 'system', array(':username' => Session::get('user_login'))), 'top', 'users&action=edit&user_id='.Session::get('user_id'), 1, Navigation::TOP, false);
Navigation::add(__('View site', 'system'), 'top', Option::get('siteurl'), 2, Navigation::TOP, true);
Navigation::add(__('Logout', 'users'), 'top', '&logout=do', 3, Navigation::TOP, false);
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) {
Navigation::add(__('Settings', 'system'), 'system', 'system', 1);
}
}
Plugin::Admin('system', 'box');

View File

@@ -0,0 +1,58 @@
<!-- System -->
<br />
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php echo Html::anchor(__('Create sitemap', 'system'), 'index.php?id=system&sitemap=create', array('class' => 'btn')).Html::nbsp(2); ?>
<?php echo Html::anchor(__('Delete temporary files', 'system'), 'index.php?id=system&temporary_files=delete', array('class' => 'btn')).Html::nbsp(2); ?>
<?php if ('off' == Option::get('maintenance_status', 'system')) { ?>
<?php echo Html::anchor(__('Maintenance Mode On', 'system'), 'index.php?id=system&maintenance=on', array('class' => 'btn')); ?>
<?php } else { ?>
<?php echo Html::anchor(__('Maintenance Mode Off', 'system'), 'index.php?id=system&maintenance=off', array('class' => 'btn btn-danger')); ?>
<?php } ?>
<?php Action::run('admin_system_extra_buttons'); ?>
<hr />
<h2><?php echo __('Site settings', 'system'); ?></h2>
<br />
<?php
echo (
Form::open().
Form::hidden('csrf', Security::token()).
Form::label('site_name', __('Site name', 'system')).
Form::input('site_name', Option::get('sitename'), array('class' => 'span7')). Html::br().
Form::label('site_description', __('Site description', 'system')).
Form::input('site_description', Option::get('description'), array('class' => 'span7')). Html::br().
Form::label('site_keywords', __('Site keywords', 'system')).
Form::input('site_keywords', Option::get('keywords'), array('class' => 'span7')). Html::br().
Form::label('site_slogan', __('Site slogan', 'system')).
Form::input('site_slogan', Option::get('slogan'), array('class' => 'span7')). Html::br().
Form::label('site_default_page', __('Default page', 'system')).
Form::select('site_default_page', $pages_array, Option::get('defaultpage'), array('class' => 'span3')). Html::br(2)
);
?>
<h2><?php echo __('System settings', 'system'); ?></h2>
<br />
<?php
echo (
Form::label('system_url', __('Site url', 'system')).
Form::input('system_url', Option::get('siteurl'), array('class' => 'span7')). Html::br().
Form::label('system_timezone', __('Time zone', 'system')).
Form::select('system_timezone', Date::timezones(), Option::get('timezone'), array('class' => 'span7')). Html::br().
Form::label('system_language', __('Language', 'system')).
Form::select('system_language', $languages_array, Option::get('language'), array('class' => 'span2')). Html::br().
Form::label('site_maintenance_message', __('Maintenance Mode', 'system')).
Form::textarea('site_maintenance_message', Html::toText(Option::get('maintenance_message')), array('style' => 'width:640px;height:160px;')). Html::br(2)
);
?>
<?php
echo (
Form::submit('edit_settings', __('Save', 'system'), array('class' => 'btn')).
Form::close()
);
?>
<!-- /System -->

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<plugin_location>plugins/box/themes/themes.plugin.php</plugin_location>
<plugin_status>active</plugin_status>
<plugin_priority>3</plugin_priority>
<plugin_name>Themes</plugin_name>
<plugin_description>Themes 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>

View File

@@ -0,0 +1,49 @@
<?php
return array(
'themes' => array(
'Themes' => 'Themes',
'Themes manager' => 'Themes manager',
'Select theme' => 'Select theme',
'Save' => 'Save',
'Save and exit' => 'Save and exit',
'Name' => 'Name',
'Create new template' => 'Create new template',
'New template' => 'New template',
'Delete template: :name' => 'Delete template: :name',
'Delete chunk: :name' => 'Delete chunk: :name',
'Delete styles: :name' => 'Delete styles: :name',
'Templates' => 'Templates',
'Clone' => 'Clone',
'Edit' => 'Edit',
'Delete' => 'Delete',
'Actions' => 'Actions',
'Create new chunk' => 'Create new chunk',
'New chunk' => 'New chunk',
'Chunks' => 'Chunks',
'Create new styles' => 'Create new styles',
'New styles' => 'New styles',
'Styles' => 'Styles',
'Template content' => 'Template content',
'Styles content' => 'Styles content',
'Chunk content' => 'Chunk content',
'Edit template' => 'Edit template',
'Edit chunk' => 'Edit chunk',
'Edit styles' => 'Edit styles',
'Current site theme' => 'Current site theme',
'Current admin theme' => 'Current admin theme',
'This template already exists' => 'This template already exists',
'This chunk already exists' => 'This chunk already exists',
'This styles already exists' => 'This styles already exists',
'Components templates' => 'Components templates',
'Your changes to the chunk <i>:name</i> have been saved.' => 'Your changes to the chunk <i>:name</i> have been saved.',
'Your changes to the styles <i>:name</i> have been saved.' => 'Your changes to the styles <i>:name</i> have been saved.',
'Your changes to the template <i>:name</i> have been saved.' => 'Your changes to the template <i>:name</i> have been saved.',
'This field should not be empty' => 'This field should not be empty',
'Scripts' => 'Scripts',
'Create new script' => 'Create new script',
'Script content' => 'Script content',
'New script' => 'New script',
'Edit script' => 'Edit script',
)
);

View File

@@ -0,0 +1,51 @@
<?php
return array(
'themes' => array(
'Themes' => 'Темы',
'Themes manager' => 'Менеджер тем',
'Select theme' => 'Выбрать тему',
'Save' => 'Сохранить',
'Name' => 'Название',
'Save and exit' => 'Сохранить и выйти',
'Create new template' => 'Создать новый шаблон',
'New template' => 'Новый шаблон',
'Delete template: :name' => 'Удалить шаблон: :name',
'Delete chunk: :name' => 'Удалить чанк: :name',
'Delete styles: :name' => 'Удалить стили: :name',
'Templates' => 'Шаблоны',
'Clone' => 'Клонировать',
'Edit' => 'Редактировать',
'Delete' => 'Удалить',
'Actions' => 'Действия',
'Create new chunk' => 'Создать новый чанк',
'New chunk' => 'Новый чанк',
'Chunks' => 'Чанки',
'Create new styles' => 'Создать новые стили',
'New styles' => 'Новые стили',
'Styles' => 'Стили',
'Template content' => 'Содержимое шаблона',
'Styles content' => 'Содержимое стилей',
'Chunk content' => 'Содержимое чанка',
'Edit template' => 'Редактирование шаблона',
'Edit chunk' => 'Редактирование чанка',
'Edit styles' => 'Редкатирование стилей',
'Site theme' => 'Тема сайта',
'Admin theme' => 'Тема админки',
'Current site theme' => 'Текущая тема сайта',
'Current admin theme' => 'Текущая тема админки',
'This template already exists' => 'Этот шаблон уже существует',
'This chunk already exists' => 'Этот чанк уже существует',
'This styles already exists' => 'Эти стили уже существуют',
'Components templates' => 'Шаблоны компонентов',
'Your changes to the chunk <i>:name</i> have been saved.' => 'Ваши изменения к чанку <i>:name</i> были сохранены',
'Your changes to the styles <i>:name</i> have been saved.' => 'Ваши изменения к стилям <i>:name</i> были сохранены',
'Your changes to the template <i>:name</i> have been saved.' => 'Ваши изменения к шаблону <i>:name</i> были сохранены',
'This field should not be empty' => 'Это поле не должно быть пустым',
'Scripts' => 'Скрипты',
'Create new script' => 'Создать новый скрипт',
'Script content' => 'Содержимое скрипта',
'New script' => 'Новый скрипт',
'Edit script' => 'Редактирование скрипта',
)
);

View File

@@ -0,0 +1,547 @@
<?php
Navigation::add(__('Themes', 'themes'), 'extends', 'themes', 2);
class ThemesAdmin extends Backend {
/**
* Themes plugin admin
*/
public static function main() {
// Get current themes
$current_site_theme = Option::get('theme_site_name');
$current_admin_theme = Option::get('theme_admin_name');
// Init vsrs
$themes_site = Themes::getSiteThemes();
$themes_admin = Themes::getAdminThemes();
$templates = Themes::getTemplates();
$chunks = Themes::getChunks();
$styles = Themes::getStyles();
$scripts = Themes::getScripts();
$errors = array();
$chunk_path = THEMES_SITE . DS . $current_site_theme . DS;
$template_path = THEMES_SITE . DS . $current_site_theme . DS;
$style_path = THEMES_SITE . DS . $current_site_theme . DS . 'css' . DS;
$script_path = THEMES_SITE . DS . $current_site_theme . DS . 'js' . DS;
// Save site theme
if (Request::post('save_site_theme')) {
if (Security::check(Request::post('csrf'))) {
Option::update('theme_site_name', Request::post('themes'));
// Cleanup minify
if (count($files = File::scan(MINIFY, array('css', 'js', 'php'))) > 0) foreach ($files as $file) File::delete(MINIFY . DS . $file);
Request::redirect('index.php?id=themes');
} else { die('csrf detected!'); }
}
// Save site theme
if (Request::post('save_admin_theme')) {
if (Security::check(Request::post('csrf'))) {
Option::update('theme_admin_name', Request::post('themes'));
// Cleanup minify
if (count($files = File::scan(MINIFY, array('css', 'js', 'php'))) > 0) foreach ($files as $file) File::delete(MINIFY . DS . $file);
Request::redirect('index.php?id=themes');
} else { die('csrf detected!'); }
}
// Its mean that you can add your own actions for this plugin
Action::run('admin_themes_extra_actions');
// Check for get actions
// -------------------------------------
if (Request::get('action')) {
// Switch actions
// -------------------------------------
switch (Request::get('action')) {
// Add chunk
// -------------------------------------
case "add_chunk":
if (Request::post('add_file') || Request::post('add_file_and_exit')) {
if (Security::check(Request::post('csrf'))) {
if (trim(Request::post('name')) == '') $errors['file_empty_name'] = __('Required field', 'themes');
if (file_exists($chunk_path.Security::safeName(Request::post('name')).'.chunk.php')) $errors['file_exists'] = __('This chunk already exists', 'themes');
if (count($errors) == 0) {
// Save chunk
File::setContent($chunk_path.Security::safeName(Request::post('name')).'.chunk.php', Request::post('content'));
Notification::set('success', __('Your changes to the chunk <i>:name</i> have been saved.', 'themes', array(':name' => Security::safeName(Request::post('name')))));
if (Request::post('add_file_and_exit')) {
Request::redirect('index.php?id=themes');
} else {
Request::redirect('index.php?id=themes&action=edit_chunk&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/themes/views/backend/add')
->assign('name', $name)
->assign('content', $content)
->assign('errors', $errors)
->assign('action', 'chunk')
->display();
break;
// Add template
// -------------------------------------
case "add_template":
if (Request::post('add_file') || Request::post('add_file_and_exit')) {
if (Security::check(Request::post('csrf'))) {
if (trim(Request::post('name')) == '') $errors['file_empty_name'] = __('Required field', 'themes');
if (file_exists($template_path.Security::safeName(Request::post('name')).'.template.php')) $errors['file_exists'] = __('This template already exists', 'themes');
if (count($errors) == 0) {
// Save chunk
File::setContent($template_path.Security::safeName(Request::post('name')).'.template.php', Request::post('content'));
Notification::set('success', __('Your changes to the chunk <i>:name</i> have been saved.', 'themes', array(':name' => Security::safeName(Request::post('name')))));
if (Request::post('add_file_and_exit')) {
Request::redirect('index.php?id=themes');
} else {
Request::redirect('index.php?id=themes&action=edit_template&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/themes/views/backend/add')
->assign('name', $name)
->assign('content', $content)
->assign('errors', $errors)
->assign('action', 'template')
->display();
break;
// Add styles
// -------------------------------------
case "add_styles":
if (Request::post('add_file') || Request::post('add_file_and_exit')) {
if (Security::check(Request::post('csrf'))) {
if (trim(Request::post('name')) == '') $errors['file_empty_name'] = __('Required field', 'themes');
if (file_exists($style_path.Security::safeName(Request::post('name')).'.css')) $errors['file_exists'] = __('This styles already exists', 'themes');
if (count($errors) == 0) {
// Save chunk
File::setContent($style_path.Security::safeName(Request::post('name')).'.css', Request::post('content'));
Notification::set('success', __('Your changes to the styles <i>:name</i> have been saved.', 'themes', array(':name' => Security::safeName(Request::post('name')))));
if (Request::post('add_file_and_exit')) {
Request::redirect('index.php?id=themes');
} else {
Request::redirect('index.php?id=themes&action=edit_styles&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/themes/views/backend/add')
->assign('name', $name)
->assign('content', $content)
->assign('errors', $errors)
->assign('action', 'styles')
->display();
break;
// Add script
// -------------------------------------
case "add_script":
if (Request::post('add_file') || Request::post('add_file_and_exit')) {
if (Security::check(Request::post('csrf'))) {
if (trim(Request::post('name')) == '') $errors['file_empty_name'] = __('Required field', 'themes');
if (file_exists($script_path.Security::safeName(Request::post('name')).'.js')) $errors['file_exists'] = __('This script already exists', 'themes');
if (count($errors) == 0) {
// Save chunk
File::setContent($script_path.Security::safeName(Request::post('name')).'.js', Request::post('content'));
Notification::set('success', __('Your changes to the script <i>:name</i> have been saved.', 'themes', array(':name' => Security::safeName(Request::post('name')))));
if (Request::post('add_file_and_exit')) {
Request::redirect('index.php?id=themes');
} else {
Request::redirect('index.php?id=themes&action=edit_script&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/themes/views/backend/add')
->assign('name', $name)
->assign('content', $content)
->assign('errors', $errors)
->assign('action', 'script')
->display();
break;
// Edit chunk
// -------------------------------------
case "edit_chunk":
// Save current chunk action
if (Request::post('edit_file') || Request::post('edit_file_and_exit') ) {
if (Security::check(Request::post('csrf'))) {
if (trim(Request::post('name')) == '') $errors['file_empty_name'] = __('Required field', 'themes');
if ((file_exists($chunk_path.Security::safeName(Request::post('name')).'.chunk.php')) and (Security::safeName(Request::post('chunk_old_name')) !== Security::safeName(Request::post('name')))) $errors['file_exists'] = __('This chunk already exists', 'themes');
// Save fields
if (Request::post('content')) $content = Request::post('content'); else $content = '';
if (count($errors) == 0) {
$chunk_old_filename = $chunk_path.Request::post('chunk_old_name').'.chunk.php';
$chunk_new_filename = $chunk_path.Security::safeName(Request::post('name')).'.chunk.php';
if ( ! empty($chunk_old_filename)) {
if ($chunk_old_filename !== $chunk_new_filename) {
rename($chunk_old_filename, $chunk_new_filename);
$save_filename = $chunk_new_filename;
} else {
$save_filename = $chunk_new_filename;
}
} else {
$save_filename = $chunk_new_filename;
}
// Save chunk
File::setContent($save_filename, Request::post('content'));
Notification::set('success', __('Your changes to the chunk <i>:name</i> have been saved.', 'themes', array(':name' => basename($save_filename, '.chunk.php'))));
if (Request::post('edit_file_and_exit')) {
Request::redirect('index.php?id=themes');
} else {
Request::redirect('index.php?id=themes&action=edit_chunk&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($chunk_path.Request::get('filename').'.chunk.php');
// Display view
View::factory('box/themes/views/backend/edit')
->assign('content', $content)
->assign('name', $name)
->assign('errors', $errors)
->assign('action', 'chunk')
->display();
break;
// Edit template
// -------------------------------------
case "edit_template":
// Save current chunk action
if (Request::post('edit_file') || Request::post('edit_file_and_exit') ) {
if (Security::check(Request::post('csrf'))) {
if (trim(Request::post('name')) == '') $errors['file_empty_name'] = __('Required field', 'themes');
if ((file_exists($template_path.Security::safeName(Request::post('name')).'.template.php')) and (Security::safeName(Request::post('template_old_name')) !== Security::safeName(Request::post('name')))) $errors['template_exists'] = __('This template already exists', 'themes');
// Save fields
if (Request::post('content')) $content = Request::post('content'); else $content = '';
if (count($errors) == 0) {
$template_old_filename = $template_path.Request::post('template_old_name').'.template.php';
$template_new_filename = $template_path.Security::safeName(Request::post('name')).'.template.php';
if ( ! empty($template_old_filename)) {
if ($template_old_filename !== $template_new_filename) {
rename($template_old_filename, $template_new_filename);
$save_filename = $template_new_filename;
} else {
$save_filename = $template_new_filename;
}
} else {
$save_filename = $template_new_filename;
}
// Save chunk
File::setContent($save_filename, Request::post('content'));
Notification::set('success', __('Your changes to the template <i>:name</i> have been saved.', 'themes', array(':name' => basename($save_filename, '.template.php'))));
if (Request::post('edit_file_and_exit')) {
Request::redirect('index.php?id=themes');
} else {
Request::redirect('index.php?id=themes&action=edit_template&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($chunk_path.Request::get('filename').'.template.php');
// Display view
View::factory('box/themes/views/backend/edit')
->assign('content', $content)
->assign('name', $name)
->assign('errors', $errors)
->assign('action', 'template')
->display();
break;
// Edit styles
// -------------------------------------
case "edit_styles":
// Save current chunk action
if (Request::post('edit_file') || Request::post('edit_file_and_exit') ) {
if (Security::check(Request::post('csrf'))) {
if (trim(Request::post('name')) == '') $errors['file_empty_name'] = __('Required field', 'themes');
if ((file_exists($style_path.Security::safeName(Request::post('name')).'.css')) and (Security::safeName(Request::post('styles_old_name')) !== Security::safeName(Request::post('name')))) $errors['file_exists'] = __('This styles already exists', 'themes');
// Save fields
if (Request::post('content')) $content = Request::post('content'); else $content = '';
if (count($errors) == 0) {
$styles_old_filename = $style_path.Request::post('styles_old_name').'.css';
$styles_new_filename = $style_path.Security::safeName(Request::post('name')).'.css';
if ( ! empty($styles_old_filename)) {
if ($styles_old_filename !== $styles_new_filename) {
rename($styles_old_filename, $styles_new_filename);
$save_filename = $styles_new_filename;
} else {
$save_filename = $styles_new_filename;
}
} else {
$save_filename = $styles_new_filename;
}
// Save chunk
File::setContent($save_filename, Request::post('content'));
Notification::set('success', __('Your changes to the styles <i>:name</i> have been saved.', 'themes', array(':name' => basename($save_filename, '.css'))));
if (Request::post('edit_file_and_exit')) {
Request::redirect('index.php?id=themes');
} else {
Request::redirect('index.php?id=themes&action=edit_styles&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($style_path.Request::get('filename').'.css');
// Display view
View::factory('box/themes/views/backend/edit')
->assign('content', $content)
->assign('name', $name)
->assign('errors', $errors)
->assign('action', 'styles')
->display();
break;
// Edit script
// -------------------------------------
case "edit_script":
// Save current chunk action
if (Request::post('edit_file') || Request::post('edit_file_and_exit') ) {
if (Security::check(Request::post('csrf'))) {
if (trim(Request::post('name')) == '') $errors['file_empty_name'] = __('Required field', 'themes');
if ((file_exists($script_path.Security::safeName(Request::post('name')).'.js')) and (Security::safeName(Request::post('script_old_name')) !== Security::safeName(Request::post('name')))) $errors['file_exists'] = __('This script already exists', 'themes');
// Save fields
if (Request::post('content')) $content = Request::post('content'); else $content = '';
if (count($errors) == 0) {
$script_old_filename = $script_path.Request::post('script_old_name').'.js';
$script_new_filename = $script_path.Security::safeName(Request::post('name')).'.js';
if ( ! empty($script_old_filename)) {
if ($script_old_filename !== $script_new_filename) {
rename($script_old_filename, $script_new_filename);
$save_filename = $script_new_filename;
} else {
$save_filename = $script_new_filename;
}
} else {
$save_filename = $script_new_filename;
}
// Save chunk
File::setContent($save_filename, Request::post('content'));
Notification::set('success', __('Your changes to the script <i>:name</i> have been saved.', 'themes', array(':name' => basename($save_filename, '.js'))));
if (Request::post('edit_file_and_exit')) {
Request::redirect('index.php?id=themes');
} else {
Request::redirect('index.php?id=themes&action=edit_script&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($script_path.Request::get('filename').'.js');
// Display view
View::factory('box/themes/views/backend/edit')
->assign('content', $content)
->assign('name', $name)
->assign('errors', $errors)
->assign('action', 'script')
->display();
break;
// Delete chunk
// -------------------------------------
case "delete_chunk":
File::delete($chunk_path.Request::get('filename').'.chunk.php');
Notification::set('success', __('Chunk <i>:name</i> deleted', 'themes', array(':name' => File::name(Request::get('filename')))));
Request::redirect('index.php?id=themes');
break;
// Delete styles
// -------------------------------------
case "delete_styles":
File::delete($style_path.Request::get('filename').'.css');
Notification::set('success', __('Styles <i>:name</i> deleted', 'themes', array(':name' => File::name(Request::get('filename')))));
Request::redirect('index.php?id=themes');
break;
// Delete script
// -------------------------------------
case "delete_script":
File::delete($style_path.Request::get('filename').'.js');
Notification::set('success', __('Script <i>:name</i> deleted', 'themes', array(':name' => File::name(Request::get('filename')))));
Request::redirect('index.php?id=themes');
break;
// Delete template
// -------------------------------------
case "delete_template":
File::delete($template_path.Request::get('filename').'.template.php');
Notification::set('success', __('Template <i>:name</i> deleted', 'themes', array(':name' => File::name(Request::get('filename')))));
Request::redirect('index.php?id=themes');
break;
// Clone styles
// -------------------------------------
case "clone_styles":
File::setContent(THEMES_SITE . DS . $current_site_theme . DS . 'css' . DS . Request::get('filename') .'_clone_'.date("Ymd_His").'.css',
File::getContent(THEMES_SITE . DS . $current_site_theme . DS . 'css' . DS . Request::get('filename') . '.css'));
Request::redirect('index.php?id=themes');
break;
// Clone script
// -------------------------------------
case "clone_script":
File::setContent(THEMES_SITE . DS . $current_site_theme . DS . 'js' . DS . Request::get('filename') .'_clone_'.date("Ymd_His").'.js',
File::getContent(THEMES_SITE . DS . $current_site_theme . DS . 'js' . DS . Request::get('filename') . '.js'));
Request::redirect('index.php?id=themes');
break;
// Clone template
// -------------------------------------
case "clone_template":
File::setContent(THEMES_SITE . DS . $current_site_theme . DS . Request::get('filename') .'_clone_'.date("Ymd_His").'.template.php',
File::getContent(THEMES_SITE . DS . $current_site_theme . DS . Request::get('filename') . '.template.php'));
Request::redirect('index.php?id=themes');
break;
// Clone chunk
// -------------------------------------
case "clone_chunk":
File::setContent(THEMES_SITE . DS . $current_site_theme . DS . Request::get('filename') .'_clone_'.date("Ymd_His").'.chunk.php',
File::getContent(THEMES_SITE . DS . $current_site_theme . DS . Request::get('filename') . '.chunk.php'));
Request::redirect('index.php?id=themes');
break;
}
} else {
// Display view
View::factory('box/themes/views/backend/index')
->assign('themes_site', $themes_site)
->assign('themes_admin', $themes_admin)
->assign('templates', $templates)
->assign('chunks', $chunks)
->assign('styles', $styles)
->assign('scripts', $scripts)
->assign('current_site_theme', $current_site_theme)
->assign('current_admin_theme', $current_admin_theme)
->display();
}
}
}

View File

@@ -0,0 +1,195 @@
<?php
/**
* Themes plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Themes', 'themes'),
__('Themes manager', 'themes'),
'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('themes', 'box');
}
class Themes {
/**
* Get Themes
*/
public static function getAdminThemes() {
$themes_folders = array();
// Get all themes folders
$_themes_admin_folders = Dir::scan(THEMES_ADMIN);
// Create an array of valid themes folders
foreach($_themes_admin_folders as $folder) if (File::exists(THEMES_ADMIN . DS . $folder . DS . 'index.template.php')) $__themes_admin_folders[] = $folder;
foreach($__themes_admin_folders as $theme) $themes[$theme] = $theme;
return $themes;
}
/**
* Get Admin Themes
*/
public static function getSiteThemes() {
$themes_folders = array();
// Get all themes folders
$_themes_folders = Dir::scan(THEMES_SITE);
// Create an array of valid themes folders
foreach($_themes_folders as $folder) if (File::exists(THEMES_SITE . DS . $folder . DS . 'index.template.php')) $__themes_folders[] = $folder;
foreach($__themes_folders as $theme) $themes[$theme] = $theme;
return $themes;
}
/**
* Get Templates
*
* @param string $theme Theme name
* @return array
*/
public static function getTemplates($theme = null) {
$theme = ($theme === null) ? null : (string) $theme;
if ($theme == null) $theme = Option::get('theme_site_name');
$templates = array();
// Get all templates in current theme folder
$templates = File::scan(THEMES_SITE . DS . $theme, '.template.php');
return $templates;
}
/**
* Get Chunks
*
* @param string $theme Theme name
* @return array
*/
public static function getChunks($theme = null) {
$theme = ($theme === null) ? null : (string) $theme;
if ($theme == null) $theme = Option::get('theme_site_name');
$chunks = array();
// Get all templates in current theme folder
$chunks = File::scan(THEMES_SITE . DS . $theme, '.chunk.php');
return $chunks;
}
/**
* Get Styles
*
* @param string $theme Theme name
* @return array
*/
public static function getStyles($theme = null) {
$theme = ($theme === null) ? null : (string) $theme;
if ($theme == null) $theme = Option::get('theme_site_name');
$styles = array();
// Get all templates in current theme folder
$styles = File::scan(THEMES_SITE . DS . $theme . DS . 'css', '.css');
return $styles;
}
/**
* Get Scripts
*
* @param string $theme Theme name
* @return array
*/
public static function getScripts($theme = null) {
$theme = ($theme === null) ? null : (string) $theme;
if ($theme == null) $theme = Option::get('theme_site_name');
$scripts = array();
// Get all templates in current theme folder
$scripts = File::scan(THEMES_SITE . DS . $theme . DS . 'js', '.js');
return $scripts;
}
}
/**
* Chunk frontend class
*/
class Chunk {
/**
* Get chunk
*
* @param string $name Chunk name
* @param string $theme Theme name
*/
public static function get($name, $theme = null) {
$name = (string) $name;
$current_theme = ($theme === null) ? null : (string) $theme;
if ($current_theme == null) $current_theme = Option::get('theme_site_name');
$chunk_path = THEMES_SITE . DS . $current_theme . DS;
// Is chunk exist ?
if (file_exists($chunk_path . $name . '.chunk.php')) {
// Is chunk minified
if ( ! file_exists(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $name . '.chunk.php') or
filemtime(THEMES_SITE . DS . $current_theme . DS . $name .'.chunk.php') > filemtime(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $name . '.chunk.php')) {
$buffer = file_get_contents(THEMES_SITE. DS . $current_theme . DS . $name .'.chunk.php');
$buffer = Minify::html($buffer);
file_put_contents(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $name . '.chunk.php', $buffer);
}
// Include chunk
include MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $name . '.chunk.php';
}
}
}

View File

@@ -0,0 +1,47 @@
<?php if ($action == 'chunk') { ?><h2><?php echo __('New chunk', 'themes'); ?></h2><?php } ?>
<?php if ($action == 'template') { ?><h2><?php echo __('New template', 'themes'); ?></h2><?php } ?>
<?php if ($action == 'styles') { ?><h2><?php echo __('New styles', 'themes'); ?></h2><?php } ?>
<?php if ($action == 'script') { ?><h2><?php echo __('New script', 'themes'); ?></h2><?php } ?>
<br />
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php if (isset($errors['file_empty_name']) || isset($errors['file_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', 'themes'))); ?>
<div class="input-append">
<?php echo (Form::input('name', $name, array('class' => 'input-xlarge'))); ?>
<?php if ($action == 'chunk') { ?><span class="add-on">.chunk.php</span><?php } ?>
<?php if ($action == 'template') { ?><span class="add-on">.template.php</span><?php } ?>
<?php if ($action == 'styles') { ?><span class="add-on">.css</span><?php } ?>
<?php if ($action == 'script') { ?><span class="add-on">.js</span><?php } ?>
</div>
<?php
if (isset($errors['file_empty_name'])) echo '&nbsp;&nbsp;&nbsp;<span style="color:red">'.$errors['file_empty_name'].'</span>';
if (isset($errors['file_exists'])) echo '&nbsp;&nbsp;&nbsp;<span style="color:red">'.$errors['file_exists'].'</span>';
?>
<br><br>
<?php
if ($action == 'chunk') { echo Form::label('content', __('Chunk content', 'themes')); }
if ($action == 'template') { echo Form::label('content', __('Template content', 'themes')); }
if ($action == 'styles') { echo Form::label('content', __('Styles content', 'themes')); }
if ($action == 'script') { echo Form::label('content', __('Script content', 'themes')); }
echo Form::textarea('content', $content, array('style' => 'width:100%;height:400px;', 'class' => 'source-editor'));
echo (
Html::br(2).
Form::submit('add_file_and_exit', __('Save and exit', 'themes'), array('class' => 'btn')).Html::nbsp(2).
Form::submit('add_file', __('Save', 'themes'), array('class' => 'btn')).
Form::close()
);
?>

View File

@@ -0,0 +1,64 @@
<?php if ($action == 'chunk') { ?><h2><?php echo __('Edit chunk', 'themes'); ?></h2><?php } ?>
<?php if ($action == 'template') { ?><h2><?php echo __('Edit template', 'themes'); ?></h2><?php } ?>
<?php if ($action == 'styles') { ?><h2><?php echo __('Edit styles', 'themes'); ?></h2><?php } ?>
<?php if ($action == 'script') { ?><h2><?php echo __('Edit script', 'themes'); ?></h2><?php } ?>
<br />
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php
if ($content !== null) {
if (isset($errors['file_empty_name']) or isset($errors['file_exists'])) $error_class = 'error'; else $error_class = '';
echo (Form::open(null, array('class' => 'form-horizontal')));
echo (Form::hidden('csrf', Security::token()));
?>
<?php if ($action == 'chunk') { echo (Form::hidden('chunk_old_name', Request::get('filename'))); } ?>
<?php if ($action == 'template') { echo (Form::hidden('template_old_name', Request::get('filename'))); } ?>
<?php if ($action == 'styles') { echo (Form::hidden('styles_old_name', Request::get('filename'))); } ?>
<?php if ($action == 'script') { echo (Form::hidden('script_old_name', Request::get('filename'))); } ?>
<?php echo (Form::label('name', __('Name', 'themes'))); ?>
<div class="input-append">
<?php echo (Form::input('name', $name, array('class' => 'input-xlarge'))); ?>
<?php if ($action == 'chunk') { ?><span class="add-on">.chunk.php</span><?php } ?>
<?php if ($action == 'template') { ?><span class="add-on">.template.php</span><?php } ?>
<?php if ($action == 'styles') { ?><span class="add-on">.css</span><?php } ?>
<?php if ($action == 'script') { ?><span class="add-on">.js</span><?php } ?>
</div>
<?php
if (isset($errors['file_empty_name'])) echo '&nbsp;&nbsp;&nbsp;<span style="color:red">'.$errors['file_empty_name'].'</span>';
if (isset($errors['file_exists'])) echo '&nbsp;&nbsp;&nbsp;<span style="color:red">'.$errors['file_exists'].'</span>';
?>
<br><br>
<?php
if ($action == 'chunk') { echo Form::label('content', __('Chunk content', 'themes')); }
if ($action == 'template') { echo Form::label('content', __('Template content', 'themes')); }
if ($action == 'styles') { echo Form::label('content', __('Styles content', 'themes')); }
if ($action == 'script') { echo Form::label('content', __('Script content', 'themes')); }
echo (
Form::textarea('content', Html::toText($content), array('style' => 'width:100%;height:400px;', 'class' => 'source-editor')).
Html::br(2).
Form::submit('edit_file_and_exit', __('Save and exit', 'themes'), array('class' => 'btn default')).Html::nbsp(2).
Form::submit('edit_file', __('Save', 'themes'), array('class' => 'btn default')). Html::nbsp().
Form::close()
);
} else {
if ($action == 'chunk') { echo '<div class="message-error">'.__('This chunk does not exist', 'themes').'</div>'; }
if ($action == 'template') { echo '<div class="message-error">'.__('This template does not exist', 'themes').'</div>'; }
if ($action == 'styles') { echo '<div class="message-error">'.__('This styles does not exist', 'themes').'</div>'; }
if ($action == 'script') { echo '<div class="message-error">'.__('This script does not exist', 'themes').'</div>'; }
}
?>

View File

@@ -0,0 +1,199 @@
<div class="row-fluid">
<div class="span6">
<h2><?php echo __('Site theme', 'themes'); ?></h2>
<br />
<!-- Themes_selector -->
<?php
echo (
Form::open().
Form::hidden('csrf', Security::token()).
Form::label('themes', __('Select theme', 'themes')).
Form::select('themes', $themes_site, $current_site_theme, array('class' => 'span6')). Html::br().
Form::submit('save_site_theme', __('Save', 'themes'), array('class' => 'btn')).
Form::close()
);
?>
<!-- /Themes_selector -->
</div>
<div class="span6">
<h2><?php echo __('Admin theme', 'themes'); ?></h2>
<br />
<!-- Themes_selector -->
<?php
echo (
Form::open().
Form::hidden('csrf', Security::token()).
Form::label('themes', __('Select theme', 'themes')).
Form::select('themes', $themes_admin, $current_admin_theme, array('class' => 'span6')). Html::br().
Form::submit('save_admin_theme', __('Save', 'themes'), array('class' => 'btn')).
Form::close()
);
?>
<!-- /Themes_selector -->
</div>
</div>
<hr>
<div class="row-fluid">
<div class="span12">
<?php
echo (
Html::heading(__('Current site theme', 'themes') . ': '. $current_site_theme, 2). Html::br()
);
?>
<?php echo (Html::anchor(__('Create new template', 'themes'), 'index.php?id=themes&action=add_template', array('title' => __('Create new template'), 'class' => 'btn btn-small')).Html::br(2)); ?>
<!-- Templates_list -->
<table class="table table-bordered">
<thead>
<tr><td><?php echo __('Templates', 'themes'); ?></td><td width="40%"><?php echo __('Actions', 'themes'); ?></td></tr>
</thead>
<tbody>
<?php if (count($templates) != 0) foreach ($templates as $template) { ?>
<tr>
<td><?php echo basename($template, '.template.php'); ?></td>
<td>
<div class="btn-toolbar">
<div class="btn-group">
<?php echo Html::anchor(__('Edit', 'themes'), 'index.php?id=themes&action=edit_template&filename='.basename($template, '.template.php'), array('class' => 'btn btn-actions')); ?>
<a class="btn dropdown-toggle btn-actions" data-toggle="dropdown" href="#" style="font-family:arial;"><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><?php echo Html::anchor(__('Clone', 'themes'), 'index.php?id=themes&action=clone_template&filename='.basename($template, '.template.php'), array('title' => __('Clone'))); ?></li>
</ul>
<?php echo Html::anchor(__('Delete', 'themes'),
'index.php?id=themes&action=delete_template&filename='.basename($template, '.template.php'),
array('class' => 'btn btn-actions btn-actions-default', 'onclick' => "return confirmDelete('".__('Delete template: :name', 'themes', array(':name' => basename($template, '.template.php')))."')"));
?>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<!-- /Templates_list -->
<?php echo (Html::anchor(__('Create new chunk', 'themes'), 'index.php?id=themes&action=add_chunk', array('title' => __('Create new chnuk', 'themes'), 'class' => 'btn btn-small')).Html::br(2)); ?>
<!-- Chunks_list -->
<table class="table table-bordered">
<thead>
<tr><td><?php echo __('Chunks', 'themes'); ?></td><td width="40%"><?php echo __('Actions', 'themes'); ?></td></tr>
</thead>
<tbody>
<?php if (count($chunks) != 0) foreach ($chunks as $chunk) { ?>
<tr>
<td><?php echo basename($chunk, '.chunk.php'); ?></td>
<td>
<div class="btn-toolbar">
<div class="btn-group">
<?php echo Html::anchor(__('Edit', 'themes'), 'index.php?id=themes&action=edit_chunk&filename='.basename($chunk, '.chunk.php'), array('class' => 'btn btn-actions')); ?>
<a class="btn dropdown-toggle btn-actions" data-toggle="dropdown" href="#" style="font-family:arial;"><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><?php echo Html::anchor(__('Clone', 'themes'), 'index.php?id=themes&action=clone_chunk&filename='.basename($chunk, '.chunk.php'), array('title' => __('Clone', 'themes'))); ?></li>
</ul>
<?php echo Html::anchor(__('Delete', 'themes'),
'index.php?id=themes&action=delete_chunk&filename='.basename($chunk, '.chunk.php'),
array('class' => 'btn btn-actions btn-actions-default', 'onclick' => "return confirmDelete('".__('Delete chunk: :name', 'themes', array(':name' => basename($chunk, '.chunk.php')))."')"));
?>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<!-- /Chunks_list -->
<?php echo (Html::anchor(__('Create new styles', 'themes'), 'index.php?id=themes&action=add_styles', array('title' => __('Create new style', 'themes'), 'class' => 'btn btn-small')).Html::br(2)); ?>
<!-- Styles_list -->
<table class="table table-bordered">
<thead>
<tr><td><?php echo __('Styles', 'themes'); ?></td><td width="40%"><?php echo __('Actions', 'themes'); ?></td></tr>
</thead>
<tbody>
<?php if (count($styles) != 0) foreach ($styles as $style) { ?>
<tr>
<td><?php echo basename($style, '.css'); ?></td>
<td>
<div class="btn-toolbar">
<div class="btn-group">
<?php echo Html::anchor(__('Edit', 'themes'), 'index.php?id=themes&action=edit_styles&filename='.basename($style, '.css'), array('class' => 'btn btn-actions')); ?>
<a class="btn dropdown-toggle btn-actions" data-toggle="dropdown" href="#" style="font-family:arial;"><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><?php echo Html::anchor(__('Clone', 'themes'), 'index.php?id=themes&action=clone_styles&filename='.basename($style, '.css'), array('title' => __('Clone', 'themes'))); ?></li>
</ul>
<?php echo Html::anchor(__('Delete', 'themes'),
'index.php?id=themes&action=delete_styles&filename='.basename($style, '.css'),
array('class' => 'btn btn-actions btn-actions-default', 'onclick' => "return confirmDelete('".__('Delete styles: :name', 'themes', array(':name' => basename($style, '.css')))."')"));
?>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<!-- /Styles_list -->
<?php echo (Html::anchor(__('Create new script', 'themes'), 'index.php?id=themes&action=add_script', array('title' => __('Create new script', 'themes'), 'class' => 'btn btn-small')).Html::br(2)); ?>
<!-- Scripts_list -->
<table class="table table-bordered">
<thead>
<tr><td><?php echo __('Scripts', 'themes'); ?></td><td width="40%"><?php echo __('Actions', 'themes'); ?></td></tr>
</thead>
<tbody>
<?php if (count($scripts) != 0) foreach ($scripts as $script) { ?>
<tr>
<td><?php echo basename($script, '.js'); ?></td>
<td>
<div class="btn-toolbar">
<div class="btn-group">
<?php echo Html::anchor(__('Edit', 'themes'), 'index.php?id=themes&action=edit_script&filename='.basename($script, '.js'), array('class' => 'btn btn-actions')); ?>
<a class="btn dropdown-toggle btn-actions" data-toggle="dropdown" href="#" style="font-family:arial;"><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><?php echo Html::anchor(__('Clone', 'themes'), 'index.php?id=themes&action=clone_script&filename='.basename($script, '.js'), array('title' => __('Clone', 'themes'))); ?></li>
</ul>
<?php echo Html::anchor(__('Delete', 'themes'),
'index.php?id=themes&action=delete_script&filename='.basename($script, '.js'),
array('class' => 'btn btn-actions btn-actions-default', 'onclick' => "return confirmDelete('".__('Delete script: :name', 'themes', array(':name' => basename($script, '.js')))."')"));
?>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<!-- /Scripts_list -->
<?php // All exept Pages, Users and Sitemap plugins
if(count(Plugin::$components) > 3) {
?>
<h2><?php echo __('Components templates', 'themes'); ?></h2><br />
<?php
// Its mean that you can add your own actions for this plugin
Action::run('admin_themes_extra_index_template_actions');
}
?>
</div>
</div>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<plugin_location>plugins/box/users/users.plugin.php</plugin_location>
<plugin_status>active</plugin_status>
<plugin_priority>7</plugin_priority>
<plugin_name>Users</plugin_name>
<plugin_description>Users 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,60 @@
<?php
return array(
'users' => array(
'Users' => 'Users',
'Login' => 'Login',
'Username' => 'Username',
'Password' => 'Password',
'Registered' => 'Registered',
'Email' => 'Email',
'Role' => 'Role',
'Roles' => 'Roles',
'Edit' => 'Edit',
'Actions' => 'Actions',
'Delete' => 'Delete',
'Enter' => 'Enter',
'Logout' => 'Logout',
'Register new user' => 'Register new user',
'New User Registration' => 'New User Registration',
'Delete user: :user' => 'Delete user: :user',
'User <i>:user</i> have been deleted.' => 'User <i>:user</i> have been deleted.',
'This field should not be empty' => 'This field should not be empty',
'This user alredy exist' => 'This user alredy exist',
'Changes saved' => 'Changes saved',
'Wrong old password' => 'Wrong old password',
'Admin' => 'Admin',
'User' => 'User',
'Editor' => 'Editor',
'Register' => 'Register',
'Edit profile' => 'Edit profile',
'Save' => 'Save',
'Firstname' => 'Firstname',
'Lastname' => 'Lastname',
'Old password' => 'Old password',
'New password' => 'New password',
'Welcome' => 'Welcome',
'Wrong <b>username</b> or <b>password</b>' => 'Wrong <b>username</b> or <b>password</b>',
'Your changes have been saved.' => 'Your changes have been saved.',
'New user have been registered.' => 'New user have been registered.',
'Captcha' => 'Captcha',
'Registration' => 'Registration',
'Username' => 'Username',
'User email is invalid' => 'User email is invalid',
'Reset Password' => 'Reset Password',
'Send New Password' => 'Send New Password',
'This user doesnt alredy exist' => 'This user doesnt alredy exist',
'Users - Profile' => 'Users - Profile',
'Users - Edit Profile' => 'Users - Edit Profile',
'Users - Login' => 'Users - Login',
'Users - Registration' => 'Users - Registration',
'Users - Password Recover' => 'Users - Password Recover',
'New Password' => 'New Password',
'Forgot your password?' => 'Forgot your password?',
'New password has been sent' => 'New password has been sent',
'Monstra says: This is not your profile...' => 'Monstra says: This is not your profile...',
'User registration is closed.' => 'User registration is closed.',
'Allow user registration' => 'Allow user registration',
'Required field' => 'Required field',
)
);

View File

@@ -0,0 +1,59 @@
<?php
return array(
'users' => array(
'Users' => 'Пользователи',
'Login' => 'Вход',
'Password' => 'Пароль',
'Email' => 'Емейл',
'Registered' => 'Зарегистрирован',
'Role' => 'Роль',
'Roles' => 'Роли',
'Actions' => 'Действия',
'Edit' => 'Редактировать',
'Delete' => 'Удалить',
'Enter' => 'Вход',
'Logout' => 'Выход',
'New User Registration' => 'Регистрация нового пользователя',
'Register new user' => 'Регистрация нового пользователя',
'Delete user: :user' => 'Удалить пользователя: :user',
'User <i>:user</i> have been deleted.' => 'Пользователь <i>:user</i> удален.',
'This field should not be empty' => 'Это поле не должно быть пустым',
'This user alredy exist' => 'Такой пользователь уже существует',
'Changes saved' => 'Изменения сохранены',
'Wrong old password' => 'Неправильный старый пароль',
'Admin' => 'Администратор',
'User' => 'Пользователь',
'Editor' => 'Редактор',
'Register' => 'Регистрация',
'Edit profile' => 'Редактирование профиля пользователя',
'Save' => 'Сохранить',
'Firstname' => 'Имя',
'Lastname' => 'Фамилия',
'Old password' => 'Старый пароль',
'New password' => 'Новый пароль',
'Welcome' => 'Добро пожаловать',
'Wrong <b>login</b> or <b>password</b>' => 'Неправильный <b>логин</b> или <b>пароль</b>',
'Your changes have been saved.' => 'Ваши изменения были сохранены.',
'New user have been registered.' => 'Новый пользователь был зарегистрирован.',
'Captcha' => 'Капча',
'Registration' => 'Регистрация',
'Username' => 'Имя пользователя',
'User email is invalid' => 'Электронная почта является недействительной',
'Reset Password' => 'Сбросить пароль',
'Send New Password' => 'Отослать пароль',
'This user doesnt alredy exist' => 'Такого пользователя не существует',
'Users - Profile' => 'Пользователи - Профиль',
'Users - Edit Profile' => 'Пользователи - Редактирование профиля',
'Users - Login' => 'Пользователи - Вход',
'Users - Registration' => 'Пользователи - Регистрация',
'Users - Password Recover' => 'Пользователи - Восстановление пароля',
'New Password' => 'Новый пароль',
'Forgot your password?' => 'Забыли пароль ?',
'New password has been sent' => 'Новый пароль был отправлен',
'Monstra says: This is not your profile...' => 'Монстра говорит: Это не твой профиль.',
'User registration is closed.' => 'Регистрация пользователей закрыта.',
'Allow user registration' => 'Разрешить регистрацию пользователей.',
'Required field' => 'Обязательное поле',
)
);

View File

@@ -0,0 +1,214 @@
<?php
// Check if is user is logged in then set variables for welcome button
if (Session::exists('user_id')) {
$user_id = Session::get('user_id');
$user_login = Session::get('user_login');
} else {
$user_id = '';
$user_login = '';
}
Navigation::add(__('Users', 'users'), 'system', 'users', 2);
Action::add('admin_header', 'UsersAdmin::headers');
class UsersAdmin extends Backend {
public static function headers() {
echo ('
<script>
$(document).ready(function(){
$("[name=users_frontend_registration] , [name=users_frontend_authorization]").click(function() {
$("[name=users_frontend]").submit();
});
});
</script>
');
}
/**
* Users admin
*/
public static function main() {
// Users roles
$roles = array('admin' => __('Admin', 'users'),
'editor' => __('Editor', 'users'),
'user' => __('User', 'users'));
// Get uses table
$users = new Table('users');
if (Option::get('users_frontend_registration') == 'true') {
$users_frontend_registration = true;
} else {
$users_frontend_registration = false;
}
if (Request::post('users_frontend_submit')) {
if (Request::post('users_frontend_registration')) $users_frontend_registration = 'true'; else $users_frontend_registration = 'false';
Option::update('users_frontend_registration', $users_frontend_registration);
Request::redirect('index.php?id=users');
}
// Check for get actions
// ---------------------------------------------
if (Request::get('action')) {
// Switch actions
// -----------------------------------------
switch (Request::get('action')) {
// Add
// -------------------------------------
case "add":
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) {
$errors = array();
if (Request::post('register')) {
if (Security::check(Request::post('csrf'))) {
$user_login = trim(Request::post('login'));
$user_password = trim(Request::post('password'));
if ($user_login == '') $errors['users_empty_login'] = __('This field should not be empty', 'users');
if ($user_password == '') $errors['users_empty_password'] = __('This field should not be empty', 'users');
$user = $users->select("[login='".$user_login."']");
if ($user != null) $errors['users_this_user_alredy_exists'] = __('This user alredy exist', 'users');
if (count($errors) == 0) {
$users->insert(array('login' => Security::safeName($user_login),
'password' => Security::encryptPassword(Request::post('password')),
'email' => Request::post('email'),
'date_registered' => time(),
'role' => Request::post('role')));
Notification::set('success', __('New user have been registered.', 'users'));
Request::redirect('index.php?id=users');
}
} else { die('csrf detected!'); }
}
// Display view
View::factory('box/users/views/backend/add')
->assign('roles', $roles)
->assign('errors', $errors)
->display();
} else {
Request::redirect('index.php?id=users&action=edit&user_id='.Session::get('user_id'));
}
break;
// Edit
// -------------------------------------
case "edit":
// Get current user record
$user = $users->select("[id='".(int)Request::get('user_id')."']", null);
if (isset($user['firstname'])) $user_firstname = $user['firstname']; else $user_firstname = '';
if (isset($user['lastname'])) $user_lastname = $user['lastname']; else $user_lastname = '';
if (isset($user['email'])) $user_email = $user['email']; else $user_email = '';
if (isset($user['twitter'])) $user_twitter = $user['twitter']; else $user_twitter = '';
if (isset($user['skype'])) $user_skype = $user['skype']; else $user_skype = '';
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor'))) {
if ((Request::post('edit_profile')) and
(((int)Session::get('user_id') == (int)Request::get('user_id')) or
(in_array(Session::get('user_role'), array('admin'))))){
if (Security::check(Request::post('csrf'))) {
if (Security::safeName(Request::post('login')) != '') {
if ($users->update(Request::post('user_id'), array('login' => Security::safeName(Request::post('login')),
'firstname' => Request::post('firstname'),
'lastname' => Request::post('lastname'),
'email' => Request::post('email'),
'skype' => Request::post('skype'),
'twitter' => Request::post('twitter'),
'role' => Request::post('role')))) {
Notification::set('success', __('Your changes have been saved.', 'users'));
Request::redirect('index.php?id=users&action=edit&user_id='.Request::post('user_id'));
}
} else { }
} else { die('csrf detected!'); }
}
if (Request::post('edit_profile_password')) {
if (Security::check(Request::post('csrf'))) {
if (trim(Request::post('new_password')) != '') {
$users->update(Request::post('user_id'), array('password' => Security::encryptPassword(trim(Request::post('new_password')))));
Notification::set('success', __('Your changes have been saved.', 'users'));
Request::redirect('index.php?id=users&action=edit&user_id='.Request::post('user_id'));
}
} else { die('csrf detected!'); }
}
if ( ((int)Session::get('user_id') == (int)Request::get('user_id')) or (in_array(Session::get('user_role'), array('admin')) && count($user) != 0) ) {
// Display view
View::factory('box/users/views/backend/edit')
->assign('user', $user)
->assign('user_firstname', $user_firstname)
->assign('user_lastname', $user_lastname)
->assign('user_email', $user_email)
->assign('user_twitter', $user_twitter)
->assign('user_skype', $user_skype)
->assign('roles', $roles)
->display();
} else {
echo __('Monstra says: This is not your profile...', 'users');
}
}
break;
// Delete
// -------------------------------------
case "delete":
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) {
$user = $users->select('[id="'.Request::get('user_id').'"]', null);
$users->delete(Request::get('user_id'));
Notification::set('success', __('User <i>:user</i> have been deleted.', 'users', array(':user' => $user['login'])));
Request::redirect('index.php?id=users');
}
break;
}
} else {
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) {
// Get all records from users table
$users_list = $users->select();
// Dislay view
View::factory('box/users/views/backend/index')
->assign('roles', $roles)
->assign('users_list', $users_list)
->assign('users_frontend_registration', $users_frontend_registration)
->display();
} else {
Request::redirect('index.php?id=users&action=edit&user_id='.Session::get('user_id'));
}
}
}
}

View File

@@ -0,0 +1,399 @@
<?php
/**
* Users plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Users', 'users'),
__('Users manager', 'users'),
'1.0.0',
'Awilum',
'http://monstra.org/',
'users',
'box');
// Include Users Admin
Plugin::Admin('users', 'box');
/**
* Users class
*/
class Users extends Frontend {
/**
* Users table
*/
public static $users = null;
/**
* Sandbox main function
*/
public static function main(){
// Get users table
Users::$users = new Table('users');
// Logout
if (Uri::segment(1) == 'logout') { Users::logout(); }
}
/**
* Route
*/
protected static function route() {
/* /users */
if (Uri::segment(0) == 'users' && !Uri::segment(1)) return 'list';
/* /users/(int) */
if (Uri::segment(1) && (Uri::segment(1) !== 'login' && Uri::segment(1) !== 'registration' && Uri::segment(1) !== 'password-reset' && Uri::segment(2) !== 'edit')) return 'profile';
/* /users/login */
if (Uri::segment(1) == 'login') return 'login';
/* /users/registration */
if (Uri::segment(1) == 'registration') return 'registration';
/* /pusers/password-reset */
if (Uri::segment(1) == 'password-reset') return 'password-reset';
/* /users/(int)/edit */
if ( ( Uri::segment(1) and (Uri::segment(1) !== 'login' && Uri::segment(1) !== 'registration' && Uri::segment(1) !== 'password-reset') ) and Uri::segment(2) == 'edit') return 'edit';
/* /users/logout */
if (Uri::segment(1) == 'logout') return 'logout';
}
/**
* Get users list
*/
public static function getList() {
View::factory('box/users/views/frontend/index')
->assign('users', Users::$users->select(null, 'all'))
->display();
}
/**
* Get user profile
*/
public static function getProfile($id) {
View::factory('box/users/views/frontend/profile')
->assign('user', Users::$users->select("[id=".(int)$id."]", null))
->display();
}
/**
* Get New User Registration
*/
public static function getRegistration() {
if (Option::get('users_frontend_registration') == 'true') {
// Is User Loged in ?
if ( ! Session::get('user_id')) {
$errors = array();
$user_email = Request::post('email');
$user_login = Request::post('login');
$user_password = Request::post('password');
// Register form submit
if (Request::post('register')) {
// Check csrf
if (Security::check(Request::post('csrf'))) {
$user_email = trim($user_email);
$user_login = trim($user_login);
$user_password = trim($user_password);
if (Option::get('captcha_installed') == 'true' && ! CryptCaptcha::check(Request::post('answer'))) $errors['users_captcha_wrong'] = __('Captcha code is wrong', 'captcha');
if ($user_login == '') $errors['users_empty_login'] = __('Required field', 'users');
if ($user_password == '') $errors['users_empty_password'] = __('Required field', 'users');
if ($user_email == '') $errors['users_empty_email'] = __('Required field', 'users');
if ($user_email != '' && ! Valid::email($user_email)) $errors['users_invalid_email'] = __('User email is invalid', 'users');
if (Users::$users->select("[login='".$user_login."']")) $errors['users_this_user_alredy_exists'] = __('This user alredy exist', 'users');
if (Users::$users->select("[email='".$user_email."']")) $errors['users_this_email_alredy_exists'] = __('This email alredy exist', 'users');
if (count($errors) == 0) {
Users::$users->insert(array('login' => Security::safeName($user_login),
'password' => Security::encryptPassword(Request::post('password')),
'email' => Request::post('email'),
'date_registered' => time(),
'role' => 'user'));
// Log in
$user = Users::$users->select("[id='".Users::$users->lastId()."']", null);
Session::set('user_id', (int)$user['id']);
Session::set('user_login', (string)$user['login']);
Session::set('user_role', (string)$user['role']);
// Redirect to user profile
Request::redirect(Option::get('siteurl').'users/'.Users::$users->lastId());
}
} else { die('csrf detected!'); }
}
// Display view
View::factory('box/users/views/frontend/registration')
->assign('errors', $errors)
->assign('user_email', $user_email)
->assign('user_login', $user_login)
->assign('user_password', $user_password)
->display();
} else {
Request::redirect(Site::url().'users/'.Session::get('user_id'));
}
} else {
echo __('User registration is closed.', 'users');
}
}
/**
* Get user panel
*/
public static function getPanel() {
View::factory('box/users/views/frontend/userspanel')->display();
}
/**
* Is User Loged
*/
public static function isLoged() {
if ((Session::get('user_id')) and (((int)Session::get('user_id') == Uri::segment(1)) or (in_array(Session::get('user_role'), array('admin'))))) {
return true;
} else {
return false;
}
}
/**
* Logout
*/
public static function logout() {
Session::destroy(); Request::redirect(Site::url().'users/login');
}
/**
* Edit user profile
*/
public static function getProfileEdit($id) {
// Is Current User Loged in ?
if (Users::isLoged()) {
$user = Users::$users->select("[id='".(int)$id."']", null);
// Edit Profile Submit
if (Request::post('edit_profile')) {
// Check csrf
if (Security::check(Request::post('csrf'))) {
if (Security::safeName(Request::post('login')) != '') {
if (Users::$users->update(Request::post('user_id'),
array('login' => Security::safeName(Request::post('login')),
'firstname' => Request::post('firstname'),
'lastname' => Request::post('lastname'),
'email' => Request::post('email'),
'skype' => Request::post('skype'),
'twitter' => Request::post('twitter')))) {
// Change password
if (trim(Request::post('new_password')) != '') {
Users::$users->update(Request::post('user_id'), array('password' => Security::encryptPassword(trim(Request::post('new_password')))));
}
Notification::set('success', __('Your changes have been saved.', 'users'));
Request::redirect(Site::url().'users/'.$user['id'].'/edit');
}
} else { }
} else { die('csrf detected!'); }
}
View::factory('box/users/views/frontend/edit')
->assign('user', $user)
->display();
} else {
Request::redirect(Site::url().'users/login');
}
}
/**
* Get Password Reset
*/
public static function getPasswordReset() {
// Is User Loged in ?
if ( ! Session::get('user_id')) {
$errors = array();
$user_login = Request::post('login');
// Reset Password Form Submit
if (Request::post('reset_password_submit')) {
$user_login = trim($user_login);
// Check csrf
if (Security::check(Request::post('csrf'))) {
if (Option::get('captcha_installed') == 'true' && ! CryptCaptcha::check(Request::post('answer'))) $errors['users_captcha_wrong'] = __('Captcha code is wrong', 'users');
if ($user_login == '') $errors['users_empty_field'] = __('Required field', 'users');
if ($user_login != '' && ! Users::$users->select("[login='".$user_login."']")) $errors['users_user_doesnt_exists'] = __('This user doesnt alredy exist', 'users');
if (count($errors) == 0) {
$user = Users::$users->select("[login='" . $user_login . "']", null);
// Generate new password
$new_password = Text::random('alnum', 6);
// Update user profile
Users::$users->updateWhere("[login='" . $user_login . "']", array('password' => Security::encryptPassword($new_password)));
// Message
$message = "Login: {$user['login']}\nNew Password: {$new_password}";
// Send
@mail($user['email'], 'MonstraPasswordReset', $message);
// Set notification
Notification::set('success', __('New password has been sent', 'users'));
// Redirect to password-reset page
Request::redirect(Site::url().'users/password-reset');
}
} else { die('csrf detected!'); }
}
View::factory('box/users/views/frontend/password_reset')
->assign('errors', $errors)
->assign('user_login', $user_login)
->display();
}
}
/**
* Get User login
*/
public static function getLogin() {
// Is User Loged in ?
if ( ! Session::get('user_id')) {
// Login Form Submit
if (Request::post('login_submit')) {
// Check csrf
if (Security::check(Request::post('csrf'))) {
$user = Users::$users->select("[login='" . trim(Request::post('username')) . "']", null);
if (count($user) !== 0) {
if ($user['login'] == Request::post('username')) {
if (trim($user['password']) == Security::encryptPassword(Request::post('password'))) {
if ($user['role'] == 'admin' || $user['role'] == 'editor') {
Session::set('admin', true);
}
Session::set('user_id', (int)$user['id']);
Session::set('user_login', (string)$user['login']);
Session::set('user_role', (string)$user['role']);
Request::redirect(Site::url().'users/'.Session::get('user_id'));
} else {
Notification::setNow('error', __('Wrong <b>login</b> or <b>password</b>', 'users'));
}
}
} else {
Notification::setNow('error', __('Wrong <b>login</b> or <b>password</b>', 'users'));
}
} else { die('csrf detected!'); }
}
View::factory('box/users/views/frontend/login')->display();
} else {
Request::redirect(Site::url().'users/'.Session::get('user_id'));
}
}
/**
* Set title
*/
public static function title(){
switch (Users::route()) {
case 'list': return __('Users'); break;
case 'profile': return __('Users - Profile'); break;
case 'edit': return __('Users - Edit Profile'); break;
case 'login': return __('Users - Login'); break;
case 'registration': return __('Users - Registration'); break;
case 'password-reset': return __('Users - Password Recover'); break;
}
}
/**
* Set content
*/
public static function content(){
switch (Users::route()) {
case 'list': Users::getList(); break;
case 'profile': Users::getProfile(Uri::segment(1)); break;
case 'edit': Users::getProfileEdit(Uri::segment(1)); break;
case 'login': Users::getLogin(); break;
case 'registration': Users::getRegistration(); break;
case 'password-reset': Users::getPasswordReset(); break;
}
}
/**
* Set template
*/
public static function template() {
return 'index';
}
/**
* Get Gravatar
*/
public static function getGravatarURL($email, $size) {
return 'http://www.gravatar.com/avatar.php?gravatar_id='.md5($email).'&rating=PG'.'&size='.$size;
}
}

View File

@@ -0,0 +1,32 @@
<!-- Users_add -->
<?php
echo ( '<h2>'.__('New User Registration', 'users').'</h2>' );
echo (
Html::br().
Form::open().
Form::hidden('csrf', Security::token()).
Form::label('login', __('Username', 'users')).
Form::input('login', null, array('class' => 'span3'))
);
if (isset($errors['users_this_user_alredy_exists'])) echo Html::nbsp(3).'<span class="error">'.$errors['users_this_user_alredy_exists'].'</span>';
if (isset($errors['users_empty_login'])) echo Html::nbsp(3).'<span class="error">'.$errors['users_empty_login'].'</span>';
echo (
Form::label('password', __('Password', 'users')).
Form::password('password', null, array('class' => 'span3'))
);
if (isset($errors['users_empty_password'])) echo Html::nbsp(3).'<span class="error">'.$errors['users_empty_password'].'</span>';
echo (
Form::label('email', __('Email', 'users')).
Form::input('email', null, array('class' => 'span3')). Html::br().
Form::label('role', __('Role', 'users')).
Form::select('role', array('admin' => __('Admin', 'users'), 'editor' => __('Editor', 'users'), 'user' => __('User', 'users')), null, array('class' => 'span3')). Html::br(2).
Form::submit('register', __('Register', 'users'), array('class' => 'btn default')).
Form::close()
);
?>
<!-- /Users_add -->

View File

@@ -0,0 +1,89 @@
<!-- Users_edit -->
<?php
// Show template for exist user else show error
if ($user !== null) {
echo ( '<h2>'.__('Edit profile', 'users').'</h2>' );
?>
<br />
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php if (Notification::get('error')) Alert::error(Notification::get('error')); ?>
<div>
<div class="span7">
<?php
echo (
Form::open().
Form::hidden('csrf', Security::token()).
Form::hidden('user_id', Request::get('user_id'))
);
if (isset($_SESSION['user_role']) && in_array($_SESSION['user_role'], array('admin'))) {
echo Form::label('login', __('Username', 'users'));
echo Form::input('login', $user['login'], array('class' => 'span6'));
} else {
echo Form::hidden('login', $user['login']);
}
echo (
Html::br().
Form::label('firstname', __('Firstname', 'users')).
Form::input('firstname', $user_firstname, array('class' => 'span6')).Html::br().
Form::label('lastname', __('Lastname', 'users')).
Form::input('lastname', $user_lastname, array('class' => 'span6')).Html::br().
Form::label('email', __('Email', 'users')).
Form::input('email', $user_email, array('class' => 'span6')).Html::br().
Form::label('twitter', __('Twitter', 'users')).
Form::input('twitter', $user_twitter, array('class' => 'span6')).Html::br().
Form::label('skype', __('Skype', 'users')).
Form::input('skype', $user_skype, array('class' => 'span6')).Html::br()
);
if (isset($_SESSION['user_role']) && in_array($_SESSION['user_role'], array('admin'))) {
echo Form::label('role', __('Role', 'users'));
echo Form::select('role', array('admin' => __('Admin', 'users'), 'editor' => __('Editor', 'users'), 'user' => __('User', 'users')), $user['role'], array('class' => 'span3')). Html::br();
} else {
echo Form::hidden('role', $_SESSION['user_role']);
}
echo (
Html::br().
Form::submit('edit_profile', __('Save', 'users'), array('class' => 'btn')).
Form::close()
);
?>
</div>
<div class="span5">
<?php
echo (
Form::open().
Form::hidden('csrf', Security::token()).
Form::hidden('user_id', Request::get('user_id')).
Form::label('new_password', __('New password', 'users')).
Form::password('new_password', null, array('class' => 'span6')).Html::br().Html::br().
Form::submit('edit_profile_password', __('Save', 'users'), array('class' => 'btn')).
Form::close()
);
?>
</div>
</div>
<div style="clear:both"></div>
<?php
} else {
echo '<div class="message-error">'.__('This user does not exist', 'users').'</div>';
}
?>
<!-- /Users_edit -->

View File

@@ -0,0 +1,55 @@
<h2><?php echo __('Users', 'users'); ?></h2>
<br />
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php echo Html::anchor(__('Register new user', 'users'), 'index.php?id=users&action=add', array('title' => __('Create new page', 'users'), 'class' => 'btn default btn-small')); ?>
<div class="pull-right">
<?php echo Form::open(null, array('name' => 'users_frontend')); ?>
<?php echo Form::hidden('csrf', Security::token()); ?>
<?php echo Form::checkbox('users_frontend_registration', null, $users_frontend_registration); ?> <?php echo __('Allow user registration') ?>
<?php echo Form::input('users_frontend_submit', 'users_frontend_submit', array('style' => 'display:none;')); ?>
<?php echo Form::close();?>
</div>
<br /><br />
<!-- Users_list -->
<table class="table table-bordered">
<thead>
<tr>
<td><?php echo __('Username', 'users'); ?></td>
<td><?php echo __('Email', 'users'); ?></td>
<td><?php echo __('Registered', 'users'); ?></td>
<td><?php echo __('Role', 'users'); ?></td>
<td width="30%"><?php echo __('Actions', 'users'); ?></td>
</tr>
</thead>
<tbody>
<?php foreach ($users_list as $user) { ?>
<tr>
<td>
<?php echo Html::toText($user['login']); ?>
</td>
<td>
<?php echo Html::toText($user['email']); ?>
</td>
<td>
<?php echo Date::format($user['date_registered']); ?>
</td>
<td>
<?php echo $roles["{$user['role']}"]; ?>
</td>
<td>
<?php echo Html::anchor(__('Edit', 'users'), 'index.php?id=users&action=edit&user_id='.$user['id'], array('class' => 'btn btn-actions')); ?>
<?php echo Html::anchor(__('Delete', 'users'),
'index.php?id=users&action=delete&user_id='.$user['id'],
array('class' => 'btn btn-actions', 'onclick' => "return confirmDelete('".__('Delete user: :user', 'users', array(':user' => Html::toText($user['login'])))."')"));
?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<!-- /Users_list -->

View File

@@ -0,0 +1,26 @@
<h3><?php echo __('Edit profile', 'users') ?></h3>
<hr>
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php if (Notification::get('error')) Alert::success(Notification::get('error')); ?>
<form method="post">
<?php
echo (
Form::hidden('csrf', Security::token()).
Form::hidden('user_id', $user['id'])
);
?>
<table>
<?php if (isset($_SESSION['user_role']) && in_array($_SESSION['user_role'], array('admin'))) { ?>
<label><?php echo __('Username', 'users'); ?></label><input type="text" value="<?php echo $user['login']; ?>" name="login">
<?php } else { echo Form::hidden('login', $user['login']); } ?>
<label><?php echo __('Firstname', 'users'); ?></label><input type="text" value="<?php echo $user['firstname']; ?>" name="firstname">
<label><?php echo __('Lastname', 'users'); ?></label><input type="text" value="<?php echo $user['lastname']; ?>" name="lastname">
<label><?php echo __('Email', 'users'); ?></label><input type="text" value="<?php echo $user['email']; ?>" name="email">
<label><?php echo __('Twitter', 'users'); ?></label><input type="text" value="<?php echo $user['twitter']; ?>" name="twitter">
<label><?php echo __('Skype', 'users'); ?></label><input type="text" value="<?php echo $user['skype']; ?>" name="skype">
<label><?php echo __('New Password', 'users'); ?></label><input type="text" name="new_password">
<br/><input type="submit" class="btn" value="<?php echo __('Save', 'users'); ?>" name="edit_profile">
</table>
</form>

View File

@@ -0,0 +1,14 @@
<h3><?php echo __('Users', 'users'); ?></h3>
<hr>
<table>
<tr>
<td></td>
</tr>
<?php foreach ($users as $user) { ?>
<tr>
<td>
<a href="<?php echo Site::url(); ?>users/<?php echo $user['id']; ?>"><?php echo $user['login']; ?></a>
</td>
</tr>
<?php } ?>
</table>

View File

@@ -0,0 +1,10 @@
<h3><?php echo __('Login', 'users'); ?></h3>
<hr>
<?php if (Notification::get('error')) Alert::error(Notification::get('error')); ?>
<form method="post">
<?php echo Form::hidden('csrf', Security::token()); ?>
<label><?php echo __('Username', 'users'); ?></label><input name="username" type="text" />
<label><?php echo __('Password', 'users'); ?></label><input name="password" type="password" />
<br /><input name="login_submit" class="btn" type="submit" value="<?php echo __('Enter', 'users'); ?>" /> <a class="small-grey-text reset-password-btn" href="<?php echo Option::get('siteurl').'users/password-reset'; ?>"><?php echo __('Forgot your password?', 'users');?></a></td></tr>
</form>

View File

@@ -0,0 +1,25 @@
<h3><?php echo __('Reset Password', 'users') ?></h3>
<hr>
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php if (Notification::get('error')) Alert::success(Notification::get('error')); ?>
<form method="post">
<?php
echo (Form::hidden('csrf', Security::token()));
?>
<label><?php echo __('Username', 'users'); ?></label><input type="text" value="<?php echo $user_login; ?>" name="login">
<?php
if (isset($errors['users_user_doesnt_exists'])) echo Html::nbsp(3).'<span class="error">'.$errors['users_user_doesnt_exists'].'</span>';
if (isset($errors['users_empty_field'])) echo Html::nbsp(3).'<span class="error">'.$errors['users_empty_field'].'</span>';
?>
<?php if (Option::get('captcha_installed') == 'true') { ?>
<label><?php echo __('Captcha'); ?><label>
<input type="text" name="answer"><?php if (isset($errors['users_captcha_wrong'])) echo Html::nbsp(3).'<span class="error">'.$errors['users_captcha_wrong'].'</span>'; ?>
<?php CryptCaptcha::draw(); ?>
<?php } ?>
<br /><input type="submit" class="btn" value="<?php echo __('Send New Password', 'users'); ?>" name="reset_password_submit">
</form>

View File

@@ -0,0 +1,19 @@
<h3><?php echo __('Profile', 'users'); ?></h3>
<hr>
<?php if ($user) { ?>
<table>
<tr><td><?php echo __('Username', 'users'); ?></td><td><?php echo $user['login']; ?></td></tr>
<tr><td><?php echo __('Firstname', 'users'); ?></td><td><?php echo Html::toText($user['firstname']); ?></td></tr>
<tr><td><?php echo __('Lastname', 'users'); ?></td><td><?php echo Html::toText($user['lastname']); ?></td></tr>
<tr><td><?php echo __('Email', 'users'); ?></td><td><?php echo Html::toText($user['email']); ?></td></tr>
<tr><td><?php echo __('Registered', 'users'); ?></td><td><?php echo Date::format($user['date_registered']); ?></td></tr>
<tr><td><?php echo __('Skype', 'users'); ?></td><td><?php echo Html::toText($user['skype']); ?></td></tr>
<tr><td><?php echo __('Twitter', 'users'); ?></td><td><?php echo Html::toText($user['twitter']); ?></td></tr>
</table>
<br />
<?php if (Users::isLoged()) { ?>
<a href="<?php echo Site::url(); ?>users/<?php echo $user['id']; ?>/edit"><?php echo __('Edit profile', 'users'); ?></a> /
<?php if(in_array(Session::get('user_role'), array('admin', 'editor'))) { ?> <a href="<?php echo Site::url(); ?>admin"><?php echo __('Administration', 'system'); ?></a> / <?php } ?>
<a href="<?php echo Site::url(); ?>users/logout"><?php echo __('Logout', 'users'); ?></a>
<?php } ?>
<?php } else { echo __('This users doesnt exists', 'users'); } ?>

View File

@@ -0,0 +1,30 @@
<h3><?php echo __('Registration', 'users'); ?></h3>
<hr>
<form method="post">
<?php
echo (Form::hidden('csrf', Security::token()));
?>
<label><?php echo __('Username', 'users'); ?></label><input type="text" value="<?php echo $user_login; ?>" name="login">
<?php
if (isset($errors['users_this_user_alredy_exists'])) echo Html::nbsp(3).'<span class="error">'.$errors['users_this_user_alredy_exists'].'</span>';
if (isset($errors['users_empty_login'])) echo Html::nbsp(3).'<span class="error">'.$errors['users_empty_login'].'</span>';
?>
<label><?php echo __('Password', 'users'); ?></label><input type="password" value="<?php echo $user_password; ?>" name="password">
<?php
if (isset($errors['users_empty_password'])) echo Html::nbsp(3).'<span class="error">'.$errors['users_empty_password'].'</span>';
?>
<label><?php echo __('Email', 'users'); ?></label><input type="text" value="<?php echo $user_email; ?>" name="email">
<?php
if (isset($errors['users_this_email_alredy_exists'])) echo Html::nbsp(3).'<span class="error">'.$errors['users_this_email_alredy_exists'].'</span>';
if (isset($errors['users_empty_email'])) echo Html::nbsp(3).'<span class="error">'.$errors['users_empty_email'].'</span>';
if (isset($errors['users_invalid_email'])) echo Html::nbsp(3).'<span class="error">'.$errors['users_invalid_email'].'</span>';
?>
<?php if (Option::get('captcha_installed') == 'true') { ?>
<label><?php echo __('Captcha'); ?><label>
<input type="text" name="answer"><?php if (isset($errors['users_captcha_wrong'])) echo Html::nbsp(3).'<span class="error">'.$errors['users_captcha_wrong'].'</span>'; ?>
<?php CryptCaptcha::draw(); ?>
<?php } ?>
<br /><input type="submit" class="btn" value="<?php echo __('Register', 'users'); ?>" name="register">
</form>

View File

@@ -0,0 +1,13 @@
<div style="float:right">
<?php if (Session::get('user_id')) { ?>
<?php echo __('Welcome', 'users'); ?>,
<a href="<?php echo Site::url(); ?>users/<?php echo Session::get('user_id'); ?>"><?php echo Session::get('user_login'); ?></a> /
<?php if(in_array(Session::get('user_role'), array('admin', 'editor'))) { ?>
<a href="<?php echo Site::url(); ?>admin"><?php echo __('Administration', 'system'); ?></a> /
<?php } ?>
<a href="<?php echo Site::url(); ?>users/logout"><?php echo __('Logout', 'users'); ?></a>
<?php } else { ?>
<a href="<?php echo Site::url(); ?>users/login"><?php echo __('Login', 'users'); ?></a> /
<a href="<?php echo Site::url(); ?>users/registration"><?php echo __('Registration', 'users'); ?></a>
<?php } ?>
</div>

View File

@@ -0,0 +1,49 @@
<?php
/**
* Captcha plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Captcha', 'captcha'),
__('Captcha plugin for Monstra', 'captcha'),
'1.0.0',
'Awilum',
'http://monstra.org/');
// Set crypt captcha path to images
$cryptinstall = Option::get('siteurl').'plugins/captcha/crypt/images/';
// Include Crypt Captcha
include PLUGINS . DS . 'captcha/crypt/cryptographp.fct.php';
/**
* Crypt Captha class
*/
class CryptCaptcha {
/**
* Draw
*/
public static function draw() {
dsp_crypt();
}
/**
* Check
*/
public static function check($answer) {
return chk_crypt($answer);
}
}

View File

@@ -0,0 +1,2 @@
Options -Indexes
Allow from all

Some files were not shown because too many files have changed in this diff Show More