| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | $source = $_POST['htisource_name']; |
|---|
| 13 | $source = stripslashes($source); |
|---|
| 14 | $cwd = str_replace("\\","/",getcwd())."/"; |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | $descriptorspec = array( |
|---|
| 18 | 0 => array("pipe", "r"), |
|---|
| 19 | 1 => array("pipe", "w") |
|---|
| 20 | ); |
|---|
| 21 | $process = @proc_open("tidy -utf8 -config {$cwd}html-tidy-config.cfg", $descriptorspec, $pipes); |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | if (is_resource($process)) { |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | fwrite($pipes[0], $source); |
|---|
| 30 | fclose($pipes[0]); |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | while (!feof($pipes[1])) { |
|---|
| 34 | |
|---|
| 35 | $newsrc .= fgets($pipes[1], 1024); |
|---|
| 36 | } |
|---|
| 37 | fclose($pipes[1]); |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | proc_close($process); |
|---|
| 41 | |
|---|
| 42 | } else { |
|---|
| 43 | |
|---|
| 44 | if( function_exists('tidy_parse_string') ) |
|---|
| 45 | { |
|---|
| 46 | $tempsrc = tidy_parse_string($source); |
|---|
| 47 | tidy_clean_repair(); |
|---|
| 48 | $newsrc = tidy_get_output(); |
|---|
| 49 | } |
|---|
| 50 | else |
|---|
| 51 | { |
|---|
| 52 | |
|---|
| 53 | $newsrc = "<body>\n" .$source. "\n</body>"; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | $srcLines = preg_split("/\n/",$newsrc,-1,PREG_SPLIT_NO_EMPTY); |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | $startLn = 0; |
|---|
| 62 | while ( strpos( $srcLines[$startLn++], '<body' ) === false && $startLn < sizeof($srcLines) ); |
|---|
| 63 | $endLn = $startLn; |
|---|
| 64 | while ( strpos( $srcLines[$endLn++], '</body' ) === false && $endLn < sizeof($srcLines) ); |
|---|
| 65 | |
|---|
| 66 | $srcLines = array_slice( $srcLines, $startLn, ($endLn - $startLn - 1) ); |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | foreach ($srcLines as $line) { |
|---|
| 70 | $jsMakeSrc .= "\tns += '" . str_replace("'","\'",$line) . "\\n';\n"; |
|---|
| 71 | } |
|---|
| 72 | if(!sizeof($srcLines)) { |
|---|
| 73 | echo "alert(HTMLArea._lc('Tidy failed. Check your HTML for syntax errors.', 'HtmlTidy'));\n"; |
|---|
| 74 | } else { |
|---|
| 75 | ?> |
|---|
| 76 | var ns=""; |
|---|
| 77 | <?php echo $jsMakeSrc; ?> |
|---|
| 78 | editor.setHTML(ns); |
|---|
| 79 | <? } ?> |
|---|