edit.py 6.2 KB

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