function generate_valid_xml_from_array($array, $node_block = 'response', $node_name = 'node') { $xml = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n"; $xml .= '<' . $node_block . '>' . "\n"; $xml .= generate_xml_from_array($array, $node_name); $xml .= '</' . $node_block . '>' . "\n"; return $xml; }
function generate_xml_from_array($array, $node_name, &$tab = -1) { $tab++; $xml = ""; if (is_array($array) || is_object($array)) { foreach ($array as $key => $value) { if (is_numeric($key)) { $key = $node_name; } $xml .= str_repeat("\t", $tab) . '<' . $key . '>' . "\n"; $xml .= generate_xml_from_array($value, $node_name, $tab); $xml .= str_repeat("\t", $tab) . '</' . $key . '>' . "\n"; } } else { $xml = str_repeat("\t", $tab) . htmlspecialchars($array, ENT_QUOTES) . "\n"; } $tab--; return $xml; }
$rss->addItem($item); } } $rss->outputFeed($tz, $format); break; case 'CSV': header("Content-Transfer-Encoding: binary"); header("Content-Disposition: attachment;filename=PimpMyLog_" . get_slug($file_id) . "_" . date("Y-m-d-His") . '.csv'); header("Content-type: application/vnd.ms-excel; charset=UTF-16LE"); echo chr(255) . chr(254) . mb_convert_encoding(array2csv($logs['logs']), 'UTF-16LE', 'UTF-8'); break; case 'XML': header('Content-type: application/xml', true); $xml = '<?xml version="1.0" encoding="UTF-8" ?>'; $xml .= '<pml>'; $xml .= generate_xml_from_array($logs, 'log'); $xml .= '</pml>'; echo $xml; break; case 'JSONPR': header('Content-type: application/json', true); if (version_compare(PHP_VERSION, '5.4.0') >= 0) { echo json_encode($logs, JSON_PRETTY_PRINT); } else { echo json_indent(json_encode($logs)); } break; case 'JSONP': header('Content-type: application/javascript', true); echo isset($_GET['callback']) ? $_GET['callback'] : '?'; echo '(';
/** * Generate a xml string of the provided array * * @param array $array the array to convert in XML * @param string $node_name the node name for numerical arrays * * @return string the xml string */ function generate_xml_from_array($array, $node_name) { $xml = ''; if (is_array($array) || is_object($array)) { foreach ($array as $key => $value) { if (is_numeric($key)) { $key = $node_name; } $xml .= '<' . $key . '>' . generate_xml_from_array($value, $node_name) . '</' . $key . '>'; } } else { $xml = htmlspecialchars($array, ENT_QUOTES); } return $xml; }
function generate_valid_xml_from_array($array, $node_block = 'SoapFault', $node_name = 'node') { /*$xml = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";*/ $xml = '<' . $node_block . '>'; $xml .= generate_xml_from_array($array, $node_name); $xml .= '</' . $node_block . '>'; $xml = str_replace('<@attributes>', '', $xml); // Remove the XML namespace closing tags $xml = str_replace('</@attributes>', '', $xml); $xml = str_replace('<nil>', '', $xml); $xml = str_replace('</nil>', '', $xml); $xml = str_replace('"', '', $xml); return $xml; }
public function epm_advanced_poce_select_file() { $arrVal['VAR_REQUEST'] = array("product_select", "file_id", "file_name", "type_file"); foreach ($arrVal['VAR_REQUEST'] as $valor) { if (!array_key_exists($valor, $_REQUEST)) { return array("status" => false, "message" => _("No send value!") . " [" . $valor . "]"); } } if (!is_numeric($_REQUEST['product_select'])) { return array("status" => false, "message" => _("Product Select send is not number!")); } elseif ($_REQUEST['product_select'] < 0) { return array("status" => false, "message" => _("Product Select send is number not valid!")); } $dget['product_select'] = $_REQUEST['product_select']; $dget['file_name'] = $_REQUEST['file_name']; $dget['file_id'] = $_REQUEST['file_id']; $dget['type_file'] = $_REQUEST['type_file']; if ($dget['type_file'] == "sql") { $sql = 'SELECT * FROM endpointman_custom_configs WHERE id =' . $dget['file_id']; $row = sql($sql, 'getrow', DB_FETCHMODE_ASSOC); $type = $dget['type_file']; $sendidt = $row['id']; $product_select = $row['product_id']; $save_as_name_value = $row['name']; $original_name = $row['original_name']; $filename = $row['name']; $location = "SQL: " . $row['name']; $config_data = $this->display_htmlspecialchars($row['data']); } elseif ($dget['type_file'] == "file") { $sql = "SELECT cfg_dir,directory,config_files FROM endpointman_product_list,endpointman_brand_list WHERE endpointman_product_list.brand = endpointman_brand_list.id AND endpointman_product_list.id = '" . $dget['product_select'] . "'"; $row = sql($sql, 'getRow', DB_FETCHMODE_ASSOC); $config_files = explode(",", $row['config_files']); //TODO: Añadir validacion para ver si $dget['file_name'] esta en el array $config_files $filename = $dget['file_name']; $pathfile = $this->PHONE_MODULES_PATH . 'endpoint/' . $row['directory'] . "/" . $row['cfg_dir'] . "/" . $filename; if (is_readable($pathfile)) { if (filesize($pathfile) > 0) { $handle = fopen($pathfile, "rb"); $contents = fread($handle, filesize($pathfile)); fclose($handle); $contents = $this->display_htmlspecialchars($contents); } else { $contents = ""; } $type = $dget['type_file']; $sendidt = $dget['file_id']; $product_select = $dget['product_select']; $save_as_name_value = $filename; $original_name = $filename; $filename = $filename; $location = $pathfile; $config_data = $contents; } else { $retarr = array("status" => false, "message" => _("File not readable, check the permission! ") . $filename); } } elseif ($dget['type_file'] == "tfile") { if ($dget['file_id'] == "template_data_custom.xml") { $sendidt = ""; $original_name = $dget['file_name']; $config_data = ""; } else { $sql = "SELECT * FROM endpointman_model_list WHERE id = '" . $dget['file_id'] . "'"; $data = sql($sql, 'getRow', DB_FETCHMODE_ASSOC); $sendidt = $data['id']; $original_name = $dget['file_name']; $config_data = unserialize($data['template_data']); $config_data = generate_xml_from_array($config_data, 'node'); } $type = $dget['type_file']; $product_select = $dget['product_select']; $save_as_name_value = $dget['file_name']; $filename = $dget['file_name']; $location = $dget['file_name']; } $retarr = array("status" => true, "message" => "OK", "type" => $type, "sendidt" => $sendidt, "product_select" => $product_select, "save_as_name_value" => $save_as_name_value, "original_name" => $original_name, "filename" => $filename, "location" => $location, "config_data" => $config_data); unset($dget); return $retarr; }