-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·108 lines (84 loc) · 2.79 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* csv2ics
*
* Copyright (c) 2014-2019 Martin Kozianka <kozianka.de>
*
* @package Csv2ics
* @link https://csv2ics.kozianka.de
* @license MIT License
*/
namespace Csv2ics;
require 'vendor/autoload.php';
use League\Plates\Engine;
use Michelf\MarkdownExtra;
date_default_timezone_set('Europe/Berlin');
session_start();
$strPath = dirname(__FILE__);
$engine = new Engine($strPath . '/templates');
$engine->addData([
'title' => 'csv2ics',
'copyright' => 'Copyright 2014-' . (new \DateTime())->format('Y') . ' Martin Kozianka (kozianka.de)',
'errorMessage' => Manager::getErrorMessage(),
]);
// Gib die ICS-Datei aus!
if (array_key_exists('ics', $_GET)) {
$csvData = null;
$sessionKey = $_GET['ics'];
if (array_key_exists($sessionKey, $_SESSION)) {
$csvData = $_SESSION[$sessionKey];
}
if ($csvData === null) {
Manager::handleError('CSV data not found.');
}
$objConverter = new Converter(null, $csvData);
session_unset();
session_destroy();
$objConverter->getIcsFile($csvData);
} elseif (array_key_exists('result', $_GET)) {
$strFilename = null;
$fileKey = $_GET['result'];
// Die hochgeladene Datei verarbeiten
if (array_key_exists($fileKey, $_SESSION)) {
$strFilename = $_SESSION[$fileKey];
}
$strPath = Manager::getPath() . '/' . $strFilename;
if (!file_exists($strPath) || $strFilename === null) {
Manager::handleError('File not found.');
}
try
{
$objConverter = new Converter($strPath);
} catch (\Exception $e) {
// Datei löschen
unlink($strPath);
Manager::handleError($e->getMessage());
}
// Datei löschen und den Wert aus der Session entfernen
unlink($strPath);
unset($_SESSION[$fileKey]);
$icsKey = 'csv2ics' . uniqid();
$_SESSION[$icsKey] = $objConverter->csvData;
$arrConvert = ['icsKey' => $icsKey, 'csvData' => $objConverter->csvData];
echo $engine->render('result', $arrConvert);
} else {
$arrUpload = [];
// Wurde das Formular abgesendet?
if (array_key_exists('upload', $_GET)) {
$arrUpload = Manager::handleUpload();
// Gab es Fehler im Formular?
if ($arrUpload['uploadError'] === null) {
$key = 'csv2ics' . uniqid();
$_SESSION[$key] = $arrUpload['name'];
header("Location: ?result=" . $key);
exit;
} else {
Manager::handleError($arrUpload['uploadError']);
}
}
$strReadme = file_get_contents($strPath . '/docs/README.md');
$strDetails = file_get_contents($strPath . '/docs/DETAILS.md');
$arrUpload['mdReadme'] = MarkdownExtra::defaultTransform($strReadme);
$arrUpload['mdDetails'] = MarkdownExtra::defaultTransform($strDetails);
echo $engine->render('upload', $arrUpload);
}