Difference between revisions of "Ics.php"

From HacDC Wiki
Jump to: navigation, search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
<nowiki>This code still needs to be cleaned up some.
+
{{Obsolete}}
  
<?php
+
This code still needs to be cleaned up some.
  
include('Drupal.login.php');
+
*Note, this script requires: [[Drupal.login.php]]
  
$ics_contents = "BEGIN:VCALENDAR\n";
+
&lt;?php<br>
$ics_contents .= "VERSION:2.0\n";
+
<br>
$ics_contents .= "PRODID:PHP\n";
+
include('Drupal.login.php');<br>
$ics_contents .= "METHOD:PUBLISH\n";
+
<br>
$ics_contents .= "X-WR-CALNAME:HacDC Schedule\n";
+
$ics_contents = &quot;BEGIN:VCALENDAR\n&quot;;<br>
+
$ics_contents .= &quot;VERSION:2.0\n&quot;;<br>
# Change the timezone as well daylight settings if need be
+
$ics_contents .= &quot;PRODID:PHP\n&quot;;<br>
$ics_contents .= "X-WR-TIMEZONE:America/New_York\n";
+
$ics_contents .= &quot;METHOD:PUBLISH\n&quot;;<br>
$ics_contents .= "BEGIN:VTIMEZONE\n";
+
$ics_contents .= &quot;X-WR-CALNAME:HacDC Schedule\n&quot;;<br>
$ics_contents .= "TZID:America/New_York\n";
+
<br>
$ics_contents .= "BEGIN:DAYLIGHT\n";
+
<nowiki>#</nowiki> Change the timezone as well daylight settings if need be<br>
$ics_contents .= "TZOFFSETFROM:-0500\n";
+
$ics_contents .= &quot;X-WR-TIMEZONE:America/New_York\n&quot;;<br>
$ics_contents .= "TZOFFSETTO:-0400\n";
+
$ics_contents .= &quot;BEGIN:VTIMEZONE\n&quot;;<br>
$ics_contents .= "DTSTART:20070311T020000\n";
+
$ics_contents .= &quot;TZID:America/New_York\n&quot;;<br>
$ics_contents .= "RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU\n";
+
$ics_contents .= &quot;BEGIN:DAYLIGHT\n&quot;;<br>
$ics_contents .= "TZNAME:EDT\n";
+
$ics_contents .= &quot;TZOFFSETFROM:-0500\n&quot;;<br>
$ics_contents .= "END:DAYLIGHT\n";
+
$ics_contents .= &quot;TZOFFSETTO:-0400\n&quot;;<br>
$ics_contents .= "BEGIN:STANDARD\n";
+
$ics_contents .= &quot;DTSTART:20070311T020000\n&quot;;<br>
$ics_contents .= "TZOFFSETFROM:-0400\n";
+
$ics_contents .= &quot;RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU\n&quot;;<br>
$ics_contents .= "TZOFFSETTO:-0500\n";
+
$ics_contents .= &quot;TZNAME:EDT\n&quot;;<br>
$ics_contents .= "DTSTART:20071104T020000\n";
+
$ics_contents .= &quot;END:DAYLIGHT\n&quot;;<br>
$ics_contents .= "RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU\n";
+
$ics_contents .= &quot;BEGIN:STANDARD\n&quot;;<br>
$ics_contents .= "TZNAME:EST\n";
+
$ics_contents .= &quot;TZOFFSETFROM:-0400\n&quot;;<br>
$ics_contents .= "END:STANDARD\n";
+
$ics_contents .= &quot;TZOFFSETTO:-0500\n&quot;;<br>
$ics_contents .= "END:VTIMEZONE\n";
+
$ics_contents .= &quot;DTSTART:20071104T020000\n&quot;;<br>
 
