添加入库程序
parent
1aca664ff4
commit
9554ad2d67
@ -0,0 +1,55 @@
|
|||||||
|
<?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->load->view('welcome');
|
||||||
|
}
|
||||||
|
|
||||||
|
//自动抓取分数和排名
|
||||||
|
public function auto($sitecode = 'cht') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run($psd_URL, $psd_SiteCode) {
|
||||||
|
$psd_URL = urlencode(trim($psd_URL));
|
||||||
|
if (empty($psd_URL)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$desktop_url = "https://www.googleapis.com/pagespeedonline/v2/runPagespeed?strategy=desktop&locale=zh_CN&url=$psd_URL";
|
||||||
|
$mobile_url = "https://www.googleapis.com/pagespeedonline/v2/runPagespeed?strategy=mobile&locale=zh_CN&url=$psd_URL";
|
||||||
|
|
||||||
|
$desktop_data = GET_HTTP($desktop_url);
|
||||||
|
if (!empty($desktop_data)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$mobile_data = GET_HTTP($mobile_url);
|
||||||
|
if (!empty($mobile_data)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
$PageSpeedData = new StdClass;
|
||||||
|
$PageSpeedData->psd_DesktopScore = '';
|
||||||
|
$PageSpeedData->psd_MobileScore = '';
|
||||||
|
$PageSpeedData->psd_DesktopData = '';
|
||||||
|
$PageSpeedData->psd_MobileData = '';
|
||||||
|
$PageSpeedData->psd_URL = '';
|
||||||
|
$PageSpeedData->psd_Datetime = '';
|
||||||
|
$PageSpeedData->psd_SiteCode = '';
|
||||||
|
$pagespeed_data = $this->PageSpeedData_model->detail($psd_URL, $psd_SiteCode);
|
||||||
|
if (empty($pagespeed_data)) {
|
||||||
|
$psd_id = $this->PageSpeedData_model->add('PageSpeedData', $PageSpeedData);
|
||||||
|
} else {
|
||||||
|
$psd_id = $this->PageSpeedData_model->update('PageSpeedData', $PageSpeedData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
<?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 ps_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 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
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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>
|
Loading…
Reference in New Issue