Commit 08da5495 authored by Vadim's avatar Vadim

Version 2.5

Разрешены типы : 'post', 'category', 'tag', 'index' для счетчиков учета посещения страниц и посетителей online. Для рейтинга - только 'post'.
parent 3b31c134
......@@ -3,7 +3,7 @@
Plugin Name: Bg Az-Counter
Plugin URI: https://bogaiskov.ru
Description: Подсчет количества посещений страниц на базе stat.azbyka.ru
Version: 2.4.12
Version: 2.5
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.12');
define('BG_COUNTER_VERSION', '2.4.33');
define('BG_COUNTER_LOG', dirname(__FILE__ ).'/bg_counter.log');
define('BG_COUNTER_STAT_COUNTERS','https://stat.azbyka.ru/counters');
......@@ -87,14 +87,23 @@ function bg_counter_enqueue_frontend_scripts () {
global $project;
$option = get_option('bg_counter_options');
$postID = '';
$theID = '';
$type = '';
if (is_single() || is_page()) { // Только записи и страницы
$post = get_post();
if ($post->post_status == 'publish') { // Только опубликованные
$postID = $post->ID;
$theID = $post->ID;
$type = 'post';
}
} elseif (is_category()) {
$theID = get_query_var('cat');
$type = 'category';
} elseif (is_tag()) {
$theID = get_query_var('tag_id');
$type = 'tag';
} elseif (is_home()) {
$theID = 1;
$type = 'index';
}
wp_enqueue_script( 'bg_counter_websocket', plugins_url( 'js/reconnecting-websocket.min.js', __FILE__ ), false, BG_COUNTER_VERSION, true );
wp_enqueue_script( 'bg_counter_rating', plugins_url( 'js/rating.js', __FILE__ ), false, BG_COUNTER_VERSION, true );
......@@ -108,8 +117,8 @@ function bg_counter_enqueue_frontend_scripts () {
'updatesocket' => BG_COUNTER_REALTIME_UPDATES, // Всегда 'wss://stat.azbyka.ru/updates'
'updatetime' => (int) $option['update'], // Время обновление счетчиков онлайн-посетителей
'project' => $project, // Имя текущего проекта, например, '/propovedi'
'type' => $type, // Пока только 'post' или пусто
'ID' => $postID, // ID поста
'type' => $type, // Тип объекта 'post', 'category', 'tag', 'index' или пусто
'ID' => $theID, // ID объекта
'votes5' => 'голосов',
'votes2' => 'голоcа',
'vote1' => 'голос',
......
......@@ -147,14 +147,39 @@ function bg_az_counter_views ($type=null, $id=null, $now=null, $rate=null, $view
global $project;
$option = get_option('bg_counter_options');
if (is_single() || is_page()) {
if (is_null($id)) {
if (!isset ($post)) $post = get_post();
$id = $post->ID;
}
if (is_null($type)) {
$type='post';
if (is_single() || is_page()) { // Только записи и страницы
$post = get_post();
if ($post->post_status == 'publish') { // Только опубликованные
$id = $post->ID;
$type = 'post';
} else return false;
} elseif (is_category()) {
$id = get_query_var('cat');
$type = 'category';
} elseif (is_tag()) {
$id = get_query_var('tag_id');
$type = 'tag';
} elseif (is_home()) {
$id = 1;
$type = 'index';
} else return false;
}
if (is_null($id)) {
if ($type == 'post') { // Только записи и страницы
$post = get_post();
if ($post->post_status == 'publish') { // Только опубликованные
$id = $post->ID;
} else return false;
} elseif ($type == 'category') {
$cat = get_the_category();
$id = $cat->cat_ID;
} elseif ($type == 'tag') {
$tags = get_the_tags();
$id = $tags->term_id ;
} elseif ($type == 'index') {
$id = 1;
} else return false;
}
if (is_null($views)) {
$views = $option['views'];
......@@ -165,6 +190,8 @@ function bg_az_counter_views ($type=null, $id=null, $now=null, $rate=null, $view
if (is_null($rate)) {
$rate = $option['rate'];
}
if ($type != 'post') $rate = null;
if ($id) {
$link = get_permalink($id);
// Получить имя проекта по ссылке
......
......@@ -35,17 +35,16 @@ GET /item-score/project/test/author/1
function bg_az_counter_rating($type, $id) {
global $project;
if (!get_the_ID()) return false;
// Список типов записей имеющих страницу во форонте
if (!$id) return false;
if ($type == 'post') {
// Список типов записей имеющих страницу во фронте
$post_types = get_post_types( [ 'publicly_queryable'=>1 ] );
$post_types['page'] = 'page'; // встроенный тип не имеет publicly_queryable
unset( $post_types['attachment'] ); // удалим attachment
$type = get_post_type();
if (!in_array($type, $post_types)) return false;
if (get_post_status() != 'publish') return false;
$the_type = get_post_type($id);
if (!in_array($the_type, $post_types)) return false;
if (get_post_status($id) != 'publish') return false;
} else return false;
$option = get_option('bg_counter_options');
if ($option['title']) $page_title = $option['title'];
......
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