作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

正在显示 46 个修改的文件 包含 4402 行增加70 行删除

要显示太多修改。

为保证性能只显示 46 of 46+ 个文件。

... ... @@ -9,20 +9,13 @@ namespace App\Console\Commands\KeywordInVideo;
use App\Console\Commands\Model;
use App\Console\Commands\TaskSub;
use App\Enums\Common\Code;
use App\Models\Com\KeywordVideoTask;
use App\Models\Com\KeywordVideoTaskLog;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BSettingTemplate;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\Setting;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
... ... @@ -156,8 +149,11 @@ class VideoTask extends Command
'is_ytb'=>true
];
$result = Http::post('http://216.250.255.116:7866/create_task', $data);
$res_json = json_decode($result,true);
$val->task_id = $task_id;
$val->status = KeywordVideoTaskLog::STATUS_RUNNING;
if(isset($res_json['code']) && ($res_json['code'] == 200)){
$val->status = KeywordVideoTaskLog::STATUS_RUNNING;
}
$val->result_info = $result;
$val->save();
}
... ...
... ... @@ -196,7 +196,56 @@ if (!function_exists('checkDomain')) {
}
}
if (!function_exists('page_init')) {
/**
* amp分页初始化
* @param $page
* @param $total
* @author Akun
* @date 2024/01/29 15:43
*/
function page_init($page, $total)
{
//中间页处理
$center_page = [];
if ($total <= 5) {
for ($i = 1; $i <= $total; $i++) {
$center_page[] = $i;
}
} else {
if ($page < 5) {
for ($i = 1; $i <= 5; $i++) {
$center_page[] = $i;
}
} else {
if ($page == $total) {
for ($i = $total - 5; $i <= $total; $i++) {
$center_page[] = $i;
}
} else if ($page <= $total) {
if ($total - $page <= 5) {
if ($total - $page == 1) {
for ($i = $total - 4; $i <= $total; $i++) {
$center_page[] = $i;
}
} else {
for ($i = $page - 2; $i <= $page + 2; $i++) {
$center_page[] = $i;
}
}
} else {
for ($i = $page - 2; $i <= $page + 2; $i++) {
$center_page[] = $i;
}
}
}
}
}
return $center_page;
}
}
/**
* 把返回的数据集转换成Tree
* @param $list array 数据列表
... ... @@ -240,6 +289,37 @@ function list_to_tree($list, $pk = 'id', $pid = 'pid', $child = '_child', $root
return $tree;
}
if (!function_exists('special2str')) {
/**
* 特殊字符串替换
* @param $str
* @return string|string[]
* @author Akun
* @date 2024/01/30 17:46
*/
function special2str($str)
{
if (strpos($str, ';') === false) {
return $str;
}
$list = [
'&lt;' => '<',
'&gt;' => '>',
'&amp;' => '&',
'&acute;' => '´',
'&quot;' => '“',
'&nbsp;' => ' '
];
foreach ($list as $k => $v) {
$str = str_replace($k, $v, $str);
}
return $str;
}
}
/**
* tree数据转list
* @param $tree
... ...
... ... @@ -2,10 +2,14 @@
namespace App\Http\Controllers\Api;
use App\Enums\Common\Code;
use App\Exceptions\InquiryFilterException;
use App\Models\SyncSubmitTask\SyncSubmitTask;
use App\Models\Visit\Visit;
use App\Services\CosService;
use App\Services\ProjectServer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
* Class InquiryController
... ... @@ -51,4 +55,39 @@ class InquiryController extends BaseController
}
return $this->success();
}
/**
* @remark :修改
* @name :editInquiryStatus
* @author :lyh
* @method :post
* @time :2024/3/22 15:41
*/
public function editInquiryStatus(){
$this->request->validate([
'project_id'=>'required',
'ip'=>'required',
'updated_date'=>'required',
],[
'project_id.required' => 'project_id不能为空',
'ip.required' => 'ip不能为空',
'updated_date.required' => '日期不能为空',
]);
ProjectServer::useProject($this->param['project_id']);
$customerVisitModel = new Visit();
$info = $customerVisitModel->read([
'ip'=>$this->param['ip'],
'updated_date'=>$this->param['updated_date']
]);
if($info === false){
$this->response('当前记录不存在',Code::SYSTEM_ERROR);
}
try {
$customerVisitModel->edit(['is_inquiry'=>1],['id'=>$info['id']]);
}catch (\Exception $e){
$this->response('操作失败',Code::SYSTEM_ERROR);
}
DB::disconnect('custom_mysql');
$this->response('success');
}
}
... ...
... ... @@ -3,7 +3,12 @@
namespace App\Http\Controllers\Api;
use App\Enums\Common\Code;
use App\Helper\Translate;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Services\CosService;
use App\Services\ProjectServer;
use App\Utils\LogUtils;
use Illuminate\Http\Request;
... ... @@ -25,7 +30,6 @@ class ProductController extends BaseController
public function getImages(Request $request)
{
$project_id = $request->input('project_id');
$project = ProjectServer::useProject($project_id);
if (!$project) {
$this->response('项目不存在', Code::SYSTEM_ERROR);
... ... @@ -43,4 +47,208 @@ class ProductController extends BaseController
}
$this->response('success', Code::SUCCESS, $info);
}
/**
* @remark :保存产品
* @name :saveProduct
* @author :lyh
* @method :post
* @time :2024/3/20 11:09
*/
public function saveProduct(){
$api_key = '8242LYUGaOfUQ1koc4Rq6MhEEOG7NW68oRaB7iO9coJDjG5L5gA1Q';
if($this->request->header('api-key') != $api_key){
$this->response('非法请求',Code::SYSTEM_ERROR);
}
$this->request->validate([
'project_id'=>'required',
'title'=>'required',
],[
'project_id.required' => 'project_id不能为空',
'title.required' => 'title不能为空',
]);
$project = ProjectServer::useProject($this->param['project_id']);
if (!$project) {
$this->response('项目不存在', Code::SYSTEM_ERROR);
}
//处理图片
$imageInfo = $this->handleImage($this->param['image'],$this->param['project_id']);
$thumb = $imageInfo['thumb'];
$gallery = $imageInfo['gallery'];
//处理分类
$category_id = $this->handleCategory($this->param['category_name'],$this->param['project_id']);
try {
$productModel = new Product();
$productInfo = $productModel->read(['title'=>$this->param['title']]);
if($productInfo === false){
$productData = [
'project_id'=>$this->param['project_id'],
'title'=>$this->param['title'],
'intro'=>$this->param['intro'] ?? '',
'content'=>$this->param['content'] ?? '',
'thumb'=>json_encode($thumb,true),
'gallery'=>json_encode($gallery,true),
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
if(!empty($category_id)){
$productData['category_id'] = ','.$category_id.',';
}
$product_id = $productModel->addReturnId($productData);
$route = RouteMap::setRoute($productData['title'], RouteMap::SOURCE_PRODUCT, $product_id, $this->param['project_id']);
$productModel->edit(['route'=>$route],['id'=>$product_id]);
//添加到关联分类
CategoryRelated::saveRelated($product_id, [$category_id]);
}
} catch (\Exception $e) {
LogUtils::error('Project Id: ' . $this->param['project_id'] . ' saveProduct error:' . $e->getMessage());
$this->response('保存失败,请联系管理员',Code::SYSTEM_ERROR);
}
$this->response('success');
}
/**
* @remark :处理图片
* @name :handleImage
* @author :lyh
* @method :post
* @time :2024/3/20 14:44
*/
public function handleImage($image,$project_id){
$gallery = [];
$thumb = [];
if(!empty($image) && is_array($image)){
foreach ($image as $k => $v){
//TODO::图片转存
$url = CosService::uploadRemote($project_id,'image_product',$v);
if($k == 0){
$thumb = ['url'=>$url,'alt'=>''];
}
$gallery[] = ['url'=>$url,'alt'=>''];
}
}
return ['thumb'=>$thumb,'gallery'=>$gallery];
}
/**
* @remark :处理分类
* @name :handleCategory
* @author :lyh
* @method :post
* @time :2024/3/20 14:48
*/
public function handleCategory($category_name,$project_id){
$category_id = '';
if(isset($category_name) && !empty($category_name)){
$categoryModel = new Category();
$cateInfo = $categoryModel->read(['title'=>$this->param['category_name']]);
if($cateInfo === false){
$cateData =[
'project_id'=>$project_id,
'title'=>$category_name,
'pid'=>0,
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
$cate_id = $categoryModel->addReturnId($cateData);
$route = RouteMap::setRoute($cateData['title'], RouteMap::SOURCE_PRODUCT_CATE, $cate_id, $project_id);
$categoryModel->edit(['route'=>$route],['id'=>$cate_id]);
}else{
$cate_id = $cateInfo['id'];
}
$category_id = $cate_id;
}
return $category_id;
}
/**
* @param Request $request
* @author zbj
* @date 2024/1/22
*/
protected function searchProduct(Request $request)
{
$project_id = $request->input('project_id');
$limit = $request->input('limit') ?: 5;
$text = $request->input('text');
$key = $request->input('key') ?: 'title';
$key_limit = $request->input('key_limit') ?: 15;
$project = ProjectServer::useProject($project_id);
if (!$project) {
$this->response('项目不存在', Code::SYSTEM_ERROR);
}
//匹配产品
$products = Product::with('category')
->where("title", 'like', $text . '%')
->where("status", 1)
->orderBy("id", "DESC")
->limit($limit)
->select('title', 'thumb', 'id', 'route')
->get()
->toArray();
//对应分类
$categories = [];
foreach ($products as &$product) {
foreach ($product['category'] as $category) {
$categories[$category['route']] = [
'title' => $category['title'],
'route' => '/' . $category['route'] . '/',
];
}
unset($product['id']);
unset($product['category']);
if(!empty($product['thumb']) && !empty($product['thumb']['url'])){
$product['thumb'] = getImageUrl($product['thumb']['url'],$project['storage_type'] ?? 0,$project['project_location']);
}
$product['route'] = '/' . $product['route'] . '/';
}
$data = [
'products' => $products,
'categories' => array_values($categories),
'suggestions' => $this->searchSuggestion($text, $key, $key_limit)
];
$this->response('success', Code::SUCCESS, $data);
}
protected function searchSuggestion($text, $key, $key_limit): array
{
$model = new Product();
$columns = $model->getConnection()->getSchemaBuilder()->getColumnListing($model->getTable());
//产品字段
if (in_array($key, $columns)) {
//匹配产品
$suggestions = Product::where("status", 1)
->where($key, 'like', $text . '%')
->orderBy("id", "DESC")
->limit($key_limit)
->select($key .' as title', 'route')
->get()
->toArray();
} else {
//扩展字段
$suggestions = Product::leftJoin('gl_product_extend_info as pei', 'gl_product.id', '=', 'pei.product_id')
->where('pei.values', 'like', $text . '%')
->where("gl_product.status", 1)
->orderBy("gl_product.id", "DESC")
->limit($key_limit)
->select('pei.values','gl_product.route')
->get()
->toArray();
}
foreach ($suggestions as &$suggestion){
$suggestion['route'] = '/' . $suggestion['route'] . '/';
}
return $suggestions;
}
}
... ...
... ... @@ -8,6 +8,7 @@ use App\Http\Logic\Bside\News\NewsLogic;
use App\Http\Requests\Bside\News\NewsRequest;
use App\Models\News\News as NewsModel;
use App\Models\News\NewsCategory;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BTemplate;
use App\Models\Template\Setting;
... ... @@ -313,7 +314,20 @@ class NewsController extends BaseController
],[
'keyword.required' => 'keyword不能为空',
]);
$data = http_get('http://gnews.globalso.com/gnews_news.php?keyword='.$this->param['keyword'],['charset=utf-8']);
$data = curl_c('http://gnews.globalso.com/gnews_news.php?keyword='.$this->param['keyword'],false);
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :不分页产品列表
* @name :productNoPage
* @author :lyh
* @method :post
* @time :2024/3/20 11:02
*/
public function newsNoPage(NewsModel $news){
$this->map['status'] = $news::STATUS_ONE;
$lists = $news->list($this->map);
$this->response('success',Code::SUCCESS,$lists);
}
}
... ...
... ... @@ -68,7 +68,20 @@ class ProductController extends BaseController
$lists['list'][$k] = $v;
}
}
return $this->response('success',Code::SUCCESS,$lists);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :不分页产品列表
* @name :productNoPage
* @author :lyh
* @method :post
* @time :2024/3/20 11:02
*/
public function productNoPage(Product $product){
$this->map['status'] = $product::STATUS_ON;
$lists = $product->list($this->map,'id',['id','title']);
$this->response('success',Code::SUCCESS,$lists);
}
/**
... ... @@ -129,8 +142,8 @@ class ProductController extends BaseController
if(isset($this->map['status'])){
$query = $query->where('status',$this->map['status']);
}
if(!empty($this->map['start_at']) && !empty($this->map['end_at'])){
$query->whereBetween('created_at', [$this->map['start_at'],$this->map['end_at']]);
if(!empty($this->param['start_at']) && !empty($this->param['end_at'])){
$query->where('created_at', '>=' ,$this->param['start_at'].' 00:00:00')->where('created_at', '<=' ,$this->param['end_at'].' 59:59:59');
}
return $query;
}
... ...
... ... @@ -30,7 +30,6 @@ class ATemplateModuleLogic extends BaseLogic
*/
public function aTemplateModuleLists($map,$page,$row,$order = 'created_at',$filed = ['*']){
$map['deleted_status'] = 0;
$map['status'] = 0;
$lists = $this->model->lists($map,$page,$row,$order,$filed);
return $this->success($lists);
}
... ...
... ... @@ -189,6 +189,9 @@ class NewsLogic extends BaseLogic
if(isset($param['image'])){
$param['image'] = str_replace_url($param['image'] ?? '');
}
if(isset($param['related_news_id'])){
$param['related_news_id'] = implode(',',$param['related_news_id']);
}
if(isset($this->param['id'])){
$param['operator_id'] = $this->user['id'];
if(isset($param['category_id']) && !empty($param['category_id'])){
... ...
... ... @@ -62,8 +62,9 @@ class KeywordLogic extends BaseLogic
$this->fail('当前title已存在');
}
//TODO::不能修改路由
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_KEYWORD, $this->param['id'], $this->user['project_id']);
$this->param['route'] = $route;
$this->model->edit($this->param,['id'=>$this->param['id']]);
$route = RouteMap::getRoute(RouteMap::SOURCE_PRODUCT_KEYWORD,$this->param['id'], $this->user['project_id']);
$data = ['id'=>$this->param['id']];
}else{
$info = $this->model->read(['title'=>$this->param['title']]);
... ...
... ... @@ -12,6 +12,7 @@ namespace App\Http\Logic\Bside\Scoring;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Scoring\RatingQuestion;
use App\Models\Scoring\ScoringSystem;
use App\Models\User\User;
use AWS\CRT\Log;
class RatingLogic extends BaseLogic
... ... @@ -34,7 +35,7 @@ class RatingLogic extends BaseLogic
public function getRatingRead(){
$data = [
'company'=>$this->project['company'],
'mobile'=>$this->project['mobile'],
'mobile'=>$this->user['mobile'],
'uptime'=>$this->project['uptime'],
'domain'=>$this->user['domain'],
'question'=>$this->model->list(['type'=>$this->param['type']]),
... ... @@ -43,6 +44,7 @@ class RatingLogic extends BaseLogic
return $this->success($data);
}
/**
* @remark :提交统计
* @name :ratingSave
... ...
... ... @@ -34,7 +34,7 @@ class TranslateLogic extends BaseLogic
if($this->param['url'] == 'All'){
$info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]);
if(!empty($info) && !empty($info['data'])){
$translateInfo = json_decode($info['data'],true);
$translateInfo = json_decode($info['data'],JSON_UNESCAPED_UNICODE);
foreach ($translateInfo as $k => $v){
$data[] = [$k=>$v];
}
... ... @@ -48,7 +48,7 @@ class TranslateLogic extends BaseLogic
// 原始校对内容
$info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]);
if($info !== false){
$data_read = json_decode($info['data'],true);
$data_read = json_decode($info['data'],JSON_UNESCAPED_UNICODE);
foreach ($data_read as $k => $v){
$data[] = [$k => $v];
}
... ... @@ -130,7 +130,7 @@ class TranslateLogic extends BaseLogic
$info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]);
$data = [];
if(!empty($info) && !empty($info['data'])){
$translateInfo = json_decode($info['data'],true);
$translateInfo = json_decode($info['data'],JSON_UNESCAPED_UNICODE);
foreach ($translateInfo as $k => $v){
$data[] = [$k=>$v];
}
... ... @@ -151,7 +151,7 @@ class TranslateLogic extends BaseLogic
}
$new_list = $this->getUrlImageRead($url);
$old_list = [];
$data_read = json_decode($info['data'],true);
$data_read = json_decode($info['data'],JSON_UNESCAPED_UNICODE);
foreach ($data_read as $k=>$v){
$old_list[] = $k;
$data[] = [
... ... @@ -282,10 +282,10 @@ class TranslateLogic extends BaseLogic
'language_id'=>$this->param['language_id'],
'alias'=>$this->param['alias'],
];
$param['data'] = json_encode($data,true);
$param['data'] = json_encode($data,JSON_UNESCAPED_UNICODE);
$this->model->add($param);
}else{
$data = json_encode($data,true);
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
$this->model->edit(['data'=>$data],['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'type'=>$this->param['type']]);
}
}catch (\Exception $e){
... ...
... ... @@ -223,19 +223,19 @@ class UserLoginLogic
$date = date('Y-m-d H:i:s');
$scoringSystem = new ScoringSystem();
if($date <= $after30Days){
$info = $scoringSystem->read(['type'=>1]);//第一阶段是否有值
$info = $scoringSystem->read(['type'=>1,'project_id'=>$projectInfo['id']]);//第一阶段是否有值
if($info === false){
return $this->success(1);
}
}
if($date >= $afterThreeMonths && $date <= $afterSixMonths){
$info = $scoringSystem->read(['type'=>2]);//第一阶段是否有值
$info = $scoringSystem->read(['type'=>2,'project_id'=>$projectInfo['id']]);//第一阶段是否有值
if($info === false){
return $this->success(2);
}
}
if($date >= $afterOneYear){
$info = $scoringSystem->read(['type'=>3]);//第一阶段是否有值
$info = $scoringSystem->read(['type'=>3,'project_id'=>$projectInfo['id']]);//第一阶段是否有值
if($info === false){
return $this->success(3);
}
... ...
... ... @@ -7,4 +7,32 @@ use App\Models\Base;
class Notify extends Base
{
protected $table = 'gl_notify';
/**
* 状态 0:待处理, 1:路由生成完成, 2:页面生成完成
*/
const STATUS_INIT = 0;
const STATUS_FINISH_ROUTE = 1;
const STATUS_FINISH_PAGE = 2;
/**
* 类型 1:主站, 2:小语种
*/
const TYPE_MASTER = 1;
const TYPE_MINOR = 2;
/**
* 路由
* 1:所有路由,整站生成,
* 2:修改过内容的路由,按需生成,
* 3:指定路由,按url生成
* 4:生成聚合页生成
* 5:生成漏翻页面
* 6:生成视频聚合页
*/
const ROUTE_ALL = 1;
const ROUTE_NEED = 2;
const ROUTE_URL = 3;
const ROUTE_PRODUCT_KEYWORD = 4;
const ROUTE_NOT_TRANSLATE = 5;
const ROUTE_PRODUCT_VIDEO_KEYWORD = 6;
}
... ...
... ... @@ -10,6 +10,7 @@
namespace App\Models\CustomModule;
use App\Models\Base;
use App\Models\Module\ModuleCategory;
class CustomModule extends Base
{
... ...
... ... @@ -16,4 +16,20 @@ class CustomModuleCategory extends Base
protected $table = 'gl_custom_module_category';
//连接数据库
protected $connection = 'custom_mysql';
/**
* 根据路由获取模块分类及模块信息
*/
public static function getModuleCategoryAndExtendByRoute($projectId,$route)
{
return self::with("getExtend")->where("project_id",$projectId)->where("route",$route)->where("status",0)->first();
}
/**
* 根据路由获取模块分类及模块信息
*/
public static function getModuleCategoryAndExtendById($projectId,$id)
{
return self::with("getExtend")->where("project_id",$projectId)->where("id",$id)->where("status",0)->first();
}
}
... ...
... ... @@ -11,6 +11,9 @@ namespace App\Models\CustomModule;
use App\Helper\Arr;
use App\Models\Base;
use App\Models\Module\CustomModule;
use App\Models\Module\ModuleCategory;
use App\Services\Html\PageService;
class CustomModuleContent extends Base
{
... ... @@ -18,8 +21,9 @@ class CustomModuleContent extends Base
//连接数据库
protected $connection = 'custom_mysql';
public function getCategoryIdAttribute($value){
return explode(',',trim($value,','));
public function getCategoryIdAttribute($value)
{
return explode(',', trim($value, ','));
}
/**
... ... @@ -29,10 +33,114 @@ class CustomModuleContent extends Base
* @method :post
* @time :2024/1/23 14:31
*/
public function getVideoAttribute($value){
if(!empty($value)){
public function getVideoAttribute($value)
{
if (!empty($value)) {
$value = Arr::s2a($value);
}
return $value;
}
/**
* 根据路由获取模块信息
*/
public static function getModuleAndExtendById($projectId, $id)
{
return self::with("getExtend")->where("project_id", $projectId)->where("id", $id)->where("status", 0)->first();
}
/**
* 关联模块信息
*/
public function getExtend(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->hasOne(CustomModule::class, 'id', 'module_id');
}
/**
* module数据处理
*/
public static function modulesListDataHandle($moduleCategoryInfo, $modules): array
{
$newT = [];
$pageService = new PageService();
if (!empty($modules)) {
foreach ($modules as $key => $item) {
if (!empty($item->remark)) {
$remark = $item->remark;
} else {
$text = strip_tags($item->content);
$remark = strlen($text) > 260 ? substr($text, 0, 260) . '...' : $text;
}
$newT[$key]["id"] = $item->id;
if (!empty($item->category_id)) {
$categoryIdArr = explode(",", $item->category_id);
if (!empty($categoryIdArr)) {
$categoryIdArr = array_filter($categoryIdArr);
$categoryId = (int)array_shift($categoryIdArr);
$newT[$key]["category_id"] = $categoryId;
}
}
//视频
$newT[$key]["video"] = !empty($item->video) ? json_decode($item->video) : null;
$newT[$key]["image"] = !empty($item->image) ? $pageService->getImageUrl($item->image) : "";
$newT[$key]["content"] = !empty($item->content) ? $item->content : "";
$newT[$key]["name"] = !empty($item->name) ? $item->name : "";
$newT[$key]["remark"] = $remark;
if (isset($item->release_at) && !empty(isset($item->release_at))) {
$newT[$key]["created_at"] = $item->release_at;
} else {
$time = !empty($item->created_at) ? $item->created_at->toArray()['formatted'] : "";
$newT[$key]["created_at"] = $time;
}
$newT[$key]["created_at"] = strtotime($newT[$key]["created_at"]);
$newT[$key]["created_at"] = date("Y-m-d", $newT[$key]["created_at"]);
if (isset($newT[$key]["category_id"]) && !empty($newT[$key]["category_id"])) {
$categoryInfo = CustomModuleCategory::getModuleCategoryAndExtendById($item->project_id, $newT[$key]["category_id"]);
$newT[$key]["aUrl"] = !empty($categoryInfo) ? $categoryInfo->route . "/" . $item->route : "";
} else {
$newT[$key]["aUrl"] = !empty($item->route) ? $moduleCategoryInfo->route . "/" . $item->route : "";
}
}
}
return $newT;
}
/**
* 根据模块查找自定义模块分类数据
*/
public static function getModuleCategory($projectId, $modules)
{
$moduleCategoryInfo = null;
if (isset($modules->category_id) && !empty($modules->category_id) && $modules->category_id != ",,") {
$cateArr = explode(",", $modules->category_id);
$cateArr = array_filter($cateArr);
if (!empty($cateArr)) {
$cateId = (int)array_shift($cateArr);
$moduleCategoryInfo = CustomModuleCategory::getModuleCategoryAndExtendById($projectId, $cateId);
}
}
return $moduleCategoryInfo;
}
/**
* 是否是自定义扩展模块
*/
public static function isModule($moduleDataModule)
{
$moduleDataModuleArr = explode("-", $moduleDataModule);
if (count($moduleDataModuleArr) == 2) {
$moduleArr = $moduleDataModuleArr;
if (!empty($moduleArr)) {
$moduleArr[0] = isset($moduleArr[0]) && !empty($moduleArr[0]) ? $moduleArr[0] : null;
$moduleArr[1] = isset($moduleArr[1]) && !empty($moduleArr[1]) ? (int)$moduleArr[1] : null;
}
return $moduleArr;
} else {
// return $moduleDataModule;
return null;
}
}
}
... ...
... ... @@ -2,6 +2,7 @@
namespace App\Models\News;
use App\Helper\Arr;
use App\Models\Base;
class News extends Base
... ... @@ -22,4 +23,8 @@ class News extends Base
}
return $value;
}
public function getRelatedNewsIdAttribute($value){
return Arr::setToArr($value);
}
}
... ...
... ... @@ -17,4 +17,7 @@ class NewsCategory extends Base
const STATUS_SHOW = 0;
const STATUS_HIDE = 1;
//新闻分类,博客分类列表分页条数
public static $newsCategoryPagePercent = 10;
}
... ...
... ... @@ -21,6 +21,63 @@ class Category extends Base
protected $connection = 'custom_mysql';
const STATUS_ACTIVE = 1;
//新闻产品分类列表分页条数
public static $productCategoryPagePercent = 15;
public static $productSearchPagePercent = 12;
/**
* 根据分类ID查询上面所有父级,递归
*/
public static function getAllFatherCategory($categoryId): array
{
$category = self::find($categoryId);
return $category->getAncestorsRecursive();
}
/**
* 根据产品分类获取分类列表和产品
*/
public static function getCategoryBySelfCategory($projectId,$routerMap)
{
if ($routerMap->source_id == 0){
$categoryList = Category::with("products")->where("project_id",$projectId)->where("pid",0)->where("status",1)->orderBy("sort","desc")->orderBy("id","desc")->get();
}else{
$categoryIds = [];
$category = Category::where("project_id",$projectId)->where("pid",$routerMap->source_id)->where("status",1)->orderBy("sort","desc")->orderBy("id","desc")->get();
if (count($category)>=1){
foreach ($category as $categoryItem){
$categoryIds[] = $categoryItem->id;
}
}else{
$categoryIds[] = $routerMap->source_id;
}
$categoryList = Category::with("products")->where("project_id",$projectId)->whereIn("id",$categoryIds)->where("status",1)->orderBy("sort","desc")->orderBy("id","desc")->get();
}
return $categoryList;
}
/**
* 森联数据处理
*/
public static function getSenLianCategoryAndProducts($routerMap)
{
$data = [];
//下级分类及产品+产品扩展型号
$categorys = null;
$sonData = self::with("productsSl")->where("project_id",$routerMap->project_id)->where("status",1)->where("pid",$routerMap->source_id)->orderBy("id","desc")->get();
if ($routerMap->route == "products" || !empty($sonData)){
if ($routerMap->route == "products"){
$categorys = self::with("productsSl")->where("project_id",$routerMap->project_id)->where("status",1)->where("pid",0)->where("route","!=","products")->orderBy("id","desc")->get();
}else{
$categorys = $sonData;
}
}
if (!empty($categorys)){
$categorys = $categorys->toArray();
}
$data["categorySon"] = $categorys;
return $data;
}
/**
* 获取指定分类的所有子分类IDS(包括自己)
... ... @@ -72,4 +129,33 @@ class Category extends Base
$count = count($productArr);
return $count;
}
/**
* 根据分类ID查询下面所有子级ID,递归
*/
public static function getAllSonCategoryById($projectId,$id): array
{
$ids = [];
$ids[] = $id;
self::getProductCategoryList($projectId,$id,$ids);
return $ids;
}
/**
* 获取分类
*/
public static function getProductCategoryList($projectId,$id,&$ids)
{
$categoryListPid = self::where("project_id",$projectId)->where("pid",$id)->get();
if (!empty($categoryListPid)){
foreach ($categoryListPid as $item){
$ids[] = $item->id;
self::getProductCategoryList($projectId,$item->id,$ids);
}
}else{
$ids[] = $categoryListPid->id;
}
return $ids;
}
}
... ...
... ... @@ -17,4 +17,10 @@ class Extend extends Base
protected $table = 'gl_product_extend';
//连接数据库
protected $connection = 'custom_mysql';
//产品详情扩展字段类型 1,文本输入框 2,代码块 3,图片列表 4,文件列表
public static $textExtendType = 1;
public static $codeExtendType = 2;
public static $imageExtendType = 3;
public static $fileExtendType = 4;
}
... ...
... ... @@ -17,4 +17,76 @@ class ExtendInfo extends Base
protected $table = 'gl_product_extend_info';
//连接数据库
protected $connection = 'custom_mysql';
/**
* 搜索模块-广州万天实业有限公司-项目ID:194,获取产品品牌和型号扩展字段的值
* key值固定为:pd_extended_field_1:品牌,pd_extended_field_2:型号
*/
public static function getProductsAllBrandAndModel($projectId): array
{
$brandAndModel = [];
$brandArr = [];
$productIds = [];
$productsExtendInfo = self::where("project_id",$projectId)->get();
if (!empty($productsExtendInfo)){
$productsExtendBrandInfo = $productsExtendInfo->where("key","pd_extended_field_1");
if (!empty($productsExtendBrandInfo)){
foreach ($productsExtendBrandInfo as $productsExtendBrandInfoItem){
if (!empty($productsExtendBrandInfoItem->values)){
$brand = explode(",",$productsExtendBrandInfoItem->values);
$brands = array_filter($brand);
if (!empty($brands)){
foreach ($brands as $brandsItem){
$brandArr[] = $brandsItem;
}
}
}
}
}
}
//临时数据
if (!empty($brandArr)){
$brandArr = array_unique($brandArr);
$key = 0;
foreach ($brandArr as $brandArrItem){
$brandKeys = $productsExtendInfo->where("key","pd_extended_field_1");
if (!empty($brandKeys)){
foreach ($brandKeys as $brandKeysItem){
if ($brandKeysItem->values){
if (strpos($brandKeysItem->values, $brandArrItem) !== false){
$brandAndModel[$key]["ids"][] = $brandKeysItem->product_id;
$brandAndModel[$key]["brand"] = $brandArrItem;
}
}
}
}
$key++;
}
}
if (!empty($brandAndModel)){
foreach ($brandAndModel as $keyItem=>$brandAndModelItem){
if (!empty($brandAndModelItem["ids"])){
$productIds = array_unique($brandAndModelItem["ids"]);
$modelKeys = $productsExtendInfo->where("key","pd_extended_field_2")->whereIn("product_id",$productIds);
$models = [];
if (!empty($modelKeys)){
foreach ($modelKeys as $modelKeysItem){
if (!empty($modelKeysItem->values)){
$modelArr = array_filter(explode(",",$modelKeysItem->values));
foreach ($modelArr as $modelArrItem){
$models[] = $modelArrItem;
}
}
}
}
if (!empty($models)){
$models = array_unique($models);
$brandAndModel[$keyItem]["model"] = $models;
}
}
}
}
return $brandAndModel;
}
}
... ...
... ... @@ -55,4 +55,13 @@ class Keyword extends Base
}
return $value ?: [];
}
/**
* 随机获取关键词列表
*/
public function getProductsKeywordsList($project)
{
return Keyword::where("project_id",$project->id)->where("status",1)->inRandomOrder()->take(10)->get();
}
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Models\Product;
use App\Helper\Arr;
use App\Models\Base;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
... ... @@ -209,4 +210,15 @@ class Product extends Base
}
return $value;
}
/**
* 多对多关联
* @return BelongsToMany
* @author zbj
* @date 2024/1/22
*/
public function category(): BelongsToMany
{
return $this->belongsToMany(Category::class, 'gl_product_category_related', 'product_id', 'cate_id');
}
}
... ...
... ... @@ -3,8 +3,29 @@
namespace App\Models\Project;
use App\Models\Base;
use App\Models\WebSetting\WebLanguage;
use App\Models\WebSetting\WebSetting;
use Illuminate\Support\Facades\Redis;
class Country extends Base
{
protected $table = 'gl_project_country';
public static function getProjectCountry($projectId)
{
if (Redis::get("project_" . $projectId . "_country") == null) {
$country = Country::where("project_id", $projectId)->first();
if (!empty($country)) {
// $webCountry = WebLanguage::with("countryCustom")->whereIn("id", explode(",", $country->country_lists))->get();
$webCountry = WebLanguage::with(["countryCustom" => function($query) use ($projectId) {
$query->where('project_id', $projectId);
}])->whereIn("id", explode(",", $country->country_lists))->orderByRaw(DB::raw("FIND_IN_SET(id,'" . $country->country_lists. "'" . ')'))->get();
} else {
$webCountry = null;
}
Redis::set("project_" . $projectId . "_country", json_encode($webCountry));
Redis::expire("project_" . $projectId . "_country", WebSetting::$redisExpireTime);
}
return json_decode(Redis::get("project_".$projectId."_country"));
}
}
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Models\Project;
use App\Models\Base;
use App\Models\WebSetting\WebSetting;
use Illuminate\Database\Eloquent\SoftDeletes;
class CountryCustom extends Base
... ... @@ -10,4 +11,14 @@ class CountryCustom extends Base
use SoftDeletes;
protected $table = 'gl_project_country_custom';
public static function getCountryCustomByProjectId($projectId){
if (Redis::get("project_" . $projectId . "_country_custom") == null) {
$countryCustomInfo = self::with("countryCustomLanguage")->where("project_id",$projectId)->where("status",1)->where("is_create",1)->get();
Redis::set("project_" . $projectId . "_country_custom", json_encode($countryCustomInfo));
Redis::expire("project_" . $projectId . "_country_custom", WebSetting::$redisExpireTime);
}
return json_decode(Redis::get("project_".$projectId."_country_custom"));
}
}
... ...
... ... @@ -4,8 +4,6 @@ namespace App\Models\Project;
use App\Helper\Arr;
use App\Models\Base;
use App\Models\Devops\ServerConfig;
use Illuminate\Support\Facades\Cache;
class DomainInfo extends Base
{
... ...
... ... @@ -14,7 +14,25 @@ class Project extends Base
{
//设置关联表名
protected $table = 'gl_project';
public static $domainEndSlash = 1; //斜杠结尾
public static $projectLocationZero = 0; //普通项目
public static $projectLocationDangerous = 1; //危险项目
public static $storageTypeZero = 0; //默认腾讯压缩存储桶
public static $storageTypeOne = 1; //非压缩存储桶
public static $storageTypeZeroFileFix = "ecdn6.globalso.com"; //非压缩存储桶
public static $storageTypeOneFileFix = "ecdn6-nc.globalso.com"; //压缩存储桶
public static $projectLocationDangerousFileFix = "globalso-v6.s3.us-west-2.amazonaws.com"; //危险项目存储桶
//项目标识集合
public static $blockItems = "blockitems"; //html循环项父级标识
public static $blockAttrItems = "[blockitems]"; //html循环项父级属性标识
public static $blockItem = "blockitem"; //html循环项标识
public static $blockAttrItem = "[blockitem]"; //html循环项属性标识
public static $productListBlock = "productlistblock"; //html产品列表标识
public static $newListBlock = "newlistblock"; //html新闻列表标识
public static $blogListBlock = "bloglistblock"; //html博客列表标识
public static $productCategoryListBlock = "productcategorylistblock"; //html产品分类列表标识
const DATABASE_NAME_FIX = 'gl_data_';
const CUSTOMIZED_ONE = 1;//定制项目
... ...
<?php
namespace App\Models\Project;
use Illuminate\Database\Eloquent\Model;
/**
* @method static where(string $string, int $param)
* @method static find($id)
* @method static get()
* @method static insertGetId()
* @method static create(array $array)
* @method static offset(float|int $param)
* @method static select(string $string)
* @method static orderBy(string $string, string $string1)
*/
class UpdateMasterWebsiteModel extends Model
{
protected $connection = "custom_mysql";
protected $table = 'gl_update_master_website';
}
... ...
<?php
namespace App\Models\Project;
use Illuminate\Database\Eloquent\Model;
/**
* @method static where(string $string, int $param)
* @method static find($id)
* @method static get()
* @method static insertGetId()
* @method static create(array $array)
* @method static select(string $string)
* @method static orderBy(string $string, string $string1)
*/
class UpdateMinorLanguagesModel extends Model
{
protected $connection = "custom_mysql";
protected $table = 'gl_update_minor_languages';
}
... ...
<?php
namespace App\Models\Template;
use App\Models\Base;
/**
* @remark :默认主题
* @name :Setting
* @author :lyh
* @time :2023/6/28 16:51
*/
class BSettingTemplate extends Base
{
protected $table = 'gl_web_setting_template';
//连接数据库
protected $connection = 'custom_mysql';
}
... ... @@ -16,4 +16,5 @@ class BTemplateCommon extends Base
protected $table = 'gl_web_template_common';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -13,4 +13,12 @@ use App\Models\Base;
class Setting extends Base
{
protected $table = 'gl_web_setting_template';
/**
* 获取项目模板信息
*/
public static function getProjectTemplateInfo($projectId)
{
return self::where("project_id",$projectId)->first();
}
}
... ...
<?php
/**
* @remark :
* @name :TemplateProject.php
* @author :lyh
* @method :post
* @time :2023/11/15 14:38
*/
namespace App\Models\Template;
use App\Models\Base;
class TemplateProject extends Base
{
protected $table = 'gl_web_setting_template';
//连接数据库
protected $connection = 'custom_mysql';
}
... ... @@ -25,4 +25,9 @@ class SettingNum extends Base
protected $table = 'gl_setting_num';
//连接数据库
protected $connection = 'custom_mysql';
//列表页种类
public static $productListType = 1;
public static $blogListType = 2;
public static $newsListType = 3;
}
... ...
... ... @@ -16,4 +16,8 @@ class Translate extends Base
protected $table = 'gl_translate';
//连接数据库
protected $connection = 'custom_mysql';
public static $textType = 1;
public static $imageType = 2;
}
... ...
... ... @@ -10,13 +10,30 @@
namespace App\Models\WebSetting;
use App\Models\Base;
use App\Models\Project\CountryCustom;
use Illuminate\Support\Facades\Cache;
class WebLanguage extends Base
{
protected $table = 'gl_web_language';
/**
* 关键词17种语种
*/
public static function getKeywordsCountry($project = null)
{
$languageIds = [1,4,5,6,7,8,9,10,11,14,15,18,22,26,40,68,78,95,99];
//加入项目主语种
if (!empty($project)){
$mainLangId = $project->main_lang_id;
array_unshift($languageIds,(int)$mainLangId);
}
$projectId = $project->id;
$languageIds=array_unique($languageIds);
return WebLanguage::with(["countryCustom" => function($query) use ($projectId) {
$query->where('project_id', $projectId);
}])->whereIn("id",$languageIds)->get();
}
/**
* @param $id
* @return mixed
... ... @@ -48,4 +65,39 @@ class WebLanguage extends Base
}
return $id;
}
/**
* 获取项目主语种
*/
public static function getProjectMainLang($mainLangId = 1)
{
$mainLang = self::find($mainLangId);
if (empty($mainLang)){
return null;
}
return $mainLang;
}
/**
* 关键词17种语种IDS
*/
public static function getKeywordsCountryIds($project = null): array
{
$languageIds = [1,4,5,6,7,8,9,10,11,14,15,18,22,26,40,68,78,95,99];
//加入项目主语种
if (!empty($project)){
$mainLangId = $project->main_lang_id;
array_unshift($languageIds,(int)$mainLangId);
}
return array_unique($languageIds);
}
/**
* 关联语种自定义跳转设置
*/
public function countryCustom(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->hasOne(CountryCustom::class, 'language_id', 'id');
}
}
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Models\WebSetting;
use App\Models\Base;
use Illuminate\Support\Facades\Redis;
class WebSetting extends Base
{
... ... @@ -12,5 +13,26 @@ class WebSetting extends Base
//连接数据库
protected $connection = 'custom_mysql';
//网站缓存过期时间
public static $redisExpireTime = 600;
public static $redisUpdateHtmlExpireTime = 60;
public static $okStatus = 200;
public static $errStatus = 500;
/**
* 网站设置
*/
public static function getWebSetting($project)
{
if (Redis::get("project_".$project->id."_web_setting") == null) {
$webSetting = self::where("project_id", $project->id)->first();
if (!empty($webSetting)) {
Redis::set("project_".$project->id."_web_setting", json_encode($webSetting->toArray()));
} else {
Redis::set("project_".$project->id."_web_setting", null);
}
Redis::expire("project_".$project->id."_web_setting", WebSetting::$redisExpireTime);
}
return json_decode(Redis::get("project_".$project->id."_web_setting"));
}
}
... ...
<?php
namespace App\Models\WebSetting;
use Illuminate\Database\Eloquent\Model;
/**
* @method static whereIn(string $string, false|string[] $explode)
* @method static where(string $string, mixed|string $lang)
*/
class WebSettingCountry extends Model
{
protected $table = 'gl_web_setting_country';
}
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Models\WebSetting;
use App\Models\Base;
use Illuminate\Support\Facades\Redis;
class WebSettingText extends Base
{
... ... @@ -27,4 +28,21 @@ class WebSettingText extends Base
self::TYPE_NEWS=>'新闻页',
self::TYPE_BLOG=>'博客页',
];
/**
* 网站锚文本
*/
public static function getWebSettingText($project)
{
if (Redis::get("project_".$project->id."_web_setting_text") == null) {
$webSettingText = WebSettingText::where("project_id",$project->id)->get();
if (!empty($webSettingText)) {
Redis::set("project_".$project->id."_web_setting_text", json_encode($webSettingText->toArray()));
} else {
Redis::set("project_".$project->id."_web_setting_text", null);
}
Redis::expire("project_".$project->id."_web_setting_text", WebSetting::$redisExpireTime);
}
return json_decode(Redis::get("project_".$project->id."_web_setting_text"));
}
}
... ...
<?php
namespace App\Repositories\Bt;
/**
* 宝塔面板站点操作类库
* @author 阿良 or Youngxj(二次开发)
* @link https://www.bt.cn/api-doc.pdf
* @link https://gitee.com/youngxj0/Bty1.0
* @version 1.0
* @example
* $bt = new Bt('http://127.0.0.1/8888','xxxxxxxxxxxxxxxx');
* echo $bt->GetSystemTotal();//获取系统基础统计
* @return Array
*/
class Bt
{
private $BT_KEY = ""; //接口密钥
private $BT_PANEL = "http://127.0.0.1/8888"; //面板地址
/**
* 初始化
* @param [type] $bt_panel 宝塔接口地址
* @param [type] $bt_key 宝塔Api密钥
*/
public function __construct($bt_panel = null,$bt_key = null){
if($bt_panel) $this->BT_PANEL = $bt_panel;
if($bt_key) $this->BT_KEY = $bt_key;
}
/**
* 获取系统基础统计
*/
public function GetSystemTotal(){
$url = $this->BT_PANEL.$this->config("GetSystemTotal");
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取磁盘分区信息
*/
public function GetDiskInfo(){
$url = $this->BT_PANEL.$this->config("GetDiskInfo");
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取实时状态信息
* (CPU、内存、网络、负载)
*/
public function GetNetWork(){
$url = $this->BT_PANEL.$this->config("GetNetWork");
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 检查是否有安装任务
*/
public function GetTaskCount(){
$url = $this->BT_PANEL.$this->config("GetTaskCount");
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 检查面板更新
*/
public function UpdatePanel($check=false,$force=false){
$url = $this->BT_PANEL.$this->config("UpdatePanel");
$p_data = $this->GetKeyData();
$p_data['check'] = $check;
$p_data['force'] = $force;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 申请ssl
*/
public function ApplyCert($domains,$id){
$url = $this->BT_PANEL.$this->config("ApplyCert");
$p_data = $this->GetKeyData();
$p_data['domains'] = $domains;
$p_data['auth_type'] = "http";
$p_data['auth_to'] = $id;
$p_data['auto_wildcard'] = 0;
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 续签ssl
*/
public function RenewCert($index){
$url = $this->BT_PANEL.$this->config("RenewCert");
$p_data = $this->GetKeyData();
$p_data['index'] = $index;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站列表
* @param string $page 当前分页
* @param string $limit 取出的数据行数
* @param string $type 分类标识 -1: 分部分类 0: 默认分类
* @param string $order 排序规则 使用 id 降序:id desc 使用名称升序:name desc
* @param string $tojs 分页 JS 回调,若不传则构造 URI 分页连接
* @param string $search 搜索内容
*/
public function Websites($search='',$page='1',$limit='15',$type='-1',$order='id desc',$tojs=''){
$url = $this->BT_PANEL.$this->config("Websites");
$p_data = $this->GetKeyData();
$p_data['p'] = $page;
$p_data['limit'] = $limit;
$p_data['type'] = $type;
$p_data['order'] = $order;
$p_data['tojs'] = $tojs;
$p_data['search'] = $search;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站FTP列表
* @param string $page 当前分页
* @param string $limit 取出的数据行数
* @param string $type 分类标识 -1: 分部分类 0: 默认分类
* @param string $order 排序规则 使用 id 降序:id desc 使用名称升序:name desc
* @param string $tojs 分页 JS 回调,若不传则构造 URI 分页连接
* @param string $search 搜索内容
*/
public function WebFtpList($search='',$page='1',$limit='15',$type='-1',$order='id desc',$tojs=''){
$url = $this->BT_PANEL.$this->config("WebFtpList");
$p_data = $this->GetKeyData();
$p_data['p'] = $page;
$p_data['limit'] = $limit;
$p_data['type'] = $type;
$p_data['order'] = $order;
$p_data['tojs'] = $tojs;
$p_data['search'] = $search;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站SQL列表
* @param string $page 当前分页
* @param string $limit 取出的数据行数
* @param string $type 分类标识 -1: 分部分类 0: 默认分类
* @param string $order 排序规则 使用 id 降序:id desc 使用名称升序:name desc
* @param string $tojs 分页 JS 回调,若不传则构造 URI 分页连接
* @param string $search 搜索内容
*/
public function WebSqlList($search='',$page='1',$limit='15',$type='-1',$order='id desc',$tojs=''){
$url = $this->BT_PANEL.$this->config("WebSqlList");
$p_data = $this->GetKeyData();
$p_data['p'] = $page;
$p_data['limit'] = $limit;
$p_data['type'] = $type;
$p_data['order'] = $order;
$p_data['tojs'] = $tojs;
$p_data['search'] = $search;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取所有网站分类
*/
public function Webtypes(){
$url = $this->BT_PANEL.$this->config("Webtypes");
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取已安装的 PHP 版本列表
*/
public function GetPHPVersion(){
//拼接URL地址
$url = $this->BT_PANEL.$this->config("GetPHPVersion");
//准备POST数据
$p_data = $this->GetKeyData(); //取签名
//请求面板接口
$result = $this->HttpPostCookie($url,$p_data);
//解析JSON数据
$data = json_decode($result,true);
return $data;
}
/**
* 修改指定网站的PHP版本
* @param [type] $site 网站名
* @param [type] $php PHP版本
*/
public function SetPHPVersion($site,$php){
$url = $this->BT_PANEL.$this->config("SetPHPVersion");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$p_data['version'] = $php;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取指定网站运行的PHP版本
* @param [type] $site 网站名
*/
public function GetSitePHPVersion($site){
$url = $this->BT_PANEL.$this->config("GetSitePHPVersion");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 新增网站
* @param [type] $webname 网站域名 json格式
* @param [type] $path 网站路径
* @param [type] $type_id 网站分类ID
* @param string $type 网站类型
* @param [type] $version PHP版本
* @param [type] $port 网站端口
* @param [type] $ps 网站备注
* @param [type] $ftp 网站是否开通FTP
* @param [type] $ftp_username FTP用户名
* @param [type] $ftp_password FTP密码
* @param [type] $sql 网站是否开通数据库
* @param [type] $codeing 数据库编码类型 utf8|utf8mb4|gbk|big5
* @param [type] $datauser 数据库账号
* @param [type] $datapassword 数据库密码
*/
public function AddSite($infoArr=[]){
$url = $this->BT_PANEL.$this->config("WebAddSite");
//准备POST数据
$p_data = $this->GetKeyData(); //取签名
$p_data['webname'] = $infoArr['webname'];
$p_data['path'] = $infoArr['path'];
$p_data['type_id'] = $infoArr['type_id'];
$p_data['type'] = $infoArr['type'];
$p_data['version'] = $infoArr['version'];
$p_data['port'] = $infoArr['port'];
$p_data['ps'] = $infoArr['ps'];
$p_data['ftp'] = $infoArr['ftp'];
$p_data['ftp_username'] = $infoArr['ftp_username'];
$p_data['ftp_password'] = $infoArr['ftp_password'];
$p_data['sql'] = $infoArr['sql'];
$p_data['codeing'] = $infoArr['codeing'];
$p_data['datauser'] = $infoArr['datauser'];
$p_data['datapassword'] = $infoArr['datapassword'];
//请求面板接口
$result = $this->HttpPostCookie($url,$p_data);
//var_dump($result);
//解析JSON数据
$data = json_decode($result,true);
return $data;
}
/**
* 删除网站
* @param [type] $id 网站ID
* @param [type] $webname 网站名称
* @param [type] $ftp 是否删除关联FTP
* @param [type] $database 是否删除关联数据库
* @param [type] $path 是否删除关联网站根目录
*
*/
public function WebDeleteSite($id,$webname,$ftp,$database,$path){
$url = $this->BT_PANEL.$this->config("WebDeleteSite");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['webname'] = $webname;
$p_data['ftp'] = $ftp;
$p_data['database'] = $database;
$p_data['path'] = $path;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 停用站点
* @param [type] $id 网站ID
* @param [type] $name 网站域名
*/
public function WebSiteStop($id,$name){
$url = $this->BT_PANEL.$this->config("WebSiteStop");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['name'] = $name;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 启用网站
* @param [type] $id 网站ID
* @param [type] $name 网站域名
*/
public function WebSiteStart($id,$name){
$url = $this->BT_PANEL.$this->config("WebSiteStart");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['name'] = $name;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置网站到期时间
* @param [type] $id 网站ID
* @param [type] $edate 网站到期时间 格式:2019-01-01,永久:0000-00-00
*/
public function WebSetEdate($id,$edate){
$url = $this->BT_PANEL.$this->config("WebSetEdate");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['edate'] = $edate;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 修改网站备注
* @param [type] $id 网站ID
* @param [type] $ps 网站备注
*/
public function WebSetPs($id,$ps){
$url = $this->BT_PANEL.$this->config("WebSetPs");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['ps'] = $ps;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站备份列表
* @param [type] $id 网站ID
* @param string $page 当前分页
* @param string $limit 每页取出的数据行数
* @param string $type 备份类型 目前固定为0
* @param string $tojs 分页js回调若不传则构造 URI 分页连接 get_site_backup
*/
public function WebBackupList($id,$page='1',$limit='5',$type='0',$tojs=''){
$url = $this->BT_PANEL.$this->config("WebBackupList");
$p_data = $this->GetKeyData();
$p_data['p'] = $page;
$p_data['limit'] = $limit;
$p_data['type'] = $type;
$p_data['tojs'] = $tojs;
$p_data['search'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 创建网站备份
* @param [type] $id 网站ID
*/
public function WebToBackup($id){
$url = $this->BT_PANEL.$this->config("WebToBackup");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 删除网站备份
* @param [type] $id 网站备份ID
*/
public function WebDelBackup($id){
$url = $this->BT_PANEL.$this->config("WebDelBackup");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 删除数据库备份
* @param [type] $id 数据库备份ID
*/
public function SQLDelBackup($id){
$url = $this->BT_PANEL.$this->config("SQLDelBackup");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 备份数据库
* @param [type] $id 数据库列表ID
*/
public function SQLToBackup($id){
$url = $this->BT_PANEL.$this->config("SQLToBackup");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站域名列表
* @param [type] $id 网站ID
* @param boolean $list 固定传true
*/
public function WebDoaminList($id,$list=true){
$url = $this->BT_PANEL.$this->config("WebDoaminList");
$p_data = $this->GetKeyData();
$p_data['search'] = $id;
$p_data['list'] = $list;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站列表
* @param string $search
* @param int $p
* @param int $limit
* @param int $type
* @return mixed
*/
public function WebSiteList($search = '', $p = 1, $limit = 20, $type = 0){
$url = $this->BT_PANEL.$this->config("WebSiteList");
$p_data = $this->GetKeyData();
$p_data['search'] = $search;
$p_data['p'] = $p;
$p_data['limit'] = $limit;
$p_data['type'] = $type;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 添加域名
* @param [type] $id 网站ID
* @param [type] $webname 网站名称
* @param [type] $domain 要添加的域名:端口 80 端品不必构造端口,多个域名用换行符隔开
*/
public function WebAddDomain($id,$webname,$domain){
$url = $this->BT_PANEL.$this->config("WebAddDomain");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['webname'] = $webname;
$p_data['domain'] = $domain;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 删除网站域名
* @param [type] $id 网站ID
* @param [type] $webname 网站名
* @param [type] $domain 网站域名
* @param [type] $port 网站域名端口
*/
public function WebDelDomain($id,$webname,$domain,$port){
$url = $this->BT_PANEL.$this->config("WebDelDomain");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['webname'] = $webname;
$p_data['domain'] = $domain;
$p_data['port'] = $port;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取可选的预定义伪静态列表
* @param [type] $siteName 网站名
*/
public function GetRewriteList($siteName){
$url = $this->BT_PANEL.$this->config("GetRewriteList");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $siteName;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取预置伪静态规则内容(文件内容)
* @param [type] $path 规则名
* @param [type] $type 0->获取内置伪静态规则;1->获取当前站点伪静态规则
*/
public function GetFileBody($path,$type=0){
$url = $this->BT_PANEL.$this->config("GetFileBody");
$p_data = $this->GetKeyData();
// $path_dir = $type?'vhost/rewrite':'rewrite/nginx';
if ($type == 2) {
$path_dir = 'vhost/nginx';
} elseif ($type == 1) {
$path_dir = 'vhost/rewrite';
} else {
$path_dir = 'rewrite/nginx';
}
//获取当前站点伪静态规则
///www/server/panel/vhost/rewrite/user_hvVBT_1.test.com.conf
//获取内置伪静态规则
///www/server/panel/rewrite/nginx/EmpireCMS.conf
//保存伪静态规则到站点
///www/server/panel/vhost/rewrite/user_hvVBT_1.test.com.conf
///www/server/panel/rewrite/nginx/typecho.conf
$p_data['path'] = '/www/server/panel/'.$path_dir.'/'.$path.'.conf';
//var_dump($p_data['path']);
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 保存伪静态规则内容(保存文件内容)
* @param [type] $path 规则名
* @param [type] $data 规则内容
* @param string $encoding 规则编码强转utf-8
* @param number $type 0->系统默认路径;1->自定义全路径
*/
public function SaveFileBody($path,$data,$encoding='utf-8',$type=0){
$url = $this->BT_PANEL.$this->config("SaveFileBody");
if($type){
$path_dir = $path;
}else{
$path_dir = '/www/server/panel/vhost/rewrite/'.$path.'.conf';
}
$p_data = $this->GetKeyData();
$p_data['path'] = $path_dir;
$p_data['data'] = $data;
$p_data['encoding'] = $encoding;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置密码访问网站
* @param [type] $id 网站ID
* @param [type] $username 用户名
* @param [type] $password 密码
*/
public function SetHasPwd($id,$username,$password){
$url = $this->BT_PANEL.$this->config("SetHasPwd");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['username'] = $username;
$p_data['password'] = $password;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 关闭密码访问网站
* @param [type] $id 网站ID
*/
public function CloseHasPwd($id){
$url = $this->BT_PANEL.$this->config("CloseHasPwd");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站日志
* @param [type] $site 网站名
*/
public function GetSiteLogs($site){
$url = $this->BT_PANEL.$this->config("GetSiteLogs");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站盗链状态及规则信息
* @param [type] $id 网站ID
* @param [type] $site 网站名
*/
public function GetSecurity($id,$site){
$url = $this->BT_PANEL.$this->config("GetSecurity");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['name'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置网站盗链状态及规则信息
* @param [type] $id 网站ID
* @param [type] $site 网站名
* @param [type] $fix URL后缀
* @param [type] $domains 许可域名
* @param [type] $status 状态
*/
public function SetSecurity($id,$site,$fix,$domains,$status){
$url = $this->BT_PANEL.$this->config("SetSecurity");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['name'] = $site;
$p_data['fix'] = $fix;
$p_data['domains'] = $domains;
$p_data['status'] = $status;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站三项配置开关(防跨站、日志、密码访问)
* @param [type] $id 网站ID
* @param [type] $path 网站运行目录
*/
public function GetDirUserINI($id,$path){
$url = $this->BT_PANEL.$this->config("GetDirUserINI");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['path'] = $path;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 开启强制HTTPS
* @param [type] $site 网站域名(纯域名)
*/
public function HttpToHttps($site){
$url = $this->BT_PANEL.$this->config("HttpToHttps");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 关闭强制HTTPS
* @param [type] $site 域名(纯域名)
*/
public function CloseToHttps($site){
$url = $this->BT_PANEL.$this->config("CloseToHttps");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置SSL域名证书
* @param [type] $type 类型
* @param [type] $site 网站名
* @param [type] $key 证书key
* @param [type] $csr 证书PEM
*/
public function SetSSL($type,$site,$key,$csr){
$url = $this->BT_PANEL.$this->config("SetSSL");
$p_data = $this->GetKeyData();
$p_data['type'] = $type;
$p_data['siteName'] = $site;
$p_data['key'] = $key;
$p_data['csr'] = $csr;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 关闭SSL
* @param [type] $updateOf 修改状态码
* @param [type] $site 域名(纯域名)
*/
public function CloseSSLConf($updateOf,$site){
$url = $this->BT_PANEL.$this->config("CloseSSLConf");
$p_data = $this->GetKeyData();
$p_data['updateOf'] = $updateOf;
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取SSL状态及证书信息
* @param [type] $site 域名(纯域名)
*/
public function GetSSL($site){
$url = $this->BT_PANEL.$this->config("GetSSL");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站默认文件
* @param [type] $id 网站ID
*/
public function WebGetIndex($id){
$url = $this->BT_PANEL.$this->config("WebGetIndex");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置网站默认文件
* @param [type] $id 网站ID
* @param [type] $index 内容
*/
public function WebSetIndex($id,$index){
$url = $this->BT_PANEL.$this->config("WebSetIndex");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['Index'] = $index;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站流量限制信息
* @param [type] $id [description]
*/
public function GetLimitNet($id){
$url = $this->BT_PANEL.$this->config("GetLimitNet");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置网站流量限制信息
* @param [type] $id 网站ID
* @param [type] $perserver 并发限制
* @param [type] $perip 单IP限制
* @param [type] $limit_rate 流量限制
*/
public function SetLimitNet($id,$perserver,$perip,$limit_rate){
$url = $this->BT_PANEL.$this->config("SetLimitNet");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['perserver'] = $perserver;
$p_data['perip'] = $perip;
$p_data['limit_rate'] = $limit_rate;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 关闭网站流量限制
* @param [type] $id 网站ID
*/
public function CloseLimitNet($id){
$url = $this->BT_PANEL.$this->config("CloseLimitNet");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站301重定向信息
* @param [type] $site 网站名
*/
public function Get301Status($site){
$url = $this->BT_PANEL.$this->config("Get301Status");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置网站301重定向信息
* @param [type] $site 网站名
* @param [type] $toDomain 目标Url
* @param [type] $srcDomain 来自Url
* @param [type] $type 类型
*/
public function Set301Status($site,$toDomain,$srcDomain,$type){
$url = $this->BT_PANEL.$this->config("Set301Status");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$p_data['toDomain'] = $toDomain;
$p_data['srcDomain'] = $srcDomain;
$p_data['type'] = $type;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站反代信息及状态
* @param [type] $site [description]
*/
public function GetProxyList($site){
$url = $this->BT_PANEL.$this->config("GetProxyList");
$p_data = $this->GetKeyData();
$p_data['sitename'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 添加网站反代信息
* @param [type] $cache 是否缓存
* @param [type] $proxyname 代理名称
* @param [type] $cachetime 缓存时长 /小时
* @param [type] $proxydir 代理目录
* @param [type] $proxysite 反代URL
* @param [type] $todomain 目标域名
* @param [type] $advanced 高级功能:开启代理目录
* @param [type] $sitename 网站名
* @param [type] $subfilter 文本替换json格式[{"sub1":"百度","sub2":"白底"},{"sub1":"","sub2":""}]
* @param [type] $type 开启或关闭 0关;1开
*/
public function CreateProxy($cache,$proxyname,$cachetime,$proxydir,$proxysite,$todomain,$advanced,$sitename,$subfilter,$type){
$url = $this->BT_PANEL.$this->config("CreateProxy");
$p_data = $this->GetKeyData();
$p_data['cache'] = $cache;
$p_data['proxyname'] = $proxyname;
$p_data['cachetime'] = $cachetime;
$p_data['proxydir'] = $proxydir;
$p_data['proxysite'] = $proxysite;
$p_data['todomain'] = $todomain;
$p_data['advanced'] = $advanced;
$p_data['sitename'] = $sitename;
$p_data['subfilter'] = $subfilter;
$p_data['type'] = $type;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 添加网站反代信息
* @param [type] $cache 是否缓存
* @param [type] $proxyname 代理名称
* @param [type] $cachetime 缓存时长 /小时
* @param [type] $proxydir 代理目录
* @param [type] $proxysite 反代URL
* @param [type] $todomain 目标域名
* @param [type] $advanced 高级功能:开启代理目录
* @param [type] $sitename 网站名
* @param [type] $subfilter 文本替换json格式[{"sub1":"百度","sub2":"白底"},{"sub1":"","sub2":""}]
* @param [type] $type 开启或关闭 0关;1开
*/
public function ModifyProxy($cache,$proxyname,$cachetime,$proxydir,$proxysite,$todomain,$advanced,$sitename,$subfilter,$type){
$url = $this->BT_PANEL.$this->config("ModifyProxy");
$p_data = $this->GetKeyData();
$p_data['cache'] = $cache;
$p_data['proxyname'] = $proxyname;
$p_data['cachetime'] = $cachetime;
$p_data['proxydir'] = $proxydir;
$p_data['proxysite'] = $proxysite;
$p_data['todomain'] = $todomain;
$p_data['advanced'] = $advanced;
$p_data['sitename'] = $sitename;
$p_data['subfilter'] = $subfilter;
$p_data['type'] = $type;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站域名绑定二级目录信息
* @param [type] $id 网站ID
*/
public function GetDirBinding($id){
$url = $this->BT_PANEL.$this->config("GetDirBinding");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置网站域名绑定二级目录
* @param [type] $id 网站ID
* @param [type] $domain 域名
* @param [type] $dirName 目录
*/
public function AddDirBinding($id,$domain,$dirName){
$url = $this->BT_PANEL.$this->config("AddDirBinding");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['domain'] = $domain;
$p_data['dirName'] = $dirName;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 删除网站域名绑定二级目录
* @param [type] $dirid 子目录ID
*/
public function DelDirBinding($dirid){
$url = $this->BT_PANEL.$this->config("DelDirBinding");
$p_data = $this->GetKeyData();
$p_data['id'] = $dirid;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站子目录绑定伪静态信息
* @param [type] $dirid 子目录绑定ID
*/
public function GetDirRewrite($dirid,$type=0){
$url = $this->BT_PANEL.$this->config("GetDirRewrite");
$p_data = $this->GetKeyData();
$p_data['id'] = $dirid;
if($type){
$p_data['add'] = 1;
}
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 修改FTP账号密码
* @param [type] $id FTPID
* @param [type] $ftp_username 用户名
* @param [type] $new_password 密码
*/
public function SetUserPassword($id,$ftp_username,$new_password){
$url = $this->BT_PANEL.$this->config("SetUserPassword");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['ftp_username'] = $ftp_username;
$p_data['new_password'] = $new_password;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 修改SQL账号密码
* @param [type] $id SQLID
* @param [type] $ftp_username 用户名
* @param [type] $new_password 密码
*/
public function ResDatabasePass($id,$name,$password){
$url = $this->BT_PANEL.$this->config("ResDatabasePass");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['name'] = $name;
$p_data['password'] = $password;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 启用/禁用FTP
* @param [type] $id FTPID
* @param [type] $username 用户名
* @param [type] $status 状态 0->关闭;1->开启
*/
public function SetStatus($id,$username,$status){
$url = $this->BT_PANEL.$this->config("SetStatus");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['username'] = $username;
$p_data['status'] = $status;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 宝塔一键部署列表
* @param string $search 搜索关键词
* @return [type] [description]
*/
public function deployment($search=''){
if($search){
$url = $this->BT_PANEL.$this->config("deployment").'&search='.$search;
}else{
$url = $this->BT_PANEL.$this->config("deployment");
}
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 宝塔一键部署执行
* @param [type] $dname 部署程序名
* @param [type] $site_name 部署到网站名
* @param [type] $php_version PHP版本
*/
public function SetupPackage($dname,$site_name,$php_version){
$url = $this->BT_PANEL.$this->config("SetupPackage");
$p_data = $this->GetKeyData();
$p_data['dname'] = $dname;
$p_data['site_name'] = $site_name;
$p_data['php_version'] = $php_version;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置文件权限
* @param $path
* @param $user
* @param $access
* @param $all
* @return mixed
*/
public function setFileAccess($path, $user, $access, $all) {
$url = $this->BT_PANEL.$this->config("SetFileAccess");
$p_data = $this->GetKeyData();
$p_data['user'] = $user;
$p_data['access'] = $access;
$p_data['all'] = $all;
$p_data['filename'] = $path;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取队列
* @return mixed
*/
public function getProcessList()
{
$url = $this->BT_PANEL.$this->config("GetProcessList");
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 停止队列
* @param $program
* @param int $numprocs
* @return mixed
*/
public function stopProcess($program, $numprocs = 1)
{
$url = $this->BT_PANEL.$this->config("StopProcess");
$p_data = $this->GetKeyData();
$p_data['program'] = $program;
$p_data['numprocs'] = $numprocs;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 启动队列
* @param $program
* @param int $numprocs
* @return mixed
*/
public function startProcess($program, $numprocs = 1)
{
$url = $this->BT_PANEL.$this->config("StartProcess");
$p_data = $this->GetKeyData();
$p_data['program'] = $program;
$p_data['numprocs'] = $numprocs;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置文件权限
* @param $path
* @return mixed
*/
public function DeleteFile($path) {
$url = $this->BT_PANEL.$this->config("DeleteFile");
$p_data = $this->GetKeyData();
$p_data['path'] = $path;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 更新网站目录
* @param $site_id
* @param $path
* @return mixed
*/
public function SetPath($site_id, $path)
{
$url = $this->BT_PANEL.$this->config("SetPath");
$p_data = $this->GetKeyData();
$p_data['id'] = $site_id;
$p_data['path'] = $path;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 更新运行目录
* @param $site_id
* @param $path
* @return mixed
*/
public function SetSiteRunPath($site_id, $path)
{
$url = $this->BT_PANEL.$this->config("SetSiteRunPath");
$p_data = $this->GetKeyData();
$p_data['id'] = $site_id;
$p_data['runPath'] = $path;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 构造带有签名的关联数组
*/
public function GetKeyData(){
$now_time = time();
$p_data = array(
'request_token' => md5($now_time.''.md5($this->BT_KEY)),
'request_time' => $now_time
);
return $p_data;
}
/**
* 发起POST请求
* @param String $url 目标网填,带http://
* @param Array|String $data 欲提交的数据
* @return string
*/
private function HttpPostCookie($url, $data,$timeout = 60)
{
//定义cookie保存位置
$cookie_file='./'.md5($this->BT_PANEL).'.cookie';
if(!file_exists($cookie_file)){
$fp = fopen($cookie_file,'w+');
fclose($fp);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
/**
* 加载宝塔数据接口
* @param [type] $str [description]
* @return [type] [description]
*/
private function config($str){
$config = config("bt");
//var_dump($config);
return $config[$str];
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/09/18
* Time: 20:56
*/
namespace App\Repositories;
use App\Repositories\Bt\Bt;
use Illuminate\Support\Facades\Log;
/**
* Class BtRepository
* @package App\Repositories
*/
class BtRepository
{
public $instance = [];
/**
* @param $domain
* @return array|bool
*/
public function createBtSite($domain, $rewrite = [], $domain_list = [])
{
$domain_array = parse_url($domain);
$host = $domain_array['host'] ?? $domain_array['path'];
// TODO 验证当前服务器是否已经创建过了
$bt = $this->getBtObject();
$site_list = $bt->WebSiteList($host);
if (!empty($site_list['data'])) {
return ['site_id' => $site_list['data'][0]['id']];
}
// if ($domain_list) {
// $web_name = ['domain' => $host, 'domainlist' => $domain_list, 'count' => 0];
// } else {
// $host_array = explode('.', $host);
// if (FALSE == empty($host_array[0]) && $host_array[0] == 'www')
// unset($host_array[0]);
// $domain_top = implode('.', $host_array);
// if ($domain_top == $host){
// $web_name = ['domain' => $host, 'domainlist' => ['www.'.$domain_top, '*.' . $host], 'count' => 0];
// }else{
// $web_name = ['domain' => $host, 'domainlist' => [$domain_top, '*.' . $domain_top], 'count' => 0];
// }
// }
$web_name = ['domain' => $host, 'domainlist' => $domain_list, 'count' => 0];
$array = [
'webname' => json_encode($web_name),
'path' => '/www/wwwroot/createSite',
'type_id' => 0,
'type' => 'PHP',
'version' => '80',
'port' => '80',
'ps' => $host,
'ftp' => false,
'ftp_username' => '',
'ftp_password' => '',
'sql' => false,
'codeing' => '',
'datauser' => '',
'datapassword' => '',
];
$result = $bt->AddSite($array);
// result 返回信息
// $result = ['siteStatus' => true, 'siteId' => 39, 'ftpStatus' => false, 'databaseStatus' => false,];
if (empty($result) || empty($result['siteId']))
return false;
// 更新站点目录 更新站点运行目录
$bt->SetPath($result['siteId'], public_path());
// 删除 .user.ini
$bt->DeleteFile('/www/wwwroot/c-globalso/public/.user.ini');
$bt->DeleteFile('/www/wwwroot/c-globalso/.user.ini');
// $bt->SetSiteRunPath($result['siteId'], '/');
#---------------------------------------------------------------------------------------------------------------
// 伪静态设置
// $htaccess = $this->rewrite301($rewrite);
// if ($htaccess)
// $bt->SaveFileBody($host, $htaccess);
// 获取配置
// 设置Nginx配置
// $nginx_config = $this->getAfterNginxConfStr($host);
// $bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $nginx_config, 'utf-8', 1);
#---------------------------------------------------------------------------------------------------------------
return ['site_id' => $result['siteId']];
}
/**
* 申请免费证书
* @param string $domain
* @param array $rewrite
* @param array $otherDomain
* @param int $is_https
* @return bool
*/
public function applySsl($domain, $rewrite = [], $otherDomain = [], $is_https = 0)
{
$domain_array = parse_url($domain);
$host = $domain_array['host'] ?? $domain_array['path'];
$bt = $this->getBtObject();
$site_list = $bt->WebSiteList($host);
if (empty($site_list['data'])) {
$site = $this->createBtSite($domain,$rewrite,$otherDomain);
$site_id = $site['site_id'];
}else{
$site_id = $site_list['data'][0]['id'];
$host = $site_list['data'][0]['name'];
}
// 获取站点域名
$site_domain = $bt->WebDoaminList($site_id);
$domain_list = [];
foreach ($site_domain as $val) {
if (FALSE === strpos($val['name'], '*')) {
array_push($domain_list, $val['name']);
}
}
//添加站点域名
$this->addDomain($site_id, $host, $otherDomain, $site_domain);
//还原配置
$nginx_config = $this->getBeforeNginxConfStr($host);
$bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $nginx_config, 'utf-8', 1);
// 如果已经申请了ssl证书, 并且证书有效期超过3天, 那么就使用已经申请好的证书
$ssl = $bt->GetSSL($host);
$is_set_status = false;//是否需要设置证书
if (FALSE == empty($ssl['cert_data']['notAfter']) && strtotime($ssl['cert_data']['notAfter']) - time() > 259200) {
$key = $ssl['key'];
$cer = $ssl['csr'];
$is_set_status = !$ssl['status'];
} else {
// 申请证书时需要将重写规则情况, 不然会跳转到其他地方
$bt->SaveFileBody($host, '');
// 如果没有证书, 申请证书并设置证书
$rs = $bt->ApplyCert(json_encode($domain_list),$site_id);
if(isset($rs['status']) && $rs['status']){
//申请成功,设置证书
$key = $rs['private_key'];
$cer = $rs['cert'];
$is_set_status = true;
}else{
$key = '';
$cer = '';
}
}
if($key && $cer && $is_set_status){
$bt->SetSSL(1, $host, $key, $cer);
}
$bt->DeleteFile('/www/wwwroot/c-globalso/public/.user.ini');
$bt->DeleteFile('/www/wwwroot/c-globalso/.user.ini');
$htaccess = $this->rewrite301($rewrite,$is_https);
if ($htaccess)
$bt->SaveFileBody($host, $htaccess);
// 更新配置
$nginx_config = $this->getAfterNginxConfStr($host);
$bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $nginx_config, 'utf-8', 1);
return true;
}
/**
* 设置ssl证书
* @param string $domain
* @param array $rewrite
* @param array $otherDomain
* @param string $private_key
* @param string $cert
* @param int $is_https
* @return bool
*/
public function setSsl($domain, $rewrite = [], $otherDomain = [], $private_key = '', $cert = '', $is_https = 0)
{
$domain_array = parse_url($domain);
$host = $domain_array['host'] ?? $domain_array['path'];
$bt = $this->getBtObject();
$site_list = $bt->WebSiteList($host);
if (empty($site_list['data'])) {
$site = $this->createBtSite($domain,$rewrite,$otherDomain);
$site_id = $site['site_id'];
}else{
$host = $site_list['data'][0]['name'];
$site_id = $site_list['data'][0]['id'];
}
//添加站点域名
$this->addDomain($site_id, $host, $otherDomain);
// 还原配置
$nginx_config = $this->getBeforeNginxConfStr($host);
$bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $nginx_config, 'utf-8', 1);
$bt->SetSSL(1, $host, $private_key, $cert);
$bt->DeleteFile('/www/wwwroot/c-globalso/public/.user.ini');
$bt->DeleteFile('/www/wwwroot/c-globalso/.user.ini');
// 设置301跳转
$htaccess = $this->rewrite301($rewrite,$is_https);
if ($htaccess)
$bt->SaveFileBody($host, $htaccess);
// 更新配置
$nginx_config = $this->getAfterNginxConfStr($host);
$bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $nginx_config, 'utf-8', 1);
return true;
}
/**
* 获取bt对象
* @param string $key
* @param string $panel
* @return Bt
*/
public function getBtObject($key = '', $panel = '')
{
$key = $key ?: env('BT_KEY');
$panel = $panel ?: env('BT_PANEL');
$object_key = md5($key . $panel);
if (empty($this->instance[$object_key])) {
$bt = new Bt($panel, $key);
$this->instance[$object_key] = $bt;
}
return $this->instance[$object_key];
}
/**
* 获取配置前的文件内容
* @param $domain
* @return string|string[]
*/
public function getBeforeNginxConfStr($domain)
{
$bt = $this->getBtObject();
$conf = $bt->GetFileBody($domain, 2);
//如果有变量标识,去掉变量标识
if (FALSE !== strpos($conf['data'], 'map $domain_prefix')){
$conf['data'] = str_replace($this->domainPrefixConf(),'',$conf['data']);
//去掉自定义配置
$conf['data'] = str_replace($this->customConf($domain),'root ' . public_path() . ';', $conf['data']);
}
// preg_match('/set \$root[\S\s]+root \$root;/iU', $conf['data'], $matches);
// if (FALSE == empty($matches[0])) {
// $conf['data'] = str_replace($matches[0], 'root ' . public_path() . ';', $conf['data']);
// }
return $conf['data'];
}
/**
* 获取配置后的文件内容
* @param $domain
* @return mixed
*/
public function getAfterNginxConfStr($domain)
{
$bt = $this->getBtObject();
$conf = $bt->GetFileBody($domain, 2);
// $conf['data'] = file_get_contents(storage_path('logs/nginx.conf'));
// 如果没有变量, 添加变量识别
if (FALSE === strpos($conf['data'], 'map $domain_prefix')){
$conf['data'] = $this->domainPrefixConf() . $conf['data'];
// 替换自定义配置
$conf['data'] = str_replace('root ' . public_path() . ';', $this->customConf($domain), $conf['data']);
}
return $conf['data'];
}
/**
* 需要定制修改的配置
* @return string
*/
public function customConf($domain): string
{
$string = ' root '.public_path().'; # 设置根目录
set $domain_prefix "";
if ($host ~* "^(?<domain_prefix>[^.]+)\.") {
set $domain_prefix $1;
}
location / {
root '.public_path().'/'.$domain.'; # 设置根目录
if ($is_prefix_in_string = 1) {
root '.public_path().'/'.$domain.'/$domain_prefix;
}
try_files $uri $uri/ /404/index.html =404;
}
location ~ ^/(api|search) {
root '.public_path().'; # 设置/api /search /.well-known的根目录
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^/(well-known) {
root '.public_path().';
try_files $uri $uri/ /404/index.html =404;
}
error_page 403 /404/index.html;';
return $string;
}
/**
* 解析301跳转
* @param $rewrite
* @param $is_https
* @return string
*/
public function rewrite301($rewrite,$is_https)
{
$string = '# 屏蔽蜘蛛
if ($http_user_agent ~* "(Knowledge|SiteAuditBot|DotBot|rogerbot|MJ12bot|MegaIndex|Paracrawl|HubSpot|serpstatbot|SemrushBot|DataForSeoBot|BLEXBot|Bytespider|Sogou|Seekport|HubSpot|Barkrowler|PetalBot|Amazonbot|RainBot|test-bot|fidget-spinner-bot)") {
return 444;
}
# 设置跳转
';
if (FALSE == is_array($rewrite))
return $string;
foreach ($rewrite as $val) {
if (empty($val['origin']) || empty($val['target']))
continue;
$origin_tmp = parse_url($val['origin']);
$origin = $origin_tmp['host'] ?? $origin_tmp['path'];
$target_tmp = parse_url($val['target']);
$target = $target_tmp['host'] ?? $target_tmp['path'];
$string .= '
if ($host ~ "^' . $origin . '"){
return 301 $scheme://' . $target . '$request_uri;
}
';
}
if($is_https){
$string .= '
#HTTP_TO_HTTPS_START
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
';
}
return $string;
}
/**
* 配置变量
* @return string
*/
public function domainPrefixConf()
{
return 'map $domain_prefix $is_prefix_in_string {
default 0; en 1; zh 1; fr 1; de 1; ko 1; ja 1; es 1; ar 1; pt 1; ru 1; af 1; sq 1;
am 1; hy 1; az 1; eu 1; be 1; bn 1; bs 1; bg 1; ca 1; ceb 1; zh-CN 1; zh-TW 1; co 1;
hr 1; cs 1; da 1; nl 1; eo 1; et 1; fi 1; fy 1; gl 1; ka 1; el 1; gu 1; ht 1; ha 1; haw 1;
iw 1; hi 1; hmn 1; hu 1; is 1; ig 1; id 1; ga 1; it 1; jw 1; kn 1; kk 1; km 1; rw 1;
ku 1; ky 1; lo 1; la 1; lv 1; lt 1; lb 1; mk 1; mg 1; ms 1; ml 1; mt 1; mi 1; mr 1; mn 1;
my 1; ne 1; no 1; ny 1; or 1; ps 1; fa 1; pl 1; pa 1; ro 1; sm 1; gd 1; sr 1; st 1; sn 1;
sd 1; si 1; sk 1; sl 1; so 1; su 1; sw 1; sv 1; tl 1; tg 1; ta 1; tt 1; te 1; th 1; tr 1;
tk 1; uk 1; ur 1; ug 1; uz 1; vi 1; cy 1; xh 1; yi 1; yo 1; zu 1;
}';
}
//添加站点域名
protected function addDomain($site_id, $domain, $otherDomains, $site_domain = [])
{
$bt = $this->getBtObject();
if(!$site_domain){
$site_domain = $bt->WebDoaminList($site_id);
}
$site_domain = array_column($site_domain, 'name');
foreach ($otherDomains as $k => $otherDomain) {
// 如果已经包含, 就不添加
if (in_array($otherDomain, $site_domain)) {
unset($otherDomains[$k]);
}
}
if ($otherDomains) {
$otherDomains = implode(',', $otherDomains);
$res = $bt->WebAddDomain($site_id, $domain, $otherDomains);
if (!$res['status']) {
return false;
}
}
return true;
}
/**
* 创建amp站点
* @param $domain
* @param $key
* @param $cer
* @return array|bool
* @author Akun
* @date 2024/02/18 17:04
*/
public function createBtSiteAmp($domain,$key,$cer)
{
$domain_array = parse_url($domain);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.',$host);
if(count($host_array) <= 2){
array_unshift($host_array,'m');
}else{
$host_array[0] = 'm';
}
$host = implode('.',$host_array);
// 验证当前服务器是否已经创建过了
$bt = $this->getBtObject();
$site_list = $bt->WebSiteList($host);
if (!empty($site_list['data'])) {
$site_id = $site_list['data'][0]['id'];
}else{
$web_name = ['domain' => $host, 'domainlist' => [], 'count' => 0];
$array = [
'webname' => json_encode($web_name),
'path' => '/www/wwwroot/createSite',
'type_id' => 0,
'type' => 'PHP',
'version' => '80',
'port' => '80',
'ps' => $host,
'ftp' => false,
'ftp_username' => '',
'ftp_password' => '',
'sql' => false,
'codeing' => '',
'datauser' => '',
'datapassword' => '',
];
$result = $bt->AddSite($array);
if (empty($result) || empty($result['siteId']))
return false;
$site_id = $result['siteId'];
// 更新站点目录 更新站点运行目录
$bt->SetPath($site_id, public_path());
// 删除 .user.ini
$bt->DeleteFile('/www/wwwroot/c-globalso/public/.user.ini');
$bt->DeleteFile('/www/wwwroot/c-globalso/.user.ini');
}
if(empty($key) || empty($cer)){
$ssl = $bt->GetSSL($host);
$is_set_status = false;//是否需要设置证书
if (FALSE == empty($ssl['cert_data']['notAfter']) && strtotime($ssl['cert_data']['notAfter']) - time() > 259200) {
// 如果已经申请了ssl证书, 并且证书有效期超过3天, 那么就使用已经申请好的证书
$key = $ssl['key'];
$cer = $ssl['csr'];
$is_set_status = !$ssl['status'];
} else {
// 如果没有证书, 申请证书并设置证书
$bt->SaveFileBody($host, ''); // 申请证书时需要将重写规则清空, 不然会跳转到其他地方
$rs = $bt->ApplyCert(json_encode([$host]),$site_id);
if(isset($rs['status']) && $rs['status']){
//申请成功,设置证书
$key = $rs['private_key'];
$cer = $rs['cert'];
$is_set_status = true;
}else{
$key = '';
$cer = '';
}
}
}else{
$is_set_status = true;
}
if($key && $cer && $is_set_status){
$bt->SetSSL(1, $host, $key, $cer);
}
// 伪静态设置
$bt->SaveFileBody($host, 'location / {
try_files $uri $uri/ /index.php?$query_string;
}');
return ['site_id' => $site_id];
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/8/31
* Time: 14:54
*/
namespace App\Repositories;
use App\Helper\Translate;
use App\Models\CustomModule\CustomModule;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\Module\Module;
use App\Models\Module\ModuleCategory;
use App\Models\RouteMap\RouteMap;
use App\Models\WebSetting\Translate as WebTranslate;
/**
* Class StaticHtmlRepository
* @package App\Repositories
*/
class StaticHtmlRepository
{
/**
* 通过域名和路由 获取主语种HTML
* @param string $domain
* @param string $route
* @return string
*/
public function getMainHtml($domain, $route)
{
$html = '';
return $html;
}
/**
* 5.0生成路径
*/
public function getProjectRoutePath5($project,$route,$page): string
{
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("path","")->first();
if (empty($routerMap)){
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->first();
}
if (!empty($routerMap)){
if ($routerMap->source == "news"){
$route = "news/".$route;
}elseif($routerMap->source == "blog" || $routerMap->source == "blogs"){
$route = "blogs/".$route;
}elseif ($routerMap->source == "news_category"){
if ($route == "news"){
$route = $page == null || $page == 1 ? $route : $route . "/page";
}else{
$route = $page == null || $page == 1 ? "news_catalog/".$route : "news_catalog/".$route."/page";
}
}elseif ($routerMap->source == "blog_category"){
if ($route == "blog"){
$route = $page == null || $page == 1 ? $route : $route."/page";
}else{
$route = $page == null || $page == 1 ? "blog_catalog/".$route : "blog_catalog/".$route."/page";
}
}elseif ($routerMap->source == "product_category"){
$route = $page == null || $page == 1 ? $route : $route."/page";
}elseif ($routerMap->source == "module_category"){
$moduleCategory = CustomModuleCategory::getModuleCategoryAndExtendById($project->id,$routerMap->source_id);
if (!empty($moduleCategory->getExtend->route)){
if ($moduleCategory->getExtend->route == $route){
$route = $moduleCategory->route;
}else{
$route = $moduleCategory->getExtend->route."_catalog/".$moduleCategory->route."/page";
}
}else{
$route = $moduleCategory->route."/page";
}
}elseif ($routerMap->source == "module"){
$modules = CustomModule::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
$moduleCategoryInfo = CustomModule::getModuleCategory($project->id,$modules);
if (isset($moduleCategoryInfo->getExtend->route) && !empty($moduleCategoryInfo->getExtend->route)){
$route = $moduleCategoryInfo->route."/".$modules->route;
}
}else{
$route = $route == "index" ? "/" : $route;
}
}else{
if ($route == "products"){
if ($page == null || $page == 1){
}else{
$route = $route."/page";
}
}elseif ($route == "news"){
}elseif ($route == "blog"){
$route = $page == null || $page == 1 ? "blog_catalog/".$route : "blog_catalog/".$route."/page";
}else{
$route = $route == "index" ? "/" : $route;
}
}
return $route;
}
/**
* 6.0生成路径
*/
public function getProjectRoutePath6($project,$route): string
{
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->first();
if (!empty($routerMap)){
if ($routerMap->source == "news"){
$route = "news/".$route;
}elseif($routerMap->source == "blog"){
$route = "blogs/".$route;
}elseif($routerMap->source == "module"){
$modules = CustomModule::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
$moduleCategoryInfo = CustomModule::getModuleCategory($project->id,$modules);
if (isset($moduleCategoryInfo->route) && !empty($moduleCategoryInfo->route)){
$route = $moduleCategoryInfo->route."/".$route;
}
}else{
$route = $route == "index" ? "/" : $route;
}
}else{
$route = $route == "index" ? "/" : $route;
}
return $route;
}
public function compactUrl($project,$route,$page): string
{
//是否是5.0升级项目
if (isset($project->update_info["is_update"]) && $project->update_info["is_update"] == 1){
//5.0生成路径
$path = $this->getProjectRoutePath5($project,$route,$page);
}else{
//6.0生成路径
$path = $this->getProjectRoutePath6($project,$route);
}
return $path;
}
/**
* 通过域名和路由以及目标语种 获取小语种HTML
* @param string $domain
* @param string $route
* @param string $tl
* @return string
*/
public function getOtherLangHtml($domain, $route, $tl)
{
$path = '通过域名和路由获取主语种静态文件路径';
if (is_file($path)) {
$main_html = file_get_contents($path);
} else {
$main_html = $this->getMainHtml($domain, $route);
}
$html = '通过主语种HTML生成小语种HTML 并处理小语种特有的内容';
return $html;
}
/**
* 获取翻译后的HTML
* TODO HTML转dom, 提取需要渲染的词, 翻译关键词, 根据节点还原关键词, 清除dom, 返回HTML
* @param string $html 原HTML
* @param string $tl 目标语种
* @param string $sl 原语种
* @return mixed
*/
public function getTranHtml($project,string $html, string $tl,$route,$page, string $sl = 'auto')
{
$dom = str_get_html($html);
// file_put_contents(public_path("aaa.html"), $html);
if (is_bool($dom)){
return $html;
}
$texts = $dom->find("text");
$description = $dom->find("meta[name=description]",0);
$keywords = $dom->find("meta[name=keywords]",0);
// 组装需要翻译的内容 HTML内文案、meta description、meta keywords
$need_tran = [];
//处理图片alt
$images = $dom->find("img");
foreach ($images as $img){
$alt = $img->alt;
if($alt){
$need_tran[] = $alt;
}
}
//处理a标签title
$aTitles = $dom->find("a");
foreach ($aTitles as $aTitle){
$title = $aTitle->title;
if($title){
$need_tran[] = $title;
}
}
foreach ($texts as $k=>$text) {
$tag= $text->parent()->tag;
if (in_array($tag, ['script', 'style', 'root']))
continue;
$string = trim($text->text());
if (empty($string))
continue;
$country_class = '';
if (method_exists($text->parent()->parent(),"find") && $text->parent()->parent()->find("b")) {
$country_class = $text->parent()->parent()->find("b",0)->class;
}
if(FALSE !== strpos($country_class, 'country-flag'))
continue;
$need_tran[] = htmlspecialchars_decode(html_entity_decode($string));
}
if (isset($description->attr['content'])){
$need_tran[] = $description->attr['content'];
}
if (isset($keywords->attr['content'])){
$need_tran[] = $keywords->attr['content'];
}
// 翻译内容字符串, 最多翻译三次, 超过三次没有结果, 返回原文
$tran_string = [];
if ($need_tran) {
$i = 0;
$tl_tran = $tl == "zh-ct" ? "zh-TW" : $tl;
TranslateArray:
$tran_result = Translate::translate($need_tran, $tl_tran, $sl);
if (!isset($tran_result[0]) || empty($tran_result[0]['code'] || $tran_result[0]['code'] != 200)) {
if ($i >= 3)
return $html;
$i++;
goto TranslateArray;
}
$tran_string = $tran_result[0]['texts'];
}
//组装路由
$page = $page == null || $page == 1 ? "" : "/".$page;
$route = $this->compactUrl($project,$route,$page);
$url = $route.$page;
//图片翻译校对数据
$webImageTranslate = WebTranslate::where("alias",$tl)->where("url",$url)->where("type",WebTranslate::$imageType)->first();
$webImageAllTranslate = WebTranslate::where("alias",$tl)->where("url","All")->where("type",WebTranslate::$imageType)->first();
$imageAllData = !empty($webImageAllTranslate) ? json_decode($webImageAllTranslate->data,true) : [];
$imageSelfData = !empty($webImageTranslate) ? json_decode($webImageTranslate->data,true) : [];
$imageData = array_merge($imageAllData,$imageSelfData);
//文本翻译校对数据
$webTextTranslate = WebTranslate::where("alias",$tl)->where("url",$url)->where("type",WebTranslate::$textType)->first();
$webTextAllTranslate = WebTranslate::where("alias",$tl)->where("url","All")->where("type",WebTranslate::$textType)->first();
$textAllData = !empty($webTextAllTranslate) ? json_decode($webTextAllTranslate->data,true) : [];
$textSelfData = !empty($webTextTranslate) ? json_decode($webTextTranslate->data,true) : [];
$textData = array_merge($textSelfData, $textAllData);
// 图片按照节点还原
$tmp = [];
foreach ($images as $img){
$alt = $img->alt;
if($alt){
$tmp[] = $alt;
$key = count($tmp) - 1;
if (!empty($imageData) && isset($imageData[$alt])){
$img->attr['alt'] = $imageData[$alt];
}else{
$img->attr['alt'] = $tran_string[$key];
}
}
}
foreach ($aTitles as $aTitle){
$title = $aTitle->title;
if($title){
$tmp[] = $title;
$key = count($tmp) - 1;
if (!empty($textData) && isset($textData[$title])){
$aTitle->attr['title'] = $textData[$title];
}else{
$aTitle->attr['title'] = $tran_string[$key];
}
}
}
foreach ($texts as $text) {
$tag= $text->parent()->tag;
if (in_array($tag, ['script', 'style', 'root']))
continue;
$string = trim($text->text());
if (empty($string))
continue;
$country_class = '';
if (method_exists($text->parent()->parent(),"find") && $text->parent()->parent()->find("b")) {
$country_class = $text->parent()->parent()->find("b",0)->class;
}
if(FALSE !== strpos($country_class, 'country-flag'))
continue;
$tmp[] = htmlspecialchars_decode(html_entity_decode($string));
// FIXME 查找校对内容中是否有当前值 优先使用校对内容,没有获取翻译内容
$key = count($tmp) - 1;
// dump($string);
$string = html_entity_decode($string);
if (!empty($textData) && isset($textData[$string])){
// dump("数据库:".$textData[$string]);
$text->outertext = $textData[$string];
}else{
// dump("翻译:".$tran_string[$key]);
$text->outertext = $tran_string[$key];
}
}
// 按照节点还原 description、keywords
$tmp[] = $description;
$key = count($tmp) - 1;
if (isset($description->attr['content'])){
$dom->find("meta[name=description]")[0]->attr['content'] = $tran_string[$key];
}
$tmp[] = $keywords;
$key = count($tmp) - 1;
if (isset($description->attr['keywords'])){
$dom->find("meta[name=keywords]")[0]->attr['content'] = $tran_string[$key];
}
// 保存修改 清除缓存
$html_string = $dom->save();
$dom->clear();
return $html_string;
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2024/1/6
* Time: 14:00
*/
namespace App\Repositories;
use App\Models\SyncSubmitTask\SyncSubmitTask;
use App\Models\Visit\Visit;
/**
* Class SyncSubmitRepository
* @package App\Repositories
*/
class SyncSubmitRepository
{
/**
* 上线站点引流
* @param $ip
* @param $url
* @param $user_agent
* @param string $referrer_url
* @param int $device_port
* @param int $traffic
* @return bool
*/
public function trafficVisit($ip, $url, $user_agent, $referrer_url = '', $device_port = Visit::DEVICE_PC, $traffic = SyncSubmitTask::TRAFFIC_DEFAULT)
{
if (empty($ip) || $ip == '127.0.0.1')
return false;
if ($this->isBot($user_agent))
return false;
$url_array = parse_url($url);
if (empty($url_array['host']))
return false;
// 检查重置来源URL
$referrer_url = $this->initReferrer($referrer_url);
// 头信息中带有这些信息, 代表是手机端, 重置设备类型
if (preg_match('/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile|wap|windowsce|ucweb/', $user_agent)) {
$device_port = 2;
}
// 组装字段数据
$array = [
'ip' => $ip,
'domain' => $url_array['host'],
'referer' => $referrer_url,
'user_agent' => $user_agent,
'data' => [
'url' => $url,
'domain' => $url_array['scheme'] . '://' . $url_array['host'],
'device_port' => in_array($device_port, array_keys(Visit::deviceMap())) ? $device_port : Visit::DEVICE_PC,
'referrer_url' => $referrer_url
]
];
SyncSubmitTask::createTask($array, SyncSubmitTask::TYPE_VISIT, $traffic);
return true;
}
/**
* 通过头信息,判断是否是蜘蛛爬虫
* @param $agent
* @return bool
*/
public function isBot($agent)
{
$spiderSite= ["TencentTraveler", "Baiduspider+", "BaiduGame", "Googlebot", "msnbot", "Sosospider+", "Sogou web spider", "ia_archiver", "Yahoo! Slurp", "YoudaoBot",
"Yahoo Slurp", "MSNBot", "Java (Often spam bot)", "BaiDuSpider", "Voila", "Yandex bot", "BSpider", "twiceler", "Sogou Spider", "Speedy Spider", "Google AdSense",
"Heritrix", "Python-urllib", "Alexa (IA Archiver)", "Ask", "Exabot", "Custo", "OutfoxBot/YodaoBot", "yacy", "SurveyBot", "legs", "lwp-trivial", "Nutch", "StackRambler",
"The web archive (IA Archiver)", "Perl tool", "MJ12bot", "Netcraft", "MSIECrawler", "WGet tools", "larbin", "Fish search", "yandex.com/bots", "google.com/bot",
"bingbot", "YandexMobileBot", "BingPreview", "AhrefsBot", "bot"
];
foreach($spiderSite as $val) {
$str = strtolower($val);
if (strpos($agent, $str) !== false) {
return true;
}
}
return false;
}
/**
* 按照规则重置referrer信息
* TODO 如果来自特定网站的原样返回, 其他的重置到google
* @param $referrer
* @return string
*/
public function initReferrer($referrer)
{
if (empty($referrer))
return '';
if (preg_match('/google|facebook|bing|yahoo|youtobe|linkedin|messefrankfurt|yandex|tiktok|twitter|instagram|reddit|telegram|pinterest|tumblr/', $referrer)) {
return $referrer;
}else{
return 'https://www.google.com/';
}
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/10/26
* Time: 13:55
*/
namespace App\Repositories;
/**
* Class ToolRepository
* @package App\Repositories
*/
class ToolRepository
{
/**
* @param $url
* @param $data
* @param string $method
* @param array $header
* @param int $time_out
* @return array
*/
public function curlRequest($url, $data, $method = 'POST', $header = [], $time_out = 60)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, $time_out);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
if ($data)
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge([
'Expect:',
'Content-type: application/json',
'Accept: application/json',
], $header)
);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [$code, $response];
}
/**
* 多请求批处理
* @param $host
* @param $request_urls
* @return array
*/
public function batCurlblobr($request_urls)
{
// //脚本开始的毫秒时刻
// $start = microtime(true);
//打开一个curl批处理句柄
$mh = curl_multi_init();
$headers = [
"X-BLOBR-KEY:" . $this->key
];
$ch = [];
foreach ($request_urls as $key => $url) {
//初始化cURL会话
$ch[$key] = curl_init($url);
//设置curl传输选项
curl_setopt($ch[$key], CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch[$key], CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch[$key], CURLOPT_ENCODING, "");
curl_setopt($ch[$key], CURLOPT_MAXREDIRS, 10);
// curl_setopt($ch[$key], CURLOPT_TIMEOUT, $this->time_out);
curl_setopt($ch[$key], CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch[$key], CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch[$key], CURLOPT_HTTPHEADER, $headers);
// curl_setopt($ch[$key], CURLOPT_HEADER, 0);
//关闭https请求验证
// if (strpos($url,'https')){
// curl_setopt ( $ch[$key], CURLOPT_SSL_VERIFYPEER, false );
// curl_setopt ( $ch[$key], CURLOPT_SSL_VERIFYHOST, 2 );
// }
//向批处理句柄中添加单独的curl句柄
curl_multi_add_handle($mh, $ch[$key]);
}
$running = null;
//执行批处理句柄
do {
$mrc = curl_multi_exec($mh, $running);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($running && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $running);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
$res = [];
//获取内容
foreach ($request_urls as $k => $url) {
//关闭执行完的子句柄
curl_multi_remove_handle($mh, $ch[$k]);
//返回获取的输出文本流
$res[$k] = curl_multi_getcontent($ch[$k]);
}
//5.关闭父curl
curl_multi_close($mh);
// $end = microtime(true) - $start;
// file_put_contents(__DIR__ . '/exec_time.log', $end . PHP_EOL, FILE_APPEND);
return $res;
}
/**
* 多请求批处理
* @param $headers
* @param $request_urls
* @return array
*/
public function batCurl($request_urls, $headers = [])
{
// //脚本开始的毫秒时刻
// $start = microtime(true);
//打开一个curl批处理句柄
$mh = curl_multi_init();
$ch = [];
foreach ($request_urls as $key => $url) {
//初始化cURL会话
$ch[$key] = curl_init($url);
//设置curl传输选项
curl_setopt($ch[$key], CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch[$key], CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch[$key], CURLOPT_ENCODING, "");
curl_setopt($ch[$key], CURLOPT_MAXREDIRS, 10);
curl_setopt($ch[$key], CURLOPT_TIMEOUT, 30);
curl_setopt($ch[$key], CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch[$key], CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch[$key], CURLOPT_HTTPHEADER, $headers);
// curl_setopt($ch[$key], CURLOPT_HEADER, 0);
//关闭https请求验证
// if (strpos($url,'https')){
// curl_setopt ( $ch[$key], CURLOPT_SSL_VERIFYPEER, false );
// curl_setopt ( $ch[$key], CURLOPT_SSL_VERIFYHOST, 2 );
// }
//向批处理句柄中添加单独的curl句柄
curl_multi_add_handle($mh, $ch[$key]);
}
$running = null;
//执行批处理句柄
do {
$mrc = curl_multi_exec($mh, $running);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($running && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $running);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
$res = [];
//获取内容
foreach ($request_urls as $k => $url) {
//关闭执行完的子句柄
curl_multi_remove_handle($mh, $ch[$k]);
//返回获取的输出文本流
$res[$k] = curl_multi_getcontent($ch[$k]);
}
//5.关闭父curl
curl_multi_close($mh);
// $end = microtime(true) - $start;
// file_put_contents(__DIR__ . '/exec_time.log', $end . PHP_EOL, FILE_APPEND);
return $res;
}
/**
* 替换特殊词汇
* @param $data
* @return array
*/
public function filterString($data)
{
if (is_array($data)) {
foreach ($data as $key => $val) {
$data[$key] = $this->filterString($val);
}
} else {
$data = ' ' . $data;
$array = "/\(\w.*\)| company| Company| inc| Inc| Co| co| Ltd| ltd| Llc| llc| Import And Export| Limited| limited|,|\./";
$result = preg_replace($array, '', $data);
return $result == ' ' ? '' : $result;
}
return $data;
}
}
... ...
<?php
namespace App\Services\Html;
use App\Models\Blog\Blog;
use App\Models\News\News;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Models\WebSetting\SettingNum;
use App\Models\WebSetting\WebSetting;
use App\Models\WebSetting\WebSettingAmp;
use App\Models\WebSetting\WebSettingSeo;
class AmpService
{
/**
* 获取首页html
* @param $project
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
* @author Akun
* @date 2024/03/14 15:04
*/
public static function getIndexHtml($project)
{
//站点配置
$project_config = self::getProjectConfig($project->id);
//产品所有分类
$category = self::getProductsCategory($project->id);
//排序最前的3个产品
$products = self::getProductsList($project->id, 1, 3)['data'];
//排序最前的3篇新闻
$news = self::getNewsBlogList($project->id, 1, 1, 3)['data'];
//排序最前的3篇博客
$blogs = AmpService::getNewsBlogList($project->id, 2, 1, 3)['data'];
//当前页面地址
$current_url = self::getCurrentUrl($project->domain);
return view('amp/index', compact('project_config', 'category', 'products', 'news', 'blogs', 'current_url'));
}
/**
* 获取路由页html
* @param $project
* @param $route
* @param $source
* @param $page
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
* @author Akun
* @date 2024/03/14 15:05
*/
public static function getHtmlByRoute($project, $route, $source, $page)
{
//站点配置
$project_config = self::getProjectConfig($project->id);
//产品所有分类
$category = self::getProductsCategory($project->id);
//固定菜单页面
if ($route == '404') {
//404页面
$current_url = self::getCurrentUrl($project->domain, '/404/');
return view('amp/404', compact('project_config', 'category', 'current_url'));
} elseif ($route == 'contact-us') {
//contact-us页面
$current_url = self::getCurrentUrl($project->domain, '/contact-us/');
return view('amp/contact', compact('project_config', 'category', 'current_url'));
} elseif ($route == 'about-us') {
//about-us页面
$current_url = self::getCurrentUrl($project->domain, '/aboout-us/');
return view('amp/about', compact('project_config', 'category', 'current_url'));
} elseif ($route == 'products') {
//产品列表
$products = self::getProductsList($project->id, $page, 8);
//当前分类详情
$category_info = self::getCategoryInfo($project->id, 0);
$current_url = self::getCurrentUrl($project->domain, '/' . $category_info['route'] . '/' . ($page > 1 ? $page . '/' : ''));
return view('amp/products', compact('project_config', 'category', 'products', 'category_info', 'page', 'current_url'));
} elseif ($route == 'news') {
//新闻列表
$news = self::getNewsBlogList($project->id, 1, $page, 5);
$current_url = self::getCurrentUrl($project->domain, '/news/' . ($page > 1 ? $page . '/' : ''));
return view('amp/news', compact('project_config', 'category', 'news', 'page', 'current_url'));
} elseif ($route == 'blog') {
//博客列表
$blogs = self::getNewsBlogList($project->id, 2, $page, 5);
$current_url = self::getCurrentUrl($project->domain, '/blog/' . ($page > 1 ? $page . '/' : ''));
return view('amp/blogs', compact('project_config', 'category', 'blogs', 'page', 'current_url'));
} elseif (strpos($route, 'top-search') !== false) {
//top-search页面
$pageService = new PageService();
$search_list = $pageService->getProductKeywordsByLetter($project, $route, $page);
//处理路由后缀为-tag的关键词
foreach ($search_list['pageInfo']['pageListData'] as &$v) {
if (substr($v['route'], -4, 4) == '-tag') {
$v['route'] = substr($v['route'], 0, -4);
}
}
//俄语站没有首字母筛选
if ($project->serve_id == 3) {
$search_list['keywordsLabel'] = [];
}
$total_page = count($search_list['pageInfo']['pageNum']);
$search_list['pageInfo']['center_pages'] = page_init($page, $total_page);
$search_list['pageInfo']['prev'] = max($page - 1, 1);
$search_list['pageInfo']['next'] = min($page + 1, $total_page);
$current_url = self::getCurrentUrl($project->domain, '/' . $route . '/' . ($page > 1 ? $page . '/' : ''));
return view('amp/top_search', compact('project_config', 'category', 'search_list', 'page', 'route', 'current_url'));
} else {
//剩下的页面:产品分类,产品详情,新闻详情,关键词详情
$map = ['route' => $route];
if ($source) {
$map['source'] = $source;
}
$route_info = RouteMap::where($map)->orderByRaw("FIELD(source, 'product_category','product','news','blog','product_keyword')")->first();
if (!$route_info) {
//特殊情况:关键词后缀为-tag
$map['route'] = $route . '-tag';
$map['source'] = 'product_keyword';
$route_info = RouteMap::where($map)->first();
}
if (!$route_info) {
$current_url = self::getCurrentUrl($project->domain, '/404/');
return view('amp/404', compact('project_config', 'category', 'current_url'));
}
switch ($route_info->source) {
case 'product_category':
//产品列表
$products = self::getProductsList($project->id, $page, 8, $route_info->source_id);
//当前分类详情
$category_info = self::getCategoryInfo($project->id, $route_info->source_id);
$current_url = self::getCurrentUrl($project->domain, '/' . $category_info['route'] . '/' . ($page > 1 ? $page . '/' : ''));
return view('amp/products', compact('project_config', 'category', 'products', 'category_info', 'page', 'current_url'));
case 'product':
//获取产品详情
$product_info = self::getProductInfo($project->id, $route_info->source_id);
//获取关联产品
$relate_products = self::getRelateProducts($project->id, $product_info['id'], $product_info['category_id'], 8);
$current_url = self::getCurrentUrl($project->domain, '/' . $product_info['route'] . '/');
return view('amp/product_info', compact('project_config', 'category', 'product_info', 'relate_products', 'current_url'));
case 'news':
//新闻详情
$news_info = self::getNewsBlogInfo($project->id, 1, $route_info->source_id);
$current_url = self::getCurrentUrl($project->domain, '/news/' . $news_info['url'] . '/');
return view('amp/news_info', compact('project_config', 'category', 'news_info', 'current_url'));
case 'blog':
//博客详情
$blog_info = self::getNewsBlogInfo($project->id, 2, $route_info->source_id);
$current_url = self::getCurrentUrl($project->domain, '/blog/' . $blog_info['url'] . '/');
return view('amp/blog_info', compact('project_config', 'category', 'blog_info', 'current_url'));
case 'product_keyword':
//获取关键词详情
$tag_info = self::getTagInfo($project->id, $route_info->source_id);
//获取关联产品和热门产品
$pageService = new PageService();
$products = $pageService->getRecommendAndHotProducts($project, $tag_info['route']) ?: [];
//获取关联新闻
$news = self::getNewsBlogList($project->id, 1, 1, 2)['data'];
//随机获取关键词列表
$relate_tags = self::getRelateTags($project->id);
$current_url = self::getCurrentUrl($project->domain, '/' . $tag_info['route'] . '/');
return view('amp/tag', compact('project_config', 'category', 'tag_info', 'products', 'news', 'relate_tags', 'current_url'));
default:
$current_url = self::getCurrentUrl($project->domain, '/404/');
return view('amp/404', compact('project_config', 'category', 'current_url'));
}
}
}
/**
* 拼接当前页面完整路径
* @param $domain
* @param $path
* @return string
* @author Akun
* @date 2024/03/15 15:48
*/
public static function getCurrentUrl($domain, $path = '')
{
$host_array = explode('.', $domain);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
$host_array[0] = 'm';
}
$amp_domain = implode('.', $host_array);
return 'https://' . $amp_domain . $path;
}
/**
* 获取站点amp配置
* @param $project_id
* @return mixed
* @author Akun
* @date 2024/01/26 16:07
*/
public static function getProjectConfig($project_id)
{
$config_amp = WebSettingAmp::where('project_id', $project_id)->first();
$config_index = WebSetting::where('project_id', $project_id)->first();
$config_seo = WebSettingSeo::where('project_id', $project_id)->first();
$show_news = News::where('project_id', $project_id)->where('status', 1)->count('id');
$show_blogs = Blog::where('project_id', $project_id)->where('status', 1)->count('id');
return [
'show_news' => $show_news,
'show_blogs' => $show_blogs,
'top_backgroundcolor' => $config_amp->top_backgroundcolor ?? '',
'web_icon' => $config_amp->web_icon ?? '',
'top_logo' => $config_amp->top_logo ?? [],
'index_banner' => $config_amp->index_banner ?? [],
'index_intro' => $config_amp->index_intro ?? '',
'company_image' => $config_amp->company_image ?? [],
'company_about' => $config_amp->company_about ?? '',
'company_email' => $config_amp->company_email ?? '',
'company_address' => $config_amp->company_address ?? '',
'company_tel' => $config_amp->company_tel ?? '',
'third_code' => $config_amp->third_code ?? '',
'index_title' => $config_index->title ?? '',
'index_description' => $config_index->remark ?? '',
'index_keywords' => $config_index->keyword ?? '',
'single_page_suffix' => $config_seo->single_page_suffix ?? '',
'tab_suffix' => $config_seo->tab_suffix ?? '',
'tab_prefix' => $config_seo->tab_prefix ?? '',
'product_cate_suffix' => $config_seo->product_cate_suffix ?? '',
'product_cate_prefix' => $config_seo->product_cate_prefix ?? '',
'product_suffix' => $config_seo->product_suffix ?? '',
'product_prefix' => $config_seo->product_prefix ?? '',
];
}
/**
* 获取分类列表
* @param $project_id
* @return array
* @author Akun
* @date 2024/01/29 11:25
*/
public static function getProductsCategory($project_id)
{
$category = [];
$result = Category::where('project_id', $project_id)->where('title', '!=', 'Featured Products')->where('status', 1)->orderBy("sort", "desc")->orderBy("id", "desc")->get();
if ($result->count() > 0) {
$result_tree = list_to_tree($result->toArray());
foreach ($result_tree as $cate) {
if ($cate['title'] == 'Products' || $cate['title'] == 'products') {
foreach ($cate['_child'] as $child) {
$category[] = $child;
}
} else {
$category[] = $cate;
}
}
}
return $category;
}
/**
* 获取分类详情
* @param $project_id
* @param $category_id
* @return array
* @author Akun
* @date 2024/01/29 11:31
*/
public static function getCategoryInfo($project_id, $category_id)
{
if ($category_id > 0) {
$category_info = Category::where('project_id', $project_id)->where('id', $category_id)->first();
} else {
$category_info = Category::where('project_id', $project_id)->whereIn('title', ['Products', 'products'])->first();
if ($category_info) {
$category_info->id = 0;
} else {
return [
'id' => 0,
'route' => 'products',
'title' => 'Products',
'keywords' => '',
'describe' => '',
'seo_title' => '',
'seo_keywords' => '',
'seo_description' => '',
];
}
}
return [
'id' => $category_info->id ?? 0,
'route' => $category_info->route ?? '',
'title' => $category_info->title ?? '',
'keywords' => $category_info->keywords ?? '',
'describe' => $category_info->describe ?? '',
'seo_title' => $category_info->seo_title ?? '',
'seo_keywords' => $category_info->seo_keywords ?? '',
'seo_description' => $category_info->seo_des ?? '',
];
}
/**
* 根据分类id获取产品id
* @param $category_id
* @return mixed
* @author Akun
* @date 2024/01/29 11:26
*/
public static function getProductIdByCategory($category_id)
{
return CategoryRelated::where('cate_id', $category_id)->pluck('product_id')->toArray();
}
/**
* 获取产品列表
* @param int $project_id
* @param int $page
* @param int $limit
* @param int $category_id
* @param string $search
* @return array
* @author Akun
* @date 2024/01/26 16:07
*/
public static function getProductsList($project_id, $page = 1, $limit = 20, $category_id = 0, $search = '')
{
$total_page = 0;
$products = [];
$model = Product::where('project_id', $project_id)->where('status', 1);
//根据分类id获取关联的产品id
if ($category_id > 0) {
$product_ids = self::getProductIdByCategory($category_id);
if ($product_ids) {
$model = $model->whereIn('id', $product_ids);
}
} else {
//获取所有产品需要排除掉Featured Products分类
$fp_cate_id = Category::where('title', 'Featured Products')->value('id');
$model->where('category_id', '!=', ',' . $fp_cate_id . ',');
}
//搜索条件
if ($search) {
if (strpos($search, '\\') !== false) {
$search = str_replace('\\', '\\\\', $search);
}
$model = $model->where('title', 'like', "%$search%");
}
$count = $model->count('id');
if ($count > 0) {
$total_page = (int)ceil($count / $limit);
//获取产品自定义排序规则
$sort_rule = self::getProductSortRule($project_id);
foreach ($sort_rule as $rk => $rv) {
$model = $model->orderBy($rk, $rv);
}
$result = $model->select(['id', 'title', 'thumb', 'intro', 'content', 'route'])->offset(($page - 1) * $limit)->limit($limit)->get();
if ($result->count() > 0) {
foreach ($result as $value) {
$thumb = [];
if ($value->thumb) {
$thumb_arr = json_decode($value->thumb, true);
$thumb = [
'alt' => (isset($thumb_arr['alt']) && $thumb_arr['alt']) ? $thumb_arr['alt'] : $value->title,
'url' => getImageUrl($thumb_arr['url'] ?? '')
];
}
$intro = $value->intro ?: $value->content;
$intro = strip_tags(special2str($intro));
$products[] = [
'id' => $value->id,
'title' => $value->title,
'thumb' => $thumb,
'route' => $value->route,
'intro' => strlen($intro) > 200 ? substr($intro, 0, 200) . '...' : $intro,
];
}
}
}
$pre = max($page - 1, 1);
$next = min($page + 1, $total_page);
$center_pages = page_init($page, $total_page);
return ['data' => $products, 'total_page' => $total_page, 'prev' => $pre, 'next' => $next, 'center_pages' => $center_pages];
}
/**
* 获取产品自定义排序规则
* @param $project_id
* @return array|string[]
* @author Akun
* @date 2024/03/21 11:13
*/
public static function getProductSortRule($project_id)
{
$order_list = [];
$orderDataFirst = SettingNum::where('project_id', $project_id)->where('type', 10)->first();
if ($orderDataFirst && $orderDataFirst->data) {
$orderData = json_decode($orderDataFirst->data, true);
foreach ($orderData as $key => $orderDataItem) {
$orderKey = $key == "created_at" ? "send_time" : $key;
$order_list[$orderKey] = $orderDataItem;
if ($key != "id") {
$order_list['id'] = 'desc';
}
}
} else {
$order_list = [
'sort' => 'desc',
'id' => 'desc'
];
}
return $order_list;
}
/**
* 获取产品详情
* @param $project_id
* @param $id
* @return array
* @author Akun
* @date 2024/01/30 9:22
*/
public static function getProductInfo($project_id, $id)
{
$gallery = [];
$seo = [
'title' => '',
'keywords' => '',
'description' => ''
];
$product_info = Product::where('project_id', $project_id)->where('status', 1)->where('id', $id)->first();
if ($product_info) {
if ($product_info->gallery) {
$gallery_arr = json_decode($product_info->gallery, true);
foreach ($gallery_arr as $vg) {
$gallery[] = [
'alt' => (isset($vg['alt']) && $vg['alt']) ? $vg['alt'] : $product_info->title,
'url' => getImageUrl($vg['url'] ?? '')
];
}
}
if ($product_info->seo_mate) {
$seo_arr = json_decode($product_info->seo_mate, true);
$seo['title'] = $seo_arr['title'] ?? '';
$seo['keywords'] = $seo_arr['keywords'] ?? '';
$seo['description'] = $seo_arr['description'] ?? '';
}
}
return [
'id' => $product_info->id ?? 0,
'route' => $product_info->route ?? '',
'gallery' => $gallery,
'title' => $product_info->title ?? '',
'intro' => $product_info->intro ?? '',
'content' => $product_info->content ?? '',
'seo' => $seo,
'category_id' => $product_info->category_id ?? ''
];
}
/**
* 获取关联产品
* @param $project_id
* @param $id
* @param $category_id
* @param $limit
* @return array
* @author Akun
* @date 2024/01/30 9:34
*/
public static function getRelateProducts($project_id, $id, $category_id, $limit = 2)
{
if (is_string($category_id)) {
$category_id = explode(',', $category_id);
}
$relate_ids = CategoryRelated::whereIn('cate_id', $category_id)->where('product_id', '!=', $id)->limit($limit)->pluck('product_id')->toArray();
$relate_products = [];
if ($relate_ids) {
$result = Product::where('project_id', $project_id)->whereIn('id', $relate_ids)->where('status', 1)->orderBy('sort', 'desc')->limit(8)->get();
if ($result->count() == 0) {
$result = Product::where('project_id', $project_id)->where('status', 1)->inRandomOrder()->take(8)->get();
}
if ($result->count() > 0) {
foreach ($result as $value) {
$thumb = '';
if ($value->thumb) {
$thumb_arr = json_decode($value->thumb, true);
$thumb = [
'alt' => (isset($thumb_arr['alt']) && $thumb_arr['alt']) ? $thumb_arr['alt'] : $value->title,
'url' => getImageUrl($thumb_arr['url'] ?? '')
];
}
$relate_products[] = [
'id' => $value->id,
'route' => $value->route,
'title' => $value->title,
'thumb' => $thumb
];
}
}
}
return $relate_products;
}
/**
* 获取新闻博客列表
* @param $project_id
* @param int $type
* @param int $page
* @param int $limit
* @return array
* @author Akun
* @date 2024/01/26 16:38
*/
public static function getNewsBlogList($project_id, $type = 1, $page = 1, $limit = 10)
{
$total_page = 0;
$news = [];
if ($type == 1) {
$model = new News();
} else {
$model = new Blog();
}
$count = $model->where('project_id', $project_id)->where('status', 1)->count('id');
if ($count > 0) {
$total_page = (int)ceil($count / $limit);
$result = $model->select(['id', 'name', 'image', 'remark', 'text', 'release_at', 'created_at', 'url'])->where('project_id', $project_id)->where('status', 1)->orderBy('sort', 'desc')->orderBy('id', 'desc')->offset(($page - 1) * $limit)->limit($limit)->get();
if ($result->count() > 0) {
foreach ($result as $value) {
$remark = $value->remark ?: $value->text;
$remark = strip_tags(special2str($remark));
$news[] = [
'type' => $type,
'id' => $value->id,
'name' => $value->name,
'url' => $value->url,
'image' => getImageUrl($value->image),
'remark' => strlen($remark) > 200 ? substr($remark, 0, 200) . '...' : $remark,
'release_at' => $value->release_at ? $value->release_at : $value->created_at
];
}
}
}
$pre = max($page - 1, 1);
$next = min($page + 1, $total_page);
$center_pages = page_init($page, $total_page);
return ['data' => $news, 'total_page' => $total_page, 'prev' => $pre, 'next' => $next, 'center_pages' => $center_pages];
}
/**
* 获取新闻博客详情
* @param $project_id
* @param $type
* @param $id
* @return array
* @author Akun
* @date 2024/01/30 11:17
*/
public static function getNewsBlogInfo($project_id, $type, $id)
{
if ($type == 1) {
$model = new News();
} else {
$model = new Blog();
}
$news_info = $model->where('project_id', $project_id)->where('status', 1)->where('id', $id)->first();
$release_at = '';
if (isset($news_info->release_at) && $news_info->release_at) {
$release_at = $news_info->release_at;
} elseif (isset($news_info->created_at) && $news_info->created_at) {
$release_at = $news_info->created_at;
}
return [
'id' => $news_info->id ?? 0,
'name' => $news_info->name ?? '',
'sort' => $news_info->sort ?? 0,
'url' => $news_info->url ?? 0,
'text' => $news_info->text ?? '',
'image' => getImageUrl($news_info->image ?? ''),
'seo_title' => $news_info->seo_title ?? '',
'seo_keywords' => $news_info->seo_keywords ?? '',
'seo_description' => $news_info->seo_description ?? '',
'release_at' => $release_at
];
}
/**
* 获取关键词详情
* @param $project_id
* @param $id
* @return array
* @author Akun
* @date 2024/01/30 16:17
*/
public static function getTagInfo($project_id, $id)
{
$tag_info = Keyword::where('project_id', $project_id)->where('status', 1)->where('id', $id)->first();
return [
'id' => $tag_info->id ?? 0,
'route' => $tag_info->route ?? '',
'title' => $tag_info->title ?? '',
'keyword_title' => $tag_info->keyword_title ?? '',
'keyword_content' => $tag_info->keyword_content ?? '',
'seo_title' => $tag_info->seo_title ?? '',
'seo_keywords' => $tag_info->seo_keywords ?? '',
'seo_description' => $tag_info->seo_description ?? '',
];
}
/**
* 获取关联关键词
* @param $project_id
* @return mixed
* @author Akun
* @date 2024/01/30 18:30
*/
public static function getRelateTags($project_id)
{
return Keyword::select(['id', 'title', 'route'])->where('project_id', $project_id)->where('status', 1)->inRandomOrder()->take(10)->get()->toArray();
}
}
... ...
<?php
namespace App\Services\Html;
use App\Helper\Translate;
use App\Models\Com\UpdateProgress;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\DomainInfo;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\WebSetting\Proofreading;
use App\Models\WebSetting\WebLanguage;
use App\Models\WebSetting\WebProofreading;
use App\Models\WebSetting\WebSetting;
use App\Models\WebSetting\WebSettingCountry;
use App\Models\WebSetting\WebSettingHtml;
use App\Models\WebSetting\WebSettingText;
use App\Models\WebSetting\WebTemplateCommon;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\Redis;
use phpQuery;
/**
* 生成静态页相关
*/
class CommonService
{
/**
* 翻译
*/
public function webHtmlTranslate($project,$content, $lang,$domain)
{
//翻译过滤器
$lang = $lang == "zh-ct" ? "zh-TW" : $lang;
$tlsList = Translate::$tls_list;
if (isset($tlsList[$lang])){
$main_lang = $project->main_lang_id;
$mainLangInfo = WebLanguage::getProjectMainLang($main_lang);
$master_lang = $mainLangInfo ? $mainLangInfo->short : 'en';
//翻译
if ($master_lang != 'en') {
$result = Translate::translate($content, $lang, $master_lang);
$content = $result[0]['texts'] ?? '';
} else {
$content = Translate::tran($content, $lang);
}
// 翻译有时会返回空数据 再翻译一次 FIXME 后续需要重新封装
if (empty($content)) {
$result = Translate::translate($content, $lang, $master_lang);
$content = $result[0]['texts'] ?? '';
}
//翻译校对
$content = $this->translationProofread($project,$content,$lang,$domain);
}
return $content;
}
/**
* 翻译校对
*/
public function translationProofread($project, $content, $lang,$domain)
{
$webProofreading = Proofreading::where("project_id",$project->id)->where("alias",$lang)->get();
if (!empty($webProofreading)){
foreach ($webProofreading as $item){
$content = str_ireplace($item->text,$item->translate,$content);
}
}
return $content;
}
/**
* 处理第三方代码
*/
public function thirdPartyCodeHandle($project,$content,$route,$routeMap=null): string
{
if (Redis::get("project_".$project->id."_third_party_code") != null){
$webSettingHtml = json_decode(Redis::get("project_".$project->id."_third_party_code"));
}else{
$webSettingHtml = WebSettingHtml::where("project_id",$project->id)->first();
Redis::set("project_".$project->id."_third_party_code", json_encode($webSettingHtml));
Redis::expire("project_".$project->id."_third_party_code", WebSetting::$redisExpireTime);
}
$phpQueryDom = phpQuery::newDocument($content);
//网站icon
$webIcon = WebSetting::where("project_id",$project->id)->first();
if (!empty($webIcon)){
$iconDom = $phpQueryDom->find("link[rel=icon]");
if (count($iconDom) >= 1){
if (isset($webIcon->web_site_icon) && !empty($webIcon->web_site_icon) && $webIcon->web_site_icon != "" && $webIcon->web_site_icon != 0){
$iconDom->attr("href",$webIcon->web_site_icon);
}else{
$iconDom->attr("href","");
}
}
}
//第三方代码(网页顶部,中间,底部),以后启用位置
if (!empty($webSettingHtml)) {
$phpQueryDom->find('head')->append($webSettingHtml->head_html?:'');
$phpQueryDom->find('body')->append($webSettingHtml->body_html?:'');
$phpQueryDom->find('html')->append($webSettingHtml->footer_html?:'');
}
//A端添加的网站追踪代码
$deployOptimize = DeployOptimize::where("project_id",$project->id)->first();
if (!empty($deployOptimize)){
if (isset($deployOptimize->meta) && !empty($deployOptimize->meta)){
$phpQueryDom->find('head')->append($deployOptimize->meta);
}
}
//首页头部独立样式
if ($route == "index"){
$phpQueryDom->find('header')->attr("headerprivate","");
}
//处理header顶部搜索跳转链接
$phpQueryDom->find('header form')->attr("action", "/search/");
//C端访问埋点
$isBodyEnd = $phpQueryDom->find('body')->eq(0);
if (count($isBodyEnd)>=1){
$phpQueryDom->find('body')->append("<script src='https://ecdn6.globalso.com/public/customerVisit.min.js'></script>");
}else{
$phpQueryDom->find('html')->append("<script src='https://ecdn6.globalso.com/public/customerVisit.min.js'></script>");
}
$data = date("Y-m-d H:i:s");
$phpQueryDom->find('html')->append("<!-- Globalso Cache file was created on ".$data." -->");
//这个功能其他类型页面移到面包屑导航处理
if ($route == "index" || (!empty($routeMap) && $routeMap->source == RouteMap::SOURCE_PAGE)){
$phpQueryDom->find('head')->append('<script>var currentPage = "'.$route.'"</script>');
}
if ($route == "search"){
//暂时先去掉小语种按钮显示
$phpQueryDom->find(".change-language")->remove();
$phpQueryDom->find('head')->append('<meta name="robots" content="noindex, nofollow"/>');
}
$phpQueryDom->find('body')->attr("unevents","");
$content = $phpQueryDom->htmlOuter();
unset($phpQueryDom);
phpQuery::unloadDocuments();
//处理全部内容,如果有上线正式域名,则把所有的测试域名替换为正式域名
$projectDomainInfo = DomainInfo::where("project_id",$project->id)->first();
if (!empty($projectDomainInfo)){
$deployBuild = DeployBuild::where("project_id",$project->id)->first();
if (!empty($deployBuild)){
$parsedUrl = parse_url($deployBuild->test_domain);
$domain = $projectDomainInfo->domain;
$testDomain = $parsedUrl['host'];
if ($domain != '' && $testDomain != ''){
$content = str_replace($testDomain,$domain,$content);
}
}
}
return $content;
}
/**
* 处理锚文本
*/
public function anchorTextHandle($project,$route,$content): string
{
$source = "";
//解析路由
if ($route != "index"){
$routerNewsMap = RouteMap::where("project_id",$project->id)->where("route",$route)->first();
if (!empty($routerNewsMap)){
$source = $routerNewsMap->source;
}
}else{
$source = "index";
}
//判断来源类型
switch ($source) {
case 'news_category' || 'news':
$num = 4;
break;
case 'product_category' || 'product':
$num = 2;
break;
case 'blog_category' || 'blog':
$num = 6;
break;
case 'page':
$num = 1;
break;
default:
$num = 1;
}
//网站设置锚文本
$webSetting = WebSetting::getWebSetting($project);
if (!empty($webSetting)){
$anchorIsEnable = $webSetting->anchor_is_enable;
if ($anchorIsEnable == 0){
$anchorSetting = $webSetting->anchor_setting;
$anchorSettingArr = explode(',', substr($anchorSetting, 1, -1));
foreach ($anchorSettingArr as $item){
$itemArr = explode('"', substr($item, 1, -1));
$tracingText[] = intval($itemArr[0]);
}
if (in_array($num, $tracingText)) {
$webSettingText = WebSettingText::getWebSettingText($project);
$phpQueryDom=phpQuery::newDocument($content);
$mainElement = $phpQueryDom->find('main');
$con = $mainElement->html();
if (!empty($webSettingText)){
foreach ($webSettingText as $v){
$con = str_replace( $v->key_words, '<a target="_blank" href="'. $v->url.'">'. $v->key_words.'</a>', $con);
}
}
$mainElement->html($con);
return $phpQueryDom->htmlOuter();
}
}
}
return $content;
}
/**
* 链接项目
*/
public function connectProject($updateData)
{
$project = null;
$projectIn = Project::getProjectByDomain($updateData->domain);
if (!empty($projectIn)){
$project = Project::where("id",$projectIn->project_id)->first();
if (!empty($project)){
$project->domain = $updateData->domain;
}
ProjectServer::useProject($project->id);
}
return $project;
}
/**
* 获取小语种更新国家
*/
public function getMinorLanguage($updateData)
{
$minorLanguage = [];
$updateProgressQuery = UpdateProgress::find($updateData->id);
if (!empty($updateProgressQuery)){
$extends = $updateProgressQuery->extends;
if (!empty($extends)){
$extends = json_decode($extends);
if (isset($extends->language) && !empty($extends->language)){
$language = $extends->language;
foreach ($language as $lang){
$minorLanguage[] = (int)$lang;
}
}
}
}
return WebSettingCountry::whereIn("id", $minorLanguage)->get();
}
}
... ...