2
0

edit.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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('\r\n', '\n').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(
  67. '\n(?P<in>={1,6})',
  68. '<br>\g<in>',
  69. html.escape('\n' + old[0][0].replace('\r\n', '\n') + '\n')
  70. )
  71. i = 0
  72. while 1:
  73. g_data = re.search('((?:<br>)(?:(?:(?!\n|<br>).)+)(?:\n*(?:(?:(?!<br>).)+\n*)+)?)', data)
  74. if g_data:
  75. if int(section) - 1 == i:
  76. data = html.unescape(re.sub('<br>(?P<in>={1,6})', '\n\g<in>', g_data.groups()[0]))
  77. break
  78. else:
  79. data = re.sub('((?:<br>)(?:(?:(?!\n|<br>).)+)(?:\n*(?:(?:(?!<br>).)+\n*)+)?)', '\n', data, 1)
  80. i += 1
  81. else:
  82. break
  83. else:
  84. data = old[0][0].replace('\r\n', '\n')
  85. else:
  86. data = ''
  87. data_old = data
  88. get_name = ''
  89. if not section:
  90. get_name = '''
  91. <a href="/manager/15?plus=''' + url_pas(name) + '">(' + load_lang('load') + ')</a> <a href="/edit_filter">(' + load_lang('edit_filter_rule') + ''')</a>
  92. <hr class=\"main_hr\">
  93. '''
  94. if flask.request.args.get('plus', None):
  95. curs.execute(db_change("select data from data where title = ?"), [flask.request.args.get('plus', 'test')])
  96. get_data = curs.fetchall()
  97. if get_data:
  98. data = get_data[0][0]
  99. save_button = load_lang('save')
  100. menu_plus = [['delete/' + url_pas(name), load_lang('delete')], ['move/' + url_pas(name), load_lang('move')]]
  101. sub = load_lang('edit')
  102. curs.execute(db_change('select data from other where name = "edit_bottom_text"'))
  103. sql_d = curs.fetchall()
  104. if sql_d and sql_d[0][0] != '':
  105. b_text = '<hr class=\"main_hr\">' + sql_d[0][0]
  106. else:
  107. b_text = ''
  108. curs.execute(db_change('select data from other where name = "edit_help"'))
  109. sql_d = curs.fetchall()
  110. if sql_d and sql_d[0][0] != '':
  111. p_text = sql_d[0][0]
  112. else:
  113. p_text = load_lang('defalut_edit_help')
  114. return easy_minify(flask.render_template(skin_check(),
  115. imp = [name, wiki_set(), custom(), other2([' (' + sub + ')', 0])],
  116. data = get_name + '''
  117. <form method="post">
  118. <script>do_stop_exit();</script>
  119. ''' + edit_button() + '''
  120. <textarea rows="25" id="content" placeholder="''' + p_text + '''" name="content">''' + html.escape(re.sub('\n$', '', data)) + '''</textarea>
  121. <textarea id="origin" name="otent">''' + html.escape(re.sub('\n$', '', data_old)) + '''</textarea>
  122. <hr class=\"main_hr\">
  123. <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
  124. <hr class=\"main_hr\">
  125. ''' + captcha_get() + ip_warring() + '''
  126. <button id="save" type="submit" onclick="go_save_zone = 1;">''' + save_button + '''</button>
  127. <button id="preview" type="button" onclick="load_preview(\'''' + url_pas(name) + '\')">' + load_lang('preview') + '''</button>
  128. </form>
  129. ''' + b_text + '''
  130. <hr class=\"main_hr\">
  131. <div id="see_preview"></div>
  132. ''',
  133. menu = [['w/' + url_pas(name), load_lang('return')]] + menu_plus
  134. ))