edit.py 6.2 KB

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