PluginProbe ʕ •ᴥ•ʔ
OttoKit: All-in-One Automation Platform / trunk
OttoKit: All-in-One Automation Platform vtrunk
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 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.47 1.0.48 1.0.49 1.0.50 1.0.51 1.0.52 1.0.53 1.0.54 1.0.55 1.0.56 1.0.57 1.0.58 1.0.59 1.0.60 1.0.61 1.0.62 1.0.63 1.0.64 1.0.65 1.0.66 1.0.67 1.0.68 1.0.69 1.0.7 1.0.70 1.0.71 1.0.72 1.0.73 1.0.74 1.0.75 1.0.76 1.0.77 1.0.78 1.0.79 1.0.8 1.0.80 1.0.81 1.0.82 1.0.83 1.0.84 1.0.85 1.0.86 1.0.87 1.0.88 1.0.89 1.0.9 1.0.90 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8
suretriggers / src / Controllers / IntegrationsController.php
suretriggers / src / Controllers Last commit date
AuthController.php 3 months ago AutomationController.php 11 months ago EventController.php 11 months ago GlobalSearchController.php 2 weeks ago IntegrationsController.php 11 months ago OptionController.php 3 years ago RestController.php 4 weeks ago RoutesController.php 1 year ago SettingsController.php 10 months ago WebhookRequestsController.php 1 month ago
IntegrationsController.php
150 lines
1 <?php
2 /**
3 * File Integrations Controller.
4 * php version 5.6
5 *
6 * @package SureTrigger
7 */
8
9 namespace SureTriggers\Controllers;
10
11 use RecursiveDirectoryIterator;
12 use RecursiveIteratorIterator;
13 use ReflectionClass;
14 use SureTriggers\Integrations\Integrations;
15 use SureTriggers\Traits\SingletonLoader;
16 use WP_REST_Request;
17 use WP_REST_Response;
18
19 /**
20 * Class IntegrationsController
21 *
22 * @package SureTriggers\Controllers
23 */
24 class IntegrationsController {
25
26 use SingletonLoader;
27
28 /**
29 * Get registered pluggable variables.
30 *
31 * @return mixed|void
32 */
33 public static function get_registered_pluggable_variables() {
34 return apply_filters( 'sure_trigger_register_pluggable_variables', [] );
35 }
36
37 /**
38 * Registering integration classes
39 *
40 * @param string $class Integration class name.
41 *
42 * @return void
43 */
44 public static function register( $class ) {
45 add_filter(
46 'sure_trigger_integrations',
47 function ( $integrations_classes ) use ( $class ) {
48
49 $obj = new $class();
50
51 $integrations_classes[ $obj->get_id() ] = $obj;
52
53 return $integrations_classes;
54 },
55 99
56 );
57 }
58
59 /**
60 * Include activated integrations events files
61 *
62 * @return void
63 */
64 public static function load_event_files() {
65 /**
66 * Get integration class and check if the class is activated
67 * If yes, then include those classes event files.
68 */
69 $integrations_classes = self::get_integrations();
70 foreach ( $integrations_classes as $class ) {
71
72 if ( $class->is_enabled() ) {
73 $reflector = new ReflectionClass( $class );
74 $event_files = new RecursiveDirectoryIterator( dirname( $reflector->getFileName() ) );
75 foreach ( new RecursiveIteratorIterator( $event_files ) as $filename => $file ) {
76 if ( $file->isFile() ) {
77 require_once $filename;
78 }
79 }
80 }
81 }
82 }
83
84 /**
85 * Get all integration classes
86 *
87 * @return Integrations[]
88 */
89 public static function get_integrations() {
90 return apply_filters( 'sure_trigger_integrations', [] );
91 }
92
93 /**
94 * Get integration which plugins are activated.
95 *
96 * @return array
97 */
98 public static function get_activated_integrations() {
99 $integrations_classes = self::get_integrations();
100 $allowed_integrations = [];
101
102 foreach ( $integrations_classes as $integration => $class ) {
103 if ( 'WordPress' === $integration ) {
104 continue;
105 }
106
107 if ( $class->is_enabled() ) {
108 $allowed_integrations [] = $integration;
109 }
110 }
111
112 return $allowed_integrations;
113 }
114
115 /**
116 * Verify child integration
117 *
118 * @param WP_REST_Request $request Request data.
119 * @return object
120 */
121 public function child_integration_verify( $request ) {
122 $plugin_url = admin_url( 'plugins.php' );
123 if ( $request->get_param( 'integration_plugin' ) ) {
124 $is_plugin_active = false;
125
126 $plugin = $request->get_param( 'integration_plugin' );
127
128 $integration_class_name = $plugin['key'];
129
130 $fully_qualified_class_name = "\SureTriggers\Integrations\\$integration_class_name\\$integration_class_name";
131
132 if ( class_exists( $fully_qualified_class_name ) ) {
133 $class_obj = new $fully_qualified_class_name();
134 if ( method_exists( $class_obj, 'is_plugin_installed' ) ) {
135 $is_plugin_active = $class_obj->is_plugin_installed();
136 }
137 }
138
139 if ( $is_plugin_active ) {
140 return RestController::success_message( [ 'Integration is verified and has all necessary plugins installed.' ] );
141 } else {
142 return RestController::error_message( sprintf( 'To use %1s integration, you must have installed and activated %1$s on your <a class="text-app-primary" target="_blank" href="%2$s"> WordPress website</a>.', $plugin['name'], $plugin_url ), 200 );
143 }
144 }
145
146 return RestController::error_message( 'No integration details provided.', 200 );
147 }
148
149 }
150