topic.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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(db_change("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(db_change("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(db_change("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(db_change("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(db_change("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(db_change('insert into alarm (name, data, date) values (?, ?, ?)'), [
  45. match.groups()[0],
  46. ip + ' | <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '">' + name + ' | ' + sub + ' | #' + str(num) + '</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(db_change("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(db_change('insert into alarm (name, data, date) values (?, ?, ?)'), [
  56. ip_data[0][0],
  57. ip + ' | <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#' + str(num) + '">' + name + ' | ' + sub + ' | #' + str(num) + '</a>',
  58. today
  59. ])
  60. data = re.sub("(?P<in>#(?:[0-9]+))", '[[\g<in>]]', data)
  61. data = savemark(data)
  62. rd_plus(name, sub, today)
  63. curs.execute(db_change("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, ?, ?, ?, '', '')"), [str(num), name, sub, data, today, ip])
  64. conn.commit()
  65. return redirect('/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '#reload')
  66. else:
  67. data = ''
  68. curs.execute(db_change("select stop from rd where title = ? and sub = ? and stop != ''"), [name, sub])
  69. close_data = curs.fetchall()
  70. if (close_data and admin != 1) or topic_check(name, sub) == 1:
  71. display = 'display: none;'
  72. else:
  73. display = ''
  74. data += '''
  75. <div id="top_topic"></div>
  76. <div id="main_topic"></div>
  77. <div id="plus_topic"></div>
  78. <script>topic_top_load("''' + name + '''", "''' + sub + '''");</script>
  79. <a href="/topic/''' + url_pas(name) + '''/sub/''' + url_pas(sub) + '''/tool">(''' + load_lang('topic_tool') + ''')</a>
  80. <hr class=\"main_hr\">
  81. <form style="''' + display + '''" method="post">
  82. <textarea id="content" style="height: 100px;" name="content"></textarea>
  83. <hr class=\"main_hr\">
  84. ''' + captcha_get() + (ip_warring() if display == '' else '') + '''
  85. <button type="submit">''' + load_lang('send') + '''</button>
  86. <button id="preview" type="button" onclick="load_preview(\'''' + url_pas(name) + '\')">' + load_lang('preview') + '''</button>
  87. </form>
  88. <hr class=\"main_hr\">
  89. <div id="see_preview"></div>
  90. '''
  91. return easy_minify(flask.render_template(skin_check(),
  92. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('discussion') + ')', 0])],
  93. data = '''
  94. <h2 id="topic_top_title">''' + sub + '''</h2>
  95. ''' + data,
  96. menu = [['topic/' + url_pas(name), load_lang('list')]]
  97. ))