PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/s2member/includes/classes/mms-patches.inc.php

https://gitlab.com/Gashler/dp
PHP | 150 lines | 94 code | 15 blank | 41 comment | 46 complexity | 2897b0f4d1b385d59ad943f9c8a8dcd4 MD5 | raw file
  1. <?php
  2. /**
  3. * Main Multisite patches.
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * (coded in the USA)
  8. *
  9. * Released under the terms of the GNU General Public License.
  10. * You should have received a copy of the GNU General Public License,
  11. * along with this software. In the main directory, see: /licensing/
  12. * If not, see: {@link http://www.gnu.org/licenses/}.
  13. *
  14. * @package s2Member\Main_Multisite_Patches
  15. * @since 3.5
  16. */
  17. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  18. exit("Do not access this file directly.");
  19. if (!class_exists ("c_ws_plugin__s2member_mms_patches"))
  20. {
  21. /**
  22. * Main Multisite patches.
  23. *
  24. * @package s2Member\Main_Multisite_Patches
  25. * @since 3.5
  26. */
  27. class c_ws_plugin__s2member_mms_patches
  28. {
  29. /**
  30. * Synchronizes Multisite patches with WordPress® core upgrades.
  31. *
  32. * @package s2Member\Main_Multisite_Patches
  33. * @since 3.5
  34. *
  35. * @attaches-to ``add_filter("update_feedback");``
  36. *
  37. * @param str $message Expects message string passed through by the Filter.
  38. * @return str Message after having been Filtered by this routine.
  39. */
  40. public static function sync_mms_patches ($message = FALSE)
  41. {
  42. global $pagenow; // Need access to this global var.
  43. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  44. do_action ("ws_plugin__s2member_before_sync_mms_patches", get_defined_vars ());
  45. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  46. if (is_multisite () && is_network_admin () && $pagenow === "update-core.php")
  47. if ($message === "Upgrading database&#8230;" && c_ws_plugin__s2member_mms_patches::mms_patches ())
  48. apply_filters ("update_feedback", "s2 Multisite patches applied&#8230;");
  49. return apply_filters ("ws_plugin__s2member_sync_mms_patches", $message, get_defined_vars ());
  50. }
  51. /**
  52. * Handles patches on a Multisite Network installation.
  53. *
  54. * @package s2Member\Main_Multisite_Patches
  55. * @since 3.5
  56. *
  57. * @param bool $display_notices Defaults to false. If true, notices are displayed.
  58. * @return bool True if Multisite patches were processed, else false.
  59. */
  60. public static function mms_patches ($display_notices = FALSE)
  61. {
  62. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  63. do_action ("ws_plugin__s2member_before_mms_patches", get_defined_vars ());
  64. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  65. if (is_multisite () && is_admin () && is_main_site () && $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["configured"])
  66. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["mms_auto_patch"] && (!defined ("DISALLOW_FILE_MODS") || !DISALLOW_FILE_MODS))
  67. {
  68. do_action ("ws_plugin__s2member_during_mms_patches_before", get_defined_vars ());
  69. $wp_login_file = ABSPATH . "wp-login.php"; // This works for both WordPress® 3.0 and 3.1. WordPress® 3.1+ uses: `site_url('wp-signup.php')`. WordPress® 3.5+ uses: `network_site_url('wp-signup.php')`.
  70. $wp_login_section = "/([\r\n\t\s ]+)(wp_redirect( *?)\(( *?)apply_filters( *?)\(( *?)['\"]wp_signup_location['\"],( *?)(site_url( *?)\(( *?)['\"]wp-signup\.php['\"]( *?)\)|network_site_url( *?)\(( *?)['\"]wp-signup\.php['\"]( *?)\)|get_bloginfo( *?)\(['\"]wpurl['\"]\)( *?)\.( *?)['\"]\/wp-signup\.php['\"])( *?)\)( *?)\);)([\r\n\t\s ]+)(exit;)/";
  71. $wp_login_replace = "\n\t\t// Modified for full plugin compatiblity.\n\t\t//wp_redirect( apply_filters( 'wp_signup_location', network_site_url('wp-signup.php') ) );\n\t\t//exit;";
  72. if (file_exists ($wp_login_file) && ($wp_login = file_get_contents ($wp_login_file)) && is_writable ($wp_login_file))
  73. {
  74. if ((($wp_login_written = file_put_contents ($wp_login_file, preg_replace ($wp_login_section, $wp_login_replace, $wp_login, 1, $wp_login_patched))) && $wp_login_patched) || ($wp_login_patched_already = $wp_login_patched = strpos ($wp_login, $wp_login_replace)))
  75. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-login.php</code> file ' . (($wp_login_patched_already) ? 'is patched' : 'has been patched successfully') . '.') : null;
  76. else if (!$wp_login_written) // Otherwise, we need to report that /wp-login.php could NOT be updated. Possibly a permissions error.
  77. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-login.php</code> file could NOT be patched. Patch NOT written.', true) : null;
  78. else if (!$wp_login_patched) // Otherwise, we need to report that /wp-login.php could NOT be updated. Wrong WordPress® version?
  79. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-login.php</code> file could NOT be patched. Unverifiable.', true) : null;
  80. }
  81. else // Otherwise, we need to report that /wp-login.php could NOT be updated. Possibly a permissions error.
  82. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-login.php</code> file could NOT be patched. File NOT writable.', true) : null;
  83. $load_file = ABSPATH . WPINC . "/load.php";
  84. $load_section = "/([\r\n\t\s ]+)(if( *?)\(( *?)empty( *?)\(( *?)\\\$active_plugins( *?)\)( *?)\|\|( *?)defined( *?)\(( *?)['\"]WP_INSTALLING['\"]( *?)\)( *?)\))/";
  85. $load_replace = "\n\n\t// Modified for full plugin compatiblity.\n\t//if ( empty( \$active_plugins ) || defined( 'WP_INSTALLING' ) )\n\tif ( empty( \$active_plugins ) || ( defined( 'WP_INSTALLING' ) && !preg_match(\"/\/wp-activate\.php/\", \$_SERVER[\"REQUEST_URI\"]) ) )";
  86. if (file_exists ($load_file) && ($load = file_get_contents ($load_file)) && is_writable ($load_file))
  87. {
  88. if ((($load_written = file_put_contents ($load_file, preg_replace ($load_section, $load_replace, $load, 1, $load_patched))) && $load_patched) || ($load_patched_already = $load_patched = strpos ($load, $load_replace)))
  89. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-includes/load.php</code> file ' . (($load_patched_already) ? 'is patched' : 'has been patched successfully') . '.') : null;
  90. else if (!$load_written) // Otherwise, we need to report that /wp-includes/load.php could NOT be updated. Possibly a permissions error.
  91. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-includes/load.php</code> file could NOT be patched. Patch NOT written.', true) : null;
  92. else if (!$load_patched) // Otherwise, we need to report that /wp-includes/load.php could NOT be updated. Wrong WordPress® version?
  93. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-includes/load.php</code> file could NOT be patched. Unverifiable.', true) : null;
  94. }
  95. else // Otherwise, we need to report that /wp-includes/load.php could NOT be updated. Possibly a permissions error.
  96. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-includes/load.php</code> file could NOT be patched. File NOT writable.', true) : null;
  97. $user_new_file = ABSPATH . "wp-admin/user-new.php";
  98. $user_new_section = "/([\r\n\t\s ]+)(wpmu_signup_user( *?)\(( *?)\\\$new_user_login,( *?)\\\$_REQUEST\[( *?)'email'( *?)\],( *?)array( *?)\(( *?)'add_to_blog'( *?)\=\>( *?)\\\$wpdb->blogid,( *?)'new_role'( *?)\=\>( *?)\\\$_REQUEST\[( *?)'role'( *?)\]( *?)\)( *?)\);)/";
  99. $user_new_replace = "\n\t\t\t// Modified for full plugin compatiblity.\n\t\t\t//wpmu_signup_user( \$new_user_login, \$_REQUEST[ 'email' ], array( 'add_to_blog' => \$wpdb->blogid, 'new_role' => \$_REQUEST[ 'role' ] ) );\n\t\t\twpmu_signup_user( \$new_user_login, \$_REQUEST[ 'email' ], apply_filters( 'add_signup_meta', array( 'add_to_blog' => \$wpdb->blogid, 'new_role' => \$_REQUEST[ 'role' ] ) ) );";
  100. if (file_exists ($user_new_file) && ($user_new = file_get_contents ($user_new_file)) && is_writable ($user_new_file))
  101. {
  102. if ((($user_new_written = file_put_contents ($user_new_file, preg_replace ($user_new_section, $user_new_replace, $user_new, 1, $user_new_patched))) && $user_new_patched) || ($user_new_patched_already = $user_new_patched = strpos ($user_new, $user_new_replace)))
  103. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-admin/user-new.php</code> file ' . (($user_new_patched_already) ? 'is patched' : 'has been patched successfully') . '.') : null;
  104. else if (!$user_new_written) // Otherwise, we need to report that /wp-admin/user-new.php could NOT be updated. Possibly a permissions error.
  105. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-admin/user-new.php</code> file could NOT be patched. Patch NOT written.', true) : null;
  106. else if (!$user_new_patched) // Otherwise, we need to report that /wp-admin/user-new.php could NOT be updated. Wrong WordPress® version?
  107. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-admin/user-new.php</code> file could NOT be patched. Unverifiable.', true) : null;
  108. }
  109. else // Otherwise, we need to report that /wp-admin/user-new.php could NOT be updated. Possibly a permissions error.
  110. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-admin/user-new.php</code> file could NOT be patched. File NOT writable.', true) : null;
  111. $ms_functions_file = ABSPATH . "wp-includes/ms-functions.php";
  112. $ms_functions_section = "/([\r\n\t\s ]+)(return new WP_Error( *?)\(( *?)'user_already_exists'( *?),( *?)__( *?)\(( *?)'That username is already activated.'( *?)\),( *?)\\\$signup( *?)\);)/";
  113. $ms_functions_replace = "\n\t\t\t// Modified for full plugin compatiblity.\n\t\t\t//return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), \$signup);\n\t\t\treturn apply_filters('_wpmu_activate_existing_error_', new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), \$signup), get_defined_vars());";
  114. if (file_exists ($ms_functions_file) && ($ms_functions = file_get_contents ($ms_functions_file)) && is_writable ($ms_functions_file))
  115. {
  116. if ((($ms_functions_written = file_put_contents ($ms_functions_file, preg_replace ($ms_functions_section, $ms_functions_replace, $ms_functions, 1, $ms_functions_patched))) && $ms_functions_patched) || ($ms_functions_patched_already = $ms_functions_patched = strpos ($ms_functions, $ms_functions_replace)))
  117. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-includes/ms-functions.php</code> file ' . (($ms_functions_patched_already) ? 'is patched' : 'has been patched successfully') . '.') : null;
  118. else if (!$ms_functions_written) // Otherwise, we need to report that /wp-includes/ms-functions.php could NOT be updated. Possibly a permissions error.
  119. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-includes/ms-functions.php</code> file could NOT be patched. Patch NOT written.', true) : null;
  120. else if (!$ms_functions_patched) // Otherwise, we need to report that /wp-includes/ms-functions.php could NOT be updated. Wrong WordPress® version?
  121. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-includes/ms-functions.php</code> file could NOT be patched. Unverifiable.', true) : null;
  122. }
  123. else // Otherwise, we need to report that /wp-includes/ms-functions.php could NOT be updated. Possibly a permissions error.
  124. ($display_notices) ? c_ws_plugin__s2member_admin_notices::display_admin_notice ('Your <code>/wp-includes/ms-functions.php</code> file could NOT be patched. File NOT writable.', true) : null;
  125. $ran_mms_patches = true; // Flag indicating this routine was indeed processed.
  126. do_action ("ws_plugin__s2member_during_mms_patches_after", get_defined_vars ());
  127. }
  128. do_action ("ws_plugin__s2member_after_mms_patches", get_defined_vars ());
  129. return !empty ($ran_mms_patches) ? $ran_mms_patches : false;
  130. }
  131. }
  132. }
  133. ?>