2
0

edit.py 6.1 KB

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