api_topic_sub.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. if flask.request.args.get('render', None):
  19. all_ip = ip_pas([i[3] for i in data])
  20. for i in data:
  21. ip = all_ip[i[3]]
  22. if i[4] != 'O':
  23. t_data_f = i[1]
  24. b_color = 'toron_color'
  25. else:
  26. t_data_f = ''
  27. b_color = 'toron_color_not'
  28. ip += ' <a href="/admin_log?search=blind%20(code%20' + topic_num + '#' + i[0] + '">(B)</a>'
  29. if admin == 1:
  30. ip += ' <a href="/thread/' + topic_num + '/raw/' + i[0] + '">(R)</a>'
  31. if i[0] == '1':
  32. s_user = i[3]
  33. else:
  34. if flask.request.args.get('num', None):
  35. curs.execute(db_change("select ip from topic where code = ? order by id + 0 asc limit 1"), [topic_num])
  36. g_data = curs.fetchall()
  37. if g_data:
  38. s_user = g_data[0][0]
  39. else:
  40. s_user = ''
  41. if flask.request.args.get('top', None):
  42. t_color = 'toron_color_red'
  43. elif i[3] == s_user and i[5] != '1':
  44. t_color = 'toron_color_green'
  45. elif i[5] == '1':
  46. t_color = 'toron_color_blue'
  47. else:
  48. t_color = 'toron_color'
  49. if admin == 1 or b_color != 'toron_color_not':
  50. ip += ' <a href="/thread/' + topic_num + '/admin/' + i[0] + '">(' + load_lang('discussion_tool') + ')</a>'
  51. if t_data_f == '':
  52. t_data_f = '[br]'
  53. t_data_f = render_set(data = t_data_f, num = 2, include = 'topic_' + i[0])
  54. t_plus_data = t_data_f[1]
  55. t_data_f = t_data_f[0]
  56. t_data_f = re.sub(
  57. r'&lt;topic_a&gt;((?:(?!&lt;\/topic_a&gt;).)+)&lt;\/topic_a&gt;',
  58. '<a href="\g<1>">\g<1></a>',
  59. t_data_f
  60. )
  61. t_data_f = re.sub(
  62. r'&lt;topic_call&gt;@((?:(?!&lt;\/topic_call&gt;).)+)&lt;\/topic_call&gt;',
  63. '<a href="/w/user:\g<1>">@\g<1></a>',
  64. t_data_f
  65. )
  66. all_data = '' + \
  67. '<table id="toron">' + \
  68. '<tbody>' + \
  69. '<tr>' + \
  70. '<td id="' + t_color + '">' + \
  71. '<a href="javascript:void(0);" id="' + i[0] + '">#' + i[0] + '</a> ' + ip + ' <span style="float: right;">' + i[2] + '</span>' + \
  72. '</td>' + \
  73. '</tr>' + \
  74. '<tr>' + \
  75. '<td id="' + b_color + '">' + \
  76. '<div id="topic_scroll">' + t_data_f + '</div>' + \
  77. '</td>' + \
  78. '</tr>' + \
  79. '</tbody>' + \
  80. '</table>' + \
  81. '<hr class="main_hr">' + \
  82. ''
  83. json_data[i[0]] = {
  84. "data" : all_data,
  85. "plus_data" : t_plus_data
  86. }
  87. else:
  88. for i in data:
  89. if i[4] != 'O' or (i[4] == 'O' and admin == 1):
  90. t_data_f = i[1]
  91. else:
  92. t_data_f = '(B)'
  93. json_data[i[0]] = {
  94. "data" : t_data_f,
  95. "date" : i[2],
  96. "ip" : ip_pas(i[3], 1),
  97. "block" : i[4],
  98. }
  99. return flask.jsonify(json_data)
  100. else:
  101. return flask.jsonify({})