← All changes
|
includes/integrations/class-abstract-integration.php
+114
-220
1.6.26
→
1.1.1
View file →
| @@ -1,220 +1,114 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * The Integration abstract class | |
| 5 | - * | |
| 6 | - * @since 1.1.0 | |
| 7 | - */ | |
| 8 | -abstract class WeForms_Abstract_Integration { | |
| 9 | - | |
| 10 | - /** | |
| 11 | - * The integration id | |
| 12 | - * | |
| 13 | - * @var bool | |
| 14 | - */ | |
| 15 | - public $id; | |
| 16 | - | |
| 17 | - /** | |
| 18 | - * If the integration is enabled | |
| 19 | - * | |
| 20 | - * @var bool | |
| 21 | - */ | |
| 22 | - public $enabled; | |
| 23 | - | |
| 24 | - /** | |
| 25 | - * Integration title | |
| 26 | - * | |
| 27 | - * @var string | |
| 28 | - */ | |
| 29 | - public $title; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * URL to the integration icon | |
| 33 | - * | |
| 34 | - * @var string | |
| 35 | - */ | |
| 36 | - public $icon; | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * The settings fields for this integrations | |
| 40 | - * | |
| 41 | - * @var array | |
| 42 | - */ | |
| 43 | - public $settings_fields = []; | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * The settings fields for this integrations | |
| 47 | - * | |
| 48 | - * @var array | |
| 49 | - */ | |
| 50 | - protected $template = null; | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * The settings settings_template | |
| 54 | - * | |
| 55 | - * @var array | |
| 56 | - */ | |
| 57 | - protected $settings_template = null; | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * Get the integration title | |
| 61 | - * | |
| 62 | - * @return string | |
| 63 | - */ | |
| 64 | - public function get_title() { | |
| 65 | - return apply_filters( 'weforms_integration_title', $this->title, $this ); | |
| 66 | - } | |
| 67 | - | |
| 68 | - /** | |
| 69 | - * Get the integration id | |
| 70 | - * | |
| 71 | - * @return string | |
| 72 | - */ | |
| 73 | - public function get_id() { | |
| 74 | - return apply_filters( 'weforms_integration_title', $this->id, $this ); | |
| 75 | - } | |
| 76 | - | |
| 77 | - /** | |
| 78 | - * Get intgration icon | |
| 79 | - * | |
| 80 | - * @return string | |
| 81 | - */ | |
| 82 | - public function get_icon() { | |
| 83 | - return apply_filters( 'weforms_integration_icon', $this->icon, $this ); | |
| 84 | - } | |
| 85 | - | |
| 86 | - /** | |
| 87 | - * Check if the integration is enabled | |
| 88 | - * | |
| 89 | - * @return bool | |
| 90 | - */ | |
| 91 | - public function is_enabled() { | |
| 92 | - return $this->enabled == true; | |
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * Check if it's a pro field | |
| 97 | - * | |
| 98 | - * @return bool | |
| 99 | - */ | |
| 100 | - public function is_pro() { | |
| 101 | - return false; | |
| 102 | - } | |
| 103 | - | |
| 104 | - /** | |
| 105 | - * Get the settings fields | |
| 106 | - * | |
| 107 | - * @return array | |
| 108 | - */ | |
| 109 | - public function get_settings_fields() { | |
| 110 | - return $this->settings_fields; | |
| 111 | - } | |
| 112 | - | |
| 113 | - /** | |
| 114 | - * Get the integration settings for the component | |
| 115 | - * | |
| 116 | - * @return array | |
| 117 | - */ | |
| 118 | - public function get_js_settings() { | |
| 119 | - return [ | |
| 120 | - 'id' => $this->get_id(), | |
| 121 | - 'title' => $this->get_title(), | |
| 122 | - 'icon' => $this->get_icon(), | |
| 123 | - 'settings' => $this->get_settings_fields(), | |
| 124 | - 'pro' => $this->is_pro(), | |
| 125 | - ]; | |
| 126 | - } | |
| 127 | - | |
| 128 | - /** | |
| 129 | - * Check if it's the forms page | |
| 130 | - * | |
| 131 | - * @return bool | |
| 132 | - */ | |
| 133 | - public function is_weforms_page() { | |
| 134 | - if ( get_current_screen()->base != 'toplevel_page_weforms' ) { | |
| 135 | - return false; | |
| 136 | - } | |
| 137 | - | |
| 138 | - return true; | |
| 139 | - } | |
| 140 | - | |
| 141 | - /** | |
| 142 | - * Load the individual template file if exists | |
| 143 | - * | |
| 144 | - * @return void | |
| 145 | - */ | |
| 146 | - public function load_template() { | |
| 147 | - if ( !$this->is_weforms_page() ) { | |
| 148 | - return; | |
| 149 | - } | |
| 150 | - | |
| 151 | - if ( !$this->template ) { | |
| 152 | - return; | |
| 153 | - } | |
| 154 | - | |
| 155 | - echo '<script type="text/x-template" id="tmpl-wpuf-integration-' . esc_attr( $this->id ). '">'; | |
| 156 | - include $this->template; | |
| 157 | - echo '</script>'; | |
| 158 | - } | |
| 159 | - | |
| 160 | - /** | |
| 161 | - * Load settings | |
| 162 | - * | |
| 163 | - * @return void | |
| 164 | - */ | |
| 165 | - public function load_settings( $priority = 10 ) { | |
| 166 | - if ( !$this->settings_template ) { | |
| 167 | - return; | |
| 168 | - } | |
| 169 | - | |
| 170 | - add_action( 'weforms_settings_tabs', [ $this, 'settings_tabs' ], $priority ); | |
| 171 | - add_action( 'weforms_settings_tab_content_' . $this->id, [ $this, 'settings_panel' ], $priority ); | |
| 172 | - } | |
| 173 | - | |
| 174 | - /** | |
| 175 | - * Render the settings panel | |
| 176 | - * | |
| 177 | - * @return void | |
| 178 | - */ | |
| 179 | - public function settings_panel() { | |
| 180 | - if ( file_exists( $this->settings_template ) ) { | |
| 181 | - include $this->settings_template; | |
| 182 | - } | |
| 183 | - } | |
| 184 | - | |
| 185 | - /** | |
| 186 | - * Add new tab at settings | |
| 187 | - * | |
| 188 | - * @return void | |
| 189 | - */ | |
| 190 | - public function settings_tabs( $tabs ) { | |
| 191 | - $tabs[ $this->id ] = [ | |
| 192 | - 'label' => $this->title, | |
| 193 | - 'icon' => $this->icon, | |
| 194 | - ]; | |
| 195 | - | |
| 196 | - return $tabs; | |
| 197 | - } | |
| 198 | - | |
| 199 | - /** | |
| 200 | - * Get file prefix | |
| 201 | - * | |
| 202 | - * @return string | |
| 203 | - */ | |
| 204 | - public function get_prefix() { | |
| 205 | - $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; | |
| 206 | - | |
| 207 | - return $prefix; | |
| 208 | - } | |
| 209 | - | |
| 210 | - /** | |
| 211 | - * Get default componenet url | |
| 212 | - * | |
| 213 | - * @return string | |
| 214 | - */ | |
| 215 | - public function module_component_file( $plugin_file ) { | |
| 216 | - $prefix = $this->get_prefix(); | |
| 217 | - | |
| 218 | - return plugins_url( 'component/index' . $prefix . '.js', $plugin_file ); | |
| 219 | - } | |
| 220 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * The Integration abstract class | |
| 5 | + * | |
| 6 | + * @since 1.1.0 | |
| 7 | + */ | |
| 8 | +abstract class WeForms_Abstract_Integration { | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * The integration id | |
| 12 | + * | |
| 13 | + * @var boolean | |
| 14 | + */ | |
| 15 | + public $id; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * If the integration is enabled | |
| 19 | + * | |
| 20 | + * @var boolean | |
| 21 | + */ | |
| 22 | + public $enabled; | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * Integration title | |
| 26 | + * | |
| 27 | + * @var string | |
| 28 | + */ | |
| 29 | + public $title; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * URL to the integration icon | |
| 33 | + * | |
| 34 | + * @var string | |
| 35 | + */ | |
| 36 | + public $icon; | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * The settings fields for this integrations | |
| 40 | + * | |
| 41 | + * @var array | |
| 42 | + */ | |
| 43 | + public $settings_fields = array(); | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * Get the integration title | |
| 47 | + * | |
| 48 | + * @return string | |
| 49 | + */ | |
| 50 | + public function get_title() { | |
| 51 | + return apply_filters( 'weforms_integration_title', $this->title, $this ); | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Get the integration id | |
| 56 | + * | |
| 57 | + * @return string | |
| 58 | + */ | |
| 59 | + public function get_id() { | |
| 60 | + return apply_filters( 'weforms_integration_title', $this->id, $this ); | |
| 61 | + } | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * Get intgration icon | |
| 65 | + * | |
| 66 | + * @return string | |
| 67 | + */ | |
| 68 | + public function get_icon() { | |
| 69 | + return apply_filters( 'weforms_integration_icon', $this->icon, $this ); | |
| 70 | + } | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * Check if the integration is enabled | |
| 74 | + * | |
| 75 | + * @return boolean | |
| 76 | + */ | |
| 77 | + public function is_enabled() { | |
| 78 | + return $this->enabled == true; | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * Check if it's a pro field | |
| 83 | + * | |
| 84 | + * @return boolean | |
| 85 | + */ | |
| 86 | + public function is_pro() { | |
| 87 | + return false; | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * Get the settings fields | |
| 92 | + * | |
| 93 | + * @return array | |
| 94 | + */ | |
| 95 | + public function get_settings_fields() { | |
| 96 | + return $this->settings_fields; | |
| 97 | + } | |
| 98 | + | |
| 99 | + /** | |
| 100 | + * Get the integration settings for the component | |
| 101 | + * | |
| 102 | + * @return array | |
| 103 | + */ | |
| 104 | + public function get_js_settings() { | |
| 105 | + return array( | |
| 106 | + 'id' => $this->get_id(), | |
| 107 | + 'title' => $this->get_title(), | |
| 108 | + 'icon' => $this->get_icon(), | |
| 109 | + 'settings' => $this->get_settings_fields(), | |
| 110 | + 'pro' => $this->is_pro() | |
| 111 | + ); | |
| 112 | + } | |
| 113 | + | |
| 114 | +} | |