api_topic_sub.py 4.5 KB

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