PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.4.01
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.4.01
2.11.0 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 All 78 releases
fluent-community / Modules / PushNotification / PushNotificationModule.php

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

113 lines 3.9 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 switch ($key):
82 case 'notifed_to_author':
83 $title = \sprintf(__('💬 by %1$s: %2$s', 'fluent-community'), $commenter, $feedTitle);
84 break;
85 case 'notifed_to_mentions':
86 $title = \sprintf(__('%1$s mentioned you on: %2$s', 'fluent-community'), $commenter, $feedTitle);
87 break;
88 case 'notifed_to_other_users':
89 $title = \sprintf(__('New comment by %1$s on: %2$s', 'fluent-community'), $commenter, $feedTitle);
90 break;
91 case 'notifed_to_thread_commetenter':
92 $title = \sprintf(__('%1$s replied to a comment on: %2$s', 'fluent-community'), $commenter, $feedTitle);
93 break;
94 default:
95 $content = \sprintf(__('Comment by %1$s on %2$s', 'fluent-community'), $commenter, $feedTitle);
96 endswitch;
97
98 $userIds = Arr::get($eventData, 'user_ids', []);
99 $feedPermalik = $feed->getPermalink() . '?comment_id=' . $comment->id;
100
101 do_action('fluent_notify/schedule_notifications', $userIds, [
102 'user_ids' => $userIds,
103 'title' => $title,
104 'message' => $content,
105 'action_url' => $feedPermalik,
106 'icon' => $xprofile->avatar,
107 'source' => 'community_comment',
108 'source_id' => $comment->id,
109 ]);
110 }
111 }
112
113