InfiniteWP Client - Version 1.1.7

Version Description

  • Old backups retained when a site is restored
  • Compatible with Better WP Security
  • Compatible with WP Engine
  • Improved backups
  • Bug fixes
Download this release

Release Info

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

Code changes from version 1.1.6 to 1.1.7

addons/comments/comments.class.php ADDED
@@ -0,0 +1,256 @@
1
+ <?php
2
+ /*************************************************************
3
+ *
4
+ * comment.class.php
5
+ *
6
+ * Get comments
7
+ *
8
+ *
9
+ * Copyright (c) 2011 Prelovac Media
10
+ * www.prelovac.com
11
+ **************************************************************/
12
+ if(basename($_SERVER['SCRIPT_FILENAME']) == "comments.class.php"):
13
+ exit;
14
+ endif;
15
+ class IWP_MMB_Comment extends IWP_MMB_Core
16
+ {
17
+ function __construct()
18
+ {
19
+ parent::__construct();
20
+ }
21
+
22
+ function change_status($args)
23
+ {
24
+
25
+ global $wpdb;
26
+ $comment_id = $args['comment_id'];
27
+ $status = $args['status'];
28
+
29
+ if ( 'approve' == $status )
30
+ $status_sql = '1';
31
+ elseif ( 'unapprove' == $status )
32
+ $status_sql = '0';
33
+ elseif ( 'spam' == $status )
34
+ $status_sql = 'spam';
35
+ elseif ( 'trash' == $status )
36
+ $status_sql = 'trash';
37
+ $sql = "update ".$wpdb->prefix."comments set comment_approved = '%s' where comment_ID = '%s'";
38
+ $success = $wpdb->query($wpdb->prepare($sql, $status_sql, $comment_id));
39
+
40
+
41
+ return $success;
42
+ }
43
+
44
+ function get_comments($args){
45
+
46
+ global $wpdb;
47
+
48
+ $where='';
49
+
50
+ extract($args);
51
+
52
+ if(!empty($filter_comments))
53
+ {
54
+ $where.=" AND (c.comment_author LIKE '%".mysql_real_escape_string($filter_comments)."%' OR c.comment_content LIKE '%".mysql_real_escape_string($filter_comments)."%')";
55
+ }
56
+ $comment_array = array();
57
+ $comment_statuses = array('approved', 'pending', 'spam', 'trash');
58
+ foreach ($args as $checkbox => $checkbox_val)
59
+ {
60
+ if($checkbox_val=="on") {
61
+ $status_val = str_replace("iwp_get_comments_","",$checkbox);
62
+ if($status_val == 'approved'){
63
+ $status_val = 1;
64
+ }elseif($status_val == 'pending'){
65
+ $status_val = 0;
66
+ }
67
+ $comment_array[]="'".$status_val."'";
68
+ }
69
+ }
70
+ if(!empty($comment_array))
71
+ {
72
+ $where.=" AND c.comment_approved IN (".implode(",",$comment_array).")";
73
+ }
74
+
75
+ $sql_query = "$wpdb->comments as c, $wpdb->posts as p WHERE c.comment_post_ID = p.ID ".$where;
76
+
77
+ $comments_total = $wpdb->get_results("SELECT count(*) as total_comments FROM ".$sql_query);
78
+ $total=$comments_total[0]->total_comments;
79
+ $comments_approved = $this->comment_total();
80
+
81
+ $query_comments = $wpdb->get_results("SELECT c.comment_ID, c.comment_post_ID, c.comment_author, c.comment_author_email, c.comment_author_url, c.comment_author_IP, c.comment_date, c.comment_content, c.comment_approved, c.comment_parent, p.post_title, p.post_type, p.guid FROM ".$sql_query." ORDER BY c.comment_date DESC LIMIT 500");
82
+ $comments = array();
83
+ foreach ( $query_comments as $comments_info )
84
+ {
85
+ $comment_total_approved = 0;
86
+ if(isset($comments_approved[$comments_info->comment_post_ID]['approved'])){
87
+ $comment_total_approved = $comments_approved[$comments_info->comment_post_ID]['approved'];
88
+ }
89
+ $comment_total_pending = 0;
90
+ if(isset($comments_approved[$comments_info->comment_post_ID]['pending'])){
91
+ $comment_total_pending = $comments_approved[$comments_info->comment_post_ID]['pending'];
92
+ }
93
+ $comment_parent_author = '';
94
+ if($comments_info->comment_parent > 0){
95
+ $select_parent_author = "SELECT comment_author FROM $wpdb->comments WHERE comment_ID = ".$comments_info->comment_parent;
96
+ $select_parent_author_res = $wpdb->get_row($select_parent_author);
97
+ $comment_parent_author = $select_parent_author_res->comment_author;
98
+ }
99
+
100
+ $comments[$comments_info->comment_ID] = array(
101
+ "comment_post_ID" => $comments_info->comment_post_ID,
102
+ "comment_author" => $comments_info->comment_author,
103
+ "comment_author_email" => $comments_info->comment_author_email,
104
+ "comment_author_url" => $comments_info->comment_author_url,
105
+ "comment_author_IP" => $comments_info->comment_author_IP,
106
+ "comment_date" => $comments_info->comment_date,
107
+ "comment_content" => $comments_info->comment_content,
108
+ "comment_approved" => $comments_info->comment_approved,
109
+ "comment_parent" => $comments_info->comment_parent,
110
+ "comment_parent_author" => $comment_parent_author,
111
+ "post_title" => $comments_info->post_title,
112
+ "post_type" => $comments_info->post_type,
113
+ "guid" => $comments_info->guid,
114
+ "comment_total_approved" => $comment_total_approved,
115
+ "comment_total_pending" => $comment_total_pending,
116
+ );
117
+ }
118
+
119
+ return array('comments' => $comments, 'total' => $total);
120
+ }
121
+
122
+ function comment_total(){
123
+ global $wpdb;
124
+ $totals = array();
125
+ $select_total_approved = "SELECT COUNT(*) as total, p.ID FROM $wpdb->comments as c, $wpdb->posts as p WHERE c.comment_post_ID = p.ID AND c.comment_approved = 1 GROUP BY p.ID";
126
+ $select_total_approved_res = $wpdb->get_results($select_total_approved);
127
+
128
+ if(!empty($select_total_approved_res)){
129
+ foreach($select_total_approved_res as $row){
130
+ $totals[$row->ID]['approved'] = $row->total;
131
+ }
132
+ }
133
+ $select_total_pending = "SELECT COUNT(*) as total, p.ID FROM $wpdb->comments as c, $wpdb->posts as p WHERE c.comment_post_ID = p.ID AND c.comment_approved = 0 GROUP BY p.ID";
134
+ $select_total_pending_res = $wpdb->get_results($select_total_pending);
135
+ if(!empty($select_total_pending_res)){
136
+ foreach($select_total_pending_res as $row){
137
+ $totals[$row->ID]['pending'] = $row->total;
138
+ }
139
+ }
140
+
141
+ return $totals;
142
+ }
143
+
144
+ function action_comment($args){
145
+ global $wpdb;
146
+ extract($args);
147
+ if($docomaction == 'approve'){
148
+ $docomaction = '1';
149
+ }else if($docomaction == 'unapprove' || $docomaction == 'untrash' || $docomaction == 'unspam'){
150
+ $docomaction = '0';
151
+ }
152
+
153
+ if(!empty($comment_id)){
154
+ if($docomaction == 'delete'){
155
+ $update_query = "DELETE FROM $wpdb->comments WHERE comment_ID = ".$comment_id;
156
+ $delete_query = "DELETE FROM $wpdb->commentmeta WHERE comment_id = ".$comment_id;
157
+ $wpdb->query($delete_query);
158
+ }else{
159
+ $update_query = "UPDATE $wpdb->comments SET comment_approved = '".$docomaction."' WHERE comment_ID = ".$comment_id;
160
+ }
161
+ $wpdb->query($update_query);
162
+
163
+ return 'Comment updated.';
164
+ }else{
165
+ return 'No ID...';
166
+ }
167
+ }
168
+
169
+ function bulk_action_comments($args){
170
+ global $wpdb;
171
+ extract($args);
172
+
173
+ if($docomaction=='delete'){
174
+ $update_query_intro = "DELETE FROM $wpdb->comments WHERE comment_ID = ";
175
+ }else{
176
+ if($docomaction=='unapprove' || $docomaction == 'untrash' || $docomaction == 'unspam'){
177
+ $docomaction = '0';
178
+ }else if($docomaction == 'approve'){
179
+ $docomaction = '1';
180
+ }
181
+ $update_query_intro = "UPDATE $wpdb->comments SET comment_approved = '".$docomaction."' WHERE comment_ID = ";
182
+ }
183
+ foreach($args as $key=>$val){
184
+
185
+ if(!empty($val) && is_numeric($val))
186
+ {
187
+ if($docomaction=='delete'){
188
+ $delete_query = "DELETE FROM $wpdb->commentmeta WHERE comment_id = ".$val;
189
+ $wpdb->query($delete_query);
190
+ }
191
+ $update_query = $update_query_intro.$val;
192
+
193
+ $wpdb->query($update_query);
194
+ }
195
+ }
196
+ return "comments updated";
197
+ }
198
+
199
+ function reply_comment($args){
200
+ global $wpdb, $current_user;
201
+
202
+ extract($args);
203
+
204
+ $comments = array();
205
+
206
+ if(!empty($comment_id) && !empty($reply_text)){
207
+ $admins = get_userdata($current_user->ID);
208
+ $now = time();
209
+ $insert_reply = "INSERT INTO $wpdb->comments(comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_karma, comment_approved, comment_agent, comment_parent, user_id) VALUES(".$post_id.", '".$admins->user_login."', '".$admins->user_email."', '".$admins->user_url."', '".$_SERVER['REMOTE_ADDR']."', NOW(), NOW(), '%s', 0, 1, '".$_SERVER['HTTP_USER_AGENT']."', ".$comment_id.", ".$current_user->ID.")";
210
+ $insert_reply_res = $wpdb->query($wpdb->prepare($insert_reply, $reply_text));
211
+ $lastid = $wpdb->insert_id;
212
+
213
+ $comments_approved = $this->comment_total();
214
+
215
+ $comment_total_approved = 0;
216
+ if(isset($comments_approved[$post_id]['approved'])){
217
+ $comment_total_approved = $comments_approved[$post_id]['approved'];
218
+ }
219
+ $comment_total_pending = 0;
220
+ if(isset($comments_approved[$post_id]['pending'])){
221
+ $comment_total_pending = $comments_approved[$post_id]['pending'];
222
+ }
223
+
224
+ $comment_parent_author = '';
225
+ if($comment_id > 0){
226
+ $select_parent_author = "SELECT c.comment_author, p.post_title, p.post_type, p.guid FROM $wpdb->comments as c, $wpdb->posts as p WHERE c.comment_post_ID = p.ID AND c.comment_ID = ".$comment_id;
227
+ $select_parent_author_res = $wpdb->get_row($select_parent_author);
228
+ $comment_parent_author = $select_parent_author_res->comment_author;
229
+ }
230
+
231
+ $comments[$lastid] = array(
232
+ "comment_post_ID" => $post_id,
233
+ "comment_author" => $admins->user_login,
234
+ "comment_author_email" => $admins->user_email,
235
+ "comment_author_url" => $admins->user_url,
236
+ "comment_author_IP" => $_SERVER['REMOTE_ADDR'],
237
+ "comment_date" => $now,
238
+ "comment_content" => $reply_text,
239
+ "comment_approved" => '1',
240
+ "comment_parent" => $comment_id,
241
+ "comment_parent_author" => $comment_parent_author,
242
+ "post_title" => $select_parent_author_res->post_title,
243
+ "post_type" => $select_parent_author_res->post_type,
244
+ "guid" => $select_parent_author_res->guid,
245
+ "comment_total_approved" => $comment_total_approved,
246
+ "comment_total_pending" => $comment_total_pending,
247
+ );
248
+
249
+
250
+ }
251
+
252
+ return $comments;
253
+ }
254
+
255
+ }
256
+ ?>
addons/post_links/link.class.php ADDED
@@ -0,0 +1,182 @@
1
+ <?php
2
+ /*************************************************************
3
+ *
4
+ * link.class.php
5
+ *
6
+ * Manage/Add Links
7
+ *
8
+ *
9
+ * Copyright (c) 2011 Prelovac Media
10
+ * www.prelovac.com
11
+ **************************************************************/
12
+ if(basename($_SERVER['SCRIPT_FILENAME']) == "link.class.php"):
13
+ exit;
14
+ endif;
15
+ class IWP_MMB_Link extends IWP_MMB_Core
16
+ {
17
+ function __construct()
18
+ {
19
+ parent::__construct();
20
+ }
21
+
22
+ function add_link($args)
23
+ {
24
+ extract($args);
25
+
26
+ $params['link_url'] = esc_html($url);
27
+ $params['link_url'] = esc_url($params['link_url']);
28
+ $params['link_name'] = esc_html($name);
29
+ $params['link_id'] = '';
30
+ $params['link_description'] = $description;
31
+ $params['link_target'] = $link_target;
32
+ $params['link_category'] = array();
33
+
34
+ //Add Link category
35
+ if(is_array($link_category) && !empty($link_category)){
36
+ $terms = get_terms('link_category',array('hide_empty' => 0));
37
+
38
+ if($terms){
39
+ foreach($terms as $term){
40
+ if(in_array($term->name,$link_category)){
41
+ $params['link_category'][] = $term->term_id;
42
+ $link_category = $this->remove_element($link_category, $term->name);
43
+ }
44
+ }
45
+ }
46
+ if(!empty($link_category)){
47
+ foreach($link_category as $linkkey => $linkval){
48
+ if(!empty($linkval)){
49
+ $link = wp_insert_term($linkval,'link_category');
50
+
51
+ if(isset($link['term_id']) && !empty($link['term_id'])){
52
+ $params['link_category'][] = $link['term_id'];
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+ //Add Link Owner
60
+ $user_obj = get_userdatabylogin($user);
61
+ if($user_obj && $user_obj->ID){
62
+ $params['link_owner'] = $user_obj->ID;
63
+ }
64
+
65
+
66
+ if(!function_exists('wp_insert_link'))
67
+ include_once (ABSPATH . 'wp-admin/includes/bookmark.php');
68
+
69
+ $is_success = wp_insert_link($params);
70
+
71
+ return $is_success ? true : array('error' => 'Failed to add link.');
72
+ }
73
+
74
+ function remove_element($arr, $val){
75
+ foreach ($arr as $key => $value){
76
+ if ($value == $val){
77
+ unset($arr[$key]);
78
+ }
79
+ }
80
+ return $arr = array_values($arr);
81
+ }
82
+
83
+ function get_links($args){
84
+ global $wpdb;
85
+
86
+ $where='';
87
+
88
+ extract($args);
89
+
90
+ if(!empty($filter_links))
91
+ {
92
+ $where.=" AND (link_name LIKE '%".mysql_real_escape_string($filter_links)."%' OR link_url LIKE '%".mysql_real_escape_string($filter_links)."%')";
93
+ }
94
+
95
+ $linkcats = $this->getLinkCats();
96
+ $sql_query = "$wpdb->links WHERE 1=1 ".$where;
97
+
98
+ $links_total = $wpdb->get_results("SELECT count(*) as total_links FROM ".$sql_query);
99
+ $total=$links_total[0]->total_links;
100
+
101
+ $query_links = $wpdb->get_results("SELECT link_id, link_url, link_name, link_target, link_visible, link_rating, link_rel FROM ".$sql_query." ORDER BY link_name ASC LIMIT 500");
102
+ $links = array();
103
+ foreach ( $query_links as $link_info )
104
+ {
105
+ $link_cat = $linkcats[$link_info->link_id];
106
+ $cats = array();
107
+ foreach($link_cat as $catkey=>$catval)
108
+ {
109
+ $cats[] = $catval;
110
+ }
111
+
112
+ $links[$link_info->link_id] = array(
113
+ "link_url" => $link_info->link_url,
114
+ "link_name" => $link_info->link_name,
115
+ "link_target" => $link_info->link_target,
116
+ "link_visible" => $link_info->link_visible,
117
+ "link_rating" => $link_info->link_rating,
118
+ "link_rel" => $link_info->link_rel,
119
+ "link_cats" => $cats
120
+ );
121
+ }
122
+
123
+ return array('links' => $links, 'total' => $total);
124
+ }
125
+
126
+ function getLinkCats($taxonomy = 'link_category')
127
+ {
128
+ global $wpdb;
129
+
130
+ $cats = $wpdb->get_results("SELECT l.link_id, $wpdb->terms.name
131
+ FROM $wpdb->links AS l
132
+ INNER JOIN $wpdb->term_relationships ON ( l.link_id = $wpdb->term_relationships.object_id )
133
+ INNER JOIN $wpdb->term_taxonomy ON ( $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
134
+ AND $wpdb->term_taxonomy.taxonomy = '".$taxonomy."' )
135
+ INNER JOIN $wpdb->terms ON ( $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id )");
136
+
137
+ foreach ( $cats as $post_val )
138
+ {
139
+
140
+ $post_cats[$post_val->link_id][] = $post_val->name;
141
+ }
142
+
143
+ return $post_cats;
144
+ }
145
+
146
+ function delete_link($args){
147
+ global $wpdb;
148
+
149
+ if(!empty($args['link_id']))
150
+ {
151
+ $delete_query = "DELETE FROM $wpdb->links WHERE link_id = ".$args['link_id'];
152
+ $wpdb->get_results($delete_query);
153
+
154
+ return 'Link deleted.';
155
+ }
156
+ else
157
+ {
158
+ return 'No ID...';
159
+ }
160
+ }
161
+
162
+ function delete_links($args){
163
+ global $wpdb;
164
+ extract($args);
165
+
166
+ if($deleteaction=='delete'){
167
+ $delete_query_intro = "DELETE FROM $wpdb->links WHERE link_id = ";
168
+ }
169
+ foreach($args as $key=>$val){
170
+
171
+ if(!empty($val) && is_numeric($val))
172
+ {
173
+ $delete_query = $delete_query_intro.$val;
174
+
175
+ $wpdb->query($delete_query);
176
+ }
177
+ }
178
+ return "Link deleted";
179
+ }
180
+
181
+ }
182
+ ?>
addons/post_links/post.class.php ADDED
@@ -0,0 +1,773 @@
1
+ <?php
2
+ /*************************************************************
3
+ *
4
+ * post.class.php
5
+ *
6
+ * Create remote post
7
+ *
8
+ *
9
+ * Copyright (c) 2011 Prelovac Media
10
+ * www.prelovac.com
11
+ **************************************************************/
12
+ if(basename($_SERVER['SCRIPT_FILENAME']) == "post.class.php"):
13
+ exit;
14
+ endif;
15
+ class IWP_MMB_Post extends IWP_MMB_Core
16
+ {
17
+ function __construct()
18
+ {
19
+ parent::__construct();
20
+ }
21
+
22
+ function create($args)
23
+ {
24
+
25
+ //$this->_log($args);
26
+ global $wpdb;
27
+
28
+ /**
29
+ * algorithm
30
+ * 1. create post using wp_insert_post (insert tags also here itself)
31
+ * 2. use wp_create_categories() to create(not exists) and insert in the post
32
+ * 3. insert meta values
33
+ */
34
+
35
+ include_once ABSPATH . 'wp-admin/includes/taxonomy.php';
36
+ include_once ABSPATH . 'wp-admin/includes/image.php';
37
+ include_once ABSPATH . 'wp-admin/includes/file.php';
38
+
39
+ $post_struct = $args['post_data'];
40
+
41
+
42
+
43
+ $post_data = $post_struct['post_data'];
44
+ $new_custom = $post_struct['post_extras']['post_meta'];
45
+ $post_categories = explode(',', $post_struct['post_extras']['post_categories']);
46
+ $post_atta_img = $post_struct['post_extras']['post_atta_images'];
47
+ $post_upload_dir = $post_struct['post_extras']['post_upload_dir'];
48
+ $post_checksum = $post_struct['post_extras']['post_checksum'];
49
+ $post_featured_img = $post_struct['post_extras']['featured_img'];
50
+
51
+ $upload = wp_upload_dir();
52
+
53
+ // create dynamic url RegExp
54
+ $iwp_base_url = parse_url($post_upload_dir['url']);
55
+ $iwp_regexp_url = $iwp_base_url['host'] . $iwp_base_url['path'];
56
+ $rep = array(
57
+ '/',
58
+ '+',
59
+ '.',
60
+ ':',
61
+ '?'
62
+ );
63
+ $with = array(
64
+ '\/',
65
+ '\+',
66
+ '\.',
67
+ '\:',
68
+ '\?'
69
+ );
70
+ $iwp_regexp_url = str_replace($rep, $with, $iwp_regexp_url);
71
+
72
+ // rename all src ../wp-content/ with hostname/wp-content/
73
+
74
+ $iwp_mmb_dot_url = '..' . $iwp_mmb_base_url['path'];
75
+ $iwp_mmb_dot_url = str_replace($rep, $with, $iwp_mmb_dot_url);
76
+ $dot_match_count = preg_match_all('/(<a[^>]+href=\"([^"]+)\"[^>]*>)?(<\s*img.[^\/>]*src="([^"]*' . $iwp_mmb_dot_url . '[^\s]+\.(jpg|jpeg|png|gif|bmp))"[^>]*>)/ixu', $post_data['post_content'], $dot_get_urls, PREG_SET_ORDER);
77
+
78
+ file_put_contents("C:\wamp\www\_teste.php", var_export($iwp_base_url, true).'--iwp_mmb_base_url---'.var_export($post_data['post_content'], true).'--iwp_mmb_base_url---'.var_export($dot_match_count, true).'--iwp_mmb_dot_url---'.var_export($iwp_mmb_dot_url, true).'--iwp_mmb_base_url---'.var_export($iwp_mmb_base_url, true).'--iwp_mmb_base_url---'.var_export($dot_get_urls, true));
79
+
80
+ if ($dot_match_count > 0) {
81
+ foreach ($dot_get_urls as $dot_url) {
82
+ $match_dot = '/' . str_replace($rep, $with, $dot_url[4]) . '/';
83
+ $replace_dot = 'http://' . $iwp_mmb_base_url['host'] . substr($dot_url[4], 2, strlen($dot_url[4]));
84
+ $post_data['post_content'] = preg_replace($match_dot, $replace_dot, $post_data['post_content']);
85
+
86
+ if ($dot_url[1] != '') {
87
+ $match_dot_a = '/' . str_replace($rep, $with, $dot_url[2]) . '/';
88
+ $replace_dot_a = 'http://' . $iwp_mmb_base_url['host'] . substr($dot_url[2], 2, strlen($dot_url[2]));
89
+ $post_data['post_content'] = preg_replace($match_dot_a, $replace_dot_a, $post_data['post_content']);
90
+ }
91
+ }
92
+ }
93
+
94
+ //to find all the images
95
+ $match_count = preg_match_all('/(<a[^>]+href=\"([^"]+)\"[^>]*>)?(<\s*img.[^\/>]*src="([^"]+' . $iwp_mmb_regexp_url . '[^\s]+\.(jpg|jpeg|png|gif|bmp))"[^>]*>)/ixu', $post_data['post_content'], $get_urls, PREG_SET_ORDER);
96
+
97
+ ///////////
98
+ //$html = $params['postContent'];
99
+ //
100
+ // $doc = new DOMDocument();
101
+ // @$doc->loadHTML($html);
102
+ //
103
+ // $tags = $doc->getElementsByTagName('img');
104
+ //
105
+ // foreach ($tags as $tag) {
106
+ // $img[]['src'] = str_replace('\"','',$tag->getAttribute('src'));
107
+ // }
108
+ /////////////////
109
+
110
+ if ($match_count > 0) {
111
+ $attachments = array();
112
+ $post_content = $post_data['post_content'];
113
+
114
+ foreach ($get_urls as $get_url_k => $get_url) {
115
+ // unset url in attachment array
116
+ foreach ($post_atta_img as $atta_url_k => $atta_url_v) {
117
+ $match_patt_url = '/' . str_replace($rep, $with, substr($atta_url_v['src'], 0, strrpos($atta_url_v['src'], '.'))) . '/';
118
+ if (preg_match($match_patt_url, $get_url[4])) {
119
+ unset($post_atta_img[$atta_url_k]);
120
+ }
121
+ }
122
+ $pic_from_other_site = $get_urls[$get_url_k][4];
123
+ /* if(strpos($pic_from_other_site,'exammple.com') === false){
124
+ continue;
125
+ }*/
126
+
127
+ if (isset($get_urls[$get_url_k][6])) { // url have parent, don't download this url
128
+ if ($get_url[1] != '') {
129
+ // change src url
130
+ $s_mmb_mp = '/' . str_replace($rep, $with, $get_url[4]) . '/';
131
+
132
+ $s_img_atta = wp_get_attachment_image_src($get_urls[$get_url_k][6]);
133
+ $s_mmb_rp = $s_img_atta[0];
134
+ $post_content = preg_replace($s_mmb_mp, $s_mmb_rp, $post_content);
135
+ // change attachment url
136
+ if (preg_match('/attachment_id/i', $get_url[2])) {
137
+ $iwp_mmb_mp = '/' . str_replace($rep, $with, $get_url[2]) . '/';
138
+ $iwp_mmb_rp = get_bloginfo('wpurl') . '/?attachment_id=' . $get_urls[$get_url_k][6];
139
+ $post_content = preg_replace($iwp_mmb_mp, $iwp_mmb_rp, $post_content);
140
+ }
141
+ }
142
+ continue;
143
+ }
144
+
145
+ $no_thumb = '';
146
+ if (preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}#x2F;', $get_url[4])) {
147
+ $no_thumb = preg_replace('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}#x2F;', '.' . $get_url[5], $get_url[4]);
148
+ } else {
149
+ $no_thumb = $get_url[4];
150
+ }
151
+
152
+ if(isset($upload['error']) && !empty($upload['error'])){
153
+ return array('error' => $upload['error']);
154
+ }
155
+ $file_name = basename($no_thumb);
156
+ $tmp_file = download_url($no_thumb);
157
+
158
+ if(is_wp_error($tmp_file)){
159
+ return array('error' => $tmp_file->get_error_message());
160
+ }
161
+
162
+ $attach_upload['url'] = $upload['url'] . '/' . $file_name;
163
+ $attach_upload['path'] = $upload['path'] . '/' . $file_name;
164
+ $renamed = @rename($tmp_file, $attach_upload['path']);
165
+ if ($renamed === true) {
166
+ $match_pattern = '/' . str_replace($rep, $with, $get_url[4]) . '/';
167
+ $replace_pattern = $attach_upload['url'];
168
+ $post_content = preg_replace($match_pattern, $replace_pattern, $post_content);
169
+ if (preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}#x2F;', $get_url[4])) {
170
+ $match_pattern = '/' . str_replace($rep, $with, preg_replace('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}#x2F;', '.' . $get_url[5], $get_url[4])) . '/';
171
+ $post_content = preg_replace($match_pattern, $replace_pattern, $post_content);
172
+ }
173
+
174
+ $attachment = array(
175
+ 'post_title' => $file_name,
176
+ 'post_content' => '',
177
+ 'post_type' => 'attachment',
178
+ //'post_parent' => $post_id,
179
+ 'post_mime_type' => 'image/' . $get_url[5],
180
+ 'guid' => $attach_upload['url']
181
+ );
182
+
183
+ // Save the data
184
+
185
+ $attach_id = wp_insert_attachment($attachment, $attach_upload['path']);
186
+
187
+ $attachments[$attach_id] = 0;
188
+
189
+ // featured image
190
+ if ($post_featured_img != '') {
191
+ $feat_img_url = '';
192
+ if (preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}#x2F;', $post_featured_img)) {
193
+ $feat_img_url = substr($post_featured_img, 0, strrpos($post_featured_img, '.') - 8);
194
+ } else {
195
+ $feat_img_url = substr($post_featured_img, 0, strrpos($post_featured_img, '.'));
196
+ }
197
+ $m_feat_url = '/' . str_replace($rep, $with, $feat_img_url) . '/';
198
+ if (preg_match($m_feat_url, $get_url[4])) {
199
+ $post_featured_img = '';
200
+ $attachments[$attach_id] = $attach_id;
201
+ }
202
+ }
203
+
204
+ // set $get_urls value[6] - parent atta_id
205
+ foreach ($get_urls as $url_k => $url_v) {
206
+ if ($get_url_k != $url_k) {
207
+ $s_get_url = '';
208
+ if (preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}#x2F;', $url_v[4])) {
209
+ $s_get_url = substr($url_v[4], 0, strrpos($url_v[4], '.') - 8);
210
+ } else {
211
+ $s_get_url = substr($url_v[4], 0, strrpos($url_v[4], '.'));
212
+ }
213
+ $m_patt_url = '/' . str_replace($rep, $with, $s_get_url) . '/';
214
+ if (preg_match($m_patt_url, $get_url[4])) {
215
+ array_push($get_urls[$url_k], $attach_id);
216
+ }
217
+ }
218
+ }
219
+
220
+
221
+ $some_data = wp_generate_attachment_metadata($attach_id, $attach_upload['path']);
222
+ wp_update_attachment_metadata($attach_id, $some_data);
223
+
224
+
225
+ //changing href of a tag
226
+ if ($get_url[1] != '') {
227
+ $iwp_mmb_mp = '/' . str_replace($rep, $with, $get_url[2]) . '/';
228
+ if (preg_match('/attachment_id/i', $get_url[2])) {
229
+ $iwp_mmb_rp = get_bloginfo('wpurl') . '/?attachment_id=' . $attach_id;
230
+ $post_content = preg_replace($iwp_mmb_mp, $iwp_mmb_rp, $post_content);
231
+ }
232
+ }
233
+ } else {
234
+ @unlink($tmp_file);
235
+ return array('error' => "Cannot create attachment file in ".$attach_upload['path']." Please set correct permissions.");
236
+
237
+ }
238
+ @unlink($tmp_file);
239
+ }
240
+
241
+
242
+ $post_data['post_content'] = $post_content;
243
+
244
+ }
245
+ if (count($post_atta_img)) {
246
+ foreach ($post_atta_img as $img) {
247
+ $file_name = basename($img['src']);
248
+
249
+ if(isset($upload['error']) && !empty($upload['error'])){
250
+ return array('error' => $upload['error']);
251
+ }
252
+
253
+ $tmp_file = download_url($img['src']);
254
+ if(is_wp_error($tmp_file)){
255
+ return array('error' => $tmp_file->get_error_message());
256
+ }
257
+
258
+ $attach_upload['url'] = $upload['url'] . '/' . $file_name;
259
+ $attach_upload['path'] = $upload['path'] . '/' . $file_name;
260
+ $renamed = @rename($tmp_file, $attach_upload['path']);
261
+ if ($renamed === true) {
262
+ $atta_ext = end(explode('.', $file_name));
263
+
264
+ $attachment = array(
265
+ 'post_title' => $file_name,
266
+ 'post_content' => '',
267
+ 'post_type' => 'attachment',
268
+ //'post_parent' => $post_id,
269
+ 'post_mime_type' => 'image/' . $atta_ext,
270
+ 'guid' => $attach_upload['url']
271
+ );
272
+
273
+ // Save the data
274
+ $attach_id = wp_insert_attachment($attachment, $attach_upload['path']);
275
+ wp_update_attachment_metadata($attach_id, wp_generate_attachment_metadata($attach_id, $attach_upload['path']));
276
+ $attachments[$attach_id] = 0;
277
+
278
+ // featured image
279
+ if ($post_featured_img != '') {
280
+ $feat_img_url = '';
281
+ if (preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}#x2F;', $post_featured_img)) {
282
+ $feat_img_url = substr($post_featured_img, 0, strrpos($post_featured_img, '.') - 8);
283
+ } else {
284
+ $feat_img_url = substr($post_featured_img, 0, strrpos($post_featured_img, '.'));
285
+ }
286
+ $m_feat_url = '/' . str_replace($rep, $with, $feat_img_url) . '/';
287
+ if (preg_match($m_feat_url, $img['src'])) {
288
+ $post_featured_img = '';
289
+ $attachments[$attach_id] = $attach_id;
290
+ }
291
+ }
292
+
293
+ } else {
294
+ @unlink($tmp_file);
295
+ return array('error' => "Cannot create attachment file in ".$attach_upload['path']." Please set correct permissions.");
296
+ }
297
+ @unlink($tmp_file);
298
+ }
299
+ }
300
+
301
+ //Prepare post data and temporarily remove content filters before insert post
302
+ $user = $this->iwp_mmb_get_user_info( $args['username'] );
303
+ if($user && $user->ID){
304
+ $post_data['post_author'] = $user->ID;
305
+ }
306
+ //remove filter which can brake scripts or html
307
+ remove_filter('content_save_pre', 'wp_filter_post_kses');
308
+
309
+ //check for edit post
310
+ $post_result = 0;
311
+ if(isset($post_data['iwp_post_edit']) && $post_data['iwp_post_edit']){
312
+
313
+
314
+ if($post_data['iwp_match_by'] == 'title'){
315
+ $match_by = "post_title = '".$post_data['post_title']."'";
316
+ } else {
317
+ $match_by = "post_name = '".$post_data['post_name']."'";
318
+ }
319
+
320
+ $query = "SELECT ID FROM $wpdb->posts WHERE $match_by AND post_status NOT IN('inherit','auto-draft','draft') LIMIT 1";
321
+
322
+ $post_result = $wpdb->get_var($query);
323
+
324
+ }
325
+
326
+
327
+ if($post_result){
328
+ //update existing post
329
+ $post_data['ID'] = $post_result;
330
+ $post_id = wp_update_post($post_data);
331
+
332
+ //check for previous attachments
333
+ $atta_allimages =& get_children('post_type=attachment&post_parent=' . $post_id);
334
+ if (!empty($atta_allimages)) {
335
+ foreach ($atta_allimages as $image) {
336
+ wp_delete_attachment($image->ID);
337
+ }
338
+ }
339
+
340
+ } else {
341
+ if($post_data['iwp_post_edit'] && $post_data['iwp_force_publish']){
342
+ $post_id = wp_insert_post($post_data);
343
+ } elseif($post_data['iwp_post_edit'] && !$post_data['iwp_force_publish']) {
344
+ return array('error' => "Post not found.");
345
+ } else {
346
+ $post_id = wp_insert_post($post_data);
347
+ }
348
+
349
+ }
350
+
351
+ if (count($attachments)) {
352
+ foreach ($attachments as $atta_id => $featured_id) {
353
+ $result = wp_update_post(array(
354
+ 'ID' => $atta_id,
355
+ 'post_parent' => $post_id
356
+ ));
357
+ if ($featured_id > 0) {
358
+ $new_custom['_thumbnail_id'] = array(
359
+ $featured_id
360
+ );
361
+ }
362
+ }
363
+ }
364
+
365
+ // featured image
366
+ if ($post_featured_img != '') {
367
+ $file_name = basename($post_featured_img);
368
+ if(isset($upload['error']) && !empty($upload['error'])){
369
+ return array('error' => $upload['error']);
370
+ }
371
+ $tmp_file = download_url($post_featured_img);
372
+ if(is_wp_error($tmp_file)){
373
+ return array('error' => $tmp_file->get_error_message());
374
+ }
375
+ $attach_upload['url'] = $upload['url'] . '/' . $file_name;
376
+ $attach_upload['path'] = $upload['path'] . '/' . $file_name;
377
+ $renamed = @rename($tmp_file, $attach_upload['path']);
378
+ if ($renamed === true) {
379
+ $atta_ext = end(explode('.', $file_name));
380
+
381
+ $attachment = array(
382
+ 'post_title' => $file_name,
383
+ 'post_content' => '',
384
+ 'post_type' => 'attachment',
385
+ 'post_parent' => $post_id,
386
+ 'post_mime_type' => 'image/' . $atta_ext,
387
+ 'guid' => $attach_upload['url']
388
+ );
389
+
390
+ // Save the data
391
+ $attach_id = wp_insert_attachment($attachment, $attach_upload['path']);
392
+ wp_update_attachment_metadata($attach_id, wp_generate_attachment_metadata($attach_id, $attach_upload['path']));
393
+ $new_custom['_thumbnail_id'] = array(
394
+ $attach_id
395
+ );
396
+ } else {
397
+ @unlink($tmp_file);
398
+ return array('error' => "Cannot create attachment file in ".$attach_upload['path']." Please set correct permissions.");
399
+ }
400
+ @unlink($tmp_file);
401
+ }
402
+
403
+ if ($post_id && is_array($post_categories)) {
404
+ //insert categories
405
+
406
+ $cat_ids = wp_create_categories($post_categories, $post_id);
407
+ }
408
+
409
+
410
+ //get current custom fields
411
+ $cur_custom = get_post_custom($post_id);
412
+ //check which values doesnot exists in new custom fields
413
+ $diff_values = array_diff_key($cur_custom, $new_custom);
414
+
415
+ if (is_array($diff_values))
416
+ foreach ($diff_values as $meta_key => $value) {
417
+ delete_post_meta($post_id, $meta_key);
418
+ }
419
+ //insert new post meta
420
+ foreach ($new_custom as $meta_key => $value) {
421
+ if (strpos($meta_key, '_mmb') === 0 || strpos($meta_key, '_edit') === 0) {
422
+ continue;
423
+ } else {
424
+ update_post_meta($post_id, $meta_key, $value[0]);
425
+ }
426
+ }
427
+ return $post_id;
428
+ }
429
+
430
+
431
+ function change_status($args)
432
+ {
433
+
434
+ global $wpdb;
435
+ $post_id = $args['post_id'];
436
+ $status = $args['status'];
437
+ $success = false;
438
+
439
+ if(in_array($status, array('draft', 'publish', 'trash'))){
440
+ $sql = "update ".$wpdb->prefix."posts set post_status = '$status' where ID = '$post_id'";
441
+ $success = $wpdb->query($sql);
442
+ }
443
+
444
+ return $success;
445
+ }
446
+
447
+ /**
448
+ * Function which gets posts from client depending on arguments.
449
+ * If FROM and TO dates are provided and range, range has bigger priority to date FROM.
450
+ * This means if there are less posts between FROM and TO than range provided,
451
+ * this function omit date from and returns last range number posts to date TO.
452
+ *
453
+ * @param array $args arguments passed to function
454
+ * @arg string filter_posts search phrase for post titles
455
+ * @arg string iwp_get_posts_date_from date in format(Y-m-d H:i:s) when posts are publishes from
456
+ * @arg string iwp_get_posts_date_to date in format(Y-m-d H:i:s) when posts are publishes to
457
+ * @arg string iwp_get_posts_range range number of returned posts
458
+ * @arg string iwp_get_posts_publish on or off
459
+ * @arg string iwp_get_posts_pending on or off
460
+ * @arg string iwp_get_posts_private on or off
461
+ * @arg string iwp_get_posts_future on or off
462
+ * @arg string iwp_get_posts_draft on or off
463
+ * @arg string iwp_get_posts_trash on or off
464
+ * @return array posts related to args
465
+ */
466
+ function get_posts($args){
467
+ global $wpdb;
468
+
469
+ $where='';
470
+
471
+ extract($args);
472
+
473
+ if(!empty($filter_posts))
474
+ {
475
+ $where.=" AND post_title LIKE '%".mysql_real_escape_string($filter_posts)."%'";
476
+ }
477
+
478
+ if(!empty($iwp_get_posts_date_from) && !empty($iwp_get_posts_date_to))
479
+ {
480
+ $where.=" AND post_date BETWEEN '".mysql_real_escape_string($iwp_get_posts_date_from)."' AND '".mysql_real_escape_string($iwp_get_posts_date_to)."'";
481
+ }
482
+ else if(!empty($iwp_get_posts_date_from) && empty($iwp_get_posts_date_to))
483
+ {
484
+ $where.=" AND post_date >= '".mysql_real_escape_string($iwp_get_posts_date_from)."'";
485
+ }
486
+ else if(empty($iwp_get_posts_date_from) && !empty($iwp_get_posts_date_to))
487
+ {
488
+ $where.=" AND post_date <= '".mysql_real_escape_string($iwp_get_posts_date_to)."'";
489
+ }
490
+ $post_array=array();
491
+ $post_statuses = array('publish', 'pending', 'private', 'future', 'draft', 'trash');
492
+ foreach ($args as $checkbox => $checkbox_val)
493
+ {
494
+ if($checkbox_val=="on") {
495
+ $post_array[]="'".str_replace("iwp_get_posts_","",$checkbox)."'";
496
+ }
497
+ }
498
+ if(!empty($post_array))
499
+ {
500
+ $where.=" AND post_status IN (".implode(",",$post_array).")";
501
+ }
502
+
503
+ $limit = ($iwp_get_posts_range) ? ' LIMIT ' . mysql_real_escape_string($iwp_get_posts_range) : ' LIMIT 500';
504
+
505
+ $sql_query = "$wpdb->posts WHERE post_status!='auto-draft' AND post_status!='inherit' AND post_type='post' ".$where." ORDER BY post_date DESC";
506
+
507
+ $total = array();
508
+ $posts = array();
509
+ $posts_info = $wpdb->get_results("SELECT * FROM ".$sql_query.$limit);
510
+ $user_info = $this->getUsersIDs();
511
+ $post_cats=$this->getPostCats();
512
+ $post_tags=$this->getPostCats('post_tag');
513
+ $total['total_num']=count($posts_info);
514
+
515
+ if($iwp_get_posts_range && !empty($iwp_get_posts_date_from) && !empty($iwp_get_posts_date_to) && $total['total_num'] < $iwp_get_posts_range) {
516
+ $sql_query = "$wpdb->posts
517
+ WHERE post_status!='auto-draft' AND post_status!='inherit' AND post_type='post' AND post_date <= '".mysql_real_escape_string($iwp_get_posts_date_to)."'
518
+ ORDER BY post_date DESC
519
+ LIMIT " . mysql_real_escape_string($iwp_get_posts_range);
520
+
521
+ $posts_info = $wpdb->get_results("SELECT * FROM ".$sql_query);
522
+ $total = array();
523
+ $total['total_num']=count($posts_info);
524
+ }
525
+
526
+ foreach ( $posts_info as $post_info )
527
+ {
528
+
529
+ $cats=array();
530
+ foreach($post_cats[$post_info->ID] as $cat_array => $cat_array_val)
531
+ {
532
+ $cats[] = array('name' => $cat_array_val);
533
+ }
534
+
535
+ $tags=array();
536
+ if (!empty($post_tags[$post_info->ID])) {
537
+ foreach($post_tags[$post_info->ID] as $tag_array => $tag_array_val)
538
+ {
539
+ $tags[] = array('name' => $tag_array_val);
540
+ }
541
+ }
542
+
543
+ $posts[]=array(
544
+ 'post_id'=>$post_info->ID,
545
+ 'post_title'=>$post_info->post_title,
546
+ 'post_name'=>$post_info->post_name,
547
+ 'post_author'=>array('author_id'=>$post_info->post_author, 'author_name'=>$user_info[$post_info->post_author]),
548
+ 'post_date'=>$post_info->post_date,
549
+ 'post_modified'=>$post_info->post_modified,
550
+ 'post_status'=>$post_info->post_status,
551
+ 'post_type'=>$post_info->post_type,
552
+ 'guid'=>$post_info->guid,
553
+ 'post_password'=>$post_info->post_password,
554
+ 'ping_status'=>$post_info->ping_status,
555
+ 'comment_status'=>$post_info->comment_status,
556
+ 'comment_count'=>$post_info->comment_count,
557
+ 'cats'=>$cats,
558
+ 'tags'=>$tags,
559
+
560
+ );
561
+ }
562
+
563
+ return array('posts' => $posts, 'total' => $total);
564
+ }
565
+
566
+ function delete_post($args){
567
+ global $wpdb;
568
+ if(!empty($args['post_id']) && !empty($args['action']))
569
+ {
570
+ if($args['action']=='delete')
571
+ {
572
+ $delete_query = "UPDATE $wpdb->posts SET post_status = 'trash' WHERE ID = ".$args['post_id'];
573
+ }
574
+ else if($args['action']=='delete_perm'){
575
+ $delete_query = "DELETE FROM $wpdb->posts WHERE ID = ".$args['post_id'];
576
+ }
577
+ else if($args['action']=='delete_restore'){
578
+ $delete_query = "UPDATE $wpdb->posts SET post_status = 'publish' WHERE ID = ".$args['post_id'];
579
+ }
580
+ $wpdb->get_results($delete_query);
581
+
582
+ return 'Post deleted.';
583
+ }
584
+ else
585
+ {
586
+ return 'No ID...';
587
+ }
588
+ }
589
+
590
+ function delete_posts($args){
591
+ global $wpdb;
592
+ extract($args);
593
+ if($deleteaction=='delete'){
594
+ $delete_query_intro = "DELETE FROM $wpdb->posts WHERE ID = ";
595
+ }elseif($deleteaction=='trash'){
596
+ $delete_query_intro = "UPDATE $wpdb->posts SET post_status = 'trash' WHERE ID = ";
597
+ }elseif($deleteaction=='draft'){
598
+ $delete_query_intro = "UPDATE $wpdb->posts SET post_status = 'draft' WHERE ID = ";
599
+ }elseif($deleteaction=='publish'){
600
+ $delete_query_intro = "UPDATE $wpdb->posts SET post_status = 'publish' WHERE ID = ";
601
+ }
602
+ foreach($args as $key=>$val){
603
+
604
+ if(!empty($val) && is_numeric($val))
605
+ {
606
+ $delete_query = $delete_query_intro.$val;
607
+
608
+ $wpdb->query($delete_query);
609
+ }
610
+ }
611
+ return "Post deleted";
612
+
613
+ }
614
+
615
+ /**
616
+ * Function which gets pages from client depending on arguments.
617
+ * If FROM and TO dates are provided and range, range has bigger priority to date FROM.
618
+ * This means if there are less pages between FROM and TO than range provided,
619
+ * this function omit date from and returns last range number pages to date TO.
620
+ *
621
+ * @param array $args arguments passed to function
622
+ * @arg string filter_pages search phrase for page titles
623
+ * @arg string iwp_get_pages_date_from date in format(Y-m-d H:i:s) when pages are publishes from
624
+ * @arg string iwp_get_pages_date_to date in format(Y-m-d H:i:s) when pages are publishes to
625
+ * @arg string iwp_get_pages_range range number of returned pages
626
+ * @arg string iwp_get_pages_publish on or off
627
+ * @arg string iwp_get_pages_pending on or off
628
+ * @arg string iwp_get_pages_private on or off
629
+ * @arg string iwp_get_pages_future on or off
630
+ * @arg string iwp_get_pages_draft on or off
631
+ * @arg string iwp_get_pages_trash on or off
632
+ * @return array pages related to args
633
+ */
634
+ function get_pages($args){
635
+ global $wpdb;
636
+
637
+ $where='';
638
+ extract($args);
639
+
640
+ if(!empty($filter_pages))
641
+ {
642
+ $where.=" AND post_title LIKE '%".mysql_real_escape_string($filter_pages)."%'";
643
+ }
644
+ if(!empty($iwp_get_pages_date_from) && !empty($iwp_get_pages_date_to))
645
+ {
646
+ $where.=" AND post_date BETWEEN '".mysql_real_escape_string($iwp_get_pages_date_from)."' AND '".mysql_real_escape_string($iwp_get_pages_date_to)."'";
647
+ }
648
+ else if(!empty($iwp_get_pages_date_from) && empty($iwp_get_pages_date_to))
649
+ {
650
+ $where.=" AND post_date >= '".mysql_real_escape_string($iwp_get_pages_date_from)."'";
651
+ }
652
+ else if(empty($iwp_get_pages_date_from) && !empty($iwp_get_pages_date_to))
653
+ {
654
+ $where.=" AND post_date <= '".mysql_real_escape_string($iwp_get_pages_date_to)."'";
655
+ }
656
+
657
+ $post_array=array();
658
+ $post_statuses = array('publish', 'pending', 'private', 'future', 'draft', 'trash');
659
+ foreach ($args as $checkbox => $checkbox_val)
660
+ {
661
+ if($checkbox_val=="on") {
662
+ $post_array[]="'".str_replace("iwp_get_pages_","",$checkbox)."'";
663
+ }
664
+ }
665
+ if(!empty($post_array))
666
+ {
667
+ $where.=" AND post_status IN (".implode(",",$post_array).")";
668
+ }
669
+
670
+ $limit = ($iwp_get_pages_range) ? ' LIMIT ' . mysql_real_escape_string($iwp_get_pages_range) : ' LIMIT 500';
671
+
672
+ $sql_query = "$wpdb->posts WHERE post_status!='auto-draft' AND post_status!='inherit' AND post_type='page' ".$where.' ORDER BY post_date DESC';
673
+
674
+ $total = array();
675
+ $posts = array();
676
+ $posts_info = $wpdb->get_results("SELECT * FROM ".$sql_query.$limit);
677
+ $user_info = $this->getUsersIDs();
678
+ $total['total_num']=count($posts_info);
679
+
680
+ if($iwp_get_pages_range && !empty($iwp_get_pages_date_from) && !empty($iwp_get_pages_date_to) && $total['total_num'] < $iwp_get_pages_range) {
681
+ $sql_query = "$wpdb->posts
682
+ WHERE post_status!='auto-draft' AND post_status!='inherit' AND post_type='post' AND post_date <= '".mysql_real_escape_string($iwp_get_pages_date_to)."'
683
+ ORDER BY post_date DESC
684
+ LIMIT " . mysql_real_escape_string($iwp_get_pages_range);
685
+
686
+ $posts_info = $wpdb->get_results("SELECT * FROM ".$sql_query);
687
+ $total = array();
688
+ $total['total_num']=count($posts_info);
689
+ }
690
+
691
+ foreach ( $posts_info as $post_info )
692
+ {
693
+
694
+ $posts[]=array(
695
+ 'post_id'=>$post_info->ID,
696
+ 'post_title'=>$post_info->post_title,
697
+ 'post_name'=>$post_info->post_name,
698
+ 'post_author'=>array('author_id'=>$post_info->post_author, 'author_name'=>$user_info[$post_info->post_author]),
699
+ 'post_date'=>$post_info->post_date,
700
+ 'post_modified'=>$post_info->post_modified,
701
+ 'post_status'=>$post_info->post_status,
702
+ 'post_type'=>$post_info->post_type,
703
+ 'guid'=>$post_info->guid,
704
+ 'post_password'=>$post_info->post_password,
705
+ 'ping_status'=>$post_info->ping_status,
706
+ 'comment_status'=>$post_info->comment_status,
707
+ 'comment_count'=>$post_info->comment_count
708
+
709
+ );
710
+ }
711
+
712
+ return array('pages' => $posts, 'total' => $total);
713
+ }
714
+
715
+ function delete_page($args){
716
+ global $wpdb;
717
+ if(!empty($args['post_id']) && !empty($args['action']))
718
+ {
719
+ if($args['action']=='delete')
720
+ {
721
+ $delete_query = "UPDATE $wpdb->posts SET post_status = 'trash' WHERE ID = ".$args['post_id'];
722
+ }
723
+ else if($args['action']=='delete_perm'){
724
+ $delete_query = "DELETE FROM $wpdb->posts WHERE ID = ".$args['post_id'];
725
+ }
726
+ else if($args['action']=='delete_restore'){
727
+ $delete_query = "UPDATE $wpdb->posts SET post_status = 'publish' WHERE ID = ".$args['post_id'];
728
+ }
729
+ $wpdb->get_results($delete_query);
730
+
731
+ return 'Page deleted.';
732
+ }
733
+ else
734
+ {
735
+ return 'No ID...';
736
+ }
737
+ }
738
+
739
+ function getPostCats($taxonomy = 'category')
740
+ {
741
+ global $wpdb;
742
+
743
+ $cats = $wpdb->get_results("SELECT p.ID AS post_id, $wpdb->terms.name
744
+ FROM $wpdb->posts AS p
745
+ INNER JOIN $wpdb->term_relationships ON ( p.ID = $wpdb->term_relationships.object_id )
746
+ INNER JOIN $wpdb->term_taxonomy ON ( $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
747
+ AND $wpdb->term_taxonomy.taxonomy = '".$taxonomy."' )
748
+ INNER JOIN $wpdb->terms ON ( $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id )");
749
+
750
+ foreach ( $cats as $post_val )
751
+ {
752
+
753
+ $post_cats[$post_val->post_id][] = $post_val->name;
754
+ }
755
+
756
+ return $post_cats;
757
+ }
758
+
759
+ function getUsersIDs()
760
+ {
761
+ global $wpdb;
762
+ $users_authors=array();
763
+ $users = $wpdb->get_results("SELECT ID as user_id, display_name FROM $wpdb->users WHERE user_status=0");
764
+
765
+ foreach ( $users as $user_key=>$user_val )
766
+ {
767
+ $users_authors[$user_val->user_id] = $user_val->display_name;
768
+ }
769
+
770
+ return $users_authors;
771
+ }
772
+ }
773
+ ?>
backup.class.php CHANGED
@@ -22,18 +22,18 @@ $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',
@@ -596,29 +596,31 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
596
$disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
597
$comp_level = $disable_comp ? '-0' : '-1';
598
$zip = $this->get_zip();
599
//Add database file
600
chdir(IWP_BACKUP_DIR);
601
$command = "$zip -q -r $comp_level $backup_file 'iwp_db'";
602
ob_start();
603
$result = $this->iwp_mmb_exec($command);
604
ob_get_clean();
605
- echo "\n".'DB ZIP CMD';
606
/*zip_backup_db*/
607
608
if(!$result){
609
$zip_archive_db_result = false;
610
if (class_exists("ZipArchive")) {
611
$this->_log("DB zip, fallback to ZipArchive");
612
$zip_archive_db_result = $this->zip_archive_backup_db($task_name, $db_result, $backup_file);
613
- echo "\n".'DB ZIP Archive';
614
}
615
616
if (!$zip_archive_db_result) {
617
- echo "\n".'DB ZIP PCL';
618
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
619
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
620
$archive = new IWPPclZip($backup_file);
621
-
622
if($fail_safe_files && $disable_comp){
623
$result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
624
}
@@ -631,6 +633,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
631
else{
632
$result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
633
}
634
635
@unlink($db_result);
636
@unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
@@ -675,23 +678,21 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
675
$exclude_data .= " $data/*.*";
676
else
677
$exclude_data .= " '$data/*'";
678
-
679
-
680
- } else {
681
if ($sys == 'WIN'){
682
if(file_exists(ABSPATH . $data)){
683
- $exclude_data .= " $data";
684
$exclude_file_data .= " $data";
685
}
686
- } else {
687
- if(file_exists(ABSPATH . $data)){
688
- $exclude_data .= " '$data'";
689
- $exclude_file_data .= " '$data'";
690
- }
691
- }
692
- }
693
- }
694
- }
695
696
if($exclude_file_data){
697
$exclude_file_data = "-x".$exclude_file_data;
@@ -704,7 +705,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
704
$exclude_data .= " $data/*.*";
705
else
706
$exclude_data .= " '$data/*'";
707
- }*///commented for pclzip modifications
708
709
//Include paths by default
710
$add = array(
@@ -737,37 +738,63 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
737
738
$this->update_status($task_name, $this->statuses['files_zip']);
739
chdir(ABSPATH);
740
- ob_start();
741
- $command = "$zip -q -j $comp_level $backup_file .* * $exclude_file_data";
742
$result_f = $this->iwp_mmb_exec($command, false, true);
743
- if (!$result_f || $result_f == 18) { // disregard permissions error, file can't be accessed
744
$command = "$zip -q -r $comp_level $backup_file $include_data $exclude_data";
745
- $result_d = $this->iwp_mmb_exec($command, false, true);
746
if ($result_d && $result_d != 18) {
747
@unlink($backup_file);
748
- if ($result_d > 0 && $result_d < 18)
749
- return array(
750
- 'error' => 'Failed to archive files (' . $zip_errors[$result_d] . ') .'
751
- );
752
- else
753
- return array(
754
- 'error' => 'Failed to archive files.'
755
- );
756
}
757
}
758
- ob_get_clean();
759
- echo "\n".'Files ZIP CMD';
760
- if ($result_f && $result_f != 18) {
761
$zip_archive_result = false;
762
if (class_exists("ZipArchive")) {
763
$this->_log("Files zip fallback to ZipArchive");
764
$zip_archive_result = $this->zip_archive_backup($task_name, $backup_file, $exclude, $include);
765
- echo "\n".'Files ZIP Archive';
766
}
767
768
769
if (!$zip_archive_result) { //Try pclZip
770
- echo "\n".'Files ZIP PCL';
771
if (!isset($archive)) {
772
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
773
//require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
@@ -827,6 +854,8 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
827
$result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_IWP_EXCLUDE, $exclude_data);
828
}
829
830
if (!$result) {
831
@unlink($backup_file);
832
return array(
@@ -960,10 +989,11 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
960
$paths = $this->check_mysql_paths();
961
$brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
962
$command = $brace . $paths['mysqldump'] . $brace . ' --force --host="' . DB_HOST . '" --user="' . DB_USER . '" --password="' . DB_PASSWORD . '" --add-drop-table --skip-lock-tables "' . DB_NAME . '" > ' . $brace . $file . $brace;
963
ob_start();
964
$result = $this->iwp_mmb_exec($command);
965
ob_get_clean();
966
- echo "\n".'DB DUMP CMD';
967
968
if (!$result) { // Fallback to php
969
$result = $this->backup_db_php($file);
@@ -983,7 +1013,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
983
global $wpdb;
984
985
if(empty($GLOBALS['fail_safe_db'])){
986
- echo "\n".'DB DUMP PHP Normal';
987
$fp = fopen( $file, 'w' );
988
if ( !mysql_ping( $wpdb->dbh ) ) {
989
mysql_connect( DB_HOST, DB_USER, DB_PASSWORD );
@@ -1064,9 +1094,11 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
1064
}
1065
fclose( $fp );
1066
unset ($fp);
1067
}
1068
else{
1069
- echo "\n".'DB DUMP PHP Fail-safe';
1070
$tables = $wpdb->get_results('SHOW TABLES', ARRAY_N);
1071
foreach ($tables as $table) {
1072
//drop existing table
@@ -1111,6 +1143,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
1111
unset($rows);
1112
unset($dump_data);
1113
}
1114
}
1115
1116
if (filesize($file) == 0 || !is_file($file)) {
@@ -1126,6 +1159,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
1126
1127
function restore($args)
1128
{
1129
global $wpdb;
1130
if (empty($args)) {
1131
return false;
@@ -1153,13 +1187,8 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
1153
if (isset($task['task_results'][$result_id]['server'])) {
1154
$backup_file = $task['task_results'][$result_id]['server']['file_path'];
1155
$unlink_file = false; //Don't delete file if stored on server
1156
- }
1157
-
1158
- /*
1159
- //IWP Remove starts here//IWP Remove ends here
1160
- */
1161
-
1162
- elseif (isset($task['task_results'][$result_id]['ftp'])) {
1163
$ftp_file = $task['task_results'][$result_id]['ftp'];
1164
$args = $task['task_args']['account_info']['iwp_ftp'];
1165
$args['backup_file'] = $ftp_file;
@@ -1230,9 +1259,10 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1230
1231
} else {
1232
$restore_options = array();
1233
- $restore_options['iwp_client_notifications'] = get_option('iwp_client_notifications');
1234
- $restore_options['iwp_client_pageview_alerts'] = get_option('iwp_client_pageview_alerts');
1235
- $restore_options['iwp_client_user_hit_count'] = get_option('iwp_client_user_hit_count');
1236
}
1237
1238
@@ -1250,6 +1280,7 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1250
$archive = new IWPPclZip($backup_file);
1251
$result = $archive->extract(PCLZIP_OPT_PATH, ABSPATH, PCLZIP_OPT_REPLACE_NEWER);
1252
}
1253
1254
if ($unlink_file) {
1255
@unlink($backup_file);
@@ -1371,15 +1402,25 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1371
//Check for .htaccess permalinks update
1372
$this->replace_htaccess($home);
1373
} else {
1374
-
1375
- //restore client options
1376
- if (is_array($restore_options) && !empty($restore_options)) {
1377
- foreach ($restore_options as $key => $option) {
1378
- update_option($key,$option);
1379
- }
1380
- }
1381
-
1382
- }
1383
1384
return !empty($new_user) ? $new_user : true ;
1385
}
@@ -1416,7 +1457,9 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1416
1417
function restore_db_php($file_name)
1418
{
1419
- global $wpdb;
1420
$current_query = '';
1421
// Read in entire file
1422
$lines = file($file_name);
@@ -1680,7 +1723,7 @@ function ftp_backup($args)
1680
}
1681
} else {
1682
return array(
1683
- 'error' => 'Your server doesn\'t support SFTP',
1684
'partial' => 1
1685
);
1686
}
@@ -2423,7 +2466,7 @@ function get_next_schedules()
2423
}
2424
2425
}
2426
- if (isset($task['account_info']) && is_array($task['account_info'])) { //only if sends from master first time(secure data)
2427
$task['args']['account_info'] = $task['account_info'];
2428
}
2429
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. Please check if this domain\'s account has enough disk space.',
33
'Read or seek error',
34
'zip has nothing to do',
35
'Missing or empty zip file',
36
+ 'Error writing to a file. Please check if this domain\'s account has enough disk space.',
37
'zip was unable to create a file to write to',
38
'bad command line parameters',
39
'no error',
596
$disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
597
$comp_level = $disable_comp ? '-0' : '-1';
598
$zip = $this->get_zip();
599
+ echo "\n".'DB ZIP CMD: Start';
600
//Add database file
601
chdir(IWP_BACKUP_DIR);
602
$command = "$zip -q -r $comp_level $backup_file 'iwp_db'";
603
ob_start();
604
$result = $this->iwp_mmb_exec($command);
605
ob_get_clean();
606
+ echo "\n".'DB ZIP CMD: End';
607
/*zip_backup_db*/
608
609
if(!$result){
610
$zip_archive_db_result = false;
611
if (class_exists("ZipArchive")) {
612
+ echo "\n".'DB ZIP Archive: Start';
613
$this->_log("DB zip, fallback to ZipArchive");
614
$zip_archive_db_result = $this->zip_archive_backup_db($task_name, $db_result, $backup_file);
615
+ echo "\n".'DB ZIP Archive: End';
616
}
617
618
if (!$zip_archive_db_result) {
619
+ echo "\n".'DB ZIP PCL: Start';
620
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
621
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
622
$archive = new IWPPclZip($backup_file);
623
+
624
if($fail_safe_files && $disable_comp){
625
$result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
626
}
633
else{
634
$result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
635
}
636
+ echo "\n".'DB ZIP PCL: End';
637
638
@unlink($db_result);
639
@unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
678
$exclude_data .= " $data/*.*";
679
else
680
$exclude_data .= " '$data/*'";
681
+ }else {
682
if ($sys == 'WIN'){
683
if(file_exists(ABSPATH . $data)){
684
+ $exclude_data .= " $data";
685
$exclude_file_data .= " $data";
686
}
687
+ }else {
688
+ if(file_exists(ABSPATH . $data)){
689
+ $exclude_data .= " '$data'";
690
+ $exclude_file_data .= " '$data'";
691
+ }
692
+ }
693
+ }
694
+ }
695
+ }
696
697
if($exclude_file_data){
698
$exclude_file_data = "-x".$exclude_file_data;
705
$exclude_data .= " $data/*.*";
706
else
707
$exclude_data .= " '$data/*'";
708
+ }*/ //commented for pclzip modifications
709
710
//Include paths by default
711
$add = array(
738
739
$this->update_status($task_name, $this->statuses['files_zip']);
740
chdir(ABSPATH);
741
+
742
+ $do_cmd_zip_alternative = false;
743
+ @copy($backup_file, $backup_file.'_2');
744
+
745
+ echo "\n".'Files ZIP CMD: Start';
746
+ $command = "$zip -q -j $comp_level $backup_file .* * $exclude_file_data";
747
+ ob_start();
748
$result_f = $this->iwp_mmb_exec($command, false, true);
749
+ ob_get_clean();
750
+ if (!$result_f || $result_f == 18) { // disregard permissions error, file can't be accessed
751
$command = "$zip -q -r $comp_level $backup_file $include_data $exclude_data";
752
+ ob_start();
753
+ $result_d = $this->iwp_mmb_exec($command, false, true);
754
+ ob_get_clean();
755
if ($result_d && $result_d != 18) {
756
@unlink($backup_file);
757
+ $do_cmd_zip_alternative = true;
758
+
759
+
760
+ if($result_d > 0 && $result_d < 18){
761
+ //return array(
762
+ // 'error' => 'Failed to archive files (' . $zip_errors[$result_d] . ') .'
763
+ // );
764
+ echo "\n".'Files ZIP CMD: Failed to archive files (' . $zip_errors[$result_d] . ') .';
765
+ }
766
+ else{
767
+ //return array(
768
+ // 'error' => 'Failed to archive files.'
769
+ //);
770
+ echo "\n".'Files ZIP CMD: Failed to archive files.';
771
+ }
772
}
773
}
774
+
775
+ if(!$do_cmd_zip_alternative){//if FILE ZIP CMD successful
776
+ @unlink($backup_file.'_2');
777
+ }
778
+
779
+ echo "\n".'Files ZIP CMD: End';
780
+ if (($result_f && $result_f != 18) || ($do_cmd_zip_alternative)) {
781
+
782
+ if($do_cmd_zip_alternative){
783
+ @copy($backup_file.'_2', $backup_file);
784
+ @unlink($backup_file.'_2');
785
+ }
786
+
787
$zip_archive_result = false;
788
if (class_exists("ZipArchive")) {
789
+ echo "\n".'Files ZIP Archive: Start';
790
$this->_log("Files zip fallback to ZipArchive");
791
$zip_archive_result = $this->zip_archive_backup($task_name, $backup_file, $exclude, $include);
792
+ echo "\n".'Files ZIP Archive: End';
793
}
794
795
796
if (!$zip_archive_result) { //Try pclZip
797
+ echo "\n".'Files ZIP PCL: Start';
798
if (!isset($archive)) {
799
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
800
//require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
854
$result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_IWP_EXCLUDE, $exclude_data);
855
}
856
857
+ echo "\n".'Files ZIP PCL: End';
858
+
859
if (!$result) {
860
@unlink($backup_file);
861
return array(
989
$paths = $this->check_mysql_paths();
990
$brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
991
$command = $brace . $paths['mysqldump'] . $brace . ' --force --host="' . DB_HOST . '" --user="' . DB_USER . '" --password="' . DB_PASSWORD . '" --add-drop-table --skip-lock-tables "' . DB_NAME . '" > ' . $brace . $file . $brace;
992
+ echo "\n".'DB DUMP CMD: Start';
993
ob_start();
994
$result = $this->iwp_mmb_exec($command);
995
ob_get_clean();
996
+ echo "\n".'DB DUMP CMD: End';
997
998
if (!$result) { // Fallback to php
999
$result = $this->backup_db_php($file);
1013
global $wpdb;
1014
1015
if(empty($GLOBALS['fail_safe_db'])){
1016
+ echo "\n".'DB DUMP PHP Normal: Start';
1017
$fp = fopen( $file, 'w' );
1018
if ( !mysql_ping( $wpdb->dbh ) ) {
1019
mysql_connect( DB_HOST, DB_USER, DB_PASSWORD );
1094
}
1095
fclose( $fp );
1096
unset ($fp);
1097
+ echo "\n".'DB DUMP PHP Normal: End';
1098
}
1099
else{
1100
+ echo "\n".'DB DUMP PHP Fail-safe: Start';
1101
+ file_put_contents($file, '');//safe to reset any old data
1102
$tables = $wpdb->get_results('SHOW TABLES', ARRAY_N);
1103
foreach ($tables as $table) {
1104
//drop existing table
1143
unset($rows);
1144
unset($dump_data);
1145
}
1146
+ echo "\n".'DB DUMP PHP Fail-safe: End';
1147
}
1148
1149
if (filesize($file) == 0 || !is_file($file)) {
1159
1160
function restore($args)
1161
{
1162
+
1163
global $wpdb;
1164
if (empty($args)) {
1165
return false;
1187
if (isset($task['task_results'][$result_id]['server'])) {
1188
$backup_file = $task['task_results'][$result_id]['server']['file_path'];
1189
$unlink_file = false; //Don't delete file if stored on server
1190
+
1191
+ } elseif (isset($task['task_results'][$result_id]['ftp'])) {
1192
$ftp_file = $task['task_results'][$result_id]['ftp'];
1193
$args = $task['task_args']['account_info']['iwp_ftp'];
1194
$args['backup_file'] = $ftp_file;
1259
1260
} else {
1261
$restore_options = array();
1262
+ $restore_options['iwp_client_notifications'] = serialize(get_option('iwp_client_notifications'));
1263
+ $restore_options['iwp_client_pageview_alerts'] = serialize(get_option('iwp_client_pageview_alerts'));
1264
+ $restore_options['iwp_client_user_hit_count'] = serialize(get_option('iwp_client_user_hit_count'));
1265
+ $restore_options['iwp_client_backup_tasks'] = serialize(get_option('iwp_client_backup_tasks'));
1266
}
1267
1268
1280
$archive = new IWPPclZip($backup_file);
1281
$result = $archive->extract(PCLZIP_OPT_PATH, ABSPATH, PCLZIP_OPT_REPLACE_NEWER);
1282
}
1283
+ $this->wpdb_reconnect();
1284
1285
if ($unlink_file) {
1286
@unlink($backup_file);
1402
//Check for .htaccess permalinks update
1403
$this->replace_htaccess($home);
1404
} else {
1405
+ //restore client options
1406
+ if (is_array($restore_options) && !empty($restore_options)) {
1407
+ foreach ($restore_options as $key => $option) {
1408
+ if (!empty($key)) {
1409
+ $query = "SELECT option_value FROM " . $wpdb->base_prefix . "options WHERE option_name = %s";
1410
+ $res = $wpdb->get_var($wpdb->prepare($query, $key));
1411
+ if ($res == false) {
1412
+ $query = "INSERT INTO " . $wpdb->base_prefix . "options (option_value,option_name) VALUES(%s,%s)";
1413
+ $wpdb->query($wpdb->prepare($query, $option, $key));
1414
+ } else {
1415
+ $query = "UPDATE " . $wpdb->base_prefix . "options SET option_value = %s WHERE option_name = %s";
1416
+ $wpdb->query($wpdb->prepare($query, $option, $key));
1417
+ }
1418
+ }
1419
+
1420
+ /*$test = update_option($key,$option);*/
1421
+ }
1422
+ }
1423
+ }
1424
1425
return !empty($new_user) ? $new_user : true ;
1426
}
1457
1458
function restore_db_php($file_name)
1459
{
1460
+
1461
+ $this->wpdb_reconnect();
1462
+ global $wpdb;
1463
$current_query = '';
1464
// Read in entire file
1465
$lines = file($file_name);
1723
}
1724
} else {
1725
return array(
1726
+ 'error' => 'Your server doesn\'t support FTP SSL',
1727
'partial' => 1
1728
);
1729
}
2466
}
2467
2468
}
2469
+ if (isset($task['account_info']) && is_array($task['account_info'])) { //only if sends from panel first time(secure data)
2470
$task['args']['account_info'] = $task['account_info'];
2471
}
2472
core.class.php CHANGED
@@ -1,712 +1,746 @@
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
-
39
- var $backup_repository_instance;
40
-
41
- private $action_call;
42
- private $action_params;
43
- private $iwp_mmb_pre_init_actions;
44
- private $iwp_mmb_pre_init_filters;
45
- private $iwp_mmb_init_actions;
46
-
47
-
48
- function __construct()
49
- {
50
- global $iwp_mmb_plugin_dir, $wpmu_version, $blog_id, $_iwp_mmb_plugin_actions, $_iwp_mmb_item_filter;
51
-
52
- $_iwp_mmb_plugin_actions = array();
53
- $this->name = 'Manage Multiple Blogs';
54
- $this->slug = 'manage-multiple-blogs';
55
- $this->action_call = null;
56
- $this->action_params = null;
57
-
58
-
59
- $this->settings = get_option($this->slug);
60
- if (!$this->settings) {
61
- $this->settings = array(
62
- 'blogs' => array(),
63
- 'current_blog' => array(
64
- 'type' => null
65
- )
66
- );
67
- $this->save_options();
68
- }
69
- if ( function_exists('is_multisite') ) {
70
- if ( is_multisite() ) {
71
- $this->iwp_mmb_multisite = $blog_id;
72
- $this->network_admin_install = get_option('iwp_client_network_admin_install');
73
- }
74
- } else if (!empty($wpmu_version)) {
75
- $this->iwp_mmb_multisite = $blog_id;
76
- $this->network_admin_install = get_option('iwp_client_network_admin_install');
77
- } else {
78
- $this->iwp_mmb_multisite = false;
79
- $this->network_admin_install = null;
80
- }
81
-
82
- // admin notices
83
- if ( !get_option('iwp_client_public_key') ){
84
- if( $this->iwp_mmb_multisite ){
85
- if( is_network_admin() && $this->network_admin_install == '1'){
86
- add_action('network_admin_notices', array( &$this, 'network_admin_notice' ));
87
- } else if( $this->network_admin_install != '1' ){
88
- //$parent_key = $this->get_parent_blog_option('iwp_client_public_key');//IWP commented to show notice to all subsites of network
89
- //if(empty($parent_key))//IWP commented to show notice to all subsites of network
90
- add_action('admin_notices', array( &$this, 'admin_notice' ));
91
- }
92
- } else {
93
- add_action('admin_notices', array( &$this, 'admin_notice' ));
94
- }
95
- }
96
-
97
- // default filters
98
- //$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
99
- $this->iwp_mmb_pre_init_filters['get_stats']['iwp_mmb_stats_filter'][] = 'iwp_mmb_pre_init_stats';
100
-
101
- $_iwp_mmb_item_filter['pre_init_stats'] = array( 'core_update', 'hit_counter', 'comments', 'backups', 'posts', 'drafts', 'scheduled' );
102
- $_iwp_mmb_item_filter['get'] = array( 'updates', 'errors' );
103
-
104
- $this->iwp_mmb_pre_init_actions = array(
105
- 'backup_req' => 'iwp_mmb_get_backup_req',
106
- );
107
-
108
- $this->iwp_mmb_init_actions = array(
109
- 'do_upgrade' => 'iwp_mmb_do_upgrade',
110
- 'get_stats' => 'iwp_mmb_stats_get',
111
- 'remove_site' => 'iwp_mmb_remove_site',
112
- 'backup_clone' => 'iwp_mmb_backup_now',
113
- 'restore' => 'iwp_mmb_restore_now',
114
- 'optimize_tables' => 'iwp_mmb_optimize_tables',
115
- 'check_wp_version' => 'iwp_mmb_wp_checkversion',
116
- 'create_post' => 'iwp_mmb_post_create',
117
- 'update_client' => 'iwp_mmb_update_client_plugin',
118
- 'change_comment_status' => 'iwp_mmb_change_comment_status',
119
- 'change_post_status' => 'iwp_mmb_change_post_status',
120
- 'get_comment_stats' => 'iwp_mmb_comment_stats_get',
121
- 'install_addon' => 'iwp_mmb_install_addon',
122
- 'add_link' => 'iwp_mmb_add_link',
123
- 'add_user' => 'iwp_mmb_add_user',
124
- 'email_backup' => 'iwp_mmb_email_backup',
125
- 'check_backup_compat' => 'iwp_mmb_check_backup_compat',
126
- 'scheduled_backup' => 'iwp_mmb_scheduled_backup',
127
- 'run_task' => 'iwp_mmb_run_task_now',
128
- 'delete_schedule_task' => 'iwp_mmb_delete_task_now',
129
- 'execute_php_code' => 'iwp_mmb_execute_php_code',
130
- 'delete_backup' => 'mmm_delete_backup',
131
- 'remote_backup_now' => 'iwp_mmb_remote_backup_now',
132
- 'set_notifications' => 'iwp_mmb_set_notifications',
133
- 'clean_orphan_backups' => 'iwp_mmb_clean_orphan_backups',
134
- 'get_users' => 'iwp_mmb_get_users',
135
- 'edit_users' => 'iwp_mmb_edit_users',
136
- 'get_plugins_themes' => 'iwp_mmb_get_plugins_themes',
137
- 'edit_plugins_themes' => 'iwp_mmb_edit_plugins_themes',
138
- 'client_brand' => 'iwp_mmb_client_brand',
139
- 'set_alerts' => 'iwp_mmb_set_alerts',
140
- 'maintenance' => 'iwp_mmb_maintenance_mode',
141
-
142
- 'backup_repository' => 'iwp_mmb_backup_repository'
143
- );
144
-
145
- add_action('rightnow_end', array( &$this, 'add_right_now_info' ));
146
- add_action('admin_init', array(&$this,'admin_actions'));
147
- add_action('init', array( &$this, 'iwp_mmb_remote_action'), 9999);
148
- add_action('setup_theme', 'iwp_mmb_parse_request');
149
- add_action('set_auth_cookie', array( &$this, 'iwp_mmb_set_auth_cookie'));
150
- add_action('set_logged_in_cookie', array( &$this, 'iwp_mmb_set_logged_in_cookie'));
151
-
152
- }
153
-
154
- function iwp_mmb_remote_action(){
155
- if($this->action_call != null){
156
- $params = isset($this->action_params) && $this->action_params != null ? $this->action_params : array();
157
- call_user_func($this->action_call, $params);
158
- }
159
- }
160
-
161
- function register_action_params( $action = false, $params = array() ){
162
-
163
- if(isset($this->iwp_mmb_pre_init_actions[$action]) && function_exists($this->iwp_mmb_pre_init_actions[$action])){
164
- call_user_func($this->iwp_mmb_pre_init_actions[$action], $params);
165
- }
166
-
167
- if(isset($this->iwp_mmb_init_actions[$action]) && function_exists($this->iwp_mmb_init_actions[$action])){
168
- $this->action_call = $this->iwp_mmb_init_actions[$action];
169
- $this->action_params = $params;
170
-
171
- if( isset($this->iwp_mmb_pre_init_filters[$action]) && !empty($this->iwp_mmb_pre_init_filters[$action])){
172
- global $iwp_mmb_filters;
173
-
174
- foreach($this->iwp_mmb_pre_init_filters[$action] as $_name => $_functions){
175
- if(!empty($_functions)){
176
- $data = array();
177
-
178
- foreach($_functions as $_k => $_callback){
179
- if(is_array($_callback) && method_exists($_callback[0], $_callback[1]) ){
180
- $data = call_user_func( $_callback, $params );
181
- } elseif (is_string($_callback) && function_exists( $_callback )){
182
- $data = call_user_func( $_callback, $params );
183
- }
184
- $iwp_mmb_filters[$_name] = isset($iwp_mmb_filters[$_name]) && !empty($iwp_mmb_filters[$_name]) ? array_merge($iwp_mmb_filters[$_name], $data) : $data;
185
- add_filter( $_name, create_function( '$a' , 'global $iwp_mmb_filters; return array_merge($a, $iwp_mmb_filters["'.$_name.'"]);') );
186
- }
187
- }
188
-
189
- }
190
- }
191
- return true;
192
- }
193
- return false;
194
- }
195
-
196
- /**
197
- * Add notice to network admin dashboard for security reasons
198
- *
199
- */
200
- function network_admin_notice()
201
- {
202
- echo '<div class="error" style="text-align: center;"><p style="font-size: 14px; font-weight: bold; color:#c00;">Attention !</p>
203
- <p>The InfiniteWP client plugin has to be activated on individual sites. Kindly deactivate the plugin from the network admin dashboard and activate them from the individual dashboards.</p></div>';
204
- }
205
-
206
-
207
- /**
208
- * Add notice to admin dashboard for security reasons
209
- *
210
- */
211
- function admin_notice()
212
- {
213
- /* IWP */
214
- if(defined('MULTISITE') && MULTISITE == true){
215
- global $blog_id;
216
- $user_id_from_email = get_user_id_from_string( get_blog_option($blog_id, 'admin_email'));
217
- $details = get_userdata($user_id_from_email);
218
- $username = $details->user_login;
219
- }
220
- else{
221
- $current_user = wp_get_current_user();
222
- $username = $current_user->data->user_login;
223
- }
224
-
225
- $iwp_client_activate_key = get_option('iwp_client_activate_key');
226
-
227
- 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>
228
- <table border="0" align="center">';
229
- if(!empty($iwp_client_activate_key)){
230
- echo '<tr><td align="right">WEBSITE URL:</td><td align="left"><strong>'.get_option('home').'/</strong></td></tr>
231
- <tr><td align="right">ADMIN USERNAME:</td><td align="left"><strong>'.$username.'</strong> (or any admin id)</td></tr>
232
- <tr><td align="right">ACTIVATION KEY:</td><td align="left"><strong>'.$iwp_client_activate_key.'</strong></td></tr>';
233
- }
234
- else{
235
- echo '<tr><td align="center">Please deactivate and then activate InfiniteWP Client plugin.</td></tr>';
236
- }
237
-
238
- echo '</table>
239
- </p></div>';
240
-
241
- }
242
-
243
- /**
244
- * Add an item into the Right Now Dashboard widget
245
- * to inform that the blog can be managed remotely
246
- *
247
- */
248
- function add_right_now_info()
249
- {
250
- echo '<div class="iwp_mmb-slave-info">
251
- <p>This site can be managed remotely.</p>
252
- </div>';
253
- }
254
-
255
- /**
256
- * Get parent blog options
257
- *
258
- */
259
- private function get_parent_blog_option( $option_name = '' )
260
- {
261
- global $wpdb;
262
- $option = $wpdb->get_var( $wpdb->prepare( "SELECT `option_value` FROM {$wpdb->base_prefix}options WHERE option_name = %s LIMIT 1", $option_name ) );
263
- return $option;
264
- }
265
-
266
- /**
267
- * Gets an instance of the Comment class
268
- *
269
- */
270
- function get_comment_instance()
271
- {
272
- if (!isset($this->comment_instance)) {
273
- $this->comment_instance = new IWP_MMB_Comment();
274
- }
275
-
276
- return $this->comment_instance;
277
- }
278
-
279
- /**
280
- * Gets an instance of the Plugin class
281
- *
282
- */
283
- function get_plugin_instance()
284
- {
285
- if (!isset($this->plugin_instance)) {
286
- $this->plugin_instance = new IWP_MMB_Plugin();
287
- }
288
-
289
- return $this->plugin_instance;
290
- }
291
-
292
- /**
293
- * Gets an instance of the Theme class
294
- *
295
- */
296
- function get_theme_instance()
297
- {
298
- if (!isset($this->theme_instance)) {
299
- $this->theme_instance = new IWP_MMB_Theme();
300
- }
301
-
302
- return $this->theme_instance;
303
- }
304
-
305
-
306
- /**
307
- * Gets an instance of IWP_MMB_Post class
308
- *
309
- */
310
- function get_post_instance()
311
- {
312
- if (!isset($this->post_instance)) {
313
- $this->post_instance = new IWP_MMB_Post();
314
- }
315
-
316
- return $this->post_instance;
317
- }
318
-
319
- /**
320
- * Gets an instance of Blogroll class
321
- *
322
- */
323
- function get_blogroll_instance()
324
- {
325
- if (!isset($this->blogroll_instance)) {
326
- $this->blogroll_instance = new IWP_MMB_Blogroll();
327
- }
328
-
329
- return $this->blogroll_instance;
330
- }
331
-
332
-
333
-
334
- /**
335
- * Gets an instance of the WP class
336
- *
337
- */
338
- function get_wp_instance()
339
- {
340
- if (!isset($this->wp_instance)) {
341
- $this->wp_instance = new IWP_MMB_WP();
342
- }
343
-
344
- return $this->wp_instance;
345
- }
346
-
347
- /**
348
- * Gets an instance of User
349
- *
350
- */
351
- function get_user_instance()
352
- {
353
- if (!isset($this->user_instance)) {
354
- $this->user_instance = new IWP_MMB_User();
355
- }
356
-
357
- return $this->user_instance;
358
- }
359
-
360
- /**
361
- * Gets an instance of stats class
362
- *
363
- */
364
- function get_stats_instance()
365
- {
366
- if (!isset($this->stats_instance)) {
367
- $this->stats_instance = new IWP_MMB_Stats();
368
- }
369
- return $this->stats_instance;
370
- }
371
- /**
372
- * Gets an instance of search class
373
- *
374
- */
375
- function get_search_instance()
376
- {
377
- if (!isset($this->search_instance)) {
378
- $this->search_instance = new IWP_MMB_Search();
379
- }
380
- //return $this->search_instance;
381
- return $this->search_instance;
382
- }
383
- /**
384
- * Gets an instance of stats class
385
- *
386
- */
387
- function get_backup_instance()
388
- {
389
- if (!isset($this->backup_instance)) {
390
- $this->backup_instance = new IWP_MMB_Backup();
391
- }
392
-
393
- return $this->backup_instance;
394
- }
395
-
396
- function get_backup_repository_instance()
397
- {
398
- if (!isset($this->backup_repository_instance)) {
399
- $this->backup_repository_instance = new IWP_MMB_Backup_Repository();
400
- }
401
-
402
- return $this->backup_repository_instance;
403
- }
404
-
405
- /**
406
- * Gets an instance of links class
407
- *
408
- */
409
- function get_link_instance()
410
- {
411
- if (!isset($this->link_instance)) {
412
- $this->link_instance = new IWP_MMB_Link();
413
- }
414
-
415
- return $this->link_instance;
416
- }
417
-
418
- function get_installer_instance()
419
- {
420
- if (!isset($this->installer_instance)) {
421
- $this->installer_instance = new IWP_MMB_Installer();
422
- }
423
- return $this->installer_instance;
424
- }
425
-
426
- /**
427
- * Plugin install callback function
428
- * Check PHP version
429
- */
430
- function install() {
431
-
432
- global $wpdb, $_wp_using_ext_object_cache, $current_user;
433
- $_wp_using_ext_object_cache = false;
434
-
435
- //delete plugin options, just in case
436
- if ($this->iwp_mmb_multisite != false) {
437
- $network_blogs = $wpdb->get_results("select `blog_id`, `site_id` from `{$wpdb->blogs}`");
438
- if(!empty($network_blogs)){
439
- if( is_network_admin() ){
440
- update_option('iwp_client_network_admin_install', 1);
441
- foreach($network_blogs as $details){
442
- if($details->site_id == $details->blog_id)
443
- update_blog_option($details->blog_id, 'iwp_client_network_admin_install', 1);
444
- else
445
- update_blog_option($details->blog_id, 'iwp_client_network_admin_install', -1);
446
-
447
- delete_blog_option($blog_id, 'iwp_client_nossl_key');
448
- delete_blog_option($blog_id, 'iwp_client_public_key');
449
- delete_blog_option($blog_id, 'iwp_client_action_message_id');
450
- }
451
- } else {
452
- update_option('iwp_client_network_admin_install', -1);
453
- delete_option('iwp_client_nossl_key');
454
- delete_option('iwp_client_public_key');
455
- delete_option('iwp_client_action_message_id');
456
- }
457
- }
458
- } else {
459
- delete_option('iwp_client_nossl_key');
460
- delete_option('iwp_client_public_key');
461
- delete_option('iwp_client_action_message_id');
462
- }
463
-
464
- //delete_option('iwp_client_backup_tasks');
465
- delete_option('iwp_client_notifications');
466
- delete_option('iwp_client_brand');
467
- delete_option('iwp_client_pageview_alerts');
468
-
469
- add_option('iwp_client_activate_key', sha1( rand(1, 99999). uniqid('', true) . get_option('siteurl') ) );
470
-
471
- }
472
-
473
- /**
474
- * Saves the (modified) options into the database
475
- *
476
- */
477
- function save_options()
478
- {
479
- if (get_option($this->slug)) {
480
- update_option($this->slug, $this->settings);
481
- } else {
482
- add_option($this->slug, $this->settings);
483
- }
484
- }
485
-
486
- /**
487
- * Deletes options for communication with IWP Admin panel
488
- *
489
- */
490
- function uninstall( $deactivate = false )
491
- {
492
- global $current_user, $wpdb, $_wp_using_ext_object_cache;
493
- $_wp_using_ext_object_cache = false;
494
-
495
- if ($this->iwp_mmb_multisite != false) {
496
- $network_blogs = $wpdb->get_col("select `blog_id` from `{$wpdb->blogs}`");
497
- if(!empty($network_blogs)){
498
- if( is_network_admin() ){
499
- if( $deactivate ) {
500
- delete_option('iwp_client_network_admin_install');
501
- foreach($network_blogs as $blog_id){
502
- delete_blog_option($blog_id, 'iwp_client_network_admin_install');
503
- delete_blog_option($blog_id, 'iwp_client_nossl_key');
504
- delete_blog_option($blog_id, 'iwp_client_public_key');
505
- delete_blog_option($blog_id, 'iwp_client_action_message_id');
506
- delete_blog_option($blog_id, 'iwp_client_maintenace_mode');
507
- }
508
- }
509
- } else {
510
- if( $deactivate )
511
- delete_option('iwp_client_network_admin_install');
512
-
513
- delete_option('iwp_client_nossl_key');
514
- delete_option('iwp_client_public_key');
515
- delete_option('iwp_client_action_message_id');
516
- }
517
- }
518
- } else {
519
- delete_option('iwp_client_nossl_key');
520
- delete_option('iwp_client_public_key');
521
- delete_option('iwp_client_action_message_id');
522
- }
523
-
524
- //Delete options
525
- delete_option('iwp_client_maintenace_mode');
526
- //delete_option('iwp_client_backup_tasks');
527
- wp_clear_scheduled_hook('iwp_client_backup_tasks');
528
- delete_option('iwp_client_notifications');
529
- wp_clear_scheduled_hook('iwp_client_notifications');
530
- delete_option('iwp_client_brand');
531
- delete_option('iwp_client_pageview_alerts');
532
-
533
- delete_option('iwp_client_activate_key');
534
- }
535
-
536
-
537
- /**
538
- * Constructs a url (for ajax purpose)
539
- *
540
- * @param mixed $base_page
541
- */
542
- function construct_url($params = array(), $base_page = 'index.php')
543
- {
544
- $url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
545
- foreach ($params as $key => $value) {
546
- $url .= "&$key=$value";
547