Repository navigation
Expand file tree
/
Copy pathEmbedCodesPlugin.php
More file actions
118 lines (106 loc) · 3.88 KB
/
Copy pathEmbedCodesPlugin.php
File metadata and controls
118 lines (106 loc) · 3.88 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
<?php
class EmbedCodesPlugin extends Omeka_Plugin_AbstractPlugin
{
protected $_hooks = [
'install',
'uninstall',
'define_routes',
'public_items_show',
'admin_items_show_sidebar',
'admin_items_browse_detailed_each',
'initialize',
];
protected $_filters = ['admin_navigation_main'];
public function hookInitialize()
{
add_translation_source(dirname(__FILE__) . '/languages');
}
public function hookInstall()
{
$db = $this->_db;
$sql = "
CREATE TABLE IF NOT EXISTS `$db->Embed` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`item_id` int(10) unsigned NOT NULL,
`url` text NOT NULL,
`host` tinytext NOT NULL,
`first_view` date DEFAULT NULL,
`last_view` date DEFAULT NULL,
`view_count` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB; ";
$db->query($sql);
}
public function hookUninstall()
{
$db = $this->_db;
$sql = "DROP TABLE IF EXISTS `$db->Embed`; ";
$db->query($sql);
}
public function hookPublicItemsShow($args)
{
$item = $args['item'];
$uri = absolute_url(['controller' => 'items', 'action' => 'embed', 'id' => $item->id], 'id');
$html = "<div id='embed-codes'><h2>" . __('Embed') . "</h2>";
$html .= '<p><label for="embed-code-text">' . __("Copy the code below into your web page") . '</label></p>';
$iFrameHtml = "<iframe class='omeka-embed' src='$uri' style='margin: 2em 0; border: 1px solid #e7e7e7' width='315px' height='285px' frameborder='0' allowfullscreen></iframe>";
$html .= "<textarea id='embed-code-text' style='font-family:monospace' rows='4' readonly>$iFrameHtml</textarea>";
$html .= "</div>";
echo $html;
}
public function hookAdminItemsBrowseDetailedEach($args)
{
$item = $args['item'];
$embedTable = get_db()->getTable('Embed');
$totalEmbeds = $embedTable->totalEmbeds($item->id);
$html = '<p>';
$html .= "<a href='" . url('embed-codes/item/' . $item->id) . "'>" . __('Embeds (%d)', $totalEmbeds) . "</a>";
$html .= '</p>';
echo $html;
}
public function hookAdminItemsShowSidebar($args)
{
$item = $args['item'];
$embedTable = get_db()->getTable('Embed');
$totalEmbeds = $embedTable->totalEmbeds($item->id);
$allEmbeds = $embedTable->findBy(['item_id'=>$item->id]);
$html = "<div class='embed-codes panel'>";
$html .= "<h4>" . __("Embeds") . "</h4>";
$html .= "<a href='" . url('embed-codes/item/' . $item->id) . "'>" . __('Details') . "</a>";
$html .= "<p>" . __("Total views: %d", $totalEmbeds) . "</p>";
$html .= "<p>" . __("Total embeds: %d", count($allEmbeds)) . "</p>";
$html .= "</div>";
echo $html;
}
public function hookDefineRoutes($array)
{
$router = $array['router'];
$router->addRoute(
'embed',
new Zend_Controller_Router_Route(
'items/embed/:id',
[
'module' => 'embed-codes',
'controller' => 'index',
'action' => 'embed',
]
)
);
$router->addRoute(
'embed-item',
new Zend_Controller_Router_Route(
'embed-codes/item/:id',
[
'module' => 'embed-codes',
'controller' => 'index',
'action' => 'item',
]
)
);
}
public function filterAdminNavigationMain($navArray)
{
$navArray['EmbedCodes'] = ['label' => __('Embedded Items'), 'uri' => url('embed-codes')];
return $navArray;
}
}