| 1 |
<?php |
| 2 |
/** |
| 3 |
* Installation routines for s2Member. |
| 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\Installation |
| 15 |
* @since 3.5 |
| 16 |
*/ |
| 17 |
if(realpath(__FILE__) === realpath($_SERVER["SCRIPT_FILENAME"])) |
| 18 |
exit("Do not access this file directly."); |
| 19 |
/**/ |
| 20 |
if(!class_exists("c_ws_plugin__s2member_installation")) |
| 21 |
{ |
| 22 |
/** |
| 23 |
* Installation routines for s2Member. |
| 24 |
* |
| 25 |
* @package s2Member\Installation |
| 26 |
* @since 3.5 |
| 27 |
*/ |
| 28 |
class c_ws_plugin__s2member_installation |
| 29 |
{ |
| 30 |
/** |
| 31 |
* Activation routines for s2Member. |
| 32 |
* |
| 33 |
* @package s2Member\Installation |
| 34 |
* @since 3.5 |
| 35 |
* |
| 36 |
* @return null |
| 37 |
*/ |
| 38 |
public static function activate($reactivation_reason = FALSE) |
| 39 |
{ |
| 40 |
global $wpdb; /* Global database object reference. */ |
| 41 |
global $current_site, $current_blog; /* Multisite. */ |
| 42 |
/**/ |
| 43 |
do_action("ws_plugin__s2member_before_activation", get_defined_vars()); |
| 44 |
/**/ |
| 45 |
c_ws_plugin__s2member_roles_caps::config_roles(); /* Config Roles/Caps. */ |
| 46 |
update_option("ws_plugin__s2member_activated_levels", $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]); |
| 47 |
/**/ |
| 48 |
if(!is_dir($files_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"])) |
| 49 |
if(is_writable(dirname(c_ws_plugin__s2member_utils_dirs::strip_dir_app_data($files_dir)))) |
| 50 |
mkdir($files_dir, 0777, true); |
| 51 |
/**/ |
| 52 |
if(is_dir($files_dir) && is_writable($files_dir)) |
| 53 |
if(!file_exists($htaccess = $files_dir."/.htaccess") || !apply_filters("ws_plugin__s2member_preserve_files_dir_htaccess", false, get_defined_vars())) |
| 54 |
file_put_contents($htaccess, trim(c_ws_plugin__s2member_utilities::evl(file_get_contents($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir_htaccess"])))); |
| 55 |
/**/ |
| 56 |
c_ws_plugin__s2member_files::write_no_gzip_into_root_htaccess /* Handle the root `.htaccess` file as well now, for GZIP exclusions. */(); |
| 57 |
/**/ |
| 58 |
if(!is_dir($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"])) |
| 59 |
if(is_writable(dirname(c_ws_plugin__s2member_utils_dirs::strip_dir_app_data($logs_dir)))) |
| 60 |
mkdir($logs_dir, 0777, true); |
| 61 |
/**/ |
| 62 |
if(is_dir($logs_dir) && is_writable($logs_dir)) |
| 63 |
if(!file_exists($htaccess = $logs_dir."/.htaccess") || !apply_filters("ws_plugin__s2member_preserve_logs_dir_htaccess", false, get_defined_vars())) |
| 64 |
file_put_contents($htaccess, trim(c_ws_plugin__s2member_utilities::evl(file_get_contents($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir_htaccess"])))); |
| 65 |
/**/ |
| 66 |
(!is_array(get_option("ws_plugin__s2member_cache"))) ? update_option("ws_plugin__s2member_cache", array()) : null; |
| 67 |
(!is_array(get_option("ws_plugin__s2member_notices"))) ? update_option("ws_plugin__s2member_notices", array()) : null; |
| 68 |
(!is_array(get_option("ws_plugin__s2member_options"))) ? update_option("ws_plugin__s2member_options", array()) : null; |
| 69 |
(!is_numeric(get_option("ws_plugin__s2member_configured"))) ? update_option("ws_plugin__s2member_configured", "0") : null; |
| 70 |
/**/ |
| 71 |
if($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["configured"]) /* If we are re-activating. */ |
| 72 |
{ |
| 73 |
$v = get_option("ws_plugin__s2member_activated_version"); /* Currently. */ |
| 74 |
/**/ |
| 75 |
if(!$v || !version_compare($v, "3.2", ">=")) /* Needs to be upgraded? */ |
| 76 |
/* Version 3.2 is where `meta_key` names were changed. They're prefixed now. */ |
| 77 |
{ |
| 78 |
$like = "`meta_key` LIKE 's2member\_%' AND `meta_key` NOT LIKE '%s2member\_originating\_blog%'"; |
| 79 |
$wpdb->query("UPDATE `".$wpdb->usermeta."` SET `meta_key` = CONCAT('".$wpdb->prefix."', `meta_key`) WHERE ".$like); |
| 80 |
} |
| 81 |
/**/ |
| 82 |
if(!$v || !version_compare($v, "3.2.5", ">=")) /* Needs to be upgraded? */ |
| 83 |
/* Version 3.2.5 is where transient names were changed. They're prefixed now. */ |
| 84 |
{ |
| 85 |
$wpdb->query("DELETE FROM `".$wpdb->options."` WHERE `option_name` LIKE '\_transient\_%'"); |
| 86 |
} |
| 87 |
/**/ |
| 88 |
if(!$v || !version_compare($v, "3.2.6", ">=")) /* Needs to be upgraded? */ |
| 89 |
/* Version 3.2.6 fixed `s2member_ccaps_req` being stored empty and/or w/ one empty element in the array. */ |
| 90 |
{ |
| 91 |
$wpdb->query("DELETE FROM `".$wpdb->postmeta."` WHERE `meta_key` = 's2member_ccaps_req' AND `meta_value` IN('','a:0:{}','a:1:{i:0;s:0:\"\";}')"); |
| 92 |
} |
| 93 |
/**/ |
| 94 |
if(!$v || !version_compare($v, "110912", ">=") && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["filter_wp_query"] === array("all")) |
| 95 |
/* s2Member v110912 changed the way the "all" option for Alternative Views was handled. */ |
| 96 |
{ |
| 97 |
$notice = '<strong>IMPORTANT:</strong> This version of s2Member® changes the way your <code>Alternative View Protections</code> work. Please review your options under: <code>s2Member -> Restriction Options -> Alternative View Protections</code>.<br />'; |
| 98 |
c_ws_plugin__s2member_admin_notices::enqueue_admin_notice($notice, array("blog|network:plugins.php", "blog|network:ws-plugin--s2member-start", "blog|network:ws-plugin--s2member-mms-ops", "blog|network:ws-plugin--s2member-gen-ops", "blog|network:ws-plugin--s2member-res-ops")); |
| 99 |
} |
| 100 |
/**/ |
| 101 |
$notice = '<strong>s2Member</strong> has been <strong>reactivated</strong>, with '.(($reactivation_reason === "levels") ? '<code>'.esc_html($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]).'</code> Membership Levels' : 'the latest version').'.<br />'; |
| 102 |
$notice .= 'You now have version '.esc_html(WS_PLUGIN__S2MEMBER_VERSION).'. Your existing configuration remains.'; |
| 103 |
/**/ |
| 104 |
if(!is_multisite() || !c_ws_plugin__s2member_utils_conds::is_multisite_farm() || is_main_site()) /* No Changelog on a Multisite Blog Farm. */ |
| 105 |
$notice .= '<br />Have fun, <a href="'.esc_attr(admin_url("/admin.php?page=ws-plugin--s2member-info#rm-changelog")).'">read the Changelog</a>, and make some money! :-)'; |
| 106 |
/**/ |
| 107 |
c_ws_plugin__s2member_admin_notices::enqueue_admin_notice($notice, array("blog|network:plugins.php", "blog|network:ws-plugin--s2member-start", "blog|network:ws-plugin--s2member-mms-ops", "blog|network:ws-plugin--s2member-gen-ops", "blog|network:ws-plugin--s2member-res-ops")); |
| 108 |
} |
| 109 |
else /* Otherwise (initial activation); we'll help the Site Owner out by giving them a link to the Quick Start Guide. */ |
| 110 |
{ |
| 111 |
$notice = '<strong>Note:</strong> s2Member adds some new data columns to your list of Users/Members. If your list gets overcrowded, please use the <strong>Screen Options</strong> tab <em>( upper right-hand corner )</em>. With WordPress® Screen Options, you can add/remove specific data columns; thereby making the most important data easier to read. For example, if you create Custom Registration/Profile Fields with s2Member, those Custom Fields will result in new data columns; which can cause your list of Users/Members to become nearly unreadable. So just use the Screen Options tab to clean things up.'; |
| 112 |
/**/ |
| 113 |
c_ws_plugin__s2member_admin_notices::enqueue_admin_notice($notice, "blog:users.php", false, false, true); |
| 114 |
/**/ |
| 115 |
$notice = '<strong>s2Member</strong> v'.esc_html(WS_PLUGIN__S2MEMBER_VERSION).' has been <strong>activated</strong>. Nice work!<br />'; |
| 116 |
$notice .= 'Have fun, <a href="'.esc_attr(admin_url("/admin.php?page=ws-plugin--s2member-start")).'">read the Quick Start Guide</a>, and make some money! :-)'; |
| 117 |
/**/ |
| 118 |
c_ws_plugin__s2member_admin_notices::enqueue_admin_notice($notice, array("blog|network:plugins.php", "blog|network:ws-plugin--s2member-start", "blog|network:ws-plugin--s2member-mms-ops", "blog|network:ws-plugin--s2member-gen-ops", "blog|network:ws-plugin--s2member-res-ops")); |
| 119 |
} |
| 120 |
/**/ |
| 121 |
if(is_multisite() && is_main_site()) /* Network activation routines. */ |
| 122 |
{ |
| 123 |
$wpdb->query("INSERT INTO `".$wpdb->usermeta."` (`user_id`, `meta_key`, `meta_value`) SELECT `ID`, 's2member_originating_blog', '".esc_sql($current_site->blog_id)."' FROM `".$wpdb->users."` WHERE `ID` NOT IN (SELECT `user_id` FROM `".$wpdb->usermeta."` WHERE `meta_key` = 's2member_originating_blog')"); |
| 124 |
/**/ |
| 125 |
$notice = '<strong>Multisite Network</strong> updated automatically by <strong>s2Member</strong> v'.esc_html(WS_PLUGIN__S2MEMBER_VERSION).'.<br />'; |
| 126 |
$notice .= 'You\'ll want to configure s2Member\'s Multisite options now.<br />'; |
| 127 |
$notice .= 'In the Dashboard for your Main Site, see:<br />'; |
| 128 |
$notice .= '<code>s2Member -> Multisite ( Config )</code>.'; |
| 129 |
/**/ |
| 130 |
c_ws_plugin__s2member_admin_notices::enqueue_admin_notice($notice, array("blog|network:plugins.php", "blog|network:ws-plugin--s2member-start", "blog|network:ws-plugin--s2member-mms-ops", "blog|network:ws-plugin--s2member-gen-ops", "blog|network:ws-plugin--s2member-res-ops")); |
| 131 |
/**/ |
| 132 |
update_site_option("ws_plugin__s2member_options", (array)get_option("ws_plugin__s2member_options")); |
| 133 |
/**/ |
| 134 |
update_option("ws_plugin__s2member_activated_mms_version", WS_PLUGIN__S2MEMBER_VERSION); |
| 135 |
} |
| 136 |
/**/ |
| 137 |
update_option("ws_plugin__s2member_activated_version", WS_PLUGIN__S2MEMBER_VERSION); |
| 138 |
/**/ |
| 139 |
do_action("ws_plugin__s2member_after_activation", get_defined_vars()); |
| 140 |
/**/ |
| 141 |
return; /* Return for uniformity. */ |
| 142 |
} |
| 143 |
/** |
| 144 |
* Deactivation routines for s2Member. |
| 145 |
* |
| 146 |
* @package s2Member\Installation |
| 147 |
* @since 3.5 |
| 148 |
* |
| 149 |
* @return null |
| 150 |
*/ |
| 151 |
public static function deactivate() |
| 152 |
{ |
| 153 |
global $wpdb; /* Global database object reference. */ |
| 154 |
global $current_site, $current_blog; /* Multisite. */ |
| 155 |
/**/ |
| 156 |
do_action("ws_plugin__s2member_before_deactivation", get_defined_vars()); |
| 157 |
/**/ |
| 158 |
if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["run_deactivation_routines"]) |
| 159 |
{ |
| 160 |
c_ws_plugin__s2member_roles_caps::unlink_roles(); /* Unlink Roles/Caps. */ |
| 161 |
/**/ |
| 162 |
c_ws_plugin__s2member_files::remove_no_gzip_from_root_htaccess /* Remove GZIP exclusions. */(); |
| 163 |
/**/ |
| 164 |
if(is_dir($files_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"])) |
| 165 |
{ |
| 166 |
if(file_exists($htaccess = $files_dir."/.htaccess")) |
| 167 |
if(is_writable($htaccess)) |
| 168 |
unlink($htaccess); |
| 169 |
/**/ |
| 170 |
@rmdir($files_dir).@rmdir(c_ws_plugin__s2member_utils_dirs::strip_dir_app_data($files_dir)); |
| 171 |
} |
| 172 |
/**/ |
| 173 |
if(is_dir($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"])) |
| 174 |
{ |
| 175 |
foreach(scandir($logs_dir) as $log_file) |
| 176 |
if(is_file($log_file = $logs_dir."/".$log_file)) |
| 177 |
if(is_writable($log_file)) |
| 178 |
unlink($log_file); |
| 179 |
/**/ |
| 180 |
@rmdir($logs_dir).@rmdir(c_ws_plugin__s2member_utils_dirs::strip_dir_app_data($logs_dir)); |
| 181 |
} |
| 182 |
/**/ |
| 183 |
delete_option("ws_plugin__s2member_cache"); |
| 184 |
delete_option("ws_plugin__s2member_notices"); |
| 185 |
delete_option("ws_plugin__s2member_options"); |
| 186 |
delete_option("ws_plugin__s2member_configured"); |
| 187 |
delete_option("ws_plugin__s2member_activated_levels"); |
| 188 |
delete_option("ws_plugin__s2member_activated_version"); |
| 189 |
delete_option("ws_plugin__s2member_activated_mms_version"); |
| 190 |
/**/ |
| 191 |
if(is_multisite() && is_main_site()) /* Site options? */ |
| 192 |
delete_site_option("ws_plugin__s2member_options"); |
| 193 |
/**/ |
| 194 |
$wpdb->query("DELETE FROM `".$wpdb->options."` WHERE `option_name` LIKE '%".esc_sql(like_escape("s2member_"))."%'"); |
| 195 |
$wpdb->query("DELETE FROM `".$wpdb->options."` WHERE `option_name` LIKE '".esc_sql(like_escape("_transient_s2m_"))."%'"); |
| 196 |
$wpdb->query("DELETE FROM `".$wpdb->options."` WHERE `option_name` LIKE '".esc_sql(like_escape("_transient_timeout_s2m_"))."%'"); |
| 197 |
$wpdb->query("DELETE FROM `".$wpdb->postmeta."` WHERE `meta_key` LIKE '%".esc_sql(like_escape("s2member_"))."%'"); |
| 198 |
$wpdb->query("DELETE FROM `".$wpdb->usermeta."` WHERE `meta_key` LIKE '%".esc_sql(like_escape("s2member_"))."%'"); |
| 199 |
/**/ |
| 200 |
do_action("ws_plugin__s2member_during_deactivation", get_defined_vars()); |
| 201 |
} |
| 202 |
/**/ |
| 203 |
do_action("ws_plugin__s2member_after_deactivation", get_defined_vars()); |
| 204 |
/**/ |
| 205 |
return; /* Return for uniformity. */ |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
?> |