| ** |
| |
63 |
63 |
|
* Takes the raw data and makes some comaptibility magic on it |
| |
64 |
64 |
|
* |
  |
65 |
|
- |
* @param string $rawData The raw (partial) ICS data |
| |
66 |
|
- |
* @param boolean $cleanData Wether to clean the data or not; this should |
| |
67 |
|
- |
* only be done once on the entire data |
| |
|
65 |
+ |
* @param string $rawData The raw ICS data |
| |
68 |
66 |
|
*/ |
  |
69 |
|
- |
public function __construct($rawData, $cleanData = true) |
| |
|
67 |
+ |
public function __construct($rawData) |
| |
70 |
68 |
|
{ |
  |
71 |
|
- |
// Clean the data only if required |
| |
72 |
|
- |
if ($cleanData === true) { |
| |
73 |
|
- |
// Convert \r\n and single \r's to \ņ |
| |
74 |
|
- |
$rawData = preg_replace("#\r\n?#", "\n", $rawData); |
| |
|
69 |
+ |
// Convert to single new-line endings |
| |
|
70 |
+ |
$rawData = preg_replace("#\r\n?#", "\n", $rawData); |
| |
75 |
71 |
|
|
  |
76 |
|
- |
// Unfold the raw data |
| |
77 |
|
- |
$rawData = str_replace(array("\n ", "\n\t"), '', $rawData); |
| |
78 |
|
- |
} |
| |
|
72 |
+ |
// Unfold the raw data |
| |
|
73 |
+ |
$rawData = str_replace(array("\n ", "\n\t"), '', $rawData); |
| |
79 |
74 |
|
|
  |
80 |
|
- |
// Finally set them internally |
| |
|
75 |
+ |
// Save data internally |
| |
81 |
76 |
|
$this->_rawData = $rawData; |
| |
82 |
77 |
|
$this->_rawDataLength = strlen($rawData); |
| |
83 |
78 |
|
} |
| |
|
|

|
…
|
| |
100 |
95 |
|
* parsed until it's end. |
| |
101 |
96 |
|
* |
| |
102 |
97 |
|
* @param string $currentNodeName Name of the node which this run is parsing |
  |
103 |
|
- |
* @throws Zend_Ical_Exception When there is a lonely \r |
| |
104 |
98 |
|
* @throws Zend_Ical_Exception When there is an unknown node |
  |
