diff --git a/application/controllers/information.php b/application/controllers/information.php index 52f1e0ca..e7e61f10 100644 --- a/application/controllers/information.php +++ b/application/controllers/information.php @@ -526,7 +526,8 @@ class Information extends CI_Controller { if ($delete_only === true) { $url = 'https://www.asiahighlights.com/index.php/information/delete_cache_8X913mksJ/?static_html_url=' . $url; } else { - $url = 'https://www.asiahighlights.com/index.php/information/detail/?static_html_url=' . $url; + // static_html_optimize=comeon 启用静态化压缩和js、css延迟加载 + $url = 'https://www.asiahighlights.com/index.php/information/detail/?static_html_url=' . $url . '&static_html_optimize=comeon'; } } else { //子站点使用 $url = $this->config->item('site_url') . $url . '@cache@refresh'; diff --git a/application/controllers/sendmail.php b/application/controllers/sendmail.php index 7325bc27..f63debf8 100644 --- a/application/controllers/sendmail.php +++ b/application/controllers/sendmail.php @@ -92,7 +92,7 @@ class Sendmail extends CI_Controller } } - $this->InfoSMS_model->set_mail_status($m->M_SN,1,$order_condition); + $this->InfoSMS_model->set_mail_status($m->M_SN,1); $this->email->clear(TRUE); } } diff --git a/application/controllers/welcome.php b/application/controllers/welcome.php index efaaf3a3..bbea50bc 100644 --- a/application/controllers/welcome.php +++ b/application/controllers/welcome.php @@ -12,7 +12,9 @@ class Welcome extends CI_Controller { $this->load->model('Area_model'); $this->load->model('InfoStructures_model'); $this->load->model('Information_model'); + $this->load->model('InfoContents_model'); $this->load->model('Coupon_model'); + $this->load->model('Logs_model'); } public function index() { @@ -94,6 +96,130 @@ class Welcome extends CI_Controller { $this->load->view('bootstrap/footer'); } + public function get_infomation_urls($is_parent_id) { + $this->output->enable_profiler(FALSE); + $structure = $this->InfoStructures_model->Detail($is_parent_id); + if (empty($structure)) { + show_404(); + return false; + } + $data['all_information'] = $this->Information_model->get_list_by_path($structure->is_path); + + $this->load->view('bootstrap/header', $data); + $this->load->view('bootstrap/static_url', $data); + $this->load->view('bootstrap/footer'); + } + + public function get_info_backup_id($info_id) { + $last_backup = $this->Logs_model->get_last_backup($info_id); + if (empty($last_backup)) { + $this->echo_json(array( + 'status' => 'error', + 'logId' => 0, + 'datetime' => 0, + 'username' => 0 + )); + } else { + $this->echo_json(array( + 'status' => 'success', + 'logId' => $last_backup->log_id, + 'datetime' => $last_backup->log_datetime, + 'username' => $last_backup->log_ht_username + )); + } + } + + public function change_static_url($info_id) { + $information = $this->Information_model->Detail($info_id); + $htm_doc = new DOMDocument(); + $htm_doc->encoding='UTF-8'; + libxml_use_internal_errors(true); + $htm_doc->strictErrorChecking = false; + if (empty($information->ic_content)) { + $this->echo_json(array( + 'status' => 'error', + 'infoId' => $info_id, + 'message' => 'info content is empty' + )); + return; + } + $htm_doc->loadHTML( + mb_convert_encoding($information->ic_content, 'HTML-ENTITIES', 'UTF-8')); + $htm_doc->normalizeDocument(); + $img_list = $htm_doc->getElementsByTagName('img'); + foreach ($img_list as $img) { + $img_src = $img->getAttribute('src'); + $img_src = $this->check_url($img_src); + $img->setAttribute('src', $img_src); + } + + $information->ic_content = $htm_doc->saveHTML(); + $this->InfoContents_model->Update( + $information->ic_id, + $information->ic_url, + $information->ic_url_title, + $information->ic_type, + $information->ic_title, + $information->ic_content, + $information->ic_summary, + $information->ic_seo_title, + $information->ic_seo_description, + $information->ic_seo_keywords, + $information->ic_show_bread_crumbs, + $information->ic_status, + $information->ic_template, + $information->ic_photo, + $information->ic_photo_width, + $information->ic_photo_height, + $information->ic_recommend_tours, + $information->ic_recommend_packages, + $information->ic_ht_area_id, + $information->ic_ht_area_type, + $information->ic_ht_product_id, + $information->ic_ht_product_type, + $information->ic_author); + + $this->echo_json(array( + 'status' => 'ok', + 'infoId' => $info_id, + 'message' => 'success', + 'date' => date('Y-m-d h:i:s') + )); + } + + private function echo_json($obj) { + $this->output + ->set_content_type('application/json') + ->set_output(json_encode($obj)); + } + + private function check_url($subject) { + $result = $subject; + $check_rules = array( + '/^\/image\/(.*)/' => '//data.chinahighlights.com/image/', + '/^\/pic\/(.*)/' => '//data.chinahighlights.com/pic/', + '/^\/allpicture\/(.*)/' => '//data.chinahighlights.com/allpicture/', + '/^http:\/\/images.chinahighlights.com(.*)/' => '//images.chinahighlights.com', + '/^http:\/\/data.chinahighlights.com(.*)/' => '//data.chinahighlights.com', + '/^http:\/\/www.chinahighlights.com(.*)/' => '//www.chinahighlights.com'); + + foreach ($check_rules as $pattern => $replace) { + $result = $this->replace_url($pattern, $replace, $result); + } + return $result; + } + + private function replace_url($pattern, $replace, $subject) { + $result = $subject; + $match_result = array(); + preg_match($pattern, $subject, $match_result); + $result_count = count($match_result); + if ($result_count == 2) { + $result = $replace.$match_result[1]; + } + return $result; + } + //生肖促销订单查询 public function coupon() { $data['countryList'] = $this->Area_model->get_country_list(); diff --git a/application/helpers/info_helper.php b/application/helpers/info_helper.php index fc53eb95..99909ace 100644 --- a/application/helpers/info_helper.php +++ b/application/helpers/info_helper.php @@ -296,7 +296,12 @@ function get_content_by_url($url) { curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在 - curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 + if (isset($_SERVER['HTTP_USER_AGENT'])) { + $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT']; + } else { + $HTTP_USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'; + } + curl_setopt($curl, CURLOPT_USERAGENT, $HTTP_USER_AGENT); // 模拟用户使用的浏览器 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer if ($method == 'POST' && !empty($data)) { diff --git a/application/libraries/simple_html_dom_lib.php b/application/libraries/simple_html_dom_lib.php new file mode 100644 index 00000000..0e0d7192 --- /dev/null +++ b/application/libraries/simple_html_dom_lib.php @@ -0,0 +1,9 @@ +config->item('site_image_url'), $this->config->item('site_image_url'),$ic_content); $ic_content=str_replace($this->config->item('media_image_url_remote2'), $this->config->item('site_image_url'),$ic_content); $ic_content=str_replace($this->config->item('media_image_url_org'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url2'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url_remote'), $this->config->item('site_image_url'),$ic_content); $ic_content=str_replace('#textarea#', 'textarea',$ic_content); $sql = "INSERT INTO infoContents \n" . " ( \n" @@ -41,7 +45,9 @@ class InfoContents_model extends CI_Model $ic_show_bread_crumbs, $ic_status, $ic_template, $ic_photo, $ic_photo_width, $ic_photo_height, $ic_recommend_tours, $ic_recommend_packages, $ic_ht_area_id, $ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author) { + $ic_content=str_replace('http:'.$this->config->item('site_image_url'), $this->config->item('site_image_url'),$ic_content); $ic_content=str_replace($this->config->item('media_image_url'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url2'), $this->config->item('site_image_url'),$ic_content); $ic_content=str_replace($this->config->item('media_image_url_org'), $this->config->item('site_image_url'),$ic_content); $ic_content=str_replace($this->config->item('media_image_url_remote'), $this->config->item('site_image_url'),$ic_content); $ic_content=str_replace($this->config->item('media_image_url_remote2'), $this->config->item('site_image_url'),$ic_content); diff --git a/application/models/logs_model.php b/application/models/logs_model.php index 5be5e378..9e269469 100644 --- a/application/models/logs_model.php +++ b/application/models/logs_model.php @@ -41,6 +41,15 @@ class Logs_model extends CI_Model { return $this->get_list(); } + //获取最近的备份信息内容 + function get_last_backup($is_id) { + $this->init(); + $this->top_num = 1; + $this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id); + $this->log_action = " AND il.log_action = 'backup_info'"; + return $this->get_list(); + } + //获取所有备份信息内容 function get_all_backup_list($is_id) { $this->init(); @@ -76,13 +85,13 @@ class Logs_model extends CI_Model { $map = ''; if ($last_id) $map = " AND log_id > $last_id"; - $sql = " SELECT log_id,is_sitecode,ic_url - FROM infoLogs - LEFT JOIN infoStructures ON is_id=log_res_id - LEFT JOIN infoContents ON is_ic_id=ic_id - WHERE ic_url != '' - AND log_action = 'backup_info' - + $sql = " SELECT log_id,is_sitecode,ic_url + FROM infoLogs + LEFT JOIN infoStructures ON is_id=log_res_id + LEFT JOIN infoContents ON is_ic_id=ic_id + WHERE ic_url != '' + AND log_action = 'backup_info' + $map ORDER BY log_id ASC"; $query = $this->HT->query($sql); @@ -170,7 +179,7 @@ class Logs_model extends CI_Model { ,log_datetime ) VALUES - ( ?,?,N?,?,?,GETDATE()) + ( ?,?,N?,?,?,GETDATE()) "; $query = $this->HT->query($sql, array('write_test', 0, '数据库写入测试', 'system', 'system')); diff --git a/application/third_party/htmlcompressor/controllers/index.php b/application/third_party/htmlcompressor/controllers/index.php new file mode 100644 index 00000000..bbf12e44 --- /dev/null +++ b/application/third_party/htmlcompressor/controllers/index.php @@ -0,0 +1,141 @@ +load->library('simple_html_dom_lib'); + } + + public function index() { + $this->load->view('welcome'); + } + + public function optimize() { + $htmlsource = $this->input->post('htmlsource'); + $websitehost = $this->input->post('websitehost'); + if (empty($htmlsource) || empty($websitehost)) { + $this->output->set_status_header(500); + echo 'error:htmlsource or websitehost is empty!'; + return false; + } + //域名后面不能有/ + if (substr($websitehost, -1, 1) == '/') { + $websitehost = substr($websitehost, 0, -1); + } + + $html_object = str_get_html($htmlsource); + if (!empty($html_object)) { + +//提取和下载所有CSS样式,包括链接文件和页面样式 + $link_css_array = array(); + $css_content = ''; + foreach ($html_object->find('link') as $link_css) { + if ($link_css->rel == 'stylesheet' && !empty($link_css->href)) { + $link_css_array[] = $link_css->href; + $link_css->outertext = ''; //删除链接 + } + } + //print_r($link_css_array); + foreach ($link_css_array as $item) { + $get_http_temp = GET_HTTP($this->format_url($item, $websitehost)); + if ($get_http_temp == false) { + $this->output->set_status_header(404); + echo 'CSS文件下载错误'; + return FALSE; + } + $css_content.=$get_http_temp; + } + foreach ($html_object->find('style') as $style_css) { + if ($style_css->type == "text/css") { + $css_content .= $style_css->innertext; + } + } + // echo $css_content; + // echo $html_object;die(); + // +//提取和下载所有JS脚本,包括链接文件和页面脚本 + $link_js_array = array(); + $js_inline_content = ''; + $js_jquery_content = ''; + foreach ($html_object->find('script') as $link_script) { + if (!empty($link_script->src)) { + $link_js_array[] = $link_script->src; + $link_script->outertext = ''; //删除链接,移动到页底 + } else { + //网页内的js不需要提取 + //$js_content.= $link_script->innertext;//js的内容 + // $js_content.= $link_script;//js的内容,包含'; + + $js_content = $js_scr_content . $js_jquery_content; + //延迟加载js,需要把返回的js代码保存到一个文件中,然后替换占位符,以便加载js文件 + $lastload_js.=''; + $lastload_js.=$js_inline_content; + + $html_object = str_replace('
+', $lastload_js . '', $html_object); + } + echo json_encode(array('result' => 'ok', 'data' => array('html_object' => $html_object, 'js_content' => $js_content))); + } + +//格式化url,保证请求的URL有域名,//更换为对应的域名路径 + function format_url($url, $host = '') { + if (substr($url, 0, 8) == 'https://' || substr($url, 0, 7) == 'http://') { + return urldecode($url); + } + + if (substr($url, 0, 2) == '//') { //https或http + return urldecode(str_replace('//', 'http://', $url)); + } + + return urldecode($host . $url); + } + +} diff --git a/application/third_party/htmlcompressor/views/welcome.php b/application/third_party/htmlcompressor/views/welcome.php new file mode 100644 index 00000000..e18468fd --- /dev/null +++ b/application/third_party/htmlcompressor/views/welcome.php @@ -0,0 +1,22 @@ + + +
+ + + + +
+ + +
+