Commit 65d5e99f authored by Vadim's avatar Vadim

Version 2.5.1

Запрет wss://stat.azbyka.ru/updates при пустом path (отсутствие счетчиков на странице).
parent 286844ec
......@@ -3,7 +3,7 @@
Plugin Name: Bg Az-Counter
Plugin URI: https://bogaiskov.ru
Description: Подсчет количества посещений страниц на базе stat.azbyka.ru
Version: 2.5
Version: 2.5.1
Author: VBog
Author URI: https://bogaiskov.ru
License: GPL2
......@@ -37,7 +37,7 @@
if ( !defined('ABSPATH') ) {
die( 'Sorry, you are not allowed to access this page directly.' );
}
define('BG_COUNTER_VERSION', '2.4.33');
define('BG_COUNTER_VERSION', '2.5.1');
define('BG_COUNTER_LOG', dirname(__FILE__ ).'/bg_counter.log');
define('BG_COUNTER_STAT_COUNTERS','https://stat.azbyka.ru/counters');
......
......@@ -62,53 +62,57 @@ jQuery( document ).ready(function() {
data[i] = path;
i++;
});
var json = JSON.stringify(data);
var request = bg_counter.updatesocket+(bg_counter.updatetime?('?time='+bg_counter.updatetime):'');
// Создаем сокет
var updatesocket = new ReconnectingWebSocket(request);
// Отправляем данные, как только сокет будет подключен
updatesocket.onopen = function() {
if (bg_counter.debug) console.log(" Соединение установлено: "+request);
updatesocket.send(json);
};
// Слушаем сокет
updatesocket.onmessage = function(e) {
if (bg_counter.debug) console.log(" Пришло сообщение: "+e.data);
var online = JSON.parse(e.data);
jQuery('span.bg-az-counter').each (function () {
var el = jQuery(this);
var type = el.attr('data-type');
var id = el.attr('data-ID');
var project = el.attr('data-project');
if (project == "") path = "/";
else {
if (project == undefined) project = bg_counter.project;
else project = '/project/'+project;
if (!type || !id) var path = project;
else var path = project+"/"+type+"/"+id;
if (data.length) {
var json = JSON.stringify(data);
var request = bg_counter.updatesocket+(bg_counter.updatetime?('?time='+bg_counter.updatetime):'');
// Создаем сокет
var updatesocket = new ReconnectingWebSocket(request);
// Отправляем данные, как только сокет будет подключен
updatesocket.onopen = function() {
if (bg_counter.debug) {
console.log(" Соединение установлено: "+request);
console.log(" Path ("+i+"): "+json);
}
for (var key in online) {
if(path == key) {
el.find('span.bg-az-counter-now').text(addDelimiter(online[key]));
}
}
});
};
// Обработка ошибок
if (bg_counter.debug) {
updatesocket.onerror = function(error) {
console.log("Ошибка " + error.message);
updatesocket.send(json);
};
updatesocket.onclose = function(event) {
if (event.wasClean) {
console.log('Соединение закрыто чисто: '+request);
} else {
console.log('Обрыв соединения: '+request);
}
console.log('Код: ' + event.code + ' причина: ' + event.reason);
// Слушаем сокет
updatesocket.onmessage = function(e) {
if (bg_counter.debug) console.log(" Пришло сообщение: "+e.data);
var online = JSON.parse(e.data);
jQuery('span.bg-az-counter').each (function () {
var el = jQuery(this);
var type = el.attr('data-type');
var id = el.attr('data-ID');
var project = el.attr('data-project');
if (project == "") path = "/";
else {
if (project == undefined) project = bg_counter.project;
else project = '/project/'+project;
if (!type || !id) var path = project;
else var path = project+"/"+type+"/"+id;
}
for (var key in online) {
if(path == key) {
el.find('span.bg-az-counter-now').text(addDelimiter(online[key]));
}
}
});
};
// Обработка ошибок
if (bg_counter.debug) {
updatesocket.onerror = function(error) {
console.log("Ошибка " + error.message);
};
updatesocket.onclose = function(event) {
if (event.wasClean) {
console.log('Соединение закрыто чисто: '+request);
} else {
console.log('Обрыв соединения: '+request);
}
console.log('Код: ' + event.code + ' причина: ' + event.reason);
};
}
}
});
/*********************************************************************************
POST /counters/<path>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment