| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) exit; |
| 4 |
if (!class_exists('BVMiscCallback')) : |
| 5 |
|
| 6 |
class BVMiscCallback extends BVCallbackBase { |
| 7 |
public $settings; |
| 8 |
public $bvinfo; |
| 9 |
public $siteinfo; |
| 10 |
public $account; |
| 11 |
public $bvapi; |
| 12 |
public $db; |
| 13 |
|
| 14 |
const MISC_WING_VERSION = 1.2; |
| 15 |
|
| 16 |
public function __construct($callback_handler) { |
| 17 |
$this->settings = $callback_handler->settings; |
| 18 |
$this->siteinfo = $callback_handler->siteinfo; |
| 19 |
$this->account = $callback_handler->account; |
| 20 |
$this->db = $callback_handler->db; |
| 21 |
$this->bvinfo = new WPRInfo($callback_handler->settings); |
| 22 |
$this->bvapi = new WPRWPAPI($callback_handler->settings); |
| 23 |
} |
| 24 |
|
| 25 |
public function refreshPluginUpdates() { |
| 26 |
global $wp_current_filter; |
| 27 |
$wp_current_filter[] = 'load-update-core.php'; |
| 28 |
|
| 29 |
wp_update_plugins(); |
| 30 |
|
| 31 |
array_pop($wp_current_filter); |
| 32 |
|
| 33 |
wp_update_plugins(); |
| 34 |
|
| 35 |
return array("wpupdateplugins" => true); |
| 36 |
} |
| 37 |
|
| 38 |
public function refreshThemeUpdates() { |
| 39 |
global $wp_current_filter; |
| 40 |
$wp_current_filter[] = 'load-update-core.php'; |
| 41 |
|
| 42 |
wp_update_themes(); |
| 43 |
|
| 44 |
array_pop($wp_current_filter); |
| 45 |
|
| 46 |
wp_update_themes(); |
| 47 |
|
| 48 |
return array("wpupdatethemes" => true); |
| 49 |
} |
| 50 |
|
| 51 |
public function getWingInfo() { |
| 52 |
return array('wing_info' => self::$wing_infos); |
| 53 |
} |
| 54 |
|
| 55 |
public function post_types_data($post_params) { |
| 56 |
$result = array(); |
| 57 |
$get_post_types_args = $post_params['get_post_types_args']; |
| 58 |
$post_types = get_post_types($get_post_types_args); |
| 59 |
$post_types = array_merge($post_types, $post_params['include_post_types']); |
| 60 |
$post_types = array_diff( $post_types, $post_params['exclude_post_types']); |
| 61 |
$result['post_types'] = $post_types; |
| 62 |
$post_types = esc_sql($post_types); |
| 63 |
$post_types = "'" . implode("','", $post_types) . "'"; |
| 64 |
$post_table = $post_params['table']; |
| 65 |
$post_select_columns = implode(", ", $post_params['select_column']); |
| 66 |
$post_query = "SELECT MAX(ID) as $post_select_columns FROM ( SELECT |
| 67 |
$post_select_columns FROM $post_table WHERE post_type IN ( $post_types ) |
| 68 |
AND post_status='publish' ORDER BY post_date DESC ) AS posts GROUP BY post_type"; |
| 69 |
$posts = $this->db->getResult($post_query); |
| 70 |
foreach ( $posts as $key => $post ) { |
| 71 |
$posts[$key]['url'] = get_permalink($post['ID']); |
| 72 |
} |
| 73 |
$result['posts'] = $posts; |
| 74 |
return $result; |
| 75 |
} |
| 76 |
|
| 77 |
public function taxonomy_data($taxonomy_params) { |
| 78 |
$result = array(); |
| 79 |
$get_taxonomies_args = $taxonomy_params['get_taxonomies_args']; |
| 80 |
$taxonomies = get_taxonomies($get_taxonomies_args); |
| 81 |
$taxonomies = array_diff($taxonomies, $taxonomy_params['exclude_taxonomies']); |
| 82 |
$result['taxonomies'] = $taxonomies; |
| 83 |
$taxonomies = esc_sql( $taxonomies ); |
| 84 |
$taxonomies = "'" . implode( "','", $taxonomies ) . "'"; |
| 85 |
$taxonomy_table = $taxonomy_params['table']; |
| 86 |
$taxonomy_select_columns = implode(", ", $taxonomy_params['select_column']); |
| 87 |
$taxonomy_query = "SELECT MAX( term_id ) AS $taxonomy_select_columns FROM ( |
| 88 |
SELECT $taxonomy_select_columns FROM $taxonomy_table WHERE taxonomy IN ( |
| 89 |
$taxonomies ) AND count > 0) AS taxonomies GROUP BY taxonomy"; |
| 90 |
|
| 91 |
$taxonomies = $this->db->getResult($taxonomy_query); |
| 92 |
foreach($taxonomies as $key => $taxonomy) { |
| 93 |
$taxonomies[$key]['url'] = get_term_link((int)$taxonomy['term_id'], $taxonomy['taxonomy']); |
| 94 |
} |
| 95 |
$result['taxonomy_data'] = $taxonomies; |
| 96 |
return $result; |
| 97 |
} |
| 98 |
|
| 99 |
public function process($request) { |
| 100 |
$bvinfo = $this->bvinfo; |
| 101 |
$settings = $this->settings; |
| 102 |
$params = $request->params; |
| 103 |
switch ($request->method) { |
| 104 |
case "dummyping": |
| 105 |
$resp = array(); |
| 106 |
$resp = array_merge($resp, $this->siteinfo->info()); |
| 107 |
$resp = array_merge($resp, $this->account->info()); |
| 108 |
$resp = array_merge($resp, $this->bvinfo->info()); |
| 109 |
$resp = array_merge($resp, $this->getWingInfo()); |
| 110 |
break; |
| 111 |
case "pngbv": |
| 112 |
$info = array(); |
| 113 |
$this->siteinfo->basic($info); |
| 114 |
$this->bvapi->pingbv('/bvapi/pingbv', $info); |
| 115 |
$resp = array("status" => true); |
| 116 |
break; |
| 117 |
case "enablebadge": |
| 118 |
$option = $bvinfo->badgeinfo; |
| 119 |
$badgeinfo = array(); |
| 120 |
$badgeinfo['badgeurl'] = $params['badgeurl']; |
| 121 |
$badgeinfo['badgeimg'] = $params['badgeimg']; |
| 122 |
$badgeinfo['badgealt'] = $params['badgealt']; |
| 123 |
$settings->updateOption($option, $badgeinfo); |
| 124 |
$resp = array("status" => $settings->getOption($option)); |
| 125 |
break; |
| 126 |
case "disablebadge": |
| 127 |
$option = $bvinfo->badgeinfo; |
| 128 |
$settings->deleteOption($option); |
| 129 |
$resp = array("status" => !$settings->getOption($option)); |
| 130 |
break; |
| 131 |
case "getoption": |
| 132 |
$resp = array('getoption' => $settings->getOption($params['opkey'])); |
| 133 |
break; |
| 134 |
case "setdynplug": |
| 135 |
$settings->updateOption('bvdynplug', $params['dynplug']); |
| 136 |
$resp = array("setdynplug" => $settings->getOption('bvdynplug')); |
| 137 |
break; |
| 138 |
case "unsetdynplug": |
| 139 |
$settings->deleteOption('bvdynplug'); |
| 140 |
$resp = array("unsetdynplug" => $settings->getOption('bvdynplug')); |
| 141 |
break; |
| 142 |
case "wpupplgs": |
| 143 |
$resp = $this->refreshPluginUpdates(); |
| 144 |
break; |
| 145 |
case "wpupthms": |
| 146 |
$resp = $this->refreshThemeUpdates(); |
| 147 |
break; |
| 148 |
case "wpupcre": |
| 149 |
$resp = array("wpupdatecore" => wp_version_check()); |
| 150 |
break; |
| 151 |
case "phpinfo": |
| 152 |
phpinfo(); |
| 153 |
die(); |
| 154 |
break; |
| 155 |
case "wpnonce": |
| 156 |
$resp = array("wpnonce" => wp_create_nonce($params["wpnonce_action"])); |
| 157 |
break; |
| 158 |
case "dlttrsnt": |
| 159 |
$resp = array("dlttrsnt" => $settings->deleteTransient($params['key'])); |
| 160 |
break; |
| 161 |
case "optns": |
| 162 |
$resp = array(); |
| 163 |
|
| 164 |
if (array_key_exists("get_options", $params)) |
| 165 |
$resp["get_options"] = $settings->getOptions($params["get_options"]); |
| 166 |
|
| 167 |
if (array_key_exists("update_options", $params)) |
| 168 |
$resp["update_options"] = $settings->updateOptions($params["update_options"]); |
| 169 |
|
| 170 |
if (array_key_exists("delete_options", $params)) |
| 171 |
$resp["delete_options"] = $settings->deleteOptions($params["delete_options"]); |
| 172 |
|
| 173 |
break; |
| 174 |
case "setbvss": |
| 175 |
$resp = array("status" => $settings->updateOption('bv_site_settings', $params['bv_site_settings'])); |
| 176 |
break; |
| 177 |
case "stsrvcs": |
| 178 |
$resp = array(); |
| 179 |
$deleted_configs = array(); |
| 180 |
$updated_configs = array(); |
| 181 |
if (array_key_exists("configs_to_delete", $params)) { |
| 182 |
foreach($params["configs_to_delete"] as $config_name) { |
| 183 |
$deleted_configs[$config_name] = $settings->deleteOption($config_name); |
| 184 |
} |
| 185 |
} |
| 186 |
if (array_key_exists("configs_to_update", $params)) { |
| 187 |
foreach($params["configs_to_update"] as $config_name => $config_value) { |
| 188 |
$settings->updateOption($config_name, $config_value); |
| 189 |
$updated_configs[$config_name] = $settings->getOption($config_name); |
| 190 |
} |
| 191 |
} |
| 192 |
$resp["updated_configs"] = $updated_configs; |
| 193 |
$resp["deleted_configs"] = $deleted_configs; |
| 194 |
break; |
| 195 |
case "critical_css_data": |
| 196 |
$resp = array(); |
| 197 |
if (array_key_exists('fetch_post_data', $params) && $params['fetch_post_data'] == true) { |
| 198 |
$post_params = $params['post_params']; |
| 199 |
$post_result = $this->post_types_data($post_params); |
| 200 |
$resp['post_cp_results'] = $post_result['posts']; |
| 201 |
$resp['post_types'] = $post_result['post_types']; |
| 202 |
} |
| 203 |
if (array_key_exists('fetch_taxonomy_data', $params) && $params['fetch_taxonomy_data'] == true) { |
| 204 |
$taxonomy_params = $params['taxonomy_params']; |
| 205 |
$taxonomy_result = $this->taxonomy_data($taxonomy_params); |
| 206 |
$resp['taxonomy_cp_results'] = $taxonomy_result['taxonomy_data']; |
| 207 |
$resp['taxonomies'] = $taxonomy_result['taxonomies']; |
| 208 |
} |
| 209 |
break; |
| 210 |
|
| 211 |
case "get_post_ids": |
| 212 |
if (array_key_exists('urls', $params)) { |
| 213 |
$resp = array(); |
| 214 |
foreach ( $params['urls'] as $url ) { |
| 215 |
$resp[$url] = url_to_postid($url); |
| 216 |
} |
| 217 |
} |
| 218 |
break; |
| 219 |
|
| 220 |
case "permalink": |
| 221 |
if (array_key_exists('post_ids', $params)) { |
| 222 |
$resp = array(); |
| 223 |
foreach ( $params['post_ids'] as $id ) { |
| 224 |
$resp[$id]['url'] = get_permalink($id); |
| 225 |
} |
| 226 |
} |
| 227 |
break; |
| 228 |
default: |
| 229 |
$resp = false; |
| 230 |
} |
| 231 |
return $resp; |
| 232 |
} |
| 233 |
} |
| 234 |
endif; |