|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Services\Html;
|
|
|
|
|
|
|
|
use App\Helper\Str;
|
|
|
|
use App\Models\Blog\Blog;
|
|
|
|
use App\Models\Module\Module;
|
|
|
|
use App\Models\Module\ModuleCategory;
|
|
|
|
use App\Models\News\News;
|
|
|
|
use App\Models\News\NewsCategory;
|
|
|
|
use App\Models\Product\Category;
|
|
|
|
use App\Models\Product\CategoryRelated;
|
|
|
|
use App\Models\Product\Keyword;
|
|
|
|
use App\Models\Product\Product;
|
|
|
|
use App\Models\Project\CollectTask;
|
|
|
|
use App\Models\Project\Country;
|
|
|
|
use App\Models\Project\CountryCustom;
|
|
|
|
use App\Models\Project\DeployBuild;
|
|
|
|
use App\Models\Project\DomainInfo;
|
|
|
|
use App\Models\Project\Notify;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Models\Project\UpdateHtmlModel;
|
|
|
|
use App\Models\Project\UpdateMasterWebsiteModel;
|
|
|
|
use App\Models\Project\UpdateMinorLanguagesModel;
|
|
|
|
use App\Models\Project\UpdateProgressModel;
|
|
|
|
use App\Models\RouteMap;
|
|
|
|
use App\Models\Template\BSetting;
|
|
|
|
use App\Models\WebSetting\WebCustom;
|
|
|
|
use App\Models\WebSetting\WebLanguage;
|
|
|
|
use App\Models\WebSetting\WebSettingNum;
|
|
|
|
use App\Models\WebSetting\WebTemplate;
|
|
|
|
use App\Models\WebSetting\WebTemplateCommon;
|
|
|
|
use App\Repositories\StaticHtmlRepository;
|
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
use phpQuery;
|
|
|
|
use stdClass;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* C端生成页面服务
|
|
|
|
*/
|
|
|
|
class CreatePageService{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取升级项目小语种采集的页面
|
|
|
|
* @param $project
|
|
|
|
* @param $route
|
|
|
|
* @param $source
|
|
|
|
* @param $lang
|
|
|
|
* @return string
|
|
|
|
* @author Akun
|
|
|
|
* @date 2024/01/08 11:40
|
|
|
|
*/
|
|
|
|
public function getMinorLanguagePage($project,$route,$source,$lang){
|
|
|
|
if($project['update_info']['is_language_update'] == 0){
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($source == 'news' || $source == 'blog' || $source == 'product' || $source == 'page' || $source == 'module'){
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("source",$source)->first();
|
|
|
|
}elseif($source == ''){
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->whereIn("source",["product","page","module"])->orderBy('source','desc')->first();
|
|
|
|
}else{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if($routerMap) {
|
|
|
|
switch ($routerMap->source) {
|
|
|
|
//产品详情
|
|
|
|
case WebTemplateCommon::$productName:
|
|
|
|
$detail = Product::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
|
|
|
|
break;
|
|
|
|
//博客详情
|
|
|
|
case WebTemplateCommon::$blogName:
|
|
|
|
$detail = Blog::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
|
|
|
|
break;
|
|
|
|
//新闻详情
|
|
|
|
case WebTemplateCommon::$newsName:
|
|
|
|
$detail = News::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
|
|
|
|
break;
|
|
|
|
//自定义模块详情
|
|
|
|
case WebTemplateCommon::$extendName:
|
|
|
|
$detail = Module::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//单页详情
|
|
|
|
$detail = WebCustom::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
|
|
|
|
}
|
|
|
|
if($detail && $detail->six_read){
|
|
|
|
return $this->getOldHtml($project,$routerMap,$project['update_info']['old_domain_test'],$project['update_info']['old_domain_online'],$lang);
|
|
|
|
}else{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据语言,路由,分页数,获取页面内容
|
|
|
|
*/
|
|
|
|
public function getPageByLangRoutePage($project,$route,$page=null,$source=""): string
|
|
|
|
{
|
|
|
|
$html = "";
|
|
|
|
$page = $page == null ? null : (int)$page;
|
|
|
|
$router = $route == "" ? "404" : $route;
|
|
|
|
|
|
|
|
$productKeywordRouter = new Keyword();
|
|
|
|
$productKeywordRouters = $productKeywordRouter->product_keyword_route;
|
|
|
|
if (in_array($router, $productKeywordRouters)) {
|
|
|
|
$html = $this->getProductKeywordListPage($project,$router,$page);
|
|
|
|
unset($productKeywordRouter);
|
|
|
|
} else {
|
|
|
|
//新增:products,news,blog 三个路由为C端固定路由,数据库路由表没有路由也可以访问或调数据
|
|
|
|
if ($router == "products" || $router == "news" || $router == "blog"){
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$router)->first();
|
|
|
|
$routerMapRegular = new stdClass();
|
|
|
|
if (empty($routerMap)){
|
|
|
|
if ($router == "products"){
|
|
|
|
$routerMapRegular->source = WebTemplateCommon::$productCategoryName;
|
|
|
|
$routerMapRegular->route = "products";
|
|
|
|
}
|
|
|
|
if ($router == "news"){
|
|
|
|
$routerMapRegular->source = WebTemplateCommon::$newsCategoryName;
|
|
|
|
$routerMapRegular->route = "news";
|
|
|
|
}
|
|
|
|
if ($router == "blog"){
|
|
|
|
$routerMapRegular->source = WebTemplateCommon::$blogCategoryName;
|
|
|
|
$routerMapRegular->route = "blog";
|
|
|
|
}
|
|
|
|
$routerMapRegular->source_id = 0;
|
|
|
|
$routerMapRegular->project_id = $project->id;
|
|
|
|
$routerMap = $routerMapRegular;
|
|
|
|
unset($routerMapRegular);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if ($project->update_info["is_update"] == 1){
|
|
|
|
if ($source != ""){
|
|
|
|
//$source可能值:news,blog,news_category,blog_category
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$router)->where("source",$source)->first();
|
|
|
|
}else{
|
|
|
|
//product_category,product,page,product_keyword,module_category,module
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$router)->whereIn("source",["product","product_category","page","module_category","module","product_keyword"])->orderByRaw("FIELD(source, 'product_category','product','module_category','module','page','product_keyword')")->first();
|
|
|
|
}
|
|
|
|
if (empty($routerMap)){
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$router)->first();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
//6.0
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$router)->first();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($routerMap)){
|
|
|
|
$type = $routerMap->source;
|
|
|
|
switch ($type) {
|
|
|
|
//产品详情
|
|
|
|
case WebTemplateCommon::$productName:
|
|
|
|
$html = $this->getProductPage($project,$routerMap);
|
|
|
|
break;
|
|
|
|
//产品列表
|
|
|
|
case WebTemplateCommon::$productCategoryName:
|
|
|
|
$html = $this->getProductListPage($project,$routerMap,$page);
|
|
|
|
break;
|
|
|
|
//博客详情
|
|
|
|
case WebTemplateCommon::$blogName:
|
|
|
|
$html = $this->getBlogPage($project,$routerMap);
|
|
|
|
break;
|
|
|
|
//博客列表
|
|
|
|
case WebTemplateCommon::$blogCategoryName:
|
|
|
|
$html = $this->getBlogListPage($project,$routerMap,$page);
|
|
|
|
break;
|
|
|
|
//新闻详情
|
|
|
|
case WebTemplateCommon::$newsName:
|
|
|
|
$html = $this->getNewsPage($project,$routerMap);
|
|
|
|
break;
|
|
|
|
//新闻列表
|
|
|
|
case WebTemplateCommon::$newsCategoryName:
|
|
|
|
$html = $this->getNewsListPage($project,$routerMap,$page);
|
|
|
|
break;
|
|
|
|
//自定义模块列表
|
|
|
|
case WebTemplateCommon::$extendCategoryName:
|
|
|
|
$html = $this->getModuleListPage($project,$routerMap,$page);
|
|
|
|
break;
|
|
|
|
//自定义模块详情
|
|
|
|
case WebTemplateCommon::$extendName:
|
|
|
|
$html = $this->getModulePage($project,$routerMap);
|
|
|
|
break;
|
|
|
|
//聚合页
|
|
|
|
case WebTemplateCommon::$productKeywordName:
|
|
|
|
$html = $this->getProductKeywordPage($project,$routerMap);
|
|
|
|
break;
|
|
|
|
case WebTemplateCommon::$pageName:
|
|
|
|
if ($router == WebTemplateCommon::$indexName){
|
|
|
|
//首页
|
|
|
|
$html = $this->getIndexPage($project,$routerMap);
|
|
|
|
}else{
|
|
|
|
//单页面
|
|
|
|
$html = $this->getSinglePage($project,$routerMap);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$html = $this->getSinglePage($project,$routerMap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取首页html
|
|
|
|
*/
|
|
|
|
public function getIndexPage($project,$routerMap): string
|
|
|
|
{
|
|
|
|
$pageService = new PageService();
|
|
|
|
$commonService = new CommonService();
|
|
|
|
$tdkService = new TdkService();
|
|
|
|
//首页模板
|
|
|
|
$info = BSetting::where("project_id",$project->id)->first();
|
|
|
|
if (empty($info)){
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
$webIndexTemplate = WebTemplate::where("project_id",$project->id)->where("template_id",$info->template_id)->where("source",1)->first();
|
|
|
|
if (!empty($webIndexTemplate)){
|
|
|
|
$html = $pageService->isAndGetVisualizationHtml($project,WebTemplateCommon::$indexName,$routerMap);
|
|
|
|
if ($html == ""){
|
|
|
|
//组装首页页面
|
|
|
|
$html = $pageService->assembleIndexPage($project,$webIndexTemplate);
|
|
|
|
}
|
|
|
|
|
|
|
|
// $filePath = public_path("6666.html");
|
|
|
|
// file_put_contents($filePath, $html);
|
|
|
|
// dd(5656);
|
|
|
|
//公共处理
|
|
|
|
$html = $pageService->publicHtmlHandle($html,$project->id);
|
|
|
|
$isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$indexName);
|
|
|
|
if ((int)$isVisual == 1 || $isVisual == null){
|
|
|
|
//产品,产品分类,新闻,博客(section模板通用数据模块处理)
|
|
|
|
$html = $pageService->generalTemplateProcessingForDataModules($html,$project->id);
|
|
|
|
}
|
|
|
|
//第三方
|
|
|
|
$html = $commonService->thirdPartyCodeHandle($project,$html,WebTemplateCommon::$indexName);
|
|
|
|
//TDK处理
|
|
|
|
$html = $tdkService->pageTdkHandle($project,$html,WebTemplateCommon::$indexName,$routerMap);
|
|
|
|
//特殊首页模块处理
|
|
|
|
// $html = $pageService->specialIndexModuleHandle($project,$html);
|
|
|
|
//处理URL等,处理html链接a标签href
|
|
|
|
if (!empty($html)){
|
|
|
|
return $this->pageUrlHandle($project,$routerMap,$html);
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取产品列表页html
|
|
|
|
*/
|
|
|
|
public function getProductListPage($project,$routerMap,$page): string
|
|
|
|
{
|
|
|
|
$pageService = new PageService();
|
|
|
|
$commonService = new CommonService();
|
|
|
|
$tdkService = new TdkService();
|
|
|
|
//公共拼接页面方法
|
|
|
|
$webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$productCategoryName,$routerMap);
|
|
|
|
//公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
|
|
|
|
$webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$productCategoryName,$routerMap,$page);
|
|
|
|
//是否开启可视化
|
|
|
|
$isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$productCategoryName);
|
|
|
|
if ((int)$isVisual == 1 || $isVisual == null){
|
|
|
|
//产品,产品分类,新闻,博客(section模板通用数据模块处理)
|
|
|
|
$webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
|
|
|
|
}
|
|
|
|
$webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$productCategoryName,$routerMap);
|
|
|
|
$webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
|
|
|
|
unset($pageService);
|
|
|
|
$html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routerMap->route);
|
|
|
|
//处理URL等,处理html链接a标签href
|
|
|
|
if (!empty($html)){
|
|
|
|
return $this->pageUrlHandle($project,$routerMap,$html,"",$page);
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取产品页html
|
|
|
|
*/
|
|
|
|
public function getProductPage($project,$routerMap,$lang=''): string
|
|
|
|
{
|
|
|
|
$pageService = new PageService();
|
|
|
|
$commonService = new CommonService();
|
|
|
|
$products_detail = Product::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->whereNotNull('route')->first();
|
|
|
|
if($project['update_info']['is_update'] && $products_detail && $products_detail->six_read){
|
|
|
|
return $this->getOldHtml($project,$routerMap,$project['update_info']['old_domain_test'],$project['update_info']['old_domain_online'],$lang);
|
|
|
|
}else{
|
|
|
|
$products_detail = $pageService->productDataHandle($project,$products_detail);
|
|
|
|
if (!empty($products_detail)){
|
|
|
|
//公共拼接页面方法
|
|
|
|
$webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$productName,$routerMap);
|
|
|
|
//公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
|
|
|
|
$webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,"product",$routerMap,null);
|
|
|
|
$isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$productName);
|
|
|
|
if ((int)$isVisual == 1 || $isVisual == null){
|
|
|
|
//产品,产品分类,新闻,博客(section模板通用数据模块处理)
|
|
|
|
$webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
|
|
|
|
}
|
|
|
|
$webCustomHtml = $pageService->productsDetailTdkHandle($project,$webCustomHtml,$products_detail);
|
|
|
|
$webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
|
|
|
|
unset($pageService);
|
|
|
|
$html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routerMap->route);
|
|
|
|
//处理URL等,处理html链接a标签href
|
|
|
|
if (!empty($html)){
|
|
|
|
return $this->pageUrlHandle($project,$routerMap,$html);
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取产品关键词页html
|
|
|
|
*/
|
|
|
|
public function getProductKeywordPage($project,$routerMap): string
|
|
|
|
{
|
|
|
|
$pageService = new PageService();
|
|
|
|
$commonService = new CommonService();
|
|
|
|
$keywordModel = new Keyword();
|
|
|
|
$tdkService = new TdkService();
|
|
|
|
$routePath = $routerMap->route;
|
|
|
|
|
|
|
|
//公共头部底部
|
|
|
|
$publicTemplate = $pageService->getPublicTemplate($project);
|
|
|
|
$headerHtml = $publicTemplate->headerHtml;
|
|
|
|
$footerHtml = $publicTemplate->footerHtml;
|
|
|
|
//关键词详情
|
|
|
|
$keywordsDetails = $pageService->getKeywordDetails($project, $routerMap->route);
|
|
|
|
if (!empty($keywordsDetails)){
|
|
|
|
if (!empty($keywordsDetails->embed_code)){
|
|
|
|
$videoUrl = $keywordsDetails->embed_code;
|
|
|
|
preg_match('/src="([^"]+)"/', $videoUrl, $matches);
|
|
|
|
$src = $matches[1];
|
|
|
|
$keywordsDetails->video = $src;
|
|
|
|
}
|
|
|
|
//随机获取关键词列表
|
|
|
|
$productsKeywordsList = $keywordModel->getProductsKeywordsList($project);
|
|
|
|
//调整为相关产品
|
|
|
|
$productsRecommendAndHot = $pageService->getRecommendAndHotProducts($project,$routePath);
|
|
|
|
//博客新闻数据
|
|
|
|
$blogT = $pageService->getProductsBlogNews($project);
|
|
|
|
$viewPath = isset($keywordsDetails->video) && !empty($keywordsDetails->video) ? "products/products_video_keywords" : "products/products_keywords";
|
|
|
|
$html = view($viewPath, compact("headerHtml", "footerHtml", "routePath", "productsKeywordsList", "productsRecommendAndHot", "blogT","keywordsDetails"))->__toString();
|
|
|
|
$html = $pageService->publicHtmlHandle($html, $project->id);
|
|
|
|
//生成静态页
|
|
|
|
$webCustomHtml = $commonService->thirdPartyCodeHandle($project, $html, $routerMap->route);
|
|
|
|
//TDK
|
|
|
|
unset($html,$productsKeywordsList,$productsRecommendAndHot,$blogT);
|
|
|
|
$html = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$productKeywordName,$routerMap);
|
|
|
|
//处理URL等,处理html链接a标签href
|
|
|
|
if (!empty($html)){
|
|
|
|
return $this->pageUrlHandle($project,$routerMap,$html);
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取产品新闻列表页html
|
|
|
|
*/
|
|
|
|
public function getNewsListPage($project,$routerMap,$page): string
|
|
|
|
{
|
|
|
|
$pageService = new PageService();
|
|
|
|
$commonService = new CommonService();
|
|
|
|
$tdkService = new TdkService();
|
|
|
|
$routePath = $routerMap->route;
|
|
|
|
//公共拼接页面方法
|
|
|
|
$webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$newsCategoryName,$routerMap);
|
|
|
|
//公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
|
|
|
|
$webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$newsCategoryName,$routerMap,$page);
|
|
|
|
$isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$newsCategoryName);
|
|
|
|
if ((int)$isVisual == 1 || $isVisual == null){
|
|
|
|
//产品,产品分类,新闻,博客(section模板通用数据模块处理)
|
|
|
|
$webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
|
|
|
|
}
|
|
|
|
$webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$newsCategoryName,$routerMap);
|
|
|
|
$webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
|
|
|
|
unset($pageService);
|
|
|
|
$html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routePath);
|
|
|
|
//处理URL等,处理html链接a标签href
|
|
|
|
if (!empty($html)){
|
|
|
|
return $this->pageUrlHandle($project,$routerMap,$html,"",$page);
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 自定义模块列表
|
|
|
|
*/
|
|
|
|
public function getModuleListPage($project,$routerMap,$page): string
|
|
|
|
{
|
|
|
|
$pageService = new PageService();
|
|
|
|
$commonService = new CommonService();
|
|
|
|
$tdkService = new TdkService();
|
|
|
|
$routePath = $routerMap->route;
|
|
|
|
//公共拼接页面方法
|
|
|
|
$webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$extendCategoryName,$routerMap);
|
|
|
|
//公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
|
|
|
|
$webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$extendCategoryName,$routerMap,$page);
|
|
|
|
$moduleCategoryInfo = ModuleCategory::getModuleCategoryAndExtendById($project->id,$routerMap->source_id);
|
|
|
|
if (isset($moduleCategoryInfo->getExtend->list_visualization) && $moduleCategoryInfo->getExtend->list_visualization == 1){
|
|
|
|
//产品,产品分类,新闻,博客(section模板通用数据模块处理)
|
|
|
|
$webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
$webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$extendCategoryName,$routerMap);
|
|
|
|
$webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
|
|
|
|
unset($pageService);
|
|
|
|
$html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routePath);
|
|
|
|
//处理URL等,处理html链接a标签href
|
|
|
|
if (!empty($html)){
|
|
|
|
return $this->pageUrlHandle($project,$routerMap,$html,"",$page);
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取产品新闻页html
|
|
|
|
*/
|
|
|
|
public function getNewsPage($project,$routerMap,$lang=''): string
|
|
|
|
{
|
|
|
|
$pageService = new PageService();
|
|
|
|
$commonService = new CommonService();
|
|
|
|
$tdkService = new TdkService();
|
|
|
|
//页面路由
|
|
|
|
$routePath = $routerMap->route;
|
|
|
|
$news_detail = News::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
|
|
|
|
if (!empty($news_detail)){
|
|
|
|
if($project['update_info']['is_update'] && $news_detail->six_read){
|
|
|
|
return $this->getOldHtml($project,$routerMap,$project['update_info']['old_domain_test'],$project['update_info']['old_domain_online'],$lang);
|
|
|
|
}else{
|
|
|
|
//公共拼接页面方法
|
|
|
|
$webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$newsName,$routerMap);
|
|
|
|
//公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
|
|
|
|
$webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$newsName,$routerMap,null);
|
|
|
|
$isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$newsName);
|
|
|
|
if ((int)$isVisual == 1 || $isVisual == null){
|
|
|
|
//产品,产品分类,新闻,博客(section模板通用数据模块处理)
|
|
|
|
$webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
|
|
|
|
}
|
|
|
|
//TDK处理
|
|
|
|
$webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$newsName,$routerMap);
|
|
|
|
//网页公共部分
|
|
|
|
$webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
|
|
|
|
unset($pageService);
|
|
|
|
$html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routePath);
|
|
|
|
//处理URL等,处理html链接a标签href
|
|
|
|
if (!empty($html)){
|
|
|
|
return $this->pageUrlHandle($project,$routerMap,$html);
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 自定义模块详情
|
|
|
|
*/
|
|
|
|
public function getModulePage($project,$routerMap,$lang=''): string
|
|
|
|
{
|
|
|
|
$pageService = new PageService();
|
|
|
|
$commonService = new CommonService();
|
|
|
|
$tdkService = new TdkService();
|
|
|
|
//页面路由
|
|
|
|
$routePath = $routerMap->route;
|
|
|
|
$module_detail = Module::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
|
|
|
|
if (!empty($module_detail)){
|
|
|
|
if($project['update_info']['is_update'] && $module_detail->six_read){
|
|
|
|
return $this->getOldHtml($project,$routerMap,$project['update_info']['old_domain_test'],$project['update_info']['old_domain_online'],$lang);
|
|
|
|
}else{
|
|
|
|
//公共拼接页面方法
|
|
|
|
$webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$extendName,$routerMap);
|
|
|
|
//公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
|
|
|
|
$webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$extendName,$routerMap,null);
|
|
|
|
$moduleCategoryInfo = Module::getModuleCategory($project->id,$module_detail);
|
|
|
|
if (isset($moduleCategoryInfo->getExtend->detail_visualization) && $moduleCategoryInfo->getExtend->detail_visualization == 1){
|
|
|
|
//产品,产品分类,新闻,博客(section模板通用数据模块处理)
|
|
|
|
$webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
|
|
|
|
}
|
|
|
|
//TDK处理
|
|
|
|
$webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$extendName,$routerMap);
|
|
|
|
//网页公共部分
|
|
|
|
$webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
|
|
|
|
unset($pageService);
|
|
|
|
$html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routePath);
|
|
|
|
//处理URL等,处理html链接a标签href
|
|
|
|
if (!empty($html)){
|
|
|
|
return $this->pageUrlHandle($project,$routerMap,$html);
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取博客列表页html
|
|
|
|
*/
|
|
|
|
public function getBlogListPage($project,$routerMap,$page): string
|
|
|
|
{
|
|
|
|
$pageService = new PageService();
|
|
|
|
$commonService = new CommonService();
|
|
|
|
$tdkService = new TdkService();
|
|
|
|
//公共拼接页面方法
|
|
|
|
$webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$blogCategoryName,$routerMap);
|
|
|
|
//公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
|
|
|
|
$webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$blogCategoryName,$routerMap,$page);
|
|
|
|
$isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$blogCategoryName);
|
|
|
|
if ((int)$isVisual == 1 || $isVisual == null){
|
|
|
|
//产品,产品分类,新闻,博客(section模板通用数据模块处理)
|
|
|
|
$webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
|
|
|
|
}
|
|
|
|
$webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$blogCategoryName,$routerMap);
|
|
|
|
$webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
|
|
|
|
unset($pageService);
|
|
|
|
$html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routerMap->route);
|
|
|
|
//处理URL等,处理html链接a标签href
|
|
|
|
if (!empty($html)){
|
|
|
|
return $this->pageUrlHandle($project,$routerMap,$html,"",$page);
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取博客页html
|
|
|
|
*/
|
|
|
|
public function getBlogPage($project,$routerMap,$lang=''): string
|
|
|
|
{
|
|
|
|
$pageService = new PageService();
|
|
|
|
$commonService = new CommonService();
|
|
|
|
$tdkService = new TdkService();
|
|
|
|
$blog_detail = Blog::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
|
|
|
|
if (!empty($blog_detail)){
|
|
|
|
if($project['update_info']['is_update'] && $blog_detail->six_read){
|
|
|
|
return $this->getOldHtml($project,$routerMap,$project['update_info']['old_domain_test'],$project['update_info']['old_domain_online'],$lang);
|
|
|
|
}else{
|
|
|
|
//公共拼接页面方法
|
|
|
|
$webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$blogName,$routerMap);
|
|
|
|
//公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
|
|
|
|
$webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$blogName,$routerMap,null);
|
|
|
|
$isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$blogName);
|
|
|
|
if ((int)$isVisual == 1 || $isVisual == null){
|
|
|
|
//产品,产品分类,新闻,博客(section模板通用数据模块处理)
|
|
|
|
$webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
|
|
|
|
}
|
|
|
|
$webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$blogName,$routerMap);
|
|
|
|
$webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
|
|
|
|
unset($pageService);
|
|
|
|
//生成静态页
|
|
|
|
$html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routerMap->route);
|
|
|
|
//处理URL等,处理html链接a标签href
|
|
|
|
if (!empty($html)){
|
|
|
|
return $this->pageUrlHandle($project,$routerMap,$html);
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取单页面html
|
|
|
|
*/
|
|
|
|
public function getSinglePage($project,$routerMap,$lang=''): string
|
|
|
|
{
|
|
|
|
$pageService = new PageService();
|
|
|
|
$commonService = new CommonService();
|
|
|
|
$tdkService = new TdkService();
|
|
|
|
//页面路由
|
|
|
|
$routePath = $routerMap->route;
|
|
|
|
$webCustom = WebCustom::where("id",$routerMap->source_id)->where("status",1)->first();
|
|
|
|
if (!empty($webCustom)){
|
|
|
|
if($project['update_info']['is_update'] && $webCustom->six_read){
|
|
|
|
return $this->getOldHtml($project,$routerMap,$project['update_info']['old_domain_test'],$project['update_info']['old_domain_online'],$lang);
|
|
|
|
}else{
|
|
|
|
//公共拼接页面方法
|
|
|
|
$content = $pageService->publicMontagePage($project,WebTemplateCommon::$pageName,$routerMap);
|
|
|
|
//公共左侧导航处理
|
|
|
|
$phpQueryDom=phpQuery::newDocument($content);
|
|
|
|
$pageService->leftNavSideNavHandle($project,WebTemplateCommon::$pageName,$phpQueryDom,$routerMap);
|
|
|
|
$content = $phpQueryDom->htmlOuter();
|
|
|
|
unset($phpQueryDom);
|
|
|
|
//产品,产品分类,新闻,博客(section模板通用数据模块处理)
|
|
|
|
$content = $pageService->generalTemplateProcessingForDataModules($content,$project->id);
|
|
|
|
//生成静态页
|
|
|
|
$content = $tdkService->pageTdkHandle($project,$content,WebTemplateCommon::$pageName,$routerMap);
|
|
|
|
$content = $pageService->publicHtmlHandle($content,$project->id);
|
|
|
|
unset($pageService);
|
|
|
|
$html = $commonService->thirdPartyCodeHandle($project,$content,$routePath,$routerMap);
|
|
|
|
//处理URL等,处理html链接a标签href
|
|
|
|
if (!empty($html)){
|
|
|
|
return $this->pageUrlHandle($project,$routerMap,$html);
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取关键词列表页面
|
|
|
|
*/
|
|
|
|
public function getProductKeywordListPage($project,$router,$page): string
|
|
|
|
{
|
|
|
|
if (isset($router->route) && $router->route != null) {
|
|
|
|
$routePath = $router->route;
|
|
|
|
} else {
|
|
|
|
$routePath = $router;
|
|
|
|
}
|
|
|
|
//公共头部底部
|
|
|
|
$pageService = new PageService();
|
|
|
|
$commonService = new CommonService();
|
|
|
|
$publicTemplate = $pageService->getPublicTemplate($project);
|
|
|
|
$headerHtml = $publicTemplate->headerHtml;
|
|
|
|
$footerHtml = $publicTemplate->footerHtml;
|
|
|
|
|
|
|
|
//获取字母开头关键词列表
|
|
|
|
$keywords = $pageService->getProductKeywordsByLetter($project,$router,$page);
|
|
|
|
$html = view("products/products_keywords_list",compact("headerHtml","footerHtml","keywords","routePath"))->__toString();
|
|
|
|
$html = $pageService->publicHtmlHandle($html, $project->id);
|
|
|
|
//生成静态页
|
|
|
|
$webCustomHtml = $commonService->thirdPartyCodeHandle($project, $html, $routePath);
|
|
|
|
//top-search TDK处理,分页link索引处理
|
|
|
|
$webCustomHtml = $pageService->productKeywordListTdkHandle($webCustomHtml,$project,$routePath,$keywords,$page);
|
|
|
|
//处理URL等,处理html链接a标签href
|
|
|
|
if (!empty($html)){
|
|
|
|
$webCustomHtml = $this->pageUrlHandle($project,$routePath,$webCustomHtml);
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
unset($keywords);
|
|
|
|
unset($html);
|
|
|
|
return $webCustomHtml;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO:处理URL等,处理html链接a标签href,获取最终html
|
|
|
|
*/
|
|
|
|
public function pageUrlHandle($project,$routerMap,$html,$lang="",$page=null): string
|
|
|
|
{
|
|
|
|
if (isset($routerMap->route) && $routerMap->route != null) {
|
|
|
|
$route = $routerMap->route;
|
|
|
|
} else {
|
|
|
|
$route = $routerMap;
|
|
|
|
}
|
|
|
|
$pageService = new PageService();
|
|
|
|
$phpQueryDom=phpQuery::newDocument($html);
|
|
|
|
$domainEnd = $project->domain_end;
|
|
|
|
//主站a链接处理
|
|
|
|
$this->masterWebATagHandle($phpQueryDom,$project,$domainEnd);
|
|
|
|
|
|
|
|
//html 标签处理
|
|
|
|
$this->htmlTagHandle($phpQueryDom,$project);
|
|
|
|
|
|
|
|
//888项目禁用鼠标右键点击,查看元素
|
|
|
|
// $this->prohibitRightMouseClick($phpQueryDom,$project);
|
|
|
|
|
|
|
|
//国家
|
|
|
|
$webCountry = $pageService->getCountryList($project->id);
|
|
|
|
|
|
|
|
//语种 alternate
|
|
|
|
$this->setHrefLang($phpQueryDom,$project,$route,$page,$lang,$webCountry);
|
|
|
|
|
|
|
|
//以-tag的聚合页结尾的路由加上 <meta name="robots" content="noindex">
|
|
|
|
$this->setTagRobotsNoindex($phpQueryDom,$routerMap);
|
|
|
|
|
|
|
|
//<meta name="cookie_consent_banner" content="参数值"> 配置
|
|
|
|
$this->setCookieConsentBanner($phpQueryDom,$project);
|
|
|
|
|
|
|
|
$html = $phpQueryDom->htmlOuter();
|
|
|
|
unset($phpQueryDom);
|
|
|
|
phpQuery::unloadDocuments();
|
|
|
|
|
|
|
|
//根据配置读取不同的资源路径功能
|
|
|
|
$html = $this->setResourcePath($project,$html);
|
|
|
|
//网站语种列表
|
|
|
|
return $pageService->publicCountryLanguageHandle($html,$project,$route);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* html 标签处理
|
|
|
|
*/
|
|
|
|
public function htmlTagHandle($phpQueryDom,$project)
|
|
|
|
{
|
|
|
|
$phpQueryDom->find("html")->attr("dir","ltr");
|
|
|
|
$mainLang = WebLanguage::getProjectMainLang($project->main_lang_id);
|
|
|
|
if ($mainLang->short == "ru"){
|
|
|
|
$phpQueryDom->find('main .keyword_search')->remove();
|
|
|
|
}
|
|
|
|
$lang = $mainLang ? $mainLang->short : 'en';
|
|
|
|
$phpQueryDom->find("html")->attr("lang",$lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 888项目禁用鼠标右键点击,查看元素
|
|
|
|
*/
|
|
|
|
public function prohibitRightMouseClick($phpQueryDom,$project)
|
|
|
|
{
|
|
|
|
if ($project->id == 888){
|
|
|
|
$phpQueryDom->find("body")->attr("ondragstart","window.event.returnValue=false");
|
|
|
|
$phpQueryDom->find("body")->attr("oncontextmenu","window.event.returnValue=false");
|
|
|
|
$phpQueryDom->find("body")->attr("onselectstart","event.returnValue=false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*主站a链接处理
|
|
|
|
*/
|
|
|
|
public function masterWebATagHandle($phpQueryDom,$project,$domainEnd)
|
|
|
|
{
|
|
|
|
foreach ($phpQueryDom->find('a') as $a) {
|
|
|
|
$href = pq($a)->attr('href');
|
|
|
|
//a标签href字符串是否有http://或者https://等协议头,有的话不做处理
|
|
|
|
if (strpos($href, 'http://') !== false || strpos($href, 'https://') !== false || strpos($href, 'javascript') !== false || strpos($href, 'javasctipt') !== false || strpos($href, '#') !== false || empty($href) || strpos($href, '.zip') !== false || strpos($href, '.txt') !== false || strpos($href, 'tel:') !== false || strpos($href, 'mailto') !== false || strpos($href, '.pdf') !== false || strpos($href, '.tar') !== false || strpos($href, '.jpg') !== false || strpos($href, '.png') !== false || strpos($href, '.jpeg') !== false || strpos($href, '.xml') !== false || strpos($href, 'skype:') !== false || strpos($href, 'whatsapp:') !== false) {
|
|
|
|
$domain = $project->domain;
|
|
|
|
$domain = str_replace("http://","",$domain);
|
|
|
|
$domain = str_replace("https://","",$domain);
|
|
|
|
$domain = str_replace("/","",$domain);
|
|
|
|
$domainArr = parse_url($domain);
|
|
|
|
if (strpos($href, '#') !== false || strpos($href, '.xml') !== false){}else{
|
|
|
|
if (isset($domainArr["path"]) && !empty($domainArr["path"])){
|
|
|
|
if (strpos($href, 'http://') !== false || strpos($href, 'https://') !== false){
|
|
|
|
$domain = $domainArr["path"];
|
|
|
|
if (strpos($href, $domain) !== false){
|
|
|
|
$href = str_replace("http://","",$href);
|
|
|
|
$href = str_replace("https://","",$href);
|
|
|
|
$href = str_replace($domain,"",$href);
|
|
|
|
if ($domainEnd == Project::$domainEndSlash){
|
|
|
|
//以斜杠结尾
|
|
|
|
$href = substr($href, -1) === '/' ? $href : $href . "/";
|
|
|
|
}else{
|
|
|
|
//不以斜杠结尾
|
|
|
|
if (substr($href, -1) === '/') {
|
|
|
|
if ($href != "/"){
|
|
|
|
$href = rtrim($href, '/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pq($a)->attr('href', $href);
|
|
|
|
}else{
|
|
|
|
if ($domainEnd == Project::$domainEndSlash){
|
|
|
|
//以斜杠结尾
|
|
|
|
$href = substr($href, -1) === '/' ? $href : $href . "/";
|
|
|
|
if (strpos($href, ".html") !== false || strpos($href, ".htm") !== false){
|
|
|
|
$href = rtrim($href, '/');
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
//不以斜杠结尾
|
|
|
|
if (substr($href, -1) === '/') {
|
|
|
|
if ($href != "/"){
|
|
|
|
$href = rtrim($href, '/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pq($a)->attr('href', $href);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <meta name="cookie_consent_banner" content="参数值"> 配置
|
|
|
|
*/
|
|
|
|
public function setCookieConsentBanner($phpQueryDom,$project)
|
|
|
|
{
|
|
|
|
$deployBuildInfo = DeployBuild::where("project_id",$project->id)->first();
|
|
|
|
if (!empty($deployBuildInfo)){
|
|
|
|
$phpQueryDom->find('head')->append('<meta name="cookie_consent_banner" content="'.$deployBuildInfo->cookie_consent_banner.'">');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 语种 alternate
|
|
|
|
*/
|
|
|
|
public function setHrefLang($phpQueryDom,$project,$route,$page,$lang,$webCountry)
|
|
|
|
{
|
|
|
|
//处理源代码语言url
|
|
|
|
$countryUrl = [];
|
|
|
|
$createPageService = new CreatePageService();
|
|
|
|
$domain = $createPageService->domainHandle($project->domain);
|
|
|
|
$mainLang = WebLanguage::getProjectMainLang($project->main_lang_id);
|
|
|
|
if (!empty($webCountry)) {
|
|
|
|
foreach ($webCountry as $key => $item) {
|
|
|
|
//语种列表调整,新增自定义跳转链接
|
|
|
|
if (isset($item->country_custom) && !empty($item->country_custom)){
|
|
|
|
if ($item->country_custom->is_create == 1){
|
|
|
|
$page = (int)$page != null && (int)$page != 0 ? (int)$page . "/" : "";
|
|
|
|
if (!empty($mainLang) && $item->short != $mainLang->short){
|
|
|
|
$countryUrl[$key]["url"] = "https://" . $item->country_custom->custom_domain . "/" . $route . "/" . $page;
|
|
|
|
}else{
|
|
|
|
$countryUrl[$key]["url"] = "https://" . $domain . "/" . $route . "/" . $page;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$countryUrl[$key]["url"] = "https://" . $item->country_custom->custom_domain . "/";
|
|
|
|
}
|
|
|
|
$countryUrl[$key]["alias"] = $item->short;
|
|
|
|
}else{
|
|
|
|
if (!empty($mainLang) && $item->short != $mainLang->short){
|
|
|
|
$langShort = $item->short."/";
|
|
|
|
}else{
|
|
|
|
$langShort = "";
|
|
|
|
}
|
|
|
|
if ((int)$page != null) {
|
|
|
|
$countryUrl[$key]["url"] = "https://" . $domain . "/" .$langShort . $route . "/" . (int)$page . "/";
|
|
|
|
} else {
|
|
|
|
$countryUrl[$key]["url"] = $route == "index" ? "https://" . $domain . "/" . $langShort : "https://" . $domain . "/" . $langShort. $route . "/";
|
|
|
|
}
|
|
|
|
$countryUrl[$key]["alias"] = $item->short;
|
|
|
|
}
|
|
|
|
|
|
|
|
//之前
|
|
|
|
// $langShort = $item->short == "en" ? "" : $item->short."/";
|
|
|
|
// if ((int)$page != null) {
|
|
|
|
// $countryUrl[$key]["url"] = "https://" . $domain . "/" .$langShort . $route . "/" . (int)$page . "/";
|
|
|
|
// } else {
|
|
|
|
// $countryUrl[$key]["url"] = $route == "index" ? "https://" . $domain . "/" . $langShort : "https://" . $domain . "/" . $langShort. $route . "/";
|
|
|
|
// }
|
|
|
|
// $countryUrl[$key]["alias"] = $item->short;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//路径
|
|
|
|
if ($route == "index") {
|
|
|
|
$webUrl = "https://" . $domain . "/";
|
|
|
|
} else {
|
|
|
|
if ((int)$page != null || (int)$page != 0) {
|
|
|
|
if ($lang != "") {
|
|
|
|
$langShort = $lang == "en" ? "" : $lang."/";
|
|
|
|
$webUrl = "https://" . $domain . "/" .$langShort. $route . "/" . (int)$page . "/";
|
|
|
|
} else {
|
|
|
|
$webUrl = "https://" . $domain . "/" . $route . "/" . (int)$page . "/";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($lang != "") {
|
|
|
|
$langShort = $lang == "en" ? "" : $lang."/";
|
|
|
|
$webUrl = "https://" . $domain . "/" . $langShort . $route . "/";
|
|
|
|
} else {
|
|
|
|
$webUrl = "https://" . $domain . "/" . $route . "/";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$phpQueryDom->find('head')->append("<meta property='og:url' content='$route'/>");
|
|
|
|
$phpQueryDom->find('head')->append("<link rel='canonical' href='$webUrl' />");
|
|
|
|
if (!empty($countryUrl)){
|
|
|
|
foreach ($countryUrl as $item){
|
|
|
|
if (isset($item['alias']) && isset($item['url'])){
|
|
|
|
$phpQueryDom->find('head')->append("<link rel='alternate' hreflang='".$item['alias']."' href='".$item['url']."'>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 以-tag的聚合页结尾的路由加上 <meta name="robots" content="noindex">
|
|
|
|
*/
|
|
|
|
public function setTagRobotsNoindex($phpQueryDom,$routerMap)
|
|
|
|
{
|
|
|
|
if (isset($routerMap->source) && $routerMap->source == WebTemplateCommon::$productKeywordName){
|
|
|
|
$routerSuffix = substr($routerMap->route, -4);
|
|
|
|
$routerLength = strlen($routerMap->route);
|
|
|
|
if ($routerLength >= 4 && $routerSuffix == "-tag"){
|
|
|
|
$phpQueryDom->find('head')->append('<meta name="robots" content="noindex,nofollow">');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 配置资源路径
|
|
|
|
*/
|
|
|
|
public function setResourcePath($project,$html)
|
|
|
|
{
|
|
|
|
$projectLocation = $project->project_location;
|
|
|
|
$storageType = $project->storage_type;
|
|
|
|
if ($projectLocation == Project::$projectLocationZero){
|
|
|
|
//普通项目
|
|
|
|
if ($storageType == Project::$storageTypeZero){
|
|
|
|
//压缩项目
|
|
|
|
$html = str_replace(Project::$storageTypeOneFileFix,Project::$storageTypeZeroFileFix,$html);
|
|
|
|
}else{
|
|
|
|
//非压缩项目
|
|
|
|
$html = str_replace(Project::$storageTypeZeroFileFix,Project::$storageTypeOneFileFix,$html);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
//危险项目
|
|
|
|
$html = str_replace(Project::$storageTypeOneFileFix,Project::$projectLocationDangerousFileFix,$html);
|
|
|
|
$html = str_replace(Project::$storageTypeZeroFileFix,Project::$projectLocationDangerousFileFix,$html);
|
|
|
|
}
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 放入文件
|
|
|
|
*/
|
|
|
|
public function putHtmlToPageFile($project,$lang,$route,$page,$html,$routeType=""): bool
|
|
|
|
{
|
|
|
|
if (empty($html) || $html == ""){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (strpos($route, '.php') !== false || strpos($route, '.env') !== false || strpos($route, '.jpg') !== false || strpos($route, '.asp') !== false || strpos($route, '.png') !== false || strpos($route, '.gif') !== false ){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$domain = $project->domain;
|
|
|
|
$domain = str_replace("https://","",$domain);
|
|
|
|
$domain = str_replace("http://","",$domain);
|
|
|
|
$domain = str_replace("/","",$domain);
|
|
|
|
$originLang = $lang;
|
|
|
|
$lang = $lang == "zh-TW" ? "zh-ct" : $lang;
|
|
|
|
$lang = $lang=="" ? "" : "/".$lang;
|
|
|
|
$page = $page == null || (int)$page == 1 ? null : "/".(int)$page;
|
|
|
|
|
|
|
|
//是否是5.0升级项目
|
|
|
|
if (isset($project->update_info["is_update"]) && $project->update_info["is_update"] == 1){
|
|
|
|
//5.0生成路径
|
|
|
|
$path = $this->getProjectRoutePath5($project,$domain,$route,$routeType,$lang,$page);
|
|
|
|
}else{
|
|
|
|
//6.0生成路径
|
|
|
|
$path = $this->getProjectRoutePath6($project,$domain,$route,$routeType,$lang,$page);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
//$filePath = iconv("UTF-8", "GBK", $path);
|
|
|
|
$filePath = $path;
|
|
|
|
if (!file_exists(public_path($filePath))) {
|
|
|
|
mkdir(public_path($filePath), 0777, true);
|
|
|
|
}
|
|
|
|
if (strpos($route, ".html") !== false || strpos($route, ".htm") !== false) {
|
|
|
|
file_put_contents(public_path($filePath . ".html"), $html);
|
|
|
|
chmod(public_path($filePath . ".html"), 0777);
|
|
|
|
}else{
|
|
|
|
file_put_contents(public_path($filePath . "/index.html"), $html);
|
|
|
|
chmod(public_path($filePath . "/index.html"), 0777);
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 6.0生成路径
|
|
|
|
*/
|
|
|
|
public function getProjectRoutePath6($project,$domain,$route,$routeType,$lang,$page): string
|
|
|
|
{
|
|
|
|
if ($routeType == "news" || $routeType == "blogs"){
|
|
|
|
if ($routeType == "blogs"){
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->whereIn('path', ['blog','blogs',''])->first();
|
|
|
|
}else{
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("path",$routeType)->first();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$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 = Module::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
|
|
|
|
$moduleCategoryInfo = Module::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;
|
|
|
|
}
|
|
|
|
$route = str_replace(".html","",$route);
|
|
|
|
$route = str_replace(".htm","",$route);
|
|
|
|
return $domain.$lang.$route.$page;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 5.0生成路径
|
|
|
|
*/
|
|
|
|
public function getProjectRoutePath5($project,$domain,$route,$routeType,$lang,$page): string
|
|
|
|
{
|
|
|
|
if ($routeType == "news" || $routeType == "blogs"){
|
|
|
|
if ($routeType == "blogs"){
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->whereIn('path', ['blog','blogs',''])->first();
|
|
|
|
}else{
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("path",$routeType)->first();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$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 = ModuleCategory::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 = Module::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
|
|
|
|
$moduleCategoryInfo = Module::getModuleCategory($project->id,$modules);
|
|
|
|
if (isset($moduleCategoryInfo->getExtend->route) && !empty($moduleCategoryInfo->getExtend->route)){
|
|
|
|
$route = "/".$moduleCategoryInfo->route."/".$modules->route;
|
|
|
|
}else{
|
|
|
|
$route = "/".$modules->route;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$route = $route == "index" ? "" : "/".$route;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if ($route == "products"){
|
|
|
|
if ($page == null || $page == 1){
|
|
|
|
$route = "/".$route;
|
|
|
|
}else{
|
|
|
|
$route = "/".$route."/page";
|
|
|
|
}
|
|
|
|
}elseif ($route == "news"){
|
|
|
|
$route = $page == null || $page == 1 ? "/".$route : "/".$route;
|
|
|
|
}elseif ($route == "blog"){
|
|
|
|
$route = $page == null || $page == 1 ? "/blog_catalog/".$route : "/blog_catalog/".$route."/page";
|
|
|
|
}else{
|
|
|
|
$route = $route == "index" ? "" : "/".$route;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$route = str_replace(".html","",$route);
|
|
|
|
$route = str_replace(".htm","",$route);
|
|
|
|
return $domain.$lang.$route.$page;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 从主站拿页面
|
|
|
|
*/
|
|
|
|
public function getHtmlToPageFile($project,$lang,$route,$page,$routeType = "")
|
|
|
|
{
|
|
|
|
$domain = $project->domain;
|
|
|
|
$domain = str_replace("https://","",$domain);
|
|
|
|
$domain = str_replace("http://","",$domain);
|
|
|
|
$domain = str_replace("/","",$domain);
|
|
|
|
$lang = $lang=="" ? "" : "/".$lang;
|
|
|
|
$page = $page == null || (int)$page == 1 ? null : "/".(int)$page;
|
|
|
|
|
|
|
|
//是否是5.0升级项目
|
|
|
|
if (isset($project->update_info["is_update"]) && $project->update_info["is_update"] == 1){
|
|
|
|
//取5.0生成路径
|
|
|
|
$path = $this->getProjectRoutePagePath5($project,$domain,$route,$routeType,$lang,$page);
|
|
|
|
}else{
|
|
|
|
//取6.0生成路径
|
|
|
|
$path = $this->getProjectRoutePagePath6($project,$domain,$route,$routeType,$lang,$page);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$filePath = iconv("UTF-8", "GBK", $path);
|
|
|
|
if (file_exists(public_path($filePath . "/index.html"))) {
|
|
|
|
$html = file_get_contents(public_path($filePath . "/index.html"));
|
|
|
|
}else{
|
|
|
|
$html = "";
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$html = "";
|
|
|
|
}
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 拿6.0页面
|
|
|
|
*/
|
|
|
|
public function getProjectRoutePagePath6($project,$domain,$route,$routeType,$lang,$page): string
|
|
|
|
{
|
|
|
|
if ($routeType == "news" || $routeType == "blogs"){
|
|
|
|
if ($routeType == "blogs"){
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->whereIn('path', ['blog','blogs',''])->first();
|
|
|
|
}else{
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("path",$routeType)->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
$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"){
|
|
|
|
$route = "/blogs/".$route;
|
|
|
|
}elseif($routerMap->source == "module"){
|
|
|
|
$modules = Module::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
|
|
|
|
$moduleCategoryInfo = Module::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 $domain.$lang.$route.$page;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 拿5.0页面
|
|
|
|
*/
|
|
|
|
public function getProjectRoutePagePath5($project,$domain,$route,$routeType,$lang,$page): string
|
|
|
|
{
|
|
|
|
if ($routeType == "news" || $routeType == "blogs"){
|
|
|
|
if ($routeType == "blogs"){
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->whereIn('path', ['blog','blogs',''])->first();
|
|
|
|
}else{
|
|
|
|
$routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("path",$routeType)->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
$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"){
|
|
|
|
$route = "/news_catalog/".$route."/page";
|
|
|
|
}elseif ($routerMap->source == "blog_category"){
|
|
|
|
$route = "/blog_catalog/".$route."/page";
|
|
|
|
}elseif ($routerMap->source == "product_category"){
|
|
|
|
$route = "/".$route."/page";
|
|
|
|
}elseif ($routerMap->source == "module"){
|
|
|
|
$modules = Module::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
|
|
|
|
$moduleCategoryInfo = Module::getModuleCategory($project->id,$modules);
|
|
|
|
if (isset($moduleCategoryInfo->getExtend->route) && !empty($moduleCategoryInfo->getExtend->route)){
|
|
|
|
$route = "/".$moduleCategoryInfo->getExtend->route."_catalog/".$moduleCategoryInfo->route."/page";
|
|
|
|
}else{
|
|
|
|
$route = "/extend_catalog/".$moduleCategoryInfo->route."/page";
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$route = $route == "index" ? "" : "/".$route;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$route = $route == "index" ? "" : "/".$route;
|
|
|
|
}
|
|
|
|
return $domain.$lang.$route.$page;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 翻译
|
|
|
|
*/
|
|
|
|
public function translateWebPage($project,$html,$lang,$domain,$route="",$page=null,$countryLang=null): string
|
|
|
|
{
|
|
|
|
if (empty($html) || $html == ""){
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
$staticHtmlRepository = new StaticHtmlRepository();
|
|
|
|
try {
|
|
|
|
//非主站处理html语言
|
|
|
|
$htmlOld = $this->langUrlHandle($project,$lang,$html,$route,$page,$countryLang);
|
|
|
|
$phpQueryDomOld = phpQuery::newDocument($htmlOld);
|
|
|
|
$langDomContent = $phpQueryDomOld->find("header .change-language")->eq(0)->html();
|
|
|
|
$footerFormDomContent = $phpQueryDomOld->find(".form-footer-inquiry-block")->eq(0)->html();
|
|
|
|
$mainFormDomContent = $phpQueryDomOld->find(".section-form-wrap-block")->eq(0)->html();
|
|
|
|
$popFormDomContent = $phpQueryDomOld->find(".pop-box.inquiry-box")->eq(0)->html();
|
|
|
|
$topSearchDomContent = $phpQueryDomOld->find("main .top-search-title-first-letter-list")->eq(0)->html();
|
|
|
|
$langDomContent5 = $phpQueryDomOld->find(".prisna-wp-translate-seo")->eq(0)->html();
|
|
|
|
unset($phpQueryDomOld);
|
|
|
|
phpQuery::unloadDocuments();
|
|
|
|
|
|
|
|
$newHtml = "";
|
|
|
|
if ($lang != '') {
|
|
|
|
//翻译测试成功,用下面第二红最新翻译
|
|
|
|
// 第一种翻译
|
|
|
|
// $commonService = new CommonService();
|
|
|
|
// $htmlNew = $commonService->webHtmlTranslate($project,$htmlOld,$lang,$domain);
|
|
|
|
// 第二种翻译
|
|
|
|
$htmlNew = $staticHtmlRepository->getTranHtml($project,$htmlOld,$lang,$route,$page);
|
|
|
|
$phpQueryDomNew = phpQuery::newDocument($htmlNew);
|
|
|
|
unset($htmlOld);
|
|
|
|
$phpQueryDomNew->find("header .change-language")->eq(0)->html($langDomContent);
|
|
|
|
//取消根据翻译状态,翻译tag状态显示主站小语种列表功能(2024.02.27)
|
|
|
|
// $phpQueryDomNew->find("header div[data-module=2]")->find(".change-language-cont")->removeAttr("style");
|
|
|
|
$phpQueryDomNew->find(".form-footer-inquiry-block")->eq(0)->html($footerFormDomContent);
|
|
|
|
$phpQueryDomNew->find(".section-form-wrap-block")->eq(0)->html($mainFormDomContent);
|
|
|
|
$phpQueryDomNew->find(".pop-box.inquiry-box")->eq(0)->html($popFormDomContent);
|
|
|
|
$phpQueryDomNew->find("main .top-search-title-first-letter-list")->eq(0)->html($topSearchDomContent);
|
|
|
|
$phpQueryDomNew->find(".prisna-wp-translate-seo")->eq(0)->html($langDomContent5);
|
|
|
|
$newHtml = $phpQueryDomNew->htmlOuter();
|
|
|
|
unset($phpQueryDomNew,$htmlNew,$langDomContent,$footerFormDomContent,$mainFormDomContent,$popFormDomContent);
|
|
|
|
}
|
|
|
|
phpQuery::unloadDocuments();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$newHtml = $staticHtmlRepository->getTranHtml($project,$html,$lang,$route,$page);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $newHtml;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 小语种url处理
|
|
|
|
*/
|
|
|
|
public function langUrlHandle($project,$lang,$html,$route="",$page=null,$countryLang=null)
|
|
|
|
{
|
|
|
|
// $html = str_replace("\n","",$html);
|
|
|
|
$content = $html;
|
|
|
|
//主站翻译,不进行小语种链接和页面处理
|
|
|
|
if ($project->is_lang_translate == 1){
|
|
|
|
$langInfo = WebLanguage::getProjectMainLang($project->main_lang_id);
|
|
|
|
if ($langInfo->short == $lang){
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//当前语言国徽背景图片处理
|
|
|
|
if ($lang != ""){
|
|
|
|
$oldLang = $lang;
|
|
|
|
$oldRoute = $route;
|
|
|
|
$phpQueryDom = phpQuery::newDocument($content);
|
|
|
|
//去掉小语种搜索框
|
|
|
|
$phpQueryDom->find("header .search")->remove();
|
|
|
|
$phpQueryDom->find("header .btn--search")->remove();
|
|
|
|
$phpQueryDom->find("header .btn-search")->remove();
|
|
|
|
$phpQueryDom->find("header .head-search")->remove();
|
|
|
|
|
|
|
|
$page = $page == null ? "" : $page."/";
|
|
|
|
$route = $route == "index" || $route == "" ? "" : $route."/";
|
|
|
|
$lang = $lang."/";
|
|
|
|
$langUrl = "https://".$project->domain."/".$lang.$route.$page;
|
|
|
|
$phpQueryDom->find("link[rel=canonical]")->attr("href",$langUrl);
|
|
|
|
|
|
|
|
//翻译版块当前小语种显示
|
|
|
|
$countryDom = $phpQueryDom->find("header div[data-module=2]");
|
|
|
|
$langInfo = WebLanguage::where("short",$oldLang)->first();
|
|
|
|
if (!empty($langInfo)){
|
|
|
|
$countryDom->find(".change-language-title span")->text($langInfo->english);
|
|
|
|
}
|
|
|
|
$oldTwLang = $oldLang == "zh-ct" ? "zh-TW" : $oldLang;
|
|
|
|
$countryDom->find(".change-language-title .country-flag")->attr("class","country-flag language-flag-".$oldTwLang);
|
|
|
|
|
|
|
|
//html 标签处理
|
|
|
|
if ($oldLang == "ar" || $oldLang == "ug"){
|
|
|
|
$phpQueryDom->find("html")->attr("dir","rtl");
|
|
|
|
}else{
|
|
|
|
$phpQueryDom->find("html")->attr("dir","ltr");
|
|
|
|
}
|
|
|
|
|
|
|
|
$phpQueryDom->find("html")->attr("lang",$oldLang);
|
|
|
|
//1:2级目录 2:2级域名
|
|
|
|
$linkingFormat = 1;
|
|
|
|
$mainLang = null;
|
|
|
|
$projectBuild = $project->deployBuild;
|
|
|
|
if (!empty($projectBuild)){
|
|
|
|
$linkingFormat = $projectBuild->linking_format;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($project->main_lang_id) && !empty($project->main_lang_id)){
|
|
|
|
$mainLang = WebLanguage::getProjectMainLang($project->main_lang_id);
|
|
|
|
}
|
|
|
|
//小语种自定义跳转
|
|
|
|
$countryCustomInfo = CountryCustom::getCountryCustomByProjectId($project->id);
|
|
|
|
$countryCustomInfoNew = [];
|
|
|
|
if (!empty($countryCustomInfo)){
|
|
|
|
foreach ($countryCustomInfo as $countryCustomInfoItem){
|
|
|
|
if (isset($countryCustomInfoItem->country_custom_language->short)){
|
|
|
|
$countryCustomInfoNew[$countryCustomInfoItem->country_custom_language->short]["custom_domain"] = $countryCustomInfoItem->custom_domain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 1、处理A标签跳过图标 2、获取图标HTML a标签处理完成 还原图标HTML
|
|
|
|
//a标签路径问题
|
|
|
|
foreach ($phpQueryDom->find('a') as $a) {
|
|
|
|
$class =pq($a)->attr('class');
|
|
|
|
if (strpos($class, 'language-flag') !== false){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$href = pq($a)->attr('href');
|
|
|
|
//a标签href字符串是否有http://或者https://等协议头,有的话不做处理
|
|
|
|
if (strpos($href, 'http://') !== false || strpos($href, 'https://') !== false || strpos($href,'javascript') !== false || strpos($href, 'javasctipt') !== false || $href == "#" || empty($href) || strpos($href, '.zip') !== false || strpos($href, '.txt') !== false || strpos($href, 'tel:') !== false || strpos($href, 'mailto') !== false || strpos($href, '.pdf') !== false || strpos($href, '.tar') !== false || strpos($href, '.jpg') !== false || strpos($href, '.png') !== false || strpos($href, '.jpeg') !== false || strpos($href, '.xml') !== false || strpos($href, 'skype:') !== false || strpos($href, 'whatsapp:') !== false) {
|
|
|
|
}else{
|
|
|
|
if ($lang != ''){
|
|
|
|
if (!empty($mainLang)){
|
|
|
|
if ($lang != $mainLang->short){
|
|
|
|
//小语种自定义链接
|
|
|
|
if (isset($countryCustomInfoNew[$oldLang])){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($linkingFormat == 1){
|
|
|
|
$hrefNew = '/'.$lang . ltrim($href, '/');
|
|
|
|
}else{
|
|
|
|
$hrefNew = '/' . ltrim($href, '/');
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$hrefNew = '/' . ltrim($href, '/');
|
|
|
|
}
|
|
|
|
pq($a)->attr('href', $hrefNew);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = date("Y-m-d H:i:s");
|
|
|
|
$phpQueryDom->find('html')->append("<!-- Globalso translate Cache file was created on ".$data." -->");
|
|
|
|
$content = $phpQueryDom->htmlOuter();
|
|
|
|
unset($html,$phpQueryDom);
|
|
|
|
phpQuery::unloadDocuments();
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生成robots
|
|
|
|
* @param Project $project
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function createRobots($project)
|
|
|
|
{
|
|
|
|
if (!empty($project)){
|
|
|
|
$robotTxtPath = public_path($project->domain."/robots.txt");
|
|
|
|
$createSitemapService = new CreateSitemapService();
|
|
|
|
//A端是否开启允许robots爬虫爬取
|
|
|
|
if ($project->robots == 0){
|
|
|
|
$sitemapContent = $this->getRefuseRobotsStr($project->domain);
|
|
|
|
}else{
|
|
|
|
$sitemapContent = $this->getAllowRobotsStr($project->domain);
|
|
|
|
}
|
|
|
|
$domainPath = public_path($project->domain);
|
|
|
|
if (!file_exists($domainPath)){
|
|
|
|
mkdir($domainPath, 0777, true);
|
|
|
|
}
|
|
|
|
$res = $createSitemapService->putSitemapFile($robotTxtPath,$sitemapContent);
|
|
|
|
if ($res){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生成允许爬虫爬取robots内容
|
|
|
|
* @param $domain
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getAllowRobotsStr($domain)
|
|
|
|
{
|
|
|
|
$domain_arr = config('custom.robots_disallow_domain');
|
|
|
|
$disallow = '';
|
|
|
|
if (in_array($domain, $domain_arr)) {
|
|
|
|
$langArr = WebLanguage::pluck('short');
|
|
|
|
foreach ($langArr as $val) {
|
|
|
|
if ($val == 'en')
|
|
|
|
continue;
|
|
|
|
$disallow .= 'Disallow: /' . $val . '/' . PHP_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$trans_string = is_file(public_path($domain . '/trans_sitemap.xml')) ? "Sitemap: https://".$domain."/trans_sitemap.xml" : '';
|
|
|
|
return "User-agent: *
|
|
|
|
Allow: /
|
|
|
|
Disallow: /404/
|
|
|
|
|
|
|
|
".$disallow."
|
|
|
|
User-agent: MSNBot
|
|
|
|
Disallow: /
|
|
|
|
User-agent: YoudaoBot
|
|
|
|
Disallow: /
|
|
|
|
User-agent: JikeSpider
|
|
|
|
Disallow: /
|
|
|
|
User-agent: EasouSpider
|
|
|
|
Disallow: /
|
|
|
|
User-agent: AhrefsBot
|
|
|
|
Disallow: /
|
|
|
|
User-agent: MJ12bot
|
|
|
|
Disallow: /
|
|
|
|
User-agent: YYSpider
|
|
|
|
Disallow: /
|
|
|
|
User-agent: Teoma
|
|
|
|
Disallow: /
|
|
|
|
User-agent: rogerbot
|
|
|
|
Disallow: /
|
|
|
|
User-agent: exabot
|
|
|
|
Disallow: /
|
|
|
|
User-agent: DotBot
|
|
|
|
Disallow: /
|
|
|
|
User-agent: gigabot
|
|
|
|
Disallow: /
|
|
|
|
User-agent: BLEXBot
|
|
|
|
Disallow: /
|
|
|
|
User-agent: DOCOMO Sprider
|
|
|
|
Disallow: /
|
|
|
|
User-agent: Applebot
|
|
|
|
Disallow: /
|
|
|
|
User-agent: SeznamBot
|
|
|
|
Disallow: /
|
|
|
|
User-agent: SemrushBot
|
|
|
|
Disallow: /
|
|
|
|
|
|
|
|
Sitemap: https://".$domain."/sitemap.xml
|
|
|
|
$trans_string";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取允许爬虫爬取robots内容
|
|
|
|
*/
|
|
|
|
public function getRefuseRobotsStr($domain): string
|
|
|
|
{
|
|
|
|
return "User-agent: *
|
|
|
|
Disallow: /";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 升级项目,并且以老版本展示
|
|
|
|
* @param $project
|
|
|
|
* @param $routerMap
|
|
|
|
* @param $old_domain_test
|
|
|
|
* @param $old_domain_online
|
|
|
|
* @param $language
|
|
|
|
* @return string
|
|
|
|
* @author Akun
|
|
|
|
* @date 2023/11/29 14:52
|
|
|
|
*/
|
|
|
|
public function getOldHtml($project, $routerMap, $old_domain_test, $old_domain_online, $language=''){
|
|
|
|
$collect_info = CollectTask::where('project_id',$project->id)->where('language',$language)->where('source',$routerMap->source)->where('source_id',$routerMap->source_id)->where('status',CollectTask::STATUS_COM)->first();
|
|
|
|
if($collect_info){
|
|
|
|
$html = $collect_info->html;
|
|
|
|
if(strpos($html,'404 Not Found') !== false){
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
//替换域名
|
|
|
|
$html = str_replace("http://".$old_domain_test,"",$html);
|
|
|
|
$html = str_replace("https://".$old_domain_test,"",$html);
|
|
|
|
$html = str_replace("http://".$old_domain_online,"",$html);
|
|
|
|
$html = str_replace("https://".$old_domain_online,"",$html);
|
|
|
|
// //暂时隐藏小语种
|
|
|
|
// $html = str_replace('<div class="change-language ensemble">','<div class="change-language ensemble" style="display: none">',$html);
|
|
|
|
// $html = str_replace('<div class="language_more">','<div class="language_more" style="display: none">',$html);
|
|
|
|
//处理搜索
|
|
|
|
preg_match_all('/<form\s+[^>]*?action\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_search);
|
|
|
|
$search = $result_search[2] ?? [];
|
|
|
|
foreach ($search as $vc) {
|
|
|
|
if((strpos($vc,'search.php') !== false) || (strpos($vc,'index.php') !== false)){
|
|
|
|
$html = str_replace($vc,'/search/',$html);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//增加统计代码
|
|
|
|
$html = str_replace('</body>','<script src="https://ecdn6.globalso.com/public/customerVisit.min.js"></script></body>',$html);
|
|
|
|
return $html;
|
|
|
|
}else{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 更新获取路由
|
|
|
|
*/
|
|
|
|
public function getRouters($updateNotifyData,$pageNum): array
|
|
|
|
{
|
|
|
|
$routers = null;
|
|
|
|
$perPage = 100;
|
|
|
|
$offset = ($pageNum - 1) * $perPage;
|
|
|
|
$updateNotifyQuery = UpdateHtmlModel::where("project_id",$updateNotifyData->project_id);
|
|
|
|
if ($updateNotifyData->route == Notify::ROUTE_ALL){
|
|
|
|
//所有更新
|
|
|
|
if ($updateNotifyData->type == Notify::TYPE_MASTER){
|
|
|
|
$updateNotifyQuery->where("status","<",2)->update(['status' => 2]);
|
|
|
|
$routers = RouteMap::where("project_id",$updateNotifyData->project_id)->offset($offset)->limit($perPage)->get()->sortBy(function($item) {
|
|
|
|
return array_search($item->source, ['page', 'product_category', 'product', 'news_category', 'news', 'blog_category', 'blog', 'product_keyword']);
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
$updateNotifyQuery->where("minor_languages_status","<",2)->update(['minor_languages_status' => 2]);
|
|
|
|
$routers = RouteMap::where("project_id",$updateNotifyData->project_id)->where("source","!=","product_keyword")->offset($offset)->limit($perPage)->get()->sortBy(function($item) {
|
|
|
|
return array_search($item->source, ['page', 'product_category', 'product', 'news_category', 'news', 'blog_category', 'blog']);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}else if($updateNotifyData->route == Notify::ROUTE_PRODUCT_KEYWORD){
|
|
|
|
//产品聚合页更新
|
|
|
|
$routers = RouteMap::where("project_id",$updateNotifyData->project_id)->where("source","product_keyword")->offset($offset)->limit($perPage)->get();
|
|
|
|
}else if($updateNotifyData->route == Notify::ROUTE_PRODUCT_VIDEO_KEYWORD){
|
|
|
|
//产品视频聚合页更新
|
|
|
|
$videoKeywordIdList = Keyword::where("project_id",$updateNotifyData->project_id)->where("status",1)->whereNotNull("route")->whereNotNull("video")->pluck("id")->toArray();
|
|
|
|
if (!empty($videoKeywordIdList)){
|
|
|
|
$routers = RouteMap::where("project_id",$updateNotifyData->project_id)->where("source","product_keyword")->whereIn("source_id",$videoKeywordIdList)->offset($offset)->limit($perPage)->get();
|
|
|
|
}
|
|
|
|
}else if($updateNotifyData->route == Notify::ROUTE_NOT_TRANSLATE){
|
|
|
|
//漏翻译
|
|
|
|
if ($updateNotifyData->type == Notify::TYPE_MINOR){
|
|
|
|
$routers = RouteMap::where("project_id",$updateNotifyData->project_id)->offset($offset)->limit($perPage)->get()->sortBy(function($item) {
|
|
|
|
return array_search($item->source, ['page', 'product_category', 'product', 'news_category', 'news', 'blog_category', 'blog', 'product_keyword']);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}else if($updateNotifyData->route == Notify::ROUTE_NEED){
|
|
|
|
//按需更新
|
|
|
|
if ($updateNotifyData->type == Notify::TYPE_MASTER){
|
|
|
|
$routers = $updateNotifyQuery->where("status","<",2)->offset($offset)->limit($perPage)->get();
|
|
|
|
$updateNotifyQuery->where("status","<",2)->update(['status' => 2]);
|
|
|
|
}else{
|
|
|
|
$routers = $updateNotifyQuery->where("minor_languages_status","<",2)->offset($offset)->limit($perPage)->get();
|
|
|
|
$updateNotifyQuery->where("minor_languages_status","<",2)->update(['minor_languages_status' => 2]);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
//按url更新
|
|
|
|
$urlArrMap = [];
|
|
|
|
$dataJson = json_decode($updateNotifyData->data);
|
|
|
|
$urlArr = $dataJson->url;
|
|
|
|
if (!empty($urlArr)){
|
|
|
|
if (count($urlArr) != 0){
|
|
|
|
foreach ($urlArr as $key => $item){
|
|
|
|
if (strpos($item, 'http://') !== false || strpos($item, 'https://') !== false) {
|
|
|
|
$pathUrl = parse_url($item);
|
|
|
|
if (isset($pathUrl["path"])){
|
|
|
|
$pathUrl = $pathUrl["path"];
|
|
|
|
if ($pathUrl == "/"){
|
|
|
|
$urlArrMap[] = "index";
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$urlArrMap[] = "index";
|
|
|
|
}
|
|
|
|
$pathInfo = urldecode($pathUrl);
|
|
|
|
$pageService = new PageService();
|
|
|
|
$analysisRouteArr = $pageService->analysisRoute($pathInfo);
|
|
|
|
if (isset($analysisRouteArr["router"])){
|
|
|
|
$urlArrMap[] = $analysisRouteArr["router"];
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$urlArrMap[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$pageNum = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$routeNew = [];
|
|
|
|
if (!empty($urlArrMap)){
|
|
|
|
foreach ($urlArrMap as $v){
|
|
|
|
$routerItem = RouteMap::where("project_id",$updateNotifyData->project_id)->where("route",$v)->first();
|
|
|
|
if (!empty($routerItem)){
|
|
|
|
$routeNew[] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($routeNew)){
|
|
|
|
$routeNew = array_values(array_unique(array_filter($routeNew)));
|
|
|
|
$routers = RouteMap::where("project_id",$updateNotifyData->project_id)->whereIn("route",$routeNew)->get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$routersInfo["routers"] = $routers;
|
|
|
|
$routersInfo["pageNum"] = $pageNum;
|
|
|
|
return $routersInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 数据详情入库数据处理
|
|
|
|
*/
|
|
|
|
public function htmlPageQueryDataHandle($routers,$updateNotifyData,$task_id,$isHasData = true)
|
|
|
|
{
|
|
|
|
$page = null;
|
|
|
|
$updateData = [];
|
|
|
|
$data = json_decode($updateNotifyData->data, true);
|
|
|
|
$updateNotifyData->domain = $data['domain'];
|
|
|
|
if ($updateNotifyData->route == Notify::ROUTE_ALL || $updateNotifyData->route == Notify::ROUTE_URL || $updateNotifyData->route == Notify::ROUTE_PRODUCT_KEYWORD || $updateNotifyData->route == Notify::ROUTE_NOT_TRANSLATE){
|
|
|
|
//全部更新
|
|
|
|
if ($isHasData && !empty($routers) && !$routers->isEmpty()){
|
|
|
|
foreach ($routers as $item){
|
|
|
|
$count = $this->isListAndGetCount($item,$updateNotifyData);
|
|
|
|
if ($count == 0 || $item->route == "index"){
|
|
|
|
$updateData['project_id'] = $updateNotifyData->project_id;
|
|
|
|
$updateData['id'] = $task_id;
|
|
|
|
$updateData['type'] = $item->source;
|
|
|
|
$updateData['route'] = $item->route;
|
|
|
|
$updateData['page'] = $page;
|
|
|
|
$updateData['domain'] =$updateNotifyData->domain;
|
|
|
|
$updateDataJson = json_encode($updateData);
|
|
|
|
//更新页面
|
|
|
|
$this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
|
|
|
|
}else{
|
|
|
|
for ($i = 1; $i <= $count; $i++) {
|
|
|
|
if ($i == 1){
|
|
|
|
$updateData['page'] = null;
|
|
|
|
}else{
|
|
|
|
$updateData['page'] = $i;
|
|
|
|
}
|
|
|
|
$updateData['project_id'] = $updateNotifyData->project_id;
|
|
|
|
$updateData['id'] = $task_id;
|
|
|
|
$updateData['type'] = $item->source;
|
|
|
|
$updateData['route'] = $item->route;
|
|
|
|
$updateData['domain'] =$updateNotifyData->domain;
|
|
|
|
$updateDataJson = json_encode($updateData);
|
|
|
|
//更新页面
|
|
|
|
$this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$isHasData){
|
|
|
|
//判断products,news,blog三个列表页是否存在路由,不存在主动更新
|
|
|
|
//手动更新所有关键词列表页(自定义top-search系列页面)
|
|
|
|
$this->checkProductsNewsBlogListAndGetCount($updateNotifyData,$task_id);
|
|
|
|
if ($updateNotifyData->type == Notify::TYPE_MASTER){
|
|
|
|
$this->productKeywordListAdnGetCount($updateNotifyData,$task_id);
|
|
|
|
}else{
|
|
|
|
if ($updateNotifyData->route == Notify::ROUTE_PRODUCT_KEYWORD){
|
|
|
|
$this->productKeywordListAdnGetCount($updateNotifyData,$task_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
//按需更新
|
|
|
|
if ($isHasData && !empty($routers) && !$routers->isEmpty()){
|
|
|
|
foreach ($routers as $item){
|
|
|
|
$count = $this->isListAndGetCount($item,$updateNotifyData);
|
|
|
|
if ($count == 0 || $item->type == "index"){
|
|
|
|
$updateData['project_id'] = $updateNotifyData->project_id;
|
|
|
|
$updateData['id'] = $task_id;
|
|
|
|
if ($item->type == "index"){
|
|
|
|
$updateData['type'] = "page";
|
|
|
|
$updateData['route'] = "index";
|
|
|
|
}else{
|
|
|
|
$updateData['type'] = $item->type;
|
|
|
|
$updateData['route'] = $item->route;
|
|
|
|
}
|
|
|
|
$updateData['page'] = $page;
|
|
|
|
$updateData['domain'] =$updateNotifyData->domain;
|
|
|
|
$updateDataJson = json_encode($updateData);
|
|
|
|
//更新页面
|
|
|
|
$this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
|
|
|
|
}else{
|
|
|
|
for ($i = 1; $i <= $count; $i++) {
|
|
|
|
if ($i == 1){
|
|
|
|
$updateData['page'] = null;
|
|
|
|
}else{
|
|
|
|
$updateData['page'] = $i;
|
|
|
|
}
|
|
|
|
$updateData['project_id'] = $updateNotifyData->project_id;
|
|
|
|
$updateData['id'] = $task_id;
|
|
|
|
$updateData['type'] = $item->type;
|
|
|
|
$updateData['route'] = $item->route;
|
|
|
|
$updateData['domain'] =$updateNotifyData->domain;
|
|
|
|
$updateDataJson = json_encode($updateData);
|
|
|
|
//更新页面
|
|
|
|
$this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$isHasData){
|
|
|
|
//判断products,news,blog三个列表页是否存在路由,不存在主动更新
|
|
|
|
$this->checkProductsNewsBlogListAndGetCount($updateNotifyData,$task_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
unset($routers);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 是否是列表,并返回页数
|
|
|
|
*/
|
|
|
|
public function isListAndGetCount($router,$updateNotifyData)
|
|
|
|
{
|
|
|
|
$count = 0;
|
|
|
|
$newsQuery = News::where("project_id",$updateNotifyData->project_id)->select("id")->where("status",1);
|
|
|
|
$blogQuery = Blog::where("project_id",$updateNotifyData->project_id)->select("id")->where("status",1);
|
|
|
|
$productsQuery = Product::where("project_id",$updateNotifyData->project_id)->select("id")->where("status",1)->whereNotNull('route');
|
|
|
|
if ($updateNotifyData->route == Notify::ROUTE_ALL || $updateNotifyData->route == Notify::ROUTE_URL){
|
|
|
|
if ($router->source == "news_category"){
|
|
|
|
if ($router->route == "news"){
|
|
|
|
$count = $newsQuery->count();
|
|
|
|
}else{
|
|
|
|
$count = $newsQuery->where("category_id","like","%".",".$router->source_id.","."%")->count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($router->source == "blog_category"){
|
|
|
|
if ($router->route == "blog"){
|
|
|
|
$count = $blogQuery->count();
|
|
|
|
}else{
|
|
|
|
$count = $blogQuery->where("category_id","like","%".",".$router->source_id.","."%")->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($router->source == "product_category"){
|
|
|
|
if ($router->route == "products"){
|
|
|
|
$count =$productsQuery->count();
|
|
|
|
}else{
|
|
|
|
$ids = [];
|
|
|
|
$productCategoryList = Category::getAllSonCategoryById($updateNotifyData->project_id,(int)$router->source_id);
|
|
|
|
if (!empty($productCategoryList)){
|
|
|
|
$productList = CategoryRelated::whereIn("cate_id",$productCategoryList)->get();
|
|
|
|
if (!empty($productList)){
|
|
|
|
foreach ($productList as $productV){
|
|
|
|
$ids[] = $productV->product_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$count =$productsQuery->whereIn("id",$ids)->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$routerMap = RouteMap::where("project_id",$updateNotifyData->project_id)->where("route",$router->route)->first();
|
|
|
|
if (!empty($routerMap)){
|
|
|
|
if ($router->type == "news_category"){
|
|
|
|
if ($router->route == "news"){
|
|
|
|
$count = $newsQuery->count();
|
|
|
|
}else{
|
|
|
|
$count = $newsQuery->where("category_id","like","%".",".$routerMap->source_id.","."%")->count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($router->type == "blog_category"){
|
|
|
|
if ($router->route == "blog"){
|
|
|
|
$count = $blogQuery->count();
|
|
|
|
}else{
|
|
|
|
$count = $blogQuery->where("category_id","like","%".",".$routerMap->source_id.","."%")->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($router->type == "product_category"){
|
|
|
|
if ($router->route == "products"){
|
|
|
|
$count = $productsQuery->count();
|
|
|
|
}else{
|
|
|
|
$count = $productsQuery->where("category_id","like","%,".(string)$routerMap->source_id.",%")->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($count != 0){
|
|
|
|
if ($router->type == "product_category"){
|
|
|
|
$webSettingNum = WebSettingNum::where("project_id",$updateNotifyData->project_id)->where("type",WebSettingNum::$productListType)->orderBy("id","desc")->first();
|
|
|
|
if (!empty($webSettingNum)){
|
|
|
|
$perPage = (int)$webSettingNum->num;
|
|
|
|
}else{
|
|
|
|
$perPage = Category::$productCategoryPagePercent; //产品每页条数
|
|
|
|
}
|
|
|
|
$total = (int)ceil($count / $perPage); //产品分类总页数
|
|
|
|
}elseif($router->type == "news_category"){
|
|
|
|
$webSettingNum = WebSettingNum::where("project_id",$updateNotifyData->project_id)->where("type",WebSettingNum::$newsListType)->orderBy("id","desc")->first();
|
|
|
|
if (!empty($webSettingNum)){
|
|
|
|
$perPage = (int)$webSettingNum->num;
|
|
|
|
}else{
|
|
|
|
$perPage = NewsCategory::$newsCategoryPagePercent; //新闻每页条数
|
|
|
|
}
|
|
|
|
$total = (int)ceil($count / $perPage); //新闻总页数
|
|
|
|
}else{
|
|
|
|
$webSettingNum = WebSettingNum::where("project_id",$updateNotifyData->project_id)->where("type",WebSettingNum::$blogListType)->orderBy("id","desc")->first();
|
|
|
|
if (!empty($webSettingNum)){
|
|
|
|
$perPage = (int)$webSettingNum->num;
|
|
|
|
}else{
|
|
|
|
$perPage = NewsCategory::$newsCategoryPagePercent; //博客每页条数
|
|
|
|
}
|
|
|
|
$total = (int)ceil($count / $perPage); //博客总页数
|
|
|
|
}
|
|
|
|
$count = $total;
|
|
|
|
}
|
|
|
|
return $count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 需要更新的页面,主站页面或者小语种页面
|
|
|
|
*/
|
|
|
|
public function pushHtmlPage($updateNotifyData, $updateDataJson,$taskId)
|
|
|
|
{
|
|
|
|
//更新页面
|
|
|
|
$mysqlData["created_at"] = now();
|
|
|
|
$mysqlData["updated_at"] = now();
|
|
|
|
$mysqlData["data"] =$updateDataJson;
|
|
|
|
$mysqlData["task_id"] =$taskId;
|
|
|
|
$data = json_decode($updateDataJson);
|
|
|
|
if (!empty($data->page)){
|
|
|
|
$page =",分页:".$data->page;
|
|
|
|
}else{
|
|
|
|
$page = "";
|
|
|
|
}
|
|
|
|
echo "创建项目路由:任务ID:" . $taskId .",项目ID:".$data->project_id.",域名:".$data->domain.",路由:".$data->route.$page. PHP_EOL;
|
|
|
|
|
|
|
|
if ($updateNotifyData->type == Notify::TYPE_MASTER){
|
|
|
|
UpdateMasterWebsiteModel::insertGetId($mysqlData);
|
|
|
|
}else{
|
|
|
|
UpdateMinorLanguagesModel::insertGetId($mysqlData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 判断products,news,blog三个列表页是否存在路由,不存在主动更新
|
|
|
|
*/
|
|
|
|
public function checkProductsNewsBlogListAndGetCount($updateNotifyData,$task_id)
|
|
|
|
{
|
|
|
|
$productsCount = 0;
|
|
|
|
$newsCount = 0;
|
|
|
|
$blogCount = 0;
|
|
|
|
//产品
|
|
|
|
$routerProductsMap = RouteMap::where("project_id",$updateNotifyData->project_id)->where("route","products")->first();
|
|
|
|
if (empty($routerProductsMap)){
|
|
|
|
$productsCount = Product::where("project_id",$updateNotifyData->project_id)->select("id")->where("status",1)->whereNotNull('route')->orderBy("id","DESC")->count();
|
|
|
|
if ($productsCount != 0){
|
|
|
|
$webSettingNum = WebSettingNum::where("project_id",$updateNotifyData->project_id)->where("type",WebSettingNum::$productListType)->orderBy("id","desc")->first();
|
|
|
|
if (!empty($webSettingNum)){
|
|
|
|
$perPage = (int)$webSettingNum->num;
|
|
|
|
}else{
|
|
|
|
$perPage = Category::$productCategoryPagePercent; //产品每页条数
|
|
|
|
}
|
|
|
|
$productsTotal = (int)ceil($productsCount / $perPage);
|
|
|
|
if ($productsTotal>=1){
|
|
|
|
for ($i = 1; $i <= $productsTotal; $i++) {
|
|
|
|
$updateData = [];
|
|
|
|
if ($i == 1){
|
|
|
|
$updateData['page'] = null;
|
|
|
|
}else{
|
|
|
|
$updateData['page'] = $i;
|
|
|
|
}
|
|
|
|
$updateData['project_id'] = $updateNotifyData->project_id;
|
|
|
|
$updateData['id'] = $task_id;
|
|
|
|
$updateData['type'] = "product_category";
|
|
|
|
$updateData['route'] = "products";
|
|
|
|
$updateData['domain'] =$updateNotifyData->domain;
|
|
|
|
$updateDataJson = json_encode($updateData);
|
|
|
|
//更新页面
|
|
|
|
$this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//新闻
|
|
|
|
$routerNewsMap = RouteMap::where("project_id",$updateNotifyData->project_id)->where("route","news")->first();
|
|
|
|
if (empty($routerNewsMap)){
|
|
|
|
$newsCount = News::where("project_id",$updateNotifyData->project_id)->select("id")->where("status",1)->orderBy("id","DESC")->count();
|
|
|
|
$webSettingNum = WebSettingNum::where("project_id",$updateNotifyData->project_id)->where("type",WebSettingNum::$newsListType)->orderBy("id","desc")->first();
|
|
|
|
if (!empty($webSettingNum)){
|
|
|
|
$perPage = (int)$webSettingNum->num;
|
|
|
|
}else{
|
|
|
|
$perPage = NewsCategory::$newsCategoryPagePercent;
|
|
|
|
}
|
|
|
|
$NewsTotal = (int)ceil($newsCount / $perPage);
|
|
|
|
if ($NewsTotal>=1){
|
|
|
|
for ($i = 1; $i <= $NewsTotal; $i++) {
|
|
|
|
$updateData = [];
|
|
|
|
if ($i == 1){
|
|
|
|
$updateData['page'] = null;
|
|
|
|
}else{
|
|
|
|
$updateData['page'] = $i;
|
|
|
|
}
|
|
|
|
$updateData['project_id'] = $updateNotifyData->project_id;
|
|
|
|
$updateData['id'] = $task_id;
|
|
|
|
$updateData['type'] = "news_category";
|
|
|
|
$updateData['route'] = "news";
|
|
|
|
$updateData['domain'] =$updateNotifyData->domain;
|
|
|
|
$updateDataJson = json_encode($updateData);
|
|
|
|
//更新页面
|
|
|
|
$this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//博客
|
|
|
|
$routerBlogMap = RouteMap::where("project_id",$updateNotifyData->project_id)->where("route","blog")->first();
|
|
|
|
if (empty($routerBlogMap)){
|
|
|
|
$blogCount = Blog::where("project_id",$updateNotifyData->project_id)->select("id")->where("status",1)->orderBy("id","DESC")->count();
|
|
|
|
$webSettingNum = WebSettingNum::where("project_id",$updateNotifyData->project_id)->where("type",WebSettingNum::$blogListType)->orderBy("id","desc")->first();
|
|
|
|
if (!empty($webSettingNum)){
|
|
|
|
$perPage = (int)$webSettingNum->num;
|
|
|
|
}else{
|
|
|
|
$perPage = NewsCategory::$newsCategoryPagePercent;
|
|
|
|
}
|
|
|
|
$BlogTotal = (int)ceil($blogCount / $perPage);
|
|
|
|
if ($BlogTotal>=1){
|
|
|
|
for ($i = 1; $i <= $BlogTotal; $i++) {
|
|
|
|
$updateData = [];
|
|
|
|
if ($i == 1){
|
|
|
|
$updateData['page'] = null;
|
|
|
|
}else{
|
|
|
|
$updateData['page'] = $i;
|
|
|
|
}
|
|
|
|
$updateData['project_id'] = $updateNotifyData->project_id;
|
|
|
|
$updateData['id'] = $task_id;
|
|
|
|
$updateData['type'] = "blog_category";
|
|
|
|
$updateData['route'] = "blog";
|
|
|
|
$updateData['domain'] =$updateNotifyData->domain;
|
|
|
|
$updateDataJson = json_encode($updateData);
|
|
|
|
//更新页面
|
|
|
|
$this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 手动更新所有关键词列表页(自定义top-search系列页面)
|
|
|
|
*/
|
|
|
|
public function productKeywordListAdnGetCount($updateNotifyData,$task_id)
|
|
|
|
{
|
|
|
|
$productKeywordInfo = $this->projectProductKeywordsDataAndHandle($updateNotifyData->project_id);
|
|
|
|
if (isset($productKeywordInfo["productKeywordListInfo"]) && !empty($productKeywordInfo["productKeywordListInfo"])){
|
|
|
|
foreach ($productKeywordInfo["productKeywordListInfo"] as $productKeywordItem){
|
|
|
|
if ($productKeywordItem['total']>=1){
|
|
|
|
for ($i = 1; $i <= $productKeywordItem['total']; $i++) {
|
|
|
|
if ($i == 1){
|
|
|
|
$updateData['page'] = null;
|
|
|
|
}else{
|
|
|
|
$updateData['page'] = $i;
|
|
|
|
}
|
|
|
|
$updateData['project_id'] = $updateNotifyData->project_id;
|
|
|
|
$updateData['id'] = $task_id;
|
|
|
|
$updateData['type'] = "product_keyword_list";
|
|
|
|
$updateData['route'] = $productKeywordItem['route'];
|
|
|
|
$updateData['domain'] =$updateNotifyData->domain;
|
|
|
|
$updateDataJson = json_encode($updateData);
|
|
|
|
//更新页面
|
|
|
|
$this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($productKeywordInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取更新进度表
|
|
|
|
*/
|
|
|
|
public function getUpdateProgress($projectId,$type)
|
|
|
|
{
|
|
|
|
$updateProgressQuery = UpdateProgressModel::where("project_id",(int)$projectId)->orderBy("id","desc");
|
|
|
|
if ($type == "master_website"){
|
|
|
|
$updateProgressQuery = $updateProgressQuery->where("type",1)->first();
|
|
|
|
}else{
|
|
|
|
$updateProgressQuery = $updateProgressQuery->where("type",2)->first();
|
|
|
|
}
|
|
|
|
return $updateProgressQuery;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 项目产品关键词列表路由,及数据处理
|
|
|
|
*/
|
|
|
|
public function projectProductKeywordsDataAndHandle($projectId): array
|
|
|
|
{
|
|
|
|
$keywordsArr = [];
|
|
|
|
$keywordModel = new Keyword();
|
|
|
|
$keywords = $keywordModel->where("project_id",$projectId)->get();
|
|
|
|
|
|
|
|
if (!empty($keywords)){
|
|
|
|
foreach ($keywords->toArray() as $item){
|
|
|
|
$firstLetter = mb_strtolower(mb_substr($item['title'], 0, 1, 'utf-8'), 'utf-8');
|
|
|
|
$keywordsArr["top-search"][] = $item;
|
|
|
|
if (in_array($firstLetter, $keywordModel->routeZ)){
|
|
|
|
$keywordsArr["top-search-0"][] = $item;
|
|
|
|
}else{
|
|
|
|
$keywordsArr["top-search-".$firstLetter][] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [
|
|
|
|
"productKeywordListInfo"=>$this->projectProductKeywordsDataAndTotalPageHandle($keywordsArr),
|
|
|
|
"productKeywords"=>$keywords,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 项目产品关键词列表路由数据及总页数
|
|
|
|
*/
|
|
|
|
public function projectProductKeywordsDataAndTotalPageHandle($data): array
|
|
|
|
{
|
|
|
|
$projectProjectKeywords = [];
|
|
|
|
$perPage = 80;
|
|
|
|
if (!empty($data)){
|
|
|
|
foreach ($data as $key => $item){
|
|
|
|
$count = count($item);
|
|
|
|
$total = (int)ceil($count / $perPage);
|
|
|
|
$projectProjectKeywords[$key]["route"] =$key;
|
|
|
|
$projectProjectKeywords[$key]["total"] =$total;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $projectProjectKeywords;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 站点域名处理
|
|
|
|
*/
|
|
|
|
public function domainHandle($domain)
|
|
|
|
{
|
|
|
|
$langDomain = str_replace("http://","",$domain);
|
|
|
|
$langDomain = str_replace("https://","",$langDomain);
|
|
|
|
$langDomain = str_replace("/","",$langDomain);
|
|
|
|
return $langDomain;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 小语种自定义创建站点目录页面拷贝
|
|
|
|
*/
|
|
|
|
public function copyPageMinorWebsiteToCreateDomainDirectory($project)
|
|
|
|
{
|
|
|
|
$countryCustomInfo = CountryCustom::with("countryCustomLanguage")->where("language_id","!=",$project->main_lang_id)->where("project_id",$project->id)->where("status",1)->where("is_create",1)->get();
|
|
|
|
if (!empty($countryCustomInfo)){
|
|
|
|
$langDomain = $this->domainHandle($project->domain);
|
|
|
|
foreach ($countryCustomInfo as $countryCustomInfoItem){
|
|
|
|
$publicLangPath = public_path($langDomain."/".$countryCustomInfoItem->countryCustomLanguage->short);
|
|
|
|
$publicCreatePath = public_path($countryCustomInfoItem->custom_domain);
|
|
|
|
if (file_exists($publicLangPath)){
|
|
|
|
if (!file_exists($publicCreatePath)){
|
|
|
|
mkdir($publicCreatePath,0777);
|
|
|
|
}
|
|
|
|
File::copyDirectory($publicLangPath, $publicCreatePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|