';
for ($i = 0, $count = substr_count($result, ' ') + 1; $i < $count; $i++) { $table .= ($i + $options['first_line']) . ' '; } $result = $table . ' | ' . $result . ' |
(.*?)\\s*#sie', '$this->performHighlight(\'\\2\', \'\\1\', $content);', $content);
return $content;
}
function highlightCode2($content) {
$content = str_replace(array_keys($this->blocks), array_values($this->blocks), $content);
$this->blocks = array();
return $content;
}
function protectCommentContent1($content) {
$content = preg_replace('#\s*(\[cc.*?\].*?\[/cc\])\s*#sie', '$this->performProtect(\'\\1\', $content);', $content);
$content = preg_replace('#\s*(\' . $text . '';
} else {
// See if we should force a height
$num_lines = count(explode("\n", $text));
$result = $this->highlightGeshi($text, $options);
$result = $this->addContainer($result, $options, $num_lines);
$blockID = $this->getBlockID($content);
$this->blocks[$blockID] = $result;
$result = "\n\n" . $blockID . "\n\n";
}
return $result;
}
/** Perform code protecting from mangling by Wordpress (used in Comments) */
function performProtect($text, $content) {
$text = str_replace(array("\\\"", "\\\'"), array ("\"", "\'"), $text);
$blockID = $this->getBlockID($content, true, '', '');
$this->comments[$blockID] = $text;
return "\n\n" . $blockID . "\n\n";
}
function addContainer($html, $options, $num_lines) {
$style = 'style="overflow:auto;white-space:nowrap;width:' . $options['width'] . 'px';
if($num_lines > $options['lines'] && $options['lines'] > 0) {
$style .= ';height:' . $options['height'] . 'px';
}
$style .= '"';
$result = '';
return $result;
}
/** Process the lang identifier sttribute string */
function filterLang($lang) {
$lang = strtolower($lang);
if (strstr($lang, 'html')) {
$lang = 'html4strict';
} elseif ($lang == 'c#') {
$lang = 'csharp';
} elseif ($lang == 'c++') {
$lang = 'cpp';
}
return $lang;
}
function parseOptions($opts) {
$opts = str_replace(array("\\\"", "\\\'"), array ("\"", "\'"), $opts);
preg_match_all('#([a-z_-]*?)\s*=\s*(["\'])(.*?)\2#i', $opts, $matches, PREG_SET_ORDER);
$options = array();
for ($i = 0; $i < sizeof($matches); $i++) {
$options[$matches[$i][1]] = $matches[$i][3];
}
return $this->populateDefaultValues($options);
}
function populateDefaultValues($options) {
if (!$options['lang']) $options['lang'] = 'text';
$options['lang'] = $this->filterLang($options['lang']);
if (!$options['no_cc']) {
$options['no_cc'] = false;
} else {
$options['no_cc'] = $this->parseBoolean($options['no_cc']);
}
// Tab size (int)
if (!$options['tab_size']) {
$options['tab_size'] = intval(get_option('codecolorer_tab_size'));
} else {
$options['tab_size'] = intval($options['tab_size']);
}
// Line numbers (bool)
if (!$options['line_numbers']) {
$options['line_numbers'] = $this->parseBoolean(get_option('codecolorer_line_numbers'));
} else {
$options['line_numbers'] = $this->parseBoolean($options['line_numbers']);
}
// First line (int)
if (!$options['first_line'] && $options['first_line'] !== '0') {
$options['first_line'] = 1;
} else {
$options['first_line'] = intval($options['first_line']);
}
// Disable keyword linking (bool)
if (!$options['no_links']) {
$options['no_links'] = $this->parseBoolean(get_option('codecolorer_disable_keyword_linking'));
} else {
$options['no_links'] = $this->parseBoolean($options['no_links']);
}
// Lines to scroll (int)
if (!$options['lines']) {
$options['lines'] = intval(get_option('codecolorer_lines_to_scroll'));
} else {
$options['lines'] = intval($options['lines']);
}
// Block width (int)
if (!$options['width']) {
$options['width'] = intval(get_option('codecolorer_width'));
} else {
$options['width'] = intval($options['width']);
}
// Block height (int)
if (!$options['height']) {
$options['height'] = intval(get_option('codecolorer_height'));
} else {
$options['height'] = intval($options['height']);
}
// Theme (string)
if (!$options['theme']) {
$options['theme'] = get_option('codecolorer_theme');
}
if ($options['theme'] == 'default') {
$options['theme'] = '';
}
return $options;
}
function parseBoolean($val) {
return $val === true || $val === 'true' || $val === '1' || (is_int($val) && $val !== 0);
}
function getDefaultLinesToScroll() {
return $this->DEFAULT_LINES_TO_SCROLL;
}
function getDefaultWidth() {
return $this->DEFAULT_WIDTH;
}
function getDefaultHeight() {
return $this->DEFAULT_HEIGHT;
}
}
?>