Ver código fonte

Changes to the templating system.

This breaks bugs.
Nathaniel van Diepen 10 anos atrás
pai
commit
40c678e72f
2 arquivos alterados com 21 adições e 10 exclusões
  1. 19 8
      api.php
  2. 2 2
      php/functions.php

+ 19 - 8
api.php

@@ -110,9 +110,6 @@
 				case 'page':
 					$title = $id;
 					if(file_exists(PATH_DATA.'pages/'.$id.'.template')){
-						if(!isset($_GET['template'])||$_GET['template']=='true'){
-							$ret['template'] = file_get_contents(PATH_DATA.'pages/'.$id.'.template');
-						}
 						$context = array();
 						if($LOGGEDIN){
 							$context['key'] = true;
@@ -170,21 +167,35 @@
 				break;
 				case 'manifest':
 					case 'pages':
-						if(isset($_GET['manifest'])){
-							$files = array_diff(scandir(dirname(PATH_DATA.'/'.$_GET['manifest'])),array('..', '.'));
+						if(isset($_GET['id'])){
+							$manifest = array();
+							$files = array_diff(scandir(PATH_DATA.'/'.$_GET['id']),array('..', '.','.htaccess','version'));
 							foreach($files as $k => $file){
-								$files[$k] = basename($file)."\n";
+								if(pathinfo(PATH_DATA.'/'.$_GET['id'].'/'.$file,PATHINFO_EXTENSION) == 'template'){
+									array_push($manifest,basename($file,'.template'));
+								}
 							}
 							retj(array(
-								'manifest'=>$files
+								'manifest'=>$manifest
 							));
 						}else{
 							retj(array(
-								'error'=>'Manifest not defined'
+								'error'=>'Manifest ID not defined'
 							));
 						}
 					break;
 				break;
+				case 'template':
+					if(isset($_GET['name'])){
+						retj(array(
+							'template'=>file_get_conetents(PATH_DATA.'/'.$_GET['id'].'/'.$_GET['name'])
+						));
+					}else{
+						retj(array(
+							'error'=>'Template name missing'
+						));
+					}
+				break;
 				case 'action':
 						switch($id){
 							case 'login':

+ 2 - 2
php/functions.php

@@ -72,8 +72,8 @@
 				'context'=>$context
 			);
 		}
-		echo json_encode($json);
-		die();
+		header('Content-type: application/json');
+		die(json_encode($json));
 	}
 	function is_valid($col,$v=null){
 		if($v == null){