function has_flash_enabled($bitfield_data) { $bitfield = new bitfield($bitfield_data); return $bitfield->get(11); }
/** * Return the bbcode.html template for every installed style * * @return array 2D array. style_id as keys, each element is an array with a "template" element that contains the style's bbcode.html and a "bbcodes" element that contains the name of each BBCode that is to be stylised */ public function get_styles_templates() { $templates = array(); $bbcode_ids = array('quote' => 0, 'b' => 1, 'i' => 2, 'url' => 3, 'img' => 4, 'size' => 5, 'color' => 6, 'u' => 7, 'code' => 8, 'list' => 9, '*' => 9, 'email' => 10, 'flash' => 11, 'attachment' => 12); $styles = array(); foreach ($this->get_styles() as $row) { $styles[$row['style_id']] = $row; } foreach ($styles as $style_id => $style) { $bbcodes = array(); // Collect the name of the BBCodes whose bit is set in the style's bbcode_bitfield $template_bitfield = new \bitfield($style['bbcode_bitfield']); foreach ($bbcode_ids as $bbcode_name => $bit) { if ($template_bitfield->get($bit)) { $bbcodes[] = $bbcode_name; } } $filename = $this->resolve_style_filename($styles, $style); if ($filename === false) { // Ignore this style, it will use the default templates continue; } $templates[$style_id] = array('bbcodes' => $bbcodes, 'template' => file_get_contents($filename)); } return $templates; }
function bbcode_tpl($tpl_name, $bbcode_id = -1) { global $_CLASS; if (empty($bbcode_hardtpl)) { static $bbcode_hardtpl = array(); $bbcode_hardtpl = array('b_open' => '<span style="font-weight: bold">', 'b_close' => '</span>', 'i_open' => '<span style="font-style: italic">', 'i_close' => '</span>', 'u_open' => '<span style="text-decoration: underline">', 'u_close' => '</span>', 'img' => '<img src="$1" alt="' . $_CLASS['core_user']->get_lang('IMAGE') . '" />', 'size' => '<span style="font-size: $1px; line-height: normal">$2</span>', 'color' => '<span style="color: $1">$2</span>', 'email' => '<a href="mailto:$1">$2</a>'); $template_bitfield = new bitfield($this->template_bitfield); } if ($bbcode_id != -1 && !$template_bitfield->get($bbcode_id)) { return isset($bbcode_hardtpl[$tpl_name]) ? $bbcode_hardtpl[$tpl_name] : FALSE; } if (empty($this->bbcode_template)) { if (($tpl = file_get_contents($this->template_filename)) === false) { trigger_error('Could not load bbcode template', E_USER_ERROR); } // replace \ with \\ and then ' with \'. $tpl = str_replace('\\', '\\\\', $tpl); $tpl = str_replace("'", "\\'", $tpl); // strip newlines and indent $tpl = preg_replace("/\n[\n\r\\s\t]*/", '', $tpl); // Turn template blocks into PHP assignment statements for the values of $bbcode_tpl.. $this->bbcode_template = array(); $matches = preg_match_all('#<!-- BEGIN (.*?) -->(.*?)<!-- END (?:.*?) -->#', $tpl, $match); for ($i = 0; $i < $matches; $i++) { if (empty($match[1][$i])) { continue; } $this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]); } } return isset($this->bbcode_template[$tpl_name]) ? $this->bbcode_template[$tpl_name] : (isset($bbcode_hardtpl[$tpl_name]) ? $bbcode_hardtpl[$tpl_name] : false); }