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. 12
      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 { @@ -391,6 +391,28 @@ class Api {
];
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
*/

11
controller/admin.php

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

13
controller/api.php

@ -43,6 +43,9 @@ switch ($method) { @@ -43,6 +43,9 @@ switch ($method) {
case 'get_link_info':
get_link_info($api);
break;
case 'add_js':
add_js($api);
break;
default:
# code...
break;
@ -174,4 +177,14 @@ function get_link_info($api) { @@ -174,4 +177,14 @@ function get_link_info($api) {
//获取URL
$url = @$_POST['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 @@ @@ -0,0 +1,3 @@
20200409
1. 新增快捷键支持
2. 后台增加自定义js功能

27
templates/admin/ext_js.php

@ -0,0 +1,27 @@ @@ -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 @@ @@ -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'); ?>

12
templates/admin/left.php

@ -17,9 +17,19 @@ @@ -17,9 +17,19 @@
<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=add_link">添加链接</a></dd>
<dd><a href="/index.php?c=admin&page=imp_link">书签导入</a></dd>
</dl>
</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>
</div>
</div>

14
templates/admin/static/embed.js

@ -205,6 +205,20 @@ layui.use(['element','table','layer','form'], function(){ @@ -205,6 +205,20 @@ layui.use(['element','table','layer','form'], function(){
console.log(data.field) //当前容器的全部表单字段,名值对形式:{name: value}
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){
$.post('/index.php?c=api&method=edit_category',data.field,function(data,status){

4
templates/default/index.php

@ -13,8 +13,7 @@ @@ -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="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>
<?php echo $onenav['extend']; ?>
<script src="https://cdn.jsdelivr.net/npm/hotkeys-js@3.7.3/dist/hotkeys.min.js"></script>
</head>
<body class = "mdui-drawer-body-left mdui-appbar-with-toolbar mdui-theme-primary-indigo mdui-theme-accent-pink mdui-loaded">
<!--导航工具-->
@ -193,4 +192,5 @@ @@ -193,4 +192,5 @@
<script>
<?php echo $onenav['right_menu']; ?>
</script>
<?php echo $onenav['extend']; ?>
</html>

24
templates/default/static/embed.js

@ -211,6 +211,10 @@ $.contextMenu({ @@ -211,6 +211,10 @@ $.contextMenu({
// 添加链接按钮
$("#add").click(function(){
open_add_link();
});
function open_add_link(){
layer.open({
type: 2,
title: '添加链接',
@ -219,4 +223,24 @@ $("#add").click(function(){ @@ -219,4 +223,24 @@ $("#add").click(function(){
area : ['800px' , '520px'],
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 @@ @@ -1,5 +1,5 @@
<?php
$content = file_get_contents('./bookmarks_2021_4_8.html');
$content = file_get_contents('./bookmarks.html');
$pattern = "/<A.*<\/A>/i";

Loading…
Cancel
Save