Files

171 lines
6.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php namespace Phpcmf\Control;
/**
* https://www.besyun.com
* BESCMS
* 本代码基于MIT开源协议,协议规定此处版权信息不可去除
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
// 生成静态
class Html extends \Phpcmf\Home\Module {
private $is_html;
// 首页动作
public function _index_page() {
ob_start();
\Phpcmf\Service::V()->assign([
'is_cms' => 1,
'indexc' => 1,
'fix_html_now_url' => defined('IS_MOBILE') && IS_MOBILE ? SITE_MURL : SITE_URL,
]);
\Phpcmf\Service::V()->assign($this->_index_seo());
\Phpcmf\Service::V()->display('index.html');
$html = ob_get_clean();
// 开启过首页静态时
if ($this->site_info[SITE_ID]['SITE_INDEX_HTML'] && !defined('SC_HTML_FILE')) {
if (IS_CLIENT) {
// 自定义终端
$file = dr_is_app('chtml') ? \Phpcmf\Service::L('html', 'chtml')->get_webpath(SITE_ID, 'site', IS_CLIENT.'/index.html') : WEBPATH.IS_CLIENT.'/index.html';
$rt = file_put_contents($file, $html);
!$rt && CI_DEBUG && log_message('error', '首页终端('.IS_CLIENT.')生成失败:'.$file);
} elseif (defined('IS_MOBILE') && IS_MOBILE) {
// 移动端,当移动端独立域名情况下才生成静态
if (defined('SITE_IS_MOBILE_HTML') && SITE_IS_MOBILE_HTML && SITE_MURL == dr_now_url()) {
$mfile = dr_is_app('chtml') ? \Phpcmf\Service::L('html', 'chtml')->get_webpath(SITE_ID, 'site', SITE_MOBILE_DIR.'/index.html') : WEBPATH.SITE_MOBILE_DIR.'/index.html';
$mobile = file_put_contents($mfile, $html);
!$mobile && CI_DEBUG && log_message('error', '首页移动端生成失败:'.$mfile);
}
} else {
// pc
$file = dr_is_app('chtml') ? \Phpcmf\Service::L('html', 'chtml')->get_webpath(SITE_ID, 'site', 'index.html') : WEBPATH.'index.html';
$pc = file_put_contents($file, $html);
!$pc && CI_DEBUG && log_message('error', '首页PC端首页生成失败:'.$file);
}
}
echo $html;
}
// 首页显示
public function index() {
if (IS_POST) {
$this->_json(0, '禁止提交,请检查提交地址是否有误');
}
// 挂钩点 网站首页时
\Phpcmf\Hooks::trigger_callback('cms_index');
\Phpcmf\Service::L('Router')->is_redirect_url(dr_url_prefix('/'), 1);
$this->_index_page();
}
// 生成静态
public function html() {
// 判断权限
if (!dr_html_auth()) {
$this->_json(0, '权限验证超时,请重新执行生成');
}
// 标识变量
!defined('SC_HTML_FILE') && define('SC_HTML_FILE', 1);
// 开启ob函数
ob_start();
$this->is_html = 1;
\Phpcmf\Service::V()->init('pc');
\Phpcmf\Service::V()->assign([
'fix_html_now_url' => SITE_URL, // 修复静态下的当前url变量
]);
$this->_index_page();
$html = ob_get_clean();
$file = dr_is_app('chtml') ? \Phpcmf\Service::L('html', 'chtml')->get_webpath(SITE_ID, 'site', 'index.html') : WEBPATH.'index.html';
$pc = file_put_contents($file, $html, LOCK_EX);
!$pc && CI_DEBUG && log_message('error', '首页PC端首页生成失败:'.$file);
if (SITE_MURL != SITE_URL) {
// 开启ob函数
ob_start();
$this->is_html = 1;
\Phpcmf\Service::V()->init('mobile');
\Phpcmf\Service::V()->assign([
'fix_html_now_url' => SITE_MURL, // 修复静态下的当前url变量
]);
$this->_index_page();
$html = ob_get_clean();
$mfile = dr_is_app('chtml') ? \Phpcmf\Service::L('html', 'chtml')->get_webpath(SITE_ID, 'site', SITE_MOBILE_DIR.'/index.html') : WEBPATH.SITE_MOBILE_DIR.'/index.html';
$mobile = file_put_contents($mfile, $html, LOCK_EX);
!$mobile && CI_DEBUG && log_message('error', '首页移动端生成失败:'.$mfile);
} else {
CI_DEBUG && log_message('error', '首页移动端生成失败:移动端未绑定域名');
}
$this->_json(1, dr_lang('电脑端 %s),移动端 %s', dr_format_file_size($pc), dr_format_file_size($mobile)));
}
private function _index_seo() {
$seo = [
'meta_title' => \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'seo', 'SITE_TITLE'),
'meta_keywords' => \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'seo', 'SITE_KEYWORDS'),
'meta_description' => \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'seo', 'SITE_DESCRIPTION')
];
if (IS_CLIENT) {
// 终端模式下
$cdata = \Phpcmf\Service::R(WRITEPATH.'config/app_client_seo_'.SITE_ID.'.php');
if ($cdata && isset($cdata[IS_CLIENT]) && $cdata[IS_CLIENT]) {
$seo = [
'meta_title' => $cdata[IS_CLIENT]['SITE_TITLE'],
'meta_keywords' => $cdata[IS_CLIENT]['SITE_KEYWORDS'],
'meta_description' => $cdata[IS_CLIENT]['SITE_DESCRIPTION']
];
}
}
!$seo['meta_title'] && $seo['meta_title'] = SITE_NAME;
if ($seo['meta_title'] && strpos($seo['meta_title'], '{page}') !== false) {
$page = max(1, intval($_GET['page']));
if ($page > 1) {
$seo['meta_title'] = str_replace(array('[', ']'), '', $seo['meta_title']);
$seo['meta_title'] = str_replace('{join}', SITE_SEOJOIN, $seo['meta_title']);
$seo['meta_title'] = str_replace('{page}', $page, $seo['meta_title']);
} else {
$seo['meta_title'] = preg_replace('/\[.+\]/U', '', $seo['meta_title']);
}
}
return \Phpcmf\Service::L('Seo')->get_seo_value([], $seo);
}
// 生成栏目
public function category() {
parent::_Category_Html();
}
// 生成内容
public function show() {
parent::_Show_Html();
}
// 生成栏目单页
public function categoryfile() {
parent::_Category_Html_File();
}
// 生成内容单页
public function showfile() {
parent::_Show_Html_File();
}
}