+
$ics_contents .= &quot;RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU\n&quot;;<br>
$events = mysql_query("SELECT  
+
$ics_contents .= &quot;TZNAME:EST\n&quot;;<br>
node.nid AS nid,
+
$ics_contents .= &quot;END:STANDARD\n&quot;;<br>
  node.title AS title,
+
$ics_contents .= &quot;END:VTIMEZONE\n&quot;;<br>
  node.changed as node_changed,
+
<br>
  node.type AS node_type,
+
$events = mysql_query(&quot;SELECT <br>
  node.vid AS node_vid,
+
node.nid AS nid,<br>
  content_field_date.field_date_value as Start,
+
node.title AS title,<br>
  content_field_date.field_date_value2 as End
+
node.changed as node_changed,<br>
FROM (node
+
node.type AS node_type,<br>
left join content_field_date on node.vid = content_field_date.vid)
+
node.vid AS node_vid,<br>
WHERE type = 'event'
+
content_field_date.field_date_value as Start, <br>
ORDER BY Start
+
content_field_date.field_date_value2 as End<br>
");
+
FROM (node<br>
 
+
left join content_field_date on node.vid = content_field_date.vid)<br>
function clean_url($desc) {
+
WHERE type = 'event'<br>
$desc = html_entity_decode($desc);
+
ORDER BY Start<br>
$desc = strip_tags($desc);
+
&quot;);<br>
$desc = ereg_replace("[^A-Za-z0-9 -|=`~!@#$%^&*()_+,./?><:;'{}]", "", $desc );
+
<br>
return $desc;
+
function clean_url($desc) {<br>
}  
+
$desc = html_entity_decode($desc);<br>
 
+
$desc = strip_tags($desc);<br>
while ($schedule_details = mysql_fetch_assoc($events)) {
+
$desc = ereg_replace(&quot;[^A-Za-z0-9 -|=`~!@#$%^&amp;*()_+,./?&gt;&lt;:;'{}]&quot;, &quot;&quot;, $desc );<br>
 
+
return $desc;<br>
if (date('T', strtotime($schedule_details['Start'])) == "EDT") {
+
} <br>
$Offset = 4*60*60;
+
<br>
} else {
+
while ($schedule_details = mysql_fetch_assoc($events)) {<br>
$Offset = 5*60*60;
+
<br>
}
+
if (date('T', strtotime($schedule_details['Start'])) == &quot;EDT&quot;) {<br>
$Start = strtotime($schedule_details['Start'])-$Offset;
+
$Offset = 4*60*60;<br>
$End = strtotime($schedule_details['End'])-$Offset;
+
} else {<br>
 
+
$Offset = 5*60*60;<br>
#if ($Start >= time()) {
+
}<br>
 
+
$Start = strtotime($schedule_details['Start'])-$Offset;<br>
$desc1 = mysql_query("SELECT * from node_revisions
+
$End = strtotime($schedule_details['End'])-$Offset;<br>
WHERE  
+
<br>
nid = '".$schedule_details['nid']."' and  
+
<br>
vid = '".$schedule_details['node_vid']."'");
+
$desc1 = mysql_query(&quot;SELECT * from node_revisions<br>
 
+
WHERE <br>
$desc1 = mysql_fetch_assoc($desc1);
+
nid = '&quot;.$schedule_details['nid'].&quot;' and <br>
 
+
vid = '&quot;.$schedule_details['node_vid'].&quot;'&quot;);<br>
#echo html_entity_decode($desc1['title'])."<br>";
+
<br>
#echo html_entity_decode($desc1['teaser'])."<br>";
+
$desc1 = mysql_fetch_assoc($desc1);<br>
#echo html_entity_decode($desc1['body'])."<br><br>";
+
<br>
 
+
$Yr = date(Y,$Start);<br>
$Yr = date(Y,$Start);
+
$Mo = date(m,$Start);<br>
$Mo = date(m,$Start);
+
$Day = date(d,$Start);<br>
$Day = date(d,$Start);
+
$Hr = date(H,$Start);<br>
$Hr = date(H,$Start);
+
$Min = date(i,$Start);<br>
$Min = date(i,$Start);
+
$Yr1 = date(Y,$End);<br>
$Yr1 = date(Y,$End);
+
$Mo1 = date(m,$End);<br>
$Mo1 = date(m,$End);
+
$Day1 = date(d,$End);<br>
$Day1 = date(d,$End);
+
$Hr1 = date(H,$End);<br>
$Hr1 = date(H,$End);
+
$Min1 = date(i,$End);<br>
$Min1 = date(i,$End);
+
<br>
 
+
$id = $schedule_details['nid'];<br>
  $id            = $schedule_details['nid'];
+
$start_date = $Yr.&quot;-&quot;.$Mo.&quot;-&quot;.$Day;<br>
  $start_date    = $Yr."-".$Mo."-".$Day;
+
$start_time = $Hr.&quot;:&quot;.$Min.&quot;:00&quot;;<br>
  $start_time    = $Hr.":".$Min.":00";
+
$end_date = $Yr1.&quot;-&quot;.$Mo1.&quot;-&quot;.$Day1;<br>
  $end_date      = $Yr1."-".$Mo1."-".$Day1;
+
$end_time = $Hr1.&quot;:&quot;.$Min1.&quot;:00&quot;; <br>
  $end_time      = $Hr1.":".$Min1.":00";
+
<br>
 
+
$category = &quot;HacDC&quot;;<br>
#  $category      = $schedule_details['Category'];
+
$name = $schedule_details['title'];<br>
  $category      = "HacDC";
+
$location = &quot;1525 Newton St NW, Washington DC 20010 (Near corner of 16th and Newton NW)&quot;;<br>
  $name          = $schedule_details['title'];
+
$description = clean_url(strip_tags($desc1['body']));<br>
  $location     = "1525 Newton St NW, Washington DC 20010 (Near corner of 16th and Newton NW)";
+
<br>
  $description   = clean_url(strip_tags($desc1['body']));
+
<nowiki>#</nowiki> Remove '-' in $start_date and $end_date<br>
+
$estart_date = str_replace(&quot;-&quot;, &quot;&quot;, $start_date);<br>
  # Remove '-' in $start_date and $end_date
+
$eend_date = str_replace(&quot;-&quot;, &quot;&quot;, $end_date);<br>
  $estart_date   = str_replace("-", "", $start_date);
+
<br>
  $eend_date     = str_replace("-", "", $end_date);
+
<nowiki>#</nowiki> Remove ':' in $start_time and $end_time<br>
+
$estart_time = str_replace(&quot;:&quot;, &quot;&quot;, $start_time);<br>
  # Remove ':' in $start_time and $end_time
+
$eend_time = str_replace(&quot;:&quot;, &quot;&quot;, $end_time);<br>
  $estart_time   = str_replace(":", "", $start_time);
+
<br>
  $eend_time     = str_replace(":", "", $end_time);
+
<nowiki>#</nowiki> Replace some HTML tags<br>
+
$name = str_replace(&quot;&lt;br&gt;&quot;, &quot;\\r\\n&quot;, $name);<br>
  # Replace some HTML tags
+
$name = str_replace(&quot;&amp;amp;&quot;, &quot;&amp;&quot;, $name);<br>
  $name         = str_replace("<br>", "\\r\\n",   $name);
+
$name = str_replace(&quot;&amp;rarr;&quot;, &quot;--&gt;&quot;, $name);<br>
  $name         = str_replace("&amp;", "&",   $name);
+
$name = str_replace(&quot;&amp;larr;&quot;, &quot;&lt;--&quot;, $name);<br>
  $name         = str_replace("&rarr;", "-->", $name);
+
$name = str_replace(&quot;,&quot;, &quot;\\,&quot;, $name);<br>
  $name         = str_replace("&larr;", "<--", $name);
+
$name = str_replace(&quot;;&quot;, &quot;\\;&quot;, $name);<br>
  $name         = str_replace(",", "\\,",     $name);
+
<br>
  $name         = str_replace(";", "\\;",     $name);
+
$location = str_replace(&quot;&lt;br&gt;&quot;, &quot;\\r\\n&quot;, $location);<br>
+
$location = str_replace(&quot;&amp;amp;&quot;, &quot;&amp;&quot;, $location);<br>
  $location     = str_replace("<br>", "\\r\\n",   $location);
+
$location = str_replace(&quot;&amp;rarr;&quot;, &quot;--&gt;&quot;, $location);<br>
  $location     = str_replace("&amp;", "&",   $location);
+
$location = str_replace(&quot;&amp;larr;&quot;, &quot;&lt;--&quot;, $location);<br>
  $location     = str_replace("&rarr;", "-->", $location);
+
$location = str_replace(&quot;,&quot;, &quot;\\,&quot;, $location);<br>
  $location     = str_replace("&larr;", "<--", $location);
+
$location = str_replace(&quot;;&quot;, &quot;\\;&quot;, $location);<br>
  $location     = str_replace(",", "\\,",     $location);
+
<br>
  $location     = str_replace(";", "\\;",     $location);
+
$description = str_replace(&quot;&lt;br&gt;&quot;, &quot;\\r\\n&quot;, $description);<br>
+
$description = str_replace(&quot;&amp;amp;&quot;, &quot;&amp;&quot;, $description);<br>
  $description   = str_replace("<br>", "\\r\\n",   $description);
+
$description = str_replace(&quot;&amp;rarr;&quot;, &quot;--&gt;&quot;, $description);<br>
  $description   = str_replace("&amp;", "&",   $description);
+
$description = str_replace(&quot;&amp;larr;&quot;, &quot;&lt;--&quot;, $description);<br>
  $description   = str_replace("&rarr;", "-->", $description);
+
$description = str_replace(&quot;&lt;em&gt;&quot;, &quot;&quot;, $description);<br>
  $description   = str_replace("&larr;", "<--", $description);
+
$description = str_replace(&quot;&lt;/em&gt;&quot;, &quot;&quot;, $description);<br>
  $description   = str_replace("<em>", "",     $description);
+
<br>
  $description   = str_replace("</em>", "",     $description);
+
<nowiki>#</nowiki> Change TZID if need be<br>
+
$ics_contents .= &quot;BEGIN:VEVENT\r\n&quot;;<br>
  # Change TZID if need be
+
$ics_contents .= &quot;DTSTART;TZID=America/New_York:&quot; . $estart_date . &quot;T&quot;.  
  $ics_contents .= "BEGIN:VEVENT\r\n";
+
$estart_time . &quot;\r\n&quot;;<br>
  $ics_contents .= "DTSTART;TZID=America/New_York:"    . $estart_date . "T". $estart_time . "\r\n";
+
$ics_contents .= &quot;DTEND;TZID=America/New_York:&quot; . $eend_date . &quot;T&quot;. $eend_time .  
  $ics_contents .= "DTEND;TZID=America/New_York:"      . $eend_date . "T". $eend_time . "\r\n";
+
&quot;\r\n&quot;;<br>
  $ics_contents .= "DTSTAMP:"    . date('Ymd') . "T". date('His') . "Z\r\n";
+
$ics_contents .= &quot;DTSTAMP:&quot; . date('Ymd') . &quot;T&quot;. date('His') . &quot;Z\r\n&quot;;<br>
  $ics_contents .= "SUMMARY:"    . $name . "\r\n";
+
$ics_contents .= &quot;SUMMARY:&quot; . $name . &quot;\r\n&quot;;<br>
  $ics_contents .= "LOCATION:"    . $location . "\r\n";
+
$ics_contents .= &quot;LOCATION:&quot; . $location . &quot;\r\n&quot;;<br>
  $ics_contents .= "DESCRIPTION:" . $description . "\r\n";
+
$ics_contents .= &quot;DESCRIPTION:&quot; . $description . &quot;\r\n&quot;;<br>
  $ics_contents .= "UID:"        . $id .rand(0,9999). "\r\n";
+
$ics_contents .= &quot;UID:&quot; . $id .rand(0,9999). &quot;\r\n&quot;;<br>
  $ics_contents .= "SEQUENCE:0\r\n";
+
$ics_contents .= &quot;SEQUENCE:0\r\n&quot;;<br>
  $ics_contents .= "END:VEVENT\r\n";
+
$ics_contents .= &quot;END:VEVENT\r\n&quot;;<br>
}
+
}<br>
#}
+
$ics_contents .= &quot;END:VCALENDAR\r\n&quot;;<br>
$ics_contents .= "END:VCALENDAR\r\n";
+
<br>
 
+
echo $ics_contents;<br>
echo $ics_contents;
 
</nowiki>
 

Latest revision as of 14:14, 3 April 2012

Information on this page is Obsolete; it is preserved for historical interest


This code still needs to be cleaned up some.

<?php

include('Drupal.login.php');

$ics_contents = "BEGIN:VCALENDAR\n";
$ics_contents .= "VERSION:2.0\n";
$ics_contents .= "PRODID:PHP\n";
$ics_contents .= "METHOD:PUBLISH\n";
$ics_contents .= "X-WR-CALNAME:HacDC Schedule\n";

# Change the timezone as well daylight settings if need be
$ics_contents .= "X-WR-TIMEZONE:America/New_York\n";
$ics_contents .= "BEGIN:VTIMEZONE\n";
$ics_contents .= "TZID:America/New_York\n";
$ics_contents .= "BEGIN:DAYLIGHT\n";
$ics_contents .= "TZOFFSETFROM:-0500\n";
$ics_contents .= "TZOFFSETTO:-0400\n";
$ics_contents .= "DTSTART:20070311T020000\n";
$ics_contents .= "RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU\n";
$ics_contents .= "TZNAME:EDT\n";
$ics_contents .= "END:DAYLIGHT\n";
$ics_contents .= "BEGIN:STANDARD\n";
$ics_contents .= "TZOFFSETFROM:-0400\n";
$ics_contents .= "TZOFFSETTO:-0500\n";
$ics_contents .= "DTSTART:20071104T020000\n";
$ics_contents .= "RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU\n";
$ics_contents .= "TZNAME:EST\n";
$ics_contents .= "END:STANDARD\n";
$ics_contents .= "END:VTIMEZONE\n";

$events = mysql_query("SELECT
node.nid AS nid,
node.title AS title,
node.changed as node_changed,
node.type AS node_type,
node.vid AS node_vid,
content_field_date.field_date_value as Start,
content_field_date.field_date_value2 as End
FROM (node
left join content_field_date on node.vid = content_field_date.vid)
WHERE type = 'event'
ORDER BY Start
");

function clean_url($desc) {
$desc = html_entity_decode($desc);
$desc = strip_tags($desc);
$desc = ereg_replace("[^A-Za-z0-9 -|=`~!@#$%^&*()_+,./?><:;'{}]", "", $desc );
return $desc;
}

while ($schedule_details = mysql_fetch_assoc($events)) {

if (date('T', strtotime($schedule_details['Start'])) == "EDT") {
$Offset = 4*60*60;
} else {
$Offset = 5*60*60;
}
$Start = strtotime($schedule_details['Start'])-$Offset;
$End = strtotime($schedule_details['End'])-$Offset;


$desc1 = mysql_query("SELECT * from node_revisions
WHERE
nid = '".$schedule_details['nid']."' and
vid = '".$schedule_details['node_vid']."'");

$desc1 = mysql_fetch_assoc($desc1);

$Yr = date(Y,$Start);
$Mo = date(m,$Start);
$Day = date(d,$Start);
$Hr = date(H,$Start);
$Min = date(i,$Start);
$Yr1 = date(Y,$End);
$Mo1 = date(m,$End);
$Day1 = date(d,$End);
$Hr1 = date(H,$End);
$Min1 = date(i,$End);

$id = $schedule_details['nid'];
$start_date = $Yr."-".$Mo."-".$Day;
$start_time = $Hr.":".$Min.":00";
$end_date = $Yr1."-".$Mo1."-".$Day1;
$end_time = $Hr1.":".$Min1.":00";

$category = "HacDC";
$name = $schedule_details['title'];
$location = "1525 Newton St NW, Washington DC 20010 (Near corner of 16th and Newton NW)";
$description = clean_url(strip_tags($desc1['body']));

# Remove '-' in $start_date and $end_date
$estart_date = str_replace("-", "", $start_date);
$eend_date = str_replace("-", "", $end_date);

# Remove ':' in $start_time and $end_time
$estart_time = str_replace(":", "", $start_time);
$eend_time = str_replace(":", "", $end_time);

# Replace some HTML tags
$name = str_replace("<br>", "\\r\\n", $name);
$name = str_replace("&amp;", "&", $name);
$name = str_replace("&rarr;", "-->", $name);
$name = str_replace("&larr;", "<--", $name);
$name = str_replace(",", "\\,", $name);
$name = str_replace(";", "\\;", $name);

$location = str_replace("<br>", "\\r\\n", $location);
$location = str_replace("&amp;", "&", $location);
$location = str_replace("&rarr;", "-->", $location);
$location = str_replace("&larr;", "<--", $location);
$location = str_replace(",", "\\,", $location);
$location = str_replace(";", "\\;", $location);

$description = str_replace("<br>", "\\r\\n", $description);
$description = str_replace("&amp;", "&", $description);
$description = str_replace("&rarr;", "-->", $description);
$description = str_replace("&larr;", "<--", $description);
$description = str_replace("<em>", "", $description);
$description = str_replace("</em>", "", $description);

# Change TZID if need be
$ics_contents .= "BEGIN:VEVENT\r\n";
$ics_contents .= "DTSTART;TZID=America/New_York:" . $estart_date . "T". $estart_time . "\r\n";
$ics_contents .= "DTEND;TZID=America/New_York:" . $eend_date . "T". $eend_time . "\r\n";
$ics_contents .= "DTSTAMP:" . date('Ymd') . "T". date('His') . "Z\r\n";
$ics_contents .= "SUMMARY:" . $name . "\r\n";
$ics_contents .= "LOCATION:" . $location . "\r\n";
$ics_contents .= "DESCRIPTION:" . $description . "\r\n";
$ics_contents .= "UID:" . $id .rand(0,9999). "\r\n";
$ics_contents .= "SEQUENCE:0\r\n";
$ics_contents .= "END:VEVENT\r\n";
}
$ics_contents .= "END:VCALENDAR\r\n";

echo $ics_contents;