plus_inter.py 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. from .tool.func import *
  2. def plus_inter_2(conn, tools, name):
  3. curs = conn.cursor()
  4. if flask.request.method == 'POST':
  5. if tools == 'plus_inter_wiki':
  6. curs.execute('insert into inter (title, link) values (?, ?)', [flask.request.form.get('title', None), flask.request.form.get('link', None)])
  7. admin_check(None, 'inter_wiki_plus')
  8. elif tools == 'plus_edit_filter':
  9. if admin_check(1, 'edit_filter edit') != 1:
  10. return re_error('/error/3')
  11. if flask.request.form.get('limitless', '') != '':
  12. end = 'X'
  13. else:
  14. end = flask.request.form.get('second', 'X')
  15. try:
  16. re.compile(flask.request.form.get('content', 'test'))
  17. curs.execute("select name from filter where name = ?", [name])
  18. if curs.fetchall():
  19. curs.execute("update filter set regex = ?, sub = ? where name = ?", [flask.request.form.get('content', 'test'), end, name])
  20. else:
  21. curs.execute("insert into filter (name, regex, sub) values (?, ?, ?)", [name, flask.request.form.get('content', 'test'), end])
  22. except:
  23. return re_error('/error/23')
  24. else:
  25. if tools == 'plus_name_filter':
  26. admin_check(None, 'name_filter edit')
  27. type_d = 'name'
  28. else:
  29. admin_check(None, 'email_filter edit')
  30. type_d = 'email'
  31. curs.execute('insert into html_filter (html, kind) values (?, ?)', [flask.request.form.get('title', 'test'), type_d])
  32. conn.commit()
  33. return redirect('/' + re.sub('^plus_', '', tools))
  34. else:
  35. if admin_check(1) != 1:
  36. stat = 'disabled'
  37. else:
  38. stat = ''
  39. if tools == 'plus_inter_wiki':
  40. title = load_lang('interwiki_add')
  41. form_data = '''
  42. <input placeholder="''' + load_lang('name') + '''" type="text" name="title">
  43. <hr class=\"main_hr\">
  44. <input placeholder="link" type="text" name="link">
  45. '''
  46. elif tools == 'plus_edit_filter':
  47. curs.execute("select regex, sub from filter where name = ?", [name])
  48. exist = curs.fetchall()
  49. if exist:
  50. textarea = exist[0][0]
  51. if exist[0][1] == 'X':
  52. time_check = 'checked="checked"'
  53. time_data = ''
  54. else:
  55. time_check = ''
  56. time_data = exist[0][1]
  57. else:
  58. textarea = ''
  59. time_check = ''
  60. time_data = ''
  61. title = load_lang('edit_filter_add')
  62. form_data = '''
  63. <input placeholder="''' + load_lang('second') + '''" name="second" type="text" value="''' + html.escape(time_data) + '''">
  64. <hr class=\"main_hr\">
  65. <input ''' + stat + ''' type="checkbox" ''' + time_check + ''' name="limitless"> ''' + load_lang('limitless') + '''
  66. <hr class=\"main_hr\">
  67. <input ''' + stat + ''' placeholder="''' + load_lang('regex') + '''" name="content" value="''' + html.escape(textarea) + '''" type="text">
  68. '''
  69. elif tools == 'plus_name_filter':
  70. title = load_lang('id_filter_add')
  71. form_data = '<input placeholder="' + load_lang('id') + ' ' + load_lang('regex') + '" type="text" name="title">'
  72. else:
  73. title = load_lang('email_filter_add')
  74. form_data = '<input placeholder="email" type="text" name="title">'
  75. return easy_minify(flask.render_template(skin_check(),
  76. imp = [title, wiki_set(), custom(), other2([0, 0])],
  77. data = '''
  78. <form method="post">
  79. ''' + form_data + '''
  80. <hr class=\"main_hr\">
  81. <button ''' + stat + ''' type="submit">''' + load_lang('add') + '''</button>
  82. </form>
  83. ''',
  84. menu = [[re.sub('^plus_', '', tools), load_lang('return')]]
  85. ))