]> git.bts.cx Git - cx.git/blobdiff - cx/lib/template.php
Moved how assets get served
[cx.git] / cx / lib / template.php
index 76e5318eba3477605dd9a069149db6bb10e46ce9..6826d162ea22b1d2611073016e54f9f650baf07a 100644 (file)
@@ -1,5 +1,38 @@
 <?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;
        
@@ -7,7 +40,7 @@ function cx_template_render($class, $name, $variables = null) {
 
        $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;