bbs_w_edit.py 7.7 KB

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