edit.py 7.8 KB

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