topic.py 9.2 KB

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