view_read.py 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. 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. curs.execute(db_change("select title from back where link = ? and type = 'redirect'"), [name])
  14. r_db = curs.fetchall()
  15. if r_db:
  16. r_data = link_fix(r_db[0][0])
  17. return redirect('/w/' + url_pas(r_data[0]) + '?from=' + name + r_data[1])
  18. curs.execute(db_change("select sub from rd where title = ? and not stop = 'O' order by date desc"), [name])
  19. if curs.fetchall():
  20. topic = 1
  21. else:
  22. topic = 0
  23. curs.execute(db_change("select link from back where title = ? and type = 'cat' order by link asc"), [name])
  24. curs.execute(db_change("select title from data where title >= '' and title like ?"), ['%' + name + '/%'])
  25. if curs.fetchall():
  26. down = 1
  27. else:
  28. down = 0
  29. m = re.search("^(.*)\/(.*)$", name)
  30. if m:
  31. uppage = m.groups()[0]
  32. else:
  33. uppage = 0
  34. if re.search('^category:', name):
  35. curs.execute(db_change("select link from back where title = ? and type = 'cat' order by link asc"), [name])
  36. back = curs.fetchall()
  37. if back:
  38. u_div = ''
  39. for data in back:
  40. if div == '':
  41. div = '<br><h2 id="cate_normal">' + load_lang('category_title') + '</h2><ul>'
  42. if re.search('^category:', data[0]):
  43. u_div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  44. else:
  45. curs.execute(db_change("select title from back where title = ? and type = 'include'"), [data[0]])
  46. db_data = curs.fetchall()
  47. if db_data:
  48. 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>'
  49. else:
  50. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  51. if div != '':
  52. div += '</ul>'
  53. if u_div != '':
  54. div += '<br><h2 id="cate_under">' + load_lang('under_category') + '</h2><ul>' + u_div + '</ul>'
  55. cache_data = None
  56. if num:
  57. curs.execute(db_change("select title from history where title = ? and id = ? and hide = 'O'"), [name, str(num)])
  58. if curs.fetchall() and admin_check(6) != 1:
  59. return redirect('/history/' + url_pas(name))
  60. curs.execute(db_change("select data from history where title = ? and id = ?"), [name, str(num)])
  61. else:
  62. curs.execute(db_change("select id from history where title = ? order by id + 0 desc limit 1"), [name])
  63. last_history_num = curs.fetchall()
  64. if last_history_num and not flask.request.args.get('reload', None):
  65. curs.execute(db_change("select data from cache_data where title = ? and id = ?"), [name, last_history_num[0][0]])
  66. cache_data = curs.fetchall()
  67. if not cache_data:
  68. curs.execute(db_change("select data from data where title = ?"), [name])
  69. else:
  70. curs.execute(db_change("select data from data where title = ?"), [name])
  71. if cache_data and acl_check(name, 'render') != 1:
  72. end_data = cache_data[0][0]
  73. else:
  74. data = curs.fetchall()
  75. if data:
  76. else_data = data[0][0]
  77. else:
  78. else_data = None
  79. curs.execute(db_change("select decu from acl where title = ?"), [name])
  80. data = curs.fetchall()
  81. if data:
  82. acl = 1
  83. if flask.request.args.get('from', None) and else_data:
  84. else_data = re.sub('^\r\n', '', else_data)
  85. else_data = re.sub('\r\n$', '', else_data)
  86. end_data = render_set(
  87. title = name,
  88. data = else_data
  89. )
  90. if not num and acl_check(name, 'render') != 1:
  91. curs.execute(db_change("delete from cache_data where title = ?"), [name])
  92. if last_history_num:
  93. curs.execute(db_change("insert into cache_data (title, data, id) values (?, ?, ?)"), [name, end_data, last_history_num[0][0]])
  94. if end_data == 'HTTP Request 401.3':
  95. response_data = 401
  96. curs.execute(db_change('select data from other where name = "error_401"'))
  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('authority_error') + '</li></ul>'
  102. elif end_data == 'HTTP Request 404':
  103. response_data = 404
  104. curs.execute(db_change('select data from other where name = "error_404"'))
  105. sql_d = curs.fetchall()
  106. if sql_d and sql_d[0][0] != '':
  107. end_data = '<h2>' + load_lang('error') + '</h2><ul><li>' + sql_d[0][0] + '</li></ul>'
  108. else:
  109. end_data = '<h2>' + load_lang('error') + '</h2><ul><li>' + load_lang('decument_404_error') + '</li></ul>'
  110. curs.execute(db_change('select ip, date, leng, send from history where title = ? order by id desc limit 3'), [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] + ' | ' + 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. adsense_code = '<div align="center" style="display: block; margin-bottom: 10px;">{}</div>'
  162. curs.execute(db_change("select data from other where name = 'adsense'"))
  163. adsense_enabled = curs.fetchall()[0][0]
  164. if adsense_enabled == 'True':
  165. curs.execute(db_change("select data from other where name = 'adsense_code'"))
  166. adsense_code = adsense_code.format(curs.fetchall()[0][0])
  167. else:
  168. adsense_code = adsense_code.format('')
  169. div = adsense_code + '<div>' + div + '</div>'
  170. match = re.search("^user:([^/]*)", name)
  171. if match:
  172. user_name = match.groups()[0]
  173. div = '''
  174. <div id="get_user_info"></div>
  175. <script>load_user_info("''' + user_name + '''");</script>
  176. ''' + div
  177. curs.execute(db_change("select data from other where name = 'body'"))
  178. body = curs.fetchall()
  179. if body:
  180. div = body[0][0] + '<hr class=\"main_hr\">' + div
  181. curs.execute(db_change("select data from other where name = 'bottom_body'"))
  182. body = curs.fetchall()
  183. if body:
  184. div += '<hr class=\"main_hr\">' + body[0][0]
  185. if ip_or_user(ip) == 0:
  186. curs.execute(db_change("select title from scan where user = ? and title = ?"), [ip, name])
  187. if curs.fetchall():
  188. watch_list = 2
  189. else:
  190. watch_list = 1
  191. else:
  192. watch_list = 0
  193. return easy_minify(flask.render_template(skin_check(),
  194. imp = [flask.request.args.get('show', name), wiki_set(), custom(), other2([sub, r_date, watch_list])],
  195. data = div,
  196. menu = menu
  197. )), response_data