inter_wiki_plus.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. from .tool.func import *
  2. def inter_wiki_plus_2(conn, tools, name):
  3. curs = conn.cursor()
  4. if not name:
  5. if tools == 'plus_edit_filter':
  6. return redirect('/manager/9')
  7. if flask.request.method == 'POST':
  8. if tools == 'plus_inter_wiki':
  9. if name:
  10. curs.execute(db_change("delete from html_filter where html = ? and kind = 'inter_wiki'"), [name])
  11. curs.execute(db_change("delete from html_filter where html = ? and kind = 'inter_wiki'"), [
  12. flask.request.form.get('title', 'test')
  13. ])
  14. curs.execute(db_change('insert into html_filter (html, plus, plus_t, kind) values (?, ?, ?, "inter_wiki")'), [
  15. flask.request.form.get('title', 'test'),
  16. flask.request.form.get('link', 'test'),
  17. flask.request.form.get('icon', '')
  18. ])
  19. admin_check(None, 'inter_wiki_plus')
  20. elif tools == 'plus_edit_filter':
  21. if admin_check(None, 'edit_filter edit') != 1:
  22. return re_error('/error/3')
  23. if flask.request.form.get('second', '0') == '0':
  24. end = 'X'
  25. else:
  26. end = flask.request.form.get('second', 'X')
  27. try:
  28. re.compile(flask.request.form.get('content', 'test'))
  29. curs.execute(db_change("delete from html_filter where html = ? and kind = 'regex_filter'"), [name])
  30. curs.execute(db_change("insert into html_filter (html, plus, plus_t, kind) values (?, ?, ?, 'regex_filter')"), [
  31. name,
  32. flask.request.form.get('content', 'test'),
  33. end
  34. ])
  35. except:
  36. return re_error('/error/23')
  37. else:
  38. plus_d = ''
  39. if tools == 'plus_name_filter':
  40. try:
  41. re.compile(flask.request.form.get('title', 'test'))
  42. except:
  43. return re_error('/error/23')
  44. admin_check(None, 'name_filter edit')
  45. type_d = 'name'
  46. elif tools == 'plus_file_filter':
  47. try:
  48. re.compile(flask.request.form.get('title', 'test'))
  49. except:
  50. return re_error('/error/23')
  51. admin_check(None, 'file_filter edit')
  52. type_d = 'file'
  53. elif tools == 'plus_email_filter':
  54. admin_check(None, 'email_filter edit')
  55. type_d = 'email'
  56. elif tools == 'plus_image_license':
  57. admin_check(None, 'image_license edit')
  58. type_d = 'image_license'
  59. elif tools == 'plus_extension_filter':
  60. admin_check(None, 'extension_filter edit')
  61. type_d = 'extension'
  62. else:
  63. admin_check(None, 'edit_top edit')
  64. type_d = 'edit_top'
  65. plus_d = flask.request.form.get('markup', 'test')
  66. if name:
  67. curs.execute(db_change("delete from html_filter where html = ? and kind = ?"), [
  68. name,
  69. type_d
  70. ])
  71. curs.execute(db_change('insert into html_filter (html, kind, plus) values (?, ?, ?)'), [
  72. flask.request.form.get('title', 'test'),
  73. type_d,
  74. plus_d
  75. ])
  76. conn.commit()
  77. return redirect('/' + re.sub(r'^plus_', '', tools))
  78. else:
  79. get_sub = 0
  80. if admin_check() != 1:
  81. stat = 'disabled'
  82. else:
  83. stat = ''
  84. if tools == 'plus_inter_wiki':
  85. if name:
  86. curs.execute(db_change("select html, plus, plus_t from html_filter where html = ? and kind = 'inter_wiki'"), [name])
  87. exist = curs.fetchall()
  88. if exist:
  89. value = exist[0]
  90. else:
  91. value = ['', '', '']
  92. else:
  93. value = ['', '', '']
  94. title = load_lang('interwiki_add')
  95. form_data = '''
  96. ''' + load_lang('name') + '''
  97. <hr class="main_hr">
  98. <input value="''' + html.escape(value[0]) + '''" type="text" name="title">
  99. <hr class="main_hr">
  100. ''' + load_lang('link') + '''
  101. <hr class="main_hr">
  102. <input value="''' + html.escape(value[1]) + '''" type="text" name="link">
  103. <hr class="main_hr">
  104. ''' + load_lang('icon') + ''' (HTML)
  105. <hr class="main_hr">
  106. <input value="''' + html.escape(value[2]) + '''" type="text" name="icon">
  107. '''
  108. elif tools == 'plus_edit_filter':
  109. curs.execute(db_change("select plus, plus_t from html_filter where html = ? and kind = 'regex_filter'"), [name])
  110. exist = curs.fetchall()
  111. if exist:
  112. textarea = exist[0][0]
  113. if exist[0][1] == 'X':
  114. time_check = 'checked="checked"'
  115. time_data = ''
  116. else:
  117. time_check = ''
  118. time_data = exist[0][1]
  119. else:
  120. textarea = ''
  121. time_check = ''
  122. time_data = ''
  123. insert_data = ''
  124. if stat == '':
  125. t_data = [
  126. ['86400', load_lang('1_day')],
  127. ['432000‬', load_lang('5_day')],
  128. ['2592000', load_lang('30_day')],
  129. ['15552000', load_lang('180_day')],
  130. ['31104000‬', load_lang('360_day')],
  131. ['0', load_lang('limitless')]
  132. ]
  133. for i in t_data:
  134. insert_data += '<a href="javascript:insert_v(\'second\', \'' + i[0] + '\')">(' + i[1] + ')</a> '
  135. title = load_lang('edit_filter_add')
  136. form_data = '''
  137. <script>function insert_v(name, data) { document.getElementById(name).value = data; }</script>''' + insert_data + '''
  138. <hr class="main_hr">
  139. <input ''' + stat + ''' placeholder="''' + load_lang('second') + '''" id="second" name="second" type="text" value="''' + html.escape(time_data) + '''">
  140. <hr class="main_hr">
  141. <input ''' + stat + ''' placeholder="''' + load_lang('regex') + '''" name="content" value="''' + html.escape(textarea) + '''" type="text">
  142. '''
  143. elif tools == 'plus_name_filter':
  144. title = load_lang('id_filter_add')
  145. form_data = '' + \
  146. load_lang('regex') + \
  147. '<hr class="main_hr">' + \
  148. '<input value="' + html.escape(name if name else '') + '" type="text" name="title">' + \
  149. ''
  150. elif tools == 'plus_file_filter':
  151. title = load_lang('file_filter_add')
  152. form_data = '' + \
  153. load_lang('regex') + \
  154. '<hr class="main_hr">' + \
  155. '<input value="' + html.escape(name if name else '') + '" type="text" name="title">' + \
  156. ''
  157. elif tools == 'plus_email_filter':
  158. title = load_lang('email_filter_add')
  159. form_data = '' + \
  160. load_lang('email') + \
  161. '<hr class="main_hr">' + \
  162. '<input value="' + html.escape(name if name else '') + '" type="text" name="title">' + \
  163. ''
  164. elif tools == 'plus_image_license':
  165. title = load_lang('image_license_add')
  166. form_data = '' + \
  167. load_lang('license') + \
  168. '<hr class="main_hr">' + \
  169. '<input value="' + html.escape(name if name else '') + '" type="text" name="title">' + \
  170. ''
  171. elif tools == 'plus_extension_filter':
  172. title = load_lang('extension_filter_add')
  173. form_data = '' + \
  174. load_lang('extension') + \
  175. '<hr class="main_hr">' + \
  176. '<input value="' + html.escape(name if name else '') + '" type="text" name="title">' + \
  177. ''
  178. else:
  179. title = load_lang('edit_tool_add')
  180. if name:
  181. curs.execute(db_change("select plus from html_filter where html = ? and kind = 'edit_top'"), [name])
  182. exist = curs.fetchall()
  183. if exist:
  184. value = exist[0][0]
  185. else:
  186. value = ''
  187. else:
  188. value = ''
  189. form_data = '''
  190. ''' + load_lang('title') + '''
  191. <hr class="main_hr">
  192. <input value="''' + html.escape(name if name else '') + '''" type="text" name="title">
  193. <hr class="main_hr">
  194. ''' + load_lang('markup') + '''
  195. <hr class="main_hr">
  196. <input value="''' + html.escape(value) + '''" type="text" name="markup">
  197. '''
  198. return easy_minify(flask.render_template(skin_check(),
  199. imp = [title, wiki_set(), wiki_custom(), wiki_css([get_sub, 0])],
  200. data = '''
  201. <form method="post">
  202. ''' + form_data + '''
  203. <hr class="main_hr">
  204. <button ''' + stat + ''' type="submit">''' + load_lang('add') + '''</button>
  205. </form>
  206. ''',
  207. menu = [[re.sub('^plus_', '', tools), load_lang('return')]]
  208. ))