main_func_setting_head.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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="opennamu_js_preview" type="button" onclick="load_raw_preview(\'content\', \'opennamu_js_preview_area\')">''' + load_lang('preview') + '''</button>
  45. <hr class="main_hr">
  46. <div id="opennamu_js_preview_area"></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="opennamu_js_preview" type="button" onclick="load_raw_preview(\'content\', \'opennamu_js_preview_area\')">''' + load_lang('preview') + '''</button>
  54. <hr class="main_hr">
  55. <div id="opennamu_js_preview_area"></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="/setting/head">(' + load_lang('all') + ')</a> ' + \
  62. ' '.join(['<a href="/setting/head/' + url_pas(i) + '">(' + html.escape(i) + ')</a>' for i in load_skin('', 1)]) + '''
  63. <hr class="main_hr">
  64. <span>
  65. &lt;style&gt;CSS&lt;/style&gt;
  66. <br>
  67. &lt;script&gt;JS&lt;/script&gt;
  68. </span>
  69. <hr class="main_hr">
  70. '''
  71. plus = ''
  72. head = curs.fetchall()
  73. if head:
  74. data = head[0][0]
  75. else:
  76. data = ''
  77. if skin_name != '':
  78. sub_plus = ' (' + skin_name + ')'
  79. else:
  80. sub_plus = ''
  81. return easy_minify(flask.render_template(skin_check(),
  82. imp = [load_lang(data = 'main' + title, safe = 1), wiki_set(), wiki_custom(), wiki_css(['(HTML)' + sub_plus, 0])],
  83. data = '''
  84. <form method="post">
  85. ''' + start + '''
  86. <textarea rows="25" placeholder="''' + load_lang('enter_html') + '''" name="content" id="content">''' + html.escape(data) + '''</textarea>
  87. <hr class="main_hr">
  88. ''' + (load_lang('main_css_warning') + '<hr class="main_hr">' if title == '_head' else '') + '''
  89. <button id="opennamu_js_save" type="submit">''' + load_lang('save') + '''</button>
  90. ''' + plus + '''
  91. </form>
  92. ''',
  93. menu = [['setting', load_lang('return')]]
  94. ))