main_func_setting_head.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. from .tool.func import *
  2. def main_func_setting_head(num, skin_name = ''):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. if admin_check() != 1:
  6. return re_error('/ban')
  7. if flask.request.method == 'POST':
  8. if num == 4:
  9. info_d = 'body'
  10. end_r = 'body/top'
  11. coverage = ''
  12. elif num == 7:
  13. info_d = 'bottom_body'
  14. end_r = 'body/bottom'
  15. coverage = ''
  16. else:
  17. info_d = 'head'
  18. end_r = 'head'
  19. if skin_name == '':
  20. coverage = ''
  21. else:
  22. coverage = skin_name
  23. curs.execute(db_change("select name from other where name = ? and coverage = ?"), [info_d, coverage])
  24. if curs.fetchall():
  25. curs.execute(db_change("update other set data = ? where name = ? and coverage = ?"), [
  26. flask.request.form.get('content', ''),
  27. info_d,
  28. coverage
  29. ])
  30. else:
  31. curs.execute(db_change("insert into other (name, data, coverage) values (?, ?, ?)"), [info_d, flask.request.form.get('content', ''), coverage])
  32. conn.commit()
  33. admin_check(None, 'edit_set (' + info_d + ')')
  34. if skin_name == '':
  35. return redirect('/setting/' + end_r)
  36. else:
  37. return redirect('/setting/' + end_r + '/' + skin_name)
  38. else:
  39. if num == 4:
  40. curs.execute(db_change("select data from other where name = 'body'"))
  41. title = '_body'
  42. start = ''
  43. plus = '''
  44. <button id="preview" type="button" onclick="load_raw_preview(\'content\', \'see_preview\')">''' + load_lang('preview') + '''</button>
  45. <hr class="main_hr">
  46. <div id="see_preview"></div>
  47. '''
  48. elif num == 7:
  49. curs.execute(db_change("select data from other where name = 'bottom_body'"))
  50. title = '_bottom_body'
  51. start = ''
  52. plus = '''
  53. <button id="preview" type="button" onclick="load_raw_preview(\'content\', \'see_preview\')">''' + load_lang('preview') + '''</button>
  54. <hr class="main_hr">
  55. <div id="see_preview"></div>
  56. '''
  57. else:
  58. curs.execute(db_change("select data from other where name = 'head' and coverage = ?"), [skin_name])
  59. title = '_head'
  60. start = '' + \
  61. '<a href="?">(' + load_lang('all') + ')</a> ' + \
  62. ' '.join(['<a href="/setting/head/' + i + '">(' + i + ')</a>' for i in load_skin('', 1)]) + '''
  63. <hr class="main_hr">
  64. <span>&lt;style&gt;CSS&lt;/style&gt;<br>&lt;script&gt;JS&lt;/script&gt;</span>
  65. <hr class="main_hr">
  66. '''
  67. plus = ''
  68. head = curs.fetchall()
  69. if head:
  70. data = head[0][0]
  71. else:
  72. data = ''
  73. if skin_name != '':
  74. sub_plus = ' (' + skin_name + ')'
  75. else:
  76. sub_plus = ''
  77. return easy_minify(flask.render_template(skin_check(),
  78. imp = [load_lang(data = 'main' + title, safe = 1), wiki_set(), wiki_custom(), wiki_css(['(HTML)' + sub_plus, 0])],
  79. data = '''
  80. <form method="post">
  81. ''' + start + '''
  82. <textarea rows="25" placeholder="''' + load_lang('enter_html') + '''" name="content" id="content">''' + html.escape(data) + '''</textarea>
  83. <hr class="main_hr">
  84. <button id="save" type="submit">''' + load_lang('save') + '''</button>
  85. ''' + plus + '''
  86. </form>
  87. ''',
  88. menu = [['setting', load_lang('return')]]
  89. ))