get( 'bg' ); $color_ti = $HELPDOCS_COLORS->get( 'ti' ); ?> -1, 'post_status' => 'publish', 'post_type' => $post_type, 'meta_key' => HELPDOCS_GO_PF.'site_location', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key 'meta_value' => base64_encode( 'main' ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value 'meta_compare' => '=', ]; // Are we filtering by category? // Must be category id if ( $cat = absint( helpdocs_get( 'cat' ) ) ) { $args[ 'category' ] = absint( $cat ); } // Are we filtering by tag? // Must be slug if ( $tag = sanitize_text_field( helpdocs_get( 'tag' ) ) ) { $args[ 'tag' ] = $tag; } // Get the posts $docs = get_posts( $args ); // Also get the imports $imports = helpdocs_get_imports( $args ); // Merge them together if ( !empty( $imports ) ) { $docs = array_merge( $docs, $imports ); } // Stop if no posts are found if ( !$docs ) { echo '


No documents found. Start by clicking "Add New" above!'; return; } // First we sort by the doc order usort( $docs, function( $a, $b ) { return $a->helpdocs_order - $b->helpdocs_order; } ); // Are we searching for something? if ( helpdocs_get( 'search' ) ) { $s = sanitize_text_field( helpdocs_get( 'search' ) ); $current_url = add_query_arg( 'search', $s, $current_url ); } else { $s = ''; } // Get the folders $folder_taxonomy = 'help-docs-folder'; $folders = get_terms( [ 'taxonomy' => $folder_taxonomy, 'hide_empty' => false, 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query [ 'key' => HELPDOCS_GO_PF.'order', 'type' => 'NUMERIC', ] ], ] ); // Add Expand and Collapse links, only if folders exist if ( !empty( $folders ) ) { $folder_action_links = 'Expand Folders Collapse Folders'; } else { $folder_action_links = ''; } // Search bar echo ''; // Check if we are viewing a doc if ( $get_id = helpdocs_get( 'id' ) ) { $current_doc_id = $get_id; } elseif ( $s !== '' ) { $current_doc_id = false; } else { // Check if we have a default $default_doc_id = get_option( HELPDOCS_GO_PF.'default_doc' ); if ( $default_doc_id && 'publish' == get_post_status( $default_doc_id ) ) { if ( get_post_meta( $default_doc_id, HELPDOCS_GO_PF.'site_location', true ) && get_post_meta( $default_doc_id, HELPDOCS_GO_PF.'site_location', true ) == base64_encode( 'main' ) ) { $current_doc_id = $default_doc_id; } else { $current_doc_id = false; } } else { $current_doc_id = false; } if ( $current_doc_id ) { helpdocs_add_qs_without_refresh( 'id', $current_doc_id ); } } // Store the current doc here $current_doc = (Object)[]; $feed = false; // Icons $file_icon = '1F4C4'; // Start the full page container echo '
'; /** * Let's add a table of contents */ // Create a nonce $nonce = wp_create_nonce( 'drag-doc-toc' ); // Start the toc container echo '
'; /** * Now load the document in the viewer */ // Make sure the current doc is set $current_doc_as_array = (array)$current_doc; if ( !empty( $current_doc_as_array ) ) { // Start the toc container echo '
'; // Are we including doc meta? if ( !get_option( HELPDOCS_GO_PF.'hide_doc_meta' ) ) { // Get the author if ( is_numeric( $current_doc->post_author ) ) { $created_by = get_userdata( $current_doc->post_author ); $created_by = $created_by->display_name; } else { $created_by = $current_doc->post_author; } $incl_created_by = 'Created: ' . date_i18n( 'F j, Y g:i A T', strtotime( $current_doc->post_date ) ) . ' by ' . $created_by; // Get the modified by if ( $current_doc->_edit_last ) { // Modified by if ( is_numeric( $current_doc->_edit_last ) ) { $modified_by = get_userdata( $current_doc->_edit_last ); $modified_by = $modified_by->display_name; } else { $modified_by = $current_doc->_edit_last; } $incl_modified = '
Last modified: ' . date_i18n( 'F j, Y g:i A T', strtotime( $current_doc->post_modified ) ) . ' by ' . esc_attr( $modified_by ); } else { $incl_modified = ''; } } else { $incl_created_by = ''; $incl_modified = ''; } // The edit link if ( helpdocs_user_can_edit() ) { if ( $feed == $current_doc_id ) { $post_id = $current_doc->feed_id; } else { $post_id = $current_doc_id; } $incl_edit = ' [edit]'; } else { $incl_edit = ''; } // If imported, say so if ( $feed == $current_doc_id ) { $incl_feed = '
Content feed: '.$current_doc->auto_feed; } else { $incl_feed = ''; } // Highlight the title if ( $s != '' ) { $post_title = preg_replace( '/'.$s.'/i', '$0', sanitize_text_field( $current_doc->post_title ) ); } else { $post_title = sanitize_text_field( $current_doc->post_title ); } // Add the header echo '

'.wp_kses_post( $post_title ).'

'.wp_kses_post( $incl_edit ).' '.wp_kses_post( $incl_created_by ).' '.wp_kses_post( $incl_modified ).' '.wp_kses_post( $incl_feed ).'
'; // Get the content if ( $s != '' ) { $post_content = str_replace( $s, ''.$s.'', $current_doc->post_content ); } else { $post_content = $current_doc->post_content; } // Auto-Generate TOC from Headings if ( get_option( HELPDOCS_GO_PF.'auto_htoc' ) ) { // Match all h2–h6 tags preg_match_all( '/]*>(.*?)<\/h\1>/i', $post_content, $matches, PREG_SET_ORDER ); if ( $matches ) { $toc = '
    '; $prev_level = 0; foreach ( $matches as $match ) { $level = intval( $match[1] ); $heading_text = strip_tags( $match[2] ); $anchor = sanitize_title( $heading_text ); // Insert anchor into the heading tag $post_content = preg_replace( '/'.preg_quote( $match[0], '/' ).'/', ''.$heading_text.'', $post_content, 1 // Only replace first occurrence ); // Handle nested lists based on heading level if ( $prev_level && $level > $prev_level ) { $toc .= str_repeat( '
      ', $level - $prev_level ); } elseif ( $prev_level && $level < $prev_level ) { $toc .= str_repeat( '
    ', $prev_level - $level ); } $toc .= '
  • '.esc_html( $heading_text ).'
  • '; $prev_level = $level; } // Close any remaining open lists if ( $prev_level > 0 ) { $toc .= str_repeat( '
', $prev_level - 1 ); } $toc .= '
'; echo $toc; } } // Highlight the content add_filter( 'wp_kses_allowed_html', 'helpdocs_allow_addt_tags', 10, 1 ); echo '
'.wp_kses_post( apply_filters( 'the_content', $post_content ) ).'
'; remove_filter( 'wp_kses_allowed_html', 'helpdocs_allow_addt_tags', 10, 1 ); // End the toc container echo '
'; // Search with no results } else if ( $s !== '' ) { // Remove the id qs helpdocs_remove_qs_without_refresh( 'id' ); // Say it aint so echo '
No docs found with the keyword "'.esc_html( $s ).'"... Please try again.
'; // Otherwise redirect to page without doc id } else { wp_safe_redirect( $current_url ); } // End the full page container echo '
'; // Alert echo ''; ?>