| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
// No direct access allowed. |
| 7 |
defined('ABSPATH') or die("Access denied"); |
| 8 |
|
| 9 |
/** |
| 10 |
* |
| 11 |
*/ |
| 12 |
abstract class HTMLComponent { |
| 13 |
|
| 14 |
/** |
| 15 |
* |
| 16 |
*/ |
| 17 |
const DEFAULT_TEMPLATE_DIR = 'tmpl'; |
| 18 |
|
| 19 |
/** |
| 20 |
* |
| 21 |
*/ |
| 22 |
const DEFAULT_TEMPLATE_EXTENSION = 'html.tmpl'; |
| 23 |
|
| 24 |
/** |
| 25 |
* put your comment there... |
| 26 |
* |
| 27 |
* @var mixed |
| 28 |
*/ |
| 29 |
protected $componentFile = null; |
| 30 |
|
| 31 |
/** |
| 32 |
* put your comment there... |
| 33 |
* |
| 34 |
* @var mixed |
| 35 |
*/ |
| 36 |
protected $templatesDir = null; |
| 37 |
|
| 38 |
/** |
| 39 |
* put your comment there... |
| 40 |
* |
| 41 |
* @var mixed |
| 42 |
*/ |
| 43 |
protected $templateFileExtension = null; |
| 44 |
|
| 45 |
/** |
| 46 |
* put your comment there... |
| 47 |
* |
| 48 |
* @param mixed $file |
| 49 |
* @return HTMLComponent |
| 50 |
*/ |
| 51 |
protected function __construct($file, $templatesDir = self::DEFAULT_TEMPLATE_DIR, $templateFileExtension = self::DEFAULT_TEMPLATE_EXTENSION) { |
| 52 |
// Intialize object vars. |
| 53 |
$this->componentFile = $file; |
| 54 |
$this->templatesDir = $templatesDir; |
| 55 |
$this->templateFileExtension = $templateFileExtension; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* put your comment there... |
| 60 |
* |
| 61 |
*/ |
| 62 |
public abstract function __toString(); |
| 63 |
|
| 64 |
/** |
| 65 |
* put your comment there... |
| 66 |
* |
| 67 |
* @param mixed $basePath |
| 68 |
* @param mixed $baseURI |
| 69 |
* @param mixed $path |
| 70 |
*/ |
| 71 |
public function getURI($basePath, $baseURI, $path = '') { |
| 72 |
// Build path to the component file. |
| 73 |
$pathToComponent = str_replace($basePath, '', dirname($this->componentFile)); |
| 74 |
// Build component resource URI. |
| 75 |
$resourceURI = "{$baseURI}{$pathToComponent}/public/{$path}"; |
| 76 |
return $resourceURI; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* put your comment there... |
| 81 |
* |
| 82 |
* @param mixed $name |
| 83 |
*/ |
| 84 |
public function getTemplate($name) { |
| 85 |
$templatePath = dirname($this->componentFile); |
| 86 |
// Get content into alternate output buffer. |
| 87 |
ob_start(); |
| 88 |
// Import template file. |
| 89 |
require "{$templatePath}/{$this->templatesDir}/{$name}.{$this->templateFileExtension}"; |
| 90 |
// Return content. |
| 91 |
return ob_get_clean(); |
| 92 |
} |
| 93 |
|
| 94 |
} // End class. |