diff --git a/application/controllers/keyworlds.php b/application/controllers/keyworlds.php index 429adf01..1adf548b 100644 --- a/application/controllers/keyworlds.php +++ b/application/controllers/keyworlds.php @@ -16,7 +16,7 @@ class Keyworlds extends CI_Controller { public function index($kw_is_id = '') { $this->load->library('Accesscheck'); - $this->accesscheck->check_access(); + $this->accesscheck->check_access(); // test-- $this->permission->is_admin(); //查询结构列表信息 @@ -70,6 +70,7 @@ class Keyworlds extends CI_Controller { $data['wordcount'] = 2; } } + $data['rank_info'] = $this->Keywordsrank_model->get_rank_list($is_id_string, 30, $startdate, $enddate); empty($data['rank_info']) && $data['rank_info'] = $this->Keywordsrank_model->get_rank_list($is_id_string, 30); if (!empty($data['rank_info'])) { @@ -94,10 +95,15 @@ class Keyworlds extends CI_Controller { } } } +// print_r($data['wordcount']); +// print_r($rank_json); + // 拼接highcharts数据格式 $data['rank_json'] = '['; foreach ($rank_json as &$ra) { ksort($ra); + // 每条线 $data['rank_json'] .='{"name":"' . $ra[$data_time[0]]->kw_keyworlds . '","data":['; + // 每个点 foreach ($ra as $v) { $kwr_rank = $v->kwr_rank; if ($v->kwr_rank == '>150') @@ -110,8 +116,25 @@ class Keyworlds extends CI_Controller { } $data['rank_json'] = substr($data['rank_json'], 0, -1); $data['rank_json'] .=']},'; + // 叶子节点 显示mobile记录 + if ($data['wordcount'] == 1) { + $data['rank_json'] .='{"name":"' . $ra[$data_time[0]]->kw_keyworlds . '(mobile)","data":['; + foreach ($ra as $v) { + $kwr_mobile_rank = $v->kwr_mobile_rank ? $v->kwr_mobile_rank : 'null' ; + if ($v->kwr_mobile_rank == '>150') + $kwr_mobile_rank = 100; + if (strtolower($this->config->item('site_code')) == 'gm') { + $data['rank_json'] .=-$kwr_mobile_rank . ','; + } else { + $data['rank_json'] .=$kwr_mobile_rank . ','; + } + } + $data['rank_json'] = substr($data['rank_json'], 0, -1); + $data['rank_json'] .=']},'; + } } $data['rank_json'] = substr($data['rank_json'], 0, -1) . ']'; +// print_r($data['rank_json']); $data['data_time'] = json_encode($data_time); $data['rank_info'] = ''; isset($rank_json[$data['current_keyworld']->kw_id]) && $data['rank_info'] = $rank_json[$data['current_keyworld']->kw_id]; @@ -120,9 +143,10 @@ class Keyworlds extends CI_Controller { redirect(site_url("Keyworlds/index")); } - $data['analytics'] = $this->analytics_model->get_keyword_analytics($data['current_keyworld']->kw_keyworlds, 30); + // $data['analytics'] = $this->analytics_model->get_keyword_analytics($data['current_keyworld']->kw_keyworlds, 30); $data['site_code'] = strtolower($this->config->item('site_code')); - +// print_r($data['rank_info']); +// print_r($data["rank_json"]); $this->load->view('bootstrap/header', $data); $this->load->view('keyworlds/index'); $this->load->view('bootstrap/footer'); @@ -228,12 +252,29 @@ class Keyworlds extends CI_Controller { public function get_google_rank() { $keyworlds = $this->input->post('keyworlds'); //搜索关键字 - $kw_id = $this->input->post('kw_id'); - $site_url = $this->config->item('site_url'); - - //$engines = array('cht'=>'get_search_content_by_aol','gm' =>'get_search_content_by_google','vc' =>'get_search_content_by_google','jp' =>'get_search_content_by_yahoo','vac'=>'get_search_content_by_google','it' =>'get_search_content_by_google','ru' =>'get_search_content_by_google','wt' =>'get_search_content_by_baidu','tbt'=>'get_search_content_by_aol','sht'=>'get_search_content_by_aol','yz' =>'get_search_content_by_aol','gl' =>'get_search_content_by_aol','mbj'=>'get_search_content_by_aol','ct' =>'get_search_content_by_aol','mct'=>'get_search_content_by_aol','dct'=>'get_search_content_by_aol','cits' =>'get_search_content_by_baidu',); - //$engines = array('cht'=>'get_search_content_by_google','gm' =>'get_search_content_by_google','vc' =>'get_search_content_by_google','jp' =>'get_search_content_by_yahoo','vac'=>'get_search_content_by_google','it' =>'get_search_content_by_google','ru' =>'get_search_content_by_google','wt' =>'get_search_content_by_baidu','tbt'=>'get_search_content_by_google','sht'=>'get_search_content_by_google','yz' =>'get_search_content_by_google','gl' =>'get_search_content_by_google','mbj'=>'get_search_content_by_google','ct' =>'get_search_content_by_google','mct'=>'get_search_content_by_google','dct'=>'get_search_content_by_google','cits' =>'get_search_content_by_baidu'); - $engines = array('cht' => 'get_search_content_by_google', 'gm' => 'get_search_content_by_google', 'vc' => 'get_search_content_by_google', 'jp' => 'get_search_content_by_google', 'vac' => 'get_search_content_by_google', 'it' => 'get_search_content_by_google', 'ru' => 'get_search_content_by_google', 'wt' => 'get_search_content_by_baidu', 'tbt' => 'get_search_content_by_google', 'sht' => 'get_search_content_by_google', 'yz' => 'get_search_content_by_google', 'gl' => 'get_search_content_by_google', 'mbj' => 'get_search_content_by_google', 'ct' => 'get_search_content_by_google', 'mct' => 'get_search_content_by_google', 'dct' => 'get_search_content_by_google', 'cits' => 'get_search_content_by_baidu', 'ah' => 'get_search_content_by_google'); + $kw_id = $this->input->post('kw_id'); + $site_url = $this->config->item('site_url'); + + $engines = array( + 'cht' => 'get_search_content_by_google', + 'gm' => 'get_search_content_by_google', + 'vc' => 'get_search_content_by_google', + 'jp' => 'get_search_content_by_google', + 'vac' => 'get_search_content_by_google', + 'it' => 'get_search_content_by_google', + 'ru' => 'get_search_content_by_google', + 'wt' => 'get_search_content_by_baidu', + 'tbt' => 'get_search_content_by_google', + 'sht' => 'get_search_content_by_google', + 'yz' => 'get_search_content_by_google', + 'gl' => 'get_search_content_by_google', + 'mbj' => 'get_search_content_by_google', + 'ct' => 'get_search_content_by_google', + 'mct' => 'get_search_content_by_google', + 'dct' => 'get_search_content_by_google', + 'cits' => 'get_search_content_by_baidu', + 'ah' => 'get_search_content_by_google' + ); $site_code = $this->config->item('site_code'); $method = $engines[$site_code]; @@ -268,15 +309,15 @@ class Keyworlds extends CI_Controller { if ($rank['rank'] == '151') { //超过151的排名则不记录 $this->Keywords_model->update_time($kw_id); } elseif (isset($last_rank[0]->kwr_datetime) and $last_rank[0]->kwr_datetime > strtotime(date('Y-m-d'))) { - if ($rank['rank'] != -1 and $rank['rank'] != -2 and $this->Keywordsrank_model->update_rank($last_rank[0]->kwr_id, $rank['rank'], $rank['source'])) { + if ($rank['rank'] != -1 and $rank['rank'] != -2 and $this->Keywordsrank_model->update_rank($last_rank[0]->kwr_id, $rank['rank'], $rank['rank_m'], $rank['source'], $rank['source_m'])) { $this->Keywords_model->update_time($kw_id); } } else { - if ($rank['rank'] != -1 and $rank['rank'] != -2 and $this->Keywordsrank_model->add_rank($kw_id, $rank['rank'], $rank['source'], $rank['engines'])) { + if ($rank['rank'] != -1 and $rank['rank'] != -2 and $this->Keywordsrank_model->add_rank($kw_id, $rank['rank'], $rank['rank_m'], $rank['source'], $rank['source_m'], $rank['engines'])) { $this->Keywords_model->update_time($kw_id); } } - $data[] = array('name' => 'rank', 'value' => $rank['rank']); + $data[] = array('name' => 'rank', 'value' => ($rank['rank'] . " -- " . $rank["rank_m"])); echo json_encode($data); return TRUE; } @@ -307,8 +348,6 @@ class Keyworlds extends CI_Controller { $rank = $this->get_search_content_by_google($v->kw_keyworlds, $site_url, $i, $site_code); } else if ($engines == 'yandex') {//俄语站的yangdex $rank = $this->get_search_content_by_yandex($v->kw_keyworlds, $site_url, $i - 1); - } elseif ($engines == 'yahoo') { - $rank = $this->get_search_content_by_yahoo($v->kw_keyworlds, $site_url, $i, $site_code); } if ($rank['rank'] != 0) { @@ -323,7 +362,7 @@ class Keyworlds extends CI_Controller { } if ($rank['rank'] == '151') { //超过151的排名则不记录 $this->Keywords_model->update_time($v->kw_id); - }else if ($rank['rank'] != -1 and $rank['rank'] != -2 and $this->Keywordsrank_model->add_rank($v->kw_id, $rank['rank'], $rank['source'], $rank['engines'])) { + }else if ($rank['rank'] != -1 and $rank['rank'] != -2 and $this->Keywordsrank_model->add_rank($v->kw_id, $rank['rank'], $rank['rank_m'], $rank['source'], $rank['source_m'], $rank['engines'])) { $this->load->model('InfoSMS_model'); $last_rank = isset($last_rank[0]) ? $last_rank[0]->kwr_rank : $rank['rank']; $this->InfoSMS_model->readed_for_info($v->kw_id, 'keywords_rank'); @@ -339,31 +378,27 @@ class Keyworlds extends CI_Controller { public function get_search_content_by_google($keyworlds, $site_url, $page, $site_code) { $rank['rank'] = 0; $rank['source'] = $site_url; + $rank['rank_m'] = 0; + $rank['source_m'] = $site_url; $rank['engines'] = 'google'; if ($page > 3) { $rank['rank'] = 151; + $rank['rank_m'] = 151; return $rank; } - //拼接关键词 - /* $key_array = explode(' ',$keyworlds); - $search_worlds=''; - foreach ($key_array as $v) { - $search_worlds.='+'.$v; - } - $search_worlds = substr($search_worlds,1); */ $search_worlds = urlencode($keyworlds); //拼接搜索url链接 $start = ($page - 1) * 50; $google_url = 'google.com'; $google_domain = array( - 'gm' => 'google.de', - 'vc' => 'google.fr', + 'gm' => 'google.de', + 'vc' => 'google.fr', 'vac' => 'google.es', - 'ru' => 'google.ru', - 'it' => 'google.it', - 'jp' => 'google.co.jp' + 'ru' => 'google.ru', + 'it' => 'google.it', + 'jp' => 'google.co.jp' ); if (!empty($google_domain[$site_code])) $google_url = $google_domain[$site_code]; @@ -374,12 +409,9 @@ class Keyworlds extends CI_Controller { $language = $language_array[$site_code]; //抓取google搜索结果 - $this->load->library('Snoopy'); - $snoopy = $this->snoopy; - $snoopy->maxredirs = 0; - $snoopy->agent = '(compatible; MSIE 11; MSN 8; AOL 4.0; Windows 98)'; //模拟浏览器 - if ($snoopy->fetch("http://www.$google_url/search?q=$search_worlds&start=$start&num=50&hl=$language")) { - $response = $snoopy->results; + $url = "https://www.$google_url/search?q=$search_worlds&start=$start&num=50&hl=$language"; + $response = $this->curl($url); + if ($response) { //分析google搜索结果,计算排名 if (false !== stripos($response, '

302 Moved

')) { $rank['rank'] = -2; @@ -391,17 +423,43 @@ class Keyworlds extends CI_Controller { //计算排名 $rank['rank'] = $start + $k + 1; //抓取关键词来源 - $end = stripos($v, '&', $ismatch); + $end = strpos($v, '"', $ismatch); $source = substr($v, $ismatch, $end); - $source = explode('&', $source); + $source = explode('"', $source); $rank['source'] = $source[0]; break; } } + } else { + // log_message('error','google search response not found CH'); } } else { $rank['rank'] = -1; } + // 移动端 + $response_m = $this->curl($url,"m"); + if ($response_m) { + if (false !== stripos($response_m, '

302 Moved

')) { + $rank['rank_m'] = -2; + } elseif (false !== stripos($response_m, $site_url)) { + preg_match_all('/ $vm) { + $ismatch_m = stripos($vm, $site_url); + if (false !== $ismatch_m) { + //计算排名 + $rank['rank_m'] = $start + $km + 1; + //抓取关键词来源 + $end_m = strpos($vm, '"', $ismatch_m); + $source_m = substr($vm, $ismatch_m, $end_m); + $source_m = explode('"', $source_m); + $rank['source_m'] = $source_m[0]; + break; + } + } + } + } else { + $rank['rank_m'] = -1; + } // ---- 移动端 end ---- return $rank; } @@ -414,26 +472,30 @@ class Keyworlds extends CI_Controller { //计算关键词在yandex搜索引擎的排名 public function get_search_content_by_yandex($keyworlds, $site_url, $page = 0, $sitecode = false) { $rank['rank'] = 0; + $rank['rank_m'] = 0; $rank['source'] = $site_url; + $rank['source_m'] = $site_url; $rank['engines'] = 'yandex'; + if ($page > 3) { + $rank['rank'] = 151; + $rank['rank_m'] = 151; + return $rank; + } $startrank = $page * 10; $search_worlds = urlencode($keyworlds); //抓取搜索结果数据 - $this->load->library('Snoopy'); - $snoopy = $this->snoopy; - $snoopy->host = 'yandex.ru'; - $snoopy->referer = "http://www.yandex.ru/"; - //$snoopy->maxredirs=0; - $snoopy->agent = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:20.0) Gecko/20100101 Firefox/20.0'; - //$snoopy->agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36';//模拟浏览器 - if ($snoopy->fetch("http://www.yandex.ru/yandsearch?p=$page&text=$search_worlds&lr=21436")) { - $response = $snoopy->results; + $url = "https://www.yandex.ru/yandsearch?p=$page&text=$search_worlds&lr=21436"; + $refer = "https://www.yandex.ru/"; + $response = $this->curl($url,'PC',$refer); + if ($response) { +// log_message('error','yandex 1'); //分析YANDEX搜索结果,计算排名 - if (false !== stripos($response, '

302 Found

')) { + if (false !== stripos($response, '

302 Found

') || + false !== stripos($response, 'капчей') || false !== stripos($response, 'captcha')) { $rank['rank'] = -2; } elseif (false !== stripos($response, $site_url)) { - preg_match_all("/(.*)<\/a>/smUi", $response, $store); + preg_match_all("/
$v) { $start_s = stripos($v, $site_url); if (false !== $start_s) { @@ -449,217 +511,33 @@ class Keyworlds extends CI_Controller { } else { $rank['rank'] = -1; } - return $rank; - } - - //计算关键词在google搜索引擎的排名 - public function get_search_content_by_yahoo($keyworlds, $site_url, $page = 1, $sitecode = false) { - $rank['rank'] = 0; - $rank['source'] = $site_url; - $site_url_array = explode('//', $site_url); - $site_url = $site_url_array[1]; - $rank['engines'] = 'yahoo'; - if ($page > 3) { - $rank['rank'] = 151; - return $rank; - } - - //拼接关键词 - /* $key_array = explode(' ',$keyworlds); - $search_worlds=''; - foreach ($key_array as $v) { - $search_worlds.='+'.$v; - } - $search_worlds = substr($search_worlds,1); */ - $search_worlds = urlencode($keyworlds); - $yahoourl = 'http://search.yahoo.com'; - if ($sitecode == 'jp') - $yahoourl = 'http://search.yahoo.co.jp'; - - $start = ($page - 1) * 50 + 1; - $pstart = $page + 4; - - //抓取yahoo搜索结果 - $this->load->library('Snoopy'); - $snoopy = $this->snoopy; - $snoopy->maxredirs = 0; - $snoopy->agent = '(compatible; MSIE 9; MSN 8; AOL 4.0; Windows 98)'; //模拟浏览器 - if ($snoopy->fetch("$yahoourl/search;_ylt=A0SO8yDYHxBT6xQAWAFXNyoA?p=$search_worlds&n=100&ei=UTF-8&va_vt=any&vo_vt=any&ve_vt=any&vp_vt=any&vst=0&vf=all&vm=i&fl=0&fr=sfp&b=$start&pstart=$pstart")) { - $response = $snoopy->results; - //分析yahoo搜索结果,计算排名 - //出现被屏蔽情况 - if (false !== stripos($response, 'document has moved')) { - $rank['rank'] = -2; - } else { - preg_match_all('/
(.*)<\/ol>/smUi', $response, $search_c); - if (false !== stripos($search_c[0][0], $site_url)) { - preg_match_all('/
  • /smUi', $search_c[0][0], $store); - foreach ($store[1] as $k => $v) { - $ismatch = stripos($v, $site_url); - if (false !== $ismatch) { - //计算排名 - $rank['rank'] = $start + $k + 1; - //抓取关键词来源 - $end = stripos($v, '">', $ismatch); - $source = substr($v, $ismatch, $end); - $source = explode('">', $source); - $rank['source'] = 'http://' . $source[0]; - break; - } + // 移动端 + $response_m = $this->curl($url,"m",$refer); + if ($response_m) { + if (false !== stripos($response_m, '

    302 Found

    ') || + false !== stripos($response, 'капчей') || false !== stripos($response, 'captcha')) { + $rank['rank_m'] = -2; + } elseif (false !== stripos($response_m, $site_url)) { + preg_match_all('/
    $vm) { + $ismatch_m = stripos($vm, $site_url); + if (false !== $ismatch_m) { + //计算排名 + $rank['rank_m'] = $startrank + $km + 1; + //抓取关键词来源 + $end_m = strpos($vm, '"', $ismatch_m); + $source_m = substr($vm, $ismatch_m, $end_m); + $source_m = explode('"', $source_m); + $rank['source_m'] = $source_m[0]; + break; } } } } else { - $rank['rank'] = -1; - } - return($rank); - } - - //返回指定页面路径pagepath在指定时间内的成效信息 - public function get_analytics_by_date($loadtotal = 0) { - $data = array(); - //获取请求的日期范围以及请求的页面路径 - $startdate = $this->input->post('startdate'); - $enddate = $this->input->post('enddate'); - $pagepath = $this->input->post('pagepath'); - //如果开始时间为空则把开始时间设为往前七天 - if ($startdate == '') { - $startdate = time() - 7 * 24 * 60 * 60; - } else { - $startdate = strtotime($startdate); - } - //如果结束时间为空,则把结束时间设为当天 - if ($enddate == '') { - $enddate = time(); - } else { - $enddate = strtotime($enddate); - } - if ($startdate > $enddate) { - echo "请选择正确的日期"; - die(); - } - //查取google分析数据 - $data['analytics_list'] = $this->analytics_model->get_analytics_list($pagepath, 50, $startdate, $enddate); - $total_visit['pv'] = $total_visit['uv'] = $total_visit['agv_time'] = $total_visit['entrances'] = 0; - $analytics_count = 0; - //访问量汇总 - foreach ($data['analytics_list'] as $v) { - $total_visit['pv']+=$v->kwa_pageviews; - $total_visit['uv']+=$v->kwa_uniquepageviews; - $total_visit['agv_time']+=$v->kwa_avgtimeonpage; - $total_visit['entrances']+=$v->kwa_entrances; - $analytics_count++; - } - $analytics_count == 0 ? $analytics_count = 1 : null; - $total_visit['agv_time'] = ceil($total_visit['agv_time'] / $analytics_count); - $data['total_visit'] = $total_visit; - //如果loadtotal==1,则只返回google分析的汇总数据;如果loadtotal==0,则返回明细数据表 - $data['loadtotal'] = $loadtotal; - - $this->load->view('keyworlds/analytics', $data); - } + $rank['rank_m'] = -1; + } // ---- 移动端 end ---- - //从google分析接口获取数据并入库,$start_index:从接口提取数据时的起始条数 - public function get_google_analytics_data($sitecode = 'cht', $start_index = 1) { - session_start(); - //判断该站点是否已经更新. - $update_count = $this->analytics_model->get_update_count($sitecode); - $update_count; - $flag = false; - switch ($sitecode) { - case 'cht': - case 'jp': - case 'ct': - //对于以上三个站点如果数据库中存在的数量大于当前起始数,则表示该站点已经更新 - if ($update_count > $start_index) - $flag = true; - break; - default: - //对于其他站点如果数据库中存在的数量大于0,则表示该站点已经更新 - if ($update_count > 0) { - $flag = true; - } - } - //如果站点已经更新,则放弃从google分析抓取数据 - if ($flag) { - echo 'finished'; - exit(); - } - //初始化Google_Client - require_once APPPATH . 'libraries/Google_Client/Google_Client.php'; - require_once APPPATH . 'libraries/Google_Client/contrib/Google_AnalyticsService.php'; - $baseurl = site_url("Keyworlds/get_google_analytics_data/"); - $revokeUrl = $baseurl . '?action=revoke'; - - //google分析接口过滤条件 - $site_config = array('cht' => 5120, 'gm' => 6028186, 'vc' => 68571571, 'vac' => 68484932, 'ru' => 68577400, 'it' => 68564185, 'jp' => 574459, 'tbt' => 715050, 'sht' => 4705635, 'yz' => 68484504, 'gl' => 68460695, 'mbj' => 68479244, 'ct' => 8567691); - $profileId = $site_config[$sitecode]; //网站标志ID - $analytics_start_time = date('Y-m-d', time() - 7 * 24 * 60 * 60); //获取数据的开始时间 - $analytics_end_time = date('Y-m-d', time()); //获取数据的结束时间 - //授权设置 - $client = new Google_Client(); - $client->setClientId('50804699713-l5sfpffqpo4kbrbhk9tf53049labr214.apps.googleusercontent.com'); - $client->setClientSecret('_IpQ8Qi1QFlogmxiMhIRHgEa'); - $client->setRedirectUri('http://localhost:9999/info.php/Keyworlds/get_google_analytics_data'); - $client->setApplicationName('Google Analytics Application'); - $client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly')); - $client->setUseObjects(true); - $client->setAccessType('offline'); - - //解除授权 - if (isset($_GET['action']) && $_GET['action'] == 'revoke') { - $accessToken = $_SESSION['access_token']; - if ($accessToken) { - $tokenObj = json_decode($accessToken); - $client->revokeToken($tokenObj->refresh_token); - unset($_SESSION['access_token']); - } - header("Location: $baseurl"); - } - //获取授权 - if (isset($_SESSION['access_token'])) { - $accessToken = $_SESSION['access_token']; - $client->setAccessToken($accessToken); - } else { - //授权过期重新生成access_token - $client->refreshToken('1/ZX7Qo-m_rxIL1_LqE8vM2sYKATkAJxm0Fc5g7BRXeo0'); - $_SESSION['access_token'] = $client->getAccessToken(); - //$accessToken = $client->authenticate(); - //$_SESSION['access_token'] = $accessToken; - } - - //获取数据 - if ($client->getAccessToken()) { - $analytics = new Google_AnalyticsService($client); - //获取详细信息 - $results = $analytics->data_ga->get( - 'ga:' . $profileId, $analytics_start_time, $analytics_end_time, 'ga:visits', array( - 'dimensions' => 'ga:pagePath,ga:source,ga:keyword', - 'metrics' => 'ga:pageviews,ga:uniquePageviews,ga:avgTimeOnPage,ga:entrances,ga:exitRate,ga:pageValue', - 'sort' => '-ga:pageviews', - 'max-results' => '10000', - 'start-index' => $start_index - ) - ); - } - $_SESSION['access_token'] = $client->getAccessToken(); - - $columnheader = array('pagepath', 'source', 'keyword', 'pv', 'uv', 'avgtimeonpage', 'entrances', 'exitrate', 'pageValue'); - $output = array(); - $txt = ''; - foreach ($results->getRows() as $row) { - foreach ($row as $i => $cell) { - $table[$columnheader[$i]] = htmlspecialchars($cell, ENT_NOQUOTES); - } - $txt.=$table['source'] . '|@|' . $table['pv'] . '|@|' . $table['uv'] . '|@|' . $table['avgtimeonpage'] . '|@|' . $table['entrances'] . '|@|' . $table['exitrate'] . '|@|' . $table['pageValue'] . '|@|' . time() . '|@|' . $sitecode . '|@|' . $table['pagepath'] . '|@|' . substr($table['keyword'], 0, 255) . "\r\n"; - $output[] = $table; - unset($table); - } - $fp = fopen(APPPATH . 'helpers/analytics_data.txt', 'wb'); - fwrite($fp, $txt); - fclose($fp); - $this->analytics_model->add_analytics_by_txt(); - echo $sitecode; + return $rank; } //从cvs文件导入关键词 @@ -669,8 +547,8 @@ class Keyworlds extends CI_Controller { if (($handle = fopen($filename, "r")) !== false) { while (($dataSrc = fgetcsv($handle)) !== false) { $num = count($dataSrc); - for ($c = 0; $c < $num; $c++) {//列 column - if ($row === 1) {//第一行作为字段 + for ($c = 0; $c < $num; $c++) {//列 column + if ($row === 1) {//第一行作为字段 $dataName[] = $dataSrc[$c]; //字段名称 } else { foreach ($dataName as $k => $v) { @@ -864,4 +742,45 @@ class Keyworlds extends CI_Controller { echo $html; } + protected function curl($url, $useragent = 'PC', $referer = false) { + if ($useragent == 'PC') { + $useragent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22"; + } else { + $useragent = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Mobile Safari/537.36"; + } + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_FAILONERROR, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + // curl_setopt($ch, CURLOPT_SSLVERSION, 1); // 2,3 + // curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_SSLv3'); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_USERAGENT, $useragent); + curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME); + curl_setopt($ch, CURLOPT_PROXY, "202.103.68.28:11111"); + if ($referer) { + curl_setopt($ch, CURLOPT_REFERER, $referer); + } + + $headers = array('content-type: application/x-www-form-urlencoded;charset=UTF-8'); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + + $reponse = curl_exec($ch); + + if (curl_errno($ch)) { + log_message('error', "search engines curl error code: ".curl_error($ch).";"); + } else { + $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if (200 !== $httpStatusCode) { + log_message('error', "search engines Request html Status Code: ".$httpStatusCode.";"); + } + } + curl_close($ch); + return $reponse; + } + } diff --git a/application/models/infokeywordsrank_model.php b/application/models/infokeywordsrank_model.php index 213749de..6629f407 100644 --- a/application/models/infokeywordsrank_model.php +++ b/application/models/infokeywordsrank_model.php @@ -9,27 +9,31 @@ class infoKeywordsrank_model extends CI_Model } //添加关键词排名 - public function add_rank($kwr_kw_id,$kwr_rank,$kwr_source,$kwr_engines) + public function add_rank($kwr_kw_id,$kwr_rank,$kwr_mobile_rank,$kwr_source,$kwr_mobile_source,$kwr_engines) { $sql = "INSERT INTO infoKeywordsrank ( kwr_kw_id, kwr_rank, + kwr_mobile_rank, kwr_source, + kwr_mobile_source, kwr_datetime, kwr_engines - ) VALUES (?,?,?,?,?)"; - $query = $this->HT->query($sql, array($kwr_kw_id,$kwr_rank,$kwr_source,time(),$kwr_engines)); + ) VALUES (?,?,?,?,?,?,?)"; + $query = $this->HT->query($sql, array($kwr_kw_id,$kwr_rank,$kwr_mobile_rank,$kwr_source,$kwr_mobile_source,time(),$kwr_engines)); return $this->HT->last_id('infoKeywordsrank'); } //更新关键词排名 - public function update_rank($kwr_id,$rank,$source){ + public function update_rank($kwr_id,$rank,$mobile_rank,$source,$mobile_source){ $set_sql = "UPDATE infoKeywordsrank SET kwr_datetime = ?, kwr_rank=?, - kwr_source=? + kwr_mobile_rank=?, + kwr_source=?, + kwr_mobile_source=? WHERE kwr_id = ?"; - $result=$this->HT->query($set_sql, array(time(),$rank,$source,$kwr_id)); + $result=$this->HT->query($set_sql, array(time(),$rank,$mobile_rank,$source,$mobile_source,$kwr_id)); return $result; } @@ -43,10 +47,12 @@ class infoKeywordsrank_model extends CI_Model }else{ $topmap= "TOP $top"; } - $sql = "SELECT $topmap kwr_id, + $sql = "SELECT $topmap kwr_id, kwr_kw_id, kwr_rank, + kwr_mobile_rank, kwr_source, + kwr_mobile_source, kwr_engines, kwr_datetime, kw_keyworlds @@ -71,4 +77,4 @@ class infoKeywordsrank_model extends CI_Model $query = $this->HT->query($sql, array($kwr_id)); return $query; } -} \ No newline at end of file +} diff --git a/application/views/keyworlds/index.php b/application/views/keyworlds/index.php index 2a9365b5..b161c433 100644 --- a/application/views/keyworlds/index.php +++ b/application/views/keyworlds/index.php @@ -31,7 +31,7 @@
  • - +
    kw_is_id"); ?>">
    @@ -48,53 +48,28 @@ # 时间 - 来源 - 排名 + 来源(PC/Mobile) + 排名(PC/Mobile) - $rank) { ?> + $rank) { ?> - + kwr_datetime); ?> - kwr_source; ?> - kwr_rank; ?> + + kwr_source; ?> +
    + kwr_mobile_source; ?> + + kwr_rank; ?> --  + kwr_mobile_rank ? $rank->kwr_mobile_rank : '未抓取'; echo $kwr_mobile_rank; ?>

    - - - 访问量明细 - - - - - - - - - - - - - - $a) { ?> - - - - - - - - - - - -
    #时间路径PVUV平均停留时间跳出率
    kwa_datetime-7*24*60*60); ?>kwa_pagepath; ?>kwa_pageviews; ?>kwa_uniquepageviews; ?>kwa_avgtimeonpage,1); ?>kwa_exitrate,1); ?>%
    -
    @@ -252,12 +227,12 @@ } //选择节点 var node = zTree.getNodeByParam("id",kw_is_id; ?>); - zTree.selectNode(node); + zTree.selectNode(node); $("#startdate,#enddate").datepicker({ showButtonPanel: true, dateFormat:'yy-mm-dd' - }); + }); }); //删除结构和信息 @@ -353,7 +328,7 @@ categories: , labels: {rotation: -45,align: 'right'} }, - yAxis: {title: {text: '关键词排名'}}, + yAxis: {title: {text: '关键词排名'},reversed:true,allowDecimals:false}, tooltip: { enabled: true, formatter: function() { @@ -389,4 +364,4 @@ }); - \ No newline at end of file +