* added tinymce editor to 'Pages' in admin panel

* enabled code plugin for tinymce which enabled raw html code editing
This commit is contained in:
slawkens 2017-10-23 14:59:43 +02:00
parent 25f8028ae3
commit bf988a7f6e
4 changed files with 57 additions and 70 deletions

View File

@ -34,12 +34,13 @@ if(!empty($action))
if(isset($_REQUEST['title']))
$p_title = $_REQUEST['title'];
$php = isset($_REQUEST['php']);
//if($php)
// $body = $_REQUEST['body'];
//else
if(isset($_REQUEST['body']))
$php = isset($_REQUEST['php']) && $_REQUEST['php'] == 1;
if($php)
$body = $_REQUEST['body'];
else if(isset($_REQUEST['body'])) {
//$body = $_REQUEST['body'];
$body = html_entity_decode(stripslashes($_REQUEST['body']));
}
if(isset($_REQUEST['access']))
$access = $_REQUEST['access'];
@ -134,7 +135,7 @@ class Pages
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));
else
$errors[] = 'Page with this words already exists.';
$errors[] = 'Page with this link already exists.';
}
else
$errors[] = 'Please fill all inputs.';

View File

@ -3,8 +3,8 @@
tinymce.init({
selector : "textarea",
theme : "modern",
plugins: 'print preview fullpage searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount spellchecker imagetools contextmenu colorpicker textpattern help',
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat',
plugins: 'print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount spellchecker imagetools contextmenu colorpicker textpattern help code',
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat code',
image_advtab: true,
relative_urls : false,
remove_script_host : false,

View File

@ -1,54 +1,3 @@
{% set use_tinymce = false %}
<!--
//if($action != 'edit' || !$php)
// $use_tinymce = true;
-->
{% if use_tinymce %}
<script type="text/javascript" src="tools/tiny_mce/jquery.tinymce.js"></script>
<script type="text/javascript">
$(function() {
$('#news-body').tinymce({
script_url : 'tools/tiny_mce/tiny_mce.js',
forced_root_block : false,
theme : "advanced",
plugins: "safari,advimage,emotions,insertdatetime,preview,wordcount",
theme_advanced_buttons3_add : "emotions,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
});
<?php /*if($action != 'edit'): ?>
$("#page-edit-table").hide();
$("#page-button").click(function() {
$("#page-edit-table").toggle();
return false;
});
<?php endif; */ ?>
});
</script>
<!--script type="text/javascript">
tinyMCE.init({
forced_root_block : false,
mode : "textareas",
theme : "advanced",
plugins: "safari,advimage,emotions,insertdatetime,preview,wordcount",
theme_advanced_buttons3_add : "emotions,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
});
</script-->
{% endif %}
<form method="post" action="?p=pages&action={% if action == 'edit' %}edit{% else %}add{% endif %}">
{% if action == 'edit' %}
<input type="hidden" name="id" value="{{ id }}" />
@ -70,17 +19,12 @@
</tr>
<tr>
<td>PHP:</td>
<td><input type="checkbox" id="news-checkbox" name="php" title="Check if page should be executed as PHP" value="1"{% if php %} checked="true"{% endif %}/></td>
<td><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 %}/></td>
</tr>
<tr>
<td>Content:</td>
<td>
<textarea id="news-body" name="body" maxlength="65000" cols="50" rows="5">{{ body|raw }}</textarea>
{% if use_tinymce %}
<br/>
<a href="javascript:;" onmousedown="$('#news-body').tinymce().hide();">[Hide]</a>
<a href="javascript:;" onmousedown="$('#news-body').tinymce().show();">[Show]</a>
{% endif %}
<td id="body-parent">
<textarea id="body" name="body" maxlength="65000" cols="50" rows="5">{{ body|raw }}</textarea>
</td>
<tr/>
<tr>
@ -104,3 +48,45 @@
</tr>
</table>
</form>
<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) {
tinymce.remove('#body');
} else {
if(tinymce.editors.length > 0) {
tinymce.activeEditor.show();
}
else {
init_tinymce();
}
}
});
{% if not php %}
init_tinymce();
{% endif %}
function init_tinymce() {
tinymce.init({
selector : "#body",
theme : "modern",
plugins: 'code print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount spellchecker imagetools contextmenu colorpicker textpattern help',
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat code',
image_advtab: true,
relative_urls : false,
remove_script_host : false,
document_base_url : "{{ constant('BASE_URL') }}"
});
}
function decodeHtml(html) {
var txt = document.createElement("textarea");
txt.innerHTML = html;
return txt.value;
}
});
</script>

View File

@ -3,8 +3,8 @@
tinymce.init({
selector : "textarea",
theme : "modern",
plugins: 'print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount spellchecker imagetools contextmenu colorpicker textpattern help',
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat',
plugins: 'print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount spellchecker imagetools contextmenu colorpicker textpattern help code',
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat code',
image_advtab: true
});
</script>