-
Notifications
You must be signed in to change notification settings - Fork 2
/
ir_citation.inc
282 lines (259 loc) · 9.2 KB
/
ir_citation.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<?php
/**
* @file
* This file supplies helper functions and utilities to the ir_citation module.
* @author
* William Panting
*/
/**
* This function will load the necessary javascript files onto the page currently
* being generated so that the citeproc-js citation style language engine can run.
* Only call this once on a page
*/
function load_citeproc_javascript() {
//jquery library loads
drupal_add_js(drupal_get_path('module', 'ir_citation') . '/jQuery/jquery-1.6.2.min.js');
drupal_add_js(drupal_get_path('module', 'ir_citation') . '/jQuery/re_alias_jQuery.js');
//citeproc library loads
drupal_add_js(drupal_get_path('module', 'ir_citation') . '/citeproc-js/xmle4x.js');
drupal_add_js(drupal_get_path('module', 'ir_citation') . '/citeproc-js/xmldom.js');
drupal_add_js(drupal_get_path('module', 'ir_citation') . '/citeproc-js/citeproc.js');
/* module specific javascript for making drupal api work with the citeproc javascript */
//creates a 'sys' object that gives the citeproc engine access to the variables set by drupal
drupal_add_js(drupal_get_path('module', 'ir_citation') . '/ir_citation_sys.js');
//currently being used to launch demo/test
drupal_add_js(drupal_get_path('module', 'ir_citation') . '/ir_citation_run.js');
}
/**
* This function will create and make available the citeproc_json related to the fedora object
* Relies on the MODS datastream
* The indicated CSL will also be made available
* @param string $fedora_pid
* The pid of the fedora object to cite.
* @param mixed $variable_name
* The id to insert into the json object, needs to be unique for the page, also
* the name in the drupal.settings object that will hold the completed json
* If this is NULL it gets the value of $fedora_pid
* @return mixed
* The metadata that was sent to JS, or false if something went wrong
*/
function load_meta_data_from_fedora_pid($fedora_pid, $variable_name=NULL) {
if ($variable_name == NULL) {//allows to do this with only setting $fedora_pid
$variable_name = $fedora_pid;
}
//get the mods from fedora
$cite_mods = get_mods_from_pid($fedora_pid);
if (!cite_mods) {
return FALSE;
}
//load json
return (load_citeproc_json_from_mods($variable_name, $cite_mods));
}
/**
* This is a convienence function that simply wraps mods_to_citeproc_json
* and load_metadata_object_for_javascript
* @param string $variable_name
* The id to insert into the json object, needs to be unique for the page, also
* the name in the drupal.settings object that will hold the completed json
* @param string $cite_mods
* The mods to convert to citeproc_json for citation purposes
* @return
* the metadata that was sent to JS
*/
function load_citeproc_json_from_mods($variable_name, $cite_mods) {
//get json
$citeproc_json = mods_to_citeproc_json($cite_mods, $variable_name);
//load json in javascript
return (load_metadata_object_for_javascript($variable_name, $citeproc_json));
}
/**
* This function will transform the MODS string it is given into a json format
* that the citeproc-js engine can understand
* This function is a module level api style wrapper for converting mods to citeproc_json
* @param $cite_mods
* The mods to convert to citeproc_json for citation purposes
* @param $item_id
* The id to insert into the json object, needs to be unique for the page
* @return
* The json formated citation data
* @todo
* Examine if this is necessary, it may just be waisted redirection now
*/
function mods_to_citeproc_json($cite_mods, $item_id) {
module_load_include('php', 'ir_citation', 'mods_to_citeproc_json/converter');
return (convert_mods_to_citeproc_json($cite_mods, $item_id));
}
/**
* This function will make available the supplied json for use with citeproc-js
* on the current page being generated's javacript
* @param string $variable_name
* This name to make the json available under.
* @param stirng $meta_data_object
* The json to make available.
* @return stirng $meta_data_object
* The metadata being added
*/
function load_metadata_object_for_javascript($variable_name, $meta_data_object) {
drupal_add_js(array(
'ir_citation' => array(
'meta_data_objects' => array(
$variable_name => $meta_data_object,
)
)
), 'setting');
return $meta_data_object;
}
/**
* This function will make avaialbe the list of citations to use in a bibliography in json formated string
* so it can be made into a JavaScript array.
* @param array $bibliography_list
* This array is the list of names of the json meta data citation objects to include in the citation
* @param string $variable_name
* This name to make the json available under.
* @return string $bibliography_json
* This is the json that will actualy get added javascript side
*/
function load_bibliography_list_for_javascript($bibliography_list, $variable_name) {
$bibliography_json = json_encode($bibliography_list);
drupal_add_js(array(
'ir_citation' => array(
'bibliography_lists' => array(
$variable_name => $bibliography_json,
)
)
), 'setting');
return $bibliography_json;
}
/**
* This function will add a bibliography selector to
* @param string $bibliography_selector
* json string representing a selector for bibliographies:
* http://gsl-nagoya-u.net/http/pub/citeproc-doc.html#selective-output
* @param string $variable_name
* This name to make the json available under.
* @return $bibliography_selector
* The data sent to javascript
*/
function load_bibliography_selector($bibliography_selector, $variable_name) {
drupal_add_js(array(
'ir_citation' => array(
'bibliography_selectors' => array(
$variable_name => $bibliography_selector,
)
)
), 'setting');
return ($bibliography_selector);
}
/**
* This function will make available the supplied citation object json for use with citeproc-js
* on the current page being generated's javacript
* @param string $variable_name
* This name to make the json available under.
* @param stirng $json
* The json to make available. The formatting can be found here:
* http://gsl-nagoya-u.net/http/pub/citeproc-doc.html#citation-data-object
* @return $json
* The data added to javascript
*/
function load_citeproc_citation_object_for_javascript($json, $variable_name) {
drupal_add_js(array(
'ir_citation' => array(
'citation_objects' => array(
$variable_name => $json,
)
)
), 'setting');
return ($json);
}
/**
* This function will make available the supplied CSL string for use with citeproc-js
* on the current page being generated's javacript
* @param string $variable_name
* This name to make the CSL available under.
* @param stirng $csl
* The xml CSL to make available.
* @return $csl
* The data added to javascript
*/
function load_csl_for_javascript($variable_name, $csl) {
drupal_add_js(array(
'ir_citation' => array(
'csl' => array(
$variable_name => $csl,
)
)
), 'setting');
return $csl;
}
/**
* This function will make available the supplied locale string for use with citeproc-js
* on the current page being generated's javacript
* @param string $lang
* This name to make the locale available under.
* @param stirng $locale
* The xml locale data to make available.
* @return $locale
* The data added to javascript
*/
function load_locale($lang, $locale) {
drupal_add_js(array(
'ir_citation' => array(
'locale' => array(
$lang => $locale,
)
)
), 'setting');
return $locale;
}
/**
* This function will make available the supplied abbreviation data for use with citeproc-js
* on the current page being generated's javacript
* @param string $name
* This name to make the abreviation available under.
* @param string $var_type
* This type of abbreviation data. ie."institution"
* @param stirng $abbreviation_data
* The abbreviation data to make available.
* @return $abbreviation_data
* The data sent to JS
*/
function load_abbreviation($name, $var_type, $abbreviation_data) {
drupal_add_js(array(
'ir_citation' => array(
'abbreviations' => array(
$name => array(
$var_type => $abbreviation_data,
)
)
)
), 'setting');
return $abbreviation_data;
}
/**
* This will get the mods datastream from the indicated fedora pid
* @param string $pid
* The pid to get the mods datastream from
* @return mixed $cite_mods
* The string of the mods datastream from the indicate pid. Or false if there is none
*/
function get_mods_from_pid($pid) {
/*
* switch back to this code when the class FedoraObject is renamed in core
module_load_include('object.inc', 'islandora_fedora_api'); //for getting an object
$object= new FedoraObject($pid);
$object_datastreams=$object->get_datastreams();
if (!isset($object_datastreams['MODS'])) {
return FALSE;
}
//get the DS xml
$mods_datastream=$object_datastreams['MODS'];
$cite_mods=$mods_datastream->__get('content');
*/
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); //for getting an object
$item = new Fedora_Item($pid);
if (empty($item->datastreams['MODS'])) {
return FALSE;
}
$content = $item->get_datastream_dissemination('MODS');
return $content;
}