Table of Contents Plus - Version 1107.1

Version Description

(10/July/2011) = * 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. * New: smooth scroll effect added to animate to anchor rather than jump. It's off by default. * New: appearance options to match your theme a little bit more.

Download this release

Release Info

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

Code changes from version 1107 to 1107.1

Files changed (12) hide show
  1. admin.css +5 -0
  2. admin.js +16 -14
  3. front.js +49 -0
  4. images/black.png +0 -0
  5. images/blue.png +0 -0
  6. images/grey.png +0 -0
  7. images/white.png +0 -0
  8. jquery.smooth-scroll.min.js +19 -0
  9. readme.txt +11 -5
  10. screen.css +12 -0
  11. screenshot-2.png +0 -0
  12. toc.php +141 -41
admin.css CHANGED
@@ -62,4 +62,9 @@ div.tab_content {
62
  h3 span.show_hide {
63
  font-size: 0.85em;
64
  font-weight: normal;
 
 
 
 
 
65
  }
62
  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
  }
admin.js CHANGED
@@ -1,28 +1,30 @@
1
  jQuery(document).ready(function($) {
2
- $(".tab_content, #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
 
6
- $("ul#tabbed-nav li").click(function() {
7
- $("ul#tabbed-nav li").removeClass("active"); //Remove any "active" class
8
- $(this).addClass("active"); //Add "active" class to selected tab
9
- $(".tab_content").hide(); //Hide all tab content
 
10
 
11
- var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
12
  $(activeTab).fadeIn(); //Fade in the active ID content
13
- return false;
14
  });
15
 
16
- $('h3 span.show_hide a').click(function() {
 
17
  $( $(this).attr('href') ).toggle('fast');
18
  if ( $(this).text() == 'show' )
19
  $(this).text('hide');
20
  else
21
  $(this).text('show');
22
- return false;
23
  });
24
 
25
- $('#background_colour_wheel').hide();
26
- $('#background_colour_wheel').farbtastic("#background_colour");
27
- $("#background_colour").click(function(){$('#background_colour_wheel').slideToggle()});
 
 
28
  });
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
 
6
+ $('ul#tabbed-nav li').click(function(event) {
7
+ event.preventDefault();
8
+ $('ul#tabbed-nav li').removeClass('active'); //Remove any "active" class
9
+ $(this).addClass('active'); //Add "active" class to selected tab
10
+ $('.tab_content').hide(); //Hide all tab content
11
 
12
+ var activeTab = $(this).find('a').attr('href'); //Find the href attribute value to identify the active tab + content
13
  $(activeTab).fadeIn(); //Fade in the active ID content
 
14
  });
15
 
16
+ $('h3 span.show_hide a').click(function(event) {
17
+ event.preventDefault();
18
  $( $(this).attr('href') ).toggle('fast');
19
  if ( $(this).text() == 'show' )
20
  $(this).text('hide');
21
  else
22
  $(this).text('show');
 
23
  });
24
 
25
+ if ( $.farbtastic ) {
26
+ $('#background_colour_wheel').hide();
27
+ $('#background_colour_wheel').farbtastic('#background_colour');
28
+ $("#background_colour").click(function(){$('#background_colour_wheel').slideToggle()});
29
+ }
30
  });
