view_read.py 8.9 KB

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