/[drupal]/contributions/modules/rdf/rdf.schema.inc
ViewVC logotype

Contents of /contributions/modules/rdf/rdf.schema.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Mon Feb 16 13:27:09 2009 UTC (9 months, 1 week ago) by arto
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-ALPHA6, DRUPAL-6--1-0-ALPHA7, HEAD
Changes since 1.1: +7 -7 lines
File MIME type: text/x-php
Merged latest changes from http://github.com/bendiken/drupal-rdf.

Changelog:
- #330541 by jmiccolis: Views integration.
- Cache rdf_db_get_repository_tables() and rdf_db_count_repository_triples() results (by alex.k).
- Refactored rdf_db_get_repository_tables() and rdf_db_count_repository_triples().
- Prevent duplicate RDF statements from being inserted (in accordance with repository settings).
- Merge any duplicated RDF statements on cron runs (in accordance with repository settings).
- Implemented support for CCK Fieldgroup fields when outputting RSS feeds from the Views plugin.
- Honor Location module content-type-specific RSS settings when outputting RSS feeds from the Views plugin.
- Folded the RDF Schema module back into the base module, leaving a placeholder (for the time being) in order to allow users to cleanly uninstall the submodule.
- Renamed the 'RDF API' module to 'RDF'.
- Minor coding conventions cleanup.
- Updated the information in README.txt and INSTALL.txt; added contributors to README.txt.
1 <?php
2 // $Id$
3
4 //////////////////////////////////////////////////////////////////////////////
5 // RDF Schema API
6
7 function rdf_schema_data() {
8 return rdf_query(NULL, NULL, NULL, array('context' => RDF_SCHEMA_URI));
9 }
10
11 function rdf_schema_get_class_uri($class) {
12 return RDF_SCHEMA_URI . $class;
13 }
14
15 function rdf_schema_get_property_uri($class, $property) {
16 return RDF_SCHEMA_URI . $class . '#' . $property;
17 }
18
19 function rdf_schema_get_entities() {
20 return array_keys(module_invoke_all('rdf_classes'));
21 }
22
23 function rdf_schema_get_classes() {
24 $resources = array(RDF_SCHEMA_URI => new RDF_QueryCallback('rdf_schema_load_schema'));
25
26 $url_options = array('absolute' => TRUE, 'alias' => TRUE);
27 foreach (module_invoke_all('rdf_classes') as $class => $class_info) {
28 if (empty($class_info['enabled']) || !module_exists($class_info['module']))
29 continue; // skip disabled modules
30
31 // Class URI
32 $uri = rdf_schema_get_class_uri($class);
33 $resources[$uri] = new RDF_QueryCallback('rdf_schema_load_schema_class', array($class, $class_info));
34
35 // Property URIs
36 if (!empty($class_info['table'])) {
37 $sql_schema = drupal_get_schema($class_info['table']);
38 $form_info = _rdf_schema_get_form($class);
39 foreach ($sql_schema['fields'] as $field_name => $field_info) {
40
41 $uri = rdf_schema_get_property_uri($class, $field_name);
42 $resources[$uri] = new RDF_QueryCallback('rdf_schema_load_schema_property', array($class, $field_name, $field_info, @$form_info[$field_name]));
43 }
44 }
45 }
46
47 return $resources;
48 }
49
50 function rdf_schema_get_resources() {
51 $resources = array(RDF_SITE_URI => new RDF_QueryCallback('rdf_schema_load_site'));
52
53 $url_options = array('absolute' => TRUE, 'alias' => TRUE);
54 foreach (module_invoke_all('rdf_classes') as $class => $class_info) {
55 if (empty($class_info['enabled']) || !module_exists($class_info['module']))
56 continue; // skip disabled modules
57
58 $result = db_query($class_info['query']);
59 while ($row = db_fetch_array($result)) {
60 $uri = $class_info['uri'];
61 foreach ($row as $field => $value) {
62 $uri = str_replace('%' . $field, $value, $uri);
63 }
64
65 $uri_options = array();
66
67 // URI fragments must be specially handled in order to use them with url()
68 if (strpos($uri, '#') !== FALSE) {
69 list($uri, $uri_options['fragment']) = explode('#', $uri, 2);
70 }
71
72 $menu_item = menu_get_item($uri);
73 if (!empty($menu_item['access'])) {
74 if (is_object($menu_item['page_arguments'][0])) {
75 $item = $menu_item['page_arguments'][0];
76
77 $uri = url($uri, array_merge($url_options, $uri_options));
78 $resources[$uri] = new RDF_QueryCallback('rdf_schema_load_' . $class, array($item));
79 }
80 }
81 }
82 }
83
84 return $resources;
85 }
86
87 //////////////////////////////////////////////////////////////////////////////
88 // RDF Schema meta-model
89
90 function rdf_schema_load_schema() {
91 return array(
92 rdf::type => rdf_qname_to_uriref('owl:Ontology'),
93 rdfs::seeAlso => rdf_uri(url('rdf', array('absolute' => TRUE))),
94 rdfs::label => t('RDF schema for @site_name', array('@site_name' => variable_get('site_name', 'Drupal'))),
95 dc::type => rdf_qname_to_uriref('dcmitype:Dataset'),
96 dc::format => RDF_FORMAT,
97 dc::publisher => rdf_uri(RDF_SITE_URI),
98 dc::creator => rdf_uri(RDF_SCHEMA_MODULE_URI),
99 );
100 }
101
102 function rdf_schema_load_schema_class($class, $class_info, $comment = NULL) {
103 $comment = !empty($comment) ? $comment : module_invoke($class_info['module'], 'help', 'node/add/#' . $class, NULL);
104 $comment = !empty($comment) ? $comment : module_invoke($class_info['module'], 'help', 'admin/help#' . $class_info['module'], NULL);
105 return array(
106 rdf::type => rdf_qname_to_uriref('rdfs:Class'),
107 rdfs::isDefinedBy => rdf_uri(RDF_SCHEMA_URI),
108 rdfs::subClassOf => rdf_qname_to_uriref('rdfs:Resource'),
109 rdfs::label => rdf_literal($class_info['title'], 'en'),
110 rdfs::comment => !empty($comment) ? rdf_literal(strip_tags($comment), 'en') : NULL,
111 );
112 }
113
114 function rdf_schema_load_schema_property($class, $field_name, $field_info, $form_info) {
115 $title = isset($form_info['#title']) ? $form_info['#title'] : @$field_info['description'];
116 return array(
117 rdf::type => rdf_qname_to_uriref('rdf:Property'),
118 rdfs::isDefinedBy => rdf_uri(RDF_SCHEMA_URI),
119 rdfs::domain => rdf_uri(rdf_schema_get_class_uri($class)),
120 rdfs::range => rdf_qname_to_uriref('rdfs:Literal'), // TODO: should we map these to xsd:* types?
121 rdfs::label => !empty($title) ? rdf_literal($title, 'en') : NULL,
122 rdfs::comment => !empty($form_info['#description']) ? rdf_literal($form_info['#description'], 'en') : NULL,
123 );
124 }
125
126 //////////////////////////////////////////////////////////////////////////////
127 // RDF Schema mappings
128
129 function rdf_schema_load_site() {
130 return array(
131 rdf::type => rdf_uri(rdf_qname_to_uri('drupal:site')),
132 );
133 }
134
135 function rdf_schema_load_user($user) {
136 $user = is_object($user) ? $user : user_load((int)$user);
137 return array(
138 rdf::type => rdf_uri(rdf_qname_to_uri('drupal:user')),
139 'user:uid' => (int)$user->uid,
140 'user:name' => $user->name,
141 'user:mail' => rdf_mailto($user->mail),
142 'user:created' => rdf_datetime($user->created),
143 'user:access' => rdf_datetime($user->access),
144 'user:login' => rdf_datetime($user->login),
145 'user:status' => (bool)$user->status,
146 );
147 }
148
149 function rdf_schema_load_node($node) {
150 $node = is_object($node) ? $node : node_load((int)$node);
151 return array(
152 rdf::type => rdf_uri(rdf_qname_to_uri(variable_get('rdf_schema_class_' . $node->type, 'drupal:node'))),
153 'node:nid' => (int)$node->nid,
154 'node:vid' => (int)$node->vid,
155 'node:uid' => (int)$node->uid,
156 'node:type' => (int)$node->type,
157 'node:title' => $node->title,
158 'node:body' => $node->body,
159 'node:created' => rdf_datetime($node->created),
160 'node:changed' => rdf_datetime($node->changed),
161 'node:status' => (bool)$node->status,
162 'node:comment' => (bool)$node->comment,
163 'node:promote' => (bool)$node->promote,
164 'node:moderate' => (bool)$node->moderate,
165 'node:sticky' => (bool)$node->sticky,
166 'node:translate' => (bool)$node->translate,
167 );
168 }
169
170 //////////////////////////////////////////////////////////////////////////////
171 // Forms API helper functions
172
173 function _rdf_schema_get_form($entity) {
174 $form_builder = '_rdf_schema_get_' . $entity . '_form';
175 $form = function_exists($form_builder) ? $form_builder() : array();
176 return _rdf_schema_cleanup_form($form);
177 }
178
179 function _rdf_schema_get_user_form() {
180 $form = @user_edit_form($form_state, NULL, NULL, TRUE);
181 return $form/*['account']*/;
182 }
183
184 function _rdf_schema_get_vocabulary_form() {
185 module_load_include('inc', 'taxonomy', 'taxonomy.admin');
186
187 $form = @taxonomy_form_vocabulary($form_state);
188 $form['vid']['#title'] = t('ID');
189 return $form;
190 }
191
192 function _rdf_schema_get_term_form() {
193 module_load_include('inc', 'taxonomy', 'taxonomy.admin');
194
195 // TODO: pass a fake $vocabulary object to get all fields?
196 $form = @taxonomy_form_term($form_state);
197 $form['tid']['#title'] = t('ID');
198 return $form;
199 }
200
201 function _rdf_schema_get_node_form($type = 'page') {
202 module_load_include('inc', 'node', 'node.pages');
203
204 $user = user_load(1);
205 $node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type, 'language' => '');
206
207 // TODO: created, type, language, changed
208 $form = @node_form($form_state, $node);
209 $form['nid']['#title'] = t('ID');
210 $form['vid']['#title'] = t('Version ID');
211 $form['uid']['#title'] = t('User ID');
212 $form['tnid']['#title'] = t('Translation ID');
213 return $form;
214 }
215
216 function _rdf_schema_get_comment_form() { // FIXME
217 $form = @comment_form($form_state, array());
218 $form['cid']['#title'] = t('ID');
219 $form['pid']['#title'] = t('Parent ID');
220 $form['nid']['#title'] = t('Node ID');
221 $form['nid']['#title'] = t('User ID');
222 return $form;
223 }
224
225 function _rdf_schema_cleanup_form(&$form) {
226 unset($form['buttons']);
227 foreach ($form as $key => &$element) {
228 if (strpos($key, '#') === 0 || !is_array($element)) {
229 unset($form[$key]);
230 continue;
231 }
232
233 if ((isset($element['#type']) && $element['#type'] == 'fieldset') ||
234 isset($element['#after_build'])) {
235 foreach ($element as $field => $field_info) {
236 if (is_string($field) && strpos($field, '#') !== 0) {
237 $form[$field] = $field_info;
238 }
239 }
240 unset($form[$key]);
241 }
242 }
243 return $form;
244 }

  ViewVC Help
Powered by ViewVC 1.1.2