hooks(); } /** * Add the core admin hooks. * * @access private * @since 1.0 * @static */ private function hooks() { global $pagenow; if($pagenow == 'options-general.php' && isset($_REQUEST['page']) && !empty($_REQUEST['page']) && $_REQUEST['page'] == 'table-of-contents') { add_action( 'admin_head', array( $this,'_clean_other_plugins_stuff' ) ); } add_action( 'admin_init', array( $this, 'registerScripts' ) ); add_action( 'admin_menu', array( $this, 'menu' ) ); add_action( 'init', array( $this, 'registerMetaboxes' ), 99 ); add_filter( 'plugin_action_links_' . EZ_TOC_BASE_NAME, array( $this, 'pluginActionLinks' ), 10, 2 ); add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts' ) ); add_action('wp_ajax_eztoc_send_query_message', array( $this, 'eztoc_send_query_message')); } /** * Attach to admin_head hook to hide all admin notices. * * @scope public * @since 2.0.33 * @return void * @uses remove_all_actions() */ public function _clean_other_plugins_stuff() { remove_all_actions('admin_notices'); remove_all_actions('network_admin_notices'); remove_all_actions('all_admin_notices'); remove_all_actions('user_admin_notices'); } /** * Callback to add the Settings link to the plugin action links. * * @access private * @since 1.0 * @static * * @param $links * @param $file * * @return array */ public function pluginActionLinks( $links, $file ) { $url = add_query_arg( 'page', 'table-of-contents', self_admin_url( 'options-general.php' ) ); $setting_link = '' . __( 'Settings', 'easy-table-of-contents' ) . ' |'; $setting_link .= '' . __( ' Support', 'easy-table-of-contents' ) . ' |'; $setting_link .= '' . __( ' Upgrade', 'easy-table-of-contents' ) . ' |'; $setting_link .= '' . __( ' Website', 'easy-table-of-contents' ) . ''; array_push( $links, $setting_link ); return $links; } /** * Register the scripts used in the admin. * * @access private * @since 1.0 * @static */ public function registerScripts() { $min = defined ( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_register_script( 'cn_toc_admin_script', EZ_TOC_URL . "assets/js/admin$min.js", array( 'jquery', 'wp-color-picker' ), ezTOC::VERSION, true ); wp_register_style( 'cn_toc_admin_style', EZ_TOC_URL . "assets/css/admin$min.css", array( 'wp-color-picker' ), ezTOC::VERSION ); wp_enqueue_script( 'cn_toc_admin_script' ); $data = array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'eztoc_security_nonce' => wp_create_nonce('eztoc_ajax_check_nonce'), ); $data = apply_filters( 'eztoc_localize_filter', $data, 'eztoc_admin_data' ); wp_localize_script( 'cn_toc_admin_script', 'cn_toc_admin_data', $data ); self::inlineAdminAMPNonJS(); self::inlineAdminHeadingsPaddingJS(); self::inlineAdminDisplayHeaderLabel(); self::inlineAdminInitialView(); } /** * inlineAdminAMPNonJS Method * Prints out inline AMP Non JS. * * @access private * @return void * @since 2.0.46 * @static */ private static function inlineAdminAMPNonJS() { $isAmpActivated = false; if ( function_exists('ez_toc_is_amp_activated') ) { $isAmpActivated = ez_toc_is_amp_activated(); } if( false == $isAmpActivated ) { $inlineAdminAMPNonJS = << 0 ) { $(tocAMPSupportOption).attr('disabled', true); } }); inlineAdminAMPNonJS; wp_add_inline_script( 'cn_toc_admin_script', $inlineAdminAMPNonJS ); } } /** * inlineAdminHeadingsPaddingJS Method * Prints out inline AMP Non JS. * * @access private * @return void * @since 2.0.48 * @static */ private static function inlineAdminHeadingsPaddingJS() { $inlineAdminHeadingsPaddingJS = <<
   " + $(headingsPaddingTopHTML).html() + ""); $('#eztoc-appearance').find("select[name='ez-toc-settings[headings-padding-top_units]']").html(''); let headingsPaddingBottomHTML = $(headingsPaddingBottom).parent(); $(headingsPaddingBottomHTML).find("input[name='ez-toc-settings[headings-padding-bottom]']").attr("type", "number"); $(headingsPaddingBottom).parents('tr').remove(); $(headingsPaddingCheckbox).parent().append("       " + $(headingsPaddingBottomHTML).html() + ""); $('#eztoc-appearance').find("select[name='ez-toc-settings[headings-padding-bottom_units]']").html(''); let headingsPaddingLeftHTML = $(headingsPaddingLeft).parent(); $(headingsPaddingLeftHTML).find("input[name='ez-toc-settings[headings-padding-left]']").attr("type", "number"); $(headingsPaddingLeft).parents('tr').remove(); $(headingsPaddingCheckbox).parent().append("       " + $(headingsPaddingLeftHTML).html() + ""); $('#eztoc-appearance').find("select[name='ez-toc-settings[headings-padding-left_units]']").html(''); let headingsPaddingRightHTML = $(headingsPaddingRight).parent(); $(headingsPaddingRightHTML).find("input[name='ez-toc-settings[headings-padding-right]']").attr("type", "number"); $(headingsPaddingRight).parents('tr').remove(); $(headingsPaddingCheckbox).parent().append("       " + $(headingsPaddingRightHTML).html() + ""); $('#eztoc-appearance').find("select[name='ez-toc-settings[headings-padding-right_units]']").html(''); let headingsPaddingContainerTop = $('#eztoc-appearance').find("span#headings-padding-top-container"); let headingsPaddingContainerBottom = $('#eztoc-appearance').find("span#headings-padding-bottom-container"); let headingsPaddingContainerLeft = $('#eztoc-appearance').find("span#headings-padding-left-container"); let headingsPaddingContainerRight = $('#eztoc-appearance').find("span#headings-padding-right-container"); if($(headingsPaddingCheckbox).prop('checked') == false) { $(headingsPaddingContainerTop).hide(500); $(headingsPaddingContainerBottom).hide(500); $(headingsPaddingContainerLeft).hide(500); $(headingsPaddingContainerRight).hide(500); $(headingsPaddingTop).val(0); $(headingsPaddingBottom).val(0); $(headingsPaddingLeft).val(0); $(headingsPaddingRight).val(0); } $(document).on("change, click", "input[name='ez-toc-settings[headings-padding]']", function() { if($(headingsPaddingCheckbox).prop('checked') == true) { $(headingsPaddingContainerTop).show(500); $(headingsPaddingContainerBottom).show(500); $(headingsPaddingContainerLeft).show(500); $(headingsPaddingContainerRight).show(500); } else { $(headingsPaddingContainerTop).hide(500); $(headingsPaddingContainerBottom).hide(500); $(headingsPaddingContainerLeft).hide(500); $(headingsPaddingContainerRight).hide(500); $(headingsPaddingTop).val(0); $(headingsPaddingBottom).val(0); $(headingsPaddingLeft).val(0); $(headingsPaddingRight).val(0); } }); }); inlineAdminHeadingsPaddingJS; wp_add_inline_script( 'cn_toc_admin_script', $inlineAdminHeadingsPaddingJS ); } /** * inlineAdminDisplayHeaderLabel Method * Prints out inline AMP Non JS. * * @access private * @return void * @since 2.0.51 * @static */ private static function inlineAdminDisplayHeaderLabel() { $inlineAdminDisplayHeaderLabel = <<ID, '_ez-toc-disabled', true ) == 1 ? true : false; $insert = get_post_meta( $post->ID, '_ez-toc-insert', true ) == 1 ? true : false; $header_label = get_post_meta( $post->ID, '_ez-toc-header-label', true ); $alignment = get_post_meta( $post->ID, '_ez-toc-alignment', true ); $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 ); $initial_view = get_post_meta( $post->ID, '_ez-toc-visibility_hide_by_default', true ); $hide_counter = get_post_meta( $post->ID, '_ez-toc-hide_counter', true ); if ( ! is_array( $headings ) ) { $headings = array(); } ?>
'disabled-toc', 'desc' => esc_html__( 'Disable the automatic insertion of the table of contents.', 'easy-table-of-contents' ), '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.', 'easy-table-of-contents' ), 'default' => $insert, ), $insert ); endif; ?>
'header-label', 'desc' => '
'.__( 'Eg: Contents, Table of Contents, Page Contents', 'easy-table-of-contents' ), 'default' => $header_label, ), $header_label ); ?>
'appearance-desc', 'desc' => '

