| 1 |
<?php |
| 2 |
/** |
| 3 |
* Integration base class file |
| 4 |
* |
| 5 |
* @package SureTrigger |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace SureTriggers\Integrations; |
| 10 |
|
| 11 |
use SureTriggers\Controllers\EventController; |
| 12 |
|
| 13 |
if ( ! function_exists( 'is_plugin_active' ) ) { |
| 14 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Class Integrations |
| 19 |
* |
| 20 |
* @package SureTriggers\Integrations |
| 21 |
*/ |
| 22 |
abstract class Integrations { |
| 23 |
|
| 24 |
/** |
| 25 |
* ID of the integration |
| 26 |
* |
| 27 |
* @var string |
| 28 |
*/ |
| 29 |
protected $id; |
| 30 |
|
| 31 |
/** |
| 32 |
* Integration Name |
| 33 |
* |
| 34 |
* @var string |
| 35 |
*/ |
| 36 |
protected $name; |
| 37 |
|
| 38 |
/** |
| 39 |
* Integration Description |
| 40 |
* |
| 41 |
* @var string |
| 42 |
*/ |
| 43 |
protected $description; |
| 44 |
|
| 45 |
/** |
| 46 |
* Integration icon/logo URL |
| 47 |
* |
| 48 |
* @var string |
| 49 |
*/ |
| 50 |
protected $icon_url; |
| 51 |
|
| 52 |
/** |
| 53 |
* Contains configuration form fields. |
| 54 |
* |
| 55 |
* @var array |
| 56 |
*/ |
| 57 |
protected $config_fields = []; |
| 58 |
|
| 59 |
/** |
| 60 |
* Contains saved configurations |
| 61 |
* |
| 62 |
* @var array |
| 63 |
*/ |
| 64 |
protected $config = []; |
| 65 |
|
| 66 |
/** |
| 67 |
* Contains errors list |
| 68 |
* |
| 69 |
* @var array |
| 70 |
*/ |
| 71 |
protected $errors = []; |
| 72 |
|
| 73 |
/** |
| 74 |
* If the form should be verify or not. |
| 75 |
* |
| 76 |
* @var bool |
| 77 |
*/ |
| 78 |
protected $form_validation = false; |
| 79 |
|
| 80 |
/** |
| 81 |
* Get api key page URL |
| 82 |
* |
| 83 |
* @var null|bool |
| 84 |
*/ |
| 85 |
protected $api_page_url = null; |
| 86 |
|
| 87 |
/** |
| 88 |
* Contains it's actions list, if any. For the future usage |
| 89 |
* |
| 90 |
* @var array |
| 91 |
*/ |
| 92 |
protected $actions = []; |
| 93 |
|
| 94 |
/** |
| 95 |
* Contains it's triggers list, if any. For the future usage |
| 96 |
* |
| 97 |
* @var array |
| 98 |
*/ |
| 99 |
protected $triggers = []; |
| 100 |
|
| 101 |
/** |
| 102 |
* Integrations constructor. |
| 103 |
*/ |
| 104 |
public function __construct() { |
| 105 |
$this->process_events(); |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Process and get all events |
| 110 |
* |
| 111 |
* @return void |
| 112 |
*/ |
| 113 |
public function process_events() { |
| 114 |
$events = EventController::get_instance(); |
| 115 |
|
| 116 |
if ( ! empty( $events->triggers[ $this->id ] ) ) { |
| 117 |
$this->triggers = $events->triggers[ $this->id ]; |
| 118 |
} |
| 119 |
|
| 120 |
if ( ! empty( $events->actions[ $this->id ] ) ) { |
| 121 |
$this->actions = $events->actions[ $this->id ]; |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* If enabled or not |
| 127 |
* |
| 128 |
* @return bool |
| 129 |
*/ |
| 130 |
public function is_enabled() { |
| 131 |
return (bool) $this->is_plugin_installed(); |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Check if plugin is installed. |
| 136 |
* |
| 137 |
* @return bool |
| 138 |
*/ |
| 139 |
abstract public function is_plugin_installed(); |
| 140 |
|
| 141 |
/** |
| 142 |
* Returns ID |
| 143 |
* |
| 144 |
* @return string |
| 145 |
*/ |
| 146 |
public function get_id() { |
| 147 |
return $this->id; |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Returns integration name |
| 152 |
* |
| 153 |
* @return string |
| 154 |
*/ |
| 155 |
public function get_name() { |
| 156 |
return $this->name; |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Returns integration description |
| 161 |
* |
| 162 |
* @return string |
| 163 |
*/ |
| 164 |
public function get_description() { |
| 165 |
return $this->description; |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* Get the integration URL |
| 170 |
* |
| 171 |
* @return string |
| 172 |
*/ |
| 173 |
public function get_icon_url() { |
| 174 |
return $this->icon_url; |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* Get config form fields |
| 179 |
* |
| 180 |
* @return array |
| 181 |
*/ |
| 182 |
public function get_config_fields() { |
| 183 |
return $this->config_fields; |
| 184 |
} |
| 185 |
|
| 186 |
/** |
| 187 |
* Get saved |
| 188 |
* |
| 189 |
* @return array |
| 190 |
*/ |
| 191 |
public function get_config() { |
| 192 |
return $this->config; |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Get errors if any |
| 197 |
* |
| 198 |
* @return array |
| 199 |
*/ |
| 200 |
public function get_errors() { |
| 201 |
return $this->errors; |
| 202 |
} |
| 203 |
|
| 204 |
/** |
| 205 |
* Determine if the form is require validation. |
| 206 |
* |
| 207 |
* @return bool |
| 208 |
*/ |
| 209 |
public function form_validation() { |
| 210 |
return $this->form_validation; |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Get API key page URL |
| 215 |
* |
| 216 |
* @return bool|null |
| 217 |
*/ |
| 218 |
public function get_api_page_url() { |
| 219 |
return $this->api_page_url; |
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* Get actions if any |
| 224 |
* |
| 225 |
* @return array |
| 226 |
*/ |
| 227 |
public function get_actions() { |
| 228 |
return $this->actions; |
| 229 |
} |
| 230 |
|
| 231 |
/** |
| 232 |
* Get triggers if any |
| 233 |
* |
| 234 |
* @return array |
| 235 |
*/ |
| 236 |
public function get_triggers() { |
| 237 |
return $this->triggers; |
| 238 |
} |
| 239 |
|
| 240 |
/** |
| 241 |
* Default validation abstract method (optional) |
| 242 |
* |
| 243 |
* @param array $args Form input as $args. |
| 244 |
* |
| 245 |
* @return false |
| 246 |
*/ |
| 247 |
public function validation( $args = [] ) { |
| 248 |
return false; |
| 249 |
} |
| 250 |
} |
| 251 |
|