view_raw.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. from .tool.func import *
  2. from .api_bbs_w_post import api_bbs_w_post
  3. from .api_bbs_w_comment_one import api_bbs_w_comment_one
  4. def view_raw_2(name = None, topic_num = None, num = None, doc_acl = 0, bbs_num = '', post_num = '', comment_num = ''):
  5. with get_db_connect() as conn:
  6. curs = conn.cursor()
  7. bbs_num_str = str(bbs_num)
  8. post_num_str = str(post_num)
  9. if bbs_num != '' and post_num != '':
  10. if acl_check(bbs_num_str, 'bbs_view') == 1:
  11. return re_error('/ban')
  12. name = ''
  13. elif topic_num:
  14. topic_num = str(topic_num)
  15. if acl_check('', 'topic_view', topic_num) == 1:
  16. return re_error('/ban')
  17. else:
  18. if acl_check(name, 'render') == 1:
  19. return re_error('/ban')
  20. if num:
  21. num = str(num)
  22. v_name = name
  23. p_data = ''
  24. sub = '(' + load_lang('raw') + ')'
  25. if bbs_num != '' and post_num != '':
  26. sub += ' (' + load_lang('bbs') + ')'
  27. menu = [['bbs/tool/' + url_pas(bbs_num_str) + '/' + url_pas(post_num_str), load_lang('return')]]
  28. if comment_num != '':
  29. sub += ' (' + comment_num + ')'
  30. elif not topic_num and num:
  31. curs.execute(db_change("select title from history where title = ? and id = ? and hide = 'O'"), [name, num])
  32. if curs.fetchall() and admin_check(6) != 1:
  33. return re_error('/error/3')
  34. curs.execute(db_change("select data from history where title = ? and id = ?"), [name, num])
  35. sub += ' (r' + num + ')'
  36. menu = [['history_tool/' + url_pas(num) + '/' + url_pas(name), load_lang('return')]]
  37. elif topic_num:
  38. if admin_check(6) != 1:
  39. curs.execute(db_change("select data from topic where id = ? and code = ? and block = ''"), [num, topic_num])
  40. else:
  41. curs.execute(db_change("select data from topic where id = ? and code = ?"), [num, topic_num])
  42. v_name = load_lang('discussion_raw')
  43. sub = ' (#' + num + ')'
  44. menu = [
  45. ['thread/' + topic_num + '#' + num, load_lang('discussion')],
  46. ['thread/' + topic_num + '/comment/' + num + '/tool', load_lang('return')]
  47. ]
  48. else:
  49. curs.execute(db_change("select data from data where title = ?"), [name])
  50. menu = [['w/' + url_pas(name), load_lang('return')]]
  51. if bbs_num != '' and post_num != '':
  52. if comment_num != '':
  53. data = json.loads(api_bbs_w_comment_one(bbs_num_str + '-' + post_num_str + '-' + comment_num).data)
  54. sub_data = json.loads(api_bbs_w_post(bbs_num_str + '-' + post_num_str).data)
  55. else:
  56. data = json.loads(api_bbs_w_post(bbs_num_str + '-' + post_num_str).data)
  57. if 'comment' in data:
  58. v_name = sub_data["title"]
  59. data = [[data["comment"]]]
  60. elif 'data' in data:
  61. v_name = data["title"]
  62. data = [[data["data"]]]
  63. else:
  64. data = None
  65. else:
  66. data = curs.fetchall()
  67. if data:
  68. p_data += '<textarea readonly class="opennamu_textarea_500">' + html.escape(data[0][0]) + '</textarea>'
  69. if doc_acl == 1:
  70. p_data = '' + \
  71. load_lang('authority_error') + \
  72. '<hr class="main_hr">' + \
  73. p_data
  74. ''
  75. sub = ' (' + load_lang('edit') + ')'
  76. return easy_minify(flask.render_template(skin_check(),
  77. imp = [v_name, wiki_set(), wiki_custom(), wiki_css([sub, 0])],
  78. data = p_data,
  79. menu = menu
  80. ))
  81. else:
  82. return re_error('/error/3')