2011-07-26 22:10:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/** Edit all fields containing "_html" by HTML editor WYMeditor and display the HTML in select
|
2015-09-08 09:23:25 -07:00
|
|
|
* @link https://www.adminer.org/plugins/#use
|
2011-07-26 22:10:45 +02:00
|
|
|
* @uses WYMeditor, http://www.wymeditor.org/
|
2017-02-27 13:43:33 +01:00
|
|
|
* @author Jakub Vrana, https://www.vrana.cz/
|
2018-01-14 11:03:54 +01: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-07-26 22:10:45 +02:00
|
|
|
*/
|
|
|
|
|
class AdminerWymeditor {
|
2025-03-11 07:21:13 +01:00
|
|
|
protected $scripts, $options;
|
2013-07-24 16:26:41 -07:00
|
|
|
|
2011-07-26 22:10:45 +02:00
|
|
|
/**
|
|
|
|
|
* @param array
|
|
|
|
|
* @param string in format "skin: 'custom', preInit: function () { }"
|
|
|
|
|
*/
|
2015-08-15 17:04:21 +02:00
|
|
|
function __construct($scripts = array("jquery/jquery.js", "wymeditor/jquery.wymeditor.min.js"), $options = "") {
|
2011-07-26 22:10:45 +02:00
|
|
|
$this->scripts = $scripts;
|
|
|
|
|
$this->options = $options;
|
|
|
|
|
}
|
2013-07-24 16:26:41 -07:00
|
|
|
|
2011-07-26 22:10:45 +02:00
|
|
|
function head() {
|
|
|
|
|
foreach ($this->scripts as $script) {
|
2025-03-05 11:40:56 +01:00
|
|
|
echo Adminer\script_src($script);
|
2011-07-26 22:10:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
2013-07-24 16:26:41 -07:00
|
|
|
|
2014-01-10 21:32:07 -08:00
|
|
|
function selectVal(&$val, $link, $field, $original) {
|
2011-07-26 22:10:45 +02:00
|
|
|
// copied from tinymce.php
|
2018-02-20 16:02:25 +01:00
|
|
|
if (preg_match("~_html~", $field["field"]) && $val != '') {
|
2018-12-18 14:45:37 +01:00
|
|
|
$ellipsis = "<i>…</i>";
|
|
|
|
|
$length = strlen($ellipsis);
|
|
|
|
|
$shortened = (substr($val, -$length) == $ellipsis);
|
2011-07-26 22:10:45 +02:00
|
|
|
if ($shortened) {
|
2018-12-18 14:45:37 +01:00
|
|
|
$val = substr($val, 0, -$length);
|
2011-07-26 22:10:45 +02: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) {
|
2018-12-18 14:45:37 +01:00
|
|
|
$val .= $ellipsis;
|
2011-07-26 22:10:45 +02: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 16:27:40 +01:00
|
|
|
$val = preg_replace('~.*<body[^>]*>(.*)</body>.*~is', '\1', $dom->saveHTML());
|
2011-07-26 22:10:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-24 16:26:41 -07:00
|
|
|
|
2011-07-26 22:10:45 +02:00
|
|
|
function editInput($table, $field, $attrs, $value) {
|
|
|
|
|
static $lang = "";
|
2013-07-24 16:26:41 -07:00
|
|
|
if (!$lang && preg_match("~text~", $field["type"]) && preg_match("~_html~", $field["field"])) {
|
2025-03-05 11:40:56 +01:00
|
|
|
$lang = Adminer\get_lang();
|
2025-03-05 11:28:53 +01:00
|
|
|
$lang = ($lang == "zh" || $lang == "zh-tw" ? "zh_cn" : $lang);
|
2025-03-05 11:40:56 +01:00
|
|
|
return "<textarea$attrs id='fields-" . Adminer\h($field["field"]) . "' rows='12' cols='50'>" . Adminer\h($value) . "</textarea>" . Adminer\script("
|
|
|
|
|
jQuery('#fields-" . Adminer\js_escape($field["field"]) . "').wymeditor({ updateSelector: '#form [type=\"submit\"]', lang: '$lang'" . ($this->options ? ", $this->options" : "") . " });
|
2018-01-12 15:27:44 +01:00
|
|
|
");
|
2011-07-26 22:10:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|