PluginProbe
OttoKit: All-in-One Automation Platform / 1.0.42
OttoKit: All-in-One Automation Platform v1.0.42
1.1.38 1.1.37 1.1.36 1.1.35 1.1.34 1.1.33 1.1.32 1.1.31 1.1.30 1.1.29 1.1.28 1.1.27 1.1.9 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 All 124 releases
suretriggers / src / Integrations / buddyboss / buddyboss.php
buddyboss.php
136 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * BuddyBoss integration class file
4 *
5 * @package SureTriggers
6 * @since 1.0.0
7 */
8
9 namespace SureTriggers\Integrations\BuddyBoss;
10
11 use SureTriggers\Controllers\IntegrationsController;
12 use SureTriggers\Integrations\Integrations;
13 use SureTriggers\Traits\SingletonLoader;
14
15 /**
16 * Class BuddyBoss
17 *
18 * @package SureTriggers\Integrations\BuddyBoss
19 */
20 class BuddyBoss extends Integrations {
21
22 use SingletonLoader;
23
24 /**
25 * ID of the integration
26 *
27 * @var string
28 */
29 protected $id = 'BuddyBoss';
30
31 /**
32 * BuddyBoss constructor.
33 */
34 public function __construct() {
35 add_filter(
36 'bp_notifications_get_registered_components',
37 [
38 $this,
39 'st_bdb_component',
40 ],
41 99,
42 2
43 );
44
45 add_filter(
46 'bp_notifications_get_notifications_for_user',
47 [
48 $this,
49 'st_bdb_notification_content',
50 ],
51 99,
52 8
53 );
54 parent::__construct();
55 }
56
57 /**
58 * Add Sure Triggers component
59 *
60 * @param array $component_names component names.
61 * @param array $active_components active components.
62 * @return array
63 */
64 public function st_bdb_component( $component_names, $active_components ) {
65 $component_names = ! is_array( $component_names ) ? [] : $component_names;
66 array_push( $component_names, 'suretriggers' );
67 return $component_names;
68 }
69
70 /**
71 * Update notification Content for SureTrigger Notifications.
72 *
73 * @param string $content content.
74 * @param int $item_id item id.
75 * @param int $secondary_item_id secondary item id.
76 * @param int $action_item_count action item count.
77 * @param string $format format.
78 * @param string $component_action_name component action name.
79 * @param string $component_name component name.
80 * @param int $id id.
81 * @return array|string
82 */
83 public function st_bdb_notification_content( $content, $item_id, $secondary_item_id, $action_item_count, $format, $component_action_name, $component_name, $id ) {
84 if ( 'sure-triggers_bb_notification' === $component_action_name ) {
85 $notification_content = bp_notifications_get_meta( $id, 'st_notification_content' );
86 $notification_link = bp_notifications_get_meta( $id, 'st_notification_link' );
87
88 if ( 'string' === $format ) {
89 if ( '' !== $notification_link ) {
90 $notification_content = '<a href="' . esc_url( $notification_link ) . '">' . $notification_content . '</a>';
91 }
92 return $notification_content;
93 } elseif ( 'object' === $format ) {
94 return [
95 'text' => $notification_content,
96 'link' => $notification_link,
97 ];
98 }
99 }
100
101 return $content;
102 }
103
104 /**
105 * Check if content has links.
106 *
107 * @param string $content content.
108 * @return array|string
109 */
110 public static function st_content_has_links( $content ) {
111 // Define a regular expression pattern to match URLs.
112 $pattern = '/<a\b[^>]*href=["\']([^"\'#]+)/i';
113
114 // Use preg_match_all to find all links in the content.
115 preg_match_all( $pattern, $content, $matches );
116
117 // Return the array of matched links.
118 return isset( $matches[1] ) ? $matches[1] : [];
119 }
120
121 /**
122 * Check plugin is installed.
123 *
124 * @return bool
125 */
126 public function is_plugin_installed() {
127 if ( function_exists( 'buddypress' ) && isset( buddypress()->buddyboss ) && buddypress()->buddyboss ) {
128 return true;
129 } else {
130 return false;
131 }
132 }
133 }
134
135 IntegrationsController::register( BuddyBoss::class );
136