185 行
5.8 KiB
PHP
185 行
5.8 KiB
PHP
<?php
|
|
|
|
// 公共助手函数
|
|
|
|
use app\common\library\Auth;
|
|
use think\Cache;
|
|
|
|
/**
|
|
* 获取中英文数据
|
|
*/
|
|
if (!function_exists('ze')) {
|
|
function ze($date, $name)
|
|
{
|
|
$language = (int) cookie('language') ? (int) cookie('language') : 2;
|
|
if ($language == 1) {
|
|
return $date['e_' . $name];
|
|
} else {
|
|
return $date[$name];
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取配置项数据
|
|
* @param $name 名称
|
|
* @param $stu 获取字段 title 和 value
|
|
* @param string $m 如果stu为value返回的数据序号
|
|
*/
|
|
if (!function_exists('__config')) {
|
|
function __config($name, $stu = 'title', $m = 0)
|
|
{
|
|
$language_stu = (int) cookie('language') ? (int) cookie('language') : 2;//1=English,2=Chinese
|
|
$name .= ($language_stu == 1) ? '_en' : '';
|
|
|
|
//生成配置文件
|
|
$official_data_url = ADDON_PATH . 'official' . DS . 'config' . DS . 'official_data.php';
|
|
if (!file_exists($official_data_url)) {
|
|
throw new \think\Exception("您的'$official_data_url'文件缺失。");
|
|
} else {
|
|
$config_all = include $official_data_url;
|
|
}
|
|
$config = $config_all[$name] ?? '';
|
|
if (empty($config)) return '';
|
|
if ($stu == 'title') return $config['title'];
|
|
if ($stu == 'value') {
|
|
//判断图片
|
|
$zhui = substr(strrchr($config['value'],'.'),1);
|
|
//bmp,jpg,png,tif,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw,WMF,webp,avif,apng
|
|
if (in_array($zhui,['jpg','png','gif','svg','bmp'])){
|
|
return cdnurl($config['value'],true);
|
|
}
|
|
$array = explode('|', $config['value']);
|
|
return $array[$m] ?? '';
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取中英文数据
|
|
* @param $model_name 模型名称
|
|
* @param $name 字段名称
|
|
* @param string $stu 语言字段
|
|
* @param string $m 模块
|
|
* @return mixed|string
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
if (!function_exists('__l')) {
|
|
function __l($model_name, $name, $m = 'official')
|
|
{
|
|
$auth = Auth::instance();
|
|
$language_stu = (int) cookie('language') ? (int) cookie('language') : 2;//1=English,2=Chinese
|
|
$language = ($language_stu == 1) ? 'en' : 'zh-cn';
|
|
$url = ROOT_PATH . "addons/$m/lang/$language/official_$model_name.php";
|
|
if (file_exists($url)) {
|
|
$data = include $url;
|
|
if (isset($data[$name]) && !empty($data[$name])) {
|
|
return $data[$name];
|
|
}
|
|
}
|
|
|
|
$common = ROOT_PATH . "addons/$m/lang/$language.php";
|
|
if (file_exists($common)) {
|
|
$common_f = include $common;
|
|
if (isset($common_f[$name]) && !empty($common_f[$name])) {
|
|
return $common_f[$name];
|
|
}
|
|
}
|
|
return $name;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取自己地址栏的数据
|
|
*/
|
|
if (!function_exists('get_pid_sid')) {
|
|
function get_pid_sid($data = [])
|
|
{
|
|
$array = $_GET;
|
|
if (count($data)) {
|
|
foreach ($data as $key => $item) {
|
|
$array[$key] = $item;
|
|
}
|
|
}
|
|
$ur = '';
|
|
if (count($array)) {
|
|
foreach ($array as $key => $item) {
|
|
if ($item) {
|
|
if ($ur) {
|
|
$ur .= "&$key=" . $item;
|
|
} else {
|
|
$ur .= "?$key=" . $item;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $ur;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 栏目跳转
|
|
*/
|
|
if (!function_exists('get_cate_url')) {
|
|
function get_cate_url($category)
|
|
{
|
|
//判断是不是外链
|
|
if ($category['status'] == 3) {
|
|
return $category['url'];
|
|
}
|
|
|
|
//判断是不是一级栏目
|
|
$pid = $category['id'];
|
|
$sid = $category['id'];
|
|
$get_data = [':pid'=>$pid,':sid'=>$sid];
|
|
|
|
if ($category['pid'] != 0) {
|
|
//如果是有父级的
|
|
$official_tree_category_url = ADDON_PATH . 'official' . DS . 'config' . DS . 'official_tree_category.php';
|
|
if (file_exists($official_tree_category_url)) {
|
|
$tree_category_all = include $official_tree_category_url;
|
|
foreach ($tree_category_all as $item) {
|
|
if ($item['id'] == $category['pid']) {
|
|
$father_category = $item;
|
|
}
|
|
}
|
|
}
|
|
if (isset($father_category) && !empty($father_category)) {
|
|
$pid = $father_category['id'];
|
|
$get_data = [':pid'=>$pid,':sid'=>$sid];
|
|
}
|
|
}
|
|
//判断是不是单页
|
|
if ($category['status'] == 1) {
|
|
return addon_url('official/web.official_home/single',$get_data,true,true);
|
|
}
|
|
//判断是不是列表
|
|
if ($category['status'] == 2) {
|
|
//生成配置文件
|
|
$official_rule_url = ADDON_PATH . 'official' . DS . 'config' . DS . 'official_rule.php';
|
|
if (!file_exists($official_rule_url)) {
|
|
$official_rule = [];
|
|
$rule_all = db('official_rule')->select();
|
|
foreach ($rule_all as $item) {
|
|
$official_rule[$item['id']] = $item;
|
|
}
|
|
file_put_contents(
|
|
$official_rule_url,
|
|
'<?php' . "\n\nreturn " . var_export_short($official_rule) . ";\n"
|
|
);
|
|
} else {
|
|
$official_rule = include $official_rule_url;
|
|
};
|
|
$official_rule = $official_rule[$category['official_rule_id']] ?? [];
|
|
return addon_url('/official/web.official_' . str_replace('official_list_', '', $official_rule['table_name'] ?? '') . '/list',$get_data,true,true);
|
|
}
|
|
}
|
|
}
|
|
|
|
|