From e55c7204bed02e4259375c41f6d241939439a425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Fri, 9 Jun 2017 17:53:12 +0800 Subject: [PATCH 01/41] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A1=B5=E9=9D=A2css?= =?UTF-8?q?=E5=92=8Cjs=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/libraries/simple_html_dom_lib.php | 9 + .../htmlcompressor/controllers/index.php | 116 ++ .../htmlcompressor/views/welcome.php | 22 + lib/simple_html_dom.php | 1721 +++++++++++++++++ lib/第三方类库,调用方法请看.txt | 3 + 5 files changed, 1871 insertions(+) create mode 100644 application/libraries/simple_html_dom_lib.php create mode 100644 application/third_party/htmlcompressor/controllers/index.php create mode 100644 application/third_party/htmlcompressor/views/welcome.php create mode 100644 lib/simple_html_dom.php 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 @@ +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) { + $css_content.= GET_HTTP($this->format_url($item, $websitehost)); + } + 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_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; + $link_script->outertext = ''; //删除js,移动到页底 + } + } + + foreach ($link_js_array as $item) { + //$js_content.= GET_HTTP($this->format_url($item, $websitehost)); + } + //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精简错误'; + echo ''; + return FALSE; + } + + //把精简的css添加到head后面 + $html_object = str_replace('', '", $html_object); + +//在最后加载原始css文件和js文件 + $lastload_js = ''; + //把js移动到页面底部 + foreach ($link_js_array as $item) { + $lastload_js.=''; + } + $lastload_js.=$js_content; + + $html_object = str_replace('', $lastload_js . '', $html_object); + } + echo $html_object; + } + +//格式化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 @@ + + + + + + + + HTML-Compressor + + + +

页面样式精简

+
+

