<?php
+cx_require('third_party', 'mime', 'mime_types.php');
+
+function cx_template_content_path($class, $path) {
+ $segments = array(CX_PATH, 'templates', $class, 'assets', $path);
+ $path = join(DIRECTORY_SEPARATOR, $segments);
+ return $path;
+}
+
+function cx_template_has_content($class, $path) {
+ return file_exists(cx_template_content_path($class, $path));
+}
+
+function cx_template_output_content($class, $path) {
+ $full_path = cx_template_content_path($class, $path);
+
+ $extension = pathinfo($path, PATHINFO_EXTENSION);
+
+ if (isset(MIME_REVERSE_MAP[$extension])) {
+ $mime_type = MIME_REVERSE_MAP[$extension][0];
+ } else {
+ $finfo = finfo_open(FILEINFO_MIME_TYPE);
+ $mime_type = finfo_file($finfo, $full_path);
+ //finfo_close($finfo); - Deprecated
+ }
+
+ header('Content-Type: ' . $mime_type);
+ header('Content-Length: ' . filesize($full_path));
+
+ $fp = fopen($full_path, 'rb');
+ fpassthru($fp);
+ fclose($fp);
+}
+
function cx_template_render($class, $name, $variables = null) {
global $cx_template_base, $cx_template_content;
$output = '';
while ($name != null) {
- $segments = array(CX_PATH, 'templates', $class, $name . '.php');
+ $segments = array(CX_PATH, 'templates', $class, 'pages', $name . '.php');
$path = join(DIRECTORY_SEPARATOR, $segments);
$base_template = null;