getResource() static public method

* resource
static public getResource ( $a = '' )
 public function getResourcePredicates($subject)
 {
     $resource = ARC2::getResource();
     $resource->setStore($this->getStore());
     $resource->setURI($subject);
     $properties = $resource->getProps();
     return $properties;
 }
 function getResource($uri, $store_or_props = '')
 {
     $res = ARC2::getResource($this->a);
     $res->setURI($uri);
     if (is_array($store_or_props)) {
         $res->setProps($store_or_props);
     } else {
         $res->setStore($store_or_props);
     }
     return $res;
 }
Ejemplo n.º 3
0
    return $str;
}
// http://vision-media.ca/resources/php/php-word-limit
function string_limit_words($string, $word_limit)
{
    $words = explode(' ', $string);
    return implode(' ', array_slice($words, 0, $word_limit));
}
$format = isset($_REQUEST['format']) && !empty($_REQUEST['format']) ? $_REQUEST['format'] : 'xml';
$url = @trim($_REQUEST['url']);
if (empty($url)) {
    die('');
}
$ns = array('rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'foaf' => 'http://xmlns.com/foaf/0.1/', 'dc' => 'http://purl.org/dc/elements/1.1/', 'dcterms' => 'http://purl.org/dc/terms/', 'scalar' => 'http://vectorsjournal.org/scalar/elements/1.0/', 'ctag' => 'http://commontag.org/ns#', 'art' => 'http://simile.mit.edu/2003/10/ontologies/artstor#', 'sioc' => 'http://rdfs.org/sioc/ns#', 'sioctypes' => 'http://rdfs.org/sioc/types#', 'foaf' => 'http://xmlns.com/foaf/0.1/', 'owl' => 'http://www.w3.org/2002/07/owl#');
$conf = array('ns' => $ns);
$resource = ARC2::getResource($conf);
$resource->setURI($url);
$resource->setProp('rdf:type', array('value' => 'scalar:External', 'type' => 'uri'));
$resource->setProp('dcterms:title', '');
$resource->setProp('dcterms:description', '');
$contents = @file_get_contents($url);
if ($contents) {
    $title = getTextBetweenTags($contents, 'title');
    if (empty($title)) {
        $title = '';
    }
    $resource->setProp('dcterms:title', trim($title));
    $meta = get_meta_data($contents);
    if (!empty($meta)) {
        $desc = '';
        foreach ($meta as $row) {
Ejemplo n.º 4
0
 /**
  * Return an ARC Helper object around a supplied index
  */
 public function helper($index = '')
 {
     $conf = array('ns' => $this->ns);
     $resource = ARC2::getResource($conf);
     if (!empty($index)) {
         $resource->setIndex($index);
     }
     $resource->setURI(key($index));
     return $resource;
 }
Ejemplo n.º 5
0
 /**
  * Outputs the public projects list as ADMS.SW for /projects
  * @param unknown_type $params
  */
 function content_negociated_projects_list(&$params)
 {
     $accept = $params['accept'];
     if ($accept == 'application/rdf+xml') {
         // We will return RDF+XML
         $params['content_type'] = 'application/rdf+xml';
         // 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#');
         $conf = array('ns' => $ns);
         $res = ARC2::getResource($conf);
         $res->setURI(util_make_url("/projects"));
         // $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);
         $ser = ARC2::getRDFXMLSerializer($conf);
         /* Serialize a resource index */
         $doc = $ser->getSerializedIndex($res->index);
         $params['content'] = $doc . "\n";
     }
 }
Ejemplo n.º 6
0
 public function LoadResourceFromFile($file)
 {
     $this->set_URI_Document($file);
     if (false === ($index = $this->cache->getVar($this->URI_Document, 'Foafpress', time() - filectime($file), 0))) {
         // load arc2 parser
         $parser = ARC2::getRDFParser();
         // parse rdf document
         $parser->parse($this->URI_Document, $this->content->SANDBOX);
         // get rdf content as multi-indexed array
         $index = $parser->getSimpleIndex(0);
         $this->cache->saveVar($index, $this->URI_Document, 'Foafpress', true);
     }
     // load namespaces from config
     $namespaces = array();
     if (isset($this->config['ns'])) {
         $namespaces = $this->config['ns'];
     }
     // load rdf content as arc2 resource
     $this->arc2_resource = ARC2::getResource(array('ns' => $namespaces));
     $this->arc2_resource->setIndex($index);
     $uri = $this->ResolveResourceRequest();
     //die($uri);
     // set shown resource
     $this->arc2_resource->setURI($uri);
     //*
     if ($exporttype = $this->isExportRequest()) {
         if (isset($this->arc2_exportfunctions[$exporttype])) {
             // $this->exportRdfData($exporttype);
             $this->exportRdfData();
         } else {
             $template_type = $this->config['types'][$exporttype];
         }
     }
     //*/
     if (!isset($template_type)) {
         $template_type = $this->config['types'][$this->config['typefallback']];
     }
     // load Foafpress wrapper for arc2 resource
     $FP = new Foafpress_Resource_Arc2File(array('FP_config' => &$this->config, 'spcms_cache' => &$this->cache, 'spcms_pm' => &$this->pm));
     $FP->initResource($this->arc2_resource);
     //$FP->initResource(&$this->arc2_resource);
     // set shown resource
     $FP->uri = $uri;
     // add sameAs resources
     if ($this->config['LinkedData']['followSameas'] == true) {
         $FP->includeSameAs();
     }
     // default namespace in Foafpress wrapper
     $concept = $FP->updateNamespacePrefix();
     // use ns:concept to set controller, and fallbacks for layout and template
     if ($concept !== false && $FP->ns_prefix) {
         // try to set controller
         try {
             $action_controller_class_path = $this->pm->need($FP->ns_prefix . DIRECTORY_SEPARATOR . $concept);
             if (!isset($_SERVER['REQUEST_METHOD']) || !$_SERVER['REQUEST_METHOD']) {
                 $this->dieWithHttpErrorCode('Empty request method!', 503);
                 // TODO is 503 right?
             } elseif (in_array($_SERVER['REQUEST_METHOD'], $this->config['supportedmethods'])) {
                 $action_controller_class_name = ucfirst($FP->ns_prefix . '_' . $concept . '_Controller');
                 $action_controller_use_method = strtolower($_SERVER['REQUEST_METHOD']) . '_request';
                 $action_controller = new $action_controller_class_name($this->sandbox, $action_controller_class_path);
                 // execute controller request action with resource
                 $action_controller->add_resource_object($FP);
                 $action_controller->set_template_extension($template_type);
                 $action_controller->{$action_controller_use_method}();
             } else {
                 $this->dieWithHttpErrorCode($_SERVER['REQUEST_METHOD'] . ' is not supported here!', 503);
                 // TODO is 503 right?
             }
         } catch (Exception $e) {
             throw $e;
         }
         // set layout
         if (isset($this->config['layout'])) {
             $layoutfile = $this->config['layout'];
         } elseif ($this->sandbox->layoutname) {
             $layoutfile = $this->sandbox->layoutname;
         } else {
             $layoutfile = 'Foafpress';
         }
         if ($this->sandbox->templateSearch($layoutfile . $template_type)) {
             // change sandbox layout which was configured before
             $this->sandbox->templateSetLayout($layoutfile . $template_type);
         } else {
             // TODO: line?
             $this->dieWithException($layoutfile . $template_type . '.php not found!');
         }
         // try to set template
         if (!$this->sandbox->templatename) {
             // if not set then its name is namespace/concept.tpl
             $templatefile = $FP->ns_prefix . DIRECTORY_SEPARATOR . $concept . $template_type;
             if ($this->sandbox->templateSearch($templatefile)) {
                 // change sandbox template which was configured before
                 $this->sandbox->templateSetName($templatefile);
             } else {
                 // TODO: line?
                 $this->dieWithException($templatefile . '.php not found!');
             }
         }
     }
     return;
 }
 /**
  * Outputs user's FOAF profile
  * @param unknown_type $params
  */
 function content_negociated_user_home(&$params)
 {
     $username = $params['username'];
     $accept = $params['accept'];
     if ($accept == 'application/rdf+xml') {
         $params['content_type'] = 'application/rdf+xml';
         $user_obj = user_get_object_by_name($username);
         $user_real_name = $user_obj->getRealName();
         $user_email = $user_obj->getEmail();
         $mbox = 'mailto:' . $user_email;
         $mbox_sha1sum = sha1($mbox);
         $projects = $user_obj->getGroups();
         sortProjectList($projects);
         $roles = RBACEngine::getInstance()->getAvailableRolesForUser($user_obj);
         sortRoleList($roles);
         // 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#', 'foaf' => 'http://xmlns.com/foaf/0.1/', 'sioc' => 'http://rdfs.org/sioc/ns#', 'doap' => 'http://usefulinc.com/ns/doap#', 'dcterms' => 'http://purl.org/dc/terms/', 'planetforge' => 'http://coclico-project.org/ontology/planetforge#');
         $conf = array('ns' => $ns);
         // First, let's deal with the account
         $account_res = ARC2::getResource($conf);
         $account_uri = util_make_url_u($username, $user_obj->getID());
         $account_uri = rtrim($account_uri, '/');
         $person_uri = $account_uri . '#person';
         $account_res->setURI($account_uri);
         // $account_res->setRel('rdf:type', 'foaf:OnlineAccount');
         rdfutils_setPropToUri($account_res, 'rdf:type', 'foaf:OnlineAccount');
         rdfutils_setPropToUri($account_res, 'foaf:accountServiceHomepage', $account_uri . '/');
         $account_res->setProp('foaf:accountName', $username);
         rdfutils_setPropToUri($account_res, 'sioc:account_of', $person_uri);
         rdfutils_setPropToUri($account_res, 'foaf:accountProfilePage', $account_uri);
         $groups_index = array();
         $projects_index = array();
         $roles_index = array();
         $usergroups_uris = array();
         // see if there were any groups
         if (count($projects) >= 1) {
             foreach ($projects as $p) {
                 // TODO : report also private projects if authenticated, for instance through OAuth
                 if ($p->isPublic()) {
                     $project_link = util_make_link_g($p->getUnixName(), $p->getID(), $p->getPublicName());
                     $project_uri = util_make_url_g($p->getUnixName(), $p->getID());
                     // sioc:UserGroups for all members of a project are named after /projects/A_PROJECT/members/
                     $usergroup_uri = $project_uri . 'members/';
                     $role_names = array();
                     $usergroups_uris[] = $usergroup_uri;
                     $usergroup_res = ARC2::getResource($conf);
                     $usergroup_res->setURI($usergroup_uri);
                     rdfutils_setPropToUri($usergroup_res, 'rdf:type', 'sioc:UserGroup');
                     rdfutils_setPropToUri($usergroup_res, 'sioc:usergroup_of', $project_uri);
                     $roles_uris = array();
                     foreach ($roles as $r) {
                         if ($r instanceof RoleExplicit && $r->getHomeProject() != NULL && $r->getHomeProject()->getID() == $p->getID()) {
                             $role_names[$r->getID()] = $r->getName();
                             $role_uri = $project_uri . 'roles/' . $r->getID();
                             $roles_uris[] = $role_uri;
                         }
                     }
                     rdfutils_setPropToUri($usergroup_res, 'planetforge:group_has_function', $roles_uris);
                     $project_res = ARC2::getResource($conf);
                     $project_res->setURI($project_uri);
                     rdfutils_setPropToUri($project_res, 'rdf:type', 'planetforge:ForgeProject');
                     $project_res->setProp('doap:name', $p->getUnixName());
                     $projects_index = ARC2::getMergedIndex($projects_index, $project_res->index);
                     foreach ($role_names as $id => $name) {
                         $role_res = ARC2::getResource($conf);
                         $role_res->setURI($project_uri . 'roles/' . $id);
                         rdfutils_setPropToUri($role_res, 'rdf:type', 'sioc:Role');
                         $role_res->setProp('sioc:name', $name);
                         $roles_index = ARC2::getMergedIndex($roles_index, $role_res->index);
                     }
                     $groups_index = ARC2::getMergedIndex($groups_index, $usergroup_res->index);
                 }
             }
         }
         // end if groups
         rdfutils_setPropToUri($account_res, 'sioc:member_of', $usergroups_uris);
         // next, deal with the person
         $person_res = ARC2::getResource($conf);
         $person_res->setURI($person_uri);
         rdfutils_setPropToUri($person_res, 'rdf:type', 'foaf:Person');
         $person_res->setProp('foaf:name', $user_real_name);
         rdfutils_setPropToUri($person_res, 'foaf:holdsAccount', $account_uri);
         $person_res->setProp('foaf:mbox_sha1sum', $mbox_sha1sum);
         // merge the two sets of triples
         $merged_index = ARC2::getMergedIndex($account_res->index, $person_res->index);
         $merged_index = ARC2::getMergedIndex($merged_index, $groups_index);
         $merged_index = ARC2::getMergedIndex($merged_index, $projects_index);
         $merged_index = ARC2::getMergedIndex($merged_index, $roles_index);
         $conf = array('ns' => $ns, 'serializer_type_nodes' => true);
         $ser = ARC2::getRDFXMLSerializer($conf);
         /* Serialize a resource index */
         $doc = $ser->getSerializedIndex($merged_index);
         $params['content'] = $doc . "\n";
     }
 }
Ejemplo n.º 8
0
 /**
  * Outputs project's DOAP profile
  * @param unknown_type $params
  */
 function content_negociated_project_home(&$params)
 {
     $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')) {
             $group = group_get_object($group_id);
             $tags_list = $group->getTags();
         }
         // We will return RDF+XML
         $params['content_type'] = 'application/rdf+xml';
         // 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/', 'schema' => 'http://schema.org/');
         $conf = array('ns' => $ns);
         $res = ARC2::getResource($conf);
         $res->setURI(util_make_url_g($projectname, $group_id));
         // $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);
         $ser = ARC2::getRDFXMLSerializer($conf);
         /* Serialize a resource index */
         $doc = $ser->getSerializedIndex($merged_index);
         $params['content'] = $doc . "\n";
     }
 }