' . esc_html__( 'NOTE:', 'easy-table-of-contents' ) . '

' . '
    ' . '
  • ' . esc_html__( 'Using the appearance options below will override the global Appearance settings.', 'easy-table-of-contents' ) . '
  • ' . '
', ) ); ?>
'toc-alignment', 'options' => array( 'none' => __( 'None (Default)', 'easy-table-of-contents' ), 'left' => __( 'Left', 'easy-table-of-contents' ), 'right' => __( 'Right', 'easy-table-of-contents' ), 'center' => __( 'Center', 'easy-table-of-contents' ), ), 'default' => $alignment, ), $alignment ); ?>
'exclude-desc', 'name' => '', 'desc' => '

' . esc_html__( 'NOTE:', 'easy-table-of-contents' ) . '

' . '
    ' . '
  • ' . esc_html__( 'Using the advanced options below will override the global advanced settings.', 'easy-table-of-contents' ) . '
  • ' . '
', ) ); ?>
'heading-levels', 'desc' => esc_html__( 'Select the heading to consider when generating the table of contents. Deselecting a heading will exclude it.', 'easy-table-of-contents' ), 'options' => array( '1' => __( 'Heading 1 (h1)', 'easy-table-of-contents' ), '2' => __( 'Heading 2 (h2)', 'easy-table-of-contents' ), '3' => __( 'Heading 3 (h3)', 'easy-table-of-contents' ), '4' => __( 'Heading 4 (h4)', 'easy-table-of-contents' ), '5' => __( 'Heading 5 (h5)', 'easy-table-of-contents' ), '6' => __( 'Heading 6 (h6)', 'easy-table-of-contents' ), ), 'default' => array(), ), array_map( 'absint', $headings ) ); ?>
'visibility_hide_by_default', 'name' => __( 'Initial View', 'easy-table-of-contents' ), 'desc' => __( 'Initially hide the table of contents.', 'easy-table-of-contents' ), 'default' => false, ), $initial_view ); ?>
'hide_counter', 'name' => __( 'Hide Counter', 'easy-table-of-contents' ), 'desc' => __( 'Do not show counters for the table of contents.', 'easy-table-of-contents' ), 'default' => false, ), $hide_counter ); ?>
'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 |. Put each additional original and alternate header on its own line.', 'easy-table-of-contents' ), 'size' => 'large', 'default' => '', ), $altText ); ?>
'alttext-desc', 'name' => '', 'desc' => '

