inter_wiki_plus.py 9.2 KB

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