--- vcard.module 2008-01-26 21:48:31.000000000 +0100 +++ vcard.module 2008-06-06 20:20:31.000000000 +0200 @@ -94,7 +94,7 @@ if (!_vcard_init()) { drupal_set_message(t('The PEAR package Contact_Vcard_Build (required by vcard.module) has not been installed properly, please read INSTALL.txt.'), 'error'); } - + $form['field_mappings'] = array( '#type' => 'fieldset', '#title' => t('Field Mappings'), @@ -110,7 +110,31 @@ '#options' => $options, ); } - + + $form['vcard_photo_inclusion'] = array( + '#type' => 'fieldset', + '#title' => t('Include Profile photos'), + '#description' => t('You can specify, whether you want profile photos to be included in vCards') + ); + + $form['vcard_photo_inclusion']['vcard_photos_enabled'] = array( + '#type' => 'checkbox', + '#title' => 'enabled', + '#default_value' => variable_get('vcard_photos_enabled', 'checked') + ); + + $form['vcard_photo_inclusion']['vcard_photos_type'] = array( + '#type' => 'select', + '#title' => t('Photos can be included inline or externally linked'), + '#default_value' => variable_get('vcard_photos_type', 'base64'), + '#options' => array( + + 'base64' => t('inline (using base64)'), + 'uri' => t('externally linked (using uri)') + + ) + ); + return system_settings_form($form); } @@ -192,10 +216,46 @@ if ($account->location['latitude'] && $account->location['longitude']) { $vcard->setGeo($account->location['latitude'], $account->location['longitude']); } - - header('Content-type: text/x-vcard'); - header('Content-Disposition: attachment; filename="'. $account->name .'.vcf"'); - print $vcard->fetch(); + + // Check if user pictures are enabled + if(variable_get('user_pictures', 0) && variable_get('vcard_photos_enabled', 'checked')) + { + // Check if the user has a picture + $sql = "SELECT picture FROM users WHERE uid = %d"; + $db_res = db_query($sql, arg(1)); + if(db_num_rows($db_res)) + { + if($row = db_fetch_array($db_res)) + $picture = $row['picture']; + + if(variable_get('vcard_photos_type', 'base64') == 'base64') + { + // Attach the photo to the vcard using base64 encoding + $base64_encoded_image = base64_encode(file_get_contents($picture)); + $vcard->SetPhoto($base64_encoded_image); + $vcard->addParam('ENCODING', 'b'); + // Parse file extension + $image_type = strtoupper(substr($picture, strrpos($picture, '.')+1, strlen($picture)-strrpos($picture, '.'))); + if(strlen($image_type)) + { + if($image_type == "JPG") $image_type = "JPEG"; + $vcard->addParam('TYPE', $image_type); + } + } + else if(variable_get('vcard_photos_type', 'base64') == 'uri') + { + $vcard->SetPhoto('http://'.$_SERVER['HTTP_HOST'].'/'.$picture); + $vcard->addParam("VALUE", "uri"); + } + } + } + + header('Content-type: text/x-vcard; charset="'.variable_get("vcard_encoding", "UTF-8").'";'); + header('Content-Disposition: attachment; filename="'. $account->name.'.vcf"'); + + $vcard_content = $vcard->fetch(); + + print $vcard_content; exit; }