edit.py 6.1 KB

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