2
0

api_topic_sub.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. curs.execute('select acl from user where id = ?', [i[3]])
  52. u_acl = curs.fetchall()
  53. if u_acl and u_acl[0][0] != 'user':
  54. ip += ' <a href="javascript:void(0);" title="' + load_lang('admin') + '">★</a>'
  55. if admin == 1 or b_color != 'toron_color_grey':
  56. ip += ' <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/admin/' + i[0] + '">(' + load_lang('discussion_tool') + ')</a>'
  57. curs.execute("select end from ban where block = ?", [i[3]])
  58. if curs.fetchall():
  59. ip += ' <a href="javascript:void(0);" title="' + load_lang('blocked') + '">†</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) + '''</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("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" : i[3],
  94. "block" : i[4],
  95. }
  96. return flask.jsonify(json_data)
  97. else:
  98. return flask.jsonify({})