Exemplo n.º 1
0
 function testParsing()
 {
     $parser = new DateTimeParser();
     $dom = new DOMDocument();
     $dom->load("test/testData/testDates.xml");
     foreach ($dom->getElementsByTagName('testDate') as $dateNode) {
         $lang = $dateNode->getAttribute('lang');
         $input = $dateNode->nodeValue;
         $unit = $dateNode->getAttribute('unit');
         $expected = $dateNode->getAttribute('expected');
         $output = $parser->parseValue($input, $lang, array(PAGEID => 'testPage', PROPERTYNAME => 'testProperty', UNITTYPE => null, UNITEXACTTYPE => null, TARGETUNIT => null));
         $this->assertEqual($expected, $output[0], 'VALUE test - Input: ' . htmlspecialchars($input) . ' # Output: ' . $output[0] . ' # Expected: ' . $expected);
         $this->assertEqual($expected, $output[0], 'UNIT test - Input: ' . htmlspecialchars($input) . ' # Output: ' . $output[1] . ' # Expected: ' . $unit);
     }
 }
 /**
  * Запуск валидации
  *
  * @param $sValue	Данные для валидации
  *
  * @return bool|string
  */
 public function validate($sValue)
 {
     if ($this->allowEmpty && $this->isEmpty($sValue)) {
         return true;
     }
     require_once Config::Get('path.root.engine') . '/lib/external/DateTime/DateTimeParser.php';
     $aFormats = is_string($this->format) ? array($this->format) : $this->format;
     $bValid = false;
     foreach ($aFormats as $sFormat) {
         $iTimestamp = DateTimeParser::parse($sValue, $sFormat, array('month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0));
         if ($iTimestamp !== false) {
             $bValid = true;
             break;
         }
     }
     if (!$bValid) {
         return $this->getMessage($this->Lang_Get('validate_date_format_invalid', null, false), 'msg');
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * Запуск валидации
  *
  * @param mixed $sValue    Данные для валидации
  *
  * @return bool|string
  */
 public function validate($sValue)
 {
     if (is_array($sValue)) {
         return $this->getMessage(E::ModuleLang()->Get('validate_date_format_invalid', null, false), 'msg');
     }
     if ($this->allowEmpty && $this->isEmpty($sValue)) {
         return true;
     }
     F::IncludeLib('DateTime/DateTimeParser.php');
     $aFormats = is_string($this->format) ? array($this->format) : $this->format;
     $bValid = false;
     foreach ($aFormats as $sFormat) {
         $iTimestamp = DateTimeParser::parse($sValue, $sFormat, array('month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0));
         if ($iTimestamp !== false) {
             $bValid = true;
             break;
         }
     }
     if (!$bValid) {
         return $this->getMessage(E::ModuleLang()->Get('validate_date_format_invalid', null, false), 'msg');
     }
     return true;
 }
 /**
  * Запуск валидации
  *
  * @param mixed $sValue Данные для валидации
  *
  * @return bool|string
  */
 public function validate($sValue)
 {
     if (is_array($sValue)) {
         return $this->getMessage($this->Lang_Get('validate.date.format_invalid', null, false), 'msg');
     }
     if ($this->allowEmpty && $this->isEmpty($sValue)) {
         return true;
     }
     require_once Config::Get('path.framework.libs_vendor.server') . '/DateTime/DateTimeParser.php';
     $aFormats = is_string($this->format) ? array($this->format) : $this->format;
     $bValid = false;
     foreach ($aFormats as $sFormat) {
         $iTimestamp = DateTimeParser::parse($sValue, $sFormat);
         if ($iTimestamp !== false) {
             $bValid = true;
             break;
         }
     }
     if (!$bValid) {
         return $this->getMessage($this->Lang_Get('validate.date.format_invalid', null, false), 'msg');
     }
     return true;
 }
Exemplo n.º 5
0
 /**
  * Handles conversion of a single property.
  *
  * @param Component\VCard $input
  * @param Component\VCard $output
  * @param Property $property
  * @param int $targetVersion
  * @return void
  */
 protected function convertProperty(Component\VCard $input, Component\VCard $output, Property $property, $targetVersion)
 {
     // Skipping these, those are automatically added.
     if (in_array($property->name, array('VERSION', 'PRODID'))) {
         return;
     }
     $parameters = $property->parameters();
     $valueType = null;
     if (isset($parameters['VALUE'])) {
         $valueType = $parameters['VALUE']->getValue();
         unset($parameters['VALUE']);
     }
     if (!$valueType) {
         $valueType = $property->getValueType();
     }
     $newProperty = $output->createProperty($property->name, $property->getParts(), array(), $valueType);
     if ($targetVersion === Document::VCARD30) {
         if ($property instanceof Property\Uri && in_array($property->name, array('PHOTO', 'LOGO', 'SOUND'))) {
             $newProperty = $this->convertUriToBinary($output, $newProperty, $parameters);
         } elseif ($property instanceof Property\VCard\DateAndOrTime) {
             // In vCard 4, the birth year may be optional. This is not the
             // case for vCard 3. Apple has a workaround for this that
             // allows applications that support Apple's extension still
             // omit birthyears in vCard 3, but applications that do not
             // support this, will just use a random birthyear. We're
             // choosing 1604 for the birthyear, because that's what apple
             // uses.
             $parts = DateTimeParser::parseVCardDateTime($property->getValue());
             if (is_null($parts['year'])) {
                 $newValue = '1604-' . $parts['month'] . '-' . $parts['date'];
                 $newProperty->setValue($newValue);
                 $newProperty['X-APPLE-OMIT-YEAR'] = '1604';
             }
             if ($newProperty->name == 'ANNIVERSARY') {
                 // Microsoft non-standard anniversary
                 $newProperty->name = 'X-ANNIVERSARY';
                 // We also need to add a new apple property for the same
                 // purpose. This apple property needs a 'label' in the same
                 // group, so we first need to find a groupname that doesn't
                 // exist yet.
                 $x = 1;
                 while ($output->select('ITEM' . $x . '.')) {
                     $x++;
                 }
                 $output->add('ITEM' . $x . '.X-ABDATE', $newProperty->getValue(), array('VALUE' => 'DATE-AND-OR-TIME'));
                 $output->add('ITEM' . $x . '.X-ABLABEL', '_$!<Anniversary>!$_');
             }
         } elseif ($property->name === 'KIND') {
             switch (strtolower($property->getValue())) {
                 case 'org':
                     // vCard 3.0 does not have an equivalent to KIND:ORG,
                     // but apple has an extension that means the same
                     // thing.
                     $newProperty = $output->createProperty('X-ABSHOWAS', 'COMPANY');
                     break;
                 case 'individual':
                     // Individual is implicit, so we skip it.
                     return;
                 case 'group':
                     // OS X addressbook property
                     $newProperty = $output->createProperty('X-ADDRESSBOOKSERVER-KIND', 'GROUP');
                     break;
             }
         }
     } elseif ($targetVersion === Document::VCARD40) {
         // These properties were removed in vCard 4.0
         if (in_array($property->name, array('NAME', 'MAILER', 'LABEL', 'CLASS'))) {
             return;
         }
         if ($property instanceof Property\Binary) {
             $newProperty = $this->convertBinaryToUri($output, $newProperty, $parameters);
         } elseif ($property instanceof Property\VCard\DateAndOrTime && isset($parameters['X-APPLE-OMIT-YEAR'])) {
             // If a property such as BDAY contained 'X-APPLE-OMIT-YEAR',
             // then we're stripping the year from the vcard 4 value.
             $parts = DateTimeParser::parseVCardDateTime($property->getValue());
             if ($parts['year'] === $property['X-APPLE-OMIT-YEAR']->getValue()) {
                 $newValue = '--' . $parts['month'] . '-' . $parts['date'];
                 $newProperty->setValue($newValue);
             }
             // Regardless if the year matched or not, we do need to strip
             // X-APPLE-OMIT-YEAR.
             unset($parameters['X-APPLE-OMIT-YEAR']);
         }
         switch ($property->name) {
             case 'X-ABSHOWAS':
                 if (strtoupper($property->getValue()) === 'COMPANY') {
                     $newProperty = $output->createProperty('KIND', 'ORG');
                 }
                 break;
             case 'X-ADDRESSBOOKSERVER-KIND':
                 if (strtoupper($property->getValue()) === 'GROUP') {
                     $newProperty = $output->createProperty('KIND', 'GROUP');
                 }
                 break;
             case 'X-ANNIVERSARY':
                 $newProperty->name = 'ANNIVERSARY';
                 // If we already have an anniversary property with the same
                 // value, ignore.
                 foreach ($output->select('ANNIVERSARY') as $anniversary) {
                     if ($anniversary->getValue() === $newProperty->getValue()) {
                         return;
                     }
                 }
                 break;
             case 'X-ABDATE':
                 // Find out what the label was, if it exists.
                 if (!$property->group) {
                     break;
                 }
                 $label = $input->{$property->group . '.X-ABLABEL'};
                 // We only support converting anniversaries.
                 if ($label->getValue() !== '_$!<Anniversary>!$_') {
                     break;
                 }
                 // If we already have an anniversary property with the same
                 // value, ignore.
                 foreach ($output->select('ANNIVERSARY') as $anniversary) {
                     if ($anniversary->getValue() === $newProperty->getValue()) {
                         return;
                     }
                 }
                 $newProperty->name = 'ANNIVERSARY';
                 break;
                 // Apple's per-property label system.
             // Apple's per-property label system.
             case 'X-ABLABEL':
                 if ($newProperty->getValue() === '_$!<Anniversary>!$_') {
                     // We can safely remove these, as they are converted to
                     // ANNIVERSARY properties.
                     return;
                 }
                 break;
         }
     }
     // set property group
     $newProperty->group = $property->group;
     if ($targetVersion === Document::VCARD40) {
         $this->convertParameters40($newProperty, $parameters);
     } else {
         $this->convertParameters30($newProperty, $parameters);
     }
     // Lastly, we need to see if there's a need for a VALUE parameter.
     //
     // We can do that by instantating a empty property with that name, and
     // seeing if the default valueType is identical to the current one.
     $tempProperty = $output->createProperty($newProperty->name);
     if ($tempProperty->getValueType() !== $newProperty->getValueType()) {
         $newProperty['VALUE'] = $newProperty->getValueType();
     }
     $output->add($newProperty);
 }
Exemplo n.º 6
0
 /**
  * Creates the iterator
  *
  * You should pass a VCALENDAR component, as well as the UID of the event
  * we're going to traverse.
  *
  * @param Component $vcal
  * @param string|null $uid
  */
 public function __construct(Component $vcal, $uid = null)
 {
     if (is_null($uid)) {
         if ($vcal instanceof Component\VCalendar) {
             throw new \InvalidArgumentException('If you pass a VCALENDAR object, you must pass a uid argument as well');
         }
         $components = array($vcal);
         $uid = (string) $vcal->uid;
     } else {
         $components = $vcal->select('VEVENT');
     }
     foreach ($components as $component) {
         if ((string) $component->uid == $uid) {
             if (isset($component->{'RECURRENCE-ID'})) {
                 $this->overriddenEvents[$component->DTSTART->getDateTime()->getTimeStamp()] = $component;
                 $this->overriddenDates[] = $component->{'RECURRENCE-ID'}->getDateTime();
             } else {
                 $this->baseEvent = $component;
             }
         }
     }
     if (!$this->baseEvent) {
         // No base event was found. CalDAV does allow cases where only
         // overridden instances are stored.
         //
         // In this barticular case, we're just going to grab the first
         // event and use that instead. This may not always give the
         // desired result.
         if (!count($this->overriddenEvents)) {
             throw new \InvalidArgumentException('Could not find an event with uid: ' . $uid);
         }
         ksort($this->overriddenEvents, SORT_NUMERIC);
         $this->baseEvent = array_shift($this->overriddenEvents);
     }
     $this->startDate = clone $this->baseEvent->DTSTART->getDateTime();
     $this->endDate = null;
     if (isset($this->baseEvent->DTEND)) {
         $this->endDate = clone $this->baseEvent->DTEND->getDateTime();
     } else {
         $this->endDate = clone $this->startDate;
         if (isset($this->baseEvent->DURATION)) {
             $this->endDate->add(DateTimeParser::parse((string) $this->baseEvent->DURATION));
         } elseif (!$this->baseEvent->DTSTART->hasTime()) {
             $this->endDate->modify('+1 day');
         }
     }
     $this->currentDate = clone $this->startDate;
     $rrule = $this->baseEvent->RRULE;
     // If no rrule was specified, we create a default setting
     if (!$rrule) {
         $this->frequency = 'daily';
         $this->count = 1;
     } else {
         foreach ($rrule->getParts() as $key => $value) {
             switch ($key) {
                 case 'FREQ':
                     if (!in_array(strtolower($value), array('secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly', 'yearly'))) {
                         throw new \InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value));
                     }
                     $this->frequency = strtolower($value);
                     break;
                 case 'UNTIL':
                     $this->until = DateTimeParser::parse($value);
                     // In some cases events are generated with an UNTIL=
                     // parameter before the actual start of the event.
                     //
                     // Not sure why this is happening. We assume that the
                     // intention was that the event only recurs once.
                     //
                     // So we are modifying the parameter so our code doesn't
                     // break.
                     if ($this->until < $this->baseEvent->DTSTART->getDateTime()) {
                         $this->until = $this->baseEvent->DTSTART->getDateTime();
                     }
                     break;
                 case 'COUNT':
                     $this->count = (int) $value;
                     break;
                 case 'INTERVAL':
                     $this->interval = (int) $value;
                     if ($this->interval < 1) {
                         throw new \InvalidArgumentException('INTERVAL in RRULE must be a positive integer!');
                     }
                     break;
                 case 'BYSECOND':
                     $this->bySecond = (array) $value;
                     break;
                 case 'BYMINUTE':
                     $this->byMinute = (array) $value;
                     break;
                 case 'BYHOUR':
                     $this->byHour = (array) $value;
                     break;
                 case 'BYDAY':
                     $this->byDay = (array) $value;
                     break;
                 case 'BYMONTHDAY':
                     $this->byMonthDay = (array) $value;
                     break;
                 case 'BYYEARDAY':
                     $this->byYearDay = (array) $value;
                     break;
                 case 'BYWEEKNO':
                     $this->byWeekNo = (array) $value;
                     break;
                 case 'BYMONTH':
                     $this->byMonth = (array) $value;
                     break;
                 case 'BYSETPOS':
                     $this->bySetPos = (array) $value;
                     break;
                 case 'WKST':
                     $this->weekStart = strtoupper($value);
                     break;
             }
         }
     }
     // Parsing exception dates
     if (isset($this->baseEvent->EXDATE)) {
         foreach ($this->baseEvent->EXDATE as $exDate) {
             foreach (explode(',', (string) $exDate) as $exceptionDate) {
                 $this->exceptionDates[] = DateTimeParser::parse($exceptionDate, $this->startDate->getTimeZone());
             }
         }
     }
 }
 /**
  * Creates the iterator
  *
  * You should pass a VCALENDAR component, as well as the UID of the event
  * we're going to traverse.
  *
  * @param Component $vcal
  * @param string|null $uid
  */
 public function __construct(Component $vcal, $uid = null)
 {
     if (is_null($uid)) {
         if ($vcal->name === 'VCALENDAR') {
             throw new \InvalidArgumentException('If you pass a VCALENDAR object, you must pass a uid argument as well');
         }
         $components = array($vcal);
         $uid = (string) $vcal->uid;
     } else {
         $components = $vcal->select('VEVENT');
     }
     foreach ($components as $component) {
         if ((string) $component->uid == $uid) {
             if (isset($component->{'RECURRENCE-ID'})) {
                 $this->overriddenEvents[$component->DTSTART->getDateTime()->getTimeStamp()] = $component;
                 $this->overriddenDates[] = $component->{'RECURRENCE-ID'}->getDateTime();
             } else {
                 $this->baseEvent = $component;
             }
         }
     }
     if (!$this->baseEvent) {
         throw new \InvalidArgumentException('Could not find a base event with uid: ' . $uid);
     }
     $this->startDate = clone $this->baseEvent->DTSTART->getDateTime();
     $this->endDate = null;
     if (isset($this->baseEvent->DTEND)) {
         $this->endDate = clone $this->baseEvent->DTEND->getDateTime();
     } else {
         $this->endDate = clone $this->startDate;
         if (isset($this->baseEvent->DURATION)) {
             $this->endDate->add(DateTimeParser::parse($this->baseEvent->DURATION->value));
         } elseif ($this->baseEvent->DTSTART->getDateType() === Property\DateTime::DATE) {
             $this->endDate->modify('+1 day');
         }
     }
     $this->currentDate = clone $this->startDate;
     $rrule = (string) $this->baseEvent->RRULE;
     $parts = explode(';', $rrule);
     // If no rrule was specified, we create a default setting
     if (!$rrule) {
         $this->frequency = 'daily';
         $this->count = 1;
     } else {
         foreach ($parts as $part) {
             list($key, $value) = explode('=', $part, 2);
             switch (strtoupper($key)) {
                 case 'FREQ':
                     if (!in_array(strtolower($value), array('secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly', 'yearly'))) {
                         throw new \InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value));
                     }
                     $this->frequency = strtolower($value);
                     break;
                 case 'UNTIL':
                     $this->until = DateTimeParser::parse($value);
                     // In some cases events are generated with an UNTIL=
                     // parameter before the actual start of the event.
                     //
                     // Not sure why this is happening. We assume that the
                     // intention was that the event only recurs once.
                     //
                     // So we are modifying the parameter so our code doesn't
                     // break.
                     if ($this->until < $this->baseEvent->DTSTART->getDateTime()) {
                         $this->until = $this->baseEvent->DTSTART->getDateTime();
                     }
                     break;
                 case 'COUNT':
                     $this->count = (int) $value;
                     break;
                 case 'INTERVAL':
                     $this->interval = (int) $value;
                     if ($this->interval < 1) {
                         throw new \InvalidArgumentException('INTERVAL in RRULE must be a positive integer!');
                     }
                     break;
                 case 'BYSECOND':
                     $this->bySecond = explode(',', $value);
                     break;
                 case 'BYMINUTE':
                     $this->byMinute = explode(',', $value);
                     break;
                 case 'BYHOUR':
                     $this->byHour = explode(',', $value);
                     break;
                 case 'BYDAY':
                     $this->byDay = explode(',', strtoupper($value));
                     break;
                 case 'BYMONTHDAY':
                     $this->byMonthDay = explode(',', $value);
                     break;
                 case 'BYYEARDAY':
                     $this->byYearDay = explode(',', $value);
                     break;
                 case 'BYWEEKNO':
                     $this->byWeekNo = explode(',', $value);
                     break;
                 case 'BYMONTH':
                     $this->byMonth = explode(',', $value);
                     break;
                 case 'BYSETPOS':
                     $this->bySetPos = explode(',', $value);
                     break;
                 case 'WKST':
                     $this->weekStart = strtoupper($value);
                     break;
             }
         }
     }
     // Parsing exception dates
     if (isset($this->baseEvent->EXDATE)) {
         foreach ($this->baseEvent->EXDATE as $exDate) {
             foreach (explode(',', (string) $exDate) as $exceptionDate) {
                 $this->exceptionDates[] = DateTimeParser::parse($exceptionDate, $this->startDate->getTimeZone());
             }
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Parses the input data and returns a correct VFREEBUSY object, wrapped in
  * a VCALENDAR.
  *
  * @return Component
  */
 public function getResult()
 {
     $busyTimes = array();
     foreach ($this->objects as $object) {
         foreach ($object->getBaseComponents() as $component) {
             switch ($component->name) {
                 case 'VEVENT':
                     $FBTYPE = 'BUSY';
                     if (isset($component->TRANSP) && strtoupper($component->TRANSP) === 'TRANSPARENT') {
                         break;
                     }
                     if (isset($component->STATUS)) {
                         $status = strtoupper($component->STATUS);
                         if ($status === 'CANCELLED') {
                             break;
                         }
                         if ($status === 'TENTATIVE') {
                             $FBTYPE = 'BUSY-TENTATIVE';
                         }
                     }
                     $times = array();
                     if ($component->RRULE) {
                         $iterator = new RecurrenceIterator($object, (string) $component->uid);
                         if ($this->start) {
                             $iterator->fastForward($this->start);
                         }
                         $maxRecurrences = 200;
                         while ($iterator->valid() && --$maxRecurrences) {
                             $startTime = $iterator->getDTStart();
                             if ($this->end && $startTime > $this->end) {
                                 break;
                             }
                             $times[] = array($iterator->getDTStart(), $iterator->getDTEnd());
                             $iterator->next();
                         }
                     } else {
                         $startTime = $component->DTSTART->getDateTime();
                         if ($this->end && $startTime > $this->end) {
                             break;
                         }
                         $endTime = null;
                         if (isset($component->DTEND)) {
                             $endTime = $component->DTEND->getDateTime();
                         } elseif (isset($component->DURATION)) {
                             $duration = DateTimeParser::parseDuration((string) $component->DURATION);
                             $endTime = clone $startTime;
                             $endTime->add($duration);
                         } elseif ($component->DTSTART->getDateType() === Property\DateTime::DATE) {
                             $endTime = clone $startTime;
                             $endTime->modify('+1 day');
                         } else {
                             // The event had no duration (0 seconds)
                             break;
                         }
                         $times[] = array($startTime, $endTime);
                     }
                     foreach ($times as $time) {
                         if ($this->end && $time[0] > $this->end) {
                             break;
                         }
                         if ($this->start && $time[1] < $this->start) {
                             break;
                         }
                         $busyTimes[] = array($time[0], $time[1], $FBTYPE);
                     }
                     break;
                 case 'VFREEBUSY':
                     foreach ($component->FREEBUSY as $freebusy) {
                         $fbType = isset($freebusy['FBTYPE']) ? strtoupper($freebusy['FBTYPE']) : 'BUSY';
                         // Skipping intervals marked as 'free'
                         if ($fbType === 'FREE') {
                             continue;
                         }
                         $values = explode(',', $freebusy);
                         foreach ($values as $value) {
                             list($startTime, $endTime) = explode('/', $value);
                             $startTime = DateTimeParser::parseDateTime($startTime);
                             if (substr($endTime, 0, 1) === 'P' || substr($endTime, 0, 2) === '-P') {
                                 $duration = DateTimeParser::parseDuration($endTime);
                                 $endTime = clone $startTime;
                                 $endTime->add($duration);
                             } else {
                                 $endTime = DateTimeParser::parseDateTime($endTime);
                             }
                             if ($this->start && $this->start > $endTime) {
                                 continue;
                             }
                             if ($this->end && $this->end < $startTime) {
                                 continue;
                             }
                             $busyTimes[] = array($startTime, $endTime, $fbType);
                         }
                     }
                     break;
             }
         }
     }
     if ($this->baseObject) {
         $calendar = $this->baseObject;
     } else {
         $calendar = Component::create('VCALENDAR');
         $calendar->version = '2.0';
         $calendar->prodid = '-//Sabre//Sabre VObject ' . Version::VERSION . '//EN';
         $calendar->calscale = 'GREGORIAN';
     }
     $vfreebusy = Component::create('VFREEBUSY');
     $calendar->add($vfreebusy);
     if ($this->start) {
         $dtstart = Property::create('DTSTART');
         $dtstart->setDateTime($this->start, Property\DateTime::UTC);
         $vfreebusy->add($dtstart);
     }
     if ($this->end) {
         $dtend = Property::create('DTEND');
         $dtend->setDateTime($this->end, Property\DateTime::UTC);
         $vfreebusy->add($dtend);
     }
     $dtstamp = Property::create('DTSTAMP');
     $dtstamp->setDateTime(new \DateTime('now'), Property\DateTime::UTC);
     $vfreebusy->add($dtstamp);
     foreach ($busyTimes as $busyTime) {
         $busyTime[0]->setTimeZone(new \DateTimeZone('UTC'));
         $busyTime[1]->setTimeZone(new \DateTimeZone('UTC'));
         $prop = Property::create('FREEBUSY', $busyTime[0]->format('Ymd\\THis\\Z') . '/' . $busyTime[1]->format('Ymd\\THis\\Z'));
         $prop['FBTYPE'] = $busyTime[2];
         $vfreebusy->add($prop);
     }
     return $calendar;
 }
Exemplo n.º 9
0
 /**
  * Handles conversion of a single property.
  *
  * @param Component\VCard $input
  * @param Component\VCard $output
  * @param Property $property
  * @param int $targetVersion
  * @return void
  */
 protected function convertProperty(Component\VCard $input, Component\VCard $output, Property $property, $targetVersion)
 {
     // Skipping these, those are automatically added.
     if (in_array($property->name, ['VERSION', 'PRODID'])) {
         return;
     }
     $parameters = $property->parameters();
     $valueType = null;
     if (isset($parameters['VALUE'])) {
         $valueType = $parameters['VALUE']->getValue();
         unset($parameters['VALUE']);
     }
     if (!$valueType) {
         $valueType = $property->getValueType();
     }
     $newProperty = null;
     if ($targetVersion === Document::VCARD30) {
         if ($property instanceof Property\Uri && in_array($property->name, ['PHOTO', 'LOGO', 'SOUND'])) {
             $newProperty = $this->convertUriToBinary($output, $property, $parameters);
         } elseif ($property instanceof Property\VCard\DateAndOrTime) {
             // In vCard 4, the birth year may be optional. This is not the
             // case for vCard 3. Apple has a workaround for this that
             // allows applications that support Apple's extension still
             // omit birthyears in vCard 3, but applications that do not
             // support this, will just use a random birthyear. We're
             // choosing 1604 for the birthyear, because that's what apple
             // uses.
             $parts = DateTimeParser::parseVCardDateTime($property->getValue());
             if (is_null($parts['year'])) {
                 $newValue = '1604-' . $parts['month'] . '-' . $parts['date'];
                 $newProperty = $output->createProperty($property->name, $newValue, ['X-APPLE-OMIT-YEAR' => '1604'], $valueType);
             }
         } elseif ($property->name === 'KIND') {
             switch (strtolower($property->getValue())) {
                 case 'org':
                     // OS X addressbook property.
                     $newProperty = $output->createProperty('X-ABSHOWAS', 'COMPANY');
                     break;
                 case 'individual':
                     // Individual is implied, so we can just skip it.
                     return;
                 case 'group':
                     // OS X addressbook property
                     $newProperty = $output->createProperty('X-ADDRESSBOOKSERVER-KIND', 'GROUP');
                     break;
             }
         }
     } elseif ($targetVersion === Document::VCARD40) {
         // These properties were removed in vCard 4.0
         if (in_array($property->name, ['NAME', 'MAILER', 'LABEL', 'CLASS'])) {
             return;
         }
         if ($property instanceof Property\Binary) {
             $newProperty = $this->convertBinaryToUri($output, $property, $parameters);
         } elseif ($property instanceof Property\VCard\DateAndOrTime && isset($parameters['X-APPLE-OMIT-YEAR'])) {
             // If a property such as BDAY contained 'X-APPLE-OMIT-YEAR',
             // then we're stripping the year from the vcard 4 value.
             $parts = DateTimeParser::parseVCardDateTime($property->getValue());
             if ($parts['year'] === $property['X-APPLE-OMIT-YEAR']->getValue()) {
                 $newValue = '--' . $parts['month'] . '-' . $parts['date'];
                 $newProperty = $output->createProperty($property->name, $newValue, [], $valueType);
             }
             // Regardless if the year matched or not, we do need to strip
             // X-APPLE-OMIT-YEAR.
             unset($parameters['X-APPLE-OMIT-YEAR']);
         } else {
             switch ($property->name) {
                 case 'X-ABSHOWAS':
                     if (strtoupper($property->getValue()) === 'COMPANY') {
                         $newProperty = $output->createProperty('KIND', 'org');
                     }
                     break;
                 case 'X-ADDRESSBOOKSERVER-KIND':
                     if (strtoupper($property->getValue()) === 'GROUP') {
                         $newProperty = $output->createProperty('KIND', 'group');
                     }
                     break;
             }
         }
     }
     if (is_null($newProperty)) {
         $newProperty = $output->createProperty($property->name, $property->getParts(), [], $valueType);
     }
     // set property group
     $newProperty->group = $property->group;
     if ($targetVersion === Document::VCARD40) {
         $this->convertParameters40($newProperty, $parameters);
     } else {
         $this->convertParameters30($newProperty, $parameters);
     }
     // Lastly, we need to see if there's a need for a VALUE parameter.
     //
     // We can do that by instantating a empty property with that name, and
     // seeing if the default valueType is identical to the current one.
     $tempProperty = $output->createProperty($newProperty->name);
     if ($tempProperty->getValueType() !== $newProperty->getValueType()) {
         $newProperty['VALUE'] = $newProperty->getValueType();
     }
     $output->add($newProperty);
 }
Exemplo n.º 10
0
 /**
  * Create a new Date object from a parsable date.
  *
  * @param string|int The date to parse
  * @param string|int The time to parse (ignored, use the DateTimeParser for time parsing)
  *
  * @return Date
  */
 public function parse($date, $time = null)
 {
     $result = parent::parse($date, 0);
     return new Date($result->timestamp());
 }
Exemplo n.º 11
0
 /**
  * Запуск валидации
  *
  * @param mixed $sValue    Данные для валидации
  *
  * @return bool|string
  */
 public function validate($sValue)
 {
     if ($this->allowEmpty && $this->isEmpty($sValue)) {
         return true;
     }
     F::IncludeLib('DateTime/DateTimeParser.php');
     if ($this->type === 'integer') {
         $bValid = preg_match('/^[-+]?[0-9]+$/', trim($sValue));
     } else {
         if ($this->type === 'float') {
             $bValid = preg_match('/^[-+]?([0-9]*\\.)?[0-9]+([eE][-+]?[0-9]+)?$/', trim($sValue));
         } else {
             if ($this->type === 'date') {
                 $bValid = DateTimeParser::parse($sValue, $this->dateFormat, array('month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0)) !== false;
             } else {
                 if ($this->type === 'time') {
                     $bValid = DateTimeParser::parse($sValue, $this->timeFormat) !== false;
                 } else {
                     if ($this->type === 'datetime') {
                         $bValid = DateTimeParser::parse($sValue, $this->datetimeFormat, array('month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0)) !== false;
                     } else {
                         if ($this->type === 'array') {
                             $bValid = is_array($sValue);
                         } else {
                             return true;
                         }
                     }
                 }
             }
         }
     }
     if (!$bValid) {
         return $this->getMessage(E::ModuleLang()->Get('validate_type_error', null, false), 'msg', array('type' => $this->type));
     }
     return true;
 }
Exemplo n.º 12
0
 public function extractPage($pageID, $pageTitle, $pageSource)
 {
     $mysql = $this->mysql;
     $result = new ExtractionResult($pageID, $this->language, $this->getExtractorID());
     if ($this->decode_title($pageTitle) == NULL) {
         return $result;
     }
     // don't remove tables
     // 1. some templates are used within templates, e.g. http://en.wikipedia.org/wiki/Plato
     // 2. the regex sometimes reaches PREG_BACKTRACK_LIMIT_ERROR
     // $text=preg_replace('~{\|.*\|}~s','',$pageSource); // remove Prettytables
     $text = $pageSource;
     $templates = Util::getTemplates($text);
     foreach ($templates as $template) {
         $tpl = $template["content"];
         //TODO: HIER NICHT "TEMPLATE" HARDCODE, SONDERN SPRACHABHAENGIG
         $dbpedia_uri = "http://dbpedia.org/resource/Template:" . Util::encodeLocalName($template["name"]);
         //var_dump($dbpedia_uri);
         // get template ID from DB
         $templatequery = "select template_id from template_uri where uri = '{$dbpedia_uri}'";
         $templatequeryresult = $mysql->query($templatequery);
         $tqrow = mysql_fetch_array($templatequeryresult, MYSQL_ASSOC);
         $template_id = $tqrow['template_id'];
         if (!isset($template_id)) {
             continue;
         }
         $props = Util::getTemplateProperties($tpl);
         //TODO: INNER JOIN VERWENDEN STATT NORMALEM JOIN
         // find ontology class with template id
         $classquery = "select name, class_id from class, template_class where template_class.template_id = '{$template_id}' and template_class.class_id = class.id";
         $classqueryresult = $mysql->query($classquery);
         $cqrow = mysql_fetch_array($classqueryresult, MYSQL_ASSOC);
         $class_id = $cqrow['class_id'];
         $class_name = $cqrow['name'];
         // get template properties
         $template_properties = array();
         $template_properties_to_merge = array();
         // get merging rules for template ID
         $mergequery = "select ordered_template_property_ids from template_property_merge_rule where template_id = '{$template_id}'";
         $mergequeryresult = $mysql->query($mergequery);
         $i = 0;
         while ($mergerow = mysql_fetch_array($mergequeryresult, MYSQL_ASSOC)) {
             $temp = explode(",", $mergerow['ordered_template_property_ids']);
             $merging_group_count[$i] = 0;
             foreach ($temp as $tempp) {
                 $template_properties_to_merge[] = $tempp;
                 $merging_group[$tempp] = $i;
                 $merging_group_count[$i]++;
             }
             $i++;
         }
         $merge_template_sets_done = array();
         $main_propid_from_merging_group[] = array();
         $main_propvalue_from_merging_group[] = array();
         foreach ($props as $keyvalue) {
             $propkey = mysql_escape_string($keyvalue[1]);
             $propvalue = $keyvalue[2];
             if (trim($propvalue) == "" || $propvalue == null) {
                 continue;
             }
             $propquery = "select id from template_property where name = '{$propkey}' and template_id = '{$template_id}'";
             $propqueryresult = $mysql->query($propquery);
             $pqrow = mysql_fetch_array($propqueryresult, MYSQL_ASSOC);
             $template_property_id = $pqrow['id'];
             if (!is_null($template_property_id)) {
                 if (!in_array($template_property_id, $template_properties_to_merge)) {
                     $template_properties[$template_property_id] = trim($propvalue);
                 } else {
                     $query = "select class_property_id from template_property_class_property where template_property_id = {$template_property_id}";
                     $dbresult = $mysql->query($query);
                     $target_unit = null;
                     while ($row = mysql_fetch_array($dbresult, MYSQL_ASSOC)) {
                         $class_property_ids = $row['class_property_id'];
                         $ptrquery = "select * from parser_type_rule where class_property_id = '{$class_property_ids}'";
                         $ptrresult = $mysql->query($ptrquery);
                         $ptrrow = mysql_fetch_array($ptrresult, MYSQL_ASSOC);
                         $parser_rule = $ptrrow['parser_type'];
                         $unit_type = $ptrrow['unit_type'];
                         $target_unit = $ptrrow['target_unit'];
                     }
                     $unit_exact_type = null;
                     $query1 = "select unit_exact_type from template_parser_type_rule where template_property_id = {$template_property_id}";
                     $dbresult1 = $mysql->query($query1);
                     while ($row1 = mysql_fetch_array($dbresult1, MYSQL_ASSOC)) {
                         if (strlen($row1['unit_exact_type']) > 0) {
                             $unit_exact_type = $row1['unit_exact_type'];
                         }
                     }
                     if (!in_array($merging_group[$template_property_id], $merge_template_sets_done)) {
                         $merge_template_sets_done[] = $merging_group[$template_property_id];
                         $propvalue = trim($propvalue);
                         if ($parser_rule == "unit") {
                             if ($unit_type == "Length") {
                                 $parseResultArray = UnitValueParser::parseValue($propvalue, $this->language, array(PAGEID => $pageID, PROPERTYNAME => $propkey, UNITTYPE => $unit_type, UNITEXACTTYPE => $unit_exact_type, TARGETUNIT => $target_unit, IGNOREUNIT => true));
                                 if (!is_null($parseResultArray)) {
                                     foreach ($parseResultArray as $parseResults) {
                                         $propvalue = (string) $parseResults[0] . " {$unit_exact_type}";
                                     }
                                 }
                             }
                         } else {
                             if ($parser_rule == "geocoordinates") {
                                 if ($merging_group_count[$merging_group[$template_property_id]] == 6 || $merging_group_count[$merging_group[$template_property_id]] == 8) {
                                     //{{coord|51|30|29|N|00|07|29|W}}
                                     $propvalue = "{{coord|" . $propvalue;
                                     $geocoordinatescount = $merging_group_count[$merging_group[$template_property_id]] - 1;
                                 }
                             } else {
                                 // TODO: new Unit type!
                             }
                         }
                         $template_properties[$template_property_id] = $propvalue;
                         $main_propid_from_merging_group[$merging_group[$template_property_id]] = $template_property_id;
                         $main_propvalue_from_merging_group[$merging_group[$template_property_id]] = $propvalue;
                     } else {
                         $main_propvalue = $main_propvalue_from_merging_group[$merging_group[$template_property_id]];
                         $main_template_property_id = $main_propid_from_merging_group[$merging_group[$template_property_id]];
                         if ($parser_rule == "unit") {
                             if ($unit_type == "Length") {
                                 $parseResultArray = UnitValueParser::parseValue($propvalue, $this->language, array(PAGEID => $pageID, PROPERTYNAME => $propkey, UNITTYPE => $unit_type, UNITEXACTTYPE => $unit_exact_type, TARGETUNIT => $target_unit));
                                 if (!is_null($parseResultArray)) {
                                     foreach ($parseResultArray as $parseResults) {
                                         $propvalue = (string) $parseResults[0] . " {$unit_exact_type}";
                                     }
                                 }
                                 $template_properties[$main_template_property_id] = $main_propvalue . " " . $propvalue;
                             }
                         } else {
                             if ($parser_rule == "geocoordinates") {
                                 $geocoordinatescount--;
                                 if ($merging_group_count[$merging_group[$template_property_id]] == 6 || $merging_group_count[$merging_group[$template_property_id]] == 8) {
                                     //{{coord|51|30|29|N|00|07|29|W}}
                                     if ($geocoordinatescount == 0) {
                                         $propvalue = $propvalue . "}}";
                                     }
                                     $main_propvalue_from_merging_group[$merging_group[$main_template_property_id]] = $main_propvalue . "|" . $propvalue;
                                     $template_properties[$main_template_property_id] = $main_propvalue . "|" . $propvalue;
                                 } else {
                                     $main_propvalue_from_merging_group[$merging_group[$main_template_property_id]] = $main_propvalue . " " . $propvalue;
                                     $template_properties[$main_template_property_id] = $main_propvalue . " " . $propvalue;
                                 }
                             } else {
                                 // TODO: new Unit type!
                             }
                         }
                         unset($template_properties[$template_property_id]);
                     }
                 }
             }
         }
         foreach ($template_properties as $template_property_id => $propvalue) {
             $query = "select class_property_id from template_property_class_property where template_property_id = {$template_property_id}";
             $dbresult = $mysql->query($query);
             while ($row = mysql_fetch_array($dbresult, MYSQL_ASSOC)) {
                 $class_property_ids = $row['class_property_id'];
                 // foreach template_property_class_property.class_property_id
                 // get parser_type_rule.parser_type
                 $target_unit = null;
                 $ptrquery = "select * from parser_type_rule where class_property_id = '{$class_property_ids}'";
                 $ptrresult = $mysql->query($ptrquery);
                 $ptrrow = mysql_fetch_array($ptrresult, MYSQL_ASSOC);
                 $parser_rule = $ptrrow['parser_type'];
                 $unit_type = $ptrrow['unit_type'];
                 $target_unit = $ptrrow['target_unit'];
                 $cpquery = "select cp.type, cp.datatype_range, cp.name, c.name as superclass from class_property cp inner join class c on(cp.class_id = c.id) where cp.id = {$class_property_ids}";
                 $cpresult = $mysql->query($cpquery);
                 $cprow = mysql_fetch_array($cpresult, MYSQL_ASSOC);
                 $property_type = $cprow['type'];
                 $datatype_range = $cprow['datatype_range'];
                 $property_name = $cprow['name'];
                 $ontclass = $cprow['superclass'];
                 //IF PROPERTY IS NOT FROM ONTOLOGY, BUT EXTERNAL, SUCH AS FOAF
                 if (!$cprow) {
                     $cpquery = "select name, uri, class_id from class_property where id = {$class_property_ids}";
                     $cpresult = $mysql->query($cpquery);
                     $cprow = mysql_fetch_array($cpresult, MYSQL_ASSOC);
                     //TODO: IST DIE CLASS_ID NICHT IMMER NULL IN DIESEM FALL???
                     $domain_class_id = $cprow['class_id'];
                     if ($domain_class_id == null && $cprow['uri'] == "http://xmlns.com/foaf/0.1/" && $cprow['name'] == "homepage") {
                         try {
                             $result->addTriple(RDFtriple::page($pageID), RDFtriple::URI("http://xmlns.com/foaf/0.1/homepage"), RDFtriple::URI($propvalue));
                         } catch (Exception $e) {
                             //TODO uncorrect URI
                         }
                     } else {
                         if ($domain_class_id == null && $cprow['uri'] == "http://xmlns.com/foaf/0.1/" && $cprow['name'] == "name") {
                             if (strpos($propvalue, "{{PAGENAME}}") === false) {
                                 if (strpos($propvalue, "{{") === false) {
                                     $parseResults = StringParser::parseValue($propvalue, $this->language, null);
                                     foreach ($parseResults as $mystring) {
                                         if ($mystring != "") {
                                             $result->addTriple(RDFtriple::page($pageID), RDFtriple::URI("http://xmlns.com/foaf/0.1/name"), RDFtriple::Literal($mystring));
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 } else {
                     /*
                     if (strpos($propvalue, "[[") !== false) {
                     $propvalue = Util::replaceWikiLinks($propvalue);
                     }
                     */
                     switch ($property_type) {
                         case 'object':
                             $rangequery = "SELECT c.name as rangeclass FROM class_property_range cpr inner join class c on (cpr.range_class_id = c.id) where property_id = {$class_property_ids}";
                             $rangeresult = $mysql->query($rangequery);
                             $rowrange = mysql_fetch_array($rangeresult, MYSQL_ASSOC);
                             $rangeclass = $rowrange['rangeclass'];
                             $propvalue = Util::removeWikiEmphasis($propvalue);
                             //TODO:ADD LANGUAGE AS PARAM
                             $parseResults = ObjectTypeParser::parseValue($propvalue, $this->language, $rangeclass);
                             foreach ($parseResults as $r) {
                                 $result->addTriple(RDFtriple::page($pageID), RDFtriple::property($ontclass, $property_name, $this->flagNewSchema), RDFtriple::page($r));
                             }
                             break;
                         case 'datatype':
                             switch ($datatype_range) {
                                 case 'string':
                                     switch ($parser_rule) {
                                         case 'geocoordinates':
                                             //TODO: Predicate URIs entweder nur in DB oder nur hardcoden?
                                             $propvalue = Util::removeHtmlTags($propvalue);
                                             $propvalue = Util::removeHtmlComments($propvalue);
                                             $parseResultArray = GeoParser::parseValue($propvalue, $this->language, null);
                                             if (!is_null($parseResultArray)) {
                                                 // http://www.georss.org/georss/point:(NULL) 52.5166666667 13.4166666667
                                                 // geo:lat 52.516666 (xsd:float)
                                                 // geo:long 13.416667 (xsd:float)
                                                 // $output = array('georss'=>$georss,'lat'=>$lat,'long'=>$long);
                                                 $georss = $parseResultArray["georss"];
                                                 $lat = $parseResultArray["lat"];
                                                 $long = $parseResultArray["long"];
                                                 if ($georss != null) {
                                                     $result->addTriple(RDFtriple::page($pageID), RDFtriple::URI("http://www.georss.org/georss/point"), RDFtriple::Literal($georss));
                                                 }
                                                 if ($lat != null) {
                                                     $result->addTriple(RDFtriple::page($pageID), RDFtriple::URI("http://www.w3.org/2003/01/geo/wgs84_pos#lat"), RDFtriple::Literal($lat, "http://www.w3.org/2001/XMLSchema#float", NULL));
                                                 }
                                                 if ($long != null) {
                                                     $result->addTriple(RDFtriple::page($pageID), RDFtriple::URI("http://www.w3.org/2003/01/geo/wgs84_pos#long"), RDFtriple::Literal($long, "http://www.w3.org/2001/XMLSchema#float", NULL));
                                                 }
                                             } else {
                                                 //TODO: DEBUG LOGFILE FOR UN-PARSED VALUES
                                                 $this->addLiteral($result, $pageID, $ontclass, $property_name, $propvalue);
                                             }
                                             break;
                                         default:
                                             $parseResults = StringParser::parseValue($propvalue, $this->language, null);
                                             foreach ($parseResults as $mystring) {
                                                 $this->addLiteral($result, $pageID, $ontclass, $property_name, $mystring);
                                             }
                                             break;
                                     }
                                     break;
                                 case 'integer':
                                     if (strpos($propvalue, "{{") !== false) {
                                         $propvalue = Util::replaceTemplates($propvalue);
                                     }
                                     $propvalue = Util::removeHtmlTags($propvalue);
                                     $propvalue = Util::removeHtmlComments($propvalue);
                                     $propvalue = Util::removeWikiEmphasis($propvalue);
                                     /*
                                     preg_match_all("/([^0-9]+)[0-9]/", $propvalue, $other_characters, PREG_SET_ORDER);
                                     $only_commata_whitespaces_dots = true;
                                     foreach ($other_characters as $other_character) {
                                     //echo $other_character[1];
                                     if (($other_character[1] != " ") && ($other_character[1] != ",") && ($other_character[1] != ".")) {
                                     $only_commata_whitespaces_dots = false;
                                     break;
                                     }
                                     }
                                     if ($only_commata_whitespaces_dots) {
                                     $propvalue = preg_replace("/[^0-9]*([0-9])/", "$1", $propvalue);
                                     }
                                     */
                                     $parseResults = NumberParser::parseValue($propvalue, $this->language, array("integer"));
                                     if (!is_null($parseResults)) {
                                         $this->addLiteral($result, $pageID, $ontclass, $property_name, $parseResults, "http://www.w3.org/2001/XMLSchema#integer");
                                     } else {
                                         //TODO: ADD DEGUB LOGFILE FOR UN-PARSED TRIPLES
                                         if (!$this->flagStrictExport) {
                                             $this->addLiteral($result, $pageID, $ontclass, $property_name, $propvalue);
                                         }
                                     }
                                     break;
                                 case 'float':
                                     if (strpos($propvalue, "{{") !== false) {
                                         $propvalue = Util::replaceTemplates($propvalue);
                                     }
                                     $propvalue = Util::removeHtmlTags($propvalue);
                                     $propvalue = Util::removeHtmlComments($propvalue);
                                     $propvalue = Util::removeWikiEmphasis($propvalue);
                                     $parseResults = NumberParser::parseValue($propvalue, $this->language, array("float"));
                                     if (!is_null($parseResults)) {
                                         $this->addLiteral($result, $pageID, $ontclass, $property_name, $parseResults, "http://www.w3.org/2001/XMLSchema#float");
                                     } else {
                                         //TODO: ADD DEGUB LOGFILE FOR UN-PARSED TRIPLES
                                         if (!$this->flagStrictExport) {
                                             $this->addLiteral($result, $pageID, $ontclass, $property_name, $propvalue);
                                         }
                                     }
                                     break;
                                 case 'double':
                                     switch ($parser_rule) {
                                         case 'currency':
                                             $propvalue = Util::removeHtmlTags($propvalue);
                                             $propvalue = Util::removeHtmlComments($propvalue);
                                             $parseResultArray = UnitValueParser::parseValue($propvalue, $this->language, array(PAGEID => $pageID, PROPERTYNAME => $property_name, UNITTYPE => 'Currency', UNITEXACTTYPE => null, TARGETUNIT => null));
                                             if (!is_null($parseResultArray)) {
                                                 foreach ($parseResultArray as $parseResults) {
                                                     $parsedDataType = $parseResults[1];
                                                     if ($parsedDataType == "") {
                                                         $parsedDataType = null;
                                                     }
                                                     if ($parseResults[0] != "") {
                                                         $this->addLiteral($result, $pageID, $ontclass, $property_name, (string) $parseResults[0], $parsedDataType);
                                                     }
                                                 }
                                             } else {
                                                 if (!$this->flagStrictExport) {
                                                     $propvalue = Util::removeTemplates($propvalue);
                                                     $this->addLiteral($result, $pageID, $ontclass, $property_name, $propvalue);
                                                 }
                                             }
                                             break;
                                         case 'unit':
                                             $propvalue = Util::replaceWikiLinks($propvalue);
                                             //TODO: WARUM NUR IN DIESEM FALL CITE RAUSNEHMEN?
                                             preg_match_all("/{{2}cite.*?\\}{2}/i", $propvalue, $matches);
                                             foreach ($matches as $match) {
                                                 $propvalue = str_replace($match[0], Util::replaceTemplates($match[0]), $propvalue);
                                             }
                                             $propvalue = Util::removeHtmlTags($propvalue);
                                             $propvalue = Util::removeHtmlComments($propvalue);
                                             // get unit exact type
                                             $unit_exact_type = null;
                                             // if property is part of merged properties then unit is (probably) already appended, otherwise append unit (here: "exact unit type")
                                             if (!in_array($template_property_id, $template_properties_to_merge)) {
                                                 $query1 = "select unit_exact_type from template_parser_type_rule where template_property_id = {$template_property_id}";
                                                 $dbresult1 = $mysql->query($query1);
                                                 while ($row1 = mysql_fetch_array($dbresult1, MYSQL_ASSOC)) {
                                                     if (strlen($row1['unit_exact_type']) > 0) {
                                                         $unit_exact_type = $row1['unit_exact_type'];
                                                     }
                                                 }
                                             }
                                             $parseResultArray = UnitValueParser::parseValue($propvalue, $this->language, array(PAGEID => $pageID, PROPERTYNAME => $property_name, UNITTYPE => $unit_type, UNITEXACTTYPE => $unit_exact_type, TARGETUNIT => $target_unit));
                                             if (!is_null($parseResultArray)) {
                                                 foreach ($parseResultArray as $parseResults) {
                                                     $parsedDataType = $parseResults[1];
                                                     if ($parsedDataType == "") {
                                                         $parsedDataType = null;
                                                     }
                                                     if ($parseResults[0] != "") {
                                                         $this->addLiteral($result, $pageID, $ontclass, $property_name, (string) $parseResults[0], $parsedDataType);
                                                     }
                                                 }
                                             } else {
                                                 //TODO: GENERATE LOGFILE WITH UNPARSED VALUES
                                                 if (!$this->flagStrictExport) {
                                                     $this->addLiteral($result, $pageID, $ontclass, $property_name, $propvalue);
                                                 }
                                             }
                                             break;
                                         default:
                                             if (strpos($propvalue, "{{") !== false) {
                                                 $propvalue = Util::replaceTemplates($propvalue);
                                             }
                                             $propvalue = Util::removeHtmlTags($propvalue);
                                             $propvalue = Util::removeHtmlComments($propvalue);
                                             $propvalue = Util::removeWikiEmphasis($propvalue);
                                             $parseResults = NumberParser::parseValue($propvalue, $this->language, array("float"));
                                             if (!is_null($parseResults)) {
                                                 $this->addLiteral($result, $pageID, $ontclass, $property_name, $parseResults, "http://www.w3.org/2001/XMLSchema#double");
                                             } else {
                                                 //TODO: ADD DEGUB LOGFILE FOR UN-PARSED TRIPLES
                                                 if (!$this->flagStrictExport) {
                                                     $this->addLiteral($result, $pageID, $ontclass, $property_name, $propvalue);
                                                 }
                                             }
                                             break;
                                     }
                                     break;
                                 case 'date':
                                     // TODO: when DateTimeParser uses restrictions (start date / end date), pass them as parameter
                                     // $parseResults = DateTimeParser::parseValue($propvalue, $this->language, array($unit_type));
                                     $parseResultArray = DateTimeParser::parseValue($propvalue, $this->language, array(PAGEID => $pageID, PROPERTYNAME => $property_name, UNITTYPE => $unit_type, UNITEXACTTYPE => $unit_exact_type, TARGETUNIT => $target_unit));
                                     if (!is_null($parseResultArray)) {
                                         $this->addLiteral($result, $pageID, $ontclass, $property_name, $parseResultArray[0], $parseResultArray[1]);
                                     } else {
                                         if (!$this->flagStrictExport) {
                                             $parseResults = StringParser::parseValue($propvalue, $this->language, null);
                                             foreach ($parseResults as $mystring) {
                                                 $this->addLiteral($result, $pageID, $ontclass, $property_name, $mystring);
                                             }
                                         }
                                     }
                                     break;
                                 default:
                                     break;
                             }
                             break;
                         default:
                             break;
                     }
                 }
             }
         }
     }
     return $result;
 }
 /**
  * Запуск валидации
  *
  * @param mixed $sValue Данные для валидации
  *
  * @return bool|string
  */
 public function validate($sValue)
 {
     if ($this->allowEmpty && $this->isEmpty($sValue)) {
         return true;
     }
     require_once Config::Get('path.framework.libs_vendor.server') . '/DateTime/DateTimeParser.php';
     if ($this->type === 'integer') {
         $bValid = preg_match('/^[-+]?[0-9]+$/', trim($sValue));
     } else {
         if ($this->type === 'float') {
             $bValid = preg_match('/^[-+]?([0-9]*\\.)?[0-9]+([eE][-+]?[0-9]+)?$/', trim($sValue));
         } else {
             if ($this->type === 'date') {
                 $bValid = DateTimeParser::parse($sValue, $this->dateFormat, array('month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0)) !== false;
             } else {
                 if ($this->type === 'time') {
                     $bValid = DateTimeParser::parse($sValue, $this->timeFormat) !== false;
                 } else {
                     if ($this->type === 'datetime') {
                         $bValid = DateTimeParser::parse($sValue, $this->datetimeFormat, array('month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0)) !== false;
                     } else {
                         if ($this->type === 'array') {
                             $bValid = is_array($sValue);
                         } else {
                             return true;
                         }
                     }
                 }
             }
         }
     }
     if (!$bValid) {
         return $this->getMessage($this->Lang_Get('validate.type.error', null, false), 'msg', array('type' => $this->type));
     }
     return true;
 }
Exemplo n.º 14
0
 /**
  * Create a new DateTime object from a parsable date/time.
  *
  * @param string|int $date The date to parse
  * @param string|int $time The time to parse
  *
  * @return static
  */
 public static function parse($date, $time = null)
 {
     $parser = new DateTimeParser();
     $parser->addDefaultParsers();
     return $parser->parse($date, $time);
 }
Exemplo n.º 15
0
 public function parse($value)
 {
     return DateTimeParser::parseValue($value, $this->language, null);
 }