Table of Contents Plus - Version 2106

Version Description

  • Released: 23 June 2021
  • Add compatibility with Rank Math SEO
  • Bump tested WordPress version to 5.7
  • Add PHP coding style
  • Adhere to majority of coding tips
Download this release

Release Info

Developer conjur3r
Plugin Icon 128x128 Table of Contents Plus
Version 2106
Comparing to
See all releases

Code changes from version 2002 to 2106

Files changed (6) hide show
  1. LICENSE.md +340 -0
  2. README.md +20 -0
  3. class-toc-plus.php +1793 -0
  4. phpcs.xml +26 -0
  5. readme.txt +9 -2
  6. toc.php +38 -1763
LICENSE.md ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ {description}
294
+ Copyright (C) {year} {fullname}
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ {signature of Ty Coon}, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
340
+
README.md ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Table of Contents Plus
2
+
3
+ A powerful yet user friendly WordPress plugin that automatically creates a context specific index or table of contents (TOC) for long pages (and custom post types). More than just a table of contents plugin, this plugin can also output a sitemap listing pages and/or categories across your entire site.
4
+
5
+ Built from the ground up and with Wikipedia in mind, the table of contents by default appears before the first heading on a page. This allows the author to insert lead-in content that may summarise or introduce the rest of the page. It also uses a unique numbering scheme that doesn't get lost through CSS differences across themes.
6
+
7
+ This plugin is a great companion for content rich sites such as content management system oriented configurations. That said, bloggers also have the same benefits when writing long structured articles. [Discover how Google](http://dublue.com/2012/05/12/another-benefit-to-structure-your-web-pages/) uses this index to provide 'Jump To' links to your content.
8
+
9
+ Includes an administration options panel where you can customise settings like display position, define the minimum number of headings before an index is displayed, other appearance, and more. For power users, expand the advanced options to further tweak its behaviour - eg: exclude undesired heading levels like h5 and h6 from being included; disable the output of the included CSS file; adjust the top offset and more. Using shortcodes, you can override default behaviour such as special exclusions on a specific page or even to hide the table of contents altogether.
10
+
11
+ Prefer to include the index in the sidebar? Go to Appearance > Widgets and drag the TOC+ to your desired sidebar and position.
12
+
13
+ Custom post types are supported, however, auto insertion works only when the_content() has been used by the custom post type. Each post type will appear in the options panel, so enable the ones you want.
14
+
15
+ Collaborate, participate, fork this plugin on [Github](https://github.com/zedzedzed/table-of-contents-plus/).
16
+
17
+ ## Links
18
+
19
+ * [WordPress plugin page](https://wordpress.org/plugins/table-of-contents-plus/)
20
+ * [Plugin homepage](http://dublue.com/plugins/toc/)
class-toc-plus.php ADDED
@@ -0,0 +1,1793 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ define( 'TOC_VERSION', '2106' );
4
+ define( 'TOC_POSITION_BEFORE_FIRST_HEADING', 1 );
5
+ define( 'TOC_POSITION_TOP', 2 );
6
+ define( 'TOC_POSITION_BOTTOM', 3 );
7
+ define( 'TOC_POSITION_AFTER_FIRST_HEADING', 4 );
8
+ define( 'TOC_MIN_START', 2 );
9
+ define( 'TOC_MAX_START', 10 );
10
+ define( 'TOC_SMOOTH_SCROLL_OFFSET', 30 );
11
+ define( 'TOC_WRAPPING_NONE', 0 );
12
+ define( 'TOC_WRAPPING_LEFT', 1 );
13
+ define( 'TOC_WRAPPING_RIGHT', 2 );
14
+ define( 'TOC_THEME_GREY', 1 );
15
+ define( 'TOC_THEME_LIGHT_BLUE', 2 );
16
+ define( 'TOC_THEME_WHITE', 3 );
17
+ define( 'TOC_THEME_BLACK', 4 );
18
+ define( 'TOC_THEME_TRANSPARENT', 99 );
19
+ define( 'TOC_THEME_CUSTOM', 100 );
20
+ define( 'TOC_DEFAULT_BACKGROUND_COLOUR', '#f9f9f9' );
21
+ define( 'TOC_DEFAULT_BORDER_COLOUR', '#aaaaaa' );
22
+ define( 'TOC_DEFAULT_TITLE_COLOUR', '#' );
23
+ define( 'TOC_DEFAULT_LINKS_COLOUR', '#' );
24
+ define( 'TOC_DEFAULT_LINKS_HOVER_COLOUR', '#' );
25
+ define( 'TOC_DEFAULT_LINKS_VISITED_COLOUR', '#' );
26
+
27
+
28
+ if ( ! class_exists( 'TOC_Plus' ) ) :
29
+ class TOC_Plus {
30
+
31
+ private $path; // eg /wp-content/plugins/toc
32
+ private $options;
33
+ private $show_toc; // allows to override the display (eg through [no_toc] shortcode)
34
+ private $exclude_post_types;
35
+ private $collision_collector; // keeps a track of used anchors for collision detecting
36
+
37
+ function __construct() {
38
+ $this->path = plugins_url( '', __FILE__ );
39
+ $this->show_toc = true;
40
+ $this->exclude_post_types = [ 'attachment', 'revision', 'nav_menu_item', 'safecss' ];
41
+ $this->collision_collector = [];
42
+
43
+ // get options
44
+ $defaults = [ // default options
45
+ 'fragment_prefix' => 'i',
46
+ 'position' => TOC_POSITION_BEFORE_FIRST_HEADING,
47
+ 'start' => 4,
48
+ 'show_heading_text' => true,
49
+ 'heading_text' => 'Contents',
50
+ 'auto_insert_post_types' => [ 'page' ],
51
+ 'show_heirarchy' => true,
52
+ 'ordered_list' => true,
53
+ 'smooth_scroll' => false,
54
+ 'smooth_scroll_offset' => TOC_SMOOTH_SCROLL_OFFSET,
55
+ 'visibility' => true,
56
+ 'visibility_show' => 'show',
57
+ 'visibility_hide' => 'hide',
58
+ 'visibility_hide_by_default' => false,
59
+ 'width' => 'Auto',
60
+ 'width_custom' => '275',
61
+ 'width_custom_units' => 'px',
62
+ 'wrapping' => TOC_WRAPPING_NONE,
63
+ 'font_size' => '95',
64
+ 'font_size_units' => '%',
65
+ 'theme' => TOC_THEME_GREY,
66
+ 'custom_background_colour' => TOC_DEFAULT_BACKGROUND_COLOUR,
67
+ 'custom_border_colour' => TOC_DEFAULT_BORDER_COLOUR,
68
+ 'custom_title_colour' => TOC_DEFAULT_TITLE_COLOUR,
69
+ 'custom_links_colour' => TOC_DEFAULT_LINKS_COLOUR,
70
+ 'custom_links_hover_colour' => TOC_DEFAULT_LINKS_HOVER_COLOUR,
71
+ 'custom_links_visited_colour' => TOC_DEFAULT_LINKS_VISITED_COLOUR,
72
+ 'lowercase' => false,
73
+ 'hyphenate' => false,
74
+ 'bullet_spacing' => false,
75
+ 'include_homepage' => false,
76
+ 'exclude_css' => false,
77
+ 'exclude' => '',
78
+ 'heading_levels' => [ '1', '2', '3', '4', '5', '6' ],
79
+ 'restrict_path' => '',
80
+ 'css_container_class' => '',
81
+ 'sitemap_show_page_listing' => true,
82
+ 'sitemap_show_category_listing' => true,
83
+ 'sitemap_heading_type' => 3,
84
+ 'sitemap_pages' => 'Pages',
85
+ 'sitemap_categories' => 'Categories',
86
+ 'show_toc_in_widget_only' => false,
87
+ 'show_toc_in_widget_only_post_types' => [ 'page' ],
88
+ ];
89
+
90
+ $options = get_option( 'toc-options', $defaults );
91
+ $this->options = wp_parse_args( $options, $defaults );
92
+
93
+ add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
94
+ add_action( 'wp_enqueue_scripts', [ $this, 'wp_enqueue_scripts' ] );
95
+ add_action( 'wp_head', [ $this, 'wp_head' ] );
96
+ add_action( 'admin_init', [ $this, 'admin_init' ] );
97
+ add_action( 'admin_menu', [ $this, 'admin_menu' ] );
98
+ add_action( 'widgets_init', [ $this, 'widgets_init' ] );
99
+ add_action( 'sidebar_admin_setup', [ $this, 'sidebar_admin_setup' ] );
100
+ add_action( 'init', [ $this, 'init' ] );
101
+
102
+ add_filter( 'the_content', [ $this, 'the_content' ], 100 ); // run after shortcodes are interpretted (level 10)
103
+ add_filter( 'plugin_action_links', [ $this, 'plugin_action_links' ], 10, 2 );
104
+ add_filter( 'widget_text', 'do_shortcode' );
105
+
106
+ add_shortcode( 'toc', [ $this, 'shortcode_toc' ] );
107
+ add_shortcode( 'no_toc', [ $this, 'shortcode_no_toc' ] );
108
+ add_shortcode( 'sitemap', [ $this, 'shortcode_sitemap' ] );
109
+ add_shortcode( 'sitemap_pages', [ $this, 'shortcode_sitemap_pages' ] );
110
+ add_shortcode( 'sitemap_categories', [ $this, 'shortcode_sitemap_categories' ] );
111
+ add_shortcode( 'sitemap_posts', [ $this, 'shortcode_sitemap_posts' ] );
112
+ }
113
+
114
+
115
+ function __destruct() {}
116
+
117
+
118
+ public function get_options() {
119
+ return $this->options;
120
+ }
121
+
122
+
123
+ public function set_option( $array ) {
124
+ $this->options = array_merge( $this->options, $array );
125
+ }
126
+
127
+
128
+ /**
129
+ * Allows the developer to disable TOC execution
130
+ */
131
+ public function disable() {
132
+ $this->show_toc = false;
133
+ }
134
+
135
+
136
+ /**
137
+ * Allows the developer to enable TOC execution
138
+ */
139
+ public function enable() {
140
+ $this->show_toc = true;
141
+ }
142
+
143
+
144
+ public function set_show_toc_in_widget_only( $value = false ) {
145
+ if ( $value ) {
146
+ $this->options['show_toc_in_widget_only'] = true;
147
+ } else {
148
+ $this->options['show_toc_in_widget_only'] = false;
149
+ }
150
+
151
+ update_option( 'toc-options', $this->options );
152
+ }
153
+
154
+
155
+ public function set_show_toc_in_widget_only_post_types( $value = false ) {
156
+ if ( $value ) {
157
+ $this->options['show_toc_in_widget_only_post_types'] = $value;
158
+ } else {
159
+ $this->options['show_toc_in_widget_only_post_types'] = [];
160
+ }
161
+
162
+ update_option( 'toc-options', $this->options );
163
+ }
164
+
165
+
166
+ public function get_exclude_post_types() {
167
+ return $this->exclude_post_types;
168
+ }
169
+
170
+
171
+ function plugin_action_links( $links, $file ) {
172
+ if ( 'table-of-contents-plus/' . basename( __FILE__ ) == $file ) {
173
+ $settings_link = '<a href="options-general.php?page=toc">' . __( 'Settings', 'table-of-contents-plus' ) . '</a>';
174
+ $links = array_merge( [ $settings_link ], $links );
175
+ }
176
+ return $links;
177
+ }
178
+
179
+
180
+ function shortcode_toc( $atts ) {
181
+ extract(
182
+ shortcode_atts(
183
+ [
184
+ 'label' => $this->options['heading_text'],
185
+ 'label_show' => $this->options['visibility_show'],
186
+ 'label_hide' => $this->options['visibility_hide'],
187
+ 'no_label' => false,
188
+ 'class' => false,
189
+ 'wrapping' => $this->options['wrapping'],
190
+ 'heading_levels' => $this->options['heading_levels'],
191
+ 'exclude' => $this->options['exclude'],
192
+ 'collapse' => false,
193
+ ],
194
+ $atts
195
+ )
196
+ );
197
+
198
+ $re_enqueue_scripts = false;
199
+
200
+ if ( $no_label ) {
201
+ $this->options['show_heading_text'] = false;
202
+ }
203
+ if ( $label ) {
204
+ $this->options['heading_text'] = html_entity_decode( $label );
205
+ }
206
+ if ( $label_show ) {
207
+ $this->options['visibility_show'] = html_entity_decode( $label_show );
208
+ $re_enqueue_scripts = true;
209
+ }
210
+ if ( $label_hide ) {
211
+ $this->options['visibility_hide'] = html_entity_decode( $label_hide );
212
+ $re_enqueue_scripts = true;
213
+ }
214
+ if ( $class ) {
215
+ $this->options['css_container_class'] = $class;
216
+ }
217
+ if ( $wrapping ) {
218
+ switch ( strtolower( trim( $wrapping ) ) ) {
219
+ case 'left':
220
+ $this->options['wrapping'] = TOC_WRAPPING_LEFT;
221
+ break;
222
+
223
+ case 'right':
224
+ $this->options['wrapping'] = TOC_WRAPPING_RIGHT;
225
+ break;
226
+
227
+ default:
228
+ // do nothing
229
+ }
230
+ }
231
+
232
+ if ( $exclude ) {
233
+ $this->options['exclude'] = $exclude;
234
+ }
235
+ if ( $collapse ) {
236
+ $this->options['visibility_hide_by_default'] = true;
237
+ $re_enqueue_scripts = true;
238
+ }
239
+
240
+ if ( $re_enqueue_scripts ) {
241
+ do_action( 'wp_enqueue_scripts' );
242
+ }
243
+
244
+ // if $heading_levels is an array, then it came from the global options
245
+ // and wasn't provided by per instance
246
+ if ( $heading_levels && ! is_array( $heading_levels ) ) {
247
+ // make sure they are numbers between 1 and 6 and put into
248
+ // the $clean_heading_levels array if not already
249
+ $clean_heading_levels = [];
250
+ foreach ( explode( ',', $heading_levels ) as $heading_level ) {
251
+ if ( is_numeric( $heading_level ) ) {
252
+ if ( 1 <= $heading_level && $heading_level <= 6 ) {
253
+ if ( ! in_array( $heading_level, $clean_heading_levels ) ) {
254
+ $clean_heading_levels[] = $heading_level;
255
+ }
256
+ }
257
+ }
258
+ }
259
+
260
+ if ( count( $clean_heading_levels ) > 0 ) {
261
+ $this->options['heading_levels'] = $clean_heading_levels;
262
+ }
263
+ }
264
+
265
+ if ( ! is_search() && ! is_archive() && ! is_feed() ) {
266
+ return '<!--TOC-->';
267
+ } else {
268
+ return;
269
+ }
270
+ }
271
+
272
+
273
+ function shortcode_no_toc( $atts ) {
274
+ $this->show_toc = false;
275
+
276
+ return;
277
+ }
278
+
279
+
280
+ function shortcode_sitemap( $atts ) {
281
+ $html = '';
282
+
283
+ // only do the following if enabled
284
+ if ( $this->options['sitemap_show_page_listing'] || $this->options['sitemap_show_category_listing'] ) {
285
+ $html = '<div class="toc_sitemap">';
286
+ if ( $this->options['sitemap_show_page_listing'] ) {
287
+ $html .=
288
+ '<h' . $this->options['sitemap_heading_type'] . ' class="toc_sitemap_pages">' . htmlentities( $this->options['sitemap_pages'], ENT_COMPAT, 'UTF-8' ) . '</h' . $this->options['sitemap_heading_type'] . '>' .
289
+ '<ul class="toc_sitemap_pages_list">' .
290
+ wp_list_pages( [ 'title_li' => '', 'echo' => false ] ) .
291
+ '</ul>';
292
+ }
293
+ if ( $this->options['sitemap_show_category_listing'] ) {
294
+ $html .=
295
+ '<h' . $this->options['sitemap_heading_type'] . ' class="toc_sitemap_categories">' . htmlentities( $this->options['sitemap_categories'], ENT_COMPAT, 'UTF-8' ) . '</h' . $this->options['sitemap_heading_type'] . '>' .
296
+ '<ul class="toc_sitemap_categories_list">' .
297
+ wp_list_categories( [ 'title_li' => '', 'echo' => false ] ) .
298
+ '</ul>';
299
+ }
300
+ $html .= '</div>';
301
+ }
302
+
303
+ return $html;
304
+ }
305
+
306
+
307
+ function shortcode_sitemap_pages( $atts ) {
308
+ extract(
309
+ shortcode_atts(
310
+ [
311
+ 'heading' => $this->options['sitemap_heading_type'],
312
+ 'label' => htmlentities( $this->options['sitemap_pages'], ENT_COMPAT, 'UTF-8' ),
313
+ 'no_label' => false,
314
+ 'exclude' => '',
315
+ 'exclude_tree' => '',
316
+ ],
317
+ $atts
318
+ )
319
+ );
320
+
321
+ if ( $heading < 1 || $heading > 6 ) { // h1 to h6 are valid
322
+ $heading = $this->options['sitemap_heading_type'];
323
+ }
324
+
325
+ $html = '<div class="toc_sitemap">';
326
+ if ( ! $no_label ) {
327
+ $html .= '<h' . $heading . ' class="toc_sitemap_pages">' . $label . '</h' . $heading . '>';
328
+ }
329
+ $html .=
330
+ '<ul class="toc_sitemap_pages_list">' .
331
+ wp_list_pages( [ 'title_li' => '', 'echo' => false, 'exclude' => $exclude, 'exclude_tree' => $exclude_tree ] ) .
332
+ '</ul>' .
333
+ '</div>';
334
+
335
+ return $html;
336
+ }
337
+
338
+
339
+ function shortcode_sitemap_categories( $atts ) {
340
+ extract(
341
+ shortcode_atts(
342
+ [
343
+ 'heading' => $this->options['sitemap_heading_type'],
344
+ 'label' => htmlentities( $this->options['sitemap_categories'], ENT_COMPAT, 'UTF-8' ),
345
+ 'no_label' => false,
346
+ 'exclude' => '',
347
+ 'exclude_tree' => '',
348
+ ],
349
+ $atts
350
+ )
351
+ );
352
+
353
+ if ( $heading < 1 || $heading > 6 ) { // h1 to h6 are valid
354
+ $heading = $this->options['sitemap_heading_type'];
355
+ }
356
+
357
+ $html = '<div class="toc_sitemap">';
358
+ if ( ! $no_label ) {
359
+ $html .= '<h' . $heading . ' class="toc_sitemap_categories">' . $label . '</h' . $heading . '>';
360
+ }
361
+ $html .=
362
+ '<ul class="toc_sitemap_categories_list">' .
363
+ wp_list_categories( [ 'title_li' => '', 'echo' => false, 'exclude' => $exclude, 'exclude_tree' => $exclude_tree ] ) .
364
+ '</ul>' .
365
+ '</div>';
366
+
367
+ return $html;
368
+ }
369
+
370
+
371
+ function shortcode_sitemap_posts( $atts ) {
372
+ extract(
373
+ shortcode_atts(
374
+ [
375
+ 'order' => 'ASC',
376
+ 'orderby' => 'title',
377
+ 'separate' => true,
378
+ ],
379
+ $atts
380
+ )
381
+ );
382
+
383
+ $articles = new WP_Query(
384
+ [
385
+ 'post_type' => 'post',
386
+ 'post_status' => 'publish',
387
+ 'order' => $order,
388
+ 'orderby' => $orderby,
389
+ 'posts_per_page' => -1,
390
+ ]
391
+ );
392
+
393
+ $html = '';
394
+ $letter = '';
395
+
396
+ $separate = strtolower( $separate );
397
+ if ( 'false' == $separate || 'no' == $separate ) {
398
+ $separate = false;
399
+ }
400
+
401
+ while ( $articles->have_posts() ) {
402
+ $articles->the_post();
403
+ $title = strip_tags( get_the_title() );
404
+
405
+ if ( $separate ) {
406
+ if ( strtolower( $title[0] ) != $letter ) {
407
+ if ( $letter ) {
408
+ $html .= '</ul></div>';
409
+ }
410
+
411
+ $html .= '<div class="toc_sitemap_posts_section"><p class="toc_sitemap_posts_letter">' . strtolower( $title[0] ) . '</p><ul class="toc_sitemap_posts_list">';
412
+ $letter = strtolower( $title[0] );
413
+ }
414
+ }
415
+
416
+ $html .= '<li><a href="' . get_permalink( $articles->post->ID ) . '">' . $title . '</a></li>';
417
+ }
418
+
419
+ if ( $html ) {
420
+ if ( $separate ) {
421
+ $html .= '</div>';
422
+ } else {
423
+ $html = '<div class="toc_sitemap_posts_section"><ul class="toc_sitemap_posts_list">' . $html . '</ul></div>';
424
+ }
425
+ }
426
+
427
+ wp_reset_postdata();
428
+
429
+ return $html;
430
+ }
431
+
432
+
433
+ /**
434
+ * Register and load CSS and javascript files for frontend.
435
+ */
436
+ function wp_enqueue_scripts() {
437
+ $js_vars = [];
438
+
439
+ // register our CSS and scripts
440
+ wp_register_style( 'toc-screen', $this->path . '/screen.min.css', [], TOC_VERSION );
441
+ wp_register_script( 'toc-front', $this->path . '/front.min.js', [ 'jquery' ], TOC_VERSION, true );
442
+
443
+ // enqueue them!
444
+ if ( ! $this->options['exclude_css'] ) {
445
+ wp_enqueue_style( 'toc-screen' );
446
+ }
447
+
448
+ if ( $this->options['smooth_scroll'] ) {
449
+ $js_vars['smooth_scroll'] = true;
450
+ }
451
+ wp_enqueue_script( 'toc-front' );
452
+ if ( $this->options['show_heading_text'] && $this->options['visibility'] ) {
453
+ $width = ( 'User defined' != $this->options['width'] ) ? $this->options['width'] : $this->options['width_custom'] . $this->options['width_custom_units'];
454
+ $js_vars['visibility_show'] = esc_js( $this->options['visibility_show'] );
455
+ $js_vars['visibility_hide'] = esc_js( $this->options['visibility_hide'] );
456
+ if ( $this->options['visibility_hide_by_default'] ) {
457
+ $js_vars['visibility_hide_by_default'] = true;
458
+ }
459
+ $js_vars['width'] = esc_js( $width );
460
+ }
461
+ if ( TOC_SMOOTH_SCROLL_OFFSET != $this->options['smooth_scroll_offset'] ) {
462
+ $js_vars['smooth_scroll_offset'] = esc_js( $this->options['smooth_scroll_offset'] );
463
+ }
464
+
465
+ if ( count( $js_vars ) > 0 ) {
466
+ wp_localize_script(
467
+ 'toc-front',
468
+ 'tocplus',
469
+ $js_vars
470
+ );
471
+ }
472
+ }
473
+
474
+
475
+ function plugins_loaded() {
476
+ load_plugin_textdomain( 'table-of-contents-plus', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
477
+ }
478
+
479
+
480
+ function admin_init() {
481
+ wp_register_script( 'toc_admin_script', $this->path . '/admin.js' );
482
+ wp_register_style( 'toc_admin_style', $this->path . '/admin.css' );
483
+ }
484
+
485
+
486
+ function admin_menu() {
487
+ $page = add_submenu_page(
488
+ 'options-general.php',
489
+ __( 'TOC', 'table-of-contents-plus' ) . '+',
490
+ __( 'TOC', 'table-of-contents-plus' ) . '+',
491
+ 'manage_options',
492
+ 'toc',
493
+ [ $this, 'admin_options' ]
494
+ );
495
+
496
+ add_action( 'admin_print_styles-' . $page, [ $this, 'admin_options_head' ] );
497
+ }
498
+
499
+
500
+ function widgets_init() {
501
+ register_widget( 'toc_widget' );
502
+ }
503
+
504
+
505
+ /**
506
+ * Remove widget options on widget deletion
507
+ */
508
+ function sidebar_admin_setup() {
509
+ // this action is loaded at the start of the widget screen
510
+ // so only do the following only when a form action has been initiated
511
+ if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) ) {
512
+ if ( 'toc-widget' == @$_POST['id_base'] ) {
513
+ if ( isset( $_POST['delete_widget'] ) ) {
514
+ if ( 1 === (int) $_POST['delete_widget'] ) {
515
+ $this->set_show_toc_in_widget_only( false );
516
+ $this->set_show_toc_in_widget_only_post_types( [ 'page' ] );
517
+ }
518
+ }
519
+ }
520
+ }
521
+ }
522
+
523
+
524
+ function init() {
525
+ // Add compatibility with Rank Math SEO
526
+ if ( class_exists( 'RankMath' ) ) {
527
+ add_filter( 'rank_math/researches/toc_plugins', function( $toc_plugins ) {
528
+ $toc_plugins['table-of-contents-plus/toc.php'] = 'Table of Contents Plus';
529
+ return $toc_plugins;
530
+ } );
531
+ }
532
+ }
533
+
534
+
535
+ /**
536
+ * Load needed scripts and styles only on the toc administration interface.
537
+ */
538
+ function admin_options_head() {
539
+ wp_enqueue_style( 'farbtastic' );
540
+ wp_enqueue_script( 'farbtastic' );
541
+ wp_enqueue_script( 'jquery' );
542
+ wp_enqueue_script( 'toc_admin_script' );
543
+ wp_enqueue_style( 'toc_admin_style' );
544
+ }
545
+
546
+
547
+ /**
548
+ * Tries to convert $string into a valid hex colour.
549
+ * Returns $default if $string is not a hex value, otherwise returns verified hex.
550
+ */
551
+ private function hex_value( $string = '', $default = '#' ) {
552
+ $return = $default;
553
+
554
+ if ( $string ) {
555
+ // strip out non hex chars
556
+ $return = preg_replace( '/[^a-fA-F0-9]*/', '', $string );
557
+
558
+ switch ( strlen( $return ) ) {
559
+ case 3: // do next
560
+ case 6:
561
+ $return = '#' . $return;
562
+ break;
563
+
564
+ default:
565
+ if ( strlen( $return ) > 6 ) {
566
+ $return = '#' . substr( $return, 0, 6 ); // if > 6 chars, then take the first 6
567
+ } elseif ( strlen( $return ) > 3 && strlen( $return ) < 6 ) {
568
+ $return = '#' . substr( $return, 0, 3 ); // if between 3 and 6, then take first 3
569
+ } else {
570
+ $return = $default; // not valid, return $default
571
+ }
572
+ }
573
+ }
574
+
575
+ return $return;
576
+ }
577
+
578
+
579
+ private function save_admin_options() {
580
+ global $post_id;
581
+
582
+ // security check
583
+ if ( ! wp_verify_nonce( @$_POST['toc-admin-options'], plugin_basename( __FILE__ ) ) ) {
584
+ return false;
585
+ }
586
+
587
+ // require an administrator level to save
588
+ if ( ! current_user_can( 'manage_options', $post_id ) ) {
589
+ return false;
590
+ }
591
+
592
+ // use stripslashes on free text fields that can have ' " \
593
+ // WordPress automatically slashes these characters as part of
594
+ // wp-includes/load.php::wp_magic_quotes()
595
+
596
+ $custom_background_colour = $this->hex_value( trim( $_POST['custom_background_colour'] ), TOC_DEFAULT_BACKGROUND_COLOUR );
597
+ $custom_border_colour = $this->hex_value( trim( $_POST['custom_border_colour'] ), TOC_DEFAULT_BORDER_COLOUR );
598
+ $custom_title_colour = $this->hex_value( trim( $_POST['custom_title_colour'] ), TOC_DEFAULT_TITLE_COLOUR );
599
+ $custom_links_colour = $this->hex_value( trim( $_POST['custom_links_colour'] ), TOC_DEFAULT_LINKS_COLOUR );
600
+ $custom_links_hover_colour = $this->hex_value( trim( $_POST['custom_links_hover_colour'] ), TOC_DEFAULT_LINKS_HOVER_COLOUR );
601
+ $custom_links_visited_colour = $this->hex_value( trim( $_POST['custom_links_visited_colour'] ), TOC_DEFAULT_LINKS_VISITED_COLOUR );
602
+
603
+ if ( $restrict_path = trim( $_POST['restrict_path'] ) ) {
604
+ if ( strpos( $restrict_path, '/' ) !== 0 ) {
605
+ // restrict path did not start with a / so unset it
606
+ $restrict_path = '';
607
+ }
608
+ }
609
+
610
+ $this->options = array_merge(
611
+ $this->options,
612
+ [
613
+ 'fragment_prefix' => trim( $_POST['fragment_prefix'] ),
614
+ 'position' => intval( $_POST['position'] ),
615
+ 'start' => intval( $_POST['start'] ),
616
+ 'show_heading_text' => ( isset( $_POST['show_heading_text'] ) && $_POST['show_heading_text'] ) ? true : false,
617
+ 'heading_text' => stripslashes( trim( $_POST['heading_text'] ) ),
618
+ 'auto_insert_post_types' => @ (array) $_POST['auto_insert_post_types'],
619
+ 'show_heirarchy' => ( isset( $_POST['show_heirarchy'] ) && $_POST['show_heirarchy'] ) ? true : false,
620
+ 'ordered_list' => ( isset( $_POST['ordered_list'] ) && $_POST['ordered_list'] ) ? true : false,
621
+ 'smooth_scroll' => ( isset( $_POST['smooth_scroll'] ) && $_POST['smooth_scroll'] ) ? true : false,
622
+ 'smooth_scroll_offset' => intval( $_POST['smooth_scroll_offset'] ),
623
+ 'visibility' => ( isset( $_POST['visibility'] ) && $_POST['visibility'] ) ? true : false,
624
+ 'visibility_show' => stripslashes( trim( $_POST['visibility_show'] ) ),
625
+ 'visibility_hide' => stripslashes( trim( $_POST['visibility_hide'] ) ),
626
+ 'visibility_hide_by_default' => ( isset( $_POST['visibility_hide_by_default'] ) && $_POST['visibility_hide_by_default'] ) ? true : false,
627
+ 'width' => trim( $_POST['width'] ),
628
+ 'width_custom' => floatval( $_POST['width_custom'] ),
629
+ 'width_custom_units' => trim( $_POST['width_custom_units'] ),
630
+ 'wrapping' => intval( $_POST['wrapping'] ),
631
+ 'font_size' => floatval( $_POST['font_size'] ),
632
+ 'font_size_units' => trim( $_POST['font_size_units'] ),
633
+ 'theme' => intval( $_POST['theme'] ),
634
+ 'custom_background_colour' => $custom_background_colour,
635
+ 'custom_border_colour' => $custom_border_colour,
636
+ 'custom_title_colour' => $custom_title_colour,
637
+ 'custom_links_colour' => $custom_links_colour,
638
+ 'custom_links_hover_colour' => $custom_links_hover_colour,
639
+ 'custom_links_visited_colour' => $custom_links_visited_colour,
640
+ 'lowercase' => ( isset( $_POST['lowercase'] ) && $_POST['lowercase'] ) ? true : false,
641
+ 'hyphenate' => ( isset( $_POST['hyphenate'] ) && $_POST['hyphenate'] ) ? true : false,
642
+ 'bullet_spacing' => ( isset( $_POST['bullet_spacing'] ) && $_POST['bullet_spacing'] ) ? true : false,
643
+ 'include_homepage' => ( isset( $_POST['include_homepage'] ) && $_POST['include_homepage'] ) ? true : false,
644
+ 'exclude_css' => ( isset( $_POST['exclude_css'] ) && $_POST['exclude_css'] ) ? true : false,
645
+ 'heading_levels' => @ (array) $_POST['heading_levels'],
646
+ 'exclude' => stripslashes( trim( $_POST['exclude'] ) ),
647
+ 'restrict_path' => $restrict_path,
648
+ 'sitemap_show_page_listing' => ( isset( $_POST['sitemap_show_page_listing'] ) && $_POST['sitemap_show_page_listing'] ) ? true : false,
649
+ 'sitemap_show_category_listing' => ( isset( $_POST['sitemap_show_category_listing'] ) && $_POST['sitemap_show_category_listing'] ) ? true : false,
650
+ 'sitemap_heading_type' => intval( $_POST['sitemap_heading_type'] ),
651
+ 'sitemap_pages' => stripslashes( trim( $_POST['sitemap_pages'] ) ),
652
+ 'sitemap_categories' => stripslashes( trim( $_POST['sitemap_categories'] ) ),
653
+ ]
654
+ );
655
+
656
+ // update_option will return false if no changes were made
657
+ update_option( 'toc-options', $this->options );
658
+
659
+ return true;
660
+ }
661
+
662
+
663
+ function admin_options() {
664
+ $msg = '';
665
+
666
+ if ( isset( $_GET['update'] ) ) {
667
+ if ( $this->save_admin_options() ) {
668
+ $msg = '<div id="message" class="updated fade"><p>' . __( 'Options saved.', 'table-of-contents-plus' ) . '</p></div>';
669
+ } else {
670
+ $msg = '<div id="message" class="error fade"><p>' . __( 'Save failed.', 'table-of-contents-plus' ) . '</p></div>';
671
+ }
672
+ }
673
+
674
+ ?>
675
+ <div id='toc' class='wrap'>
676
+ <div id="icon-options-general" class="icon32"><br /></div>
677
+ <h2>Table of Contents Plus</h2>
678
+ <?php echo $msg; ?>
679
+ <form method="post" action="<?php echo htmlentities( '?page=' . $_GET['page'] . '&update' ); ?>">
680
+ <?php wp_nonce_field( plugin_basename( __FILE__ ), 'toc-admin-options' ); ?>
681
+
682
+ <ul id="tabbed-nav">
683
+ <li><a href="#tab1"><?php _e( 'Main Options', 'table-of-contents-plus' ); ?></a></li>
684
+ <li><a href="#tab2"><?php _e( 'Sitemap', 'table-of-contents-plus' ); ?></a></li>
685
+ <li class="url"><a href="http://dublue.com/plugins/toc/#Help"><?php _e( 'Help', 'table-of-contents-plus' ); ?></a></li>
686
+ </ul>
687
+ <div class="tab_container">
688
+ <div id="tab1" class="tab_content">
689
+
690
+ <table class="form-table">
691
+ <tbody>
692
+ <tr>
693
+ <th><label for="position"><?php _e( 'Position', 'table-of-contents-plus' ); ?></label></th>
694
+ <td>
695
+ <select name="position" id="position">
696
+ <option value="<?php echo TOC_POSITION_BEFORE_FIRST_HEADING; ?>"<?php if ( TOC_POSITION_BEFORE_FIRST_HEADING == $this->options['position'] ) echo ' selected="selected"'; ?>><?php _e( 'Before first heading (default)', 'table-of-contents-plus' ); ?></option>
697
+ <option value="<?php echo TOC_POSITION_AFTER_FIRST_HEADING; ?>"<?php if ( TOC_POSITION_AFTER_FIRST_HEADING == $this->options['position'] ) echo ' selected="selected"'; ?>><?php _e( 'After first heading', 'table-of-contents-plus' ); ?></option>
698
+ <option value="<?php echo TOC_POSITION_TOP; ?>"<?php if ( TOC_POSITION_TOP == $this->options['position'] ) echo ' selected="selected"'; ?>><?php _e( 'Top', 'table-of-contents-plus' ); ?></option>
699
+ <option value="<?php echo TOC_POSITION_BOTTOM; ?>"<?php if ( TOC_POSITION_BOTTOM == $this->options['position'] ) echo ' selected="selected"'; ?>><?php _e( 'Bottom', 'table-of-contents-plus' ); ?></option>
700
+ </select>
701
+ </td>
702
+ </tr>
703
+ <tr>
704
+ <th><label for="start"><?php _e( 'Show when', 'table-of-contents-plus' ); ?></label></th>
705
+ <td>
706
+ <select name="start" id="start">
707
+ <?php
708
+ for ($i = TOC_MIN_START; $i <= TOC_MAX_START; $i++) {
709
+ echo '<option value="' . $i . '"';
710
+ if ( $i == $this->options['start'] ) echo ' selected="selected"';
711
+ echo '>' . $i . '</option>' . "\n";
712
+ }
713
+ ?>
714
+ </select> <?php
715
+ /* translators: text follows drop down list of numbers */
716
+ _e( 'or more headings are present', 'table-of-contents-plus' ); ?>
717
+ </td>
718
+ </tr>
719
+ <tr>
720
+ <th><?php _e( 'Auto insert for the following content types', 'table-of-contents-plus' ); ?></th>
721
+ <td><?php
722
+ foreach ( get_post_types() as $post_type ) {
723
+ // make sure the post type isn't on the exclusion list
724
+ if ( ! in_array( $post_type, $this->exclude_post_types ) ) {
725
+ echo '<input type="checkbox" value="' . $post_type . '" id="auto_insert_post_types_' . $post_type .'" name="auto_insert_post_types[]"';
726
+ if ( in_array( $post_type, $this->options['auto_insert_post_types'] ) ) echo ' checked="checked"';
727
+ echo ' /><label for="auto_insert_post_types_' . $post_type . '"> ' . $post_type . '</label><br />';
728
+ }
729
+ }
730
+ ?>
731
+ </tr>
732
+ <tr>
733
+ <th><label for="show_heading_text"><?php
734
+ /* translators: this is the title of the table of contents */
735
+ _e( 'Heading text', 'table-of-contents-plus' ); ?></label></th>
736
+ <td>
737
+ <input type="checkbox" value="1" id="show_heading_text" name="show_heading_text"<?php if ( $this->options['show_heading_text'] ) echo ' checked="checked"'; ?> /><label for="show_heading_text"> <?php _e( 'Show title on top of the table of contents', 'table-of-contents-plus' ); ?></label><br />
738
+ <div class="more_toc_options<?php if ( ! $this->options['show_heading_text'] ) echo ' disabled'; ?>">
739
+ <input type="text" class="regular-text" value="<?php echo htmlentities( $this->options['heading_text'], ENT_COMPAT, 'UTF-8' ); ?>" id="heading_text" name="heading_text" />
740
+ <span class="description"><label for="heading_text"><?php _e( 'Eg: Contents, Table of Contents, Page Contents', 'table-of-contents-plus' ); ?></label></span><br /><br />
741
+
742
+ <input type="checkbox" value="1" id="visibility" name="visibility"<?php if ( $this->options['visibility'] ) echo ' checked="checked"'; ?> /><label for="visibility"> <?php _e( 'Allow the user to toggle the visibility of the table of contents', 'table-of-contents-plus' ); ?></label><br />
743
+ <div class="more_toc_options<?php if ( ! $this->options['visibility'] ) echo ' disabled'; ?>">
744
+ <table class="more_toc_options_table">
745
+ <tbody>
746
+ <tr>
747
+ <th><label for="visibility_show"><?php _e( 'Show text', 'table-of-contents-plus' ); ?></label></th>
748
+ <td><input type="text" class="" value="<?php echo htmlentities( $this->options['visibility_show'], ENT_COMPAT, 'UTF-8' ); ?>" id="visibility_show" name="visibility_show" />
749
+ <span class="description"><label for="visibility_show"><?php
750
+ /* translators: example text to display when you want to expand the table of contents */
751
+ _e( 'Eg: show', 'table-of-contents-plus' ); ?></label></span></td>
752
+ </tr>
753
+ <tr>
754
+ <th><label for="visibility_hide"><?php _e( 'Hide text', 'table-of-contents-plus' ); ?></label></th>
755
+ <td><input type="text" class="" value="<?php echo htmlentities( $this->options['visibility_hide'], ENT_COMPAT, 'UTF-8' ); ?>" id="visibility_hide" name="visibility_hide" />
756
+ <span class="description"><label for="visibility_hide"><?php
757
+ /* translators: example text to display when you want to collapse the table of contents */
758
+ _e( 'Eg: hide', 'table-of-contents-plus' ); ?></label></span></td>
759
+ </tr>
760
+ </tbody>
761
+ </table>
762
+ <input type="checkbox" value="1" id="visibility_hide_by_default" name="visibility_hide_by_default"<?php if ( $this->options['visibility_hide_by_default'] ) echo ' checked="checked"'; ?> /><label for="visibility_hide_by_default"> <?php _e( 'Hide the table of contents initially', 'table-of-contents-plus' ); ?></label>
763
+ </div>
764
+ </div>
765
+ </td>
766
+ </tr>
767
+ <tr>
768
+ <th><label for="show_heirarchy"><?php _e( 'Show hierarchy', 'table-of-contents-plus' ); ?></label></th>
769
+ <td><input type="checkbox" value="1" id="show_heirarchy" name="show_heirarchy"<?php if ( $this->options['show_heirarchy'] ) echo ' checked="checked"'; ?> /></td>
770
+ </tr>
771
+ <tr>
772
+ <th><label for="ordered_list"><?php _e( 'Number list items', 'table-of-contents-plus' ); ?></label></th>
773
+ <td><input type="checkbox" value="1" id="ordered_list" name="ordered_list"<?php if ( $this->options['ordered_list'] ) echo ' checked="checked"'; ?> /></td>
774
+ </tr>
775
+ <tr>
776
+ <th><label for="smooth_scroll"><?php _e( 'Enable smooth scroll effect', 'table-of-contents-plus' ); ?></label></th>
777
+ <td><input type="checkbox" value="1" id="smooth_scroll" name="smooth_scroll"<?php if ( $this->options['smooth_scroll'] ) echo ' checked="checked"'; ?> /><label for="smooth_scroll"> <?php _e( 'Scroll rather than jump to the anchor link', 'table-of-contents-plus' ); ?></label></td>
778
+ </tr>
779
+ </tbody>
780
+ </table>
781
+
782
+ <h3><?php _e( 'Appearance', 'table-of-contents-plus' ); ?></h3>
783
+ <table class="form-table">
784
+ <tbody>
785
+ <tr>
786
+ <th><label for="width"><?php _e( 'Width', 'table-of-contents-plus' ); ?></label></td>
787
+ <td>
788
+ <select name="width" id="width">
789
+ <optgroup label="<?php _e( 'Fixed width', 'table-of-contents-plus' ); ?>">
790
+ <option value="200px"<?php if ( '200px' == $this->options['width'] ) echo ' selected="selected"'; ?>>200px</option>
791
+ <option value="225px"<?php if ( '225px' == $this->options['width'] ) echo ' selected="selected"'; ?>>225px</option>
792
+ <option value="250px"<?php if ( '250px' == $this->options['width'] ) echo ' selected="selected"'; ?>>250px</option>
793
+ <option value="275px"<?php if ( '275px' == $this->options['width'] ) echo ' selected="selected"'; ?>>275px</option>
794
+ <option value="300px"<?php if ( '300px' == $this->options['width'] ) echo ' selected="selected"'; ?>>300px</option>
795
+ <option value="325px"<?php if ( '325px' == $this->options['width'] ) echo ' selected="selected"'; ?>>325px</option>
796
+ <option value="350px"<?php if ( '350px' == $this->options['width'] ) echo ' selected="selected"'; ?>>350px</option>
797
+ <option value="375px"<?php if ( '375px' == $this->options['width'] ) echo ' selected="selected"'; ?>>375px</option>
798
+ <option value="400px"<?php if ( '400px' == $this->options['width'] ) echo ' selected="selected"'; ?>>400px</option>
799
+ </optgroup>
800
+ <optgroup label="<?php _e( 'Relative', 'table-of-contents-plus' ) ; ?>">
801
+ <option value="Auto"<?php if ( 'Auto' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e( 'Auto (default)', 'table-of-contents-plus' ); ?></option>
802
+ <option value="25%"<?php if ( '25%' == $this->options['width'] ) echo ' selected="selected"'; ?>>25%</option>
803
+ <option value="33%"<?php if ( '33%' == $this->options['width'] ) echo ' selected="selected"'; ?>>33%</option>
804
+ <option value="50%"<?php if ( '50%' == $this->options['width'] ) echo ' selected="selected"'; ?>>50%</option>
805
+ <option value="66%"<?php if ( '66%' == $this->options['width'] ) echo ' selected="selected"'; ?>>66%</option>
806
+ <option value="75%"<?php if ( '75%' == $this->options['width'] ) echo ' selected="selected"'; ?>>75%</option>
807
+ <option value="100%"<?php if ( '100%' == $this->options['width'] ) echo ' selected="selected"'; ?>>100%</option>
808
+ </optgroup>
809
+ <optgroup label="<?php
810
+ /* translators: other width */
811
+ _e( 'Other', 'table-of-contents-plus' ); ?>">
812
+ <option value="User defined"<?php if ( 'User defined' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e( 'User defined', 'table-of-contents-plus' ); ?></option>
813
+ </optgroup>
814
+ </select>
815
+ <div class="more_toc_options<?php if ( 'User defined' != $this->options['width'] ) echo ' disabled'; ?>">
816
+ <label for="width_custom"><?php
817
+ /* translators: ignore %s as it's some HTML label tags */
818
+ printf( __( 'Please enter a number and %s select its units, eg: 100px, 10em', 'table-of-contents-plus' ), '</label><label for="width_custom_units">' ); ?></label><br />
819
+ <input type="text" class="regular-text" value="<?php echo floatval( $this->options['width_custom'] ); ?>" id="width_custom" name="width_custom" />
820
+ <select name="width_custom_units" id="width_custom_units">
821
+ <option value="px"<?php if ( 'px' == $this->options['width_custom_units'] ) echo ' selected="selected"'; ?>>px</option>
822
+ <option value="%"<?php if ( '%' == $this->options['width_custom_units'] ) echo ' selected="selected"'; ?>>%</option>
823
+ <option value="em"<?php if ( 'em' == $this->options['width_custom_units'] ) echo ' selected="selected"'; ?>>em</option>
824
+ </select>
825
+ </div>
826
+ </td>
827
+ </tr>
828
+ <tr>
829
+ <th><label for="wrapping"><?php _e( 'Wrapping', 'table-of-contents-plus' ); ?></label></td>
830
+ <td>
831
+ <select name="wrapping" id="wrapping">
832
+ <option value="<?php echo TOC_WRAPPING_NONE; ?>"<?php if ( TOC_WRAPPING_NONE == $this->options['wrapping'] ) echo ' selected="selected"'; ?>><?php _e( 'None (default)', 'table-of-contents-plus' ); ?></option>
833
+ <option value="<?php echo TOC_WRAPPING_LEFT; ?>"<?php if ( TOC_WRAPPING_LEFT == $this->options['wrapping'] ) echo ' selected="selected"'; ?>><?php _e( 'Left', 'table-of-contents-plus' ); ?></option>
834
+ <option value="<?php echo TOC_WRAPPING_RIGHT; ?>"<?php if ( TOC_WRAPPING_RIGHT == $this->options['wrapping'] ) echo ' selected="selected"'; ?>><?php _e( 'Right', 'table-of-contents-plus' ); ?></option>
835
+ </select>
836
+ </td>
837
+ </tr>
838
+ <tr>
839
+ <th><label for="font_size"><?php _e( 'Font size', 'table-of-contents-plus' ); ?></label></th>
840
+ <td>
841
+ <input type="text" class="regular-text" value="<?php echo floatval( $this->options['font_size'] ); ?>" id="font_size" name="font_size" />
842
+ <select name="font_size_units" id="font_size_units">
843
+ <option value="px"<?php if ( 'pt' == $this->options['font_size_units'] ) echo ' selected="selected"'; ?>>pt</option>
844
+ <option value="%"<?php if ( '%' == $this->options['font_size_units'] ) echo ' selected="selected"'; ?>>%</option>
845
+ <option value="em"<?php if ( 'em' == $this->options['font_size_units'] ) echo ' selected="selected"'; ?>>em</option>
846
+ </select>
847
+ </td>
848
+ </tr>
849
+ <tr>
850
+ <th><?php
851
+ /* translators: appearance / colour / look and feel options */
852
+ _e( 'Presentation', 'table-of-contents-plus' ); ?></th>
853
+ <td>
854
+ <div class="toc_theme_option">
855
+ <input type="radio" name="theme" id="theme_<?php echo TOC_THEME_GREY; ?>" value="<?php echo TOC_THEME_GREY; ?>"<?php if ( $this->options['theme'] == TOC_THEME_GREY ) echo ' checked="checked"'; ?> /><label for="theme_<?php echo TOC_THEME_GREY; ?>"> <?php _e( 'Grey (default)', 'table-of-contents-plus' ); ?><br />
856
+ <img src="<?php echo $this->path; ?>/images/grey.png" alt="" />
857
+ </label>
858
+ </div>
859
+ <div class="toc_theme_option">
860
+ <input type="radio" name="theme" id="theme_<?php echo TOC_THEME_LIGHT_BLUE; ?>" value="<?php echo TOC_THEME_LIGHT_BLUE; ?>"<?php if ( $this->options['theme'] == TOC_THEME_LIGHT_BLUE ) echo ' checked="checked"'; ?> /><label for="theme_<?php echo TOC_THEME_LIGHT_BLUE; ?>"> <?php _e( 'Light blue', 'table-of-contents-plus' ); ?><br />
861
+ <img src="<?php echo $this->path; ?>/images/blue.png" alt="" />
862
+ </label>
863
+ </div>
864
+ <div class="toc_theme_option">
865
+ <input type="radio" name="theme" id="theme_<?php echo TOC_THEME_WHITE; ?>" value="<?php echo TOC_THEME_WHITE; ?>"<?php if ( $this->options['theme'] == TOC_THEME_WHITE ) echo ' checked="checked"'; ?> /><label for="theme_<?php echo TOC_THEME_WHITE; ?>"> <?php _e( 'White', 'table-of-contents-plus' ); ?><br />
866
+ <img src="<?php echo $this->path; ?>/images/white.png" alt="" />
867
+ </label>
868
+ </div>
869
+ <div class="toc_theme_option">
870
+ <input type="radio" name="theme" id="theme_<?php echo TOC_THEME_BLACK; ?>" value="<?php echo TOC_THEME_BLACK; ?>"<?php if ( $this->options['theme'] == TOC_THEME_BLACK ) echo ' checked="checked"'; ?> /><label for="theme_<?php echo TOC_THEME_BLACK; ?>"> <?php _e( 'Black', 'table-of-contents-plus' ); ?><br />
871
+ <img src="<?php echo $this->path; ?>/images/black.png" alt="" />
872
+ </label>
873
+ </div>
874
+ <div class="toc_theme_option">
875
+ <input type="radio" name="theme" id="theme_<?php echo TOC_THEME_TRANSPARENT; ?>" value="<?php echo TOC_THEME_TRANSPARENT; ?>"<?php if ( $this->options['theme'] == TOC_THEME_TRANSPARENT ) echo ' checked="checked"'; ?> /><label for="theme_<?php echo TOC_THEME_TRANSPARENT; ?>"> <?php _e( 'Transparent', 'table-of-contents-plus' ); ?><br />
876
+ <img src="<?php echo $this->path; ?>/images/transparent.png" alt="" />
877
+ </label>
878
+ </div>
879
+ <div class="toc_theme_option">
880
+ <input type="radio" name="theme" id="theme_<?php echo TOC_THEME_CUSTOM; ?>" value="<?php echo TOC_THEME_CUSTOM; ?>"<?php if ( $this->options['theme'] == TOC_THEME_CUSTOM ) echo ' checked="checked"'; ?> /><label for="theme_<?php echo TOC_THEME_CUSTOM; ?>"> <?php _e( 'Custom', 'table-of-contents-plus' ); ?><br />
881
+ <img src="<?php echo $this->path; ?>/images/custom.png" alt="" />
882
+ </label>
883
+ </div>
884
+ <div class="clear"></div>
885
+
886
+ <div class="more_toc_options<?php if ( TOC_THEME_CUSTOM !== $this->options['theme'] ) echo ' disabled'; ?>">
887
+ <table id="theme_custom" class="more_toc_options_table">
888
+ <tbody>
889
+ <tr>
890
+ <th><label for="custom_background_colour"><?php _e( 'Background', 'table-of-contents-plus' ); ?></label></th>
891
+ <td><input type="text" class="custom_colour_option" value="<?php echo htmlentities( $this->options['custom_background_colour'] ); ?>" id="custom_background_colour" name="custom_background_colour" /> <img src="<?php echo $this->path; ?>/images/colour-wheel.png" alt="" /></td>
892
+ </tr>
893
+ <tr>
894
+ <th><label for="custom_border_colour"><?php _e( 'Border', 'table-of-contents-plus' ); ?></label></th>
895
+ <td><input type="text" class="custom_colour_option" value="<?php echo htmlentities( $this->options['custom_border_colour'] ); ?>" id="custom_border_colour" name="custom_border_colour" /> <img src="<?php echo $this->path; ?>/images/colour-wheel.png" alt="" /></td>
896
+ </tr>
897
+ <tr>
898
+ <th><label for="custom_title_colour"><?php _e( 'Title', 'table-of-contents-plus' ); ?></label></th>
899
+ <td><input type="text" class="custom_colour_option" value="<?php echo htmlentities( $this->options['custom_title_colour'] ); ?>" id="custom_title_colour" name="custom_title_colour" /> <img src="<?php echo $this->path; ?>/images/colour-wheel.png" alt="" /></td>
900
+ </tr>
901
+ <tr>
902
+ <th><label for="custom_links_colour"><?php _e( 'Links', 'table-of-contents-plus' ); ?></label></th>
903
+ <td><input type="text" class="custom_colour_option" value="<?php echo htmlentities( $this->options['custom_links_colour'] ); ?>" id="custom_links_colour" name="custom_links_colour" /> <img src="<?php echo $this->path; ?>/images/colour-wheel.png" alt="" /></td>
904
+ </tr>
905
+ <tr>
906
+ <th><label for="custom_links_hover_colour"><?php _e( 'Links (hover)', 'table-of-contents-plus' ); ?></label></th>
907
+ <td><input type="text" class="custom_colour_option" value="<?php echo htmlentities( $this->options['custom_links_hover_colour'] ); ?>" id="custom_links_hover_colour" name="custom_links_hover_colour" /> <img src="<?php echo $this->path; ?>/images/colour-wheel.png" alt="" /></td>
908
+ </tr>
909
+ <tr>
910
+ <th><label for="custom_links_visited_colour"><?php _e( 'Links (visited)', 'table-of-contents-plus' ); ?></label></th>
911
+ <td><input type="text" class="custom_colour_option" value="<?php echo htmlentities( $this->options['custom_links_visited_colour'] ); ?>" id="custom_links_visited_colour" name="custom_links_visited_colour" /> <img src="<?php echo $this->path; ?>/images/colour-wheel.png" alt="" /></td>
912
+ </tr>
913
+ </tbody>
914
+ </table>
915
+ <div id="farbtastic_colour_wheel"></div>
916
+ <div class="clear"></div>
917
+ <p><?php printf( __( "Leaving the value as %s will inherit your theme's styles", 'table-of-contents-plus' ), '<code>#</code>' ); ?></p>
918
+ </div>
919
+ </td>
920
+ </tr>
921
+ </tbody>
922
+ </table>
923
+
924
+ <h3><?php _e( 'Advanced', 'table-of-contents-plus' ); ?> <span class="show_hide">(<a href="#toc_advanced_usage"><?php _e( 'show', 'table-of-contents-plus' ); ?></a>)</span></h3>
925
+ <div id="toc_advanced_usage">
926
+ <h4><?php _e( 'Power options', 'table-of-contents-plus' ); ?></h4>
927
+ <table class="form-table">
928
+ <tbody>
929
+ <tr>
930
+ <th><label for="lowercase"><?php _e( 'Lowercase', 'table-of-contents-plus' ); ?></label></th>
931
+ <td><input type="checkbox" value="1" id="lowercase" name="lowercase"<?php if ( $this->options['lowercase'] ) echo ' checked="checked"'; ?> /><label for="lowercase"> <?php _e( 'Ensure anchors are in lowercase', 'table-of-contents-plus' ); ?></label></td>
932
+ </tr>
933
+ <tr>
934
+ <th><label for="hyphenate"><?php _e( 'Hyphenate', 'table-of-contents-plus' ); ?></label></th>
935
+ <td><input type="checkbox" value="1" id="hyphenate" name="hyphenate"<?php if ( $this->options['hyphenate'] ) echo ' checked="checked"'; ?> /><label for="hyphenate"> <?php _e( 'Use - rather than _ in anchors', 'table-of-contents-plus' ); ?></label></td>
936
+ </tr>
937
+ <tr>
938
+ <th><label for="include_homepage"><?php _e( 'Include homepage', 'table-of-contents-plus' ); ?></label></th>
939
+ <td><input type="checkbox" value="1" id="include_homepage" name="include_homepage"<?php if ( $this->options['include_homepage'] ) echo ' checked="checked"'; ?> /><label for="include_homepage"> <?php _e( 'Show the table of contents for qualifying items on the homepage', 'table-of-contents-plus' ); ?></label></td>
940
+ </tr>
941
+ <tr>
942
+ <th><label for="exclude_css"><?php _e( 'Exclude CSS file', 'table-of-contents-plus' ); ?></label></th>
943
+ <td><input type="checkbox" value="1" id="exclude_css" name="exclude_css"<?php if ( $this->options['exclude_css'] ) echo ' checked="checked"'; ?> /><label for="exclude_css"> <?php _e( "Prevent the loading of this plugin's CSS styles. When selected, the appearance options from above will also be ignored.", 'table-of-contents-plus' ); ?></label></td>
944
+ </tr>
945
+ <tr>
946
+ <th><label for="bullet_spacing"><?php _e( 'Preserve theme bullets', 'table-of-contents-plus' ); ?></label></th>
947
+ <td><input type="checkbox" value="1" id="bullet_spacing" name="bullet_spacing"<?php if ( $this->options['bullet_spacing'] ) echo ' checked="checked"'; ?> /><label for="bullet_spacing"> <?php _e( 'If your theme includes background images for unordered list elements, enable this to support them', 'table-of-contents-plus' ); ?></label></td>
948
+ </tr>
949
+ <tr>
950
+ <th><?php _e( 'Heading levels', 'table-of-contents-plus' ); ?></th>
951
+ <td>
952
+ <p><?php _e( 'Include the following heading levels. Deselecting a heading will exclude it.', 'table-of-contents-plus' ); ?></p>
953
+ <?php
954
+ // show heading 1 to 6 options
955
+ for ( $i = 1; $i <= 6; $i++ ) {
956
+ echo '<input type="checkbox" value="' . $i . '" id="heading_levels' . $i .'" name="heading_levels[]"';
957
+ if ( in_array( $i, $this->options['heading_levels'] ) ) {
958
+ echo ' checked="checked"';
959
+ }
960
+ echo ' /><label for="heading_levels' . $i .'"> ' . __( 'heading ' ) . $i . ' - h' . $i . '</label><br />';
961
+ }
962
+ ?>
963
+ </td>
964
+ </tr>
965
+ <tr>
966
+ <th><label for="exclude"><?php _e( 'Exclude headings', 'table-of-contents-plus' ); ?></label></th>
967
+ <td>
968
+ <input type="text" class="regular-text" value="<?php echo htmlentities( $this->options['exclude'], ENT_COMPAT, 'UTF-8' ); ?>" id="exclude" name="exclude" style="width: 100%;" /><br />
969
+ <label for="exclude"><?php _e( 'Specify headings to be excluded from appearing in the table of contents. Separate multiple headings with a pipe <code>|</code>. Use an asterisk <code>*</code> as a wildcard to match other text. Note that this is not case sensitive. Some examples:', 'table-of-contents-plus' ); ?></label><br/>
970
+ <ul>
971
+ <li><?php _e( '<code>Fruit*</code> ignore headings starting with "Fruit"', 'table-of-contents-plus' ); ?></li>
972
+ <li><?php _e( '<code>*Fruit Diet*</code> ignore headings with "Fruit Diet" somewhere in the heading', 'table-of-contents-plus' ); ?></li>
973
+ <li><?php _e( '<code>Apple Tree|Oranges|Yellow Bananas</code> ignore headings that are exactly "Apple Tree", "Oranges" or "Yellow Bananas"', 'table-of-contents-plus' ); ?></li>
974
+ </ul>
975
+ </td>
976
+ </tr>
977
+ <tr id="smooth_scroll_offset_tr" class="<?php if ( ! $this->options['smooth_scroll'] ) echo 'disabled'; ?>">
978
+ <th><label for="smooth_scroll_offset"><?php _e( 'Smooth scroll top offset', 'table-of-contents-plus' ); ?></label></th>
979
+ <td>
980
+ <input type="text" class="regular-text" value="<?php echo intval( $this->options['smooth_scroll_offset'] ); ?>" id="smooth_scroll_offset" name="smooth_scroll_offset" /> px<br />
981
+ <label for="smooth_scroll_offset"><?php _e( 'If you have a consistent menu across the top of your site, you can adjust the top offset to stop the headings from appearing underneath the top menu. A setting of 30 accommodates the WordPress admin bar. This setting appears after you have enabled smooth scrolling from above.', 'table-of-contents-plus' ); ?></label>
982
+ </td>
983
+ </tr>
984
+ <tr>
985
+ <th><label for="restrict_path"><?php _e( 'Restrict path', 'table-of-contents-plus' ); ?></label></th>
986
+ <td>
987
+ <input type="text" class="regular-text" value="<?php echo htmlentities( $this->options['restrict_path'], ENT_COMPAT, 'UTF-8' ); ?>" id="restrict_path" name="restrict_path" /><br />
988
+ <label for="restrict_path"><?php _e( 'Restrict generation of the table of contents to pages that match the required path. This path is from the root of your site and always begins with a forward slash.', 'table-of-contents-plus' ); ?><br />
989
+ <span class="description"><?php
990
+ /* translators: example URL path restriction */
991
+ _e( 'Eg: /wiki/, /corporate/annual-reports/', 'table-of-contents-plus' ); ?></span></label>
992
+ </td>
993
+ </tr>
994
+ <tr>
995
+ <th><label for="fragment_prefix"><?php _e( 'Default anchor prefix', 'table-of-contents-plus' ); ?></label></th>
996
+ <td>
997
+ <input type="text" class="regular-text" value="<?php echo htmlentities( $this->options['fragment_prefix'], ENT_COMPAT, 'UTF-8' ); ?>" id="fragment_prefix" name="fragment_prefix" /><br />
998
+ <label for="fragment_prefix"><?php _e( 'Anchor targets are restricted to alphanumeric characters as per HTML specification (see readme for more detail). The default anchor prefix will be used when no characters qualify. When left blank, a number will be used instead.', 'table-of-contents-plus' ); ?><br />
999
+ <?php _e( 'This option normally applies to content written in character sets other than ASCII.', 'table-of-contents-plus' ); ?><br />
1000
+ <span class="description"><?php
1001
+ /* translators: example anchor prefixes when no ascii characters match */
1002
+ _e( 'Eg: i, toc_index, index, _', 'table-of-contents-plus' ); ?></span></label>
1003
+ </td>
1004
+ </tr>
1005
+ </tbody>
1006
+ </table>
1007
+
1008
+ <h4><?php
1009
+ /* translators: advanced usage */
1010
+ _e( 'Usage', 'table-of-contents-plus' ); ?></h4>
1011
+ <p><?php printf( __( 'If you would like to fully customise the position of the table of contents, you can use the %s shortcode by placing it at the desired position of your post, page or custom post type. This method allows you to generate the table of contents despite having auto insertion disabled for its content type. Please visit the help tab for further information about this shortcode.', 'table-of-contents-plus' ), '<code>[toc]</code>' ); ?></p>
1012
+ </div>
1013
+
1014
+
1015
+ </div>
1016
+ <div id="tab2" class="tab_content">
1017
+
1018
+
1019
+ <p><?php printf( __( 'At its simplest, placing %s into a page will automatically create a sitemap of all pages and categories. This also works in a text widget.', 'table-of-contents-plus' ), '<code>[sitemap]</code>' ); ?></p>
1020
+ <table class="form-table">
1021
+ <tbody>
1022
+ <tr>
1023
+ <th><label for="sitemap_show_page_listing"><?php _e( 'Show page listing', 'table-of-contents-plus' ); ?></label></th>
1024
+ <td><input type="checkbox" value="1" id="sitemap_show_page_listing" name="sitemap_show_page_listing"<?php if ( $this->options['sitemap_show_page_listing'] ) echo ' checked="checked"'; ?> /></td>
1025
+ </tr>
1026
+ <tr>
1027
+ <th><label for="sitemap_show_category_listing"><?php _e( 'Show category listing', 'table-of-contents-plus' ); ?></label></th>
1028
+ <td><input type="checkbox" value="1" id="sitemap_show_category_listing" name="sitemap_show_category_listing"<?php if ( $this->options['sitemap_show_category_listing'] ) echo ' checked="checked"'; ?> /></td>
1029
+ </tr>
1030
+ <tr>
1031
+ <th><label for="sitemap_heading_type"><?php _e( 'Heading type', 'table-of-contents-plus' ); ?></label></th>
1032
+ <td><label for="sitemap_heading_type"><?php
1033
+ /* translators: the full line is supposed to read - Use [1-6 drop down list] to print out the titles */
1034
+ _e( 'Use', 'table-of-contents-plus' ); ?> h</label><select name="sitemap_heading_type" id="sitemap_heading_type">
1035
+ <?php
1036
+ // h1 to h6
1037
+ for ( $i = 1; $i <= 6; $i++ ) {
1038
+ echo '<option value="' . $i . '"';
1039
+ if ( $i == $this->options['sitemap_heading_type'] ) {
1040
+ echo ' selected="selected"';
1041
+ }
1042
+ echo '>' . $i . '</option>' . "\n";
1043
+ }
1044
+ ?>
1045
+ </select> <?php
1046
+ /* translators: the full line is supposed to read - Use [h1-h6 drop down list] to print out the titles */
1047
+ _e( 'to print out the titles', 'table-of-contents-plus' ); ?>
1048
+ </td>
1049
+ </tr>
1050
+ <tr>
1051
+ <th><label for="sitemap_pages"><?php _e( 'Pages label', 'table-of-contents-plus' ); ?></label></th>
1052
+ <td><input type="text" class="regular-text" value="<?php echo htmlentities( $this->options['sitemap_pages'], ENT_COMPAT, 'UTF-8' ); ?>" id="sitemap_pages" name="sitemap_pages" />
1053
+ <span class="description"><?php _e( 'Eg: Pages, Page List', 'table-of-contents-plus' ); ?></span>
1054
+ </td>
1055
+ </tr>
1056
+ <tr>
1057
+ <th><label for="sitemap_categories"><?php _e( 'Categories label', 'table-of-contents-plus' ); ?></label></th>
1058
+ <td><input type="text" class="regular-text" value="<?php echo htmlentities( $this->options['sitemap_categories'], ENT_COMPAT, 'UTF-8' ); ?>" id="sitemap_categories" name="sitemap_categories" />
1059
+ <span class="description"><?php _e( 'Eg: Categories, Category List', 'table-of-contents-plus' ); ?></span>
1060
+ </td>
1061
+ </tr>
1062
+ </tbody>
1063
+ </table>
1064
+
1065
+ <h3><?php _e( 'Advanced usage', 'table-of-contents-plus' ); ?> <span class="show_hide">(<a href="#sitemap_advanced_usage"><?php _e( 'show', 'table-of-contents-plus' ); ?></a>)</span></h3>
1066
+ <div id="sitemap_advanced_usage">
1067
+ <p><code>[sitemap_pages]</code> <?php printf( __( 'lets you print out a listing of only pages. Similarly %s can be used to print out a category listing. They both can accept a number of attributes so visit the help tab for more information.', 'table-of-contents-plus' ), '<code>[sitemap_categories]</code>' ); ?></p>
1068
+ <p><?php _e( 'Examples', 'table-of-contents-plus' ); ?></p>
1069
+ <ol>
1070
+ <li><code>[sitemap_categories no_label="true"]</code> <?php _e( 'hides the heading from a category listing', 'table-of-contents-plus' ); ?></li>
1071
+ <li><code>[sitemap_pages heading="6" label="This is an awesome listing" exclude="1,15"]</code> <?php printf( __( 'Uses h6 to display %s on a page listing excluding pages with IDs 1 and 15', 'table-of-contents-plus' ), '<em>This is an awesome listing</em>' ); ?></li>
1072
+ </ol>
1073
+ </div>
1074
+
1075
+
1076
+ </div>
1077
+ </div>
1078
+
1079
+
1080
+ <p class="submit"><input type="submit" name="submit" class="button-primary" value="<?php _e( 'Update Options', 'table-of-contents-plus' ); ?>" /></p>
1081
+ </form>
1082
+ </div>
1083
+ <?php
1084
+ }
1085
+
1086
+
1087
+ function wp_head() {
1088
+ $css = '';
1089
+
1090
+ if ( ! $this->options['exclude_css'] ) {
1091
+ if ( TOC_THEME_CUSTOM === $this->options['theme'] || 'Auto' !== $this->options['width'] ) {
1092
+ $css .= 'div#toc_container {';
1093
+ if ( TOC_THEME_CUSTOM === $this->options['theme'] ) {
1094
+ $css .= 'background: ' . $this->options['custom_background_colour'] . ';border: 1px solid ' . $this->options['custom_border_colour'] . ';';
1095
+ }
1096
+ if ( 'Auto' !== $this->options['width'] ) {
1097
+ $css .= 'width: ';
1098
+ if ( 'User defined' !== $this->options['width'] ) {
1099
+ $css .= $this->options['width'];
1100
+ } else {
1101
+ $css .= $this->options['width_custom'] . $this->options['width_custom_units'];
1102
+ }
1103
+ $css .= ';';
1104
+ }
1105
+ $css .= '}';
1106
+ }
1107
+
1108
+ if ( '95%' !== $this->options['font_size'] . $this->options['font_size_units'] ) {
1109
+ $css .= 'div#toc_container ul li {font-size: ' . $this->options['font_size'] . $this->options['font_size_units'] . ';}';
1110
+ }
1111
+
1112
+ if ( TOC_THEME_CUSTOM === $this->options['theme'] ) {
1113
+ if ( TOC_DEFAULT_TITLE_COLOUR !== $this->options['custom_title_colour'] ) {
1114
+ $css .= 'div#toc_container p.toc_title {color: ' . $this->options['custom_title_colour'] . ';}';
1115
+ }
1116
+ if ( TOC_DEFAULT_LINKS_COLOUR !== $this->options['custom_links_colour'] ) {
1117
+ $css .= 'div#toc_container p.toc_title a,div#toc_container ul.toc_list a {color: ' . $this->options['custom_links_colour'] . ';}';
1118
+ }
1119
+ if ( TOC_DEFAULT_LINKS_HOVER_COLOUR !== $this->options['custom_links_hover_colour'] ) {
1120
+ $css .= 'div#toc_container p.toc_title a:hover,div#toc_container ul.toc_list a:hover {color: ' . $this->options['custom_links_hover_colour'] . ';}';
1121
+ }
1122
+ if ( TOC_DEFAULT_LINKS_HOVER_COLOUR !== $this->options['custom_links_hover_colour'] ) {
1123
+ $css .= 'div#toc_container p.toc_title a:hover,div#toc_container ul.toc_list a:hover {color: ' . $this->options['custom_links_hover_colour'] . ';}';
1124
+ }
1125
+ if ( TOC_DEFAULT_LINKS_VISITED_COLOUR !== $this->options['custom_links_visited_colour'] ) {
1126
+ $css .= 'div#toc_container p.toc_title a:visited,div#toc_container ul.toc_list a:visited {color: ' . $this->options['custom_links_visited_colour'] . ';}';
1127
+ }
1128
+ }
1129
+ }
1130
+
1131
+ if ( $css ) {
1132
+ echo '<style type="text/css">' . $css . '</style>';
1133
+ }
1134
+ }
1135
+
1136
+
1137
+ /**
1138
+ * Returns a clean url to be used as the destination anchor target
1139
+ */
1140
+ private function url_anchor_target( $title ) {
1141
+ $return = false;
1142
+
1143
+ if ( $title ) {
1144
+ $return = trim( strip_tags( $title ) );
1145
+
1146
+ // convert accented characters to ASCII
1147
+ $return = remove_accents( $return );
1148
+
1149
+ // replace newlines with spaces (eg when headings are split over multiple lines)
1150
+ $return = str_replace( [ "\r", "\n", "\n\r", "\r\n" ], ' ', $return );
1151
+
1152
+ // remove &amp;
1153
+ $return = str_replace( '&amp;', '', $return );
1154
+
1155
+ // remove non alphanumeric chars
1156
+ $return = preg_replace( '/[^a-zA-Z0-9 \-_]*/', '', $return );
1157
+
1158
+ // convert spaces to _
1159
+ $return = str_replace(
1160
+ [ ' ', ' ' ],
1161
+ '_',
1162
+ $return
1163
+ );
1164
+
1165
+ // remove trailing - and _
1166
+ $return = rtrim( $return, '-_' );
1167
+
1168
+ // lowercase everything?
1169
+ if ( $this->options['lowercase'] ) {
1170
+ $return = strtolower( $return );
1171
+ }
1172
+
1173
+ // if blank, then prepend with the fragment prefix
1174
+ // blank anchors normally appear on sites that don't use the latin charset
1175
+ if ( ! $return ) {
1176
+ $return = ( $this->options['fragment_prefix'] ) ? $this->options['fragment_prefix'] : '_';
1177
+ }
1178
+
1179
+ // hyphenate?
1180
+ if ( $this->options['hyphenate'] ) {
1181
+ $return = str_replace( '_', '-', $return );
1182
+ $return = str_replace( '--', '-', $return );
1183
+ }
1184
+ }
1185
+
1186
+ if ( array_key_exists( $return, $this->collision_collector ) ) {
1187
+ $this->collision_collector[ $return ]++;
1188
+ $return .= '-' . $this->collision_collector[ $return ];
1189
+ } else {
1190
+ $this->collision_collector[ $return ] = 1;
1191
+ }
1192
+
1193
+ return apply_filters( 'toc_url_anchor_target', $return );
1194
+ }
1195
+
1196
+
1197
+ private function build_hierarchy( &$matches ) {
1198
+ $current_depth = 100; // headings can't be larger than h6 but 100 as a default to be sure
1199
+ $html = '';
1200
+ $numbered_items = [];
1201
+ $numbered_items_min = null;
1202
+
1203
+ // reset the internal collision collection
1204
+ $this->collision_collector = [];
1205
+
1206
+ // find the minimum heading to establish our baseline
1207
+ for ( $i = 0; $i < count( $matches ); $i++ ) {
1208
+ if ( $current_depth > $matches[ $i ][2] ) {
1209
+ $current_depth = (int) $matches[ $i ][2];
1210
+ }
1211
+ }
1212
+
1213
+ $numbered_items[ $current_depth ] = 0;
1214
+ $numbered_items_min = $current_depth;
1215
+
1216
+ for ( $i = 0; $i < count( $matches ); $i++ ) {
1217
+
1218
+ if ( $current_depth === (int) $matches[ $i ][2] ) {
1219
+ $html .= '<li>';
1220
+ }
1221
+
1222
+ // start lists
1223
+ if ( $current_depth !== (int) $matches[ $i ][2] ) {
1224
+ for ( $current_depth; $current_depth < (int) $matches[ $i ][2]; $current_depth++ ) {
1225
+ $numbered_items[ $current_depth + 1 ] = 0;
1226
+ $html .= '<ul><li>';
1227
+ }
1228
+ }
1229
+
1230
+ // list item
1231
+ if ( in_array( $matches[ $i ][2], $this->options['heading_levels'] ) ) {
1232
+ $html .= '<a href="#' . $this->url_anchor_target( $matches[ $i ][0] ) . '">';
1233
+ if ( $this->options['ordered_list'] ) {
1234
+ // attach leading numbers when lower in hierarchy
1235
+ $html .= '<span class="toc_number toc_depth_' . ( $current_depth - $numbered_items_min + 1 ) . '">';
1236
+ for ( $j = $numbered_items_min; $j < $current_depth; $j++ ) {
1237
+ $number = ( $numbered_items[ $j ] ) ? $numbered_items[ $j ] : 0;
1238
+ $html .= $number . '.';
1239
+ }
1240
+
1241
+ $html .= ( $numbered_items[ $current_depth ] + 1 ) . '</span> ';
1242
+ $numbered_items[ $current_depth ]++;
1243
+ }
1244
+ $html .= strip_tags( $matches[ $i ][0] ) . '</a>';
1245
+ }
1246
+
1247
+ // end lists
1248
+ if ( count( $matches ) - 1 !== $i ) {
1249
+ if ( $current_depth > (int) $matches[ $i + 1 ][2] ) {
1250
+ for ( $current_depth; $current_depth > (int) $matches[ $i + 1 ][2]; $current_depth-- ) {
1251
+ $html .= '</li></ul>';
1252
+ $numbered_items[ $current_depth ] = 0;
1253
+ }
1254
+ }
1255
+
1256
+ if ( (int) @$matches[ $i + 1 ][2] === $current_depth ) {
1257
+ $html .= '</li>';
1258
+ }
1259
+ } else {
1260
+ // this is the last item, make sure we close off all tags
1261
+ for ( $current_depth; $current_depth >= $numbered_items_min; $current_depth-- ) {
1262
+ $html .= '</li>';
1263
+ if ( $current_depth !== $numbered_items_min ) {
1264
+ $html .= '</ul>';
1265
+ }
1266
+ }
1267
+ }
1268
+ }
1269
+
1270
+ return $html;
1271
+ }
1272
+
1273
+
1274
+ /**
1275
+ * Returns a string with all items from the $find array replaced with their matching
1276
+ * items in the $replace array. This does a one to one replacement (rather than
1277
+ * globally).
1278
+ *
1279
+ * This function is multibyte safe.
1280
+ *
1281
+ * $find and $replace are arrays, $string is the haystack. All variables are
1282
+ * passed by reference.
1283
+ */
1284
+ private function mb_find_replace( &$find = false, &$replace = false, &$string = '' ) {
1285
+ if ( is_array( $find ) && is_array( $replace ) && $string ) {
1286
+ // check if multibyte strings are supported
1287
+ if ( function_exists( 'mb_strpos' ) ) {
1288
+ for ( $i = 0; $i < count( $find ); $i++ ) {
1289
+ $string =
1290
+ mb_substr( $string, 0, mb_strpos( $string, $find[ $i ] ) ) . // everything before $find
1291
+ $replace[ $i ] . // its replacement
1292
+ mb_substr( $string, mb_strpos( $string, $find[ $i ] ) + mb_strlen( $find[ $i ] ) ); // everything after $find
1293
+ }
1294
+ } else {
1295
+ for ( $i = 0; $i < count( $find ); $i++ ) {
1296
+ $string = substr_replace(
1297
+ $string,
1298
+ $replace[ $i ],
1299
+ strpos( $string, $find[ $i ] ),
1300
+ strlen( $find[ $i ] )
1301
+ );
1302
+ }
1303
+ }
1304
+ }
1305
+
1306
+ return $string;
1307
+ }
1308
+
1309
+
1310
+ /**
1311
+ * This function extracts headings from the html formatted $content. It will pull out
1312
+ * only the required headings as specified in the options. For all qualifying headings,
1313
+ * this function populates the $find and $replace arrays (both passed by reference)
1314
+ * with what to search and replace with.
1315
+ *
1316
+ * Returns a html formatted string of list items for each qualifying heading. This
1317
+ * is everything between and NOT including <ul> and </ul>
1318
+ */
1319
+ public function extract_headings( &$find, &$replace, $content = '' ) {
1320
+ $matches = [];
1321
+ $anchor = '';
1322
+ $items = false;
1323
+
1324
+ // reset the internal collision collection as the_content may have been triggered elsewhere
1325
+ // eg by themes or other plugins that need to read in content such as metadata fields in
1326
+ // the head html tag, or to provide descriptions to twitter/facebook
1327
+ $this->collision_collector = [];
1328
+
1329
+ if ( is_array( $find ) && is_array( $replace ) && $content ) {
1330
+ // get all headings
1331
+ // the html spec allows for a maximum of 6 heading depths
1332
+ if ( preg_match_all( '/(<h([1-6]{1})[^>]*>).*<\/h\2>/msuU', $content, $matches, PREG_SET_ORDER ) ) {
1333
+
1334
+ // remove undesired headings (if any) as defined by heading_levels
1335
+ if ( count( $this->options['heading_levels'] ) != 6 ) {
1336
+ $new_matches = [];
1337
+ for ( $i = 0; $i < count( $matches ); $i++ ) {
1338
+ if ( in_array( $matches[ $i ][2], $this->options['heading_levels'] ) ) {
1339
+ $new_matches[] = $matches[ $i ];
1340
+ }
1341
+ }
1342
+ $matches = $new_matches;
1343
+ }
1344
+
1345
+ // remove specific headings if provided via the 'exclude' property
1346
+ if ( $this->options['exclude'] ) {
1347
+ $excluded_headings = explode( '|', $this->options['exclude'] );
1348
+ if ( count( $excluded_headings ) > 0 ) {
1349
+ for ( $j = 0; $j < count( $excluded_headings ); $j++ ) {
1350
+ // escape some regular expression characters
1351
+ // others: http://www.php.net/manual/en/regexp.reference.meta.php
1352
+ $excluded_headings[ $j ] = str_replace(
1353
+ [ '*' ],
1354
+ [ '.*' ],
1355
+ trim( $excluded_headings[ $j ] )
1356
+ );
1357
+ }
1358
+
1359
+ $new_matches = [];
1360
+ for ( $i = 0; $i < count( $matches ); $i++ ) {
1361
+ $found = false;
1362
+ for ( $j = 0; $j < count( $excluded_headings ); $j++ ) {
1363
+ if ( @preg_match( '/^' . $excluded_headings[ $j ] . '$/imU', strip_tags( $matches[ $i ][0] ) ) ) {
1364
+ $found = true;
1365
+ break;
1366
+ }
1367
+ }
1368
+ if ( ! $found ) {
1369
+ $new_matches[] = $matches[ $i ];
1370
+ }
1371
+ }
1372
+ if ( count( $matches ) !== count( $new_matches ) ) {
1373
+ $matches = $new_matches;
1374
+ }
1375
+ }
1376
+ }
1377
+
1378
+ // remove empty headings
1379
+ $new_matches = [];
1380
+ for ( $i = 0; $i < count( $matches ); $i++ ) {
1381
+ if ( trim( strip_tags( $matches[ $i ][0] ) ) != false ) {
1382
+ $new_matches[] = $matches[ $i ];
1383
+ }
1384
+ }
1385
+ if ( count( $matches ) !== count( $new_matches ) ) {
1386
+ $matches = $new_matches;
1387
+ }
1388
+
1389
+ // check minimum number of headings
1390
+ if ( count( $matches ) >= $this->options['start'] ) {
1391
+
1392
+ for ( $i = 0; $i < count( $matches ); $i++ ) {
1393
+ // get anchor and add to find and replace arrays
1394
+ $anchor = $this->url_anchor_target( $matches[ $i ][0] );
1395
+ $find[] = $matches[ $i ][0];
1396
+ $replace[] = str_replace(
1397
+ [
1398
+ $matches[ $i ][1], // start of heading
1399
+ '</h' . $matches[ $i ][2] . '>', // end of heading
1400
+ ],
1401
+ [
1402
+ $matches[ $i ][1] . '<span id="' . $anchor . '">',
1403
+ '</span></h' . $matches[ $i ][2] . '>',
1404
+ ],
1405
+ $matches[ $i ][0]
1406
+ );
1407
+
1408
+ // assemble flat list
1409
+ if ( ! $this->options['show_heirarchy'] ) {
1410
+ $items .= '<li><a href="#' . $anchor . '">';
1411
+ if ( $this->options['ordered_list'] ) {
1412
+ $items .= count( $replace ) . ' ';
1413
+ }
1414
+ $items .= strip_tags( $matches[ $i ][0] ) . '</a></li>';
1415
+ }
1416
+ }
1417
+
1418
+ // build a hierarchical toc?
1419
+ // we could have tested for $items but that var can be quite large in some cases
1420
+ if ( $this->options['show_heirarchy'] ) {
1421
+ $items = $this->build_hierarchy( $matches );
1422
+ }
1423
+ }
1424
+ }
1425
+ }
1426
+
1427
+ return $items;
1428
+ }
1429
+
1430
+
1431
+ /**
1432
+ * Returns true if the table of contents is eligible to be printed, false otherwise.
1433
+ */
1434
+ public function is_eligible( $shortcode_used = false ) {
1435
+ global $post;
1436
+
1437
+ // do not trigger the TOC when displaying an XML/RSS feed
1438
+ if ( is_feed() ) {
1439
+ return false;
1440
+ }
1441
+
1442
+ // if the shortcode was used, this bypasses many of the global options
1443
+ if ( false !== $shortcode_used ) {
1444
+ // shortcode is used, make sure it adheres to the exclude from
1445
+ // homepage option if we're on the homepage
1446
+ if ( ! $this->options['include_homepage'] && is_front_page() ) {
1447
+ return false;
1448
+ } else {
1449
+ return true;
1450
+ }
1451
+ } else {
1452
+ if (
1453
+ ( in_array( get_post_type( $post ), $this->options['auto_insert_post_types'] ) && $this->show_toc && ! is_search() && ! is_archive() && ! is_front_page() ) ||
1454
+ ( $this->options['include_homepage'] && is_front_page() )
1455
+ ) {
1456
+ if ( $this->options['restrict_path'] ) {
1457
+ if ( strpos( $_SERVER['REQUEST_URI'], $this->options['restrict_path'] ) === 0 ) {
1458
+ return true;
1459
+ } else {
1460
+ return false;
1461
+ }
1462
+ } else {
1463
+ return true;
1464
+ }
1465
+ } else {
1466
+ return false;
1467
+ }
1468
+ }
1469
+ }
1470
+
1471
+
1472
+ function the_content( $content ) {
1473
+ global $post;
1474
+ $items = '';
1475
+ $css_classes = '';
1476
+ $anchor = '';
1477
+ $find = [];
1478
+ $replace = [];
1479
+ $custom_toc_position = strpos( $content, '<!--TOC-->' );
1480
+
1481
+ if ( $this->is_eligible( $custom_toc_position ) ) {
1482
+
1483
+ $items = $this->extract_headings( $find, $replace, $content );
1484
+
1485
+ if ( $items ) {
1486
+ // do we display the toc within the content or has the user opted
1487
+ // to only show it in the widget? if so, then we still need to
1488
+ // make the find/replace call to insert the anchors
1489
+ if ( $this->options['show_toc_in_widget_only'] && ( in_array( get_post_type(), $this->options['show_toc_in_widget_only_post_types'] ) ) ) {
1490
+ $content = $this->mb_find_replace( $find, $replace, $content );
1491
+ } else {
1492
+
1493
+ // wrapping css classes
1494
+ switch ( $this->options['wrapping'] ) {
1495
+ case TOC_WRAPPING_LEFT:
1496
+ $css_classes .= ' toc_wrap_left';
1497
+ break;
1498
+
1499
+ case TOC_WRAPPING_RIGHT:
1500
+ $css_classes .= ' toc_wrap_right';
1501
+ break;
1502
+
1503
+ case TOC_WRAPPING_NONE:
1504
+ default:
1505
+ // do nothing
1506
+ }
1507
+
1508
+ // colour themes
1509
+ switch ( $this->options['theme'] ) {
1510
+ case TOC_THEME_LIGHT_BLUE:
1511
+ $css_classes .= ' toc_light_blue';
1512
+ break;
1513
+
1514
+ case TOC_THEME_WHITE:
1515
+ $css_classes .= ' toc_white';
1516
+ break;
1517
+
1518
+ case TOC_THEME_BLACK:
1519
+ $css_classes .= ' toc_black';
1520
+ break;
1521
+
1522
+ case TOC_THEME_TRANSPARENT:
1523
+ $css_classes .= ' toc_transparent';
1524
+ break;
1525
+
1526
+ case TOC_THEME_GREY:
1527
+ default:
1528
+ // do nothing
1529
+ }
1530
+
1531
+ // bullets?
1532
+ if ( $this->options['bullet_spacing'] ) {
1533
+ $css_classes .= ' have_bullets';
1534
+ } else {
1535
+ $css_classes .= ' no_bullets';
1536
+ }
1537
+
1538
+ if ( $this->options['css_container_class'] ) {
1539
+ $css_classes .= ' ' . $this->options['css_container_class'];
1540
+ }
1541
+
1542
+ $css_classes = trim( $css_classes );
1543
+
1544
+ // an empty class="" is invalid markup!
1545
+ if ( ! $css_classes ) {
1546
+ $css_classes = ' ';
1547
+ }
1548
+
1549
+ // add container, toc title and list items
1550
+ $html = '<div id="toc_container" class="' . $css_classes . '">';
1551
+ if ( $this->options['show_heading_text'] ) {
1552
+ $toc_title = htmlentities( $this->options['heading_text'], ENT_COMPAT, 'UTF-8' );
1553
+ if ( false !== strpos( $toc_title, '%PAGE_TITLE%' ) ) {
1554
+ $toc_title = str_replace( '%PAGE_TITLE%', get_the_title(), $toc_title );
1555
+ }
1556
+ if ( false !== strpos( $toc_title, '%PAGE_NAME%' ) ) {
1557
+ $toc_title = str_replace( '%PAGE_NAME%', get_the_title(), $toc_title );
1558
+ }
1559
+ $html .= '<p class="toc_title">' . $toc_title . '</p>';
1560
+ }
1561
+ $html .= '<ul class="toc_list">' . $items . '</ul></div>' . "\n";
1562
+
1563
+ if ( false !== $custom_toc_position ) {
1564
+ $find[] = '<!--TOC-->';
1565
+ $replace[] = $html;
1566
+ $content = $this->mb_find_replace( $find, $replace, $content );
1567
+ } else {
1568
+ if ( count( $find ) > 0 ) {
1569
+ switch ( $this->options['position'] ) {
1570
+ case TOC_POSITION_TOP:
1571
+ $content = $html . $this->mb_find_replace( $find, $replace, $content );
1572
+ break;
1573
+
1574
+ case TOC_POSITION_BOTTOM:
1575
+ $content = $this->mb_find_replace( $find, $replace, $content ) . $html;
1576
+ break;
1577
+
1578
+ case TOC_POSITION_AFTER_FIRST_HEADING:
1579
+ $replace[0] = $replace[0] . $html;
1580
+ $content = $this->mb_find_replace( $find, $replace, $content );
1581
+ break;
1582
+
1583
+ case TOC_POSITION_BEFORE_FIRST_HEADING:
1584
+ default:
1585
+ $replace[0] = $html . $replace[0];
1586
+ $content = $this->mb_find_replace( $find, $replace, $content );
1587
+ }
1588
+ }
1589
+ }
1590
+ }
1591
+ }
1592
+ } else {
1593
+ // remove <!--TOC--> (inserted from shortcode) from content
1594
+ $content = str_replace( '<!--TOC-->', '', $content );
1595
+ }
1596
+
1597
+ return $content;
1598
+ }
1599
+
1600
+ } // end class
1601
+ endif;
1602
+
1603
+
1604
+
1605
+ if ( ! class_exists( 'toc_widget' ) ) :
1606
+ class toc_widget extends WP_Widget {
1607
+
1608
+ function __construct() {
1609
+ $widget_options = [
1610
+ 'classname' => 'toc_widget',
1611
+ 'description' => __( 'Display the table of contents in the sidebar with this widget', 'table-of-contents-plus' ),
1612
+ ];
1613
+ $control_options = [
1614
+ 'width' => 250,
1615
+ 'height' => 350,
1616
+ 'id_base' => 'toc-widget',
1617
+ ];
1618
+ parent::__construct( 'toc-widget', 'TOC+', $widget_options, $control_options );
1619
+ }
1620
+
1621
+
1622
+ /**
1623
+ * Widget output to the public
1624
+ */
1625
+ function widget( $args, $instance ) {
1626
+ global $toc_plus, $wp_query;
1627
+ $items = '';
1628
+ $custom_toc_position = '';
1629
+ $find = [];
1630
+ $replace = [];
1631
+
1632
+ $toc_options = $toc_plus->get_options();
1633
+ $post = get_post( $wp_query->post->ID );
1634
+ $custom_toc_position = strpos( $post->post_content, '[toc]' ); // at this point, shortcodes haven't run yet so we can't search for <!--TOC-->
1635
+
1636
+ if ( $toc_plus->is_eligible( $custom_toc_position ) ) {
1637
+
1638
+ extract( $args );
1639
+
1640
+ $items = $toc_plus->extract_headings( $find, $replace, wptexturize( $post->post_content ) );
1641
+ $title = ( array_key_exists( 'title', $instance ) ) ? apply_filters( 'widget_title', $instance['title'] ) : '';
1642
+ if ( false !== strpos( $title, '%PAGE_TITLE%' ) ) {
1643
+ $title = str_replace( '%PAGE_TITLE%', get_the_title(), $title );
1644
+ }
1645
+ if ( false !== strpos( $title, '%PAGE_NAME%' ) ) {
1646
+ $title = str_replace( '%PAGE_NAME%', get_the_title(), $title );
1647
+ }
1648
+ $hide_inline = $toc_options['show_toc_in_widget_only'];
1649
+
1650
+ $css_classes = '';
1651
+ // bullets?
1652
+ if ( $toc_options['bullet_spacing'] ) {
1653
+ $css_classes .= ' have_bullets';
1654
+ } else {
1655
+ $css_classes .= ' no_bullets';
1656
+ }
1657
+
1658
+ if ( $items ) {
1659
+ // before widget (defined by themes)
1660
+ echo $before_widget;
1661
+
1662
+ // display the widget title if one was input (before and after titles defined by themes)
1663
+ if ( $title ) {
1664
+ echo $before_title . $title . $after_title;
1665
+ }
1666
+
1667
+ // display the list
1668
+ echo '<ul class="toc_widget_list' . $css_classes . '">' . $items . '</ul>';
1669
+
1670
+ // after widget (defined by themes)
1671
+ echo $after_widget;
1672
+ }
1673
+ }
1674
+ }
1675
+
1676
+
1677
+ /**
1678
+ * Update the widget settings
1679
+ */
1680
+ function update( $new_instance, $old_instance ) {
1681
+ global $toc_plus;
1682
+
1683
+ $instance = $old_instance;
1684
+
1685
+ // strip tags for title to remove HTML (important for text inputs)
1686
+ $instance['title'] = strip_tags( trim( $new_instance['title'] ) );
1687
+
1688
+ // no need to strip tags for the following
1689
+ //$instance['hide_inline'] = $new_instance['hide_inline'];
1690
+ $toc_plus->set_show_toc_in_widget_only( $new_instance['hide_inline'] );
1691
+ $toc_plus->set_show_toc_in_widget_only_post_types( (array) $new_instance['show_toc_in_widget_only_post_types'] );
1692
+
1693
+ return $instance;
1694
+ }
1695
+
1696
+
1697
+ /**
1698
+ * Displays the widget settings on the widget panel.
1699
+ */
1700
+ function form( $instance ) {
1701
+ global $toc_plus;
1702
+ $toc_options = $toc_plus->get_options();
1703
+
1704
+ $defaults = [ 'title' => $toc_options['heading_text'] ];
1705
+ $instance = wp_parse_args( (array) $instance, $defaults );
1706
+
1707
+ ?>
1708
+ <p>
1709
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'table-of-contents-plus' ); ?>:</label>
1710
+ <input type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
1711
+ </p>
1712
+
1713
+ <p>
1714
+ <input class="checkbox" type="checkbox" <?php checked( $toc_options['show_toc_in_widget_only'], 1 ); ?> id="<?php echo $this->get_field_id( 'hide_inline' ); ?>" name="<?php echo $this->get_field_name( 'hide_inline' ); ?>" value="1" />
1715
+ <label for="<?php echo $this->get_field_id( 'hide_inline' ); ?>"> <?php _e( 'Show the table of contents only in the sidebar', 'table-of-contents-plus' ); ?></label>
1716
+ </p>
1717
+
1718
+ <div class="show_toc_in_widget_only_post_types" style="margin: 0 0 25px 25px; display: <?php echo ( $toc_options['show_toc_in_widget_only'] == 1 ) ? 'block' : 'none'; ?>;">
1719
+ <p><?php _e( 'For the following content types:', 'table-of-contents-plus' ); ?></p>
1720
+
1721
+ <?php
1722
+ foreach ( get_post_types() as $post_type ) {
1723
+ // make sure the post type isn't on the exclusion list
1724
+ if ( ! in_array( $post_type, $toc_plus->get_exclude_post_types() ) ) {
1725
+ echo '<input type="checkbox" value="' . $post_type . '" id="' . $this->get_field_id( 'show_toc_in_widget_only_post_types_' . $post_type ) . '" name="' . $this->get_field_name( 'show_toc_in_widget_only_post_types' ) . '[]"';
1726
+ if ( in_array( $post_type, $toc_options['show_toc_in_widget_only_post_types'] ) ) {
1727
+ echo ' checked="checked"';
1728
+ }
1729
+ echo ' /><label for="' . $this->get_field_id( 'show_toc_in_widget_only_post_types_' . $post_type ) . '"> ' . $post_type . '</label><br />';
1730
+ }
1731
+ }
1732
+
1733
+ ?></div>
1734
+
1735
+ <script type="text/javascript">
1736
+ jQuery(document).ready(function($) {
1737
+ $('#<?php echo $this->get_field_id( 'hide_inline' ); ?>').click(function() {
1738
+ $(this).parent().siblings('div.show_toc_in_widget_only_post_types').toggle('fast');
1739
+ });
1740
+ });
1741
+ </script>
1742
+ <?php
1743
+ }
1744
+
1745
+ } // end class
1746
+ endif;
1747
+
1748
+
1749
+ /**
1750
+ * Returns a HTML formatted string of the table of contents without the surrounding UL or OL
1751
+ * tags to enable the theme editor to supply their own ID and/or classes to the outer list.
1752
+ *
1753
+ * There are three optional parameters you can feed this function with:
1754
+ *
1755
+ * - $content is the entire content with headings. If blank, will default to the current $post
1756
+ *
1757
+ * - $link is the URL to prefix the anchor with. If provided a string, will use it as the prefix.
1758
+ * If set to true then will try to obtain the permalink from the $post object.
1759
+ *
1760
+ * - $apply_eligibility bool, defaults to false. When set to true, will apply the check to
1761
+ * see if bit of content has the prerequisites needed for a TOC, eg minimum number of headings
1762
+ * enabled post type, etc.
1763
+ */
1764
+ function toc_get_index( $content = '', $prefix_url = '', $apply_eligibility = false ) {
1765
+ global $wp_query, $toc_plus;
1766
+
1767
+ $return = '';
1768
+ $find = [];
1769
+ $replace = [];
1770
+ $proceed = true;
1771
+
1772
+ if ( ! $content ) {
1773
+ $post = get_post( $wp_query->post->ID );
1774
+ $content = wptexturize( $post->post_content );
1775
+ }
1776
+
1777
+ if ( $apply_eligibility ) {
1778
+ if ( ! $toc_plus->is_eligible() ) {
1779
+ $proceed = false;
1780
+ }
1781
+ } else {
1782
+ $toc_plus->set_option( [ 'start' => 0 ] );
1783
+ }
1784
+
1785
+ if ( $proceed ) {
1786
+ $return = $toc_plus->extract_headings( $find, $replace, $content );
1787
+ if ( $prefix_url ) {
1788
+ $return = str_replace( 'href="#', 'href="' . $prefix_url . '#', $return );
1789
+ }
1790
+ }
1791
+
1792
+ return $return;
1793
+ }
phpcs.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <ruleset name="WordPress Coding Standards">
3
+ <description>WordPress Coding Standards</description>
4
+
5
+ <!-- Scan all files in directory -->
6
+ <file>.</file>
7
+
8
+ <!-- Scan only PHP files -->
9
+ <arg name="extensions" value="php"/>
10
+
11
+ <!-- Show progress, show the error codes for each message (source). -->
12
+ <arg value="ps" />
13
+
14
+ <!-- Check up to 8 files simultaneously. -->
15
+ <arg name="parallel" value="8" />
16
+
17
+ <!-- Include the WordPress-Core standard. -->
18
+ <rule ref="WordPress-Core">
19
+ <exclude name="Generic.Arrays.DisallowShortArraySyntax.Found"/>
20
+ <exclude name="WordPress.PHP.DisallowShortTernary.Found"/>
21
+ </rule>
22
+
23
+ <rule ref="Internal.NoCodeFound">
24
+ <severity>0</severity>
25
+ </rule>
26
+ </ruleset>
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: conjur3r
3
  Tags: table of contents, indexes, toc, sitemap, cms, options, list, page listing, category listing
4
  Requires at least: 3.2
5
- Tested up to: 5.3
6
- Stable tag: 2002
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -99,6 +99,13 @@ I will never ask for any form of reward or compensation. Helping others achieve
99
 
100
 
101
  == Changelog ==
 
 
 
 
 
 
 
102
  = 2002 =
103
  * Released: 9 February 2020
104
  * Fixed encoding when using %PAGE_TITLE% or %PAGE_NAME%
2
  Contributors: conjur3r
3
  Tags: table of contents, indexes, toc, sitemap, cms, options, list, page listing, category listing
4
  Requires at least: 3.2
5
+ Tested up to: 5.7
6
+ Stable tag: 2106
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
99
 
100
 
101
  == Changelog ==
102
+ = 2106 =
103
+ * Released: 23 June 2021
104
+ * Add compatibility with Rank Math SEO
105
+ * Bump tested WordPress version to 5.7
106
+ * Add PHP coding style
107
+ * Adhere to majority of coding tips
108
+
109
  = 2002 =
110
  * Released: 9 February 2020
111
  * Fixed encoding when using %PAGE_TITLE% or %PAGE_NAME%
toc.php CHANGED
@@ -1,1763 +1,38 @@
1
- <?php
2
- /*
3
- Plugin Name: Table of Contents Plus
4
- Plugin URI: http://dublue.com/plugins/toc/
5
- Description: A powerful yet user friendly plugin that automatically creates a table of contents. Can also output a sitemap listing all pages and categories.
6
- Author: Michael Tran
7
- Author URI: http://dublue.com/
8
- Text Domain: table-of-contents-plus
9
- Domain Path: /languages
10
- Version: 2002
11
- License: GPL2
12
- */
13
-
14
- /* Copyright 2002 Michael Tran (michael@dublue.com)
15
-
16
- This program is free software; you can redistribute it and/or modify
17
- it under the terms of the GNU General Public License, version 2, as
18
- published by the Free Software Foundation.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
- */
29
-
30
- /*
31
- GPL licenced Oxygen icon used for the colour wheel - http://www.iconfinder.com/search/?q=iconset%3Aoxygen
32
- */
33
-
34
- /**
35
- FOR CONSIDERATION:
36
- - back to top links
37
- - sitemap
38
- - easier exclude pages/categories
39
- - support other taxonomies
40
- - advanced options
41
- - highlight target css
42
- */
43
-
44
- define( 'TOC_VERSION', '2002' );
45
- define( 'TOC_POSITION_BEFORE_FIRST_HEADING', 1 );
46
- define( 'TOC_POSITION_TOP', 2 );
47
- define( 'TOC_POSITION_BOTTOM', 3 );
48
- define( 'TOC_POSITION_AFTER_FIRST_HEADING', 4 );
49
- define( 'TOC_MIN_START', 2 );
50
- define( 'TOC_MAX_START', 10 );
51
- define( 'TOC_SMOOTH_SCROLL_OFFSET', 30 );
52
- define( 'TOC_WRAPPING_NONE', 0 );
53
- define( 'TOC_WRAPPING_LEFT', 1 );
54
- define( 'TOC_WRAPPING_RIGHT', 2 );
55
- define( 'TOC_THEME_GREY', 1 );
56
- define( 'TOC_THEME_LIGHT_BLUE', 2 );
57
- define( 'TOC_THEME_WHITE', 3 );
58
- define( 'TOC_THEME_BLACK', 4 );
59
- define( 'TOC_THEME_TRANSPARENT', 99 );
60
- define( 'TOC_THEME_CUSTOM', 100 );
61
- define( 'TOC_DEFAULT_BACKGROUND_COLOUR', '#f9f9f9' );
62
- define( 'TOC_DEFAULT_BORDER_COLOUR', '#aaaaaa' );
63
- define( 'TOC_DEFAULT_TITLE_COLOUR', '#' );
64
- define( 'TOC_DEFAULT_LINKS_COLOUR', '#' );
65
- define( 'TOC_DEFAULT_LINKS_HOVER_COLOUR', '#' );
66
- define( 'TOC_DEFAULT_LINKS_VISITED_COLOUR', '#' );
67
-
68
-
69
- if ( !class_exists( 'toc' ) ) :
70
- class toc {
71
-
72
- private $path; // eg /wp-content/plugins/toc
73
- private $options;
74
- private $show_toc; // allows to override the display (eg through [no_toc] shortcode)
75
- private $exclude_post_types;
76
- private $collision_collector; // keeps a track of used anchors for collision detecting
77
-
78
- function __construct()
79
- {
80
- $this->path = plugins_url( '', __FILE__ );
81
- $this->show_toc = true;
82
- $this->exclude_post_types = array( 'attachment', 'revision', 'nav_menu_item', 'safecss' );
83
- $this->collision_collector = array();
84
-
85
- // get options
86
- $defaults = array( // default options
87
- 'fragment_prefix' => 'i',
88
- 'position' => TOC_POSITION_BEFORE_FIRST_HEADING,
89
- 'start' => 4,
90
- 'show_heading_text' => true,
91
- 'heading_text' => 'Contents',
92
- 'auto_insert_post_types' => array('page'),
93
- 'show_heirarchy' => true,
94
- 'ordered_list' => true,
95
- 'smooth_scroll' => false,
96
- 'smooth_scroll_offset' => TOC_SMOOTH_SCROLL_OFFSET,
97
- 'visibility' => true,
98
- 'visibility_show' => 'show',
99
- 'visibility_hide' => 'hide',
100
- 'visibility_hide_by_default' => false,
101
- 'width' => 'Auto',
102
- 'width_custom' => '275',
103
- 'width_custom_units' => 'px',
104
- 'wrapping' => TOC_WRAPPING_NONE,
105
- 'font_size' => '95',
106
- 'font_size_units' => '%',
107
- 'theme' => TOC_THEME_GREY,
108
- 'custom_background_colour' => TOC_DEFAULT_BACKGROUND_COLOUR,
109
- 'custom_border_colour' => TOC_DEFAULT_BORDER_COLOUR,
110
- 'custom_title_colour' => TOC_DEFAULT_TITLE_COLOUR,
111
- 'custom_links_colour' => TOC_DEFAULT_LINKS_COLOUR,
112
- 'custom_links_hover_colour' => TOC_DEFAULT_LINKS_HOVER_COLOUR,
113
- 'custom_links_visited_colour' => TOC_DEFAULT_LINKS_VISITED_COLOUR,
114
- 'lowercase' => false,
115
- 'hyphenate' => false,
116
- 'bullet_spacing' => false,
117
- 'include_homepage' => false,
118
- 'exclude_css' => false,
119
- 'exclude' => '',
120
- 'heading_levels' => array('1', '2', '3', '4', '5', '6'),
121
- 'restrict_path' => '',
122
- 'css_container_class' => '',
123
- 'sitemap_show_page_listing' => true,
124
- 'sitemap_show_category_listing' => true,
125
- 'sitemap_heading_type' => 3,
126
- 'sitemap_pages' => 'Pages',
127
- 'sitemap_categories' => 'Categories',
128
- 'show_toc_in_widget_only' => false,
129
- 'show_toc_in_widget_only_post_types' => array('page')
130
- );
131
- $options = get_option( 'toc-options', $defaults );
132
- $this->options = wp_parse_args( $options, $defaults );
133
-
134
- add_action( 'plugins_loaded', array(&$this, 'plugins_loaded') );
135
- add_action( 'wp_enqueue_scripts', array(&$this, 'wp_enqueue_scripts') );
136
- add_action( 'wp_head', array(&$this, 'wp_head') );
137
- add_action( 'admin_init', array(&$this, 'admin_init') );
138
- add_action( 'admin_menu', array(&$this, 'admin_menu') );
139
- add_action( 'widgets_init', array(&$this, 'widgets_init') );
140
- add_action( 'sidebar_admin_setup', array(&$this, 'sidebar_admin_setup') );
141
-
142
- add_filter( 'the_content', array(&$this, 'the_content'), 100 ); // run after shortcodes are interpretted (level 10)
143
- add_filter( 'plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 );
144
- add_filter( 'widget_text', 'do_shortcode' );
145
-
146
- add_shortcode( 'toc', array(&$this, 'shortcode_toc') );
147
- add_shortcode( 'no_toc', array(&$this, 'shortcode_no_toc') );
148
- add_shortcode( 'sitemap', array(&$this, 'shortcode_sitemap') );
149
- add_shortcode( 'sitemap_pages', array(&$this, 'shortcode_sitemap_pages') );
150
- add_shortcode( 'sitemap_categories', array(&$this, 'shortcode_sitemap_categories') );
151
- add_shortcode( 'sitemap_posts', array(&$this, 'shortcode_sitemap_posts') );
152
- }
153
-
154
-
155
- function __destruct()
156
- {
157
- }
158
-
159
-
160
- public function get_options()
161
- {
162
- return $this->options;
163
- }
164
-
165
-
166
- public function set_option($array)
167
- {
168
- $this->options = array_merge($this->options, $array);
169
- }
170
-
171
-
172
- /**
173
- * Allows the developer to disable TOC execution
174
- */
175
- public function disable()
176
- {
177
- $this->show_toc = false;
178
- }
179
-
180
-
181
- /**
182
- * Allows the developer to enable TOC execution
183
- */
184
- public function enable()
185
- {
186
- $this->show_toc = true;
187
- }
188
-
189
-
190
- public function set_show_toc_in_widget_only( $value = false )
191
- {
192
- if ( $value )
193
- $this->options['show_toc_in_widget_only'] = true;
194
- else
195
- $this->options['show_toc_in_widget_only'] = false;
196
-
197
- update_option( 'toc-options', $this->options );
198
- }
199
-
200
-
201
- public function set_show_toc_in_widget_only_post_types( $value = false )
202
- {
203
- if ( $value )
204
- $this->options['show_toc_in_widget_only_post_types'] = $value;
205
- else
206
- $this->options['show_toc_in_widget_only_post_types'] = array();
207
-
208
- update_option( 'toc-options', $this->options );
209
- }
210
-
211
-
212
- public function get_exclude_post_types()
213
- {
214
- return $this->exclude_post_types;
215
- }
216
-
217
-
218
- function plugin_action_links( $links, $file )
219
- {
220
- if ( $file == 'table-of-contents-plus/' . basename(__FILE__) ) {
221
- $settings_link = '<a href="options-general.php?page=toc">' . __('Settings', 'table-of-contents-plus') . '</a>';
222
- $links = array_merge( array( $settings_link ), $links );
223
- }
224
- return $links;
225
- }
226
-
227
-
228
- function shortcode_toc( $atts )
229
- {
230
- extract( shortcode_atts( array(
231
- 'label' => $this->options['heading_text'],
232
- 'label_show' => $this->options['visibility_show'],
233
- 'label_hide' => $this->options['visibility_hide'],
234
- 'no_label' => false,
235
- 'class' => false,
236
- 'wrapping' => $this->options['wrapping'],
237
- 'heading_levels' => $this->options['heading_levels'],
238
- 'exclude' => $this->options['exclude'],
239
- 'collapse' => false
240
- ), $atts )
241
- );
242
-
243
- $re_enqueue_scripts = false;
244
-
245
- if ( $no_label ) $this->options['show_heading_text'] = false;
246
- if ( $label ) $this->options['heading_text'] = html_entity_decode( $label );
247
- if ( $label_show ) {
248
- $this->options['visibility_show'] = html_entity_decode( $label_show );
249
- $re_enqueue_scripts = true;
250
- }
251
- if ( $label_hide ) {
252
- $this->options['visibility_hide'] = html_entity_decode( $label_hide );
253
- $re_enqueue_scripts = true;
254
- }
255
- if ( $class ) $this->options['css_container_class'] = $class;
256
- if ( $wrapping ) {
257
- switch ( strtolower(trim($wrapping)) ) {
258
- case 'left':
259
- $this->options['wrapping'] = TOC_WRAPPING_LEFT;
260
- break;
261
-
262
- case 'right':
263
- $this->options['wrapping'] = TOC_WRAPPING_RIGHT;
264
- break;
265
-
266
- default:
267
- // do nothing
268
- }
269
- }
270
-
271
- if ( $exclude ) $this->options['exclude'] = $exclude;
272
- if ( $collapse ) {
273
- $this->options['visibility_hide_by_default'] = true;
274
- $re_enqueue_scripts = true;
275
- }
276
-
277
- if ( $re_enqueue_scripts ) do_action( 'wp_enqueue_scripts' );
278
-
279
- // if $heading_levels is an array, then it came from the global options
280
- // and wasn't provided by per instance
281
- if ( $heading_levels && !is_array($heading_levels) ) {
282
- // make sure they are numbers between 1 and 6 and put into
283
- // the $clean_heading_levels array if not already
284
- $clean_heading_levels = array();
285
- foreach (explode(',', $heading_levels) as $heading_level) {
286
- if ( is_numeric($heading_level) ) {
287
- if ( 1 <= $heading_level && $heading_level <= 6 ) {
288
- if ( !in_array($heading_level, $clean_heading_levels) ) {
289
- $clean_heading_levels[] = $heading_level;
290
- }
291
- }
292
- }
293
- }
294
-
295
- if ( count($clean_heading_levels) > 0 )
296
- $this->options['heading_levels'] = $clean_heading_levels;
297
- }
298
-
299
- if ( !is_search() && !is_archive() && !is_feed() )
300
- return '<!--TOC-->';
301
- else
302
- return;
303
- }
304
-
305
-
306
- function shortcode_no_toc( $atts )
307
- {
308
- $this->show_toc = false;
309
-
310
- return;
311
- }
312
-
313
-
314
- function shortcode_sitemap( $atts )
315
- {
316
- $html = '';
317
-
318
- // only do the following if enabled
319
- if ( $this->options['sitemap_show_page_listing'] || $this->options['sitemap_show_category_listing'] ) {
320
- $html = '<div class="toc_sitemap">';
321
- if ( $this->options['sitemap_show_page_listing'] )
322
- $html .=
323
- '<h' . $this->options['sitemap_heading_type'] . ' class="toc_sitemap_pages">' . htmlentities( $this->options['sitemap_pages'], ENT_COMPAT, 'UTF-8' ) . '</h' . $this->options['sitemap_heading_type'] . '>' .
324
- '<ul class="toc_sitemap_pages_list">' .
325
- wp_list_pages( array('title_li' => '', 'echo' => false ) ) .
326
- '</ul>'
327
- ;
328
- if ( $this->options['sitemap_show_category_listing'] )
329
- $html .=
330
- '<h' . $this->options['sitemap_heading_type'] . ' class="toc_sitemap_categories">' . htmlentities( $this->options['sitemap_categories'], ENT_COMPAT, 'UTF-8' ) . '</h' . $this->options['sitemap_heading_type'] . '>' .
331
- '<ul class="toc_sitemap_categories_list">' .
332
- wp_list_categories( array( 'title_li' => '', 'echo' => false ) ) .
333
- '</ul>'
334
- ;
335
- $html .= '</div>';
336
- }
337
-
338
- return $html;
339
- }
340
-
341
-
342
- function shortcode_sitemap_pages( $atts )
343
- {
344
- extract( shortcode_atts( array(
345
- 'heading' => $this->options['sitemap_heading_type'],
346
- 'label' => htmlentities( $this->options['sitemap_pages'], ENT_COMPAT, 'UTF-8' ),
347
- 'no_label' => false,
348
- 'exclude' => '',
349
- 'exclude_tree' => ''
350
- ), $atts )
351
- );
352
-
353
- if ( $heading < 1 || $heading > 6 ) // h1 to h6 are valid
354
- $heading = $this->options['sitemap_heading_type'];
355
-
356
- $html = '<div class="toc_sitemap">';
357
- if ( !$no_label ) $html .= '<h' . $heading . ' class="toc_sitemap_pages">' . $label . '</h' . $heading . '>';
358
- $html .=
359
- '<ul class="toc_sitemap_pages_list">' .
360
- wp_list_pages( array('title_li' => '', 'echo' => false, 'exclude' => $exclude, 'exclude_tree' => $exclude_tree ) ) .
361
- '</ul>' .
362
- '</div>'
363
- ;
364
-
365
- return $html;
366
- }
367
-
368
-
369
- function shortcode_sitemap_categories( $atts )
370
- {
371
- extract( shortcode_atts( array(
372
- 'heading' => $this->options['sitemap_heading_type'],
373
- 'label' => htmlentities( $this->options['sitemap_categories'], ENT_COMPAT, 'UTF-8' ),
374
- 'no_label' => false,
375
- 'exclude' => '',
376
- 'exclude_tree' => ''
377
- ), $atts )
378
- );
379
-
380
- if ( $heading < 1 || $heading > 6 ) // h1 to h6 are valid
381
- $heading = $this->options['sitemap_heading_type'];
382
-
383
- $html = '<div class="toc_sitemap">';
384
- if ( !$no_label ) $html .= '<h' . $heading . ' class="toc_sitemap_categories">' . $label . '</h' . $heading . '>';
385
- $html .=
386
- '<ul class="toc_sitemap_categories_list">' .
387
- wp_list_categories( array('title_li' => '', 'echo' => false, 'exclude' => $exclude, 'exclude_tree' => $exclude_tree ) ) .
388
- '</ul>' .
389
- '</div>'
390
- ;
391
-
392
- return $html;
393
- }
394
-
395
-
396
- function shortcode_sitemap_posts( $atts )
397
- {
398
- extract( shortcode_atts( array(
399
- 'order' => 'ASC',
400
- 'orderby' => 'title',
401
- 'separate' => true
402
- ), $atts )
403
- );
404
-
405
- $articles = new WP_Query(array(
406
- 'post_type' => 'post',
407
- 'post_status' => 'publish',
408
- 'order' => $order,
409
- 'orderby' => $orderby,
410
- 'posts_per_page' => -1
411
- ));
412
-
413
- $html = $letter = '';
414
-
415
- $separate = strtolower($separate);
416
- if ( $separate == 'false' || $separate == 'no') $separate = false;
417
-
418
- while ( $articles->have_posts() ) {
419
- $articles->the_post();
420
- $title = strip_tags(get_the_title());
421
-
422
- if ( $separate ) {
423
- if ( $letter != strtolower($title[0]) ) {
424
- if ( $letter ) $html .= '</ul></div>';
425
-
426
- $html .= '<div class="toc_sitemap_posts_section"><p class="toc_sitemap_posts_letter">' . strtolower($title[0]) . '</p><ul class="toc_sitemap_posts_list">';
427
- $letter = strtolower($title[0]);
428
- }
429
- }
430
-
431
- $html .= '<li><a href="' . get_permalink($articles->post->ID) . '">' . $title . '</a></li>';
432
- }
433
-
434
- if ( $html ) {
435
- if ( $separate )
436
- $html .= '</div>';
437
- else
438
- $html = '<div class="toc_sitemap_posts_section"><ul class="toc_sitemap_posts_list">' . $html . '</ul></div>';
439
- }
440
-
441
- wp_reset_postdata();
442
-
443
- return $html;
444
- }
445
-
446
-
447
- /**
448
- * Register and load CSS and javascript files for frontend.
449
- */
450
- function wp_enqueue_scripts()
451
- {
452
- $js_vars = array();
453
-
454
- // register our CSS and scripts
455
- wp_register_style( 'toc-screen', $this->path . '/screen.min.css', array(), TOC_VERSION );
456
- wp_register_script( 'toc-front', $this->path . '/front.min.js', array('jquery'), TOC_VERSION, true );
457
-
458
- // enqueue them!
459
- if ( !$this->options['exclude_css'] ) wp_enqueue_style("toc-screen");
460
-
461
- if ( $this->options['smooth_scroll'] ) $js_vars['smooth_scroll'] = true;
462
- wp_enqueue_script( 'toc-front' );
463
- if ( $this->options['show_heading_text'] && $this->options['visibility'] ) {
464
- $width = ( $this->options['width'] != 'User defined' ) ? $this->options['width'] : $this->options['width_custom'] . $this->options['width_custom_units'];
465
- $js_vars['visibility_show'] = esc_js($this->options['visibility_show']);
466
- $js_vars['visibility_hide'] = esc_js($this->options['visibility_hide']);
467
- if ( $this->options['visibility_hide_by_default'] ) $js_vars['visibility_hide_by_default'] = true;
468
- $js_vars['width'] = esc_js($width);
469
- }
470
- if ( $this->options['smooth_scroll_offset'] != TOC_SMOOTH_SCROLL_OFFSET )
471
- $js_vars['smooth_scroll_offset'] = esc_js($this->options['smooth_scroll_offset']);
472
-
473
- if ( count($js_vars) > 0 ) {
474
- wp_localize_script(
475
- 'toc-front',
476
- 'tocplus',
477
- $js_vars
478
- );
479
- }
480
- }
481
-
482
-
483
- function plugins_loaded()
484
- {
485
- load_plugin_textdomain( 'table-of-contents-plus', false, dirname(plugin_basename(__FILE__)) . '/languages/' );
486
- }
487
-
488
-
489
- function admin_init()
490
- {
491
- wp_register_script( 'toc_admin_script', $this->path . '/admin.js' );
492
- wp_register_style( 'toc_admin_style', $this->path . '/admin.css' );
493
- }
494
-
495
-
496
- function admin_menu()
497
- {
498
- $page = add_submenu_page(
499
- 'options-general.php',
500
- __('TOC', 'table-of-contents-plus') . '+',
501
- __('TOC', 'table-of-contents-plus') . '+',
502
- 'manage_options',
503
- 'toc',
504
- array(&$this, 'admin_options')
505
- );
506
-
507
- add_action( 'admin_print_styles-' . $page, array(&$this, 'admin_options_head') );
508
- }
509
-
510
-
511
- function widgets_init()
512
- {
513
- register_widget('toc_widget');
514
- }
515
-
516
-
517
- /**
518
- * Remove widget options on widget deletion
519
- */
520
- function sidebar_admin_setup()
521
- {
522
- // this action is loaded at the start of the widget screen
523
- // so only do the following only when a form action has been initiated
524
- if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) ) {
525
- if ( @$_POST['id_base'] == 'toc-widget' ) {
526
- if ( isset( $_POST['delete_widget'] ) ) {
527
- if ( 1 === (int) $_POST['delete_widget'] ) {
528
- $this->set_show_toc_in_widget_only( false );
529
- $this->set_show_toc_in_widget_only_post_types( array('page') );
530
- }
531
- }
532
- }
533
- }
534
- }
535
-
536
-
537
- /**
538
- * Load needed scripts and styles only on the toc administration interface.
539
- */
540
- function admin_options_head()
541
- {
542
- wp_enqueue_style( 'farbtastic' );
543
- wp_enqueue_script( 'farbtastic' );
544
- wp_enqueue_script( 'jquery' );
545
- wp_enqueue_script( 'toc_admin_script' );
546
- wp_enqueue_style( 'toc_admin_style' );
547
- }
548
-
549
-
550
- /**
551
- * Tries to convert $string into a valid hex colour.
552
- * Returns $default if $string is not a hex value, otherwise returns verified hex.
553
- */
554
- private function hex_value( $string = '', $default = '#' )
555
- {
556
- $return = $default;
557
-
558
- if ( $string ) {
559
- // strip out non hex chars
560
- $return = preg_replace( '/[^a-fA-F0-9]*/', '', $string );
561
-
562
- switch ( strlen($return) ) {
563
- case 3: // do next
564
- case 6:
565
- $return = '#' . $return;
566
- break;
567
-
568
- default:
569
- if ( strlen($return) > 6 )
570
- $return = '#' . substr($return, 0, 6); // if > 6 chars, then take the first 6
571
- elseif ( strlen($return) > 3 && strlen($return) < 6 )
572
- $return = '#' . substr($return, 0, 3); // if between 3 and 6, then take first 3
573
- else
574
- $return = $default; // not valid, return $default
575
- }
576
- }
577
-
578
- return $return;
579
- }
580
-
581
-
582
- private function save_admin_options()
583
- {
584
- global $post_id;
585
-
586
- // security check
587
- if ( !wp_verify_nonce( @$_POST['toc-admin-options'], plugin_basename(__FILE__) ) )
588
- return false;
589
-
590
- // require an administrator level to save
591
- if ( !current_user_can( 'manage_options', $post_id ) )
592
- return false;
593
-
594
- // use stripslashes on free text fields that can have ' " \
595
- // WordPress automatically slashes these characters as part of
596
- // wp-includes/load.php::wp_magic_quotes()
597
-
598
- $custom_background_colour = $this->hex_value( trim($_POST['custom_background_colour']), TOC_DEFAULT_BACKGROUND_COLOUR );
599
- $custom_border_colour = $this->hex_value( trim($_POST['custom_border_colour']), TOC_DEFAULT_BORDER_COLOUR );
600
- $custom_title_colour = $this->hex_value( trim($_POST['custom_title_colour']), TOC_DEFAULT_TITLE_COLOUR );
601
- $custom_links_colour = $this->hex_value( trim($_POST['custom_links_colour']), TOC_DEFAULT_LINKS_COLOUR );
602
- $custom_links_hover_colour = $this->hex_value( trim($_POST['custom_links_hover_colour']), TOC_DEFAULT_LINKS_HOVER_COLOUR );
603
- $custom_links_visited_colour = $this->hex_value( trim($_POST['custom_links_visited_colour']), TOC_DEFAULT_LINKS_VISITED_COLOUR );
604
-
605
- if ( $restrict_path = trim($_POST['restrict_path']) ) {
606
- if ( strpos($restrict_path, '/') !== 0 ) {
607
- // restrict path did not start with a / so unset it
608
- $restrict_path = '';
609
- }
610
- }
611
-
612
- $this->options = array_merge(
613
- $this->options,
614
- array(
615
- 'fragment_prefix' => trim($_POST['fragment_prefix']),
616
- 'position' => intval($_POST['position']),
617
- 'start' => intval($_POST['start']),
618
- 'show_heading_text' => (isset($_POST['show_heading_text']) && $_POST['show_heading_text']) ? true : false,
619
- 'heading_text' => stripslashes( trim($_POST['heading_text']) ),
620
- 'auto_insert_post_types' => @(array)$_POST['auto_insert_post_types'],
621
- 'show_heirarchy' => (isset($_POST['show_heirarchy']) && $_POST['show_heirarchy']) ? true : false,
622
- 'ordered_list' => (isset($_POST['ordered_list']) && $_POST['ordered_list']) ? true : false,
623
- 'smooth_scroll' => (isset($_POST['smooth_scroll']) && $_POST['smooth_scroll']) ? true : false,
624
- 'smooth_scroll_offset' => intval($_POST['smooth_scroll_offset']),
625
- 'visibility' => (isset($_POST['visibility']) && $_POST['visibility']) ? true : false,
626
- 'visibility_show' => stripslashes( trim($_POST['visibility_show']) ),
627
- 'visibility_hide' => stripslashes( trim($_POST['visibility_hide']) ),
628
- 'visibility_hide_by_default' => (isset($_POST['visibility_hide_by_default']) && $_POST['visibility_hide_by_default']) ? true : false,
629
- 'width' => trim($_POST['width']),
630
- 'width_custom' => floatval($_POST['width_custom']),
631
- 'width_custom_units' => trim($_POST['width_custom_units']),
632
- 'wrapping' => intval($_POST['wrapping']),
633
- 'font_size' => floatval($_POST['font_size']),
634
- 'font_size_units' => trim($_POST['font_size_units']),
635
- 'theme' => intval($_POST['theme']),
636
- 'custom_background_colour' => $custom_background_colour,
637
- 'custom_border_colour' => $custom_border_colour,
638
- 'custom_title_colour' => $custom_title_colour,
639
- 'custom_links_colour' => $custom_links_colour,
640
- 'custom_links_hover_colour' => $custom_links_hover_colour,
641
- 'custom_links_visited_colour' => $custom_links_visited_colour,
642
- 'lowercase' => (isset($_POST['lowercase']) && $_POST['lowercase']) ? true : false,
643
- 'hyphenate' => (isset($_POST['hyphenate']) && $_POST['hyphenate']) ? true : false,
644
- 'bullet_spacing' => (isset($_POST['bullet_spacing']) && $_POST['bullet_spacing']) ? true : false,
645
- 'include_homepage' => (isset($_POST['include_homepage']) && $_POST['include_homepage']) ? true : false,
646
- 'exclude_css' => (isset($_POST['exclude_css']) && $_POST['exclude_css']) ? true : false,
647
- 'heading_levels' => @(array)$_POST['heading_levels'],
648
- 'exclude' => stripslashes( trim($_POST['exclude']) ),
649
- 'restrict_path' => $restrict_path,
650
- 'sitemap_show_page_listing' => (isset($_POST['sitemap_show_page_listing']) && $_POST['sitemap_show_page_listing']) ? true : false,
651
- 'sitemap_show_category_listing' => (isset($_POST['sitemap_show_category_listing']) && $_POST['sitemap_show_category_listing']) ? true : false,
652
- 'sitemap_heading_type' => intval($_POST['sitemap_heading_type']),
653
- 'sitemap_pages' => stripslashes( trim($_POST['sitemap_pages']) ),
654
- 'sitemap_categories' => stripslashes( trim($_POST['sitemap_categories']) )
655
- )
656
- );
657
-
658
- // update_option will return false if no changes were made
659
- update_option( 'toc-options', $this->options );
660
-
661
- return true;
662
- }
663
-
664
-
665
- function admin_options()
666
- {
667
- $msg = '';
668
-
669
- if ( isset( $_GET['update'] ) ) {
670
- if ( $this->save_admin_options() )
671
- $msg = '<div id="message" class="updated fade"><p>' . __('Options saved.', 'table-of-contents-plus') . '</p></div>';
672
- else
673
- $msg = '<div id="message" class="error fade"><p>' . __('Save failed.', 'table-of-contents-plus') . '</p></div>';
674
- }
675
-
676
- ?>
677
- <div id='toc' class='wrap'>
678
- <div id="icon-options-general" class="icon32"><br /></div>
679
- <h2>Table of Contents Plus</h2>
680
- <?php echo $msg; ?>
681
- <form method="post" action="<?php echo htmlentities('?page=' . $_GET['page'] . '&update'); ?>">
682
- <?php wp_nonce_field( plugin_basename(__FILE__), 'toc-admin-options' ); ?>
683
-
684
- <ul id="tabbed-nav">
685
- <li><a href="#tab1"><?php _e('Main Options', 'table-of-contents-plus'); ?></a></li>
686
- <li><a href="#tab2"><?php _e('Sitemap', 'table-of-contents-plus'); ?></a></li>
687
- <li class="url"><a href="http://dublue.com/plugins/toc/#Help"><?php _e('Help', 'table-of-contents-plus'); ?></a></li>
688
- </ul>
689
- <div class="tab_container">
690
- <div id="tab1" class="tab_content">
691
-
692
- <table class="form-table">
693
- <tbody>
694
- <tr>
695
- <th><label for="position"><?php _e('Position', 'table-of-contents-plus'); ?></label></th>
696
- <td>
697
- <select name="position" id="position">
698
- <option value="<?php echo TOC_POSITION_BEFORE_FIRST_HEADING; ?>"<?php if ( TOC_POSITION_BEFORE_FIRST_HEADING == $this->options['position'] ) echo ' selected="selected"'; ?>><?php _e('Before first heading (default)', 'table-of-contents-plus'); ?></option>
699
- <option value="<?php echo TOC_POSITION_AFTER_FIRST_HEADING; ?>"<?php if ( TOC_POSITION_AFTER_FIRST_HEADING == $this->options['position'] ) echo ' selected="selected"'; ?>><?php _e('After first heading', 'table-of-contents-plus'); ?></option>
700
- <option value="<?php echo TOC_POSITION_TOP; ?>"<?php if ( TOC_POSITION_TOP == $this->options['position'] ) echo ' selected="selected"'; ?>><?php _e('Top', 'table-of-contents-plus'); ?></option>
701
- <option value="<?php echo TOC_POSITION_BOTTOM; ?>"<?php if ( TOC_POSITION_BOTTOM == $this->options['position'] ) echo ' selected="selected"'; ?>><?php _e('Bottom', 'table-of-contents-plus'); ?></option>
702
- </select>
703
- </td>
704
- </tr>
705
- <tr>
706
- <th><label for="start"><?php _e('Show when', 'table-of-contents-plus'); ?></label></th>
707
- <td>
708
- <select name="start" id="start">
709
- <?php
710
- for ($i = TOC_MIN_START; $i <= TOC_MAX_START; $i++) {
711
- echo '<option value="' . $i . '"';
712
- if ( $i == $this->options['start'] ) echo ' selected="selected"';
713
- echo '>' . $i . '</option>' . "\n";
714
- }
715
- ?>
716
- </select> <?php
717
- /* translators: text follows drop down list of numbers */
718
- _e('or more headings are present', 'table-of-contents-plus'); ?>
719
- </td>
720
- </tr>
721
- <tr>
722
- <th><?php _e('Auto insert for the following content types', 'table-of-contents-plus'); ?></th>
723
- <td><?php
724
- foreach (get_post_types() as $post_type) {
725
- // make sure the post type isn't on the exclusion list
726
- if ( !in_array($post_type, $this->exclude_post_types) ) {
727
- echo '<input type="checkbox" value="' . $post_type . '" id="auto_insert_post_types_' . $post_type .'" name="auto_insert_post_types[]"';
728
- if ( in_array($post_type, $this->options['auto_insert_post_types']) ) echo ' checked="checked"';
729
- echo ' /><label for="auto_insert_post_types_' . $post_type .'"> ' . $post_type . '</label><br />';
730
- }
731
- }
732
- ?>
733
- </tr>
734
- <tr>
735
- <th><label for="show_heading_text"><?php
736
- /* translators: this is the title of the table of contents */
737
- _e('Heading text', 'table-of-contents-plus'); ?></label></th>
738
- <td>
739
- <input type="checkbox" value="1" id="show_heading_text" name="show_heading_text"<?php if ( $this->options['show_heading_text'] ) echo ' checked="checked"'; ?> /><label for="show_heading_text"> <?php _e('Show title on top of the table of contents', 'table-of-contents-plus'); ?></label><br />
740
- <div class="more_toc_options<?php if ( !$this->options['show_heading_text'] ) echo ' disabled'; ?>">
741
- <input type="text" class="regular-text" value="<?php echo htmlentities( $this->options['heading_text'], ENT_COMPAT, 'UTF-8' ); ?>" id="heading_text" name="heading_text" />
742
- <span class="description"><label for="heading_text"><?php _e('Eg: Contents, Table of Contents, Page Contents', 'table-of-contents-plus'); ?></label></span><br /><br />
743
-
744
- <input type="checkbox" value="1" id="visibility" name="visibility"<?php if ( $this->options['visibility'] ) echo ' checked="checked"'; ?> /><label for="visibility"> <?php _e( 'Allow the user to toggle the visibility of the table of contents', 'table-of-contents-plus'); ?></label><br />
745
- <div class="more_toc_options<?php if ( !$this->options['visibility'] ) echo ' disabled'; ?>">
746
- <table class="more_toc_options_table">
747
- <tbody>
748
- <tr>
749
- <th><label for="visibility_show"><?php _e('Show text', 'table-of-contents-plus'); ?></label></th>
750
- <td><input type="text" class="" value="<?php echo htmlentities( $this->options['visibility_show'], ENT_COMPAT, 'UTF-8' ); ?>" id="visibility_show" name="visibility_show" />
751
- <span class="description"><label for="visibility_show"><?php
752
- /* translators: example text to display when you want to expand the table of contents */
753
- _e('Eg: show', 'table-of-contents-plus'); ?></label></span></td>
754
- </tr>
755
- <tr>
756
- <th><label for="visibility_hide"><?php _e('Hide text', 'table-of-contents-plus'); ?></label></th>
757
- <td><input type="text" class="" value="<?php echo htmlentities( $this->options['visibility_hide'], ENT_COMPAT, 'UTF-8' ); ?>" id="visibility_hide" name="visibility_hide" />
758
- <span class="description"><label for="visibility_hide"><?php
759
- /* translators: example text to display when you want to collapse the table of contents */
760
- _e('Eg: hide', 'table-of-contents-plus'); ?></label></span></td>
761
- </tr>
762
- </tbody>
763
- </table>
764
- <input type="checkbox" value="1" id="visibility_hide_by_default" name="visibility_hide_by_default"<?php if ( $this->options['visibility_hide_by_default'] ) echo ' checked="checked"'; ?> /><label for="visibility_hide_by_default"> <?php _e( 'Hide the table of contents initially', 'table-of-contents-plus'); ?></label>
765
- </div>
766
- </div>
767
- </td>
768
- </tr>
769
- <tr>
770
- <th><label for="show_heirarchy"><?php _e('Show hierarchy', 'table-of-contents-plus'); ?></label></th>
771
- <td><input type="checkbox" value="1" id="show_heirarchy" name="show_heirarchy"<?php if ( $this->options['show_heirarchy'] ) echo ' checked="checked"'; ?> /></td>
772
- </tr>
773
- <tr>
774
- <th><label for="ordered_list"><?php _e('Number list items', 'table-of-contents-plus'); ?></label></th>
775
- <td><input type="checkbox" value="1" id="ordered_list" name="ordered_list"<?php if ( $this->options['ordered_list'] ) echo ' checked="checked"'; ?> /></td>
776
- </tr>
777
- <tr>
778
- <th><label for="smooth_scroll"><?php _e('Enable smooth scroll effect', 'table-of-contents-plus'); ?></label></th>
779
- <td><input type="checkbox" value="1" id="smooth_scroll" name="smooth_scroll"<?php if ( $this->options['smooth_scroll'] ) echo ' checked="checked"'; ?> /><label for="smooth_scroll"> <?php _e( 'Scroll rather than jump to the anchor link', 'table-of-contents-plus'); ?></label></td>
780
- </tr>
781
- </tbody>
782
- </table>
783
-
784
- <h3><?php _e('Appearance', 'table-of-contents-plus'); ?></h3>
785
- <table class="form-table">
786
- <tbody>
787
- <tr>
788
- <th><label for="width"><?php _e('Width', 'table-of-contents-plus'); ?></label></td>
789
- <td>
790
- <select name="width" id="width">
791
- <optgroup label="<?php _e('Fixed width', 'table-of-contents-plus'); ?>">
792
- <option value="200px"<?php if ( '200px' == $this->options['width'] ) echo ' selected="selected"'; ?>>200px</option>
793
- <option value="225px"<?php if ( '225px' == $this->options['width'] ) echo ' selected="selected"'; ?>>225px</option>
794
- <option value="250px"<?php if ( '250px' == $this->options['width'] ) echo ' selected="selected"'; ?>>250px</option>
795
- <option value="275px"<?php if ( '275px' == $this->options['width'] ) echo ' selected="selected"'; ?>>275px</option>
796
- <option value="300px"<?php if ( '300px' == $this->options['width'] ) echo ' selected="selected"'; ?>>300px</option>
797
- <option value="325px"<?php if ( '325px' == $this->options['width'] ) echo ' selected="selected"'; ?>>325px</option>
798
- <option value="350px"<?php if ( '350px' == $this->options['width'] ) echo ' selected="selected"'; ?>>350px</option>
799
- <option value="375px"<?php if ( '375px' == $this->options['width'] ) echo ' selected="selected"'; ?>>375px</option>
800
- <option value="400px"<?php if ( '400px' == $this->options['width'] ) echo ' selected="selected"'; ?>>400px</option>
801
- </optgroup>
802
- <optgroup label="<?php _e('Relative', 'table-of-contents-plus'); ?>">
803
- <option value="Auto"<?php if ( 'Auto' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('Auto (default)', 'table-of-contents-plus'); ?></option>
804
- <option value="25%"<?php if ( '25%' == $this->options['width'] ) echo ' selected="selected"'; ?>>25%</option>
805
- <option value="33%"<?php if ( '33%' == $this->options['width'] ) echo ' selected="selected"'; ?>>33%</option>
806
- <option value="50%"<?php if ( '50%' == $this->options['width'] ) echo ' selected="selected"'; ?>>50%</option>
807
- <option value="66%"<?php if ( '66%' == $this->options['width'] ) echo ' selected="selected"'; ?>>66%</option>
808
- <option value="75%"<?php if ( '75%' == $this->options['width'] ) echo ' selected="selected"'; ?>>75%</option>
809
- <option value="100%"<?php if ( '100%' == $this->options['width'] ) echo ' selected="selected"'; ?>>100%</option>
810
- </optgroup>
811
- <optgroup label="<?php
812
- /* translators: other width */
813
- _e('Other', 'table-of-contents-plus'); ?>">
814
- <option value="User defined"<?php if ( 'User defined' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('User defined', 'table-of-contents-plus'); ?></option>
815
- </optgroup>
816
- </select>
817
- <div class="more_toc_options<?php if ( 'User defined' != $this->options['width'] ) echo ' disabled'; ?>">
818
- <label for="width_custom"><?php
819
- /* translators: ignore %s as it's some HTML label tags */
820
- printf( __('Please enter a number and %s select its units, eg: 100px, 10em', 'table-of-contents-plus'), '</label><label for="width_custom_units">' ); ?></label><br />
821
- <input type="text" class="regular-text" value="<?php echo floatval($this->options['width_custom']); ?>" id="width_custom" name="width_custom" />
822
- <select name="width_custom_units" id="width_custom_units">
823
- <option value="px"<?php if ( 'px' == $this->options['width_custom_units'] ) echo ' selected="selected"'; ?>>px</option>
824
- <option value="%"<?php if ( '%' == $this->options['width_custom_units'] ) echo ' selected="selected"'; ?>>%</option>
825
- <option value="em"<?php if ( 'em' == $this->options['width_custom_units'] ) echo ' selected="selected"'; ?>>em</option>
826
- </select>
827
- </div>
828
- </td>
829
- </tr>
830
- <tr>
831
- <th><label for="wrapping"><?php _e('Wrapping', 'table-of-contents-plus'); ?></label></td>
832
- <td>
833
- <select name="wrapping" id="wrapping">
834
- <option value="<?php echo TOC_WRAPPING_NONE; ?>"<?php if ( TOC_WRAPPING_NONE == $this->options['wrapping'] ) echo ' selected="selected"'; ?>><?php _e('None (default)', 'table-of-contents-plus'); ?></option>
835
- <option value="<?php echo TOC_WRAPPING_LEFT; ?>"<?php if ( TOC_WRAPPING_LEFT == $this->options['wrapping'] ) echo ' selected="selected"'; ?>><?php _e('Left', 'table-of-contents-plus'); ?></option>
836
- <option value="<?php echo TOC_WRAPPING_RIGHT; ?>"<?php if ( TOC_WRAPPING_RIGHT == $this->options['wrapping'] ) echo ' selected="selected"'; ?>><?php _e('Right', 'table-of-contents-plus'); ?></option>
837
- </select>
838
- </td>
839
- </tr>
840
- <tr>
841
- <th><label for="font_size"><?php _e('Font size', 'table-of-contents-plus'); ?></label></th>
842
- <td>
843
- <input type="text" class="regular-text" value="<?php echo floatval($this->options['font_size']); ?>" id="font_size" name="font_size" />
844
- <select name="font_size_units" id="font_size_units">
845
- <option value="px"<?php if ( 'pt' == $this->options['font_size_units'] ) echo ' selected="selected"'; ?>>pt</option>
846
- <option value="%"<?php if ( '%' == $this->options['font_size_units'] ) echo ' selected="selected"'; ?>>%</option>
847
- <option value="em"<?php if ( 'em' == $this->options['font_size_units'] ) echo ' selected="selected"'; ?>>em</option>
848
- </select>
849
- </td>
850
- </tr>
851
- <tr>
852
- <th><?php
853
- /* translators: appearance / colour / look and feel options */
854
- _e('Presentation', 'table-of-contents-plus'); ?></th>
855
- <td>
856
- <div class="toc_theme_option">
857
- <input type="radio" name="theme" id="theme_<?php echo TOC_THEME_GREY; ?>" value="<?php echo TOC_THEME_GREY; ?>"<?php if ( $this->options['theme'] == TOC_THEME_GREY ) echo ' checked="checked"'; ?> /><label for="theme_<?php echo TOC_THEME_GREY; ?>"> <?php _e('Grey (default)', 'table-of-contents-plus'); ?><br />
858
- <img src="<?php echo $this->path; ?>/images/grey.png" alt="" />
859
- </label>
860
- </div>
861
- <div class="toc_theme_option">
862
- <input type="radio" name="theme" id="theme_<?php echo TOC_THEME_LIGHT_BLUE; ?>" value="<?php echo TOC_THEME_LIGHT_BLUE; ?>"<?php if ( $this->options['theme'] == TOC_THEME_LIGHT_BLUE ) echo ' checked="checked"'; ?> /><label for="theme_<?php echo TOC_THEME_LIGHT_BLUE; ?>"> <?php _e('Light blue', 'table-of-contents-plus'); ?><br />
863
- <img src="<?php echo $this->path; ?>/images/blue.png" alt="" />
864
- </label>
865
- </div>
866
- <div class="toc_theme_option">
867
- <input type="radio" name="theme" id="theme_<?php echo TOC_THEME_WHITE; ?>" value="<?php echo TOC_THEME_WHITE; ?>"<?php if ( $this->options['theme'] == TOC_THEME_WHITE ) echo ' checked="checked"'; ?> /><label for="theme_<?php echo TOC_THEME_WHITE; ?>"> <?php _e('White', 'table-of-contents-plus'); ?><br />
868
- <img src="<?php echo $this->path; ?>/images/white.png" alt="" />
869
- </label>
870
- </div>
871
- <div class="toc_theme_option">
872
- <input type="radio" name="theme" id="theme_<?php echo TOC_THEME_BLACK; ?>" value="<?php echo TOC_THEME_BLACK; ?>"<?php if ( $this->options['theme'] == TOC_THEME_BLACK ) echo ' checked="checked"'; ?> /><label for="theme_<?php echo TOC_THEME_BLACK; ?>"> <?php _e('Black', 'table-of-contents-plus'); ?><br />
873
- <img src="<?php echo $this->path; ?>/images/black.png" alt="" />
874
- </label>
875
- </div>
876
- <div class="toc_theme_option">
877
- <input type="radio" name="theme" id="theme_<?php echo TOC_THEME_TRANSPARENT; ?>" value="<?php echo TOC_THEME_TRANSPARENT; ?>"<?php if ( $this->options['theme'] == TOC_THEME_TRANSPARENT ) echo ' checked="checked"'; ?> /><label for="theme_<?php echo TOC_THEME_TRANSPARENT; ?>"> <?php _e('Transparent', 'table-of-contents-plus'); ?><br />
878
- <img src="<?php echo $this->path; ?>/images/transparent.png" alt="" />
879
- </label>
880
- </div>
881
- <div class="toc_theme_option">
882
- <input type="radio" name="theme" id="theme_<?php echo TOC_THEME_CUSTOM; ?>" value="<?php echo TOC_THEME_CUSTOM; ?>"<?php if ( $this->options['theme'] == TOC_THEME_CUSTOM ) echo ' checked="checked"'; ?> /><label for="theme_<?php echo TOC_THEME_CUSTOM; ?>"> <?php _e('Custom', 'table-of-contents-plus'); ?><br />
883
- <img src="<?php echo $this->path; ?>/images/custom.png" alt="" />
884
- </label>
885
- </div>
886
- <div class="clear"></div>
887
-
888
- <div class="more_toc_options<?php if ( TOC_THEME_CUSTOM != $this->options['theme'] ) echo ' disabled'; ?>">
889
- <table id="theme_custom" class="more_toc_options_table">
890
- <tbody>
891
- <tr>
892
- <th><label for="custom_background_colour"><?php _e('Background', 'table-of-contents-plus'); ?></label></th>
893
- <td><input type="text" class="custom_colour_option" value="<?php echo htmlentities( $this->options['custom_background_colour'] ); ?>" id="custom_background_colour" name="custom_background_colour" /> <img src="<?php echo $this->path; ?>/images/colour-wheel.png" alt="" /></td>
894
- </tr>
895
- <tr>
896
- <th><label for="custom_border_colour"><?php _e('Border', 'table-of-contents-plus'); ?></label></th>
897
- <td><input type="text" class="custom_colour_option" value="<?php echo htmlentities( $this->options['custom_border_colour'] ); ?>" id="custom_border_colour" name="custom_border_colour" /> <img src="<?php echo $this->path; ?>/images/colour-wheel.png" alt="" /></td>
898
- </tr>
899
- <tr>
900
- <th><label for="custom_title_colour"><?php _e('Title', 'table-of-contents-plus'); ?></label></th>
901
- <td><input type="text" class="custom_colour_option" value="<?php echo htmlentities( $this->options['custom_title_colour'] ); ?>" id="custom_title_colour" name="custom_title_colour" /> <img src="<?php echo $this->path; ?>/images/colour-wheel.png" alt="" /></td>
902
- </tr>
903
- <tr>
904
- <th><label for="custom_links_colour"><?php _e('Links', 'table-of-contents-plus'); ?></label></th>
905
- <td><input type="text" class="custom_colour_option" value="<?php echo htmlentities( $this->options['custom_links_colour'] ); ?>" id="custom_links_colour" name="custom_links_colour" /> <img src="<?php echo $this->path; ?>/images/colour-wheel.png" alt="" /></td>
906
- </tr>
907
- <tr>
908
- <th><label for="custom_links_hover_colour"><?php _e('Links (hover)', 'table-of-contents-plus'); ?></label></th>
909
- <td><input type="text" class="custom_colour_option" value="<?php echo htmlentities( $this->options['custom_links_hover_colour'] ); ?>" id="custom_links_hover_colour" name="custom_links_hover_colour" /> <img src="<?php echo $this->path; ?>/images/colour-wheel.png" alt="" /></td>
910
- </tr>
911
- <tr>
912
- <th><label for="custom_links_visited_colour"><?php _e('Links (visited)', 'table-of-contents-plus'); ?></label></th>
913
- <td><input type="text" class="custom_colour_option" value="<?php echo htmlentities( $this->options['custom_links_visited_colour'] ); ?>" id="custom_links_visited_colour" name="custom_links_visited_colour" /> <img src="<?php echo $this->path; ?>/images/colour-wheel.png" alt="" /></td>
914
- </tr>
915
- </tbody>
916
- </table>
917
- <div id="farbtastic_colour_wheel"></div>
918
- <div class="clear"></div>
919
- <p><?php printf(__("Leaving the value as %s will inherit your theme's styles", 'table-of-contents-plus'), '<code>#</code>'); ?></p>
920
- </div>
921
- </td>
922
- </tr>
923
- </tbody>
924
- </table>
925
-
926
- <h3><?php _e('Advanced', 'table-of-contents-plus'); ?> <span class="show_hide">(<a href="#toc_advanced_usage"><?php _e('show', 'table-of-contents-plus'); ?></a>)</span></h3>
927
- <div id="toc_advanced_usage">
928
- <h4><?php _e('Power options', 'table-of-contents-plus'); ?></h4>
929
- <table class="form-table">
930
- <tbody>
931
- <tr>
932
- <th><label for="lowercase"><?php _e('Lowercase', 'table-of-contents-plus'); ?></label></th>
933
- <td><input type="checkbox" value="1" id="lowercase" name="lowercase"<?php if ( $this->options['lowercase'] ) echo ' checked="checked"'; ?> /><label for="lowercase"> <?php _e('Ensure anchors are in lowercase', 'table-of-contents-plus'); ?></label></td>
934
- </tr>
935
- <tr>
936
- <th><label for="hyphenate"><?php _e('Hyphenate', 'table-of-contents-plus'); ?></label></th>
937
- <td><input type="checkbox" value="1" id="hyphenate" name="hyphenate"<?php if ( $this->options['hyphenate'] ) echo ' checked="checked"'; ?> /><label for="hyphenate"> <?php _e('Use - rather than _ in anchors', 'table-of-contents-plus'); ?></label></td>
938
- </tr>
939
- <tr>
940
- <th><label for="include_homepage"><?php _e('Include homepage', 'table-of-contents-plus'); ?></label></th>
941
- <td><input type="checkbox" value="1" id="include_homepage" name="include_homepage"<?php if ( $this->options['include_homepage'] ) echo ' checked="checked"'; ?> /><label for="include_homepage"> <?php _e('Show the table of contents for qualifying items on the homepage', 'table-of-contents-plus'); ?></label></td>
942
- </tr>
943
- <tr>
944
- <th><label for="exclude_css"><?php _e('Exclude CSS file', 'table-of-contents-plus'); ?></label></th>
945
- <td><input type="checkbox" value="1" id="exclude_css" name="exclude_css"<?php if ( $this->options['exclude_css'] ) echo ' checked="checked"'; ?> /><label for="exclude_css"> <?php _e("Prevent the loading of this plugin's CSS styles. When selected, the appearance options from above will also be ignored.", 'table-of-contents-plus'); ?></label></td>
946
- </tr>
947
- <tr>
948
- <th><label for="bullet_spacing"><?php _e('Preserve theme bullets', 'table-of-contents-plus'); ?></label></th>
949
- <td><input type="checkbox" value="1" id="bullet_spacing" name="bullet_spacing"<?php if ( $this->options['bullet_spacing'] ) echo ' checked="checked"'; ?> /><label for="bullet_spacing"> <?php _e('If your theme includes background images for unordered list elements, enable this to support them', 'table-of-contents-plus'); ?></label></td>
950
- </tr>
951
- <tr>
952
- <th><?php _e('Heading levels', 'table-of-contents-plus'); ?></th>
953
- <td>
954
- <p><?php _e('Include the following heading levels. Deselecting a heading will exclude it.', 'table-of-contents-plus'); ?></p>
955
- <?php
956
- // show heading 1 to 6 options
957
- for ($i = 1; $i <= 6; $i++) {
958
- echo '<input type="checkbox" value="' . $i . '" id="heading_levels' . $i .'" name="heading_levels[]"';
959
- if ( in_array($i, $this->options['heading_levels']) ) echo ' checked="checked"';
960
- echo ' /><label for="heading_levels' . $i .'"> ' . __('heading ') . $i . ' - h' . $i . '</label><br />';
961
- }
962
- ?>
963
- </td>
964
- </tr>
965
- <tr>
966
- <th><label for="exclude"><?php _e('Exclude headings', 'table-of-contents-plus'); ?></label></th>
967
- <td>
968
- <input type="text" class="regular-text" value="<?php echo htmlentities( $this->options['exclude'], ENT_COMPAT, 'UTF-8' ); ?>" id="exclude" name="exclude" style="width: 100%;" /><br />
969
- <label for="exclude"><?php _e('Specify headings to be excluded from appearing in the table of contents. Separate multiple headings with a pipe <code>|</code>. Use an asterisk <code>*</code> as a wildcard to match other text. Note that this is not case sensitive. Some examples:', 'table-of-contents-plus'); ?></label><br/>
970
- <ul>
971
- <li><?php _e('<code>Fruit*</code> ignore headings starting with "Fruit"', 'table-of-contents-plus'); ?></li>
972
- <li><?php _e('<code>*Fruit Diet*</code> ignore headings with "Fruit Diet" somewhere in the heading', 'table-of-contents-plus'); ?></li>
973
- <li><?php _e('<code>Apple Tree|Oranges|Yellow Bananas</code> ignore headings that are exactly "Apple Tree", "Oranges" or "Yellow Bananas"', 'table-of-contents-plus'); ?></li>
974
- </ul>
975
- </td>
976
- </tr>
977
- <tr id="smooth_scroll_offset_tr" class="<?php if ( !$this->options['smooth_scroll'] ) echo 'disabled'; ?>">
978
- <th><label for="smooth_scroll_offset"><?php _e('Smooth scroll top offset', 'table-of-contents-plus'); ?></label></th>
979
- <td>
980
- <input type="text" class="regular-text" value="<?php echo intval($this->options['smooth_scroll_offset']); ?>" id="smooth_scroll_offset" name="smooth_scroll_offset" /> px<br />
981
- <label for="smooth_scroll_offset"><?php _e('If you have a consistent menu across the top of your site, you can adjust the top offset to stop the headings from appearing underneath the top menu. A setting of 30 accommodates the WordPress admin bar. This setting appears after you have enabled smooth scrolling from above.', 'table-of-contents-plus'); ?></label>
982
- </td>
983
- </tr>
984
- <tr>
985
- <th><label for="restrict_path"><?php _e('Restrict path', 'table-of-contents-plus'); ?></label></th>
986
- <td>
987
- <input type="text" class="regular-text" value="<?php echo htmlentities( $this->options['restrict_path'], ENT_COMPAT, 'UTF-8' ); ?>" id="restrict_path" name="restrict_path" /><br />
988
- <label for="restrict_path"><?php _e('Restrict generation of the table of contents to pages that match the required path. This path is from the root of your site and always begins with a forward slash.', 'table-of-contents-plus'); ?><br />
989
- <span class="description"><?php
990
- /* translators: example URL path restriction */
991
- _e('Eg: /wiki/, /corporate/annual-reports/', 'table-of-contents-plus'); ?></span></label>
992
- </td>
993
- </tr>
994
- <tr>
995
- <th><label for="fragment_prefix"><?php _e('Default anchor prefix', 'table-of-contents-plus'); ?></label></th>
996
- <td>
997
- <input type="text" class="regular-text" value="<?php echo htmlentities( $this->options['fragment_prefix'], ENT_COMPAT, 'UTF-8' ); ?>" id="fragment_prefix" name="fragment_prefix" /><br />
998
- <label for="fragment_prefix"><?php _e('Anchor targets are restricted to alphanumeric characters as per HTML specification (see readme for more detail). The default anchor prefix will be used when no characters qualify. When left blank, a number will be used instead.', 'table-of-contents-plus'); ?><br />
999
- <?php _e('This option normally applies to content written in character sets other than ASCII.', 'table-of-contents-plus'); ?><br />
1000
- <span class="description"><?php
1001
- /* translators: example anchor prefixes when no ascii characters match */
1002
- _e('Eg: i, toc_index, index, _', 'table-of-contents-plus'); ?></span></label>
1003
- </td>
1004
- </tr>
1005
- </tbody>
1006
- </table>
1007
-
1008
- <h4><?php
1009
- /* translators: advanced usage */
1010
- _e('Usage', 'table-of-contents-plus'); ?></h4>
1011
- <p><?php printf(__('If you would like to fully customise the position of the table of contents, you can use the %s shortcode by placing it at the desired position of your post, page or custom post type. This method allows you to generate the table of contents despite having auto insertion disabled for its content type. Please visit the help tab for further information about this shortcode.', 'table-of-contents-plus'), '<code>[toc]</code>'); ?></p>
1012
- </div>
1013
-
1014
-
1015
- </div>
1016
- <div id="tab2" class="tab_content">
1017
-
1018
-
1019
- <p><?php printf(__('At its simplest, placing %s into a page will automatically create a sitemap of all pages and categories. This also works in a text widget.', 'table-of-contents-plus'), '<code>[sitemap]</code>'); ?></p>
1020
- <table class="form-table">
1021
- <tbody>
1022
- <tr>
1023
- <th><label for="sitemap_show_page_listing"><?php _e('Show page listing', 'table-of-contents-plus'); ?></label></th>
1024
- <td><input type="checkbox" value="1" id="sitemap_show_page_listing" name="sitemap_show_page_listing"<?php if ( $this->options['sitemap_show_page_listing'] ) echo ' checked="checked"'; ?> /></td>
1025
- </tr>
1026
- <tr>
1027
- <th><label for="sitemap_show_category_listing"><?php _e('Show category listing', 'table-of-contents-plus'); ?></label></th>
1028
- <td><input type="checkbox" value="1" id="sitemap_show_category_listing" name="sitemap_show_category_listing"<?php if ( $this->options['sitemap_show_category_listing'] ) echo ' checked="checked"'; ?> /></td>
1029
- </tr>
1030
- <tr>
1031
- <th><label for="sitemap_heading_type"><?php _e('Heading type', 'table-of-contents-plus'); ?></label></th>
1032
- <td><label for="sitemap_heading_type"><?php
1033
- /* translators: the full line is supposed to read - Use [1-6 drop down list] to print out the titles */
1034
- _e('Use', 'table-of-contents-plus'); ?> h</label><select name="sitemap_heading_type" id="sitemap_heading_type">
1035
- <?php
1036
- // h1 to h6
1037
- for ($i = 1; $i <= 6; $i++) {
1038
- echo '<option value="' . $i . '"';
1039
- if ( $i == $this->options['sitemap_heading_type'] ) echo ' selected="selected"';
1040
- echo '>' . $i . '</option>' . "\n";
1041
- }
1042
- ?>
1043
- </select> <?php
1044
- /* translators: the full line is supposed to read - Use [h1-h6 drop down list] to print out the titles */
1045
- _e('to print out the titles', 'table-of-contents-plus'); ?>
1046
- </td>
1047
- </tr>
1048
- <tr>
1049
- <th><label for="sitemap_pages"><?php _e('Pages label', 'table-of-contents-plus'); ?></label></th>
1050
- <td><input type="text" class="regular-text" value="<?php echo htmlentities( $this->options['sitemap_pages'], ENT_COMPAT, 'UTF-8' ); ?>" id="sitemap_pages" name="sitemap_pages" />
1051
- <span class="description"><?php _e('Eg: Pages, Page List', 'table-of-contents-plus'); ?></span>
1052
- </td>
1053
- </tr>
1054
- <tr>
1055
- <th><label for="sitemap_categories"><?php _e('Categories label', 'table-of-contents-plus'); ?></label></th>
1056
- <td><input type="text" class="regular-text" value="<?php echo htmlentities( $this->options['sitemap_categories'], ENT_COMPAT, 'UTF-8' ); ?>" id="sitemap_categories" name="sitemap_categories" />
1057
- <span class="description"><?php _e('Eg: Categories, Category List', 'table-of-contents-plus'); ?></span>
1058
- </td>
1059
- </tr>
1060
- </tbody>
1061
- </table>
1062
-
1063
- <h3><?php _e('Advanced usage', 'table-of-contents-plus'); ?> <span class="show_hide">(<a href="#sitemap_advanced_usage"><?php _e('show', 'table-of-contents-plus'); ?></a>)</span></h3>
1064
- <div id="sitemap_advanced_usage">
1065
- <p><code>[sitemap_pages]</code> <?php printf(__('lets you print out a listing of only pages. Similarly %s can be used to print out a category listing. They both can accept a number of attributes so visit the help tab for more information.', 'table-of-contents-plus'), '<code>[sitemap_categories]</code>'); ?></p>
1066
- <p><?php _e('Examples', 'table-of-contents-plus'); ?></p>
1067
- <ol>
1068
- <li><code>[sitemap_categories no_label="true"]</code> <?php _e('hides the heading from a category listing', 'table-of-contents-plus'); ?></li>
1069
- <li><code>[sitemap_pages heading="6" label="This is an awesome listing" exclude="1,15"]</code> <?php printf(__('Uses h6 to display %s on a page listing excluding pages with IDs 1 and 15', 'table-of-contents-plus'), '<em>This is an awesome listing</em>'); ?></li>
1070
- </ol>
1071
- </div>
1072
-
1073
-
1074
- </div>
1075
- </div>
1076
-
1077
-
1078
- <p class="submit"><input type="submit" name="submit" class="button-primary" value="<?php _e('Update Options', 'table-of-contents-plus'); ?>" /></p>
1079
- </form>
1080
- </div>
1081
- <?php
1082
- }
1083
-
1084
-
1085
- function wp_head()
1086
- {
1087
- $css = '';
1088
-
1089
- if ( !$this->options['exclude_css'] ) {
1090
- if ( $this->options['theme'] == TOC_THEME_CUSTOM || $this->options['width'] != 'Auto' ) {
1091
- $css .= 'div#toc_container {';
1092
- if ( $this->options['theme'] == TOC_THEME_CUSTOM )
1093
- $css .= 'background: ' . $this->options['custom_background_colour'] . ';border: 1px solid ' . $this->options['custom_border_colour'] . ';';
1094
- if ( $this->options['width'] != 'Auto' ) {
1095
- $css .= 'width: ';
1096
- if ( $this->options['width'] != 'User defined' )
1097
- $css .= $this->options['width'];
1098
- else
1099
- $css .= $this->options['width_custom'] . $this->options['width_custom_units'];
1100
- $css .= ';';
1101
- }
1102
- $css .= '}';
1103
- }
1104
-
1105
- if ( '95%' != $this->options['font_size'] . $this->options['font_size_units'] )
1106
- $css .= 'div#toc_container ul li {font-size: ' . $this->options['font_size'] . $this->options['font_size_units'] . ';}';
1107
-
1108
- if ( $this->options['theme'] == TOC_THEME_CUSTOM ) {
1109
- if ( $this->options['custom_title_colour'] != TOC_DEFAULT_TITLE_COLOUR )
1110
- $css .= 'div#toc_container p.toc_title {color: ' . $this->options['custom_title_colour'] . ';}';
1111
- if ( $this->options['custom_links_colour'] != TOC_DEFAULT_LINKS_COLOUR )
1112
- $css .= 'div#toc_container p.toc_title a,div#toc_container ul.toc_list a {color: ' . $this->options['custom_links_colour'] . ';}';
1113
- if ( $this->options['custom_links_hover_colour'] != TOC_DEFAULT_LINKS_HOVER_COLOUR )
1114
- $css .= 'div#toc_container p.toc_title a:hover,div#toc_container ul.toc_list a:hover {color: ' . $this->options['custom_links_hover_colour'] . ';}';
1115
- if ( $this->options['custom_links_hover_colour'] != TOC_DEFAULT_LINKS_HOVER_COLOUR )
1116
- $css .= 'div#toc_container p.toc_title a:hover,div#toc_container ul.toc_list a:hover {color: ' . $this->options['custom_links_hover_colour'] . ';}';
1117
- if ( $this->options['custom_links_visited_colour'] != TOC_DEFAULT_LINKS_VISITED_COLOUR )
1118
- $css .= 'div#toc_container p.toc_title a:visited,div#toc_container ul.toc_list a:visited {color: ' . $this->options['custom_links_visited_colour'] . ';}';
1119
- }
1120
- }
1121
-
1122
- if ( $css )
1123
- echo '<style type="text/css">' . $css . '</style>';
1124
- }
1125
-
1126
-
1127
- /**
1128
- * Returns a clean url to be used as the destination anchor target
1129
- */
1130
- private function url_anchor_target( $title )
1131
- {
1132
- $return = false;
1133
-
1134
- if ( $title ) {
1135
- $return = trim( strip_tags($title) );
1136
-
1137
- // convert accented characters to ASCII
1138
- $return = remove_accents( $return );
1139
-
1140
- // replace newlines with spaces (eg when headings are split over multiple lines)
1141
- $return = str_replace( array("\r", "\n", "\n\r", "\r\n"), ' ', $return );
1142
-
1143
- // remove &amp;
1144
- $return = str_replace( '&amp;', '', $return );
1145
-
1146
- // remove non alphanumeric chars
1147
- $return = preg_replace( '/[^a-zA-Z0-9 \-_]*/', '', $return );
1148
-
1149
- // convert spaces to _
1150
- $return = str_replace(
1151
- array(' ', ' '),
1152
- '_',
1153
- $return
1154
- );
1155
-
1156
- // remove trailing - and _
1157
- $return = rtrim( $return, '-_' );
1158
-
1159
- // lowercase everything?
1160
- if ( $this->options['lowercase'] ) $return = strtolower($return);
1161
-
1162
- // if blank, then prepend with the fragment prefix
1163
- // blank anchors normally appear on sites that don't use the latin charset
1164
- if ( !$return ) {
1165
- $return = ( $this->options['fragment_prefix'] ) ? $this->options['fragment_prefix'] : '_';
1166
- }
1167
-
1168
- // hyphenate?
1169
- if ( $this->options['hyphenate'] ) {
1170
- $return = str_replace('_', '-', $return);
1171
- $return = str_replace('--', '-', $return);
1172
- }
1173
- }
1174
-
1175
- if ( array_key_exists($return, $this->collision_collector) ) {
1176
- $this->collision_collector[$return]++;
1177
- $return .= '-' . $this->collision_collector[$return];
1178
- }
1179
- else
1180
- $this->collision_collector[$return] = 1;
1181
-
1182
- return apply_filters( 'toc_url_anchor_target', $return );
1183
- }
1184
-
1185
-
1186
- private function build_hierarchy( &$matches )
1187
- {
1188
- $current_depth = 100; // headings can't be larger than h6 but 100 as a default to be sure
1189
- $html = '';
1190
- $numbered_items = array();
1191
- $numbered_items_min = null;
1192
-
1193
- // reset the internal collision collection
1194
- $this->collision_collector = array();
1195
-
1196
- // find the minimum heading to establish our baseline
1197
- for ($i = 0; $i < count($matches); $i++) {
1198
- if ( $current_depth > $matches[$i][2] )
1199
- $current_depth = (int)$matches[$i][2];
1200
- }
1201
-
1202
- $numbered_items[$current_depth] = 0;
1203
- $numbered_items_min = $current_depth;
1204
-
1205
- for ($i = 0; $i < count($matches); $i++) {
1206
-
1207
- if ( $current_depth == (int)$matches[$i][2] )
1208
- $html .= '<li>';
1209
-
1210
- // start lists
1211
- if ( $current_depth != (int)$matches[$i][2] ) {
1212
- for ($current_depth; $current_depth < (int)$matches[$i][2]; $current_depth++) {
1213
- $numbered_items[$current_depth + 1] = 0;
1214
- $html .= '<ul><li>';
1215
- }
1216
- }
1217
-
1218
- // list item
1219
- if ( in_array($matches[$i][2], $this->options['heading_levels']) ) {
1220
- $html .= '<a href="#' . $this->url_anchor_target( $matches[$i][0] ) . '">';
1221
- if ( $this->options['ordered_list'] ) {
1222
- // attach leading numbers when lower in hierarchy
1223
- $html .= '<span class="toc_number toc_depth_' . ($current_depth - $numbered_items_min + 1) . '">';
1224
- for ($j = $numbered_items_min; $j < $current_depth; $j++) {
1225
- $number = ($numbered_items[$j]) ? $numbered_items[$j] : 0;
1226
- $html .= $number . '.';
1227
- }
1228
-
1229
- $html .= ($numbered_items[$current_depth] + 1) . '</span> ';
1230
- $numbered_items[$current_depth]++;
1231
- }
1232
- $html .= strip_tags($matches[$i][0]) . '</a>';
1233
- }
1234
-
1235
-
1236
- // end lists
1237
- if ( $i != count($matches) - 1 ) {
1238
- if ( $current_depth > (int)$matches[$i + 1][2] ) {
1239
- for ($current_depth; $current_depth > (int)$matches[$i + 1][2]; $current_depth--) {
1240
- $html .= '</li></ul>';
1241
- $numbered_items[$current_depth] = 0;
1242
- }
1243
- }
1244
-
1245
- if ( $current_depth == (int)@$matches[$i + 1][2] )
1246
- $html .= '</li>';
1247
- }
1248
- else {
1249
- // this is the last item, make sure we close off all tags
1250
- for ($current_depth; $current_depth >= $numbered_items_min; $current_depth--) {
1251
- $html .= '</li>';
1252
- if ( $current_depth != $numbered_items_min ) $html .= '</ul>';
1253
- }
1254
- }
1255
- }
1256
-
1257
- return $html;
1258
- }
1259
-
1260
-
1261
- /**
1262
- * Returns a string with all items from the $find array replaced with their matching
1263
- * items in the $replace array. This does a one to one replacement (rather than
1264
- * globally).
1265
- *
1266
- * This function is multibyte safe.
1267
- *
1268
- * $find and $replace are arrays, $string is the haystack. All variables are
1269
- * passed by reference.
1270
- */
1271
- private function mb_find_replace( &$find = false, &$replace = false, &$string = '' )
1272
- {
1273
- if ( is_array($find) && is_array($replace) && $string ) {
1274
- // check if multibyte strings are supported
1275
- if ( function_exists( 'mb_strpos' ) ) {
1276
- for ($i = 0; $i < count($find); $i++) {
1277
- $string =
1278
- mb_substr( $string, 0, mb_strpos($string, $find[$i]) ) . // everything befor $find
1279
- $replace[$i] . // its replacement
1280
- mb_substr( $string, mb_strpos($string, $find[$i]) + mb_strlen($find[$i]) ) // everything after $find
1281
- ;
1282
- }
1283
- }
1284
- else {
1285
- for ($i = 0; $i < count($find); $i++) {
1286
- $string = substr_replace(
1287
- $string,
1288
- $replace[$i],
1289
- strpos($string, $find[$i]),
1290
- strlen($find[$i])
1291
- );
1292
- }
1293
- }
1294
- }
1295
-
1296
- return $string;
1297
- }
1298
-
1299
-
1300
- /**
1301
- * This function extracts headings from the html formatted $content. It will pull out
1302
- * only the required headings as specified in the options. For all qualifying headings,
1303
- * this function populates the $find and $replace arrays (both passed by reference)
1304
- * with what to search and replace with.
1305
- *
1306
- * Returns a html formatted string of list items for each qualifying heading. This
1307
- * is everything between and NOT including <ul> and </ul>
1308
- */
1309
- public function extract_headings( &$find, &$replace, $content = '' )
1310
- {
1311
- $matches = array();
1312
- $anchor = '';
1313
- $items = false;
1314
-
1315
- // reset the internal collision collection as the_content may have been triggered elsewhere
1316
- // eg by themes or other plugins that need to read in content such as metadata fields in
1317
- // the head html tag, or to provide descriptions to twitter/facebook
1318
- $this->collision_collector = array();
1319
-
1320
- if ( is_array($find) && is_array($replace) && $content ) {
1321
- // get all headings
1322
- // the html spec allows for a maximum of 6 heading depths
1323
- if ( preg_match_all('/(<h([1-6]{1})[^>]*>).*<\/h\2>/msuU', $content, $matches, PREG_SET_ORDER) ) {
1324
-
1325
- // remove undesired headings (if any) as defined by heading_levels
1326
- if ( count($this->options['heading_levels']) != 6 ) {
1327
- $new_matches = array();
1328
- for ($i = 0; $i < count($matches); $i++) {
1329
- if ( in_array($matches[$i][2], $this->options['heading_levels']) )
1330
- $new_matches[] = $matches[$i];
1331
- }
1332
- $matches = $new_matches;
1333
- }
1334
-
1335
- // remove specific headings if provided via the 'exclude' property
1336
- if ( $this->options['exclude'] ) {
1337
- $excluded_headings = explode('|', $this->options['exclude']);
1338
- if ( count($excluded_headings) > 0 ) {
1339
- for ($j = 0; $j < count($excluded_headings); $j++) {
1340
- // escape some regular expression characters
1341
- // others: http://www.php.net/manual/en/regexp.reference.meta.php
1342
- $excluded_headings[$j] = str_replace(
1343
- array('*'),
1344
- array('.*'),
1345
- trim($excluded_headings[$j])
1346
- );
1347
- }
1348
-
1349
- $new_matches = array();
1350
- for ($i = 0; $i < count($matches); $i++) {
1351
- $found = false;
1352
- for ($j = 0; $j < count($excluded_headings); $j++) {
1353
- if ( @preg_match('/^' . $excluded_headings[$j] . '$/imU', strip_tags($matches[$i][0])) ) {
1354
- $found = true;
1355
- break;
1356
- }
1357
- }
1358
- if (!$found) $new_matches[] = $matches[$i];
1359
- }
1360
- if ( count($matches) != count($new_matches) )
1361
- $matches = $new_matches;
1362
- }
1363
- }
1364
-
1365
- // remove empty headings
1366
- $new_matches = array();
1367
- for ($i = 0; $i < count($matches); $i++) {
1368
- if ( trim( strip_tags($matches[$i][0]) ) != false )
1369
- $new_matches[] = $matches[$i];
1370
- }
1371
- if ( count($matches) != count($new_matches) )
1372
- $matches = $new_matches;
1373
-
1374
- // check minimum number of headings
1375
- if ( count($matches) >= $this->options['start'] ) {
1376
-
1377
- for ($i = 0; $i < count($matches); $i++) {
1378
- // get anchor and add to find and replace arrays
1379
- $anchor = $this->url_anchor_target( $matches[$i][0] );
1380
- $find[] = $matches[$i][0];
1381
- $replace[] = str_replace(
1382
- array(
1383
- $matches[$i][1], // start of heading
1384
- '</h' . $matches[$i][2] . '>' // end of heading
1385
- ),
1386
- array(
1387
- $matches[$i][1] . '<span id="' . $anchor . '">',
1388
- '</span></h' . $matches[$i][2] . '>'
1389
- ),
1390
- $matches[$i][0]
1391
- );
1392
-
1393
- // assemble flat list
1394
- if ( !$this->options['show_heirarchy'] ) {
1395
- $items .= '<li><a href="#' . $anchor . '">';
1396
- if ( $this->options['ordered_list'] ) $items .= count($replace) . ' ';
1397
- $items .= strip_tags($matches[$i][0]) . '</a></li>';
1398
- }
1399
- }
1400
-
1401
- // build a hierarchical toc?
1402
- // we could have tested for $items but that var can be quite large in some cases
1403
- if ( $this->options['show_heirarchy'] ) $items = $this->build_hierarchy( $matches );
1404
-
1405
- }
1406
- }
1407
- }
1408
-
1409
- return $items;
1410
- }
1411
-
1412
-
1413
- /**
1414
- * Returns true if the table of contents is eligible to be printed, false otherwise.
1415
- */
1416
- public function is_eligible( $shortcode_used = false )
1417
- {
1418
- global $post;
1419
-
1420
- // do not trigger the TOC when displaying an XML/RSS feed
1421
- if ( is_feed() ) return false;
1422
-
1423
- // if the shortcode was used, this bypasses many of the global options
1424
- if ( $shortcode_used !== false ) {
1425
- // shortcode is used, make sure it adheres to the exclude from
1426
- // homepage option if we're on the homepage
1427
- if ( !$this->options['include_homepage'] && is_front_page() )
1428
- return false;
1429
- else
1430
- return true;
1431
- }
1432
- else {
1433
- if (
1434
- ( in_array(get_post_type($post), $this->options['auto_insert_post_types']) && $this->show_toc && !is_search() && !is_archive() && !is_front_page() ) ||
1435
- ( $this->options['include_homepage'] && is_front_page() )
1436
- ) {
1437
- if ( $this->options['restrict_path'] ) {
1438
- if ( strpos($_SERVER['REQUEST_URI'], $this->options['restrict_path']) === 0 )
1439
- return true;
1440
- else
1441
- return false;
1442
- }
1443
- else
1444
- return true;
1445
- }
1446
- else
1447
- return false;
1448
- }
1449
- }
1450
-
1451
-
1452
- function the_content( $content )
1453
- {
1454
- global $post;
1455
- $items = $css_classes = $anchor = '';
1456
- $custom_toc_position = strpos($content, '<!--TOC-->');
1457
- $find = $replace = array();
1458
-
1459
- if ( $this->is_eligible($custom_toc_position) ) {
1460
-
1461
- $items = $this->extract_headings($find, $replace, $content);
1462
-
1463
- if ( $items ) {
1464
- // do we display the toc within the content or has the user opted
1465
- // to only show it in the widget? if so, then we still need to
1466
- // make the find/replace call to insert the anchors
1467
- if ( $this->options['show_toc_in_widget_only'] && (in_array(get_post_type(), $this->options['show_toc_in_widget_only_post_types'])) ) {
1468
- $content = $this->mb_find_replace($find, $replace, $content);
1469
- }
1470
- else {
1471
-
1472
- // wrapping css classes
1473
- switch( $this->options['wrapping'] ) {
1474
- case TOC_WRAPPING_LEFT:
1475
- $css_classes .= ' toc_wrap_left';
1476
- break;
1477
-
1478
- case TOC_WRAPPING_RIGHT:
1479
- $css_classes .= ' toc_wrap_right';
1480
- break;
1481
-
1482
- case TOC_WRAPPING_NONE:
1483
- default:
1484
- // do nothing
1485
- }
1486
-
1487
- // colour themes
1488
- switch ( $this->options['theme'] ) {
1489
- case TOC_THEME_LIGHT_BLUE:
1490
- $css_classes .= ' toc_light_blue';
1491
- break;
1492
-
1493
- case TOC_THEME_WHITE:
1494
- $css_classes .= ' toc_white';
1495
- break;
1496
-
1497
- case TOC_THEME_BLACK:
1498
- $css_classes .= ' toc_black';
1499
- break;
1500
-
1501
- case TOC_THEME_TRANSPARENT:
1502
- $css_classes .= ' toc_transparent';
1503
- break;
1504
-
1505
- case TOC_THEME_GREY:
1506
- default:
1507
- // do nothing
1508
- }
1509
-
1510
- // bullets?
1511
- if ( $this->options['bullet_spacing'] )
1512
- $css_classes .= ' have_bullets';
1513
- else
1514
- $css_classes .= ' no_bullets';
1515
-
1516
- if ( $this->options['css_container_class'] ) $css_classes .= ' ' . $this->options['css_container_class'];
1517
-
1518
- $css_classes = trim($css_classes);
1519
-
1520
- // an empty class="" is invalid markup!
1521
- if ( !$css_classes ) $css_classes = ' ';
1522
-
1523
- // add container, toc title and list items
1524
- $html = '<div id="toc_container" class="' . $css_classes . '">';
1525
- if ( $this->options['show_heading_text'] ) {
1526
- $toc_title = htmlentities( $this->options['heading_text'], ENT_COMPAT, 'UTF-8' );
1527
- if ( strpos($toc_title, '%PAGE_TITLE%') !== false ) $toc_title = str_replace( '%PAGE_TITLE%', get_the_title(), $toc_title );
1528
- if ( strpos($toc_title, '%PAGE_NAME%') !== false ) $toc_title = str_replace( '%PAGE_NAME%', get_the_title(), $toc_title );
1529
- $html .= '<p class="toc_title">' . $toc_title . '</p>';
1530
- }
1531
- $html .= '<ul class="toc_list">' . $items . '</ul></div>' . "\n";
1532
-
1533
- if ( $custom_toc_position !== false ) {
1534
- $find[] = '<!--TOC-->';
1535
- $replace[] = $html;
1536
- $content = $this->mb_find_replace($find, $replace, $content);
1537
- }
1538
- else {
1539
- if ( count($find) > 0 ) {
1540
- switch ( $this->options['position'] ) {
1541
- case TOC_POSITION_TOP:
1542
- $content = $html . $this->mb_find_replace($find, $replace, $content);
1543
- break;
1544
-
1545
- case TOC_POSITION_BOTTOM:
1546
- $content = $this->mb_find_replace($find, $replace, $content) . $html;
1547
- break;
1548
-
1549
- case TOC_POSITION_AFTER_FIRST_HEADING:
1550
- $replace[0] = $replace[0] . $html;
1551
- $content = $this->mb_find_replace($find, $replace, $content);
1552
- break;
1553
-
1554
- case TOC_POSITION_BEFORE_FIRST_HEADING:
1555
- default:
1556
- $replace[0] = $html . $replace[0];
1557
- $content = $this->mb_find_replace($find, $replace, $content);
1558
- }
1559
- }
1560
- }
1561
- }
1562
- }
1563
- }
1564
- else {
1565
- // remove <!--TOC--> (inserted from shortcode) from content
1566
- $content = str_replace('<!--TOC-->', '', $content);
1567
- }
1568
-
1569
- return $content;
1570
- }
1571
-
1572
- } // end class
1573
- endif;
1574
-
1575
-
1576
-
1577
- if ( !class_exists( 'toc_widget' ) ) :
1578
- class toc_widget extends WP_Widget {
1579
-
1580
- function __construct()
1581
- {
1582
- $widget_options = array(
1583
- 'classname' => 'toc_widget',
1584
- 'description' => __('Display the table of contents in the sidebar with this widget', 'table-of-contents-plus')
1585
- );
1586
- $control_options = array(
1587
- 'width' => 250,
1588
- 'height' => 350,
1589
- 'id_base' => 'toc-widget'
1590
- );
1591
- parent::__construct( 'toc-widget', 'TOC+', $widget_options, $control_options );
1592
- }
1593
-
1594
-
1595
- /**
1596
- * Widget output to the public
1597
- */
1598
- function widget( $args, $instance )
1599
- {
1600
- global $tic, $wp_query;
1601
- $items = $custom_toc_position = '';
1602
- $find = $replace = array();
1603
-
1604
- $toc_options = $tic->get_options();
1605
- $post = get_post( $wp_query->post->ID );
1606
- $custom_toc_position = strpos( $post->post_content, '[toc]' ); // at this point, shortcodes haven't run yet so we can't search for <!--TOC-->
1607
-
1608
- if ( $tic->is_eligible($custom_toc_position) ) {
1609
-
1610
- extract( $args );
1611
-
1612
- $items = $tic->extract_headings( $find, $replace, wptexturize($post->post_content) );
1613
- $title = ( array_key_exists('title', $instance) ) ? apply_filters('widget_title', $instance['title']) : '';
1614
- if ( strpos($title, '%PAGE_TITLE%') !== false ) $title = str_replace( '%PAGE_TITLE%', get_the_title(), $title );
1615
- if ( strpos($title, '%PAGE_NAME%') !== false ) $title = str_replace( '%PAGE_NAME%', get_the_title(), $title );
1616
- $hide_inline = $toc_options['show_toc_in_widget_only'];
1617
-
1618
- $css_classes = '';
1619
- // bullets?
1620
- if ( $toc_options['bullet_spacing'] )
1621
- $css_classes .= ' have_bullets';
1622
- else
1623
- $css_classes .= ' no_bullets';
1624
-
1625
- if ( $items ) {
1626
- // before widget (defined by themes)
1627
- echo $before_widget;
1628
-
1629
- // display the widget title if one was input (before and after titles defined by themes)
1630
- if ( $title ) echo $before_title . $title . $after_title;
1631
-
1632
- // display the list
1633
- echo '<ul class="toc_widget_list' . $css_classes . '">' . $items . '</ul>';
1634
-
1635
- // after widget (defined by themes)
1636
- echo $after_widget;
1637
- }
1638
- }
1639
- }
1640
-
1641
-
1642
- /**
1643
- * Update the widget settings
1644
- */
1645
- function update( $new_instance, $old_instance )
1646
- {
1647
- global $tic;
1648
-
1649
- $instance = $old_instance;
1650
-
1651
- // strip tags for title to remove HTML (important for text inputs)
1652
- $instance['title'] = strip_tags( trim( $new_instance['title'] ) );
1653
-
1654
- // no need to strip tags for the following
1655
- //$instance['hide_inline'] = $new_instance['hide_inline'];
1656
- $tic->set_show_toc_in_widget_only( $new_instance['hide_inline'] );
1657
- $tic->set_show_toc_in_widget_only_post_types( (array)$new_instance['show_toc_in_widget_only_post_types'] );
1658
-
1659
- return $instance;
1660
- }
1661
-
1662
-
1663
- /**
1664
- * Displays the widget settings on the widget panel.
1665
- */
1666
- function form( $instance )
1667
- {
1668
- global $tic;
1669
- $toc_options = $tic->get_options();
1670
-
1671
- $defaults = array(
1672
- 'title' => $toc_options['heading_text']
1673
- );
1674
- $instance = wp_parse_args( (array)$instance, $defaults );
1675
-
1676
- ?>
1677
- <p>
1678
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title', 'table-of-contents-plus'); ?>:</label>
1679
- <input type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
1680
- </p>
1681
-
1682
- <p>
1683
- <input class="checkbox" type="checkbox" <?php checked( $toc_options['show_toc_in_widget_only'], 1 ); ?> id="<?php echo $this->get_field_id( 'hide_inline' ); ?>" name="<?php echo $this->get_field_name( 'hide_inline' ); ?>" value="1" />
1684
- <label for="<?php echo $this->get_field_id( 'hide_inline' ); ?>"> <?php _e('Show the table of contents only in the sidebar', 'table-of-contents-plus'); ?></label>
1685
- </p>
1686
-
1687
- <div class="show_toc_in_widget_only_post_types" style="margin: 0 0 25px 25px; display: <?php echo ( $toc_options['show_toc_in_widget_only'] == 1 ) ? 'block' : 'none'; ?>;">
1688
- <p><?php _e('For the following content types:', 'table-of-contents-plus'); ?></p>
1689
-
1690
- <?php
1691
- foreach (get_post_types() as $post_type) {
1692
- // make sure the post type isn't on the exclusion list
1693
- if ( !in_array($post_type, $tic->get_exclude_post_types()) ) {
1694
- echo '<input type="checkbox" value="' . $post_type . '" id="' . $this->get_field_id( 'show_toc_in_widget_only_post_types_' . $post_type ) . '" name="' . $this->get_field_name( "show_toc_in_widget_only_post_types" ) . '[]"';
1695
- if ( in_array($post_type, $toc_options['show_toc_in_widget_only_post_types']) ) echo ' checked="checked"';
1696
- echo ' /><label for="' . $this->get_field_id( 'show_toc_in_widget_only_post_types_' . $post_type ) . '"> ' . $post_type . '</label><br />';
1697
- }
1698
- }
1699
-
1700
- ?></div>
1701
-
1702
- <script type="text/javascript">
1703
- jQuery(document).ready(function($) {
1704
- $('#<?php echo $this->get_field_id( 'hide_inline' ); ?>').click(function() {
1705
- $(this).parent().siblings('div.show_toc_in_widget_only_post_types').toggle('fast');
1706
- });
1707
- });
1708
- </script>
1709
- <?php
1710
- }
1711
-
1712
- } // end class
1713
- endif;
1714
-
1715
-
1716
- /**
1717
- * Returns a HTML formatted string of the table of contents without the surrounding UL or OL
1718
- * tags to enable the theme editor to supply their own ID and/or classes to the outer list.
1719
- *
1720
- * There are three optional parameters you can feed this function with:
1721
- *
1722
- * - $content is the entire content with headings. If blank, will default to the current $post
1723
- *
1724
- * - $link is the URL to prefix the anchor with. If provided a string, will use it as the prefix.
1725
- * If set to true then will try to obtain the permalink from the $post object.
1726
- *
1727
- * - $apply_eligibility bool, defaults to false. When set to true, will apply the check to
1728
- * see if bit of content has the prerequisites needed for a TOC, eg minimum number of headings
1729
- * enabled post type, etc.
1730
- */
1731
- function toc_get_index( $content = '', $prefix_url = '', $apply_eligibility = false )
1732
- {
1733
- global $wp_query, $tic;
1734
-
1735
- $return = '';
1736
- $find = $replace = array();
1737
- $proceed = true;
1738
-
1739
- if ( !$content ) {
1740
- $post = get_post( $wp_query->post->ID );
1741
- $content = wptexturize($post->post_content);
1742
- }
1743
-
1744
- if ( $apply_eligibility ) {
1745
- if ( !$tic->is_eligible() ) {
1746
- $proceed = false;
1747
- }
1748
- }
1749
- else {
1750
- $tic->set_option(array('start' => 0));
1751
- }
1752
-
1753
- if ( $proceed ) {
1754
- $return = $tic->extract_headings( $find, $replace, $content );
1755
- if ( $prefix_url ) $return = str_replace('href="#', 'href="' . $prefix_url . '#', $return);
1756
- }
1757
-
1758
- return $return;
1759
- }
1760
-
1761
-
1762
- // do the magic
1763
- $tic = new toc();
1
+ <?php
2
+ /**
3
+ * Plugin Name: Table of Contents Plus
4
+ * Plugin URI : http://dublue.com/plugins/toc/
5
+ * Description: A powerful yet user friendly plugin that automatically creates a table of contents. Can also output a sitemap listing all pages and categories.
6
+ * Author: Michael Tran
7
+ * Author URI: http://dublue.com/
8
+ * Text Domain: table-of-contents-plus
9
+ * Domain Path: /languages
10
+ * Version: 2106
11
+ * License: GPL2
12
+ */
13
+
14
+ /**
15
+ Table of Contents Plus is free software: you can redistribute it and/or modify
16
+ it under the terms of the GNU General Public License as published by
17
+ the Free Software Foundation, either version 2 of the License, or
18
+ any later version.
19
+
20
+ Table of Contents Plus is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with Table of Contents Plus. If not, see
27
+ https://github.com/zedzedzed/table-of-contents-plus/blob/main/LICENSE.md
28
+ */
29
+
30
+ /**
31
+ * GPL licenced Oxygen icon used for the colour wheel
32
+ * http://www.iconfinder.com/search/?q=iconset%3Aoxygen
33
+ */
34
+
35
+ require_once __DIR__ . '/class-toc-plus.php';
36
+
37
+ // do the magic
38
+ $toc_plus = new TOC_Plus();