PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 1.7.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v1.7.3
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / elementor / betterdocs-template-source.php

betterdocs-template-source.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 1.7.3, at includes/elementor/betterdocs-template-source.php

112 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.net>
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 'template_id' => $template_data['template_id'],
63 'source' => 'remote',
64 'type' => $template_data['type'],
65 'subtype' => $template_data['subtype'],
66 'title' => $template_data['title'],
67 'thumbnail' => $template_data['thumbnail'],
68 'date' => $template_data['date'],
69 'author' => $template_data['author'],
70 'tags' => $template_data['tags'],
71 'isPro' => ( 1 == $template_data['isPro'] ),
72 'popularityIndex' => (int)$template_data['popularityIndex'],
73 'trendIndex' => (int)$template_data['trendIndex'],
74 'hasPageSettings' => ( 1 == $template_data['hasPageSettings'] ),
75 'url' => $template_data['url'],
76 'favorite' => ( 1 == $template_data['favorite'] ),
77 ];
78 }
79
80 public function save_item( $template_data ) {
81 return false;
82 }
83
84 public function update_item( $new_data ) {
85 return false;
86 }
87
88 public function delete_template( $template_id ) {
89 return false;
90 }
91
92 public function export_template( $template_id ) {
93 return false;
94 }
95
96 public function get_data( array $args, $context = 'display' ) {
97 $file_url = $this->cloud_url . 'template/' . $args['template_id'];
98 $request = wp_remote_get( $file_url );
99 $response = wp_remote_retrieve_body( $request );
100 $body = json_decode( $response, true );
101 $data = !empty( $body['data'] ) ? $body['data'] : false;
102
103 $result = array();
104
105 $result['content'] = $this->replace_elements_ids( $data );
106 $result['content'] = $this->process_export_import_content( $result['content'], 'on_import' );
107 $result['page_settings'] = array();
108
109 return $result;
110 }
111 }
112