adminerevo/plugins/tinymce.php

78 lines
2.5 KiB
PHP
Raw Normal View History

2011-02-09 16:57:10 +00:00
<?php
2011-02-09 17:39:25 +00:00
/** Edit all fields containing "_html" by HTML editor TinyMCE and display the HTML in select
2015-09-08 16:23:25 +00:00
* @link https://www.adminer.org/plugins/#use
2011-02-18 15:18:14 +00:00
* @uses TinyMCE, http://tinymce.moxiecode.com/
2017-02-27 12:43:33 +00:00
* @author Jakub Vrana, https://www.vrana.cz/
2018-01-14 10:03:54 +00:00
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
2011-02-09 16:57:10 +00:00
*/
class AdminerTinymce {
2011-08-11 15:06:42 +00:00
/** @access protected */
2011-02-09 16:57:10 +00:00
var $path;
2011-02-09 16:57:10 +00:00
/**
* @param string
*/
2015-08-15 15:04:21 +00:00
function __construct($path = "tiny_mce/tiny_mce.js") {
2011-02-09 16:57:10 +00:00
$this->path = $path;
}
2011-05-31 05:55:14 +00:00
function head() {
$lang = "en";
if (function_exists('get_lang')) { // since Adminer 3.2.0
$lang = get_lang();
$lang = ($lang == "zh" ? "zh-cn" : ($lang == "zh-tw" ? "zh" : $lang));
if (!file_exists(dirname($this->path) . "/langs/$lang.js")) {
$lang = "en";
}
}
2018-01-13 15:25:11 +00:00
echo script_src($this->path);
2011-05-31 05:55:14 +00:00
?>
2018-01-13 21:17:00 +00:00
<script<?php echo nonce(); ?>>
2011-05-31 05:55:14 +00:00
tinyMCE.init({
entity_encoding: 'raw',
language: '<?php echo $lang; ?>'
}); // learn how to customize here: https://www.tinymce.com/docs/configure/
2011-05-31 05:55:14 +00:00
</script>
<?php
}
2014-01-11 05:32:07 +00:00
function selectVal(&$val, $link, $field, $original) {
if (preg_match("~_html~", $field["field"]) && $val != '') {
2021-02-08 14:50:02 +00:00
$ellipsis = "<i>…</i>";
$length = strlen($ellipsis);
$shortened = (substr($val, -$length) == $ellipsis);
2011-04-12 15:08:58 +00:00
if ($shortened) {
$val = substr($val, 0, -$length);
2011-04-12 15:08:58 +00:00
}
//! shorten with regard to HTML tags - http://php.vrana.cz/zkraceni-textu-s-xhtml-znackami.php
$val = preg_replace('~<[^>]*$~', '', html_entity_decode($val, ENT_QUOTES)); // remove ending incomplete tag (text can be shortened)
if ($shortened) {
$val .= $ellipsis;
2011-04-12 15:08:58 +00:00
}
if (class_exists('DOMDocument')) { // close all opened tags
$dom = new DOMDocument;
if (@$dom->loadHTML("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head>$val")) { // @ - $val can contain errors
2018-02-20 15:27:40 +00:00
$val = preg_replace('~.*<body[^>]*>(.*)</body>.*~is', '\1', $dom->saveHTML());
2011-04-12 15:08:58 +00:00
}
}
2011-02-09 16:57:10 +00:00
}
}
2011-02-09 16:57:10 +00:00
function editInput($table, $field, $attrs, $value) {
if (preg_match("~text~", $field["type"]) && preg_match("~_html~", $field["field"])) {
2018-01-12 14:27:44 +00:00
return "<textarea$attrs id='fields-" . h($field["field"]) . "' rows='12' cols='50'>" . h($value) . "</textarea>" . script("
2011-06-13 16:02:16 +00:00
tinyMCE.remove(tinyMCE.get('fields-" . js_escape($field["field"]) . "') || { });
tinyMCE.EditorManager.execCommand('mceAddControl', true, 'fields-" . js_escape($field["field"]) . "');
qs('#form').onsubmit = function () {
2011-06-13 16:02:16 +00:00
tinyMCE.each(tinyMCE.editors, function (ed) {
ed.remove();
});
};
2018-01-12 14:27:44 +00:00
");
2011-02-09 16:57:10 +00:00
}
}
2011-02-09 16:57:10 +00:00
}