topic.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. from .tool.func import *
  2. def topic_2(conn, topic_num):
  3. curs = conn.cursor()
  4. admin = admin_check(3)
  5. topic_num = str(topic_num)
  6. if flask.request.method == 'POST':
  7. name = flask.request.form.get('topic', 'test')
  8. sub = flask.request.form.get('title', 'test')
  9. else:
  10. curs.execute(db_change("select title, sub from topic where code = ? and id = '1'"), [topic_num])
  11. name = curs.fetchall()
  12. if name:
  13. sub = name[0][1]
  14. name = name[0][0]
  15. else:
  16. return redirect('/')
  17. ban = acl_check(name, 'topic', topic_num)
  18. if flask.request.method == 'POST':
  19. if captcha_post(flask.request.form.get('g-recaptcha-response', '')) == 1:
  20. return re_error('/error/13')
  21. else:
  22. captcha_post('', 0)
  23. ip = ip_check()
  24. today = get_time()
  25. if ban == 1:
  26. return re_error('/ban')
  27. curs.execute(db_change("select id from topic where code = ? order by id + 0 desc limit 1"), [topic_num])
  28. old_num = curs.fetchall()
  29. if old_num:
  30. num = int(old_num[0][0]) + 1
  31. else:
  32. num = 1
  33. num = str(num)
  34. match = re.search('^user:([^/]+)', name)
  35. if match:
  36. y_check = 0
  37. if ip_or_user(match.groups()[0]) == 1:
  38. curs.execute(db_change("select ip from history where ip = ? limit 1"), [match.groups()[0]])
  39. u_data = curs.fetchall()
  40. if u_data:
  41. y_check = 1
  42. else:
  43. curs.execute(db_change("select ip from topic where ip = ? limit 1"), [match.groups()[0]])
  44. u_data = curs.fetchall()
  45. if u_data:
  46. y_check = 1
  47. else:
  48. curs.execute(db_change("select id from user where id = ?"), [match.groups()[0]])
  49. u_data = curs.fetchall()
  50. if u_data:
  51. y_check = 1
  52. if y_check == 1:
  53. curs.execute(db_change('insert into alarm (name, data, date) values (?, ?, ?)'), [
  54. match.groups()[0],
  55. ip + ' | <a href="/thread/' + topic_num + '#' + num + '">' + name + ' | ' + sub + ' | #' + num + '</a>',
  56. today
  57. ])
  58. cate_re = re.compile('\[\[((?:분류|category):(?:(?:(?!\]\]).)*))\]\]', re.I)
  59. data = cate_re.sub('[br]', flask.request.form.get('content', 'Test'))
  60. for rd_data in re.findall("(?:#([0-9]+))", data):
  61. curs.execute(db_change("select ip from topic where code = ? and id = ?"), [topic_num, rd_data])
  62. ip_data = curs.fetchall()
  63. if ip_data and ip_or_user(ip_data[0][0]) == 0:
  64. curs.execute(db_change('insert into alarm (name, data, date) values (?, ?, ?)'), [
  65. ip_data[0][0],
  66. ip + ' | <a href="/thread/' + topic_num + '#' + num + '">' + name + ' | ' + sub + ' | #' + num + '</a>',
  67. today
  68. ])
  69. data = re.sub("(?P<in>#(?:[0-9]+))", '[[\g<in>]]', data)
  70. data = savemark(data)
  71. rd_plus(topic_num, today)
  72. curs.execute(db_change("insert into topic (id, title, sub, data, date, ip, code) values (?, ?, ?, ?, ?, ?, ?)"), [
  73. num,
  74. name if num == 1 else '',
  75. sub if num == 1 else '',
  76. data,
  77. today,
  78. ip,
  79. topic_num
  80. ])
  81. conn.commit()
  82. return redirect('/thread/' + topic_num + '?where=bottom')
  83. else:
  84. data = ''
  85. curs.execute(db_change("select stop from rd where code = ? and stop != ''"), [topic_num])
  86. close_data = curs.fetchall()
  87. if (close_data and admin != 1) or ban == 1:
  88. display = 'display: none;'
  89. else:
  90. display = ''
  91. data += '''
  92. <div id="top_topic"></div>
  93. <div id="main_topic"></div>
  94. <div id="plus_topic"></div>
  95. <script>topic_top_load("''' + topic_num + '''");</script>
  96. <a href="/thread/''' + topic_num + '/tool">(' + load_lang('topic_tool') + ''')</a>
  97. <hr class=\"main_hr\">
  98. <form style="''' + display + '''" method="post">
  99. <textarea rows="10" id="content" placeholder="''' + load_lang('content') + '''" name="content"></textarea>
  100. <hr class=\"main_hr\">
  101. ''' + captcha_get() + (ip_warring() if display == '' else '') + '''
  102. <input style="display: none;" name="topic" value="''' + name + '''">
  103. <input style="display: none;" name="title" value="''' + sub + '''">
  104. <button type="submit">''' + load_lang('send') + '''</button>
  105. <button id="preview" type="button" onclick="load_preview(\'\')">''' + load_lang('preview') + '''</button>
  106. </form>
  107. <hr class=\"main_hr\">
  108. <div id="see_preview"></div>
  109. '''
  110. return easy_minify(flask.render_template(skin_check(),
  111. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('discussion') + ')', 0])],
  112. data = '''
  113. <h2 id="topic_top_title">''' + sub + '''</h2>
  114. ''' + data,
  115. menu = [['topic/' + url_pas(name), load_lang('list')]]
  116. ))