PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 2.5.4
ShareThis Dashboard for Google Analytics v2.5.4
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 2.5.2 2.5.3 2.5.4 2.5.5 3.0.0 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.3.0 3.3.1
googleanalytics / class / Ga_Template.php
googleanalytics / class Last commit date
controller 5 years ago core 5 years ago Ga_Admin.php 4 years ago Ga_Autoloader.php 4 years ago Ga_Frontend.php 5 years ago Ga_Helper.php 4 years ago Ga_Hook.php 4 years ago Ga_Notice.php 6 years ago Ga_Sharethis.php 6 years ago Ga_Stats.php 4 years ago Ga_Template.php 4 years ago
Ga_Template.php
73 lines
1 <?php
2
3 /**
4 * Class Ga_Template
5 */
6 class Ga_Template {
7 /**
8 * @var array Array of template properties.
9 */
10 protected $props;
11
12 /**
13 * @var string Relative path in view/ folder.
14 */
15 protected $path;
16
17 /**
18 * Ga_Template constructor.
19 *
20 * @param string $path Relative path in view/ folder.
21 * @param array $props Array of props to be passed to the template.
22 */
23 public function __construct( $path, $props = [] ) {
24 $this->path = $path;
25 $this->props = $props;
26 }
27
28 /**
29 * Include rendered template inline.
30 *
31 * @param string $path Relative path in view/ folder.
32 * @param array $props Array of props to be passed to the template.
33 */
34 public static function load( $path, $props = [] ) {
35 ( new static( $path, $props ) )->includeTemplate();
36 }
37
38 /**
39 * Get rendered template.
40 *
41 * @param string $path Relative path in view/ folder.
42 * @param array $props Array of props to be passed to the template.
43 *
44 * @return string Rendered template.
45 */
46 public static function render( $path, $props = [] ) {
47 return ( new static( $path, $props ) )->renderTemplate();
48 }
49
50 /**
51 * Include template.
52 */
53 public function includeTemplate() {
54 $template_path = GA_PLUGIN_DIR . '/view/' . $this->path . '.php';
55
56 if ( is_readable( $template_path ) ) {
57 load_template( $template_path, false, $this->props );
58 }
59 }
60
61 /**
62 * Get rendered template.
63 *
64 * @return string
65 */
66 public function renderTemplate() {
67 ob_start();
68 $this->includeTemplate();
69 $render = ob_get_contents();
70
71 return $render ?: '';
72 }
73 }