1. Check existence of mb_string, mysql and xml extensions before installation.
[openemr.git] / phpmyadmin / libraries / Template.class.php
blob2af6b491d95788ddde481bd98671e52e8aef85d3
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold PMA\Template class
6 * @package PMA
7 */
9 namespace PMA;
11 if (! defined('PHPMYADMIN')) {
12 exit;
15 /**
16 * Class Template
18 * Handle front end templating
20 * @package PMA
22 class Template
25 protected $name = null;
27 const BASE_PATH = 'templates/';
29 /**
30 * Template constructor
32 * @param string $name Template name
34 protected function __construct($name)
36 $this->name = $name;
39 /**
40 * Template getter
42 * @param string $name Template name
44 * @return Template
46 public static function get($name)
48 return new Template($name);
51 /**
52 * Remove whitespaces between tags and innerHTML
54 * @param string $content HTML to perform the trim method
56 * @return string
58 public static function trim($content)
60 $regexp = '/(<[^\/][^>]+>)\s+|\s+(<\/)/';
62 return preg_replace($regexp, "$1$2", $content);
65 /**
66 * Render template
68 * @param array $data Variables to provides for template
69 * @param bool $trim Trim content
71 * @return string
73 public function render($data = array(), $trim = true)
75 $template = static::BASE_PATH . $this->name . '.phtml';
76 try {
77 extract($data);
78 ob_start();
79 if (file_exists($template)) {
80 include $template;
81 } else {
82 throw new \LogicException(
83 'The template "' . $template . '" not found.'
86 if ($trim) {
87 $content = Template::trim(ob_get_clean());
88 } else {
89 $content = ob_get_clean();
92 return $content;
93 } catch (\LogicException $e) {
94 ob_end_clean();
95 throw new \LogicException($e->getMessage());