Version Description
Download this release
Release Info
Developer | bhittani |
Plugin | kk Star Ratings |
Version | 5.2.5 |
Comparing to | |
See all releases |
Code changes from version 5.2.4 to 5.2.5
- CHANGELOG.md +10 -0
- index.php +1 -1
- languages/kk-star-ratings.pot +5 -5
- readme.txt +1 -1
- src/core/actions/admin/script.php +5 -1
- src/core/actions/admin/style.php +1 -1
- src/core/actions/script.php +2 -18
- src/core/actions/sd.php +2 -8
- src/core/actions/style.php +3 -7
- src/core/filters/blocks.php +22 -0
- src/core/filters/embed.php +38 -0
- src/core/filters/payload.php +16 -2
- src/core/functions/data.php +24 -0
- src/core/functions/ld_json.php +26 -0
- src/core/functions/scripts/index.php +15 -0
- src/core/functions/scripts/main.php +39 -0
- src/core/functions/styles/index.php +15 -0
- src/core/functions/styles/main.php +28 -0
- src/core/functions/width.php +5 -2
- src/core/index.php +15 -3
- src/core/wp/actions/admin_enqueue_scripts.php +3 -5
- src/core/wp/actions/init.php +27 -0
- src/core/wp/actions/wp_head.php +4 -7
- src/core/wp/{filters → functions}/the_content.php +4 -10
- src/functions/autoload_blocks.php +79 -0
- src/functions/bind.php +27 -0
- src/functions/block.php +36 -0
- src/functions/prefix.php +3 -3
- src/functions/relative.php +25 -0
- src/functions/url.php +22 -0
CHANGELOG.md
CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
|
|
5 |
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6 |
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
## [5.2.4] - 2021-11-22
|
9 |
|
10 |
### Fixed
|
5 |
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6 |
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7 |
|
8 |
+
## [5.2.5] - 2022-01-22
|
9 |
+
|
10 |
+
### Added
|
11 |
+
- Support for custom rich snippets (ld_json) with binding.
|
12 |
+
- Support for Gutenberg blocks using hooks.
|
13 |
+
- Url and path utility functions.
|
14 |
+
|
15 |
+
### Fixed
|
16 |
+
- The prefix function logic has been corrected.
|
17 |
+
|
18 |
## [5.2.4] - 2021-11-22
|
19 |
|
20 |
### Fixed
|
index.php
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
* Author URI: http://bhittani.com
|
11 |
* Text Domain: kk-star-ratings
|
12 |
* Domain Path: /languages
|
13 |
-
* Version: 5.2.
|
14 |
* License: GPLv2 or later
|
15 |
*/
|
16 |
|
10 |
* Author URI: http://bhittani.com
|
11 |
* Text Domain: kk-star-ratings
|
12 |
* Domain Path: /languages
|
13 |
+
* Version: 5.2.5
|
14 |
* License: GPLv2 or later
|
15 |
*/
|
16 |
|
languages/kk-star-ratings.pot
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
-
# Copyright (C)
|
2 |
# This file is distributed under the same license as the kk Star Ratings plugin.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
-
"Project-Id-Version: kk Star Ratings 5.2.
|
6 |
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/kk-star-ratings\n"
|
7 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
8 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
9 |
"MIME-Version: 1.0\n"
|
10 |
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
"Content-Transfer-Encoding: 8bit\n"
|
12 |
-
"POT-Creation-Date:
|
13 |
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
14 |
"X-Generator: WP-CLI 2.4.0\n"
|
15 |
"X-Domain: kk-star-ratings\n"
|
@@ -381,12 +381,12 @@ msgctxt "Label"
|
|
381 |
msgid "Select Icon"
|
382 |
msgstr ""
|
383 |
|
384 |
-
#: src/premium/top-rated-posts/classes/TopRatedPostsWidget.php:
|
385 |
msgctxt "label"
|
386 |
msgid "Top Rated Posts"
|
387 |
msgstr ""
|
388 |
|
389 |
-
#: src/premium/top-rated-posts/classes/TopRatedPostsWidget.php:
|
390 |
msgid "Show top rated posts."
|
391 |
msgstr ""
|
392 |
|
1 |
+
# Copyright (C) 2022 Kamal Khan
|
2 |
# This file is distributed under the same license as the kk Star Ratings plugin.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
+
"Project-Id-Version: kk Star Ratings 5.2.5\n"
|
6 |
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/kk-star-ratings\n"
|
7 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
8 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
9 |
"MIME-Version: 1.0\n"
|
10 |
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"POT-Creation-Date: 2022-01-22T10:15:19+00:00\n"
|
13 |
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
14 |
"X-Generator: WP-CLI 2.4.0\n"
|
15 |
"X-Domain: kk-star-ratings\n"
|
381 |
msgid "Select Icon"
|
382 |
msgstr ""
|
383 |
|
384 |
+
#: src/premium/top-rated-posts/classes/TopRatedPostsWidget.php:41
|
385 |
msgctxt "label"
|
386 |
msgid "Top Rated Posts"
|
387 |
msgstr ""
|
388 |
|
389 |
+
#: src/premium/top-rated-posts/classes/TopRatedPostsWidget.php:53
|
390 |
msgid "Show top rated posts."
|
391 |
msgstr ""
|
392 |
|
readme.txt
CHANGED
@@ -6,7 +6,7 @@ Tags: star ratings, votings, rate posts, ajax ratings, infinite stars, unlimited
|
|
6 |
Requires at least: 5.0
|
7 |
Requires PHP: 7.2
|
8 |
Tested up to: 5.8.1
|
9 |
-
Stable tag: 5.2.
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
6 |
Requires at least: 5.0
|
7 |
Requires PHP: 7.2
|
8 |
Tested up to: 5.8.1
|
9 |
+
Stable tag: 5.2.5
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
src/core/actions/admin/script.php
CHANGED
@@ -19,9 +19,13 @@ if (! defined('KK_STAR_RATINGS')) {
|
|
19 |
exit();
|
20 |
}
|
21 |
|
22 |
-
function script(bool $isDebugMode = false): void
|
23 |
{
|
24 |
// if (! migrations()->isEmpty()) {
|
25 |
// script_migrations($isDebugMode);
|
26 |
// }
|
|
|
|
|
|
|
|
|
27 |
}
|
19 |
exit();
|
20 |
}
|
21 |
|
22 |
+
function script(string $hook, bool $isDebugMode = false): void
|
23 |
{
|
24 |
// if (! migrations()->isEmpty()) {
|
25 |
// script_migrations($isDebugMode);
|
26 |
// }
|
27 |
+
|
28 |
+
if ($hook == ('toplevel_page_'.kksr('slug'))) {
|
29 |
+
// Admin menu hook.
|
30 |
+
}
|
31 |
}
|
src/core/actions/admin/style.php
CHANGED
@@ -16,6 +16,6 @@ if (! defined('KK_STAR_RATINGS')) {
|
|
16 |
exit();
|
17 |
}
|
18 |
|
19 |
-
function style(bool $isDebugMode = false): void
|
20 |
{
|
21 |
}
|
16 |
exit();
|
17 |
}
|
18 |
|
19 |
+
function style(string $hook, bool $isDebugMode = false): void
|
20 |
{
|
21 |
}
|
src/core/actions/script.php
CHANGED
@@ -13,6 +13,7 @@ namespace Bhittani\StarRating\core\actions;
|
|
13 |
|
14 |
use function Bhittani\StarRating\core\functions\migrations;
|
15 |
use function Bhittani\StarRating\core\functions\script_migrations;
|
|
|
16 |
|
17 |
if (! defined('KK_STAR_RATINGS')) {
|
18 |
http_response_code(404);
|
@@ -25,22 +26,5 @@ function script(bool $isDebugMode = false): void
|
|
25 |
// script_migrations($isDebugMode);
|
26 |
// }
|
27 |
|
28 |
-
|
29 |
-
kksr('slug'),
|
30 |
-
kksr('core.url').'public/js/kk-star-ratings'
|
31 |
-
.($isDebugMode ? '' : '.min').'.js',
|
32 |
-
['jquery'],
|
33 |
-
kksr('version'),
|
34 |
-
true
|
35 |
-
);
|
36 |
-
|
37 |
-
wp_localize_script(
|
38 |
-
kksr('slug'),
|
39 |
-
str_replace('-', '_', kksr('slug')),
|
40 |
-
[
|
41 |
-
'action' => kksr('slug'),
|
42 |
-
'endpoint' => admin_url('admin-ajax.php'),
|
43 |
-
'nonce' => wp_create_nonce(kksr('core.wp.actions.wp_ajax_'.kksr('slug'))),
|
44 |
-
]
|
45 |
-
);
|
46 |
}
|
13 |
|
14 |
use function Bhittani\StarRating\core\functions\migrations;
|
15 |
use function Bhittani\StarRating\core\functions\script_migrations;
|
16 |
+
use function Bhittani\StarRating\core\functions\scripts\main;
|
17 |
|
18 |
if (! defined('KK_STAR_RATINGS')) {
|
19 |
http_response_code(404);
|
26 |
// script_migrations($isDebugMode);
|
27 |
// }
|
28 |
|
29 |
+
main($isDebugMode);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
}
|
src/core/actions/sd.php
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
|
12 |
namespace Bhittani\StarRating\core\actions;
|
13 |
|
14 |
-
use function Bhittani\StarRating\core\functions\
|
15 |
|
16 |
if (! defined('KK_STAR_RATINGS')) {
|
17 |
http_response_code(404);
|
@@ -20,11 +20,5 @@ if (! defined('KK_STAR_RATINGS')) {
|
|
20 |
|
21 |
function sd(array $payload): void
|
22 |
{
|
23 |
-
|
24 |
-
$sd = str_replace('{best}', $payload['best'], $sd);
|
25 |
-
$sd = str_replace('{count}', $payload['count'], $sd);
|
26 |
-
$sd = str_replace('{score}', $payload['score'], $sd);
|
27 |
-
$sd = str_replace('{title}', $payload['title'], $sd);
|
28 |
-
|
29 |
-
echo $sd;
|
30 |
}
|
11 |
|
12 |
namespace Bhittani\StarRating\core\actions;
|
13 |
|
14 |
+
use function Bhittani\StarRating\core\functions\ld_json;
|
15 |
|
16 |
if (! defined('KK_STAR_RATINGS')) {
|
17 |
http_response_code(404);
|
20 |
|
21 |
function sd(array $payload): void
|
22 |
{
|
23 |
+
echo ld_json($payload);
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
}
|
src/core/actions/style.php
CHANGED
@@ -11,6 +11,8 @@
|
|
11 |
|
12 |
namespace Bhittani\StarRating\core\actions;
|
13 |
|
|
|
|
|
14 |
if (! defined('KK_STAR_RATINGS')) {
|
15 |
http_response_code(404);
|
16 |
exit();
|
@@ -18,11 +20,5 @@ if (! defined('KK_STAR_RATINGS')) {
|
|
18 |
|
19 |
function style(bool $isDebugMode = false): void
|
20 |
{
|
21 |
-
|
22 |
-
kksr('slug'),
|
23 |
-
kksr('core.url').'public/css/kk-star-ratings'
|
24 |
-
.($isDebugMode ? '' : '.min').'.css',
|
25 |
-
[],
|
26 |
-
kksr('version')
|
27 |
-
);
|
28 |
}
|
11 |
|
12 |
namespace Bhittani\StarRating\core\actions;
|
13 |
|
14 |
+
use function Bhittani\StarRating\core\functions\styles\main;
|
15 |
+
|
16 |
if (! defined('KK_STAR_RATINGS')) {
|
17 |
http_response_code(404);
|
18 |
exit();
|
20 |
|
21 |
function style(bool $isDebugMode = false): void
|
22 |
{
|
23 |
+
main($isDebugMode);
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
}
|
src/core/filters/blocks.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Bhittani\StarRating\core\filters;
|
13 |
+
|
14 |
+
if (! defined('KK_STAR_RATINGS')) {
|
15 |
+
http_response_code(404);
|
16 |
+
exit();
|
17 |
+
}
|
18 |
+
|
19 |
+
function blocks(array $blocks): array
|
20 |
+
{
|
21 |
+
return $blocks + kksr('core.blocks', []);
|
22 |
+
}
|
src/core/filters/embed.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Bhittani\StarRating\core\filters;
|
13 |
+
|
14 |
+
if (! defined('KK_STAR_RATINGS')) {
|
15 |
+
http_response_code(404);
|
16 |
+
exit();
|
17 |
+
}
|
18 |
+
|
19 |
+
/** Whether to auto-embed the star ratings in a post. */
|
20 |
+
function embed(?bool $bool, string $content): bool
|
21 |
+
{
|
22 |
+
if (! is_null($bool)) {
|
23 |
+
return $bool;
|
24 |
+
}
|
25 |
+
|
26 |
+
foreach ([
|
27 |
+
kksr('slug'),
|
28 |
+
// Legacy...
|
29 |
+
'kkratings', // < v3
|
30 |
+
'kkstarratings', // v3, v4
|
31 |
+
] as $tag) {
|
32 |
+
if (has_shortcode($content, $tag)) {
|
33 |
+
return false;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
return true;
|
38 |
+
}
|
src/core/filters/payload.php
CHANGED
@@ -12,6 +12,7 @@
|
|
12 |
namespace Bhittani\StarRating\core\filters;
|
13 |
|
14 |
use function Bhittani\StarRating\core\functions\calculate;
|
|
|
15 |
use function Bhittani\StarRating\core\functions\width;
|
16 |
|
17 |
if (! defined('KK_STAR_RATINGS')) {
|
@@ -21,16 +22,29 @@ if (! defined('KK_STAR_RATINGS')) {
|
|
21 |
|
22 |
function payload(array $payload): array
|
23 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
[$count, $score] = calculate($payload['id'], $payload['slug'], $payload['best']);
|
25 |
|
26 |
-
if (! (is_numeric($payload['count']) || $payload['count'])) {
|
27 |
$payload['count'] = $count;
|
28 |
}
|
29 |
|
30 |
-
if (! (is_numeric($payload['score']) || $payload['score'])) {
|
31 |
$payload['score'] = $score;
|
32 |
}
|
33 |
|
|
|
|
|
|
|
34 |
$payload['width'] = width($payload['score'], $payload['size'], $payload['gap']);
|
35 |
|
36 |
return $payload;
|
12 |
namespace Bhittani\StarRating\core\filters;
|
13 |
|
14 |
use function Bhittani\StarRating\core\functions\calculate;
|
15 |
+
use function Bhittani\StarRating\core\functions\option;
|
16 |
use function Bhittani\StarRating\core\functions\width;
|
17 |
|
18 |
if (! defined('KK_STAR_RATINGS')) {
|
22 |
|
23 |
function payload(array $payload): array
|
24 |
{
|
25 |
+
$payload['id'] = (int) ($payload['id'] ?? get_post_field('ID'));
|
26 |
+
|
27 |
+
if (! $payload['id']) {
|
28 |
+
$url = home_url(add_query_arg([]));
|
29 |
+
$payload['id'] = url_to_postid($url);
|
30 |
+
}
|
31 |
+
|
32 |
+
$payload['slug'] = $payload['slug'] ?? 'default';
|
33 |
+
$payload['best'] = $payload['best'] ?? option('stars');
|
34 |
+
|
35 |
[$count, $score] = calculate($payload['id'], $payload['slug'], $payload['best']);
|
36 |
|
37 |
+
if (! isset($payload['count']) || ! (is_numeric($payload['count']) || $payload['count'])) {
|
38 |
$payload['count'] = $count;
|
39 |
}
|
40 |
|
41 |
+
if (! isset($payload['score']) || ! (is_numeric($payload['score']) || $payload['score'])) {
|
42 |
$payload['score'] = $score;
|
43 |
}
|
44 |
|
45 |
+
$payload['size'] = $payload['size'] ?? option('size');
|
46 |
+
$payload['gap'] = $payload['gap'] ?? option('gap');
|
47 |
+
|
48 |
$payload['width'] = width($payload['score'], $payload['size'], $payload['gap']);
|
49 |
|
50 |
return $payload;
|
src/core/functions/data.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Bhittani\StarRating\core\functions;
|
13 |
+
|
14 |
+
if (! defined('KK_STAR_RATINGS')) {
|
15 |
+
http_response_code(404);
|
16 |
+
exit();
|
17 |
+
}
|
18 |
+
|
19 |
+
function data(array $payload = []): array
|
20 |
+
{
|
21 |
+
$payload['title'] = esc_html($payload['title'] ?? get_post_field('post_title'));
|
22 |
+
|
23 |
+
return filter('payload', $payload);
|
24 |
+
}
|
src/core/functions/ld_json.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Bhittani\StarRating\core\functions;
|
13 |
+
|
14 |
+
use function Bhittani\StarRating\functions\bind;
|
15 |
+
|
16 |
+
if (! defined('KK_STAR_RATINGS')) {
|
17 |
+
http_response_code(404);
|
18 |
+
exit();
|
19 |
+
}
|
20 |
+
|
21 |
+
function ld_json(array $payload = [], string $json = null): string
|
22 |
+
{
|
23 |
+
$sd = bind($json ?: option('sd'), data($payload));
|
24 |
+
|
25 |
+
return '<script type="application/ld+json">'.trim($sd).'</script>';
|
26 |
+
}
|
src/core/functions/scripts/index.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
if (! defined('KK_STAR_RATINGS')) {
|
13 |
+
http_response_code(404);
|
14 |
+
exit();
|
15 |
+
}
|
src/core/functions/scripts/main.php
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Bhittani\StarRating\core\functions\scripts;
|
13 |
+
|
14 |
+
if (! defined('KK_STAR_RATINGS')) {
|
15 |
+
http_response_code(404);
|
16 |
+
exit();
|
17 |
+
}
|
18 |
+
|
19 |
+
function main(bool $isDebugMode = false): void
|
20 |
+
{
|
21 |
+
wp_enqueue_script(
|
22 |
+
kksr('slug'),
|
23 |
+
kksr('core.url').'public/js/kk-star-ratings'
|
24 |
+
.($isDebugMode ? '' : '.min').'.js',
|
25 |
+
['jquery'],
|
26 |
+
kksr('version'),
|
27 |
+
true
|
28 |
+
);
|
29 |
+
|
30 |
+
wp_localize_script(
|
31 |
+
kksr('slug'),
|
32 |
+
str_replace('-', '_', kksr('slug')),
|
33 |
+
[
|
34 |
+
'action' => kksr('slug'),
|
35 |
+
'endpoint' => admin_url('admin-ajax.php'),
|
36 |
+
'nonce' => wp_create_nonce(kksr('core.wp.actions.wp_ajax_'.kksr('slug'))),
|
37 |
+
]
|
38 |
+
);
|
39 |
+
}
|
src/core/functions/styles/index.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
if (! defined('KK_STAR_RATINGS')) {
|
13 |
+
http_response_code(404);
|
14 |
+
exit();
|
15 |
+
}
|
src/core/functions/styles/main.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Bhittani\StarRating\core\functions\styles;
|
13 |
+
|
14 |
+
if (! defined('KK_STAR_RATINGS')) {
|
15 |
+
http_response_code(404);
|
16 |
+
exit();
|
17 |
+
}
|
18 |
+
|
19 |
+
function main(bool $isDebugMode = false): void
|
20 |
+
{
|
21 |
+
wp_enqueue_style(
|
22 |
+
kksr('slug'),
|
23 |
+
kksr('core.url').'public/css/kk-star-ratings'
|
24 |
+
.($isDebugMode ? '' : '.min').'.css',
|
25 |
+
[],
|
26 |
+
kksr('version')
|
27 |
+
);
|
28 |
+
}
|
src/core/functions/width.php
CHANGED
@@ -16,8 +16,11 @@ if (! defined('KK_STAR_RATINGS')) {
|
|
16 |
exit();
|
17 |
}
|
18 |
|
19 |
-
/** Calculate the width, providing a gap */
|
20 |
-
function width(float $score, float $size, float $gap =
|
21 |
{
|
|
|
|
|
|
|
22 |
return max(0, $score * $size + $score * $gap - $gap / 2);
|
23 |
}
|
16 |
exit();
|
17 |
}
|
18 |
|
19 |
+
/** Calculate the width, providing a size and a gap */
|
20 |
+
function width(float $score, float $size = null, float $gap = null): float
|
21 |
{
|
22 |
+
$size = $size ?? option('size');
|
23 |
+
$gap = $gap ?? option('gap');
|
24 |
+
|
25 |
return max(0, $score * $size + $score * $gap - $gap / 2);
|
26 |
}
|
src/core/index.php
CHANGED
@@ -19,9 +19,21 @@ kksr(['core' => require __DIR__.'/config.php']);
|
|
19 |
require_once __DIR__.'/hooks.php';
|
20 |
require_once __DIR__.'/hydrate.php';
|
21 |
|
|
|
|
|
|
|
|
|
22 |
register_deactivation_hook(KK_STAR_RATINGS, kksr('core.wp.functions.deactivate'));
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
27 |
// register_activation_hook(KK_STAR_RATINGS, kksr('core.wp.functions.activate'));
|
|
|
|
|
|
|
|
|
|
|
|
19 |
require_once __DIR__.'/hooks.php';
|
20 |
require_once __DIR__.'/hydrate.php';
|
21 |
|
22 |
+
/* ===============================================================
|
23 |
+
We hook a deactivation here instead of hydrating so that we may
|
24 |
+
allow the plugin files to be residing under a different name.
|
25 |
+
=============================================================== */
|
26 |
register_deactivation_hook(KK_STAR_RATINGS, kksr('core.wp.functions.deactivate'));
|
27 |
|
28 |
+
/* ==============================================================
|
29 |
+
We aren't using `register_activation_hook` because it is buggy
|
30 |
+
and does not get called when the plugin is implictly updated.
|
31 |
+
The activation will be handled when the plugin is loaded.
|
32 |
+
============================================================== */
|
33 |
// register_activation_hook(KK_STAR_RATINGS, kksr('core.wp.functions.activate'));
|
34 |
+
|
35 |
+
/* ==================================================
|
36 |
+
We need a higher priority for `the_content` filter
|
37 |
+
so that we can check for shortcodes and blocks.
|
38 |
+
================================================== */
|
39 |
+
add_filter('the_content', kksr('core.wp.functions.the_content'), 8);
|
src/core/wp/actions/admin_enqueue_scripts.php
CHANGED
@@ -20,10 +20,8 @@ if (! defined('KK_STAR_RATINGS')) {
|
|
20 |
|
21 |
function admin_enqueue_scripts($hook): void
|
22 |
{
|
23 |
-
|
24 |
-
$isDebugMode = defined('WP_DEBUG') && WP_DEBUG;
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
}
|
29 |
}
|
20 |
|
21 |
function admin_enqueue_scripts($hook): void
|
22 |
{
|
23 |
+
$isDebugMode = defined('WP_DEBUG') && WP_DEBUG;
|
|
|
24 |
|
25 |
+
action('admin/style', $hook, $isDebugMode);
|
26 |
+
action('admin/script', $hook, $isDebugMode);
|
|
|
27 |
}
|
src/core/wp/actions/init.php
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Bhittani\StarRating\core\wp\actions;
|
13 |
+
|
14 |
+
use function Bhittani\StarRating\core\functions\filter;
|
15 |
+
use function Bhittani\StarRating\functions\block;
|
16 |
+
|
17 |
+
if (! defined('KK_STAR_RATINGS')) {
|
18 |
+
http_response_code(404);
|
19 |
+
exit();
|
20 |
+
}
|
21 |
+
|
22 |
+
function init(): void
|
23 |
+
{
|
24 |
+
foreach (filter('blocks', []) as $namespace => $payload) {
|
25 |
+
block($namespace, $payload);
|
26 |
+
}
|
27 |
+
}
|
src/core/wp/actions/wp_head.php
CHANGED
@@ -12,7 +12,7 @@
|
|
12 |
namespace Bhittani\StarRating\core\wp\actions;
|
13 |
|
14 |
use function Bhittani\StarRating\core\functions\action;
|
15 |
-
use function Bhittani\StarRating\core\functions\
|
16 |
use function Bhittani\StarRating\core\functions\option;
|
17 |
|
18 |
if (! defined('KK_STAR_RATINGS')) {
|
@@ -23,14 +23,11 @@ if (! defined('KK_STAR_RATINGS')) {
|
|
23 |
function wp_head(): void
|
24 |
{
|
25 |
if (option('enable') && option('grs') && is_singular()) {
|
26 |
-
$
|
27 |
-
$id = get_post_field('ID');
|
28 |
-
$title = esc_html(get_post_field('post_title'));
|
29 |
-
[$count, $score] = calculate($id, 'default', $best);
|
30 |
|
31 |
-
if ($count && $score) {
|
32 |
ob_start();
|
33 |
-
action('sd',
|
34 |
echo ob_get_clean();
|
35 |
}
|
36 |
}
|
12 |
namespace Bhittani\StarRating\core\wp\actions;
|
13 |
|
14 |
use function Bhittani\StarRating\core\functions\action;
|
15 |
+
use function Bhittani\StarRating\core\functions\data;
|
16 |
use function Bhittani\StarRating\core\functions\option;
|
17 |
|
18 |
if (! defined('KK_STAR_RATINGS')) {
|
23 |
function wp_head(): void
|
24 |
{
|
25 |
if (option('enable') && option('grs') && is_singular()) {
|
26 |
+
$payload = data();
|
|
|
|
|
|
|
27 |
|
28 |
+
if ($payload['count'] && $payload['score']) {
|
29 |
ob_start();
|
30 |
+
action('sd', $payload);
|
31 |
echo ob_get_clean();
|
32 |
}
|
33 |
}
|
src/core/wp/{filters → functions}/the_content.php
RENAMED
@@ -9,8 +9,9 @@
|
|
9 |
* the LICENSE file that was distributed with this source code.
|
10 |
*/
|
11 |
|
12 |
-
namespace Bhittani\StarRating\core\wp\
|
13 |
|
|
|
14 |
use function Bhittani\StarRating\core\functions\option;
|
15 |
use function Bhittani\StarRating\functions\to_shortcode;
|
16 |
|
@@ -21,15 +22,8 @@ if (! defined('KK_STAR_RATINGS')) {
|
|
21 |
|
22 |
function the_content(string $content): string
|
23 |
{
|
24 |
-
|
25 |
-
|
26 |
-
// Legacy...
|
27 |
-
'kkratings', // < v3
|
28 |
-
'kkstarratings', // v3, v4
|
29 |
-
] as $tag) {
|
30 |
-
if (has_shortcode($content, $tag)) {
|
31 |
-
return $content;
|
32 |
-
}
|
33 |
}
|
34 |
|
35 |
$align = 'left';
|
9 |
* the LICENSE file that was distributed with this source code.
|
10 |
*/
|
11 |
|
12 |
+
namespace Bhittani\StarRating\core\wp\functions;
|
13 |
|
14 |
+
use function Bhittani\StarRating\core\functions\filter;
|
15 |
use function Bhittani\StarRating\core\functions\option;
|
16 |
use function Bhittani\StarRating\functions\to_shortcode;
|
17 |
|
22 |
|
23 |
function the_content(string $content): string
|
24 |
{
|
25 |
+
if (! filter('embed', null, $content)) {
|
26 |
+
return $content;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
}
|
28 |
|
29 |
$align = 'left';
|
src/functions/autoload_blocks.php
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Bhittani\StarRating\functions;
|
13 |
+
|
14 |
+
if (! defined('KK_STAR_RATINGS')) {
|
15 |
+
http_response_code(404);
|
16 |
+
exit();
|
17 |
+
}
|
18 |
+
|
19 |
+
use DirectoryIterator;
|
20 |
+
|
21 |
+
function autoload_blocks(string $namespace, string $path, string $slug = null): array
|
22 |
+
{
|
23 |
+
$path = rtrim($path, '\/');
|
24 |
+
$namespace = rtrim($namespace, '\\');
|
25 |
+
|
26 |
+
if (! is_dir($path)) {
|
27 |
+
return [];
|
28 |
+
}
|
29 |
+
|
30 |
+
if (is_null($slug)) {
|
31 |
+
$slug = kksr('slug');
|
32 |
+
}
|
33 |
+
|
34 |
+
$isDebugMode = defined('WP_DEBUG') && WP_DEBUG;
|
35 |
+
|
36 |
+
$autoloads = [];
|
37 |
+
|
38 |
+
foreach (new DirectoryIterator($path) as $fileInfo) {
|
39 |
+
if (! ($fileInfo->isDot()
|
40 |
+
|| $fileInfo->isFile()
|
41 |
+
)) {
|
42 |
+
$name = $fileInfo->getFilename();
|
43 |
+
$path = $fileInfo->getRealPath();
|
44 |
+
$ns = $namespace.'\\'.$name;
|
45 |
+
$signature = $slug.'/'.$name;
|
46 |
+
|
47 |
+
$functions = autoload($ns, $path);
|
48 |
+
|
49 |
+
$attributes = [];
|
50 |
+
|
51 |
+
if ($attributes = ($functions['attributes'] ?? [])) {
|
52 |
+
unset($functions['attributes']);
|
53 |
+
$attributes = $attributes();
|
54 |
+
}
|
55 |
+
|
56 |
+
$dependencies = [];
|
57 |
+
|
58 |
+
if ($dependencies = ($functions['dependencies'] ?? [])) {
|
59 |
+
unset($functions['dependencies']);
|
60 |
+
$dependencies = $dependencies();
|
61 |
+
}
|
62 |
+
|
63 |
+
$dist = $path.'/dist/block'.($isDebugMode ? '.es5' : '.min');
|
64 |
+
|
65 |
+
$assetFile = $dist.'.asset.php';
|
66 |
+
$options = is_file($assetFile) ? ((array) require $assetFile) : [];
|
67 |
+
|
68 |
+
$autoloads[$signature] = $functions + [
|
69 |
+
// 'namespace' => $signature,
|
70 |
+
'script' => url($dist.'.js'),
|
71 |
+
'version' => $options['version'] ?? kksr('version'),
|
72 |
+
'attributes' => $attributes,
|
73 |
+
'dependencies' => array_merge($options['dependencies'] ?? [], $dependencies),
|
74 |
+
];
|
75 |
+
}
|
76 |
+
}
|
77 |
+
|
78 |
+
return $autoloads;
|
79 |
+
}
|
src/functions/bind.php
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Bhittani\StarRating\functions;
|
13 |
+
|
14 |
+
if (! defined('KK_STAR_RATINGS')) {
|
15 |
+
http_response_code(404);
|
16 |
+
exit();
|
17 |
+
}
|
18 |
+
|
19 |
+
/** Bind values based on provided key value pairs. */
|
20 |
+
function bind(string $subject, array $payload): string
|
21 |
+
{
|
22 |
+
foreach ($payload as $key => $value) {
|
23 |
+
$subject = str_replace('{'.$key.'}', $value, $subject);
|
24 |
+
}
|
25 |
+
|
26 |
+
return $subject;
|
27 |
+
}
|
src/functions/block.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Bhittani\StarRating\functions;
|
13 |
+
|
14 |
+
if (! defined('KK_STAR_RATINGS')) {
|
15 |
+
http_response_code(404);
|
16 |
+
exit();
|
17 |
+
}
|
18 |
+
|
19 |
+
function block(string $namespace, array $payload): void
|
20 |
+
{
|
21 |
+
$slug = 'block-'.$namespace;
|
22 |
+
|
23 |
+
wp_register_script(
|
24 |
+
$slug,
|
25 |
+
$payload['script'],
|
26 |
+
$payload['dependencies'] ?? [],
|
27 |
+
$payload['version'] ?? kksr('version')
|
28 |
+
);
|
29 |
+
|
30 |
+
register_block_type($namespace, array_filter([
|
31 |
+
'api_version' => 2,
|
32 |
+
'attributes' => $payload['attributes'] ?? [],
|
33 |
+
'editor_script' => $slug,
|
34 |
+
'render_callback' => $payload['block'] ?? null,
|
35 |
+
]));
|
36 |
+
}
|
src/functions/prefix.php
CHANGED
@@ -34,9 +34,9 @@ function prefix($strOrPayload, string $prefix)
|
|
34 |
|
35 |
$str = $strOrPayload;
|
36 |
|
37 |
-
if (strpos($str, $prefix)
|
38 |
-
return $
|
39 |
}
|
40 |
|
41 |
-
return
|
42 |
}
|
34 |
|
35 |
$str = $strOrPayload;
|
36 |
|
37 |
+
if (strpos($str, $prefix) === 0) {
|
38 |
+
return $str;
|
39 |
}
|
40 |
|
41 |
+
return $prefix.$str;
|
42 |
}
|
src/functions/relative.php
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Bhittani\StarRating\functions;
|
13 |
+
|
14 |
+
if (! defined('KK_STAR_RATINGS')) {
|
15 |
+
http_response_code(404);
|
16 |
+
exit();
|
17 |
+
}
|
18 |
+
|
19 |
+
function relative(string $path): string
|
20 |
+
{
|
21 |
+
$path = str_replace('\\', '/', $path);
|
22 |
+
$prefix = str_replace('\\', '/', kksr('path'));
|
23 |
+
|
24 |
+
return strip_prefix($path, $prefix);
|
25 |
+
}
|
src/functions/url.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of bhittani/kk-star-ratings.
|
5 |
+
*
|
6 |
+
* (c) Kamal Khan <shout@bhittani.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view
|
9 |
+
* the LICENSE file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Bhittani\StarRating\functions;
|
13 |
+
|
14 |
+
if (! defined('KK_STAR_RATINGS')) {
|
15 |
+
http_response_code(404);
|
16 |
+
exit();
|
17 |
+
}
|
18 |
+
|
19 |
+
function url(string $path): string
|
20 |
+
{
|
21 |
+
return rtrim(kksr('url'), '/').'/'.relative($path);
|
22 |
+
}
|