|
1
|
|
|
<?php |
|
2
|
|
|
/****************************************************************** |
|
3
|
|
|
mod_tidy.php Muze Ariadne |
|
4
|
|
|
------------------------------------------------------------------ |
|
5
|
|
|
Author: Muze ([email protected]) |
|
6
|
|
|
Date: 26 november 2002 |
|
7
|
|
|
|
|
8
|
|
|
Copyright 2002 Muze |
|
9
|
|
|
|
|
10
|
|
|
This file is part of Ariadne. |
|
11
|
|
|
|
|
12
|
|
|
Ariadne is free software; you can redistribute it and/or modify |
|
13
|
|
|
it under the terms of the GNU General Public License as published |
|
14
|
|
|
by the Free Software Foundation; either version 2 of the License, |
|
15
|
|
|
or (at your option) any later version. |
|
16
|
|
|
|
|
17
|
|
|
Ariadne is distributed in the hope that it will be useful, |
|
18
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20
|
|
|
GNU General Public License for more details. |
|
21
|
|
|
|
|
22
|
|
|
You should have received a copy of the GNU General Public License |
|
23
|
|
|
along with Ariadne; if not, write to the Free Software |
|
24
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
|
25
|
|
|
02111-1307 USA |
|
26
|
|
|
|
|
27
|
|
|
------------------------------------------------------------------- |
|
28
|
|
|
|
|
29
|
|
|
Description: |
|
30
|
|
|
|
|
31
|
|
|
This module calls the html tidy executable with the given |
|
32
|
|
|
options and returns 'clean' html. |
|
33
|
|
|
|
|
34
|
|
|
******************************************************************/ |
|
35
|
|
|
|
|
36
|
|
|
class ARtidy { |
|
37
|
|
|
|
|
38
|
|
|
function __construct($config) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->tidy=$config["path"]; |
|
|
|
|
|
|
41
|
|
|
$this->temp=$config["temp"]; |
|
|
|
|
|
|
42
|
|
|
$this->options=$config["options"]; |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
function clean($html, $config=false) |
|
46
|
|
|
{ |
|
47
|
|
|
global $AR; |
|
48
|
|
|
if (!$config) { |
|
49
|
|
|
$config["path"]=$this->tidy; |
|
50
|
|
|
$config["temp"]=$this->temp; |
|
51
|
|
|
$config["options"]=$this->options; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if ($AR->OS == "WIN32") { |
|
55
|
|
|
include_once($AR->dir->install."/lib/modules/mod_unicode.php"); |
|
56
|
|
|
$html=unicode::utf8convert($html); |
|
57
|
|
|
} |
|
58
|
|
|
$html = preg_replace('|(<[?]xml:namespace[^/]*office[^/]*/>)|i', '', $html); |
|
59
|
|
|
|
|
60
|
|
|
$file = tempnam($config["temp"],'tidy-php-tmp'); |
|
61
|
|
|
$errfile = tempnam($config["temp"],'tidy-php-err'); |
|
62
|
|
|
|
|
63
|
|
|
$fd = fopen($file,"w"); |
|
64
|
|
|
fwrite($fd,$html,strlen($html)); |
|
65
|
|
|
fclose($fd); |
|
66
|
|
|
|
|
67
|
|
|
$pd = popen($config["path"]." -f ".$errfile." ".$config["options"]." ".$file,"r"); |
|
68
|
|
|
while (!feof($pd)) |
|
69
|
|
|
{ |
|
70
|
|
|
$outhtml .= fread($pd, 1024); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
pclose($pd); |
|
73
|
|
|
|
|
74
|
|
|
$fd = fopen($errfile,"r"); |
|
75
|
|
|
while (!feof($fd)) |
|
76
|
|
|
{ |
|
77
|
|
|
$errors .= fread($fd, 1024); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
fclose($fd); |
|
80
|
|
|
|
|
81
|
|
|
unlink($file); |
|
82
|
|
|
unlink($errfile); |
|
83
|
|
|
$ret['html'] = $outhtml; |
|
|
|
|
|
|
84
|
|
|
$ret['errors'] = $errors; |
|
85
|
|
|
return $ret; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
if (!class_exists('tidy', false)) { |
|
91
|
|
|
// provide tidy class for code not migrated to ARtidy name, but only if the package php5-tidy is not loaded |
|
92
|
|
|
class tidy extends ARtidy {} |
|
93
|
|
|
} |
|
94
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: