You are here

function htmltidy_nodeapi in HTML Tidy 6

Same name and namespace in other branches
  1. 5 htmltidy.module \htmltidy_nodeapi()

File

./htmltidy.module, line 258
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_nodeapi(&$node, $op, $a3 = NULL, $page = NULL) {
  if (variable_get('htmltidy_process_input', TRUE)) {
    switch ($op) {
      case 'prepare':

        //var_dump($_htmltidy_filter); exit();
        if (isset($_POST['body'])) {
          $_POST['body'] = htmltidy_fragment($_POST['body'], $node->format, $errors, $warnings);
        }
        if (!empty($errors)) {
          $errors = array_map('htmlentities', $errors);
          form_set_error('body', theme('item_list', $errors));
        }
        break;
      case 'validate':
        global $_htmltidy_filter;
        if ($node->body) {

          // call the filters so if they're using html tidy as a filter it'll
          // be called in order
          check_markup($node->body, $node->format);
          if (isset($_htmltidy_filter['filtered']) && $_htmltidy_filter['filtered']) {
            $errors = $_htmltidy_filter['errors'];
            $warnings = $_htmltidy_filter['warnings'];
          }
          else {
            $clean = htmltidy_fragment($node->body, $node->format, $errors, $warnings);
            form_set_value(array(
              '#parents' => array(
                'body',
              ),
            ), $clean, $a3);
          }
          if ($errors || $warnings) {
            $message = '<p>Original body:</p><pre>' . htmlentities($node->body) . '</pre>';
            if ($errors) {
              $message .= theme('item_list', array_map('htmlentities', $errors));
              form_set_error('body', $message);
            }
            if ($warnings) {
              drupal_set_message("The following HTML errors have been cleaned up automatically for you: " . theme('item_list', array_map('htmlentities', $warnings)));
            }
          }
        }
        break;
    }
  }
}