Browse Source

0409

pull/14/head
xiaoz 4 years ago
parent
commit
bb5b0567e1
  1. 22
      class/Api.php
  2. 11
      controller/admin.php
  3. 13
      controller/api.php
  4. 3
      data/update.txt
  5. 27
      templates/admin/ext_js.php
  6. 49
      templates/admin/imp_link.php
  7. 10
      templates/admin/left.php
  8. 14
      templates/admin/static/embed.js
  9. 4
      templates/default/index.php
  10. 24
      templates/default/static/embed.js
  11. 2
      test.php

22
class/Api.php

@ -391,6 +391,28 @@ class Api {
]; ];
exit(json_encode($data)); exit(json_encode($data));
} }
/**
* 自定义js
*/
public function add_js($token,$content){
$this->auth($token);
//如果内容为空
// if( $content == '' ){
// $this->err_msg(-1013,'The content cannot be empty!');
// }
//写入文件
try{
file_put_contents("data/extend.js",$content);
$data = [
'code' => 0,
'data' => 'success'
];
exit(json_encode($data));
}
catch(Exception $e){
$this->err_msg(-2000,$e->getMessage());
}
}
/** /**
* 获取IP * 获取IP
*/ */

11
controller/admin.php

@ -68,6 +68,17 @@ if ($page == 'logout') {
exit; exit;
} }
//如果是自定义js页面
if ($page == 'ext_js') {
//判断文件是否存在
if (is_file('data/extend.js')) {
$content = file_get_contents('data/extend.js');
}
else{
$content = '';
}
}
$page = $page.'.php'; $page = $page.'.php';
//获取访客IP //获取访客IP

13
controller/api.php

@ -43,6 +43,9 @@ switch ($method) {
case 'get_link_info': case 'get_link_info':
get_link_info($api); get_link_info($api);
break; break;
case 'add_js':
add_js($api);
break;
default: default:
# code... # code...
break; break;
@ -175,3 +178,13 @@ function get_link_info($api) {
$url = @$_POST['url']; $url = @$_POST['url'];
$api->get_link_info($token,$url); $api->get_link_info($token,$url);
} }
/**
* 添加自定义js
*/
function add_js($api) {
//获取token
$token = $_POST['token'];
$content = @$_POST['content'];
$api->add_js($token,$content);
}

3
data/update.txt

@ -0,0 +1,3 @@
20200409
1. 新增快捷键支持
2. 后台增加自定义js功能

27
templates/admin/ext_js.php

@ -0,0 +1,27 @@
<?php include_once('header.php'); ?>
<?php include_once('left.php'); ?>
<div class="layui-body">
<!-- 内容主体区域 -->
<div class="layui-row content-body">
<div class="layui-col-lg12">
<form class="layui-form">
<div style = "margin-bottom:1.6em;"><h3>自定义JavaScript,仅对默认主题有效:</h3></div>
<div class="layui-form-item layui-form-text">
<textarea name="content" rows="20" required placeholder="请输入" class="layui-textarea"><?php echo $content; ?></textarea>
</div>
<div class="layui-form-item">
<div>
<button class="layui-btn" lay-submit lay-filter="add_js">添加</button>
<!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
</div>
</div>
</form>
</div>
</div>
<!-- 内容主题区域END -->
</div>
<?php include_once('footer.php'); ?>

49
templates/admin/imp_link.php

