Page 1 of 1

use TIDY with PHPWCMS

Posted: Tue 8. Mar 2005, 10:48
by marcus@localhorst
well, I try out the TIDY integration and it works very fast and fine at the moment. I'm not shure about the performance with high traffic or larger sites but anyway.

First TIDY is a free validator to check and transform your site to valid XHTML.

Oliver integrates this to validate the PHPWCMS output on the fly.

edit: exec command must work on your server!!

1. go to http://tidy.sourceforge.net/#binaries and download the app
if your site running under Linux choose LINUX/x86 else any other provided OS

2. upload tidy to any folder you want into your phpwcms directory

3. open index.php and go to line 140 and uncomment:

Code: Select all

// EXPERIMENTAL
// now try to cleanup html code with tidy
	if(isset($phpwcms['tidy']) && $phpwcms['tidy']) {

		require_once ("include/inc_front/utf8.func.inc.php");

		$tmp_tidy_file = PHPWCMS_ROOT.'/content/tmp/'.time().'_tidy_cleanup.html';
		$tidy_written = entities_to_utf8($content['page_start'].$content["all"].$content['page_end']);
		$tidy_written = write_textfile($tmp_tidy_file, $tidy_written);
		$tidy_page_end = $content['page_end'];
		if($tidy_written && filesize($tmp_tidy_file)){
			
			//echo '<!-- '.$phpwcms['tidy_command'].' "'.$tmp_tidy_file.'" //-->';
			
			@exec($phpwcms['tidy_command'].' "'.$tmp_tidy_file.'"', $tidy_return);
			if(!isset($tidy_return[0])) {
				
				if(filesize($tmp_tidy_file) && ($content['page_end'] = file_get_contents($tmp_tidy_file))) {
					
					echo $content['page_start'] = '';
					echo $content["all"] = '';
				
				} else {
				
					$content['page_end'] = $tidy_page_end;
				}
				
			}
			unlink($tmp_tidy_file);
		}
	}
4. open conf.inc.php -> you should find (or add)

Code: Select all

$phpwcms["tidy"]              = 1;        //use tidy to cleanup rendered document 
$phpwcms["tidy_command"]      = '/www/your_root/tidy/tidy -cqm -utf8 -asxhtml -clean -numeric --wrap 0 --tidy-mark 0 --alt-text 1';        //use tidy to cleanup rendered document 
change the path on the second var $phpwcms["tidy_command"] on windows it could be C:\webroot\tidy\tidy.exe

after the filename you write the commands.
-cqm (don't know what this mean/find no documentation)
-utf8
-asxhtml (means it will validate XHTML)

and the you can notice a lot more functions with
--tidy-mark 0 (means tidy don't add a <meta generator="tidy..." /> tag)
--wrap 0 (don't wrap the sourcecode like in default settings after 68 chars)

there are a lot more commads you will find description here:
http://tidy.sourceforge.net/docs/quickref.html
http://www.perpetualpc.net/srtd_tidy.html
http://jnpassieux.chez.tiscali.fr/info/Tidy.php

sorry for my bad english, hope you understand ;-)
if you know more about this (performance, commands etc.) please tell us.

greetings marcus

Posted: Tue 8. Mar 2005, 11:04
by Gnolen
Thanks man!!!

This is really cool! I first thought it was that I could use tidy when I make articles..to check them just. But this that it could fix small problems is great!

Even if we have a valid layout from the beginning some small fault can occur when you add articles!

Yeah, maybe it will be slow with high traffic but I hope not..

Thanks for the solution...I am just a bit afraid that it will mess up thing that I do not want...

/ Gnolen

Posted: Tue 8. Mar 2005, 11:17
by marcus@localhorst
8) i found a tidy function in HTML Area for validating articles (turn on in the HTMLAREA config file), but the global solution is really fine.
No backenduser without HTML knowlege know what he should do with that function...
and the WYSIWYG Editors has many strange behaviors and write strange code, if you dont't use them carely (empty span tags and so on.)

a great thing is: tidy rewrite some HTML attributes to CSS

this line:

Code: Select all

<body text="#000000" link="#FF9900" vlink="#FF9900" alink="#FF9900" style="margin:0px 0px 0px 0px;">
turns to:

Code: Select all

<style type="text/css">
/*<![CDATA[*/
 body {
  color: #000000;
 }
 :link { color: #FF9900 }
 :visited { color: #FF9900 }
 :active { color: #FF9900 }
 body.c1 {margin:0px 0px 0px 0px;}
/*]]>*/
</style>
and

Code: Select all

<body class="c1">
:-)

Posted: Wed 9. Mar 2005, 23:35
by Gnolen
This function works great! I just really wonder how it will be if a hell of a lot of visitors comes at once...

The tidy function in the htmlarea sounds really interesting! I have trying to install it and I have come to the parts to install the buttons in htmlarea.js.

The plugin text says:

* 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...)

How did you do this??

Thanks / gnolen

Posted: Thu 10. Mar 2005, 08:49
by marcus@localhorst
i've only read about this ;-) i never try it out...

Posted: Tue 17. May 2005, 11:30
by suncomet
Is there way to know what is wrong when tidy won't work with phpwcms. I did put all the things correcty what was mentioned in this post but my page's code isn't tidy'ng. :? I get no error messages thought...

I have set the chmod 755 for the tidy binary and I have tried various of paths to tidy but nothing seems to work. Is there anything other than in this post that should be done?

Any help would be good, thanks!

Posted: Tue 17. May 2005, 13:36
by marcus@localhorst
did you download the right app for your operating system?
which OS do you use?
if you follow the steps, it should work (i've only tested it with linux).

best wishes
marcus

Posted: Tue 17. May 2005, 14:11
by suncomet
Hi,

Sorry for the fuzz! :) I got it working. For some reason I did have 755 for content/tmp (just upgraded...) where it should be 777, so it didn't work!

So if anyone else does have problems, first check permissions!

Anyway thanks for your help. :D

Posted: Wed 7. Jun 2006, 00:39
by easybaner
Wo kann ich denn im Quellcode sehen, ob Tidy benutzt wird?
Ich nehme an, ich habe alles soweit richtig gemacht, aber wie prüfen?
Hier: http://validator.de.selfhtml.org/ kommt noch Käse raus.
Also hats erstmal wohl nicht geklappt :-)

Danke,
easybaner

Posted: Wed 12. Jul 2006, 00:28
by easybaner
Kann jemand noch mal bitte deutlich sagen, was man für einen Pfad zum eigentlichen tity-Programm angibt (Linux).
Ich habe alle Settings gemacht und unkommentiert. tidy entpackt und in ein tidy-Verzeichnis geladen. Ich habe die tidy-Meta-Tags angeschaltet, um zu sehen, ob es geht. tidy liegt in einem Verzeichnis /www.xxx.com/tidy/
Es lässt sich aber scheinbar nicht ansprechen. Kann es sein, dass der Provider das Ausführen blockiert? Hat jemand einen Tipp?

Danke,
Andreas