Update to 0.9.0

This commit is contained in:
happybooking 2013-10-13 11:00:21 +00:00
parent b14ec0a4b3
commit dd96c39d8d
2 changed files with 142 additions and 33 deletions

View File

@ -2,8 +2,8 @@
/*
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. 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.6
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.9.0
Author: Daniel Boldura, HappyBooking UG
Author URI: http://www.happybooking.de/
@ -25,16 +25,7 @@ Author URI: http://www.happybooking.de/
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Planed features and todos:
*
* 1. Collision detection for anchors
* 2. Header hierarchie
* 3. Support markups for show or hide the ToC on single pages/posts
* 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.6' );
define( 'EXTENDED_TOC_VERSION', '0.9.0' );
define( 'EXTENDED_TOC_ID', 'extended_toc' );
define( 'EXTENDED_TOC_NAME', 'Extended-ToC' );
define( 'TOC_MIN_START', 2 );
@ -62,7 +53,7 @@ if( !class_exists('ExToC') ) {
'start' => 3,
'show_heading_text' => true,
'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,
'number_list_items' => true,
);
@ -82,6 +73,9 @@ if( !class_exists('ExToC') ) {
/** Add the content filter and enqueue css **/
add_filter( 'the_content', array(&$this, 'the_content'), 100 );
add_action( 'wp_enqueue_scripts', array(&$this, 'wp_enqueue_scripts') );
add_shortcode( 'extoc', array(&$this, 'shortcode_extoc') );
add_shortcode( 'noextoc', array(&$this, 'shortcode_noextoc') );
}
}
@ -128,6 +122,7 @@ if( !class_exists('ExToC') ) {
'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,
'number_list_items' => (isset($_POST['number_list_items']) && $_POST['number_list_items']) ? true : false,
'heading_levels' => @(array)$_POST['heading_levels'],
)
);
@ -154,9 +149,28 @@ if( !class_exists('ExToC') ) {
<?php echo $msg; ?>
<h2 class="nav-tab-wrapper">
<a class="nav-tab<?php echo !$_GET['tab']||$_GET['tab']==''?' nav-tab-active':''; ?>" href="?page=<?php echo $_GET['page']; ?>"><?php _e('Main Options', 'EXTENDED_TOC_ID'); ?></a>
<a class="nav-tab<?php echo $_GET['tab']=='help'?' nav-tab-active':''; ?>" href="?page=<?php echo $_GET['page']; ?>&amp;tab=help"><?php _e('Help', 'EXTENDED_TOC_ID'); ?></a>
</h2>
<?php
if( !$_GET['tab'] || $_GET['tab'] == '' ) {
$this->displayMainContent();
}
else {
$this->displayHelpContent();
}
?>
</div>
<?php
}
private function displayMainContent() {
?>
<form method="post" action="<?php echo htmlentities('?page=' . $_GET['page'] . '&update'); ?>">
<?php wp_nonce_field( plugin_basename(__FILE__), EXTENDED_TOC_ID ); ?>
<div class="form_container">
<table class="form-table">
<tbody>
@ -213,16 +227,69 @@ if( !class_exists('ExToC') ) {
<input id="number_list_items" type="checkbox" name="number_list_items" <?php if ( $this->options['number_list_items'] ) echo ' checked="checked"'; ?> />
</td>
</tr>
<tr>
<th>
<label for="number_list_items"><?php echo __('Heading levels', EXTENDED_TOC_ID); ?></label>
</th>
<td>
<?php
// show heading 1 to 6 options
for ($i = 1; $i <= 6; $i++) {
echo '<input type="checkbox" value="' . $i . '" id="heading_levels' . $i .'" name="heading_levels[]"';
if ( in_array($i, $this->options['heading_levels']) ) echo ' checked="checked"';
echo ' /><label for="heading_levels' . $i .'"> ' . __('heading ') . $i . ' - h' . $i . '</label><br />';
}
?>
</td>
</tr>
</tbody>
</table>
</div>
<p class="submit"><input class="button-primary" type="submit" value="<?php echo __("Save Options", EXTENDED_TOC_ID)?>" name="submit" /></p>
</form>
</div>
<?php
}
// ToDo: Also allow to markup settings Hierarchie and Kapitelnummer
private function displayHelpContent() {
?>
<div class="form_container">
<h3>Position the ToC</h3>
<div>
The table of contents is generated automatically and is inserted at the very top of your post and, if its paginated, at the top of every subpage. To change the position of the ToC
you can insert the markup [extoc] at the position you want it to be displayed. You have to position the ToC on every subpage, otherwise it will be shown on the subpages again at the top of the page.
</div>
<h3>Blacklist posts/pages</h3>
<div>
If you need a table of content for the main part of you posts and pages, but you want to exclude the ToC from sepcial posts, you can use a blacklist. Per default the ToC is
shown in posts and pages. You can insert the markup [noextoc] to prohibit the insertion of the ToC in this page/post/subpage. This markup also has to be inserted in every subpage, if you use
the nextpage-tag, otherwise it will be inserted within the subpages.
</div>
<h3>Whitelist posts/pages</h3>
<div>
If you have only a few posts where you want the ToC to be inserted, you can switch off the ToC from general settings and insert it within your posts/pages by the markup [extoc].
</div>
<h3>Individual setting withthin the [extoc] markup</h3>
<div>
The [extoc] markup can also be used to change the main settings for the ToC only for some posts/pages.<br /><br />
Example: [extoc start=10 headers=1,2,3 title="My individual ToC title"]<br /><br />
This will insert a ToC that only will be displayed if 10 oder more headings are contained. "headers=1,2,3" means that only the header h1, h2 and h3 are considered for the ToC. The "title" attribute
lets you set an individual title for the ToC. If one of these attributes is missing, the default value will be taken.<br /><br />
You can also remove the title by adding "notitle" e.g. [extoc notitle]. Leaving the title attribute empty will also take the header defined within the general plugin settings.
</div>
</div>
<?php
}
public function wp_enqueue_scripts() {
wp_register_style(EXTENDED_TOC_ID, $this->path . '/style.css', array(), POWER_TOC_VERSION);
wp_enqueue_style(EXTENDED_TOC_ID);
@ -232,6 +299,34 @@ if( !class_exists('ExToC') ) {
load_plugin_textdomain( EXTENDED_TOC_ID, false, dirname(plugin_basename(__FILE__)) . '/locale/' );
}
public function shortcode_extoc($atts) {
extract( shortcode_atts( array(
'start' => $this->options["start"],
'headers' => $this->options["heading_levels"],
'title' => $this->options["heading_text"],
), $atts ) );
$headers = preg_split('/[\s*,]+/i', $headers);
// echo "<pre>"; print_r($headers); echo "</pre>";
if($start) $this->options['start'] = $start;
if($headers) $this->options['heading_levels'] = $headers;
if($title) $this->options['heading_text'] = $title;
if( isset($atts[0]['notitle']) )
$this->options['show_heading_text'] = false;
if ( !is_search() && !is_archive() && !is_feed() )
return '[extoc]';
else
return;
}
public function shortcode_noextoc($atts) {
return;
}
public function the_content($content) {
global $post;
@ -256,11 +351,14 @@ if( !class_exists('ExToC') ) {
$toc_content .= "<ul class=\"no-bullets\">";
$toc_content .= $this->extract_toc();
$toc_content .= "</ul></div>";
if( $this->totalHeadings >= $this->options['start'] )
return $this->insert_toc_at_markup_position($toc_content); // $toc_content . $this->content;
else
return $this->content;
else {
$content = preg_replace("/\[extoc\]|\[noextoc\]/", "", $this->content);
return $content;
}
}
/** returns the content for display added by the ToC */
@ -268,7 +366,7 @@ if( !class_exists('ExToC') ) {
// clean content without markups for returning
$content = $this->content;
$content = preg_replace("/\[extoc\]|\[noextoc\]/", "", $content);
// [noextoc] has priority. If this is found, return the original
if( strpos($this->content, '[noextoc]') !== false )
return $content;
@ -326,7 +424,7 @@ if( !class_exists('ExToC') ) {
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']) )
if( in_array($matches[$i][2], $this->options['heading_levels']) )
$new_matches[] = $matches[$i];
}
$matches = $new_matches;
@ -364,25 +462,29 @@ if( !class_exists('ExToC') ) {
if( $matches[$i][2] > $currentLevel && $this->options['show_hierarchy'] == true) {
$currentLevel = $matches[$i][2];
$this->counter[$currentLevel] = 1;
// echo '$this->counter['.$currentLevel.'] = 1 <br>';
}
else if( $matches[$i][2] < $currentLevel && $matches[$i][2] >= $this->minLevel && $this->options['show_hierarchy'] == true) {
$currentLevel = $matches[$i][2];
$this->counter[$currentLevel] += 1;
// echo '$this->counter['.$currentLevel.'] += 1 <br>';
}
else {
$this->counter[$currentLevel] += 1;
// echo '$this->counter['.$currentLevel.'] += 1 <br>';
}
/** build html */
$items .= '<li class="header-level-' . ($currentLevel - $this->minLevel + 1) . '">';
// echo $currentLevel . ' - ' . $this->minLevel . ' <br>';
$items .= '<a href="?p='.$this->ID.($pagenum>0?'&page='.$pagenum:'').'#' . $anchor . '">';
// echo $currentLevel . ' - ' . $this->minLevel . ' <br>';
global $page;
if( $pagenum == $page )
$items .= '<a href="#' . $anchor . '">';
else {
if( $pagenum == 1 )
$items .= '<a href="' . get_permalink($this->ID) . '#' . $anchor . '">';
else
$items .= '<a href="?p='.$this->ID.($pagenum>1?'&page='.$pagenum:'').'#' . $anchor . '">';
}
// Show numbers only if user wants it
if( $this->options['number_list_items'] ) {

View File

@ -3,8 +3,8 @@ Contributors: happybooking
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.8.4
Tested up to: 3.6.1
Stable tag: 0.9.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@ -12,7 +12,7 @@ This plugin automatically generates and inserts a table of contents (ToC) to you
== 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.
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.
= Available Languages =
* English
@ -40,6 +40,13 @@ You can change the default settings and more under Plugins > Extended-ToC
If you have any questions or suggestions please contact us at any time: support@happybooking.de or http://www.happybooking.de/
== Changelog ==
= 0.9.0 =
* Added markups [extoc] [noextoc]
* Inidivual settings within markup per post/page
* Optimisation for SEO by removing "page=1"
* No page reload when anchor is on the same page (Performance optimisation)
* Help Tab added with some examples
= 0.8.6 =
* Permalink bug not linking correctly to the first page of the ToC fixed