From c3cf8d5151079d04ffb938c2bdf5b5401594f171 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Wed, 21 Apr 2004 19:18:54 +0000 Subject: [PATCH] add HtmlTidy plugin --- phpgwapi/js/htmlarea/plugins/HtmlTidy/README | 104 ++++++++++++++ .../plugins/HtmlTidy/html-tidy-config.cfg | 29 ++++ .../plugins/HtmlTidy/html-tidy-logic.php | 83 ++++++++++++ .../js/htmlarea/plugins/HtmlTidy/html-tidy.js | 128 ++++++++++++++++++ .../plugins/HtmlTidy/img/html-tidy.gif | Bin 0 -> 107 bytes .../js/htmlarea/plugins/HtmlTidy/lang/en.js | 18 +++ 6 files changed, 362 insertions(+) create mode 100755 phpgwapi/js/htmlarea/plugins/HtmlTidy/README create mode 100755 phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy-config.cfg create mode 100755 phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy-logic.php create mode 100755 phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy.js create mode 100755 phpgwapi/js/htmlarea/plugins/HtmlTidy/img/html-tidy.gif create mode 100755 phpgwapi/js/htmlarea/plugins/HtmlTidy/lang/en.js diff --git a/phpgwapi/js/htmlarea/plugins/HtmlTidy/README b/phpgwapi/js/htmlarea/plugins/HtmlTidy/README new file mode 100755 index 0000000000..a3e19f2c85 --- /dev/null +++ b/phpgwapi/js/htmlarea/plugins/HtmlTidy/README @@ -0,0 +1,104 @@ +// Plugin for htmlArea to run code through the server's HTML Tidy +// By Adam Wright, for The University of Western Australia +// +// Email: zeno@ucc.gu.uwa.edu.au +// Homepage: http://blog.hipikat.org/ +// +// Distributed under the same terms as HTMLArea itself. +// This notice MUST stay intact for use (see license.txt). +// +// Version: 0.5 +// Released to the outside world: 04/03/04 + + +HtmlTidy is a plugin for the popular cross-browser TTY WYSIWYG editor, +htmlArea (http://www.interactivetools.com/products/htmlarea/). HtmlTidy +basically queries HTML Tidy (http://tidy.sourceforge.net/) on the +server side, getting it to make-html-nice, instead of relying on masses +of javascript, which the client would have to download. + +Hi, this is a quick explanation of how to install HtmlTidy. Much better +documentation is probably required, and you're welcome to write it :) + + +* The HtmlTidy directory you should have found this file in should + include the following: + + - README + This file, providing help installing the plugin. + + - html-tidy-config.cfg + This file contains the configuration options HTML Tidy uses to + clean html, and can be modified to suit your organizations + requirements. + + - html-tidy-logic.php + This is the php script, which is queried with dirty html and is + responsible for invoking HTML Tidy, getting nice new html and + returning it to the client. + + - html-tidy.js + The main htmlArea plugin, providing functionality to tidy html + through the htmlArea interface. + + - htmlarea.js.onmode_event.diff + At the time of publishing, an extra event handler was required + inside the main htmlarea.js file. htmlarea.js may be patched + against this file to make the changes reuquired, but be aware + that the event handler may either now be in the core or + htmlarea.js may have changed enough to invalidate the patch. + + UPDATE: now it exists in the official htmlarea.js; applying + this patch is thus no longer necessary. + + - img/html-tidy.gif + The HtmlTidy icon, for the htmlArea toolbar. Created by Dan + Petty for The University of Western Australia. + + - lang/en.js + English language file. Add your own language files here and + please contribute back into the htmlArea community! + + The HtmlArea directory should be extracted to your htmlarea/plugins/ + directory. + + +* Make sure the onMode event handler mentioned above, regarding + htmlarea.js.onmode_event.diff, exists in your htmlarea.js + + +* html-tidy-logic.php should be executable, and your web server should + be configured to execute php scripts in the directory + html-tidy-logic.php exists in. + + +* HTML Tidy needs to be installed on your server, and 'tidy' should be + an alias to it, lying in the PATH known to the user executing such + web scripts. + + +* In your htmlArea configuration, do something like this: + + HTMLArea.loadPlugin("HtmlTidy"); + + editor = new HTMLArea("doc"); + editor.registerPlugin("HtmlTidy"); + + +* Then, in your htmlArea toolbar configuration, use: + + - "HT-html-tidy" + This will create the 'tidy broom' icon on the toolbar, which + will attempt to tidy html source when clicked, and; + + - "HT-auto-tidy" + This will create an "Auto Tidy" / "Don't Tidy" dropdown, to + select whether the source should be tidied automatically when + entering source view. On by default, if you'd like it otherwise + you can do so programatically after generating the toolbar :) + (Or just hack it to be otherwise...) + + +Thank you. + +Any bugs you find can be emailed to zeno@ucc.gu.uwa.edu.au diff --git a/phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy-config.cfg b/phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy-config.cfg new file mode 100755 index 0000000000..996e1ff690 --- /dev/null +++ b/phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy-config.cfg @@ -0,0 +1,29 @@ +// Default configuration file for the htmlArea, HtmlTidy plugin +// By Adam Wright, for The University of Western Australia +// +// Evertything you always wanted to know about HTML Tidy * +// can be found at http://tidy.sourceforge.net/, and a +// quick reference to the configuration options exists at +// http://tidy.sourceforge.net/docs/quickref.html +// +// * But were afraid to ask +// +// Distributed under the same terms as HTMLArea itself. +// This notice MUST stay intact for use (see license.txt). + +word-2000: yes +clean: no +drop-font-tags: yes +doctype: auto +drop-empty-paras: yes +drop-proprietary-attributes: yes +enclose-block-text: yes +enclose-text: yes +escape-cdata: yes +logical-emphasis: yes +indent: auto +indent-spaces: 2 +break-before-br: yes +output-xhtml: yes + +force-output: yes diff --git a/phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy-logic.php b/phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy-logic.php new file mode 100755 index 0000000000..6e17b6d2e7 --- /dev/null +++ b/phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy-logic.php @@ -0,0 +1,83 @@ + array("pipe", "r"), + 1 => array("pipe", "w"), + 2 => array("file", "/dev/null", "a") + ); + $process = proc_open("tidy -config html-tidy-config.cfg", $descriptorspec, $pipes); + + // Make sure the program started and we got the hooks... + // Either way, get some source code into $source + if (is_resource($process)) { + + // Feed untidy source into the stdin + fwrite($pipes[0], $source); + fclose($pipes[0]); + + // Read clean source out to the browser + while (!feof($pipes[1])) { + //echo fgets($pipes[1], 1024); + $newsrc .= fgets($pipes[1], 1024); + } + fclose($pipes[1]); + + // Clean up after ourselves + proc_close($process); + + } else { + // Better give them back what they came with, so they don't lose it all... + $newsrc = "\n" .$source. "\n"; + } + + // Split our source into an array by lines + $srcLines = explode("\n",$newsrc); + + // Get only the lines between the body tags + $startLn = 0; + while ( strpos( $srcLines[$startLn++], ' + + + + + + + + + + diff --git a/phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy.js b/phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy.js new file mode 100755 index 0000000000..7fc52521c0 --- /dev/null +++ b/phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy.js @@ -0,0 +1,128 @@ +// Plugin for htmlArea to run code through the server's HTML Tidy +// By Adam Wright, for The University of Western Australia +// +// Distributed under the same terms as HTMLArea itself. +// This notice MUST stay intact for use (see license.txt). + +function HtmlTidy(editor) { + this.editor = editor; + + var cfg = editor.config; + var tt = HtmlTidy.I18N; + var bl = HtmlTidy.btnList; + var self = this; + + this.onMode = this.__onMode; + + // register the toolbar buttons provided by this plugin + var toolbar = []; + for (var i in bl) { + var btn = bl[i]; + if (btn == "html-tidy") { + var id = "HT-html-tidy"; + cfg.registerButton(id, tt[id], editor.imgURL(btn[0] + ".gif", "HtmlTidy"), true, + function(editor, id) { + // dispatch button press event + self.buttonPress(editor, id); + }, btn[1]); + toolbar.push(id); + } else if (btn == "html-auto-tidy") { + var ht_class = { + id : "HT-auto-tidy", + options : { "Auto-Tidy" : "auto", "Don't Tidy" : "noauto" }, + action : function (editor) { self.__onSelect(editor, this); }, + refresh : function (editor) { }, + context : "body" + }; + cfg.registerDropdown(ht_class); + } + } + + for (var i in toolbar) { + cfg.toolbar[0].push(toolbar[i]); + } +}; + +HtmlTidy._pluginInfo = { + name : "HtmlTidy", + version : "1.0", + developer : "Adam Wright", + developer_url : "http://blog.hipikat.org/", + sponsor : "The University of Western Australia", + sponsor_url : "http://www.uwa.edu.au/", + license : "htmlArea" +}; + +HtmlTidy.prototype.__onSelect = function(editor, obj) { + // Get the toolbar element object + var elem = editor._toolbarObjects[obj.id].element; + + // Set our onMode event appropriately + if (elem.value == "auto") + this.onMode = this.__onMode; + else + this.onMode = null; +}; + +HtmlTidy.prototype.__onMode = function(mode) { + if ( mode == "textmode" ) { + this.buttonPress(this.editor, "HT-html-tidy"); + } +}; + +HtmlTidy.btnList = [ + null, // separator + ["html-tidy"], + ["html-auto-tidy"] +]; + +HtmlTidy.prototype.onGenerateOnce = function() { + var editor = this.editor; + + var ifr = document.createElement("iframe"); + ifr.name = "htiframe_name"; + var s = ifr.style; + s.position = "absolute"; + s.width = s.height = s.border = s.left = s.top = s.padding = s.margin = "0px"; + document.body.appendChild(ifr); + + var frm = '
'; + + var newdiv = document.createElement('div'); + newdiv.style.display = "none"; + newdiv.innerHTML = frm; + document.body.appendChild(newdiv); +}; + +HtmlTidy.prototype.buttonPress = function(editor, id) { + var i18n = HtmlTidy.I18N; + + switch (id) { + case "HT-html-tidy": + + var oldhtml = editor.getHTML(); + + // Ask the server for some nice new html, based on the old... + var myform = document.getElementById('htiform_id'); + var txtarea = document.getElementById('htisource_id'); + txtarea.value = editor.getHTML(); + + // Apply the 'meanwhile' text, e.g. "Tidying HTML, please wait..." + editor.setHTML(i18n['tidying']); + + // The returning tidying processing script needs to find the editor + window._editorRef = editor; + + // ...And send our old source off for processing! + myform.submit(); + break; + } +}; + +HtmlTidy.prototype.processTidied = function(newSrc) { + editor = this.editor; + editor.setHTML(newSrc); +}; diff --git a/phpgwapi/js/htmlarea/plugins/HtmlTidy/img/html-tidy.gif b/phpgwapi/js/htmlarea/plugins/HtmlTidy/img/html-tidy.gif new file mode 100755 index 0000000000000000000000000000000000000000..ed1cbb1bd40077b5ba53f234f67387732120550b GIT binary patch literal 107 zcmZ?wbhEHb6k-r!IK;rPaN$Cwq^}H;Ees3{|B-;=PZmZ71{MY#Mg~R(0U%^xHt^VW zMp1Va`%>Ynerv?vMsMRdsH!C)>Bc;PEuLk|`;%w%!m@tc{<=$E_k{E