Simple Membership - Version 1.5

Version Description

  • Fixed a bug with sending member email when added via admin dashboard.
  • Fixed a bug with general settings values resetting.
  • Added a few action hooks to the plugin.
Download this release

Release Info

Developer mra13
Plugin Icon 128x128 Simple Membership
Version 1.5
Comparing to
See all releases

Version 1.5

Files changed (64) hide show
  1. classes/class.bAccessControl.php +66 -0
  2. classes/class.bAdminRegistration.php +72 -0
  3. classes/class.bAjax.php +31 -0
  4. classes/class.bAuth.php +209 -0
  5. classes/class.bForm.php +280 -0
  6. classes/class.bFrontForm.php +7 -0
  7. classes/class.bFrontRegistration.php +196 -0
  8. classes/class.bInstallation.php +174 -0
  9. classes/class.bLevelForm.php +62 -0
  10. classes/class.bLog.php +77 -0
  11. classes/class.bMembers.php +178 -0
  12. classes/class.bMembershipLevel.php +63 -0
  13. classes/class.bMembershipLevelCustom.php +93 -0
  14. classes/class.bMembershipLevelUtils.php +8 -0
  15. classes/class.bMembershipLevels.php +141 -0
  16. classes/class.bMessages.php +23 -0
  17. classes/class.bPermission.php +55 -0
  18. classes/class.bProtection.php +66 -0
  19. classes/class.bProtectionBase.php +259 -0
  20. classes/class.bRegistration.php +48 -0
  21. classes/class.bSession.php +0 -0
  22. classes/class.bSettings.php +318 -0
  23. classes/class.bTransfer.php +63 -0
  24. classes/class.bUtils.php +181 -0
  25. classes/class.miscUtils.php +143 -0
  26. classes/class.simple-wp-membership.php +502 -0
  27. css/jquery.tools.dateinput.css +159 -0
  28. css/swpm.common.css +29 -0
  29. css/validationEngine.jquery.css +143 -0
  30. images/join-now-button-image.gif +0 -0
  31. images/logo.png +0 -0
  32. images/logo2.png +0 -0
  33. images/next.gif +0 -0
  34. images/prev.gif +0 -0
  35. images/simple-membership-content-protection-usage.png +0 -0
  36. ipn/swpm_handle_pp_ipn.php +328 -0
  37. ipn/swpm_handle_subsc_ipn.php +219 -0
  38. js/jquery.tools18.min.js +51 -0
  39. js/jquery.validationEngine-en.js +210 -0
  40. js/jquery.validationEngine.js +1194 -0
  41. js/swpm.password-meter.js +38 -0
  42. log.txt +0 -0
  43. readme.txt +92 -0
  44. simple-wp-membership.php +37 -0
  45. views/add.php +82 -0
  46. views/admin_add.php +28 -0
  47. views/admin_add_level.php +72 -0
  48. views/admin_edit.php +24 -0
  49. views/admin_edit_level.php +71 -0
  50. views/admin_member_form_common_part.php +88 -0
  51. views/admin_members.php +21 -0
  52. views/admin_membership_level_menu.php +4 -0
  53. views/admin_membership_levels.php +24 -0
  54. views/admin_membership_manage.php +22 -0
  55. views/admin_payment_settings.php +48 -0
  56. views/admin_settings.php +11 -0
  57. views/admin_tools_settings.php +42 -0
  58. views/edit.php +61 -0
  59. views/forgot_password.php +17 -0
  60. views/join_us.php +0 -0
  61. views/loggedin.php +17 -0
  62. views/login.php +37 -0
  63. views/login_widget.php +16 -0
  64. views/login_widget_logged.php +15 -0
classes/class.bAccessControl.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class BAccessControl {
3
+ private $lastError;
4
+ private $moretags;
5
+ private static $_this;
6
+ private function __construct(){
7
+ $this->lastError = '';
8
+ $this->moretags = array();
9
+ }
10
+ public static function get_instance(){
11
+ self::$_this = empty(self::$_this)? new BAccessControl():self::$_this;
12
+ return self::$_this;
13
+ }
14
+
15
+ public function can_i_read_post($id){
16
+ $this->lastError = '';
17
+ $protected = BProtection::get_instance();
18
+ if ($protected->is_protected($id)){
19
+ $auth = BAuth::get_instance();
20
+ if($auth->is_logged_in()){
21
+ $perms = BPermission::get_instance($auth->get('membership_level'));
22
+ if($perms->is_permitted($id))return true;
23
+ $this->lastError ='You are not allowed to view this content' ;
24
+ return false;
25
+ }
26
+ $this->lastError ='You need to login to view this content. '
27
+ . BSettings::get_instance()->get_login_link();
28
+ return false;
29
+ }
30
+ return true;
31
+ }
32
+ public function can_i_read_comment($id){
33
+ $this->lastError = '';
34
+ $protected = BProtection::get_instance();
35
+ if ($protected->is_protected_comment($id)){
36
+ $auth = BAuth::get_instance();
37
+ if($auth->is_logged_in()){
38
+ $perms = BPermission::get_instance($auth->get('membership_level'));
39
+ if($perms->is_permitted_comment($id))return true;
40
+ $this->lastError ="You are not allowed to view this content";
41
+ return false;
42
+ }
43
+ $this->lastError ="You need to login to view this content. "
44
+ . BSettings::get_instance()->get_login_link();
45
+ return false;
46
+ }
47
+ return true;
48
+ }
49
+ public function why(){
50
+ return $this->lastError;
51
+ }
52
+ public function filter_post($id,$content){
53
+ //if(in_array($id, $this->moretags)) return $content;
54
+ if($this->can_i_read_post($id)) return $content;
55
+ return $this->lastError;
56
+ }
57
+ public function filter_comment($id,$content){
58
+ if($this->can_i_read_comment($id)) return $content;
59
+ return $this->lastError;
60
+ }
61
+ public function filter_post_with_moretag($id, $content){
62
+ $this->moretags[] = $id;
63
+ if($this->can_i_read_post($id)) return $content;
64
+ return $this->lastError;
65
+ }
66
+ }
classes/class.bAdminRegistration.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Description of BAdminRegistration
5
+ *
6
+ * @author nur
7
+ */
8
+ class BAdminRegistration extends BRegistration {
9
+ protected static $__CLASS__ = __CLASS__;
10
+ public function show_form() {
11
+
12
+ }
13
+
14
+ public function register() {
15
+ global $wpdb;
16
+ $member = BTransfer::$default_fields;
17
+ $form = new BForm($member);
18
+ if ($form->is_valid()) {
19
+ $member_info = $form->get_sanitized();
20
+ $member_info['account_state'] = 'active';
21
+ $plain_password = $member_info['plain_password'];
22
+ unset($member_info['plain_password']);
23
+ $wpdb->insert($wpdb->prefix . "swpm_members_tbl", $member_info);
24
+ /* * ******************** register to wordpress ********** */
25
+ $query = "SELECT role FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id = " . $member_info['membership_level'];
26
+ $wp_user_info = array();
27
+ $wp_user_info['user_nicename'] = implode('-', explode(' ', $member_info['user_name']));
28
+ $wp_user_info['display_name'] = $member_info['user_name'];
29
+ $wp_user_info['user_email'] = $member_info['email'];
30
+ $wp_user_info['nickname'] = $member_info['user_name'];
31
+ $wp_user_info['first_name'] = $member_info['first_name'];
32
+ $wp_user_info['last_name'] = $member_info['last_name'];
33
+ $wp_user_info['user_login'] = $member_info['user_name'];
34
+ $wp_user_info['password'] = $plain_password;
35
+ $wp_user_info['role'] = $wpdb->get_var($query);
36
+ $wp_user_info['user_registered'] = date('Y-m-d H:i:s');
37
+ BUtils::create_wp_user($wp_user_info);
38
+ /* * ******************** register to wordpress ********** */
39
+ $send_notification = BSettings::get_instance()->get_value('enable-notification-after-manual-user-add');
40
+ $member_info['plain_password'] = $plain_password;
41
+ $this->member_info = $member_info;
42
+ if (!empty($send_notification)){
43
+ $this->send_reg_email();
44
+ }
45
+ $message = array('succeeded' => true, 'message' => 'Registration Successful.');
46
+ BTransfer::get_instance()->set('status', $message);
47
+ wp_redirect('admin.php?page=simple_wp_membership');
48
+ return;
49
+ }
50
+ $message = array('succeeded' => false, 'message' => 'Please correct the following:', 'extra' => $form->get_errors());
51
+ BTransfer::get_instance()->set('status', $message);
52
+ }
53
+ public function edit($id){
54
+ global $wpdb;
55
+ $query = "SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE member_id = $id";
56
+ $member = $wpdb->get_row($query, ARRAY_A);
57
+ unset($member['member_id']);
58
+ unset($member['email']);
59
+ unset($member['user_name']);
60
+ $form = new BForm($member);
61
+ if ($form->is_valid()) {
62
+ $member = $form->get_sanitized();
63
+ unset($member['plain_password']);
64
+ $wpdb->update($wpdb->prefix . "swpm_members_tbl", $member, array('member_id' => $id));
65
+ $message = array('succeeded' => true, 'message' => 'Updated Successfully.');
66
+ BTransfer::get_instance()->set('status', $message);
67
+ wp_redirect('admin.php?page=simple_wp_membership');
68
+ }
69
+ $message = array('succeeded' => false, 'message' => 'Please correct the following:', 'extra' => $form->get_errors());
70
+ BTransfer::get_instance()->set('status', $message);
71
+ }
72
+ }
classes/class.bAjax.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Description of BAjax
4
+ *
5
+ * @author nur
6
+ */
7
+ class BAjax {
8
+ public static function validate_email_ajax() {
9
+ global $wpdb;
10
+ $field_value = filter_input(INPUT_GET, 'fieldValue');
11
+ $field_id = filter_input(INPUT_GET, 'fieldId');
12
+ $table = $wpdb->prefix . "swpm_members_tbl";
13
+ $email = esc_sql($field_value);
14
+ $query = $wpdb->prepare("SELECT COUNT(*) FROM $table WHERE email = %s", $email);
15
+ $exists = $wpdb->get_var($query) > 0;
16
+ echo '[ "' . $field_id . (($exists) ? '",false, "&chi;&nbsp;Aready taken"]' : '",true, "&radic;&nbsp;Available"]');
17
+ exit;
18
+ }
19
+
20
+ public static function validate_user_name_ajax() {
21
+ global $wpdb;
22
+ $field_value = filter_input(INPUT_GET, 'fieldValue');
23
+ $field_id = filter_input(INPUT_GET, 'fieldId');
24
+ $table = $wpdb->prefix . "swpm_members_tbl";
25
+ $user = esc_sql($field_value);
26
+ $query = $wpdb->prepare("SELECT COUNT(*) FROM $table WHERE user_name = %s", $user);
27
+ $exists = $wpdb->get_var($query) > 0;
28
+ echo '[ "' . $field_id . (($exists) ? '",false,"&chi;&nbsp;Aready taken"]' : '",true,"&radic;&nbsp;Available"]');
29
+ exit;
30
+ }
31
+ }
classes/class.bAuth.php ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class BAuth {
4
+
5
+ public $protected;
6
+ public $permitted;
7
+ private $isLoggedIn;
8
+ private $lastStatusMsg;
9
+ private static $_this;
10
+ public $userData;
11
+
12
+ private function __construct() {
13
+ $this->isLoggedIn = false;
14
+ $this->userData = null;
15
+ $this->protected = BProtection::get_instance();
16
+ if (!$this->validate()){
17
+ $this->authenticate();
18
+ }
19
+ }
20
+
21
+ public static function get_instance() {
22
+ self::$_this = empty(self::$_this) ? new BAuth() : self::$_this;
23
+ return self::$_this;
24
+ }
25
+
26
+ private function authenticate() {
27
+ global $wpdb;
28
+ $swpm_user_name = filter_input(INPUT_POST, 'swpm_user_name');
29
+ $swpm_password = filter_input(INPUT_POST, 'swpm_password');
30
+ if (!empty($swpm_user_name) && !empty($swpm_password)) {
31
+ $user = sanitize_user($swpm_user_name);
32
+ $pass = trim($swpm_password);
33
+ $query = " SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl";
34
+ $query.= " WHERE user_name = '" . $user . "'";
35
+ $userData = $wpdb->get_row($query);
36
+ $this->userData = $userData;
37
+ if (!$userData) {
38
+ $this->isLoggedIn = false;
39
+ $this->userData = null;
40
+ $this->lastStatusMsg = "User Not Found.";
41
+ return false;
42
+ }
43
+ $check = $this->check_password($pass, $userData->password);
44
+ if (!$check) {
45
+ $this->isLoggedIn = false;
46
+ $this->userData = null;
47
+ $this->lastStatusMsg = "Password Empty or Invalid.";
48
+ return false;
49
+ }
50
+ if ($this->check_constraints()) {
51
+ $rememberme = filter_input(INPUT_POST, 'rememberme');
52
+ $remember = empty($rememberme) ? false : true;
53
+ $this->set_cookie($remember);
54
+ $this->isLoggedIn = true;
55
+ $this->lastStatusMsg = "Logged In.";
56
+ do_action('swpm_login', $user, $pass, $remember);
57
+ return true;
58
+ }
59
+ }
60
+ return false;
61
+ }
62
+
63
+ private function check_constraints() {
64
+ if (empty($this->userData)){
65
+ return false;
66
+ }
67
+ $permission = BPermission::get_instance($this->userData->membership_level);
68
+ $valid = true;
69
+ if ($this->userData->account_state != 'active') {
70
+ $this->lastStatusMsg = 'Account is inactive.';
71
+ $valid = false;
72
+ }
73
+ if (!$valid) {
74
+ $this->isLoggedIn = false;
75
+ $this->userData = null;
76
+ return false;
77
+ }
78
+ //:todo check if account expired and update db if it did.
79
+ $this->userData->permitted = $permission;
80
+ $this->lastStatusMsg = "You are logged in as:" . $this->userData->user_name;
81
+ $this->isLoggedIn = true;
82
+ return true;
83
+ }
84
+
85
+ private function check_password($password, $hash) {
86
+ global $wp_hasher;
87
+ if (empty($password)){
88
+ return false;
89
+ }
90
+ if (empty($wp_hasher)) {
91
+ require_once( ABSPATH . 'wp-includes/class-phpass.php');
92
+ $wp_hasher = new PasswordHash(8, TRUE);
93
+ }
94
+ return $wp_hasher->CheckPassword($password, $hash);
95
+ }
96
+
97
+ public function login($user, $pass, $remember = '', $secure = '') {
98
+ if ($this->isLoggedIn){
99
+ return;
100
+ }
101
+ if ($this->authenticate($user, $pass) && $this->validate()) {
102
+ $this->set_cookie($remember, $secure);
103
+ } else {
104
+ $this->isLoggedIn = false;
105
+ $this->userData = null;
106
+ }
107
+ return $this->lastStatusMsg;
108
+ }
109
+
110
+ public function logout() {
111
+ if (!$this->isLoggedIn){
112
+ return;
113
+ }
114
+ setcookie(SIMPLE_WP_MEMBERSHIP_AUTH, ' ', time() - YEAR_IN_SECONDS, "/", COOKIE_DOMAIN);
115
+ setcookie(SIMPLE_WP_MEMBERSHIP_SEC_AUTH, ' ', time() - YEAR_IN_SECONDS, "/", COOKIE_DOMAIN);
116
+ $this->userData = null;
117
+ $this->isLoggedIn = false;
118
+ $this->lastStatusMsg = "Logged Out Successfully.";
119
+ do_action('swpm_logout');
120
+ }
121
+
122
+ private function set_cookie($remember = '', $secure = '') {
123
+ if ($remember){
124
+ $expire = time() + 1209600;
125
+ }
126
+ else{
127
+ $expire = time() + 172800;
128
+ }
129
+ $pass_frag = substr($this->userData->password, 8, 4);
130
+ $scheme = 'auth';
131
+ if (!$secure){
132
+ $secure = is_ssl();
133
+ }
134
+ $key = BAuth::b_hash($this->userData->user_name . $pass_frag . '|' . $expire, $scheme);
135
+ $hash = hash_hmac('md5', $this->userData->user_name . '|' . $expire, $key);
136
+ $auth_cookie = $this->userData->user_name . '|' . $expire . '|' . $hash;
137
+ $auth_cookie_name = $secure ? SIMPLE_WP_MEMBERSHIP_SEC_AUTH : SIMPLE_WP_MEMBERSHIP_AUTH;
138
+ //setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true);
139
+ setcookie($auth_cookie_name, $auth_cookie, $expire, "/", COOKIE_DOMAIN, $secure, true);
140
+ }
141
+
142
+ private function validate() {
143
+ $auth_cookie_name = is_ssl() ? SIMPLE_WP_MEMBERSHIP_SEC_AUTH : SIMPLE_WP_MEMBERSHIP_AUTH;
144
+ if (!isset($_COOKIE[$auth_cookie_name]) || empty($_COOKIE[$auth_cookie_name])){
145
+ return false;
146
+ }
147
+ $cookie_elements = explode('|', $_COOKIE[$auth_cookie_name]);
148
+ if (count($cookie_elements) != 3){
149
+ return false;
150
+ }
151
+ list($username, $expiration, $hmac) = $cookie_elements;
152
+ $expired = $expiration;
153
+ // Allow a grace period for POST and AJAX requests
154
+ if (defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD']){
155
+ $expired += HOUR_IN_SECONDS;
156
+ }
157
+ // Quick check to see if an honest cookie has expired
158
+ if ($expired < time()) {
159
+ $this->lastStatusMsg = "Session Expired."; //do_action('auth_cookie_expired', $cookie_elements);
160
+ return false;
161
+ }
162
+ global $wpdb;
163
+ $query = " SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl";
164
+ $query.= " WHERE user_name = '" . $username . "'";
165
+ $user = $wpdb->get_row($query);
166
+ if (!$user) {
167
+ $this->lastStatusMsg = "Invalid User Name";
168
+ return false;
169
+ }
170
+
171
+ $pass_frag = substr($user->password, 8, 4);
172
+ $key = BAuth::b_hash($username . $pass_frag . '|' . $expiration);
173
+ $hash = hash_hmac('md5', $username . '|' . $expiration, $key);
174
+ if ($hmac != $hash) {
175
+ $this->lastStatusMsg = "Bad Cookie Hash";
176
+ return false;
177
+ }
178
+
179
+ if ($expiration < time()){
180
+ $GLOBALS['login_grace_period'] = 1;
181
+ }
182
+ $this->userData = $user;
183
+ return $this->check_constraints();
184
+ }
185
+
186
+ public static function b_hash($data, $scheme = 'auth') {
187
+ $salt = wp_salt($scheme) . 'j4H!B3TA,J4nIn4.';
188
+ return hash_hmac('md5', $data, $salt);
189
+ }
190
+
191
+ public function is_logged_in() {
192
+ return $this->isLoggedIn;
193
+ }
194
+
195
+ public function get($key, $default = "") {
196
+ if (isset($this->userData->$key)){
197
+ return $this->userData->$key;
198
+ }
199
+ if (isset($this->userData->permitted->$key)){
200
+ return $this->userData->permitted->$key;
201
+ }
202
+ return $default;
203
+ }
204
+
205
+ public function get_message() {
206
+ return $this->lastStatusMsg;
207
+ }
208
+
209
+ }
classes/class.bForm.php ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class BForm {
4
+
5
+ protected $fields;
6
+ protected $op;
7
+ protected $errors;
8
+ protected $sanitized;
9
+
10
+ public function __construct($fields) {
11
+ $this->fields = $fields;
12
+ ;
13
+ $this->sanitized = array();
14
+ foreach ($fields as $key => $value){
15
+ $this->$key();
16
+ }
17
+ }
18
+
19
+ protected function user_name() {
20
+ global $wpdb;
21
+ if (!empty($this->fields['user_name'])){return;}
22
+ $user_name = filter_input(INPUT_POST, 'user_name',FILTER_SANITIZE_STRING);
23
+ if (empty($user_name)) {
24
+ $this->errors['user_name'] = 'User name is required';
25
+ return;
26
+ }
27
+ $saned = sanitize_text_field($user_name);
28
+ $query = "SELECT count(member_id) FROM {$wpdb->prefix}swpm_members_tbl WHERE user_name= '" .
29
+ strip_tags($saned) . "'";
30
+ $result = $wpdb->get_var($query);
31
+ if ($result > 0) {
32
+ if ($saned != $this->fields['user_name']) {
33
+ $this->errors['user_name'] = 'User name already exists.';
34
+ return;
35
+ }
36
+ }
37
+ $this->sanitized['user_name'] = $saned;
38
+ }
39
+
40
+ protected function first_name() {
41
+ $first_name = filter_input(INPUT_POST, 'first_name', FILTER_SANITIZE_STRING);
42
+ if (empty($first_name)) {return;}
43
+ $this->sanitized['first_name'] = sanitize_text_field($first_name);
44
+ }
45
+
46
+ protected function last_name() {
47
+ $last_name = filter_input(INPUT_POST, 'last_name', FILTER_SANITIZE_STRING);
48
+ if (empty($last_name)) {return;}
49
+ $this->sanitized['last_name'] = sanitize_text_field($last_name);
50
+ }
51
+
52
+ protected function password() {
53
+ $password = filter_input(INPUT_POST, 'password',FILTER_UNSAFE_RAW);
54
+ $password_re = filter_input(INPUT_POST, 'password_re',FILTER_UNSAFE_RAW);
55
+ if (empty($this->fields['password']) && empty($password)) {
56
+ $this->errors['password'] = 'Password is required';
57
+ return;
58
+ }
59
+ if (!empty($password)) {
60
+ $saned = sanitize_text_field($password);
61
+ $saned_re = sanitize_text_field($password_re);
62
+ if ($saned != $saned_re){
63
+ $this->errors['password'] = 'Password mismatch';
64
+ }
65
+ include_once(ABSPATH . WPINC . '/class-phpass.php');
66
+ $wp_hasher = new PasswordHash(8, TRUE);
67
+ $this->sanitized['plain_password'] = $password;
68
+ $this->sanitized['password'] = $wp_hasher->HashPassword(trim($password)); //should use $saned??;
69
+ }
70
+ }
71
+
72
+ protected function email() {
73
+ global $wpdb;
74
+ if (!empty($this->fields['email'])){
75
+ return;
76
+ }
77
+ $email = filter_input(INPUT_POST, 'email', FILTER_UNSAFE_RAW);
78
+ if (empty($email)) {
79
+ $this->errors['email'] = 'Email is required';
80
+ return;
81
+ }
82
+ if (!is_email($email)) {
83
+ $this->errors['email'] = 'Email is invalid';
84
+ return;
85
+ }
86
+ $saned = sanitize_email($email);
87
+ $query = "SELECT count(member_id) FROM {$wpdb->prefix}swpm_members_tbl WHERE email= '" .
88
+ strip_tags($saned) . "'";
89
+ $member_id = filter_input(INPUT_GET, 'member_id', FILTER_SANITIZE_NUMBER_INT);
90
+ if (!empty($member_id)) {
91
+ $query .= ' AND member_id !=' . $member_id;
92
+ }
93
+ $result = $wpdb->get_var($query);
94
+ if ($result > 0) {
95
+ if ($saned != $this->fields['email']) {
96
+ $this->errors['email'] = 'Email is already used.';
97
+ return;
98
+ }
99
+ }
100
+ $this->sanitized['email'] = $saned;
101
+ }
102
+
103
+ protected function phone() {
104
+ $phone = filter_input(INPUT_POST, 'phone', FILTER_UNSAFE_RAW);
105
+ if (empty($phone)) {return;}
106
+ $saned = wp_kses($phone, array());
107
+ $this->sanitized['phone'] = $saned;
108
+ if (strlen($saned) > 9 && preg_match('/^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$/', $saned)){
109
+ $this->sanitized['phone'] = $saned;
110
+ }
111
+ else{
112
+ $this->errors['phone'] = 'Phone number is invalid';
113
+ }
114
+ }
115
+
116
+ protected function address_street() {
117
+ $address_street = filter_input(INPUT_POST, 'address_street', FILTER_SANITIZE_STRING);
118
+ if (empty($address_street)) { return;}
119
+ $this->sanitized['address_street'] = wp_kses($address_street, array());
120
+ }
121
+
122
+ protected function address_city() {
123
+ $address_city = filter_input(INPUT_POST, 'address_city', FILTER_SANITIZE_STRING);
124
+ if (empty($address_city)){ return; }
125
+ $this->sanitized['address_city'] = wp_kses($address_city, array());
126
+ }
127
+
128
+ protected function address_state() {
129
+ $address_state = filter_input(INPUT_POST, 'address_state', FILTER_SANITIZE_STRING);
130
+ if (empty($address_state)) {return;}
131
+ $this->sanitized['address_state'] = wp_kses($address_state, array());
132
+ }
133
+
134
+ protected function address_zipcode() {
135
+ $address_zipcode = filter_input(INPUT_POST, 'address_zipcode', FILTER_UNSAFE_RAW);
136
+ if (empty($address_zipcode)){ return;}
137
+ $this->sanitized['address_zipcode'] = wp_kses($address_zipcode, array());
138
+ }
139
+
140
+ protected function country() {
141
+ $country = filter_input(INPUT_POST, 'country', FILTER_SANITIZE_STRING);
142
+ if (empty($country)){ return;}
143
+ $this->sanitized['country'] = wp_kses($country, array());
144
+ }
145
+
146
+ protected function company_name() {
147
+ $company_name = filter_input(INPUT_POST, 'company_name', FILTER_SANITIZE_STRING);
148
+ $this->sanitized['company_name'] = $company_name;
149
+ }
150
+
151
+ protected function member_since() {
152
+ $member_since = filter_input(INPUT_POST, 'member_since', FILTER_UNSAFE_RAW);
153
+ if (empty($member_since)) {return;}
154
+ if (preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $member_since)){
155
+ $this->sanitized['member_since'] = sanitize_text_field($member_since);
156
+ return;
157
+ }
158
+ $this->errors['member_since'] = 'Member since field is invalid';
159
+
160
+ }
161
+
162
+ protected function subscription_starts() {
163
+ $subscription_starts = filter_input(INPUT_POST, 'subscription_starts', FILTER_SANITIZE_STRING);
164
+ if(empty($subscription_starts)) {return ;}
165
+ if (preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $subscription_starts)){
166
+ $this->sanitized['subscription_starts'] = sanitize_text_field($subscription_starts);
167
+ return;
168
+ }
169
+ $this->errors['subscription_starts'] = 'Subscription starts field is invalid';
170
+ }
171
+
172
+ protected function gender() {
173
+ $gender = filter_input(INPUT_POST, 'gender', FILTER_SANITIZE_STRING);
174
+ if(empty($gender)) {return;}
175
+ if (in_array($gender, array('male', 'female', 'not specified'))){
176
+ $this->sanitized['gender'] = $gender;
177
+ }
178
+ else{
179
+ $this->errors['gender'] = 'Gender field is invalid';
180
+ }
181
+ }
182
+
183
+ protected function account_state() {
184
+ $account_state = filter_input(INPUT_POST, 'account_state', FILTER_SANITIZE_STRING);
185
+ if(empty($account_state)) {return;}
186
+ if (in_array($account_state, array('active', 'pending', 'inactive', 'expired'))){
187
+ $this->sanitized['account_state'] = $account_state;
188
+ }
189
+ else{
190
+ $this->errors['account_state'] = 'Account state field is invalid';
191
+ }
192
+ }
193
+
194
+ protected function membership_level() {
195
+ $membership_level = filter_input(INPUT_POST, 'membership_level', FILTER_SANITIZE_NUMBER_INT);
196
+ if (empty($membership_level)) {return;}
197
+ $this->sanitized['membership_level'] = $membership_level;
198
+ }
199
+
200
+ protected function password_re() {
201
+
202
+ }
203
+
204
+ protected function last_accessed() {
205
+
206
+ }
207
+
208
+ protected function last_accessed_from_ip() {
209
+
210
+ }
211
+
212
+ protected function referrer() {
213
+
214
+ }
215
+
216
+ protected function extra_info() {
217
+
218
+ }
219
+
220
+ protected function reg_code() {
221
+
222
+ }
223
+
224
+ protected function txn_id() {
225
+
226
+ }
227
+
228
+ protected function subscr_id() {
229
+
230
+ }
231
+
232
+ protected function flags() {
233
+
234
+ }
235
+
236
+ protected function more_membership_levels() {
237
+
238
+ }
239
+
240
+ protected function initial_membership_level() {
241
+
242
+ }
243
+
244
+ protected function home_page() {
245
+
246
+ }
247
+
248
+ protected function notes() {
249
+
250
+ }
251
+
252
+ protected function profile_image() {
253
+
254
+ }
255
+
256
+ protected function expiry_1st() {
257
+
258
+ }
259
+
260
+ protected function expiry_2nd() {
261
+
262
+ }
263
+
264
+ protected function member_id() {
265
+
266
+ }
267
+
268
+ public function is_valid() {
269
+ return count($this->errors) < 1;
270
+ }
271
+
272
+ public function get_sanitized() {
273
+ return $this->sanitized;
274
+ }
275
+
276
+ public function get_errors() {
277
+ return $this->errors;
278
+ }
279
+
280
+ }
classes/class.bFrontForm.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class BFrontForm extends BForm{
4
+ public function membership_level(){
5
+
6
+ }
7
+ }
classes/class.bFrontRegistration.php ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Description of BFrontRegistration
5
+ *
6
+ * @author nur
7
+ */
8
+ class BFrontRegistration extends BRegistration {
9
+ protected static $__CLASS__ = __CLASS__;
10
+ public function regigstration_ui(){
11
+ $settings_configs = BSettings::get_instance();
12
+ $is_free = BSettings::get_instance()->get_value('enable-free-membership');
13
+ $free_level = absint(BSettings::get_instance()->get_value('free-membership-id'));
14
+ $joinuspage_url = $settings_configs->get_value('join-us-page-url');
15
+ $membership_level = '';
16
+ $member_id = filter_input(INPUT_GET, 'member_id', FILTER_SANITIZE_NUMBER_INT);
17
+ $code = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_STRING);
18
+ $member = BTransfer::$default_fields;
19
+ global $wpdb;
20
+ if (!empty($member_id) && !empty($code)){
21
+ $query = 'SELECT * FROM ' . $wpdb->prefix . 'swpm_members_tbl WHERE member_id= %d AND reg_code=%s';
22
+ $query = $wpdb->prepare($query, $member_id, $code);
23
+ $member = $wpdb->get_row($query);
24
+ if (empty($member)){
25
+ echo 'Error! Invalid Request. Could not find a match for the given security code and the user ID.';
26
+ }
27
+ $membership_level = $member->membership_level;
28
+ }
29
+ else if (isset($_SESSION['swpm-registered-level'])) {
30
+ $membership_level = absint($_SESSION['swpm-registered-level']);
31
+ } else if ($is_free) {
32
+ $membership_level = $free_level;
33
+ }
34
+ if (empty($membership_level)) {
35
+ $joinuspage_link = '<a href="' . $joinuspage_url . '">Join us</a>';
36
+ $output = 'Free membership is disabled on this site. Please make a payment from the ' . $joinuspage_link . ' page to pay for a premium membership.';
37
+ echo $output;
38
+ return;
39
+ }
40
+
41
+ $query = "SELECT alias FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id = $membership_level";
42
+ $result = $wpdb->get_row($query);
43
+ if (empty($result)) {
44
+ return "Membership Level Not Found.";
45
+ }
46
+ $membership_level_alias = $result->alias;
47
+ $swpm_registration_submit = filter_input(INPUT_POST, 'swpm_registration_submit');
48
+ if (!empty($swpm_registration_submit)){
49
+ $member = $_POST;
50
+ }
51
+ extract((array)$member, EXTR_SKIP);
52
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/add.php');
53
+ }
54
+ public function register() {
55
+ if($this->create_swpm_user()&&$this->create_wp_user()&&$this->send_reg_email()){
56
+ do_action('swpm_front_end_registration_complete');
57
+
58
+ $login_page_url = BSettings::get_instance()->get_value('login-page-url');
59
+ $after_rego_msg = '<p>Registration Successful. Please <a href="' . $login_page_url . '">Login</a></p>';
60
+ $message = array('succeeded' => true, 'message' => $after_rego_msg);
61
+ BTransfer::get_instance()->set('status', $message);
62
+ return;
63
+ }
64
+ }
65
+ private function create_swpm_user(){
66
+ global $wpdb;
67
+ $member = BTransfer::$default_fields;
68
+ $form = new BFrontForm($member);
69
+ $is_free = BSettings::get_instance()->get_value('enable-free-membership');
70
+ $free_level = absint(BSettings::get_instance()->get_value('free-membership-id'));
71
+ $member_id = filter_input(INPUT_GET, 'member_id', FILTER_SANITIZE_NUMBER_INT);
72
+ $code = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_STRING);
73
+ if (!$form->is_valid()) {
74
+ $message = array('succeeded' => false, 'message' => 'Please correct the following',
75
+ 'extra' => $form->get_errors());
76
+ BTransfer::get_instance()->set('status', $message);
77
+ return false;
78
+ }
79
+ $member_info = $form->get_sanitized();
80
+ if (isset($_SESSION['swpm-registered-level'])){
81
+ $member_info['membership_level'] = absint($_SESSION['swpm-registered-level']);
82
+ }
83
+ else if ($is_free && !empty($free_level)){
84
+ $member_info['membership_level'] = $free_level;
85
+ }
86
+ else if (empty($member_id)){
87
+ $message = array('succeeded' => false, 'message' => 'Membership Level Couldn\'t be found.');
88
+ BTransfer::get_instance()->set('status', $message);
89
+ return false;
90
+ }
91
+ $member_info['last_accessed_from_ip'] = BTransfer::get_real_ip_addr();
92
+ $member_info['member_since'] = date("Y-m-d");
93
+ $member_info['subscription_starts'] = date("Y-m-d");
94
+ $member_info['account_state'] = 'active';
95
+ $plain_password = $member_info['plain_password'];
96
+ unset($member_info['plain_password']);
97
+ if(!empty($member_id) && !empty($code)){
98
+ $member_info['reg_code'] = '';
99
+ $wpdb->update($wpdb->prefix . "swpm_members_tbl", $member_info,
100
+ array('member_id' => $member_id,'reg_code'=>$code));
101
+ $last_insert_id = $member_id;
102
+ }
103
+ else{
104
+ $wpdb->insert($wpdb->prefix . "swpm_members_tbl", $member_info);
105
+ $last_insert_id = $wpdb->insert_id;
106
+ }
107
+ if (!isset($member_info['membership_level'])){
108
+ $query = 'SELECT membership_level FROM ' . $wpdb->prefix . 'swpm_members_tbl WHERE member_id=' . $member_id;
109
+ $member_info['membership_level'] = $wpdb->get_var( $query );
110
+ }
111
+ $member_info['plain_password'] = $plain_password;
112
+ $this->member_info = $member_info;
113
+ return true;
114
+ }
115
+ private function create_wp_user(){
116
+ global $wpdb;
117
+ $member_info = $this->member_info;
118
+ $query = "SELECT role FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id = " . $member_info['membership_level'];
119
+ $wp_user_info = array();
120
+ $wp_user_info['user_nicename'] = implode('-', explode(' ', $member_info['user_name']));
121
+ $wp_user_info['display_name'] = $member_info['user_name'];
122
+ $wp_user_info['user_email'] = $member_info['email'];
123
+ $wp_user_info['nickname'] = $member_info['user_name'];
124
+ $wp_user_info['first_name'] = $member_info['first_name'];
125
+ $wp_user_info['last_name'] = $member_info['last_name'];
126
+ $wp_user_info['user_login'] = $member_info['user_name'];
127
+ $wp_user_info['password'] = $member_info['plain_password'];
128
+ $wp_user_info['role'] = $wpdb->get_var($query);
129
+ $wp_user_info['user_registered'] = date('Y-m-d H:i:s');
130
+ BUtils::create_wp_user($wp_user_info);
131
+ return true;
132
+ }
133
+ public function edit() {
134
+ global $wpdb;
135
+ $auth = BAuth::get_instance();
136
+ if (!$auth->is_logged_in()) {
137
+ return;
138
+ }
139
+ $user_data = (array) $auth->userData;
140
+ unset($user_data['permitted']);
141
+ $form = new BForm($user_data);
142
+ if ($form->is_valid()) {
143
+ global $wpdb;
144
+ $member_info = $form->get_sanitized();
145
+ if (isset($member_info['plain_password'])) {
146
+ unset($member_info['plain_password']);
147
+ }
148
+ $wpdb->update(
149
+ $wpdb->prefix . "swpm_members_tbl", $member_info, array('member_id' => $auth->get('member_id')));
150
+ echo '<pre>';
151
+ $message = array('succeeded' => true, 'message' => 'Profile Updated.');
152
+ BTransfer::get_instance()->set('status', $message);
153
+ } else {
154
+ $message = array('succeeded' => false, 'message' => 'Please correct the following',
155
+ 'extra' => $form->get_errors());
156
+ BTransfer::get_instance()->set('status', $message);
157
+ return;
158
+ }
159
+ }
160
+
161
+ public function reset_password($email) {
162
+ $email = sanitize_email($email);
163
+ if (!is_email($email)) {
164
+ $message = "Email Address Not Valid.";
165
+ $message = array('succeeded' => false, 'message' => $message);
166
+ BTransfer::get_instance()->set('status', $message);
167
+ return;
168
+ }
169
+ global $wpdb;
170
+ $query = 'SELECT member_id,user_name,first_name, last_name FROM ' .
171
+ $wpdb->prefix . 'swpm_members_tbl ' .
172
+ ' WHERE email = %s';
173
+ $user = $wpdb->get_row($wpdb->prepare($query, $email));
174
+ if (empty($user)) {
175
+ $message = "User Not Found.";
176
+ $message = array('succeeded' => false, 'message' => $message);
177
+ BTransfer::get_instance()->set('status', $message);
178
+ return;
179
+ }
180
+ $settings = BSettings::get_instance();
181
+ $password = wp_generate_password();
182
+ $body = $settings->get_value('reset-mail-body');
183
+ $subject = $settings->get_value('reset-mail-subject');
184
+ $wpdb->update($wpdb->prefix . "swpm_members_tbl", array('password' => $password), array('member_id' => $user->member_id));
185
+ $search = array('{user_name}', '{first_name}', '{last_name}', '{password}');
186
+ $replace = array($user->user_name, $user->first_name, $user->last_name, $password);
187
+ $body = str_replace($search, $replace, $body);
188
+ $from = $settings->get_value('email-from');
189
+ $headers = "From: " . $from . "\r\n";
190
+ wp_mail($from, $subject, $body, $headers);
191
+ $message = "New password has been sent to your email address.";
192
+ $message = array('succeeded' => false, 'message' => $message);
193
+ BTransfer::get_instance()->set('status', $message);
194
+ }
195
+
196
+ }
classes/class.bInstallation.php ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Description of BInstallation
5
+ *
6
+ * @author nur
7
+ */
8
+ class BInstallation {
9
+
10
+ public static function do_multisite() {
11
+ global $wpdb;
12
+ $networkwide = filter_input(INPUT_GET, 'networkwide');
13
+ // check if it is a network activation - if so, run the activation function for each blog id
14
+ if ($networkwide == 1) {
15
+ $old_blog = $wpdb->blogid;
16
+ // Get all blog ids
17
+ $blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
18
+ foreach ($blogids as $blog_id) {
19
+ switch_to_blog($blog_id);
20
+ SimpleWpMembership::installer();
21
+ SimpleWpMembership::initdb();
22
+ }
23
+ switch_to_blog($old_blog);
24
+ return;
25
+ }
26
+ }
27
+ public static function installer() {
28
+ global $wpdb;
29
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
30
+ $sql = "CREATE TABLE " . $wpdb->prefix . "swpm_members_tbl (
31
+ member_id int(12) NOT NULL PRIMARY KEY AUTO_INCREMENT,
32
+ user_name varchar(32) NOT NULL,
33
+ first_name varchar(32) DEFAULT '',
34
+ last_name varchar(32) DEFAULT '',
35
+ password varchar(64) NOT NULL,
36
+ member_since date NOT NULL DEFAULT '0000-00-00',
37
+ membership_level smallint(6) NOT NULL,
38
+ more_membership_levels VARCHAR(100) DEFAULT NULL,
39
+ account_state enum('active','inactive','expired','pending','unsubscribed') DEFAULT 'pending',
40
+ last_accessed datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
41
+ last_accessed_from_ip varchar(64) NOT NULL,
42
+ email varchar(64) DEFAULT NULL,
43
+ phone varchar(64) DEFAULT NULL,
44
+ address_street varchar(255) DEFAULT NULL,
45
+ address_city varchar(255) DEFAULT NULL,
46
+ address_state varchar(255) DEFAULT NULL,
47
+ address_zipcode varchar(255) DEFAULT NULL,
48
+ home_page varchar(255) DEFAULT NULL,
49
+ country varchar(255) DEFAULT NULL,
50
+ gender enum('male','female','not specified') DEFAULT 'not specified',
51
+ referrer varchar(255) DEFAULT NULL,
52
+ extra_info text,
53
+ reg_code varchar(255) DEFAULT NULL,
54
+ subscription_starts date DEFAULT NULL,
55
+ initial_membership_level smallint(6) DEFAULT NULL,
56
+ txn_id varchar(64) DEFAULT '',
57
+ subscr_id varchar(32) DEFAULT '',
58
+ company_name varchar(100) DEFAULT '',
59
+ notes text DEFAULT NULL,
60
+ flags int(11) DEFAULT '0',
61
+ profile_image varchar(255) DEFAULT ''
62
+ )ENGINE=MyISAM DEFAULT CHARSET=utf8;";
63
+ dbDelta($sql);
64
+
65
+ $sql = "CREATE TABLE " . $wpdb->prefix . "swpm_membership_tbl (
66
+ id int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
67
+ alias varchar(127) NOT NULL,
68
+ role varchar(255) NOT NULL DEFAULT 'subscriber',
69
+ permissions tinyint(4) NOT NULL DEFAULT '0',
70
+ subscription_period int(11) NOT NULL DEFAULT '-1',
71
+ subscription_unit VARCHAR(20) NULL,
72
+ loginredirect_page text NULL,
73
+ category_list longtext,
74
+ page_list longtext,
75
+ post_list longtext,
76
+ comment_list longtext,
77
+ attachment_list longtext,
78
+ custom_post_list longtext,
79
+ disable_bookmark_list longtext,
80
+ options longtext,
81
+ campaign_name varchar(60) NOT NULL DEFAULT ''
82
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
83
+ dbDelta($sql);
84
+ $sql = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id = 1";
85
+ $results = $wpdb->get_row($sql);
86
+ if (is_null($results)) {
87
+ $sql = "INSERT INTO " . $wpdb->prefix . "swpm_membership_tbl (
88
+ id ,
89
+ alias ,
90
+ role ,
91
+ permissions ,
92
+ subscription_period ,
93
+ subscription_unit,
94
+ loginredirect_page,
95
+ category_list ,
96
+ page_list ,
97
+ post_list ,
98
+ comment_list,
99
+ disable_bookmark_list,
100
+ options,
101
+ campaign_name
102
+ )VALUES (1 , 'Content Protection', 'administrator', '15', '0',NULL,NULL, NULL , NULL , NULL , NULL,NULL,NULL,'');";
103
+ $wpdb->query($sql);
104
+ }
105
+ $sql = "CREATE TABLE " . $wpdb->prefix . "swpm_membership_meta_tbl (
106
+ id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
107
+ level_id int(11) NOT NULL,
108
+ meta_key varchar(255) NOT NULL,
109
+ meta_label varchar(255) NULL,
110
+ meta_value text,
111
+ meta_type varchar(255) NOT NULL DEFAULT 'text',
112
+ meta_default text,
113
+ meta_context varchar(255) NOT NULL DEFAULT 'default',
114
+ KEY level_id (level_id),
115
+ UNIQUE KEY meta_key_id (level_id,meta_key)
116
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
117
+ dbDelta($sql);
118
+ }
119
+
120
+ public static function initdb() {
121
+ $settings = BSettings::get_instance();
122
+
123
+ $installed_version = $settings->get_value('swpm-active-version');
124
+
125
+ //Set other default settings values
126
+ $reg_prompt_email_subject = "Complete your registration";
127
+ $reg_prompt_email_body = "Dear {first_name} {last_name}" .
128
+ "\n\nThank you for joining us!" .
129
+ "\n\nPlease complete your registration by visiting the following link:" .
130
+ "\n\n{reg_link}" .
131
+ "\n\nThank You";
132
+ $reg_email_subject = "Your registration is complete";
133
+ $reg_email_body = "Dear {first_name} {last_name}\n\n" .
134
+ "Your registration is now complete!\n\n" .
135
+ "Registration details:\n" .
136
+ "Username: {user_name}\n" .
137
+ "Password: {password}\n\n" .
138
+ "Please login to the member area at the following URL:\n\n" .
139
+ "{login_link}\n\n" .
140
+ "Thank You";
141
+
142
+ $upgrade_email_subject = "Subject for email sent after account upgrade";
143
+ $upgrade_email_body = "Dear {first_name} {last_name}" .
144
+ "\n\nYour Account Has Been Upgraded." .
145
+ "\n\nThank You";
146
+ $reset_email_subject = get_bloginfo('name') . ": New Password";
147
+ $reset_email_body = "Dear {first_name} {last_name}" .
148
+ "\n\nHere is your new password" .
149
+ "\n\nUser name: {user_name}" .
150
+ "\n\nPassword: {password}" .
151
+ "\n\nThank You";
152
+ if (empty($installed_version)) {
153
+ //Do fresh install tasks
154
+
155
+ /* * * Create the mandatory pages (if they are not there) ** */
156
+ miscUtils::create_mandatory_wp_pages();
157
+ /* * * End of page creation ** */
158
+ $settings->set_value('reg-complete-mail-subject', stripslashes($reg_email_subject))
159
+ ->set_value('reg-complete-mail-body', stripslashes($reg_email_body))
160
+ ->set_value('reg-prompt-complete-mail-subject', stripslashes($reg_prompt_email_subject))
161
+ ->set_value('reg-prompt-complete-mail-body', stripslashes($reg_prompt_email_body))
162
+ ->set_value('upgrade-complete-mail-subject', stripslashes($upgrade_email_subject))
163
+ ->set_value('upgrade-complete-mail-body', stripslashes($upgrade_email_body))
164
+ ->set_value('reset-mail-subject', stripslashes($reset_email_subject))
165
+ ->set_value('reset-mail-body', stripslashes($reset_email_body))
166
+ ->set_value('email-from', trim(get_option('admin_email')));
167
+ }
168
+ if (version_compare($installed_version, SIMPLE_WP_MEMBERSHIP_VER) == -1) {
169
+ //Do upgrade tasks
170
+ }
171
+
172
+ $settings->set_value('swpm-active-version', SIMPLE_WP_MEMBERSHIP_VER)->save(); //save everything.
173
+ }
174
+ }
classes/class.bLevelForm.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class BLevelForm{
3
+ protected $fields;
4
+ protected $op;
5
+ protected $errors;
6
+ protected $sanitized;
7
+ public function __construct($fields){
8
+ $this->fields = $fields;
9
+ $this->sanitized = array();
10
+ foreach($fields as $key=>$value)
11
+ $this->$key();
12
+ }
13
+
14
+ protected function id(){}
15
+ protected function alias(){
16
+ $this->sanitized['alias'] = sanitize_text_field($_POST['alias']);
17
+ }
18
+ protected function role(){
19
+ $this->sanitized['role'] = sanitize_text_field($_POST['role']);
20
+ }
21
+ protected function permissions(){
22
+ $this->sanitized['permissions'] = 63;
23
+ }
24
+ protected function subscription_period(){
25
+ if($_POST['subscript_duration_type'] == 0){
26
+ $this->sanitized['subscription_period'] = 0;
27
+ return;
28
+ }
29
+
30
+ if(empty($_POST['subscription_period'])){
31
+ $this->errors['subscription_period'] = "Subscriptoin duration must be > 0.";
32
+ return;
33
+ }
34
+ $this->sanitized['subscription_period'] = absint($_POST['subscription_period']);
35
+ }
36
+ protected function subscription_unit(){
37
+ if($_POST['subscript_duration_type'] == 0){
38
+ $this->sanitized['subscription_unit'] = null;
39
+ return;
40
+ }
41
+ $this->sanitized['subscription_unit'] = sanitize_text_field($_POST['subscription_unit']);
42
+ }
43
+ protected function loginredirect_page(){}
44
+ protected function category_list(){}
45
+ protected function page_list(){}
46
+ protected function post_list(){}
47
+ protected function comment_list(){}
48
+ protected function attachment_list(){}
49
+ protected function custom_post_list(){}
50
+ protected function disable_bookmark_list(){}
51
+ protected function options(){}
52
+ protected function campaign_name(){}
53
+ public function is_valid(){
54
+ return count($this->errors)<1;
55
+ }
56
+ public function get_sanitized(){
57
+ return $this->sanitized;
58
+ }
59
+ public function get_errors(){
60
+ return $this->errors;
61
+ }
62
+ }
classes/class.bLog.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class BLog {
4
+ private $error;
5
+ private $warn;
6
+ private $notice;
7
+ private static $intance;
8
+ private function __construct() {
9
+ $this->error = array();
10
+ $this->warn = array();
11
+ $this->notice = array();
12
+ }
13
+ public static function get_logger($context = ''){
14
+ $context = empty($context)? 'default': $context;
15
+ if (!isset(self::$intance[$context])){
16
+ self::$intance[$context] = new BLog();
17
+ }
18
+ return self::$intance[$context];
19
+ }
20
+ public function error($msg){
21
+ $this->error[] = $msg;
22
+ }
23
+ public function warn($msg){
24
+ $this->warn[] = $msg;
25
+ }
26
+ public function debug($msg){
27
+ $this->notice[] = $msg;
28
+ }
29
+ public function get($to_screen = false){
30
+ $msg = '';
31
+ foreach ($this->error as $error ){
32
+ $msg .= 'ERROR: ' . $error . ($to_screen?"<br/>":"\n");
33
+ }
34
+ foreach($this->warn as $warn){
35
+ $msg .= 'WARN: ' . $warn . ($to_screen?"<br/>":"\n");
36
+ }
37
+ foreach ($this->notice as $notice){
38
+ $msg = 'NOTICE: ' . $notice . ($to_screen?"<br/>":"\n");
39
+ }
40
+ return $msg;
41
+ }
42
+ public static function writeall($path = ''){
43
+ if (empty($path)) {$path = SIMPLE_WP_MEMBERSHIP_PATH . 'log.txt';}
44
+ $fp = fopen($path, 'a');
45
+ $date = date("Y-m-d H:i:s");
46
+ fwrite($fp, strtoupper($date) . ":\n");
47
+ fwrite($fp, str_repeat('-=', (strlen($date)+1.0)/2.0) . "\n");
48
+ foreach (self::$intance as $context=>$intance){
49
+ fwrite($fp, strtoupper($context) . ":\n");
50
+ fwrite($fp, str_repeat('=', strlen($context)+1) . "\n");
51
+ fwrite($fp, $intance->get());
52
+ }
53
+ fclose($fp);
54
+ }
55
+
56
+ public static function log_simple_debug($message, $success, $end = false) {
57
+ $settings = BSettings::get_instance();
58
+ $debug_enabled = $settings->get_value('enable-debug');
59
+ if (empty($debug_enabled)) {//Debug is not enabled
60
+ return;
61
+ }
62
+
63
+ //Lets write to the log file
64
+ $debug_log_file_name = SIMPLE_WP_MEMBERSHIP_PATH . 'log.txt';
65
+
66
+ // Timestamp
67
+ $text = '[' . date('m/d/Y g:i A') . '] - ' . (($success) ? 'SUCCESS :' : 'FAILURE :') . $message . "\n";
68
+ if ($end) {
69
+ $text .= "\n------------------------------------------------------------------\n\n";
70
+ }
71
+ // Write to log
72
+ $fp = fopen($debug_log_file_name, 'a');
73
+ fwrite($fp, $text);
74
+ fclose($fp); // close file
75
+ }
76
+
77
+ }
classes/class.bMembers.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class BMembers extends WP_List_Table {
4
+
5
+ function __construct() {
6
+ parent::__construct(array(
7
+ 'singular' => 'Member',
8
+ 'plural' => 'Members',
9
+ 'ajax' => false
10
+ ));
11
+ }
12
+
13
+ function get_columns() {
14
+ return array(
15
+ 'cb' => '<input type="checkbox" />'
16
+ , 'member_id' => 'ID'
17
+ , 'user_name' => 'User Name'
18
+ , 'first_name' => 'First Name'
19
+ , 'last_name' => 'Last Name'
20
+ , 'email' => 'Email'
21
+ , 'alias' => 'Membership Level'
22
+ , 'subscription_starts' => 'Subscription Starts'
23
+ , 'account_state' => 'Account State'
24
+ );
25
+ }
26
+
27
+ function get_sortable_columns() {
28
+ return array(
29
+ 'user_name' => array('user_name', true)
30
+ );
31
+ }
32
+
33
+ function get_bulk_actions() {
34
+ $actions = array(
35
+ 'bulk_delete' => 'Delete'
36
+ );
37
+ return $actions;
38
+ }
39
+
40
+ function column_default($item, $column_name) {
41
+ return $item[$column_name];
42
+ }
43
+
44
+ function column_member_id($item) {
45
+ $actions = array(
46
+ 'edit' => sprintf('<a href="admin.php?page=%s&member_action=edit&member_id=%s">Edit</a>', $_REQUEST['page'], $item['member_id']),
47
+ 'delete' => sprintf('<a href="?page=%s&member_action=delete&member_id=%s"
48
+ onclick="return confirm(\'Are you sure you want to delete this entry?\')">Delete</a>', $_REQUEST['page'], $item['member_id']),
49
+ );
50
+ return $item['member_id'] . $this->row_actions($actions);
51
+ }
52
+
53
+ function column_cb($item) {
54
+ return sprintf(
55
+ '<input type="checkbox" name="members[]" value="%s" />', $item['member_id']
56
+ );
57
+ }
58
+
59
+ function prepare_items() {
60
+ global $wpdb;
61
+ $query = "SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl";
62
+ $query .= " LEFT JOIN " . $wpdb->prefix . "swpm_membership_tbl";
63
+ $query .= " ON ( membership_level = id ) ";
64
+ if (isset($_POST['s']))
65
+ $query .= " WHERE = user_name = '" . strip_tags($_POST['s']) . "' ";
66
+ $orderby = !empty($_GET["orderby"]) ? mysql_real_escape_string($_GET["orderby"]) : 'ASC';
67
+ $order = !empty($_GET["order"]) ? mysql_real_escape_string($_GET["order"]) : '';
68
+ if (!empty($orderby) & !empty($order)) {
69
+ $query.=' ORDER BY ' . $orderby . ' ' . $order;
70
+ }
71
+ $totalitems = $wpdb->query($query); //return the total number of affected rows
72
+ $perpage = 20;
73
+ $paged = !empty($_GET["paged"]) ? mysql_real_escape_string($_GET["paged"]) : '';
74
+ if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
75
+ $paged = 1;
76
+ }
77
+ $totalpages = ceil($totalitems / $perpage);
78
+ if (!empty($paged) && !empty($perpage)) {
79
+ $offset = ($paged - 1) * $perpage;
80
+ $query.=' LIMIT ' . (int) $offset . ',' . (int) $perpage;
81
+ }
82
+ $this->set_pagination_args(array(
83
+ "total_items" => $totalitems,
84
+ "total_pages" => $totalpages,
85
+ "per_page" => $perpage,
86
+ ));
87
+
88
+ $columns = $this->get_columns();
89
+ $hidden = array();
90
+ $sortable = $this->get_sortable_columns();
91
+
92
+ $this->_column_headers = array($columns, $hidden, $sortable);
93
+ $this->items = $wpdb->get_results($query, ARRAY_A);
94
+ }
95
+
96
+ function no_items() {
97
+ _e('No Member found.');
98
+ }
99
+
100
+ function process_form_request() {
101
+ if (isset($_REQUEST['member_id']))
102
+ return $this->edit($_REQUEST['member_id']);
103
+ return $this->add();
104
+ }
105
+
106
+ function add() {
107
+ global $wpdb;
108
+ $member = BTransfer::$default_fields;
109
+ $member['member_since'] = date('Y-m-d');
110
+ $member['subscription_starts'] = date('Y-m-d');
111
+ if (isset($_POST['createswpmuser'])) {
112
+ $member = $_POST;
113
+ }
114
+ extract($member, EXTR_SKIP);
115
+ $query = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
116
+ $levels = $wpdb->get_results($query, ARRAY_A);
117
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_add.php');
118
+ return false;
119
+ }
120
+
121
+ function edit($id) {
122
+ global $wpdb;
123
+ $id = absint($id);
124
+ $query = "SELECT * FROM {$wpdb->prefix}swpm_members_tbl WHERE member_id = $id";
125
+ $member = $wpdb->get_row($query, ARRAY_A);
126
+ if (isset($_POST["editswpmuser"])) {
127
+ $_POST['user_name'] = $member['user_name'];
128
+ $_POST['email'] = $member['email'];
129
+ $member = $_POST;
130
+ }
131
+ extract($member, EXTR_SKIP);
132
+ $query = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
133
+ $levels = $wpdb->get_results($query, ARRAY_A);
134
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_edit.php');
135
+ return false;
136
+ }
137
+
138
+ function delete() {
139
+ global $wpdb;
140
+ if (isset($_REQUEST['member_id'])) {
141
+ $id = absint($_REQUEST['member_id']);
142
+ $user_name = BUtils::get_user_by_id($id);
143
+ $this->delete_wp_user($user_name);
144
+ $query = "DELETE FROM " . $wpdb->prefix . "swpm_members_tbl WHERE member_id = $id";
145
+ $wpdb->query($query);
146
+ } else if (isset($_REQUEST['members'])) {
147
+ $members = $_REQUEST['members'];
148
+ if (!empty($members)) {
149
+ $members = array_map('absint', $members);
150
+ foreach ($members as $swpm_id) {
151
+ $user_name = BUtils::get_user_by_id($swpm_id);
152
+ $this->delete_wp_user($user_name);
153
+ }
154
+ $query = "DELETE FROM " . $wpdb->prefix . "swpm_members_tbl WHERE member_id IN (" . implode(',', $members) . ")";
155
+ $wpdb->query($query);
156
+ }
157
+ }
158
+ }
159
+
160
+ function show() {
161
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_members.php');
162
+ }
163
+
164
+ private function delete_wp_user($user_name) {
165
+ $wp_user_id = username_exists($user_name);
166
+ $ud = get_userdata($wp_user_id);
167
+ if (!empty($ud) && (isset($ud->wp_capabilities['administrator']) || $ud->wp_user_level == 10)) {
168
+ BTransfer::get_instance()->set('status', 'For consistency, we do not allow deleting any associated wordpress account with administrator role.<br/>'
169
+ . 'Please delete from <a href="users.php">Users</a> menu.');
170
+ return;
171
+ }
172
+ if ($wp_user_id) {
173
+ include_once(ABSPATH . 'wp-admin/includes/user.php');
174
+ wp_delete_user($wp_user_id, 1); //assigns all related to this user to admin.
175
+ }
176
+ }
177
+
178
+ }
classes/class.bMembershipLevel.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Description of BMembershipLevel
5
+ *
6
+ * @author nur
7
+ */
8
+ class BMembershipLevel {
9
+
10
+ private static $_instance = null;
11
+
12
+ private function __construct() {
13
+ ;
14
+ }
15
+
16
+ public static function get_instance() {
17
+ self::$_instance = empty(self::$_instance) ? new BMembershipLevel() : self::$_instance;
18
+ return self::$_instance;
19
+ }
20
+
21
+ public function create() {
22
+ global $wpdb;
23
+ $level = BTransfer::$default_level_fields;
24
+ $form = new BLevelForm($level);
25
+ if ($form->is_valid()) {
26
+ $level_info = $form->get_sanitized();
27
+ $wpdb->insert($wpdb->prefix . "swpm_membership_tbl", $level_info);
28
+ $id = $wpdb->insert_id;
29
+ $custom = apply_filters('swpm_admin_add_membership_level', array());
30
+ $this->save_custom_fields($id, $custom);
31
+ $message = array('succeeded' => true, 'message' => 'Membership Level Creation Successful.');
32
+ BTransfer::get_instance()->set('status', $message);
33
+ wp_redirect('admin.php?page=simple_wp_membership_levels');
34
+ return;
35
+ }
36
+ $message = array('succeeded' => false, 'message' => 'Please correct the following:', 'extra' => $form->get_errors());
37
+ BTransfer::get_instance()->set('status', $message);
38
+ }
39
+
40
+ public function edit($id) {
41
+ global $wpdb;
42
+ $query = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id = $id";
43
+ $level = $wpdb->get_row($query, ARRAY_A);
44
+ $form = new BLevelForm($level);
45
+ if ($form->is_valid()) {
46
+ $wpdb->update($wpdb->prefix . "swpm_membership_tbl", $form->get_sanitized(), array('id' => $id));
47
+ //@todo meta table and collect all relevant info and pass as argument
48
+ $custom = apply_filters('swpm_admin_edit_membership_level', array(), $id);
49
+ $this->save_custom_fields($id, $custom);
50
+ $message = array('succeeded' => true, 'message' => 'Updated Successfully.');
51
+ BTransfer::get_instance()->set('status', $message);
52
+ wp_redirect('admin.php?page=simple_wp_membership_levels');
53
+ }
54
+ $message = array('succeeded' => false, 'message' => 'Please correct the following:', 'extra' => $form->get_errors());
55
+ BTransfer::get_instance()->set('status', $message);
56
+ }
57
+ private function save_custom_fields($level_id, $data){
58
+ $custom_obj = BMembershipLevelCustom::get_instance_by_id($level_id);
59
+ foreach ($data as $item){
60
+ $custom_obj->set($item);
61
+ }
62
+ }
63
+ }
classes/class.bMembershipLevelCustom.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Description of BMembershipLevelCustom
4
+ *
5
+ * @author nur
6
+ */
7
+ class BMembershipLevelCustom {
8
+ private static $instances = array();
9
+ private $level_id;
10
+ private $fields;
11
+ private function __construct() {
12
+ $this->fields = array();
13
+ }
14
+ public static function get_instance_by_id($level_id){
15
+ if (!isset(self::$instances[$level_id])){
16
+ self::$instances[$level_id] = new BMembershipLevelCustom();
17
+ self::$instances[$level_id]->level_id = $level_id;
18
+ self::$instances[$level_id]->load_by_id($level_id);
19
+ }
20
+ return self::$instances[$level_id];
21
+ }
22
+ public function load_by_id($level_id){
23
+ global $wpdb;
24
+ $query = 'SELECT * FROM ' . $wpdb->prefix . 'swpm_membership_meta_tbl WHERE level_id=%d';
25
+ $results = $wpdb->get_results($wpdb->prepare($query, $level_id), ARRAY_A);
26
+ foreach($results as $result){
27
+ $this->fields[$result['meta_key']] = $result;
28
+ }
29
+ }
30
+ public function set($item){
31
+ $meta_key = preg_replace('|[^A-Z0-9_]|i', '', $item['meta_key']);
32
+ $new = array(
33
+ 'meta_key'=>$meta_key,
34
+ 'level_id'=>$this->level_id,
35
+ 'meta_label'=> isset($item['meta_label'])?$item['meta_label']:'',
36
+ 'meta_value'=>$item['meta_value'],
37
+ 'meta_type'=> isset($item['meta_type'])?$item['meta_type']:'text',
38
+ 'meta_default'=> isset($item['meta_default'])?$item['meta_default']:'',
39
+ 'meta_context'=> $item['meta_context'],
40
+ );
41
+ if (isset($this->fields[$meta_key])){
42
+ $new['id'] = $this->fields[$meta_key]['id'];
43
+ $this->fields[$meta_key] = $new;
44
+ }
45
+ else{
46
+ $this->fields[$meta_key] = $new;
47
+ }
48
+ $this->save($this->fields[$meta_key]);
49
+ return $this;
50
+ }
51
+ public function get($meta_key, $default=''){
52
+ $meta_key = preg_replace('|[^A-Z0-9_]|i', '', $meta_key);
53
+ if (isset($this->fields[$meta_key])){
54
+ return maybe_unserialize($this->fields[$meta_key]['meta_value']);
55
+
56
+ }
57
+ return $default;
58
+ }
59
+ public function get_by_context($context){
60
+ $result = array();
61
+ foreach ($this->fields as $key=>$field){
62
+ if ($field['meta_context'] == $context){
63
+ $result[$key] = $field;
64
+ }
65
+ }
66
+ return $result;
67
+ }
68
+ private function save($field){
69
+ global $wpdb;
70
+ if (!isset($field['meta_key'])){retern;} // cannot continue without key field.
71
+ $meta_key = preg_replace('|[^A-Z0-9_]|i', '', $field['meta_key']);
72
+ $query = $wpdb->prepare(
73
+ 'REPLACE INTO ' . $wpdb->prefix. 'swpm_membership_meta_tbl
74
+ (level_id, meta_key, meta_label, meta_value, meta_type, meta_default, meta_context)
75
+ VALUES(%d, %s, %s, %s, %s, %s, %s); ',
76
+ $this->level_id,
77
+ $meta_key,
78
+ isset($field['meta_label'])? sanitize_text_field($field['meta_label']): '',
79
+ isset($field['meta_value'])? sanitize_text_field($field['meta_value']): '',
80
+ 'text', // at the moment we have only one type
81
+ '',
82
+ isset($field['meta_context'])? sanitize_text_field($field['meta_context']): 'default'
83
+ );
84
+
85
+ $wpdb->query($query);
86
+ }
87
+ public static function get_value_by_key($level_id, $key, $default= ''){
88
+ return BMembershipLevelCustom::get_instance_by_id($level_id)->get($key, $default);
89
+ }
90
+ public static function get_value_by_context($level_id, $context){
91
+ return BMembershipLevelCustom::get_instance_by_id($level_id)->get_by_context($context);
92
+ }
93
+ }
classes/class.bMembershipLevelUtils.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Description of class
4
+ *
5
+ * @author nur
6
+ */
7
+ class BMembershipLevelUtils {
8
+ }
classes/class.bMembershipLevels.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if( ! class_exists( 'WP_List_Table' ) )
3
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
4
+
5
+ class BMembershipLevels extends WP_List_Table{
6
+ function __construct(){
7
+ parent::__construct(array(
8
+ 'singular'=>'Membership Level',
9
+ 'plural' => 'Membership Levels',
10
+ 'ajax' => false
11
+ ));
12
+ }
13
+ function get_columns(){
14
+ return array(
15
+ 'cb' => '<input type="checkbox" />'
16
+ ,'id'=>'ID'
17
+ ,'alias'=>'Membership Level'
18
+ ,'role'=>'Role'
19
+ ,'valid_for'=>'Subscription Valid For'
20
+ );
21
+ }
22
+ function get_sortable_columns(){
23
+ return array(
24
+ 'alias'=>array('alias',true)
25
+ );
26
+ }
27
+ function get_bulk_actions() {
28
+ $actions = array(
29
+ 'bulk_delete' => 'Delete'
30
+ );
31
+ return $actions;
32
+ }
33
+ function column_default($item, $column_name){
34
+ if($column_name == 'valid_for'){
35
+ if(empty($item['subscription_period'])) return 'No Expiry';
36
+ return $item['subscription_period'] ." " . $item['subscription_unit']; //bUtils::calculate_subscription_period($item['subscription_period'],
37
+ // $item['subscription_unit']);
38
+ }
39
+ if($column_name == 'role') return ucfirst($item['role']);
40
+ return stripslashes($item[$column_name]);
41
+ }
42
+ function column_id($item){
43
+ $actions = array(
44
+ 'edit' => sprintf('<a href="admin.php?page=%s&level_action=edit&id=%s">Edit</a>',
45
+ $_REQUEST['page'],$item['id']),
46
+ 'delete' => sprintf('<a href="?page=%s&level_action=delete&id=%s"
47
+ onclick="return confirm(\'Are you sure you want to delete this entry?\')">Delete</a>',
48
+ $_REQUEST['page'],$item['id']),
49
+ );
50
+ return $item['id'] . $this->row_actions($actions);
51
+ }
52
+ function column_cb($item) {
53
+ return sprintf(
54
+ '<input type="checkbox" name="ids[]" value="%s" />', $item['id']
55
+ );
56
+ }
57
+ function prepare_items() {
58
+ global $wpdb;
59
+ $query = "SELECT * FROM " .$wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
60
+ if(isset($_POST['s'])) $query .= " AND alias LIKE '%" . strip_tags($_POST['s']). "%' ";
61
+ $orderby = !empty($_GET["orderby"]) ? mysql_real_escape_string($_GET["orderby"]) : 'id';
62
+ $order = !empty($_GET["order"]) ? mysql_real_escape_string($_GET["order"]) : 'DESC';
63
+ if(!empty($orderby) && !empty($order)){ $query.=' ORDER BY '.$orderby.' '.$order; }
64
+ $totalitems = $wpdb->query($query); //return the total number of affected rows
65
+ $perpage = 20;
66
+ $paged = !empty($_GET["paged"]) ? mysql_real_escape_string($_GET["paged"]) : '';
67
+ if(empty($paged) || !is_numeric($paged) || $paged<=0 ){ $paged=1; }
68
+ $totalpages = ceil($totalitems/$perpage);
69
+ if(!empty($paged) && !empty($perpage)){
70
+ $offset=($paged-1)*$perpage;
71
+ $query.=' LIMIT '.(int)$offset.','.(int)$perpage;
72
+ }
73
+ $this->set_pagination_args( array(
74
+ "total_items" => $totalitems,
75
+ "total_pages" => $totalpages,
76
+ "per_page" => $perpage,
77
+ ) );
78
+
79
+ $columns = $this->get_columns();
80
+ $hidden = array();
81
+ $sortable = $this->get_sortable_columns();
82
+
83
+ $this->_column_headers = array($columns, $hidden, $sortable);
84
+ $this->items = $wpdb->get_results($query, ARRAY_A);
85
+ }
86
+ function no_items() {
87
+ _e( 'No membership levels found.' );
88
+ }
89
+ function process_form_request(){
90
+ if(isset($_REQUEST['id']))
91
+ return $this->edit($_REQUEST['id']);
92
+ return $this->add();
93
+
94
+ }
95
+ function add(){
96
+ global $wpdb;
97
+ $member = BTransfer::$default_fields;
98
+ if(isset($_POST['createswpmlevel'])){
99
+ $member = $_POST;
100
+ }
101
+ extract($member, EXTR_SKIP);
102
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH.'views/admin_add_level.php');
103
+ return false;
104
+ }
105
+ function edit($id){
106
+ global $wpdb;
107
+ $id = absint($id);
108
+ $query = "SELECT * FROM {$wpdb->prefix}swpm_membership_tbl WHERE id = $id";
109
+ $member = $wpdb->get_row($query, ARRAY_A);
110
+ extract($member, EXTR_SKIP);
111
+ $noexpire = bUtils::calculate_subscription_period($subscription_period,$subscription_unit) == 'noexpire';
112
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH.'views/admin_edit_level.php');
113
+ return false;
114
+ }
115
+ function delete(){
116
+ global $wpdb;
117
+ if(isset($_REQUEST['id'])){
118
+ $id = absint($_REQUEST['id']);
119
+ $query = "DELETE FROM " .$wpdb->prefix . "swpm_membership_tbl WHERE id = $id";
120
+ $wpdb->query($query);
121
+ }
122
+ else if (isset($_REQUEST['ids'])){
123
+ $members = $_REQUEST['ids'];
124
+ if(!empty($members)){
125
+ $members = array_map('absint', $members);
126
+ $members = implode(',', $members);
127
+ $query = "DELETE FROM " .$wpdb->prefix . "swpm_membership_tbl WHERE id IN (" . $members . ")";
128
+ $wpdb->query($query);
129
+ }
130
+ }
131
+ }
132
+ function show(){
133
+ $selected = 1;
134
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH.'views/admin_membership_levels.php');
135
+ }
136
+ function manage(){
137
+ $selected = 2;
138
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH.'views/admin_membership_manage.php');
139
+ }
140
+ }
141
+
classes/class.bMessages.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ *
5
+ * @author nur
6
+ */
7
+ class BMessages {
8
+ private $messages;
9
+ public function __construct() {
10
+ $this->messages = array();
11
+ }
12
+ public function get($key){
13
+ if(isset($this->messages[$key])){
14
+ $m = $this->messages[$key];
15
+ $this->messages[$key] ='';
16
+ return $m;
17
+ }
18
+ return '';
19
+ }
20
+ public function set($key, $value){
21
+ $this->messages[$key] = $value;
22
+ }
23
+ }
classes/class.bPermission.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ include_once('class.bProtectionBase.php');
3
+ class BPermission extends bProtectionBase{
4
+ private static $_this = array();
5
+
6
+ private function __construct($level_id) {
7
+ $this->init($level_id);
8
+ }
9
+
10
+ public static function get_instance($level_id) {
11
+ if (!isset(self::$_this[$level_id]))
12
+ self::$_this[$level_id] = new BPermission($level_id);
13
+ return self::$_this[$level_id];
14
+ }
15
+
16
+ public function is_permitted($id) {
17
+ return $this->post_in_parent_categories($id) || $this->post_in_categories($id) || $this->in_posts($id) || $this->in_pages($id) || $this->in_attachments($id) || $this->in_custom_posts($id);
18
+ }
19
+
20
+ public function is_permitted_attachment($id) {
21
+ return (($this->bitmap & 16) === 16) && $this->in_attachments($id);
22
+ }
23
+
24
+ public function is_permitted_custom_post($id) {
25
+ return (($this->bitmap & 32) === 32) && $this->in_custom_posts($id);
26
+ }
27
+
28
+ public function is_permitted_category($id) {
29
+ return (($this->bitmap & 1) === 1) && $this->in_categories($id);
30
+ }
31
+
32
+ public function is_post_in_permitted_category($post_id) {
33
+ return (($this->bitmap & 1) === 1) && $this->post_in_categories($post_id);
34
+ }
35
+
36
+ public function is_permitted_post($id) {
37
+ return (($this->bitmap & 4) === 4) && $this->in_posts($id);
38
+ }
39
+
40
+ public function is_permitted_page($id) {
41
+ return (($this->bitmap & 8) === 8) && $this->in_pages($id);
42
+ }
43
+
44
+ public function is_permitted_comment($id) {
45
+ return (($this->bitmap & 2) === 2) && $this->in_comments($id);
46
+ }
47
+
48
+ public function is_post_in_permitted_parent_category($post_id) {
49
+ return (($this->bitmap & 1) === 1) && $this->post_in_parent_categories($post_id);
50
+ }
51
+
52
+ public function is_permitted_parent_category($id) {
53
+ return (($this->bitmap & 1) === 1) && $this->in_parent_categories($id);
54
+ }
55
+ }
classes/class.bProtection.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ include_once('class.bProtectionBase.php');
3
+
4
+ class BProtection extends BProtectionBase{
5
+ private static $_this;
6
+
7
+ private function __construct() {
8
+ $this->msg = "";
9
+ $this->init(1);
10
+ }
11
+
12
+ public static function get_instance() {
13
+ self::$_this = empty(self::$_this) ? (new BProtection()) : self::$_this;
14
+ return self::$_this;
15
+ }
16
+
17
+ public function is_protected($id) {
18
+ if ($this->post_in_parent_categories($id) || $this->post_in_categories($id)) {
19
+ $this->msg = '<p style="background: #FFF6D5; border: 1px solid #D1B655; color: #3F2502; margin: 10px 0px 10px 0px; padding: 5px 5px 5px 10px;">
20
+ The category or parent category of this post is protected. You can change the category protection settings from the <a href="admin.php?page=eMember_membership_level_menu&level_action=2" target="_blank">manage content protection</a> menu.
21
+ </p>';
22
+ return true;
23
+ }
24
+ return $this->in_posts($id) || $this->in_pages($id) || $this->in_attachments($id) || $this->in_custom_posts($id);
25
+ }
26
+
27
+ public function get_last_message() {
28
+ return $this->msg;
29
+ }
30
+
31
+ public function is_protected_post($id) {
32
+ return /* (($this->bitmap&4) != 4) && */ $this->in_posts($id);
33
+ }
34
+
35
+ public function is_protected_page($id) {
36
+ return /* (($this->bitmap&4) != 4) && */ $this->in_pages($id);
37
+ }
38
+
39
+ public function is_protected_attachment($id) {
40
+ return /* (($this->bitmap&16)!=16) && */ $this->in_attachments($id);
41
+ }
42
+
43
+ public function is_protected_custom_post($id) {
44
+ return /* (($this->bitmap&32)!=32) && */ $this->in_custom_posts($id);
45
+ }
46
+
47
+ public function is_protected_comment($id) {
48
+ return /* (($this->bitmap&2)!=2) && */ $this->in_comments($id);
49
+ }
50
+
51
+ public function is_post_in_protected_category($post_id) {
52
+ return /* (($this->bitmap&1)!=1) && */ $this->post_in_categories($post_id);
53
+ }
54
+
55
+ public function is_post_in_protected_parent_category($post_id) {
56
+ return /* (($this->bitmap&1)!=1) && */ $this->post_in_parent_categories($post_id);
57
+ }
58
+
59
+ public function is_protected_category($id) {
60
+ return /* (($this->bitmap&1)!=1) && */ $this->in_categories($id);
61
+ }
62
+
63
+ public function is_protected_parent_category($id) {
64
+ return /* (($this->bitmap&1)!=1) && */ $this->in_parent_categories($id);
65
+ }
66
+ }
classes/class.bProtectionBase.php ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class BProtectionBase {
4
+
5
+ protected $bitmap;
6
+ protected $posts;
7
+ protected $pages;
8
+ protected $comments;
9
+ protected $categories;
10
+ protected $attachments;
11
+ protected $custom_posts;
12
+ protected $details;
13
+ protected $options;
14
+
15
+ private function __construct() {
16
+
17
+ }
18
+
19
+ protected function init($level_id) {
20
+ global $wpdb;
21
+ $this->owning_level_id = $level_id;
22
+ $query = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id =" . $level_id;
23
+ $result = $wpdb->get_row($query);
24
+ $this->bitmap = isset($result->permissions) ? $result->permissions : 0;
25
+ $this->posts = isset($result->post_list) ? (array) unserialize($result->post_list) : array();
26
+ $this->pages = isset($result->page_list) ? (array) unserialize($result->page_list) : array();
27
+ $this->comments = isset($result->comment_list) ? (array) unserialize($result->comment_list) : array();
28
+ $this->categories = isset($result->category_list) ? (array) unserialize($result->category_list) : array();
29
+ $this->attachments = isset($result->attachment_list) ? (array) unserialize($result->attachment_list) : array();
30
+ $this->custom_posts = isset($result->custom_post_list) ? (array) unserialize($result->custom_post_list) : array();
31
+ $this->options = isset($result->options) ? (array) unserialize($result->options) : array();
32
+ $this->disable_bookmark = isset($result->disable_bookmark_list) ? (array) unserialize($result->disable_bookmark_list) : array();
33
+ $this->details = (array) $result;
34
+ }
35
+ public function apply($ids, $type){
36
+ $post_types = get_post_types(array('public' => true, '_builtin' => false));
37
+ if(in_array($type,$post_types)){$type = 'custom_post';}
38
+ return $this->update_perms($ids, true, $type);
39
+ }
40
+ public function remove($ids, $type){
41
+ $post_types = get_post_types(array('public' => true, '_builtin' => false));
42
+ if(in_array($type,$post_types)){$type = 'custom_post';}
43
+ return $this->update_perms($ids, false, $type);
44
+ }
45
+ public function get_options() {
46
+ return $this->options;
47
+ }
48
+
49
+ public function get_posts() {
50
+ return $this->posts;
51
+ }
52
+
53
+ public function get_pages() {
54
+ return $this->pages;
55
+ }
56
+
57
+ public function get_comments() {
58
+ return $this->comments;
59
+ }
60
+
61
+ public function get_categories() {
62
+ return $this->categories;
63
+ }
64
+
65
+ public function get_attachments() {
66
+ return $this->attachments;
67
+ }
68
+
69
+ public function get_custom_posts() {
70
+ return $this->custom_posts;
71
+ }
72
+
73
+ public function is_bookmark_disabled($id) {
74
+ $posts = isset($this->disable_bookmark['posts']) ?
75
+ $this->disable_bookmark['posts'] : array();
76
+ $pages = isset($this->disable_bookmark['pages']) ?
77
+ $this->disable_bookmark['pages'] : array();
78
+ return in_array($id, $pages) || in_array($id, $posts);
79
+ }
80
+
81
+ public function in_posts($id) {
82
+ return (/* ($this->bitmap&4)===4) && */in_array($id, (array) $this->posts));
83
+ }
84
+
85
+ public function in_pages($id) {
86
+ return (/* ($this->bitmap&8)===8) && */ in_array($id, (array) $this->pages));
87
+ }
88
+
89
+ public function in_attachments($id) {
90
+ return (/* ($this->bitmap&16)===16) && */in_array($id, (array) $this->attachments));
91
+ }
92
+
93
+ public function in_custom_posts($id) {
94
+ return (/* ($this->bitmap&32)===32) && */ in_array($id, (array) $this->custom_posts));
95
+ }
96
+
97
+ public function in_comments($id) {
98
+ return (/* ($this->bitmap&2)===2) && */ in_array($id, (array) $this->comments));
99
+ }
100
+
101
+ public function in_categories($id) {
102
+ if (empty($this->categories))
103
+ return false;
104
+ return (/* ($this->bitmap&1)===1) && */ in_array($id, (array) $this->categories));
105
+ }
106
+
107
+ public function post_in_categories($post_id) {
108
+ if (empty($this->categories))
109
+ return false;
110
+ return (/* ($this->bitmap&1)===1) && */ in_category((array) $this->categories, $post_id));
111
+ }
112
+
113
+ public function in_parent_categories($id) {
114
+ if (empty($this->categories))
115
+ return false;
116
+ $parents = explode(',', get_category_parents($id, false, ','));
117
+ $parents = array_unique($parents);
118
+ foreach ($parents as $parent) {
119
+ if (empty($parent))
120
+ continue;
121
+ if (/* (($this->bitmap&1)===1) && */(in_array($parent, (array) $this->categories)))
122
+ return true;
123
+ }
124
+ return false;
125
+ }
126
+
127
+ public function post_in_parent_categories($post_id) {
128
+ if (empty($this->categories))
129
+ return false;
130
+ $cats = get_the_category($post_id);
131
+ $parents = array();
132
+ foreach ($cats as $key => $cat) {
133
+ $parents = array_merge($parents, explode(',', get_category_parents($cat->cat_ID, false, ',')));
134
+ }
135
+ $parents = array_unique($parents);
136
+ foreach ($parents as $parent) {
137
+ if (empty($parent))
138
+ continue;
139
+ if (/* (($this->bitmap&1)===1) && */(in_array(get_cat_ID($parent), (array) $this->categories)))
140
+ return true;
141
+ }
142
+ return false;
143
+ }
144
+
145
+ public function add_posts($ids) {
146
+ return $this->update_perms($ids, true, 'post');
147
+ }
148
+
149
+ public function add_pages($ids) {
150
+ return $this->update_perms($ids, true, 'page');
151
+ }
152
+
153
+ public function add_attachments($ids) {
154
+ return $this->update_perms($ids, true, 'attachment');
155
+ }
156
+
157
+ public function add_comments($ids) {
158
+ return $this->update_perms($ids, true, 'comment');
159
+ }
160
+
161
+ public function add_categories($ids) {
162
+ return $this->update_perms($ids, true, 'category');
163
+ }
164
+
165
+ public function add_custom_posts($ids) {
166
+ return $this->update_perms($ids, true, 'custom_post');
167
+ }
168
+
169
+ public function remove_posts($ids) {
170
+ return $this->update_perms($ids, false, 'post');
171
+ }
172
+
173
+ public function remove_pages($ids) {
174
+ return $this->update_perms($ids, false, 'page');
175
+ }
176
+
177
+ public function remove_attachments($ids) {
178
+ return $this->update_perms($ids, false, 'attachment');
179
+ }
180
+
181
+ public function remove_comments($ids) {
182
+ return $this->update_perms($ids, false, 'comment');
183
+ }
184
+
185
+ public function remove_categories($ids) {
186
+ return $this->update_perms($ids, false, 'category');
187
+ }
188
+
189
+ public function remove_custom_posts($ids) {
190
+ return $this->update_perms($ids, false, 'custom_post');
191
+ }
192
+
193
+ private function update_perms($ids, $set, $type) {
194
+ $list = null;
195
+ $index = '';
196
+ switch ($type) {
197
+ case 'page':
198
+ $list = $this->pages;
199
+ $index = 'page_list';
200
+ break;
201
+ case 'post':
202
+ $list = $this->posts;
203
+ $index = 'post_list';
204
+ break;
205
+ case 'attachment':
206
+ $list = $this->attachments;
207
+ $index = 'attachment_list';
208
+ break;
209
+ case 'comment':
210
+ $list = $this->comments;
211
+ $index = 'comment_list';
212
+ break;
213
+ case 'category':
214
+ $list = $this->categories;
215
+ $index = 'category_list';
216
+ break;
217
+ case 'custom_post':
218
+ $list = $this->custom_posts;
219
+ $index = 'custom_post_list';
220
+ break;
221
+ default:
222
+ break;
223
+ }
224
+ if (!empty($index)) {
225
+ if ($set) {
226
+ $list = array_merge($list, $ids);
227
+ $list = array_unique($list);
228
+ } else {
229
+ $list = array_diff($list, $ids);
230
+ }
231
+ $this->details[$index] = $list;
232
+ }
233
+ return $this;
234
+ }
235
+
236
+ public function save() {
237
+ global $wpdb;
238
+ $data = array();
239
+
240
+ $list_type = array('page_list', 'post_list', 'attachment_list',
241
+ 'custom_post_list', 'comment_list', 'category_list');
242
+ foreach ($this->details as $key => $value) {
243
+ if ($key == 'id')
244
+ continue;
245
+ if (is_serialized($value) || !in_array($key, $list_type))
246
+ $data[$key] = $value;
247
+ else
248
+ $data[$key] = serialize($value);
249
+ }
250
+ $wpdb->update($wpdb->prefix . "swpm_membership_tbl", $data, array('id' => $this->owning_level_id));
251
+ }
252
+
253
+ public function get($key) {
254
+ if (isset($this->details[$key]))
255
+ return $this->details[$key];
256
+ return "";
257
+ }
258
+
259
+ }
classes/class.bRegistration.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Description of BRegistration
5
+ *
6
+ * @author nur
7
+ */
8
+ abstract class BRegistration {
9
+ protected $member_info = array();
10
+ protected static $_intance = null;
11
+ protected function __construct() {
12
+ ;
13
+ }
14
+ public static function get_instance(){
15
+ $cls = static::$__CLASS__;
16
+ self::$_intance = empty(self::$_intance)? new $cls():self::$_intance;
17
+ return self::$_intance;
18
+ }
19
+ protected function send_reg_email(){
20
+ global $wpdb;
21
+ if (empty($this->member_info)) {return false;}
22
+ $member_info = $this->member_info;
23
+ $settings = BSettings::get_instance();
24
+ $subject = $settings->get_value('reg-complete-mail-subject');
25
+ $body = $settings->get_value('reg-complete-mail-body');
26
+ $from_address = $settings->get_value('email-from');
27
+ $login_link = $settings->get_value('login-page-url');
28
+ $headers = 'From: ' . $from_address . "\r\n";
29
+ $query = "SELECT alias FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id = " . $member_info['membership_level'];
30
+ $member_info['membership_level_name'] = $wpdb->get_var($query);
31
+ $member_info['password'] = $member_info['plain_password'];
32
+ $member_info['login_link'] = $login_link;
33
+ $values = array_values($member_info);
34
+ $keys = array_map(function($n) {
35
+ return '{'.$n .'}';
36
+ }, array_keys($member_info));
37
+ $body = str_replace($keys, $values, $body);
38
+ wp_mail(trim($_POST['email']), $subject, $body, $headers);
39
+ if ($settings->get_value('enable-admin-notification-after-reg')) {
40
+ $subject = "Notification of New Member Registration";
41
+ $body = "A new member has registered. The following email was sent to the member." .
42
+ "\n\n-------Member Email----------\n" . $body .
43
+ "\n\n------End------\n";
44
+ wp_mail($from_address, $subject, $body, $headers);
45
+ }
46
+ return true;
47
+ }
48
+ }
classes/class.bSession.php ADDED
File without changes
classes/class.bSettings.php ADDED
@@ -0,0 +1,318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class BSettings {
4
+
5
+ private static $_this;
6
+ private $settings;
7
+ public $current_tab;
8
+
9
+ private function __construct() {
10
+ $this->settings = (array) get_option('swpm-settings');
11
+ }
12
+ public function init_config_hooks(){
13
+ $page = filter_input(INPUT_GET, 'page');
14
+ // if($page == 'simple_wp_membership_settings'){
15
+ if(is_admin()){ // for frontend just load settings but dont try to render settings page.
16
+ $tab = filter_input(INPUT_GET, 'tab');
17
+ $tab = empty($tab)?filter_input(INPUT_POST, 'tab'):$tab;
18
+ $this->current_tab = empty($tab) ? 1 : $tab;
19
+ add_action('swpm-draw-tab', array(&$this, 'draw_tabs'));
20
+ $method = 'tab_' . $this->current_tab;
21
+ if (method_exists($this, $method)){
22
+ $this->$method();
23
+ }
24
+ }
25
+ }
26
+ private function tab_1() {
27
+ register_setting('swpm-settings-tab-1', 'swpm-settings', array(&$this, 'sanitize_tab_1'));
28
+ add_settings_section('swpm-documentation', 'Plugin Documentation',
29
+ array(&$this, 'swpm_documentation_callback'), 'simple_wp_membership_settings');
30
+ add_settings_section('general-settings', 'General Settings',
31
+ array(&$this, 'general_settings_callback'), 'simple_wp_membership_settings');
32
+ add_settings_field('enable-free-membership', 'Enable Free Membership',
33
+ array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'general-settings',
34
+ array('item' => 'enable-free-membership',
35
+ 'message'=>''));
36
+ add_settings_field('free-membership-id', 'Free Membership Level ID',
37
+ array(&$this, 'textfield_small_callback'), 'simple_wp_membership_settings', 'general-settings',
38
+ array('item' => 'free-membership-id',
39
+ 'message'=>''));
40
+
41
+ add_settings_section('pages-settings', 'Pages Settings',
42
+ array(&$this, 'pages_settings_callback'), 'simple_wp_membership_settings');
43
+ add_settings_field('login-page-url', 'Login Page URL',
44
+ array(&$this, 'textfield_long_callback'), 'simple_wp_membership_settings', 'pages-settings',
45
+ array('item' => 'login-page-url',
46
+ 'message'=>''));
47
+ add_settings_field('registration-page-url', 'Registration Page URL',
48
+ array(&$this, 'textfield_long_callback'), 'simple_wp_membership_settings', 'pages-settings',
49
+ array('item' => 'registration-page-url',
50
+ 'message'=>''));
51
+ add_settings_field('join-us-page-url', 'Join Us Page URL',
52
+ array(&$this, 'textfield_long_callback'), 'simple_wp_membership_settings', 'pages-settings',
53
+ array('item' => 'join-us-page-url',
54
+ 'message'=>''));
55
+ add_settings_field('profile-page-url', 'Edit Profile Page URL',
56
+ array(&$this, 'textfield_long_callback'), 'simple_wp_membership_settings', 'pages-settings',
57
+ array('item' => 'profile-page-url',
58
+ 'message'=>''));
59
+ add_settings_field('reset-page-url', 'Password Reset Page URL',
60
+ array(&$this, 'textfield_long_callback'), 'simple_wp_membership_settings', 'pages-settings',
61
+ array('item' => 'reset-page-url',
62
+ 'message'=>''));
63
+
64
+ add_settings_section('debug-settings', 'Test & Debug Settings',
65
+ array(&$this, 'testndebug_settings_callback'), 'simple_wp_membership_settings');
66
+ add_settings_field('enable-debug', 'Enable Debug',
67
+ array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'debug-settings',
68
+ array('item' => 'enable-debug',
69
+ 'message'=>'Check this option to enable debug logging. View debug log file <a href="'.SIMPLE_WP_MEMBERSHIP_URL.'/log.txt" target="_blank">here</a>.'));
70
+ add_settings_field('enable-sandbox-testing', 'Enable Sandbox Testing',
71
+ array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'debug-settings',
72
+ array('item' => 'enable-sandbox-testing',
73
+ 'message'=>'Enable this option if you want to do sandbox payment testing.'));
74
+
75
+ }
76
+
77
+ private function tab_2() {
78
+ //register_setting( 'swpm-settings-tab-2', 'swpm-settings' , array(&$this, 'sanitize_tab_2'));
79
+ //add_settings_section('paypal-settings', 'PayPal Settings', array(&$this,'pp_payment_settings_callback'), 'simple_wp_membership_settings');
80
+ //add_settings_field( 'paypal-email', 'PayPal Email', array(&$this, 'textfield_callback'), 'simple_wp_membership_settings', 'paypal-settings' ,array('item'=>'paypal-email'));
81
+ }
82
+
83
+ private function tab_3() {
84
+ register_setting('swpm-settings-tab-3', 'swpm-settings', array(&$this, 'sanitize_tab_3'));
85
+
86
+ add_settings_section('email-misc-settings', 'Email Misc. Settings',
87
+ array(&$this, 'email_misc_settings_callback'), 'simple_wp_membership_settings');
88
+ add_settings_field('email-misc-from', 'From Email Address',
89
+ array(&$this, 'textfield_callback'), 'simple_wp_membership_settings', 'email-misc-settings',
90
+ array('item' => 'email-from',
91
+ 'message'=>'field specific message.'));
92
+
93
+ add_settings_section('reg-prompt-email-settings', 'Email Settings (Prompt to Complete Registration )',
94
+ array(&$this, 'reg_prompt_email_settings_callback'), 'simple_wp_membership_settings');
95
+ add_settings_field('reg-prompt-complete-mail-subject', 'Email Subject',
96
+ array(&$this, 'textfield_callback'), 'simple_wp_membership_settings', 'reg-prompt-email-settings',
97
+ array('item' => 'reg-prompt-complete-mail-subject',
98
+ 'message'=>''));
99
+ add_settings_field('reg-prompt-complete-mail-body', 'Email Body',
100
+ array(&$this, 'textarea_callback'), 'simple_wp_membership_settings', 'reg-prompt-email-settings',
101
+ array('item' => 'reg-prompt-complete-mail-body',
102
+ 'message'=>''));
103
+
104
+ add_settings_section('reg-email-settings', 'Email Settings (Registration Complete)',
105
+ array(&$this, 'reg_email_settings_callback'), 'simple_wp_membership_settings');
106
+ add_settings_field('reg-complete-mail-subject', 'Email Subject',
107
+ array(&$this, 'textfield_callback'), 'simple_wp_membership_settings', 'reg-email-settings',
108
+ array('item' => 'reg-complete-mail-subject',
109
+ 'message'=>''));
110
+ add_settings_field('reg-complete-mail-body', 'Email Body',
111
+ array(&$this, 'textarea_callback'), 'simple_wp_membership_settings', 'reg-email-settings',
112
+ array('item' => 'reg-complete-mail-body',
113
+ 'message'=>''));
114
+ add_settings_field('enable-admin-notification-after-reg', 'Send Notification To Admin',
115
+ array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'reg-email-settings',
116
+ array('item' => 'enable-admin-notification-after-reg',
117
+ 'message'=>''));
118
+ add_settings_field('enable-notification-after-manual-user-add', 'Send Email to Member When Added via Admin Dashboard',
119
+ array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'reg-email-settings',
120
+ array('item' => 'enable-notification-after-manual-user-add',
121
+ 'message'=>''));
122
+
123
+ add_settings_section('upgrade-email-settings', ' Email Settings (Account Upgrade Notification)',
124
+ array(&$this, 'upgrade_email_settings_callback'), 'simple_wp_membership_settings');
125
+ add_settings_field('upgrade-complete-mail-subject', 'Email Subject',
126
+ array(&$this, 'textfield_callback'), 'simple_wp_membership_settings', 'upgrade-email-settings',
127
+ array('item' => 'upgrade-complete-mail-subject',
128
+ 'message'=>''));
129
+ add_settings_field('upgrade-complete-mail-body', 'Email Body',
130
+ array(&$this, 'textarea_callback'), 'simple_wp_membership_settings', 'upgrade-email-settings',
131
+ array('item' => 'upgrade-complete-mail-body',
132
+ 'message'=>''));
133
+ }
134
+ private function tab_4(){
135
+ }
136
+
137
+ public static function get_instance() {
138
+ self::$_this = empty(self::$_this) ? new BSettings() : self::$_this;
139
+ return self::$_this;
140
+ }
141
+
142
+ public function checkbox_callback($args) {
143
+ $item = $args['item'];
144
+ $msg = isset($args['message'])?$args['message']: '';
145
+ $is = esc_attr($this->get_value($item));
146
+ echo "<input type='checkbox' $is name='swpm-settings[" . $item . "]' value=\"checked='checked'\" />";
147
+ echo '<br/><i>'.$msg.'</i>';
148
+ }
149
+
150
+ public function textarea_callback($args) {
151
+ $item = $args['item'];
152
+ $msg = isset($args['message'])?$args['message']: '';
153
+ $text = esc_attr($this->get_value($item));
154
+ echo "<textarea name='swpm-settings[" . $item . "]' rows='6' cols='60' >" . $text . "</textarea>";
155
+ echo '<br/><i>'.$msg.'</i>';
156
+ }
157
+
158
+ public function textfield_small_callback($args) {
159
+ $item = $args['item'];
160
+ $msg = isset($args['message'])?$args['message']: '';
161
+ $text = esc_attr($this->get_value($item));
162
+ echo "<input type='text' name='swpm-settings[" . $item . "]' size='5' value='" . $text . "' />";
163
+ echo '<br/><i>'.$msg.'</i>';
164
+ }
165
+
166
+ public function textfield_callback($args) {
167
+ $item = $args['item'];
168
+ $msg = isset($args['message'])?$args['message']: '';
169
+ $text = esc_attr($this->get_value($item));
170
+ echo "<input type='text' name='swpm-settings[" . $item . "]' size='50' value='" . $text . "' />";
171
+ echo '<br/><i>'.$msg.'</i>';
172
+ }
173
+
174
+ public function textfield_long_callback($args) {
175
+ $item = $args['item'];
176
+ $msg = isset($args['message'])?$args['message']: '';
177
+ $text = esc_attr($this->get_value($item));
178
+ echo "<input type='text' name='swpm-settings[" . $item . "]' size='100' value='" . $text . "' />";
179
+ echo '<br/><i>'.$msg.'</i>';
180
+ }
181
+
182
+ public function swpm_documentation_callback() {
183
+ ?>
184
+ <div style="background: none repeat scroll 0 0 #FFF6D5;border: 1px solid #D1B655;color: #3F2502;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
185
+ <p>Please visit the
186
+ <a target="_blank" href="https://simple-membership-plugin.com/">Simple Membership Plugin Site</a>
187
+ to read setup and configuration documentation.
188
+ </p>
189
+ </div>
190
+ <?php
191
+ }
192
+
193
+ public function general_settings_callback() {
194
+ echo "<p>General Plugin Settings.</p>";
195
+ }
196
+
197
+ public function testndebug_settings_callback(){
198
+ echo "<p>Test and Debug Related Settings.</p>";
199
+ }
200
+ public function reg_email_settings_callback() {
201
+ echo "<p>This email will be sent to your users when they complete the registration and become a member.</p>";
202
+ }
203
+ public function email_misc_settings_callback(){
204
+ echo "<p>Settings in this section apply to all emails.</p>";
205
+ }
206
+ public function upgrade_email_settings_callback() {
207
+ echo "<p>This email will be sent to your users after account upgrade.</p>";
208
+ }
209
+
210
+ public function reg_prompt_email_settings_callback() {
211
+ echo "<p>This email will be sent to prompt user to complete registration.</p>";
212
+ }
213
+
214
+ public function pages_settings_callback() {
215
+ echo '<p>Page Setup and URL Related settings.<p>';
216
+ }
217
+
218
+ public function sanitize_tab_1($input) {
219
+ if (empty($this->settings)){
220
+ $this->settings = (array) get_option('swpm-settings');
221
+ }
222
+ $output = $this->settings;
223
+ //general settings block
224
+ if (isset($input['enable-free-membership'])){
225
+ $output['enable-free-membership'] = esc_url($input['enable-free-membership']);
226
+ }
227
+ else{
228
+ $output['enable-free-membership'] = "";
229
+ }
230
+ if (isset($input['enable-debug'])){
231
+ $output['enable-debug'] = esc_url($input['enable-debug']);
232
+ }
233
+ else{
234
+ $output['enable-debug'] = "";
235
+ }
236
+ if (isset($input['enable-sandbox-testing'])){
237
+ $output['enable-sandbox-testing'] = esc_url($input['enable-sandbox-testing']);
238
+ }
239
+ else{
240
+ $output['enable-sandbox-testing'] = "";
241
+ }
242
+ $output['free-membership-id'] = ($input['free-membership-id'] != 1) ? absint($input['free-membership-id']) : '';
243
+ $output['login-page-url'] = esc_url($input['login-page-url']);
244
+ $output['registration-page-url'] = esc_url($input['registration-page-url']);
245
+ $output['profile-page-url'] = esc_url($input['profile-page-url']);
246
+ $output['reset-page-url'] = esc_url($input['reset-page-url']);
247
+ $output['join-us-page-url'] = esc_url($input['join-us-page-url']);
248
+ return $output;
249
+ }
250
+
251
+ public function sanitize_tab_3($input) {
252
+ if (empty($this->settings)){
253
+ $this->settings = (array) get_option('swpm-settings');
254
+ }
255
+ $output = $this->settings;
256
+ $output['reg-complete-mail-subject'] = sanitize_text_field($input['reg-complete-mail-subject']);
257
+ $output['reg-complete-mail-body'] = wp_kses_data(force_balance_tags($input['reg-complete-mail-body']));
258
+
259
+ $output['upgrade-complete-mail-subject'] = sanitize_text_field($input['upgrade-complete-mail-subject']);
260
+ $output['upgrade-complete-mail-body'] = wp_kses_data(force_balance_tags($input['upgrade-complete-mail-body']));
261
+
262
+ $output['reg-prompt-complete-mail-subject'] = sanitize_text_field($input['reg-prompt-complete-mail-subject']);
263
+ $output['reg-prompt-complete-mail-body'] = wp_kses_data(force_balance_tags($input['reg-prompt-complete-mail-body']));
264
+ $output['email-from'] = trim($input['email-from']);
265
+ if (isset($input['enable-admin-notification-after-reg'])){
266
+ $output['enable-admin-notification-after-reg'] = esc_html($input['enable-admin-notification-after-reg']);
267
+ }
268
+ else{
269
+ $output['enable-admin-notification-after-reg'] = "";
270
+ }
271
+ if (isset($input['enable-notification-after-manual-user-add'])){
272
+ $output['enable-notification-after-manual-user-add'] = esc_html($input['enable-notification-after-manual-user-add']);
273
+ }
274
+ else{
275
+ $output['enable-notification-after-manual-user-add'] = "";
276
+ }
277
+ return $output;
278
+ }
279
+
280
+ public function get_value($key, $default = "") {
281
+ if (isset($this->settings[$key])){
282
+ return $this->settings[$key];
283
+ }
284
+ return $default;
285
+ }
286
+
287
+ public function set_value($key, $value) {
288
+ $this->settings[$key] = $value;
289
+ return $this;
290
+ }
291
+
292
+ public function save() {
293
+ update_option('swpm-settings', $this->settings);
294
+ }
295
+
296
+ public function draw_tabs() {
297
+ $current = $this->current_tab;
298
+ ?>
299
+ <h3 class="nav-tab-wrapper">
300
+ <a class="nav-tab <?php echo ($current == 1) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_settings">General Settings</a>
301
+ <a class="nav-tab <?php echo ($current == 2) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_settings&tab=2">Payment Settings</a>
302
+ <a class="nav-tab <?php echo ($current == 3) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_settings&tab=3">Email Settings</a>
303
+ <a class="nav-tab <?php echo ($current == 4) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_settings&tab=4">Tools</a>
304
+ </h3>
305
+ <?php
306
+ }
307
+
308
+ public function get_login_link() {
309
+ $login = $this->get_value('login-page-url');
310
+ $joinus = $this->get_value('join-us-page-url');
311
+ if (empty ($login) || empty($joinus)){
312
+ return '<span style="color:red;">Simple Membership is not configured correctly.'
313
+ . 'Please contact <a href="mailto:' . get_option('admin_email'). '">Admin</a>';
314
+ }
315
+ return 'Please <a href="' . $login . '">Login</a>. Not a Member? <a href="' . $joinus . '">Join Us</a>';
316
+ }
317
+
318
+ }
classes/class.bTransfer.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class BTransfer {
4
+
5
+ public static $default_fields = array(
6
+ 'first_name' => '', 'last_name' => '',
7
+ 'user_name' => '', 'email' => '',
8
+ 'password' => '',
9
+ 'phone' => '', 'account_state' => '',
10
+ 'member_since' => '', 'subscription_starts' => '',
11
+ 'address_street' => '', 'address_city' => '',
12
+ 'address_state' => '', 'address_zipcode' => '',
13
+ 'company_name' => '', 'country' => '',
14
+ 'gender' => 'not specified',
15
+ 'membership_level' => '2');
16
+ public static $default_level_fields = array(
17
+ 'alias' => '', 'role' => '',
18
+ 'subscription_period' => '', 'subscription_unit' => 'days');
19
+ public static $admin_messages = array();
20
+ private static $_this;
21
+ private $message;
22
+
23
+ private function __contruct() {
24
+ $this->message = get_option('swpm-messages');
25
+ }
26
+
27
+ public static function get_instance() {
28
+ self::$_this = empty(self::$_this) ? new BTransfer() : self::$_this;
29
+ self::$_this->message = get_option('swpm-messages');
30
+ return self::$_this;
31
+ }
32
+
33
+ public function get($key) {
34
+ $sesion_key = $_COOKIE['swpm_session'];
35
+ $m = '';
36
+ if (isset($this->message[$sesion_key])){
37
+ $m = $this->message[$sesion_key]->get($key);
38
+ }
39
+ update_option('swpm-messages', $this->message);
40
+ return $m;
41
+ }
42
+
43
+ public function set($key, $value) {
44
+ $sesion_key = $_COOKIE['swpm_session'];
45
+ if (!isset($this->message[$sesion_key])){
46
+ $this->message[$sesion_key] = new BMessages();
47
+ }
48
+ $this->message[$sesion_key]->set($key,$value);
49
+ update_option('swpm-messages', $this->message);
50
+ }
51
+
52
+ public static function get_real_ip_addr() {
53
+ if (!empty($_SERVER['HTTP_CLIENT_IP']))
54
+ $ip = $_SERVER['HTTP_CLIENT_IP'];
55
+ else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
56
+ $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
57
+ else
58
+ $ip = $_SERVER['REMOTE_ADDR'];
59
+
60
+ return $ip;
61
+ }
62
+
63
+ }
classes/class.bUtils.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class BUtils {
4
+
5
+ public static function calculate_subscription_period($subcript_period, $subscript_unit) {
6
+ if (($subcript_period == 0) && !empty($subscript_unit)) //will expire after a fixed date.
7
+ return date(get_option('date_format'), strtotime($subscript_unit));
8
+ switch ($subscript_unit) {
9
+ case 'Days':
10
+ break;
11
+ case 'Weeks':
12
+ $subcript_period = $subcript_period * 7;
13
+ break;
14
+ case 'Months':
15
+ $subcript_period = $subcript_period * 30;
16
+ break;
17
+ case 'Years':
18
+ $subcript_period = $subcript_period * 365;
19
+ break;
20
+ }
21
+ if ($subcript_period == 0)// its set to no expiry until cancelled
22
+ return 'noexpire';
23
+ return $subcript_period . ' ' . $subscript_unit;
24
+ }
25
+
26
+ public static function gender_dropdown($selected = 'not specified') {
27
+ return '<option ' . ((strtolower($selected) == 'male') ? 'selected="selected"' : "") . ' value="male">Male</option>' .
28
+ '<option ' . ((strtolower($selected) == 'female') ? 'selected="selected"' : "") . ' value="female">Female</option>' .
29
+ '<option ' . ((strtolower($selected) == 'not specified') ? 'selected="selected"' : "") . ' value="not specified">Not Specified</option>';
30
+ }
31
+
32
+ public static function subscription_unit_dropdown($selected = 'days') {
33
+ return '<option ' . ((strtolower($selected) == 'days') ? 'selected="selected"' : "") . ' value="days">Days</option>' .
34
+ '<option ' . ((strtolower($selected) == 'weeks') ? 'selected="selected"' : "") . ' value="weeks">Weeks</option>' .
35
+ '<option ' . ((strtolower($selected) == 'months') ? 'selected="selected"' : "") . ' value="months">Months</option>' .
36
+ '<option ' . ((strtolower($selected) == 'years') ? 'selected="selected"' : "") . ' value="years">Years</option>';
37
+ }
38
+
39
+ public static function get_user_by_id($swpm_id) {
40
+ global $wpdb;
41
+ $query = "SELECT user_name FROM {$wpdb->prefix}swpm_members_tbl WHERE member_id = $swpm_id";
42
+ return $wpdb->get_var($query);
43
+ }
44
+
45
+ public static function get_registration_link($for = 'all', $send_email = false, $member_id = '') {
46
+ $members = array();
47
+ global $wpdb;
48
+ switch ($for) {
49
+ case 'one':
50
+ if (empty($member_id)) {
51
+ return array();
52
+ }
53
+ $query = "SELECT * FROM {$wpdb->prefix}swpm_members_tbl WHERE member_id = $member_id ";
54
+ $members = $wpdb->get_results($query);
55
+ break;
56
+ case 'all':
57
+ $query = "SELECT * FROM {$wpdb->prefix}swpm_members_tbl WHERE reg_code != '' ";
58
+ $members = $wpdb->get_results($query);
59
+ break;
60
+ }
61
+ $settings = BSettings::get_instance();
62
+ $separator = '?';
63
+ $url = $settings->get_value('registration-page-url');
64
+ if (strpos($url, '?') !== false) {
65
+ $separator = '&';
66
+ }
67
+ $subject = $settings->get_value('reg-complete-mail-subject');
68
+ if (empty($subject)) {
69
+ $subject = "Please complete your registration";
70
+ }
71
+ $body = $settings->get_value('reg-complete-mail-body');
72
+ if (empty($body)) {
73
+ $body = "Please use the following link to complete your registration. \n {reg_link}";
74
+ }
75
+ $from_address = $settings->get_value('email-from');
76
+ $links = array();
77
+ foreach ($members as $member) {
78
+ $reg_url = $url . $separator . 'member_id=' . $member->member_id . '&code=' . $member->reg_code;
79
+ if (!empty($send_email) && empty($member->user_name)) {
80
+ $tags = array("{first_name}", "{last_name}", "{reg_link}");
81
+ $vals = array($member->first_name, $member->last_name, $reg_url);
82
+ $email_body = str_replace($tags, $vals, $body);
83
+ $headers = 'From: ' . $from_address . "\r\n";
84
+ wp_mail($member->email, $subject, $email_body, $headers);
85
+ }
86
+ $links[] = $reg_url;
87
+ }
88
+ return $links;
89
+ }
90
+
91
+ public static function update_wp_user_Role($wp_user_id, $role) {
92
+ $preserve_role = 'yes';
93
+ if ($preserve_role) {
94
+ return;
95
+ }
96
+ if (self::is_multisite_install()) {//MS install
97
+ return; //TODO - don't do this for MS install
98
+ }
99
+ $caps = get_user_meta($wp_user_id, 'wp_capabilities', true);
100
+ if (in_array('administrator', array_keys((array) $caps))) {
101
+ return;
102
+ }
103
+ do_action('set_user_role', $wp_user_id, $role); //Fire the action for other plugin(s)
104
+ wp_update_user(array('ID' => $wp_user_id, 'role' => $role));
105
+ $roles = new WP_Roles();
106
+ $level = $roles->roles[$role]['capabilities'];
107
+ if (isset($level['level_10']) && $level['level_10']) {
108
+ update_user_meta($wp_user_id, 'wp_user_level', 10);
109
+ return;
110
+ }
111
+ if (isset($level['level_9']) && $level['level_9']) {
112
+ update_user_meta($wp_user_id, 'wp_user_level', 9);
113
+ return;
114
+ }
115
+ if (isset($level['level_8']) && $level['level_8']) {
116
+ update_user_meta($wp_user_id, 'wp_user_level', 8);
117
+ return;
118
+ }
119
+ if (isset($level['level_7']) && $level['level_7']) {
120
+ update_user_meta($wp_user_id, 'wp_user_level', 7);
121
+ return;
122
+ }
123
+ if (isset($level['level_6']) && $level['level_6']) {
124
+ update_user_meta($wp_user_id, 'wp_user_level', 6);
125
+ return;
126
+ }
127
+ if (isset($level['level_5']) && $level['level_5']) {
128
+ update_user_meta($wp_user_id, 'wp_user_level', 5);
129
+ return;
130
+ }
131
+ if (isset($level['level_4']) && $level['level_4']) {
132
+ update_user_meta($wp_user_id, 'wp_user_level', 4);
133
+ return;
134
+ }
135
+ if (isset($level['level_3']) && $level['level_3']) {
136
+ update_user_meta($wp_user_id, 'wp_user_level', 3);
137
+ return;
138
+ }
139
+ if (isset($level['level_2']) && $level['level_2']) {
140
+ update_user_meta($wp_user_id, 'wp_user_level', 2);
141
+ return;
142
+ }
143
+ if (isset($level['level_1']) && $level['level_1']) {
144
+ update_user_meta($wp_user_id, 'wp_user_level', 1);
145
+ return;
146
+ }
147
+ if (isset($level['level_0']) && $level['level_0']) {
148
+ update_user_meta($wp_user_id, 'wp_user_level', 0);
149
+ return;
150
+ }
151
+ }
152
+ public static function create_wp_user($wp_user_data) {
153
+ if (self::is_multisite_install()) {//MS install
154
+ global $blog_id;
155
+ if ($wp_user_id = email_exists($wp_user_data['user_email'])) {// if user exists then just add him to current blog.
156
+ add_existing_user_to_blog(array('user_id' => $wp_user_id, 'role' => 'subscriber'));
157
+ return $wp_user_id;
158
+ }
159
+ $wp_user_id = wpmu_create_user($wp_user_data['user_login'], $wp_user_data['password'], $wp_user_data['user_email']);
160
+ $role = 'subscriber'; //TODO - add user as a subscriber first. The subsequent update user role function to update the role to the correct one
161
+ add_user_to_blog($blog_id, $wp_user_id, $role);
162
+ } else {//Single site install
163
+ $wp_user_id = wp_create_user($wp_user_data['user_login'], $wp_user_data['password'], $wp_user_data['user_email']);
164
+ }
165
+ $wp_user_data['ID'] = $wp_user_id;
166
+ wp_update_user($wp_user_data);
167
+ $user_info = get_userdata($wp_user_id);
168
+ $user_cap = (isset($user_info->wp_capabilities) && is_array($user_info->wp_capabilities)) ? array_keys($user_info->wp_capabilities) : array();
169
+ if (!in_array('administrator', $user_cap)){
170
+ BUtils::update_wp_user_Role($wp_user_id, $wp_user_data['role']);
171
+ }
172
+ return $wp_user_id;
173
+ }
174
+ public static function is_multisite_install() {
175
+ if (function_exists('is_multisite') && is_multisite()) {
176
+ return true;
177
+ } else {
178
+ return false;
179
+ }
180
+ }
181
+ }
classes/class.miscUtils.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class miscUtils
4
+ {
5
+ public static function create_mandatory_wp_pages()
6
+ {
7
+ $settings = BSettings::get_instance();
8
+
9
+ //Create join us page
10
+ $swpm_join_page_content = '<p style="color:red;font-weight:bold;">This page and the content has been automatically generated for you to give you a basic idea of how a "Join Us" page should look like. You can customize this page however you like it by editing this page from your WordPress page editor.</p>';
11
+ $swpm_join_page_content .= '<p style="font-weight:bold;">If you end up changing the URL of this page then make sure to update the URL value in the settings menu of the plugin.</p>';
12
+ $swpm_join_page_content .= '<p style="border-top:1px solid #ccc;padding-top:10px;margin-top:10px;"></p>
13
+ <strong>Free Membership</strong>
14
+ <br />
15
+ You get unlimited access to free membership content
16
+ <br />
17
+ <em><strong>Price: Free!</strong></em>
18
+ <br /><br />Link the following image to go to the Registration Page if you want your visitors to be able to create a free membership account<br /><br />
19
+ <img title="Join Now" src="' . SIMPLE_WP_MEMBERSHIP_URL . '/images/join-now-button-image.gif" alt="Join Now Button" width="277" height="82" />
20
+ <p style="border-bottom:1px solid #ccc;padding-bottom:10px;margin-bottom:10px;"></p>';
21
+ $swpm_join_page_content .= '<p><strong>You can register for a Free Membership or pay for one of the following membership options</strong></p>';
22
+ $swpm_join_page_content .= '<p style="border-top:1px solid #ccc;padding-top:10px;margin-top:10px;"></p>
23
+ [ ==> Insert Payment Button For Your Paid Membership Levels Here <== ]
24
+ <p style="border-bottom:1px solid #ccc;padding-bottom:10px;margin-bottom:10px;"></p>';
25
+
26
+ $swpm_join_page = array(
27
+ 'post_title' => 'Join Us',
28
+ 'post_name' => 'membership-join',
29
+ 'post_content' => $swpm_join_page_content,
30
+ 'post_parent' => 0,
31
+ 'post_status' => 'publish',
32
+ 'post_type' => 'page',
33
+ 'comment_status' => 'closed',
34
+ 'ping_status' => 'closed'
35
+ );
36
+
37
+ $join_page_obj = get_page_by_path('membership-join');
38
+ if(!$join_page_obj) {
39
+ $join_page_id = wp_insert_post($swpm_join_page);
40
+ }else {
41
+ $join_page_id = $join_page_obj->ID;
42
+ if ($join_page_obj->post_status == 'trash'){ //For cases where page may be in trash, bring it out of trash
43
+ wp_update_post(array('ID' => $join_page_obj->ID, 'post_status' => 'publish'));
44
+ }
45
+ }
46
+ $swpm_join_page_permalink = get_permalink($join_page_id);
47
+ $settings->set_value('join-us-page-url',$swpm_join_page_permalink);
48
+
49
+ //Create registration page
50
+ $swpm_rego_page = array(
51
+ 'post_title' => 'Registration',
52
+ 'post_name' => 'membership-registration',
53
+ 'post_content' => '[swpm_registration_form]',
54
+ 'post_parent' => $join_page_id,
55
+ 'post_status' => 'publish',
56
+ 'post_type' => 'page',
57
+ 'comment_status' => 'closed',
58
+ 'ping_status' => 'closed'
59
+ );
60
+ $rego_page_obj = get_page_by_path('membership-registration');
61
+ if(!$rego_page_obj) {
62
+ $rego_page_id = wp_insert_post($swpm_rego_page);
63
+ }else {
64
+ $rego_page_id = $rego_page_obj->ID;
65
+ if ($rego_page_obj->post_status == 'trash'){ //For cases where page may be in trash, bring it out of trash
66
+ wp_update_post(array('ID' => $rego_page_obj->ID, 'post_status' => 'publish'));
67
+ }
68
+ }
69
+ $swpm_rego_page_permalink = get_permalink($rego_page_id);
70
+ $settings->set_value('registration-page-url',$swpm_rego_page_permalink);
71
+
72
+ //Create login page
73
+ $swpm_login_page = array(
74
+ 'post_title' => 'Member Login',
75
+ 'post_name' => 'membership-login',
76
+ 'post_content' => '[swpm_login_form]',
77
+ 'post_parent' => 0,
78
+ 'post_status' => 'publish',
79
+ 'post_type' => 'page',
80
+ 'comment_status' => 'closed',
81
+ 'ping_status' => 'closed'
82
+ );
83
+ $login_page_obj = get_page_by_path('membership-login');
84
+ if(!$login_page_obj) {
85
+ $login_page_id = wp_insert_post($swpm_login_page);
86
+ }else {
87
+ $login_page_id = $login_page_obj->ID;
88
+ if ($login_page_obj->post_status == 'trash'){ //For cases where page may be in trash, bring it out of trash
89
+ wp_update_post(array('ID' => $login_page_obj->ID, 'post_status' => 'publish'));
90
+ }
91
+ }
92
+ $swpm_login_page_permalink = get_permalink($login_page_id);
93
+ $settings->set_value('login-page-url',$swpm_login_page_permalink);
94
+
95
+ //Create profile page
96
+ $swpm_profile_page = array(
97
+ 'post_title' => 'Profile',
98
+ 'post_name' => 'membership-profile',
99
+ 'post_content' => '[swpm_profile_form]',
100
+ 'post_parent' => $login_page_id,
101
+ 'post_status' => 'publish',
102
+ 'post_type' => 'page',
103
+ 'comment_status' => 'closed',
104
+ 'ping_status' => 'closed'
105
+ );
106
+ $profile_page_obj = get_page_by_path('membership-profile');
107
+ if(!$profile_page_obj) {
108
+ $profile_page_id = wp_insert_post($swpm_profile_page);
109
+ }else {
110
+ $profile_page_id = $profile_page_obj->ID;
111
+ if ($profile_page_obj->post_status == 'trash'){ //For cases where page may be in trash, bring it out of trash
112
+ wp_update_post(array('ID' => $profile_page_obj->ID, 'post_status' => 'publish'));
113
+ }
114
+ }
115
+ $swpm_profile_page_permalink = get_permalink($profile_page_id);
116
+ $settings->set_value('profile-page-url',$swpm_profile_page_permalink);
117
+
118
+ //Create reset page
119
+ $swpm_reset_page = array(
120
+ 'post_title' => 'Password Reset',
121
+ 'post_name' => 'password-reset',
122
+ 'post_content' => '[swpm_reset_form]',
123
+ 'post_parent' => $login_page_id,
124
+ 'post_status' => 'publish',
125
+ 'post_type' => 'page',
126
+ 'comment_status' => 'closed',
127
+ 'ping_status' => 'closed'
128
+ );
129
+ $reset_page_obj = get_page_by_path('password-reset');
130
+ if(!$profile_page_obj) {
131
+ $reset_page_id = wp_insert_post($swpm_reset_page);
132
+ }else {
133
+ $reset_page_id = $reset_page_obj->ID;
134
+ if ($reset_page_obj->post_status == 'trash'){ //For cases where page may be in trash, bring it out of trash
135
+ wp_update_post(array('ID' => $reset_page_obj->ID, 'post_status' => 'publish'));
136
+ }
137
+ }
138
+ $swpm_reset_page_permalink = get_permalink($reset_page_id);
139
+ $settings->set_value('reset-page-url',$swpm_reset_page_permalink);
140
+
141
+ $settings->save();//Save all settings object changes
142
+ }
143
+ }
classes/class.simple-wp-membership.php ADDED
@@ -0,0 +1,502 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ include_once('class.bUtils.php');
4
+ include_once('class.miscUtils.php');
5
+ include_once('class.bSettings.php');
6
+ include_once('class.bProtection.php');
7
+ include_once('class.bPermission.php');
8
+ include_once('class.bAuth.php');
9
+ include_once('class.bAccessControl.php');
10
+ include_once('class.bForm.php');
11
+ include_once('class.bTransfer.php');
12
+ include_once('class.bFrontForm.php');
13
+ include_once('class.bLevelForm.php');
14
+ include_once('class.bMembershipLevels.php');
15
+ include_once('class.bLog.php');
16
+ include_once('class.bMessages.php');
17
+ include_once('class.bAjax.php');
18
+ include_once('class.bRegistration.php');
19
+ include_once('class.bFrontRegistration.php');
20
+ include_once('class.bAdminRegistration.php');
21
+ include_once('class.bMembershipLevel.php');
22
+ include_once('class.bMembershipLevelCustom.php');
23
+ include_once('class.bMembershipLevelUtils.php');
24
+
25
+ class SimpleWpMembership {
26
+ public function __construct() {
27
+ BAuth::get_instance();
28
+ add_action('admin_menu', array(&$this, 'menu'));
29
+ //add_action('admin_init', array(&$this, 'admin_init')); //This call has been moved inside 'init' function
30
+ add_action('init', array(&$this, 'init'));
31
+ add_filter('the_content', array(&$this, 'filter_content'));
32
+ //add_filter( 'the_content_more_link', array(&$this, 'filter_moretag'), 10, 2 );
33
+ add_filter('comment_text', array(&$this, 'filter_comment'));
34
+ add_action('save_post', array(&$this, 'save_postdata'));
35
+ add_shortcode("swpm_registration_form", array(&$this, 'registration_form'));
36
+ add_shortcode('swpm_profile_form', array(&$this, 'profile_form'));
37
+ add_shortcode('swpm_login_form', array(&$this, 'login'));
38
+ add_shortcode('swpm_reset_form', array(&$this, 'reset'));
39
+ add_action('admin_notices', array(&$this, 'notices'));
40
+ add_action('wp_enqueue_scripts', array(&$this, 'front_library'));
41
+ add_action('load-toplevel_page_simple_wp_membership', array(&$this, 'admin_library'));
42
+ add_action('load-wp-membership_page_simple_wp_membership_levels', array(&$this, 'admin_library'));
43
+ add_action('profile_update', array(&$this, 'sync_with_wp_profile'), 10, 2);
44
+ add_action('wp_logout', array(&$this, 'wp_logout'));
45
+ add_action('wp_authenticate', array(&$this, 'wp_login'), 1, 2);
46
+ add_action('swpm_logout', array(&$this, 'swpm_logout'));
47
+
48
+ //AJAX hooks
49
+ add_action('wp_ajax_swpm_validate_email', 'BAjax::validate_email_ajax');
50
+ add_action('wp_ajax_nopriv_swpm_validate_email', 'BAjax::validate_email_ajax');
51
+ add_action('wp_ajax_swpm_validate_user_name', 'BAjax::validate_user_name_ajax');
52
+ add_action('wp_ajax_nopriv_swpm_validate_user_name', 'BAjax::validate_user_name_ajax');
53
+
54
+ //init is too early for settings api.
55
+ add_action('admin_init', function (){BSettings::get_instance()->init_config_hooks();});
56
+
57
+ }
58
+ public function shutdown(){
59
+ BLog::writeall();
60
+ }
61
+ public static function swpm_login($user, $pass, $rememberme = true) {
62
+ if (is_user_logged_in()) {
63
+ $current_user = wp_get_current_user();
64
+ if ($current_user->user_login == $user){
65
+ return;
66
+ }
67
+ }
68
+ wp_signon(array('user_login' => $user, 'user_password' => $pass, 'remember' => $rememberme), is_ssl() ? true : false);
69
+ do_action('swpm_after_login');
70
+ wp_redirect(site_url());
71
+ }
72
+
73
+ public function swpm_logout() {
74
+ if (is_user_logged_in()) {
75
+ wp_logout();
76
+ wp_set_current_user(0);
77
+ }
78
+ }
79
+
80
+ public function wp_login($username, $password) {
81
+ $auth = BAuth::get_instance();
82
+ if (($auth->is_logged_in() && ($auth->userData->user_name == $username))) {
83
+ return;
84
+ }
85
+ $auth->login($username, $password, true);
86
+ }
87
+
88
+ public function wp_logout() {
89
+ $auth = BAuth::get_instance();
90
+ if ($auth->is_logged_in()){
91
+ $auth->logout();
92
+ }
93
+ }
94
+
95
+ public function sync_with_wp_profile($wp_user_id) {
96
+ global $wpdb;
97
+ $wp_user_data = get_userdata($wp_user_id);
98
+ $query = "SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE " . ' user_name=\'' . $wp_user_data->user_login . '\'';
99
+ $profile = $wpdb->get_row($query, ARRAY_A);
100
+ $profile = (array) $profile;
101
+ if (empty($profile)){
102
+ return;
103
+ }
104
+ $profile['user_name'] = $wp_user_data->user_login;
105
+ $profile['email'] = $wp_user_data->user_email;
106
+ $profile['password'] = $wp_user_data->user_pass;
107
+ $profile['first_name'] = $wp_user_data->user_firstname;
108
+ $profile['last_name'] = $wp_user_data->user_lastname;
109
+ $wpdb->update($wpdb->prefix . "swpm_members_tbl", $profile, array('member_id' => $profile['member_id']));
110
+ }
111
+
112
+ public function login() {
113
+ $auth = BAuth::get_instance();
114
+ if ($auth->is_logged_in()){
115
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/loggedin.php');
116
+ }
117
+ else {
118
+ $setting = BSettings::get_instance();
119
+ $password_reset_url = $setting->get_value('reset-page-url');
120
+ $join_url = $setting->get_value('join-us-page-url');
121
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/login.php');
122
+ }
123
+ }
124
+
125
+ public function reset() {
126
+ $succeeded = $this->notices();
127
+ if($succeeded){
128
+ return;
129
+ }
130
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/forgot_password.php');
131
+ }
132
+ public function profile_form() {
133
+ $auth = BAuth::get_instance();
134
+ $this->notices();
135
+ if ($auth->is_logged_in()) {
136
+ $user_data = (array) $auth->userData;
137
+ $user_data['membership_level_alias'] = $auth->userData->permitted->get('alias');
138
+ extract($user_data, EXTR_SKIP);
139
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/edit.php');
140
+ return;
141
+ }
142
+ echo 'You are not logged in.';
143
+ }
144
+
145
+ public function notices() {
146
+ $message = BTransfer::get_instance()->get('status');
147
+ $succeeded = false;
148
+ if (empty($message)) { return false;}
149
+ if ($message['succeeded']) {
150
+ echo "<div id='message' class='updated'>";
151
+ $succeeded = true;
152
+ } else{
153
+ echo "<div id='message' class='error'>";
154
+ }
155
+ echo $message['message'];
156
+ $extra = isset($message['extra']) ? $message['extra'] : array();
157
+ if (!empty($extra)) {
158
+ echo '<ul>';
159
+ foreach ($extra as $key => $value){
160
+ echo '<li>' . $value . '</li>';
161
+ }
162
+ echo '</ul>';
163
+ }
164
+ echo "</div>";
165
+ return $succeeded;
166
+ }
167
+
168
+ public function meta_box() {
169
+ if (function_exists('add_meta_box')) {
170
+ $post_types = get_post_types();
171
+ foreach ($post_types as $post_type => $post_type){
172
+ add_meta_box('swpm_sectionid',
173
+ __('Simple WP Membership Protection', 'swpm_textdomain'),
174
+ array(&$this, 'inner_custom_box'), $post_type, 'advanced');
175
+ }
176
+ } else {//older version doesn't have custom post type so modification isn't needed.
177
+ add_action('dbx_post_advanced', array(&$this, 'show_old_custom_box'));
178
+ add_action('dbx_page_advanced', array(&$this, 'show_old_custom_box'));
179
+ }
180
+ }
181
+
182
+ public function show_old_custom_box() {
183
+ echo '<div class="dbx-b-ox-wrapper">' . "\n";
184
+ echo '<fieldset id="eMember_fieldsetid" class="dbx-box">' . "\n";
185
+ echo '<div class="dbx-h-andle-wrapper"><h3 class="dbx-handle">' .
186
+ __('Simple Membership Protection options', 'swpm_textdomain') . "</h3></div>";
187
+ echo '<div class="dbx-c-ontent-wrapper"><div class="dbx-content">';
188
+ // output editing form
189
+ $this->inner_custom_box();
190
+ // end wrapper
191
+ echo "</div></div></fieldset></div>\n";
192
+ }
193
+
194
+ public function inner_custom_box() {
195
+ global $post, $wpdb;
196
+ $id = $post->ID;
197
+ // Use nonce for verification
198
+ $is_protected = BProtection::get_instance()->is_protected($id);
199
+ echo '<input type="hidden" name="swpm_noncename" id="swpm_noncename" value="' .
200
+ wp_create_nonce(plugin_basename(__FILE__)) . '" />';
201
+ // The actual fields for data entry
202
+ echo '<h4>' . __("Do you want to protect this content?", 'eMember_textdomain') . '</h4>';
203
+ echo '<input type="radio" ' . ((!$is_protected) ? 'checked' : "") .
204
+ ' name="swpm_protect_post" value="1" /> No, Do not protect this content. <br/>';
205
+ echo '<input type="radio" ' . (($is_protected) ? 'checked' : "") .
206
+ ' name="swpm_protect_post" value="2" /> Yes, Protect this content.<br/>';
207
+ echo '<h4>' . __("Select the membership level that can access this content:", 'eMember_textdomain') . "</h4>";
208
+ $query = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
209
+ $levels = $wpdb->get_results($query, ARRAY_A);
210
+ foreach ($levels as $level) {
211
+ echo '<input type="checkbox" ' . (BPermission::get_instance($level['id'])->is_permitted($id) ? "checked='checked'" : "") .
212
+ ' name="swpm_protection_level[' . $level['id'] . ']" value="' . $level['id'] . '" /> ' . $level['alias'] . "<br/>";
213
+ }
214
+ }
215
+
216
+ public function save_postdata($post_id) {
217
+ global $wpdb;
218
+ $post_type = filter_input(INPUT_POST,'post_type');
219
+ $swpm_protect_post = filter_input(INPUT_POST,'swpm_protect_post');
220
+ $swpm_noncename = filter_input(INPUT_POST, 'swpm_noncename');
221
+ if (wp_is_post_revision($post_id)){
222
+ return;
223
+ }
224
+ if (!wp_verify_nonce($swpm_noncename, plugin_basename(__FILE__))){
225
+ return $post_id;
226
+ }
227
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
228
+ return $post_id;
229
+ }
230
+ if ('page' == $post_type ) {
231
+ if (!current_user_can('edit_page', $post_id)){
232
+ return $post_id;
233
+ }
234
+ } else {
235
+ if (!current_user_can('edit_post', $post_id)){
236
+ return $post_id;
237
+ }
238
+ }
239
+ if (empty($swpm_protect_post)){
240
+ return;
241
+ }
242
+ // OK, we're authenticated: we need to find and save the data
243
+ $isprotected = ($swpm_protect_post == 2);
244
+ $args = array('swpm_protection_level'=>array(
245
+ 'filter' => FILTER_VALIDATE_INT,
246
+ 'flags' => FILTER_REQUIRE_ARRAY,
247
+ ));
248
+ $swpm_protection_level = filter_input_array(INPUT_POST, $args);
249
+ $swpm_protection_level = $swpm_protection_level['swpm_protection_level'];
250
+ if (!empty($post_type)) {
251
+ if($isprotected){
252
+ BProtection::get_instance()->apply(array($post_id),$post_type);
253
+ }
254
+ else{
255
+ BProtection::get_instance()->remove(array($post_id),$post_type);
256
+ }
257
+ BProtection::get_instance()->save();
258
+ $query = "SELECT id FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
259
+ $level_ids = $wpdb->get_col($query);
260
+ foreach ($level_ids as $level){
261
+ if(isset($swpm_protection_level[$level])){
262
+ BPermission::get_instance($level)->apply(array($post_id), $post_type)->save();
263
+ }
264
+ else{
265
+ BPermission::get_instance($level)->remove(array($post_id), $post_type)->save();
266
+ }
267
+ }
268
+ }
269
+ $enable_protection = array();
270
+ $enable_protection['protect'] = $swpm_protect_post;
271
+ $enable_protection['level'] = $swpm_protection_level;
272
+ return $enable_protection;
273
+ }
274
+
275
+ public function filter_comment($content) {
276
+ $acl = BAccessControl::get_instance();
277
+ global $comment;
278
+ return $acl->filter_comment($comment->comment_ID, $content);
279
+ }
280
+
281
+ public function filter_content($content) {
282
+ $acl = BAccessControl::get_instance();
283
+ global $post;
284
+ return $acl->filter_post($post->ID, $content);
285
+ }
286
+
287
+ public function filter_moretag($more_link, $more_link_text = "More") {
288
+ $acl = BAccessControl::get_instance();
289
+ //return $acl->filter_post_with_moretag($post->post_ID, $);
290
+ }
291
+
292
+ public function admin_init() {
293
+ $createswpmuser = filter_input(INPUT_POST, 'createswpmuser');
294
+ if (!empty($createswpmuser)) {
295
+ BAdminRegistration::get_instance()->register();
296
+ }
297
+ $editswpmuser = filter_input(INPUT_POST, 'editswpmuser');
298
+ if (!empty($editswpmuser)) {
299
+ $id = filter_input(INPUT_GET, 'member_id', FILTER_VALIDATE_INT);
300
+ BAdminRegistration::get_instance()->edit($id);
301
+ }
302
+ $createswpmlevel = filter_input(INPUT_POST, 'createswpmlevel');
303
+ if (!empty($createswpmlevel)) {
304
+ BMembershipLevel::get_instance()->create();
305
+ }
306
+ $editswpmlevel = filter_input(INPUT_POST, 'editswpmlevel');
307
+ if (!empty($editswpmlevel)) {
308
+ $id = filter_input(INPUT_GET, 'id');
309
+ BMembershipLevel::get_instance()->edit($id);
310
+ }
311
+ }
312
+
313
+ public function init() {
314
+ if (!isset($_COOKIE['swpm_session'])) { // give a unique ID to current session.
315
+ $uid = md5(microtime());
316
+ $_COOKIE['swpm_session'] = $uid; // fake it for current session/
317
+ setcookie('swpm_session', $uid, 0, '/');
318
+ }
319
+
320
+ if(current_user_can('manage_options')){ // admin stuff
321
+ $this->admin_init();
322
+ }
323
+ if (!is_admin()){ //frontend stuff
324
+ BAuth::get_instance();
325
+ $swpm_logout = filter_input(INPUT_GET, 'swpm-logout');
326
+ if (!empty($swpm_logout)) {
327
+ BAuth::get_instance()->logout();
328
+ wp_redirect(site_url());
329
+ }
330
+ $widget_options = array('classname' => 'swpm_widget',
331
+ 'description' => __("Display SWPM Login."));
332
+ wp_register_sidebar_widget('swpm_login_widget',
333
+ __('SWPM Login'), 'SimpleWpMembership::login_widget',
334
+ $widget_options);
335
+ $this->process_password_reset();
336
+ $this->register_member();
337
+ $this->edit_profile();
338
+ }
339
+ $this->swpm_ipn_listener();
340
+ }
341
+
342
+ public function swpm_ipn_listener() {
343
+ $swpm_process_ipn = filter_input(INPUT_GET, 'swpm_process_ipn');
344
+ if ($swpm_process_ipn == '1') {
345
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH.'ipn/swpm_handle_pp_ipn.php');
346
+ exit;
347
+ }
348
+ }
349
+
350
+ public function process_password_reset() {
351
+ $message = "";
352
+ $swpm_reset = filter_input(INPUT_POST, 'swpm-reset');
353
+ $swpm_reset_email = filter_input(INPUT_POST, 'swpm_reset_email', FILTER_UNSAFE_RAW);
354
+ if (!empty($swpm_reset)) {
355
+ BFrontRegistration::get_instance()->reset_password($swpm_reset_email);
356
+ }
357
+ }
358
+
359
+ public static function login_widget($args) {
360
+ extract($args);
361
+ $auth = BAuth::get_instance();
362
+ $widget_title = "User Login";
363
+ echo $before_widget;
364
+ echo $before_title . $widget_title . $after_title;
365
+ if ($auth->is_logged_in()){
366
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/login_widget_logged.php');
367
+ }
368
+ else{
369
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/login_widget.php');
370
+ }
371
+ echo $after_widget;
372
+ }
373
+
374
+ private function edit_profile() {
375
+ $swpm_editprofile_submit = filter_input(INPUT_POST, 'swpm_editprofile_submit');
376
+ if (!empty($swpm_editprofile_submit)) {
377
+ BFrontRegistration::get_instance()->edit();
378
+ //todo: do a redirect
379
+ }
380
+ }
381
+
382
+ public function admin_library() {
383
+ $this->common_library();
384
+ wp_enqueue_script('password-strength-meter');
385
+ wp_enqueue_script('swpm.password-meter', SIMPLE_WP_MEMBERSHIP_URL . '/js/swpm.password-meter.js');
386
+ }
387
+
388
+ public function front_library() {
389
+ $this->common_library();
390
+ }
391
+
392
+ private function common_library() {
393
+ wp_enqueue_script('jquery');
394
+ wp_enqueue_style('swpm.common', SIMPLE_WP_MEMBERSHIP_URL . '/css/swpm.common.css');
395
+ wp_enqueue_style('validationEngine.jquery', SIMPLE_WP_MEMBERSHIP_URL . '/css/validationEngine.jquery.css');
396
+ wp_enqueue_style('jquery.tools.dateinput', SIMPLE_WP_MEMBERSHIP_URL . '/css/jquery.tools.dateinput.css');
397
+ wp_enqueue_script('jquery.tools', SIMPLE_WP_MEMBERSHIP_URL . '/js/jquery.tools18.min.js');
398
+ wp_enqueue_script('jquery.validationEngine-en', SIMPLE_WP_MEMBERSHIP_URL . '/js/jquery.validationEngine-en.js');
399
+ wp_enqueue_script('jquery.validationEngine', SIMPLE_WP_MEMBERSHIP_URL . '/js/jquery.validationEngine.js');
400
+ }
401
+
402
+ public function registration_form() {
403
+ $succeeded = $this->notices();
404
+ if($succeeded){
405
+ return;
406
+ }
407
+ BFrontRegistration::get_instance()->regigstration_ui();
408
+ }
409
+
410
+ private function register_member() {
411
+ $registration = filter_input(INPUT_POST, 'swpm_registration_submit');
412
+ if (!empty($registration)) {
413
+ BFrontRegistration::get_instance()->register();
414
+ }
415
+ }
416
+
417
+ public function menu() {
418
+ add_menu_page(__("WP Membership", 'swpm'), __("WP Membership", 'swpm')
419
+ , 'manage_options', 'simple_wp_membership', array(&$this, "admin_members")
420
+ , SIMPLE_WP_MEMBERSHIP_URL . '/images/logo.png');
421
+ add_submenu_page('simple_wp_membership', __("Members", 'swpm'), __('Members', 'swpm'),
422
+ 'activate_plugins', 'simple_wp_membership', array(&$this, "admin_members"));
423
+ add_submenu_page('simple_wp_membership', __("Membership Levels", 'swpm'), __("Membership Levels", 'swpm'),
424
+ 'activate_plugins', 'simple_wp_membership_levels', array(&$this, "admin_membership_levels"));
425
+ add_submenu_page('simple_wp_membership', __("Settings", 'swpm'), __("Settings", 'swpm'),
426
+ 'activate_plugins', 'simple_wp_membership_settings', array(&$this, "admin_settings"));
427
+ $this->meta_box();
428
+ }
429
+
430
+ public function admin_membership_levels() {
431
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'classes/class.bMembershipLevels.php');
432
+ $levels = new BMembershipLevels();
433
+ $level_action = filter_input(INPUT_GET, 'level_action');
434
+ $action2 = filter_input(INPUT_GET, 'action2');
435
+ $action = $level_action ? : ($action2 ? : "");
436
+ switch ($action) {
437
+ case 'add':
438
+ case 'edit':
439
+ $levels->process_form_request();
440
+ break;
441
+ case 'manage':
442
+ $levels->manage();
443
+ break;
444
+ case 'delete':
445
+ case 'bulk_delete':
446
+ $levels->delete();
447
+ default:
448
+ $levels->show();
449
+ break;
450
+ }
451
+ }
452
+
453
+ public function admin_members() {
454
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'classes/class.bMembers.php');
455
+ $members = new BMembers();
456
+ $action = filter_input(INPUT_GET, 'member_action');
457
+ switch ($action) {
458
+ case 'add':
459
+ case 'edit':
460
+ $members->process_form_request();
461
+ break;
462
+ case 'delete':
463
+ case 'bulk_delete':
464
+ $members->delete();
465
+ default:
466
+ $members->show();
467
+ break;
468
+ }
469
+ }
470
+
471
+ public function admin_settings() {
472
+ $current_tab = BSettings::get_instance()->current_tab;
473
+ switch ($current_tab) {
474
+ case 4:
475
+ $link_for = filter_input(INPUT_POST, 'swpm_link_for',FILTER_SANITIZE_STRING);
476
+ $member_id = filter_input(INPUT_POST, 'member_id',FILTER_SANITIZE_NUMBER_INT);
477
+ $send_email = filter_input(INPUT_POST, 'swpm_reminder_email',FILTER_SANITIZE_NUMBER_INT);
478
+ $links = BUtils::get_registration_link($link_for, $send_email, $member_id);
479
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_tools_settings.php');
480
+ break;
481
+ case 2:
482
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_payment_settings.php');
483
+ break;
484
+ default:
485
+ include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_settings.php');
486
+ break;
487
+ }
488
+ }
489
+
490
+ public static function activate() {
491
+ include_once('class.bInstallation.php');
492
+ global $wpdb;
493
+ if (BUtils::is_multisite_install()) {
494
+ BInstallation::do_multisite();
495
+ }
496
+ BInstallation::installer();
497
+ BInstallation::initdb();
498
+ }
499
+ public function deactivate() {
500
+
501
+ }
502
+ }
css/jquery.tools.dateinput.css ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* get rid of those system borders being generated for A tags */
2
+ a:active {
3
+ outline:none;
4
+ }
5
+
6
+ :focus {
7
+ -moz-outline-style:none;
8
+ }
9
+ /* For the details, see: http://flowplayer.org/tools/dateinput/index.html#skinning */
10
+
11
+ /* the input field */
12
+ .date {
13
+ border:1px solid #ccc;
14
+ font-size:13px;
15
+ padding:4px;
16
+ text-align:center;
17
+ width:178px;
18
+
19
+ -moz-box-shadow:0 0 10px #eee inset;
20
+ -webkit-box-shadow:0 0 10px #eee inset;
21
+ }
22
+
23
+ /* calendar root element */
24
+ #calroot {
25
+ /* place on top of other elements. set a higher value if nessessary */
26
+ z-index:10000;
27
+
28
+ margin-top:-1px;
29
+ width:198px;
30
+ padding:2px;
31
+ background-color:#fff;
32
+ font-size:11px;
33
+ border:1px solid #ccc;
34
+
35
+ -moz-border-radius:5px;
36
+ -webkit-border-radius:5px;
37
+
38
+ -moz-box-shadow: 0 0 15px #666;
39
+ -webkit-box-shadow: 0 0 15px #666;
40
+ }
41
+
42
+ /* head. contains title, prev/next month controls and possible month/year selectors */
43
+ #calhead {
44
+ padding:2px 0;
45
+ height:22px;
46
+ }
47
+
48
+ #caltitle {
49
+ font-size:14px;
50
+ color:#0150D1;
51
+ float:left;
52
+ text-align:center;
53
+ width:155px;
54
+ line-height:20px;
55
+ text-shadow:0 1px 0 #ddd;
56
+ }
57
+
58
+ #calnext, #calprev {
59
+ display:block;
60
+ width:20px;
61
+ height:20px;
62
+ background:transparent url(../images/prev.gif) no-repeat scroll center center;
63
+ float:left;
64
+ cursor:pointer;
65
+ }
66
+
67
+ #calnext {
68
+ background-image:url(../images/next.gif);
69
+ float:right;
70
+ }
71
+
72
+ #calprev.caldisabled, #calnext.caldisabled {
73
+ visibility:hidden;
74
+ }
75
+
76
+ /* year/month selector */
77
+ #caltitle select {
78
+ font-size:10px;
79
+ }
80
+
81
+ /* names of the days */
82
+ #caldays {
83
+ height:14px;
84
+ border-bottom:1px solid #ddd;
85
+ }
86
+
87
+ #caldays span {
88
+ display:block;
89
+ float:left;
90
+ width:28px;
91
+ text-align:center;
92
+ }
93
+
94
+ /* container for weeks */
95
+ #calweeks {
96
+ background-color:#fff;
97
+ margin-top:4px;
98
+ }
99
+
100
+ /* single week */
101
+ .calweek {
102
+ clear:left;
103
+ height:22px;
104
+ }
105
+
106
+ /* single day */
107
+ .calweek a {
108
+ display:block;
109
+ float:left;
110
+ width:27px;
111
+ height:20px;
112
+ text-decoration:none;
113
+ font-size:11px;
114
+ margin-left:1px;
115
+ text-align:center;
116
+ line-height:20px;
117
+ color:#666;
118
+ -moz-border-radius:3px;
119
+ -webkit-border-radius:3px;
120
+ }
121
+
122
+ /* different states */
123
+ .calweek a:hover, .calfocus {
124
+ background-color:#ddd;
125
+ }
126
+
127
+ /* sunday */
128
+ a.calsun {
129
+ color:red;
130
+ }
131
+
132
+ /* offmonth day */
133
+ a.caloff {
134
+ color:#ccc;
135
+ }
136
+
137
+ a.caloff:hover {
138
+ background-color:rgb(245, 245, 250);
139
+ }
140
+
141
+
142
+ /* unselecteble day */
143
+ a.caldisabled {
144
+ background-color:#efefef !important;
145
+ color:#ccc !important;
146
+ cursor:default;
147
+ }
148
+
149
+ /* current day */
150
+ #calcurrent {
151
+ background-color:#498CE2;
152
+ color:#fff;
153
+ }
154
+
155
+ /* today */
156
+ #caltoday {
157
+ background-color:#333;
158
+ color:#fff;
159
+ }
css/swpm.common.css ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Login form CSS */
2
+ .swpm-login-widget-form input,.swpm-login-widget-form checkbox{
3
+ width: auto;
4
+ }
5
+ .swpm-login-widget-form table{
6
+ border: none;
7
+ }
8
+ .swpm-login-widget-form tr{
9
+ border: none;
10
+ }
11
+ .swpm-login-widget-form td{
12
+ border: none;
13
+ }
14
+
15
+ /* Password reset form CSS */
16
+ .swpm-password-reset-widget-form table{
17
+ border: none;
18
+ }
19
+ swpm-password-reset-widget-form tr{
20
+ border: none;
21
+ }
22
+ .swpm-password-reset-widget-form td{
23
+ border: none;
24
+ }
25
+
26
+ /* Registration form CSS */
27
+ .swpm-registration-widget-form td{
28
+ min-width: 100px;
29
+ }
css/validationEngine.jquery.css ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .inputContainer {
2
+ position: relative;
3
+ float: left;
4
+ }
5
+
6
+ .formError {
7
+ position: absolute;
8
+ top: 300px;
9
+ left: 300px;
10
+ display: block;
11
+ z-index: 5000;
12
+ cursor: pointer;
13
+ }
14
+
15
+ .ajaxSubmit {
16
+ padding: 20px;
17
+ background: #55ea55;
18
+ border: 1px solid #999;
19
+ display: none
20
+ }
21
+
22
+ .formError .formErrorContent {
23
+ width: 100%;
24
+ background: #ee0101;
25
+ position:relative;
26
+ z-index:5001;
27
+ color: #fff;
28
+ font-weight: bolder;
29
+ width: 150px;
30
+ font-family: tahoma;
31
+ font-size: 11px;
32
+ border: 2px solid #ddd;
33
+ box-shadow: 0 0 6px #000;
34
+ -moz-box-shadow: 0 0 6px #000;
35
+ -webkit-box-shadow: 0 0 6px #000;
36
+ padding: 4px 10px 4px 10px;
37
+ border-radius: 6px;
38
+ -moz-border-radius: 6px;
39
+ -webkit-border-radius: 6px;
40
+ }
41
+
42
+ .greenPopup .formErrorContent {
43
+ background: #33be40;
44
+ }
45
+
46
+ .blackPopup .formErrorContent {
47
+ background: #393939;
48
+ color: #FFF;
49
+ }
50
+
51
+ .formError .formErrorArrow {
52
+ width: 15px;
53
+ margin: -2px 0 0 13px;
54
+ position:relative;
55
+ z-index: 5006;
56
+ }
57
+
58
+ .formError .formErrorArrowBottom {
59
+ box-shadow: none;
60
+ -moz-box-shadow: none;
61
+ -webkit-box-shadow: none;
62
+ margin: 0px 0 0 12px;
63
+ top:2px;
64
+ }
65
+
66
+ .formError .formErrorArrow div {
67
+ border-left: 2px solid #ddd;
68
+ border-right: 2px solid #ddd;
69
+ box-shadow: 0 2px 3px #444;
70
+ -moz-box-shadow: 0 2px 3px #444;
71
+ -webkit-box-shadow: 0 2px 3px #444;
72
+ font-size: 0px;
73
+ height: 1px;
74
+ background: #ee0101;
75
+ margin: 0 auto;
76
+ line-height: 0;
77
+ font-size: 0;
78
+ display: block;
79
+ }
80
+
81
+ .formError .formErrorArrowBottom div {
82
+ box-shadow: none;
83
+ -moz-box-shadow: none;
84
+ -webkit-box-shadow: none;
85
+ }
86
+
87
+ .greenPopup .formErrorArrow div {
88
+ background: #33be40;
89
+ }
90
+
91
+ .blackPopup .formErrorArrow div {
92
+ background: #393939;
93
+ color: #FFF;
94
+ }
95
+
96
+ .formError .formErrorArrow .line10 {
97
+ width: 15px;
98
+ border: none;
99
+ }
100
+
101
+ .formError .formErrorArrow .line9 {
102
+ width: 13px;
103
+ border: none;
104
+ }
105
+
106
+ .formError .formErrorArrow .line8 {
107
+ width: 11px;
108
+ }
109
+
110
+ .formError .formErrorArrow .line7 {
111
+ width: 9px;
112
+ }
113
+
114
+ .formError .formErrorArrow .line6 {
115
+ width: 7px;
116
+ }
117
+
118
+ .formError .formErrorArrow .line5 {
119
+ width: 5px;
120
+ }
121
+
122
+ .formError .formErrorArrow .line4 {
123
+ width: 3px;
124
+ }
125
+
126
+ .formError .formErrorArrow .line3 {
127
+ width: 1px;
128
+ border-left: 2px solid #ddd;
129
+ border-right: 2px solid #ddd;
130
+ border-bottom: 0 solid #ddd;
131
+ }
132
+
133
+ .formError .formErrorArrow .line2 {
134
+ width: 3px;
135
+ border: none;
136
+ background: #ddd;
137
+ }
138
+
139
+ .formError .formErrorArrow .line1 {
140
+ width: 1px;
141
+ border: none;
142
+ background: #ddd;
143
+ }
images/join-now-button-image.gif ADDED
Binary file
images/logo.png ADDED
Binary file
images/logo2.png ADDED
Binary file
images/next.gif ADDED
Binary file
images/prev.gif ADDED
Binary file
images/simple-membership-content-protection-usage.png ADDED
Binary file
ipn/swpm_handle_pp_ipn.php ADDED
@@ -0,0 +1,328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ include_once('swpm_handle_subsc_ipn.php');
4
+
5
+ class swpm_paypal_ipn_handler {
6
+
7
+ var $last_error; // holds the last error encountered
8
+ var $ipn_log = false; // bool: log IPN results to text file?
9
+ var $ipn_log_file; // filename of the IPN log
10
+ var $ipn_response; // holds the IPN response from paypal
11
+ var $ipn_data = array(); // array contains the POST values for IPN
12
+ var $fields = array(); // array holds the fields to submit to paypal
13
+ var $sandbox_mode = false;
14
+
15
+ function swpm_paypal_ipn_handler()
16
+ {
17
+ $this->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
18
+ $this->last_error = '';
19
+ $this->ipn_log_file = 'ipn_handle_debug_swpm.log';
20
+ $this->ipn_response = '';
21
+ }
22
+
23
+ function swpm_validate_and_create_membership()
24
+ {
25
+ // Check Product Name , Price , Currency , Receivers email ,
26
+ $error_msg = "";
27
+
28
+ // Read the IPN and validate
29
+ $payment_status = $this->ipn_data['payment_status'];
30
+ if (!empty($payment_status))
31
+ {
32
+ if ($payment_status != "Completed" && $payment_status != "Processed" && $payment_status != "Refunded")
33
+ {
34
+ $error_msg .= 'Funds have not been cleared yet. Product(s) will be delivered when the funds clear!';
35
+ $this->debug_log($error_msg,false);
36
+ return false;
37
+ }
38
+ }
39
+
40
+ $custom = $this->ipn_data['custom'];
41
+ $delimiter = "&";
42
+ $customvariables = array();
43
+
44
+ $namevaluecombos = explode($delimiter, $custom);
45
+ foreach ($namevaluecombos as $keyval_unparsed)
46
+ {
47
+ $equalsignposition = strpos($keyval_unparsed, '=');
48
+ if ($equalsignposition === false)
49
+ {
50
+ $customvariables[$keyval_unparsed] = '';
51
+ continue;
52
+ }
53
+ $key = substr($keyval_unparsed, 0, $equalsignposition);
54
+ $value = substr($keyval_unparsed, $equalsignposition + 1);
55
+ $customvariables[$key] = $value;
56
+ }
57
+
58
+ $transaction_type = $this->ipn_data['txn_type'];
59
+ $txn_id = $this->ipn_data['txn_id'];
60
+ $gross_total = $this->ipn_data['mc_gross'];
61
+ if ($gross_total < 0)
62
+ {
63
+ // This is a refund or reversal
64
+ swpm_handle_subsc_cancel_stand_alone($this->ipn_data,true);
65
+ $this->debug_log('This is a refund notification. Refund amount: '.$gross_total,true);
66
+ return true;
67
+ }
68
+
69
+ if (($transaction_type == "subscr_signup"))
70
+ {
71
+ $this->debug_log('Subscription signup IPN received... nothing to do here(handled by the subscription IPN handler)',true);
72
+ // Code to handle the signup IPN for subscription
73
+ $subsc_ref = $customvariables['subsc_ref'];
74
+
75
+ if (!empty($subsc_ref))
76
+ {
77
+ $this->debug_log('swpm integration is being used... creating member account... see the "subscription_handle_debug.log" file for details',true);
78
+ $swpm_id = $customvariables['swpm_id'];
79
+ swpm_handle_subsc_signup_stand_alone($this->ipn_data,$subsc_ref,$this->ipn_data['subscr_id'],$swpm_id);
80
+ //Handle customized subscription signup
81
+ }
82
+ return true;
83
+ }
84
+ else if (($transaction_type == "subscr_cancel") || ($transaction_type == "subscr_eot") || ($transaction_type == "subscr_failed"))
85
+ {
86
+ // Code to handle the IPN for subscription cancellation
87
+ swpm_handle_subsc_cancel_stand_alone($this->ipn_data);
88
+ $this->debug_log('Subscription cancellation IPN received... nothing to do here(handled by the subscription IPN handler)',true);
89
+ return true;
90
+ }
91
+ else
92
+ {
93
+ $cart_items = array();
94
+ $this->debug_log('Transaction Type: Buy Now/Subscribe',true);
95
+ $item_number = $this->ipn_data['item_number'];
96
+ $item_name = $this->ipn_data['item_name'];
97
+ $quantity = $this->ipn_data['quantity'];
98
+ $mc_gross = $this->ipn_data['mc_gross'];
99
+ $mc_currency = $this->ipn_data['mc_currency'];
100
+
101
+ $current_item = array(
102
+ 'item_number' => $item_number,
103
+ 'item_name' => $item_name,
104
+ 'quantity' => $quantity,
105
+ 'mc_gross' => $mc_gross,
106
+ 'mc_currency' => $mc_currency,
107
+ );
108
+
109
+ array_push($cart_items, $current_item);
110
+ }
111
+
112
+ $product_id_array = Array();
113
+ $product_name_array = Array();
114
+ $product_price_array = Array();
115
+ $attachments_array = Array();
116
+ $download_link_array = Array();
117
+ $counter = 0;
118
+ foreach ($cart_items as $current_cart_item)
119
+ {
120
+ $cart_item_data_num = $current_cart_item['item_number'];
121
+ $cart_item_data_name = trim($current_cart_item['item_name']);
122
+ $cart_item_data_quantity = $current_cart_item['quantity'];
123
+ $cart_item_data_total = $current_cart_item['mc_gross'];
124
+ $cart_item_data_currency = $current_cart_item['mc_currency'];
125
+ if(empty($cart_item_data_quantity))
126
+ {
127
+ $cart_item_data_quantity = 1;
128
+ }
129
+ $this->debug_log('Item Number: '.$cart_item_data_num,true);
130
+ $this->debug_log('Item Name: '.$cart_item_data_name,true);
131
+ $this->debug_log('Item Quantity: '.$cart_item_data_quantity,true);
132
+ $this->debug_log('Item Total: '.$cart_item_data_total,true);
133
+ $this->debug_log('Item Currency: '.$cart_item_data_currency,true);
134
+
135
+
136
+ //*** Handle Membership Payment ***
137
+ //--------------------------------------------------------------------------------------
138
+ // ========= Need to find the (level ID) in the custom variable ============
139
+ $subsc_ref = $customvariables['subsc_ref'];//Membership level ID
140
+ $this->debug_log('Membership payment paid for membership level ID: '.$subsc_ref,true);
141
+ if (!empty($subsc_ref))
142
+ {
143
+ $swpm_id = "";
144
+ if(isset($customvariables['swpm_id'])){
145
+ $swpm_id = $customvariables['swpm_id'];
146
+ }
147
+ if ($transaction_type == "web_accept")
148
+ {
149
+ $this->debug_log('swpm integration is being used... creating member account... see the "subscription_handle_debug.log" file for details',true);
150
+ swpm_handle_subsc_signup_stand_alone($this->ipn_data,$subsc_ref,$this->ipn_data['txn_id'],$swpm_id);
151
+ }
152
+ else if($transaction_type == "subscr_payment"){
153
+ //swpm_update_member_subscription_start_date_if_applicable($this->ipn_data);
154
+ }
155
+ }
156
+ else
157
+ {
158
+ $this->debug_log('Membership level ID is missing in the payment notification! Cannot process this notification',false);
159
+ }
160
+ //== End of Membership payment handling ==
161
+ $counter++;
162
+ }
163
+
164
+ // Do Post payment operation and cleanup
165
+ if (function_exists('wp_aff_platform_install'))
166
+ {
167
+ $this->debug_log('WP Affiliate Platform is installed, checking if custom field has affiliate data...',true);
168
+ //It expects the value of the custom field to be like the following:
169
+ //<input type="hidden" name="custom" value="subsc_ref=4&ap_id=AFF_ID" />
170
+
171
+ $custom_field_val = $this->ipn_data['custom'];
172
+ $this->debug_log('Custom field value: '.$custom_field_val,true);
173
+ $findme = 'ap_id';
174
+ $pos = strpos($custom_field_val, $findme);
175
+ if($pos !== false){
176
+ parse_str($custom_field_val);
177
+ $referrer = $ap_id;
178
+ }else{
179
+ $this->debug_log('Could not find affiliate ID (ap_id) data in the custom field',true);
180
+ }
181
+
182
+ if(!empty($referrer))
183
+ {
184
+ $total_tax = $this->ipn_data['tax'];
185
+ if(empty($total_tax)){$total_tax = 0;}
186
+ $total_shipping = 0;
187
+ if(!empty($this->ipn_data['shipping'])){
188
+ $total_shipping = $this->ipn_data['shipping'];
189
+ }else if (!empty($this->ipn_data['mc_shipping'])){
190
+ $total_shipping = $this->ipn_data['mc_shipping'];
191
+ }
192
+ $gross_sale_amt = $this->ipn_data['mc_gross'];
193
+ $this->debug_log('Gross sale amount: '.$gross_sale_amt.' Tax: '.$total_tax.' Shipping: '.$total_shipping,true);
194
+ $sale_amount = $gross_sale_amt - $total_shipping - $total_tax;
195
+
196
+ $txn_id = $this->ipn_data['txn_id'];
197
+ $item_id = $this->ipn_data['item_number'];
198
+ $buyer_email = $this->ipn_data['payer_email'];
199
+ $buyer_name = $this->ipn_data['first_name'] . " " .$this->ipn_data['last_name'];
200
+ wp_aff_award_commission_unique($referrer,$sale_amount,$txn_id,$item_id,$buyer_email,'','',$buyer_name);
201
+ $aff_details_debug = "Referrer: ".$referrer." Sale Amt: ".$sale_amount." Buyer Email: ".$buyer_email." Txn ID: ".$txn_id;
202
+ $this->debug_log('Affiliate Commission Details => '.$aff_details_debug,true);
203
+ }
204
+ else
205
+ {
206
+ $this->debug_log("Referrer value is empty! No commission will be awarded for this sale",true);
207
+ }
208
+
209
+ do_action('swpm_paypal_ipn_processed', $this->ipn_data);
210
+ }
211
+ return true;
212
+ }
213
+
214
+ function swpm_validate_ipn()
215
+ {
216
+ // parse the paypal URL
217
+ $url_parsed=parse_url($this->paypal_url);
218
+
219
+ // generate the post string from the _POST vars aswell as load the _POST vars into an arry
220
+ $post_string = '';
221
+ foreach ($_POST as $field=>$value) {
222
+ $this->ipn_data["$field"] = $value;
223
+ $post_string .= $field.'='.urlencode(stripslashes($value)).'&';
224
+ }
225
+
226
+ $this->post_string = $post_string;
227
+ $this->debug_log('Post string : '. $this->post_string,true);
228
+
229
+ $post_string.="cmd=_notify-validate"; // append ipn command
230
+
231
+ // open the connection to paypal
232
+ if($this->sandbox_mode){//connect to PayPal sandbox
233
+ $uri = 'ssl://'.$url_parsed['host'];
234
+ $port = '443';
235
+ $fp = fsockopen($uri,$port,$err_num,$err_str,30);
236
+ }
237
+ else{//connect to live PayPal site using standard approach
238
+ $fp = fsockopen($url_parsed['host'],"80",$err_num,$err_str,30);
239
+ }
240
+
241
+ if(!$fp)
242
+ {
243
+ // could not open the connection. If loggin is on, the error message
244
+ // will be in the log.
245
+ $this->debug_log('Connection to '.$url_parsed['host']." failed.fsockopen error no. $errnum: $errstr",false);
246
+ return false;
247
+
248
+ }
249
+ else
250
+ {
251
+ // Post the data back to paypal
252
+ fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n");
253
+ fputs($fp, "Host: $url_parsed[host]\r\n");
254
+ fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
255
+ fputs($fp, "Content-length: ".strlen($post_string)."\r\n");
256
+ fputs($fp, "Connection: close\r\n\r\n");
257
+ fputs($fp, $post_string . "\r\n\r\n");
258
+
259
+ // loop through the response from the server and append to variable
260
+ while(!feof($fp)) {
261
+ $this->ipn_response .= fgets($fp, 1024);
262
+ }
263
+
264
+ fclose($fp); // close connection
265
+
266
+ $this->debug_log('Connection to '.$url_parsed['host'].' successfuly completed.',true);
267
+ }
268
+
269
+ //if (eregi("VERIFIED",$this->ipn_response))
270
+ if (strpos($this->ipn_response, "VERIFIED") !== false)
271
+ {
272
+ // Valid IPN transaction.
273
+ $this->debug_log('IPN successfully verified.',true);
274
+ return true;
275
+
276
+ }
277
+ else
278
+ {
279
+ // Invalid IPN transaction. Check the log for details.
280
+ $this->debug_log('IPN validation failed.',false);
281
+ return false;
282
+ }
283
+ }
284
+
285
+ function debug_log($message,$success,$end=false)
286
+ {
287
+ BLog::log_simple_debug($message, $success, $end);
288
+ }
289
+ }
290
+
291
+ // Start of IPN handling (script execution)
292
+
293
+ $ipn_handler_instance = new swpm_paypal_ipn_handler();
294
+
295
+ $settings = BSettings::get_instance();
296
+ $debug_enabled = $settings->get_value('enable-debug');
297
+ if(!empty($debug_enabled))//debug is enabled in the system
298
+ {
299
+ $debug_log = "log.txt"; // Debug log file name
300
+ echo 'Debug logging is enabled. Check the '.$debug_log.' file for debug output.';
301
+ $ipn_handler_instance->ipn_log = true;
302
+ $ipn_handler_instance->ipn_log_file = $debug_log;
303
+ if(empty($_POST))
304
+ {
305
+ $ipn_handler_instance->debug_log('This debug line was generated because you entered the URL of the ipn handling script in the browser.',true,true);
306
+ exit;
307
+ }
308
+ }
309
+
310
+ $sandbox_enabled = $settings->get_value('enable-sandbox-testing');
311
+ if(!empty($sandbox_enabled)) // Sandbox testing enabled
312
+ {
313
+ $ipn_handler_instance->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
314
+ $ipn_handler_instance->sandbox_mode = true;
315
+ }
316
+
317
+ $ipn_handler_instance->debug_log('Paypal Class Initiated by '.$_SERVER['REMOTE_ADDR'],true);
318
+
319
+ // Validate the IPN
320
+ if ($ipn_handler_instance->swpm_validate_ipn())
321
+ {
322
+ $ipn_handler_instance->debug_log('Creating product Information to send.',true);
323
+
324
+ if(!$ipn_handler_instance->swpm_validate_and_create_membership()){
325
+ $ipn_handler_instance->debug_log('IPN product validation failed.',false);
326
+ }
327
+ }
328
+ $ipn_handler_instance->debug_log('Paypal class finished.',true,true);
ipn/swpm_handle_subsc_ipn.php ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function swpm_handle_subsc_signup_stand_alone($ipn_data,$subsc_ref,$unique_ref,$swpm_id='')
4
+ {
5
+ global $wpdb;
6
+ $settings = BSettings::get_instance();
7
+ $members_table_name = $wpdb->prefix . "swpm_members_tbl";
8
+ $membership_level_table = $wpdb->prefix . "swpm_membership_tbl";
9
+
10
+ if(empty($swpm_id))
11
+ {
12
+ //Lets try to find an existing user profile for this payment
13
+ $email = $ipn_data['payer_email'];
14
+ $query_db = $wpdb->get_row("SELECT * FROM $members_table_name WHERE email = '$email'", OBJECT);
15
+ if(!$query_db){//try to retrieve the member details based on the unique_ref
16
+ swpm_debug_log_subsc("Could not find any record using the given email address (".$email."). Attempting to query database using the unique reference: ".$unique_ref,true);
17
+ if(!empty($unique_ref)){
18
+ $query_db = $wpdb->get_row("SELECT * FROM $members_table_name WHERE subscr_id = '$unique_ref'", OBJECT);
19
+ $swpm_id = $query_db->member_id;
20
+ }
21
+ else{
22
+ swpm_debug_log_subsc("Unique reference is missing in the notification so we have to assume that this is not a payment for an existing member.",true);
23
+ }
24
+ }
25
+ else
26
+ {
27
+ $swpm_id = $query_db->member_id;
28
+ swpm_debug_log_subsc("Found a match in the member database. Member ID: ".$swpm_id,true);
29
+ }
30
+ }
31
+
32
+ if (!empty($swpm_id))
33
+ {
34
+ //This is payment from an existing member/user. Update the existing member account
35
+ swpm_debug_log_subsc("Modifying the existing membership profile... Member ID: ".$swpm_id,true);
36
+ // upgrade the member account
37
+ $account_state = 'active';
38
+ $membership_level = $subsc_ref;
39
+ $subscription_starts = (date ("Y-m-d"));
40
+ $subscr_id = $unique_ref;
41
+
42
+ $resultset = "";
43
+ $resultset = $wpdb->get_row("SELECT * FROM $members_table_name where member_id='$swpm_id'", OBJECT);
44
+ if(!$resultset){
45
+ swpm_debug_log_subsc("ERROR! Could not find a member account record for the given Member ID: ".$swpm_id,false);
46
+ return;
47
+ }
48
+ $old_membership_level = $resultset->membership_level;
49
+
50
+ swpm_debug_log_subsc("Not using secondary membership level feature... upgrading the current membership level.",true);
51
+ $updatedb = "UPDATE $members_table_name SET account_state='$account_state',membership_level='$membership_level',subscription_starts='$subscription_starts',subscr_id='$subscr_id' WHERE member_id='$swpm_id'";
52
+ $results = $wpdb->query($updatedb);
53
+ do_action('swpm_membership_changed', array('member_id'=>$swpm_id, 'from_level'=>$old_membership_level, 'to_level'=>$membership_level));
54
+
55
+ //Set Email details for the account upgrade notification
56
+ $email = $ipn_data['payer_email'];
57
+ $subject = $settings->get_value('upgrade-complete-mail-subject');
58
+ if (empty($subject)){
59
+ $subject = "Member Account Upgraded";
60
+ }
61
+ $body = $settings->get_value('upgrade-complete-mail-body');
62
+ if (empty($body)){
63
+ $body = "Your account has been upgraded successfully";
64
+ }
65
+ $from_address = get_option('admin_email');
66
+ $login_link = $settings->get_value('login-page-url');
67
+
68
+ $tags1 = array("{first_name}","{last_name}","{user_name}","{login_link}");
69
+ $vals1 = array($resultset->first_name,$resultset->last_name,$resultset->user_name,$login_link);
70
+ $email_body = str_replace($tags1,$vals1,$body);
71
+ $headers = 'From: '.$from_address . "\r\n";
72
+ }// End of existing user account upgrade
73
+ else
74
+ {
75
+ // create new member account
76
+ $user_name ='';
77
+ $password = '';
78
+
79
+ $first_name = $ipn_data['first_name'];
80
+ $last_name = $ipn_data['last_name'];
81
+ $email = $ipn_data['payer_email'];
82
+ $membership_level = $subsc_ref;
83
+ $subscr_id = $unique_ref;
84
+ $gender = 'not specified';
85
+
86
+ swpm_debug_log_subsc("Membership level ID: ".$membership_level,true);
87
+
88
+ $address_street = $ipn_data['address_street'];
89
+ $address_city = $ipn_data['address_city'];
90
+ $address_state = $ipn_data['address_state'];
91
+ $address_zipcode = $ipn_data['address_zip'];
92
+ $country = $ipn_data['address_country'];
93
+
94
+ $date = (date ("Y-m-d"));
95
+ $account_state = 'active';
96
+ $reg_code = uniqid();//rand(10, 1000);
97
+ $md5_code = md5($reg_code);
98
+
99
+ $updatedb = "INSERT INTO $members_table_name (user_name,first_name,last_name,password,member_since,membership_level,account_state,last_accessed,last_accessed_from_ip,email,address_street,address_city,address_state,address_zipcode,country,gender,referrer,extra_info,reg_code,subscription_starts,txn_id,subscr_id) VALUES ('$user_name','$first_name','$last_name','$password', '$date','$membership_level','$account_state','$date','IP','$email','$address_street','$address_city','$address_state','$address_zipcode','$country','$gender','','','$md5_code','$date','','$subscr_id')";
100
+ $results = $wpdb->query($updatedb);
101
+
102
+ $results = $wpdb->get_row("SELECT * FROM $members_table_name where subscr_id='$subscr_id' and reg_code='$md5_code'", OBJECT);
103
+ $id = $results->member_id; //Alternatively use $wpdb->insert_id;
104
+ if(empty($id)){
105
+ swpm_debug_log_subsc("Error! Failed to insert a new member record. This request will fail.",false);
106
+ return;
107
+ }
108
+
109
+ $separator='?';
110
+ $url = $settings->get_value('registration-page-url');
111
+ if(strpos($url,'?')!==false){$separator='&';}
112
+
113
+ $reg_url = $url.$separator.'member_id='.$id.'&code='.$md5_code;
114
+ swpm_debug_log_subsc("Member signup URL: ".$reg_url,true);
115
+
116
+ $subject = $settings->get_value('reg-prompt-complete-mail-subject');
117
+ if (empty($subject)){
118
+ $subject = "Please complete your registration";
119
+ }
120
+ $body = $settings->get_value('reg-prompt-complete-mail-body');
121
+ if (empty($body)){
122
+ $body = "Please use the following link to complete your registration. \n {reg_link}";
123
+ }
124
+ $from_address = $settings->get_value('email-from');
125
+
126
+ $tags = array("{first_name}","{last_name}","{reg_link}");
127
+ $vals = array($first_name,$last_name,$reg_url);
128
+ $email_body = str_replace($tags,$vals,$body);
129
+ $headers = 'From: '.$from_address . "\r\n";
130
+ }
131
+
132
+ wp_mail($email,$subject,$email_body,$headers);
133
+ swpm_debug_log_subsc("Member signup/upgrade completion email successfully sent to: ".$email,true);
134
+ }
135
+
136
+ function swpm_handle_subsc_cancel_stand_alone($ipn_data,$refund=false)
137
+ {
138
+ if($refund)
139
+ {
140
+ $subscr_id = $ipn_data['parent_txn_id'];
141
+ swpm_debug_log_subsc("Refund notification check - check if a member account needs to be deactivated... subscr ID: ".$subscr_id,true);
142
+ }
143
+ else
144
+ {
145
+ $subscr_id = $ipn_data['subscr_id'];
146
+ }
147
+
148
+ global $wpdb;
149
+ $members_table_name = $wpdb->prefix . "swpm_members_tbl";
150
+
151
+ swpm_debug_log_subsc("Retrieving member account from the database...",true);
152
+ $resultset = $wpdb->get_row("SELECT * FROM $members_table_name where subscr_id='$subscr_id'", OBJECT);
153
+ if($resultset)
154
+ {
155
+ //Deactivate this account as it is a refund or cancellation
156
+ $account_state = 'inactive';
157
+ $updatedb = "UPDATE $members_table_name SET account_state='$account_state' WHERE subscr_id='$subscr_id'";
158
+ $resultset = $wpdb->query($updatedb);
159
+ swpm_debug_log_subsc("Subscription cancellation received! Member account deactivated.",true);
160
+ }
161
+ else
162
+ {
163
+ swpm_debug_log_subsc("No member found for the given subscriber ID: ".$subscr_id,false);
164
+ return;
165
+ }
166
+ }
167
+
168
+ function swpm_update_member_subscription_start_date_if_applicable($ipn_data)
169
+ {
170
+ global $wpdb;
171
+ $members_table_name = $wpdb->prefix . "swpm_members_tbl";
172
+ $membership_level_table = $wpdb->prefix . "swpm_membership_tbl";
173
+ $email = $ipn_data['payer_email'];
174
+ $subscr_id = $ipn_data['subscr_id'];
175
+ swpm_debug_log_subsc("Updating subscription start date if applicable for this subscription payment. Subscriber ID: ".$subscr_id." Email: ".$email,true);
176
+
177
+ //We can also query using the email address
178
+ $query_db = $wpdb->get_row("SELECT * FROM $members_table_name WHERE subscr_id = '$subscr_id'", OBJECT);
179
+ if($query_db){
180
+ $swpm_id = $query_db->member_id;
181
+ $current_primary_level = $query_db->membership_level;
182
+ swpm_debug_log_subsc("Found a record in the member table. The Member ID of the account to check is: ".$swpm_id." Membership Level: ".$current_primary_level,true);
183
+
184
+ $level_query = $wpdb->get_row("SELECT * FROM $membership_level_table where id='$current_primary_level'", OBJECT);
185
+ if(!empty($level_query->subscription_period) && !empty($level_query->subscription_unit)){//Duration value is used
186
+ $account_state = "active";
187
+ $subscription_starts = (date ("Y-m-d"));
188
+
189
+ $updatedb = "UPDATE $members_table_name SET account_state='$account_state',subscription_starts='$subscription_starts' WHERE member_id='$swpm_id'";
190
+ $resultset = $wpdb->query($updatedb);
191
+ swpm_debug_log_subsc("Updated the member profile with current date as the subscription start date.",true);
192
+ }else{
193
+ swpm_debug_log_subsc("This membership level is not using a duration/interval value as the subscription duration.",true);
194
+ }
195
+ }else{
196
+ swpm_debug_log_subsc("Did not find a record in the members table for subscriber ID: ".$subscr_id,true);
197
+ }
198
+ }
199
+
200
+ function swpm_debug_log_subsc($message,$success,$end=false)
201
+ {
202
+ $settings = BSettings::get_instance();
203
+ $debug_enabled = $settings->get_value('enable-debug');
204
+ if (empty($debug_enabled)) {//Debug is not enabled
205
+ return;
206
+ }
207
+
208
+ $debug_log_file_name = SIMPLE_WP_MEMBERSHIP_PATH . 'log.txt';
209
+
210
+ // Timestamp
211
+ $text = '['.date('m/d/Y g:i A').'] - '.(($success)?'SUCCESS :':'FAILURE :').$message. "\n";
212
+ if ($end) {
213
+ $text .= "\n------------------------------------------------------------------\n\n";
214
+ }
215
+ // Write to log
216
+ $fp=fopen($debug_log_file_name,'a');
217
+ fwrite($fp, $text );
218
+ fclose($fp); // close file
219
+ }
js/jquery.tools18.min.js ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery Tools v1.2.5 - The missing UI library for the Web
3
+ *
4
+ * dateinput/dateinput.js
5
+ * overlay/overlay.js
6
+ * overlay/overlay.apple.js
7
+ * rangeinput/rangeinput.js
8
+ * scrollable/scrollable.js
9
+ * scrollable/scrollable.autoscroll.js
10
+ * scrollable/scrollable.navigator.js
11
+ * tabs/tabs.js
12
+ * tabs/tabs.slideshow.js
13
+ * toolbox/toolbox.expose.js
14
+ * toolbox/toolbox.flashembed.js
15
+ * toolbox/toolbox.history.js
16
+ * toolbox/toolbox.mousewheel.js
17
+ * tooltip/tooltip.js
18
+ * tooltip/tooltip.dynamic.js
19
+ * tooltip/tooltip.slide.js
20
+ * validator/validator.js
21
+ *
22
+ * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
23
+ *
24
+ * http://flowplayer.org/tools/
25
+ *
26
+ * jquery.event.wheel.js - rev 1
27
+ * Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)
28
+ * Liscensed under the MIT License (MIT-LICENSE.txt)
29
+ * http://www.opensource.org/licenses/mit-license.php
30
+ * Created: 2008-07-01 | Updated: 2008-07-14
31
+ *
32
+ * -----
33
+ *
34
+ */
35
+ (function(a){a.tools=a.tools||{version:"v1.2.5"};var b=[],c,d=[75,76,38,39,74,72,40,37],e={};c=a.tools.dateinput={conf:{format:"mm/dd/yy",selectors:!1,yearRange:[-5,5],lang:"en",offset:[0,0],speed:0,firstDay:0,min:undefined,max:undefined,trigger:!1,css:{prefix:"cal",input:"date",root:0,head:0,title:0,prev:0,next:0,month:0,year:0,days:0,body:0,weeks:0,today:0,current:0,week:0,off:0,sunday:0,focus:0,disabled:0,trigger:0}},localize:function(b,c){a.each(c,function(a,b){c[a]=b.split(",")}),e[b]=c}},c.localize("en",{months:"January,February,March,April,May,June,July,August,September,October,November,December",shortMonths:"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",days:"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday",shortDays:"Sun,Mon,Tue,Wed,Thu,Fri,Sat"});function f(a,b){return 32-(new Date(a,b,32)).getDate()}function g(a,b){a=""+a,b=b||2;while(a.length<b)a="0"+a;return a}var h=/d{1,4}|m{1,4}|yy(?:yy)?|"[^"]*"|'[^']*'/g,i=a("<a/>");function j(a,b,c){var d=a.getDate(),f=a.getDay(),j=a.getMonth(),k=a.getFullYear(),l={d:d,dd:g(d),ddd:e[c].shortDays[f],dddd:e[c].days[f],m:j+1,mm:g(j+1),mmm:e[c].shortMonths[j],mmmm:e[c].months[j],yy:String(k).slice(2),yyyy:k},m=b.replace(h,function(a){return a in l?l[a]:a.slice(1,a.length-1)});return i.html(m).html()}function k(a){return parseInt(a,10)}function l(a,b){return a.getFullYear()===b.getFullYear()&&a.getMonth()==b.getMonth()&&a.getDate()==b.getDate()}function m(a){if(a){if(a.constructor==Date)return a;if(typeof a=="string"){var b=a.split("-");if(b.length==3)return new Date(k(b[0]),k(b[1])-1,k(b[2]));if(!/^-?\d+$/.test(a))return;a=k(a)}var c=new Date;c.setDate(c.getDate()+a);return c}}function n(c,g){var h=this,i=new Date,n=g.css,o=e[g.lang],p=a("#"+n.root),q=p.find("#"+n.title),r,s,t,u,v,w,x=c.attr("data-value")||g.value||c.val(),y=c.attr("min")||g.min,z=c.attr("max")||g.max,A;y===0&&(y="0"),x=m(x)||i,y=m(y||g.yearRange[0]*365),z=m(z||g.yearRange[1]*365);if(!o)throw"Dateinput: invalid language: "+g.lang;if(c.attr("type")=="date"){var B=a("<input/>");a.each("class,disabled,id,maxlength,name,readonly,required,size,style,tabindex,title,value".split(","),function(a,b){B.attr(b,c.attr(b))}),c.replaceWith(B),c=B}c.addClass(n.input);var C=c.add(h);if(!p.length){p=a("<div><div><a/><div/><a/></div><div><div/><div/></div></div>").hide().css({position:"absolute"}).attr("id",n.root),p.children().eq(0).attr("id",n.head).end().eq(1).attr("id",n.body).children().eq(0).attr("id",n.days).end().eq(1).attr("id",n.weeks).end().end().end().find("a").eq(0).attr("id",n.prev).end().eq(1).attr("id",n.next),q=p.find("#"+n.head).find("div").attr("id",n.title);if(g.selectors){var D=a("<select/>").attr("id",n.month),E=a("<select/>").attr("id",n.year);q.html(D.add(E))}var F=p.find("#"+n.days);for(var G=0;G<7;G++)F.append(a("<span/>").text(o.shortDays[(G+g.firstDay)%7]));a("body").append(p)}g.trigger&&(r=a("<a/>").attr("href","#").addClass(n.trigger).click(function(a){h.show();return a.preventDefault()}).insertAfter(c));var H=p.find("#"+n.weeks);E=p.find("#"+n.year),D=p.find("#"+n.month);function I(b,d,e){x=b,u=b.getFullYear(),v=b.getMonth(),w=b.getDate(),e=e||a.Event("api"),e.type="change",C.trigger(e,[b]);e.isDefaultPrevented()||(c.val(j(b,d.format,d.lang)),c.data("date",b),h.hide(e))}function J(b){b.type="onShow",C.trigger(b),a(document).bind("keydown.d",function(b){if(b.ctrlKey)return!0;var e=b.keyCode;if(e==8){c.val("");return h.hide(b)}if(e==27)return h.hide(b);if(a(d).index(e)>=0){if(!A){h.show(b);return b.preventDefault()}var f=a("#"+n.weeks+" a"),g=a("."+n.focus),i=f.index(g);g.removeClass(n.focus);if(e==74||e==40)i+=7;else if(e==75||e==38)i-=7;else if(e==76||e==39)i+=1;else if(e==72||e==37)i-=1;i>41?(h.addMonth(),g=a("#"+n.weeks+" a:eq("+(i-42)+")")):i<0?(h.addMonth(-1),g=a("#"+n.weeks+" a:eq("+(i+42)+")")):g=f.eq(i),g.addClass(n.focus);return b.preventDefault()}if(e==34)return h.addMonth();if(e==33)return h.addMonth(-1);if(e==36)return h.today();e==13&&(a(b.target).is("select")||a("."+n.focus).click());return a([16,17,18,9]).index(e)>=0}),a(document).bind("click.d",function(b){var d=b.target;!a(d).parents("#"+n.root).length&&d!=c[0]&&(!r||d!=r[0])&&(d!=document)&&h.hide(b)})}a.extend(h,{show:function(d){if(!(c.attr("readonly")||c.attr("disabled")||A)){d=d||a.Event(),d.type="onBeforeShow",C.trigger(d);if(d.isDefaultPrevented())return;a.each(b,function(){this.hide()}),A=!0,D.unbind("change").change(function(){h.setValue(E.val(),a(this).val())}),E.unbind("change").change(function(){h.setValue(a(this).val(),D.val())}),s=p.find("#"+n.prev).unbind("click").click(function(a){s.hasClass(n.disabled)||h.addMonth(-1);return!1}),t=p.find("#"+n.next).unbind("click").click(function(a){t.hasClass(n.disabled)||h.addMonth();return!1}),h.setValue(x);var e=c.offset();/iPad/i.test(navigator.userAgent)&&(e.top-=a(window).scrollTop()),p.css({top:e.top+c.outerHeight(true)+g.offset[0],left:e.left+g.offset[1]}),g.speed?p.show(g.speed,function(){J(d)}):(p.show(),J(d));return h}},setValue:function(b,c,d){var e=k(c)>=-1?new Date(k(b),k(c),k(d||1)):b||x;e<y?e=y:e>z&&(e=z),b=e.getFullYear(),c=e.getMonth(),d=e.getDate(),c==-1?(c=11,b--):c==12&&(c=0,b++);if(!A){I(e,g);return h}v=c,u=b;var j=new Date(b,c,1-g.firstDay),m=j.getDay(),p=f(b,c),r=f(b,c-1),w;if(g.selectors){D.empty(),a.each(o.months,function(c,d){y<new Date(b,c+1,-1)&&z>new Date(b,c,0)&&D.append(a("<option/>").html(d).attr("value",c))}),E.empty();var B=i.getFullYear();for(var C=B+g.yearRange[0];C<B+g.yearRange[1];C++)y<=new Date(C+1,-1,1)&&z>new Date(C,0,0)&&E.append(a("<option/>").text(C));D.val(c),E.val(b)}else q.html(o.months[c]+" "+b);H.empty(),s.add(t).removeClass(n.disabled);for(var F=m?0:-7,G,J;F<(m?42:35);F++)G=a("<a/>"),F%7===0&&(w=a("<div/>").addClass(n.week),H.append(w)),F<m?(G.addClass(n.off),J=r-m+F+1,e=new Date(b,c-1,J)):F<m+p?(J=F-m+1,e=new Date(b,c,J),l(x,e)?G.attr("id",n.current).addClass(n.focus):l(i,e)&&G.attr("id",n.today)):(G.addClass(n.off),J=F-p-m+1,e=new Date(b,c+1,J)),y&&e<y&&G.add(s).addClass(n.disabled),z&&e>z&&G.add(t).addClass(n.disabled),G.attr("href","#"+J).text(J).data("date",e),w.append(G);H.find("a").click(function(b){var c=a(this);c.hasClass(n.disabled)||(a("#"+n.current).removeAttr("id"),c.attr("id",n.current),I(c.data("date"),g,b));return!1}),n.sunday&&H.find(n.week).each(function(){var b=g.firstDay?7-g.firstDay:0;a(this).children().slice(b,b+1).addClass(n.sunday)});return h},setMin:function(a,b){y=m(a),b&&x<y&&h.setValue(y);return h},setMax:function(a,b){z=m(a),b&&x>z&&h.setValue(z);return h},today:function(){return h.setValue(i)},addDay:function(a){return this.setValue(u,v,w+(a||1))},addMonth:function(a){return this.setValue(u,v+(a||1),w)},addYear:function(a){return this.setValue(u+(a||1),v,w)},hide:function(b){if(A){b=a.Event(),b.type="onHide",C.trigger(b),a(document).unbind("click.d").unbind("keydown.d");if(b.isDefaultPrevented())return;p.hide(),A=!1}return h},getConf:function(){return g},getInput:function(){return c},getCalendar:function(){return p},getValue:function(a){return a?j(x,a,g.lang):x},isOpen:function(){return A}}),a.each(["onBeforeShow","onShow","change","onHide"],function(b,c){a.isFunction(g[c])&&a(h).bind(c,g[c]),h[c]=function(b){b&&a(h).bind(c,b);return h}}),c.bind("focus click",h.show).keydown(function(b){var c=b.keyCode;if(!A&&a(d).index(c)>=0){h.show(b);return b.preventDefault()}return b.shiftKey||b.ctrlKey||b.altKey||c==9?!0:b.preventDefault()}),m(c.val())&&I(x,g)}a.expr[":"].date=function(b){var c=b.getAttribute("type");return c&&c=="date"||a(b).data("dateinput")},a.fn.dateinput=function(d){if(this.data("dateinput"))return this;d=a.extend(!0,{},c.conf,d),a.each(d.css,function(a,b){!b&&a!="prefix"&&(d.css[a]=(d.css.prefix||"")+(b||a))});var e;this.each(function(){var c=new n(a(this),d);b.push(c);var f=c.getInput().data("dateinput",c);e=e?e.add(f):f});return e?e:this}})(jQuery);
36
+ (function(a){a.tools=a.tools||{version:"v1.2.5"},a.tools.overlay={addEffect:function(a,b,d){c[a]=[b,d]},conf:{close:null,closeOnClick:!0,closeOnEsc:!0,closeSpeed:"fast",effect:"default",fixed:!a.browser.msie||a.browser.version>6,left:"center",load:!1,mask:null,oneInstance:!0,speed:"normal",target:null,top:"10%"}};var b=[],c={};a.tools.overlay.addEffect("default",function(b,c){var d=this.getConf(),e=a(window);d.fixed||(b.top+=e.scrollTop(),b.left+=e.scrollLeft()),b.position=d.fixed?"fixed":"absolute",this.getOverlay().css(b).fadeIn(d.speed,c)},function(a){this.getOverlay().fadeOut(this.getConf().closeSpeed,a)});function d(d,e){var f=this,g=d.add(f),h=a(window),i,j,k,l=a.tools.expose&&(e.mask||e.expose),m=Math.random().toString().slice(10);l&&(typeof l=="string"&&(l={color:l}),l.closeOnClick=l.closeOnEsc=!1);var n=e.target||d.attr("rel");j=n?a(n):null||d;if(!j.length)throw"Could not find Overlay: "+n;d&&d.index(j)==-1&&d.click(function(a){f.load(a);return a.preventDefault()}),a.extend(f,{load:function(d){if(f.isOpened())return f;var i=c[e.effect];if(!i)throw"Overlay: cannot find effect : \""+e.effect+"\"";e.oneInstance&&a.each(b,function(){this.close(d)}),d=d||a.Event(),d.type="onBeforeLoad",g.trigger(d);if(d.isDefaultPrevented())return f;k=!0,l&&a(j).expose(l);var n=e.top,o=e.left,p=j.outerWidth(true),q=j.outerHeight(true);typeof n=="string"&&(n=n=="center"?Math.max((h.height()-q)/2,0):parseInt(n,10)/100*h.height()),o=="center"&&(o=Math.max((h.width()-p)/2,0)),i[0].call(f,{top:n,left:o},function(){k&&(d.type="onLoad",g.trigger(d))}),l&&e.closeOnClick&&a.mask.getMask().one("click",f.close),e.closeOnClick&&a(document).bind("click."+m,function(b){a(b.target).parents(j).length||f.close(b)}),e.closeOnEsc&&a(document).bind("keydown."+m,function(a){a.keyCode==27&&f.close(a)});return f},close:function(b){if(!f.isOpened())return f;b=b||a.Event(),b.type="onBeforeClose",g.trigger(b);if(!b.isDefaultPrevented()){k=!1,c[e.effect][1].call(f,function(){b.type="onClose",g.trigger(b)}),a(document).unbind("click."+m).unbind("keydown."+m),l&&a.mask.close();return f}},getOverlay:function(){return j},getTrigger:function(){return d},getClosers:function(){return i},isOpened:function(){return k},getConf:function(){return e}}),a.each("onBeforeLoad,onStart,onLoad,onBeforeClose,onClose".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}}),i=j.find(e.close||".close"),!i.length&&!e.close&&(i=a("<a class=\"close\"></a>"),j.prepend(i)),i.click(function(a){f.close(a)}),e.load&&f.load()}a.fn.overlay=function(c){var e=this.data("overlay");if(e)return e;a.isFunction(c)&&(c={onBeforeLoad:c}),c=a.extend(!0,{},a.tools.overlay.conf,c),this.each(function(){e=new d(a(this),c),b.push(e),a(this).data("overlay",e)});return c.api?e:this}})(jQuery);
37
+ (function(a){var b=a.tools.overlay,c=a(window);a.extend(b.conf,{start:{top:null,left:null},fadeInSpeed:"fast",zIndex:9999});function d(a){var b=a.offset();return{top:b.top+a.height()/2,left:b.left+a.width()/2}}var e=function(b,e){var f=this.getOverlay(),g=this.getConf(),h=this.getTrigger(),i=this,j=f.outerWidth(true),k=f.data("img"),l=g.fixed?"fixed":"absolute";if(!k){var m=f.css("backgroundImage");if(!m)throw"background-image CSS property not set for overlay";m=m.slice(m.indexOf("(")+1,m.indexOf(")")).replace(/\"/g,""),f.css("backgroundImage","none"),k=a("<img src=\""+m+"\"/>"),k.css({border:0,display:"none"}).width(j),a("body").append(k),f.data("img",k)}var n=g.start.top||Math.round(c.height()/2),o=g.start.left||Math.round(c.width()/2);if(h){var p=d(h);n=p.top,o=p.left}g.fixed?(n-=c.scrollTop(),o-=c.scrollLeft()):(b.top+=c.scrollTop(),b.left+=c.scrollLeft()),k.css({position:"absolute",top:n,left:o,width:0,zIndex:g.zIndex}).show(),b.position=l,f.css(b),k.animate({top:f.css("top"),left:f.css("left"),width:j},g.speed,function(){f.css("zIndex",g.zIndex+1).fadeIn(g.fadeInSpeed,function(){i.isOpened()&&!a(this).index(f)?e.call():f.hide()})}).css("position",l)},f=function(b){var e=this.getOverlay().hide(),f=this.getConf(),g=this.getTrigger(),h=e.data("img"),i={top:f.start.top,left:f.start.left,width:0};g&&a.extend(i,d(g)),f.fixed&&h.css({position:"absolute"}).animate({top:"+="+c.scrollTop(),left:"+="+c.scrollLeft()},0),h.animate(i,f.closeSpeed,b)};b.addEffect("apple",e,f)})(jQuery);
38
+ (function(a){a.tools=a.tools||{version:"v1.2.5"};var b;b=a.tools.rangeinput={conf:{min:0,max:100,step:"any",steps:0,value:0,precision:undefined,vertical:0,keyboard:!0,progress:!1,speed:100,css:{input:"range",slider:"slider",progress:"progress",handle:"handle"}}};var c,d;a.fn.drag=function(b){document.ondragstart=function(){return!1},b=a.extend({x:!0,y:!0,drag:!0},b),c=c||a(document).bind("mousedown mouseup",function(e){var f=a(e.target);if(e.type=="mousedown"&&f.data("drag")){var g=f.position(),h=e.pageX-g.left,i=e.pageY-g.top,j=!0;c.bind("mousemove.drag",function(a){var c=a.pageX-h,e=a.pageY-i,g={};b.x&&(g.left=c),b.y&&(g.top=e),j&&(f.trigger("dragStart"),j=!1),b.drag&&f.css(g),f.trigger("drag",[e,c]),d=f}),e.preventDefault()}else try{d&&d.trigger("dragEnd")}finally{c.unbind("mousemove.drag"),d=null}});return this.data("drag",!0)};function e(a,b){var c=Math.pow(10,b);return Math.round(a*c)/c}function f(a,b){var c=parseInt(a.css(b),10);if(c)return c;var d=a[0].currentStyle;return d&&d.width&&parseInt(d.width,10)}function g(a){var b=a.data("events");return b&&b.onSlide}function h(b,c){var d=this,h=c.css,i=a("<div><div/><a href='#'/></div>").data("rangeinput",d),j,k,l,m,n;b.before(i);var o=i.addClass(h.slider).find("a").addClass(h.handle),p=i.find("div").addClass(h.progress);a.each("min,max,step,value".split(","),function(a,d){var e=b.attr(d);parseFloat(e)&&(c[d]=parseFloat(e,10))});var q=c.max-c.min,r=c.step=="any"?0:c.step,s=c.precision;if(s===undefined)try{s=r.toString().split(".")[1].length}catch(t){s=0}if(b.attr("type")=="range"){var u=a("<input/>");a.each("class,disabled,id,maxlength,name,readonly,required,size,style,tabindex,title,value".split(","),function(a,c){u.attr(c,b.attr(c))}),u.val(c.value),b.replaceWith(u),b=u}b.addClass(h.input);var v=a(d).add(b),w=!0;function x(a,f,g,h){g===undefined?g=f/m*q:h&&(g-=c.min),r&&(g=Math.round(g/r)*r);if(f===undefined||r)f=g*m/q;if(isNaN(g))return d;f=Math.max(0,Math.min(f,m)),g=f/m*q;if(h||!j)g+=c.min;j&&(h?f=m-f:g=c.max-g),g=e(g,s);var i=a.type=="click";if(w&&k!==undefined&&!i){a.type="onSlide",v.trigger(a,[g,f]);if(a.isDefaultPrevented())return d}var l=i?c.speed:0,t=i?function(){a.type="change",v.trigger(a,[g])}:null;j?(o.animate({top:f},l,t),c.progress&&p.animate({height:m-f+o.width()/2},l)):(o.animate({left:f},l,t),c.progress&&p.animate({width:f+o.width()/2},l)),k=g,n=f,b.val(g);return d}a.extend(d,{getValue:function(){return k},setValue:function(b,c){y();return x(c||a.Event("api"),undefined,b,!0)},getConf:function(){return c},getProgress:function(){return p},getHandle:function(){return o},getInput:function(){return b},step:function(b,e){e=e||a.Event();var f=c.step=="any"?1:c.step;d.setValue(k+f*(b||1),e)},stepUp:function(a){return d.step(a||1)},stepDown:function(a){return d.step(-a||-1)}}),a.each("onSlide,change".split(","),function(b,e){a.isFunction(c[e])&&a(d).bind(e,c[e]),d[e]=function(b){b&&a(d).bind(e,b);return d}}),o.drag({drag:!1}).bind("dragStart",function(){y(),w=g(a(d))||g(b)}).bind("drag",function(a,c,d){if(b.is(":disabled"))return!1;x(a,j?c:d)}).bind("dragEnd",function(a){a.isDefaultPrevented()||(a.type="change",v.trigger(a,[k]))}).click(function(a){return a.preventDefault()}),i.click(function(a){if(b.is(":disabled")||a.target==o[0])return a.preventDefault();y();var c=o.width()/2;x(a,j?m-l-c+a.pageY:a.pageX-l-c)}),c.keyboard&&b.keydown(function(c){if(!b.attr("readonly")){var e=c.keyCode,f=a([75,76,38,33,39]).index(e)!=-1,g=a([74,72,40,34,37]).index(e)!=-1;if((f||g)&&!(c.shiftKey||c.altKey||c.ctrlKey)){f?d.step(e==33?10:1,c):g&&d.step(e==34?-10:-1,c);return c.preventDefault()}}}),b.blur(function(b){var c=a(this).val();c!==k&&d.setValue(c,b)}),a.extend(b[0],{stepUp:d.stepUp,stepDown:d.stepDown});function y(){j=c.vertical||f(i,"height")>f(i,"width"),j?(m=f(i,"height")-f(o,"height"),l=i.offset().top+m):(m=f(i,"width")-f(o,"width"),l=i.offset().left)}function z(){y(),d.setValue(c.value!==undefined?c.value:c.min)}z(),m||a(window).load(z)}a.expr[":"].range=function(b){var c=b.getAttribute("type");return c&&c=="range"||a(b).filter("input").data("rangeinput")},a.fn.rangeinput=function(c){if(this.data("rangeinput"))return this;c=a.extend(!0,{},b.conf,c);var d;this.each(function(){var b=new h(a(this),a.extend(!0,{},c)),e=b.getInput().data("rangeinput",b);d=d?d.add(e):e});return d?d:this}})(jQuery);
39
+ (function(a){a.tools=a.tools||{version:"v1.2.5"},a.tools.scrollable={conf:{activeClass:"active",circular:!1,clonedClass:"cloned",disabledClass:"disabled",easing:"swing",initialIndex:0,item:null,items:".items",keyboard:!0,mousewheel:!1,next:".next",prev:".prev",speed:400,vertical:!1,touch:!0,wheelSpeed:0}};function b(a,b){var c=parseInt(a.css(b),10);if(c)return c;var d=a[0].currentStyle;return d&&d.width&&parseInt(d.width,10)}function c(b,c){var d=a(c);return d.length<2?d:b.parent().find(c)}var d;function e(b,e){var f=this,g=b.add(f),h=b.children(),i=0,j=e.vertical;d||(d=f),h.length>1&&(h=a(e.items,b)),a.extend(f,{getConf:function(){return e},getIndex:function(){return i},getSize:function(){return f.getItems().size()},getNaviButtons:function(){return m.add(n)},getRoot:function(){return b},getItemWrap:function(){return h},getItems:function(){return h.children(e.item).not("."+e.clonedClass)},move:function(a,b){return f.seekTo(i+a,b)},next:function(a){return f.move(1,a)},prev:function(a){return f.move(-1,a)},begin:function(a){return f.seekTo(0,a)},end:function(a){return f.seekTo(f.getSize()-1,a)},focus:function(){d=f;return f},addItem:function(b){b=a(b),e.circular?(h.children("."+e.clonedClass+":last").before(b),h.children("."+e.clonedClass+":first").replaceWith(b.clone().addClass(e.clonedClass))):h.append(b),g.trigger("onAddItem",[b]);return f},seekTo:function(b,c,k){b.jquery||(b*=1);if(e.circular&&b===0&&i==-1&&c!==0)return f;if(!e.circular&&b<0||b>f.getSize()||b<-1)return f;var l=b;b.jquery?b=f.getItems().index(b):l=f.getItems().eq(b);var m=a.Event("onBeforeSeek");if(!k){g.trigger(m,[b,c]);if(m.isDefaultPrevented()||!l.length)return f}var n=j?{top:-l.position().top}:{left:-l.position().left};i=b,d=f,c===undefined&&(c=e.speed),h.animate(n,c,e.easing,k||function(){g.trigger("onSeek",[b])});return f}}),a.each(["onBeforeSeek","onSeek","onAddItem"],function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}});if(e.circular){var k=f.getItems().slice(-1).clone().prependTo(h),l=f.getItems().eq(1).clone().appendTo(h);k.add(l).addClass(e.clonedClass),f.onBeforeSeek(function(a,b,c){if(!a.isDefaultPrevented()){if(b==-1){f.seekTo(k,c,function(){f.end(0)});return a.preventDefault()}b==f.getSize()&&f.seekTo(l,c,function(){f.begin(0)})}}),f.seekTo(0,0,function(){})}var m=c(b,e.prev).click(function(){f.prev()}),n=c(b,e.next).click(function(){f.next()});!e.circular&&f.getSize()>1&&(f.onBeforeSeek(function(a,b){setTimeout(function(){a.isDefaultPrevented()||(m.toggleClass(e.disabledClass,b<=0),n.toggleClass(e.disabledClass,b>=f.getSize()-1))},1)}),e.initialIndex||m.addClass(e.disabledClass)),e.mousewheel&&a.fn.mousewheel&&b.mousewheel(function(a,b){if(e.mousewheel){f.move(b<0?1:-1,e.wheelSpeed||50);return!1}});if(e.touch){var o={};h[0].ontouchstart=function(a){var b=a.touches[0];o.x=b.clientX,o.y=b.clientY},h[0].ontouchmove=function(a){if(a.touches.length==1&&!h.is(":animated")){var b=a.touches[0],c=o.x-b.clientX,d=o.y-b.clientY;f[j&&d>0||!j&&c>0?"next":"prev"](),a.preventDefault()}}}e.keyboard&&a(document).bind("keydown.scrollable",function(b){if(e.keyboard&&!b.altKey&&!b.ctrlKey&&!a(b.target).is(":input")){if(e.keyboard!="static"&&d!=f)return;var c=b.keyCode;if(j&&(c==38||c==40)){f.move(c==38?-1:1);return b.preventDefault()}if(!j&&(c==37||c==39)){f.move(c==37?-1:1);return b.preventDefault()}}}),e.initialIndex&&f.seekTo(e.initialIndex,0,function(){})}a.fn.scrollable=function(b){var c=this.data("scrollable");if(c)return c;b=a.extend({},a.tools.scrollable.conf,b),this.each(function(){c=new e(a(this),b),a(this).data("scrollable",c)});return b.api?c:this}})(jQuery);
40
+ (function(a){var b=a.tools.scrollable;b.autoscroll={conf:{autoplay:!0,interval:3e3,autopause:!0}},a.fn.autoscroll=function(c){typeof c=="number"&&(c={interval:c});var d=a.extend({},b.autoscroll.conf,c),e;this.each(function(){var b=a(this).data("scrollable");b&&(e=b);var c,f=!0;b.play=function(){c||(f=!1,c=setInterval(function(){b.next()},d.interval))},b.pause=function(){c=clearInterval(c)},b.stop=function(){b.pause(),f=!0},d.autopause&&b.getRoot().add(b.getNaviButtons()).hover(b.pause,b.play),d.autoplay&&b.play()});return d.api?e:this}})(jQuery);
41
+ (function(a){var b=a.tools.scrollable;b.navigator={conf:{navi:".navi",naviItem:null,activeClass:"active",indexed:!1,idPrefix:null,history:!1}};function c(b,c){var d=a(c);return d.length<2?d:b.parent().find(c)}a.fn.navigator=function(d){typeof d=="string"&&(d={navi:d}),d=a.extend({},b.navigator.conf,d);var e;this.each(function(){var b=a(this).data("scrollable"),f=d.navi.jquery?d.navi:c(b.getRoot(),d.navi),g=b.getNaviButtons(),h=d.activeClass,i=d.history&&a.fn.history;b&&(e=b),b.getNaviButtons=function(){return g.add(f)};function j(a,c,d){b.seekTo(c);if(i)location.hash&&(location.hash=a.attr("href").replace("#",""));else return d.preventDefault()}function k(){return f.find(d.naviItem||"> *")}function l(b){var c=a("<"+(d.naviItem||"a")+"/>").click(function(c){j(a(this),b,c)}).attr("href","#"+b);b===0&&c.addClass(h),d.indexed&&c.text(b+1),d.idPrefix&&c.attr("id",d.idPrefix+b);return c.appendTo(f)}k().length?k().each(function(b){a(this).click(function(c){j(a(this),b,c)})}):a.each(b.getItems(),function(a){l(a)}),b.onBeforeSeek(function(a,b){setTimeout(function(){if(!a.isDefaultPrevented()){var c=k().eq(b);!a.isDefaultPrevented()&&c.length&&k().removeClass(h).eq(b).addClass(h)}},1)});function m(a,b){var c=k().eq(b.replace("#",""));c.length||(c=k().filter("[href="+b+"]")),c.click()}b.onAddItem(function(a,c){c=l(b.getItems().index(c)),i&&c.history(m)}),i&&k().history(m)});return d.api?e:this}})(jQuery);
42
+ (function(a){a.tools=a.tools||{version:"v1.2.5"},a.tools.tabs={conf:{tabs:"a",current:"current",onBeforeClick:null,onClick:null,effect:"default",initialIndex:0,event:"click",rotate:!1,history:!1},addEffect:function(a,c){b[a]=c}};var b={"default":function(a,b){this.getPanes().hide().eq(a).show(),b.call()},fade:function(a,b){var c=this.getConf(),d=c.fadeOutSpeed,e=this.getPanes();d?e.fadeOut(d):e.hide(),e.eq(a).fadeIn(c.fadeInSpeed,b)},slide:function(a,b){this.getPanes().slideUp(200),this.getPanes().eq(a).slideDown(400,b)},ajax:function(a,b){this.getPanes().eq(0).load(this.getTabs().eq(a).attr("href"),b)}},c;a.tools.tabs.addEffect("horizontal",function(b,d){c||(c=this.getPanes().eq(0).width()),this.getCurrentPane().animate({width:0},function(){a(this).hide()}),this.getPanes().eq(b).animate({width:c},function(){a(this).show(),d.call()})});function d(c,d,e){var f=this,g=c.add(this),h=c.find(e.tabs),i=d.jquery?d:c.children(d),j;h.length||(h=c.children()),i.length||(i=c.parent().find(d)),i.length||(i=a(d)),a.extend(this,{click:function(c,d){var i=h.eq(c);typeof c=="string"&&c.replace("#","")&&(i=h.filter("[href*="+c.replace("#","")+"]"),c=Math.max(h.index(i),0));if(e.rotate){var k=h.length-1;if(c<0)return f.click(k,d);if(c>k)return f.click(0,d)}if(!i.length){if(j>=0)return f;c=e.initialIndex,i=h.eq(c)}if(c===j)return f;d=d||a.Event(),d.type="onBeforeClick",g.trigger(d,[c]);if(!d.isDefaultPrevented()){b[e.effect].call(f,c,function(){d.type="onClick",g.trigger(d,[c])}),j=c,h.removeClass(e.current),i.addClass(e.current);return f}},getConf:function(){return e},getTabs:function(){return h},getPanes:function(){return i},getCurrentPane:function(){return i.eq(j)},getCurrentTab:function(){return h.eq(j)},getIndex:function(){return j},next:function(){return f.click(j+1)},prev:function(){return f.click(j-1)},destroy:function(){h.unbind(e.event).removeClass(e.current),i.find("a[href^=#]").unbind("click.T");return f}}),a.each("onBeforeClick,onClick".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}}),e.history&&a.fn.history&&(a.tools.history.init(h),e.event="history"),h.each(function(b){a(this).bind(e.event,function(a){f.click(b,a);return a.preventDefault()})}),i.find("a[href^=#]").bind("click.T",function(b){f.click(a(this).attr("href"),b)}),location.hash&&e.tabs=="a"&&c.find("[href="+location.hash+"]").length?f.click(location.hash):(e.initialIndex===0||e.initialIndex>0)&&f.click(e.initialIndex)}a.fn.tabs=function(b,c){var e=this.data("tabs");e&&(e.destroy(),this.removeData("tabs")),a.isFunction(c)&&(c={onBeforeClick:c}),c=a.extend({},a.tools.tabs.conf,c),this.each(function(){e=new d(a(this),b,c),a(this).data("tabs",e)});return c.api?e:this}})(jQuery);
43
+ (function(a){var b;b=a.tools.tabs.slideshow={conf:{next:".forward",prev:".backward",disabledClass:"disabled",autoplay:!1,autopause:!0,interval:3e3,clickable:!0,api:!1}};function c(b,c){var d=this,e=b.add(this),f=b.data("tabs"),g,h=!0;function i(c){var d=a(c);return d.length<2?d:b.parent().find(c)}var j=i(c.next).click(function(){f.next()}),k=i(c.prev).click(function(){f.prev()});a.extend(d,{getTabs:function(){return f},getConf:function(){return c},play:function(){if(g)return d;var b=a.Event("onBeforePlay");e.trigger(b);if(b.isDefaultPrevented())return d;g=setInterval(f.next,c.interval),h=!1,e.trigger("onPlay");return d},pause:function(){if(!g)return d;var b=a.Event("onBeforePause");e.trigger(b);if(b.isDefaultPrevented())return d;g=clearInterval(g),e.trigger("onPause");return d},stop:function(){d.pause(),h=!0}}),a.each("onBeforePlay,onPlay,onBeforePause,onPause".split(","),function(b,e){a.isFunction(c[e])&&a(d).bind(e,c[e]),d[e]=function(b){return a(d).bind(e,b)}}),c.autopause&&f.getTabs().add(j).add(k).add(f.getPanes()).hover(d.pause,function(){h||d.play()}),c.autoplay&&d.play(),c.clickable&&f.getPanes().click(function(){f.next()});if(!f.getConf().rotate){var l=c.disabledClass;f.getIndex()||k.addClass(l),f.onBeforeClick(function(a,b){k.toggleClass(l,!b),j.toggleClass(l,b==f.getTabs().length-1)})}}a.fn.slideshow=function(d){var e=this.data("slideshow");if(e)return e;d=a.extend({},b.conf,d),this.each(function(){e=new c(a(this),d),a(this).data("slideshow",e)});return d.api?e:this}})(jQuery);
44
+ (function(a){a.tools=a.tools||{version:"v1.2.5"};var b;b=a.tools.expose={conf:{maskId:"exposeMask",loadSpeed:"slow",closeSpeed:"fast",closeOnClick:!0,closeOnEsc:!0,zIndex:9998,opacity:.8,startOpacity:0,color:"#fff",onLoad:null,onClose:null}};function c(){if(a.browser.msie){var b=a(document).height(),c=a(window).height();return[window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,b-c<20?c:b]}return[a(document).width(),a(document).height()]}function d(b){if(b)return b.call(a.mask)}var e,f,g,h,i;a.mask={load:function(j,k){if(g)return this;typeof j=="string"&&(j={color:j}),j=j||h,h=j=a.extend(a.extend({},b.conf),j),e=a("#"+j.maskId),e.length||(e=a("<div/>").attr("id",j.maskId),a("body").append(e));var l=c();e.css({position:"absolute",top:0,left:0,width:l[0],height:l[1],display:"none",opacity:j.startOpacity,zIndex:j.zIndex}),j.color&&e.css("backgroundColor",j.color);if(d(j.onBeforeLoad)===!1)return this;j.closeOnEsc&&a(document).bind("keydown.mask",function(b){b.keyCode==27&&a.mask.close(b)}),j.closeOnClick&&e.bind("click.mask",function(b){a.mask.close(b)}),a(window).bind("resize.mask",function(){a.mask.fit()}),k&&k.length&&(i=k.eq(0).css("zIndex"),a.each(k,function(){var b=a(this);/relative|absolute|fixed/i.test(b.css("position"))||b.css("position","relative")}),f=k.css({zIndex:Math.max(j.zIndex+1,i=="auto"?0:i)})),e.css({display:"block"}).fadeTo(j.loadSpeed,j.opacity,function(){a.mask.fit(),d(j.onLoad),g="full"}),g=!0;return this},close:function(){if(g){if(d(h.onBeforeClose)===!1)return this;e.fadeOut(h.closeSpeed,function(){d(h.onClose),f&&f.css({zIndex:i}),g=!1}),a(document).unbind("keydown.mask"),e.unbind("click.mask"),a(window).unbind("resize.mask")}return this},fit:function(){if(g){var a=c();e.css({width:a[0],height:a[1]})}},getMask:function(){return e},isLoaded:function(a){return a?g=="full":g},getConf:function(){return h},getExposed:function(){return f}},a.fn.mask=function(b){a.mask.load(b);return this},a.fn.expose=function(b){a.mask.load(b,this);return this}})(jQuery);
45
+ (function(){var a=document.all,b="http://www.adobe.com/go/getflashplayer",c=typeof jQuery=="function",d=/(\d+)[^\d]+(\d+)[^\d]*(\d*)/,e={width:"100%",height:"100%",id:"_"+(""+Math.random()).slice(9),allowfullscreen:!0,allowscriptaccess:"always",quality:"high",version:[3,0],onFail:null,expressInstall:null,w3c:!1,cachebusting:!1};window.attachEvent&&window.attachEvent("onbeforeunload",function(){__flash_unloadHandler=function(){},__flash_savedUnloadHandler=function(){}});function f(a,b){if(b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}function g(a,b){var c=[];for(var d in a)a.hasOwnProperty(d)&&(c[d]=b(a[d]));return c}window.flashembed=function(a,b,c){typeof a=="string"&&(a=document.getElementById(a.replace("#","")));if(a){typeof b=="string"&&(b={src:b});return new j(a,f(f({},e),b),c)}};var h=f(window.flashembed,{conf:e,getVersion:function(){var a,b;try{b=navigator.plugins["Shockwave Flash"].description.slice(16)}catch(c){try{a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"),b=a&&a.GetVariable("$version")}catch(e){try{a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"),b=a&&a.GetVariable("$version")}catch(f){}}}b=d.exec(b);return b?[b[1],b[3]]:[0,0]},asString:function(a){if(a===null||a===undefined)return null;var b=typeof a;b=="object"&&a.push&&(b="array");switch(b){case"string":a=a.replace(new RegExp("([\"\\\\])","g"),"\\$1"),a=a.replace(/^\s?(\d+\.?\d+)%/,"$1pct");return"\""+a+"\"";case"array":return"["+g(a,function(a){return h.asString(a)}).join(",")+"]";case"function":return"\"function()\"";case"object":var c=[];for(var d in a)a.hasOwnProperty(d)&&c.push("\""+d+"\":"+h.asString(a[d]));return"{"+c.join(",")+"}"}return String(a).replace(/\s/g," ").replace(/\'/g,"\"")},getHTML:function(b,c){b=f({},b);var d="<object width=\""+b.width+"\" height=\""+b.height+"\" id=\""+b.id+"\" name=\""+b.id+"\"";b.cachebusting&&(b.src+=(b.src.indexOf("?")!=-1?"&":"?")+Math.random()),b.w3c||!a?d+=" data=\""+b.src+"\" type=\"application/x-shockwave-flash\"":d+=" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"",d+=">";if(b.w3c||a)d+="<param name=\"movie\" value=\""+b.src+"\" />";b.width=b.height=b.id=b.w3c=b.src=null,b.onFail=b.version=b.expressInstall=null;for(var e in b)b[e]&&(d+="<param name=\""+e+"\" value=\""+b[e]+"\" />");var g="";if(c){for(var i in c)if(c[i]){var j=c[i];g+=i+"="+(/function|object/.test(typeof j)?h.asString(j):j)+"&"}g=g.slice(0,-1),d+="<param name=\"flashvars\" value='"+g+"' />"}d+="</object>";return d},isSupported:function(a){return i[0]>a[0]||i[0]==a[0]&&i[1]>=a[1]}}),i=h.getVersion();function j(c,d,e){if(h.isSupported(d.version))c.innerHTML=h.getHTML(d,e);else if(d.expressInstall&&h.isSupported([6,65]))c.innerHTML=h.getHTML(f(d,{src:d.expressInstall}),{MMredirectURL:location.href,MMplayerType:"PlugIn",MMdoctitle:document.title});else{c.innerHTML.replace(/\s/g,"")||(c.innerHTML="<h2>Flash version "+d.version+" or greater is required</h2><h3>"+(i[0]>0?"Your version is "+i:"You have no flash plugin installed")+"</h3>"+(c.tagName=="A"?"<p>Click here to download latest version</p>":"<p>Download latest version from <a href='"+b+"'>here</a></p>"),c.tagName=="A"&&(c.onclick=function(){location.href=b}));if(d.onFail){var g=d.onFail.call(this);typeof g=="string"&&(c.innerHTML=g)}}a&&(window[d.id]=document.getElementById(d.id)),f(this,{getRoot:function(){return c},getOptions:function(){return d},getConf:function(){return e},getApi:function(){return c.firstChild}})}c&&(jQuery.tools=jQuery.tools||{version:"v1.2.5"},jQuery.tools.flashembed={conf:e},jQuery.fn.flashembed=function(a,b){return this.each(function(){$(this).data("flashembed",flashembed(this,a,b))})})})();
46
+ (function(a){var b,c,d,e;a.tools=a.tools||{version:"v1.2.5"},a.tools.history={init:function(g){e||(a.browser.msie&&a.browser.version<"8"?c||(c=a("<iframe/>").attr("src","javascript:false;").hide().get(0),a("body").append(c),setInterval(function(){var d=c.contentWindow.document,e=d.location.hash;b!==e&&a.event.trigger("hash",e)},100),f(location.hash||"#")):setInterval(function(){var c=location.hash;c!==b&&a.event.trigger("hash",c)},100),d=d?d.add(g):g,g.click(function(b){var d=a(this).attr("href");c&&f(d);if(d.slice(0,1)!="#"){location.href="#"+d;return b.preventDefault()}}),e=!0)}};function f(a){if(a){var b=c.contentWindow.document;b.open().close(),b.location.hash=a}}a(window).bind("hash",function(c,e){e?d.filter(function(){var b=a(this).attr("href");return b==e||b==e.replace("#","")}).trigger("history",[e]):d.eq(0).trigger("history",[e]),b=e}),a.fn.history=function(b){a.tools.history.init(this);return this.bind("history",b)}})(jQuery);
47
+ (function(a){a.fn.mousewheel=function(a){return this[a?"bind":"trigger"]("wheel",a)},a.event.special.wheel={setup:function(){a.event.add(this,b,c,{})},teardown:function(){a.event.remove(this,b,c)}};var b=a.browser.mozilla?"DOMMouseScroll"+(a.browser.version<"1.9"?" mousemove":""):"mousewheel";function c(b){switch(b.type){case"mousemove":return a.extend(b.data,{clientX:b.clientX,clientY:b.clientY,pageX:b.pageX,pageY:b.pageY});case"DOMMouseScroll":a.extend(b,b.data),b.delta=-b.detail/3;break;case"mousewheel":b.delta=b.wheelDelta/120}b.type="wheel";return a.event.handle.call(this,b,b.delta)}})(jQuery);
48
+ (function(a){a.tools=a.tools||{version:"v1.2.5"},a.tools.tooltip={conf:{effect:"toggle",fadeOutSpeed:"fast",predelay:0,delay:30,opacity:1,tip:0,position:["top","center"],offset:[0,0],relative:!1,cancelDefault:!0,events:{def:"mouseenter,mouseleave",input:"focus,blur",widget:"focus mouseenter,blur mouseleave",tooltip:"mouseenter,mouseleave"},layout:"<div/>",tipClass:"tooltip"},addEffect:function(a,c,d){b[a]=[c,d]}};var b={toggle:[function(a){var b=this.getConf(),c=this.getTip(),d=b.opacity;d<1&&c.css({opacity:d}),c.show(),a.call()},function(a){this.getTip().hide(),a.call()}],fade:[function(a){var b=this.getConf();this.getTip().fadeTo(b.fadeInSpeed,b.opacity,a)},function(a){this.getTip().fadeOut(this.getConf().fadeOutSpeed,a)}]};function c(b,c,d){var e=d.relative?b.position().top:b.offset().top,f=d.relative?b.position().left:b.offset().left,g=d.position[0];e-=c.outerHeight()-d.offset[0],f+=b.outerWidth()+d.offset[1],/iPad/i.test(navigator.userAgent)&&(e-=a(window).scrollTop());var h=c.outerHeight()+b.outerHeight();g=="center"&&(e+=h/2),g=="bottom"&&(e+=h),g=d.position[1];var i=c.outerWidth()+b.outerWidth();g=="center"&&(f-=i/2),g=="left"&&(f-=i);return{top:e,left:f}}function d(d,e){var f=this,g=d.add(f),h,i=0,j=0,k=d.attr("title"),l=d.attr("data-tooltip"),m=b[e.effect],n,o=d.is(":input"),p=o&&d.is(":checkbox, :radio, select, :button, :submit"),q=d.attr("type"),r=e.events[q]||e.events[o?p?"widget":"input":"def"];if(!m)throw"Nonexistent effect \""+e.effect+"\"";r=r.split(/,\s*/);if(r.length!=2)throw"Tooltip: bad events configuration for "+q;d.bind(r[0],function(a){clearTimeout(i),e.predelay?j=setTimeout(function(){f.show(a)},e.predelay):f.show(a)}).bind(r[1],function(a){clearTimeout(j),e.delay?i=setTimeout(function(){f.hide(a)},e.delay):f.hide(a)}),k&&e.cancelDefault&&(d.removeAttr("title"),d.data("title",k)),a.extend(f,{show:function(b){if(!h){l?h=a(l):e.tip?h=a(e.tip).eq(0):k?h=a(e.layout).addClass(e.tipClass).appendTo(document.body).hide().append(k):(h=d.next(),h.length||(h=d.parent().next()));if(!h.length)throw"Cannot find tooltip for "+d}if(f.isShown())return f;h.stop(!0,!0);var o=c(d,h,e);e.tip&&h.html(d.data("title")),b=b||a.Event(),b.type="onBeforeShow",g.trigger(b,[o]);if(b.isDefaultPrevented())return f;o=c(d,h,e),h.css({position:"absolute",top:o.top,left:o.left}),n=!0,m[0].call(f,function(){b.type="onShow",n="full",g.trigger(b)});var p=e.events.tooltip.split(/,\s*/);h.data("__set")||(h.bind(p[0],function(){clearTimeout(i),clearTimeout(j)}),p[1]&&!d.is("input:not(:checkbox, :radio), textarea")&&h.bind(p[1],function(a){a.relatedTarget!=d[0]&&d.trigger(r[1].split(" ")[0])}),h.data("__set",!0));return f},hide:function(c){if(!h||!f.isShown())return f;c=c||a.Event(),c.type="onBeforeHide",g.trigger(c);if(!c.isDefaultPrevented()){n=!1,b[e.effect][1].call(f,function(){c.type="onHide",g.trigger(c)});return f}},isShown:function(a){return a?n=="full":n},getConf:function(){return e},getTip:function(){return h},getTrigger:function(){return d}}),a.each("onHide,onBeforeShow,onShow,onBeforeHide".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}})}a.fn.tooltip=function(b){var c=this.data("tooltip");if(c)return c;b=a.extend(!0,{},a.tools.tooltip.conf,b),typeof b.position=="string"&&(b.position=b.position.split(/,?\s/)),this.each(function(){c=new d(a(this),b),a(this).data("tooltip",c)});return b.api?c:this}})(jQuery);
49
+ (function(a){var b=a.tools.tooltip;b.dynamic={conf:{classNames:"top right bottom left"}};function c(b){var c=a(window),d=c.width()+c.scrollLeft(),e=c.height()+c.scrollTop();return[b.offset().top<=c.scrollTop(),d<=b.offset().left+b.width(),e<=b.offset().top+b.height(),c.scrollLeft()>=b.offset().left]}function d(a){var b=a.length;while(b--)if(a[b])return!1;return!0}a.fn.dynamic=function(e){typeof e=="number"&&(e={speed:e}),e=a.extend({},b.dynamic.conf,e);var f=e.classNames.split(/\s/),g;this.each(function(){var b=a(this).tooltip().onBeforeShow(function(b,h){var i=this.getTip(),j=this.getConf();g||(g=[j.position[0],j.position[1],j.offset[0],j.offset[1],a.extend({},j)]),a.extend(j,g[4]),j.position=[g[0],g[1]],j.offset=[g[2],g[3]],i.css({visibility:"hidden",position:"absolute",top:h.top,left:h.left}).show();var k=c(i);if(!d(k)){k[2]&&(a.extend(j,e.top),j.position[0]="top",i.addClass(f[0])),k[3]&&(a.extend(j,e.right),j.position[1]="right",i.addClass(f[1])),k[0]&&(a.extend(j,e.bottom),j.position[0]="bottom",i.addClass(f[2])),k[1]&&(a.extend(j,e.left),j.position[1]="left",i.addClass(f[3]));if(k[0]||k[2])j.offset[0]*=-1;if(k[1]||k[3])j.offset[1]*=-1}i.css({visibility:"visible"}).hide()});b.onBeforeShow(function(){var a=this.getConf(),b=this.getTip();setTimeout(function(){a.position=[g[0],g[1]],a.offset=[g[2],g[3]]},0)}),b.onHide(function(){var a=this.getTip();a.removeClass(e.classNames)}),ret=b});return e.api?ret:this}})(jQuery);
50
+ (function(a){var b=a.tools.tooltip;a.extend(b.conf,{direction:"up",bounce:!1,slideOffset:10,slideInSpeed:200,slideOutSpeed:200,slideFade:!a.browser.msie});var c={up:["-","top"],down:["+","top"],left:["-","left"],right:["+","left"]};b.addEffect("slide",function(a){var b=this.getConf(),d=this.getTip(),e=b.slideFade?{opacity:b.opacity}:{},f=c[b.direction]||c.up;e[f[1]]=f[0]+"="+b.slideOffset,b.slideFade&&d.css({opacity:0}),d.show().animate(e,b.slideInSpeed,a)},function(b){var d=this.getConf(),e=d.slideOffset,f=d.slideFade?{opacity:0}:{},g=c[d.direction]||c.up,h=""+g[0];d.bounce&&(h=h=="+"?"-":"+"),f[g[1]]=h+"="+e,this.getTip().animate(f,d.slideOutSpeed,function(){a(this).hide(),b.call()})})})(jQuery);
51
+ (function(a){a.tools=a.tools||{version:"v1.2.5"};var b=/\[type=([a-z]+)\]/,c=/^-?[0-9]*(\.[0-9]+)?$/,d=a.tools.dateinput,e=/^([a-z0-9_\.\-\+]+)@([\da-z\.\-]+)\.([a-z\.]{2,6})$/i,f=/^(https?:\/\/)?[\da-z\.\-]+\.[a-z\.]{2,6}[#&+_\?\/\w \.\-=]*$/i,g;g=a.tools.validator={conf:{grouped:!1,effect:"default",errorClass:"invalid",inputEvent:null,errorInputEvent:"keyup",formEvent:"submit",lang:"en",message:"<div/>",messageAttr:"data-message",messageClass:"error",offset:[0,0],position:"center right",singleError:!1,speed:"normal"},messages:{"*":{en:"Please correct this value"}},localize:function(b,c){a.each(c,function(a,c){g.messages[a]=g.messages[a]||{},g.messages[a][b]=c})},localizeFn:function(b,c){g.messages[b]=g.messages[b]||{},a.extend(g.messages[b],c)},fn:function(c,d,e){a.isFunction(d)?e=d:(typeof d=="string"&&(d={en:d}),this.messages[c.key||c]=d);var f=b.exec(c);f&&(c=i(f[1])),j.push([c,e])},addEffect:function(a,b,c){k[a]=[b,c]}};function h(b,c,d){var e=b.offset().top,f=b.offset().left,g=d.position.split(/,?\s+/),h=g[0],i=g[1];e-=c.outerHeight()-d.offset[0],f+=b.outerWidth()+d.offset[1],/iPad/i.test(navigator.userAgent)&&(e-=a(window).scrollTop());var j=c.outerHeight()+b.outerHeight();h=="center"&&(e+=j/2),h=="bottom"&&(e+=j);var k=b.outerWidth();i=="center"&&(f-=(k+c.outerWidth())/2),i=="left"&&(f-=k);return{top:e,left:f}}function i(a){function b(){return this.getAttribute("type")==a}b.key="[type="+a+"]";return b}var j=[],k={"default":[function(b){var c=this.getConf();a.each(b,function(b,d){var e=d.input;e.addClass(c.errorClass);var f=e.data("msg.el");f||(f=a(c.message).addClass(c.messageClass).appendTo(document.body),e.data("msg.el",f)),f.css({visibility:"hidden"}).find("p").remove(),a.each(d.messages,function(b,c){a("<p/>").html(c).appendTo(f)}),f.outerWidth()==f.parent().width()&&f.add(f.find("p")).css({display:"inline"});var g=h(e,f,c);f.css({visibility:"visible",position:"absolute",top:g.top,left:g.left}).fadeIn(c.speed)})},function(b){var c=this.getConf();b.removeClass(c.errorClass).each(function(){var b=a(this).data("msg.el");b&&b.css({visibility:"hidden"})})}]};a.each("email,url,number".split(","),function(b,c){a.expr[":"][c]=function(a){return a.getAttribute("type")===c}}),a.fn.oninvalid=function(a){return this[a?"bind":"trigger"]("OI",a)},g.fn(":email","Please enter a valid email address",function(a,b){return!b||e.test(b)}),g.fn(":url","Please enter a valid URL",function(a,b){return!b||f.test(b)}),g.fn(":number","Please enter a numeric value.",function(a,b){return c.test(b)}),g.fn("[max]","Please enter a value smaller than $1",function(a,b){if(b===""||d&&a.is(":date"))return!0;var c=a.attr("max");return parseFloat(b)<=parseFloat(c)?!0:[c]}),g.fn("[min]","Please enter a value larger than $1",function(a,b){if(b===""||d&&a.is(":date"))return!0;var c=a.attr("min");return parseFloat(b)>=parseFloat(c)?!0:[c]}),g.fn("[required]","Please complete this mandatory field.",function(a,b){if(a.is(":checkbox"))return a.is(":checked");return b}),g.fn("[pattern]",function(a){var b=new RegExp("^"+a.attr("pattern")+"$");return b.test(a.val())});function l(b,c,e){var f=this,i=c.add(f);b=b.not(":button, :image, :reset, :submit");function l(b,c,d){if(e.grouped||!b.length){var f;if(d===!1||a.isArray(d)){f=g.messages[c.key||c]||g.messages["*"],f=f[e.lang]||g.messages["*"].en;var h=f.match(/\$\d/g);h&&a.isArray(d)&&a.each(h,function(a){f=f.replace(this,d[a])})}else f=d[e.lang]||d;b.push(f)}}a.extend(f,{getConf:function(){return e},getForm:function(){return c},getInputs:function(){return b},reflow:function(){b.each(function(){var b=a(this),c=b.data("msg.el");if(c){var d=h(b,c,e);c.css({top:d.top,left:d.left})}});return f},invalidate:function(c,d){if(!d){var g=[];a.each(c,function(a,c){var d=b.filter("[name='"+a+"']");d.length&&(d.trigger("OI",[c]),g.push({input:d,messages:[c]}))}),c=g,d=a.Event()}d.type="onFail",i.trigger(d,[c]),d.isDefaultPrevented()||k[e.effect][0].call(f,c,d);return f},reset:function(c){c=c||b,c.removeClass(e.errorClass).each(function(){var b=a(this).data("msg.el");b&&(b.remove(),a(this).data("msg.el",null))}).unbind(e.errorInputEvent||"");return f},destroy:function(){c.unbind(e.formEvent+".V").unbind("reset.V"),b.unbind(e.inputEvent+".V").unbind("change.V");return f.reset()},checkValidity:function(c,g){c=c||b,c=c.not(":disabled");if(!c.length)return!0;g=g||a.Event(),g.type="onBeforeValidate",i.trigger(g,[c]);if(g.isDefaultPrevented())return g.result;var h=[];c.not(":radio:not(:checked)").each(function(){var b=[],c=a(this).data("messages",b),k=d&&c.is(":date")?"onHide.v":e.errorInputEvent+".v";c.unbind(k),a.each(j,function(){var a=this,d=a[0];if(c.filter(d).length){var h=a[1].call(f,c,c.val());if(h!==!0){g.type="onBeforeFail",i.trigger(g,[c,d]);if(g.isDefaultPrevented())return!1;var j=c.attr(e.messageAttr);if(j){b=[j];return!1}l(b,d,h)}}}),b.length&&(h.push({input:c,messages:b}),c.trigger("OI",[b]),e.errorInputEvent&&c.bind(k,function(a){f.checkValidity(c,a)}));if(e.singleError&&h.length)return!1});var m=k[e.effect];if(!m)throw"Validator: cannot find effect \""+e.effect+"\"";if(h.length){f.invalidate(h,g);return!1}m[1].call(f,c,g),g.type="onSuccess",i.trigger(g,[c]),c.unbind(e.errorInputEvent+".v");return!0}}),a.each("onBeforeValidate,onBeforeFail,onFail,onSuccess".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}}),e.formEvent&&c.bind(e.formEvent+".V",function(a){if(!f.checkValidity(null,a))return a.preventDefault()}),c.bind("reset.V",function(){f.reset()}),b[0]&&b[0].validity&&b.each(function(){this.oninvalid=function(){return!1}}),c[0]&&(c[0].checkValidity=f.checkValidity),e.inputEvent&&b.bind(e.inputEvent+".V",function(b){f.checkValidity(a(this),b)}),b.filter(":checkbox, select").filter("[required]").bind("change.V",function(b){var c=a(this);(this.checked||c.is("select")&&a(this).val())&&k[e.effect][1].call(f,c,b)});var m=b.filter(":radio").change(function(a){f.checkValidity(m,a)});a(window).resize(function(){f.reflow()})}a.fn.validator=function(b){var c=this.data("validator");c&&(c.destroy(),this.removeData("validator")),b=a.extend(!0,{},g.conf,b);if(this.is("form"))return this.each(function(){var d=a(this);c=new l(d.find(":input"),d,b),d.data("validator",c)});c=new l(this,this.eq(0).closest("form"),b);return this.data("validator",c)}})(jQuery);
js/jquery.validationEngine-en.js ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($){
2
+ $.fn.validationEngineLanguage = function(){
3
+ };
4
+ $.validationEngineLanguage = {
5
+ newLang: function(){
6
+ $.validationEngineLanguage.allRules = {
7
+ "required": { // Add your regex rules here, you can take telephone as an example
8
+ "regex": "none",
9
+ "alertText": "* This field is required",
10
+ "alertTextCheckboxMultiple": "* Please select an option",
11
+ "alertTextCheckboxe": "* This checkbox is required",
12
+ "alertTextDateRange": "* Both date range fields are required"
13
+ },
14
+ "requiredInFunction": {
15
+ "func": function(field, rules, i, options){
16
+ return (field.val() == "test") ? true : false;
17
+ },
18
+ "alertText": "* Field must equal test"
19
+ },
20
+ "dateRange": {
21
+ "regex": "none",
22
+ "alertText": "* Invalid ",
23
+ "alertText2": "Date Range"
24
+ },
25
+ "dateTimeRange": {
26
+ "regex": "none",
27
+ "alertText": "* Invalid ",
28
+ "alertText2": "Date Time Range"
29
+ },
30
+ "minSize": {
31
+ "regex": "none",
32
+ "alertText": "* Minimum ",
33
+ "alertText2": " characters required"
34
+ },
35
+ "maxSize": {
36
+ "regex": "none",
37
+ "alertText": "* Maximum ",
38
+ "alertText2": " characters allowed"
39
+ },
40
+ "groupRequired": {
41
+ "regex": "none",
42
+ "alertText": "* You must fill one of the following fields"
43
+ },
44
+ "min": {
45
+ "regex": "none",
46
+ "alertText": "* Minimum value is "
47
+ },
48
+ "max": {
49
+ "regex": "none",
50
+ "alertText": "* Maximum value is "
51
+ },
52
+ "past": {
53
+ "regex": "none",
54
+ "alertText": "* Date prior to "
55
+ },
56
+ "future": {
57
+ "regex": "none",
58
+ "alertText": "* Date past "
59
+ },
60
+ "maxCheckbox": {
61
+ "regex": "none",
62
+ "alertText": "* Maximum ",
63
+ "alertText2": " options allowed"
64
+ },
65
+ "minCheckbox": {
66
+ "regex": "none",
67
+ "alertText": "* Please select ",
68
+ "alertText2": " options"
69
+ },
70
+ "equals": {
71
+ "regex": "none",
72
+ "alertText": "* Fields do not match"
73
+ },
74
+ "creditCard": {
75
+ "regex": "none",
76
+ "alertText": "* Invalid credit card number"
77
+ },
78
+ "phone": {
79
+ // credit: jquery.h5validate.js / orefalo
80
+ "regex": /^([\+][0-9]{1,3}[\ \.\-])?([\(]{1}[0-9]{2,6}[\)])?([0-9\ \.\-\/]{3,20})((x|ext|extension)[\ ]?[0-9]{1,4})?$/,
81
+ "alertText": "* Invalid phone number"
82
+ },
83
+ "email": {
84
+ // HTML5 compatible email regex ( http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html# e-mail-state-%28type=email%29 )
85
+ "regex": /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
86
+ "alertText": "* Invalid email address"
87
+ },
88
+ "SWPMUserName": {
89
+ "regex": /^[a-zA-Z0-9!@#$%&\'*+\/=?^_`{|}~\.-]+$/,
90
+ "alertText": "* Invalid User Name"
91
+ },
92
+ "integer": {
93
+ "regex": /^[\-\+]?\d+$/,
94
+ "alertText": "* Not a valid integer"
95
+ },
96
+ "number": {
97
+ // Number, including positive, negative, and floating decimal. credit: orefalo
98
+ "regex": /^[\-\+]?((([0-9]{1,3})([,][0-9]{3})*)|([0-9]+))?([\.]([0-9]+))?$/,
99
+ "alertText": "* Invalid floating decimal number"
100
+ },
101
+ "date": {
102
+ // Check if date is valid by leap year
103
+ "func": function (field) {
104
+ var pattern = new RegExp(/^(\d{4})[\/\-\.](0?[1-9]|1[012])[\/\-\.](0?[1-9]|[12][0-9]|3[01])$/);
105
+ var match = pattern.exec(field.val());
106
+ if (match == null)
107
+ return false;
108
+
109
+ var year = match[1];
110
+ var month = match[2]*1;
111
+ var day = match[3]*1;
112
+ var date = new Date(year, month - 1, day); // because months starts from 0.
113
+
114
+ return (date.getFullYear() == year && date.getMonth() == (month - 1) && date.getDate() == day);
115
+ },
116
+ "alertText": "* Invalid date, must be in YYYY-MM-DD format"
117
+ },
118
+ "ipv4": {
119
+ "regex": /^((([01]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))[.]){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))$/,
120
+ "alertText": "* Invalid IP address"
121
+ },
122
+ "url": {
123
+ "regex": /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i,
124
+ "alertText": "* Invalid URL"
125
+ },
126
+ "onlyNumberSp": {
127
+ "regex": /^[0-9\ ]+$/,
128
+ "alertText": "* Numbers only"
129
+ },
130
+ "onlyLetterSp": {
131
+ "regex": /^[a-zA-Z\ \']+$/,
132
+ "alertText": "* Letters only"
133
+ },
134
+ "onlyLetterNumber": {
135
+ "regex": /^[0-9a-zA-Z]+$/,
136
+ "alertText": "* No special characters allowed"
137
+ },
138
+ "onlyLetterNumberUnderscore": {
139
+ "regex": /^[0-9a-zA-Z_]+$/,
140
+ "alertText": "* Only number, character and underscore allowed"
141
+ },
142
+
143
+ // --- CUSTOM RULES -- Those are specific to the demos, they can be removed or changed to your likings
144
+ "ajaxUserCall": {
145
+ "url": "ajaxurl",
146
+ // you may want to pass extra data on the ajax call
147
+ "extraData": "&action=swpm_validate_user_name",
148
+ "alertTextOk": "* This username is available",
149
+ "alertText": "* This user is already taken",
150
+ "alertTextLoad": "* Validating, please wait"
151
+ },
152
+ "ajaxEmailCall": {
153
+ "url": "ajaxurl",
154
+ // you may want to pass extra data on the ajax call
155
+ "extraData": "&action=swpm_validate_email",
156
+ "alertText": "* This email is already taken",
157
+ "alertTextOk": "* This email is available",
158
+ "alertTextLoad": "* Validating, please wait"
159
+ },
160
+ "ajaxUserCallPhp": {
161
+ "url": "phpajax/ajaxValidateFieldUser.php",
162
+ // you may want to pass extra data on the ajax call
163
+ "extraData": "name=eric",
164
+ // if you provide an "alertTextOk", it will show as a green prompt when the field validates
165
+ "alertTextOk": "* This username is available",
166
+ "alertText": "* This user is already taken",
167
+ "alertTextLoad": "* Validating, please wait"
168
+ },
169
+ "ajaxNameCall": {
170
+ // remote json service location
171
+ "url": "ajaxValidateFieldName",
172
+ // error
173
+ "alertText": "* This name is already taken",
174
+ // if you provide an "alertTextOk", it will show as a green prompt when the field validates
175
+ "alertTextOk": "* This name is available",
176
+ // speaks by itself
177
+ "alertTextLoad": "* Validating, please wait"
178
+ },
179
+ "ajaxNameCallPhp": {
180
+ // remote json service location
181
+ "url": "phpajax/ajaxValidateFieldName.php",
182
+ // error
183
+ "alertText": "* This name is already taken",
184
+ // speaks by itself
185
+ "alertTextLoad": "* Validating, please wait"
186
+ },
187
+ "validate2fields": {
188
+ "alertText": "* Please input HELLO"
189
+ },
190
+ //tls warning:homegrown not fielded
191
+ "dateFormat":{
192
+ "regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$/,
193
+ "alertText": "* Invalid Date"
194
+ },
195
+ //tls warning:homegrown not fielded
196
+ "dateTimeFormat": {
197
+ "regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1}$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^((1[012]|0?[1-9]){1}\/(0?[1-9]|[12][0-9]|3[01]){1}\/\d{2,4}\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1})$/,
198
+ "alertText": "* Invalid Date or Date Format",
199
+ "alertText2": "Expected Format: ",
200
+ "alertText3": "mm/dd/yyyy hh:mm:ss AM|PM or ",
201
+ "alertText4": "yyyy-mm-dd hh:mm:ss AM|PM"
202
+ }
203
+ };
204
+
205
+ }
206
+ };
207
+
208
+ $.validationEngineLanguage.newLang();
209
+
210
+ })(jQuery);
js/jquery.validationEngine.js ADDED
@@ -0,0 +1,1194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Inline Form Validation Engine 2.1, jQuery plugin
3
+ *
4
+ * Copyright(c) 2010, Cedric Dugas
5
+ * http://www.position-absolute.com
6
+ *
7
+ * 2.0 Rewrite by Olivier Refalo
8
+ * http://www.crionics.com
9
+ *
10
+ * Form validation engine allowing custom regex rules to be added.
11
+ * Licensed under the MIT License
12
+ */
13
+ (function($) {
14
+
15
+ var methods = {
16
+
17
+ /**
18
+ * Kind of the constructor, called before any action
19
+ * @param {Map} user options
20
+ */
21
+ init: function(options) {
22
+ var form = this;
23
+ if (!form.data('jqv') || form.data('jqv') == null ) {
24
+ methods._saveOptions(form, options);
25
+
26
+ // bind all formError elements to close on click
27
+ $(".formError").live("click", function() {
28
+ $(this).fadeOut(150, function() {
29
+
30
+ // remove prompt once invisible
31
+ $(this).remove();
32
+ });
33
+ });
34
+ }
35
+ },
36
+ /**
37
+ * Attachs jQuery.validationEngine to form.submit and field.blur events
38
+ * Takes an optional params: a list of options
39
+ * ie. jQuery("#formID1").validationEngine('attach', {promptPosition : "centerRight"});
40
+ */
41
+ attach: function(userOptions) {
42
+ var form = this;
43
+ var options;
44
+
45
+ if(userOptions)
46
+ options = methods._saveOptions(form, userOptions);
47
+ else
48
+ options = form.data('jqv');
49
+
50
+ if (!options.binded) {
51
+ if (options.bindMethod == "bind"){
52
+ // bind fields
53
+ form.find("[class*=validate]:not([type=checkbox])").bind(options.validationEventTrigger, methods._onFieldEvent);
54
+ form.find("[class*=validate][type=checkbox]").bind("click", methods._onFieldEvent);
55
+
56
+ // bind form.submit
57
+ form.bind("submit", methods._onSubmitEvent);
58
+ } else if (options.bindMethod == "live") {
59
+ // bind fields with LIVE (for persistant state)
60
+ form.find("[class*=validate]:not([type=checkbox])").live(options.validationEventTrigger, methods._onFieldEvent);
61
+ form.find("[class*=validate][type=checkbox]").live("click", methods._onFieldEvent);
62
+
63
+ // bind form.submit
64
+ form.live("submit", methods._onSubmitEvent);
65
+ }
66
+
67
+ options.binded = true;
68
+ }
69
+
70
+ },
71
+ /**
72
+ * Unregisters any bindings that may point to jQuery.validaitonEngine
73
+ */
74
+ detach: function() {
75
+ var form = this;
76
+ var options = form.data('jqv');
77
+ if (options.binded) {
78
+
79
+ // unbind fields
80
+ form.find("[class*=validate]").not("[type=checkbox]").unbind(options.validationEventTrigger, methods._onFieldEvent);
81
+ form.find("[class*=validate][type=checkbox]").unbind("click", methods._onFieldEvent);
82
+ // unbind form.submit
83
+ form.unbind("submit", methods.onAjaxFormComplete);
84
+
85
+
86
+ // unbind live fields (kill)
87
+ form.find("[class*=validate]").not("[type=checkbox]").die(options.validationEventTrigger, methods._onFieldEvent);
88
+ form.find("[class*=validate][type=checkbox]").die("click", methods._onFieldEvent);
89
+ // unbind form.submit
90
+ form.die("submit", methods.onAjaxFormComplete);
91
+
92
+ form.removeData('jqv');
93
+ }
94
+ },
95
+ /**
96
+ * Validates the form fields, shows prompts accordingly.
97
+ * Note: There is no ajax form validation with this method, only field ajax validation are evaluated
98
+ *
99
+ * @return true if the form validates, false if it fails
100
+ */
101
+ validate: function() {
102
+ return methods._validateFields(this);
103
+ },
104
+ /**
105
+ * Validates one field, shows prompt accordingly.
106
+ * Note: There is no ajax form validation with this method, only field ajax validation are evaluated
107
+ *
108
+ * @return true if the form validates, false if it fails
109
+ */
110
+ validateField: function(el) {
111
+ var options = $(this).data('jqv');
112
+ return methods._validateField($(el), options);
113
+ },
114
+ /**
115
+ * Validates the form fields, shows prompts accordingly.
116
+ * Note: this methods performs fields and form ajax validations(if setup)
117
+ *
118
+ * @return true if the form validates, false if it fails, undefined if ajax is used for form validation
119
+ */
120
+ validateform: function() {
121
+ return methods._onSubmitEvent.call(this);
122
+ },
123
+ /**
124
+ * Displays a prompt on a element.
125
+ * Note that the element needs an id!
126
+ *
127
+ * @param {String} promptText html text to display type
128
+ * @param {String} type the type of bubble: 'pass' (green), 'load' (black) anything else (red)
129
+ * @param {String} possible values topLeft, topRight, bottomLeft, centerRight, bottomRight
130
+ */
131
+ showPrompt: function(promptText, type, promptPosition, showArrow) {
132
+
133
+ var form = this.closest('form');
134
+ var options = form.data('jqv');
135
+ // No option, take default one
136
+ if(!options) options = methods._saveOptions(this, options);
137
+ if(promptPosition)
138
+ options.promptPosition=promptPosition;
139
+ options.showArrow = showArrow==true;
140
+
141
+ methods._showPrompt(this, promptText, type, false, options);
142
+ },
143
+ /**
144
+ * Closes all error prompts on the page
145
+ */
146
+ hidePrompt: function() {
147
+ var promptClass = "."+ methods._getClassName($(this).attr("id")) + "formError"
148
+ $(promptClass).fadeTo("fast", 0.3, function() {
149
+ $(this).remove();
150
+ });
151
+ },
152
+ /**
153
+ * Closes form error prompts, CAN be invidual
154
+ */
155
+ hide: function() {
156
+ if($(this).is("form")){
157
+ var closingtag = "parentForm"+$(this).attr('id');
158
+ }else{
159
+
160
+ var closingtag = $(this).attr('id') +"formError"
161
+ }
162
+ $('.'+closingtag).fadeTo("fast", 0.3, function() {
163
+ $(this).remove();
164
+ });
165
+ },
166
+ /**
167
+ * Closes all error prompts on the page
168
+ */
169
+ hideAll: function() {
170
+ $('.formError').fadeTo("fast", 0.3, function() {
171
+ $(this).remove();
172
+ });
173
+ },
174
+ /**
175
+ * Typically called when user exists a field using tab or a mouse click, triggers a field
176
+ * validation
177
+ */
178
+ _onFieldEvent: function() {
179
+ var field = $(this);
180
+ var form = field.closest('form');
181
+ var options = form.data('jqv');
182
+ // validate the current field
183
+ methods._validateField(field, options);
184
+ },
185
+ /**
186
+ * Called when the form is submited, shows prompts accordingly
187
+ *
188
+ * @param {jqObject}
189
+ * form
190
+ * @return false if form submission needs to be cancelled
191
+ */
192
+ _onSubmitEvent: function() {
193
+ var form = $(this);
194
+ var options = form.data('jqv');
195
+
196
+ // validate each field (- skip field ajax validation, no necessary since we will perform an ajax form validation)
197
+ var r=methods._validateFields(form, true);
198
+
199
+ if (r && options.ajaxFormValidation) {
200
+ methods._validateFormWithAjax(form, options);
201
+ return false;
202
+ }
203
+
204
+ if(options.onValidationComplete) {
205
+ options.onValidationComplete(form, r);
206
+ return false;
207
+ }
208
+ return r;
209
+ },
210
+
211
+ /**
212
+ * Return true if the ajax field validations passed so far
213
+ * @param {Object} options
214
+ * @return true, is all ajax validation passed so far (remember ajax is async)
215
+ */
216
+ _checkAjaxStatus: function(options) {
217
+ var status = true;
218
+ $.each(options.ajaxValidCache, function(key, value) {
219
+ if (!value) {
220
+ status = false;
221
+ // break the each
222
+ return false;
223
+ }
224
+ });
225
+ return status;
226
+ },
227
+ /**
228
+ * Validates form fields, shows prompts accordingly
229
+ *
230
+ * @param {jqObject}
231
+ * form
232
+ * @param {skipAjaxFieldValidation}
233
+ * boolean - when set to true, ajax field validation is skipped, typically used when the submit button is clicked
234
+ *
235
+ * @return true if form is valid, false if not, undefined if ajax form validation is done
236
+ */
237
+ _validateFields: function(form, skipAjaxValidation) {
238
+ var options = form.data('jqv');
239
+
240
+ // this variable is set to true if an error is found
241
+ var errorFound = false;
242
+
243
+ // Trigger hook, start validation
244
+ form.trigger("jqv.form.validating")
245
+ // first, evaluate status of non ajax fields
246
+ form.find('[class*=validate]').not(':hidden').each( function() {
247
+ var field = $(this);
248
+ errorFound |= methods._validateField(field, options, skipAjaxValidation);
249
+ });
250
+ // second, check to see if all ajax calls completed ok
251
+ // errorFound |= !methods._checkAjaxStatus(options);
252
+
253
+ // thrird, check status and scroll the container accordingly
254
+ form.trigger("jqv.form.result", [errorFound])
255
+
256
+ if (errorFound) {
257
+
258
+ if (options.scroll) {
259
+
260
+ // get the position of the first error, there should be at least one, no need to check this
261
+ //var destination = form.find(".formError:not('.greenPopup'):first").offset().top;
262
+
263
+ // look for the visually top prompt
264
+ var destination = Number.MAX_VALUE;
265
+
266
+ var lst = $(".formError:not('.greenPopup')");
267
+ for (var i = 0; i < lst.length; i++) {
268
+ var d = $(lst[i]).offset().top;
269
+ if (d < destination)
270
+ destination = d;
271
+ }
272
+
273
+ if (!options.isOverflown)
274
+ $("html:not(:animated),body:not(:animated)").animate({
275
+ scrollTop: destination
276
+ }, 1100);
277
+ else {
278
+ var overflowDIV = $(options.overflownDIV);
279
+ var scrollContainerScroll = overflowDIV.scrollTop();
280
+ var scrollContainerPos = -parseInt(overflowDIV.offset().top);
281
+
282
+ destination += scrollContainerScroll + scrollContainerPos - 5;
283
+ var scrollContainer = $(options.overflownDIV + ":not(:animated)");
284
+
285
+ scrollContainer.animate({
286
+ scrollTop: destination
287
+ }, 1100);
288
+ }
289
+ }
290
+ return false;
291
+ }
292
+ return true;
293
+ },
294
+ /**
295
+ * This method is called to perform an ajax form validation.
296
+ * During this process all the (field, value) pairs are sent to the server which returns a list of invalid fields or true
297
+ *
298
+ * @param {jqObject} form
299
+ * @param {Map} options
300
+ */
301
+ _validateFormWithAjax: function(form, options) {
302
+
303
+ var data = form.serialize();
304
+ var url = (options.ajaxFormValidationURL) ? options.ajaxFormValidationURL : form.attr("action");
305
+ $.ajax({
306
+ type: "GET",
307
+ url: url,
308
+ cache: false,
309
+ dataType: "json",
310
+ data: data,
311
+ form: form,
312
+ methods: methods,
313
+ options: options,
314
+ beforeSend: function() {
315
+ return options.onBeforeAjaxFormValidation(form, options);
316
+ },
317
+ error: function(data, transport) {
318
+ methods._ajaxError(data, transport);
319
+ },
320
+ success: function(json) {
321
+
322
+ if (json !== true) {
323
+
324
+ // getting to this case doesn't necessary means that the form is invalid
325
+ // the server may return green or closing prompt actions
326
+ // this flag helps figuring it out
327
+ var errorInForm=false;
328
+ for (var i = 0; i < json.length; i++) {
329
+ var value = json[i];
330
+
331
+ var errorFieldId = value[0];
332
+ var errorField = $($("#" + errorFieldId)[0]);
333
+
334
+ // make sure we found the element
335
+ if (errorField.length == 1) {
336
+
337
+ // promptText or selector
338
+ var msg = value[2];
339
+ // if the field is valid
340
+ if (value[1] == true) {
341
+
342
+ if (msg == "" || !msg){
343
+ // if for some reason, status==true and error="", just close the prompt
344
+ methods._closePrompt(errorField);
345
+ } else {
346
+ // the field is valid, but we are displaying a green prompt
347
+ if (options.allrules[msg]) {
348
+ var txt = options.allrules[msg].alertTextOk;
349
+ if (txt)
350
+ msg = txt;
351
+ }
352
+ methods._showPrompt(errorField, msg, "pass", false, options, true);
353
+ }
354
+
355
+ } else {
356
+ // the field is invalid, show the red error prompt
357
+ errorInForm|=true;
358
+ if (options.allrules[msg]) {
359
+ var txt = options.allrules[msg].alertText;
360
+ if (txt)
361
+ msg = txt;
362
+ }
363
+ methods._showPrompt(errorField, msg, "", false, options, true);
364
+ }
365
+ }
366
+ }
367
+ options.onAjaxFormComplete(!errorInForm, form, json, options);
368
+ } else
369
+ options.onAjaxFormComplete(true, form, "", options);
370
+ }
371
+ });
372
+
373
+ },
374
+ /**
375
+ * Validates field, shows prompts accordingly
376
+ *
377
+ * @param {jqObject}
378
+ * field
379
+ * @param {Array[String]}
380
+ * field's validation rules
381
+ * @param {Map}
382
+ * user options
383
+ * @return true if field is valid
384
+ */
385
+ _validateField: function(field, options, skipAjaxValidation) {
386
+ if (!field.attr("id"))
387
+ $.error("jQueryValidate: an ID attribute is required for this field: " + field.attr("name") + " class:" +
388
+ field.attr("class"));
389
+
390
+ var rulesParsing = field.attr('class');
391
+ var getRules = /validate\[(.*)\]/.exec(rulesParsing);
392
+ if (!getRules)
393
+ return false;
394
+ var str = getRules[1];
395
+ var rules = str.split(/\[|,|\]/);
396
+
397
+ // true if we ran the ajax validation, tells the logic to stop messing with prompts
398
+ var isAjaxValidator = false;
399
+ var fieldName = field.attr("name");
400
+ var promptText = "";
401
+ var required = false;
402
+ var equals = true;
403
+ options.isError = false;
404
+ options.showArrow = true;
405
+ optional = false;
406
+
407
+ for (var i = 0; i < rules.length; i++) {
408
+
409
+ var errorMsg = undefined;
410
+ switch (rules[i]) {
411
+
412
+ case "optional":
413
+ optional = true;
414
+ break;
415
+ case "required":
416
+ required = true;
417
+ errorMsg = methods._required(field, rules, i, options);
418
+ break;
419
+ case "custom":
420
+ errorMsg = methods._customRegex(field, rules, i, options);
421
+ break;
422
+ case "ajax":
423
+ // ajax has its own prompts handling technique
424
+ if(!skipAjaxValidation){
425
+ methods._ajax(field, rules, i, options);
426
+ isAjaxValidator = true;
427
+ }
428
+ break;
429
+ case "minSize":
430
+ errorMsg = methods._minSize(field, rules, i, options);
431
+ break;
432
+ case "maxSize":
433
+ errorMsg = methods._maxSize(field, rules, i, options);
434
+ break;
435
+ case "min":
436
+ errorMsg = methods._min(field, rules, i, options);
437
+ break;
438
+ case "max":
439
+ errorMsg = methods._max(field, rules, i, options);
440
+ break;
441
+ case "past":
442
+ errorMsg = methods._past(field, rules, i, options);
443
+ break;
444
+ case "future":
445
+ errorMsg = methods._future(field, rules, i, options);
446
+ break;
447
+ case "maxCheckbox":
448
+ errorMsg = methods._maxCheckbox(field, rules, i, options);
449
+ field = $($("input[name='" + fieldName + "']"));
450
+ break;
451
+ case "minCheckbox":
452
+ errorMsg = methods._minCheckbox(field, rules, i, options);
453
+ field = $($("input[name='" + fieldName + "']"));
454
+ break;
455
+ case "equals":
456
+ errorMsg = methods._equals(field, rules, i, options);
457
+ if (errorMsg !== undefined) equals = false;
458
+ break;
459
+ case "funcCall":
460
+ errorMsg = methods._funcCall(field, rules, i, options);
461
+ break;
462
+
463
+ default:
464
+ //$.error("jQueryValidator rule not found"+rules[i]);
465
+ }
466
+
467
+ if (errorMsg !== undefined) {
468
+ promptText += errorMsg + "<br/>";
469
+ options.isError = true;
470
+
471
+ }
472
+
473
+ }
474
+ // If the rules required is not added, an empty field is not validated
475
+ if(!required){
476
+ if(field.val() == "") options.isError = false;
477
+ }
478
+ // Hack for radio/checkbox group button, the validation go into the
479
+ // first radio/checkbox of the group
480
+ var fieldType = field.attr("type");
481
+
482
+ if ((fieldType == "radio" || fieldType == "checkbox") && $("input[name='" + fieldName + "']").size() > 1) {
483
+ field = $($("input[name='" + fieldName + "'][type!=hidden]:first"));
484
+ options.showArrow = false;
485
+ }
486
+
487
+ if (options.isError || !equals){
488
+
489
+ methods._showPrompt(field, promptText, "", false, options);
490
+ }else{
491
+ if (!isAjaxValidator) methods._closePrompt(field);
492
+ }
493
+ field.closest('form').trigger("jqv.field.error", [field, options.isError, promptText])
494
+ return options.isError || (!equals);
495
+ },
496
+ /**
497
+ * Required validation
498
+ *
499
+ * @param {jqObject} field
500
+ * @param {Array[String]} rules
501
+ * @param {int} i rules index
502
+ * @param {Map}
503
+ * user options
504
+ * @return an error string if validation failed
505
+ */
506
+ _required: function(field, rules, i, options) {
507
+ switch (field.attr("type")) {
508
+ case "text":
509
+ case "password":
510
+ case "textarea":
511
+ case "file":
512
+ default:
513
+ if (!field.val())
514
+ return options.allrules[rules[i]].alertText;
515
+ break;
516
+ case "radio":
517
+ case "checkbox":
518
+ var name = field.attr("name");
519
+ if ($("input[name='" + name + "']:checked").size() == 0) {
520
+
521
+ if ($("input[name='" + name + "']").size() == 1)
522
+ return options.allrules[rules[i]].alertTextCheckboxe;
523
+ else
524
+ return options.allrules[rules[i]].alertTextCheckboxMultiple;
525
+ }
526
+ break;
527
+ // required for <select>
528
+ case "select-one":
529
+ // added by paul@kinetek.net for select boxes, Thank you
530
+ if (!field.val())
531
+ return options.allrules[rules[i]].alertText;
532
+ break;
533
+ case "select-multiple":
534
+ // added by paul@kinetek.net for select boxes, Thank you
535
+ if (!field.find("option:selected").val())
536
+ return options.allrules[rules[i]].alertText;
537
+ break;
538
+ }
539
+ },
540
+ /**
541
+ * Validate Regex rules
542
+ *
543
+ * @param {jqObject} field
544
+ * @param {Array[String]} rules
545
+ * @param {int} i rules index
546
+ * @param {Map}
547
+ * user options
548
+ * @return an error string if validation failed
549
+ */
550
+ _customRegex: function(field, rules, i, options) {
551
+ var customRule = rules[i + 1];
552
+ var rule = options.allrules[customRule];
553
+ if(!rule) {
554
+ alert("jqv:custom rule not found "+customRule);
555
+ return;
556
+ }
557
+
558
+ var ex=rule.regex;
559
+ if(!ex) {
560
+ alert("jqv:custom regex not found "+customRule);
561
+ return;
562
+ }
563
+ var pattern = new RegExp(ex);
564
+
565
+ if (!pattern.test(field.attr('value')))
566
+ return options.allrules[customRule].alertText;
567
+ },
568
+ /**
569
+ * Validate custom function outside of the engine scope
570
+ *
571
+ * @param {jqObject} field
572
+ * @param {Array[String]} rules
573
+ * @param {int} i rules index
574
+ * @param {Map}
575
+ * user options
576
+ * @return an error string if validation failed
577
+ */
578
+ _funcCall: function(field, rules, i, options) {
579
+ var functionName = rules[i + 1];
580
+ var fn = window[functionName];
581
+ if (typeof(fn) == 'function')
582
+ return fn(field, rules, i, options);
583
+
584
+ },
585
+ /**
586
+ * Field match
587
+ *
588
+ * @param {jqObject} field
589
+ * @param {Array[String]} rules
590
+ * @param {int} i rules index
591
+ * @param {Map}
592
+ * user options
593
+ * @return an error string if validation failed
594
+ */
595
+ _equals: function(field, rules, i, options) {
596
+ var equalsField = rules[i + 1];
597
+
598
+ if (field.attr('value') != $("#" + equalsField).attr('value')){
599
+ field.css('border','1px solid red');
600
+ $("#" + equalsField).css('border', '1px solid red');
601
+ return options.allrules.equals.alertText;
602
+ }
603
+ else{
604
+ field.css('border','');
605
+ $("#" + equalsField).css('border', '');
606
+ }
607
+
608
+ },
609
+ /**
610
+ * Check the maximum size (in characters)
611
+ *
612
+ * @param {jqObject} field
613
+ * @param {Array[String]} rules
614
+ * @param {int} i rules index
615
+ * @param {Map}
616
+ * user options
617
+ * @return an error string if validation failed
618
+ */
619
+ _maxSize: function(field, rules, i, options) {
620
+ var max = rules[i + 1];
621
+ var len = field.attr('value').length;
622
+
623
+ if (len > max) {
624
+ var rule = options.allrules.maxSize;
625
+ return rule.alertText + max + rule.alertText2;
626
+ }
627
+ },
628
+ /**
629
+ * Check the minimum size (in characters)
630
+ *
631
+ * @param {jqObject} field
632
+ * @param {Array[String]} rules
633
+ * @param {int} i rules index
634
+ * @param {Map}
635
+ * user options
636
+ * @return an error string if validation failed
637
+ */
638
+ _minSize: function(field, rules, i, options) {
639
+ var min = rules[i + 1];
640
+ var len = field.attr('value').length;
641
+
642
+ if (len < min) {
643
+ var rule = options.allrules.minSize;
644
+ return rule.alertText + min + rule.alertText2;
645
+ }
646
+ },
647
+ /**
648
+ * Check number minimum value
649
+ *
650
+ * @param {jqObject} field
651
+ * @param {Array[String]} rules
652
+ * @param {int} i rules index
653
+ * @param {Map}
654
+ * user options
655
+ * @return an error string if validation failed
656
+ */
657
+ _min: function(field, rules, i, options) {
658
+ var min = parseFloat(rules[i + 1]);
659
+ var len = parseFloat(field.attr('value'));
660
+
661
+ if (len < min) {
662
+ var rule = options.allrules.min;
663
+ if (rule.alertText2) return rule.alertText + min + rule.alertText2;
664
+ return rule.alertText + min;
665
+ }
666
+ },
667
+ /**
668
+ * Check number maximum value
669
+ *
670
+ * @param {jqObject} field
671
+ * @param {Array[String]} rules
672
+ * @param {int} i rules index
673
+ * @param {Map}
674
+ * user options
675
+ * @return an error string if validation failed
676
+ */
677
+ _max: function(field, rules, i, options) {
678
+ var max = parseFloat(rules[i + 1]);
679
+ var len = parseFloat(field.attr('value'));
680
+
681
+ if (len >max ) {
682
+ var rule = options.allrules.max;
683
+ if (rule.alertText2) return rule.alertText + max + rule.alertText2;
684
+ //orefalo: to review, also do the translations
685
+ return rule.alertText + max;
686
+ }
687
+ },
688
+ /**
689
+ * Checks date is in the past
690
+ *
691
+ * @param {jqObject} field
692
+ * @param {Array[String]} rules
693
+ * @param {int} i rules index
694
+ * @param {Map}
695
+ * user options
696
+ * @return an error string if validation failed
697
+ */
698
+ _past: function(field, rules, i, options) {
699
+
700
+ var p=rules[i + 1];
701
+ var pdate = (p.toLowerCase() == "now")? new Date():methods._parseDate(p);
702
+ var vdate = methods._parseDate(field.attr('value'));
703
+
704
+ if (vdate > pdate ) {
705
+ var rule = options.allrules.past;
706
+ if (rule.alertText2) return rule.alertText + methods._dateToString(pdate) + rule.alertText2;
707
+ return rule.alertText + methods._dateToString(pdate);
708
+ }
709
+ },
710
+ /**
711
+ * Checks date is in the past
712
+ *
713
+ * @param {jqObject} field
714
+ * @param {Array[String]} rules
715
+ * @param {int} i rules index
716
+ * @param {Map}
717
+ * user options
718
+ * @return an error string if validation failed
719
+ */
720
+ _future: function(field, rules, i, options) {
721
+
722
+ var p=rules[i + 1];
723
+ var pdate = (p.toLowerCase() == "now")? new Date():methods._parseDate(p);
724
+ var vdate = methods._parseDate(field.attr('value'));
725
+
726
+ if (vdate < pdate ) {
727
+ var rule = options.allrules.future;
728
+ if (rule.alertText2) return rule.alertText + methods._dateToString(pdate) + rule.alertText2;
729
+ return rule.alertText + methods._dateToString(pdate);
730
+ }
731
+ },
732
+ /**
733
+ * Max number of checkbox selected
734
+ *
735
+ * @param {jqObject} field
736
+ * @param {Array[String]} rules
737
+ * @param {int} i rules index
738
+ * @param {Map}
739
+ * user options
740
+ * @return an error string if validation failed
741
+ */
742
+ _maxCheckbox: function(field, rules, i, options) {
743
+
744
+ var nbCheck = rules[i + 1];
745
+ var groupname = field.attr("name");
746
+ var groupSize = $("input[name='" + groupname + "']:checked").size();
747
+ if (groupSize > nbCheck) {
748
+ options.showArrow = false;
749
+ return options.allrules.maxCheckbox.alertText;
750
+ }
751
+ },
752
+ /**
753
+ * Min number of checkbox selected
754
+ *
755
+ * @param {jqObject} field
756
+ * @param {Array[String]} rules
757
+ * @param {int} i rules index
758
+ * @param {Map}
759
+ * user options
760
+ * @return an error string if validation failed
761
+ */
762
+ _minCheckbox: function(field, rules, i, options) {
763
+
764
+ var nbCheck = rules[i + 1];
765
+ var groupname = field.attr("name");
766
+ var groupSize = $("input[name='" + groupname + "']:checked").size();
767
+ if (groupSize < nbCheck) {
768
+ options.showArrow = false;
769
+ return options.allrules.minCheckbox.alertText + " " + nbCheck + " " +
770
+ options.allrules.minCheckbox.alertText2;
771
+ }
772
+ },
773
+ /**
774
+ * Ajax field validation
775
+ *
776
+ * @param {jqObject} field
777
+ * @param {Array[String]} rules
778
+ * @param {int} i rules index
779
+ * @param {Map}
780
+ * user options
781
+ * @return nothing! the ajax validator handles the prompts itself
782
+ */
783
+ _ajax: function(field, rules, i, options) {
784
+
785
+
786
+ var errorSelector = rules[i + 1];
787
+ var rule = options.allrules[errorSelector];
788
+ var extraData = rule.extraData;
789
+
790
+ if (!extraData)
791
+ extraData = "";
792
+
793
+ if (!options.isError) {
794
+ $.ajax({
795
+ type: "GET",
796
+ url: rule.url,
797
+ cache: false,
798
+ dataType: "json",
799
+ data: "fieldId=" + field.attr("id") + "&fieldValue=" + field.attr("value") + "&extraData=" + extraData,
800
+ field: field,
801
+ rule: rule,
802
+ methods: methods,
803
+ options: options,
804
+ beforeSend: function() {
805
+ // build the loading prompt
806
+ var loadingText = rule.alertTextLoad;
807
+ if (loadingText)
808
+ methods._showPrompt(field, loadingText, "load", true, options);
809
+ },
810
+ error: function(data, transport) {
811
+ methods._ajaxError(data, transport);
812
+ },
813
+ success: function(json) {
814
+
815
+ // asynchronously called on success, data is the json answer from the server
816
+ var errorFieldId = json[0];
817
+ var errorField = $($("#" + errorFieldId)[0]);
818
+ // make sure we found the element
819
+ if (errorField.length == 1) {
820
+ var status = json[1];
821
+ if (!status) {
822
+ // Houston we got a problem
823
+ options.ajaxValidCache[errorFieldId] = false;
824
+ options.isError = true;
825
+ var promptText = rule.alertText;
826
+ methods._showPrompt(errorField, promptText, "", true, options);
827
+ } else {
828
+ if (options.ajaxValidCache[errorFieldId] !== undefined)
829
+ options.ajaxValidCache[errorFieldId] = true;
830
+
831
+ // see if we should display a green prompt
832
+ var alertTextOk = rule.alertTextOk;
833
+ if (alertTextOk)
834
+ methods._showPrompt(errorField, alertTextOk, "pass", true, options);
835
+ else
836
+ methods._closePrompt(errorField);
837
+ }
838
+ }
839
+ }
840
+ });
841
+ }
842
+ },
843
+ /**
844
+ * Common method to handle ajax errors
845
+ *
846
+ * @param {Object} data
847
+ * @param {Object} transport
848
+ */
849
+ _ajaxError: function(data, transport) {
850
+ if(data.status == 0 && transport == null)
851
+ alert("The page is not served from a server! ajax call failed");
852
+ else if(typeof console != "undefined")
853
+ console.log("Ajax error: " + data.status + " " + transport);
854
+ },
855
+ /**
856
+ * date -> string
857
+ *
858
+ * @param {Object} date
859
+ */
860
+ _dateToString: function(date) {
861
+
862
+ return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
863
+ },
864
+ /**
865
+ * Parses an ISO date
866
+ * @param {String} d
867
+ */
868
+ _parseDate: function(d) {
869
+
870
+ var dateParts = d.split("-");
871
+ if(dateParts!==d)
872
+ dateParts = d.split("/");
873
+ return new Date(dateParts[0], (dateParts[1] - 1) ,dateParts[2]);
874
+ },
875
+ /**
876
+ * Builds or updates a prompt with the given information
877
+ *
878
+ * @param {jqObject} field
879
+ * @param {String} promptText html text to display type
880
+ * @param {String} type the type of bubble: 'pass' (green), 'load' (black) anything else (red)
881
+ * @param {boolean} ajaxed - use to mark fields than being validated with ajax
882
+ * @param {Map} options user options
883
+ */
884
+ _showPrompt: function(field, promptText, type, ajaxed, options, ajaxform) {
885
+ var prompt = methods._getPrompt(field);
886
+ // The ajax submit errors are not see has an error in the form,
887
+ // When the form errors are returned, the engine see 2 bubbles, but those are ebing closed by the engine at the same time
888
+ // Because no error was found befor submitting
889
+ if(ajaxform) prompt = false;
890
+ if (prompt)
891
+ methods._updatePrompt(field, prompt, promptText, type, ajaxed, options);
892
+ else
893
+ methods._buildPrompt(field, promptText, type, ajaxed, options);
894
+ },
895
+ /**
896
+ * Builds and shades a prompt for the given field.
897
+ *
898
+ * @param {jqObject} field
899
+ * @param {String} promptText html text to display type
900
+ * @param {String} type the type of bubble: 'pass' (green), 'load' (black) anything else (red)
901
+ * @param {boolean} ajaxed - use to mark fields than being validated with ajax
902
+ * @param {Map} options user options
903
+ */
904
+ _buildPrompt: function(field, promptText, type, ajaxed, options) {
905
+
906
+ // create the prompt
907
+ var prompt = $('<div>');
908
+ prompt.addClass(methods._getClassName(field.attr("id")) + "formError");
909
+ // add a class name to identify the parent form of the prompt
910
+ if(field.is(":input")) prompt.addClass("parentForm"+methods._getClassName(field.parents('form').attr("id")));
911
+ prompt.addClass("formError");
912
+
913
+ switch (type) {
914
+ case "pass":
915
+ prompt.addClass("greenPopup");
916
+ break;
917
+ case "load":
918
+ prompt.addClass("blackPopup");
919
+ }
920
+ if (ajaxed)
921
+ prompt.addClass("ajaxed");
922
+
923
+ // create the prompt content
924
+ var promptContent = $('<div>').addClass("formErrorContent").html(promptText).appendTo(prompt);
925
+ // create the css arrow pointing at the field
926
+ // note that there is no triangle on max-checkbox and radio
927
+ if (options.showArrow) {
928
+ var arrow = $('<div>').addClass("formErrorArrow");
929
+
930
+ switch (options.promptPosition) {
931
+ case "bottomLeft":
932
+ case "bottomRight":
933
+ prompt.find(".formErrorContent").before(arrow);
934
+ arrow.addClass("formErrorArrowBottom").html('<div class="line1"><!-- --></div><div class="line2"><!-- --></div><div class="line3"><!-- --></div><div class="line4"><!-- --></div><div class="line5"><!-- --></div><div class="line6"><!-- --></div><div class="line7"><!-- --></div><div class="line8"><!-- --></div><div class="line9"><!-- --></div><div class="line10"><!-- --></div>');
935
+ break;
936
+ case "topLeft":
937
+ case "topRight":
938
+ arrow.html('<div class="line10"><!-- --></div><div class="line9"><!-- --></div><div class="line8"><!-- --></div><div class="line7"><!-- --></div><div class="line6"><!-- --></div><div class="line5"><!-- --></div><div class="line4"><!-- --></div><div class="line3"><!-- --></div><div class="line2"><!-- --></div><div class="line1"><!-- --></div>');
939
+ prompt.append(arrow);
940
+ break;
941
+ }
942
+ }
943
+
944
+ //Cedric: Needed if a container is in position:relative
945
+ // insert prompt in the form or in the overflown container?
946
+ if (options.isOverflown)
947
+ field.before(prompt);
948
+ else
949
+ $("body").append(prompt);
950
+
951
+ var pos = methods._calculatePosition(field, prompt, options);
952
+ prompt.css({
953
+ "top": pos.callerTopPosition,
954
+ "left": pos.callerleftPosition,
955
+ "marginTop": pos.marginTopSize,
956
+ "opacity": 0
957
+ });
958
+
959
+ return prompt.animate({
960
+ "opacity": 0.87
961
+ });
962
+
963
+ },
964
+ /**
965
+ * Updates the prompt text field - the field for which the prompt
966
+ * @param {jqObject} field
967
+ * @param {String} promptText html text to display type
968
+ * @param {String} type the type of bubble: 'pass' (green), 'load' (black) anything else (red)
969
+ * @param {boolean} ajaxed - use to mark fields than being validated with ajax
970
+ * @param {Map} options user options
971
+ */
972
+ _updatePrompt: function(field, prompt, promptText, type, ajaxed, options) {
973
+
974
+ if (prompt) {
975
+ if (type == "pass")
976
+ prompt.addClass("greenPopup");
977
+ else
978
+ prompt.removeClass("greenPopup");
979
+
980
+ if (type == "load")
981
+ prompt.addClass("blackPopup");
982
+ else
983
+ prompt.removeClass("blackPopup");
984
+
985
+ if (ajaxed)
986
+ prompt.addClass("ajaxed");
987
+ else
988
+ prompt.removeClass("ajaxed");
989
+
990
+ prompt.find(".formErrorContent").html(promptText);
991
+
992
+ var pos = methods._calculatePosition(field, prompt, options);
993
+ prompt.animate({
994
+ "top": pos.callerTopPosition,
995
+ "marginTop": pos.marginTopSize
996
+ });
997
+ }
998
+ },
999
+ /**
1000
+ * Closes the prompt associated with the given field
1001
+ *
1002
+ * @param {jqObject}
1003
+ * field
1004
+ */
1005
+ _closePrompt: function(field) {
1006
+
1007
+ var prompt = methods._getPrompt(field);
1008
+ if (prompt)
1009
+ prompt.fadeTo("fast", 0, function() {
1010
+ prompt.remove();
1011
+ });
1012
+ },
1013
+ closePrompt: function(field) {
1014
+ return methods._closePrompt(field);
1015
+ },
1016
+ /**
1017
+ * Returns the error prompt matching the field if any
1018
+ *
1019
+ * @param {jqObject}
1020
+ * field
1021
+ * @return undefined or the error prompt (jqObject)
1022
+ */
1023
+ _getPrompt: function(field) {
1024
+
1025
+ var className = "." + methods._getClassName(field.attr("id")) + "formError";
1026
+ var match = $(className)[0];
1027
+ if (match)
1028
+ return $(match);
1029
+ },
1030
+ /**
1031
+ * Calculates prompt position
1032
+ *
1033
+ * @param {jqObject}
1034
+ * field
1035
+ * @param {jqObject}
1036
+ * the prompt
1037
+ * @param {Map}
1038
+ * options
1039
+ * @return positions
1040
+ */
1041
+ _calculatePosition: function(field, promptElmt, options) {
1042
+
1043
+ var promptTopPosition, promptleftPosition, marginTopSize;
1044
+ var fieldWidth = field.width();
1045
+ var promptHeight = promptElmt.height();
1046
+
1047
+ var overflow = options.isOverflown;
1048
+ if (overflow) {
1049
+ // is the form contained in an overflown container?
1050
+ promptTopPosition = promptleftPosition = 0;
1051
+ // compensation for the arrow
1052
+ marginTopSize = -promptHeight;
1053
+ } else {
1054
+ var offset = field.offset();
1055
+ promptTopPosition = offset.top;
1056
+ promptleftPosition = offset.left;
1057
+ marginTopSize = 0;
1058
+ }
1059
+
1060
+ switch (options.promptPosition) {
1061
+
1062
+ default:
1063
+ case "topRight":
1064
+ if (overflow)
1065
+ // Is the form contained in an overflown container?
1066
+ promptleftPosition += fieldWidth - 30;
1067
+ else {
1068
+ promptleftPosition += fieldWidth - 30;
1069
+ promptTopPosition += -promptHeight;
1070
+ }
1071
+ break;
1072
+ case "topLeft":
1073
+ promptTopPosition += -promptHeight - 10;
1074
+ break;
1075
+ case "centerRight":
1076
+ promptleftPosition += fieldWidth + 13;
1077
+ break;
1078
+ case "bottomLeft":
1079
+ promptTopPosition = promptTopPosition + field.height() + 15;
1080
+ break;
1081
+ case "bottomRight":
1082
+ promptleftPosition += fieldWidth - 30;
1083
+ promptTopPosition += field.height() + 5;
1084
+ }
1085
+
1086
+ return {
1087
+ "callerTopPosition": promptTopPosition + "px",
1088
+ "callerleftPosition": promptleftPosition + "px",
1089
+ "marginTopSize": marginTopSize + "px"
1090
+ };
1091
+ },
1092
+ /**
1093
+ * Saves the user options and variables in the form.data
1094
+ *
1095
+ * @param {jqObject}
1096
+ * form - the form where the user option should be saved
1097
+ * @param {Map}
1098
+ * options - the user options
1099
+ * @return the user options (extended from the defaults)
1100
+ */
1101
+ _saveOptions: function(form, options) {
1102
+
1103
+ // is there a language localisation ?
1104
+ if ($.validationEngineLanguage)
1105
+ var allRules = $.validationEngineLanguage.allRules;
1106
+ else
1107
+ $.error("jQuery.validationEngine rules are not loaded, plz add localization files to the page");
1108
+
1109
+ var userOptions = $.extend({
1110
+
1111
+ // Name of the event triggering field validation
1112
+ validationEventTrigger: "blur",
1113
+ // Automatically scroll viewport to the first error
1114
+ scroll: true,
1115
+ // Opening box position, possible locations are: topLeft,
1116
+ // topRight, bottomLeft, centerRight, bottomRight
1117
+ promptPosition: "topRight",
1118
+ bindMethod:"bind",
1119
+ // internal, automatically set to true when it parse a _ajax rule
1120
+ inlineAjax: false,
1121
+ // if set to true, the form data is sent asynchronously via ajax to the form.action url (get)
1122
+ ajaxFormValidation: false,
1123
+ // Ajax form validation callback method: boolean onComplete(form, status, errors, options)
1124
+ // retuns false if the form.submit event needs to be canceled.
1125
+ ajaxFormValidationURL: false,
1126
+ // The url to send the submit ajax validation (default to action)
1127
+ onAjaxFormComplete: $.noop,
1128
+ // called right before the ajax call, may return false to cancel
1129
+ onBeforeAjaxFormValidation: $.noop,
1130
+ // Stops form from submitting and execute function assiciated with it
1131
+ onValidationComplete: false,
1132
+
1133
+ // Used when the form is displayed within a scrolling DIV
1134
+ isOverflown: false,
1135
+ overflownDIV: "",
1136
+
1137
+ // --- Internals DO NOT TOUCH or OVERLOAD ---
1138
+ // validation rules and i18
1139
+ allrules: allRules,
1140
+ // true when form and fields are binded
1141
+ binded: false,
1142
+ // set to true, when the prompt arrow needs to be displayed
1143
+ showArrow: true,
1144
+ // did one of the validation fail ? kept global to stop further ajax validations
1145
+ isError: false,
1146
+ // Caches field validation status, typically only bad status are created.
1147
+ // the array is used during ajax form validation to detect issues early and prevent an expensive submit
1148
+ ajaxValidCache: {}
1149
+
1150
+ }, options);
1151
+
1152
+ form.data('jqv', userOptions);
1153
+ return userOptions;
1154
+ },
1155
+
1156
+ /**
1157
+ * Removes forbidden characters from class name
1158
+ * @param {String} className
1159
+ */
1160
+ _getClassName: function(className) {
1161
+ return className.replace(":","_").replace(".","_");
1162
+ }
1163
+ };
1164
+
1165
+ /**
1166
+ * Plugin entry point.
1167
+ * You may pass an action as a parameter or a list of options.
1168
+ * if none, the init and attach methods are being called.
1169
+ * Remember: if you pass options, the attached method is NOT called automatically
1170
+ *
1171
+ * @param {String}
1172
+ * method (optional) action
1173
+ */
1174
+ $.fn.validationEngine = function(method) {
1175
+
1176
+ var form = $(this);
1177
+ if(!form[0]) return false; // stop here if the form does not exist
1178
+
1179
+ if (typeof(method) == 'string' && method.charAt(0) != '_' && methods[method]) {
1180
+
1181
+ // make sure init is called once
1182
+ if(method != "showPrompt" && method != "hidePrompt" && method != "hide" && method != "hideAll")
1183
+ methods.init.apply(form);
1184
+
1185
+ return methods[method].apply(form, Array.prototype.slice.call(arguments, 1));
1186
+ } else if (typeof method == 'object' || !method) {
1187
+ // default constructor with or without arguments
1188
+ methods.init.apply(form, arguments);
1189
+ return methods.attach.apply(form);
1190
+ } else {
1191
+ $.error('Method ' + method + ' does not exist in jQuery.validationEngine');
1192
+ }
1193
+ };
1194
+ })(jQuery);
js/swpm.password-meter.js ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($){
2
+
3
+ function check_pass_strength() {
4
+ var pass1 = $('#pass1').val(), user = $('#user_name').val(), pass2 = $('#pass2').val(), strength;
5
+
6
+ $('#pass-strength-result').removeClass('short bad good strong');
7
+ if ( ! pass1 ) {
8
+ $('#pass-strength-result').html( pwsL10n.empty );
9
+ return;
10
+ }
11
+
12
+ strength = passwordStrength(pass1, user, pass2);
13
+
14
+ switch ( strength ) {
15
+ case 2:
16
+ $('#pass-strength-result').addClass('bad').html( pwsL10n['bad'] );
17
+ break;
18
+ case 3:
19
+ $('#pass-strength-result').addClass('good').html( pwsL10n['good'] );
20
+ break;
21
+ case 4:
22
+ $('#pass-strength-result').addClass('strong').html( pwsL10n['strong'] );
23
+ break;
24
+ case 5:
25
+ $('#pass-strength-result').addClass('short').html( pwsL10n['mismatch'] );
26
+ break;
27
+ default:
28
+ $('#pass-strength-result').addClass('short').html( pwsL10n['short'] );
29
+ }
30
+ }
31
+
32
+ $(document).ready( function() {
33
+ $('#pass1').val('').keyup( check_pass_strength );
34
+ $('#pass2').val('').keyup( check_pass_strength );
35
+ $('#pass-strength-result').show();
36
+ });
37
+
38
+ })(jQuery);
log.txt ADDED
File without changes
readme.txt ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Simple Membership ===
2
+ Contributors: smp7, wp.insider
3
+ Donate link: https://simple-membership-plugin.com/
4
+ Tags: member, members, members only, membership, memberships, register, WordPress membership plugin, content protection, paypal, restrict access, Restrict content
5
+ Requires at least: 3.3
6
+ Tested up to: 3.9.1
7
+ Stable tag: 1.5
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Simple membership plugin can add membership functionality to your site. Protect members only content using content protection easily.
12
+
13
+ == Description ==
14
+
15
+ = A flexible, well-supported, and easy-to-use WordPress membership plugin for offering free and premium content from your WordPress site =
16
+
17
+ The simple membership plugin lets you protect your posts and pages so only your members can view the protected content.
18
+
19
+ = Unlimited Membership Access Levels =
20
+ Set up unlimited membership levels (example: free, silver, gold etc) and protect your posts and pages using the membership levels you create.
21
+
22
+ = User Friendly Interface for Content Protection =
23
+ When you are editing a post or page in the WordPress editor, you can select to protect that post or page for your members.
24
+
25
+ Non-members viewing a protected page will be prompted to login or become a member.
26
+
27
+ = Have Free and Paid Memberships =
28
+ You can configure it to have free and/or paid memberships on your site. Paid membership payment is handled securely via PayPal.
29
+
30
+ Both one time and recurring/subscription payments are supported.
31
+
32
+ = Documentation =
33
+
34
+ Read the [setup documentation](https://simple-membership-plugin.com/wp-content/uploads/documentation/simple-membership/membership-basic-setup-and-configuration.pdf) after you install the plugin to get started.
35
+
36
+ = Plugin Support =
37
+
38
+ If you have any issue with this plugin, please post it on the support forum here:
39
+ https://simple-membership-plugin.com/forums/
40
+
41
+ You can create a free forum user account and ask your question in the above forum.
42
+
43
+ = Miscellaneous =
44
+
45
+ * Ability to protect photo galleries.
46
+ * There is an option to enable debug logging so you can troubleshoot membership payment related issues easily (if any).
47
+ * Membership management side is handled by the plugin.
48
+ * Can be translated to any language.
49
+ * Works with any WordPress theme.
50
+ * The login and registration widgets will be responsive if you are using a responsive theme.
51
+
52
+ == Installation ==
53
+
54
+ Do the following to install the membership plugin:
55
+
56
+ 1. Upload the 'simple-wp-membership.zip' file from the Plugins->Add New page in the WordPress administration panel.
57
+ 2. Activate the plugin through the 'Plugins' menu in WordPress.
58
+
59
+ == Frequently Asked Questions ==
60
+
61
+ None.
62
+
63
+ == Screenshots ==
64
+
65
+ Please visit the memberhsip plugin page to view screenshots:
66
+ https://simple-membership-plugin.com/
67
+
68
+ == Changelog ==
69
+
70
+ = 1.5 =
71
+ - Fixed a bug with sending member email when added via admin dashboard.
72
+ - Fixed a bug with general settings values resetting.
73
+ - Added a few action hooks to the plugin.
74
+
75
+ = 1.4 =
76
+ - Refactored some code to enhance the architecture. This will help us add some good features in the future.
77
+ - Added debug logger to help troubleshoot after membership payment tasks.
78
+ - Added a new action hook for after paypal IPN is processed.
79
+
80
+ = 1.3 =
81
+ - Fixed a bug with premium membership registration.
82
+
83
+ = 1.2 =
84
+ - First commit to WordPress repository.
85
+
86
+ == Upgrade Notice ==
87
+
88
+ None
89
+
90
+ == Arbitrary section ==
91
+
92
+ None
simple-wp-membership.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Simple WordPress Membership
4
+ Version: v1.5
5
+ Plugin URI: https://simple-membership-plugin.com/
6
+ Author: smp7, wp.insider
7
+ Author URI: https://simple-membership-plugin.com/
8
+ Description: A flexible, well-supported, and easy-to-use WordPress membership plugin for offering free and premium content from your WordPress site.
9
+ */
10
+
11
+ //Direct access to this file is not permitted
12
+ if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"])){
13
+ exit("Do not access this file directly.");
14
+ }
15
+
16
+ include_once('classes/class.simple-wp-membership.php');
17
+
18
+ define('SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL', home_url());
19
+ define('SIMPLE_WP_MEMBERSHIP_VER', '1.5');
20
+ define('SIMPLE_WP_MEMBERSHIP_PATH', dirname(__FILE__) . '/');
21
+ define('SIMPLE_WP_MEMBERSHIP_URL', plugins_url('',__FILE__));
22
+ define('SIMPLE_WP_MEMBERSHIP_AUTH', 'simple_wp_membership_'. COOKIEHASH);
23
+ define('SIMPLE_WP_MEMBERSHIP_SEC_AUTH', 'simple_wp_membership_sec_'. COOKIEHASH);
24
+ register_activation_hook( SIMPLE_WP_MEMBERSHIP_PATH .'simple-wp-membership.php', 'SimpleWpMembership::activate' );
25
+ register_deactivation_hook( SIMPLE_WP_MEMBERSHIP_PATH . 'simple-wp-membership.php', 'SimpleWpMembership::deactivate' );
26
+ add_action('swpm_login','SimpleWpMembership::swpm_login', 10,3);
27
+ add_action('plugins_loaded', function(){new SimpleWpMembership();});
28
+
29
+ //Add settings link in plugins listing page
30
+ function swpm_add_settings_link($links, $file) {
31
+ if ($file == plugin_basename(__FILE__)) {
32
+ $settings_link = '<a href="admin.php?page=simple_wp_membership_settings">Settings</a>';
33
+ array_unshift($links, $settings_link);
34
+ }
35
+ return $links;
36
+ }
37
+ add_filter('plugin_action_links', 'swpm_add_settings_link', 10, 2);
views/add.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="swpm-registration-widget-form">
2
+ <form id="swpm-registration-form" name="swpm-registration-form" method="post" action="">
3
+ <table>
4
+ <tr>
5
+ <td><label for="user_name">User Name</label></td>
6
+ <td><input type="text" id="user_name" class="validate[required,custom[SWPMUserName],minSize[4],ajax[ajaxUserCall]]" value="<?php echo $user_name;?>" tabindex="1" size="50" name="user_name" /></td>
7
+ </tr>
8
+ <tr>
9
+ <td><label for="email">Email</label></td>
10
+ <td><input type="text" id="email" class="validate[required,custom[email],ajax[ajaxEmailCall]]" value="<?php echo $email;?>" tabindex="2" size="50" name="email" /></td>
11
+ </tr>
12
+ <tr>
13
+ <td><label for="password">Password</label></td>
14
+ <td><input type="password" id="password" value="" tabindex="3" size="50" name="password" /></td>
15
+ </tr>
16
+ <tr>
17
+ <td><label for="password_re">Repeat Password</label></td>
18
+ <td><input type="password" id="password_re" value="" tabindex="4" size="50" name="password_re" /></td>
19
+ </tr>
20
+ <tr>
21
+ <td><label for="first_name">First Name</label></td>
22
+ <td><input type="text" id="first_name" value="<?php echo $first_name;?>" tabindex="5" size="50" name="first_name" /></td>
23
+ </tr>
24
+ <tr>
25
+ <td><label for="last_name">Last Name</label></td>
26
+ <td><input type="text" id="last_name" value="<?php echo $last_name;?>" tabindex="6" size="50" name="last_name" /></td>
27
+ </tr>
28
+ <tr>
29
+ <td><label for="gender"><?php _e('Gender'); ?></label></td>
30
+ <td><select name="gender" id="gender">
31
+ <?= BUtils::gender_dropdown() ?>
32
+ </select>
33
+ </td>
34
+ </tr>
35
+ <tr>
36
+ <td><label for="phone">Phone</label></td>
37
+ <td><input type="text" id="phone" value="<?php echo $phone;?>" tabindex="7" size="50" name="phone" /></td>
38
+ </tr>
39
+ <tr>
40
+ <td><label for="address_street">Street</label></td>
41
+ <td><input type="text" id="address_street" value="<?php echo $address_street;?>" tabindex="8" size="50" name="address_street" /></td>
42
+ </tr>
43
+ <tr>
44
+ <td><label for="address_city">City</label></td>
45
+ <td><input type="text" id="address_city" value="<?php echo $address_city;?>" tabindex="9" size="50" name="address_city" /></td>
46
+ </tr>
47
+ <tr>
48
+ <td><label for="address_state">State</label></td>
49
+ <td><input type="text" id="address_state" value="<?php echo $address_state;?>" tabindex="10" size="50" name="address_state" /></td>
50
+ </tr>
51
+ <tr>
52
+ <td><label for="address_zipcode">Zipcode</label></td>
53
+ <td><input type="text" id="address_zipcode" value="<?php echo $address_zipcode;?>" tabindex="11" size="50" name="address_zipcode" /></td>
54
+ </tr>
55
+ <tr>
56
+ <td><label for="country">Country</label></td>
57
+ <td><input type="text" id="country" value="<?php echo $country;?>" tabindex="12" size="50" name="country" /></td>
58
+ </tr>
59
+ <tr>
60
+ <td ><label for="company_name"><?php _e('Company') ?></label></td>
61
+ <td><input name="company_name" type="text" id="company_name" tabindex="13" size="50" value="<?php echo esc_attr($company_name); ?>" /></td>
62
+ </tr>
63
+ <tr>
64
+ <td><label for="membership_level">Membership Level</label></td>
65
+ <td>
66
+ <?php echo $membership_level_alias;?>
67
+ <input type="hidden" value="<?php echo $membership_level;?>" size="50" name="membership_level" id="membership_level" />
68
+ </td>
69
+ </tr>
70
+ </table>
71
+ <p align="center"><input type="submit" value="Register" tabindex="6" id="submit" name="swpm_registration_submit" /></p>
72
+ <input type="hidden" name="action" value="custom_posts" />
73
+ <?php wp_nonce_field( 'name_of_my_action','name_of_nonce_field' ); ?>
74
+ </form>
75
+ </div>
76
+ <script>
77
+ jQuery(document).ready(function($){
78
+ $.validationEngineLanguage.allRules['ajaxUserCall']['url']= '<?php echo admin_url('admin-ajax.php');?>';
79
+ $.validationEngineLanguage.allRules['ajaxEmailCall']['url']= '<?php echo admin_url('admin-ajax.php');?>';
80
+ $("#swpm-registration-form").validationEngine('attach');
81
+ });
82
+ </script>
views/admin_add.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap" id="swpm-profile-page">
2
+ <?php //screen_icon(); ?>
3
+ <form action="" method="post" name="swpm-create-user" id="swpm-create-user" class="validate"<?php do_action('user_new_form_tag');?>>
4
+ <input name="action" type="hidden" value="createuser" />
5
+ <?php wp_nonce_field( 'create-swpmuser', '_wpnonce_create-swpmuser' ) ?>
6
+ <h3>Add Member</h3>
7
+ <p><?php _e('Create a brand new user and add it to this site.'); ?></p>
8
+ <table class="form-table">
9
+ <tbody>
10
+ <tr class="form-required">
11
+ <th scope="row"><label for="user_name"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
12
+ <td><input class="regular-text validate[required,custom[SWPMUserName],minSize[4],ajax[ajaxUserCall]]" name="user_name" type="text" id="user_name" value="<?php echo esc_attr($user_name); ?>" aria-required="true" /></td>
13
+ </tr>
14
+ <tr class="form-required">
15
+ <th scope="row"><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
16
+ <td><input name="email" class="regular-text validate[required,custom[email],ajax[ajaxEmailCall]]" type="text" id="email" value="<?php echo esc_attr($email); ?>" /></td>
17
+ </tr>
18
+ <?php include('admin_member_form_common_part.php');?>
19
+ <?php submit_button( __( 'Add New Member '), 'primary', 'createswpmuser', true, array( 'id' => 'createswpmusersub' ) ); ?>
20
+ </form>
21
+ </div>
22
+ <script>
23
+ jQuery(document).ready(function($){
24
+ $.validationEngineLanguage.allRules['ajaxUserCall']['url']= '<?php echo admin_url('admin-ajax.php');?>';
25
+ $.validationEngineLanguage.allRules['ajaxEmailCall']['url']= '<?php echo admin_url('admin-ajax.php');?>';
26
+ $("#swpm-create-user").validationEngine('attach');
27
+ });
28
+ </script>
views/admin_add_level.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap" id="swpm-level-page">
2
+
3
+ <form action="" method="post" name="swpm-create-level" id="swpm-create-level" class="validate"<?php do_action('level_new_form_tag');?>>
4
+ <input name="action" type="hidden" value="createlevel" />
5
+ <h3>Add Membership Level</h3>
6
+ <p><?php _e('Create new membership level.'); ?></p>
7
+ <?php wp_nonce_field( 'create-swpmlevel', '_wpnonce_create-swpmlevel' ) ?>
8
+ <table class="form-table">
9
+ <tbody>
10
+ <tr>
11
+ <th scope="row"><label for="alias"><?php _e('Membership Level Name'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
12
+ <td><input class="regular-text validate[required]" name="alias" type="text" id="alias" value="" aria-required="true" /></td>
13
+ </tr>
14
+ <tr class="form-field form-required">
15
+ <th scope="row"><label for="role"><?php _e('Default WordPress Role'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
16
+ <td><select class="regular-text" name="role"><?php wp_dropdown_roles( 'subscriber' ); ?></select></td>
17
+ </tr>
18
+ <tr>
19
+ <th scope="row"><label for="subscription_unit"><?php _e('Subscription Duration'); ?> <span class="description"><?php _e('(required)'); ?></span></label>
20
+ </th>
21
+ <td>
22
+ <div class="color-option"><input name="subscript_duration_type" id="subscript_duration_noexpire" checked="checked" type="radio" value="0" class="tog">
23
+ <table class="color-palette">
24
+ <tbody><tr>
25
+ <td style="width: 60px;"><b>No Expiry</b></td>
26
+ </tr>
27
+ </tbody></table>
28
+ </div>
29
+ </td>
30
+ </tr>
31
+ <tr>
32
+ <th></th>
33
+ <td>
34
+ <div class="color-option"><input name="subscript_duration_type" id="subscript_duration_expire" type="radio" value="1" class="tog">
35
+ <table class="color-palette">
36
+ <tbody><tr>
37
+ <td style="background-color: #d1e5ee" title="fresh"><input type="text" class="validate[required]" size="3" id="subscription_period" name="subscription_period" value=""></td>
38
+ <td style="background-color: #cfdfe9" title="fresh">
39
+ <select id="subscription_unit" name="subscription_unit">
40
+ <option value="Days">Days</option>
41
+ <option value="Weeks">Weeks</option>
42
+ <option value="Months">Months</option>
43
+ <option value="Years">Years</option>
44
+ </select>
45
+ </td>
46
+ </tr>
47
+ </tbody></table>
48
+ </div>
49
+ </td>
50
+ </tr>
51
+ <?= apply_filters('swpm_admin_add_membership_level_ui', '');?>
52
+ </tbody>
53
+ </table>
54
+ <?php submit_button( __( 'Add New Membership Level '), 'primary', 'createswpmlevel', true, array( 'id' => 'createswpmlevelsub' ) ); ?>
55
+ </form>
56
+ </div>
57
+ <script>
58
+ jQuery(document).ready(function($){
59
+ $('.tog:radio').on('update_deps click',function(){
60
+ if($(this).attr('checked')){
61
+ $("#swpm-create-level").validationEngine('detach');
62
+ if($(this).val()==0)
63
+ $('#subscription_period').removeClass('validate[required]');
64
+ else if($(this).val()==1)
65
+ $('#subscription_period').addClass('validate[required]');
66
+ $("#swpm-create-level").validationEngine('attach');
67
+ }
68
+ });
69
+ $('.tog:radio').trigger('update_deps');
70
+ });
71
+ </script>
72
+
views/admin_edit.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap" id="swpm-profile-page">
2
+ <form action="" method="post" name="swpm-edit-user" id="swpm-edit-user" class="validate"<?php do_action('user_new_form_tag');?>>
3
+ <input name="action" type="hidden" value="edituser" />
4
+ <?php wp_nonce_field( 'edit-swpmuser', '_wpnonce_edit-swpmuser' ) ?>
5
+ <h3>Edit Member</h3>
6
+ <p><?php _e('Edit existing member details.'); ?></p>
7
+ <table class="form-table">
8
+ <tr class="form-field form-required">
9
+ <th scope="row"><label for="user_name"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
10
+ <td><?php echo esc_attr($user_name); ?></td>
11
+ </tr>
12
+ <tr class="form-field form-required">
13
+ <th scope="row"><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
14
+ <td><?php echo esc_attr($email); ?></td>
15
+ </tr>
16
+ <?php include('admin_member_form_common_part.php');?>
17
+ <?php submit_button( __( ' Edit User '), 'primary', 'editswpmuser', true, array( 'id' => 'createswpmusersub' ) ); ?>
18
+ </form>
19
+ </div>
20
+ <script>
21
+ jQuery(document).ready(function($){
22
+ $("#swpm-edit-user").validationEngine('attach');
23
+ });
24
+ </script>
views/admin_edit_level.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap" id="swpm-level-page">
2
+ <form action="" method="post" name="swpm-edit-level" id="swpm-edit-level" class="validate"<?php do_action('level_edit_form_tag');?>>
3
+ <input name="action" type="hidden" value="editlevel" />
4
+ <?php wp_nonce_field( 'edit-swpmlevel', '_wpnonce_edit-swpmlevel' ) ?>
5
+ <h3><?= _e('Edit membership level'); ?></h3>
6
+ <p><?= _e('Edit membership level.'); ?></p>
7
+ <table class="form-table">
8
+ <tbody>
9
+ <tr>
10
+ <th scope="row"><label for="alias"><?php _e('Membership Level Name'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
11
+ <td><input class="regular-text validate[required]" name="alias" type="text" id="alias" value="<?php echo stripslashes($alias);?>" aria-required="true" /></td>
12
+ </tr>
13
+ <tr class="form-field form-required">
14
+ <th scope="row"><label for="role"><?php _e('Default WordPress Role'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
15
+ <td><select class="regular-text" name="role"><?php wp_dropdown_roles( $role ); ?></select></td>
16
+ </tr>
17
+ <tr>
18
+ <th scope="row"><label for="subscription_unit"><?php _e('Subscription Duration'); ?> <span class="description"><?php _e('(required)'); ?></span></label>
19
+ </th>
20
+ <td>
21
+ <fieldset>
22
+ <div class="color-option">
23
+ <input name="subscript_duration_type" id="subscript_duration_noexpire"
24
+ <?php echo $noexpire?'checked="checked"': ""; ?> type="radio" value="0" class="tog">
25
+ <table class="color-palette">
26
+ <tbody><tr>
27
+ <td style="width: 60px;"><b>No Expiry</b></td>
28
+ </tr>
29
+ </tbody></table>
30
+ </div>
31
+ <div class="color-option">
32
+ <input name="subscript_duration_type" id="subscript_duration_expire"
33
+ <?php echo !$noexpire?'checked="checked"': ""; ?> type="radio" value="1" class="tog">
34
+ <table class="color-palette">
35
+ <tbody><tr>
36
+ <td style="background-color: #d1e5ee" title="fresh">
37
+ <input type="text" class="validate[required]" size="3" id="subscription_period" name="subscription_period"
38
+ value="<?php echo $noexpire?'':$subscription_period;?>"></td>
39
+ <td style="background-color: #cfdfe9" title="fresh">
40
+ <select id="subscription_unit" name="subscription_unit">
41
+ <?= BUtils::subscription_unit_dropdown($subscription_unit)?>
42
+ </select>
43
+ </td>
44
+ </tr>
45
+ </tbody></table>
46
+ </div>
47
+ </fieldset>
48
+
49
+ </td>
50
+ </tr>
51
+ <?= apply_filters('swpm_admin_edit_membership_level_ui', '', $id);?>
52
+ </tbody>
53
+ </table>
54
+ <?php submit_button( __( 'Edit Membership Level '), 'primary', 'editswpmlevel', true, array( 'id' => 'editswpmlevelsub' ) ); ?>
55
+ </form>
56
+ </div>
57
+ <script>
58
+ jQuery(document).ready(function($){
59
+ $('.tog:radio').on('update_deps click',function(){
60
+ if($(this).attr('checked')){
61
+ $("#swpm-edit-level").validationEngine('detach');
62
+ if($(this).val()==0)
63
+ $('#subscription_period').removeClass('validate[required]');
64
+ else if($(this).val()==1)
65
+ $('#subscription_period').addClass('validate[required]');
66
+ $("#swpm-edit-level").validationEngine('attach');
67
+ }
68
+ });
69
+ $('.tog:radio').trigger('update_deps');
70
+ });
71
+ </script>
views/admin_member_form_common_part.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <tr>
2
+ <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th>
3
+ <td><input class="regular-text" name="first_name" type="text" id="first_name" value="<?php echo esc_attr($first_name); ?>" /></td>
4
+ </tr>
5
+ <tr>
6
+ <th scope="row"><label for="last_name"><?php _e('Last Name') ?> </label></th>
7
+ <td><input class="regular-text" name="last_name" type="text" id="last_name" value="<?php echo esc_attr($last_name); ?>" /></td>
8
+ </tr>
9
+ <tr>
10
+ <th scope="row"><label for="gender"><?php _e('Gender'); ?></label></th>
11
+ <td><select class="regular-text" name="gender" id="gender">
12
+ <?= BUtils::gender_dropdown($gender) ?>
13
+ </select>
14
+ </td>
15
+ </tr>
16
+ <tr>
17
+ <th scope="row"><label for="phone"><?php _e('Phone') ?> </label></th>
18
+ <td><input class="regular-text" name="phone" type="text" id="phone" value="<?php echo esc_attr($phone); ?>" /></td>
19
+ </tr>
20
+ <tr>
21
+ <th scope="row"><label for="address_street"><?php _e('Street') ?> </label></th>
22
+ <td><input class="regular-text" name="address_street" type="text" id="address_street" value="<?php echo esc_attr($address_street); ?>" /></td>
23
+ </tr>
24
+ <tr>
25
+ <th scope="row"><label for="address_city"><?php _e('City') ?> </label></th>
26
+ <td><input class="regular-text" name="address_city" type="text" id="address_city" value="<?php echo esc_attr($address_city); ?>" /></td>
27
+ </tr>
28
+ <tr>
29
+ <th scope="row"><label for="address_state"><?php _e('State') ?> </label></th>
30
+ <td><input class="regular-text" name="address_state" type="text" id="address_state" value="<?php echo esc_attr($address_state); ?>" /></td>
31
+ </tr>
32
+ <tr>
33
+ <th scope="row"><label for="address_zipcode"><?php _e('Zipcode') ?> </label></th>
34
+ <td><input class="regular-text" name="address_zipcode" type="text" id="address_zipcode" value="<?php echo esc_attr($address_zipcode); ?>" /></td>
35
+ </tr>
36
+ <tr>
37
+ <th scope="row"><label for="country"><?php _e('Country') ?> </label></th>
38
+ <td><input class="regular-text" name="country" type="text" id="country" value="<?php echo esc_attr($country); ?>" /></td>
39
+ </tr>
40
+ <tr>
41
+ <th scope="row"><label for="company_name"><?php _e('Company') ?></label></th>
42
+ <td><input name="company_name" type="text" id="company_name" class="code regular-text" value="<?php echo esc_attr($company_name); ?>" /></td>
43
+ </tr>
44
+ <tr class="form-required">
45
+ <th scope="row"><label for="password"><?php _e('Password'); ?> <span class="description"><?php /* translators: password input field */_e('(twice, required)'); ?></span></label></th>
46
+ <td><input class="regular-text" name="password" type="password" id="pass1" autocomplete="off" />
47
+ <br />
48
+ <input class="regular-text" name="password_re" type="password" id="pass2" autocomplete="off" />
49
+ <br />
50
+ <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
51
+ <p class="description indicator-hint"><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).'); ?></p>
52
+ </td>
53
+ </tr>
54
+ <tr>
55
+ <th scope="row"><label for="membership_level"><?php _e('Membership Level'); ?></label></th>
56
+ <td><select class="regular-text" name="membership_level" id="membership_level">
57
+ <?php foreach ($levels as $level):?>
58
+ <option <?php echo ($level['id'] == $membership_level)? "selected='selected'": "";?> value="<?php echo $level['id'];?>"> <?php echo $level['alias']?></option>
59
+ <?php endforeach;?>
60
+ </select>
61
+ </td>
62
+ </tr>
63
+ <tr>
64
+ <th scope="row"><label for="account_state"><?php _e('Account Status'); ?></label></th>
65
+ <td><select class="regular-text" name="account_state" id="account_state">
66
+ <option value="active">Active</option>
67
+ <option value="inactive">Inactive</option>
68
+ <option value="pending">Pending</option>
69
+ <option value="expired">Expired</option>
70
+ </select>
71
+ </td>
72
+ </tr>
73
+ <tr>
74
+ <th scope="row"><label for="member_since"><?php _e('Member Since') ?> </label></th>
75
+ <td><input class="regular-text" name="member_since" type="text" id="member_since" value="<?php echo esc_attr($member_since); ?>" /></td>
76
+ </tr>
77
+ <tr>
78
+ <th scope="row"><label for="subscription_starts"><?php _e('Subscription Starts') ?> </label></th>
79
+ <td><input class="regular-text" name="subscription_starts" type="text" id="subscription_starts" value="<?php echo esc_attr($subscription_starts); ?>" /></td>
80
+ </tr>
81
+ </tbody>
82
+ </table>
83
+ <script>
84
+ jQuery(document).ready(function($){
85
+ $('#member_since').dateinput({'format':'yyyy-mm-dd',selectors: true,yearRange:[-100,100]});
86
+ $('#subscription_starts').dateinput({'format':'yyyy-mm-dd',selectors: true,yearRange:[-100,100]});
87
+ });
88
+ </script>
views/admin_members.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap">
2
+ <h2><?php screen_icon('users'); ?>Simple WP Membership::Members
3
+ <a href="admin.php?page=simple_wp_membership&member_action=add" class="add-new-h2"><?php echo "Add New"; ?></a></h2>
4
+ <form method="post">
5
+ <p class="search-box">
6
+ <label class="screen-reader-text" for="search_id-search-input">
7
+ search:</label>
8
+ <input id="search_id-search-input" type="text" name="s" value="" />
9
+ <input id="search-submit" class="button" type="submit" name="" value="search" />
10
+ <input type="hidden" name="page" value="my_list_test" />
11
+ </p>
12
+ </form>
13
+ <?php $this->prepare_items(); ?>
14
+ <form method="post">
15
+ <?php $this->display(); ?>
16
+ </form>
17
+
18
+ <p>
19
+ <a href="admin.php?page=simple_wp_membership&member_action=add" class="button-primary"><?php echo "Add New"; ?></a>
20
+ </p>
21
+ </div><!-- end of wrap -->
views/admin_membership_level_menu.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <h3 class="nav-tab-wrapper">
2
+ <a class="nav-tab <?php echo ($selected==1) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels">Membership level</a>
3
+ <a class="nav-tab <?php echo ($selected==2) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_levels&level_action=manage">Manage Content Production</a>
4
+ </h3>
views/admin_membership_levels.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap">
2
+
3
+ <h2><?php screen_icon('users'); ?>Simple WP Membership::Membership Levels
4
+ <a href="admin.php?page=simple_wp_membership_levels&level_action=add" class="add-new-h2"><?php echo esc_html_x('Add New', 'Level'); ?></a></h2>
5
+ <?php include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_membership_level_menu.php'); ?>
6
+ <form method="post">
7
+ <p class="search-box">
8
+ <label class="screen-reader-text" for="search_id-search-input">
9
+ search:</label>
10
+ <input id="search_id-search-input" type="text" name="s" value="" />
11
+ <input id="search-submit" class="button" type="submit" name="" value="search" />
12
+ <input type="hidden" name="page" value="my_list_test" />
13
+ </p>
14
+ </form>
15
+ <?php $this->prepare_items(); ?>
16
+ <form method="post">
17
+ <?php $this->display(); ?>
18
+ </form>
19
+
20
+ <p>
21
+ <a href="admin.php?page=simple_wp_membership_levels&level_action=add" class="button-primary">Add New</a>
22
+ </p>
23
+
24
+ </div><!-- end of .wrap -->
views/admin_membership_manage.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap">
2
+ <h2><?php screen_icon( 'users' );?>Simple WP Membership::Manage Protection</h2>
3
+ <?php include_once(SIMPLE_WP_MEMBERSHIP_PATH.'views/admin_membership_level_menu.php');?>
4
+
5
+ <div id="poststuff"><div id="post-body">
6
+ <h1>How to Apply Content Protection</h1>
7
+
8
+ <p>Take the following steps to apply protection your content so only members can have access to it.</p>
9
+
10
+ 1. Edit the Post or Page that you want to protect in WordPress editor.
11
+ <br />2. Scroll down to the section titled 'Simple WP Membership Protection'.
12
+ <br />3. Select 'Yes, Protect this content' option.
13
+ <br />4. Check the membership levels that should have access to that page's content.
14
+ <br />5. Hit the Update/Save Button to save the changes.
15
+
16
+ <br /><br />
17
+ <h3>Example Content Protection Settings</h3>
18
+
19
+ <img src="<?php echo SIMPLE_WP_MEMBERSHIP_URL.'/images/simple-membership-content-protection-usage.png'; ?>" alt="Content protection example usage">
20
+
21
+ </div></div>
22
+ </div> <!-- end of wrap -->
views/admin_payment_settings.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php screen_icon( 'options-general' );?>
2
+ <h1>Simple WP Membership::Settings</h1>
3
+ <div class="wrap">
4
+
5
+ <?php do_action("swpm-draw-tab"); ?>
6
+
7
+ <div id="poststuff"><div id="post-body">
8
+
9
+ <?php
10
+ global $wpdb;
11
+
12
+ if(isset($_POST['swpm_generate_adv_code']))
13
+ {
14
+ $paypal_ipn_url = SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL.'/?swpm_process_ipn=1';
15
+ $mem_level = trim($_POST['swpm_paypal_adv_member_level']);
16
+
17
+ $query = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id =". $mem_level;
18
+ $membership_level_resultset = $wpdb->get_row($query);
19
+ if($membership_level_resultset){
20
+ $pp_av_code = 'notify_url='.$paypal_ipn_url.'<br /> '.'custom=subsc_ref='.$mem_level;
21
+ echo '<div id="message" class="updated fade"><p>';
22
+ echo '<strong>Paste the code below in the "Add advanced variables" field of your PayPal button for membership level '.$mem_level.'</strong>';
23
+ echo '<br /><br /><code>'.$pp_av_code.'</code>';
24
+ echo '</p></div>';
25
+ }
26
+ else{
27
+ echo '<div id="message" class="updated fade"><p><strong>';
28
+ echo 'Error! The membership level ID ('.$mem_level.') you specified is incorrect. Please check this value again.';
29
+ echo '</strong></p></div>';
30
+ }
31
+ }
32
+ ?>
33
+ <div class="postbox">
34
+ <h3><label for="title">PayPal Integration Settings</label></h3>
35
+ <div class="inside">
36
+
37
+ <p><strong>Generate the "Advanced Variables" Code for your PayPal button</strong></p>
38
+
39
+ <form action="" method="post">
40
+ Enter the Membership Level ID
41
+ <input type="text" value="" size="4" name="swpm_paypal_adv_member_level">
42
+ <input type="submit" value="Generate Code" class="button-primary" name="swpm_generate_adv_code">
43
+ </form>
44
+
45
+ </div></div>
46
+
47
+ </div></div><!-- end of poststuff and post-body -->
48
+ </div><!-- end of wrap -->
views/admin_settings.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php screen_icon( 'options-general' );?>
2
+ <h1>Simple WP Membership::Settings</h1>
3
+ <div class="wrap">
4
+ <?php do_action("swpm-draw-tab"); ?>
5
+ <form action="options.php" method="POST">
6
+ <input type="hidden" name="tab" value="<?php echo $current_tab;?>" />
7
+ <?php settings_fields( 'swpm-settings-tab-' . $current_tab ); ?>
8
+ <?php do_settings_sections( 'simple_wp_membership_settings' ); ?>
9
+ <?php submit_button(); ?>
10
+ </form>
11
+ </div>
views/admin_tools_settings.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php screen_icon( 'options-general' );?>
2
+ <h1>Simple WP Membership::Settings</h1>
3
+ <div class="wrap">
4
+
5
+ <?php do_action("swpm-draw-tab"); ?>
6
+
7
+ <div id="poststuff"><div id="post-body">
8
+ <div class="postbox">
9
+ <h3><label for="title">Generate a Registration Completion link</label></h3>
10
+ <div class="inside">
11
+
12
+ <p><strong>You can manually generate a registration completion link here and give it to your customer if they have missed the email that was automatically sent out to them after the payment.</strong></p>
13
+
14
+ <form action="" method="post">
15
+ <table>
16
+ <tr>
17
+ Generate Registration Completion Link
18
+ <br /><input type="radio" value="one" name="swpm_link_for" />For a Particular Member ID
19
+ <input type="text" name="member_id" size="5" value="" />
20
+ <br /> <strong> OR </strong>
21
+ <br /><input type="radio" checked="checked" value="all" name="swpm_link_for" /> For All Pending Registrations
22
+ </tr>
23
+ <tr>
24
+ <td>Registration Completion Links Will Appear Below:<br/>
25
+ <?php foreach ($links as $key=>$link):?>
26
+ <input type="text" size="100" readonly="readonly" name="link[<?= $key?>]" value="<?= $link;?>"/><br/>
27
+ <?php endforeach;?>
28
+ </td>
29
+ </tr>
30
+ <tr>
31
+ <td>Send Registration Reminder Email too <input type="checkbox" value="checked" name="swpm_reminder_email"></td>
32
+ </tr>
33
+ <tr>
34
+ <td><input type="submit" name="submit" class="button-primary" value="Submit" /></td>
35
+ </tr>
36
+ </table>
37
+ </form>
38
+
39
+ </div></div>
40
+
41
+ </div></div><!-- end of poststuff and post-body -->
42
+ </div><!-- end of wrap -->
views/edit.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <form id="swpm-editprofile-form" name="swpm-editprofile-form" method="post" action="">
2
+ <table>
3
+ <tr>
4
+ <td><label for="user_name">User Name</label></td>
5
+ <td><?= $user_name?></td>
6
+ </tr>
7
+ <tr>
8
+ <td><label for="email">Email</label></td>
9
+ <td><?= $email;?></td>
10
+ </tr>
11
+ <tr>
12
+ <td><label for="password">Password</label></td>
13
+ <td><input type="text" id="password" value="" tabindex="3" size="50" name="password" /></td>
14
+ </tr>
15
+ <tr>
16
+ <td><label for="password_re">Repeat Password</label></td>
17
+ <td><input type="text" id="password_re" value="" tabindex="4" size="50" name="password_re" /></td>
18
+ </tr>
19
+ <tr>
20
+ <td><label for="first_name">First Name</label></td>
21
+ <td><input type="text" id="first_name" value="<?= $first_name;?>" tabindex="5" size="50" name="first_name" /></td>
22
+ </tr>
23
+ <tr>
24
+ <td><label for="last_name">Last Name</label></td>
25
+ <td><input type="text" id="last_name" value="<?= $last_name;?>" tabindex="6" size="50" name="last_name" /></td>
26
+ </tr>
27
+ <tr>
28
+ <td><label for="phone">Phone</label></td>
29
+ <td><input type="text" id="phone" value="<?= $phone;?>" tabindex="7" size="50" name="phone" /></td>
30
+ </tr>
31
+ <tr>
32
+ <td><label for="address_street">Street</label></td>
33
+ <td><input type="text" id="address_street" value="<?= $address_street;?>" tabindex="8" size="50" name="address_street" /></td>
34
+ </tr>
35
+ <tr>
36
+ <td><label for="address_city">City</label></td>
37
+ <td><input type="text" id="address_city" value="<?= $address_city;?>" tabindex="9" size="50" name="address_city" /></td>
38
+ </tr>
39
+ <tr>
40
+ <td><label for="address_state">State</label></td>
41
+ <td><input type="text" id="address_state" value="<?= $address_state;?>" tabindex="10" size="50" name="address_state" /></td>
42
+ </tr>
43
+ <tr>
44
+ <td><label for="address_zipcode">Zipcode</label></td>
45
+ <td><input type="text" id="address_zipcode" value="<?= $address_zipcode;?>" tabindex="11" size="50" name="address_zipcode" /></td>
46
+ </tr>
47
+ <tr>
48
+ <td><label for="country">Country</label></td>
49
+ <td><input type="text" id="country" value="<?= $country;?>" tabindex="12" size="50" name="country" /></td>
50
+ </tr>
51
+ <tr>
52
+ <td><label for="membership_level">Membership Level</label></td>
53
+ <td>
54
+ <?= $membership_level_alias;?>
55
+ </td>
56
+ </tr>
57
+ </table>
58
+ <p align="center"><input type="submit" value="Update" tabindex="6" id="submit" name="swpm_editprofile_submit" /></p>
59
+ <input type="hidden" name="action" value="custom_posts" />
60
+ <?php wp_nonce_field( 'name_of_my_action','name_of_nonce_field' ); ?>
61
+ </form>
views/forgot_password.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="swpm-password-reset-widget-form">
2
+ <form id="swpm-reset-form" name="swpm-reset-form" method="post" action="">
3
+ <table width="95%" border="0" cellpadding="3" cellspacing="5" class="forms">
4
+ <tr>
5
+ <td colspan="2"><label for="swpm_reset_email" class="swpm_label">Email Address</label></td>
6
+ </tr>
7
+ <tr>
8
+ <td colspan="2"><input type="text" class="swpm_text_field" id="swpm_reset_email" value="" size="40" name="swpm_reset_email" /></td>
9
+ </tr>
10
+ <tr>
11
+ <td colspan="2">
12
+ <input type="submit" name="swpm-reset" value="Reset Password"/>
13
+ </td>
14
+ </tr>
15
+ </table>
16
+ </form>
17
+ </div>
views/join_us.php ADDED
File without changes
views/loggedin.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <table>
2
+ <tr>
3
+ <td>Logged in as</td>
4
+ <td><b><?php echo $auth->userData->user_name;?><b></td>
5
+ </tr>
6
+ <tr>
7
+ <td>Account Status</td>
8
+ <td><b><?php echo ucfirst($auth->userData->account_state);?></b></td>
9
+ </tr>
10
+ <tr>
11
+ <td>Membership</td>
12
+ <td><b><?php echo $auth->userData->permitted->get('alias');?></b></td>
13
+ </tr>
14
+ <tr>
15
+ <td colspan="2"><a href="?swpm-logout=true">Logout</a></td>
16
+ </tr>
17
+ </table>
views/login.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="swpm-login-widget-form">
2
+ <form id="swpm-login-form" name="swpm-login-form" method="post" action="">
3
+ <table width="95%" border="0" cellpadding="3" cellspacing="5" class="forms">
4
+ <tr>
5
+ <td colspan="2"><label for="login_user_name" class="eMember_label">User Name</label></td>
6
+ </tr>
7
+ <tr>
8
+ <td colspan="2"><input type="text" class="swpm_text_field" id="swpm_user_name" value="" size="30" name="swpm_user_name" /></td>
9
+ </tr>
10
+ <tr>
11
+ <td colspan="2"><label for="login_pwd" class="eMember_label">Password</label></td>
12
+ </tr>
13
+ <tr>
14
+ <td colspan="2"><input type="password" class="swpm_text_field" id="swpm_password" value="" size="30" name="swpm_password" /></td>
15
+ </tr>
16
+ <tr>
17
+ <td colspan="2"><input type="checkbox" name="rememberme" value="checked='checked'"> Remember Me</td>
18
+ </tr>
19
+ <tr>
20
+ <td colspan="2">
21
+ <input type="submit" name="swpm-login" value="Login"/>
22
+ </td>
23
+ </tr>
24
+ <tr>
25
+ <td colspan="2">
26
+ <a id="forgot_pass" href="<?php echo $password_reset_url;?>">Forgot Password?</a>
27
+ </td>
28
+ </tr>
29
+ <tr>
30
+ <td colspan="2"><a id="register" class="register_link" href="<?php echo $join_url; ?>">Join Us</a></td>
31
+ </tr>
32
+ <tr>
33
+ <td colspan="2"><span> <?php echo $auth->get_message();?> </span></td>
34
+ </tr>
35
+ </table>
36
+ </form>
37
+ </div>
views/login_widget.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php include('login.php');?>
2
+ <!--<form id="swpm-login-form" name="swpm-login-form" method="post" action="">
3
+ <p>
4
+ <label for="swpm_user_name">User Name</label>
5
+ <input type="text" id="swpm_user_name" value="" size="30" name="swpm_user_name" />
6
+ </p>
7
+ <p>
8
+ <label for="swpm_password">Password</label>
9
+ <input type="password" id="swpm_password" value="" size="30" name="swpm_password" />
10
+ </p>
11
+ <p>
12
+ <input type="submit" name="swpm-login" value="Login"/>
13
+ <input type="checkbox" name="rememberme" value="checked='checked'">Remember Me
14
+ <span><?php echo $auth->get_message();?></span>
15
+ </p>
16
+ </form>-->
views/login_widget_logged.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <ul class="xoxo">
3
+ <li id="text-1" class="widget widget_text"><h3 class="widgettitle">Logged in as</h3>
4
+ <div class="textwidget"><b><?php echo $auth->userData->user_name;?><b></div>
5
+ </li>
6
+ <li id="text-2" class="widget widget_text"><h3 class="widgettitle">Account Status</h3>
7
+ <div class="textwidget"><b><?php echo ucfirst($auth->userData->account_state);?></b></div>
8
+ </li>
9
+ <li id="text-2" class="widget widget_text"><h3 class="widgettitle">Membership</h3>
10
+ <div class="textwidget"><b><?php echo $auth->userData->permitted->get('alias');?></b></div>
11
+ </li>
12
+ <li id="text-2" class="widget widget_text">
13
+ <a href="?swpm-logout=true">Logout</a>
14
+ </li>
15
+ </ul>