Server IP : 103.119.228.120 / Your IP : 3.133.122.131 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/softaculous/sitepad/editor/site-data/plugins/documentor/includes/ |
Upload File : |
<?php /** * Template loader. * * @package documentor */ if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Template Loader * * @class Documentor_Template_Loader * @package documentor */ class Documentor_Template_Loader { /** * Docs archive page ID * * @var int */ private static $docs_archive_id = 0; /** * Hook in methods. */ public static function init() { self::$docs_archive_id = documentor()->get_option( 'docs_page_id', 'documentor_settings', false ); add_filter( 'template_include', array( __CLASS__, 'template_loader' ) ); // To make the links like /docs/space/category/arctile-name to /docs/space/arctile-name add_filter('post_type_link', array( __CLASS__, 'permalink' ), 10001, 4); } /** * Load a template. * * Handles template usage so that we can use our own templates instead of the themes. * * Templates are in the 'templates' folder. documentor looks for theme. * overrides in /theme/documentor/ by default. * * @param string $template - template name. * @return string */ public static function template_loader( $template ) { if ( is_embed() ) { return $template; } $default_file = self::get_template_loader_default_file(); if ( $default_file ) { /** * Filter hook to choose which files to find before Documentor does it's own logic. * * @var array */ $search_files = self::get_template_loader_files( $default_file ); $template = locate_template( $search_files ); if ( ! $template ) { $template = documentor()->template_path . $default_file; } } return $template; } /** * Get the default filename for a template. * * @return string */ private static function get_template_loader_default_file() { $default_file = ''; if ( is_singular( 'docs' ) ) { $default_file = 'single.php'; documentor()->is_single = true; } elseif ( is_post_type_archive( 'docs' ) || self::$docs_archive_id && is_page( self::$docs_archive_id ) ) { $default_file = 'archive.php'; documentor()->is_archive = true; // Add query for page docs. global $wp_query; $args = array( 'post_type' => 'docs', 'posts_per_page' => -1, // phpcs:ignore 'post_parent' => 0, 'orderby' => array( 'menu_order' => 'ASC', 'date' => 'DESC', ), ); // prepare args for search page. if ( ! is_admin() && is_search() ) { $default_file = 'search.php'; unset( $args['posts_per_page'] ); unset( $args['post_parent'] ); $args['s'] = get_search_query(); // phpcs:ignore $parent = isset( $_GET['child_of'] ) ? sanitize_text_field( wp_unslash( $_GET['child_of'] ) ) : false; $parent = intval( $parent ); // we need to get all docs IDs and the use it in WP_Query as we need get also all childrens. if ( $parent ) { $post__in = array( $parent => $parent ); $children_docs = get_pages( array( 'child_of' => $parent, 'post_type' => 'docs', 'depth' => -1, ) ); if ( $children_docs ) { $post__in = array_merge( $post__in, wp_list_pluck( $children_docs, 'ID' ) ); } $args['post__in'] = $post__in; } } // make order by term. if ( 'archive.php' === $default_file ) { $categories = get_terms( array( 'taxonomy' => 'docs_category', 'hide_empty' => false, ) ); // we need to make query and loop over items and sort it by term. if ( ! empty( $categories ) ) { $docs_by_cat = array( 0 => array(), ); // get all available terms in array. foreach ( $categories as $cat ) { $docs_by_cat[ $cat->slug ] = array(); } // get parent docs. $parent_docs = get_pages( array( 'post_type' => 'docs', 'parent' => 0, 'sort_column' => 'menu_order', ) ); if ( $parent_docs ) { // set all doc IDs to array by terms. foreach ( $parent_docs as $doc ) { $term = get_the_terms( $doc, 'docs_category' ); if ( $term && ! empty( $term ) ) { $term = $term[0]->slug; } else { $term = 0; } $docs_by_cat[ $term ][] = $doc->ID; } // add posts IDs in post__in. if ( count( $docs_by_cat ) >= 2 ) { $args['post__in'] = array(); foreach ( $docs_by_cat as $docs ) { $args['post__in'] = array_merge( $args['post__in'], $docs ); } $args['orderby'] = 'post__in'; } } } } $wp_query = new WP_Query( $args ); // phpcs:ignore } return $default_file; } /** * Get an array of filenames to search for a given template. * * @param string $default_file The default file name. * @return string[] */ private static function get_template_loader_files( $default_file ) { $search_files = apply_filters( 'documentor_template_loader_files', array(), $default_file ); if ( is_page_template() ) { $search_files[] = get_page_template_slug(); } $search_files[] = '/documentor/' . $default_file; return array_unique( $search_files ); } // Change the post permalink public static function permalink($post_link, $post, $leavename, $sample){ // Only for docs type if($post->post_type == documentor()->post_type){ //die(home_url('/docs').' - '.$post_link); $url = get_permalink( self::$docs_archive_id ); // We need to clean extra parts in the docs $section = str_replace($url, '', $post_link); $section = str_replace(home_url(), '', $section); //in case the url dosent have custom post type $section = explode('/', trim($section, '/')); $count = count($section); //This is to reduce the URL length. if($count > 2) { for($i = 1; $i < ($count - 1); $i++){ unset($section[$i]); } } $post_link = $url.implode('/', $section); //die($post_link); } return $post_link; } } Documentor_Template_Loader::init();