+ + +
+ + + diff --git a/lib/simple_html_dom.php b/lib/simple_html_dom.php new file mode 100644 index 00000000..ce412794 --- /dev/null +++ b/lib/simple_html_dom.php @@ -0,0 +1,1721 @@ +size is the "real" number of bytes the dom was created from. + * but for most purposes, it's a really good estimation. + * Paperg - Added the forceTagsClosed to the dom constructor. Forcing tags closed is great for malformed html, but it CAN lead to parsing errors. + * Allow the user to tell us how much they trust the html. + * Paperg add the text and plaintext to the selectors for the find syntax. plaintext implies text in the innertext of a node. text implies that the tag is a text node. + * This allows for us to find tags based on the text they contain. + * Create find_ancestor_tag to see if a tag is - at any level - inside of another specific tag. + * Paperg: added parse_charset so that we know about the character set of the source document. + * NOTE: If the user's system has a routine called get_last_retrieve_url_contents_content_type availalbe, we will assume it's returning the content-type header from the + * last transfer or curl_exec, and we will parse that and use it in preference to any other method of charset detection. + * + * Found infinite loop in the case of broken html in restore_noise. Rewrote to protect from that. + * PaperG (John Schlick) Added get_display_size for "IMG" tags. + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @author S.C. Chen + * @author John Schlick + * @author Rus Carroll + * @version 1.5 ($Rev: 196 $) + * @package PlaceLocalInclude + * @subpackage simple_html_dom + */ + +/** + * All of the Defines for the classes below. + * @author S.C. Chen + */ +define('HDOM_TYPE_ELEMENT', 1); +define('HDOM_TYPE_COMMENT', 2); +define('HDOM_TYPE_TEXT', 3); +define('HDOM_TYPE_ENDTAG', 4); +define('HDOM_TYPE_ROOT', 5); +define('HDOM_TYPE_UNKNOWN', 6); +define('HDOM_QUOTE_DOUBLE', 0); +define('HDOM_QUOTE_SINGLE', 1); +define('HDOM_QUOTE_NO', 3); +define('HDOM_INFO_BEGIN', 0); +define('HDOM_INFO_END', 1); +define('HDOM_INFO_QUOTE', 2); +define('HDOM_INFO_SPACE', 3); +define('HDOM_INFO_TEXT', 4); +define('HDOM_INFO_INNER', 5); +define('HDOM_INFO_OUTER', 6); +define('HDOM_INFO_ENDSPACE',7); +define('DEFAULT_TARGET_CHARSET', 'UTF-8'); +define('DEFAULT_BR_TEXT', "\r\n"); +define('DEFAULT_SPAN_TEXT', " "); +define('MAX_FILE_SIZE', 600000); +// helper functions +// ----------------------------------------------------------------------------- +// get html dom from file +// $maxlen is defined in the code as PHP_STREAM_COPY_ALL which is defined as -1. +function file_get_html($url, $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) +{ + // We DO force the tags to be terminated. + $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText); + // For sourceforge users: uncomment the next line and comment the retreive_url_contents line 2 lines down if it is not already done. + $contents = file_get_contents($url, $use_include_path, $context, $offset); + // Paperg - use our own mechanism for getting the contents as we want to control the timeout. + //$contents = retrieve_url_contents($url); + if (empty($contents) || strlen($contents) > MAX_FILE_SIZE) + { + return false; + } + // The second parameter can force the selectors to all be lowercase. + $dom->load($contents, $lowercase, $stripRN); + return $dom; +} + +// get html dom from string +function str_get_html($str, $lowercase=true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) +{ + $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText); + if (empty($str) || strlen($str) > MAX_FILE_SIZE) + { + $dom->clear(); + return false; + } + $dom->load($str, $lowercase, $stripRN); + return $dom; +} + +// dump html dom tree +function dump_html_tree($node, $show_attr=true, $deep=0) +{ + $node->dump($node); +} + + +/** + * simple html dom node + * PaperG - added ability for "find" routine to lowercase the value of the selector. + * PaperG - added $tag_start to track the start position of the tag in the total byte index + * + * @package PlaceLocalInclude + */ +class simple_html_dom_node +{ + public $nodetype = HDOM_TYPE_TEXT; + public $tag = 'text'; + public $attr = array(); + public $children = array(); + public $nodes = array(); + public $parent = null; + // The "info" array - see HDOM_INFO_... for what each element contains. + public $_ = array(); + public $tag_start = 0; + private $dom = null; + + function __construct($dom) + { + $this->dom = $dom; + $dom->nodes[] = $this; + } + + function __destruct() + { + $this->clear(); + } + + function __toString() + { + return $this->outertext(); + } + + // clean up memory due to php5 circular references memory leak... + function clear() + { + $this->dom = null; + $this->nodes = null; + $this->parent = null; + $this->children = null; + } + + // dump node's tree + function dump($show_attr=true, $deep=0) + { + $lead = str_repeat(' ', $deep); + + echo $lead.$this->tag; + if ($show_attr && count($this->attr)>0) + { + echo '('; + foreach ($this->attr as $k=>$v) + echo "[$k]=>\"".$this->$k.'", '; + echo ')'; + } + echo "\n"; + + if ($this->nodes) + { + foreach ($this->nodes as $c) + { + $c->dump($show_attr, $deep+1); + } + } + } + + + // Debugging function to dump a single dom node with a bunch of information about it. + function dump_node($echo=true) + { + + $string = $this->tag; + if (count($this->attr)>0) + { + $string .= '('; + foreach ($this->attr as $k=>$v) + { + $string .= "[$k]=>\"".$this->$k.'", '; + } + $string .= ')'; + } + if (count($this->_)>0) + { + $string .= ' $_ ('; + foreach ($this->_ as $k=>$v) + { + if (is_array($v)) + { + $string .= "[$k]=>("; + foreach ($v as $k2=>$v2) + { + $string .= "[$k2]=>\"".$v2.'", '; + } + $string .= ")"; + } else { + $string .= "[$k]=>\"".$v.'", '; + } + } + $string .= ")"; + } + + if (isset($this->text)) + { + $string .= " text: (" . $this->text . ")"; + } + + $string .= " HDOM_INNER_INFO: '"; + if (isset($node->_[HDOM_INFO_INNER])) + { + $string .= $node->_[HDOM_INFO_INNER] . "'"; + } + else + { + $string .= ' NULL '; + } + + $string .= " children: " . count($this->children); + $string .= " nodes: " . count($this->nodes); + $string .= " tag_start: " . $this->tag_start; + $string .= "\n"; + + if ($echo) + { + echo $string; + return; + } + else + { + return $string; + } + } + + // returns the parent of node + // If a node is passed in, it will reset the parent of the current node to that one. + function parent($parent=null) + { + // I am SURE that this doesn't work properly. + // It fails to unset the current node from it's current parents nodes or children list first. + if ($parent !== null) + { + $this->parent = $parent; + $this->parent->nodes[] = $this; + $this->parent->children[] = $this; + } + + return $this->parent; + } + + // verify that node has children + function has_child() + { + return !empty($this->children); + } + + // returns children of node + function children($idx=-1) + { + if ($idx===-1) + { + return $this->children; + } + if (isset($this->children[$idx])) return $this->children[$idx]; + return null; + } + + // returns the first child of node + function first_child() + { + if (count($this->children)>0) + { + return $this->children[0]; + } + return null; + } + + // returns the last child of node + function last_child() + { + if (($count=count($this->children))>0) + { + return $this->children[$count-1]; + } + return null; + } + + // returns the next sibling of node + function next_sibling() + { + if ($this->parent===null) + { + return null; + } + + $idx = 0; + $count = count($this->parent->children); + while ($idx<$count && $this!==$this->parent->children[$idx]) + { + ++$idx; + } + if (++$idx>=$count) + { + return null; + } + return $this->parent->children[$idx]; + } + + // returns the previous sibling of node + function prev_sibling() + { + if ($this->parent===null) return null; + $idx = 0; + $count = count($this->parent->children); + while ($idx<$count && $this!==$this->parent->children[$idx]) + ++$idx; + if (--$idx<0) return null; + return $this->parent->children[$idx]; + } + + // function to locate a specific ancestor tag in the path to the root. + function find_ancestor_tag($tag) + { + global $debugObject; + if (is_object($debugObject)) { $debugObject->debugLogEntry(1); } + + // Start by including ourselves in the comparison. + $returnDom = $this; + + while (!is_null($returnDom)) + { + if (is_object($debugObject)) { $debugObject->debugLog(2, "Current tag is: " . $returnDom->tag); } + + if ($returnDom->tag == $tag) + { + break; + } + $returnDom = $returnDom->parent; + } + return $returnDom; + } + + // get dom node's inner html + function innertext() + { + if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER]; + if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); + + $ret = ''; + foreach ($this->nodes as $n) + $ret .= $n->outertext(); + return $ret; + } + + // get dom node's outer text (with tag) + function outertext() + { + global $debugObject; + if (is_object($debugObject)) + { + $text = ''; + if ($this->tag == 'text') + { + if (!empty($this->text)) + { + $text = " with text: " . $this->text; + } + } + $debugObject->debugLog(1, 'Innertext of tag: ' . $this->tag . $text); + } + + if ($this->tag==='root') return $this->innertext(); + + // trigger callback + if ($this->dom && $this->dom->callback!==null) + { + call_user_func_array($this->dom->callback, array($this)); + } + + if (isset($this->_[HDOM_INFO_OUTER])) return $this->_[HDOM_INFO_OUTER]; + if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); + + // render begin tag + if ($this->dom && $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]) + { + $ret = $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]->makeup(); + } else { + $ret = ""; + } + + // render inner text + if (isset($this->_[HDOM_INFO_INNER])) + { + // If it's a br tag... don't return the HDOM_INNER_INFO that we may or may not have added. + if ($this->tag != "br") + { + $ret .= $this->_[HDOM_INFO_INNER]; + } + } else { + if ($this->nodes) + { + foreach ($this->nodes as $n) + { + $ret .= $this->convert_text($n->outertext()); + } + } + } + + // render end tag + if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END]!=0) + $ret .= 'tag.'>'; + return $ret; + } + + // get dom node's plain text + function text() + { + if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER]; + switch ($this->nodetype) + { + case HDOM_TYPE_TEXT: return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); + case HDOM_TYPE_COMMENT: return ''; + case HDOM_TYPE_UNKNOWN: return ''; + } + if (strcasecmp($this->tag, 'script')===0) return ''; + if (strcasecmp($this->tag, 'style')===0) return ''; + + $ret = ''; + // In rare cases, (always node type 1 or HDOM_TYPE_ELEMENT - observed for some span tags, and some p tags) $this->nodes is set to NULL. + // NOTE: This indicates that there is a problem where it's set to NULL without a clear happening. + // WHY is this happening? + if (!is_null($this->nodes)) + { + foreach ($this->nodes as $n) + { + $ret .= $this->convert_text($n->text()); + } + + // If this node is a span... add a space at the end of it so multiple spans don't run into each other. This is plaintext after all. + if ($this->tag == "span") + { + $ret .= $this->dom->default_span_text; + } + + + } + return $ret; + } + + function xmltext() + { + $ret = $this->innertext(); + $ret = str_ireplace('', '', $ret); + return $ret; + } + + // build node's text with tag + function makeup() + { + // text, comment, unknown + if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); + + $ret = '<'.$this->tag; + $i = -1; + + foreach ($this->attr as $key=>$val) + { + ++$i; + + // skip removed attribute + if ($val===null || $val===false) + continue; + + $ret .= $this->_[HDOM_INFO_SPACE][$i][0]; + //no value attr: nowrap, checked selected... + if ($val===true) + $ret .= $key; + else { + switch ($this->_[HDOM_INFO_QUOTE][$i]) + { + case HDOM_QUOTE_DOUBLE: $quote = '"'; break; + case HDOM_QUOTE_SINGLE: $quote = '\''; break; + default: $quote = ''; + } + $ret .= $key.$this->_[HDOM_INFO_SPACE][$i][1].'='.$this->_[HDOM_INFO_SPACE][$i][2].$quote.$val.$quote; + } + } + $ret = $this->dom->restore_noise($ret); + return $ret . $this->_[HDOM_INFO_ENDSPACE] . '>'; + } + + // find elements by css selector + //PaperG - added ability for find to lowercase the value of the selector. + function find($selector, $idx=null, $lowercase=false) + { + $selectors = $this->parse_selector($selector); + if (($count=count($selectors))===0) return array(); + $found_keys = array(); + + // find each selector + for ($c=0; $c<$count; ++$c) + { + // The change on the below line was documented on the sourceforge code tracker id 2788009 + // used to be: if (($levle=count($selectors[0]))===0) return array(); + if (($levle=count($selectors[$c]))===0) return array(); + if (!isset($this->_[HDOM_INFO_BEGIN])) return array(); + + $head = array($this->_[HDOM_INFO_BEGIN]=>1); + + // handle descendant selectors, no recursive! + for ($l=0; $l<$levle; ++$l) + { + $ret = array(); + foreach ($head as $k=>$v) + { + $n = ($k===-1) ? $this->dom->root : $this->dom->nodes[$k]; + //PaperG - Pass this optional parameter on to the seek function. + $n->seek($selectors[$c][$l], $ret, $lowercase); + } + $head = $ret; + } + + foreach ($head as $k=>$v) + { + if (!isset($found_keys[$k])) + $found_keys[$k] = 1; + } + } + + // sort keys + ksort($found_keys); + + $found = array(); + foreach ($found_keys as $k=>$v) + $found[] = $this->dom->nodes[$k]; + + // return nth-element or array + if (is_null($idx)) return $found; + else if ($idx<0) $idx = count($found) + $idx; + return (isset($found[$idx])) ? $found[$idx] : null; + } + + // seek for given conditions + // PaperG - added parameter to allow for case insensitive testing of the value of a selector. + protected function seek($selector, &$ret, $lowercase=false) + { + global $debugObject; + if (is_object($debugObject)) { $debugObject->debugLogEntry(1); } + + list($tag, $key, $val, $exp, $no_key) = $selector; + + // xpath index + if ($tag && $key && is_numeric($key)) + { + $count = 0; + foreach ($this->children as $c) + { + if ($tag==='*' || $tag===$c->tag) { + if (++$count==$key) { + $ret[$c->_[HDOM_INFO_BEGIN]] = 1; + return; + } + } + } + return; + } + + $end = (!empty($this->_[HDOM_INFO_END])) ? $this->_[HDOM_INFO_END] : 0; + if ($end==0) { + $parent = $this->parent; + while (!isset($parent->_[HDOM_INFO_END]) && $parent!==null) { + $end -= 1; + $parent = $parent->parent; + } + $end += $parent->_[HDOM_INFO_END]; + } + + for ($i=$this->_[HDOM_INFO_BEGIN]+1; $i<$end; ++$i) { + $node = $this->dom->nodes[$i]; + + $pass = true; + + if ($tag==='*' && !$key) { + if (in_array($node, $this->children, true)) + $ret[$i] = 1; + continue; + } + + // compare tag + if ($tag && $tag!=$node->tag && $tag!=='*') {$pass=false;} + // compare key + if ($pass && $key) { + if ($no_key) { + if (isset($node->attr[$key])) $pass=false; + } else { + if (($key != "plaintext") && !isset($node->attr[$key])) $pass=false; + } + } + // compare value + if ($pass && $key && $val && $val!=='*') { + // If they have told us that this is a "plaintext" search then we want the plaintext of the node - right? + if ($key == "plaintext") { + // $node->plaintext actually returns $node->text(); + $nodeKeyValue = $node->text(); + } else { + // this is a normal search, we want the value of that attribute of the tag. + $nodeKeyValue = $node->attr[$key]; + } + if (is_object($debugObject)) {$debugObject->debugLog(2, "testing node: " . $node->tag . " for attribute: " . $key . $exp . $val . " where nodes value is: " . $nodeKeyValue);} + + //PaperG - If lowercase is set, do a case insensitive test of the value of the selector. + if ($lowercase) { + $check = $this->match($exp, strtolower($val), strtolower($nodeKeyValue)); + } else { + $check = $this->match($exp, $val, $nodeKeyValue); + } + if (is_object($debugObject)) {$debugObject->debugLog(2, "after match: " . ($check ? "true" : "false"));} + + // handle multiple class + if (!$check && strcasecmp($key, 'class')===0) { + foreach (explode(' ',$node->attr[$key]) as $k) { + // Without this, there were cases where leading, trailing, or double spaces lead to our comparing blanks - bad form. + if (!empty($k)) { + if ($lowercase) { + $check = $this->match($exp, strtolower($val), strtolower($k)); + } else { + $check = $this->match($exp, $val, $k); + } + if ($check) break; + } + } + } + if (!$check) $pass = false; + } + if ($pass) $ret[$i] = 1; + unset($node); + } + // It's passed by reference so this is actually what this function returns. + if (is_object($debugObject)) {$debugObject->debugLog(1, "EXIT - ret: ", $ret);} + } + + protected function match($exp, $pattern, $value) { + global $debugObject; + if (is_object($debugObject)) {$debugObject->debugLogEntry(1);} + + switch ($exp) { + case '=': + return ($value===$pattern); + case '!=': + return ($value!==$pattern); + case '^=': + return preg_match("/^".preg_quote($pattern,'/')."/", $value); + case '$=': + return preg_match("/".preg_quote($pattern,'/')."$/", $value); + case '*=': + if ($pattern[0]=='/') { + return preg_match($pattern, $value); + } + return preg_match("/".$pattern."/i", $value); + } + return false; + } + + protected function parse_selector($selector_string) { + global $debugObject; + if (is_object($debugObject)) {$debugObject->debugLogEntry(1);} + + // pattern of CSS selectors, modified from mootools + // Paperg: Add the colon to the attrbute, so that it properly finds like google does. + // Note: if you try to look at this attribute, yo MUST use getAttribute since $dom->x:y will fail the php syntax check. +// Notice the \[ starting the attbute? and the @? following? This implies that an attribute can begin with an @ sign that is not captured. +// This implies that an html attribute specifier may start with an @ sign that is NOT captured by the expression. +// farther study is required to determine of this should be documented or removed. +// $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is"; + $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-:]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is"; + preg_match_all($pattern, trim($selector_string).' ', $matches, PREG_SET_ORDER); + if (is_object($debugObject)) {$debugObject->debugLog(2, "Matches Array: ", $matches);} + + $selectors = array(); + $result = array(); + //print_r($matches); + + foreach ($matches as $m) { + $m[0] = trim($m[0]); + if ($m[0]==='' || $m[0]==='/' || $m[0]==='//') continue; + // for browser generated xpath + if ($m[1]==='tbody') continue; + + list($tag, $key, $val, $exp, $no_key) = array($m[1], null, null, '=', false); + if (!empty($m[2])) {$key='id'; $val=$m[2];} + if (!empty($m[3])) {$key='class'; $val=$m[3];} + if (!empty($m[4])) {$key=$m[4];} + if (!empty($m[5])) {$exp=$m[5];} + if (!empty($m[6])) {$val=$m[6];} + + // convert to lowercase + if ($this->dom->lowercase) {$tag=strtolower($tag); $key=strtolower($key);} + //elements that do NOT have the specified attribute + if (isset($key[0]) && $key[0]==='!') {$key=substr($key, 1); $no_key=true;} + + $result[] = array($tag, $key, $val, $exp, $no_key); + if (trim($m[7])===',') { + $selectors[] = $result; + $result = array(); + } + } + if (count($result)>0) + $selectors[] = $result; + return $selectors; + } + + function __get($name) { + if (isset($this->attr[$name])) + { + return $this->convert_text($this->attr[$name]); + } + switch ($name) { + case 'outertext': return $this->outertext(); + case 'innertext': return $this->innertext(); + case 'plaintext': return $this->text(); + case 'xmltext': return $this->xmltext(); + default: return array_key_exists($name, $this->attr); + } + } + + function __set($name, $value) { + switch ($name) { + case 'outertext': return $this->_[HDOM_INFO_OUTER] = $value; + case 'innertext': + if (isset($this->_[HDOM_INFO_TEXT])) return $this->_[HDOM_INFO_TEXT] = $value; + return $this->_[HDOM_INFO_INNER] = $value; + } + if (!isset($this->attr[$name])) { + $this->_[HDOM_INFO_SPACE][] = array(' ', '', ''); + $this->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE; + } + $this->attr[$name] = $value; + } + + function __isset($name) { + switch ($name) { + case 'outertext': return true; + case 'innertext': return true; + case 'plaintext': return true; + } + //no value attr: nowrap, checked selected... + return (array_key_exists($name, $this->attr)) ? true : isset($this->attr[$name]); + } + + function __unset($name) { + if (isset($this->attr[$name])) + unset($this->attr[$name]); + } + + // PaperG - Function to convert the text from one character set to another if the two sets are not the same. + function convert_text($text) + { + global $debugObject; + if (is_object($debugObject)) {$debugObject->debugLogEntry(1);} + + $converted_text = $text; + + $sourceCharset = ""; + $targetCharset = ""; + + if ($this->dom) + { + $sourceCharset = strtoupper($this->dom->_charset); + $targetCharset = strtoupper($this->dom->_target_charset); + } + if (is_object($debugObject)) {$debugObject->debugLog(3, "source charset: " . $sourceCharset . " target charaset: " . $targetCharset);} + + if (!empty($sourceCharset) && !empty($targetCharset) && (strcasecmp($sourceCharset, $targetCharset) != 0)) + { + // Check if the reported encoding could have been incorrect and the text is actually already UTF-8 + if ((strcasecmp($targetCharset, 'UTF-8') == 0) && ($this->is_utf8($text))) + { + $converted_text = $text; + } + else + { + $converted_text = iconv($sourceCharset, $targetCharset, $text); + } + } + + // Lets make sure that we don't have that silly BOM issue with any of the utf-8 text we output. + if ($targetCharset == 'UTF-8') + { + if (substr($converted_text, 0, 3) == "\xef\xbb\xbf") + { + $converted_text = substr($converted_text, 3); + } + if (substr($converted_text, -3) == "\xef\xbb\xbf") + { + $converted_text = substr($converted_text, 0, -3); + } + } + + return $converted_text; + } + + /** + * Returns true if $string is valid UTF-8 and false otherwise. + * + * @param mixed $str String to be tested + * @return boolean + */ + static function is_utf8($str) + { + $c=0; $b=0; + $bits=0; + $len=strlen($str); + for($i=0; $i<$len; $i++) + { + $c=ord($str[$i]); + if($c > 128) + { + if(($c >= 254)) return false; + elseif($c >= 252) $bits=6; + elseif($c >= 248) $bits=5; + elseif($c >= 240) $bits=4; + elseif($c >= 224) $bits=3; + elseif($c >= 192) $bits=2; + else return false; + if(($i+$bits) > $len) return false; + while($bits > 1) + { + $i++; + $b=ord($str[$i]); + if($b < 128 || $b > 191) return false; + $bits--; + } + } + } + return true; + } + /* + function is_utf8($string) + { + //this is buggy + return (utf8_encode(utf8_decode($string)) == $string); + } + */ + + /** + * Function to try a few tricks to determine the displayed size of an img on the page. + * NOTE: This will ONLY work on an IMG tag. Returns FALSE on all other tag types. + * + * @author John Schlick + * @version April 19 2012 + * @return array an array containing the 'height' and 'width' of the image on the page or -1 if we can't figure it out. + */ + function get_display_size() + { + global $debugObject; + + $width = -1; + $height = -1; + + if ($this->tag !== 'img') + { + return false; + } + + // See if there is aheight or width attribute in the tag itself. + if (isset($this->attr['width'])) + { + $width = $this->attr['width']; + } + + if (isset($this->attr['height'])) + { + $height = $this->attr['height']; + } + + // Now look for an inline style. + if (isset($this->attr['style'])) + { + // Thanks to user gnarf from stackoverflow for this regular expression. + $attributes = array(); + preg_match_all("/([\w-]+)\s*:\s*([^;]+)\s*;?/", $this->attr['style'], $matches, PREG_SET_ORDER); + foreach ($matches as $match) { + $attributes[$match[1]] = $match[2]; + } + + // If there is a width in the style attributes: + if (isset($attributes['width']) && $width == -1) + { + // check that the last two characters are px (pixels) + if (strtolower(substr($attributes['width'], -2)) == 'px') + { + $proposed_width = substr($attributes['width'], 0, -2); + // Now make sure that it's an integer and not something stupid. + if (filter_var($proposed_width, FILTER_VALIDATE_INT)) + { + $width = $proposed_width; + } + } + } + + // If there is a width in the style attributes: + if (isset($attributes['height']) && $height == -1) + { + // check that the last two characters are px (pixels) + if (strtolower(substr($attributes['height'], -2)) == 'px') + { + $proposed_height = substr($attributes['height'], 0, -2); + // Now make sure that it's an integer and not something stupid. + if (filter_var($proposed_height, FILTER_VALIDATE_INT)) + { + $height = $proposed_height; + } + } + } + + } + + // Future enhancement: + // Look in the tag to see if there is a class or id specified that has a height or width attribute to it. + + // Far future enhancement + // Look at all the parent tags of this image to see if they specify a class or id that has an img selector that specifies a height or width + // Note that in this case, the class or id will have the img subselector for it to apply to the image. + + // ridiculously far future development + // If the class or id is specified in a SEPARATE css file thats not on the page, go get it and do what we were just doing for the ones on the page. + + $result = array('height' => $height, + 'width' => $width); + return $result; + } + + // camel naming conventions + function getAllAttributes() {return $this->attr;} + function getAttribute($name) {return $this->__get($name);} + function setAttribute($name, $value) {$this->__set($name, $value);} + function hasAttribute($name) {return $this->__isset($name);} + function removeAttribute($name) {$this->__set($name, null);} + function getElementById($id) {return $this->find("#$id", 0);} + function getElementsById($id, $idx=null) {return $this->find("#$id", $idx);} + function getElementByTagName($name) {return $this->find($name, 0);} + function getElementsByTagName($name, $idx=null) {return $this->find($name, $idx);} + function parentNode() {return $this->parent();} + function childNodes($idx=-1) {return $this->children($idx);} + function firstChild() {return $this->first_child();} + function lastChild() {return $this->last_child();} + function nextSibling() {return $this->next_sibling();} + function previousSibling() {return $this->prev_sibling();} + function hasChildNodes() {return $this->has_child();} + function nodeName() {return $this->tag;} + function appendChild($node) {$node->parent($this); return $node;} + +} + +/** + * simple html dom parser + * Paperg - in the find routine: allow us to specify that we want case insensitive testing of the value of the selector. + * Paperg - change $size from protected to public so we can easily access it + * Paperg - added ForceTagsClosed in the constructor which tells us whether we trust the html or not. Default is to NOT trust it. + * + * @package PlaceLocalInclude + */ +class simple_html_dom +{ + public $root = null; + public $nodes = array(); + public $callback = null; + public $lowercase = false; + // Used to keep track of how large the text was when we started. + public $original_size; + public $size; + protected $pos; + protected $doc; + protected $char; + protected $cursor; + protected $parent; + protected $noise = array(); + protected $token_blank = " \t\r\n"; + protected $token_equal = ' =/>'; + protected $token_slash = " />\r\n\t"; + protected $token_attr = ' >'; + // Note that this is referenced by a child node, and so it needs to be public for that node to see this information. + public $_charset = ''; + public $_target_charset = ''; + protected $default_br_text = ""; + public $default_span_text = ""; + + // use isset instead of in_array, performance boost about 30%... + protected $self_closing_tags = array('img'=>1, 'br'=>1, 'input'=>1, 'meta'=>1, 'link'=>1, 'hr'=>1, 'base'=>1, 'embed'=>1, 'spacer'=>1); + protected $block_tags = array('root'=>1, 'body'=>1, 'form'=>1, 'div'=>1, 'span'=>1, 'table'=>1); + // Known sourceforge issue #2977341 + // B tags that are not closed cause us to return everything to the end of the document. + protected $optional_closing_tags = array( + 'tr'=>array('tr'=>1, 'td'=>1, 'th'=>1), + 'th'=>array('th'=>1), + 'td'=>array('td'=>1), + 'li'=>array('li'=>1), + 'dt'=>array('dt'=>1, 'dd'=>1), + 'dd'=>array('dd'=>1, 'dt'=>1), + 'dl'=>array('dd'=>1, 'dt'=>1), + 'p'=>array('p'=>1), + 'nobr'=>array('nobr'=>1), + 'b'=>array('b'=>1), + 'option'=>array('option'=>1), + ); + + function __construct($str=null, $lowercase=true, $forceTagsClosed=true, $target_charset=DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) + { + if ($str) + { + if (preg_match("/^http:\/\//i",$str) || is_file($str)) + { + $this->load_file($str); + } + else + { + $this->load($str, $lowercase, $stripRN, $defaultBRText, $defaultSpanText); + } + } + // Forcing tags to be closed implies that we don't trust the html, but it can lead to parsing errors if we SHOULD trust the html. + if (!$forceTagsClosed) { + $this->optional_closing_array=array(); + } + $this->_target_charset = $target_charset; + } + + function __destruct() + { + $this->clear(); + } + + // load html from string + function load($str, $lowercase=true, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) + { + global $debugObject; + + // prepare + $this->prepare($str, $lowercase, $stripRN, $defaultBRText, $defaultSpanText); + // strip out comments + $this->remove_noise("''is"); + // strip out cdata + $this->remove_noise("''is", true); + // Per sourceforge http://sourceforge.net/tracker/?func=detail&aid=2949097&group_id=218559&atid=1044037 + // Script tags removal now preceeds style tag removal. + // strip out '; + $lastload_js.='},1000);'; //把js移动到页面底部 foreach ($link_js_array as $item) { $lastload_js.=''; From 1aca664ff4cf23b40b4557cfce99753fffd833d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Mon, 12 Jun 2017 13:29:42 +0800 Subject: [PATCH 03/41] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=9D=99=E6=80=81?= =?UTF-8?q?=E5=8C=96=E4=BC=98=E5=8C=96=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/information.php | 7 ++++++- application/views/bootstrap3/information_edit.php | 11 ++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/application/controllers/information.php b/application/controllers/information.php index 52f1e0ca..3309bc53 100644 --- a/application/controllers/information.php +++ b/application/controllers/information.php @@ -526,7 +526,12 @@ 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 = $this->input->get_post('static_html_optimize'); + if (!empty($static_html_optimize)) { + $url = 'https://www.asiahighlights.com/index.php/information/detail/?static_html_url=' . $url . '&static_html_optimize=comeon'; + } else { + $url = 'https://www.asiahighlights.com/index.php/information/detail/?static_html_url=' . $url; + } } } else { //子站点使用 $url = $this->config->item('site_url') . $url . '@cache@refresh'; diff --git a/application/views/bootstrap3/information_edit.php b/application/views/bootstrap3/information_edit.php index 21155868..0edd64da 100644 --- a/application/views/bootstrap3/information_edit.php +++ b/application/views/bootstrap3/information_edit.php @@ -1,4 +1,4 @@ - + + +

