topic.py 5.4 KB

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