本文整理汇总了PHP中Horde_Icalendar类的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Icalendar类的具体用法?PHP Horde_Icalendar怎么用?PHP Horde_Icalendar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Horde_Icalendar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _create
/**
*/
protected function _create($mbox, $subject, $body)
{
global $notification, $registry;
$list = str_replace(self::TASKLIST_EDIT, '', $mbox);
/* Create a new iCalendar. */
$vCal = new Horde_Icalendar();
$vCal->setAttribute('PRODID', '-//The Horde Project//IMP ' . $registry->getVersion() . '//EN');
$vCal->setAttribute('METHOD', 'PUBLISH');
/* Create a new vTodo object using this message's contents. */
$vTodo = Horde_Icalendar::newComponent('vtodo', $vCal);
$vTodo->setAttribute('SUMMARY', $subject);
$vTodo->setAttribute('DESCRIPTION', $body);
$vTodo->setAttribute('PRIORITY', '3');
/* Get the list of editable tasklists. */
$lists = $this->getTasklists(true);
/* Attempt to add the new vTodo item to the requested tasklist. */
try {
$res = $registry->call('tasks/import', array($vTodo, 'text/calendar', $list));
} catch (Horde_Exception $e) {
$notification->push($e);
return;
}
if (!$res) {
$notification->push(_("An unknown error occured while creating the new task."), 'horde.error');
} elseif (!empty($lists)) {
$name = '"' . htmlspecialchars($subject) . '"';
/* Attempt to convert the object name into a hyperlink. */
if ($registry->hasLink('tasks/show')) {
$name = sprintf('<a href="%s">%s</a>', Horde::url($registry->link('tasks/show', array('uid' => $res))), $name);
}
$notification->push(sprintf(_("%s was successfully added to \"%s\"."), $name, htmlspecialchars($lists[$list]->get('name'))), 'horde.success', array('content.raw'));
}
}
示例2: _addOrganizer
/**
* Yet another problem: Outlook seems to remove the organizer from
* the iCal when forwarding -- we put the original sender back in
* as organizer.
*
* @param string $icaltext The ical message.
* @param MIME_Headers $from The message sender.
*/
function _addOrganizer(&$icaltxt, $from)
{
global $conf;
if (isset($conf['kolab']['filter']['email_domain'])) {
$email_domain = $conf['kolab']['filter']['email_domain'];
} else {
$email_domain = 'localhost';
}
$iCal = new Horde_Icalendar();
$iCal->parsevCalendar($icaltxt);
$vevent =& $iCal->findComponent('VEVENT');
if ($vevent) {
$organizer = $vevent->getAttribute('ORGANIZER', true);
if (is_a($organizer, 'PEAR_Error')) {
$adrs = imap_rfc822_parse_adrlist($from, $email_domain);
if (count($adrs) > 0) {
$org_email = 'mailto:' . $adrs[0]->mailbox . '@' . $adrs[0]->host;
$org_name = $adrs[0]->personal;
if ($org_name) {
$vevent->setAttribute('ORGANIZER', $org_email, array('CN' => $org_name), false);
} else {
$vevent->setAttribute('ORGANIZER', $org_email, array(), false);
}
Horde::log(sprintf("Adding missing organizer '%s <%s>' to iCal.", $org_name, $org_email), 'DEBUG');
$icaltxt = $iCal->exportvCalendar();
}
}
}
}
示例3: testInvite
/**
* Test creating a Horde_ActiveSync_Message_MeetingRequest from a MIME Email
*/
public function testInvite()
{
$this->markTestIncomplete('Has issues on 32bit systems');
$fixture = file_get_contents(__DIR__ . '/fixtures/invitation_one.eml');
$mime = Horde_Mime_Part::parseMessage($fixture);
$msg = new Horde_ActiveSync_Message_MeetingRequest();
foreach ($mime->contentTypeMap() as $id => $type) {
if ($type == 'text/calendar') {
$vcal = new Horde_Icalendar();
$vcal->parseVcalendar($mime->getPart($id)->getContents());
$msg->fromvEvent($vcal);
break;
}
}
$stream = fopen('php://memory', 'wb+');
$encoder = new Horde_ActiveSync_Wbxml_Encoder($stream);
$msg->encodeStream($encoder);
rewind($stream);
$results = stream_get_contents($stream);
fclose($stream);
$stream = fopen(__DIR__ . '/fixtures/meeting_request_one.wbxml', 'r+');
$expected = '';
// Using file_get_contents or even fread mangles the binary data for some
// reason.
while ($line = fgets($stream)) {
$expected .= $line;
}
fclose($stream);
$this->assertEquals($expected, $results);
}
示例4: _getFixture
private function _getFixture($element)
{
$iCal = new Horde_Icalendar();
$iCal->parsevCalendar(file_get_contents(__DIR__ . '/../fixtures/allday.ics'));
$components = $iCal->getComponents();
return $components[$element];
}
示例5: _handle
/**
* Variables required in form input:
* - imple_submit: vcard action. Contains import and source properties
* - mime_id
* - muid
*
* @return boolean True on success.
*/
protected function _handle(Horde_Variables $vars)
{
global $registry, $injector, $notification;
$iCal = new Horde_Icalendar();
try {
$contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices_Mailbox($vars));
if (!($mime_part = $contents->getMimePart($vars->mime_id))) {
throw new IMP_Exception(_("Cannot retrieve vCard data from message."));
} elseif (!$iCal->parsevCalendar($mime_part->getContents(), 'VCALENDAR', $mime_part->getCharset())) {
throw new IMP_Exception(_("Error reading the contact data."));
}
$components = $iCal->getComponents();
} catch (Exception $e) {
$notification->push($e, 'horde.error');
}
$import = !empty($vars->imple_submit->import) ? $vars->imple_submit->import : false;
$source = !empty($vars->imple_submit->source) ? $vars->imple_submit->source : false;
if ($import && $source && $registry->hasMethod('contacts/import')) {
$count = 0;
foreach ($components as $c) {
if ($c->getType() == 'vcard') {
try {
$registry->call('contacts/import', array($c, null, $source));
++$count;
} catch (Horde_Exception $e) {
$notification->push(Horde_Core_Translation::t("There was an error importing the contact data:") . ' ' . $e->getMessage(), 'horde.error');
}
}
}
$notification->push(sprintf(Horde_Core_Translation::ngettext("%d contact was successfully added to your address book.", "%d contacts were successfully added to your address book.", $count), $count), 'horde.success');
}
}
示例6: _renderInline
/**
* Return the rendered inline version of the Horde_Mime_Part object.
*
* @return array See parent::render().
*/
protected function _renderInline()
{
$GLOBALS['page_output']->growler = true;
$data = $this->_mimepart->getContents();
$mime_id = $this->_mimepart->getMimeId();
// Parse the iCal file.
$vCal = new Horde_Icalendar();
if (!$vCal->parsevCalendar($data, 'VCALENDAR', $this->_mimepart->getCharset())) {
$status = new IMP_Mime_Status(_("The calendar data is invalid"));
$status->action(IMP_Mime_Status::ERROR);
return array($mime_id => array('data' => '', 'status' => $status, 'type' => 'text/html; charset=UTF-8'));
}
// Check if we got vcard data with the wrong vcalendar mime type.
$imp_contents = $this->getConfigParam('imp_contents');
$c = $vCal->getComponentClasses();
if (count($c) == 1 && !empty($c['horde_icalendar_vcard'])) {
return $imp_contents->renderMIMEPart($mime_id, IMP_Contents::RENDER_INLINE, array('type' => 'text/x-vcard'));
}
$imple = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create('IMP_Ajax_Imple_ItipRequest', array('mime_id' => $mime_id, 'muid' => strval($imp_contents->getIndicesOb())));
// Get the method type.
try {
$method = $vCal->getAttribute('METHOD');
} catch (Horde_Icalendar_Exception $e) {
$method = '';
}
$out = array();
$components = $vCal->getComponents();
foreach ($components as $key => $component) {
switch ($component->getType()) {
case 'vEvent':
try {
if ($component->getAttribute('RECURRENCE-ID')) {
break;
}
} catch (Horde_ICalendar_Exception $e) {
}
$out[] = $this->_vEvent($component, $key, $method, $components);
break;
case 'vTodo':
$out[] = $this->_vTodo($component, $key, $method);
break;
case 'vTimeZone':
// Ignore them.
break;
case 'vFreebusy':
$out[] = $this->_vFreebusy($component, $key, $method);
break;
// @todo: handle stray vcards here as well.
// @todo: handle stray vcards here as well.
default:
$out[] = sprintf(_("Unhandled component of type: %s"), $component->getType());
break;
}
}
$view = $this->_getViewOb();
$view->formid = $imple->getDomId();
$view->out = implode('', $out);
return array($mime_id => array('data' => $view->render('base'), 'type' => 'text/html; charset=UTF-8'));
}
示例7: testGeo
public function testGeo()
{
$ical = new Horde_Icalendar();
$ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/geo1.vcf'));
$this->assertEquals(array('latitude' => -17.87, 'longitude' => 37.24), $ical->getComponent(0)->getAttribute('GEO'));
$ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/geo2.vcf'));
$this->assertEquals(array('latitude' => 37.386013, 'longitude' => -122.082932), $ical->getComponent(0)->getAttribute('GEO'));
}
示例8: testIgnoringMultipleAttributeValues
public function testIgnoringMultipleAttributeValues()
{
$ical = new Horde_Icalendar();
$ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/multiple-summary.ics'));
$result = $ical->getComponent(0)->getAttributeSingle('SUMMARY');
$this->assertInternalType('string', $result);
$this->assertEquals('Summary 1', $result);
}
示例9: testFiles
public function testFiles()
{
$test_files = glob(__DIR__ . '/fixtures/charset*.ics');
foreach ($test_files as $file) {
$ical = new Horde_Icalendar();
$ical->parsevCalendar(file_get_contents($file));
$this->assertEquals('möchen', $ical->getComponent(0)->getAttribute('SUMMARY'));
}
}
示例10: _getFixture
private function _getFixture($name, $item = 0)
{
$iCal = new Horde_Icalendar();
$iCal->parsevCalendar(file_get_contents(__DIR__ . '/../fixtures/' . $name));
$components = $iCal->getComponents();
$event = new Kronolith_Event_Sql(new Kronolith_Stub_Driver());
$event->fromiCalendar($components[$item]);
return $event;
}
示例11: testBug14132
public function testBug14132()
{
$ical = new Horde_Icalendar();
$ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/bug14132.ics'));
$params = $ical->getComponent(1)->getAttribute('DTSTART', true);
$tz = $params[0]['TZID'];
$start = $ical->getComponent(1)->getAttribute('DTSTART');
$dtstart = new Horde_Date($start, $tz);
$this->assertEquals((string) $dtstart, '2015-10-09 03:00:00');
}
示例12: getVevent
/**
* Return the response as an iCalendar vEvent object.
*
* @param Horde_Itip_Response_Type $type The response type.
* @param Horde_Icalendar|boolean $vCal The parent container or false if not
* provided.
*
* @return Horde_Icalendar_Vevent The response object.
*/
public function getVevent(Horde_Itip_Response_Type $type, $vCal = false)
{
$itip_reply = new Horde_Itip_Event_Vevent(Horde_Icalendar::newComponent('VEVENT', $vCal));
$this->_request->copyEventInto($itip_reply);
$type->setRequest($this->_request);
$itip_reply->setAttendee($this->_resource->getMailAddress(), $this->_resource->getCommonName(), $type->getStatus());
return $itip_reply->getVevent();
}
示例13: testFile
/**
* @dataProvider timezones
*/
public function testFile($file)
{
$result = '';
$ical = new Horde_Icalendar();
$ical->parsevCalendar(file_get_contents($file));
foreach ($ical->getComponents() as $component) {
if ($component->getType() != 'vEvent') {
continue;
}
$date = $component->getAttribute('DTSTART');
if (is_array($date)) {
continue;
}
$result .= str_replace("\r", '', $component->getAttribute('SUMMARY')) . "\n";
$d = new Horde_Date($date);
$result .= $d->format('H:i') . "\n";
}
$this->assertStringEqualsFile(__DIR__ . '/fixtures/vTimezone/' . basename($file, 'ics') . 'txt', $result, 'Failed parsing file ' . basename($file));
}
示例14: _process
/**
* Process the iCalendar data.
*
* @return array A hash of UID => id.
* @throws Kronolith_Exception
*/
protected function _process()
{
$ids = array();
$components = $this->_iCal->getComponents();
if (count($components) == 0) {
throw new Kronolith_Exception(_("No iCalendar data was found."));
}
foreach ($components as $component) {
if (!$this->_preSave($component)) {
continue;
}
try {
// RECURRENCE-ID - must import after base event is
// imported/saved so defer these until all other data is
// processed.
$component->getAttribute('RECURRENCE-ID');
$this->_exceptions[] = $component;
} catch (Horde_Icalendar_Exception $e) {
$event = $this->_driver->getEvent();
$event->fromiCalendar($component, true);
// Delete existing exception events. There is no efficient way
// to determine if any existing events have been changed/deleted
// so we just remove them all since they will be re-added during
// the import process.
foreach ($event->boundExceptions() as $exception) {
$this->_driver->deleteEvent($exception->id);
}
// Save and post-process.
$event->save();
$this->_postSave($event);
$ids[$event->uid] = $event->id;
}
}
// Save exception events.
foreach ($this->_exceptions as $exception) {
$event = $this->_driver->getEvent();
$event->fromiCalendar($exception);
$event->save();
}
return $ids;
}
示例15: testRead
public function testRead()
{
$ical = new Horde_Icalendar();
$ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/vfreebusy1.ics'));
// Get the vFreeBusy component
$vfb = $ical->getComponent(0);
// Dump the type
$this->assertEquals('vFreebusy', $vfb->getType());
// Dump the vfreebusy component again (the duration should be
// converted to start/end
$this->assertStringEqualsFile(__DIR__ . '/fixtures/vfreebusy2.ics', $vfb->exportvCalendar());
// Dump organizer name
$this->assertEquals('GunnarWrobel', $vfb->getName());
// Dump organizer mail
$this->assertEquals('wrobel@demo2.pardus.de', $vfb->getEmail());
// Dump busy periods
$this->assertEquals(array(1164258000 => 1164261600, 1164268800 => 1164276000), $vfb->getBusyPeriods());
// Decode the summary information
$extra = $vfb->getExtraParams();
$this->assertEquals('testtermin', base64_decode($extra[1164258000]['X-SUMMARY']));
// Dump the free periods in between the two given time stamps
$this->assertEquals(array(1164261600 => 1164268800), $vfb->getFreePeriods(1164261500, 1164268900));
// Dump start of the free/busy information
$this->assertEquals(1164236400, $vfb->getStart());
// Dump end of the free/busy information
$this->assertEquals(1169420400, $vfb->getEnd());
// Free periods don't get added
$vfb->addBusyPeriod('FREE', 1164261600, 1164268800);
$this->assertEquals(array(1164258000 => 1164261600, 1164268800 => 1164276000), $vfb->getBusyPeriods());
// Add a busy period with start/end (11:00 / 12:00)
$vfb->addBusyPeriod('BUSY', 1164279600, 1164283200);
// Add a busy period with start/duration (14:00 / 2h)
$vfb->addBusyPeriod('BUSY', 1164290400, null, 7200, array('X-SUMMARY' => 'dGVzdA=='));
// Dump busy periods
$this->assertEquals(array(1164258000 => 1164261600, 1164268800 => 1164276000, 1164279600 => 1164283200, 1164290400 => 1164297600), $vfb->getBusyPeriods());
// Dump the extra parameters
$this->assertEquals(array(1164258000 => array('X-UID' => 'MmZlNWU3NDRmMGFjNjZkNjRjZjFkZmFmYTE4NGFiZTQ=', 'X-SUMMARY' => 'dGVzdHRlcm1pbg=='), 1164268800 => array(), 1164279600 => array(), 1164290400 => array('X-SUMMARY' => 'dGVzdA==')), $vfb->getExtraParams());
return $vfb;
}