PluginProbe
Bookit — Booking & Appointment Calendar / trunk
Bookit — Booking & Appointment Calendar vtrunk
2.6.0.4 2.6.0.3 2.6.0.2 2.6.0.1 2.6.0 trunk 1.2 1.2.2 1.2.3 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 All 61 releases
bookit / includes / classes / Template.php

Template.php in Bookit — Booking & Appointment Calendar trunk, at includes/classes/Template.php

76 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Bookit\Classes;
4
5 class Template {
6
7 /**
8 * @param $template_name
9 * @param string $template_path
10 * @param string $default_path
11 *
12 * @return string
13 */
14 public static function locate_template( $template_name, $template_path = 'bookit/', $default_path = '' ) {
15 $template_name .= '.php';
16 if ( self::template_path() != $template_path ) {
17 $template_path = self::template_path() . $template_path;
18 }
19 if ( locate_template( $template_path . $template_name ) ) {
20 return locate_template( $template_path . $template_name );
21 }
22
23 return self::plugin_path( $default_path ) . '/' . $template_name;
24 }
25
26 /**
27 * @param $template_name
28 * @param array $args
29 * @param null $echo
30 *
31 * @return bool|string
32 */
33 public static function load_template( $template_name, $args = array(), $echo = null ) {
34 if ( null == $echo ) {
35 return self::load( $template_name, $args );
36 }
37 echo self::load( $template_name, $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
38 }
39
40 /**
41 * @param $template_name
42 * @param array $args
43 * @param string $template_path
44 * @param string $default_path
45 *
46 * @return bool|string
47 */
48 public static function load( $template_name, $args = array(), $template_path = 'bookit/', $default_path = '' ) {
49 ob_start();
50 if ( is_array( $args ) ) {
51 extract( $args );
52 }
53 $file = self::locate_template( $template_name, $template_path, $default_path );
54 if ( ! file_exists( $file ) ) {
55 return false;
56 }
57 include( $file );
58
59 return ob_get_clean();
60 }
61
62 public static function template_path() {
63 return apply_filters( 'bookit_template_path', 'bookit/' );
64 }
65
66 /**
67 * @return string
68 */
69 public static function plugin_path( $default_path = '' ) {
70 if ( ! empty( $default_path ) ) {
71 return untrailingslashit( $default_path );
72 }
73 return untrailingslashit( BOOKIT_PATH . '/templates/' );
74 }
75 }
76