topic.py 6.0 KB

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