/** * do the mapping and replacements * * @param VCard $card * @param array $_headline [optional] * @return array * * @todo split this into smaller parts */ protected function _doMapping($card) { $data = array(); $data = $this->_getName($card, $data); $data = $this->_getPhoto($card, $data); $data = $this->_getUrl($card, $data); // TODO check sample format support // BDAY:1996-04-15 // BDAY:1953-10-15T23:10:00Z // BDAY:1987-09-27T08:30:00-06:00 if ($card->getProperty('BDAY')) { $data['bday'] = $card->getProperty('BDAY')->value; } $addressProperty = $card->getProperty('ADR') ? 'ADR' : ($card->getProperty('ITEM1.ADR') ? 'ITEM1.ADR' : ''); if ($addressProperty) { $properties = $card->getProperties($addressProperty); foreach ($properties as $property) { if (!array_key_exists('TYPE', $property->params)) { $property->params['TYPE'] = 'work'; } // types available from RFC : 'dom', 'intl', 'postal', 'parcel', 'home', 'work', 'pref' $types = $property->params['TYPE']; //post office box; the extended address; the street //address; the locality (e.g., city); the region (e.g., state or //province); the postal code; the country name $components = $property->getComponents(); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Address components ' . print_r($components, TRUE)); } $mapping = array(NULL, 'street2', 'street', 'locality', 'region', 'postalcode', 'countryname'); $adrType = $types && Tinebase_Helper::in_array_case($types, 'home') ? 'two' : 'one'; foreach ($components as $index => $value) { if (!isset($mapping[$index]) || $mapping[$index] === NULL) { continue; } $data['adr_' . $adrType . '_' . $mapping[$index]] = $value; } } } // $properties = $card->getProperties('LABEL'); //NOT_IMPLEMENTED if ($card->getProperty('TEL')) { $properties = $card->getProperties('TEL'); foreach ($properties as $property) { // types available from RFC : "home", "msg", "work", "pref", "voice", "fax", "cell", "video", "pager", "bbs", "modem", "car", "isdn", "pcs" $types = $property->params['TYPE']; $key = 'tel_work'; if ($types) { if (Tinebase_Helper::in_array_case($types, 'home') && !Tinebase_Helper::in_array_case($types, 'cell') && !Tinebase_Helper::in_array_case($types, 'fax')) { $key = 'tel_home'; } else { if (Tinebase_Helper::in_array_case($types, 'home') && Tinebase_Helper::in_array_case($types, 'cell')) { $key = 'tel_cell_private'; } else { if (Tinebase_Helper::in_array_case($types, 'home') && Tinebase_Helper::in_array_case($types, 'fax')) { $key = 'tel_fax_home'; } else { if (Tinebase_Helper::in_array_case($types, 'work') && !Tinebase_Helper::in_array_case($types, 'cell') && !Tinebase_Helper::in_array_case($types, 'fax')) { $key = 'tel_work'; } else { if (Tinebase_Helper::in_array_case($types, 'work') && Tinebase_Helper::in_array_case($types, 'cell')) { $key = 'tel_cell'; } else { if (Tinebase_Helper::in_array_case($types, 'work') && !Tinebase_Helper::in_array_case($types, 'fax')) { $key = 'tel_fax'; } else { if (Tinebase_Helper::in_array_case($types, 'car')) { $key = 'tel_car'; } else { if (Tinebase_Helper::in_array_case($types, 'pager')) { $key = 'tel_pager'; } else { if (Tinebase_Helper::in_array_case($types, 'fax')) { $key = 'tel_fax'; } else { if (Tinebase_Helper::in_array_case($types, 'cell')) { $key = 'tel_cell'; } } } } } } } } } } } $data[$key] = $property->value; //$data['tel_assistent'] = ''; //RFC has *a lot* of type, but not this one ^^ } } if ($card->getProperty('EMAIL')) { $properties = $card->getProperties('EMAIL'); foreach ($properties as $property) { // types available from RFC (custom allowed): "internet", "x400", "pref" // home and work are commons, so we manage them $types = $property->params['TYPE']; $key = 'email'; if ($types) { if (Tinebase_Helper::in_array_case($types, 'home')) { $key = 'email_home'; } } $data[$key] = $property->value; } } // $properties = $card->getProperties('MAILER'); //NOT_IMPLEMENTED // TODO Check samples are supported // TZ:-05:00 // TZ;VALUE=text:-05:00; EST; Raleigh/North America if ($card->getProperty('TZ')) { $data['tz'] = $card->getProperty('TZ')->value; } // $properties = $card->getProperties('GEO'); //NOT_IMPLEMENTED if ($card->getProperty('TITLE')) { $data['title'] = $card->getProperty('TITLE')->value; } if ($card->getProperty('ROLE')) { $data['role'] = $properties = $card->getProperty('ROLE')->value; } // $properties = $card->getProperties('LOGO'); // NOT_IMPLEMENTED // Type can be a specification "secretary", "assistant", etc. // Value can be a URI or a nested VCARD... // $data['assistent'] = $properties = $card->getProperties('AGENT'); // NESTED VCARD NOT SUPPORTED BY vcardphp if ($card->getProperty('ORG')) { $components = $card->getProperty('ORG')->getComponents(); $data['org_name'] = $components[0]; $data['org_unit'] = ''; for ($i = 1; $i < count($components); $i++) { $data['org_unit'] .= $components[$i] . ";"; } } // $properties = $card->getProperties('CATEGORIES'); // NOT_IMPLEMENTED if ($card->getProperty('NOTE')) { $data['note'] = $card->getProperty('NOTE')->value; } // $properties = $card->getProperties('PRODID'); // NOT_IMPLEMENTED // $properties = $card->getProperties('REV'); // NOT_IMPLEMENTED (could be with tine20 modification history) // $properties = $card->getProperties('SORT-STRING'); // NOT_IMPLEMENTED // $properties = $card->getProperties('SOUND'); // NOT_IMPLEMENTED // $properties = $card->getProperties('UID'); // NOT_IMPLEMENTED // $properties = $card->getProperties('VERSION'); // NOT_IMPLEMENTED // $properties = $card->getProperties('CLASS'); // NOT_IMPLEMENTED // TODO $data['pubkey'] = $properties = $card->getProperties('KEY'); // NOT_IMPLEMENTED // missing binary uncode return $data; }
/** * creates demo data for all applications * accepts same arguments as Tinebase_Frontend_Cli_Abstract::createDemoData * and the additional argument "skipAdmin" to force no user/group/role creation * * @param Zend_Console_Getopt $_opts */ public function createAllDemoData($_opts) { if (!$this->_checkAdminRight()) { return FALSE; } // fetch all applications and check if required are installed, otherwise remove app from array $applications = Tinebase_Application::getInstance()->getApplicationsByState(Tinebase_Application::ENABLED)->name; foreach ($applications as $appName) { echo 'Searching for DemoData in application "' . $appName . '"...' . PHP_EOL; $className = $appName . '_Setup_DemoData'; if (class_exists($className)) { echo 'DemoData in application "' . $appName . '" found!' . PHP_EOL; $required = $className::getRequiredApplications(); foreach ($required as $requiredApplication) { if (!Tinebase_Helper::in_array_case($applications, $requiredApplication)) { echo 'Creating DemoData for Application ' . $appName . ' is impossible, because application "' . $requiredApplication . '" is not installed.' . PHP_EOL; continue 2; } } $this->_applicationsToWorkOn[$appName] = array('appName' => $appName, 'required' => $required); } else { echo 'DemoData in application "' . $appName . '" not found.' . PHP_EOL . PHP_EOL; } } unset($applications); foreach ($this->_applicationsToWorkOn as $app => $cfg) { $this->_createDemoDataRecursive($app, $cfg, $_opts); } return 0; }
/** * Returns true if the card belongs to at least one of the categories. */ function inCategories(&$categories) { $our_categories = $this->getCategories(); foreach ($categories as $category) { if (Tinebase_Helper::in_array_case($category, $our_categories)) { return true; } } return false; }