api_topic_sub.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 = '<table id="toron"><tbody><tr><td id="' + t_color + '">'
  63. all_data += '<a href="#' + i[0] + '">#' + i[0] + '</a> ' + ip + ' <span style="float: right;">' + i[2] + '</span>'
  64. all_data += '</td></tr><tr><td id="' + b_color + '">' + render_set(data = t_data_f) + '</td></tr></tbody></table><hr class=\"main_hr\">'
  65. json_data[i[0]] = {
  66. "data" : all_data
  67. }
  68. else:
  69. json_data[i[0]] = {
  70. "data" : t_data_f,
  71. "date" : i[2],
  72. "ip" : i[3],
  73. "block" : i[4],
  74. }
  75. return flask.jsonify(json_data)
  76. else:
  77. return flask.jsonify({})