PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110710
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110710
260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 120219 All 188 releases
s2member / includes / classes / installation.inc.php

installation.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 110710, at includes/classes/installation.inc.php

213 lines 12.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 /**/
47 update_option ("ws_plugin__s2member_activated_levels", $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]);
48 /**/
49 if (!is_dir ($files_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"]))
50 if (is_writable (dirname (c_ws_plugin__s2member_utils_dirs::strip_dir_app_data ($files_dir))))
51 mkdir ($files_dir, 0777, true);
52 /**/
53 if (is_dir ($files_dir) && is_writable ($files_dir))
54 if (!file_exists ($htaccess = $files_dir . "/.htaccess"))
55 file_put_contents ($htaccess, "deny from all");
56 /**/
57 if (!is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
58 if (is_writable (dirname (c_ws_plugin__s2member_utils_dirs::strip_dir_app_data ($logs_dir))))
59 mkdir ($logs_dir, 0777, true);
60 /**/
61 if (is_dir ($logs_dir) && is_writable ($logs_dir))
62 if (!file_exists ($htaccess = $logs_dir . "/.htaccess"))
63 file_put_contents ($htaccess, "deny from all");
64 /**/
65 (!is_array (get_option ("ws_plugin__s2member_cache"))) ? update_option ("ws_plugin__s2member_cache", array ()) : null;
66 (!is_array (get_option ("ws_plugin__s2member_notices"))) ? update_option ("ws_plugin__s2member_notices", array ()) : null;
67 (!is_array (get_option ("ws_plugin__s2member_options"))) ? update_option ("ws_plugin__s2member_options", array ()) : null;
68 (!is_numeric (get_option ("ws_plugin__s2member_configured"))) ? update_option ("ws_plugin__s2member_configured", "0") : null;
69 /**/
70 if ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["configured"]) /* If already configured, we are re-activating. */
71 {
72 $v = get_option ("ws_plugin__s2member_activated_version");
73 /**/
74 if (!$v || !version_compare ($v, "3.2", ">=")) /* Needs to be upgraded? */
75 /* Version 3.2 is where `meta_key` names were changed. They're prefixed now. */
76 {
77 $like = "`meta_key` LIKE 's2member\_%' AND `meta_key` NOT LIKE '%s2member\_originating\_blog%'";
78 $wpdb->query ("UPDATE `" . $wpdb->usermeta . "` SET `meta_key` = CONCAT('" . $wpdb->prefix . "', `meta_key`) WHERE " . $like);
79 }
80 /**/
81 if (!$v || !version_compare ($v, "3.2.5", ">=")) /* Needs to be upgraded? */
82 /* Version 3.2.5 is where transient names were changed. They're prefixed now. */
83 {
84 $wpdb->query ("DELETE FROM `" . $wpdb->options . "` WHERE `option_name` LIKE '\_transient\_%'");
85 }
86 /**/
87 if (!$v || !version_compare ($v, "3.2.6", ">=")) /* Needs to be upgraded? */
88 /* Version 3.2.6 fixed `s2member_ccaps_req` being stored empty and/or w/ one empty element in the array. */
89 {
90 $wpdb->query ("DELETE FROM `" . $wpdb->postmeta . "` WHERE `meta_key` = 's2member_ccaps_req' AND `meta_value` IN('','a:0:{}','a:1:{i:0;s:0:\"\";}')");
91 }
92 /**/
93 if (!$v || !version_compare ($v, "3.5", ">=")) /* Needs to be notified about Screen Options? */
94 /* Version 3.5 introduced a dismissal message regarding Screen Options in the list of Users/Members. */
95 {
96 $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 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.';
97 c_ws_plugin__s2member_admin_notices::enqueue_admin_notice ($notice, "blog:users.php", false, false, true);
98 }
99 /**/
100 $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 />';
101 $notice .= 'You now have version ' . esc_html (WS_PLUGIN__S2MEMBER_VERSION) . '. Your existing configuration remains.';
102 /**/
103 if (!is_multisite () || !c_ws_plugin__s2member_utils_conds::is_multisite_farm () || is_main_site ()) /* No Changelog on a Multisite Farm. */
104 $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! :-)';
105 /**/
106 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"));
107 /**/
108 if (preg_match ("/^win/i", PHP_OS) && is_dir (c_ws_plugin__s2member_utils_dirs::strip_dir_app_data ($files_dir)) && count (scandir (c_ws_plugin__s2member_utils_dirs::strip_dir_app_data ($files_dir))) > 4)
109 {
110 $notice = '<strong>Windows® Server ( NOTICE ):</strong> Your protected files MUST be moved to the <code>/app_data</code> sub-directory. For further details, see: <code>s2Member -> Download Options -> Basic</code>.';
111 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"), true);
112 }
113 }
114 else /* Otherwise, (initial activation); we'll help the Site Owner out by giving them a link to the Quick Start Guide. */
115 {
116 $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 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.';
117 /**/
118 c_ws_plugin__s2member_admin_notices::enqueue_admin_notice ($notice, "blog:users.php", false, false, true);
119 /**/
120 $notice = '<strong>s2Member</strong> v' . esc_html (WS_PLUGIN__S2MEMBER_VERSION) . ' has been <strong>activated</strong>. Nice work!<br />';
121 $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! :-)';
122 /**/
123 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"));
124 }
125 /**/
126 update_option ("ws_plugin__s2member_activated_version", WS_PLUGIN__S2MEMBER_VERSION); /* Mark version. */
127 /**/
128 if (is_multisite () && is_main_site ()) /* Network activation routines. A few quick adjustments. */
129 {
130 foreach ((array)($users = $wpdb->get_results ("SELECT `ID` FROM `" . $wpdb->users . "`")) as $user)
131 {
132 /* Here we convert everyone already in the system; without a point of origin.
133 This will set their point of origin to the Main Site. */
134 if (!($originating_blog = get_user_meta ($user->ID, "s2member_originating_blog", true)))
135 update_user_meta ($user->ID, "s2member_originating_blog", $current_site->blog_id);
136 }
137 /**/
138 $notice = '<strong>Multisite Network</strong> updated automatically by <strong>s2Member</strong> v' . esc_html (WS_PLUGIN__S2MEMBER_VERSION) . '.<br />';
139 $notice .= 'You\'ll want to configure s2Member\'s Multisite options now.<br />';
140 $notice .= 'In the Dashboard for your Main Site, see:<br />';
141 $notice .= '<code>s2Member -> Multisite ( Config )</code>.';
142 /**/
143 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"));
144 /**/
145 update_option ("ws_plugin__s2member_activated_mms_version", WS_PLUGIN__S2MEMBER_VERSION);
146 }
147 /**/
148 do_action ("ws_plugin__s2member_after_activation", get_defined_vars ());
149 /**/
150 return; /* Return for uniformity. */
151 }
152 /**
153 * Deactivation routines for s2Member.
154 *
155 * @package s2Member\Installation
156 * @since 3.5
157 *
158 * @return null
159 */
160 public static function deactivate ()
161 {
162 global $wpdb; /* Global database object reference. */
163 global $current_site, $current_blog; /* Multisite. */
164 /**/
165 do_action ("ws_plugin__s2member_before_deactivation", get_defined_vars ());
166 /**/
167 if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["run_deactivation_routines"])
168 {
169 c_ws_plugin__s2member_roles_caps::unlink_roles (); /* Unlink Roles/Caps. */
170 /**/
171 if (is_dir ($files_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"]))
172 {
173 if (file_exists ($htaccess = $files_dir . "/.htaccess"))
174 if (is_writable ($htaccess))
175 unlink($htaccess);
176 /**/
177 @rmdir($files_dir) . @rmdir (c_ws_plugin__s2member_utils_dirs::strip_dir_app_data ($files_dir));
178 }
179 /**/
180 if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
181 {
182 foreach (scandir ($logs_dir) as $log_file)
183 if (is_file ($log_file = $logs_dir . "/" . $log_file))
184 if (is_writable ($log_file))
185 unlink($log_file);
186 /**/
187 @rmdir($logs_dir) . @rmdir (c_ws_plugin__s2member_utils_dirs::strip_dir_app_data ($logs_dir));
188 }
189 /**/
190 delete_option("ws_plugin__s2member_cache");
191 delete_option("ws_plugin__s2member_notices");
192 delete_option("ws_plugin__s2member_options");
193 delete_option("ws_plugin__s2member_configured");
194 delete_option("ws_plugin__s2member_activated_levels");
195 delete_option("ws_plugin__s2member_activated_version");
196 delete_option("ws_plugin__s2member_activated_mms_version");
197 /**/
198 $wpdb->query ("DELETE FROM `" . $wpdb->options . "` WHERE `option_name` LIKE '%" . esc_sql (like_escape ("s2member_")) . "%'");
199 $wpdb->query ("DELETE FROM `" . $wpdb->options . "` WHERE `option_name` LIKE '" . esc_sql (like_escape ("_transient_s2m_")) . "%'");
200 $wpdb->query ("DELETE FROM `" . $wpdb->options . "` WHERE `option_name` LIKE '" . esc_sql (like_escape ("_transient_timeout_s2m_")) . "%'");
201 $wpdb->query ("DELETE FROM `" . $wpdb->postmeta . "` WHERE `meta_key` LIKE '%" . esc_sql (like_escape ("s2member_")) . "%'");
202 $wpdb->query ("DELETE FROM `" . $wpdb->usermeta . "` WHERE `meta_key` LIKE '%" . esc_sql (like_escape ("s2member_")) . "%'");
203 /**/
204 do_action ("ws_plugin__s2member_during_deactivation", get_defined_vars ());
205 }
206 /**/
207 do_action ("ws_plugin__s2member_after_deactivation", get_defined_vars ());
208 /**/
209 return; /* Return for uniformity. */
210 }
211 }
212 }
213 ?>