[Fusionforge-commits] r16126 - in trunk/src: docs plugins/doaprdf plugins/doaprdf/etc plugins/doaprdf/include www www/include

Olivier Berger olberger at fusionforge.org
Tue Aug 21 18:20:30 CEST 2012


Author: olberger
Date: 2012-08-21 18:20:30 +0200 (Tue, 21 Aug 2012)
New Revision: 16126

Modified:
   trunk/src/docs/README.Plugins
   trunk/src/plugins/doaprdf/README
   trunk/src/plugins/doaprdf/etc/doaprdf.ini
   trunk/src/plugins/doaprdf/include/doaprdfPlugin.class.php
   trunk/src/www/include/Layout.class.php
   trunk/src/www/projects
Log:
Add support for /projects RDF rendering via content-negociation through 'content_negociated_projects_list' hook

Modified: trunk/src/docs/README.Plugins
===================================================================
--- trunk/src/docs/README.Plugins	2012-08-21 16:09:41 UTC (rev 16125)
+++ trunk/src/docs/README.Plugins	2012-08-21 16:20:30 UTC (rev 16126)
@@ -502,7 +502,7 @@
   Parameters : $params['accept'] provides the content-type to be rendered, $params['groupname'] the project name, $params['group_id'] the project ID
   Description: returns in $params['content'] an alternate content for /projects/ page and 
                in $params['content_type'] the actual content-type to return
-		
+
   Hook Name  : content_negociated_user_home
   Parameters : $params['accept'] provides the content-type to be rendered, $params['username'] the user name
   Description: returns in $params['content'] an alternate content for /users/ page and 
@@ -526,6 +526,11 @@
   Parameters : $params['script_name'] contains the SCRIPT_NAME (filtered to work only on /projects or /users for the moment)
   Description: returns alternate representations for a particular page in $params['results'] which is populated by the hook users 
 
+  Hook Name  : content_negociated_projects_list
+  Parameters : $params['accept'] provides the content-type to be rendered
+  Description: returns in $params['content'] an alternate content for /projects page and 
+               in $params['content_type'] the actual content-type to return
+
 TODO (nerville) : document display_hierarchy
 TODO (lolando ?) : document role_normalize, role_translate_strings, role_has_permission, role_get_setting, list_roles_by_permission 
 TODO : document project_link_with_tooltip

Modified: trunk/src/plugins/doaprdf/README
===================================================================
--- trunk/src/plugins/doaprdf/README	2012-08-21 16:09:41 UTC (rev 16125)
+++ trunk/src/plugins/doaprdf/README	2012-08-21 16:20:30 UTC (rev 16126)
@@ -5,4 +5,6 @@
 For instance, one may try :
  curl -k -H 'Accept: application/rdf+xml' https://myforge.example.com/projects/aproject/
 
+More details about DOAP available from https://github.com/edumbill/doap/wiki
+
 This plugin has been initiated as part of the COCLICO project.

Modified: trunk/src/plugins/doaprdf/etc/doaprdf.ini
===================================================================
--- trunk/src/plugins/doaprdf/etc/doaprdf.ini	2012-08-21 16:09:41 UTC (rev 16125)
+++ trunk/src/plugins/doaprdf/etc/doaprdf.ini	2012-08-21 16:20:30 UTC (rev 16126)
@@ -4,4 +4,4 @@
 ; valid means : production ready.
 ; Any other strings means it's under work or broken and plugin
 ; is available in installation_environment = development only.
-plugin_status = valid
\ No newline at end of file
+plugin_status = valid

Modified: trunk/src/plugins/doaprdf/include/doaprdfPlugin.class.php
===================================================================
--- trunk/src/plugins/doaprdf/include/doaprdfPlugin.class.php	2012-08-21 16:09:41 UTC (rev 16125)
+++ trunk/src/plugins/doaprdf/include/doaprdfPlugin.class.php	2012-08-21 16:20:30 UTC (rev 16126)
@@ -41,7 +41,7 @@
 	}
 
 	/**
-	 * Declares itself as accepting RDF XML on /users
+	 * Declares itself as accepting RDF XML on /projects/...
 	 * @param unknown_type $params
 	 */
 	function script_accepted_types (&$params) {
@@ -52,7 +52,7 @@
 	}
 
 	/**
-	 * Outputs user's FOAF profile
+	 * Outputs project's DOAP profile
 	 * @param unknown_type $params
 	 */
 	function content_negociated_project_home (&$params) {
@@ -81,55 +81,42 @@
 					'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
 					'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
 					'doap' => 'http://usefulinc.com/ns/doap#',
-					'dcterms' => 'http://purl.org/dc/terms/' /*,
-					'oslc' => 'http://open-services.net/ns/core#' */
+					'dcterms' => 'http://purl.org/dc/terms/' 
 			);
-			
+				
 			$conf = array(
 					'ns' => $ns
-					/*,
-					'serializer_type_nodes' => true*/
 			);
 			
 			$res = ARC2::getResource($conf);
-			$res->setURI('');
+			$res->setURI(util_make_url_g($projectname, $group_id));
 				
