Commit bd9c416c authored by Vadim's avatar Vadim

Version 2.2

1. Кол-во постов в виджете 2. "Звездочка" в инфостроке поста 3. Старо-новые названия оценок 4. Поиск постов-ссылок
parent f75eab89
...@@ -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.1.1 Version: 2.2
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.1.1'); define('BG_COUNTER_VERSION', '2.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');
...@@ -112,7 +112,7 @@ function bg_counter_enqueue_frontend_scripts () { ...@@ -112,7 +112,7 @@ function bg_counter_enqueue_frontend_scripts () {
'votes2' => 'голоcа', 'votes2' => 'голоcа',
'vote1' => 'голос', 'vote1' => 'голос',
'voted' => 'Вы уже проголосовали', 'voted' => 'Вы уже проголосовали',
'price' => array("ужасно", "плохо", "удовлетворительно", "хорошо", "отлично"), 'price' => array("тяжко", "слабо", "сносно", "достойно", "чудесно"),
'debug' => ((int) $option['debug'])?true:false // Выводить или нет инфу в консоль 'debug' => ((int) $option['debug'])?true:false // Выводить или нет инфу в консоль
) )
); );
...@@ -140,3 +140,54 @@ include_once ("inc/counter.php"); ...@@ -140,3 +140,54 @@ include_once ("inc/counter.php");
// Запускаем голосование // Запускаем голосование
include_once ("inc/rating.php"); include_once ("inc/rating.php");
/*****************************************************************************************
Этот блок позволяет найти на сайте посты-ссылки,
по наличию произвольного поля 'link'
Шорт-код [find_meta_link] выводит на экран список таких постов
с ссылкой на страницу его редактирования
******************************************************************************************/
// Регистрируем шорт-код find_meta_link
add_shortcode( 'find_meta_link', 'find_meta_link_shortcode' );
// [find_meta_link]
function find_meta_link_shortcode( $atts ) {
// Список типов записей имеющих страницу во форонте
$post_types = get_post_types( [ 'publicly_queryable'=>1 ] );
$post_types['page'] = 'page'; // встроенный тип не имеет publicly_queryable
unset( $post_types['attachment'] ); // удалим attachment
$true_query = new WP_Query( $true_args );
// задаем нужные нам критерии выборки данных из БД
$args = array(
'posts_per_page' => -1,
'post_type' => $post_types,
'meta_query' => array(
array(
'key' => 'link'
)
)
);
$query = new WP_Query( $args );
// Цикл
if ( $query->have_posts() ) {
$quote .= '<ol>';
while ( $query->have_posts() ) {
$query->the_post();
$quote .= '<li><a href="https://azbyka.ru/propovedi/wp-admin/post.php?post=' . get_the_ID() . '&action=edit">' . get_the_title() . '</a></li>';
}
}
$quote .= '</ol>';
// Возвращаем оригинальные данные поста. Сбрасываем $post.
wp_reset_postdata();
return "{$quote}";
}
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
} }
.widget-item li .bg-az-count, .widget-item li .bg-az-count,
.widget-item p .bg-az-counter-now, .widget-item p .bg-az-counter-now,
.widget-item p .bg-az-counter-views { .widget-item p .bg-az-counter-views,
.widget-item p .bg-az-counter-posts {
color: #999; color: #999;
} }
.widget-item li:hover { .widget-item li:hover {
...@@ -36,7 +37,8 @@ ...@@ -36,7 +37,8 @@
transition: all .4s ease; transition: all .4s ease;
} }
i.fa-user-o:before { i.fa-user-o:before,
i.fa-star-o:before {
margin-left: 1em; margin-left: 1em;
} }
......
...@@ -177,7 +177,8 @@ function bg_az_counter_views ($type=null, $id=null, $now=null) { ...@@ -177,7 +177,8 @@ function bg_az_counter_views ($type=null, $id=null, $now=null) {
if (!is_null($type) && !is_null($id)) { if (!is_null($type) && !is_null($id)) {
$views = '<i title="Просмотры страницы" class="fa fa-eye"></i> <span class="bg-az-counter-views"></span>'; $views = '<i title="Просмотры страницы" class="fa fa-eye"></i> <span class="bg-az-counter-views"></span>';
$users = ' <i title="Сейчас читают страницу" class="fa fa-user-o"></i> <span class="bg-az-counter-now"></span>'; $users = ' <i title="Сейчас читают страницу" class="fa fa-user-o"></i> <span class="bg-az-counter-now"></span>';
$quote = '<span class="bg-az-counter" data-type="'.$type.'" data-ID="'.$id.'">'.$views.($now?$users:'').'</span>'; $score = ' <i title="Оценка пользователей" class="fa fa-star-o"></i> <span class="bg-az-counter-score"></span>';
$quote = '<span class="bg-az-counter" data-type="'.$type.'" data-ID="'.$id.'">'.$views.($now?$users:'').$score.'</span>';
return $quote; return $quote;
} else return ""; } else return "";
} }
......
...@@ -11,7 +11,7 @@ class bg_counter_TopPostsWidget extends WP_Widget { ...@@ -11,7 +11,7 @@ class bg_counter_TopPostsWidget extends WP_Widget {
parent::__construct( parent::__construct(
'bg_counter_top_widget', 'bg_counter_top_widget',
'Популярные записи', // заголовок виджета 'Популярные записи', // заголовок виджета
array( 'description' => 'Позволяет вывести записи, отсортированные по количеству просмотров.' ) // описание array( 'description' => 'Bg Az-Counter: Позволяет вывести записи, отсортированные по количеству просмотров.' ) // описание
); );
} }
...@@ -69,8 +69,8 @@ class bg_counter_TopPostsWidget extends WP_Widget { ...@@ -69,8 +69,8 @@ class bg_counter_TopPostsWidget extends WP_Widget {
/***************************************************************************************** /*****************************************************************************************
Виджет отображает в сайдбаре Виджет отображает в сайдбаре
Количество онлайн посетителей на сайте Количество онлайн посетителей на сайте,
и Общее количество просмотров общее количество просмотров и количество записей
******************************************************************************************/ ******************************************************************************************/
class bg_counter_OnlineNowWidget extends WP_Widget { class bg_counter_OnlineNowWidget extends WP_Widget {
...@@ -80,7 +80,7 @@ class bg_counter_OnlineNowWidget extends WP_Widget { ...@@ -80,7 +80,7 @@ class bg_counter_OnlineNowWidget extends WP_Widget {
parent::__construct( parent::__construct(
'bg_counter_online_widget', 'bg_counter_online_widget',
'Сейчас на сайте', // заголовок виджета 'Сейчас на сайте', // заголовок виджета
array( 'description' => 'Количество посетителей на сайте.' ) // описание array( 'description' => 'Bg Az-Counter: Количество посетителей на сайте.' ) // описание
); );
} }
...@@ -89,6 +89,7 @@ class bg_counter_OnlineNowWidget extends WP_Widget { ...@@ -89,6 +89,7 @@ class bg_counter_OnlineNowWidget extends WP_Widget {
$title = apply_filters( 'widget_title', $instance['title'] ); // к заголовку применяем фильтр (необязательно) $title = apply_filters( 'widget_title', $instance['title'] ); // к заголовку применяем фильтр (необязательно)
$subtitle1 = $instance['subtitle1']; $subtitle1 = $instance['subtitle1'];
$subtitle2 = $instance['subtitle2']; $subtitle2 = $instance['subtitle2'];
$subtitle3 = $instance['subtitle3'];
echo $args['before_widget']; echo $args['before_widget'];
...@@ -101,6 +102,8 @@ class bg_counter_OnlineNowWidget extends WP_Widget { ...@@ -101,6 +102,8 @@ class bg_counter_OnlineNowWidget extends WP_Widget {
<span class="bg-az-counter"> <span class="bg-az-counter">
<p><?php echo $subtitle1; ?>: <span class="bg-az-counter-now"></span></p> <p><?php echo $subtitle1; ?>: <span class="bg-az-counter-now"></span></p>
<p><?php echo $subtitle2; ?>: <span class="bg-az-counter-views"></span></p> <p><?php echo $subtitle2; ?>: <span class="bg-az-counter-views"></span></p>
<p><?php echo $subtitle3; ?>: <span class="bg-az-counter-posts"><?php echo wp_count_posts()->publish; ?></span></p>
</span> </span>
</div> </div>
</div> </div>
...@@ -113,22 +116,23 @@ class bg_counter_OnlineNowWidget extends WP_Widget { ...@@ -113,22 +116,23 @@ class bg_counter_OnlineNowWidget extends WP_Widget {
if ( isset( $instance[ 'title' ] ) ) { if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ]; $title = $instance[ 'title' ];
} }
if ( isset( $instance[ 'posts_per_page' ] ) ) {
$posts_per_page = $instance[ 'posts_per_page' ];
}
?> ?>
<p> <p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>">Заголовок</label> <label for="<?php echo $this->get_field_id( 'title' ); ?>">Заголовок</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p> </p>
<p> <p>
<label for="<?php echo $this->get_field_id( 'subtitle1' ); ?>">Количество записей:</label> <label for="<?php echo $this->get_field_id( 'subtitle1' ); ?>">Сейчас на сайте:</label>
<input id="<?php echo $this->get_field_id( 'subtitle1' ); ?>" name="<?php echo $this->get_field_name( 'subtitle1' ); ?>" type="text" value="<?php echo ($subtitle1) ? esc_attr( $subtitle1 ) : 'Сейчас на сайте'; ?>" /> <input id="<?php echo $this->get_field_id( 'subtitle1' ); ?>" name="<?php echo $this->get_field_name( 'subtitle1' ); ?>" type="text" value="<?php echo ($subtitle1) ? esc_attr( $subtitle1 ) : 'Сейчас на сайте'; ?>" />
</p> </p>
<p> <p>
<label for="<?php echo $this->get_field_id( 'subtitle2' ); ?>">Количество записей:</label> <label for="<?php echo $this->get_field_id( 'subtitle2' ); ?>">Всего просмотров:</label>
<input id="<?php echo $this->get_field_id( 'subtitle2' ); ?>" name="<?php echo $this->get_field_name( 'subtitle2' ); ?>" type="text" value="<?php echo ($subtitle2) ? esc_attr( $subtitle2 ) : 'Всего просмотров'; ?>" /> <input id="<?php echo $this->get_field_id( 'subtitle2' ); ?>" name="<?php echo $this->get_field_name( 'subtitle2' ); ?>" type="text" value="<?php echo ($subtitle2) ? esc_attr( $subtitle2 ) : 'Всего просмотров'; ?>" />
</p> </p>
<p>
<label for="<?php echo $this->get_field_id( 'subtitle3' ); ?>">Всего записей:</label>
<input id="<?php echo $this->get_field_id( 'subtitle3' ); ?>" name="<?php echo $this->get_field_name( 'subtitle3' ); ?>" type="text" value="<?php echo ($subtitle3) ? esc_attr( $subtitle3 ) : 'Всего записей'; ?>" />
</p>
<?php <?php
} }
...@@ -138,6 +142,7 @@ class bg_counter_OnlineNowWidget extends WP_Widget { ...@@ -138,6 +142,7 @@ class bg_counter_OnlineNowWidget extends WP_Widget {
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
$instance['subtitle1'] = ( ! empty( $new_instance['subtitle1'] ) ) ? strip_tags( $new_instance['subtitle1'] ) : 'Сейчас на сайте'; $instance['subtitle1'] = ( ! empty( $new_instance['subtitle1'] ) ) ? strip_tags( $new_instance['subtitle1'] ) : 'Сейчас на сайте';
$instance['subtitle2'] = ( ! empty( $new_instance['subtitle2'] ) ) ? strip_tags( $new_instance['subtitle2'] ) : 'Всего просмотров'; $instance['subtitle2'] = ( ! empty( $new_instance['subtitle2'] ) ) ? strip_tags( $new_instance['subtitle2'] ) : 'Всего просмотров';
$instance['subtitle3'] = ( ! empty( $new_instance['subtitle3'] ) ) ? strip_tags( $new_instance['subtitle3'] ) : 'Всего записей';
return $instance; return $instance;
} }
} }
...@@ -153,7 +158,7 @@ class bg_counter_PostRatingWidget extends WP_Widget { ...@@ -153,7 +158,7 @@ class bg_counter_PostRatingWidget extends WP_Widget {
parent::__construct( parent::__construct(
'bg_counter_post_rating_widget', 'bg_counter_post_rating_widget',
'Популярные записи', // заголовок виджета 'Популярные записи', // заголовок виджета
array( 'description' => 'Позволяет вывести записи, отсортированные по количеству голосов.' ) // описание array( 'description' => 'Bg Az-Counter: Позволяет вывести записи, отсортированные по количеству голосов.' ) // описание
); );
} }
......
...@@ -5,6 +5,7 @@ options.path=window.location.pathname; // Текущий путь ...@@ -5,6 +5,7 @@ options.path=window.location.pathname; // Текущий путь
jQuery( document ).ready(function() { jQuery( document ).ready(function() {
getAllRates();
if (!bg_counter.ID) return; if (!bg_counter.ID) return;
// start_rate_index = Math.round(parseFloat(jQuery( "#bg_counter_score" ).html())); // start_rate_index = Math.round(parseFloat(jQuery( "#bg_counter_score" ).html()));
...@@ -15,6 +16,7 @@ jQuery( document ).ready(function() { ...@@ -15,6 +16,7 @@ jQuery( document ).ready(function() {
iniRatingState(start_rate_index, rating_voted); iniRatingState(start_rate_index, rating_voted);
getRate(bg_counter.type, bg_counter.ID); getRate(bg_counter.type, bg_counter.ID);
jQuery( "#bg_counter_rate_box li" ).mouseover(function() { jQuery( "#bg_counter_rate_box li" ).mouseover(function() {
if(!rating_voted){ if(!rating_voted){
var index = jQuery( this ).index(); var index = jQuery( this ).index();
...@@ -123,6 +125,40 @@ function getRate(type, id) { ...@@ -123,6 +125,40 @@ function getRate(type, id) {
} }
function getAllRates() {
jQuery('span.bg-az-counter').each (function () {
var el = jQuery(this);
var type = el.attr('data-type');
var id = el.attr('data-ID');
if (!type || !id) return;
var request = bg_counter.scoreurl+bg_counter.project+"/"+type+"/"+id;
var xhr = new XMLHttpRequest();
xhr.open("GET", request, true);
if (bg_counter.debug) console.log('GET REQUEST: '+request);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
if (xhr.responseText) {
var response = JSON.parse(xhr.responseText);
if (response.success) {
// Вывод данных на экран
if (bg_counter.debug) console.log(JSON.stringify(response.data));
el.find('span.bg-az-counter-score').text(parseFloat(response.data.score).toFixed(1));
} else {
if (bg_counter.debug) console.log('GET REQUEST: '+request+' ERROR: '+response.error);
el.find('span.bg-az-counter-score').text('0');
}
} else {
if (bg_counter.debug) console.warn('GET REQUEST: '+request+' Warning: responseText is empty!');
el.find('span.bg-az-counter-score').text(' - ');
}
}
}
xhr.send();
});
}
/********************************************************************************* /*********************************************************************************
POST /rate/<path> POST /rate/<path>
...@@ -170,6 +206,7 @@ function sendRate(type, id, number) { ...@@ -170,6 +206,7 @@ function sendRate(type, id, number) {
jQuery('#bg_counter_votes_txt').html(txt_votes); jQuery('#bg_counter_votes_txt').html(txt_votes);
jQuery('#bg_counter_score').html(start_rate_index); jQuery('#bg_counter_score').html(start_rate_index);
iniRatingState(start_rate_index, true); iniRatingState(start_rate_index, true);
getAllRates();
} else { } else {
if (bg_counter.debug) console.log('POST REQUEST: '+request+' ERROR: '+response.error); if (bg_counter.debug) console.log('POST REQUEST: '+request+' ERROR: '+response.error);
} }
......
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