Changeset 3245295
- Timestamp:
- 02/23/2025 07:51:31 PM (3 weeks ago)
- Location:
- web-stat/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
web-stat/trunk/Web-Stat.php
r3151486 r3245295 4 4 Plugin URI: https://www.web-stat.com/ 5 5 Description: Free, real-time stats for your website with full visitor details and traffic analytics. 6 Version: 2. 46 Version: 2.5 7 7 Author: <a href="https://www.web-stat.com" target="_new">Web-Stat</a> 8 8 License: GPLv2 or later … … 18 18 19 19 class WebStatPlugin { 20 const VERSION = '2. 4';20 const VERSION = '2.5'; 21 21 private $site_id = null; 22 22 private $alias = null; … … 50 50 } 51 51 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 56 65 private function init_options() { 57 66 // Initialize plugin options 58 67 $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; 60 69 if (!$this->site_id) { 61 70 $this->site_id = wp_generate_uuid4(); 62 71 update_option('wts_site_id', $this->site_id); 63 72 } 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; 67 76 $this->language = substr(get_bloginfo('language'), 0, 2); 68 77 if (!preg_match('/^[a-z]{2}$/', $this->language)) { 69 78 $this->language = 'en'; 70 79 } 71 $this->old_uid = get_option('wts_web_stat_uid') ;80 $this->old_uid = get_option('wts_web_stat_uid') ?? null; 72 81 $this->has_json = extension_loaded('json'); 73 82 $this->has_openssl = extension_loaded('openssl'); 74 83 } 75 84 76 public function load_textdomain() {77 load_plugin_textdomain('web-stat', false, dirname(plugin_basename(__FILE__)) . '/languages');78 }79 85 80 86 // Fetch data if needed then load log7 or admin options 81 87 public function enqueue_scripts() { 82 88 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') ); 84 90 if (is_admin()) { 85 91 $nonce = wp_create_nonce('wts_ajax_nonce'); … … 112 118 public function handle_ajax_data() { 113 119 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(); 115 124 } 116 125 if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'wts_ajax_nonce')) { 126 // send error back to wts_init_js 117 127 wp_send_json_error('Invalid nonce'); 118 128 return; … … 121 131 if (!empty($data)) { 122 132 $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'])) { 124 136 $this->alias = $data['alias']; 125 137 $this->db = $data['db']; … … 131 143 wp_send_json_success(); 132 144 } 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; 133 155 } 134 156 } … … 141 163 142 164 public function add_admin_menu() { 143 $host = $this->get_host();144 165 // Add the main Web-Stat menu 145 166 add_menu_page( … … 205 226 $host = $this->get_host(); 206 227 $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 } 207 231 echo ' 208 232 <style> … … 215 239 #wts_iframe{ 216 240 font-size:0.9em; 241 margin: 0px !important; 242 overflow: hidden !important; 243 height: 100vh !important; 244 width: 100% !important; 245 border: 0px; 217 246 } 218 247 .notice { … … 220 249 } 221 250 </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>229 251 <iframe src="' . $url . '" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" id="wts_iframe"></iframe>'; 230 252 } … … 255 277 $host = $this->get_host(); 256 278 $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 } 257 282 echo '<iframe src="' . $url . '" style="width:100%; height:500px;" id="wts_iframe"></iframe>'; 258 283 } … … 324 349 </script>"; 325 350 } 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 326 373 } 327 374 328 register_activation_hook(__FILE__, ['WebStatPlugin', 'activate']); 375 376 377 378 register_activation_hook(__FILE__, ['WebStatPlugin', 'reset_wts_data']); 379 register_deactivation_hook(__FILE__, ['WebStatPlugin', 'reset_wts_data']); 329 380 330 381 new WebStatPlugin(); -
web-stat/trunk/js/wts_script.js
r3151486 r3245295 66 66 67 67 function initAdmin() { 68 // Does nothing. No further admin initializaton needed 68 69 return; 69 70 } … … 86 87 .then(function(response) { 87 88 if (! response.success) { 88 console.error('Error sending data to PHP:', response.data);89 send_debug_message('Error sending data to PHP', response.data); 89 90 } 90 91 }) 91 92 .catch(function(error) { 92 console.error('Error sending data to PHP:', error);93 send_debug_message('Error sending data to PHP', error); 93 94 }); 95 } 96 97 function 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; 94 108 } 95 109 -
web-stat/trunk/readme.txt
r3151486 r3245295 4 4 Requires PHP: 5.2.4 5 5 Requires at least: 4.9.5 6 Tested up to: 6. 6.17 Stable tag: 2. 46 Tested up to: 6.7.2 7 Stable tag: 2.5 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 107 107 108 108 == Changelog == 109 = 2.5 = 110 * fixed display issue in dashboard and improved error reporting. Please uppdate your plugin to this version 109 111 = 2.4 = 110 112 * housekeeping - stable version
Note: See TracChangeset
for help on using the changeset viewer.