bbs_w_edit.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. from .tool.func import *
  2. from .api_bbs_w_post import api_bbs_w_post
  3. from .api_bbs_w_comment_one import api_bbs_w_comment_one
  4. from .edit import edit_editor
  5. def bbs_w_edit(bbs_num = '', post_num = '', comment_num = ''):
  6. with get_db_connect() as conn:
  7. curs = conn.cursor()
  8. bbs_num_str = str(bbs_num)
  9. post_num_str = str(post_num)
  10. ip = ip_check()
  11. curs.execute(db_change('select set_id from bbs_set where set_id = ? and set_name = "bbs_name"'), [bbs_num_str])
  12. if not curs.fetchall():
  13. return redirect(conn, '/bbs/main')
  14. if comment_num != '':
  15. temp_dict = json.loads(api_bbs_w_comment_one(bbs_num_str + '-' + post_num_str + '-' + comment_num).data)
  16. if 'comment_user_id' in temp_dict:
  17. if not temp_dict['comment_user_id'] == ip and admin_check(conn) != 1:
  18. return re_error(conn, '/ban')
  19. else:
  20. return redirect(conn, '/bbs/main')
  21. elif post_num != '':
  22. temp_dict = json.loads(api_bbs_w_post(bbs_num_str + '-' + post_num_str).data)
  23. if 'user_id' in temp_dict:
  24. if not temp_dict['user_id'] == ip and admin_check(conn) != 1:
  25. return re_error(conn, '/ban')
  26. else:
  27. return redirect(conn, '/bbs/main')
  28. if acl_check(bbs_num_str, 'bbs_edit') == 1:
  29. return redirect(conn, '/bbs/set/' + bbs_num_str)
  30. i_list = ['post_view_acl', 'post_comment_acl']
  31. if flask.request.method == 'POST':
  32. if captcha_post(conn, flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
  33. return re_error(conn, '/error/13')
  34. else:
  35. captcha_post(conn, '', 0)
  36. if post_num == '':
  37. curs.execute(db_change('select set_code from bbs_data where set_name = "title" and set_id = ? order by set_code + 0 desc'), [bbs_num_str])
  38. db_data = curs.fetchall()
  39. id_data = str(int(db_data[0][0]) + 1) if db_data else '1'
  40. else:
  41. id_data = post_num_str
  42. title = flask.request.form.get('title', 'test')
  43. title = 'test' if title == '' else title
  44. data = flask.request.form.get('content', '')
  45. if data == '':
  46. # re_error로 대체 예정
  47. return redirect(conn, '/bbs/in/' + bbs_num_str)
  48. if do_edit_filter(conn, title) == 1:
  49. return re_error(conn, '/error/21')
  50. if do_edit_filter(conn, data) == 1:
  51. return re_error(conn, '/error/21')
  52. date = get_time()
  53. if comment_num != '':
  54. sub_code = (bbs_num_str + '-' + post_num_str + '-' + comment_num).split('-')
  55. sub_code_last = ''
  56. if len(sub_code) > 2:
  57. sub_code_last = sub_code[len(sub_code) - 1]
  58. del sub_code[len(sub_code) - 1]
  59. sub_code = '-'.join(sub_code)
  60. curs.execute(db_change("update bbs_data set set_data = ? where set_name = 'comment' and set_code = ? and set_id = ?"), [data, sub_code_last, sub_code])
  61. elif post_num == '':
  62. curs.execute(db_change("insert into bbs_data (set_name, set_code, set_id, set_data) values ('title', ?, ?, ?)"), [id_data, bbs_num_str, title])
  63. curs.execute(db_change("insert into bbs_data (set_name, set_code, set_id, set_data) values ('data', ?, ?, ?)"), [id_data, bbs_num_str, data])
  64. curs.execute(db_change("insert into bbs_data (set_name, set_code, set_id, set_data) values ('date', ?, ?, ?)"), [id_data, bbs_num_str, date])
  65. curs.execute(db_change("insert into bbs_data (set_name, set_code, set_id, set_data) values ('user_id', ?, ?, ?)"), [id_data, bbs_num_str, ip])
  66. else:
  67. curs.execute(db_change("update bbs_data set set_data = ? where set_name = 'title' and set_code = ? and set_id = ?"), [title, post_num, bbs_num_str])
  68. curs.execute(db_change("update bbs_data set set_data = ? where set_name = 'data' and set_code = ? and set_id = ?"), [data, id_data, bbs_num_str])
  69. curs.execute(db_change("update bbs_data set set_data = ? where set_name = 'date' and set_code = ? and set_id = ?"), [date, id_data, bbs_num_str])
  70. if comment_num != '':
  71. return redirect(conn, '/bbs/w/' + bbs_num_str + '/' + id_data + '#' + url_pas(comment_num))
  72. else:
  73. return redirect(conn, '/bbs/w/' + bbs_num_str + '/' + id_data)
  74. else:
  75. option_display = ''
  76. if comment_num != '':
  77. temp_dict = json.loads(api_bbs_w_comment_one(bbs_num_str + '-' + post_num_str + '-' + comment_num).data)
  78. title = ''
  79. data = temp_dict['comment']
  80. option_display = 'display: none;'
  81. elif post_num == '':
  82. title = ''
  83. data = ''
  84. else:
  85. temp_dict = json.loads(api_bbs_w_post(bbs_num_str + '-' + post_num_str).data)
  86. title = temp_dict['title']
  87. data = temp_dict['data']
  88. acl_div = ['' for _ in range(0, len(i_list))]
  89. acl_list = get_acl_list()
  90. for for_a in range(0, len(i_list)):
  91. for data_list in acl_list:
  92. acl_div[for_a] += '<option value="' + data_list + '">' + (data_list if data_list != '' else 'normal') + '</option>'
  93. editor_top_text = '<a href="/filter/edit_filter">(' + get_lang(conn, 'edit_filter_rule') + ')</a>'
  94. if editor_top_text != '':
  95. editor_top_text += '<hr class="main_hr">'
  96. if comment_num != '':
  97. bbs_title = get_lang(conn, 'bbs_comment_edit')
  98. elif post_num == '':
  99. bbs_title = get_lang(conn, 'post_add')
  100. else:
  101. bbs_title = get_lang(conn, 'post_edit')
  102. return easy_minify(conn, flask.render_template(skin_check(conn),
  103. imp = [bbs_title, wiki_set(conn), wiki_custom(conn), wiki_css([0, 0])],
  104. data = editor_top_text + '''
  105. <form method="post">
  106. <input style="''' + option_display + '''" placeholder="''' + get_lang(conn, 'title') + '''" name="title" value="''' + html.escape(title) + '''">
  107. <hr style="''' + option_display + '''" class="main_hr">
  108. ''' + edit_editor(conn, ip, data, 'bbs') + '''
  109. <!--
  110. <div style="''' + option_display + '''">
  111. ''' + render_simple_set(conn, '''
  112. <hr class="main_hr">
  113. <a href="/acl/TEST#exp">(''' + get_lang(conn, 'reference') + ''')</a>
  114. <h2>''' + get_lang(conn, 'acl') + '''</h2>
  115. <h3>''' + get_lang(conn, 'post_view_acl') + '''</h3>
  116. <select name="post_view_acl">''' + acl_div[0] + '''</select>
  117. <h4>''' + get_lang(conn, 'post_comment_acl') + '''</h4>
  118. <select name="post_comment_acl">''' + acl_div[1] + '''</select>
  119. <h2>''' + get_lang(conn, 'markup') + '''</h2>
  120. ''' + get_lang(conn, 'not_working') + '''
  121. ''') + '''
  122. </div>
  123. -->
  124. </form>
  125. ''',
  126. menu = [['bbs/in/' + bbs_num_str, get_lang(conn, 'return')]]
  127. ))