-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentryPoint.php
More file actions
125 lines (114 loc) · 3.4 KB
/
entryPoint.php
File metadata and controls
125 lines (114 loc) · 3.4 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
require_once('../../config/icalLogin.php');
$tmpGet = $_GET;
try {
$updateIdDateTime = false;
if (isset($_GET['id']) && $_GET['id'] != '') {
$id = $_GET['id'];
$conn = new PDO($dbDriver . ':host=' . $dbHost . ';dbname=' . $db . ';charset=ascii', $dbUser, $dbPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = $conn->prepare('SELECT url_fragment FROM shortLinks WHERE id=:id');
$query->bindValue('id', $id);
if ($query->execute()) {
$rows = $query->fetchAll(PDO::FETCH_ASSOC);
if (count($rows) > 0) {
foreach ($_GET as $key => $value) {
$_GET[$key] = NULL;
unset($_GET[$key]);
}
$frag = $rows[0]['url_fragment'];
$parts = explode('&',$frag);
foreach ($parts as $part) {
$p = explode('=', $part);
$p1 = $p[0];
$p2 = '';
if (count($p)>1)
$p2 = urldecode(implode('=', array_slice($p, 1)));
$_GET[$p1] = $p2;
}
$updateIdDateTime = true;
}
}
if ($updateIdDateTime == true) {
$query = $conn->prepare('UPDATE shortLinks SET last_requested=:dt WHERE id=:id');
$dt = date('Y-m-d H:i:s', time());
$query->bindValue('dt', $dt);
$query->bindValue('id', $id);
$query->execute();
}
}
}
catch (PDOException $e) {
$_GET = $tmpGet;
}
//parse ical file
require_once('ical.php');
if (!isset($_GET['ical_link'])) {
die('');
}
$amount = 1;
while (isset($_GET['ical_link'.($amount+1)])) $amount++;
$link = array();
$ical = array();
$c = array();
$checkSummary = array();
$checkDescription = array();
$regex = array();
$checkSummaryNot = array();
$checkDescriptionNot = array();
$regexNot = array();
$link[1] = $_GET['ical_link'];
$checkSummary[1] = isset($_GET['summary']);
$checkDescription[1] = isset($_GET['description']);
$regex[1] = '.';
if (isset($_GET['regex'])) {
$regex[1] = $_GET['regex'];
}
$checkSummaryNot[1] = isset($_GET['summary_not']);
$checkDescriptionNot[1] = isset($_GET['description_not']);
$regexNot[1] = '.';
if (isset($_GET['regex_not'])) {
$regexNot[1] = $_GET['regex_not'];
}
for ($i = 2; $i <= $amount; $i++) {
$link[$i] = $_GET['ical_link'.$i];
$checkSummary[$i] = isset($_GET['summary'.$i]);
$checkDescription[$i] = isset($_GET['description'.$i]);
$regex[$i] = '.';
if (isset($_GET['regex'.$i])) {
$regex[$i] = $_GET['regex'.$i];
}
$checkSummaryNot[$i] = isset($_GET['summary_not'.$i]);
$checkDescriptionNot[$i] = isset($_GET['description_not'.$i]);
$regexNot[$i] = '.';
if (isset($_GET['regex_not'.$i])) {
$regexNot[$i] = $_GET['regex_not'.$i];
}
}
$final = null;
for ($i = 1; $i <= $amount; $i++) {
if (filter_var($link[$i], FILTER_VALIDATE_URL)) {
$ical[$i] = file_get_contents($link[$i]);
$c[$i] = parseIcal($ical[$i]);
if (isset($c[$i]) && !is_null($c[$i]) && $c[$i] != null) {
$c[$i]->filter($regex[$i],$checkSummary[$i],$checkDescription[$i],$regexNot[$i],$checkSummaryNot[$i],$checkDescriptionNot[$i]);
if ($final == null)
$final = $c[$i];
else
$final = mergeIcal($final, $c[$i]);
}
}
}
if ($final != null) {
if (isset($_GET['name']) && $_GET['name'] !== NULL && $_GET['name'] !== '') {
$final->setName($_GET['name']);
}
if (isset($_GET['desc']) && $_GET['desc'] !== NULL && $_GET['desc'] !== '') {
$final->setDescription($_GET['desc']);
}
if (isset($_GET['ttl']) && $_GET['ttl'] !== NULL && $_GET['ttl'] !== '' && is_numeric($_GET['ttl']) && intval($_GET['ttl']) > 0) {
$final->setTtl('PT' . intval($_GET['ttl']) . 'H');
}
echo $final->toString();
}
?>