bbs_w_edit.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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('/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() != 1:
  18. return re_error('/ban')
  19. else:
  20. return redirect('/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() != 1:
  25. return re_error('/ban')
  26. else:
  27. return redirect('/bbs/main')
  28. if acl_check(bbs_num_str, 'bbs_edit') == 1:
  29. return redirect('/bbs/set/' + bbs_num_str)
  30. i_list = ['post_view_acl', 'post_comment_acl']
  31. if flask.request.method == 'POST':
  32. if captcha_post(flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
  33. return re_error('/error/13')
  34. else:
  35. captcha_post('', 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('/bbs/w/' + bbs_num_str)
  48. date = get_time()
  49. if comment_num != '':
  50. sub_code = (bbs_num_str + '-' + post_num_str + '-' + comment_num).split('-')
  51. sub_code_last = ''
  52. if len(sub_code) > 2:
  53. sub_code_last = sub_code[len(sub_code) - 1]
  54. del sub_code[len(sub_code) - 1]
  55. sub_code = '-'.join(sub_code)
  56. 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])
  57. elif post_num == '':
  58. curs.execute(db_change("insert into bbs_data (set_name, set_code, set_id, set_data) values ('title', ?, ?, ?)"), [id_data, bbs_num_str, title])
  59. curs.execute(db_change("insert into bbs_data (set_name, set_code, set_id, set_data) values ('data', ?, ?, ?)"), [id_data, bbs_num_str, data])
  60. curs.execute(db_change("insert into bbs_data (set_name, set_code, set_id, set_data) values ('date', ?, ?, ?)"), [id_data, bbs_num_str, date])
  61. 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])
  62. else:
  63. 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])
  64. 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])
  65. 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])
  66. if comment_num != '':
  67. return redirect('/bbs/w/' + bbs_num_str + '/' + id_data + '#' + url_pas(comment_num))
  68. else:
  69. return redirect('/bbs/w/' + bbs_num_str + '/' + id_data)
  70. else:
  71. option_display = ''
  72. if comment_num != '':
  73. temp_dict = json.loads(api_bbs_w_comment_one(bbs_num_str + '-' + post_num_str + '-' + comment_num).data)
  74. title = ''
  75. data = temp_dict['comment']
  76. option_display = 'display: none;'
  77. elif post_num == '':
  78. title = ''
  79. data = ''
  80. else:
  81. temp_dict = json.loads(api_bbs_w_post(bbs_num_str + '-' + post_num_str).data)
  82. title = temp_dict['title']
  83. data = temp_dict['data']
  84. acl_div = ['' for _ in range(0, len(i_list))]
  85. acl_list = get_acl_list()
  86. for for_a in range(0, len(i_list)):
  87. for data_list in acl_list:
  88. acl_div[for_a] += '<option value="' + data_list + '">' + (data_list if data_list != '' else 'normal') + '</option>'
  89. editor_top_text = '<a href="/filter/edit_filter">(' + load_lang('edit_filter_rule') + ')</a>'
  90. if editor_top_text != '':
  91. editor_top_text += '<hr class="main_hr">'
  92. if comment_num != '':
  93. bbs_title = load_lang('bbs_comment_edit')
  94. elif post_num == '':
  95. bbs_title = load_lang('post_add')
  96. else:
  97. bbs_title = load_lang('post_edit')
  98. return easy_minify(flask.render_template(skin_check(),
  99. imp = [bbs_title, wiki_set(), wiki_custom(), wiki_css([0, 0])],
  100. data = editor_top_text + '''
  101. <form method="post">
  102. <input style="''' + option_display + '''" placeholder="''' + load_lang('title') + '''" name="title" value="''' + html.escape(title) + '''">
  103. <hr style="''' + option_display + '''" class="main_hr">
  104. ''' + edit_editor(curs, ip, data, 'bbs') + '''
  105. <!--
  106. <div style="''' + option_display + '''">
  107. ''' + render_simple_set('''
  108. <hr class="main_hr">
  109. <a href="/acl/TEST#exp">(''' + load_lang('reference') + ''')</a>
  110. <h2>''' + load_lang('acl') + '''</h2>
  111. <h3>''' + load_lang('post_view_acl') + '''</h3>
  112. <select name="post_view_acl">''' + acl_div[0] + '''</select>
  113. <h4>''' + load_lang('post_comment_acl') + '''</h4>
  114. <select name="post_comment_acl">''' + acl_div[1] + '''</select>
  115. <h2>''' + load_lang('markup') + '''</h2>
  116. ''' + load_lang('not_working') + '''
  117. ''') + '''
  118. </div>
  119. -->
  120. </form>
  121. ''',
  122. menu = [['bbs/w/' + bbs_num_str, load_lang('return')]]
  123. ))