view_read.py 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. from .tool.func import *
  2. def view_read_2(conn, name):
  3. curs = conn.cursor()
  4. sub = ''
  5. acl = ''
  6. div = ''
  7. plus_d = ''
  8. plus_t = []
  9. num = flask.request.args.get('num', None)
  10. if num:
  11. num = int(number_check(num))
  12. else:
  13. if not flask.request.args.get('from', None):
  14. curs.execute("select title from back where link = ? and type = 'redirect'", [name])
  15. r_db = curs.fetchall()
  16. if r_db:
  17. r_data = link_fix(r_db[0][0])
  18. return redirect('/w/' + r_data[0] + '?from=' + name + r_data[1])
  19. curs.execute("select sub from rd where title = ? and not stop = 'O' order by date desc", [name])
  20. if curs.fetchall():
  21. sub += ' (' + load_lang('discussion') + ')'
  22. curs.execute("select link from back where title = ? and type = 'cat' order by link asc", [name])
  23. curs.execute("select title from data where title like ?", ['%' + name + '/%'])
  24. if curs.fetchall():
  25. down = 1
  26. else:
  27. down = 0
  28. m = re.search("^(.*)\/(.*)$", name)
  29. if m:
  30. uppage = m.groups()[0]
  31. else:
  32. uppage = 0
  33. if re.search('^category:', name):
  34. curs.execute("select link from back where title = ? and type = 'cat' order by link asc", [name])
  35. back = curs.fetchall()
  36. if back:
  37. div = '<br><h2 id="cate_normal">' + load_lang('category') + '</h2><ul>'
  38. u_div = ''
  39. for data in back:
  40. if re.search('^category:', data[0]):
  41. u_div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  42. else:
  43. curs.execute("select title from back where title = ? and type = 'include'", [data[0]])
  44. db_data = curs.fetchall()
  45. if db_data:
  46. 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>'
  47. else:
  48. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  49. div += '</ul>'
  50. if div == '<br><h2 id="cate_normal">' + load_lang('category') + '</h2><ul></ul>':
  51. div = ''
  52. if u_div != '':
  53. div += '<br><h2 id="cate_under">' + load_lang('under_category') + '</h2><ul>' + u_div + '</ul>'
  54. if num:
  55. curs.execute("select title from history where title = ? and id = ? and hide = 'O'", [name, str(num)])
  56. if curs.fetchall() and admin_check(6) != 1:
  57. return redirect('/history/' + url_pas(name))
  58. curs.execute("select title, data from history where title = ? and id = ?", [name, str(num)])
  59. else:
  60. curs.execute("select title, data from data where title = ?", [name])
  61. data = curs.fetchall()
  62. if data:
  63. else_data = data[0][1]
  64. else:
  65. else_data = None
  66. curs.execute("select decu from acl where title = ?", [name])
  67. data = curs.fetchall()
  68. if data:
  69. acl += ' (' + load_lang('acl') + ')'
  70. if flask.request.args.get('from', None) and else_data:
  71. else_data = re.sub('^\r\n', '', else_data)
  72. else_data = re.sub('\r\n$', '', else_data)
  73. end_data = render_set(
  74. title = name,
  75. data = else_data
  76. )
  77. if end_data == 'HTTP Request 401.3':
  78. response_data = 401
  79. curs.execute('select data from other where name = "error_401"')
  80. sql_d = curs.fetchall()
  81. if sql_d and sql_d[0][0] != '':
  82. end_data = '<h2>' + load_lang('error') + '</h2><ul><li>' + sql_d[0][0] + '</li></ul>'
  83. else:
  84. end_data = '<h2>' + load_lang('error') + '</h2><ul><li>' + load_lang('authority_error') + '</li></ul>'
  85. elif end_data == 'HTTP Request 404':
  86. response_data = 404
  87. curs.execute('select data from other where name = "error_404"')
  88. sql_d = curs.fetchall()
  89. if sql_d and sql_d[0][0] != '':
  90. end_data = '<h2>' + load_lang('error') + '</h2><ul><li>' + sql_d[0][0] + '</li></ul>'
  91. else:
  92. end_data = '<h2>' + load_lang('error') + '</h2><ul><li>' + load_lang('decument_404_error') + '</li></ul>'
  93. curs.execute('select ip, date, leng, send from history where title = ? order by id desc limit 3', [name])
  94. sql_d = curs.fetchall()
  95. if sql_d:
  96. end_data += '<h2>' + load_lang('history') + '</h2><ul>'
  97. for i in sql_d:
  98. if re.search("\+", i[2]):
  99. leng = '<span style="color:green;">(' + i[2] + ')</span>'
  100. elif re.search("\-", i[2]):
  101. leng = '<span style="color:red;">(' + i[2] + ')</span>'
  102. else:
  103. leng = '<span style="color:gray;">(' + i[2] + ')</span>'
  104. end_data += '<li>' + i[1] + ' | ' + ip_pas(i[0]) + ' | ' + leng + (' | ' + i[3] if i[3] != '' else '') + '</li>'
  105. end_data += '<li><a href="/history/' + url_pas(name) + '">(...)</a></li></ul>'
  106. else:
  107. response_data = 200
  108. if num:
  109. menu = [['history/' + url_pas(name), load_lang('history')]]
  110. sub = ' (r' + str(num) + ')'
  111. acl = ''
  112. r_date = 0
  113. else:
  114. if response_data == 404:
  115. menu = [['edit/' + url_pas(name), load_lang('create')]]
  116. else:
  117. menu = [['edit/' + url_pas(name), load_lang('edit')]]
  118. menu += [['topic/' + url_pas(name), load_lang('discussion')], ['history/' + url_pas(name), load_lang('history')], ['xref/' + url_pas(name), load_lang('backlink')], ['acl/' + url_pas(name), load_lang('acl')]]
  119. if flask.request.args.get('from', None):
  120. menu += [['w/' + url_pas(name), load_lang('pass')]]
  121. end_data = '''
  122. <div id="redirect">
  123. <a href="/w/''' + url_pas(flask.request.args.get('from', None)) + '?from=' + url_pas(name) + '">' + flask.request.args.get('from', None) + '</a> → ' + name + '''
  124. </div>
  125. <br>
  126. ''' + end_data
  127. if uppage != 0:
  128. menu += [['w/' + url_pas(uppage), load_lang('upper')]]
  129. if down:
  130. menu += [['down/' + url_pas(name), load_lang('sub')]]
  131. curs.execute("select date from history where title = ? order by date desc limit 1", [name])
  132. date = curs.fetchall()
  133. if date:
  134. r_date = date[0][0]
  135. else:
  136. r_date = 0
  137. div = end_data + div
  138. adsense_code = '<div align="center" style="display: block; margin-bottom: 10px;">{}</div>'
  139. curs.execute("select data from other where name = 'adsense'")
  140. adsense_enabled = curs.fetchall()[0][0]
  141. if adsense_enabled == 'True':
  142. curs.execute("select data from other where name = 'adsense_code'")
  143. adsense_code = adsense_code.format(curs.fetchall()[0][0])
  144. else:
  145. adsense_code = adsense_code.format('')
  146. curs.execute("select data from other where name = 'body'")
  147. body = curs.fetchall()
  148. if body:
  149. div = body[0][0] + '<hr class=\"main_hr\">' + div
  150. div = adsense_code + '<div>' + div + '</div>'
  151. # 이 부분 개선 필요
  152. m = re.search("^user:([^/]*)", name)
  153. if m:
  154. g = m.groups()
  155. plus_d = '''
  156. <table>
  157. <tbody>
  158. <tr>
  159. <td>''' + load_lang('authority') + '''</td>
  160. <td>{}</td>
  161. </tr>
  162. <tr>
  163. <td>''' + load_lang('state') + '''</td>
  164. <td>{}</td>
  165. </tr>
  166. </tbody>
  167. </table>
  168. '''
  169. curs.execute("select acl from user where id = ?", [g[0]])
  170. data = curs.fetchall()
  171. if data:
  172. if data[0][0] != 'user':
  173. plus_t += [data[0][0]]
  174. else:
  175. plus_t += [load_lang('member')]
  176. else:
  177. plus_t += [load_lang('normal')]
  178. if ban_check(g[0]) == 0:
  179. plus_t += [load_lang('normal')]
  180. else:
  181. match = re.search("^([0-9]{1,3}\.[0-9]{1,3})", g[0])
  182. if match:
  183. match = match.groups()[0]
  184. else:
  185. match = '-'
  186. curs.execute("select end, login, band from ban where block = ? or block = ?", [g[0], match])
  187. block_data = curs.fetchall()
  188. if block_data:
  189. if block_data[0][0] != '':
  190. plus_t += [load_lang('period') + ' : ' + block_data[0][0]]
  191. else:
  192. plus_t += [load_lang('limitless')]
  193. if block_data[0][1] != '':
  194. plus_t += [load_lang('login_able')]
  195. if block_data[0][2] == 'O':
  196. plus_t += [load_lang('band_blocked')]
  197. plus_d = plus_d.format(plus_t[0], plus_t[1])
  198. return easy_minify(flask.render_template(skin_check(),
  199. imp = [flask.request.args.get('show', name), wiki_set(), custom(), other2([sub + acl, r_date])],
  200. data = plus_d + div,
  201. menu = menu
  202. )), response_data