upgrade
This commit is contained in:
55
plugin/dictionary/DictionaryPlugin.php
Normal file
55
plugin/dictionary/DictionaryPlugin.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Class DictionaryPlugin.
|
||||
*/
|
||||
class DictionaryPlugin extends Plugin
|
||||
{
|
||||
/**
|
||||
* DictionaryPlugin constructor.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'1.0',
|
||||
'Julio Montoya',
|
||||
[
|
||||
'enable_plugin_dictionary' => 'boolean',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DictionaryPlugin|null
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
static $result = null;
|
||||
|
||||
return $result ? $result : $result = new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Installation process.
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
$sql = "CREATE TABLE IF NOT EXISTS plugin_dictionary (
|
||||
id INT NOT NULL AUTO_INCREMENT,
|
||||
term VARCHAR(255) NOT NULL,
|
||||
definition LONGTEXT NOT NULL,
|
||||
PRIMARY KEY (id));
|
||||
";
|
||||
Database::query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall process.
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
$sql = "DROP TABLE IF EXISTS plugin_dictionary";
|
||||
Database::query($sql);
|
||||
}
|
||||
}
|
||||
2
plugin/dictionary/index.php
Normal file
2
plugin/dictionary/index.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
7
plugin/dictionary/install.php
Normal file
7
plugin/dictionary/install.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
if (!api_is_platform_admin()) {
|
||||
exit('You must have admin permissions to install plugins');
|
||||
}
|
||||
DictionaryPlugin::create()->install();
|
||||
6
plugin/dictionary/lang/english.php
Normal file
6
plugin/dictionary/lang/english.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$strings['plugin_title'] = "Extensible Dictionary";
|
||||
$strings['plugin_comment'] = "This plugin allows the admins to add terms and definitions to a global dictionary. Only admins have access to it (through /plugin/dictionary/terms.php) as it is mainly useful to extend upon through other plugins, at this point in time.";
|
||||
$strings['enable_plugin_dictionary'] = "Enable plugin";
|
||||
$strings['Term'] = "Term";
|
||||
$strings['Definition'] = "Definition";
|
||||
4
plugin/dictionary/plugin.php
Normal file
4
plugin/dictionary/plugin.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
$plugin_info = DictionaryPlugin::create()->get_info();
|
||||
82
plugin/dictionary/terms.php
Normal file
82
plugin/dictionary/terms.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../../main/inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$plugin = DictionaryPlugin::create();
|
||||
|
||||
$table = 'plugin_dictionary';
|
||||
$sql = "SELECT * FROM $table ORDER BY TERM";
|
||||
$result = Database::query($sql);
|
||||
$terms = Database::store_result($result, 'ASSOC');
|
||||
|
||||
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : 'add';
|
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
|
||||
$term = null;
|
||||
if (!empty($id)) {
|
||||
$sql = "SELECT * FROM $table WHERE id = $id";
|
||||
$result = Database::query($sql);
|
||||
$term = Database::fetch_array($result, 'ASSOC');
|
||||
if (empty($term)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
}
|
||||
|
||||
$form = new FormValidator('dictionary', 'post', api_get_self().'?action='.$action.'&id='.$id);
|
||||
$form->addText('term', $plugin->get_lang('Term'), true);
|
||||
$form->addTextarea('definition', $plugin->get_lang('Definition'), [], true);
|
||||
//$form->addHtmlEditor('definition', get_lang('Definition'), true);
|
||||
$form->addButtonSave(get_lang('Save'));
|
||||
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
$params = [
|
||||
'term' => $values['term'],
|
||||
'definition' => $values['definition'],
|
||||
];
|
||||
$result = Database::insert($table, $params);
|
||||
if ($result) {
|
||||
Display::addFlash(Display::return_message(get_lang('Added')));
|
||||
}
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
$form->setDefaults($term);
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
$params = [
|
||||
'term' => $values['term'],
|
||||
'definition' => $values['definition'],
|
||||
];
|
||||
Database::update($table, $params, ['id = ?' => $id]);
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if (!empty($term)) {
|
||||
Database::delete($table, ['id = ?' => $id]);
|
||||
Display::addFlash(Display::return_message(get_lang('Deleted')));
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$tpl = new Template($plugin->get_lang('plugin_title'));
|
||||
$tpl->assign('terms', $terms);
|
||||
$tpl->assign('form', $form->returnForm());
|
||||
$content = $tpl->fetch('/'.$plugin->get_name().'/view/terms.html.twig');
|
||||
// Assign into content
|
||||
$tpl->assign('content', $content);
|
||||
// Display
|
||||
$tpl->display_one_col_template();
|
||||
34
plugin/dictionary/view/terms.html.twig
Normal file
34
plugin/dictionary/view/terms.html.twig
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
{{ form }}
|
||||
|
||||
<table class="table table-hover table-striped data_table">
|
||||
<tr>
|
||||
<th>
|
||||
{{ 'Term' | get_plugin_lang('DictionaryPlugin') }}
|
||||
</th>
|
||||
<th>
|
||||
{{ 'Definition' | get_plugin_lang('DictionaryPlugin') }}
|
||||
</th>
|
||||
<th>
|
||||
{{ 'Actions' | get_lang }}
|
||||
</th>
|
||||
</tr>
|
||||
{% for term in terms %}
|
||||
<tr>
|
||||
<td>
|
||||
{{ term.term }}
|
||||
</td>
|
||||
<td>
|
||||
{{ term.definition }}
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{ _p.web_plugin }}dictionary/terms.php?action=edit&{{ {'id': term.id}|url_encode() }}" class="btn btn-success">
|
||||
<span class="fa fa-edit fa-fw" aria-hidden="true"></span> {{ 'Edit'|get_lang }}
|
||||
</a>
|
||||
<a href="{{ _p.web_plugin }}dictionary/terms.php?action=delete&{{ {'id': term.id}|url_encode() }}" class="btn btn-danger">
|
||||
<span class="fa fa-times fa-fw" aria-hidden="true"></span> {{ 'Delete'|get_lang }}
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
Reference in New Issue
Block a user