inter_wiki_add.py 10 KB

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