$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; }