-			//$res->setRel('rdf:type', 'doap:Project');
+			// $res->setRel('rdf:type', 'doap:Project');
 			rdfutils_setPropToUri($res, 'rdf:type', 'doap:Project');
-				
+							
 			$res->setProp('doap:name', $projectname);
 			$res->setProp('doap:shortdesc', $project_shortdesc);
 			if($project_description) {
 				$res->setProp('doap:description', $project_description);
 			}
+			$res->setProp('doap:homepage', $project->getHomePage());
+			$tags = array();
 			if($tags_list) {
 				$tags = split(', ',$tags_list);
 				$res->setProp('dcterms:subject', $tags);
 			}
-
+			
 			// Now, we need to collect complementary RDF descriptiosn of the project via other plugins 
 			// invoke the 'project_rdf_metadata' hook so as to complement the RDF description
 			$hook_params = array();
-			
 			$hook_params['prefixes'] = array();
 			foreach($ns as $prefix => $url) {
 				$hook_params['prefixes'][$url] = $prefix;
 			}
-			/*
-			$hook_params['prefixes'] = array(
-					'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf',
-					'http://www.w3.org/2000/01/rdf-schema#' => 'rdfs',
-					'http://usefulinc.com/ns/doap#' => 'doap',
-					'http://purl.org/dc/terms/' => 'dcterms'
-			);
-			*/
 			$hook_params['group'] = $group_id;
-			
 			// pass the resource in case it could be useful (read-only in principle)
 			$hook_params['in_Resource'] = $res;
-
 			$hook_params['out_Resources'] = array();
-			
 			plugin_hook_by_reference('project_rdf_metadata', $hook_params);
 
 			// add new prefixes to the list
@@ -139,6 +126,7 @@
 				}
 			}
 
+			// merge the two sets of triples
 			$merged_index = $res->index;
 			foreach($hook_params['out_Resources'] as $out_res) {
 				$merged_index = ARC2::getMergedIndex($merged_index, $out_res->index);
@@ -154,7 +142,7 @@
 			/* Serialize a resource index */
 			$doc = $ser->getSerializedIndex($merged_index);
 
-			$params['content'] = $doc;
+			$params['content'] = $doc . "\n";
 		}
 	}
 	
@@ -164,7 +152,9 @@
 	 */
 	function alt_representations (&$params) {
 		$script_name = $params['script_name'];
-		if ($script_name == '/projects') {
+		$php_self = $params['php_self'];
+		// really trigger only for real projects descriptions, not for the projects index
+		if ( ($script_name == '/projects') && (($php_self != '/projects') && ($php_self != '/projects/')) ) {
 			$params['return'][] = '<link rel="meta" type="application/rdf+xml" title="DOAP RDF Data" href=""/>';
 		}
 	}

Modified: trunk/src/www/include/Layout.class.php
===================================================================
--- trunk/src/www/include/Layout.class.php	2012-08-21 16:09:41 UTC (rev 16125)
+++ trunk/src/www/include/Layout.class.php	2012-08-21 16:20:30 UTC (rev 16126)
@@ -380,8 +380,11 @@
 
 		if ($script_name == '/projects' || $script_name == '/users') {
 
+			$php_self = getStringFromServer('PHP_SELF');
+			
 			// invoke the 'alt_representations' hook
 			$params = array('script_name' => $script_name,
+							'php_self' => $php_self,
 							'return' => array());
 
 			plugin_hook_by_reference('alt_representations', $params);

Modified: trunk/src/www/projects
===================================================================
--- trunk/src/www/projects	2012-08-21 16:09:41 UTC (rev 16125)
+++ trunk/src/www/projects	2012-08-21 16:20:30 UTC (rev 16126)
@@ -38,11 +38,29 @@
 //
 
 $default_content_type = 'text/html';
-$script='project_home';
-$content_type = util_negociate_alternate_content_types($script, $default_content_type);
 
 if (!$group_id || !$project) {
-	exit_no_group();
+
+	$script = 'projects_list';
+	$content_type = util_negociate_alternate_content_types($script, $default_content_type);
+
+	if($content_type != $default_content_type) {
+		$hook_params = array();
+		$hook_params['accept'] = $content_type;
+		$hook_params['return'] = '';
+		$hook_params['content_type'] = '';
+		plugin_hook_by_reference('content_negociated_projects_list', $hook_params);
+		if($hook_params['content_type'] != ''){
+				header('Content-type: '. $hook_params['content_type']);
+				echo $hook_params['content'];
+		}
+		else {
+			header('HTTP/1.1 406 Not Acceptable',true,406);
+			exit(0);
+		}
+	} else {
+		exit_no_group();
+	}
 } else {
 	$subpage = getStringFromRequest('subpage');
 
@@ -58,6 +76,10 @@
 		header("Location: ".account_group_cvsweb_url($project->getUnixName()));
 		exit();
 	} else {
+	
+		$script='project_home';
+		$content_type = util_negociate_alternate_content_types($script, $default_content_type);
+	
 		// if a custom content-type is selected, then redirect to plugin's rendering
 		if($content_type != $default_content_type) {
 			$hook_params = array();




More information about the Fusionforge-commits mailing list