merge origin master

hotfix/远程访问多媒体中心
lmr@hainatravel.com 8 years ago
commit 2be745c070

@ -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';

@ -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);
}
}

@ -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();

@ -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)) {

@ -0,0 +1,9 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require '/lib/simple_html_dom.php';
class Simple_html_dom_lib extends CI_Controller{
}

@ -15,8 +15,12 @@ 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_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);

@ -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'));

@ -0,0 +1,141 @@
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Index extends CI_Controller {
public function __construct() {
parent::__construct();
$this->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的内容包含<script>
//含有$表示调用了jquery的函数添加延迟加载defer
if (strpos($link_script, '$') !== FALSE) {
$js_jquery_content.= $link_script->innertext;
} else {
$js_inline_content.= $link_script; //js的内容包含<script>
}
$link_script->outertext = ''; //删除js移动到页底
}
}
$js_scr_content = '';
foreach ($link_js_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 'JS文件下载错误';
return FALSE;
}
$js_scr_content.=$get_http_temp;
}
//echo $js_content;
//把网页内容和css提交到purifycss处理
$optimize_css = GET_HTTP('http://184.172.113.219:33033/', 'html_source=' . urlencode($htmlsource) . '&html_css=' . urlencode($css_content), 'POST');
if (empty($optimize_css)) {
$this->output->set_status_header(500);
echo 'css精简错误';
return FALSE;
}
//把精简的css添加到head前面
$html_object = str_replace('</head>', '<style type="text/css">' . $optimize_css . "</style></head>", $html_object);
//删除多余空格和换行符
$html_object = str_replace(array(" ", "\t", "\n", "\r"), " ", $html_object);
//循环n次把双空格替换为一个空格
for ($i = 0; $i <= 4; $i++) {
$html_object = str_replace(" ", " ", $html_object);
}
//在最后加载原始css文件和js文件
//把css移动到页面底部延迟加载
$lastload_js = '<noscript id="deferred-styles">';
foreach ($link_css_array as $item) {
$lastload_js.='<link rel="stylesheet" type="text/css" href="' . $item . '"/>';
}
$lastload_js.='</noscript><script>var loadDeferredStyles=function(){var addStylesNode=document.getElementById("deferred-styles");var replacement=document.createElement("div");replacement.innerHTML=addStylesNode.textContent;document.body.appendChild(replacement);addStylesNode.parentElement.removeChild(addStylesNode)};var raf=requestAnimationFrame||mozRequestAnimationFrame||webkitRequestAnimationFrame||msRequestAnimationFrame;if(raf){raf(function(){window.setTimeout(loadDeferredStyles,0)})}else{window.addEventListener("load",loadDeferredStyles)};</script>';
$js_content = $js_scr_content . $js_jquery_content;
//延迟加载js需要把返回的js代码保存到一个文件中然后替换占位符以便加载js文件
$lastload_js.='<script defer src="##DEFERSCRIPTDEFER##"></script>';
$lastload_js.=$js_inline_content;
$html_object = str_replace('</body>', $lastload_js . '</body>', $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);
}
}

@ -0,0 +1,22 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="Expires" CONTENT="0"/>
<meta http-equiv="Cache-Control" CONTENT="no-cache"/>
<meta http-equiv="Pragma" CONTENT="no-cache"/>
<title>HTML-Compressor</title>
</head>
<script type="text/javascript">
</script>
<body>
<h1>页面样式精简</h1>
<form name="form_htmlsource" id="form_htmlsource" action="<?php echo site_url('apps/htmlcompressor/index/optimize'); ?>" method="post">
<input type="text" name="websitehost" id="websitehost" style="width:200px;" placeholder="域名" /><br/><br/>
<textarea name="htmlsource" id="htmlsource" rows="22" style="width:800px;" placeholder="网页代码" ></textarea>
<input type="submit"/>
</form>
</body>
</html>

