*/
var $data_array;
- function FRSFileType ($type_id, $name) {
+ function FRSFileType ($type_id=false, $name=false) {
$this->Error();
- $this->data_array = array( 'type_id' => $type_id, 'name' => $name);
+ if($type_id && $name) {
+ $this->data_array = array( 'type_id' => $type_id, 'name' => $name);
+ }
+ else {
+ if ($type_id) {
+ $this->fetchData($type_id);
+ }
+ }
}
/**
$res = db_query_params ('SELECT * FROM frs_release WHERE package_id=$1',
array ($this->getID())) ;
while ($arr = db_fetch_array($res)) {
- $this->package_releases[]=new FRSRelease($this,$arr['release_id'],$arr);
+ $this->package_releases[]=$this->newFRSRelease($arr['release_id'],$arr);
}
}
return $this->package_releases;
}
+
+ /**
+ * newFRSRelease - generates a FRSRelease (allows overloading by subclasses)
+ *
+ * @param string FRS release identifier
+ * @param array fetched data from the DB
+ * @return FRSRelease new FRSFile object.
+ */
+ protected function newFRSRelease($release_id, $data) {
+ return new FRSRelease($this,$release_id, $data);
+ }
+
/**
* delete - delete this package and all its related data.
*
util_handle_message(array_unique($arr),$subject,$text);
}
}
+
+ /**
+ * newFRSFile - generates a FRSFile (allows overloading by subclasses)
+ *
+ * @param string FRS file identifier
+ * @param array fetched data from the DB
+ * @return FRSFile new FRSFile object.
+ */
+ protected function newFRSFile($file_id, $data) {
+ return new FRSFile($this,$file_id, $data);
+ }
/**
* getFiles - gets all the file objects for files in this release.
$res = db_query_params ('SELECT * FROM frs_file_vw WHERE release_id=$1',
array ($this->getID())) ;
while ($arr = db_fetch_array($res)) {
- $this->release_files[]=new FRSFile($this,$arr['file_id'],$arr);
+ $this->release_files[]=$this->newFRSFile($arr['file_id'],$arr);
}
}
return $this->release_files;
--- /dev/null
+<?php
+/**
+ * FusionForge trove categories
+ *
+ * Copyright 2013, Olivier Berger and Institut Mines-Telecom
+ * Copyright 2013, Roland Mas
+ *
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+/**
+ * TODO: FusionForge Trove Categories
+ *
+ */
+class TroveCat extends Error {
+
+ var $data_array;
+
+ /**
+ * TroveCat() - CONSTRUCTOR.
+ *
+ * @param object The Group object.
+ * @param int The role_id.
+ */
+ function TroveCat($cat_id = false) {
+
+ if (!$cat_id) {
+ //setting up an empty object
+ //probably going to call create()
+ return true;
+ }
+ return $this->fetchData($cat_id);
+ }
+
+ /**
+ * fetchData - May need to refresh database fields.
+ *
+ * If an update occurred and you need to access the updated info.
+ *
+ * @return boolean success;
+ */
+ function fetchData($cat_id, &$res = false) {
+
+ unset($this->data_array);
+
+ if(! $res) {
+ $res = db_query_params('SELECT * FROM trove_cat WHERE trove_cat_id=$1',
+ array ($cat_id)) ;
+ if (!$res || db_numrows($res) < 1) {
+ $this->setError('TroveCat::fetchData()::'.db_error());
+ return false;
+ }
+ }
+ $row = db_fetch_array($res);
+ if($row) {
+ $this->data_array = $row;
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ function getId() {
+ return $this->data_array['trove_cat_id'];
+ }
+
+ function getShortName() {
+ return $this->data_array['shortname'];
+ }
+
+ function getFullName() {
+ return $this->data_array['fullname'];
+ }
+
+ function getParentId() {
+ return $this->data_array['parent'];
+ }
+
+ function getRootCatId() {
+ return $this->data_array['root_parent'];
+ }
+
+ function getIdsFullPath() {
+ return $this->data_array['fullpath_ids'];
+
+ }
+
+ function getDescription() {
+ return $this->data_array['description'];
+
+ }
+
+ function listSubTree() {
+ return TroveCat::getSubtree($this->data_array['trove_cat_id']);
+ }
+
+ static function getAllRoots() {
+ $rootcats = array();
+
+ $res = db_query_params ('
+ SELECT *
+ FROM trove_cat
+ WHERE parent=0
+ AND trove_cat_id!=0',
+ array());
+
+ do {
+ $trovecat = new TroveCat();
+ $fetched = $trovecat->fetchData(false, $res);
+ if ($fetched) {
+ $rootcats[] = $trovecat;
+ }
+ } while ($fetched);
+
+ return $rootcats;
+ }
+
+ static function getSubtree($root_cat_id) {
+ $subcats = array();
+
+ $res = db_query_params('
+ SELECT *
+ FROM trove_cat
+ WHERE root_parent=$1
+ ORDER BY fullpath',
+ array($root_cat_id));
+
+ do {
+ $trovecat = new TroveCat();
+ $fetched = $trovecat->fetchData(false, $res);
+ if ($fetched) {
+ $subcats[] = $trovecat;
+ }
+ } while ($fetched);
+
+ return $subcats;
+ }
+
+ static function getProjectCats($group_id) {
+ $cats = array();
+
+ $res = db_query_params ('
+ SELECT trove_cat.trove_cat_id AS trove_cat_id
+ FROM trove_cat,trove_group_link
+ WHERE trove_cat.trove_cat_id=trove_group_link.trove_cat_id
+ AND trove_group_link.group_id=$1
+ ORDER BY trove_cat.fullpath',
+ array($group_id));
+
+ $catids = array();
+ while($row = db_fetch_array($res)) {
+ $catids[] = $row['trove_cat_id'];
+ }
+
+ foreach($catids as $catid) {
+ $cats[] = new TroveCat($catid);
+ }
+ return $cats;
+ }
+}
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>
in $params['content_type'] the actual content-type to return
Hook Name : project_rdf_metadata
- Parameters : $params['prefixes'] : already used RDF prefixes in the form URL => shortname, $params['in_Resource'] : already constructed ARC2_Resource instances (read-only)
- Description: returns in $params['prefixes'] added prefixes, and in the array $params['out_Resources'] new ARC2_Resources including new triples to be included in the project's DOAP description
+ Parameters : $params['prefixes'] : already used RDF prefixes in the form URL => shortname,
+ $hook_params['group'] : group_id of the project,
+ $hook_params['in_Resource'] : (read-only) ARC2 resource already available,
+ $hook_params['details'] : 'full' or 'minimal' whether requesting a detailed or minimal description
+ $hook_params['out_Resources'] : (write) to be returned the new ARC2 resource
+ Description: returns in $params['prefixes'] and $params['out_Resources'] added prefixes and ARC2 RDF resource to be included in the project's DOAP description
Hook Name : role_adduser
Parameters : $params['user'] : user added to the role, $params['role'] : role added to the user
--- /dev/null
+<?php
+/**
+ * FusionForge ADMS.SW plugin - RDF serializable extension of FRSFile
+ *
+ * Copyright 2013, Olivier Berger and Institut Mines-Telecom
+ *
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+// This class overloads FRSFile to add RDF representation, based on ADMS.SW, using ARC2 and Graphite
+
+require_once $gfcommon.'frs/FRSFile.class.php';
+require_once 'RDFedFRSRelease.class.php';
+
+/**
+ * Factory method which creates a RDFedFRSFile from an file id
+ *
+ * @param int The file id
+ * @param array The result array, if it's passed in
+ * @return object RDFedFRSFile object
+ */
+function &rdfed_frsfile_get_object($file_id, $data=false) {
+ global $RDFED_FRSFILE_OBJ;
+ if (!isset($RDFED_FRSFILE_OBJ['_'.$file_id.'_'])) {
+ if ($data) {
+ //the db result handle was passed in
+ } else {
+ $res = db_query_params ('SELECT * FROM frs_file WHERE file_id=$1',
+ array ($file_id)) ;
+ if (db_numrows($res)<1 ) {
+ $RDFED_FRSFILE_OBJ['_'.$file_id.'_']=false;
+ return false;
+ }
+ $data = db_fetch_array($res);
+ }
+ $FRSRelease =& rdfed_frsrelease_get_object($data['release_id']);
+ $RDFED_FRSFILE_OBJ['_'.$file_id.'_']= new RDFedFRSFile($FRSRelease,$data['file_id'],$data);
+ }
+ return $RDFED_FRSFILE_OBJ['_'.$file_id.'_'];
+}
+
+
+class RDFedFRSFile extends FRSFile {
+
+ /**
+ * getDownloadUrl - constructs the download URL
+ *
+ * @return string URL
+ */
+ public function getDownloadUrl() {
+ return util_make_url('/frs/download.php/file/'.$this->getID().'/'.rawurlencode($this->getName()));
+ }
+
+ /**
+ * getUri - constructs the resource URI
+ *
+ * @return string resource URI
+ */
+ public function getUri() {
+ return $this->getDownloadUrl().'#package';
+ }
+
+ /**
+ * saveToGraph - updates a Graphite graph to add the resource's triples
+ *
+ * @param Graphite a Graphite graph to be updated
+ */
+ public function saveToGraph(&$graph) {
+
+ // Construct an ARC2_Resource containing the RDFedFRSFile RDF description
+ $ns = $graph->ns;
+
+ $conf = array(
+ 'ns' => $ns
+ );
+
+
+ $res = ARC2::getResource($conf);
+
+ $frs_release = $this->getFRSRelease();
+ $frs_package = $frs_release->getFRSPackage();
+ $group = $frs_package->getGroup();
+
+ $frs_file_name = $this->getName();
+
+ $file_uri = $this->getUri();
+ $res->setURI($file_uri);
+
+ // $res->setRel('rdf:type', 'admssw:SoftwarePackage');
+ rdfutils_setPropToUri($res, 'rdf:type', 'admssw:SoftwarePackage');
+
+ $res->setProp('rdfs:label', $frs_file_name);
+ $description = $frs_file_name. _(', part of ') .$frs_package->getName(). ' ' .$frs_release->getName();
+ $res->setProp('dcterms:description', $description);
+
+ rdfutils_setPropToUri($res, 'schema:downloadUrl', $this->getDownloadUrl());
+ rdfutils_setPropToXSDdateTime($res, 'dcterms:created', date('c', $this->getReleaseTime()));
+ $res->setProp('schema:fileSize', $this->getSize());
+
+ $frs_filetype_id = $this->getTypeID();
+ $frs_filetype = new FRSFileType($frs_filetype_id);
+
+ // This is hackish... ultimately, FusionForge should support proper mime-types
+ $mime_type = '';
+ $frs_filetype_name = $frs_filetype->getName();
+ switch ($frs_filetype_name) {
+ case '.deb':
+ $mime_type = 'application/x-deb';
+ break;
+ case '.rpm':
+ $mime_type = 'application/x-rpm';
+ break;
+ case '.zip':
+ $mime_type = 'application/zip';
+ break;
+ case '.bz2':
+ $mime_type = 'application/x-bzip2';
+ break;
+ case '.gz':
+ $mime_type = 'application/x-gzip';
+ break;
+ case '.jpg':
+ $mime_type = 'image/jpeg';
+ break;
+ case 'text':
+ $mime_type = 'text/plain';
+ break;
+ case 'html':
+ $mime_type = 'text/html';
+ break;
+ case 'pdf':
+ $mime_type = 'application/pdf';
+ break;
+ /* we won't treat these
+ Source .zip
+ Source .bz2
+ Source .gz
+ Source .rpm
+ Other Source File
+ Other
+ */
+ default:
+ $mime_type = 'application/binary';
+ break;
+ }
+ rdfutils_setPropToUri($res, 'dcterms:format', 'http://purl.org/NET/mediatypes/'. $mime_type);
+
+ rdfutils_setPropToUri($res, 'admssw:release', $frs_release->getUri());
+
+ rdfutils_setPropToUri($res, 'dcterms:license', $this->getDownloadUrl().'#unspecified_license');
+
+ $count = $graph->addTriples( ARC2::getTriplesFromIndex($res->index) );
+
+ // Add a resource for the license, that is an explicit "unspecified license", rather than not setting it... the ADMS.SW seem to require a mandatory license
+ $res = ARC2::getResource($conf);
+ $res->setURI($this->getDownloadUrl().'#unspecified_license');
+ $res->setProp('rdfs:label', 'Unspecified license (unavailable meta-data in the FusionForge File Release System)');
+
+ $count = $graph->addTriples( ARC2::getTriplesFromIndex($res->index) );
+
+ }
+}
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>
--- /dev/null
+<?php
+/**
+ * FusionForge ADMS.SW plugin - RDF serializable extension of FRSPackage
+ *
+ * Copyright 2013, Olivier Berger and Institut Mines-Telecom
+ *
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+// This class overloads FRSPackage to add RDF representation, based on ADMS.SW, using ARC2 and Graphite
+
+include_once('RDFedFRSRelease.class.php');
+
+/**
+ * Factory method which creates a RDFedFRSPackage from an project/group
+ *
+ * @param Group The project object
+ * @return object RDFedFRSPackage object
+ */
+function get_rdfed_frs_packages($Group) {
+ $ps = array();
+ $res = db_query_params ('SELECT * FROM frs_package WHERE group_id=$1',
+ array ($Group->getID())) ;
+ if (db_numrows($res) > 0) {
+ while($arr = db_fetch_array($res)) {
+ $ps[]=new RDFedFRSPackage($Group,$arr['package_id'],$arr);
+ }
+ }
+ return $ps;
+}
+
+
+class RDFedFRSPackage extends FRSPackage {
+
+ /**
+ * newFRSRelease - generates a RDFedFRSRelease, overloading base class' generator
+ *
+ * @param string FRS release identifier
+ * @param array fetched data from the DB
+ * @return RDFedFRSRelease new RDFedFRSRelease object.
+ */
+ protected function newFRSRelease($release_id, $data) {
+ return new RDFedFRSRelease($this,$release_id, $data);
+ }
+
+ /**
+ * getUri - constructs the resource URI
+ *
+ * @return string resource URI
+ */
+ static function getUri($projectname, $package_name) {
+ return util_make_url ('/frs/'.$projectname.'/'.$package_name);
+ }
+
+ /**
+ * saveToGraph - updates a Graphite graph to add the resource's triples
+ *
+ * @param Graphite a Graphite graph to be updated
+ */
+ public function saveToGraph(&$graph) {
+
+ $ns = $graph->ns;
+
+ $conf = array(
+ 'ns' => $ns
+ );
+
+ $group = $this->getGroup();
+
+ $projectname = $group->getUnixName();
+
+ $package_name = $this->getFileName();
+
+ $res = ARC2::getResource($conf);
+
+ $res->setURI(RDFedFRSPackage::getUri($projectname, $package_name));
+
+ // We don't type the object, which is only there for information, and does not correspond to any ADMS.SW entity
+ // $res->setRel('rdf:type', 'fusionforge:ReleaseSeries');
+ //rdfutils_setPropToUri($res, 'rdf:type', 'fusionforge:ReleaseSeries');
+
+ $res->setProp('rdfs:label', sprintf( _('%1$s release series of project %2$s'), $package_name, $projectname) );
+
+ $count = $graph->addTriples( ARC2::getTriplesFromIndex($res->index) );
+
+ $frs_releases = $this->getReleases();
+ foreach($frs_releases as $frs_release) {
+ if( $frs_release->getStatus() == 1 ) {
+ $frs_release->saveToGraph($graph);
+ }
+ }
+ }
+}
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>
--- /dev/null
+<?php
+/**
+ * FusionForge ADMS.SW plugin - RDF serializable extension of FRSRelease
+ *
+ * Copyright 2013, Olivier Berger and Institut Mines-Telecom
+ *
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+// This class overloads FRSRelease to add RDF representation, based on ADMS.SW, using ARC2 and Graphite
+
+include_once('RDFedFRSFile.class.php');
+
+/**
+ * Factory method which creates a RDFedFRSRelease from an release id
+ *
+ * @param int The release id
+ * @param array The result array, if it's passed in
+ * @return object RDFedFRSRelease object
+ */
+function rdfed_frsrelease_get_object($release_id, $data = false) {
+ global $RDFED_FRSRELEASE_OBJ;
+ if (!isset($RDFED_FRSRELEASE_OBJ['_'.$release_id.'_'])) {
+ if ($data) {
+ //the db result handle was passed in
+ } else {
+ $res = db_query_params ('SELECT * FROM frs_release WHERE release_id=$1',
+ array ($release_id)) ;
+ if (db_numrows($res)<1 ) {
+ $RDFED_FRSRELEASE_OBJ['_'.$release_id.'_']=false;
+ return false;
+ }
+ $data = db_fetch_array($res);
+ }
+ $FRSPackage = rdfed_frspackage_get_object($data['package_id']);
+ $RDFED_FRSRELEASE_OBJ['_'.$release_id.'_']= new RDFedFRSRelease($FRSPackage,$data['release_id'],$data);
+ }
+ return $RDFED_FRSRELEASE_OBJ['_'.$release_id.'_'];
+}
+
+class RDFedFRSRelease extends FRSRelease {
+
+ var $uri;
+
+ /**
+ * newFRSFile - generates a RDFedFRSFile, overloading base class' generator
+ *
+ * @param string FRS file identifier
+ * @param array fetched data from the DB
+ * @return RDFedFRSFile new RDFedFRSFile object.
+ */
+ protected function newFRSFile($file_id, $data) {
+ return new RDFedFRSFile($this, $file_id, $data);
+ }
+
+ /**
+ * getUri - constructs the resource URI
+ *
+ * @return string resource URI
+ */
+ function getUri() {
+ if(!$this->uri) {
+ $frs_package = $this->getFRSPackage();
+ $group = $frs_package->getGroup();
+
+ $projectname = $group->getUnixName();
+ $package_name = $frs_package->getFileName();
+ $release_name = $this->getFileName();
+
+ $this->uri = util_make_url ('/frs/'.$projectname.'/'.$package_name.'/'.$release_name);
+ }
+ return $this->uri;
+ }
+
+ /**
+ * saveToGraph - updates a Graphite graph to add the resource's triples
+ *
+ * @param Graphite a Graphite graph to be updated
+ */
+ public function saveToGraph(&$graph) {
+
+ // Construct an ARC2_Resource containing the FRSRelease RDF description
+ $ns = $graph->ns;
+
+ $conf = array(
+ 'ns' => $ns
+ );
+
+ $frs_package = $this->getFRSPackage();
+ $group = $frs_package->getGroup();
+
+ $projectname = $group->getUnixName();
+
+ $release_name = $this->getFileName();
+
+ $package_name = $frs_package->getFileName();
+
+ $res = ARC2::getResource($conf);
+
+ $res->setURI($this->getUri());
+
+ // $res->setRel('rdf:type', 'admssw:SoftwareRelease');
+ rdfutils_setPropToUri($res, 'rdf:type', 'admssw:SoftwareRelease');
+
+ $res->setProp('rdfs:label', $package_name.' '.$release_name );
+ $res->setProp('doap:revision', $release_name );
+
+ rdfutils_setPropToXSDdateTime($res, 'dcterms:created', date('c', $this->getReleaseDate()));
+
+ $res->setProp('dcterms:description', $this->getNotes());
+
+ $res->setProp('schema:releaseNotes', $this->getChanges());
+
+ $projecturi = util_make_url ('/projects/'. $projectname .'/#project');
+
+ rdfutils_setPropToUri($res, 'admssw:project', $projecturi);
+
+ rdfutils_setPropToUri($res, 'dcterms:publisher', $projecturi);
+
+ rdfutils_setPropToUri($res, 'adms:relatedWebPage', util_make_url ('/frs/shownotes.php?release_id='.$this->getID()) );
+
+ rdfutils_setPropToUri($res, 'dcterms:isPartOf', util_make_url ('/projects#repo'));
+
+ $file_uris = array();
+ $frs_files = $this->getFiles();
+ foreach($frs_files as $frs_file) {
+ $file_uris[] = $frs_file->getUri();
+ }
+ rdfutils_setPropToUri($res, 'admssw:package', $file_uris);
+
+ $count = $graph->addTriples( ARC2::getTriplesFromIndex($res->index) );
+
+ foreach($frs_files as $frs_file) {
+ $frs_file->saveToGraph($graph);
+ }
+
+ }
+}
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>
/**
* admsswPlugin Class
*
- * Copyright 2012, Olivier Berger & Institut Mines-Telecom
+ * Copyright 2012-2013, Olivier Berger & Institut Mines-Telecom
+ * Copyright 2013, Roland Mas
*
* This file is part of FusionForge. FusionForge is free software;
* you can redistribute it and/or modify it under the terms of the
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+// This Plugin publishes meta-data about the public projects hosted on the forge
+// as RDF conforming to the ADMS.SW 1.0 specifications :
+// https://joinup.ec.europa.eu/asset/adms_foss/release/release100
-//require_once('common/include/ProjectManager.class.php');
-//require_once('common/include/rdfutils.php');
+require_once('common/include/TroveCat.class.php');
+require_once('common/frs/FRSFileType.class.php');
+require_once $gfplugins.'admssw/common/RDFedFRSPackage.class.php' ;
+require_once('common/include/rdfutils.php');
+include_once("Graphite.php");
class admsswPlugin extends Plugin {
+
+ //var $trovecat_id_index; // cat_id to TroveCat instances
+ var $trovecat_id_to_shortname; // cat_id to shortname
+ var $trovecat_id_to_path; // cat_id to path
+
+ /**
+ * Constructor
+ *
+ * @param number $id plugin identifier
+ */
public function __construct($id=0) {
$this->Plugin($id) ;
$this->name = "admssw";
$this->text = "ADMS.SW"; // To show in the tabs, use...
+
+ // The standard RDF namespaces that will be used in the plugin
+ $this->ns = array(
+ '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/',
+ 'admssw' => 'http://purl.org/adms/sw/',
+ 'adms' => 'http://www.w3.org/ns/adms#',
+ 'foaf' => 'http://xmlns.com/foaf/0.1/',
+ 'schema' => 'http://schema.org/',
+ 'rad' => 'http://www.w3.org/ns/rad#'
+ );
+
+ //$this->trovecat_id_index = array();
+ $this->trovecat_id_to_shortname = array();
+ $this->trovecat_id_to_path = array();
+
+ // Add the doaprdf plugin's namespaces
+ $doaprdfplugin = plugin_get_object ("doaprdf");
+ $ns = $doaprdfplugin->doapNameSpaces();
+ foreach($ns as $s => $u)
+ {
+ if (! in_array($u, $this->ns)) {
+ $this->ns[$u] = $s;
+ }
+ }
$this->_addHook("project_rdf_metadata"); // will provide some RDF metadata for the project's DOAP profile to 'doaprdf' plugin
- $this->_addHook("alt_representations");
- $this->_addHook("script_accepted_types");
- $this->_addHook("content_negociated_projects_list");
+ $this->_addHook("alt_representations"); // declares a link to itself in the link+meta HTML headers of /projects and /softwaremap
+ $this->_addHook("script_accepted_types"); // supported alternate content-types (Accept HTTP header values)
+ $this->_addHook("content_negociated_projects_list"); // registers to be able to return content-negociated content for /projects/...
+ $this->_addHook("softwaremap_links"); // display additional submenu in the softwaremap tool
+ $this->_addHook("project_after_description"); // displays additional info in the project info widget
+ $this->_addHook("content_negociated_trove_list"); // generates the RDF document containing the trove categories as SKOS
+ $this->_addHook("content_negociated_frs_index"); // generates the public projects list/index as RDF
+ $this->_addHook("content_negociated_frs_download_file"); // generates the RDF meta-data about a FRS downloadable file
}
+ //
+ // General conneg related or other hook callbacks
+ //
+
+ /**
+ * Declares itself as accepting RDF XML or Turtle on /projects and other scripts ...
+ *
+ * @param unknown_type $params
+ */
+ public function script_accepted_types (&$params) {
+ $script = $params['script'];
+ if ($script == 'projects_list' || $script == 'admssw_full' || $script == 'trove_list' || $script == 'frs_index' || $script == 'frs_download_file') {
+ $params['accepted_types'][] = 'application/rdf+xml';
+ $params['accepted_types'][] = 'text/turtle';
+ }
+ }
/**
- * Declares itself as accepting RDF XML on /projects/...
+ * Declares a link to itself in the link+meta HTML headers of /projects and /softwaremap
+ *
* @param unknown_type $params
*/
- function project_rdf_metadata (&$params) {
+ public function alt_representations (&$params) {
+ $script_name = $params['script_name'];
+ $php_self = $params['php_self'];
+ if ($php_self == '/softwaremap/trove_list.php') {
+ $params['return'][] = '<link rel="alternate" type="application/rdf+xml" title="ADMS.SW RDF Data" href="'. util_make_url ("/plugins/admssw/trove.php") .'"/>';
+ $params['return'][] = '<link rel="alternate" type="text/turtle" title="ADMS.SW RDF Data" href="'. util_make_url ("/plugins/admssw/trove.php") .'"/>';
+ }
+ elseif ($script_name == '/softwaremap') {
+ $params['return'][] = '<link rel="alternate" type="application/rdf+xml" title="ADMS.SW RDF Data" href="'. util_make_url ("/projects") .'"/>';
+ $params['return'][] = '<link rel="alternate" type="text/turtle" title="ADMS.SW RDF Data" href="'. util_make_url ("/projects") .'"/>';
+ }
+ else if($script_name == '/projects') {
+ $params['return'][] = '<link rel="alternate" type="application/rdf+xml" title="ADMS.SW RDF Data" href="'. util_make_url ($php_self) .'"/>';
+ $params['return'][] = '<link rel="alternate" type="text/turtle" title="ADMS.SW RDF Data" href="'. util_make_url ($php_self) .'"/>';
+ }
+ }
+
+ /**
+ * Add a new link to the softwaremap submenu
+ *
+ * @param array $params
+ */
+ public function softwaremap_links (&$params) {
+
+ $params['TITLES'][] = _('ADMS.SW meta-data');
+ $params['URLS'][] = '/plugins/'. $this->name .'/index.php';
+ $params['ATTRS'][] = array('title' => _('ADMS.SW RDF meta-data about forge projects.'), 'class' => 'tabtitle');
+ }
+
+ /**
+ * Add a line in the project infos widget in the project home
+ *
+ * @param array $params
+ */
+ public function project_after_description (&$params) {
+ $group_id = $params['group_id'];
+ print '<br />'. sprintf( _('Preview <a href="%1$s">ADMS.SW meta-data</a> about the project'), util_make_url ('/plugins/'. $this->name .'/projectturtle.php?group_id='.$group_id));
+ }
+
+
+ //
+ // Utility functions
+ //
+
+ /**
+ * Returns namespaces used in ADMS.SW
+ *
+ * @return array the namespaces associative array
+ */
+ private function admsswNameSpaces() {
+ return $this->ns;
+ }
- # TODO : create another resource
- $group_id=$params['group'];
+ /**
+ * Initialize Graphite graph's namespaces
+ */
+ private function graphSetAdmsswNameSpaces(&$graph) {
+ $ns = $this->admsswNameSpaces();
+ foreach($ns as $s => $u)
+ {
+ $graph->ns( $s, $u );
+ }
+ }
+
+ static function repositoryUri() {
+ return util_make_url ('/projects#repo');
+ }
+
+ //
+ // Project related methods and callbacks
+ //
+
+ /**
+ * Provides an HTML preview of a project's ADMS.SW meta-data looking like turtle
+ *
+ * @param int $group_id
+ */
+ public function htmlPreviewProjectAsTurtle($group_id) {
- $new_prefixes = array('admssw' => 'http://purl.org/adms/sw/',
- 'rad' => 'http://www.w3.org/ns/radion#',
- 'schema' => 'http://schema.org/');
+ $detailed = true;
+
+ $graph = new Graphite();
+
+ $this->graphSetAdmsswNameSpaces($graph);
+
+ $resourceindex = $this->addProjectResourceToGraph($graph, $group_id, $detailed);
+
+ return $graph->dump();
+ }
+
+ /**
+ * Provides an ARC2 resource index of a project's ADMS.SW meta-data
+ *
+ * @param int $group_id
+ */
+ private function addProjectResourceToGraph(&$graph, $group_id, $detailed = false) {
+
+ // part of the work is done by the doaprdf plugin, which will in turn call us back (see project_rdf_metadata)
+ $doaprdfplugin = plugin_get_object ("doaprdf");
+
+ $ns = $this->admsswNameSpaces();
+
+ $resourceindex = $doaprdfplugin->getProjectResourceIndex($group_id, $ns, $detailed);
+
+ // update the namespaces if they happen to get updated in between
+ foreach($ns as $s => $u)
+ {
+ if (! in_array($u, $this->ns)) {
+ $this->ns[$u] = $s;
+ }
+ }
+
+ $count = $graph->addTriples( ARC2::getTriplesFromIndex($resourceindex) );
+
+ return $graph;
+ }
+
+ /**
+ * Improves the DOAP description made by doaprdf (ARC2 resource) to add ADMS.SW meta-data for a project
+ *
+ * @param unknown_type $params
+ *
+ * This is a hook callback so part of the resource construction is made in the doaprdf plugin
+ */
+ public function project_rdf_metadata (&$params) {
+
+ # TODO : check that the passed in_Resource is indeed a doap:Project
+ $group_id = $params['group'];
+
+ // Update the prefixes by ADMS.SW ones
+ $new_prefixes = $this->admsswNameSpaces();
foreach($new_prefixes as $s => $u)
{
if (! isset($params['prefixes'][$u])) {
$params['prefixes'][$u] = $s;
}
}
-
+
+ $detailed = false;
+ if ($params['details'] == 'full') {
+ $detailed = true;
+ }
+
+ // The ARC2 RDF_Resource already initialized by doaprdf plugin
$res = $params['in_Resource'];
// we could save the type doap:Project in such case, as there's an equivalence, but not sure all consumers do reasoning
$types = array('doap:Project', 'admssw:SoftwareProject');
rdfutils_setPropToUri($res, 'rdf:type', $types);
+
+ // Handle project tags
$tags_list = NULL;
if (forge_get_config('use_project_tags')) {
$group = group_get_object($group_id);
// connect to FusionForge internals
$pm = ProjectManager::instance();
$project = $pm->getProject($group_id);
-
$tags = array();
if($tags_list) {
$tags = split(', ',$tags_list);
if($project_description) {
// it seems that doap:description is not equivalent to dcterms:description, so repeat
$res->setProp('dcterms:description', $project_description);
+ }
+
+ // Handle trove categories
+ $trovecaturis=array('admssw:intendedAudience' => array(),
+ 'admssw:locale' => array(),
+ 'admssw:userInterfaceType' => array(),
+ 'admssw:programmingLanguage' => array(),
+ 'schema:operatingSystem' => array(),
+ 'admssw:status' => array(),
+ 'rad:theme' => array());
+ $trovecats = TroveCat::getProjectCats($group_id);
+ foreach($trovecats as $trovecat) {
+ $cat_id = $trovecat->getId();
+ if(!isset($this->trovecat_id_to_shortname[$cat_id])) {
+ $this->trovecat_id_to_shortname[$cat_id] = $trovecat->getShortName();
}
-
+ $idsfullpath = $trovecat->getIdsFullPath();
+ $folders_ids = explode(" :: ", $idsfullpath);
+ $paths = array();
+ foreach ($folders_ids as $id) {
+ if (! isset($this->trovecat_id_to_shortname[$id])) {
+ $supercat = new TroveCat($id);
+ $this->trovecat_id_to_shortname[$id] = $supercat->getShortName();
+ }
+ $paths[] = $this->trovecat_id_to_shortname[$id];
+ }
+ $path=implode('/', $paths);
+ $this->trovecat_id_to_path[$cat_id] = $path;
+ $trovecaturi = util_make_url ('/softwaremap/trove/'.$path);
+ $rootcatid = $trovecat->getRootCatId();
+ $rootcatshortname = $this->trovecat_id_to_shortname[$rootcatid];
+ // This is a bit hackish
+ switch ($rootcatshortname) {
+ case 'developmentstatus':
+ $trovecaturis['admssw:status'][] = $trovecaturi;
+ break;
+ case 'audience':
+ $trovecaturis['admssw:intendedAudience'][] = $trovecaturi;
+ break;
+ case 'license':
+ $trovecaturis['dcterms:license'][] = $trovecaturi;
+ break;
+ case 'natlanguage':
+ $trovecaturis['admssw:locale'][] = $trovecaturi;
+ break;
+ case 'os':
+ $trovecaturis['schema:operatingSystem'][] = $trovecaturi;
+ break;
+ case 'language':
+ $trovecaturis['admssw:programmingLanguage'][] = $trovecaturi;
+ break;
+ default:
+ $trovecaturis['rad:theme'][] = $trovecaturi;
+ break;
+ }
+ }
+ foreach ($trovecaturis as $prop => $uris) {
+ if (count($uris)) {
+ rdfutils_setPropToUri($res, $prop, $uris);
+ }
+ }
+
$res->setProp('rdfs:comment', "Generated with the doaprdf and admssw plugins of fusionforge");
- rdfutils_setPropToUri($res, 'dcterms:isPartOf', util_make_url ("/projects"));
+ rdfutils_setPropToUri($res, 'dcterms:isPartOf', admsswPlugin::repositoryUri());
+ // Handle project members
$admins = $project->getAdmins() ;
$members = $project->getUsers() ;
$contributors_uris = array();
-
foreach ($admins as $u) {
$contributor_uri = util_make_url_u ($u->getUnixName(),$u->getID());
$contributor_uri = rtrim($contributor_uri, '/');
}
rdfutils_setPropToUri($res, 'schema:contributor', $contributors_uris);
+ // Handle FRS releases
+ $release_uris = array();
+ $frs_packages = get_rdfed_frs_packages($project);
+ foreach ($frs_packages as $frs_package) {
+ //print_r($frs_package);
+
+ if($frs_package->isPublic() && $frs_package->getStatus() == 1) {
+ $package_name = $frs_package->getFileName();
+
+ $frs_releases = $frs_package->getReleases();
+ foreach ($frs_releases as $frs_release) {
+ if( $frs_release->getStatus() == 1 ) {
+ //print_r($frs_release);
+ $release_uris[] = $frs_release->getUri();
+ }
+ }
+ }
+ }
+ if(count($release_uris)) {
+ rdfutils_setPropToUri($res, 'doap:release', $release_uris);
+ }
+ // The releases aren't discoverable by follow your nose yet, so add the proper document/script URL to use
+ rdfutils_setPropToUri($res, 'rdfs:seeAlso', util_make_url ('/frs/?group_id='.$group_id));
+
$params['out_Resources'][] = $res;
+
+ if ($detailed) {
+ $graph = new Graphite();
+ $this->graphSetAdmsswNameSpaces($graph);
+
+ $this->addProjectFrsResourcesToGraph($graph, $group_id);
+
+ $subjects = $graph->allSubjects();
+ foreach ($subjects as $subject) {
+ $resource = $graph->resource( $subject );
+ $triples = $resource->toArcTriples();
+
+ $index = ARC2::getSimpleIndex($triples, false);
+
+ $res = ARC2::getResource();
+ $res->setIndex($index);
+
+ $params['out_Resources'][] = $res;
+ }
+ }
+
}
+ //
+ // Project list / SoftwareRepository related methods
+ //
+
/**
- * Declares a link to itself in the link+meta HTML headers
- * @param unknown_type $params
+ * Provides a Graphite graph for resource(s) representing the ADMS.SW SoftwareRepository
+ *
+ * @param string URI of the document to use
+ * @param bool are projects to be fully described or just a URI of their resource
*/
- function alt_representations (&$params) {
- $script_name = $params['script_name'];
- $php_self = $params['php_self'];
- $php_self = rtrim($php_self, '/');
- if ($php_self == '/projects') {
- $params['return'][] = '<link rel="meta" type="application/rdf+xml" title="ADMS.SW RDF Data" href=""/>';
- $params['return'][] = '<link rel="meta" type="text/turtle" title="ADMS.SW RDF Data" href=""/>';
+ public function getProjectListResourcesGraph($documenturi, $detailed=false) {
+
+ // Construct an ARC2_Resource containing the project's RDF (DOAP) description
+ $ns = $this->admsswNameSpaces();
+
+ $conf = array(
+ 'ns' => $ns
+ );
+
+ $res = ARC2::getResource($conf);
+ $res->setURI( admsswPlugin::repositoryUri() );
+
+ // $res->setRel('rdf:type', 'admssw:SoftwareRepository');
+ rdfutils_setPropToUri($res, 'rdf:type', 'admssw:SoftwareRepository');
+
+ //$res->setProp('doap:name', $projectname);
+ rdfutils_setPropToUri($res, 'adms:accessURL', util_make_url ("/softwaremap/") );
+ $forge_name = forge_get_config ('forge_name');
+ $ff = new FusionForge();
+ $res->setProp('dcterms:description', 'Public projects in the '. $ff->software_name .' Software Map on '. $forge_name );
+ $res->setProp('rdfs:label', $forge_name .' public projects');
+ $res->setProp('adms:supportedSchema', 'ADMS.SW v1.0');
+
+ // same as for trove's full list
+ $projects = get_public_active_projects_asc();
+ $proj_uris = array();
+ foreach ($projects as $row_grp) {
+ $proj_uri = util_make_url_g(strtolower($row_grp['unix_group_name']),$row_grp['group_id']).'#project';
+ $proj_uris[] = $proj_uri;
+ }
+ if(count($proj_uris)) {
+ rdfutils_setPropToUri($res, 'dcterms:hasPart', $proj_uris);
}
+
+ $graph = new Graphite();
+ $this->graphSetAdmsswNameSpaces($graph);
+
+ $count = $graph->addTriples( ARC2::getTriplesFromIndex($res->index) );
+
+ // if needed, provide also full details about the projects
+ foreach ($projects as $row_grp) {
+ $group_id = $row_grp['group_id'];
+ //$proj_uri = util_make_url_g(strtolower($row_grp['unix_group_name']),$row_grp['group_id']);
+ $count = $this->addProjectResourceToGraph($graph, $row_grp['group_id'], $detailed);
+ }
+
+ $this->graphSetAdmsswNameSpaces($graph);
+
+ // The document the document itself
+ $res = ARC2::getResource($conf);
+ $res->setURI( $documenturi );
+ rdfutils_setPropToUri($res, 'rdf:type', 'foaf:Document');
+ rdfutils_setPropToUri($res, 'foaf:primaryTopic', admsswPlugin::repositoryUri() );
+ rdfutils_setPropToXSDdateTime($res, 'dcterms:created', date('c'));
+ $res->setProp('dcterms:title', "ADMS.SW full dump" );
+
+ $count = $graph->addTriples( ARC2::getTriplesFromIndex($res->index) );
+
+ return $graph;
}
-
/**
- * Declares itself as accepting RDF XML on /projects ...
- * @param unknown_type $params
+ * Provides an HTML preview of the ADMS.SW SoftwareRepository meta-data looking like turtle
+ *
+ * @param int $group_id
*/
- function script_accepted_types (&$params) {
- $script = $params['script'];
- if ($script == 'projects_list') {
- $params['accepted_types'][] = 'application/rdf+xml';
- $params['accepted_types'][] = 'text/turtle';
- }
+ public function htmlPreviewProjectsAsTurtle() {
+ $graph = $this->getProjectListResourcesGraph(util_make_url ("/projects"));
+
+ return $graph->dump();
}
/**
* Outputs the public projects list as ADMS.SW for /projects
+ *
* @param unknown_type $params
*/
- function content_negociated_projects_list (&$params) {
+ public function content_negociated_projects_list (&$params) {
$accept = $params['accept'];
-
+
+ // we are asked for RDF either as RDF+XML or Turtle
if($accept == 'application/rdf+xml' || $accept == 'text/turtle') {
- // We will return RDF+XML
- $params['content_type'] = 'application/rdf+xml';
+ // We will return RDF
+ $params['content_type'] = $accept;
- // Construct an ARC2_Resource containing the project's RDF (DOAP) description
- $ns = array(
- '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/',
- 'admssw' => 'http://purl.org/adms/sw/',
- 'adms' => 'http://www.w3.org/ns/adms#'
- );
+ $graph = $this->getProjectListResourcesGraph(util_make_url ("/projects"));
+
+ if ($accept == 'text/turtle') {
+ $doc = $graph->serialize($serializer="Turtle");
+ }
+ if ($accept == 'application/rdf+xml') {
+ $doc = $graph->serialize();
+ }
+
+ $params['content'] = $doc . "\n";
+
+ }
+ }
- $conf = array(
- 'ns' => $ns
- );
-
- $res = ARC2::getResource($conf);
- $res->setURI( util_make_url ("/projects") );
+ //
+ // Trove related methods
+ //
+
+ /**
+ * Provides a Graphite graph for resource(s) representing the trove categories as SKOS concepts
+ *
+ */
+ private function getTroveListResourcesGraph() {
+
+ // Construct an ARC2_Resource containing the project's RDF (DOAP) description
+ $ns = array(
+ 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
+ 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
+ 'skos' => 'http://www.w3.org/2004/02/skos/core#'
+ );
+
+ $conf = array(
+ 'ns' => $ns
+ );
+
+
+ $graph = new Graphite();
+ $this->graphSetAdmsswNameSpaces($graph);
+
+ $rootcats = TroveCat::getAllRoots();
+
+ foreach($rootcats as $rootcat) {
+
+ // First the ConceptScheme itself
+
+ $conceptschemeres = ARC2::getResource($conf);
+
+ $scheme_shortname = $rootcat->getShortName();
+ $conceptscheme_uri = util_make_url ('/softwaremap/trove/'.$scheme_shortname);
+ $conceptschemeres->setURI( $conceptscheme_uri );
+
// $res->setRel('rdf:type', 'doap:Project');
- rdfutils_setPropToUri($res, 'rdf:type', 'admssw:SoftwareRepository');
-
- //$res->setProp('doap:name', $projectname);
- $res->setProp('adms:accessURL', util_make_url ("/softwaremap/") );
- $forge_name = forge_get_config ('forge_name');
- $ff = new FusionForge();
- $res->setProp('dcterms:description', 'Public projects in the '. $ff->software_name .' Software Map on '. $forge_name );
- $res->setProp('rdfs:label', $forge_name .' public projects');
- $res->setProp('adms:supportedSchema', 'ADMS.SW v1.0');
-
- // same as for trove's full list
- $projects = get_public_active_projects_asc();
- $proj_uris = array();
- foreach ($projects as $row_grp) {
- $proj_uri = util_make_url_g(strtolower($row_grp['unix_group_name']),$row_grp['group_id']);
- $proj_uris[] = $proj_uri;
- }
- if(count($proj_uris)) {
- rdfutils_setPropToUri($res, 'dcterms:hasPart', $proj_uris);
- }
-
- $conf = array(
- 'ns' => $ns,
- 'serializer_type_nodes' => true
- );
-
- if($accept == 'application/rdf+xml') {
- $ser = ARC2::getRDFXMLSerializer($conf);
- }
- else {
- // text/turtle
- $ser = ARC2::getTurtleSerializer($conf);
- }
- /* Serialize a resource index */
- $doc = $ser->getSerializedIndex($res->index);
+ rdfutils_setPropToUri($conceptschemeres, 'rdf:type', 'skos:ConceptScheme');
+
+ $conceptschemeres->setProp('skos:prefLabel', $rootcat->getFullName());
+ $conceptschemeres->setProp('skos:definition', $rootcat->getDescription());
+
+ $count = $graph->addTriples( ARC2::getTriplesFromIndex($conceptschemeres->index) );
+
+
+ $subcats = $rootcat->listSubTree();
+
+ // memorize a few indexes
+
+ foreach($subcats as $subcat) {
+ $cat_id = $subcat->getId();
+ //$this->trovecat_id_index[$cat_id] = &$subcat;
+
+ $this->trovecat_id_to_shortname[$cat_id] = $subcat->getShortName();
+ }
+
+ foreach($subcats as $subcat) {
+ $cat_id = $subcat->getId();
+
+ $idsfullpath = $subcat->getIdsFullPath();
+
+ $folders_ids = explode(" :: ", $idsfullpath);
+
+ $paths = array();
+ foreach ($folders_ids as $id) {
+ if (isset($this->trovecat_id_to_shortname[$id])) {
+ $paths[] = $this->trovecat_id_to_shortname[$id];
+ }
+ }
+ $path=implode('/', $paths);
+
+ $this->trovecat_id_to_path[$cat_id] = $path;
+ }
+
+ // Now, for all Concepts in this ConceptScheme
+
+ foreach($subcats as $subcat) {
+ $conceptres = ARC2::getResource($conf);
+
+ $path = $this->trovecat_id_to_path[$subcat->getId()];
+ $conceptres->setURI( util_make_url ('/softwaremap/trove/'.$scheme_shortname.'/'.$path) );
+
+ // $res->setRel('rdf:type', 'doap:Project');
+ rdfutils_setPropToUri($conceptres, 'rdf:type', 'skos:Concept');
+
+ rdfutils_setPropToUri($conceptres, 'skos:inScheme', $conceptscheme_uri);
+
+ $conceptres->setProp('skos:prefLabel', $subcat->getFullName());
+ $conceptres->setProp('skos:definition', $subcat->getDescription());
+
+ $parentid = $subcat->getParentId();
+ $rootparentid = $subcat->getRootCatId();
+
+ if ($parentid != $rootparentid) {
+ $parentpath = $this->trovecat_id_to_path[$parentid];
+ rdfutils_setPropToUri($conceptres, 'skos:broader', util_make_url ('/softwaremap/trove/'.$scheme_shortname.'/'.$parentpath) );
+ }
+
+ $count = $graph->addTriples( ARC2::getTriplesFromIndex($conceptres->index) );
+ }
+
+ }
+
+ return $graph;
+ }
+
+ /**
+ * Provides an HTML preview of the trove categories as SKOS looking like turtle
+ *
+ */
+ public function htmlPreviewTroveCatsAsTurtle() {
+ $graph = $this->getTroveListResourcesGraph();
+
+ return $graph->dump();
+ }
+
+ /**
+ * Outputs the trove categories as SKOS
+ *
+ * @param unknown_type $params
+ */
+ public function content_negociated_trove_list (&$params) {
+
+ $accept = $params['accept'];
+
+ // we are asked for RDF either as RDF+XML or Turtle
+ if($accept == 'application/rdf+xml' || $accept == 'text/turtle') {
+
+
+ // We will return RDF
+ $params['content_type'] = $accept;
+
+ $graph = $this->getTroveListResourcesGraph();
+ if ($accept == 'text/turtle') {
+ $doc = $graph->serialize($serializer="Turtle");
+ }
+ if ($accept == 'application/rdf+xml') {
+ $doc = $graph->serialize();
+ }
+
$params['content'] = $doc . "\n";
+
+ }
+ }
+
+
+ //
+ // FRS related methods
+ //
+
+ /**
+ * Add RDF resources to a Graphite graph for the File Release system
+ *
+ * @param Graphite graph to be updated
+ * @param int group id
+ * @param int optional release id
+ */
+ private function addProjectFrsResourcesToGraph(&$graph, $group_id, $release_id = false) {
+ $group = &group_get_object($group_id);
+
+ // if we are passed a release ID, then only process that particular release
+ if($release_id) {
+
+ $frs_release = rdfed_frsrelease_get_object($release_id);
+
+ // Don't produce RDF for hidden releases
+ if( $frs_release->getStatus() == 1 ) {
+ $frs_package = $frs_release->getFRSPackage();
+
+ // Only produce RDF for releases of public and not hidden packages
+ if ($frs_package->isPublic() && $frs_package->getStatus() == 1) {
+
+ $frs_release->saveToGraph($graph);
+
+ }
+ }
}
+ else {
+ // then produce RDF for all the project's packages
+ $frs_packages = get_rdfed_frs_packages($group);
+
+ foreach($frs_packages as $frs_package) {
+ // well actually, only for public and not hidden packages
+ if ($frs_package->isPublic() && $frs_package->getStatus() == 1) {
+
+ $frs_package->saveToGraph($graph);
+ }
+ }
+ }
+ return $graph;
+
}
+
+ /**
+ * Outputs the public projects releases as ADMS.SW for /frs
+ *
+ * @param unknown_type $params
+ */
+ public function content_negociated_frs_index (&$params) {
+ $accept = $params['accept'];
+
+ // we are asked for RDF either as RDF+XML or Turtle
+ if($accept == 'application/rdf+xml' || $accept == 'text/turtle') {
+
+
+ // We will return RDF
+ $params['content_type'] = $accept;
+
+ $group_id = $params['group_id'];
+ $release_id = $params['release_id'];
+
+ $graph = new Graphite();
+ $this->graphSetAdmsswNameSpaces($graph);
+
+ $this->addProjectFrsResourcesToGraph($graph, $group_id, $release_id);
+
+ if ($accept == 'text/turtle') {
+ $doc = $graph->serialize($serializer="Turtle");
+ }
+ if ($accept == 'application/rdf+xml') {
+ $doc = $graph->serialize();
+ }
+
+ $params['content'] = $doc . "\n";
+
+ }
+ }
+
+ /**
+ * Outputs the public downloadable files as ADMS.SW SoftwarePackages for /frs/download.php...
+ *
+ * @param unknown_type $params
+ */
+ public function content_negociated_frs_download_file (&$params) {
+
+ $accept = $params['accept'];
+
+ // we are asked for RDF either as RDF+XML or Turtle
+ if($accept == 'application/rdf+xml' || $accept == 'text/turtle') {
+
+ // We will return RDF
+ $params['content_type'] = $accept;
+
+ $file_id = $params['file_id'];
+
+ $frs_file = rdfed_frsfile_get_object($file_id);
+ if (!$frs_file) {
+ session_redirect404();
+ }
+
+ $frs_release = $frs_file->getFRSRelease();
+ $frs_package = $frs_release->getFRSPackage();
+ $group = $frs_package->getGroup();
+
+ $graph = new Graphite();
+ $this->graphSetAdmsswNameSpaces($graph);
+
+ // We only accept files in public and non-hidden project's packages
+ if ($frs_package->isPublic() && $frs_package->getStatus() == 1) {
+ $frs_file->saveToGraph($graph);
+ }
+
+ if ($accept == 'text/turtle') {
+ $doc = $graph->serialize($serializer="Turtle");
+ }
+ if ($accept == 'application/rdf+xml') {
+ $doc = $graph->serialize();
+ }
+
+ $params['content'] = $doc . "\n";
+
+ }
+ }
}
// Local Variables:
--- /dev/null
+<?php
+/**
+ * admssw plugin script which produces a full list of public projects with all their details
+*
+* This file is (c) Copyright 2012 by Olivier BERGER, Institut Mines-Telecom
+*
+* This file is part of FusionForge. FusionForge is free software;
+* you can redistribute it and/or modify it under the terms of the
+* GNU General Public License as published by the Free Software
+* Foundation; either version 2 of the Licence, or (at your option)
+* any later version.
+*
+* FusionForge is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License along
+* with FusionForge; if not, write to the Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+require_once('../../env.inc.php');
+require_once $gfcommon.'include/pre.php';
+
+$pluginname = 'admssw';
+
+$script = 'admssw_full';
+$default_content_type = 'text/html';
+
+// check for alternate representations (RDF content-types)
+$content_type = util_negociate_alternate_content_types($script, $default_content_type);
+
+$plugin = plugin_get_object($pluginname);
+
+// if not HTML
+if($content_type != $default_content_type) {
+
+ // process as in content_negociated_projects_list but with full details
+ $graph = $plugin->getProjectListResourcesGraph(util_make_url('/plugins/'.$pluginname.'/full.php'), true);
+
+ // We can support only RDF as RDF+XML or Turtle
+ if ($content_type == 'text/turtle' || $content_type == 'application/rdf+xml') {
+ header('Content-type: '. $content_type);
+ if ($content_type == 'text/turtle') {
+ print $graph->serialize($serializer="Turtle")."\n";
+ }
+ if ($content_type == 'application/rdf+xml') {
+ print $graph->serialize()."\n";
+ }
+ }
+ else {
+ header('HTTP/1.1 406 Not Acceptable',true,406);
+ print $graph->dumpText();
+ exit(0);
+ }
+} else {
+ $HTML->header(array('title'=>_('Full ADMS.SW export'),'pagename'=>'admssw_full'));
+ $HTML->printSoftwareMapLinks();
+
+ echo '<p>'. _('This script is meant to produce machine-readable RDF meta-data, in Turtle or RDF/XML formats, which can be obtained with, for instance:').'<br />';
+
+ $graph = $plugin->getProjectListResourcesGraph(util_make_url('/plugins/'.$pluginname.'/full.php'), true);
+
+ print $graph->dump();
+
+ echo _('To access this RDF document, you may use, for instance :<br />');
+ echo '<tt>$ curl -H "Accept: text/turtle" '. util_make_url('/plugins/'.$pluginname.'/full.php') .'</tt>';
+
+ $HTML->footer(array());
+}
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * admssw plugin main script
+*
+* This file is (c) Copyright 2012 by Olivier BERGER, Institut Mines-Telecom
+*
+* This file is part of FusionForge. FusionForge is free software;
+* you can redistribute it and/or modify it under the terms of the
+* GNU General Public License as published by the Free Software
+* Foundation; either version 2 of the Licence, or (at your option)
+* any later version.
+*
+* FusionForge is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License along
+* with FusionForge; if not, write to the Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+require_once('../../env.inc.php');
+require_once $gfcommon.'include/pre.php';
+
+/* FIXME
+* Parameters:
+* $gwords = target words to search
+* $gexact = 1 for search ing all words (AND), 0 - for any word (OR)
+* $otherfreeknowledge = 1 for search in Free/Libre Knowledge Gforge Initiatives
+* $order = "project_title" or "title" - criteria for ordering results: if empty or not allowed results are ordered by rank
+*
+*/
+
+$pluginname = 'admssw';
+
+$HTML->header(array('title'=>_('ADMS.SW'),'pagename'=>'admssw'));
+$HTML->printSoftwareMapLinks();
+
+echo '<p>'._('Preview of RDF meta-data about the forge, conforming to the ADMS.SW specifications').'</p>';
+
+echo '<ul>';
+echo '<li>'._('Public projects :');
+
+ echo '<ul>';
+ echo '<li>'.util_make_link('/plugins/'.$pluginname.'/projectsturtle.php', _('short index')).', '.
+ _('or '). util_make_link('/plugins/'.$pluginname.'/full.php', _('full dump')) . _(' (as Turtle)').'</li>';
+ //echo '<li>'.util_make_link('/plugins/'.$pluginname.'/projectsrdfxml.php', _('as RDF+XML')).'</li>';
+ echo '</ul>';
+
+echo '</li>';
+
+echo '<li>'._('Trove categories :');
+
+echo '<ul>';
+echo '<li>'.util_make_link('/plugins/'.$pluginname.'/trove.php', _('as Turtle')).'</li>';
+echo '</ul>';
+
+echo '</li>';
+
+echo '</ul>';
+
+$HTML->footer(array());
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * admssw plugin script which displays an HTML preview of the projects list as Turtle
+*
+* This file is (c) Copyright 2012 by Olivier BERGER, Institut Mines-Telecom
+*
+* This file is part of FusionForge. FusionForge is free software;
+* you can redistribute it and/or modify it under the terms of the
+* GNU General Public License as published by the Free Software
+* Foundation; either version 2 of the Licence, or (at your option)
+* any later version.
+*
+* FusionForge is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License along
+* with FusionForge; if not, write to the Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+require_once('../../env.inc.php');
+require_once $gfcommon.'include/pre.php';
+
+/* FIXME
+* Parameters:
+* $gwords = target words to search
+* $gexact = 1 for search ing all words (AND), 0 - for any word (OR)
+* $otherfreeknowledge = 1 for search in Free/Libre Knowledge Gforge Initiatives
+* $order = "project_title" or "title" - criteria for ordering results: if empty or not allowed results are ordered by rank
+*
+*/
+
+$pluginname = 'admssw';
+
+$HTML->header(array('title'=>_('ADMS.SW meta-data index of public projects'),'pagename'=>'admssw'));
+$HTML->printSoftwareMapLinks();
+
+$plugin = plugin_get_object ($pluginname);
+
+echo '<p>'. sprintf( _('The following is a preview of the (machine-readable) RDF meta-data which can be obtained at <tt>%1$s</tt> as Turtle'), util_make_url('/projects/')) .'</p>';
+
+echo $plugin->htmlPreviewProjectsAsTurtle();
+
+echo _('To access this RDF document, you may use, for instance :<br />');
+echo '<tt>$ curl -H "Accept: text/turtle" '. util_make_url('/projects/') .'</tt><br />';
+
+$HTML->footer(array());
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * admssw plugin script which displays an HTML preview of a project metadata as Turtle
+*
+* This file is (c) Copyright 2012 by Olivier BERGER, Institut Mines-Telecom
+*
+* This file is part of FusionForge. FusionForge is free software;
+* you can redistribute it and/or modify it under the terms of the
+* GNU General Public License as published by the Free Software
+* Foundation; either version 2 of the Licence, or (at your option)
+* any later version.
+*
+* FusionForge is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License along
+* with FusionForge; if not, write to the Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+require_once('../../env.inc.php');
+require_once $gfcommon.'include/pre.php';
+
+/* FIXME
+* Parameters:
+* $gwords = target words to search
+* $gexact = 1 for search ing all words (AND), 0 - for any word (OR)
+* $otherfreeknowledge = 1 for search in Free/Libre Knowledge Gforge Initiatives
+* $order = "project_title" or "title" - criteria for ordering results: if empty or not allowed results are ordered by rank
+*
+*/
+
+$pluginname = 'admssw';
+
+$group_id = getIntFromRequest ('group_id') ;
+
+session_require_perm ('project_read', $group_id) ;
+
+$group = &group_get_object($group_id);
+$projectname = $group->getUnixName();
+
+site_project_header(array('title'=>_('ADMS.SW project meta-data preview'), 'h1' => '', 'group'=>$group_id, 'toptab' => 'home', 'pagename'=>'projectturtle'));
+
+$plugin = plugin_get_object($pluginname);
+
+echo '<p>'. sprintf( _('The following is a preview of the (machine-readable) RDF meta-data which can be obtained at <tt>%1$s</tt> as Turtle'), util_make_url_g($projectname, $group_id)) .'</p>';
+
+echo $plugin->htmlPreviewProjectAsTurtle($group_id);
+
+echo _('To access this RDF document, you may use, for instance :<br />');
+echo '<tt>$ curl -H "Accept: text/turtle" '. util_make_url_g($projectname, $group_id) .'</tt><br />';
+
+$HTML->footer(array());
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * admssw plugin script which displays an HTML preview of the SKOS export of the trove categories, as Turtle
+*
+* This file is (c) Copyright 2012 by Olivier BERGER, Institut Mines-Telecom
+*
+* This file is part of FusionForge. FusionForge is free software;
+* you can redistribute it and/or modify it under the terms of the
+* GNU General Public License as published by the Free Software
+* Foundation; either version 2 of the Licence, or (at your option)
+* any later version.
+*
+* FusionForge is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License along
+* with FusionForge; if not, write to the Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+require_once('../../env.inc.php');
+require_once $gfcommon.'include/pre.php';
+
+/* FIXME
+* Parameters:
+* $gwords = target words to search
+* $gexact = 1 for search ing all words (AND), 0 - for any word (OR)
+* $otherfreeknowledge = 1 for search in Free/Libre Knowledge Gforge Initiatives
+* $order = "project_title" or "title" - criteria for ordering results: if empty or not allowed results are ordered by rank
+*
+*/
+
+$pluginname = 'admssw';
+
+$HTML->header(array('title'=>_('SKOS meta-data for trove categories'),'pagename'=>'trove'));
+$HTML->printSoftwareMapLinks();
+
+$plugin = plugin_get_object ($pluginname);
+
+echo '<p>'. sprintf( _('The following is a preview of the (machine-readable) RDF meta-data which can be obtained at <tt>%1$s</tt> as Turtle'), util_make_url('/softwaremap/trove_list.php')) .'</p>';
+
+echo $plugin->htmlPreviewTroveCatsAsTurtle();
+
+echo _('To access this RDF document, you may use, for instance :<br />');
+echo '<tt>$ curl -H "Accept: text/turtle" '. util_make_url('/softwaremap/trove_list.php') .'</tt><br />';
+
+$HTML->footer(array());
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>
\ No newline at end of file
}
}
+ function doapNameSpaces() {
+ // Construct an ARC2_Resource containing the project's RDF (DOAP) description
+ $ns = array(
+ '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/'
+ );
+ return $ns;
+ }
+
+ function getProjectResourceIndex($group_id, &$ns, $detailed = false) {
+
+ // connect to FusionForge internals
+ $pm = ProjectManager::instance();
+ $project = $pm->getProject($group_id);
+ $projectname = $project->getUnixName();
+ $project_shortdesc = $project->getPublicName();
+ $project_description = $project->getDescription();
+ $tags_list = NULL;
+ if (forge_get_config('use_project_tags')) {
+ $group = group_get_object($group_id);
+ $tags_list = $group->getTags();
+ }
+
+ $conf = array(
+ 'ns' => $ns
+ );
+
+ $res = ARC2::getResource($conf);
+ $res->setURI(util_make_url_g($projectname, $group_id).'#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);
+ }
+ $homepages = array(util_make_url_g($projectname, $group_id));
+ $project_homepage = $project->getHomePage();
+ if(!in_array($project_homepage, $homepages)) {
+ $homepages[] = $project_homepage;
+ }
+ $res->setProp('doap:homepage', $homepages);
+ $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['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();
+ if ($detailed) {
+ $hook_params['details'] = 'full';
+ }
+ else {
+ $hook_params['details'] = 'minimal';
+ }
+ plugin_hook_by_reference('project_rdf_metadata', $hook_params);
+
+ // add new prefixes to the list
+ foreach($hook_params['prefixes'] as $url => $prefix) {
+ if (!isset($ns[$prefix])) {
+ $ns[$prefix] = $url;
+ }
+ }
+
+ // 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);
+ }
+
+ return $merged_index;
+ }
+
/**
* Outputs project's DOAP profile
* @param unknown_type $params
if($accept == 'application/rdf+xml' || $accept == 'text/turtle') {
- // 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')) {
- $group = group_get_object($group_id);
- $tags_list = $group->getTags();
- }
// We will return RDF+XML
- $params['content_type'] = 'application/rdf+xml';
+ $params['content_type'] = $accept;
- // Construct an ARC2_Resource containing the project's RDF (DOAP) description
- $ns = array(
- '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/'
- );
-
- $conf = array(
- 'ns' => $ns
- );
+ $ns = $this->doapNameSpaces();
- $res = ARC2::getResource($conf);
- $res->setURI(util_make_url_g($projectname, $group_id));
+ $merged_index = $this->getProjectResourceIndex($group_id, $ns, $detailed = true);
- // $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['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
- foreach($hook_params['prefixes'] as $url => $prefix) {
- if (!isset($ns[$prefix])) {
- $ns[$prefix] = $url;
- }
- }
-
- // 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);
- }
-
$conf = array(
'ns' => $ns,
'serializer_type_nodes' => true
$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=""/>';
- $params['return'][] = '<link rel="meta" type="test/turtle" title="DOAP RDF Data" href=""/>';
+ $params['return'][] = '<link rel="alternate" type="application/rdf+xml" title="DOAP RDF Data" href=""/>';
+ $params['return'][] = '<link rel="alternate" type="test/turtle" title="DOAP RDF Data" href=""/>';
}
}