function htmltidy_test in HTML Tidy 6
Same name and namespace in other branches
- 5 htmltidy.module \htmltidy_test()
- 7 htmltidy.module \htmltidy_test()
Sets the htmltidy_apppath Drupal variable to a valid value.
Parameters
$message Assigned to an explanation.:
Return value
true if ok, false on error.
1 call to htmltidy_test()
- _htmltidy_settings in ./
htmltidy.module - Drupal hook that allows an administrator to view or modify module settings.
File
- ./
htmltidy.module, line 520 - The theme system, which controls the output of Drupal. The htmltidy module uses Tidy (http://tidy.sf.net) to properly format HTML for saving and display.
Code
function htmltidy_test(&$message, &$version) {
# // we aren't setup to use the extension
# if (extension_loaded('tidy')) {
# $version = 'PHP Tidy Extension enabled OK';
# return TRUE;
# }
$tidypath = variable_get('htmltidy_apppath', '/usr/bin/tidy');
if (!file_exists($tidypath)) {
// windows specific paths
if (substr(PHP_OS, 0, 3) == 'WIN') {
$maybepaths = array(
preg_replace('|\\\\+|', '/', dirname(__FILE__)) . '/bin/tidy.exe',
);
}
else {
$maybepaths = array(
'/bin/tidy',
'/usr/bin/tidy',
'/usr/local/bin/tidy',
preg_replace('|\\\\+|', '/', dirname(__FILE__)) . '/bin/tidy',
);
}
foreach ($maybepaths as $tidypath) {
drupal_set_message('Looking for tidy at ' . $tidypath);
if (file_exists($tidypath)) {
break;
}
}
if (!file_exists($tidypath)) {
$message = "Couldn't find tidy binary anywhere!";
return FALSE;
}
variable_set('htmltidy_apppath', $tidypath);
}
// now test it
$command = escapeshellcmd($tidypath . ' -v');
if (exec($command, $response)) {
$version = $response[0];
return TRUE;
}
else {
$message = "Found a 'tidy' binary, but it didn't run right. \n{$command}\nfailed to respond correctly";
return FALSE;
}
}