* Switch on/off the numbering of the list items (headers)

* Anchor bugs fixed
This commit is contained in:
happybooking 2013-08-08 15:42:52 +00:00
parent b403fd425f
commit 5c7eb73563
2 changed files with 36 additions and 17 deletions

View File

@ -3,7 +3,7 @@
Plugin Name: Extended Table of Contents (with nextpage support) Plugin Name: Extended Table of Contents (with nextpage support)
Plugin URI: http://www.happybooking.de/wordpress/plugins/extended-toc Plugin URI: http://www.happybooking.de/wordpress/plugins/extended-toc
Description: This plugin automatically generates and inserts a table of contents (ToC) to your pages and posts, based on tags h1-h6. Whenever the plugin discovers more than a certain amount of headings (default: 3) the ToC is inserted at the top of the page. This plugin also can handle posts that are divided into pages by the nextpage-wordpress-tag. By using the markups [extoc] you can decide where to insert the ToC. Also you can use a whitelist by disable general ToC insertion and insert the ToC to special pages/subpages/posts by [extoc]. Otherwise you can use a blacklist and disable the ToC only on special pages/subpages/posts by using the [noextoc] markup. Any feedback or suggestions are welcome. Description: This plugin automatically generates and inserts a table of contents (ToC) to your pages and posts, based on tags h1-h6. Whenever the plugin discovers more than a certain amount of headings (default: 3) the ToC is inserted at the top of the page. This plugin also can handle posts that are divided into pages by the nextpage-wordpress-tag. By using the markups [extoc] you can decide where to insert the ToC. Also you can use a whitelist by disable general ToC insertion and insert the ToC to special pages/subpages/posts by [extoc]. Otherwise you can use a blacklist and disable the ToC only on special pages/subpages/posts by using the [noextoc] markup. Any feedback or suggestions are welcome.
Version: 0.8.0 Version: 0.8.1
Author: HappyBooking UG // Daniel Boldura Author: HappyBooking UG // Daniel Boldura
Author URI: http://www.happybooking.de/ Author URI: http://www.happybooking.de/
@ -34,7 +34,7 @@ Author URI: http://www.happybooking.de/
* 4. Config the ToC within a markup e.g. [extoc start=5 headers=1,2,3 title="My table of contents"] oder [extoc start=5 headers=1,2,3 notitle] * 4. Config the ToC within a markup e.g. [extoc start=5 headers=1,2,3 title="My table of contents"] oder [extoc start=5 headers=1,2,3 notitle]
*/ */
define( 'EXTENDED_TOC_VERSION', '0.8.0' ); define( 'EXTENDED_TOC_VERSION', '0.8.1' );
define( 'EXTENDED_TOC_ID', 'extended_toc' ); define( 'EXTENDED_TOC_ID', 'extended_toc' );
define( 'EXTENDED_TOC_NAME', 'Extended-ToC' ); define( 'EXTENDED_TOC_NAME', 'Extended-ToC' );
define( 'TOC_MIN_START', 2 ); define( 'TOC_MIN_START', 2 );
@ -63,6 +63,7 @@ if( !class_exists('ExToC') ) {
'auto_insert_post_types' => array('page', 'post'), 'auto_insert_post_types' => array('page', 'post'),
'heading_levels' => array('1', '2', '3', '4', '5', '6'), 'heading_levels' => array('1', '2', '3', '4', '5', '6'),
'show_hierarchy' => true, 'show_hierarchy' => true,
'number_list_items' => true,
); );
$options = get_option( EXTENDED_TOC_ID, $defaults ); $options = get_option( EXTENDED_TOC_ID, $defaults );
$this->options = wp_parse_args( $options, $defaults ); $this->options = wp_parse_args( $options, $defaults );
@ -113,6 +114,7 @@ if( !class_exists('ExToC') ) {
'start' => intval($_POST['start']), 'start' => intval($_POST['start']),
'show_heading_text' => (isset($_POST['show_heading_text']) && $_POST['show_heading_text']) ? true : false, 'show_heading_text' => (isset($_POST['show_heading_text']) && $_POST['show_heading_text']) ? true : false,
'show_hierarchy' => (isset($_POST['show_hierarchy']) && $_POST['show_hierarchy']) ? true : false, 'show_hierarchy' => (isset($_POST['show_hierarchy']) && $_POST['show_hierarchy']) ? true : false,
'number_list_items' => (isset($_POST['number_list_items']) && $_POST['number_list_items']) ? true : false,
) )
); );
@ -191,6 +193,13 @@ if( !class_exists('ExToC') ) {
<input id="show_hierarchy" type="checkbox" name="show_hierarchy" <?php if ( $this->options['show_hierarchy'] ) echo ' checked="checked"'; ?> /> <input id="show_hierarchy" type="checkbox" name="show_hierarchy" <?php if ( $this->options['show_hierarchy'] ) echo ' checked="checked"'; ?> />
</td> </td>
</tr> </tr>
<tr>
<th><label for="number_list_items"><?=__('Number list items', EXTENDED_TOC_ID); ?></label></th>
<td>
<input id="number_list_items" type="checkbox" name="number_list_items" <?php if ( $this->options['number_list_items'] ) echo ' checked="checked"'; ?> />
</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@ -267,9 +276,6 @@ if( !class_exists('ExToC') ) {
return $content; return $content;
} }
private function check_for_first_toc_position() {
}
/** Extract the full unshortened content from the post **/ /** Extract the full unshortened content from the post **/
private function extract_full_post_content() { private function extract_full_post_content() {
global $post; global $post;
@ -310,6 +316,8 @@ if( !class_exists('ExToC') ) {
$matches = $new_matches; $matches = $new_matches;
} }
// echo "<pre>"; print_r($matches); echo "</pre>";
$items = ""; $items = "";
/** Take first h-level as baseline */ /** Take first h-level as baseline */
@ -319,8 +327,8 @@ if( !class_exists('ExToC') ) {
for( $i = 0; $i < count($matches); $i++ ) { for( $i = 0; $i < count($matches); $i++ ) {
/** get anchor and add to find and replace arrays **/ /** get anchor and add to find and replace arrays **/
$anchor = $this->url_encode_anchor($matches[$i][0]); $anchor = $this->url_encode_anchor($matches[$i][0]);
$find[] = $matches[$i][0]; $find = $matches[$i][0];
$this->content = str_replace( $replace = str_replace(
array( array(
$matches[$i][1], // start of heading $matches[$i][1], // start of heading
'</h' . $matches[$i][2] . '>' // end of heading '</h' . $matches[$i][2] . '>' // end of heading
@ -329,9 +337,11 @@ if( !class_exists('ExToC') ) {
$matches[$i][1] . '<span id="' . $anchor . '">', $matches[$i][1] . '<span id="' . $anchor . '">',
'</span></h' . $matches[$i][2] . '>' '</span></h' . $matches[$i][2] . '>'
), ),
$this->content $matches[$i][0]
); );
$this->content = str_replace($find, $replace, $this->content);
/** Check if header lower current header, then add level and update current header */ /** Check if header lower current header, then add level and update current header */
if( $matches[$i][2] > $currentLevel && $this->options['show_hierarchy'] == true) { if( $matches[$i][2] > $currentLevel && $this->options['show_hierarchy'] == true) {
$currentLevel = $matches[$i][2]; $currentLevel = $matches[$i][2];
@ -347,6 +357,9 @@ if( !class_exists('ExToC') ) {
/** build html */ /** build html */
$items .= '<li class="header-level-' . ($currentLevel - $minLevel + 1) . '">'; $items .= '<li class="header-level-' . ($currentLevel - $minLevel + 1) . '">';
$items .= '<a href="?p='.$this->ID.($pagenum>1?'&page='.$pagenum:'').'#' . $anchor . '">'; $items .= '<a href="?p='.$this->ID.($pagenum>1?'&page='.$pagenum:'').'#' . $anchor . '">';
// Show numbers only if user wants it
if( $this->options['number_list_items'] ) {
$items .= "<span class=\"toc-np-number\">"; $items .= "<span class=\"toc-np-number\">";
if( $this->options['show_hierarchy'] == true ) { if( $this->options['show_hierarchy'] == true ) {
@ -357,6 +370,8 @@ if( !class_exists('ExToC') ) {
$items = $items . $this->counter[$currentLevel]; $items = $items . $this->counter[$currentLevel];
$items .= "</span>"; $items .= "</span>";
}
$items .= strip_tags($matches[$i][0]) . '</a>'; $items .= strip_tags($matches[$i][0]) . '</a>';
$items .= '</li>'; $items .= '</li>';

View File

@ -4,7 +4,7 @@ Donate link: http://www.happybooking.de/wordpress/plugins/extended-toc/donate
Tags: table of contents, indexes, toc, sitemap, cms, options, list, page listing, category listing Tags: table of contents, indexes, toc, sitemap, cms, options, list, page listing, category listing
Requires at least: 3.0.1 Requires at least: 3.0.1
Tested up to: 3.5.2 Tested up to: 3.5.2
Stable tag: 0.7.0 Stable tag: 0.8.1
License: GPLv2 or later License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html License URI: http://www.gnu.org/licenses/gpl-2.0.html
@ -39,6 +39,10 @@ If you have any questions or suggestions please contact us at any time: support@
== Changelog == == Changelog ==
= 0.8.1 =
* Switch on/off the numbering of the list items (headers)
* Anchor bugs fixed
= 0.8.0 = = 0.8.0 =
* Override the ToC position by using the markup [extoc] * Override the ToC position by using the markup [extoc]
* Insert the ToC only in special pages/subpages/posts by using the markup [extoc] * Insert the ToC only in special pages/subpages/posts by using the markup [extoc]