Browse Source

20220509

pull/75/head
xiaoz 3 years ago
parent
commit
6dfd1505d4
  1. 39
      class/Api.php
  2. 28
      controller/api.php
  3. 2
      templates/admin/header.php
  4. 5
      templates/admin/link_list.php
  5. 25
      templates/admin/static/embed.js

39
class/Api.php

@ -380,6 +380,8 @@ class Api { @@ -380,6 +380,8 @@ class Api {
}
}
$categoryt = array_unique($categoryt);
//追加一个默认分类,用来存储部分链接找不到分类的情况
array_push($categoryt,"默认分类");
//批量创建分类
$this->batch_create_category($categoryt);
@ -398,6 +400,8 @@ class Api { @@ -398,6 +400,8 @@ class Api {
//批量导入链接
foreach ($data as $key => $value) {
$category_name = trim($value['category']);
//如果链接的分类是空的,则设置为默认分类
$value['category'] = empty( $value['category'] ) ? "默认分类" : $value['category'];
foreach ($categorys as $category) {
if( trim( $category['name'] ) == $category_name ) {
@ -405,6 +409,7 @@ class Api { @@ -405,6 +409,7 @@ class Api {
break;
}
}
//合并数据
$link_data = [
'fid' => $fid,
@ -494,6 +499,40 @@ class Api { @@ -494,6 +499,40 @@ class Api {
}
}
}
/**
* 导出HTML链接进行备份
*/
public function export_link(){
//鉴权
$this->auth($token);
//查询所有分类
$categorys = $this->db->select("on_categorys","*");
//定义一个空数组用来存储查询后的数据
$data = [];
//遍历分类
foreach ($categorys as $key => $category) {
//查询该分类下的所有链接
$links = $this->db->select("on_links","*",[
"fid" => $category['id']
]);
// echo $category['name'];
// var_dump($links);
// exit;
//组合为一个一维数组
$arr[$category['name']] = $links;
// var_dump();
// exit;
$data[$category['name']] = $arr[$category['name']];
//清除临时数据
unset($arr);
}
//返回数据
return $data;
}
/**
* name:修改链接
*/

28
controller/api.php

@ -375,4 +375,32 @@ function set_link_attribute($api) { @@ -375,4 +375,32 @@ function set_link_attribute($api) {
"property" => $property
];
$api->set_link_attribute($data);
}
//导出链接数据
function export_link($api) {
header('Content-Type: text/html;charset=utf8');
$data = $api->export_link();
//当前时间
$current = time();
echo <<< EOF
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>从OneNav导出的书签</TITLE>
<H1>Bookmarks</H1>
EOF;
//遍历结果
foreach ($data as $key => $value) {
echo "<DT>\n";
echo "<h3 add_date=\"$current\" last_modified=\"$current\">$key</h3>\n";
echo "<dl><p></p>\n";
foreach ($value as $link) {
$title = $link['title'];
$add_time = $link['add_time'];
echo "<dt><a href = \"$title\" add_date = \"$add_time\" ICON = \"\">$title</a></dt>\n";
}
echo "<p></p></dl>\n";
echo "</DT>\n";
}
}

2
templates/admin/header.php

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
<div class="layui-header">
<div class="layui-logo"><a href="/index.php?c=admin" style="color:#009688;"><h2>OneNav后台管理</h1></a></div>
<div class="layui-logo"><a href="/index.php?c=admin" style="color:#009688;"><h2>OneNav后台管理</h2></a></div>
<!-- 头部区域(可配合layui已有的水平导航) -->
<ul class="layui-nav layui-layout-left">
<li class="layui-nav-item"><a href="/"><i class="layui-icon layui-icon-home"></i> 前台首页</a></li>

5
templates/admin/link_list.php

@ -21,11 +21,11 @@ @@ -21,11 +21,11 @@
<div class="layui-input-inline" style="width: 100px;">
<button class="layui-btn" lay-submit lay-filter="screen_link">查询此分类下的链接</button>
</div>
</div>
</div>
</div>
</form>
</div>
<!-- 表单上面的按钮END -->
<div class="layui-col-lg12">
<table id="link_list" lay-filter="mylink" lay-data="{id: 'mylink_reload'}"></table>
@ -46,6 +46,9 @@ @@ -46,6 +46,9 @@
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick = "">删除</a>
</script>
<!-- 表单下面的按钮 -->
<button class="layui-btn layui-btn-sm" lay-submit onclick = "export_link()">导出所有链接</button>
<!-- 表单下面的按钮END -->
</div>
<!-- 内容主题区域END -->
</div>

25
templates/admin/static/embed.js

@ -783,4 +783,29 @@ function set_link_attribute(ids,property) { @@ -783,4 +783,29 @@ function set_link_attribute(ids,property) {
}
});
}
}
//导出所有链接
function export_link(url, fileName) {
layer.confirm('导出的链接可以导入到浏览器也可以再次导入到OneNav!', {icon: 3, title:'确定导出所有链接?'}, function(index){
var date = new Date();
var current_time = date.toLocaleDateString();
current_time = current_time.replaceAll("/","-");
var url = "index.php?c=api&method=export_link";
var fileName = "OneNav_Export_" + current_time + ".html";
var x = new XMLHttpRequest();
x.open("GET", url, true);
x.responseType = 'blob';
x.onload=function(e) {
var url = window.URL.createObjectURL(x.response)
var a = document.createElement('a');
a.href = url
a.download = fileName;
a.click()
}
x.send();
layer.close(index);
});
}
Loading…
Cancel
Save