front.js CHANGED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+
3
+ if ( $.smoothScroll ) {
4
+ var target = hostname = hash = null;
5
+
6
+ $('body a').click(function(event) {
7
+ // 1.6 moved some attributes to the .prop method
8
+ if ( minVersion('1.6') ) {
9
+ hostname = $(this).prop('hostname');
10
+ hash = $(this).prop('hash');
11
+ }
12
+ else {
13
+ hostname = $(this).attr('hostname');
14
+ hash = $(this).attr('hash');
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=__)
23
+ anchor = hash;
24
+ anchor = anchor.replace('#', '');
25
+ target = 'a[name="' + anchor + '"]';
26
+ }
27
+ event.preventDefault();
28
+ $.smoothScroll({
29
+ scrollTarget: target,
30
+ offset: -30
31
+ });
32
+
33
+ }
34
+ });
35
+ }
36
+
37
+ function minVersion(version) {
38
+ var $vrs = window.jQuery.fn.jquery.split('.'),
39
+ min = version.split('.');
40
+ for (var i=0, len=$vrs.length; i<len; i++) {
41
+ console.log($vrs[i], min[i]);
42
+ if (min[i] && $vrs[i] < min[i]) {
43
+ return false;
44
+ }
45
+ }
46
+ return true;
47
+ }
48
+
49
+ });
images/black.png ADDED
Binary file
images/blue.png ADDED
Binary file
images/grey.png ADDED
Binary file
images/white.png ADDED
Binary file
jquery.smooth-scroll.min.js ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery Smooth Scroll Plugin v1.4
3
+ *
4
+ * Date: Mon Apr 25 00:02:30 2011 EDT
5
+ * Requires: jQuery v1.3+
6
+ *
7
+ * Copyright 2010, Karl Swedberg
8
+ * Dual licensed under the MIT and GPL licenses (just like jQuery):
9
+ * http://www.opensource.org/licenses/mit-license.php
10
+ * http://www.gnu.org/licenses/gpl.html
11
+ *
12
+ *
13
+ *
14
+ *
15
+ */
16
+ (function(c){function k(b){return b.replace(/^\//,"").replace(/(index|default).[a-zA-Z]{3,4}$/,"").replace(/\/$/,"")}var l=k(location.pathname),m=function(b){var d=[],a=false,e=b.dir&&b.dir=="left"?"scrollLeft":"scrollTop";this.each(function(){if(!(this==document||this==window)){var f=c(this);if(f[e]()>0)d.push(this);else{f[e](1);a=f[e]()>0;f[e](0);a&&d.push(this)}}});if(b.el==="first"&&d.length)d=[d.shift()];return d};c.fn.extend({scrollable:function(b){return this.pushStack(m.call(this,{dir:b}))},
17
+ firstScrollable:function(b){return this.pushStack(m.call(this,{el:"first",dir:b}))},smoothScroll:function(b){b=b||{};var d=c.extend({},c.fn.smoothScroll.defaults,b);this.die("click.smoothscroll").live("click.smoothscroll",function(a){var e=c(this),f=location.hostname===this.hostname||!this.hostname,g=d.scrollTarget||(k(this.pathname)||l)===l,i=this.hash,h=true;if(!d.scrollTarget&&(!f||!g||!i))h=false;else{f=d.exclude;g=0;for(var j=f.length;h&&g<j;)if(e.is(f[g++]))h=false;f=d.excludeWithin;g=0;for(j=
18
+ f.length;h&&g<j;)if(e.closest(f[g++]).length)h=false}if(h){d.scrollTarget=b.scrollTarget||i;d.link=this;a.preventDefault();c.smoothScroll(d)}});return this}});c.smoothScroll=function(b,d){var a,e,f,g=0;e="offset";var i="scrollTop",h={};if(typeof b==="number"){a=c.fn.smoothScroll.defaults;f=b}else{a=c.extend({},c.fn.smoothScroll.defaults,b||{});if(a.scrollElement){e="position";a.scrollElement.css("position")=="static"&&a.scrollElement.css("position","relative")}f=d||c(a.scrollTarget)[e]()&&c(a.scrollTarget)[e]()[a.direction]||
19
+ 0}a=c.extend({link:null},a);i=a.direction=="left"?"scrollLeft":i;if(a.scrollElement){e=a.scrollElement;g=e[i]()}else e=c("html, body").firstScrollable();h[i]=f+g+a.offset;e.animate(h,{duration:a.speed,easing:a.easing,complete:function(){a.afterScroll&&c.isFunction(a.afterScroll)&&a.afterScroll.call(a.link,a)}})};c.smoothScroll.version="1.4";c.fn.smoothScroll.defaults={exclude:[],excludeWithin:[],offset:0,direction:"top",scrollElement:null,scrollTarget:null,afterScroll:null,easing:"swing",speed:400}})(jQuery);
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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: trunk
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
 
