function bb_content__GenerateShortcode($tagnum, $tag, $pos, $pos2, $depth, &$data, $options) { global $bb_widget, $g_bb_content_shortcodes; $str = substr($tag, $pos + 1); $taginfo = BB_HTMLParseTag("<" . $tag); if (isset($taginfo["id"])) { $sid = $taginfo["id"]; $pos = strrpos($sid, "_"); if ($pos !== false) { $sid = substr($sid, $pos + 1); } $sid = (int) $sid; if (isset($bb_widget->shortcodes[$sid]) && isset($bb_widget->shortcodes[$sid]["_sn"])) { $sname = $bb_widget->shortcodes[$sid]["_sn"]; if (isset($g_bb_content_shortcodes[$sname])) { if (!isset($g_bb_content_shortcodes[$sname]["instance"])) { if (!$g_bb_content_shortcodes[$sname]["cache"]) { $bb_widget->body_cached = false; } $shortcode = "bb_content_shortcode_" . $sname; $g_bb_content_shortcodes[$sname]["instance"] = new $shortcode(); } $info = $bb_widget->shortcodes[$sid]; bb_content_shortcode_cache_profile_pre($sname, $options["__parent"], $sid, $depth); $data2 = $g_bb_content_shortcodes[$sname]["instance"]->GenerateShortcode($options["__parent"], $sid, $depth); $data .= bb_content_shortcode_cache_profile_post($sname, $options["__parent"], $sid, $depth, $data2); $bb_widget->shortcodes[$sid] = $info; } } } $data .= $str; }
function BB_HTMLTransformForWYMEditor($data, $options) { if (isset($options["backtrack_stack_callback"]) && !function_exists($options["backtrack_stack_callback"])) { unset($options["backtrack_stack_callback"]); } if (isset($options["inline_tag_callback"]) && !function_exists($options["inline_tag_callback"])) { unset($options["inline_tag_callback"]); } if (isset($options["p_tag_callback"]) && !function_exists($options["p_tag_callback"])) { unset($options["p_tag_callback"]); } if (isset($options["shortcode_callback"]) && !function_exists($options["shortcode_callback"])) { unset($options["shortcode_callback"]); } // Process special classes and make the HTML look pretty. $bodytags = array("p" => false, "ul" => true, "ol" => true, "li" => false, "h1" => false, "h2" => false, "h3" => false, "h4" => false, "h5" => false, "h6" => false, "pre" => false, "blockquote" => true); $depth = "\n"; $tags = explode("<", $data); $data = ""; $stack = array(); $skiptag = ""; $replacetag = array("", ""); $floatused = false; foreach ($tags as $tagnum => $tag) { $pos = strpos($tag, ">"); if ($pos === false) { $data .= $tag; } else { $pos2 = strpos($tag, " "); if ($pos2 === false) { $pos2 = strlen($tag); } $name = substr($tag, 0, $pos < $pos2 ? $pos : $pos2); if (substr($name, 0, 1) != "/") { $closetag = false; } else { $name = substr($name, 1); $closetag = true; } if ($name == "img" && isset($options["shortcode_callback"])) { $options["shortcode_callback"]($tagnum, $tag, $pos, $pos2, $depth, $data, $options); } else { if (!isset($bodytags[$name])) { if (!$closetag) { if (isset($options["link_target"]) && $name == "a") { $taginfo = BB_HTMLParseTag("<" . $tag); $taginfo["target"] = $options["link_target"]; $tag = substr(BB_HTMLMakeTag($taginfo), 1) . substr($tag, $pos + 1); } if (isset($options["inline_tag_callback"])) { $options["inline_tag_callback"]($tagnum, $tag, $pos, $pos2, $name, $closetag, $stack, $depth, $skiptag, $replacetag, $data, $options); } } $data .= $skiptag == $name ? "" : "<" . ($replacetag[0] == $name ? $replacetag[1] : $tag); if ($skiptag == $name) { $skiptag = ""; } if ($replacetag[0] == $name) { $replacetag = array("", ""); } } else { if ($closetag) { if (!$bodytags[$name]) { $data .= $skiptag == $name ? "" : "<" . ($replacetag[0] == $name ? $replacetag[1] : $tag); } else { if ($name == "blockquote" && BB_HTMLTransformForWYMEditor_BacktrackStack("blockquote", $stack, $depth, $data, $options) && count($stack)) { $stack = array_slice($stack, 0, -1); } $depth = substr($depth, 0, -1); $data .= $skiptag == $name ? "" : ($data != "" ? $depth : "") . "<" . ($replacetag[0] == $name ? $replacetag[1] : $tag); } if ($skiptag == $name) { $skiptag = ""; } if ($replacetag[0] == $name) { $replacetag = array("", ""); } } else { $newdepth = $depth; if ($name == "blockquote") { $stack[] = "blockquote"; } else { if ($name == "p" && $pos2 < $pos) { // Process special classes. If the 'p' tag ever accepts more than 'class', the extraction code here will need rewriting (replace with BB_HTMLParseTag). $pos3 = strpos($tag, "\"", $pos2 + 1); if ($pos3 !== false && $pos3 < $pos) { $pos4 = strpos($tag, "\"", $pos3 + 1); if ($pos4 !== false && $pos4 < $pos) { $classes = substr($tag, $pos3 + 1, $pos4 - $pos3 - 1); $classes = BB_HTMLClassExplode($classes); if (!$floatused && (isset($classes["float-left"]) || isset($classes["float-right"]))) { $floatused = true; } if (isset($classes["wrap-shortcode"])) { unset($classes["wrap-shortcode"]); $classes["shortcode"] = "shortcode"; $tag = "div" . (count($classes) ? " class=\"" . implode(" ", $classes) . "\"" : "") . substr($tag, $pos); $replacetag = array("p", "/div>"); } else { if (isset($classes["wrap-start"])) { $stack[] = "wrap"; unset($classes["wrap-start"]); $classes["wrap"] = "wrap"; $str = substr($tag, $pos + 1); $tag = "div" . (count($classes) ? " class=\"" . implode(" ", $classes) . "\">" : ">"); $newdepth .= "\t"; if ($str == "" && $tags[$tagnum + 1] == "/p>") { $skiptag = "p"; } else { $tag .= $newdepth . "<p>" . $str; } } else { if (isset($classes["wrap-end"])) { if (BB_HTMLTransformForWYMEditor_BacktrackStack("wrap", $stack, $depth, $data, $options) && count($stack)) { $stack = array_slice($stack, 0, -1); unset($classes["wrap-end"]); $str = substr($tag, $pos + 1); $tag = "/div>"; $closetag = true; $newdepth = $depth = substr($depth, 0, -1); if ($str == "" && $tags[$tagnum + 1] == "/p>") { $skiptag = "p"; } else { $tag .= (strlen($depth) == 1 ? "\n" : "") . $depth . "<p" . (count($classes) ? " class=\"" . implode(" ", $classes) . "\">" : ">") . $str; } } } else { if (isset($classes["table-row"])) { unset($classes["table-row"]); $rowspan = $colspan = 1; foreach ($classes as $class) { if (substr($class, 0, 8) == "rowspan-") { $rowspan = (int) substr($class, 8); unset($classes[$class]); } else { if (substr($class, 0, 8) == "colspan-") { $colspan = (int) substr($class, 8); unset($classes[$class]); } } } if ($rowspan < 1) { $rowspan = 1; } if ($colspan < 1) { $colspan = 1; } $td = ($rowspan > 1 ? " rowspan=\"" . $rowspan . "\"" : "") . ($colspan > 1 ? " rowspan=\"" . $colspan . "\"" : ""); $str = substr($tag, $pos + 1); if (count($stack) && $stack[count($stack) - 1] == "table") { $tag = "/td>" . substr($depth, 0, -2) . "</tr>" . substr($depth, 0, -2) . "<tr>" . substr($depth, 0, -1) . "<td" . $td . (count($classes) ? " class=\"" . implode(" ", $classes) . "\">" : ">"); $newdepth = $depth; $depth = substr($depth, 0, -1); } else { $stack[] = "table"; $tag = "table>" . $depth . "\t<tr>" . $depth . "\t\t<td" . $td . (count($classes) ? " class=\"" . implode(" ", $classes) . "\">" : ">"); $newdepth .= "\t\t\t"; } if ($str == "" && $tags[$tagnum + 1] == "/p>") { $skiptag = "p"; } else { $tag .= $newdepth . "<p>" . $str; } } else { if (isset($classes["table-cell"])) { unset($classes["table-cell"]); $rowspan = $colspan = 1; foreach ($classes as $class) { if (substr($class, 0, 8) == "rowspan-") { $rowspan = (int) substr($class, 8); unset($classes[$class]); } else { if (substr($class, 0, 8) == "colspan-") { $colspan = (int) substr($class, 8); unset($classes[$class]); } } } if ($rowspan < 1) { $rowspan = 1; } if ($colspan < 1) { $colspan = 1; } $td = ($rowspan > 1 ? " rowspan=\"" . $rowspan . "\"" : "") . ($colspan > 1 ? " rowspan=\"" . $colspan . "\"" : ""); $str = substr($tag, $pos + 1); if (count($stack) && $stack[count($stack) - 1] == "table") { $tag = "/td>" . substr($depth, 0, -1) . "<td" . $td . (count($classes) ? " class=\"" . implode(" ", $classes) . "\">" : ">"); $newdepth = $depth; $depth = substr($depth, 0, -1); } else { $stack[] = "table"; $tag = "table>" . $depth . "\t<tr>" . $depth . "\t\t<td" . $td . (count($classes) ? " class=\"" . implode(" ", $classes) . "\">" : ">"); $newdepth .= "\t\t\t"; } if ($str == "" && $tags[$tagnum + 1] == "/p>") { $skiptag = "p"; } else { $tag .= $newdepth . "<p>" . $str; } } else { if (isset($classes["table-end"])) { if (BB_HTMLTransformForWYMEditor_BacktrackStack("table", $stack, $depth, $data, $options) && count($stack)) { $stack = array_slice($stack, 0, -1); unset($classes["table-end"]); $str = substr($tag, $pos + 1); $depth = substr($depth, 0, -1); $newdepth = substr($depth, 0, -2); $tag = "/td>" . substr($depth, 0, -1) . "</tr>" . $newdepth . "</table>"; if ($str == "" && $tags[$tagnum + 1] == "/p>") { $skiptag = "p"; } else { $tag .= (strlen($newdepth) == 1 ? "\n" : "") . $newdepth . "<p" . (count($classes) ? " class=\"" . implode(" ", $classes) . "\">" : ">") . $str; } } } else { if (isset($options["p_tag_callback"])) { $options["p_tag_callback"]($tagnum, $tag, $pos, $pos2, $name, $closetag, $stack, $depth, $skiptag, $replacetag, $data, $options); } } } } } } } } } } } $data .= ($data != "" ? (!$closetag && strlen($depth) == 1 ? "\n" : "") . $depth : "") . "<" . $tag; if ($bodytags[$name]) { $depth .= "\t"; } else { $depth = $newdepth; } } } } } } BB_HTMLTransformForWYMEditor_BacktrackStack("", $stack, $depth, $data, $options); if ($floatused) { $data .= "\n<p class=\"float-clear\"></p>"; } // Last second transformation of single tags from XHTML to HTML (e.g. <img /> to <img>). if (isset($options["doctype"]) && strtolower(substr($options["doctype"], 0, 6)) == "html 4") { $data = str_replace("/>", ">", str_replace(" />", ">", $data)); } return "\n" . $data . "\n"; }