view_xref.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. curs.execute(db_change('select data from other where name = "link_case_insensitive"'))
  17. db_data = curs.fetchall()
  18. link_case_insensitive = ' collate nocase' if db_data and db_data[0][0] != '' else ''
  19. sql_insert = ['link', 'title'] if xref_type == 1 else ['title', 'link']
  20. curs.execute(db_change("" + \
  21. "select distinct " + sql_insert[0] + ", type from back " + \
  22. "where " + sql_insert[1] + " = ?" + link_case_insensitive + " and not type = 'no' and not type = 'nothing' " + \
  23. "order by type asc, " + sql_insert[0] + " asc limit ?, 50" + \
  24. ""), [
  25. name,
  26. sql_num
  27. ])
  28. data_list = curs.fetchall()
  29. for data in data_list:
  30. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a>'
  31. if data[1]:
  32. div += ' (' + data[1] + ')'
  33. curs.execute(db_change("select title from back where title = ? and type = 'include'"), [data[0]])
  34. db_data = curs.fetchall()
  35. if db_data:
  36. div += ' <a class="opennamu_link_inter" href="/xref/' + url_pas(data[0]) + '">(' + load_lang('backlink') + ')</a>'
  37. div += '</li>'
  38. div += '</ul>' + next_fix('/xref/' + url_pas(name) + '?change=' + str(xref_type) + '&num=', num, data_list)
  39. return easy_minify(flask.render_template(skin_check(),
  40. imp = [name, wiki_set(), wiki_custom(), wiki_css([data_sub, 0])],
  41. data = div,
  42. menu = [['w/' + url_pas(name), load_lang('return')], ['xref_reset/' + url_pas(name), load_lang('reset_backlink')]]
  43. ))