view_read.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. from .tool.func import *
  2. def view_read_2(conn, name, doc_rev, doc_from):
  3. curs = conn.cursor()
  4. sub = ''
  5. menu = []
  6. user_doc = ''
  7. category_doc = ''
  8. file_data = ''
  9. ip = ip_check()
  10. name_doc_pass = doc_from
  11. uppage = re.sub(r"/([^/]+)$", '', name)
  12. num = str(doc_rev)
  13. curs.execute(db_change("select sub from rd where title = ? and not stop = 'O' order by date desc"), [name])
  14. topic = 1 if curs.fetchall() else 0
  15. curs.execute(db_change("select title from data where title like ?"), [name + '/%'])
  16. down = 1 if curs.fetchall() else 0
  17. if re.search(r'^category:', name):
  18. category_doc = ''
  19. category_sub = ''
  20. curs.execute(db_change("select link from back where title = ? and type = 'cat' order by link asc"), [name])
  21. category_sql = curs.fetchall()
  22. for data in category_sql:
  23. if re.search(r'^category:', data[0]):
  24. category_sub += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  25. else:
  26. category_doc += '<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>'
  27. if category_doc != '':
  28. category_doc = '<h2 id="cate_normal">' + load_lang('category_title') + '</h2><ul class="inside_ul">' + category_doc + '</ul>'
  29. if category_sub != '':
  30. category_doc += '<h2 id="cate_under">' + load_lang('under_category') + '</h2><ul class="inside_ul">' + category_sub + '</ul>'
  31. elif re.search(r"^user:([^/]*)", name):
  32. match = re.search(r"^user:([^/]*)", name)
  33. user_name = html.escape(match.group(1))
  34. user_doc = '''
  35. <div id="get_user_info"></div>
  36. <script>load_user_info("''' + user_name + '''");</script>
  37. <hr class="main_hr">
  38. '''
  39. if name == 'user:' + user_name:
  40. menu += [['w/' + url_pas(name) + '/' + url_pas(get_time().split()[0]), load_lang('today_doc')]]
  41. elif re.search(r"^file:", name):
  42. mime_type = re.search(r'([^.]+)$', name)
  43. if mime_type:
  44. mime_type = mime_type.group(1).lower()
  45. else:
  46. mime_type = 'jpg'
  47. file_name = re.sub(r'\.([^.]+)$', '', name)
  48. file_name = re.sub(r'^file:', '', file_name)
  49. file_size = str(round(os.path.getsize(os.path.join(load_image_url(), sha224_replace(file_name) + '.' + mime_type)) / 1000, 1))
  50. file_data = '''
  51. <img src="/image/''' + sha224_replace(file_name) + '''.''' + mime_type + '''">
  52. <h2>DATA</h2>
  53. <table>
  54. <tr><td>URL</td><td><a href="/image/''' + url_pas(sha224_replace(name) + '.' + mime_type) + '''">LINK</a></td></tr>
  55. <tr><td>VOLUME</td><td>''' + file_size + '''KB</td></tr>
  56. </table>
  57. <h2>CONTENT</h2>
  58. '''
  59. if num != '0':
  60. curs.execute(db_change("select title from history where title = ? and id = ? and hide = 'O'"), [name, num])
  61. if curs.fetchall() and admin_check(6) != 1:
  62. return redirect('/history/' + url_pas(name))
  63. curs.execute(db_change("select data from history where title = ? and id = ?"), [name, num])
  64. else:
  65. curs.execute(db_change("select data from data where title = ?"), [name])
  66. data = curs.fetchall()
  67. end_data = render_set(
  68. doc_name = name,
  69. doc_data = data[0][0] if data else None
  70. )
  71. if end_data == 'HTTP Request 401.3':
  72. response_data = 401
  73. curs.execute(db_change('select data from other where name = "error_401"'))
  74. sql_d = curs.fetchall()
  75. if sql_d and sql_d[0][0] != '':
  76. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + sql_d[0][0] + '</li></ul>'
  77. else:
  78. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + load_lang('authority_error') + '</li></ul>'
  79. elif end_data == 'HTTP Request 404':
  80. response_data = 404
  81. curs.execute(db_change('select data from other where name = "error_404"'))
  82. sql_d = curs.fetchall()
  83. if sql_d and sql_d[0][0] != '':
  84. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + sql_d[0][0] + '</li></ul>'
  85. else:
  86. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + load_lang('decument_404_error') + '</li></ul>'
  87. curs.execute(db_change('' + \
  88. 'select ip, date, leng, send, id from history ' + \
  89. 'where title = ? and hide != "O" order by id + 0 desc limit 3' + \
  90. ''), [name])
  91. sql_d = curs.fetchall()
  92. if sql_d:
  93. end_data += '<h2>' + load_lang('history') + '</h2><ul class="inside_ul">'
  94. for i in sql_d:
  95. if re.search(r"\+", i[2]):
  96. leng = '<span style="color:green;">(' + i[2] + ')</span>'
  97. elif re.search(r"\-", i[2]):
  98. leng = '<span style="color:red;">(' + i[2] + ')</span>'
  99. else:
  100. leng = '<span style="color:gray;">(' + i[2] + ')</span>'
  101. end_data += '<li>' + i[1] + ' | r' + i[4] + ' | ' + ip_pas(i[0]) + ' | ' + leng + (' | ' + i[3] if i[3] != '' else '') + '</li>'
  102. end_data += '<li><a href="/history/' + url_pas(name) + '">(...)</a></li></ul>'
  103. else:
  104. response_data = 200
  105. if num != '0':
  106. menu += [['history/' + url_pas(name), load_lang('history')]]
  107. sub = ' (r' + str(num) + ')'
  108. acl = 0
  109. r_date = 0
  110. else:
  111. curs.execute(db_change("select title from acl where title = ?"), [name])
  112. acl = 1 if curs.fetchall() else 0
  113. menu_acl = 1 if acl_check(name) == 1 else 0
  114. if response_data == 404:
  115. menu += [['edit/' + url_pas(name), load_lang('create'), menu_acl]]
  116. else:
  117. menu += [['edit/' + url_pas(name), load_lang('edit'), menu_acl]]
  118. menu += [
  119. ['topic/' + url_pas(name), load_lang('discussion'), topic],
  120. ['history/' + url_pas(name), load_lang('history')],
  121. ['xref/' + url_pas(name), load_lang('backlink')],
  122. ['acl/' + url_pas(name), load_lang('acl'), acl],
  123. ]
  124. if name_doc_pass != '':
  125. menu += [['w/' + url_pas(name), load_lang('pass')]]
  126. end_data = '''
  127. <div id="redirect">
  128. <a href="/w/''' + url_pas(name_doc_pass) + '/doc_from/' + url_pas(name) + '">' + name_doc_pass + '</a> ⇨ <b>' + name + '''</b>
  129. </div>
  130. <br>
  131. ''' + end_data
  132. if uppage != 0:
  133. menu += [['w/' + url_pas(uppage), load_lang('upper')]]
  134. if down:
  135. menu += [['down/' + url_pas(name), load_lang('sub')]]
  136. curs.execute(db_change("select date from history where title = ? order by date desc limit 1"), [name])
  137. r_date = curs.fetchall()
  138. r_date = r_date[0][0] if r_date else 0
  139. div = file_data + user_doc + end_data + category_doc
  140. curs.execute(db_change("select data from other where name = 'body'"))
  141. body = curs.fetchall()
  142. div = (body[0][0] + div) if body else div
  143. curs.execute(db_change("select data from other where name = 'bottom_body'"))
  144. body = curs.fetchall()
  145. div += body[0][0] if body else ''
  146. if ip_or_user(ip) == 0:
  147. curs.execute(db_change("select title from scan where user = ? and title = ?"), [ip, name])
  148. watch_list = 2 if curs.fetchall() else 1
  149. else:
  150. watch_list = 0
  151. return easy_minify(flask.render_template(skin_check(),
  152. imp = [name, wiki_set(), wiki_custom(), wiki_css([sub, r_date, watch_list])],
  153. data = div,
  154. menu = menu
  155. )), response_data