api_topic_sub.py 4.4 KB

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