Table of Contents Plus - Version 1107

Version Description

  • First world release (functional & feature packed)

=

Download this release

Release Info

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

Version 1107

Files changed (9) hide show
  1. admin.css +65 -0
  2. admin.js +28 -0
  3. front.js +0 -0
  4. readme.txt +70 -0
  5. screen.css +34 -0
  6. screenshot-1.png +0 -0
  7. screenshot-2.png +0 -0
  8. screenshot-3.png +0 -0
  9. toc.php +621 -0
admin.css ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ div.tab_content table {
2
+ margin-bottom: 1em;
3
+ }
4
+ ul#tabbed-nav {
5
+ margin-top: 1em;
6
+ }
7
+ #tabbed-nav {
8
+ margin: 0;
9
+ padding: 0;
10
+ float: left;
11
+ list-style: none;
12
+ height: 32px; /*--Set height of tabs--*/
13
+ border-bottom: 1px solid #DFDFDF;
14
+ border-left: 1px solid #DFDFDF;
15
+ width: 100%;
16
+ }
17
+ #tabbed-nav li {
18
+ float: left;
19
+ margin: 0;
20
+ padding: 0;
21
+ height: 31px; /*--Subtract 1px from the height of the unordered list--*/
22
+ line-height: 31px; /*--Vertically aligns the text within the tab--*/
23
+ border: 1px solid #DFDFDF;
24
+ border-left: none;
25
+ margin-bottom: -1px; /*--Pull the list item down 1px--*/
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;
33
+ color: #000;
34
+ display: block;
35
+ font-size: 1.2em;
36
+ padding: 0 20px;
37
+ border: 1px solid #fff; /*--Gives the bevel look with a 1px white border inside the list item--*/
38
+ outline: none;
39
+ }
40
+ #tabbed-nav li a:hover {
41
+ background: #ececec;
42
+ }
43
+ html #tabbed-nav li.active, html #tabbed-nav li.active a:hover { /*--Makes sure that the active tab does not listen to the hover properties--*/
44
+ background: #fff;
45
+ border-bottom: 1px solid #fff; /*--Makes the active tab look like it's connected with its content--*/
46
+ }
47
+ div.tab_container {
48
+ border: 1px solid #DFDFDF;
49
+ border-top: none;
50
+ overflow: hidden;
51
+ clear: both;
52
+ float: left; width: 100%;
53
+ background: #fff;
54
+ margin-bottom: 2em;
55
+ padding-bottom: 2em;
56
+ }
57
+ div.tab_content {
58
+ padding: 10px;
59
+ padding-bottom: 0;
60
+ font-size: 1em;
61
+ }
62
+ h3 span.show_hide {
63
+ font-size: 0.85em;
64
+ font-weight: normal;
65
+ }
admin.js ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ });
front.js ADDED
File without changes
readme.txt ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Table of Contents Plus ===
2
+ 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: 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
+
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
+
24
+ If you have questions or suggestions, please place them at [http://dublue.com/plugins/toc/](http://dublue.com/plugins/toc/)
25
+
26
+
27
+ == Screenshots ==
28
+
29
+ 1. An example of the table of contents, positioned at the top and right aligned
30
+ 2. The main options tab in the administration area
31
+ 3. The sitemap options tab
32
+
33
+
34
+ == Installation ==
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
49
+ ** "label": text, title of the list
50
+ ** "no_label": true/false, shows or hides the list heading
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
+
63
+ == Frequently Asked Questions ==
64
+
65
+ None yet.
66
+
67
+
68
+ == Upgrade Notice ==
69
+
70
+ Update folder with the latest files. Any previous options will be saved.
screen.css ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_title {
15
+ text-align: center;
16
+ font-weight: bold;
17
+ }
18
+ .toc_wrap_left {
19
+ float: left;
20
+ margin-right: 10px;
21
+ }
22
+ .toc_wrap_right {
23
+ float: right;
24
+ margin-left: 10px;
25
+ }
26
+ #toc_container ul ul {
27
+ margin-left: 1.5em;
28
+ }
29
+ #toc_container a {
30
+ text-decoration: none;
31
+ }
32
+ #toc_container a:hover {
33
+ text-decoration: underline;
34
+ }
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file
toc.php ADDED
@@ -0,0 +1,621 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Version: 1107
9
+ License: GPL2
10
+ */
11
+
12
+ /* Copyright 2011 Michael Tran (michael@dublue.com)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License, version 2, as
16
+ published by the Free Software Foundation.
17
+
18
+ This program is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
+
23
+ You should have received a copy of the GNU General Public License
24
+ along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+
28
+ /**
29
+ FOR CONSIDERATION:
30
+ - shortcode (custom position)
31
+ - support headings already with an id
32
+ - back to top links
33
+ - sitemap
34
+ - exclude pages/categories
35
+ - support other taxonomies
36
+ - advanced options
37
+ - width
38
+ - colour variations
39
+ - jquery smooth scroll
40
+ - highlight target css
41
+ */
42
+
43
+
44
+ define( 'TOC_ANCHOR_PREFIX', 'toc_index_' );
45
+ define( 'TOC_POSITION_BEFORE_FIRST_HEADING', 1 );
46
+ define( 'TOC_POSITION_TOP', 2 );
47
+ define( 'TOC_POSITION_BOTTOM', 3 );
48
+ define( 'TOC_MIN_START', 4 );
49
+ 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' ) ) :
56
+ class toc {
57
+
58
+ private $path; // eg /wp-content/plugins/toc
59
+ private $options;
60
+ private $show_toc; // allows to override the display (eg through [no_toc] shortcode)
61
+ private $exclude_post_types;
62
+
63
+ function __construct()
64
+ {
65
+ $this->path = dirname( WP_PLUGIN_URL . '/' . plugin_basename( __FILE__ ) );
66
+ $this->show_toc = true;
67
+ $this->exclude_post_types = array( 'attachment', 'revision', 'nav_menu_item', 'safecss' );
68
+
69
+ // get options
70
+ $defaults = array( // default options
71
+ 'position' => TOC_POSITION_BEFORE_FIRST_HEADING,
72
+ 'start' => TOC_MIN_START,
73
+ 'heading_text' => 'Contents',
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,
81
+ 'sitemap_pages' => 'Pages',
82
+ 'sitemap_categories' => 'Categories'
83
+ );
84
+ $options = get_option( 'toc-options', $defaults );
85
+ $this->options = wp_parse_args( $options, $defaults );
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
+
92
+ add_filter( 'the_content', array(&$this, 'the_content'), 11 ); // run after shortcodes are interpretted (level 10)
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') );
99
+ add_shortcode( 'sitemap_categories', array(&$this, 'shortcode_sitemap_categories') );
100
+ }
101
+
102
+
103
+ function __destruct()
104
+ {
105
+ }
106
+
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
+ }
114
+ return $links;
115
+ }
116
+
117
+
118
+ function shortcode_no_toc( $atts )
119
+ {
120
+ $this->show_toc = false;
121
+
122
+ return;
123
+ }
124
+
125
+
126
+ function shortcode_sitemap( $atts )
127
+ {
128
+ $html = '';
129
+
130
+ // only do the following if enabled
131
+ if ( $this->options['sitemap_show_page_listing'] || $this->options['sitemap_show_category_listing'] ) {
132
+ $html = '<div class="toc_sitemap">';
133
+ if ( $this->options['sitemap_show_page_listing'] )
134
+ $html .=
135
+ '<h' . $this->options['sitemap_heading_type'] . ' class="toc_sitemap_pages">' . $this->options['sitemap_pages'] . '</h' . $this->options['sitemap_heading_type'] . '>' .
136
+ '<ul class="toc_sitemap_pages_list">' .
137
+ wp_list_pages( array('title_li' => '', 'echo' => false ) ) .
138
+ '</ul>'
139
+ ;
140
+ if ( $this->options['sitemap_show_category_listing'] )
141
+ $html .=
142
+ '<h' . $this->options['sitemap_heading_type'] . ' class="toc_sitemap_categories">' . $this->options['sitemap_categories'] . '</h' . $this->options['sitemap_heading_type'] . '>' .
143
+ '<ul class="toc_sitemap_categories_list">' .
144
+ wp_list_categories( array( 'title_li' => '', 'echo' => false ) ) .
145
+ '</ul>'
146
+ ;
147
+ $html .= '</div>';
148
+ }
149
+
150
+ return $html;
151
+ }
152
+
153
+
154
+ function shortcode_sitemap_pages( $atts )
155
+ {
156
+ extract( shortcode_atts( array(
157
+ 'heading' => $this->options['sitemap_heading_type'],
158
+ 'label' => $this->options['sitemap_pages'],
159
+ 'no_label' => false,
160
+ 'exclude' => ''
161
+ ), $atts )
162
+ );
163
+
164
+ if ( $heading < 1 || $heading > 6 ) // h1 to h6 are valid
165
+ $heading = $this->options['sitemap_heading_type'];
166
+
167
+ $html = '<div class="toc_sitemap">';
168
+ if ( !$no_label ) $html .= '<h' . $heading . ' class="toc_sitemap_pages">' . $label . '</h' . $heading . '>';
169
+ $html .=
170
+ '<ul class="toc_sitemap_pages_list">' .
171
+ wp_list_pages( array('title_li' => '', 'echo' => false, 'exclude' => $exclude ) ) .
172
+ '</ul>' .
173
+ '</div>'
174
+ ;
175
+
176
+ return $html;
177
+ }
178
+
179
+
180
+ function shortcode_sitemap_categories( $atts )
181
+ {
182
+ extract( shortcode_atts( array(
183
+ 'heading' => $this->options['sitemap_heading_type'],
184
+ 'label' => $this->options['sitemap_pages'],
185
+ 'no_label' => false,
186
+ 'exclude' => ''
187
+ ), $atts )
188
+ );
189
+
190
+ if ( $heading < 1 || $heading > 6 ) // h1 to h6 are valid
191
+ $heading = $this->options['sitemap_heading_type'];
192
+
193
+ $html = '<div class="toc_sitemap">';
194
+ if ( !$no_label ) $html .= '<h' . $heading . ' class="toc_sitemap_categories">' . $label . '</h' . $heading . '>';
195
+ $html .=
196
+ '<ul class="toc_sitemap_categories_list">' .
197
+ wp_list_categories( array('title_li' => '', 'echo' => false, 'exclude' => $exclude ) ) .
198
+ '</ul>' .
199
+ '</div>'
200
+ ;
201
+
202
+ return $html;
203
+ }
204
+
205
+
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
+
216
+ function admin_init()
217
+ {
218
+ wp_register_script( 'toc_admin_script', $this->path . '/admin.js' );
219
+ wp_register_style( 'toc_admin_style', $this->path . '/admin.css' );
220
+ }
221
+
222
+
223
+ function admin_menu()
224
+ {
225
+ $page = add_submenu_page(
226
+ 'options-general.php',
227
+ __('TOC') . '+',
228
+ __('TOC') . '+',
229
+ 'manage_options',
230
+ 'toc',
231
+ array(&$this, 'admin_options')
232
+ );
233
+
234
+ add_action( 'admin_print_styles-' . $page, array(&$this, 'admin_options_head') );
235
+ }
236
+
237
+
238
+ /**
239
+ * Load needed scripts and styles only on the toc administration interface.
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' );
248
+ }
249
+
250
+
251
+ private function save_admin_options()
252
+ {
253
+ // security check
254
+ if ( !wp_verify_nonce( $_POST['toc-admin-options'], plugin_basename(__FILE__) ) )
255
+ return false;
256
+
257
+ // require an administrator level to save
258
+ if ( !current_user_can( 'manage_options', $post_id ) )
259
+ return false;
260
+
261
+ $this->options = array(
262
+ 'position' => intval($_POST['position']),
263
+ 'start' => intval($_POST['start']),
264
+ 'heading_text' => trim($_POST['heading_text']),
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']),
272
+ 'sitemap_pages' => trim($_POST['sitemap_pages']),
273
+ 'sitemap_categories' => trim($_POST['sitemap_categories'])
274
+ );
275
+
276
+ // update_option will return false if no changes were made
277
+ update_option( 'toc-options', $this->options );
278
+
279
+ return true;
280
+ }
281
+
282
+
283
+ function admin_options()
284
+ {
285
+ $msg = '';
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
+ ?>
295
+ <div id='toc' class='wrap'>
296
+ <div id="icon-options-general" class="icon32"><br /></div>
297
+ <h2><?php _e('Table of Contents', 'toc+'); ?>+</h2>
298
+ <?php echo $msg; ?>
299
+ <form method="post" action="<?php echo $_SERVER['PHP_SELF'] . '?page=' . htmlentities($_GET['page'] . '&update'); ?>">
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">
309
+
310
+ <table class="form-table">
311
+ <tbody>
312
+ <tr>
313
+ <th><label for="position"><?php _e('Position', 'toc+'); ?></label></th>
314
+ <td>
315
+ <select name="position" id="position">
316
+ <option value="<?php echo TOC_POSITION_BEFORE_FIRST_HEADING; ?>"<?php if ( TOC_POSITION_BEFORE_FIRST_HEADING == $this->options['position'] ) echo ' selected="selected"'; ?>>Before first heading (default)</option>
317
+ <option value="<?php echo TOC_POSITION_TOP; ?>"<?php if ( TOC_POSITION_TOP == $this->options['position'] ) echo ' selected="selected"'; ?>>Top</option>
318
+ <option value="<?php echo TOC_POSITION_BOTTOM; ?>"<?php if ( TOC_POSITION_BOTTOM == $this->options['position'] ) echo ' selected="selected"'; ?>>Bottom</option>
319
+ </select>
320
+ </td>
321
+ </tr>
322
+ <tr>
323
+ <th><label for="start"><?php _e('Show when', 'toc+'); ?></label></th>
324
+ <td>
325
+ <select name="start" id="start">
326
+ <?php
327
+ for ($i = TOC_MIN_START; $i <= TOC_MAX_START; $i++) {
328
+ echo '<option value="' . $i . '"';
329
+ if ( $i == $this->options['start'] ) echo ' selected="selected"';
330
+ echo '>' . $i . '</option>' . "\n";
331
+ }
332
+ ?>
333
+ </select> <?php _e('or more headings are present', 'toc+'); ?>
334
+ </td>
335
+ </tr>
336
+ <tr>
337
+ <th><label for="heading_text"><?php _e('Heading text', 'toc+'); ?></label></th>
338
+ <td><input type="text" class="regular-text" value="<?php echo htmlentities($this->options['heading_text']); ?>" id="heading_text" name="heading_text" />
339
+ <span class="description"><?php _e('Eg: Contents, Table of Contents, Page Contents', 'toc+'); ?></span>
340
+ </td>
341
+ </tr>
342
+ <tr>
343
+ <th><?php _e('Auto insert for the following post types', 'toc+'); ?></th>
344
+ <td><?php
345
+ foreach (get_post_types() as $post_type) {
346
+ // make sure the post type isn't on the exclusion list
347
+ if ( !in_array($post_type, $this->exclude_post_types) ) {
348
+ echo '<input type="checkbox" value="' . $post_type . '" id="auto_insert_post_types_' . $post_type .'" name="auto_insert_post_types[]"';
349
+ if ( in_array($post_type, $this->options['auto_insert_post_types']) ) echo ' checked="checked"';
350
+ echo ' /><label for="auto_insert_post_types_' . $post_type .'"> ' . $post_type . '</label><br />';
351
+ }
352
+ }
353
+ ?>
354
+ </tr>
355
+ <tr>
356
+ <th><label for="show_heirarchy"><?php _e('Show heirarchy', 'toc+'); ?></label></th>
357
+ <td><input type="checkbox" value="1" id="show_heirarchy" name="show_heirarchy"<?php if ( $this->options['show_heirarchy'] ) echo ' checked="checked"'; ?> /></td>
358
+ </tr>
359
+ <tr>
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>
366
+ <select name="wrapping" id="wrapping">
367
+ <option value="<?php echo TOC_WRAPPING_NONE; ?>"<?php if ( TOC_WRAPPING_NONE == $this->options['wrapping'] ) echo ' selected="selected"'; ?>>None (default)</option>
368
+ <option value="<?php echo TOC_WRAPPING_LEFT; ?>"<?php if ( TOC_WRAPPING_LEFT == $this->options['wrapping'] ) echo ' selected="selected"'; ?>>Left</option>
369
+ <option value="<?php echo TOC_WRAPPING_RIGHT; ?>"<?php if ( TOC_WRAPPING_RIGHT == $this->options['wrapping'] ) echo ' selected="selected"'; ?>>Right</option>
370
+ </select>
371
+ </td>
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>
389
+ <tr>
390
+ <th><label for="sitemap_show_page_listing"><?php _e('Show page listing', 'toc+'); ?></label></th>
391
+ <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>
392
+ </tr>
393
+ <tr>
394
+ <th><label for="sitemap_show_category_listing"><?php _e('Show category listing', 'toc+'); ?></label></th>
395
+ <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>
396
+ </tr>
397
+ <tr>
398
+ <th><label for="sitemap_heading_type"><?php _e('Heading type', 'toc+'); ?></label></th>
399
+ <td><label for="sitemap_heading_type"><?php _e('Use', 'toc+'); ?> h</label><select name="sitemap_heading_type" id="sitemap_heading_type">
400
+ <?php
401
+ // h1 to h6
402
+ for ($i = 1; $i <= 6; $i++) {
403
+ echo '<option value="' . $i . '"';
404
+ if ( $i == $this->options['sitemap_heading_type'] ) echo ' selected="selected"';
405
+ echo '>' . $i . '</option>' . "\n";
406
+ }
407
+ ?>
408
+ </select> <?php _e('to print out the titles', 'toc+'); ?>
409
+ </td>
410
+ </tr>
411
+ <tr>
412
+ <th><label for="sitemap_pages"><?php _e('Pages label', 'toc+'); ?></label></th>
413
+ <td><input type="text" class="regular-text" value="<?php echo htmlentities($this->options['sitemap_pages']); ?>" id="sitemap_pages" name="sitemap_pages" />
414
+ <span class="description"><?php _e('Eg: Pages, Page List', 'toc+'); ?></span>
415
+ </td>
416
+ </tr>
417
+ <tr>
418
+ <th><label for="sitemap_categories"><?php _e('Categories label', 'toc+'); ?></label></th>
419
+ <td><input type="text" class="regular-text" value="<?php echo htmlentities($this->options['sitemap_categories']); ?>" id="sitemap_categories" name="sitemap_categories" />
420
+ <span class="description"><?php _e('Eg: Categories, Category List', 'toc+'); ?></span>
421
+ </td>
422
+ </tr>
423
+ </tbody>
424
+ </table>
425
+
426
+ <h3>Advanced usage <span class="show_hide">(<a href="#sitemap_advanced_usage">show</a>)</span></h3>
427
+ <div id="sitemap_advanced_usage">
428
+ <p><code>[sitemap_pages]</code> lets you print out a listing of only pages. Similarly, <code>[sitemap_categories]</code> can be used to print out a category listing. They both can accept the following parameters for further customisation:</p>
429
+ <ul>
430
+ <li><strong>heading</strong>: number between 1 and 6, defines which html heading to use</li>
431
+ <li><strong>label</strong>: text, title of the list</li>
432
+ <li><strong>no_label</strong>: true/false, shows or hides the list heading</li>
433
+ <li><strong>exclude</strong>: IDs of the pages or categories you wish to exclude</li>
434
+ </ul>
435
+ <p>When parameters are left out, they will fallback to the default settings.</p>
436
+ <p>Examples</p>
437
+ <ol>
438
+ <li><code>[sitemap_categories no_label="true"]</code> hides the heading from a category listing</li>
439
+ <li><code>[sitemap_pages heading="6" label="This is an awesome listing" exclude="1,15"]</code> Uses h6 to display <em>This is an awesome listing</em> on a page listing excluding pages with IDs 1 and 15.</li>
440
+ </ol>
441
+ </div>
442
+
443
+
444
+ </div>
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>
455
+
456
+ <h3>I have another question...</h3>
457
+ <p>Visit the <a href="http://dublue.com/plugins/toc/">plugin homepage</a> to ask your question - who knows, maybe your question has already been answered. I'd really like to hear your suggestions if you have any.</p>
458
+
459
+ </div>
460
+ </div>
461
+
462
+
463
+ <p class="submit"><input type="submit" name="submit" class="button-primary" value="<?php _e('Update Options', 'toc+'); ?>" /></p>
464
+ </form>
465
+ </div>
466
+ <?php
467
+ }
468
+
469
+
470
+ function public_styles()
471
+ {
472
+ wp_enqueue_style("toc-screen");
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
479
+ $html = '';
480
+ $numbered_items = array();
481
+ $numbered_items_min = null;
482
+
483
+ // find the minimum heading to establish our baseline
484
+ for ($i = 0; $i < count($matches); $i++) {
485
+ if ( $current_depth > $matches[$i][2] )
486
+ $current_depth = (int)$matches[$i][2];
487
+ }
488
+
489
+ $numbered_items[$current_depth] = 0;
490
+ $numbered_items_min = $current_depth;
491
+
492
+ for ($i = 0; $i < count($matches); $i++) {
493
+
494
+ if ( $current_depth == (int)$matches[$i][2] )
495
+ $html .= '<li>';
496
+
497
+ // start lists
498
+ if ( $current_depth != (int)$matches[$i][2] ) {
499
+ for ($current_depth; $current_depth < (int)$matches[$i][2]; $current_depth++) {
500
+ $html .= '<ul><li>';
501
+ }
502
+ }
503
+
504
+ // list item
505
+ $html .= '<a href="#' . TOC_ANCHOR_PREFIX . ($i + 1) . '">';
506
+ if ( $this->options['ordered_list'] ) {
507
+ // attach leading numbers when lower in heirarchy
508
+ for ($j = $numbered_items_min; $j < $current_depth; $j++) {
509
+ $number = ($numbered_items[$j]) ? $numbered_items[$j] : 0;
510
+ $html .= $number . '.';
511
+ }
512
+
513
+ $html .= ($numbered_items[$current_depth] + 1) . ' ';
514
+ $numbered_items[$current_depth]++;
515
+ }
516
+ $html .= strip_tags($matches[$i][0]) . '</a>';
517
+
518
+
519
+ // end lists
520
+ if ( $i != count($matches) - 1 ) {
521
+ if ( $current_depth > (int)$matches[$i + 1][2] ) {
522
+ for ($current_depth; $current_depth > (int)$matches[$i + 1][2]; $current_depth--) {
523
+ $html .= '</li></ul>';
524
+ $numbered_items[$current_depth] = 0;
525
+ }
526
+ }
527
+ }
528
+
529
+ if ( $current_depth == (int)$matches[$i + 1][2] )
530
+ $html .= '</li>';
531
+
532
+ }
533
+
534
+ return $html;
535
+ }
536
+
537
+
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'] ) {
548
+ for ($i = 0; $i < count($matches); $i++) {
549
+
550
+ // create find and replace arrays
551
+ $find[] = $matches[$i][0];
552
+ $replace[] = str_replace(
553
+ $matches[$i][1],
554
+ trim($matches[$i][1], '>') . ' id="' . TOC_ANCHOR_PREFIX . ($i + 1) . '">',
555
+ $matches[$i][0]
556
+ );
557
+
558
+ // assemble flat list
559
+ if ( !$this->options['show_heirarchy'] ) {
560
+ $items .= '<li><a href="#' . TOC_ANCHOR_PREFIX . ($i + 1) . '">';
561
+ if ( $this->options['ordered_list'] ) $items .= ($i + 1) . ' ';
562
+ $items .= strip_tags($matches[$i][0]) . '</a></li>';
563
+ }
564
+ }
565
+
566
+ // build a heirarchical toc?
567
+ // we could have tested for $items but that var can be quite large in some cases
568
+ if ( $this->options['show_heirarchy'] ) $items = $this->build_heirarchy( &$matches );
569
+
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
+ }
609
+
610
+ return $content;
611
+ }
612
+
613
+
614
+ } // end class
615
+ endif;
616
+
617
+
618
+ // do the magic
619
+ $tic = new toc();
620
+
621
+ ?>