@@ -35,14 +35,16 @@ If you have questions or suggestions, please place them at [http://dublue.com/pl
35
 
36
  The normal plugin install process applies, that is search for `table of contents plus` from your plugin screen or via the manual method:
37
 
38
- 1. Upload the `toc` folder into your `/wp-content/plugins/` directory
39
  1. Activate the plugin through the 'Plugins' menu in WordPress
40
- 1. Customise your options if needed
41
 
42
  Requires PHP 5.
43
 
44
  == Shortcodes ==
45
 
 
 
46
  * `[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.
47
  * `[sitemap_pages]` lets you print out a listing of only pages. The following parameters are accepted:
48
  ** "heading": number between 1 and 6, defines which html heading to use
@@ -51,12 +53,16 @@ Requires PHP 5.
51
  ** "exclude": IDs of the pages or categories you wish to exclude
52
  When parameters are left out, they will fallback to the default settings.
53
  * `[sitemap_categories]` as above but for categories.
54
- * `[no_toc]` allows you to disable the table of contents for the current post, page, or custom post type.
55
 
56
 
57
  == Changelog ==
58
 
59
- = 1107 =
 
 
 
 
 
60
  * First world release (functional & feature packed)
61
 
62
 
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
 
35
 
36
  The normal plugin install process applies, that is search for `table of contents plus` from your plugin screen or via the manual method:
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:
50
  ** "heading": number between 1 and 6, defines which html heading to use
53
  ** "exclude": IDs of the pages or categories you wish to exclude
54
  When parameters are left out, they will fallback to the default settings.
55
  * `[sitemap_categories]` as above but for categories.
 
56
 
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
 
screen.css CHANGED
@@ -11,10 +11,22 @@
11
  width: 278px;
12
  font-size: 95%;
13
  }
 
 
 
 
 
 
 
 
 
14
  .toc_title {
15
  text-align: center;
16
  font-weight: bold;
17
  }
 
 
 
18
  .toc_wrap_left {
19
  float: left;
20
  margin-right: 10px;
11
  width: 278px;
12
  font-size: 95%;
13
  }
14
+ #toc_container.toc_light_blue {
15
+ background: #edf6ff;
16
+ }
17
+ #toc_container.toc_white {
18
+ background: #fff;
19
+ }
20
+ #toc_container.toc_black {
21
+ background: #000;
22
+ }
23
  .toc_title {
24
  text-align: center;
25
  font-weight: bold;
26
  }
27
+ #toc_container.toc_black .toc_title {
28
+ color: #aaa;
29
+ }
30
  .toc_wrap_left {
31
  float: left;
32
  margin-right: 10px;
screenshot-2.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
9
  License: GPL2
10
  */
11
 
@@ -27,7 +27,6 @@ License: GPL2
27
 
28
  /**
29
  FOR CONSIDERATION:
30
- - shortcode (custom position)
31
  - support headings already with an id
32
  - back to top links
33
  - sitemap
@@ -35,8 +34,6 @@ FOR CONSIDERATION:
35
  - support other taxonomies
36
  - advanced options
37
  - width
38
- - colour variations
39
- - jquery smooth scroll
40
  - highlight target css
41
  */
42
 
@@ -50,6 +47,11 @@ define( 'TOC_MAX_START', 10 );
50
  define( 'TOC_WRAPPING_NONE', 0 );
51
  define( 'TOC_WRAPPING_LEFT', 1 );
52
  define( 'TOC_WRAPPING_RIGHT', 2 );
 
 
 
 
 
53
 
54
 
55
  if ( !class_exists( 'toc' ) ) :
@@ -74,7 +76,9 @@ if ( !class_exists( 'toc' ) ) :
74
  'auto_insert_post_types' => array('page'),
75
  'show_heirarchy' => true,
76
  'ordered_list' => true,
 
77
  'wrapping' => TOC_WRAPPING_NONE,
 
78
  'sitemap_show_page_listing' => true,
79
  'sitemap_show_category_listing' => true,
80
  'sitemap_heading_type' => 3,
@@ -86,6 +90,7 @@ if ( !class_exists( 'toc' ) ) :
86
 
87
  add_action( 'init', array(&$this, 'init') );
88
  add_action( 'wp_print_styles', array(&$this, 'public_styles') );
 
89
  add_action( 'admin_init', array(&$this, 'admin_init') );
90
  add_action( 'admin_menu', array(&$this, 'admin_menu') );
91
 
@@ -93,6 +98,7 @@ if ( !class_exists( 'toc' ) ) :
93
  add_filter( 'plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 );
94
  add_filter( 'widget_text', 'do_shortcode' );
95
 
 
96
  add_shortcode( 'no_toc', array(&$this, 'shortcode_no_toc') );
97
  add_shortcode( 'sitemap', array(&$this, 'shortcode_sitemap') );
98
  add_shortcode( 'sitemap_pages', array(&$this, 'shortcode_sitemap_pages') );
@@ -107,7 +113,7 @@ if ( !class_exists( 'toc' ) ) :
107
 
108
  function plugin_action_links( $links, $file )
109
  {
110
- if ( $file == "toc/" . basename(__FILE__) ) {
111
  $settings_link = '<a href="options-general.php?page=toc">' . __('Settings') . '</a>';
112
  $links = array_merge( array( $settings_link ), $links );
113
  }
@@ -115,6 +121,15 @@ if ( !class_exists( 'toc' ) ) :
115
  }
116
 
117
 
 
 
 
 
 
 
 
 
 
118
  function shortcode_no_toc( $atts )
119
  {
120
  $this->show_toc = false;
@@ -206,10 +221,8 @@ if ( !class_exists( 'toc' ) ) :
206
  function init()
207
  {
208
  wp_register_style( 'toc-screen', $this->path . '/screen.css' );
209
- wp_register_script( 'toc-front', $this->path . '/front.js' );
210
-
211
- wp_enqueue_script( 'jquery' );
212
- wp_enqueue_script( 'toc-front' );
213
  }
214
 
215
 
@@ -224,8 +237,8 @@ if ( !class_exists( 'toc' ) ) :
224
  {
225
  $page = add_submenu_page(
226
  'options-general.php',
227
- __('TOC') . '+',
228
- __('TOC') . '+',
229
  'manage_options',
230
  'toc',
231
  array(&$this, 'admin_options')
@@ -240,8 +253,8 @@ if ( !class_exists( 'toc' ) ) :
240
  */
241
  function admin_options_head()
242
  {
243
- wp_enqueue_style( 'farbtastic' );
244
- wp_enqueue_script( 'farbtastic' );
245
  wp_enqueue_script ( 'jquery' );
246
  wp_enqueue_script( 'toc_admin_script' );
247
  wp_enqueue_style( 'toc_admin_style' );
@@ -265,7 +278,9 @@ if ( !class_exists( 'toc' ) ) :
265
  'auto_insert_post_types' => (array)$_POST['auto_insert_post_types'],
266
  'show_heirarchy' => ($_POST['show_heirarchy']) ? true : false,
267
  'ordered_list' => ($_POST['ordered_list']) ? true : false,
 
268
  'wrapping' => intval($_POST['wrapping']),
 
269
  'sitemap_show_page_listing' => ($_POST['sitemap_show_page_listing']) ? true : false,
270
  'sitemap_show_category_listing' => ($_POST['sitemap_show_category_listing']) ? true : false,
271
  'sitemap_heading_type' => intval($_POST['sitemap_heading_type']),
@@ -286,9 +301,9 @@ if ( !class_exists( 'toc' ) ) :
286
 
287
  if ( isset( $_GET['update'] ) ) {
288
  if ( $this->save_admin_options() )
289
- $msg = "<div id='message' class='updated fade'><p>" . __('Options saved.') . "</p></div>";
290
  else
291
- $msg = "<div id='message' class='error fade'><p>" . __('Save failed.') . "</p></div>";
292
  }
293
 
294
  ?>
@@ -300,9 +315,9 @@ if ( !class_exists( 'toc' ) ) :
300
  <?php wp_nonce_field( plugin_basename(__FILE__), 'toc-admin-options' ); ?>
301
 
302
  <ul id="tabbed-nav">
303
- <li><a href="#tab1">Main Options</a></li>
304
- <li><a href="#tab2">Sitemap</a></li>
305
- <li><a href="#tab3">Help</a></li>
306
  </ul>
307
  <div class="tab_container">
308
  <div id="tab1" class="tab_content">
@@ -360,6 +375,10 @@ if ( !class_exists( 'toc' ) ) :
360
  <th><label for="ordered_list"><?php _e('Number list items', 'toc+'); ?></label></th>
361
  <td><input type="checkbox" value="1" id="ordered_list" name="ordered_list"<?php if ( $this->options['ordered_list'] ) echo ' checked="checked"'; ?> /></td>
362
  </tr>
 
 
 
 
363
  <tr>
364
  <th><label for="wrapping"><?php _e('Wrapping', 'toc+'); ?></label></td>
365
  <td>
@@ -372,17 +391,51 @@ if ( !class_exists( 'toc' ) ) :
372
  </tr>
373
  </tbody>
374
  </table>
375
- <!--
376
  <h3>Appearance</h3>
377
- Background Colour
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
  <input type="text" name="background_colour" id="background_colour" value="#00ffff" /><div id="background_colour_wheel"></div>
379
  -->
380
 
 
 
 
 
 
 
381
  </div>
382
  <div id="tab2" class="tab_content">
383
 
384
 
385
- <h3 class="title"><?php _e('Sitemap', 'toc+'); ?></h3>
386
  <p><?php _e('At its simplest, placing', 'toc+'); ?> <code>[sitemap]</code> <?php _e('into a page will automatically create a sitemap of all pages and categories. This also works in a text widget.', 'toc+'); ?></p>
387
  <table class="form-table">
388
  <tbody>
@@ -445,10 +498,11 @@ Background Colour
445
  <div id="tab3" class="tab_content">
446
 
447
  <h3>How do I stop the table of contents from appearing on a single page?</h3>
448
- <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 and custom post types that make use of the_content().</p>
449
 
450
  <h3>I've set wrapping to left or right but the headings don't wrap around the table of contents</h3>
451
- <p>This normally occurs when there is a CSS clear directive in or around the heading. This directive tells the user agent to reset the previous wrapping specifications. You can adjust your theme's CSS or try moving the table of contents position to the top of the page. If you didn't build your theme, I'd highly suggest you try the <a href="http://wordpress.org/extend/plugins/safecss/">Custom CSS plugin</a> if you wish to make CSS changes.</p>
 
452
 
453
  <h3>What's with the version numbers?</h3>
454
  <p>I like Ubuntu, especially the server product and highly recommend it for Linux deployments. I also like their versioning scheme and have adopted it. All versions are in a YYMM format (year month) of when the release was made.</p>
@@ -473,6 +527,17 @@ Background Colour
473
  }
474
 
475
 
 
 
 
 
 
 
 
 
 
 
 
476
  private function build_heirarchy( &$matches )
477
  {
478
  $current_depth = 100; // headings can't be larger than h6 but 100 as a default to be sure
@@ -538,10 +603,14 @@ Background Colour
538
  function the_content( $content )
539
  {
540
  global $post;
541
- $items = '';
 
542
  $matches = $find = $replace = array();
543
 
544
- if ( in_array(get_post_type($post), $this->options['auto_insert_post_types']) && !is_search() && $this->show_toc ) {
 
 
 
545
  // get all headings
546
  // the html spec allows for a maximum of 6 heading depths
547
  if ( preg_match_all('/(<h([2-6]{1})>).*<\/h\2>/', $content, $matches, PREG_SET_ORDER) >= $this->options['start'] ) {
@@ -570,39 +639,70 @@ Background Colour
570
  // wrapping css classes
571
  switch( $this->options['wrapping'] ) {
572
  case TOC_WRAPPING_LEFT:
573
- $wrapping = 'toc_wrap_left';
574
  break;
575
 
576
  case TOC_WRAPPING_RIGHT:
577
- $wrapping = 'toc_wrap_right';
578
  break;
579
 
580
  case TOC_WRAPPING_NONE:
581
  default:
582
- $wrapping = ' ';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
583
  }
584
 
 
 
 
 
 
585
  // add container, toc title and list items
586
  $html =
587
- '<div id="toc_container" class="' . $wrapping . '">' .
588
  '<p class="toc_title">' . htmlentities($this->options['heading_text']) . '</p>' .
589
  '<ul>' . $items . '</ul>' .
590
  '</div>'
591
  ;
592
 
593
- switch ( $this->options['position'] ) {
594
- case TOC_POSITION_TOP:
595
- $content = $html . str_replace($find, $replace, $content);
596
- break;
 
 
 
 
 
 
 
 
 
 
597
 
598
- case TOC_POSITION_BOTTOM:
599
- $content = str_replace($find, $replace, $content) . $html;
600
- break;
601
-
602
- case TOC_POSITION_BEFORE_FIRST_HEADING:
603
- default:
604
- $replace[0] = $html . $replace[0];
605
- $content = str_replace($find, $replace, $content);
606
  }
607
  }
608
  }
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
 
28
  /**
29
  FOR CONSIDERATION:
 
30
  - support headings already with an id
31
  - back to top links
32
  - sitemap
34
  - support other taxonomies
35
  - advanced options
36
  - width
 
 
37
  - highlight target css
38
  */
39
 
47
  define( 'TOC_WRAPPING_NONE', 0 );
48
  define( 'TOC_WRAPPING_LEFT', 1 );
49
  define( 'TOC_WRAPPING_RIGHT', 2 );
50
+ define( 'TOC_THEME_GREY', 1 );
51
+ define( 'TOC_THEME_LIGHT_BLUE', 2 );
52
+ define( 'TOC_THEME_WHITE', 3 );
53
+ define( 'TOC_THEME_BLACK', 4 );
54
+ define( 'TOC_THEME_CUSTOM', 100 );
55
 
56
 
57
  if ( !class_exists( 'toc' ) ) :
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,
90
 
91
  add_action( 'init', array(&$this, 'init') );
92
  add_action( 'wp_print_styles', array(&$this, 'public_styles') );
93
+ add_action( 'template_redirect', array(&$this, 'template_redirect') );
94
  add_action( 'admin_init', array(&$this, 'admin_init') );
95
  add_action( 'admin_menu', array(&$this, 'admin_menu') );
96
 
98
  add_filter( 'plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 );
99
  add_filter( 'widget_text', 'do_shortcode' );
100
 
101
+ add_shortcode( 'toc', array(&$this, 'shortcode_toc') );
102
  add_shortcode( 'no_toc', array(&$this, 'shortcode_no_toc') );
103
  add_shortcode( 'sitemap', array(&$this, 'shortcode_sitemap') );
104
  add_shortcode( 'sitemap_pages', array(&$this, 'shortcode_sitemap_pages') );
113
 
114
  function plugin_action_links( $links, $file )
115
  {
116
+ if ( $file == 'table-of-contents-plus/' . basename(__FILE__) ) {
117
  $settings_link = '<a href="options-general.php?page=toc">' . __('Settings') . '</a>';
118
  $links = array_merge( array( $settings_link ), $links );
119
  }
121
  }
122
 
123
 
124
+ function shortcode_toc( $atts )
125
+ {
126
+ if ( !is_search() && !is_archive() )
127
+ return '<!--TOC-->';
128
+ else
129
+ return;
130
+ }
131
+
132
+
133
  function shortcode_no_toc( $atts )
134
  {
135
  $this->show_toc = false;
221
  function init()
222
  {
223
  wp_register_style( 'toc-screen', $this->path . '/screen.css' );
224
+ wp_register_script( 'smooth-scroll', $this->path . '/jquery.smooth-scroll.min.js', array('jquery') );
225
+ wp_register_script( 'toc-front', $this->path . '/front.js', array('jquery') );
 
 
226
  }
227
 
228
 
237
  {
238
  $page = add_submenu_page(
239
  'options-general.php',
240
+ __('TOC', 'toc+') . '+',
241
+ __('TOC', 'toc+') . '+',
242
  'manage_options',
243
  'toc',
244
  array(&$this, 'admin_options')
253
  */
254
  function admin_options_head()
255
  {
256
+ //wp_enqueue_style( 'farbtastic' );
257
+ //wp_enqueue_script( 'farbtastic' );
258
  wp_enqueue_script ( 'jquery' );
259
  wp_enqueue_script( 'toc_admin_script' );
260
  wp_enqueue_style( 'toc_admin_style' );
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']),
301
 
302
  if ( isset( $_GET['update'] ) ) {
303
  if ( $this->save_admin_options() )
304
+ $msg = '<div id="message" class="updated fade"><p>' . __('Options saved.', 'toc+') . '</p></div>';
305
  else
306
+ $msg = '<div id="message" class="error fade"><p>' . __('Save failed.', 'toc+') . '</p></div>';
307
  }
308
 
309
  ?>
315
  <?php wp_nonce_field( plugin_basename(__FILE__), 'toc-admin-options' ); ?>
316
 
317
  <ul id="tabbed-nav">
318
+ <li><a href="#tab1"><?php _e('Main Options', 'toc+'); ?></a></li>
319
+ <li><a href="#tab2"><?php _e('Sitemap', 'toc+'); ?></a></li>
320
+ <li><a href="#tab3"><?php _e('Help', 'toc+'); ?></a></li>
321
  </ul>
322
  <div class="tab_container">
323
  <div id="tab1" class="tab_content">
375
  <th><label for="ordered_list"><?php _e('Number list items', 'toc+'); ?></label></th>
376
  <td><input type="checkbox" value="1" id="ordered_list" name="ordered_list"<?php if ( $this->options['ordered_list'] ) echo ' checked="checked"'; ?> /></td>
377
  </tr>
378
+ <tr>
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>
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 />
403
+ <img src="<?php echo $this->path; ?>/images/grey.png" alt="" />
404
+ </label>
405
+ </div>
406
+ <div class="toc_theme_option">
407
+ <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; ?>"> Light blue<br />
408
+ <img src="<?php echo $this->path; ?>/images/blue.png" alt="" />
409
+ </label>
410
+ </div>
411
+ <div class="toc_theme_option">
412
+ <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; ?>"> White<br />
413
+ <img src="<?php echo $this->path; ?>/images/white.png" alt="" />
414
+ </label>
415
+ </div>
416
+ <div class="toc_theme_option">
417
+ <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; ?>"> Black<br />
418
+ <img src="<?php echo $this->path; ?>/images/black.png" alt="" />
419
+ </label>
420
+ </div>
421
+ </td>
422
+ </tr>
423
+ </tbody>
424
+ </table>
425
+ <!--Background Colour
426
  <input type="text" name="background_colour" id="background_colour" value="#00ffff" /><div id="background_colour_wheel"></div>
427
  -->
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
+
435
  </div>
436
  <div id="tab2" class="tab_content">
437
 
438
 
 
439
  <p><?php _e('At its simplest, placing', 'toc+'); ?> <code>[sitemap]</code> <?php _e('into a page will automatically create a sitemap of all pages and categories. This also works in a text widget.', 'toc+'); ?></p>
440
  <table class="form-table">
441
  <tbody>
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
 
503
  <h3>I've set wrapping to left or right but the headings don't wrap around the table of contents</h3>
504
+ <p>This normally occurs when there is a CSS clear directive in or around the heading specified by the theme author. This directive tells the user agent to reset the previous wrapping specifications.</p>
505
+ <p>You can adjust your theme's CSS or try moving the table of contents position to the top of the page. If you didn't build your theme, I'd highly suggest you try the <a href="http://wordpress.org/extend/plugins/safecss/">Custom CSS plugin</a> if you wish to make CSS changes.</p>
506
 
507
  <h3>What's with the version numbers?</h3>
508
  <p>I like Ubuntu, especially the server product and highly recommend it for Linux deployments. I also like their versioning scheme and have adopted it. All versions are in a YYMM format (year month) of when the release was made.</p>
527
  }
528
 
529
 
530
+ /**
531
+ * Load front end javascript only on front end pages. Putting it into 'init' will
532
+ * load it on both frontend and backend pages.
533
+ */
534
+ function template_redirect()
535
+ {
536
+ if ( $this->options['smooth_scroll'] ) wp_enqueue_script( 'smooth-scroll' );
537
+ wp_enqueue_script( 'toc-front' );
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
603
  function the_content( $content )
604
  {
605
  global $post;
606
+ $items = $css_classes = '';
607
+ $custom_toc_position = strpos($content, '<!--TOC-->');
608
  $matches = $find = $replace = array();
609
 
610
+ if (
611
+ ( in_array(get_post_type($post), $this->options['auto_insert_post_types']) && $this->show_toc && !is_search() && !is_archive() ) ||
612
+ ( $custom_toc_position !== false )
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'] ) {
639
  // wrapping css classes
640
  switch( $this->options['wrapping'] ) {
641
  case TOC_WRAPPING_LEFT:
642
+ $css_classes .= ' toc_wrap_left';
643
  break;
644
 
645
  case TOC_WRAPPING_RIGHT:
646
+ $css_classes .= ' toc_wrap_right';
647
  break;
648
 
649
  case TOC_WRAPPING_NONE:
650
  default:
651
+ // do nothing
652
+ }
653
+
654
+ // colour themes
655
+ switch ( $this->options['theme'] ) {
656
+ case TOC_THEME_LIGHT_BLUE:
657
+ $css_classes .= ' toc_light_blue';
658
+ break;
659
+
660
+ case TOC_THEME_WHITE:
661
+ $css_classes .= ' toc_white';
662
+ break;
663
+
664
+ case TOC_THEME_BLACK:
665
+ $css_classes .= ' toc_black';
666
+ break;
667
+
668
+ case TOC_THEME_GREY:
669
+ default:
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-->';
688
+ $replace[] = $html;
689
+ $content = str_replace($find, $replace, $content);
690
+ }
691
+ else {
692
+ switch ( $this->options['position'] ) {
693
+ case TOC_POSITION_TOP:
694
+ $content = $html . str_replace($find, $replace, $content);
695
+ break;
696
+
697
+ case TOC_POSITION_BOTTOM:
698
+ $content = str_replace($find, $replace, $content) . $html;
699
+ break;
700
 
701
+ case TOC_POSITION_BEFORE_FIRST_HEADING:
702
+ default:
703
+ $replace[0] = $html . $replace[0];
704
+ $content = str_replace($find, $replace, $content);
705
+ }
 
 
 
706
  }
707
  }
708
  }