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