view_read.py 8.3 KB

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