mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-23 00:13:35 +01:00
add HtmlTidy plugin
This commit is contained in:
parent
2194c868e3
commit
c3cf8d5151
104
phpgwapi/js/htmlarea/plugins/HtmlTidy/README
Executable file
104
phpgwapi/js/htmlarea/plugins/HtmlTidy/README
Executable file
@ -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
|
29
phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy-config.cfg
Executable file
29
phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy-config.cfg
Executable file
@ -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
|
83
phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy-logic.php
Executable file
83
phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy-logic.php
Executable file
@ -0,0 +1,83 @@
|
||||
<? ###################################################################
|
||||
##
|
||||
## Plugin for htmlArea, to run code through the server's HTML Tidy
|
||||
## By Adam Wright, for The University of Western Australia
|
||||
## This is the server-side script, which dirty code is run through.
|
||||
##
|
||||
## Distributed under the same terms as HTMLArea itself.
|
||||
## This notice MUST stay intact for use (see license.txt).
|
||||
##
|
||||
|
||||
// Get the original source
|
||||
$source = $_POST['htisource_name'];
|
||||
$source = stripslashes($source);
|
||||
|
||||
// Open a tidy process - I hope it's installed!
|
||||
$descriptorspec = array(
|
||||
0 => 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 = "<body>\n" .$source. "\n</body>";
|
||||
}
|
||||
|
||||
// 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++], '<body' ) === false && $startLn < sizeof($srcLines) );
|
||||
$endLn = $startLn;
|
||||
while ( strpos( $srcLines[$endLn++], '</body' ) === false && $endLn < sizeof($srcLines) );
|
||||
|
||||
$srcLines = array_slice( $srcLines, $startLn, ($endLn - $startLn - 1) );
|
||||
|
||||
// Create a set of javascript code to compile a new source string
|
||||
foreach ($srcLines as $line) {
|
||||
$jsMakeSrc .= "\tns += '" . str_replace("'","\'",$line) . "\\n';\n";
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript">
|
||||
|
||||
function setNewHtml() {
|
||||
var htRef = window.parent._editorRef.plugins['HtmlTidy'];
|
||||
htRef.instance.processTidied(tidyString());
|
||||
}
|
||||
function tidyString() {
|
||||
var ns = '\n';
|
||||
<?=$jsMakeSrc;?>
|
||||
return ns;
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body id="htiNewBody" onload="setNewHtml()">
|
||||
</body>
|
||||
</html>
|
128
phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy.js
Executable file
128
phpgwapi/js/htmlarea/plugins/HtmlTidy/html-tidy.js
Executable file
@ -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 = '<form id="htiform_id" name="htiform_name" method="post" target="htiframe_name" action="';
|
||||
frm += _editor_url + 'plugins/HtmlTidy/html-tidy-logic.php';
|
||||
frm += '"><textarea name="htisource_name" id="htisource_id">';
|
||||
frm += '</textarea></form>';
|
||||
|
||||
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);
|
||||
};
|
BIN
phpgwapi/js/htmlarea/plugins/HtmlTidy/img/html-tidy.gif
Executable file
BIN
phpgwapi/js/htmlarea/plugins/HtmlTidy/img/html-tidy.gif
Executable file
Binary file not shown.
After Width: | Height: | Size: 107 B |
18
phpgwapi/js/htmlarea/plugins/HtmlTidy/lang/en.js
Executable file
18
phpgwapi/js/htmlarea/plugins/HtmlTidy/lang/en.js
Executable file
@ -0,0 +1,18 @@
|
||||
// I18N constants
|
||||
|
||||
// LANG: "en", ENCODING: UTF-8 | ISO-8859-1
|
||||
// Author: Adam Wright, http://blog.hipikat.org/
|
||||
|
||||
// FOR TRANSLATORS:
|
||||
//
|
||||
// 1. PLEASE PUT YOUR CONTACT INFO IN THE ABOVE LINE
|
||||
// (at least a valid email address)
|
||||
//
|
||||
// 2. PLEASE TRY TO USE UTF-8 FOR ENCODING;
|
||||
// (if this is not possible, please include a comment
|
||||
// that states what encoding is necessary.)
|
||||
|
||||
HtmlTidy.I18N = {
|
||||
"tidying" : "\n Tidying up the HTML source, please wait...",
|
||||
"HT-html-tidy" : "HTML Tidy"
|
||||
};
|
Loading…
Reference in New Issue
Block a user