' . esc_html__( 'Examples:', 'easy-table-of-contents' ) . '

' . '
    ' . '
  • ' . __( 'Level [1.1]|Alternate TOC Header Replaces Level [1.1] in the table of contents with Alternate TOC Header.', 'easy-table-of-contents' ) . '
  • ' . '
' . '

' . __( 'Note: This is case sensitive.', 'easy-table-of-contents' ) . '

', ) ); ?>
'exclude', 'desc' => __( 'Specify headings to be excluded from appearing in the table of contents. Separate multiple headings with a pipe |. Use an asterisk * as a wildcard to match other text.', 'easy-table-of-contents' ), 'size' => 'large', 'default' => '', ), $exclude ); ?>
'exclude-desc', 'name' => '', 'desc' => '

' . esc_html__( 'Examples:', 'easy-table-of-contents' ) . '

' . '
    ' . '
  • ' . __( 'Fruit* Ignore headings starting with "Fruit".', 'easy-table-of-contents' ) . '
  • ' . '
  • ' . __( '*Fruit Diet* Ignore headings with "Fruit Diet" somewhere in the heading.', 'easy-table-of-contents' ) . '
  • ' . '
  • ' . __( 'Apple Tree|Oranges|Yellow Bananas Ignore headings that are exactly "Apple Tree", "Oranges" or "Yellow Bananas".', 'easy-table-of-contents' ) . '
  • ' . '
