api_topic_sub.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 = 'toron_color_grey'
  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. if admin == 1 or b_color != 'toron_color_grey':
  52. ip += ' <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/admin/' + i[0] + '">(' + load_lang('discussion_tool') + ')</a>'
  53. if t_data_f == '':
  54. t_data_f = '[br]'
  55. all_data = '''
  56. <table id="toron">
  57. <tbody>
  58. <tr>
  59. <td id="''' + t_color + '''">
  60. <a href="javascript:void(0);" id="''' + i[0] + '">#' + i[0] + '</a> ' + ip + ' <span style="float: right;">' + i[2] + '''</span>
  61. </td>
  62. </tr>
  63. <tr>
  64. <td id="''' + b_color + '">' + render_set(data = t_data_f) + '''</td>
  65. </tr>
  66. </tbody>
  67. </table>
  68. <hr class="main_hr">
  69. '''
  70. json_data[i[0]] = {
  71. "data" : all_data
  72. }
  73. else:
  74. if i[4] != 'O' or (i[4] == 'O' and admin == 1):
  75. t_data_f = i[1]
  76. else:
  77. curs.execute("select who from re_admin where what = ? order by time desc limit 1", ['blind (' + name + ' - ' + sub + '#' + str(i[0]) + ')'])
  78. who_blind = curs.fetchall()
  79. if who_blind:
  80. t_data_f = '[[user:' + who_blind[0][0] + ']] block'
  81. else:
  82. t_data_f = 'block'
  83. json_data[i[0]] = {
  84. "data" : t_data_f,
  85. "date" : i[2],
  86. "ip" : i[3],
  87. "block" : i[4],
  88. }
  89. return flask.jsonify(json_data)
  90. else:
  91. return flask.jsonify({})