-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathislandora_sp_text_html.module
154 lines (127 loc) · 6.16 KB
/
islandora_sp_text_html.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
<?php
/**
* @file
* Handles the creation and display of text/html files.
*/
/**
* Implements hook_theme
*/
function islandora_sp_text_html_theme($existing, $type, $theme, $path)
{
return [
'islandora_sp_text_html' => [
'template' => 'theme/islandora-sp-text-html',
],
];
}
/**
* Implements hook_islandora_required_objects().
*/
function islandora_sp_text_html_islandora_required_objects(IslandoraTuque $connection)
{
$modulePath = drupal_get_path('module', 'islandora_sp_text_html');
// Content Model
$contentModel = $connection->repository->constructObject('islandora:sp_text_html');
$contentModel->owner = 'fedoraAdmin';
$contentModel->label = 'Islandora SP Text/HTML Content Model';
$contentModel->models = 'fedora-system:ContentModel-3.0';
// DS-COMPOSITE-MODEL Datastream
$datastream = $contentModel->constructDatastream('DS-COMPOSITE-MODEL', 'X');
$datastream->label = 'DS-COMPOSITE-MODEL';
$datastream->mimetype = 'application/xml';
$datastream->setContentFromFile($modulePath . '/xml/islandora_sp_text_html_ds_composite_model.xml', false);
$contentModel->ingestDatastream($datastream);
// Collection
$collection = $connection->repository->constructObject('islandora:sp_text_html_collection');
$collection->owner = 'fedoraAdmin';
$collection->label = 'Text/HTML collection';
$collection->models = 'islandora:collectionCModel';
$collection->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', 'islandora:root');
// Collection Policy
$datastream = $collection->constructDatastream('COLLECTION_POLICY', 'X');
$datastream->label = 'Collection policy';
$datastream->mimetype = 'application/xml';
$datastream->setContentFromFile($modulePath . '/xml/islandora_sp_text_html_collection_policy.xml', false);
$collection->ingestDatastream($datastream);
return [
'islandora_sp_text_html' => [
'title' => 'Islandora SP Text/HTML',
'objects' => [
$contentModel,
$collection,
],
],
];
}
/**
* Implements hook_CMODEL_PID_islandora_view_object().
*/
function islandora_sp_text_html_islandora_sp_text_html_islandora_view_object($object, $page_number, $page_size)
{
$output = theme('islandora_sp_text_html', array('islandora_object' => $object));
return array('' => $output);
}
/**
* Implements hook_preprocess_theme().
*/
function template_preprocess_islandora_sp_text_html(array &$variables)
{
drupal_add_js('misc/form.js');
drupal_add_js('misc/collapse.js');
$islandora_object = $variables['islandora_object'];
$repository = $islandora_object->repository;
module_load_include('inc', 'islandora', 'includes/datastream');
module_load_include('inc', 'islandora', 'includes/utilities');
module_load_include('inc', 'islandora', 'includes/metadata');
// We should eventually remove the DC object and dc_array code as it only
// exists to not break legacy implementations.
if (islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['DC'])) {
try {
$dc = $islandora_object['DC']->content;
$dc_object = DublinCore::importFromXMLString($dc);
} catch (Exception $e) {
drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error', FALSE);
}
}
$variables['islandora_dublin_core'] = isset($dc_object) ? $dc_object : NULL;
$variables['dc_array'] = isset($dc_object) ? $dc_object->asArray() : array();
$variables['islandora_object_label'] = $islandora_object->label;
$variables['theme_hook_suggestions'][] = 'islandora_sp_text_html__' . str_replace(':', '_', $islandora_object->id);
$variables['parent_collections'] = islandora_get_parents_from_rels_ext($islandora_object);
$variables['metadata'] = islandora_retrieve_metadata_markup($islandora_object);
$variables['description'] = islandora_retrieve_description_markup($islandora_object);
global $user;
// Text/HTML object.
if (isset($islandora_object['OBJ']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['OBJ'], $user)) {
$datastream = $filteredContent = $islandora_object->getDatastream('OBJ');
if ($datastream->mimetype === 'text/html') {
$content = $datastream->content;
// since drupal filtered_html does not filter text between style tags, we'll do that first
$filteredContent = preg_replace('@<style[^>]*?>.*?</style>@siu', '', $content);
$filteredContent = check_markup($filteredContent, 'filtered_html');
$filteredContent = '<div class="filtered-html">' . $filteredContent . '</div>';
} elseif (in_array($datastream->mimetype, array('text/plain', 'text/x-chat', 'text/praat-script', 'text/r-script', 'text/x-R', 'text/x-esf', 'text/x-matlab', 'text/x-presentation-script', 'text/x-presentation-template', 'text/x-python', 'text/x-shoebox-language', 'text/x-shoebox-lexicon', 'text/x-shoebox-text', 'text/x-shoebox-type', 'text/x-toolbox-lexicon', 'text/x-toolbox-text'))) {
$filteredContent = check_markup($datastream->content, 'plain_text');
// strip br tags, "white-space: pre-wrap" css already preserves line breaks and we don't want them twice
$filteredContent = preg_replace("~<br />~", "", $filteredContent);
$filteredContent = '<div class="plain-text">' . $filteredContent . '</div>';
} else {
$filteredContent = '';
}
// removing mailto links
$filteredContent = preg_replace('/\<a href="mailto:.+?"\>(.+?)\<\/a\>/ims', '$1', $filteredContent);
$variables['islandora_content'] = $filteredContent;
}
}
function islandora_sp_text_html_islandora_sp_text_html_islandora_ingest_steps()
{
return [
'islandora_sp_text_html' => [
'weight' => 10,
'type' => 'form',
'form_id' => 'islandora_sp_text_html_text_html_upload',
'module' => 'islandora_sp_text_html',
'file' => 'includes/text_html_upload.form.inc',
],
];
}