mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-07-09 23:56:26 +02:00
Monstra Library: basic core improvments
This commit is contained in:
@ -8,4 +8,4 @@
|
||||
<plugin_version>1.0.0</plugin_version>
|
||||
<plugin_author>Awilum</plugin_author>
|
||||
<plugin_author_uri>http://monstra.org/</plugin_author_uri>
|
||||
</root>
|
||||
</root>
|
||||
|
@ -1,30 +1,30 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'snippets' => array(
|
||||
'Snippets' => 'Snippets',
|
||||
'Snippets manager' => 'Snippet Manager',
|
||||
'Actions' => 'Aktionen',
|
||||
'Delete' => 'Löschen',
|
||||
'Edit' => 'Bearbeiten',
|
||||
'Name' => 'Name',
|
||||
'Create new snippet' => 'Erstelle neues Snippet',
|
||||
'New snippet' => 'Neues Snippet',
|
||||
'Edit snippet' => 'Bearbeite Snippet',
|
||||
'Save' => 'Save',
|
||||
'Save and exit' => 'Speichern und Schließen',
|
||||
'This field should not be empty' => 'Dieses Feld darf nicht leer sein',
|
||||
'This snippet already exists' => 'Dieses Snippet existiert bereits',
|
||||
'This snippet does not exist' => 'Dieses Snippet existiert nicht',
|
||||
'Delete snippet: :snippet' => 'Lösche Snippet: :snippet',
|
||||
'Snippet content' => 'Snippet Inhalt',
|
||||
'Snippet <i>:name</i> deleted' => 'Snippet <i>:name</i> wurde gelöscht',
|
||||
'Your changes to the snippet <i>:name</i> have been saved.' => 'Deine Änerungen für das Snippet <i>:name</i> wurden gespeichert.',
|
||||
'Delete snippet: :snippet' => 'Lösche Snippet: :snippet',
|
||||
'Required field' => 'Pflichtfeld',
|
||||
'View Embed Code' => 'View Embed Code',
|
||||
'Embed Code' => 'Embed Code',
|
||||
'Shortcode' => 'Shortcode',
|
||||
'PHP Code' => 'PHP Code',
|
||||
)
|
||||
);
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'snippets' => array(
|
||||
'Snippets' => 'Snippets',
|
||||
'Snippets manager' => 'Snippet Manager',
|
||||
'Actions' => 'Aktionen',
|
||||
'Delete' => 'Löschen',
|
||||
'Edit' => 'Bearbeiten',
|
||||
'Name' => 'Name',
|
||||
'Create new snippet' => 'Erstelle neues Snippet',
|
||||
'New snippet' => 'Neues Snippet',
|
||||
'Edit snippet' => 'Bearbeite Snippet',
|
||||
'Save' => 'Save',
|
||||
'Save and exit' => 'Speichern und Schließen',
|
||||
'This field should not be empty' => 'Dieses Feld darf nicht leer sein',
|
||||
'This snippet already exists' => 'Dieses Snippet existiert bereits',
|
||||
'This snippet does not exist' => 'Dieses Snippet existiert nicht',
|
||||
'Delete snippet: :snippet' => 'Lösche Snippet: :snippet',
|
||||
'Snippet content' => 'Snippet Inhalt',
|
||||
'Snippet <i>:name</i> deleted' => 'Snippet <i>:name</i> wurde gelöscht',
|
||||
'Your changes to the snippet <i>:name</i> have been saved.' => 'Deine Änerungen für das Snippet <i>:name</i> wurden gespeichert.',
|
||||
'Delete snippet: :snippet' => 'Lösche Snippet: :snippet',
|
||||
'Required field' => 'Pflichtfeld',
|
||||
'View Embed Code' => 'View Embed Code',
|
||||
'Embed Code' => 'Embed Code',
|
||||
'Shortcode' => 'Shortcode',
|
||||
'PHP Code' => 'PHP Code',
|
||||
)
|
||||
);
|
||||
|
@ -3,16 +3,16 @@
|
||||
return array(
|
||||
'snippets' => array(
|
||||
'Snippets' => 'Snippets',
|
||||
'Snippets manager' => 'Snippets manager',
|
||||
'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',
|
||||
'Edit snippet' => 'Edit snippet',
|
||||
'Save' => 'Save',
|
||||
'Save and exit' => 'Save and exit',
|
||||
'This snippet already exists' => 'This snippet already exists',
|
||||
'This snippet does not exist' => 'This snippet does not exist',
|
||||
'Delete snippet: :snippet' => 'Delete snippet: :snippet',
|
||||
@ -22,8 +22,8 @@
|
||||
'Delete snippet: :snippet' => 'Delete snippet: :snippet',
|
||||
'Required field' => 'Required field',
|
||||
'View Embed Code' => 'View Embed Code',
|
||||
'Embed Code' => 'Embed Code',
|
||||
'Embed Code' => 'Embed Code',
|
||||
'Shortcode' => 'Shortcode',
|
||||
'PHP Code' => 'PHP Code',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@ -3,16 +3,16 @@
|
||||
return array(
|
||||
'snippets' => array(
|
||||
'Snippets' => 'Snippet',
|
||||
'Snippets manager' => 'Gestione snippet',
|
||||
'Snippets manager' => 'Gestione snippet',
|
||||
'Actions' => 'Azioni',
|
||||
'Delete' => 'Elimina',
|
||||
'Edit' => 'Modifica',
|
||||
'New snippet' => 'Nuovo snippet',
|
||||
'Create new snippet' => 'Crea nuovo snippet',
|
||||
'New snippet' => 'Nuovo snippet',
|
||||
'Create new snippet' => 'Crea nuovo snippet',
|
||||
'Name' => 'Nome',
|
||||
'Edit snippet' => 'Modifica snippet',
|
||||
'Save' => 'Salva',
|
||||
'Save and exit' => 'Salva ed esci',
|
||||
'Save' => 'Salva',
|
||||
'Save and exit' => 'Salva ed esci',
|
||||
'This snippet already exists' => 'Tale snippet già esistente',
|
||||
'This snippet does not exist' => 'Tale snippet non esiste',
|
||||
'Delete snippet: :block' => 'Elimina snippet: :snippet',
|
||||
@ -22,8 +22,8 @@
|
||||
'Delete snippet: :snippet' => 'Elimina snippet: :snippet',
|
||||
'Required field' => 'Campo obbligatorio',
|
||||
'View Embed Code' => 'View Embed Code',
|
||||
'Embed Code' => 'Embed Code',
|
||||
'Embed Code' => 'Embed Code',
|
||||
'Shortcode' => 'Shortcode',
|
||||
'PHP Code' => 'PHP Code',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@ -3,16 +3,16 @@
|
||||
return array(
|
||||
'snippets' => array(
|
||||
'Snippets' => 'Fragmentai',
|
||||
'Snippets manager' => 'Fragmentų tvarkyklė',
|
||||
'Snippets manager' => 'Fragmentų tvarkyklė',
|
||||
'Actions' => 'Veiksmai',
|
||||
'Delete' => 'Ištrinti',
|
||||
'Edit' => 'Redaguoti',
|
||||
'Name' => 'Pavadinimas',
|
||||
'Create new snippet' => 'Kurti naują fragmentą',
|
||||
'New snippet' => 'Naujas fragmentas',
|
||||
'Edit snippet' => 'Redaguoti fragmentą',
|
||||
'Save' => 'Išsaugoti',
|
||||
'Save and exit' => 'Išsaugoti ir išeiti',
|
||||
'Edit snippet' => 'Redaguoti fragmentą',
|
||||
'Save' => 'Išsaugoti',
|
||||
'Save and exit' => 'Išsaugoti ir išeiti',
|
||||
'Required field' => 'Privalomas laukas',
|
||||
'This snippet already exists' => 'Toks fragmentas jau yra',
|
||||
'This snippet does not exist' => 'Tokio fragmento nėra',
|
||||
@ -21,8 +21,8 @@
|
||||
'Snippet <i>:name</i> deleted' => 'Fragmentas <i>:name</i> ištrintas',
|
||||
'Your changes to the snippet <i>:name</i> have been saved.' => 'Fragmento <i>:name</i> pakeitimai išsaugoti.',
|
||||
'View Embed Code' => 'View Embed Code',
|
||||
'Embed Code' => 'Embed Code',
|
||||
'Embed Code' => 'Embed Code',
|
||||
'Shortcode' => 'Shortcode',
|
||||
'PHP Code' => 'PHP Code',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@ -23,8 +23,8 @@
|
||||
'Delete snippet: :snippet' => 'Deletar o código: :snippet',
|
||||
'Required field' => 'Campo requerido',
|
||||
'View Embed Code' => 'View Embed Code',
|
||||
'Embed Code' => 'Embed Code',
|
||||
'Embed Code' => 'Embed Code',
|
||||
'Shortcode' => 'Shortcode',
|
||||
'PHP Code' => 'PHP Code',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@ -3,16 +3,16 @@
|
||||
return array(
|
||||
'snippets' => array(
|
||||
'Snippets' => 'Сниппеты',
|
||||
'Snippets manager' => 'Менеджер сниппетов',
|
||||
'Snippets manager' => 'Менеджер сниппетов',
|
||||
'Actions' => 'Действия',
|
||||
'Delete' => 'Удалить',
|
||||
'Edit' => 'Редактировать',
|
||||
'New snippet' => 'Новый сниппет',
|
||||
'Create new snippet' => 'Создать новый сниппет',
|
||||
'New snippet' => 'Новый сниппет',
|
||||
'Create new snippet' => 'Создать новый сниппет',
|
||||
'Name' => 'Название',
|
||||
'Edit snippet' => 'Редактирование сниппета',
|
||||
'Save' => 'Сохранить',
|
||||
'Save and exit' => 'Сохранить и выйти',
|
||||
'Save' => 'Сохранить',
|
||||
'Save and exit' => 'Сохранить и выйти',
|
||||
'This snippet already exists' => 'Такой сниппет уже существует',
|
||||
'This snippet does not exist' => 'Такого сниппета не существует',
|
||||
'Delete snippet: :block' => 'Удалить сниппет: :snippet',
|
||||
@ -22,8 +22,8 @@
|
||||
'Delete snippet: :snippet' => 'Удалить сниппет: :snippet',
|
||||
'Required field' => 'Обязательное поле',
|
||||
'View Embed Code' => 'Код для вставки',
|
||||
'Embed Code' => 'Код для вставки',
|
||||
'Embed Code' => 'Код для вставки',
|
||||
'Shortcode' => 'Шорткод',
|
||||
'PHP Code' => 'PHP код',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@ -3,16 +3,16 @@
|
||||
return array(
|
||||
'snippets' => array(
|
||||
'Snippets' => 'Сніппети',
|
||||
'Snippets manager' => 'Менеджер сніппетів',
|
||||
'Snippets manager' => 'Менеджер сніппетів',
|
||||
'Actions' => 'Дії',
|
||||
'Delete' => 'Видалити',
|
||||
'Edit' => 'Редагувати',
|
||||
'New snippet' => 'Новий сніппет',
|
||||
'Create new snippet' => 'Створити новий сніппет',
|
||||
'New snippet' => 'Новий сніппет',
|
||||
'Create new snippet' => 'Створити новий сніппет',
|
||||
'Name' => 'Назва',
|
||||
'Edit snippet' => 'Редагування сніппета',
|
||||
'Save' => 'Зберегти',
|
||||
'Save and exit' => 'Зберегти та вийти',
|
||||
'Save' => 'Зберегти',
|
||||
'Save and exit' => 'Зберегти та вийти',
|
||||
'This snippet already exists' => 'Такий сніппет вже існує',
|
||||
'This snippet does not exist' => 'Такого сніппета не існує',
|
||||
'Delete snippet: :block' => 'Видалити сніппет: :snippet',
|
||||
@ -22,8 +22,8 @@
|
||||
'Delete snippet: :snippet' => 'Видалити сніппет: :snippet',
|
||||
'Required field' => 'Обов’язкове поле',
|
||||
'View Embed Code' => 'Код для вставки',
|
||||
'Embed Code' => 'Код для вставки',
|
||||
'Embed Code' => 'Код для вставки',
|
||||
'Shortcode' => 'Шорткод',
|
||||
'PHP Code' => 'PHP код',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@ -1,144 +1,144 @@
|
||||
<?php
|
||||
|
||||
// Add plugin navigation link
|
||||
Navigation::add(__('Snippets', 'snippets'), 'extends', 'snippets', 3);
|
||||
// Add plugin navigation link
|
||||
Navigation::add(__('Snippets', 'snippets'), 'extends', 'snippets', 3);
|
||||
|
||||
/**
|
||||
* Snippets Admin Class
|
||||
*/
|
||||
class SnippetsAdmin extends Backend
|
||||
{
|
||||
/**
|
||||
* Snippets Admin Class
|
||||
* Snippets admin function
|
||||
*/
|
||||
class SnippetsAdmin extends Backend {
|
||||
public static function main()
|
||||
{
|
||||
// Init vars
|
||||
$snippets_path = STORAGE . DS . 'snippets' . DS;
|
||||
$snippets_list = array();
|
||||
$errors = array();
|
||||
|
||||
/**
|
||||
* Snippets admin function
|
||||
*/
|
||||
public static function main() {
|
||||
// Check for get actions
|
||||
// -------------------------------------
|
||||
if (Request::get('action')) {
|
||||
|
||||
// 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')) {
|
||||
|
||||
// Switch actions
|
||||
// -------------------------------------
|
||||
switch (Request::get('action')) {
|
||||
// Add snippet
|
||||
// -------------------------------------
|
||||
case "add_snippet":
|
||||
if (Request::post('add_snippets') || Request::post('add_snippets_and_exit')) {
|
||||
|
||||
// Add snippet
|
||||
// -------------------------------------
|
||||
case "add_snippet":
|
||||
if (Request::post('add_snippets') || Request::post('add_snippets_and_exit')) {
|
||||
if (Security::check(Request::post('csrf'))) {
|
||||
|
||||
if (Security::check(Request::post('csrf'))) {
|
||||
|
||||
if (trim(Request::post('name')) == '') $errors['snippets_empty_name'] = __('Required field', 'snippets');
|
||||
if (file_exists($snippets_path.Security::safeName(Request::post('name')).'.snippet.php')) $errors['snippets_exists'] = __('This snippet already exists', 'snippets');
|
||||
if (trim(Request::post('name')) == '') $errors['snippets_empty_name'] = __('Required field', '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 (count($errors) == 0) {
|
||||
|
||||
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')));
|
||||
}
|
||||
// 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;
|
||||
} 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 = '';
|
||||
|
||||
// Edit snippet
|
||||
// -------------------------------------
|
||||
case "edit_snippet":
|
||||
// Save current snippet action
|
||||
if (Request::post('edit_snippets') || Request::post('edit_snippets_and_exit') ) {
|
||||
// Display view
|
||||
View::factory('box/snippets/views/backend/add')
|
||||
->assign('content', $content)
|
||||
->assign('name', $name)
|
||||
->assign('errors', $errors)
|
||||
->display();
|
||||
break;
|
||||
|
||||
if (Security::check(Request::post('csrf'))) {
|
||||
// Edit snippet
|
||||
// -------------------------------------
|
||||
case "edit_snippet":
|
||||
// Save current snippet action
|
||||
if (Request::post('edit_snippets') || Request::post('edit_snippets_and_exit') ) {
|
||||
|
||||
if (trim(Request::post('name')) == '') $errors['snippets_empty_name'] = __('Required field', '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');
|
||||
if (Security::check(Request::post('csrf'))) {
|
||||
|
||||
// Save fields
|
||||
if (Request::post('content')) $content = Request::post('content'); else $content = '';
|
||||
if (count($errors) == 0) {
|
||||
if (trim(Request::post('name')) == '') $errors['snippets_empty_name'] = __('Required field', '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');
|
||||
|
||||
$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;
|
||||
}
|
||||
// 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'));
|
||||
// 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'))));
|
||||
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":
|
||||
|
||||
if (Security::check(Request::get('token'))) {
|
||||
|
||||
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');
|
||||
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');
|
||||
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Display view
|
||||
View::factory('box/snippets/views/backend/edit')
|
||||
->assign('content', $content)
|
||||
->assign('name', $name)
|
||||
->assign('errors', $errors)
|
||||
->display();
|
||||
break;
|
||||
case "delete_snippet":
|
||||
|
||||
// Get snippets
|
||||
$snippets_list = File::scan($snippets_path, '.snippet.php');
|
||||
if (Security::check(Request::get('token'))) {
|
||||
|
||||
// Display view
|
||||
View::factory('box/snippets/views/backend/index')
|
||||
->assign('snippets_list', $snippets_list)
|
||||
->display();
|
||||
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');
|
||||
|
||||
} else { die('csrf detected!'); }
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,104 +1,101 @@
|
||||
<?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 Plugin Javascript
|
||||
Javascript::add('plugins/box/snippets/js/snippets.js', 'backend');
|
||||
|
||||
// Add shortcode {snippet}
|
||||
Shortcode::add('snippet', 'Snippet::_content');
|
||||
|
||||
/**
|
||||
* Snippet class
|
||||
*/
|
||||
class Snippet
|
||||
{
|
||||
/**
|
||||
* Snippets plugin
|
||||
* Get snippet
|
||||
*
|
||||
* @package Monstra
|
||||
* @subpackage Plugins
|
||||
* @author Romanenko Sergey / Awilum
|
||||
* @copyright 2012 Romanenko Sergey / Awilum
|
||||
* @version 1.0.0
|
||||
* <code>
|
||||
* echo Snippet::get('snippetname');
|
||||
* echo Snippet::get('snippetname', array('message' => 'Hello World'));
|
||||
* </code>
|
||||
*
|
||||
* @param string $name Snippet file name
|
||||
* @param string $vars Vars
|
||||
* @return string
|
||||
*/
|
||||
public static function get($name, $vars = array())
|
||||
{
|
||||
$vars['get'] = $name;
|
||||
|
||||
|
||||
// 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');
|
||||
|
||||
return Snippet::_content($vars);
|
||||
}
|
||||
|
||||
// Add Plugin Javascript
|
||||
Javascript::add('plugins/box/snippets/js/snippets.js', 'backend');
|
||||
|
||||
// Add shortcode {snippet}
|
||||
Shortcode::add('snippet', 'Snippet::_content');
|
||||
|
||||
|
||||
/**
|
||||
* Snippet class
|
||||
* Returns snippet content for shortcode {snippet get="snippetname"}
|
||||
*
|
||||
* <code>
|
||||
* {snippet get="snippetname"}
|
||||
* {snippet get="snippetname" message="Hello World"}
|
||||
* </code>
|
||||
*
|
||||
* @param array $attributes Array of attributes
|
||||
* @return string
|
||||
*/
|
||||
class Snippet {
|
||||
public static function _content($attributes)
|
||||
{
|
||||
// Extracst attributes
|
||||
extract($attributes);
|
||||
|
||||
// Get snippet name
|
||||
$name = (isset($get)) ? (string) $get : '';
|
||||
|
||||
/**
|
||||
* Get snippet
|
||||
*
|
||||
* <code>
|
||||
* echo Snippet::get('snippetname');
|
||||
* echo Snippet::get('snippetname', array('message' => 'Hello World'));
|
||||
* </code>
|
||||
*
|
||||
* @param string $name Snippet file name
|
||||
* @param string $vars Vars
|
||||
* @return string
|
||||
*/
|
||||
public static function get($name, $vars = array()) {
|
||||
$vars['get'] = $name;
|
||||
return Snippet::_content($vars);
|
||||
}
|
||||
// Get snippet path
|
||||
$snippet_path = STORAGE . DS . 'snippets' . DS . $name . '.snippet.php';
|
||||
|
||||
// Get snippet content
|
||||
if (File::exists($snippet_path)) {
|
||||
|
||||
/**
|
||||
* Returns snippet content for shortcode {snippet get="snippetname"}
|
||||
*
|
||||
* <code>
|
||||
* {snippet get="snippetname"}
|
||||
* {snippet get="snippetname" message="Hello World"}
|
||||
* </code>
|
||||
*
|
||||
* @param array $attributes Array of attributes
|
||||
* @return string
|
||||
*/
|
||||
public static function _content($attributes) {
|
||||
// Turn on output buffering
|
||||
ob_start();
|
||||
|
||||
// Extracst attributes
|
||||
extract($attributes);
|
||||
// Include view file
|
||||
include $snippet_path;
|
||||
|
||||
// Get snippet name
|
||||
$name = (isset($get)) ? (string)$get : '';
|
||||
|
||||
// Get snippet path
|
||||
$snippet_path = STORAGE . DS . 'snippets' . DS . $name . '.snippet.php';
|
||||
// Output...
|
||||
return ob_get_clean();
|
||||
|
||||
// Get snippet content
|
||||
if (File::exists($snippet_path)) {
|
||||
|
||||
// Turn on output buffering
|
||||
ob_start();
|
||||
|
||||
// Include view file
|
||||
include $snippet_path;
|
||||
|
||||
// Output...
|
||||
return ob_get_clean();
|
||||
|
||||
} else {
|
||||
if (Session::exists('admin') && Session::get('admin') == true) {
|
||||
return __('<b>Snippet <u>:name</u> is not found!</b>', 'snippets', array(':name' => $name));
|
||||
}
|
||||
} else {
|
||||
if (Session::exists('admin') && Session::get('admin') == true) {
|
||||
return __('<b>Snippet <u>:name</u> is not found!</b>', 'snippets', array(':name' => $name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,12 +5,10 @@
|
||||
|
||||
<?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">
|
||||
|
@ -4,7 +4,7 @@
|
||||
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
|
||||
|
||||
<?php
|
||||
if ($content !== null) {
|
||||
if ($content !== null) {
|
||||
|
||||
if (isset($errors['snippets_empty_name']) or isset($errors['snippets_exists'])) $error_class = 'error'; else $error_class = '';
|
||||
|
||||
@ -16,9 +16,8 @@
|
||||
|
||||
?>
|
||||
|
||||
|
||||
<?php echo (Form::label('name', __('Name', 'snippets'))); ?>
|
||||
|
||||
|
||||
<div class="input-append">
|
||||
<?php echo (Form::input('name', $name, array('class' => (isset($errors['snippets_empty_name']) || isset($errors['snippets_exists'])) ? 'input-xxlarge error-field' : 'input-xxlarge'))); ?><span class="add-on">.snippet.php</span>
|
||||
</div>
|
||||
@ -39,8 +38,8 @@
|
||||
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>';
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
@ -4,9 +4,9 @@
|
||||
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
|
||||
|
||||
<?php
|
||||
echo (
|
||||
echo (
|
||||
Html::anchor(__('Create New Snippet', 'snippets'), 'index.php?id=snippets&action=add_snippet', array('title' => __('Create New Snippet', 'snippets'), 'class' => 'btn btn-small')). Html::nbsp(3)
|
||||
);
|
||||
);
|
||||
?>
|
||||
|
||||
<br /><br />
|
||||
@ -22,7 +22,7 @@
|
||||
<tbody>
|
||||
<?php if (count($snippets_list) != 0) foreach ($snippets_list as $snippet) { ?>
|
||||
<tr>
|
||||
<td><?php echo basename($snippet, '.snippet.php'); ?></td>
|
||||
<td><?php echo basename($snippet, '.snippet.php'); ?></td>
|
||||
<td>
|
||||
<div class="pull-right">
|
||||
<div class="btn-toolbar">
|
||||
@ -31,7 +31,7 @@
|
||||
<a class="btn dropdown-toggle btn-actions btn-small" data-toggle="dropdown" href="#" style="font-family:arial;"><span class="caret"></span></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><?php echo Html::anchor(__('View Embed Code', 'snippets'), 'javascript:;', array('title' => __('View Embed Code', 'snippets'), 'onclick' => '$.monstra.snippets.showEmbedCodes("'.basename($snippet, '.snippet.php').'");')); ?></li>
|
||||
</ul>
|
||||
</ul>
|
||||
<?php echo Html::anchor(__('Delete', 'snippets'),
|
||||
'index.php?id=snippets&action=delete_snippet&filename='.basename($snippet, '.snippet.php').'&token='.Security::token(),
|
||||
array('class' => 'btn btn-actions btn-small btn-actions-default', 'onclick' => "return confirmDelete('".__('Delete snippet: :snippet', 'snippets', array(':snippet' => basename($snippet, '.snippet.php')))."')"));
|
||||
@ -60,4 +60,4 @@
|
||||
<code id="phpcode"></code>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user