view_read.py 11 KB

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