This commit has been accessed 674 times via Git panel.
commit 4451d7bb68239ec2f1d3bf3b4a8f87fc1613487d
tree e9bcd78432abca803aaa57851d25a711c30f9637
parent faf9e1c2041223ad0971336e6948889fa5f08991
author Engels Antonio <engels@kartero.org> 1364276240 +0800
committer Engels Antonio <engels@kartero.org> 1364276240 +0800
Add iCalendar parsers
diff --git a/ics1.php b/ics1.php
new file mode 100644
index 0000000..3e02bcc
--- /dev/null
+++ b/ics1.php
@@ -0,0 +1,33 @@
+<?php
+
+if (!isset($_SESSION['logged_uid']) or !isset($_SESSION['logged_lvl']) or !isset($_SESSION['logged_key']) or ($_SESSION['logged_lvl'] != "subscriber")) {
+ exit;
+}
+
+/* Andy Bailey - http://fiddyp.co.uk/text-between-strings-php/ */
+
+function get_between($text, $s1, $s2, $sn = 0) {
+ $mid = "";
+ $pos_s = mb_strpos($text, $s1);
+ $pos_e = mb_strpos($text, $s2);
+ for ($i = $pos_s + mb_strlen($s1); (($i < ($pos_e)) && $i < mb_strlen($text)); $i++) {
+ $mid.= $text[$i];
+ }
+ if ($sn > 0) {
+ return $s1 . $mid . "\n$s2";
+ }
+ else {
+ return $mid;
+ }
+}
+
+$raw_fetch = imap_utf8(imap_fetchheader($mbox, $msgno, FT_UID | FT_PREFETCHTEXT)) . mb_convert_encoding(mb_convert_encoding(imap_body($mbox, $msgno, FT_UID) , "UTF-8", "auto") , "UTF-8", "UTF-8");
+
+if (mb_strpos($raw_fetch, "BEGIN:VCALENDAR") and mb_strpos($raw_fetch, "END:VCALENDAR")) {
+ if (!file_exists($filePath)) {
+ mkdir($filePath, 0700, 1);
+ }
+ file_put_contents("$filePath/meeting.ics",get_between($raw_fetch,"BEGIN:VCALENDAR","END:VCALENDAR",1));
+}
+
+?>
diff --git a/ics2.php b/ics2.php
new file mode 100644
index 0000000..5c244a3
--- /dev/null
+++ b/ics2.php
@@ -0,0 +1,167 @@
+<?php
+
+if (!isset($_SESSION['logged_uid']) or !isset($_SESSION['logged_lvl']) or !isset($_SESSION['logged_key']) or ($_SESSION['logged_lvl'] != "subscriber")) {
+ exit;
+}
+
+/* http://stackoverflow.com/questions/4757061/which-ics-parser-written-in-php-is-good */
+/* http://stackoverflow.com/users/1898503/steffen-behn */
+
+function ics2array($file) {
+ $data = file_get_contents($file);
+ $data = str_replace(array(
+ "\r\n ",
+ "\n ",
+ "\r "
+ ) , '', $data);
+ $data = str_replace(array(
+ "\r\n\t",
+ "\n\t",
+ "\r\t"
+ ) , '', $data);
+ $data = str_replace('\,', ',', $data);
+ $arr = explode("BEGIN:", $data);
+ foreach($arr as $key => $val) {
+ $meta[$key] = explode("\n", $val);
+ }
+ foreach($meta as $key => $val) {
+ foreach($val as $skey => $sval) {
+ if ($sval != "") {
+ if ($key != 0 && $skey == 0) {
+ $ics[$key]["BEGIN"] = $sval;
+ }
+ else {
+ $sval_r = explode(":", $sval, 2);
+ $ics[$key][$sval_r[0]] = $sval_r[1];
+ }
+ }
+ }
+ }
+ return $ics;
+}
+
+function ics2table($file, $border = 0, $spacing = 1, $padding = 4) {
+ foreach(ics2array($file) as $arr) {
+ if (trim($arr["BEGIN"]) == "VEVENT") {
+ $ics_summary = trim($arr["SUMMARY"]);
+ $ics_decription = str_replace("\\n", "<br />", trim($arr["DESCRIPTION"]));
+ $ics_location = trim($arr["LOCATION"]);
+ foreach($arr as $key => $val) {
+ $dtstart = mb_strpos($key, "DTSTART");
+ if ($dtstart !== false) {
+ $ics_dtstart = $val;
+ }
+ $dtend = mb_strpos($key, "DTEND");
+ if ($dtend !== false) {
+ $ics_dtend = $val;
+ }
+ $organizer = mb_strpos($key, "ORGANIZER");
+ if ($organizer !== false) {
+ $org = explode(";", $key);
+ foreach($org as $ok) {
+ $cn = mb_strpos($ok, "CN=");
+ if ($cn !== false) {
+ $ok = str_replace("CN=", "", $ok);
+ $ok = trim($ok, "'");
+ $ok = trim($ok, '"');
+ $ics_organizer = $ok;
+ $ics_organizer = str_replace(array(
+ "\r\n",
+ "\n",
+ "\r"
+ ) , '', $ics_organizer);
+ $ics_organizer = mb_strtolower($ics_organizer);
+ $ics_organizer = mb_convert_case($ics_organizer, MB_CASE_TITLE, "UTF-8");
+ }
+ $em = mb_strpos($ok, "EMAIL=");
+ if ($em !== false) {
+ $ok = str_replace("EMAIL=", "", $ok);
+ $ok = trim($ok, "'");
+ $ok = trim($ok, '"');
+ $ics_organizer_email = $ok;
+ $ics_organizer_email = str_replace(array(
+ "\r\n",
+ "\n",
+ "\r"
+ ) , '', $ics_organizer_email);
+ $ics_organizer_email = mb_strtolower($ics_organizer_email);
+ }
+ }
+ }
+ $attendee = mb_strpos($key, "ATTENDEE");
+ if ($attendee !== false) {
+ $em = str_replace("mailto:", "", $val);
+ $em = str_replace(array(
+ "\r\n",
+ "\n",
+ "\r"
+ ) , '', $em);
+ $att = explode(";", $key);
+ foreach($att as $ak) {
+ $ps = mb_strpos($ak, "PARTSTAT=");
+ if ($ps !== false) {
+ $pst = str_replace("PARTSTAT=", "", $ak);
+ }
+ $cn = mb_strpos($ak, "CN=");
+ if ($cn !== false) {
+ $nm = str_replace("CN=", "", $ak);
+ $nm = str_replace(array(
+ "\r\n",
+ "\n",
+ "\r"
+ ) , '', $nm);
+ $nm = trim($nm, '"');
+ $nm = trim($nm, "'");
+ }
+ }
+ $nm = mb_strtolower($nm);
+ $em = mb_strtolower($em);
+ if ($nm !== $em) {
+ $nm = mb_convert_case($nm, MB_CASE_TITLE, "UTF-8");
+ $ics_attendees[] = "$nm <$em> $pst";
+ }
+ else {
+ $ics_attendees[] = "$em $pst";
+ }
+ }
+ }
+ }
+ }
+ echo "<table border=\"$border\" cellspacing=\"$spacing\" cellpadding=\"$padding\">";
+ if (mb_strlen($ics_summary) > 0) {
+ echo "\n<tr><td valign=\"top\"><b>summary</b></td><td>$ics_summary</td></tr>";
+ }
+ if (mb_strlen($ics_location) > 0) {
+ echo "\n<tr><td valign=\"top\"><b>location</b></td><td>$ics_location</td></tr>";
+ }
+ if (mb_strlen($ics_dtstart) > 0) {
+ echo "\n<tr><td valign=\"top\"><b>dtstart</b></td><td>$ics_dtstart</td></tr>";
+ }
+ if (mb_strlen($ics_dtend) > 0) {
+ echo "\n<tr><td valign=\"top\"><b>dtend</b></td><td>$ics_dtend</td></tr>";
+ }
+ if (mb_strlen($ics_organizer) > 0) {
+ if (mb_strlen($ics_organizer_email) > 0) {
+ $ics_organizer_email = "<$ics_organizer_email>";
+ }
+ echo "\n<tr><td valign=\"top\"><b>organizer</b></td><td>$ics_organizer $ics_organizer_email</td></tr>";
+ }
+ $ics_attendees_count = count($ics_attendees);
+ if ($ics_attendees_count > 0) {
+ echo "\n<tr><td rowspan=\"$ics_attendees_count\" valign=\"top\"><b>attendees</b></td>";
+ foreach($ics_attendees as $ics_attendee_key => $ics_attendee_val) {
+ if ($ics_attendee_key == 0) {
+ echo "<td>$ics_attendee_val</td></tr>";
+ }
+ else {
+ echo "\n<tr><td>$ics_attendee_val</td></tr>";
+ }
+ }
+ }
+ if (mb_strlen($ics_decription) > 0) {
+ echo "\n<tr><td valign=\"top\"><b>description</b></td><td>$ics_decription</td></tr>";
+ }
+ echo "\n</table>";
+}
+
+?>
diff --git a/read.php b/read.php
index 39c27ae..b80da8a 100644
--- a/read.php
+++ b/read.php
@@ -474,6 +474,7 @@ if (isset($_POST['msg']) and !empty($_POST['msg']) and is_numeric($_POST['msg'])
if (strlen($msgBody) == 0) {
$msgBody = "This message has no content.";
+ include("ics1.php");
}
$get_fromaddress = extract_emails_from($header->fromaddress);
@@ -542,6 +543,11 @@ if (isset($_POST['msg']) and !empty($_POST['msg']) and is_numeric($_POST['msg'])
}
else {
echo "\r\n<tr><td><a href=\"$fileAttachment\"><img src=\"images/file.png\" border=\"0\" width=\"36\" height=\"36\"></a></td><td><a href=\"$fileAttachment\">$fileName</a><br>$fileSize{$fileScan}</td></tr>\r\n";
+
+ if (pathinfo($fileAttachment,PATHINFO_EXTENSION) == "ics") {
+ include("ics2.php");
+ ics2table($fileAttachment);
+ }
}
}
@@ -583,5 +589,5 @@ if (isset($header_rr) and (strlen($header_rr) > 0)) {
echo "<script>if (confirm('The message sender has requested a response to indicate that you have read this message.\\nWould you like to send a receipt?')) { document.getElementById('receipt').submit(); }</script>";
}
}
-
-?>
+
+?>
\ No newline at end of file
tree e9bcd78432abca803aaa57851d25a711c30f9637
parent faf9e1c2041223ad0971336e6948889fa5f08991
author Engels Antonio <engels@kartero.org> 1364276240 +0800
committer Engels Antonio <engels@kartero.org> 1364276240 +0800
Add iCalendar parsers
diff --git a/ics1.php b/ics1.php
new file mode 100644
index 0000000..3e02bcc
--- /dev/null
+++ b/ics1.php
@@ -0,0 +1,33 @@
+<?php
+
+if (!isset($_SESSION['logged_uid']) or !isset($_SESSION['logged_lvl']) or !isset($_SESSION['logged_key']) or ($_SESSION['logged_lvl'] != "subscriber")) {
+ exit;
+}
+
+/* Andy Bailey - http://fiddyp.co.uk/text-between-strings-php/ */
+
+function get_between($text, $s1, $s2, $sn = 0) {
+ $mid = "";
+ $pos_s = mb_strpos($text, $s1);
+ $pos_e = mb_strpos($text, $s2);
+ for ($i = $pos_s + mb_strlen($s1); (($i < ($pos_e)) && $i < mb_strlen($text)); $i++) {
+ $mid.= $text[$i];
+ }
+ if ($sn > 0) {
+ return $s1 . $mid . "\n$s2";
+ }
+ else {
+ return $mid;
+ }
+}
+
+$raw_fetch = imap_utf8(imap_fetchheader($mbox, $msgno, FT_UID | FT_PREFETCHTEXT)) . mb_convert_encoding(mb_convert_encoding(imap_body($mbox, $msgno, FT_UID) , "UTF-8", "auto") , "UTF-8", "UTF-8");
+
+if (mb_strpos($raw_fetch, "BEGIN:VCALENDAR") and mb_strpos($raw_fetch, "END:VCALENDAR")) {
+ if (!file_exists($filePath)) {
+ mkdir($filePath, 0700, 1);
+ }
+ file_put_contents("$filePath/meeting.ics",get_between($raw_fetch,"BEGIN:VCALENDAR","END:VCALENDAR",1));
+}
+
+?>
diff --git a/ics2.php b/ics2.php
new file mode 100644
index 0000000..5c244a3
--- /dev/null
+++ b/ics2.php
@@ -0,0 +1,167 @@
+<?php
+
+if (!isset($_SESSION['logged_uid']) or !isset($_SESSION['logged_lvl']) or !isset($_SESSION['logged_key']) or ($_SESSION['logged_lvl'] != "subscriber")) {
+ exit;
+}
+
+/* http://stackoverflow.com/questions/4757061/which-ics-parser-written-in-php-is-good */
+/* http://stackoverflow.com/users/1898503/steffen-behn */
+
+function ics2array($file) {
+ $data = file_get_contents($file);
+ $data = str_replace(array(
+ "\r\n ",
+ "\n ",
+ "\r "
+ ) , '', $data);
+ $data = str_replace(array(
+ "\r\n\t",
+ "\n\t",
+ "\r\t"
+ ) , '', $data);
+ $data = str_replace('\,', ',', $data);
+ $arr = explode("BEGIN:", $data);
+ foreach($arr as $key => $val) {
+ $meta[$key] = explode("\n", $val);
+ }
+ foreach($meta as $key => $val) {
+ foreach($val as $skey => $sval) {
+ if ($sval != "") {
+ if ($key != 0 && $skey == 0) {
+ $ics[$key]["BEGIN"] = $sval;
+ }
+ else {
+ $sval_r = explode(":", $sval, 2);
+ $ics[$key][$sval_r[0]] = $sval_r[1];
+ }
+ }
+ }
+ }
+ return $ics;
+}
+
+function ics2table($file, $border = 0, $spacing = 1, $padding = 4) {
+ foreach(ics2array($file) as $arr) {
+ if (trim($arr["BEGIN"]) == "VEVENT") {
+ $ics_summary = trim($arr["SUMMARY"]);
+ $ics_decription = str_replace("\\n", "<br />", trim($arr["DESCRIPTION"]));
+ $ics_location = trim($arr["LOCATION"]);
+ foreach($arr as $key => $val) {
+ $dtstart = mb_strpos($key, "DTSTART");
+ if ($dtstart !== false) {
+ $ics_dtstart = $val;
+ }
+ $dtend = mb_strpos($key, "DTEND");
+ if ($dtend !== false) {
+ $ics_dtend = $val;
+ }
+ $organizer = mb_strpos($key, "ORGANIZER");
+ if ($organizer !== false) {
+ $org = explode(";", $key);
+ foreach($org as $ok) {
+ $cn = mb_strpos($ok, "CN=");
+ if ($cn !== false) {
+ $ok = str_replace("CN=", "", $ok);
+ $ok = trim($ok, "'");
+ $ok = trim($ok, '"');
+ $ics_organizer = $ok;
+ $ics_organizer = str_replace(array(
+ "\r\n",
+ "\n",
+ "\r"
+ ) , '', $ics_organizer);
+ $ics_organizer = mb_strtolower($ics_organizer);
+ $ics_organizer = mb_convert_case($ics_organizer, MB_CASE_TITLE, "UTF-8");
+ }
+ $em = mb_strpos($ok, "EMAIL=");
+ if ($em !== false) {
+ $ok = str_replace("EMAIL=", "", $ok);
+ $ok = trim($ok, "'");
+ $ok = trim($ok, '"');
+ $ics_organizer_email = $ok;
+ $ics_organizer_email = str_replace(array(
+ "\r\n",
+ "\n",
+ "\r"
+ ) , '', $ics_organizer_email);
+ $ics_organizer_email = mb_strtolower($ics_organizer_email);
+ }
+ }
+ }
+ $attendee = mb_strpos($key, "ATTENDEE");
+ if ($attendee !== false) {
+ $em = str_replace("mailto:", "", $val);
+ $em = str_replace(array(
+ "\r\n",
+ "\n",
+ "\r"
+ ) , '', $em);
+ $att = explode(";", $key);
+ foreach($att as $ak) {
+ $ps = mb_strpos($ak, "PARTSTAT=");
+ if ($ps !== false) {
+ $pst = str_replace("PARTSTAT=", "", $ak);
+ }
+ $cn = mb_strpos($ak, "CN=");
+ if ($cn !== false) {
+ $nm = str_replace("CN=", "", $ak);
+ $nm = str_replace(array(
+ "\r\n",
+ "\n",
+ "\r"
+ ) , '', $nm);
+ $nm = trim($nm, '"');
+ $nm = trim($nm, "'");
+ }
+ }
+ $nm = mb_strtolower($nm);
+ $em = mb_strtolower($em);
+ if ($nm !== $em) {
+ $nm = mb_convert_case($nm, MB_CASE_TITLE, "UTF-8");
+ $ics_attendees[] = "$nm <$em> $pst";
+ }
+ else {
+ $ics_attendees[] = "$em $pst";
+ }
+ }
+ }
+ }
+ }
+ echo "<table border=\"$border\" cellspacing=\"$spacing\" cellpadding=\"$padding\">";
+ if (mb_strlen($ics_summary) > 0) {
+ echo "\n<tr><td valign=\"top\"><b>summary</b></td><td>$ics_summary</td></tr>";
+ }
+ if (mb_strlen($ics_location) > 0) {
+ echo "\n<tr><td valign=\"top\"><b>location</b></td><td>$ics_location</td></tr>";
+ }
+ if (mb_strlen($ics_dtstart) > 0) {
+ echo "\n<tr><td valign=\"top\"><b>dtstart</b></td><td>$ics_dtstart</td></tr>";
+ }
+ if (mb_strlen($ics_dtend) > 0) {
+ echo "\n<tr><td valign=\"top\"><b>dtend</b></td><td>$ics_dtend</td></tr>";
+ }
+ if (mb_strlen($ics_organizer) > 0) {
+ if (mb_strlen($ics_organizer_email) > 0) {
+ $ics_organizer_email = "<$ics_organizer_email>";
+ }
+ echo "\n<tr><td valign=\"top\"><b>organizer</b></td><td>$ics_organizer $ics_organizer_email</td></tr>";
+ }
+ $ics_attendees_count = count($ics_attendees);
+ if ($ics_attendees_count > 0) {
+ echo "\n<tr><td rowspan=\"$ics_attendees_count\" valign=\"top\"><b>attendees</b></td>";
+ foreach($ics_attendees as $ics_attendee_key => $ics_attendee_val) {
+ if ($ics_attendee_key == 0) {
+ echo "<td>$ics_attendee_val</td></tr>";
+ }
+ else {
+ echo "\n<tr><td>$ics_attendee_val</td></tr>";
+ }
+ }
+ }
+ if (mb_strlen($ics_decription) > 0) {
+ echo "\n<tr><td valign=\"top\"><b>description</b></td><td>$ics_decription</td></tr>";
+ }
+ echo "\n</table>";
+}
+
+?>
diff --git a/read.php b/read.php
index 39c27ae..b80da8a 100644
--- a/read.php
+++ b/read.php
@@ -474,6 +474,7 @@ if (isset($_POST['msg']) and !empty($_POST['msg']) and is_numeric($_POST['msg'])
if (strlen($msgBody) == 0) {
$msgBody = "This message has no content.";
+ include("ics1.php");
}
$get_fromaddress = extract_emails_from($header->fromaddress);
@@ -542,6 +543,11 @@ if (isset($_POST['msg']) and !empty($_POST['msg']) and is_numeric($_POST['msg'])
}
else {
echo "\r\n<tr><td><a href=\"$fileAttachment\"><img src=\"images/file.png\" border=\"0\" width=\"36\" height=\"36\"></a></td><td><a href=\"$fileAttachment\">$fileName</a><br>$fileSize{$fileScan}</td></tr>\r\n";
+
+ if (pathinfo($fileAttachment,PATHINFO_EXTENSION) == "ics") {
+ include("ics2.php");
+ ics2table($fileAttachment);
+ }
}
}
@@ -583,5 +589,5 @@ if (isset($header_rr) and (strlen($header_rr) > 0)) {
echo "<script>if (confirm('The message sender has requested a response to indicate that you have read this message.\\nWould you like to send a receipt?')) { document.getElementById('receipt').submit(); }</script>";
}
}
-
-?>
+
+?>
\ No newline at end of file