]> git.joonet.de Git - adminer.git/commitdiff
WYMeditor
authorJakub Vrana <jakub@vrana.cz>
Tue, 26 Jul 2011 20:10:45 +0000 (22:10 +0200)
committerJakub Vrana <jakub@vrana.cz>
Tue, 26 Jul 2011 20:10:45 +0000 (22:10 +0200)
.gitmodules
adminer/plugin.php
plugins/wymeditor.php [new file with mode: 0644]

index 127b40b9944fe98ff00d1e81c5860f230cc5fe98..afa3554fdce62dad5a2fef13ce557578ec3513d5 100644 (file)
@@ -13,3 +13,6 @@
 [submodule "jquery-timepicker"]
        path = externals/jquery-timepicker
        url = git://github.com/trentrichardson/jQuery-Timepicker-Addon.git
+[submodule "wymeditor"]
+       path = externals/wymeditor
+       url = git://github.com/wymeditor/wymeditor.git
index 9df8f32a2476da487af597a4da6ec6c7f49274b8..84198adbc671c994fa8bfd65ded17563a9f9a044 100644 (file)
@@ -14,6 +14,7 @@ function adminer_object() {
                new AdminerDumpXml,
                //~ new AdminerEditCalendar("<script type='text/javascript' src='../externals/jquery-ui/jquery-1.4.4.js'></script>\n<script type='text/javascript' src='../externals/jquery-ui/ui/jquery.ui.core.js'></script>\n<script type='text/javascript' src='../externals/jquery-ui/ui/jquery.ui.widget.js'></script>\n<script type='text/javascript' src='../externals/jquery-ui/ui/jquery.ui.datepicker.js'></script>\n<script type='text/javascript' src='../externals/jquery-ui/ui/jquery.ui.mouse.js'></script>\n<script type='text/javascript' src='../externals/jquery-ui/ui/jquery.ui.slider.js'></script>\n<script type='text/javascript' src='../externals/jquery-timepicker/jquery-ui-timepicker-addon.js'></script>\n<link rel='stylesheet' href='../externals/jquery-ui/themes/base/jquery.ui.all.css'>\n<style type='text/css'>\n.ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }\n.ui-timepicker-div dl { text-align: left; }\n.ui-timepicker-div dl dt { height: 25px; }\n.ui-timepicker-div dl dd { margin: -25px 0 10px 65px; }\n.ui-timepicker-div td { font-size: 90%; }\n</style>\n", "../externals/jquery-ui/ui/i18n/jquery.ui.datepicker-%s.js"),
                //~ new AdminerTinymce("../externals/tinymce/jscripts/tiny_mce/tiny_mce_dev.js"),
+               //~ new AdminerWymeditor(array("../externals/wymeditor/src/jquery/jquery.js", "../externals/wymeditor/src/wymeditor/jquery.wymeditor.js", "../externals/wymeditor/src/wymeditor/jquery.wymeditor.explorer.js", "../externals/wymeditor/src/wymeditor/jquery.wymeditor.mozilla.js", "../externals/wymeditor/src/wymeditor/jquery.wymeditor.opera.js", "../externals/wymeditor/src/wymeditor/jquery.wymeditor.safari.js")),
                new AdminerFileUpload(""),
                new AdminerSlugify,
                new AdminerTranslation,
diff --git a/plugins/wymeditor.php b/plugins/wymeditor.php
new file mode 100644 (file)
index 0000000..cb72623
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+
+/** Edit all fields containing "_html" by HTML editor WYMeditor and display the HTML in select
+* @uses WYMeditor, http://www.wymeditor.org/
+* @author Jakub Vrana, http://www.vrana.cz/
+* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
+*/
+class AdminerWymeditor {
+       /** @var array @access protected */
+       var $scripts;
+       
+       /** @var string @access protected */
+       var $options;
+       
+       /**
+       * @param array
+       * @param string in format "skin: 'custom', preInit: function () { }"
+       */
+       function AdminerWymeditor($scripts = array("jquery/jquery.js", "wymeditor/jquery.wymeditor.min.js"), $options = "") {
+               $this->scripts = $scripts;
+               $this->options = $options;
+       }
+       
+       function head() {
+               foreach ($this->scripts as $script) {
+                       echo "<script type='text/javascript' src='" . h($script) . "'></script>\n";
+               }
+       }
+       
+       function selectVal(&$val, $link, $field) {
+               // copied from tinymce.php
+               if (ereg("_html", $field["field"]) && $val != '&nbsp;') {
+                       $shortened = (substr($val, -10) == "<i>...</i>");
+                       if ($shortened) {
+                               $val = substr($val, 0, -10);
+                       }
+                       //! 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 .= "<i>...</i>";
+                       }
+                       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
+                                       $val = preg_replace('~.*<body[^>]*>(.*)</body>.*~is', '\\1', $dom->saveHTML());
+                               }
+                       }
+               }
+       }
+       
+       function editInput($table, $field, $attrs, $value) {
+               static $lang = "";
+               if (!$lang && ereg("text", $field["type"]) && ereg("_html", $field["field"])) {
+                       $lang = "en";
+                       if (function_exists('get_lang')) { // since Adminer 3.2.0
+                               $lang = get_lang();
+                               $lang = ($lang == "zh" || $lang == "zh-tw" ? "zh_cn" : $lang);
+                       }
+                       return "<textarea$attrs id='fields-" . h($field["field"]) . "' rows='12' cols='50'>" . h($value) . "</textarea><script type='text/javascript'>
+jQuery(function () {
+       jQuery('textarea[name*=\"_html\"]').wymeditor({ updateSelector: '#form [type=\"submit\"]', lang: '$lang'" . ($this->options ? ", $this->options" : "") . " });
+});
+</script>";
+               }
+       }
+       
+}