view_xref.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from .tool.func import *
  2. def view_xref(name = 'Test', xref_type = 1):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. if acl_check(name, 'render') == 1:
  6. return re_error('/ban')
  7. num = int(number_check(flask.request.args.get('num', '1')))
  8. sql_num = (num * 50 - 50) if num * 50 > 0 else 0
  9. if xref_type == 1:
  10. div = '<a href="/xref_this/' + url_pas(name) + '">(' + load_lang('link_in_this') + ')</a><hr class="main_hr">'
  11. data_sub = '(' + load_lang('backlink') + ')'
  12. else:
  13. div = '<a href="/xref/' + url_pas(name) + '">(' + load_lang('normal') + ')</a><hr class="main_hr">'
  14. data_sub = '(' + load_lang('link_in_this') + ')'
  15. div += '<ul class="opennamu_ul">'
  16. sql_insert = ['link', 'title'] if xref_type == 1 else ['title', 'link']
  17. curs.execute(db_change("" + \
  18. "select distinct " + sql_insert[0] + ", type from back " + \
  19. "where " + sql_insert[1] + " = ? and not type = 'no' and not type = 'nothing'" + \
  20. "order by type asc, title asc limit ?, 50" + \
  21. ""), [
  22. name,
  23. sql_num
  24. ])
  25. data_list = curs.fetchall()
  26. for data in data_list:
  27. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a>'
  28. if data[1]:
  29. div += ' (' + data[1] + ')'
  30. curs.execute(db_change("select title from back where title = ? and type = 'include'"), [data[0]])
  31. db_data = curs.fetchall()
  32. if db_data:
  33. div += ' <a id="inside" href="/xref/' + url_pas(data[0]) + '">(' + load_lang('backlink') + ')</a>'
  34. div += '</li>'
  35. div += '</ul>' + next_fix('/xref/' + url_pas(name) + '?change=' + str(xref_type) + '&num=', num, data_list)
  36. return easy_minify(flask.render_template(skin_check(),
  37. imp = [name, wiki_set(), wiki_custom(), wiki_css([data_sub, 0])],
  38. data = div,
  39. menu = [['w/' + url_pas(name), load_lang('return')], ['xref_reset/' + url_pas(name), load_lang('reset_backlink')]]
  40. ))