1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774 |
- <?php
- /**
- * 易优CMS
- * ============================================================================
- * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
- * 网站地址: http://www.eyoucms.com
- * ----------------------------------------------------------------------------
- * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
- * ============================================================================
- * Author: 小虎哥 <1105415366@qq.com>
- * Date: 2018-4-3
- */
-
- namespace app\home\controller;
- use think\Db;
- use think\template\driver\File;
-
- class Buildmhtml extends Base
- {
- public $php_sessid;
- public function _initialize()
- {
- parent::_initialize();
- @ini_set('memory_limit','-1');
- $this->php_sessid = !empty($_COOKIE['PHPSESSID']) ? $_COOKIE['PHPSESSID'] : '';
- if (!session('?admin_id')) {
- $this->error("只允许后台管理员操作!");
- }
-
- $this->makeminfo = \think\Db::name('weapp_makemhtml')->find(1);
- }
-
- /*
- * 清理缓存
- */
- private function clearCache()
- {
- cache("channel_page_total_serialize".$this->php_sessid, null);
- cache("channel_info_serialize".$this->php_sessid, null);
- cache("has_children_Row_serialize".$this->php_sessid, null);
- cache("aid_arr_serialize".$this->php_sessid, null);
- cache("channel_arr_serialize".$this->php_sessid, null);
- cache("article_info_serialize".$this->php_sessid, null);
- cache("article_page_total_serialize".$this->php_sessid, null);
- cache("article_tags_serialize".$this->php_sessid, null);
- cache("article_attr_info_serialize".$this->php_sessid, null);
- cache("article_children_row_serialize".$this->php_sessid, null);
- }
-
- /*
- * 获取全站生成时,需要生成的页面的个数
- */
- public function buildIndexAll()
- {
- \think\Session::pause(); // 暂停session,防止session阻塞机制
- $this->clearCache();
-
- $uphtmltype = input('param.uphtmltype/d');
- if (!empty($uphtmltype)) { // 指定文档后全部生成
- $this->buildAppointAll($uphtmltype);
- }
- else { // 更新全部
- $channelData = $this->getChannelData(0);
- $archivesArr = getAllArchivesAid(0, $this->home_lang);
- $articleData_pagetotal = count($archivesArr['aid_arr']);
- $allpagetotal = 1 + $channelData['pagetotal'] + $articleData_pagetotal;
- $msg = $this->handleBuildIndex();
-
- $data = [
- 'achievepage' => 1,
- 'channelpagetotal' => $channelData['pagetotal'],
- 'articlepagetotal' => $articleData_pagetotal,
- 'allpagetotal' => $allpagetotal,
- ];
- $this->success($msg, null, $data);
- }
- }
-
- /*
- * 指定文档生成全部(涉及栏目、首页)
- */
- private function buildAppointAll($uphtmltype = 0)
- {
- if (1 == $uphtmltype) { // 指定时间的文档更新
- $seo_start_time = $this->eyou['global']['seo_start_time'];
- $seo_start_time = !empty($seo_start_time) ? strtotime($seo_start_time) : 0;
- $startid = Db::name('archives')->where([
- 'add_time' => ['egt', $seo_start_time],
- ])->order('aid asc')->limit(1)->value('aid');
- if (empty($startid)) {
- $startid = Db::name('archives')->max('aid');
- $startid += 1;
- }
- }
- else if (2 == $uphtmltype) { // 指定ID文档的全部更新
- $startid = $this->eyou['global']['seo_startid2'];
- }
- $archivesArr = getAllArchivesAid(0, $this->home_lang, $startid);
- $articleData_pagetotal = count($archivesArr['aid_arr']);
- $channelpagetotal = 0;
- $typeid_arr = [];
- if (!empty($articleData_pagetotal)) {
- $typeid_arr = $archivesArr['typeid_arr'];
- foreach ($archivesArr['typeid_arr'] as $key => $val) {
- // 包含所有的上级栏目
- $allParentRow = model('Arctype')->getAllPid($val);
- $typeid_arr = array_merge($typeid_arr, get_arr_column($allParentRow, 'id'));
- }
- $typeid_arr = array_unique($typeid_arr);
- $channelData = $this->getChannelData($typeid_arr, false);
- $channelpagetotal = intval($channelData['pagetotal']);
- }
-
- $allpagetotal = 1 + $channelpagetotal + $articleData_pagetotal;
- $msg = $this->handleBuildIndex();
-
- $data = [
- 'achievepage' => 1,
- 'channelpagetotal' => $channelpagetotal,
- 'articlepagetotal' => $articleData_pagetotal,
- 'allpagetotal' => $allpagetotal,
- 'startid' => $startid,
- 'typeids' => implode(',', $typeid_arr),
- ];
- $this->success($msg, null, $data);
- }
-
- /*
- * 生成首页静态页面
- */
- public function buildIndex()
- {
- \think\Session::pause(); // 暂停session,防止session阻塞机制
- $msg = $this->handleBuildIndex();
- $this->success($msg);
- }
-
- /*
- * 处理生成首页
- */
- private function handleBuildIndex()
- {
- $msg = '';
- $indexurl = $this->request->domain().$this->root_dir;
- // 保存的文件名
- $seo_html_position_arr = explode('/', $this->eyou['global']['seo_html_position']);
- if (!empty($seo_html_position_arr)) {
- $savefilename = end($seo_html_position_arr);
- } else {
- $savefilename = 'index.html';
- }
- //获取手机路径
- $makeminfo = $this->makeminfo;
-
- if($makeminfo['web_url_model']==2){
- $seo_html_arcdir='';
- }else{
- $seo_html_arcdir=$makeminfo['value'];
- }
-
-
-
- if (!empty($this->eyou['global']['seo_showmod'])){
- $seo_html_position = !empty($this->eyou['global']['seo_html_position']) ? $this->eyou['global']['seo_html_position'] : '';
- if ($seo_html_position) {
- $seo_html_position = preg_replace('/^\.{1,}([\\\\\/]+)/i', '', $seo_html_position);
- $seo_html_position = ltrim($seo_html_position, '/');
- $seo_html_position = ROOT_PATH.$seo_html_position;
- $seo_html_position_path = dirname($seo_html_position);
- tp_mkdir($seo_html_position_path);
- clearstatcache(); // 清除文件夹权限缓存
- if (!is_writeable($seo_html_position_path)) {
- $msg = "目录 {$seo_html_position_path} 没有权限写入,生成失败";
- return $msg;
- }
- }
- $result['pageurl'] = $this->request->domain() . ROOT_DIR; // 获取当前页面URL
- // $result['pageurl_m'] = pc_to_mobile_url($result['pageurl']); // 获取当前页面对应的移动端URL
- // 移动端域名
- // $result['mobile_domain'] = '';
- // if (!empty($this->eyou['global']['web_mobile_domain_open']) && !empty($this->eyou['global']['web_mobile_domain'])) {
- // $result['mobile_domain'] = $this->eyou['global']['web_mobile_domain'] . '.' . $this->request->rootDomain();
- // }
- $eyou = array(
- 'field' => $result,
- );
- $this->eyou = array_merge($this->eyou, $eyou);
- $this->assign('eyou', $this->eyou);
- try {
- // $savepath = '.'.$seo_html_arcdir.'/'.$savefilename;
- // if($makeminfo['web_url_model']==2){
- // $savepath = '.'.$makeminfo['value'].'/'.$savefilename;
- // }
- $makeminfo =$this->makeminfo;
- //$seo_html_arcdir=$makeminfo['value'];
- $savepath = '.'.$makeminfo['value'].'/'.$savefilename;
-
-
- $tpl = 'index';
- $seo_html_templet = !empty($this->eyou['global']['seo_html_templet']) ? $this->eyou['global']['seo_html_templet'] : '';
- $seo_html_templet_arr = explode('.',$seo_html_templet);
- if(!empty($seo_html_templet_arr[0])){
- $tpl = $seo_html_templet_arr[0];
- }
- $this->request->get(['m' => 'Index']); // 首页焦点
- $this->filePutContents($savepath, $tpl, 'mobile', 0, '/', 0, 1, $result);
- if ($seo_html_position){
- //@copy($savepath, $seo_html_position);
- // @copy($savepath, './index.html');
- // $msg .= "成功更新主页HTML:<a href='".$indexurl."' target='_blank' onclick='layer.closeAll();'>浏览...</a><br />";
- }else{
- // $msg .= "成功更新主页HTML:".$savepath."<br /><a href='$savepath' target='_blank' onclick='layer.closeAll();'>浏览...</a><br />";
- }
- } catch (\Exception $e) {
- //$msg .= '<span>index.html生成失败!' . $e->getMessage() . '</span><br>';
- }
- }else{
- //@unlink('index.html');
- @unlink($savefilename);
- $msg .= "采用动态浏览模式:<a href='".$indexurl."' target='_blank' onclick='layer.closeAll();'>浏览...</a><br />";
- }
-
- return $msg;
- }
-
- /*
- * 写入静态页面
- */
- private function filePutContents($savepath, $tpl, $model = 'mobile', $pages = 0, $dir = '/', $tid = 0, $top = 1, $result = [])
- {
-
- ob_start();
- static $templateConfig = null;
- null === $templateConfig && $templateConfig = \think\Config::get('template');
- $templateConfig['view_path'] = "./template/".TPL_THEME."mobile/";
- $template = "./template/".TPL_THEME."{$model}/{$tpl}.{$templateConfig['view_suffix']}";
- $content = $this->fetch($template, [], [], $templateConfig);
- /*解决模板里没有设置编码的情况*/
- // if (!stristr($content, 'utf-8')) {
- // $content = str_ireplace('<head>', "<head>\n<meta charset='utf-8'>", $content);
- // }
- /*end*/
-
- /*解决手机端图片路径问题*/
- $url = tpCache('web.web_basehost');
- $pattern='#<img(.*?)src="(?!(https|http):)([^"]+)"#';
- $content = preg_replace($pattern,'<img $1 src="' .$url.'$3'.'"',$content);
-
- /*解决手机端动态页面问题*/
- $content = preg_replace('#"/index.php(.*?)#','"'.$url.'/index.php$1',$content);
-
- /*解决模板里有pc样式路径的情况*/
- if (stristr($content, '/template/pc/')) {
- $content = str_ireplace('/template/pc/', "/template/mobile/", $content);
- }
- /*解决模板里有pc样式路径的情况*/
- if (stristr($content, '/template/eyou/pc/')) {
- $content = str_ireplace('/template/eyou/pc/', "/template/eyou/mobile/", $content);
- }
- /*解决模板里有pc样式路径的情况*/
- if (stristr($content, '/template/default/pc/')) {
- $content = str_ireplace('/template/default/pc/', "/template/default/mobile/", $content);
- }
- if (stristr($content, '/tags/')) {
- $content = str_ireplace('/tags/', "/m/tags/", $content);
- }
-
- if ($pages > 0) {
- $page = "/<a(.*?)href(\s*)=(\s*)[\'|\"](.*?)page=([0-9]*)(.*?)data-ey_fc35fdc=[\'|\"]html[\'|\"](.*?)>/i";
- preg_match_all($page, $content, $matchpage);
-
- $dir = trim($dir, '.');
-
- $seo_html_listname = $this->eyou['global']['seo_html_listname'];
-
- foreach ($matchpage[0] as $key1 => $value1) {
- if ($matchpage[5][$key1] == 1) {
- if ($top == 1) {
- $url = $dir;
- } elseif ($top == 2) {
- $url = $dir . '/lists_' . $tid . '.html';
- } else {
- $url = $dir . '/lists_' . $tid . '.html';
- }
- } else {
- if ($seo_html_listname == 4) {
- if (!empty($result['rulelist'])) {
- if (!preg_match('/{page}/i', $result['rulelist'])) { // 没有分页变量的情况
- $rulelist_filename = '';
- } else {
- $rulelist = trim($result['rulelist'], '/');
- $rulelist_filename = preg_replace('/^((.*)\/)?([^\/]+)$/i', '${3}', $rulelist);
- $rulelist_filename = str_replace("{tid}", $tid, $rulelist_filename);
- $rulelist_filename = str_replace("{page}", $matchpage[5][$key1], $rulelist_filename);
- }
- $url = $dir;
- if (!empty($rulelist_filename)) {
- $url .= '/' . $rulelist_filename;
- }
- }else{
- $url = $dir . '/list_' . $tid . '_' . $matchpage[5][$key1] . '.html';
- }
- } else {
- $url = $dir . '/lists_' . $tid . '_' . $matchpage[5][$key1] . '.html';
- }
- }
-
- $url = ROOT_DIR . '/' . trim($url, '/');
-
- $value1_new = preg_replace('/href(\s*)=(\s*)[\'|\"]([^\'\"]*)[\'|\"]/i', '', $value1);
- $value1_new = str_replace('data-ey_fc35fdc=', " href=\"{$url}\" data-ey_fc35fdc=", $value1_new);
- $content = str_ireplace($value1, $value1_new, $content);
-
- }
- }
-
- // $content = $this->pc_to_mobile_js($content, $result); // 生成静态模式下,自动加上PC端跳转移动端的JS代码
- echo $content;
- $_cache = ob_get_contents();
- ob_end_clean();
- static $File = null;
- null === $File && $File = new File;
- $File->fwrite($savepath, $_cache);
- }
- /*
- * 生成文档静态页面
- */
- public function buildArticle()
- {
- function_exists('set_time_limit') && set_time_limit(0);
- \think\Session::pause(); // 暂停session,防止session阻塞机制
- $typeid = input("param.id/d", 0); // 栏目ID
- $findex = input("param.findex/d", 0);
- $achievepage = input("param.achieve/d", 0); // 已完成文档数
- if (empty($findex) && empty($achievepage)){
- $this->clearCache();
- }
- $data = $this->handelBuildArticleList($typeid, $findex, $achievepage,true,20);
-
- $this->success($data[0], null, $data[1]);
- }
- /*
- * 批量生成文档静态页面时候生成
- ** $typeid 栏目id
- * $aid 内容页id
- * $achievepage 已完成文档数
- * $batch 是否分批次执行,true:分批,false:不分批
- * limit 每次执行多少条数据
- * type 执行类型,0:aid指定的文档页,1:上一篇,2:下一篇
- */
- private function handelBuildArticleList($typeid, $nextid = 0, $achievepage = 0, $batch = true, $limit = 20)
- {
- !empty($this->eyou['global']['seo_pagesize']) && $limit = $this->eyou['global']['seo_pagesize'];
- $startid = '';
- $endid = '';
- $uphtmltype = input('param.uphtmltype/d');
- if (!empty($uphtmltype)) { // 更新选项/指定时间或者文档ID,最后都是转为以文档起始ID
- $startid = input('param.startid/d');
- empty($startid) && $startid = !empty($this->eyou['global']['seo_startid']) ? $this->eyou['global']['seo_startid'] : '';
- $endid = !empty($this->eyou['global']['seo_endid']) ? $this->eyou['global']['seo_endid'] : '';
- }
- $msg = "";
- $globalConfig = $this->eyou['global'];
- $result = $this->getArticleAidData($typeid,$startid,$endid);
- $aid_arr = $result['aid_arr'];
- $channel_arr = $result['channel_arr'];
- $allAttrInfo = getAllAttrInfo($channel_arr);
- $allTags = $result['allTags'];
- $has_children_Row = $result['has_children_Row'];
-
- $data['allpagetotal'] = $pagetotal = $result['pagetotal'];
- $data['achievepage'] = $achievepage;
- $data['pagetotal'] = 0;
- if ($batch && $pagetotal > $achievepage) {
- while ($limit && isset($aid_arr[$nextid])) {
- $archives = getAllArchives($this->home_lang, 0, $aid_arr[$nextid]);
- $row = $archives['info'][0];
- $arctypeRow = $archives['arctypeRow'];
- $attrInfo = getOneAttrInfo($allAttrInfo, $aid_arr[$nextid]);
- $msg .= $msg_temp = $this->createArticle($row, $globalConfig, $arctypeRow, $allTags, $has_children_Row, $attrInfo);
- $data['achievepage'] += 1;
- $limit--;
- $nextid++;
- }
- $data['findex'] = $nextid;
- } else if (!$batch) {
- foreach ($aid_arr as $key => $val) {
- $archives = getAllArchives($this->home_lang, 0, $val);
- $row = $archives['info'][0];
- $arctypeRow = $archives['arctypeRow'];
- $attrInfo = getOneAttrInfo($allAttrInfo, $val);
- $msg .= $msg_temp = $this->createArticle($row, $globalConfig, $arctypeRow, $allTags, $has_children_Row, $attrInfo);
- $data['achievepage'] += 1;
- $data['findex'] = $key;
- }
- }
- if ($data['allpagetotal'] == $data['achievepage']) { //生成完全部页面,删除缓存
- cache("aid_arr_serialize".$this->php_sessid, null);
- cache("channel_arr_serialize".$this->php_sessid, null);
- cache("article_page_total_serialize".$this->php_sessid, null);
- cache("article_tags_serialize".$this->php_sessid, null);
- cache("article_attr_info_serialize".$this->php_sessid, null);
- cache("article_children_row_serialize".$this->php_sessid, null);
- }
-
- return [$msg, $data];
- }
- /*
- * 获取所有需要生成静态的文档页面aid集合及相关信息
- * $typeid 栏目id,0:表示生成全部
- * $startid 起始ID(空或0表示从头开始)
- * $endid 结束ID(空或0表示直到结束ID)
- */
- private function getArticleAidData($typeid = 0,$startid = 0,$endid = 0){
- $aid_arr_serialize = cache("aid_arr_serialize".$this->php_sessid);
- if (empty($aid_arr_serialize)){
- $archivesArr = getAllArchivesAid($typeid, $this->home_lang,$startid,$endid);
- $aid_arr = $archivesArr['aid_arr'];
- $channel_arr = $archivesArr['channel_arr'];
- $pagetotal = count($aid_arr);
- $allTags = getAllTags();
- /*获取所有栏目是否有子栏目的数组*/
- $has_children_Row = Db::name('Arctype')->field('parent_id, count(id) AS total')->where([
- 'current_channel'=>['neq', 51], // 过滤问答模型
- 'is_del' => 0,
- ])->group('parent_id')->getAllWithIndex('parent_id');
- cache("aid_arr_serialize".$this->php_sessid, serialize($aid_arr), null, 'buildhtml');
- cache("channel_arr_serialize".$this->php_sessid, serialize($channel_arr), null, 'buildhtml');
- cache("article_page_total_serialize".$this->php_sessid, $pagetotal, null, 'buildhtml');
- cache("article_tags_serialize".$this->php_sessid, serialize($allTags), null, 'buildhtml');
- cache("article_children_row_serialize".$this->php_sessid, serialize($has_children_Row), null, 'buildhtml');
- }else{
- $aid_arr = unserialize($aid_arr_serialize);
- $channel_arr = cache("channel_arr_serialize".$this->php_sessid);
- $channel_arr = unserialize($channel_arr);
- $pagetotal = cache("article_page_total_serialize".$this->php_sessid);
- $allTags = unserialize(cache("article_tags_serialize".$this->php_sessid));
- $has_children_Row = unserialize(cache("article_children_row_serialize".$this->php_sessid));
- }
-
- return [
- 'aid_arr' => $aid_arr,
- 'channel_arr' => $channel_arr,
- 'pagetotal' => $pagetotal,
- 'allTags' => $allTags,
- 'has_children_Row' => $has_children_Row
- ];
- }
-
- /**
- * 获取所有详情页数据
- * $typeid 栏目id
- * $aid 文章id
- * $type 类型,0:aid指定的内容,1:上一篇,2:下一篇
- */
- private function getArticleData($typeid, $aid, $type = 0)
- {
- $info_serialize = cache("article_info_serialize".$this->php_sessid);
- if (empty($info_serialize)) {
- if ($type == 0) {
- $data = getAllArchives($this->home_lang, $typeid, $aid);
- } else if ($type == 1) {
- $data = getPreviousArchives($this->home_lang, $typeid, $aid);
- } else if ($type == 2) {
- $data = getNextArchives($this->home_lang, $typeid, $aid);
- }
- $info = $data['info'];
- $aid_arr = $typeid_arr = $channel_arr = [];
- foreach ($info as $key => $val) {
- $aid_arr[] = $val['aid'];
- $typeid_arr[] = $val['typeid'];
- $channel_arr[$val['channel']][] = $val['aid'];
- }
- $pagetotal = count($info);
- $allTags = getAllTags($aid_arr);
- $allAttrInfo = getAllAttrInfo($channel_arr);
- /*获取所有栏目是否有子栏目的数组*/
- $has_children_Row = model('Arctype')->hasChildren($typeid_arr);
- cache("article_info_serialize".$this->php_sessid, serialize($data), null, 'buildhtml');
- cache("article_page_total_serialize".$this->php_sessid, $pagetotal, null, 'buildhtml');
- cache("article_tags_serialize".$this->php_sessid, serialize($allTags), null, 'buildhtml');
- cache("article_attr_info_serialize".$this->php_sessid, serialize($allAttrInfo), null, 'buildhtml');
- cache("article_children_row_serialize".$this->php_sessid, serialize($has_children_Row), null, 'buildhtml');
- } else {
- $data = unserialize($info_serialize);
- $pagetotal = cache("article_page_total_serialize".$this->php_sessid);
- $allTags = unserialize(cache("article_tags_serialize".$this->php_sessid));
- $allAttrInfo = unserialize(cache("article_attr_info_serialize".$this->php_sessid));
- $has_children_Row = unserialize(cache("article_children_row_serialize".$this->php_sessid));
- }
-
- return ['data' => $data, 'pagetotal' => $pagetotal, 'allTags' => $allTags, 'allAttrInfo' => $allAttrInfo, 'has_children_Row' => $has_children_Row];
- }
-
- /**
- * 更新文档内容时候生成处理生成内容页
- * $typeid 栏目id
- * $aid 内容页id
- * $findex 下一次执行栏目id
- * $achievepage 已完成文档数
- * $batch 是否分批次执行,true:分批,false:不分批
- * limit 每次执行多少条数据
- * type 执行类型,0:aid指定的文档页,1:上一篇,2:下一篇
- *
- */
- private function handelBuildArticle($typeid, $aid = 0, $nextid = 0, $achievepage = 0, $batch = true, $limit = 20, $type = 0)
- {
- $msg = "";
- $globalConfig = $this->eyou['global'];
- $result = $this->getArticleData($typeid, $aid, $type);
- $info = $result['data']['info'];
- $arctypeRow = $result['data']['arctypeRow'];
- $allTags = $result['allTags'];
- $has_children_Row = $result['has_children_Row'];
- $allAttrInfo = $result['allAttrInfo'];
- $data['allpagetotal'] = $pagetotal = $result['pagetotal'];
- $data['achievepage'] = $achievepage;
- $data['pagetotal'] = 0;
-
- if ($batch && $pagetotal > $achievepage) {
- while ($limit && isset($info[$nextid])) {
- $row = $info[$nextid];
- $msg .= $msg_temp = $this->createArticle($row, $globalConfig, $arctypeRow, $allTags, $has_children_Row, $allAttrInfo);
- $data['achievepage'] += 1;
- $limit--;
- $nextid++;
- }
- $data['findex'] = $nextid;
- } else if (!$batch) {
- foreach ($info as $key => $row) {
- $msg .= $msg_temp = $this->createArticle($row, $globalConfig, $arctypeRow, $allTags, $has_children_Row, $allAttrInfo);
- $data['achievepage'] += 1;
- $data['findex'] = $key;
- }
- }
- if ($data['allpagetotal'] == $data['achievepage']) { //生成完全部页面,删除缓存
- cache("article_info_serialize".$this->php_sessid, null);
- cache("article_page_total_serialize".$this->php_sessid, null);
- cache("article_tags_serialize".$this->php_sessid, null);
- cache("article_attr_info_serialize".$this->php_sessid, null);
- cache("article_children_row_serialize".$this->php_sessid, null);
- }
-
- return [$msg, $data];
- }
-
- /*
- * 生成详情页静态页面
- */
- private function createArticle($result, $globalConfig, $arctypeRow, $allTags, $has_children_Row, $allAttrInfo)
- {
- $msg = "";
- $aid = $result['aid'];
- static $arc_seo_description_length = null;
- null === $arc_seo_description_length && $arc_seo_description_length = config('global.arc_seo_description_length');
- $this->request->get(['aid' => $aid]);
- $this->request->get(['tid' => $result['typeid']]);
-
- $arctypeInfo = $arctypeRow[$result['typeid']];
- /*排除文档模型与栏目模型对不上的文档 \ 问答模型 \ 外部链接跳转*/
- if (empty($result) || $arctypeInfo['current_channel'] != $result['channel'] || 51 == $result['channel']) {
- return false;
- }
- /*--end*/
- $arctypeInfo = model('Arctype')->parentAndTopInfo($result['typeid'], $arctypeInfo);
- /*自定义字段的数据格式处理*/
- $arctypeInfo = $this->fieldLogic->getTableFieldList($arctypeInfo, config('global.arctype_channel_id'));
- /*是否有子栏目,用于标记【全部】选中状态*/
- $arctypeInfo['has_children'] = !empty($has_children_Row[$result['typeid']]) ? 1 : 0;
- /*--end*/
- // 文档模板文件,不指定文档模板,默认以栏目设置的为主
- empty($result['tempview']) && $result['tempview'] = $arctypeInfo['tempview'];
-
- /*给没有type前缀的字段新增一个带前缀的字段,并赋予相同的值*/
- foreach ($arctypeInfo as $key => $val) {
- if (!preg_match('/^type/i', $key)) {
- $key_new = 'type' . $key;
- !array_key_exists($key_new, $arctypeInfo) && $arctypeInfo[$key_new] = $val;
- }
- }
- /*--end*/
-
- $result = array_merge($arctypeInfo, $result);
- //移动端详情
- if (!empty($result['content_ey_m'])){
- $result['content'] = $result['content_ey_m'];
- }
- // 获取当前页面URL
- $result['arcurl'] = $result['pageurl'] = $result['pageurl_m'] = '';
- if ($result['is_jump'] != 1) {
- $result['arcurl'] = $result['pageurl'] = arcurl('home/View/index', $result, true, true);
- $result['pageurl_m'] = pc_to_mobile_url($result['pageurl'], $result['typeid'], $result['aid']); // 获取当前页面对应的移动端URL
- }
- /*--end*/
-
- // 移动端域名
- $result['mobile_domain'] = '';
- if (!empty($this->eyou['global']['web_mobile_domain_open']) && !empty($this->eyou['global']['web_mobile_domain'])) {
- $result['mobile_domain'] = $this->eyou['global']['web_mobile_domain'] . '.' . $this->request->rootDomain();
- }
-
- $result['seo_title'] = set_arcseotitle($result['title'], $result['seo_title'], $result['typename'], $result['typeid']);
- $result['seo_description'] = checkStrHtml($result['seo_description']);
- $result['tags'] = empty($allTags[$aid]) ? '' : implode(',', $allTags[$aid]);
- $result['litpic'] = handle_subdir_pic($result['litpic']); // 支持子目录
- $result = view_logic($aid, $result['channel'], $result, $allAttrInfo); // 模型对应逻辑
- $result = $this->fieldLogic->getChannelFieldList($result, $result['channel']); // 自定义字段的数据格式处理
-
- if (!empty($result['users_id'])){
- $users_where['a.users_id'] = $result['users_id'];
- }elseif (!empty($result['admin_id'])){
- $users_where['a.admin_id'] = $result['admin_id'];
- }else {
- $users_where['a.admin_id'] = ['>',0];
- }
- $users = Db::name('users')->alias('a')->field('a.username,a.nickname,a.head_pic,b.level_name,b.level_value')->where($users_where)->join('users_level b','a.level = b.level_id','left')->find();
- if (!empty($users)) {
- $users['head_pic'] = get_default_pic($users['head_pic']);
- empty($users['nickname']) && $users['nickname'] = $users['username'];
- }
-
-
- $eyou = array(
- 'type' => $arctypeInfo,
- 'field' => $result,
- 'users' => $users,
- );
- $this->eyou = array_merge($this->eyou, $eyou);
- $this->assign('eyou', $this->eyou);
-
- // 模板文件
- $tpl = '';
- if (!empty($result['tempview']) && file_exists("./template/".TPL_THEME."mobile/{$result['tempview']}")) {
- $tpl = str_replace('.' . $this->view_suffix, '', $result['tempview']);
- } else {
- $tpl = 'view_' . $result['nid'];
- }
-
- $dir = $this->getArticleDir($result);
- if (!empty($result['htmlfilename'])) {
- $aid = $result['htmlfilename'];
- }
- if (4 == $this->eyou['global']['seo_html_pagename']) {
- if (!empty($result['ruleview'])) {
- $savepath = $dir;
- }else{
- $savepath = $dir . '/' . $aid . '.html';
- }
- } else {
- $savepath = $dir . '/' . $aid . '.html';
- }
-
- $makeminfo =$this->makeminfo;
- $seo_html_arcdir=$makeminfo['value'];
- $savepath = '.'.$seo_html_arcdir.trim($savepath, '.');
- try {
- $this->filePutContents($savepath, $tpl, 'mobile', 0, '/', 0, 1, $result);
- } catch (\Exception $e) {
- //$msg .= '<span>' . $savepath . '生成失败!' . $e->getMessage() . '</span><br>';
- }
-
- return $msg;
- }
-
- private function getArticleDir($row = [])
- {
- $dir = "";
- $seo_html_pagename = $this->eyou['global']['seo_html_pagename'];
- $makeminfo = $makem->info;
- $seo_html_arcdir=$makeminfo['value'];
-
-
- $dirpath = !empty($row['dirpath']) ? $row['dirpath'] : '';
- $aid = !empty($row['htmlfilename']) ? $row['htmlfilename'] : $row['aid'];
- if ($seo_html_pagename == 1) {//存放顶级目录
- $dirpath_arr = explode('/', $dirpath);
- if (count($dirpath_arr) > 2) {
- $dir = '.' . $seo_html_arcdir . '/' . $dirpath_arr[1];
- } else {
- $dir = '.' . $seo_html_arcdir . $dirpath;
- }
- } else if ($seo_html_pagename == 3) { //存放子级目录
- $dirpath_arr = explode('/', $dirpath);
- if (count($dirpath_arr) > 2) {
- $dir = '.' . $seo_html_arcdir . '/' . end($dirpath_arr);
- } else {
- $dir = '.' . $seo_html_arcdir . $dirpath;
- }
- } else if ($seo_html_pagename == 4) { //自定义存放目录
- $dir = '.' . $seo_html_arcdir;
- $diy_dirpath = !empty($row['diy_dirpath']) ? $row['diy_dirpath'] : '';
- if (!empty($row['ruleview'])) {
- $y = $m = $d = 1;
- if (!empty($row['add_time'])) {
- $y = date('Y', $row['add_time']);
- $m = date('m', $row['add_time']);
- $d = date('d', $row['add_time']);
- }
- $ruleview = ltrim($row['ruleview'], '/');
- $ruleview = str_ireplace("{aid}", $aid, $ruleview);
- $ruleview = str_ireplace("{Y}", $y, $ruleview);
- $ruleview = str_ireplace("{M}", $m, $ruleview);
- $ruleview = str_ireplace("{D}", $d, $ruleview);
- $ruleview = preg_replace('/{(栏目目录|typedir)}(\/?)/i', $diy_dirpath.'/', $ruleview);
- $ruleview = '/'.ltrim($ruleview, '/');
- $dir .= $ruleview;
- }else{
- $dir .= $diy_dirpath;
- }
- } else { //存放父级目录
- $dir = '.' . $seo_html_arcdir . $dirpath;
- }
-
- return $dir;
- }
-
- /*
- * 生成栏目静态页面
- * $id tpyeid 栏目id
- * $findex 下一次执行栏目id
- * $achievepage 已完成页数
- *$batch 是否分批次执行,true:分批,false:不分批
- *
- */
- public function buildChannel()
- {
-
- function_exists('set_time_limit') && set_time_limit(0);
- \think\Session::pause(); // 暂停session,防止session阻塞机制
- $id = input("param.id/d", 0); // 选中栏目ID(需要生成静态的栏目,需要生成全部时候为0)
- $findex = input("param.findex/d", 0); //栏目下标
- $index = input("param.index/d", 0); //本栏目本次执行下标
- $achievepage = input("param.achieve/d", 0);
- $parent = true;
- if (empty($findex) && empty($achievepage)){
- $this->clearCache();
- }
- // 指定文档后,生成的相关栏目
- $uphtmltype = input('param.uphtmltype/d');
- if (!empty($uphtmltype)) {
- $typeids = input("param.typeids/s");
- $id = explode(',', $typeids);
- $parent = false;
- }
-
- $data = $this->handleBuildChannelList($id, $findex, $achievepage,true,$parent,$index);
-
-
- $this->success($data[0], null, $data[1]);
- }
-
- /*
- * 获取栏目数据
- * $id 栏目id
- * $parent 是否获取下级栏目 true:获取,false:不获取
- */
- private function getChannelData($id, $parent = true, $aid = 0)
- {
-
- $info_serialize = cache("channel_info_serialize".$this->php_sessid);
-
- if (empty($info_serialize)) {
-
- $result = $this->getAllArctype($this->home_lang, $id, $this->view_suffix, $parent, $aid);
- $info = $result["info"];
- $pagetotal = intval($result["pagetotal"]);
- $has_children_Row = model('Arctype')->hasChildren(get_arr_column($info, 'typeid'));
-
- cache("channel_page_total_serialize".$this->php_sessid, $pagetotal, null, 'buildhtml');
- cache("channel_info_serialize".$this->php_sessid, serialize($info), null, 'buildhtml');
- cache("has_children_Row_serialize".$this->php_sessid, serialize($has_children_Row), null, 'buildhtml');
- } else {
- $info = unserialize($info_serialize);
- $pagetotal = cache("channel_page_total_serialize".$this->php_sessid);
- $has_children_Row = unserialize(cache("has_children_Row_serialize".$this->php_sessid));
- }
-
- return ['info' => $info, 'pagetotal' => $pagetotal, 'has_children_Row' => $has_children_Row];
- }
- /*
- * 处理生成栏目页
- * $id 栏目id
- * $findex 本次次执行栏目id
- * $achievepage 已完成页数
- * $batch 是否分批次执行,true:分批,false:不分批
- * $parent 是否获取下级栏目 true:获取,false:不获取
- * $index 本栏目本次执行第一条下标
- * $limit 单个栏目一次执行最多生成页数
- */
- private function handleBuildChannelList($id, $findex = 0, $achievepage = 0, $batch = true, $parent = true,$index = 0, $limit = 50){
- !empty($this->eyou['global']['seo_maxpagesize']) && $limit = $this->eyou['global']['seo_maxpagesize'];
- $msg = '';
-
- $result = $this->getChannelData($id, $parent);
-
-
- $info = $result['info'];
- $has_children_Row = $result['has_children_Row'];
- $data['allpagetotal'] = $pagetotal = $result['pagetotal'];
- $data['achievepage'] = $achievepage;
- $data['index'] = 0;
- $data['findex'] = $findex;
- $data['pagetotal'] = 1;
- $data['typeid'] = 0;
- $data['typename'] = "";
-
-
- $info = array_values($info);//重组数组
-
- if ($batch && $data['allpagetotal'] > $data['achievepage']) {
- $row = !empty($info[$findex]) ? $info[$findex] : [];
-
- // cache("buildhtml_channel_aidarr".$this->php_sessid, serialize($row['aid']), null, 'buildhtml');
- if (!empty($row)){
-
- list($msg_temp,$return_data) = $this->createChannelList($row, $has_children_Row,$index,$limit);
-
- $msg .= $msg_temp;
- $data['achievepage'] += !empty($return_data['achieve']) ? $return_data['achieve'] : 1;
- $data['index'] = !empty($return_data['index']) ? $return_data['index'] : 0;
- if (empty($return_data['index'])){
- $data['findex'] = $findex + 1;
- }else{
- $data['findex'] = $findex ;
- }
- }else{
- $data['findex'] = $findex + 1;
- }
- $data['pagetotal'] = !empty($row['pagetotal']) ? $row['pagetotal'] : 1;
- $data['typeid'] = !empty($row['typeid']) ? $row['typeid'] : 0;
- $data['typename'] = !empty($row['typename']) ? $row['typename'] :"";
- // cache("buildhtml_channel_aidarr".$this->php_sessid, null);
- } else if (!$batch) {
- foreach ($info as $key => $row) {
- $msg .= $this->createChannel($row, $has_children_Row);
- $data['pagetotal'] = $row['pagetotal'];
- $data['achievepage'] += $row['pagetotal'];
- $data['findex'] = $key;
- $data['typeid'] = !empty($row['typeid']) ? $row['typeid'] : 0;
- $data['typename'] = !empty($row['typename']) ? $row['typename'] :"";
- }
- }
-
- if ($data['allpagetotal'] == $data['achievepage']) { //生成完全部页面,删除缓存
- cache("channel_page_total_serialize".$this->php_sessid, null);
- cache("channel_info_serialize".$this->php_sessid, null);
- cache("has_children_Row_serialize".$this->php_sessid, null);
- }
-
- return [$msg, $data];
- }
- /*
- * 处理生成栏目页
- * $id typeid
- * $findex 下一次执行栏目id
- * $achievepage 已完成页数
- * $batch 是否分批次执行,true:分批,false:不分批
- * $parent 是否获取下级栏目 true:获取,false:不获取
- * $aid 文章页id,不等于0时,表示只获取文章页所在的列表页重新生成静态(在添加或者编辑文档内容时使用)
- */
- private function handleBuildChannel($id, $findex = 0, $achievepage = 0, $batch = true, $parent = true, $aid = 0)
- {
- $msg = '';
- $result = $this->getChannelData($id, $parent, $aid);
- $info = $result['info'];
- $has_children_Row = $result['has_children_Row'];
- $data['allpagetotal'] = $pagetotal = $result['pagetotal'];
- $data['achievepage'] = $achievepage;
- /***********2020 05 19 过滤并删除外部链接生成的静态页面 s*************/
- // foreach ($info as $k => $v) {
- // if ($v['is_part'] == 1 || $v['nid'] == 'ask') {//外部链接或问答模型
- // unset($info[$k]);//从数组里移除
- // $dir = ROOT_PATH . trim($v['dirpath'], '/');
- // if (!empty($v['dirpath']) && true == is_dir($dir)) {//判断是否生成过文件夹,文件夹存在则删除
- // $this->deldir($dir);
- // }
- // }
- // }
- // $info = array_values($info);//重组数组
- /***********2020 05 19 新增 e*************/
- if ($batch && $data['allpagetotal'] > $data['achievepage']) {
- $row = !empty($info[$findex]) ? $info[$findex] : [];
- !empty($row) && $msg .= $msg_temp = $this->createChannel($row, $has_children_Row);
- $data['pagetotal'] = !empty($row['pagetotal']) ? $row['pagetotal'] : 1;
- $data['achievepage'] += !empty($row['pagetotal']) ? $row['pagetotal'] : 1;
- $data['findex'] = $findex + 1;
- $data['typeid'] = !empty($row['typeid']) ? $row['typeid'] : 0;
- } else if (!$batch) {
- foreach ($info as $key => $row) {
- $msg .= $msg_temp = $this->createChannel($row, $has_children_Row, $aid);
- $data['pagetotal'] = $row['pagetotal'];
- $data['achievepage'] += $row['pagetotal'];
- $data['findex'] = $key;
- $data['typeid'] = $row['typeid'];
- }
- }
- if ($data['allpagetotal'] == $data['achievepage']) { //生成完全部页面,删除缓存
- cache("channel_page_total_serialize".$this->php_sessid, null);
- cache("channel_info_serialize".$this->php_sessid, null);
- cache("has_children_Row_serialize".$this->php_sessid, null);
- }
-
- return [$msg, $data];
- }
-
- /*
- * 分批生成栏目页面
- * $index 当前执行的页码下标
- * $limit 每次最多生成个数
- */
- private function createChannelList($row, $has_children_Row,$index = 0, $limit = 10)
- {
-
- $msg = "";
- $data = [
- 'achieve' => 0,
- 'index' => 0
- ];
- $seo_html_listname = $this->eyou['global']['seo_html_listname'];
- $seo_html_arcdir = '/';
- $tid = $row['typeid'];
- $this->request->get(['tid' => $tid]);
- $row = $this->lists_logic($row, $has_children_Row); // 模型对应逻辑
- $eyou = array(
- 'field' => $row,
- );
- $this->eyou = array_merge($this->eyou, $eyou);
- $this->assign('eyou', $this->eyou);
- // 模板文件
- $tpl = '';
- if (!empty($row['templist']) && file_exists("./template/".TPL_THEME."mobile/{$row['templist']}")) {
- $tpl = str_replace('.' . $this->view_suffix, '', $row['templist']);
- } else {
- $tpl = 'lists_' . $row['nid'];
- }
-
- if (in_array($row['current_channel'], [6, 8])) {
- //留言模型或单页模型,不存在多页
- $this->request->get(['page' => '']);
- $dirpath = explode('/', $eyou['field']['dirpath']);
- $dirpath_end = end($dirpath);
- if ($seo_html_listname == 1) { //存放顶级目录
- $savepath = '.' . $seo_html_arcdir . '/' . $dirpath[1] . "/lists_" . $eyou['field']['typeid'] . ".html";
- } else if ($seo_html_listname == 3) { //存放子级目录
- $savepath = '.' . $seo_html_arcdir . '/' . $dirpath_end . "/lists_" . $eyou['field']['typeid'] . ".html";
- } else if ($seo_html_listname == 4) { //自定义存放目录
- $savepath = '.' . $seo_html_arcdir;
- $diy_dirpath = !empty($eyou['field']['diy_dirpath']) ? $eyou['field']['diy_dirpath'] : '';
- if (!empty($eyou['field']['rulelist'])) {
- $rulelist = ltrim($eyou['field']['rulelist'], '/');
- $rulelist = str_replace("{tid}", $eyou['field']['typeid'], $rulelist);
- $rulelist = str_replace("{page}", '', $rulelist);
- $rulelist = preg_replace('/{(栏目目录|typedir)}(\/?)/i', $diy_dirpath.'/', $rulelist);
- $rulelist = '/'.ltrim($rulelist, '/');
- $rulelist = preg_replace('/([\/]+)/i', '/', $rulelist);
- $savepath .= $rulelist;
- }else{
- $eyou['field']['rulelist'] = '{栏目目录}/list_{tid}_{page}.html';
- $savepath .= $diy_dirpath . '/' . 'list_' . $eyou['field']['typeid'] . ".html";
- }
- } else {
- $savepath = '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/' . 'lists_' . $eyou['field']['typeid'] . ".html";
- }
-
- try {
-
- $makeminfo =$this->makeminfo;
- $seo_html_arcdir=$makeminfo['value'];
- $savepath = '.'.$seo_html_arcdir.trim($savepath, '.');
- // echo $savepath;
- // echo '----';
- // echo $seo_html_arcdir;
- // die;
- $this->filePutContents($savepath, $tpl, 'mobile', 0, '/', 0, 1, $row);
- if ($seo_html_listname == 3) {
- @copy($savepath, '.' . $seo_html_arcdir . '/' . $dirpath_end . '/index.html');
- @unlink($savepath);
- } else if ($seo_html_listname == 4) {
- if (preg_match('/^{(栏目目录|typedir)}\/list_{tid}_{page}\.html$/i', $eyou['field']['rulelist'])) {
- $dst_savepath = preg_replace('/\/([^\/]+)$/i', '/index.html', $savepath);
- @copy($savepath, $dst_savepath);
- @unlink($savepath);
- }
- } else if ($seo_html_listname == 2 || count($dirpath) < 3) {
- @copy($savepath, '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/index.html');
- @unlink($savepath);
- }
- } catch (\Exception $e) {
- //$msg .= '<span>' . $savepath . '生成失败!' . $e->getMessage() . '</span><br>';
- }
- $data['achieve'] += 1;
- }else { //多条信息的栏目
-
-
- $totalpage = $row['pagetotal'];
- $lastPage = cache("eyou-TagList-lastPage_{$tid}_{$this->php_sessid}"); //本栏目真实条数
- $differ = 0; //实际页数和预计页数的差集
- while ($limit && $totalpage > $index) {
- $msg .= $this->createMultipageChannel($index+1, $tid, $row, $has_children_Row, $seo_html_listname, $seo_html_arcdir, $tpl);
- $limit--;
- $index++;
- $data['achieve'] += 1;
- if (!empty($lastPage)) {
- if ($totalpage > $lastPage) {
- $differ = $totalpage - $lastPage;
- $totalpage = $lastPage;
- }
- }
- }
- if ($totalpage <= $index){ //已经执行完成本栏目
- $data['index'] = 0;
- $data['achieve'] += $differ;
- }else{
- $data['index'] = $index;
- }
- }
-
- return [$msg,$data];
- }
- /*
- * 生成栏目页面
- */
- private function createChannel($row, $has_children_Row, $aid = 0)
- {
- $msg = "";
- $seo_html_listname = $this->eyou['global']['seo_html_listname'];
- // $seo_html_arcdir = $this->eyou['global']['seo_html_arcdir'];
- $tid = $row['typeid'];
- $this->request->get(['tid' => $tid]);
- $seo_html_arcdir = '';
- $row = $this->lists_logic($row, $has_children_Row); // 模型对应逻辑
- $eyou = array(
- 'field' => $row,
- );
- $this->eyou = array_merge($this->eyou, $eyou);
- $this->assign('eyou', $this->eyou);
-
- // 模板文件
- $tpl = '';
- if (!empty($row['templist']) && file_exists("./template/".TPL_THEME."mobile/{$row['templist']}")) {
- $tpl = str_replace('.' . $this->view_suffix, '', $row['templist']);
- } else {
- $tpl = 'lists_' . $row['nid'];
- }
-
- if (in_array($row['current_channel'], [6, 8])) { //留言模型或单页模型,不存在多页
- $this->request->get(['page' => '']);
- $dirpath = explode('/', $eyou['field']['dirpath']);
- $dirpath_end = end($dirpath);
- if ($seo_html_listname == 1) { //存放顶级目录
- $savepath = '.' . $seo_html_arcdir . '/' . $dirpath[1] . "/lists_" . $eyou['field']['typeid'] . ".html";
- } else if ($seo_html_listname == 3) { //存放子级目录
- $savepath = '.' . $seo_html_arcdir . '/' . $dirpath_end . "/lists_" . $eyou['field']['typeid'] . ".html";
- } else if ($seo_html_listname == 4) { //自定义存放目录
- $savepath = '.' . $seo_html_arcdir;
- $diy_dirpath = !empty($eyou['field']['diy_dirpath']) ? $eyou['field']['diy_dirpath'] : '';
- if (!empty($eyou['field']['rulelist'])) {
- $rulelist = ltrim($eyou['field']['rulelist'], '/');
- $rulelist = str_replace("{tid}", $eyou['field']['typeid'], $rulelist);
- $rulelist = str_replace("{page}", '', $rulelist);
- $rulelist = preg_replace('/{(栏目目录|typedir)}(\/?)/i', $diy_dirpath.'/', $rulelist);
- $rulelist = '/'.ltrim($rulelist, '/');
- $rulelist = preg_replace('/([\/]+)/i', '/', $rulelist);
- $savepath .= $rulelist;
-
- }else{
- $eyou['field']['rulelist'] = '{栏目目录}/lists_{tid}_{page}.html';
- $savepath .= $diy_dirpath . '/' . 'list_' . $eyou['field']['typeid'] . ".html";
- }
- } else {
- $savepath = '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/' . 'lists_' . $eyou['field']['typeid'] . ".html";
- }
- try {
- $makeminfo =$this->makeminfo;
- $seo_html_arcdir=$makeminfo['value'];
- $savepath = '.'.$seo_html_arcdir.trim($savepath, '.');
- $this->filePutContents($savepath, $tpl, 'mobile', 0, '/', 0, 1, $row);
- if ($seo_html_listname == 3) {
- @copy($savepath, '.' . $seo_html_arcdir . '/' . $dirpath_end . '/index.html');
- @unlink($savepath);
- } else if ($seo_html_listname == 4) {
- if (preg_match('/^{(栏目目录|typedir)}\/list_{tid}_{page}\.html$/i', $eyou['field']['rulelist'])) {
- $dst_savepath = preg_replace('/\/([^\/]+)$/i', '/index.html', $savepath);
- @copy($savepath, $dst_savepath);
- @unlink($savepath);
- }
- } else if ($seo_html_listname == 2 || count($dirpath) < 3) {
- @copy($savepath, '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/index.html');
- @unlink($savepath);
- }
- } catch (\Exception $e) {
- //$msg .= '<span>' . $savepath . '生成失败!' . $e->getMessage() . '</span><br>';
- }
- } else if (!empty($aid)) { //只更新aid所在的栏目页码
- $orderby = getOrderBy($row['orderby'], $row['ordermode']);
- $limit = getLocationPages($tid, $aid, $orderby);
- $i = !empty($limit) ? ceil($limit / $row['pagesize']) : 1;
- $msg .= $this->createMultipageChannel($i, $tid, $row, $has_children_Row, $seo_html_listname, $seo_html_arcdir, $tpl);
-
- } else { //多条信息的栏目
- $totalpage = $row['pagetotal'];
- for ($i = 1; $i <= $totalpage; $i++) {
- $msg .= $this->createMultipageChannel($i, $tid, $row, $has_children_Row, $seo_html_listname, $seo_html_arcdir, $tpl);
- $lastPage = cache("eyou-TagList-lastPage_{$tid}_{$this->php_sessid}");
- if (!empty($lastPage)) {
- $totalpage = $lastPage;
- }
- }
- }
-
- return $msg;
- }
-
- /*
- * 创建有文档列表模型的静态栏目页面
- */
- private function createMultipageChannel($i, $tid, $row, $has_children_Row, $seo_html_listname, $seo_html_arcdir, $tpl)
- {
- $makeminfo =$this->makeminfo;
- // 二级目录模式
- if($makeminfo['web_url_model'] !=2){
- $seo_html_arcdir = $makeminfo['value'];
- }
-
- $msg = "";
- $this->request->get(['page' => $i]);
- $row['seo_title'] = set_typeseotitle($row['typename'], $row['seo_title_tmp']);
- // $row = $this->lists_logic($row, $has_children_Row); // 模型对应逻辑
- $eyou = array(
- 'field' => $row,
- );
- $this->eyou = array_merge($this->eyou, $eyou);
- $this->assign('eyou', $this->eyou);
- $dirpath = explode('/', $eyou['field']['dirpath']);
- $dirpath_end = end($dirpath);
- if ($seo_html_listname == 1) { //存放顶级目录
- $dir = '.' . $seo_html_arcdir . '/' . $dirpath[1];
- $savepath = '.' . $seo_html_arcdir . '/' . $dirpath[1] . "/lists_" . $eyou['field']['typeid'];
- } else if ($seo_html_listname == 3) { //存放子级目录
- $dir = '.' . $seo_html_arcdir . '/' . $dirpath_end;
- $savepath = '.' . $seo_html_arcdir . '/' . $dirpath_end . "/lists_" . $eyou['field']['typeid'];
- } else if ($seo_html_listname == 4) { //自定义存放目录
- $dir = $savepath = '.' . $seo_html_arcdir;
- $diy_dirpath = !empty($eyou['field']['diy_dirpath']) ? $eyou['field']['diy_dirpath'] : '';
- if (!empty($eyou['field']['rulelist'])) {
- $rulelist = ltrim($eyou['field']['rulelist'], '/');
- $rulelist = str_replace("{tid}", $eyou['field']['typeid'], $rulelist);
- $rulelist = str_replace("{page}", $i, $rulelist);
- $rulelist = preg_replace('/{(栏目目录|typedir)}(\/?)/i', $diy_dirpath.'/', $rulelist);
- $rulelist = '/'.ltrim($rulelist, '/');
- $dir .= preg_replace('/\/([\/]*)([^\/]*)$/i', '', $rulelist);
- $savepath .= $rulelist;
- }else{
- $dir .= $diy_dirpath;
- $savepath .= $diy_dirpath . '/' . 'list_' . $eyou['field']['typeid'];
- }
- } else {
- $dir = '.' . $seo_html_arcdir . $eyou['field']['dirpath'];
- $savepath = '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/' . 'lists_' . $eyou['field']['typeid'];
- }
-
- if ($seo_html_listname != 4 || empty($eyou['field']['rulelist'])) {
- if ($i > 1) {
- $savepath .= '_' . $i . '.html';
- } else {
- $savepath .= '.html';
- }
- }
-
- $top = 1;
- if ($i > 1 && $seo_html_listname == 1 && count($dirpath) > 2) {
- $top = 2;
- } else if ($i > 1 && $seo_html_listname == 3) {
- $top = 1;
- } else if ($i > 1 && $seo_html_listname == 4) {
- $top = 1;
- }
-
- // $seo_html_arcdir ='/m';
- // $savepath = './m'.trim($savepath, '.');
- //获取手机路径
-
- if($makeminfo['web_url_model'] ==2){
- $seo_html_arcdir=$makeminfo['value'];
- $savepath = '.'.$seo_html_arcdir.trim($savepath, '.');
- }else{
- $savepath = '.'.trim($savepath, '.');
- }
-
- // echo $seo_html_arcdir;
- // echo '----';
- // echo $savepath;
- // die;
-
- try {
- $this->filePutContents($savepath, $tpl, 'mobile', $i, $dir, $tid, $top, $row);
- if ($i == 1 && $seo_html_listname == 3) {
- @copy($savepath, '.' . $seo_html_arcdir . '/' . $dirpath_end . '/index.html');
- @unlink($savepath);
- } else if ($seo_html_listname == 4) {
- if ($i == 1) {
- $dst_savepath = preg_replace('/\/([^\/]+)$/i', '/index.html', $savepath);
- @copy($savepath, $dst_savepath);
- @unlink($savepath);
- } else if ($i > 1) {
- if (!empty($eyou['field']['rulelist']) && !preg_match('/{page}/i', $eyou['field']['rulelist'])) { // 没有分页变量的情况
- @unlink($savepath);
- }
- }
- } else if ($i == 1 && ($seo_html_listname == 2 || count($dirpath) < 3)) {
- @copy($savepath, '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/index.html');
- @unlink($savepath);
- }
- } catch (\Exception $e) {
- //$msg .= '<span>' . $savepath . '生成失败!' . $e->getMessage() . '</span><br>';
- }
-
- return $msg;
- }
-
- /**
- * 更新静态生成页
- * @param int $aid 文章id
- * @param int $typeid 栏目id
- * @return boolean
- * $del_ids 删除的文章数组
- */
- public function upHtml()
- {
- \think\Session::pause(); // 暂停session,防止session阻塞机制
- $aid = input("param.aid/d");
- $typeid = input("param.typeid/d");
- $del_ids = input('param.del_ids/a');
- $type = input('param.type/s');
- $lang = input("param.lang/s", 'cn');
- $seo_uphtml_after_pernext = input("param.seo_uphtml_after_pernext/d");
- $param = input('param.');
- $this->php_sessid .= 'upHtml'.json_encode($param);
-
- /*由于全站共用删除JS代码,这里排除不能发布文档的模型的控制器*/
- if ('index' != $type) {
- $ctl_name = input("param.ctl_name/s");
- $channeltypeRow = Db::name('channeltype')
- ->where('nid', 'NOT IN', ['guestbook', 'single'])
- ->column('ctl_name');
- array_push($channeltypeRow, 'Archives', 'Arctype', 'Custom');
- if (!in_array($ctl_name, $channeltypeRow)) {
- $this->error("排除非发布文档的模型");
- }
- }
- /*end*/
-
- $seo_pseudo = $this->eyou['global']['seo_pseudo'];
- $seo_html_pagename = $this->eyou['global']['seo_html_pagename'];
- $this->clearCache();
- if ($seo_pseudo != 2) {
- $this->error("当前非静态模式,不做静态处理");
- }
- if (!empty($del_ids)) { //删除文章页面
- $info = Db::name('archives')->field('b.dirpath,b.diy_dirpath,b.rulelist,b.ruleview,a.*')
- ->alias('a')
- ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
- ->where([
- 'a.aid' => ['in', $del_ids],
- 'a.lang' => $lang,
- ])
- ->select();
-
- foreach ($info as $key => $row) {
- $filename = $row['aid'];
- if (!empty($row['htmlfilename'])) {
- $filename = $row['htmlfilename'];
- }
- $dir = $this->getArticleDir($row);
- if (4 == $seo_html_pagename) {
- if (!empty($row['ruleview'])) {
- $path = $dir;
- }else{
- $path = $dir . "/" . $filename . ".html";
- }
- } else {
- $path = $dir . "/" . $filename . ".html";
- }
-
- if (file_exists($path)) @unlink($path);
- }
- } else if (!empty($aid) && !empty($typeid)) { //变更文档信息,更新文档页及相关的栏目页
- if ('view' == $type) {
- $this->handelBuildArticle($typeid, $aid, 0, 0, false, 1, 0);
- if (1 == $seo_uphtml_after_pernext) {
- $this->handelBuildArticle($typeid, $aid, 0, 0, false, 1, 1); // 更新上篇
- $this->handelBuildArticle($typeid, $aid, 0, 0, false, 1, 2); // 更新下篇
- }
- } else if ('lists' == $type) {
- $data = $this->handleBuildChannel($typeid, 0, 0, false, false, $aid);
- } else {
- $this->handleBuildChannel($typeid, 0, 0, false, false, $aid);
- $this->handelBuildArticle($typeid, $aid, 0, 0, false);
- }
- } else if (!empty($typeid)) { //变更栏目信息,更新栏目页
- $this->handleBuildIndex();
- $data = $this->handleBuildChannel($typeid, 0, 0, false, false);
- } else if ('index' == $type) {
- $this->handleBuildIndex();
- }
-
- $this->success("静态页面生成完成");
- }
-
- /*
- * 拓展页面相关信息
- */
- private function lists_logic($result = [], $has_children_Row = [])
- {
- if (empty($result)) {
- return [];
- }
-
- $tid = $result['typeid'];
-
- switch ($result['current_channel']) {
- case '6': // 单页模型
- {
- $arctype_info = model('Arctype')->parentAndTopInfo($tid, $result);
- if ($arctype_info) {
- // 读取当前栏目的内容,否则读取每一级第一个子栏目的内容,直到有内容或者最后一级栏目为止。
- $archivesModel = new \app\home\model\Archives();
- $result_new = $archivesModel->readContentFirst($tid);
- // 阅读权限 或 外部链接跳转
- if ($result_new['arcrank'] == -1 || $result_new['is_part'] == 1) {
- return false;
- }
- /*自定义字段的数据格式处理*/
- $result_new = $this->fieldLogic->getChannelFieldList($result_new, $result_new['current_channel']);
- /*--end*/
-
- $result = array_merge($arctype_info, $result_new);
-
- $result['templist'] = !empty($arctype_info['templist']) ? $arctype_info['templist'] : 'lists_' . $arctype_info['nid'];
- $result['dirpath'] = $arctype_info['dirpath'];
- $result['diy_dirpath'] = $arctype_info['diy_dirpath'];
- $result['typeid'] = $arctype_info['typeid'];
- $result['rulelist'] = $arctype_info['rulelist'];
- }
- break;
- }
-
- default:
- {
- $result = model('Arctype')->parentAndTopInfo($tid, $result);
- break;
- }
- }
-
- if (!empty($result)) {
- /*自定义字段的数据格式处理*/
- $result = $this->fieldLogic->getTableFieldList($result, config('global.arctype_channel_id'));
- /*--end*/
- }
-
- /*是否有子栏目,用于标记【全部】选中状态*/
- $result['has_children'] = !empty($has_children_Row[$tid]) ? 1 : 0;
- /*--end*/
-
- // seo
- if (!isset($result['seo_title_tmp'])) {
- $result['seo_title_tmp'] = $result['seo_title'];
- }
- $result['seo_title'] = set_typeseotitle($result['typename'], $result['seo_title_tmp']);
-
- $result['pageurl'] = $result['typeurl']; // 获取当前页面URL
- $result['pageurl_m'] = pc_to_mobile_url($result['pageurl'], $result['typeid']); // 获取当前页面对应的移动端URL
- // 移动端域名
- $result['mobile_domain'] = '';
- if (!empty($this->eyou['global']['web_mobile_domain_open']) && !empty($this->eyou['global']['web_mobile_domain'])) {
- $result['mobile_domain'] = $this->eyou['global']['web_mobile_domain'] . '.' . $this->request->rootDomain();
- }
-
- /*给没有type前缀的字段新增一个带前缀的字段,并赋予相同的值*/
- foreach ($result as $key => $val) {
- if (!preg_match('/^type/i', $key)) {
- $key_new = 'type' . $key;
- !array_key_exists($key_new, $result) && $result[$key_new] = $val;
- }
- }
- /*--end*/
-
- return $result;
- }
-
- /**
- * 生成静态模式下且PC和移动端模板分离,就自动给PC端加上跳转移动端的JS代码
- * @access public
- */
- private function pc_to_mobile_js($html = '', $result = [])
- {
- static $other_pcwapjs = null;
- null === $other_pcwapjs && $other_pcwapjs = tpCache('other.other_pcwapjs');
- if (!empty($other_pcwapjs)) {
- return $html;
- }
-
- if (file_exists('./template/'.TPL_THEME.'mobile')) { // 分离式模板
-
- /*是否开启手机站域名,并且配置*/
- if (!empty($this->eyou['global']['web_mobile_domain_open']) && !empty($this->eyou['global']['web_mobile_domain'])) {
- $domain = $this->eyou['global']['web_mobile_domain'] . '.' . $this->request->rootDomain();
- } else {
- $domain = true;
- }
- /*end*/
-
- $aid = input('param.aid/d');
- $tid = input('param.tid/d');
- if (!empty($aid)) { // 内容页
- $url = url('home/View/index', ['aid' => $aid], true, $domain, 1, 1, 0);
- } else if (!empty($tid)) { // 列表页
- $url = url('home/Lists/index', ['tid' => $tid], true, $domain, 1, 1, 0);
- } else { // 首页
- $url = $this->request->scheme().'://'. $this->request->host(true) . ROOT_DIR . '/index.php';
- }
-
- $jsStr = <<<EOF
- <meta http-equiv="mobile-agent" content="format=xhtml;url={$url}">
- <script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/applewebkit.*mobile/i.test(navigator.userAgent.toLowerCase()) || (/midp|symbianos|nokia|samsung|lg|nec|tcl|alcatel|bird|dbtel|dopod|philips|haier|lenovo|mot-|nokia|sonyericsson|sie-|amoi|zte/.test(navigator.userAgent.toLowerCase()))){try{if(/android|windows phone|webos|iphone|ipod|blackberry/i.test(navigator.userAgent.toLowerCase())){window.location.href="{$url}";}else if(/ipad/i.test(navigator.userAgent.toLowerCase())){}else{}}catch(e){}}}</script>
- EOF;
- $html = str_ireplace('</head>', $jsStr . "\n</head>", $html);
- } else { // 响应式模板
- // 开启手机站域名,且配置
- if (!empty($this->eyou['global']['web_mobile_domain_open']) && !empty($this->eyou['global']['web_mobile_domain'])) {
- if (empty($result['pageurl'])) {
- $url = $this->request->subDomain($this->eyou['global']['web_mobile_domain']) . ROOT_DIR . '/index.php';
- } else {
- $url = !preg_match('/^(http(s?):)?\/\/(.*)$/i', $result['pageurl']) ? $this->request->domain() . $result['pageurl'] : $result['pageurl'];
- $url = preg_replace('/^(.*)(\/\/)([^\/]*)(\.?)(' . $this->request->rootDomain() . ')(.*)$/i', '${1}${2}' . $this->eyou['global']['web_mobile_domain'] . '.${5}${6}', $url);
- }
-
- $mobileDomain = $this->eyou['global']['web_mobile_domain'] . '.' . $this->request->rootDomain();
- $jsStr = <<<EOF
- <meta http-equiv="mobile-agent" content="format=xhtml;url={$url}">
- <script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/applewebkit.*mobile/i.test(navigator.userAgent.toLowerCase()) || (/midp|symbianos|nokia|samsung|lg|nec|tcl|alcatel|bird|dbtel|dopod|philips|haier|lenovo|mot-|nokia|sonyericsson|sie-|amoi|zte/.test(navigator.userAgent.toLowerCase()))){try{if(/android|windows phone|webos|iphone|ipod|blackberry/i.test(navigator.userAgent.toLowerCase())){if(window.location.toString().indexOf('{$mobileDomain}') == -1){window.location.href="{$url}";}}else if(/ipad/i.test(navigator.userAgent.toLowerCase())){}else{}}catch(e){}}}</script>
- EOF;
- $html = str_ireplace('</head>', $jsStr . "\n</head>", $html);
- }
- }
-
- return $html;
- }
-
- /**
- * 删除文件夹
- * @param $dir
- * @return bool
- */
- private function deldir($dir)
- {
- //先删除目录下的文件:
- $fileArr = glob($dir.'/*.html');
- if (!empty($fileArr)) {
- foreach ($fileArr as $key => $val) {
- !empty($val) && @unlink($val);
- }
- }
-
- $fileArr = glob($dir.'/*');
- if(empty($fileArr)){ //目录为空
- rmdir($dir); // 删除空目录
- }
- return true;
- }
-
-
- /*getAllArctype*/
-
- function getAllArctype($home_lang,$id,$view_suffix,$parent = true,$aid = 0){
-
- $map = [];
- if (!empty($id)){
- if (is_array($id)) {
- $map['a.id'] = ['IN', $id];
- } else {
- $map['a.id'] = $id;
- }
- }
- $map['a.lang'] = $home_lang;
- $map['a.is_del'] = 0;
- $map['a.status'] = 1;
- $info = \think\Db::name('arctype')->field('c.*, a.*, a.id as typeid')
- ->alias('a')
- ->join('__CHANNELTYPE__ c', 'c.id = a.current_channel', 'LEFT')
- ->where($map)
- ->order("a.grade desc")
- ->cache(true,EYOUCMS_CACHE_TIME,"arctype")
- ->select();
-
-
-
-
- if (!empty($id) && $parent && $aid == 0) {
-
-
- // $aid > 0 表示栏目生成不生成子栏目
- $this->getAllChildArctype($info,$id);
-
- }
- $info = $this->getAllArctypeCount($home_lang,$info,$id,$view_suffix,$aid);
-
- return $info;
- }
-
-
- //递归查询所有的子类
- function getAllChildArctype(&$arctype_child_all,$id){
- $where['a.is_del'] = 0;
- $where['a.status'] = 1;
- $where['a.parent_id'] = $id;
- $arctype_child = \think\Db::name('arctype')->field('c.*, a.*, a.id as typeid')
- ->alias('a')
- ->join('__CHANNELTYPE__ c', 'c.id = a.current_channel', 'LEFT')
- ->where($where)
- ->select();
- if(!empty($arctype_child)){
- $arctype_child_all = array_merge($arctype_child,$arctype_child_all);
- for($i=0;$i<count($arctype_child);$i++){
- $this->getAllChildArctype($arctype_child_all,$arctype_child[$i]['typeid']);
- }
- }
- }
-
- function getAllArctypeCount($home_lang,$info,$id = 0,$view_suffix = ".htm",$aid = 0)
- {
- /**
- * 这里统计每个栏目的文档数有两种方法
- * 1、当文档数量少于10W时,执行第一种方法,在循环外部查询一条sql统计出栏目的文档数
- * 2、当文档数量大于10W时,执行第二种方法,在循环里面每次执行一个统计当前栏目的文档数sql
- * @var integer
- */
- $method_mode = 1; // 默认是第一种方法
- $max_aid = \think\Db::name('archives')->max('aid'); // 取出文档的最大数量,已最大文档ID来大概计算
- if ($max_aid > 100000) {
- $method_mode = 2;
- }
-
- $map_arc = [];
- // 是否更新子栏目
- $seo_upnext = tpCache('seo.seo_upnext');
- $web_stypeid_open = tpCache('web.web_stypeid_open'); // 是否开启副栏目
- if (1 == $method_mode && $id) {
- if (empty($web_stypeid_open)) {
- $map_arc['typeid'] = array('in',get_arr_column($info,'typeid'));
- } else {
- $typeids_tmp = get_arr_column($info,'typeid');
- $typeids_tmp = implode(',', $typeids_tmp);
- $map_arc[] = \think\Db::raw(" ( typeid IN ({$typeids_tmp}) OR CONCAT(',', stypeid, ',') LIKE '%,{$id},%' ) ");
- }
- }
- // 可发布文档列表的频道模型
- static $new_channel = null;
- if (null === $new_channel) {
- $allow_release_channel = config('global.allow_release_channel');
- $arctypeRow = \think\Db::name('arctype')->field('channeltype,current_channel')->select();
- foreach ($arctypeRow as $key => $val) {
- if (in_array($val['channeltype'], $allow_release_channel)) {
- $new_channel[] = $val['channeltype'];
- }
- if (in_array($val['current_channel'], $allow_release_channel)) {
- $new_channel[] = $val['current_channel'];
- }
- }
- $new_channel = array_unique($new_channel);
- }
- !empty($new_channel) && $map_arc['a.channel'] = ['IN', $new_channel];
- $map_arc['a.arcrank'] = ['egt', 0];
- $map_arc['a.status'] = 1;
- $map_arc['a.is_del'] = 0;
- $map_arc['a.lang'] = $home_lang;
- /*定时文档显示插件*/
- if (is_dir('./weapp/TimingTask/')) {
- $TimingTaskRow = model('Weapp')->getWeappList('TimingTask');
- if (!empty($TimingTaskRow['status']) && 1 == $TimingTaskRow['status']) {
- $map_arc['a.add_time'] = array('elt', getTime()); // 只显当天或之前的文档
- }
- }
- /*end*/
-
- if (1 == $method_mode) { // 方法1
- $count_type = [];
- $archivesList = \think\Db::name('archives')->alias('a')->field("typeid,stypeid")->where($map_arc)->order('typeid asc')->select();
- foreach ($archivesList as $key => $val) {
- if (!isset($count_type[$val['typeid']])) {
- $count_type[$val['typeid']] = [
- 'typeid' => $val['typeid'],
- 'count' => 1,
- ];
- } else {
- $count_type[$val['typeid']]['count']++;
- }
-
- // 开启副栏目
- if (!empty($web_stypeid_open) && !empty($val['stypeid'])) {
- $stypeids = explode(',', $val['stypeid']);
- $arr_index = array_search($val['typeid'], $stypeids);
- if (is_numeric($arr_index) && 0 <= $arr_index) {
- unset($stypeids[$arr_index]);
- }
- foreach ($stypeids as $_k => $_v) {
- if (!isset($count_type[$_v])) {
- $count_type[$_v] = [
- 'typeid' => $_v,
- 'count' => 1,
- ];
- } else {
- $count_type[$_v]['count']++;
- }
- }
- }
- }
- }
-
- $db = new \think\Db;
- $pagetotal = 0;
- $arctypeAllSub = arctypeAllSub(); // 获取所有栏目,并每个栏目都包含所有子栏目,以及自己
- $info2 = $tplData = [];
- $info = convert_arr_key($info,'typeid');
- foreach ($info as $k => $v) {
- //外链
- if ($v['is_part'] == 1 || 'ask' == $v['nid']) {
- $dir = ROOT_PATH . trim($v['dirpath'], '/');
- if (!empty($v['dirpath']) && true == is_dir($dir)) {//判断是否生成过文件夹,文件夹存在则删除
- deldir_html($dir);
- }
- continue;
- }
-
- if (1 == $method_mode) { // 方法1
- if (!isset($info[$v['typeid']]['count'])){ //判断当前栏目的count是否已经存在
- $v['count'] = 0;
- }else{
- $v['count'] = intval($info[$v['typeid']]['count']);
- }
- if (isset($count_type[$v['typeid']])){ //存在当前栏目个数
- $v['count'] += $count_type[$v['typeid']]['count'];
- }
-
- //判断是否存在上级目录,且当前栏目和上级栏目都不是单页,且当前栏目和上级栏目是相同模型,则,把当前栏目的aid和count赋值给父栏目
- if ($v['parent_id'] && !in_array($v['current_channel'], [6,8]) && isset($info[$v['parent_id']]) && $v['current_channel'] == $info[$v['parent_id']]['current_channel']){
- if (isset($info[$v['parent_id']]['count'])) {
- $info[$v['parent_id']]['count'] += intval($v['count']);
- }else{
- $info[$v['parent_id']]['count'] = intval($v['count']);
- }
- }
- }
-
- /**
- * 判断是否需要更新子栏目
- * 1、更新子栏目,正常处理
- * 2、不更新子栏目
- * (1)、选择指定栏目的情况下,判断当前栏目是否为选择栏目,如果是,走正常流程,否则,去掉当前栏目
- * (2)、不选择指定栏目的情况下,判断当前栏目是否为顶级栏目,如果是,走正常流程,否则,去掉当前栏目
- */
- if (empty($seo_upnext) && ( (!empty($id) && $v['typeid'] != $id) || (empty($id) && !empty($v['parent_id'])) ) ){
- continue;
- }
-
- $tag_attr_arr = [];
- if (!isset($tplData[$v['templist']])) {
- $tpl = !empty($v['templist']) ? str_replace('.'.$view_suffix, '',$v['templist']) : 'lists_'. $v['nid'];
- $template_html = "./template/".TPL_THEME."mobile/".$tpl.".htm";
- $content = file_get_contents($template_html);
- if ($content) {
- preg_match_all('/\{eyou:list(\s+)?(.*)\}/i', $content, $matchs);
- if (!empty($matchs[0][0])) {
- $tag_attr = !empty($matchs[2][0]) ? $matchs[2][0] : '';
- if (!empty($tag_attr)) {
- $tag_attr = preg_replace('/([a-z]+)(\s*)=(\s*)([\'|\"]?)([^ \f\n\r\t\v\'\"]+)([\'|\"]?)/i', '${1}=\'${5}\'', $tag_attr); // 属性引导统一设置单引号
- preg_match_all('/([0-9a-z_-]+)=\'([^\']+)\'/i', $tag_attr, $attr_matchs);
- $attr_keys = !empty($attr_matchs[1]) ? $attr_matchs[1] : [];
- $attr_vals = !empty($attr_matchs[2]) ? $attr_matchs[2] : [];
- if (!empty($attr_keys)) {
- foreach ($attr_keys as $_ak => $_av) {
- $tag_attr_arr[$_av] = $attr_vals[$_ak];
- }
- // 每页条数
- if (!empty($tag_attr_arr['loop'])) $tag_attr_arr['pagesize'] = intval($tag_attr_arr['loop']);
- $tag_attr_arr['pagesize'] = !empty($tag_attr_arr['pagesize']) ? intval($tag_attr_arr['pagesize']) : 10;
- // 模型ID
- if (!empty($tag_attr_arr['modelid'])) $tag_attr_arr['channelid'] = intval($tag_attr_arr['modelid']);
- // 排序
- if (empty($tag_attr_arr['ordermode'])) {
- if (!empty($tag['orderWay'])) {
- $tag_attr_arr['ordermode'] = $tag_attr_arr['orderWay'];
- } else {
- $tag_attr_arr['ordermode'] = !empty($tag_attr_arr['orderway']) ? $tag_attr_arr['orderway'] : 'desc';
- }
- }
- }
- }
- $tag_attr_arr['orderby'] = !empty($tag_attr_arr['orderby']) ? $tag_attr_arr['orderby'] : "";
- $tag_attr_arr['ordermode'] = !empty($tag_attr_arr['ordermode']) ? $tag_attr_arr['ordermode'] : "desc";
- $tplData[$v['templist']] = $tag_attr_arr;
- } else {
- $tplData[$v['templist']]['count'] = -1;
- }
- }
- }
- $tplDataInfo = !empty($tplData[$v['templist']]) ? $tplData[$v['templist']] : [];
-
- if (2 == $method_mode) { // 方法2
- $map_arc2 = $map_arc;
- if (empty($web_stypeid_open)) { // 没开启副栏目
- $map_arc2['a.typeid'] = array('in', $arctypeAllSub[$v['typeid']]);
- } else { // 开启副栏目
- $stypeid_where = "";
- $typeid_str = implode(',', $arctypeAllSub[$v['typeid']]);
- foreach ($arctypeAllSub[$v['typeid']] as $_k => $_v) {
- $stypeid_where .= " OR CONCAT(',', a.stypeid, ',') LIKE '%,{$_v},%' ";
- }
- $map_arc2[] = $db::raw(" (a.typeid IN ({$typeid_str}) {$stypeid_where}) ");
- }
-
- $v['count'] = 0;
- if (!in_array($v['current_channel'], [6,8])) {
- $v['count'] = $db::name('archives')->alias('a')->where($map_arc2)->count('aid');
- }
- }
-
- if (in_array($v['current_channel'], [6,8])){
- $v['pagesize'] = 1;
- $v['pagetotal'] = 1;
- $pagetotal += $v['pagetotal'];
- }else{
- if (!empty($tplDataInfo)) {
- $count = !empty($tplDataInfo['count']) ? $tplDataInfo['count'] : 0;
- if (-1 == $count) {
- $v['count'] = 1;
- } else {
- $pagesize = !empty($tplDataInfo['pagesize']) ? $tplDataInfo['pagesize'] : 0;
- $channelid = !empty($tplDataInfo['channelid']) ? $tplDataInfo['channelid'] : 0;
- if (!empty($channelid)) {
- $map_arc['a.channel'] = $channelid;
- if (isset($map_arc['a.typeid'])) {
- unset($map_arc['a.typeid']);
- }
- if (isset($map_arc[0])) {
- foreach ($map_arc as $_k => $_v) {
- if (is_numeric($_k) && stristr($_v, 'stypeid')) {
- unset($map_arc[$_k]);
- }
- }
- }
- $v['count'] = $db::name('archives')->alias('a')->where($map_arc)->count();
- }
- if ($aid) {
- $orderby = !empty($tplDataInfo['orderby']) ? $tplDataInfo['orderby'] : '';
- $ordermode = !empty($tplDataInfo['ordermode']) ? $tplDataInfo['ordermode'] : 'desc';
- }
- }
- }
- $v['pagesize'] = !empty($pagesize) ? $pagesize : 10;
- $v['pagetotal'] = !empty($v['count']) ? (int)ceil($v['count'] / $v['pagesize']) : 1;
- $pagetotal += $v['pagetotal'];
- }
- $v['orderby'] = !empty($orderby) ? $orderby : "";
- $v['ordermode'] = !empty($ordermode) ? $ordermode : "desc";
-
- $info2[] = $v;
- }
- // file_put_contents ( ROOT_PATH."/log.txt", var_export($info2,true) . "\r\n", FILE_APPEND );
- // exit;
- return ["info"=>$info2, "pagetotal"=>$pagetotal];
- }
-
- }
|