prefix . 'eistat_'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $days = isset($_GET['days']) && (int) $_GET['days'] === 28 ? 28 : 7; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $eistat_raw_link_type = isset($_GET['link_type']) ? sanitize_key(wp_unslash($_GET['link_type'])) : ''; $eistat_filter_type = in_array($eistat_raw_link_type, ['outbound', 'email', 'phone'], true) ? $eistat_raw_link_type : ''; if ($eistat_filter_type !== '') { $eistat_where_type = " AND link_type = %s"; $eistat_args_links = [$days, $eistat_filter_type]; $eistat_args_pages = [$days, $eistat_filter_type]; } else { $eistat_where_type = ""; $eistat_args_links = [$days]; $eistat_args_pages = [$days]; } // --- Top links --- $eistat_sql_links = "SELECT link_type, link_url, link_text, SUM(count) AS c FROM {$eistat_p}events WHERE date >= DATE_SUB(CURDATE(), INTERVAL %d DAY){$eistat_where_type} GROUP BY link_type, link_url, link_text ORDER BY c DESC LIMIT 50"; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $eistat_top_links = $wpdb->get_results($wpdb->prepare($eistat_sql_links, ...$eistat_args_links)); // --- Top pages with clicks --- $eistat_sql_pages = "SELECT page_type, page_id, SUM(count) AS c FROM {$eistat_p}events WHERE date >= DATE_SUB(CURDATE(), INTERVAL %d DAY){$eistat_where_type} GROUP BY page_type, page_id ORDER BY c DESC LIMIT 20"; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $eistat_top_pages = $wpdb->get_results($wpdb->prepare($eistat_sql_pages, ...$eistat_args_pages)); // --- Load page URLs for the top pages --- $eistat_page_urls = []; if ($eistat_top_pages) { $eistat_keys = []; foreach ($eistat_top_pages as $tp) { $eistat_keys[] = $wpdb->prepare("(page_type = %s AND page_id = %d)", $tp->page_type, $tp->page_id); } $eistat_where = implode(' OR ', $eistat_keys); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $eistat_rows = $wpdb->get_results( "SELECT DISTINCT page_type, page_id, page_url FROM {$eistat_p}pageviews WHERE date >= DATE_SUB(CURDATE(), INTERVAL " . (int) $days . " DAY) AND ({$eistat_where})" ); foreach ($eistat_rows as $r) { $eistat_page_urls[$r->page_type . '|' . $r->page_id] = $r->page_url; } } // --- Summary by link type --- // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $eistat_by_type = $wpdb->get_results($wpdb->prepare( "SELECT link_type, SUM(count) AS c FROM {$eistat_p}events WHERE date >= DATE_SUB(CURDATE(), INTERVAL %d DAY) GROUP BY link_type ORDER BY c DESC", $days )); $eistat_type_labels = [ 'outbound' => __('External links', 'statinform'), 'email' => __('Email', 'statinform'), 'phone' => __('Phone', 'statinform'), ]; $eistat_type_totals = ['outbound' => 0, 'email' => 0, 'phone' => 0]; $eistat_grand_total = 0; foreach ($eistat_by_type as $t) { $eistat_type_totals[$t->link_type] = (int) $t->c; $eistat_grand_total += (int) $t->c; } ?>

$eistat_label): ?>
0 ? round($eistat_type_totals[$eistat_key] / $eistat_grand_total * 100, 1) : 0; /* translators: %s: percentage of all clicks */ echo esc_html(sprintf(__('%s%% of all clicks', 'statinform'), $eistat_pct)); ?>
$eistat_label): ?>

link_url); ?> link_text)): ?>
link_text); ?>
link_type] ?? $l->link_type); ?> c)); ?>

page_type . '|' . $tp->page_id; $eistat_url = $eistat_page_urls[$eistat_key] ?? ''; ?>
page_type, (int) $tp->page_id)); ?> c)); ?>