public function __construct() { parent::__construct(); $this->controller_name = CONTROLLER_NAME; $this->action_name = ACTION_NAME; //读取配置信息 $web_stting = F('setting'); if ($web_stting === false) { $params = array(); $list = M('Setting')->getField('name,value'); foreach ($list as $key => $val) { $params[$key] = unserialize($val) ? unserialize($val) : $val; } F('setting', $params); $web_stting = F('setting'); } $this->assign('web_stting', $web_stting); //站点状态判断 if ($web_stting['site_status'] != 1) { echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; echo $web_stting['closed_reason']; exit; } else { /* $link = M('Link')->where(array('status'=>1))->order('sort DESC')->select(); $this->assign('link',$link); */ $this->mid = session('member_id'); $this->assign('seo', seo()); $this->about = M('SystemArticle')->where(array('ac_type' => 'about'))->order('article_sort desc')->select(); $this->service = M('SystemArticle')->where(array('ac_type' => 'service'))->order('article_sort desc')->select(); $this->article_class = M('ArticleClass')->where(array('ac_parent_id' => 0))->order('ac_sort desc')->select(); $this->ip_info = get_ip_info(get_client_ip(), 2); /*$ip = new Ip(); $this->ip_info = $ip->find(get_client_ip()); if ($this->ip_info[0] != '中国' || $this->ip_info[1] != '香港' || $this->ip_info[1] != '澳门' || $this->ip_info[1] != '台湾') { $this->in_gfw = 0; }else { $this->in_gfw = 1; }*/ } }
/** * 测试 * * @author mrmsl <*****@*****.**> * @date 2013-07-16 11:52:29 * * @return void 无返回值 */ public function testAction() { !APP_DEBUG && exit('Access Denied'); set_time_limit(0); $model = $this->_model; $db = $model->getDb(); if (isset($_GET['getIp'])) { //重新获取ip地址信息 static $ip_result = array(); $c = ''; $comment_arr = $model->field('user_ip,comment_id')->table('tb_comments')->select(); foreach ($comment_arr as $comment_info) { $user_ip = $comment_info['user_ip']; if (isset($ip_result[$user_ip])) { $data = $ip_result[$user_ip]; } else { $ip_info = get_ip_info($user_ip); //ip地址信息 if (is_array($ip_info)) { $data = array('province' => $ip_info[0], 'city' => $ip_info[1]); } else { $data = array('city' => $ip_info); } $ip_result[$user_ip] = $data; } $db->update($data, array('table' => TB_COMMENTS, 'where' => 'comment_id=' . $comment_info['comment_id'])); } return; } //end if $model->startTrans(); $blog_arr = $model->table('tb_blog_laruence')->order('add_time ASC')->select(); foreach ($blog_arr as $blog_info) { $blog_id = $blog_info['blog_id']; unset($blog_info['blog_id']); $blog_info['title'] = html_entity_decode($blog_info['title']); $blog_info['content'] = trim($blog_info['content']); $blog_info['summary'] = trim($blog_info['summary']); if ($db->insert($blog_info, array('table' => TB_BLOG))) { $insert_id = $model->getLastInsertID(); $model->save(array($this->_pk_field => $insert_id, 'link_url' => BASE_SITE_URL . 'blog/' . date('Ymd/', $blog_info['add_time']) . $insert_id . C('HTML_SUFFIX'))); $model->addTags($insert_id, $blog_info['seo_keyword']); //评论 $comment_arr = $model->table('tb_comments_laruence')->order('add_time ASC')->where('blog_id=' . $blog_id)->select(); foreach ($comment_arr as $comment_info) { unset($comment_info['comment_id']); $comment_info['username'] = htmlspecialchars_decode($comment_info['username'], ENT_QUOTES); $comment_info['user_ip'] = sprintf('%u', ip2long($comment_info['node'])); $comment_info['blog_id'] = $insert_id; $db->insert($comment_info, array('table' => TB_COMMENTS)); } } } $db->query('UPDATE ' . TB_COMMENTS . ' SET node=comment_id'); $model->commit(); }
// пример использования $ipinfo = get_ip_info($ip); //echo $ipinfo->city; // город //$ipinfo->city = "Санкт-Петербург"; // пример использования //echo $_SERVER["REMOTE_ADDR"]; //$ipinfo = get_ip_info($_SERVER['REMOTE_ADDR']); $ipAddress = $_SERVER['REMOTE_ADDR']; if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $ipAddress = array_pop($arr); } if ($ipAddress = "127.0.0.1") { $ipAddress = "78.25.120.1"; } $ipinfo = get_ip_info($ipAddress); //print_r($ipinfo); //echo $ipinfo->region; // регион //echo $ipinfo->district; // федеральный округ РФ if ($ip == "127.0.0.1") { $ipinfo->city = "LOCALHOST"; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- The above 2 meta tags *must* come first in the head; any other head content must come *after* these tags --> <meta name="description" content=""> <meta name="author" content="">
{ $postData = "\n <ipquery>\n <fields>\n <all/>\n </fields>\n <ip-list>\n <ip>{$ip}</ip>\n </ip-list>\n </ipquery>\n "; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://194.85.91.253:8090/geo/geo.html'); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); curl_setopt($curl, CURLOPT_TIMEOUT, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $responseXml = curl_exec($curl); curl_close($curl); if (substr($responseXml, 0, 5) == '<?xml') { $ipinfo = new SimpleXMLElement($responseXml); return $ipinfo->ip; } return false; } $ipinfo = get_ip_info($_SERVER['REMOTE_ADDR']); /* определение геолокации */ /* тело письма */ $msg = ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=320, target-densitydpi=device-dpi"> <style type="text/css"> /* Mobile-specific Styles */ @media only screen and (max-width: 600px) { table[class=w0], td[class=w0] { width: 0 !important; } table[class=w10], td[class=w10], img[class=w10] { width:10px !important; } table[class=w15], td[class=w15], img[class=w15] { width:5px !important; }
global $source, $utmSource, $utmMedium, $utmTerm, $utmContent, $utmCampaign; $link = scraperwiki::scrape($source); $html = str_get_html($link); foreach ($html->find('a[href]') as $a) { $href = $a->href; $a->href = $href.'#utm_source='.$utmSource.'&utm_medium='.$utmMedium.'&utm_term='.$utmTerm.'&utm_content='.$utmContent.'&utm_campaign='.$utmCampaign; } print $html; } */ /* SETTINGS */ //Nog loopen door resultaten $source = "http://www.washingtontimes.com/news/2012/sep/18/pentagon-stops-training-partnering-afghan-troops-b/"; $host = parse_url($source, PHP_URL_HOST); $ip = gethostbyname($host); $info = get_ip_info($ip); $result = array('host' => $host, 'ip' => $ip, 'info' => $info); print_r($result); /* Array ( [host] => www.washingtontimes.com [ip] => 38.118.71.70 [info] => Array ( [host] => theconservatives.com [country] => United States [country_code] => USA [continent] => North America [region] => Virginia [latitude] => 38.9687
/** * {@inheritDoc} */ protected function _beforeInsert(&$data, $options) { if (TB_COMMENTS != $options['table']) { return; } $ip_info = get_ip_info(); //ip地址信息 if (is_array($ip_info)) { $data['province'] = $ip_info[0]; $data['city'] = $ip_info[1]; } else { $data['city'] = $ip_info; } $data['email'] = empty($data['email']) ? '' : strtolower($data['email']); if (!empty($data['at_email']) && empty($data['email'])) { //勾选 有人回复我时通知我,邮箱却为空 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L(C('T_MODULE')) . ',' . L('AT_ME_NOTICE_ME') . ',' . L('EMAIL,IS_EMPTY'); trigger_error($log); unset($data['at_email']); } }
/** * {@inheritDoc} */ protected function _beforeInsert(&$data, $options) { if (TB_COMMENTS != $options['table']) { return; } $ip_info = get_ip_info(); //ip地址信息 if (is_array($ip_info)) { $data['province'] = $ip_info[0]; $data['city'] = $ip_info[1]; } else { $data['city'] = $ip_info; } $data['email'] = empty($data['email']) ? '' : strtolower($data['email']); if (!empty($data['at_email']) && empty($data['email'])) { //勾选 有人回复我时通知我,邮箱却为空 $this->_module->triggerError(__METHOD__ . ': ' . __LINE__ . ',' . L(C('T_MODULE')) . ',' . L('AT_ME_NOTICE_ME') . ',' . L('EMAIL,IS_EMPTY'), E_USER_WARNING); unset($data['at_email']); } }
/** * 回复留言评论 * * @author mrmsl <*****@*****.**> * @date 2013-06-03 17:11:14 * * @return void 无返回值 */ public function replyAction() { $comment_id = Filter::int($this->_pk_field); $add_time = Filter::int('add_time'); if (!$comment_id && !$add_time) { //非法参数 $log = L('REPLY,CONTROLLER_NAME,%.,INVALID_PARAM') . "{$this->_pk_field}({$comment_id}),add_time({$add_time})"; $msg = L('INVALID_PARAM'); } elseif (!($comment_info = $this->_model->where(array($this->_pk_field => $comment_id, 'add_time' => $add_time))->find())) { //不存在 $log = L('REPLY,CONTROLLER_NAME') . ".{$this->_pk_field}({$comment_id}),add_time({$add_time})" . L('NOT_EXIST'); $msg = L('CONTROLLER_NAME,NOT_EXIST'); } elseif (COMMENT_REPLY_TYPE_ADMIN == $comment_info['admin_reply_type']) { // $msg = L('CONTROLLER_NAME_ADMIN,REPLY,%。,CAN_NOT,REPLY'); $log = L('REPLY,CONTROLLER_NAME') . '.admin_reply_type=' . COMMENT_REPLY_TYPE_ADMIN . ',' . $msg; } elseif (!($content = Filter::raw('content'))) { $log = L('REPLY,CONTROLLER_NAME') . ".{$this->_pk_field}" . L('REPLY,CONTENT,IS_EMPTY'); $msg = L('PLEASE_ENTER,REPLY,CONTENT'); } elseif ('<p>' != substr($content, 0, 3)) { $content = '<p>' . $content . '</p>'; } if (!empty($msg)) { //错误 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $log; trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, $msg); } $this->_model->startTrans(); $ip_info = get_ip_info(); //ip地址信息 if (is_array($ip_info)) { $province = $ip_info[0]; $city = $ip_info[1]; } else { $province = ''; $city = $ip_info; } $db = $this->_model->getDb(); $data = array('province' => $province, 'city' => $city, 'content' => $content); if (COMMENT_REPLY_TYPE_REPLIED == $comment_info['admin_reply_type']) { //已经回复 $add = false; $reply_info = $this->_model->field($this->_pk_field . ',content')->where('admin_reply_type=' . COMMENT_REPLY_TYPE_ADMIN . ' AND real_parent_id=' . $comment_id)->find(); $log = $this->_dataDiff(array('content' => $reply_info['content']), $data); $db->update($data, array('table' => TB_COMMENTS, 'where' => "{$this->_pk_field}={$reply_info[$this->_pk_field]}")); } else { $add = true; $data = $data + array('parent_id' => $comment_id, 'real_parent_id' => $comment_id, 'add_time' => time(), 'username' => sys_config('module_guestbook_comments_reply_admin_username', 'Module'), 'email' => sys_config('module_guestbook_comments_reply_admin_email', 'Module'), 'user_pic' => str_replace('@common_imgcache@', COMMON_IMGCACHE, sys_config('module_guestbook_comments_reply_admin_img', 'Module')), 'user_ip' => get_client_ip(1), 'user_homepage' => BASE_SITE_URL, 'admin_reply_type' => COMMENT_REPLY_TYPE_ADMIN, 'status' => COMMENT_STATUS_PASS, 'type' => $comment_info['type'], 'blog_id' => $comment_info['blog_id'], 'at_email' => 1, 'level' => $comment_info['level'] + 1); $reply = '@<a class="link" href="#comment-' . $comment_info['comment_id'] . '" rel="nofollow">' . $comment_info['username'] . '</a> '; $data['content'] = substr_replace($data['content'], '<p>' . $reply, 0, 3); if (false === $this->_model->getDb()->insert($data, array('table' => TB_COMMENTS))) { $this->_sqlErrorExit(L('REPLY,FAILURE')); } $insert_id = $db->getLastInsertID(); $max_reply_level = $this->getGuestbookCommentsSetting(COMMENT_TYPE_GUESTBOOK == $comment_info['type'] ? 'module_guestbook' : 'module_comments', 'max_reply_level'); if ($max_reply_level == $comment_info['level']) { //最多5层回复 $comment_info['level']--; $comment_info['node'] = substr($comment_info['node'], 0, strrpos($comment_info['node'], ',')); $node_arr = explode(',', $comment_info['node']); $parent_id = $node_arr[$max_reply_level > 2 ? $max_reply_level - 2 : 1]; //父级id取第四个 } $update = array('level' => $comment_info['level'] + 1, 'node' => $comment_info['node'] . ',' . $insert_id); if (!empty($parent_id)) { $update['parent_id'] = $parent_id; } C('_FACADE_SKIP', true); $this->_model->where($this->_pk_field . '=' . $comment_id)->save(array('admin_reply_type' => COMMENT_REPLY_TYPE_REPLIED)); //已经回复 $this->_model->where($this->_pk_field . '=' . $insert_id)->save($update); $this->_model->where(array($this->_pk_field => array('IN', $comment_info['node'])))->save(array('last_reply_time' => time())); //更新最上层最后回复时间 //干掉静态页,重新统计评论数等 $a = array($comment_id); $b = ''; $this->_beforeExec($a, $b); //处理发送有回复邮件 if ($comment_info['at_email']) { C('T_INFO.at_email', $this->_getMailCommentsInfo($comment_id, C('T_INFO.delete_blog_html'))); $this->_afterSetField('status', null, null); } $log = $content; } $this->_model->addLog(L('REPLY,GUESTBOOK_COMMENTS') . $this->_pk_field . "({$comment_id})" . $log); $this->_ajaxReturn(true, L('REPLY,SUCCESS')); }
public function index() { $ip = trim($_GET['ip']); p(get_ip_info($ip, 2)); }