mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 09:19:22 +02:00
Add enable_tinymce option to Pages editor
This commit is contained in:
parent
1ab32ca3ba
commit
f475c671f7
@ -27,7 +27,7 @@ session_start();
|
||||
|
||||
define('MYAAC', true);
|
||||
define('MYAAC_VERSION', '0.8-dev');
|
||||
define('DATABASE_VERSION', 28);
|
||||
define('DATABASE_VERSION', 29);
|
||||
define('TABLE_PREFIX', 'myaac_');
|
||||
define('START_TIME', microtime(true));
|
||||
define('MYAAC_OS', stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : (strtoupper(PHP_OS) === 'DARWIN' ? 'MAC' : 'LINUX'));
|
||||
|
@ -285,6 +285,7 @@ CREATE TABLE `myaac_pages`
|
||||
`date` 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',
|
||||
`enable_tinymce` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '1 - enabled, 0 - disabled',
|
||||
`access` TINYINT(2) NOT NULL DEFAULT 0,
|
||||
`hidden` TINYINT(1) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
|
5
system/migrations/29.php
Normal file
5
system/migrations/29.php
Normal 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`;');
|
||||
}
|
@ -21,6 +21,7 @@ $name = $p_title = '';
|
||||
$groups = new OTS_Groups_List();
|
||||
|
||||
$php = false;
|
||||
$enable_tinymce = true;
|
||||
$access = 0;
|
||||
|
||||
if (!empty($action)) {
|
||||
@ -34,6 +35,7 @@ if (!empty($action)) {
|
||||
$p_title = $_REQUEST['title'];
|
||||
|
||||
$php = isset($_REQUEST['php']) && $_REQUEST['php'] == 1;
|
||||
$enable_tinymce = isset($_REQUEST['enable_tinymce']) && $_REQUEST['enable_tinymce'] == 1;
|
||||
if ($php)
|
||||
$body = $_REQUEST['body'];
|
||||
else if (isset($_REQUEST['body'])) {
|
||||
@ -48,10 +50,11 @@ if (!empty($action)) {
|
||||
$player_id = 1;
|
||||
|
||||
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 = '';
|
||||
$player_id = $access = 0;
|
||||
$php = false;
|
||||
$enable_tinymce = true;
|
||||
}
|
||||
} else if ($action == 'delete') {
|
||||
if (Pages::delete($id, $errors))
|
||||
@ -63,13 +66,15 @@ if (!empty($action)) {
|
||||
$p_title = $_page['title'];
|
||||
$body = $_page['body'];
|
||||
$php = $_page['php'] == '1';
|
||||
$enable_tinymce = $_page['enable_tinymce'] == '1';
|
||||
$access = $_page['access'];
|
||||
} 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 = '';
|
||||
$player_id = 1;
|
||||
$access = 0;
|
||||
$php = false;
|
||||
$enable_tinymce = true;
|
||||
}
|
||||
} else if ($action == 'hide') {
|
||||
Pages::toggleHidden($id, $errors);
|
||||
@ -99,6 +104,7 @@ $twig->display('admin.pages.form.html.twig', array(
|
||||
'name' => $name,
|
||||
'title' => $p_title,
|
||||
'php' => $php,
|
||||
'enable_tinymce' => $enable_tinymce,
|
||||
'body' => isset($body) ? htmlentities($body, ENT_COMPAT, 'UTF-8') : '',
|
||||
'groups' => $groups->getGroups(),
|
||||
'access' => $access
|
||||
@ -120,13 +126,23 @@ class Pages
|
||||
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;
|
||||
if (isset($name[0]) && isset($title[0]) && isset($body[0]) && $player_id != 0) {
|
||||
$query = $db->select(TABLE_PREFIX . 'pages', array('name' => $name));
|
||||
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
|
||||
$errors[] = 'Page with this link already exists.';
|
||||
} else
|
||||
@ -135,10 +151,20 @@ class Pages
|
||||
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;
|
||||
$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)
|
||||
@ -171,4 +197,4 @@ class Pages
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
@ -33,12 +33,25 @@
|
||||
<div class="col-sm-10">
|
||||
<input type="checkbox" id="php" name="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' %}
|
||||
<input type="hidden" name="php" value="{% if php %}1{% else %}0{% endif %}"/>
|
||||
{% endif %}
|
||||
</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">
|
||||
<label for="body" class="col-sm-2 control-label">Content</label>
|
||||
<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">
|
||||
$(function () {
|
||||
$('#php').on('change', function (e) {
|
||||
if (this.checked) {
|
||||
$('#enable_tinymce').on('change', function (e) {
|
||||
if (!this.checked) {
|
||||
tinymce.remove('#body');
|
||||
} else {
|
||||
if (tinymce.editors.length > 0) {
|
||||
@ -85,7 +98,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
{% if not php %}
|
||||
{% if not php and enable_tinymce %}
|
||||
init_tinymce();
|
||||
{% endif %}
|
||||
|
||||
@ -108,4 +121,4 @@
|
||||
return txt.value;
|
||||
}
|
||||
});
|
||||
</script> {% endif %}
|
||||
</script> {% endif %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user