| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
die( 'You are not allowed to call this page directly.' ); |
| 5 |
} |
| 6 |
|
| 7 |
class FrmYoutubeFeedApi extends FrmFormApi { |
| 8 |
|
| 9 |
/** |
| 10 |
* The YouTube API URL. |
| 11 |
* |
| 12 |
* @var string |
| 13 |
*/ |
| 14 |
private static $base_api_url = 'https://formidableforms.com/wp-json/s11-sites/v1/youtube-feed/'; |
| 15 |
|
| 16 |
/** |
| 17 |
* The cache key names. |
| 18 |
* |
| 19 |
* @var string |
| 20 |
*/ |
| 21 |
protected $cache_key = 'frm_yt_videos'; |
| 22 |
|
| 23 |
public function __construct() { |
| 24 |
// Don't load license key or dynamic cache key. |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* @return string |
| 29 |
*/ |
| 30 |
protected function api_url() { |
| 31 |
return self::$base_api_url; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Get the YouTube video. It gets the data from cache, if cache is no available it will make a new request to YouTube API. |
| 36 |
* |
| 37 |
* @param string $type The video type that will be fetched: welcome|featured|latest. |
| 38 |
* |
| 39 |
* @return array |
| 40 |
*/ |
| 41 |
public function get_video( $type = 'welcome' ) { |
| 42 |
$videos = $this->get_api_info(); |
| 43 |
if ( isset( $videos[ $type ] ) ) { |
| 44 |
return $videos[ $type ]; |
| 45 |
} |
| 46 |
return array(); |
| 47 |
} |
| 48 |
} |
| 49 |
|