2
0

topic.py 4.5 KB

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