@ -0,0 +1,132 @@
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Index extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('PageSpeedData_model');
}
public function index() {
$this->permission->is_admin();
$data = array();
$data['score_data'] = $this->PageSpeedData_model->score_chart($this->config->item('site_code'));
$this->load->view('bootstrap3/header', $data);
$this->load->view('welcome');
$this->load->view('bootstrap3/footer');
}
//根据分数段来查询页面
public function search_score() {
$this->permission->is_admin();
$data = array();
$device = $this->input->post('device');
$start_score = $this->input->post('start_score');
$end_score = $this->input->post('end_score');
$data['score_data_list'] = $this->PageSpeedData_model->search_score_list($start_score, $end_score, $this->config->item('site_code'), $device);
if (empty($data['score_data_list'])) {
echo json_encode('没有找到数据');
} else {
echo json_encode($this->load->view('search', $data, true));
}
}
//自动抓取分数和排名
public function auto($sitecode = 'cht') {
//添加数据,信息平台中发布的,并且当前数据库没有的
$this->PageSpeedData_model->insert_list($sitecode);
$update_list = $this->PageSpeedData_model->get_update_list($sitecode, 2);
if (empty($update_list)) {
echo'all done!';
return;
}
foreach ($update_list as $item) {
$this->run($item->psd_URL, $item->
psd_SiteCode);
}
}
public function show_score() {
$psd_URL = $this->input->get_post('psd_URL');
$psd_SiteCode = $this->input->get_post('psd_SiteCode');
if (empty($psd_URL) || empty($psd_SiteCode)) {
echo json_encode(array('result' => 'error', 'data' => 'url或站点为空'));
return false;
}
$pagespeed_data = $this->PageSpeedData_model->detail($psd_URL, $psd_SiteCode);
if (!empty($pagespeed_data)) {
echo json_encode(array('result' => 'ok', 'data' => 'M:' . $pagespeed_data->psd_MobileScore . ',D:' . $pagespeed_data->
psd_DesktopScore));
}
}
public function run($psd_URL = false, $psd_SiteCode = false) {
if (empty($psd_URL) || empty($psd_SiteCode)) {
$psd_URL = $this->input->get_post('psd_URL');
$psd_SiteCode = $this->input->get_post('psd_SiteCode');
if (empty($psd_URL) || empty($psd_SiteCode)) {
echo json_encode(array('result' => 'error', 'data' => 'url或站点为空'));
return false;
}
}
$sites = $this->config->item('site');
if (empty($sites[$psd_SiteCode])) {
echo json_encode(array('result' => 'error', 'data' => '找不到站点'));
return false;
}
$site_url = rtrim($sites[$psd_SiteCode]['site_url'], '/'); //删除/因为URL已经含有了
$run_URL = urlencode(trim($site_url . $psd_URL));
$pagespeed_data = $this->PageSpeedData_model->detail($psd_URL, $psd_SiteCode);
$PageSpeedData = new StdClass;
$desktop_url = "https://www.googleapis.com/pagespeedonline/v2/runPagespeed?strategy=desktop&locale=zh_CN&url=$run_URL";
//$desktop_url = "http://pagespeed.mycht.cn/pagespeedonline/v2/runPagespeed?strategy=desktop&locale=zh_CN&url=$run_URL";
$mobile_url = "https://www.googleapis.com/pagespeedonline/v2/runPagespeed?strategy=mobile&locale=zh_CN&url=$run_URL";
//$mobile_url = "http://pagespeed.mycht.cn/pagespeedonline/v2/runPagespeed?strategy=mobile&locale=zh_CN&url=$run_URL";
//echo $desktop_url;die();
$desktop_data = GET_HTTP($desktop_url);
$mobile_data = GET_HTTP($mobile_url);
if (empty($desktop_data) || empty($mobile_data)) {
echo json_encode(array('result' => 'error', 'data' => 'API不返回数据'));
return false;
}
$desktop_object = json_decode($desktop_data);
$mobile_object = json_decode($mobile_data);
if (isset($desktop_object->error) || isset($mobile_object->error)) {
$this->PageSpeedData_model->update_error($pagespeed_data->psd_id);
echo json_encode(array('result' => 'error', 'data' => 'API返回错误'));
log_message('error ', 'pagespeed_error:' . json_encode($desktop_object) . ' ' . json_encode($mobile_object));
return false;
}
if ($desktop_object->responseCode !== 200 || $mobile_object->responseCode !== 200) {
$this->PageSpeedData_model->update_error($pagespeed_data->psd_id);
echo json_encode(array('result' => 'error', 'data' => 'API返回错误网页打不开'));
log_message('error ', 'pagespeed_error:' . json_encode($desktop_object) . ' ' . json_encode($mobile_object));
return FALSE;
}
$PageSpeedData->psd_DesktopScore = $desktop_object->ruleGroups->SPEED->score;
$PageSpeedData->psd_MobileScore = $mobile_object->ruleGroups->SPEED->score;
$PageSpeedData->psd_DesktopData = $desktop_data;
$PageSpeedData->psd_MobileData = $mobile_data;
$PageSpeedData->psd_URL = $psd_URL;
$PageSpeedData->psd_Datetime = date('Y-m-d H:i:s', time());
$PageSpeedData->psd_SiteCode = $psd_SiteCode;
$PageSpeedData->psd_ErrorCount = 0;
if (empty($pagespeed_data)) {
$psd_id = $this->PageSpeedData_model->add('PageSpeedData', $PageSpeedData);
} else {
$where = array('psd_id' => $pagespeed_data->psd_id);
$this->PageSpeedData_model->update('PageSpeedData', $PageSpeedData, $where);
}
echo json_encode(array('result' => 'ok', 'data' => 'M:' . $PageSpeedData->psd_MobileScore . ',D:' . $PageSpeedData->psd_DesktopScore));
}
}

