InfiniteWP Client - Version 0.1.4

Version Description

Download this release

Release Info

Developer infinitewp
Plugin Icon 128x128 InfiniteWP Client
Version 0.1.4
Comparing to
See all releases

Version 0.1.4

api.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /************************************************************
3
+ * This plugin was modified by Revmakx *
4
+ * Copyright (c) 2012 Revmakx *
5
+ * www.revmakx.com *
6
+ * *
7
+ ************************************************************/
8
+ /*************************************************************
9
+ *
10
+ * api.php
11
+ *
12
+ * InfiniteWP addons api
13
+ *
14
+ * Copyright (c) 2011 Prelovac Media
15
+ * www.prelovac.com
16
+ **************************************************************/
17
+ if( !function_exists('iwp_mmb_add_action')) :
18
+ function iwp_mmb_add_action($action = false, $callback = false)
19
+ {
20
+ if (!$action || !$callback)
21
+ return false;
22
+
23
+ global $iwp_mmb_actions;
24
+ iwp_mmb_function_exists($callback);
25
+
26
+ if (isset($iwp_mmb_actions[$action]))
27
+ wp_die('Cannot redeclare InfiniteWP action "' . $action . '".');
28
+
29
+ $iwp_mmb_actions[$action] = $callback;
30
+ }
31
+ endif;
32
+
33
+ if( !function_exists('iwp_mmb_function_exists') ) :
34
+ function iwp_mmb_function_exists($callback)
35
+ {
36
+ global $iwp_core;
37
+ if (count($callback) === 2) {
38
+ if (!method_exists($callback[0], $callback[1]))
39
+ wp_die($iwp_core->iwp_dashboard_widget('Information', '', '<p>Class ' . get_class($callback[0]) . ' does not contain <b>"' . $callback[1] . '"</b> function</p>', '', '50%'));
40
+ } else {
41
+ if (!function_exists($callback))
42
+ wp_die($iwp_core->iwp_dashboard_widget('Information', '', '<p>Function <b>"' . $callback . '"</b> does not exists.</p>', '', '50%'));
43
+ }
44
+ }
45
+ endif;
46
+
47
+ ?>
backup.class.php ADDED
@@ -0,0 +1,2060 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /************************************************************
3
+ * This plugin was modified by Revmakx *
4
+ * Copyright (c) 2012 Revmakx *
5
+ * www.revmakx.com *
6
+ * *
7
+ ************************************************************/
8
+ /*************************************************************
9
+ *
10
+ * backup.class.php
11
+ *
12
+ * Manage Backups
13
+ *
14
+ *
15
+ * Copyright (c) 2011 Prelovac Media
16
+ * www.prelovac.com
17
+ **************************************************************/
18
+ define('IWP_BACKUP_DIR', WP_CONTENT_DIR . '/infinitewp/backups');
19
+ define('IWP_DB_DIR', IWP_BACKUP_DIR . '/iwp_db');
20
+
21
+ $zip_errors = array(
22
+ 'No error',
23
+ 'No error',
24
+ 'Unexpected end of zip file',
25
+ 'A generic error in the zipfile format was detected.',
26
+ 'zip was unable to allocate itself memory',
27
+ 'A severe error in the zipfile format was detected',
28
+ 'Entry too large to be split with zipsplit',
29
+ 'Invalid comment format',
30
+ 'zip -T failed or out of memory',
31
+ 'The user aborted zip prematurely',
32
+ 'zip encountered an error while using a temp file',
33
+ 'Read or seek error',
34
+ 'zip has nothing to do',
35
+ 'Missing or empty zip file',
36
+ 'Error writing to a file',
37
+ 'zip was unable to create a file to write to',
38
+ 'bad command line parameters',
39
+ 'no error',
40
+ 'zip could not open a specified file to read'
41
+ );
42
+ $unzip_errors = array(
43
+ 'No error',
44
+ 'One or more warning errors were encountered, but processing completed successfully anyway',
45
+ 'A generic error in the zipfile format was detected',
46
+ 'A severe error in the zipfile format was detected.',
47
+ 'unzip was unable to allocate itself memory.',
48
+ 'unzip was unable to allocate memory, or encountered an encryption error',
49
+ 'unzip was unable to allocate memory during decompression to disk',
50
+ 'unzip was unable allocate memory during in-memory decompression',
51
+ 'unused',
52
+ 'The specified zipfiles were not found',
53
+ 'Bad command line parameters',
54
+ 'No matching files were found',
55
+ 50 => 'The disk is (or was) full during extraction',
56
+ 51 => 'The end of the ZIP archive was encountered prematurely.',
57
+ 80 => 'The user aborted unzip prematurely.',
58
+ 81 => 'Testing or extraction of one or more files failed due to unsupported compression methods or unsupported decryption.',
59
+ 82 => 'No files were found due to bad decryption password(s)'
60
+ );
61
+
62
+
63
+ class IWP_MMB_Backup extends IWP_MMB_Core
64
+ {
65
+ var $site_name;
66
+ var $statuses;
67
+ var $tasks;
68
+ var $s3;
69
+ var $ftp;
70
+ var $dropbox;
71
+ function __construct()
72
+ {
73
+ parent::__construct();
74
+ $this->site_name = str_replace(array(
75
+ "_",
76
+ "/"
77
+ ), array(
78
+ "",
79
+ "-"
80
+ ), rtrim($this->remove_http(get_bloginfo('url')), "/"));
81
+ $this->statuses = array(
82
+ 'db_dump' => 1,
83
+ 'db_zip' => 2,
84
+ 'files_zip' => 3,
85
+ /*
86
+ //IWP Remove starts here
87
+ 's3' => 4,
88
+ 'dropbox' => 5,
89
+ 'ftp' => 6,
90
+ 'email' => 7,
91
+ //IWP Remove ends here
92
+ */
93
+ 'finished' => 100
94
+ );
95
+ $this->tasks = get_option('iwp_client_backup_tasks');
96
+ }
97
+
98
+ function get_backup_settings()
99
+ {
100
+ $backup_settings = get_option('iwp_client_backup_tasks');
101
+ if (!empty($backup_settings))
102
+ return $backup_settings;
103
+ else
104
+ return false;
105
+ }
106
+
107
+ function set_backup_task($params)
108
+ {
109
+ //$params => [$task_name, $args, $error]
110
+ if (!empty($params)) {
111
+ extract($params);
112
+
113
+ //$before = $this->get_backup_settings();
114
+ $before = $this->tasks;
115
+ if (!$before || empty($before))
116
+ $before = array();
117
+
118
+ if (isset($args['remove'])) {
119
+ unset($before[$task_name]);
120
+ $return = array(
121
+ 'removed' => true
122
+ );
123
+ } else {
124
+ /*
125
+ //IWP Remove starts here
126
+ if (is_array($params['account_info'])) { //only if sends from IWP Admin Panel first time(secure data)
127
+ $args['account_info'] = $account_info;
128
+ }
129
+ //IWP Remove ends here
130
+ */
131
+ $before[$task_name]['task_args'] = $args;
132
+ /*
133
+ //IWP Remove starts here
134
+ if (strlen($args['schedule']))
135
+ $before[$task_name]['task_args']['next'] = $this->schedule_next($args['type'], $args['schedule']);
136
+ //IWP Remove ends here
137
+ */
138
+ $return = $before[$task_name];
139
+ }
140
+
141
+ //Update with error
142
+ if ($error) {
143
+ if (is_array($error)) {
144
+ $before[$task_name]['task_results'][count($before[$task_name]['task_results']) - 1]['error'] = $error['error'];
145
+ } else {
146
+ $before[$task_name]['task_results'][count($before[$task_name]['task_results'])]['error'] = $error;
147
+ }
148
+ }
149
+
150
+ if ($time) { //set next result time before backup
151
+ if (is_array($before[$task_name]['task_results'])) {
152
+ $before[$task_name]['task_results'] = array_values($before[$task_name]['task_results']);
153
+ }
154
+ $before[$task_name]['task_results'][count($before[$task_name]['task_results'])]['time'] = $time;
155
+ }
156
+
157
+ $this->update_tasks($before);
158
+ //update_option('iwp_client_backup_tasks', $before);
159
+
160
+ if ($task_name == 'Backup Now') {
161
+ $result = $this->backup($args, $task_name);
162
+ $backup_settings = $this->tasks;
163
+
164
+ if (is_array($result) && array_key_exists('error', $result)) {
165
+ $return = $result;
166
+ } else {
167
+ $return = $backup_settings[$task_name];
168
+ }
169
+ }
170
+ return $return;
171
+ }
172
+ return false;
173
+ }
174
+
175
+ //Cron check
176
+ function check_backup_tasks()
177
+ {
178
+ $settings = $this->tasks;
179
+ if (is_array($settings) && !empty($settings)) {
180
+ foreach ($settings as $task_name => $setting) {
181
+
182
+ if ($setting['task_args']['next'] && $setting['task_args']['next'] < time()) {
183
+ //if ($setting['task_args']['next'] && $_GET['force_backup']) {
184
+ if ($setting['task_args']['url'] && $setting['task_args']['task_id'] && $setting['task_args']['site_key']) {
185
+ //Check orphan task
186
+ $check_data = array(
187
+ 'task_name' => $task_name,
188
+ 'task_id' => $setting['task_args']['task_id'],
189
+ 'site_key' => $setting['task_args']['site_key']
190
+ );
191
+
192
+ $check = $this->validate_task($check_data, $setting['task_args']['url']);
193
+
194
+ }
195
+
196
+ $update = array(
197
+ 'task_name' => $task_name,
198
+ 'args' => $settings[$task_name]['task_args']
199
+ );
200
+
201
+
202
+ if($check != 'paused'){
203
+ $update['time'] = time();
204
+ }
205
+
206
+ //Update task with next schedule
207
+ $this->set_backup_task($update);
208
+
209
+ if($check == 'paused'){
210
+ continue;
211
+ }
212
+
213
+
214
+ $result = $this->backup($setting['task_args'], $task_name);
215
+ $error = '';
216
+ if (is_array($result) && array_key_exists('error', $result)) {
217
+ $error = $result;
218
+ $this->set_backup_task(array(
219
+ 'task_name' => $task_name,
220
+ 'args' => $settings[$task_name]['task_args'],
221
+ 'error' => $error
222
+ ));
223
+ } else {
224
+ $error = '';
225
+ }
226
+ break; //Only one backup per cron
227
+ }
228
+ }
229
+ }
230
+
231
+ }
232
+
233
+ /*
234
+ //IWP Remove starts here
235
+ function task_now($task_name){
236
+
237
+ $settings = $this->tasks;
238
+ if(!array_key_exists($task_name,$settings)){
239
+ return array('error' => $task_name." does not exist.");
240
+ } else {
241
+ $setting = $settings[$task_name];
242
+ }
243
+
244
+ $this->set_backup_task(array(
245
+ 'task_name' => $task_name,
246
+ 'args' => $settings[$task_name]['task_args'],
247
+ 'time' => time()
248
+ ));
249
+
250
+ //Run backup
251
+ $result = $this->backup($setting['task_args'], $task_name);
252
+
253
+ //Check for error
254
+ if (is_array($result) && array_key_exists('error', $result)) {
255
+ $this->set_backup_task(array(
256
+ 'task_name' => $task_name,
257
+ 'args' => $settings[$task_name]['task_args'],
258
+ 'error' => $result['error']
259
+ ));
260
+ return $result;
261
+ } else {
262
+ return $this->get_backup_stats();
263
+ }
264
+
265
+ }
266
+ //IWP Remove ends here
267
+ */
268
+
269
+
270
+
271
+ /*
272
+ * If Task Name not set then it's manual backup
273
+ * Backup args:
274
+ * type -> db, full
275
+ * what -> daily, weekly, monthly
276
+ * account_info -> ftp, amazons3, dropbox
277
+ * exclude-> array of paths to exclude from backup
278
+ */
279
+
280
+ function backup($args, $task_name = false)
281
+ {
282
+ if (!$args || empty($args))
283
+ return false;
284
+
285
+ extract($args); //extract settings
286
+
287
+ //Try increase memory limit and execution time
288
+ @ini_set('memory_limit', '256M');
289
+ @set_time_limit(600); //ten minutes
290
+
291
+ //Remove old backup(s)
292
+ $this->remove_old_backups($task_name);
293
+
294
+ $new_file_path = IWP_BACKUP_DIR;
295
+
296
+ if (!file_exists($new_file_path)) {
297
+ if (!mkdir($new_file_path, 0755, true))
298
+ return array(
299
+ 'error' => 'Permission denied, make sure you have write permission to wp-content folder.'
300
+ );
301
+ }
302
+
303
+ @file_put_contents($new_file_path . '/index.php', ''); //safe
304
+
305
+ //Prepare .zip file name
306
+ $hash = md5(time());
307
+ $label = $type ? $type : 'manual';
308
+ $backup_file = $new_file_path . '/' . $this->site_name . '_' . $label . '_' . $what . '_' . date('Y-m-d') . '_' . $hash . '.zip';
309
+ $backup_url = WP_CONTENT_URL . '/infinitewp/backups/' . $this->site_name . '_' . $label . '_' . $what . '_' . date('Y-m-d') . '_' . $hash . '.zip';
310
+
311
+ //Optimize tables?
312
+ if (isset($optimize_tables) && !empty($optimize_tables)) {
313
+ $this->optimize_tables();
314
+ }
315
+
316
+ //What to backup - db or full?
317
+ if (trim($what) == 'db') {
318
+ //Take database backup
319
+ $this->update_status($task_name, $this->statuses['db_dump']);
320
+ $db_result = $this->backup_db();
321
+ if ($db_result == false) {
322
+ return array(
323
+ 'error' => 'Failed to backup database.'
324
+ );
325
+ } else if (is_array($db_result) && isset($db_result['error'])) {
326
+ return array(
327
+ 'error' => $db_result['error']
328
+ );
329
+ } else {
330
+ $this->update_status($task_name, $this->statuses['db_dump'], true);
331
+ $this->update_status($task_name, $this->statuses['db_zip']);
332
+
333
+ $disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
334
+ $comp_level = $disable_comp ? '-0' : '-1';
335
+
336
+ chdir(IWP_BACKUP_DIR);
337
+ $zip = $this->get_zip();
338
+ $command = "$zip -q -r $comp_level $backup_file 'iwp_db'";
339
+ ob_start();
340
+ $result = $this->iwp_mmb_exec($command);
341
+ ob_get_clean();
342
+ if (!$result) { // fallback to pclzip
343
+ define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
344
+ require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
345
+ $archive = new PclZip($backup_file);
346
+ if ($disable_comp) {
347
+ $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
348
+ } else {
349
+ $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
350
+ }
351
+ @unlink($db_result);
352
+ @rmdir(IWP_DB_DIR);
353
+ if (!$result) {
354
+ return array(
355
+ 'error' => 'Failed to zip database (pclZip - ' . $archive->error_code . '): .' . $archive->error_string
356
+ );
357
+ }
358
+ }
359
+
360
+ @unlink($db_result);
361
+ @rmdir(IWP_DB_DIR);
362
+ if (!$result) {
363
+ return array(
364
+ 'error' => 'Failed to zip database.'
365
+ );
366
+ }
367
+ $this->update_status($task_name, $this->statuses['db_zip'], true);
368
+ }
369
+ } elseif (trim($what) == 'full') {
370
+ $content_backup = $this->backup_full($task_name, $backup_file, $exclude, $include);
371
+ if (is_array($content_backup) && array_key_exists('error', $content_backup)) {
372
+ return array(
373
+ 'error' => $content_backup['error']
374
+ );
375
+ }
376
+ }
377
+
378
+ //Update backup info
379
+ if ($task_name) {
380
+ //backup task (scheduled)
381
+ $backup_settings = $this->tasks;
382
+ $paths = array();
383
+ $size = ceil(filesize($backup_file) / 1024);
384
+
385
+ if ($size > 1000) {
386
+ $paths['size'] = ceil($size / 1024) . "MB";//Modified by IWP //Mb => MB
387
+ } else {
388
+ $paths['size'] = $size . 'KB';//Modified by IWP //Kb => KB
389
+ }
390
+
391
+ $paths['backup_name'] = $backup_settings[$task_name]['task_args']['backup_name'];
392
+
393
+ if ($task_name != 'Backup Now') {
394
+ if (!$backup_settings[$task_name]['task_args']['del_host_file']) {
395
+ $paths['server'] = array(
396
+ 'file_path' => $backup_file,
397
+ 'file_url' => $backup_url
398
+ );
399
+ }
400
+ } else {
401
+ $paths['server'] = array(
402
+ 'file_path' => $backup_file,
403
+ 'file_url' => $backup_url
404
+ );
405
+ }
406
+
407
+ /*
408
+ //IWP Remove starts here
409
+ if (isset($backup_settings[$task_name]['task_args']['account_info']['iwp_ftp'])) {
410
+ $paths['ftp'] = basename($backup_url);
411
+ }
412
+
413
+ if (isset($backup_settings[$task_name]['task_args']['account_info']['iwp_amazon_s3'])) {
414
+ $paths['amazons3'] = basename($backup_url);
415
+ }
416
+
417
+ if (isset($backup_settings[$task_name]['task_args']['account_info']['iwp_dropbox'])) {
418
+ $paths['dropbox'] = basename($backup_url);
419
+ }
420
+
421
+ if (isset($backup_settings[$task_name]['task_args']['account_info']['iwp_email'])) {
422
+ $paths['email'] = basename($backup_url);
423
+ }
424
+ //IWP Remove ends here
425
+ */
426
+
427
+ $temp = $backup_settings[$task_name]['task_results'];
428
+ $temp = array_values($temp);
429
+ $paths['time'] = time();
430
+
431
+
432
+ if ($task_name != 'Backup Now') {
433
+ $paths['status'] = $temp[count($temp) - 1]['status'];
434
+ $temp[count($temp) - 1] = $paths;
435
+
436
+ } else {
437
+ $temp[count($temp)] = $paths;
438
+ }
439
+
440
+ $backup_settings[$task_name]['task_results'] = $temp;
441
+ $this->update_tasks($backup_settings);
442
+ //update_option('iwp_client_backup_tasks', $backup_settings);
443
+ }
444
+
445
+
446
+ //Additional: Email, ftp, amazon_s3, dropbox...
447
+
448
+ if ($task_name != 'Backup Now') {
449
+ /*
450
+ //IWP Remove starts here
451
+ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
452
+ $this->update_status($task_name, $this->statuses['ftp']);
453
+ $account_info['iwp_ftp']['backup_file'] = $backup_file;
454
+ $ftp_result = $this->ftp_backup($account_info['iwp_ftp']);
455
+
456
+ if ($ftp_result !== true && $del_host_file) {
457
+ @unlink($backup_file);
458
+ }
459
+
460
+ if (is_array($ftp_result) && isset($ftp_result['error'])) {
461
+ return $ftp_result;
462
+ }
463
+ $this->wpdb_reconnect();
464
+ $this->update_status($task_name, $this->statuses['ftp'], true);
465
+ }
466
+
467
+ if (isset($account_info['iwp_amazon_s3']) && !empty($account_info['iwp_amazon_s3'])) {
468
+ $this->update_status($task_name, $this->statuses['s3']);
469
+ $account_info['iwp_amazon_s3']['backup_file'] = $backup_file;
470
+ $amazons3_result = $this->amazons3_backup($account_info['iwp_amazon_s3']);
471
+ if ($amazons3_result !== true && $del_host_file) {
472
+ @unlink($backup_file);
473
+ }
474
+ if (is_array($amazons3_result) && isset($amazons3_result['error'])) {
475
+ return $amazons3_result;
476
+ }
477
+ $this->wpdb_reconnect();
478
+ $this->update_status($task_name, $this->statuses['s3'], true);
479
+ }
480
+
481
+ if (isset($account_info['iwp_dropbox']) && !empty($account_info['iwp_dropbox'])) {
482
+ $this->update_status($task_name, $this->statuses['dropbox']);
483
+ $account_info['iwp_dropbox']['backup_file'] = $backup_file;
484
+ $dropbox_result = $this->dropbox_backup($account_info['iwp_dropbox']);
485
+ if ($dropbox_result !== true && $del_host_file) {
486
+ @unlink($backup_file);
487
+ }
488
+
489
+ if (is_array($dropbox_result) && isset($dropbox_result['error'])) {
490
+ return $dropbox_result;
491
+ }
492
+ $this->wpdb_reconnect();
493
+ $this->update_status($task_name, $this->statuses['dropbox'], true);
494
+ }
495
+
496
+ if (isset($account_info['iwp_email']) && !empty($account_info['iwp_email'])) {
497
+ $this->update_status($task_name, $this->statuses['email']);
498
+ $account_info['iwp_email']['task_name'] = $task_name;
499
+ $account_info['iwp_email']['file_path'] = $backup_file;
500
+
501
+ $email_result = $this->email_backup($account_info['iwp_email']);
502
+ if (is_array($email_result) && isset($email_result['error'])) {
503
+ return $email_result;
504
+ }
505
+ $this->update_status($task_name, $this->statuses['email'], true);
506
+ }
507
+ //IWP Remove ends here
508
+ */
509
+
510
+ if ($del_host_file) {
511
+ @unlink($backup_file);
512
+ }
513
+
514
+ } //end additional
515
+
516
+ //$this->update_status($task_name,$this->statuses['finished'],true);
517
+ return $backup_url; //Return url to backup file
518
+ }
519
+
520
+ function backup_full($task_name, $backup_file, $exclude = array(), $include = array())
521
+ {
522
+ global $zip_errors;
523
+ $sys = substr(PHP_OS, 0, 3);
524
+
525
+ $this->update_status($task_name, $this->statuses['db_dump']);
526
+ $db_result = $this->backup_db();
527
+
528
+ if ($db_result == false) {
529
+ return array(
530
+ 'error' => 'Failed to backup database.'
531
+ );
532
+ } else if (is_array($db_result) && isset($db_result['error'])) {
533
+ return array(
534
+ 'error' => $db_result['error']
535
+ );
536
+ }
537
+
538
+ $this->update_status($task_name, $this->statuses['db_dump'], true);
539
+ $this->update_status($task_name, $this->statuses['db_zip']);
540
+ $disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
541
+ $comp_level = $disable_comp ? '-0' : '-1';
542
+
543
+ $zip = $this->get_zip();
544
+ //Add database file
545
+ chdir(IWP_BACKUP_DIR);
546
+ $command = "$zip -q -r $comp_level $backup_file 'iwp_db'";
547
+ ob_start();
548
+ $result = $this->iwp_mmb_exec($command);
549
+ ob_get_clean();
550
+
551
+
552
+ if (!$result) {
553
+ define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
554
+ require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
555
+ $archive = new PclZip($backup_file);
556
+
557
+ if ($disable_comp) {
558
+ $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
559
+ } else {
560
+ $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
561
+ }
562
+
563
+ @unlink($db_result);
564
+ @rmdir(IWP_DB_DIR);
565
+
566
+ if (!$result_db) {
567
+ return array(
568
+ 'error' => 'Failed to zip database. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
569
+ );
570
+ }
571
+ }
572
+
573
+ @unlink($db_result);
574
+ @rmdir(IWP_DB_DIR);
575
+
576
+ $this->update_status($task_name, $this->statuses['db_zip'], true);
577
+
578
+
579
+ //Always remove backup folders
580
+ $remove = array(
581
+ trim(basename(WP_CONTENT_DIR)) . "/infinitewp/backups",
582
+ trim(basename(WP_CONTENT_DIR)) . "/" . md5('iwp_mmb-client') . "/iwp_backups"
583
+ );
584
+
585
+ //Exclude paths
586
+ $exclude_data = "-x";
587
+
588
+ if (!empty($exclude)) {
589
+ foreach ($exclude as $data) {
590
+ if (is_dir(ABSPATH . $data)) {
591
+ if ($sys == 'WIN')
592
+ $exclude_data .= " $data/*.*";
593
+ else
594
+ $exclude_data .= " '$data/*'";
595
+ } else {
596
+ if ($sys == 'WIN')
597
+ $exclude_data .= " $data";
598
+ else
599
+ $exclude_data .= " '$data'";
600
+ }
601
+ }
602
+ }
603
+
604
+ foreach ($remove as $data) {
605
+ if ($sys == 'WIN')
606
+ $exclude_data .= " $data/*.*";
607
+ else
608
+ $exclude_data .= " '$data/*'";
609
+ }
610
+
611
+ //Include paths by default
612
+ $add = array(
613
+ trim(WPINC),
614
+ trim(basename(WP_CONTENT_DIR)),
615
+ "wp-admin"
616
+ );
617
+
618
+ $include_data = ". -i";
619
+ foreach ($add as $data) {
620
+ if ($sys == 'WIN')
621
+ $include_data .= " $data/*.*";
622
+ else
623
+ $include_data .= " '$data/*'";
624
+ }
625
+
626
+ //Additional includes?
627
+ if (!empty($include)) {
628
+ foreach ($include as $data) {
629
+ if ($data) {
630
+ if ($sys == 'WIN')
631
+ $include_data .= " $data/*.*";
632
+ else
633
+ $include_data .= " '$data/*'";
634
+ }
635
+ }
636
+ }
637
+
638
+ $this->update_status($task_name, $this->statuses['files_zip']);
639
+ chdir(ABSPATH);
640
+ ob_start();
641
+ $command = "$zip -q -j $comp_level $backup_file .* * $exclude_data";
642
+ $result_f = $this->iwp_mmb_exec($command, false, true);
643
+ if (!$result_f || $result_f == 18) { // disregard permissions error, file can't be accessed
644
+ $command = "$zip -q -r $comp_level $backup_file $include_data $exclude_data";
645
+ $result_d = $this->iwp_mmb_exec($command, false, true);
646
+ if ($result_d && $result_d != 18) {
647
+ @unlink($backup_file);
648
+ if ($result_d > 0 && $result_d < 18)
649
+ return array(
650
+ 'error' => 'Failed to archive files (' . $zip_errors[$result_d] . ') .'
651
+ );
652
+ else
653
+ return array(
654
+ 'error' => 'Failed to archive files.'
655
+ );
656
+ }
657
+ }
658
+ ob_get_clean();
659
+
660
+ if ($result_f && $result_f != 18) { //Try pclZip
661
+
662
+ if (!isset($archive)) {
663
+ define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
664
+ require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
665
+ $archive = new PclZip($backup_file);
666
+ }
667
+
668
+ //Include paths
669
+ $include_data = array();
670
+ if (!empty($include)) {
671
+ foreach ($include as $data) {
672
+ if ($data && file_exists(ABSPATH . $data))
673
+ $include_data[] = ABSPATH . $data . '/';
674
+ }
675
+ }
676
+
677
+ foreach ($add as $data) {
678
+ if (file_exists(ABSPATH . $data))
679
+ $include_data[] = ABSPATH . $data . '/';
680
+ }
681
+
682
+ //Include root files
683
+ if ($handle = opendir(ABSPATH)) {
684
+ while (false !== ($file = readdir($handle))) {
685
+ if ($file != "." && $file != ".." && !is_dir($file) && file_exists(ABSPATH . $file)) {
686
+ $include_data[] = ABSPATH . $file;
687
+ }
688
+ }
689
+ closedir($handle);
690
+ }
691
+
692
+ if ($disable_comp) {
693
+ $result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_NO_COMPRESSION);
694
+ } else {
695
+ $result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH);
696
+ }
697
+ if (!$result) {
698
+ @unlink($backup_file);
699
+ return array(
700
+ 'error' => 'Failed to zip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
701
+ );
702
+ }
703
+
704
+ //Now exclude paths
705
+ $exclude_data = array();
706
+ if (!empty($exclude)) {
707
+ foreach ($exclude as $data) {
708
+ if (is_dir(ABSPATH . $data))
709
+ $exclude_data[] = $data . '/';
710
+ else
711
+ $exclude_data[] = $data;
712
+ }
713
+ }
714
+
715
+ foreach ($remove as $rem) {
716
+ $exclude_data[] = $rem . '/';
717
+ }
718
+
719
+ $result_excl = $archive->delete(PCLZIP_OPT_BY_NAME, $exclude_data);
720
+ if (!$result_excl) {
721
+ @unlink($backup_file);
722
+ return array(
723
+ 'error' => 'Failed to zip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
724
+ );
725
+ }
726
+
727
+ }
728
+
729
+ //Reconnect
730
+ $this->wpdb_reconnect();
731
+
732
+ $this->update_status($task_name, $this->statuses['files_zip'], true);
733
+ return true;
734
+ }
735
+
736
+
737
+ function backup_db()
738
+ {
739
+ $db_folder = IWP_DB_DIR . '/';
740
+ if (!file_exists($db_folder)) {
741
+ if (!mkdir($db_folder, 0755, true))
742
+ return array(
743
+ 'error' => 'Error creating database backup folder (' . $db_folder . '). Make sure you have corrrect write permissions.'
744
+ );
745
+ }
746
+
747
+ $file = $db_folder . DB_NAME . '.sql';
748
+ $result = $this->backup_db_dump($file); // try mysqldump always then fallback to php dump
749
+ return $result;
750
+ }
751
+
752
+ function backup_db_dump($file)
753
+ {
754
+ global $wpdb;
755
+ $paths = $this->check_mysql_paths();
756
+ $brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
757
+ $command = $brace . $paths['mysqldump'] . $brace . ' --host="' . DB_HOST . '" --user="' . DB_USER . '" --password="' . DB_PASSWORD . '" --add-drop-table --skip-lock-tables "' . DB_NAME . '" > ' . $brace . $file . $brace;
758
+ ob_start();
759
+ $result = $this->iwp_mmb_exec($command);
760
+ ob_get_clean();
761
+
762
+ if (!$result) { // Fallback to php
763
+ $result = $this->backup_db_php($file);
764
+ return $result;
765
+ }
766
+
767
+ if (filesize($file) == 0 || !is_file($file) || !$result) {
768
+ @unlink($file);
769
+ return false;
770
+ } else {
771
+ return $file;
772
+ }
773
+ }
774
+
775
+ function backup_db_php($file)
776
+ {
777
+ global $wpdb;
778
+ $tables = $wpdb->get_results('SHOW TABLES', ARRAY_N);
779
+ foreach ($tables as $table) {
780
+ //drop existing table
781
+ $dump_data = "DROP TABLE IF EXISTS $table[0];";
782
+ //create table
783
+ $create_table = $wpdb->get_row("SHOW CREATE TABLE $table[0]", ARRAY_N);
784
+ $dump_data .= "\n\n" . $create_table[1] . ";\n\n";
785
+
786
+ $count = $wpdb->get_var("SELECT count(*) FROM $table[0]");
787
+ if ($count > 100)
788
+ $count = ceil($count / 100);
789
+ else if ($count > 0)
790
+ $count = 1;
791
+
792
+ for ($i = 0; $i < $count; $i++) {
793
+ $low_limit = $i * 100;
794
+ $qry = "SELECT * FROM $table[0] LIMIT $low_limit, 100";
795
+ $rows = $wpdb->get_results($qry, ARRAY_A);
796
+ if (is_array($rows)) {
797
+ foreach ($rows as $row) {
798
+ //insert single row
799
+ $dump_data .= "INSERT INTO $table[0] VALUES(";
800
+ $num_values = count($row);
801
+ $j = 1;
802
+ foreach ($row as $value) {
803
+ $value = addslashes($value);
804
+ $value = preg_replace("/\n/Ui", "\\n", $value);
805
+ $num_values == $j ? $dump_data .= "'" . $value . "'" : $dump_data .= "'" . $value . "', ";
806
+ $j++;
807
+ unset($value);
808
+ }
809
+ $dump_data .= ");\n";
810
+ }
811
+ }
812
+ }
813
+ $dump_data .= "\n\n\n";
814
+
815
+ unset($rows);
816
+ file_put_contents($file, $dump_data, FILE_APPEND);
817
+ unset($dump_data);
818
+ }
819
+
820
+ if (filesize($file) == 0 || !is_file($file)) {
821
+ @unlink($file);
822
+ return array(
823
+ 'error' => 'Database backup failed. Try to enable MySQL dump on your server.'
824
+ );
825
+ }
826
+
827
+ return $file;
828
+
829
+ }
830
+
831
+ function restore($args)
832
+ {
833
+ global $wpdb;
834
+ if (empty($args)) {
835
+ return false;
836
+ }
837
+
838
+ extract($args);
839
+ @ini_set('memory_limit', '256M');
840
+ @set_time_limit(600);
841
+
842
+ $unlink_file = true; //Delete file after restore
843
+
844
+ //Detect source
845
+ if ($backup_url) {
846
+ //This is for clone (overwrite)
847
+ include_once ABSPATH . 'wp-admin/includes/file.php';
848
+ $backup_file = download_url($backup_url);
849
+ if (is_wp_error($backup_file)) {
850
+ return array(
851
+ 'error' => 'Unable to download backup file ('.$backup_file->get_error_message().')'
852
+ );
853
+ }
854
+ $what = 'full';
855
+ } else {
856
+ $tasks = $this->tasks;
857
+ $task = $tasks[$task_name];
858
+ if (isset($task['task_results'][$result_id]['server'])) {
859
+ $backup_file = $task['task_results'][$result_id]['server']['file_path'];
860
+ $unlink_file = false; //Don't delete file if stored on server
861
+ } /*
862
+ //IWP Remove starts here
863
+ elseif (isset($task['task_results'][$result_id]['ftp'])) {
864
+ $ftp_file = $task['task_results'][$result_id]['ftp'];
865
+ $args = $task['task_args']['account_info']['iwp_ftp'];
866
+ $args['backup_file'] = $ftp_file;
867
+ $backup_file = $this->get_ftp_backup($args);
868
+ if ($backup_file == false) {
869
+ return array(
870
+ 'error' => 'Failed to download file from FTP.'
871
+ );
872
+ }
873
+ } elseif (isset($task['task_results'][$result_id]['amazons3'])) {
874
+ $amazons3_file = $task['task_results'][$result_id]['amazons3'];
875
+ $args = $task['task_args']['account_info']['iwp_amazon_s3'];
876
+ $args['backup_file'] = $ftp_file;
877
+ $backup_file = $this->get_amazons3_backup($args);
878
+ if ($backup_file == false) {
879
+ return array(
880
+ 'error' => 'Failed to download file from Amazon S3.'
881
+ );
882
+ }
883
+ }
884
+ //IWP Remove ends here
885
+ */
886
+
887
+ $what = $tasks[$task_name]['task_args']['what'];
888
+ }
889
+
890
+ if ($backup_file && file_exists($backup_file)) {
891
+ if ($overwrite) {
892
+ //Keep old db credentials before overwrite
893
+ if (!copy(ABSPATH . 'wp-config.php', ABSPATH . 'iwp-temp-wp-config.php')) {
894
+ @unlink($backup_file);
895
+ return array(
896
+ 'error' => 'Error creating wp-config. Please check your write permissions.'
897
+ );
898
+ }
899
+
900
+ $db_host = DB_HOST;
901
+ $db_user = DB_USER;
902
+ $db_password = DB_PASSWORD;
903
+ $home = rtrim(get_option('home'), "/");
904
+ $site_url = get_option('site_url');
905
+
906
+ $clone_options = array();
907
+ if (trim($clone_from_url) || trim($iwp_clone)) {
908
+
909
+ $clone_options['iwp_client_nossl_key'] = get_option('iwp_client_nossl_key');
910
+ $clone_options['iwp_client_public_key'] = get_option('iwp_client_public_key');
911
+ $clone_options['iwp_client_action_message_id'] = get_option('iwp_client_action_message_id');
912
+
913
+ }
914
+
915
+ $clone_options['iwp_client_backup_tasks'] = serialize(get_option('iwp_client_backup_tasks'));
916
+ $clone_options['iwp_client_notifications'] = serialize(get_option('iwp_client_notifications'));
917
+ $clone_options['iwp_client_pageview_alerts'] = serialize(get_option('iwp_client_pageview_alerts'));
918
+
919
+
920
+ } else {
921
+ $restore_options = array();
922
+ $restore_options['iwp_client_notifications'] = get_option('iwp_client_notifications');
923
+ $restore_options['iwp_client_pageview_alerts'] = get_option('iwp_client_pageview_alerts');
924
+ $restore_options['iwp_client_user_hit_count'] = get_option('iwp_client_user_hit_count');
925
+ }
926
+
927
+
928
+ chdir(ABSPATH);
929
+ $unzip = $this->get_unzip();
930
+ $command = "$unzip -o $backup_file";
931
+ ob_start();
932
+ $result = $this->iwp_mmb_exec($command);
933
+ ob_get_clean();
934
+
935
+ if (!$result) { //fallback to pclzip
936
+ define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
937
+ require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
938
+ $archive = new PclZip($backup_file);
939
+ $result = $archive->extract(PCLZIP_OPT_PATH, ABSPATH, PCLZIP_OPT_REPLACE_NEWER);
940
+ }
941
+
942
+ if ($unlink_file) {
943
+ @unlink($backup_file);
944
+ }
945
+
946
+ if (!$result) {
947
+ return array(
948
+ 'error' => 'Failed to unzip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
949
+ );
950
+ }
951
+
952
+ $db_result = $this->restore_db();
953
+
954
+ if (!$db_result) {
955
+ return array(
956
+ 'error' => 'Error restoring database.'
957
+ );
958
+ } else if(is_array($db_result) && isset($db_result['error'])){
959
+ return array(
960
+ 'error' => $db_result['error']
961
+ );
962
+ }
963
+
964
+ } else {
965
+ return array(
966
+ 'error' => 'Error restoring. Cannot find backup file.'
967
+ );
968
+ }
969
+
970
+ //Replace options and content urls
971
+ if ($overwrite) {
972
+ //Get New Table prefix
973
+ $new_table_prefix = trim($this->get_table_prefix());
974
+ //Retrieve old wp_config
975
+ @unlink(ABSPATH . 'wp-config.php');
976
+ //Replace table prefix
977
+ $lines = file(ABSPATH . 'iwp-temp-wp-config.php');
978
+
979
+ foreach ($lines as $line) {
980
+ if (strstr($line, '$table_prefix')) {
981
+ $line = '$table_prefix = "' . $new_table_prefix . '";' . PHP_EOL;
982
+ }
983
+ file_put_contents(ABSPATH . 'wp-config.php', $line, FILE_APPEND);
984
+ }
985
+
986
+ @unlink(ABSPATH . 'iwp-temp-wp-config.php');
987
+
988
+ //Replace options
989
+ $query = "SELECT option_value FROM " . $new_table_prefix . "options WHERE option_name = 'home'";
990
+ $old = $wpdb->get_var($wpdb->prepare($query));
991
+ $old = rtrim($old, "/");
992
+ $query = "UPDATE " . $new_table_prefix . "options SET option_value = '$home' WHERE option_name = 'home'";
993
+ $wpdb->query($wpdb->prepare($query));
994
+ $query = "UPDATE " . $new_table_prefix . "options SET option_value = '$home' WHERE option_name = 'siteurl'";
995
+ $wpdb->query($wpdb->prepare($query));
996
+ //Replace content urls
997
+ $query = "UPDATE " . $new_table_prefix . "posts SET post_content = REPLACE (post_content, '$old','$home') WHERE post_content REGEXP 'src=\"(.*)$old(.*)\"' OR post_content REGEXP 'href=\"(.*)$old(.*)\"'";
998
+ $wpdb->query($wpdb->prepare($query));
999
+
1000
+ if (trim($new_password)) {
1001
+ $new_password = wp_hash_password($new_password);
1002
+ }
1003
+ if (!trim($clone_from_url) && !trim($iwp_clone)) {
1004
+ if ($new_user && $new_password) {
1005
+ $query = "UPDATE " . $new_table_prefix . "users SET user_login = '$new_user', user_pass = '$new_password' WHERE user_login = '$old_user'";
1006
+ $wpdb->query($wpdb->prepare($query));
1007
+ }
1008
+ } else {
1009
+ if ($clone_from_url) {
1010
+ if ($new_user && $new_password) {
1011
+ $query = "UPDATE " . $new_table_prefix . "users SET user_pass = '$new_password' WHERE user_login = '$new_user'";
1012
+ $wpdb->query($wpdb->prepare($query));
1013
+ }
1014
+ }
1015
+
1016
+ if ($iwp_clone) {
1017
+ if ($admin_email) {
1018
+ //Clean Install
1019
+ $query = "UPDATE " . $new_table_prefix . "options SET option_value = '$admin_email' WHERE option_name = 'admin_email'";
1020
+ $wpdb->query($wpdb->prepare($query));
1021
+ $query = "SELECT * FROM " . $new_table_prefix . "users LIMIT 1";
1022
+ $temp_user = $wpdb->get_row($query);
1023
+ if (!empty($temp_user)) {
1024
+ $query = "UPDATE " . $new_table_prefix . "users SET user_email='$admin_email', user_login = '$new_user', user_pass = '$new_password' WHERE user_login = '$temp_user->user_login'";
1025
+ $wpdb->query($wpdb->prepare($query));
1026
+ }
1027
+
1028
+ }
1029
+ }
1030
+ }
1031
+
1032
+ if (is_array($clone_options) && !empty($clone_options)) {
1033
+ foreach ($clone_options as $key => $option) {
1034
+ if (!empty($key)) {
1035
+ $query = "SELECT option_value FROM " . $new_table_prefix . "options WHERE option_name = '$key'";
1036
+ $res = $wpdb->get_var($query);
1037
+ if ($res == false) {
1038
+ $query = "INSERT INTO " . $new_table_prefix . "options (option_value,option_name) VALUES('$option','$key')";
1039
+ $wpdb->query($wpdb->prepare($query));
1040
+ } else {
1041
+ $query = "UPDATE " . $new_table_prefix . "options SET option_value = '$option' WHERE option_name = '$key'";
1042
+ $wpdb->query($wpdb->prepare($query));
1043
+ }
1044
+ }
1045
+ }
1046
+ }
1047
+
1048
+ //Remove hit count
1049
+ $query = "DELETE FROM " . $new_table_prefix . "options WHERE option_name = 'iwp_client_user_hit_count'";
1050
+ $wpdb->query($wpdb->prepare($query));
1051
+
1052
+ //Check for .htaccess permalinks update
1053
+ $this->replace_htaccess($home);
1054
+ } else {
1055
+
1056
+ //restore client options
1057
+ if (is_array($restore_options) && !empty($restore_options)) {
1058
+ foreach ($restore_options as $key => $option) {
1059
+ update_option($key,$option);
1060
+ }
1061
+ }
1062
+
1063
+ }
1064
+
1065
+
1066
+
1067
+
1068
+ return true;
1069
+ }
1070
+
1071
+ function restore_db()
1072
+ {
1073
+ global $wpdb;
1074
+ $paths = $this->check_mysql_paths();
1075
+ $file_path = ABSPATH . 'iwp_db';
1076
+ @chmod($file_path,0755);
1077
+ $file_name = glob($file_path . '/*.sql');
1078
+ $file_name = $file_name[0];
1079
+
1080
+ if(!$file_name){
1081
+ return array('error' => 'Cannot access database file.');
1082
+ }
1083
+
1084
+ $brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
1085
+ $command = $brace . $paths['mysql'] . $brace . ' --host="' . DB_HOST . '" --user="' . DB_USER . '" --password="' . DB_PASSWORD . '" ' . DB_NAME . ' < ' . $brace . $file_name . $brace;
1086
+
1087
+ ob_start();
1088
+ $result = $this->iwp_mmb_exec($command);
1089
+ ob_get_clean();
1090
+ if (!$result) {
1091
+ //try php
1092
+ $this->restore_db_php($file_name);
1093
+ }
1094
+
1095
+
1096
+ @unlink($file_name);
1097
+ return true;
1098
+ }
1099
+
1100
+ function restore_db_php($file_name)
1101
+ {
1102
+ global $wpdb;
1103
+ $current_query = '';
1104
+ // Read in entire file
1105
+ $lines = file($file_name);
1106
+ // Loop through each line
1107
+ foreach ($lines as $line) {
1108
+ // Skip it if it's a comment
1109
+ if (substr($line, 0, 2) == '--' || $line == '')
1110
+ continue;
1111
+
1112
+ // Add this line to the current query
1113
+ $current_query .= $line;
1114
+ // If it has a semicolon at the end, it's the end of the query
1115
+ if (substr(trim($line), -1, 1) == ';') {
1116
+ // Perform the query
1117
+ $result = $wpdb->query($current_query);
1118
+ if ($result === false)
1119
+ return false;
1120
+ // Reset temp variable to empty
1121
+ $current_query = '';
1122
+ }
1123
+ }
1124
+
1125
+ @unlink($file_name);
1126
+ return true;
1127
+ }
1128
+
1129
+ function get_table_prefix()
1130
+ {
1131
+ $lines = file(ABSPATH . 'wp-config.php');
1132
+ foreach ($lines as $line) {
1133
+ if (strstr($line, '$table_prefix')) {
1134
+ $pattern = "/(\'|\")[^(\'|\")]*/";
1135
+ preg_match($pattern, $line, $matches);
1136
+ $prefix = substr($matches[0], 1);
1137
+ return $prefix;
1138
+ break;
1139
+ }
1140
+ }
1141
+ return 'wp_'; //default
1142
+ }
1143
+
1144
+ function optimize_tables()
1145
+ {
1146
+ global $wpdb;
1147
+ $query = 'SHOW TABLE STATUS FROM ' . DB_NAME;
1148
+ $tables = $wpdb->get_results($wpdb->prepare($query), ARRAY_A);
1149
+ foreach ($tables as $table) {
1150
+ if (in_array($table['Engine'], array(
1151
+ 'MyISAM',
1152
+ 'ISAM',
1153
+ 'HEAP',
1154
+ 'MEMORY',
1155
+ 'ARCHIVE'
1156
+ )))
1157
+ $table_string .= $table['Name'] . ",";
1158
+ elseif ($table['Engine'] == 'InnoDB') {
1159
+ $optimize = $wpdb->query("ALTER TABLE {$table['Name']} ENGINE=InnoDB");
1160
+ }
1161
+ }
1162
+
1163
+ $table_string = rtrim($table_string);
1164
+ $optimize = $wpdb->query("OPTIMIZE TABLE $table_string");
1165
+
1166
+ return $optimize ? true : false;
1167
+ }
1168
+
1169
+ ### Function: Auto Detect MYSQL and MYSQL Dump Paths
1170
+ function check_mysql_paths()
1171
+ {
1172
+ global $wpdb;
1173
+ $paths = array(
1174
+ 'mysql' => '',
1175
+ 'mysqldump' => ''
1176
+ );
1177
+ if (substr(PHP_OS, 0, 3) == 'WIN') {
1178
+ $mysql_install = $wpdb->get_row("SHOW VARIABLES LIKE 'basedir'");
1179
+ if ($mysql_install) {
1180
+ $install_path = str_replace('\\', '/', $mysql_install->Value);
1181
+ $paths['mysql'] = $install_path . 'bin/mysql.exe';
1182
+ $paths['mysqldump'] = $install_path . 'bin/mysqldump.exe';
1183
+ } else {
1184
+ $paths['mysql'] = 'mysql.exe';
1185
+ $paths['mysqldump'] = 'mysqldump.exe';
1186
+ }
1187
+ } else {
1188
+ $paths['mysql'] = $this->iwp_mmb_exec('which mysql', true);
1189
+ if (empty($paths['mysql']))
1190
+ $paths['mysql'] = 'mysql'; // try anyway
1191
+
1192
+ $paths['mysqldump'] = $this->iwp_mmb_exec('which mysqldump', true);
1193
+ if (empty($paths['mysqldump']))
1194
+ $paths['mysqldump'] = 'mysqldump'; // try anyway
1195
+
1196
+ }
1197
+
1198
+
1199
+ return $paths;
1200
+ }
1201
+
1202
+ //Check if exec, system, passthru functions exist
1203
+ function check_sys()
1204
+ {
1205
+ if ($this->iwp_mmb_function_exists('exec'))
1206
+ return 'exec';
1207
+
1208
+ if ($this->iwp_mmb_function_exists('system'))
1209
+ return 'system';
1210
+
1211
+ if ($this->iwp_mmb_function_exists('passhtru'))
1212
+ return 'passthru';
1213
+
1214
+ return false;
1215
+
1216
+ }
1217
+
1218
+ function iwp_mmb_exec($command, $string = false, $rawreturn = false)
1219
+ {
1220
+ if ($command == '')
1221
+ return false;
1222
+
1223
+ if ($this->iwp_mmb_function_exists('exec')) {
1224
+ $log = @exec($command, $output, $return);
1225
+
1226
+ if ($string)
1227
+ return $log;
1228
+ if ($rawreturn)
1229
+ return $return;
1230
+
1231
+ return $return ? false : true;
1232
+ } elseif ($this->iwp_mmb_function_exists('system')) {
1233
+ $log = @system($command, $return);
1234
+
1235
+ if ($string)
1236
+ return $log;
1237
+
1238
+ if ($rawreturn)
1239
+ return $return;
1240
+
1241
+ return $return ? false : true;
1242
+ } elseif ($this->iwp_mmb_function_exists('passthru') && !$string) {
1243
+ $log = passthru($command, $return);
1244
+
1245
+ if ($rawreturn)
1246
+ return $return;
1247
+
1248
+ return $return ? false : true;
1249
+ }
1250
+
1251
+ if ($rawreturn)
1252
+ return -1;
1253
+
1254
+ return false;
1255
+ }
1256
+
1257
+ function get_zip()
1258
+ {
1259
+ $zip = $this->iwp_mmb_exec('which zip', true);
1260
+ if (!$zip)
1261
+ $zip = "zip";
1262
+ return $zip;
1263
+ }
1264
+
1265
+ function get_unzip()
1266
+ {
1267
+ $unzip = $this->iwp_mmb_exec('which unzip', true);
1268
+ if (!$unzip)
1269
+ $unzip = "unzip";
1270
+ return $unzip;
1271
+ }
1272
+
1273
+ function check_backup_compat()
1274
+ {
1275
+ $reqs = array();
1276
+ if (strpos($_SERVER['DOCUMENT_ROOT'], '/') === 0) {
1277
+ $reqs['Server OS']['status'] = 'Linux (or compatible)';
1278
+ $reqs['Server OS']['pass'] = true;
1279
+ } else {
1280
+ $reqs['Server OS']['status'] = 'Windows';
1281
+ $reqs['Server OS']['pass'] = true;
1282
+ $pass = false;
1283
+ }
1284
+ $reqs['PHP Version']['status'] = phpversion();
1285
+ if ((float) phpversion() >= 5.1) {
1286
+ $reqs['PHP Version']['pass'] = true;
1287
+ } else {
1288
+ $reqs['PHP Version']['pass'] = false;
1289
+ $pass = false;
1290
+ }
1291
+
1292
+
1293
+ if (is_writable(WP_CONTENT_DIR)) {
1294
+ $reqs['Backup Folder']['status'] = "writable";
1295
+ $reqs['Backup Folder']['pass'] = true;
1296
+ } else {
1297
+ $reqs['Backup Folder']['status'] = "not writable";
1298
+ $reqs['Backup Folder']['pass'] = false;
1299
+ }
1300
+
1301
+
1302
+ $file_path = IWP_BACKUP_DIR;
1303
+ $reqs['Backup Folder']['status'] .= ' (' . $file_path . ')';
1304
+
1305
+ if ($func = $this->check_sys()) {
1306
+ $reqs['Execute Function']['status'] = $func;
1307
+ $reqs['Execute Function']['pass'] = true;
1308
+ } else {
1309
+ $reqs['Execute Function']['status'] = "not found";
1310
+ $reqs['Execute Function']['info'] = "(will try PHP replacement)";
1311
+ $reqs['Execute Function']['pass'] = false;
1312
+ }
1313
+ $reqs['Zip']['status'] = $this->get_zip();
1314
+
1315
+ $reqs['Zip']['pass'] = true;
1316
+
1317
+
1318
+
1319
+ $reqs['Unzip']['status'] = $this->get_unzip();
1320
+
1321
+ $reqs['Unzip']['pass'] = true;
1322
+
1323
+ $paths = $this->check_mysql_paths();
1324
+
1325
+ if (!empty($paths['mysqldump'])) {
1326
+ $reqs['MySQL Dump']['status'] = $paths['mysqldump'];
1327
+ $reqs['MySQL Dump']['pass'] = true;
1328
+ } else {
1329
+ $reqs['MySQL Dump']['status'] = "not found";
1330
+ $reqs['MySQL Dump']['info'] = "(will try PHP replacement)";
1331
+ $reqs['MySQL Dump']['pass'] = false;
1332
+ }
1333
+
1334
+ $exec_time = ini_get('max_execution_time');
1335
+ $reqs['Execution time']['status'] = $exec_time ? $exec_time . "s" : 'unknown';
1336
+ $reqs['Execution time']['pass'] = true;
1337
+
1338
+ $mem_limit = ini_get('memory_limit');
1339
+ $reqs['Memory limit']['status'] = $mem_limit ? $mem_limit : 'unknown';
1340
+ $reqs['Memory limit']['pass'] = true;
1341
+
1342
+
1343
+ return $reqs;
1344
+ }
1345
+
1346
+ /*
1347
+ //IWP Remove starts here
1348
+ function email_backup($args)
1349
+ {
1350
+ $email = $args['email'];
1351
+
1352
+ if (!is_email($email)) {
1353
+ return array(
1354
+ 'error' => 'Your email (' . $email . ') is not correct'
1355
+ );
1356
+ }
1357
+ $backup_file = $args['file_path'];
1358
+ $task_name = isset($args['task_name']) ? $args['task_name'] : '';
1359
+ if (file_exists($backup_file) && $email) {
1360
+ $attachments = array(
1361
+ $backup_file
1362
+ );
1363
+ $headers = 'From: InfiniteWP <no-reply@infinitewp.com>' . "\r\n";
1364
+ $subject = "InfiniteWP - " . $task_name . " - " . $this->site_name;
1365
+ ob_start();
1366
+ $result = wp_mail($email, $subject, $subject, $headers, $attachments);
1367
+ ob_end_clean();
1368
+
1369
+ }
1370
+
1371
+ if (!$result) {
1372
+ return array(
1373
+ 'error' => 'Email not sent. Maybe your backup is too big for email or email server is not available on your website.'
1374
+ );
1375
+ }
1376
+ return true;
1377
+
1378
+ }
1379
+
1380
+ function ftp_backup($args)
1381
+ {
1382
+ extract($args);
1383
+ //Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder, $ftp_site_folder
1384
+ $port = $ftp_port ? $ftp_port : 21; //default port is 21
1385
+ if ($ftp_ssl) {
1386
+ if (function_exists('ftp_ssl_connect')) {
1387
+ $conn_id = ftp_ssl_connect($ftp_hostname,$port);
1388
+ } else {
1389
+ return array(
1390
+ 'error' => 'Your server doesn\'t support SFTP',
1391
+ 'partial' => 1
1392
+ );
1393
+ }
1394
+ } else {
1395
+ if (function_exists('ftp_connect')) {
1396
+ $conn_id = ftp_connect($ftp_hostname,$port);
1397
+ if ($conn_id === false) {
1398
+ return array(
1399
+ 'error' => 'Failed to connect to ' . $ftp_hostname,
1400
+ 'partial' => 1
1401
+ );
1402
+ }
1403
+ } else {
1404
+ return array(
1405
+ 'error' => 'Your server doesn\'t support FTP',
1406
+ 'partial' => 1
1407
+ );
1408
+ }
1409
+ }
1410
+ $login = @ftp_login($conn_id, $ftp_username, $ftp_password);
1411
+ if ($login === false) {
1412
+ return array(
1413
+ 'error' => 'FTP login failed for ' . $ftp_username . ', ' . $ftp_password,
1414
+ 'partial' => 1
1415
+ );
1416
+ }
1417
+
1418
+ if($ftp_passive){
1419
+ @ftp_pasv($conn_id,true);
1420
+ }
1421
+
1422
+ @ftp_mkdir($conn_id, $ftp_remote_folder);
1423
+ if ($ftp_site_folder) {
1424
+ $ftp_remote_folder .= '/' . $this->site_name;
1425
+ }
1426
+ @ftp_mkdir($conn_id, $ftp_remote_folder);
1427
+
1428
+ $upload = @ftp_put($conn_id, $ftp_remote_folder . '/' . basename($backup_file), $backup_file, FTP_BINARY);
1429
+
1430
+ if ($upload === false) { //Try ascii
1431
+ $upload = @ftp_put($conn_id, $ftp_remote_folder . '/' . basename($backup_file), $backup_file, FTP_ASCII);
1432
+ }
1433
+ ftp_close($conn_id);
1434
+
1435
+ if ($upload === false) {
1436
+ return array(
1437
+ 'error' => 'Failed to upload file to FTP. Please check your specified path.',
1438
+ 'partial' => 1
1439
+ );
1440
+ }
1441
+
1442
+ return true;
1443
+ }
1444
+
1445
+ function remove_ftp_backup($args)
1446
+ {
1447
+ extract($args);
1448
+ //Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder
1449
+ $port = $ftp_port ? $ftp_port : 21; //default port is 21
1450
+ if ($ftp_ssl && function_exists('ftp_ssl_connect')) {
1451
+ $conn_id = ftp_ssl_connect($ftp_hostname,$port);
1452
+ } else if (function_exists('ftp_connect')) {
1453
+ $conn_id = ftp_connect($ftp_hostname,$port);
1454
+ }
1455
+
1456
+ if ($conn_id) {
1457
+ $login = @ftp_login($conn_id, $ftp_username, $ftp_password);
1458
+ if ($ftp_site_folder)
1459
+ $ftp_remote_folder .= '/' . $this->site_name;
1460
+
1461
+ if($ftp_passive){
1462
+ @ftp_pasv($conn_id,true);
1463
+ }
1464
+
1465
+ $delete = ftp_delete($conn_id, $ftp_remote_folder . '/' . $backup_file);
1466
+
1467
+ ftp_close($conn_id);
1468
+ }
1469
+
1470
+ }
1471
+
1472
+ function get_ftp_backup($args)
1473
+ {
1474
+ extract($args);
1475
+ //Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder
1476
+ $port = $ftp_port ? $ftp_port : 21; //default port is 21
1477
+ if ($ftp_ssl && function_exists('ftp_ssl_connect')) {
1478
+ $conn_id = ftp_ssl_connect($ftp_hostname,$port);
1479
+
1480
+ } else if (function_exists('ftp_connect')) {
1481
+ $conn_id = ftp_connect($ftp_hostname,$port);
1482
+ if ($conn_id === false) {
1483
+ return false;
1484
+ }
1485
+ }
1486
+ $login = @ftp_login($conn_id, $ftp_username, $ftp_password);
1487
+ if ($login === false) {
1488
+ return false;
1489
+ } else {
1490
+ }
1491
+
1492
+ if ($ftp_site_folder)
1493
+ $ftp_remote_folder .= '/' . $this->site_name;
1494
+
1495
+ if($ftp_passive){
1496
+ @ftp_pasv($conn_id,true);
1497
+ }
1498
+
1499
+ $temp = ABSPATH . 'iwp_temp_backup.zip';
1500
+ $get = ftp_get($conn_id, $temp, $ftp_remote_folder . '/' . $backup_file, FTP_BINARY);
1501
+ if ($get === false) {
1502
+ return false;
1503
+ } else {
1504
+ }
1505
+ ftp_close($conn_id);
1506
+
1507
+ return $temp;
1508
+ }
1509
+
1510
+ function dropbox_backup($args)
1511
+ {
1512
+ require_once('lib/dropbox.php');
1513
+ extract($args);
1514
+
1515
+ //$email, $password, $backup_file, $destination, $dropbox_site_folder
1516
+
1517
+ $size = ceil(filesize($backup_file) / 1024);
1518
+ if ($size > 300000) {
1519
+ return array(
1520
+ 'error' => 'Cannot upload file to Dropbox. Dropbox has upload limit of 300Mb per file.',
1521
+ 'partial' => 1
1522
+ );
1523
+ }
1524
+
1525
+ if ($dropbox_site_folder == true)
1526
+ $dropbox_destination .= '/' . $this->site_name;
1527
+
1528
+ try {
1529
+ $uploader = new DropboxUploader($dropbox_username, $dropbox_password);
1530
+ $uploader->upload($backup_file, $dropbox_destination);
1531
+ }
1532
+ catch (Exception $e) {
1533
+ return array(
1534
+ 'error' => $e->getMessage(),
1535
+ 'partial' => 1
1536
+ );
1537
+ }
1538
+
1539
+ return true;
1540
+
1541
+ }
1542
+
1543
+ function amazons3_backup($args)
1544
+ {
1545
+ if ($this->iwp_mmb_function_exists('curl_init')) {
1546
+ require_once('lib/s3.php');
1547
+ extract($args);
1548
+
1549
+ if ($as3_site_folder == true)
1550
+ $as3_directory .= '/' . $this->site_name;
1551
+
1552
+ $endpoint = isset($as3_bucket_region) ? $as3_bucket_region : 's3.amazonaws.com';
1553
+
1554
+ $s3 = new S3(trim($as3_access_key), trim(str_replace(' ', '+', $as3_secure_key)), false, $endpoint);
1555
+
1556
+ $s3->putBucket($as3_bucket, S3::ACL_PUBLIC_READ);
1557
+
1558
+ if ($s3->putObjectFile($backup_file, $as3_bucket, $as3_directory . '/' . basename($backup_file), S3::ACL_PRIVATE)) {
1559
+ return true;
1560
+ } else {
1561
+ return array(
1562
+ 'error' => 'Failed to upload to Amazon S3. Please check your details and set upload/delete permissions on your bucket.',
1563
+ 'partial' => 1
1564
+ );
1565
+ }
1566
+ } else {
1567
+ return array(
1568
+ 'error' => 'You cannot use Amazon S3 on your server. Please enable curl first.',
1569
+ 'partial' => 1
1570
+ );
1571
+ }
1572
+ }
1573
+
1574
+ function remove_amazons3_backup($args)
1575
+ {
1576
+ require_once('lib/s3.php');
1577
+ extract($args);
1578
+ if ($as3_site_folder == true)
1579
+ $as3_directory .= '/' . $this->site_name;
1580
+ $endpoint = isset($as3_bucket_region) ? $as3_bucket_region : 's3.amazonaws.com';
1581
+ $s3 = new S3($as3_access_key, str_replace(' ', '+', $as3_secure_key), false, $endpoint);
1582
+ $s3->deleteObject($as3_bucket, $as3_directory . '/' . $backup_file);
1583
+ }
1584
+
1585
+ function get_amazons3_backup($args)
1586
+ {
1587
+ require_once('lib/s3.php');
1588
+ extract($args);
1589
+ $endpoint = isset($as3_bucket_region) ? $as3_bucket_region : 's3.amazonaws.com';
1590
+ $s3 = new S3($as3_access_key, str_replace(' ', '+', $as3_secure_key), false, $endpoint);
1591
+ if ($as3_site_folder == true)
1592
+ $as3_directory .= '/' . $this->site_name;
1593
+
1594
+ $temp = ABSPATH . 'iwp_temp_backup.zip';
1595
+ $s3->getObject($as3_bucket, $as3_directory . '/' . $backup_file, $temp);
1596
+
1597
+ return $temp;
1598
+ }
1599
+
1600
+ function schedule_next($type, $schedule)
1601
+ {
1602
+ $schedule = explode("|", $schedule);
1603
+ if (empty($schedule))
1604
+ return false;
1605
+ switch ($type) {
1606
+
1607
+ case 'daily':
1608
+
1609
+ if ($schedule[1]) {
1610
+ $delay_time = $schedule[1] * 60;
1611
+ }
1612
+
1613
+ $current_hour = date("H");
1614
+ $schedule_hour = $schedule[0];
1615
+ if ($current_hour >= $schedule_hour){
1616
+ $time = mktime($schedule_hour, 0, 0, date("m"), date("d") + 1, date("Y"));
1617
+ //$time ='0001#'.$current_hour.'|'.$schedule_hour;
1618
+ }
1619
+ else{
1620
+ $time = mktime($schedule_hour, 0, 0, date("m"), date("d"), date("Y"));
1621
+ //$time ='0000#'.$current_hour.'|'.$schedule_hour;
1622
+ }
1623
+ $time = time() + 30;
1624
+ break;
1625
+
1626
+
1627
+ case 'weekly':
1628
+ if ($schedule[2]) {
1629
+ $delay_time = $schedule[2] * 60;
1630
+ }
1631
+ $current_weekday = date('w');
1632
+ $schedule_weekday = $schedule[1];
1633
+ $current_hour = date("H");
1634
+ $schedule_hour = $schedule[0];
1635
+
1636
+ if ($current_weekday > $schedule_weekday)
1637
+ $weekday_offset = 7 - ($week_day - $task_schedule[1]);
1638
+ else
1639
+ $weekday_offset = $schedule_weekday - $current_weekday;
1640
+
1641
+
1642
+ if (!$weekday_offset) { //today is scheduled weekday
1643
+ if ($current_hour >= $schedule_hour)
1644
+ $time = mktime($schedule_hour, 0, 0, date("m"), date("d") + 7, date("Y"));
1645
+ else
1646
+ $time = mktime($schedule_hour, 0, 0, date("m"), date("d"), date("Y"));
1647
+ } else {
1648
+ $time = mktime($schedule_hour, 0, 0, date("m"), date("d") + $weekday_offset, date("Y"));
1649
+ }
1650
+
1651
+ break;
1652
+
1653
+ case 'monthly':
1654
+ if ($schedule[2]) {
1655
+ $delay_time = $schedule[2] * 60;
1656
+ }
1657
+ $current_monthday = date('j');
1658
+ $schedule_monthday = $schedule[1];
1659
+ $current_hour = date("H");
1660
+ $schedule_hour = $schedule[0];
1661
+
1662
+ if ($current_monthday > $schedule_monthday) {
1663
+ $time = mktime($schedule_hour, 0, 0, date("m") + 1, $schedule_monthday, date("Y"));
1664
+ } else if ($current_monthday < $schedule_monthday) {
1665
+ $time = mktime($schedule_hour, 0, 0, date("m"), $schedule_monthday, date("Y"));
1666
+ } else if ($current_monthday == $schedule_monthday) {
1667
+ if ($current_hour >= $schedule_hour)
1668
+ $time = mktime($schedule_hour, 0, 0, date("m") + 1, $schedule_monthday, date("Y"));
1669
+ else
1670
+ $time = mktime($schedule_hour, 0, 0, date("m"), $schedule_monthday, date("Y"));
1671
+ break;
1672
+ }
1673
+
1674
+ break;
1675
+ default:
1676
+ break;
1677
+ }
1678
+
1679
+ if ($delay_time) {
1680
+ $time += $delay_time;
1681
+ }
1682
+
1683
+
1684
+ return $time;
1685
+
1686
+ }
1687
+ //IWP Remove ends here
1688
+ */
1689
+
1690
+ //Parse task arguments for info on IWP Admin Panel
1691
+ function get_backup_stats()
1692
+ {
1693
+ $stats = array();
1694
+ $tasks = $this->tasks;
1695
+ if (is_array($tasks) && !empty($tasks)) {
1696
+ foreach ($tasks as $task_name => $info) {
1697
+ if (is_array($info['task_results']) && !empty($info['task_results'])) {
1698
+ foreach ($info['task_results'] as $key => $result) {
1699
+ if (isset($result['server']) && !isset($result['error'])) {
1700
+ if (!file_exists($result['server']['file_path'])) {
1701
+ $info['task_results'][$key]['error'] = 'Backup created but manually removed from server.';
1702
+ }
1703
+ }
1704
+ }
1705
+ }
1706
+ if (is_array($info['task_results']))
1707
+ $stats[$task_name] = array_values($info['task_results']);
1708
+
1709
+ }
1710
+ }
1711
+ return $stats;
1712
+ }
1713
+
1714
+ /*
1715
+ //IWP Remove starts here
1716
+ function get_next_schedules()
1717
+ {
1718
+ $stats = array();
1719
+ $tasks = $this->tasks;
1720
+ if (is_array($tasks) && !empty($tasks)) {
1721
+ foreach ($tasks as $task_name => $info) {
1722
+ $stats[$task_name] = isset($info['task_args']['next']) ? $info['task_args']['next'] : array();
1723
+ }
1724
+ }
1725
+ return $stats;
1726
+ }
1727
+ //IWP Remove ends here
1728
+ */
1729
+
1730
+ function remove_old_backups($task_name)
1731
+ {
1732
+ //Check for previous failed backups first
1733
+ $this->cleanup();
1734
+
1735
+ //Remove by limit
1736
+ $backups = $this->tasks;
1737
+ if ($task_name == 'Backup Now') {
1738
+ $num = 0;
1739
+ } else {
1740
+ $num = 1;
1741
+ }
1742
+
1743
+
1744
+ if ((count($backups[$task_name]['task_results']) - $num) >= $backups[$task_name]['task_args']['limit']) {
1745
+ //how many to remove ?
1746
+ $remove_num = (count($backups[$task_name]['task_results']) - $num - $backups[$task_name]['task_args']['limit']) + 1;
1747
+ for ($i = 0; $i < $remove_num; $i++) {
1748
+ //Remove from the server
1749
+ if (isset($backups[$task_name]['task_results'][$i]['server'])) {
1750
+ @unlink($backups[$task_name]['task_results'][$i]['server']['file_path']);
1751
+ }
1752
+
1753
+ /*
1754
+ //IWP Remove starts here
1755
+ //Remove from ftp
1756
+ if (isset($backups[$task_name]['task_results'][$i]['ftp'])) {
1757
+ $ftp_file = $backups[$task_name]['task_results'][$i]['ftp'];
1758
+ $args = $backups[$task_name]['task_args']['account_info']['iwp_ftp'];
1759
+ $args['backup_file'] = $ftp_file;
1760
+ $this->remove_ftp_backup($args);
1761
+ }
1762
+
1763
+ if (isset($backups[$task_name]['task_results'][$i]['amazons3'])) {
1764
+ $amazons3_file = $backups[$task_name]['task_results'][$i]['amazons3'];
1765
+ $args = $backups[$task_name]['task_args']['account_info']['iwp_amazon_s3'];
1766
+ $args['backup_file'] = $amazons3_file;
1767
+ $this->remove_amazons3_backup($args);
1768
+ }
1769
+
1770
+ if (isset($backups[$task_name]['task_results'][$i]['dropbox'])) {
1771
+ //To do: dropbox remove
1772
+ }
1773
+ //IWP Remove ends here
1774
+ */
1775
+
1776
+ //Remove database backup info
1777
+ unset($backups[$task_name]['task_results'][$i]);
1778
+
1779
+ } //end foreach
1780
+
1781
+ if (is_array($backups[$task_name]['task_results']))
1782
+ $backups[$task_name]['task_results'] = array_values($backups[$task_name]['task_results']);
1783
+ else
1784
+ $backups[$task_name]['task_results']=array();
1785
+
1786
+ $this->update_tasks($backups);
1787
+ //update_option('iwp_client_backup_tasks', $backups);
1788
+ }
1789
+ }
1790
+
1791
+ /**
1792
+ * Delete specified backup
1793
+ * Args: $task_name, $result_id
1794
+ */
1795
+
1796
+ function delete_backup($args)
1797
+ {
1798
+ if (empty($args))
1799
+ return false;
1800
+ extract($args);
1801
+
1802
+ $tasks = $this->tasks;
1803
+ $task = $tasks[$task_name];
1804
+ $backups = $task['task_results'];
1805
+ $backup = $backups[$result_id];
1806
+
1807
+ if (isset($backup['server'])) {
1808
+ @unlink($backup['server']['file_path']);
1809
+ }
1810
+
1811
+ /*
1812
+ //IWP Remove starts here
1813
+ //Remove from ftp
1814
+ if (isset($backup['ftp'])) {
1815
+ $ftp_file = $backup['ftp'];
1816
+ $args = $tasks[$task_name]['task_args']['account_info']['iwp_ftp'];
1817
+ $args['backup_file'] = $ftp_file;
1818
+ $this->remove_ftp_backup($args);
1819
+ }
1820
+
1821
+ if (isset($backup['amazons3'])) {
1822
+ $amazons3_file = $backup['amazons3'];
1823
+ $args = $tasks[$task_name]['task_args']['account_info']['iwp_amazon_s3'];
1824
+ $args['backup_file'] = $amazons3_file;
1825
+ $this->remove_amazons3_backup($args);
1826
+ }
1827
+
1828
+ if (isset($backup['dropbox'])) {
1829
+ }
1830
+ //IWP Remove ends here
1831
+ */
1832
+
1833
+ unset($backups[$result_id]);
1834
+
1835
+ if (count($backups)) {
1836
+ $tasks[$task_name]['task_results'] = $backups;
1837
+ } else {
1838
+ unset($tasks[$task_name]['task_results']);
1839
+ }
1840
+
1841
+ $this->update_tasks($tasks);
1842
+ //update_option('iwp_client_backup_tasks', $tasks);
1843
+ return true;
1844
+
1845
+ }
1846
+
1847
+ function cleanup()
1848
+ {
1849
+ $tasks = $this->tasks;
1850
+ $backup_folder = WP_CONTENT_DIR . '/' . md5('iwp_mmb-client') . '/iwp_backups/';
1851
+ $backup_folder_new = IWP_BACKUP_DIR . '/';
1852
+ $files = glob($backup_folder . "*");
1853
+ $new = glob($backup_folder_new . "*");
1854
+
1855
+ //Failed db files first
1856
+ $db_folder = IWP_DB_DIR . '/';
1857
+ $db_files = glob($db_folder . "*");
1858
+ if (is_array($db_files) && !empty($db_files)) {
1859
+ foreach ($db_files as $file) {
1860
+ @unlink($file);
1861
+ }
1862
+ @rmdir(IWP_DB_DIR);
1863
+ }
1864
+
1865
+
1866
+ //clean_old folder?
1867
+ if ((basename($files[0]) == 'index.php' && count($files) == 1) || (empty($files))) {
1868
+ foreach ($files as $file) {
1869
+ @unlink($file);
1870
+ }
1871
+ @rmdir(WP_CONTENT_DIR . '/' . md5('iwp_mmb-client') . '/iwp_backups');
1872
+ @rmdir(WP_CONTENT_DIR . '/' . md5('iwp_mmb-client'));
1873
+ }
1874
+
1875
+
1876
+ foreach ($new as $b) {
1877
+ $files[] = $b;
1878
+ }
1879
+ $deleted = array();
1880
+
1881
+ if (is_array($files) && count($files)) {
1882
+ $results = array();
1883
+ if (!empty($tasks)) {
1884
+ foreach ((array) $tasks as $task) {
1885
+ if (isset($task['task_results']) && count($task['task_results'])) {
1886
+ foreach ($task['task_results'] as $backup) {
1887
+ if (isset($backup['server'])) {
1888
+ $results[] = $backup['server']['file_path'];
1889
+ }
1890
+ }
1891
+ }
1892
+ }
1893
+ }
1894
+
1895
+ $num_deleted = 0;
1896
+ foreach ($files as $file) {
1897
+ if (!in_array($file, $results) && basename($file) != 'index.php') {
1898
+ @unlink($file);
1899
+ $deleted[] = basename($file);
1900
+ $num_deleted++;
1901
+ }
1902
+ }
1903
+ }
1904
+
1905
+
1906
+
1907
+ return $deleted;
1908
+ }
1909
+
1910
+
1911
+ /*
1912
+ //IWP Remove starts here
1913
+ function remote_backup_now($args)
1914
+ {
1915
+ if (!empty($args))
1916
+ extract($args);
1917
+
1918
+ $tasks = $this->tasks;
1919
+ $task = $tasks['Backup Now'];
1920
+
1921
+ if (!empty($task)) {
1922
+ extract($task['task_args']);
1923
+ }
1924
+
1925
+ $results = $task['task_results'];
1926
+
1927
+ if (is_array($results) && count($results)) {
1928
+ $backup_file = $results[count($results) - 1]['server']['file_path'];
1929
+ }
1930
+
1931
+ if ($backup_file && file_exists($backup_file)) {
1932
+ //FTP, Amazon S3 or Dropbox
1933
+ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
1934
+ $account_info['iwp_ftp']['backup_file'] = $backup_file;
1935
+ $return = $this->ftp_backup($account_info['iwp_ftp']);
1936
+ }
1937
+
1938
+ if (isset($account_info['iwp_amazon_s3']) && !empty($account_info['iwp_amazon_s3'])) {
1939
+ $account_info['iwp_amazon_s3']['backup_file'] = $backup_file;
1940
+ $return = $this->amazons3_backup($account_info['iwp_amazon_s3']);
1941
+ }
1942
+
1943
+ if (isset($account_info['iwp_dropbox']) && !empty($account_info['iwp_dropbox'])) {
1944
+ $account_info['iwp_dropbox']['backup_file'] = $backup_file;
1945
+ $return = $this->dropbox_backup($account_info['iwp_dropbox']);
1946
+ }
1947
+
1948
+ if (isset($account_info['iwp_email']) && !empty($account_info['iwp_email'])) {
1949
+ $account_info['iwp_email']['file_path'] = $backup_file;
1950
+ $account_info['iwp_email']['task_name'] = 'Backup Now';
1951
+ $return = $this->email_backup($account_info['iwp_email']);
1952
+ }
1953
+
1954
+
1955
+ if ($return == true && $del_host_file) {
1956
+ @unlink($backup_file);
1957
+ unset($tasks['Backup Now']['task_results'][count($results) - 1]['server']);
1958
+ $this->update_tasks($tasks);
1959
+ //update_option('iwp_client_backup_tasks', $tasks);
1960
+ }
1961
+
1962
+
1963
+
1964
+ } else {
1965
+ $return = array(
1966
+ 'error' => 'Backup file not found on your server. Please try again.'
1967
+ );
1968
+ }
1969
+
1970
+ return $return;
1971
+
1972
+ }
1973
+ //IWP Remove ends here
1974
+ */
1975
+
1976
+ function validate_task($args, $url)
1977
+ {
1978
+ if (!class_exists('WP_Http')) {
1979
+ include_once(ABSPATH . WPINC . '/class-http.php');
1980
+ }
1981
+ $params = array();
1982
+ $params['body'] = $args;
1983
+ $result = wp_remote_post($url, $params);
1984
+ if (is_array($result) && $result['body'] == 'iwp_delete_task') {
1985
+ //$tasks = $this->get_backup_settings();
1986
+ $tasks = $this->tasks;
1987
+ unset($tasks[$args['task_name']]);
1988
+ $this->update_tasks($tasks);
1989
+ $this->cleanup();
1990
+ exit;
1991
+ } elseif(is_array($result) && $result['body'] == 'iwp_pause_task'){
1992
+ return 'paused';
1993
+ }
1994
+
1995
+ return 'ok';
1996
+ }
1997
+
1998
+ function update_status($task_name, $status, $completed = false)
1999
+ {
2000
+ /* Statuses:
2001
+ 0 - Backup started
2002
+ 1 - DB dump
2003
+ 2 - DB ZIP
2004
+ 3 - Files ZIP
2005
+ 4 - Amazon S3
2006
+ 5 - Dropbox
2007
+ 6 - FTP
2008
+ 7 - Email
2009
+ 100 - Finished
2010
+ */
2011
+ if ($task_name != 'Backup Now') {
2012
+ $tasks = $this->tasks;
2013
+ $index = count($tasks[$task_name]['task_results']) - 1;
2014
+ if (!is_array($tasks[$task_name]['task_results'][$index]['status'])) {
2015
+ $tasks[$task_name]['task_results'][$index]['status'] = array();
2016
+ }
2017
+ if (!$completed) {
2018
+ $tasks[$task_name]['task_results'][$index]['status'][] = (int) $status * (-1);
2019
+ } else {
2020
+ $status_index = count($tasks[$task_name]['task_results'][$index]['status']) - 1;
2021
+ $tasks[$task_name]['task_results'][$index]['status'][$status_index] = abs($tasks[$task_name]['task_results'][$index]['status'][$status_index]);
2022
+ }
2023
+
2024
+ $this->update_tasks($tasks);
2025
+ //update_option('iwp_client_backup_tasks',$tasks);
2026
+ }
2027
+ }
2028
+
2029
+ function update_tasks($tasks)
2030
+ {
2031
+ $this->tasks = $tasks;
2032
+ update_option('iwp_client_backup_tasks', $tasks);
2033
+ }
2034
+
2035
+ function wpdb_reconnect(){
2036
+ global $wpdb;
2037
+ //Reconnect to avoid timeout problem after ZIP files
2038
+ if(class_exists('wpdb') && function_exists('wp_set_wpdb_vars')){
2039
+ @mysql_close($wpdb->dbh);
2040
+ $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
2041
+ wp_set_wpdb_vars();
2042
+ }
2043
+ }
2044
+
2045
+ function replace_htaccess($url)
2046
+ {
2047
+ $file = @file_get_contents(ABSPATH.'.htaccess');
2048
+ if ($file && strlen($file)) {
2049
+ $args = parse_url($url);
2050
+ $string = rtrim($args['path'], "/");
2051
+ $regex = "/BEGIN WordPress(.*?)RewriteBase(.*?)\n(.*?)RewriteRule \.(.*?)index\.php(.*?)END WordPress/sm";
2052
+ $replace = "BEGIN WordPress$1RewriteBase " . $string . "/ \n$3RewriteRule . " . $string . "/index.php$5END WordPress";
2053
+ $file = preg_replace($regex, $replace, $file);
2054
+ @file_put_contents(ABSPATH.'.htaccess', $file);
2055
+ }
2056
+ }
2057
+
2058
+ }
2059
+
2060
+ ?>
core.class.php ADDED
@@ -0,0 +1,681 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /************************************************************
3
+ * This plugin was modified by Revmakx *
4
+ * Copyright (c) 2012 Revmakx *
5
+ * www.revmakx.com *
6
+ * *
7
+ ************************************************************/
8
+ /*************************************************************
9
+ *
10
+ * core.class.php
11
+ *
12
+ * Upgrade Plugins
13
+ *
14
+ *
15
+ * Copyright (c) 2011 Prelovac Media
16
+ * www.prelovac.com
17
+ **************************************************************/
18
+
19
+ class IWP_MMB_Core extends IWP_MMB_Helper
20
+ {
21
+ var $name;
22
+ var $slug;
23
+ var $settings;
24
+ var $remote_client;
25
+ var $comment_instance;
26
+ var $plugin_instance;
27
+ var $theme_instance;
28
+ var $wp_instance;
29
+ var $post_instance;
30
+ var $stats_instance;
31
+ var $search_instance;
32
+ var $links_instance;
33
+ var $user_instance;
34
+ var $backup_instance;
35
+ var $installer_instance;
36
+ var $iwp_mmb_multisite;
37
+ var $network_admin_install;
38
+ private $action_call;
39
+ private $action_params;
40
+ private $iwp_mmb_pre_init_actions;
41
+ private $iwp_mmb_pre_init_filters;
42
+ private $iwp_mmb_init_actions;
43
+
44
+
45
+ function __construct()
46
+ {
47
+ global $iwp_mmb_plugin_dir, $wpmu_version, $blog_id, $_iwp_mmb_plugin_actions, $_iwp_mmb_item_filter;
48
+
49
+ $_iwp_mmb_plugin_actions = array();
50
+ $this->name = 'Manage Multiple Blogs';
51
+ $this->slug = 'manage-multiple-blogs';
52
+ $this->action_call = null;
53
+ $this->action_params = null;
54
+
55
+
56
+ $this->settings = get_option($this->slug);
57
+ if (!$this->settings) {
58
+ $this->settings = array(
59
+ 'blogs' => array(),
60
+ 'current_blog' => array(
61
+ 'type' => null
62
+ )
63
+ );
64
+ $this->save_options();
65
+ }
66
+ if ( function_exists('is_multisite') ) {
67
+ if ( is_multisite() ) {
68
+ $this->iwp_mmb_multisite = $blog_id;
69
+ $this->network_admin_install = get_option('iwp_client_network_admin_install');
70
+ }
71
+ } else if (!empty($wpmu_version)) {
72
+ $this->iwp_mmb_multisite = $blog_id;
73
+ $this->network_admin_install = get_option('iwp_client_network_admin_install');
74
+ } else {
75
+ $this->iwp_mmb_multisite = false;
76
+ $this->network_admin_install = null;
77
+ }
78
+
79
+ // admin notices
80
+ if ( !get_option('iwp_client_public_key') ){
81
+ if( $this->iwp_mmb_multisite ){
82
+ if( is_network_admin() && $this->network_admin_install == '1'){
83
+ add_action('network_admin_notices', array( &$this, 'network_admin_notice' ));
84
+ } else if( $this->network_admin_install != '1' ){
85
+ $parent_key = $this->get_parent_blog_option('iwp_client_public_key');
86
+ if(empty($parent_key))
87
+ add_action('admin_notices', array( &$this, 'admin_notice' ));
88
+ }
89
+ } else {
90
+ add_action('admin_notices', array( &$this, 'admin_notice' ));
91
+ }
92
+ }
93
+
94
+ // default filters
95
+ //$this->iwp_mmb_pre_init_filters['get_stats']['iwp_mmb_stats_filter'][] = array('IWP_MMB_Stats', 'pre_init_stats'); // called with class name, use global $iwp_mmb_core inside the function instead of $this
96
+ $this->iwp_mmb_pre_init_filters['get_stats']['iwp_mmb_stats_filter'][] = 'iwp_mmb_pre_init_stats';
97
+
98
+ $_iwp_mmb_item_filter['pre_init_stats'] = array( 'core_update', 'hit_counter', 'comments', 'backups', 'posts', 'drafts', 'scheduled' );
99
+ $_iwp_mmb_item_filter['get'] = array( 'updates', 'errors' );
100
+
101
+ $this->iwp_mmb_pre_init_actions = array(
102
+ 'backup_req' => 'iwp_mmb_get_backup_req',
103
+ );
104
+
105
+ $this->iwp_mmb_init_actions = array(
106
+ 'do_upgrade' => 'iwp_mmb_do_upgrade',
107
+ 'get_stats' => 'iwp_mmb_stats_get',
108
+ 'remove_site' => 'iwp_mmb_remove_site',
109
+ 'backup_clone' => 'iwp_mmb_backup_now',
110
+ 'restore' => 'iwp_mmb_restore_now',
111
+ 'optimize_tables' => 'iwp_mmb_optimize_tables',
112
+ 'check_wp_version' => 'iwp_mmb_wp_checkversion',
113
+ 'create_post' => 'iwp_mmb_post_create',
114
+ 'update_client' => 'iwp_mmb_update_client_plugin',
115
+ 'change_comment_status' => 'iwp_mmb_change_comment_status',
116
+ 'change_post_status' => 'iwp_mmb_change_post_status',
117
+ 'get_comment_stats' => 'iwp_mmb_comment_stats_get',
118
+ 'install_addon' => 'iwp_mmb_install_addon',
119
+ 'add_link' => 'iwp_mmb_add_link',
120
+ 'add_user' => 'iwp_mmb_add_user',
121
+ 'email_backup' => 'iwp_mmb_email_backup',
122
+ 'check_backup_compat' => 'iwp_mmb_check_backup_compat',
123
+ 'scheduled_backup' => 'iwp_mmb_scheduled_backup',
124
+ 'run_task' => 'iwp_mmb_run_task_now',
125
+ 'execute_php_code' => 'iwp_mmb_execute_php_code',
126
+ 'delete_backup' => 'mmm_delete_backup',
127
+ 'remote_backup_now' => 'iwp_mmb_remote_backup_now',
128
+ 'set_notifications' => 'iwp_mmb_set_notifications',
129
+ 'clean_orphan_backups' => 'iwp_mmb_clean_orphan_backups',
130
+ 'get_users' => 'iwp_mmb_get_users',
131
+ 'edit_users' => 'iwp_mmb_edit_users',
132
+ 'get_plugins_themes' => 'iwp_mmb_get_plugins_themes',
133
+ 'edit_plugins_themes' => 'iwp_mmb_edit_plugins_themes',
134
+ 'client_brand' => 'iwp_mmb_client_brand',
135
+ 'set_alerts' => 'iwp_mmb_set_alerts',
136
+ 'maintenance' => 'iwp_mmb_maintenance_mode'
137
+ );
138
+
139
+ add_action('rightnow_end', array( &$this, 'add_right_now_info' ));
140
+ add_action('admin_init', array(&$this,'admin_actions'));
141
+ add_action('init', array( &$this, 'iwp_mmb_remote_action'), 9999);
142
+ add_action('setup_theme', 'iwp_mmb_parse_request');
143
+ add_action('set_auth_cookie', array( &$this, 'iwp_mmb_set_auth_cookie'));
144
+ add_action('set_logged_in_cookie', array( &$this, 'iwp_mmb_set_logged_in_cookie'));
145
+
146
+ }
147
+
148
+ function iwp_mmb_remote_action(){
149
+ if($this->action_call != null){
150
+ $params = isset($this->action_params) && $this->action_params != null ? $this->action_params : array();
151
+ call_user_func($this->action_call, $params);
152
+ }
153
+ }
154
+
155
+ function register_action_params( $action = false, $params = array() ){
156
+
157
+ if(isset($this->iwp_mmb_pre_init_actions[$action]) && function_exists($this->iwp_mmb_pre_init_actions[$action])){
158
+ call_user_func($this->iwp_mmb_pre_init_actions[$action], $params);
159
+ }
160
+
161
+ if(isset($this->iwp_mmb_init_actions[$action]) && function_exists($this->iwp_mmb_init_actions[$action])){
162
+ $this->action_call = $this->iwp_mmb_init_actions[$action];
163
+ $this->action_params = $params;
164
+
165
+ if( isset($this->iwp_mmb_pre_init_filters[$action]) && !empty($this->iwp_mmb_pre_init_filters[$action])){
166
+ global $iwp_mmb_filters;
167
+
168
+ foreach($this->iwp_mmb_pre_init_filters[$action] as $_name => $_functions){
169
+ if(!empty($_functions)){
170
+ $data = array();
171
+
172
+ foreach($_functions as $_k => $_callback){
173
+ if(is_array($_callback) && method_exists($_callback[0], $_callback[1]) ){
174
+ $data = call_user_func( $_callback, $params );
175
+ } elseif (is_string($_callback) && function_exists( $_callback )){
176
+ $data = call_user_func( $_callback, $params );
177
+ }
178
+ $iwp_mmb_filters[$_name] = isset($iwp_mmb_filters[$_name]) && !empty($iwp_mmb_filters[$_name]) ? array_merge($iwp_mmb_filters[$_name], $data) : $data;
179
+ add_filter( $_name, create_function( '$a' , 'global $iwp_mmb_filters; return array_merge($a, $iwp_mmb_filters["'.$_name.'"]);') );
180
+ }
181
+ }
182
+
183
+ }
184
+ }
185
+ return true;
186
+ }
187
+ return false;
188
+ }
189
+
190
+ /**
191
+ * Add notice to network admin dashboard for security reasons
192
+ *
193
+ */
194
+ function network_admin_notice()
195
+ {
196
+ echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
197
+ Please add this site and your network blogs, with your network adminstrator username, to your <a target="_blank" href="http://infinitewp.com/wp-admin">InfiniteWP.com</a> account now to remove this notice or "Network Deactivate" the Client plugin to avoid <a target="_blank" href="http://infinitewp.com/user-guide/security">security issues</a>.
198
+ </p></div>';
199
+ }
200
+
201
+
202
+ /**
203
+ * Add notice to admin dashboard for security reasons
204
+ *
205
+ */
206
+ function admin_notice()
207
+ {
208
+ /* IWP */
209
+ /* echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
210
+ Please add this site now to your <a target="_blank" href="http://infinitewp.com/wp-admin">InfiniteWP.com</a> account. Or deactivate the Client plugin to avoid <a target="_blank" href="http://infinitewp.com/user-guide/security">security issues</a>.
211
+ </p></div>';*/
212
+ $current_user = wp_get_current_user();
213
+ echo '<div class="updated" style="text-align: center;"><p style="color: green; font-size: 14px; font-weight: bold;">Add this site to IWP Admin panel</p><p>
214
+ <table border="0" align="center">
215
+ <tr><td align="right">WEBSITE URL:</td><td align="left"><strong>'.get_option('home').'/</strong></td></tr>
216
+ <tr><td align="right">ADMIN USERNAME:</td><td align="left"><strong>'.$current_user->data->user_login.'</strong> (or any admin id)</td></tr>
217
+ <tr><td align="right">ACTIVATION KEY:</td><td align="left"><strong>'.get_option('iwp_client_activate_key').'</strong></td></tr>
218
+ </table>
219
+ </p></div>';
220
+
221
+ }
222
+
223
+ /**
224
+ * Add an item into the Right Now Dashboard widget
225
+ * to inform that the blog can be managed remotely
226
+ *
227
+ */
228
+ function add_right_now_info()
229
+ {
230
+ echo '<div class="iwp_mmb-slave-info">
231
+ <p>This site can be managed remotely.</p>
232
+ </div>';
233
+ }
234
+
235
+ /**
236
+ * Get parent blog options
237
+ *
238
+ */
239
+ private function get_parent_blog_option( $option_name = '' )
240
+ {
241
+ global $wpdb;
242
+ $option = $wpdb->get_var( $wpdb->prepare( "SELECT `option_value` FROM {$wpdb->base_prefix}options WHERE option_name = '{$option_name}' LIMIT 1" ) );
243
+ return $option;
244
+ }
245
+
246
+ /**
247
+ * Gets an instance of the Comment class
248
+ *
249
+ */
250
+ function get_comment_instance()
251
+ {
252
+ if (!isset($this->comment_instance)) {
253
+ $this->comment_instance = new IWP_MMB_Comment();
254
+ }
255
+
256
+ return $this->comment_instance;
257
+ }
258
+
259
+ /**
260
+ * Gets an instance of the Plugin class
261
+ *
262
+ */
263
+ function get_plugin_instance()
264
+ {
265
+ if (!isset($this->plugin_instance)) {
266
+ $this->plugin_instance = new IWP_MMB_Plugin();
267
+ }
268
+
269
+ return $this->plugin_instance;
270
+ }
271
+
272
+ /**
273
+ * Gets an instance of the Theme class
274
+ *
275
+ */
276
+ function get_theme_instance()
277
+ {
278
+ if (!isset($this->theme_instance)) {
279
+ $this->theme_instance = new IWP_MMB_Theme();
280
+ }
281
+
282
+ return $this->theme_instance;
283
+ }
284
+
285
+
286
+ /**
287
+ * Gets an instance of IWP_MMB_Post class
288
+ *
289
+ */
290
+ function get_post_instance()
291
+ {
292
+ if (!isset($this->post_instance)) {
293
+ $this->post_instance = new IWP_MMB_Post();
294
+ }
295
+
296
+ return $this->post_instance;
297
+ }
298
+
299
+ /**
300
+ * Gets an instance of Blogroll class
301
+ *
302
+ */
303
+ function get_blogroll_instance()
304
+ {
305
+ if (!isset($this->blogroll_instance)) {
306
+ $this->blogroll_instance = new IWP_MMB_Blogroll();
307
+ }
308
+
309
+ return $this->blogroll_instance;
310
+ }
311
+
312
+
313
+
314
+ /**
315
+ * Gets an instance of the WP class
316
+ *
317
+ */
318
+ function get_wp_instance()
319
+ {
320
+ if (!isset($this->wp_instance)) {
321
+ $this->wp_instance = new IWP_MMB_WP();
322
+ }
323
+
324
+ return $this->wp_instance;
325
+ }
326
+
327
+ /**
328
+ * Gets an instance of User
329
+ *
330
+ */
331
+ function get_user_instance()
332
+ {
333
+ if (!isset($this->user_instance)) {
334
+ $this->user_instance = new IWP_MMB_User();
335
+ }
336
+
337
+ return $this->user_instance;
338
+ }
339
+
340
+ /**
341
+ * Gets an instance of stats class
342
+ *
343
+ */
344
+ function get_stats_instance()
345
+ {
346
+ if (!isset($this->stats_instance)) {
347
+ $this->stats_instance = new IWP_MMB_Stats();
348
+ }
349
+ return $this->stats_instance;
350
+ }
351
+ /**
352
+ * Gets an instance of search class
353
+ *
354
+ */
355
+ function get_search_instance()
356
+ {
357
+ if (!isset($this->search_instance)) {
358
+ $this->search_instance = new IWP_MMB_Search();
359
+ }
360
+ //return $this->search_instance;
361
+ return $this->search_instance;
362
+ }
363
+ /**
364
+ * Gets an instance of stats class
365
+ *
366
+ */
367
+ function get_backup_instance()
368
+ {
369
+ if (!isset($this->backup_instance)) {
370
+ $this->backup_instance = new IWP_MMB_Backup();
371
+ }
372
+
373
+ return $this->backup_instance;
374
+ }
375
+
376
+ /**
377
+ * Gets an instance of links class
378
+ *
379
+ */
380
+ function get_link_instance()
381
+ {
382
+ if (!isset($this->link_instance)) {
383
+ $this->link_instance = new IWP_MMB_Link();
384
+ }
385
+
386
+ return $this->link_instance;
387
+ }
388
+
389
+ function get_installer_instance()
390
+ {
391
+ if (!isset($this->installer_instance)) {
392
+ $this->installer_instance = new IWP_MMB_Installer();
393
+ }
394
+ return $this->installer_instance;
395
+ }
396
+
397
+ /**
398
+ * Plugin install callback function
399
+ * Check PHP version
400
+ */
401
+ function install() {
402
+
403
+ global $wpdb, $_wp_using_ext_object_cache, $current_user;
404
+ $_wp_using_ext_object_cache = false;
405
+
406
+ //delete plugin options, just in case
407
+ if ($this->iwp_mmb_multisite != false) {
408
+ $network_blogs = $wpdb->get_results($wpdb->prepare("select `blog_id`, `site_id` from `{$wpdb->blogs}`"));
409
+ if(!empty($network_blogs)){
410
+ if( is_network_admin() ){
411
+ update_option('iwp_client_network_admin_install', 1);
412
+ foreach($network_blogs as $details){
413
+ if($details->site_id == $details->blog_id)
414
+ update_blog_option($details->blog_id, 'iwp_client_network_admin_install', 1);
415
+ else
416
+ update_blog_option($details->blog_id, 'iwp_client_network_admin_install', -1);
417
+
418
+ delete_blog_option($blog_id, 'iwp_client_nossl_key');
419
+ delete_blog_option($blog_id, 'iwp_client_public_key');
420
+ delete_blog_option($blog_id, 'iwp_client_action_message_id');
421
+ }
422
+ } else {
423
+ update_option('iwp_client_network_admin_install', -1);
424
+ delete_option('iwp_client_nossl_key');
425
+ delete_option('iwp_client_public_key');
426
+ delete_option('iwp_client_action_message_id');
427
+ }
428
+ }
429
+ } else {
430
+ delete_option('iwp_client_nossl_key');
431
+ delete_option('iwp_client_public_key');
432
+ delete_option('iwp_client_action_message_id');
433
+ }
434
+
435
+ delete_option('iwp_client_backup_tasks');
436
+ delete_option('iwp_client_notifications');
437
+ delete_option('iwp_client_brand');
438
+ delete_option('iwp_client_pageview_alerts');
439
+
440
+ add_option('iwp_client_activate_key', sha1( rand(1, 99999). uniqid('', true) . get_option('siteurl') ) );
441
+
442
+ }
443
+
444
+ /**
445
+ * Saves the (modified) options into the database
446
+ *
447
+ */
448
+ function save_options()
449
+ {
450
+ if (get_option($this->slug)) {
451
+ update_option($this->slug, $this->settings);
452
+ } else {
453
+ add_option($this->slug, $this->settings);
454
+ }
455
+ }
456
+
457
+ /**
458
+ * Deletes options for communication with IWP Admin panel
459
+ *
460
+ */
461
+ function uninstall( $deactivate = false )
462
+ {
463
+ global $current_user, $wpdb, $_wp_using_ext_object_cache;
464
+ $_wp_using_ext_object_cache = false;
465
+
466
+ if ($this->iwp_mmb_multisite != false) {
467
+ $network_blogs = $wpdb->get_col($wpdb->prepare("select `blog_id` from `{$wpdb->blogs}`"));
468
+ if(!empty($network_blogs)){
469
+ if( is_network_admin() ){
470
+ if( $deactivate ) {
471
+ delete_option('iwp_client_network_admin_install');
472
+ foreach($network_blogs as $blog_id){
473
+ delete_blog_option($blog_id, 'iwp_client_network_admin_install');
474
+ delete_blog_option($blog_id, 'iwp_client_nossl_key');
475
+ delete_blog_option($blog_id, 'iwp_client_public_key');
476
+ delete_blog_option($blog_id, 'iwp_client_action_message_id');
477
+ delete_blog_option($blog_id, 'iwp_client_maintenace_mode');
478
+ }
479
+ }
480
+ } else {
481
+ if( $deactivate )
482
+ delete_option('iwp_client_network_admin_install');
483
+
484
+ delete_option('iwp_client_nossl_key');
485
+ delete_option('iwp_client_public_key');
486
+ delete_option('iwp_client_action_message_id');
487
+ }
488
+ }
489
+ } else {
490
+ delete_option('iwp_client_nossl_key');
491
+ delete_option('iwp_client_public_key');
492
+ delete_option('iwp_client_action_message_id');
493
+ }
494
+
495
+ //Delete options
496
+ delete_option('iwp_client_maintenace_mode');
497
+ delete_option('iwp_client_backup_tasks');
498
+ wp_clear_scheduled_hook('iwp_client_backup_tasks');
499
+ delete_option('iwp_client_notifications');
500
+ wp_clear_scheduled_hook('iwp_client_notifications');
501
+ delete_option('iwp_client_brand');
502
+ delete_option('iwp_client_pageview_alerts');
503
+
504
+ delete_option('iwp_client_activate_key');
505
+ }
506
+
507
+
508
+ /**
509
+ * Constructs a url (for ajax purpose)
510
+ *
511
+ * @param mixed $base_page
512
+ */
513
+ function construct_url($params = array(), $base_page = 'index.php')
514
+ {
515
+ $url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
516
+ foreach ($params as $key => $value) {
517
+ $url .= "&$key=$value";
518
+ }
519
+
520
+ return $url;
521
+ }
522
+
523
+ /**
524
+ * Client update
525
+ *
526
+ */
527
+ function update_client_plugin($params)
528
+ {
529
+ extract($params);
530
+ if ($download_url) {
531
+ @include_once ABSPATH . 'wp-admin/includes/file.php';
532
+ @include_once ABSPATH . 'wp-admin/includes/misc.php';
533
+ @include_once ABSPATH . 'wp-admin/includes/template.php';
534
+ @include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
535
+ @include_once ABSPATH . 'wp-admin/includes/screen.php';
536
+
537
+ if (!$this->is_server_writable()) {
538
+ return array(
539
+ 'error' => 'Failed, please <a target="_blank" href="http://infinitewp.com/user-guide#ftp">add FTP details for automatic upgrades.</a></a>'
540
+ );
541
+ }
542
+
543
+ ob_start();
544
+ @unlink(dirname(__FILE__));
545
+ $upgrader = new Plugin_Upgrader();
546
+ $result = $upgrader->run(array(
547
+ 'package' => $download_url,
548
+ 'destination' => WP_PLUGIN_DIR,
549
+ 'clear_destination' => true,
550
+ 'clear_working' => true,
551
+ 'hook_extra' => array(
552
+ 'plugin' => 'iwp-client/init.php'
553
+ )
554
+ ));
555
+ ob_end_clean();
556
+ if (is_wp_error($result) || !$result) {
557
+ return array(
558
+ 'error' => 'InfiniteWP Client plugin could not be updated.'
559
+ );
560
+ } else {
561
+ return array(
562
+ 'success' => 'InfiniteWP Client plugin successfully updated.'
563
+ );
564
+ }
565
+ }
566
+ return array(
567
+ 'error' => 'Bad download path for client installation file.'
568
+ );
569
+ }
570
+
571
+ /**
572
+ * Automatically logs in when called from IWP Admin panel
573
+ *
574
+ */
575
+ function automatic_login()
576
+ {
577
+ $where = isset($_GET['iwp_goto']) ? $_GET['iwp_goto'] : false;
578
+ $username = isset($_GET['username']) ? $_GET['username'] : '';
579
+ $auto_login = isset($_GET['auto_login']) ? $_GET['auto_login'] : 0;
580
+
581
+ if( !function_exists('is_user_logged_in') )
582
+ include_once( ABSPATH.'wp-includes/pluggable.php' );
583
+
584
+ if (( $auto_login && strlen(trim($username)) && !is_user_logged_in() ) || (isset($this->iwp_mmb_multisite) && $this->iwp_mmb_multisite )) {
585
+ $signature = base64_decode($_GET['signature']);
586
+ $message_id = trim($_GET['message_id']);
587
+
588
+ $auth = $this->authenticate_message($where . $message_id, $signature, $message_id);
589
+ if ($auth === true) {
590
+
591
+ if (!headers_sent())
592
+ header('P3P: CP="CAO PSA OUR"');
593
+
594
+ if(!defined('IWP_MMB_USER_LOGIN'))
595
+ define('IWP_MMB_USER_LOGIN', true);
596
+
597
+ $siteurl = function_exists('get_site_option') ? get_site_option( 'siteurl' ) : get_option('siteurl');
598
+ $user = $this->iwp_mmb_get_user_info($username);
599
+ wp_set_current_user($user->ID);
600
+
601
+ if(!defined('COOKIEHASH') || (isset($this->iwp_mmb_multisite) && $this->iwp_mmb_multisite) )
602
+ wp_cookie_constants();
603
+
604
+ wp_set_auth_cookie($user->ID);
605
+ @iwp_mmb_client_header();
606
+
607
+ if((isset($this->iwp_mmb_multisite) && $this->iwp_mmb_multisite ) || isset($_REQUEST['iwpredirect'])){
608
+ if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
609
+ wp_safe_redirect(admin_url($where));
610
+ exit();
611
+ }
612
+ }
613
+ } else {
614
+ wp_die($auth['error']);
615
+ }
616
+ } elseif( is_user_logged_in() ) {
617
+ @iwp_mmb_client_header();
618
+ if(isset($_REQUEST['iwpredirect'])){
619
+ if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
620
+ wp_safe_redirect(admin_url($where));
621
+ exit();
622
+ }
623
+ }
624
+ }
625
+ }
626
+
627
+ function iwp_mmb_set_auth_cookie( $auth_cookie ){
628
+ if(!defined('IWP_MMB_USER_LOGIN'))
629
+ return false;
630
+
631
+ if( !defined('COOKIEHASH') )
632
+ wp_cookie_constants();
633
+
634
+ $_COOKIE['wordpress_'.COOKIEHASH] = $auth_cookie;
635
+
636
+ }
637
+ function iwp_mmb_set_logged_in_cookie( $logged_in_cookie ){
638
+ if(!defined('IWP_MMB_USER_LOGIN'))
639
+ return false;
640
+
641
+ if( !defined('COOKIEHASH') )
642
+ wp_cookie_constants();
643
+
644
+ $_COOKIE['wordpress_logged_in_'.COOKIEHASH] = $logged_in_cookie;
645
+ }
646
+
647
+ function admin_actions(){
648
+ add_filter('all_plugins', array($this, 'client_replace'));
649
+ }
650
+
651
+ function client_replace($all_plugins){
652
+ $replace = get_option("iwp_client_brand");
653
+ if(is_array($replace)){
654
+ if($replace['name'] || $replace['desc'] || $replace['author'] || $replace['author_url']){
655
+ $all_plugins['iwp-client/init.php']['Name'] = $replace['name'];
656
+ $all_plugins['iwp-client/init.php']['Title'] = $replace['name'];
657
+ $all_plugins['iwp-client/init.php']['Description'] = $replace['desc'];
658
+ $all_plugins['iwp-client/init.php']['AuthorURI'] = $replace['author_url'];
659
+ $all_plugins['iwp-client/init.php']['Author'] = $replace['author'];
660
+ $all_plugins['iwp-client/init.php']['AuthorName'] = $replace['author'];
661
+ $all_plugins['iwp-client/init.php']['PluginURI'] = '';
662
+ }
663
+
664
+ if($replace['hide']){
665
+ if (!function_exists('get_plugins')) {
666
+ include_once(ABSPATH . 'wp-admin/includes/plugin.php');
667
+ }
668
+ $activated_plugins = get_option('active_plugins');
669
+ if (!$activated_plugins)
670
+ $activated_plugins = array();
671
+ if(in_array('iwp-client/init.php',$activated_plugins))
672
+ unset($all_plugins['iwp-client/init.php']);
673
+ }
674
+ }
675
+
676
+ return $all_plugins;
677
+ }
678
+
679
+
680
+ }
681
+ ?>
helper.class.php ADDED
@@ -0,0 +1,506 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /************************************************************
3
+ * This plugin was modified by Revmakx *
4
+ * Copyright (c) 2012 Revmakx *
5
+ * www.revmakx.com *
6
+ * *
7
+ ************************************************************/
8
+ /*************************************************************
9
+ *
10
+ * helper.class.php
11
+ *
12
+ * Utility functions
13
+ *
14
+ *
15
+ * Copyright (c) 2011 Prelovac Media
16
+ * www.prelovac.com
17
+ **************************************************************/
18
+
19
+ class IWP_MMB_Helper
20
+ {
21
+ /**
22
+ * A helper function to log data
23
+ *
24
+ * @param mixed $mixed
25
+ */
26
+ function _log($mixed)
27
+ {
28
+ if (is_array($mixed)) {
29
+ $mixed = print_r($mixed, 1);
30
+ } else if (is_object($mixed)) {
31
+ ob_start();
32
+ var_dump($mixed);
33
+ $mixed = ob_get_clean();
34
+ }
35
+
36
+ $handle = fopen(dirname(__FILE__) . '/log', 'a');
37
+ fwrite($handle, $mixed . PHP_EOL);
38
+ fclose($handle);
39
+ }
40
+
41
+ function _escape(&$array)
42
+ {
43
+ global $wpdb;
44
+
45
+ if (!is_array($array)) {
46
+ return ($wpdb->escape($array));
47
+ } else {
48
+ foreach ((array) $array as $k => $v) {
49
+ if (is_array($v)) {
50
+ $this->_escape($array[$k]);
51
+ } else if (is_object($v)) {
52
+ //skip
53
+ } else {
54
+ $array[$k] = $wpdb->escape($v);
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Initializes the file system
62
+ *
63
+ */
64
+ function init_filesystem()
65
+ {
66
+ global $wp_filesystem;
67
+
68
+ if (!$wp_filesystem || !is_object($wp_filesystem)) {
69
+ WP_Filesystem();
70
+ }
71
+
72
+ if (!is_object($wp_filesystem))
73
+ return FALSE;
74
+
75
+ return TRUE;
76
+ }
77
+
78
+ /**
79
+ *
80
+ * Check if function exists or not on `suhosin` black list
81
+ *
82
+ */
83
+
84
+ function iwp_mmb_get_user_info( $user_info = false, $info = 'login' ){
85
+
86
+ if($user_info === false)
87
+ return false;
88
+
89
+ if( strlen( trim( $user_info ) ) == 0)
90
+ return false;
91
+
92
+
93
+ global $wp_version;
94
+ if (version_compare($wp_version, '3.2.2', '<=')){
95
+ return get_userdatabylogin( $user_info );
96
+ } else {
97
+ return get_user_by( $info, $user_info );
98
+ }
99
+ }
100
+
101
+ /**
102
+ *
103
+ * Call action item filters
104
+ *
105
+ */
106
+
107
+ function iwp_mmb_parse_action_params( $key = '', $params = null, $call_object = null ){
108
+
109
+ global $_iwp_mmb_item_filter;
110
+ $call_object = $call_object !== null ? $call_object : $this;
111
+ $return = array();
112
+
113
+ if(isset($_iwp_mmb_item_filter[$key]) && !empty($_iwp_mmb_item_filter[$key])){
114
+ if( isset($params['item_filter']) && !empty($params['item_filter'])){
115
+ foreach($params['item_filter'] as $_items){
116
+ if(!empty($_items)){
117
+ foreach($_items as $_item){
118
+ if(in_array($_item[0], $_iwp_mmb_item_filter[$key])){
119
+ $_item[1] = isset($_item[1]) ? $_item[1] : array();
120
+ $return = call_user_func(array( &$call_object, 'get_'.$_item[0]), $return, $_item[1]);
121
+ }
122
+ }
123
+ }
124
+ }
125
+ }
126
+ }
127
+
128
+ return $return;
129
+ }
130
+
131
+ /**
132
+ *
133
+ * Check if function exists or not on `suhosin` black list
134
+ *
135
+ */
136
+
137
+ function iwp_mmb_function_exists($function_callback){
138
+
139
+ if(!function_exists($function_callback))
140
+ return false;
141
+
142
+ $disabled = explode(', ', @ini_get('disable_functions'));
143
+ if (in_array($function_callback, $disabled))
144
+ return false;
145
+
146
+ if (extension_loaded('suhosin')) {
147
+ $suhosin = @ini_get("suhosin.executor.func.blacklist");
148
+ if (empty($suhosin) == false) {
149
+ $suhosin = explode(',', $suhosin);
150
+ $blacklist = array_map('trim', $suhosin);
151
+ $blacklist = array_map('strtolower', $blacklist);
152
+ if(in_array($function_callback, $blacklist))
153
+ return false;
154
+ }
155
+ }
156
+ return true;
157
+ }
158
+
159
+ /**
160
+ * Gets transient based on WP version
161
+ *
162
+ * @global string $wp_version
163
+ * @param string $option_name
164
+ * @return mixed
165
+ */
166
+
167
+ function iwp_mmb_set_transient($option_name = false, $data = false){
168
+
169
+ if (!$option_name || !$data) {
170
+ return false;
171
+ }
172
+ if($this->iwp_mmb_multisite)
173
+ return $this->iwp_mmb_set_sitemeta_transient($option_name, $data);
174
+
175
+ global $wp_version;
176
+
177
+ if (version_compare($wp_version, '2.7.9', '<=')) {
178
+ update_option($option_name, $data);
179
+ } else if (version_compare($wp_version, '2.9.9', '<=')) {
180
+ update_option('_transient_' . $option_name, $data);
181
+ } else {
182
+ update_option('_site_transient_' . $option_name, $data);
183
+ }
184
+
185
+ }
186
+ function iwp_mmb_get_transient($option_name)
187
+ {
188
+ if (trim($option_name) == '') {
189
+ return FALSE;
190
+ }
191
+ if($this->iwp_mmb_multisite)
192
+ return $this->iwp_mmb_get_sitemeta_transient($option_name);
193
+
194
+ global $wp_version;
195
+
196
+ $transient = array();
197
+
198
+ if (version_compare($wp_version, '2.7.9', '<=')) {
199
+ return get_option($option_name);
200
+ } else if (version_compare($wp_version, '2.9.9', '<=')) {
201
+ $transient = get_option('_transient_' . $option_name);
202
+ return apply_filters("transient_".$option_name, $transient);
203
+ } else {
204
+ $transient = get_option('_site_transient_' . $option_name);
205
+ return apply_filters("site_transient_".$option_name, $transient);
206
+ }
207
+ }
208
+
209
+ function iwp_mmb_delete_transient($option_name)
210
+ {
211
+ if (trim($option_name) == '') {
212
+ return FALSE;
213
+ }
214
+
215
+ global $wp_version;
216
+
217
+ if (version_compare($wp_version, '2.7.9', '<=')) {
218
+ delete_option($option_name);
219
+ } else if (version_compare($wp_version, '2.9.9', '<=')) {
220
+ delete_option('_transient_' . $option_name);
221
+ } else {
222
+ delete_option('_site_transient_' . $option_name);
223
+ }
224
+ }
225
+
226
+ function iwp_mmb_get_sitemeta_transient($option_name){
227
+ global $wpdb;
228
+ $option_name = '_site_transient_'. $option_name;
229
+
230
+ $result = $wpdb->get_var( $wpdb->prepare("SELECT `meta_value` FROM `{$wpdb->sitemeta}` WHERE meta_key = '{$option_name}' AND `site_id` = '{$this->iwp_mmb_multisite}' "));
231
+ $result = maybe_unserialize($result);
232
+ return $result;
233
+ }
234
+
235
+ function iwp_mmb_set_sitemeta_transient($option_name, $option_value){
236
+ global $wpdb;
237
+ $option_name = '_site_transient_'. $option_name;
238
+
239
+ if($this->iwp_mmb_get_sitemeta_transient($option_name)){
240
+ $result = $wpdb->update( $wpdb->sitemeta,
241
+ array(
242
+ 'meta_value' => maybe_serialize($option_value)
243
+ ),
244
+ array(
245
+ 'meta_key' => $option_name,
246
+ 'site_id' => $this->iwp_mmb_multisite
247
+ )
248
+ );
249
+ }else {
250
+ $result = $wpdb->insert( $wpdb->sitemeta,
251
+ array(
252
+ 'meta_key' => $option_name,
253
+ 'meta_value' => maybe_serialize($option_value),
254
+ 'site_id' => $this->iwp_mmb_multisite
255
+ )
256
+ );
257
+ }
258
+ return $result;
259
+ }
260
+
261
+ function delete_temp_dir($directory)
262
+ {
263
+ if (substr($directory, -1) == "/") {
264
+ $directory = substr($directory, 0, -1);
265
+ }
266
+ if (!file_exists($directory) || !is_dir($directory)) {
267
+ return false;
268
+ } elseif (!is_readable($directory)) {
269
+ return false;
270
+ } else {
271
+ $directoryHandle = opendir($directory);
272
+
273
+ while ($contents = readdir($directoryHandle)) {
274
+ if ($contents != '.' && $contents != '..') {
275
+ $path = $directory . "/" . $contents;
276
+
277
+ if (is_dir($path)) {
278
+ $this->delete_temp_dir($path);
279
+ } else {
280
+ unlink($path);
281
+ }
282
+ }
283
+ }
284
+ closedir($directoryHandle);
285
+ rmdir($directory);
286
+ return true;
287
+ }
288
+ }
289
+
290
+ function set_client_message_id($message_id = false)
291
+ {
292
+ if ($message_id) {
293
+ add_option('iwp_client_action_message_id', $message_id) or update_option('iwp_client_action_message_id', $message_id);
294
+ return $message_id;
295
+ }
296
+ return false;
297
+ }
298
+
299
+ function get_client_message_id()
300
+ {
301
+ return (int) get_option('iwp_client_action_message_id');
302
+ }
303
+
304
+ function set_admin_panel_public_key($public_key = false)
305
+ {
306
+ if ($public_key && !get_option('iwp_client_public_key')) {
307
+ add_option('iwp_client_public_key', base64_encode($public_key));
308
+ return true;
309
+ }
310
+ return false;
311
+ }
312
+
313
+ function get_admin_panel_public_key()
314
+ {
315
+ if (!get_option('iwp_client_public_key'))
316
+ return false;
317
+ return base64_decode(get_option('iwp_client_public_key'));
318
+ }
319
+
320
+
321
+ function get_random_signature()
322
+ {
323
+ if (!get_option('iwp_client_nossl_key'))
324
+ return false;
325
+ return base64_decode(get_option('iwp_client_nossl_key'));
326
+ }
327
+
328
+ function set_random_signature($random_key = false)
329
+ {
330
+ if ($random_key && !get_option('iwp_client_nossl_key')) {
331
+ add_option('iwp_client_nossl_key', base64_encode($random_key));
332
+ return true;
333
+ }
334
+ return false;
335
+ }
336
+
337
+
338
+ function authenticate_message($data = false, $signature = false, $message_id = false)
339
+ {
340
+ if (!$data && !$signature) {
341
+ return array(
342
+ 'error' => 'Authentication failed.'
343
+ );
344
+ }
345
+
346
+ $current_message = $this->get_client_message_id();
347
+
348
+ /*if ((int) $current_message > (int) $message_id)
349
+ return array(
350
+ 'error' => 'Invalid message recieved. Deactivate and activate the InfiniteWP Client plugin on this site, then remove the website from your InfiniteWP account and add it again.'
351
+ );*/
352
+
353
+ $pl_key = $this->get_admin_panel_public_key();
354
+ if (!$pl_key) {
355
+ return array(
356
+ 'error' => 'Authentication failed. Deactivate and activate the InfiniteWP Client plugin on this site, then remove the website from your InfiniteWP account and add it again.'
357
+ );
358
+ }
359
+
360
+ if (function_exists('openssl_verify') && !$this->get_random_signature()) {
361
+ $verify = openssl_verify($data, $signature, $pl_key);
362
+ if ($verify == 1) {
363
+ $message_id = $this->set_client_message_id($message_id);
364
+ return true;
365
+ } else if ($verify == 0) {
366
+ return array(
367
+ 'error' => 'Invalid message signature. Deactivate and activate the InfiniteWP Client plugin on this site, then remove the website from your InfiniteWP account and add it again.'
368
+ );
369
+ } else {
370
+ return array(
371
+ 'error' => 'Command not successful! Please try again.'
372
+ );
373
+ }
374
+ } else if ($this->get_random_signature()) {
375
+
376
+ if (md5($data . $this->get_random_signature()) == $signature) {
377
+ $message_id = $this->set_client_message_id($message_id);
378
+ return true;
379
+ }
380
+ return array(
381
+ 'error' => 'Invalid message signature. Deactivate and activate the InfiniteWP Client plugin on this site, then remove the website from your InfiniteWP account and add it again.'
382
+ );
383
+ }
384
+ // no rand key - deleted in get_stat maybe
385
+ else
386
+ return array(
387
+ 'error' => 'Invalid message signature. Deactivate and activate the InfiniteWP Client plugin on this site, then remove the website from your InfiniteWP account and add it again.'
388
+ );
389
+ }
390
+
391
+ function _secure_data($data = false){
392
+ if($data == false)
393
+ return false;
394
+
395
+ $pl_key = $this->get_admin_panel_public_key();
396
+ if (!$pl_key)
397
+ return false;
398
+
399
+ $secure = '';
400
+ if( function_exists('openssl_public_decrypt') && !$this->get_random_signature()){
401
+ if(is_array($data) && !empty($data)){
402
+ foreach($data as $input){
403
+ openssl_public_decrypt($input, $decrypted, $pl_key);
404
+ $secure .= $decrypted;
405
+ }
406
+ } else {
407
+ openssl_public_decrypt($input, $decrypted, $pl_key);
408
+ $secure = $decrypted;
409
+ }
410
+ return $secure;
411
+ }
412
+ return false;
413
+
414
+ }
415
+
416
+ function check_if_user_exists($username = false)
417
+ {
418
+ global $wpdb;
419
+ if ($username) {
420
+ if( !function_exists('username_exists') )
421
+ include_once(ABSPATH . WPINC . '/registration.php');
422
+
423
+ include_once(ABSPATH . 'wp-includes/pluggable.php');
424
+
425
+ if (username_exists($username) == null) {
426
+ return false;
427
+ }
428
+
429
+ $user = (array) $this->iwp_mmb_get_user_info( $username );
430
+ if ((isset($user[$wpdb->prefix . 'user_level']) && $user[$wpdb->prefix . 'user_level'] == 10) || isset($user[$wpdb->prefix . 'capabilities']['administrator']) ||
431
+ (isset($user['caps']['administrator']) && $user['caps']['administrator'] == 1)){
432
+ return true;
433
+ }
434
+ return false;
435
+ }
436
+ return false;
437
+ }
438
+
439
+ function refresh_updates()
440
+ {
441
+ if (rand(1, 3) == '2') {
442
+ require_once(ABSPATH . WPINC . '/update.php');
443
+ wp_update_plugins();
444
+ wp_update_themes();
445
+ wp_version_check();
446
+ }
447
+ }
448
+
449
+ function remove_http($url = '')
450
+ {
451
+ if ($url == 'http://' OR $url == 'https://') {
452
+ return $url;
453
+ }
454
+ return preg_replace('/^(http|https)\:\/\/(www.)?/i', '', $url);
455
+
456
+ }
457
+
458
+ function iwp_mmb_get_error($error_object)
459
+ {
460
+ if (!is_wp_error($error_object)) {
461
+ return $error_object != '' ? $error_object : '';
462
+ } else {
463
+ $errors = array();
464
+ if(!empty($error_object->error_data)) {
465
+ foreach ($error_object->error_data as $error_key => $error_string) {
466
+ $errors[] = str_replace('_', ' ', ucfirst($error_key)) . ': ' . $error_string;
467
+ }
468
+ } elseif (!empty($error_object->errors)){
469
+ foreach ($error_object->errors as $error_key => $err) {
470
+ $errors[] = 'Error: '.str_replace('_', ' ', strtolower($error_key));
471
+ }
472
+ }
473
+ return implode('<br />', $errors);
474
+ }
475
+ }
476
+
477
+ function is_server_writable(){
478
+ if((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && (get_filesystem_method(array(), false) != 'direct'))
479
+ return false;
480
+ else
481
+ return true;
482
+ }
483
+
484
+ function iwp_mmb_download_url($url, $file_name)
485
+ {
486
+ if (function_exists('fopen') && function_exists('ini_get') && ini_get('allow_url_fopen') == true && ($destination = @fopen($file_name, 'wb')) && ($source = @fopen($url, "r")) ) {
487
+
488
+
489
+ while ($a = @fread($source, 1024* 1024)) {
490
+ @fwrite($destination, $a);
491
+ }
492
+
493
+ fclose($source);
494
+ fclose($destination);
495
+ } else
496
+ if (!fsockopen_download($url, $file_name))
497
+ die('Error downloading file ' . $url);
498
+ return $file_name;
499
+ }
500
+
501
+
502
+
503
+
504
+
505
+ }
506
+ ?>
index.html ADDED
File without changes
init.php ADDED
@@ -0,0 +1,891 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: InfiniteWP - Client
4
+ Plugin URI: http://infinitewp.com/
5
+ Description: This is the client plugin of InfiniteWP that communicates with the InfiniteWP Admin panel.
6
+ Author: Revmakx
7
+ Version: 0.1.4
8
+ Author URI: http://www.revmakx.com
9
+ */
10
+ /************************************************************
11
+ * This plugin was modified by Revmakx *
12
+ * Copyright (c) 2012 Revmakx *
13
+ * www.revmakx.com *
14
+ * *
15
+ ************************************************************/
16
+
17
+ /*************************************************************
18
+ *
19
+ * init.php
20
+ *
21
+ * Initialize the communication with master
22
+ *
23
+ *
24
+ * Copyright (c) 2011 Prelovac Media
25
+ * www.prelovac.com
26
+ **************************************************************/
27
+
28
+ if(!defined('IWP_MMB_CLIENT_VERSION'))
29
+ define('IWP_MMB_CLIENT_VERSION', '0.1.4');
30
+
31
+ if ( !defined('IWP_MMB_XFRAME_COOKIE')){
32
+ $siteurl = function_exists('get_site_option') ? get_site_option( 'siteurl' ) : get_option('siteurl');
33
+ define('IWP_MMB_XFRAME_COOKIE', $xframe = 'wordpress_'.md5($siteurl).'_xframe');
34
+ }
35
+ global $wpdb, $iwp_mmb_plugin_dir, $iwp_mmb_plugin_url, $wp_version, $iwp_mmb_filters, $_iwp_mmb_item_filter;
36
+ if (version_compare(PHP_VERSION, '5.0.0', '<')) // min version 5 supported
37
+ exit("<p>InfiniteWP Client plugin requires PHP 5 or higher.</p>");
38
+
39
+
40
+ $iwp_mmb_wp_version = $wp_version;
41
+ $iwp_mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
42
+ $iwp_mmb_plugin_url = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__));
43
+
44
+ require_once("$iwp_mmb_plugin_dir/helper.class.php");
45
+ require_once("$iwp_mmb_plugin_dir/core.class.php");
46
+ /*
47
+ //IWP Remove starts here
48
+ require_once("$iwp_mmb_plugin_dir/post.class.php");
49
+ require_once("$iwp_mmb_plugin_dir/comment.class.php");
50
+ //IWP Remove ends here
51
+ */
52
+ require_once("$iwp_mmb_plugin_dir/stats.class.php");
53
+ require_once("$iwp_mmb_plugin_dir/backup.class.php");
54
+ require_once("$iwp_mmb_plugin_dir/installer.class.php");
55
+ /*
56
+ //IWP Remove starts here
57
+ require_once("$iwp_mmb_plugin_dir/link.class.php");
58
+ require_once("$iwp_mmb_plugin_dir/user.class.php");
59
+ //IWP Remove ends here
60
+ */
61
+ require_once("$iwp_mmb_plugin_dir/api.php");
62
+
63
+ require_once("$iwp_mmb_plugin_dir/plugins/search/search.php");
64
+ require_once("$iwp_mmb_plugin_dir/plugins/cleanup/cleanup.php");
65
+
66
+
67
+ if( !function_exists ('iwp_mmb_parse_request')) {
68
+ function iwp_mmb_parse_request()
69
+ {
70
+
71
+ if (!isset($HTTP_RAW_POST_DATA)) {
72
+ $HTTP_RAW_POST_DATA = file_get_contents('php://input');
73
+ }
74
+ ob_start();
75
+
76
+ global $current_user, $iwp_mmb_core, $new_actions, $wp_db_version, $wpmu_version, $_wp_using_ext_object_cache;
77
+ $data = base64_decode($HTTP_RAW_POST_DATA);
78
+ if ($data)
79
+ $num = @extract(unserialize($data));
80
+
81
+ if (isset($iwp_action)) {
82
+ $action = $iwp_action;
83
+ $_wp_using_ext_object_cache = false;
84
+ @set_time_limit(600);
85
+
86
+ if (!$iwp_mmb_core->check_if_user_exists($params['username']))
87
+ iwp_mmb_response('Username <b>' . $params['username'] . '</b> does not have administrative access. Enter the correct username in the site options.', false);
88
+
89
+ if ($action == 'add_site') {
90
+ iwp_mmb_add_site($params);
91
+ iwp_mmb_response('You should never see this.', false);
92
+ }
93
+
94
+ $auth = $iwp_mmb_core->authenticate_message($action . $id, $signature, $id);
95
+ if ($auth === true) {
96
+
97
+ if(isset($params['username']) && !is_user_logged_in()){
98
+ $user = function_exists('get_user_by') ? get_user_by('login', $params['username']) : get_userdatabylogin( $params['username'] );
99
+ wp_set_current_user($user->ID);
100
+ }
101
+
102
+ /* in case database upgrade required, do database backup and perform upgrade ( wordpress wp_upgrade() function ) */
103
+ if( strlen(trim($wp_db_version)) && !defined('ACX_PLUGIN_DIR') ){
104
+ if ( get_option('db_version') != $wp_db_version ) {
105
+ /* in multisite network, please update database manualy */
106
+ if (empty($wpmu_version) || (function_exists('is_multisite') && !is_multisite())){
107
+ if( ! function_exists('wp_upgrade'))
108
+ include_once(ABSPATH.'wp-admin/includes/upgrade.php');
109
+
110
+ ob_clean();
111
+ @wp_upgrade();
112
+ @do_action('after_db_upgrade');
113
+ ob_end_clean();
114
+ }
115
+ }
116
+ }
117
+
118
+ if(isset($params['secure'])){
119
+ if($decrypted = $iwp_mmb_core->_secure_data($params['secure'])){
120
+ $decrypted = maybe_unserialize($decrypted);
121
+ if(is_array($decrypted)){
122
+ foreach($decrypted as $key => $val){
123
+ if(!is_numeric($key))
124
+ $params[$key] = $val;
125
+ }
126
+ unset($params['secure']);
127
+ } else $params['secure'] = $decrypted;
128
+ }
129
+ }
130
+
131
+ if( !$iwp_mmb_core->register_action_params( $action, $params ) ){
132
+ global $_iwp_mmb_plugin_actions;
133
+ $_iwp_mmb_plugin_actions[$action] = $params;
134
+ }
135
+
136
+ } else {
137
+ iwp_mmb_response($auth['error'], false);
138
+ }
139
+ } else {
140
+ IWP_MMB_Stats::set_hit_count();
141
+ }
142
+ ob_end_clean();
143
+ }
144
+ }
145
+ /* Main response function */
146
+ if( !function_exists ( 'iwp_mmb_response' )) {
147
+
148
+ function iwp_mmb_response($response = false, $success = true)
149
+ {
150
+ $return = array();
151
+
152
+ if ((is_array($response) && empty($response)) || (!is_array($response) && strlen($response) == 0))
153
+ $return['error'] = 'Empty response.';
154
+ else if ($success)
155
+ $return['success'] = $response;
156
+ else
157
+ $return['error'] = $response;
158
+
159
+ if( !headers_sent() ){
160
+ header('HTTP/1.0 200 OK');
161
+ header('Content-Type: text/plain');
162
+ }
163
+ exit("<IWPHEADER>" . base64_encode(serialize($return))."<ENDIWPHEADER>");
164
+ }
165
+ }
166
+
167
+
168
+
169
+ if( !function_exists ( 'iwp_mmb_add_site' )) {
170
+ function iwp_mmb_add_site($params)
171
+ {
172
+ global $iwp_mmb_core;
173
+ $num = extract($params);
174
+
175
+ if ($num) {
176
+ if (!get_option('iwp_client_action_message_id') && !get_option('iwp_client_public_key')) {
177
+ $public_key = base64_decode($public_key);
178
+
179
+
180
+ if(trim($activation_key) != get_option('iwp_client_activate_key')){ //iwp
181
+ iwp_mmb_response('Invalid activation key', false);
182
+ return;
183
+ }
184
+
185
+ if (function_exists('openssl_verify') && !$user_random_key_signing) {
186
+ $verify = openssl_verify($action . $id, base64_decode($signature), $public_key);
187
+ if ($verify == 1) {
188
+ $iwp_mmb_core->set_admin_panel_public_key($public_key);
189
+ $iwp_mmb_core->set_client_message_id($id);
190
+ $iwp_mmb_core->get_stats_instance();
191
+ if(is_array($notifications) && !empty($notifications)){
192
+ $iwp_mmb_core->stats_instance->set_notifications($notifications);
193
+ }
194
+ if(is_array($brand) && !empty($brand)){
195
+ update_option('iwp_client_brand',$brand);
196
+ }
197
+
198
+ iwp_mmb_response($iwp_mmb_core->stats_instance->get_initial_stats(), true);
199
+ delete_option('iwp_client_activate_key');//iwp
200
+ } else if ($verify == 0) {
201
+ iwp_mmb_response('Invalid message signature. Please contact us if you see this message often.', false);
202
+ } else {
203
+ iwp_mmb_response('Command not successful. Please try again.', false);
204
+ }
205
+ } else {
206
+ if (!get_option('iwp_client_nossl_key')) {
207
+ srand();
208
+
209
+ $random_key = md5(base64_encode($public_key) . rand(0, getrandmax()));
210
+
211
+ $iwp_mmb_core->set_random_signature($random_key);
212
+ $iwp_mmb_core->set_client_message_id($id);
213
+ $iwp_mmb_core->set_admin_panel_public_key($public_key);
214
+ $iwp_mmb_core->get_stats_instance();
215
+ if(is_array($notifications) && !empty($notifications)){
216
+ $iwp_mmb_core->stats_instance->set_notifications($notifications);
217
+ }
218
+
219
+ if(is_array($brand) && !empty($brand)){
220
+ update_option('iwp_client_brand',$brand);
221
+ }
222
+
223
+ iwp_mmb_response($iwp_mmb_core->stats_instance->get_initial_stats(), true);
224
+ delete_option('iwp_client_activate_key');//IWP
225
+ } else
226
+ iwp_mmb_response('Please deactivate & activate InfiniteWP Client plugin on your site, then add the site again.', false);
227
+ }
228
+ } else {
229
+ iwp_mmb_response('Please deactivate &amp; activate InfiniteWP Client plugin on your site, then add the site again.', false);
230
+ }
231
+ } else {
232
+ iwp_mmb_response('Invalid parameters received. Please try again.', false);
233
+ }
234
+ }
235
+ }
236
+
237
+ if( !function_exists ( 'iwp_mmb_remove_site' )) {
238
+ function iwp_mmb_remove_site($params)
239
+ {
240
+ extract($params);
241
+ global $iwp_mmb_core;
242
+ $iwp_mmb_core->uninstall( $deactivate );
243
+
244
+ include_once(ABSPATH . 'wp-admin/includes/plugin.php');
245
+ $plugin_slug = basename(dirname(__FILE__)) . '/' . basename(__FILE__);
246
+
247
+ if ($deactivate) {
248
+ deactivate_plugins($plugin_slug, true);
249
+ }
250
+
251
+ if (!is_plugin_active($plugin_slug))
252
+ iwp_mmb_response(array(
253
+ 'deactivated' => 'Site removed successfully. <br /><br />InfiniteWP Client plugin successfully deactivated.'
254
+ ), true);
255
+ else
256
+ iwp_mmb_response(array(
257
+ 'removed_data' => 'Site removed successfully. <br /><br /><b>InfiniteWP Client plugin was not deactivated.</b>'
258
+ ), true);
259
+
260
+ }
261
+ }
262
+ if( !function_exists ( 'iwp_mmb_stats_get' )) {
263
+ function iwp_mmb_stats_get($params)
264
+ {
265
+ global $iwp_mmb_core;
266
+ $iwp_mmb_core->get_stats_instance();
267
+ iwp_mmb_response($iwp_mmb_core->stats_instance->get($params), true);
268
+ }
269
+ }
270
+
271
+ if( !function_exists ( 'iwp_mmb_client_header' )) {
272
+ function iwp_mmb_client_header()
273
+ { global $iwp_mmb_core, $current_user;
274
+
275
+ if(!headers_sent()){
276
+ if(isset($current_user->ID))
277
+ $expiration = time() + apply_filters('auth_cookie_expiration', 10800, $current_user->ID, false);
278
+ else
279
+ $expiration = time() + 10800;
280
+
281
+ setcookie(IWP_MMB_XFRAME_COOKIE, md5(IWP_MMB_XFRAME_COOKIE), $expiration, COOKIEPATH, COOKIE_DOMAIN, false, true);
282
+ $_COOKIE[IWP_MMB_XFRAME_COOKIE] = md5(IWP_MMB_XFRAME_COOKIE);
283
+ }
284
+ }
285
+ }
286
+
287
+ if( !function_exists ( 'iwp_mmb_pre_init_stats' )) {
288
+ function iwp_mmb_pre_init_stats( $params )
289
+ {
290
+ global $iwp_mmb_core;
291
+ $iwp_mmb_core->get_stats_instance();
292
+ return $iwp_mmb_core->stats_instance->pre_init_stats($params);
293
+ }
294
+ }
295
+
296
+ /*
297
+ //IWP Remove starts here
298
+ //post
299
+ if( !function_exists ( 'iwp_mmb_post_create' )) {
300
+ function iwp_mmb_post_create($params)
301
+ {
302
+ global $iwp_mmb_core;
303
+ $iwp_mmb_core->get_post_instance();
304
+ $return = $iwp_mmb_core->post_instance->create($params);
305
+ if (is_int($return))
306
+ iwp_mmb_response($return, true);
307
+ else{
308
+ if(isset($return['error'])){
309
+ iwp_mmb_response($return['error'], false);
310
+ } else {
311
+ iwp_mmb_response($return, false);
312
+ }
313
+ }
314
+ }
315
+ }
316
+
317
+ if( !function_exists ( 'iwp_mmb_change_post_status' )) {
318
+ function iwp_mmb_change_post_status($params)
319
+ {
320
+ global $iwp_mmb_core;
321
+ $iwp_mmb_core->get_post_instance();
322
+ $return = $iwp_mmb_core->post_instance->change_status($params);
323
+ //iwp_mmb_response($return, true);
324
+
325
+ }
326
+ }
327
+
328
+ //comments
329
+ if( !function_exists ( 'iwp_mmb_change_comment_status' )) {
330
+ function iwp_mmb_change_comment_status($params)
331
+ {
332
+ global $iwp_mmb_core;
333
+ $iwp_mmb_core->get_comment_instance();
334
+ $return = $iwp_mmb_core->comment_instance->change_status($params);
335
+ //iwp_mmb_response($return, true);
336
+ if ($return){
337
+ $iwp_mmb_core->get_stats_instance();
338
+ iwp_mmb_response($iwp_mmb_core->stats_instance->get_comments_stats($params), true);
339
+ }else
340
+ iwp_mmb_response('Comment not updated', false);
341
+ }
342
+
343
+ }
344
+ if( !function_exists ( 'iwp_mmb_comment_stats_get' )) {
345
+ function iwp_mmb_comment_stats_get($params)
346
+ {
347
+ global $iwp_mmb_core;
348
+ $iwp_mmb_core->get_stats_instance();
349
+ iwp_mmb_response($iwp_mmb_core->stats_instance->get_comments_stats($params), true);
350
+ }
351
+ }
352
+ //IWP Remove ends here
353
+ */
354
+
355
+ if( !function_exists ( 'iwp_mmb_backup_now' )) {
356
+ //backup
357
+ function iwp_mmb_backup_now($params)
358
+ {
359
+ global $iwp_mmb_core;
360
+
361
+ $iwp_mmb_core->get_backup_instance();
362
+ $return = $iwp_mmb_core->backup_instance->backup($params);
363
+
364
+ if (is_array($return) && array_key_exists('error', $return))
365
+ iwp_mmb_response($return['error'], false);
366
+ else {
367
+ iwp_mmb_response($return, true);
368
+ }
369
+ }
370
+ }
371
+
372
+ if( !function_exists ( 'iwp_mmb_run_task_now' )) {
373
+ function iwp_mmb_run_task_now($params)
374
+ {
375
+ global $iwp_mmb_core;
376
+ $iwp_mmb_core->get_backup_instance();
377
+ $return = $iwp_mmb_core->backup_instance->task_now($params['task_name']);
378
+ if (is_array($return) && array_key_exists('error', $return))
379
+ iwp_mmb_response($return['error'], false);
380
+ else {
381
+ iwp_mmb_response($return, true);
382
+ }
383
+ }
384
+ }
385
+
386
+ /*
387
+ //IWP Remove starts here
388
+ if( !function_exists ( 'iwp_mmb_email_backup' )) {
389
+ function iwp_mmb_email_backup($params)
390
+ {
391
+ global $iwp_mmb_core;
392
+ $iwp_mmb_core->get_backup_instance();
393
+ $return = $iwp_mmb_core->backup_instance->email_backup($params);
394
+
395
+ if (is_array($return) && array_key_exists('error', $return))
396
+ iwp_mmb_response($return['error'], false);
397
+ else {
398
+ iwp_mmb_response($return, true);
399
+ }
400
+ }
401
+ }
402
+ //IWP Remove ends here
403
+ */
404
+
405
+ if( !function_exists ( 'iwp_mmb_check_backup_compat' )) {
406
+ function iwp_mmb_check_backup_compat($params)
407
+ {
408
+ global $iwp_mmb_core;
409
+ $iwp_mmb_core->get_backup_instance();
410
+ $return = $iwp_mmb_core->backup_instance->check_backup_compat($params);
411
+
412
+ if (is_array($return) && array_key_exists('error', $return))
413
+ iwp_mmb_response($return['error'], false);
414
+ else {
415
+ iwp_mmb_response($return, true);
416
+ }
417
+ }
418
+ }
419
+
420
+ if( !function_exists ( 'iwp_mmb_get_backup_req' )) {
421
+ function iwp_mmb_get_backup_req( $params )
422
+ {
423
+ global $iwp_mmb_core;
424
+ $iwp_mmb_core->get_stats_instance();
425
+ $return = $iwp_mmb_core->stats_instance->get_backup_req($params);
426
+
427
+ iwp_mmb_response($return, true);
428
+ }
429
+ }
430
+
431
+
432
+ if( !function_exists ( 'iwp_mmb_scheduled_backup' )) {
433
+ function iwp_mmb_scheduled_backup($params)
434
+ {
435
+ global $iwp_mmb_core;
436
+ $iwp_mmb_core->get_backup_instance();
437
+ $return = $iwp_mmb_core->backup_instance->set_backup_task($params);
438
+ iwp_mmb_response($return, $return);
439
+ }
440
+ }
441
+
442
+
443
+ if( !function_exists ( 'mmm_delete_backup' )) {
444
+ function mmm_delete_backup($params)
445
+ {
446
+ global $iwp_mmb_core;
447
+ $iwp_mmb_core->get_backup_instance();
448
+ $return = $iwp_mmb_core->backup_instance->delete_backup($params);
449
+ iwp_mmb_response($return, $return);
450
+ }
451
+ }
452
+
453
+ if( !function_exists ( 'iwp_mmb_optimize_tables' )) {
454
+ function iwp_mmb_optimize_tables($params)
455
+ {
456
+ global $iwp_mmb_core;
457
+ $iwp_mmb_core->get_backup_instance();
458
+ $return = $iwp_mmb_core->backup_instance->optimize_tables();
459
+ if ($return)
460
+ iwp_mmb_response($return, true);
461
+ else
462
+ iwp_mmb_response(false, false);
463
+ }
464
+ }
465
+ if( !function_exists ( 'iwp_mmb_restore_now' )) {
466
+ function iwp_mmb_restore_now($params)
467
+ {
468
+ global $iwp_mmb_core;
469
+ $iwp_mmb_core->get_backup_instance();
470
+ $return = $iwp_mmb_core->backup_instance->restore($params);
471
+ if (is_array($return) && array_key_exists('error', $return))
472
+ iwp_mmb_response($return['error'], false);
473
+ else
474
+ iwp_mmb_response($return, true);
475
+
476
+ }
477
+ }
478
+
479
+ /*
480
+ //IWP Remove starts here
481
+ if( !function_exists ( 'iwp_mmb_remote_backup_now' )) {
482
+ function iwp_mmb_remote_backup_now($params)
483
+ {
484
+ global $iwp_mmb_core;
485
+ $backup_instance = $iwp_mmb_core->get_backup_instance();
486
+ $return = $iwp_mmb_core->backup_instance->remote_backup_now($params);
487
+ if (is_array($return) && array_key_exists('error', $return))
488
+ iwp_mmb_response($return['error'], false);
489
+ else
490
+ iwp_mmb_response($return, true);
491
+ }
492
+ }
493
+ //IWP Remove ends here
494
+ */
495
+
496
+
497
+ if( !function_exists ( 'iwp_mmb_clean_orphan_backups' )) {
498
+ function iwp_mmb_clean_orphan_backups()
499
+ {
500
+ global $iwp_mmb_core;
501
+ $backup_instance = $iwp_mmb_core->get_backup_instance();
502
+ $return = $iwp_mmb_core->backup_instance->cleanup();
503
+ if(is_array($return))
504
+ iwp_mmb_response($return, true);
505
+ else
506
+ iwp_mmb_response($return, false);
507
+ }
508
+ }
509
+
510
+ if( !function_exists ( 'iwp_mmb_update_client_plugin' )) {
511
+ function iwp_mmb_update_client_plugin($params)
512
+ {
513
+ global $iwp_mmb_core;
514
+ iwp_mmb_response($iwp_mmb_core->update_client_plugin($params), true);
515
+ }
516
+ }
517
+
518
+ if( !function_exists ( 'iwp_mmb_wp_checkversion' )) {
519
+ function iwp_mmb_wp_checkversion($params)
520
+ {
521
+ include_once(ABSPATH . 'wp-includes/version.php');
522
+ global $iwp_mmb_wp_version, $iwp_mmb_core;
523
+ iwp_mmb_response($iwp_mmb_wp_version, true);
524
+ }
525
+ }
526
+ if( !function_exists ( 'iwp_mmb_search_posts_by_term' )) {
527
+ function iwp_mmb_search_posts_by_term($params)
528
+ {
529
+ global $iwp_mmb_core;
530
+ $iwp_mmb_core->get_search_instance();
531
+
532
+ $search_type = trim($params['search_type']);
533
+ $search_term = strtolower(trim($params['search_term']));
534
+
535
+ switch ($search_type){
536
+ /*
537
+ //IWP Remove starts here
538
+ case 'page_post':
539
+ $return = $iwp_mmb_core->search_instance->iwp_mmb_search_posts_by_term($params);
540
+ if($return){
541
+ $return = serialize($return);
542
+ iwp_mmb_response($return, true);
543
+ }else{
544
+ iwp_mmb_response('No posts found', false);
545
+ }
546
+ break;
547
+ //IWP Remove ends here
548
+ */
549
+
550
+ case 'plugin':
551
+ $plugins = get_option('active_plugins');
552
+
553
+ $have_plugin = false;
554
+ foreach ($plugins as $plugin) {
555
+ if(strpos($plugin, $search_term)>-1){
556
+ $have_plugin = true;
557
+ }
558
+ }
559
+ if($have_plugin){
560
+ iwp_mmb_response(serialize($plugin), true);
561
+ }else{
562
+ iwp_mmb_response(false, false);
563
+ }
564
+ break;
565
+ case 'theme':
566
+ $theme = strtolower(get_option('template'));
567
+ if(strpos($theme, $search_term)>-1){
568
+ iwp_mmb_response($theme, true);
569
+ }else{
570
+ iwp_mmb_response(false, false);
571
+ }
572
+ break;
573
+ default: iwp_mmb_response(false, false);
574
+ }
575
+ $return = $iwp_mmb_core->search_instance->iwp_mmb_search_posts_by_term($params);
576
+
577
+
578
+
579
+ if ($return_if_true) {
580
+ iwp_mmb_response($return_value, true);
581
+ } else {
582
+ iwp_mmb_response($return_if_false, false);
583
+ }
584
+ }
585
+ }
586
+
587
+ if( !function_exists ( 'iwp_mmb_install_addon' )) {
588
+ function iwp_mmb_install_addon($params)
589
+ {
590
+ global $iwp_mmb_core;
591
+ $iwp_mmb_core->get_installer_instance();
592
+ $return = $iwp_mmb_core->installer_instance->install_remote_file($params);
593
+ iwp_mmb_response($return, true);
594
+
595
+ }
596
+ }
597
+
598
+ if( !function_exists ( 'iwp_mmb_do_upgrade' )) {
599
+ function iwp_mmb_do_upgrade($params)
600
+ {
601
+ global $iwp_mmb_core, $iwp_mmb_upgrading;
602
+ $iwp_mmb_core->get_installer_instance();
603
+ $return = $iwp_mmb_core->installer_instance->do_upgrade($params);
604
+ iwp_mmb_response($return, true);
605
+
606
+ }
607
+ }
608
+ /*
609
+ //IWP Remove starts here
610
+ if( !function_exists ( 'iwp_mmb_add_link' )) {
611
+ function iwp_mmb_add_link($params)
612
+ {
613
+ global $iwp_mmb_core;
614
+ $iwp_mmb_core->get_link_instance();
615
+ $return = $iwp_mmb_core->link_instance->add_link($params);
616
+ if (is_array($return) && array_key_exists('error', $return))
617
+
618
+ iwp_mmb_response($return['error'], false);
619
+ else {
620
+ iwp_mmb_response($return, true);
621
+ }
622
+
623
+ }
624
+ }
625
+
626
+ if( !function_exists ( 'iwp_mmb_add_user' )) {
627
+ function iwp_mmb_add_user($params)
628
+ {
629
+ global $iwp_mmb_core;
630
+ $iwp_mmb_core->get_user_instance();
631
+ $return = $iwp_mmb_core->user_instance->add_user($params);
632
+ if (is_array($return) && array_key_exists('error', $return))
633
+
634
+ iwp_mmb_response($return['error'], false);
635
+ else {
636
+ iwp_mmb_response($return, true);
637
+ }
638
+
639
+ }
640
+ }
641
+
642
+ if( !function_exists ('iwp_mmb_get_users')) {
643
+ function iwp_mmb_get_users($params)
644
+ {
645
+ global $iwp_mmb_core;
646
+ $iwp_mmb_core->get_user_instance();
647
+ $return = $iwp_mmb_core->user_instance->get_users($params);
648
+ if (is_array($return) && array_key_exists('error', $return))
649
+ iwp_mmb_response($return['error'], false);
650
+ else {
651
+ iwp_mmb_response($return, true);
652
+ }
653
+ }
654
+ }
655
+
656
+ if( !function_exists ('iwp_mmb_edit_users')) {
657
+ function iwp_mmb_edit_users($params)
658
+ {
659
+ global $iwp_mmb_core;
660
+ $iwp_mmb_core->get_user_instance();
661
+ $return = $iwp_mmb_core->user_instance->edit_users($params);
662
+ iwp_mmb_response($return, true);
663
+ }
664
+ }
665
+ //IWP Remove ends here
666
+ */
667
+
668
+ if( !function_exists ( 'iwp_mmb_iframe_plugins_fix' )) {
669
+ function iwp_mmb_iframe_plugins_fix($update_actions)
670
+ {
671
+ foreach($update_actions as $key => $action)
672
+ {
673
+ $update_actions[$key] = str_replace('target="_parent"','',$action);
674
+ }
675
+
676
+ return $update_actions;
677
+
678
+ }
679
+ }
680
+ /*
681
+ //IWP Remove starts here
682
+ if( !function_exists ( 'iwp_mmb_execute_php_code' )) {
683
+ function iwp_mmb_execute_php_code($params)
684
+ {
685
+ ob_start();
686
+ eval($params['code']);
687
+ $return = ob_get_flush();
688
+ iwp_mmb_response(print_r($return, true), true);
689
+ }
690
+ }
691
+
692
+ //IWP Remove ends here
693
+ */
694
+ if( !function_exists ( 'iwp_mmb_set_notifications' )) {
695
+ function iwp_mmb_set_notifications($params)
696
+ {
697
+ global $iwp_mmb_core;
698
+ $iwp_mmb_core->get_stats_instance();
699
+ $return = $iwp_mmb_core->stats_instance->set_notifications($params);
700
+ if (is_array($return) && array_key_exists('error', $return))
701
+ iwp_mmb_response($return['error'], false);
702
+ else {
703
+ iwp_mmb_response($return, true);
704
+ }
705
+
706
+ }
707
+ }
708
+
709
+ if( !function_exists ( 'iwp_mmb_set_alerts' )) {
710
+ function iwp_mmb_set_alerts($params)
711
+ {
712
+ global $iwp_mmb_core;
713
+ $iwp_mmb_core->get_stats_instance();
714
+ $return = $iwp_mmb_core->stats_instance->set_alerts($params);
715
+ iwp_mmb_response(true, true);
716
+ }
717
+
718
+ }
719
+
720
+ if(!function_exists('iwp_mmb_more_reccurences')){
721
+ //Backup Tasks
722
+ add_filter('cron_schedules', 'iwp_mmb_more_reccurences');
723
+ function iwp_mmb_more_reccurences($schedules) {
724
+
725
+ $schedules['minutely'] = array('interval' => 60, 'display' => 'Once in a minute');
726
+ $schedules['fiveminutes'] = array('interval' => 300, 'display' => 'Once every five minutes');
727
+ $schedules['tenminutes'] = array('interval' => 600, 'display' => 'Once every ten minutes');
728
+
729
+ return $schedules;
730
+ }
731
+ }
732
+
733
+
734
+ if (!wp_next_scheduled('iwp_client_backup_tasks')) {
735
+ wp_schedule_event( time(), 'tenminutes', 'iwp_client_backup_tasks' );
736
+ }
737
+ add_action('iwp_client_backup_tasks', 'iwp_check_backup_tasks');
738
+
739
+
740
+
741
+ /*
742
+ //IWP Remove starts here
743
+ if( !function_exists('iwp_check_backup_tasks') ){
744
+ function iwp_check_backup_tasks() {
745
+ global $iwp_mmb_core, $_wp_using_ext_object_cache;
746
+ $_wp_using_ext_object_cache = false;
747
+
748
+ $iwp_mmb_core->get_backup_instance();
749
+ $iwp_mmb_core->backup_instance->check_backup_tasks();
750
+ }
751
+ }
752
+
753
+ if (!wp_next_scheduled('iwp_client_notifications')) {
754
+ wp_schedule_event( time(), 'twicedaily', 'iwp_client_notifications' );
755
+ }
756
+ add_action('iwp_client_notifications', 'iwp_check_notifications');
757
+
758
+ //IWP Remove ends here
759
+ */
760
+
761
+
762
+ if( !function_exists('iwp_check_notifications') ){
763
+ function iwp_check_notifications() {
764
+ global $iwp_mmb_core, $_wp_using_ext_object_cache;
765
+ $_wp_using_ext_object_cache = false;
766
+
767
+ $iwp_mmb_core->get_stats_instance();
768
+ $iwp_mmb_core->stats_instance->check_notifications();
769
+ }
770
+ }
771
+
772
+
773
+ if( !function_exists('iwp_mmb_get_plugins_themes') ){
774
+ function iwp_mmb_get_plugins_themes($params) {
775
+ global $iwp_mmb_core;
776
+ $iwp_mmb_core->get_installer_instance();
777
+ $return = $iwp_mmb_core->installer_instance->get($params);
778
+ iwp_mmb_response($return, true);
779
+ }
780
+ }
781
+
782
+ if( !function_exists('iwp_mmb_edit_plugins_themes') ){
783
+ function iwp_mmb_edit_plugins_themes($params) {
784
+ global $iwp_mmb_core;
785
+ $iwp_mmb_core->get_installer_instance();
786
+ $return = $iwp_mmb_core->installer_instance->edit($params);
787
+ iwp_mmb_response($return, true);
788
+ }
789
+ }
790
+
791
+ /*
792
+ //IWP Remove starts here
793
+ if( !function_exists('iwp_mmb_client_brand')){
794
+ function iwp_mmb_client_brand($params) {
795
+ update_option("iwp_client_brand",$params['brand']);
796
+ iwp_mmb_response(true, true);
797
+ }
798
+ }
799
+ //IWP Remove ends here
800
+ */
801
+
802
+ if( !function_exists('iwp_mmb_maintenance_mode')){
803
+ function iwp_mmb_maintenance_mode( $params ) {
804
+ global $wp_object_cache;
805
+
806
+ $default = get_option('iwp_client_maintenace_mode');
807
+ $params = empty($default) ? $params : array_merge($default, $params);
808
+ update_option("iwp_client_maintenace_mode", $params);
809
+
810
+ if(!empty($wp_object_cache))
811
+ @$wp_object_cache->flush();
812
+ iwp_mmb_response(true, true);
813
+ }
814
+ }
815
+
816
+ if( !function_exists('iwp_mmb_plugin_actions') ){
817
+ function iwp_mmb_plugin_actions() {
818
+ global $iwp_mmb_actions, $iwp_mmb_core;
819
+
820
+ if(!empty($iwp_mmb_actions)){
821
+ global $_iwp_mmb_plugin_actions;
822
+ if(!empty($_iwp_mmb_plugin_actions)){
823
+ $failed = array();
824
+ foreach($_iwp_mmb_plugin_actions as $action => $params){
825
+ if(isset($iwp_mmb_actions[$action]))
826
+ call_user_func($iwp_mmb_actions[$action], $params);
827
+ else
828
+ $failed[] = $action;
829
+ }
830
+ if(!empty($failed)){
831
+ $f = implode(', ', $failed);
832
+ $s = count($f) > 1 ? 'Actions "' . $f . '" do' : 'Action "' . $f . '" does';
833
+ iwp_mmb_response($s.' not exist. Please update your IWP Client plugin.', false);
834
+ }
835
+
836
+ }
837
+ }
838
+
839
+ global $pagenow, $current_user, $mmode;
840
+ if( !is_admin() && !in_array($pagenow, array( 'wp-login.php' ))){
841
+ $mmode = get_option('iwp_client_maintenace_mode');
842
+ if( !empty($mmode) ){
843
+ if(isset($mmode['active']) && $mmode['active'] == true){
844
+ if(isset($current_user->data) && !empty($current_user->data) && isset($mmode['hidecaps']) && !empty($mmode['hidecaps'])){
845
+ $usercaps = array();
846
+ if(isset($current_user->caps) && !empty($current_user->caps)){
847
+ $usercaps = $current_user->caps;
848
+ }
849
+ foreach($mmode['hidecaps'] as $cap => $hide){
850
+ if(!$hide)
851
+ continue;
852
+
853
+ foreach($usercaps as $ucap => $val){
854
+ if($ucap == $cap){
855
+ ob_end_clean();
856
+ ob_end_flush();
857
+ die($mmode['template']);
858
+ }
859
+ }
860
+ }
861
+ } else
862
+ die($mmode['template']);
863
+ }
864
+ }
865
+ }
866
+ }
867
+ }
868
+
869
+ $iwp_mmb_core = new IWP_MMB_Core();
870
+
871
+ if(isset($_GET['auto_login']))
872
+ $iwp_mmb_core->automatic_login();
873
+
874
+ if (function_exists('register_activation_hook'))
875
+ register_activation_hook( __FILE__ , array( $iwp_mmb_core, 'install' ));
876
+
877
+ if (function_exists('register_deactivation_hook'))
878
+ register_deactivation_hook(__FILE__, array( $iwp_mmb_core, 'uninstall' ));
879
+
880
+ if (function_exists('add_action'))
881
+ add_action('init', 'iwp_mmb_plugin_actions', 99999);
882
+
883
+ if (function_exists('add_filter'))
884
+ add_filter('install_plugin_complete_actions','iwp_mmb_iframe_plugins_fix');
885
+
886
+ if( isset($_COOKIE[IWP_MMB_XFRAME_COOKIE]) ){
887
+ remove_action( 'admin_init', 'send_frame_options_header');
888
+ remove_action( 'login_init', 'send_frame_options_header');
889
+ }
890
+
891
+ ?>
installer.class.php ADDED
@@ -0,0 +1,816 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /************************************************************
3
+ * This plugin was modified by Revmakx *
4
+ * Copyright (c) 2012 Revmakx *
5
+ * www.revmakx.com *
6
+ * *
7
+ ************************************************************/
8
+ /*************************************************************
9
+ *
10
+ * installer.class.php
11
+ *
12
+ * Upgrade WordPress
13
+ *
14
+ *
15
+ * Copyright (c) 2011 Prelovac Media
16
+ * www.prelovac.com
17
+ **************************************************************/
18
+
19
+ class IWP_MMB_Installer extends IWP_MMB_Core
20
+ {
21
+ function __construct()
22
+ {
23
+ @set_time_limit(600);
24
+ parent::__construct();
25
+ @include_once(ABSPATH . 'wp-admin/includes/file.php');
26
+ @include_once(ABSPATH . 'wp-admin/includes/plugin.php');
27
+ @include_once(ABSPATH . 'wp-admin/includes/theme.php');
28
+ @include_once(ABSPATH . 'wp-admin/includes/misc.php');
29
+ @include_once(ABSPATH . 'wp-admin/includes/template.php');
30
+ @include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
31
+
32
+ global $wp_filesystem;
33
+ if (!$wp_filesystem)
34
+ WP_Filesystem();
35
+ }
36
+
37
+ function iwp_mmb_maintenance_mode($enable = false, $maintenance_message = '')
38
+ {
39
+ global $wp_filesystem;
40
+
41
+ $maintenance_message .= '<?php $upgrading = ' . time() . '; ?>';
42
+
43
+ $file = $wp_filesystem->abspath() . '.maintenance';
44
+ if ($enable) {
45
+ $wp_filesystem->delete($file);
46
+ $wp_filesystem->put_contents($file, $maintenance_message, FS_CHMOD_FILE);
47
+ } else {
48
+ $wp_filesystem->delete($file);
49
+ }
50
+ }
51
+
52
+ function install_remote_file($params)
53
+ {
54
+ global $wp_filesystem;
55
+ extract($params);
56
+
57
+ if (!isset($package) || empty($package))
58
+ return array(
59
+ 'error' => '<p>No files received. Internal error.</p>'
60
+ );
61
+
62
+ if (defined('WP_INSTALLING') && file_exists(ABSPATH . '.maintenance'))
63
+ return array(
64
+ 'error' => '<p>Site under maintanace.</p>'
65
+ );
66
+
67
+ if (!class_exists('WP_Upgrader'))
68
+ include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
69
+
70
+ $upgrader_skin = new WP_Upgrader_Skin();
71
+ $upgrader_skin->done_header = true;
72
+
73
+ $upgrader = new WP_Upgrader($upgrader_skin);
74
+ $destination = $type == 'themes' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR;
75
+ $clear_destination = isset($clear_destination) ? $clear_destination : false;
76
+
77
+ foreach ($package as $package_url) {
78
+ $key = basename($package_url);
79
+ $install_info[$key] = @$upgrader->run(array(
80
+ 'package' => $package_url,
81
+ 'destination' => $destination,
82
+ 'clear_destination' => $clear_destination, //Do not overwrite files.
83
+ 'clear_working' => true,
84
+ 'hook_extra' => array()
85
+ ));
86
+ }
87
+
88
+ if ($activate) {
89
+ if ($type == 'plugins') {
90
+ include_once(ABSPATH . 'wp-admin/includes/plugin.php');
91
+ $all_plugins = get_plugins();
92
+ foreach ($all_plugins as $plugin_slug => $plugin) {
93
+ $plugin_dir = preg_split('/\//', $plugin_slug);
94
+ foreach ($install_info as $key => $install) {
95
+ if (!$install || is_wp_error($install))
96
+ continue;
97
+ if ($install['destination_name'] == $plugin_dir[0]) {
98
+ $install_info[$key]['activated'] = activate_plugin($plugin_slug, '', false);
99
+ }
100
+ }
101
+ }
102
+ } else if (count($install_info) == 1) {
103
+ global $wp_themes;
104
+ include_once(ABSPATH . 'wp-includes/theme.php');
105
+
106
+ $wp_themes = null;
107
+ unset($wp_themes); //prevent theme data caching
108
+
109
+ $all_themes = get_themes();
110
+ foreach ($all_themes as $theme_name => $theme_data) {
111
+ foreach ($install_info as $key => $install) {
112
+ if (!$install || is_wp_error($install))
113
+ continue;
114
+
115
+ if ($theme_data['Template'] == $install['destination_name']) {
116
+ $install_info[$key]['activated'] = switch_theme($theme_data['Template'], $theme_data['Stylesheet']);
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+ ob_clean();
123
+ $this->iwp_mmb_maintenance_mode(false);
124
+ return $install_info;
125
+ }
126
+
127
+ function do_upgrade($params = null)
128
+ {
129
+ if ($params == null || empty($params))
130
+ return array(
131
+ 'failed' => 'No upgrades passed.'
132
+ );
133
+
134
+ if (!$this->is_server_writable()) {
135
+ return array(
136
+ 'error' => 'Failed, please <a target="_blank" href="http://infinitewp.com/user-guide#ftp">add FTP details</a></a>'
137
+ );
138
+ }
139
+
140
+
141
+ $params = isset($params['upgrades_all']) ? $params['upgrades_all'] : $params;
142
+
143
+ $core_upgrade = isset($params['wp_upgrade']) ? $params['wp_upgrade'] : array();
144
+ $upgrade_plugins = isset($params['upgrade_plugins']) ? $params['upgrade_plugins'] : array();
145
+ $upgrade_themes = isset($params['upgrade_themes']) ? $params['upgrade_themes'] : array();
146
+
147
+ $upgrades = array();
148
+ $premium_upgrades = array();
149
+ if (!empty($core_upgrade)) {
150
+ $upgrades['core'] = $this->upgrade_core($core_upgrade);
151
+ }
152
+
153
+ if (!empty($upgrade_plugins)) {
154
+ $plugin_files = array();
155
+ foreach ($upgrade_plugins as $plugin) {
156
+ if (isset($plugin->file))
157
+ $plugin_files[$plugin->file] = $plugin->old_version;
158
+ else
159
+ $premium_upgrades[md5($plugin->name)] = $plugin;
160
+ }
161
+ if (!empty($plugin_files))
162
+ $upgrades['plugins'] = $this->upgrade_plugins($plugin_files);
163
+
164
+ }
165
+
166
+ if (!empty($upgrade_themes)) {
167
+ $theme_temps = array();
168
+ foreach ($upgrade_themes as $theme) {
169
+ if (isset($theme['theme_tmp']))
170
+ $theme_temps[] = $theme['theme_tmp'];
171
+ else
172
+ $premium_upgrades[md5($theme['name'])] = $theme;
173
+ }
174
+
175
+ if (!empty($theme_temps))
176
+ $upgrades['themes'] = $this->upgrade_themes($theme_temps);
177
+
178
+ }
179
+
180
+ if (!empty($premium_upgrades)) {
181
+ $premium_upgrades = $this->upgrade_premium($premium_upgrades);
182
+ if (!empty($premium_upgrades)) {
183
+ if (!empty($upgrades)) {
184
+ foreach ($upgrades as $key => $val) {
185
+ if (isset($premium_upgrades[$key])) {
186
+ $upgrades[$key] = array_merge_recursive($upgrades[$key], $premium_upgrades[$key]);
187
+ }
188
+ }
189
+ } else {
190
+ $upgrades = $premium_upgrades;
191
+ }
192
+ }
193
+ }
194
+ ob_clean();
195
+ $this->iwp_mmb_maintenance_mode(false);
196
+ return $upgrades;
197
+ }
198
+
199
+ /**
200
+ * Upgrades WordPress locally
201
+ *
202
+ */
203
+ function upgrade_core($current)
204
+ {
205
+ ob_start();
206
+ if (!function_exists('wp_version_check'))
207
+ include_once(ABSPATH . '/wp-admin/includes/update.php');
208
+
209
+ @wp_version_check();
210
+
211
+ $current_update = false;
212
+ ob_end_flush();
213
+ ob_end_clean();
214
+ $core = $this->iwp_mmb_get_transient('update_core');
215
+
216
+ if (isset($core->updates) && !empty($core->updates)) {
217
+ $updates = $core->updates[0];
218
+ $updated = $core->updates[0];
219
+ if (!isset($updated->response) || $updated->response == 'latest')
220
+ return array(
221
+ 'upgraded' => ' updated'
222
+ );
223
+
224
+ if ($updated->response == "development" && $current->response == "upgrade") {
225
+ return array(
226
+ 'upgraded' => '<font color="#900">Unexpected error. Please upgrade manually.</font>'
227
+ );
228
+ } else if ($updated->response == $current->response || ($updated->response == "upgrade" && $current->response == "development")) {
229
+ if ($updated->locale != $current->locale) {
230
+ foreach ($updates as $update) {
231
+ if ($update->locale == $current->locale) {
232
+ $current_update = $update;
233
+ break;
234
+ }
235
+ }
236
+ if ($current_update == false)
237
+ return array(
238
+ 'error' => ' Localization mismatch. Try again.'
239
+ );
240
+ } else {
241
+ $current_update = $updated;
242
+ }
243
+ } else
244
+ return array(
245
+ 'error' => ' Transient mismatch. Try again.'
246
+ );
247
+ } else
248
+ return array(
249
+ 'error' => ' Refresh transient failed. Try again.'
250
+ );
251
+ if ($current_update != false) {
252
+ global $iwp_mmb_wp_version, $wp_filesystem, $wp_version;
253
+
254
+ if (version_compare($wp_version, '3.1.9', '>')) {
255
+ if (!class_exists('Core_Upgrader'))
256
+ include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
257
+
258
+ $core = new Core_Upgrader();
259
+ $result = $core->upgrade($current_update);
260
+ $this->iwp_mmb_maintenance_mode(false);
261
+ if (is_wp_error($result)) {
262
+ return array(
263
+ 'error' => $this->iwp_mmb_get_error($result)
264
+ );
265
+ } else
266
+ return array(
267
+ 'upgraded' => ' updated'
268
+ );
269
+
270
+ } else {
271
+ if (!class_exists('WP_Upgrader')) {
272
+ include_once(ABSPATH . 'wp-admin/includes/update.php');
273
+ if (function_exists('wp_update_core')) {
274
+ $result = wp_update_core($current_update);
275
+ if (is_wp_error($result)) {
276
+ return array(
277
+ 'error' => $this->iwp_mmb_get_error($result)
278
+ );
279
+ } else
280
+ return array(
281
+ 'upgraded' => ' updated'
282
+ );
283
+ }
284
+ }
285
+
286
+ if (class_exists('WP_Upgrader')) {
287
+ $upgrader_skin = new WP_Upgrader_Skin();
288
+ $upgrader_skin->done_header = true;
289
+
290
+ $upgrader = new WP_Upgrader($upgrader_skin);
291
+
292
+ // Is an update available?
293
+ if (!isset($current_update->response) || $current_update->response == 'latest')
294
+ return array(
295
+ 'upgraded' => ' updated'
296
+ );
297
+
298
+ $res = $upgrader->fs_connect(array(
299
+ ABSPATH,
300
+ WP_CONTENT_DIR
301
+ ));
302
+ if (is_wp_error($res))
303
+ return array(
304
+ 'error' => $this->iwp_mmb_get_error($res)
305
+ );
306
+
307
+ $wp_dir = trailingslashit($wp_filesystem->abspath());
308
+
309
+ $core_package = false;
310
+ if (isset($current_update->package) && !empty($current_update->package))
311
+ $core_package = $current_update->package;
312
+ elseif (isset($current_update->packages->full) && !empty($current_update->packages->full))
313
+ $core_package = $current_update->packages->full;
314
+
315
+ $download = $upgrader->download_package($core_package);
316
+ if (is_wp_error($download))
317
+ return array(
318
+ 'error' => $this->iwp_mmb_get_error($download)
319
+ );
320
+
321
+ $working_dir = $upgrader->unpack_package($download);
322
+ if (is_wp_error($working_dir))
323
+ return array(
324
+ 'error' => $this->iwp_mmb_get_error($working_dir)
325
+ );
326
+
327
+ if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
328
+ $wp_filesystem->delete($working_dir, true);
329
+ return array(
330
+ 'error' => 'Unable to move update files.'
331
+ );
332
+ }
333
+
334
+ $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
335
+
336
+ require(ABSPATH . 'wp-admin/includes/update-core.php');
337
+
338
+
339
+ $update_core = update_core($working_dir, $wp_dir);
340
+ ob_end_clean();
341
+
342
+ $this->iwp_mmb_maintenance_mode(false);
343
+ if (is_wp_error($update_core))
344
+ return array(
345
+ 'error' => $this->iwp_mmb_get_error($update_core)
346
+ );
347
+ ob_end_flush();
348
+ return array(
349
+ 'upgraded' => 'updated'
350
+ );
351
+ } else {
352
+ return array(
353
+ 'error' => 'failed'
354
+ );
355
+ }
356
+ }
357
+ } else {
358
+ return array(
359
+ 'error' => 'failed'
360
+ );
361
+ }
362
+ }
363
+
364
+ function upgrade_plugins($plugins = false)
365
+ {
366
+ if (!$plugins || empty($plugins))
367
+ return array(
368
+ 'error' => 'No plugin files for upgrade.'
369
+ );
370
+
371
+ $current = $this->iwp_mmb_get_transient('update_plugins');
372
+ $versions = array();
373
+ if(!empty($current)){
374
+ foreach($plugins as $plugin => $data){
375
+ if(isset($current->checked[$plugin])){
376
+ $versions[$current->checked[$plugin]] = $plugin;
377
+ }
378
+ }
379
+ }
380
+ $return = array();
381
+ if (class_exists('Plugin_Upgrader') && class_exists('Bulk_Plugin_Upgrader_Skin')) {
382
+ $upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
383
+ $result = $upgrader->bulk_upgrade(array_keys($plugins));
384
+ if (!function_exists('wp_update_plugins'))
385
+ include_once(ABSPATH . 'wp-includes/update.php');
386
+
387
+ @wp_update_plugins();
388
+ $current = $this->iwp_mmb_get_transient('update_plugins');
389
+ if (!empty($result)) {
390
+ foreach ($result as $plugin_slug => $plugin_info) {
391
+ if (!$plugin_info || is_wp_error($plugin_info)) {
392
+ $return[$plugin_slug] = $this->iwp_mmb_get_error($plugin_info);
393
+ } else {
394
+ if(!empty($result[$plugin_slug]) || (isset($current->checked[$plugin_slug]) && version_compare(array_search($plugin_slug, $versions), $current->checked[$plugin_slug], '<') == true)){
395
+ $return[$plugin_slug] = 1;
396
+ } else {
397
+ update_option('iwp_client_forcerefresh', true);
398
+ $return[$plugin_slug] = 'Could not refresh upgrade transients, please reload website data';
399
+ }
400
+ }
401
+ }
402
+ ob_end_clean();
403
+ return array(
404
+ 'upgraded' => $return
405
+ );
406
+ } else
407
+ return array(
408
+ 'error' => 'Upgrade failed.'
409
+ );
410
+ } else {
411
+ ob_end_clean();
412
+ return array(
413
+ 'error' => 'WordPress update required first.'
414
+ );
415
+ }
416
+ }
417
+
418
+ function upgrade_themes($themes = false)
419
+ {
420
+ if (!$themes || empty($themes))
421
+ return array(
422
+ 'error' => 'No theme files for upgrade.'
423
+ );
424
+
425
+ $current = $this->iwp_mmb_get_transient('update_themes');
426
+ $versions = array();
427
+ if(!empty($current)){
428
+ foreach($themes as $theme){
429
+ if(isset($current->checked[$theme])){
430
+ $versions[$current->checked[$theme]] = $theme;
431
+ }
432
+ }
433
+ }
434
+ if (class_exists('Theme_Upgrader') && class_exists('Bulk_Theme_Upgrader_Skin')) {
435
+ $upgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('title', 'nonce', 'url', 'theme')));
436
+ $result = $upgrader->bulk_upgrade($themes);
437
+
438
+ if (!function_exists('wp_update_themes'))
439
+ include_once(ABSPATH . 'wp-includes/update.php');
440
+
441
+ @wp_update_themes();
442
+ $current = $this->iwp_mmb_get_transient('update_themes');
443
+ $return = array();
444
+ if (!empty($result)) {
445
+ foreach ($result as $theme_tmp => $theme_info) {
446
+ if (is_wp_error($theme_info) || empty($theme_info)) {
447
+ $return[$theme_tmp] = $this->iwp_mmb_get_error($theme_info);
448
+ } else {
449
+ if(!empty($result[$theme_tmp]) || (isset($current->checked[$theme_tmp]) && version_compare(array_search($theme_tmp, $versions), $current->checked[$theme_tmp], '<') == true)){
450
+ $return[$theme_tmp] = 1;
451
+ } else {
452
+ update_option('iwp_client_forcerefresh', true);
453
+ $return[$theme_tmp] = 'Could not refresh upgrade transients, please reload website data';
454
+ }
455
+ }
456
+ }
457
+ return array(
458
+ 'upgraded' => $return
459
+ );
460
+ } else
461
+ return array(
462
+ 'error' => 'Upgrade failed.'
463
+ );
464
+ } else {
465
+ ob_end_clean();
466
+ return array(
467
+ 'error' => 'WordPress update required first'
468
+ );
469
+ }
470
+ }
471
+
472
+ function upgrade_premium($premium = false)
473
+ {
474
+ global $iwp_mmb_plugin_url;
475
+
476
+ if (!class_exists('WP_Upgrader'))
477
+ include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
478
+
479
+ if (!$premium || empty($premium))
480
+ return array(
481
+ 'error' => 'No premium files for upgrade.'
482
+ );
483
+
484
+ $upgrader = false;
485
+ $pr_update = array();
486
+ $result = array();
487
+ $premium_update = array();
488
+ $premium_update = apply_filters('iwp_premium_perform_update', $premium_update);
489
+
490
+ if (!empty($premium_update)) {
491
+ foreach ($premium as $pr) {
492
+ foreach ($premium_update as $update) {
493
+ $update = array_change_key_case($update, CASE_LOWER);
494
+
495
+ if ($update['name'] == $pr['name']) {
496
+ $update_result = false;
497
+ if (isset($update['url'])) {
498
+ if (defined('WP_INSTALLING') && file_exists(ABSPATH . '.maintenance'))
499
+ $pr_update[$update['type'] . 's']['upgraded'][md5($update['name'])] = 'Site under maintanace.';
500
+
501
+ if ($upgrader == false) {
502
+ $upgrader_skin = new WP_Upgrader_Skin();
503
+ $upgrader_skin->done_header = true;
504
+
505
+ $upgrader = new WP_Upgrader();
506
+ }
507
+
508
+ @$update_result = $upgrader->run(array(
509
+ 'package' => $update['url'],
510
+ 'destination' => isset($update['type']) && $update['type'] == 'theme' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR,
511
+ 'clear_destination' => true,
512
+ 'clear_working' => true,
513
+ 'hook_extra' => array()
514
+ ));
515
+ $update_result = !$update_result || is_wp_error($update_result) ? $this->iwp_mmb_get_error($update_result) : 1;
516
+
517
+ } else if (isset($update['callback'])) {
518
+ if (is_array($update['callback'])) {
519
+ $update_result = call_user_func(array(
520
+ $update['callback'][0],
521
+ $update['callback'][1]
522
+ ));
523
+ } else if (is_string($update['callback'])) {
524
+ $update_result = call_user_func($update['callback']);
525
+ } else {
526
+ $update_result = 'Upgrade function "' . $update['callback'] . '" does not exists.';
527
+ }
528
+
529
+ $update_result = $update_result !== true ? $this->iwp_mmb_get_error($update_result) : 1;
530
+ } else
531
+ $update_result = 'Bad update params.';
532
+
533
+ $pr_update[$update['type'] . 's']['upgraded'][md5($update['name'])] = $update_result;
534
+ }
535
+ }
536
+ }
537
+ return $pr_update;
538
+ } else {
539
+ foreach ($premium as $pr) {
540
+ $result[$pr['type'] . 's']['upgraded'][md5($pr['name'])] = 'This premium update is not registered.';
541
+ }
542
+ return $result;
543
+ }
544
+ }
545
+
546
+ function get_upgradable_plugins()
547
+ {
548
+ $current = $this->iwp_mmb_get_transient('update_plugins');
549
+
550
+ $upgradable_plugins = array();
551
+ if (!empty($current->response)) {
552
+ if (!function_exists('get_plugin_data'))
553
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
554
+ foreach ($current->response as $plugin_path => $plugin_data) {
555
+ if ($plugin_path == 'iwp-client/init.php')
556
+ continue;
557
+
558
+ $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path);
559
+ if (strlen($data['Name']) > 0 && strlen($data['Version']) > 0) {
560
+ $current->response[$plugin_path]->name = $data['Name'];
561
+ $current->response[$plugin_path]->old_version = $data['Version'];
562
+ $current->response[$plugin_path]->file = $plugin_path;
563
+ unset($current->response[$plugin_path]->upgrade_notice);
564
+ $upgradable_plugins[] = $current->response[$plugin_path];
565
+ }
566
+ }
567
+ return $upgradable_plugins;
568
+ } else
569
+ return array();
570
+ }
571
+
572
+ function get_upgradable_themes()
573
+ {
574
+ $all_themes = get_themes();
575
+ $upgrade_themes = array();
576
+
577
+ $current = $this->iwp_mmb_get_transient('update_themes');
578
+ if (!empty($current->response)) {
579
+ foreach ((array) $all_themes as $theme_template => $theme_data) {
580
+ if(isset($theme_data['Parent Theme']) && !empty($theme_data['Parent Theme']))
581
+ continue;
582
+
583
+ foreach ($current->response as $current_themes => $theme) {
584
+ if ($theme_data['Template'] == $current_themes) {
585
+ if (strlen($theme_data['Name']) > 0 && strlen($theme_data['Version']) > 0) {
586
+ $current->response[$current_themes]['name'] = $theme_data['Name'];
587
+ $current->response[$current_themes]['old_version'] = $theme_data['Version'];
588
+ $current->response[$current_themes]['theme_tmp'] = $theme_data['Template'];
589
+ $upgrade_themes[] = $current->response[$current_themes];
590
+ }
591
+ }
592
+ }
593
+ }
594
+ }
595
+
596
+ return $upgrade_themes;
597
+ }
598
+
599
+ function get($args)
600
+ {
601
+ if (empty($args))
602
+ return false;
603
+
604
+ //Args: $items('plugins,'themes'), $type (active || inactive), $search(name string)
605
+
606
+ $return = array();
607
+ if (is_array($args['items']) && in_array('plugins', $args['items'])) {
608
+ $return['plugins'] = $this->get_plugins($args);
609
+ }
610
+ if (is_array($args['items']) && in_array('themes', $args['items'])) {
611
+ $return['themes'] = $this->get_themes($args);
612
+ }
613
+
614
+ return $return;
615
+ }
616
+
617
+ function get_plugins($args)
618
+ {
619
+ if (empty($args))
620
+ return false;
621
+
622
+ extract($args);
623
+
624
+ if (!function_exists('get_plugins')) {
625
+ include_once(ABSPATH . 'wp-admin/includes/plugin.php');
626
+ }
627
+ $all_plugins = get_plugins();
628
+ $plugins = array(
629
+ 'active' => array(),
630
+ 'inactive' => array()
631
+ );
632
+ if (is_array($all_plugins) && !empty($all_plugins)) {
633
+ $activated_plugins = get_option('active_plugins');
634
+ if (!$activated_plugins)
635
+ $activated_plugins = array();
636
+
637
+ $br_a = 0;
638
+ $br_i = 0;
639
+ foreach ($all_plugins as $path => $plugin) {
640
+ if ($plugin['Name'] != 'InfiniteWP - Client') {
641
+ if (in_array($path, $activated_plugins)) {
642
+ $plugins['active'][$br_a]['path'] = $path;
643
+ $plugins['active'][$br_a]['name'] = $plugin['Name'];
644
+ $br_a++;
645
+ }
646
+
647
+ if (!in_array($path, $activated_plugins)) {
648
+ $plugins['inactive'][$br_i]['path'] = $path;
649
+ $plugins['inactive'][$br_i]['name'] = $plugin['Name'];
650
+ $br_i++;
651
+ }
652
+
653
+ }
654
+ /***************** Displaying all plugins so Not using serach function - Commented by IWP ******************/
655
+ /*if ($search) {
656
+ foreach ($plugins['active'] as $k => $plugin) {
657
+ if (!stristr($plugin['name'], $search)) {
658
+ unset($plugins['active'][$k]);
659
+ }
660
+ }
661
+
662
+ foreach ($plugins['inactive'] as $k => $plugin) {
663
+ if (!stristr($plugin['name'], $search)) {
664
+ unset($plugins['inactive'][$k]);
665
+ }
666
+ }
667
+ }*/
668
+ }
669
+ }
670
+
671
+ return $plugins;
672
+ }
673
+
674
+ function get_themes($args)
675
+ {
676
+ if (empty($args))
677
+ return false;
678
+
679
+ extract($args);
680
+
681
+ if (!function_exists('get_themes')) {
682
+ include_once(ABSPATH . WPINC . '/theme.php');
683
+ }
684
+ $all_themes = get_themes();
685
+ $themes = array(
686
+ 'active' => array(),
687
+ 'inactive' => array()
688
+ );
689
+
690
+ if (is_array($all_themes) && !empty($all_themes)) {
691
+ $current_theme = get_current_theme();
692
+
693
+ $br_a = 0;
694
+ $br_i = 0;
695
+ foreach ($all_themes as $theme_name => $theme) {
696
+ if ($current_theme == $theme_name) {
697
+ $themes['active'][$br_a]['path'] = $theme['Template'];
698
+ $themes['active'][$br_a]['name'] = $theme['Name'];
699
+ $themes['active'][$br_a]['stylesheet'] = $theme['Stylesheet'];
700
+ $br_a++;
701
+ }
702
+
703
+ if ($current_theme != $theme_name) {
704
+ $themes['inactive'][$br_i]['path'] = $theme['Template'];
705
+ $themes['inactive'][$br_i]['name'] = $theme['Name'];
706
+ $themes['inactive'][$br_i]['stylesheet'] = $theme['Stylesheet'];
707
+ $br_i++;
708
+ }
709
+
710
+ }
711
+
712
+ if ($search) {
713
+ foreach ($themes['active'] as $k => $theme) {
714
+ if (!stristr($theme['name'], $search)) {
715
+ unset($themes['active'][$k]);
716
+ }
717
+ }
718
+
719
+ foreach ($themes['inactive'] as $k => $theme) {
720
+ if (!stristr($theme['name'], $search)) {
721
+ unset($themes['inactive'][$k]);
722
+ }
723
+ }
724
+ }
725
+ }
726
+
727
+ return $themes;
728
+ }
729
+
730
+ function edit($args)
731
+ {
732
+ extract($args);
733
+ $return = array();
734
+ if ($type == 'plugins') {
735
+ $return['plugins'] = $this->edit_plugins($args);
736
+ } elseif ($type == 'themes') {
737
+ $return['themes'] = $this->edit_themes($args);
738
+ }
739
+ return $return;
740
+ }
741
+
742
+ function edit_plugins($args)
743
+ {
744
+ extract($args);
745
+ $return = array();
746
+ foreach ($items as $item) {
747
+ switch ($item['action']) {//switch ($items_edit_action) => switch ($item['action'])
748
+ case 'activate':
749
+ $result = activate_plugin($item['path']);
750
+ break;
751
+ case 'deactivate':
752
+ $result = deactivate_plugins(array(
753
+ $item['path']
754
+ ));
755
+ break;
756
+ case 'delete':
757
+ $result = delete_plugins(array(
758
+ $item['path']
759
+ ));
760
+ break;
761
+ default:
762
+ break;
763
+ }
764
+
765
+ if (is_wp_error($result)) {
766
+ $result = array(
767
+ 'error' => $result->get_error_message()
768
+ );
769
+ } elseif ($result === false) {
770
+ $result = array(
771
+ 'error' => "Failed to perform action."
772
+ );
773
+ } else {
774
+ $result = "OK";
775
+ }
776
+ $return[$item['name']] = $result;
777
+ }
778
+
779
+ return $return;
780
+ }
781
+
782
+ function edit_themes($args)
783
+ {
784
+ extract($args);
785
+ $return = array();
786
+ foreach ($items as $item) {
787
+ switch ($item['action']) {//switch ($items_edit_action) => switch ($item['action'])
788
+ case 'activate':
789
+ switch_theme($item['path'], $item['stylesheet']);
790
+ break;
791
+ case 'delete':
792
+ $result = delete_theme($item['path']);
793
+ break;
794
+ default:
795
+ break;
796
+ }
797
+
798
+ if (is_wp_error($result)) {
799
+ $result = array(
800
+ 'error' => $result->get_error_message()
801
+ );
802
+ } elseif ($result === false) {
803
+ $result = array(
804
+ 'error' => "Failed to perform action."
805
+ );
806
+ } else {
807
+ $result = "OK";
808
+ }
809
+ $return[$item['name']] = $result;
810
+ }
811
+
812
+ return $return;
813
+
814
+ }
815
+ }
816
+ ?>
plugins/cleanup/cleanup.php ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /************************************************************
3
+ * This plugin was modified by Revmakx *
4
+ * Copyright (c) 2012 Revmakx *
5
+ * www.revmakx.com *
6
+ * *
7
+ ************************************************************/
8
+ /*************************************************************
9
+ *
10
+ *
11
+ *
12
+ * InfiniteWP Client Plugin
13
+ *
14
+ *
15
+ * Copyright (c) 2011 Prelovac Media
16
+ * www.prelovac.com
17
+ **************************************************************/
18
+
19
+ add_filter('iwp_mmb_stats_filter', 'iwp_mmb_get_extended_info');
20
+
21
+
22
+ function iwp_mmb_get_extended_info($stats)
23
+ {
24
+ $stats['num_revisions'] = iwp_mmb_num_revisions();
25
+ //$stats['num_revisions'] = 5;
26
+ $stats['overhead'] = iwp_mmb_handle_overhead(false);
27
+ $stats['num_spam_comments'] = iwp_mmb_num_spam_comments();
28
+ return $stats;
29
+ }
30
+
31
+ /* Revisions */
32
+
33
+ iwp_mmb_add_action('cleanup_delete', 'iwp_mmb_cleanup_delete_client');
34
+
35
+ function iwp_mmb_cleanup_delete_client($params = array())
36
+ {
37
+ global $iwp_mmb_core;
38
+
39
+ $params_array = explode('_', $params['actions']);
40
+ $return_array = array();
41
+ foreach ($params_array as $param) {
42
+ switch ($param) {
43
+ case 'revision':
44
+ if (iwp_mmb_delete_all_revisions()) {
45
+ $return_array['revision'] = 'OK';
46
+ } else {
47
+ $return_array['revision_error'] = 'Failed, please try again';
48
+ }
49
+ break;
50
+ case 'overhead':
51
+ if (iwp_mmb_handle_overhead(true)) {
52
+ $return_array['overhead'] = 'OK';
53
+ } else {
54
+ $return_array['overhead_error'] = 'Failed, please try again';
55
+ }
56
+ break;
57
+ case 'comment':
58
+ if (iwp_mmb_delete_spam_comments()) {
59
+ $return_array['comment'] = 'OK';
60
+ } else {
61
+ $return_array['comment_error'] = 'Failed, please try again';
62
+ }
63
+ break;
64
+ default:
65
+ break;
66
+ }
67
+
68
+ }
69
+
70
+ unset($params);
71
+
72
+ iwp_mmb_response($return_array, true);
73
+ }
74
+
75
+ function iwp_mmb_num_revisions()
76
+ {
77
+ global $wpdb;
78
+ $sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'revision'";
79
+ $num_revisions = $wpdb->get_var($wpdb->prepare($sql));
80
+ return $num_revisions;
81
+ }
82
+
83
+ function iwp_mmb_select_all_revisions()
84
+ {
85
+ global $wpdb;
86
+ $sql = "SELECT * FROM $wpdb->posts WHERE post_type = 'revision'";
87
+ $revisions = $wpdb->get_results($wpdb->prepare($sql));
88
+ return $revisions;
89
+ }
90
+
91
+ function iwp_mmb_delete_all_revisions()
92
+ {
93
+ global $wpdb;
94
+ $sql = "DELETE a,b,c FROM $wpdb->posts a LEFT JOIN $wpdb->term_relationships b ON (a.ID = b.object_id) LEFT JOIN $wpdb->postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision'";
95
+ $revisions = $wpdb->query($wpdb->prepare($sql));
96
+
97
+ return $revisions;
98
+ }
99
+
100
+
101
+
102
+
103
+
104
+ /* Optimize */
105
+
106
+ function iwp_mmb_handle_overhead($clear = false)
107
+ {
108
+ global $wpdb, $iwp_mmb_core;
109
+ $tot_data = 0;
110
+ $tot_idx = 0;
111
+ $tot_all = 0;
112
+ $query = 'SHOW TABLE STATUS FROM ' . DB_NAME;
113
+ $tables = $wpdb->get_results($wpdb->prepare($query), ARRAY_A);
114
+ $total_gain = 0;
115
+ $table_string = '';
116
+ foreach ($tables as $table) {
117
+ if (in_array($table['Engine'], array(
118
+ 'MyISAM',
119
+ 'ISAM',
120
+ 'HEAP',
121
+ 'MEMORY',
122
+ 'ARCHIVE'
123
+ ))) {
124
+ if ($wpdb->base_prefix != $wpdb->prefix) {
125
+ if (preg_match('/^' . $wpdb->prefix . '*/Ui', $table['Name'])) {
126
+ if ($table['Data_free'] > 0) {
127
+ $total_gain += $table['Data_free'] / 1024;
128
+ $table_string .= $table['Name'] . ",";
129
+ }
130
+ }
131
+ } else if (preg_match('/^' . $wpdb->prefix . '[0-9]{1,20}_*/Ui', $table['Name'])) {
132
+ continue;
133
+ } else {
134
+ if ($table['Data_free'] > 0) {
135
+ $total_gain += $table['Data_free'] / 1024;
136
+ $table_string .= $table['Name'] . ",";
137
+ }
138
+ }
139
+ } elseif ($table['Engine'] == 'InnoDB') {
140
+ //$total_gain += $table['Data_free'] > 100*1024*1024 ? $table['Data_free'] / 1024 : 0;
141
+ }
142
+ }
143
+
144
+ if ($clear) {
145
+ $table_string = substr($table_string, 0, strlen($table_string) - 1); //remove last ,
146
+
147
+ $table_string = rtrim($table_string);
148
+
149
+ $query = "OPTIMIZE TABLE $table_string";
150
+
151
+ $optimize = $wpdb->query($query);
152
+
153
+ return $optimize === FALSE ? false : true;
154
+ } else
155
+ return round($total_gain, 3);
156
+ }
157
+
158
+
159
+
160
+
161
+ /* Spam Comments */
162
+
163
+ function iwp_mmb_num_spam_comments()
164
+ {
165
+ global $wpdb;
166
+ $sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'";
167
+ $num_spams = $wpdb->get_var($wpdb->prepare($sql));
168
+ return $num_spams;
169
+ }
170
+
171
+ function iwp_mmb_delete_spam_comments()
172
+ {
173
+ global $wpdb;
174
+ $spams = 1;
175
+ $total = 0;
176
+ while ($spams) {
177
+ $sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam' LIMIT 200";
178
+ $spams = $wpdb->query($wpdb->prepare($sql));
179
+ $total += $spams;
180
+ if ($spams)
181
+ usleep(100000);
182
+ }
183
+ return $total;
184
+ }
185
+
186
+
187
+ function iwp_mmb_get_spam_comments()
188
+ {
189
+ global $wpdb;
190
+ $sql = "SELECT * FROM $wpdb->comments as a LEFT JOIN $wpdb->commentmeta as b WHERE a.comment_ID = b.comment_id AND a.comment_approved = 'spam'";
191
+ $spams = $wpdb->get_results($wpdb->prepare($sql));
192
+ return $spams;
193
+ }
194
+
195
+ ?>
plugins/extra_html_example/extra_html_example.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /************************************************************
3
+ * This plugin was modified by Revmakx *
4
+ * Copyright (c) 2012 Revmakx *
5
+ * www.revmakx.com *
6
+ * *
7
+ ************************************************************/
8
+
9
+ // add filter for the stats structure
10
+ add_filter('iwp_mmb_stats_filter', iwp_mmb_extra_html_example);
11
+
12
+ function iwp_mmb_extra_html_example($stats)
13
+ {
14
+ $count_posts = wp_count_posts();
15
+
16
+ $published_posts = $count_posts->publish;
17
+
18
+ // add 'extra_html' element. This is what gets displayed in the dashboard
19
+ $stats['extra_html'] = '<p>Hello from '.get_bloginfo('name').' with '.$published_posts.' published posts.</p>';
20
+
21
+ // return the whole array back
22
+ return $stats;
23
+ }
24
+ ?>
plugins/search/search.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /************************************************************
3
+ * This plugin was modified by Revmakx *
4
+ * Copyright (c) 2012 Revmakx *
5
+ * www.revmakx.com *
6
+ * *
7
+ ************************************************************/
8
+ /*************************************************************
9
+ *
10
+ * stats.class.php
11
+ *
12
+ * Various searches on client
13
+ *
14
+ *
15
+ * Copyright (c) 2011 Prelovac Media
16
+ * www.prelovac.com
17
+ **************************************************************/
18
+
19
+ iwp_mmb_add_action('iwp_mmb_search_posts_by_term', 'iwp_mmb_search_posts_by_term');
20
+
21
+ function iwp_mmb_search_posts_by_term($params = false){
22
+
23
+ global $wpdb, $current_user;
24
+
25
+ $search_type = trim($params['search_type']);
26
+ $search_term = strtolower(trim($params['search_term']));
27
+ switch ($search_type){
28
+ case 'plugin':
29
+ $plugins = get_option('active_plugins');
30
+
31
+ if(!function_exists('get_plugin_data'))
32
+ include_once( ABSPATH.'/wp-admin/includes/plugin.php');
33
+
34
+ $have_plugin = array();
35
+ foreach ($plugins as $plugin) {
36
+ $pl = WP_PLUGIN_DIR . '/' . $plugin ;
37
+ $pl_extended = get_plugin_data($pl);
38
+ $pl_name = $pl_extended['Name'];
39
+ if(strpos(strtolower($pl_name), $search_term)>-1){
40
+
41
+ $have_plugin[] = $pl_name;
42
+ }
43
+ }
44
+ if($have_plugin){
45
+ iwp_mmb_response($have_plugin, true);
46
+ }else{
47
+ iwp_mmb_response('Not found', false);
48
+ }
49
+ break;
50
+ case 'theme':
51
+ $theme = strtolower(get_option('stylesheet'));
52
+ $tm = ABSPATH . 'wp-content/themes/'. $theme . '/style.css' ;
53
+ $tm_extended = get_theme_data($tm);
54
+ $tm_name = $tm_extended['Name'];
55
+ $have_theme = array();
56
+ if(strpos(strtolower($tm_name), $search_term)>-1){
57
+ $have_theme[] = $tm_name;
58
+ iwp_mmb_response($have_theme, true);
59
+ }else{
60
+ iwp_mmb_response('Not found', false);
61
+ }
62
+ break;
63
+ default: iwp_mmb_response('Not found', false);
64
+ }
65
+ }
66
+
67
+ ?>
stats.class.php ADDED
@@ -0,0 +1,768 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /************************************************************
3
+ * This plugin was modified by Revmakx *
4
+ * Copyright (c) 2012 Revmakx *
5
+ * www.revmakx.com *
6
+ * *
7
+ ************************************************************/
8
+ /*************************************************************
9
+ *
10
+ * stats.class.php
11
+ *
12
+ * Get Site Stats
13
+ *
14
+ *
15
+ * Copyright (c) 2011 Prelovac Media
16
+ * www.prelovac.com
17
+ **************************************************************/
18
+
19
+
20
+ class IWP_MMB_Stats extends IWP_MMB_Core
21
+ {
22
+ function __construct()
23
+ {
24
+ parent::__construct();
25
+ }
26
+
27
+ /*************************************************************
28
+ * FACADE functions
29
+ * (functions to be called after a remote call from IWP Admin panel)
30
+ **************************************************************/
31
+
32
+ function get_core_update($stats, $options = array())
33
+ {
34
+ global $wp_version;
35
+
36
+ if (isset($options['core']) && $options['core']) {
37
+ $core = $this->iwp_mmb_get_transient('update_core');
38
+ if (isset($core->updates) && !empty($core->updates)) {
39
+ $current_transient = $core->updates[0];
40
+ if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) {
41
+ $current_transient->current_version = $wp_version;
42
+ $stats['core_updates'] = $current_transient;
43
+ } else
44
+ $stats['core_updates'] = false;
45
+ } else
46
+ $stats['core_updates'] = false;
47
+ }
48
+
49
+ return $stats;
50
+ }
51
+
52
+ function get_hit_counter($stats, $options = array())
53
+ {
54
+ $iwp_mmb_user_hits = get_option('iwp_client_user_hit_count');
55
+ if (is_array($iwp_mmb_user_hits)) {
56
+ end($iwp_mmb_user_hits);
57
+ $last_key_date = key($iwp_mmb_user_hits);
58
+ $current_date = date('Y-m-d');
59
+ if ($last_key_date != $current_date)
60
+ $this->set_hit_count(true);
61
+ }
62
+ $stats['hit_counter'] = get_option('iwp_client_user_hit_count');
63
+
64
+ return $stats;
65
+ }
66
+
67
+ function get_comments($stats, $options = array())
68
+ {
69
+ $nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20;
70
+ $trimlen = isset($options['trimcontent']) ? (int) $options['trimcontent'] : 200;
71
+
72
+ if ($nposts) {
73
+ $comments = get_comments('status=hold&number=' . $nposts);
74
+ if (!empty($comments)) {
75
+ foreach ($comments as &$comment) {
76
+ $commented_post = get_post($comment->comment_post_ID);
77
+ $comment->post_title = $commented_post->post_title;
78
+ $comment->comment_content = $this->trim_content($comment->comment_content, $trimlen);
79
+ unset($comment->comment_author_url);
80
+ unset($comment->comment_author_email);
81
+ unset($comment->comment_author_IP);
82
+ unset($comment->comment_date_gmt);
83
+ unset($comment->comment_karma);
84
+ unset($comment->comment_agent);
85
+ unset($comment->comment_type);
86
+ unset($comment->comment_parent);
87
+ unset($comment->user_id);
88
+ }
89
+ $stats['comments']['pending'] = $comments;
90
+ }
91
+
92
+ $comments = get_comments('status=approve&number=' . $nposts);
93
+ if (!empty($comments)) {
94
+ foreach ($comments as &$comment) {
95
+ $commented_post = get_post($comment->comment_post_ID);
96
+ $comment->post_title = $commented_post->post_title;
97
+ $comment->comment_content = $this->trim_content($comment->comment_content, $trimlen);
98
+ unset($comment->comment_author_url);
99
+ unset($comment->comment_author_email);
100
+ unset($comment->comment_author_IP);
101
+ unset($comment->comment_date_gmt);
102
+ unset($comment->comment_karma);
103
+ unset($comment->comment_agent);
104
+ unset($comment->comment_type);
105
+ unset($comment->comment_parent);
106
+ unset($comment->user_id);
107
+ }
108
+ $stats['comments']['approved'] = $comments;
109
+ }
110
+ }
111
+ return $stats;
112
+ }
113
+
114
+ function get_posts($stats, $options = array())
115
+ {
116
+ $nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20;
117
+
118
+ if ($nposts) {
119
+ $posts = get_posts('post_status=publish&numberposts=' . $nposts . '&orderby=post_date&order=desc');
120
+ $recent_posts = array();
121
+ if (!empty($posts)) {
122
+ foreach ($posts as $id => $recent_post) {
123
+ $recent = new stdClass();
124
+ $recent->post_permalink = get_permalink($recent_post->ID);
125
+ $recent->ID = $recent_post->ID;
126
+ $recent->post_date = $recent_post->post_date;
127
+ $recent->post_title = $recent_post->post_title;
128
+ $recent->comment_count = (int) $recent_post->comment_count;
129
+ $recent_posts[] = $recent;
130
+ }
131
+ }
132
+
133
+ $posts = get_pages('post_status=publish&numberposts=' . $nposts . '&orderby=post_date&order=desc');
134
+ $recent_pages_published = array();
135
+ if (!empty($posts)) {
136
+ foreach ((array) $posts as $id => $recent_page_published) {
137
+ $recent = new stdClass();
138
+ $recent->post_permalink = get_permalink($recent_page_published->ID);
139
+
140
+ $recent->ID = $recent_page_published->ID;
141
+ $recent->post_date = $recent_page_published->post_date;
142
+ $recent->post_title = $recent_page_published->post_title;
143
+
144
+ $recent_posts[] = $recent;
145
+ }
146
+ }
147
+ if (!empty($recent_posts)) {
148
+ usort($recent_posts, array(
149
+ $this,
150
+ 'cmp_posts_client'
151
+ ));
152
+ $stats['posts'] = array_slice($recent_posts, 0, $nposts);
153
+ }
154
+ }
155
+ return $stats;
156
+ }
157
+
158
+ function get_drafts($stats, $options = array())
159
+ {
160
+ $nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20;
161
+
162
+ if ($nposts) {
163
+ $drafts = get_posts('post_status=draft&numberposts=' . $nposts . '&orderby=post_date&order=desc');
164
+ $recent_drafts = array();
165
+ if (!empty($drafts)) {
166
+ foreach ($drafts as $id => $recent_draft) {
167
+ $recent = new stdClass();
168
+ $recent->post_permalink = get_permalink($recent_draft->ID);
169
+ $recent->ID = $recent_draft->ID;
170
+ $recent->post_date = $recent_draft->post_date;
171
+ $recent->post_title = $recent_draft->post_title;
172
+
173
+ $recent_drafts[] = $recent;
174
+ }
175
+ }
176
+ $drafts = get_pages('post_status=draft&numberposts=' . $nposts . '&orderby=post_date&order=desc');
177
+ $recent_pages_drafts = array();
178
+ if (!empty($drafts)) {
179
+ foreach ((array) $drafts as $id => $recent_pages_draft) {
180
+ $recent = new stdClass();
181
+ $recent->post_permalink = get_permalink($recent_pages_draft->ID);
182
+ $recent->ID = $recent_pages_draft->ID;
183
+ $recent->post_date = $recent_pages_draft->post_date;
184
+ $recent->post_title = $recent_pages_draft->post_title;
185
+
186
+ $recent_drafts[] = $recent;
187
+ }
188
+ }
189
+ if (!empty($recent_drafts)) {
190
+ usort($recent_drafts, array(
191
+ $this,
192
+ 'cmp_posts_client'
193
+ ));
194
+ $stats['drafts'] = array_slice($recent_drafts, 0, $nposts);
195
+ }
196
+ }
197
+ return $stats;
198
+ }
199
+
200
+ function get_scheduled($stats, $options = array())
201
+ {
202
+ $nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20;
203
+
204
+ if ($nposts) {
205
+ $scheduled = get_posts('post_status=future&numberposts=' . $nposts . '&orderby=post_date&order=desc');
206
+ $scheduled_posts = array();
207
+ if (!empty($scheduled)) {
208
+ foreach ($scheduled as $id => $scheduled) {
209
+ $recent = new stdClass();
210
+ $recent->post_permalink = get_permalink($scheduled->ID);
211
+ $recent->ID = $scheduled->ID;
212
+ $recent->post_date = $scheduled->post_date;
213
+ $recent->post_title = $scheduled->post_title;
214
+ $scheduled_posts[] = $recent;
215
+ }
216
+ }
217
+ $scheduled = get_pages('post_status=future&numberposts=' . $nposts . '&orderby=post_date&order=desc');
218
+ $recent_pages_drafts = array();
219
+ if (!empty($scheduled)) {
220
+ foreach ((array) $scheduled as $id => $scheduled) {
221
+ $recent = new stdClass();
222
+ $recent->post_permalink = get_permalink($scheduled->ID);
223
+ $recent->ID = $scheduled->ID;
224
+ $recent->post_date = $scheduled->post_date;
225
+ $recent->post_title = $scheduled->post_title;
226
+
227
+ $scheduled_posts[] = $recent;
228
+ }
229
+ }
230
+ if (!empty($scheduled_posts)) {
231
+ usort($scheduled_posts, array(
232
+ $this,
233
+ 'cmp_posts_client'
234
+ ));
235
+ $stats['scheduled'] = array_slice($scheduled_posts, 0, $nposts);
236
+ }
237
+ }
238
+ return $stats;
239
+ }
240
+
241
+ function get_backups($stats, $options = array())
242
+ {
243
+ $stats['iwp_backups'] = $this->get_backup_instance()->get_backup_stats();
244
+ /*
245
+ //IWP Remove starts here
246
+ $stats['iwp_next_backups'] = $this->get_backup_instance()->get_next_schedules();
247
+ //IWP Remove ends here
248
+ */
249
+
250
+ return $stats;
251
+ }
252
+
253
+ function get_backup_req($stats = array(), $options = array())
254
+ {
255
+ $stats['iwp_backups'] = $this->get_backup_instance()->get_backup_stats();
256
+ $stats['iwp_next_backups'] = $this->get_backup_instance()->get_next_schedules();
257
+ $stats['iwp_backup_req'] = $this->get_backup_instance()->check_backup_compat();
258
+
259
+ return $stats;
260
+ }
261
+
262
+ function get_updates($stats, $options = array())
263
+ {
264
+ $upgrades = false;
265
+
266
+ if (isset($options['premium']) && $options['premium']) {
267
+ $premium_updates = array();
268
+ $upgrades = apply_filters('iwp_premium_update_notification', $premium_updates);
269
+ if (!empty($upgrades)) {
270
+ $stats['premium_updates'] = $upgrades;
271
+ $upgrades = false;
272
+ }
273
+ }
274
+ if (isset($options['themes']) && $options['themes']) {
275
+ $this->get_installer_instance();
276
+ $upgrades = $this->installer_instance->get_upgradable_themes();
277
+ if (!empty($upgrades)) {
278
+ $stats['upgradable_themes'] = $upgrades;
279
+ $upgrades = false;
280
+ }
281
+ }
282
+
283
+ if (isset($options['plugins']) && $options['plugins']) {
284
+ $this->get_installer_instance();
285
+ $upgrades = $this->installer_instance->get_upgradable_plugins();
286
+ if (!empty($upgrades)) {
287
+ $stats['upgradable_plugins'] = $upgrades;
288
+ $upgrades = false;
289
+ }
290
+ }
291
+
292
+ return $stats;
293
+ }
294
+
295
+ function get_errors($stats, $options = array())
296
+ {
297
+ $period = isset($options['days']) ? (int) $options['days'] * 86400 : 86400;
298
+ $maxerrors = isset($options['max']) ? (int) $options['max'] : 20;
299
+ $errors = array();
300
+ if (isset($options['get']) && $options['get'] == true) {
301
+ if (function_exists('ini_get')) {
302
+ $logpath = ini_get('error_log');
303
+ if (!empty($logpath) && file_exists($logpath)) {
304
+ $logfile = @fopen($logpath, 'r');
305
+ if ($logfile && filesize($logpath) > 0) {
306
+ $maxlines = 1;
307
+ $linesize = -4096;
308
+ $lines = array();
309
+ $line = true;
310
+ while ($line !== false) {
311
+ if( fseek($logfile, ($maxlines * $linesize), SEEK_END) !== -1){
312
+ $maxlines++;
313
+ if ($line) {
314
+ $line = fread($logfile, ($linesize * -1)) . $line;
315
+
316
+ foreach ((array) preg_split("/(\r|\n|\r\n)/U", $line) as $l) {
317
+ preg_match('/\[(.*)\]/Ui', $l, $match);
318
+ if (!empty($match)) {
319
+ $key = str_replace($match[0], '', $l);
320
+ if(!isset($errors[$key])){
321
+ $errors[$key] = 1;
322
+ } else {
323
+ $errors[$key] = $errors[$key] + 1;
324
+ }
325
+
326
+ if ((strtotime($match[1]) < ((int) time() - $period)) || count($errors) >= $maxerrors) {
327
+ $line = false;
328
+ break;
329
+ }
330
+ }
331
+ }
332
+ }
333
+ } else
334
+ break;
335
+ }
336
+ }
337
+ if (!empty($errors)){
338
+ $stats['errors'] = $errors;
339
+ $stats['logpath'] = $logpath;
340
+ $stats['logsize'] = @filesize($logpath);
341
+ }
342
+ }
343
+ }
344
+ }
345
+
346
+ return $stats;
347
+ }
348
+
349
+ function pre_init_stats($params)
350
+ {
351
+ global $_iwp_mmb_item_filter;
352
+
353
+ include_once(ABSPATH . 'wp-includes/update.php');
354
+ include_once(ABSPATH . '/wp-admin/includes/update.php');
355
+
356
+ $stats = $this->iwp_mmb_parse_action_params('pre_init_stats', $params, $this);
357
+ $num = extract($params);
358
+
359
+ if ($refresh == 'transient') {
360
+ $current = $this->iwp_mmb_get_transient('update_core');
361
+ if (isset($current->last_checked) || get_option('iwp_client_forcerefresh')) {
362
+ update_option('iwp_client_forcerefresh', false);
363
+ if (time() - $current->last_checked > 14400) {
364
+ @wp_version_check();
365
+ @wp_update_plugins();
366
+ @wp_update_themes();
367
+ }
368
+ }
369
+ }
370
+
371
+ global $wpdb, $iwp_mmb_wp_version, $iwp_mmb_plugin_dir, $wp_version, $wp_local_package;
372
+
373
+ $stats['client_version'] = IWP_MMB_CLIENT_VERSION;
374
+ $stats['wordpress_version'] = $wp_version;
375
+ $stats['wordpress_locale_pckg'] = $wp_local_package;
376
+ $stats['php_version'] = phpversion();
377
+ $stats['mysql_version'] = $wpdb->db_version();
378
+ $stats['wp_multisite'] = $this->iwp_mmb_multisite;
379
+ $stats['network_install'] = $this->network_admin_install;
380
+
381
+ if ( !function_exists('get_filesystem_method') )
382
+ include_once(ABSPATH . 'wp-admin/includes/file.php');
383
+ $mmode = get_option('iwp_client_maintenace_mode');
384
+
385
+ if( !empty($mmode) && isset($mmode['active']) && $mmode['active'] == true){
386
+ $stats['maintenance'] = true;
387
+ }
388
+ $stats['writable'] = $this->is_server_writable();
389
+
390
+ return $stats;
391
+ }
392
+
393
+ function get($params)
394
+ {
395
+ global $wpdb, $iwp_mmb_wp_version, $iwp_mmb_plugin_dir, $_iwp_mmb_item_filter;
396
+
397
+ include_once(ABSPATH . 'wp-includes/update.php');
398
+ include_once(ABSPATH . '/wp-admin/includes/update.php');
399
+
400
+ $stats = $this->iwp_mmb_parse_action_params('get', $params, $this);
401
+ $update_check = array();
402
+ $num = extract($params);
403
+ if ($refresh == 'transient') {
404
+ $update_check = apply_filters('iwp_premium_update_check', $update_check);
405
+ if (!empty($update_check)) {
406
+ foreach ($update_check as $update) {
407
+ if (is_array($update['callback'])) {
408
+ $update_result = call_user_func(array(
409
+ $update['callback'][0],
410
+ $update['callback'][1]
411
+ ));
412
+ } else if (is_string($update['callback'])) {
413
+ $update_result = call_user_func($update['callback']);
414
+ }
415
+ }
416
+ }
417
+ }
418
+
419
+ if ($this->iwp_mmb_multisite) {
420
+ $stats = $this->get_multisite($stats);
421
+ }
422
+
423
+ $stats = apply_filters('iwp_mmb_stats_filter', $stats);
424
+ return $stats;
425
+ }
426
+
427
+ function get_multisite($stats = array())
428
+ {
429
+ global $current_user, $wpdb;
430
+ $user_blogs = get_blogs_of_user( $current_user->ID );
431
+ $network_blogs = $wpdb->get_results( $wpdb->prepare("select `blog_id`, `site_id` from `{$wpdb->blogs}`") );
432
+ if ($this->network_admin_install == '1' && is_super_admin()) {
433
+ if (!empty($network_blogs)) {
434
+ $blogs = array();
435
+ foreach ( $network_blogs as $details) {
436
+ if($details->site_id == $details->blog_id)
437
+ continue;
438
+ else {
439
+ $data = get_blog_details($details->blog_id);
440
+ if(in_array($details->blog_id, array_keys($user_blogs)))
441
+ $stats['network_blogs'][] = $data->siteurl;
442
+ else {
443
+ $user = get_users( array( 'blog_id' => $details->blog_id, 'number' => 1) );
444
+ if( !empty($user) )
445
+ $stats['other_blogs'][$data->siteurl] = $user[0]->user_login;
446
+ }
447
+ }
448
+ }
449
+ }
450
+ }
451
+ return $stats;
452
+ }
453
+
454
+ function get_comments_stats()
455
+ {
456
+ $num_pending_comments = 3;
457
+ $num_approved_comments = 3;
458
+ $pending_comments = get_comments('status=hold&number=' . $num_pending_comments);
459
+ foreach ($pending_comments as &$comment) {
460
+ $commented_post = get_post($comment->comment_post_ID);
461
+ $comment->post_title = $commented_post->post_title;
462
+ }
463
+ $stats['comments']['pending'] = $pending_comments;
464
+
465
+
466
+ $approved_comments = get_comments('status=approve&number=' . $num_approved_comments);
467
+ foreach ($approved_comments as &$comment) {
468
+ $commented_post = get_post($comment->comment_post_ID);
469
+ $comment->post_title = $commented_post->post_title;
470
+ }
471
+ $stats['comments']['approved'] = $approved_comments;
472
+
473
+ return $stats;
474
+ }
475
+
476
+ function get_initial_stats()
477
+ {
478
+ global $iwp_mmb_plugin_dir;
479
+
480
+ $stats = array();
481
+
482
+ $stats['email'] = get_option('admin_email');
483
+ $stats['no_openssl'] = $this->get_random_signature();
484
+ $stats['content_path'] = WP_CONTENT_DIR;
485
+ $stats['client_path'] = $iwp_mmb_plugin_dir;
486
+ $stats['client_version'] = IWP_MMB_CLIENT_VERSION;
487
+ $stats['site_title'] = get_bloginfo('name');
488
+ $stats['site_tagline'] = get_bloginfo('description');
489
+ $stats['site_home'] = get_option('home');
490
+ $stats['admin_url'] = admin_url();
491
+ $stats['wp_multisite'] = $this->iwp_mmb_multisite;
492
+ $stats['network_install'] = $this->network_admin_install;
493
+
494
+ if ($this->iwp_mmb_multisite) {
495
+ $details = get_blog_details($this->iwp_mmb_multisite);
496
+ if (isset($details->site_id)) {
497
+ $details = get_blog_details($details->site_id);
498
+ if (isset($details->siteurl))
499
+ $stats['network_parent'] = $details->siteurl;
500
+ }
501
+ }
502
+ if (!function_exists('get_filesystem_method'))
503
+ include_once(ABSPATH . 'wp-admin/includes/file.php');
504
+
505
+ $stats['writable'] = $this->is_server_writable();
506
+
507
+ return $stats;
508
+ }
509
+
510
+ function set_hit_count($fix_count = false)
511
+ {
512
+ if ($fix_count || (!is_admin() && !IWP_MMB_Stats::is_bot())) {
513
+ $date = date('Y-m-d');
514
+ $iwp_client_user_hit_count = (array) get_option('iwp_client_user_hit_count');
515
+ if (!$iwp_client_user_hit_count) {
516
+ $iwp_client_user_hit_count[$date] = 1;
517
+ update_option('iwp_client_user_hit_count', $iwp_client_user_hit_count);
518
+ } else {
519
+ $dated_keys = array_keys($iwp_client_user_hit_count);
520
+ $last_visit_date = $dated_keys[count($dated_keys) - 1];
521
+
522
+ $days = intval((strtotime($date) - strtotime($last_visit_date)) / 60 / 60 / 24);
523
+
524
+ if ($days > 1) {
525
+ $date_to_add = date('Y-m-d', strtotime($last_visit_date));
526
+
527
+ for ($i = 1; $i < $days; $i++) {
528
+ if (count($iwp_client_user_hit_count) > 14) {
529
+ $shifted = @array_shift($iwp_client_user_hit_count);
530
+ }
531
+
532
+ $next_key = strtotime('+1 day', strtotime($date_to_add));
533
+ if ($next_key == $date) {
534
+ break;
535
+ } else {
536
+ $iwp_client_user_hit_count[$next_key] = 0;
537
+ }
538
+ }
539
+
540
+ }
541
+
542
+ if (!isset($iwp_client_user_hit_count[$date])) {
543
+ $iwp_client_user_hit_count[$date] = 0;
544
+ }
545
+ if (!$fix_count)
546
+ $iwp_client_user_hit_count[$date] = ((int) $iwp_client_user_hit_count[$date]) + 1;
547
+
548
+ if (count($iwp_client_user_hit_count) > 14) {
549
+ $shifted = @array_shift($iwp_client_user_hit_count);
550
+ }
551
+
552
+ update_option('iwp_client_user_hit_count', $iwp_client_user_hit_count);
553
+
554
+ }
555
+ }
556
+ }
557
+
558
+ function get_hit_count()
559
+ {
560
+ // Check if there are no hits on last key date
561
+ $iwp_mmb_user_hits = get_option('iwp_client_user_hit_count');
562
+ if (is_array($iwp_mmb_user_hits)) {
563
+ end($iwp_mmb_user_hits);
564
+ $last_key_date = key($iwp_mmb_user_hits);
565
+ $current_date = date('Y-m-d');
566
+ if ($last_key_date != $curent_date)
567
+ $this->set_hit_count(true);
568
+ }
569
+
570
+ return get_option('iwp_client_user_hit_count');
571
+ }
572
+
573
+ function is_bot()
574
+ {
575
+ $agent = $_SERVER['HTTP_USER_AGENT'];
576
+
577
+ if ($agent == '')
578
+ return false;
579
+
580
+ $bot_list = array(
581
+ "Teoma",
582
+ "alexa",
583
+ "froogle",
584
+ "Gigabot",
585
+ "inktomi",
586
+ "looksmart",
587
+ "URL_Spider_SQL",
588
+ "Firefly",
589
+ "NationalDirectory",
590
+ "Ask Jeeves",
591
+ "TECNOSEEK",
592
+ "InfoSeek",
593
+ "WebFindBot",
594
+ "girafabot",
595
+ "crawler",
596
+ "www.galaxy.com",
597
+ "Googlebot",
598
+ "Scooter",
599
+ "Slurp",
600
+ "msnbot",
601
+ "appie",
602
+ "FAST",
603
+ "WebBug",
604
+ "Spade",
605
+ "ZyBorg",
606
+ "rabaz",
607
+ "Baiduspider",
608
+ "Feedfetcher-Google",
609
+ "TechnoratiSnoop",
610
+ "Rankivabot",
611
+ "Mediapartners-Google",
612
+ "Sogou web spider",
613
+ "WebAlta Crawler",
614
+ "aolserver"
615
+ );
616
+
617
+ foreach ($bot_list as $bot)
618
+ if (strpos($agent, $bot) !== false)
619
+ return true;
620
+
621
+ return false;
622
+ }
623
+
624
+
625
+ function set_notifications($params)
626
+ {
627
+ if (empty($params))
628
+ return false;
629
+
630
+ extract($params);
631
+
632
+ if (!isset($delete)) {
633
+ $iwp_client_notifications = array(
634
+ 'plugins' => $plugins,
635
+ 'themes' => $themes,
636
+ 'wp' => $wp,
637
+ 'backups' => $backups,
638
+ 'url' => $url,
639
+ 'notification_key' => $notification_key
640
+ );
641
+ update_option('iwp_client_notifications', $iwp_client_notifications);
642
+ } else {
643
+ delete_option('iwp_client_notifications');
644
+ }
645
+
646
+ return true;
647
+
648
+ }
649
+
650
+ //Cron update check for notifications
651
+ function check_notifications()
652
+ {
653
+ global $wpdb, $iwp_mmb_wp_version, $iwp_mmb_plugin_dir, $wp_version, $wp_local_package;
654
+
655
+ $iwp_client_notifications = get_option('iwp_client_notifications', true);
656
+
657
+ $args = array();
658
+ $updates = array();
659
+ $send = 0;
660
+ if (is_array($iwp_client_notifications) && $iwp_client_notifications != false) {
661
+ include_once(ABSPATH . 'wp-includes/update.php');
662
+ include_once(ABSPATH . '/wp-admin/includes/update.php');
663
+ extract($iwp_client_notifications);
664
+
665
+ //Check wordpress core updates
666
+ if ($wp) {
667
+ @wp_version_check();
668
+ if (function_exists('get_core_updates')) {
669
+ $wp_updates = get_core_updates();
670
+ if (!empty($wp_updates)) {
671
+ $current_transient = $wp_updates[0];
672
+ if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) {
673
+ $current_transient->current_version = $wp_version;
674
+ $updates['core_updates'] = $current_transient;
675
+ } else
676
+ $updates['core_updates'] = array();
677
+ } else
678
+ $updates['core_updates'] = array();
679
+ }
680
+ }
681
+
682
+ //Check plugin updates
683
+ if ($plugins) {
684
+ @wp_update_plugins();
685
+ $this->get_installer_instance();
686
+ $updates['upgradable_plugins'] = $this->installer_instance->get_upgradable_plugins();
687
+ }
688
+
689
+ //Check theme updates
690
+ if ($themes) {
691
+ @wp_update_themes();
692
+ $this->get_installer_instance();
693
+
694
+ $updates['upgradable_themes'] = $this->installer_instance->get_upgradable_themes();
695
+ }
696
+
697
+ if ($backups) {
698
+ $this->get_backup_instance();
699
+ $backups = $this->backup_instance->get_backup_stats();
700
+ $updates['backups'] = $backups;
701
+ foreach ($backups as $task_name => $backup_results) {
702
+ foreach ($backup_results as $k => $backup) {
703
+ if (isset($backups[$task_name][$k]['server']['file_path'])) {
704
+ unset($backups[$task_name][$k]['server']['file_path']);
705
+ }
706
+ }
707
+ }
708
+ $updates['backups'] = $backups;
709
+ }
710
+
711
+
712
+ if (!empty($updates)) {
713
+ $args['body']['updates'] = $updates;
714
+ $args['body']['notification_key'] = $notification_key;
715
+ $send = 1;
716
+ }
717
+
718
+ }
719
+
720
+
721
+ $alert_data = get_option('iwp_client_pageview_alerts',true);
722
+ if(is_array($alert_data) && $alert_data['alert']){
723
+ $pageviews = get_option('iwp_client_user_hit_count');
724
+ $args['body']['alerts']['pageviews'] = $pageviews;
725
+ $args['body']['alerts']['site_id'] = $alert_data['site_id'];
726
+ if(!isset($url)){
727
+ $url = $alert_data['url'];
728
+ }
729
+ $send = 1;
730
+ }
731
+
732
+ if($send){
733
+ if (!class_exists('WP_Http')) {
734
+ include_once(ABSPATH . WPINC . '/class-http.php');
735
+ }
736
+ $result = wp_remote_post($url, $args);
737
+
738
+ if (is_array($result) && $result['body'] == 'iwp_delete_alert') {
739
+ delete_option('iwp_client_pageview_alerts');
740
+ }
741
+ }
742
+
743
+
744
+ }
745
+
746
+
747
+ function cmp_posts_client($a, $b)
748
+ {
749
+ return ($a->post_date < $b->post_date);
750
+ }
751
+
752
+ function trim_content($content = '', $length = 200)
753
+ {
754
+ if (function_exists('mb_strlen') && function_exists('mb_substr'))
755
+ $content = (mb_strlen($content) > ($length + 3)) ? mb_substr($content, 0, $length) . '...' : $content;
756
+ else
757
+ $content = (strlen($content) > ($length + 3)) ? substr($content, 0, $length) . '...' : $content;
758
+
759
+ return $content;
760
+ }
761
+
762
+ function set_alerts($args){
763
+ extract($args);
764
+ update_option('iwp_client_pageview_alerts',array('site_id' => $site_id,'alert' => $alert,'url' => $url));
765
+ }
766
+
767
+ }
768
+ ?>