api_topic_sub.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. from .tool.func import *
  2. def api_topic_sub_2(conn, name, sub, time):
  3. curs = conn.cursor()
  4. if flask.request.args.get('num', None):
  5. curs.execute("select id, data, date, ip, block, top from topic where title = ? and sub = ? and id + 0 = ? + 0 order by id + 0 asc", [
  6. name,
  7. sub,
  8. flask.request.args.get('num', '')
  9. ])
  10. elif flask.request.args.get('top', None):
  11. curs.execute("select id, data, date, ip, block, top from topic where title = ? and sub = ? and top = 'O' order by id + 0 asc", [name, sub])
  12. else:
  13. curs.execute("select id, data, date, ip, block, top from topic where title = ? and sub = ? order by id + 0 asc", [name, sub])
  14. data = curs.fetchall()
  15. if data:
  16. json_data = {}
  17. admin = admin_check(3)
  18. for i in data:
  19. if i[4] != 'O' or (i[4] == 'O' and admin == 1):
  20. t_data_f = i[1]
  21. b_color = ''
  22. else:
  23. curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['blind (' + name + ' - ' + sub + '#' + str(i[0]) + ')'])
  24. who_blind = curs.fetchall()
  25. if who_blind:
  26. t_data_f = '[[user:' + who_blind[0][0] + ']] block'
  27. b_color = 'toron_color_grey'
  28. else:
  29. t_data_f = 'block'
  30. b_color = 'toron_color_grey'
  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("select ip from topic where title = ? and sub = ? order by id + 0 asc limit 1", [name, sub])
  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:
  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. ip = ip_pas(i[3])
  51. plus_ip = ''
  52. curs.execute('select acl from user where id = ?', [i[3]])
  53. u_acl = curs.fetchall()
  54. if u_acl and u_acl[0][0] != 'user':
  55. plus_ip = '<b>' + i[3] + '</b>'
  56. if admin == 1 or b_color != 'toron_color_grey':
  57. ip += ' <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/admin/' + i[0] + '">(' + load_lang('discussion_tool') + ')</a>'
  58. curs.execute("select end from ban where block = ?", [i[3]])
  59. if curs.fetchall():
  60. if plus_ip != '':
  61. plus_ip = '<s>' + plus_ip + '</s>'
  62. else:
  63. plus_ip = '<s>' + i[3] + '</s>'
  64. if t_data_f == '':
  65. t_data_f = '[br]'
  66. if plus_ip != '':
  67. ip = ip.replace('>' + i[3] + '<', '>' + plus_ip + '<')
  68. all_data = '''
  69. <table id="toron">
  70. <tbody>
  71. <tr>
  72. <td id="''' + t_color + '''">
  73. <a href="javascript:void(0);" id="''' + i[0] + '">#' + i[0] + '</a> ' + ip + ' <span style="float: right;">' + i[2] + '''</span>
  74. </td>
  75. </tr>
  76. <tr>
  77. <td id="''' + b_color + '">' + render_set(data = t_data_f) + '''</td>
  78. </tr>
  79. </tbody>
  80. </table>
  81. <hr class="main_hr">
  82. '''
  83. json_data[i[0]] = {
  84. "data" : all_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("select who from re_admin where what = ? order by time desc limit 1", ['blind (' + name + ' - ' + sub + '#' + str(i[0]) + ')'])
  91. who_blind = curs.fetchall()
  92. if who_blind:
  93. t_data_f = '[[user:' + who_blind[0][0] + ']] block'
  94. else:
  95. t_data_f = 'block'
  96. json_data[i[0]] = {
  97. "data" : t_data_f,
  98. "date" : i[2],
  99. "ip" : i[3],
  100. "block" : i[4],
  101. }
  102. return flask.jsonify(json_data)
  103. else:
  104. return flask.jsonify({})