Esempio n. 1
0
 function printServiceData($arrData, $format = null, $statusCode = 200)
 {
     if ($statusCode == null || !is_numeric($statusCode)) {
         $statusCode = 200;
     }
     $envelop = getMsgEnvelop();
     if ($format == null) {
         $format = $_REQUEST['format'];
     }
     if (getConfig("SERVICE_SHOW_REQUEST")) {
         $arrData['Request']['uri'] = SiteLocation . $GLOBALS['LOGIKS']["_SERVER"]['REQUEST_URI'];
         $arrData['Request']['site'] = $_REQUEST['site'];
         $arrData['Request']['scmd'] = $_REQUEST['scmd'];
         $arrData['Request']['format'] = $format;
         if (isset($GLOBALS['LOGIKS']["_SERVER"]["REQUEST_TIME_FLOAT"])) {
             $arrData['Request']['latency'] = microtime(true) - $GLOBALS['LOGIKS']["_SERVER"]["REQUEST_TIME_FLOAT"];
         } else {
             $arrData['Request']['latency'] = microtime(true) - $GLOBALS['LOGIKS']["_SERVER"]["REQUEST_SERVICE_START"];
         }
         $arrData['Request']['slug'] = array();
         foreach ($_REQUEST['slug'] as $key => $value) {
             $arrData['Request']['slug']["SLUG_{$key}"] = $value;
         }
     }
     $htmlFormats = array("list", "select", "table");
     if (in_array($format, $htmlFormats)) {
         if (isset($_REQUEST['debug']) && $_REQUEST['debug'] == "true") {
             header("Content-Type:text/text");
         } else {
             header("Content-Type:text/html");
         }
     } else {
         header("Content-Type:text/{$format}");
     }
     if (getConfig("SERVICE_SHOW_ERROR_CODE")) {
         header("Status: {$statusCode}");
         //header(':', true, $statusCode);
         header("HTTP/1.1 {$statusCode}");
     }
     $msgData = $arrData['Data'];
     // $msgData=array(
     // 		// "a"=>"m",
     // 		// "c"=>"n",
     // 		// "a","b",
     // 		// "a"=>array("x"=>array("m"=>"n"),"z"=>"w"),
     // 		// "b"=>array("m"=>"n","o"=>"p"),
     // 		// array("x"=>array("m"=>"n"),"z"=>"w"),
     // 		// array("m"=>"n","o"=>"p"),
     // 	);
     switch ($format) {
         case 'table':
             if (is_array($msgData)) {
                 if (isset($_REQUEST['autoformat']) && $_REQUEST['autoformat'] == "false") {
                     printFormattedArray($msgData, false, "table");
                 } else {
                     printFormattedArray($msgData, true, "table");
                 }
             } else {
                 echo "<tr><td>{$msgData}</td></tr>";
             }
             break;
         case 'list':
             if (is_array($msgData)) {
                 if (isset($_REQUEST['autoformat']) && $_REQUEST['autoformat'] == "false") {
                     printFormattedArray($msgData, false, "list");
                 } else {
                     printFormattedArray($msgData, true, "list");
                 }
             } else {
                 echo "<li>{$msgData}</li>";
             }
             break;
         case 'select':
             if (is_array($msgData)) {
                 if (isset($_REQUEST['autoformat']) && $_REQUEST['autoformat'] == "false") {
                     printFormattedArray($msgData, false, "select");
                 } else {
                     printFormattedArray($msgData, true, "select");
                 }
             } else {
                 echo "<option>{$msgData}</option>";
             }
             break;
         case 'xml':
             $xml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><service></service>");
             arrayToXML($arrData, $xml);
             //array_walk_recursive($arrData, array ($xml, 'addChild'));
             echo $xml->asXML();
             break;
         case 'json':
             echo json_encode($arrData);
             break;
         case 'txt':
             if (is_array($msgData)) {
                 trigger_logikserror(900, E_USER_ERROR);
             } else {
                 $msgData = strip_tags($msgData);
                 echo $msgData;
             }
         default:
             //Anything else (raw,css,js)
             if (is_array($msgData)) {
                 printFormattedArray($msgData);
             } else {
                 $msgData = strip_tags($msgData);
                 echo $msgData;
             }
             break;
     }
 }
