Файловый менеджер - Редактировать - /var/www/vhosts/innovatech2023.dev1.mndrn.cloud/src/innovatech-catalogo_dev.php
Назад
<?php /** * INNOVATECH CATALOGO 2023 * * @author TofuZen * */ use PrettyXml\Formatter; include "Formatter.php"; /** * Carica il file csv esportato dall'excel d'origine * * @param [type] $file [description] * @return [type] [description] */ function fetch_csv($file, $delimiter=','){ $csv = array_map('str_getcsv', file($file), [$delimiter]); array_walk($csv, function(&$a) use ($csv) { $a = array_combine($csv[0], $a); }); array_shift($csv); # remove column header return $csv; } /** * Processa le info nel csv importato * * @param [type] $csv [description] * @return [type] [description] */ function proc_csv($csv, $mode='normal'){ $local_index = 0; foreach ($csv as $k => $v) { // LINEA // if ($v['CODICE'] == '' && $v['NOME'] != '') { # echo "PARSING: ".$v['NOME']."\n"; $last_index = $v['NOME']; $local_index = 0; } // NUMERO PAGINA // if ($v['CODICE'] == '' && $v['NOME'] == '') { $local_index = $local_index + 1; } // DATO // if ($mode == 'normal') { if ($v['CODICE'] != '' && $v['NOME'] != '' && ( (isset($v['MISURE']) && $v['MISURE'] != '' ) || (isset($v['DIMENSIONI']) && $v['DIMENSIONI'] != '' ) )) { $parsed[$last_index][$v['NOME']][] = $v; } } if ($mode == 'illuminazione_interni' || $mode == 'illuminazione_esterni' ) { if ($v['CODICE'] != '' && $v['NOME'] != '' && $v['DISEGNO TECNICO'] != '' && ( (isset($v['MISURE']) && $v['MISURE'] != '' ) || (isset($v['DIMENSIONI']) && $v['DIMENSIONI'] != '' ) )) { $parsed[$last_index][$v['NOME']][] = $v; } } } return $parsed; } /** * Manipola i field di tipo Immagine * * @param [type] $str_image [description] * @param [type] $path [description] * @param string $delimiter [description] * @return [type] [description] */ function proc_images($str_image, $path, $delimiter = ',', $search=['.svg', '.SVG'], $replace ='.eps') { $exploded = array_map('trim',explode($delimiter, $str_image)); foreach ($exploded as $key => $value) { $exploded[$key] = str_replace($search, $replace, $value); } $to_xml = []; foreach ($exploded as $k => $v) { $to_xml[] = $path.$v; } return $to_xml; } /** * Crea la tabella fissa * * @param [type] $array_input [description] * @return [type] [description] */ function proc_tabella_fissa($array_input, $delimiter = "\t") { return implode($delimiter, $array_input); } /** * Crea la tabella * * @param [type] $array_input [description] * @return [type] [description] */ function proc_tabella($array_input, $delimiter = "\t") { $tabella = ""; foreach ($array_input as $k => $v) { $tabella .= proc_tabella_fissa($v, $delimiter)."\n"; } $tabella = substr($tabella, 0, strlen($tabella)-1); return $tabella; } /** * Genera l'xml, sia da stampare che da salvare * * @param [type] $parsed_to_xml [description] * @param array $mapper [description] * @return [type] [description] */ function make_xml($parsed_to_xml, $print = 1) { $xmlstr = <<<XML <?xml version='1.0' standalone='yes'?> <root> </root> XML; $xml = new SimpleXMLElement($xmlstr); foreach ($parsed_to_xml as $k_linea => $v_linea) { // $k_linea == nome linea // foreach ($v_linea as $k_pagina => $v_pagina) { $pagina = $xml->addChild("pagina_".$k_pagina, ''); foreach ($v_pagina as $k_dato => $v_dato) { if (is_array($v_dato)) { }else{ switch ($k_dato) { case 'immagine_icone': $icone = $pagina->addChild($k_dato, ''); foreach ($v_dato as $kk => $vv) { $img = $icone->addChild('Image'); $img->addAttribute('href', $vv); } break; case 'Image': $img = $pagina->addChild('Image'); $img->addAttribute('href', $v_dato.".JPG"); break; case 'immagine_disegno_tecnico': $img = $pagina->addChild('Image'); $img->addAttribute('href', $v_dato.".JPG"); break; default: $pagina->addChild($k_dato, $v_dato); break; } #$pagina->addChild($k_dato, $v_dato); } } } } // $xml = html_entity_decode($xml, ENT_NOQUOTES, 'UTF-8'); # $formatter = new Formatter(); # $formatter->setIndentSize(2); # $formatter->setIndentCharacter("\t"); # echo $formatter->format($xml->asXML()); if ($print == 1) { header('Content-Type: text/xml'); echo $xml->asXML(); }else{ $xml->preserveWhiteSpace = true; $xml->formatOutput = true; return $xml->saveXML(); } } /** * Salva l'xml * * @param [type] $folder [description] * @param [type] $file_name [description] * @param [type] $data [description] * @return [type] [description] */ function save_xml($folder, $file_name, $data) { return file_put_contents($file_name, $data); } /** * Processa e manipola le caratteristiche * * @param [type] $str [description] * @param string $action [description] * @param string $delimiter [description] * @return [type] [description] */ function proc_caratteristiche($str, $action = 'explode' ,$delimiter = '•', $delimiter_implode = '\t') { if ($action == 'explode') { return implode($delimiter_implode, array_map('trim', explode($delimiter, $str) ) ); }else{ return $str; } } /* $xml = '<test><a><b></b></a><c></c></test>'; $dom = new \DOMDocument('1.0'); $dom->preserveWhiteSpace = true; $dom->formatOutput = true; $dom->loadXML($xml); $xml_pretty = $dom->saveXML(); */
| ver. 1.4 |
Github
|
.
| PHP 8.2.5 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка