edit.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. from .tool.func import *
  2. def edit_2(conn, name):
  3. curs = conn.cursor()
  4. ip = ip_check()
  5. section = flask.request.args.get('section', None)
  6. curs.execute(db_change("select data from data where title = ?"), [name])
  7. old = curs.fetchall()
  8. if acl_check(name) == 1:
  9. return redirect('/edit_req/' + url_pas(name))
  10. if flask.request.method == 'POST':
  11. if captcha_post(flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
  12. return re_error('/error/13')
  13. else:
  14. captcha_post('', 0)
  15. if slow_edit_check() == 1:
  16. return re_error('/error/24')
  17. today = get_time()
  18. content = flask.request.form.get('content', '')
  19. if flask.request.form.get('otent', '') == content:
  20. return redirect('/w/' + url_pas(name))
  21. if edit_filter_do(content) == 1:
  22. return re_error('/error/21')
  23. curs.execute(db_change('select data from other where name = "copyright_checkbox_text"'))
  24. copyright_checkbox_text_d = curs.fetchall()
  25. if copyright_checkbox_text_d and copyright_checkbox_text_d[0][0] != '' and flask.request.form.get('copyright_agreement', '') != 'yes':
  26. return re_error('/error/29')
  27. content = savemark(content)
  28. if old:
  29. leng = leng_check(len(flask.request.form.get('otent', '')), len(content))
  30. if section:
  31. content = old[0][0].replace('\r\n', '\n').replace(
  32. flask.request.form.get('otent', '').replace('\r\n', '\n'),
  33. content.replace('\r\n', '\n')
  34. )
  35. else:
  36. leng = '+' + str(len(content))
  37. if old:
  38. curs.execute(db_change("update data set data = ? where title = ?"), [content, name])
  39. else:
  40. curs.execute(db_change("insert into data (title, data) values (?, ?)"), [name, content])
  41. curs.execute(db_change('select data from other where name = "count_all_title"'))
  42. curs.execute(db_change("update other set data = ? where name = 'count_all_title'"), [str(int(curs.fetchall()[0][0]) + 1)])
  43. curs.execute(db_change("select user from scan where title = ?"), [name])
  44. for scan_user in curs.fetchall():
  45. curs.execute(db_change("insert into alarm (name, data, date) values (?, ?, ?)"), [
  46. scan_user[0],
  47. ip + ' | <a href="/w/' + url_pas(name) + '">' + name + '</a> | Edit',
  48. today
  49. ])
  50. history_plus(
  51. name,
  52. content,
  53. today,
  54. ip,
  55. flask.request.form.get('send', ''),
  56. leng
  57. )
  58. curs.execute(db_change("delete from back where link = ?"), [name])
  59. curs.execute(db_change("delete from back where title = ? and type = 'no'"), [name])
  60. render_set(
  61. title = name,
  62. data = content,
  63. num = 1
  64. )
  65. conn.commit()
  66. return redirect('/w/' + url_pas(name))
  67. else:
  68. if old:
  69. if section:
  70. data = re.sub(
  71. '\n(?P<in>={1,6})',
  72. '<br>\g<in>',
  73. html.escape('\n' + old[0][0].replace('\r\n', '\n') + '\n')
  74. )
  75. i = 0
  76. while 1:
  77. g_data = re.search('((?:<br>)(?:(?:(?!\n|<br>).)+)(?:\n*(?:(?:(?!<br>).)+\n*)+)?)', data)
  78. if g_data:
  79. if int(section) - 1 == i:
  80. data = html.unescape(re.sub('<br>(?P<in>={1,6})', '\n\g<in>', g_data.groups()[0]))
  81. break
  82. else:
  83. data = re.sub('((?:<br>)(?:(?:(?!\n|<br>).)+)(?:\n*(?:(?:(?!<br>).)+\n*)+)?)', '\n', data, 1)
  84. i += 1
  85. else:
  86. break
  87. else:
  88. data = old[0][0].replace('\r\n', '\n')
  89. else:
  90. data = ''
  91. data_old = data
  92. get_name = ''
  93. if not section:
  94. get_name = '''
  95. <a href="/manager/15?plus=''' + url_pas(name) + '">(' + load_lang('load') + ')</a> <a href="/edit_filter">(' + load_lang('edit_filter_rule') + ''')</a>
  96. <hr class=\"main_hr\">
  97. '''
  98. if flask.request.args.get('plus', None):
  99. curs.execute(db_change("select data from data where title = ?"), [flask.request.args.get('plus', 'test')])
  100. get_data = curs.fetchall()
  101. if get_data:
  102. data = get_data[0][0]
  103. save_button = load_lang('save')
  104. menu_plus = [
  105. ['delete/' + url_pas(name), load_lang('delete')],
  106. ['move/' + url_pas(name), load_lang('move')],
  107. ['upload', load_lang('upload')]
  108. ]
  109. sub = load_lang('edit')
  110. curs.execute(db_change('select data from other where name = "edit_bottom_text"'))
  111. sql_d = curs.fetchall()
  112. if sql_d and sql_d[0][0] != '':
  113. b_text = '<hr class=\"main_hr\">' + sql_d[0][0]
  114. else:
  115. b_text = ''
  116. cccb_text = ''
  117. curs.execute(db_change('select data from other where name = "copyright_checkbox_text"'))
  118. sql_d = curs.fetchall()
  119. if sql_d and sql_d[0][0] != '':
  120. cccb_text = '<hr class=\"wmain_hr\"><input type="checkbox" name="copyright_agreement" value="yes">' + sql_d[0][0] + '<hr class=\"main_hr\">'
  121. curs.execute(db_change('select data from other where name = "edit_help"'))
  122. sql_d = curs.fetchall()
  123. if sql_d and sql_d[0][0] != '':
  124. p_text = sql_d[0][0]
  125. else:
  126. p_text = load_lang('defalut_edit_help')
  127. return easy_minify(flask.render_template(skin_check(),
  128. imp = [name, wiki_set(), custom(), other2([' (' + sub + ')', 0])],
  129. data = get_name + '''
  130. <form method="post">
  131. <label for="pasteUploadToggle">이미지 복붙해서 첨부하기 &nbsp;</label>
  132. <input type="checkbox" name="pasteUploadToggle" onClick="togglePasteUploaderSwtich()" />
  133. <script>do_stop_exit();</script>
  134. ''' + edit_button() + '''
  135. <textarea rows="25" id="content" placeholder="''' + p_text + '''" name="content">''' + html.escape(re.sub('\n$', '', data)) + '''</textarea>
  136. <textarea id="origin" name="otent">''' + html.escape(re.sub('\n$', '', data_old)) + '''</textarea>
  137. <hr class=\"main_hr\">
  138. <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
  139. <hr class=\"main_hr\">
  140. ''' + captcha_get() + ip_warring() + cccb_text + '''
  141. <button id="save" type="submit" onclick="go_save_zone = 1;">''' + save_button + '''</button>
  142. <button id="preview" type="button" onclick="load_preview(\'''' + url_pas(name) + '\')">' + load_lang('preview') + '''</button>
  143. </form>
  144. ''' + b_text + '''
  145. <hr class=\"main_hr\">
  146. <div id="see_preview"></div>
  147. ''',
  148. menu = [['w/' + url_pas(name), load_lang('return')]] + menu_plus
  149. ))