PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 2.2.10
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v2.2.10
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 / includes / API / Profile.php

Profile.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 2.2.10, at includes/API/Profile.php

154 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\API;
4
5 use Templately\Utils\Helper;
6
7 class Profile extends API {
8
9 public function register_routes() {
10 $this->get( 'profile/sync', [ $this, 'sync' ] );
11 $this->get( 'profile/verified', [ $this, 'verified' ] );
12 $this->get( 'profile/download-history', [ $this, 'get_download_history' ] );
13 $this->get( 'profile/my-favourites', [ $this, 'get_my_favourites' ] );
14 $this->get( 'profile/purchased-items', [ $this, 'get_my_purchased_items' ] );
15 }
16
17 public function sync() {
18 $query = 'status, message, user{ id, name, first_name, last_name, display_name, email, profile_photo, joined, is_verified, api_key, plan, plan_expire_at, my_cloud{ limit, usages, last_pushed }, favourites{ id, type }, show_notice }';
19
20 $funcArgs = [
21 'api_key' => $this->api_key,
22 'site_url' => home_url( '/' ),
23 'ip' => Helper::get_ip()
24 ];
25
26 $response = $this->http()->mutation( 'connectWithApiKey', $query, $funcArgs )->post();
27
28 if ( is_wp_error( $response ) ) {
29 return $response;
30 }
31
32 $meta = [
33 'is_globally_signed' => Login::is_globally_signed(),
34 'signed_as_global' => Login::signed_as_global()
35 ];
36
37 if ( ! empty( $response['user']['my_cloud']['last_pushed'] ) ) {
38 $_cloud_activity = unserialize( $response['user']['my_cloud']['last_pushed'] );
39 $this->utils( 'options' )->set( 'cloud_activity', $_cloud_activity );
40 $meta['cloud_activity'] = $_cloud_activity;
41 unset( $response['user']['my_cloud']['last_pushed'] );
42 }
43
44 if ( ! empty( $response['user']['favourites'] ) ) {
45 $_favourites = $this->utils( 'helper' )->normalizeFavourites( $response['user']['favourites'] );
46 $this->utils( 'options' )->set( 'favourites', $_favourites );
47
48 unset( $response['user']['favourites'] );
49 $meta['favourites'] = $_favourites;
50 }
51
52 $this->utils( 'options' )->set( 'user', $response['user'] );
53 $response['user']['meta'] = Login::get_instance()->user_meta( $meta );
54
55 return $this->success( $response );
56 }
57
58 public function verified() {
59 $funcArgs = [
60 'api_key' => $this->api_key
61 ];
62
63 $response = $this->http()->query( 'isVerifiedUser', '', $funcArgs )->post();
64
65 if ( $response ) {
66 $user = $this->utils( 'options' )->get( 'user' );
67
68 $user['is_verified'] = true;
69 $this->utils( 'options' )->set( 'user', $user );
70 }
71
72 return $response;
73 }
74
75 public function get_download_history() {
76 $page = $this->get_param( 'page', 1, 'intval' );
77 $per_page = $this->get_param( 'per_page', 10, 'intval' );
78
79 $response = $this->http()->mutation( 'myDownloadHistory', 'data{ name, thumbnail, downloaded_at, slug, type }, current_page, total_page, total', [
80 'api_key' => $this->api_key,
81 'per_page' => $per_page,
82 "page" => $page
83 ] )->post();
84
85 if ( is_wp_error( $response ) ) {
86 return $this->error( 'invalid_download_history_response', __( $response->get_error_message(), 'templately' ), 'profile/download-history', $response->get_error_code() );
87 }
88
89 if ( isset( $response['total'] ) ) {
90 $this->utils( 'options' )->set( 'total_download_counts', $response['total'] );
91 }
92
93 return $response;
94 }
95
96 public function get_my_favourites() {
97 $type = $this->get_param( 'itemType', 'all' );
98 $plan = $this->get_param( 'plan', 'all' );
99 $plan_type = $this->get_plan( $plan );
100 $page = $this->get_param( 'page', 1, 'intval' );
101 $per_page = $this->get_param( 'per_page', 20, 'intval' );
102
103 $funcArgs = [
104 'api_key' => $this->api_key,
105 "page" => $page,
106 "per_page" => $per_page,
107 "plan_type" => $plan_type
108 ];
109
110 if ( $type != 'all' ) {
111 $funcArgs['type'] = $type;
112 }
113
114 $response = $this->http()->mutation( 'myFavouriteItem', 'total_page, current_page, data { id, name, rating, type, slug, favourite_count, thumbnail, thumbnail2, thumbnail3, price, author{ display_name, name, joined }, dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link } }', $funcArgs )->post();
115
116 if ( is_wp_error( $response ) ) {
117 return $this->error( 'invalid_my_favourites_response', __( $response->get_error_message(), 'templately' ), 'profile/my-favourites', $response->get_error_code() );
118 }
119
120 return $response;
121 }
122
123 public function get_my_purchased_items() {
124 $page = $this->get_param( 'page', 1, 'intval' );
125 $per_page = $this->get_param( 'per_page', 10, 'intval' );
126 $_all = $this->get_param( 'all', false );
127
128 $funcArgs = [
129 'api_key' => $this->api_key,
130 'page' => $page,
131 'per_page' => $per_page
132 ];
133
134 $query = 'total_page, current_page, data { id, item_id, name, slug, type, platform, thumbnail, purchased_at }';
135
136 if ( $_all ) {
137 $query = 'total_page, current_page, data { id, item_id, type, platform }';
138 $funcArgs['per_page'] = -1;
139 }
140
141 $response = $this->http()->query( 'myItems', $query, $funcArgs )->post();
142
143 // dlog( $response );
144
145 if ( $response ) {
146 // $user = $this->utils('options')->get('user');
147
148 // $user['is_verified'] = true;
149 // $this->utils('options')->set('user', $user);
150 }
151
152 return $response;
153 }
154 }