ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCalendarRemoteReader.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
5include_once './Services/WebServices/Curl/classes/class.ilCurlConnection.php';
6include_once './Services/WebServices/Curl/classes/class.ilCurlConnectionException.php';
7
15{
16 const TYPE_ICAL = 1;
17
18 // Fixed in the moment
20
21 private $curl = null;
22
23 private $url;
24 private $user;
25 private $pass;
26
27 private $ical;
28
29
34 public function __construct($a_url)
35 {
36 $this->url = $a_url;
37 }
38
39 public function setUser($a_user)
40 {
41 $this->user = $a_user;
42 }
43
44 public function setPass($a_pass)
45 {
46 $this->pass = $a_pass;
47 }
48
49 public function getType()
50 {
51 return $this->type;
52 }
53
54 public function getUrl()
55 {
56 return $this->url;
57 }
58
59
65 public function read()
66 {
67 $this->initCurl();
68
69 switch ($this->getType()) {
70 case self::TYPE_ICAL:
71 return $this->readIcal();
72 }
73 }
74
79 public function import(ilCalendarCategory $cat)
80 {
81 switch ($this->getType()) {
82 case self::TYPE_ICAL:
83 return $this->importIcal($cat);
84 }
85 }
86
92 protected function readIcal()
93 {
94 $this->ical = $this->call();
95 $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->ical);
96 return true;
97 }
98
103 protected function importIcal(ilCalendarCategory $cat)
104 {
105 // Delete old appointments
106 include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
108 include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
110 }
112
113 // Import new appointments
114 include_once './Services/Calendar/classes/iCal/class.ilICalParser.php';
116 $parser->setCategoryId($cat->getCategoryID());
117 $parser->parse();
118 }
119
123 protected function initCurl()
124 {
125 try {
126 $this->replaceWebCalProtocol();
127
128 $this->curl = new ilCurlConnection($this->getUrl());
129 $this->curl->init();
130
131 if (ilProxySettings::_getInstance()->isActive()) {
132 $this->curl->setOpt(CURLOPT_HTTPPROXYTUNNEL, true);
133 $this->curl->setOpt(CURLOPT_PROXY, ilProxySettings::_getInstance()->getHost());
134 $this->curl->setOpt(CURLOPT_PROXYPORT, ilProxySettings::_getInstance()->getPort());
135 }
136
137 $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
138 $this->curl->setOpt(CURLOPT_SSL_VERIFYHOST, 0);
139 $this->curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
140
141 $this->curl->setOpt(CURLOPT_FOLLOWLOCATION, 1);
142 $this->curl->setOpt(CURLOPT_MAXREDIRS, 3);
143
144 if ($this->user) {
145 $this->curl->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
146 $this->curl->setOpt(CURLOPT_USERPWD, $this->user . ':' . $this->pass);
147 }
148 } catch (Exception $e) {
149 throw $e;
150 }
151 }
152
153 protected function replaceWebCalProtocol()
154 {
155 if (substr($this->getUrl(), 0, 6) == 'webcal') {
156 $purged = preg_replace('/webcal/', 'http', $this->getUrl(), 1);
157 $this->url = $purged;
158 $GLOBALS['ilLog']->write(__METHOD__ . ': Using new url: ' . $this->getUrl());
159 }
160 }
161
168 private function call()
169 {
170 try {
171 $res = $this->curl->exec();
172 return $res;
173 } catch (ilCurlConnectionException $exc) {
174 throw($exc);
175 }
176 }
177}
$parser
Definition: BPMN2Parser.php:23
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.
static _deleteByCategoryId($a_cat_id)
Delete assignments by category id.
Stores calendar categories.
static _delete($a_entry_id)
delete entry
Reader for remote ical calendars.
__construct($a_url)
Constructor init curl.
importIcal(ilCalendarCategory $cat)
Import ical in calendar.
static _getInstance()
Getter for unique instance.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
foreach($_POST as $key=> $value) $res