PluginProbe ʕ •ᴥ•ʔ
Download Manager / trunk
Download Manager vtrunk
3.3.62 3.3.61 3.3.60 3.3.59 3.3.58 3.3.57 3.3.56 trunk 2.1.3 2.3.0 2.5.96 2.5.97 2.6.2 2.6.96 2.8.3 2.9.99 3.0.4 3.1.05 3.1.07 3.1.08 3.1.11 3.1.12 3.1.14 3.1.17 3.1.18 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.2.04 3.2.13 3.2.14 3.2.16 3.2.18 3.2.19 3.2.21 3.2.22 3.2.23 3.2.24 3.2.25 3.2.27 3.2.28 3.2.29 3.2.30 3.2.31 3.2.32 3.2.33 3.2.34 3.2.35 3.2.37 3.2.38 3.2.39 3.2.40 3.2.41 3.2.42 3.2.43 3.2.44 3.2.45 3.2.46 3.2.47 3.2.48 3.2.49 3.2.50 3.2.51 3.2.52 3.2.53 3.2.54 3.2.55 3.2.56 3.2.57 3.2.58 3.2.59 3.2.60 3.2.61 3.2.63 3.2.64 3.2.65 3.2.66 3.2.67 3.2.68 3.2.69 3.2.70 3.2.71 3.2.72 3.2.73 3.2.74 3.2.75 3.2.76 3.2.77 3.2.78 3.2.79 3.2.80 3.2.81 3.2.82 3.2.83 3.2.84 3.2.85 3.2.86 3.2.87 3.2.88 3.2.89 3.2.90 3.2.91 3.2.92 3.2.93 3.2.94 3.2.95 3.2.96 3.2.97 3.2.98 3.2.99 3.3.00 3.3.01 3.3.02 3.3.03 3.3.04 3.3.05 3.3.06 3.3.07 3.3.08 3.3.09 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.15 3.3.16 3.3.17 3.3.18 3.3.19 3.3.20 3.3.21 3.3.22 3.3.23 3.3.24 3.3.25 3.3.26 3.3.27 3.3.28 3.3.29 3.3.30 3.3.31 3.3.32 3.3.33 3.3.34 3.3.35 3.3.36 3.3.37 3.3.38 3.3.39 3.3.40 3.3.41 3.3.42 3.3.43 3.3.44 3.3.45 3.3.46 3.3.47 3.3.48 3.3.49 3.3.50 3.3.51 3.3.52 3.3.53 3.3.54 3.3.55
download-manager / src / User / User.php
download-manager / src / User Last commit date
views 6 hours ago Dashboard.php 4 months ago EditProfile.php 5 months ago Login.php 4 months ago PublicProfile.php 5 months ago Register.php 5 months ago User.php 2 months ago UserController.php 4 months ago
User.php
229 lines
1 <?php
2
3
4 namespace WPDM\User;
5
6
7 use PrivateMessage\__\__;
8 use WPDM\__\Template;
9
10 class User
11 {
12 public $ID;
13 public $name;
14 public $profile;
15 public $avatar;
16 public $description;
17 public $signup_date;
18 public $title;
19 public $following = [];
20 public $contacts = [];
21 public $blocked = [];
22 public $me;
23
24 private static $instance;
25
26 public static function getInstance()
27 {
28 if (self::$instance === null) {
29 self::$instance = new self;
30 }
31 return self::$instance;
32 }
33
34 function __construct($userID = null)
35 {
36 global $current_user;
37
38 $this->ID = $userID ? $userID : get_current_user_id();
39
40 if($this->ID) {
41 $this->profile = get_userdata($this->ID);
42 $this->profile->avatar = get_avatar($this->ID, 512);
43 $this->description = get_user_meta($this->ID, 'description', true);
44 $this->signup_date = wp_date(get_option('date_format'), strtotime($this->profile->user_registered));
45 $this->title = get_user_meta($this->ID, '__wpdm_title', true);
46 $this->name = $this->profile->display_name;
47 $this->avatar = get_avatar($this->ID, 512, '', $this->name, ['class' => 'profile-avatar']);
48 }
49
50 $this->me = $current_user;
51
52 add_shortcode("wpdm_user_favourites", [$this, 'favourites']);
53 add_shortcode('wpdm_members', [$this, 'members']);
54 add_shortcode('wpdm_authors', [$this, 'members']);
55 }
56
57 function getFollowings($userID = null)
58 {
59 if(!is_user_logged_in()) return [];
60 $follower = $userID ? $userID : $this->ID;
61 $followings = get_user_meta($follower, '__wpdm_following', true);
62 $followings = maybe_unserialize($followings);
63 if(!is_array($followings)) $followings = [];
64 $this->following = $followings;
65 return $followings;
66 }
67
68 function getContacts($userID = null)
69 {
70 if(!is_user_logged_in()) return [];
71 $user = $userID ? $userID : $this->ID;
72 $contacts = get_user_meta($user, '__wpdm_contacts', true);
73 $contacts = maybe_unserialize($contacts);
74 if(!is_array($contacts)) $contacts = [];
75 $this->contacts = $contacts;
76 return $contacts;
77 }
78
79 function getBlockedContacts($userID = null)
80 {
81 if(!is_user_logged_in()) return [];
82 $user = $userID ? $userID : $this->ID;
83 $blockedContacts = get_user_meta($user, '__wpdm_blocked_contacts', true);
84 $blockedContacts = maybe_unserialize($blockedContacts);
85 if(!is_array($blockedContacts)) $blockedContacts = [];
86 $this->blocked = $blockedContacts;
87 return $blockedContacts;
88 }
89
90 function follow($userID)
91 {
92 if(!is_user_logged_in()) return false;
93 $this->getFollowings($this->ID);
94 $this->following[$userID] = time();
95 update_user_meta($this->ID, '__wpdm_following', $this->following);
96 return true;
97 }
98
99 function isFollowing($userID)
100 {
101 if(!is_user_logged_in()) return false;
102 $this->getFollowings($this->ID);
103 return isset($this->following[$userID]) ? $this->following[$userID] : false;
104 }
105
106 function unfollow($userID)
107 {
108 if(!is_user_logged_in()) return false;
109 $this->getFollowings($this->ID);
110 if(isset($this->following[$userID])) unset($this->following[$userID]);
111 update_user_meta($this->ID, '__wpdm_following', $this->following);
112 }
113
114 function addToContact($userID)
115 {
116 if(!is_user_logged_in()) return false;
117 $this->getContacts($this->ID);
118 $this->contacts[$userID] = time();
119 update_user_meta($this->ID, '__wpdm_contacts', $this->contacts);
120 return true;
121 }
122
123 function inContactList($userID)
124 {
125 if(!is_user_logged_in()) return false;
126 $this->getContacts($this->ID);
127 return isset($this->contacts[$userID]) ? $this->contacts[$userID] : false;
128 }
129
130 function removeContact($userID)
131 {
132 if(!is_user_logged_in()) return false;
133 $this->getContacts($this->ID);
134 if(isset($this->contacts[$userID])) unset($this->contacts[$userID]);
135 update_user_meta($this->ID, '__wpdm_contacts', $this->contacts);
136 }
137
138
139 function block($userID)
140 {
141 if(!is_user_logged_in()) return false;
142 $this->getBlockedContacts($this->ID);
143 $this->blocked[$userID] = time();
144 update_user_meta($this->ID, '__wpdm_blocked_contacts', $this->blocked);
145 return true;
146 }
147
148 function isBlocked($userID)
149 {
150 if(!is_user_logged_in()) return false;
151 $this->getBlockedContacts($this->ID);
152 return isset($this->blocked[$userID]) ? $this->blocked[$userID] : false;
153 }
154
155 function unblock($userID)
156 {
157 if(!is_user_logged_in()) return false;
158 $this->getBlockedContacts($this->ID);
159 if(isset($this->blocked[$userID])) unset($this->blocked[$userID]);
160 update_user_meta($this->ID, '__wpdm_blocked_contacts', $this->contacts);
161 }
162
163 function favourites($params = array())
164 {
165 global $wpdb, $current_user;
166 if (!isset($params['user']) && !is_user_logged_in()) return WPDM()->user->login->form();
167 ob_start();
168 include Template::locate('user-favourites.php', __DIR__.'/views');
169 return ob_get_clean();
170 }
171
172
173 function members($params = array())
174 {
175 $sid = isset($params['sid']) ? preg_replace('/[^a-zA-Z0-9_\-]/', '', $params['sid']) : '';
176 $params['sid'] = $sid;
177 update_post_meta(get_the_ID(), '__wpdm_users_params' . $sid, $params);
178 ob_start();
179 include Template::locate("members.php", __DIR__.'/views');
180 return ob_get_clean();
181 }
182
183 function listAuthors($params = [])
184
185 {
186
187 if (!$params) $params = get_post_meta(wpdm_query_var('_pid', 'int'), '__wpdm_users_params' . preg_replace('/[^a-zA-Z0-9_\-]/', '', wpdm_query_var('_sid')), true);
188 $page = isset($_REQUEST['cp']) && $_REQUEST['cp'] > 0 ? (int)$_REQUEST['cp'] : 1;
189 $items_per_page = isset($params['items_per_page']) ? $params['items_per_page'] : 12;
190 //$offset = $page * $items_per_page;
191 $cols = isset($params['cols']) && in_array($params['cols'], [1, 2, 3, 4, 6]) ? $params['cols'] : 0;
192 if ($cols > 0) $cols_class = "col-md-" . (12 / $cols);
193
194 $args = array(
195 'role' => isset($params['role']) ? $params['role'] : '',
196 'role__in' => isset($params['role__in']) ? explode(",", $params['role__in']) : array(),
197 'role__not_in' => isset($params['role__not_in']) ? explode(",", $params['role__not_in']) : array(),
198 'meta_key' => isset($params['meta_key']) ? $params['meta_key'] : '',
199 'meta_value' => isset($params['meta_value']) ? $params['meta_value'] : '',
200 'meta_compare' => isset($params['meta_compare']) ? $params['meta_compare'] : '',
201 //'meta_query' => array(),
202 //'date_query' => array(),
203 'include' => isset($params['include']) ? explode(",", $params['include']) : array(),
204 'exclude' => isset($params['exclude']) ? explode(",", $params['exclude']) : array(),
205 'orderby' => isset($params['orderby']) ? $params['orderby'] : 'login',
206 'order' => isset($params['order']) ? $params['order'] : 'DESC',
207 //'offset' => $offset,
208 'search' => isset($params['search']) ? $params['search'] : '',
209 'number' => $items_per_page,
210 'paged' => $page,
211 'count_total' => true,
212 );
213 $users = new \WP_User_Query($args);
214 if ($cols > 0) echo "<div class='row'>";
215 foreach ($users->get_results() as $user) {
216 if (isset($cols_class)) echo "<div class='$cols_class'>";
217 include Template::locate("profile-cards/default.php", __DIR__.'/views');
218 if (isset($cols_class)) echo "</div>";
219 }
220 if ($cols > 0) echo "</div>";
221 $total = $users->get_total();
222 $contid = isset($params['sid']) ? "-{$params['sid']}" : '';
223 if (isset($params['paging']) && (int)$params['paging'] == 1)
224 echo wpdm_paginate_links($total, $items_per_page, $page, 'cp', array('async' => 1, 'container' => "#wpdm-authors{$contid}"));
225 }
226
227
228 }
229