'Tag that triggers Geshi', 'code_class' => 'Class name for the Geshi tag', 'geshi_path' => 'Location where Geshi is installed' ); var $_frontend; // options var $code_tag = 'pre'; var $code_class = 'geshi'; var $geshi_path; var $_geshi_re; function GeshiHighlighter(&$frontend, $args, $dummy_run=false) { $this->LightPressPlugin($frontend, $args, $dummy_run); if (!$dummy_run) { if (!isset($this->geshi_path)) $this->geshi_path = implode(DIRECTORY_SEPARATOR, array($frontend->options['basedir'], 'plugins', 'geshi')); $geshi_class_path = implode(DIRECTORY_SEPARATOR, array($this->geshi_path, 'geshi.php')); if (!is_file($geshi_class_path)) $this->active = false; else if (!include_once($geshi_class_path)) $this->active = false; if ($this->active) $this->_geshi_re = '/(<' . $this->code_tag . '[^>]*class="([^"]*)"[^>]*>)(.*?)(<\/' . $this->code_tag . '>)/ims'; } } function _geshi($matches) { //$g =& new Geshi(); // 0 is the full match // 1 is the full open tag // 2 are the css classes // 3 is the code // 4 is the close tag $classes = explode(' ', $matches[2]); $found = false; foreach ($classes as $k=>$v) { if ($v == $this->code_class) { $found = true; unset($classes[$k]); } } if (!$found || count($classes) == 0) return $matches[0]; $lang = array_shift($classes); $g =& new Geshi($matches[3], $lang); // TODO: make the following configurable by the user //$g->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); return $g->parse_code(); } function run($hook, &$post) { if (!$this->active) return ($this->hide()); $post['post_content'] = preg_replace_callback($this->_geshi_re, array(&$this, '_geshi'), $post['post_content']); if (isset($post['more']) && $post['more']) $post['post_more'] = preg_replace_callback($this->_geshi_re, array(&$this, '_geshi'), $post['post_more']); } function hide() { } } ?>