| Server IP : 188.114.96.3 / Your IP : 216.73.216.143 Web Server : Apache System : Linux sv058.home.net.pl 6.8.2 husak_dirty_pages_fix #1 SMP PREEMPT_DYNAMIC Tue Apr 2 22:06:51 CEST 2024 x86_64 User : ( 3194769) PHP Version : 8.5.12 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /polana/includes/ |
Upload File : |
<?php
declare(strict_types=1);
/** POLANA V17.6 — minimal OOXML/XLSX writer, no Composer/ZipArchive dependency. */
function pv176_xml(string $value): string {
$value = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F]/', '', $value) ?? '';
if (function_exists('mb_substr')) $value = mb_substr($value, 0, 32767, 'UTF-8');
else $value = substr($value, 0, 32767);
return htmlspecialchars($value, ENT_QUOTES | ENT_XML1 | ENT_SUBSTITUTE, 'UTF-8');
}
function pv176_xlsx_cell(string $address, string $text, int $style=0): string {
// All user-supplied cells are explicit strings, never Excel formulas.
if (preg_match('/^\s*[=+\-@\t\r]/u', $text)) $text = "'" . $text;
return '<c r="' . $address . '" t="inlineStr" s="' . $style . '"><is><t xml:space="preserve">' . pv176_xml($text) . '</t></is></c>';
}
function pv176_zip_archive(array $entries): string {
// Portable ZIP writer (method 0: stored). XLSX works without the PHP zip extension.
$zip = ''; $central = ''; $count = 0;
$time = (int)date('G') << 11 | (int)date('i') << 5 | (int)(date('s') / 2);
$date = ((int)date('Y') - 1980) << 9 | (int)date('n') << 5 | (int)date('j');
foreach ($entries as $name => $content) {
$name = (string)$name; $content = (string)$content;
$length = strlen($content); $crc = crc32($content); $offset = strlen($zip); $nameLen = strlen($name);
$zip .= pack('VvvvvvVVVvv', 0x04034b50, 20, 0, 0, $time, $date, $crc, $length, $length, $nameLen, 0) . $name . $content;
$central .= pack('VvvvvvvVVVvvvvvVV', 0x02014b50, 20, 20, 0, 0, $time, $date, $crc, $length, $length, $nameLen, 0, 0, 0, 0, 0, $offset) . $name;
$count++;
}
return $zip . $central . pack('VvvvvVVv', 0x06054b50, 0, 0, $count, $count, strlen($central), strlen($zip), 0);
}
function pv176_make_xlsx(iterable $rows): string {
$heads = ['E-mail','Imię','Źródło','Status','Data zgody','Data potwierdzenia','Data wypisania'];
$sheet = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
. '<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">'
. '<sheetViews><sheetView workbookViewId="0"><pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen"/></sheetView></sheetViews>'
. '<sheetFormatPr defaultRowHeight="17"/>'
. '<cols><col min="1" max="1" width="37" customWidth="1"/><col min="2" max="2" width="25" customWidth="1"/>'
. '<col min="3" max="4" width="18" customWidth="1"/><col min="5" max="7" width="22" customWidth="1"/></cols>'
. '<sheetData><row r="1" ht="27" customHeight="1">';
foreach ($heads as $i => $label) $sheet .= pv176_xlsx_cell(chr(65+$i).'1', $label, 1);
$sheet .= '</row>';
$index=1;
foreach ($rows as $row) {
if (++$index > 50001) break;
$sheet .= '<row r="'.$index.'">';
for ($i=0;$i<7;$i++) $sheet .= pv176_xlsx_cell(chr(65+$i).$index, (string)($row[$i] ?? ''), 0);
$sheet .= '</row>';
}
$sheet .= '</sheetData><autoFilter ref="A1:G'.$index.'"/></worksheet>';
$contentTypes = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
. '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">'
. '<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>'
. '<Default Extension="xml" ContentType="application/xml"/>'
. '<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>'
. '<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>'
. '<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>'
. '</Types>';
$rels = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
. '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'
. '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>'
. '</Relationships>';
$workbook = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
. '<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">'
. '<sheets><sheet name="Newsletter" sheetId="1" r:id="rId1"/></sheets></workbook>';
$wbRels = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
. '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'
. '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>'
. '<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>'
. '</Relationships>';
$styles = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
. '<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">'
. '<fonts count="2"><font><sz val="11"/><name val="Calibri"/></font><font><b/><sz val="11"/><color rgb="FFFFFFFF"/><name val="Calibri"/></font></fonts>'
. '<fills count="3"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill>'
. '<fill><patternFill patternType="solid"><fgColor rgb="FF215D43"/><bgColor indexed="64"/></patternFill></fill></fills>'
. '<borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders>'
. '<cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs>'
. '<cellXfs count="2"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>'
. '<xf numFmtId="0" fontId="1" fillId="2" borderId="0" xfId="0" applyFill="1" applyFont="1"/></cellXfs>'
. '<cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles>'
. '</styleSheet>';
return pv176_zip_archive([
'[Content_Types].xml'=>$contentTypes,
'_rels/.rels'=>$rels,
'xl/workbook.xml'=>$workbook,
'xl/_rels/workbook.xml.rels'=>$wbRels,
'xl/styles.xml'=>$styles,
'xl/worksheets/sheet1.xml'=>$sheet,
]);
}