Browse Source

20220429

pull/71/head
xiaoz 2 years ago
parent
commit
ecbef7833d
  1. 105
      class/Api.php
  2. 31
      controller/admin.php
  3. 36
      controller/api.php
  4. 101
      controller/ico.php
  5. 26
      controller/index.php

105
class/Api.php

@ -214,6 +214,38 @@ class Api { @@ -214,6 +214,38 @@ class Api {
$this->err_msg(-1011,'The URL already exists!');
}
}
/**
* 批量修改链接分类
*/
public function batch_modify_category($data) {
$this->auth($token);
//获取链接ID,是一个数组
$id = implode(',',$data['id']);
//获取分类ID
$fid = $data['fid'];
//查询分类ID是否存在
$count = $this->db->count('on_categorys',[ 'id' => $fid]);
//如果分类ID不存在
if( empty($fid) || empty($count) ) {
$this->err_msg(-2000,'分类ID不存在!');
}
else{
$sql = "UPDATE on_links SET fid='$fid' WHERE id IN ($id)";
$re = $this->db->query($sql);
if( $re ) {
$id = $this->db->id();
$data = [
'code' => 0,
'msg' => "success"
];
exit(json_encode($data));
}
else{
$this->err_msg(-2000,'更新失败!');
}
}
}
/**
* 批量导入链接
*/
@ -909,6 +941,79 @@ class Api { @@ -909,6 +941,79 @@ class Api {
$this->err_msg(-2000,$e->getMessage());
}
}
/**
* 保存主题参数
*/
public function save_theme_config($data) {
$this->auth($token);
//获取主题名称
$name = $data['name'];
//获取config参数,是一个对象
$config = $data['config'];
//获取主题配置文件config.json
if ( is_dir("templates/".$name) ) {
$config_file = "templates/".$name."/config.json";
}
else{
$config_file = "data/templates/".$name."/config.json";
}
$config_content = json_encode($config,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
//写入配置
try {
$re = @file_put_contents($config_file,$config_content);
$this->return_json(0,"success");
} catch (\Throwable $th) {
$this->err_msg(-2000,"写入配置失败!");
}
}
/**
* 获取主题参数
*/
public function get_theme_config() {
$template = $this->db->get("on_options","value",[
"key" => "theme"
]);
//获取主题配置信息
//获取主题配置
if( file_exists("templates/".$template."/config.json") ) {
$config_file = "templates/".$template."/config.json";
}
else if(data/templates/".$template."/config.json) {
$config_file = "data/templates/".$template."/config.json";
}
else if( file_exists("templates/".$template."/info.json") ) {
$config_file = "templates/".$template."/info.json";
}
else {
$config_file = "data/templates/".$template."/info.json";
}
//读取主题配置
$config_content = @file_get_contents($config_file);
//如果是info.json,则特殊处理下
if ( strstr($config_file,"info.json") ) {
$theme_config = $config_content->config;
}
else{
$theme_config = $config_content;
}
$theme_config = json_decode($theme_config);
$this->return_json(200,$theme_config,"");
}
/**
* 通用json消息返回
*/
public function return_json($code,$data,$msg = "") {
$return = [
"code" => intval($code),
"data" => $data,
"msg" => $msg
];
exit(json_encode($return));
}
/**
* 更新option
*/

31
controller/admin.php

@ -43,6 +43,31 @@ if ( $page == 'edit_category' ) { @@ -43,6 +43,31 @@ if ( $page == 'edit_category' ) {
}
}
//如果是主题设置页面
if ( $page == "setting/theme_config" ){
//获取主题名称
$name = trim($_GET['name']);
//获取主题目录
if ( is_dir("templates/".$name) ) {
$theme_dir = "templates/".$name;
}
else{
$theme_dir = "data/templates/".$name;
}
//读取主题配置
$config_content = @file_get_contents("templates/".$name."/info.json");
if( !$config_content ) {
$config_content = @file_get_contents("data/templates/".$name."/info.json");
}
$configs = json_decode($config_content);
$configs = $configs->config;
//获取当前的配置参数
$current_configs = file_get_contents($theme_dir."/config.json");
$current_configs = json_decode($current_configs);
//var_dump($current_configs);
}
//添加分类页面
if ( $page == 'add_category' ) {
//查询父级分类
@ -80,6 +105,12 @@ if ($page == 'edit_link') { @@ -80,6 +105,12 @@ if ($page == 'edit_link') {
}
}
//链接列表页面
if ( $page == "link_list" ) {
//查询所有分类信息,用于分类框选择
$categorys = $db->select('on_categorys','*',[ 'ORDER' => ['weigth' => 'DESC'] ]);
}
//如果页面是添加链接页面
if ( ($page == 'add_link') || ($page == 'add_link_tpl') || ($page == 'add_quick_tpl') ) {
//查询所有分类信息

36
controller/api.php

@ -145,8 +145,8 @@ function category_list($api){ @@ -145,8 +145,8 @@ function category_list($api){
* 查询链接列表
*/
function link_list($api){
$page = empty(intval($_GET['page'])) ? 1 : intval($_GET['page']);
$limit = empty(intval($_GET['limit'])) ? 10 : intval($_GET['limit']);
$page = empty(intval($_REQUEST['page'])) ? 1 : intval($_REQUEST['page']);
$limit = empty(intval($_REQUEST['limit'])) ? 10 : intval($_REQUEST['limit']);
//获取token
$token = $_POST['token'];
//获取分类ID
@ -322,4 +322,36 @@ function get_latest_version() { @@ -322,4 +322,36 @@ function get_latest_version() {
];
}
exit(json_encode($data));
}
//批量修改链接分类
function batch_modify_category($api) {
//获取id列表
$id = $_POST['id'];
//获取分类ID
$fid = intval($_POST['fid']);
$data = [
'id' => $id,
'fid' => $fid
];
$api->batch_modify_category($data);
}
//保存主题参数设置
function save_theme_config($api) {
//获取所有POST数组,并组合为对象
$post_data = $_POST;
//数组转对象
foreach ($post_data as $key => $value) {
$data['config']->$key = $value;
}
$data['name'] = $post_data['name'];
unset($data['config']->name);
$api->save_theme_config($data);
}
//获取主题配置信息
function get_theme_config($api) {
$api->get_theme_config();
}

101
controller/ico.php

@ -0,0 +1,101 @@ @@ -0,0 +1,101 @@
<?php
/**
* 首字母头像
* @param $text
* @return string
* 原作者:http://t.zoukankan.com/ccw869476711-p-13596791.html
*/
function letter_avatar($text)
{
$total = unpack('L', hash('adler32', $text, true))[1];
$hue = $total % 360;
list($r, $g, $b) = hsv2rgb($hue / 360, 0.3, 0.9);
$bg = "rgb({$r},{$g},{$b})";
$color = "#ffffff";
$first = mb_strtoupper(mb_substr($text, 0, 1));
$src = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="100" width="100"><rect fill="' . $bg . '" x="0" y="0" width="100" height="100"></rect><text x="50" y="50" font-size="50" text-copy="fast" fill="' . $color . '" text-anchor="middle" text-rights="admin" alignment-baseline="central">' . $first . '</text></svg>';
//$value = 'data:image/svg+xml;base64,' . $src;
$value = $src;
return $value;
}
function hsv2rgb($h, $s, $v)
{
$r = $g = $b = 0;
$i = floor($h * 6);
$f = $h * 6 - $i;
$p = $v * (1 - $s);
$q = $v * (1 - $f * $s);
$t = $v * (1 - (1 - $f) * $s);
switch ($i % 6) {
case 0:
$r = $v;
$g = $t;
$b = $p;
break;
case 1:
$r = $q;
$g = $v;
$b = $p;
break;
case 2:
$r = $p;
$g = $v;
$b = $t;
break;
case 3:
$r = $p;
$g = $q;
$b = $v;
break;
case 4:
$r = $t;
$g = $p;
$b = $v;
break;
case 5:
$r = $v;
$g = $p;
$b = $q;
break;
}
return [
floor($r * 255),
floor($g * 255),
floor($b * 255)
];
}
/**
* 输出svg图像
*/
function output_ico() {
//获取文字
$text = @trim($_GET['text']);
$text = empty($text) ? '空' : $text;
//获取当前主机名
$host = $_SERVER['HTTP_HOST'];
//获取reffrer
$referer = $_SERVER['HTTP_REFERER'];
//如果referer和主机名不匹配,则禁止调用
if ( ( !empty($referer) ) && ( !strstr($referer,$host) ) ) {
exit('调用失败');
}
else{
header('Cache-Control: max-age=604800');
header('Content-Type:image/svg+xml');
echo letter_avatar($text);
}
}
//调用ico输出函数
output_ico();

26
controller/index.php

@ -162,6 +162,32 @@ $template = $db->get("on_options","value",[ @@ -162,6 +162,32 @@ $template = $db->get("on_options","value",[
$site = $db->get('on_options','value',[ 'key' => "s_site" ]);
$site = unserialize($site);
//获取主题配置信息
//获取主题配置
if( file_exists("templates/".$template."/config.json") ) {
$config_file = "templates/".$template."/config.json";
}
else if(data/templates/".$template."/config.json) {
$config_file = "data/templates/".$template."/config.json";
}
else if( file_exists("templates/".$template."/info.json") ) {
$config_file = "templates/".$template."/info.json";
}
else {
$config_file = "data/templates/".$template."/info.json";
}
//读取主题配置
$config_content = @file_get_contents($config_file);
//如果是info.json,则特殊处理下
if ( strstr($config_file,"info.json") ) {
$theme_config = $config_content->config;
}
else{
$theme_config = $config_content;
}
$theme_config = json_decode($config_content);
//判断文件夹是否存在
if( is_dir('templates/'.$template) ){
$tpl_dir = 'templates/';

Loading…
Cancel
Save