Plugin Directory

Changeset 3245295


Ignore:
Timestamp:
02/23/2025 07:51:31 PM (3 weeks ago)
Author:
webstat
Message:

Version 2.5. fixed display issue in dashboard and improved error reporting. Please uppdate your plugin to this version

Location:
web-stat/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • web-stat/trunk/Web-Stat.php

    r3151486 r3245295  
    44Plugin URI: https://www.web-stat.com/
    55Description: Free, real-time stats for your website with full visitor details and traffic analytics.
    6 Version: 2.4
     6Version: 2.5
    77Author: <a href="https://www.web-stat.com" target="_new">Web-Stat</a>
    88License: GPLv2 or later
     
    1818
    1919class WebStatPlugin {
    20     const VERSION = '2.4';
     20    const VERSION = '2.5';
    2121    private $site_id = null;
    2222    private $alias = null;
     
    5050    }
    5151   
    52     public static function activate() {
    53        update_option('wts_alias', '');
    54     }
    55    
     52    // load translations
     53    public function load_textdomain() {
     54        load_plugin_textdomain('web-stat', false, dirname(plugin_basename(__FILE__)) . '/languages');
     55    }
     56
     57    // Reset alias if plugin is activated or re-activated
     58    public static function reset_wts_data() {
     59        delete_option('wts_alias');
     60        delete_option('wts_db');
     61        delete_option('wts_oc_a2');
     62    }
     63   
     64    // Get stored data if any and create a site_id if none
    5665    private function init_options() {
    5766        // Initialize plugin options
    5867        $this->supported_languages = ['de', 'es', 'fr', 'it', 'ja', 'pt', 'ru', 'tr'];
    59         $this->site_id = get_option('wts_site_id');
     68        $this->site_id = get_option('wts_site_id') ?? null;
    6069        if (!$this->site_id) {
    6170            $this->site_id = wp_generate_uuid4();
    6271            update_option('wts_site_id', $this->site_id);
    6372        }
    64         $this->alias = get_option('wts_alias');
    65         $this->db = get_option('wts_db');
    66         $this->oc_a2 = is_admin() ? get_option('wts_oc_a2') : null;
     73        $this->alias = get_option('wts_alias') ?? null;
     74        $this->db = get_option('wts_db') ?? null;
     75        $this->oc_a2 = is_admin() ? (get_option('wts_oc_a2') ?? null) : null;
    6776        $this->language = substr(get_bloginfo('language'), 0, 2);
    6877        if (!preg_match('/^[a-z]{2}$/', $this->language)) {
    6978            $this->language = 'en';
    7079        }
    71         $this->old_uid = get_option('wts_web_stat_uid');
     80        $this->old_uid = get_option('wts_web_stat_uid') ?? null;
    7281        $this->has_json = extension_loaded('json');
    7382        $this->has_openssl = extension_loaded('openssl');
    7483    }
    7584   
    76     public function load_textdomain() {
    77         load_plugin_textdomain('web-stat', false, dirname(plugin_basename(__FILE__)) . '/languages');
    78     }
    7985
    8086    // Fetch data if needed then load log7 or admin options
    8187    public function enqueue_scripts() {
    8288        wp_enqueue_script('wts_init_js', plugin_dir_url(__FILE__) . 'js/wts_script.js', array(), '1.0.0', true);
    83         $wts_data = array('ajax_url' => 'https://app.ardalio.com/ajax.pl', 'action' => 'get_wp_data', 'version' => self::VERSION, 'alias' => $this->alias, 'db' => $this->db, 'site_id' => $this->site_id, 'old_uid' => $this->old_uid, 'url' => get_bloginfo('url'), 'language' => get_bloginfo('language'), 'time_zone' => get_option('timezone_string'), 'gmt_offset' => get_option('gmt_offset') );
     89        $wts_data = array('ajax_url' => 'https://app.ardalio.com/ajax.pl', 'action' => 'get_wp_data', 'version' => self::VERSION, 'alias' => $this->alias, 'db' => $this->db, 'site_id' => $this->site_id, 'old_uid' => $this->old_uid, 'url' => get_bloginfo('url'), 'language' => get_bloginfo('language'), 'time_zone' => get_option('timezone_string'), 'gmt_offset' => get_option('gmt_offset'), 'email' => get_option('admin_email') );
    8490        if (is_admin()) {
    8591            $nonce = wp_create_nonce('wts_ajax_nonce');
     
    112118    public function handle_ajax_data() {
    113119        if (!$this->has_json) {
    114             return;
     120            // send error back to wts_init_js
     121            header("Content-Type: application/json");
     122            echo '{ "success": false, "data": "JSON not available" }';
     123            wp_die();
    115124        }
    116125        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'wts_ajax_nonce')) {
     126            // send error back to wts_init_js
    117127            wp_send_json_error('Invalid nonce');
    118128            return;
     
    121131        if (!empty($data)) {
    122132            $data = json_decode(stripslashes($data), true);
    123             if (isset($data['alias']) && isset($data['db'])) {
     133            if (isset($data['alias'], $data['db']) &&
     134             preg_match('/^\d+$/', $data['alias']) &&
     135             preg_match('/^\d{1,2}$/', $data['db'])) {
    124136                $this->alias = $data['alias'];
    125137                $this->db = $data['db'];
     
    131143                wp_send_json_success();
    132144            }
     145            else{
     146                $aliasValue = $data['alias'] ?? 'not set';
     147                $dbValue = $data['db'] ?? 'not set';
     148                wp_send_json_error('wts_init_js sent invalid alias (' . $aliasValue . ') or invalid db (' . $dbValue . ')');
     149                return;
     150            }
     151        }
     152        else{
     153            wp_send_json_error(' wts_init_js sent back empty data');
     154            return;
    133155        }
    134156    }
     
    141163   
    142164    public function add_admin_menu() {
    143         $host = $this->get_host(); 
    144165        // Add the main Web-Stat menu
    145166        add_menu_page(
     
    205226        $host = $this->get_host();
    206227        $url = $host . '/' . $page . '?oc_a2=' . $this->oc_a2 . '&version=' . self::VERSION . '&source=WordPress';
     228        if (!$host || !$page || !$this->oc_a2){
     229           self::send_php_error('Could not display dashboard / host = ' . $host . ' / page = ' . $page . ' / oc_a2 = ' . $this->oc_a2);
     230        }
    207231        echo '
    208232        <style>
     
    215239        #wts_iframe{
    216240            font-size:0.9em;
     241            margin: 0px !important;
     242            overflow: hidden !important;
     243            height: 100vh !important;
     244            width: 100% !important;
     245            border: 0px;
    217246        }
    218247        .notice {
     
    220249        }
    221250        </style>
    222         <script>
    223         document.addEventListener("DOMContentLoaded", function() {
    224             var iframe = document.getElementById("wts_iframe");
    225             var container = document.getElementById("wpbody");
    226             iframe.style.height = container.clientHeight + "px";
    227         });
    228         </script>
    229251        <iframe src="' . $url . '" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" id="wts_iframe"></iframe>';
    230252    }
     
    255277        $host = $this->get_host();
    256278        $url = $host . '/wpFrame.htm?&oc_a2=' . $this->oc_a2 . '&version=' . self::VERSION . '&dashboard_url=' . $dashboard_url;
     279        if (!$host || !$this->oc_a2){
     280           self::send_php_error('Could not display dashboard widget / host = ' . $host . ' / oc_a2 = ' . $this->oc_a2 . ' / dashboard_url = '.$dashboard_url);
     281        }
    257282        echo '<iframe src="' . $url . '" style="width:100%; height:500px;" id="wts_iframe"></iframe>';
    258283    }
     
    324349        </script>";
    325350    }
     351   
     352    public static function send_php_error($e_text, $e_object = '') {
     353        // Use the plugin version if available
     354        $version = defined('self::VERSION') ? self::VERSION : 'unknown';
     355     
     356        // Build the error data array
     357        $errData = array(
     358            'origin'   => 'WP Plugin v.' . $version,
     359            'e_text'   => $e_text,
     360            // If $e_object is not a string, encode it as JSON
     361            'e_object' => is_string($e_object) ? $e_object : json_encode($e_object),
     362            'url'      => home_url()
     363        );
     364   
     365        // Send the data using wp_remote_post()
     366        wp_remote_post('https://app.ardalio.com/print.pl', array(
     367            'method' => 'POST',
     368            'body'   => $errData,
     369        ));
     370    }
     371
     372
    326373}
    327374
    328 register_activation_hook(__FILE__, ['WebStatPlugin', 'activate']);
     375
     376
     377
     378register_activation_hook(__FILE__, ['WebStatPlugin', 'reset_wts_data']);
     379register_deactivation_hook(__FILE__, ['WebStatPlugin', 'reset_wts_data']);
    329380
    330381new WebStatPlugin();
  • web-stat/trunk/js/wts_script.js

    r3151486 r3245295  
    6666
    6767function initAdmin() {
     68    // Does nothing. No further admin initializaton needed
    6869    return;
    6970}
     
    8687        .then(function(response) {
    8788            if (! response.success) {
    88                 console.error('Error sending data to PHP:', response.data);
     89                send_debug_message('Error sending data to PHP', response.data);
    8990            }
    9091        })
    9192        .catch(function(error) {
    92             console.error('Error sending data to PHP:', error);
     93            send_debug_message('Error sending data to PHP', error);
    9394        });
     95}
     96
     97function send_debug_message(e_text, e_object) {
     98    console.log(e_text, e_object);
     99    var errData = new URLSearchParams();
     100    errData.append('origin', 'WP Plugin v.'+window.wts_data.version);
     101    errData.append('e_text', e_text);
     102    if (e_object) {
     103       errData.append('e_object', e_object.toString());
     104    }
     105    errData.append('url', document.URL);
     106    navigator.sendBeacon("https://app.ardalio.com/print.pl", errData);
     107    return;
    94108}
    95109
  • web-stat/trunk/readme.txt

    r3151486 r3245295  
    44Requires PHP: 5.2.4
    55Requires at least: 4.9.5
    6 Tested up to: 6.6.1
    7 Stable tag: 2.4
     6Tested up to: 6.7.2
     7Stable tag: 2.5
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    107107
    108108== Changelog ==
     109= 2.5 =
     110* fixed display issue in dashboard and improved error reporting. Please uppdate your plugin to this version
    109111= 2.4 =
    110112* housekeeping - stable version
Note: See TracChangeset for help on using the changeset viewer.