topic.py 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 admin == 1 and topic_exist:
  72. if close_data:
  73. all_data += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/close">(' + load_lang('open') + ')</a> '
  74. else:
  75. all_data += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/close">(' + load_lang('close') + ')</a> '
  76. if stop_data:
  77. all_data += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/stop">(' + load_lang('restart') + ')</a> '
  78. else:
  79. all_data += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/stop">(' + load_lang('stop') + ')</a> '
  80. curs.execute("select title from rd where title = ? and sub = ? and agree = 'O'", [name, sub])
  81. if curs.fetchall():
  82. all_data += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/agree">(' + load_lang('destruction') + ')</a>'
  83. else:
  84. all_data += '<a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/tool/agree">(' + load_lang('agreement') + ')</a>'
  85. all_data += '<hr class=\"main_hr\">'
  86. if (close_data or stop_data) and admin != 1:
  87. display = 'display: none;'
  88. curs.execute("select data, id, date, ip, block, top from topic where title = ? and sub = ? order by id + 0 asc", [name, sub])
  89. topic = curs.fetchall()
  90. curs.execute("select data, id, date, ip from topic where title = ? and sub = ? and top = 'O' order by id + 0 asc", [name, sub])
  91. for topic_data in curs.fetchall():
  92. who_plus = ''
  93. curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['notice (' + name + ' - ' + sub + '#' + topic_data[1] + ')'])
  94. topic_data_top = curs.fetchall()
  95. if topic_data_top:
  96. who_plus += ' <span style="margin-right: 5px;">@' + topic_data_top[0][0] + ' </span>'
  97. all_data += '''
  98. <table id="toron">
  99. <tbody>
  100. <tr>
  101. <td id="toron_color_red">
  102. <a href="#''' + topic_data[1] + '''">
  103. #''' + topic_data[1] + '''
  104. </a> ''' + ip_pas(topic_data[3]) + who_plus + ''' <span style="float: right;">''' + topic_data[2] + '''</span>
  105. </td>
  106. </tr>
  107. <tr>
  108. <td>''' + render_set(data = topic_data[0]) + '''</td>
  109. </tr>
  110. </tbody>
  111. </table>
  112. <hr class=\"main_hr\">
  113. '''
  114. for topic_data in topic:
  115. user_write = topic_data[0]
  116. if number == 1:
  117. start = topic_data[3]
  118. if topic_data[4] == 'O':
  119. blind_data = 'id="toron_color_grey"'
  120. if admin != 1:
  121. curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['blind (' + name + ' - ' + sub + '#' + str(number) + ')'])
  122. who_blind = curs.fetchall()
  123. if who_blind:
  124. user_write = '[[user:' + who_blind[0][0] + ']] ' + load_lang('hide')
  125. else:
  126. user_write = load_lang('hide')
  127. else:
  128. blind_data = ''
  129. user_write = render_set(data = user_write)
  130. ip = ip_pas(topic_data[3])
  131. curs.execute('select acl from user where id = ?', [topic_data[3]])
  132. user_acl = curs.fetchall()
  133. if user_acl and user_acl[0][0] != 'user':
  134. ip += ' <a href="javascript:void(0);" title="' + load_lang('admin') + '">★</a>'
  135. if admin == 1 or blind_data == '':
  136. ip += ' <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/admin/' + str(number) + '">(' + load_lang('discussion_tool') + ')</a>'
  137. curs.execute("select end from ban where block = ?", [topic_data[3]])
  138. if curs.fetchall():
  139. ip += ' <a href="javascript:void(0);" title="' + load_lang('blocked') + '">†</a>'
  140. if topic_data[5] == '1':
  141. color = '_blue'
  142. elif topic_data[3] == start:
  143. color = '_green'
  144. else:
  145. color = ''
  146. if user_write == '':
  147. user_write = '<br>'
  148. all_data += '''
  149. <table id="toron">
  150. <tbody>
  151. <tr>
  152. <td id="toron_color''' + color + '''">
  153. <a href="javascript:void(0);" id="''' + str(number) + '">#' + str(number) + '</a> ' + ip + '''</span>
  154. </td>
  155. </tr>
  156. <tr ''' + blind_data + '''>
  157. <td>''' + user_write + '''</td>
  158. </tr>
  159. </tbody>
  160. </table>
  161. <hr class=\"main_hr\">
  162. '''
  163. number += 1
  164. if ban != 1 or admin == 1:
  165. data += '''
  166. <div id="plus"></div>
  167. <script>topic_load("''' + name + '''", "''' + sub + '''", "''' + str(number) + '''");</script>
  168. <a id="reload" href="javascript:void(0);" onclick="location.href.endsWith(\'#reload\')? location.reload(true):location.href=\'#reload\'">(''' + load_lang('reload') + ''')</a>
  169. <hr class=\"main_hr\">
  170. <form style="''' + display + '''" method="post">
  171. <textarea style="height: 100px;" name="content"></textarea>
  172. <hr class=\"main_hr\">
  173. ''' + captcha_get()
  174. if display == '':
  175. data += ip_warring()
  176. data += '''
  177. <button type="submit">''' + load_lang('send') + '''</button>
  178. </form>
  179. '''
  180. return easy_minify(flask.render_template(skin_check(),
  181. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('discussion') + ')', 0])],
  182. data = '<h2 id="topic_top_title">' + sub + '</h2>' + all_data + data,
  183. menu = [['topic/' + url_pas(name), load_lang('list')]]
  184. ))