use WP_STATISTICS\Country;
use WP_STATISTICS\IP;
use WP_STATISTICS\Pages;
use WP_Statistics\Service\Analytics\DeviceDetection\DeviceHelper;
use WP_Statistics\Service\Analytics\DeviceDetection\UserAgent;
use WP_Statistics\Service\Geolocation\GeolocationFactory;
use WP_Statistics\Service\Admin\PrivacyAudit\Faqs\RequireConsent;
use WP_STATISTICS\TimeZone;
use WP_STATISTICS\User;
/**
* Get Current User IP
*/
function wp_statistics_get_user_ip()
{
return IP::getIP();
}
/**
* Get Current User Data
*
* @throws Exception
*/
function wp_statistics_get_current_user_data()
{
// Get Current User country and City
$data = wp_statistics_get_user_location();
// Get Current User IP
$data['ip'] = wp_statistics_get_user_ip();
// Get User Agent contain Browser and Platform
$data['agent'] = UserAgent::getUserAgent();
// Get User info if Registered in WordPress
if (User::is_login()) {
$data['user'] = User::get();
}
// Return
return $data;
}
/**
* Get User Statistics Data By IP
*
* @param bool $ip
* @return array
* @throws Exception
*/
function wp_statistics_get_user_location($ip = false)
{
$ip = ($ip === false ? wp_statistics_get_user_ip() : $ip);
$data = array(
'country' => '',
'city' => '',
);
// Get the location
$location = GeolocationFactory::getLocation($ip);
$country = $location['country'];
$data['country'] = array(
'code' => $location,
'name' => Country::getName($country),
'flag' => Country::flag($country)
);
// Get User City
$data['city'] = $location['city'];
return $data;
}
/**
* Get Current Users online
*
* @param array $options
* @return mixed
*/
function wp_statistics_useronline($options = array())
{
global $wpdb;
//Check Parameter
$defaults = array(
/**
* Type Of Page in WordPress
* @See Frontend\get_page_type
*
* -- Acceptable values --
*
* post -> WordPress Post single page From All of public post Type
* page -> WordPress page single page
* product -> WooCommerce product single page
* home -> Home Page website
* category -> WordPress Category Page
* post_tag -> WordPress Post Tags Page
* tax -> WordPress Term Page for all Taxonomies
* author -> WordPress Users page
* 404 -> 404 Not Found Page
* archive -> WordPress Archive Page
* all -> All Site Page
*
*/
'type' => 'all',
/**
* WordPress Query object ID
* @example array('type' => 'product', 'ID' => 5)
*/
'ID' => 0,
/**
* Get number of logged users or all users
*
* -- Acceptable values --
* false -> Get Number of all users
* true -> Get Number of all logged users in wordpress
*/
'logged_users' => false,
/**
* Get number User From Custom Country
*
* -- Acceptable values --
* ISO Country Code -> For Get List @See \wp-statistics\includes\functions\country-code.php
*
*/
'location' => 'all',
/**
* Search Filter by User agent name
* e.g : Firefox , Chrome , Safari , Unknown ..
* @see wp_statistics_get_browser_list()
*
*/
'agent' => 'all',
/**
* Search filter by User Operating System name
* e.g : Windows, iPad, Macintosh, Unknown, ..
*
*/
'platform' => 'all',
/**
* Return Of Data
*
* -- Acceptable values --
* count -> Get number of user online
* all -> Get List of User Online data
*/
'return' => 'count'
);
// Parse incoming $args into an array and merge it with $defaults
$arg = wp_parse_args($options, $defaults);
//Basic SQL
$type_request = ($arg['return'] == "all" ? '*' : 'COUNT(*)');
$sql = "SELECT {$type_request} FROM " . WP_STATISTICS\DB::table('useronline') . " as useronline JOIN " . WP_STATISTICS\DB::table('visitor') . " as visitor ON useronline.visitor_id = visitor.ID";
//Check Where Condition
$where = [];
//Check Type of Page
if ($arg['type'] != "all") {
$where[] = "`visitor`.`last_page` = " . $arg['ID'];
}
//Check Custom user
if ($arg['logged_users'] === true) {
$where[] = "`user_id` > 0";
}
//Check Location
if ($arg['location'] != "all") {
$ISOCountryCode = Country::getList();
if (array_key_exists($arg['location'], $ISOCountryCode)) {
$where[] = "`location` = '" . $arg['location'] . "'";
}
}
//Check User Agent
if ($arg['agent'] != "all") {
$where[] = "`agent` = '" . $arg['agent'] . "'";
}
//Check User Platform
if ($arg['platform'] != "all") {
$where[] = "`platform` = '" . $arg['platform'] . "'";
}
//Push Conditions to SQL
if (!empty($where)) {
$sql .= ' WHERE ' . implode(' AND ', $where);
}
//Return Number od user Online
return ($arg['return'] == "count" ? $wpdb->get_var($sql) : $wpdb->get_results($sql)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}
/**
* This function get the visit statistics for a given time frame
*
* @param $time
* @param null $daily
* @return int
*/
function wp_statistics_visit($time, $daily = null)
{
global $wpdb;
//Date Column Name in visits table
$table_name = WP_STATISTICS\DB::table('visit');
$date_column = 'last_counter';
//Prepare Selector Sql
$selector = 'SUM(visit)';
if ($daily == true) {
$selector = '*';
}
//Generate Base Sql
$sql = "SELECT " . $selector . " FROM `" . $table_name . "` ";
//Create Sum Views variable
$sum = 0;
//Check if daily Report
if ($daily === true) {
// Check Sanitize Datetime
if (TimeZone::isValidDate($time)) {
$d = $time;
} else {
$d = TimeZone::getCurrentDate('Y-m-d', $time);
}
$result = $wpdb->get_row($sql . " WHERE `$date_column` = '" . $d . "'"); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
if (null !== $result) {
$sum = $result->visit;
}
} else {
//Generate MySql Time Conditions
if (is_array($time) && array_key_exists('start', $time) && array_key_exists('end', $time)) {
$mysql_time_sql = WP_STATISTICS\Helper::mysql_time_conditions($date_column, '', $time);
if (!empty($mysql_time_sql)) {
$sql = $sql . ' WHERE ' . $mysql_time_sql;
}
} else {
$mysql_time_sql = WP_STATISTICS\Helper::mysql_time_conditions($date_column, $time);
if (!empty($mysql_time_sql)) {
$sql = $sql . ' WHERE ' . $mysql_time_sql;
}
}
//Request To database
$result = $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
//Custom Action
if ($time == "total") {
$result += WP_STATISTICS\Historical::get('visits');
}
$sum = $result;
}
return !is_numeric($sum) ? 0 : $sum;
}
/**
* This function gets the visitor statistics for a given time frame.
*
* @param $time
* @param null $daily
* @param bool $count_only
* @param array $options
* @return int|null|string
*/
function wp_statistics_visitor($time, $daily = null, $count_only = false, $options = array())
{
global $wpdb;
//Check Parameter
$defaults = array(
/**
* Type Of Page in WordPress
* @See Frontend\get_page_type
*
* -- Acceptable values --
*
* post -> WordPress Post single page From All of public post Type
* page -> WordPress page single page
* product -> WooCommerce product single page
* home -> Home Page website
* category -> WordPress Category Page
* post_tag -> WordPress Post Tags Page
* tax -> WordPress Term Page for all Taxonomies
* author -> WordPress Users page
* 404 -> 404 Not Found Page
* archive -> WordPress Archive Page
* all -> All Site Page
*
*/
'type' => 'all',
/**
* WordPress Query object ID
* @example array('type' => 'product', 'ID' => 5)
*/
'ID' => 0,
/**
* Get number User From Custom Country
*
* -- Acceptable values --
* ISO Country Code -> For Get List @See \wp-statistics\includes\functions\country-code.php
*
*/
'location' => 'all',
/**
* Search Filter by User agent name
* e.g : Firefox , Chrome , Safari , Unknown ..
* @see wp_statistics_get_browser_list()
*
*/
'agent' => 'all',
/**
* Search filter by User Operating System name
* e.g : Windows, iPad, Macintosh, Unknown, ..
*
*/
'platform' => 'all'
);
// Parse incoming $args into an array and merge it with $defaults
$arg = wp_parse_args($options, $defaults);
//Create History Visitors variable
$history = 0;
//Prepare Selector Sql
$date_column = 'last_counter';
$selector = '*';
if ($count_only == true) {
$selector = 'count(last_counter)';
}
//Generate Base Sql
if ($arg['type'] != "all" and WP_STATISTICS\Option::get('visitors_log') == true) {
$sql = "SELECT {$selector} FROM `" . WP_STATISTICS\DB::table('visitor') . "` INNER JOIN `" . WP_STATISTICS\DB::table("visitor_relationships") . "` ON `" . WP_STATISTICS\DB::table("visitor_relationships") . "`.`visitor_id` = `" . WP_STATISTICS\DB::table('visitor') . "`.`ID` INNER JOIN `" . WP_STATISTICS\DB::table('pages') . "` ON `" . WP_STATISTICS\DB::table('pages') . "`.`page_id` = `" . WP_STATISTICS\DB::table("visitor_relationships") . "` . `page_id`";
} else {
$sql = "SELECT {$selector} FROM `" . WP_STATISTICS\DB::table('visitor') . "`";
}
//Check Where Condition
$where = [];
//Check Type of Page
if ($arg['type'] != "all" and WP_STATISTICS\Option::get('visitors_log') == true) {
$where[] = "`" . WP_STATISTICS\DB::table('pages') . "`.`type`='" . $arg['type'] . "' AND `" . WP_STATISTICS\DB::table('pages') . "`.`page_id` = " . $arg['ID'];
}
//Check Location
if ($arg['location'] != "all") {
$ISOCountryCode = Country::getList();
if (array_key_exists($arg['location'], $ISOCountryCode)) {
$where[] = "`" . WP_STATISTICS\DB::table('visitor') . "`.`location` = '" . $arg['location'] . "'";
}
}
//Check User Agent
if ($arg['agent'] != "all") {
$where[] = "`" . WP_STATISTICS\DB::table('visitor') . "`.`agent` = '" . $arg['agent'] . "'";
}
//Check User Platform
if ($arg['platform'] != "all") {
$where[] = "`" . WP_STATISTICS\DB::table('visitor') . "`.`platform` = '" . $arg['platform'] . "'";
}
//Check Date Time report
if ($daily == true) {
// Check Sanitize Datetime
if (TimeZone::isValidDate($time)) {
$d = $time;
} else {
$d = TimeZone::getCurrentDate('Y-m-d', $time);
}
//Get Only Current Day Visitors
$where[] = "`" . WP_STATISTICS\DB::table('visitor') . "`.`last_counter` = '" . $d . "'";
} else {
//Generate MySql Time Conditions
if (is_array($time) && array_key_exists('start', $time) && array_key_exists('end', $time)) {
$mysql_time_sql = WP_STATISTICS\Helper::mysql_time_conditions($date_column, '', $time);
if (!empty($mysql_time_sql)) {
$sql = $sql . ' WHERE ' . $mysql_time_sql;
}
} else {
$mysql_time_sql = WP_STATISTICS\Helper::mysql_time_conditions($date_column, $time);
if (!empty($mysql_time_sql)) {
$where[] = $mysql_time_sql;
}
}
}
//Push Conditions to SQL
if (!empty($where)) {
$sql .= ' WHERE ' . implode(' AND ', $where);
}
//Custom Action
if ($time == "total" and $arg['type'] == "all") {
$history = WP_STATISTICS\Historical::get('visitors');
}
// Execute the SQL call, if we're only counting we can use get_var(), otherwise we use query().
if ($count_only == true) {
$sum = $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$sum += $history;
} else {
$sum = $wpdb->query($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}
return $sum;
}
/**
* This function returns the statistics for a given page.
*
* @param $time
* @param string $page_uri
* @param int $id
* @param null $rangestartdate
* @param null $rangeenddate
* @param bool $type
* @return int|null|string
*
* @todo Replace all instances of this function with `ViewsModel->countViews()`.
*/
function wp_statistics_pages($time, $page_uri = '', $id = -1, $rangestartdate = null, $rangeenddate = null, $type = false)
{
global $wpdb;
//Date Column Name in visits table
$table_name = WP_STATISTICS\DB::table('pages');
$date_column = 'date';
// History Vars
$history = 0;
$history_key = null;
$history_id = null;
//Check Where Condition
$where = [];
//Check Query By Page ID or Page Url
if ($type) {
$query = $wpdb->prepare("`type` = %s", $type);
if ($id != -1) {
$query .= $wpdb->prepare(" AND `id` = %d", $id);
$history_key = 'page';
$history_id = absint($id);
}
if ($page_uri != '') {
$page_uri_sql = esc_sql($page_uri);
$query .= $wpdb->prepare(" AND `URI` = %s", $page_uri_sql);
$history_key = 'uri';
$history_id = $page_uri;
}
$where[] = apply_filters('wp_statistics_pages_where_type_query', $query, $id, $type);
} else {
// If no page URI has been passed in, get the current page URI.
if ($page_uri == '') {
$page_uri = Pages::get_page_uri();
}
$page_uri_sql = esc_sql($page_uri);
// If a page/post ID has been passed, use it to select the rows, otherwise use the URI.
if ($id != -1) {
$where[] = "`id`= " . absint($id);
$history_key = 'page';
$history_id = absint($id);
} else {
$where[] = "`URI` = '{$page_uri_sql}'";
$history_key = 'uri';
$history_id = $page_uri;
}
}
//Custom Action
if ($time == "total") {
if ($history_key && $history_id) {
$history = WP_STATISTICS\Historical::get($history_key, $history_id);
}
}
//Prepare Time
$time_array = array();
if (is_numeric($time) || TimeZone::isValidDate($time)) {
$time_array['is_day'] = true;
}
if (!is_null($rangestartdate) and !is_null($rangeenddate)) {
$time_array = array('start' => $rangestartdate, 'end' => $rangeenddate);
}
//Check MySql Time Conditions
$mysql_time_sql = WP_STATISTICS\Helper::mysql_time_conditions($date_column, $time, $time_array);
if (!empty($mysql_time_sql)) {
$where[] = $mysql_time_sql;
}
//Generate Base Sql
$sql = "SELECT SUM(count) FROM {$table_name}";
//Push Conditions to SQL
if (!empty($where)) {
$sql .= ' WHERE ' . implode(' AND ', $where);
}
//Request Get data
$sum = $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$sum += $history;
//Return Number Statistic
return ($sum == '' ? 0 : $sum);
}
/**
* Get top Pages between Time
*
* @param null $rangestartdate
* @param null $rangeenddate
* @param null $limit
* @param null $post_type
* @return array
*/
function wp_statistics_get_top_pages($rangestartdate = null, $rangeenddate = null, $limit = null, $post_type = null)
{
global $wpdb;
$spliceLimit = ($limit != null ? $limit : 5);
$limit = null;
// Get every unique URI from the pages database.
if ($rangestartdate != null && $rangeenddate != null) {
$whereType = ($post_type != null ? $wpdb->prepare(" AND `type`=%s", $post_type) : '');
$result = $wpdb->get_results(
$wpdb->prepare("SELECT `uri`,`id`,`type` FROM " . \WP_STATISTICS\DB::table('pages') . " WHERE `date` BETWEEN %s AND %s {$whereType} GROUP BY `id`" . ($limit != null ? ' LIMIT ' . $limit : ''), $rangestartdate, $rangeenddate), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
ARRAY_N);
} else {
$limitQuery = '';
if ($limit) {
$limitQuery = $wpdb->prepare(" LIMIT %d", $limit);
}
$whereType = ($post_type != null ? $wpdb->prepare(" WHERE `type`=%s", $post_type) : '');
$result = $wpdb->get_results("SELECT `uri`, `id`, `type` FROM " . \WP_STATISTICS\DB::table('pages') . " {$whereType} GROUP BY `id` {$limitQuery}", ARRAY_N); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}
$total = 0;
$uris = array();
// Now get the total page visit count for each unique URI.
foreach ($result as $out) {
//Prepare item
list($url, $page_id, $page_type) = $out;
// Check if item is of specific post type (string or part of an array) or if post type is set to null
if (is_null($post_type) || $page_type == $post_type || (is_array($post_type) && in_array($page_type, $post_type))) {
// Increment the total number of results.
$total++;
//Get Page Title
$page_info = Pages::get_page_info($page_id, $page_type);
$title = mb_substr($page_info['title'], 0, 200, "utf-8");
$page_url = $page_info['link'];
// Check age Title if page id or type not exist
if ($page_info['link'] == "") {
$page_url = path_join(get_site_url(), $url);
$id = WP_STATISTICS\Pages::uri_to_id($out[0]);
$post = get_post($id);
if (is_object($post)) {
$title = esc_html($post->post_title);
} else {
if ($out[0] == '/') {
$title = get_bloginfo();
} else {
$title = '';
}
}
}
//Check Title is empty
if (empty($title)) {
$title = '-';
}
// Add the current post to the array.
if ($rangestartdate != null && $rangeenddate != null) {
$uris[] = array(
urldecode_deep($out[0]),
wp_statistics_pages('range', $out[0], -1, $rangestartdate, $rangeenddate, $post_type),
$page_id,
$title,
$page_url,
);
} else {
$uris[] = array(
urldecode_deep($out[0]),
wp_statistics_pages('total', $out[0], -1, $rangestartdate, $rangeenddate, $post_type),
$page_id,
$title,
$page_url
);
}
}
}
// If we have more than one result, let's sort them using usort.
if (count($uris) > 1) {
usort($uris, array('\WP_STATISTICS\Helper', 'compare_uri_hits_int'));
}
array_splice($uris, $spliceLimit);
return array($spliceLimit, $uris);
// return array($total, $uris);
}
/**
* Returns all unique user agents in the database.
*
* @param null $rangestartdate
* @param null $rangeenddate
* @return array
*/
function wp_statistics_ua_list($rangestartdate = null, $rangeenddate = null)
{
global $wpdb;
if ($rangestartdate != null && $rangeenddate != null) {
if ($rangeenddate == 'CURDATE()') {
$result = $wpdb->get_results(
$wpdb->prepare("SELECT DISTINCT agent FROM `" . \WP_STATISTICS\DB::table('visitor') . "` WHERE `last_counter` BETWEEN %s AND CURDATE()", $rangestartdate),
ARRAY_N);
} else {
$result = $wpdb->get_results(
$wpdb->prepare("SELECT DISTINCT agent FROM `" . \WP_STATISTICS\DB::table('visitor') . "` WHERE `last_counter` BETWEEN %s AND %s", $rangestartdate, $rangeenddate),
ARRAY_N);
}
} else {
$result = $wpdb->get_results(
"SELECT DISTINCT agent FROM `" . \WP_STATISTICS\DB::table('visitor') . "` ",
ARRAY_N);
}
$Browsers = array();
$default_browser = DeviceHelper::getBrowserList();
foreach ($result as $out) {
//Check Browser is defined in wp-statistics
if (array_key_exists(strtolower($out[0]), $default_browser)) {
$Browsers[] = esc_html($out[0]);
}
}
return $Browsers;
}
/**
* Count User By User Agent
*
* @param $agent
* @param null $rangestartdate
* @param null $rangeenddate
* @return mixed
*/
function wp_statistics_useragent($agent, $rangestartdate = null, $rangeenddate = null)
{
global $wpdb;
if ($rangestartdate != null || $rangeenddate != null) {
if ($rangeenddate == null) {
$result = $wpdb->get_var(
$wpdb->prepare("SELECT COUNT(*) FROM `" . \WP_STATISTICS\DB::table('visitor') . "` WHERE `agent` = %s AND `last_counter` = %s", $agent, $rangestartdate)
);
} else {
$result = $wpdb->get_var(
$wpdb->prepare("SELECT COUNT(*) FROM `" . \WP_STATISTICS\DB::table('visitor') . "` WHERE `agent` = %s AND `last_counter` BETWEEN %s AND %s", $agent, $rangestartdate, $rangeenddate)
);
}
} else {
$result = $wpdb->get_var(
$wpdb->prepare("SELECT COUNT(*) FROM `" . \WP_STATISTICS\DB::table('visitor') . "` WHERE `agent` = %s", $agent)
);
}
return $result;
}
/**
* Returns all unique platform types from the database.
*
* @param null $rangestartdate
* @param null $rangeenddate
* @return array
*/
function wp_statistics_platform_list($rangestartdate = null, $rangeenddate = null)
{
global $wpdb;
if ($rangestartdate != null && $rangeenddate != null) {
$result = $wpdb->get_results(
$wpdb->prepare("SELECT DISTINCT platform FROM `" . \WP_STATISTICS\DB::table('visitor') . "` WHERE `last_counter` BETWEEN %s AND %s", $rangestartdate, $rangeenddate),
ARRAY_N);
} else {
$result = $wpdb->get_results(
"SELECT DISTINCT platform FROM `" . \WP_STATISTICS\DB::table('visitor') . "` ",
ARRAY_N);
}
$Platforms = array();
foreach ($result as $out) {
$Platforms[] = esc_html($out[0]);
}
return $Platforms;
}
/**
* Returns the count of a given platform in the database.
*
* @param $platform
* @param null $rangestartdate
* @param null $rangeenddate
* @return mixed
*/
function wp_statistics_platform($platform, $rangestartdate = null, $rangeenddate = null)
{
global $wpdb;
if ($rangestartdate != null && $rangeenddate != null) {
$result = $wpdb->get_var(
$wpdb->prepare("SELECT COUNT(platform) FROM `" . \WP_STATISTICS\DB::table('visitor') . "` WHERE `platform` = %s AND `last_counter` BETWEEN %s AND %s", $platform, $rangestartdate, $rangeenddate)
);
} else {
$result = $wpdb->get_var(
$wpdb->prepare("SELECT COUNT(platform) FROM `" . \WP_STATISTICS\DB::table('visitor') . "` WHERE `platform` = %s", $platform)
);
}
return $result;
}
/**
* Returns all unique versions for a given agent from the database.
*
* @param $agent
* @param null $rangestartdate
* @param null $rangeenddate
* @return array
*/
function wp_statistics_agent_version_list($agent, $rangestartdate = null, $rangeenddate = null)
{
global $wpdb;
if ($rangestartdate != null && $rangeenddate != null) {
$result = $wpdb->get_results(
$wpdb->prepare("SELECT DISTINCT `version` FROM `" . \WP_STATISTICS\DB::table('visitor') . "` WHERE agent = %s AND `last_counter` BETWEEN %s AND %s", $agent, $rangestartdate, $rangeenddate),
ARRAY_N);
} else {
$result = $wpdb->get_results(
$wpdb->prepare("SELECT DISTINCT `version` FROM `" . \WP_STATISTICS\DB::table('visitor') . "` WHERE agent = %s", $agent),
ARRAY_N);
}
$Versions = array();
foreach ($result as $out) {
$Versions[] = $out[0];
}
return $Versions;
}
/**
* Returns the statistics for a given agent/version pair from the database.
*
* @param $agent
* @param $version
* @param null $rangestartdate
* @param null $rangeenddate
* @return mixed
*/
function wp_statistics_agent_version($agent, $version, $rangestartdate = null, $rangeenddate = null)
{
global $wpdb;
if ($rangestartdate != null && $rangeenddate != null) {
$result = $wpdb->get_var(
$wpdb->prepare("SELECT COUNT(version) FROM `" . \WP_STATISTICS\DB::table('visitor') . "` WHERE agent = %s AND version = %s AND `last_counter` BETWEEN %s AND %s", $agent, $version, $rangestartdate, $rangeenddate)
);
} else {
$result = $wpdb->get_var(
$wpdb->prepare("SELECT COUNT(version) FROM `" . \WP_STATISTICS\DB::table('visitor') . "` WHERE agent = %s AND version = %s", $agent, $version)
);
}
return $result;
}
/**
* Return the SQL WHERE clause for getting the search engine.
*
* @param string $search_engine
* @return bool|string
*/
function wp_statistics_searchengine_query($search_engine = 'all')
{
global $wpdb;
$search_query = '';
// Are we getting results for all search engines or a specific one?
if (strtolower($search_engine) == 'all') {
$search_query .= "`source_channel` in ('search')";
} else {
// Are we getting results for all search engines or a specific one?
$search_query .= $wpdb->prepare("`source_name` = %s", $search_engine);
}
return $search_query;
}
/**
* Get Search engine Statistics
*
* @param string $search_engine
* @param string $time
* @param string $search_by [query / name]
* @param array $range
* @return mixed
*/
function wp_statistics_get_search_engine_query($search_engine = 'all', $time = 'total', $search_by = 'query', $range = [])
{
global $wpdb;
//Prepare Table Name
$table_name = \WP_STATISTICS\DB::table('visitor');
//Date Column table
$date_column = 'last_counter';
// Get a complete list of search engines
if ($search_by == "query") {
$search_query = wp_statistics_searchengine_query($search_engine);
}
//Generate Base Sql
$sql = "SELECT COUNT(ID) FROM {$table_name} WHERE ({$search_query})";
// Check Sanitize Datetime
if (TimeZone::isValidDate($time)) {
if (empty($range)) $range = ['is_day' => true];
} else {
if (empty($range)) $range = ['current_date' => true];
}
$mysql_time_sql = WP_STATISTICS\Helper::mysql_time_conditions($date_column, $time, $range);
//Generate MySql Time Conditions
if (!empty($mysql_time_sql)) {
$sql = $sql . ' AND (' . $mysql_time_sql . ')';
}
//Request Data
return $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}
/**
* This function will return the statistics for a given search engine.
*
* @param string $search_engine
* @param string $time
* @param array $range
* @return mixed
*/
function wp_statistics_searchengine($search_engine = 'all', $time = 'total', $range = [])
{
return wp_statistics_get_search_engine_query($search_engine, $time, $search_by = 'query', $range);
}
/**
* Return Refer List
*
* @param null $time
* @param array $range
* @return int
*/
function wp_statistics_referrer($time = null, $range = [])
{
global $wpdb;
$sql = "SELECT `referred` FROM `" . \WP_STATISTICS\DB::table('visitor') . "` WHERE referred <> ''";
// Check Sanitize Datetime
if (TimeZone::isValidDate($time)) {
if (empty($range)) $range = ['is_day' => true];
} else {
if (empty($range)) $range = ['current_date' => true];
}
$mysql_time_sql = WP_STATISTICS\Helper::mysql_time_conditions('last_counter', $time, $range);
//Generate MySql Time Conditions
if (!empty($mysql_time_sql)) {
$sql = $sql . ' AND (' . $mysql_time_sql . ')';
}
$result = $wpdb->get_results($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$urls = array();
foreach ($result as $item) {
$url = wp_parse_url($item->referred);
if (empty($url['host']) || stripos(get_bloginfo('url'), $url['host']) !== false) {
continue;
}
$urls[] = $url['scheme'] . '://' . $url['host'];
}
$get_urls = array_count_values($urls);
return count($get_urls);
}
/**
* Checks if consent is required for collecting user statistics.
*
* This function evaluates several conditions that determine whether consent
* is needed to collect and store user data for statistics purposes. If any
* of the conditions are not met, it indicates that consent is required.
*
* @return bool Returns true if consent is required, false otherwise.
* @since 14.10.1
*/
function wp_statistics_needs_consent()
{
// Get the current status of the consent requirement
$status = RequireConsent::getStatus();
// Check if consent is required
if ($status == 'warning') {
return true; // Consent is required
}
// Return false if consent is not required
return false;
}
班夫五日游行程建议 ⋆ 晒鱼
Skip to content
原创 — 班夫国家公园 班夫
微信号 BanffNationalPark
功能介绍 加拿大班夫国家公园(Banff National Park)——加拿大的”九寨沟”、落基山脉的璀璨明珠,欢迎您的关注!
春天到了,班夫娘收到的问题也像冬天的雪花一般纷纷飘来(希望冬天也这样),问最多的就是——我该如何安排我的行程。所以班夫娘特地整理了一个3 – 5天的行程供大家参考~希望能帮到大家。
注意:
所有的行程安排基本类似于每天一个一日游,在班夫和露易丝湖地区一天之内可以到达和玩耍。如果不开车建议你可以住在班夫镇;如果开车,选择露易丝湖更加方便。我们的行程也会兼顾开车的老师和不自驾的老师。为了方便不开车的老师,除了Jasper地区,都默认在班夫镇居住。行程的安排不涉及酒店推荐。
各个景点的介绍将不会出现在这里,毕竟真做那么长,可能会影响你的选择。未来班夫娘也会对每一个景点都好好做一些介绍的。
Day 1 :班夫镇和周边
事实上,班夫镇绝对是一个值得你花点时间逛逛的好地方。不少人说一个班夫等于20个瑞士,虽然连班夫娘都觉得这种说法略显夸张,但班夫镇的魅力可见一斑。
在镇上,你的第一站必须是Visitor Centre,Visitor Centre旁边是教堂,特别好找。如果有老师需要自驾,可以在那里拿到免费的地图,当然还有各种免费的资料,这些地图上有一些折扣券,可以好好利用。也记得问问路况信息哦!如果你不打算自驾,也一定要来Visitor Centre,根据自己的行程,和工作人员咨询有没有合适的一日游半日游团队。他们一定很乐意帮助你。
传说中最好吃的冰激凌店吉祥物并不想理你并向你扔了一个冰激凌
接下来,你可以在镇上随便走走,看看全世界最好吃的冰淇淋店什么的,或者直接租辆自行车开始镇周边的探索之旅(如果你开车,这句当我没说)。
镇周边值得一去的地方包括弓河瀑布(Bow Fall),Surprise Corner, Lake Minnewanka,Hoodoos,2 Jack Lake,Johnson Lake。傍晚记得到Vermillion Lake, 拍能当明信片的日落。过了五月中旬,你还可以在Lake Minnewanka乘坐游船。
如果你对山地文化,和班夫历史感兴趣,Whyte Museum和Cave and Basin Historic Site就值得一看了,这两个地方有很多老照片,还有不少班夫的故事,非常有趣。Fairmont Banff Spring Hotel也是个好地方,这座酒店本身就在一个饱经岁月的古堡之中,酒店里就像是一个巨大的博物馆,也陈列了许多老照片。这里还经常有一人在现场创作或者演奏。
Day 2 :爬山,去峡谷
今天早点起吧,先到Sulphur Mountain坐坐缆车(Banff Gondola),这也算是第一次来班夫的游客一定会体验的项目之一了。如果你喜欢爬山,你还可以再多走几步到山顶。在山顶,你能俯瞰到整个班夫镇。
这边开车或者坐公交都非常方便(Roam 大巴的Route one)。今年Banff Gondola刚进行了翻新,5月1日正式开放,到8月1日的时候,你能在这里找到很多更有意思的设施,一起期待吧。
接下来你可以到Johnston Canyon徒步。关于Johnston Canyon的徒步攻略,大家可以参考我们之前的文章班夫徒步线路——Johnston Canyon ; 从班夫镇到Johnston Canyon需要开车沿着Bow Valley Parkway走20多分钟,Bow Valley Parkway沿途风景特别迷人,还有很大的几率发现小动物的身影。如果你不开车,可以考虑报团参加半日游或者骑车子前往。25公里的路程,不过会有一段爬坡,大概骑车子一个半小时能到。别太沮丧,有多少上坡就有多少下坡,想想你返程时候将会多爽吧。
如果不想走这种大众行程,建议你可以到Mt Norquay去,那边的缆车也可以俯瞰到班夫镇的全貌。这边还有一个很酷的活动叫Via Ferrata,即使是零基础的人也可以让你体验户外登山的乐趣。
注意: 诺奎山夏日运营时间是从6月10日开始的,你最近去大概只能看见一个滑雪场。Mt Norquay每天都有往返班夫的接送大巴,不管是自驾还是不自驾都很方便呢。
两种行程都非常消耗体力,下午或者傍晚回来以后就去泡温泉吧~班夫的露天温泉(Banff Upper Hotspring)历史悠久价格实惠,一边欣赏山景一边洗去全身的疲累简直不能更棒。这样的温泉你猜多少钱?一个人7.3加元。乘坐(Roam 大巴的Route one)就可以到达这里了~
从第三天开始是一个分界线,大家根据情况制定行程,如果你打算从Jasper直接离开落基山脉,可以把Day 3的行程安排在第四天,先去露易丝湖,并在那边住一晚。
Day 3 :班夫 – 冰原大道 – 贾斯珀
冰原大道是一个值得你花一天时间去看的好地方,毕竟这里被评选为全世界最美的自驾线路之一。那些经常出现在班夫娘微信的壮观的冰川,可爱的Peyto湖,迷人的弓湖都在冰原大道上。如果自驾,随时停下来各种拍照可能一整天的时间都不够。如果不自驾,可以参加Sundog或者是Brewster的冰原大道观光之旅,所有重点拍照地都会停车的。
需要单独拿出来给大家说一说的是Brewster的冰原探险中心,这边的冰原雪车探险和冰川天空步道(Skywalk)非常值得一看,夏天的阿萨巴斯卡(Athabasca)冰川非常壮观,而天空步道的高度能给你带来的战栗的快感。冰原中心现在已经开放了,大家可以欢乐地去玩耍了~
Zizka 拍摄的Athabasca攀冰,很迷人
关于冬天的Athabasca,是这个样子的,不过只能自己走过去,挺危险的,夏天相对来说安全了很多。
注意: 当天在贾斯珀过夜,如果不打算住在Jasper,也可以参加冰原大道一日游旅程,班夫出发,回到班夫。
Day 4 : 贾斯珀国家公园
一般来说,第一次来落基山脉的大家肯定少不了到贾斯珀国家公园参观一番。贾斯珀国家公园是落基山脉国家公园中最大的第一个。也是班夫的好朋友之一。在贾斯珀国家公园你可以到Maligne Canyon参观,也可以到Maligne Lake 乘坐游船。
Day 4 : 贾斯珀 – 露易丝湖
如果不打算继续花时间在路上,你可以考虑乘坐Sundog的直达大巴,或者到露易丝湖,早晨的露易丝湖静谧美好简直让人不想走。如果过了五月中旬,你还可以顺便到梦莲湖看看,那个传说中被印在加元上的风景。
如果最近去露易丝湖,你可以选择去Lake Louise Gondola玩耍,在那边,你可以俯瞰整个露易丝湖(有接送大巴)。
露易丝湖周边有很多徒步线路,随着冰雪的化开,随自己开心选一条走走吧,一定记得组队超过四个人再开始玩哦!
懒得走路的,就到Chateau Lake Louise逛逛吧,这边有不少商场,也有不少老照片。你还可以在这里享用一顿美食,最好选择可以看到露易丝湖美景的位置。
露易丝湖的Visitor Centre也很有趣,你可以在这边了解到很多露易丝湖形成的知识。
关于不自驾到梦莲湖,你可以选择联系Mountain Park transportation(403) 522-2525班夫到露易丝湖的大巴有很多,Sundog,Brewster都可以,参加Discover Banff Tour的Day Trip也不错。你也可以到班夫美景旅游问一问,也许他们也有不错的一日游行程哦。
注意:
露易丝湖夏日缆车到5月13日可以到达,缆车那边徒步什么的都非常适合。冬季运营到5月1日结束。
如果你不去贾斯珀,你还有更多其他的选择,这里班夫娘大致给大家说说,大家可以到游客中心询问具体详情
1. 骑车沿着Legacy trail到Canmore,看看小李拍摄荒野猎人的Kananaskis;可以坐Roam大巴回来;2. 镇上还有很多博物馆和画廊,感兴趣的可以看看,下午再去报名参加瑜伽课程 ,度过安静的一天;3. 到Fairmont Banff spring hotel那边打高尔夫球4. 随便选个一日游行程玩玩,比如直升机之旅啦,比如寻找野生动物啦,剩下的空余时间就在镇上闲逛吧~5. 到Calgary血拼,CrossIron Mills是个好地方,Coach包和Levis不要更便宜咯,户外装备也值得来上一套。6. 去爬山,除了Sulphur Mountain以外,Tunnel Mountain也是个不错的去处。7. 五月中旬还没到,Sunshine Village还能滑雪,抓住最后的机会吧!8. 到Yoho National park看看,翡翠湖也很美的。
讲道理,你就算想玩个8天9天的,这些还不够吗?
班夫娘有话说
对于我们的内容,大家还有什么想法,欢迎留言问班夫娘哦~
提到了一些商家,不过不是植入,因为班夫娘并没有收到广告费~
别忘了订酒店,已经听到没定着酒店的悲剧了!
毕竟写了这么多,希望更多人能看到呀~不要脸地求个转发呗
关于我们
大家好,如果你是第一次看到这篇内容~这段话可以给你做一个小小的扫盲~
我们是位于加拿大艾伯塔省的班夫国家公园。这个账号自然是我们的官方微信
我们位于美丽雄伟的落基山脉
我们是加拿大最早也是最美丽的国家公园之一~
如果到加拿大,特别是加西,请千万别忘记来到这里哦!
关注我们
我们的微信号是: BanffNationalPark
长按下面的图片,选择【识别图中二维码】你就能关注我们了
微信扫一扫 关注该公众号
文章导航