Table of Contents Plus - Version 1108

Version Description

  • 1 August 2011 =
  • New: option to hide the title on top of the table of contents. Thanks to http://dublue.com/plugins/toc/#comment-82 for the suggestion.
  • New: option to preserve existing theme specified bullet images for unordered list elements.
  • New: option to set the width of the table of contents. You can select from a number of common widths, or define your own.
  • Allow 3 to be set as the minimum number of headings for auto insertion. The default stays at 4.
  • Now accepts heading 1s (h1) within the body of a post, page or custom post type.
  • Now creates new span tags for the target rather than the id of the heading.
  • Now uses the heading as the anchor target rather than toc_index.
  • Adjusted CSS styles for lists to be a little more consistent across themes (eg list-style, margins & paddings).
  • Fixed: typo 'heirarchy' should be 'hierarchy'. Also thanks to Andrew.
  • Fixed: addressed an issue while saving on networked installs using sub directories. Thanks to http://dublue.com/plugins/toc/#comment-79.
  • Fixed: closing of the last list item when deeply nested.
Download this release

Release Info

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

Code changes from version 1107.1 to 1108

Files changed (8) hide show
  1. admin.css +11 -1
  2. admin.js +20 -1
  3. front.js +3 -1
  4. readme.txt +31 -12
  5. screen.css +10 -4
  6. screenshot-2.png +0 -0
  7. screenshot-3.png +0 -0
  8. toc.php +172 -46
admin.css CHANGED
@@ -26,7 +26,7 @@ ul#tabbed-nav {
26
  overflow: hidden;
27
  position: relative;
28
  background: #DFDFDF;
29
- background-image: -moz-linear-gradient(center top , #F9F9F9, #F5F5F5);
30
  }
31
  #tabbed-nav li a {
32
  text-decoration: none;
@@ -63,8 +63,18 @@ h3 span.show_hide {
63
  font-size: 0.85em;
64
  font-weight: normal;
65
  }
 
 
 
66
  div.toc_theme_option {
67
  width: 200px;
68
  float: left;
69
  margin-right: 5px;
 
 
 
 
 
 
 
70
  }
26
  overflow: hidden;
27
  position: relative;
28
  background: #DFDFDF;
29
+ background-image: -moz-linear-gradient(center top, #F9F9F9, #F5F5F5);
30
  }
31
  #tabbed-nav li a {
32
  text-decoration: none;
63
  font-size: 0.85em;
64
  font-weight: normal;
65
  }
66
+ div.more_toc_options {
67
+ margin-top: 4px;
68
+ }
69
  div.toc_theme_option {
70
  width: 200px;
71
  float: left;
72
  margin-right: 5px;
73
+ }
74
+ #wpcontent select optgroup option {
75
+ padding-left: 15px;
76
+ }
77
+ input#width_custom {
78
+ width: 50px;
79
+ text-align: center;
80
  }
