This repository has been archived by the owner on Aug 18, 2020. It is now read-only.
forked from ajstanley/scholar
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscholar.module
199 lines (192 loc) · 6.23 KB
/
scholar.module
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
<?php
/**
* @file
*
* Implements hooks and callbacks for this module.
*/
/**
* Constants
*/
define('MENU_SCHOLAR_HOME', 'scholar');
define('MENU_SCHOLAR_ADVANCED_SEARCH_ADD_FIELD', 'scholar/search/advanced/field/add');
define('MENU_SCHOLAR_ADVANCED_SEARCH_REMOVE_FIELD', 'scholar/search/advanced/field/remove');
define('THEME_SCHOLAR_HOME', 'scholar_home');
define('THEME_SCHOLAR_SEARCH_ITEM', 'scholar_search_item');
define('THEME_SCHOLAR_SEARCH_TABLE', 'scholar_search_results_table');
define('THEME_SCHOLAR_OVERVIEW_PANEL_CITATION', 'scholar_overview_panel_citation');
/**
* Implements hook_menu().
*/
function scholar_menu() {
$items = array();
$items[MENU_SCHOLAR_HOME] = array(
'title' => t('Search Publications'),
'file' => 'pages/Home.inc',
'page callback' => 'scholar_home',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
$items[MENU_SCHOLAR_ADVANCED_SEARCH_ADD_FIELD] = array(
'file' => 'SearchForm.inc',
'page callback' => 'scholar_search_advanced_add_field',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items[MENU_SCHOLAR_ADVANCED_SEARCH_REMOVE_FIELD] = array(
'file' => 'SearchForm.inc',
'page callback' => 'scholar_search_advanced_remove_field',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_theme().
*/
function scholar_theme() {
return array(
THEME_SCHOLAR_HOME => array(
'template' => 'templates/Home',
'file' => 'pages/Home.inc',
),
THEME_SCHOLAR_SEARCH_ITEM => array(
'template' => 'templates/SearchItem',
'file' => 'IslandoraSolrResultsCitation.inc',
'arguments' => array('pid' => NULL, 'style' => NULL)
),
THEME_SCHOLAR_SEARCH_TABLE => array(
'file' => 'IslandoraSolrResultsCitation.inc',
'arguments' => array('element' => NULL)
),
THEME_SCHOLAR_OVERVIEW_PANEL_CITATION => array(
'template' => 'templates/CitationModel',
'file' => 'CitationModel.inc',
'arguments' => array('pid' => NULL)
)
);
}
/**
* Implements hook_register_content_models_for_viewer().
*/
function scholar_register_content_models_for_viewer() {
$models = array();
$models['ir:citationCModel'] = array(
'type' => 'inc',
'module' => 'scholar',
'file' => 'CitationModel',
'class' => 'CitationModel'
);
$models['ir:authorityCModel'] = array(
'type' => 'inc',
'module' => 'content_model_viewer',
'file' => 'models/Default',
'class' => 'DefaultModelViewer'
);
$models['ir:citationCollectionCModel'] = array(
'type' => 'inc',
'module' => 'content_model_viewer',
'file' => 'models/Default',
'class' => 'DefaultModelViewer'
);
$models['ir:authorityCollectionCModel'] = array(
'type' => 'inc',
'module' => 'content_model_viewer',
'file' => 'models/Default',
'class' => 'DefaultModelViewer'
);
$models['islandora:collectionCModel'] = array(
'type' => 'inc',
'module' => 'content_model_viewer',
'file' => 'models/Default',
'class' => 'DefaultModelViewer'
);
return $models;
}
/**
* Implements hook_islandora_solr_primary_display().
*/
function scholar_islandora_solr_primary_display() {
return array(
'scholar' => array(
'name' => t('Citations'),
'module' => 'scholar',
'file' => 'IslandoraSolrResultsCitation.inc',
'class' => "IslandoraSolrResultsCitation",
'function' => "displayResults",
'description' => t("A results are rendered as APA style citations."),
)
);
}
/**
* Implements hook_form_alter().
*
* Alters the content_model_viewer_ingest_metadata_form to make it more user friendly in the context of
* the presence of the build ingest form.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
*/
function scholar_form_content_model_viewer_ingest_metadata_form_alter(array &$form, array &$form_state) {
if ($form_state['storage']['step'] == 1 && isset($form['indicator'])) {
$models = array('ir:citationCModel/ISLANDORACM');
$show_bulk_ingest = FALSE;
foreach ($form['indicator']['models']['#options'] as $model => $label) {
if (array_search($model, $models) !== FALSE) {
$show_bulk_ingest = TRUE;
}
}
if ($show_bulk_ingest) {
module_load_include('inc', 'scholar', 'Batch');
$bulk_ingest = scholar_bulk_ingest_form($form_state, $form['collection_pid']['#value']);
// Move the next button within the field set to make it clearer.
$form['indicator']['submit'] = $form['submit'];
unset($form['submit']);
array_unshift($form, $bulk_ingest);
$form['#attributes'] = array('enctype' => 'multipart/form-data'); // Allow the uploading of files.
$form['#validate'] = array('scholar_bulk_ingest_form_validate');
}
}
}
/**
* Implements hook_form_alter().
*
* Alters the content_model_viewer_edit_metadata_form so that the Citation is Rendered at the top of the page.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
*/
function scholar_form_content_model_viewer_edit_metadata_form_alter(array &$form, array &$form_state) {
if ($form_state['storage']['step'] == 2) {
$pid = $form['pid']['#value'];
$item = new Fedora_Item($pid);
if ($item->exists() && isset($item->datastreams['MODS'])) {
$mods = $item->get_datastream_dissemination('MODS');
$mods = trim($mods);
if (!empty($mods)) {
$doc = new DOMDocument();
$doc->loadXML($mods);
module_load_include('inc', 'csl', 'CSL');
$names = CSL::GetNames();
$style = citeproc_style('APA');
$bibliography = citeproc_bibliography_from_mods($style, $doc);
}
}
$title = array(
'#type' => 'markup',
'#prefix' => '<h3>',
'#value' => check_plain($form_state['values']['forms']),
'#suffix' => '</h3>'
);
$citation = array('#value' => $bibliography->render());
array_unshift($form, $citation);
array_unshift($form, $title);
$form['#attributes'] = array('enctype' => 'multipart/form-data'); // Allow the uploading of files.
}
}