PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 2.3.6
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v2.3.6
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 2.3.6, at includes/elementor/betterdocs-template-source.php

130 lines 3.8 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.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
21 public function get_prefix() {
22 return $this->template_prefix;
23 }
24
25 public function get_id() {
26 return 'betterdocs-templates';
27 }
28
29 public function get_title() {
30 return __( 'BetterDocs Templates', 'betterdocs' );
31 }
32
33 public function register_data() {
34 }
35
36 public function get_items( $args = array() ) {
37
38 $url = $this->cloud_url . 'templates';
39 $response = wp_remote_get( $url, [ 'timeout' => 60 ] );
40 $body = wp_remote_retrieve_body( $response );
41 $body = json_decode( $body, true );
42 $templates_data = !empty( $body['data'] ) ? $body['data'] : false;
43 $templates = array();
44
45 if ( !empty( $templates_data ) ) {
46 foreach ( $templates_data as $template_data ) {
47 $templates[] = $this->prepare_template( $template_data );
48 }
49 }
50
51 if ( ! empty( $args ) ) {
52 $templates = wp_list_filter( $templates, $args );
53 }
54
55 return $templates;
56 }
57
58
59 public function prepare_template( $template_data ) {
60 return [
61 'accessLevel' => 0,
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 /**
81 * Get remote template.
82 *
83 * Retrieve a single remote template from betterdocs.co
84 *
85 * @since 1.0.0
86 * @access public
87 *
88 * @param int $template_id The template ID.
89 *
90 * @return array Remote template.
91 */
92 public function get_item( $template_id ) {
93 $templates = $this->get_items();
94
95 return $templates[ $template_id ];
96 }
97
98 public function save_item( $template_data ) {
99 return false;
100 }
101
102 public function update_item( $new_data ) {
103 return false;
104 }
105
106 public function delete_template( $template_id ) {
107 return false;
108 }
109
110 public function export_template( $template_id ) {
111 return false;
112 }
113
114 public function get_data( array $args, $context = 'display' ) {
115 $file_url = $this->cloud_url . 'template/' . $args['template_id'];
116 $request = wp_remote_get( $file_url );
117 $response = wp_remote_retrieve_body( $request );
118 $body = json_decode( $response, true );
119 $data = !empty( $body['data'] ) ? $body['data'] : false;
120
121 $result = array();
122
123 $result['content'] = $this->replace_elements_ids( $data );
124 $result['content'] = $this->process_export_import_content( $result['content'], 'on_import' );
125 $result['page_settings'] = array();
126
127 return $result;
128 }
129 }
130