Skip to content

Commit effe4ef

Browse files
committed
0.9.28
1 parent 9ceaac1 commit effe4ef

26 files changed

Lines changed: 470 additions & 68 deletions

.htaccess

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
RewriteEngine On
22
RewriteRule '^click\/(.*)$' /index.php?c=click&id=$1 [L]
33
RewriteRule '^api\/(.*)?(.*)$' /index.php?c=api&method=$1&$2 [L]
4-
RewriteRule login /index.php?c=login [NC,L]
54
RewriteRule .*.(db3|rar|gz|json)$ - [F]

class/Api.php

Lines changed: 94 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ protected function auth($token){
206206
/**
207207
* name:添加链接
208208
*/
209-
public function add_link($token,$fid,$title,$url,$description = '',$weight = 0,$property = 0,$url_standby = '',$font_icon=''){
209+
public function add_link($token,$fid,$title,$url,$description = '',$weight = 0,$property = 0,$url_standby = '',$font_icon = ''){
210210
$this->auth($token);
211211
$fid = intval($fid);
212212
//检测链接是否合法
@@ -227,9 +227,13 @@ public function add_link($token,$fid,$title,$url,$description = '',$weight = 0,$
227227
'description' => htmlspecialchars($description,ENT_QUOTES),
228228
'add_time' => time(),
229229
'weight' => $weight,
230-
'property' => $property,
231-
'font_icon' => $font_icon
230+
'property' => $property
232231
];
232+
233+
//如果$font_icon不为空,才一起追加写入数据库
234+
if( !empty($font_icon) ) {
235+
$data['font_icon'] = $font_icon;
236+
}
233237
//插入数据库
234238
$re = $this->db->insert('on_links',$data);
235239
//返回影响行数
@@ -539,11 +543,28 @@ public function upload($token,$type){
539543
* 图标上传
540544
* type:上传类型
541545
*/
542-
public function uploadImages($token,$type){
546+
public function uploadImages($token){
543547
$this->auth($token);
548+
//获取icon名称
549+
$icon_name = $_POST['icon_name'];
550+
//获取老文件名称,然后删除
551+
$old_pic = $_POST['old_pic'];
552+
//如果老文件名称合法,则删除
553+
$pattern = "/^data\/upload\/[0-9]+\/[0-9a-zA-Z]+\.(jpg|jpeg|png|bmp|gif|svg)$/";
554+
//如果名称不合法,则终止执行
555+
if( preg_match($pattern,$old_pic) ){
556+
@unlink($old_pic);
557+
}
558+
559+
//如果名称是空的
560+
if( empty($icon_name) ) {
561+
$this->return_json(-2000,'','获取图标名称失败!');
562+
}
563+
544564
if ($_FILES["file"]["error"] > 0)
545565
{
546-
$this->err_msg(-1015,'File upload failed!');
566+
//$this->err_msg(-1015,'File upload failed!');
567+
$this->return_json(-2000,'','File upload failed!');
547568
}
548569
else
549570
{
@@ -555,20 +576,33 @@ public function uploadImages($token,$type){
555576

556577
//临时文件位置
557578
$temp = $_FILES["file"]["tmp_name"];
558-
if( $suffix != 'ico' && $suffix != 'jpg' && $suffix != 'png' && $suffix != 'bmp' ) {
579+
if( $suffix != 'ico' && $suffix != 'jpg' && $suffix != 'jpeg' && $suffix != 'png' && $suffix != 'bmp' && $suffix != 'gif' && $suffix != 'svg' ) {
559580
//删除临时文件
560-
unlink($filename);
561-
$this->err_msg(-1014,'Unsupported file suffix name!');
581+
@unlink($filename);
582+
@unlink($temp);
583+
$this->return_json(-2000,'','Unsupported file suffix name!');
562584
}
563585

564-
$newfilename='upload/'.time().'.'.$suffix;
565-
566-
if( copy($temp,$newfilename) ) {
586+
//上传路径,格式为data/upload/202212/1669689755.png
587+
$upload_path = "data/upload/".date( "Ym", time() ).'/'.$icon_name.'.'.$suffix;
588+
589+
//如果目录不存在,则创建
590+
$upload_dir = dirname($upload_path);
591+
if( !is_dir( $upload_dir ) ) {
592+
//递归创建目录
593+
mkdir($upload_dir,0755,true);
594+
}
595+
596+
//$newfilename = 'upload/'.time().'.'.$suffix;
597+
//移动临时文件到指定上传路径
598+
if( move_uploaded_file($temp,$upload_path) ) {
567599
$data = [
568-
'code' => 0,
569-
'file_name' => $newfilename
600+
'file_name' => $upload_path
570601
];
571-
exit(json_encode($data));
602+
$this->return_json(200,$data,'success');
603+
}
604+
else{
605+
$this->return_json(-2000,'','上传失败,请检查目录权限!');
572606
}
573607
}
574608
}
@@ -613,6 +647,12 @@ public function export_link(){
613647
public function edit_link($token,$id,$fid,$title,$url,$description = '',$weight = 0,$property = 0,$url_standby = '',$font_icon = ''){
614648
$this->auth($token);
615649
$fid = intval($fid);
650+
/**
651+
* name:获取更新类型
652+
* description:主要是因为兼容部分之前老的接口,老的接口不用变动,只能从OneNav后台添加图标,因此增加type判断是否是OneNav后台
653+
* console:指从OneNav后台进行更新
654+
*/
655+
$type = trim($_GET['type']);
616656
//检测链接是否合法
617657
//$this->check_link($fid,$title,$url);
618658
$this->check_link([
@@ -636,9 +676,16 @@ public function edit_link($token,$id,$fid,$title,$url,$description = '',$weight
636676
'description' => htmlspecialchars($description,ENT_QUOTES),
637677
'up_time' => time(),
638678
'weight' => $weight,
639-
'property' => $property,
640-
'font_icon' => $font_icon
679+
'property' => $property
641680
];
681+
682+
if( !empty($font_icon) ) {
683+
$data['font_icon'] = $font_icon;
684+
}
685+
//如果是从OneNav后台更新,则无论如何都要加上font_icon
686+
if( $type === 'console' ) {
687+
$data['font_icon'] = $font_icon;
688+
}
642689
//插入数据库
643690
$re = $this->db->update('on_links',$data,[ 'id' => $id]);
644691
//返回影响行数
@@ -2226,6 +2273,37 @@ public function site_info() {
22262273

22272274
$this->return_json(200,$site,'success');
22282275
}
2276+
2277+
/**
2278+
* name:删除链接图标
2279+
*/
2280+
public function del_link_icon(){
2281+
//验证授权
2282+
$this->auth($token);
2283+
2284+
//获取图标路径
2285+
$icon_path = trim($_POST['icon_path']);
2286+
//正则判断路径是否合法
2287+
$pattern = "/^data\/upload\/[0-9]+\/[0-9a-zA-Z]+\.(jpg|jpeg|png|bmp|gif|svg)$/";
2288+
//如果名称不合法,则终止执行
2289+
if( !preg_match($pattern,$icon_path) ){
2290+
$this->return_json(-2000,'','非法路径!');
2291+
}
2292+
2293+
//继续执行
2294+
//检查图标是否存在
2295+
if( !is_file($icon_path) ) {
2296+
$this->return_json(-2000,'','图标文件不存在,无需删除!');
2297+
}
2298+
2299+
//执行删除操作
2300+
if( unlink($icon_path) ) {
2301+
$this->return_json(200,'','success');
2302+
}
2303+
else{
2304+
$this->return_json(-2000,'','图标删除失败,请检查目录权限!');
2305+
}
2306+
}
22292307

22302308
}
22312309

controller/api.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ function upload($api){
242242
$api->upload($token,$type);
243243
}
244244
// 上传图标
245-
function uploadImages($api){
245+
function uploadImages(){
246+
global $api;
246247
//获取token
247248
$token = empty( $_POST['token'] ) ? $_GET['token'] : $_POST['token'];
248249
//获取上传类型
249-
$type = $_GET['type'];
250-
$api->uploadImages($token,$type);
250+
$api->uploadImages($token);
251251
}
252252
//书签导入
253253
function imp_link($api) {
@@ -633,4 +633,10 @@ function del_share() {
633633
function site_info() {
634634
global $api;
635635
$api->site_info();
636+
}
637+
638+
//删除图标
639+
function del_link_icon() {
640+
global $api;
641+
$api->del_link_icon();
636642
}

controller/index.php

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,28 @@ function base64($url){
149149
$template = $db->get("on_options","value",[
150150
"key" => "theme"
151151
]);
152+
//获取用户传递的主题参数
153+
$theme = trim( @$_GET['theme'] );
154+
//如果用户传递了主题参数
155+
if( !empty($theme) ) {
156+
//获取所有主题
157+
$themes = get_all_themes();
158+
159+
//查找主题是否存在
160+
if( array_search($theme,$themes) !== FALSE ) {
161+
//改变默认主题
162+
$template = $theme;
163+
}
164+
else{
165+
//主题不存在,终止执行
166+
exit("<h1>主题参数错误!</h1>");
167+
}
168+
}
152169
//获取当前站点信息
153170
$site = $db->get('on_options','value',[ 'key' => "s_site" ]);
154171
$site = unserialize($site);
155172

156173
//获取主题配置信息
157-
//获取主题配置
158174
if( file_exists("templates/".$template."/config.json") ) {
159175
$config_file = "templates/".$template."/config.json";
160176
}
@@ -189,6 +205,53 @@ function base64($url){
189205
$tpl_dir = 'data/templates/';
190206
}
191207

208+
//定义搜索引擎
209+
$search_engines = [
210+
"baidu" => [
211+
"name" => "百度",
212+
"url" => "https://www.baidu.com/s?ie=utf-8&word="
213+
],
214+
"google" => [
215+
"name" => "Google",
216+
"url" => "https://www.google.com/search?q="
217+
],
218+
"bing" => [
219+
"name" => "必应",
220+
"url" => "https://cn.bing.com/search?FORM=BESBTB&q="
221+
],
222+
"sogou" => [
223+
"name" => "搜狗",
224+
"url" => "https://www.sogou.com/web?query="
225+
],
226+
"360" => [
227+
"name" => "360搜索",
228+
"url" => "https://www.so.com/s?ie=utf-8&fr=none&src=360sou_newhome&ssid=&q="
229+
],
230+
"zhihu" => [
231+
"name" => "知乎",
232+
"url" => "https://www.zhihu.com/search?type=content&q="
233+
],
234+
"weibo" => [
235+
"name" => "微博",
236+
"url" => "https://s.weibo.com/weibo?q="
237+
]
238+
];
192239

193-
require($tpl_dir.$template.'/index.php');
194-
?>
240+
//获取主题的最低版本要求
241+
$info_json = @file_get_contents($tpl_dir.$template."/info.json");
242+
243+
if( $info_json ) {
244+
$info = json_decode($info_json);
245+
246+
$min_version = @$info->require->min;
247+
//获取到了最低版本
248+
if( !empty($min_version) ) {
249+
//如果主程序不满足主题要求
250+
if( new_get_version() < $min_version ) {
251+
$onenav_version = new_get_version();
252+
exit($template."主题要求最低OneNav版本为:".$min_version.",您当前OneNav版本为:".$onenav_version.",请先<a title = 'OneNav升级说明' href = 'https://dwz.ovh/br5wt' target = '_blank'>升级OneNav版本!</a>");
253+
}
254+
}
255+
}
256+
//载入主题
257+
require($tpl_dir.$template.'/index.php');

data/update.log

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,11 @@ CREATE INDEX on_options_key_IDX ON on_options ("key");
173173
4. 其它优化和BUG修复
174174

175175
20221117
176-
1. 修复获取分类目录失败的BUG
176+
1. 修复获取分类目录失败的BUG
177+
178+
20221129
179+
1. 新增链接自定义图标支持
180+
2. 修复书签分享私有链接无法查看的BUG
181+
3. 带上?theme=参数可以指定主题
182+
4. 新增heimdall主题
183+
5. 新增OneNav主程序是否满足主题要求的检测

db/onenav.simple.db3

0 Bytes
Binary file not shown.

db/sql/20221129.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE on_links ADD font_icon TEXT(512);

functions/helper.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,70 @@ function jump_mobile() {
108108
header("Location: /index.php?c=admin");
109109
exit;
110110
}
111+
}
112+
113+
//获取所有主题
114+
function get_all_themes() {
115+
//主题目录
116+
$tpl_dir1 = dirname(__DIR__).'/templates/';
117+
//备用主题目录
118+
$tpl_dir2 = dirname(__DIR__).'/data/templates/';
119+
120+
//声明两个空数组用来存放模板目录列表
121+
$tpl_one = [];
122+
$tpl_two = [];
123+
//遍历第一个目录
124+
foreach ( scandir($tpl_dir1) as $value) {
125+
//完整的路径
126+
$path = $tpl_dir1.$value;
127+
//如果是目录,则push到目录列表1
128+
if( is_dir($path) ) {
129+
switch ($value) {
130+
case '.':
131+
case '..':
132+
case 'admin':
133+
case 'mobile':
134+
case 'universal':
135+
continue;
136+
break;
137+
default:
138+
array_push($tpl_one,$value);
139+
break;
140+
}
141+
142+
}
143+
else{
144+
continue;
145+
}
146+
}
147+
//如果第二个目录存在,则遍历
148+
if( is_dir($tpl_dir2) ) {
149+
foreach ( scandir($tpl_dir2) as $value) {
150+
//完整的路径
151+
$path = $tpl_dir2.$value;
152+
//如果是目录,则push到目录列表1
153+
if( is_dir($path) ) {
154+
switch ($value) {
155+
case '.':
156+
case '..':
157+
case 'admin':
158+
continue;
159+
break;
160+
default:
161+
array_push($tpl_two,$value);
162+
break;
163+
}
164+
}
165+
else{
166+
continue;
167+
}
168+
}
169+
}
170+
171+
//合并目录
172+
//现在$tpl_one是合并后的完整主题列表
173+
$tpls = array_merge($tpl_one,$tpl_two);
174+
175+
$tpls = array_unique($tpls);
176+
return $tpls;
111177
}

static/images/white64.png

119 Bytes
Loading

0 commit comments

Comments
 (0)