/includes/bbcode.php
PHP | 4718 lines | 3684 code | 297 blank | 737 comment | 680 complexity | 442916b2d1bda1372e286b299bbb16db MD5 | raw file
Possible License(s): AGPL-1.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- *
- * @package Icy Phoenix
- * @version $Id$
- * @copyright (c) 2008 Icy Phoenix
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- *
- */
- /**
- *
- * @Extra credits for this file
- * Vjacheslav Trushkin (http://www.stsoftware.biz)
- *
- */
- if (!defined('IN_ICYPHOENIX'))
- {
- die('Hacking attempt');
- }
- /*
- =================
- Includes
- =================
- include_once(IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT);
- =================
- Globals
- =================
- global $bbcode;
- =================
- BBCode Parsing
- =================
- $text = $bbcode->parse($text);
- =================
- BBCode Conditions
- =================
- $bbcode->allow_html = ($user->data['user_allowhtml'] && $config['allow_html']) ? true : false;
- $bbcode->allow_bbcode = ($user->data['user_allowbbcode'] && $config['allow_bbcode']) ? true : false;
- $bbcode->allow_smilies = ($user->data['user_allowsmile'] && $config['allow_smilies']) ? true : false;
- =================
- $html_on = ($user->data['user_allowhtml'] && $config['allow_html']) ? 1 : 0 ;
- $bbcode_on = ($user->data['user_allowbbcode'] && $config['allow_bbcode']) ? 1 : 0 ;
- $smilies_on = ($user->data['user_allowsmile'] && $config['allow_smilies']) ? 1 : 0 ;
- $bbcode->allow_html = $html_on;
- $bbcode->allow_bbcode = $bbcode_on;
- $bbcode->allow_smilies = $smilies_on;
- =================
- $bbcode->allow_html = ($config['allow_html'] ? true : false);
- $bbcode->allow_bbcode = ($config['allow_bbcode'] ? true : false);
- $bbcode->allow_smilies = ($config['allow_smilies'] ? true : false);
- =================
- $bbcode->allow_html = (($config['allow_html'] && $row['enable_bbcode']) ? true : false);
- $bbcode->allow_bbcode = (($config['allow_bbcode'] && $row['enable_bbcode']) ? true : false);
- $bbcode->allow_smilies = (($config['allow_smilies'] && $row['enable_smilies']) ? true : false);
- =================
- $bbcode->allow_html = ($config['allow_html'] && $postrow[$i]['enable_bbcode'] ? true : false);
- $bbcode->allow_bbcode = ($config['allow_bbcode'] && $postrow[$i]['enable_bbcode'] ? true : false);
- $bbcode->allow_smilies = ($config['allow_smilies'] && $postrow[$i]['enable_smilies'] ? true : false);
- =================
- =================================
- Acronyms, Autolinks
- =================================
- $text = $bbcode->acronym_pass($text);
- $text = $bbcode->autolink_text($text, $forum_id);
- ====================
- */
- // If included via function we need to make sure to have the requested globals...
- global $db, $cache, $config, $lang;
- // To use this file outside Icy Phoenix you need to comment the define below and remove the check on top of the file.
- define('IS_ICYPHOENIX', true);
- if(defined('IS_ICYPHOENIX'))
- {
- // Include moved to functions... to avoid including wrong lang file ($config['default_lang'] is only assigned after session request)
- //setup_extra_lang(array('lang_bbcb_mg'));
- }
- else
- {
- if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './../');
- if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
- $config['allow_all_bbcode'] = 0;
- $config['allow_html'] = false;
- $config['allow_bbcode'] = true;
- $config['allow_smilies'] = true;
- $config['default_lang'] = 'english';
- $config['cookie_secure'] = 0;
- $config['server_name'] = 'icyphoenix.com';
- $config['script_path'] = '/';
- $config['liw_enabled'] = 0;
- $config['liw_max_width'] = 0;
- $config['thumbnail_cache'] = 0;
- $config['thumbnail_posts'] = 0;
- $config['thumbnail_highslide'] = 0;
- $config['disable_html_guests'] = 0;
- $config['quote_iterations'] = 3;
- $config['switch_bbcb_active_content'] = 1;
- $user->data['is_bot'] = false;
- $user->data['session_logged_in'] = 0;
- $lang['OpenNewWindow'] = 'Open in new window';
- $lang['Click_enlarge_pic'] = 'Click to enlarge the image';
- $lang['Links_For_Guests'] = 'You must be logged in to see this link';
- $lang['Quote'] = 'Quote';
- $lang['Code'] = 'Code';
- $lang['OffTopic'] = 'Off Topic';
- $lang['ReviewPost'] = 'Review Post';
- $lang['wrote'] = 'wrote';
- $lang['Description'] = 'Description';
- $lang['Download'] = 'Download';
- $lang['Hide'] = 'Hide';
- $lang['Show'] = 'Show';
- $lang['Select'] = 'Select';
- $lang['xs_bbc_hide_message'] = 'Hidden';
- $lang['xs_bbc_hide_message_explain'] = 'This message is hidden, you have to answer this topic to see it.';
- $lang['DOWNLOADED'] = 'Downloaded';
- $lang['FILESIZE'] = 'Filesize';
- $lang['FILENAME'] = 'Filename';
- $lang['Not_Authorized'] = 'Not Authorized';
- $lang['FILE_NOT_AUTH'] = 'You are not authorized to download this file';
- }
- $server_protocol = !empty($config['cookie_secure']) ? 'https://' : 'http://';
- $local_urls = array(
- $server_protocol . 'www.' . $config['server_name'] . $config['script_path'],
- $server_protocol . $config['server_name'] . $config['script_path']
- );
- if (function_exists('create_server_url'))
- {
- $server_url = create_server_url();
- }
- else
- {
- $host = getenv('HTTP_HOST');
- $host = (!empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (!empty($host) ? $host : $config['server_name']));
- $server_url = $server_protocol . $host . $config['script_path'];
- }
- $smileys_path = $server_url . $config['smilies_path'] . '/';
- define('BBCODE_UID_LEN', 10);
- define('BBCODE_NOSMILIES_START', '<!-- no smilies start -->');
- define('BBCODE_NOSMILIES_END', '<!-- no smilies end -->');
- define('BBCODE_SMILIES_PATH', $smileys_path);
- define('AUTOURL', time());
- // Need to initialize the random numbers only ONCE
- mt_srand((double) microtime() * 1000000);
- class bbcode
- {
- var $text = '';
- var $html = '';
- var $tag = '';
- var $code_counter = 0;
- var $code_post_id = 0;
- var $allow_html = false;
- var $allow_styling = true;
- var $allow_bbcode = true;
- var $allow_smilies = true;
- var $allow_hs = true;
- var $plain_html = false;
- var $is_sig = false;
- var $params = array();
- var $data = array();
- var $replaced_smilies = array();
- var $self_closing_tags = array('[*]', '[hr]');
- var $allowed_bbcode = array(
- 'b' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'strong' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'em' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'i' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'u' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'tt' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'strike' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'sup' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'sub' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'color' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'highlight' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'rainbow' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'gradient' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'fade' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'opacity' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'align' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'center' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'font' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'size' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'hr' => array('nested' => true, 'inurl' => true, 'allow_empty' => true),
- 'url' => array('nested' => false, 'inurl' => false),
- 'a' => array('nested' => false, 'inurl' => false),
- 'email' => array('nested' => false, 'inurl' => false),
- 'list' => array('nested' => true, 'inurl' => false),
- 'ul' => array('nested' => true, 'inurl' => false),
- 'ol' => array('nested' => true, 'inurl' => false),
- 'li' => array('nested' => true, 'inurl' => false),
- '*' => array('nested' => true, 'inurl' => false),
- 'div' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'span' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'cell' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'spoiler' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'hide' => array('nested' => false, 'inurl' => true, 'allow_empty' => false),
- 'quote' => array('nested' => true, 'inurl' => false),
- 'ot' => array('nested' => true, 'inurl' => false),
- 'code' => array('nested' => false, 'inurl' => false),
- 'codeblock' => array('nested' => false, 'inurl' => false),
- 'c' => array('nested' => false, 'inurl' => false),
- 'img' => array('nested' => false, 'inurl' => true),
- 'imgba' => array('nested' => false, 'inurl' => true),
- 'albumimg' => array('nested' => false, 'inurl' => true),
- 'attachment' => array('nested' => false, 'inurl' => false, 'allow_empty' => true),
- 'download' => array('nested' => false, 'inurl' => false, 'allow_empty' => true),
- 'user' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'search' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'tag' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'langvar' => array('nested' => true, 'inurl' => true, 'allow_empty' => true),
- 'language' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'random' => array('nested' => true, 'inurl' => true, 'allow_empty' => true),
- 'marquee' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'smiley' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'flash' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'swf' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'flv' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'video' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'ram' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'quick' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'stream' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'emff' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'mp3' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'vimeo' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'youtube' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'googlevideo' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- // All these tags require HTML 4 specification (NON XHTML) and only work with IE!
- // Decomment below to use these properly...
- /*
- 'glow' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'shadow' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'blur' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'wave' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'fliph' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'flipv' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- */
- // Requires external file for parsing TEX
- //'tex' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- // To use tables you just need to decomment this... no need to decomment even TR and TD
- //'table' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- /*
- 'tr' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'td' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- */
- // To use IFRAMES you just need to decomment this line (and the block some hundreds lines below)... good luck!
- //'iframe' => array('nested' => true, 'inurl' => false, 'allow_empty' => true),
- );
- var $allowed_html = array(
- 'b' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'strong' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'em' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'i' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'u' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'tt' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'strike' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'sup' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'sub' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
- 'div' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'span' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'center' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'hr' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'a' => array('nested' => false, 'inurl' => false),
- 'ul' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'ol' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'li' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'code' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'blockquote' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
- 'table' => array('nested' => true, 'inurl' => false),
- /*
- 'tr' => array('nested' => true, 'inurl' => false),
- 'td' => array('nested' => true, 'inurl' => false),
- */
- // To use IFRAMES you just need to decomment this line (and the block some hundreds lines below)... good luck!
- //'iframe' => array('nested' => true, 'inurl' => false, 'allow_empty' => true),
- );
- var $allowed_smilies = array(
- array('code' => ':wink:', 'replace' => '(wink)'),
- array('code' => ';)', 'replace' => '(smile1)'),
- array('code' => ':)', 'replace' => '(smile2)'),
- );
- /**
- * Instantiate class
- */
- function __construct()
- {
- global $config;
- $this->allow_html = (!empty($config['allow_html']) ? true : false);
- $this->allow_bbcode = (!empty($config['allow_bbcode']) ? true : false);
- $this->allow_smilies = (!empty($config['allow_smilies']) ? true : false);
- }
- /*
- Clean bbcode/html tag.
- */
- function clean_tag(&$item)
- {
- $tag = $item['tag'];
- //echo 'clean_tag(', $tag, ')<br />';
- $start = substr($this->text, $item['start'], $item['start_len']);
- $end = substr($this->text, $item['end'], $item['end_len']);
- $content = substr($this->text, $item['start'] + $item['start_len'], $item['end'] - $item['start'] - $item['start_len']);
- $error = array(
- 'valid' => false,
- 'start' => $this->process_text($start),
- 'end' => $this->process_text($end)
- );
- if(isset($item['valid']) && $item['valid'] == false)
- {
- return $error;
- }
- // check if empty item is allowed
- if(!strlen($content))
- {
- $allow_empty = true;
- if($item['is_html'] && isset($this->allowed_html[$tag]['allow_empty']) && !$this->allowed_html[$tag]['allow_empty'])
- {
- $allow_empty = false;
- }
- if(!$item['is_html'] && isset($this->allowed_bbcode[$tag]['allow_empty']) && !$this->allowed_bbcode[$tag]['allow_empty'])
- {
- $allow_empty = false;
- }
- if(!$allow_empty)
- {
- return array(
- 'valid' => true,
- 'html' => '',
- 'end' => '',
- 'allow_nested' => false,
- );
- }
- }
- return array(
- 'valid' => true,
- 'start' => '',
- 'end' => ''
- );
- }
- /*
- Process bbcode/html tag.
- This is the only function you would want to modify to add your own bbcode/html tags.
- Note: this bbcode parser doesn't make any differece of bbcode and html, so <b> and [b] are treated exactly same way
- */
- function process_tag(&$item)
- {
- global $db, $cache, $config, $user, $lang, $topic_id, $local_urls, $meta_content;
- $server_protocol = !empty($config['cookie_secure']) ? 'https://' : 'http://';
- if (function_exists('create_server_url'))
- {
- $server_url = create_server_url();
- $local_urls = empty($local_urls) ? array($server_url) : array_merge(array($server_url), $local_urls);
- }
- else
- {
- $host = getenv('HTTP_HOST');
- $host = (!empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (!empty($host) ? $host : $config['server_name']));
- $server_url = $server_protocol . $host . $config['script_path'];
- }
- //LIW - BEGIN
- $max_image_width = intval($config['liw_max_width']);
- //LIW - END
- $tag = $item['tag'];
- //echo 'process_tag(', $tag, ')<br />';
- $start = substr($this->text, $item['start'], $item['start_len']);
- $end = substr($this->text, $item['end'], $item['end_len']);
- $content = substr($this->text, $item['start'] + $item['start_len'], $item['end'] - $item['start'] - $item['start_len']);
- $error = array(
- 'valid' => false,
- 'start' => $this->process_text($start),
- 'end' => $this->process_text($end)
- );
- if(isset($item['valid']) && $item['valid'] == false)
- {
- return $error;
- }
- // check if empty item is allowed
- if(!strlen($content))
- {
- $allow_empty = true;
- if($item['is_html'] && isset($this->allowed_html[$tag]['allow_empty']) && !$this->allowed_html[$tag]['allow_empty'])
- {
- $allow_empty = false;
- }
- if(!$item['is_html'] && isset($this->allowed_bbcode[$tag]['allow_empty']) && !$this->allowed_bbcode[$tag]['allow_empty'])
- {
- $allow_empty = false;
- }
- if(!$allow_empty)
- {
- return array(
- 'valid' => true,
- 'html' => '',
- 'end' => '',
- 'allow_nested' => false,
- );
- }
- }
- // check if nested item is allowed
- if($item['iteration'])
- {
- if($item['is_html'] && !$this->allowed_html[$tag]['nested'])
- {
- return $error;
- }
- if(!$item['is_html'] && !$this->allowed_bbcode[$tag]['nested'])
- {
- return $error;
- }
- }
- // Simple tags: B, EM, STRONG, I, U, TT, STRIKE, SUP, SUB, DIV, SPAN, CENTER
- if(($tag === 'b') || ($tag === 'em') || ($tag === 'strong') || ($tag === 'i') || ($tag === 'u') || ($tag === 'tt') || ($tag === 'strike') || ($tag === 'sup') || ($tag === 'sub') || ($tag === 'div') || ($tag === 'span') || ($tag === 'center'))
- {
- $extras = $this->allow_styling ? array('style', 'class', 'name') : array('class', 'name');
- $html = '<' . $tag . $this->add_extras($item['params'], $extras) . '>';
- return array(
- 'valid' => true,
- 'start' => $html,
- 'end' => '</' . $tag . '>'
- );
- }
- // COLOR
- if($tag === 'color')
- {
- $extras = $this->allow_styling ? array('class') : array();
- $color = $this->valid_color((isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['color']) ? $item['params']['color'] : false)));
- if($color === false)
- {
- return $error;
- }
- $html = '<span style="' . ($this->allow_styling && isset($item['params']['style']) ? htmlspecialchars($this->valid_style($item['params']['style'], '')) : '') . 'color: ' . $color . ';"' . $this->add_extras($item['params'], $extras) . '>';
- return array(
- 'valid' => true,
- 'start' => $html,
- 'end' => '</span>',
- );
- }
- // RAINBOW
- if($tag === 'rainbow')
- {
- $html = $this->rainbow($content);
- return array(
- 'valid' => true,
- 'html' => $html,
- 'allow_nested' => false,
- );
- }
- // GRADIENT
- if($tag === 'gradient')
- {
- $default_color1 = '#000080';
- $color1 = $this->valid_color((isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['cols']) ? $item['params']['cols'] : $default_color1)), true);
- $color1 = (($color1 === false) ? $default_color1 : $color1);
- $default_color2 = '#aaccee';
- $color2 = $this->valid_color((isset($item['params']['cole']) ? $item['params']['cole'] : $default_color2), true);
- $color2 = (($color2 === false) ? $default_color2 : $color2);
- $mode = $this->process_text((isset($item['params']['mode']) ? $item['params']['mode'] : ''));
- $default_iterations = 10;
- $iterations = intval(isset($item['params']['iterations']) ? $item['params']['iterations'] : $default_iterations);
- $iterations = ((($iterations < 10) || ($iterations > 100)) ? $default_iterations : $iterations);
- $html = $this->gradient($content, $color1, $color2, $mode, $iterations);
- return array(
- 'valid' => true,
- 'html' => $html,
- 'allow_nested' => false,
- );
- }
- // HIGHLIGHT
- if($tag === 'highlight')
- {
- $extras = $this->allow_styling ? array('class') : array();
- $default_param = '#ffffaa';
- $color = (isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['color']) ? $item['params']['color'] : $default_param));
- $color = $this->valid_color($color);
- if($color === false)
- {
- return $error;
- }
- $html = '<span style="' . ($this->allow_styling && isset($item['params']['style']) ? htmlspecialchars($this->valid_style($item['params']['style'], '')) : '') . 'background-color: ' . $color . ';"' . $this->add_extras($item['params'], $extras) . '>';
- return array(
- 'valid' => true,
- 'start' => $html,
- 'end' => '</span>',
- );
- }
- // SIZE
- if($tag === 'size')
- {
- $extras = $this->allow_styling ? array('class') : array();
- $default_param = 0;
- $size = intval((isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['size']) ? $item['params']['size'] : $default_param)));
- if($size > 0 && $size < 7)
- {
- // vBulletin-style sizes
- switch($size)
- {
- case 1: $size = 7; break;
- case 2: $size = 8; break;
- case 3: $size = 10; break;
- case 4: $size = 12; break;
- case 5: $size = 15; break;
- case 6: $size = 24; break;
- }
- }
- if(($size < 6) || ($size > 48))
- {
- return $error;
- }
- $html = '<span style="' . ($this->allow_styling && isset($item['params']['style']) ? htmlspecialchars($this->valid_style($item['params']['style'], '')) : '') . 'font-size: ' . $size . 'px; line-height: 116%;"' . $this->add_extras($item['params'], $extras) . '>';
- return array(
- 'valid' => true,
- 'start' => $html,
- 'end' => '</span>',
- );
- }
- // Single tags: HR
- if($tag === 'hr')
- {
- if($this->is_sig && !$config['allow_all_bbcode']) return $error;
- $extras = $this->allow_styling ? array('style', 'class') : array();
- $color = $this->valid_color((isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['color']) ? $item['params']['color'] : false)));
- $html = '<' . $tag . (($color === false) ? ($this->allow_styling && isset($item['params']['style']) ? (' style="' . htmlspecialchars($this->valid_style($item['params']['style'], '')) . '"') : '') : (' style="border-color: ' . $color . ';"')) . ' />';
- return array(
- 'valid' => true,
- 'html' => $html
- );
- }
- // ALIGN
- if($tag === 'align')
- {
- $extras = $this->allow_styling ? array('style', 'class') : array();
- $default_param = 'left';
- $align = (isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['align']) ? $item['params']['align'] : $default_param));
- if (($align === 'left') || ($align === 'right') || ($align === 'center') || ($align === 'justify'))
- {
- $html = '<div style="text-align: ' . $align . ';' . (($align === 'center') ? (' margin-left: auto; margin-right: auto;') : '') . '">';
- return array(
- 'valid' => true,
- 'start' => $html,
- 'end' => '</div>',
- );
- }
- else
- {
- return $error;
- }
- }
- // IMG
- if($tag === 'img')
- {
- if($this->is_sig && !$config['allow_all_bbcode']) return $error;
- // main parameters
- $params = array(
- 'src' => false,
- 'alt' => false,
- 'slide' => false,
- );
- // additional allowed parameters
- $extras = $this->allow_styling ? array('width', 'height', 'border', 'style', 'class', 'title', 'align') : array('width', 'height', 'border', 'title', 'align');
- if ($config['thumbnail_highslide'])
- {
- $slideshow = !empty($item['params']['slide']) ? ', { slideshowGroup: \'' . $this->process_text($item['params']['slide']) . '\' } ' : '';
- }
- $liw_bypass = false;
- // [img=blah]blah2[/img]
- if(isset($item['params']['param']))
- {
- $params['src'] = $item['params']['param'];
- $img_url = $params['src'];
- $img_url_enc = urlencode(ip_utf8_decode($params['src']));
- $path_parts = pathinfo($img_url);
- $params['alt'] = (!empty($content) ? $content : ip_clean_string($path_parts['filename'], $lang['ENCODING'], true));
- }
- // [img src=blah alt=blah width=123][/img]
- elseif(isset($item['params']['src']))
- {
- $params['src'] = $item['params']['src'];
- $img_url = $params['src'];
- $img_url_enc = urlencode(ip_utf8_decode($params['src']));
- $path_parts = pathinfo($img_url);
- $params['alt'] = (isset($item['params']['alt']) ? $item['params']['alt'] : (!empty($content) ? $content : ip_clean_string($path_parts['filename'], $lang['ENCODING'], true)));
- for($i = 0; $i < sizeof($extras); $i++)
- {
- if(!empty($item['params'][$extras[$i]]))
- {
- if($extras[$i] === 'style')
- {
- $style = $this->valid_style($item['params']['style']);
- if($style !== false)
- {
- $params['style'] = $style;
- }
- }
- else
- {
- $params[$extras[$i]] = $item['params'][$extras[$i]];
- }
- }
- }
- }
- // [img]blah[/img], [img width=blah]blah[/img]
- elseif(!empty($content))
- {
- $params['src'] = $content;
- $img_url = $params['src'];
- $img_url_enc = urlencode(ip_utf8_decode($params['src']));
- $path_parts = pathinfo($img_url);
- $params['alt'] = (isset($item['params']['alt']) ? $item['params']['alt'] : (isset($params['title']) ? $params['title'] : ip_clean_string($path_parts['filename'], $lang['ENCODING'], true)));
- // LIW - BEGIN
- if (($config['liw_enabled'] == 1) && ($max_image_width > 0) && ($config['thumbnail_posts'] == 0) && empty($this->plain_html))
- {
- $liw_bypass = true;
- if (isset($item['params']['width']))
- {
- $item['params']['width'] = ($item['params']['width'] > $max_image_width) ? $max_image_width : $item['params']['width'];
- }
- else
- {
- $image_size = @getimagesize($content);
- $item['params']['width'] = ($image_size[0] > $max_image_width) ? $max_image_width : $image_size[0];
- }
- }
- // LIW - END
- for($i = 0; $i < sizeof($extras); $i++)
- {
- if(!empty($item['params'][$extras[$i]]))
- {
- if($extras[$i] === 'style')
- {
- $style = $this->valid_style($item['params']['style']);
- if($style !== false)
- {
- $params['style'] = $style;
- }
- }
- else
- {
- $params[$extras[$i]] = $item['params'][$extras[$i]];
- }
- }
- }
- }
- $is_smiley = false;
- if (substr($params['src'], 0, strlen(BBCODE_SMILIES_PATH)) == BBCODE_SMILIES_PATH)
- {
- $is_smiley = true;
- }
- if (!$is_smiley && $config['thumbnail_posts'] && ($liw_bypass == false) && empty($this->plain_html))
- {
- $process_thumb = !empty($config['thumbnail_cache']) ? true : false;
- $thumb_exists = false;
- $thumb_processed = false;
- $is_light_view = false;
- if (isset($item['params']['thumb']))
- {
- if ($item['params']['thumb'] == 'false')
- {
- $process_thumb = false;
- }
- }
- if(!empty($process_thumb))
- {
- $thumb_processed = true;
- $pic_id = $img_url;
- $pic_fullpath = str_replace(array(' '), array('%20'), $pic_id);
- $pic_id = str_replace('http://', '', str_replace('https://', '', $pic_id));
- $pic_path[] = array();
- $pic_path = explode('/', $pic_id);
- $pic_filename = end($pic_path);
- $file_part = explode('.', strtolower($pic_filename));
- $pic_filetype = end($file_part);
- $thumb_ext_array = array('gif', 'jpg', 'png');
- if (in_array($pic_filetype, $thumb_ext_array))
- {
- $user_dir = '';
- $users_images_path = str_replace('http://', '', str_replace('https://', '', $server_url . str_replace(IP_ROOT_PATH, '', POSTED_IMAGES_PATH)));
- $pic_title = substr($pic_filename, 0, strlen($pic_filename) - strlen($pic_filetype) - 1);
- $pic_title_reg = preg_replace('/[^A-Za-z0-9]+/', '_', $pic_title);
- $pic_thumbnail = 'mid_' . md5($pic_id) . '_' . $pic_filename;
- if (strpos($pic_id, $users_images_path) !== false)
- {
- $user_dir = str_replace($pic_filename, '', str_replace($users_images_path, '', $pic_id));
- $pic_thumbnail = $pic_filename;
- }
- $pic_thumbnail_fullpath = POSTED_IMAGES_THUMBS_PATH . $user_dir . $pic_thumbnail;
- // Light View - BEGIN
- $light_view = request_var('light_view', 0);
- // Force to false for debugging purpose...
- $light_view = 0;
- if (!empty($light_view) && !empty($user_dir))
- {
- $is_light_view = true;
- $pic_thumbnail_fullpath = POSTED_IMAGES_THUMBS_S_PATH . $user_dir . $pic_thumbnail;
- }
- // Light View - END
- if(file_exists($pic_thumbnail_fullpath))
- {
- $thumb_exists = true;
- $params['src'] = $server_url . str_replace(IP_ROOT_PATH, '', $pic_thumbnail_fullpath);
- }
- }
- }
- $cache_image = true;
- $cache_append = '';
- if (isset($item['params']['cache']))
- {
- if ($item['params']['cache'] == 'false')
- {
- //$bbc_eamp = '&';
- $bbc_eamp = '&';
- $cache_image = false;
- $cache_append = 'cache=false' . $bbc_eamp . 'rand=' . md5(rand()) . $bbc_eamp;
- }
- else
- {
- $cache_image = true;
- }
- }
- if (!empty($process_thumb) && (($thumb_exists == false) || ($cache_image == false)))
- {
- $pic_thumbnail_script = $server_url . CMS_PAGE_IMAGE_THUMBNAIL . '?' . $cache_append . 'pic_id=' . $img_url_enc;
- // Light View - BEGIN
- if (!empty($thumb_processed) && !empty($is_light_view))
- {
- $img_url_enc = $user_dir . $pic_thumbnail;
- $pic_thumbnail_script = $server_url . CMS_PAGE_IMAGE_THUMBNAIL_S . '?' . $cache_append . 'pic_id=' . $img_url_enc;
- }
- // Light View - END
- $params['src'] = $pic_thumbnail_script;
- }
- }
- // generate html
- $html = '<img';
- foreach($params as $var => $value)
- {
- if ($this->process_text($value) != '')
- {
- $html .= ' ' . $var . '="' . $this->process_text($value) . '"';
- }
- if (($var == 'src') && (!$this->is_sig))
- {
- $meta_content['og_img'][] = $value;
- }
- }
- if(!isset($params['title']))
- {
- $html .= ' title="' . $this->process_text($params['alt']) . '"';
- }
- $html .= ' />';
- // add url
- /*
- if (strpos($params['src'], trim($config['server_name'])) == false)
- {
- $html = $this->process_text($params['alt']);
- }
- */
- // Light View - BEGIN
- if (!empty($thumb_processed) && !empty($is_light_view) && empty($this->plain_html))
- {
- $item['inurl'] = true;
- }
- // Light View - END
- if(empty($item['inurl']) && !$is_smiley && empty($this->plain_html))
- {
- if ($this->allow_hs && $config['thumbnail_posts'] && $config['thumbnail_highslide'])
- {
- $extra_html = ' class="highslide" onclick="return hs.expand(this' . $slideshow . ')"';
- }
- else
- {
- $extra_html = ' target="_blank" title="' . $lang['OpenNewWindow'] . '"';
- }
- $html = '<a href="' . $this->process_text($img_url) . '"' . $extra_html . '>' . $html . '</a>';
- }
- return array(
- 'valid' => true,
- 'html' => $html,
- 'allow_nested' => false,
- );
- }
- // IMGBA
- if($tag === 'imgba')
- {
- if($this->is_sig) return $error;
- if (!empty($this->plain_html)) return $error;
- // main parameters
- $params = array(
- 'before' => false,
- 'after' => false,
- 'width' => false,
- 'w' => false,
- 'height' => false,
- 'h' => false,
- 'alt' => false,
- 'title' => false,
- );
- foreach ($params as $k => $v)
- {
- $params[$k] = $item['params'][$k];
- }
- if (empty($params['before']) || empty($params['after']))
- {
- return $error;
- }
- $path_parts = pathinfo($params['before']);
- (int) $params['width'] = !empty($params['w']) ? intval($params['w']) : intval($params['width']);
- (int) $params['height'] = !empty($params['h']) ? intval($params['h']) : intval($params['height']);
- $params['alt'] = (!empty($params['alt']) ? $params['alt'] : ip_clean_string($path_parts['filename'], $lang['ENCODING'], true));
- if (empty($params['width']) || empty($params['height']))
- {
- return $error;
- }
- // Since we passed the main tests, we may force all needed JS inclusions...
- $config['jquery_ui'] = true;
- $config['jquery_ui_ba'] = true;
- $max_width = 600;
- $or_width = $params['width'];
- $or_height = $params['height'];
- if ($params['width'] > $max_width)
- {
- $params['width'] = $max_width;
- $params['height'] = $max_width / ($or_width / $or_height);
- }
- // additional allowed parameters
- $extras = $this->allow_styling ? array('style', 'class') : array();
- for($i = 0; $i < sizeof($extras); $i++)
- {
- if(!empty($item['params'][$extras[$i]]))
- {
- if($extras[$i] === 'style')
- {
- $style = $this->valid_style($item['params']['style']);
- if($style !== false)
- {
- $params['style'] = $style;
- }
- }
- else
- {
- $params[$extras[$i]] = $item['params'][$extras[$i]];
- }
- }
- }
- $container = 'imgba_' . substr(md5($params['before']), 0, 6);
- $imgba_error = false;
- $allowed_ext = array('gif', 'jpeg', 'jpg', 'png');
- $img_test_array = array('before', 'after');
- // Few "pseudo-security" tests
- foreach ($img_test_array as $img_test)
- {
- $file_ext = substr(strrchr($params[$img_test], '.'), 1);
- //if (!in_array($file_ext, $allowed_ext) || (strpos($params[$img_test], $server_url) !== 0) || (strpos($params[$img_test], '?') !== 0))
- if (!in_array($file_ext, $allowed_ext))
- {
- $imgba_error = true;
- }
- }
- if (!empty($imgba_error))
- {
- return $error;
- }
- // generate html
- $html = '';
- $html .= '<div id="' . $container . '"';
- foreach($params as $var => $value)
- {
- if (in_array($value, array('width', 'height')) && ($this->process_text($value) != ''))
- {
- $html .= ' ' . $var . '="' . $this->process_text($value) . '"';
- }
- }
- $html .= '>';
- $img_alt = $this->process_text($params['alt']);
- $img_title = (!empty($params['title']) ? ' title="' . $this->process_text($params['title']) . '"' : '');
- $html .= '<div><img src="' . $params['before'] . '" width="' . $params['width'] . '" height="' . $params['height'] . '" alt="Before: ' . $img_alt . '"' . $img_title . ' /></div>';
- $html .= '<div><img src="' . $params['after'] . '" width="' . $params['width'] . '" height="' . $params['height'] . '" alt="After: ' . $img_alt . '"' . $img_title . ' /></div>';
- $html .= '</div>';
- $html .= '<script type="text/javascript">$(function(){ $(\'#' . $container . '\').beforeAfter({imagePath: \'' . $server_url . 'templates/common/jquery/\', showFullLinks: true, cursor: \'e-resize\', dividerColor: \'#dd2222\', beforeLinkText: \'' . $lang['IMG_BA_SHOW_ONLY_BEFORE'] . '\', afterLinkText: \'' . $lang['IMG_BA_SHOW_ONLY_AFTER'] . '\'}); });</script>';
- return array(
- 'valid' => true,
- 'html' => $html,
- 'allow_nested' => false,
- );
- }
- // ALBUMIMG
- if($tag === 'albumimg')
- {
- if($this->is_sig && !$config['allow_all_bbcode']) return $error;
- if (!empty($this->plain_html)) return $error;
- // main parameters
- $params = array(
- 'src' => false,
- 'alt' => false,
- );
- // additional allowed parameters
- $extras = $this->allow_styling ? array('width', 'height', 'border', 'style', 'class', 'title', 'align') : array('width', 'height', 'border', 'title', 'align');
- // [albumimg=blah]blah2[/albumimg]
- if(isset($item['params']['param']))
- {
- $params['src'] = $item['params']['param'];
- $pic_url = $item['params']['param'];
- $params['alt'] = $content;
- }
- // [albumimg src=blah alt=blah width=123][/albumimg]
- elseif(isset($item['params']['src']))
- {
- $params['src'] = $item['params']['src'];
- $pic_url = $item['params']['src'];
- $params['alt'] = isset($item['params']['alt']) ? $item['params']['alt'] : $content;
- for($i = 0; $i < sizeof($extras); $i++)
- {
- if(!empty($item['params'][$extras[$i]]))
- {
- if($extras[$i] === 'style')
- {
- $style = $this->valid_style($item['params']['style']);
- if($style !== false)
- {
- $params['style'] = $style;
- }
- }
- else
- {
- $params[$extras[$i]] = $item['params'][$extras[$i]];
- }
- }
- }
- }
- // [albumimg]blah[/albumimg], [albumimg width=blah]blah[/albumimg]
- elseif(!empty($content))
- {
- $params['src'] = $content;
- $pic_url = $content;
- $params['alt'] = isset($item['params']['alt']) ? $item['params']['alt'] : (isset($params['title']) ? $params['title'] : '');
- for($i = 0; $i < sizeof($extras); $i++)
- {
- if(!empty($item['params'][$extras[$i]]))
- {
- if($extras[$i] === 'style')
- {
- $style = $this->valid_style($item['params']['style']);
- if($style !== false)
- {
- $params['style'] = $style;
- }
- }
- else
- {
- $params[$extras[$i]] = $item['params'][$extras[$i]];
- }
- }
- }
- }
- // generate html
- $pic_url = $server_url . 'album_showpage.' . PHP_EXT . '?pic_id=' . $pic_url;
- if(isset($item['params']['mode']))
- {
- $pic_mode = $item['params']['mode'];
- if ($pic_mode === 'full')
- {
- $params['src'] = $server_url . 'album_picm.' . PHP_EXT . '?pic_id=' . $params['src'];
- }
- else
- {
- $params['src'] = $server_url . 'album_thumbnail.' . PHP_EXT . '?pic_id=' . $params['src'];
- }
- }
- else
- {
- $params['src'] = $server_url . 'album_thumbnail.' . PHP_EXT . '?pic_id=' . $params['src'];
- }
- $html = '<img';
- foreach($params as $var => $value)
- {
- $html .= ' ' . $var . '="' . $this->process_text($value) . '"';
- if (($var == 'src') && (!$this->is_sig))
- {
- $meta_content['og_img'][] = $value;
- }
- }
- if(!isset($params['title']))
- {
- $html .= ' title="' . $this->process_text($params['alt']) . '"';
- }
- $html .= ' />';
- // add url
- if(empty($item['inurl']))
- {
- $html = '<a href="' . $this->process_text($pic_url) . '" title="' . $lang['Click_enlarge_pic'] . '">' . $html . '</a>';
- }
- return array(
- 'valid' => true,
- 'html' => $html,
- 'allow_nested' => false,
- );
- }
- // ATTACHMENT
- if(($tag === 'attachment') || ($tag === 'download'))
- {
- if($this->is_sig && !$config['allow_all_bbcode']) return $error;
- if (!empty($this->plain_html)) return $error;
- $html = '';
- $params['id'] = isset($item['params']['param']) ? intval($item['params']['param']) : (isset($item['params']['id']) ? intval($item['params']['id']) : false);
- $params['title'] = isset($item['params']['title']) ? $this->process_text($item['params']['title']) : false;
- $params['description'] = isset($item['params']['description']) ? $this->process_text($item['params']['description']) : (!empty($content) ? $this->process_text($content) : false);
- $params['icon'] = isset($item['params']['icon']) ? $this->process_text($item['params']['icon']) : false;
- $color = $this->valid_color(isset($item['params']['color']) ? $item['params']['color'] : false);
- $bgcolor = $this->valid_color(isset($item['params']['bgcolor']) ? $item['params']['bgcolor'] : false);
- $errored = false;
- if ($params['id'] <= 0)
- {
- $errored = true;
- }
- if (!$errored)
- {
- if ($tag === 'attachment')
- {
- if (!function_exists('get_attachment_details'))
- {
- include_once(IP_ROOT_PATH . 'includes/functions_bbcode.' . PHP_EXT);
- }
- $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $user->data);
- $is_download_auth_ary = auth(AUTH_DOWNLOAD, AUTH_LIST_ALL, $user->data);
- $attachment_details = get_attachment_details($params['id']);
- if (($attachment_details == false) || !$is_auth_ary[$attachment_details['forum_id']]['auth_read'] || !$is_download_auth_ary[$attachment_details['forum_id']]['auth_download'])
- {
- $errored = true;
- }
- }
- else
- {
- if (!function_exists('get_download_details'))
- {
- include_once(IP_ROOT_PATH . 'includes/functions_bbcode.' . PHP_EXT);
- }
- $attachment_details = get_download_details($params['id']);
- $errored = ($attachment_details == false) ? true : false;
- }
- }
- if (!$errored)
- {
- if ($tag === 'attachment')
- {
- $params['title'] = $params['title'] ? $params['title'] : (!empty($attachment_details['real_filename']) ? $attachment_details['real_filename'] : ' ');
- $params['description'] = $params['description'] ? $params['description'] : (!empty($attachment_details['comment']) ? $attachment_details['comment'] : ' ');
- $params['icon'] = IP_ROOT_PATH . FILES_ICONS_DIR . ($params['icon'] ? $params['icon'] : 'default.png');
- $download_url = IP_ROOT_PATH . 'download.' . PHP_EXT . '?id=' . $params['id'];
- }
- else
- {
- $params['title'] = $params['title'] ? $params['title'] : (!empty($attachment_details['file_name']) ? $attachment_details['file_name'] : ' ');
- $params['description'] = $params['description'] ? $params['description'] : (!empty($attachment_details['file_desc']) ? $attachment_details['file_desc'] : ' ');
- $params['icon'] = IP_ROOT_PATH . FILES_ICONS_DIR . ($params['icon'] ? $params['icon'] : (!empty($attachment_details['file_posticon']) ? $attachment_details['file_posticon'] : 'default.png'));
- $attachment_details['filesize'] = $attachment_details['file_size'];
- $attachment_details['download_count'] = $attachment_details['file_dls'];
- $download_url = IP_ROOT_PATH . 'dload.' . PHP_EXT . '?action=file&file_id=' . $params['id'];
- }
- $params['title'] = htmlspecialchars($params['title']);
- $params['description'] = htmlspecialchars($params['description']);
- $params['icon'] = file_exists($params['icon']) ? $params['icon'] : (IP_ROOT_PATH . FILES_ICONS_DIR . 'default.png');
- $style = ($color || $bgcolor) ? (' style="' . ($color ? 'color: ' . $color . ';' : '') . ($bgcolor ? 'background-color: ' . $bgcolor . ';' : '') . '"') : '';
- $html .= '<div class="mg_attachtitle"' . $style . '>' . $params['title'] . '</div>';
- $html .= '<div class="mg_attachdiv"><table>';
- $html .= '<tr><td style="width: 15%;"><b class="gensmall">' . $lang['Description'] . ':</b></td><td style="width: 75%;"><span class="gensmall">' . $params['description'] . '</span></td><td rowspan="3" class="row-center" style="width: 10%;"><img src="' . $params['icon'] . '" alt="' . $params['description'] . '" /><br /><a href="' . append_sid($download_url) . '" title="' . $lang['Download'] . ' ' . $params['title'] . '"><b>' . $lang['Download'] . '</b></a></td></tr>';
- $html .= '<tr><td><b class="gensmall">' . $lang['FILESIZE'] . ':</b></td><td><span class="gensmall">' . round(($attachment_details['filesize'] / 1024), 2) . ' KB</span></td></tr>';
- $html .= '<tr><td><b class="gensmall">' . $lang['DOWNLOADED'] . ':</b></td><td><span class="gensmall">' . $attachment_details['download_count'] . '</span></td></tr>';
- $html .= '</table></div>';
- }
- else
- {
- $style = ($color || $bgcolor) ? (' style="' . ($color ? 'color: ' . $color . ';' : '') . ($bgcolor ? 'background-color: ' . $bgcolor . ';' : '') . '"') : '';
- $html .= '<div class="mg_attachtitle"' . $style . '>' . $lang['Not_Authorized'] . '</div>';
- $html .= '<div class="mg_attachdiv"><div style="text-align: center;">' . $lang['FILE_NOT_AUTH'] . '</div></div>';
- }
- return array(
- 'valid' => true,
- 'html' => $html,
- 'allow_nested' => false,
- );
- }
- // LIST
- if(($tag === 'list') || ($tag === 'ul') || ($tag === 'ol'))
- {
- if($this->is_sig && !$config['allow_all_bbcode']) return $error;
- $extras = $this->allow_styling ? array('style', 'class') : array();
- // check if nested tags are all [*]
- $nested_count = 0;
- for($i = 0; $i < sizeof($item['items']); $i++)
- {
- $tag2 = $item['items'][$i]['tag'];
- if(($tag2 === '*') || ($tag2 === 'li'))
- {
- $nested_count++;
- }
- }
- if(!$nested_count)
- {
- // no <li> items. return error
- return $error;
- }
- // replace "list" with html tag
- if($tag === 'list')
- {
- if(isset($item['params']['param']) || isset($item['params']['type']))
- {
- $tag = 'ol';
- }
- else
- {
- $tag = 'ul';
- }
- }
- // valid tag. process subitems to make sure there are no extra items and remove all code between elements
- $last_item = false;
- for($i = 0; $i < sizeof($item['items']); $i++)
- {
- $item2 = &$item['items'][$i];
- $tag2 = $item2['tag'];
- if(($tag2 === '*') || ($tag2 === 'li'))
- {
- // mark as valid
- $item2['list_valid'] = true;
- if($last_item === false)
- {
- // change start position to end of [list]
- $pos = !empty($pos) ? $pos : 0;
- $pos2 = $item2['start'] + $item2['start_len'];
- $item2['start'] = $pos;
- $item2['start_len'] = $pos2 - $pos;
- $item2['first_entry'] = true;
- }
- $last_item = &$item['items'][$i];
- }
- }
- // generate html
- $html = '<' . $tag;
- if(isset($item['params']['param']))
- {
- $html .= ' type="' . htmlspecialchars($item['params']['param']) . '"';
- }
- elseif(isset($item['params']['type']))
- {
- $html .= ' type="' . htmlspecialchars($item['params']['type']) . '"';
- }
- $html .= $this->add_extras($item['params'], $extras) . '>';
- return array(
- 'valid' => true,
- 'start' => $html,
- 'end' => '</li></' . $tag . '>'
- );
- }
- // [*], LI
- if(($tag === '*') || ($tag === 'li'))
- {
- if($this->is_sig && !$config['allow_all_bbcode']) return $error;
- $extras = $this->allow_styling ? array('style', 'class') : array();
- // if not marked as valid return error
- if(empty($item['list_valid']))
- {
- return $error;
- }
- $html = '<li';
- if(empty($item['first_entry']))
- {
- // add closing tag for previous list entry
- $html = '</li>' . $html;
- }
- $html .= $this->add_extras($item['params'], $extras) . '>';
- return array(
- 'valid' => true,
- 'start' => $html,
- 'end' => '',
- );
- }
- // FONT
- if($tag === 'font')
- {
- $fonts = array(
- 'Arial',
- 'Arial Black',
- 'Comic Sans MS',
- 'Courier New',
- 'Impact',
- 'Lucida Console',
- 'Lucida Sans Unicode',
- 'Microsoft Sans Serif',
- 'Symbol',
- 'Tahoma',
- 'Times New Roman',
- 'Traditional Arabic',
- 'Trebuchet MS',
- 'Verdana',
- 'Webdings',
- 'Wingdings'
- );
- if (defined('FONTS_DIR'))
- {
- foreach ($cache->obtain_fonts() as $font_file)
- {
- $fonts[] = substr($font_file, 0, -4);
- }
- }
- $extras = $this->allow_styling ? array('style', 'class') : array();
- $default_param = 'Verdana';
- $font = (isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['font']) ? $item['params']['font'] : $default_param));
- $font = in_array($font, $fonts) ? $font : $default_param;
- $html = '<span style="font-family: \'' . $font . '\';">';
- return array(
- 'valid' => true,
- 'start' => $html,
- 'end' => '</span>',
- );
- }
- // CELL
- if($tag === 'cell')
- {
- $extras = $this->allow_styling ? array('style', 'class', 'align', 'border') : array('class', 'align');
- $width = (isset($item['params']['width']) ? (' width: ' . intval($item['params']['width']) . 'px;') : '');
- $height = (isset($item['params']['height']) ? (' height: ' . intval($item['params']['height']) . 'px;') : '');
- $padding = (isset($item['params']['padding']) ? (' padding: ' . intval($item['params']['padding']) . 'px;') : '');
- $margin = (isset($item['params']['margin']) ? (' margin: ' . intval($item['params']['margin']) . 'px;') : '');
- $borderwidth = (isset($item['params']['borderwidth']) ? (' border-width: ' . intval($item['params']['borderwidth']) . 'px;') : '');
- $bgcolor = $this->valid_color((isset($item['params']['bgcolor']) ? $item['params']['bgcolor'] : false));
- $bgcolor = (($bgcolor !== false) ? (' background-color: ' . $bgcolor . ';') : '');
- $bordercolor = $this->valid_color((isset($item['params']['bordercolor']) ? $item['params']['bordercolor'] : false));
- $bordercolor = (($bordercolor !== false) ? (' border-color: ' . $bordercolor . ';') : '');
- $color = $this->valid_color((isset($item['params']['color']) ? $item['params']['color'] : false));
- $color = (($color !== false) ? (' color: ' . $color . ';') : '');
- $html = '<div style="' . ($this->allow_styling && isset($item['params']['style']) ? htmlspecialchars($this->valid_style($item['params']['style'], '')) : '') . $height . $width . $bgcolor . $bordercolor . $borderwidth . $color . $padding . $margin . '"' . $this->add_extras($item['params'], $extras) . '>';
- return array(
- 'valid' => true,
- 'start' => $html,
- 'end' => '</div>',
- );
- }
- // URL, A
- if(($tag === 'url') || ($tag === 'a'))
- {
- $extras = $this->allow_styling ? array('style', 'class', 'name', 'title') : array('name', 'title');
- $allow_nested = true;
- $strip_text = false;
- $show_content = true;
- $url = '';
- // get url
- if(!empty($item['params']['param']))
- {
- $url = $item['params']['param'];
- }
- elseif(!empty($item['params']['href']))
- {
- $url = $item['params']['href'];
- }
- elseif(!$item['is_html'])
- {
- $url = $content;
- $allow_nested = false;
- $strip_text = true;
- }
- else
- {
- return $error;
- }
- if(($url === $content) && (strlen($content) > 64))
- {
- $content = htmlspecialchars(substr($content, 0, 35) . '...' . substr($content, strlen($content) - 15));
- $show_content = false;
- }
- // check if its email
- if(substr(strtolower($url), 0, 7) === 'mailto:')
- {
- $item['tag'] = 'email';
- return $this->process_tag($item);
- }
- // check for invalid urls
- $url = $this->valid_url($url, '');
- if(empty($url))
- {
- return $error;
- }
- // check nested items
- if(!$allow_nested)
- {
- for($i = 0; $i < sizeof($item['items']); $i+…
Large files files are truncated, but you can click here to view the full file