This blob has been accessed 499 times via Git panel.
- <?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 = quoted_printable_decode($data);
- $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>";
- }
- ?>