Hi,

I'm scratching my head over htmltidy a bit, and I'm a Drupal/php newbie.

I installed html tidy, with the linux library, onto my hosted website. It didn't work and I got this on the settings page:

* warning: exec() has been disabled for security reasons in /home/gowithme/public_html/jon/drupal/modules/htmltidy/htmltidy.module on line 536.
* HTMLTidy executable is not available. Found a 'tidy' binary, but it didn't run right. /home/gowithme/public_html/jon/drupal/modules/htmltidy/bin -v failed to respond correctly

I couldn't find an answer on drupal for what to do about this. I contacted my host to ask them if they could take off the security restrictions, but they said this wasn't possible.

They did offer to do this:

We can install the tidy pecl package that gives these functions if required ?

http://uk2.php.net/tidy

Which they then did and the tidy settings can be found here:

http://byethost5.org/phpinfo.php

so my question is, now that tidy is enabled in PHP (version 5.2.4) how can I make my drupal htmltidy module work with it?

Thanks!

Comments

dman’s picture

The commandline attempt tried and failed - that error is pretty normal when exec() is disabled, but you are lucky the host was co-operative with the extension instead.

Your phpinfo says that tidy is available, however it seems that there are different flavours of the extension.
I've only used the binary distributions, but other problems have been seen with the PECL version. I do not know how different these may be,
The troubleshooting process tried in http://drupal.org/node/121323#comment-315774 will be your next best step, Although I thought that with PHP5 and a 2007 release of tidylib things would be fine.

It could be the way I test if the extension is right to work in the way expected.
Try removing the extra test from tidy-functions.inc
From

// Tidy
  if ( extension_loaded('tidy' ) && function_exists('tidy') ) {
    debug('Using tidy Extension', 3);

To

// Tidy
  if ( extension_loaded('tidy' ) ) {
    debug('Using tidy Extension', 3);

I think the test was there specifically to work around a difference in extensions I found once - one functional, one OO.

If you follow the process that shiva7663 did, you can probably fix it up to work in only 4 or 5 line changes.

Also, if you want to see what's happening, you can edit import_html.module to uncomment the DEBUGLEVEL at the top of the file. It's messy, but very informative.

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

lejon’s picture

Hi Dan,

Thanks for the advice. I didn't really understand what I was doing but your post gave me a new conviction. I found that there was a section that read like this in the htmltidy.module file which is found in the htmltidy folder in the modules folder of drupal:

/**
 * Sets the htmltidy_apppath Drupal variable to a valid value.
 * @param $message Assigned to an explanation.
 * @return true if ok, false on error.
 */
function htmltidy_test(&$message, &11.12.0-CURRENT_17349){
#  // we aren't setup to use the extension
#  if (extension_loaded('tidy')) {
#    11.12.0-CURRENT_17349 = 'PHP Tidy Extension enabled OK';
#    return TRUE;
#  }

All I did was then uncomment it so it read:

/**
 * Sets the htmltidy_apppath Drupal variable to a valid value.
 * @param $message Assigned to an explanation.
 * @return true if ok, false on error.
 */
function htmltidy_test(&$message, &11.12.0-CURRENT_17349){
#  // we aren't setup to use the extension
  if (extension_loaded('tidy')) {
    11.12.0-CURRENT_17349 = 'PHP Tidy Extension enabled OK';
    return TRUE;
  }

And then it worked!

I've never touched code before, but I suppose it all made sense when you think about it. Will also put this comment on the other page you suggested.

Cheers,

Jon

lejon’s picture

This never worked after all.

How can I get the Drupal HTML Tidy module to use the PECL tidy package installed by my web host on PHP5?

Few sites I found which I don't understand...

http://weblog.cemper.com/a/200606/18-how-to-setup-html-tidy-for-php-and-...

This is my host's php info:

http://byethost5.org/phpinfo.php

though looking at it, actually I can't find the tidy extension...

Help!

dman’s picture

The PECL branch is frustrating, as it's hard to tell whether it's installed, and then uses different functions to do the intended job.

My binary distro, that works with my PHP Version 5.1.2 has

Tidy support	enabled
libTidy Release 	1 September 2005
Extension Version 	2.0 ($Id: tidy.c,v 1.66.2.5 2006/01/01 12:50:16 sniper Exp $)

Your PECL (?) version says

Tidy support enabled 
libTidy Build Date  11 February 2007  

I have NOT been able to modify the code to work with the munant PECL version, as I've only developed and tested on Ubuntu, Debian and Windows machines, where the distributed extension works.

Someone else that can actually replicate the problem needs to try and fix it themselves

Looking at the docs, the change from OO back to functional calls - pretty much named the same - should only take a handful of lines, but I cannot test it on any of the machines available to me.

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

lejon’s picture

Hi dan,

My host has updated the library, which now says:
libTidy Release 11 February 2007
Extension Version 2.0 ($Id: tidy.c,v 1.66.2.8.2.23 2007/05/04 17:11:05 nlopess Exp $)

(see http://byethost5.org/phpinfo.php)

However, HTML tidy is still unable to see it:

* warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/bin/tidy) is not within the allowed path(s): (/home/gowithme:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/gowithme/public_html/main/sites/all/modules/htmltidy/htmltidy.module on line 522.
* warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/usr/bin/tidy) is not within the allowed path(s): (/home/gowithme:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/gowithme/public_html/main/sites/all/modules/htmltidy/htmltidy.module on line 522.
* warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/usr/local/bin/tidy) is not within the allowed path(s): (/home/gowithme:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/gowithme/public_html/main/sites/all/modules/htmltidy/htmltidy.module on line 522.
* HTMLTidy executable is not available. Couldn't find tidy binary anywhere!

Any ideas? I will try reinstalling HTMLtidy from scratch again just to see if that works as well. Otherwise, I'm at a loss.

Thanks for your help!

lejon’s picture

Hi,

My site's been moved to a virtual debian server. You say you had html tidy working with Debian but I can't find a tidy downlaod for debian, only mandrake and various others.

Is it ok to use the mandrake distribution?

Thanks!

dman’s picture

Debian:

sudo apt-get install php5-tidy

(best) or maybe:

sudo apt-get install tidy

for the command-line one.

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

lejon’s picture

Hurrah! It works! Thanks!

alpha2zee’s picture

You might be interested in looking at the htmLawed module. It enables the use of the htmLawed filter, a simple stand-alone alternative to the HTMLTidy application.