topic.py 9.3 KB

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