/', $text, $matches); for ($i = 0; $i < $count; $i++) { // Determine if the specified path is absolute, or relative to the root path // If it's neither, assume it's relative to the default path set on line 12 if (strpos(($matches[1][$i]), 'http://') !== false) { $path = $matches[1][$i]; } else if (substr(($matches[1][$i]), 0, 1) == '/') { $path = $_SERVER['DOCUMENT_ROOT'] . $matches[1][$i]; } else { $path = $default_path . $matches[1][$i]; } // Open the file // If the file can't be found, print an error message if ($lines = @file($path)) { $codelist = '
    ' . "\n"; foreach ($lines as $line_num => $line) { $toggle = (($line_num % 2 == 0) ? "odd" : "even"); // set alternating class names for each line // If the line is blank, insert a space to prevent collapsing // Otherwise insert the line if (ltrim($line) == "") { $codelist .= "\t" . '
  1.  
  2. ' . "\n"; } else { $numtabs = strlen($line) - strlen(ltrim($line)); // determine the number of tabs $line = trim($line); // trim leading/trailing whitespace $codelist .= "\t" . '
  3. ' . htmlspecialchars($line) . '
  4. ' . "\n"; } } // If requested, insert a link to the source file if (strtolower($matches[2][$i]) == "yes") { $filename = substr(strrchr($path, '/'), 1); $codelist .= "\t" . '' . "\n"; } $codelist .= "
"; } else { $codelist = '

[The requested file ' . $path . ' could not be found]

'; } $text = str_replace(($matches[0][$i]), $codelist, $text); } return $text; } function fix_bad_p($text) { $text = str_replace('

    ', '
      ', $text); $text = str_replace('

    ', '
', $text); return $text; } add_filter('the_content', 'code_viewer', 9); add_filter('the_content', 'fix_bad_p'); ?>