PageRenderTime 26ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/chat/include/caddchatm.php

https://gitlab.com/ppkbb3cker/ppkbb3cker2
PHP | 235 lines | 174 code | 24 blank | 37 comment | 43 complexity | 49c3243b208fa0b5640869a60e311819 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package ppkBB3cker
  5. * @version $Id: caddchatm.php 1.000 2010-03-14 13:14:00 PPK $
  6. * @copyright (c) 2010 PPK
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. if($edit_mode)
  18. {
  19. !$rights[18] && !$rights[19] ? $edit_mode=0 : '';
  20. }
  21. if($rights[4] && $rights[2])//is_canviewchatm is_canaddchatm
  22. {
  23. if($edit_mode)
  24. {
  25. $to_user_id=$to_room=0;
  26. }
  27. if($config['ppkbb_chat_autokill_onpost'] && !$rights[10] && ($dt - $chat_user['lastpost']) < $config['ppkbb_chat_waittime'] - 1 && !$edit_mode)
  28. {
  29. userkick(2);
  30. }
  31. else
  32. {
  33. if(!$acommand)
  34. {
  35. //$chat_message = str_replace('-', '&minus;', $chat_message);
  36. //$chat_user['username'] = str_replace('-', '&minus;', $chat_user['username']);
  37. intval($config['ppkbb_chat_messlength']) ? '' : $config['ppkbb_chat_messlength']=255;
  38. $mbstring=extension_loaded('mbstring') ? 1 : 0;
  39. $chat_message_len=$mbstring ? mbstring_utf8_strlen($chat_message) : utf8_strlen($chat_message);
  40. if($chat_message_len > $config['ppkbb_chat_messlength'])
  41. {
  42. $chat_message=$mbstring ? mbstring_utf8_substr($chat_message, 0, $config['ppkbb_chat_messlength']) : utf8_substr($chat_message, 0, $config['ppkbb_chat_messlength']);
  43. }
  44. if($to_user_id && ((@!$users[$to_user_id] && !$rights[14])/* || @$users[$to_user_id]['user_hidden']*/ || @$users[$to_user_id]['lastaccess'] > $dt))
  45. {
  46. $to_user_id=0;
  47. }
  48. else
  49. {
  50. !$config['ppkbb_chat_enable_bbcodes'] || !$rights[12] ? $chat_message=preg_replace('#\[/?(b|i|u|pre|samp|code|colou?r(=[^\[]+)?|size(=[^\[]+)?|noparse|url(=[^\[]+)?|s|q|blockquote)\]#', '', $chat_message) : '';
  51. !$config['ppkbb_chat_enable_bbcodes'] || !$rights[17] ? $chat_message=preg_replace('#\[/?img(=[^\[]+)?\]#', '', $chat_message) : '';
  52. $chat_message=preg_replace('/sid=([a-zA-Z0-9]{32})(&amp;)?/', '', $chat_message);
  53. if($chat_message!=='')
  54. {
  55. if(!$edit_mode)
  56. {
  57. $sql='INSERT INTO ' .TRACKER_CHATMESSAGES_TABLE. " (message, user_id, to_user, date, rights, room, username, user_color, user_ip) VALUES ('".mysql_real_escape_string($chat_message, $c)."', '{$chat_user['user_id']}', '".($rights[9] && $to_user_id ? $to_user_id : 0)."', '{$dt}', '{$chat_user['rights']}', '{$forum_id}', '".mysql_real_escape_string($chat_user['username'], $c)."', '{$chat_user['user_color']}', INET_ATON('".mysql_real_escape_string($_SERVER['REMOTE_ADDR'], $c)."'))";
  58. $result=my_sql_query($sql);
  59. $lastpost=$dt;
  60. }
  61. else
  62. {
  63. $sql='UPDATE ' .TRACKER_CHATMESSAGES_TABLE. " SET message='".mysql_real_escape_string($chat_message, $c)."', edited_by='{$chat_user['user_id']}' WHERE id='{$edit_mode}' AND (to_user='0' OR to_user='{$chat_user['user_id']}')".(!$rights[19] ? " AND user_id='{$chat_user['user_id']}'" : '').(!$config['ppkbb_chat_bot'][2] ? " AND user_id!='0'" : '');
  64. $result=my_sql_query($sql);
  65. if(mysql_affected_rows($c) && $config['ppkbb_chat_logs'][4])
  66. {
  67. $sql='SELECT room, user_id FROM ' .TRACKER_CHATMESSAGES_TABLE. " WHERE id='{$edit_mode}' AND (to_user='0' OR to_user='{$chat_user['user_id']}')".(!$rights[19] ? " AND user_id='{$chat_user['user_id']}'" : '').(!$config['ppkbb_chat_bot'][2] ? " AND user_id!='0'" : '');
  68. $result=my_sql_query($sql);
  69. $edit_data=mysql_fetch_array($result);
  70. mysql_free_result($result);
  71. if($edit_data)
  72. {
  73. $edit_data['user_id'] > 1 ? '' : $edit_data['user_id']=1;
  74. include_once($phpbb_root_path.'chat/include/caddlogchat.'.$phpEx);
  75. chat_add_log(3, $chat_user['user_id'], my_int_val($edit_data['room']), mysql_real_escape_string($edit_data['user_id'], $c), 'LOG_CHAT_EDITMESS', '');
  76. }
  77. }
  78. }
  79. $skip_lacheck=1;
  80. }
  81. }
  82. }
  83. }
  84. }
  85. else
  86. {
  87. userkick(3);
  88. }
  89. //############################################################
  90. //From includes/utf/utf_tools.php
  91. function mbstring_utf8_substr($str, $offset, $length = null)
  92. {
  93. if (is_null($length))
  94. {
  95. return mb_substr($str, $offset);
  96. }
  97. else
  98. {
  99. return mb_substr($str, $offset, $length);
  100. }
  101. }
  102. //From includes/utf/utf_tools.php
  103. function mbstring_utf8_strlen($text)
  104. {
  105. return mb_strlen($text, 'utf-8');
  106. }
  107. //From includes/utf/utf_tools.php
  108. function utf8_substr($str, $offset, $length = NULL)
  109. {
  110. // generates E_NOTICE
  111. // for PHP4 objects, but not PHP5 objects
  112. $str = (string) $str;
  113. $offset = (int) $offset;
  114. if (!is_null($length))
  115. {
  116. $length = (int) $length;
  117. }
  118. // handle trivial cases
  119. if ($length === 0 || ($offset < 0 && $length < 0 && $length < $offset))
  120. {
  121. return '';
  122. }
  123. // normalise negative offsets (we could use a tail
  124. // anchored pattern, but they are horribly slow!)
  125. if ($offset < 0)
  126. {
  127. // see notes
  128. $strlen = utf8_strlen($str);
  129. $offset = $strlen + $offset;
  130. if ($offset < 0)
  131. {
  132. $offset = 0;
  133. }
  134. }
  135. $op = '';
  136. $lp = '';
  137. // establish a pattern for offset, a
  138. // non-captured group equal in length to offset
  139. if ($offset > 0)
  140. {
  141. $ox = (int) ($offset / 65535);
  142. $oy = $offset % 65535;
  143. if ($ox)
  144. {
  145. $op = '(?:.{65535}){' . $ox . '}';
  146. }
  147. $op = '^(?:' . $op . '.{' . $oy . '})';
  148. }
  149. else
  150. {
  151. // offset == 0; just anchor the pattern
  152. $op = '^';
  153. }
  154. // establish a pattern for length
  155. if (is_null($length))
  156. {
  157. // the rest of the string
  158. $lp = '(.*)$';
  159. }
  160. else
  161. {
  162. if (!isset($strlen))
  163. {
  164. // see notes
  165. $strlen = utf8_strlen($str);
  166. }
  167. // another trivial case
  168. if ($offset > $strlen)
  169. {
  170. return '';
  171. }
  172. if ($length > 0)
  173. {
  174. // reduce any length that would
  175. // go passed the end of the string
  176. $length = min($strlen - $offset, $length);
  177. $lx = (int) ($length / 65535);
  178. $ly = $length % 65535;
  179. // negative length requires a captured group
  180. // of length characters
  181. if ($lx)
  182. {
  183. $lp = '(?:.{65535}){' . $lx . '}';
  184. }
  185. $lp = '(' . $lp . '.{'. $ly . '})';
  186. }
  187. else if ($length < 0)
  188. {
  189. if ($length < ($offset - $strlen))
  190. {
  191. return '';
  192. }
  193. $lx = (int)((-$length) / 65535);
  194. $ly = (-$length) % 65535;
  195. // negative length requires ... capture everything
  196. // except a group of -length characters
  197. // anchored at the tail-end of the string
  198. if ($lx)
  199. {
  200. $lp = '(?:.{65535}){' . $lx . '}';
  201. }
  202. $lp = '(.*)(?:' . $lp . '.{' . $ly . '})$';
  203. }
  204. }
  205. if (!preg_match('#' . $op . $lp . '#us', $str, $match))
  206. {
  207. return '';
  208. }
  209. return $match[1];
  210. }
  211. ?>