view_read.py 8.4 KB

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