view_read.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. name_view = name
  20. category_doc = ''
  21. category_sub = ''
  22. curs.execute(db_change("select link from back where title = ? and type = 'cat' order by link asc"), [name])
  23. category_sql = curs.fetchall()
  24. for data in category_sql:
  25. if data[0].startswith('category:'):
  26. category_sub += '<li><a href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a></li>'
  27. else:
  28. category_doc += '' + \
  29. '<li><a href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a> ' + \
  30. '<a id="inside" href="/xref/' + url_pas(data[0]) + '">(' + load_lang('backlink') + ')</a></li>' + \
  31. ''
  32. if category_doc != '':
  33. category_doc = '<h2 id="cate_normal">' + load_lang('category_title') + '</h2><ul class="inside_ul">' + category_doc + '</ul>'
  34. if category_sub != '':
  35. category_doc += '<h2 id="cate_under">' + load_lang('under_category') + '</h2><ul class="inside_ul">' + category_sub + '</ul>'
  36. elif re.search(r"^user:([^/]*)", name):
  37. name_view = name
  38. match = re.search(r"^user:([^/]*)", name)
  39. user_name = html.escape(match.group(1))
  40. user_doc = ''
  41. # S admin or owner 특수 틀 추가
  42. if admin_check('all', None, user_name) == 1:
  43. if admin_check(None, None, user_name) == 1:
  44. curs.execute(db_change('select data from other where name = "phrase_user_page_owner"'))
  45. db_data = curs.fetchall()
  46. if db_data and db_data[0][0] != '':
  47. user_doc += db_data[0][0] + '<br>'
  48. else:
  49. curs.execute(db_change('select data from other where name = "phrase_user_page_admin"'))
  50. db_data = curs.fetchall()
  51. if db_data and db_data[0][0] != '':
  52. user_doc += db_data[0][0] + '<br>'
  53. else:
  54. curs.execute(db_change('select data from other where name = "phrase_user_page_admin"'))
  55. db_data = curs.fetchall()
  56. if db_data and db_data[0][0] != '':
  57. user_doc += db_data[0][0] + '<br>'
  58. # E
  59. user_doc += '''
  60. <div id="opennamu_get_user_info">''' + html.escape(user_name) + '''</div>
  61. <hr class="main_hr">
  62. '''
  63. if name == 'user:' + user_name:
  64. menu += [['w/' + url_pas(name) + '/' + url_pas(get_time().split()[0]), load_lang('today_doc')]]
  65. elif re.search(r"^file:", name):
  66. name_view = name
  67. mime_type = re.search(r'([^.]+)$', name)
  68. if mime_type:
  69. mime_type = mime_type.group(1).lower()
  70. else:
  71. mime_type = 'jpg'
  72. file_name = re.sub(r'\.([^.]+)$', '', name)
  73. file_name = re.sub(r'^file:', '', file_name)
  74. file_all_name = sha224_replace(file_name) + '.' + mime_type
  75. file_path_name = os.path.join(load_image_url(), file_all_name)
  76. if os.path.exists(file_path_name):
  77. file_size = str(round(os.path.getsize(file_path_name) / 1000, 1))
  78. file_data = '''
  79. <img src="/image/''' + url_pas(file_all_name) + '''">
  80. <h2>DATA</h2>
  81. <table>
  82. <tr><td>URL</td><td><a href="/image/''' + url_pas(file_all_name) + '''">LINK</a></td></tr>
  83. <tr><td>VOLUME</td><td>''' + file_size + '''KB</td></tr>
  84. </table>
  85. <h2>CONTENT</h2>
  86. '''
  87. menu += [['delete_file/' + url_pas(name), load_lang('file_delete')]]
  88. else:
  89. file_data = ''
  90. else:
  91. name_view = name
  92. if num != '0':
  93. curs.execute(db_change("select title from history where title = ? and id = ? and hide = 'O'"), [name, num])
  94. if curs.fetchall() and admin_check(6) != 1:
  95. return redirect('/history/' + url_pas(name))
  96. curs.execute(db_change("select data from history where title = ? and id = ?"), [name, num])
  97. else:
  98. curs.execute(db_change("select data from data where title = ?"), [name])
  99. data = curs.fetchall()
  100. end_data = render_set(
  101. doc_name = name,
  102. doc_data = data[0][0] if data else None
  103. )
  104. if end_data == 'HTTP Request 401.3':
  105. response_data = 401
  106. curs.execute(db_change('select data from other where name = "error_401"'))
  107. sql_d = curs.fetchall()
  108. if sql_d and sql_d[0][0] != '':
  109. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + sql_d[0][0] + '</li></ul>'
  110. else:
  111. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + load_lang('authority_error') + '</li></ul>'
  112. elif end_data == 'HTTP Request 404':
  113. response_data = 404
  114. curs.execute(db_change('select data from other where name = "error_404"'))
  115. sql_d = curs.fetchall()
  116. if sql_d and sql_d[0][0] != '':
  117. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + sql_d[0][0] + '</li></ul>'
  118. else:
  119. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + load_lang('decument_404_error') + '</li></ul>'
  120. curs.execute(db_change('' + \
  121. 'select ip, date, leng, send, id from history ' + \
  122. 'where title = ? and hide != "O" order by id + 0 desc limit 3' + \
  123. ''), [name])
  124. sql_d = curs.fetchall()
  125. if sql_d:
  126. end_data += '<h2>' + load_lang('history') + '</h2><ul class="inside_ul">'
  127. for i in sql_d:
  128. if re.search(r"\+", i[2]):
  129. leng = '<span style="color:green;">(' + i[2] + ')</span>'
  130. elif re.search(r"\-", i[2]):
  131. leng = '<span style="color:red;">(' + i[2] + ')</span>'
  132. else:
  133. leng = '<span style="color:gray;">(' + i[2] + ')</span>'
  134. end_data += '<li>' + i[1] + ' | r' + i[4] + ' | ' + ip_pas(i[0]) + ' | ' + leng + (' | ' + i[3] if i[3] != '' else '') + '</li>'
  135. end_data += '<li><a href="/history/' + url_pas(name) + '">(...)</a></li></ul>'
  136. else:
  137. response_data = 200
  138. if num != '0':
  139. menu += [['history/' + url_pas(name), load_lang('history')]]
  140. sub = ' (r' + str(num) + ')'
  141. acl = 0
  142. r_date = 0
  143. else:
  144. curs.execute(db_change("select title from acl where title = ?"), [name])
  145. acl = 1 if curs.fetchall() else 0
  146. menu_acl = 1 if acl_check(name) == 1 else 0
  147. if response_data == 404:
  148. menu += [['edit/' + url_pas(name), load_lang('create'), menu_acl]]
  149. else:
  150. menu += [['edit/' + url_pas(name), load_lang('edit'), menu_acl]]
  151. menu += [
  152. ['topic/' + url_pas(name), load_lang('discussion'), topic],
  153. ['history/' + url_pas(name), load_lang('history')],
  154. ['xref/' + url_pas(name), load_lang('backlink')],
  155. ['acl/' + url_pas(name), load_lang('acl'), acl],
  156. ]
  157. if do_type == 'from':
  158. menu += [['w/' + url_pas(name), load_lang('pass')]]
  159. if flask.session and 'lastest_document' in flask.session:
  160. end_data = '''
  161. <div id="redirect">
  162. <a href="/w_from/''' + url_pas(flask.session['lastest_document']) + '''">''' + flask.session['lastest_document'] + '''</a> ⇨ <b>''' + name + '''</b>
  163. </div>
  164. <br>
  165. ''' + end_data
  166. flask.session['lastest_document'] = name
  167. else:
  168. flask.session['lastest_document'] = name
  169. if uppage != 0:
  170. menu += [['w/' + url_pas(uppage), load_lang('upper')]]
  171. if down:
  172. menu += [['down/' + url_pas(name), load_lang('sub')]]
  173. curs.execute(db_change("select date from history where title = ? order by date desc limit 1"), [name])
  174. r_date = curs.fetchall()
  175. r_date = r_date[0][0] if r_date else 0
  176. div = file_data + user_doc + end_data + category_doc
  177. if num != '0':
  178. curs.execute(db_change('select data from other where name = "phrase_old_page_warring"'))
  179. db_data = curs.fetchall()
  180. if db_data and db_data[0][0] != '':
  181. div = db_data[0][0] + '<hr class="main_hr">' + div
  182. curs.execute(db_change("select data from other where name = 'body'"))
  183. body = curs.fetchall()
  184. div = (body[0][0] + div) if body else div
  185. curs.execute(db_change("select data from other where name = 'bottom_body'"))
  186. body = curs.fetchall()
  187. div += body[0][0] if body else ''
  188. if ip_or_user(ip) == 0:
  189. curs.execute(db_change("select title from scan where user = ? and title = ?"), [ip, name])
  190. watch_list = 2 if curs.fetchall() else 1
  191. else:
  192. watch_list = 0
  193. return easy_minify(flask.render_template(skin_check(),
  194. imp = [name_view, wiki_set(), wiki_custom(), wiki_css([sub, r_date, watch_list])],
  195. data = div,
  196. menu = menu
  197. )), response_data