PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.7.7
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.7.7
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / Modules / PushNotification / PushNotificationModule.php

PushNotificationModule.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.7.7, at Modules/PushNotification/PushNotificationModule.php

118 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\Modules\PushNotification;
4
5 use FluentCommunity\App\Services\Helper;
6 use FluentCommunity\Framework\Support\Arr;
7
8 class PushNotificationModule
9 {
10 public function register()
11 {
12 if (!defined('FLUENT_NOTIFY_PLUGIN_VERSION') || !\FluentNotify\App\Services\Helper::isEnabled()) {
13 return;
14 }
15
16 $commentActions = [
17 'fluent_community/notification/comment/notifed_to_author',
18 // 'fluent_community/notification/comment/notifed_to_author',
19 'fluent_community/notification/comment/notifed_to_mentions',
20 //'fluent_community/notification/comment/notifed_to_other_users',
21 'fluent_community/notification/comment/notifed_to_thread_commetenter',
22 ];
23 foreach ($commentActions as $action) {
24 add_action($action, [ $this, 'handleCommentNotification' ], 10, 1);
25 }
26
27 // let's load the assets
28 add_filter('fluent_community/portal_data_vars', function ($vars) {
29 if (!is_user_logged_in()) {
30 return $vars;
31 }
32
33 $vars['js_files']['push_notification'] = [
34 'url' => \FluentNotify\App\Vite::getStaticSrcUrl('push_notification.js'),
35 'deps' => [],
36 ];
37 $vars['js_vars']['fluentNotifyPublic'] = \FluentNotify\App\Services\Helper::getPublicConfig();
38
39 return $vars;
40 });
41
42 add_filter('fluent_community/portal_vars', function ($vars) {
43 if (!is_user_logged_in()) {
44 return $vars;
45 }
46
47 $vars['has_push_notification'] = true;
48
49 return $vars;
50 });
51
52 }
53
54 public function handleCommentNotification($eventData)
55 {
56 $key = Arr::get($eventData, 'key');
57 $comment = Arr::get($eventData, 'comment');
58 $feed = Arr::get($eventData, 'feed');
59
60 $xprofile = $comment->xprofile;
61
62 if (!$feed || !$comment) {
63 return;
64 }
65
66 $notification = Arr::get($eventData, 'notification');
67 $content = Helper::getHumanExcerpt($comment->message, 100);
68 if (!$content) {
69 $content = Helper::getHumanExcerpt($notification->content, 100);
70 }
71
72 $commenter = $xprofile ? $xprofile->display_name : '' . __('Someone', 'fluent-community');
73 $feedTitle = $feed->title ? $feed->title : __('post', 'fluent-community');
74
75 // get the first name only
76 $commenterParts = explode(' ', $commenter);
77 if (count($commenterParts) > 0) {
78 $commenter = $commenterParts[0];
79 }
80
81 $title = '';
82 switch ($key):
83 case 'notifed_to_author':
84 /* translators: %1$s is the commenter name, %2$s is the post title */
85 $title = \sprintf(__('💬 by %1$s: %2$s', 'fluent-community'), $commenter, $feedTitle);
86 break;
87 case 'notifed_to_mentions':
88 /* translators: %1$s is the commenter name, %2$s is the post title */
89 $title = \sprintf(__('%1$s mentioned you on: %2$s', 'fluent-community'), $commenter, $feedTitle);
90 break;
91 case 'notifed_to_other_users':
92 /* translators: %1$s is the commenter name, %2$s is the post title */
93 $title = \sprintf(__('New comment by %1$s on: %2$s', 'fluent-community'), $commenter, $feedTitle);
94 break;
95 case 'notifed_to_thread_commetenter':
96 /* translators: %1$s is the commenter name, %2$s is the post title */
97 $title = \sprintf(__('%1$s replied to a comment on: %2$s', 'fluent-community'), $commenter, $feedTitle);
98 break;
99 default:
100 /* translators: %1$s is the commenter name, %2$s is the post title */
101 $content = \sprintf(__('Comment by %1$s on %2$s', 'fluent-community'), $commenter, $feedTitle);
102 endswitch;
103
104 $userIds = Arr::get($eventData, 'user_ids', []);
105 $feedPermalik = $feed->getPermalink() . '?comment_id=' . $comment->id;
106
107 do_action('fluent_notify/schedule_notifications', $userIds, [
108 'user_ids' => $userIds,
109 'title' => $title,
110 'message' => $content,
111 'action_url' => $feedPermalik,
112 'icon' => $xprofile->avatar,
113 'source' => 'community_comment',
114 'source_id' => $comment->id,
115 ]);
116 }
117 }
118