PageRenderTime 49ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/Quản lý website đọc truyện online PHP/soo/includes/nt.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 204 lines | 174 code | 6 blank | 24 comment | 42 complexity | e216e0e950c9877cafd6806f3f31632c MD5 | raw file
  1. <?php
  2. /*
  3. WMR: R118530587041
  4. ICQ: 365848916
  5. Автор: VladiSs
  6. Сайт: http://wapnex.ru
  7. */
  8. defined('_IN_JOHNCMS') or die('Error: restricted access');
  9. /*
  10. -----------------------------------------------------------------
  11. Закрываем доступ для определенных ситуаций
  12. -----------------------------------------------------------------
  13. */
  14. if (!$id || !$user_id || isset($ban['1']) || isset($ban['11']) || (!core::$user_rights && $set['mod_forum'] == 3)) {
  15. require('../incfiles/head.php');
  16. echo functions::display_error($lng['access_forbidden']);
  17. require('../incfiles/end.php');
  18. exit;
  19. }
  20. /*
  21. -----------------------------------------------------------------
  22. Вспомогательная Функция обработки ссылок форума
  23. -----------------------------------------------------------------
  24. */
  25. function forum_link($m)
  26. {
  27. global $set;
  28. if (!isset($m[3])) {
  29. return '[url=' . $m[1] . ']' . $m[2] . '[/url]';
  30. } else {
  31. $p = parse_url($m[3]);
  32. if ('http://' . $p['host'] . $p['path'] . '?id=' == $set['homeurl'] . '../soo/?mod=forum&amp;id=') {
  33. $thid = abs(intval(preg_replace('/(.*?)id=/si', '', $m[3])));
  34. $req = mysql_query("SELECT `text` FROM `soo_forum` where `website` = '$website' AND `id`= '$thid' AND `type` = 't' AND `close` != '1'");
  35. if (mysql_num_rows($req) > 0) {
  36. $res = mysql_fetch_array($req);
  37. $name = strtr($res['text'], array(
  38. '&quot;' => '',
  39. '&amp;' => '',
  40. '&lt;' => '',
  41. '&gt;' => '',
  42. '&#039;' => '',
  43. '[' => '',
  44. ']' => ''
  45. ));
  46. if (mb_strlen($name) > 40)
  47. $name = mb_substr($name, 0, 40) . '...';
  48. return '[url=' . $m[3] . ']' . $name . '[/url]';
  49. } else {
  50. return $m[3];
  51. }
  52. } else
  53. return $m[3];
  54. }
  55. }
  56. // Проверка на флуд
  57. $flood = functions::antiflood();
  58. if ($flood) {
  59. require('../incfiles/head.php');
  60. echo functions::display_error($lng['error_flood'] . ' ' . $flood . $lng['sec'] . ', <a href="../soo/?mod=forum&amp;id=' . $id . '&amp;start=' . $start . '">' . $lng['back'] . '</a>');
  61. require('../incfiles/end.php');
  62. exit;
  63. }
  64. $req_r = mysql_query("SELECT * FROM `soo_forum` where `website` = '$website' AND `id` = '$id' AND `type` = 'r' LIMIT 1");
  65. if (!mysql_num_rows($req_r)) {
  66. require('../incfiles/head.php');
  67. echo functions::display_error($lng['error_wrong_data']);
  68. require('../incfiles/end.php');
  69. exit;
  70. }
  71. $th = isset($_POST['th']) ? functions::check(mb_substr(trim($_POST['th']), 0, 100)) : '';
  72. $msg = isset($_POST['msg']) ? trim($_POST['msg']) : '';
  73. if (isset($_POST['msgtrans'])) {
  74. $th = functions::trans($th);
  75. $msg = functions::trans($msg);
  76. }
  77. $msg = preg_replace_callback('~\\[url=(http://.+?)\\](.+?)\\[/url\\]|(http://(www.)?[0-9a-zA-Z\.-]+\.[0-9a-zA-Z]{2,6}[0-9a-zA-Z/\?\.\~&amp;_=/%-:#]*)~', 'forum_link', $msg);
  78. if (isset($_POST['submit'])) {
  79. $error = array();
  80. if (empty($th))
  81. $error[] = $lng_forum['error_topic_name'];
  82. if (mb_strlen($th) < 2)
  83. $error[] = $lng_forum['error_topic_name_lenght'];
  84. if (empty($msg))
  85. $error[] = $lng['error_empty_message'];
  86. if (mb_strlen($msg) < 4)
  87. $error[] = $lng['error_message_short'];
  88. if (!$error) {
  89. $msg = preg_replace_callback('~\\[url=(http://.+?)\\](.+?)\\[/url\\]|(http://(www.)?[0-9a-zA-Z\.-]+\.[0-9a-zA-Z]{2,6}[0-9a-zA-Z/\?\.\~&amp;_=/%-:#]*)~', 'forum_link', $msg);
  90. // Прверяем, есть ли уже такая тема в текущем разделе?
  91. if (mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_forum` where `website` = '$website' AND `type` = 't' AND `refid` = '$id' AND `text` = '$th'"), 0) > 0)
  92. $error[] = $lng_forum['error_topic_exists'];
  93. // Проверяем, не повторяется ли сообщение?
  94. $req = mysql_query("SELECT * FROM `soo_forum` where `website` = '$website' AND `user_id` = '$user_id' AND `type` = 'm' ORDER BY `time` DESC");
  95. if (mysql_num_rows($req) > 0) {
  96. $res = mysql_fetch_array($req);
  97. if ($msg == $res['text'])
  98. $error[] = $lng['error_message_exists'];
  99. }
  100. }
  101. if (!$error) {
  102. // Добавляем тему
  103. mysql_query("INSERT INTO `soo_forum` SET
  104. `refid` = '$id',
  105. `type` = 't',
  106. `time` = '" . time() . "',
  107. `user_id` = '$user_id',
  108. `from` = '$login',
  109. `text` = '$th',
  110. `sid` = '$sid',
  111. `website` = '$website'
  112. ");
  113. $rid = mysql_insert_id();
  114. // Добавляем текст поста
  115. mysql_query("INSERT INTO `soo_forum` SET
  116. `refid` = '$rid',
  117. `type` = 'm',
  118. `time` = '" . time() . "',
  119. `user_id` = '$user_id',
  120. `from` = '$login',
  121. `ip` = '" . core::$ip . "',
  122. `ip_via_proxy` = '" . core::$ip_via_proxy . "',
  123. `soft` = '" . mysql_real_escape_string($agn) . "',
  124. `text` = '" . mysql_real_escape_string($msg) . "',
  125. `sid` = '$sid',
  126. `website` = '$website'
  127. ");
  128. $postid = mysql_insert_id();
  129. // Записываем счетчик постов юзера
  130. $fpst = $datauser['postforum'] + 1;
  131. mysql_query("UPDATE `users` SET
  132. `postforum` = '$fpst',
  133. `lastpost` = '" . time() . "'
  134. where `website` = '$website' AND `id` = '$user_id'
  135. ");
  136. // Ставим метку о прочтении
  137. mysql_query("INSERT INTO `soo_forum_rdm` SET
  138. `topic_id`='$rid',
  139. `user_id`='$user_id',
  140. `time`='" . time() . "',
  141. `website` = '$website'
  142. ");
  143. if ($_POST['addfiles'] == 1)
  144. header("Location: ../soo/?mod=forum&sid=$sid&id=$postid&act=addfile");
  145. else
  146. header("Location: ../soo/?mod=forum&sid=$sid&id=$rid");
  147. } else {
  148. // Выводим сообщение об ошибке
  149. require('../incfiles/head.php');
  150. echo functions::display_error($error, '<a href="../soo/?mod=forum&amp;act=nt&amp;sid='. $sid .'&amp;id=' . $id . '">' . $lng['repeat'] . '</a>');
  151. require('../incfiles/end.php');
  152. exit;
  153. }
  154. } else {
  155. $res_r = mysql_fetch_assoc($req_r);
  156. $req_c = mysql_query("SELECT * FROM `soo_forum` where `website` = '$website' AND `id` = '" . $res_r['refid'] . "'");
  157. $res_c = mysql_fetch_assoc($req_c);
  158. require('../incfiles/head.php');
  159. if ($datauser['postforum'] == 0) {
  160. if (!isset($_GET['yes'])) {
  161. $lng_faq = core::load_lng('faq');
  162. echo '<p>' . $lng_faq['forum_rules_text'] . '</p>';
  163. echo '<p><a href="../soo/?mod=forum&amp;act=nt&amp;sid='. $sid .'&amp;id=' . $id . '&amp;yes">' . $lng_forum['agree'] . '</a> | <a href="../soo/?mod=forum&amp;id=' . $id . '">' . $lng_forum['not_agree'] . '</a></p>';
  164. require('../incfiles/end.php');
  165. exit;
  166. }
  167. }
  168. $msg_pre = functions::checkout($msg, 1, 1);
  169. if ($set_user['smileys'])
  170. $msg_pre = functions::smileys($msg_pre, $datauser['rights'] ? 1 : 0);
  171. $msg_pre = preg_replace('#\[c\](.*?)\[/c\]#si', '<div class="quote">\1</div>', $msg_pre);
  172. echo '<div class="phdr"><a href="../soo/?act=soo&amp;id=' . $sid . '"><b>Сообщество </b></a> | ' . $lng_forum['new_topic'] . '</div>';
  173. if ($msg && $th && !isset($_POST['submit']))
  174. echo '<div class="list1"><img src="http://img.infoviet.net/theme/default/images/op.gif" border="0" alt="op" /> <span style="font-weight: bold">' . $th . '</span></div>' .
  175. '<div class="list2">' . functions::display_user($datauser, array('iphide' => 1, 'header' => '<span class="gray">(' . functions::display_date(time()) . ')</span>', 'body' => $msg_pre)) . '</div>';
  176. echo '<form name="form" action="../soo/?mod=forum&amp;act=nt&amp;sid='. $sid .'&amp;id=' . $id . '" method="post">' .
  177. '<div class="gmenu">' .
  178. '<p><h3>' . $lng['section'] . '</h3>' .
  179. '<a href="../soo/?mod=forum&amp;sid='. $sid .'&amp;id=' . $res_c['id'] . '">' . $res_c['text'] . '</a> | <a href="../soo/?mod=forum&amp;sid='. $sid .'&amp;id=' . $res_r['id'] . '">' . $res_r['text'] . '</a></p>' .
  180. '<p><h3>' . $lng_forum['new_topic_name'] . '</h3>' .
  181. '<input type="text" size="20" maxlength="100" name="th" value="' . $th . '"/></p>' .
  182. '<p><h3>' . $lng_forum['post'] . '</h3>';
  183. if (!$is_mobile)
  184. echo '</p><p>' . bbcode::auto_bb('form', 'msg');
  185. echo '<textarea rows="' . $set_user['field_h'] . '" name="msg">' . (isset($_POST['msg']) ? functions::checkout($_POST['msg']) : '') . '</textarea></p>' .
  186. '<p><input type="checkbox" name="addfiles" value="1" ' . (isset($_POST['addfiles']) ? 'checked="checked" ' : '') . '/> ' . $lng_forum['add_file'];
  187. if ($set_user['translit'])
  188. echo '<br /><input type="checkbox" name="msgtrans" value="1" ' . (isset($_POST['msgtrans']) ? 'checked="checked" ' : '') . '/> ' . $lng['translit'];
  189. echo '</p><p><input type="submit" name="submit" value="' . $lng['save'] . '" style="width: 107px; cursor: pointer;"/> ' .
  190. ($set_forum['preview'] ? '<input type="submit" value="' . $lng['preview'] . '" style="width: 107px; cursor: pointer;"/>' : '') .
  191. '</p></div></form>' .
  192. '<div class="phdr"><a href="../pages/faq.php?act=trans">' . $lng['translit'] . '</a> | ' .
  193. '<a href="../pages/faq.php?act=smileys">' . $lng['smileys'] . '</a></div>' .
  194. '<p><a href="../soo/?mod=forum&amp;sid='. $sid .'&amp;id=' . $id . '">' . $lng['back'] . '</a></p>';
  195. }
  196. require_once('../incfiles/end.php');
  197. break;
  198. ?>