2
0

plus_inter.py 4.3 KB

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