-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.php
More file actions
executable file
·68 lines (50 loc) · 1.86 KB
/
plugin.php
File metadata and controls
executable file
·68 lines (50 loc) · 1.86 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
<?php
add_plugin_hook('install', 'item_show_log_install');
add_plugin_hook('uninstall', 'item_show_log_uninstall');
add_plugin_hook('admin_theme_header','item_show_log_admin_theme_header');
add_plugin_hook('admin_append_to_items_show_secondary', 'item_show_log_admin_append_to_items_show_secondary');
add_plugin_hook('public_append_to_items_show', 'item_show_log_public_append_to_items_show');
add_filter('admin_navigation_main', 'adminNavigationMain');
function item_show_log_install()
{
$db = get_db();
$sql = "
CREATE TABLE `{$db->prefix}item_show_log_logs` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`item_id` int(10) unsigned NOT NULL,
`ip_address` tinytext COLLATE utf8_unicode_ci NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;";
$db->exec($sql);
}
function item_show_log_uninstall()
{
$db = get_db();
$sql = "DROP TABLE IF EXISTS `{$db->prefix}item_show_log_logs` ; ";
$db->exec($sql);
}
function item_show_log_public_append_to_items_show()
{
$item = get_current_item();
$newLogRecord = new ItemShowLogLog();
$newLogRecord->item_id = $item->id;
$newLogRecord->timestamp = date('Y-m-d H:i:s');
$newLogRecord->ip_address =$_SERVER['REMOTE_ADDR'];
$newLogRecord->save();
# print_r($newLogRecord);
}
function item_show_log_admin_theme_header() {
echo "<link rel='stylesheet' href='" . css('itemshowlog') . "' />";
}
function item_show_log_admin_append_to_items_show_secondary()
{
$item = get_current_item();
$log_count = get_db()->getTable('ItemShowLogLog')->findCountByItemId($item->id);
echo "<div class='info-panel'><h2>Log data</h2><p>Viewed $log_count times in public view.</p></div>";
}
function adminNavigationMain($nav)
{
$nav['Item Show Log'] = uri('item-show-log');
return $nav;
}