Example #1
0
 */
require_once 'Horde/Cli.php';
require_once 'Horde/Icalendar.php';
// This only works on the command line.
if (!Horde_Cli::runningFromCLI()) {
    exit("Must be run from the command line\n");
}
// Load the CLI environment - make sure there's no time limit, init
// some variables, etc.
$cli = Horde_Cli::init();
if (empty($argv[1])) {
    $cli->fatal('No file specified on the command line.');
}
$input_file = $argv[1];
if (!file_exists($input_file)) {
    $cli->fatal($input_file . ' does not exist.');
}
if (!is_readable($input_file)) {
    $cli->fatal($input_file . ' is not readable.');
}
$cli->writeln($cli->blue('Parsing ' . $input_file . ' ...'));
$data = file_get_contents($input_file);
$ical = new Horde_Icalendar();
if (!$ical->parseVCalendar($data)) {
    $cli->fatal('iCalendar parsing failed.');
}
$cli->writeln($cli->green('Parsing successful, found ' . $ical->getComponentCount() . ' component(s).'));
$components = $ical->getComponents();
foreach ($components as $component) {
    var_dump($component->toHash(true));
}
Example #2
0
 public function testEscapes()
 {
     $ical = new Horde_Icalendar();
     $event1 = Horde_Icalendar::newComponent('vevent', $ical);
     $event2 = Horde_Icalendar::newComponent('vevent', $ical);
     $event1->setAttribute('UID', '20041120-8550-innerjoin-org');
     $event1->setAttribute('DTSTART', array('year' => 2005, 'month' => 5, 'mday' => 3), array('VALUE' => 'DATE'));
     $event1->setAttribute('DTSTAMP', array('year' => 2004, 'month' => 11, 'mday' => 20), array('VALUE' => 'DATE'));
     $event1->setAttribute('SUMMARY', 'Escaped Comma in Description Field');
     $event1->setAttribute('DESCRIPTION', 'There is a comma (escaped with a baskslash) in this sentence and some important words after it, see anything here?');
     $event1->setAttribute('CATEGORIES', null, array(), true, array('Foo'));
     $event2->setAttribute('UID', '20041120-8549-innerjoin-org');
     $event2->setAttribute('DTSTART', array('year' => 2005, 'month' => 5, 'mday' => 4), array('VALUE' => 'DATE'));
     $event2->setAttribute('DTSTAMP', array('year' => 2004, 'month' => 11, 'mday' => 20), array('VALUE' => 'DATE'));
     $event2->setAttribute('SUMMARY', 'Dash (rather than Comma) in the Description Field');
     $event2->setAttribute('DESCRIPTION', 'There are important words after this dash - see anything here or have the words gone?');
     $event2->setAttribute('CATEGORIES', null, array(), true, array('Foo', 'Foo,Bar', 'Bar'));
     $ical->addComponent($event1);
     $ical->addComponent($event2);
     $this->assertStringEqualsFile(__DIR__ . '/fixtures/escapes2.ics', $ical->exportVCalendar());
     $readIcal = new Horde_Icalendar();
     $readIcal->parseVCalendar($ical->exportVCalendar());
     $this->assertEquals(array('There is a comma (escaped with a baskslash) in this sentence and some important words after it, see anything here?'), $readIcal->getComponent(0)->getAttributeValues('DESCRIPTION'));
     $this->assertEquals(array('There are important words after this dash - see anything here or have the words gone?'), $readIcal->getComponent(1)->getAttributeValues('DESCRIPTION'));
 }