topic.py 5.4 KB

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