@ -0,0 +1,177 @@
<?php
class PageSpeedData_model extends CI_Model {
var $topnum = false; //返回记录数
var $orderby = false;
var $where = false; //查询条件
function __construct() {
parent::__construct();
$this->HT = $this->load->database('HT', TRUE);
$this->INFO = $this->load->database('INFO', TRUE);
}
public function init() {
$this->topnum = false;
$this->where = false;
$this->orderby = ' ORDER BY psd_Datetime ASC ';
}
public function detail($psd_URL, $psd_SiteCode) {
$this->init();
$this->topnum = 1;
$this->where = ' AND psd.psd_URL=' . $this->INFO->escape($psd_URL);
$this->where .= ' AND psd.psd_SiteCode=' . $this->INFO->escape($psd_SiteCode);
return $this->get_list();
}
public function add($table, $data) {
if ($this->INFO->insert($table, $data)) {
return $this->INFO->last_id($table);
} else {
return false;
}
}
public function insert_list($psd_SiteCode) {
$sql = "
INSERT INTO PageSpeedData
(
psd_URL
,psd_SiteCode
)
SELECT TOP 200 ic.ic_url
,ic.ic_sitecode
FROM Tourmanager.dbo.infoContents ic
WHERE ic.ic_status = 1
AND ic.ic_url<>''
AND ic.ic_sitecode = ?
AND NOT EXISTS(
SELECT TOP 1 1
FROM PageSpeedData psd
WHERE psd.psd_URL = ic.ic_url
AND psd.psd_SiteCode = ic.ic_sitecode
)
ORDER BY
ic.ic_datetime ASC
";
$this->INFO->query($sql, array($psd_SiteCode));
}
public function get_update_list($psd_SiteCode, $topnum = 3) {
$this->init();
$this->topnum = $topnum;
$this->where = ' AND psd.psd_SiteCode=' . $this->INFO->escape($psd_SiteCode);
$this->where .= ' AND ISNULL(psd.psd_Datetime,1999) < GETDATE()-1 ';
$this->where .= ' AND psd.psd_ErrorCount<=3 ';
$this->orderby = ' ORDER BY psd_Datetime ASC ';
return $this->get_list();
}
public function update($table, $data, $where) {
$this->INFO->update($table, $data, $where);
}
//记录错误次数
public function update_error($psd_id) {
$sql = "
UPDATE PageSpeedData
SET psd_ErrorCount = psd_ErrorCount+1
, psd_Datetime=GETDATE()
WHERE psd_id = ?
";
$this->INFO->query($sql, array($psd_id));
//删除错误数大于3的数据保持没有冗余数据 ,不删除,很多页面信息平台发布了,但是网前删除了
//$sql = " DELETE FROM PageSpeedData WHERE psd_ErrorCount>3 ";
// $this->INFO->query($sql);
}
//删除数据
// public function delete($psd_id) {
// $sql = " DELETE FROM PageSpeedData WHERE psd_id=? ";
// return $this->INFO->query($sql, array($psd_id));
// }
public function get_list() {
$this->topnum ? $sql = "SELECT TOP " . $this->topnum : $sql = "SELECT ";
$sql .= "
psd.psd_id,
psd.psd_DesktopScore,
psd.psd_MobileScore,
psd.psd_DesktopData,
psd.psd_MobileData,
psd.psd_URL,
psd.psd_Datetime,
psd.psd_SiteCode,
psd.psd_ErrorCount
FROM
PageSpeedData psd
WHERE 1 = 1
";
$this->where ? $sql.=$this->where : false;
$this->orderby ? $sql.=$this->orderby : false;
$query = $this->INFO->query($sql);
//print_r($this->INFO->queries);
if ($this->topnum === 1) {
if ($query->num_rows() > 0) {
$row = $query->row();
return $row;
} else {
return FALSE;
}
} else {
return $query->result();
}
}
public function search_score_list($start_score, $end_score, $psd_SiteCode, $device = 'moblie') {
$this->init();
$this->topnum = 50;
$this->where = ' AND psd.psd_SiteCode=' . $this->INFO->escape($psd_SiteCode);
if ($device == 'moblie') {
$this->where .= " AND psd.psd_MobileScore BETWEEN $start_score AND $end_score ";
$this->orderby = ' ORDER BY psd_MobileScore ASC ';
} else {
$this->where .= " AND psd.psd_DesktopScore BETWEEN $start_score AND $end_score ";
$this->orderby = ' ORDER BY psd_DesktopScore ASC ';
}
$this->where .= " AND psd.psd_ErrorCount<=3 ";
return $this->get_list();
}
//分数段统计
public function score_chart($psd_SiteCode) {
$sql = "
SELECT COUNT(psd.psd_id) AS [page_count]
,AVG(psd.psd_DesktopScore)AS [d_avg]
,COUNT(CASE WHEN psd.psd_DesktopScore BETWEEN 96 AND 100 THEN 1 END) AS [d96_100]
,COUNT(CASE WHEN psd.psd_DesktopScore BETWEEN 90 AND 95 THEN 1 END) AS [d90_95]
,COUNT(CASE WHEN psd.psd_DesktopScore BETWEEN 86 AND 89 THEN 1 END) AS [d86_89]
,COUNT(CASE WHEN psd.psd_DesktopScore BETWEEN 80 AND 85 THEN 1 END) AS [d80_85]
,COUNT(CASE WHEN psd.psd_DesktopScore BETWEEN 70 AND 79 THEN 1 END) AS [d70_79]
,COUNT(CASE WHEN psd.psd_DesktopScore BETWEEN 60 AND 69 THEN 1 END) AS [d60_69]
,COUNT(CASE WHEN psd.psd_DesktopScore<60 THEN 1 END) AS [d60_0]
,AVG(psd.psd_MobileScore)AS [m_avg]
,COUNT(CASE WHEN psd.psd_MobileScore BETWEEN 96 AND 100 THEN 1 END) AS [m96_100]
,COUNT(CASE WHEN psd.psd_MobileScore BETWEEN 90 AND 95 THEN 1 END) AS [m90_95]
,COUNT(CASE WHEN psd.psd_MobileScore BETWEEN 86 AND 89 THEN 1 END) AS [m86_89]
,COUNT(CASE WHEN psd.psd_MobileScore BETWEEN 80 AND 85 THEN 1 END) AS [m80_85]
,COUNT(CASE WHEN psd.psd_MobileScore BETWEEN 70 AND 79 THEN 1 END) AS [m70_79]
,COUNT(CASE WHEN psd.psd_MobileScore BETWEEN 60 AND 69 THEN 1 END) AS [m60_69]
,COUNT(CASE WHEN psd.psd_MobileScore<60 THEN 1 END) AS [m60_0]
FROM PageSpeedData psd
WHERE 1=1
AND psd.psd_SiteCode=?
AND psd.psd_ErrorCount<=3
";
$query = $this->INFO->query($sql, array($psd_SiteCode));
if ($query->num_rows() > 0) {
$row = $query->row();
return $row;
} else {
return FALSE;
}
}
}

