* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+\r
require_once('common/include/ProjectManager.class.php');
+require_once('common/include/rdfutils.php');\r
class doaprdfPlugin extends Plugin {
public function __construct($id=0) {
$this->Plugin($id) ;
$this->name = "doaprdf";
$this->text = "DoaPRDF!"; // To show in the tabs, use...
- //$this->_addHook("user_personal_links");//to make a link to the user's personal part of the plugin
- //$this->_addHook("usermenu");
- //$this->_addHook("groupmenu"); // To put into the project tabs
- //$this->_addHook("groupisactivecheckbox"); // The "use ..." checkbox in editgroupinfo
- //$this->_addHook("groupisactivecheckboxpost"); //
- //$this->_addHook("userisactivecheckbox"); // The "use ..." checkbox in user account
- //$this->_addHook("userisactivecheckboxpost"); //
- //$this->_addHook("project_admin_plugins"); // to show up in the admin page fro group
$this->_addHook("script_accepted_types");
$this->_addHook("content_negociated_project_home");
+ $this->_addHook("alt_representations");
}
-/*
- function CallHook ($hookname, &$params) {
- global $use_doaprdfplugin,$G_SESSION,$HTML;
- if ($hookname == "usermenu") {
- $text = $this->text; // this is what shows in the tab
- if ($G_SESSION->usesPlugin("doaprdf")) {
- $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we're calling is the user one
- echo ' | ' . $HTML->PrintSubMenu (array ($text),
- array ('/plugins/doaprdf/index.php' . $param ));
- }
- } elseif ($hookname == "groupmenu") {
- $group_id=$params['group'];
- $project = &group_get_object($group_id);
- if (!$project || !is_object($project)) {
- return;
- }
- if ($project->isError()) {
- return;
- }
- if (!$project->isProject()) {
- return;
- }
- if ( $project->usesPlugin ( $this->name ) ) {
- $params['TITLES'][]=$this->text;
- $params['DIRS'][]=util_make_url ('/plugins/doaprdf/index.php?type=group&id=' . $group_id . "&pluginname=" . $this->name) ; // we indicate the part we're calling is the project one
- } else {
- $params['TITLES'][]=$this->text." is [Off]";
- $params['DIRS'][]='';
- }
- (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
- } elseif ($hookname == "groupisactivecheckbox") {
- //Check if the group is active
- // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
- $group_id=$params['group'];
- $group = &group_get_object($group_id);
- echo "<tr>";
- echo "<td>";
- echo ' <input type="checkbox" name="use_doaprdfplugin" value="1" ';
- // checked or unchecked?
- if ( $group->usesPlugin ( $this->name ) ) {
- echo "checked";
- }
- echo " /><br/>";
- echo "</td>";
- echo "<td>";
- echo "<strong>Use ".$this->text." Plugin</strong>";
- echo "</td>";
- echo "</tr>";
- } elseif ($hookname == "groupisactivecheckboxpost") {
- // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
- $group_id=$params['group'];
- $group = &group_get_object($group_id);
- $use_doaprdfplugin = getStringFromRequest('use_doaprdfplugin');
- if ( $use_doaprdfplugin == 1 ) {
- $group->setPluginUse ( $this->name );
- } else {
- $group->setPluginUse ( $this->name, false );
- }
- } elseif ($hookname == "user_personal_links") {
- // this displays the link in the user's profile page to it's personal DoaPRDF (if you want other sto access it, youll have to change the permissions in the index.php
- $userid = $params['user_id'];
- $user = user_get_object($userid);
- $text = $params['text'];
- //check if the user has the plugin activated
- if ($user->usesPlugin($this->name)) {
- echo ' <p>' ;
- echo util_make_link ("/plugins/doaprdf/index.php?id=$userid&type=user&pluginname=".$this->name,
- _('View Personal DoaPRDF')
- );
- echo '</p>';
- }
- } elseif ($hookname == "project_admin_plugins") {
- // this displays the link in the project admin options page to it's DoaPRDF administration
- $group_id = $params['group_id'];
- $group = &group_get_object($group_id);
- if ( $group->usesPlugin ( $this->name ) ) {
- echo '<p>'.util_make_link ("/plugins/doaprdf/admin/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
- _('DoaPRDF Admin')).'</p>' ;
- }
- }
- elseif ($hookname == "blahblahblah") {
- // ...
- }
- }
- */
/**
* Declares itself as accepting RDF XML on /users
* @param unknown_type $params
*/
function content_negociated_project_home (&$params) {
- global $group_id;
-
$projectname = $params['groupname'];
$accept = $params['accept'];
+ $group_id = $params['group_id'];
if($accept == 'application/rdf+xml') {
+
+ // connect to FusionForge internals
$pm = ProjectManager::instance();
$project = $pm->getProject($group_id);
+ $project_shortdesc = $project->getPublicName();
$project_description = $project->getDescription();
$tags_list = NULL;
if (forge_get_config('use_project_tags')) {
$tags_list = $group->getTags();
}
+ // We will return RDF+XML
$params['content_type'] = 'application/rdf+xml';
- $xml = '<?xml version="1.0"?>
- <rdf:RDF
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
- xmlns:doap="http://usefulinc.com/ns/doap#"
- xmlns:dcterms="http://purl.org/dc/terms/">
-
- <doap:Project rdf:about="">
- <doap:name>'. $projectname .'</doap:name>';
- if($project_description) {
- $xml .= '<doap:shortdesc>'. $project_description . '</doap:shortdesc>';
- }
- if($tags_list) {
- $tags = split(', ',$tags_list);
- foreach($tags as $tag) {
- $xml .= '<dcterms:subject>'.$tag.'</dcterms:subject>';
- }
+ // Construct an ARC2_Resource containing the project's RDF (DOAP) description
+ $ns = array(\r
+ 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',\r
+ 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',\r
+ 'doap' => 'http://usefulinc.com/ns/doap#',\r
+ 'dcterms' => 'http://purl.org/dc/terms/' /*,\r
+ 'oslc' => 'http://open-services.net/ns/core#' */\r
+ );\r
+ \r
+ $conf = array(\r
+ 'ns' => $ns\r
+ /*,
+ 'serializer_type_nodes' => true*/\r
+ );\r
+ \r
+ $res = ARC2::getResource($conf);\r
+ $res->setURI('');\r
+ \r
+ //$res->setRel('rdf:type', 'doap:Project');\r
+ rdfutils_setPropToUri($res, 'rdf:type', 'doap:Project');\r
+ \r
+ $res->setProp('doap:name', $projectname);\r
+ $res->setProp('doap:shortdesc', $project_shortdesc);\r
+ if($project_description) {\r
+ $res->setProp('doap:description', $project_description);\r
+ }\r
+ if($tags_list) {\r
+ $tags = split(', ',$tags_list);\r
+ $res->setProp('dcterms:subject', $tags);\r
+ }\r
+
+ // Now, we need to collect complementary RDF descriptiosn of the project via other plugins \r
+ // invoke the 'project_rdf_metadata' hook so as to complement the RDF description\r
+ $hook_params = array();
+
+ $hook_params['prefixes'] = array();
+ foreach($ns as $prefix => $url) {
+ $hook_params['prefixes'][$url] = $prefix;
}
+ /*\r
+ $hook_params['prefixes'] = array(\r
+ 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf',\r
+ 'http://www.w3.org/2000/01/rdf-schema#' => 'rdfs',\r
+ 'http://usefulinc.com/ns/doap#' => 'doap',\r
+ 'http://purl.org/dc/terms/' => 'dcterms'\r
+ );
+ */\r
+ $hook_params['group'] = $group_id;\r
- $xml .='</doap:Project>
- </rdf:RDF>';
+ // pass the resource in case it could be useful (read-only in principle)\r
+ $hook_params['in_Resource'] = $res;\r
+
+ $hook_params['out_Resources'] = array();\r
+ \r
+ plugin_hook_by_reference('project_rdf_metadata', $hook_params);\r
+
+ // add new prefixes to the list
+ foreach($hook_params['prefixes'] as $url => $prefix) {
+ if (!isset($ns[$prefix])) {\r
+ $ns[$prefix] = $url;
+ }\r
+ }\r
+
+ $merged_index = $res->index;\r
+ foreach($hook_params['out_Resources'] as $out_res) {
+ $merged_index = ARC2::getMergedIndex($merged_index, $out_res->index);
+ }\r
+
+ $conf = array(\r
+ 'ns' => $ns,\r
+ 'serializer_type_nodes' => true\r
+ );\r
- $params['content'] = $xml;
+ $ser = ARC2::getRDFXMLSerializer($conf);\r
+ \r
+ /* Serialize a resource index */\r
+ $doc = $ser->getSerializedIndex($merged_index);\r
+
+ $params['content'] = $doc;
}
}
+
+ /**\r
+ * Declares a link to itself in the link+meta HTML headers\r
+ * @param unknown_type $params\r
+ */\r
+ function alt_representations (&$params) {\r
+ $script_name = $params['script_name'];
+ if ($script_name == '/projects') {
+ $params['return'][] = '<link rel="meta" type="application/rdf+xml" title="DOAP RDF Data" href=""/>';
+ }
+ }\r
+
}
// Local Variables: