You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
5.1 KiB
PHTML

9 years ago
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Information extends CI_Controller {
public function __construct() {
parent::__construct();
//$this->output->enable_profiler(TRUE);
$this->load->model('Information_model');
$this->load->model('InfoMetas_model');
$this->load->library('Tags_analysis');
}
public function index() {
echo 'Information Index';
}
//优先使用传入的URL用于主动生成静态页面去映射(优先使用POST参数)
public function detail($url = '') {
$data = array();
if (empty($url)) {
$url = $this->input->get_post('static_html_url');
}
if (empty($url) || $url == 'index.php') {
$url = get_origin_url();
if (preg_match('/\?.*/', $url) == 1) {
$url = preg_replace('/\?.*/', '', $url);
php_301($url);
return;
}
}
//大小写转向只要url有大写字母的全部转到小写字母的url上
if ($url != mb_strtolower($url)) {
php_301(mb_strtolower($url));
return;
}
$data['detail'] = $this->Information_model->get_detail($url);
if ($data['detail'] === false) {
// send_404($this);todo写一个友好的404页面
redirect('/error/page_not_found');
return false;
}
$data['detail']->ic_content = $this->tags_analysis->analysis($data['detail']);
9 years ago
$data['seo_title'] = $data['detail']->ic_seo_title;
$data['seo_keywords'] = $data['detail']->ic_seo_keywords;
$data['seo_description'] = $data['detail']->ic_seo_description;
$data['seo_url'] = $data['detail']->ic_url;
//判断是否有AMP版本并生成缓存文件
if($this->InfoMetas_model->get($data['detail']->ic_id, 'AMP_STATUS')=='1'){
$AMP=$this->InfoMetas_model->get($data['detail']->ic_id, 'AMP');
if(!empty($AMP)){
if (mb_substr($data['seo_url'], -1, 1) == '/') {
$data['amp_url'] =$data['seo_url'].'index.htm.amp.htm';
}else{
$data['amp_url'] =$data['seo_url'].'.amp.htm';
}
$cache_path = 'd:/Dropbox/wwwcache/asiahighlights.com'.$data['amp_url'];
$dir=dirname($cache_path);
if (!is_dir($dir)) {
@mkdir($dir, 0777, true);
}
//表单替换和价格替换
$AMP_Clone_content=$data['detail']->ic_content;//因为tags_analysis是根据信息结构来替换的所以需要克隆一个信息结构然后用AMP代码覆盖ic_content
$data['detail']->ic_content =$AMP;
$AMP=$this->tags_analysis->analysis($data['detail']);
$data['detail']->ic_content=$AMP_Clone_content;
file_put_contents($cache_path,$AMP);
}
}
9 years ago
$data['meta_addon_css'] = $this->InfoMetas_model->get($data['detail']->ic_id, 'meta_addon_css');
$data['meta_addon_js'] = $this->InfoMetas_model->get($data['detail']->ic_id, 'meta_addon_js');
$this->load->view('header', $data);
$this->load->view('information_' . $data['detail']->ic_template);
$this->load->view('footer');
$this->output->cache(99999);
}
//后面这串是密码,防止爬虫程序扫到
//删除缓存文件比如页面不在发布或者修改了URL等情况
public function delete_cache_8X913mksJ() {
$url = $this->input->get_post('static_html_url');
if (empty($url)) {
$this->output->set_status_header(404);
return false;
}
$cache_path = 'd:/Dropbox/wwwcache/asiahighlights.com';
if (!is_dir($cache_path) OR ! is_really_writable($cache_path)) {
log_message('error', "Unable to write cache file: " . $cache_path);
$this->output->set_status_header(404);
return false;
}
$cache_path = $cache_path . $url;
if (mb_substr($cache_path, -1, 1) == '/') {
$cache_path.='index.htm';
}
//如果文件存在,先判断是否为缓存文件,防止覆盖原始程序文件
if (file_exists($cache_path)) {
if (!$fp_read = @fopen($cache_path, FOPEN_READ)) {
$this->output->set_status_header(404);
return FALSE;
}
flock($fp_read, LOCK_SH);
$cache = '';
if (filesize($cache_path) > 0) {
$cache = fread($fp_read, filesize($cache_path));
}
flock($fp_read, LOCK_UN);
fclose($fp_read);
if (strpos($cache, '<!-- Generated by ') === false) {
log_message('error', "is not cache file." . $cache_path);
$this->output->set_status_header(404);
return FALSE;
} else {
if (unlink($cache_path)) {
unlink($cache_path.'.mobile.htm');//删除移动端文件
echo 'ok';
return TRUE;
} else {
$this->output->set_status_header(404);
return FALSE;
}
}
}
9 years ago
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */