forked from patrickmj/Corrections
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCorrectionsPlugin.php
120 lines (108 loc) · 3.8 KB
/
CorrectionsPlugin.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
<?php
//require(PLUGIN_DIR . '/Corrections/forms/Correction.php');
define('CORRECTIONS_DIR', PLUGIN_DIR . '/Corrections');
class CorrectionsPlugin extends Omeka_Plugin_AbstractPlugin
{
protected $_hooks = array(
'install',
'uninstall',
'public_items_show',
'config',
'config_form'
);
protected $_filters = array(
'admin_navigation_main'
);
public function hookInstall($args)
{
if (! Omeka_Captcha::getCaptcha()) {
$messenger = new Omeka_Controller_Action_Helper_FlashMessenger;
$message = __('ReCaptcha is not configured. Anonymous users will not be able to submit corrections.');
$messenger->addMessage($message, 'alert');
}
$db = get_db();
$sql = "
CREATE TABLE IF NOT EXISTS `$db->CorrectionsCorrection` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`reviewed` timestamp NULL,
`item_id` int(10) NOT NULL,
`comment` text COLLATE utf8_unicode_ci,
`status` tinytext NULL,
`owner_id` int(10) NULL,
`email` tinytext NULL,
`may_contact` BOOLEAN NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
";
$db->query($sql);
set_option('corrections_elements', json_encode(array()));
set_option('corrections_text', 'Submit a correction');
}
public function hookUninstall($args)
{
$db = get_db();
$sql = "
DROP TABLE IF EXISTS `$db->CorrectionsCorrection`
";
$db->query($sql);
delete_option('corrections_elements');
}
public function hookPublicItemsShow($args)
{
$user = current_user();
if (! $user && ! Omeka_Captcha::getCaptcha()) {
return;
}
$item = $args['item'];
echo self::correctionLink($item);
}
public static function correctionLink($item, $text = null)
{
if (is_null($text)) {
$text = get_option('corrections_text');
}
$link = link_to('Corrections_IndexController',
'add',
$text,
array(),
array('item_id' => $item->id)
);
$url = url('corrections/index/add/item_id/' . $item->id);
$html = '';
$html .= "<div class='corrections'>";
$html .= "<h2>" . __('Correction?') . "</h2>";
$html .= "<a href='$url'>$text</a>";
$html .= "</div>";
return $html;
}
public function hookConfigForm($args)
{
include 'config_form.php';
}
public function hookConfig($args)
{
$post = $args['post'];
$elements = array();
$elTable = get_db()->getTable('Element');
foreach($post['element_sets'] as $elId) {
$element = $elTable->find($elId);
$elSet = $element->getElementSet();
if(!array_key_exists($elSet->name, $elements)) {
$elements[$elSet->name] = array();
}
$elements[$elSet->name][] = $element->name;
}
set_option('corrections_email', $post['corrections_email']);
set_option('corrections_text', $post['corrections_text']);
set_option('corrections_elements', json_encode($elements));
}
public function filterAdminNavigationMain($nav)
{
$nav['Corrections'] = array(
'label' => __('Corrections'),
'uri' => url('corrections',
array('status' => 'submitted')));
return $nav;
}
}