Add enable_tinymce option to Pages editor

This commit is contained in:
slawkens 2020-02-11 01:02:46 +01:00
parent 1ab32ca3ba
commit f475c671f7
5 changed files with 58 additions and 13 deletions

View File

@ -27,7 +27,7 @@ session_start();
define('MYAAC', true); define('MYAAC', true);
define('MYAAC_VERSION', '0.8-dev'); define('MYAAC_VERSION', '0.8-dev');
define('DATABASE_VERSION', 28); define('DATABASE_VERSION', 29);
define('TABLE_PREFIX', 'myaac_'); define('TABLE_PREFIX', 'myaac_');
define('START_TIME', microtime(true)); define('START_TIME', microtime(true));
define('MYAAC_OS', stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : (strtoupper(PHP_OS) === 'DARWIN' ? 'MAC' : 'LINUX')); define('MYAAC_OS', stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : (strtoupper(PHP_OS) === 'DARWIN' ? 'MAC' : 'LINUX'));

View File

@ -285,6 +285,7 @@ CREATE TABLE `myaac_pages`
`date` INT(11) NOT NULL DEFAULT 0, `date` INT(11) NOT NULL DEFAULT 0,
`player_id` INT(11) NOT NULL DEFAULT 0, `player_id` INT(11) NOT NULL DEFAULT 0,
`php` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '0 - plain html, 1 - php', `php` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '0 - plain html, 1 - php',
`enable_tinymce` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '1 - enabled, 0 - disabled',
`access` TINYINT(2) NOT NULL DEFAULT 0, `access` TINYINT(2) NOT NULL DEFAULT 0,
`hidden` TINYINT(1) NOT NULL DEFAULT 0, `hidden` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),

5
system/migrations/29.php Normal file
View File

@ -0,0 +1,5 @@
<?php
if(!$db->hasColumn(TABLE_PREFIX . 'pages', 'enable_tinymce')) {
$db->exec('ALTER TABLE `' . TABLE_PREFIX . 'pages` ADD `enable_tinymce` TINYINT(1) NOT NULL DEFAULT 1 COMMENT \'1 - enabled, 0 - disabled\' AFTER `php`;');
}

View File

