1 | <?php |
---|
2 | /** |
---|
3 | * Serviço ical |
---|
4 | * |
---|
5 | * Classe responsavel por gerar, e interpretar arquivos ical/vcalendar. |
---|
6 | * |
---|
7 | * @package Service |
---|
8 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
9 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
10 | * @author Cristiano Corr?a Schmidt |
---|
11 | * @version 1.0 |
---|
12 | * @since Classe disponibilizada na versão 1.0 |
---|
13 | */ |
---|
14 | class ICalService |
---|
15 | { |
---|
16 | private $ical; |
---|
17 | |
---|
18 | function ICalService() |
---|
19 | { |
---|
20 | require_once ( LIBRARY.'/iCalcreator/iCalcreator.class.php' ); |
---|
21 | } |
---|
22 | |
---|
23 | /** |
---|
24 | * Cria um novo Ical |
---|
25 | * |
---|
26 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
27 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
28 | * @author Cristiano Corrêa Schmidt |
---|
29 | * @param string $method |
---|
30 | * @access private |
---|
31 | */ |
---|
32 | public function createICal($method) |
---|
33 | { |
---|
34 | |
---|
35 | $this->ical = new vcalendar(); |
---|
36 | |
---|
37 | /* |
---|
38 | * Seta propiedades obrigatorias para alguns softwares (Outlook) |
---|
39 | */ |
---|
40 | $this->ical->setProperty( 'method' , $method ); |
---|
41 | $this->ical->setProperty( 'x-wr-calname', 'Calendar Expresso' ); |
---|
42 | $this->ical->setProperty( 'X-WR-CALDESC', 'Calendar Expresso' ); |
---|
43 | $this->ical->setProperty( 'X-WR-TIMEZONE', date('e') ); |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * Adiciona um novo Evento |
---|
48 | * |
---|
49 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
50 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
51 | * @author Cristiano Corrêa Schmidt |
---|
52 | * @param miexed $dtStart 0000-00-00 00:00:00 | array('0000-00-00 00:00:00' => array('XXXX' => 'XXXX')) |
---|
53 | * @param miexed $dtEnd 0000-00-00 00:00:00 | array('0000-00-00 00:00:00' => array('XXXX' => 'XXXX')) |
---|
54 | * @param miexed $organizer array('xxx@xxx.com.br' => array('cn' => 'XXXXXXXX')) |
---|
55 | * @param miexed $summary xxxxx | array('XXXX' => array('XXXX' => 'XXXX')) |
---|
56 | * @param miexed $description xxxxx | array( 'XXXX'=> array('XXXX' => 'XXXX')) |
---|
57 | * @param miexed $location xxxxx | array( 'XXXX'=> array('XXXX' => 'XXXX')) |
---|
58 | * @param array $attendee array('xxx@xxx.com.br' => array('cn') => 'XXXX XXXX')) |
---|
59 | * @param array $other array('xxxx' => array('xxx' => array('xxx' =>'xxx')) |
---|
60 | * @param array $components |
---|
61 | * @param string $uid |
---|
62 | * @access public |
---|
63 | */ |
---|
64 | public function addEvent($dtStart,$dtEnd,$organizer,$summary,$description,$location,$attendee = false,$other = false,$components = false,$uid = false) |
---|
65 | { |
---|
66 | $vevent = &$this->ical->newComponent( 'vevent' ); |
---|
67 | |
---|
68 | $this->setP($vevent, 'dtstart', $dtStart); |
---|
69 | $this->setP($vevent, 'dtend', $dtEnd); |
---|
70 | $this->setP($vevent, 'organizer', $organizer); |
---|
71 | $this->setP($vevent, 'summary', $summary); |
---|
72 | $this->setP($vevent, 'description', $description); |
---|
73 | $this->setP($vevent, 'location', $location); |
---|
74 | |
---|
75 | if($attendee) |
---|
76 | $this->setP($vevent, 'attendee', $attendee); |
---|
77 | |
---|
78 | if($other) |
---|
79 | { |
---|
80 | foreach ($other as $property => $value) |
---|
81 | $this->setP($vevent, 'attendee', $value); |
---|
82 | } |
---|
83 | |
---|
84 | if($components) |
---|
85 | { |
---|
86 | foreach ($components as $component) |
---|
87 | foreach ($component as $name => $value) |
---|
88 | $this->setC($vevent, $name, $value); |
---|
89 | } |
---|
90 | |
---|
91 | if($uid === false) |
---|
92 | $uid = time().'@Expresso'; |
---|
93 | |
---|
94 | $vevent->setProperty( 'uid' , $uid ); |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | * Seta uma propiedade ao componente |
---|
99 | * |
---|
100 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
101 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
102 | * @author Cristiano Corrêa Schmidt |
---|
103 | * @param mixed $component |
---|
104 | * @param string $property Tipo de propiedade |
---|
105 | * @param mixed $value |
---|
106 | * @access private |
---|
107 | */ |
---|
108 | private function setP($component,$property,$value) |
---|
109 | { |
---|
110 | if(is_array($value)) |
---|
111 | { |
---|
112 | foreach ($value as $value2 => $params) |
---|
113 | $component->setProperty( $property , $value2 , $params ); |
---|
114 | } |
---|
115 | else |
---|
116 | $component->setProperty( $property , $value ); |
---|
117 | } |
---|
118 | |
---|
119 | /** |
---|
120 | * Seta um componente ao componente |
---|
121 | * |
---|
122 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
123 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
124 | * @author Cristiano Corrêa Schmidt |
---|
125 | * @param mixed $component |
---|
126 | * @param string $name Tipo do componente |
---|
127 | * @param mixed $value |
---|
128 | * @access private |
---|
129 | */ |
---|
130 | private function setC($component,$name,$value) |
---|
131 | { |
---|
132 | $comp = & $component->newComponent( $name ); |
---|
133 | foreach ($value as $key => $value2) |
---|
134 | $this->setP($comp,$key,$value2); |
---|
135 | } |
---|
136 | |
---|
137 | /** |
---|
138 | * Importa ical via string ou caminho do arquivo ics |
---|
139 | * |
---|
140 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
141 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
142 | * @author Cristiano Corrêa Schmidt |
---|
143 | * @param string $iCal |
---|
144 | * @access public |
---|
145 | */ |
---|
146 | public function setIcal($iCal) |
---|
147 | { |
---|
148 | $this->ical = new vcalendar(); |
---|
149 | return $this->ical->parse($iCal); |
---|
150 | } |
---|
151 | |
---|
152 | /** |
---|
153 | * Retorna todos os componentes do ical parseados |
---|
154 | * |
---|
155 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
156 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
157 | * @author Cristiano Corrêa Schmidt |
---|
158 | * @return array |
---|
159 | * @access public |
---|
160 | */ |
---|
161 | public function getComponents() |
---|
162 | { |
---|
163 | |
---|
164 | $return = array(); |
---|
165 | |
---|
166 | $componentes = $this->ical->getConfig('compsinfo'); |
---|
167 | foreach ($componentes as $key => $value) |
---|
168 | { |
---|
169 | $return[] = $this->parseComponent($this->ical->getComponent( $key ), $value['type']); |
---|
170 | } |
---|
171 | return $return; |
---|
172 | } |
---|
173 | |
---|
174 | /** |
---|
175 | * Retorna componente especificado, tipo ou o numero do componente |
---|
176 | * |
---|
177 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
178 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
179 | * @author Cristiano Corrêa Schmidt |
---|
180 | * @param mixed $component |
---|
181 | * @return array |
---|
182 | * @access public |
---|
183 | */ |
---|
184 | public function getComponent($component) |
---|
185 | { |
---|
186 | if(is_int($component)) |
---|
187 | { |
---|
188 | $componentes = $this->ical->getConfig('compsinfo'); |
---|
189 | return $this->parseComponent($this->ical->getComponent($component),$componentes[$component]['type']); |
---|
190 | } |
---|
191 | else |
---|
192 | return $this->parseComponent($this->ical->getComponent($component),$component); |
---|
193 | } |
---|
194 | |
---|
195 | /** |
---|
196 | * Retorna metodo usado no ical |
---|
197 | * |
---|
198 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
199 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
200 | * @author Cristiano Corrêa Schmidt |
---|
201 | * @return string |
---|
202 | * @access public |
---|
203 | */ |
---|
204 | public function getMethod() |
---|
205 | { |
---|
206 | return strtoupper($this->ical->getProperty( 'method' )); |
---|
207 | } |
---|
208 | |
---|
209 | /** |
---|
210 | * Retorna um array com as informações dos componentes |
---|
211 | * |
---|
212 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
213 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
214 | * @author Cristiano Corrêa Schmidt |
---|
215 | * @return array |
---|
216 | * @access public |
---|
217 | */ |
---|
218 | public function getComponentInfo() |
---|
219 | { |
---|
220 | return $this->ical->getConfig('compsinfo'); |
---|
221 | } |
---|
222 | |
---|
223 | |
---|
224 | /** |
---|
225 | * Parseia o componente em um array |
---|
226 | * |
---|
227 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
228 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
229 | * @author Cristiano Corrêa Schmidt |
---|
230 | * @param mixed $component |
---|
231 | * @param string $type |
---|
232 | * @return array |
---|
233 | * @access private |
---|
234 | */ |
---|
235 | private function parseComponent($component,$type) |
---|
236 | { |
---|
237 | $return = array(); |
---|
238 | |
---|
239 | switch (strtoupper($type)) { |
---|
240 | case 'VEVENT': |
---|
241 | |
---|
242 | $return['type'] = 'VEVENT'; |
---|
243 | $return['summary'] = $component->getProperty( 'summary' , FALSE , TRUE ); |
---|
244 | $return['description'] = $component->getProperty( 'description' ,FALSE,TRUE); |
---|
245 | $return['organizer'] = $component->getProperty( 'organizer' , FALSE , TRUE ); |
---|
246 | $return['organizer']['value'] = str_replace('MAILTO:', '', $return['organizer']['value']); |
---|
247 | $return['location'] = $component->getProperty( 'location', FALSE , TRUE ); |
---|
248 | $return['dtstart'] = $component->getProperty( 'dtstart', FALSE , TRUE ); |
---|
249 | $return['dtend'] = $component->getProperty( 'dtend', FALSE , TRUE ); |
---|
250 | $return['status'] = $component->getProperty( 'status' , FALSE , TRUE ); |
---|
251 | $return['class'] = $component->getProperty( 'class' , FALSE , TRUE ); |
---|
252 | $return['priority'] = $component->getProperty( 'priority' , FALSE , TRUE ); |
---|
253 | $return['uid'] = $component->getProperty( 'uid' , FALSE , TRUE ); |
---|
254 | $return['dtstamp'] = $component->getProperty( 'dtstamp' , FALSE , TRUE ); |
---|
255 | $return['sequence'] = $component->getProperty( 'sequence' , FALSE , TRUE ); |
---|
256 | $return['request-status'] = $component->getProperty( 'request-status' , propOrderNo/FALSE, TRUE ); |
---|
257 | $return['rrule'] = $component->getProperty( 'rrule' , propOrderNo/FALSE, TRUE ); |
---|
258 | $return['transp'] = $component->getProperty( 'transp' , FALSE , TRUE ); |
---|
259 | $return['url'] = $component->getProperty( 'url' , FALSE , TRUE ); |
---|
260 | $return['recurrence-id'] = $component->getProperty( 'recurrence-id' , FALSE , TRUE ); |
---|
261 | $return['attach'] = $component->getProperty( 'attach' , FALSE , TRUE ); |
---|
262 | $return['comment'] = $component->getProperty( 'comment' , FALSE , TRUE ); |
---|
263 | $return['created'] = $component->getProperty( 'created' , FALSE , TRUE ); |
---|
264 | $return['duration'] = $component->getProperty( 'duration' , FALSE , TRUE ); |
---|
265 | $return['geo'] = $component->getProperty( 'geo' , FALSE , TRUE ); |
---|
266 | $return['last-modified'] = $component->getProperty( 'last-modified', FALSE , TRUE ); |
---|
267 | $return['rdate'] = $component->getProperty( 'rdate' , propOrderNo/FALSE , TRUE ); |
---|
268 | $return['related-to'] = $component->getProperty( 'related-to' , propOrderNo/FALSE , TRUE ); |
---|
269 | $return['resources'] = $component->getProperty( 'resources' , propOrderNo/FALSE, TRUE ); |
---|
270 | |
---|
271 | while($property = $component->getProperty( FALSE, propOrderNo/FALSE, TRUE )){$return['x-property'][] = array('name' => $property[0], 'value' => $property[1]['value'],'params' => $property[1]['params']);}; |
---|
272 | |
---|
273 | while($property = $component->getProperty('attendee',propOrderNo/FALSE , TRUE)) |
---|
274 | { |
---|
275 | $ateendee = $property; |
---|
276 | $ateendee['value'] = str_replace('MAILTO:', '', $ateendee['value']); |
---|
277 | $return['attendee'][] = $ateendee; |
---|
278 | }; |
---|
279 | |
---|
280 | while($property = $component->getProperty('categories',propOrderNo/FALSE , TRUE)){$return['categories'][] = $property;}; |
---|
281 | while($component->getProperty('contact',propOrderNo/FALSE , TRUE)){$return['contact'][] = $property;}; |
---|
282 | while($component->getProperty('exdate',propOrderNo/FALSE , TRUE)){$return['exdate'][] = $property;}; |
---|
283 | while($component->getProperty('exrule',propOrderNo/FALSE , TRUE)){$return['exrule'][] = $property;}; |
---|
284 | |
---|
285 | $return['sub'] = array(); |
---|
286 | |
---|
287 | $componentes = $component->getConfig('compsinfo'); |
---|
288 | foreach ($componentes as $key => $value) |
---|
289 | $return['sub'][] = $this->parseComponent($component->getComponent( $key ), $value['type']); |
---|
290 | |
---|
291 | break; |
---|
292 | |
---|
293 | case 'VALARM': |
---|
294 | $return['type'] = 'VALARM'; |
---|
295 | $return['action'] = $component->getProperty( 'action' , FALSE , TRUE ); |
---|
296 | $return['attach'] = $component->getProperty( 'attach' , FALSE , TRUE ); |
---|
297 | $return['description'] = $component->getProperty( 'description' ,FALSE,TRUE); |
---|
298 | $return['duration'] = $component->getProperty( 'duration' , FALSE , TRUE ); |
---|
299 | $return['repeat'] = $component->getProperty( 'repeat', FALSE , TRUE ); |
---|
300 | $return['summary'] = $component->getProperty( 'summary' , FALSE , TRUE ); |
---|
301 | $return['trigger'] = $component->getProperty( 'trigger' , FALSE , TRUE ); |
---|
302 | while($property = $component->getProperty( FALSE, propOrderNo/FALSE, TRUE )){$return['x-property'][] = array('name' => $property[0], 'value' => $property[1]['value'],'params' => $property[1]['params']);}; |
---|
303 | |
---|
304 | break; |
---|
305 | default: |
---|
306 | break; |
---|
307 | } |
---|
308 | |
---|
309 | |
---|
310 | return $return; |
---|
311 | } |
---|
312 | |
---|
313 | /** |
---|
314 | * Retorna o ical em uma string |
---|
315 | * |
---|
316 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
317 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
318 | * @author Cristiano Corrêa Schmidt |
---|
319 | * @return string |
---|
320 | * @access prublic |
---|
321 | */ |
---|
322 | public function getICal() |
---|
323 | { |
---|
324 | return $this->ical->createCalendar(); |
---|
325 | } |
---|
326 | |
---|
327 | /** |
---|
328 | * Retorna o ical para download direto |
---|
329 | * |
---|
330 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
331 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
332 | * @author Cristiano Corrêa Schmidt |
---|
333 | * @return string |
---|
334 | * @access prublic |
---|
335 | */ |
---|
336 | public function downloadICal() |
---|
337 | { |
---|
338 | return $this->ical->returnCalendar(); |
---|
339 | } |
---|
340 | |
---|
341 | /** |
---|
342 | * Salva o ical em disco |
---|
343 | * |
---|
344 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
345 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
346 | * @author Cristiano Corrêa Schmidt |
---|
347 | * @param string $directory |
---|
348 | * @param string $filename |
---|
349 | * @return string |
---|
350 | * @access prublic |
---|
351 | */ |
---|
352 | public function saveICal($directory,$filename) |
---|
353 | { |
---|
354 | $config = array( 'directory' => $directory, 'filename' => $filename); |
---|
355 | $this->ical->setConfig( $config ); |
---|
356 | $this->ical->saveCalendar(); |
---|
357 | } |
---|
358 | |
---|
359 | } |
---|
360 | |
---|
361 | ServiceLocator::register( 'ical', new ICalService() ); |
---|
362 | |
---|
363 | ?> |
---|