2
0

view_read.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. from .tool.func import *
  2. def view_read_2(conn, name):
  3. curs = conn.cursor()
  4. sub = ''
  5. div = ''
  6. ip = ip_check()
  7. run_redirect = ''
  8. num = flask.request.args.get('num', None)
  9. num = int(number_check(num)) if num else None
  10. curs.execute(db_change("select sub from rd where title = ? and not stop = 'O' order by date desc"), [name])
  11. topic = 1 if curs.fetchall() else 0
  12. curs.execute(db_change("select link from back where title = ? and type = 'cat' order by link asc"), [name])
  13. curs.execute(db_change("select title from data where title like ?"), ['%' + name + '/%'])
  14. down = 1 if curs.fetchall() else 0
  15. m = re.search(r"^(.*)\/(.*)$", name)
  16. uppage = m.group(1) if m else 0
  17. if re.search(r'^category:', name):
  18. curs.execute(db_change("select link from back where title = ? and type = 'cat' order by link asc"), [name])
  19. back = curs.fetchall()
  20. if back:
  21. u_div = ''
  22. for data in back:
  23. if div == '':
  24. div = '<br><h2 id="cate_normal">' + load_lang('category_title') + '</h2><ul class="inside_ul">'
  25. if re.search(r'^category:', data[0]):
  26. u_div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  27. else:
  28. curs.execute(db_change("select title from back where title = ? and type = 'include'"), [data[0]])
  29. db_data = curs.fetchall()
  30. if db_data:
  31. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> <a id="inside" href="/xref/' + url_pas(data[0]) + '">(' + load_lang('backlink') + ')</a></li>'
  32. else:
  33. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  34. if div != '':
  35. div += '</ul>'
  36. if u_div != '':
  37. div += '<br><h2 id="cate_under">' + load_lang('under_category') + '</h2><ul class="inside_ul">' + u_div + '</ul>'
  38. cache_data = None
  39. if num:
  40. curs.execute(db_change("select title from history where title = ? and id = ? and hide = 'O'"), [name, str(num)])
  41. if curs.fetchall() and admin_check(6) != 1:
  42. return redirect('/history/' + url_pas(name))
  43. curs.execute(db_change("select data from history where title = ? and id = ?"), [name, str(num)])
  44. else:
  45. curs.execute(db_change("select id from history where title = ? order by id + 0 desc limit 1"), [name])
  46. last_history_num = curs.fetchall()
  47. if last_history_num and not flask.request.args.get('reload', None):
  48. curs.execute(db_change("select data from cache_data where title = ? and id = ?"), [name, last_history_num[0][0]])
  49. cache_data = curs.fetchall()
  50. if not cache_data:
  51. curs.execute(db_change("select data from data where title = ?"), [name])
  52. else:
  53. curs.execute(db_change("select data from data where title = ?"), [name])
  54. if cache_data and acl_check(name, 'render') != 1:
  55. end_data = cache_data[0][0]
  56. else:
  57. data = curs.fetchall()
  58. if data:
  59. else_data = data[0][0]
  60. else:
  61. else_data = None
  62. if flask.request.args.get('from', None) and else_data:
  63. else_data = re.sub(r'^\r\n', '', else_data)
  64. else_data = re.sub(r'\r\n$', '', else_data)
  65. end_data = render_set(
  66. doc_name = name,
  67. doc_data = else_data
  68. )
  69. if not num and acl_check(name, 'render') != 1:
  70. curs.execute(db_change("delete from cache_data where title = ?"), [name])
  71. if last_history_num:
  72. curs.execute(db_change("insert into cache_data (title, data, id) values (?, ?, ?)"), [name, end_data, last_history_num[0][0]])
  73. if end_data == 'HTTP Request 401.3':
  74. response_data = 401
  75. curs.execute(db_change('select data from other where name = "error_401"'))
  76. sql_d = curs.fetchall()
  77. if sql_d and sql_d[0][0] != '':
  78. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + sql_d[0][0] + '</li></ul>'
  79. else:
  80. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + load_lang('authority_error') + '</li></ul>'
  81. elif end_data == 'HTTP Request 404':
  82. response_data = 404
  83. curs.execute(db_change('select data from other where name = "error_404"'))
  84. sql_d = curs.fetchall()
  85. if sql_d and sql_d[0][0] != '':
  86. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + sql_d[0][0] + '</li></ul>'
  87. else:
  88. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + load_lang('decument_404_error') + '</li></ul>'
  89. curs.execute(db_change('' + \
  90. 'select ip, date, leng, send, id from history ' + \
  91. 'where title = ? and hide != "O" order by id + 0 desc limit 3' + \
  92. ''), [name])
  93. sql_d = curs.fetchall()
  94. if sql_d:
  95. end_data += '<h2>' + load_lang('history') + '</h2><ul class="inside_ul">'
  96. for i in sql_d:
  97. if re.search(r"\+", i[2]):
  98. leng = '<span style="color:green;">(' + i[2] + ')</span>'
  99. elif re.search(r"\-", i[2]):
  100. leng = '<span style="color:red;">(' + i[2] + ')</span>'
  101. else:
  102. leng = '<span style="color:gray;">(' + i[2] + ')</span>'
  103. end_data += '<li>' + i[1] + ' | r' + i[4] + ' | ' + ip_pas(i[0]) + ' | ' + leng + (' | ' + i[3] if i[3] != '' else '') + '</li>'
  104. end_data += '<li><a href="/history/' + url_pas(name) + '">(...)</a></li></ul>'
  105. else:
  106. response_data = 200
  107. if num:
  108. menu = [['history/' + url_pas(name), load_lang('history')]]
  109. sub = ' (r' + str(num) + ')'
  110. acl = 0
  111. r_date = 0
  112. else:
  113. curs.execute(db_change("select title from acl where title = ?"), [name])
  114. acl = 1 if curs.fetchall() else 0
  115. menu_acl = 1 if acl_check(name) == 1 else 0
  116. if response_data == 404:
  117. menu = [['edit/' + url_pas(name), load_lang('create'), menu_acl]]
  118. else:
  119. menu = [['edit/' + url_pas(name), load_lang('edit'), menu_acl]]
  120. menu += [
  121. ['topic/' + url_pas(name), load_lang('discussion'), topic],
  122. ['history/' + url_pas(name), load_lang('history')],
  123. ['xref/' + url_pas(name), load_lang('backlink')],
  124. ['acl/' + url_pas(name), load_lang('acl'), acl],
  125. ['w/' + url_pas(name) + '?reload=true', load_lang('reload')]
  126. ]
  127. if flask.request.args.get('from', None):
  128. menu += [['w/' + url_pas(name), load_lang('pass')]]
  129. end_data = '''
  130. <div id="redirect">
  131. <a href="/w/''' + url_pas(flask.request.args.get('from', None)) + '?from=' + url_pas(name) + '">' + flask.request.args.get('from', None) + '</a> ⇨ <b>' + name + '''</b>
  132. </div>
  133. <br>
  134. ''' + end_data
  135. if uppage != 0:
  136. menu += [['w/' + url_pas(uppage), load_lang('upper')]]
  137. if down:
  138. menu += [['down/' + url_pas(name), load_lang('sub')]]
  139. curs.execute(db_change("select date from history where title = ? order by date desc limit 1"), [name])
  140. r_date = curs.fetchall()
  141. r_date = r_date[0][0] if r_date else 0
  142. div = end_data + div
  143. match = re.search(r"^user:([^/]*)", name)
  144. if match:
  145. user_name = match.group(1)
  146. div = '''
  147. <div id="get_user_info"></div>
  148. <script>load_user_info("''' + user_name + '''");</script>
  149. ''' + div
  150. curs.execute(db_change("select data from other where name = 'body'"))
  151. body = curs.fetchall()
  152. div = (body[0][0] + div) if body else div
  153. curs.execute(db_change("select data from other where name = 'bottom_body'"))
  154. body = curs.fetchall()
  155. div += body[0][0] if body else ''
  156. if ip_or_user(ip) == 0:
  157. curs.execute(db_change("select title from scan where user = ? and title = ?"), [ip, name])
  158. watch_list = 2 if curs.fetchall() else 1
  159. else:
  160. watch_list = 0
  161. div += run_redirect
  162. return easy_minify(flask.render_template(skin_check(),
  163. imp = [flask.request.args.get('show', name), wiki_set(), custom(), other2([sub, r_date, watch_list])],
  164. data = div,
  165. menu = menu
  166. )), response_data