topic.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. from .tool.func import *
  2. def topic_2(conn, name, sub):
  3. curs = conn.cursor()
  4. ban = topic_check(name, sub)
  5. admin = admin_check(3)
  6. curs.execute("select id from topic where title = ? and sub = ? limit 1", [name, sub])
  7. topic_exist = curs.fetchall()
  8. if not topic_exist and len(sub) > 256:
  9. return re_error('/error/11')
  10. if flask.request.method == 'POST':
  11. if captcha_post(flask.request.form.get('g-recaptcha-response', '')) == 1:
  12. return re_error('/error/13')
  13. else:
  14. captcha_post('', 0)
  15. ip = ip_check()
  16. today = get_time()
  17. if ban == 1:
  18. return re_error('/ban')
  19. curs.execute("select id from topic where title = ? and sub = ? order by id + 0 desc limit 1", [name, sub])
  20. old_num = curs.fetchall()
  21. if old_num:
  22. num = int(old_num[0][0]) + 1
  23. else:
  24. num = 1
  25. match = re.search('^user:([^/]+)', name)
  26. if match:
  27. y_check = 0
  28. if ip_or_user(match.groups()[0]) == 1:
  29. curs.execute("select ip from history where ip = ? limit 1", [match.groups()[0]])
  30. u_data = curs.fetchall()
  31. if u_data:
  32. y_check = 1
  33. else:
  34. curs.execute("select ip from topic where ip = ? limit 1", [match.groups()[0]])
  35. u_data = curs.fetchall()
  36. if u_data:
  37. y_check = 1
  38. else:
  39. curs.execute("select id from user where id = ?", [match.groups()[0]])
  40. u_data = curs.fetchall()
  41. if u_data:
  42. y_check = 1
  43. if y_check == 1:
  44. curs.execute('insert into alarm (name, data, date) values (?, ?, ?)', [
  45. match.groups()[0],
  46. ip + ' - <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '">' + load_lang('user_discussion', 1) + '</a>',
  47. today
  48. ])
  49. cate_re = re.compile('\[\[((?:분류|category):(?:(?:(?!\]\]).)*))\]\]', re.I)
  50. data = cate_re.sub('[br]', flask.request.form.get('content', 'Test'))
  51. for rd_data in re.findall("(?:#([0-9]+))", data):
  52. curs.execute("select ip from topic where title = ? and sub = ? and id = ?", [name, sub, rd_data])
  53. ip_data = curs.fetchall()
  54. if ip_data and ip_or_user(ip_data[0][0]) == 0:
  55. curs.execute('insert into alarm (name, data, date) values (?, ?, ?)', [ip_data[0][0], ip + ' - <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#' + str(num) + '">' + load_lang('discussion', 1) + '</a>', today])
  56. data = re.sub("(?P<in>#(?:[0-9]+))", '[[\g<in>]]', data)
  57. data = savemark(data)
  58. rd_plus(name, sub, today)
  59. curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, ?, ?, ?, '', '')", [str(num), name, sub, data, today, ip])
  60. conn.commit()
  61. return redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#reload')
  62. else:
  63. curs.execute("select title from rd where title = ? and sub = ? and stop = 'O'", [name, sub])
  64. close_data = curs.fetchall()
  65. curs.execute("select title from rd where title = ? and sub = ? and stop = 'S'", [name, sub])
  66. stop_data = curs.fetchall()
  67. display = ''
  68. all_data = ''
  69. data = ''
  70. number = 1
  71. if (close_data or stop_data) and admin != 1:
  72. display = 'display: none;'
  73. curs.execute("select data, id, date, ip, block, top from topic where title = ? and sub = ? order by id + 0 asc", [name, sub])
  74. topic = curs.fetchall()
  75. curs.execute("select data, id, date, ip from topic where title = ? and sub = ? and top = 'O' order by id + 0 asc", [name, sub])
  76. for topic_data in curs.fetchall():
  77. who_plus = ''
  78. curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['notice (' + name + ' - ' + sub + '#' + topic_data[1] + ')'])
  79. topic_data_top = curs.fetchall()
  80. if topic_data_top:
  81. who_plus += ' <span style="margin-right: 5px;">@' + topic_data_top[0][0] + ' </span>'
  82. all_data += '''
  83. <table id="toron">
  84. <tbody>
  85. <tr>
  86. <td id="toron_color_red">
  87. <a href="#''' + topic_data[1] + '''">
  88. #''' + topic_data[1] + '''
  89. </a> ''' + ip_pas(topic_data[3]) + who_plus + ''' <span style="float: right;">''' + topic_data[2] + '''</span>
  90. </td>
  91. </tr>
  92. <tr>
  93. <td>''' + render_set(data = topic_data[0]) + '''</td>
  94. </tr>
  95. </tbody>
  96. </table>
  97. <hr class=\"main_hr\">
  98. '''
  99. for topic_data in topic:
  100. user_write = topic_data[0]
  101. if number == 1:
  102. start = topic_data[3]
  103. if topic_data[4] == 'O':
  104. blind_data = 'id="toron_color_grey"'
  105. if admin != 1:
  106. curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['blind (' + name + ' - ' + sub + '#' + str(number) + ')'])
  107. who_blind = curs.fetchall()
  108. if who_blind:
  109. user_write = '[[user:' + who_blind[0][0] + ']] ' + load_lang('hide')
  110. else:
  111. user_write = load_lang('hide')
  112. else:
  113. blind_data = ''
  114. user_write = render_set(data = user_write)
  115. ip = ip_pas(topic_data[3])
  116. curs.execute('select acl from user where id = ?', [topic_data[3]])
  117. user_acl = curs.fetchall()
  118. if user_acl and user_acl[0][0] != 'user':
  119. ip += ' <a href="javascript:void(0);" title="' + load_lang('admin') + '">★</a>'
  120. if admin == 1 or blind_data == '':
  121. ip += ' <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/admin/' + str(number) + '">(' + load_lang('discussion_tool') + ')</a>'
  122. curs.execute("select end from ban where block = ?", [topic_data[3]])
  123. if curs.fetchall():
  124. ip += ' <a href="javascript:void(0);" title="' + load_lang('blocked') + '">†</a>'
  125. if topic_data[5] == '1':
  126. color = '_blue'
  127. elif topic_data[3] == start:
  128. color = '_green'
  129. else:
  130. color = ''
  131. if user_write == '':
  132. user_write = '<br>'
  133. all_data += '''
  134. <table id="toron">
  135. <tbody>
  136. <tr>
  137. <td id="toron_color''' + color + '''">
  138. <a href="javascript:void(0);" id="''' + str(number) + '">#' + str(number) + '</a> ' + ip + '''</span>
  139. </td>
  140. </tr>
  141. <tr ''' + blind_data + '''>
  142. <td>''' + user_write + '''</td>
  143. </tr>
  144. </tbody>
  145. </table>
  146. <hr class=\"main_hr\">
  147. '''
  148. number += 1
  149. if ban != 1 or admin == 1:
  150. data += '''
  151. <div id="plus"></div>
  152. <script>topic_load("''' + name + '''", "''' + sub + '''", "''' + str(number) + '''");</script>
  153. <a id="reload" href="javascript:void(0);" onclick="reload();">(''' + load_lang('reload') + ''')</a> <a href="/topic/''' + url_pas(name) + '''/sub/''' + url_pas(sub) + '''/tool">(''' + load_lang('topic_tool') + ''')</a>
  154. <hr class=\"main_hr\">
  155. <form style="''' + display + '''" method="post">
  156. <textarea style="height: 100px;" name="content"></textarea>
  157. <hr class=\"main_hr\">
  158. ''' + captcha_get() + (ip_warring() if display == '' else '') + '''
  159. <button type="submit">''' + load_lang('send') + '''</button>
  160. </form>
  161. '''
  162. return easy_minify(flask.render_template(skin_check(),
  163. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('discussion') + ')', 0])],
  164. data = '<h2 id="topic_top_title">' + sub + '</h2>' + all_data + data,
  165. menu = [['topic/' + url_pas(name), load_lang('list')]]
  166. ))