Commit 08da5495 authored by Vadim's avatar Vadim

Version 2.5

Разрешены типы : 'post', 'category', 'tag', 'index' для счетчиков учета посещения страниц и посетителей online. Для рейтинга - только 'post'.
parent 3b31c134
...@@ -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.4.12 Version: 2.5
Author: VBog Author: VBog
Author URI: https://bogaiskov.ru Author URI: https://bogaiskov.ru
License: GPL2 License: GPL2
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,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.4.12'); define('BG_COUNTER_VERSION', '2.4.33');
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');
...@@ -87,14 +87,23 @@ function bg_counter_enqueue_frontend_scripts () { ...@@ -87,14 +87,23 @@ function bg_counter_enqueue_frontend_scripts () {
global $project; global $project;
$option = get_option('bg_counter_options'); $option = get_option('bg_counter_options');
$postID = ''; $theID = '';
$type = ''; $type = '';
if (is_single() || is_page()) { // Только записи и страницы if (is_single() || is_page()) { // Только записи и страницы
$post = get_post(); $post = get_post();
if ($post->post_status == 'publish') { // Только опубликованные if ($post->post_status == 'publish') { // Только опубликованные
$postID = $post->ID; $theID = $post->ID;
$type = 'post'; $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_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 ); 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 () { ...@@ -108,8 +117,8 @@ function bg_counter_enqueue_frontend_scripts () {
'updatesocket' => BG_COUNTER_REALTIME_UPDATES, // Всегда 'wss://stat.azbyka.ru/updates' 'updatesocket' => BG_COUNTER_REALTIME_UPDATES, // Всегда 'wss://stat.azbyka.ru/updates'
'updatetime' => (int) $option['update'], // Время обновление счетчиков онлайн-посетителей 'updatetime' => (int) $option['update'], // Время обновление счетчиков онлайн-посетителей
'project' => $project, // Имя текущего проекта, например, '/propovedi' 'project' => $project, // Имя текущего проекта, например, '/propovedi'
'type' => $type, // Пока только 'post' или пусто 'type' => $type, // Тип объекта 'post', 'category', 'tag', 'index' или пусто
'ID' => $postID, // ID поста 'ID' => $theID, // ID объекта
'votes5' => 'голосов', 'votes5' => 'голосов',
'votes2' => 'голоcа', 'votes2' => 'голоcа',
'vote1' => 'голос', 'vote1' => 'голос',
......
...@@ -147,14 +147,39 @@ function bg_az_counter_views ($type=null, $id=null, $now=null, $rate=null, $view ...@@ -147,14 +147,39 @@ function bg_az_counter_views ($type=null, $id=null, $now=null, $rate=null, $view
global $project; global $project;
$option = get_option('bg_counter_options'); $option = get_option('bg_counter_options');
if (is_single() || is_page()) { if (is_null($type)) {
if (is_null($id)) { if (is_single() || is_page()) { // Только записи и страницы
if (!isset ($post)) $post = get_post(); $post = get_post();
$id = $post->ID; if ($post->post_status == 'publish') { // Только опубликованные
} $id = $post->ID;
if (is_null($type)) { $type = 'post';
$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)) { if (is_null($views)) {
$views = $option['views']; $views = $option['views'];
...@@ -165,6 +190,8 @@ function bg_az_counter_views ($type=null, $id=null, $now=null, $rate=null, $view ...@@ -165,6 +190,8 @@ function bg_az_counter_views ($type=null, $id=null, $now=null, $rate=null, $view
if (is_null($rate)) { if (is_null($rate)) {
$rate = $option['rate']; $rate = $option['rate'];
} }
if ($type != 'post') $rate = null;
if ($id) { if ($id) {
$link = get_permalink($id); $link = get_permalink($id);
// Получить имя проекта по ссылке // Получить имя проекта по ссылке
......
...@@ -35,18 +35,17 @@ GET /item-score/project/test/author/1 ...@@ -35,18 +35,17 @@ GET /item-score/project/test/author/1
function bg_az_counter_rating($type, $id) { function bg_az_counter_rating($type, $id) {
global $project; global $project;
if (!$id) return false;
if (!get_the_ID()) return false; if ($type == 'post') {
// Список типов записей имеющих страницу во фронте
// Список типов записей имеющих страницу во форонте $post_types = get_post_types( [ 'publicly_queryable'=>1 ] );
$post_types = get_post_types( [ 'publicly_queryable'=>1 ] ); $post_types['page'] = 'page'; // встроенный тип не имеет publicly_queryable
$post_types['page'] = 'page'; // встроенный тип не имеет publicly_queryable unset( $post_types['attachment'] ); // удалим attachment
unset( $post_types['attachment'] ); // удалим attachment $the_type = get_post_type($id);
$type = get_post_type(); if (!in_array($the_type, $post_types)) return false;
if (!in_array($type, $post_types)) return false; if (get_post_status($id) != 'publish') return false;
} else return false;
if (get_post_status() != 'publish') return false;
$option = get_option('bg_counter_options'); $option = get_option('bg_counter_options');
if ($option['title']) $page_title = $option['title']; if ($option['title']) $page_title = $option['title'];
else $page_title = get_the_title($id); else $page_title = get_the_title($id);
......
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