api_topic_sub.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. from .tool.func import *
  2. def api_topic_sub_2(conn, topic_num):
  3. curs = conn.cursor()
  4. topic_num = str(topic_num)
  5. if flask.request.args.get('num', None):
  6. curs.execute(db_change("select id, data, date, ip, block, top from topic where code = ? and id + 0 = ? + 0 order by id + 0 asc"), [
  7. topic_num,
  8. flask.request.args.get('num', '')
  9. ])
  10. elif flask.request.args.get('top', None):
  11. curs.execute(db_change("select id, data, date, ip, block, top from topic where code = ? and top = 'O' order by id + 0 asc"), [topic_num])
  12. else:
  13. curs.execute(db_change("select id, data, date, ip, block, top from topic where code = ? order by id + 0 asc"), [topic_num])
  14. data = curs.fetchall()
  15. if data:
  16. json_data = {}
  17. admin = admin_check(3)
  18. for i in data:
  19. ip = ip_pas(i[3])
  20. if i[4] != 'O':
  21. t_data_f = i[1]
  22. b_color = 'toron_color'
  23. else:
  24. if admin == 1:
  25. t_data_f = i[1]
  26. b_color = 'toron_color_grey'
  27. else:
  28. t_data_f = ''
  29. b_color = 'toron_color_not'
  30. ip += ' (B)'
  31. if flask.request.args.get('render', None):
  32. if i[0] == '1':
  33. s_user = i[3]
  34. else:
  35. if flask.request.args.get('num', None):
  36. curs.execute(db_change("select ip from topic where code = ? order by id + 0 asc limit 1"), [topic_num])
  37. g_data = curs.fetchall()
  38. if g_data:
  39. s_user = g_data[0][0]
  40. else:
  41. s_user = ''
  42. if flask.request.args.get('top', None):
  43. t_color = 'toron_color_red'
  44. elif i[3] == s_user and i[5] != '1':
  45. t_color = 'toron_color_green'
  46. elif i[5] == '1':
  47. t_color = 'toron_color_blue'
  48. else:
  49. t_color = 'toron_color'
  50. if admin == 1 or b_color != 'toron_color_not':
  51. ip += ' <a href="/thread/' + topic_num + '/admin/' + i[0] + '">(' + load_lang('discussion_tool') + ')</a>'
  52. if t_data_f == '':
  53. t_data_f = '[br]'
  54. t_data_f = render_set(data = t_data_f, num = 2, include = 'topic_' + i[0])
  55. t_plus_data = t_data_f[1]
  56. t_data_f = t_data_f[0]
  57. all_data = '' + \
  58. '<table id="toron">' + \
  59. '<tbody>' + \
  60. '<tr>' + \
  61. '<td id="' + t_color + '">' + \
  62. '<a href="javascript:void(0);" id="' + i[0] + '">#' + i[0] + '</a> ' + ip + ' <span style="float: right;">' + i[2] + '</span>' + \
  63. '</td>' + \
  64. '</tr>' + \
  65. '<tr>' + \
  66. '<td id="' + b_color + '">' + \
  67. '<div id="topic_scroll">' + t_data_f + '</div>' + \
  68. '</td>' + \
  69. '</tr>' + \
  70. '</tbody>' + \
  71. '</table>' + \
  72. '<hr class="main_hr">' + \
  73. ''
  74. json_data[i[0]] = {
  75. "data" : all_data,
  76. "plus_data" : t_plus_data
  77. }
  78. else:
  79. if i[4] != 'O' or (i[4] == 'O' and admin == 1):
  80. t_data_f = i[1]
  81. else:
  82. curs.execute(db_change("select who from re_admin where what = ? order by time desc limit 1"), [
  83. 'blind (' + name + ' - ' + sub + '#' + str(i[0]) + ')'
  84. ])
  85. who_blind = curs.fetchall()
  86. if who_blind:
  87. t_data_f = '[[user:' + who_blind[0][0] + ']] block'
  88. else:
  89. t_data_f = 'block'
  90. json_data[i[0]] = {
  91. "data" : t_data_f,
  92. "date" : i[2],
  93. "ip" : ip_pas(i[3], 1),
  94. "block" : i[4],
  95. }
  96. return flask.jsonify(json_data)
  97. else:
  98. return flask.jsonify({})