2023-12-17 23:43:43 +08:00
|
|
|
<?php
|
2024-05-06 00:37:40 +08:00
|
|
|
/*
|
|
|
|
* @Description: 公共函数
|
|
|
|
* @Copyright (c) 2024 by LyLme, All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-12-17 23:43:43 +08:00
|
|
|
|
2022-07-20 13:13:26 +08:00
|
|
|
//判断蜘蛛
|
2023-12-17 23:43:43 +08:00
|
|
|
function is_spider()
|
|
|
|
{
|
|
|
|
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
|
|
|
|
$spiders = array(
|
2024-05-06 00:37:40 +08:00
|
|
|
'Googlebot',
|
|
|
|
'Baiduspider',
|
|
|
|
'Yahoo! Slurp',
|
|
|
|
'YodaoBot',
|
|
|
|
'msnbot',
|
|
|
|
'360Spider',
|
|
|
|
'spider',
|
|
|
|
'Spider'
|
|
|
|
//这里可以加入更多的蜘蛛标示
|
2023-12-17 23:43:43 +08:00
|
|
|
);
|
|
|
|
foreach ($spiders as $spider) {
|
|
|
|
$spider = strtolower($spider);
|
|
|
|
if (strpos($userAgent, $spider) !== false) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2022-07-20 13:13:26 +08:00
|
|
|
}
|
2023-12-17 23:43:43 +08:00
|
|
|
function daddslashes($string)
|
|
|
|
{
|
2024-05-06 00:37:40 +08:00
|
|
|
if (is_array($string)) {
|
|
|
|
foreach ($string as $key => $val) {
|
2023-12-17 23:43:43 +08:00
|
|
|
$string[$key] = daddslashes($val);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$string = addslashes($string);
|
|
|
|
}
|
|
|
|
return $string;
|
2022-02-19 23:39:52 +08:00
|
|
|
}
|
2023-12-17 23:43:43 +08:00
|
|
|
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0)
|
|
|
|
{
|
|
|
|
$ckey_length = 4;
|
|
|
|
$key = md5($key ? $key : ENCRYPT_KEY);
|
|
|
|
$keya = md5(substr($key, 0, 16));
|
|
|
|
$keyb = md5(substr($key, 16, 16));
|
|
|
|
$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
|
|
|
|
$cryptkey = $keya . md5($keya . $keyc);
|
|
|
|
$key_length = strlen($cryptkey);
|
|
|
|
$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
|
|
|
|
$string_length = strlen($string);
|
|
|
|
$result = '';
|
|
|
|
$box = range(0, 255);
|
|
|
|
$rndkey = array();
|
|
|
|
for ($i = 0; $i <= 255; $i++) {
|
|
|
|
$rndkey[$i] = ord($cryptkey[$i % $key_length]);
|
|
|
|
}
|
|
|
|
for ($j = $i = 0; $i < 256; $i++) {
|
|
|
|
$j = ($j + $box[$i] + $rndkey[$i]) % 256;
|
|
|
|
$tmp = $box[$i];
|
|
|
|
$box[$i] = $box[$j];
|
|
|
|
$box[$j] = $tmp;
|
|
|
|
}
|
|
|
|
for ($a = $j = $i = 0; $i < $string_length; $i++) {
|
|
|
|
$a = ($a + 1) % 256;
|
|
|
|
$j = ($j + $box[$a]) % 256;
|
|
|
|
$tmp = $box[$a];
|
|
|
|
$box[$a] = $box[$j];
|
|
|
|
$box[$j] = $tmp;
|
|
|
|
$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
|
|
|
|
}
|
|
|
|
if ($operation == 'DECODE') {
|
|
|
|
if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
|
|
|
|
return substr($result, 26);
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return $keyc . str_replace('=', '', base64_encode($result));
|
|
|
|
}
|
2022-02-19 23:39:52 +08:00
|
|
|
}
|
2024-05-06 00:37:40 +08:00
|
|
|
|
|
|
|
|
2022-03-26 15:38:52 +08:00
|
|
|
$background = $conf["background"];
|
2022-04-03 21:28:25 +08:00
|
|
|
//网站背景
|
2023-12-17 23:43:43 +08:00
|
|
|
function background()
|
|
|
|
{
|
|
|
|
return $GLOBALS['background_img'];
|
2022-03-19 21:57:34 +08:00
|
|
|
}
|
2024-05-06 00:37:40 +08:00
|
|
|
|
|
|
|
|
2023-12-17 23:43:43 +08:00
|
|
|
function getver($ver)
|
|
|
|
{
|
|
|
|
$vn = explode('.', str_replace('v', '', $ver));
|
|
|
|
return $vn[0] . sprintf("%02d", $vn[1]) . sprintf("%02d", $vn[2]);
|
2022-03-05 13:55:15 +08:00
|
|
|
}
|
2022-04-03 21:28:25 +08:00
|
|
|
//更新设置
|
2024-05-06 00:37:40 +08:00
|
|
|
function saveSetting($k, $v, $desc = '')
|
2023-12-17 23:43:43 +08:00
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
$v = daddslashes($v);
|
2024-05-06 00:37:40 +08:00
|
|
|
$query = "INSERT INTO `lylme_config` (`k`, `v`,`description`) VALUES ('$k', '$v','$desc') ON DUPLICATE KEY UPDATE `v` = '$v';";
|
|
|
|
return $DB->query($query);
|
2022-02-19 23:39:52 +08:00
|
|
|
}
|
2024-05-06 00:37:40 +08:00
|
|
|
|
2022-04-03 21:28:25 +08:00
|
|
|
//获取相对路径
|
2023-12-17 23:43:43 +08:00
|
|
|
function get_urlpath($srcurl, $baseurl)
|
|
|
|
{
|
2024-05-06 00:37:40 +08:00
|
|
|
if (substr($srcurl, 0, 2) == "//") {
|
2023-12-17 23:43:43 +08:00
|
|
|
return parse_url($baseurl)['scheme'] . ':' . $srcurl;
|
|
|
|
}
|
2024-05-06 00:37:40 +08:00
|
|
|
if (empty($srcurl)) {
|
2023-12-17 23:43:43 +08:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
$srcinfo = parse_url($srcurl);
|
2024-05-06 00:37:40 +08:00
|
|
|
if (isset($srcinfo['scheme'])) {
|
2023-12-17 23:43:43 +08:00
|
|
|
return $srcurl;
|
|
|
|
}
|
|
|
|
$baseinfo = parse_url($baseurl);
|
|
|
|
$url = $baseinfo['scheme'] . '://' . $baseinfo['host'];
|
2024-05-06 00:37:40 +08:00
|
|
|
if (substr($srcinfo['path'], 0, 1) == '/') {
|
2023-12-17 23:43:43 +08:00
|
|
|
$path = $srcinfo['path'];
|
|
|
|
} else {
|
|
|
|
$path = dirname($baseinfo['path']) . '/' . $srcinfo['path'];
|
|
|
|
}
|
|
|
|
$rst = array();
|
|
|
|
$path_array = explode('/', $path);
|
2024-05-06 00:37:40 +08:00
|
|
|
if (!$path_array[0]) {
|
2023-12-17 23:43:43 +08:00
|
|
|
$rst[] = '';
|
2022-12-01 04:06:41 +08:00
|
|
|
}
|
2023-12-17 23:43:43 +08:00
|
|
|
foreach ($path_array as $key => $dir) {
|
|
|
|
if ($dir == '..') {
|
|
|
|
if (end($rst) == '..') {
|
|
|
|
$rst[] = '..';
|
2024-05-06 00:37:40 +08:00
|
|
|
} elseif (!array_pop($rst)) {
|
2023-12-17 23:43:43 +08:00
|
|
|
$rst[] = '..';
|
|
|
|
}
|
2024-05-06 00:37:40 +08:00
|
|
|
} elseif ($dir && $dir != '.') {
|
2023-12-17 23:43:43 +08:00
|
|
|
$rst[] = $dir;
|
|
|
|
}
|
|
|
|
}
|
2024-05-06 00:37:40 +08:00
|
|
|
if (!end($path_array)) {
|
2023-12-17 23:43:43 +08:00
|
|
|
$rst[] = '';
|
|
|
|
}
|
|
|
|
$url .= implode('/', $rst);
|
2024-05-06 00:37:40 +08:00
|
|
|
if (!empty($srcinfo['query'])) {
|
2023-12-17 23:43:43 +08:00
|
|
|
$url .= '?' . $srcinfo['query'];
|
|
|
|
}
|
|
|
|
return str_replace('\\', '/', $url);
|
2022-04-03 21:28:25 +08:00
|
|
|
}
|
|
|
|
//获取客户端IP
|
2023-12-17 23:43:43 +08:00
|
|
|
function get_real_ip()
|
|
|
|
{
|
2023-01-21 18:31:00 +08:00
|
|
|
$real_ip = '';
|
|
|
|
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
|
|
|
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
|
|
|
|
$pos = array_search('unknown', $arr);
|
|
|
|
if (false !== $pos) {
|
|
|
|
unset($arr[$pos]);
|
|
|
|
}
|
|
|
|
$real_ip = trim($arr[0]);
|
|
|
|
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
|
|
|
|
$real_ip = $_SERVER['HTTP_CLIENT_IP'];
|
|
|
|
} elseif (isset($_SERVER['REMOTE_ADDR'])) {
|
|
|
|
$real_ip = $_SERVER['REMOTE_ADDR'];
|
|
|
|
}
|
2023-10-10 09:11:30 +08:00
|
|
|
if (filter_var($real_ip, FILTER_VALIDATE_IP)) {
|
|
|
|
return $real_ip;
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2023-12-17 23:43:43 +08:00
|
|
|
// return $real_ip;
|
2022-04-03 21:28:25 +08:00
|
|
|
}
|
2023-12-17 23:43:43 +08:00
|
|
|
function yan()
|
|
|
|
{
|
|
|
|
$filename = ROOT . '/assets/data/data.dat';
|
2023-12-20 00:48:12 +08:00
|
|
|
if (!file_exists($filename) || !is_readable($filename)) {
|
|
|
|
die(' 一言数据文件不存在或不可读');
|
|
|
|
}
|
2023-12-19 00:33:19 +08:00
|
|
|
$data = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
|
|
// 随机获取一行索引
|
|
|
|
$result = $data[array_rand($data)];
|
|
|
|
// 去除多余的换行符
|
|
|
|
$result = str_replace(["\r", "\n", "\r\n"], '', $result);
|
|
|
|
return $result;
|
2022-06-12 02:24:05 +08:00
|
|
|
}
|
2023-12-17 23:43:43 +08:00
|
|
|
function rearr($data, $arr)
|
|
|
|
{
|
2024-05-06 00:37:40 +08:00
|
|
|
$arr = str_replace('{group_id}', isset($data['group_id']) ? $data['group_id'] : '', $arr);
|
|
|
|
$arr = str_replace('{group_name}', isset($data['group_name']) ? $data['group_name'] : '', $arr);
|
|
|
|
$arr = str_replace('{group_icon}', isset($data['group_icon']) ? $data['group_icon'] : '', $arr);
|
|
|
|
$arr = str_replace('{link_id}', isset($data['id']) ? $data['id'] : '', $arr);
|
|
|
|
$arr = str_replace('{link_name}', isset($data['name']) ? $data['name'] : '', $arr);
|
|
|
|
$url = isset($data['url']) ? ($GLOBALS['conf']["mode"] == 2 ? "/site-" . $data["id"] . ".html" : $data["url"]) : '';
|
|
|
|
$arr = str_replace('{link_url}', $url, $arr);
|
2023-12-17 23:43:43 +08:00
|
|
|
$arr = str_replace('{group_id}', $data['group_id'], $arr);
|
2024-05-06 00:37:40 +08:00
|
|
|
$alt = isset($data['name']) ? $data['name'] : $data['group_name'];
|
2023-12-17 23:43:43 +08:00
|
|
|
if (empty($data["icon"])) {
|
2024-05-06 00:37:40 +08:00
|
|
|
$icon = '<img src="/assets/img/default-icon.png" alt="' . strip_tags($alt) . '" />';
|
2023-12-17 23:43:43 +08:00
|
|
|
} elseif (!preg_match("/^<svg*/", $data["icon"])) {
|
2024-05-06 00:37:40 +08:00
|
|
|
$icon = '<img src="' . $data["icon"] . '" alt="' . strip_tags($alt) . '" />';
|
2023-12-17 23:43:43 +08:00
|
|
|
} else {
|
|
|
|
$icon = $data["icon"];
|
|
|
|
}
|
|
|
|
$arr = str_replace('{link_icon}', $icon, $arr);
|
|
|
|
return $arr;
|
2022-06-12 02:24:05 +08:00
|
|
|
}
|
2022-06-18 20:58:20 +08:00
|
|
|
//获取head
|
2024-05-06 00:37:40 +08:00
|
|
|
function get_head($url, $cache = false)
|
2023-12-17 23:43:43 +08:00
|
|
|
{
|
2024-05-06 00:37:40 +08:00
|
|
|
|
|
|
|
if ($cache && is_numeric($url)) {
|
|
|
|
global $DB;
|
|
|
|
$site_head = $DB->get_row("SELECT * FROM `lylme_links` WHERE `id` = $url AND `link_pwd` = 0 ");
|
|
|
|
$url = $site_head['url'];
|
|
|
|
$cache_path = ROOT . "cache/";
|
|
|
|
$cache_file = $cache_path . md5($url) . ".txt";
|
|
|
|
if (file_exists($cache_file)) {
|
|
|
|
// 获取缓存文件的修改时间
|
|
|
|
$file_mtime = filemtime($cache_file);
|
|
|
|
// 如果缓存文件未过期,则直接读取并返回数据
|
|
|
|
if ((time() - $file_mtime) < 7 * 24 * 60 * 60) {
|
|
|
|
return json_decode(file_get_contents($cache_file), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-17 23:43:43 +08:00
|
|
|
$data = get_curl($url);
|
|
|
|
//获取网站title
|
|
|
|
preg_match('/<title.*?>(?<title>.*?)<\/title>/sim', $data, $title);
|
2024-05-06 00:37:40 +08:00
|
|
|
$encode = mb_detect_encoding($title['title'], array('GB2312', 'GBK', 'UTF-8', 'CP936'));
|
2023-12-17 23:43:43 +08:00
|
|
|
//得到字符串编码
|
|
|
|
$file_charset = iconv_get_encoding()['internal_encoding'];
|
|
|
|
//当前文件编码
|
|
|
|
if ($encode != 'CP936' && $encode != $file_charset) {
|
|
|
|
$title = iconv($encode, $file_charset, $title['title']);
|
|
|
|
$data = iconv($encode, $file_charset, $data);
|
|
|
|
} else {
|
|
|
|
$title = $title['title'];
|
|
|
|
}
|
|
|
|
// 获取网站icon
|
|
|
|
preg_match('/<link rel=".*?icon" * href="(.*?)".*?>/is', $data, $icon);
|
|
|
|
preg_match('/<meta +name *=["\']?description["\']? *content=["\']?([^<>"]+)["\']?/i', $data, $description);
|
|
|
|
preg_match('/<meta +name *=["\']?keywords["\']? *content=["\']?([^<>"]+)["\']?/i', $data, $keywords);
|
2022-12-01 04:06:41 +08:00
|
|
|
$icon = $icon[1];
|
2024-05-06 00:37:40 +08:00
|
|
|
if (!empty($icon)) {
|
2023-12-17 23:43:43 +08:00
|
|
|
$icon = get_urlpath($icon, $url);
|
|
|
|
} else {
|
2022-12-01 04:06:41 +08:00
|
|
|
$parse = parse_url($url);
|
2023-12-17 23:43:43 +08:00
|
|
|
$port = $parse['port'] == 80 || $parse['port'] == "" ? '' : ":" . $parse['port'];
|
|
|
|
$iconurl = $parse['scheme'] . '://' . $parse['host'] . $port . '/favicon.ico';
|
2024-05-06 00:37:40 +08:00
|
|
|
if (get_curl($iconurl) != 404) {
|
2023-12-17 23:43:43 +08:00
|
|
|
$icon = $iconurl;
|
|
|
|
}
|
2022-12-01 04:06:41 +08:00
|
|
|
}
|
2024-05-06 00:37:40 +08:00
|
|
|
$get_heads = array("title" => $title, "charset" => $encode, "icon" => $icon, "description" => $description[1], "keywords" => $keywords[1], "url" => $url);
|
|
|
|
if ($cache && is_numeric($url)) {
|
|
|
|
if (!file_exists($cache_path)) {
|
|
|
|
mkdir($cache_path);
|
|
|
|
}
|
|
|
|
file_put_contents($cache_file, json_encode($get_heads));
|
|
|
|
}
|
2023-12-17 23:43:43 +08:00
|
|
|
return $get_heads;
|
2022-12-01 04:06:41 +08:00
|
|
|
}
|
|
|
|
//模拟GET请求
|
2023-12-17 23:43:43 +08:00
|
|
|
function get_curl($url)
|
|
|
|
{
|
|
|
|
$curl = curl_init();
|
|
|
|
curl_setopt_array($curl, array(
|
|
|
|
CURLOPT_URL => $url,
|
|
|
|
CURLOPT_RETURNTRANSFER => true,
|
2024-05-06 00:37:40 +08:00
|
|
|
CURLOPT_FOLLOWLOCATION => true,
|
2023-12-17 23:43:43 +08:00
|
|
|
CURLOPT_ENCODING => '',
|
|
|
|
CURLOPT_MAXREDIRS => 10,
|
|
|
|
CURLOPT_TIMEOUT => 0,
|
2024-05-06 00:37:40 +08:00
|
|
|
CURLOPT_SSL_VERIFYPEER => false,
|
|
|
|
CURLOPT_SSL_VERIFYHOST => false,
|
2023-12-17 23:43:43 +08:00
|
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
|
|
CURLOPT_CUSTOMREQUEST => 'GET',
|
|
|
|
CURLOPT_HTTPHEADER => array(
|
|
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36 Edg/101.0.1210.39 Lylme/11.24'
|
2024-05-06 00:37:40 +08:00
|
|
|
),
|
|
|
|
));
|
2023-12-17 23:43:43 +08:00
|
|
|
$contents = curl_exec($curl);
|
|
|
|
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
|
|
curl_close($curl);
|
2024-05-06 00:37:40 +08:00
|
|
|
if ($httpCode == 404) {
|
2023-12-17 23:43:43 +08:00
|
|
|
return $httpCode;
|
|
|
|
}
|
|
|
|
return $contents;
|
2022-12-01 04:06:41 +08:00
|
|
|
}
|
2023-12-17 23:43:43 +08:00
|
|
|
//长度判断
|
|
|
|
function strlens($str)
|
|
|
|
{
|
2024-05-06 00:37:40 +08:00
|
|
|
if (strlen($str) > 255) {
|
2023-12-17 23:43:43 +08:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2022-06-18 20:58:20 +08:00
|
|
|
}
|
2024-05-06 00:37:40 +08:00
|
|
|
//收录
|
2023-12-17 23:43:43 +08:00
|
|
|
function apply($name, $url, $icon, $group_id, $status)
|
|
|
|
{
|
2024-05-06 00:37:40 +08:00
|
|
|
header('Content-Type:application/json; charset=utf-8');
|
2023-12-17 23:43:43 +08:00
|
|
|
$name = strip_tags(daddslashes($name));
|
|
|
|
$url = strip_tags(daddslashes($url));
|
|
|
|
$icon = strip_tags(daddslashes($icon));
|
2024-05-06 00:37:40 +08:00
|
|
|
$group_id = intval(strip_tags(daddslashes($group_id)));
|
2023-12-17 23:43:43 +08:00
|
|
|
$userip = get_real_ip();
|
2024-05-06 00:37:40 +08:00
|
|
|
|
2023-12-17 23:43:43 +08:00
|
|
|
$date = date("Y-m-d H:i:s");
|
2024-05-06 00:37:40 +08:00
|
|
|
if (empty($name) || empty($url) || empty($group_id)) {
|
2023-12-17 23:43:43 +08:00
|
|
|
//|| empty($icon)
|
2024-05-06 00:37:40 +08:00
|
|
|
return ('{"code": "-1", "msg": "必填项不能为空"}');
|
|
|
|
} elseif (!preg_match('/^http*/i', $url)) {
|
|
|
|
return ('{"code": "-2", "msg": "链接不符合要求"}');
|
|
|
|
} elseif (strlens($name) || strlens($url) || strlens($icon) || strlens($group_id) || strlens($userip)) {
|
|
|
|
return ('{"code": "500", "msg": "非法参数"}');
|
2023-12-17 23:43:43 +08:00
|
|
|
} else {
|
|
|
|
global $DB;
|
2024-05-06 00:37:40 +08:00
|
|
|
if ($DB->num_rows($DB->query("SELECT * FROM `lylme_apply` WHERE `apply_url` LIKE '" . $url . "';")) > 0) {
|
|
|
|
return ('{"code": "-3", "msg": "链接已存在,请勿重复提交"}');
|
2023-12-17 23:43:43 +08:00
|
|
|
}
|
2024-05-06 00:37:40 +08:00
|
|
|
$sql = "INSERT INTO `lylme_apply` (`apply_name`, `apply_url`, `apply_group`, `apply_icon`, `apply_desc`, `apply_time`, `apply_status`) VALUES ( '$name', '$url', $group_id, '$icon', '$userip', '$date', $status);";
|
|
|
|
if ($DB->query($sql)) {
|
2023-12-17 23:43:43 +08:00
|
|
|
switch ($status) {
|
|
|
|
case 0:
|
2024-05-06 00:37:40 +08:00
|
|
|
return ('{"code": "200", "msg": "请等待管理员审核"}');
|
2023-12-17 23:43:43 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2024-05-06 00:37:40 +08:00
|
|
|
if (ins_link($name, $url, $icon, $group_id)) {
|
|
|
|
return ('{"code": "200", "msg": "网站已收录"}');
|
2023-12-17 23:43:43 +08:00
|
|
|
} else {
|
2024-05-06 00:37:40 +08:00
|
|
|
return ('{"code": "-5", "msg": "请联系网站管理员"}');
|
2023-12-17 23:43:43 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2024-05-06 00:37:40 +08:00
|
|
|
return ('{"code": "-4", "msg": "未知错误,请联系网站管理员"}');
|
2023-12-17 23:43:43 +08:00
|
|
|
}
|
|
|
|
}
|
2022-06-18 20:58:20 +08:00
|
|
|
}
|
2024-05-06 00:37:40 +08:00
|
|
|
function ins_link($name, $url, $icon, $group_id)
|
2023-12-17 23:43:43 +08:00
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
$name = strip_tags(daddslashes($name));
|
|
|
|
$url = strip_tags(daddslashes($url));
|
|
|
|
$icon = strip_tags(daddslashes($icon));
|
2024-05-06 00:37:40 +08:00
|
|
|
$group_id = intval(strip_tags(daddslashes($group_id)));
|
|
|
|
$link_order = intval($DB->count('select MAX(id) from `lylme_links`') + 1);
|
|
|
|
$sql1 = "INSERT INTO `lylme_links` ( `name`, `group_id`, `url`, `icon`, `link_desc`,`link_order`) VALUES (' $name', $group_id, '$url', '$icon', '', $link_order);";
|
|
|
|
if ($DB->query($sql1)) {
|
2023-12-17 23:43:43 +08:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2022-06-18 20:58:20 +08:00
|
|
|
}
|
2024-05-06 00:37:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取主题自定义设置
|
|
|
|
* @Author: LyLme
|
|
|
|
* @param string $name 参数名称
|
|
|
|
* @param mixed $default 默认值
|
|
|
|
* @return mixed 主题参数值
|
|
|
|
*/
|
|
|
|
function theme_config($name, $default = '')
|
2023-12-17 23:43:43 +08:00
|
|
|
{
|
2024-05-06 00:37:40 +08:00
|
|
|
$config = $GLOBALS['conf'];
|
|
|
|
$theme_name = "theme_config_" . $config['template']; //当前主题配置key;
|
|
|
|
|
|
|
|
if (isset($config[$theme_name])) {
|
|
|
|
$theme_themes = json_decode($config[$theme_name], true); //当前主题所有配置
|
|
|
|
//从后台配置中获取
|
|
|
|
return $theme_themes[$name];
|
2023-12-17 23:43:43 +08:00
|
|
|
}
|
2024-05-06 00:37:40 +08:00
|
|
|
|
|
|
|
$theme_config_path = ROOT . 'template/' . $config['template'] . '/config.php';
|
|
|
|
if (file_exists($theme_config_path) && (@require $theme_config_path) !== false && is_array($theme_config)) {
|
|
|
|
//从主题默认配置中获取
|
|
|
|
foreach ($theme_config as $config_item) {
|
|
|
|
// 检查当前配置项是否为 $name
|
|
|
|
if ($config_item['name'] == $name) {
|
|
|
|
$value = array_key_exists("value", $config_item) ? $config_item['value'] : $default;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
//返回默认值
|
|
|
|
return $default;
|
2023-01-21 18:31:00 +08:00
|
|
|
}
|