2
0

api_topic_sub.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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"), [
  34. 'blind (' + name + ' - ' + sub + '#' + str(i[0]) + ')'
  35. ])
  36. who_blind = curs.fetchall()
  37. if who_blind:
  38. ip += ' (' + who_blind[0][0] + ' B)'
  39. else:
  40. ip += ' (B)'
  41. if flask.request.args.get('render', None):
  42. if i[0] == '1':
  43. s_user = i[3]
  44. else:
  45. if flask.request.args.get('num', None):
  46. curs.execute(db_change("select ip from topic where title = ? and sub = ? order by id + 0 asc limit 1"), [name, sub])
  47. g_data = curs.fetchall()
  48. if g_data:
  49. s_user = g_data[0][0]
  50. else:
  51. s_user = ''
  52. if flask.request.args.get('top', None):
  53. t_color = 'toron_color_red'
  54. elif i[3] == s_user and i[5] != '1':
  55. t_color = 'toron_color_green'
  56. elif i[5] == '1':
  57. t_color = 'toron_color_blue'
  58. else:
  59. t_color = 'toron_color'
  60. if admin == 1 or b_color != 'toron_color_not':
  61. ip += ' <a href="/thread/' + str(topic_num) + '/admin/' + i[0] + '">(' + load_lang('discussion_tool') + ')</a>'
  62. if t_data_f == '':
  63. t_data_f = '[br]'
  64. t_data_f = render_set(data = t_data_f, num = 2, include = 'topic_' + i[0])
  65. t_plus_data = t_data_f[1]
  66. t_data_f = t_data_f[0]
  67. all_data = '' + \
  68. '<table id="toron">' + \
  69. '<tbody>' + \
  70. '<tr>' + \
  71. '<td id="' + t_color + '">' + \
  72. '<a href="javascript:void(0);" id="' + i[0] + '">#' + i[0] + '</a> ' + ip + ' <span style="float: right;">' + i[2] + '</span>' + \
  73. '</td>' + \
  74. '</tr>' + \
  75. '<tr>' + \
  76. '<td id="' + b_color + '">' + t_data_f + '</td>' + \
  77. '</tr>' + \
  78. '</tbody>' + \
  79. '</table>' + \
  80. '<hr class="main_hr">' + \
  81. ''
  82. json_data[i[0]] = {
  83. "data" : all_data,
  84. "plus_data" : t_plus_data
  85. }
  86. else:
  87. if i[4] != 'O' or (i[4] == 'O' and admin == 1):
  88. t_data_f = i[1]
  89. else:
  90. curs.execute(db_change("select who from re_admin where what = ? order by time desc limit 1"), [
  91. 'blind (' + name + ' - ' + sub + '#' + str(i[0]) + ')'
  92. ])
  93. who_blind = curs.fetchall()
  94. if who_blind:
  95. t_data_f = '[[user:' + who_blind[0][0] + ']] block'
  96. else:
  97. t_data_f = 'block'
  98. json_data[i[0]] = {
  99. "data" : t_data_f,
  100. "date" : i[2],
  101. "ip" : ip_pas(i[3], 1),
  102. "block" : i[4],
  103. }
  104. return flask.jsonify(json_data)
  105. else:
  106. return flask.jsonify({})