105 |
|
- |
* @throws Zend_Ical_Exception When an unexpected END: occurs |
| |
|
99 |
+ |
* @throws Zend_Ical_Exception When an unexpected END occurs |
| |
106 |
100 |
|
* @return array |
| |
107 |
101 |
|
*/ |
| |
108 |
102 |
|
protected function _parseNode($currentNodeName = null) |
| |
109 |
103 |
|
{ |
| |
110 |
104 |
|
$nodes = array(); |
| |
111 |
105 |
|
$properties = array(); |
  |
|
106 |
+ |
$token = ''; |
| |
|
107 |
+ |
$delimiters = ':;'; |
| |
112 |
108 |
|
$tokenIsNodeBegin = false; |
| |
113 |
109 |
|
$tokenIsNodeEnd = false; |
  |
114 |
|
- |
|
| |
115 |
|
- |
if ($currentNodeName === null) { |
| |
116 |
|
- |
$token = strtok($this->_rawData, ':;'); |
| |
117 |
|
- |
} else { |
| |
118 |
|
- |
$token = strtok(':;'); |
| |
119 |
|
- |
} |
| |
120 |
|
- |
|
| |
121 |
|
- |
while ($token !== false) { |
| |
122 |
|
- |
if ($tokenIsNodeBegin) { |
| |
|
110 |
+ |
|
| |
|
111 |
+ |
// Loop through all characters |
| |
|
112 |
+ |
while ($this->_rawDataLength > $this->_currentPos) { |
| |
|
113 |
+ |
// Get the current character |
| |
|
114 |
+ |
$char = $this->_rawData[$this->_currentPos++]; |
| |
|
115 |
+ |
|
| |
|
116 |
+ |
// Add the character to the token if delimiter was not reached |
| |
|
117 |
+ |
if (strpos($delimiters, $char) === false) { |
| |
|
118 |
+ |
$token .= $char; |
| |
|
119 |
+ |
|
| |
|
120 |
+ |
continue; |
| |
|
121 |
+ |
} |
| |
|
122 |
+ |
|
| |
|
123 |
+ |
// Check the token |
| |
|
124 |
+ |
if ($tokenIsNodeBegin === true) { |
| |
123 |
125 |
|
// Validate the node name |
  |
124 |
|
- |
if (in_array($token, $this->_validNodeNames) === true) { |
| |
|
126 |
+ |
if (in_array($token, $this->_validNodeNames)) { |
| |
125 |
127 |
|
$node = array('name' => $token); |
| |
126 |
128 |
|
} else { |
  |
|
129 |
+ |
require_once 'Zend/Ical/Exception.php'; |
| |
127 |
130 |
|
throw new Zend_Ical_Exception('Unknown node `' . $token . '`'); |
| |
128 |
131 |
|
} |
| |
129 |
132 |
|
|
| |
130 |
133 |
|
// If everything was fine, parse the node |
| |
131 |
134 |
|
$nodes[] = array_merge($node, $this->_parseNode($token)); |
  |
132 |
|
- |
|
| |
|
135 |
+ |
|
| |
133 |
136 |
|
$tokenIsNodeBegin = false; |
  |
134 |
|
- |
} elseif ($tokenIsNodeEnd) { |
| |
|
137 |
+ |
} else if ($tokenIsNodeEnd === true) { |
| |
|
138 |
+ |
// This is the full node name, so we can check if it is the end |
| |
135 |
139 |
|
if ($token !== $currentNodeName) { |
  |
|
140 |
+ |
require_once 'Zend/Ical/Exception.php'; |
| |
136 |
141 |
|
throw new Zend_Ical_Exception('Expected `END:' . $currentNodeName |
| |
137 |
142 |
|
. '`, but `END:' . $token . '` found'); |
| |
138 |
143 |
|
} |
| |
139 |
144 |
|
|
| |
140 |
145 |
|
// Node is finished, break out and return it |
| |
141 |
146 |
|
break; |
  |
142 |
|
- |
} elseif ($token === 'BEGIN') { |
| |
143 |
|
- |
// Next token should be the name of the beginning node |
| |
|
147 |
+ |
} else if ($token === 'BEGIN') { |
| |
|
148 |
+ |
// This is a new node, tell the next round that it should treat |
| |
|
149 |
+ |
// it like that. |
| |
144 |
150 |
|
$tokenIsNodeBegin = true; |
  |
145 |
|
- |
$token = strtok("\n"); |
| |
146 |
|
- |
} elseif ($token === 'END') { |
| |
147 |
|
- |
// Next token should be the name of the ending node |
| |
|
151 |
+ |
$delimiters = "\n"; |
| |
|
152 |
+ |
} else if ($token === 'END') { |
| |
|
153 |
+ |
// It seems like the current node would end yet, let's check it |
| |
148 |
154 |
|
$tokenIsNodeEnd = true; |
  |
149 |
|
- |
$token = strtok("\n"); |
| |
|
155 |
+ |
$delimiters = "\n"; |
| |
150 |
156 |
|
} else { |
  |
151 |
|
- |
if (trim($token) !== '') { |
| |
152 |
|
- |
$colonPos = strpos($token, ':'); |
| |
153 |
|
- |
$semicolonPos = strpos($token, ';'); |
| |
154 |
|
- |
|
| |
155 |
|
- |
if ($semicolonPos !== false && $semicolonPos < $colonPos) { |
| |
156 |
|
- |
$propertyName = substr($token, 0, $semicolonPos); |
| |
157 |
|
- |
$parameters = substr($token, ($semicolonPos + 1), ($colonPos - $semicolonPos - 1)); |
| |
158 |
|
- |
$value = substr($token, ($colonPos + 1), -2); |
| |
159 |
|
- |
} else { |
| |
160 |
|
- |
$propertyName = substr($token, 0, $colonPos); |
| |
161 |
|
- |
$parameters = null; |
| |
162 |
|
- |
$value = substr($token, ($colonPos + 1), -2); |
| |
163 |
|
- |
} |
| |
164 |
|
- |
|
| |
165 |
|
- |
$properties[] = array('name' => $propertyName, |
| |
166 |
|
- |
'parameters' => $parameters, |
| |
167 |
|
- |
'value' => $value); |
| |
168 |
|
- |
} |
| |
169 |
|
- |
|
| |
170 |
|
- |
$token = strtok(":;\n"); |
| |
|
157 |
+ |
// This could be a property, check it |
| |
|
158 |
+ |
$delimiters = ';:'; |
| |
171 |
159 |
|
} |
  |
|
160 |
+ |
|
| |
|
161 |
+ |
$token = ''; |
| |
172 |
162 |
|
} |
  |
173 |
|
- |
|