adminerevo/plugins/wymeditor.php

67 lines
2.4 KiB
PHP
Raw Normal View History

2011-07-26 20:10:45 +00:00
<?php
/** Edit all fields containing "_html" by HTML editor WYMeditor and display the HTML in select
2015-09-08 16:23:25 +00:00
* @link https://www.adminer.org/plugins/#use
2011-07-26 20:10:45 +00:00
* @uses WYMeditor, http://www.wymeditor.org/
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-07-26 20:10:45 +00:00
*/
class AdminerWymeditor {
2011-08-11 15:06:42 +00:00
/** @access protected */
var $scripts, $options;
2011-07-26 20:10:45 +00:00
/**
* @param array
* @param string in format "skin: 'custom', preInit: function () { }"
*/
2015-08-15 15:04:21 +00:00
function __construct($scripts = array("jquery/jquery.js", "wymeditor/jquery.wymeditor.min.js"), $options = "") {
2011-07-26 20:10:45 +00:00
$this->scripts = $scripts;
$this->options = $options;
}
2011-07-26 20:10:45 +00:00
function head() {
foreach ($this->scripts as $script) {
2018-01-13 15:25:11 +00:00
echo script_src($script);
2011-07-26 20:10:45 +00:00
}
}
2014-01-11 05:32:07 +00:00
function selectVal(&$val, $link, $field, $original) {
2011-07-26 20:10:45 +00:00
// copied from tinymce.php
if (preg_match("~_html~", $field["field"]) && $val != '') {
$ellipsis = "<i>…</i>";
$length = strlen($ellipsis);
$shortened = (substr($val, -$length) == $ellipsis);
2011-07-26 20:10:45 +00:00
if ($shortened) {
$val = substr($val, 0, -$length);
2011-07-26 20:10:45 +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-07-26 20:10:45 +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-07-26 20:10:45 +00:00
}
}
}
}
2011-07-26 20:10:45 +00:00
function editInput($table, $field, $attrs, $value) {
static $lang = "";
if (!$lang && preg_match("~text~", $field["type"]) && preg_match("~_html~", $field["field"])) {
2011-07-26 20:10:45 +00:00
$lang = "en";
if (function_exists('get_lang')) { // since Adminer 3.2.0
$lang = get_lang();
$lang = ($lang == "zh" || $lang == "zh-tw" ? "zh_cn" : $lang);
}
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-09-13 00:24:22 +00:00
jQuery('#fields-" . js_escape($field["field"]) . "').wymeditor({ updateSelector: '#form [type=\"submit\"]', lang: '$lang'" . ($this->options ? ", $this->options" : "") . " });
2018-01-12 14:27:44 +00:00
");
2011-07-26 20:10:45 +00:00
}
}
2011-07-26 20:10:45 +00:00
}