Changeset 3436160
- Timestamp:
- 01/09/2026 05:17:57 PM (3 months ago)
- Location:
- digi-report/trunk
- Files:
-
- 2 edited
-
digi-report.php (modified) (15 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
digi-report/trunk/digi-report.php
r3436145 r3436160 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. 15 Version: 2.7.2 6 6 Author: DigiPerforma - Marketing Digital [digiperforma.com.br] 7 7 License: GPLv2 or later … … 24 24 25 25 function meu_plugin_relatorios_menu() { 26 // ALTERAÇÃO: Nome do menu na sidebar mudado para"DigiReport"26 // Força o nome "DigiReport" 27 27 add_options_page('Configurações do Relatório', 'DigiReport', 'manage_options', 'meu-plugin-relatorios', 'meu_plugin_relatorios_pagina'); 28 28 } … … 41 41 } 42 42 43 // Dados Salvos44 43 $email_destino = get_option('meu_plugin_relatorios_email'); 45 44 $email_opcional = get_option('meu_plugin_relatorios_email_opcional'); … … 47 46 $mensagem_mes = get_option('meu_plugin_relatorios_mensagem', ''); 48 47 49 // --- COLETA DE DADOS (Restaurada para 5 itens)---48 // --- COLETA DE DADOS --- 50 49 global $wpdb; 51 $one_month_ago = gmdate('Y-m-d H:i:s', strtotime('-1 month', current_time('timestamp'))); 50 51 // Mudança: Agora pegamos dados dos últimos 30 dias para garantir que apareça algo 52 $start_date = date('Y-m-d H:i:s', strtotime('-30 days')); 52 53 53 54 // 1. Criados 54 $args_criados = array('post_type' => array('post', 'page'), 'post_status' => 'publish', 'date_query' => array(array('after' => ' 1 monthago')), 'fields' => 'ids');55 $args_criados = array('post_type' => array('post', 'page'), 'post_status' => 'publish', 'date_query' => array(array('after' => '30 days ago')), 'fields' => 'ids'); 55 56 $posts_criados = (new WP_Query($args_criados))->found_posts ?: '0'; 56 57 57 // 2. Atualizados (Conteúdo)58 $posts_atualizados = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ('post', 'page') AND post_status = 'publish' AND post_modified > post_date AND post_modified >= %s", $ one_month_ago));58 // 2. Atualizados 59 $posts_atualizados = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ('post', 'page') AND post_status = 'publish' AND post_modified > post_date AND post_modified >= %s", $start_date)); 59 60 $posts_atualizados_texto = ($posts_atualizados > 0) ? $posts_atualizados : '0'; 60 61 61 // 3. Plugins62 62 $plugins_atualizados = count(get_option('meu_plugin_relatorios_plugins_atualizados', array())); 63 64 // 4. WordPress Core65 63 $wp_core_updates = count(get_option('meu_plugin_relatorios_wp_atualizacoes', array())); 66 64 67 // 5. Spam68 65 $spam_count = wp_count_comments(); 69 66 $spam_bloqueado = isset($spam_count->spam) ? $spam_count->spam : 0; 70 67 71 // Coleta de Dados do Independent Analytics72 68 $analytics = digi_report_get_analytics_data(); 73 69 … … 88 84 <h1 style="text-align: center; color: #444;">Painel DigiReport</h1> 89 85 90 <h2 class="digi-section-title">Manutenção & Segurança</h2>86 <h2 class="digi-section-title">Manutenção (Últimos 30 dias)</h2> 91 87 <div class="digi-card-row"> 92 88 <div class="digi-card"><h3>Posts/Páginas Criados</h3><p><?php echo esc_html($posts_criados); ?></p></div> … … 98 94 99 95 <?php if ($analytics['active']): ?> 100 <h2 class="digi-section-title"> Performance (Independent Analytics)</h2>96 <h2 class="digi-section-title">Tráfego (Últimos 30 dias)</h2> 101 97 <div class="digi-card-row"> 102 98 <div class="digi-card"><h3>Visualizações</h3><p><?php echo esc_html($analytics['views']); ?></p></div> … … 105 101 <div class="digi-card-row"> 106 102 <div class="digi-card" style="text-align: left;"> 107 <h3>Top 3Páginas</h3>103 <h3>Top Páginas</h3> 108 104 <ul style="margin:0; padding-left: 20px; font-size: 0.9em; color: #555;"> 109 105 <?php foreach($analytics['top_pages'] as $page) echo "<li>" . esc_html($page['name']) . " <strong>(" . esc_html($page['views']) . ")</strong></li>"; ?> … … 111 107 </div> 112 108 <div class="digi-card" style="text-align: left;"> 113 <h3>Top 3Cidades</h3>109 <h3>Top Cidades</h3> 114 110 <ul style="margin:0; padding-left: 20px; font-size: 0.9em; color: #555;"> 115 111 <?php foreach($analytics['top_cities'] as $city) echo "<li>" . esc_html($city['city']) . " <strong>(" . esc_html($city['visitors']) . ")</strong></li>"; ?> … … 118 114 </div> 119 115 <?php else: ?> 120 <div class="notice notice-warning inline"><p><strong> Atenção:</strong> O plugin "Independent Analytics" não foi detectado ou ainda não possui dados. Instale-o para ver métricas de tráfego aqui.</p></div>116 <div class="notice notice-warning inline"><p><strong>Status do Analytics:</strong> Não detectamos dados recentes. Certifique-se de que o plugin <em>Independent Analytics</em> está ativo e que o site teve visitas nos últimos 30 dias.</p></div> 121 117 <?php endif; ?> 122 118 … … 147 143 global $wpdb; 148 144 149 // ALTERAÇÃO: Verifica se a opção do Independent Analytics existe 150 // Essa é a maneira mais segura de saber se o plugin está instalado 151 $ia_version = get_option('ia_db_version'); 152 153 // Se a opção não existe, assume que o plugin não está instalado 154 if (!$ia_version) { 145 // Tabelas do Independent Analytics 146 $table_views = $wpdb->prefix . 'ia_views'; 147 $table_sessions = $wpdb->prefix . 'ia_sessions'; 148 149 // AJUSTE CRÍTICO: Usa 'Last 30 days' ao invés de 'Last Month' 150 // Isso garante que se você instalou hoje, já aparece dados de hoje. 151 $start_date = date('Y-m-d', strtotime('-30 days')); 152 $end_date = date('Y-m-d'); 153 154 // Verifica se a tabela existe de forma bruta (mais garantido) 155 if ($wpdb->get_var("SHOW TABLES LIKE '$table_views'") != $table_views) { 155 156 return array('active' => false); 156 157 } 157 158 158 // Tabelas 159 $table_views = $wpdb->prefix . 'ia_views'; 160 $table_sessions = $wpdb->prefix . 'ia_sessions'; 161 162 // Período: Mês Passado 163 $first_day = date('Y-m-01', strtotime('last month')); 164 $last_day = date('Y-m-t', strtotime('last month')); 165 166 // Tenta buscar os dados. Se der erro SQL (tabela não existe), captura silenciavelmente. 167 $views = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_views WHERE `date` BETWEEN %s AND %s", $first_day, $last_day)); 168 169 if ($views === null) { 170 return array('active' => false); // Tabela não encontrada 171 } 172 173 $visitors = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_sessions WHERE `date` BETWEEN %s AND %s", $first_day, $last_day)); 159 // Tenta buscar visualizações 160 $views = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_views WHERE `date` BETWEEN %s AND %s", $start_date, $end_date)); 161 162 // Se retornou NULL ou zero, pode ser que não tenha dados, mas a tabela existe. 163 // Vamos considerar ativo se a tabela existe, mesmo que views seja 0. 164 165 $visitors = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $table_sessions WHERE `date` BETWEEN %s AND %s", $start_date, $end_date)); 174 166 175 167 $top_pages = $wpdb->get_results($wpdb->prepare( 176 168 "SELECT page_path as name, COUNT(*) as views FROM $table_views WHERE `date` BETWEEN %s AND %s GROUP BY page_path ORDER BY views DESC LIMIT 3", 177 $ first_day, $last_day169 $start_date, $end_date 178 170 ), ARRAY_A); 179 171 180 172 $top_cities = $wpdb->get_results($wpdb->prepare( 181 173 "SELECT city, COUNT(*) as visitors FROM $table_sessions WHERE `date` BETWEEN %s AND %s AND city != '' GROUP BY city ORDER BY visitors DESC LIMIT 3", 182 $ first_day, $last_day174 $start_date, $end_date 183 175 ), ARRAY_A); 184 176 … … 193 185 194 186 // ========================================================= 195 // 3. ENVIO DE E-MAIL (TEMPLATE ATUALIZADO)187 // 3. ENVIO DE E-MAIL 196 188 // ========================================================= 197 189 function meu_plugin_relatorios_enviar() { … … 202 194 203 195 $msg_raw = get_option('meu_plugin_relatorios_mensagem', ''); 204 $msg_final = empty($msg_raw) ? "Mantivemos o monitoramento ativo. Confira abaixo os resultados de tráfego e as atualizações de segurança realizadas no período." : nl2br(esc_html($msg_raw));205 206 // COLETA PARA E-MAIL (5 ITENS)196 $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)); 197 198 // DADOS PARA E-MAIL (Mesma lógica de 30 dias) 207 199 global $wpdb; 208 $one_month_ago = gmdate('Y-m-d H:i:s', strtotime('-1 month', current_time('timestamp'))); 209 210 // Criados 211 $args_criados = array('post_type' => array('post', 'page'), 'post_status' => 'publish', 'date_query' => array(array('after' => '1 month ago')), 'fields' => 'ids'); 200 $start_date = date('Y-m-d H:i:s', strtotime('-30 days')); 201 202 $args_criados = array('post_type' => array('post', 'page'), 'post_status' => 'publish', 'date_query' => array(array('after' => '30 days ago')), 'fields' => 'ids'); 212 203 $posts_criados_txt = (new WP_Query($args_criados))->found_posts ?: '-'; 213 204 214 // Atualizados 215 $posts_atualizados_num = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ('post', 'page') AND post_status = 'publish' AND post_modified > post_date AND post_modified >= %s", $one_month_ago)); 205 $posts_atualizados_num = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ('post', 'page') AND post_status = 'publish' AND post_modified > post_date AND post_modified >= %s", $start_date)); 216 206 $posts_atualizados_txt = ($posts_atualizados_num > 0) ? $posts_atualizados_num : '-'; 217 207 218 // Plugins219 208 $plugins_txt = count(get_option('meu_plugin_relatorios_plugins_atualizados', array())) ?: '-'; 220 221 // WP Core222 209 $wp_core_txt = count(get_option('meu_plugin_relatorios_wp_atualizacoes', array())) ?: '-'; 223 224 // Spam225 210 $spam_count = wp_count_comments(); 226 211 $spam_txt = isset($spam_count->spam) ? $spam_count->spam : '-'; 227 212 228 // Analytics229 213 $analytics = digi_report_get_analytics_data(); 230 214 … … 240 224 241 225 $html_analytics = ' 242 <h3 style="text-align: center; margin-top: 30px; color: #f4ab1d; text-transform: uppercase;">Performance de Acesso</h3>226 <h3 style="text-align: center; margin-top: 30px; color: #f4ab1d; text-transform: uppercase;">Performance (30 Dias)</h3> 243 227 <table style="width: 100%; border-collapse: collapse;"> 244 228 <tr> … … 321 305 } 322 306 } 323 324 // Ganchos 307 // Ganchos... (resto do arquivo igual) 325 308 function meu_plugin_relatorios_agendar() { if (!wp_next_scheduled('meu_plugin_relatorios_gancho')) wp_schedule_event(time(), 'daily', 'meu_plugin_relatorios_gancho'); } 326 309 add_action('wp', 'meu_plugin_relatorios_agendar'); … … 328 311 add_action('meu_plugin_relatorios_gancho', 'meu_plugin_relatorios_verifica_dia'); 329 312 register_deactivation_hook(__FILE__, function() { wp_unschedule_event(wp_next_scheduled('meu_plugin_relatorios_gancho'), 'meu_plugin_relatorios_gancho'); }); 330 331 function meu_plugin_relatorios_teste_envio() { 332 if (isset($_POST['meu_plugin_relatorios_teste']) && check_admin_referer('meu_plugin_relatorios_teste', 'meu_plugin_relatorios_teste_nonce')) { 333 meu_plugin_relatorios_enviar(); 334 add_action('admin_notices', function() { echo '<div class="notice notice-success is-dismissible"><p>Relatório de teste enviado com sucesso!</p></div>'; }); 335 } 336 } 313 function meu_plugin_relatorios_teste_envio() { if (isset($_POST['meu_plugin_relatorios_teste']) && check_admin_referer('meu_plugin_relatorios_teste', 'meu_plugin_relatorios_teste_nonce')) { meu_plugin_relatorios_enviar(); add_action('admin_notices', function() { echo '<div class="notice notice-success is-dismissible"><p>Relatório de teste enviado com sucesso!</p></div>'; }); } } 337 314 add_action('admin_init', 'meu_plugin_relatorios_teste_envio'); 338 339 function meu_plugin_monitora_updates($upgrader, $options) { 340 if ($options['action'] === 'update' && $options['type'] === 'plugin' && !empty($options['plugins'])) { 341 $atual = get_option('meu_plugin_relatorios_plugins_atualizados', array()); 342 foreach ($options['plugins'] as $f) { $d = get_plugin_data(WP_PLUGIN_DIR.'/'.$f); $atual[] = array('nome' => $d['Name'], 'data' => gmdate('Y-m-d H:i:s')); } 343 update_option('meu_plugin_relatorios_plugins_atualizados', $atual); 344 } 345 if ($options['action'] === 'update' && $options['type'] === 'core') { 346 $atual = get_option('meu_plugin_relatorios_wp_atualizacoes', array()); 347 $atual[] = gmdate('Y-m-d H:i:s'); 348 update_option('meu_plugin_relatorios_wp_atualizacoes', $atual); 349 } 350 } 315 function meu_plugin_monitora_updates($upgrader, $options) { if ($options['action'] === 'update' && $options['type'] === 'plugin' && !empty($options['plugins'])) { $atual = get_option('meu_plugin_relatorios_plugins_atualizados', array()); foreach ($options['plugins'] as $f) { $d = get_plugin_data(WP_PLUGIN_DIR.'/'.$f); $atual[] = array('nome' => $d['Name'], 'data' => gmdate('Y-m-d H:i:s')); } update_option('meu_plugin_relatorios_plugins_atualizados', $atual); } if ($options['action'] === 'update' && $options['type'] === 'core') { $atual = get_option('meu_plugin_relatorios_wp_atualizacoes', array()); $atual[] = gmdate('Y-m-d H:i:s'); update_option('meu_plugin_relatorios_wp_atualizacoes', $atual); } } 351 316 add_action('upgrader_process_complete', 'meu_plugin_monitora_updates', 10, 2); 352 317 ?> -
digi-report/trunk/readme.txt
r3436145 r3436160 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 2.7. 16 Stable tag: 2.7.2 7 7 Requires PHP: 7.2 8 8 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.