| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Hooks |
| 4 |
* |
| 5 |
* @package MainWP/Dashboard |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace MainWP\Dashboard; |
| 9 |
|
| 10 |
/** |
| 11 |
* Class MainWP_Hooks |
| 12 |
* |
| 13 |
* @package MainWP\Dashboard |
| 14 |
*/ |
| 15 |
class MainWP_Hooks { |
| 16 |
|
| 17 |
/** |
| 18 |
* MainWP_Hooks constructor. |
| 19 |
* |
| 20 |
* Initialize MainWP_Hooks actions/filters upon creation of the object. |
| 21 |
* |
| 22 |
* @deprecated 4.0.7. Hook deprecation - Please use filter `mainwp_get_error_message` instead of `mainwp_getErrorMessage`. |
| 23 |
*/ |
| 24 |
public function __construct() { |
| 25 |
add_filter( 'mainwp_getspecificdir', array( MainWP_System_Utility::get_class_name(), 'get_mainwp_specific_dir' ), 10, 1 ); |
| 26 |
add_filter( 'mainwp_getmainwpdir', array( &$this, 'hook_get_mainwp_dir' ), 10, 3 ); |
| 27 |
add_filter( 'mainwp_is_multi_user', array( &$this, 'is_multi_user' ) ); |
| 28 |
add_filter( 'mainwp_qq2fileuploader', array( &$this, 'filter_qq2_file_uploader' ), 10, 2 ); |
| 29 |
add_action( 'mainwp_select_sites_box', array( &$this, 'select_sites_box' ), 10, 8 ); |
| 30 |
add_action( 'mainwp_prepareinstallplugintheme', array( MainWP_Install_Bulk::get_class_name(), 'prepare_install' ) ); |
| 31 |
add_action( 'mainwp_performinstallplugintheme', array( MainWP_Install_Bulk::get_class_name(), 'perform_install' ) ); |
| 32 |
add_filter( 'mainwp_getwpfilesystem', array( MainWP_System_Utility::get_class_name(), 'get_wp_file_system' ) ); |
| 33 |
add_filter( 'mainwp_getspecificurl', array( MainWP_System_Utility::get_class_name(), 'get_mainwp_specific_url' ), 10, 1 ); |
| 34 |
add_filter( 'mainwp_getdownloadurl', array( MainWP_System_Utility::get_class_name(), 'get_download_url' ), 10, 2 ); |
| 35 |
add_action( 'mainwp_renderHeader', array( MainWP_UI::get_class_name(), 'render_header' ), 10, 2 ); |
| 36 |
add_action( 'mainwp_renderFooter', array( MainWP_UI::get_class_name(), 'render_footer' ), 10, 0 ); |
| 37 |
|
| 38 |
add_action( 'mainwp_notify_user', array( &$this, 'hook_notify_user' ), 10, 3 ); |
| 39 |
add_action( 'mainwp_activePlugin', array( &$this, 'active_plugin' ), 10, 0 ); |
| 40 |
add_action( 'mainwp_deactivePlugin', array( &$this, 'deactive_plugin' ), 10, 0 ); |
| 41 |
add_action( 'mainwp_upgradePluginTheme', array( &$this, 'upgrade_plugin_theme' ), 10, 0 ); |
| 42 |
add_action( 'mainwp_deletePlugin', array( &$this, 'delete_plugin' ), 10, 0 ); |
| 43 |
add_action( 'mainwp_deleteTheme', array( &$this, 'delete_theme' ), 10, 0 ); |
| 44 |
|
| 45 |
add_filter( 'mainwp_get_user_extension', array( &$this, 'get_user_extension' ) ); |
| 46 |
add_filter( 'mainwp_getwebsitesbyurl', array( &$this, 'get_websites_by_url' ) ); |
| 47 |
add_filter( 'mainwp_getWebsitesByUrl', array( &$this, 'get_websites_by_url' ) ); |
| 48 |
|
| 49 |
/** |
| 50 |
* The mainwp_getErrorMessage filter has been deprecated. |
| 51 |
* |
| 52 |
* @deprecated 4.0.7. Please use filter mainwp_get_error_message. |
| 53 |
*/ |
| 54 |
add_filter( 'mainwp_getErrorMessage', array( &$this, 'get_error_message' ), 10, 2 ); |
| 55 |
add_filter( 'mainwp_get_error_message', array( &$this, 'get_error_message' ), 10, 2 ); |
| 56 |
|
| 57 |
add_filter( 'mainwp_getwebsitesbygroupids', array( &$this, 'hook_get_websites_by_group_ids' ), 10, 2 ); |
| 58 |
|
| 59 |
add_filter( 'mainwp_cache_getcontext', array( &$this, 'cache_getcontext' ) ); |
| 60 |
add_action( 'mainwp_cache_echo_body', array( &$this, 'cache_echo_body' ) ); |
| 61 |
add_action( 'mainwp_cache_init', array( &$this, 'cache_init' ) ); |
| 62 |
add_action( 'mainwp_cache_add_context', array( &$this, 'cache_add_context' ), 10, 2 ); |
| 63 |
add_action( 'mainwp_cache_add_body', array( &$this, 'cache_add_body' ), 10, 2 ); |
| 64 |
|
| 65 |
add_filter( 'mainwp_get_metaboxes_post', array( &$this, 'get_metaboxes_post' ), 10, 0 ); |
| 66 |
add_filter( 'mainwp_getnotificationemail', array( MainWP_System_Utility::get_class_name(), 'get_notification_email' ), 10, 1 ); |
| 67 |
add_filter( 'mainwp_getformatemail', array( &$this, 'get_formated_email' ), 10, 3 ); |
| 68 |
add_filter( 'mainwp-extension-available-check', array( MainWP_Extensions_Handler::get_class_name(), 'is_extension_available' ) ); |
| 69 |
add_action( 'mainp_log_debug', array( &$this, 'mainwp_log_debug' ), 10, 1 ); |
| 70 |
add_action( 'mainp_log_info', array( &$this, 'mainwp_log_info' ), 10, 1 ); |
| 71 |
add_action( 'mainp_log_warning', array( &$this, 'mainwp_log_warning' ), 10, 1 ); |
| 72 |
add_filter( 'mainwp_getactivateextensionnotice', array( &$this, 'get_activate_extension_notice' ), 10, 1 ); |
| 73 |
add_action( 'mainwp_enqueue_meta_boxes_scripts', array( &$this, 'enqueue_meta_boxes_scripts' ), 10, 1 ); |
| 74 |
add_filter( 'mainwp_addsite', array( &$this, 'mainwp_add_site' ), 10, 1 ); |
| 75 |
add_filter( 'mainwp_deletesite', array( &$this, 'hook_delete_site' ), 10, 1 ); |
| 76 |
add_filter( 'mainwp_clonesite', array( &$this, 'filter_clone_site' ), 10, 6 ); |
| 77 |
add_filter( 'mainwp_delete_clonesite', array( &$this, 'filter_delete_clone_site' ), 10, 4 ); |
| 78 |
add_filter( 'mainwp_editsite', array( &$this, 'mainwp_edit_site' ), 10, 1 ); |
| 79 |
add_action( 'mainwp_add_sub_leftmenu', array( &$this, 'hook_add_sub_left_menu' ), 10, 6 ); |
| 80 |
add_filter( 'mainwp_getwebsiteoptions', array( &$this, 'hook_get_site_options' ), 10, 3 ); |
| 81 |
add_filter( 'mainwp_updatewebsiteoptions', array( &$this, 'hook_update_site_options' ), 10, 4 ); |
| 82 |
add_filter( 'mainwp_getwebsitesbyuserid', array( &$this, 'hook_get_websites_by_user_id' ), 10, 5 ); |
| 83 |
|
| 84 |
add_filter( 'mainwp_addgroup', array( MainWP_Extensions_Handler::get_class_name(), 'hook_add_group' ), 10, 3 ); |
| 85 |
add_filter( 'mainwp_getallposts', array( &$this, 'hook_get_all_posts' ), 10, 2 ); |
| 86 |
add_filter( 'mainwp_check_current_user_can', array( &$this, 'hook_current_user_can' ), 10, 3 ); |
| 87 |
add_filter( 'mainwp_escape_response_data', array( &$this, 'hook_escape_response' ), 10, 3 ); |
| 88 |
|
| 89 |
add_action( 'mainwp_secure_request', array( &$this, 'hook_secure_request' ), 10, 2 ); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Method mainwp_log_debug() |
| 94 |
* |
| 95 |
* MainWP debug log. |
| 96 |
* |
| 97 |
* @param string $text Debug text. |
| 98 |
*/ |
| 99 |
public function mainwp_log_debug( $text ) { |
| 100 |
MainWP_Logger::instance()->debug( $text ); |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Method mainwp_log_info() |
| 105 |
* |
| 106 |
* MainWP log info. |
| 107 |
* |
| 108 |
* @param string $text Info Text. |
| 109 |
*/ |
| 110 |
public function mainwp_log_info( $text ) { |
| 111 |
MainWP_Logger::instance()->info( $text ); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Method mainwp_log_warning() |
| 116 |
* |
| 117 |
* MainWP log warning. |
| 118 |
* |
| 119 |
* @param string $text Warning text. |
| 120 |
*/ |
| 121 |
public function mainwp_log_warning( $text ) { |
| 122 |
MainWP_Logger::instance()->warning( $text ); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Method enqueue_meta_boxes_scripts() |
| 127 |
* |
| 128 |
* Enqueue Scripts for all Meta boxes. |
| 129 |
*/ |
| 130 |
public function enqueue_meta_boxes_scripts() { |
| 131 |
MainWP_System::enqueue_postbox_scripts(); |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Method mainwp_add_site() |
| 136 |
* |
| 137 |
* Hook to add Child Site. |
| 138 |
* |
| 139 |
* @since 3.2.2 |
| 140 |
* @param array $params site data fields: url, name, wpadmin, unique_id, groupids, ssl_verify, ssl_version, http_user, http_pass, websiteid - if edit site. |
| 141 |
* |
| 142 |
* @return array $ret data fields: response, siteid. |
| 143 |
*/ |
| 144 |
public function mainwp_add_site( $params ) { |
| 145 |
$ret = array(); |
| 146 |
|
| 147 |
if ( is_array( $params ) ) { |
| 148 |
if ( isset( $params['websiteid'] ) && MainWP_Utility::ctype_digit( $params['websiteid'] ) ) { |
| 149 |
$ret['siteid'] = self::update_wp_site( $params ); |
| 150 |
return $ret; |
| 151 |
} elseif ( isset( $params['url'] ) && isset( $params['wpadmin'] ) ) { |
| 152 |
$website = MainWP_DB::instance()->get_websites_by_url( $params['url'] ); |
| 153 |
list( $message, $error, $site_id ) = MainWP_Manage_Sites_View::add_wp_site( $website, $params ); |
| 154 |
|
| 155 |
if ( '' !== $error ) { |
| 156 |
return array( 'error' => $error ); |
| 157 |
} |
| 158 |
$ret['response'] = $message; |
| 159 |
$ret['siteid'] = $site_id; |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
return $ret; |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* Method hook_delete_site() |
| 168 |
* |
| 169 |
* Hook to delete Child Site. |
| 170 |
* |
| 171 |
* @param bool $site_id Child site ID. |
| 172 |
* |
| 173 |
* @return boolean|array Return false if empty and return array error - Site not found | result - SUCCESS. |
| 174 |
*/ |
| 175 |
public function hook_delete_site( $site_id = false ) { |
| 176 |
|
| 177 |
if ( empty( $site_id ) ) { |
| 178 |
return false; |
| 179 |
} |
| 180 |
|
| 181 |
$sql = MainWP_DB::instance()->get_sql_website_by_id( $site_id ); |
| 182 |
$websites = MainWP_DB::instance()->query( $sql ); |
| 183 |
$site = MainWP_DB::fetch_object( $websites ); |
| 184 |
|
| 185 |
if ( empty( $site ) ) { |
| 186 |
return array( 'error' => __( 'Not found the website', 'mainwp' ) ); |
| 187 |
} |
| 188 |
$hasWPFileSystem = MainWP_System_Utility::get_wp_file_system(); |
| 189 |
|
| 190 |
/** |
| 191 |
* WordPress files system object. |
| 192 |
* |
| 193 |
* @global object |
| 194 |
*/ |
| 195 |
global $wp_filesystem; |
| 196 |
|
| 197 |
if ( $hasWPFileSystem ) { |
| 198 |
$favi = MainWP_DB::instance()->get_website_option( $site, 'favi_icon', '' ); |
| 199 |
if ( ! empty( $favi ) && ( false !== strpos( $favi, 'favi-' . $site->id . '-' ) ) ) { |
| 200 |
$dirs = MainWP_System_Utility::get_icons_dir(); |
| 201 |
if ( $wp_filesystem->exists( $dirs[0] . $favi ) ) { |
| 202 |
$wp_filesystem->delete( $dirs[0] . $favi ); |
| 203 |
} |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
MainWP_DB::instance()->remove_website( $site->id ); |
| 208 |
|
| 209 |
/** This action is documented in pages\page-mainwp-manage-sites-handler.php */ |
| 210 |
do_action( 'mainwp_delete_site', $site ); |
| 211 |
return array( 'result' => 'SUCCESS' ); |
| 212 |
} |
| 213 |
|
| 214 |
/** |
| 215 |
* Method filter_clone_site() |
| 216 |
* |
| 217 |
* Hook to clone site. |
| 218 |
* |
| 219 |
* @since 3.4.4 |
| 220 |
* @param mixed $pluginFile Plugin file. |
| 221 |
* @param mixed $key Key. |
| 222 |
* @param mixed $websiteid Child site ID. |
| 223 |
* @param mixed $cloneid Clone site ID. |
| 224 |
* @param mixed $clone_url Clone site URL. |
| 225 |
* @param bool $force_update Force the update, true|false, Default: false. |
| 226 |
* |
| 227 |
* @return array Site array to clone. |
| 228 |
*/ |
| 229 |
public function filter_clone_site( $pluginFile, $key, $websiteid, $cloneid, $clone_url, $force_update = false ) { |
| 230 |
return MainWP_Extensions_Handler::hook_clone_site( $pluginFile, $key, $websiteid, $cloneid, $clone_url, $force_update ); |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* Method filter_delete_clone_site() |
| 235 |
* |
| 236 |
* Hook to delete cloaned Child Site. |
| 237 |
* |
| 238 |
* @param mixed $pluginFile Plugin file. |
| 239 |
* @param mixed $key Key. |
| 240 |
* @param string $clone_url Clone site URL. |
| 241 |
* @param bool $clone_site_id Clone site ID. |
| 242 |
* |
| 243 |
* @return array Site array to delete. |
| 244 |
*/ |
| 245 |
public function filter_delete_clone_site( $pluginFile, $key, $clone_url = '', $clone_site_id = false ) { |
| 246 |
return MainWP_Extensions_Handler::hook_delete_clone_site( $pluginFile, $key, $clone_url, $clone_site_id ); |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* Method mainwp_edit_site() |
| 251 |
* |
| 252 |
* Hook to edit Child Site. |
| 253 |
* |
| 254 |
* @since 3.2.2 |
| 255 |
* @param array $params site data fields: websiteid, name, wpadmin, unique_id. |
| 256 |
* |
| 257 |
* @return int $ret Child site ID. |
| 258 |
*/ |
| 259 |
public function mainwp_edit_site( $params ) { |
| 260 |
$ret = array(); |
| 261 |
if ( is_array( $params ) ) { |
| 262 |
if ( isset( $params['websiteid'] ) && MainWP_Utility::ctype_digit( $params['websiteid'] ) ) { |
| 263 |
$ret['siteid'] = self::update_wp_site( $params ); |
| 264 |
return $ret; |
| 265 |
} |
| 266 |
} |
| 267 |
return $ret; |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* Method hook_add_sub_left_menu() |
| 272 |
* |
| 273 |
* Hook to add MainWP Left Menu item. |
| 274 |
* |
| 275 |
* @param string $title Menu title. |
| 276 |
* @param string $slug Menu slug. |
| 277 |
* @param string $href Menu link. |
| 278 |
* @param integer $level Menu level. |
| 279 |
* @param string $parent_key Parent menu. |
| 280 |
*/ |
| 281 |
public function hook_add_sub_left_menu( $title, $slug, $href, $level = 1, $parent_key = 'mainwp_tab' ) { |
| 282 |
$item = array( |
| 283 |
'title' => $title, |
| 284 |
'parent_key' => $parent_key, |
| 285 |
'slug' => $slug, |
| 286 |
'href' => $href, |
| 287 |
); |
| 288 |
MainWP_Menu::add_left_menu( $item, $level ); |
| 289 |
} |
| 290 |
|
| 291 |
/** |
| 292 |
* Method update_wp_site() |
| 293 |
* |
| 294 |
* Update Child Site. |
| 295 |
* |
| 296 |
* @param mixed $params Udate parameters. |
| 297 |
* |
| 298 |
* @return int Child Site ID on success and return 0 on failer. |
| 299 |
*/ |
| 300 |
public static function update_wp_site( $params ) { |
| 301 |
if ( ! isset( $params['websiteid'] ) || ! MainWP_Utility::ctype_digit( $params['websiteid'] ) ) { |
| 302 |
return 0; |
| 303 |
} |
| 304 |
|
| 305 |
if ( isset( $params['is_staging'] ) ) { |
| 306 |
unset( $params['is_staging'] ); |
| 307 |
} |
| 308 |
|
| 309 |
$website = MainWP_DB::instance()->get_website_by_id( $params['websiteid'] ); |
| 310 |
if ( null == $website ) { |
| 311 |
return 0; |
| 312 |
} |
| 313 |
|
| 314 |
if ( ! MainWP_System_Utility::can_edit_website( $website ) ) { |
| 315 |
return 0; |
| 316 |
} |
| 317 |
|
| 318 |
$data = array(); |
| 319 |
$uniqueId = null; |
| 320 |
|
| 321 |
if ( isset( $params['name'] ) && ! empty( $params['name'] ) ) { |
| 322 |
$data['name'] = htmlentities( $params['name'] ); |
| 323 |
} |
| 324 |
|
| 325 |
if ( isset( $params['wpadmin'] ) && ! empty( $params['wpadmin'] ) ) { |
| 326 |
$data['adminname'] = $params['wpadmin']; |
| 327 |
} |
| 328 |
|
| 329 |
if ( isset( $params['unique_id'] ) ) { |
| 330 |
$data['uniqueId'] = $params['unique_id']; |
| 331 |
$uniqueId = $params['unique_id']; |
| 332 |
} |
| 333 |
|
| 334 |
if ( empty( $data ) ) { |
| 335 |
return 0; |
| 336 |
} |
| 337 |
|
| 338 |
MainWP_DB::instance()->update_website_values( $website->id, $data ); |
| 339 |
if ( null !== $uniqueId ) { |
| 340 |
try { |
| 341 |
$information = MainWP_Connect::fetch_url_authed( $website, 'update_values', array( 'uniqueId' => $uniqueId ) ); |
| 342 |
} catch ( MainWP_Exception $e ) { |
| 343 |
$error = $e->getMessage(); |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
/** |
| 348 |
* Action: mainwp_updated_site |
| 349 |
* |
| 350 |
* Fires after updatig the child site options. |
| 351 |
* |
| 352 |
* @param int $website->id Child site ID. |
| 353 |
* @param array $data Child site data. |
| 354 |
* |
| 355 |
* @since 3.5.1 |
| 356 |
*/ |
| 357 |
do_action( 'mainwp_updated_site', $website->id, $data ); |
| 358 |
return $website->id; |
| 359 |
} |
| 360 |
|
| 361 |
/** |
| 362 |
* Method get_activate_extension_notice() |
| 363 |
* |
| 364 |
* Check for inactive MainWP Extensions & |
| 365 |
* return an activation warning message. |
| 366 |
* |
| 367 |
* @param mixed $pluginFile MainWP Extension to check. |
| 368 |
* |
| 369 |
* @return string Activation notice. |
| 370 |
*/ |
| 371 |
public function get_activate_extension_notice( $pluginFile ) { |
| 372 |
$active = MainWP_Extensions_Handler::is_extension_activated( $pluginFile ); |
| 373 |
if ( $active ) { |
| 374 |
return false; |
| 375 |
} |
| 376 |
|
| 377 |
$activate_notices = get_user_option( 'mainwp_hide_activate_notices' ); |
| 378 |
if ( is_array( $activate_notices ) ) { |
| 379 |
$slug = basename( $pluginFile, '.php' ); |
| 380 |
if ( isset( $activate_notices[ $slug ] ) ) { |
| 381 |
return false; |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
return sprintf( __( 'You have a MainWP extension that does not have an active API entered. This means you will not receive updates or support. Please visit the %1$sExtensions%2$s page and enter your API key.', 'mainwp' ), '<a href="admin.php?page=Extensions">', '</a>' ); |
| 386 |
} |
| 387 |
|
| 388 |
/** |
| 389 |
* Method cache_getcontext() |
| 390 |
* |
| 391 |
* Get cached search context for given page. |
| 392 |
* |
| 393 |
* @param string $page Current MainWP Page. |
| 394 |
* |
| 395 |
* @return array Cached Search Array. |
| 396 |
*/ |
| 397 |
public function cache_getcontext( $page ) { |
| 398 |
return MainWP_Cache::get_cached_context( $page ); |
| 399 |
} |
| 400 |
|
| 401 |
/** |
| 402 |
* Method cache_echo_body() |
| 403 |
* |
| 404 |
* Echo Cached Search Body. |
| 405 |
* |
| 406 |
* @param string $page Current MainWP Page. |
| 407 |
*/ |
| 408 |
public function cache_echo_body( $page ) { |
| 409 |
MainWP_Cache::echo_body( $page ); |
| 410 |
} |
| 411 |
|
| 412 |
/** |
| 413 |
* Method cache_init() |
| 414 |
* |
| 415 |
* Initiate search session variables for the current page. |
| 416 |
* |
| 417 |
* @param string $page Current MainWP Page. |
| 418 |
*/ |
| 419 |
public function cache_init( $page ) { |
| 420 |
MainWP_Cache::init_cache( $page ); |
| 421 |
} |
| 422 |
|
| 423 |
/** |
| 424 |
* Method cache_add_context() |
| 425 |
* |
| 426 |
* Hook to add time & Search Context session variable. |
| 427 |
* |
| 428 |
* @param string $page Current MainWP Page. |
| 429 |
* @param mixed $context Time of search. |
| 430 |
*/ |
| 431 |
public function cache_add_context( $page, $context ) { |
| 432 |
MainWP_Cache::add_context( $page, $context ); |
| 433 |
} |
| 434 |
|
| 435 |
/** |
| 436 |
* Method cache_add_body() |
| 437 |
* |
| 438 |
* Hook to add Search Body Session variable. |
| 439 |
* |
| 440 |
* @param string $page Current MainWP Page. |
| 441 |
* @param mixed $body Search body. |
| 442 |
*/ |
| 443 |
public function cache_add_body( $page, $body ) { |
| 444 |
MainWP_Cache::add_body( $page, $body ); |
| 445 |
} |
| 446 |
|
| 447 |
/** |
| 448 |
* Method select_sites_box() |
| 449 |
* |
| 450 |
* Hook to select sites box. |
| 451 |
* |
| 452 |
* @param string $title Input title. |
| 453 |
* @param string $type Input type, radio. |
| 454 |
* @param bool $show_group Whether or not to show group, Default: true. |
| 455 |
* @param bool $show_select_all Whether to show select all. |
| 456 |
* @param string $class Default = ''. |
| 457 |
* @param string $style Default = ''. |
| 458 |
* @param array $selected_websites Selected Child Sites. |
| 459 |
* @param array $selected_groups Selected Groups. |
| 460 |
*/ |
| 461 |
public function select_sites_box( $title = '', $type = 'checkbox', $show_group = true, $show_select_all = true, $class = '', $style = '', $selected_websites = array(), $selected_groups = array() ) { |
| 462 |
MainWP_UI::select_sites_box( $type, $show_group, $show_select_all, $class, $style, $selected_websites, $selected_groups ); |
| 463 |
} |
| 464 |
|
| 465 |
/** |
| 466 |
* Method hook_notify_user() |
| 467 |
* |
| 468 |
* Hook to send user a notification. |
| 469 |
* |
| 470 |
* @param int $userId User ID. |
| 471 |
* @param string $subject Email Subject. |
| 472 |
* @param string $content Email Content. |
| 473 |
*/ |
| 474 |
public function hook_notify_user( $userId, $subject, $content ) { |
| 475 |
MainWP_Notification::send_notify_user( $userId, $subject, $content ); |
| 476 |
} |
| 477 |
|
| 478 |
/** |
| 479 |
* Method get_error_message() |
| 480 |
* |
| 481 |
* Hook to get error message. |
| 482 |
* |
| 483 |
* @param object $msg Error message. |
| 484 |
* @param object $extra HTTP error message. |
| 485 |
* |
| 486 |
* @return string Error message. |
| 487 |
*/ |
| 488 |
public function get_error_message( $msg, $extra ) { |
| 489 |
return MainWP_Error_Helper::get_error_message( new MainWP_Exception( $msg, $extra ) ); |
| 490 |
} |
| 491 |
|
| 492 |
/** |
| 493 |
* Method get_user_extension() |
| 494 |
* |
| 495 |
* Hook to get user extension. |
| 496 |
* |
| 497 |
* @return object $row User extension. |
| 498 |
*/ |
| 499 |
public function get_user_extension() { |
| 500 |
return MainWP_DB_Common::instance()->get_user_extension(); |
| 501 |
} |
| 502 |
|
| 503 |
/** |
| 504 |
* Method hook_get_site_options() |
| 505 |
* |
| 506 |
* Hook to get Child site options. |
| 507 |
* |
| 508 |
* @param mixed $boolean Boolean check. |
| 509 |
* @param object $website Child site object. |
| 510 |
* @param string $name Option table name. |
| 511 |
* |
| 512 |
* @return string|null Database query result (as string), or null on failure |
| 513 |
*/ |
| 514 |
public function hook_get_site_options( $boolean, $website, $name = '' ) { |
| 515 |
|
| 516 |
if ( empty( $name ) ) { |
| 517 |
return $boolean; |
| 518 |
} |
| 519 |
|
| 520 |
if ( is_numeric( $website ) ) { |
| 521 |
$obj = new \stdClass(); |
| 522 |
$obj->id = $website; |
| 523 |
$website = $obj; |
| 524 |
} |
| 525 |
|
| 526 |
return MainWP_DB::instance()->get_website_option( $website, $name ); |
| 527 |
} |
| 528 |
|
| 529 |
/** |
| 530 |
* Method hook_update_site_options() |
| 531 |
* |
| 532 |
* Hook to get Child site options. |
| 533 |
* |
| 534 |
* @param mixed $boolean Boolean check. |
| 535 |
* @param object $website Child site object. |
| 536 |
* @param string $option Option name. |
| 537 |
* @param string $value Option value. |
| 538 |
* |
| 539 |
* @return string|null Database query result (as string), or null on failure |
| 540 |
*/ |
| 541 |
public function hook_update_site_options( $boolean, $website, $option, $value ) { |
| 542 |
return MainWP_DB::instance()->update_website_option( $website, $option, $value ); |
| 543 |
} |
| 544 |
|
| 545 |
/** |
| 546 |
* Get sites by user ID. |
| 547 |
* |
| 548 |
* @param mixed $boolean Boolean check. |
| 549 |
* @param int $userid User ID. |
| 550 |
* @param bool $selectgroups Selected groups. |
| 551 |
* @param null $search_site Site search field value. |
| 552 |
* @param string $orderBy Order list by. Default: URL. |
| 553 |
* |
| 554 |
* @return object|null Database query results or null on failure. |
| 555 |
*/ |
| 556 |
public function hook_get_websites_by_user_id( $boolean, $userid, $selectgroups = false, $search_site = null, $orderBy = 'wp.url' ) { |
| 557 |
return MainWP_DB::instance()->get_websites_by_user_id( $userid, $selectgroups, $search_site, $orderBy ); |
| 558 |
} |
| 559 |
|
| 560 |
/** |
| 561 |
* Method get_websites_by_url() |
| 562 |
* |
| 563 |
* Hook to get Child Site by URL. |
| 564 |
* |
| 565 |
* @param string $url Child Site URL. |
| 566 |
* |
| 567 |
* @return array|object|null Database query results. |
| 568 |
*/ |
| 569 |
public function get_websites_by_url( $url ) { |
| 570 |
return MainWP_DB::instance()->get_websites_by_url( $url ); |
| 571 |
} |
| 572 |
|
| 573 |
/** |
| 574 |
* Method hook_get_all_posts() |
| 575 |
* Hook to get posts from sites. |
| 576 |
* |
| 577 |
* @since 3.4.4 |
| 578 |
* @param object $sites Child Sites object. |
| 579 |
* @param array $post_data with values: keyword, dtsstart, dtsstop, status, maxRecords, post_type. |
| 580 |
* |
| 581 |
* @return array $output All posts data array. |
| 582 |
*/ |
| 583 |
public function hook_get_all_posts( $sites, $post_data = array() ) { |
| 584 |
|
| 585 |
$dbwebsites = array(); |
| 586 |
$data = array( 'id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey', 'verify_certificate', 'http_user', 'http_pass', 'ssl_version' ); |
| 587 |
|
| 588 |
if ( '' !== $sites ) { |
| 589 |
foreach ( $sites as $k => $v ) { |
| 590 |
if ( MainWP_Utility::ctype_digit( $v ) ) { |
| 591 |
$website = MainWP_DB::instance()->get_website_by_id( $v ); |
| 592 |
$dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data ); |
| 593 |
} |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
$default_data = array( |
| 598 |
'post_type' => 'post', |
| 599 |
'status' => 'publish', |
| 600 |
'maxRecords' => 10, |
| 601 |
); |
| 602 |
|
| 603 |
$post_data = array_merge( $default_data, $post_data ); |
| 604 |
|
| 605 |
$output = new \stdClass(); |
| 606 |
$output->results = array(); |
| 607 |
if ( $dbwebsites ) { |
| 608 |
MainWP_Connect::fetch_urls_authed( |
| 609 |
$dbwebsites, |
| 610 |
'get_all_posts', |
| 611 |
$post_data, |
| 612 |
array( |
| 613 |
MainWP_Post::get_class_name(), |
| 614 |
'hook_posts_search_handler', |
| 615 |
), |
| 616 |
$output, |
| 617 |
$is_external_hook = true |
| 618 |
); |
| 619 |
} |
| 620 |
return $output; |
| 621 |
} |
| 622 |
|
| 623 |
/** |
| 624 |
* Method mainwp_current_user_have_right() |
| 625 |
* |
| 626 |
* Check permission level by hook mainwp_currentusercan of Team Control extension |
| 627 |
* |
| 628 |
* @param mixed $input Return value holder. |
| 629 |
* @param string $can_type group or type of capabilities. |
| 630 |
* @param string $which Which function to perform. |
| 631 |
* |
| 632 |
* @return bool $input Return true if the user can and false if they can not. |
| 633 |
*/ |
| 634 |
public function hook_current_user_can( $input, $can_type, $which ) { |
| 635 |
|
| 636 |
if ( function_exists( 'mainwp_current_user_have_right' ) ) { |
| 637 |
return mainwp_current_user_have_right( $can_type, $which ); |
| 638 |
} |
| 639 |
|
| 640 |
return $input; |
| 641 |
} |
| 642 |
|
| 643 |
/** |
| 644 |
* Method hook_escape_response() |
| 645 |
* |
| 646 |
* To escape response data. |
| 647 |
* |
| 648 |
* @param mixed $response response data. |
| 649 |
* @param string $fields fields of response data - option. |
| 650 |
* @param string $more_allowed input allowed tags - option. |
| 651 |
* |
| 652 |
* @return mixed $response valid response data. |
| 653 |
*/ |
| 654 |
public function hook_escape_response( $response, $fields = false, $more_allowed = array() ) { |
| 655 |
|
| 656 |
if ( false === $fields || is_string( $response ) ) { |
| 657 |
return MainWP_Utility::esc_content( $response ); |
| 658 |
} |
| 659 |
|
| 660 |
if ( ! is_array( $fields ) ) { |
| 661 |
return $response; |
| 662 |
} |
| 663 |
|
| 664 |
if ( ! in_array( 'error', $fields ) ) { |
| 665 |
$fields[] = 'error'; // to sure to valid 'error' field, if that existed. |
| 666 |
} |
| 667 |
|
| 668 |
if ( ! in_array( 'message', $fields ) ) { |
| 669 |
$fields[] = 'message'; // to sure to valid 'message' field, if that existed. |
| 670 |
} |
| 671 |
|
| 672 |
$depth = 10; |
| 673 |
|
| 674 |
foreach ( $fields as $field ) { |
| 675 |
if ( isset( $response[ $field ] ) ) { |
| 676 |
$response[ $field ] = MainWP_Utility::esc_mixed_content( $response[ $field ], $depth, $more_allowed ); |
| 677 |
} |
| 678 |
} |
| 679 |
return $response; |
| 680 |
} |
| 681 |
|
| 682 |
/** |
| 683 |
* Method hook_secure_request() |
| 684 |
* |
| 685 |
* Security check to request parameter |
| 686 |
* |
| 687 |
* @param string $action Action to perform. |
| 688 |
* @param string $query_arg Query argument. |
| 689 |
*/ |
| 690 |
public function hook_secure_request( $action = '', $query_arg = 'security' ) { |
| 691 |
MainWP_Post_Handler::instance()->secure_request( $action, $query_arg ); |
| 692 |
} |
| 693 |
|
| 694 |
/** |
| 695 |
* Method hook_get_mainwp_dir() |
| 696 |
* |
| 697 |
* Hook to get MainWP Directory. |
| 698 |
* |
| 699 |
* @param bool $false False. |
| 700 |
* @param null $dir WP files system diectories. |
| 701 |
* @param bool $direct_access Return true if Direct access file system. Default: false. |
| 702 |
* |
| 703 |
* @return array $newdir, $url. |
| 704 |
*/ |
| 705 |
public function hook_get_mainwp_dir( $false = false, $dir = null, $direct_access = false ) { |
| 706 |
return MainWP_System_Utility::get_mainwp_dir( $dir, $direct_access ); |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
/** |
| 711 |
* Method is_multi_user() |
| 712 |
* |
| 713 |
* Hook to check if multi user. |
| 714 |
* |
| 715 |
* @return bool true|false. |
| 716 |
*/ |
| 717 |
public function is_multi_user() { |
| 718 |
return MainWP_System::instance()->is_multi_user(); |
| 719 |
} |
| 720 |
|
| 721 |
/** |
| 722 |
* Method filter_qq2_file_uploader() |
| 723 |
* |
| 724 |
* Hook to create new MainWP_QQ2_File_Uploader() class. |
| 725 |
* |
| 726 |
* @param mixed $allowedExtensions Allowed files extentions. |
| 727 |
* @param mixed $sizeLimit Maximum file size allowed to be uploaded. |
| 728 |
* |
| 729 |
* @return bool Return true on upload false on failer. |
| 730 |
*/ |
| 731 |
public function filter_qq2_file_uploader( $allowedExtensions, $sizeLimit ) { |
| 732 |
return new MainWP_QQ2_File_Uploader( $allowedExtensions, $sizeLimit ); |
| 733 |
} |
| 734 |
|
| 735 |
/** |
| 736 |
* Method get_metaboxes_post() |
| 737 |
* |
| 738 |
* Hook to get meta boxes. |
| 739 |
* |
| 740 |
* @return string|bool Return error or true. |
| 741 |
*/ |
| 742 |
public function get_metaboxes_post() { |
| 743 |
return MainWP_System::instance()->metaboxes; |
| 744 |
} |
| 745 |
|
| 746 |
/** |
| 747 |
* Method get_formated_email() |
| 748 |
* |
| 749 |
* Hook to format email. |
| 750 |
* |
| 751 |
* @param mixed $body Email body. |
| 752 |
* @param mixed $email Email address. |
| 753 |
* @param string $title Email title. |
| 754 |
* |
| 755 |
* @return string|bool Return error or true. |
| 756 |
*/ |
| 757 |
public function get_formated_email( $body, $email, $title = '' ) { |
| 758 |
return MainWP_Format::format_email( $email, $body, $title ); |
| 759 |
} |
| 760 |
|
| 761 |
/** |
| 762 |
* Method active_plugin() |
| 763 |
* |
| 764 |
* Hook to activate plugins. |
| 765 |
*/ |
| 766 |
public function active_plugin() { |
| 767 |
MainWP_Plugins_Handler::activate_plugins(); |
| 768 |
die(); |
| 769 |
} |
| 770 |
|
| 771 |
/** |
| 772 |
* Method deactive_plugin() |
| 773 |
* |
| 774 |
* Hook to deactivate plugins. |
| 775 |
*/ |
| 776 |
public function deactive_plugin() { |
| 777 |
MainWP_Plugins_Handler::deactivate_plugins(); |
| 778 |
die(); |
| 779 |
} |
| 780 |
|
| 781 |
/** |
| 782 |
* Method delete_plugin() |
| 783 |
* |
| 784 |
* Hook to delete plugins. |
| 785 |
*/ |
| 786 |
public function delete_plugin() { |
| 787 |
MainWP_Plugins_Handler::delete_plugins(); |
| 788 |
die(); |
| 789 |
} |
| 790 |
|
| 791 |
/** |
| 792 |
* Method delete_theme() |
| 793 |
* |
| 794 |
* Hook to delete theme() |
| 795 |
*/ |
| 796 |
public function delete_theme() { |
| 797 |
MainWP_Themes_Handler::delete_themes(); |
| 798 |
die(); |
| 799 |
} |
| 800 |
|
| 801 |
/** |
| 802 |
* Method upgrade_plugin_theme() |
| 803 |
* |
| 804 |
* Hook to update theme. |
| 805 |
*/ |
| 806 |
public function upgrade_plugin_theme() { |
| 807 |
try { |
| 808 |
$websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : null; |
| 809 |
$type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : null; |
| 810 |
$slugs = isset( $_POST['slugs'] ) && is_array( $_POST['slugs'] ) ? wp_unslash( $_POST['slugs'] ) : array(); |
| 811 |
$error = ''; |
| 812 |
if ( 'plugin' === $type && ! mainwp_current_user_have_right( 'dashboard', 'update_plugins' ) ) { |
| 813 |
$error = mainwp_do_not_have_permissions( __( 'update plugins', 'mainwp' ), false ); |
| 814 |
} elseif ( 'theme' === $type && ! mainwp_current_user_have_right( 'dashboard', 'update_themes' ) ) { |
| 815 |
$error = mainwp_do_not_have_permissions( __( 'update themes', 'mainwp' ), false ); |
| 816 |
} |
| 817 |
|
| 818 |
if ( ! empty( $error ) ) { |
| 819 |
wp_send_json( array( 'error' => $error ) ); |
| 820 |
} |
| 821 |
|
| 822 |
if ( MainWP_Utility::ctype_digit( $websiteId ) ) { |
| 823 |
$website = MainWP_DB::instance()->get_website_by_id( $websiteId ); |
| 824 |
if ( MainWP_System_Utility::can_edit_website( $website ) ) { |
| 825 |
/** |
| 826 |
* Action: mainwp_before_plugin_theme_translation_update |
| 827 |
* |
| 828 |
* Fires before plugin/theme/translation update actions. |
| 829 |
* |
| 830 |
* @since 4.1 |
| 831 |
*/ |
| 832 |
do_action( 'mainwp_before_plugin_theme_translation_update', $type, implode( ',', $slugs ), $website ); |
| 833 |
|
| 834 |
$information = MainWP_Connect::fetch_url_authed( |
| 835 |
$website, |
| 836 |
'upgradeplugintheme', |
| 837 |
array( |
| 838 |
'type' => $type, |
| 839 |
'list' => urldecode( implode( ',', $slugs ) ), |
| 840 |
) |
| 841 |
); |
| 842 |
|
| 843 |
/** |
| 844 |
* Action: mainwp_after_plugin_theme_translation_update |
| 845 |
* |
| 846 |
* Fires before plugin/theme/translation update actions. |
| 847 |
* |
| 848 |
* @since 4.1 |
| 849 |
*/ |
| 850 |
do_action( 'mainwp_after_plugin_theme_translation_update', $information, $type, implode( ',', $slugs ), $website ); |
| 851 |
|
| 852 |
if ( isset( $information['sync'] ) ) { |
| 853 |
unset( $information['sync'] ); |
| 854 |
} |
| 855 |
|
| 856 |
wp_send_json( $information ); |
| 857 |
} |
| 858 |
} |
| 859 |
} catch ( MainWP_Exception $e ) { |
| 860 |
die( wp_json_encode( array( 'error' => MainWP_Error_Helper::get_error_message( $e ) ) ) ); |
| 861 |
} |
| 862 |
|
| 863 |
die(); |
| 864 |
} |
| 865 |
|
| 866 |
/** |
| 867 |
* Method hook_get_websites_by_group_ids() |
| 868 |
* |
| 869 |
* Hook to get Child Sites by group ID. |
| 870 |
* |
| 871 |
* @param mixed $ids Group IDs. |
| 872 |
* @param null $userId Current user ID. |
| 873 |
* |
| 874 |
* @return (object|null) Database query result for get Child Sites by group ID or null on failure. |
| 875 |
*/ |
| 876 |
public function hook_get_websites_by_group_ids( $ids, $userId = null ) { |
| 877 |
return MainWP_DB::instance()->get_websites_by_group_ids( $ids, $userId ); |
| 878 |
} |
| 879 |
|
| 880 |
} |
| 881 |
|