Plugin Directory

Changeset 3297409


Ignore:
Timestamp:
05/20/2025 01:26:01 PM (10 months ago)
Author:
RogierLankhorst
Message:

prepare for update

Location:
burst-statistics/trunk
Files:
20 added
16 edited

Legend:

Unmodified
Added
Removed
  • burst-statistics/trunk/burst.php

    r3296551 r3297409  
    44 * Plugin URI: https://www.wordpress.org/plugins/burst-statistics
    55 * Description: Get detailed insights into visitors’ behavior with Burst Statistics, the privacy-friendly analytics dashboard.
    6  * Version: 2.0.5
     6 * Version: 2.0.6
    77 * Requires at least: 6.2
    88 * Requires PHP: 7.4
  • burst-statistics/trunk/src/Admin/App/class-app.php

    r3296551 r3297409  
    826826            $this->remove_fallback_notice();
    827827        }
    828 
    829828        switch ( $action ) {
    830829            case 'plugin_actions':
     
    900899                'slug'          => 'all-in-one-wp-security-and-firewall',
    901900                'constant_free' => 'AIO_WP_SECURITY_VERSION',
    902                 'constant_pro'  => false,
     901                'premium'       => [
     902                    'type'  => 'constant',
     903                    'value' => 'AIOWPS_PREMIUM_VERSION',
     904                ],
    903905                'wordpress_url' => 'https://wordpress.org/plugins/all-in-one-wp-security-and-firewall/',
    904906                'upgrade_url'   => 'https://aiosplugin.com/product/all-in-one-wp-security-and-firewall-premium/?src=plugin-burst-other-plugins',
     
    906908            ],
    907909            [
    908                 'slug'          => 'updraftplus',
    909                 'constant_free' => 'UPDRAFTPLUS_DIR',
    910                 'constant_pro'  => false,
    911                 'wordpress_url' => 'https://wordpress.org/plugins/updraftplus/',
    912                 'upgrade_url'   => 'https://updraftplus.com/shop/updraftplus-premium/?src=plugin-burst-other-plugins',
    913                 'title'         => 'UpdraftPlus - Back-up & migrate your site with ease',
     910                'slug'              => 'updraftplus',
     911                'constant_free'     => 'UPDRAFTPLUS_DIR',
     912                // 'premium'  => [
     913                // 'type' => 'function',
     914                // 'value' => '$updraftplus_addons2 && method_exists($updraftplus_addons2, 'connection_status')) {'
     915                // ],
     916                    'wordpress_url' => 'https://wordpress.org/plugins/updraftplus/',
     917                'upgrade_url'       => 'https://updraftplus.com/shop/updraftplus-premium/?src=plugin-burst-other-plugins',
     918                'title'             => 'UpdraftPlus - Back-up & migrate your site with ease',
    914919            ],
    915920            [
    916921                'slug'          => 'wp-optimize',
    917922                'constant_free' => 'WPO_VERSION',
    918                 'constant_pro'  => false,
     923                'premium'       => [
     924                    'type'  => 'slug',
     925                    'value' => 'wp-optimize-premium/wp-optimize.php',
     926                ],
    919927                'wordpress_url' => 'https://wordpress.org/plugins/wp-optimize/',
    920928                'upgrade_url'   => 'https://getwpo.com/buy/?src=plugin-burst-other-plugins',
     
    925933        foreach ( $plugins as $index => $plugin ) {
    926934            $installer = new Installer( $plugin['slug'] );
    927             // @phpstan-ignore-next-line, constant_pro contain value in the future
    928             if ( $plugin['constant_pro'] && defined( $plugin['constant_pro'] ) ) {
     935            if ( isset( $plugin['premium'] ) && $this->plugin_is_installed( $plugin['premium']['type'], $plugin['premium']['value'] ) ) {
    929936                $plugins[ $index ]['pluginAction'] = 'installed';
    930937            } elseif ( ! $installer->plugin_is_downloaded() && ! $installer->plugin_is_activated() ) {
     
    932939            } elseif ( $installer->plugin_is_downloaded() && ! $installer->plugin_is_activated() ) {
    933940                $plugins[ $index ]['pluginAction'] = 'activate';
    934                 // @phpstan-ignore-next-line, might be true in the future
    935             } elseif ( $plugin['constant_pro'] ) {
     941            } elseif ( isset( $plugin['premium'] ) ) {
    936942                $plugins[ $index ]['pluginAction'] = 'upgrade-to-pro';
    937943            } else {
     
    949955
    950956        return $plugins;
     957    }
     958
     959    /**
     960     * Check if a plugin is installed based on the detection type and value.
     961     */
     962    private function plugin_is_installed( string $detection_type, string $detection_value ): bool {
     963        if ( $detection_type === 'constant' ) {
     964            return defined( $detection_value );
     965        } elseif ( $detection_type === 'slug' ) {
     966            return file_exists( WP_PLUGIN_DIR . '/' . $detection_value );
     967        } elseif ( $detection_type === 'function' ) {
     968            return function_exists( $detection_value );
     969        } elseif ( $detection_type === 'class' ) {
     970            return class_exists( $detection_value );
     971        }
     972        return false;
    951973    }
    952974
  • burst-statistics/trunk/src/Admin/App/config/fields.php

    r3296551 r3297409  
    8787        'disabled' => false,
    8888        'default'  => false,
     89    ],
     90    [
     91        'id'          => 'send_email_report',
     92        'menu_id'     => 'general',
     93        'group_id'    => 'email_reports',
     94        'type'        => 'button',
     95        'action'      => 'send_email_report',
     96        'button_text' => __( 'Send', 'burst-statistics' ),
     97        'label'       => __( 'Send an e-mail report', 'burst-statistics' ),
     98        'comment'     => __( 'This will send an e-mail to all listed recipients.', 'burst-statistics' ),
     99        'disabled'    => false,
     100        'default'     => false,
    89101    ],
    90102
  • burst-statistics/trunk/src/Admin/App/src/components/Fields/RestoreArchivesField.jsx

    r3296551 r3297409  
    5151    setSelectedArchives([]);
    5252    await startRestoreArchives( ids );
    53     addHelpNotice(
    54       'archive_data',
    55       'warning',
    56       __( 'Because restoring files can conflict with the archiving functionality, archiving has been disabled.', 'burst-statistics' ),
    57       __( 'Archiving disabled', 'burst-statistics' )
    58     );
     53    // addHelpNotice(
     54    //   'archive_data',
     55    //   'warning',
     56    //   __( 'Because restoring files can conflict with the archiving functionality, archiving has been disabled.', 'burst-statistics' ),
     57    //   __( 'Archiving disabled', 'burst-statistics' )
     58    // );
    5959  };
    6060
  • burst-statistics/trunk/src/Admin/App/src/components/Goals/GoalsSettings.js

    r3296551 r3297409  
    2626  const {getValue} = useSettingsData();
    2727  const cookieless = getValue( 'enable_cookieless_tracking' );
    28 
    29   console.log(isLicenseValid);
    3028
    3129  const handleAddPredefinedGoal = ( goal ) => {
  • burst-statistics/trunk/src/Admin/App/src/components/Inputs/CheckboxGroupInput.tsx

    r3296551 r3297409  
    121121                name={indeterminate ? 'indeterminate' : 'check'}
    122122                size={14}
    123                 color="dark-blue"
    124                 tooltip=""
    125                 onClick={() => {}}
    126                 className=""
     123                color="blue"
    127124              />
    128125            </Checkbox.Indicator>
  • burst-statistics/trunk/src/Admin/App/src/store/useArchivesStore.js

    r3296551 r3297409  
    3030    },
    3131    fetchData: async( ) => {
     32        if ( !burst_settings.is_pro) {
     33            return;
     34        }
    3235        if ( get().fetching ) {
    33 return;
    34 }
     36            return;
     37        }
    3538        set({fetching: true});
    3639        let data = {};
  • burst-statistics/trunk/src/Admin/App/src/store/useLicenseStore.js

    r3296551 r3297409  
    1212    // Property that returns true if license is valid
    1313    get isLicenseValid() {
    14         console.log(get().licenseStatus);
    15         console.log(burst_settings.is_pro);
    1614        return 'valid' === get().licenseStatus && burst_settings.is_pro === '1';
    1715    }
  • burst-statistics/trunk/src/Admin/App/src/utils/Icon.tsx

    r3296551 r3297409  
    11import { memo } from 'react';
    22import Tooltip from '../components/Common/Tooltip';
    3 import clsx from 'clsx';
    43import { LucideProps } from 'lucide-react';
    54import {
     
    172171    strokeWidth
    173172  };
    174  
     173
     174
    175175  // Render the icon
    176176  const renderIcon = () => {
  • burst-statistics/trunk/src/Admin/Burst_Wp_Cli/class-burst-wp-cli.php

    r3296551 r3297409  
    118118        }
    119119
     120        // remove empty values, and duplicates.
     121        $urls = array_filter(
     122            $urls,
     123            function ( $v ) {
     124                return ! empty( $v );
     125            }
     126        );
     127        $urls = array_unique( $urls );
     128        // remove keys.
     129        $urls = array_values( $urls );
     130
    120131        echo wp_json_encode( $urls, JSON_PRETTY_PRINT );
    121132    }
  • burst-statistics/trunk/src/Admin/Installer/class-installer.php

    r3296551 r3297409  
    7676            return false;
    7777        }
     78
    7879        if ( get_transient( 'burst_plugin_download_active' ) !== $this->slug ) {
    7980            set_transient( 'burst_plugin_download_active', $this->slug, MINUTE_IN_SECONDS );
  • burst-statistics/trunk/src/Admin/Mailer/class-mail-reports.php

    r3296551 r3297409  
    2323        public function __construct() {
    2424            add_action( 'burst_every_hour', [ $this, 'maybe_send_report' ] );
    25             add_action( 'admin_init', [ $this, 'test_report' ] );
     25            add_action( 'admin_init', [ $this, 'test_report_on_query_var' ] );
     26            add_filter( 'burst_do_action', [ $this, 'send_test_report_action' ], 10, 3 );
     27        }
     28
     29        /**
     30         * User can send a report by clicking the button in the settings page.
     31         *
     32         * @return array<string, mixed> The modified output array.
     33         */
     34        public function send_test_report_action( array $output, string $action, array $data ): array {
     35            // phpcs warning fixed.
     36            unset( $data );
     37            if ( ! $this->user_can_manage() ) {
     38                return $output;
     39            }
     40
     41            if ( $action === 'send_email_report' ) {
     42                $this->send_test_report();
     43                $output = [
     44                    'success' => true,
     45                    'message' => __( 'E-mail report sent.', 'burst-statistics' ),
     46                ];
     47            }
     48
     49            return $output;
     50        }
     51
     52        /**
     53         * User can add query var burst_test_report to send a report
     54         */
     55        public function test_report_on_query_var(): void {
     56            // not processing, just checking existence.
     57            // phpcs:ignore
     58            if ( ! isset( $_GET['burst_test_report'] ) ) {
     59                return;
     60            }
     61            $this->send_test_report();
    2662        }
    2763
     
    2965         * Send a test email.
    3066         */
    31         public function test_report(): void {
    32             // no formdata processed, only existence check.
    33             if ( ! isset( $_GET['burst_test_report'] ) ) { // phpcs:ignore
     67        public function send_test_report(): void {
     68            if ( ! $this->user_can_manage() ) {
    3469                return;
    3570            }
    36             // no formdata processed, only comparison check.
    37             $frequency   = $_GET['burst_test_report'] === 'monthly' ? 'monthly' : 'weekly'; // phpcs:ignore
     71            $frequency   = 'weekly';
    3872            $mailinglist = $this->get_option( 'email_reports_mailinglist' );
    39             $emails      = [];
     73            $monthly     = [];
     74            $weekly      = [];
    4075            foreach ( $mailinglist as $mailing ) {
    4176                if ( isset( $mailing['email'] ) ) {
    42                     $emails[] = $mailing['email'];
    43                 }
    44             }
    45             $this->send_report( $emails, $frequency );
     77                    if ( $mailing['frequency'] === 'monthly' ) {
     78                        $monthly[] = $mailing['email'];
     79                    }
     80                    if ( $mailing['frequency'] === 'weekly' ) {
     81                        $weekly[] = $mailing['email'];
     82                    }
     83                }
     84            }
     85            if ( count( $weekly ) > 0 ) {
     86                $this->send_report( $weekly, 'weekly' );
     87            }
     88            if ( count( $monthly ) > 0 ) {
     89                $this->send_report( $monthly, 'monthly' );
     90            }
    4691        }
    4792
     
    90135         */
    91136        private function send_report( array $mailinglist, string $frequency = 'weekly' ): void {
    92             global $wpdb;
    93137            $mailer     = new Mailer();
    94138            $mailer->to = $mailinglist;
     
    155199            }
    156200
     201            $compare = $this->get_compare_data( $date_start, $date_end, $compare_date_start, $compare_date_end );
     202            update_option( 'burst_last_report_sent', time(), false );
     203
     204            $blocks   = [];
     205            $blocks[] = [
     206                'title'    => __( 'Compare', 'burst-statistics' ),
     207                'subtitle' => $frequency === 'weekly' ? __( 'vs. previous week', 'burst-statistics' ) : __( 'vs. previous month', 'burst-statistics' ),
     208                'table'    => self::format_array_as_table( $compare ),
     209                'url'      => $this->admin_url( 'burst#/statistics' ),
     210            ];
     211
     212            $custom_blocks = $this->get_blocks();
     213            foreach ( $custom_blocks as $index => $block ) {
     214                    $results                 = $this->get_top_results( $date_start, $date_end, $block['type'] );
     215                    $completed_block         = [
     216                        'title' => $block['title'],
     217                        'table' => self::format_array_as_table( $results ),
     218                        'url'   => $this->admin_url( 'burst' . $block['url'] ),
     219                    ];
     220                    $custom_blocks[ $index ] = $completed_block;
     221            }
     222
     223            $blocks = array_merge( $blocks, $custom_blocks );
     224            $blocks = apply_filters( 'burst_mail_reports_blocks', $blocks, $date_start, $date_end );
     225
     226            $mailer->blocks = $blocks;
     227            $attachment_id  = $this->get_option( 'logo_attachment_id' );
     228            if ( (int) $attachment_id > 0 ) {
     229                $mailer->logo = wp_get_attachment_url( $attachment_id );
     230            }
     231            $mailer->send_mail_queue();
     232        }
     233
     234        /**
     235         * Get blocks for the email report.
     236         *
     237         * @return array<int, array<string, mixed>> List of blocks for the email report.
     238         */
     239        public function get_blocks(): array {
     240            $blocks = require BURST_PATH . 'src/Admin/Mailer/config/blocks.php';
     241            return apply_filters( 'burst_email_blocks', $blocks );
     242        }
     243
     244        /**
     245         * Get top results for the email report.
     246         *
     247         * @return array<int, array<int, string>> List of results
     248         */
     249        public function get_top_results( int $start_date, int $end_date, string $type ): array {
     250            global $wpdb;
     251            $metrics     = [
     252                $type,
     253                'pageviews',
     254            ];
     255            $sql         = \Burst\burst_loader()->admin->statistics->get_sql_table(
     256                $start_date,
     257                $end_date,
     258                $metrics,
     259                [],
     260                $type,
     261                'pageviews DESC',
     262                apply_filters( 'burst_mail_report_limit', 5 ),
     263            );
     264            $raw_results = $wpdb->get_results( $sql, ARRAY_A );
     265
     266            switch ( $type ) {
     267                case 'page_url':
     268                    $header = __( 'Page', 'burst-statistics' );
     269                    break;
     270                case 'source':
     271                    $header = __( 'Campaign', 'burst-statistics' );
     272                    break;
     273                default:
     274                    $header = __( 'Referrers', 'burst-statistics' );
     275                    break;
     276            }
     277
     278            $results = [
     279                'header' => [ $header, __( 'Pageviews', 'burst-statistics' ) ],
     280            ];
     281
     282            foreach ( $raw_results as $row ) {
     283                if ( $type !== 'referrer' || $row[ $type ] !== 'Direct' ) {
     284                    $results[] = [ $row[ $type ], $row['pageviews'] ];
     285                }
     286            }
     287
     288            return $results;
     289        }
     290
     291        /**
     292         * Get compare data for the email report.
     293         *
     294         * @return array<int, array<int, string>> List of compare rows grouped by type.
     295         */
     296        private function get_compare_data( int $date_start, int $date_end, int $compare_date_start, int $compare_date_end ): array {
    157297            $args = [
    158298                'date_start'         => $date_start,
     
    194334                $compare[] = $this->get_compare_row( $type, $compare_data );
    195335            }
    196 
    197             $sql     = \Burst\burst_loader()->admin->statistics->get_sql_table(
    198                 $args['date_start'],
    199                 $args['date_end'],
    200                 [
    201                     'page_url',
    202                     'pageviews',
    203                 ],
    204                 [],
    205                 'page_url',
    206                 'pageviews DESC'
    207             );
    208             $results = $wpdb->get_results( $sql, ARRAY_A );
    209 
    210             // max five urls.
    211             $results = array_slice( $results, 0, 5 );
    212 
    213             $urls = [
    214                 'header' => [ __( 'Page', 'burst-statistics' ), __( 'Pageviews', 'burst-statistics' ) ],
    215             ];
    216 
    217             foreach ( $results as $index => $row ) {
    218                 $urls[] = [ $row['page_url'], $row['pageviews'] ];
    219             }
    220             $refferers_sql  = \Burst\burst_loader()->admin->statistics->get_sql_table(
    221                 $args['date_start'],
    222                 $args['date_end'],
    223                 [
    224                     'referrer',
    225                     'pageviews',
    226                 ],
    227                 [],
    228                 'referrer',
    229                 'pageviews DESC'
    230             );
    231             $refferers_data = $wpdb->get_results( $refferers_sql, ARRAY_A );
    232 
    233             // max five referrers.
    234             $refferers_data = array_slice( $refferers_data, 0, 5 );
    235 
    236             $referrers = [
    237                 'header' => [ __( 'Referrers', 'burst-statistics' ), __( 'Pageviews', 'burst-statistics' ) ],
    238             ];
    239 
    240             foreach ( $refferers_data as $index => $row ) {
    241                 if ( $row['referrer'] !== 'Direct' ) {
    242                     $referrers[] = [ $row['referrer'], $row['pageviews'] ];
    243                 }
    244             }
    245 
    246             update_option( 'burst_last_report_sent', time(), false );
    247             $blocks = [
    248                 [
    249                     'title'    => __( 'Compare', 'burst-statistics' ),
    250                     'subtitle' => $frequency === 'weekly' ? __( 'vs. previous week', 'burst-statistics' ) : __( 'vs. previous month', 'burst-statistics' ),
    251                     'table'    => self::format_array_as_table( $compare ),
    252                     'url'      => $this->admin_url( 'burst#/statistics' ),
    253                 ],
    254                 [
    255                     'title' => __( 'Most visited pages', 'burst-statistics' ),
    256                     'table' => self::format_array_as_table( $urls ),
    257                     'url'   => $this->admin_url( 'burst#/statistics' ),
    258                 ],
    259                 [
    260                     'title' => __( 'Top referrers', 'burst-statistics' ),
    261                     'table' => self::format_array_as_table( $referrers ),
    262                     'url'   => $this->admin_url( 'burst#/statistics' ),
    263                 ],
    264             ];
    265             $blocks = apply_filters( 'burst_mail_reports_blocks', $blocks, $args['date_start'], $args['date_end'] );
    266 
    267             $mailer->blocks = $blocks;
    268             $attachment_id  = $this->get_option( 'logo_attachment_id' );
    269             if ( (int) $attachment_id > 0 ) {
    270                 $mailer->logo = wp_get_attachment_url( $attachment_id );
    271             }
    272             $mailer->send_mail_queue();
     336            return $compare;
    273337        }
    274338
     
    315379         * Format an array as an HTML table.
    316380         *
    317          * @param array $table_array The array to format.
     381         * @param array $input_array The array to format.
    318382         * @return string The formatted HTML table.
    319383         */
    320         public static function format_array_as_table( array $table_array ): string {
     384        public static function format_array_as_table( array $input_array ): string {
    321385            $html = '';
    322             if ( isset( $table_array['header'] ) ) {
    323                 $row       = $table_array['header'];
     386            if ( isset( $input_array['header'] ) ) {
     387                $row       = $input_array['header'];
    324388                $html     .= '<tr style="line-height: 32px">';
    325389                $first_row = true;
     
    333397                }
    334398                $html .= '</tr>';
    335                 unset( $table_array['header'] );
    336             }
    337             foreach ( $table_array as $row ) {
     399                unset( $input_array['header'] );
     400            }
     401            foreach ( $input_array as $row ) {
    338402                $html     .= '<tr style="line-height: 32px">';
    339403                $first_row = true;
  • burst-statistics/trunk/src/Admin/Statistics/class-statistics.php

    r3296551 r3297409  
    16351635        return 0;
    16361636    }
    1637 
    1638 
    16391637
    16401638    /**
  • burst-statistics/trunk/src/Admin/class-admin.php

    r3296551 r3297409  
    294294            do_action( 'burst_activation' );
    295295            delete_option( 'burst_run_activation' );
    296             $this->tasks->add_initial_tasks();
    297296        }
    298297    }
     
    403402            update_option( 'burst_activation_time', time(), false );
    404403            update_option( 'burst_last_cron_hit', time(), false );
    405             $this->run_table_init_hook();
     404            $this->tasks->add_initial_tasks();
     405
    406406            // tables installed, now set defaults.
    407407            $exclude_roles = $this->get_option( 'user_role_blocklist' );
  • burst-statistics/trunk/src/Frontend/class-frontend.php

    r3296551 r3297409  
    174174    public function most_visited_posts(
    175175        array $atts = [],
    176         string $content = null,
     176        ?string $content = null,
    177177        string $tag = ''
    178178    ): string {
  • burst-statistics/trunk/src/class-burst.php

    r3296551 r3297409  
    5353            $burst_plugin = implode( '/', $burst_plugin );
    5454            $debug        = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '#' . time() : '';
    55             define( 'BURST_VERSION', '2.0.5' . $debug );
     55            define( 'BURST_VERSION', '2.0.6' . $debug );
    5656            // deprecated constant.
    5757            //phpcs:ignore
Note: See TracChangeset for help on using the changeset viewer.