PageRenderTime 58ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/system/etc.php

https://github.com/foxadmin/ReloadCMS
PHP | 497 lines | 293 code | 42 blank | 162 comment | 56 complexity | af0e42b7104ae68225694b1a76895e36 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // Copyright (C) ReloadCMS Development Team //
  4. // http://reloadcms.com //
  5. // This product released under GNU General Public License v2 //
  6. ////////////////////////////////////////////////////////////////////////////////
  7. /**
  8. * Misc ReloadCMS packages
  9. *
  10. * @author DruidVAV
  11. * @package ReloadCMS
  12. */
  13. /**
  14. * Function recursively check if $needle is present in $haystack
  15. *
  16. * @param mixed $needle
  17. * @param array $haystack
  18. * @return boolean
  19. */
  20. function rcms_in_array_recursive($needle, $haystack) {
  21. foreach ($haystack as $value){
  22. if(is_array($value)) return rcms_in_array_recursive($needle, $value);
  23. else return in_array($needle, $haystack);
  24. }
  25. }
  26. function in_array_i($needle, $haystack) {
  27. $needle = strtolower(htmlentities($needle));
  28. if(!is_array($haystack)) return false;
  29. foreach ($haystack as $value){
  30. $value = strtolower(htmlentities($value));
  31. if($needle == $value) return true;
  32. }
  33. return false;
  34. }
  35. function rcms_htmlspecialchars_recursive($array) {
  36. foreach ($array as $key =>$value){
  37. if(is_array($value)) $array[$key] = rcms_htmlspecialchars_recursive($value);
  38. else $array[$key] = htmlspecialchars($value);
  39. }
  40. return $array;
  41. }
  42. /**
  43. * Recursively stripslashes array.
  44. *
  45. * @param array $array
  46. * @return boolean
  47. */
  48. function stripslash_array(&$array){
  49. foreach ($array as $key => $value) {
  50. if(is_array($array[$key])) stripslash_array($array[$key]);
  51. else $array[$key] = stripslashes($value);
  52. }
  53. return true;
  54. }
  55. /**
  56. * Shows redirection javascript.
  57. *
  58. * @param string $url
  59. */
  60. function rcms_redirect($url, $header = false) {
  61. if($header){
  62. @header('Location: ' . $url);
  63. } else {
  64. echo '<script type="text/javascript">document.location.href="' . $url . '";</script>';
  65. }
  66. }
  67. /**
  68. * Sends e-mail.
  69. *
  70. * @param string $to
  71. * @param string $from
  72. * @param string $sender
  73. * @param string $encoding
  74. * @param string $subj
  75. * @param string $text
  76. * @return boolean
  77. */
  78. function rcms_send_mail($to, $from, $sender, $encoding, $subj, $text) {
  79. $headers = 'From: =?'.$encoding.'?B?' . base64_encode($sender) . '?= <' . $from . ">\n";
  80. $headers .= "MIME-Version: 1.0\n";
  81. $headers .= 'Message-ID: <' . md5(uniqid(time())) . "@" . $sender . ">\n";
  82. $headers .= 'Date: ' . gmdate('D, d M Y H:i:s T', time()) . "\n";
  83. $headers .= "Content-type: text/plain; charset={$encoding}\n";
  84. $headers .= "Content-transfer-encoding: 8bit\n";
  85. $headers .= "X-Mailer: ReloadCMS\n";
  86. $headers .= "X-MimeOLE: ReloadCMS\n";
  87. return mail($to, '=?'.$encoding.'?B?' . base64_encode($subj). '?=', $text, $headers);
  88. }
  89. /**
  90. * Returns random string with selected length
  91. *
  92. * @param integer $num_chars
  93. * @return string
  94. */
  95. function rcms_random_string($num_chars) {
  96. $chars = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9');
  97. list($usec, $sec) = explode(' ', microtime());
  98. mt_srand($sec * $usec);
  99. $max_chars = sizeof($chars) - 1;
  100. $rand_str = '';
  101. for ($i = 0; $i < $num_chars; $i++) {
  102. $rand_str .= $chars[mt_rand(0, $max_chars)];
  103. }
  104. return $rand_str;
  105. }
  106. /**
  107. * Just returns current time
  108. *
  109. * @return integer
  110. */
  111. function rcms_get_time(){
  112. global $system;
  113. return (mktime() + ($system->config['default_tz'])*3600);
  114. }
  115. /**
  116. * Function that formats date. Similar to date() function but
  117. * uses timezone and returns localised string
  118. *
  119. * @param string $format
  120. * @param integer $gmepoch
  121. * @param integer $tz
  122. * @return string
  123. */
  124. function rcms_format_time($format, $gmepoch, $tz = ''){
  125. global $lang, $system;
  126. if(empty($tz)) $tz = $system->user['tz'];
  127. if ($system->language != 'english'){
  128. @reset($lang['datetime']);
  129. while (list($match, $replace) = @each($lang['datetime'])){
  130. $translate[$match] = $replace;
  131. }
  132. }
  133. return ( !empty($translate) ) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz)), $translate) : @gmdate($format, $gmepoch + (3600 * $tz));
  134. }
  135. /**
  136. * Return localised date from string generated by date()
  137. *
  138. * @param string $string
  139. * @return string
  140. */
  141. function rcms_date_localise($string){
  142. global $lang, $system;
  143. if ($system->language != 'english'){
  144. @reset($lang['datetime']);
  145. while (list($match, $replace) = @each($lang['datetime'])){
  146. $translate[$match] = $replace;
  147. }
  148. }
  149. return ( !empty($translate) ) ? strtr($string, $translate) : $string;
  150. }
  151. function rcms_parse_text_by_mode($str, $mode){
  152. switch ($mode){
  153. default:
  154. case 'check':
  155. return rcms_parse_text($str, false, false, false, false, false, false);
  156. break;
  157. case 'text':
  158. return rcms_parse_text($str, true, false, true, false, true, true);
  159. break;
  160. case 'text-safe':
  161. return rcms_parse_text($str, true, false, true, false, false, false);
  162. break;
  163. case 'html':
  164. return rcms_parse_text($str, false, true, false, false, true, true);
  165. break;
  166. case 'htmlbb':
  167. return rcms_parse_text($str, true, true, false, false, true, true);
  168. break;
  169. }
  170. }
  171. /**
  172. * Just a stub for backward compatibility.
  173. *
  174. * @param string $str
  175. * @param boolean $bbcode
  176. * @param boolean $html
  177. * @param boolean $nl2br
  178. * @param boolean $wordwrap
  179. * @param boolean $imgbbcode
  180. * @return string
  181. */
  182. function rcms_parse_text($str, $bbcode = true, $html = false, $nl2br = true, $wordwrap = false, $imgbbcode = false, $htmlbbcode = false){
  183. $level = intval($bbcode);
  184. if($imgbbcode && $bbcode && $level < 2) $level = 2;
  185. if($htmlbbcode && $bbcode && $level < 3) $level = 3;
  186. $message = new message($str, $level, $html, $nl2br);
  187. $message->init_bbcodes();
  188. $message->parse();
  189. if($wordwrap) {
  190. return '<div style="overflow: auto">' . $message->str . '</div>';
  191. } else {
  192. return $message->str;
  193. }
  194. }
  195. /**
  196. * Validates e-mail
  197. *
  198. * @param string $text
  199. * @return boolean
  200. */
  201. function rcms_is_valid_email($text) {
  202. if(preg_match('/^([a-zA-Z0-9\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+(\.[a-zA-Z0-9\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+)*)@((([a-z]([-a-z0-9]*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\.){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))\.)*(([a-z]([-a-z0-9]*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\.){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))$/', $text))
  203. return true;
  204. else return false;
  205. }
  206. /**
  207. * Returns bbcode panel code for selected textarea
  208. *
  209. * @param string $textarea
  210. * @return string
  211. */
  212. function rcms_show_bbcode_panel($textarea){
  213. return rcms_parse_module_template('bbcodes-panel.tpl', array('textarea' => $textarea));
  214. }
  215. function get_animated_to_array()
  216. {
  217. $arr=rcms_scandir(SMILES_PATH);
  218. $arr2 = array();
  219. foreach ($arr as $key) {
  220. if (file_exists(SMILES_PATH.basename($key, ".gif").".gif")){
  221. $arr2['#\['.basename($key, ".gif").'\]#is'] = '<img src="'.SMILES_PATH.$key.'" alt = "'.basename($key, ".gif").'" />';
  222. }
  223. }
  224. return $arr2;
  225. }
  226. function return_hidden_bb_text() {
  227. if (LOGGED_IN) {
  228. return '<div class="hidden">\\1</div>';
  229. } else {
  230. return '<div class="hidden">'.__('This block only for registered users').'</div>';
  231. }
  232. }
  233. /**
  234. * Message parser class
  235. *
  236. * @package ReloadCMS
  237. */
  238. class message{
  239. /**
  240. * Message container
  241. *
  242. * @var string
  243. */
  244. var $str = '';
  245. /**
  246. * Level of bbcode security.
  247. *
  248. * @var integer
  249. */
  250. var $bbcode_level = 0; // 0 - no bbcode, 1 - save bbcodes, 2 - all bbcodes
  251. /**
  252. * Allow HTML in message
  253. *
  254. * @var boolean
  255. */
  256. var $html = false;
  257. /**
  258. * Perform nl2br in message
  259. *
  260. * @var boolean
  261. */
  262. var $nl2br = false;
  263. /**
  264. * Array of regexps for bbcodes
  265. *
  266. * @var array
  267. */
  268. var $regexp = array();
  269. var $sr_temp = array();
  270. /**
  271. * Class constructor
  272. *
  273. * @param string $message
  274. * @param integer $bbcode_level
  275. * @param boolean $html
  276. * @param boolean $nl2br
  277. * @return message
  278. */
  279. function message($message, $bbcode_level = 0, $html = false, $nl2br = false){
  280. $this->str = $message;
  281. $this->nl2br = $nl2br;
  282. $this->bbcode_level = $bbcode_level;
  283. $this->html = $html;
  284. }
  285. /**
  286. * BBCodes initialisation. Filling in message::regexp array
  287. *
  288. */
  289. function init_bbcodes(){
  290. $this->regexp[0] = array();
  291. $this->regexp[1] = array(
  292. "#\[b\](.*?)\[/b\]#is" => '<span style="font-weight: bold">\\1</span>',
  293. "#\[i\](.*?)\[/i\]#is" => '<span style="font-style: italic">\\1</span>',
  294. "#\[u\](.*?)\[/u\]#is" => '<span style="text-decoration: underline">\\1</span>',
  295. "#\[del\](.*?)\[/del\]#is" => '<span style="text-decoration: line-through">\\1</span>',
  296. "#\[url\][\s\n\r]*(((https?|ftp|ed2k|irc)://|" . RCMS_ROOT_PATH . ")[^ \"\n\r\t\<]*)[\s\n\r]*\[/url\]#is" => '<a href="\\1" >\\1</a>',
  297. "#\[url\][\s\n\r]*(www\.[^ \"\n\r\t\<]*?)[\s\n\r]*\[/url\]#is" => '<a href="http://\\1" >\\1</a>',
  298. "#\[url\][\s\n\r]*((ftp)\.[^ \"\n\r\t\<]*?)[\s\n\r]*\[/url\]#is" => '<a href="\\2://\\1" target="_blank">\\1</a>',
  299. "#\[url=(\"|&quot;|)(((https?|ftp|ed2k|irc)://|" . RCMS_ROOT_PATH . ")[^ \"\n\r\t\<]*?)(\"|&quot;|)\](.*?)\[/url\]#is" => '<a href="\\2" >\\6</a>',
  300. "#\[url=(\"|&quot;|)(www\.[^ \"\n\r\t\<]*?)(\"|&quot;|)\](.*?)\[/url\]#is" => '<a href="http://\\2" >\\4</a>',
  301. "#\[url=(\"|&quot;|)((ftp)\.[^ \"\n\r\t\<]*?)(\"|&quot;|)\](.*?)\[/url\]#is" => '<a href="\\3://\\2" target="_blank">\\5</a>',
  302. "#\[mailto\][\s\n\r]*([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)[\s\n\r]*\[/mailto\]#is" => '<a href="mailto:\\1">\\1</a>',
  303. "#\[mailto=(\"|&quot;|)([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)(\"|&quot;|)\](.*?)\[/mailto\]#is" => '<a href="mailto:\\2">\\5</a>',
  304. "#\[color=(\"|&quot;|)([\#\w]*)(\"|&quot;|)\](.*?)\[/color(.*?)\]#is" => '<span style="color:\\2">\\4</span>',
  305. "#\[size=(\"|&quot;|)([0-9]*)(\"|&quot;|)\](.*?)\[/size(.*?)\]#is" => '<span style="font-size: \\2pt">\\4</span>',
  306. "#\[align=(\"|&quot;|)(left|right|center|justify)(\"|&quot;|)\](.*?)\[/align(.*?)\]#is" => '<span style="text-align: \\2">\\4</span>',
  307. "#\[user\]([\d\w]*?)\[/user\]#is" => ' [ <a href="' . RCMS_ROOT_PATH . '?module=user.list&amp;user=\\1">\\1</a> ] ',
  308. "#\[user=([\d\w]*?)\](.*?)\[/user\]#is" => ' [ <a href="' . RCMS_ROOT_PATH . '?module=user.list&amp;user=\\1">\\2</a> ] ',
  309. "#\[hidden\](.*?)\[/hidden\]#is" => return_hidden_bb_text()
  310. );
  311. $this->regexp[1] = array_merge(get_animated_to_array(), $this->regexp[1]);
  312. $lightbox_config = parse_ini_file(CONFIG_PATH . 'lightbox.ini');
  313. if (@$lightbox_config['articles']) {
  314. $this->regexp[2] = array(
  315. "#[\s\n\r]*\[img\][\s\n\r]*([\w]+?://[^ \"\n\r\t<]*?|".RCMS_ROOT_PATH."[^ \"\n\r\t<]*?)\.(gif|png|jpe?g)[\s\n\r]*\[/img\][\s\n\r]*#is" => '<br /><a href="\\1.\\2" class="gallery"><img src="\\1.\\2" alt="\\2" width="'.$lightbox_config['width'].'px"/></a><br />',
  316. "#[\s\n\r]*\[img=(\"|&quot;|)(left|right)(\"|&quot;|)\][\s\n\r]*([\w]+?://[^ \"\n\r\t<]*?|".RCMS_ROOT_PATH."[^ \"\n\r\t<]*?)\.(gif|png|jpe?g)[\s\n\r]*\[/img\][\s\n\r]*#is" => '<img src="\\4.\\5" alt="\\5" align="\\2" />',
  317. "#[\s\n\r]*\[img=(\"|&quot;|)(\d+)(\"|&quot;|)\][\s\n\r]*([\w]+?://[^ \"\n\r\t<]*?|".RCMS_ROOT_PATH."[^ \"\n\r\t<]*?)\.(gif|png|jpe?g)[\s\n\r]*\[/img\][\s\n\r]*#is" => '<br /><img src="\\4.\\5" alt="\\5" width="\\2px" /><br />',
  318. "#[\s\n\r]*\[img=(\"|&quot;|)(100%|[1-9]?[0-9]%)(\"|&quot;|)\][\s\n\r]*([\w]+?://[^ \"\n\r\t<]*?)\.(gif|png|jpe?g)[\s\n\r]*\[/img\][\s\n\r]*#is" => '<br/><img src="\\4.\\5" alt="\\5" width="\\2" /><br/>'
  319. );
  320. } else {
  321. $this->regexp[2] = array(
  322. "#[\s\n\r]*\[img\][\s\n\r]*([\w]+?://[^ \"\n\r\t<]*?|".RCMS_ROOT_PATH."[^ \"\n\r\t<]*?)\.(gif|png|jpe?g)[\s\n\r]*\[/img\][\s\n\r]*#is" => '<br /><img src="\\1.\\2" alt="\\5" /><br />',
  323. "#[\s\n\r]*\[img=(\"|&quot;|)(left|right)(\"|&quot;|)\][\s\n\r]*([\w]+?://[^ \"\n\r\t<]*?|".RCMS_ROOT_PATH."[^ \"\n\r\t<]*?)\.(gif|png|jpe?g)[\s\n\r]*\[/img\][\s\n\r]*#is" => '<img src="\\4.\\5" alt="\\5" align="\\2" />',
  324. "#[\s\n\r]*\[img=(\"|&quot;|)(\d+)(\"|&quot;|)\][\s\n\r]*([\w]+?://[^ \"\n\r\t<]*?|".RCMS_ROOT_PATH."[^ \"\n\r\t<]*?)\.(gif|png|jpe?g)[\s\n\r]*\[/img\][\s\n\r]*#is" => '<br /><img src="\\4.\\5" alt="\\5" width="\\2px" /><br />',
  325. "#[\s\n\r]*\[img=(\"|&quot;|)(100%|[1-9]?[0-9]%)(\"|&quot;|)\][\s\n\r]*([\w]+?://[^ \"\n\r\t<]*?)\.(gif|png|jpe?g)[\s\n\r]*\[/img\][\s\n\r]*#is" => '<br/><img src="\\4.\\5" alt="\\5" width="\\2" /><br/>'
  326. );
  327. }
  328. }
  329. /**
  330. * Main parse method. Parses message::str
  331. *
  332. */
  333. function parse(){
  334. $old = $this->str;
  335. if(!$this->html) $this->str = htmlspecialchars($this->str);
  336. if(!empty($this->bbcode_level)){
  337. $this->str = preg_replace(array_keys($this->regexp[0]), array_values($this->regexp[0]), ' ' . $this->str . ' ');
  338. if($this->bbcode_level > 0){
  339. $this->parseCodeTag();
  340. $this->parseQuoteTag();
  341. $this->str = preg_replace_callback("#\[spoiler(=(\"|&quot;|)(.*?)(\"|&quot;|)|)\](.*?)\[/spoiler\]#is", 'rcms_spoiler_tag', $this->str);
  342. $this->str = preg_replace_callback("#\[offtop(=(\"|&quot;|)(.*?)(\"|&quot;|)|)\](.*?)\[/offtop\]#is", 'rcms_offtop_tag', $this->str);
  343. $this->str = preg_replace(array_keys($this->regexp[1]), array_values($this->regexp[1]), ' ' . $this->str . ' ');
  344. }
  345. if($this->bbcode_level > 1){
  346. $this->str = preg_replace(array_keys($this->regexp[2]), array_values($this->regexp[2]), ' ' . $this->str . ' ');
  347. }
  348. if($this->bbcode_level > 2){
  349. $this->str = preg_replace_callback("#\[html\](.*?)\[/html\]#is", 'rcms_html_tag', $this->str);
  350. }
  351. if($this->nl2br){
  352. $this->str = nl2br($this->str);
  353. $this->str = preg_replace("#\[nobr\]#","\r\n",$this->str);
  354. }
  355. $this->parseUrls();
  356. }
  357. $this->str = str_replace(array_keys($this->sr_temp), array_values($this->sr_temp), $this->str);
  358. $this->result = $this->str;
  359. $rhis->str = $old;
  360. }
  361. /**
  362. * Parses message::str [qoute|quote="Who"]..[/qoute] bbtag
  363. *
  364. */
  365. function parseQuoteTag(){
  366. $this->str = preg_replace("#[\s\n\r]*\[quote\][\s\n\r]*(.*?)[\s\n\r]*\[/quote\][\s\n\r]*#is", '<div class="codetitle"><b>' . __('Quote') . ':</b></div><div class="codetext">\\1</div>', $this->str);
  367. $this->str = preg_replace("#[\s\n\r]*\[quote=(\"|&quot;|)(.*?)(\"|&quot;|)\][\s\n\r]*(.*?)[\s\n\r]*\[/quote\][\s\n\r]*#is", '<div class="codetitle"><b>\\2 ' . __('wrote') . ':</b></div><div class="codetext">\\4</div>', $this->str);
  368. if (preg_match("#\[quote(?:=.*|)\](?:.*)\[/quote\]#is", $this->str)) $this->parseQuoteTag();
  369. }
  370. /**
  371. * Parses message::str [code]..[/code] bbtag
  372. *
  373. */
  374. function parseCodeTag(){
  375. preg_match_all("#[\s\n\r]*\[code\][\s\n\r]*(.*?)[\s\n\r]*\[/code\][\s\n\r]*#is", $this->str, $matches);
  376. foreach($matches[1] as $oldpart) {
  377. $newpart = preg_replace("#[\n\r]+#", '', highlight_string(strtr($oldpart, array_flip(get_html_translation_table(HTML_SPECIALCHARS))), true));
  378. $newpart = preg_replace(array('#\[#', '#\]#'), array('&#91;', '&#93;'), $newpart);
  379. $tmp = '{SR:' . rcms_random_string(6) . '}';
  380. $this->sr_temp[$tmp] = $newpart;
  381. $this->str = str_replace($oldpart, $tmp, $this->str);
  382. }
  383. $this->str = preg_replace("#[\s\n\r]*\[code\][\s\n\r]*(.*?)[\s\n\r]*\[/code\][\s\n\r]*#is", '<div class="codetitle"><b>' . __('Code') . ':</b></div><div class="codetext" style="overflow: auto; white-space: nowrap;">\\1</div>', $this->str);
  384. }
  385. function parseUrls(){
  386. $this->str = $this->highlightUrls($this->str);
  387. return true;
  388. }
  389. function highlightUrls($string){
  390. $string = ' ' . $string;
  391. $string = preg_replace_callback("#(^|[\n\s\r])((https?|ftp|ed2k|irc)://[^ \"\n\r\t<]*)#is", 'rcms_prc_link', $string);
  392. $string = preg_replace_callback("#(^|[\n\s\r])((www|ftp)\.[^ \"\t\n\r<]*)#is", 'rcms_prc_link_short', $string);
  393. $string = preg_replace_callback("#(^|[\n\s\r])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", 'rcms_prc_mail', $string);
  394. $string = mb_substr($string, 1);
  395. return $string;
  396. }
  397. }
  398. /**
  399. * Callback for link replacement
  400. *
  401. * @param array $matches
  402. * @return string
  403. */
  404. function rcms_prc_link($matches){
  405. if(mb_strlen($matches[2])>25){
  406. return ' <a href="' . $matches[2] . '" >' . mb_substr($matches[2], 0, 11) . '...' . mb_substr($matches[2], -11) . '</a>';
  407. } else return ' <a href="' . $matches[2] . '" >' . $matches[2] . '</a>';
  408. }
  409. /**
  410. * Callback for short link replacement
  411. *
  412. * @param array $matches
  413. * @return string
  414. */
  415. function rcms_prc_link_short($matches){
  416. if(mb_strlen($matches[2])>25){
  417. return ' <a href="http://' . $matches[2] . '" >' . mb_substr($matches[2], 0, 11) . '...' . mb_substr($matches[2], -11) . '</a>';
  418. } else return ' <a href="http://' . $matches[2] . '" >' . $matches[2] . '</a>';
  419. }
  420. /**
  421. * Callback for e-mail replacement
  422. *
  423. * @param array $matches
  424. * @return string
  425. */
  426. function rcms_prc_mail($matches){
  427. if(mb_strlen($matches[2])>25){
  428. return ' <a href="mailto:' . $matches[2] . '@' . $matches[3] . '" target="_blank">' . mb_substr($matches[2], 0, 11) . '...' . mb_substr($matches[2], -11) . '</a>';
  429. } else return ' <a href="mailto:' . $matches[2] . '@' . $matches[3] . '" target="_blank">' . $matches[2] . '</a>';
  430. }
  431. function rcms_spoiler_tag($matches){
  432. if(!empty($matches[3])) $title = $matches[3]; else $title = __('Spoiler') . ' (' . __('click to view') . ')';
  433. return '<div class="codetitle" ><span onclick="openBlock(this);" style="cursor: pointer; cursor: hand;"> + </span>'. $title . '<div class="codetext" style="display:none; margin:0;">'.$matches[5].'</div></div>';
  434. }
  435. function rcms_offtop_tag($matches){
  436. if(!empty($matches[3])) $title = $matches[3]; else $title = __('Offtop') . ' (' . __('click to view') . ')';
  437. return '<div class="codetitle" ><span onclick="openBlock(this);" style="cursor: pointer; cursor: hand;"> + </span>'. $title . '<div class="codetext" style="display:none; margin:0;">'.$matches[5].'</div></div>';
  438. }
  439. function rcms_html_tag($matches){
  440. return str_replace(array('[', ']',"\r\n"), array('&#91', '&#93',"[nobr]"), strtr($matches[1], array_flip(get_html_translation_table(HTML_SPECIALCHARS))));
  441. }
  442. function rcms_remove_index($key, &$array, $preserve_keys = false) {
  443. $temp_array = $array;
  444. $array = array();
  445. foreach ($temp_array as $ckey => $value){
  446. if($key != $ckey){
  447. if($preserve_keys) {
  448. $array[$ckey] = $value;
  449. } else {
  450. $array[] = $value;
  451. }
  452. }
  453. }
  454. }
  455. ?>