PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 1.1.6
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v1.1.6
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / core / class-query.php

class-query.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 1.1.6, at core/class-query.php

97 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately;
4
5 class Query {
6 protected static $url = 'https://app.templately.com/api/plugin';
7
8 protected static function get_url(){
9 if( defined('TEMPLATELY_DEV') && TEMPLATELY_DEV ) {
10 self::$url = 'https://app.templately.dev/api/plugin';
11 }
12 return self::$url;
13 }
14
15 public static function get( $query, $args = array() ){
16 $headers = array(
17 'Content-Type' => 'application/json',
18 );
19
20 if( isset( $args['headers'] ) && ! empty( $args['headers'] ) ) {
21 $headers = wp_parse_args( $args['headers'], $headers );
22 }
23
24 $response = wp_remote_post( self::get_url(),
25 array(
26 'headers' => $headers,
27 'body' => wp_json_encode([
28 'query' => $query
29 ])
30 )
31 );
32
33 if( is_wp_error( $response ) ) {
34 return $response;
35 }
36 $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
37 return $api_response;
38 }
39
40 public static function getFromLibrary( $id ){
41 $local = new \Elementor\TemplateLibrary\Source_Local();
42 $content = $local->get_data( [
43 'template_id' => $id
44 ] );
45 return $content;
46 }
47
48 public static function remove_cloud_item( $id, $api_key, $from = 'cloud' ){
49 $query = sprintf(
50 '%s( api_key: "%s", file_id: %s){ status, data, message }}',
51 $from === 'cloud' ? 'query{ removeFromMyCloud' : 'mutation { deleteWorkspaceFile',
52 $api_key,
53 $id
54 );
55 return self::get( $query );
56 }
57
58 public static function push( $name, $file_content, $api_key, $item_type, $args = array() ){
59 $headers = array(
60 'Content-Type' => 'application/json',
61 );
62
63 if( isset( $args['headers'] ) && ! empty( $args['headers'] ) ) {
64 $headers = wp_parse_args( $args['headers'], $headers );
65 }
66 $workspace_id = false;
67 if( isset( $args['workspace_id'] ) && ! empty( $args['workspace_id'] ) ) {
68 $workspace_id = intval( $args['workspace_id'] );
69 }
70
71 $mutation = \sprintf(
72 'mutation{ pushToMyCloud( file_type: "%s", name: "%s", file_content: "%s", api_key: "%s"%s%s){ message, status, data } }',
73 $item_type,
74 $name,
75 $file_content,
76 $api_key,
77 $workspace_id !== false ? ', workspace_id: ' . $workspace_id : '',
78 isset( $args['thumbnail'] ) ? ', thumbnail: "' . $args['thumbnail'] . '"' : ''
79 );
80
81 $response = wp_remote_post( self::get_url(),
82 array(
83 'headers' => $headers,
84 'body' => wp_json_encode([
85 'query' => $mutation
86 ])
87 )
88 );
89
90 if( is_wp_error( $response ) ) {
91 return $response;
92 }
93 $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
94 return $api_response;
95 }
96 }
97