function getSiteStats($information = array(), $exit = true) { global $wp_version; if ($exit) { $this->updateExternalSettings(); } MainWP_Helper::update_option('mainwp_child_branding_disconnected', '', 'yes'); if (isset($_POST['server'])) { MainWP_Helper::update_option('mainwp_child_server', $_POST['server']); } if (isset($_POST['numberdaysOutdatePluginTheme']) && !empty($_POST['numberdaysOutdatePluginTheme'])) { $days_outdate = get_option('mainwp_child_plugintheme_days_outdate', 365); if ($days_outdate !== $_POST['numberdaysOutdatePluginTheme']) { $days_outdate = $_POST['numberdaysOutdatePluginTheme']; MainWP_Helper::update_option('mainwp_child_plugintheme_days_outdate', $days_outdate); MainWP_Child_Plugins_Check::Instance()->cleanup_deactivation(false); MainWP_Child_Themes_Check::Instance()->cleanup_deactivation(false); } } $information['version'] = self::$version; $information['wpversion'] = $wp_version; $information['siteurl'] = get_option('siteurl'); $information['nossl'] = '1' === get_option('mainwp_child_nossl') ? 1 : 0; include_once ABSPATH . '/wp-admin/includes/update.php'; $timeout = 3 * 60 * 60; // 3minutes @set_time_limit($timeout); @ini_set('max_execution_time', $timeout); //Check for new versions if (null !== $this->filterFunction) { add_filter('pre_site_transient_update_core', $this->filterFunction, 99); } if (null !== $this->filterFunction) { add_filter('pre_transient_update_core', $this->filterFunction, 99); } @wp_version_check(); $core_updates = get_core_updates(); if (count($core_updates) > 0) { foreach ($core_updates as $core_update) { if ('latest' === $core_update->response) { break; } if ('upgrade' === $core_update->response && version_compare($wp_version, $core_update->current, '<=')) { $information['wp_updates'] = $core_update->current; } } } if (!isset($information['wp_updates'])) { $information['wp_updates'] = null; } if (null !== $this->filterFunction) { remove_filter('pre_site_transient_update_core', $this->filterFunction, 99); } if (null !== $this->filterFunction) { remove_filter('pre_transient_update_core', $this->filterFunction, 99); } add_filter('default_option_active_plugins', array(&$this, 'default_option_active_plugins')); add_filter('option_active_plugins', array(&$this, 'default_option_active_plugins')); //First check for new premium updates $update_check = apply_filters('mwp_premium_update_check', array()); if (!empty($update_check)) { foreach ($update_check as $updateFeedback) { if (is_array($updateFeedback['callback']) && isset($updateFeedback['callback'][0]) && isset($updateFeedback['callback'][1])) { @call_user_func(array($updateFeedback['callback'][0], $updateFeedback['callback'][1])); } else { if (is_string($updateFeedback['callback'])) { @call_user_func($updateFeedback['callback']); } } } } $informationPremiumUpdates = apply_filters('mwp_premium_update_notification', array()); $premiumPlugins = array(); $premiumThemes = array(); if (is_array($informationPremiumUpdates)) { $premiumUpdates = array(); $information['premium_updates'] = array(); $informationPremiumUpdatesLength = count($informationPremiumUpdates); for ($i = 0; $i < $informationPremiumUpdatesLength; $i++) { if (!isset($informationPremiumUpdates[$i]['new_version'])) { continue; } $slug = isset($informationPremiumUpdates[$i]['slug']) ? $informationPremiumUpdates[$i]['slug'] : $informationPremiumUpdates[$i]['Name']; if ('plugin' === $informationPremiumUpdates[$i]['type']) { $premiumPlugins[] = $slug; } else { if ('theme' === $informationPremiumUpdates[$i]['type']) { $premiumThemes[] = $slug; } } $new_version = $informationPremiumUpdates[$i]['new_version']; unset($informationPremiumUpdates[$i]['old_version']); unset($informationPremiumUpdates[$i]['new_version']); $information['premium_updates'][$slug] = $informationPremiumUpdates[$i]; $information['premium_updates'][$slug]['update'] = (object) array('new_version' => $new_version, 'premium' => true, 'slug' => $slug); if (!in_array($slug, $premiumUpdates)) { $premiumUpdates[] = $slug; } } MainWP_Helper::update_option('mainwp_premium_updates', $premiumUpdates); } remove_filter('default_option_active_plugins', array(&$this, 'default_option_active_plugins')); remove_filter('option_active_plugins', array(&$this, 'default_option_active_plugins')); if (null !== $this->filterFunction) { add_filter('pre_site_transient_update_plugins', $this->filterFunction, 99); } global $wp_current_filter; $wp_current_filter[] = 'load-plugins.php'; @wp_update_plugins(); include_once ABSPATH . '/wp-admin/includes/plugin.php'; $plugin_updates = get_plugin_updates(); if (is_array($plugin_updates)) { $information['plugin_updates'] = array(); foreach ($plugin_updates as $slug => $plugin_update) { if (in_array($plugin_update->Name, $premiumPlugins)) { continue; } $information['plugin_updates'][$slug] = $plugin_update; } } if (null !== $this->filterFunction) { remove_filter('pre_site_transient_update_plugins', $this->filterFunction, 99); } if (null !== $this->filterFunction) { add_filter('pre_site_transient_update_themes', $this->filterFunction, 99); } @wp_update_themes(); include_once ABSPATH . '/wp-admin/includes/theme.php'; $theme_updates = $this->upgrade_get_theme_updates(); if (is_array($theme_updates)) { $information['theme_updates'] = array(); foreach ($theme_updates as $slug => $theme_update) { $name = is_array($theme_update) ? $theme_update['Name'] : $theme_update->Name; if (in_array($name, $premiumThemes)) { continue; } $information['theme_updates'][$slug] = $theme_update; } } if (null !== $this->filterFunction) { remove_filter('pre_site_transient_update_themes', $this->filterFunction, 99); } $information['recent_comments'] = $this->get_recent_comments(array('approve', 'hold'), 5); $information['recent_posts'] = $this->get_recent_posts(array('publish', 'draft', 'pending', 'trash'), 5); $information['recent_pages'] = $this->get_recent_posts(array('publish', 'draft', 'pending', 'trash'), 5, 'page'); $securityIssuess = 0; if (!MainWP_Security::prevent_listing_ok()) { $securityIssuess++; } if (!MainWP_Security::remove_wp_version_ok()) { $securityIssuess++; } if (!MainWP_Security::remove_rsd_ok()) { $securityIssuess++; } if (!MainWP_Security::remove_wlw_ok()) { $securityIssuess++; } // if (!MainWP_Security::remove_core_update_ok()) $securityIssuess++; // if (!MainWP_Security::remove_plugin_update_ok()) $securityIssuess++; // if (!MainWP_Security::remove_theme_update_ok()) $securityIssuess++; // if (!MainWP_Security::fix_file_permissions_ok()) $securityIssuess++; if (!MainWP_Security::remove_database_reporting_ok()) { $securityIssuess++; } if (!MainWP_Security::remove_php_reporting_ok()) { $securityIssuess++; } if (!MainWP_Security::remove_scripts_version_ok() || !MainWP_Security::remove_styles_version_ok()) { $securityIssuess++; } if (!MainWP_Security::admin_user_ok()) { $securityIssuess++; } if (!MainWP_Security::remove_readme_ok()) { $securityIssuess++; } $information['securityIssues'] = $securityIssuess; //Directory listings! $information['directories'] = $this->scanDir(ABSPATH, 3); $cats = get_categories(array('hide_empty' => 0, 'hierarchical' => true)); $categories = array(); foreach ($cats as $cat) { $categories[] = $cat->name; } $information['categories'] = $categories; $information['totalsize'] = $this->getTotalFileSize(); $information['dbsize'] = MainWP_Child_DB::get_size(); $auths = get_option('mainwp_child_auth'); $information['extauth'] = $auths && isset($auths[$this->maxHistory]) ? $auths[$this->maxHistory] : null; $plugins = $this->get_all_plugins_int(false); $themes = $this->get_all_themes_int(false); $information['plugins'] = $plugins; $information['themes'] = $themes; if (isset($_POST['optimize']) && '1' === $_POST['optimize']) { $information['users'] = $this->get_all_users_int(); } if (isset($_POST['pluginConflicts']) && '' !== $_POST['pluginConflicts']) { $pluginConflicts = json_decode(stripslashes($_POST['pluginConflicts']), true); $conflicts = array(); if (count($pluginConflicts) > 0) { if (!$plugins) { $plugins = $this->get_all_plugins_int(false); } if (is_array($plugins) && is_array($pluginConflicts)) { foreach ($plugins as $plugin) { foreach ($pluginConflicts as $pluginConflict) { if ('1' === $plugin['active'] && ($plugin['name'] === $pluginConflict || $plugin['slug'] === $pluginConflict)) { $conflicts[] = $plugin['name']; } } } } } if (count($conflicts) > 0) { $information['pluginConflicts'] = $conflicts; } } if (isset($_POST['themeConflicts']) && '' !== $_POST['themeConflicts']) { $themeConflicts = json_decode(stripslashes($_POST['themeConflicts']), true); $conflicts = array(); if (is_array($themeConflicts) && count($themeConflicts) > 0) { $theme = wp_get_theme()->get('Name'); foreach ($themeConflicts as $themeConflict) { if ($theme === $themeConflict) { $conflicts[] = $theme; } } } if (count($conflicts) > 0) { $information['themeConflicts'] = $conflicts; } } if (isset($_POST['othersData'])) { $othersData = json_decode(stripslashes($_POST['othersData']), true); if (!is_array($othersData)) { $othersData = array(); } $information = apply_filters('mainwp-site-sync-others-data', $information, $othersData); if (version_compare(phpversion(), '5.3', '>=')) { if (isset($othersData['syncBackUpWordPress']) && $othersData['syncBackUpWordPress']) { if (MainWP_Child_Back_Up_Wordpress::isActivated()) { $information['syncBackUpWordPress'] = MainWP_Child_Back_Up_Wordpress::Instance()->syncData(); } } } if (isset($othersData['syncWPRocketData']) && 'yes' === $othersData['syncWPRocketData']) { $data = array(); if (MainWP_Child_WP_Rocket::isActivated()) { $boxes = get_user_meta($GLOBALS['current_user']->ID, 'rocket_boxes', true); $data['rocket_boxes'] = $boxes; } $information['syncWPRocketData'] = $data; } } $information['faviIcon'] = $this->get_favicon(); $last_post = wp_get_recent_posts(array('numberposts' => absint('1'))); if (isset($last_post[0])) { $last_post = $last_post[0]; } if (isset($last_post) && isset($last_post['post_modified_gmt'])) { $information['last_post_gmt'] = strtotime($last_post['post_modified_gmt']); } $information['mainwpdir'] = MainWP_Helper::validateMainWPDir() ? 1 : -1; $information['uniqueId'] = get_option('mainwp_child_uniqueId', ''); $information['plugins_outdate_info'] = MainWP_Child_Plugins_Check::Instance()->get_plugins_outdate_info(); $information['themes_outdate_info'] = MainWP_Child_Themes_Check::Instance()->get_themes_outdate_info(); if ($exit) { MainWP_Helper::write($information); } return $information; }
static function createPost($new_post, $post_custom, $post_category, $post_featured_image, $upload_dir, $post_tags) { global $current_user; $wprocket_fields = array('lazyload', 'lazyload_iframes', 'minify_html', 'minify_css', 'minify_js', 'cdn'); $wprocket_activated = false; if (MainWP_Child_WP_Rocket::isActivated()) { if (function_exists('get_rocket_option')) { $wprocket_activated = true; foreach ($wprocket_fields as $field) { if (!isset($post_custom['_rocket_exclude_' . $field])) { // check not exclude only if (!get_rocket_option($field)) { $post_custom['_rocket_exclude_' . $field] = array(true); // set as excluded } } } } } if (!$wprocket_activated) { foreach ($wprocket_fields as $field) { if (isset($post_custom['_rocket_exclude_' . $field])) { unset($post_custom['_rocket_exclude_' . $field]); } } } //Set up a new post (adding addition information) $usr = get_user_by('login', $_POST['user']); //$new_post['post_author'] = $current_user->ID; $is_robot_post = false; if (isset($_POST['isMainWPRobot']) && !empty($_POST['isMainWPRobot'])) { $is_robot_post = true; } $post_author = isset($new_post['post_author']) ? $new_post['post_author'] : $usr->ID; if ($is_robot_post) { if (1 === $post_author) { $new_post['post_author'] = $usr->ID; } else { if (!is_numeric($post_author)) { $user_author = get_user_by('login', $post_author); if ($user_author) { $post_author = $user_author->ID; } else { $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false); $post_author = wp_create_user($post_author, $random_password, $post_author . '@asdf.com'); } } } } else { if (isset($new_post['custom_post_author']) && !empty($new_post['custom_post_author'])) { $_author = get_user_by('login', $new_post['custom_post_author']); if (!empty($_author)) { $new_post['post_author'] = $_author->ID; } else { $new_post['post_author'] = $usr->ID; } unset($new_post['custom_post_author']); } } $post_author = !empty($post_author) ? $post_author : $usr->ID; $new_post['post_author'] = $post_author; $is_ezine_post = !empty($post_custom['_ezine_post_article_source']) ? true : false; $terms = $new_post['_ezin_post_category']; unset($new_post['_ezin_post_category']); $is_post_plus = isset($post_custom['_mainwp_post_plus']) ? true : false; $wp_error = null; if ($is_ezine_post || $is_post_plus) { if (isset($new_post['post_date_gmt']) && !empty($new_post['post_date_gmt'])) { $post_date_timestamp = strtotime($new_post['post_date_gmt']) + get_option('gmt_offset') * 60 * 60; $new_post['post_date'] = date('Y-m-d H:i:s', $post_date_timestamp); $new_post['post_status'] = $post_date_timestamp <= current_time('timestamp') ? 'publish' : 'future'; } else { $new_post['post_status'] = 'publish'; } } $wpr_options = isset($_POST['wpr_options']) ? $_POST['wpr_options'] : array(); //Search for all the images added to the new post //some images have a href tag to click to navigate to the image.. we need to replace this too $foundMatches = preg_match_all('/(<a[^>]+href=\\"(.*?)\\"[^>]*>)?(<img[^>\\/]*src=\\"((.*?)(png|gif|jpg|jpeg))\\")/ix', $new_post['post_content'], $matches, PREG_SET_ORDER); if (($foundMatches > 0 || $is_robot_post && isset($wpr_options['wpr_save_images']) && 'Yes' === $wpr_options['wpr_save_images']) && !$is_ezine_post) { //We found images, now to download them so we can start balbal foreach ($matches as $match) { $hrefLink = $match[2]; $imgUrl = $match[4]; if (!isset($upload_dir['baseurl']) || 0 !== strripos($imgUrl, $upload_dir['baseurl'])) { continue; } if (preg_match('/-\\d{3}x\\d{3}\\.[a-zA-Z0-9]{3,4}$/', $imgUrl, $imgMatches)) { $search = $imgMatches[0]; $replace = '.' . $match[6]; $originalImgUrl = str_replace($search, $replace, $imgUrl); } else { $originalImgUrl = $imgUrl; } try { $downloadfile = MainWP_Helper::uploadImage($originalImgUrl); $localUrl = $downloadfile['url']; $linkToReplaceWith = dirname($localUrl); if ('' !== $hrefLink) { $server = get_option('mainwp_child_server'); $serverHost = parse_url($server, PHP_URL_HOST); if (!empty($serverHost) && strpos($hrefLink, $serverHost) !== false) { $serverHref = 'href="' . $serverHost; $replaceServerHref = 'href="' . parse_url($localUrl, PHP_URL_SCHEME) . '://' . parse_url($localUrl, PHP_URL_HOST); $new_post['post_content'] = str_replace($serverHref, $replaceServerHref, $new_post['post_content']); } else { if (strpos($hrefLink, 'http') !== false) { $lnkToReplace = dirname($hrefLink); if ('http:' !== $lnkToReplace && 'https:' !== $lnkToReplace) { $new_post['post_content'] = str_replace($lnkToReplace, $linkToReplaceWith, $new_post['post_content']); } } } } $lnkToReplace = dirname($imgUrl); if ('http:' !== $lnkToReplace && 'https:' !== $lnkToReplace) { $new_post['post_content'] = str_replace($lnkToReplace, $linkToReplaceWith, $new_post['post_content']); } } catch (Exception $e) { } } } if ($is_post_plus) { $random_publish_date = isset($post_custom['_saved_draft_random_publish_date']) ? $post_custom['_saved_draft_random_publish_date'] : false; $random_publish_date = is_array($random_publish_date) ? current($random_publish_date) : null; if (!empty($random_publish_date)) { $random_date_from = isset($post_custom['_saved_draft_publish_date_from']) ? $post_custom['_saved_draft_publish_date_from'] : 0; $random_date_from = is_array($random_date_from) ? current($random_date_from) : 0; $random_date_to = isset($post_custom['_saved_draft_publish_date_to']) ? $post_custom['_saved_draft_publish_date_to'] : 0; $random_date_to = is_array($random_date_to) ? current($random_date_to) : 0; $now = current_time('timestamp'); if (empty($random_date_from)) { $random_date_from = $now; } if (empty($random_date_to)) { $random_date_to = $now; } if ($random_date_from === $now && $random_date_from === $random_date_to) { $random_date_to = $now + 7 * 24 * 3600; } if ($random_date_from > $random_date_to) { $tmp = $random_date_from; $random_date_from = $random_date_to; $random_date_to = $tmp; } $random_timestamp = rand($random_date_from, $random_date_to); $post_status = $random_timestamp <= current_time('timestamp') ? 'publish' : 'future'; $new_post['post_status'] = $post_status; $new_post['post_date'] = date('Y-m-d H:i:s', $random_timestamp); } } if (isset($post_tags) && '' !== $post_tags) { $new_post['tags_input'] = $post_tags; } //Save the post to the wp remove_filter('content_save_pre', 'wp_filter_post_kses'); // to fix brake scripts or html $post_status = $new_post['post_status']; $new_post['post_status'] = 'auto-draft'; $new_post_id = wp_insert_post($new_post, $wp_error); //Show errors if something went wrong if (is_wp_error($wp_error)) { return $wp_error->get_error_message(); } if (empty($new_post_id)) { return 'Undefined error'; } wp_update_post(array('ID' => $new_post_id, 'post_status' => $post_status)); if (!empty($terms)) { wp_set_object_terms($new_post_id, array_map(intval, $terms), 'category'); } $permalink = get_permalink($new_post_id); $seo_ext_activated = false; if (class_exists('WPSEO_Meta') && class_exists('WPSEO_Admin')) { $seo_ext_activated = true; } //Set custom fields $not_allowed = array('_slug', '_tags', '_edit_lock', '_selected_sites', '_selected_groups', '_selected_by', '_categories', '_edit_last', '_sticky'); $not_allowed[] = '_mainwp_boilerplate_sites_posts'; $not_allowed[] = '_ezine_post_keyword'; $not_allowed[] = '_ezine_post_display_sig'; $not_allowed[] = '_ezine_post_remove_link'; $not_allowed[] = '_ezine_post_grab_image'; $not_allowed[] = '_ezine_post_grab_image_placement'; $not_allowed[] = '_ezine_post_template_id'; $not_allowed[] = '_mainwp_post_plus'; $not_allowed[] = '_saved_as_draft'; $not_allowed[] = '_saved_draft_categories'; $not_allowed[] = '_saved_draft_tags'; $not_allowed[] = '_saved_draft_random_privelege'; $not_allowed[] = '_saved_draft_random_category'; $not_allowed[] = '_saved_draft_random_publish_date'; $not_allowed[] = '_saved_draft_publish_date_from'; $not_allowed[] = '_saved_draft_publish_date_to'; $not_allowed[] = '_post_to_only_existing_categories'; $not_allowed[] = '_mainwp_robot_post_comments'; $post_to_only_existing_categories = false; foreach ($post_custom as $meta_key => $meta_values) { if (!in_array($meta_key, $not_allowed)) { foreach ($meta_values as $meta_value) { if (strpos($meta_key, "_mainwp_spinner_") === 0) { continue; } // not save if (!$seo_ext_activated) { // if Wordpress SEO plugin is not activated do not save yoast post meta if (strpos($meta_key, '_yoast_wpseo_') === false) { add_post_meta($new_post_id, $meta_key, $meta_value); } } else { add_post_meta($new_post_id, $meta_key, $meta_value); } } } else { if ('_sticky' === $meta_key) { foreach ($meta_values as $meta_value) { if ('sticky' === base64_decode($meta_value)) { stick_post($new_post_id); } } } else { if ('_post_to_only_existing_categories' === $meta_key) { if (isset($meta_values[0]) && $meta_values[0]) { $post_to_only_existing_categories = true; } } } } } // yoast seo extension if ($seo_ext_activated) { $_seo_opengraph_image = isset($post_custom[WPSEO_Meta::$meta_prefix . 'opengraph-image']) ? $post_custom[WPSEO_Meta::$meta_prefix . 'opengraph-image'] : array(); $_seo_opengraph_image = current($_seo_opengraph_image); $_server_domain = ''; $_server = get_option('mainwp_child_server'); if (preg_match('/(https?:\\/\\/[^\\/]+\\/).+/', $_server, $matchs)) { $_server_domain = isset($matchs[1]) ? $matchs[1] : ''; } // upload image if it on the server if (!empty($_seo_opengraph_image) && strpos($_seo_opengraph_image, $_server_domain) !== false) { try { $upload = MainWP_Helper::uploadImage($_seo_opengraph_image); //Upload image to WP if (null !== $upload) { update_post_meta($new_post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', $upload['url']); //Add the image to the post! } } catch (Exception $e) { } } } //If categories exist, create them (second parameter of wp_create_categories adds the categories to the post) include_once ABSPATH . 'wp-admin/includes/taxonomy.php'; //Contains wp_create_categories if (isset($post_category) && '' !== $post_category) { $categories = explode(',', $post_category); if (count($categories) > 0) { if (!$post_to_only_existing_categories) { $post_category = wp_create_categories($categories, $new_post_id); } else { $cat_ids = array(); foreach ($categories as $cat) { if ($id = category_exists($cat)) { $cat_ids[] = $id; } } if (count($cat_ids) > 0) { wp_set_post_categories($new_post_id, $cat_ids); } } } } //If featured image exists - set it if (null !== $post_featured_image) { try { $upload = MainWP_Helper::uploadImage($post_featured_image); //Upload image to WP if (null !== $upload) { update_post_meta($new_post_id, '_thumbnail_id', $upload['id']); //Add the thumbnail to the post! } } catch (Exception $e) { } } // post plus extension process if ($is_post_plus) { $random_privelege = isset($post_custom['_saved_draft_random_privelege']) ? $post_custom['_saved_draft_random_privelege'] : null; $random_privelege = is_array($random_privelege) ? current($random_privelege) : null; $random_privelege_base = base64_decode($random_privelege); $random_privelege = maybe_unserialize($random_privelege_base); if (is_array($random_privelege) && count($random_privelege) > 0) { $random_post_authors = array(); foreach ($random_privelege as $role) { $users = get_users(array('role' => $role)); foreach ($users as $user) { $random_post_authors[] = $user->ID; } } if (count($random_post_authors) > 0) { shuffle($random_post_authors); $key = array_rand($random_post_authors); wp_update_post(array('ID' => $new_post_id, 'post_author' => $random_post_authors[$key])); } } $random_category = isset($post_custom['_saved_draft_random_category']) ? $post_custom['_saved_draft_random_category'] : false; $random_category = is_array($random_category) ? current($random_category) : null; if (!empty($random_category)) { $cats = get_categories(array('type' => 'post', 'hide_empty' => 0)); $random_cats = array(); if (is_array($cats)) { foreach ($cats as $cat) { $random_cats[] = $cat->term_id; } } if (count($random_cats) > 0) { shuffle($random_cats); $key = array_rand($random_cats); wp_set_post_categories($new_post_id, array($random_cats[$key]), false); } } } // end of post plus // MainWP Robot if ($is_robot_post) { $all_comments = $post_custom['_mainwp_robot_post_comments']; MainWP_Child_Robot::Instance()->wpr_insertcomments($new_post_id, $all_comments); } $ret['success'] = true; $ret['link'] = $permalink; $ret['added_id'] = $new_post_id; return $ret; }