Commit 4cdcd1aa authored by Vadim's avatar Vadim

version 2.2.4

1. current_time('mysql') вместо time() 2. Опция: отображать общее количество просмотров записи или нет
parent 418e01a1
......@@ -3,7 +3,7 @@
Plugin Name: Bg Az-Counter
Plugin URI: https://bogaiskov.ru
Description: Подсчет количества посещений страниц на базе stat.azbyka.ru
Version: 2.2.3
Version: 2.2.4
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.2.3');
define('BG_COUNTER_VERSION', '2.2.4');
define('BG_COUNTER_LOG', dirname(__FILE__ ).'/bg_counter.log');
define('BG_COUNTER_STAT_COUNTERS','https://stat.azbyka.ru/counters');
......
......@@ -36,13 +36,13 @@ function getPopularPosts ($limit, $offset=0, $number=false) {
$result = wp_remote_get (BG_COUNTER_STAT_RATING.$project."?limit=".$limit."&offset=".$offset."&type=post");
if( is_wp_error( $result ) ) {
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." RATING (top posts). Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( PHP_EOL .current_time('mysql')." RATING (top posts). Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( " " .$result->get_error_code(), 3, BG_COUNTER_LOG ); // ключ ошибки
return false;
}
if (($code = wp_remote_retrieve_response_code( $result )) != 200) {
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." RATING (top posts). Сервер вернул код ошибки: ".$code, 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( PHP_EOL .current_time('mysql')." RATING (top posts). Сервер вернул код ошибки: ".$code, 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( " " .wp_remote_retrieve_response_message( $result ), 3, BG_COUNTER_LOG ); // ключ ошибки
return false;
}
......@@ -71,7 +71,7 @@ function getPopularPosts ($limit, $offset=0, $number=false) {
}
return $quote;
} else {
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." RATING (top posts). Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
error_log( PHP_EOL .current_time('mysql')." RATING (top posts). Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
return false;
}
}
......@@ -99,7 +99,7 @@ function setCount ($path, $counter) {
if( is_wp_error( $result ) ) {
echo "<br>".$result->get_error_message(); // сообщение ошибки
echo "<br>".$result->get_error_code(); // ключ ошибки
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SET-COUNTER. Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( PHP_EOL .current_time('mysql')." SET-COUNTER. Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( " " .$result->get_error_code(), 3, BG_COUNTER_LOG ); // ключ ошибки
return false;
}
......@@ -109,7 +109,7 @@ function setCount ($path, $counter) {
if ($response->success) return true;
else {
echo $json;
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SET-COUNTER. Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
error_log( PHP_EOL .current_time('mysql')." SET-COUNTER. Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
return false;
}
......@@ -122,7 +122,7 @@ function setAllCounts ($request) {
if( is_wp_error( $result ) ) {
echo "<br>".$result->get_error_message(); // сообщение ошибки
echo "<br>".$result->get_error_code(); // ключ ошибки
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SET-COUNTER (all). Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( PHP_EOL .current_time('mysql')." SET-COUNTER (all). Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( " " .$result->get_error_code(), 3, BG_COUNTER_LOG ); // ключ ошибки
return false;
}
......@@ -132,7 +132,7 @@ function setAllCounts ($request) {
if ($response->success) return true;
else {
echo $json;
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SET-COUNTER (all). Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
error_log( PHP_EOL .current_time('mysql')." SET-COUNTER (all). Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
return false;
}
......@@ -143,7 +143,7 @@ function setAllCounts ($request) {
Отображает разметку текста для отображения кол-ва просмотров
и кол-ва читающих пост пользователей
******************************************************************************************/
function bg_az_counter_views ($type=null, $id=null, $now=null, $rate=null) {
function bg_az_counter_views ($type=null, $id=null, $now=null, $rate=null, $views=null) {
global $project;
$option = get_option('bg_counter_options');
......@@ -156,6 +156,9 @@ function bg_az_counter_views ($type=null, $id=null, $now=null, $rate=null) {
$type='post';
}
}
if (is_null($views)) {
$views = $option['views'];
}
if (is_null($now)) {
$now = $option['now'];
}
......@@ -180,10 +183,10 @@ function bg_az_counter_views ($type=null, $id=null, $now=null, $rate=null) {
if (get_post_meta( $id, 'link', true )) $id = null;
}
if (!is_null($type) && !is_null($id)) {
$views = '<i title="Просмотры страницы" class="fa fa-eye"></i> <span class="bg-az-counter-views"></span>';
$sum = '<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>';
$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:'').($rate?$score:'').'</span>';
$quote = '<span class="bg-az-counter" data-type="'.$type.'" data-ID="'.$id.'">'.($views?$sum:'').($now?$users:'').($rate?$score:'').'</span>';
return $quote;
} else return "";
}
......@@ -204,10 +207,11 @@ function bg_counter_shortcode( $atts ) {
extract( shortcode_atts( array(
'type' => null,
'id' => null,
'views' => null,
'now' => null,
'rate' => null
), $atts ) );
$quote = bg_az_counter_views ($type, $id, $now, $rate);
$quote = bg_az_counter_views ($type, $id, $now, $rate, $views);
return "{$quote}";
}
......
......@@ -4,7 +4,7 @@
*******************************************************************************************/
// Начальные значения
add_option('bg_counter_options', array('period'=>DAY_IN_SECONDS, 'now'=>0, 'rate'=>1, 'title'=>'', 'author'=>'', 'debug'=>0, 'archive'=>0, 'pvc'=>0, 'wppp'=>0, 'wppm'=>0, 'bgar'=>0));
add_option('bg_counter_options', array('period'=>DAY_IN_SECONDS, 'views'=>1, 'now'=>1, 'rate'=>1, 'title'=>'', 'author'=>'', 'debug'=>0, 'archive'=>0, 'pvc'=>0, 'wppp'=>0, 'wppm'=>0, 'bgar'=>0));
add_option('bg_pvc_loaded', '');
add_option('bg_wppp_loaded', '');
add_option('bg_wppm_loaded', '');
......@@ -14,11 +14,14 @@ if (!isset($val['period'])) {
$val['period'] = DAY_IN_SECONDS;
update_option( 'bg_counter_period', $val['period'] );
}
if (!isset($val['views'])) {
$val['views'] = 0;
}
if (!isset($val['now'])) {
$val['now'] = 0;
}
if (!isset($val['rate'])) {
$val['rate'] = 1;
$val['rate'] = 0;
}
if (!isset($val['title'])) {
$val['title'] = "";
......@@ -185,6 +188,7 @@ function bg_counter_settings(){
// параметры: $id, $title, $callback, $page, $section, $args
add_settings_field('bg_counter_period', 'Периодичность обработки данных', 'fill_bg_counter_period', 'bg_counter_page', 'section_1' );
add_settings_field('bg_counter_views', 'Просмотров всего', 'fill_bg_counter_views', 'bg_counter_page', 'section_1' );
add_settings_field('bg_counter_now', 'Просматривают сейчас', 'fill_bg_counter_now', 'bg_counter_page', 'section_1' );
add_settings_field('bg_counter_rate', 'Оценка пользователями', 'fill_bg_counter_rate', 'bg_counter_page', 'section_1' );
add_settings_field('bg_counter_title', 'Общее название в сниппете по умолчанию', 'fill_bg_counter_title', 'bg_counter_page', 'section_1' );
......@@ -215,7 +219,15 @@ function fill_bg_counter_period(){
<?php
}
## Заполняем опцию 2
## Заполняем опцию 2a
function fill_bg_counter_views(){
$val = get_option('bg_counter_options');
$val = $val ? $val['views'] : null;
?>
<label><input type="checkbox" name="bg_counter_options[views]" value="1" <?php checked(1, $val ); ?>/> (отображать общее количество просмотров записи)</label>
<?php
}
## Заполняем опцию 2b
function fill_bg_counter_now(){
$val = get_option('bg_counter_options');
$val = $val ? $val['now'] : null;
......@@ -224,12 +236,12 @@ function fill_bg_counter_now(){
<?php
}
## Заполняем опцию 2a
## Заполняем опцию 2c
function fill_bg_counter_rate(){
$val = get_option('bg_counter_options');
$val = $val ? $val['rate'] : null;
?>
<label><input type="checkbox" name="bg_counter_options[rate]" value="1" <?php checked(1, $val ); ?>/> (отображать оценку пользователями данной записи)</label>
<label><input type="checkbox" name="bg_counter_options[rate]" value="1" <?php checked(1, $val ); ?>/> (отображать оценку пользователями записи)</label>
<?php
}
......
......@@ -45,13 +45,13 @@ function bg_az_counter_rating($type, $id) {
}
$result = wp_remote_get (BG_COUNTER_STAT_SCORE.$project."/".$type."/".$id);
if( is_wp_error( $result ) ) {
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." ITEM-SCORE. Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( PHP_EOL .current_time('mysql')." ITEM-SCORE. Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( " " .$result->get_error_code(), 3, BG_COUNTER_LOG ); // ключ ошибки
return false;
}
if (($code = wp_remote_retrieve_response_code( $result )) != 200) {
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." ITEM-SCORE. Сервер вернул код ошибки: ".$code, 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( PHP_EOL .current_time('mysql')." ITEM-SCORE. Сервер вернул код ошибки: ".$code, 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( " " .wp_remote_retrieve_response_message( $result ), 3, BG_COUNTER_LOG ); // ключ ошибки
return false;
}
......@@ -59,7 +59,7 @@ function bg_az_counter_rating($type, $id) {
$json = wp_remote_retrieve_body($result);
$response = json_decode($json, false);
if (!$response->success) {
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." ITEM-SCORE. Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
error_log( PHP_EOL .current_time('mysql')." ITEM-SCORE. Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
$score = 0;
$votes = 0;
} else {
......@@ -126,13 +126,13 @@ function getPostRating ($limit, $offset=0, $number=false) {
$result = wp_remote_get (BG_COUNTER_STAT_SCORELIST.$project."?limit=".$limit."&offset=".$offset."&type=post");
if( is_wp_error( $result ) ) {
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SCORES-LIST. Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( PHP_EOL .current_time('mysql')." SCORES-LIST. Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( " " .$result->get_error_code(), 3, BG_COUNTER_LOG ); // ключ ошибки
return false;
}
if (($code = wp_remote_retrieve_response_code( $result )) != 200) {
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SCORES-LIST. Сервер вернул код ошибки: ".$code, 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( PHP_EOL .current_time('mysql')." SCORES-LIST. Сервер вернул код ошибки: ".$code, 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( " " .wp_remote_retrieve_response_message( $result ), 3, BG_COUNTER_LOG ); // ключ ошибки
return false;
}
......@@ -147,18 +147,18 @@ function getPostRating ($limit, $offset=0, $number=false) {
else $quote = '<ul class="bg-az-top-posts">'. PHP_EOL;
foreach ($response->data as $p) {
if ($p->type!='post') {
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SCORES-LIST. Неверный тип:\n".$p->type, 3, BG_COUNTER_LOG );
error_log( PHP_EOL .current_time('mysql')." SCORES-LIST. Неверный тип:\n".$p->type, 3, BG_COUNTER_LOG );
continue;
}
$id = intval($p->id);
$votes = intval($p->votes);
if (!$id) {
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SCORES-LIST. Неверный ID:\n".$p->id, 3, BG_COUNTER_LOG );
error_log( PHP_EOL .current_time('mysql')." SCORES-LIST. Неверный ID:\n".$p->id, 3, BG_COUNTER_LOG );
continue;
}
$post = get_post($id);
if (!$post) {
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SCORES-LIST. Нет записи: \n".$p->id, 3, BG_COUNTER_LOG );
error_log( PHP_EOL .current_time('mysql')." SCORES-LIST. Нет записи: \n".$p->id, 3, BG_COUNTER_LOG );
continue;
}
$title = $post->post_title;
......@@ -173,7 +173,7 @@ function getPostRating ($limit, $offset=0, $number=false) {
}
return $quote;
} else {
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SCORES-LIST. Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
error_log( PHP_EOL .current_time('mysql')." SCORES-LIST. Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
return false;
}
}
......@@ -209,7 +209,7 @@ function setRating ($path, $request) {
if( is_wp_error( $result ) ) {
echo "<br>".$result->get_error_message(); // сообщение ошибки
echo "<br>".$result->get_error_code(); // ключ ошибки
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SET-RATING. Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( PHP_EOL .current_time('mysql')." SET-RATING. Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( " " .$result->get_error_code(), 3, BG_COUNTER_LOG ); // ключ ошибки
return false;
}
......@@ -219,7 +219,7 @@ function setRating ($path, $request) {
if ($response->success) return true;
else {
echo $json;
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SET-RATING. Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
error_log( PHP_EOL .current_time('mysql')." SET-RATING. Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
return false;
}
......@@ -233,7 +233,7 @@ function setAllRatings ($request) {
if( is_wp_error( $result ) ) {
echo "<br>".$result->get_error_message(); // сообщение ошибки
echo "<br>".$result->get_error_code(); // ключ ошибки
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SET-RATINGS (all). Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( PHP_EOL .current_time('mysql')." SET-RATINGS (all). Ошибка при получении данных с сервера: ".$result->get_error_message(), 3, BG_COUNTER_LOG ); // сообщение ошибки
error_log( " " .$result->get_error_code(), 3, BG_COUNTER_LOG ); // ключ ошибки
return false;
}
......@@ -243,7 +243,7 @@ function setAllRatings ($request) {
if ($response->success) return true;
else {
echo $json;
error_log( PHP_EOL .date("Y-m-d H:i:s ", time())." SET-RATINGS (all). Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
error_log( PHP_EOL .current_time('mysql')." SET-RATINGS (all). Сервер вернул ответ неудачи:\n".$json, 3, BG_COUNTER_LOG );
return false;
}
......
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