@ -3,11 +3,9 @@
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Keyworlds extends CI_Controller
{
class Keyworlds extends CI_Controller {
function __construct()
{
function __construct() {
parent::__construct();
$this->permission->is_admin(false);
$this->load->model('InfoKeywords_model', 'Keywords_model');
@ -16,8 +14,7 @@ class Keyworlds extends CI_Controller
$this->load->model('InfoStructures_model');
}
public function index($kw_is_id='')
{
public function index($kw_is_id = '') {
$this->load->library('Accesscheck');
$this->accesscheck->check_access();
@ -41,8 +38,10 @@ class Keyworlds extends CI_Controller
$today = date('Y-m-d', time());
$startdate = strtotime("$today -1 month");
$enddate = time();
if($this->input->post('startdate')!='')$startdate=strtotime($this->input->post('startdate'));
if($this->input->post('enddate')!='')$enddate=strtotime($this->input->post('enddate'));
if ($this->input->post('startdate') != '')
$startdate = strtotime($this->input->post('startdate'));
if ($this->input->post('enddate') != '')
$enddate = strtotime($this->input->post('enddate'));
//查询当前关键词的排名情况
$data['rank_json'] = '';
@ -63,7 +62,8 @@ class Keyworlds extends CI_Controller
$is_id_string = $data['current_keyworld']->kw_id;
$i = 0;
foreach ($data['keyworldsList'] as $kw) {
if ($i>9) break;
if ($i > 9)
break;
if ($kw->pId == $kw_is_id) {
$is_id_string.=',' . $kw->kw_id;
$i++;
@ -77,14 +77,16 @@ class Keyworlds extends CI_Controller
asort($rank_info);
$data_time = array();
foreach ($rank_info as $key => $r) {
if(!in_array(date('Y-m-d',$r->kwr_datetime), $data_time)) $data_time[] = date('Y-m-d',$r->kwr_datetime);
if (!in_array(date('Y-m-d', $r->kwr_datetime), $data_time))
$data_time[] = date('Y-m-d', $r->kwr_datetime);
$rank_json[$r->kwr_kw_id][date('Y-m-d', $r->kwr_datetime)] = $r;
$rank_json2[$r->kwr_kw_id][] = $r;
}
foreach ($data_time as $d) {
foreach ($rank_json as $kw_id => & $value) {
if(!isset($pre[$kw_id])) $pre[$kw_id]=$rank_json2[$kw_id][0];
if (!isset($pre[$kw_id]))
$pre[$kw_id] = $rank_json2[$kw_id][0];
if (!isset($value[$d])) {
$value[$d] = $pre[$kw_id];
} else {
@ -98,7 +100,8 @@ class Keyworlds extends CI_Controller
$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') $kwr_rank=100;
if ($v->kwr_rank == '>150')
$kwr_rank = 100;
if (strtolower($this->config->item('site_code')) == 'gm') {
$data['rank_json'] .=-$kwr_rank . ',';
} else {
@ -128,8 +131,7 @@ class Keyworlds extends CI_Controller
//搜索关键词
public function search_keywords() {
$keyworlds = $this->input->post('keyworlds');
if (empty($keyworlds))
{
if (empty($keyworlds)) {
echo 0;
return;
}
@ -139,8 +141,7 @@ class Keyworlds extends CI_Controller
}
//添加关键词
public function add($is_parent_id,$is_ajax=true)
{
public function add($is_parent_id, $is_ajax = true) {
$insert_id = $this->InfoStructures_model->Add($is_parent_id);
if ($insert_id & & $kw_id = $this->Keywords_model->add_keyworlds('New Keywords', $this->config->item('site_code'), time(), $insert_id)) {
$data[] = array('name' => 'ok', 'value' => $this->Keywords_model->get_keyworld($kw_id));
@ -158,16 +159,13 @@ class Keyworlds extends CI_Controller
public function edit() {
$this->form_validation->set_rules('keyworlds', 'lang:kw_keyworlds', 'required');
$this->form_validation->set_rules('kw_id', 'lang:kw_id', 'required');
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$data = array();
foreach ($this->form_validation->_error_array as $key => $value)
{
foreach ($this->form_validation->_error_array as $key => $value) {
$data[] = array('name' => $key, 'value' => $value);
}
echo json_encode($data);
}else
{
} else {
$isupdate = $this->Keywords_model->edit_keyworlds($this->input->post('keyworlds'), $this->input->post('kw_id'), $this->input->post('status'));
if ($isupdate) {
$data[] = array('name' => 'ok', 'value' => $this->lang->line('form_keyworlds_success'));
@ -189,16 +187,13 @@ class Keyworlds extends CI_Controller
public function delete_keyworlds() {
$this->form_validation->set_rules('kw_id', 'lang:kw_id', 'required');
$this->form_validation->set_rules('kw_is_id', 'lang:kw_is_id', 'required');
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$data = array();
foreach ($this->form_validation->_error_array as $key => $value)
{
foreach ($this->form_validation->_error_array as $key => $value) {
$data[] = array('name' => $key, 'value' => $value);
}
echo json_encode($data);
}else
{
} else {
$isdelete = $this->Keywords_model->delete($this->input->post('kw_id'));
if ($isdelete) {
$this->Keywordsrank_model->delete($this->input->post('kw_id'));
@ -213,16 +208,13 @@ class Keyworlds extends CI_Controller
}
//移动关键词排序顺序
public function move()
{
public function move() {
//网站会提交一个同级节点id列表字符串, 按照这个去排序
$parent_id = $this->input->post('pid');
$idsStr = $this->input->post('ids');
$idsArray = explode(',', $idsStr);
foreach ($idsArray as $key => $value)
{
if ($value)
{
foreach ($idsArray as $key => $value) {
if ($value) {
//设置排序
$this->InfoStructures_model->set_sort($value, $key);
//设置path
@ -234,8 +226,7 @@ class Keyworlds extends CI_Controller
return TRUE;
}
public function get_google_rank()
{
public function get_google_rank() {
$keyworlds = $this->input->post('keyworlds'); //搜索关键字
$kw_id = $this->input->post('kw_id');
$site_url = $this->config->item('site_url');
@ -246,8 +237,10 @@ class Keyworlds extends CI_Controller
$site_code = $this->config->item('site_code');
$method = $engines[$site_code];
if($site_code=='wt')$site_url='www.iiiyooo.com';
if($site_code=='cits')$site_url='www.guilincits.c';
if ($site_code == 'wt')
$site_url = 'www.iiiyooo.com';
if ($site_code == 'cits')
$site_url = 'www.guilincits.c';
$last_rank = $this->Keywordsrank_model->get_rank_list($kw_id, $top = 1);
if (isset($last_rank[0]->kwr_datetime) and ( time() - $last_rank[0]->kwr_datetime) < 300 ) {
@ -261,7 +254,8 @@ class Keyworlds extends CI_Controller
$j = $i;
$rank = $this->$method($keyworlds, $site_url, $j, $site_code);
if ($rank['rank'] != 0) {
if ($rank['rank']>150) $rank['rank'] = '151';
if ($rank['rank'] > 150)
$rank['rank'] = '151';
break;
}elseif ($i == 15) {
$rank['rank'] = '151';
@ -288,65 +282,38 @@ class Keyworlds extends CI_Controller
}
//自动爬取排名
public function get_auto_rank($engines=''){
public function get_auto_rank($engines = '', $fix_site_code = '') {
$rank = array();
$site_config = $this->config->item('site');
$engines = trim($engines);
//取出需要更新排名的关键词
if ($engines==''){
$worldsList = $this->Keywords_model->get_keyworld_list(1);
}else{
$worldsList = $this->Keywords_model->get_keyworld_list(1,$engines);
}
$worldsList = $this->Keywords_model->get_keyworld_list(1, $engines, $fix_site_code);
//print_r($worldsList);die();
//如果没有需要更新的则返回
if (empty($worldsList))
{
if (empty($worldsList)) {
echo 'all done';
return;
}
$last_rank = $this->Keywordsrank_model->get_rank_list($worldsList[0]->kw_id);
//获取排名并保存
foreach ($worldsList as $v)
{
foreach ($worldsList as $v) {
$site_config = $site_config[$v->kw_sitecode];
$site_url = $site_config['site_url'];
$site_code = $site_config['site_code'];
for ($i = 1; $i < = 15; $i++) {
//没有输入搜索引擎的时候根据站点自动分配获取排名的搜索引擎
if($engines=='' || $engines=='en' || $engines=='eu')
{
if (in_array($v->kw_sitecode,array('gm','vc','vac','it','ru','jp'))) {
if ($engines == '' || $engines == 'en' || $engines == 'eu') {//没有输入搜索引擎的时候根据站点自动分配获取排名的搜索引擎
$rank = $this->get_search_content_by_google($v->kw_keyworlds, $site_url, $i, $site_code);
}
//elseif ($v->kw_sitecode=='jp') {
// $rank = $this->get_search_content_by_yahoo($v->kw_keyworlds,$site_url,$i,$site_code);
//}
/*elseif ($v->kw_sitecode=='ru') {
$rank = $this->get_search_content_by_yandex($v->kw_keyworlds,$site_url,$i-1);
}*/
elseif($v->kw_sitecode=='cits' or $v->kw_sitecode=='wt'){
if($site_code=='wt')$site_url='www.iiiyooo.com';
$rank = $this->get_search_content_by_baidu($v->kw_keyworlds,$site_url,$i);
}else{
//$rank = $this->get_search_content_by_aol($v->kw_keyworlds,$site_url,$i);
$rank = $this->get_search_content_by_google($v->kw_keyworlds,$site_url,$i,$site_code);
}
}
elseif ($engines=='baidu') {
if($site_code=='wt')$site_url='www.iiiyooo.com';
$rank = $this->get_search_content_by_baidu($v->kw_keyworlds,$site_url,$i);
}
//俄语站的yangdex
else if ($engines=='yandex')
{
} 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) {
if ($rank['rank']>150) $rank['rank'] = '151';
if ($rank['rank'] > 150)
$rank['rank'] = '151';
break;
}elseif ($i == 15) {
$rank['rank'] = '151';
@ -355,75 +322,20 @@ class Keyworlds extends CI_Controller
}
}
//if ($rank['rank'] == '151') {
if (1==2) {
if ($engines!='yandex') $this->Keywords_model->update_time($v->kw_id);
}elseif ($rank['rank']!=-1 and $rank['rank']!=-2 and $this->Keywordsrank_model->add_rank($v->kw_id,$rank['rank'],$rank['source'],$rank['engines'])) {
if ($rank['rank'] != -1 and $rank['rank'] != -2 and $this->Keywordsrank_model->add_rank($v->kw_id, $rank['rank'], $rank['source'], $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');
$this->InfoSMS_model->add('keywords_rank', $v->kw_id, $rank['rank'], $last_rank, (string) ($rank['rank'] - $last_rank));
if ($engines!='yandex') $this->Keywords_model->update_time($v->kw_id);
if ($engines != 'yandex')
$this->Keywords_model->update_time($v->kw_id);
}
}
var_dump($worldsList[0]->kw_keyworlds, $rank);
}
//计算关键词在aol搜索引擎的排名
public function get_search_content_by_aol($keyworlds,$site_url,$page,$sitecode=false)
{
$rank['rank'] = 0;
$rank['source'] = $site_url;
$rank['engines'] = 'aol';
$startrank=($page-1)*10;
//拼接关键词
$key_array = explode(' ',$keyworlds);
$search_worlds='';
foreach ($key_array as $v) {
$search_worlds.='+'.$v;
}
$search_worlds = substr($search_worlds,1);
//抓取AOL搜索结果
$this->load->library('Snoopy');
$snoopy = $this->snoopy;
$snoopy->maxredirs=0;
$snoopy->agent = '(Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:20.0) Gecko/20100101 Firefox/20.0)';//模拟浏览器
if($snoopy->fetch("http://search.aol.com/aol/search?s_chn=prt_ct8& s_it=comsearch& q=$search_worlds& page=$page& s_it=topsearchbox.search"))
{
$response = $snoopy->results;
//分析AOL搜索结果, 计算排名
if (false !== stripos($response,'< title > 302 Found< / title > ')) {
$rank['rank'] = -2;
}
elseif (false !== stripos($response,$site_url))
{
preg_match_all("/class=\"find\"(.*)< \/a>/smUi",$response, $store);
foreach ($store[1] as $k=>$v) {
$start_s=stripos($v,$site_url);
if (false!==$start_s) {
$rank['rank'] = $startrank+$k+1;
$end_s=strpos($v,'" ',$start_s);
$source = substr($v, $start_s, $end_s);
$sources = explode('" ',$source);
$rank['source']=$sources[0];
break;
}
}
}
}
else
{
$rank['rank'] = -1;
}
return $rank;
}
//计算关键词在google搜索引擎的排名
public function get_search_content_by_google($keyworlds,$site_url,$page,$site_code)
{
public function get_search_content_by_google($keyworlds, $site_url, $page, $site_code) {
$rank['rank'] = 0;
$rank['source'] = $site_url;
$rank['engines'] = 'google';
@ -452,19 +364,20 @@ class Keyworlds extends CI_Controller
'it' => 'google.it',
'jp' => 'google.co.jp'
);
if(!empty($google_domain[$site_code])) $google_url= $google_domain[$site_code];
if (!empty($google_domain[$site_code]))
$google_url = $google_domain[$site_code];
//搜索使用的语种,默认是英语
$language = 'en';
$language_array = array('gm' => 'de', 'vc' => 'fr', 'vac' => 'es', 'ru' => 'ru', 'it' => 'it', 'jp' => 'jp');
if(!empty($language_array[$site_code])) $language = $language_array[$site_code];
if (!empty($language_array[$site_code]))
$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"))
{
if ($snoopy->fetch("http://www.$google_url/search?q=$search_worlds& start=$start& num=50& hl=$language")) {
$response = $snoopy->results;
//分析google搜索结果, 计算排名
if (false !== stripos($response, '< h1 > 302 Moved< / h1 > ')) {
@ -485,9 +398,7 @@ class Keyworlds extends CI_Controller
}
}
}
}
else
{
} else {
$rank['rank'] = -1;
}
@ -500,8 +411,7 @@ class Keyworlds extends CI_Controller
}
//计算关键词在yandex搜索引擎的排名
public function get_search_content_by_yandex($keyworlds,$site_url,$page=0,$sitecode=false)
{
public function get_search_content_by_yandex($keyworlds, $site_url, $page = 0, $sitecode = false) {
$rank['rank'] = 0;
$rank['source'] = $site_url;
$rank['engines'] = 'yandex';
@ -516,8 +426,7 @@ class Keyworlds extends CI_Controller
//$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"))
{
if ($snoopy->fetch("http://www.yandex.ru/yandsearch?p=$page& text=$search_worlds& lr=21436")) {
$response = $snoopy->results;
//分析YANDEX搜索结果, 计算排名
if (false !== stripos($response, '< h1 > 302 Found< / h1 > ')) {
@ -536,17 +445,14 @@ class Keyworlds extends CI_Controller
}
}
}
}
else
{
} else {
$rank['rank'] = -1;
}
return $rank;
}
//计算关键词在google搜索引擎的排名
public function get_search_content_by_yahoo($keyworlds,$site_url,$page=1,$sitecode=false)
{
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);
@ -566,7 +472,8 @@ class Keyworlds extends CI_Controller
$search_worlds = substr($search_worlds,1); */
$search_worlds = urlencode($keyworlds);
$yahoourl = 'http://search.yahoo.com';
if($sitecode=='jp') $yahoourl='http://search.yahoo.co.jp';
if ($sitecode == 'jp')
$yahoourl = 'http://search.yahoo.co.jp';
$start = ($page - 1) * 50 + 1;
$pstart = $page + 4;
@ -576,8 +483,7 @@ class Keyworlds extends CI_Controller
$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"))
{
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搜索结果, 计算排名
//出现被屏蔽情况
@ -602,74 +508,12 @@ class Keyworlds extends CI_Controller
}
}
}
}
else
{
} else {
$rank['rank'] = -1;
}
return($rank);
}
//计算关键词在百度搜索引擎的排名
public function get_search_content_by_baidu($keyworlds,$site_url='www.guilincits.com',$page=1,$sitecode=false)
{
$rank['rank'] = 0;
$rank['source'] = $site_url;
$rank['engines'] = 'baidu';
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);
$start = ($page -1) * 50;
//抓取百度搜索结果
$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("http://www.baidu.com/s?wd=$search_worlds& pn=$start& rn=50& ie=utf-8"))
{
$response = $snoopy->results;
if (false !== stripos($response,$site_url)) {
preg_match_all('/result c-container(.*)< div class = \"c-tools\"/smUi',$response, $ store ) ;
foreach ($store[1] as $k=>$v) {
if (false !== stripos($v,$site_url)) {
//计算排名
$rank['rank'] = $start+$k+1;
//抓取关键词来源
preg_match_all('/url=(.*)\"/smUi',$v, $source_array);
$rank_source = 'http://www.baidu.com/link?url='.$source_array[1][0];
$rank['source']=$rank_source;
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_NOBODY, 1); // 输出中包含body部分
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 设置超时防止死循环
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);// 使用自动跳转
curl_setopt($ch, CURLOPT_URL,$rank_source); // 想要获取内容的url
curl_exec ($ch);
$rank_source=curl_getinfo($ch);
$rank['source']=$rank_source['redirect_url'];
curl_close ($ch);
break;
}
}
}
}
else
{
$rank['rank'] = -1;
}
return $rank;
}
//返回指定页面路径pagepath在指定时间内的成效信息
public function get_analytics_by_date($loadtotal = 0) {
$data = array();
@ -690,7 +534,8 @@ class Keyworlds extends CI_Controller
$enddate = strtotime($enddate);
}
if ($startdate > $enddate) {
echo "请选择正确的日期";die();
echo "请选择正确的日期";
die();
}
//查取google分析数据
$data['analytics_list'] = $this->analytics_model->get_analytics_list($pagepath, 50, $startdate, $enddate);
@ -720,13 +565,13 @@ class Keyworlds extends CI_Controller
$update_count = $this->analytics_model->get_update_count($sitecode);
$update_count;
$flag = false;
switch ($sitecode)
{
switch ($sitecode) {
case 'cht':
case 'jp':
case 'ct':
//对于以上三个站点如果数据库中存在的数量大于当前起始数,则表示该站点已经更新
if ($update_count>$start_index) $flag = true;
if ($update_count > $start_index)
$flag = true;
break;
default:
//对于其他站点如果数据库中存在的数量大于0, 则表示该站点已经更新
@ -750,7 +595,6 @@ class Keyworlds extends CI_Controller
$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');
@ -784,16 +628,11 @@ class Keyworlds extends CI_Controller
}
//获取数据
if ($client->getAccessToken())
{
if ($client->getAccessToken()) {
$analytics = new Google_AnalyticsService($client);
//获取详细信息
$results = $analytics->data_ga->get(
'ga:' . $profileId,
$analytics_start_time,
$analytics_end_time,
'ga:visits',
array(
'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',
@ -807,8 +646,7 @@ class Keyworlds extends CI_Controller
$columnheader = array('pagepath', 'source', 'keyword', 'pv', 'uv', 'avgtimeonpage', 'entrances', 'exitrate', 'pageValue');
$output = array();
$txt = '';
foreach ($results->getRows() as $row)
{
foreach ($results->getRows() as $row) {
foreach ($row as $i => $cell) {
$table[$columnheader[$i]] = htmlspecialchars($cell, ENT_NOQUOTES);
}
@ -824,27 +662,18 @@ class Keyworlds extends CI_Controller
}
//从cvs文件导入关键词
public function hand_add($parentid,$bookname)
{
public function hand_add($parentid, $bookname) {
$row = 1; //第一行开始
$filename = APPPATH . $bookname . '.csv';
if(($handle = fopen($filename, "r")) !== false)
{
while(($dataSrc = fgetcsv($handle)) !== false)
{
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)
{
if($k == $c)//对应的字段
{
} else {
foreach ($dataName as $k => $v) {
if ($k == $c) {//对应的字段
$dataRtn[$v] = @iconv('GBK', 'UTF-8', $dataSrc[$c]);
}
}
@ -882,7 +711,8 @@ class Keyworlds extends CI_Controller
//页面url
$embody = $embody[0];
if($embody->ic_url=='') return false;
if ($embody->ic_url == '')
return false;
$site = $this->config->item('site');
$site_url = $site[$embody->ic_sitecode]['site_url'];
$site_url = $site_url . $embody->ic_url;
@ -892,7 +722,8 @@ class Keyworlds extends CI_Controller
$google_url = 'google.com';
$language = 'en';
$language_array = array('gm' => 'de', 'vc' => 'fr', 'vac' => 'es', 'ru' => 'ru', 'it' => 'it', 'jp' => 'jp');
if(!empty($language_array[$embody->ic_sitecode])) $language = $language_array[$embody->ic_sitecode];
if (!empty($language_array[$embody->ic_sitecode]))
$language = $language_array[$embody->ic_sitecode];
//抓取google搜索结果
@ -900,8 +731,7 @@ class Keyworlds extends CI_Controller
$snoopy = $this->snoopy;
$snoopy->maxredirs = 0;
$snoopy->agent = '(compatible; MSIE 9; MSN 8; AOL 4.0; Windows 98)'; //模拟浏览器
if($snoopy->fetch("http://www.$google_url/search?q=$search_worlds& start=0& num=10& hl=$language"))
{
if ($snoopy->fetch("http://www.$google_url/search?q=$search_worlds& start=0& num=10& hl=$language")) {
$response = $snoopy->results;
if (false !== stripos($response, '< h1 > 302 Moved< / h1 > ')) {
echo 302;
@ -933,8 +763,7 @@ class Keyworlds extends CI_Controller
}
//定时批量更新CDN
public function update_cdn()
{
public function update_cdn() {
$this->load->model('Logs_model');
$last_update = $this->Logs_model->get_last_cdn_update_info();
if (empty($last_update)) {
@ -994,8 +823,7 @@ class Keyworlds extends CI_Controller
var_dump($notice);
}
public function mobile_friendly_test()
{
public function mobile_friendly_test() {
set_time_limit(60);
$url = $this->input->post('pageurl');
$googleapis = 'https://www.googleapis.com/pagespeedonline/v3beta1/mobileReady?url=' . $url;
@ -1022,8 +850,7 @@ class Keyworlds extends CI_Controller
$title = '请求超时,请稍后再试!';
$link_color = 'text-error';
$data['score'] = '-';
}
elseif ($data['pass']) {
} elseif ($data['pass']) {
$pass_text = 'OK';
$link_color = 'text-info';
$title = 'Awesome! This page is mobile-friendly (友好度' . $data['score'] . ', 总分100分)';
@ -1035,4 +862,5 @@ class Keyworlds extends CI_Controller
$html = '< a title = "' . $title . '" class = "' . $link_color . '" target = "__blank" href = "https://developers.google.com/speed/pagespeed/insights/?utm_source=analytics&tab=mobile&url=' . $data['pageurl'] . '" > < span > ' . $pass_text . ',友好度:' . $data['score'] . '< / span > < / a > ';
echo $html;
}
}