Пример #1
0
 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   Node::REPAIR - May attempt to automatically repair the problem.
  *   Node::PROFILE_CARDDAV - validate the vCard for CardDAV purposes.
  *   Node::PROFILE_CALDAV - validate the iCalendar for CalDAV purposes.
  *
  * This method returns an array with detected problems.
  * Every element has the following properties:
  *
  *  * level - problem level.
  *  * message - A human-readable string describing the issue.
  *  * node - A reference to the problematic node.
  *
  * The level means:
  *   1 - The issue was repaired (only happens if REPAIR was turned on).
  *   2 - A warning.
  *   3 - An error.
  *
  * @param int $options
  * @return array
  */
 function validate($options = 0)
 {
     $result = parent::validate($options);
     if (isset($this->DTEND) && isset($this->DURATION)) {
         $result[] = array('level' => 3, 'message' => 'DTEND and DURATION cannot both be present', 'node' => $this);
     }
     return $result;
 }
Пример #2
0
 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   Node::REPAIR - May attempt to automatically repair the problem.
  *   Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes.
  *   Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes.
  *
  * This method returns an array with detected problems.
  * Every element has the following properties:
  *
  *  * level - problem level.
  *  * message - A human-readable string describing the issue.
  *  * node - A reference to the problematic node.
  *
  * The level means:
  *   1 - The issue was repaired (only happens if REPAIR was turned on).
  *   2 - A warning.
  *   3 - An error.
  *
  * @param int $options
  *
  * @return array
  */
 function validate($options = 0)
 {
     $result = parent::validate($options);
     if (isset($this->DTEND) && isset($this->DURATION)) {
         $result[] = ['level' => 3, 'message' => 'DTEND and DURATION cannot both be present', 'node' => $this];
     }
     if (isset($this->DURATION) && !isset($this->DTSTART)) {
         $result[] = ['level' => 3, 'message' => 'DURATION must be declared with a DTSTART.', 'node' => $this];
     }
     return $result;
 }
Пример #3
0
 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   - Node::REPAIR - If something is broken, and automatic repair may
  *                    be attempted.
  *
  * An array is returned with warnings.
  *
  * Every item in the array has the following properties:
  *    * level - (number between 1 and 3 with severity information)
  *    * message - (human readable message)
  *    * node - (reference to the offending node)
  *
  * @param int $options
  * @return array
  */
 public function validate($options = 0)
 {
     $warnings = array();
     $version = $this->select('VERSION');
     if (count($version) !== 1) {
         $warnings[] = array('level' => 1, 'message' => 'The VERSION property must appear in the VCARD component exactly 1 time', 'node' => $this);
         if ($options & self::REPAIR) {
             $this->VERSION = self::DEFAULT_VERSION;
         }
     } else {
         $version = (string) $this->VERSION;
         if ($version !== '2.1' && $version !== '3.0' && $version !== '4.0') {
             $warnings[] = array('level' => 1, 'message' => 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.', 'node' => $this);
             if ($options & self::REPAIR) {
                 $this->VERSION = '4.0';
             }
         }
     }
     $fn = $this->select('FN');
     if (count($fn) !== 1) {
         $warnings[] = array('level' => 1, 'message' => 'The FN property must appear in the VCARD component exactly 1 time', 'node' => $this);
         if ($options & self::REPAIR && count($fn) === 0) {
             // We're going to try to see if we can use the contents of the
             // N property.
             if (isset($this->N)) {
                 $value = explode(';', (string) $this->N);
                 if (isset($value[1]) && $value[1]) {
                     $this->FN = $value[1] . ' ' . $value[0];
                 } else {
                     $this->FN = $value[0];
                 }
                 // Otherwise, the ORG property may work
             } elseif (isset($this->ORG)) {
                 $this->FN = (string) $this->ORG;
             }
         }
     }
     return array_merge(parent::validate($options), $warnings);
 }
Пример #4
0
 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   Node::REPAIR - May attempt to automatically repair the problem.
  *
  * This method returns an array with detected problems.
  * Every element has the following properties:
  *
  *  * level - problem level.
  *  * message - A human-readable string describing the issue.
  *  * node - A reference to the problematic node.
  *
  * The level means:
  *   1 - The issue was repaired (only happens if REPAIR was turned on)
  *   2 - An inconsequential issue
  *   3 - A severe issue.
  *
  * @param int $options
  * @return array
  */
 public function validate($options = 0)
 {
     $result = parent::validate($options);
     if (isset($this->DUE) && isset($this->DTSTART)) {
         $due = $this->DUE;
         $dtStart = $this->DTSTART;
         if ($due->getValueType() !== $dtStart->getValueType()) {
             $result[] = array('level' => 3, 'message' => 'The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART', 'node' => $due);
         } elseif ($due->getDateTime() < $dtStart->getDateTime()) {
             $result[] = array('level' => 3, 'message' => 'DUE must occur after DTSTART', 'node' => $due);
         }
     }
     return $result;
 }
Пример #5
0
 /**
  * Repairs a VObject file
  *
  * @param Component $vObj
  * @return int
  */
 protected function repair($vObj)
 {
     $returnCode = 0;
     switch ($vObj->name) {
         case 'VCALENDAR':
             $this->log("iCalendar: " . (string) $vObj->VERSION);
             break;
         case 'VCARD':
             $this->log("vCard: " . (string) $vObj->VERSION);
             break;
     }
     $warnings = $vObj->validate(Node::REPAIR);
     if (!count($warnings)) {
         $this->log("  No warnings!");
     } else {
         $levels = [1 => 'REPAIRED', 2 => 'WARNING', 3 => 'ERROR'];
         $returnCode = 2;
         foreach ($warnings as $warn) {
             $extra = '';
             if ($warn['node'] instanceof Property) {
                 $extra = ' (property: "' . $warn['node']->name . '")';
             }
             $this->log("  [" . $levels[$warn['level']] . '] ' . $warn['message'] . $extra);
         }
     }
     fwrite($this->stdout, $vObj->serialize());
     return $returnCode;
 }
 /**
  * Repairs a VObject file
  *
  * @param Component $vObj
  * @return int
  */
 protected function repair($vObj)
 {
     $returnCode = 0;
     switch ($vObj->name) {
         case 'VCALENDAR':
             $this->log("iCalendar: " . (string) $vObj->VERSION);
             break;
         case 'VCARD':
             $this->log("vCard: " . (string) $vObj->VERSION);
             break;
     }
     $warnings = $vObj->validate(Node::REPAIR);
     if (!count($warnings)) {
         $this->log("  No warnings!");
     } else {
         foreach ($warnings as $warn) {
             $returnCode = 2;
             $this->log("  " . $warn['message']);
         }
     }
     fwrite($this->stdout, $vObj->serialize());
     return $returnCode;
 }