view_read.py 8.9 KB

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