-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSocialBookmarkingPlugin.php
More file actions
149 lines (132 loc) · 4.9 KB
/
SocialBookmarkingPlugin.php
File metadata and controls
149 lines (132 loc) · 4.9 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
<?php
/**
* Social Bookmarking
*
* @copyright Copyright 2008-2013 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/
require_once dirname(__FILE__) . '/helpers/SocialBookmarkingFunctions.php';
/**
* Social Bookmarking plugin.
*/
class SocialBookmarkingPlugin extends Omeka_Plugin_AbstractPlugin
{
const SERVICE_SETTINGS_OPTION = 'social_bookmarking_services';
const ADD_TO_OMEKA_ITEMS_OPTION = 'social_bookmarking_add_to_omeka_items';
const ADD_TO_OMEKA_COLLECTIONS_OPTION = 'social_bookmarking_add_to_omeka_collections';
/**
* @var array Hooks for the plugin.
*/
protected $_hooks = array(
'install',
'uninstall',
'upgrade',
'initialize',
'config_form',
'config',
'public_head',
'public_items_show',
'public_collections_show'
);
/**
* @var array Options and their default values.
*/
protected $_options = array(
'social_bookmarking_services' => '',
'social_bookmarking_add_to_omeka_items' => '1',
'social_bookmarking_add_to_omeka_collections' => '1',
);
/**
* Install the plugin.
*/
public function hookInstall()
{
$this->_options['social_bookmarking_services'] = serialize(social_bookmarking_get_default_service_settings());
$this->_installOptions();
}
/**
* Uninstall the plugin.
*/
public function hookUninstall()
{
$this->_uninstallOptions();
}
/**
* Upgrade the plugin.
*
* @param array $args contains: 'old_version' and 'new_version'
*/
public function hookUpgrade($args)
{
if (version_compare($args['old_version'], '2.1', '<')) {
$booleanFilter = new Omeka_Filter_Boolean;
$newServiceSettings = social_bookmarking_get_default_service_settings();
$oldServiceSettings = social_bookmarking_get_service_settings();
foreach($newServiceSettings as $serviceCode => $value) {
if (array_key_exists($serviceCode, $oldServiceSettings)) {
$newServiceSettings[$serviceCode] = $booleanFilter->filter($oldServiceSettings[$serviceCode]);
}
}
social_bookmarking_set_service_settings($newServiceSettings);
}
}
/**
* Add the translations.
*/
public function hookInitialize()
{
add_translation_source(dirname(__FILE__) . '/languages');
}
public function hookPublicHead()
{
queue_css_file('iconfonts');
queue_css_file('social-bookmarking');
}
/**
* Display the plugin config form.
*/
public function hookConfigForm()
{
require dirname(__FILE__) . '/config_form.php';
}
/**
* Set the options from the config form input.
*/
public function hookConfig($args)
{
$post = $args['post'];
unset($post['install_plugin']);
set_option(SocialBookmarkingPlugin::ADD_TO_OMEKA_ITEMS_OPTION, $post[SocialBookmarkingPlugin::ADD_TO_OMEKA_ITEMS_OPTION]);
unset($post[SocialBookmarkingPlugin::ADD_TO_OMEKA_ITEMS_OPTION]);
set_option(SocialBookmarkingPlugin::ADD_TO_OMEKA_COLLECTIONS_OPTION, $post[SocialBookmarkingPlugin::ADD_TO_OMEKA_COLLECTIONS_OPTION]);
unset($post[SocialBookmarkingPlugin::ADD_TO_OMEKA_COLLECTIONS_OPTION]);
$serviceSettings = social_bookmarking_get_service_settings();
$booleanFilter = new Omeka_Filter_Boolean;
foreach($post as $key => $value) {
if (array_key_exists($key, $serviceSettings)) {
$serviceSettings[$key] = $booleanFilter->filter($value);
}
}
social_bookmarking_set_service_settings($serviceSettings);
}
public function hookPublicItemsShow()
{
if (get_option(SocialBookmarkingPlugin::ADD_TO_OMEKA_ITEMS_OPTION) == '1') {
$item = get_current_record('item');
$url = record_url($item, 'show', true);
$title = strip_formatting(metadata($item, array('Dublin Core', 'Title'), array('no_escape' => true)));
$description = strip_formatting(metadata($item, array('Dublin Core', 'Description'), array('no_escape' => true)));
echo social_bookmarking_toolbar($url, $title, $description);
}
}
public function hookPublicCollectionsShow()
{
if (get_option(SocialBookmarkingPlugin::ADD_TO_OMEKA_COLLECTIONS_OPTION) == '1') {
$collection = get_current_record('collection');
$url = record_url($collection, 'show', true);
$title = strip_formatting(metadata($collection, array('Dublin Core', 'Title'), array('no_escape' => true)));
$description = strip_formatting(metadata($collection, array('Dublin Core', 'Description'), array('no_escape' => true)));
echo social_bookmarking_toolbar($url, $title, $description);
}
}
}