PluginProbe
The GDPR Framework By Data443 / trunk
The GDPR Framework By Data443 vtrunk
2.5.0 2.4.0 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.3 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 All 41 releases
gdpr-framework / src / View.php

View.php in The GDPR Framework By Data443 trunk, at src/View.php

69 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Codelight\GDPR;
4
5 /**
6 * Handles locating templates from either the theme or plugin,
7 * injecting and extracting data and rendering them.
8 *
9 * Class View
10 * @package Codelight\GDPR
11 */
12 class View
13 {
14 var $dirs;
15
16 /**
17 * View constructor.
18 */
19 public function __construct()
20 {
21 $this->dirs = $this->getTemplateDirectories();
22 }
23
24 /**
25 * Render a given template.
26 *
27 * @param $template
28 * @param array $data
29 * @param null $templateDir
30 *
31 * @return string
32 */
33 public function render($template, $data = [], $templateDir = null)
34 {
35 if (is_null($templateDir)) {
36 foreach ($this->dirs as $dir) {
37 if (file_exists($dir . $template . '.php')) {
38 $templateDir = $dir;
39 break;
40 }
41 }
42 }
43
44 extract($data);
45 ob_start();
46 require $templateDir . $template . '.php';
47
48 return ob_get_clean();
49 }
50
51 /**
52 * Get valid template directories and pass them through a filter
53 *
54 * @return array
55 */
56 protected function getTemplateDirectories()
57 {
58 global $gdpr;
59
60 $directories = array_filter([
61 get_stylesheet_directory() . '/gdpr-framework/',
62 get_template_directory() . '/gdpr-framework/',
63 $gdpr->PluginTemplatePath,
64 ], 'is_dir');
65
66 return array_unique(apply_filters('gdpr/views', $directories));
67 }
68 }
69