require_once('../inc/sanitize_html.inc');
class output_options {
var $bb2html; // BBCode as HTML? (on)
var $images_as_links; // Images as hyperlinks? (off)
var $link_popup; // Links in new windows? (off)
var $closeTags; // Close extra HTML tags? (on)
var $nl2br; // Convert newlines to
's? (on)
var $htmlitems; // Convert special chars to HTML entities? (off)
var $htmlscrub; // Scrub "bad" HTML tags? (off)
var $stripslashes; // Strip slashes (depends)
function output_options() {
// Set defaults - should we DEFINE these somewhere else?
$this->bb2html = 1;
$this->images_as_links = 0;
$this->link_popup = 0;
$this->closeTags = 1;
$this->nl2br = 1;
$this->htmlitems = 0;
$this->htmlscrub = 0;
if (get_magic_quotes_gpc()) {
$this->stripslashes = 1;
}
return true;
}
}
function output_transform($text, $options = NULL) {
// Options is a output_options object, defined above
if (!$options) {
$options = new output_options; // Defaults in the class definition
}
if ($options->stripslashes) {
$text = stripslashes($text);
}
if ($options->htmlitems) {
$text = htmlentities($text);
}
if ($options->htmlscrub) {
$text = sanitize_html($text);
}
if ($options->nl2br) {
$text = nl2br($text);
}
if ($options->bb2html) {
$text = bb2html($text);
}
if ($options->images_as_links) {
$text = image_as_link($text);
}
if ($options->link_popup) {
$text = externalize_links($text);
}
return $text;
}
function get_transform_settings_from_user($user, $options = '') {
// $user - a user object
// $options - a output_options object (optional)
if (!$options) {
$options = new output_options; // Give defaults
}
if ($user->images_as_links==1){
$options->images_as_links = 1;
}
if ($user->link_popup==1){
$options->link_popup = 1;
}
return $options;
}
function bb2html($text) {
// Function converts bbcode to HTML
$urlregex = "(?:\"?)(?:(http\:\/\/)?)([^\[\"<\ ]+)(?:\"?)";
// List of allowable tags
$bbtags = array (
"@\[b\](.*?)\[/b\]@is",
"@\[i\](.*?)\[/i\]@is",
"@\[u\](.*?)\[/u\]@is",
"@\[link=$urlregex\](.*?)\[/link\]@i",
"@\[link\]$urlregex\[/link\]@i",
"@\[url=$urlregex\](.*?)\[/url\]@i",
"@\[url\]$urlregex\[/url\]@i",
"@\[quote=(.*?)\](.*?)\[/quote\]@is",
"@\[quote\](.*?)\[/quote\]@is",
"@\[font=(.*?)\](.*?)\[/font\]@is",
"@\[list\](.*?)\[/list\]@is",
"@\[list=1\](.*?)\[/list\]@is",
"@\[pre\](.*?)\[/pre\]@is",
"@\[img\]$urlregex\[/img\]@is",
"@\[color=(?:\"?)(.{3,8})(?:\"?)\](.*?)\[/color\]@is",
"@((?:
\\2", "
\\1", "\\2", "
\\1", "", "\\2", "\\1
Tag: {$tag}\nOpen: {$o}\nClose: {$c}\nOT: {$open[$tag]}\nCT: {$close[$tag]}