页面样式精简

+
+

+ + +
+ + + From 93a4d84abd1dea35143c793b17e24def1158e803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Thu, 15 Jun 2017 10:12:18 +0800 Subject: [PATCH 05/41] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=88=B0=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pagespeed/controllers/index.php | 59 +++-- .../pagespeed/models/PageSpeedData_model.php | 11 +- author/views/signup.php | 215 ------------------ 3 files changed, 47 insertions(+), 238 deletions(-) delete mode 100644 author/views/signup.php diff --git a/application/third_party/pagespeed/controllers/index.php b/application/third_party/pagespeed/controllers/index.php index 6a2b3c8a..9e1fef6f 100644 --- a/application/third_party/pagespeed/controllers/index.php +++ b/application/third_party/pagespeed/controllers/index.php @@ -16,40 +16,59 @@ class Index extends CI_Controller { //自动抓取分数和排名 public function auto($sitecode = 'cht') { - + $this->run('/', 'cht'); } public function run($psd_URL, $psd_SiteCode) { - $psd_URL = urlencode(trim($psd_URL)); - if (empty($psd_URL)) { + if (empty($psd_URL) || empty($psd_SiteCode)) { + return false; + } + $sites = $this->config->item('site'); + if (empty($sites[$psd_SiteCode])) { 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"; + $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); - if (!empty($desktop_data)) { - + $mobile_data = GET_HTTP($mobile_url); + if (empty($desktop_data) || empty($mobile_data)) { + return false; + } + $desktop_object = json_decode($desktop_data); + $mobile_object = json_decode($mobile_data); + if (!empty($desktop_object->error) || !empty($mobile_object->error)) { + return false; } - $mobile_data = GET_HTTP($mobile_url); - if (!empty($mobile_data)) { - + if (!$desktop_object->responseCode == '200' || !$mobile_object->responseCode == '200') { + echo 'ERROR:' . $desktop_object->responseCode . ' ' . $mobile_object->responseCode; + return FALSE; } - $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); + + $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 { - $psd_id = $this->PageSpeedData_model->update('PageSpeedData', $PageSpeedData); + $where = array('psd_id' => $pagespeed_data->psd_id); + $this->PageSpeedData_model->update('PageSpeedData', $PageSpeedData, $where); } + echo $run_URL . '
'; } } diff --git a/application/third_party/pagespeed/models/PageSpeedData_model.php b/application/third_party/pagespeed/models/PageSpeedData_model.php index cf5e98fc..d31f9449 100644 --- a/application/third_party/pagespeed/models/PageSpeedData_model.php +++ b/application/third_party/pagespeed/models/PageSpeedData_model.php @@ -15,11 +15,11 @@ class PageSpeedData_model extends CI_Model { public function init() { $this->topnum = false; $this->where = false; - $this->orderby = ' ORDER BY ps_Datetime ASC '; + $this->orderby = ' ORDER BY psd_Datetime ASC '; } public function detail($psd_URL, $psd_SiteCode) { - $this->init; + $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); @@ -34,6 +34,10 @@ class PageSpeedData_model extends CI_Model { } } + public function update($table, $data, $where) { + $this->INFO->update($table, $data, $where); + } + public function get_list() { $this->topnum ? $sql = "SELECT TOP " . $this->topnum : $sql = "SELECT "; $sql .= " @@ -44,7 +48,8 @@ class PageSpeedData_model extends CI_Model { psd.psd_MobileData, psd.psd_URL, psd.psd_Datetime, - psd.psd_SiteCode + psd.psd_SiteCode, + psd.psd_ErrorCount FROM PageSpeedData psd WHERE 1 = 1 diff --git a/author/views/signup.php b/author/views/signup.php deleted file mode 100644 index 1047d9eb..00000000 --- a/author/views/signup.php +++ /dev/null @@ -1,215 +0,0 @@ - - - -
-
- - - -
- - Sign Up For China Highlights Online Writers Platform -
-
- -
- - -
-
- - \ No newline at end of file From a204e58964ee17b1cfadaca978e94e80655d1a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Thu, 15 Jun 2017 10:16:49 +0800 Subject: [PATCH 06/41] =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=BA=E8=87=AA=E9=80=82=E5=BA=94=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/config/config.php | 30 +++++++++++------------ application/models/infoContents_model.php | 1 + 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index 2c71f629..063c4fb6 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -363,25 +363,25 @@ $config['proxy_ips'] = ''; //各站信息组和人员权限分配 $config['site'] = array( - 'cht' => array('site_code' => 'cht', 'site_id' => 14, 'site_lgc' => '1', 'site_url' => 'http://www.chinahighlights.com', 'site_image_url' => 'http://images.chinahighlights.com', 'site_authors' => array('zzy', 'spt', 'yl', 'gavin', 'sw', 'zl', 'wbl', 'yqw', 'lf', 'zhm', 'pkl'), 'site_user' => ',ycc,lmr, zyh,J,shw,B,zzy,WJJ,Tony,pcf,zxy,wst,wz,v,S,yyg,yxd,wj,sw,yl,hx,spt,wmr,zl,syt,gavin,zm,htc,yqw,bhn,lmj,wbl,yqw,LYY,zhm,'), - 'gm' => array('site_code' => 'gm', 'site_id' => 22, 'site_lgc' => '4', 'site_url' => 'http://www.chinarundreisen.com', 'site_image_url' => 'http://bilder.chinarundreisen.com', 'site_authors' => array('DX', 'X', 'K', 'Lan', 'lmr', 'zyh', 'ZYHL', 'TDJ'), 'site_user' => ',ycc,lmr,B,zyh,DX,X,K,htc,zm,bhn,Lan,Tony,zyh,J,v,ZYHL,TDJ,LYY,shw,'), - 'vc' => array('site_code' => 'vc', 'site_id' => 30, 'site_lgc' => '5', 'site_url' => 'http://www.voyageschine.com', 'site_image_url' => 'http://images.voyageschine.com', 'site_authors' => array('JE', 'kq', 'lya', 'lyz', 'zyh'), 'site_user' => ',ycc,lmr, zyh,JE,htc,kq,lya,bhn,Tony,zyh,B,J,lyz,LYY,'), - 'jp' => array('site_code' => 'jp', 'site_id' => 88, 'site_lgc' => '3', 'site_url' => 'http://www.arachina.com', 'site_image_url' => 'http://images.arachina.com', 'site_authors' => array('hql', 'LLM', 'SHX', 'lmr', 'zyh', 'zb'), 'site_user' => ',ycc,lmr, zyh,hql,LLM,SHX,htc,zpl,Tony,zyh,J,B,zb,LYY,'), - 'vac' => array('site_code' => 'vac', 'site_id' => 95, 'site_lgc' => '6', 'site_url' => 'http://www.viaje-a-china.com', 'site_image_url' => 'http://imagenes.viaje-a-china.com', 'site_authors' => array('I', 'cyt', 'lmr', 'zyh', 'LLM'), 'site_user' => ',ycc,lmr, zyh,I,cyt,htc,bhn,Tony,zyh,B,J,LLM,LYY,'), - 'it' => array('site_code' => 'it', 'site_id' => 168, 'site_lgc' => '8', 'site_url' => 'http://www.viaggio-in-cina.it', 'site_image_url' => 'http://images.viaggio-in-cina.it', 'site_authors' => array('LZY', 'ZQQ', 'lmr', 'zyh'), 'site_user' => ',ycc,lmr, zyh,LZY,htc,ZQQ,Tony,zyh,B,J,LYY,'), - 'ru' => array('site_code' => 'ru', 'site_id' => 102, 'site_lgc' => '7', 'site_url' => 'http://www.chinahighlights.ru', 'site_image_url' => 'http://images.chinahighlights.ru', 'site_authors' => array('xjj', 'zyy'), 'site_user' => ',ycc,lmr, zyh,xjj,htc,DX,zyy,bhn,Tony,zyh,B,J,LYY,'), + 'cht' => array('site_code' => 'cht', 'site_id' => 14, 'site_lgc' => '1', 'site_url' => 'http://www.chinahighlights.com', 'site_image_url' => '//images.chinahighlights.com', 'site_authors' => array('zzy', 'spt', 'yl', 'gavin', 'sw', 'zl', 'wbl', 'yqw', 'lf', 'zhm', 'pkl'), 'site_user' => ',ycc,lmr, zyh,J,shw,B,zzy,WJJ,Tony,pcf,zxy,wst,wz,v,S,yyg,yxd,wj,sw,yl,hx,spt,wmr,zl,syt,gavin,zm,htc,yqw,bhn,lmj,wbl,yqw,LYY,zhm,'), + 'gm' => array('site_code' => 'gm', 'site_id' => 22, 'site_lgc' => '4', 'site_url' => 'http://www.chinarundreisen.com', 'site_image_url' => '//bilder.chinarundreisen.com', 'site_authors' => array('DX', 'X', 'K', 'Lan', 'lmr', 'zyh', 'ZYHL', 'TDJ'), 'site_user' => ',ycc,lmr,B,zyh,DX,X,K,htc,zm,bhn,Lan,Tony,zyh,J,v,ZYHL,TDJ,LYY,shw,'), + 'vc' => array('site_code' => 'vc', 'site_id' => 30, 'site_lgc' => '5', 'site_url' => 'http://www.voyageschine.com', 'site_image_url' => '//images.voyageschine.com', 'site_authors' => array('JE', 'kq', 'lya', 'lyz', 'zyh'), 'site_user' => ',ycc,lmr, zyh,JE,htc,kq,lya,bhn,Tony,zyh,B,J,lyz,LYY,'), + 'jp' => array('site_code' => 'jp', 'site_id' => 88, 'site_lgc' => '3', 'site_url' => 'http://www.arachina.com', 'site_image_url' => '//images.arachina.com', 'site_authors' => array('hql', 'LLM', 'SHX', 'lmr', 'zyh', 'zb'), 'site_user' => ',ycc,lmr, zyh,hql,LLM,SHX,htc,zpl,Tony,zyh,J,B,zb,LYY,'), + 'vac' => array('site_code' => 'vac', 'site_id' => 95, 'site_lgc' => '6', 'site_url' => 'http://www.viaje-a-china.com', 'site_image_url' => '//imagenes.viaje-a-china.com', 'site_authors' => array('I', 'cyt', 'lmr', 'zyh', 'LLM'), 'site_user' => ',ycc,lmr, zyh,I,cyt,htc,bhn,Tony,zyh,B,J,LLM,LYY,'), + 'it' => array('site_code' => 'it', 'site_id' => 168, 'site_lgc' => '8', 'site_url' => 'http://www.viaggio-in-cina.it', 'site_image_url' => '//images.viaggio-in-cina.it', 'site_authors' => array('LZY', 'ZQQ', 'lmr', 'zyh'), 'site_user' => ',ycc,lmr, zyh,LZY,htc,ZQQ,Tony,zyh,B,J,LYY,'), + 'ru' => array('site_code' => 'ru', 'site_id' => 102, 'site_lgc' => '7', 'site_url' => 'http://www.chinahighlights.ru', 'site_image_url' => '//images.chinahighlights.ru', 'site_authors' => array('xjj', 'zyy'), 'site_user' => ',ycc,lmr, zyh,xjj,htc,DX,zyy,bhn,Tony,zyh,B,J,LYY,'), 'wt' => array('site_code' => 'wt', 'site_id' => 172, 'site_lgc' => '2', 'site_url' => 'http://www.iiiyooo.com', 'site_image_url' => '', 'site_authors' => array('ylh', 'lfj', 'wx', 'lzh', 'shw', 'lx'), 'site_user' => ',ycc,lmr, zyh,ylh,lfj,wx,lzh,shw,lx,bhn,B,J,'), 'tbt' => array('site_code' => 'tbt', 'site_id' => 169, 'site_lgc' => '1', 'site_url' => 'http://www.tibettravel.info', 'site_image_url' => '/images', 'site_authors' => array('wj', 'sfx'), 'site_user' => ',ycc,wj,bhn,wx,lzh,lfj,hwt,thf,sfx,J,ZP,'), - 'sht' => array('site_code' => 'sht', 'site_id' => 96, 'site_lgc' => '1', 'site_url' => 'http://www.shanghaihighlights.com', 'site_image_url' => 'http://images.shanghaihighlights.com', 'site_authors' => array('vz', 'sfx'), 'site_user' => ',ycc,wj,bhn,wx,lzh,lfj,hwt,thf,vz,sfx,J,ZP,LYY,'), - 'yz' => array('site_code' => 'yz', 'site_id' => 89, 'site_lgc' => '1', 'site_url' => 'http://www.yangtzeriver.org', 'site_image_url' => 'http://images.yangtzeriver.org', 'site_authors' => array('wj', 'vi', 'sfx'), 'site_user' => ',ycc,wj,bhn,hwt,thf,vi,sfx,J,ZP,lyy,'), - 'gl' => array('site_code' => 'gl', 'site_id' => 90, 'site_lgc' => '1', 'site_url' => 'http://www.guilinchina.net', 'site_image_url' => 'http://images.guilinchina.net', 'site_authors' => array('vi', 'sfx'), 'site_user' => ',ycc,vi,bhn,hwt,thf,sfx,J,ZP,lyy,'), - 'mbj' => array('site_code' => 'mbj', 'site_id' => 98, 'site_lgc' => '1', 'site_url' => 'http://www.mybeijingchina.com', 'site_image_url' => 'http://images.mybeijingchina.com', 'site_authors' => array('vz', 'sfx'), 'site_user' => ',ycc,vz,bhn,hwt,thf,sfx,J,ZP,'), - 'ct' => array('site_code' => 'ct', 'site_id' => 1000, 'site_lgc' => '104', 'site_url' => 'http://www.chinatravel.com', 'site_image_url' => 'http://images.chinatravel.com', 'site_authors' => array('ll', 'D'), 'site_user' => ',ycc,vz,bhn,J,wj,ll,D,ZP,lyy,'), - 'dct' => array('site_code' => 'dct', 'site_id' => 99, 'site_lgc' => '1', 'site_url' => 'http://www.diychinatours.com', 'site_image_url' => 'http://images.chinahighlights.com', 'site_authors' => array('zzy', 'spt', 'yl', 'gavin'), 'site_user' => ',ycc,lmr, zyh,J,shw,B,zzy,WJJ,Tony,pcf,zxy,wst,wz,S,yyg,yxd,wj,sw,yl,hx,spt,wmr,syt,gavin,zm,htc,yqw,zl,sw,J,qqs,MGZ,'), + 'sht' => array('site_code' => 'sht', 'site_id' => 96, 'site_lgc' => '1', 'site_url' => 'http://www.shanghaihighlights.com', 'site_image_url' => '//images.shanghaihighlights.com', 'site_authors' => array('vz', 'sfx'), 'site_user' => ',ycc,wj,bhn,wx,lzh,lfj,hwt,thf,vz,sfx,J,ZP,LYY,'), + 'yz' => array('site_code' => 'yz', 'site_id' => 89, 'site_lgc' => '1', 'site_url' => 'http://www.yangtzeriver.org', 'site_image_url' => '//images.yangtzeriver.org', 'site_authors' => array('wj', 'vi', 'sfx'), 'site_user' => ',ycc,wj,bhn,hwt,thf,vi,sfx,J,ZP,lyy,'), + 'gl' => array('site_code' => 'gl', 'site_id' => 90, 'site_lgc' => '1', 'site_url' => 'http://www.guilinchina.net', 'site_image_url' => '//images.guilinchina.net', 'site_authors' => array('vi', 'sfx'), 'site_user' => ',ycc,vi,bhn,hwt,thf,sfx,J,ZP,lyy,'), + 'mbj' => array('site_code' => 'mbj', 'site_id' => 98, 'site_lgc' => '1', 'site_url' => 'http://www.mybeijingchina.com', 'site_image_url' => '//images.mybeijingchina.com', 'site_authors' => array('vz', 'sfx'), 'site_user' => ',ycc,vz,bhn,hwt,thf,sfx,J,ZP,'), + 'ct' => array('site_code' => 'ct', 'site_id' => 1000, 'site_lgc' => '104', 'site_url' => 'http://www.chinatravel.com', 'site_image_url' => '//images.chinatravel.com', 'site_authors' => array('ll', 'D'), 'site_user' => ',ycc,vz,bhn,J,wj,ll,D,ZP,lyy,'), + 'dct' => array('site_code' => 'dct', 'site_id' => 99, 'site_lgc' => '1', 'site_url' => 'http://www.diychinatours.com', 'site_image_url' => '//images.chinahighlights.com', 'site_authors' => array('zzy', 'spt', 'yl', 'gavin'), 'site_user' => ',ycc,lmr, zyh,J,shw,B,zzy,WJJ,Tony,pcf,zxy,wst,wz,S,yyg,yxd,wj,sw,yl,hx,spt,wmr,syt,gavin,zm,htc,yqw,zl,sw,J,qqs,MGZ,'), 'cits' => array('site_code' => 'cits', 'site_id' => 10086, 'site_lgc' => '2', 'site_image_url' => '', 'site_url' => 'www.guilincits.com'), 'mct' => array('site_code' => 'mct', 'site_id' => 6, 'site_lgc' => '101', 'site_image_url' => '', 'site_url' => 'https://www.mychinatours.com', 'site_authors' => array('cj')), - 'diy' => array('site_code' => 'diy', 'site_id' => 99, 'site_lgc' => '1', 'sitemap_name' => 'E:/Dropbox/wwwroot/diychinatours.com/information.sitemap.xml', 'site_image_url' => 'http://images.diychinatours.com', 'site_url' => 'http://www.diychinatours.com', 'site_sitemap' => 'E:/Dropbox/wwwroot/diychinatours.com/information.sitemap.xml', 'site_authors' => array('ycc,lyy')), - 'ah' => array('site_code' => 'ah', 'site_id' => 141, 'site_lgc' => '1', 'sitemap_name' => '', 'site_image_url' => 'https://images.asiahighlights.com', 'site_url' => 'https://www.asiahighlights.com', 'site_sitemap' => '', 'site_authors' => array('X', 'sfx'), 'site_user' => array(',ycc,sfx,X,')), + 'diy' => array('site_code' => 'diy', 'site_id' => 99, 'site_lgc' => '1', 'sitemap_name' => 'E:/Dropbox/wwwroot/diychinatours.com/information.sitemap.xml', 'site_image_url' => '//images.diychinatours.com', 'site_url' => 'http://www.diychinatours.com', 'site_sitemap' => 'E:/Dropbox/wwwroot/diychinatours.com/information.sitemap.xml', 'site_authors' => array('ycc,lyy')), + 'ah' => array('site_code' => 'ah', 'site_id' => 141, 'site_lgc' => '1', 'sitemap_name' => '', 'site_image_url' => '//images.asiahighlights.com', 'site_url' => 'https://www.asiahighlights.com', 'site_sitemap' => '', 'site_authors' => array('X', 'sfx'), 'site_user' => array(',ycc,sfx,X,')), 'bht' => array('site_code' => 'bht', 'site_id' => 6565, 'site_lgc' => '1', 'site_image_url' => '', 'site_url' => 'http://www.beijinghighlights.com', 'site_authors' => array('cj')) ); diff --git a/application/models/infoContents_model.php b/application/models/infoContents_model.php index 0e45d0a0..25bb684f 100644 --- a/application/models/infoContents_model.php +++ b/application/models/infoContents_model.php @@ -42,6 +42,7 @@ class InfoContents_model extends CI_Model $ic_ht_area_id, $ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author) { $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); From ea1afc6d9d57272b26fec78fbabd79e1cae79427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Thu, 15 Jun 2017 10:32:48 +0800 Subject: [PATCH 07/41] =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=BA=E8=87=AA=E9=80=82=E5=BA=94=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/models/infoContents_model.php | 3 +++ application/views/bootstrap3/information_edit.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/application/models/infoContents_model.php b/application/models/infoContents_model.php index 25bb684f..f28cbd6b 100644 --- a/application/models/infoContents_model.php +++ b/application/models/infoContents_model.php @@ -17,6 +17,9 @@ class InfoContents_model extends CI_Model { $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" diff --git a/application/views/bootstrap3/information_edit.php b/application/views/bootstrap3/information_edit.php index 0edd64da..e6283001 100644 --- a/application/views/bootstrap3/information_edit.php +++ b/application/views/bootstrap3/information_edit.php @@ -549,7 +549,7 @@ - + From 1442ed3be8bed8428bd9733e0599af7199a4d553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Thu, 15 Jun 2017 10:40:25 +0800 Subject: [PATCH 08/41] =?UTF-8?q?http=E7=9A=84=E5=9B=BE=E7=89=87=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E6=94=B9=E4=B8=BA//?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/models/infoContents_model.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/models/infoContents_model.php b/application/models/infoContents_model.php index f28cbd6b..7e6b3e64 100644 --- a/application/models/infoContents_model.php +++ b/application/models/infoContents_model.php @@ -15,6 +15,7 @@ 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); @@ -44,6 +45,7 @@ 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); From 0c84f6ca62f2da00af0968a091866aec42d2579b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Thu, 15 Jun 2017 14:01:25 +0800 Subject: [PATCH 09/41] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=8A=93=E5=8F=96?= =?UTF-8?q?=EF=BC=8C=E8=87=AA=E5=8A=A8=E6=B7=BB=E5=8A=A0=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pagespeed/controllers/index.php | 36 +++++++++--- .../pagespeed/models/PageSpeedData_model.php | 56 ++++++++++++++++++- 2 files changed, 82 insertions(+), 10 deletions(-) diff --git a/application/third_party/pagespeed/controllers/index.php b/application/third_party/pagespeed/controllers/index.php index 9e1fef6f..9b13cab9 100644 --- a/application/third_party/pagespeed/controllers/index.php +++ b/application/third_party/pagespeed/controllers/index.php @@ -16,12 +16,25 @@ class Index extends CI_Controller { //自动抓取分数和排名 public function auto($sitecode = 'cht') { - $this->run('/', '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 run($psd_URL, $psd_SiteCode) { + public function run($psd_URL = false, $psd_SiteCode = false) { if (empty($psd_URL) || empty($psd_SiteCode)) { - return false; + $psd_URL = $this->input->get_post('psd_URL'); + $psd_SiteCode = $this->input->get_post('psd_SiteCode'); + if (empty($psd_URL) || empty($psd_SiteCode)) { + return false; + } } $sites = $this->config->item('site'); if (empty($sites[$psd_SiteCode])) { @@ -33,9 +46,9 @@ class Index extends CI_Controller { $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"; + // $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"; + //$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); @@ -45,14 +58,19 @@ class Index extends CI_Controller { $desktop_object = json_decode($desktop_data); $mobile_object = json_decode($mobile_data); if (!empty($desktop_object->error) || !empty($mobile_object->error)) { + $this->PageSpeedData_model->update_error($pagespeed_data->psd_id); + echo 'pagespeed_error:' . json_encode($desktop_object) . ' ' . json_encode($mobile_object); + log_message('error ', 'pagespeed_error:' . json_encode($desktop_object) . ' ' . json_encode($mobile_object)); return false; } if (!$desktop_object->responseCode == '200' || !$mobile_object->responseCode == '200') { - echo 'ERROR:' . $desktop_object->responseCode . ' ' . $mobile_object->responseCode; + $this->PageSpeedData_model->update_error($pagespeed_data->psd_id); + echo 'pagespeed_error:' . json_encode($desktop_object) . ' ' . json_encode($mobile_object); + 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; @@ -61,14 +79,14 @@ class Index extends CI_Controller { $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 $run_URL . '
'; + echo json_encode($pagespeed_data); } } diff --git a/application/third_party/pagespeed/models/PageSpeedData_model.php b/application/third_party/pagespeed/models/PageSpeedData_model.php index d31f9449..a2086ce1 100644 --- a/application/third_party/pagespeed/models/PageSpeedData_model.php +++ b/application/third_party/pagespeed/models/PageSpeedData_model.php @@ -22,7 +22,7 @@ class PageSpeedData_model extends CI_Model { $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); + $this->where .= ' AND psd.psd_SiteCode=' . $this->INFO->escape($psd_SiteCode); return $this->get_list(); } @@ -34,10 +34,64 @@ class PageSpeedData_model extends CI_Model { } } + public function insert_list($psd_SiteCode) { + $sql = " + INSERT INTO PageSpeedData + ( + psd_URL + ,psd_SiteCode + ) + SELECT TOP 10 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 DESC + "; + $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->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 .= " From a43809eb4ed7ba2c4dc0e23ff560610bd48a9ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Thu, 15 Jun 2017 15:16:22 +0800 Subject: [PATCH 10/41] =?UTF-8?q?=E5=9B=9E=E6=98=BE=E5=88=86=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third_party/pagespeed/controllers/index.php | 13 ++++++++----- .../pagespeed/models/PageSpeedData_model.php | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/application/third_party/pagespeed/controllers/index.php b/application/third_party/pagespeed/controllers/index.php index 9b13cab9..438679c2 100644 --- a/application/third_party/pagespeed/controllers/index.php +++ b/application/third_party/pagespeed/controllers/index.php @@ -33,11 +33,13 @@ class Index extends CI_Controller { $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已经含有了 @@ -46,27 +48,28 @@ class Index extends CI_Controller { $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"; + $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"; + $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 (!empty($desktop_object->error) || !empty($mobile_object->error)) { $this->PageSpeedData_model->update_error($pagespeed_data->psd_id); - echo 'pagespeed_error:' . json_encode($desktop_object) . ' ' . json_encode($mobile_object); + 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 'pagespeed_error:' . json_encode($desktop_object) . ' ' . json_encode($mobile_object); + echo json_encode(array('result' => 'error', 'data' => 'API返回错误,网页打不开')); log_message('error ', 'pagespeed_error:' . json_encode($desktop_object) . ' ' . json_encode($mobile_object)); return FALSE; } @@ -86,7 +89,7 @@ class Index extends CI_Controller { $where = array('psd_id' => $pagespeed_data->psd_id); $this->PageSpeedData_model->update('PageSpeedData', $PageSpeedData, $where); } - echo json_encode($pagespeed_data); + echo json_encode(array('result' => 'ok', 'data' => 'M:'.$PageSpeedData->psd_MobileScore.',D:'.$PageSpeedData->psd_DesktopScore)); } } diff --git a/application/third_party/pagespeed/models/PageSpeedData_model.php b/application/third_party/pagespeed/models/PageSpeedData_model.php index a2086ce1..5ba8e070 100644 --- a/application/third_party/pagespeed/models/PageSpeedData_model.php +++ b/application/third_party/pagespeed/models/PageSpeedData_model.php @@ -41,7 +41,7 @@ class PageSpeedData_model extends CI_Model { psd_URL ,psd_SiteCode ) - SELECT TOP 10 ic.ic_url + SELECT TOP 200 ic.ic_url ,ic.ic_sitecode FROM Tourmanager.dbo.infoContents ic WHERE ic.ic_status = 1 @@ -54,7 +54,7 @@ class PageSpeedData_model extends CI_Model { AND psd.psd_SiteCode = ic.ic_sitecode ) ORDER BY - ic.ic_datetime DESC + ic.ic_datetime ASC "; $this->INFO->query($sql,array($psd_SiteCode)); } From 08e77c62a06937884b77ec5c05421b00273ca866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Thu, 15 Jun 2017 15:21:21 +0800 Subject: [PATCH 11/41] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/third_party/pagespeed/controllers/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/third_party/pagespeed/controllers/index.php b/application/third_party/pagespeed/controllers/index.php index 438679c2..16bdc672 100644 --- a/application/third_party/pagespeed/controllers/index.php +++ b/application/third_party/pagespeed/controllers/index.php @@ -48,9 +48,9 @@ class Index extends CI_Controller { $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"; + $//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"; + //$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); From 7236310e2444fc2ebdb325db4b53b74691bdba16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Thu, 15 Jun 2017 15:22:15 +0800 Subject: [PATCH 12/41] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/third_party/pagespeed/controllers/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/third_party/pagespeed/controllers/index.php b/application/third_party/pagespeed/controllers/index.php index 16bdc672..24b9b48f 100644 --- a/application/third_party/pagespeed/controllers/index.php +++ b/application/third_party/pagespeed/controllers/index.php @@ -48,7 +48,7 @@ class Index extends CI_Controller { $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"; + //$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(); From 9571e190cbfb1b50c175ab8f85e7f5807cf3a15c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Thu, 15 Jun 2017 16:02:25 +0800 Subject: [PATCH 13/41] =?UTF-8?q?=E5=9C=A8=E4=BF=A1=E6=81=AF=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E9=A1=B5=E9=9D=A2=E6=98=BE=E7=A4=BA=E7=BD=91=E9=A1=B5?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E5=88=86=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pagespeed/controllers/index.php | 15 +++++++++- .../views/bootstrap3/information_edit.php | 4 +-- js/information-system3.min.js | 29 +++++++++++++------ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/application/third_party/pagespeed/controllers/index.php b/application/third_party/pagespeed/controllers/index.php index 24b9b48f..c3ffcc6c 100644 --- a/application/third_party/pagespeed/controllers/index.php +++ b/application/third_party/pagespeed/controllers/index.php @@ -28,6 +28,19 @@ class Index extends CI_Controller { } } + 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'); @@ -89,7 +102,7 @@ class Index extends CI_Controller { $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)); + echo json_encode(array('result' => 'ok', 'data' => 'M:' . $PageSpeedData->psd_MobileScore . ',D:' . $PageSpeedData->psd_DesktopScore)); } } diff --git a/application/views/bootstrap3/information_edit.php b/application/views/bootstrap3/information_edit.php index e6283001..7bd648aa 100644 --- a/application/views/bootstrap3/information_edit.php +++ b/application/views/bootstrap3/information_edit.php @@ -1182,9 +1182,9 @@

