. */ if (!class_exists("bbLaTeX")) { class bbLaTeX { function bbLaTeX() { //constructor } function init() { $this->getAdminOptions(); } //Returns an array of admin options function getAdminOptions() { $mThemeName = bb_get_option('bb_active_theme') ; $mOptions = "bbLaTeX" . $mThemeName ; $bbLaTeXAdminOptions = array( 'cache' => dirname(__FILE__) . '/cache/', 'cacheurl' => rtrim(bb_get_option('uri'),"/") . '/' . basename(BB_PLUGIN_DIR) . '/cache/', 'latexserver' => 'http://l.wordpress.com/latex.php', 'imagefmt' => 'png', 'text_colour' => '000000', 'bg_colour' => 'FFFFFF', 'transparent' => '1', 'tag' => 'latex', 'size' => '0') ; $bbLaTeXOptions = bb_get_option($mOptions); if (!empty($bbLaTeXOptions)) { foreach ($bbLaTeXOptions as $key => $option) if ($option) { // blank option means use default $bbLaTeXAdminOptions[$key] = stripslashes($option); } } bb_update_option($mOptions, $bbLaTeXAdminOptions); return $bbLaTeXAdminOptions; } function saveTex ($toParse) { // save math code inside tags. // other filters should be told to ignore text between these tags. $bbLaTeXOptions = $this->getAdminOptions(); $tag = $bbLaTeXOptions['tag'] ; $regex = '#\[math\] *(.*?)\[/math\]#si'; if ($tag == 'tex') $regex = '#\$\$(.*?)\$\$#si'; if ($tag == 'latex') $regex = '#\\\\\[(.*?)\\\\\]#si'; return preg_replace($regex, '$1', $toParse); } function parseTex ($toParse) { $regex = '#(.*?)#si'; return preg_replace_callback($regex, array(&$this, 'createTex'), $toParse); } function createTex($toTex) { $formula_text = $toTex[1]; $imgtext=false; if (substr($formula_text, -1, 1) == "!") return "$$".substr($formula_text, 0, -1)."$$"; if (substr($formula_text, 0, 1) == "!") { $imgtext=true; $formula_text=substr($formula_text, 1); } $bbLaTeXOptions = $this->getAdminOptions(); $formula_hash = md5($formula_text . $bbLaTeXOptions['bg_colour'] . $bbLaTeXOptions['text_colour'] . $bbLaTeXOptions['size'] . $bbLaTeXOptiona['transparent']); $formula_filename = 'tex_' . $formula_hash . '.' . $bbLaTeXOptions['imagefmt']; $cache_formula_path = rtrim($bbLaTeXOptions['cache'], "/") . '/' . $formula_filename; $cache_formula_url = rtrim($bbLaTeXOptions['cacheurl'], "/") . '/' . $formula_filename; if ( !is_file($cache_formula_path)) { if ( !is_writable($bbLaTeXOptions['cache'])) { return '$$' . $formula_text . '$$' ; } $formula_url = $bbLaTeXOptions['latexserver'] . '?latex=' . rawurlencode(html_entity_decode($formula_text)) . '&bg=' . $bbLaTeXOptions['bg_colour'] . '&fg=' . $bbLaTeXOptions['text_colour'] . '&s=' . $bbLaTeXOptions['size']; $formula_image = imagecreatefrompng($formula_url); if ($bbLaTeXOptions['transparent']) { // $colour = imagecolorallocate($formula_image, hexdec('0x' . $bgColour{0} . $bgColour{1}), hexdec('0x' . $bgColour{2} . $bgColour{3}), hexdec('0x' . $bgColour{4} . $bgColour{5})); $colour = imagecolorat($formula_image, 1,1); imagecolortransparent($formula_image, $colour); } imagepng($formula_image, $cache_formula_path, 9); } $formula_output = '' . $formula_text . '' ; // returning the image-tag, referring to the image in your cache folder if($imgtext) return '
' . $formula_output . '
' ; return $formula_output ; } } } //End Class bbLaTeX if (class_exists("bbLaTeX")) { $bb_LaTeX = new bbLaTeX(); if (isset($bb_LaTeX)) { add_filter('pre_post', array($bb_LaTeX, 'saveTex'), 50); add_filter('post_text', array($bb_LaTeX, 'parseTex'), 52); add_action('bb_admin_menu_generator', 'bbLaTeX_admin_page_add'); add_filter('get_allowed_markup', 'bbLaTeX_allowed_markup', 2); add_filter('bb_allowed_tags', 'bbLaTeX_allow_tag'); } function bbLaTeX_allow_tag( $tags ) { $tags['bblatex'] = array(); return $tags; } function bbLaTeX_allowed_markup ($previous = '') { global $bb_LaTeX; // Remove bblatex from list of _displayed_ allowed tags $premarkup = preg_replace('/bblatex/', '', $previous); if ($previous) $premarkup = $premarkup . '
'; $bbLaTeXOptions = $bb_LaTeX->getAdminOptions(); $tag = $bbLaTeXOptions['tag'] ; $style = '[math]x^2 + y^2 = 1[/math]'; if ($tag == 'tex') $style = '$$x^2 + y^2 = 1$$'; if ($tag == 'latex') $style = '\[x^2 + y^2 = 1\]'; return $premarkup . 'Uses bbLaTeX. Write LaTeX syntax as ' . $style; } function bbLaTeX_admin_page_add() { bb_admin_add_submenu(__('bbLaTeX Configuration'), 'use_keys', 'bbLaTeXprintAdminPage'); } //Prints out the admin page function bbLaTeXprintAdminPage() { global $bb_LaTeX; $mThemeName = bb_get_option('bb_active_theme') ; $mOptions = "bbLaTeX" . $mThemeName ; $bbLaTeXOptions = $bb_LaTeX->getAdminOptions(); if (isset($_POST['bbLaTeX_create_cache'])) { if (!@mkdir($bbLaTeXOptions['cache'],0755)) { ?>

getAdminOptions(); ?>

'; } else { if (! is_writable($bbLaTeXOptions['cache'])) { $cache_error_msg .= 'I can\'t write to it.
'; } if (! is_readable($bbLaTeXOptions['cache'])) { $cache_error_msg .= 'I can\'t read from it.
'; } } ?>
">

bbLaTeX Setup

Instructions

Options (for the theme)

Path Configuration

Cache Directory:
Cache URL:
LaTeX Server Location:
png: /> gif: />

Colours (to match your theme)

Text Colour:
Background Colour:
On: /> Off: />

/> [math] ... [/math] phpBB Style
/> $$ ... $$ TeX Style
/> \[ ... \] LaTeX Style

/> Small " />
/> Medium " />
/> Large " />
/> X-Large " />
/> XX-Large " />




Credit