wpCentral - Version 1.0

Version Description

Download this release

Release Info

Developer softacpriya
Plugin Icon 128x128 wpCentral
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (9) hide show
  1. actions.php +275 -0
  2. file_actions.php +59 -0
  3. get_site_data.php +46 -0
  4. readme.txt +39 -0
  5. verify.php +41 -0
  6. wpc_functions.php +2319 -0
  7. wpc_soft_pclzip.php +1531 -0
  8. wpcentral.php +63 -0
  9. wpcentral_lang.php +31 -0
actions.php ADDED
@@ -0,0 +1,275 @@
1
+ <?php
2
+
3
+ if (!defined('ABSPATH')){
4
+ exit;
5
+ }
6
+
7
+ function wpc_site_actions(){
8
+ global $l, $error, $wp_config;
9
+
10
+ $return = array();
11
+
12
+ $request = wpc_optREQ('request');
13
+
14
+ if(empty($request)){
15
+ $return['error'] = $l['no_req_post'];
16
+ echo json_encode($return);
17
+ die();
18
+ }
19
+
20
+ if($request == 'update_website'){
21
+ $source = urldecode(wpc_optREQ('source'));
22
+
23
+ include_once(ABSPATH.'wp-admin/includes/class-wp-upgrader.php');
24
+ include_once(ABSPATH.'wp-admin/includes/update.php');
25
+ include_once(ABSPATH.'wp-admin/includes/misc.php');
26
+
27
+ global $wp_filesystem;
28
+
29
+ $upgrade_error = array();
30
+
31
+ $wp_upgrader_skin = new WP_Upgrader_Skin();
32
+ $wp_upgrader_skin->done_header = true;
33
+
34
+ $wp_upgrader = new WP_Upgrader($wp_upgrader_skin);
35
+
36
+ $res = $wp_upgrader->fs_connect(array(get_home_path(), WP_CONTENT_DIR));
37
+ if (!$res || is_wp_error($res)){
38
+ $upgrade_error[] = $res;
39
+ }
40
+
41
+ $download = $wp_upgrader->download_package($source);
42
+ if (is_wp_error($download)){
43
+ $upgrade_error[] = $download;
44
+ }
45
+
46
+ $working_dir = $wp_upgrader->unpack_package($download);
47
+ if (is_wp_error($working_dir)){
48
+ $upgrade_error[] = $working_dir;
49
+ }
50
+
51
+ $wp_dir = trailingslashit($wp_filesystem->abspath());
52
+
53
+ if (!$wp_filesystem->copy($working_dir.'/wordpress/wp-admin/includes/update-core.php', $wp_dir.'wp-admin/includes/update-core.php', true)){
54
+ $wp_filesystem->delete($working_dir, true);
55
+
56
+ $upgrade_error[] = $l['copy_fail'];
57
+ }
58
+
59
+ $wp_filesystem->chmod($wp_dir.'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
60
+ include_once(get_home_path().'wp-admin/includes/update-core.php');
61
+
62
+ if(!function_exists('update_core')){
63
+ $upgrade_error[] = $l['call_update_fail'];
64
+ }
65
+
66
+ $result = update_core($working_dir, $wp_dir);
67
+ if(is_wp_error($result)){
68
+ $upgrade_error[] = $result->get_error_code();
69
+ }
70
+
71
+ if(!empty($upgrade_error)){
72
+ $return['error'] = 'error: '.implode("\n", $upgrade_error);
73
+ }
74
+ }
75
+
76
+ if(wpc_optGET('plugins') || wpc_optGET('plugin')){
77
+ $plugins = urldecode($_REQUEST['plugins']);
78
+ $arr_plugins = explode(',', $plugins);
79
+
80
+ if($request == 'activate'){//Activate
81
+
82
+ $res = wpc_activate_plugin($arr_plugins);
83
+ if(!$res){
84
+ $return['error'] = $l['err_activating_pl'];
85
+ }
86
+ }elseif($request == 'deactivate'){//Deactivate
87
+
88
+ $res = wpc_deactivate_plugin($arr_plugins);
89
+ if(!$res){
90
+ $return['error'] = $l['err_deactivating_pl'];
91
+ }
92
+ }elseif($request == 'delete'){//Deactivate and then Delete
93
+
94
+ $act_res = wpc_deactivate_plugin($arr_plugins);
95
+ if(!$act_res){
96
+ $return['error'] = $l['err_deactivating_del_pl'];
97
+ }
98
+
99
+ $result = delete_plugins($arr_plugins);
100
+ if(is_wp_error($result)) {
101
+ $return['error'] = $result->get_error_message();
102
+ }elseif($result === false) {
103
+ $return['error'] = $l['err_deleting_pl'];
104
+ }
105
+ }elseif($request == 'install'){//Install Plugins
106
+
107
+ $sources = urldecode($_REQUEST['sources']);
108
+ $arr_sources = explode(',', $sources);
109
+
110
+ foreach($arr_plugins as $plk => $plval){
111
+
112
+ //Skip if the plugin is already installed
113
+ if(wpc_is_plugin_installed($plval)){
114
+ continue;
115
+ }
116
+
117
+ $filename = basename(parse_url($arr_sources[$plk], PHP_URL_PATH));
118
+
119
+ $download_dest = $wp_config['uploads_dir'].'/'.$filename;
120
+ $unzip_dest = $wp_config['plugins_root_dir'];
121
+
122
+ wpc_get_web_file($arr_sources[$plk], $download_dest);
123
+
124
+ if(wpc_sfile_exists($download_dest)){
125
+ $res = wpc_unzip($download_dest, $unzip_dest);
126
+ }
127
+
128
+ @wpc_sunlink($download_dest);
129
+
130
+ //Activate the installed plugin
131
+ $all_installed_plugins = wpc_get_plugins();
132
+ $slugs = array_keys($all_installed_plugins);
133
+
134
+ $plugin_slug = '';
135
+ //Fetch slug of the installed plugin
136
+ foreach($slugs as $val){
137
+ if(strpos($val, $plval) !== false){
138
+ $plugin_slug = $val;
139
+ break;
140
+ }
141
+ }
142
+
143
+ wpc_activate_plugin(array($plugin_slug));
144
+ }
145
+
146
+ if(!empty($error)){
147
+ $return['error'] = $error;
148
+ }
149
+ }elseif($request == 'update'){
150
+
151
+ $plugin_name = urldecode(wpc_optREQ('plugin'));
152
+ $download_link = urldecode(wpc_optREQ('source'));
153
+ $site_url = urldecode(wpc_optREQ('siteurl'));
154
+
155
+ $filename = basename(parse_url($download_link, PHP_URL_PATH));
156
+
157
+ $download_dest = $wp_config['uploads_dir'].'/'.$filename;
158
+ $unzip_dest = $wp_config['plugins_root_dir'];
159
+
160
+ wpc_get_web_file($download_link, $download_dest);
161
+
162
+ if(wpc_sfile_exists($download_dest)){
163
+ $res = wpc_unzip($download_dest, $unzip_dest);
164
+ }
165
+
166
+ @wpc_sunlink($download_dest);
167
+
168
+ // Lets visit the installation once to make the changes in the database
169
+ //$resp = wpc_curl_call($site_url, 0, 5);
170
+ $resp = wp_remote_get($site_url);
171
+
172
+ if(!empty($error)){
173
+ $return['error'] = $error;
174
+ }
175
+ }
176
+ }elseif(wpc_optGET('themes') || wpc_optGET('theme')){
177
+
178
+ $themes = urldecode(wpc_optGET('themes'));
179
+ $arr_themes = explode(',', $themes);
180
+
181
+ $active_theme = array_keys(wpc_get_active_theme());
182
+
183
+ //Do not activate/delete the theme if it is active
184
+ foreach($arr_themes as $tk => $tv){
185
+ if($active_theme[0] == $tv){
186
+ unset($arr_themes[$tk]);
187
+ }
188
+ }
189
+
190
+ if($request == 'activate' && count($arr_themes) == 1){//Activate
191
+
192
+ $res = wpc_activate_theme($arr_themes);
193
+ if(!empty($error)){
194
+ $return['error'] = $error;
195
+ }
196
+ if(!$res){
197
+ $return['error'] = $l['err_activating_theme'];
198
+ }
199
+
200
+ }elseif($request == 'delete'){//Delete
201
+
202
+ $res = wpc_delete_theme($arr_themes);
203
+ if(!empty($error)){
204
+ $return['error'] = $error;
205
+ }
206
+ if(!$res){
207
+ $return['error'] = $l['err_deleting_theme'];
208
+ }
209
+
210
+ }elseif($request == 'install'){//Install Themes
211
+
212
+ $sources = urldecode($_REQUEST['sources']);
213
+ $arr_sources = explode(',', $sources);
214
+
215
+ foreach($arr_themes as $thk => $thval){
216
+
217
+ //Skip if the theme is already installed
218
+ if(wpc_is_theme_installed($thval)){
219
+ continue;
220
+ }
221
+
222
+ $filename = basename(parse_url($arr_sources[$thk], PHP_URL_PATH));
223
+
224
+ $download_dest = $wp_config['uploads_dir'].'/'.$filename;
225
+ $unzip_dest = $wp_config['themes_root_dir'].'/';
226
+
227
+ wpc_get_web_file($arr_sources[$thk], $download_dest);
228
+
229
+ if(wpc_sfile_exists($download_dest)){
230
+ $res = wpc_unzip($download_dest, $unzip_dest);
231
+ }
232
+
233
+ @wpc_sunlink($download_dest);
234
+ }
235
+
236
+ if(!empty($error)){
237
+ $return['error'] = $error;
238
+ }
239
+ }elseif($request == 'update'){//Update Theme
240
+
241
+ $theme_name = urldecode(wpc_optREQ('theme'));
242
+ $download_link = urldecode(wpc_optREQ('source'));
243
+ $site_url = urldecode(wpc_optREQ('siteurl'));
244
+
245
+ $filename = basename(parse_url($download_link, PHP_URL_PATH));
246
+
247
+ $download_dest = $wp_config['uploads_dir'].'/'.$filename;
248
+ $unzip_dest = $wp_config['themes_root_dir'].'/';
249
+
250
+ wpc_get_web_file($download_link, $download_dest);
251
+
252
+ if(wpc_sfile_exists($download_dest)){
253
+ $res = wpc_unzip($download_dest, $unzip_dest);
254
+ }
255
+
256
+ @wpc_sunlink($download_dest);
257
+
258
+ // Lets visit the installation once to make the changes in the database
259
+ //$resp = wpc_curl_call($site_url, 0, 5);
260
+ $resp = wp_remote_get($site_url);
261
+
262
+ if(!empty($error)){
263
+ $return['error'] = $error;
264
+ }
265
+ }
266
+ }
267
+
268
+ if(empty($return['error'])){
269
+ $return['result'] = 'done';
270
+ }
271
+
272
+ //Using serialize here as all_plugins contains class object which are not json_decoded in Softaculous.
273
+ echo json_encode($return);
274
+
275
+ }
file_actions.php ADDED
@@ -0,0 +1,59 @@
1
+ <?php
2
+
3
+ if (!defined('ABSPATH')){
4
+ exit;
5
+ }
6
+
7
+ function wpc_file_actions(){
8
+ global $error, $l;
9
+
10
+ $return = array();
11
+
12
+ $action = wpc_optREQ('request');
13
+
14
+ if(empty($action)){
15
+ $return['error'] = $l['no_req_post'];
16
+ echo json_encode($return);
17
+ die();
18
+ }
19
+
20
+ if($action == 'put'){
21
+ $filename = urldecode(wpc_optREQ('filename'));
22
+ $putdata = base64_decode(wpc_optREQ('putdata'));
23
+
24
+ $func_response = wpc_put($filename, $putdata);
25
+
26
+ if($func_response){
27
+ $return['done'] = 'done';
28
+ }else{
29
+ $return['error'] = $l['err_exec'];
30
+ }
31
+
32
+ echo json_encode($return);
33
+ die();
34
+ }
35
+
36
+ $args = urldecode(wpc_optREQ('args'));
37
+
38
+ if(function_exists('wpc_'.$action)){
39
+ if(!empty($args)){
40
+ $func_response = call_user_func('wpc_'.$action, $args);
41
+ }else{
42
+ $func_response = call_user_func('wpc_'.$action);
43
+ }
44
+ //$return['func_response'] = $func_response;
45
+
46
+ if($func_response){
47
+ $return['done'] = $l['done'];
48
+ }else{
49
+ $return['error'] = $l['err_exec'];
50
+ }
51
+
52
+ }else{
53
+ $return['error'] = $l['func_not_found'];
54
+ }
55
+
56
+ echo json_encode($return);
57
+
58
+ }
59
+ ?>
get_site_data.php ADDED
@@ -0,0 +1,46 @@
1
+ <?php
2
+
3
+ if (!defined('ABSPATH')){
4
+ exit;
5
+ }
6
+
7
+ function wpc_get_site_data(){
8
+ global $l, $wp_config, $error;
9
+
10
+ $return = array();
11
+
12
+ $type = wpc_optGET('type');
13
+
14
+ $return['wordpress_current_version'] = wpc_version_wp();
15
+
16
+ if($type == 'plugins'){
17
+ $return['active_plugins'] = wpc_get_option('active_plugins');
18
+ $all_plugins = wpc_get_plugins();
19
+
20
+ foreach($all_plugins as $pk => $pv){
21
+ $installed_version = $pv['Version'];
22
+ }
23
+
24
+ $outdated_plugins = wpc_get_outdated_plugins();
25
+
26
+ $outdated_plugins_keys = array_keys($outdated_plugins);
27
+ foreach($all_plugins as $allk => $allv){
28
+ if(in_array($allk, $outdated_plugins_keys)){
29
+ $all_plugins[$allk]['new_version'] = $outdated_plugins[$allk]->new_version;
30
+ }
31
+ }
32
+
33
+ $return['all_plugins'] = $all_plugins;
34
+
35
+ }elseif($type == 'themes'){
36
+
37
+ $return['active_theme'] = array_keys(wpc_get_active_theme());
38
+ $return['all_themes'] = wpc_get_installed_themes();
39
+
40
+ }else{
41
+ $return['error'] = $l['invalid_params'];
42
+ }
43
+
44
+ echo json_encode($return);
45
+
46
+ }
readme.txt ADDED
@@ -0,0 +1,39 @@
1
+ === wpcentral ===
2
+ Contributors: softaculous
3
+ Tags: wpcentral, softaculous, sites, manage sites, backup, plugins, themes, manage wordpress,
4
+ Requires at least: 4.4
5
+ Tested up to: 4.9.8
6
+ Requires PHP: 5.3
7
+ Stable tag: 1.0
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ WPCentral provides a single-login centralized panel where you can manage tons of your WordPress websites efficiently, unitedly as well as singularly.
12
+
13
+ == Description ==
14
+
15
+ If ever you wanted a single panel to manage tons of your Wordpress websites from and save the hassle to login all your website's dashboards separately, you have it here at last. [wpcentral](https://wpcentral.co/ "Manage Multiple WordPress Websites") provides a single panel where you can add infinite number of Wordpress websites for free.
16
+
17
+ Key Features:
18
+
19
+ * Entire data of all your websites can be synced in wpcentral panel so that you may skim through the same without logging in separately. Even if you want to go into detail for any website, you can simply click and you will be logged into the website using the Single Sign On feature.
20
+
21
+ * Should you want to activate/deactivate a plugin/theme on n number of websites, you can achieve this from wpcentral panel using wpcentral plugin. Also, you can install and update the plugins/themes on all the websites in one go.
22
+
23
+ * You can also create Sets of common Plugins and Themes which you want to install on multiple websites together.
24
+
25
+ * If you are worried about loosing your data anytime in the future, we, hereby, resolve all your stress by providing you with the backup feature of your websites. In an unfortunate event, when you loose your website or your website gets corrupted, you can even restore the backup taken previously.
26
+
27
+ * A new WordPress update is out and you are all stressed up to update your websites? No worries, wpcentral helps you achieve the same without the need to go into the dashboard of each website separately.
28
+
29
+ Many more to come! We have a number of other features in our To Do list which we will be adding in the upcoming versions, so stay tuned!
30
+
31
+ Should you have any suggestions to improve wpcentral, want to see some related features in wpcentral to help you in the websites management or if you have any queries, you can open a ticket with us at https://www.softaculous.com/support/open.php.
32
+
33
+ == Installation ==
34
+ 1. Upload the plugin folder to your /wp-content/plugins/ folder
35
+ 2. Activate the plugin through the "Plugins" menu in WordPress.
36
+ 3. You can find the Connection Key by clicking on "View Connection Key" link that appears on the Plugins page.
37
+ 4. Go to [panel.wpcentral.co](https://panel.wpcentral.co/ "Manage Multiple WordPress Websites") and create an account.
38
+ 5. Add your website there by following the steps using the connection key.
39
+ 6. It's Done! You can now start exploring.
verify.php ADDED
@@ -0,0 +1,41 @@
1
+ <?php
2
+
3
+ if (!defined('ABSPATH')){
4
+ exit;
5
+ }
6
+
7
+ function wpc_verify(){
8
+ global $l, $wpdb, $wp_version, $wp_config, $error;
9
+
10
+ $return = array();
11
+
12
+ $site_settings = array();
13
+ $site_settings['ver'] = $wp_version;
14
+ $site_settings['softpath'] = rtrim(get_home_path(), '/');
15
+ $site_settings['siteurl'] = get_option('siteurl');
16
+ $site_settings['adminurl'] = admin_url();
17
+ $site_settings['softdb'] = $wp_config['softdb'];
18
+ $site_settings['softdbuser'] = $wp_config['softdbuser'];
19
+ $site_settings['softdbhost'] = $wp_config['softdbhost'];
20
+ $site_settings['softdbpass'] = $wp_config['softdbpass'];
21
+ $site_settings['dbprefix'] = $wp_config['dbprefix'];
22
+ $site_settings['site_name'] = get_option('blogname');
23
+
24
+ //Fetch all the table names
25
+ $sql = "SHOW TABLES FROM ".$wp_config['softdb'];
26
+ $results = $wpdb->get_results($sql);
27
+
28
+ $site_settings['softdbtables'] = array();
29
+ foreach($results as $index => $value) {
30
+ foreach($value as $tableName) {
31
+ $site_settings['softdbtables'][] = $tableName;
32
+ }
33
+ }
34
+
35
+ $site_settings['backup_directory'] = $wp_config['plugins_root_dir'].'/wp-central/'.wpc_srandstr(64);
36
+
37
+ $return['data'] = $site_settings;
38
+
39
+ echo json_encode($return);
40
+
41
+ }
wpc_functions.php ADDED
@@ -0,0 +1,2319 @@
1
+ <?php
2
+
3
+ if (!defined('ABSPATH')){
4
+ exit;
5
+ }
6
+
7
+ function wpc_died(){
8
+ print_r(error_get_last());
9
+ }
10
+ register_shutdown_function('wpc_died');
11
+
12
+ include_once('wpcentral_lang.php');
13
+
14
+ /*
15
+ * Fetch the value of option name from options table
16
+ *
17
+ * @param string $option_name option_name to retrieve from table.
18
+ * @param mixed $default_value Default value to return when the option does not exist.
19
+ * @param int $site_id Site ID to update. Used for multisite installations only.
20
+ * @param bool $use_cache Whether to use cache or not. Used for multisite installations only.
21
+ * @returns string The option value based on $option_name
22
+ * @since 1.0
23
+ *
24
+ * @refer get_option()
25
+ * @link https://developer.wordpress.org/reference/functions/get_option/
26
+ */
27
+ function wpc_get_option($option_name, $default_value = false, $site_id = null, $use_cache = true){
28
+
29
+ if($site_id !== null && is_multisite()){
30
+ return get_site_option($option_name, $default_value, $use_cache);
31
+ }
32
+ return get_option($option_name, $default_value);
33
+ }
34
+
35
+ /*
36
+ * Generate a random string for the given length
37
+ *
38
+ * @param int $length The number of charactes that should be returned
39
+ * @return string Randomly geterated string of the given number of charaters
40
+ * @since 1.0
41
+ */
42
+ function wpc_srandstr($length){
43
+ $randstr = "";
44
+ for($i = 0; $i < $length; $i++){
45
+ $randnum = mt_rand(0,61);
46
+ if($randnum < 10){
47
+ $randstr .= chr($randnum+48);
48
+ }elseif($randnum < 36){
49
+ $randstr .= chr($randnum+55);
50
+ }else{
51
+ $randstr .= chr($randnum+61);
52
+ }
53
+ }
54
+ return strtolower($randstr);
55
+ }
56
+
57
+ /*
58
+ * A function to display preformatted array. Basically adds the <pre> before and after the print_r() output.
59
+ *
60
+ * @param array $array
61
+ * @return string Best for HTML dump of an array.
62
+ * @since 1.0
63
+ */
64
+ function wpc_print($array){
65
+ echo '<pre>';
66
+ print_r($array);
67
+ echo '</pre>';
68
+ }
69
+
70
+ /**
71
+ * A function to return all the installed plugins and their description.
72
+ *
73
+ * @since 1.0
74
+ */
75
+ function wpc_get_plugins(){
76
+ return get_plugins();
77
+ }
78
+
79
+ /**
80
+ * A function to check if the plugin is active or not.
81
+ *
82
+ * @param string $pluginBasename slug of the plugin
83
+ * @since 1.0
84
+ */
85
+ function wpc_is_plugin_active($pluginBasename){
86
+ return is_plugin_active($pluginBasename);
87
+ }
88
+
89
+ /**
90
+ * A function to check if the plugin is installed.
91
+ *
92
+ * @param string $plslug slug of the plugin
93
+ * @since 1.0
94
+ */
95
+ function wpc_is_plugin_installed($plslug){
96
+
97
+ $all_installed_plugins = wpc_get_plugins();
98
+ $slugs = array_keys($all_installed_plugins);
99
+
100
+ $is_installed = 0;
101
+ foreach($all_installed_plugins as $key => $val){
102
+ if(strpos($key, $plslug) !== false){
103
+ $is_installed = true;
104
+ break;
105
+ }
106
+ }
107
+
108
+ return $is_installed;
109
+ }
110
+
111
+ /**
112
+ * Activates the plugins on the website
113
+ *
114
+ * @param array $plugin_slug array of plugin's slug values
115
+ * @since 1.0
116
+ */
117
+ function wpc_activate_plugin($plugin_slug = array()){
118
+ global $wp_config;
119
+
120
+ $active_plugins = wpc_get_option('active_plugins');
121
+
122
+ // Build final list of selected plugins and activated ones.
123
+ foreach($plugin_slug as $k => $v){
124
+ if(in_array($v, $active_plugins)){
125
+ continue;
126
+ }
127
+
128
+ $active_plugins[] = $v;
129
+ }
130
+
131
+ $res = update_option('active_plugins', $active_plugins);
132
+
133
+ return $res;
134
+ }
135
+
136
+ /**
137
+ * De-activates the plugins on the website
138
+ *
139
+ * @param array $plugin_slug array of plugin's slug values
140
+ * @since 1.0
141
+ */
142
+ function wpc_deactivate_plugin($plugin_slug = array()){
143
+ global $wp_config;
144
+
145
+ $active_plugins = wpc_get_option('active_plugins');
146
+
147
+ // Build final list of selected plugins and activated ones.
148
+ foreach($plugin_slug as $k => $v){
149
+
150
+ if(in_array($v, $active_plugins)){
151
+ continue;
152
+ }
153
+
154
+ $active_plugins[] = $v;
155
+ }
156
+
157
+ foreach($active_plugins as $pk => $pv){
158
+ if(in_array($pv, $plugin_slug)){
159
+ unset($active_plugins[$pk]);
160
+ }
161
+ }
162
+
163
+ $res = update_option('active_plugins', $active_plugins);
164
+
165
+ return $res;
166
+ }
167
+
168
+ /**
169
+ * Fetch the list of outdated plugins on the website
170
+ *
171
+ * @since 1.0
172
+ */
173
+ function wpc_get_outdated_plugins(){
174
+ global $wp_config, $error;
175
+
176
+ // Get the list of active plugins
177
+ $squery = 'SELECT `option_value` FROM `'.$wp_config['dbprefix'].'options` WHERE `option_name` = "active_plugins";';
178
+ $sresult = wpc_sdb_query($squery, $wp_config['softdbhost'], $wp_config['softdbuser'], $wp_config['softdbpass'], $wp_config['softdb']);
179
+
180
+ $active = array();
181
+ $active = unserialize($sresult[0]['option_value']);
182
+
183
+ foreach($active as $plugin_file){
184
+ $plugin_data = array();
185
+ if (!wpc_sfile_exists($wp_config['plugins_root_dir'].'/'.$plugin_file)){
186
+ continue;
187
+ }
188
+
189
+ $plugin_data = wpc_get_plugin_data($wp_config['plugins_root_dir'].'/'.$plugin_file);
190
+
191
+ if(empty($plugin_data['Plugin Name'])){
192
+ continue;
193
+ }else{
194
+ $plugin_data['Name'] = $plugin_data['Plugin Name'];
195
+ }
196
+
197
+ $plugins[$plugin_file] = $plugin_data;
198
+ }
199
+
200
+ uasort($plugins, '_sort_uname_callback');
201
+
202
+ $to_send = (object) compact('plugins', 'active');
203
+ $options = array('plugins' => serialize($to_send));
204
+
205
+ // Check the WordPress API to get the list of outdated plugins
206
+ //$raw_response = wpc_curl_call('http://api.wordpress.org/plugins/update-check/1.0/', 0, 5, $options);
207
+ $raw_response = wp_remote_post('http://api.wordpress.org/plugins/update-check/1.0/', array('body' => $options));
208
+ $body = wp_remote_retrieve_body($raw_response);
209
+ $outdated_plugins = unserialize($body);
210
+
211
+ // We need the Plugin name to send via email
212
+ foreach($outdated_plugins as $plugin_file => $p_data){
213
+ if(!empty($plugins[$plugin_file]['Name'])){
214
+ $outdated_plugins[$plugin_file]->Name = $plugins[$plugin_file]['Name'];
215
+ }
216
+ }
217
+
218
+ return $outdated_plugins;
219
+ }
220
+
221
+ /**
222
+ * This is to extract the plugin details from the plugin file
223
+ *
224
+ * @param string $pluginPath directory path of the installed plugin
225
+ * @since 1.0
226
+ */
227
+ function wpc_get_plugin_data($pluginPath = ''){
228
+ global $plugin_details;
229
+
230
+ $plugin_details = array();
231
+
232
+ if(empty($pluginPath)){
233
+ return false;
234
+ }
235
+
236
+ $tmp_data = array();
237
+ $data = array();
238
+ $data = wpc_sfile($pluginPath);
239
+ preg_replace_callback('/\n(\s*?)(\*?)(\s*?)Plugin(\s*?)Name:(.*?)\n/is', 'wpc_plugin_callback', $data, 1);
240
+ preg_replace_callback('/\n(\s*?)(\*?)(\s*?)Plugin(\s*?)URI:(.*?)\n/is', 'wpc_plugin_callback', $data, 1);
241
+ preg_replace_callback('/\n(\s*?)(\*?)(\s*?)Description:(.*?)\n/is', 'wpc_plugin_callback', $data, 1);
242
+ preg_replace_callback('/\n(\s*?)(\*?)(\s*?)Version:(.*?)\n/is', 'wpc_plugin_callback', $data, 1);
243
+
244
+ return $plugin_details;
245
+ }
246
+
247
+ // This is a callback function for preg_replace in wpc_get_plugin_data
248
+ function wpc_plugin_callback($matches){
249
+ global $plugin_details;
250
+ $tmp_data = explode(':', $matches[0], 2);
251
+ $tmp_data[0] = str_replace('*', '', $tmp_data[0]);
252
+ $key = trim($tmp_data[0]);
253
+ $value = trim($tmp_data[1]);
254
+ $plugin_details[$key] = $value;
255
+ }
256
+
257
+ /**
258
+ * A function to check if the theme is installed.
259
+ *
260
+ * @param string $thslug slug of the theme
261
+ * @since 1.0
262
+ */
263
+ function wpc_is_theme_installed($thslug){
264
+
265
+ $all_installed_themes = wp_get_themes();
266
+ $slugs = array_keys($all_installed_themes);
267
+
268
+ if(isset($all_installed_themes[$thslug])){
269
+ return true;
270
+ }
271
+
272
+ return false;
273
+ }
274
+
275
+ /**
276
+ * Returns active theme for the website.
277
+ *
278
+ * @since 1.0
279
+ */
280
+ function wpc_get_active_theme(){
281
+ $raw_list = wp_get_theme();
282
+ return wpc_get_themes_details(array($raw_list->stylesheet));
283
+ }
284
+
285
+ /**
286
+ * A function to return all the installed themes and their description.
287
+ *
288
+ * @since 1.0
289
+ */
290
+ function wpc_get_installed_themes(){
291
+ $raw_list = wp_get_themes();
292
+ $theme_slugs = array_keys($raw_list);
293
+
294
+ return wpc_get_themes_details($theme_slugs);
295
+ }
296
+
297
+ /**
298
+ * Returns details of the themes from wordPress.org.
299
+ *
300
+ * @param array $themes array of themes
301
+ * @since 1.0
302
+ */
303
+ function wpc_get_themes_details($themes = array()){
304
+ global $wp_config, $error;
305
+
306
+ $apiurl ='http://api.wordpress.org/themes/info/1.0/';
307
+ $theme_details = array();
308
+ foreach($themes as $current_theme){
309
+ $theme_data = wpc_get_theme_data($wp_config['themes_root_dir'].'/'.$current_theme.'/style.css');
310
+
311
+ $post_data = array(
312
+ 'action' => 'theme_information',
313
+ 'request' => serialize( (object) array( 'slug' => $current_theme )));
314
+
315
+ //$api_data = wpc_curl_call($apiurl, 0, 5, $post_data);
316
+ //$api_data = unserialize($api_data);
317
+
318
+ $raw_response = wp_remote_post($apiurl, array('body' => $post_data));
319
+ $body = wp_remote_retrieve_body($raw_response);
320
+ $api_data = unserialize($body);
321
+
322
+ $theme_details[$current_theme] = $api_data;
323
+ $theme_details[$current_theme]->installed_version = $theme_data['Version'];
324
+
325
+ if(wpc_sversion_compare($theme_data['Version'], $api_data->version, '<')){
326
+ $theme_details[$current_theme]->new_version = $api_data->version;
327
+ }
328
+ }
329
+ return $theme_details;
330
+ }
331
+
332
+ /**
333
+ * This is to extract the theme details from the theme file
334
+ *
335
+ * @param string $themePath directory path of the installed theme
336
+ * @since 1.0
337
+ */
338
+ function wpc_get_theme_data($themePath = ''){
339
+
340
+ global $theme_details;
341
+
342
+ $theme_details = array();
343
+
344
+ if(empty($themePath)){
345
+ return false;
346
+ }
347
+
348
+ $tmp_data = array();
349
+ $data = array();
350
+ $data = wpc_sfile($themePath);
351
+ preg_replace_callback('/\n(\s*?)(\*?)(\s*?)Theme(\s*?)Name:(.*?)\n/is', 'wpc_theme_callback', $data, 1);
352
+ preg_replace_callback('/\n(\s*?)(\*?)(\s*?)Theme(\s*?)URI:(.*?)\n/is', 'wpc_theme_callback', $data, 1);
353
+ preg_replace_callback('/\n(\s*?)(\*?)(\s*?)Description:(.*?)\n/is', 'wpc_theme_callback', $data, 1);
354
+ preg_replace_callback('/\n(\s*?)(\*?)(\s*?)Version:(.*?)\n/is', 'wpc_theme_callback', $data, 1);
355
+ preg_replace_callback('/\n(\s*?)(\*?)(\s*?)Author:(.*?)\n/is', 'wpc_theme_callback', $data, 1);
356
+ preg_replace_callback('/\n(\s*?)(\*?)(\s*?)Author(\s*?)URI:(.*?)\n/is', 'wpc_theme_callback', $data, 1);
357
+
358
+ return $theme_details;
359
+ }
360
+
361
+ // This is a callback function for preg_replace used in wpc_get_theme_data
362
+ function wpc_theme_callback($matches){
363
+ global $theme_details;
364
+ $tmp_data = explode(':', $matches[0], 2);
365
+ $tmp_data[0] = str_replace('*', '', $tmp_data[0]);
366
+ $key = trim($tmp_data[0]);
367
+ $value = trim($tmp_data[1]);
368
+ $theme_details[$key] = $value;
369
+ }
370
+
371
+ /**
372
+ * Activates the theme on the website
373
+ *
374
+ * @param string $theme_slug slug of the theme
375
+ * @since 1.0
376
+ */
377
+ function wpc_activate_theme($theme_slug = array()){
378
+ global $error, $l;
379
+
380
+ $theme_root = $wp_config['themes_root_dir'].'/'.$theme_slug[0];
381
+
382
+ $res = switch_theme($theme_root, $theme_slug[0]);
383
+
384
+ if(is_wp_error($res)) {
385
+ $error = $res->get_error_message();
386
+ }elseif($res === false) {
387
+ $error = $l['action_failed'];
388
+ }
389
+
390
+ if(!empty($error)){
391
+ return false;
392
+ }
393
+
394
+ return true;
395
+ }
396
+
397
+ /**
398
+ * Function to delete a theme
399
+ *
400
+ * @param string $theme_slug slug of the theme
401
+ * @since 1.0
402
+ */
403
+ function wpc_delete_theme($theme_slug = array()){
404
+ global $error, $l;
405
+
406
+ foreach($theme_slug as $slug){
407
+ $res = delete_theme($slug);
408
+ }
409
+
410
+ if(is_wp_error($res)) {
411
+ $error = $res->get_error_message();
412
+
413
+ }elseif($res === false) {
414
+ $error = $l['action_failed'];
415
+ }
416
+
417
+ if(!empty($error)){
418
+ return false;
419
+ }
420
+
421
+ return true;
422
+ }
423
+
424
+ /**
425
+ * Takes care of Slashes
426
+ *
427
+ * @param string $string The string that will be processed
428
+ * @return string A string that is safe to use for Database Queries, etc
429
+ * @since 1.0
430
+ */
431
+ function wpc_inputsec($string){
432
+
433
+ if(!get_magic_quotes_gpc()){
434
+
435
+ $string = addslashes($string);
436
+
437
+ }else{
438
+
439
+ $string = stripslashes($string);
440
+ $string = addslashes($string);
441
+
442
+ }
443
+
444
+ // This is to replace ` which can cause the command to be executed in exec()
445
+ $string = str_replace('`', '\`', $string);
446
+
447
+ return $string;
448
+
449
+ }
450
+
451
+ /**
452
+ * Converts Special characters to html entities
453
+ *
454
+ * @param string $string The string containing special characters
455
+ * @return string A string containing special characters replaced by html entities of the format &#ASCIICODE;
456
+ * @since 1.0
457
+ */
458
+ function wpc_htmlizer($string){
459
+
460
+ global $globals;
461
+
462
+ $string = htmlentities($string, ENT_QUOTES, 'UTF-8');
463
+
464
+ preg_match_all('/(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)/', $string, $matches);
465
+
466
+ foreach($matches[1] as $mk => $mv){
467
+ $tmp_m = wpc_entity_check($matches[2][$mk]);
468
+ $string = str_replace($matches[1][$mk], $tmp_m, $string);
469
+ }
470
+
471
+ return $string;
472
+
473
+ }
474
+
475
+ /**
476
+ * Used in function htmlizer()
477
+ *
478
+ * @param string $string
479
+ * @return string
480
+ * @since 1.0
481
+ */
482
+ function wpc_entity_check($string){
483
+
484
+ //Convert Hexadecimal to Decimal
485
+ $num = ((substr($string, 0, 1) === 'x') ? hexdec(substr($string, 1)) : (int) $string);
486
+
487
+ //Squares and Spaces - return nothing
488
+ $string = (($num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num < 0x20) ? '' : '&#'.$num.';');
489
+
490
+ return $string;
491
+
492
+ }
493
+
494
+ /**
495
+ * OPTIONAL REQUEST of the given REQUEST Key
496
+ *
497
+ * @param string $name The key of the $_REQUEST array i.e. the name of the input / textarea text
498
+ * @param string $default The value to return if the $_REQUEST[$name] is NOT SET
499
+ * @return string Returns the string if the REQUEST is there otherwise the default value given.
500
+ * @since 1.0
501
+ */
502
+ function wpc_optREQ($name, $default = ''){
503
+
504
+ global $error;
505
+
506
+ //Check the POSTED NAME was posted
507
+ if(isset($_REQUEST[$name])){
508
+
509
+ return wpc_inputsec(wpc_htmlizer(trim($_REQUEST[$name])));
510
+
511
+ }else{
512
+
513
+ return $default;
514
+
515
+ }
516
+
517
+ }
518
+
519
+ /**
520
+ * OPTIONAL GET of the given GET Key i.e. dont throw a error if not there
521
+ *
522
+ * @param string $name The key of the $_GET array i.e. the name of the input / textarea text
523
+ * @param string $default The value to return if the $_GET[$name] is NOT SET
524
+ * @return string Returns the string if the GET is there otherwise the default value given.
525
+ * @since 1.0
526
+ */
527
+ function wpc_optGET($name, $default = ''){
528
+
529
+ global $error;
530
+
531
+ //Check the GETED NAME was GETed
532
+ if(isset($_GET[$name])){
533
+
534
+ return wpc_inputsec(wpc_htmlizer(trim($_GET[$name])));
535
+
536
+ }else{
537
+
538
+ return $default;
539
+
540
+ }
541
+
542
+ }
543
+
544
+ /**
545
+ * A function to load a file from the net
546
+ *
547
+ * @param string $url The URL to read
548
+ * @param string $writefilename Instead of returning the data save it to the path given
549
+ * @return string The data fetched
550
+ * @since 1.0
551
+ */
552
+ function wpc_get_web_file($url, $writefilename = ''){
553
+
554
+ // Set the curl parameters.
555
+ $ch = curl_init();
556
+ curl_setopt($ch, CURLOPT_URL, $url);
557
+
558
+ // Turn off the server and peer verification (TrustManager Concept).
559
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
560
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
561
+
562
+ // Follow redirects
563
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
564
+
565
+ // UserAgent and Cookies
566
+ curl_setopt($ch, CURLOPT_USERAGENT, 'wpcentral');
567
+
568
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
569
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); // Max time to connect
570
+
571
+ curl_setopt($ch, CURLOPT_TIMEOUT, 5);
572
+
573
+ // Get response from the server.
574
+ $file = curl_exec($ch);
575
+
576
+ $meta = curl_getinfo($ch);
577
+
578
+ curl_close($ch);
579
+
580
+ //Are we to store the file
581
+ if(empty($writefilename)){
582
+ return $file;
583
+
584
+ //Store the file
585
+ }else{
586
+ $fp = @fopen($writefilename, "wb"); //This opens the file
587
+
588
+ //If its opened then proceed
589
+ if($fp){
590
+ if(@fwrite($fp, $file) === FALSE){
591
+ return false;
592
+ //Wrote the file
593
+ }else{
594
+ @fclose($fp);
595
+ return true;
596
+ }
597
+ }
598
+ }
599
+ return false;
600
+ }
601
+
602
+ /**
603
+ * A Function to unzip a ZIP file
604
+ *
605
+ * @param string $file The ZIP File
606
+ * @param string $destination The Final destination where the file will be unzipped
607
+ * @param int $overwrite Whether to Overwrite existing files
608
+ * @param array $include include files of the given pattern
609
+ * @param array $exclude exclude files of the given pattern
610
+ * @return boolean
611
+ * @since 1.0
612
+ */
613
+ function wpc_unzip($file, $destination, $overwrite = 0){
614
+
615
+ include_once('wpc_soft_pclzip.php');
616
+ $archive = new softpclzip($file);
617
+
618
+ $result = $archive->_extract(PCLZIP_OPT_PATH, $destination,
619
+ PCLZIP_CB_PRE_EXTRACT, 'wpc_inc_exc',
620
+ PCLZIP_OPT_REPLACE_NEWER);
621
+
622
+ if($result == 0){
623
+ return false;
624
+ }
625
+ return true;
626
+ }
627
+
628
+ /**
629
+ * Process includes and excludes of function unzip
630
+ *
631
+ * @param $p_event
632
+ * @param $v
633
+ * @return Returns boolean
634
+ * @since 1.0
635
+ */
636
+ function wpc_inc_exc($p_event, &$v){
637
+ return 1;
638
+ }
639
+
640
+ /**
641
+ * Checks if a file is symlink or hardlink
642
+ *
643
+ * @returns bool false if file is a symlink or a hardlink else true
644
+ * @since 1.0
645
+ */
646
+ function wpc_is_safe_file($path){
647
+
648
+ // Is it a symlink ?
649
+ if(is_link($path)) return false;
650
+
651
+ // Is it a file and is a link ?
652
+ $stat = @stat($path);
653
+ if(!is_dir($path) && $stat['nlink'] > 1) return false;
654
+
655
+ return true;
656
+ }
657
+
658
+ /**
659
+ * Read file contents from the DESTINATION. Should be used when an installations file is to be fetched.
660
+ * For local package file, use the PHP file() function. The main usage of sfile is for import or upgrade !
661
+ *
662
+ * @package files
663
+ * @param string $path The path of the file
664
+ * @returns bool
665
+ * @since 1.0
666
+ */
667
+ function wpc_sfile($path){
668
+
669
+ // Is it safe to read this file ?
670
+ if(!wpc_is_safe_file($path)){
671
+ return false;
672
+ }
673
+
674
+ return @implode('', file($path));
675
+ }
676
+
677
+ /**
678
+ * Fetch website's configuration details from the config file
679
+ *
680
+ * @since 1.0
681
+ */
682
+ function wpc_fetch_wp_config(){
683
+
684
+ global $wpdb;
685
+
686
+ $r = array();
687
+
688
+ $r['softdbhost'] = $wpdb->dbhost;
689
+ $r['softdbuser'] = $wpdb->dbuser;
690
+ $r['softdbpass'] = $wpdb->dbpassword;
691
+ $r['softdb'] = $wpdb->dbname;
692
+ $r['dbprefix'] = $wpdb->prefix;
693
+
694
+ $r['ver'] = wpc_version_wp();
695
+
696
+ //No trailing slash
697
+ $updir = wp_upload_dir();
698
+ $r['uploads_dir'] = realpath($updir['basedir']);
699
+ $r['themes_root_dir'] = realpath(get_theme_root());
700
+ $r['plugins_root_dir'] = realpath(plugin_dir_path( __DIR__ ));
701
+
702
+ return $r;
703
+ }
704
+
705
+ /**
706
+ * Fetch website's currently installed version
707
+ *
708
+ * @since 1.0
709
+ */
710
+ function wpc_version_wp(){
711
+
712
+ $file = wpc_sfile(get_home_path().'wp-includes/version.php');
713
+
714
+ if(!empty($file)){
715
+ wpc_soft_preg_replace('/\$wp_version(\s*?)=(\s*?)("|\')(.*?)("|\');/is', $file, $ver, 4);
716
+ }
717
+
718
+ return $ver;
719
+ }
720
+
721
+ /**
722
+ * This function will preg_match the pattern and return the respective values in $var
723
+ *
724
+ * @param $pattern This should be the pattern to be matched
725
+ * @param $file This should have the data to search from
726
+ * @param $var This will be the variable which will have the preg matched data
727
+ * @param $valuenum This should be the no of regular expression to be returned in $var
728
+ * @param $stripslashes 0 or 1 depending upon whether the stripslashes function is to be applied (1) or not (0)
729
+ * @return string Will pass value by reference in $var
730
+ * @since 1.0
731
+ */
732
+ function wpc_soft_preg_replace($pattern, $file, &$var, $valuenum){
733
+ preg_match($pattern, $file, $matches);
734
+ $var = trim($matches[$valuenum]);
735
+ }
736
+
737
+ /**
738
+ * Unserialize a string and also fixes any broken serialized string before unserializing
739
+ *
740
+ * @param string $str
741
+ * @return array Returns an array if successful otherwise false
742
+ * @since 1.0
743
+ */
744
+ function wpc_unserialize($str){
745
+
746
+ $var = @unserialize($str);
747
+
748
+ if(empty($var)){
749
+
750
+ preg_match_all('!s:(\d+):"(.*?)";!s', $str, $matches);
751
+ foreach($matches[2] as $mk => $mv){
752
+ $tmp_str = 's:'.strlen($mv).':"'.$mv.'";';
753
+ $str = str_replace($matches[0][$mk], $tmp_str, $str);
754
+ }
755
+ $var = @unserialize($str);
756
+ }
757
+
758
+ //If it is still empty false
759
+ if($var === false){
760
+ return false;
761
+ }else{
762
+ return $var;
763
+ }
764
+
765
+ }
766
+
767
+ ////////////////////////////////////////////
768
+ // Custom MySQL functions for WPCentral
769
+ ///////////////////////////////////////////
770
+
771
+ /**
772
+ * Connect to mysqli if exists else mysql
773
+ *
774
+ * @param string $host database host to be connected
775
+ * @param string $user db username to be used to connect
776
+ * @param string $pass db password to be used to connect
777
+ * @param string $newlink create a new link (mysql only)
778
+ * @returns string $conn returns resource link on success or FALSE on failure
779
+ * @since 1.0
780
+ */
781
+ function wpc_mysql_connect($host, $user, $pass, $newlink = false){
782
+
783
+ if(extension_loaded('mysqli')){
784
+ //echo 'mysqli';
785
+ //To handle connection if user passes a custom port along with the host as 127.0.0.1:6446.
786
+ //For testing, use port 127.0.0.1 instead of localhost as 127.0.0.1:6446 http://php.net/manual/en/mysqli.construct.php#112328
787
+ $exh = explode(':', $host);
788
+ if(!empty($exh[1])){
789
+ $sconn = @mysqli_connect($exh[0], $user, $pass, '', $exh[1]);
790
+ }else{
791
+ $sconn = @mysqli_connect($host, $user, $pass);
792
+ }
793
+ }else{
794
+ //echo 'mysql';
795
+ $sconn = @mysql_connect($host, $user, $pass, $newlink);
796
+ }
797
+
798
+ return $sconn;
799
+ }
800
+
801
+ /**
802
+ * Set the database character set
803
+ *
804
+ * @param string $conn database connection string
805
+ * @param string $charset character set to convert to
806
+ * @returns bool true if character set is set
807
+ * @since 1.0
808
+ */
809
+ function wpc_mysql_set_charset($conn, $charset){
810
+
811
+ if(extension_loaded('mysqli')){
812
+ //echo 'mysqli';
813
+ $return = @mysqli_set_charset($conn, $charset);
814
+ }else{
815
+ //echo 'mysql';
816
+ $return = @mysql_set_charset($charset, $conn);
817
+ }
818
+
819
+ return $return;
820
+ }
821
+
822
+ /**
823
+ * Selects database mysqli if exists else mysql
824
+ *
825
+ * @param string $db database to be selected
826
+ * @param string $conn Resource Link
827
+ * @returns bool TRUE on success or FALSE on failure
828
+ * @since 1.0
829
+ */
830
+ function wpc_mysql_select_db($db, $conn){
831
+
832
+ if(extension_loaded('mysqli')){
833
+ $return = @mysqli_select_db($conn, $db);
834
+ }else{
835
+ $return = @mysql_select_db($db, $conn);
836
+ }
837
+
838
+ return $return;
839
+ }
840
+
841
+ /**
842
+ * Executes the query mysqli if exists else mysql
843
+ *
844
+ * @param string $db database to be selected
845
+ * @param string $conn Resource Link
846
+ * @returns bool TRUE on success or FALSE on failure
847
+ * @since 1.0
848
+ */
849
+ function wpc_mysql_query($query, $conn){
850
+
851
+ if(extension_loaded('mysqli')){
852
+ $return = @mysqli_query($conn, $query);
853
+ }else{
854
+ $return = @mysql_query($query, $conn);
855
+ }
856
+
857
+ return $return;
858
+ }
859
+
860
+ /**
861
+ * Fetches the result from a result link mysqli if exists else mysql
862
+ *
863
+ * @param string $result result to fetch the data from
864
+ * @returns mixed Returns an array of strings that corresponds to the fetched row, or FALSE if there are no more rows
865
+ * @since 1.0
866
+ */
867
+ function wpc_mysql_fetch_array($result){
868
+
869
+ if(extension_loaded('mysqli')){
870
+ $return = @mysqli_fetch_array($result);
871
+ }else{
872
+ $return = @mysql_fetch_array($result);
873
+ }
874
+
875
+ return $return;
876
+ }
877
+
878
+ /**
879
+ * Fetches the result into associative array from a result link mysqli if exists else mysql
880
+ *
881
+ * @param string $result result to fetch the data from
882
+ * @returns mixed Returns an associative array of strings that corresponds to the fetched row, or FALSE if there are no more rows
883
+ * @since 1.0
884
+ */
885
+ function wpc_mysql_fetch_assoc($result){
886
+
887
+ if(extension_loaded('mysqli')){
888
+ $return = @mysqli_fetch_assoc($result);
889
+ }else{
890
+ $return = @mysql_fetch_assoc($result);
891
+ }
892
+
893
+ return $return;
894
+ }
895
+
896
+ /**
897
+ * Get a result row as an enumerated array mysqli if exists else mysql
898
+ *
899
+ * @param string $result result to fetch the data from
900
+ * @returns mixed returns an array of strings that corresponds to the fetched row or FALSE if there are no more rows
901
+ * @since 1.0
902
+ */
903
+ function wpc_mysql_fetch_row($result){
904
+
905
+ if(extension_loaded('mysqli')){
906
+ $return = @mysqli_fetch_row($result);
907
+ }else{
908
+ $return = @mysql_fetch_row($result);
909
+ }
910
+
911
+ return $return;
912
+ }
913
+
914
+ /**
915
+ * Get column information from a result and return as an object
916
+ *
917
+ * @param string $result result to fetch the data from
918
+ * @param string $field The numerical field offset
919
+ * @returns object Returns the definition of one column of a result set as an object.
920
+ * @since 1.0
921
+ */
922
+ function wpc_mysql_fetch_field($result, $field){
923
+
924
+ if(extension_loaded('mysqli')){
925
+ $return = @mysqli_fetch_field_direct($result, $field);
926
+ }else{
927
+ $return = @mysql_fetch_field($result, $field);
928
+ }
929
+
930
+ return $return;
931
+ }
932
+
933
+ /**
934
+ * Gets the fields meta
935
+ *
936
+ * @param string $result result to fetch the data from
937
+ * @returns object returns object of fields meta
938
+ * @since 1.0
939
+ */
940
+ function wpc_getFieldsMeta($result){
941
+ // Build an associative array for a type look up
942
+
943
+ if(!defined('WPC_MYSQLI_TYPE_VARCHAR')){
944
+ define('WPC_MYSQLI_TYPE_VARCHAR', 15);
945
+ }
946
+
947
+ $typeAr = array();
948
+ $typeAr[MYSQLI_TYPE_DECIMAL] = 'real';
949
+ $typeAr[MYSQLI_TYPE_NEWDECIMAL] = 'real';
950
+ $typeAr[MYSQLI_TYPE_BIT] = 'int';
951
+ $typeAr[MYSQLI_TYPE_TINY] = 'int';
952
+ $typeAr[MYSQLI_TYPE_SHORT] = 'int';
953
+ $typeAr[MYSQLI_TYPE_LONG] = 'int';
954
+ $typeAr[MYSQLI_TYPE_FLOAT] = 'real';
955
+ $typeAr[MYSQLI_TYPE_DOUBLE] = 'real';
956
+ $typeAr[MYSQLI_TYPE_NULL] = 'null';
957
+ $typeAr[MYSQLI_TYPE_TIMESTAMP] = 'timestamp';
958
+ $typeAr[MYSQLI_TYPE_LONGLONG] = 'int';
959
+ $typeAr[MYSQLI_TYPE_INT24] = 'int';
960
+ $typeAr[MYSQLI_TYPE_DATE] = 'date';
961
+ $typeAr[MYSQLI_TYPE_TIME] = 'time';
962
+ $typeAr[MYSQLI_TYPE_DATETIME] = 'datetime';
963
+ $typeAr[MYSQLI_TYPE_YEAR] = 'year';
964
+ $typeAr[MYSQLI_TYPE_NEWDATE] = 'date';
965
+ $typeAr[MYSQLI_TYPE_ENUM] = 'unknown';
966
+ $typeAr[MYSQLI_TYPE_SET] = 'unknown';
967
+ $typeAr[MYSQLI_TYPE_TINY_BLOB] = 'blob';
968
+ $typeAr[MYSQLI_TYPE_MEDIUM_BLOB] = 'blob';
969
+ $typeAr[MYSQLI_TYPE_LONG_BLOB] = 'blob';
970
+ $typeAr[MYSQLI_TYPE_BLOB] = 'blob';
971
+ $typeAr[MYSQLI_TYPE_VAR_STRING] = 'string';
972
+ $typeAr[MYSQLI_TYPE_STRING] = 'string';
973
+ $typeAr[WPC_MYSQLI_TYPE_VARCHAR] = 'string'; // for Drizzle
974
+ // MySQL returns MYSQLI_TYPE_STRING for CHAR
975
+ // and MYSQLI_TYPE_CHAR === MYSQLI_TYPE_TINY
976
+ // so this would override TINYINT and mark all TINYINT as string
977
+ // https://sourceforge.net/p/phpmyadmin/bugs/2205/
978
+ //$typeAr[MYSQLI_TYPE_CHAR] = 'string';
979
+ $typeAr[MYSQLI_TYPE_GEOMETRY] = 'geometry';
980
+ $typeAr[MYSQLI_TYPE_BIT] = 'bit';
981
+
982
+ $fields = mysqli_fetch_fields($result);
983
+
984
+ // this happens sometimes (seen under MySQL 4.0.25)
985
+ if (!is_array($fields)) {
986
+ return false;
987
+ }
988
+
989
+ foreach ($fields as $k => $field) {
990
+ $fields[$k]->_type = $field->type;
991
+ $fields[$k]->type = $typeAr[$field->type];
992
+ $fields[$k]->_flags = $field->flags;
993
+ $fields[$k]->flags = wpc_mysql_field_flags($result, $k);
994
+
995
+ // Enhance the field objects for mysql-extension compatibilty
996
+ //$flags = explode(' ', $fields[$k]->flags);
997
+ //array_unshift($flags, 'dummy');
998
+ $fields[$k]->multiple_key
999
+ = (int) (bool) ($fields[$k]->_flags & MYSQLI_MULTIPLE_KEY_FLAG);
1000
+ $fields[$k]->primary_key
1001
+ = (int) (bool) ($fields[$k]->_flags & MYSQLI_PRI_KEY_FLAG);
1002
+ $fields[$k]->unique_key
1003
+ = (int) (bool) ($fields[$k]->_flags & MYSQLI_UNIQUE_KEY_FLAG);
1004
+ $fields[$k]->not_null
1005
+ = (int) (bool) ($fields[$k]->_flags & MYSQLI_NOT_NULL_FLAG);
1006
+ $fields[$k]->unsigned
1007
+ = (int) (bool) ($fields[$k]->_flags & MYSQLI_UNSIGNED_FLAG);
1008
+ $fields[$k]->zerofill
1009
+ = (int) (bool) ($fields[$k]->_flags & MYSQLI_ZEROFILL_FLAG);
1010
+ $fields[$k]->numeric
1011
+ = (int) (bool) ($fields[$k]->_flags & MYSQLI_NUM_FLAG);
1012
+ $fields[$k]->blob
1013
+ = (int) (bool) ($fields[$k]->_flags & MYSQLI_BLOB_FLAG);
1014
+ }
1015
+ return $fields;
1016
+ }
1017
+
1018
+ /**
1019
+ * Returns the field flags of the field in text format
1020
+ *
1021
+ * @param string $result result to fetch the data from
1022
+ * @param string $field The numerical field offset
1023
+ * @returns string Returns the field flags of the field in text format
1024
+ * @since 1.0
1025
+ */
1026
+ function wpc_mysql_field_flags($result, $i){
1027
+
1028
+ if(!extension_loaded('mysqli')){
1029
+ return mysql_field_flags($result, $i);
1030
+ }
1031
+
1032
+ $f = mysqli_fetch_field_direct($result, $i);
1033
+ $type = $f->type;
1034
+ $charsetnr = $f->charsetnr;
1035
+ $f = $f->flags;
1036
+ $flags = '';
1037
+ if ($f & MYSQLI_UNIQUE_KEY_FLAG) {
1038
+ $flags .= 'unique ';
1039
+ }
1040
+ if ($f & MYSQLI_NUM_FLAG) {
1041
+ $flags .= 'num ';
1042
+ }
1043
+ if ($f & MYSQLI_PART_KEY_FLAG) {
1044
+ $flags .= 'part_key ';
1045
+ }
1046
+ if ($f & MYSQLI_SET_FLAG) {
1047
+ $flags .= 'set ';
1048
+ }
1049
+ if ($f & MYSQLI_TIMESTAMP_FLAG) {
1050
+ $flags .= 'timestamp ';
1051
+ }
1052
+ if ($f & MYSQLI_AUTO_INCREMENT_FLAG) {
1053
+ $flags .= 'auto_increment ';
1054
+ }
1055
+ if ($f & MYSQLI_ENUM_FLAG) {
1056
+ $flags .= 'enum ';
1057
+ }
1058
+ // See http://dev.mysql.com/doc/refman/6.0/en/c-api-datatypes.html:
1059
+ // to determine if a string is binary, we should not use MYSQLI_BINARY_FLAG
1060
+ // but instead the charsetnr member of the MYSQL_FIELD
1061
+ // structure. Watch out: some types like DATE returns 63 in charsetnr
1062
+ // so we have to check also the type.
1063
+ // Unfortunately there is no equivalent in the mysql extension.
1064
+ if (($type == MYSQLI_TYPE_TINY_BLOB || $type == MYSQLI_TYPE_BLOB
1065
+ || $type == MYSQLI_TYPE_MEDIUM_BLOB || $type == MYSQLI_TYPE_LONG_BLOB
1066
+ || $type == MYSQLI_TYPE_VAR_STRING || $type == MYSQLI_TYPE_STRING)
1067
+ && 63 == $charsetnr
1068
+ ) {
1069
+ $flags .= 'binary ';
1070
+ }
1071
+ if ($f & MYSQLI_ZEROFILL_FLAG) {
1072
+ $flags .= 'zerofill ';
1073
+ }
1074
+ if ($f & MYSQLI_UNSIGNED_FLAG) {
1075
+ $flags .= 'unsigned ';
1076
+ }
1077
+ if ($f & MYSQLI_BLOB_FLAG) {
1078
+ $flags .= 'blob ';
1079
+ }
1080
+ if ($f & MYSQLI_MULTIPLE_KEY_FLAG) {
1081
+ $flags .= 'multiple_key ';
1082
+ }
1083
+ if ($f & MYSQLI_UNIQUE_KEY_FLAG) {
1084
+ $flags .= 'unique_key ';
1085
+ }
1086
+ if ($f & MYSQLI_PRI_KEY_FLAG) {
1087
+ $flags .= 'primary_key ';
1088
+ }
1089
+ if ($f & MYSQLI_NOT_NULL_FLAG) {
1090
+ $flags .= 'not_null ';
1091
+ }
1092
+ return trim($flags);
1093
+ }
1094
+
1095
+ /**
1096
+ * Returns the text of the error message from previous MySQL/MySQLi operation
1097
+ *
1098
+ * @param string $conn MySQL/MySQLi connection
1099
+ * @returns string Returns the error text from the last MySQL function
1100
+ * @since 1.0
1101
+ */
1102
+ function wpc_mysql_error($conn){
1103
+
1104
+ if(extension_loaded('mysqli')){
1105
+ $return = @mysqli_error($conn);
1106
+
1107
+ // In mysqli if connection is not made then we will get connection error using the following function.
1108