Version Description
2020-03-07 =
+ Added hook filters lwptoc_heading_html
and lwptoc_heading_label
.
* Fixed: in some cases don't register JS/CSS files.
* Minor fixes for compatibility with future versions of WordPress.
Download this release
Release Info
Developer | theluckywp |
Plugin | LuckyWP Table of Contents |
Version | 2.0.9 |
Comparing to | |
See all releases |
Code changes from version 2.0.8 to 2.0.9
- front/Front.php +8 -2
- luckywp-table-of-contents.php +2 -2
- plugin/contentHandling/ContentHandling.php +19 -4
- plugin/dom/Dom.php +13 -9
- plugin/editorBlock/EditorBlock.php +7 -1
- plugin/editorBlock/editorBlock.min.js +1 -1
- readme.txt +7 -2
front/Front.php
CHANGED
@@ -28,10 +28,15 @@ class Front extends BaseFront
|
|
28 |
}
|
29 |
}
|
30 |
|
|
|
|
|
31 |
public function registerAssets()
|
32 |
{
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
35 |
}
|
36 |
|
37 |
private $_assetsEnqueued = false;
|
@@ -39,6 +44,7 @@ class Front extends BaseFront
|
|
39 |
public function enqueueAssets()
|
40 |
{
|
41 |
if (!$this->_assetsEnqueued) {
|
|
|
42 |
if (apply_filters('lwptoc_enqueue_style', true)) {
|
43 |
wp_enqueue_style('lwptoc-main');
|
44 |
}
|
28 |
}
|
29 |
}
|
30 |
|
31 |
+
private $_assetsRegistred = false;
|
32 |
+
|
33 |
public function registerAssets()
|
34 |
{
|
35 |
+
if (!$this->_assetsRegistred) {
|
36 |
+
wp_register_style('lwptoc-main', Core::$plugin->url . '/front/assets/main.min.css', [], Core::$plugin->version);
|
37 |
+
wp_register_script('lwptoc-main', Core::$plugin->url . '/front/assets/main.min.js', [], Core::$plugin->version);
|
38 |
+
$this->_assetsRegistred = true;
|
39 |
+
}
|
40 |
}
|
41 |
|
42 |
private $_assetsEnqueued = false;
|
44 |
public function enqueueAssets()
|
45 |
{
|
46 |
if (!$this->_assetsEnqueued) {
|
47 |
+
$this->registerAssets();
|
48 |
if (apply_filters('lwptoc_enqueue_style', true)) {
|
49 |
wp_enqueue_style('lwptoc-main');
|
50 |
}
|
luckywp-table-of-contents.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: LuckyWP Table of Contents
|
4 |
Plugin URI: https://theluckywp.com/product/table-of-contents/
|
5 |
Description: Creates a table of contents for your posts/pages. Works automatically or manually (via shortcode, Gutenberg block or widget).
|
6 |
-
Version: 2.0.
|
7 |
Author: LuckyWP
|
8 |
Author URI: https://theluckywp.com/
|
9 |
Text Domain: luckywp-table-of-contents
|
@@ -47,6 +47,6 @@ $lwptocAutoloader->register();
|
|
47 |
$lwptocAutoloader->addNamespace('luckywp\tableOfContents', __DIR__);
|
48 |
|
49 |
$config = require(__DIR__ . '/config/plugin.php');
|
50 |
-
(new \luckywp\tableOfContents\plugin\Plugin($config))->run('2.0.
|
51 |
|
52 |
require_once __DIR__ . '/functions.php';
|
3 |
Plugin Name: LuckyWP Table of Contents
|
4 |
Plugin URI: https://theluckywp.com/product/table-of-contents/
|
5 |
Description: Creates a table of contents for your posts/pages. Works automatically or manually (via shortcode, Gutenberg block or widget).
|
6 |
+
Version: 2.0.9
|
7 |
Author: LuckyWP
|
8 |
Author URI: https://theluckywp.com/
|
9 |
Text Domain: luckywp-table-of-contents
|
47 |
$lwptocAutoloader->addNamespace('luckywp\tableOfContents', __DIR__);
|
48 |
|
49 |
$config = require(__DIR__ . '/config/plugin.php');
|
50 |
+
(new \luckywp\tableOfContents\plugin\Plugin($config))->run('2.0.9', __FILE__, 'lwptoc_');
|
51 |
|
52 |
require_once __DIR__ . '/functions.php';
|
plugin/contentHandling/ContentHandling.php
CHANGED
@@ -35,10 +35,7 @@ class ContentHandling
|
|
35 |
foreach ($headingNodes as $node) {
|
36 |
/** @var $node \DOMElement */
|
37 |
|
38 |
-
$label =
|
39 |
-
$label = html_entity_decode($label, ENT_HTML5, 'UTF-8');
|
40 |
-
$label = preg_replace('/\s+/u', ' ', $label);
|
41 |
-
$label = trim($label);
|
42 |
if ($label == '') {
|
43 |
continue;
|
44 |
}
|
@@ -74,6 +71,24 @@ class ContentHandling
|
|
74 |
return $result;
|
75 |
}
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
/**
|
78 |
* @var int
|
79 |
*/
|
35 |
foreach ($headingNodes as $node) {
|
36 |
/** @var $node \DOMElement */
|
37 |
|
38 |
+
$label = static::makeLabel($node);
|
|
|
|
|
|
|
39 |
if ($label == '') {
|
40 |
continue;
|
41 |
}
|
71 |
return $result;
|
72 |
}
|
73 |
|
74 |
+
/**
|
75 |
+
* @param \DOMElement $node
|
76 |
+
* @return string
|
77 |
+
*/
|
78 |
+
protected static function makeLabel($node)
|
79 |
+
{
|
80 |
+
$html = Dom::getInnerHtml($node);
|
81 |
+
$html = apply_filters('lwptoc_heading_html', $html);
|
82 |
+
|
83 |
+
$label = strip_tags($html);
|
84 |
+
$label = html_entity_decode($label, ENT_HTML5, 'UTF-8');
|
85 |
+
$label = apply_filters('lwptoc_heading_label', $label, $html);
|
86 |
+
|
87 |
+
$label = preg_replace('/\s+/u', ' ', $label);
|
88 |
+
$label = trim($label);
|
89 |
+
return $label;
|
90 |
+
}
|
91 |
+
|
92 |
/**
|
93 |
* @var int
|
94 |
*/
|
plugin/dom/Dom.php
CHANGED
@@ -37,6 +37,19 @@ class Dom
|
|
37 |
return static::prepareHtmlOut($content);
|
38 |
}
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
/**
|
41 |
* @param \DOMNode $node
|
42 |
* @param string $shortcode
|
@@ -70,15 +83,6 @@ class Dom
|
|
70 |
}
|
71 |
}
|
72 |
|
73 |
-
/**
|
74 |
-
* @param \DOMElement $node
|
75 |
-
* @return string
|
76 |
-
*/
|
77 |
-
public static function getNodeValue($node)
|
78 |
-
{
|
79 |
-
return static::prepareHtmlOut($node->nodeValue);
|
80 |
-
}
|
81 |
-
|
82 |
/**
|
83 |
* @param string $content
|
84 |
* @return string
|
37 |
return static::prepareHtmlOut($content);
|
38 |
}
|
39 |
|
40 |
+
/**
|
41 |
+
* @param \DOMNode $node
|
42 |
+
* @return string
|
43 |
+
*/
|
44 |
+
public static function getInnerHtml($node)
|
45 |
+
{
|
46 |
+
$html = '';
|
47 |
+
foreach ($node->childNodes as $child) {
|
48 |
+
$html .= $node->ownerDocument->saveHTML($child);
|
49 |
+
}
|
50 |
+
return static::prepareHtmlOut($html);
|
51 |
+
}
|
52 |
+
|
53 |
/**
|
54 |
* @param \DOMNode $node
|
55 |
* @param string $shortcode
|
83 |
}
|
84 |
}
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
/**
|
87 |
* @param string $content
|
88 |
* @return string
|
plugin/editorBlock/EditorBlock.php
CHANGED
@@ -17,7 +17,13 @@ class EditorBlock extends BaseObject
|
|
17 |
|
18 |
public function wpInit()
|
19 |
{
|
20 |
-
wp_register_script('lwptoc-editorBlock', $this->getUrl() . '/editorBlock.min.js', [
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
register_block_type('luckywp/tableofcontents', [
|
22 |
'editor_script' => 'lwptoc-editorBlock',
|
23 |
'render_callback' => function ($attrs) {
|
17 |
|
18 |
public function wpInit()
|
19 |
{
|
20 |
+
wp_register_script('lwptoc-editorBlock', $this->getUrl() . '/editorBlock.min.js', [
|
21 |
+
'wp-blocks',
|
22 |
+
'wp-element',
|
23 |
+
wp_script_is('wp-block-editor') ? 'wp-block-editor' : 'wp-editor',
|
24 |
+
'wp-components',
|
25 |
+
'lwptoc_adminMain'
|
26 |
+
], Core::$plugin->version);
|
27 |
register_block_type('luckywp/tableofcontents', [
|
28 |
'editor_script' => 'lwptoc-editorBlock',
|
29 |
'render_callback' => function ($attrs) {
|
plugin/editorBlock/editorBlock.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
!function(t){var e={};function o(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=1)}([function(t,e){function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(e){return"function"==typeof Symbol&&"symbol"===o(Symbol.iterator)?t.exports=n=function(t){return o(t)}:t.exports=n=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":o(t)},n(e)}t.exports=n},function(t,e,o){"use strict";o.r(e);var n=o(0),r=o.n(n),i=wp.blocks.registerBlockType,l=wp.element,c=l.createElement,u=l.Fragment,p=wp.editor.BlockControls,s=wp.components,a=s.Toolbar,y=s.IconButton,f=0,d={};i("luckywp/tableofcontents",{title:lwptocMain.tableOfContents,icon:"list-view",category:"common",supports:{customClassName:!1,html:!1},attributes:{min:{type:"integer"},depth:{type:"integer"},hierarchical:{type:"boolean"},numeration:{type:"string"},numerationSuffix:{type:"string"},title:{type:"string"},toggle:{type:"boolean"},labelShow:{type:"string"},labelHide:{type:"string"},hideItems:{type:"boolean"},smoothScroll:{type:"boolean"},smoothScrollOffset:{type:"integer"},width:{type:"string"},float:{type:"string"},titleFontSize:{type:"string"},titleFontWeight:{type:"string"},itemsFontSize:{type:"string"},colorScheme:{type:"string"},backgroundColor:{type:"string"},borderColor:{type:"string"},titleColor:{type:"string"},linkColor:{type:"string"},hoverLinkColor:{type:"string"},visitedLinkColor:{type:"string"},wrapNoindex:{type:"boolean"},useNofollow:{type:"boolean"},skipHeadingLevel:{type:"string"},skipHeadingText:{type:"string"}},edit:function(t){var e=t.attributes,o=t.setAttributes,n={};jQuery.each(e,function(t,e){r()(e)==r()(!0)&&(e=e?1:0),n[t]=e});var i="lwptocEditorBlock"+ ++f,l=JSON.stringify(e);return void 0===d[l]&&(jQuery.ajax({url:lwptocMain.ajaxUrl,data:{_ajax_nonce:lwptocMain.nonce,action:"lwptoc_block_view",attrs:n},success:function(t){d[l]=t,jQuery("#"+i).replaceWith(t)}}),d[l]='<div class="lwptocEditorBlock_title lwptocEditorBlock_title-loading" id="'+i+'">'+lwptocMain.tableOfContents+"</div>"),c(u,null,c(p,null,c(a,null,c(y,{label:lwptocMain.Edit,icon:"edit",onClick:function(){jQuery(document).one("lwptocEditorBlockChanged",function(t,e){_.each(e,function(t,o){null===t&&(e[o]=void 0)}),o(e)}),jQuery.lwptocCustomize.show({action:"lwptoc_block_edit",attrs:n,postId:lwptocMain.postId},function(){jQuery(document).off("lwptocEditorBlockChanged")})}}))),c("div",{class:"lwptocEditorBlock",dangerouslySetInnerHTML:{__html:d[l]}}))},save:function(t){return t.attributes.shortcode}})}]);
|
1 |
+
!function(t){var e={};function o(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=1)}([function(t,e){function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(e){return"function"==typeof Symbol&&"symbol"===o(Symbol.iterator)?t.exports=n=function(t){return o(t)}:t.exports=n=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":o(t)},n(e)}t.exports=n},function(t,e,o){"use strict";o.r(e);var n=o(0),r=o.n(n),i=wp.blocks.registerBlockType,l=wp.element,c=l.createElement,u=l.Fragment,p=(wp.blockEditor||wp.editor).BlockControls,s=wp.components,a=s.Toolbar,y=s.IconButton,f=0,d={};i("luckywp/tableofcontents",{title:lwptocMain.tableOfContents,icon:"list-view",category:"common",supports:{customClassName:!1,html:!1},attributes:{min:{type:"integer"},depth:{type:"integer"},hierarchical:{type:"boolean"},numeration:{type:"string"},numerationSuffix:{type:"string"},title:{type:"string"},toggle:{type:"boolean"},labelShow:{type:"string"},labelHide:{type:"string"},hideItems:{type:"boolean"},smoothScroll:{type:"boolean"},smoothScrollOffset:{type:"integer"},width:{type:"string"},float:{type:"string"},titleFontSize:{type:"string"},titleFontWeight:{type:"string"},itemsFontSize:{type:"string"},colorScheme:{type:"string"},backgroundColor:{type:"string"},borderColor:{type:"string"},titleColor:{type:"string"},linkColor:{type:"string"},hoverLinkColor:{type:"string"},visitedLinkColor:{type:"string"},wrapNoindex:{type:"boolean"},useNofollow:{type:"boolean"},skipHeadingLevel:{type:"string"},skipHeadingText:{type:"string"}},edit:function(t){var e=t.attributes,o=t.setAttributes,n={};jQuery.each(e,(function(t,e){r()(e)==r()(!0)&&(e=e?1:0),n[t]=e}));var i="lwptocEditorBlock"+ ++f,l=JSON.stringify(e);return void 0===d[l]&&(jQuery.ajax({url:lwptocMain.ajaxUrl,data:{_ajax_nonce:lwptocMain.nonce,action:"lwptoc_block_view",attrs:n},success:function(t){d[l]=t,jQuery("#"+i).replaceWith(t)}}),d[l]='<div class="lwptocEditorBlock_title lwptocEditorBlock_title-loading" id="'+i+'">'+lwptocMain.tableOfContents+"</div>"),c(u,null,c(p,null,c(a,null,c(y,{label:lwptocMain.Edit,icon:"edit",onClick:function(){jQuery(document).one("lwptocEditorBlockChanged",(function(t,e){_.each(e,(function(t,o){null===t&&(e[o]=void 0)})),o(e)})),jQuery.lwptocCustomize.show({action:"lwptoc_block_edit",attrs:n,postId:lwptocMain.postId},(function(){jQuery(document).off("lwptocEditorBlockChanged")}))}}))),c("div",{class:"lwptocEditorBlock",dangerouslySetInnerHTML:{__html:d[l]}}))},save:function(t){return t.attributes.shortcode}})}]);
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: theluckywp
|
|
3 |
Donate link: https://theluckywp.com/product/table-of-contents/
|
4 |
Tags: table of contents, toc, navigation, links, seo
|
5 |
Requires at least: 4.7
|
6 |
-
Tested up to: 5.
|
7 |
-
Stable tag: 2.0.
|
8 |
Requires PHP: 5.6.20
|
9 |
License: GPLv2 or later
|
10 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
@@ -159,6 +159,11 @@ For non-English websites it is recommended to enable the `Intl` PHP extension.
|
|
159 |
|
160 |
== Changelog ==
|
161 |
|
|
|
|
|
|
|
|
|
|
|
162 |
= 2.0.8 — 2020-02-23 =
|
163 |
+ Added hook filter `lwptoc_active`.
|
164 |
+ Added tab "LuckyWP Plugins" to settings.
|
3 |
Donate link: https://theluckywp.com/product/table-of-contents/
|
4 |
Tags: table of contents, toc, navigation, links, seo
|
5 |
Requires at least: 4.7
|
6 |
+
Tested up to: 5.4
|
7 |
+
Stable tag: 2.0.9
|
8 |
Requires PHP: 5.6.20
|
9 |
License: GPLv2 or later
|
10 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
159 |
|
160 |
== Changelog ==
|
161 |
|
162 |
+
= 2.0.9 — 2020-03-07 =
|
163 |
+
+ Added hook filters `lwptoc_heading_html` and `lwptoc_heading_label`.
|
164 |
+
* Fixed: in some cases don't register JS/CSS files.
|
165 |
+
* Minor fixes for compatibility with future versions of WordPress.
|
166 |
+
|
167 |
= 2.0.8 — 2020-02-23 =
|
168 |
+ Added hook filter `lwptoc_active`.
|
169 |
+ Added tab "LuckyWP Plugins" to settings.
|