protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); // add your code here // instantiate a parser object $parse = new Contact_Vcard_Parse(); // parse it $data = $parse->fromFile(sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . 'contacts.vcf'); // output results $contact_collection = new Doctrine_Collection('contact'); $company_collection = new Doctrine_Collection('company'); foreach ($data as $contact) { print_r($contact); $vcard = new vcard($contact); if ($vcard->isCompany()) { // it's a company // $db_contact = new Company(); // $db_contact->merge($vcard->getCompanyData()); // $company_collection->add($db_contact); print_r($vcard->getCompanyData()); } else { // it's a contact // $db_contact = new Contact(); // $db_contact->merge($vcard->getContactData()); // $contact_collection->add($db_contact); print_r($vcard->getContactData()); } } // $company_collection->save(); // $contact_collection->save(); }
private static function _parse($file) { if ($data = sys_cache_get("vcard_" . sha1($file))) { return $data; } if ($message = sys_allowedpath(dirname($file))) { sys_warning(sprintf("{t}Cannot read the file %s. %s{/t}", $file, $message)); return array(); } if (!($data = @file_get_contents($file))) { sys_warning("{t}The url doesn't exist.{/t} (" . $file . ")"); return array(); } if (!class_exists("Contact_Vcard_Parse", false)) { require "lib/vcard/Contact_Vcard_Parse.php"; } $parse = new Contact_Vcard_Parse(); $rows = array(); if ($data = $parse->fromText($data)) { foreach ($data as $item) { $row = array(); foreach ($item as $key => $values) { $key = strtolower($key); $row[$key] = array(); foreach ($values as $value) { foreach ($value["value"] as $value2) { if ($value2[0]) { $row[$key][] = trim($value2[0]); } } } } $rows[] = $row; } } else { sys_warning(sprintf("{t}Cannot read the file %s. %s{/t}", $file, "")); return array(); } sys_cache_set("vcard_" . sha1($file), $rows, VCARD_CACHE); return $rows; }
/* CONTACTS $Id: vcardimport.php,v 1.4.12.1 2005/10/05 12:47:59 gregorerhardt Exp $ */ $canEdit = !getDenyEdit('contacts'); if (!$canEdit) { $AppUI->setMsg('Access denied', UI_MSG_ERROR); $AppUI->redirect(); } // check whether vCard file should be fetched from source or parsed for vCardKeys; criteria: get parameters if (isset($_FILES['vcf']) && isset($_GET['suppressHeaders']) && $_GET['suppressHeaders'] == 'true') { //parse and store vCard file $vcf = $_FILES['vcf']; // include PEAR vCard class require_once $AppUI->getLibraryClass('PEAR/Contact_Vcard_Parse'); if (is_uploaded_file($vcf['tmp_name'])) { // instantiate a parser object $parse = new Contact_Vcard_Parse(); // parse a vCard file and store the data // in $cardinfo $cardinfo = $parse->fromFile($vcf['tmp_name']); // store the card info array foreach ($cardinfo as $ci) { //one file can contain multiple vCards $obj = new CContact(); //transform the card info array to dP store format $contactValues["contact_last_name"] = $ci['N'][0]['value'][0][0]; $contactValues["contact_first_name"] = $ci['N'][0]['value'][1][0]; $contactValues["contact_title"] = $ci['N'][0]['value'][3][0]; $contactValues["contact_birthday"] = $ci['BDAY'][0]['value'][0][0]; $contactValues["contact_company"] = $ci['UID'][0]['value'][0][0]; $contactValues["contact_type"] = $ci['N'][0]['value'][2][0]; $contactValues["contact_email"] = $ci['EMAIL'][0]['value'][0][0];
/** * Phase for importing vcards * * @param String $handler_id Name of the request handler * @param array $args Variable arguments * @param array &$data Public request data, passed by reference */ public function _handler_vcards($handler_id, array $args, array &$data) { $this->_prepare_handler($args); // Update the breadcrumb line $this->_update_breadcrumb($handler_id, $args); if (array_key_exists('org_openpsa_directmarketing_import', $_POST)) { $this->_request_data['contacts'] = array(); $this->_request_data['time_start'] = time(); if (is_uploaded_file($_FILES['org_openpsa_directmarketing_import_upload']['tmp_name'])) { $parser = new Contact_Vcard_Parse(); $cards = @$parser->fromFile($_FILES['org_openpsa_directmarketing_import_upload']['tmp_name']); if (count($cards) > 0) { foreach ($cards as $card) { // Empty the person array before going through vCard data $contact = array('person' => array(), 'organization' => array(), 'organization_member' => array()); // Start parsing if (array_key_exists('N', $card) && array_key_exists('value', $card['N'][0]) && is_array($card['N'][0]['value'])) { // FIXME: We should do something about character encodings $contact['person']['lastname'] = $card['N'][0]['value'][0][0]; $contact['person']['firstname'] = $card['N'][0]['value'][1][0]; } if (array_key_exists('TEL', $card)) { foreach ($card['TEL'] as $number) { if (array_key_exists('param', $number)) { if (array_key_exists('TYPE', $number['param'])) { switch ($number['param']['TYPE'][0]) { case 'CELL': $contact['person']['handphone'] = $number['value'][0][0]; break; case 'HOME': $contact['person']['homephone'] = $number['value'][0][0]; break; case 'WORK': $contact['person']['workphone'] = $number['value'][0][0]; break; } } } } } if (array_key_exists('ORG', $card)) { $contact['organization']['official'] = $card['ORG'][0]['value'][0][0]; } if (array_key_exists('TITLE', $card)) { $contact['organization_member']['title'] = $card['TITLE'][0]['value'][0][0]; } if (array_key_exists('EMAIL', $card)) { $contact['person']['email'] = $card['EMAIL'][0]['value'][0][0]; } if (array_key_exists('X-SKYPE-USERNAME', $card)) { $contact['person']['skype'] = $card['X-SKYPE-USERNAME'][0]['value'][0][0]; } if (array_key_exists('UID', $card)) { $contact['person']['external-uid'] = $card['UID'][0]['value'][0][0]; } elseif (array_key_exists('X-ABUID', $card)) { $contact['person']['external-uid'] = $card['X-ABUID'][0]['value'][0][0]; } if (count($contact['person']) > 0) { // We have parsed some contact info. // Convert fields from latin-1 to MidCOM charset (usually utf-8) foreach ($contact as $type => $fields) { foreach ($fields as $key => $value) { $contact[$type][$key] = iconv('ISO-8859-1', midcom::get('i18n')->get_current_charset(), $value); } } // TODO: Make sanity checks before adding $this->_request_data['contacts'][] = $contact; } } } } if (count($this->_request_data['contacts']) > 0) { $this->_import_subscribers($this->_request_data['contacts']); } $this->_request_data['time_end'] = time(); } }
<?php require_once 'inc/init.php'; require_once 'inc/Contact_Vcard_Parse.php'; ldap_login(); if (!$_SESSION['ldapab']['username']) { header("Location: login.php"); exit; } $error = ''; if (isset($_FILES['userfile'])) { if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { if (preg_match('/\\.vcf$/i', $_FILES['userfile']['name'])) { //parse VCF $vcfparser = new Contact_Vcard_Parse(); $vcards = $vcfparser->fromFile($_FILES['userfile']['tmp_name']); } else { $error = "Only *.vcf accepted"; } } else { switch ($_FILES['userfile']['error']) { case 0: //no error; possible file attack! $error = "There was a problem with your upload."; break; case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini $error = "The file you are trying to upload is too big."; break; case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
$container["ADR"][$dest]["ORT"] = $value[3][0]; $container["ADR"][$dest]["REGIO"] = $value[4][0]; $container["ADR"][$dest]["PLZ"] = $value[5][0]; $container["ADR"][$dest]["LAND"] = $value[6][0]; } function saveTEL($dest, $value, &$container) { $container["TEL"][$dest] = $value[0][0]; } function saveMAIL($dest, $value, &$container) { $container["EMAIL"][$dest] = $value[0][0]; } if ($_POST["upload"]) { // instantiate a parser object $parse = new Contact_Vcard_Parse(); // parse a vCard file and store the data in $cardinfo $cardinfo = $parse->fromFile($_FILES["datei"]["tmp_name"]); $adress = array(); reset($cardinfo[0]); while (list($key, $line) = each($cardinfo[0])) { switch ($key) { case "UID": $adress["UID"] = $line[0]["value"][0][0]; break; case "REV": $adress["REV"] = $line[0]["value"][0][0]; break; case "KEY": $adress["KEY"] = $line[0]["value"][0][0]; break;
| | | This file is part of the iMobMail, the webbased eMail application | | for iPod touch(R) and iPhone(R) | | Copyright (C) 2007 by Andreas Schwelling | | Licensed under the GNU GPL | | See http://www.imobmail.org/ for more details or visit our bugtracker | | at http://trac.imobmail.org/ | | | | Use of iMobMail at your own risk! | | | +-----------------------------------------------------------------------+ */ include 'sessioncheck.php'; include 'config.php'; require_once 'Contact_Vcard_Parse.php'; $parse = new Contact_Vcard_Parse(); $cardinfo = $parse->fromFile($ADDRESSBOOK); if (isset($_GET['showimg'])) { header("Content-type: image/jpeg"); header("Content-Disposition: inline filename=\"" . md5($cardinfo[$_GET['cardnr']]["FN"][0]["value"][0][0]) . ".jpg\""); $pic = $cardinfo[$_GET['cardnr']]["PHOTO"][0]['value'][0][0]; echo base64_decode($pic); exit; } if (isset($_GET['showdet'])) { $cardno = $_GET['cardno']; $nickname = htmlentities($cardinfo[$cardno][FN][0][value][0][0]); $orgname = htmlentities($cardinfo[$cardno][ORG][0][value][0][0]); if ($orgname == $nickname) { $orgname = ""; }