forked from omeka/plugin-DublinCoreExtended
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDublinCoreExtendedPlugin.php
More file actions
148 lines (134 loc) · 4.01 KB
/
DublinCoreExtendedPlugin.php
File metadata and controls
148 lines (134 loc) · 4.01 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
<?php
/**
* Dublin Core Extended
*
* @copyright Copyright 2007-2012 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/
/**
* The Dublin Core Extended plugin.
*
* @package Omeka\Plugins\DublinCoreExtended
*/
class DublinCoreExtendedPlugin extends Omeka_Plugin_AbstractPlugin
{
protected $_hooks = array(
'install',
'uninstall',
'uninstall_message',
'upgrade',
'initialize',
);
protected $_filters = array(
'response_contexts',
'action_contexts',
);
private $_elements;
private $_dcElements = array(
'Title', 'Subject', 'Description', 'Creator', 'Source', 'Publisher',
'Date', 'Contributor', 'Rights', 'Relation', 'Format', 'Language',
'Type', 'Identifier', 'Coverage',
);
public function __construct()
{
parent::__construct();
// Set the elements.
include 'elements.php';
$this->_elements = $elements;
}
/**
* Install the plugin.
*/
public function hookInstall()
{
// Add the new elements to the Dublin Core element set.
$elementSet = $this->_db->getTable('ElementSet')->findByName('Dublin Core');
foreach ($this->_elements as $key => $element) {
if (!in_array($element['label'], $this->_dcElements)) {
$sql = "
INSERT INTO `{$this->_db->Element}` (`element_set_id`, `name`, `description`)
VALUES (?, ?, ?)";
$this->_db->query($sql, array($elementSet->id, $element['label'], $element['description']));
}
}
}
/**
* Uninstall the plugin.
*/
public function hookUninstall()
{
// Delete all the elements and element texts.
$elementTable = $this->_db->getTable('Element');
foreach ($this->_elements as $element) {
if (!in_array($element['label'], $this->_dcElements)) {
$elementTable->findByElementSetNameAndElementName('Dublin Core', $element['label'])->delete();
}
}
}
/**
* Display the uninstall message.
*/
public function hookUninstallMessage()
{
echo __('%sWarning%s: This will remove all the Dublin Core elements added '
. 'by this plugin and permanently delete all element texts entered in those '
. 'fields.%s', '<p><strong>', '</strong>', '</p>');
}
/**
* Upgrade this plugin.
*
* @param array $args
*/
public function hookUpgrade($args)
{
// Drop the unused dublin_core_extended_relationships table.
if (version_compare($args['old_version'], '2.0', '<')) {
$sql = "DROP TABLE IF EXISTS `{$this->_db->DublinCoreExtendedRelationship}`";
$this->_db->query($sql);
}
}
/**
* Initialize this plugin.
*/
public function hookInitialize()
{
// Add translation.
add_translation_source(dirname(__FILE__) . '/languages');
}
/**
* Add the dc-rdf response context.
*
* @param array $contexts
* @return array
*/
public function filterResponseContexts($contexts)
{
$contexts['dc-rdf'] = array('suffix' => 'dc-rdf',
'headers' => array('Content-Type' => 'text/xml'));
return $contexts;
}
/**
* Add the dc-rdf response context to items/browse and items/show.
*
* @param array $contexts
* @param array $args
* @return array
*/
public function filterActionContexts($contexts, $args)
{
if ($args['controller'] instanceof ItemsController) {
$contexts['browse'][] = 'dc-rdf';
$contexts['show'][] = 'dc-rdf';
}
return $contexts;
}
/**
* Get the dublin core extended elements array.
*
* @return array
*/
public function getElements()
{
return $this->_elements;
}
}