api_topic_sub.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. from .tool.func import *
  2. def api_topic_sub_2(conn, topic_num):
  3. curs = conn.cursor()
  4. topic_num = str(topic_num)
  5. if flask.request.args.get('num', None):
  6. curs.execute(db_change("select id, data, date, ip, block, top from topic where code = ? and id + 0 = ? + 0 order by id + 0 asc"), [
  7. topic_num,
  8. flask.request.args.get('num', '')
  9. ])
  10. elif flask.request.args.get('top', None):
  11. curs.execute(db_change("select id, data, date, ip, block, top from topic where code = ? and top = 'O' order by id + 0 asc"), [topic_num])
  12. else:
  13. curs.execute(db_change("select id, data, date, ip, block, top from topic where code = ? order by id + 0 asc"), [topic_num])
  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. t_data_f = ''
  25. b_color = 'toron_color_not'
  26. ip += ' <a href="/admin_log?search=blind%20(code%20' + topic_num + '#' + i[0] + '">(B)</a>'
  27. if admin == 1:
  28. ip += ' <a href="/thread/' + topic_num + '/raw/' + i[0] + '">(R)</a>'
  29. if flask.request.args.get('render', None):
  30. if i[0] == '1':
  31. s_user = i[3]
  32. else:
  33. if flask.request.args.get('num', None):
  34. curs.execute(db_change("select ip from topic where code = ? order by id + 0 asc limit 1"), [topic_num])
  35. g_data = curs.fetchall()
  36. if g_data:
  37. s_user = g_data[0][0]
  38. else:
  39. s_user = ''
  40. if flask.request.args.get('top', None):
  41. t_color = 'toron_color_red'
  42. elif i[3] == s_user and i[5] != '1':
  43. t_color = 'toron_color_green'
  44. elif i[5] == '1':
  45. t_color = 'toron_color_blue'
  46. else:
  47. t_color = 'toron_color'
  48. if admin == 1 or b_color != 'toron_color_not':
  49. ip += ' <a href="/thread/' + topic_num + '/admin/' + i[0] + '">(' + load_lang('discussion_tool') + ')</a>'
  50. if t_data_f == '':
  51. t_data_f = '[br]'
  52. t_data_f = render_set(data = t_data_f, num = 2, include = 'topic_' + i[0])
  53. t_plus_data = t_data_f[1]
  54. t_data_f = t_data_f[0]
  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 + '">' + \
  65. '<div id="topic_scroll">' + t_data_f + '</div>' + \
  66. '</td>' + \
  67. '</tr>' + \
  68. '</tbody>' + \
  69. '</table>' + \
  70. '<hr class="main_hr">' + \
  71. ''
  72. json_data[i[0]] = {
  73. "data" : all_data,
  74. "plus_data" : t_plus_data
  75. }
  76. else:
  77. if i[4] != 'O' or (i[4] == 'O' and admin == 1):
  78. t_data_f = i[1]
  79. else:
  80. curs.execute(db_change("select who from re_admin where what = ? order by time desc limit 1"), [
  81. 'blind (' + name + ' - ' + sub + '#' + str(i[0]) + ')'
  82. ])
  83. who_blind = curs.fetchall()
  84. if who_blind:
  85. t_data_f = '[[user:' + who_blind[0][0] + ']] block'
  86. else:
  87. t_data_f = 'block'
  88. json_data[i[0]] = {
  89. "data" : t_data_f,
  90. "date" : i[2],
  91. "ip" : ip_pas(i[3], 1),
  92. "block" : i[4],
  93. }
  94. return flask.jsonify(json_data)
  95. else:
  96. return flask.jsonify({})