admin.js CHANGED
@@ -1,5 +1,5 @@
1
  jQuery(document).ready(function($) {
2
- $('.tab_content, #toc_advanced_usage, #sitemap_advanced_usage').hide();
3
  $('ul#tabbed-nav li:first').addClass('active').show(); // show first tab
4
  $('.tab_content:first').show(); // show first tab content
5
 
@@ -22,6 +22,25 @@ jQuery(document).ready(function($) {
22
  $(this).text('show');
23
  });
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  if ( $.farbtastic ) {
26
  $('#background_colour_wheel').hide();
27
  $('#background_colour_wheel').farbtastic('#background_colour');
1
  jQuery(document).ready(function($) {
2
+ $('.tab_content, #toc_advanced_usage, #sitemap_advanced_usage, div.more_toc_options.disabled').hide();
3
  $('ul#tabbed-nav li:first').addClass('active').show(); // show first tab
4
  $('.tab_content:first').show(); // show first tab content
5
 
22
  $(this).text('show');
23
  });
24
 
25
+ $('input#show_heading_text').click(function() {
26
+ $(this).siblings('div.more_toc_options').toggle('fast');
27
+ });
28
+
29
+ /* width drop down */
30
+ $('select#width').change(function() {
31
+ if ( $(this).find('option:selected').val() == 'User defined' ) {
32
+ $(this).siblings('div.more_toc_options').show('fast');
33
+ $('input#width_custom').focus();
34
+ }
35
+ else
36
+ $(this).siblings('div.more_toc_options').hide('fast');
37
+ });
38
+ $('input#width_custom').keyup(function() {
39
+ var width = $(this).val();
40
+ width = width.replace(/[^0-9]/, '');
41
+ $('input#width_custom').val(width);
42
+ });
43
+
44
  if ( $.farbtastic ) {
45
  $('#background_colour_wheel').hide();
46
  $('#background_colour_wheel').farbtastic('#background_colour');
front.js CHANGED
@@ -15,8 +15,10 @@ jQuery(document).ready(function($) {
15
  }
16
 
17
  if ( (window.location.hostname == hostname) && (hash !== '') ) {
 
 
18
  // check if element exists with id=__
19
- if ( $( hash ).length > 0 )
20
  target = hash;
21
  else {
22
  // must be an anchor (a name=__)
15
  }
16
 
17
  if ( (window.location.hostname == hostname) && (hash !== '') ) {
18
+ // escape jquery selector chars, but keep the #
19
+ var hash_selector = hash.replace(/([ !"$%&'()*+,.\/:;<=>?@[\]^`{|}~])/g, '\\$1');
20
  // check if element exists with id=__
21
+ if ( $( hash_selector ).length > 0 )
22
  target = hash;
23
  else {
24
  // must be an anchor (a name=__)
readme.txt CHANGED
@@ -3,21 +3,21 @@ Contributors: conjur3r
3
  Donate link:
4
  Tags: table of contents, indexes, toc, sitemap, cms, options, list, page listing, category listing
5
  Requires at least: 3.0
6
- Tested up to: 3.2
7
- Stable tag: 1107.1
8
 
9
  A powerful yet user friendly plugin that automatically creates a table of contents. Can also output a sitemap listing all pages and categories.
10
 
11
 
12
  == Description ==
13
 
14
- A powerful yet user friendly plugin that automatically creates a context specific index or table of contents index 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.
15
 
16
- Includes an administration options panel where you can customise things like display position, define the minimum number of headings before an index is displayed, appearance, etc. Using shortcodes, you can override default behaviour such as special exclusions on a specific page or even to hide the table of contents altogether.
17
 
18
- This plugin is a great companion for content rich sites such as content management system oriented configurations. That said, bloggers have the same benefits when writing long structured articles.
19
 
20
- 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.
21
 
22
  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.
23
 
@@ -37,13 +37,19 @@ The normal plugin install process applies, that is search for `table of contents
37
 
38
  1. Upload the `table-of-contents-plus` folder into your `/wp-content/plugins/` directory
39
  1. Activate the plugin through the 'Plugins' menu in WordPress
40
- 1. Customise your options under Settings > TOC+ if needed
41
 
42
- Requires PHP 5.
 
 
 
 
 
43
 
44
  == Shortcodes ==
45
 
46
- * `[toc]` lets you generate the table of contents at the preferred position. Also useful for sites that only require a TOC on a small handful of pages.
 
 
47
  * `[no_toc]` allows you to disable the table of contents for the current post, page, or custom post type.
48
  * `[sitemap]` produces a listing of all pages and categories for your site. You can use this on any post, page or even in a text widget.
49
  * `[sitemap_pages]` lets you print out a listing of only pages. The following parameters are accepted:
@@ -57,18 +63,31 @@ When parameters are left out, they will fallback to the default settings.
57
 
58
  == Changelog ==
59
 
60
- = 1107.1 (10/July/2011) =
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  * New: added `[toc]` shortcode to generate the table of contents at the preferred position. Also useful for sites that only require a TOC on a small handful of pages.
62
  * New: smooth scroll effect added to animate to anchor rather than jump. It's off by default.
63
  * New: appearance options to match your theme a little bit more.
64
 
65
- = 1107 (1/July/2011) =
66
  * First world release (functional & feature packed)
67
 
68
 
69
  == Frequently Asked Questions ==
70
 
71
- None yet.
72
 
73
 
74
  == Upgrade Notice ==
3
  Donate link:
4
  Tags: table of contents, indexes, toc, sitemap, cms, options, list, page listing, category listing
5
  Requires at least: 3.0
6
+ Tested up to: 3.3
7
+ Stable tag: 1108
8
 
9
  A powerful yet user friendly plugin that automatically creates a table of contents. Can also output a sitemap listing all pages and categories.
10
 
11
 
12
  == Description ==
13
 
14
+ A powerful yet user friendly plugin that automatically creates a context specific index or table of contents 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.
15
 
16
+ 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.
17
 
18
+ 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.
19
 
20
+ Includes an administration options panel where you can customise settings like display position, define the minimum number of headings before an index is displayed, appearance, etc. Using shortcodes, you can override default behaviour such as special exclusions on a specific page or even to hide the table of contents altogether.
21
 
22
  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.
23
 
37
 
38
  1. Upload the `table-of-contents-plus` folder into your `/wp-content/plugins/` directory
39
  1. Activate the plugin through the 'Plugins' menu in WordPress
 
40
 
41
+ That's it! The table of contents will appear on pages with at least four or more headings.
42
+
43
+ You can change the default settings and more under Settings > TOC+
44
+
45
+ This plugin requires PHP 5.
46
+
47
 
48
  == Shortcodes ==
49
 
50
+ * `[toc]` lets you generate the table of contents at the preferred position. Useful for sites that only require a TOC on a small handful of pages. Supports the following parameters:
51
+ ** "label": text, title of the table of contents
52
+ ** "no_label": true/false, shows or hides the title
53
  * `[no_toc]` allows you to disable the table of contents for the current post, page, or custom post type.
54
  * `[sitemap]` produces a listing of all pages and categories for your site. You can use this on any post, page or even in a text widget.
55
  * `[sitemap_pages]` lets you print out a listing of only pages. The following parameters are accepted:
63
 
64
  == Changelog ==
65
 
66
+ = 1108 - 1 August 2011 =
67
+ * New: option to hide the title on top of the table of contents. Thanks to [http://dublue.com/plugins/toc/#comment-82](Andrew) for the suggestion.
68
+ * New: option to preserve existing theme specified bullet images for unordered list elements.
69
+ * New: option to set the width of the table of contents. You can select from a number of common widths, or define your own.
70
+ * Allow 3 to be set as the minimum number of headings for auto insertion. The default stays at 4.
71
+ * Now accepts heading 1s (h1) within the body of a post, page or custom post type.
72
+ * Now creates new span tags for the target rather than the id of the heading.
73
+ * Now uses the heading as the anchor target rather than toc_index.
74
+ * Adjusted CSS styles for lists to be a little more consistent across themes (eg list-style, margins & paddings).
75
+ * Fixed: typo 'heirarchy' should be 'hierarchy'. Also thanks to Andrew.
76
+ * Fixed: addressed an issue while saving on networked installs using sub directories. Thanks to [http://dublue.com/plugins/toc/#comment-79](Aubrey).
77
+ * Fixed: closing of the last list item when deeply nested.
78
+
79
+ = 1107.1 - 10 July 2011 =
80
  * New: added `[toc]` shortcode to generate the table of contents at the preferred position. Also useful for sites that only require a TOC on a small handful of pages.
81
  * New: smooth scroll effect added to animate to anchor rather than jump. It's off by default.
82
  * New: appearance options to match your theme a little bit more.
83
 
84
+ = 1107 - 1 July 2011 =
85
  * First world release (functional & feature packed)
86
 
87
 
88
  == Frequently Asked Questions ==
89
 
90
+ Check out the FAQs / Scenarios at [http://dublue.com/plugins/toc/](http://dublue.com/plugins/toc/)
91
 
92
 
93
  == Upgrade Notice ==
screen.css CHANGED
@@ -1,14 +1,23 @@
1
  #toc_container ul, #toc_container li {
2
  margin: 0;
3
  padding: 0;
 
 
 
4
  list-style-type: none;
5
  }
 
 
 
 
 
 
6
  #toc_container {
7
  background: #f9f9f9;
8
  border: 1px solid #aaa;
9
  padding: 10px;
10
  margin-bottom: 1em;
11
- width: 278px;
12
  font-size: 95%;
13
  }
14
  #toc_container.toc_light_blue {
@@ -35,9 +44,6 @@
35
  float: right;
36
  margin-left: 10px;
37
  }
38
- #toc_container ul ul {
39
- margin-left: 1.5em;
40
- }
41
  #toc_container a {
42
  text-decoration: none;
43
  }
1
  #toc_container ul, #toc_container li {
2
  margin: 0;
3
  padding: 0;
4
+ }
5
+ #toc_container.no_bullets ul, #toc_container.no_bullets li {
6
+ background: none;
7
  list-style-type: none;
8
  }
9
+ #toc_container.have_bullets li {
10
+ padding-left: 12px;
11
+ }
12
+ #toc_container ul ul {
13
+ margin-left: 1.5em;
14
+ }
15
  #toc_container {
16
  background: #f9f9f9;
17
  border: 1px solid #aaa;
18
  padding: 10px;
19
  margin-bottom: 1em;
20
+ width: 275px;
21
  font-size: 95%;
22
  }
23
  #toc_container.toc_light_blue {
44
  float: right;
45
  margin-left: 10px;
46
  }
 
 
 
47
  #toc_container a {
48
  text-decoration: none;
49
  }
screenshot-2.png CHANGED
Binary file
screenshot-3.png CHANGED
Binary file
toc.php CHANGED
@@ -5,7 +5,7 @@ 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
- Version: 1107.1
9
  License: GPL2
10
  */
11
 
@@ -27,22 +27,19 @@ License: GPL2
27
 
28
  /**
29
  FOR CONSIDERATION:
30
- - support headings already with an id
31
  - back to top links
32
  - sitemap
33
  - exclude pages/categories
34
  - support other taxonomies
35
  - advanced options
36
- - width
37
  - highlight target css
38
  */
39
 
40
 
41
- define( 'TOC_ANCHOR_PREFIX', 'toc_index_' );
42
  define( 'TOC_POSITION_BEFORE_FIRST_HEADING', 1 );
43
  define( 'TOC_POSITION_TOP', 2 );
44
  define( 'TOC_POSITION_BOTTOM', 3 );
45
- define( 'TOC_MIN_START', 4 );
46
  define( 'TOC_MAX_START', 10 );
47
  define( 'TOC_WRAPPING_NONE', 0 );
48
  define( 'TOC_WRAPPING_LEFT', 1 );
@@ -72,13 +69,18 @@ if ( !class_exists( 'toc' ) ) :
72
  $defaults = array( // default options
73
  'position' => TOC_POSITION_BEFORE_FIRST_HEADING,
74
  'start' => TOC_MIN_START,
 
75
  'heading_text' => 'Contents',
76
  'auto_insert_post_types' => array('page'),
77
  'show_heirarchy' => true,
78
  'ordered_list' => true,
79
  'smooth_scroll' => false,
 
 
 
80
  'wrapping' => TOC_WRAPPING_NONE,
81
  'theme' => TOC_THEME_GREY,
 
82
  'sitemap_show_page_listing' => true,
83
  'sitemap_show_category_listing' => true,
84
  'sitemap_heading_type' => 3,
@@ -123,6 +125,15 @@ if ( !class_exists( 'toc' ) ) :
123
 
124
  function shortcode_toc( $atts )
125
  {
 
 
 
 
 
 
 
 
 
126
  if ( !is_search() && !is_archive() )
127
  return '<!--TOC-->';
128
  else
@@ -274,13 +285,18 @@ if ( !class_exists( 'toc' ) ) :
274
  $this->options = array(
275
  'position' => intval($_POST['position']),
276
  'start' => intval($_POST['start']),
 
277
  'heading_text' => trim($_POST['heading_text']),
278
  'auto_insert_post_types' => (array)$_POST['auto_insert_post_types'],
279
  'show_heirarchy' => ($_POST['show_heirarchy']) ? true : false,
280
  'ordered_list' => ($_POST['ordered_list']) ? true : false,
281
  'smooth_scroll' => ($_POST['smooth_scroll']) ? true : false,
 
 
 
282
  'wrapping' => intval($_POST['wrapping']),
283
  'theme' => intval($_POST['theme']),
 
284
  'sitemap_show_page_listing' => ($_POST['sitemap_show_page_listing']) ? true : false,
285
  'sitemap_show_category_listing' => ($_POST['sitemap_show_category_listing']) ? true : false,
286
  'sitemap_heading_type' => intval($_POST['sitemap_heading_type']),
@@ -311,7 +327,7 @@ if ( !class_exists( 'toc' ) ) :
311
  <div id="icon-options-general" class="icon32"><br /></div>
312
  <h2><?php _e('Table of Contents', 'toc+'); ?>+</h2>
313
  <?php echo $msg; ?>
314
- <form method="post" action="<?php echo $_SERVER['PHP_SELF'] . '?page=' . htmlentities($_GET['page'] . '&update'); ?>">
315
  <?php wp_nonce_field( plugin_basename(__FILE__), 'toc-admin-options' ); ?>
316
 
317
  <ul id="tabbed-nav">
@@ -349,13 +365,17 @@ if ( !class_exists( 'toc' ) ) :
349
  </td>
350
  </tr>
351
  <tr>
352
- <th><label for="heading_text"><?php _e('Heading text', 'toc+'); ?></label></th>
353
- <td><input type="text" class="regular-text" value="<?php echo htmlentities($this->options['heading_text']); ?>" id="heading_text" name="heading_text" />
354
- <span class="description"><?php _e('Eg: Contents, Table of Contents, Page Contents', 'toc+'); ?></span>
 
 
 
 
355
  </td>
356
  </tr>
357
  <tr>
358
- <th><?php _e('Auto insert for the following post types', 'toc+'); ?></th>
359
  <td><?php
360
  foreach (get_post_types() as $post_type) {
361
  // make sure the post type isn't on the exclusion list
@@ -368,7 +388,7 @@ if ( !class_exists( 'toc' ) ) :
368
  ?>
369
  </tr>
370
  <tr>
371
- <th><label for="show_heirarchy"><?php _e('Show heirarchy', 'toc+'); ?></label></th>
372
  <td><input type="checkbox" value="1" id="show_heirarchy" name="show_heirarchy"<?php if ( $this->options['show_heirarchy'] ) echo ' checked="checked"'; ?> /></td>
373
  </tr>
374
  <tr>
@@ -379,24 +399,62 @@ if ( !class_exists( 'toc' ) ) :
379
  <th><label for="smooth_scroll"><?php _e('Enable smooth scroll effect', 'toc+'); ?></label></th>
380
  <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', 'toc+'); ?></label></td>
381
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
382
  <tr>
383
  <th><label for="wrapping"><?php _e('Wrapping', 'toc+'); ?></label></td>
384
  <td>
385
  <select name="wrapping" id="wrapping">
386
- <option value="<?php echo TOC_WRAPPING_NONE; ?>"<?php if ( TOC_WRAPPING_NONE == $this->options['wrapping'] ) echo ' selected="selected"'; ?>>None (default)</option>
387
- <option value="<?php echo TOC_WRAPPING_LEFT; ?>"<?php if ( TOC_WRAPPING_LEFT == $this->options['wrapping'] ) echo ' selected="selected"'; ?>>Left</option>
388
- <option value="<?php echo TOC_WRAPPING_RIGHT; ?>"<?php if ( TOC_WRAPPING_RIGHT == $this->options['wrapping'] ) echo ' selected="selected"'; ?>>Right</option>
389
  </select>
390
  </td>
391
  </tr>
392
- </tbody>
393
- </table>
394
-
395
- <h3>Appearance</h3>
396
- <table class="form-table">
397
- <tbody>
398
  <tr>
399
- <th><?php _e('Theme', 'toc+'); ?></th>
400
  <td>
401
  <div class="toc_theme_option">
402
  <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; ?>"> Grey (default)<br />
@@ -420,6 +478,10 @@ if ( !class_exists( 'toc' ) ) :
420
  </div>
421
  </td>
422
  </tr>
 
 
 
 
423
  </tbody>
424
  </table>
425
  <!--Background Colour
@@ -428,7 +490,11 @@ if ( !class_exists( 'toc' ) ) :
428
 
429
  <h3>Advanced usage <span class="show_hide">(<a href="#toc_advanced_usage">show</a>)</span></h3>
430
  <div id="toc_advanced_usage">
431
- <p>If you would like to fully customise the position of the table of contents, you can use the <code>[toc]</code> 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 disabling auto insertion for its content type. Except for the position, it will inherit default options as defined on this page.</p>
 
 
 
 
432
  </div>
433
 
434
 
@@ -497,6 +563,14 @@ if ( !class_exists( 'toc' ) ) :
497
  </div>
498
  <div id="tab3" class="tab_content">
499
 
 
 
 
 
 
 
 
 
500
  <h3>How do I stop the table of contents from appearing on a single page?</h3>
501
  <p>Place the following <code>[no_toc]</code> anywhere on the page to suppress the table of contents. This is known as a shortcode and works for posts, pages and custom post types that make use of the_content().</p>
502
 
@@ -538,7 +612,35 @@ if ( !class_exists( 'toc' ) ) :
538
  }
539
 
540
 
541
- private function build_heirarchy( &$matches )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
542
  {
543
  $current_depth = 100; // headings can't be larger than h6 but 100 as a default to be sure
544
  $html = '';
@@ -567,16 +669,16 @@ if ( !class_exists( 'toc' ) ) :
567
  }
568
 
569
  // list item
570
- $html .= '<a href="#' . TOC_ANCHOR_PREFIX . ($i + 1) . '">';
571
  if ( $this->options['ordered_list'] ) {
572
- // attach leading numbers when lower in heirarchy
573
  for ($j = $numbered_items_min; $j < $current_depth; $j++) {
574
  $number = ($numbered_items[$j]) ? $numbered_items[$j] : 0;
575
  $html .= $number . '.';
576
  }
577
 
578
- $html .= ($numbered_items[$current_depth] + 1) . ' ';
579
- $numbered_items[$current_depth]++;
580
  }
581
  $html .= strip_tags($matches[$i][0]) . '</a>';
582
 
@@ -589,13 +691,19 @@ if ( !class_exists( 'toc' ) ) :
589
  $numbered_items[$current_depth] = 0;
590
  }
591
  }
 
 
 
 
 
 
 
 
 
 
592
  }
593
-
594
- if ( $current_depth == (int)$matches[$i + 1][2] )
595
- $html .= '</li>';
596
-
597
  }
598
-
599
  return $html;
600
  }
601
 
@@ -613,28 +721,34 @@ if ( !class_exists( 'toc' ) ) :
613
  ) {
614
  // get all headings
615
  // the html spec allows for a maximum of 6 heading depths
616
- if ( preg_match_all('/(<h([2-6]{1})>).*<\/h\2>/', $content, $matches, PREG_SET_ORDER) >= $this->options['start'] ) {
617
  for ($i = 0; $i < count($matches); $i++) {
618
-
619
  // create find and replace arrays
620
  $find[] = $matches[$i][0];
621
  $replace[] = str_replace(
622
- $matches[$i][1],
623
- trim($matches[$i][1], '>') . ' id="' . TOC_ANCHOR_PREFIX . ($i + 1) . '">',
 
 
 
 
 
 
624
  $matches[$i][0]
625
  );
626
-
627
  // assemble flat list
628
  if ( !$this->options['show_heirarchy'] ) {
629
- $items .= '<li><a href="#' . TOC_ANCHOR_PREFIX . ($i + 1) . '">';
630
  if ( $this->options['ordered_list'] ) $items .= ($i + 1) . ' ';
631
  $items .= strip_tags($matches[$i][0]) . '</a></li>';
632
  }
633
  }
634
 
635
- // build a heirarchical toc?
636
  // we could have tested for $items but that var can be quite large in some cases
637
- if ( $this->options['show_heirarchy'] ) $items = $this->build_heirarchy( &$matches );
638
 
639
  // wrapping css classes
640
  switch( $this->options['wrapping'] ) {
@@ -670,18 +784,30 @@ if ( !class_exists( 'toc' ) ) :
670
  // do nothing
671
  }
672
 
 
 
 
 
 
 
673
  $css_classes = trim($css_classes);
674
 
675
  // an empty class="" is invalid markup!
676
  if ( !$css_classes ) $css_classes = ' ';
677
 
678
  // add container, toc title and list items
679
- $html =
680
- '<div id="toc_container" class="' . $css_classes . '">' .
681
- '<p class="toc_title">' . htmlentities($this->options['heading_text']) . '</p>' .
682
- '<ul>' . $items . '</ul>' .
683
- '</div>'
684
- ;
 
 
 
 
 
 
685
 
686
  if ( $custom_toc_position !== false ) {
687
  $find[] = '<!--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
+ Version: 1108
9
  License: GPL2
10
  */
11
 
27
 
28
  /**
29
  FOR CONSIDERATION:
 
30
  - back to top links
31
  - sitemap
32
  - exclude pages/categories
33
  - support other taxonomies
34
  - advanced options
 
35
  - highlight target css
36
  */
37
 
38
 
 
39
  define( 'TOC_POSITION_BEFORE_FIRST_HEADING', 1 );
40
  define( 'TOC_POSITION_TOP', 2 );
41
  define( 'TOC_POSITION_BOTTOM', 3 );
42
+ define( 'TOC_MIN_START', 3 );
43
  define( 'TOC_MAX_START', 10 );
44
  define( 'TOC_WRAPPING_NONE', 0 );
45
  define( 'TOC_WRAPPING_LEFT', 1 );
69
  $defaults = array( // default options
70
  'position' => TOC_POSITION_BEFORE_FIRST_HEADING,
71
  'start' => TOC_MIN_START,
72
+ 'show_heading_text' => true,
73
  'heading_text' => 'Contents',
74
  'auto_insert_post_types' => array('page'),
75
  'show_heirarchy' => true,
76
  'ordered_list' => true,
77
  'smooth_scroll' => false,
78
+ 'width' => '275px',
79
+ 'width_custom' => '275',
80
+ 'width_custom_units' => 'px',
81
  'wrapping' => TOC_WRAPPING_NONE,
82
  'theme' => TOC_THEME_GREY,
83
+ 'bullet_spacing' => false,
84
  'sitemap_show_page_listing' => true,
85
  'sitemap_show_category_listing' => true,
86
  'sitemap_heading_type' => 3,
125
 
126
  function shortcode_toc( $atts )
127
  {
128
+ extract( shortcode_atts( array(
129
+ 'label' => $this->options['heading_text'],
130
+ 'no_label' => false
131
+ ), $atts )
132
+ );
133
+
134
+ if ( $no_label ) $this->options['show_heading_text'] = false;
135
+ if ( $label ) $this->options['heading_text'] = html_entity_decode( $label );
136
+
137
  if ( !is_search() && !is_archive() )
138
  return '<!--TOC-->';
139
  else
285
  $this->options = array(
286
  'position' => intval($_POST['position']),
287
  'start' => intval($_POST['start']),
288
+ 'show_heading_text' => ($_POST['show_heading_text']) ? true : false,
289
  'heading_text' => trim($_POST['heading_text']),
290
  'auto_insert_post_types' => (array)$_POST['auto_insert_post_types'],
291
  'show_heirarchy' => ($_POST['show_heirarchy']) ? true : false,
292
  'ordered_list' => ($_POST['ordered_list']) ? true : false,
293
  'smooth_scroll' => ($_POST['smooth_scroll']) ? true : false,
294
+ 'width' => trim($_POST['width']),
295
+ 'width_custom' => intval($_POST['width_custom']),
296
+ 'width_custom_units' => trim($_POST['width_custom_units']),
297
  'wrapping' => intval($_POST['wrapping']),
298
  'theme' => intval($_POST['theme']),
299
+ 'bullet_spacing' => ($_POST['bullet_spacing']) ? true : false,
300
  'sitemap_show_page_listing' => ($_POST['sitemap_show_page_listing']) ? true : false,
301
  'sitemap_show_category_listing' => ($_POST['sitemap_show_category_listing']) ? true : false,
302
  'sitemap_heading_type' => intval($_POST['sitemap_heading_type']),
327
  <div id="icon-options-general" class="icon32"><br /></div>
328
  <h2><?php _e('Table of Contents', 'toc+'); ?>+</h2>
329
  <?php echo $msg; ?>
330
+ <form method="post" action="<?php echo htmlentities('?page=' . $_GET['page'] . '&update'); ?>">
331
  <?php wp_nonce_field( plugin_basename(__FILE__), 'toc-admin-options' ); ?>
332
 
333
  <ul id="tabbed-nav">
365
  </td>
366
  </tr>
367
  <tr>
368
+ <th><label for="show_heading_text"><?php _e('Heading text', 'toc+'); ?></label></th>
369
+ <td>
370
+ <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', 'toc+'); ?></label><br />
371
+ <div class="more_toc_options<?php if ( !$this->options['show_heading_text'] ) echo ' disabled'; ?>">
372
+ <input type="text" class="regular-text" value="<?php echo htmlentities($this->options['heading_text']); ?>" id="heading_text" name="heading_text" />
373
+ <span class="description"><label for="heading_text"><?php _e('Eg: Contents, Table of Contents, Page Contents', 'toc+'); ?></label></span>
374
+ </div>
375
  </td>
376
  </tr>
377
  <tr>
378
+ <th><?php _e('Auto insert for the following content types', 'toc+'); ?></th>
379
  <td><?php
380
  foreach (get_post_types() as $post_type) {
381
  // make sure the post type isn't on the exclusion list
388
  ?>
389
  </tr>
390
  <tr>
391
+ <th><label for="show_heirarchy"><?php _e('Show hierarchy', 'toc+'); ?></label></th>
392
  <td><input type="checkbox" value="1" id="show_heirarchy" name="show_heirarchy"<?php if ( $this->options['show_heirarchy'] ) echo ' checked="checked"'; ?> /></td>
393
  </tr>
394
  <tr>
399
  <th><label for="smooth_scroll"><?php _e('Enable smooth scroll effect', 'toc+'); ?></label></th>
400
  <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', 'toc+'); ?></label></td>
401
  </tr>
402
+ </tbody>
403
+ </table>
404
+
405
+ <h3><?php _e('Appearance', 'toc+'); ?></h3>
406
+ <table class="form-table">
407
+ <tbody>
408
+ <tr>
409
+ <th><label for="width"><?php _e('Width', 'toc+'); ?></label></td>
410
+ <td>
411
+ <select name="width" id="width">
412
+ <optgroup label="<?php _e('Fixed width', 'toc+'); ?>">
413
+ <option value="200px"<?php if ( '200px' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('200px'); ?></option>
414
+ <option value="225px"<?php if ( '225px' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('225px'); ?></option>
415
+ <option value="250px"<?php if ( '250px' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('250px'); ?></option>
416
+ <option value="275px"<?php if ( '275px' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('275px (default)'); ?></option>
417
+ <option value="300px"<?php if ( '300px' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('300px'); ?></option>
418
+ <option value="325px"<?php if ( '325px' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('325px'); ?></option>
419
+ <option value="350px"<?php if ( '350px' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('350px'); ?></option>
420
+ <option value="375px"<?php if ( '375px' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('375px'); ?></option>
421
+ <option value="400px"<?php if ( '400px' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('400px'); ?></option>
422
+ </optgroup>
423
+ <optgroup label="<?php _e('Relative', 'toc+'); ?>">
424
+ <option value="25%"<?php if ( '25%' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('25%'); ?></option>
425
+ <option value="33%"<?php if ( '33%' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('33%'); ?></option>
426
+ <option value="50%"<?php if ( '50%' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('50%'); ?></option>
427
+ <option value="66%"<?php if ( '66%' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('66%'); ?></option>
428
+ <option value="75%"<?php if ( '75%' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('75%'); ?></option>
429
+ <option value="100%"<?php if ( '100%' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('100%'); ?></option>
430
+ </optgroup>
431
+ <optgroup label="<?php _e('Other', 'toc+'); ?>">
432
+ <option value="User defined"<?php if ( 'User defined' == $this->options['width'] ) echo ' selected="selected"'; ?>><?php _e('User defined', 'toc+'); ?></option>
433
+ </optgroup>
434
+ </select>
435
+ <div class="more_toc_options<?php if ( 'User defined' != $this->options['width'] ) echo ' disabled'; ?>">
436
+ <label for="width_custom"><?php _e('Please enter a number and', 'toc+'); ?></label><label for="width_custom_units"> <?php _e('select its units, eg: 100px, 10em', 'toc+'); ?></label><br />
437
+ <input type="text" class="regular-text" value="<?php echo htmlentities($this->options['width_custom']); ?>" id="width_custom" name="width_custom" />
438
+ <select name="width_custom_units" id="width_custom_units">
439
+ <option value="px"<?php if ( 'px' == $this->options['width_custom_units'] ) echo ' selected="selected"'; ?>>px</option>
440
+ <option value="%"<?php if ( '%' == $this->options['width_custom_units'] ) echo ' selected="selected"'; ?>>%</option>
441
+ <option value="em"<?php if ( 'em' == $this->options['width_custom_units'] ) echo ' selected="selected"'; ?>>em</option>
442
+ </select>
443
+ </div>
444
+ </td>
445
+ </tr>
446
  <tr>
447
  <th><label for="wrapping"><?php _e('Wrapping', 'toc+'); ?></label></td>
448
  <td>
449
  <select name="wrapping" id="wrapping">
450
+ <option value="<?php echo TOC_WRAPPING_NONE; ?>"<?php if ( TOC_WRAPPING_NONE == $this->options['wrapping'] ) echo ' selected="selected"'; ?>><?php _e('None (default)', 'toc+'); ?></option>
451
+ <option value="<?php echo TOC_WRAPPING_LEFT; ?>"<?php if ( TOC_WRAPPING_LEFT == $this->options['wrapping'] ) echo ' selected="selected"'; ?>><?php _e('Left', 'toc+'); ?></option>
452
+ <option value="<?php echo TOC_WRAPPING_RIGHT; ?>"<?php if ( TOC_WRAPPING_RIGHT == $this->options['wrapping'] ) echo ' selected="selected"'; ?>><?php _e('Right', 'toc+'); ?></option>
453
  </select>
454
  </td>
455
  </tr>
 
 
 
 
 
 
456
  <tr>
457
+ <th><?php _e('Presentation', 'toc+'); ?></th>
458
  <td>
459
  <div class="toc_theme_option">
460
  <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; ?>"> Grey (default)<br />
478
  </div>
479
  </td>
480
  </tr>
481
+ <tr>
482
+ <th><label for="bullet_spacing"><?php _e('Preserve theme bullets', 'toc+'); ?></label></th>
483
+ <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', 'toc+'); ?></label></td>
484
+ </tr>
485
  </tbody>
486
  </table>
487
  <!--Background Colour
490
 
491
  <h3>Advanced usage <span class="show_hide">(<a href="#toc_advanced_usage">show</a>)</span></h3>
492
  <div id="toc_advanced_usage">
493
+ <p>If you would like to fully customise the position of the table of contents, you can use the <code>[toc]</code> 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. Supports the following parameters:</p>
494
+ <ul>
495
+ <li><strong>label</strong> text, title of the table of contents</li>
496
+ <li><strong>no_label</strong> true/false, shows or hides the title</li>
497
+ </ul>
498
  </div>
499
 
500
 
563
  </div>
564
  <div id="tab3" class="tab_content">
565
 
566
+ <h3>Where's my table of contents?</h3>
567
+ <p>If you're reading this, then chances are you have successfully installed and enabled the plugin and you're just wondering why the index isn't appearing right? Try the following:</p>
568
+ <ol>
569
+ <li>In most cases, the post, page or custom post type has less than the minimum number of headings. By default, this is set to four so make sure you have at least four headings within your content. If you want to change this value, you can find it under 'Main Options' &gt; 'Show when'.</li>
570
+ <li>Is auto insertion enabled for your content type? By default, only pages are enabled.</li>
571
+ <li>Have you got <code>[no_toc]</code> somewhere within the content? This will disable the index for the current post, page or custom post type.</li>
572
+ </ol>
573
+
574
  <h3>How do I stop the table of contents from appearing on a single page?</h3>
575
  <p>Place the following <code>[no_toc]</code> anywhere on the page to suppress the table of contents. This is known as a shortcode and works for posts, pages and custom post types that make use of the_content().</p>
576
 
612
  }
613
 
614
 
615
+ /**
616
+ * Returns a clean url to be used as the destination anchor target
617
+ */
618
+ private function url_anchor_target( $title )
619
+ {
620
+ $return = false;
621
+
622
+ if ( $title ) {
623
+ $return = trim( strip_tags($title) );
624
+
625
+ // remove &amp;
626
+ $return = str_replace('&amp;', '', $return);
627
+
628
+ // remove punctuation
629
+ $return = preg_replace('/[!"$%&\'()*+,.\/:;<=>?@[\]^`{|}~]/', '', $return);
630
+
631
+ // convert spaces to _
632
+ $return = str_replace(
633
+ array(' ', ' '),
634
+ '_',
635
+ $return
636
+ );
637
+ }
638
+
639
+ return $return;
640
+ }
641
+
642
+
643
+ private function build_hierarchy( &$matches )
644
  {
645
  $current_depth = 100; // headings can't be larger than h6 but 100 as a default to be sure
646
  $html = '';
669
  }
670
 
671
  // list item
672
+ $html .= '<a href="#' . $this->url_anchor_target( $matches[$i][0] . '-' . ($i + 1) ) . '">';
673
  if ( $this->options['ordered_list'] ) {
674
+ // attach leading numbers when lower in hierarchy
675
  for ($j = $numbered_items_min; $j < $current_depth; $j++) {
676
  $number = ($numbered_items[$j]) ? $numbered_items[$j] : 0;
677
  $html .= $number . '.';
678
  }
679
 
680
+ $html .= (@$numbered_items[$current_depth] + 1) . ' ';
681
+ @$numbered_items[$current_depth]++;
682
  }
683
  $html .= strip_tags($matches[$i][0]) . '</a>';
684
 
691
  $numbered_items[$current_depth] = 0;
692
  }
693
  }
694
+
695
+ if ( $current_depth == (int)@$matches[$i + 1][2] )
696
+ $html .= '</li>';
697
+ }
698
+ else {
699
+ // this is the last item, make sure we close off all tags
700
+ for ($current_depth; $current_depth >= $numbered_items_min; $current_depth--) {
701
+ $html .= '</li>';
702
+ if ( $current_depth != $numbered_items_min ) $html .= '</ul>';
703
+ }
704
  }
 
 
 
 
705
  }
706
+
707
  return $html;
708
  }
709
 
721
  ) {
722
  // get all headings
723
  // the html spec allows for a maximum of 6 heading depths
724
+ if ( preg_match_all('/(<h([1-6]{1})[^>]*>).*<\/h\2>/', $content, $matches, PREG_SET_ORDER) >= $this->options['start'] ) {
725
  for ($i = 0; $i < count($matches); $i++) {
726
+
727
  // create find and replace arrays
728
  $find[] = $matches[$i][0];
729
  $replace[] = str_replace(
730
+ array(
731
+ $matches[$i][1], // start of heading
732
+ '</h' . $matches[$i][2] . '>' // end of heading
733
+ ),
734
+ array(
735
+ $matches[$i][1] . '<span id="' . $this->url_anchor_target( $matches[$i][0] . '-' . ($i + 1) ) . '">',
736
+ '</span></h' . $matches[$i][2] . '>'
737
+ ),
738
  $matches[$i][0]
739
  );
740
+
741
  // assemble flat list
742
  if ( !$this->options['show_heirarchy'] ) {
743
+ $items .= '<li><a href="#' . $this->url_anchor_target( $matches[$i][0] . '-' . ($i + 1) ) . '">';
744
  if ( $this->options['ordered_list'] ) $items .= ($i + 1) . ' ';
745
  $items .= strip_tags($matches[$i][0]) . '</a></li>';
746
  }
747
  }
748
 
749
+ // build a hierarchical toc?
750
  // we could have tested for $items but that var can be quite large in some cases
751
+ if ( $this->options['show_heirarchy'] ) $items = $this->build_hierarchy( &$matches );
752
 
753
  // wrapping css classes
754
  switch( $this->options['wrapping'] ) {
784
  // do nothing
785
  }
786
 
787
+ // bullets?
788
+ if ( $this->options['bullet_spacing'] )
789
+ $css_classes .= ' have_bullets';
790
+ else
791
+ $css_classes .= ' no_bullets';
792
+
793
  $css_classes = trim($css_classes);
794
 
795
  // an empty class="" is invalid markup!
796
  if ( !$css_classes ) $css_classes = ' ';
797
 
798
  // add container, toc title and list items
799
+ $html = '<div id="toc_container" class="' . $css_classes . '"';
800
+ if ( $this->options['width'] != '275px' ) {
801
+ $html .= ' style="width: ';
802
+ if ( $this->options['width'] != 'User defined' )
803
+ $html .= $this->options['width'];
804
+ else
805
+ $html .= $this->options['width_custom'] . $this->options['width_custom_units'];
806
+ $html .= ';"';
807
+ }
808
+ $html .= '>';
809
+ if ( $this->options['show_heading_text'] ) $html .= '<p class="toc_title">' . htmlentities($this->options['heading_text']) . '</p>';
810
+ $html .= '<ul>' . $items . '</ul></div>' . "\n";
811
 
812
  if ( $custom_toc_position !== false ) {
813
  $find[] = '<!--TOC-->';