Example #1
0
 /**
  * Used in actionCheckLanguage. Parse the file, putting its language fields
  * into $contentArr.
  * @param String $filePath The full path to the file.
  * @param Array &$contentArr The array to put the language fields in.
  * @return string Output string, possibly containing warnings for the user.
  */
 private function _langFieldsToArray($filePath, &$contentArr)
 {
     $outputString = '';
     $langFile = new \GO\Base\Fs\File($filePath);
     if (!file_exists($langFile->path())) {
         $outputString .= '<i><font color="red">File not found: "' . $langFile->path() . '"</font></i><br />';
     } else {
         $this->_replaceBOM($filePath);
         $encodingName = $langFile->detectEncoding($langFile->getContents());
         if ($encodingName == 'UTF-8' || $encodingName == 'ASCII' || $langFile->convertToUtf8()) {
             $lines = file($langFile->path());
             if (count($lines)) {
                 foreach ($lines as $line) {
                     $first_equal = strpos($line, '=');
                     if ($first_equal != 0) {
                         $key = str_replace('"', '\'', trim(substr($line, 0, $first_equal)));
                         $contentArr[$key] = trim(substr($line, $first_equal, strlen($line) - 1));
                     }
                 }
             } else {
                 $outputString .= '<i><font color="red">Could not compare ' . str_replace(\GO::config()->root_path, '', $langFile->path()) . ', because it has no translation contents!</font></i><br />';
             }
         } else {
             $outputString .= '<i><font color="red">Could not compare with ' . str_replace(\GO::config()->root_path, '', $langFile->path()) . ', because it cannot be made UTF-8!</font></i><br />';
         }
         //for displaying errors
         include $filePath;
     }
     return $outputString;
 }
Example #2
0
 protected function actionImportVCard($params)
 {
     $summaryLog = new \GO\Base\Component\SummaryLog();
     $readOnly = !empty($params['readOnly']);
     if (isset($_FILES['files']['tmp_name'][0])) {
         $params['file'] = $_FILES['files']['tmp_name'][0];
     }
     if (!empty($params['importBaseParams'])) {
         $importBaseParams = json_decode($params['importBaseParams'], true);
         $params['addressbook_id'] = $importBaseParams['addressbook_id'];
     }
     $file = new \GO\Base\Fs\File($params['file']);
     $file->convertToUtf8();
     $options = \Sabre\VObject\Reader::OPTION_FORGIVING + \Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES;
     $vcards = new \Sabre\VObject\Splitter\VCard(fopen($file->path(), 'r+'), $options);
     unset($params['file']);
     $nr = 0;
     if ($readOnly) {
         $contactsAttr = array();
     }
     while ($vObject = $vcards->getNext()) {
         $nr++;
         \GO\Base\VObject\Reader::convertVCard21ToVCard30($vObject);
         $contact = new \GO\Addressbook\Model\Contact();
         try {
             if ($contact->importVObject($vObject, $params, !$readOnly)) {
                 $summaryLog->addSuccessful();
             }
             if ($readOnly) {
                 $contactsAttr[] = $contact->getAttributes('formatted');
             }
         } catch (\Exception $e) {
             $summaryLog->addError($nr, $e->getMessage());
         }
     }
     $response = $summaryLog->getErrorsJson();
     if ($readOnly) {
         $response['contacts'] = $contactsAttr;
     }
     $response['successCount'] = $summaryLog->getTotalSuccessful();
     $response['totalCount'] = $summaryLog->getTotal();
     $response['success'] = true;
     return $response;
 }