New features added - see readme.txt
This commit is contained in:
parent
c7c5c99bee
commit
960069d1da
|
@ -3,7 +3,7 @@
|
|||
Plugin Name: Extended Table of Contents (with nextpage support)
|
||||
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. Any feedback or suggestions are welcome.
|
||||
Version: 0.6.4
|
||||
Version: 0.7.0
|
||||
Author: HappyBooking UG // Daniel Boldura
|
||||
Author URI: http://www.happybooking.de/
|
||||
|
||||
|
@ -34,9 +34,11 @@ 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]
|
||||
*/
|
||||
|
||||
define( 'EXTENDED_TOC_VERSION', '0.6.4' );
|
||||
define( 'EXTENDED_TOC_VERSION', '0.7.0' );
|
||||
define( 'EXTENDED_TOC_ID', 'extended_toc' );
|
||||
define( 'EXTENDED_TOC_NAME', 'Extended-ToC' );
|
||||
define( 'TOC_MIN_START', 2 );
|
||||
define( 'TOC_MAX_START', 10 );
|
||||
|
||||
if( !class_exists('ExToC') ) {
|
||||
class ExToC
|
||||
|
@ -46,7 +48,7 @@ if( !class_exists('ExToC') ) {
|
|||
private $fullcontent = "";
|
||||
private $pages = array();
|
||||
private $ID = 0;
|
||||
private $counter = 1;
|
||||
private $counter = array();
|
||||
private $totalHeadings = 0;
|
||||
|
||||
public function __construct() {
|
||||
|
@ -60,6 +62,7 @@ if( !class_exists('ExToC') ) {
|
|||
'show_heading_text' => true,
|
||||
'auto_insert_post_types' => array('page', 'post'),
|
||||
'heading_levels' => array('1', '2', '3', '4', '5', '6'),
|
||||
'show_hierarchy' => true,
|
||||
);
|
||||
$options = get_option( EXTENDED_TOC_ID, $defaults );
|
||||
$this->options = wp_parse_args( $options, $defaults );
|
||||
|
@ -107,6 +110,9 @@ if( !class_exists('ExToC') ) {
|
|||
array(
|
||||
'heading_text' => stripslashes( trim($_POST['heading_text']) ),
|
||||
'auto_insert_post_types' => @(array)$_POST['auto_insert_post_types'],
|
||||
'start' => intval($_POST['start']),
|
||||
'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,
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -139,6 +145,13 @@ if( !class_exists('ExToC') ) {
|
|||
<div class="form_container">
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th><label for="show_heading_text"><?=__('Show heading text', EXTENDED_TOC_ID); ?></label></th>
|
||||
<td>
|
||||
<input id="show_heading_text" type="checkbox" name="show_heading_text" <?php if ( $this->options['show_heading_text'] ) echo ' checked="checked"'; ?> />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><label for="heading_text"><?=__('Heading text', EXTENDED_TOC_ID); ?></label></th>
|
||||
<td><input id="heading_text" type="text" class="regular-text" name="heading_text" value="<?=$this->options['heading_text']?>" /></td>
|
||||
|
@ -155,6 +168,29 @@ if( !class_exists('ExToC') ) {
|
|||
<?php endforeach; ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><label for="start"><?=__('Show when', EXTENDED_TOC_ID); ?></label></th>
|
||||
<td>
|
||||
<select name="start" id="start">
|
||||
<?php
|
||||
for ($i = TOC_MIN_START; $i <= TOC_MAX_START; $i++) {
|
||||
echo '<option value="' . $i . '"';
|
||||
if ( $i == $this->options['start'] ) echo ' selected="selected"';
|
||||
echo '>' . $i . '</option>' . "\n";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<span>or more headings are present</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><label for="show_hierarchy"><?=__('Show hierarchy', EXTENDED_TOC_ID); ?></label></th>
|
||||
<td>
|
||||
<input id="show_hierarchy" type="checkbox" name="show_hierarchy" <?php if ( $this->options['show_hierarchy'] ) echo ' checked="checked"'; ?> />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -202,6 +238,9 @@ if( !class_exists('ExToC') ) {
|
|||
return $this->content;
|
||||
}
|
||||
|
||||
private function check_for_first_toc_position() {
|
||||
}
|
||||
|
||||
/** Extract the full unshortened content from the post **/
|
||||
private function extract_full_post_content() {
|
||||
global $post;
|
||||
|
@ -233,7 +272,7 @@ if( !class_exists('ExToC') ) {
|
|||
preg_match_all('/(<h([1-6]{1})[^>]*>).*<\/h\2>/msuU', $this->pages[$pagenum-1], $matches, PREG_SET_ORDER);
|
||||
|
||||
/** Check the headings that are desired */
|
||||
if ( count($this->options['heading_levels']) != 6 ) {
|
||||
if( count($this->options['heading_levels']) != 6 ) {
|
||||
$new_matches = array();
|
||||
for ($i = 0; $i < count($matches); $i++) {
|
||||
if ( in_array($matches[$i][2], $this->options['heading_levels']) )
|
||||
|
@ -244,6 +283,10 @@ if( !class_exists('ExToC') ) {
|
|||
|
||||
$items = "";
|
||||
|
||||
/** Take first h-level as baseline */
|
||||
$minLevel = $matches[0][2]; // lowest level e.g. h3
|
||||
$currentLevel = $minLevel;
|
||||
|
||||
for( $i = 0; $i < count($matches); $i++ ) {
|
||||
/** get anchor and add to find and replace arrays **/
|
||||
$anchor = $this->url_encode_anchor($matches[$i][0]);
|
||||
|
@ -260,10 +303,31 @@ if( !class_exists('ExToC') ) {
|
|||
$this->content
|
||||
);
|
||||
|
||||
/** Check if header lower current header, then add level and update current header */
|
||||
if( $matches[$i][2] > $currentLevel && $this->options['show_hierarchy'] == true) {
|
||||
$currentLevel = $matches[$i][2];
|
||||
$this->counter[$currentLevel] = 1;
|
||||
}
|
||||
else if( $matches[$i][2] < $currentLevel && $matches[$i][2] >= $minLevel && $this->options['show_hierarchy'] == true) {
|
||||
$currentLevel = $matches[$i][2];
|
||||
$this->counter[$currentLevel] += 1;
|
||||
}
|
||||
else
|
||||
$this->counter[$currentLevel] += 1;
|
||||
|
||||
/** build html */
|
||||
$items .= '<li>';
|
||||
$items .= '<li class="header-level-' . ($currentLevel - $minLevel + 1) . '">';
|
||||
$items .= '<a href="?p='.$this->ID.($pagenum>1?'&page='.$pagenum:'').'#' . $anchor . '">';
|
||||
$items .= "<span class=\"toc-np-number\">" . $this->counter++ . "</span> ";
|
||||
$items .= "<span class=\"toc-np-number\">";
|
||||
|
||||
if( $this->options['show_hierarchy'] == true ) {
|
||||
for( $j = $minLevel; $j < $currentLevel; $j++ ) {
|
||||
$items = $items . $this->counter[$j] . ".";
|
||||
}
|
||||
}
|
||||
$items = $items . $this->counter[$currentLevel];
|
||||
|
||||
$items .= "</span>";
|
||||
$items .= strip_tags($matches[$i][0]) . '</a>';
|
||||
$items .= '</li>';
|
||||
|
||||
|
|
|
@ -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
|
||||
Requires at least: 3.0.1
|
||||
Tested up to: 3.5.2
|
||||
Stable tag: 0.6.4
|
||||
Stable tag: 0.7.0
|
||||
License: GPLv2 or later
|
||||
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 ==
|
||||
|
||||
= 0.7.0 =
|
||||
* Show the header hierarchy within the ToC
|
||||
* Further options for (min amount of headers, show/don't show header, show headers hierarchy)
|
||||
|
||||
= 0.6.4 =
|
||||
* Released: 1 July 2013
|
||||
* First release of the ToC supporting nextpage-tag
|
||||
|
|
25
style.css
25
style.css
|
@ -12,6 +12,26 @@
|
|||
padding: 0
|
||||
}
|
||||
|
||||
#toc-np-container li.header-level-2 {
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
#toc-np-container li.header-level-3 {
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
#toc-np-container li.header-level-4 {
|
||||
padding-left: 45px;
|
||||
}
|
||||
|
||||
#toc-np-container li.header-level-5 {
|
||||
padding-left: 60px;
|
||||
}
|
||||
|
||||
#toc-np-container li.header-level-6 {
|
||||
padding-left: 75px;
|
||||
}
|
||||
|
||||
#toc-np-container ul {
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
@ -24,6 +44,11 @@
|
|||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#toc-np-container .toc-np-number {
|
||||
display: inline-block;
|
||||
padding-right: 15px;
|
||||
}
|
||||
|
||||
#toc-np-container #toc-np-title {
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
|
|
Loading…
Reference in New Issue