| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\FrontEnd; |
| 4 |
use WPDeveloper\BetterDocs\Utils\Base; |
| 5 |
use WPDeveloper\BetterDocs\Utils\Views; |
| 6 |
use WPDeveloper\BetterDocs\Utils\Database; |
| 7 |
use WPDeveloper\BetterDocs\Dependencies\DI\Container; |
| 8 |
|
| 9 |
class TemplateLoader extends Base { |
| 10 |
public $is_fse_theme = false; |
| 11 |
private $templates_dir; |
| 12 |
private $block_templates_dir; |
| 13 |
private $container; |
| 14 |
private $database; |
| 15 |
private $views; |
| 16 |
|
| 17 |
public function __construct( Container $container ) { |
| 18 |
$this->container = $container; |
| 19 |
$this->database = $this->container->get( Database::class ); |
| 20 |
$this->views = $this->container->get( Views::class ); |
| 21 |
} |
| 22 |
|
| 23 |
public function init() { |
| 24 |
$this->is_fse_theme = $this->is_fse_theme(); |
| 25 |
|
| 26 |
if ( $this->is_fse_theme ) { |
| 27 |
// @todo: for FSE theme |
| 28 |
} |
| 29 |
|
| 30 |
if ( ! $this->is_fse_theme ) { |
| 31 |
add_filter( 'archive_template', [$this, 'archive_template'] ); |
| 32 |
add_filter( 'single_template', [$this, 'single_template'] ); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Render Thrive Header Markup |
| 38 |
* |
| 39 |
* @return void |
| 40 |
*/ |
| 41 |
public function render_thrive_header() { |
| 42 |
echo '<div id="wrapper">'.thrive_template()->render_theme_hf_section( THRIVE_HEADER_SECTION ).'<div id="content"><div class="main-container">'; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Render Thrive Footer Markup |
| 47 |
* |
| 48 |
* @return void |
| 49 |
*/ |
| 50 |
public function render_thrive_footer() { |
| 51 |
echo '</div></div>'.thrive_template()->render_theme_hf_section( THRIVE_FOOTER_SECTION ).'</div>'; |
| 52 |
} |
| 53 |
|
| 54 |
public function archive_template( $template ) { |
| 55 |
if ( get_post_type() !== 'docs' ) { |
| 56 |
return $template; |
| 57 |
} |
| 58 |
|
| 59 |
if ( is_embed() ) { |
| 60 |
return $template; |
| 61 |
} |
| 62 |
|
| 63 |
$_default_template = 'templates/archives/layout-1'; |
| 64 |
$layout = $this->database->get_theme_mod( 'betterdocs_docs_layout_select', 'layout-1' ); |
| 65 |
$_template = 'templates/archives/' . $layout; |
| 66 |
|
| 67 |
if ( is_tax( 'doc_category' ) ) { |
| 68 |
$_template = 'templates/taxonomy-doc_category'; |
| 69 |
$_default_template = $_template; |
| 70 |
} elseif ( is_tax( 'doc_tag' ) ) { |
| 71 |
$_template = 'templates/taxonomy-doc_tag'; |
| 72 |
$_default_template = $_template; |
| 73 |
} |
| 74 |
|
| 75 |
$eligible_template = $this->views->path( $_template, $_default_template ); |
| 76 |
|
| 77 |
//Render The Header Footer When Thrive Builder Theme Is Activated |
| 78 |
if( wp_get_theme() == 'Thrive Theme Builder' ){ |
| 79 |
$this->render_thrive_header_footer(); |
| 80 |
} |
| 81 |
|
| 82 |
if ( file_exists( $eligible_template ) ) { |
| 83 |
$template = &$eligible_template; |
| 84 |
} |
| 85 |
|
| 86 |
return apply_filters( 'betterdocs_archives_template', $template, $layout, $_default_template, $this->views ); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Render Thriver Header Footer When Thrive Theme Is Activated |
| 91 |
* |
| 92 |
* @return void |
| 93 |
*/ |
| 94 |
public function render_thrive_header_footer() { |
| 95 |
add_action( 'get_header', [$this, 'render_thrive_header'], 10 ); |
| 96 |
add_action( 'get_footer', [$this, 'render_thrive_footer'], 10 ); |
| 97 |
} |
| 98 |
|
| 99 |
public function single_template( $template ) { |
| 100 |
if ( ! is_singular( 'docs' ) ) { |
| 101 |
return $template; |
| 102 |
} |
| 103 |
|
| 104 |
//Render The Header Footer When Thrive Builder Theme Is Activated |
| 105 |
if( wp_get_theme() == 'Thrive Theme Builder' ){ |
| 106 |
$this->render_thrive_header_footer(); |
| 107 |
} |
| 108 |
|
| 109 |
$_default_template = 'templates/single/layout-1'; |
| 110 |
$layout = $this->database->get_theme_mod( 'betterdocs_single_layout_select', 'layout-1' ); |
| 111 |
$layout = 'templates/single/' . $layout; |
| 112 |
|
| 113 |
$eligible_template = $this->views->path( $layout, $_default_template ); |
| 114 |
|
| 115 |
if ( file_exists( $eligible_template ) ) { |
| 116 |
$template = &$eligible_template; |
| 117 |
} |
| 118 |
|
| 119 |
return apply_filters( 'betterdocs_single_template', $template, $layout, $_default_template, $this->views ); |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Summary of is_fse_theme |
| 124 |
* @return bool |
| 125 |
* |
| 126 |
* @suppress PHP0417 |
| 127 |
*/ |
| 128 |
private function is_fse_theme() { |
| 129 |
if ( function_exists( 'wp_is_block_theme' ) ) { |
| 130 |
return (bool) wp_is_block_theme(); |
| 131 |
} |
| 132 |
if ( function_exists( 'gutenberg_is_fse_theme' ) ) { |
| 133 |
return (bool) gutenberg_is_fse_theme(); |
| 134 |
} |
| 135 |
|
| 136 |
return false; |
| 137 |
} |
| 138 |
} |
| 139 |
|