use TIDY with PHPWCMS

If you have created additional (non official) documentation or tutorials or something like that please post this here
Post Reply
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

use TIDY with PHPWCMS

Post 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
Last edited by marcus@localhorst on Mon 3. Apr 2006, 19:50, edited 1 time in total.
Gnolen
Posts: 158
Joined: Thu 11. Mar 2004, 11:34

Post 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
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post 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">
:-)
Gnolen
Posts: 158
Joined: Thu 11. Mar 2004, 11:34

Post 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
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

i've only read about this ;-) i never try it out...
suncomet
Posts: 6
Joined: Sun 17. Apr 2005, 19:27

Post 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!
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post 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
suncomet
Posts: 6
Joined: Sun 17. Apr 2005, 19:27

Post 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
easybaner
Posts: 25
Joined: Sat 6. May 2006, 16:13

Post 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
easybaner
Posts: 25
Joined: Sat 6. May 2006, 16:13

Post 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
Post Reply