Plugin Directory

Changeset 3386274


Ignore:
Timestamp:
10/29/2025 08:53:13 AM (5 months ago)
Author:
sitesignal
Message:

new commit

Location:
sitesignal/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • sitesignal/trunk/admin/partials/dreamcore-monitor-admin-settings.php

    r3386234 r3386274  
    217217            </tr>
    218218
     219            <tr>
     220
     221                <th scope="row">
     222
     223                    <label for="dreamcore_monitor_enable_useragent_tracking"><?php esc_html_e( 'Enable User Agent Tracking', 'sitesignal' ); ?></label>
     224
     225                </th>
     226
     227                <td>
     228
     229                    <label>
     230
     231                        <input type="checkbox"
     232
     233                               name="dreamcore_monitor_enable_useragent_tracking"
     234
     235                               id="dreamcore_monitor_enable_useragent_tracking"
     236
     237                               value="1"
     238
     239                               <?php checked( absint( get_option( 'dreamcore_monitor_enable_useragent_tracking', 1 ) ), 1 ); ?> />
     240
     241                        <?php esc_html_e( 'Track user agents (browsers, bots, crawlers) visiting your site', 'sitesignal' ); ?>
     242
     243                    </label>
     244
     245                    <p class="description">
     246
     247                        <?php esc_html_e( 'This tracks all visitors including browsers, AI bots, search engine bots, and crawlers.', 'sitesignal' ); ?>
     248
     249                    </p>
     250
     251                </td>
     252
     253            </tr>
     254
    219255        </table>
    220256
  • sitesignal/trunk/includes/admin/class-dreamcore-monitor-admin.php

    r3386234 r3386274  
    6767            'sitesignal_page_dreamcore-monitor-settings',
    6868            'sitesignal_page_dreamcore-monitor-security',
    69             'sitesignal_page_dreamcore-monitor-about'
     69            'sitesignal_page_dreamcore-monitor-about',
     70            'sitesignal_page_dreamcore-monitor-useragents'
    7071        );
    7172
     
    495496            'sitesignal_page_dreamcore-monitor-settings',
    496497            'sitesignal_page_dreamcore-monitor-security',
    497             'sitesignal_page_dreamcore-monitor-about'
     498            'sitesignal_page_dreamcore-monitor-about',
     499            'sitesignal_page_dreamcore-monitor-useragents'
    498500        );
    499501
     
    562564        );
    563565
     566        // User Agents submenu
     567        add_submenu_page(
     568            'sitesignal',
     569            __( 'User Agents', 'sitesignal' ),
     570            __( 'User Agents', 'sitesignal' ),
     571            'manage_options',
     572            'dreamcore-monitor-useragents',
     573            array( $this, 'display_useragents' )
     574        );
     575
    564576        // API Settings submenu
    565577        add_submenu_page(
     
    594606        register_setting( 'dreamcore_monitor_settings', 'dreamcore_monitor_enable_api', array('sanitize_callback' => 'rest_sanitize_boolean') );
    595607        register_setting( 'dreamcore_monitor_settings', 'dreamcore_monitor_enable_geolocation', array('sanitize_callback' => 'rest_sanitize_boolean') );
     608        register_setting( 'dreamcore_monitor_settings', 'dreamcore_monitor_enable_useragent_tracking', array('sanitize_callback' => 'rest_sanitize_boolean') );
    596609    }
    597610
     
    649662
    650663    /**
    651     * Display the about page.
    652     *
    653     * @since    1.0.0
    654     */
     664     * Display the user agents page.
     665     *
     666     * @since    1.0.0
     667     */
     668    public function display_useragents() {
     669        // Check user capabilities
     670        if ( ! current_user_can( 'manage_options' ) ) {
     671            wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'sitesignal' ) );
     672        }
     673
     674        include_once DREAMCORE_MONITOR_PLUGIN_DIR . 'admin/partials/dreamcore-monitor-admin-useragents.php';
     675    }
     676
     677    /**
     678     * Display the about page.
     679     *
     680     * @since    1.0.0
     681     */
    655682    public function display_about() {
    656683        // Check user capabilities
     
    722749        } else {
    723750            update_option( 'dreamcore_monitor_enable_geolocation', 0 );
     751        }
     752
     753        // Validate and sanitize enable user agent tracking
     754        if ( isset( $_POST['dreamcore_monitor_enable_useragent_tracking'] ) ) {
     755            $enable_useragent_tracking = absint( $_POST['dreamcore_monitor_enable_useragent_tracking'] );
     756            update_option( 'dreamcore_monitor_enable_useragent_tracking', $enable_useragent_tracking );
     757        } else {
     758            update_option( 'dreamcore_monitor_enable_useragent_tracking', 0 );
    724759        }
    725760    }
  • sitesignal/trunk/includes/class-dreamcore-monitor-activator.php

    r3386234 r3386274  
    3232        // Create the login tracking table
    3333        self::create_login_table();
     34
     35        // Create the user agents tracking table
     36        self::create_useragents_table();
    3437
    3538        // Generate site ID if not exists
     
    120123
    121124    /**
     125     * Create the user agents tracking table.
     126     *
     127     * @since    1.0.0
     128     * @access   private
     129     */
     130    private static function create_useragents_table() {
     131        global $wpdb;
     132
     133        $charset_collate = $wpdb->get_charset_collate();
     134        $table_name      = $wpdb->prefix . 'dreamcore_monitor_useragents';
     135
     136        $sql = "CREATE TABLE {$wpdb->prefix}dreamcore_monitor_useragents (
     137            id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
     138            user_agent VARCHAR(500) NOT NULL,
     139            ip_address VARCHAR(45) NOT NULL,
     140            page_url VARCHAR(500) NOT NULL,
     141            referer VARCHAR(500) NULL,
     142            category VARCHAR(50) NOT NULL,
     143            browser VARCHAR(100) NULL,
     144            os VARCHAR(100) NULL,
     145            device_type VARCHAR(50) NULL,
     146            visited_at DATETIME DEFAULT CURRENT_TIMESTAMP,
     147            INDEX idx_category (category),
     148            INDEX idx_visited_at (visited_at),
     149            INDEX idx_ip_address (ip_address),
     150            INDEX idx_browser (browser),
     151            INDEX idx_device_type (device_type)
     152        ) {$charset_collate}";
     153
     154        // Safe loading of upgrade.php with proper path handling
     155        $upgrade_file = wp_normalize_path( ABSPATH . 'wp-admin/includes/upgrade.php' );
     156        if ( file_exists( $upgrade_file ) && is_readable( $upgrade_file ) ) {
     157            $expected_admin_includes = wp_normalize_path( ABSPATH . 'wp-admin/includes' );
     158            if ( strpos( $upgrade_file, $expected_admin_includes ) === 0 ) {
     159                require_once $upgrade_file;
     160            }
     161        }
     162
     163        if ( function_exists( 'dbDelta' ) ) {
     164            dbDelta( $sql );
     165        } else {
     166            // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
     167            $result = $wpdb->query( $sql );
     168            if ( false === $result ) {
     169                if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
     170                    // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
     171                    // error_log( 'Dreamcore Monitor: Failed to create user agents table - ' . $wpdb->last_error );
     172                }
     173            }
     174        }
     175    }
     176
     177    /**
    122178     * Set default plugin options.
    123179     *
     
    133189            'dreamcore_monitor_enable_api'        => 0,
    134190            'dreamcore_monitor_enable_geolocation' => 1,
     191            'dreamcore_monitor_enable_useragent_tracking' => 1,
    135192        );
    136193
  • sitesignal/trunk/includes/class-dreamcore-monitor-integrity.php

    r3386234 r3386274  
    457457        // Security check: Ensure path is within WordPress root
    458458
    459         if ( ! str_starts_with( $full_path, $wp_root ) ) {
     459        if ( strpos( $full_path, $wp_root ) !== 0 ) {
    460460
    461461            return false;
     
    643643            return array_filter( array_keys( $checksums ), function ( $file ) {
    644644
    645                 return ! str_starts_with( $file, 'wp-content/themes/' ) &&
    646 
    647                     ! str_starts_with( $file, 'wp-content/plugins/' );
     645                return strpos( $file, 'wp-content/themes/' ) !== 0 &&
     646
     647                    strpos( $file, 'wp-content/plugins/' ) !== 0;
    648648
    649649            });
     
    681681        return array_filter( array_keys( $data['checksums'] ), function ( $file ) {
    682682
    683             return ! str_starts_with( $file, 'wp-content/themes/' ) &&
    684 
    685                 ! str_starts_with( $file, 'wp-content/plugins/' );
     683            return strpos( $file, 'wp-content/themes/' ) !== 0 &&
     684
     685                strpos( $file, 'wp-content/plugins/' ) !== 0;
    686686
    687687        });
  • sitesignal/trunk/includes/class-dreamcore-monitor.php

    r3386234 r3386274  
    329329        $this->safe_require_file( 'includes/class-dreamcore-monitor-orders.php', false );
    330330
     331        $this->safe_require_file( 'includes/class-dreamcore-monitor-useragents.php', false );
     332
    331333        // Initialize loader if the class was successfully loaded
    332334
     
    463465        }
    464466
     467        if ( class_exists( 'Dreamcore_Monitor_UserAgents' ) ) {
     468
     469            $useragents_monitor = new Dreamcore_Monitor_UserAgents( $this->get_plugin_name(), $this->get_version() );
     470
     471            $this->loader->add_action( 'wp', $useragents_monitor, 'track_page_visit' );
     472
     473            $this->loader->add_action( 'rest_api_init', $useragents_monitor, 'register_rest_routes' );
     474
     475        }
     476
    465477    }
    466478
  • sitesignal/trunk/wp-site-monitor.php

    r3386240 r3386274  
    1111 * Domain Path: /languages
    1212 * Requires at least: 5.0
    13  * Tested up to: 6.8
     13 * Tested up to: 6.7
    1414 * Requires PHP: 7.4
    1515 *
Note: See TracChangeset for help on using the changeset viewer.