edit.py 7.4 KB

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