2
0

api_topic_sub.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. t_data_f = re.sub(
  56. r'&lt;topic_a&gt;((?:(?!&lt;\/topic_a&gt;).)+)&lt;\/topic_a&gt;',
  57. '<a href="\g<1>">\g<1></a>',
  58. t_data_f
  59. )
  60. t_data_f = re.sub(
  61. r'&lt;topic_call&gt;@((?:(?!&lt;\/topic_call&gt;).)+)&lt;\/topic_call&gt;',
  62. '<a href="/w/user:\g<1>">@\g<1></a>',
  63. t_data_f
  64. )
  65. all_data = '' + \
  66. '<table id="toron">' + \
  67. '<tbody>' + \
  68. '<tr>' + \
  69. '<td id="' + t_color + '">' + \
  70. '<a href="javascript:void(0);" id="' + i[0] + '">#' + i[0] + '</a> ' + ip + ' <span style="float: right;">' + i[2] + '</span>' + \
  71. '</td>' + \
  72. '</tr>' + \
  73. '<tr>' + \
  74. '<td id="' + b_color + '">' + \
  75. '<div id="topic_scroll">' + t_data_f + '</div>' + \
  76. '</td>' + \
  77. '</tr>' + \
  78. '</tbody>' + \
  79. '</table>' + \
  80. '<hr class="main_hr">' + \
  81. ''
  82. json_data[i[0]] = {
  83. "data" : all_data,
  84. "plus_data" : t_plus_data
  85. }
  86. else:
  87. if i[4] != 'O' or (i[4] == 'O' and admin == 1):
  88. t_data_f = i[1]
  89. else:
  90. curs.execute(db_change("select who from re_admin where what = ? order by time desc limit 1"), [
  91. 'blind (' + name + ' - ' + sub + '#' + str(i[0]) + ')'
  92. ])
  93. who_blind = curs.fetchall()
  94. if who_blind:
  95. t_data_f = '[[user:' + who_blind[0][0] + ']] block'
  96. else:
  97. t_data_f = 'block'
  98. json_data[i[0]] = {
  99. "data" : t_data_f,
  100. "date" : i[2],
  101. "ip" : ip_pas(i[3], 1),
  102. "block" : i[4],
  103. }
  104. return flask.jsonify(json_data)
  105. else:
  106. return flask.jsonify({})