+ mobile_friendly(true);">网页性能检测: - HTML规范验证 +

diff --git a/js/information-system3.min.js b/js/information-system3.min.js index 8c5ab002..643850e7 100644 --- a/js/information-system3.min.js +++ b/js/information-system3.min.js @@ -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,8 @@ $(document).ready(function() { $('.ShowMeTheDatePicker').datepicker({ showButtonPanel: true }); + + + setTimeout(function(){mobile_friendly(),1000}); }); \ No newline at end of file From 94d17e3836a22a942aa1500d22254225df844e92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Fri, 16 Jun 2017 09:44:37 +0800 Subject: [PATCH 14/41] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E5=8A=A0=E8=BD=BDjs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third_party/htmlcompressor/controllers/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/third_party/htmlcompressor/controllers/index.php b/application/third_party/htmlcompressor/controllers/index.php index d089cf0a..f68849d8 100644 --- a/application/third_party/htmlcompressor/controllers/index.php +++ b/application/third_party/htmlcompressor/controllers/index.php @@ -90,14 +90,14 @@ class Index extends CI_Controller { //在最后加载原始css文件和js文件 //把css移动到页面底部,延迟加载 - $lastload_js = ''; + $lastload_js.=''; //把js移动到页面底部 foreach ($link_js_array as $item) { - $lastload_js.=''; + $lastload_js.=''; } $lastload_js.=$js_content; From a3b730ff4abc0e3553bdd75401d7cadc23b3544e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Fri, 16 Jun 2017 09:53:57 +0800 Subject: [PATCH 15/41] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E5=8A=A0=E8=BD=BDjs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third_party/htmlcompressor/controllers/index.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/application/third_party/htmlcompressor/controllers/index.php b/application/third_party/htmlcompressor/controllers/index.php index f68849d8..b2bbc8bf 100644 --- a/application/third_party/htmlcompressor/controllers/index.php +++ b/application/third_party/htmlcompressor/controllers/index.php @@ -60,8 +60,7 @@ class Index extends CI_Controller { $link_script->outertext = ''; //删除链接,移动到页底 } else { //网页内的js不需要提取 - //$js_content.= $link_script->innertext;//js的内容 - $js_content.= $link_script; + $js_content.= $link_script->innertext;//js的内容 $link_script->outertext = ''; //删除js,移动到页底 } } @@ -90,7 +89,7 @@ class Index extends CI_Controller { //在最后加载原始css文件和js文件 //把css移动到页面底部,延迟加载 - $lastload_js = ''; } - $lastload_js.=$js_content; + $lastload_js.=''; $html_object = str_replace('', $lastload_js . '', $html_object); } From 4455c9958f2b8841a17598844b5df453fcd4371a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Fri, 16 Jun 2017 09:53:57 +0800 Subject: [PATCH 16/41] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E5=8A=A0=E8=BD=BDjs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/third_party/htmlcompressor/controllers/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/third_party/htmlcompressor/controllers/index.php b/application/third_party/htmlcompressor/controllers/index.php index f68849d8..9d278b75 100644 --- a/application/third_party/htmlcompressor/controllers/index.php +++ b/application/third_party/htmlcompressor/controllers/index.php @@ -61,7 +61,7 @@ class Index extends CI_Controller { } else { //网页内的js不需要提取 //$js_content.= $link_script->innertext;//js的内容 - $js_content.= $link_script; + $js_content.= $link_script;//js的内容,包含'; //把js移动到页面底部 foreach ($link_js_array as $item) { - $lastload_js.=''; + $lastload_js.=''; } - $lastload_js.=''; + $lastload_js.=$js_content; $html_object = str_replace('', $lastload_js . '', $html_object); } From 11bb9728dc13a2d6b50d96c56137295a4ce62e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Fri, 16 Jun 2017 10:53:49 +0800 Subject: [PATCH 18/41] =?UTF-8?q?css=E5=BB=B6=E8=BF=9F=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../htmlcompressor/controllers/index.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/application/third_party/htmlcompressor/controllers/index.php b/application/third_party/htmlcompressor/controllers/index.php index 9f4fccd8..b2f32dca 100644 --- a/application/third_party/htmlcompressor/controllers/index.php +++ b/application/third_party/htmlcompressor/controllers/index.php @@ -61,6 +61,14 @@ class Index extends CI_Controller { } else { //网页内的js不需要提取 //$js_content.= $link_script->innertext;//js的内容 + // $js_content.= $link_script;//js的内容,包含'; + $lastload_js.=''; //把js移动到页面底部 foreach ($link_js_array as $item) { $lastload_js.=''; From 46e0f509f85d9e97d3e0c5907c02e2739c522dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Fri, 16 Jun 2017 11:42:37 +0800 Subject: [PATCH 19/41] =?UTF-8?q?css=E5=BB=B6=E8=BF=9F=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../htmlcompressor/controllers/index.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/application/third_party/htmlcompressor/controllers/index.php b/application/third_party/htmlcompressor/controllers/index.php index b2f32dca..ca1f0e17 100644 --- a/application/third_party/htmlcompressor/controllers/index.php +++ b/application/third_party/htmlcompressor/controllers/index.php @@ -62,14 +62,16 @@ class Index extends CI_Controller { //网页内的js不需要提取 //$js_content.= $link_script->innertext;//js的内容 // $js_content.= $link_script;//js的内容,包含'; //把js移动到页面底部 foreach ($link_js_array as $item) { - $lastload_js.=''; + $lastload_js.=''; } $lastload_js.=$js_content; From eabf44005fa28c03f84fb7004de5b1fa48617d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Fri, 16 Jun 2017 22:39:17 +0800 Subject: [PATCH 20/41] =?UTF-8?q?defer=E5=9C=A8=E5=86=85=E8=BF=9Ejs?= =?UTF-8?q?=E4=BC=9A=E6=9C=89bug=EF=BC=8C=E6=9A=82=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/helpers/info_helper.php | 7 ++++++- .../htmlcompressor/controllers/index.php | 16 ++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) 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/third_party/htmlcompressor/controllers/index.php b/application/third_party/htmlcompressor/controllers/index.php index ca1f0e17..95171dfd 100644 --- a/application/third_party/htmlcompressor/controllers/index.php +++ b/application/third_party/htmlcompressor/controllers/index.php @@ -63,15 +63,15 @@ class Index extends CI_Controller { //$js_content.= $link_script->innertext;//js的内容 // $js_content.= $link_script;//js的内容,包含'; //把js移动到页面底部 foreach ($link_js_array as $item) { - $lastload_js.=''; + $lastload_js.=''; } $lastload_js.=$js_content; From 7a8d5713460dc7497899419a222bee3103b79c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Mon, 19 Jun 2017 09:08:24 +0800 Subject: [PATCH 21/41] =?UTF-8?q?=E6=8A=8Ajs=E5=88=86=E7=A6=BB=E5=87=BA?= =?UTF-8?q?=E6=9D=A5=EF=BC=8C=E8=BF=94=E5=9B=9Ejson=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../htmlcompressor/controllers/index.php | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/application/third_party/htmlcompressor/controllers/index.php b/application/third_party/htmlcompressor/controllers/index.php index 95171dfd..fceba443 100644 --- a/application/third_party/htmlcompressor/controllers/index.php +++ b/application/third_party/htmlcompressor/controllers/index.php @@ -53,7 +53,8 @@ class Index extends CI_Controller { // //提取和下载所有JS脚本,包括链接文件和页面脚本 $link_js_array = array(); - $js_content = ''; + $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; @@ -62,22 +63,19 @@ class Index extends CI_Controller { //网页内的js不需要提取 //$js_content.= $link_script->innertext;//js的内容 // $js_content.= $link_script;//js的内容,包含'; - //把js移动到页面底部 - foreach ($link_js_array as $item) { - $lastload_js.=''; - } - $lastload_js.=$js_content; + + $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 $html_object; + echo json_encode(array('result' => 'ok', 'data' => array('html_object' => $html_object, 'js_content' => $js_content))); } //格式化url,保证请求的URL有域名,//更换为对应的域名路径 From a90c87a32ded47bdba77a933e2a76d0678793b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Mon, 19 Jun 2017 09:53:21 +0800 Subject: [PATCH 22/41] =?UTF-8?q?ah=E7=AB=99=E7=82=B9=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=90=AF=E7=94=A8html=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/information.php | 6 +----- application/views/bootstrap3/information_edit.php | 6 ------ 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/application/controllers/information.php b/application/controllers/information.php index 3309bc53..e7e61f10 100644 --- a/application/controllers/information.php +++ b/application/controllers/information.php @@ -526,12 +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 { - $static_html_optimize = $this->input->get_post('static_html_optimize'); - if (!empty($static_html_optimize)) { + // 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 = 'https://www.asiahighlights.com/index.php/information/detail/?static_html_url=' . $url; - } } } else { //子站点使用 $url = $this->config->item('site_url') . $url . '@cache@refresh'; diff --git a/application/views/bootstrap3/information_edit.php b/application/views/bootstrap3/information_edit.php index 7bd648aa..f1b965a4 100644 --- a/application/views/bootstrap3/information_edit.php +++ b/application/views/bootstrap3/information_edit.php @@ -1163,12 +1163,6 @@ - config->item('site_code') == 'ah') { ?> -
- -
config->item('site_code') == 'ah')) { ?> From db4fac819945b51a057d9a468491e205a26ada2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Mon, 19 Jun 2017 15:42:01 +0800 Subject: [PATCH 23/41] =?UTF-8?q?pagespeed=E5=88=86=E6=95=B0=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=92=8C=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pagespeed/controllers/index.php | 30 +++++- .../pagespeed/models/PageSpeedData_model.php | 49 ++++++++- .../third_party/pagespeed/views/search.php | 43 ++++++++ .../third_party/pagespeed/views/welcome.php | 102 ++++++++++++++---- application/views/bootstrap/header.php | 3 +- application/views/bootstrap3/header.php | 1 + 6 files changed, 201 insertions(+), 27 deletions(-) create mode 100644 application/third_party/pagespeed/views/search.php diff --git a/application/third_party/pagespeed/controllers/index.php b/application/third_party/pagespeed/controllers/index.php index c3ffcc6c..84e81a3f 100644 --- a/application/third_party/pagespeed/controllers/index.php +++ b/application/third_party/pagespeed/controllers/index.php @@ -11,7 +11,27 @@ class Index extends CI_Controller { } 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, $device, $this->config->item('site_code')); + if (empty($data['score_data_list'])) { + echo json_encode('没有找到数据'); + } else { + echo json_encode($this->load->view('search', $data, true)); + } } //自动抓取分数和排名 @@ -20,11 +40,13 @@ class Index extends CI_Controller { $this->PageSpeedData_model->insert_list($sitecode); $update_list = $this->PageSpeedData_model->get_update_list($sitecode, 2); if (empty($update_list)) { - echo 'all done!'; + echo'all done!'; return; } + foreach ($update_list as $item) { - $this->run($item->psd_URL, $item->psd_SiteCode); + $this->run($item->psd_URL, $item-> + psd_SiteCode); } } @@ -37,7 +59,8 @@ class Index extends CI_Controller { } $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)); + echo json_encode(array('result' => 'ok', 'data' => 'M:' . $pagespeed_data->psd_MobileScore . ',D:' . $pagespeed_data-> + psd_DesktopScore)); } } @@ -47,6 +70,7 @@ class Index extends CI_Controller { $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; } } diff --git a/application/third_party/pagespeed/models/PageSpeedData_model.php b/application/third_party/pagespeed/models/PageSpeedData_model.php index 5ba8e070..e8008b85 100644 --- a/application/third_party/pagespeed/models/PageSpeedData_model.php +++ b/application/third_party/pagespeed/models/PageSpeedData_model.php @@ -56,7 +56,7 @@ class PageSpeedData_model extends CI_Model { ORDER BY ic.ic_datetime ASC "; - $this->INFO->query($sql,array($psd_SiteCode)); + $this->INFO->query($sql, array($psd_SiteCode)); } public function get_update_list($psd_SiteCode, $topnum = 3) { @@ -124,4 +124,51 @@ class PageSpeedData_model extends CI_Model { } } + 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 '; + } + 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=? + "; + $query = $this->INFO->query($sql, array($psd_SiteCode)); + if ($query->num_rows() > 0) { + $row = $query->row(); + return $row; + } else { + return FALSE; + } + } + } diff --git a/application/third_party/pagespeed/views/search.php b/application/third_party/pagespeed/views/search.php new file mode 100644 index 00000000..1d4dac44 --- /dev/null +++ b/application/third_party/pagespeed/views/search.php @@ -0,0 +1,43 @@ + $item) { + +} +?> + + +
+ + + + + + + + + + + + + config->item('site_url'), '/'); + if (!empty($score_data_list)) { + foreach ($score_data_list as $key => $item) { + ?> + + + + + + + + + + + +
#页面移动端桌面端更新时间操作
psd_URL; ?>psd_MobileScore; ?>psd_DesktopScore; ?>psd_Datetime)); ?> + 查看页面 | Google insights +
+
\ No newline at end of file diff --git a/application/third_party/pagespeed/views/welcome.php b/application/third_party/pagespeed/views/welcome.php index e18468fd..b709651e 100644 --- a/application/third_party/pagespeed/views/welcome.php +++ b/application/third_party/pagespeed/views/welcome.php @@ -1,22 +1,80 @@ - - - - - - - - HTML-Compressor - - - -

页面样式精简

-
-

- - -
- - - + + + +
+ +根据分数搜索页面 + + +
+ + \ No newline at end of file diff --git a/application/views/bootstrap/header.php b/application/views/bootstrap/header.php index 6b471097..0789cad2 100644 --- a/application/views/bootstrap/header.php +++ b/application/views/bootstrap/header.php @@ -73,11 +73,12 @@ 更多 diff --git a/application/views/bootstrap3/header.php b/application/views/bootstrap3/header.php index 8d164b96..c5ef8df2 100644 --- a/application/views/bootstrap3/header.php +++ b/application/views/bootstrap3/header.php @@ -77,6 +77,7 @@ 更多