@ -0,0 +1,44 @@
<?php
foreach ($score_data_list as $key => $item) {
}
?>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th class="col-sm-1">#</th>
<th class="col-sm-5">页面</th>
<th class="col-sm-1">移动端</th>
<th class="col-sm-1">桌面端</th>
<th class="col-sm-2">更新时间</th>
<th class="col-sm-2">操作</th>
</tr>
</thead>
<tbody>
<?php
$site_url = rtrim($this->config->item('site_url'), '/');
if (!empty($score_data_list)) {
foreach ($score_data_list as $key => $item) {
?>
<tr>
<td><?php echo ++$key; ?></td>
<td><?php echo $item->psd_URL; ?></td>
<td><?php echo $item->psd_MobileScore; ?></td>
<td><?php echo $item->psd_DesktopScore; ?></td>
<td><?php echo date('Y-m-d', strtotime($item->psd_Datetime)); ?></td>
<td>
<a href="<?php echo $site_url . $item->psd_URL ?>" target="_blank">查看页面</a> |
<a href="https://developers.google.com/speed/pagespeed/insights/?url=<?php echo urlencode($site_url . $item->psd_URL); ?>" target="_blank">Google insights</a>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>

@ -0,0 +1,80 @@
<script type="text/javascript" src="/js/highcharts/highcharts.js"></script>
<script type="text/javascript">
$(function() {
$('#score_chart').highcharts({
chart: {type: 'column'},
title: {text: '网页性能分数分布图'},
subtitle: {
text: '移动端平均分:<?php echo $score_data->m_avg; ?> | 桌面端平均分:<?php echo $score_data->d_avg; ?> 总页面数:<?php echo $score_data->page_count; ?>'
},
xAxis: {
categories: [
'60分以下',
'60-69分',
'70-79分',
'80-85分',
'86-89分',
'90-95分',
'96-100分'
],
crosshair: true
},
yAxis: {
min: 0,
title: {
text: '网页数量'
}
},
plotOptions: {
column: {
dataLabels: {
enabled: true
},
enableMouseTracking: true
}
},
series: [
{name: '移动', data: [<?php echo $score_data->m60_0 . ',' . $score_data->m60_69 . ',' . $score_data->m70_79 . ',' . $score_data->m80_85 . ',' . $score_data->m86_89 . ',' . $score_data->m90_95 . ',' . $score_data->m96_100; ?>]}
, {name: '桌面', data: [<?php echo $score_data->d60_0 . ',' . $score_data->d60_69 . ',' . $score_data->d70_79 . ',' . $score_data->d80_85 . ',' . $score_data->d86_89 . ',' . $score_data->d90_95 . ',' . $score_data->d96_100; ?>]}
]
});
});
</script>
<div id="score_chart" ></div>
<legend>根据分数搜索页面</legend>
<form class="form-inline" method="post" name="form_score_search" id="form_score_search" action="<?php echo site_url('apps/pagespeed/index/search_score'); ?>">
<div class="form-group">
<label for="exampleInputEmail1"></label>
<input type="number" class="form-control" id="start_score" name="start_score" placeholder="开始分数">
<input type="number" class="form-control" id="end_score" name="end_score" placeholder="结束分数">
<select class="form-control" name="device">
<option value="moblie">Mobile</option>
<option value="desktop">Desktop</option>
</select>
</div>
<button type="button" class="btn btn-default" onclick="submit_search();">搜索</button>
</form>
<div id="search_result_box"></div>
<script type="text/javascript">
function submit_search() {
$('#form_score_search').ajaxSubmit({
success: function(data, textStatus) {
$('#search_result_box').html(data);
},
error: function(msg) {
alert('\u53d1\u751f\u9519\u8bef\uff0c\u8bf7\u8054\u7cfbYCC...');
},
dataType: 'json',
timeout: 30000
});
return false;
}
</script>

@ -73,11 +73,12 @@
更多<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="http://www.arachina.com/html-tag-quick-query.htm"></a>html知识</li>
<li><a href="<?php echo site_url('apps/pagespeed') ?>">页面性能分析</a></li>
<li><a href="<?php echo site_url('seo') ?>">SEO管理</a></li>
<li> <a href="<?php echo site_url('thirdparty/public/infopayauthor') ?>">打赏统计</a></li>
<li> <a href="<?php echo site_url('thirdparty/form') ?>">表单管理</a></li>
<li><a href="<?php echo site_url('thirdparty/advertise') ?>">广告管理</a></li>
<li><a href="http://www.arachina.com/html-tag-quick-query.htm">html知识</a></li>
</ul>
</li>

@ -0,0 +1,97 @@
<script language="javascript">
$(function() {
var idList = [];
var index = 0;
$("td[data-id]").each(function(index, element) {
idList[index] = $(element).data("id");
});
$("#startButton").click(function() {
batch_update_cache(idList[index]);
});
batch_get_backup(idList[index]);
function batch_update_cache(infoId) {
var $statusLabel = $("#status" + infoId);
$statusLabel.html("\u7a0d\u7b49...");
console.info("infoId: " + infoId + "; length: " + idList.length + "; index: " + index);
$.get("/info.php/welcome/change_static_url/" + infoId,
function(result) {
console.info(result);
$statusLabel.html(result.message);
index++;
if (index < idList.length) {
batch_update_cache(idList[index]);
}
});
}
function batch_get_backup(infoId) {
var $backupLabel = $("#backup" + infoId);
$backupLabel.html("\u7a0d\u7b49...");
$.get("/info.php/welcome/get_info_backup_id/" + infoId,
function(result) {
console.info(result);
if (result.status == 'success') {
$backupLabel.html(result.username + ', ' + result.datetime + ', ' + result.logId);
$backupLabel.attr('href', '/info.php/information/backup_content/' + result.logId);
} else {
$backupLabel.html('无');
}
index++;
if (index < idList.length) {
batch_get_backup(idList[index]);
}
});
}
});
function update_content(infoId) {
var $statusLabel = $("#status" + infoId);
$statusLabel.html("\u7a0d\u7b49...");
console.info("infoId: " + infoId);
$.get("/info.php/welcome/change_static_url/" + infoId,
function(result) {
console.info(result);
$statusLabel.html(result.message);
});
}
</script>
<div class="row-fluid">
<div class="span1">
</div>
<div class="span10">
<table class="table table-striped">
<thead>
<tr>
<th class="span1">#ID</th>
<th class="span9">URL</th>
<th class="span5">备份</th>
<th class="span2">操作</th>
<th class="span2"><button id="startButton">开始批量</button></th>
</tr>
</thead>
<tbody>
<?php
foreach ($all_information as $key => $info) {
if ($info->ic_status == 1 && !empty($info->ic_url)) {
?>
<tr>
<td data-id='<?php echo $info->is_id; ?>'><?php echo $info->is_id; ?></td>
<td class="cache_url"><?php echo $info->ic_url; ?></td>
<td><a target="_blank" id="backup<?php echo $info->is_id; ?>" href="javascript:;">查看</a></td>
<td>
<a href="javascript:update_content(<?php echo $info->is_id; ?>);">更换</a> |
<a target="_blank" href="/info.php/information/edit/<?php echo $info->is_id; ?>">看看</a>
</td>
<td id="status<?php echo $info->is_id; ?>"><i class="icon-refresh"></i></td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>
</div>

@ -77,6 +77,7 @@
更多<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="<?php echo site_url('apps/pagespeed') ?>">页面性能分析</a></li>
<li><a href="<?php echo site_url('seo') ?>">SEO管理</a></li>
<li> <a href="<?php echo site_url('thirdparty/public/infopayauthor') ?>">打赏统计</a></li>
<li> <a href="<?php echo site_url('thirdparty/form') ?>">表单管理</a></li>

@ -514,15 +514,23 @@ function get_ajax_reviewed_list(formid, container, flag) {
$("#" + container).load(url + " #" + container, data)
};
/* basic end*/
function mobile_friendly(){
var ic_url=$("#ic_url").val();
var siteurl = $("#site_url").val();
var pageurl = siteurl+ic_url;
var url='/info.php/keyworlds/mobile_friendly_test';
$.post(url,{'pageurl':pageurl},function(html){
$("#mobile_friendly_status").html(html);
$('#btn-mobile-friendly').button('reset');
});
function mobile_friendly(refresh){
var ic_url = $("#ic_url").val();
var sitecode = $("#is_sitecode").val();
if(refresh){
var url = '/info.php/apps/pagespeed/index/run';
}else{
var url = '/info.php/apps/pagespeed/index/show_score';
}
$.post(url, {'psd_URL':ic_url, 'psd_SiteCode':sitecode}, function(data){
var json = eval('(' + data + ')');
if (json.result == 'ok'){
$("#mobile_friendly_status").html(json.data);
} else{
$("#mobile_friendly_status").html('获取不到分数');
}
$('#btn-mobile-friendly').button('reset');
});
}
@ -536,5 +544,7 @@ $(document).ready(function() {
$('.ShowMeTheDatePicker').datepicker({
showButtonPanel: true
});
});

File diff suppressed because it is too large Load Diff

@ -10,3 +10,6 @@ require APPPATH.'/libraries/lib/alipay_service.class.php';
class xxx extends CI_Controller{
调用方法
$this->load->library('image_lib');
Loading…
Cancel
Save