-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectCachePlugin.php
More file actions
171 lines (140 loc) · 3.62 KB
/
ObjectCachePlugin.php
File metadata and controls
171 lines (140 loc) · 3.62 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/*
Plugin Name: Spicy Pixel Object Cache
Plugin URI: http://spicypixel.com/
Description: A persistent memory cache.
Version: 1.0.0
Author: Spicy Pixel
Author URI: http://spicypixel.com
*/
defined('SPOC_DIR') || define('SPOC_DIR', realpath(dirname(__FILE__)));
require_once(SPOC_DIR . '/Define.php');
class SpicyPixel_ObjectCache_Plugin {
/**
* Runs plugin
*/
function run() {
register_activation_hook(SPOC_FILE, array(
&$this,
'activate'
));
register_deactivation_hook(SPOC_FILE, array(
&$this,
'deactivate'
));
add_action('shutdown', array(
&$this,
'echo_stats_comment'
));
add_action('publish_phone', array(
&$this,
'on_change'
), 0);
add_action('publish_post', array(
&$this,
'on_change'
), 0);
add_action('edit_post', array(
&$this,
'on_change'
), 0);
add_action('delete_post', array(
&$this,
'on_change'
), 0);
add_action('comment_post', array(
&$this,
'on_change'
), 0);
add_action('edit_comment', array(
&$this,
'on_change'
), 0);
add_action('delete_comment', array(
&$this,
'on_change'
), 0);
add_action('wp_set_comment_status', array(
&$this,
'on_change'
), 0);
add_action('trackback_post', array(
&$this,
'on_change'
), 0);
add_action('pingback_post', array(
&$this,
'on_change'
), 0);
add_action('switch_theme', array(
&$this,
'on_change'
), 0);
add_action('edit_user_profile_update', array(
&$this,
'on_change'
), 0);
}
function echo_stats_comment() {
global $wp_object_cache;
if(!isset($wp_object_cache))
return;
// TODO: Make this a toggle
echo "\n<!-- Spicy Pixel Object Cache\n";
if(method_exists($wp_object_cache, 'stats_comment'))
$wp_object_cache->stats_comment();
echo "-->\n";
}
/**
* Check if plugin is locked
*
* @return boolean
*/
function locked() {
static $locked = null;
if ($locked === null) {
if (sp_is_network() && function_exists('get_blog_list')) {
global $blog_id;
$blogs = get_blog_list();
foreach ($blogs as $blog) {
if ($blog['blog_id'] != $blog_id) {
$active_plugins = get_blog_option($blog['blog_id'], 'active_plugins');
if (in_array(SPOC_FILE, $active_plugins)) {
$locked = true;
break;
}
}
}
}
else {
$locked = false;
}
}
return $locked;
}
/**
* Activate plugin
*/
function activate() {
if (!$this->locked() && !@copy(SPOC_INSTALL_OBJECT_CACHE, SPOC_ADDIN_OBJECT_CACHE)) {
sp_error("Unable to copy " . SPOC_INSTALL_OBJECT_CACHE . " to " . SPOC_ADDIN_OBJECT_CACHE);
}
}
/**
* Deactivate plugin
*/
function deactivate() {
if (!$this->locked()) {
@unlink(SPOC_ADDIN_OBJECT_CACHE);
}
}
/**
* Change action
*/
function on_change() {
// TODO: flush cache
}
}
$spoc_plugin = new SpicyPixel_ObjectCache_Plugin();
$spoc_plugin->run();
?>