Esempio n. 2
0
 function printFormattedArray($arr, $autoTitle = true, $format = null)
 {
     if ($format == null) {
         if (isset($_REQUEST["format"])) {
             $format = $_REQUEST["format"];
         } else {
             $format = "select";
         }
     }
     $format = strtolower($format);
     //HTML Format
     if ($format == "select") {
         if (!array_is_associative($arr)) {
             foreach ($arr as $a => $b) {
                 if ($autoTitle) {
                     echo "<option title='{$b}' value='{$b}'>" . toTitle(_ling($b)) . "</option>\n";
                 } else {
                     echo "<option title='{$b}' value='{$b}'>" . _ling($b) . "</option>\n";
                 }
             }
         } else {
             foreach ($arr as $a => $b) {
                 $xs = "";
                 if (is_array($b)) {
                     $xx = array();
                     foreach ($b as $x => $y) {
                         $xx[] = "{$x}='{$y}'";
                     }
                     $xs = implode(" ", $xx);
                     if (isset($b['value'])) {
                         $b = $b['value'];
                     } else {
                         $b = $a;
                     }
                 }
                 if ($autoTitle) {
                     echo "<option title='{$a}' value='{$b}' {$xs}>" . toTitle(_ling($a)) . "</option>\n";
                 } else {
                     echo "<option title='{$a}' value='{$b}' {$xs}>" . _ling($a) . "</option>\n";
                 }
             }
         }
     } elseif ($format == "table") {
         foreach ($arr as $a => $b) {
             $s = "<tr rel='{$a}'>";
             if (is_array($b)) {
                 foreach ($b as $x => $y) {
                     if (is_numeric($y)) {
                         $s .= "<td name='{$x}' rel='{$y}' align=center>" . toTitle(_ling($y)) . "</td>";
                     } elseif (is_array($y)) {
                         $xs = "";
                         foreach ($y as $u => $v) {
                             $xx[] = "{$u}='{$v}'";
                         }
                         $xs = implode(" ", $xx);
                         if (isset($y['value'])) {
                             $y = $y['value'];
                         } else {
                             $y = $x;
                         }
                         $s .= "<td name='{$x}' rel='{$y}' {$xs}>" . toTitle(_ling($y)) . "</td>";
                     } elseif (is_bool($y) || $y == "true" || $y == "false") {
                         if ($y == "true" || $y == 1) {
                             $s .= "<td name='{$x}' rel='{$y}' align=center><input name={$x} type=checkbox checked /></td>";
                         } else {
                             $s .= "<td name='{$x}' rel='{$y}' align=center><input name={$x} type=checkbox /></td>";
                         }
                     } else {
                         if (strpos("#" . $y, "<") == 1) {
                             $s .= "<td name='{$x}' rel='{$x}'>{$y}</td>";
                         } elseif (strpos($y, "@") === 0) {
                             $y = substr($y, 1);
                             $s .= "<td name='{$x}' rel='{$x}'>{$y}</td>";
                         } else {
                             $s .= "<td name='{$x}' rel='{$y}'>" . toTitle(_ling($y)) . "</td>";
                         }
                     }
                 }
             } else {
                 $s .= "<td name='{$a}' rel='{$b}'>" . toTitle(_ling($b)) . "</td>";
             }
             $s .= "</tr>\n";
             echo $s;
         }
     } elseif ($format == "list") {
         if (!array_is_associative($arr)) {
             foreach ($arr as $a => $b) {
                 if (is_array($b)) {
                     echo "<ul>\n";
                     printFormattedArray($b, $autoTitle, $format);
                     echo "</ul>\n";
                 } else {
                     if ($autoTitle) {
                         echo "<li title='{$b}' value='{$b}'>" . toTitle(_ling($b)) . "</li>\n";
                     } else {
                         echo "<li title='{$b}' value='{$b}'>" . _ling($b) . "</li>\n";
                     }
                 }
             }
         } else {
             foreach ($arr as $a => $b) {
                 if (is_array($b)) {
                     $xs = "";
                     if (is_array($b)) {
                         $xx = array();
                         foreach ($b as $x => $y) {
                             $xx[] = "{$x}='{$y}'";
                         }
                         $xs = implode(" ", $xx);
                     }
                     if ($autoTitle) {
                         echo "<li title='{$a}' {$xs}>" . toTitle(_ling($a)) . "</li>\n";
                     } else {
                         echo "<li title='{$a}' {$xs}>" . _ling($a) . "</li>\n";
                     }
                     // echo "<ul>\n";
                     // printFormattedArray($b,$autoTitle,$format);
                     // echo "</ul>\n";
                 } else {
                     if ($autoTitle) {
                         echo "<li title='{$a}' value='{$b}'>" . toTitle(_ling($a)) . "</li>\n";
                     } else {
                         echo "<li title='{$a}' value='{$b}'>" . _ling($a) . "</li>\n";
                     }
                 }
             }
         }
     } elseif ($format == "text") {
         foreach ($arr as $a => $b) {
             if (is_array($b)) {
                 printFormattedArray($b, $autoTitle, $format);
             } else {
                 $sx = strip_tags("{$a}={$b}");
                 echo "{$sx}\n";
             }
         }
     } elseif ($format == "json") {
         echo json_encode($arr);
     } elseif ($format == "xml") {
         $arr = array_flip($arr);
         $xml = new SimpleXMLElement('<service/>');
         //arrayToXML($arrData,$xml);
         array_walk_recursive($arr, array($xml, 'addChild'));
         echo $xml->asXML();
     } else {
         printArray($arr);
     }
 }