| 1 |
<?php |
| 2 |
|
| 3 |
if ( !defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Working with elementor plugin |
| 9 |
* |
| 10 |
* |
| 11 |
* @since 1.3.0 |
| 12 |
* @package BetterDocs |
| 13 |
* @subpackage BetterDocs/elementor |
| 14 |
* @author WPDeveloper <support@wpdeveloper.com> |
| 15 |
*/ |
| 16 |
class BetterDocs_Template_Source extends Elementor\TemplateLibrary\Source_Base { |
| 17 |
|
| 18 |
protected $template_prefix = 'betterdocs_'; |
| 19 |
//protected $cloud_url = 'https://betterdocs.co/wp-json/bd_cloud/v1/'; |
| 20 |
protected $cloud_url = 'http://betterdocs.test/wp-json/bd_cloud/v1/'; |
| 21 |
|
| 22 |
public function get_prefix() { |
| 23 |
return $this->template_prefix; |
| 24 |
} |
| 25 |
|
| 26 |
public function get_id() { |
| 27 |
return 'betterdocs-templates'; |
| 28 |
} |
| 29 |
|
| 30 |
public function get_title() { |
| 31 |
return __( 'BetterDocs Templates', 'betterdocs' ); |
| 32 |
} |
| 33 |
|
| 34 |
public function register_data() { |
| 35 |
} |
| 36 |
|
| 37 |
public function get_items( $args = array() ) { |
| 38 |
|
| 39 |
$url = $this->cloud_url . 'templates'; |
| 40 |
$response = wp_remote_get( $url, [ 'timeout' => 60 ] ); |
| 41 |
$body = wp_remote_retrieve_body( $response ); |
| 42 |
$body = json_decode( $body, true ); |
| 43 |
$templates_data = !empty( $body['data'] ) ? $body['data'] : false; |
| 44 |
$templates = array(); |
| 45 |
|
| 46 |
if ( !empty( $templates_data ) ) { |
| 47 |
foreach ( $templates_data as $template_data ) { |
| 48 |
$templates[] = $this->get_item( $template_data ); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
if ( !empty( $args ) ) { |
| 53 |
$templates = wp_list_filter( $templates, $args ); |
| 54 |
} |
| 55 |
|
| 56 |
return $templates; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
public function get_item( $template_data ) { |
| 61 |
return [ |
| 62 |
'accessLevel' => 0, |
| 63 |
'template_id' => $template_data['template_id'], |
| 64 |
'source' => 'remote', |
| 65 |
'type' => $template_data['type'], |
| 66 |
'subtype' => $template_data['subtype'], |
| 67 |
'title' => $template_data['title'], |
| 68 |
'thumbnail' => $template_data['thumbnail'], |
| 69 |
'date' => $template_data['date'], |
| 70 |
'author' => $template_data['author'], |
| 71 |
'tags' => $template_data['tags'], |
| 72 |
'isPro' => ( 1 == $template_data['isPro'] ), |
| 73 |
'popularityIndex' => (int)$template_data['popularityIndex'], |
| 74 |
'trendIndex' => (int)$template_data['trendIndex'], |
| 75 |
'hasPageSettings' => ( 1 == $template_data['hasPageSettings'] ), |
| 76 |
'url' => $template_data['url'], |
| 77 |
'favorite' => ( 1 == $template_data['favorite'] ), |
| 78 |
]; |
| 79 |
} |
| 80 |
|
| 81 |
public function save_item( $template_data ) { |
| 82 |
return false; |
| 83 |
} |
| 84 |
|
| 85 |
public function update_item( $new_data ) { |
| 86 |
return false; |
| 87 |
} |
| 88 |
|
| 89 |
public function delete_template( $template_id ) { |
| 90 |
return false; |
| 91 |
} |
| 92 |
|
| 93 |
public function export_template( $template_id ) { |
| 94 |
return false; |
| 95 |
} |
| 96 |
|
| 97 |
public function get_data( array $args, $context = 'display' ) { |
| 98 |
$file_url = $this->cloud_url . 'template/' . $args['template_id']; |
| 99 |
$request = wp_remote_get( $file_url ); |
| 100 |
$response = wp_remote_retrieve_body( $request ); |
| 101 |
$body = json_decode( $response, true ); |
| 102 |
$data = !empty( $body['data'] ) ? $body['data'] : false; |
| 103 |
|
| 104 |
$result = array(); |
| 105 |
|
| 106 |
$result['content'] = $this->replace_elements_ids( $data ); |
| 107 |
$result['content'] = $this->process_export_import_content( $result['content'], 'on_import' ); |
| 108 |
$result['page_settings'] = array(); |
| 109 |
|
| 110 |
return $result; |
| 111 |
} |
| 112 |
} |
| 113 |
|