@ -0,0 +1,49 @@
<?php include_once('header.php'); ?>
<?php include_once('left.php'); ?>
<div class="layui-body">
<!-- 内容主体区域 -->
<div class="layui-row content-body">
<div class="layui-col-lg12">
<form class="layui-form">
<div class="layui-form-item">
<label class="layui-form-label">URL</label>
<div class="layui-input-block">
<input type="url" id = "url" name="url" required lay-verify="required|url" placeholder="请输入有效链接" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">所属分类</label>
<div class="layui-input-block">
<select name="fid" lay-verify="required" lay-search>
<option value=""></option>
<?php foreach ($categorys as $category) {
# code...
?>
<option value="<?php echo $category['id'] ?>"><?php echo $category['name']; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">是否私有</label>
<div class="layui-input-block">
<input type="checkbox" name="property" value = "1" lay-skin="switch" lay-text="是|否">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="add_link">导入</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
</div>
</div>
<!-- 内容主题区域END -->
</div>
<?php include_once('footer.php'); ?>

10
templates/admin/left.php

@ -17,9 +17,19 @@
<dl class="layui-nav-child"> <dl class="layui-nav-child">
<dd><a href="/index.php?c=admin&page=link_list">我的链接</a></dd> <dd><a href="/index.php?c=admin&page=link_list">我的链接</a></dd>
<dd><a href="/index.php?c=admin&page=add_link">添加链接</a></dd> <dd><a href="/index.php?c=admin&page=add_link">添加链接</a></dd>
<dd><a href="/index.php?c=admin&page=imp_link">书签导入</a></dd>
</dl> </dl>
</li> </li>
</ul>
<ul class="layui-nav layui-nav-tree" lay-filter="test">
<li class="layui-nav-item layui-nav-itemed">
<a class="" href="javascript:;">高级功能</a>
<dl class="layui-nav-child">
<dd><a href="/index.php?c=admin&page=ext_js">自定义JavaScript</a></dd>
</dl>
</li>
</ul> </ul>
</div> </div>
</div> </div>

14
templates/admin/static/embed.js

@ -205,6 +205,20 @@ layui.use(['element','table','layer','form'], function(){
console.log(data.field) //当前容器的全部表单字段,名值对形式:{name: value} console.log(data.field) //当前容器的全部表单字段,名值对形式:{name: value}
return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。 return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。
}); });
//添加自定义js
form.on('submit(add_js)', function(data){
$.post('/index.php?c=api&method=add_js',data.field,function(data,status){
//如果添加成功
if(data.code == 0) {
layer.msg('已添加!', {icon: 1});
}
else{
layer.msg(data.err_msg, {icon: 5});
}
});
//console.log(data.field) //当前容器的全部表单字段,名值对形式:{name: value}
return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。
});
//修改分类目录 //修改分类目录
form.on('submit(edit_category)', function(data){ form.on('submit(edit_category)', function(data){
$.post('/index.php?c=api&method=edit_category',data.field,function(data,status){ $.post('/index.php?c=api&method=edit_category',data.field,function(data,status){

4
templates/default/index.php

@ -13,8 +13,7 @@
<link rel="stylesheet" href="https://libs.xiaoz.top/font-awesome/4.7.0/css/font-awesome.css"> <link rel="stylesheet" href="https://libs.xiaoz.top/font-awesome/4.7.0/css/font-awesome.css">
<link rel="stylesheet" href="templates/<?php echo TEMPLATE; ?>/static/style.css?v=<?php echo $version; ?>"> <link rel="stylesheet" href="templates/<?php echo TEMPLATE; ?>/static/style.css?v=<?php echo $version; ?>">
<script src = 'https://libs.xiaoz.top/mdui/v1.0.1/js/mdui.min.js'></script> <script src = 'https://libs.xiaoz.top/mdui/v1.0.1/js/mdui.min.js'></script>
<?php echo $onenav['extend']; ?> <script src="https://cdn.jsdelivr.net/npm/hotkeys-js@3.7.3/dist/hotkeys.min.js"></script>
</head> </head>
<body class = "mdui-drawer-body-left mdui-appbar-with-toolbar mdui-theme-primary-indigo mdui-theme-accent-pink mdui-loaded"> <body class = "mdui-drawer-body-left mdui-appbar-with-toolbar mdui-theme-primary-indigo mdui-theme-accent-pink mdui-loaded">
<!--导航工具--> <!--导航工具-->
@ -193,4 +192,5 @@
<script> <script>
<?php echo $onenav['right_menu']; ?> <?php echo $onenav['right_menu']; ?>
</script> </script>
<?php echo $onenav['extend']; ?>
</html> </html>

24
templates/default/static/embed.js

@ -211,6 +211,10 @@ $.contextMenu({
// 添加链接按钮 // 添加链接按钮
$("#add").click(function(){ $("#add").click(function(){
open_add_link();
});
function open_add_link(){
layer.open({ layer.open({
type: 2, type: 2,
title: '添加链接', title: '添加链接',
@ -219,4 +223,24 @@ $("#add").click(function(){
area : ['800px' , '520px'], area : ['800px' , '520px'],
content: '/index.php?c=admin&page=add_link_tpl' content: '/index.php?c=admin&page=add_link_tpl'
}); });
}
//搜索框失去焦点
function clean_search(){
$(".search").val('');
$(".search").blur();
}
//搜索框得到焦点
function on_search(){
$(".search").focus();
$(".search").val('');
}
hotkeys('a,esc', function (event, handler){
switch (handler.key) {
case 'a': open_add_link();
break;
case 'esc': clean_search();
break;
default: alert(event);
}
}); });

2
test.php

@ -1,5 +1,5 @@
<?php <?php
$content = file_get_contents('./bookmarks_2021_4_8.html'); $content = file_get_contents('./bookmarks.html');
$pattern = "/<A.*<\/A>/i"; $pattern = "/<A.*<\/A>/i";

Loading…
Cancel
Save