' . "\n"; $epilog = ' '; $body = $prolog . $node->body . $epilog ; $descriptorspec = array ( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("file", "e:/tmp/error-output.txt", "a"), // stderr is a file to write to ); $process = proc_open("e:\\images\\w3c\\tidy.exe -asxml", $descriptorspec, $pipes); if (is_resource($process)) { // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // Any error output will be appended to /tmp/error-output.txt fwrite($pipes[0], $body); fclose($pipes[0]); $s = ''; while(!feof($pipes[1])) { $s .= fgets($pipes[1], 1024); } fclose($pipes[1]); $ar = explode(chr(10), $s); $head = variable_get(VALIDNODEVARHEAD, VALIDNODEDEFHEAD); for ($i = 0 ; $i < $head ; $i++) { array_shift($ar); } $tail = variable_get(VALIDNODEVARTAIL, VALIDNODEDEFTAIL); for ($i = 0 ; $i < $tail ; $i++) { array_pop($ar); } $s = implode($ar); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $return_value = proc_close($process); $node->body = $s ; } } function valid_node_settings() { $form [VALIDNODEVARTIDY] = array ( '#type' => 'textfield', '#title' => t('"%tidy" command, including path if necessary', array('%tidy' => 'tidy')), '#default_value' => variable_get(VALIDNODEVARTIDY, VALIDNODEDEFTIDY), '#description' => t('This command takes as input the unformatted content wrapped within a XHTML prolog and epilog, and returns them as a tidied XHTML document, which is then stripped from both prolog and epilog to return the body as an XHTML fragment.') ); $form [VALIDNODEVARHEAD] = array ( '#type' => 'textfield', '#title' => t('Number of lines to strip from top of tidied content to remove the prolog'), '#size' => 3, '#maxlength' => 3, '#default_value' => variable_get(VALIDNODEVARHEAD, VALIDNODEDEFHEAD), ); $form [VALIDNODEVARTAIL] = array ( '#type' => 'textfield', '#title' => t('Number of lines to strip from bottom of tidied content to remove the epilog'), '#size' => 3, '#maxlength' => 3, '#default_value' => variable_get(VALIDNODEVARTAIL, VALIDNODEDEFTAIL), ); $form[VALIDNODEVERSION] = array ( '#value' => '

' . t('This site is running valid_node version %version.', array('%version' => VALIDNODEVERSION) ) . "

\n

" . t('For information about tidy, see %tidy', array('%tidy' => 'http://www.w3.org/Markup') ) . "

\n" ); return $form; }