Changeset 3437504
- Timestamp:
- 01/12/2026 09:24:43 AM (2 months ago)
- Location:
- digi-report/trunk
- Files:
-
- 2 edited
-
digi-report.php (modified) (5 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
digi-report/trunk/digi-report.php
r3437494 r3437504 3 3 Plugin Name: Digi Report 4 4 Description: A plugin that generates and sends WordPress maintenance reports via email (Integrated with Independent Analytics). 5 Version: 2.8. 05 Version: 2.8.1 6 6 Author: DigiPerforma - Marketing Digital [digiperforma.com.br] 7 7 License: GPLv2 or later … … 98 98 </div> 99 99 100 <?php if ( $analytics['visitors'] == 0): ?>100 <?php if (empty($analytics['top_pages'])): ?> 101 101 <div class="notice notice-info inline" style="display:block; margin-bottom: 20px;"> 102 <p><strong>Diagnóstico da Tabela de Sessões:</strong></p> 103 <p>Precisamos saber o nome da coluna de data da tabela de sessões para contar os visitantes corretamente. Copie a lista abaixo:</p> 104 <div style="background:#fff; padding:10px; border:1px solid #ccc; max-height: 200px; overflow: auto;"> 105 <strong>Colunas em <?php echo esc_html($analytics['debug_table_sessions']); ?>:</strong><br> 106 <?php 107 if (!empty($analytics['debug_columns_sessions'])) { 108 echo '<ul style="list-style: disc; padding-left: 20px; margin-top: 5px;">'; 109 foreach ($analytics['debug_columns_sessions'] as $col) { 110 echo '<li>' . esc_html($col->Field) . ' (' . esc_html($col->Type) . ')</li>'; 111 } 112 echo '</ul>'; 113 } else { 114 echo 'Erro ao ler colunas.'; 115 } 116 ?> 102 <p><strong>Fase Final - Mapeamento de Tabelas:</strong></p> 103 <p>Ótimo! Os totais já devem estar aparecendo. Copie os dados abaixo para ativarmos os "Top Páginas" e "Top Cidades":</p> 104 <div style="background:#fff; padding:10px; border:1px solid #ccc; max-height: 300px; overflow: auto;"> 105 <strong>Tabela Resources (Páginas):</strong><br> 106 <?php digi_print_columns($analytics['debug_table_resources']); ?> 107 <br> 108 <strong>Tabela Cities (Cidades):</strong><br> 109 <?php digi_print_columns($analytics['debug_table_cities']); ?> 117 110 </div> 118 111 </div> … … 162 155 } 163 156 164 // ========================================================= 165 // 2. FUNÇÃO: CORREÇÃO V2.0 (VIEWED_AT) 157 function digi_print_columns($table_name) { 158 global $wpdb; 159 $cols = $wpdb->get_results("SHOW COLUMNS FROM $table_name"); 160 if ($cols) { 161 echo '<ul style="list-style: disc; padding-left: 20px; margin-top: 5px;">'; 162 foreach ($cols as $col) echo '<li>' . esc_html($col->Field) . ' (' . esc_html($col->Type) . ')</li>'; 163 echo '</ul>'; 164 } else { 165 echo 'Tabela não encontrada ou vazia.'; 166 } 167 } 168 169 // ========================================================= 170 // 2. FUNÇÃO: VISITANTES CORRIGIDO + MAPEAMENTO 166 171 // ========================================================= 167 172 function digi_report_get_analytics_data() { … … 171 176 $table_views = $wpdb->prefix . 'independent_analytics_views'; 172 177 $table_sessions = $wpdb->prefix . 'independent_analytics_sessions'; 173 174 // Datas (Últimos 30 dias) 178 // Tabelas Auxiliares (Adivinhando nomes padrão para debug) 179 $table_resources = $wpdb->prefix . 'independent_analytics_resources'; 180 $table_cities = $wpdb->prefix . 'independent_analytics_cities'; 181 175 182 $start_date = date('Y-m-d H:i:s', strtotime('-30 days')); 176 183 $end_date = date('Y-m-d H:i:s'); 177 184 178 // 1. Verifica se tabela views existe179 185 if ($wpdb->get_var("SHOW TABLES LIKE '$table_views'") != $table_views) { 180 186 return array('active' => false); 181 187 } 182 188 183 // 2. BUSCA VISUALIZAÇÕES (Agora usando a coluna CERTA:viewed_at)189 // 1. VISUALIZAÇÕES (OK - viewed_at) 184 190 $views = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_views WHERE `viewed_at` BETWEEN %s AND %s", $start_date, $end_date)); 185 191 186 // 3. BUSCA VISITANTES (Tentando adivinhar 'start_time', se falhar, retorna 0 e pedimos debug) 187 // Suprime erro temporariamente para não quebrar o site se a coluna for outra 188 $wpdb->suppress_errors(); 189 $visitors = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_sessions WHERE `start_time` BETWEEN %s AND %s", $start_date, $end_date)); 190 $wpdb->suppress_errors(false); 191 192 // Se falhou (null), tenta pegar colunas para debug 193 $debug_columns_sessions = array(); 194 if ($visitors === null) { 195 $visitors = 0; 196 $debug_columns_sessions = $wpdb->get_results("SHOW COLUMNS FROM $table_sessions"); 197 } 198 199 // TOP PÁGINAS E CIDADES DESATIVADOS TEMPORARIAMENTE (Retornam array vazio) 200 // Motivo: Requer JOIN complexo com novas tabelas (wp_independent_analytics_resources / cities) 201 // Vamos focar em fazer os totais funcionarem primeiro. 202 192 // 2. VISITANTES (CORRIGIDO - created_at) 193 $visitors = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_sessions WHERE `created_at` BETWEEN %s AND %s", $start_date, $end_date)); 194 195 // TOP PÁGINAS E CIDADES (Desativados, aguardando nomes das colunas) 196 203 197 return array( 204 198 'active' => true, 205 199 'views' => number_format_i18n((int)$views), 206 200 'visitors' => number_format_i18n((int)$visitors), 207 'top_pages' => array(), // Em breve208 'top_cities' => array(), // Em breve209 // Debug 210 'debug_table_ sessions' => $table_sessions,211 'debug_ columns_sessions' => $debug_columns_sessions201 'top_pages' => array(), 202 'top_cities' => array(), 203 // Debug para próxima fase 204 'debug_table_resources' => $table_resources, 205 'debug_table_cities' => $table_cities 212 206 ); 213 207 } … … 243 237 $html_analytics = ''; 244 238 if ($analytics['active']) { 245 // Layout simplificado (sem Top Pages por enquanto)246 239 $html_analytics = ' 247 240 <h3 style="text-align: center; margin-top: 30px; color: #f4ab1d; text-transform: uppercase;">Performance (30 Dias)</h3> -
digi-report/trunk/readme.txt
r3437494 r3437504 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 2.8. 06 Stable tag: 2.8.1 7 7 Requires PHP: 7.2 8 8 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.