| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* @since 6.0 |
| 8 |
*/ |
| 9 |
class FrmStyleApi extends FrmFormApi { |
| 10 |
|
| 11 |
/** |
| 12 |
* @var string |
| 13 |
*/ |
| 14 |
private static $base_api_url = 'https://formidableforms.com/wp-json/style-templates/v1/list'; |
| 15 |
|
| 16 |
/** |
| 17 |
* @var int |
| 18 |
*/ |
| 19 |
protected $new_days = 30; |
| 20 |
|
| 21 |
/** |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
protected $cache_timeout = '+12 hours'; |
| 25 |
|
| 26 |
/** |
| 27 |
* @return string |
| 28 |
*/ |
| 29 |
protected function api_url() { |
| 30 |
return self::$base_api_url; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* @return void |
| 35 |
*/ |
| 36 |
protected function set_cache_key() { |
| 37 |
$this->cache_key = 'frm_style_templates_l' . ( empty( $this->license ) ? '' : md5( $this->license ) ); |
| 38 |
} |
| 39 |
|
| 40 |
public function get_api_info() { |
| 41 |
$api_info = parent::get_api_info(); |
| 42 |
$api_info = $this->fill_missing_style_settings( $api_info ); |
| 43 |
return $api_info; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* @param array $api_info |
| 48 |
* @return array |
| 49 |
*/ |
| 50 |
private function fill_missing_style_settings( $api_info ) { |
| 51 |
// Remove 'Styling Template' from titles. |
| 52 |
foreach ( $api_info as $id => $template ) { |
| 53 |
if ( isset( $template['name'] ) ) { |
| 54 |
$api_info[ $id ]['name'] = preg_replace( '/(\sStyle|Styling)?(\sTemplate)?$/', '', $template['name'] ); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
return $api_info; |
| 59 |
} |
| 60 |
} |
| 61 |
|