本文整理汇总了PHP中Rest::postXML方法的典型用法代码示例。如果您正苦于以下问题:PHP Rest::postXML方法的具体用法?PHP Rest::postXML怎么用?PHP Rest::postXML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rest
的用法示例。
在下文中一共展示了Rest::postXML方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _transfer
public static function _transfer($source, $destination, $syncTaskId = 0, $ignoreUpdate = false, $whitelist = array())
{
// Stats
$stats = array('contacts' => 0);
// Get source data
$contacts = BackupsModel::all(array('user_id' => $source['username']['id'], 'sync_task_id' => $syncTaskId, 'entity_type' => static::$kind['contact']))->toArray();
$destinationContacts = BackupsModel::all(array('user_id' => $destination['username']['id'], 'sync_task_id' => $syncTaskId, 'entity_type' => static::$kind['contact']))->column('entity_title');
$syncedContacts = MigratedDataModel::all(array('source_id' => $source['username']['id'], 'destination_id' => $destination['username']['id'], 'status' => MigratedDataModel::STATUS_ACTIVE, 'kind' => static::$kind['contact']))->column('identifier');
if ($contacts) {
foreach ($contacts as $contact) {
$contactData = json_decode($contact['entity'], true);
// Whitelisting used for share feature
$whiteListed = true;
if ($whitelist) {
if (isset($whitelist['contacts']) && $whitelist['contacts']) {
if (!in_array($contactData['id'], $whitelist['contacts'])) {
$whiteListed = false;
}
}
}
if (!in_array(md5($contactData['name']), $syncedContacts) && $whiteListed) {
$body = <<<EOD
<?xml version='1.0' encoding='UTF-8'?>
<entry
\txmlns='http://www.w3.org/2005/Atom'
\txmlns:gd='http://schemas.google.com/g/2005'>
EOD;
if (in_array($contactData['name'], $destinationContacts) && !$ignoreUpdate) {
$contactData['name'] = $contactData['name'] . ' (2)';
} else {
$contactData['name'] = $contactData['name'];
}
$body .= '<title type="text">' . $contactData['name'] . '</title>';
// Emails
if (isset($contactData['emails']) && $contactData['emails']) {
foreach ($contactData['emails'] as $email) {
$body .= '<gd:email rel="' . (isset($email['rel']) ? $email['rel'] : 'http://schemas.google.com/g/2005#other') . '"';
if (isset($email['primary'])) {
$body .= ' primary="true" ';
}
$body .= ' address="' . $email['address'] . '" />';
}
}
// IM
if (isset($contactData['im']) && $contactData['im']) {
foreach ($contactData['im'] as $im) {
$body .= '<gd:im address="' . $im['address'] . '" protocol="' . $im['protocol'] . '" rel="' . $im['rel'] . '"/>';
}
}
// Numbers
if (isset($contactData['phoneNumbers']) && $contactData['phoneNumbers']) {
foreach ($contactData['phoneNumbers'] as $number) {
$body .= '<gd:phoneNumber rel="' . $number['rel'] . '">' . $number['number'] . '</gd:phoneNumber>';
}
}
// Postal
if (isset($contactData['postalAddress']) && $contactData['postalAddress']) {
foreach ($contactData['postalAddress'] as $address) {
$body .= '<gd:postalAddress rel="' . $address['rel'] . '">' . $address['address'] . '</gd:postalAddress>';
}
}
$body .= '</entry>';
$newContact = \Rest::postXML(static::$endpoints['contacts'], $body, $destination);
// Update playlist with new id
if (!$ignoreUpdate && $newContact) {
$newContactId = @basename($newContact->id);
if ($newContactId) {
$oldPlaylist = BackupsModel::first($contact['id']);
$oldPlaylist->entity_new_id = $newContactId;
$oldPlaylist->save();
}
}
$stats['contacts']++;
$syncedContact = MigratedDataModel::create();
$syncedContact->source_id = $source['username']['id'];
$syncedContact->destination_id = $destination['username']['id'];
$syncedContact->task_id = 0;
$syncedContact->sync_task_id = $syncTaskId;
$syncedContact->table = BackupsModel::$schema['table'];
$syncedContact->table_id = $contact['id'];
$syncedContact->kind = static::$kind['contact'];
$syncedContact->identifier = md5($contactData['name']);
$syncedContact->status = MigratedDataModel::STATUS_ACTIVE;
$syncedContact->created = date(DATE_TIME);
$syncedContact->save();
}
}
}
return $stats;
}