' . '

' . __( 'Note: This is not case sensitive.', 'easy-table-of-contents' ) . '

', ) ); ?>
admin_url( 'admin-ajax.php' ), 'eztoc_security_nonce' => wp_create_nonce('eztoc_ajax_check_nonce'), ); $data = apply_filters('eztoc_localize_filter',$data,'eztoc_admin_data'); wp_localize_script( 'eztoc-admin-js', 'eztoc_admin_data', $data ); $this->eztoc_dequeue_scripts(); } } /** * This is a ajax handler function for sending email from user admin panel to us. * @return type json string */ public function eztoc_send_query_message(){ if ( ! isset( $_POST['eztoc_security_nonce'] ) ){ return; } if ( !wp_verify_nonce( $_POST['eztoc_security_nonce'], 'eztoc_ajax_check_nonce' ) ){ return; } if ( !current_user_can( 'manage_options' ) ) { return; } $message = $this->eztoc_sanitize_textarea_field($_POST['message']); $email = sanitize_email($_POST['email']); if(function_exists('wp_get_current_user')){ $user = wp_get_current_user(); $message = '

'.$message.'



'.'Query from Easy Table of Content plugin support tab'; $user_data = $user->data; $user_email = $user_data->user_email; if($email){ $user_email = $email; } //php mailer variables $sendto = 'team@magazine3.in'; $subject = "Easy Table of Content Query"; $headers[] = 'Content-Type: text/html; charset=UTF-8'; $headers[] = 'From: '. esc_attr($user_email); $headers[] = 'Reply-To: ' . esc_attr($user_email); // Load WP components, no themes. $sent = wp_mail($sendto, $subject, $message, $headers); if($sent){ echo json_encode(array('status'=>'t')); }else{ echo json_encode(array('status'=>'f')); } } wp_die(); } public function eztoc_sanitize_textarea_field( $str ) { if ( is_object( $str ) || is_array( $str ) ) { return ''; } $str = (string) $str; $filtered = wp_check_invalid_utf8( $str ); if ( strpos( $filtered, '<' ) !== false ) { $filtered = wp_pre_kses_less_than( $filtered ); // This will strip extra whitespace for us. $filtered = wp_strip_all_tags( $filtered, false ); // Use HTML entities in a special case to make sure no later // newline stripping stage could lead to a functional tag. $filtered = str_replace( "<\n", "<\n", $filtered ); } $filtered = trim( $filtered ); $found = false; while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) { $filtered = str_replace( $match[0], '', $filtered ); $found = true; } if ( $found ) { // Strip out the whitespace that may now exist after removing the octets. $filtered = trim( preg_replace( '/ +/', ' ', $filtered ) ); } return $filtered; } /** * Callback used to render the admin options page. * * @access private * @since 1.0 * @static */ public function page() { include EZ_TOC_PATH . '/includes/inc.admin-options-page.php'; } /** * Function used to dequeue unwanted scripts on ETOC settings page. * * @since 2.0.52 */ public function eztoc_dequeue_scripts() { wp_dequeue_script( 'chats-js' ); wp_dequeue_script( 'custom_wp_admin_js' ); } } new ezTOC_Admin(); }