2
0

edit.py 7.1 KB

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