view_raw.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from .tool.func import *
  2. def view_raw_2(name = None, topic_num = None, num = None, doc_acl = 0):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. if topic_num:
  6. topic_num = str(topic_num)
  7. if acl_check('', 'topic_view', topic_num) == 1:
  8. return re_error('/ban')
  9. else:
  10. if acl_check(name, 'render') == 1:
  11. return re_error('/ban')
  12. if num:
  13. num = str(num)
  14. v_name = name
  15. p_data = ''
  16. sub = ' (' + load_lang('raw') + ')'
  17. if not topic_num and num:
  18. curs.execute(db_change("select title from history where title = ? and id = ? and hide = 'O'"), [name, num])
  19. if curs.fetchall() and admin_check(6) != 1:
  20. return re_error('/error/3')
  21. curs.execute(db_change("select data from history where title = ? and id = ?"), [name, num])
  22. sub += ' (r' + num + ')'
  23. menu = [['history/' + url_pas(name), load_lang('history')]]
  24. elif topic_num:
  25. if admin_check(6) != 1:
  26. curs.execute(db_change("select data from topic where id = ? and code = ? and block = ''"), [num, topic_num])
  27. else:
  28. curs.execute(db_change("select data from topic where id = ? and code = ?"), [num, topic_num])
  29. v_name = load_lang('discussion_raw')
  30. sub = ' (#' + num + ')'
  31. menu = [
  32. ['thread/' + topic_num + '#' + num, load_lang('discussion')],
  33. ['thread/' + topic_num + '/comment/' + num + '/tool', load_lang('return')]
  34. ]
  35. else:
  36. curs.execute(db_change("select data from data where title = ?"), [name])
  37. menu = [['w/' + url_pas(name), load_lang('return')]]
  38. data = curs.fetchall()
  39. if data:
  40. p_data += '<textarea readonly rows="25">' + html.escape(data[0][0]) + '</textarea>'
  41. if doc_acl == 1:
  42. p_data = '' + \
  43. load_lang('authority_error') + \
  44. '<hr class="main_hr">' + \
  45. p_data
  46. ''
  47. sub = ' (' + load_lang('edit') + ')'
  48. return easy_minify(flask.render_template(skin_check(),
  49. imp = [v_name, wiki_set(), wiki_custom(), wiki_css([sub, 0])],
  50. data = p_data,
  51. menu = menu
  52. ))
  53. else:
  54. return re_error('/error/3')