Guest User

parse.class

a guest
Mar 28th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 58.68 KB | None | 0 0
  1. <?php
  2. /*
  3. =====================================================
  4. DataLife Engine - by SoftNews Media Group
  5. -----------------------------------------------------
  6. http://dle-news.ru/
  7. -----------------------------------------------------
  8. Copyright (c) 2004,2015 SoftNews Media Group
  9. =====================================================
  10. Данный код защищен авторскими правами
  11. =====================================================
  12. Файл: parse.class.php
  13. -----------------------------------------------------
  14. Назначение: Класс парсера текста
  15. =====================================================
  16. */
  17.  
  18. if( ! defined( 'DATALIFEENGINE' ) ) {
  19. die( "Hacking attempt!" );
  20. }
  21.  
  22. class ParseFilter {
  23. var $tagsArray;
  24. var $attrArray;
  25. var $tagsMethod;
  26. var $attrMethod;
  27. var $xssAuto;
  28. var $video_config = array ();
  29. var $code_text = array ();
  30. var $code_count = 0;
  31. var $frame_code = array ();
  32. var $codes_param = array ();
  33. var $frame_count = 0;
  34. var $wysiwyg = false;
  35. var $safe_mode = false;
  36. var $allow_code = true;
  37. var $leech_mode = false;
  38. var $filter_mode = true;
  39. var $allow_url = true;
  40. var $allow_image = true;
  41. var $edit_mode = true;
  42. var $allowbbcodes = true;
  43. var $not_allowed_tags = false;
  44. var $not_allowed_text = false;
  45. var $allowed_domains = array("vkontakte.ru", "ok.ru", "vk.com", "youtube.com", "maps.google.ru", "maps.google.com", "player.vimeo.com", "facebook.com", "mover.uz", "v.kiwi.kz", "dailymotion.com", "bing.com", "ustream.tv", "w.soundcloud.com", "coveritlive.com", "video.yandex.ru", "player.rutv.ru", "promodj.com", "rutube.ru", "skydrive.live.com", "docs.google.com", "api.video.mail.ru", "megogo.net", "mapsengine.google.com", "google.com", "videoapi.my.mail.ru");
  46. var $tagBlacklist = array ('applet', 'body', 'bgsound', 'base', 'basefont', 'frame', 'frameset', 'head', 'html', 'id', 'ilayer', 'layer', 'link', 'meta', 'name', 'script', 'style', 'title', 'xml' );
  47. var $attrBlacklist = array ('action', 'background', 'codebase', 'dynsrc', 'lowsrc', 'data' );
  48.  
  49. var $font_sizes = array (1 => '8', 2 => '10', 3 => '12', 4 => '14', 5 => '18', 6 => '24', 7 => '36' );
  50.  
  51. function __construct($tagsArray = array(), $attrArray = array(), $tagsMethod = 0, $attrMethod = 0, $xssAuto = 1) {
  52. for($i = 0; $i < count( $tagsArray ); $i ++)
  53. $tagsArray[$i] = strtolower( $tagsArray[$i] );
  54. for($i = 0; $i < count( $attrArray ); $i ++)
  55. $attrArray[$i] = strtolower( $attrArray[$i] );
  56. $this->tagsArray = ( array ) $tagsArray;
  57. $this->attrArray = ( array ) $attrArray;
  58. $this->tagsMethod = $tagsMethod;
  59. $this->attrMethod = $attrMethod;
  60. $this->xssAuto = $xssAuto;
  61. }
  62. function process($source) {
  63.  
  64. if( function_exists( "get_magic_quotes_gpc" ) && get_magic_quotes_gpc() ) $source = stripslashes( $source );
  65.  
  66. $source = str_ireplace( "{include", "&#123;include", $source );
  67. $source = str_ireplace( "{content", "&#123;content", $source );
  68. $source = str_ireplace( "{custom", "&#123;custom", $source );
  69.  
  70. $source = $this->remove( $this->decode( $source ) );
  71.  
  72. if( $this->code_count ) {
  73. foreach ( $this->code_text as $key_find => $key_replace ) {
  74. $find[] = $key_find;
  75. $replace[] = $key_replace;
  76. }
  77.  
  78. $source = str_replace( $find, $replace, $source );
  79. }
  80.  
  81. $this->code_count = 0;
  82. $this->code_text = array ();
  83.  
  84. $source = preg_replace( "#<script#i", "&lt;script", $source );
  85.  
  86. if ( !$this->safe_mode ) {
  87. $source = preg_replace_callback( "#<iframe(.+?)src=['\"](.+?)['\"](.*?)>(.*?)</iframe>#is", array( &$this, 'check_frame'), $source );
  88. }
  89.  
  90. $source = str_ireplace( "<iframe", "&lt;iframe", $source );
  91. $source = str_ireplace( "</iframe>", "&lt;/iframe&gt;", $source );
  92. $source = str_replace( "<?", "&lt;?", $source );
  93. $source = str_replace( "?>", "?&gt;", $source );
  94.  
  95. $source = addslashes( $source );
  96. return $source;
  97.  
  98. }
  99. function remove($source) {
  100. $loopCounter = 0;
  101.  
  102. $var = $this->filterTags( $source );
  103.  
  104. while ( $source != $var ) {
  105. $source = $var;
  106. $var = $this->filterTags( $var );
  107. $loopCounter ++;
  108. if( $loopCounter > 50 ) { $source = ""; $var = ""; break; }
  109.  
  110. }
  111.  
  112. return $source;
  113. }
  114. function filterTags($source) {
  115. $preTag = NULL;
  116. $postTag = $source;
  117. $tagOpen_start = strpos( $source, '<' );
  118. while ( $tagOpen_start !== FALSE ) {
  119. $preTag .= substr( $postTag, 0, $tagOpen_start );
  120. $postTag = substr( $postTag, $tagOpen_start );
  121. $fromTagOpen = substr( $postTag, 1 );
  122. $tagOpen_end = strpos( $fromTagOpen, '>' );
  123. if( $tagOpen_end === false ) {
  124. $postTag = "&lt;".substr( $postTag, 1 );
  125. break;
  126. }
  127. $tagOpen_nested = strpos( $fromTagOpen, '<' );
  128. if( ($tagOpen_nested !== false) && ($tagOpen_nested < $tagOpen_end) ) {
  129. $preTag .= "&lt;".substr( $postTag, 1, ($tagOpen_nested) );
  130. $postTag = substr( $postTag, ($tagOpen_nested + 1) );
  131. $tagOpen_start = strpos( $postTag, '<' );
  132. continue;
  133. }
  134. $tagOpen_nested = (strpos( $fromTagOpen, '<' ) + $tagOpen_start + 1);
  135.  
  136. $currentTag = substr( $fromTagOpen, 0, $tagOpen_end );
  137. $tagLength = strlen( $currentTag );
  138. if( ! $tagOpen_end ) {
  139. $preTag .= $postTag;
  140. $tagOpen_start = strpos( $postTag, '<' );
  141. }
  142. $tagLeft = $currentTag;
  143. $attrSet = array ();
  144. $currentSpace = strpos( $tagLeft, ' ' );
  145. if( substr( $currentTag, 0, 1 ) == "/" ) {
  146. $isCloseTag = TRUE;
  147. list ( $tagName ) = explode( ' ', $currentTag );
  148. $tagName = substr( $tagName, 1 );
  149. } else {
  150. $isCloseTag = FALSE;
  151. list ( $tagName ) = explode( ' ', $currentTag );
  152. }
  153. if( (! preg_match( "/^[a-z][a-z0-9]*$/i", $tagName )) || (! $tagName) || ((in_array( strtolower( $tagName ), $this->tagBlacklist )) && ($this->xssAuto)) ) {
  154. $postTag = substr( $postTag, ($tagLength + 2) );
  155. $tagOpen_start = strpos( $postTag, '<' );
  156. continue;
  157. }
  158.  
  159. $tagLeft = preg_replace( '/\s+/', ' ', $tagLeft);
  160. $tagLeft = preg_replace("/=\s+/", "=", $tagLeft);
  161. $tagLeft = preg_replace("/\s+=/", "=", $tagLeft);
  162.  
  163. while ( $currentSpace !== FALSE ) {
  164. $fromSpace = substr( $tagLeft, ($currentSpace + 1) );
  165. $nextSpace = strpos( $fromSpace, ' ' );
  166. $openQuotes = strpos( $fromSpace, '"' );
  167. $closeQuotes = strpos( substr( $fromSpace, ($openQuotes + 1) ), '"' ) + $openQuotes + 1;
  168.  
  169. if( strpos( $fromSpace, '=' ) !== FALSE AND $nextSpace > $openQuotes) {
  170. if( ($openQuotes !== FALSE) && (strpos( substr( $fromSpace, ($openQuotes + 1) ), '"' ) !== FALSE) ) $attr = substr( $fromSpace, 0, ($closeQuotes + 1) );
  171. else $attr = substr( $fromSpace, 0, $nextSpace );
  172. } else
  173. $attr = substr( $fromSpace, 0, $nextSpace );
  174.  
  175. if( ! $attr ) $attr = $fromSpace;
  176. $attrSet[] = $attr;
  177. $tagLeft = substr( $fromSpace, strlen( $attr ) );
  178. $currentSpace = strpos( $tagLeft, ' ' );
  179. }
  180.  
  181. $tagFound = in_array( strtolower( $tagName ), $this->tagsArray );
  182. if( (! $tagFound && $this->tagsMethod) || ($tagFound && ! $this->tagsMethod) ) {
  183. if( ! $isCloseTag ) {
  184. $attrSet = $this->filterAttr( $attrSet, strtolower( $tagName ) );
  185. $preTag .= '<' . $tagName;
  186. for($i = 0; $i < count( $attrSet ); $i ++)
  187. $preTag .= ' ' . $attrSet[$i];
  188. if( strpos( $fromTagOpen, "</" . $tagName ) ) $preTag .= '>';
  189. else $preTag .= ' />';
  190. } else
  191. $preTag .= '</' . $tagName . '>';
  192. }
  193. $postTag = substr( $postTag, ($tagLength + 2) );
  194. $tagOpen_start = strpos( $postTag, '<' );
  195. }
  196. $preTag .= $postTag;
  197. return $preTag;
  198. }
  199.  
  200. function filterAttr($attrSet, $tagName) {
  201.  
  202. global $config;
  203.  
  204. $newSet = array ();
  205. for($i = 0; $i < count( $attrSet ); $i ++) {
  206. if( ! $attrSet[$i] ) continue;
  207.  
  208. $attrSet[$i] = trim( $attrSet[$i] );
  209.  
  210. $exp = strpos( $attrSet[$i], '=' );
  211. if( $exp === false ) $attrSubSet = Array ($attrSet[$i] );
  212. else {
  213. $attrSubSet = Array ();
  214. $attrSubSet[] = substr( $attrSet[$i], 0, $exp );
  215. $attrSubSet[] = substr( $attrSet[$i], $exp + 1 );
  216. $attrSubSet[1] = stripslashes( $attrSubSet[1] );
  217. }
  218.  
  219. list ( $attrSubSet[0] ) = explode( ' ', $attrSubSet[0] );
  220.  
  221. $attrSubSet[0] = strtolower( $attrSubSet[0] );
  222.  
  223. if( (! preg_match( "/^[a-z\-]*$/i", $attrSubSet[0] )) || (($this->xssAuto) && ((in_array( $attrSubSet[0], $this->attrBlacklist )) || (substr( $attrSubSet[0], 0, 2 ) == 'on'))) ) continue;
  224. if( $attrSubSet[1] ) {
  225. $attrSubSet[1] = str_replace( '&#', '', $attrSubSet[1] );
  226.  
  227. if ( strtolower($config['charset']) == "utf-8") $attrSubSet[1] = preg_replace( '/\s+/u', ' ', $attrSubSet[1] );
  228. else $attrSubSet[1] = preg_replace( '/\s+/', ' ', $attrSubSet[1] );
  229.  
  230. $attrSubSet[1] = str_replace( '"', '', $attrSubSet[1] );
  231. if( (substr( $attrSubSet[1], 0, 1 ) == "'") && (substr( $attrSubSet[1], (strlen( $attrSubSet[1] ) - 1), 1 ) == "'") ) $attrSubSet[1] = substr( $attrSubSet[1], 1, (strlen( $attrSubSet[1] ) - 2) );
  232. }
  233.  
  234. if( ((strpos( strtolower( $attrSubSet[1] ), 'expression' ) !== false) && ($attrSubSet[0] == 'style')) || (strpos( strtolower( $attrSubSet[1] ), 'javascript:' ) !== false) || (strpos( strtolower( $attrSubSet[1] ), 'behaviour:' ) !== false) || (strpos( strtolower( $attrSubSet[1] ), 'vbscript:' ) !== false) || (strpos( strtolower( $attrSubSet[1] ), 'mocha:' ) !== false) || (strpos( strtolower( $attrSubSet[1] ), 'data:' ) !== false and $attrSubSet[0] == "href") || (strpos( strtolower( $attrSubSet[1] ), 'data:' ) !== false and $attrSubSet[0] == "data") || (strpos( strtolower( $attrSubSet[1] ), 'data:' ) !== false and $attrSubSet[0] == "src") || ($attrSubSet[0] == "href" and @strpos( strtolower( $attrSubSet[1] ), $config['admin_path'] ) !== false and preg_match( "/[?&%<\[\]]/", $attrSubSet[1] )) || (strpos( strtolower( $attrSubSet[1] ), 'livescript:' ) !== false) ) continue;
  235.  
  236. $attrFound = in_array( $attrSubSet[0], $this->attrArray );
  237. if( (! $attrFound && $this->attrMethod) || ($attrFound && ! $this->attrMethod) ) {
  238. if( $attrSubSet[1] ) $newSet[] = $attrSubSet[0] . '="' . $attrSubSet[1] . '"';
  239. elseif( $attrSubSet[1] == "0" ) $newSet[] = $attrSubSet[0] . '="0"';
  240. elseif( isset($attrSubSet[1]) ) $newSet[] = $attrSubSet[0] . '=""';
  241. else $newSet[] = $attrSubSet[0];
  242. }
  243. }
  244.  
  245. return $newSet;
  246. }
  247.  
  248. function decode($source) {
  249. global $config;
  250.  
  251. if( $this->allow_code AND $this->allowbbcodes)
  252. $source = preg_replace_callback( "#\[code\](.+?)\[/code\]#is", array( &$this, 'code_tag'), $source );
  253.  
  254. if( $this->safe_mode AND !$this->wysiwyg ) {
  255.  
  256. $source = htmlspecialchars( $source, ENT_QUOTES, $config['charset'] );
  257. $source = str_replace( '&amp;', '&', $source );
  258.  
  259. } else {
  260.  
  261. $source = str_replace( "<>", "&lt;&gt;", str_replace( ">>", "&gt;&gt;", str_replace( "<<", "&lt;&lt;", $source ) ) );
  262. $source = str_replace( "<!--", "&lt;!--", $source );
  263.  
  264. }
  265.  
  266. return $source;
  267. }
  268.  
  269. function BB_Parse($source, $use_html = TRUE) {
  270.  
  271. global $config, $lang;
  272.  
  273. $find = array ('/data:/i', '/about:/i', '/vbscript:/i', '/onclick/i', '/onload/i', '/onunload/i', '/onabort/i', '/onerror/i', '/onblur/i', '/onchange/i', '/onfocus/i', '/onreset/i', '/onsubmit/i', '/ondblclick/i', '/onkeydown/i', '/onkeypress/i', '/onkeyup/i', '/onmousedown/i', '/onmouseup/i', '/onmouseover/i', '/onmouseout/i', '/onselect/i', '/javascript/i', '/onmouseenter/i', '/onwheel/i', '/onshow/i');
  274.  
  275. $replace = array ("d&#097;ta:", "&#097;bout:", "vbscript<b></b>:", "&#111;nclick", "&#111;nload", "&#111;nunload", "&#111;nabort", "&#111;nerror", "&#111;nblur", "&#111;nchange", "&#111;nfocus", "&#111;nreset", "&#111;nsubmit", "&#111;ndblclick", "&#111;nkeydown", "&#111;nkeypress", "&#111;nkeyup", "&#111;nmousedown", "&#111;nmouseup", "&#111;nmouseover", "&#111;nmouseout", "&#111;nselect", "j&#097;vascript", '&#111;nmouseenter', '&#111;nwheel', '&#111;nshow');
  276.  
  277. if( $use_html == false ) {
  278. $find[] = "'\r'";
  279. $replace[] = "";
  280. $find[] = "'\n'";
  281. $replace[] = "<br />";
  282. } else {
  283. $source = str_replace( "\r\n\r\n", "\n", $source );
  284. }
  285.  
  286. $smilies_arr = explode( ",", $config['smilies'] );
  287. foreach ( $smilies_arr as $smile ) {
  288. $smile = trim( $smile );
  289. $find[] = "':$smile:'";
  290. $replace[] = "<!--smile:{$smile}--><img style=\"vertical-align: middle;border: none;\" alt=\"$smile\" src=\"" . $config['http_home_url'] . "engine/data/emoticons/{$smile}.gif\" /><!--/smile-->";
  291. }
  292.  
  293. if( $this->filter_mode ) $source = $this->word_filter( $source );
  294.  
  295. $source = preg_replace( $find, $replace, $source );
  296. $source = preg_replace( "#<iframe#i", "&lt;iframe", $source );
  297. $source = preg_replace( "#<script#i", "&lt;script", $source );
  298.  
  299. $source = str_replace( "`", "&#96;", $source );
  300. $source = str_ireplace( "{THEME}", "&#123;THEME}", $source );
  301. $source = str_ireplace( "{comments}", "&#123;comments}", $source );
  302. $source = str_ireplace( "{addcomments}", "&#123;addcomments}", $source );
  303. $source = str_ireplace( "{navigation}", "&#123;navigation}", $source );
  304. $source = str_ireplace( "[declination", "&#91;declination", $source );
  305.  
  306. $source = str_replace( "<?", "&lt;?", $source );
  307. $source = str_replace( "?>", "?&gt;", $source );
  308.  
  309. if ($config['parse_links']) {
  310. $source = preg_replace("#(^|\s|>)((http|https|ftp)://\w+[^\s\[\]\<]+)#i", '\\1[url]\\2[/url]', $source);
  311. }
  312.  
  313. $count_start = substr_count ($source, "[quote");
  314. $count_end = substr_count ($source, "[/quote]");
  315.  
  316. if ($count_start AND $count_start == $count_end) {
  317. $source = str_ireplace( "[quote=]", "[quote]", $source );
  318.  
  319. if ( !$this->allow_code ) {
  320. $source = preg_replace_callback( "#\[(quote)\](.+?)\[/quote\]#is", array( &$this, 'clear_div_tag'), $source );
  321. $source = preg_replace_callback( "#\[(quote)=(.+?)\](.+?)\[/quote\]#is", array( &$this, 'clear_div_tag'), $source );
  322. }
  323.  
  324. while( preg_match( "#\[quote\](.+?)\[/quote\]#is", $source ) ) {
  325. $source = preg_replace( "#\[quote\](.+?)\[/quote\]#is", "<!--QuoteBegin--><div class=\"quote\"><!--QuoteEBegin-->\\1<!--QuoteEnd--></div><!--QuoteEEnd-->", $source );
  326. }
  327.  
  328. while( preg_match( "#\[quote=([^\]|\[|<]+)\](.+?)\[/quote\]#is", $source ) ) {
  329. $source = preg_replace( "#\[quote=([^\]|\[|<]+)\](.+?)\[/quote\]#is", "<!--QuoteBegin \\1 --><div class=\"title_quote\">{$lang['i_quote']} \\1</div><div class=\"quote\"><!--QuoteEBegin-->\\2<!--QuoteEnd--></div><!--QuoteEEnd-->", $source );
  330. }
  331. }
  332.  
  333. if ( $this->allowbbcodes ) {
  334.  
  335. $count_start = substr_count ($source, "[spoiler");
  336. $count_end = substr_count ($source, "[/spoiler]");
  337.  
  338. if ($count_start AND $count_start == $count_end) {
  339. $source = str_ireplace( "[spoiler=]", "[spoiler]", $source );
  340.  
  341. if ( !$this->allow_code ) {
  342. $source = preg_replace_callback( "#\[(spoiler)\](.+?)\[/spoiler\]#is", array( &$this, 'clear_div_tag'), $source );
  343. $source = preg_replace_callback( "#\[(spoiler)=(.+?)\](.+?)\[/spoiler\]#is", array( &$this, 'clear_div_tag'), $source );
  344. }
  345. while( preg_match( "#\[spoiler\](.+?)\[/spoiler\]#is", $source ) ) {
  346. $source = preg_replace_callback( "#\[spoiler\](.+?)\[/spoiler\]#is", array( &$this, 'build_spoiler'), $source );
  347. }
  348.  
  349. while( preg_match( "#\[spoiler=([^\]|\[|<]+)\](.+?)\[/spoiler\]#is", $source ) ) {
  350. $source = preg_replace_callback( "#\[spoiler=([^\]|\[|<]+)\](.+?)\[/spoiler\]#is", array( &$this, 'build_spoiler'), $source);
  351. }
  352.  
  353. }
  354.  
  355. $source = preg_replace( "#\[code\](.+?)\[/code\]#is", "<pre><code>\\1</code></pre>", $source );
  356.  
  357. if ( !$this->allow_code AND $this->edit_mode) {
  358. $source = preg_replace_callback( "#<pre><code>(.+?)</code></pre>#is", array( &$this, 'clear_p_tag'), $source );
  359. }
  360.  
  361. $source = preg_replace( "#\[(left|right|center|justify)\](.+?)\[/\\1\]#is", "<div style=\"text-align:\\1;\">\\2</div>", $source );
  362.  
  363. while( preg_match( "#\[(b|i|s|u|sub|sup)\](.+?)\[/\\1\]#is", $source ) ) {
  364. $source = preg_replace( "#\[(b|i|s|u|sub|sup)\](.+?)\[/\\1\]#is", "<\\1>\\2</\\1>", $source );
  365. }
  366.  
  367. if( $this->allow_url ) {
  368.  
  369. $source = preg_replace_callback( "#\[(url)\](\S.+?)\[/url\]#i", array( &$this, 'build_url'), $source );
  370. $source = preg_replace_callback( "#\[(url)\s*=\s*\&quot\;\s*(\S+?)\s*\&quot\;\s*\](.*?)\[\/url\]#i", array( &$this, 'build_url'), $source );
  371. $source = preg_replace_callback( "#\[(url)\s*=\s*(\S.+?)\s*\](.*?)\[\/url\]#i", array( &$this, 'build_url'), $source );
  372.  
  373. $source = preg_replace_callback( "#\[(leech)\](\S.+?)\[/leech\]#i", array( &$this, 'build_url'), $source );
  374. $source = preg_replace_callback( "#\[(leech)\s*=\s*\&quot\;\s*(\S+?)\s*\&quot\;\s*\](.*?)\[\/leech\]#i", array( &$this, 'build_url'), $source );
  375. $source = preg_replace_callback( "#\[(leech)\s*=\s*(\S.+?)\s*\](.*?)\[\/leech\]#i", array( &$this, 'build_url'), $source );
  376.  
  377. } else {
  378.  
  379. if( stristr( $source, "[url" ) !== false ) $this->not_allowed_tags = true;
  380. if( stristr( $source, "[leech" ) !== false ) $this->not_allowed_tags = true;
  381. if( stristr( $source, "&lt;a" ) !== false ) $this->not_allowed_tags = true;
  382.  
  383. }
  384.  
  385. if( $this->allow_image ) {
  386.  
  387. $source = preg_replace_callback( "#\[img\](.+?)\[/img\]#i", array( &$this, 'build_image'), $source );
  388. $source = preg_replace_callback( "#\[img=(.+?)\](.+?)\[/img\]#i", array( &$this, 'build_image'), $source );
  389.  
  390. } else {
  391.  
  392. if( stristr( $source, "[img" ) !== false ) $this->not_allowed_tags = true;
  393. if( stristr( $source, "&lt;img" ) !== false ) $this->not_allowed_tags = true;
  394.  
  395. }
  396.  
  397. $source = preg_replace_callback( "#\[email\s*=\s*\&quot\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\&quot\;\s*\](.*?)\[\/email\]#i", array( &$this, 'build_email'), $source );
  398. $source = preg_replace_callback( "#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i", array( &$this, 'build_email'), $source );
  399.  
  400. if( ! $this->safe_mode ) {
  401.  
  402. $source = preg_replace_callback( "'\[thumb\](.+?)\[/thumb\]'i", array( &$this, 'build_thumb'), $source );
  403. $source = preg_replace_callback( "'\[thumb=(.+?)\](.+?)\[/thumb\]'i", array( &$this, 'build_thumb'), $source );
  404. $source = preg_replace_callback( "'\[medium\](.+?)\[/medium\]'i", array( &$this, 'build_medium'), $source );
  405. $source = preg_replace_callback( "'\[medium=(.+?)\](.+?)\[/medium\]'i", array( &$this, 'build_medium'), $source );
  406. $source = preg_replace_callback( "#\[video\s*=\s*(\S.+?)\s*\]#i", array( &$this, 'build_video'), $source );
  407. $source = preg_replace_callback( "#\[audio\s*=\s*(\S.+?)\s*\]#i", array( &$this, 'build_audio'), $source );
  408. $source = preg_replace_callback( "#\[flash=([^\]]+)\](.+?)\[/flash\]#i", array( &$this, 'build_flash'), $source );
  409. $source = preg_replace_callback( "#\[media=([^\]]+)\]#i", array( &$this, 'build_media'), $source );
  410.  
  411. $source = preg_replace_callback( "#\[ol=([^\]]+)\]\[\*\]#is", array( &$this, 'build_list'), $source );
  412. $source = preg_replace_callback( "#\[ol=([^\]]+)\](.+?)\[\*\]#is", array( &$this, 'build_list'), $source );
  413. $source = str_ireplace("[list][*]", "<!--dle_list--><ul><li>", $source);
  414. $source = preg_replace( "#\[list\](.+?)\[\*\]#is", "<!--dle_list--><ul><li>", $source );
  415. $source = str_replace("[*]", "</li><!--dle_li--><li>", $source);
  416. $source = str_ireplace("[/list]", "</li></ul><!--dle_list_end-->", $source);
  417. $source = str_ireplace("[/ol]", "</li></ol><!--dle_list_end-->", $source);
  418.  
  419. $source = preg_replace_callback( "#\[(size)=([^\]]+)\]#i", array( &$this, 'font_change'), $source );
  420. $source = preg_replace_callback( "#\[(font)=([^\]]+)\]#i", array( &$this, 'font_change'), $source );
  421. $source = str_ireplace("[/size]", "<!--sizeend--></span><!--/sizeend-->", $source);
  422. $source = str_ireplace("[/font]", "<!--fontend--></span><!--/fontend-->", $source);
  423.  
  424. while( preg_match( "#\[h([1-6]{1})\](.+?)\[/h\\1\]#is", $source ) ) {
  425. $source = preg_replace( "#\[h([1-6]{1})\](.+?)\[/h\\1\]#is", "<h\\1>\\2</h\\1>", $source );
  426. }
  427.  
  428. if( $this->frame_count ) {
  429. $find=array();$replace=array();
  430. foreach ( $this->frame_code as $key_find => $key_replace ) {
  431. $find[] = $key_find;
  432. $replace[] = $key_replace;
  433. }
  434.  
  435. $source = str_replace( $find, $replace, $source );
  436. }
  437. }
  438.  
  439. $source = preg_replace_callback( "#\[(color)=([^\]]+)\]#i", array( &$this, 'font_change'), $source );
  440.  
  441. $source = str_ireplace("[/color]", "<!--colorend--></span><!--/colorend-->", $source);
  442.  
  443. $source = str_replace( "__CODENR__", "\r", $source );
  444. $source = str_replace( "__CODENN__", "\n", $source );
  445.  
  446. }
  447.  
  448. return trim( $source );
  449.  
  450. }
  451.  
  452. function decodeBBCodes($txt, $use_html = TRUE, $wysiwig = false) {
  453.  
  454. global $config;
  455.  
  456. $find = array ();
  457. $result = array ();
  458. $txt = stripslashes( $txt );
  459. if( $this->filter_mode ) $txt = $this->word_filter( $txt, false );
  460.  
  461. $txt = str_ireplace( "&#123;THEME}", "{THEME}", $txt );
  462. $txt = str_ireplace( "&#123;comments}", "{comments}", $txt );
  463. $txt = str_ireplace( "&#123;addcomments}", "{addcomments}", $txt );
  464. $txt = str_ireplace( "&#123;navigation}", "{navigation}", $txt );
  465. $txt = str_ireplace( "&#91;declination", "[declination", $txt );
  466. $txt = str_ireplace( "&#123;include", "{include", $txt );
  467. $txt = str_ireplace( "&#123;content", "{content", $txt );
  468. $txt = str_ireplace( "&#123;custom", "{custom", $txt );
  469.  
  470. $txt = preg_replace_callback( "#<!--(TBegin|MBegin):(.+?)-->(.+?)<!--(TEnd|MEnd)-->#i", array( &$this, 'decode_thumb'), $txt );
  471. $txt = preg_replace_callback( "#<!--TBegin-->(.+?)<!--TEnd-->#i", array( &$this, 'decode_oldthumb'), $txt );
  472. $txt = preg_replace( "#<!--QuoteBegin-->(.+?)<!--QuoteEBegin-->#", '[quote]', $txt );
  473. $txt = preg_replace( "#<!--QuoteBegin ([^>]+?) -->(.+?)<!--QuoteEBegin-->#", "[quote=\\1]", $txt );
  474. $txt = preg_replace( "#<!--QuoteEnd-->(.+?)<!--QuoteEEnd-->#", '[/quote]', $txt );
  475. $txt = preg_replace( "#<!--code1-->(.+?)<!--ecode1-->#", '[code]', $txt );
  476. $txt = preg_replace( "#<!--code2-->(.+?)<!--ecode2-->#", '[/code]', $txt );
  477. $txt = preg_replace_callback( "#<!--dle_leech_begin--><a href=\"(.+?)\"(.+?)>(.+?)</a><!--dle_leech_end-->#i", array( &$this, 'decode_leech'), $txt );
  478. $txt = preg_replace( "#<!--dle_video_begin-->(.+?)src=\"(.+?)\"(.+?)<!--dle_video_end-->#is", '[video=\\2]', $txt );
  479. $txt = preg_replace( "#<!--dle_video_begin:(.+?)-->(.+?)<!--dle_video_end-->#is", '[video=\\1]', $txt );
  480. $txt = preg_replace( "#<!--dle_audio_begin:(.+?)-->(.+?)<!--dle_audio_end-->#is", '[audio=\\1]', $txt );
  481. $txt = preg_replace_callback( "#<!--dle_image_begin:(.+?)-->(.+?)<!--dle_image_end-->#is", array( &$this, 'decode_dle_img'), $txt );
  482. $txt = preg_replace( "#<!--dle_youtube_begin:(.+?)-->(.+?)<!--dle_youtube_end-->#is", '[media=\\1]', $txt );
  483. $txt = preg_replace( "#<!--dle_media_begin:(.+?)-->(.+?)<!--dle_media_end-->#is", '[media=\\1]', $txt );
  484. $txt = preg_replace_callback( "#<!--dle_flash_begin:(.+?)-->(.+?)<!--dle_flash_end-->#is", array( &$this, 'decode_flash'), $txt );
  485. $txt = preg_replace( "#<!--dle_spoiler-->(.+?)<!--spoiler_text-->#is", '[spoiler]', $txt );
  486. $txt = preg_replace( "#<!--dle_spoiler (.+?) -->(.+?)<!--spoiler_text-->#is", '[spoiler=\\1]', $txt );
  487. $txt = str_replace( "<!--spoiler_text_end--></div><!--/dle_spoiler-->", '[/spoiler]', $txt );
  488. $txt = str_replace( "<!--dle_list--><ul><li>", "[list]\n[*]", $txt );
  489. $txt = str_replace( "</li></ul><!--dle_list_end-->", '[/list]', $txt );
  490. $txt = str_replace( "</li></ol><!--dle_list_end-->", '[/ol]', $txt );
  491. $txt = str_replace( "</li><!--dle_li--><li>", '[*]', $txt );
  492. $txt = str_replace( "<pre><code>", '[code]', $txt );
  493. $txt = str_replace( "</code></pre>", '[/code]', $txt );
  494. $txt = preg_replace( "#<!--dle_ol_(.+?)-->(.+?)<!--/dle_ol-->#i", "[ol=\\1]\n[*]", $txt );
  495.  
  496. if( !$wysiwig ) {
  497.  
  498. $txt = str_replace( "<b>", "[b]", str_replace( "</b>", "[/b]", $txt ) );
  499. $txt = str_replace( "<i>", "[i]", str_replace( "</i>", "[/i]", $txt ) );
  500. $txt = str_replace( "<u>", "[u]", str_replace( "</u>", "[/u]", $txt ) );
  501. $txt = str_replace( "<s>", "[s]", str_replace( "</s>", "[/s]", $txt ) );
  502. $txt = str_replace( "<sup>", "[sup]", str_replace( "</sup>", "[/sup]", $txt ) );
  503. $txt = str_replace( "<sub>", "[sub]", str_replace( "</sub>", "[/sub]", $txt ) );
  504.  
  505. $txt = preg_replace( "#<a href=[\"']mailto:(.+?)['\"]>(.+?)</a>#i", "[email=\\1]\\2[/email]", $txt );
  506. $txt = preg_replace_callback( "#<noindex><a href=\"(.+?)\"(.+?)>(.+?)</a></noindex>#i", array( &$this, 'decode_url'), $txt );
  507. $txt = preg_replace_callback( "#<a href=\"(.+?)\"(.+?)>(.+?)</a>#i", array( &$this, 'decode_url'), $txt );
  508.  
  509. $txt = preg_replace( "#<!--sizestart:(.+?)-->(.+?)<!--/sizestart-->#", "[size=\\1]", $txt );
  510. $txt = preg_replace( "#<!--colorstart:(.+?)-->(.+?)<!--/colorstart-->#", "[color=\\1]", $txt );
  511. $txt = preg_replace( "#<!--fontstart:(.+?)-->(.+?)<!--/fontstart-->#", "[font=\\1]", $txt );
  512.  
  513. $txt = str_replace( "<!--sizeend--></span><!--/sizeend-->", "[/size]", $txt );
  514. $txt = str_replace( "<!--colorend--></span><!--/colorend-->", "[/color]", $txt );
  515. $txt = str_replace( "<!--fontend--></span><!--/fontend-->", "[/font]", $txt );
  516.  
  517. $txt = preg_replace( "#<h([1-6]{1})>(.+?)</h\\1>#is", "[h\\1]\\2[/h\\1]", $txt );
  518.  
  519. $txt = preg_replace( "#<div align=['\"](left|right|center|justify)['\"]>(.+?)</div>#is", "[\\1]\\2[/\\1]", $txt );
  520. $txt = preg_replace( "#<div style=['\"]text-align:(left|right|center|justify);['\"]>(.+?)</div>#is", "[\\1]\\2[/\\1]", $txt );
  521.  
  522.  
  523.  
  524. } else {
  525.  
  526. $txt = str_replace( "<!--sizeend--></span><!--/sizeend-->", "</span>", $txt );
  527. $txt = str_replace( "<!--colorend--></span><!--/colorend-->", "</span>", $txt );
  528. $txt = str_replace( "<!--fontend--></span><!--/fontend-->", "</span>", $txt );
  529. $txt = str_replace( "<!--/sizestart-->", "", $txt );
  530. $txt = str_replace( "<!--/colorstart-->", "", $txt );
  531. $txt = str_replace( "<!--/fontstart-->", "", $txt );
  532. $txt = preg_replace( "#<!--sizestart:(.+?)-->#", "", $txt );
  533. $txt = preg_replace( "#<!--colorstart:(.+?)-->#", "", $txt );
  534. $txt = preg_replace( "#<!--fontstart:(.+?)-->#", "", $txt );
  535.  
  536. }
  537.  
  538. $txt = preg_replace( "#<!--smile:(.+?)-->(.+?)<!--/smile-->#is", ':\\1:', $txt );
  539.  
  540. $smilies_arr = explode( ",", $config['smilies'] );
  541.  
  542. foreach ( $smilies_arr as $smile ) {
  543. $smile = trim( $smile );
  544. $replace[] = ":$smile:";
  545. $find[] = "#<img style=['\"]border: none;['\"] alt=['\"]" . $smile . "['\"] align=['\"]absmiddle['\"] src=['\"](.+?)" . $smile . ".gif['\"] />#is";
  546. }
  547.  
  548. $txt = preg_replace( $find, $replace, $txt );
  549.  
  550. if( ! $use_html ) {
  551. $txt = str_ireplace( "<br>", "\n", $txt );
  552. $txt = str_ireplace( "<br />", "\n", $txt );
  553. }
  554.  
  555. if (!$this->safe_mode AND $this->edit_mode) $txt = htmlspecialchars( $txt, ENT_QUOTES, $config['charset'] );
  556. $this->codes_param['html'] = $use_html;
  557. $this->codes_param['wysiwig'] = $wysiwig;
  558. $txt = preg_replace_callback( "#\[code\](.+?)\[/code\]#is", array( &$this, 'decode_code'), $txt );
  559.  
  560. return trim( $txt );
  561.  
  562. }
  563.  
  564. function build_list( $matches=array() ) {
  565. $type = $matches[1];
  566.  
  567. $allowed_types = array ("A", "a", "I", "i", "1");
  568.  
  569. if (in_array($type, $allowed_types))
  570. return "<!--dle_ol_{$type}--><ol type=\"{$type}\"><li><!--/dle_ol-->";
  571. else
  572. return "<!--dle_ol_1--><ol type=\"1\"><li><!--/dle_ol-->";
  573.  
  574. }
  575.  
  576. function font_change( $matches=array() ) {
  577.  
  578. $style = $matches[2];
  579. $type = $matches[1];
  580.  
  581. $style = str_replace( '&quot;', '', $style );
  582. $style = preg_replace( "/[&\(\)\.\%\[\]<>\'\"]/", "", preg_replace( "#^(.+?)(?:;|$)#", "\\1", $style ) );
  583.  
  584. if( $type == 'size' ) {
  585. $style = intval( $style );
  586.  
  587. if( $this->font_sizes[$style] ) {
  588. $real = $this->font_sizes[$style];
  589. } else {
  590. $real = 12;
  591. }
  592.  
  593. return "<!--sizestart:{$style}--><span style=\"font-size:" . $real . "pt;\"><!--/sizestart-->";
  594. }
  595.  
  596. if( $type == 'font' ) {
  597. $style = preg_replace( "/[^\d\w\#\-\_\s]/s", "", $style );
  598. return "<!--fontstart:{$style}--><span style=\"font-family:" . $style . "\"><!--/fontstart-->";
  599. }
  600.  
  601. $style = preg_replace( "/[^\d\w\#\s]/s", "", $style );
  602. return "<!--colorstart:{$style}--><span style=\"color:" . $style . "\"><!--/colorstart-->";
  603. }
  604.  
  605. function build_email( $matches=array() ) {
  606.  
  607. $matches[1] = $this->clear_url( $matches[1] );
  608.  
  609. return "<a href=\"mailto:{$matches[1]}\">{$matches[2]}</a>";
  610.  
  611. }
  612.  
  613. function build_flash( $matches=array() ) {
  614.  
  615. $size = $matches[1];
  616. $url = $matches[2];
  617. $size = explode(",", $size);
  618.  
  619. $width = trim(intval($size[0]));
  620. $height = trim(intval($size[1]));
  621.  
  622. if (!$width OR !$height) return "[flash=".implode(",",$size)."]".$url."[/flash]";
  623.  
  624. $url = $this->clear_url( urldecode( $url ) );
  625.  
  626. if( $url == "" ) return;
  627.  
  628. if( preg_match( "/[?&;<\[\]]/", $url ) ) {
  629.  
  630. return "[flash=".implode(",",$size)."]".$url."[/flash]";
  631.  
  632. }
  633.  
  634. return "<!--dle_flash_begin:{$width}||{$height}||{$url}--><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='$width' height='$height'><param name='movie' value='$url'><param name='wmode' value='transparent' /><param name='play' value='true'><param name='loop' value='true'><param name='quality' value='high'><param name='allowscriptaccess' value='never'><embed AllowScriptAccess='never' src='$url' width='$width' height='$height' play='true' loop='true' quality='high' wmode='transparent'></embed></object><!--dle_flash_end-->";
  635.  
  636.  
  637. }
  638.  
  639. function decode_flash( $matches=array() )
  640. {
  641. $url = explode( "||", $matches[1] );
  642.  
  643. return '[flash='.$url[0].','.$url[1].']'.$url[2].'[/flash]';
  644. }
  645.  
  646. function build_media( $matches=array() ) {
  647. global $config;
  648.  
  649. $url = $matches[1];
  650.  
  651. if (!count($this->video_config)) {
  652.  
  653. include (ENGINE_DIR . '/data/videoconfig.php');
  654. $this->video_config = $video_config;
  655.  
  656. }
  657.  
  658. $get_size = explode( ",", trim( $url ) );
  659. $sizes = array();
  660.  
  661. if (count($get_size) == 2) {
  662.  
  663. $url = $get_size[1];
  664. $sizes = explode( "x", trim( $get_size[0] ) );
  665.  
  666. $width = intval($sizes[0]) > 0 ? intval($sizes[0]) : $this->video_config['width'];
  667. $height = intval($sizes[1]) > 0 ? intval($sizes[1]) : $this->video_config['height'];
  668.  
  669. if (substr ( $sizes[0], - 1, 1 ) == '%') $width = $width."%";
  670. if (substr ( $sizes[1], - 1, 1 ) == '%') $height = $height."%";
  671.  
  672. } else {
  673.  
  674. $width = $this->video_config['width'];
  675. $height = $this->video_config['height'];
  676.  
  677. }
  678.  
  679. $url = $this->clear_url( urldecode( $url ) );
  680. $url = str_replace("&amp;","&", $url );
  681. $url = str_replace("&amp;","&", $url );
  682.  
  683. if( $url == "" ) return;
  684.  
  685. if ( count($get_size) == 2 ) $decode_url = $width."x".$height.",".$url;
  686. else $decode_url = $url;
  687.  
  688. $source = @parse_url ( $url );
  689.  
  690. $source['host'] = str_replace( "www.", "", strtolower($source['host']) );
  691.  
  692. if ($source['host'] != "youtube.com" AND $source['host'] != "youtu.be" AND $source['host'] != "vimeo.com" AND $source['host'] != "my.mail.ru") return "[media=".$url."]";
  693.  
  694. if ($source['host'] == "youtube.com") {
  695.  
  696. $a = explode('&', $source['query']);
  697. $i = 0;
  698.  
  699. while ($i < count($a)) {
  700. $b = explode('=', $a[$i]);
  701. if ($b[0] == "v") $video_link = htmlspecialchars($b[1], ENT_QUOTES, $config['charset']);
  702. $i++;
  703. }
  704.  
  705. }
  706.  
  707. if ($source['host'] == "youtu.be") {
  708. $video_link = str_replace( "/", "", $source['path'] );
  709. $video_link = htmlspecialchars($video_link, ENT_QUOTES, $config['charset']);
  710. }
  711.  
  712. if ($source['host'] == "youtube.com" OR $source['host'] == "youtu.be") {
  713.  
  714. if ( $this->video_config['tube_dle'] ) {
  715.  
  716. if ( count($get_size) == 2 ) $decode_url = $width."x".$height.",{$source['scheme']}://www.youtube.com/watch?v=".$video_link;
  717. else $decode_url = "{$source['scheme']}://www.youtube.com/watch?v=".$video_link;
  718.  
  719.  
  720. $id_player = md5( microtime() );
  721.  
  722. return "<!--dle_media_begin:{$decode_url}--><video width=\"{$width}\" height=\"{$height}\" preload=\"none\" controls=\"controls\">
  723. <source type=\"video/youtube\" src=\"//www.youtube.com/watch?v={$video_link}\"></source>
  724. </video><!--dle_media_end-->";
  725.  
  726. } else return '<!--dle_media_begin:'.$decode_url.'--><iframe title="YouTube video player" width="'.$width.'" height="'.$height.'" src="//www.youtube.com/embed/'.$video_link.'?rel='.intval($this->video_config['tube_related']).'&amp;wmode=transparent" frameborder="0" allowfullscreen></iframe><!--dle_media_end-->';
  727.  
  728. } elseif ($source['host'] == "vimeo.com") {
  729.  
  730. if (substr ( $source['path'], - 1, 1 ) == '/') $source['path'] = substr ( $source['path'], 0, - 1 );
  731. $a = explode('/', $source['path']);
  732. $a = end($a);
  733.  
  734. $video_link = intval( $a );
  735.  
  736. if ( count($get_size) == 2 ) $decode_url = $width."x".$height.",".$url;
  737. else $decode_url = $url;
  738.  
  739. return '<!--dle_media_begin:'.$decode_url.'--><iframe width="'.$width.'" height="'.$height.'" src="//player.vimeo.com/video/'.$video_link.'" frameborder="0" allowfullscreen></iframe><!--dle_media_end-->';
  740.  
  741. } elseif ($source['host'] == "my.mail.ru") {
  742.  
  743. $video_link = $source['path'];
  744.  
  745. if ( count($get_size) == 2 ) $decode_url = $width."x".$height.",".$url;
  746. else $decode_url = $url;
  747.  
  748. return '<!--dle_media_begin:'.$decode_url.'--><iframe src="//videoapi.my.mail.ru/videos/embed'.$video_link.'" width="'.$width.'" height="'.$height.'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe><!--dle_media_end-->';
  749.  
  750. }
  751.  
  752. }
  753.  
  754. function build_url( $matches=array() ) {
  755. global $config, $member_id, $user_group;
  756.  
  757. $url = array();
  758.  
  759. if ($matches[1] == "leech" ) $url['leech'] = 1;
  760.  
  761. $option=explode("|", $matches[2]);
  762.  
  763. $url['html'] = $option[0];
  764. $url['tooltip'] = $option[1];
  765. $url['show'] = $matches[3];
  766.  
  767. if ( !$url['show'] ) $url['show'] = $url['html'];
  768.  
  769. if ( $user_group[$member_id['user_group']]['force_leech'] ) $url['leech'] = 1;
  770.  
  771. if( preg_match( "/([\.,\?]|&#33;)$/", $url['show'], $match ) ) {
  772. $url['end'] = $match[1];
  773. $url['show'] = preg_replace( "/([\.,\?]|&#33;)$/", "", $url['show'] );
  774. }
  775.  
  776. $url['html'] = $this->clear_url( $url['html'] );
  777. $url['show'] = stripslashes( $url['show'] );
  778.  
  779. if( $this->safe_mode ) {
  780.  
  781. $url['show'] = str_replace( "&nbsp;", " ", $url['show'] );
  782.  
  783. if (strlen(trim($url['show'])) < 3 )
  784. return "[url=" . $url['html'] . "]" . $url['show'] . "[/url]";
  785.  
  786. }
  787.  
  788. if( strpos( $url['html'], $config['http_home_url'] ) !== false AND strpos( $url['html'], $config['admin_path'] ) !== false ) {
  789.  
  790. return "[url=" . $url['html'] . "]" . $url['show'] . "[/url]";
  791.  
  792. }
  793.  
  794. if( ! preg_match( "#^(http|news|https|ed2k|ftp|aim|mms)://|(magnet:?)#", $url['html'] ) AND $url['html'][0] != "/" AND $url['html'][0] != "#") {
  795. $url['html'] = 'http://' . $url['html'];
  796. }
  797.  
  798. if ($url['html'] == 'http://' )
  799. return "[url=" . $url['html'] . "]" . $url['show'] . "[/url]";
  800.  
  801. $url['show'] = str_replace( "&amp;amp;", "&amp;", $url['show'] );
  802. $url['show'] = preg_replace( "/javascript:/i", "javascript&#58; ", $url['show'] );
  803.  
  804. if( $this->check_home( $url['html'] ) OR $url['html'][0] == "/" OR $url['html'][0] == "#") $target = "";
  805. else $target = " target=\"_blank\"";
  806.  
  807. if( $url['tooltip'] ) {
  808. $url['tooltip'] = htmlspecialchars( strip_tags( stripslashes( $url['tooltip'] ) ), ENT_QUOTES, $config['charset'] );
  809.  
  810. if( $this->safe_mode ) {
  811. $url['tooltip'] = str_replace( "&amp;", "&", $url['tooltip'] );
  812. }
  813.  
  814. $target = "title=\"".$url['tooltip']."\"".$target;
  815. }
  816.  
  817. if( $url['leech'] ) {
  818.  
  819. $url['html'] = $config['http_home_url'] . "engine/go.php?url=" . rawurlencode( base64_encode( $url['html'] ) );
  820.  
  821. return "<!--dle_leech_begin--><a href=\"" . $url['html'] . "\" " . $target . ">" . $url['show'] . "</a><!--dle_leech_end-->" . $url['end'];
  822.  
  823. } else {
  824.  
  825. if ($this->safe_mode AND !$config['allow_search_link'] AND $target)
  826. return "<a href=\"" . $url['html'] . "\" " . $target . " rel=\"nofollow\">" . $url['show'] . "</a>" . $url['end'];
  827. else
  828. return "<a href=\"" . $url['html'] . "\" " . $target . ">" . $url['show'] . "</a>" . $url['end'];
  829.  
  830. }
  831.  
  832. }
  833.  
  834. function code_tag( $matches=array() ) {
  835.  
  836. $txt = $matches[1];
  837.  
  838. if( $txt == "" ) {
  839. return;
  840. }
  841.  
  842. $this->code_count ++;
  843.  
  844. if ( $this->edit_mode ) {
  845. $txt = str_replace( "&", "&amp;", $txt );
  846. $txt = str_replace( "'", "&#39;", $txt );
  847. $txt = str_replace( "<", "&lt;", $txt );
  848. $txt = str_replace( ">", "&gt;", $txt );
  849. $txt = str_replace( "&quot;", "&#34;", $txt );
  850. $txt = str_replace( '"', "&#34;", $txt );
  851. $txt = str_replace( ":", "&#58;", $txt );
  852. $txt = str_replace( "[", "&#91;", $txt );
  853. $txt = str_replace( "]", "&#93;", $txt );
  854. $txt = str_replace( "&amp;#123;include", "&#123;include", $txt );
  855. $txt = str_replace( "&amp;#123;content", "&#123;content", $txt );
  856. $txt = str_replace( "&amp;#123;custom", "&#123;custom", $txt );
  857.  
  858. $txt = str_replace( "{", "&#123;", $txt );
  859.  
  860. $txt = str_replace( "\r", "__CODENR__", $txt );
  861. $txt = str_replace( "\n", "__CODENN__", $txt );
  862.  
  863. }
  864.  
  865. $p = "[code]{" . $this->code_count . "}[/code]";
  866.  
  867. $this->code_text[$p] = "[code]{$txt}[/code]";
  868.  
  869. return $p;
  870. }
  871.  
  872. function check_frame( $matches=array() ) {
  873. $allow_frame = false;
  874.  
  875. if (strpos($matches[3], "src=") !== false) return "";
  876.  
  877. $matches[2] = str_replace(chr(0), '', $matches[2]);
  878. $domain = str_replace("www.", '', $matches[2]);
  879.  
  880. if (strpos($domain, "//") === 0) $domain = "http:".$domain;
  881.  
  882. $domain = @parse_url ( $domain, PHP_URL_HOST );
  883.  
  884. if($domain AND in_array($domain, $this->allowed_domains ) ) {
  885. $allow_frame = true;
  886. }
  887.  
  888. if ( !$allow_frame ) return "";
  889.  
  890. $this->frame_count ++;
  891.  
  892. $p = "[frame{$this->frame_count}]";
  893.  
  894. $this->frame_code[$p] = "<iframe src=\"{$matches[2]}\" ".trim($matches[1].$matches[3])."></iframe>";
  895.  
  896. return $p;
  897.  
  898. }
  899.  
  900. function decode_code( $matches=array() ) {
  901.  
  902. $txt = $matches[1];
  903.  
  904. if ( !$this->codes_param['wysiwig'] AND $this->edit_mode ) {
  905.  
  906. $txt = str_replace( "&amp;", "&", $txt );
  907. }
  908.  
  909. if( !$this->codes_param['wysiwig'] AND $this->codes_param['html'] ) {
  910. $txt = str_replace( "&lt;br /&gt;", "\n", $txt );
  911. }
  912.  
  913. if ( $this->codes_param['wysiwig'] == 1 AND $this->edit_mode ) {
  914. $txt = str_replace( "\n", "&lt;br /&gt;", $txt );
  915. return "[code]".$txt."[/code]";
  916. }
  917.  
  918. if ( $this->codes_param['wysiwig'] == 2 AND $this->edit_mode ) {
  919. $txt = str_replace( "\n", "&lt;/p&gt;&lt;p&gt;", $txt );
  920. return "&lt;p&gt;[code]".$txt."[/code]&lt;/p&gt;";
  921. }
  922.  
  923. return "[code]".$txt."[/code]";
  924. }
  925.  
  926.  
  927. function build_video( $matches=array() ) {
  928. global $config;
  929.  
  930. $url = $matches[1];
  931.  
  932. if (!count($this->video_config)) {
  933.  
  934. include (ENGINE_DIR . '/data/videoconfig.php');
  935. $this->video_config = $video_config;
  936.  
  937. }
  938.  
  939. $get_size = array();
  940. $sizes = array();
  941.  
  942. $get_size = explode( ",", trim( $url ) );
  943.  
  944. if (count($get_size) > 1 AND ( stripos ( $get_size[0], "http" ) === false OR stripos ( $get_size[0], "rtmp:" ) === false ) ) {
  945.  
  946. $sizes = explode( "x", trim( $get_size[0] ) );
  947.  
  948. if (count($sizes) == 2) {
  949.  
  950. $width = intval($sizes[0]) > 0 ? intval($sizes[0]) : $this->video_config['width'];
  951. $height = intval($sizes[1]) > 0 ? intval($sizes[1]) : $this->video_config['height'];
  952.  
  953. if (substr ( $sizes[0], - 1, 1 ) == '%') $width = $width."%";
  954. if (substr ( $sizes[1], - 1, 1 ) == '%') $height = $height."%";
  955.  
  956. } else {
  957.  
  958. $width = $this->video_config['width'];
  959. $height = $this->video_config['height'];
  960.  
  961.  
  962. }
  963.  
  964. } else {
  965.  
  966. $width = $this->video_config['width'];
  967. $height = $this->video_config['height'];
  968.  
  969. }
  970.  
  971. if (count($get_size) == 3) $url = $get_size[1].",".$get_size[2];
  972. elseif (count($get_size) == 2 AND count($sizes) == 2) $url = $get_size[1];
  973.  
  974. $option = explode( "|", trim( $url ) );
  975.  
  976. $url = $this->clear_url( $option[0] );
  977.  
  978. $type = explode( ".", $url );
  979. $type = strtolower( end( $type ) );
  980.  
  981. if( preg_match( "/[?&;<\[\]]/", $url ) ) {
  982.  
  983. return "{$url}";
  984.  
  985. }
  986.  
  987. if( $option[1] != "" ) {
  988.  
  989. $option[1] = htmlspecialchars( strip_tags( stripslashes( $option[1] ) ), ENT_QUOTES, $config['charset'] );
  990. $decode_url = $url . "|" . $option[1];
  991.  
  992. } else
  993. $decode_url = $url;
  994.  
  995.  
  996. if ( count($sizes) == 2 ) $decode_url = $width."x".$height.",".$decode_url;
  997.  
  998. if ( stripos ( $url, "rtmp:" ) === false ) $detect_rtmp = false; else $detect_rtmp = true;
  999.  
  1000. if( $type == "flv" OR $type == "f4v" OR $type == "mp4" OR $type == "m4v" OR $type == "m4a" OR $type == "mov" OR $detect_rtmp) {
  1001.  
  1002. if( $this->video_config['flv_watermark'] ) $watermark = "&amp;showWatermark=true&amp;watermarkPosition={$this->video_config['flv_watermark_pos']}&amp;watermarkMargin=0&amp;watermarkAlpha={$this->video_config['flv_watermark_al']}&amp;watermarkImageUrl={THEME}/dleimages/flv_watermark.png";
  1003. else $watermark = "&amp;showWatermark=false";
  1004.  
  1005. if( $option[1] != "" ) {
  1006.  
  1007. $preview = "&amp;showPreviewImage=true&amp;previewImageUrl=".$option[1];
  1008.  
  1009. } else {
  1010.  
  1011. $preview = "&amp;showPreviewImage=true&amp;previewImageUrl={THEME}/dleimages/videopreview.jpg";
  1012.  
  1013. }
  1014.  
  1015. $id_player = md5( microtime() );
  1016.  
  1017. $list = explode( ",", $url );
  1018. $url = trim($list[0]);
  1019.  
  1020. if (count($list) > 1 ){
  1021.  
  1022. $url_hd = trim($list[1]);
  1023.  
  1024. } else {
  1025.  
  1026. $url_hd = '';
  1027. }
  1028.  
  1029. if ( $detect_rtmp ) {
  1030.  
  1031. $video_url = "&amp;rtmpURI=".$url."&amp;videoUrl=".$url_hd;
  1032.  
  1033. } else {
  1034.  
  1035. $video_url = "&amp;videoUrl=".$url."&amp;videoHDUrl=".$url_hd;
  1036.  
  1037. }
  1038.  
  1039. if( $type == "mp4" OR $type == "m4v" OR $type == "m4a" OR $type == "mov" ) {
  1040.  
  1041. if( $option[1] != "" ) {
  1042.  
  1043. $preview = $option[1];
  1044.  
  1045. } else {
  1046.  
  1047. $preview = "";
  1048. }
  1049.  
  1050. if( $this->video_config['preload'] ) $preload = "metadata";
  1051. else $preload = "none";
  1052.  
  1053. return "{$url}";
  1054.  
  1055. } else {
  1056.  
  1057. return "{$video_url}";
  1058. }
  1059.  
  1060. } elseif( $type == "avi" OR $type == "divx" OR $type == "mkv" ) {
  1061.  
  1062. $url = htmlspecialchars( trim( $url ) , ENT_QUOTES, $config['charset'] );
  1063.  
  1064. return "{$url}";
  1065.  
  1066. } else {
  1067.  
  1068. return "{$url}";
  1069.  
  1070. }
  1071.  
  1072. }
  1073. function build_audio( $matches=array() ) {
  1074. global $config;
  1075.  
  1076. $url = $matches[1];
  1077.  
  1078. if( $url == "" ) return;
  1079.  
  1080. if (!count($this->video_config)) {
  1081.  
  1082. include (ENGINE_DIR . '/data/videoconfig.php');
  1083. $this->video_config = $video_config;
  1084.  
  1085. }
  1086.  
  1087. $get_size = explode( ",", trim( $url ) );
  1088. $sizes = array();
  1089.  
  1090. if (count($get_size) == 2) {
  1091.  
  1092. $url = $get_size[1];
  1093. $sizes = explode( "x", trim( $get_size[0] ) );
  1094.  
  1095. $width = intval($sizes[0]) > 0 ? intval($sizes[0]) : $this->video_config['audio_width'];
  1096. $height = intval($sizes[1]) > 0 ? intval($sizes[1]) : "27";
  1097.  
  1098. if (substr ( $sizes[0], - 1, 1 ) == '%') $width = $width."%";
  1099. if (substr ( $sizes[1], - 1, 1 ) == '%') $height = $height."%";
  1100.  
  1101. } else {
  1102.  
  1103. $width = $this->video_config['audio_width'];
  1104. $height = 27;
  1105.  
  1106. }
  1107.  
  1108. if( preg_match( "/[?&;%<\[\]]/", $url ) ) {
  1109.  
  1110. return "[audio=" . $url . "]";
  1111. }
  1112.  
  1113. $url = $this->clear_url( $url );
  1114.  
  1115. if ( count($get_size) == 2 ) $decode_url = $width."x".$height.",".$url;
  1116. else $decode_url = $url;
  1117.  
  1118. $id_player = md5( microtime() );
  1119.  
  1120. return "<!--dle_audio_begin:{$decode_url}--><audio width=\"{$width}\" controls=\"control\" preload=\"none\" src=\"{$url}\"></audio><!--dle_audio_end-->";
  1121.  
  1122.  
  1123. }
  1124.  
  1125. function build_image( $matches=array() ) {
  1126. global $config;
  1127.  
  1128. if(count($matches) == 2 ) {
  1129.  
  1130. $align = "";
  1131. $url = $matches[1];
  1132.  
  1133. } else {
  1134. $align = $matches[1];
  1135. $url = $matches[2];
  1136. }
  1137.  
  1138. $url = trim( $url );
  1139. $url = urldecode( $url );
  1140. $option = explode( "|", trim( $align ) );
  1141. $align = $option[0];
  1142.  
  1143. if( $align != "left" and $align != "right" ) $align = '';
  1144.  
  1145. if( preg_match( "/[?&;%<\[\]]/", $url ) ) {
  1146.  
  1147. if( $align != "" ) return "[img=" . $align . "]" . $url . "[/img]";
  1148. else return "[img]" . $url . "[/img]";
  1149.  
  1150. }
  1151.  
  1152. $url = $this->clear_url( urldecode( $url ) );
  1153.  
  1154. $info = $url;
  1155.  
  1156. $info = $info."|".$align;
  1157.  
  1158. if( $url == "" ) return;
  1159.  
  1160. if( $option[1] != "" ) {
  1161.  
  1162. $alt = htmlspecialchars( strip_tags( stripslashes( $option[1] ) ), ENT_QUOTES, $config['charset'] );
  1163. $info = $info."|".$alt;
  1164. $caption = "<span class=\"highslide-caption\">" . $alt . "</span>";
  1165. $alt = "alt=\"" . $alt . "\" title=\"" . $alt . "\" ";
  1166.  
  1167. } else {
  1168.  
  1169. $alt = htmlspecialchars( strip_tags( stripslashes( $_POST['title'] ) ), ENT_QUOTES, $config['charset'] );
  1170. $caption = "";
  1171. $alt = "alt=\"" . $alt . "\" title=\"" . $alt . "\" ";
  1172.  
  1173. }
  1174.  
  1175. if( intval( $config['tag_img_width'] ) ) {
  1176.  
  1177. if (clean_url( $config['http_home_url'] ) != clean_url ( $url ) ) {
  1178.  
  1179. $img_info = @getimagesize( $url );
  1180.  
  1181. if( $img_info[0] > $config['tag_img_width'] ) {
  1182.  
  1183. $out_heigh = ($img_info[1] / 100) * ($config['tag_img_width'] / ($img_info[0] / 100));
  1184. $out_heigh = floor( $out_heigh );
  1185.  
  1186. if( $align == '' ) return "<!--dle_image_begin:{$info}--><a href=\"{$url}\" onclick=\"return hs.expand(this)\" ><img src=\"$url\" width=\"{$config['tag_img_width']}\" height=\"{$out_heigh}\" {$alt} /></a>{$caption}<!--dle_image_end-->";
  1187. else return "<!--dle_image_begin:{$info}--><a href=\"{$url}\" onclick=\"return hs.expand(this)\" ><img src=\"$url\" width=\"{$config['tag_img_width']}\" height=\"{$out_heigh}\" style=\"float:{$align};\" {$alt} /></a>{$caption}<!--dle_image_end-->";
  1188.  
  1189.  
  1190. }
  1191. }
  1192. }
  1193.  
  1194.  
  1195. if( $align == '' ) return "<!--dle_image_begin:{$info}--><img src=\"{$url}\" {$alt} /><!--dle_image_end-->";
  1196. else return "<!--dle_image_begin:{$info}--><img src=\"{$url}\" style=\"float:{$align};\" {$alt} /><!--dle_image_end-->";
  1197.  
  1198. }
  1199.  
  1200. function decode_dle_img( $matches=array() ) {
  1201.  
  1202. $txt = $matches[1];
  1203. $txt = explode("|", $txt );
  1204. $url = $txt[0];
  1205. $align = $txt[1];
  1206. $alt = $txt[2];
  1207. $extra = "";
  1208.  
  1209. if( ! $align and ! $alt ) return "[img]" . $url . "[/img]";
  1210.  
  1211. if( $align ) $extra = $align;
  1212.  
  1213. if( $alt ) {
  1214.  
  1215. $alt = str_replace("&#039;", "'", $alt);
  1216. $alt = str_replace("&quot;", '"', $alt);
  1217. $alt = str_replace("&amp;", '&', $alt);
  1218. $extra .= "|" . $alt;
  1219.  
  1220. }
  1221.  
  1222. return "[img=" . $extra . "]" . $url . "[/img]";
  1223.  
  1224. }
  1225.  
  1226. function clear_p_tag( $matches=array() ) {
  1227.  
  1228. $txt = $matches[1];
  1229.  
  1230. $txt = str_replace("\r", "", $txt);
  1231. $txt = str_replace("\n", "", $txt);
  1232.  
  1233. $txt = preg_replace('/<p[^>]*>/', '', $txt);
  1234. $txt = str_replace("</p>", "\n", $txt);
  1235. $txt = preg_replace('/<div[^>]*>/', '', $txt);
  1236. $txt = str_replace("</div>", "\n", $txt);
  1237. $txt = preg_replace('/<br[^>]*>/', "\n", $txt);
  1238.  
  1239. return "<pre><code>".$txt."</code></pre>";
  1240.  
  1241. }
  1242.  
  1243. function clear_div_tag( $matches=array() ) {
  1244.  
  1245. $spoiler = array();
  1246.  
  1247. if ( count($matches) == 3 ) {
  1248. $spoiler['title'] = '';
  1249. $spoiler['txt'] = $matches[2];
  1250. } else {
  1251. $spoiler['title'] = $matches[2];
  1252. $spoiler['txt'] = $matches[3];
  1253. }
  1254.  
  1255. $tag = $matches[1];
  1256.  
  1257. $spoiler['txt'] = preg_replace('/<div[^>]*>/', '', $spoiler['txt']);
  1258. $spoiler['txt'] = preg_replace('/<p[^>]*>/', '', $spoiler['txt']);
  1259. $spoiler['txt'] = str_replace("</p>", "<br />", $spoiler['txt']);
  1260. $spoiler['txt'] = str_replace("</div>", "<br />", $spoiler['txt']);
  1261.  
  1262. if ($spoiler['title'])
  1263. return "[{$tag}={$spoiler['title']}]".$spoiler['txt']."[/{$tag}]";
  1264. else
  1265. return "[{$tag}]".$spoiler['txt']."[/{$tag}]";
  1266.  
  1267. }
  1268.  
  1269. function build_thumb( $matches=array() ) {
  1270. global $config;
  1271.  
  1272. if (count($matches) == 2 ) {
  1273. $align = "";
  1274. $gurl = $matches[1];
  1275. } else {
  1276. $align = $matches[1];
  1277. $gurl = $matches[2];
  1278. }
  1279.  
  1280. if( preg_match( "/[?&;%<\[\]]/", $gurl ) ) {
  1281.  
  1282. if( $align != "" ) return "[thumb=" . $align . "]" . $gurl . "[/thumb]";
  1283. else return "[thumb]" . $gurl . "[/thumb]";
  1284.  
  1285. }
  1286.  
  1287. $gurl = $this->clear_url( urldecode( $gurl ) );
  1288.  
  1289. $url = preg_replace( "'([^\[]*)([/\\\\])(.*?)'i", "\\1\\2thumbs\\2\\3", $gurl );
  1290.  
  1291. $url = trim( $url );
  1292. $gurl = trim( $gurl );
  1293. $option = explode( "|", trim( $align ) );
  1294.  
  1295. $align = $option[0];
  1296.  
  1297. if( $align != "left" and $align != "right" ) $align = '';
  1298.  
  1299. $url = $this->clear_url( urldecode( $url ) );
  1300.  
  1301. $info = $gurl;
  1302. $info = $info."|".$align;
  1303.  
  1304. if( $gurl == "" or $url == "" ) return;
  1305.  
  1306. if( $option[1] != "" ) {
  1307.  
  1308. $alt = htmlspecialchars( strip_tags( stripslashes( $option[1] ) ), ENT_QUOTES, $config['charset'] );
  1309.  
  1310. $alt = str_replace("&amp;amp;","&amp;",$alt);
  1311.  
  1312. $info = $info."|".$alt;
  1313. $caption = "<span class=\"highslide-caption\">" . $alt . "</span>";
  1314. $alt = "alt=\"" . $alt . "\" title=\"" . $alt . "\" ";
  1315.  
  1316. } else {
  1317.  
  1318. $alt = htmlspecialchars( strip_tags( stripslashes( $_POST['title'] ) ), ENT_QUOTES, $config['charset'] );
  1319. $alt = "alt='" . $alt . "' title='" . $alt . "' ";
  1320. $caption = "";
  1321.  
  1322. }
  1323.  
  1324. if( $align == '' ) return "<!--TBegin:{$info}--><a href=\"$gurl\" rel=\"highslide\" class=\"highslide\"><img src=\"$url\" {$alt} /></a>{$caption}<!--TEnd-->";
  1325. else return "<!--TBegin:{$info}--><a href=\"$gurl\" rel=\"highslide\" class=\"highslide\"><img src=\"$url\" style=\"float:{$align};\" {$alt} /></a>{$caption}<!--TEnd-->";
  1326.  
  1327. }
  1328.  
  1329.  
  1330. function build_medium( $matches=array() ) {
  1331. global $config;
  1332.  
  1333. if (count($matches) == 2 ) {
  1334. $align = "";
  1335. $gurl = $matches[1];
  1336. } else {
  1337. $align = $matches[1];
  1338. $gurl = $matches[2];
  1339. }
  1340.  
  1341. if( preg_match( "/[?&;%<\[\]]/", $gurl ) ) {
  1342.  
  1343. if( $align != "" ) return "[medium=" . $align . "]" . $gurl . "[/medium]";
  1344. else return "[medium]" . $gurl . "[/medium]";
  1345.  
  1346. }
  1347.  
  1348. $gurl = $this->clear_url( urldecode( $gurl ) );
  1349.  
  1350. $url = preg_replace( "'([^\[]*)([/\\\\])(.*?)'i", "\\1\\2medium\\2\\3", $gurl );
  1351.  
  1352. $url = trim( $url );
  1353. $gurl = trim( $gurl );
  1354. $option = explode( "|", trim( $align ) );
  1355.  
  1356. $align = $option[0];
  1357.  
  1358. if( $align != "left" and $align != "right" ) $align = '';
  1359.  
  1360. $url = $this->clear_url( urldecode( $url ) );
  1361.  
  1362. $info = $gurl;
  1363. $info = $info."|".$align;
  1364.  
  1365. if( $gurl == "" or $url == "" ) return;
  1366.  
  1367. if( $option[1] != "" ) {
  1368.  
  1369. $alt = htmlspecialchars( strip_tags( stripslashes( $option[1] ) ), ENT_QUOTES, $config['charset'] );
  1370.  
  1371. $alt = str_replace("&amp;amp;","&amp;",$alt);
  1372.  
  1373. $info = $info."|".$alt;
  1374. $caption = "<span class=\"highslide-caption\">" . $alt . "</span>";
  1375. $alt = "alt=\"" . $alt . "\" title=\"" . $alt . "\" ";
  1376.  
  1377. } else {
  1378.  
  1379. $alt = htmlspecialchars( strip_tags( stripslashes( $_POST['title'] ) ), ENT_QUOTES, $config['charset'] );
  1380. $alt = "alt='" . $alt . "' title='" . $alt . "' ";
  1381. $caption = "";
  1382.  
  1383. }
  1384.  
  1385. if( $align == '' ) return "<!--MBegin:{$info}--><a href=\"$gurl\" rel=\"highslide\" class=\"highslide\"><img src=\"$url\" {$alt} /></a>{$caption}<!--MEnd-->";
  1386. else return "<!--MBegin:{$info}--><a href=\"$gurl\" rel=\"highslide\" class=\"highslide\"><img src=\"$url\" style=\"float:{$align};\" {$alt} /></a>{$caption}<!--MEnd-->";
  1387.  
  1388. }
  1389.  
  1390. function build_spoiler( $matches=array() ) {
  1391. global $lang;
  1392.  
  1393. if (count($matches) == 3 ) {
  1394.  
  1395. $title = $matches[1];
  1396. $title = trim( $title );
  1397.  
  1398. $title = str_replace( "&amp;amp;", "&amp;", $title );
  1399. $title = preg_replace( "/javascript:/i", "javascript&#58; ", $title );
  1400.  
  1401. } else $title = false;
  1402.  
  1403. $id_spoiler = "sp".md5( microtime().uniqid( mt_rand(), TRUE ) );
  1404.  
  1405. if( !$title ) {
  1406.  
  1407. return "<!--dle_spoiler--><div class=\"title_spoiler\"><a href=\"javascript:ShowOrHide('" . $id_spoiler . "')\"><img id=\"image-" . $id_spoiler . "\" style=\"vertical-align: middle;border: none;\" alt=\"\" src=\"{THEME}/dleimages/spoiler-plus.gif\" /></a>&nbsp;<a href=\"javascript:ShowOrHide('" . $id_spoiler . "')\"><!--spoiler_title-->" . $lang['spoiler_title'] . "<!--spoiler_title_end--></a></div><div id=\"" . $id_spoiler . "\" class=\"text_spoiler\" style=\"display:none;\"><!--spoiler_text-->{$matches[1]}<!--spoiler_text_end--></div><!--/dle_spoiler-->";
  1408.  
  1409. } else {
  1410.  
  1411. return "<!--dle_spoiler $title --><div class=\"title_spoiler\"><a href=\"javascript:ShowOrHide('" . $id_spoiler . "')\"><img id=\"image-" . $id_spoiler . "\" style=\"vertical-align: middle;border: none;\" alt=\"\" src=\"{THEME}/dleimages/spoiler-plus.gif\" /></a>&nbsp;<a href=\"javascript:ShowOrHide('" . $id_spoiler . "')\"><!--spoiler_title-->" . $title . "<!--spoiler_title_end--></a></div><div id=\"" . $id_spoiler . "\" class=\"text_spoiler\" style=\"display:none;\"><!--spoiler_text-->{$matches[2]}<!--spoiler_text_end--></div><!--/dle_spoiler-->";
  1412.  
  1413. }
  1414.  
  1415. }
  1416.  
  1417. function clear_url($url) {
  1418. global $config;
  1419.  
  1420. $url = strip_tags( trim( stripslashes( $url ) ) );
  1421.  
  1422. $url = str_replace( '\"', '"', $url );
  1423. $url = str_replace( "'", "", $url );
  1424. $url = str_replace( '"', "", $url );
  1425.  
  1426. if( !$this->safe_mode OR $this->wysiwyg ) {
  1427.  
  1428. $url = htmlspecialchars( $url, ENT_QUOTES, $config['charset'] );
  1429.  
  1430. }
  1431.  
  1432. $url = str_ireplace( "document.cookie", "d&#111;cument.cookie", $url );
  1433. $url = str_replace( " ", "%20", $url );
  1434. $url = str_replace( "<", "&#60;", $url );
  1435. $url = str_replace( ">", "&#62;", $url );
  1436. $url = preg_replace( "/javascript:/i", "j&#097;vascript:", $url );
  1437. $url = preg_replace( "/data:/i", "d&#097;ta:", $url );
  1438.  
  1439. return $url;
  1440.  
  1441. }
  1442.  
  1443. function decode_leech( $matches=array() ) {
  1444.  
  1445. $url = $matches[1];
  1446. $show = $matches[3];
  1447.  
  1448. if( $this->leech_mode ) return "[url=" . $url . "]" . $show . "[/url]";
  1449.  
  1450. $url = explode( "url=", $url );
  1451. $url = end( $url );
  1452. $url = rawurldecode( $url );
  1453. $url = base64_decode( $url );
  1454. $url = str_replace("&amp;","&", $url );
  1455.  
  1456. if( preg_match( "#title=['\"](.+?)['\"]#i", $matches[2], $match ) ) {
  1457. $match[1] = str_replace("&quot;", '"', $match[1]);
  1458. $match[1] = str_replace("&#039;", "'", $match[1]);
  1459. $match[1] = str_replace("&amp;", "&", $match[1]);
  1460. $url = $url."|".$match[1];
  1461. }
  1462.  
  1463. return "[leech=" . $url . "]" . $show . "[/leech]";
  1464. }
  1465.  
  1466. function decode_url( $matches=array() ) {
  1467.  
  1468. $show = $matches[3];
  1469. $url = $matches[1];
  1470. $params = trim($matches[2]);
  1471.  
  1472. if( preg_match( "#title=['\"](.+?)['\"]#i", $params, $match ) ) {
  1473. $match[1] = str_replace("&quot;", '"', $match[1]);
  1474. $match[1] = str_replace("&#039;", "'", $match[1]);
  1475. $match[1] = str_replace("&amp;", "&", $match[1]);
  1476. $url = $url."|".$match[1];
  1477. $params = trim(str_replace($match[0], "", $params));
  1478. }
  1479.  
  1480. if (!$params OR $params == 'target="_blank"' OR $params == 'target="_blank" rel="nofollow"' OR $params == 'rel="nofollow"') {
  1481.  
  1482. $url = str_replace("&amp;","&", $url );
  1483.  
  1484. return "[url=" . $url . "]" . $show . "[/url]";
  1485.  
  1486. } else {
  1487.  
  1488. return $matches[0];
  1489.  
  1490. }
  1491. }
  1492.  
  1493. function decode_thumb( $matches=array() ) {
  1494.  
  1495. if ($matches[1] == "TBegin") $tag="thumb"; else $tag="medium";
  1496. $txt = $matches[2];
  1497.  
  1498. $txt = stripslashes( $txt );
  1499. $txt = explode("|", $txt );
  1500. $url = $txt[0];
  1501. $align = $txt[1];
  1502. $alt = $txt[2];
  1503. $extra = "";
  1504.  
  1505. if( ! $align and ! $alt ) return "[{$tag}]{$url}[/{$tag}]";
  1506.  
  1507. if( $align ) $extra = $align;
  1508. if( $alt ) {
  1509.  
  1510. $alt = str_replace("&#039;", "'", $alt);
  1511. $alt = str_replace("&quot;", '"', $alt);
  1512. $alt = str_replace("&amp;", '&', $alt);
  1513. $extra .= "|" . $alt;
  1514.  
  1515. }
  1516.  
  1517. return "[{$tag}={$extra}]{$url}[/{$tag}]";
  1518.  
  1519. }
  1520.  
  1521. function decode_oldthumb( $matches=array() ) {
  1522.  
  1523. $txt = $matches[1];
  1524.  
  1525. $align = false;
  1526. $alt = false;
  1527. $extra = "";
  1528. $txt = stripslashes( $txt );
  1529.  
  1530. $url = str_replace( "<a href=\"", "", $txt );
  1531. $url = explode( "\"", $url );
  1532. $url = reset( $url );
  1533.  
  1534. if( strpos( $txt, "align=\"" ) !== false ) {
  1535.  
  1536. $align = preg_replace( "#(.+?)align=\"(.+?)\"(.*)#is", "\\2", $txt );
  1537. }
  1538.  
  1539. if( strpos( $txt, "alt=\"" ) !== false ) {
  1540.  
  1541. $alt = preg_replace( "#(.+?)alt=\"(.+?)\"(.*)#is", "\\2", $txt );
  1542. }
  1543.  
  1544. if( $align != "left" and $align != "right" ) $align = false;
  1545.  
  1546. if( ! $align and ! $alt ) return "[thumb]" . $url . "[/thumb]";
  1547.  
  1548. if( $align ) $extra = $align;
  1549. if( $alt ) {
  1550. $alt = str_replace("&#039;", "'", $alt);
  1551. $alt = str_replace("&quot;", '"', $alt);
  1552. $alt = str_replace("&amp;", '&', $alt);
  1553. $extra .= "|" . $alt;
  1554.  
  1555. }
  1556.  
  1557. return "[thumb=" . $extra . "]" . $url . "[/thumb]";
  1558.  
  1559. }
  1560.  
  1561. function decode_img( $matches=array() ) {
  1562.  
  1563. $img = $matches[1];
  1564. $txt = $matches[2];
  1565. $align = false;
  1566. $alt = false;
  1567. $extra = "";
  1568.  
  1569. if( strpos( $txt, "align=\"" ) !== false ) {
  1570.  
  1571. $align = preg_replace( "#(.+?)align=\"(.+?)\"(.*)#is", "\\2", $txt );
  1572. }
  1573.  
  1574. if( strpos( $txt, "alt=\"\"" ) !== false ) {
  1575.  
  1576. $alt = false;
  1577.  
  1578. } elseif( strpos( $txt, "alt=\"" ) !== false ) {
  1579.  
  1580. $alt = preg_replace( "#(.+?)alt=\"(.+?)\"(.*)#is", "\\2", $txt );
  1581. }
  1582.  
  1583. if( $align != "left" and $align != "right" ) $align = false;
  1584.  
  1585. if( ! $align and ! $alt ) return "[img]" . $img . "[/img]";
  1586.  
  1587. if( $align ) $extra = $align;
  1588. if( $alt ) $extra .= "|" . $alt;
  1589.  
  1590. return "[img=" . $extra . "]" . $img . "[/img]";
  1591.  
  1592. }
  1593.  
  1594. function check_home($url) {
  1595. global $config;
  1596.  
  1597. $value = str_replace( "http://", "", $config['http_home_url'] );
  1598. $value = str_replace( "www.", "", $value );
  1599. $value = explode( '/', $value );
  1600. $value = reset( $value );
  1601. if( $value == "" ) return false;
  1602.  
  1603. if( strpos( $url, $value ) === false ) return false;
  1604. else return true;
  1605. }
  1606.  
  1607. function word_filter($source, $encode = true) {
  1608. global $config;
  1609.  
  1610. if( $encode ) {
  1611.  
  1612. $all_words = @file( ENGINE_DIR . '/data/wordfilter.db.php' );
  1613. $find = array ();
  1614. $replace = array ();
  1615.  
  1616. if( ! $all_words or ! count( $all_words ) ) return $source;
  1617.  
  1618. foreach ( $all_words as $word_line ) {
  1619. $word_arr = explode( "|", $word_line );
  1620.  
  1621. if( function_exists( "get_magic_quotes_gpc" ) && get_magic_quotes_gpc() ) {
  1622.  
  1623. $word_arr[1] = addslashes( $word_arr[1] );
  1624.  
  1625. }
  1626.  
  1627. if( $word_arr[4] ) {
  1628.  
  1629. $register ="";
  1630.  
  1631. } else $register ="i";
  1632.  
  1633. if ( $config['charset'] == "utf-8" ) $register .= "u";
  1634.  
  1635. $allow_find = true;
  1636.  
  1637. if ( $word_arr[5] == 1 AND $this->safe_mode ) $allow_find = false;
  1638. if ( $word_arr[5] == 2 AND !$this->safe_mode ) $allow_find = false;
  1639.  
  1640. if ( $allow_find ) {
  1641.  
  1642. if( $word_arr[3] ) {
  1643.  
  1644. $find_text = "#(^|\b|\s|\<br \/\>)" . preg_quote( $word_arr[1], "#" ) . "(\b|\s|!|\?|\.|,|$)#".$register;
  1645.  
  1646. if( $word_arr[2] == "" ) $replace_text = "\\1";
  1647. else $replace_text = "\\1<!--filter:" . $word_arr[1] . "-->" . $word_arr[2] . "<!--/filter-->\\2";
  1648.  
  1649. } else {
  1650.  
  1651. $find_text = "#(" . preg_quote( $word_arr[1], "#" ) . ")#".$register;
  1652.  
  1653. if( $word_arr[2] == "" ) $replace_text = "";
  1654. else $replace_text = "<!--filter:" . $word_arr[1] . "-->" . $word_arr[2] . "<!--/filter-->";
  1655.  
  1656. }
  1657.  
  1658. if ( $word_arr[6] ) {
  1659.  
  1660. if ( preg_match($find_text, $source) ) {
  1661.  
  1662. $this->not_allowed_text = true;
  1663. return $source;
  1664.  
  1665. }
  1666.  
  1667. } else {
  1668.  
  1669. $find[] = $find_text;
  1670. $replace[] = $replace_text;
  1671. }
  1672.  
  1673. }
  1674.  
  1675. }
  1676.  
  1677. if( !count( $find ) ) return $source;
  1678.  
  1679. $source = preg_split( '((>)|(<))', $source, - 1, PREG_SPLIT_DELIM_CAPTURE );
  1680. $count = count( $source );
  1681.  
  1682. for($i = 0; $i < $count; $i ++) {
  1683. if( $source[$i] == "<" or $source[$i] == "[" ) {
  1684. $i ++;
  1685. continue;
  1686. }
  1687.  
  1688. if( $source[$i] != "" ) $source[$i] = preg_replace( $find, $replace, $source[$i] );
  1689. }
  1690.  
  1691. $source = join( "", $source );
  1692.  
  1693. } else {
  1694.  
  1695. $source = preg_replace( "#<!--filter:(.+?)-->(.+?)<!--/filter-->#", "\\1", $source );
  1696.  
  1697. }
  1698.  
  1699. return $source;
  1700. }
  1701.  
  1702. }
  1703. ?>
Add Comment
Please, Sign In to add comment