PluginProbe
ShareThis Dashboard for Google Analytics / 3.4.1
ShareThis Dashboard for Google Analytics v3.4.1
3.4.1 3.4.0 3.3.2 trunk 1.0.7 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.5 2.3.5 2.3.6 2.3.7 2.3.8 2.4.0 2.4.1 2.5.0 2.5.1 All 45 releases
googleanalytics / class / class-ga-template.php

class-ga-template.php in ShareThis Dashboard for Google Analytics 3.4.1, at class/class-ga-template.php

83 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Google Analytics template.
4 *
5 * @package GoogleAnalytics
6 */
7
8 /**
9 * Class Ga_Template
10 */
11 class Ga_Template {
12 /**
13 * Array of template properties.
14 *
15 * @var array Props array.
16 */
17 protected $props;
18
19 /**
20 * Relative path in view/ folder.
21 *
22 * @var string Path string.
23 */
24 protected $path;
25
26 /**
27 * Ga_Template constructor.
28 *
29 * @param string $path Relative path in view/ folder.
30 * @param array $props Array of props to be passed to the template.
31 */
32 public function __construct( $path, $props = array() ) {
33 $this->path = $path;
34 $this->props = $props;
35 }
36
37 /**
38 * Include rendered template inline.
39 *
40 * @param string $path Relative path in view/ folder.
41 * @param array $props Array of props to be passed to the template.
42 */
43 public static function load( $path, $props = array() ) {
44 ( new static( $path, $props ) )->include_template();
45 }
46
47 /**
48 * Get rendered template.
49 *
50 * @param string $path Relative path in view/ folder.
51 * @param array $props Array of props to be passed to the template.
52 *
53 * @return string Rendered template.
54 */
55 public static function render( $path, $props = array() ) {
56 return ( new static( $path, $props ) )->render_template();
57 }
58
59 /**
60 * Include template.
61 */
62 public function include_template() {
63 $template_path = GA_PLUGIN_DIR . '/view/' . $this->path . '.php';
64
65 if ( is_readable( $template_path ) ) {
66 load_template( $template_path, false, $this->props );
67 }
68 }
69
70 /**
71 * Get rendered template.
72 *
73 * @return string
74 */
75 public function render_template() {
76 ob_start();
77 $this->include_template();
78 $render = ob_get_contents();
79
80 return false === empty( $render ) ? $render : '';
81 }
82 }
83