Changeset 151 for trunk/instant_messenger/controller.php
- Timestamp:
- 01/18/08 15:17:58 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/instant_messenger/controller.php
r55 r151 1 1 <?php 2 // Explode action from cExecuteForm function 3 $cExecuteFormReturn = false; 4 $returnMode = $_REQUEST['returnMode']; 5 if($_POST['_action']) { 6 if($_FILES) { 7 $count_files = $_POST['countFiles']; 8 $array_files = array(); 9 for($idx = 1; $idx <= $count_files; $idx++) { 10 if($_FILES['file_'.$idx] && !$_FILES['file_'.$idx]['error']) 11 $array_files[] = $_FILES['file_'.$idx]; 12 } 13 $_POST['FILES'] = $array_files; 14 } 15 list($app,$class,$method) = explode('.',@$_POST['_action']); 16 $cExecuteFormReturn = true; 17 } 18 // Explode action from cExecute function 19 else if($_GET['action']) 20 { 21 unset($_GET['returnMode']); 22 list($app,$class,$method) = explode('.',@$_GET['action']); 23 } 24 // NO ACTION 25 else 26 return $_SESSION['response'] = 'false'; 2 if ( !$_GET['act'] ) 3 echo "controller - #0 : invalid action"; 4 else 5 { 6 #$header = getallheaders(); 7 #if ( !$header['ThreadId'] ) 8 # echo "controller - #1 : invalid thread id"; 9 #else 10 #{ 11 #header('ThreadId: ' . $header['ThreadId']); 12 header('ThreadId: ' . $_GET['act']); 13 list($type, $file, $complement) = explode('.', $_GET['act']); 14 switch ( $type ) 15 { 16 case '$this' : 17 case '$class' : 18 case '$obj' : 19 factory($file, $complement); 20 break; 21 case '$file' : 22 case '$xml' : 23 case '$js' : 24 case '$css' : 25 shop(); 26 break; 27 default : echo "controller - #2 : invalid type"; 28 } 29 #} 30 } 27 31 28 // Load dinamically class file. 29 if($app == '$this') 30 $filename = 'inc/class.'.$class.'.inc.php'; 31 else 32 $filename = '../'.$app.'/inc/class.'.$class.'.inc.php'; 32 exit(0); 33 33 34 include_once($filename); 34 function factory($class = false, $method = false) 35 { 36 if ( !$class || !$method ) 37 { 38 echo "controller - #3 : invalid class or method"; 39 return false; 40 } 35 41 36 // Create new Object (class loaded). 42 # Load dinamically class file. 43 $filename = 'inc/class.'.$class.'.inc.php'; 44 if ( !file_exists($filename) ) 45 { 46 echo "controller - #4 : class not exists"; 47 return false; 48 } 49 require_once $filename; 50 51 # Create new Object (class loaded). 37 52 $obj = new $class; 38 39 // Prepare parameters for execution. 53 # Prepare parameters for execution. 40 54 $params = array(); 41 55 42 // If array $_POST is not null , the submit method is POST. 43 if($_POST) { 44 $params = $_POST; 45 } 46 // If array $_POST is null , and the array $_GET > 1, the submit method is GET. 47 else if(count($_GET) > 1) { 48 array_shift($_GET); 49 $params = $_GET; 56 $request_method = $_SERVER['REQUEST_METHOD']; 57 switch ( $request_method ) 58 { 59 case 'GET' : 60 array_shift($_GET); 61 $params = $_GET; 62 break; 63 case 'POST' : 64 $params = $_POST; 65 break; 66 case 'HEAD' : 67 case 'PUT' : 68 default : 69 echo "controller - #5 : request method not avaible"; 70 return false; 50 71 } 51 72 52 $result = array(); 53 54 55 // if params is not empty, then class method with parameters. 56 if($params) 73 # if params is not empty, then class method with parameters. 74 if ( $params ) 57 75 $result = $obj -> $method($params); 58 76 else 59 77 $result = $obj -> $method(); 60 78 61 // Return result json string into xml object. 62 if(!$cExecuteFormReturn) 63 { 64 $dom = new DOMDocument;//('1.0', 'UTF-8'); 79 printf("%s", $result); 80 } 65 81 66 if ( $returnMode == 'JSON') 67 { 68 $root = $dom->appendChild(new DOMElement('retorno')); 69 encode($result, 'encode'); 70 $result = ( !is_object($result) && !is_array($result) ) ? $result : json_encode($result); 71 72 $root->appendChild($dom->createCDATASection($result)); 73 } 74 else 75 { 76 $_SESSION['phpgw_info']['instant_messenger']['debug2'] = $result; 77 $dom->loadXML('<retorno>' . utf8_encode($result) . '</retorno>'); 78 } 79 80 $dom->normalizeDocument(); 81 $retorno = $dom->saveXML(); 82 header('Pragma: anytextexeptno-cache', true); 83 header('Content-type: text/xml, charset=UTF-8'); 84 print $retorno; 85 } 86 else 87 $_SESSION['response'] = $result; 88 89 function encode(&$item, $val = 'encode') 90 { 91 switch( gettype($item) ) 92 { 93 case 'object' : 94 $item = get_object_vars($item); 95 encode($item); 96 break; 97 case 'array' : 98 array_walk_recursive($item, 'encode'); 99 break; 100 default : $item = utf8_encode($item); 101 } 102 } 82 function shop() 83 { 84 } 103 85 ?>
Note: See TracChangeset
for help on using the changeset viewer.