Changeset 3437494
- Timestamp:
- 01/12/2026 09:17:40 AM (2 months ago)
- Location:
- digi-report/trunk
- Files:
-
- 2 edited
-
digi-report.php (modified) (9 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
digi-report/trunk/digi-report.php
r3436293 r3437494 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. 7.85 Version: 2.8.0 6 6 Author: DigiPerforma - Marketing Digital [digiperforma.com.br] 7 7 License: GPLv2 or later … … 98 98 </div> 99 99 100 <?php if ($analytics['vi ews'] == 0): ?>100 <?php if ($analytics['visitors'] == 0): ?> 101 101 <div class="notice notice-info inline" style="display:block; margin-bottom: 20px;"> 102 <p><strong>Diagnóstico de Colunas (Copie a lista abaixo e me mande):</strong></p> 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> 103 104 <div style="background:#fff; padding:10px; border:1px solid #ccc; max-height: 200px; overflow: auto;"> 104 <strong>Colunas e ncontradas na tabela <?php echo esc_html($analytics['debug_table']); ?>:</strong><br>105 <strong>Colunas em <?php echo esc_html($analytics['debug_table_sessions']); ?>:</strong><br> 105 106 <?php 106 if (!empty($analytics['debug_columns '])) {107 if (!empty($analytics['debug_columns_sessions'])) { 107 108 echo '<ul style="list-style: disc; padding-left: 20px; margin-top: 5px;">'; 108 foreach ($analytics['debug_columns '] as $col) {109 foreach ($analytics['debug_columns_sessions'] as $col) { 109 110 echo '<li>' . esc_html($col->Field) . ' (' . esc_html($col->Type) . ')</li>'; 110 111 } 111 112 echo '</ul>'; 112 113 } else { 113 echo ' Nenhuma coluna listada.';114 echo 'Erro ao ler colunas.'; 114 115 } 115 116 ?> … … 118 119 <?php endif; ?> 119 120 121 <?php if (!empty($analytics['top_pages'])): ?> 120 122 <div class="digi-card-row"> 121 123 <div class="digi-card" style="text-align: left;"> … … 132 134 </div> 133 135 </div> 136 <?php endif; ?> 134 137 135 138 <?php else: ?> 136 139 <div class="notice notice-warning inline" style="display:block;"> 137 140 <p><strong>Status do Analytics:</strong> Não detectado.</p> 138 <p>O sistema não encontrou tabelas com o final <code>_independent_analytics_views</code> no banco de dados.</p>139 141 </div> 140 142 <?php endif; ?> … … 161 163 162 164 // ========================================================= 163 // 2. FUNÇÃO: AUTO-DETECÇÃO + LISTA DE COLUNAS165 // 2. FUNÇÃO: CORREÇÃO V2.0 (VIEWED_AT) 164 166 // ========================================================= 165 167 function digi_report_get_analytics_data() { 166 168 global $wpdb; 167 169 168 // 1. PROCURA A TABELA CORRETA169 $ found_views_table = $wpdb->get_var("SHOW TABLES LIKE '%independent_analytics_views'");170 $ found_sessions_table = $wpdb->get_var("SHOW TABLES LIKE '%independent_analytics_sessions'");170 // NOMES DAS TABELAS 171 $table_views = $wpdb->prefix . 'independent_analytics_views'; 172 $table_sessions = $wpdb->prefix . 'independent_analytics_sessions'; 171 173 172 174 // Datas (Últimos 30 dias) 173 $start_date = date('Y-m-d', strtotime('-30 days')); 174 $end_date = date('Y-m-d'); 175 176 if (!$found_views_table) { 175 $start_date = date('Y-m-d H:i:s', strtotime('-30 days')); 176 $end_date = date('Y-m-d H:i:s'); 177 178 // 1. Verifica se tabela views existe 179 if ($wpdb->get_var("SHOW TABLES LIKE '$table_views'") != $table_views) { 177 180 return array('active' => false); 178 181 } 179 182 180 // --- DEBUG: PEGA AS COLUNAS DA TABELA --- 181 $columns = $wpdb->get_results("SHOW COLUMNS FROM $found_views_table"); 182 // ---------------------------------------- 183 184 // Busca Oficial (Tentando usar 'date' - se falhar vai dar zero) 185 $views = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $found_views_table WHERE `date` BETWEEN %s AND %s", $start_date, $end_date)); 186 $visitors = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $found_sessions_table WHERE `date` BETWEEN %s AND %s", $start_date, $end_date)); 187 188 // Se a busca por data falhou (views=0), vamos tentar pegar sem filtro só pra garantir que o SELECT funciona 189 // (Lógica removida pra simplificar, vamos focar nas colunas) 190 191 $top_pages = $wpdb->get_results($wpdb->prepare( 192 "SELECT page_path as name, COUNT(*) as views FROM $found_views_table WHERE `date` BETWEEN %s AND %s GROUP BY page_path ORDER BY views DESC LIMIT 3", 193 $start_date, $end_date 194 ), ARRAY_A); 195 196 $top_cities = $wpdb->get_results($wpdb->prepare( 197 "SELECT city, COUNT(*) as visitors FROM $found_sessions_table WHERE `date` BETWEEN %s AND %s AND city != '' GROUP BY city ORDER BY visitors DESC LIMIT 3", 198 $start_date, $end_date 199 ), ARRAY_A); 183 // 2. BUSCA VISUALIZAÇÕES (Agora usando a coluna CERTA: viewed_at) 184 $views = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_views WHERE `viewed_at` BETWEEN %s AND %s", $start_date, $end_date)); 185 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. 200 202 201 203 return array( … … 203 205 'views' => number_format_i18n((int)$views), 204 206 'visitors' => number_format_i18n((int)$visitors), 205 'top_pages' => $top_pages ?: array(),206 'top_cities' => $top_cities ?: array(),207 // D ados de Debug208 'debug_table ' => $found_views_table,209 'debug_columns ' => $columns207 'top_pages' => array(), // Em breve 208 'top_cities' => array(), // Em breve 209 // Debug 210 'debug_table_sessions' => $table_sessions, 211 'debug_columns_sessions' => $debug_columns_sessions 210 212 ); 211 213 } 212 214 213 215 // ========================================================= 214 // 3. ENVIO DE E-MAIL (Sem alterações)216 // 3. ENVIO DE E-MAIL 215 217 // ========================================================= 216 218 function meu_plugin_relatorios_enviar() { … … 241 243 $html_analytics = ''; 242 244 if ($analytics['active']) { 243 $li_pages = ''; 244 foreach($analytics['top_pages'] as $p) $li_pages .= "<li>{$p['name']} <strong>({$p['views']})</strong></li>"; 245 if(empty($li_pages)) $li_pages = '<li>Sem dados suficientes</li>'; 246 247 $li_cities = ''; 248 foreach($analytics['top_cities'] as $c) $li_cities .= "<li>{$c['city']} <strong>({$c['visitors']})</strong></li>"; 249 if(empty($li_cities)) $li_cities = '<li>Sem dados suficientes</li>'; 250 245 // Layout simplificado (sem Top Pages por enquanto) 251 246 $html_analytics = ' 252 247 <h3 style="text-align: center; margin-top: 30px; color: #f4ab1d; text-transform: uppercase;">Performance (30 Dias)</h3> … … 266 261 </td> 267 262 </tr> 268 </table>269 <table style="width: 100%; border-collapse: collapse; margin-top: 10px;">270 <tr>271 <td style="padding: 5px; vertical-align: top; width: 50%;">272 <div style="background: #fff; border: 1px solid #e9e9e9; padding: 15px; height: 100%;">273 <div style="font-weight: bold; margin-bottom: 10px; color: #444;">Top Páginas</div>274 <ul style="padding-left: 20px; margin: 0; font-size: 0.85em; color: #666; line-height: 1.6;">'.$li_pages.'</ul>275 </div>276 </td>277 <td style="padding: 5px; vertical-align: top; width: 50%;">278 <div style="background: #fff; border: 1px solid #e9e9e9; padding: 15px; height: 100%;">279 <div style="font-weight: bold; margin-bottom: 10px; color: #444;">Top Cidades</div>280 <ul style="padding-left: 20px; margin: 0; font-size: 0.85em; color: #666; line-height: 1.6;">'.$li_cities.'</ul>281 </div>282 </td>283 </tr>284 263 </table>'; 285 264 } … … 331 310 } 332 311 } 333 334 312 // Ganchos (Manter iguais) 335 313 function meu_plugin_relatorios_agendar() { if (!wp_next_scheduled('meu_plugin_relatorios_gancho')) wp_schedule_event(time(), 'daily', 'meu_plugin_relatorios_gancho'); } -
digi-report/trunk/readme.txt
r3436293 r3437494 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 2. 7.86 Stable tag: 2.8.0 7 7 Requires PHP: 7.2 8 8 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.