@ -21,6 +21,7 @@ $name = $p_title = '';
$groups = new OTS_Groups_List(); $groups = new OTS_Groups_List();
$php = false; $php = false;
$enable_tinymce = true;
$access = 0; $access = 0;
if (!empty($action)) { if (!empty($action)) {
@ -34,6 +35,7 @@ if (!empty($action)) {
$p_title = $_REQUEST['title']; $p_title = $_REQUEST['title'];
$php = isset($_REQUEST['php']) && $_REQUEST['php'] == 1; $php = isset($_REQUEST['php']) && $_REQUEST['php'] == 1;
$enable_tinymce = isset($_REQUEST['enable_tinymce']) && $_REQUEST['enable_tinymce'] == 1;
if ($php) if ($php)
$body = $_REQUEST['body']; $body = $_REQUEST['body'];
else if (isset($_REQUEST['body'])) { else if (isset($_REQUEST['body'])) {
@ -48,10 +50,11 @@ if (!empty($action)) {
$player_id = 1; $player_id = 1;
if ($action == 'add') { if ($action == 'add') {
if (Pages::add($name, $p_title, $body, $player_id, $php, $access, $errors)) { if (Pages::add($name, $p_title, $body, $player_id, $php, $enable_tinymce, $access, $errors)) {
$name = $p_title = $body = ''; $name = $p_title = $body = '';
$player_id = $access = 0; $player_id = $access = 0;
$php = false; $php = false;
$enable_tinymce = true;
} }
} else if ($action == 'delete') { } else if ($action == 'delete') {
if (Pages::delete($id, $errors)) if (Pages::delete($id, $errors))
@ -63,13 +66,15 @@ if (!empty($action)) {
$p_title = $_page['title']; $p_title = $_page['title'];
$body = $_page['body']; $body = $_page['body'];
$php = $_page['php'] == '1'; $php = $_page['php'] == '1';
$enable_tinymce = $_page['enable_tinymce'] == '1';
$access = $_page['access']; $access = $_page['access'];
} else { } else {
Pages::update($id, $name, $p_title, $body, $player_id, $php, $access); Pages::update($id, $name, $p_title, $body, $player_id, $php, $enable_tinymce, $access);
$action = $name = $p_title = $body = ''; $action = $name = $p_title = $body = '';
$player_id = 1; $player_id = 1;
$access = 0; $access = 0;
$php = false; $php = false;
$enable_tinymce = true;
} }
} else if ($action == 'hide') { } else if ($action == 'hide') {
Pages::toggleHidden($id, $errors); Pages::toggleHidden($id, $errors);
@ -99,6 +104,7 @@ $twig->display('admin.pages.form.html.twig', array(
'name' => $name, 'name' => $name,
'title' => $p_title, 'title' => $p_title,
'php' => $php, 'php' => $php,
'enable_tinymce' => $enable_tinymce,
'body' => isset($body) ? htmlentities($body, ENT_COMPAT, 'UTF-8') : '', 'body' => isset($body) ? htmlentities($body, ENT_COMPAT, 'UTF-8') : '',
'groups' => $groups->getGroups(), 'groups' => $groups->getGroups(),
'access' => $access 'access' => $access
@ -120,13 +126,23 @@ class Pages
return false; return false;
} }
static public function add($name, $title, $body, $player_id, $php, $access, &$errors) static public function add($name, $title, $body, $player_id, $php, $enable_tinymce, $access, &$errors)
{ {
global $db; global $db;
if (isset($name[0]) && isset($title[0]) && isset($body[0]) && $player_id != 0) { if (isset($name[0]) && isset($title[0]) && isset($body[0]) && $player_id != 0) {
$query = $db->select(TABLE_PREFIX . 'pages', array('name' => $name)); $query = $db->select(TABLE_PREFIX . 'pages', array('name' => $name));
if ($query === false) if ($query === false)
$db->insert(TABLE_PREFIX . 'pages', array('name' => $name, 'title' => $title, 'body' => $body, 'player_id' => $player_id, 'php' => $php ? '1' : '0', 'access' => $access)); $db->insert(TABLE_PREFIX . 'pages',
array(
'name' => $name,
'title' => $title,
'body' => $body,
'player_id' => $player_id,
'php' => $php ? '1' : '0',
'enable_tinymce' => $enable_tinymce ? '1' : '0',
'access' => $access
)
);
else else
$errors[] = 'Page with this link already exists.'; $errors[] = 'Page with this link already exists.';
} else } else
@ -135,10 +151,20 @@ class Pages
return !count($errors); return !count($errors);
} }
static public function update($id, $name, $title, $body, $player_id, $php, $access) static public function update($id, $name, $title, $body, $player_id, $php, $enable_tinymce, $access)
{ {
global $db; global $db;
$db->update(TABLE_PREFIX . 'pages', array('name' => $name, 'title' => $title, 'body' => $body, 'player_id' => $player_id, 'php' => $php ? '1' : '0', 'access' => $access), array('id' => $id)); $db->update(TABLE_PREFIX . 'pages',
array(
'name' => $name,
'title' => $title,
'body' => $body,
'player_id' => $player_id,
'php' => $php ? '1' : '0',
'enable_tinymce' => $enable_tinymce ? '1' : '0',
'access' => $access
),
array('id' => $id));
} }
static public function delete($id, &$errors) static public function delete($id, &$errors)

View File

@ -33,12 +33,25 @@
<div class="col-sm-10"> <div class="col-sm-10">
<input type="checkbox" id="php" name="php" <input type="checkbox" id="php" name="php"
title="Check if page should be executed as PHP" title="Check if page should be executed as PHP"
value="1"{% if php %} checked="true"{% endif %}{% if action == 'edit' %} disabled{% endif %}/> value="1"{% if php %} checked{% endif %}{% if action == 'edit' %} disabled{% endif %}/>
{% if action == 'edit' %} {% if action == 'edit' %}
<input type="hidden" name="php" value="{% if php %}1{% else %}0{% endif %}"/> <input type="hidden" name="php" value="{% if php %}1{% else %}0{% endif %}"/>
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% if not php %}
<div class="form-group">
<label for="enable_tinymce" class="col-sm-2 control-label">Enable TinyMCE</label>
<div class="col-sm-10">
<input type="checkbox" id="enable_tinymce" name="enable_tinymce"
title="Check if you want to use TinyMCE Editor"
value="1"{% if enable_tinymce %} checked{% endif %}{% if action == 'edit' %} disabled{% endif %}/>
{% if action == 'edit' %}
<input type="hidden" name="enable_tinymce" value="{% if enable_tinymce %}1{% else %}0{% endif %}"/>
{% endif %}
</div>
</div>
{% endif %}
<div class="form-group"> <div class="form-group">
<label for="body" class="col-sm-2 control-label">Content</label> <label for="body" class="col-sm-2 control-label">Content</label>
<div class="col-sm-10" id="body-parent"> <div class="col-sm-10" id="body-parent">
@ -72,8 +85,8 @@
<script type="text/javascript" src="{{ constant('BASE_URL') }}tools/tinymce/tinymce.min.js"></script> <script type="text/javascript" src="{{ constant('BASE_URL') }}tools/tinymce/tinymce.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$(function () { $(function () {
$('#php').on('change', function (e) { $('#enable_tinymce').on('change', function (e) {
if (this.checked) { if (!this.checked) {
tinymce.remove('#body'); tinymce.remove('#body');
} else { } else {
if (tinymce.editors.length > 0) { if (tinymce.editors.length > 0) {
@ -85,7 +98,7 @@
} }
}); });
{% if not php %} {% if not php and enable_tinymce %}
init_tinymce(); init_tinymce();
{% endif %} {% endif %}