PageRenderTime 156ms CodeModel.GetById 10ms RepoModel.GetById 2ms app.codeStats 1ms

/includes/bbcode.php

http://github.com/MightyGorgon/icy_phoenix
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

  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Extra credits for this file
  13. * Vjacheslav Trushkin (http://www.stsoftware.biz)
  14. *
  15. */
  16. if (!defined('IN_ICYPHOENIX'))
  17. {
  18. die('Hacking attempt');
  19. }
  20. /*
  21. =================
  22. Includes
  23. =================
  24. include_once(IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT);
  25. =================
  26. Globals
  27. =================
  28. global $bbcode;
  29. =================
  30. BBCode Parsing
  31. =================
  32. $text = $bbcode->parse($text);
  33. =================
  34. BBCode Conditions
  35. =================
  36. $bbcode->allow_html = ($user->data['user_allowhtml'] && $config['allow_html']) ? true : false;
  37. $bbcode->allow_bbcode = ($user->data['user_allowbbcode'] && $config['allow_bbcode']) ? true : false;
  38. $bbcode->allow_smilies = ($user->data['user_allowsmile'] && $config['allow_smilies']) ? true : false;
  39. =================
  40. $html_on = ($user->data['user_allowhtml'] && $config['allow_html']) ? 1 : 0 ;
  41. $bbcode_on = ($user->data['user_allowbbcode'] && $config['allow_bbcode']) ? 1 : 0 ;
  42. $smilies_on = ($user->data['user_allowsmile'] && $config['allow_smilies']) ? 1 : 0 ;
  43. $bbcode->allow_html = $html_on;
  44. $bbcode->allow_bbcode = $bbcode_on;
  45. $bbcode->allow_smilies = $smilies_on;
  46. =================
  47. $bbcode->allow_html = ($config['allow_html'] ? true : false);
  48. $bbcode->allow_bbcode = ($config['allow_bbcode'] ? true : false);
  49. $bbcode->allow_smilies = ($config['allow_smilies'] ? true : false);
  50. =================
  51. $bbcode->allow_html = (($config['allow_html'] && $row['enable_bbcode']) ? true : false);
  52. $bbcode->allow_bbcode = (($config['allow_bbcode'] && $row['enable_bbcode']) ? true : false);
  53. $bbcode->allow_smilies = (($config['allow_smilies'] && $row['enable_smilies']) ? true : false);
  54. =================
  55. $bbcode->allow_html = ($config['allow_html'] && $postrow[$i]['enable_bbcode'] ? true : false);
  56. $bbcode->allow_bbcode = ($config['allow_bbcode'] && $postrow[$i]['enable_bbcode'] ? true : false);
  57. $bbcode->allow_smilies = ($config['allow_smilies'] && $postrow[$i]['enable_smilies'] ? true : false);
  58. =================
  59. =================================
  60. Acronyms, Autolinks
  61. =================================
  62. $text = $bbcode->acronym_pass($text);
  63. $text = $bbcode->autolink_text($text, $forum_id);
  64. ====================
  65. */
  66. // If included via function we need to make sure to have the requested globals...
  67. global $db, $cache, $config, $lang;
  68. // To use this file outside Icy Phoenix you need to comment the define below and remove the check on top of the file.
  69. define('IS_ICYPHOENIX', true);
  70. if(defined('IS_ICYPHOENIX'))
  71. {
  72. // Include moved to functions... to avoid including wrong lang file ($config['default_lang'] is only assigned after session request)
  73. //setup_extra_lang(array('lang_bbcb_mg'));
  74. }
  75. else
  76. {
  77. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './../');
  78. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  79. $config['allow_all_bbcode'] = 0;
  80. $config['allow_html'] = false;
  81. $config['allow_bbcode'] = true;
  82. $config['allow_smilies'] = true;
  83. $config['default_lang'] = 'english';
  84. $config['cookie_secure'] = 0;
  85. $config['server_name'] = 'icyphoenix.com';
  86. $config['script_path'] = '/';
  87. $config['liw_enabled'] = 0;
  88. $config['liw_max_width'] = 0;
  89. $config['thumbnail_cache'] = 0;
  90. $config['thumbnail_posts'] = 0;
  91. $config['thumbnail_highslide'] = 0;
  92. $config['disable_html_guests'] = 0;
  93. $config['quote_iterations'] = 3;
  94. $config['switch_bbcb_active_content'] = 1;
  95. $user->data['is_bot'] = false;
  96. $user->data['session_logged_in'] = 0;
  97. $lang['OpenNewWindow'] = 'Open in new window';
  98. $lang['Click_enlarge_pic'] = 'Click to enlarge the image';
  99. $lang['Links_For_Guests'] = 'You must be logged in to see this link';
  100. $lang['Quote'] = 'Quote';
  101. $lang['Code'] = 'Code';
  102. $lang['OffTopic'] = 'Off Topic';
  103. $lang['ReviewPost'] = 'Review Post';
  104. $lang['wrote'] = 'wrote';
  105. $lang['Description'] = 'Description';
  106. $lang['Download'] = 'Download';
  107. $lang['Hide'] = 'Hide';
  108. $lang['Show'] = 'Show';
  109. $lang['Select'] = 'Select';
  110. $lang['xs_bbc_hide_message'] = 'Hidden';
  111. $lang['xs_bbc_hide_message_explain'] = 'This message is hidden, you have to answer this topic to see it.';
  112. $lang['DOWNLOADED'] = 'Downloaded';
  113. $lang['FILESIZE'] = 'Filesize';
  114. $lang['FILENAME'] = 'Filename';
  115. $lang['Not_Authorized'] = 'Not Authorized';
  116. $lang['FILE_NOT_AUTH'] = 'You are not authorized to download this file';
  117. }
  118. $server_protocol = !empty($config['cookie_secure']) ? 'https://' : 'http://';
  119. $local_urls = array(
  120. $server_protocol . 'www.' . $config['server_name'] . $config['script_path'],
  121. $server_protocol . $config['server_name'] . $config['script_path']
  122. );
  123. if (function_exists('create_server_url'))
  124. {
  125. $server_url = create_server_url();
  126. }
  127. else
  128. {
  129. $host = getenv('HTTP_HOST');
  130. $host = (!empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (!empty($host) ? $host : $config['server_name']));
  131. $server_url = $server_protocol . $host . $config['script_path'];
  132. }
  133. $smileys_path = $server_url . $config['smilies_path'] . '/';
  134. define('BBCODE_UID_LEN', 10);
  135. define('BBCODE_NOSMILIES_START', '<!-- no smilies start -->');
  136. define('BBCODE_NOSMILIES_END', '<!-- no smilies end -->');
  137. define('BBCODE_SMILIES_PATH', $smileys_path);
  138. define('AUTOURL', time());
  139. // Need to initialize the random numbers only ONCE
  140. mt_srand((double) microtime() * 1000000);
  141. class bbcode
  142. {
  143. var $text = '';
  144. var $html = '';
  145. var $tag = '';
  146. var $code_counter = 0;
  147. var $code_post_id = 0;
  148. var $allow_html = false;
  149. var $allow_styling = true;
  150. var $allow_bbcode = true;
  151. var $allow_smilies = true;
  152. var $allow_hs = true;
  153. var $plain_html = false;
  154. var $is_sig = false;
  155. var $params = array();
  156. var $data = array();
  157. var $replaced_smilies = array();
  158. var $self_closing_tags = array('[*]', '[hr]');
  159. var $allowed_bbcode = array(
  160. 'b' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  161. 'strong' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  162. 'em' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  163. 'i' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  164. 'u' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  165. 'tt' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  166. 'strike' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  167. 'sup' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  168. 'sub' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  169. 'color' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  170. 'highlight' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  171. 'rainbow' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  172. 'gradient' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  173. 'fade' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  174. 'opacity' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  175. 'align' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  176. 'center' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  177. 'font' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  178. 'size' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  179. 'hr' => array('nested' => true, 'inurl' => true, 'allow_empty' => true),
  180. 'url' => array('nested' => false, 'inurl' => false),
  181. 'a' => array('nested' => false, 'inurl' => false),
  182. 'email' => array('nested' => false, 'inurl' => false),
  183. 'list' => array('nested' => true, 'inurl' => false),
  184. 'ul' => array('nested' => true, 'inurl' => false),
  185. 'ol' => array('nested' => true, 'inurl' => false),
  186. 'li' => array('nested' => true, 'inurl' => false),
  187. '*' => array('nested' => true, 'inurl' => false),
  188. 'div' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  189. 'span' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  190. 'cell' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  191. 'spoiler' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  192. 'hide' => array('nested' => false, 'inurl' => true, 'allow_empty' => false),
  193. 'quote' => array('nested' => true, 'inurl' => false),
  194. 'ot' => array('nested' => true, 'inurl' => false),
  195. 'code' => array('nested' => false, 'inurl' => false),
  196. 'codeblock' => array('nested' => false, 'inurl' => false),
  197. 'c' => array('nested' => false, 'inurl' => false),
  198. 'img' => array('nested' => false, 'inurl' => true),
  199. 'imgba' => array('nested' => false, 'inurl' => true),
  200. 'albumimg' => array('nested' => false, 'inurl' => true),
  201. 'attachment' => array('nested' => false, 'inurl' => false, 'allow_empty' => true),
  202. 'download' => array('nested' => false, 'inurl' => false, 'allow_empty' => true),
  203. 'user' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  204. 'search' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  205. 'tag' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  206. 'langvar' => array('nested' => true, 'inurl' => true, 'allow_empty' => true),
  207. 'language' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  208. 'random' => array('nested' => true, 'inurl' => true, 'allow_empty' => true),
  209. 'marquee' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  210. 'smiley' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  211. 'flash' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  212. 'swf' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  213. 'flv' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  214. 'video' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  215. 'ram' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  216. 'quick' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  217. 'stream' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  218. 'emff' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  219. 'mp3' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  220. 'vimeo' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  221. 'youtube' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  222. 'googlevideo' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  223. // All these tags require HTML 4 specification (NON XHTML) and only work with IE!
  224. // Decomment below to use these properly...
  225. /*
  226. 'glow' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  227. 'shadow' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  228. 'blur' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  229. 'wave' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  230. 'fliph' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  231. 'flipv' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  232. */
  233. // Requires external file for parsing TEX
  234. //'tex' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  235. // To use tables you just need to decomment this... no need to decomment even TR and TD
  236. //'table' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  237. /*
  238. 'tr' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  239. 'td' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  240. */
  241. // To use IFRAMES you just need to decomment this line (and the block some hundreds lines below)... good luck!
  242. //'iframe' => array('nested' => true, 'inurl' => false, 'allow_empty' => true),
  243. );
  244. var $allowed_html = array(
  245. 'b' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  246. 'strong' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  247. 'em' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  248. 'i' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  249. 'u' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  250. 'tt' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  251. 'strike' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  252. 'sup' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  253. 'sub' => array('nested' => true, 'inurl' => true, 'allow_empty' => false),
  254. 'div' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  255. 'span' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  256. 'center' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  257. 'hr' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  258. 'a' => array('nested' => false, 'inurl' => false),
  259. 'ul' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  260. 'ol' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  261. 'li' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  262. 'code' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  263. 'blockquote' => array('nested' => true, 'inurl' => false, 'allow_empty' => false),
  264. 'table' => array('nested' => true, 'inurl' => false),
  265. /*
  266. 'tr' => array('nested' => true, 'inurl' => false),
  267. 'td' => array('nested' => true, 'inurl' => false),
  268. */
  269. // To use IFRAMES you just need to decomment this line (and the block some hundreds lines below)... good luck!
  270. //'iframe' => array('nested' => true, 'inurl' => false, 'allow_empty' => true),
  271. );
  272. var $allowed_smilies = array(
  273. array('code' => ':wink:', 'replace' => '(wink)'),
  274. array('code' => ';)', 'replace' => '(smile1)'),
  275. array('code' => ':)', 'replace' => '(smile2)'),
  276. );
  277. /**
  278. * Instantiate class
  279. */
  280. function __construct()
  281. {
  282. global $config;
  283. $this->allow_html = (!empty($config['allow_html']) ? true : false);
  284. $this->allow_bbcode = (!empty($config['allow_bbcode']) ? true : false);
  285. $this->allow_smilies = (!empty($config['allow_smilies']) ? true : false);
  286. }
  287. /*
  288. Clean bbcode/html tag.
  289. */
  290. function clean_tag(&$item)
  291. {
  292. $tag = $item['tag'];
  293. //echo 'clean_tag(', $tag, ')<br />';
  294. $start = substr($this->text, $item['start'], $item['start_len']);
  295. $end = substr($this->text, $item['end'], $item['end_len']);
  296. $content = substr($this->text, $item['start'] + $item['start_len'], $item['end'] - $item['start'] - $item['start_len']);
  297. $error = array(
  298. 'valid' => false,
  299. 'start' => $this->process_text($start),
  300. 'end' => $this->process_text($end)
  301. );
  302. if(isset($item['valid']) && $item['valid'] == false)
  303. {
  304. return $error;
  305. }
  306. // check if empty item is allowed
  307. if(!strlen($content))
  308. {
  309. $allow_empty = true;
  310. if($item['is_html'] && isset($this->allowed_html[$tag]['allow_empty']) && !$this->allowed_html[$tag]['allow_empty'])
  311. {
  312. $allow_empty = false;
  313. }
  314. if(!$item['is_html'] && isset($this->allowed_bbcode[$tag]['allow_empty']) && !$this->allowed_bbcode[$tag]['allow_empty'])
  315. {
  316. $allow_empty = false;
  317. }
  318. if(!$allow_empty)
  319. {
  320. return array(
  321. 'valid' => true,
  322. 'html' => '',
  323. 'end' => '',
  324. 'allow_nested' => false,
  325. );
  326. }
  327. }
  328. return array(
  329. 'valid' => true,
  330. 'start' => '',
  331. 'end' => ''
  332. );
  333. }
  334. /*
  335. Process bbcode/html tag.
  336. This is the only function you would want to modify to add your own bbcode/html tags.
  337. Note: this bbcode parser doesn't make any differece of bbcode and html, so <b> and [b] are treated exactly same way
  338. */
  339. function process_tag(&$item)
  340. {
  341. global $db, $cache, $config, $user, $lang, $topic_id, $local_urls, $meta_content;
  342. $server_protocol = !empty($config['cookie_secure']) ? 'https://' : 'http://';
  343. if (function_exists('create_server_url'))
  344. {
  345. $server_url = create_server_url();
  346. $local_urls = empty($local_urls) ? array($server_url) : array_merge(array($server_url), $local_urls);
  347. }
  348. else
  349. {
  350. $host = getenv('HTTP_HOST');
  351. $host = (!empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (!empty($host) ? $host : $config['server_name']));
  352. $server_url = $server_protocol . $host . $config['script_path'];
  353. }
  354. //LIW - BEGIN
  355. $max_image_width = intval($config['liw_max_width']);
  356. //LIW - END
  357. $tag = $item['tag'];
  358. //echo 'process_tag(', $tag, ')<br />';
  359. $start = substr($this->text, $item['start'], $item['start_len']);
  360. $end = substr($this->text, $item['end'], $item['end_len']);
  361. $content = substr($this->text, $item['start'] + $item['start_len'], $item['end'] - $item['start'] - $item['start_len']);
  362. $error = array(
  363. 'valid' => false,
  364. 'start' => $this->process_text($start),
  365. 'end' => $this->process_text($end)
  366. );
  367. if(isset($item['valid']) && $item['valid'] == false)
  368. {
  369. return $error;
  370. }
  371. // check if empty item is allowed
  372. if(!strlen($content))
  373. {
  374. $allow_empty = true;
  375. if($item['is_html'] && isset($this->allowed_html[$tag]['allow_empty']) && !$this->allowed_html[$tag]['allow_empty'])
  376. {
  377. $allow_empty = false;
  378. }
  379. if(!$item['is_html'] && isset($this->allowed_bbcode[$tag]['allow_empty']) && !$this->allowed_bbcode[$tag]['allow_empty'])
  380. {
  381. $allow_empty = false;
  382. }
  383. if(!$allow_empty)
  384. {
  385. return array(
  386. 'valid' => true,
  387. 'html' => '',
  388. 'end' => '',
  389. 'allow_nested' => false,
  390. );
  391. }
  392. }
  393. // check if nested item is allowed
  394. if($item['iteration'])
  395. {
  396. if($item['is_html'] && !$this->allowed_html[$tag]['nested'])
  397. {
  398. return $error;
  399. }
  400. if(!$item['is_html'] && !$this->allowed_bbcode[$tag]['nested'])
  401. {
  402. return $error;
  403. }
  404. }
  405. // Simple tags: B, EM, STRONG, I, U, TT, STRIKE, SUP, SUB, DIV, SPAN, CENTER
  406. 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'))
  407. {
  408. $extras = $this->allow_styling ? array('style', 'class', 'name') : array('class', 'name');
  409. $html = '<' . $tag . $this->add_extras($item['params'], $extras) . '>';
  410. return array(
  411. 'valid' => true,
  412. 'start' => $html,
  413. 'end' => '</' . $tag . '>'
  414. );
  415. }
  416. // COLOR
  417. if($tag === 'color')
  418. {
  419. $extras = $this->allow_styling ? array('class') : array();
  420. $color = $this->valid_color((isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['color']) ? $item['params']['color'] : false)));
  421. if($color === false)
  422. {
  423. return $error;
  424. }
  425. $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) . '>';
  426. return array(
  427. 'valid' => true,
  428. 'start' => $html,
  429. 'end' => '</span>',
  430. );
  431. }
  432. // RAINBOW
  433. if($tag === 'rainbow')
  434. {
  435. $html = $this->rainbow($content);
  436. return array(
  437. 'valid' => true,
  438. 'html' => $html,
  439. 'allow_nested' => false,
  440. );
  441. }
  442. // GRADIENT
  443. if($tag === 'gradient')
  444. {
  445. $default_color1 = '#000080';
  446. $color1 = $this->valid_color((isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['cols']) ? $item['params']['cols'] : $default_color1)), true);
  447. $color1 = (($color1 === false) ? $default_color1 : $color1);
  448. $default_color2 = '#aaccee';
  449. $color2 = $this->valid_color((isset($item['params']['cole']) ? $item['params']['cole'] : $default_color2), true);
  450. $color2 = (($color2 === false) ? $default_color2 : $color2);
  451. $mode = $this->process_text((isset($item['params']['mode']) ? $item['params']['mode'] : ''));
  452. $default_iterations = 10;
  453. $iterations = intval(isset($item['params']['iterations']) ? $item['params']['iterations'] : $default_iterations);
  454. $iterations = ((($iterations < 10) || ($iterations > 100)) ? $default_iterations : $iterations);
  455. $html = $this->gradient($content, $color1, $color2, $mode, $iterations);
  456. return array(
  457. 'valid' => true,
  458. 'html' => $html,
  459. 'allow_nested' => false,
  460. );
  461. }
  462. // HIGHLIGHT
  463. if($tag === 'highlight')
  464. {
  465. $extras = $this->allow_styling ? array('class') : array();
  466. $default_param = '#ffffaa';
  467. $color = (isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['color']) ? $item['params']['color'] : $default_param));
  468. $color = $this->valid_color($color);
  469. if($color === false)
  470. {
  471. return $error;
  472. }
  473. $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) . '>';
  474. return array(
  475. 'valid' => true,
  476. 'start' => $html,
  477. 'end' => '</span>',
  478. );
  479. }
  480. // SIZE
  481. if($tag === 'size')
  482. {
  483. $extras = $this->allow_styling ? array('class') : array();
  484. $default_param = 0;
  485. $size = intval((isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['size']) ? $item['params']['size'] : $default_param)));
  486. if($size > 0 && $size < 7)
  487. {
  488. // vBulletin-style sizes
  489. switch($size)
  490. {
  491. case 1: $size = 7; break;
  492. case 2: $size = 8; break;
  493. case 3: $size = 10; break;
  494. case 4: $size = 12; break;
  495. case 5: $size = 15; break;
  496. case 6: $size = 24; break;
  497. }
  498. }
  499. if(($size < 6) || ($size > 48))
  500. {
  501. return $error;
  502. }
  503. $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) . '>';
  504. return array(
  505. 'valid' => true,
  506. 'start' => $html,
  507. 'end' => '</span>',
  508. );
  509. }
  510. // Single tags: HR
  511. if($tag === 'hr')
  512. {
  513. if($this->is_sig && !$config['allow_all_bbcode']) return $error;
  514. $extras = $this->allow_styling ? array('style', 'class') : array();
  515. $color = $this->valid_color((isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['color']) ? $item['params']['color'] : false)));
  516. $html = '<' . $tag . (($color === false) ? ($this->allow_styling && isset($item['params']['style']) ? (' style="' . htmlspecialchars($this->valid_style($item['params']['style'], '')) . '"') : '') : (' style="border-color: ' . $color . ';"')) . ' />';
  517. return array(
  518. 'valid' => true,
  519. 'html' => $html
  520. );
  521. }
  522. // ALIGN
  523. if($tag === 'align')
  524. {
  525. $extras = $this->allow_styling ? array('style', 'class') : array();
  526. $default_param = 'left';
  527. $align = (isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['align']) ? $item['params']['align'] : $default_param));
  528. if (($align === 'left') || ($align === 'right') || ($align === 'center') || ($align === 'justify'))
  529. {
  530. $html = '<div style="text-align: ' . $align . ';' . (($align === 'center') ? (' margin-left: auto; margin-right: auto;') : '') . '">';
  531. return array(
  532. 'valid' => true,
  533. 'start' => $html,
  534. 'end' => '</div>',
  535. );
  536. }
  537. else
  538. {
  539. return $error;
  540. }
  541. }
  542. // IMG
  543. if($tag === 'img')
  544. {
  545. if($this->is_sig && !$config['allow_all_bbcode']) return $error;
  546. // main parameters
  547. $params = array(
  548. 'src' => false,
  549. 'alt' => false,
  550. 'slide' => false,
  551. );
  552. // additional allowed parameters
  553. $extras = $this->allow_styling ? array('width', 'height', 'border', 'style', 'class', 'title', 'align') : array('width', 'height', 'border', 'title', 'align');
  554. if ($config['thumbnail_highslide'])
  555. {
  556. $slideshow = !empty($item['params']['slide']) ? ', { slideshowGroup: \'' . $this->process_text($item['params']['slide']) . '\' } ' : '';
  557. }
  558. $liw_bypass = false;
  559. // [img=blah]blah2[/img]
  560. if(isset($item['params']['param']))
  561. {
  562. $params['src'] = $item['params']['param'];
  563. $img_url = $params['src'];
  564. $img_url_enc = urlencode(ip_utf8_decode($params['src']));
  565. $path_parts = pathinfo($img_url);
  566. $params['alt'] = (!empty($content) ? $content : ip_clean_string($path_parts['filename'], $lang['ENCODING'], true));
  567. }
  568. // [img src=blah alt=blah width=123][/img]
  569. elseif(isset($item['params']['src']))
  570. {
  571. $params['src'] = $item['params']['src'];
  572. $img_url = $params['src'];
  573. $img_url_enc = urlencode(ip_utf8_decode($params['src']));
  574. $path_parts = pathinfo($img_url);
  575. $params['alt'] = (isset($item['params']['alt']) ? $item['params']['alt'] : (!empty($content) ? $content : ip_clean_string($path_parts['filename'], $lang['ENCODING'], true)));
  576. for($i = 0; $i < sizeof($extras); $i++)
  577. {
  578. if(!empty($item['params'][$extras[$i]]))
  579. {
  580. if($extras[$i] === 'style')
  581. {
  582. $style = $this->valid_style($item['params']['style']);
  583. if($style !== false)
  584. {
  585. $params['style'] = $style;
  586. }
  587. }
  588. else
  589. {
  590. $params[$extras[$i]] = $item['params'][$extras[$i]];
  591. }
  592. }
  593. }
  594. }
  595. // [img]blah[/img], [img width=blah]blah[/img]
  596. elseif(!empty($content))
  597. {
  598. $params['src'] = $content;
  599. $img_url = $params['src'];
  600. $img_url_enc = urlencode(ip_utf8_decode($params['src']));
  601. $path_parts = pathinfo($img_url);
  602. $params['alt'] = (isset($item['params']['alt']) ? $item['params']['alt'] : (isset($params['title']) ? $params['title'] : ip_clean_string($path_parts['filename'], $lang['ENCODING'], true)));
  603. // LIW - BEGIN
  604. if (($config['liw_enabled'] == 1) && ($max_image_width > 0) && ($config['thumbnail_posts'] == 0) && empty($this->plain_html))
  605. {
  606. $liw_bypass = true;
  607. if (isset($item['params']['width']))
  608. {
  609. $item['params']['width'] = ($item['params']['width'] > $max_image_width) ? $max_image_width : $item['params']['width'];
  610. }
  611. else
  612. {
  613. $image_size = @getimagesize($content);
  614. $item['params']['width'] = ($image_size[0] > $max_image_width) ? $max_image_width : $image_size[0];
  615. }
  616. }
  617. // LIW - END
  618. for($i = 0; $i < sizeof($extras); $i++)
  619. {
  620. if(!empty($item['params'][$extras[$i]]))
  621. {
  622. if($extras[$i] === 'style')
  623. {
  624. $style = $this->valid_style($item['params']['style']);
  625. if($style !== false)
  626. {
  627. $params['style'] = $style;
  628. }
  629. }
  630. else
  631. {
  632. $params[$extras[$i]] = $item['params'][$extras[$i]];
  633. }
  634. }
  635. }
  636. }
  637. $is_smiley = false;
  638. if (substr($params['src'], 0, strlen(BBCODE_SMILIES_PATH)) == BBCODE_SMILIES_PATH)
  639. {
  640. $is_smiley = true;
  641. }
  642. if (!$is_smiley && $config['thumbnail_posts'] && ($liw_bypass == false) && empty($this->plain_html))
  643. {
  644. $process_thumb = !empty($config['thumbnail_cache']) ? true : false;
  645. $thumb_exists = false;
  646. $thumb_processed = false;
  647. $is_light_view = false;
  648. if (isset($item['params']['thumb']))
  649. {
  650. if ($item['params']['thumb'] == 'false')
  651. {
  652. $process_thumb = false;
  653. }
  654. }
  655. if(!empty($process_thumb))
  656. {
  657. $thumb_processed = true;
  658. $pic_id = $img_url;
  659. $pic_fullpath = str_replace(array(' '), array('%20'), $pic_id);
  660. $pic_id = str_replace('http://', '', str_replace('https://', '', $pic_id));
  661. $pic_path[] = array();
  662. $pic_path = explode('/', $pic_id);
  663. $pic_filename = end($pic_path);
  664. $file_part = explode('.', strtolower($pic_filename));
  665. $pic_filetype = end($file_part);
  666. $thumb_ext_array = array('gif', 'jpg', 'png');
  667. if (in_array($pic_filetype, $thumb_ext_array))
  668. {
  669. $user_dir = '';
  670. $users_images_path = str_replace('http://', '', str_replace('https://', '', $server_url . str_replace(IP_ROOT_PATH, '', POSTED_IMAGES_PATH)));
  671. $pic_title = substr($pic_filename, 0, strlen($pic_filename) - strlen($pic_filetype) - 1);
  672. $pic_title_reg = preg_replace('/[^A-Za-z0-9]+/', '_', $pic_title);
  673. $pic_thumbnail = 'mid_' . md5($pic_id) . '_' . $pic_filename;
  674. if (strpos($pic_id, $users_images_path) !== false)
  675. {
  676. $user_dir = str_replace($pic_filename, '', str_replace($users_images_path, '', $pic_id));
  677. $pic_thumbnail = $pic_filename;
  678. }
  679. $pic_thumbnail_fullpath = POSTED_IMAGES_THUMBS_PATH . $user_dir . $pic_thumbnail;
  680. // Light View - BEGIN
  681. $light_view = request_var('light_view', 0);
  682. // Force to false for debugging purpose...
  683. $light_view = 0;
  684. if (!empty($light_view) && !empty($user_dir))
  685. {
  686. $is_light_view = true;
  687. $pic_thumbnail_fullpath = POSTED_IMAGES_THUMBS_S_PATH . $user_dir . $pic_thumbnail;
  688. }
  689. // Light View - END
  690. if(file_exists($pic_thumbnail_fullpath))
  691. {
  692. $thumb_exists = true;
  693. $params['src'] = $server_url . str_replace(IP_ROOT_PATH, '', $pic_thumbnail_fullpath);
  694. }
  695. }
  696. }
  697. $cache_image = true;
  698. $cache_append = '';
  699. if (isset($item['params']['cache']))
  700. {
  701. if ($item['params']['cache'] == 'false')
  702. {
  703. //$bbc_eamp = '&amp;';
  704. $bbc_eamp = '&';
  705. $cache_image = false;
  706. $cache_append = 'cache=false' . $bbc_eamp . 'rand=' . md5(rand()) . $bbc_eamp;
  707. }
  708. else
  709. {
  710. $cache_image = true;
  711. }
  712. }
  713. if (!empty($process_thumb) && (($thumb_exists == false) || ($cache_image == false)))
  714. {
  715. $pic_thumbnail_script = $server_url . CMS_PAGE_IMAGE_THUMBNAIL . '?' . $cache_append . 'pic_id=' . $img_url_enc;
  716. // Light View - BEGIN
  717. if (!empty($thumb_processed) && !empty($is_light_view))
  718. {
  719. $img_url_enc = $user_dir . $pic_thumbnail;
  720. $pic_thumbnail_script = $server_url . CMS_PAGE_IMAGE_THUMBNAIL_S . '?' . $cache_append . 'pic_id=' . $img_url_enc;
  721. }
  722. // Light View - END
  723. $params['src'] = $pic_thumbnail_script;
  724. }
  725. }
  726. // generate html
  727. $html = '<img';
  728. foreach($params as $var => $value)
  729. {
  730. if ($this->process_text($value) != '')
  731. {
  732. $html .= ' ' . $var . '="' . $this->process_text($value) . '"';
  733. }
  734. if (($var == 'src') && (!$this->is_sig))
  735. {
  736. $meta_content['og_img'][] = $value;
  737. }
  738. }
  739. if(!isset($params['title']))
  740. {
  741. $html .= ' title="' . $this->process_text($params['alt']) . '"';
  742. }
  743. $html .= ' />';
  744. // add url
  745. /*
  746. if (strpos($params['src'], trim($config['server_name'])) == false)
  747. {
  748. $html = $this->process_text($params['alt']);
  749. }
  750. */
  751. // Light View - BEGIN
  752. if (!empty($thumb_processed) && !empty($is_light_view) && empty($this->plain_html))
  753. {
  754. $item['inurl'] = true;
  755. }
  756. // Light View - END
  757. if(empty($item['inurl']) && !$is_smiley && empty($this->plain_html))
  758. {
  759. if ($this->allow_hs && $config['thumbnail_posts'] && $config['thumbnail_highslide'])
  760. {
  761. $extra_html = ' class="highslide" onclick="return hs.expand(this' . $slideshow . ')"';
  762. }
  763. else
  764. {
  765. $extra_html = ' target="_blank" title="' . $lang['OpenNewWindow'] . '"';
  766. }
  767. $html = '<a href="' . $this->process_text($img_url) . '"' . $extra_html . '>' . $html . '</a>';
  768. }
  769. return array(
  770. 'valid' => true,
  771. 'html' => $html,
  772. 'allow_nested' => false,
  773. );
  774. }
  775. // IMGBA
  776. if($tag === 'imgba')
  777. {
  778. if($this->is_sig) return $error;
  779. if (!empty($this->plain_html)) return $error;
  780. // main parameters
  781. $params = array(
  782. 'before' => false,
  783. 'after' => false,
  784. 'width' => false,
  785. 'w' => false,
  786. 'height' => false,
  787. 'h' => false,
  788. 'alt' => false,
  789. 'title' => false,
  790. );
  791. foreach ($params as $k => $v)
  792. {
  793. $params[$k] = $item['params'][$k];
  794. }
  795. if (empty($params['before']) || empty($params['after']))
  796. {
  797. return $error;
  798. }
  799. $path_parts = pathinfo($params['before']);
  800. (int) $params['width'] = !empty($params['w']) ? intval($params['w']) : intval($params['width']);
  801. (int) $params['height'] = !empty($params['h']) ? intval($params['h']) : intval($params['height']);
  802. $params['alt'] = (!empty($params['alt']) ? $params['alt'] : ip_clean_string($path_parts['filename'], $lang['ENCODING'], true));
  803. if (empty($params['width']) || empty($params['height']))
  804. {
  805. return $error;
  806. }
  807. // Since we passed the main tests, we may force all needed JS inclusions...
  808. $config['jquery_ui'] = true;
  809. $config['jquery_ui_ba'] = true;
  810. $max_width = 600;
  811. $or_width = $params['width'];
  812. $or_height = $params['height'];
  813. if ($params['width'] > $max_width)
  814. {
  815. $params['width'] = $max_width;
  816. $params['height'] = $max_width / ($or_width / $or_height);
  817. }
  818. // additional allowed parameters
  819. $extras = $this->allow_styling ? array('style', 'class') : array();
  820. for($i = 0; $i < sizeof($extras); $i++)
  821. {
  822. if(!empty($item['params'][$extras[$i]]))
  823. {
  824. if($extras[$i] === 'style')
  825. {
  826. $style = $this->valid_style($item['params']['style']);
  827. if($style !== false)
  828. {
  829. $params['style'] = $style;
  830. }
  831. }
  832. else
  833. {
  834. $params[$extras[$i]] = $item['params'][$extras[$i]];
  835. }
  836. }
  837. }
  838. $container = 'imgba_' . substr(md5($params['before']), 0, 6);
  839. $imgba_error = false;
  840. $allowed_ext = array('gif', 'jpeg', 'jpg', 'png');
  841. $img_test_array = array('before', 'after');
  842. // Few "pseudo-security" tests
  843. foreach ($img_test_array as $img_test)
  844. {
  845. $file_ext = substr(strrchr($params[$img_test], '.'), 1);
  846. //if (!in_array($file_ext, $allowed_ext) || (strpos($params[$img_test], $server_url) !== 0) || (strpos($params[$img_test], '?') !== 0))
  847. if (!in_array($file_ext, $allowed_ext))
  848. {
  849. $imgba_error = true;
  850. }
  851. }
  852. if (!empty($imgba_error))
  853. {
  854. return $error;
  855. }
  856. // generate html
  857. $html = '';
  858. $html .= '<div id="' . $container . '"';
  859. foreach($params as $var => $value)
  860. {
  861. if (in_array($value, array('width', 'height')) && ($this->process_text($value) != ''))
  862. {
  863. $html .= ' ' . $var . '="' . $this->process_text($value) . '"';
  864. }
  865. }
  866. $html .= '>';
  867. $img_alt = $this->process_text($params['alt']);
  868. $img_title = (!empty($params['title']) ? ' title="' . $this->process_text($params['title']) . '"' : '');
  869. $html .= '<div><img src="' . $params['before'] . '" width="' . $params['width'] . '" height="' . $params['height'] . '" alt="Before: ' . $img_alt . '"' . $img_title . ' /></div>';
  870. $html .= '<div><img src="' . $params['after'] . '" width="' . $params['width'] . '" height="' . $params['height'] . '" alt="After: ' . $img_alt . '"' . $img_title . ' /></div>';
  871. $html .= '</div>';
  872. $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>';
  873. return array(
  874. 'valid' => true,
  875. 'html' => $html,
  876. 'allow_nested' => false,
  877. );
  878. }
  879. // ALBUMIMG
  880. if($tag === 'albumimg')
  881. {
  882. if($this->is_sig && !$config['allow_all_bbcode']) return $error;
  883. if (!empty($this->plain_html)) return $error;
  884. // main parameters
  885. $params = array(
  886. 'src' => false,
  887. 'alt' => false,
  888. );
  889. // additional allowed parameters
  890. $extras = $this->allow_styling ? array('width', 'height', 'border', 'style', 'class', 'title', 'align') : array('width', 'height', 'border', 'title', 'align');
  891. // [albumimg=blah]blah2[/albumimg]
  892. if(isset($item['params']['param']))
  893. {
  894. $params['src'] = $item['params']['param'];
  895. $pic_url = $item['params']['param'];
  896. $params['alt'] = $content;
  897. }
  898. // [albumimg src=blah alt=blah width=123][/albumimg]
  899. elseif(isset($item['params']['src']))
  900. {
  901. $params['src'] = $item['params']['src'];
  902. $pic_url = $item['params']['src'];
  903. $params['alt'] = isset($item['params']['alt']) ? $item['params']['alt'] : $content;
  904. for($i = 0; $i < sizeof($extras); $i++)
  905. {
  906. if(!empty($item['params'][$extras[$i]]))
  907. {
  908. if($extras[$i] === 'style')
  909. {
  910. $style = $this->valid_style($item['params']['style']);
  911. if($style !== false)
  912. {
  913. $params['style'] = $style;
  914. }
  915. }
  916. else
  917. {
  918. $params[$extras[$i]] = $item['params'][$extras[$i]];
  919. }
  920. }
  921. }
  922. }
  923. // [albumimg]blah[/albumimg], [albumimg width=blah]blah[/albumimg]
  924. elseif(!empty($content))
  925. {
  926. $params['src'] = $content;
  927. $pic_url = $content;
  928. $params['alt'] = isset($item['params']['alt']) ? $item['params']['alt'] : (isset($params['title']) ? $params['title'] : '');
  929. for($i = 0; $i < sizeof($extras); $i++)
  930. {
  931. if(!empty($item['params'][$extras[$i]]))
  932. {
  933. if($extras[$i] === 'style')
  934. {
  935. $style = $this->valid_style($item['params']['style']);
  936. if($style !== false)
  937. {
  938. $params['style'] = $style;
  939. }
  940. }
  941. else
  942. {
  943. $params[$extras[$i]] = $item['params'][$extras[$i]];
  944. }
  945. }
  946. }
  947. }
  948. // generate html
  949. $pic_url = $server_url . 'album_showpage.' . PHP_EXT . '?pic_id=' . $pic_url;
  950. if(isset($item['params']['mode']))
  951. {
  952. $pic_mode = $item['params']['mode'];
  953. if ($pic_mode === 'full')
  954. {
  955. $params['src'] = $server_url . 'album_picm.' . PHP_EXT . '?pic_id=' . $params['src'];
  956. }
  957. else
  958. {
  959. $params['src'] = $server_url . 'album_thumbnail.' . PHP_EXT . '?pic_id=' . $params['src'];
  960. }
  961. }
  962. else
  963. {
  964. $params['src'] = $server_url . 'album_thumbnail.' . PHP_EXT . '?pic_id=' . $params['src'];
  965. }
  966. $html = '<img';
  967. foreach($params as $var => $value)
  968. {
  969. $html .= ' ' . $var . '="' . $this->process_text($value) . '"';
  970. if (($var == 'src') && (!$this->is_sig))
  971. {
  972. $meta_content['og_img'][] = $value;
  973. }
  974. }
  975. if(!isset($params['title']))
  976. {
  977. $html .= ' title="' . $this->process_text($params['alt']) . '"';
  978. }
  979. $html .= ' />';
  980. // add url
  981. if(empty($item['inurl']))
  982. {
  983. $html = '<a href="' . $this->process_text($pic_url) . '" title="' . $lang['Click_enlarge_pic'] . '">' . $html . '</a>';
  984. }
  985. return array(
  986. 'valid' => true,
  987. 'html' => $html,
  988. 'allow_nested' => false,
  989. );
  990. }
  991. // ATTACHMENT
  992. if(($tag === 'attachment') || ($tag === 'download'))
  993. {
  994. if($this->is_sig && !$config['allow_all_bbcode']) return $error;
  995. if (!empty($this->plain_html)) return $error;
  996. $html = '';
  997. $params['id'] = isset($item['params']['param']) ? intval($item['params']['param']) : (isset($item['params']['id']) ? intval($item['params']['id']) : false);
  998. $params['title'] = isset($item['params']['title']) ? $this->process_text($item['params']['title']) : false;
  999. $params['description'] = isset($item['params']['description']) ? $this->process_text($item['params']['description']) : (!empty($content) ? $this->process_text($content) : false);
  1000. $params['icon'] = isset($item['params']['icon']) ? $this->process_text($item['params']['icon']) : false;
  1001. $color = $this->valid_color(isset($item['params']['color']) ? $item['params']['color'] : false);
  1002. $bgcolor = $this->valid_color(isset($item['params']['bgcolor']) ? $item['params']['bgcolor'] : false);
  1003. $errored = false;
  1004. if ($params['id'] <= 0)
  1005. {
  1006. $errored = true;
  1007. }
  1008. if (!$errored)
  1009. {
  1010. if ($tag === 'attachment')
  1011. {
  1012. if (!function_exists('get_attachment_details'))
  1013. {
  1014. include_once(IP_ROOT_PATH . 'includes/functions_bbcode.' . PHP_EXT);
  1015. }
  1016. $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $user->data);
  1017. $is_download_auth_ary = auth(AUTH_DOWNLOAD, AUTH_LIST_ALL, $user->data);
  1018. $attachment_details = get_attachment_details($params['id']);
  1019. if (($attachment_details == false) || !$is_auth_ary[$attachment_details['forum_id']]['auth_read'] || !$is_download_auth_ary[$attachment_details['forum_id']]['auth_download'])
  1020. {
  1021. $errored = true;
  1022. }
  1023. }
  1024. else
  1025. {
  1026. if (!function_exists('get_download_details'))
  1027. {
  1028. include_once(IP_ROOT_PATH . 'includes/functions_bbcode.' . PHP_EXT);
  1029. }
  1030. $attachment_details = get_download_details($params['id']);
  1031. $errored = ($attachment_details == false) ? true : false;
  1032. }
  1033. }
  1034. if (!$errored)
  1035. {
  1036. if ($tag === 'attachment')
  1037. {
  1038. $params['title'] = $params['title'] ? $params['title'] : (!empty($attachment_details['real_filename']) ? $attachment_details['real_filename'] : '&nbsp;');
  1039. $params['description'] = $params['description'] ? $params['description'] : (!empty($attachment_details['comment']) ? $attachment_details['comment'] : ' ');
  1040. $params['icon'] = IP_ROOT_PATH . FILES_ICONS_DIR . ($params['icon'] ? $params['icon'] : 'default.png');
  1041. $download_url = IP_ROOT_PATH . 'download.' . PHP_EXT . '?id=' . $params['id'];
  1042. }
  1043. else
  1044. {
  1045. $params['title'] = $params['title'] ? $params['title'] : (!empty($attachment_details['file_name']) ? $attachment_details['file_name'] : '&nbsp;');
  1046. $params['description'] = $params['description'] ? $params['description'] : (!empty($attachment_details['file_desc']) ? $attachment_details['file_desc'] : ' ');
  1047. $params['icon'] = IP_ROOT_PATH . FILES_ICONS_DIR . ($params['icon'] ? $params['icon'] : (!empty($attachment_details['file_posticon']) ? $attachment_details['file_posticon'] : 'default.png'));
  1048. $attachment_details['filesize'] = $attachment_details['file_size'];
  1049. $attachment_details['download_count'] = $attachment_details['file_dls'];
  1050. $download_url = IP_ROOT_PATH . 'dload.' . PHP_EXT . '?action=file&amp;file_id=' . $params['id'];
  1051. }
  1052. $params['title'] = htmlspecialchars($params['title']);
  1053. $params['description'] = htmlspecialchars($params['description']);
  1054. $params['icon'] = file_exists($params['icon']) ? $params['icon'] : (IP_ROOT_PATH . FILES_ICONS_DIR . 'default.png');
  1055. $style = ($color || $bgcolor) ? (' style="' . ($color ? 'color: ' . $color . ';' : '') . ($bgcolor ? 'background-color: ' . $bgcolor . ';' : '') . '"') : '';
  1056. $html .= '<div class="mg_attachtitle"' . $style . '>' . $params['title'] . '</div>';
  1057. $html .= '<div class="mg_attachdiv"><table>';
  1058. $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>';
  1059. $html .= '<tr><td><b class="gensmall">' . $lang['FILESIZE'] . ':</b></td><td><span class="gensmall">' . round(($attachment_details['filesize'] / 1024), 2) . ' KB</span></td></tr>';
  1060. $html .= '<tr><td><b class="gensmall">' . $lang['DOWNLOADED'] . ':</b></td><td><span class="gensmall">' . $attachment_details['download_count'] . '</span></td></tr>';
  1061. $html .= '</table></div>';
  1062. }
  1063. else
  1064. {
  1065. $style = ($color || $bgcolor) ? (' style="' . ($color ? 'color: ' . $color . ';' : '') . ($bgcolor ? 'background-color: ' . $bgcolor . ';' : '') . '"') : '';
  1066. $html .= '<div class="mg_attachtitle"' . $style . '>' . $lang['Not_Authorized'] . '</div>';
  1067. $html .= '<div class="mg_attachdiv"><div style="text-align: center;">' . $lang['FILE_NOT_AUTH'] . '</div></div>';
  1068. }
  1069. return array(
  1070. 'valid' => true,
  1071. 'html' => $html,
  1072. 'allow_nested' => false,
  1073. );
  1074. }
  1075. // LIST
  1076. if(($tag === 'list') || ($tag === 'ul') || ($tag === 'ol'))
  1077. {
  1078. if($this->is_sig && !$config['allow_all_bbcode']) return $error;
  1079. $extras = $this->allow_styling ? array('style', 'class') : array();
  1080. // check if nested tags are all [*]
  1081. $nested_count = 0;
  1082. for($i = 0; $i < sizeof($item['items']); $i++)
  1083. {
  1084. $tag2 = $item['items'][$i]['tag'];
  1085. if(($tag2 === '*') || ($tag2 === 'li'))
  1086. {
  1087. $nested_count++;
  1088. }
  1089. }
  1090. if(!$nested_count)
  1091. {
  1092. // no <li> items. return error
  1093. return $error;
  1094. }
  1095. // replace "list" with html tag
  1096. if($tag === 'list')
  1097. {
  1098. if(isset($item['params']['param']) || isset($item['params']['type']))
  1099. {
  1100. $tag = 'ol';
  1101. }
  1102. else
  1103. {
  1104. $tag = 'ul';
  1105. }
  1106. }
  1107. // valid tag. process subitems to make sure there are no extra items and remove all code between elements
  1108. $last_item = false;
  1109. for($i = 0; $i < sizeof($item['items']); $i++)
  1110. {
  1111. $item2 = &$item['items'][$i];
  1112. $tag2 = $item2['tag'];
  1113. if(($tag2 === '*') || ($tag2 === 'li'))
  1114. {
  1115. // mark as valid
  1116. $item2['list_valid'] = true;
  1117. if($last_item === false)
  1118. {
  1119. // change start position to end of [list]
  1120. $pos = !empty($pos) ? $pos : 0;
  1121. $pos2 = $item2['start'] + $item2['start_len'];
  1122. $item2['start'] = $pos;
  1123. $item2['start_len'] = $pos2 - $pos;
  1124. $item2['first_entry'] = true;
  1125. }
  1126. $last_item = &$item['items'][$i];
  1127. }
  1128. }
  1129. // generate html
  1130. $html = '<' . $tag;
  1131. if(isset($item['params']['param']))
  1132. {
  1133. $html .= ' type="' . htmlspecialchars($item['params']['param']) . '"';
  1134. }
  1135. elseif(isset($item['params']['type']))
  1136. {
  1137. $html .= ' type="' . htmlspecialchars($item['params']['type']) . '"';
  1138. }
  1139. $html .= $this->add_extras($item['params'], $extras) . '>';
  1140. return array(
  1141. 'valid' => true,
  1142. 'start' => $html,
  1143. 'end' => '</li></' . $tag . '>'
  1144. );
  1145. }
  1146. // [*], LI
  1147. if(($tag === '*') || ($tag === 'li'))
  1148. {
  1149. if($this->is_sig && !$config['allow_all_bbcode']) return $error;
  1150. $extras = $this->allow_styling ? array('style', 'class') : array();
  1151. // if not marked as valid return error
  1152. if(empty($item['list_valid']))
  1153. {
  1154. return $error;
  1155. }
  1156. $html = '<li';
  1157. if(empty($item['first_entry']))
  1158. {
  1159. // add closing tag for previous list entry
  1160. $html = '</li>' . $html;
  1161. }
  1162. $html .= $this->add_extras($item['params'], $extras) . '>';
  1163. return array(
  1164. 'valid' => true,
  1165. 'start' => $html,
  1166. 'end' => '',
  1167. );
  1168. }
  1169. // FONT
  1170. if($tag === 'font')
  1171. {
  1172. $fonts = array(
  1173. 'Arial',
  1174. 'Arial Black',
  1175. 'Comic Sans MS',
  1176. 'Courier New',
  1177. 'Impact',
  1178. 'Lucida Console',
  1179. 'Lucida Sans Unicode',
  1180. 'Microsoft Sans Serif',
  1181. 'Symbol',
  1182. 'Tahoma',
  1183. 'Times New Roman',
  1184. 'Traditional Arabic',
  1185. 'Trebuchet MS',
  1186. 'Verdana',
  1187. 'Webdings',
  1188. 'Wingdings'
  1189. );
  1190. if (defined('FONTS_DIR'))
  1191. {
  1192. foreach ($cache->obtain_fonts() as $font_file)
  1193. {
  1194. $fonts[] = substr($font_file, 0, -4);
  1195. }
  1196. }
  1197. $extras = $this->allow_styling ? array('style', 'class') : array();
  1198. $default_param = 'Verdana';
  1199. $font = (isset($item['params']['param']) ? $item['params']['param'] : (isset($item['params']['font']) ? $item['params']['font'] : $default_param));
  1200. $font = in_array($font, $fonts) ? $font : $default_param;
  1201. $html = '<span style="font-family: \'' . $font . '\';">';
  1202. return array(
  1203. 'valid' => true,
  1204. 'start' => $html,
  1205. 'end' => '</span>',
  1206. );
  1207. }
  1208. // CELL
  1209. if($tag === 'cell')
  1210. {
  1211. $extras = $this->allow_styling ? array('style', 'class', 'align', 'border') : array('class', 'align');
  1212. $width = (isset($item['params']['width']) ? (' width: ' . intval($item['params']['width']) . 'px;') : '');
  1213. $height = (isset($item['params']['height']) ? (' height: ' . intval($item['params']['height']) . 'px;') : '');
  1214. $padding = (isset($item['params']['padding']) ? (' padding: ' . intval($item['params']['padding']) . 'px;') : '');
  1215. $margin = (isset($item['params']['margin']) ? (' margin: ' . intval($item['params']['margin']) . 'px;') : '');
  1216. $borderwidth = (isset($item['params']['borderwidth']) ? (' border-width: ' . intval($item['params']['borderwidth']) . 'px;') : '');
  1217. $bgcolor = $this->valid_color((isset($item['params']['bgcolor']) ? $item['params']['bgcolor'] : false));
  1218. $bgcolor = (($bgcolor !== false) ? (' background-color: ' . $bgcolor . ';') : '');
  1219. $bordercolor = $this->valid_color((isset($item['params']['bordercolor']) ? $item['params']['bordercolor'] : false));
  1220. $bordercolor = (($bordercolor !== false) ? (' border-color: ' . $bordercolor . ';') : '');
  1221. $color = $this->valid_color((isset($item['params']['color']) ? $item['params']['color'] : false));
  1222. $color = (($color !== false) ? (' color: ' . $color . ';') : '');
  1223. $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) . '>';
  1224. return array(
  1225. 'valid' => true,
  1226. 'start' => $html,
  1227. 'end' => '</div>',
  1228. );
  1229. }
  1230. // URL, A
  1231. if(($tag === 'url') || ($tag === 'a'))
  1232. {
  1233. $extras = $this->allow_styling ? array('style', 'class', 'name', 'title') : array('name', 'title');
  1234. $allow_nested = true;
  1235. $strip_text = false;
  1236. $show_content = true;
  1237. $url = '';
  1238. // get url
  1239. if(!empty($item['params']['param']))
  1240. {
  1241. $url = $item['params']['param'];
  1242. }
  1243. elseif(!empty($item['params']['href']))
  1244. {
  1245. $url = $item['params']['href'];
  1246. }
  1247. elseif(!$item['is_html'])
  1248. {
  1249. $url = $content;
  1250. $allow_nested = false;
  1251. $strip_text = true;
  1252. }
  1253. else
  1254. {
  1255. return $error;
  1256. }
  1257. if(($url === $content) && (strlen($content) > 64))
  1258. {
  1259. $content = htmlspecialchars(substr($content, 0, 35) . '...' . substr($content, strlen($content) - 15));
  1260. $show_content = false;
  1261. }
  1262. // check if its email
  1263. if(substr(strtolower($url), 0, 7) === 'mailto:')
  1264. {
  1265. $item['tag'] = 'email';
  1266. return $this->process_tag($item);
  1267. }
  1268. // check for invalid urls
  1269. $url = $this->valid_url($url, '');
  1270. if(empty($url))
  1271. {
  1272. return $error;
  1273. }
  1274. // check nested items
  1275. if(!$allow_nested)
  1276. {
  1277. for($i = 0; $i < sizeof($item['items']); $i+

Large files files are truncated, but you can click here to view the full file