/**
         * Displays the widget settings on the Widgets admin page.
         *
         * @access private
         * @since  1.0
         *
         * @param array $instance
         *
         * @return string|void
         */
        public function form($instance)
        {
            $defaults = array('affix' => '0', 'highlight_color' => '#ededed', 'title' => '');
            $instance = wp_parse_args((array) $instance, $defaults);
            $highlight_color = esc_attr($instance['highlight_color']);
            ?>
			<p>
				<label for="<?php 
            echo $this->get_field_id('title');
            ?>
"><?php 
            _e('Title', 'ez_toc');
            ?>
:</label>
				<input type="text" id="<?php 
            echo $this->get_field_id('title');
            ?>
"
				       name="<?php 
            echo $this->get_field_name('title');
            ?>
" value="<?php 
            echo $instance['title'];
            ?>
"
				       style="width:100%;"/>
			</p>

			<p>
				<label for="<?php 
            echo $this->get_field_id('highlight_color');
            ?>
"><?php 
            _e('Active Section Highlight Color:', 'ez_toc');
            ?>
</label><br>
				<input type="text" name="<?php 
            echo $this->get_field_name('highlight_color');
            ?>
" class="color-picker" id="<?php 
            echo $this->get_field_id('highlight_color');
            ?>
" value="<?php 
            echo $highlight_color;
            ?>
" data-default-color="<?php 
            echo $defaults['highlight_color'];
            ?>
" />
			</p>

			<p style="display: <?php 
            echo ezTOC_Option::get('widget_affix_selector') ? 'block' : 'none';
            ?>
;">
				<input class="checkbox" type="checkbox" <?php 
            checked($instance['affix'], 1);
            ?>
				       id="<?php 
            echo $this->get_field_id('affix');
            ?>
"
				       name="<?php 
            echo $this->get_field_name('affix');
            ?>
" value="1"/>
				<label for="<?php 
            echo $this->get_field_id('affix');
            ?>
"> <?php 
            _e('Affix or pin the widget.', 'ez_toc');
            ?>
</label>
			</p>

			<p class="description" style="display: <?php 
            echo ezTOC_Option::get('widget_affix_selector') ? 'block' : 'none';
            ?>
;">
				<?php 
            _e('If you choose to affix the widget, do not add any other widgets on the sidebar. Also, make sure you have only one instance Table of Contents widget on the page.', 'ez_toc');
            ?>
			</p>
			<?php 
        }
 /**
  * Callback for the `the_content` filter.
  *
  * This will add the inline table of contents page anchors to the post content. It will also insert the
  * table of contents inline with the post content as defined by the user defined preference.
  *
  * @access private
  * @since  1.0
  * @static
  *
  * @param string $content
  *
  * @return string
  */
 public static function the_content($content)
 {
     $css_classes = '';
     $html = '';
     $find = array();
     $replace = array();
     $items = self::extract_headings($find, $replace, $content);
     if ($items) {
         if (self::is_eligible()) {
             // wrapping css classes
             switch (ezTOC_Option::get('wrapping')) {
                 case 'left':
                     $css_classes .= ' ez-toc-wrap-left';
                     break;
                 case 'right':
                     $css_classes .= ' ez-toc-wrap-right';
                     break;
                 case 'none':
                 default:
                     // do nothing
             }
             if (ezTOC_Option::get('show_hierarchy')) {
                 $css_classes .= ' counter-hierarchy';
             } else {
                 $css_classes .= ' counter-flat';
             }
             switch (ezTOC_Option::get('counter')) {
                 case 'numeric':
                     $css_classes .= ' counter-numeric';
                     break;
                 case 'roman':
                     $css_classes .= ' counter-roman';
                     break;
                 case 'decimal':
                     $css_classes .= ' counter-decimal';
                     break;
             }
             // colour themes
             switch (ezTOC_Option::get('theme')) {
                 case 'light-blue':
                     $css_classes .= ' ez-toc-light-blue';
                     break;
                 case 'white':
                     $css_classes .= ' ez-toc-white';
                     break;
                 case 'black':
                     $css_classes .= ' ez-toc-black';
                     break;
                 case 'transparent':
                     $css_classes .= ' ez-toc-transparent';
                     break;
                 case 'grey':
                     $css_classes .= ' ez-toc-grey';
                     break;
                 default:
                     // do nothing
             }
             // bullets?
             //if ( ezTOC_Option::get( 'bullet_spacing' ) ) {
             //
             //	$css_classes .= ' have_bullets';
             //
             //} else {
             //
             //	$css_classes .= ' no_bullets';
             //}
             if (ezTOC_Option::get('css_container_class')) {
                 $css_classes .= ' ' . ezTOC_Option::get('css_container_class');
             }
             $css_classes = trim($css_classes);
             // an empty class="" is invalid markup!
             if (!$css_classes) {
                 $css_classes = ' ';
             }
             // add container, toc title and list items
             $html .= '<div id="ez-toc-container" class="' . $css_classes . '">' . PHP_EOL;
             if (ezTOC_Option::get('show_heading_text')) {
                 $toc_title = ezTOC_Option::get('heading_text');
                 if (strpos($toc_title, '%PAGE_TITLE%') !== FALSE) {
                     $toc_title = str_replace('%PAGE_TITLE%', get_the_title(), $toc_title);
                 }
                 if (strpos($toc_title, '%PAGE_NAME%') !== FALSE) {
                     $toc_title = str_replace('%PAGE_NAME%', get_the_title(), $toc_title);
                 }
                 $html .= '<div class="ez-toc-title-container">' . PHP_EOL;
                 $html .= '<p class="ez-toc-title">' . esc_html(htmlentities($toc_title, ENT_COMPAT, 'UTF-8')) . '</p>' . PHP_EOL;
                 $html .= '<span class="ez-toc-title-toggle">';
                 if (ezTOC_Option::get('visibility')) {
                     $html .= '<a class="pull-right btn btn-xs btn-default ez-toc-toggle"><i class="glyphicon ez-toc-icon-toggle"></i></a>';
                 }
                 $html .= '</span>';
                 $html .= '</div>' . PHP_EOL;
             }
             ob_start();
             do_action('ez_toc_before');
             $html .= ob_get_clean();
             $html .= '<ul class="ez-toc-list">' . $items . '</ul>';
             ob_start();
             do_action('ez_toc_after');
             $html .= ob_get_clean();
             $html .= '</div>' . PHP_EOL;
         }
         if (count($find) > 0) {
             switch (ezTOC_Option::get('position')) {
                 case 'top':
                     $content = $html . self::mb_find_replace($find, $replace, $content);
                     break;
                 case 'bottom':
                     $content = self::mb_find_replace($find, $replace, $content) . $html;
                     break;
                 case 'after':
                     $replace[0] = $replace[0] . $html;
                     $content = self::mb_find_replace($find, $replace, $content);
                     break;
                 case 'before':
                 default:
                     $replace[0] = $html . $replace[0];
                     $content = self::mb_find_replace($find, $replace, $content);
             }
         }
         // Enqueue the script.
         wp_enqueue_script('ez-toc-js');
     }
     return $content;
 }
        /**
         * Callback to render the content of the table of contents metaboxes.
         *
         * @access private
         * @since  1.0
         * @static
         *
         * @param object $post The post object.
         * @param        $atts
         */
        public function displayMetabox($post, $atts)
        {
            // Add an nonce field so we can check for it on save.
            wp_nonce_field('ez_toc_save', '_ez_toc_nonce');
            $suppress = get_post_meta($post->ID, '_ez-toc-disabled', TRUE) == 1 ? TRUE : FALSE;
            $insert = get_post_meta($post->ID, '_ez-toc-insert', TRUE) == 1 ? TRUE : FALSE;
            $headings = get_post_meta($post->ID, '_ez-toc-heading-levels', TRUE);
            $exclude = get_post_meta($post->ID, '_ez-toc-exclude', TRUE);
            $altText = get_post_meta($post->ID, '_ez-toc-alttext', TRUE);
            if (!is_array($headings)) {
                $headings = array();
            }
            ?>

			<table class="form-table">

				<tbody>

				<tr>
					<th scope="row"></th>
					<td>

						<?php 
            if (in_array(get_post_type($post), ezTOC_Option::get('auto_insert_post_types', array()))) {
                ezTOC_Option::checkbox(array('id' => 'disabled-toc', 'desc' => esc_html__('Disable the automatic insertion of the table of contents.', 'ez_toc'), 'default' => $suppress), $suppress);
            } elseif (in_array(get_post_type($post), ezTOC_Option::get('enabled_post_types', array()))) {
                ezTOC_Option::checkbox(array('id' => 'insert-toc', 'desc' => esc_html__('Insert table of contents.', 'ez_toc'), 'default' => $insert), $insert);
            }
            ?>

					</td>
				</tr>

				<tr>
					<th scope="row"><?php 
            esc_html_e('Advanced:', 'ez_toc');
            ?>
</th>
					<td>
						<?php 
            ezTOC_Option::descriptive_text(array('id' => 'exclude-desc', 'name' => '', 'desc' => '<p><strong>' . esc_html__('NOTE:', 'ez_toc') . '</strong></p>' . '<ul>' . '<li>' . esc_html__('Using the advanced options below will override the global advanced settings.', 'ez_toc') . '</li>' . '</ul>'));
            ?>
					</td>
				</tr>

				<tr>
					<th scope="row"><?php 
            esc_html_e('Headings:', 'ez_toc');
            ?>
</th>
					<td>
						<?php 
            ezTOC_Option::checkboxgroup(array('id' => 'heading-levels', 'desc' => esc_html__('Select the heading to consider when generating the table of contents. Deselecting a heading will exclude it.', 'ez_toc'), 'options' => array('1' => __('Heading 1 (h1)', 'ez_toc'), '2' => __('Heading 2 (h2)', 'ez_toc'), '3' => __('Heading 3 (h3)', 'ez_toc'), '4' => __('Heading 4 (h4)', 'ez_toc'), '5' => __('Heading 5 (h5)', 'ez_toc'), '6' => __('Heading 6 (h6)', 'ez_toc')), 'default' => array()), array_map('absint', $headings));
            ?>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php 
            esc_html_e('Alternate Headings', 'ez_toc');
            ?>
</th>
					<td>
						<?php 
            ezTOC_Option::textarea(array('id' => 'alttext', 'desc' => __('Specify alternate table of contents header string. Add the header to be replaced and the alternate header on a single line separated with a pipe <code>|</code>. Put each additional original and alternate header on its own line.', 'ez_toc'), 'size' => 'large', 'default' => ''), esc_textarea($altText));
            ?>
					</td>
				</tr>
				<tr>
					<th scope="row"></th>
					<td>
						<?php 
            ezTOC_Option::descriptive_text(array('id' => 'alttext-desc', 'name' => '', 'desc' => '<p><strong>' . esc_html__('Examples:', 'ez_toc') . '</strong></p>' . '<ul>' . '<li>' . __('<code>Level [1.1]|Alternate TOC Header</code> Replaces Level [1.1] in the table of contents with Alternate TOC Header.', 'ez_toc') . '</li>' . '</ul>' . '<p>' . __('<strong>Note:</strong> This is case sensitive.', 'ez_toc') . '</p>'));
            ?>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php 
            esc_html_e('Exclude Headings', 'ez_toc');
            ?>
</th>
					<td>
						<?php 
            ezTOC_Option::text(array('id' => 'exclude', 'desc' => __('Specify headings to be excluded from appearing in the table of contents. Separate multiple headings with a pipe <code>|</code>. Use an asterisk <code>*</code> as a wildcard to match other text.', 'ez_toc'), 'size' => 'large', 'default' => ''), esc_textarea($exclude));
            ?>
					</td>
				</tr>
				<tr>
					<th scope="row"></th>
					<td>
						<?php 
            ezTOC_Option::descriptive_text(array('id' => 'exclude-desc', 'name' => '', 'desc' => '<p><strong>' . esc_html__('Examples:', 'ez_toc') . '</strong></p>' . '<ul>' . '<li>' . __('<code>Fruit*</code> Ignore headings starting with "Fruit".', 'ez_toc') . '</li>' . '<li>' . __('<code>*Fruit Diet*</code> Ignore headings with "Fruit Diet" somewhere in the heading.', 'ez_toc') . '</li>' . '<li>' . __('<code>Apple Tree|Oranges|Yellow Bananas</code> Ignore headings that are exactly "Apple Tree", "Oranges" or "Yellow Bananas".', 'ez_toc') . '</li>' . '</ul>' . '<p>' . __('<strong>Note:</strong> This is not case sensitive.', 'ez_toc') . '</p>'));
            ?>
					</td>
				</tr>
				</tbody>
			</table>

			<?php 
        }