Commit f0f0a175 authored by Vadim's avatar Vadim

Version 2.7.2

Были нарушены 2 принципа: "Лучшее - враг хорошего", "Не трожь, если работает" - исправил
parent abed3e03
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Plugin Name: Bg Az-Counter Plugin Name: Bg Az-Counter
Plugin URI: https://bogaiskov.ru Plugin URI: https://bogaiskov.ru
Description: Подсчет количества посещений страниц на базе stat.azbyka.ru Description: Подсчет количества посещений страниц на базе stat.azbyka.ru
Version: 2.7.1 Version: 2.7.2
Author: VBog Author: VBog
Author URI: https://bogaiskov.ru Author URI: https://bogaiskov.ru
License: GPL2 License: GPL2
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
if ( !defined('ABSPATH') ) { if ( !defined('ABSPATH') ) {
die( 'Sorry, you are not allowed to access this page directly.' ); die( 'Sorry, you are not allowed to access this page directly.' );
} }
define('BG_COUNTER_VERSION', '2.7.1'); define('BG_COUNTER_VERSION', '2.7.2');
define('BG_COUNTER_LOG', dirname(__FILE__ ).'/bg_counter.log'); define('BG_COUNTER_LOG', dirname(__FILE__ ).'/bg_counter.log');
define('BG_COUNTER_STAT_COUNTERS','https://stat.azbyka.ru/counters'); define('BG_COUNTER_STAT_COUNTERS','https://stat.azbyka.ru/counters');
......
...@@ -139,12 +139,14 @@ function SendOnce(type, id) { ...@@ -139,12 +139,14 @@ function SendOnce(type, id) {
url: request, url: request,
type: "POST", type: "POST",
success: function(response){ success: function(response){
// Здесь надо будет добавить вывод данных на экран if (response.success) {
if (bg_counter.debug) { // Здесь надо будет добавить вывод данных на экран
console.log('POST REQUEST: '+request+' result:'); if (bg_counter.debug) {
console.log(JSON.stringify(response.data)); console.log('POST REQUEST: '+request+' result:');
console.log(JSON.stringify(response.data));
}
setViewCount (type, id, bg_counter_number_format(response.data.value), addDelimiter(response.data.now+1));
} }
setViewCount (type, id, bg_counter_number_format(response.data.value), addDelimiter(response.data.now+1));
}, },
error: function(xhr) { error: function(xhr) {
if (bg_counter.debug) console.warn('POST REQUEST: '+request+' ERROR '+xhr.status+': '+xhr.statusText); if (bg_counter.debug) console.warn('POST REQUEST: '+request+' ERROR '+xhr.status+': '+xhr.statusText);
...@@ -315,12 +317,14 @@ function fullBatchQuery(socket) { ...@@ -315,12 +317,14 @@ function fullBatchQuery(socket) {
} }
}); });
// Отправляем данные, как только сокет будет подключен if (socket !== undefined) {
if (socket.readyState == WebSocket.OPEN) { // Отправляем данные, как только сокет будет подключен
socket.send(json); if (socket.readyState == WebSocket.OPEN) {
} else {
socket.onopen = function() {
socket.send(json); socket.send(json);
} else {
socket.onopen = function() {
socket.send(json);
}
} }
} }
} }
......
...@@ -87,32 +87,35 @@ function getRate(type, id) { ...@@ -87,32 +87,35 @@ function getRate(type, id) {
url: request, url: request,
type: "GET", type: "GET",
success: function(response){ success: function(response){
if (bg_counter.debug) { if (response.success) {
console.log('POST REQUEST: '+request+' result:'); if (bg_counter.debug) {
console.log(JSON.stringify(response)); console.log('POST REQUEST: '+request+' result:');
console.log(JSON.stringify(response));
}
m = response.data.votes % 10;
j = response.data.votes % 100;
if(m==0 || m>=5 || (j>=10 && j<=20)) txt_votes = bg_counter.votes5;
else if(m>=2 && m<=4) txt_votes = bg_counter.votes2;
else txt_votes = bg_counter.vote1;
start_rate_index = parseFloat(response.data.score).toFixed(1);
jQuery('#bg_counter_votes').html(response.data.votes);
jQuery('#bg_counter_votes_txt').html(txt_votes);
jQuery('#bg_counter_score').html(start_rate_index);
jQuery('meta[itemprop=ratingCount]').attr("content", response.data.votes);
jQuery('meta[itemprop=ratingValue]').attr("content", start_rate_index);
rating_voted = response.data.alreadyVoted;
iniRatingState(start_rate_index, rating_voted);
} else {
jQuery('#bg_counter_votes').html('0');
jQuery('#bg_counter_votes_txt').html(bg_counter.votes5);
jQuery('#bg_counter_score').html('0');
jQuery('meta[itemprop=ratingCount]').attr("content", 0);
jQuery('meta[itemprop=ratingValue]').attr("content", 0);
iniRatingState(0, false);
} }
m = response.data.votes % 10;
j = response.data.votes % 100;
if(m==0 || m>=5 || (j>=10 && j<=20)) txt_votes = bg_counter.votes5;
else if(m>=2 && m<=4) txt_votes = bg_counter.votes2;
else txt_votes = bg_counter.vote1;
start_rate_index = parseFloat(response.data.score).toFixed(1);
jQuery('#bg_counter_votes').html(response.data.votes);
jQuery('#bg_counter_votes_txt').html(txt_votes);
jQuery('#bg_counter_score').html(start_rate_index);
jQuery('meta[itemprop=ratingCount]').attr("content", response.data.votes);
jQuery('meta[itemprop=ratingValue]').attr("content", start_rate_index);
rating_voted = response.data.alreadyVoted;
iniRatingState(start_rate_index, rating_voted);
}, },
error: function(xhr) { error: function(xhr) {
if (bg_counter.debug) console.warn('POST REQUEST: '+request+' ERROR '+xhr.status+': '+xhr.statusText); if (bg_counter.debug) console.warn('POST REQUEST: '+request+' ERROR '+xhr.status+': '+xhr.statusText);
jQuery('#bg_counter_votes').html('0');
jQuery('#bg_counter_votes_txt').html(bg_counter.votes5);
jQuery('#bg_counter_score').html('0');
jQuery('meta[itemprop=ratingCount]').attr("content", 0);
jQuery('meta[itemprop=ratingValue]').attr("content", 0);
iniRatingState(0, false);
} }
}); });
} }
...@@ -146,25 +149,43 @@ function sendRate(type, id, number) { ...@@ -146,25 +149,43 @@ function sendRate(type, id, number) {
jQuery.ajax ({ jQuery.ajax ({
url: request, url: request,
type: "POST", type: "POST",
data: '{"rating": '+number+'}',
success: function(response){ success: function(response){
// Вывод данных на экран if (response.success) {
if (bg_counter.debug) { // Вывод данных на экран
console.log('POST REQUEST: '+request+' result:'); if (bg_counter.debug) {
console.log(JSON.stringify(response)); console.log('POST REQUEST: '+request+' result:');
console.log(JSON.stringify(response));
}
m = response.data.votes % 10;
j = response.data.votes % 100;
if(m==0 || m>=5 || (j>=10 && j<=20)) txt_votes = bg_counter.votes5;
else if(m>=2 && m<=4) txt_votes = bg_counter.votes2;
else txt_votes = bg_counter.vote1;
start_rate_index = parseFloat(response.data.score).toFixed(1);
jQuery('#bg_counter_votes').html(response.data.votes);
jQuery('#bg_counter_votes_txt').html(txt_votes);
jQuery('#bg_counter_score').html(start_rate_index);
jQuery('meta[itemprop=ratingCount]').attr("content", response.data.votes);
jQuery('meta[itemprop=ratingValue]').attr("content", start_rate_index);
iniRatingState(start_rate_index, true);
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 (request == bg_counter.rateurl+path) el.find('span.bg-az-counter-score').text(parseFloat(response.data.score).toFixed(1));
});
// fullBatchQuery();
} }
m = response.data.votes % 10;
j = response.data.votes % 100;
if(m==0 || m>=5 || (j>=10 && j<=20)) txt_votes = bg_counter.votes5;
else if(m>=2 && m<=4) txt_votes = bg_counter.votes2;
else txt_votes = bg_counter.vote1;
start_rate_index = parseFloat(response.data.score).toFixed(1);
jQuery('#bg_counter_votes').html(response.data.votes);
jQuery('#bg_counter_votes_txt').html(txt_votes);
jQuery('#bg_counter_score').html(start_rate_index);
jQuery('meta[itemprop=ratingCount]').attr("content", response.data.votes);
jQuery('meta[itemprop=ratingValue]').attr("content", start_rate_index);
iniRatingState(start_rate_index, true);
getAllRates();
}, },
error: function(xhr) { error: function(xhr) {
if (bg_counter.debug) console.warn('POST REQUEST: '+request+' ERROR '+xhr.status+': '+xhr.statusText); if (bg_counter.debug) console.warn('POST REQUEST: '+request+' ERROR '+xhr.status+': '+xhr.statusText);
......
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