# gdpr-framework/2.1.0/src/View.php

The GDPR Framework By Data443, version 2.1.0. 69 lines.

- Page: https://pluginprobe.com/plugins/gdpr-framework/2.1.0/code/src/View.php
- Raw: https://pluginprobe.com/plugins/gdpr-framework/2.1.0/raw/src/View.php
- Modified: 2024-02-27T19:41:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/gdpr-framework/2.1.0/code/src/View.php#L10-L20`.

```php
<?php

namespace Codelight\GDPR;

/**
 * Handles locating templates from either the theme or plugin,
 * injecting and extracting data and rendering them.
 *
 * Class View
 * @package Codelight\GDPR
 */
class View
{
    var $dirs;

    /**
     * View constructor.
     */
    public function __construct()
    {
        $this->dirs = $this->getTemplateDirectories();
    }

    /**
     * Render a given template.
     *
     * @param       $template
     * @param array $data
     * @param null  $templateDir
     *
     * @return string
     */
    public function render($template, $data = [], $templateDir = null)
    {
        if (is_null($templateDir)) {
            foreach ($this->dirs as $dir) {
                if (file_exists($dir . $template . '.php')) {
                    $templateDir = $dir;
                    break;
                }
            }
        }

        extract($data);
        ob_start();
        require $templateDir . $template . '.php';

        return ob_get_clean();
    }

    /**
     * Get valid template directories and pass them through a filter
     *
     * @return array
     */
    protected function getTemplateDirectories()
    {
        global $gdpr;

        $directories = array_filter([
            get_stylesheet_directory() . '/gdpr-framework/',
            get_template_directory() . '/gdpr-framework/',
            $gdpr->PluginTemplatePath,
        ], 'is_dir');

        return array_unique(apply_filters('gdpr/views', $directories));
    }
}

```
