-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalContextsPlugin.php
executable file
·173 lines (153 loc) · 4.84 KB
/
LocalContextsPlugin.php
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
<?php
if (!defined('LOCALCONTEXTS_PLUGIN_DIR')) {
define('LOCALCONTEXTS_PLUGIN_DIR', dirname(__FILE__));
}
if (!defined('LOCALCONTEXTS_HELPERS_DIR')) {
define('LOCALCONTEXTS_HELPERS_DIR', LOCALCONTEXTS_PLUGIN_DIR . '/helpers');
}
if (!defined('LOCALCONTEXTS_FORMS_DIR')) {
define('LOCALCONTEXTS_FORMS_DIR', LOCALCONTEXTS_PLUGIN_DIR . '/forms');
}
require_once LOCALCONTEXTS_PLUGIN_DIR . '/LocalContextsPlugin.php';
/**
* LocalContexts plugin.
*
* @package Omeka\Plugins\LocalContexts
*/
class LocalContextsPlugin extends Omeka_Plugin_AbstractPlugin
{
/**
* @var array Hooks for the plugin.
*/
protected $_hooks = array(
'uninstall',
'admin_head',
'public_head',
'initialize',
'define_routes',
'config',
'config_form',
'public_footer'
);
protected $_filters = array(
'admin_navigation_main',
'exhibit_layouts'
);
public function hookUninstall()
{
// Delete the plugin options
delete_option('lc_project_id');
delete_option('lc_notices');
delete_option('lc_language');
delete_option('lc_content_site');
}
public function hookAdminHead()
{
queue_css_file('local-contexts');
}
public function hookPublicHead()
{
queue_css_file('local-contexts');
}
public function hookInitialize()
{
add_translation_source(dirname(__FILE__) . '/languages');
}
public function hookDefineRoutes($args)
{
$router = $args['router'];
$indexRoute = new Zend_Controller_Router_Route('local-contexts',
array(
'module' => 'local-contexts',
'controller' => 'localcontexts',
'action' => 'index'
)
);
$router->addRoute('localContextsIndex', $indexRoute);
$assignRoute = new Zend_Controller_Router_Route('local-contexts/assign',
array(
'module' => 'local-contexts',
'controller' => 'localcontexts',
'action' => 'assign'
)
);
$router->addRoute('localContextsAssign', $assignRoute);
}
public function hookConfig($args)
{
$post = $args['post'];
set_option('lc_language', $post['lc_language']);
if ($post['lc_content_site']) {
set_option('lc_content_site', serialize($post['lc_content_site']));
} else {
delete_option('lc_content_site');
}
}
public function hookConfigForm()
{
$view = get_view();
include 'config_form.php';
}
public function hookPublicFooter()
{
if (get_option('lc_content_site')) {
$projects = unserialize(get_option('lc_content_site'));
$localContextLanguage = get_option('lc_language');
$contentArray = array();
foreach ($projects as $project) {
$project = json_decode($project, true);
$projectArray = array();
if (isset($project['project_title'])) {
$projectArray['project_title'] = $project['project_title'];
}
if (isset($project['project_url'])) {
$projectArray['project_url'] = $project['project_url'];
}
foreach ($project as $key => $notice) {
if (is_int($key)) {
if (isset($notice['language']) && ($notice['language'] == $localContextLanguage)) {
$projectArray[] = $notice;
} elseif (!isset($notice['language']) && $localContextLanguage == 'English') {
$projectArray[] = $notice;
}
}
}
$contentArray[] = $projectArray;
}
$view = get_view();
echo $view->partial('site-footer.phtml', [
'lc_content' => $contentArray,
]);
}
}
/**
* LocalContexts admin_navigation_main filter.
*
* Adds a button to the admin's main navigation.
*
* @param array $nav
* @return array
*/
public function filterAdminNavigationMain($nav)
{
$nav[] = array(
'label' => __('Local Contexts'),
'uri' => url('local-contexts'),
);
return $nav;
}
/**
* Register an exhibit layout for displaying Local Contexts content.
*
* @param array $layouts Exhibit layout specs.
* @return array
*/
public function filterExhibitLayouts($layouts)
{
$layouts['local-contexts'] = array(
'name' => __('Local Contexts'),
'description' => __('Embed Local Contexts content.')
);
return $layouts;
}
}