Exemplo n.º 1
0
 function parse_vcards(&$lines)
 {
     $cards = array();
     $card = new VCard();
     while ($card->parse($lines)) {
         $property = $card->getProperty('N');
         if (!$property) {
             return "";
         }
         $n = $property->getComponents();
         $tmp = array();
         if ($n[3]) {
             $tmp[] = $n[3];
         }
         // Mr.
         if ($n[1]) {
             $tmp[] = $n[1];
         }
         // John
         if ($n[2]) {
             $tmp[] = $n[2];
         }
         // Quinlan
         if ($n[4]) {
             $tmp[] = $n[4];
         }
         // Esq.
         $ret = array();
         if ($n[0]) {
             $ret[] = $n[0];
         }
         $tmp = join(" ", $tmp);
         if ($tmp) {
             $ret[] = $tmp;
         }
         $key = join(", ", $ret);
         $cards[$key] = $card;
         // MDH: Create new VCard to prevent overwriting previous one (PHP5)
         $card = new VCard();
     }
     ksort($cards);
     return $cards;
 }
 /**
  * get raw data of a single record
  * 
  * @param  mixed $_resource
  * @return array
  */
 protected function _getRawData(&$_resource)
 {
     $card = new VCard();
     $result = FALSE;
     while ($card->parse($_resource)) {
         if ($card->getProperty('N')) {
             return $card;
         } else {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' No N property: ' . print_r($card, TRUE));
             }
         }
     }
     return FALSE;
 }
Exemplo n.º 3
0
    if (!isset($_FILES['my_file'])) {
        ?>
<script type="text/javascript">top.stop_upload();</script><?php 
        exit;
    }
    $vcard_file = $_FILES['my_file']['tmp_name'];
    $lines = file($vcard_file);
    if (!$lines) {
        ?>
<script type="text/javascript">top.stop_upload();</script><?php 
        exit;
    }
    // parse the file into $cards
    $cards = array();
    $card = new VCard();
    while ($card->parse($lines)) {
        $property = $card->getProperty('N');
        if (!$property) {
            ?>
<script type="text/javascript">top.stop_upload();</script><?php 
            exit;
        }
        $n = $property->getComponents();
        $tmp = array();
        if ($n[3]) {
            $tmp[] = $n[3];
        }
        // Mr.
        if ($n[1]) {
            $tmp[] = $n[1];
        }
Exemplo n.º 4
0
 /**
  * import the data
  *
  * @param  resource $_resource (if $_filename is a stream)
  * @param  array $_clientRecordData
  * @return array with Tinebase_Record_RecordSet the imported records (if dryrun) and totalcount 
  */
 public function import($_resource = NULL, $_clientRecordData = array())
 {
     $this->_initImportResult();
     $lines = array();
     while ($line = fgets($_resource)) {
         $lines[] = str_replace("\n", "", $line);
     }
     $card = new VCard();
     while ($card->parse($lines) && (!$this->_options['dryrun'] || !($this->_options['dryrunLimit'] && $this->_importResult['totalcount'] >= $this->_options['dryrunCount']))) {
         $property = $card->getProperty('N');
         if ($property) {
             try {
                 $mappedData = $this->_doMapping($card);
                 if (!empty($mappedData)) {
                     $convertedData = $this->_doConversions($mappedData);
                     // merge additional values (like group id, container id ...)
                     $mergedData = array_merge($convertedData, $this->_addData($convertedData));
                     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Merged data: ' . print_r($mergedData, true));
                     }
                     // import record into tine!
                     $recordToImport = $this->_createRecordToImport($mergedData);
                     $importedRecord = $this->_importRecord($recordToImport);
                 } else {
                     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Got empty record from mapping! Was: ' . print_r($recordData, TRUE));
                     }
                     $this->_importResult['failcount']++;
                 }
             } catch (Exception $e) {
                 // don't add incorrect record (name missing for example)
                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage());
                 if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                     Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString());
                 }
                 $this->_importResult['failcount']++;
             }
         } else {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' No N property: ' . print_r($card, TRUE));
             }
         }
         $card = new VCard();
     }
     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Import finished. (total: ' . $this->_importResult['totalcount'] . ' fail: ' . $this->_importResult['failcount'] . ' duplicates: ' . $this->_importResult['duplicatecount'] . ')');
     return $this->_importResult;
 }