forked from Daniel-KM/Omeka-plugin-PBCoreElementSet
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCAVPP_PBCoreElementSetPlugin.php
More file actions
181 lines (157 loc) · 5.46 KB
/
CAVPP_PBCoreElementSetPlugin.php
File metadata and controls
181 lines (157 loc) · 5.46 KB
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
<?php
/**
* CAVPP PBCore Element Set plugin
*
* Creates a custom element set for
* California Audiovisual Preservation Project based on
* PBCore (Public Broadcasting Metadata Dictionary),
* a standard for digitalized documents (see http://pbcore.org).
*
* copyright LibraryHost, 2014
* Based on PBCore Element Set by Pop Up Archive, 2012
* @license http://www.gnu.org/licenses/gpl-3.0.txt
*/
/**
* The CAVPP PBCore Element Set plugin.
* @package Omeka\Plugins\CAVPP_PBCoreElementSet
*/
class CAVPP_PBCoreElementSetPlugin extends Omeka_Plugin_AbstractPlugin
{
private $_elementSetName = 'CAVPP_PBCore';
/**
* @var array Hooks for the plugin.
*/
protected $_hooks = array(
'install',
'uninstall',
'after_save_item',
'public_theme_header',
// BeamMeUpToInternetArchive hook used to get list of metadata.
'beamia_set_settings',
);
/**
* @var array Filters for the plugin.
*/
protected $_filters = array(
'response_contexts',
'action_contexts',
);
/**
* Install the plugin.
*/
public function hookInstall()
{
$this->_installOptions();
// Load elements to add.
require_once('elements.php');
// Don't install if an element set already exists.
if ($this->_getElementSet($this->_elementSetName)) {
throw new Omeka_Plugin_Installer_Exception('An element set by the name "' . $this->_elementSetName . '" already exists. You must delete that element set to install this plugin.');
}
insert_element_set($elementSetMetadata, $elements);
}
/**
* Uninstall the plugin.
*/
public function hookUninstall()
{
$this->_deleteElementSet($this->_elementSetName);
$this->_uninstallOptions();
}
/**
* Saves the metadata
*/
public function hookAfterSaveItem($args)
{
$post = $args['post'];
$item = $args['record'];
}
/*
* Output pbcore xml from public view
*/
public function hookPublicThemeHeader()
{
$request = Zend_Controller_Front::getInstance()->getRequest();
if ($request->getControllerName() == 'items' && $request->getActionName() == 'show') {
echo '<link rel="alternate" type="application/rss+xml" href="' . record_url(get_current_record('item')) . '?output=cavpp_pbcore" id="cavpp_pbcore"/>' . PHP_EOL;
}
if ($request->getControllerName() == 'items' && $request->getActionName() == 'browse') {
echo '<link rel="alternate" type="application/rss+xml" href="' . record_url(get_current_record('item')) . '?output=cavpp_pbcore" id="cavpp_pbcore"/>' . PHP_EOL;
}
}
/**
* BeamMeUpToInternetArchive hook used to get list of metadata.
*
* Note that default Dublin Core metadata are removed.
*/
public function hookBeamiaSetSettings($args)
{
// Don't use Dublin Core metadata that are created by default.
$settings = array();
$record = $args['record'];
$elementSetName = $this->_elementSetName;
// Add existing elements.
$options = array(
'show_empty_elements' => false,
'return_type' => 'array',
);
if ($elementSetName) {
$options['show_element_sets'] = $elementSetName;
}
$elementTexts = all_element_texts($record, $options);
// Don't add "Dublin Core" in the header, because this is the standard
// on Internet Archive.
$cleanElementSetName = ($elementSetName == 'Dublin Core') ?
'' :
preg_replace('#[^a-z0-9]+#', '-', strtolower($elementSetName)) . '-';
foreach ($elementTexts[$elementSetName] as $element => $texts) {
// Replace unique or serie of non-alphanumeric character by "-".
$meta = preg_replace('#[^a-z0-9]+#', '-', strtolower($element));
foreach ($texts as $key => $text) {
$base = (count($texts) == 1) ?
'x-archive-meta-' :
'x-archive-meta' . sprintf('%02d', $key) . '-';
$settings[] = $base . $cleanElementSetName . $meta . ':' . $text;
}
// Add default title if it exists. If none, a generic name will be
// added automatically.
if ($element == 'Title') {
$settings[] = 'x-archive-meta-title:' . $texts[0];
}
}
$args['settings'] = $settings;
}
public function filterResponseContexts($contexts)
{
$contexts['cavpp_pbcore'] = array(
'suffix' => 'cavpp_pbcore',
'headers' => array('Content-Type' => 'text/xml'),
);
return $contexts;
}
public function filterActionContexts($contexts, $controller)
{
if ($controller['controller'] instanceof ItemsController) {
$contexts['show'][] = 'cavpp_pbcore';
$contexts['browse'][] = 'cavpp_pbcore';
}
return $contexts;
}
private function _getElementSet($elementSetName)
{
return $this->_db
->getTable('ElementSet')
->findByName($elementSetName);
}
private function _deleteElementSet($elementSetName)
{
$elementSet = $this->_getElementSet($elementSetName);
if ($elementSet) {
$elements = $elementSet->getElements();
foreach ($elements as $element) {
$element->delete();
}
$elementSet->delete();
}
}
}