Moved index.php functionality to ical.php. index.php now contains primitive front... master
authorRichard Whitehouse <github@richardwhiuk.com>
Sun, 13 Feb 2011 02:30:24 +0000 (02:30 +0000)
committerRichard Whitehouse <github@richardwhiuk.com>
Sun, 13 Feb 2011 02:30:24 +0000 (02:30 +0000)
cache/.gitignore [new file with mode: 0644]
ical.php [new file with mode: 0644]
index.php

diff --git a/cache/.gitignore b/cache/.gitignore
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/ical.php b/ical.php
new file mode 100644 (file)
index 0000000..e79ac41
--- /dev/null
+++ b/ical.php
@@ -0,0 +1,116 @@
+<?php
+
+$url = null;
+
+require 'config.php';
+
+if(!isset($url)){
+
+       if(!isset($_GET['url'])){
+               header('Location: index.php');
+       }
+
+       $url = $_GET['url'];
+       $type = md5($url);
+}
+
+$file = file($url);
+
+$directives = array();
+
+// Write a cache file for debugging
+
+$fp = fopen('cache/' . $type . '-' . time() . '.ics', 'w');
+
+if(!isset($_GET['debug'])){
+       header('Content-type: text/calendar;charset=utf-8');
+       header('Content-Disposition: attachment; filename=relay.ics');
+       foreach($file as $line){
+               echo $line;
+               fwrite($fp, $line);
+       }       
+       fclose($fp);
+       exit;
+}
+
+header('Content-type: text/plain; charset=utf-8');
+
+$d = -1;
+
+foreach($file as $line){
+       $line = rtrim($line, "\r\n");
+       if($line[0] == "\t" || $line[0] == " "){
+               $directives[$d] .= substr($line,1);
+       } else {
+               $d ++;
+               $directives[$d] = $line;
+       }
+}
+
+// sanity check
+
+if(
+       ($directives[0] != 'BEGIN:VCALENDAR') ||
+       ($directives[$d] != 'END:VCALENDAR')
+){
+       exit('INVALID .ICAL FILE');
+}
+
+$ical = new ical_obj();
+
+$current = $ical;
+
+class ical_obj {
+       public $_type = NULL;
+       public $_parent = NULL;
+       private $_data = array();
+       function __isset($name){
+               return isset($this->_data[$name]);
+       }
+       function __get($name){
+               return $this->_data[$name];
+       }
+       function __set($name, $value){
+               return ($this->_data[$name][] = $value);
+       }
+       function __unset($name){
+               unset($this->_data[$name]);
+       }
+       function display($t = 0){
+               foreach($this->_data as $k => $l){
+                       foreach($l as $v){
+                               for($i = 0; $i < $t; $i ++){ echo "\t"; }
+                               echo $k . ': ';
+                               if(is_object($v)){
+                                       echo "\r\n";  $v->display($t + 1);
+                               } else {
+                                       echo $v . "\r\n";
+                               }
+                       }
+               }
+       }
+}
+
+foreach($directives as $line){
+       $directive = explode(':', $line, 2);
+       if($directive[0] == 'BEGIN'){
+               $child = new ical_obj();
+               $child->_type = $type = $directive[1];
+               $child->_parent = $current;
+               $current->$type = $child;
+               $current = $child;
+       } elseif($directive[0] == 'END'){
+               if($current->_type != $directive[1]){
+                       exit('INVALID .ICAL FILE');
+               }
+               $current = $current->_parent;
+       } else {
+               $type = $directive[0];
+               $current->$type = $directive[1];
+       }
+}
+
+$ical->display();
+
+fclose($fp);
+
index 3f41850dde8063cf85bb5bfe9a810d5bf7e632cf..9faa6f598b803ec831f2598dd4a1ad79cebb2d30 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,87 +1,12 @@
-<?php
-
-$url = $_GET['url'];
-
-$file = file($url);
-
-$directives = array();
-
-header('Content-type: text/plain; charset=utf-8');
-
-$d = -1;
-
-foreach($file as $line){
-       $line = rtrim($line, "\r\n");
-       if($line[0] == "\t" || $line[0] == " "){
-               $directives[$d] .= substr($line,1);
-       } else {
-               $d ++;
-               $directives[$d] = $line;
-       }
-}
-
-// sanity check
-
-if(
-       ($directives[0] != 'BEGIN:VCALENDAR') ||
-       ($directives[$d] != 'END:VCALENDAR')
-){
-       exit('INVALID .ICAL FILE');
-}
-
-$ical = new ical_obj();
-
-$current = $ical;
-
-class ical_obj {
-       public $_type = NULL;
-       public $_parent = NULL;
-       private $_data = array();
-       function __isset($name){
-               return isset($this->_data[$name]);
-       }
-       function __get($name){
-               return $this->_data[$name];
-       }
-       function __set($name, $value){
-               return ($this->_data[$name][] = $value);
-       }
-       function __unset($name){
-               unset($this->_data[$name]);
-       }
-       function display($t = 0){
-               foreach($this->_data as $k => $l){
-                       foreach($l as $v){
-                               for($i = 0; $i < $t; $i ++){ echo "\t"; }
-                               echo $k . ': ';
-                               if(is_object($v)){
-                                       echo "\r\n";  $v->display($t + 1);
-                               } else {
-                                       echo $v . "\r\n";
-                               }
-                       }
-               }
-       }
-}
-
-foreach($directives as $line){
-       $directive = explode(':', $line, 2);
-       if($directive[0] == 'BEGIN'){
-               $child = new ical_obj();
-               $child->_type = $type = $directive[1];
-               $child->_parent = $current;
-               $current->$type = $child;
-               $current = $child;
-       } elseif($directive[0] == 'END'){
-               if($current->_type != $directive[1]){
-                       exit('INVALID .ICAL FILE');
-               }
-               $current = $current->_parent;
-       } else {
-               $type = $directive[0];
-               $current->$type = $directive[1];
-       }
-}
-
-$ical->display();
-
+<!DOCTYPE html>
+<html>
+<head>
+       <title>iCal Relay</title>
+</head>
+<body>
+<form action="ical.php" method="get">
+       <p>URL: <input type="text" value="" name="url"></p>
+       <p><input type="submit" value="Relay!"></p>
+</form>
+</body>
+</html>