Index: foaf.info
===================================================================
RCS file: foaf.info
diff -N foaf.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ foaf.info	10 Mar 2008 00:00:35 -0000
@@ -0,0 +1,4 @@
+; $Id$
+name = FOAF
+description = FOAF for Drupal
+dependencies = profile
Index: foaf.install
===================================================================
RCS file: foaf.install
diff -N foaf.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ foaf.install	10 Mar 2008 00:00:35 -0000
@@ -0,0 +1,12 @@
+<?php
+// $Id$
+
+function _foaf_variables() {
+  return array('foaf_export_default', 'foaf_name', 'foaf_title', 'foaf_firstName', 'foaf_surname', 'foaf_Organization', 'foaf_phone', 'foaf_aimChatID', 'foaf_icqChatID', 'foaf_msnChatID', 'foaf_yahooChatID', 'foaf_jabberID', 'foaf_workplaceHomepage', 'foaf_street', 'foaf_locality', 'foaf_region', 'foaf_pcode', 'foaf_country', 'foaf_keywords');
+}
+
+function foaf_uninstall() {
+  foreach (_foaf_variables() as $var) {
+    variable_del($var);
+  }
+}
Index: foaf.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/foaf/foaf.module,v
retrieving revision 1.13
diff -u -p -r1.13 foaf.module
--- foaf.module	12 Jul 2006 17:13:51 -0000	1.13
+++ foaf.module	10 Mar 2008 00:00:37 -0000
@@ -11,12 +11,12 @@ function foaf_help($section) {
       $output .= '<p>'. t('The FOAF module allows users to export FOAF documents based on their profile information. It also allows users to import profile information from external FOAF files, and even includes an option to let profiles auto sync when using distributed authentication.  The FOAF module can export your buddy list if the buddy list module is enabled.   You can download FOAF files in the view tab of a user profile if FOAF is enabled.') .'</p>';
       $output .= t('<p>You can</p>
 <ul>
-<li>read the <a href="%external-http-en-wikipedia-org-wiki-FOAF" title = "explanation of FOAF from wikipedia the free encyclopedia">FOAF wikipedia explanation</a>.</li>
-<li>read the <a href="http://www.socialtext.net/foafnet/index.cgi?basic_specs" title = "a programmers level description of this social networking standard">FOAFNet specificiation</a>.</li>
-<li>view <a href="%profile"> user profiles</a> and select a user to see their FOAF file.</li>
-<li>enable the buddy list module at <a href="%admin-modules" > administrator &gt;&gt; modules</a>.</li>
+<li>read the <a href="%external-http-en-wikipedia-org-wiki-FOAF" title="Explanation of FOAF from Wikipedia the free encyclopedia">FOAF Wikipedia explanation</a>.</li>
+<li>read the <a href="%external-http-www-socialtext-net-foafnet-index-cgi" title="A programmer\'s level description of this social networking standard">FOAFNet specificiation</a>.</li>
+<li>view <a href="%profile">user profiles</a> and select a user to see their FOAF file.</li>
+<li>enable the buddy list module at <a href="%admin-modules">administrator &gt;&gt; modules</a>.</li>
 ', array('%external-http-en-wikipedia-org-wiki-FOAF' => 'http://en.wikipedia.org/wiki/FOAF', '%external-http-www-socialtext-net-foafnet-index-cgi' => 'http://www.socialtext.net/foafnet/index.cgi?basic_specs', '%profile' => url('profile'), '%admin-modules' => url('admin/modules'))) .'</ul>';
-      $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%foaf">FOAF page</a>.', array('%foaf' => 'http://www.drupal.org/handbook/modules/foaf/')) .'</p>';
+      $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%foaf">FOAF page</a>.', array('%foaf' => 'http://drupal.org/handbook/modules/foaf/')) .'</p>';
       return $output;
     case 'admin/modules#description':
       return t('Allows <acronym title="Friend of a Friend">FOAF</acronym> import / export');
@@ -32,10 +32,23 @@ function foaf_menu($may_cache) {
   $items = array();
 
   if ($may_cache) {
-    $items[] = array('path' => 'foaf', 'title' => t('foaf'),
-                     'access' => user_access('access content'),
-                     'callback' => 'foaf_export',
-                     'type' => MENU_CALLBACK);
+    $items[] = array(
+      'path' => 'foaf',
+      'title' => t('FOAF'),
+      'access' => user_access('access content'),
+      'callback' => 'foaf_export',
+      'type' => MENU_CALLBACK,
+    );
+  }
+  else {
+    $items[] = array(
+      'path' => 'admin/settings/foaf',
+      'title' => t('FOAF'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('foaf_settings'),
+      'access' => user_access('administer foaf'),
+      'type' => MENU_NORMAL_ITEM,
+    );
   }
   return $items;
 }
@@ -54,10 +67,10 @@ function foaf_user($op, &$edit, &$user, 
       }
       break;
     case 'view':
-      drupal_set_html_head("\n".'<link rel="meta" type="application/rdf+xml" title="FOAF" href="'.url('foaf/'.$user->uid, NULL, NULL, TRUE).'" />');
+      drupal_set_html_head('<link rel="meta" type="application/rdf+xml" title="FOAF" href="'. url('foaf/'. $user->uid, NULL, NULL, TRUE) .'" />');
       $output = '';
       if (_foaf_allow_export($user)) {
-          return array(t('Personal Information') => l(t('Download <acronym title="Friend of a Friend">FOAF</acronym>'), 'foaf/'.$user->uid, NULL, NULL, NULL, FALSE, TRUE));
+        return array(t('Personal Information') => array(0 => array(/*'title' => 'FOAF',*/ 'value' => l(t('Download <acronym title="Friend of a Friend">FOAF</acronym>'), 'foaf/'. $user->uid, NULL, NULL, NULL, FALSE, TRUE))));
       }
       break;
     case 'form':
@@ -69,31 +82,149 @@ function foaf_user($op, &$edit, &$user, 
 }
 
 function foaf_settings() {
-  $output = '';
 
-  $output.= form_radios(t('Export <acronym title="Friend of a Friend">FOAF</acronym> for users by default'), 'foaf_export_default', variable_get('foaf_export_default', 0), array(0 => t('no'), 1=> t('yes')), t('This can be overridden by individual users'));
-  
-  $mapping.= form_select(t('Field for foaf:name'), 'foaf_name', variable_get('foaf_name', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for foaf:title'), 'foaf_title', variable_get('foaf_title', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for foaf:firstName'), 'foaf_firstName', variable_get('foaf_firstName', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for foaf:surname'), 'foaf_surname', variable_get('foaf_surname', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for foaf:Organization'), 'foaf_Organization', variable_get('foaf_Organization', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for foaf:phone'), 'foaf_phone', variable_get('foaf_phone', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for foaf:aimChatID'), 'foaf_aimChatID', variable_get('foaf_aimChatID', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for foaf:icqChatID'), 'foaf_icqChatID', variable_get('foaf_icqChatID', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for foaf:msnChatID'), 'foaf_msnChatID', variable_get('foaf_msnChatID', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for foaf:yahooChatID'), 'foaf_yahooChatID', variable_get('foaf_yahooChatID', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for foaf:jabberID'), 'foaf_jabberID', variable_get('foaf_jabberID', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for foaf:workplaceHomepage'), 'foaf_workplaceHomepage', variable_get('foaf_workplaceHomepage', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for vCard:Street'), 'foaf_street', variable_get('foaf_street', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for vCard:Locality'), 'foaf_locality', variable_get('foaf_locality', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for vCard:Region'), 'foaf_region', variable_get('foaf_region', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for vCard:Pcode'), 'foaf_pcode', variable_get('foaf_pcode', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for vCard:Country'), 'foaf_country', variable_get('foaf_country', ''), _foaf_profile_fields());
-  $mapping.= form_select(t('Field for bio:keywords'), 'foaf_keywords', variable_get('foaf_keywords', ''), _foaf_profile_fields());
+  $form['foaf_export_default'] = array(
+    '#type' => 'radios',
+    '#title' => t('Export <acronym title="Friend of a Friend">FOAF</acronym> for users by default'),
+    '#default_value' => variable_get('foaf_export_default', 0),
+    '#options' => array(0 => t('no'), 1 => t('yes')),
+    '#description' => t('This can be overridden by individual users'),
+  );
+
+  $mapping = variable_get('mapping', NULL);
+
+  $form['mapping'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Field Mappings'),
+  );
+
+  $form['mapping']['foaf_name'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for foaf:name'),
+    '#default_value' => variable_get('foaf_name', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_title'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for foaf:title'),
+    '#default_value' => variable_get('foaf_title', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_firstName'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for foaf:firstName'),
+    '#default_value' => variable_get('foaf_firstName', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_surname'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for foaf:surname'),
+    '#default_value' => variable_get('foaf_surname', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_Organization'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for foaf:Organization'),
+    '#default_value' => variable_get('foaf_Organization', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_phone'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for foaf:phone'),
+    '#default_value' => variable_get('foaf_phone', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_aimChatID'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for foaf:aimChatID'),
+    '#default_value' => variable_get('foaf_aimChatID', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_icqChatID'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for foaf:icqChatID'),
+    '#default_value' => variable_get('foaf_icqChatID', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_msnChatID'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for foaf:msnChatID'),
+    '#default_value' => variable_get('foaf_msnChatID', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_yahooChatID'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for foaf:yahooChatID'),
+    '#default_value' => variable_get('foaf_yahooChatID', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_jabberID'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for foaf:jabberID'),
+    '#default_value' => variable_get('foaf_jabberID', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_workplaceHomepage'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for foaf:workplaceHomepage'),
+    '#default_value' => variable_get('foaf_workplaceHomepage', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_street'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for vCard:Street'),
+    '#default_value' => variable_get('foaf_street', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_locality'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for vCard:Locality'),
+    '#default_value' => variable_get('foaf_locality', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_region'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for vCard:Region'),
+    '#default_value' => variable_get('foaf_region', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_pcode'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for vCard:Pcode'),
+    '#default_value' => variable_get('foaf_pcode', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_country'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for vCard:Country'),
+    '#default_value' => variable_get('foaf_country', ''),
+    '#options' => _foaf_profile_fields(),
+  );
+
+  $form['mapping']['foaf_keywords'] = array(
+    '#type' => 'select',
+    '#title' => t('Field for bio:keywords'),
+    '#default_value' => variable_get('foaf_keywords', ''),
+    '#options' => _foaf_profile_fields(),
+  );
 
-  $output.= form_group(t('Field Mappings'), $mapping);
-  return $output;
+  return system_settings_form($form);
 }
 
 function foaf_xmlrpc() {
@@ -110,144 +241,150 @@ function foaf_export($uid = null) {
     return;
   }
 
-  if ( !_foaf_allow_export($account)) {
+  if (!_foaf_allow_export($account)) {
     drupal_access_denied();
     return;
   }
 
-  $output .= '<?xml version="1.0" encoding="iso-8859-1" ?>'."\n";
-  $output .= '<!-- generator="Drupal FOAF.Module" -->'."\n";
-  $output .= '<rdf:RDF xmlns="http://xmlns.com/foaf/0.1"'."\n";
-  $output .= '  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n";
-  $output .= '  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"'."\n";
-  $output .= '  xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
-  $output .= '  xmlns:admin="http://webns.net/mvcb/"'. "\n";
-  $output .= '  xmlns:bio="http://purl.org/vocab/bio/0.1/"'."\n";
-  $output .= '  xmlns:foaf="http://xmlns.com/foaf/0.1/"'."\n";
-  $output .= '  xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#">'."\n";
-
-  // foaf:PersonalProfileDocument
-  $output .= '<foaf:PersonalProfileDocument rdf:about="">' ."\n";
-  $output .= '  <foaf:maker rdf:nodeID="_'.$uid.'" />'."\n"; 
-  $output .= '  <foaf:primaryTopic rdf:nodeID="_'.$uid.'" />'."\n";
-  $output .= '  <dc:title>'. t('FOAF for %name at %site', array('%name' => $account->name, '%site' => variable_get('site_name', 'drupal'))) ."</dc:title>\n";
-  $output .= '  <dc:description>' . t('Friend of a Friend description for %name', array('%name' => $account->name)) . "</dc:description>\n";
-  $output .= '  <admin:generatorAgent rdf:resource="http://www.drupal.org/" />'."\n";
-  $output .= "</foaf:PersonalProfileDocument>\n";
-
-  //$name = ($val = _foaf_profile_get($uid, variable_get('foaf_name',''))) ? $val : $account->name;
-  $picture = ($account->picture) ? file_create_url($account->picture) : '';
-
-  // foaf:Person
-  $output.= '<foaf:Person rdf:nodeID="_'.$uid.'">'."\n";
-  if ($firstName = _foaf_profile_get($uid, variable_get('foaf_firstName',''))) {
-    $output.= '  <foaf:firstName>'.$firstName."</foaf:firstName>\n";
+  // Define variables in the output.
+  $dc['title'] = t('FOAF for @name at @site', array('@name' => $account->name, '@site' => variable_get('site_name', 'drupal')));
+  $dc['description'] = t('Friend of a Friend description for @name', array('@name' => $account->name));
+
+  $foaf['names'] = '';
+  if ($firstName = _foaf_profile_get($uid, variable_get('foaf_firstName', ''))) {
+    $foaf['names'] .= '  <foaf:firstName>'. $firstName ."</foaf:firstName>\n";
   }
-  if ($surname = _foaf_profile_get($uid, variable_get('foaf_surname',''))) {
-    $output.= '  <foaf:surname>'.$surname."</foaf:surname>\n";
+  if ($surname = _foaf_profile_get($uid, variable_get('foaf_surname', ''))) {
+    $foaf['names'] .= '  <foaf:surname>'. $surname ."</foaf:surname>\n";
   }
-
   // Guess foaf:name (if not present)
-  if (!$name = _foaf_profile_get($uid, variable_get('foaf_name',''))) {
+  if (!$name = _foaf_profile_get($uid, variable_get('foaf_name', ''))) {
     if ($firstName && $surname) {
-      $name = $firstName . ' ' . $surname;
+      $name = $firstName .' '. $surname;
     }
     else {
       $name = $account->name;
     }
   }
-  $output.= '  <foaf:name>'.$name."</foaf:name>\n";
+  $foaf['names'] .= '  <foaf:name>'. $name ."</foaf:name>\n";
+
   if ($account->mail) {
-    $output.= '  <foaf:mbox_sha1sum>'.sha1('mailto:' . $account->mail)."</foaf:mbox_sha1sum>\n";
+    $foaf['mail'] = '  <foaf:mbox_sha1sum>'. sha1('mailto:'. $account->mail) ."</foaf:mbox_sha1sum>\n";
   }
+
+  $foaf['img'] = '';
+  $picture = ($account->picture) ? file_create_url($account->picture) : '';
   if ($picture) {
-    $output.= '  <foaf:img rdf:resource="'.$picture.'" />' . "\n";
-    $output.= '  <foaf:depiction rdf:resource="'.$picture.'" />' . "\n";
+    $foaf['img'] .= '  <foaf:img rdf:resource="'. $picture ."\" />\n";
+    $foaf['img'] .= '  <foaf:depiction rdf:resource="'. $picture ."\" />\n";
   }
-  $output.= '  <foaf:nick>'.$account->name ."</foaf:nick>\n";
 
   // weblog
-  if (module_exist('blog')) {
-    $output.= '  <foaf:weblog rdf:resource="'.url('blog/'.$uid, null, null, true) . '" />' . "\n";
+  if (module_exists('blog')) {
+    $foaf['weblog'] = '  <foaf:weblog rdf:resource="'. url('blog/'. $uid, null, null, true) .'" />'."\n";
   }
-
-  if ($title = _foaf_profile_get($uid, variable_get('foaf_title',''))) {
-    $output.= '  <foaf:title>'.$title."</foaf:title>\n";
+  if ($title = _foaf_profile_get($uid, variable_get('foaf_title', ''))) {
+    $foaf['title'] = '  <foaf:title>'. $title ."</foaf:title>\n";
   }
-  if ($Organization = _foaf_profile_get($uid, variable_get('foaf_Organization',''))) {
-    $output.= '  <foaf:Organization>'.$Organization."</foaf:Organization>\n";
+  if ($Organization = _foaf_profile_get($uid, variable_get('foaf_Organization', ''))) {
+    $foaf['Organization'] = '  <foaf:Organization>'. $Organization ."</foaf:Organization>\n";
   }
-  if ($phone = _foaf_profile_get($uid, variable_get('foaf_phone',''))) {
-    $output.= '  <foaf:phone rdf:resource="'.$phone.'"/>'."\n";
+  if ($phone = _foaf_profile_get($uid, variable_get('foaf_phone', ''))) {
+    $foaf['phone'] = '  <foaf:phone rdf:resource="'. $phone .'"/>'."\n";
   }
-  if ($aimChatID = _foaf_profile_get($uid, variable_get('foaf_aimChatID',''))) {
-    $output.= '  <foaf:aimChatID>'.$aimChatID."</foaf:aimChatID>\n";
+  if ($aimChatID = _foaf_profile_get($uid, variable_get('foaf_aimChatID', ''))) {
+    $foaf['aimChatID'] = '  <foaf:aimChatID>'. $aimChatID ."</foaf:aimChatID>\n";
   }
-  if ($icqChatID = _foaf_profile_get($uid, variable_get('foaf_icqChatID',''))) {
-    $output.= '  <foaf:icqChatID>'.$icqChatID."</foaf:icqChatID>\n";
+  if ($icqChatID = _foaf_profile_get($uid, variable_get('foaf_icqChatID', ''))) {
+    $foaf['icqChatID'] = '  <foaf:icqChatID>'. $icqChatID ."</foaf:icqChatID>\n";
   }
-  if ($msnChatID = _foaf_profile_get($uid, variable_get('foaf_msnChatID',''))) {
-    $output.= '  <foaf:msnChatID>'.$msnChatID."</foaf:msnChatID>\n";
+  if ($msnChatID = _foaf_profile_get($uid, variable_get('foaf_msnChatID', ''))) {
+    $foaf['msnChatID'] = '  <foaf:msnChatID>'. $msnChatID ."</foaf:msnChatID>\n";
   }
-  if ($yahooChatID = _foaf_profile_get($uid, variable_get('foaf_yahooChatID',''))) {
-    $output.= '  <foaf:yahooChatID>'.$yahooChatID."</foaf:yahooChatID>\n";
+  if ($yahooChatID = _foaf_profile_get($uid, variable_get('foaf_yahooChatID', ''))) {
+    $foaf['yahooChatID'] = '  <foaf:yahooChatID>'. $yahooChatID ."</foaf:yahooChatID>\n";
   }
-  if ($jabberID = _foaf_profile_get($uid, variable_get('foaf_jabberID',''))) {
-    $output.= '  <foaf:jabberID>'.$jabberID."</foaf:jabberID>\n";
+  if ($jabberID = _foaf_profile_get($uid, variable_get('foaf_jabberID', ''))) {
+    $foaf['jabberID'] = '  <foaf:jabberID>'. $jabberID ."</foaf:jabberID>\n";
   }
-  if ($workplaceHomepage = _foaf_profile_get($uid, variable_get('foaf_workplaceHomepage',''))) {
-    $output.= '  <foaf:workplaceHomepage rdf:resource="'.htmlentities($workplaceHomepage).'" />'."\n";
+  if ($workplaceHomepage = _foaf_profile_get($uid, variable_get('foaf_workplaceHomepage', ''))) {
+    $foaf['workplaceHomepage'] = '  <foaf:workplaceHomepage rdf:resource="'. htmlentities($workplaceHomepage) .'" />'."\n";
   }
 
   $address = '';
-  if ($street = _foaf_profile_get($uid, variable_get('foaf_street',''))) {
-    $address.= '    <vCard:Street>'.$street."</vCard:Street>\n";
+  if ($street = _foaf_profile_get($uid, variable_get('foaf_street', ''))) {
+    $address .= '    <vCard:Street>'. $street ."</vCard:Street>\n";
   }
-  if ($locality = _foaf_profile_get($uid, variable_get('foaf_locality',''))) {
-    $address.= '    <vCard:Locality>'.$locality."</vCard:Locality>\n";
+  if ($locality = _foaf_profile_get($uid, variable_get('foaf_locality', ''))) {
+    $address .= '    <vCard:Locality>'. $locality ."</vCard:Locality>\n";
   }
-  if ($region = _foaf_profile_get($uid, variable_get('foaf_region',''))) {
-    $address.= '    <vCard:Region>'.$region."</vCard:Region>\n";
+  if ($region = _foaf_profile_get($uid, variable_get('foaf_region', ''))) {
+    $address .= '    <vCard:Region>'. $region ."</vCard:Region>\n";
   }
-  if ($pcode = _foaf_profile_get($uid, variable_get('foaf_pcode',''))) {
-    $address.= '    <vCard:Pcode>'.$pcode."</vCard:Pcode>\n";
+  if ($pcode = _foaf_profile_get($uid, variable_get('foaf_pcode', ''))) {
+    $address .= '    <vCard:Pcode>'. $pcode ."</vCard:Pcode>\n";
   }
-  if ($country = _foaf_profile_get($uid, variable_get('foaf_country',''))) {
-    $address.= '    <vCard:Country>'.$country."</vCard:Country>\n";
+  if ($country = _foaf_profile_get($uid, variable_get('foaf_country', ''))) {
+    $address .= '    <vCard:Country>'. $country ."</vCard:Country>\n";
   }
 
   if ($address) {
-    $output.= '  <vCard:ADR rdf:parseType="Resource">'."\n";
-    $output.= $address;
-    $output.= "  </vCard:ADR>\n";
+    $vCard['ADR'] = '  <vCard:ADR rdf:parseType="Resource">'."\n$address  </vCard:ADR>\n";
   }
 
   if ($keywords = _foaf_profile_get($uid, variable_get('foaf_keywords', ''))) {
-    $output .= '  <bio:keywords>'.$keywords."</bio:keywords>\n";
+    $bio['keywords'] = '  <bio:keywords>'. $keywords ."</bio:keywords>\n";
   }
 
   if (function_exists('buddylist_get_buddies')) {
-    $buddies = buddylist_get_buddies($uid);   
+    $buddies = buddylist_get_buddies($uid);
+    $foaf_buddylist = '';
     foreach ($buddies as $buddy) {
-      $output .= "  <foaf:knows>\n";
-      $output .= "    <foaf:Person>\n";
-      $output .= "      <foaf:name>".$buddy->name."</foaf:name>\n";
+      $foaf_buddylist .= "  <foaf:knows>\n";
+      $foaf_buddylist .= "    <foaf:Person>\n";
+      $foaf_buddylist .= "      <foaf:name>". $buddy->name ."</foaf:name>\n";
       if ($buddy->mail) {
-        $output .= '      <foaf:mbox_sha1sum>'.sha1('mailto:' . $buddy->mail)."</foaf:mbox_sha1sum>\n";
+        $foaf_buddylist .= '      <foaf:mbox_sha1sum>'. sha1('mailto:'. $buddy->mail) ."</foaf:mbox_sha1sum>\n";
       }
       if ($buddy->uid) {
-        $output .= '      <rdfs:seeAlso rdf:resource="'. url('foaf/'.$buddy->uid) . '" />' ."\n";
+        $foaf_buddylist .= '      <rdfs:seeAlso rdf:resource="'. url('foaf/'. $buddy->uid) .'" />'."\n";
       }
-      $output .= "    </foaf:Person>\n";
-      $output .= "  </foaf:knows>\n";
+      $foaf_buddylist .= "    </foaf:Person>\n";
+      $foaf_buddylist .= "  </foaf:knows>\n";
     }
   }
-  
-  $output .= "</foaf:Person>\n";
-  $output .= "</rdf:RDF>\n";
 
-  header ('Content-Type: application/rdf+xml');
-  header ('Content-Disposition: attachment; filename="'.$account->name.'.rdf"');
+  // Output
+  $output .= <<<OUTPUT
+<?xml version="1.0" encoding="iso-8859-1" ?>
+<!-- generator="Drupal FOAF.Module" -->
+<rdf:RDF xmlns="http://xmlns.com/foaf/0.1"
+  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+  xmlns:dc="http://purl.org/dc/elements/1.1/"
+  xmlns:admin="http://webns.net/mvcb/"
+  xmlns:bio="http://purl.org/vocab/bio/0.1/"
+  xmlns:foaf="http://xmlns.com/foaf/0.1/"
+  xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#">
+
+<foaf:PersonalProfileDocument rdf:about="">
+  <foaf:maker rdf:nodeID="_{$uid}" />
+  <foaf:primaryTopic rdf:nodeID="_{$uid}" />
+  <dc:title>{$dc['title']}</dc:title>
+  <dc:description>{$dc['description']}</dc:description>
+  <admin:generatorAgent rdf:resource="http://drupal.org/" />
+</foaf:PersonalProfileDocument>
+
+<foaf:Person rdf:nodeID="_{$uid}">
+{$foaf['names']}{$foaf['mail']}{$foaf['img']}
+  <foaf:nick>{$account->name}</foaf:nick>
+{$foaf['weblog']}{$foaf['title']}{$foaf['Organization']}{$foaf['phone']}{$foaf['aimChatID']}{$foaf['icqChatID']}{$foaf['msnChatID']}{$foaf['yahooChatID']}{$foaf['jabberID']}{$foaf['workplaceHomepage']}{$vCard['ADR']}{$bio['keywords']}{$foaf_buddylist}
+</foaf:Person>
+</rdf:RDF>
+OUTPUT;
+
+  header('Content-Type: application/rdf+xml');
+  header('Content-Disposition: attachment; filename="'. $account->name .'.rdf"');
   print $output;
 }
 
@@ -256,10 +393,10 @@ function foaf_import($account) {
     return;
   }
   
-  $fp = fopen($account->foaf_url,'r');
+  $fp = fopen($account->foaf_url, 'r');
   if (!$fp) {
     // failed to open file (set allow_url_fopen = On)
-    return; 
+    return;
   }
   while (!feof($fp)) {
     $data .= fread($fp, 4192);
@@ -276,24 +413,24 @@ function foaf_import($account) {
     _foaf_import_image($depiction, $account);
   }
   
-  _foaf_profile_set($account->uid, variable_get('foaf_name',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:NAME'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_title',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:TITLE'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_firstName',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:FIRSTNAME'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_surname',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:SURNAME'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_Organization',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:ORGANIZATION'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_phone',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:PHONE'][0]['ATTRIBUTES']['RDF:RESOURCE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_aimChatID',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:AIMCHATID'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_icqChatID',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:ICQCHATID'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_msnChatID',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:MSNCHATID'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_yahooChatID',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:YAHOOCHATID'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_jabberID',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:JABBERID'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_workplaceHomepage',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:WORKPLACEHOMEPAGE'][0]['ATTRIBUTES']['RDF:RESOURCE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_street',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['VCARD:ADR'][0]['VCARD:STREET'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_locality',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['VCARD:ADR'][0]['VCARD:LOCALITY'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_region',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['VCARD:ADR'][0]['VCARD:REGION'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_pcode',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['VCARD:ADR'][0]['VCARD:PCODE'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_country',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['VCARD:ADR'][0]['VCARD:COUNTRY'][0]['VALUE']);
-  _foaf_profile_set($account->uid, variable_get('foaf_keywords',0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['BIO:KEYWORDS'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_name', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:NAME'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_title', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:TITLE'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_firstName', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:FIRSTNAME'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_surname', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:SURNAME'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_Organization', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:ORGANIZATION'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_phone', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:PHONE'][0]['ATTRIBUTES']['RDF:RESOURCE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_aimChatID', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:AIMCHATID'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_icqChatID', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:ICQCHATID'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_msnChatID', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:MSNCHATID'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_yahooChatID', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:YAHOOCHATID'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_jabberID', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:JABBERID'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_workplaceHomepage', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['FOAF:WORKPLACEHOMEPAGE'][0]['ATTRIBUTES']['RDF:RESOURCE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_street', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['VCARD:ADR'][0]['VCARD:STREET'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_locality', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['VCARD:ADR'][0]['VCARD:LOCALITY'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_region', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['VCARD:ADR'][0]['VCARD:REGION'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_pcode', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['VCARD:ADR'][0]['VCARD:PCODE'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_country', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['VCARD:ADR'][0]['VCARD:COUNTRY'][0]['VALUE']);
+  _foaf_profile_set($account->uid, variable_get('foaf_keywords', 0), $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]['BIO:KEYWORDS'][0]['VALUE']);
 
   watchdog('user', t('FOAF: imported data from %url', array('%url' => $account->foaf_url)));
 }
@@ -301,8 +438,8 @@ function foaf_import($account) {
 function foaf_login($user) {
   if (!$user->foaf_url) {
     if ($server = strrchr($user->name, '@')) {
-      $name = substr($user->name, 0, strlen($user->name) - strlen($server));
-      $server = substr($server, 1);
+      $name = drupal_substr($user->name, 0, drupal_strlen($user->name) - drupal_strlen($server));
+      $server = drupal_substr($server, 1);
     }
     else {
       return;
@@ -323,20 +460,36 @@ function foaf_login($user) {
  */
 function foaf_get_url($username) {
   if ($user = user_load(array('name' => $username, 'status' => 1))) {
-    return url('foaf/'.$user->uid, null,null, true);
+    return url('foaf/'. $user->uid, null, null, true);
   }
 }
-                                 
+
 function foaf_user_form($user) {
-  $data = form_textfield(t('URL for your FOAF file'), 'foaf_url', $user->foaf_url, 64, 255);
-  $data.= form_checkbox(t('Allow FOAF export'), 'foaf_export', 1, _foaf_allow_export($user));
-      
-  $items = array();
-  $items[] = array('title' => t("FOAF Settings"),
-                   'data' => $data,
-                   'weight' => 0);
 
-  return $items;
+  $foafuser = variable_get('foafuser', NULL);
+
+  $form['foafuser'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('FOAF Settings'),
+    '#weight' => 0,
+  );
+
+  $form['foafuser']['foaf_url'] = array(
+    '#type' => 'textfield',
+    '#title' => t('URL for your FOAF file'),
+    '#default_value' => $user->foaf_url,
+    '#size' => 64,
+    '#maxlength' => 255,
+  );
+
+  $form['foafuser']['foaf_export'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Allow FOAF export'),
+    '#return_value' => 1,
+    '#default_value' => _foaf_allow_export($user),
+  );
+
+  return $form;
 }
 
 /**
@@ -371,10 +524,10 @@ function _foaf_profile_set($uid, $fid, $
  * TODO - refactor user_validate_picture
  */
 function _foaf_import_image($url, $account) {
-  $fp = fopen($url,'r');
+  $fp = fopen($url, 'r');
   if (!$fp) {
     // failed to open file (set allow_url_fopen = On)
-    return; 
+    return;
   }
   while (!feof($fp)) {
     $data .= fread($fp, 4192);
@@ -398,7 +551,7 @@ function _foaf_import_image($url, $accou
     file_delete($tempfile);
   }
   else {
-    switch($size[2]) {
+    switch ($size[2]) {
       case 1:
         $ext = '.gif';
         break;
@@ -435,6 +588,7 @@ function _foaf_parse($data) {
 
 // internal function: build a node of the tree
 function _foaf_buildtag($thisvals, $vals, &$i, $type) {
+  $tag = array();
   
   if (isset($thisvals['attributes']))
     $tag['ATTRIBUTES'] = $thisvals['attributes'];
@@ -475,9 +629,11 @@ function _foaf_getchildren($vals, &$i) {
       if ($index_numeric) {
         $tag['TAG'] = $vals[$i]['tag'];
         $children[] = $tag;
-      } else
+      }
+      else {
         $children[$vals[$i]['tag']][] = $tag;
-            }
+      }
+    }
     
     // 'close:    End of node, return collected data
     //        Do not increment $i or nodes disappear!
@@ -485,7 +641,7 @@ function _foaf_getchildren($vals, &$i) {
         break;
   }
   if ($collapse_dups)
-    foreach($children as $key => $value)
+    foreach ($children as $key => $value)
         if (is_array($value) && (count($value) == 1))
           $children[$key] = $value[0];
   return $children;
@@ -499,4 +655,3 @@ function _foaf_allow_export($account) {
     return variable_get('foaf_export_default', 0);
   }
 }
-?>
\ No newline at end of file
