Plugin Directory

Changeset 3436270


Ignore:
Timestamp:
01/09/2026 07:49:25 PM (3 months ago)
Author:
andre.luiz
Message:

Versao 2.7.6 com diagnostico de datas

Location:
digi-report/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • digi-report/trunk/digi-report.php

    r3436214 r3436270  
    33Plugin Name: Digi Report
    44Description: A plugin that generates and sends WordPress maintenance reports via email (Integrated with Independent Analytics).
    5 Version: 2.7.5
     5Version: 2.7.6
    66Author: DigiPerforma - Marketing Digital [digiperforma.com.br]
    77License: GPLv2 or later
     
    9191
    9292        <?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
    112127        <?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>
    114132        <?php endif; ?>
    115133
     
    135153
    136154// =========================================================
    137 // 2. FUNÇÃO: AUTO-DETECÇÃO CORRIGIDA (NOME LONGO)
     155// 2. FUNÇÃO: AUTO-DETECÇÃO + DEBUG
    138156// =========================================================
    139157function digi_report_get_analytics_data() {
    140158    global $wpdb;
    141159
    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'");
    146163
    147164    // Datas (Últimos 30 dias)
     
    149166    $end_date   = date('Y-m-d');
    150167
    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);
    160170    }
    161171
    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));
    165180
    166181    $top_pages = $wpdb->get_results($wpdb->prepare(
    167         "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",
     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",
    168183        $start_date, $end_date
    169184    ), ARRAY_A);
    170185
    171186    $top_cities = $wpdb->get_results($wpdb->prepare(
    172         "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",
     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",
    173188        $start_date, $end_date
    174189    ), ARRAY_A);
     
    179194        'visitors' => number_format_i18n((int)$visitors),
    180195        '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
    182203    );
    183204}
    184205
    185206// =========================================================
    186 // 3. ENVIO DE E-MAIL
     207// 3. ENVIO DE E-MAIL (Sem alterações nesta versão)
    187208// =========================================================
    188209function meu_plugin_relatorios_enviar() {
     
    195216    $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));
    196217
    197     // DADOS PARA E-MAIL
    198218    global $wpdb;
    199219    $start_date = date('Y-m-d H:i:s', strtotime('-30 days'));
     
    304324    }
    305325}
    306 // Ganchos (Manter iguais)
     326
     327// Ganchos (iguais)
    307328function meu_plugin_relatorios_agendar() { if (!wp_next_scheduled('meu_plugin_relatorios_gancho')) wp_schedule_event(time(), 'daily', 'meu_plugin_relatorios_gancho'); }
    308329add_action('wp', 'meu_plugin_relatorios_agendar');
  • digi-report/trunk/readme.txt

    r3436214 r3436270  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 2.7.5
     6Stable tag: 2.7.6
    77Requires PHP: 7.2
    88License: GPLv2 or later
Note: See TracChangeset for help on using the changeset viewer.