Reformating

This commit is contained in:
Eric van der Vlist 2020-05-09 12:15:44 +02:00
parent eccd03b749
commit 9c5f86fc7b
1 changed files with 510 additions and 512 deletions

View File

@ -34,8 +34,9 @@ define( 'TOC_MIN_START', 2 );
define('TOC_MAX_START', 10);
if (!class_exists('ExToC')) {
class ExToC
{
class ExToC {
private $path;
private $content = "";
private $fullcontent = "";
@ -70,8 +71,7 @@ if( !class_exists('ExToC') ) {
add_action('admin_init', array(&$this, 'admin_init'));
add_action('admin_menu', array(&$this, 'admin_menu'));
}
else {
} else {
/** 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'));
@ -82,6 +82,7 @@ if( !class_exists('ExToC') ) {
}
public function __destruct() {
}
public function register_plugin_links($links, $file) {
@ -92,7 +93,6 @@ if( !class_exists('ExToC') ) {
return $links;
}
public function admin_init() {
wp_register_style(EXTENDED_TOC_ID, $this->path . '/admin-style.css', array(), EXTENDED_TOC_VERSION);
wp_enqueue_style(EXTENDED_TOC_ID);
@ -103,8 +103,7 @@ if( !class_exists('ExToC') ) {
$page = add_submenu_page('plugins.php', EXTENDED_TOC_NAME, EXTENDED_TOC_NAME, 'manage_options', EXTENDED_TOC_ID, array(&$this, 'admin_options'));
}
private function save_admin_options()
{
private function save_admin_options() {
global $post_id;
// security check
@ -159,8 +158,7 @@ if( !class_exists('ExToC') ) {
<?php
if (!$_GET['tab'] || $_GET['tab'] == '') {
$this->displayMainContent();
}
else {
} else {
$this->displayHelpContent();
}
?>
@ -207,7 +205,8 @@ if( !class_exists('ExToC') ) {
<?php
for ($i = TOC_MIN_START; $i <= TOC_MAX_START; $i++) {
echo '<option value="' . $i . '"';
if ( $i == $this->options['start'] ) echo ' selected="selected"';
if ($i == $this->options['start'])
echo ' selected="selected"';
echo '>' . $i . '</option>' . "\n";
}
?>
@ -239,7 +238,8 @@ if( !class_exists('ExToC') ) {
// 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"';
if (in_array($i, $this->options['heading_levels']))
echo ' checked="checked"';
echo ' /><label for="heading_levels' . $i . '"> ' . __('heading ') . $i . ' - h' . $i . '</label><br />';
}
?>
@ -311,9 +311,12 @@ if( !class_exists('ExToC') ) {
if (!is_array($headers))
$headers = preg_split('/[\s*,]+/i', $headers);
if($start) $this->options['start'] = $start;
if($headers) $this->options['heading_levels'] = $headers;
if($title) $this->options['heading_text'] = $title;
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;
@ -360,12 +363,10 @@ if( !class_exists('ExToC') ) {
}
/** returns the content for display added by the ToC */
private function insert_toc_at_markup_position($toc_content)
{
private function insert_toc_at_markup_position($toc_content) {
// clean content without markups for returning
$content = $this->content;
$content = preg_replace("/\[noextoc\]/", "", $content); // preg_replace("/\[extoc\]|\[noextoc\]/", "", $content);
// [noextoc] has priority. If this is found, return the original
if (strpos($this->content, '[noextoc]') !== false)
return $content;
@ -384,8 +385,7 @@ if( !class_exists('ExToC') ) {
}
// In this case, the markup was found in the content
if( is_numeric($pos) && $pos >= 0 )
{
if (is_numeric($pos) && $pos >= 0) {
return str_replace('[extoc]', $toc_content, $content); // substr($content, 0, $pos) . $toc_content . substr($content, $pos);
}
@ -480,12 +480,10 @@ if( !class_exists('ExToC') ) {
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] >= $this->minLevel && $this->options['show_hierarchy'] == true) {
} else if ($matches[$i][2] < $currentLevel && $matches[$i][2] >= $this->minLevel && $this->options['show_hierarchy'] == true) {
$currentLevel = $matches[$i][2];
$this->counter[$currentLevel] += 1;
}
else {
} else {
$this->counter[$currentLevel] += 1;
}
@ -525,8 +523,7 @@ if( !class_exists('ExToC') ) {
return $items;
}
private function url_encode_anchor($anchor)
{
private function url_encode_anchor($anchor) {
$return = false;
if (!empty($anchor)) {
@ -549,10 +546,11 @@ if( !class_exists('ExToC') ) {
return $return;
}
}
}
/** Initialise the class */
$tocPlugin = new ExToC();
?>