PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 3.2.2
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v3.2.2
4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / ShortcodeParser / Builder / FrontendProfileBuilder.php
wp-user-avatar / src / ShortcodeParser / Builder Last commit date
EditProfileBuilder.php 5 years ago FieldsShortcodeCallback.php 4 years ago FrontendProfileBuilder.php 4 years ago GlobalShortcodes.php 4 years ago LoginFormBuilder.php 5 years ago PasswordResetBuilder.php 5 years ago RegistrationFormBuilder.php 5 years ago index.php 5 years ago
FrontendProfileBuilder.php
710 lines
1 <?php
2
3 namespace ProfilePress\Core\ShortcodeParser\Builder;
4
5 use ProfilePress\Core\Classes\ExtensionManager as EM;
6 use ProfilePress\Core\Classes\PROFILEPRESS_sql;
7 use ProfilePress\Core\Classes\UserAvatar;
8
9 class FrontendProfileBuilder
10 {
11 /** @var \WP_User user_data */
12 static private $user_data;
13
14 /**
15 * Define all front-end profile sub-shortcode.
16 *
17 * @param $user
18 */
19 public function __construct($user)
20 {
21 self::$user_data = $user;
22
23 add_shortcode('profile-username', array($this, 'profile_username'));
24
25 add_shortcode('profile-email', array($this, 'profile_email'));
26
27 add_shortcode('profile-website', array($this, 'profile_website'));
28
29 add_shortcode('profile-nickname', array($this, 'profile_nickname'));
30
31 add_shortcode('profile-display-name', array($this, 'profile_display_name'));
32
33 add_shortcode('profile-first-name', array($this, 'profile_first_name'));
34
35 add_shortcode('profile-last-name', array($this, 'profile_last_name'));
36
37 add_shortcode('profile-bio', array($this, 'profile_bio'));
38
39 add_shortcode('profile-cpf', array($this, 'profile_custom_profile_field'));
40 add_shortcode('profile-file', array($this, 'profile_user_uploaded_file'));
41
42 add_shortcode('profile-cover-image-url', array($this, 'cover_image_url'));
43
44 add_shortcode('profile-avatar-url', array($this, 'user_avatar_url'));
45 add_shortcode('user-avatar-url', array($this, 'user_avatar_url')); // backward compat
46
47 add_shortcode('profile-hide-empty-data', array($this, 'hide_empty_data'));
48
49 add_shortcode('post-count', array($this, 'post_count'));
50 add_shortcode('profile-post-count', array($this, 'post_count'));
51
52 add_shortcode('comment-count', array($this, 'get_comment_count'));
53 add_shortcode('profile-comment-count', array($this, 'get_comment_count'));
54
55 add_shortcode('profile-post-list', array($this, 'author_post_list'));
56 add_shortcode('profile-comment-list', array($this, 'author_comment_list'));
57
58 add_shortcode('profile-author-posts-url', array($this, 'author_post_url'));
59
60 add_shortcode('profile-date-registered', array($this, 'date_user_registered'));
61
62 add_shortcode('jcarousel-author-posts', array($this, 'pp_jcarousel_author_posts'));
63
64 /**
65 * @param object $user WP_User object
66 */
67 do_action('ppress_register_profile_shortcode', $user);
68 }
69
70 public function date_user_registered()
71 {
72 return date('F jS, Y', strtotime(self::$user_data->user_registered));
73 }
74
75 public function author_post_url()
76 {
77 return get_author_posts_url(self::$user_data->ID);
78 }
79
80 public static function author_posts_query($user_id, $attributes)
81 {
82 $attributes = shortcode_atts(array('limit' => 10, 'offset' => 0), $attributes);
83
84 $limit = absint($attributes['limit']);
85 $offset = absint($attributes['offset']);
86
87 $posts = get_posts(
88 apply_filters('ppress_frontend_profile_author_post_list_args', [
89 'author' => $user_id,
90 'posts_per_page' => $limit,
91 'offset' => $offset
92 ], $user_id, $attributes)
93 );
94
95 $output = '';
96
97 if ( ! empty($posts)) {
98
99 $output .= "<ul class='pp-user-post-list'>";
100 /** @var \WP_Post $post */
101 foreach ($posts as $post) {
102 $output .= sprintf('<li class="pp-user-post-item"><a href="%s"><h3 class="pp-post-item-head">%s</h3></a></li>', get_permalink($post->ID), $post->post_title);
103 }
104
105 $output .= "</ul>";
106
107 } else {
108
109 $note = esc_html__('This user has not created any post.', 'wp-user-avatar');
110
111 if (self::$user_data->ID == get_current_user_id()) {
112 $note = esc_html__('You have not created any post.', 'wp-user-avatar');
113 }
114
115 $output .= sprintf('<div class="pp-user-comment-no-item"><span>%s</span></div>', $note);
116 }
117
118 return [
119 'structure' => $output,
120 'total_post_count' => is_array($posts) ? count($posts) : 0
121 ];
122 }
123
124 public function author_post_list($attributes)
125 {
126 $result = self::author_posts_query(self::$user_data->ID, $attributes);
127
128 return $result['structure'];
129 }
130
131 public static function author_comment_query($user_id, $attributes)
132 {
133 $attributes = shortcode_atts(array('limit' => 10, 'offset' => 0), $attributes);
134
135 $limit = absint($attributes['limit']);
136 $offset = absint($attributes['offset']);
137
138 $comments = get_comments([
139 'number' => $limit,
140 'user_id' => $user_id,
141 'post_status' => ['publish'],
142 'status' => 'approve',
143 'offset' => $offset
144 ]);
145
146 $output = '';
147
148 if ( ! empty($comments)) {
149
150 $output .= '<div class="pp-user-comment-list">';
151 /** @var \WP_Comment $comment */
152 foreach ($comments as $comment) {
153 $output .= '<div class="pp-user-comment-item">';
154 $output .= '<div class="pp-user-comment-item-link">';
155 $output .= sprintf(
156 '<a href="%s">%s</a>',
157 esc_url(get_comment_link($comment->comment_ID)),
158 get_comment_excerpt($comment->comment_ID)
159 );
160 $output .= '</div>';
161 $output .= '<div class="pp-user-comment-item-meta">';
162 $output .= sprintf('On <a href="%s">%s</a>', get_permalink($comment->comment_post_ID), get_the_title($comment->comment_post_ID));
163 $output .= '</div>';
164 $output .= '</div>';
165 }
166
167 $output .= "</div>";
168
169 } else {
170
171 $note = esc_html__('This user has not made any comment.', 'wp-user-avatar');
172
173 if (self::$user_data->ID == get_current_user_id()) {
174 $note = esc_html__('You have not made any comment.', 'wp-user-avatar');
175 }
176
177 $output .= sprintf('<div class="pp-user-comment-no-item"><span>%s</span></div>', $note);
178 }
179
180 return [
181 'structure' => $output,
182 'comment_count' => is_array($comments) ? count($comments) : 0
183 ];
184 }
185
186 public function author_comment_list($attributes)
187 {
188 $result = self::author_comment_query(self::$user_data->ID, $attributes);
189
190 return $result['structure'];
191 }
192
193 /**
194 * Profile username
195 *
196 * @return mixed
197 */
198 public function profile_username()
199 {
200 $capitalization = apply_filters('ppress_capitalize_username', true);
201
202 $username = self::$user_data->user_login;
203
204 $username = $capitalization ? ucwords($username) : $username;
205
206 return apply_filters('ppress_profile_username', $username, self::$user_data);
207 }
208
209
210 /**
211 * User email
212 *
213 * @return mixed
214 */
215 public function profile_email()
216 {
217 return apply_filters('ppress_profile_email', self::$user_data->user_email, self::$user_data);
218 }
219
220 /**
221 * Return user avatar image url
222 *
223 * @return string image url
224 */
225 public function user_avatar_url()
226 {
227 $user_id = self::$user_data->ID;
228
229 return apply_filters('ppress_profile_avatar_url', get_avatar_url($user_id, ['ppress-full' => true]), self::$user_data);
230 }
231
232 /**
233 * Return user cover photo url
234 *
235 * @return string image url
236 */
237 public function cover_image_url()
238 {
239 $user_id = self::$user_data->ID;
240
241 return apply_filters('ppress_profile_avatar_url', ppress_get_cover_image_url($user_id), self::$user_data);
242 }
243
244 /**
245 * User website URL
246 *
247 * @return mixed
248 */
249 public function profile_website()
250 {
251 return apply_filters('ppress_profile_website', self::$user_data->user_url, self::$user_data);
252 }
253
254 /**
255 * Nickname of user
256 *
257 * @return mixed
258 */
259 public function profile_nickname()
260 {
261 return apply_filters('ppress_profile_nickname', ucwords(self::$user_data->nickname), self::$user_data);
262 }
263
264 /**
265 * Display name of profile
266 *
267 * @return mixed
268 */
269 public function profile_display_name($atts = false)
270 {
271 $display_name = self::$user_data->display_name;
272
273 if ( ! empty($atts['format']) && ! empty(self::$user_data->first_name) && ! empty(self::$user_data->last_name)) {
274
275 switch ($atts['format']) {
276 case 'first_last_names':
277 $display_name = self::$user_data->first_name . ' ' . self::$user_data->last_name;
278 break;
279 case 'last_first_names':
280 $display_name = self::$user_data->last_name . ' ' . self::$user_data->first_name;
281 break;
282 case 'first_name_initial_l':
283 $display_name = self::$user_data->first_name . ' ' . self::$user_data->last_name[0];
284 break;
285 case 'f_initial_last_name':
286 $display_name = self::$user_data->first_name[0] . ' ' . self::$user_data->last_name;
287 break;
288 }
289 }
290
291 return apply_filters('ppress_profile_display_name', ucwords($display_name), self::$user_data);
292 }
293
294 /**
295 * Profile first name
296 *
297 * @return mixed
298 */
299 public function profile_first_name()
300 {
301 return apply_filters('ppress_profile_first_name', ucwords(self::$user_data->first_name), self::$user_data);
302 }
303
304
305 /**
306 * Last name of user.
307 *
308 * @return mixed
309 */
310 public function profile_last_name()
311 {
312 return apply_filters('ppress_profile_last_name', ucwords(self::$user_data->last_name), self::$user_data);
313 }
314
315 /**
316 * Description/bio of user.
317 *
318 * @return mixed
319 */
320 public function profile_bio()
321 {
322 return apply_filters('ppress_profile_bio', make_clickable(wpautop(wp_kses_post(html_entity_decode(self::$user_data->description)))), self::$user_data);
323 }
324
325 /**
326 * Custom profile data of user.
327 *
328 * @param $atts array shortcode attributes
329 *
330 * @return string
331 */
332 public function profile_custom_profile_field($atts)
333 {
334 if ( ! EM::is_enabled(EM::CUSTOM_FIELDS)) return '';
335
336 $atts = shortcode_atts(
337 array(
338 'key' => '',
339 'default' => '',
340 ),
341 $atts
342 );
343
344 $key = $atts['key'];
345
346 if (empty($key)) return esc_html__('Field key is missing', 'wp-user-avatar');
347
348 $type = PROFILEPRESS_sql::get_field_type($key);
349
350 if ('file' == $type) {
351 return $this->profile_user_uploaded_file($atts);
352 }
353
354 $data = self::$user_data->{$key};
355
356 if (is_array($data)) {
357 $data = implode(', ',
358 array_filter($data, function ($val) {
359 return ! empty($val);
360 })
361 );
362 }
363
364 if (empty($data) && ! ppress_is_boolean($data) && ! empty($atts['default'])) {
365 $data = $atts['default'];
366 }
367
368 return apply_filters('ppress_profile_cpf', $data, self::$user_data);
369 }
370
371 public function profile_user_uploaded_file($atts)
372 {
373 $atts = ppress_normalize_attributes($atts);
374
375 $atts = shortcode_atts(
376 array(
377 'key' => '',
378 'raw' => false,
379 ),
380 $atts
381 );
382
383 $key = $atts['key'];
384
385 $user_upload_data = get_user_meta(self::$user_data->ID, 'pp_uploaded_files', true);
386
387 if (empty($user_upload_data)) return '';
388
389 $filename = $user_upload_data[$key];
390
391 if (empty($filename)) return '';
392
393 $link = PPRESS_FILE_UPLOAD_URL . $filename;
394
395 if ( ! empty($atts['raw']) && ($atts['raw'] === true || $atts['raw'] == 'true')) {
396 $return = $link;
397 } else {
398 $return = "<a href='$link'>$filename</a>";
399 }
400
401 return apply_filters('ppress_profile_file', $return, self::$user_data);
402
403 }
404
405 /**
406 * Return number of post written by a user
407 *
408 * @return int
409 */
410 public function post_count()
411 {
412 return apply_filters('ppress_profile_post_count', count_user_posts(self::$user_data->ID), self::$user_data, true);
413 }
414
415 public function hide_empty_data($atts, $content)
416 {
417 $atts = shortcode_atts(
418 array(
419 'field' => '',
420 'default' => ''
421 ),
422 $atts
423 );
424
425 $key = ! empty($atts['field']) ? strip_tags($atts['field']) : '';
426
427 switch ($key) {
428 case 'username':
429 $key = 'user_login';
430 break;
431 case 'email':
432 $key = 'user_email';
433 break;
434 case 'website':
435 $key = 'user_url';
436 break;
437 case 'nickname':
438 $key = 'nickname';
439 break;
440 case 'display_name':
441 $key = 'display_name';
442 break;
443 case 'first_name':
444 $key = 'first_name';
445 break;
446 case 'last_name':
447 $key = 'last_name';
448 break;
449 case 'bio':
450 $key = 'description';
451 break;
452 }
453
454 if ( ! empty($key) && ! empty(self::$user_data->$key)) {
455 return do_shortcode($content);
456 }
457
458 return ppress_var($atts, 'default', '', true);
459 }
460
461 /**
462 * Return the total comment count made by a user
463 */
464 public function get_comment_count()
465 {
466 global $wpdb;
467 $userId = self::$user_data->ID;
468
469 $count = $wpdb->get_var('
470 SELECT COUNT(comment_ID)
471 FROM ' . $wpdb->comments . '
472 WHERE user_id = "' . $userId . '" AND comment_type = "" AND comment_approved = 1');
473
474 return apply_filters('ppress_profile_comment_count', $count, self::$user_data);
475 }
476
477 protected function jcarousel_css()
478 {
479 ob_start();
480 ?>
481 <style type="text/css">
482 /* jcarousel responsive */
483 a.jcarousel-control-next, a.jcarousel-control-prev {
484 text-decoration: none !important;
485 }
486
487 .pp-jcarousel-wrapper ul li a {
488 color: #5B5B5B;
489 text-decoration: none
490 }
491
492 .pp-jcarousel-wrapper {
493 color: #5B5B5B;
494 background-color: #F5F5F5;
495 margin: 20px auto;
496 position: relative;
497 border: 10px solid #fff;
498 -webkit-border-radius: 5px;
499 -moz-border-radius: 5px;
500 border-radius: 5px;
501 -webkit-box-shadow: 0 0 2px #999;
502 -moz-box-shadow: 0 0 2px #999;
503 box-shadow: 0 0 2px #999;
504 }
505
506 /** Carousel **/
507 .ppjcarousel {
508 position: relative;
509 overflow: hidden;
510 width: 100%;
511 }
512
513 .ppjcarousel ul {
514 width: 20000em;
515 position: relative;
516 list-style: none;
517 margin: 0;
518 padding: 0;
519 }
520
521 .ppjcarousel li {
522 width: 200px;
523 float: left;
524 margin: 1px 3px 1px 0;
525 -moz-box-sizing: border-box;
526 -webkit-box-sizing: border-box;
527 box-sizing: border-box;
528 }
529
530 .ppjcarousel img {
531 display: block;
532 width: 100%;
533 height: 100px !important;
534 }
535
536 .jc-no-post {
537 font-family: inherit;
538 font-size: 15px;
539 padding: 5px;
540 text-align: center;
541 }
542
543 .jc-title {
544 font-family: inherit;
545 font-size: 15px;
546 word-wrap: break-word;
547 padding: 5px;
548 margin: 0 4px;
549 text-align: center;
550 }
551
552 /** Carousel Controls **/
553 .jcarousel-control-prev, .jcarousel-control-next {
554 position: absolute;
555 top: 50%;
556 margin-top: -15px;
557 width: 30px;
558 height: 30px;
559 text-align: center;
560 background: #4E443C;
561 color: #fff;
562 text-decoration: none;
563 text-shadow: 0 0 1px #000;
564 font: 24px/27px Arial, sans-serif;
565 -webkit-border-radius: 30px;
566 -moz-border-radius: 30px;
567 border-radius: 30px;
568 -webkit-box-shadow: 0 0 4px #F0EFE7;
569 -moz-box-shadow: 0 0 4px #F0EFE7;
570 box-shadow: 0 0 4px #F0EFE7;
571 }
572
573 .jcarousel-control-prev {
574 left: 15px;
575 }
576
577 .jcarousel-control-next {
578 right: 15px;
579 }
580
581 /** Carousel Pagination **/
582 .jcarousel-pagination {
583 position: absolute;
584 bottom: -40px;
585 left: 50%;
586 -webkit-transform: translate(-50%, 0);
587 -ms-transform: translate(-50%, 0);
588 -moz-transform: translate(-50%, 0);
589 transform: translate(-50%, 0);
590 margin: 0;
591 }
592
593 .jcarousel-pagination a {
594 text-decoration: none;
595 display: inline-block;
596 font-size: 11px;
597 height: 10px;
598 width: 10px;
599 line-height: 10px;
600 background: #fff;
601 color: #4E443C;
602 border-radius: 10px;
603 text-indent: -9999px;
604 margin-right: 7px;
605 -webkit-box-shadow: 0 0 2px #4E443C;
606 -moz-box-shadow: 0 0 2px #4E443C;
607 box-shadow: 0 0 2px #4E443C;
608 }
609
610 .jcarousel-pagination a.active {
611 background: #4E443C;
612 color: #fff;
613 opacity: 1;
614 -webkit-box-shadow: 0 0 2px #F0EFE7;
615 -moz-box-shadow: 0 0 2px #F0EFE7;
616 box-shadow: 0 0 2px #F0EFE7;
617 }
618 </style>
619 <?php
620 return ppress_minify_css(ob_get_clean());
621 }
622
623 /**
624 * jCarousel author latest post slider
625 *
626 * @param $atts
627 *
628 * @return string
629 */
630 public function pp_jcarousel_author_posts($atts)
631 {
632 wp_enqueue_script('pp-jcarousel', PPRESS_ASSETS_URL . '/js/jcarousel.min.js', array('jquery'), PPRESS_VERSION_NUMBER, true);
633
634 $atts = shortcode_atts(
635 array(
636 'count' => 10,
637 'default' => PPRESS_ASSETS_URL . '/images/frontend/jc_dft_img.jpg',
638 'width' => '',
639 ),
640 $atts
641 );
642
643 $posts = get_posts(
644 array(
645 'post_type' => 'post',
646 'posts_per_page' => (int)$atts['count'],
647 'author' => self::$user_data->ID,
648 )
649 );
650
651 $default_img = $atts['default'];
652 $width = ! empty($atts['width']) ? ' style="width: ' . $atts['width'] . ';"' : null;
653
654 ob_start();
655 echo $this->jcarousel_css();
656 ?>
657 <div class="pp-jcarousel-wrapper"<?php echo $width; ?>>
658 <div class="ppjcarousel">
659 <?php
660 if (empty($posts)) {
661 echo '<div class="jc-no-post">' . apply_filters('jcarousel_no_post', esc_html__('No post written yet.', 'wp-user-avatar')) . '</div>';
662 } else {
663
664 echo '<ul>';
665 foreach ($posts as $post) {
666 $feature_img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium', false);
667
668 $feature_img = isset($feature_img[0]) ? $feature_img[0] : false;
669
670 if ( ! $feature_img) {
671 $feature_img = $default_img;
672 }
673 ?>
674 <li>
675 <a href="<?php echo get_permalink($post->ID); ?>">
676 <img src="<?php echo $feature_img; ?>" alt="<?php echo $post->post_title; ?>">
677
678 <div class="jc-title"><?php echo $post->post_title; ?></div>
679 </a>
680 </li>
681 <?php
682 }
683 echo '</ul>';
684 }
685 ?>
686 </div>
687
688 <?php
689 // hide jcarousel nav link if no post is found
690 if ( ! empty($posts)) { ?>
691 <a href="#" class="jcarousel-control-prev">&lsaquo;</a>
692 <a href="#" class="jcarousel-control-next">&rsaquo;</a>
693 <p class="jcarousel-pagination"></p>
694 <?php } ?>
695 </div>
696 <?php
697 return apply_filters('ppress_jcarousel_author_posts', ob_get_clean(), self::$user_data);
698 }
699
700 public static function get_instance($user = '')
701 {
702 static $instance = false;
703 $user = isset($user) && ! empty($user) ? $user : wp_get_current_user();
704 if ( ! $instance) {
705 $instance = new self($user);
706 }
707
708 return $instance;
709 }
710 }