Monday, October 23, 2006

Drupal 4.7 and the foaf.module

I wanted the foaf module for drupal on 4.7; so instead of being a whinger; I just went out and did it.

Here's the patch:

Index: modules/foaf/foaf.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/foaf/foaf.module,v
retrieving revision 1.13
diff -u -r1.13 foaf.module
--- modules/foaf/foaf.module 12 Jul 2006 17:13:51 -0000 1.13
+++ modules/foaf/foaf.module 23 Oct 2006 13:21:35 -0000
@@ -1,5 +1,5 @@
<?php
-// $Id: foaf.module,v 1.13 2006/07/12 17:13:51 walkah Exp $
+// $Id: foaf.module,v 1.6.2.4 2005/11/29 18:22:34 walkah Exp $

/**
* Implements hook_help
@@ -11,8 +11,8 @@
$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>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 >> 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>';
@@ -55,9 +55,15 @@
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).'" />');
- $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));
+
+ $title = t('Personal Information');
+
+ $link = l('Download FOAF', 'foaf/'.$user->uid, NULL, NULL, NULL, FALSE, TRUE);
+ $output = array();
+ $output[$title][] = array('value' => $link);
+
+ return $output;
}
break;
case 'form':
@@ -69,31 +75,41 @@
}

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'));
+ $form = array();
+ $form["foaf_export_default"] = array();
+ $form["foaf_export_default"]["#title"] = t('Export <acronym title="Friend of a Friend">FOAF</acronym> for users by default');
+ $form["foaf_export_default"]["#type"] = 'radios';
+ $form["foaf_export_default"]["#default_value"] = variable_get('foaf_export_default', 0);
+ $form["foaf_export_default"]["#options"] = array(0 => t('no'), 1=> t('yes'));
+ $form["foaf_export_default"]["#suffix"] = t('This can be overridden by individual users');
+
+ $formItemTemplate = array('#type' => 'select');
+
+ $fields = array('foaf_name', 'foaf_title','foaf_firstName',
+ 'foaf_surname', 'foaf_Organization',
+ 'foaf_phone', 'foaf_aimChatID', 'foaf_icqChatID',
+ 'foaf_msnChatID', 'foaf_yahooChatID', 'foaf_jabberChatID',
+ 'foaf_workplaceHomepage');
+ $fields["vCard:Street"] = 'foaf_street';
+ $fields["vCard:Locality"] = 'foaf_locality';
+ $fields["vCard:Region"] = 'foaf_region';
+ $fields["vCard:PCode"] = 'foaf_pcode';
+ $fields["vCard:Country"] = 'foaf_country';
+ $fields["bio:keywords"] = 'foaf_keywords';
+
+ $form["settings"] = array("#title" => t('Field Mappings'), "#type" => "fieldset");
+ foreach ($fields as $name => $field) {
+ if (!is_string($name)) {
+ $name = str_replace('_', ':', $field);
+ }
+ $form["settings"][$field] = array_merge($formItemTemplate,
+ array('#title' => t('Field for ' . $name),
+ '#default_value' => variable_get($field, false),
+ '#options' => _foaf_profile_fields()
+ ));
+ }

- $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());
-
- $output.= form_group(t('Field Mappings'), $mapping);
- return $output;
+ return $form;
}

function foaf_xmlrpc() {
@@ -349,6 +365,7 @@
while ($row = db_fetch_object($result)) {
$output[$row->fid] = $row->title;
}
+
return $output;
}

No comments: