Changeset 3436270
- Timestamp:
- 01/09/2026 07:49:25 PM (3 months ago)
- Location:
- digi-report/trunk
- Files:
-
- 2 edited
-
digi-report.php (modified) (7 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
digi-report/trunk/digi-report.php
r3436214 r3436270 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. 55 Version: 2.7.6 6 6 Author: DigiPerforma - Marketing Digital [digiperforma.com.br] 7 7 License: GPLv2 or later … … 91 91 92 92 <?php if ($analytics['active']): ?> 93 <h2 class="digi-section-title">Tráfego (Últimos 30 dias)</h2> 94 <div class="digi-card-row"> 95 <div class="digi-card"><h3>Visualizações</h3><p><?php echo esc_html($analytics['views']); ?></p></div> 96 <div class="digi-card"><h3>Visitantes</h3><p><?php echo esc_html($analytics['visitors']); ?></p></div> 97 </div> 98 <div class="digi-card-row"> 99 <div class="digi-card" style="text-align: left;"> 100 <h3>Top Páginas</h3> 101 <ul style="margin:0; padding-left: 20px; font-size: 0.9em; color: #555;"> 102 <?php foreach($analytics['top_pages'] as $page) echo "<li>" . esc_html($page['name']) . " <strong>(" . esc_html($page['views']) . ")</strong></li>"; ?> 103 </ul> 104 </div> 105 <div class="digi-card" style="text-align: left;"> 106 <h3>Top Cidades</h3> 107 <ul style="margin:0; padding-left: 20px; font-size: 0.9em; color: #555;"> 108 <?php foreach($analytics['top_cities'] as $city) echo "<li>" . esc_html($city['city']) . " <strong>(" . esc_html($city['visitors']) . ")</strong></li>"; ?> 109 </ul> 110 </div> 111 </div> 93 94 <h2 class="digi-section-title">Tráfego (Últimos 30 dias)</h2> 95 <div class="digi-card-row"> 96 <div class="digi-card"><h3>Visualizações</h3><p><?php echo esc_html($analytics['views']); ?></p></div> 97 <div class="digi-card"><h3>Visitantes</h3><p><?php echo esc_html($analytics['visitors']); ?></p></div> 98 </div> 99 100 <?php if ($analytics['views'] == 0): ?> 101 <div class="notice notice-info inline" style="display:block; margin-bottom: 20px;"> 102 <p><strong>Diagnóstico de Dados (Visível apenas quando Views = 0):</strong></p> 103 <div style="background:#fff; padding:10px; border:1px solid #ccc;"> 104 1. Tabela conectada: <code><?php echo esc_html($analytics['debug_table']); ?></code><br> 105 2. Total de Visualizações na HISTÓRIA do site (sem filtro de data): <strong><?php echo esc_html($analytics['debug_total_lifetime']); ?></strong><br> 106 3. Última data registrada no banco: <strong><?php echo esc_html($analytics['debug_last_date']); ?></strong><br> 107 4. Tentamos buscar dados de: <strong><?php echo esc_html($analytics['debug_start_date']); ?></strong> até <strong><?php echo esc_html($analytics['debug_end_date']); ?></strong> 108 </div> 109 </div> 110 <?php endif; ?> 111 112 <div class="digi-card-row"> 113 <div class="digi-card" style="text-align: left;"> 114 <h3>Top Páginas</h3> 115 <ul style="margin:0; padding-left: 20px; font-size: 0.9em; color: #555;"> 116 <?php foreach($analytics['top_pages'] as $page) echo "<li>" . esc_html($page['name']) . " <strong>(" . esc_html($page['views']) . ")</strong></li>"; ?> 117 </ul> 118 </div> 119 <div class="digi-card" style="text-align: left;"> 120 <h3>Top Cidades</h3> 121 <ul style="margin:0; padding-left: 20px; font-size: 0.9em; color: #555;"> 122 <?php foreach($analytics['top_cities'] as $city) echo "<li>" . esc_html($city['city']) . " <strong>(" . esc_html($city['visitors']) . ")</strong></li>"; ?> 123 </ul> 124 </div> 125 </div> 126 112 127 <?php else: ?> 113 <div class="notice notice-warning inline"><p><strong>Status do Analytics:</strong> Não detectado. Certifique-se de que o plugin <em>Independent Analytics</em> está ativo.</p></div> 128 <div class="notice notice-warning inline" style="display:block;"> 129 <p><strong>Status do Analytics:</strong> Não detectado.</p> 130 <p>O sistema não encontrou tabelas com o final <code>_ia_views</code> no banco de dados.</p> 131 </div> 114 132 <?php endif; ?> 115 133 … … 135 153 136 154 // ========================================================= 137 // 2. FUNÇÃO: AUTO-DETECÇÃO CORRIGIDA (NOME LONGO)155 // 2. FUNÇÃO: AUTO-DETECÇÃO + DEBUG 138 156 // ========================================================= 139 157 function digi_report_get_analytics_data() { 140 158 global $wpdb; 141 159 142 // DEFINIÇÃO CORRETA BASEADA NO SEU LOG: 143 // O plugin usa "independent_analytics_views" e não "ia_views" 144 $table_views = $wpdb->prefix . 'independent_analytics_views'; 145 $table_sessions = $wpdb->prefix . 'independent_analytics_sessions'; 160 // 1. PROCURA A TABELA CORRETA 161 $found_views_table = $wpdb->get_var("SHOW TABLES LIKE '%ia_views'"); 162 $found_sessions_table = $wpdb->get_var("SHOW TABLES LIKE '%ia_sessions'"); 146 163 147 164 // Datas (Últimos 30 dias) … … 149 166 $end_date = date('Y-m-d'); 150 167 151 // Verifica se a tabela principal existe 152 if ($wpdb->get_var("SHOW TABLES LIKE '$table_views'") != $table_views) { 153 // Fallback: Se não achar o nome longo, tenta o curto (só por garantia) 154 $table_views = $wpdb->prefix . 'ia_views'; 155 $table_sessions = $wpdb->prefix . 'ia_sessions'; 156 157 if ($wpdb->get_var("SHOW TABLES LIKE '$table_views'") != $table_views) { 158 return array('active' => false); 159 } 168 if (!$found_views_table) { 169 return array('active' => false); 160 170 } 161 171 162 // Se achou a tabela, executa as queries 163 $views = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_views WHERE `date` BETWEEN %s AND %s", $start_date, $end_date)); 164 $visitors = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_sessions WHERE `date` BETWEEN %s AND %s", $start_date, $end_date)); 172 // --- DEBUG: Busca TOTAL SEM DATA (Para saber se o banco está vazio ou é só a data) --- 173 $total_lifetime_views = $wpdb->get_var("SELECT COUNT(*) FROM $found_views_table"); 174 $last_date_entry = $wpdb->get_var("SELECT MAX(`date`) FROM $found_views_table"); 175 // ---------------------------------------------------------------------------------- 176 177 // Busca Oficial (Filtrada) 178 $views = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $found_views_table WHERE `date` BETWEEN %s AND %s", $start_date, $end_date)); 179 $visitors = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $found_sessions_table WHERE `date` BETWEEN %s AND %s", $start_date, $end_date)); 165 180 166 181 $top_pages = $wpdb->get_results($wpdb->prepare( 167 "SELECT page_path as name, COUNT(*) as views FROM $ table_viewsWHERE `date` BETWEEN %s AND %s GROUP BY page_path ORDER BY views DESC LIMIT 3",182 "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", 168 183 $start_date, $end_date 169 184 ), ARRAY_A); 170 185 171 186 $top_cities = $wpdb->get_results($wpdb->prepare( 172 "SELECT city, COUNT(*) as visitors FROM $ table_sessionsWHERE `date` BETWEEN %s AND %s AND city != '' GROUP BY city ORDER BY visitors DESC LIMIT 3",187 "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", 173 188 $start_date, $end_date 174 189 ), ARRAY_A); … … 179 194 'visitors' => number_format_i18n((int)$visitors), 180 195 'top_pages' => $top_pages ?: array(), 181 'top_cities' => $top_cities ?: array() 196 'top_cities' => $top_cities ?: array(), 197 // Dados de Debug 198 'debug_table' => $found_views_table, 199 'debug_total_lifetime' => $total_lifetime_views, 200 'debug_last_date' => $last_date_entry, 201 'debug_start_date' => $start_date, 202 'debug_end_date' => $end_date 182 203 ); 183 204 } 184 205 185 206 // ========================================================= 186 // 3. ENVIO DE E-MAIL 207 // 3. ENVIO DE E-MAIL (Sem alterações nesta versão) 187 208 // ========================================================= 188 209 function meu_plugin_relatorios_enviar() { … … 195 216 $msg_final = empty($msg_raw) ? "Mantivemos o monitoramento ativo. Confira abaixo os resultados de tráfego (últimos 30 dias) e as atualizações de segurança." : nl2br(esc_html($msg_raw)); 196 217 197 // DADOS PARA E-MAIL198 218 global $wpdb; 199 219 $start_date = date('Y-m-d H:i:s', strtotime('-30 days')); … … 304 324 } 305 325 } 306 // Ganchos (Manter iguais) 326 327 // Ganchos (iguais) 307 328 function meu_plugin_relatorios_agendar() { if (!wp_next_scheduled('meu_plugin_relatorios_gancho')) wp_schedule_event(time(), 'daily', 'meu_plugin_relatorios_gancho'); } 308 329 add_action('wp', 'meu_plugin_relatorios_agendar'); -
digi-report/trunk/readme.txt
r3436214 r3436270 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 2.7. 56 Stable tag: 2.7.6 7 7 Requires PHP: 7.2 8 8 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.