PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 2.0.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v2.0.0
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
← All changes | includes/API/Profile.php +22 -129 3.7.02.0.0 View file →
@@ -1,124 +1,45 @@
1 1 <?php
2 2
3 3 namespace Templately\API;
4 4
5 -use Templately\Utils\Helper;
5 +use WP_REST_Request;
6 6
7 7 class Profile extends API {
8 8
9 9 public function register_routes() {
10 - $this->get( 'profile/sync', [ $this, 'sync' ] );
11 - $this->get( 'profile/verified', [ $this, 'verified' ] );
10 + $this->register_endpoint( 'profile', [ $this, 'get_profile' ] );
12 11 $this->get( 'profile/download-history', [ $this, 'get_download_history' ] );
13 12 $this->get( 'profile/my-favourites', [ $this, 'get_my_favourites' ] );
14 - $this->get( 'profile/purchased-items', [ $this, 'get_my_purchased_items' ] );
15 13 }
16 14
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, reviews{ type, type_id, rating } }';
15 + public function get_profile( WP_REST_Request $request ) {
19 16
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 - if ( ! empty( $response['user']['reviews'] ) ) {
53 - $_reviews = $this->utils( 'helper' )->normalizeReviews( $response['user']['reviews'] );
54 - $this->utils( 'options' )->set( 'reviews', $_reviews );
55 -
56 - unset( $response['user']['reviews'] );
57 - $meta['reviews'] = $_reviews;
58 - }
59 -
60 - if ( ! empty( $response['user']['reviews'] ) ) {
61 - $_reviews = $this->utils( 'helper' )->normalizeReviews( $response['user']['reviews'] );
62 - $this->utils( 'options' )->set( 'reviews', $_reviews );
63 -
64 - unset( $response['user']['reviews'] );
65 - $meta['reviews'] = $_reviews;
66 - }
67 -
68 - if ( ! empty( $response['user'] ) && is_array( $response['user'] ) ) {
69 - /**
70 - * The cloud API key must never be persisted here or sent to the client.
71 - * Under a global login this key belongs to the admin, while any user with
72 - * `delete_posts` can reach this endpoint. Login and SignUp already drop it.
73 - */
74 - unset( $response['user']['api_key'] );
75 -
76 - $response['user']['site_url'] = base64_encode( home_url( '/' ) );
77 - $response['user']['ip'] = Helper::get_ip();
78 - }
79 -
80 - $this->utils( 'options' )->set( 'user', $response['user'] );
81 - $response['user']['meta'] = Login::get_instance()->user_meta( $meta );
82 -
83 - return $this->success( $response );
84 17 }
85 18
86 - public function verified() {
87 - $funcArgs = [
88 - 'api_key' => $this->api_key
89 - ];
90 -
91 - $response = $this->http()->query( 'isVerifiedUser', '', $funcArgs )->post();
92 -
93 - if ( $response && !is_wp_error( $response ) ) {
94 - $user = $this->utils( 'options' )->get( 'user' );
95 -
96 - $user['is_verified'] = true;
97 - $this->utils( 'options' )->set( 'user', $user );
98 - }
99 -
100 - return $response;
101 - }
102 -
103 19 public function get_download_history() {
104 20 $page = $this->get_param( 'page', 1, 'intval' );
105 21 $per_page = $this->get_param( 'per_page', 10, 'intval' );
106 22
107 - $response = $this->http()->mutation( 'myDownloadHistory', 'data{ name, thumbnail, downloaded_at, slug, type }, current_page, total_page, total', [
23 + $response = $this->http()->mutation(
24 + 'myDownloadHistory',
25 + 'data{ name, thumbnail, downloaded_at, slug, type }, current_page, total_page',
26 + [
108 27 'api_key' => $this->api_key,
109 28 'per_page' => $per_page,
110 29 "page" => $page
111 - ] )->post();
30 + ]
31 + )->post();
112 32
113 33 if ( is_wp_error( $response ) ) {
114 - return $this->error( 'invalid_download_history_response', __( $response->get_error_message(), 'templately' ), 'profile/download-history' );
34 + return $this->error(
35 + 'invalid_download_history_response',
36 + __( $response->get_error_message(), 'templately' ),
37 + 'profile/download-history',
38 + $response->get_error_code()
39 + );
115 40 }
116 41
117 - if ( isset( $response['total'] ) ) {
118 - $this->utils( 'options' )->set( 'total_download_counts', $response['total'] );
119 - }
120 -
121 42 return $response;
122 43 }
123 44
124 45 public function get_my_favourites() {
@@ -134,49 +55,21 @@
134 55 "per_page" => $per_page,
135 56 "plan_type" => $plan_type
136 57 ];
137 58
138 - if ( $type != 'all' ) {
59 + if( $type != 'all' ) {
139 60 $funcArgs['type'] = $type;
140 61 }
141 62
142 - $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();
63 + $response = $this->http()->mutation(
64 + 'myFavouriteItem',
65 + 'total_page, current_page, data { id, name, rating, type, slug, favourite_count, thumbnail, thumbnail2, thumbnail3, price, author{ display_name, name, joined } }',
66 + $funcArgs
67 + )->post();
143 68
144 69 if ( is_wp_error( $response ) ) {
145 - return $this->error( 'invalid_my_favourites_response', __( $response->get_error_message(), 'templately' ), 'profile/my-favourites' );
146 - }
147 -
148 - return $response;
149 - }
150 -
151 - public function get_my_purchased_items() {
152 - $page = $this->get_param( 'page', 1, 'intval' );
153 - $per_page = $this->get_param( 'per_page', 10, 'intval' );
154 - $_all = $this->get_param( 'all', false );
155 - $platform = $this->get_param( 'platform', 'elementor' );
156 -
157 - $funcArgs = [
158 - 'api_key' => $this->api_key,
159 - 'platform' => $platform,
160 - 'page' => $page,
161 - 'per_page' => $per_page
162 - ];
163 -
164 - $query = 'total_page, current_page, data { id, item_id, name, slug, type, platform, thumbnail, purchased_at }';
165 -
166 - if ( $_all ) {
167 - $query = 'total_page, current_page, data { id, item_id, type, platform }';
168 - $funcArgs['per_page'] = -1;
169 - }
170 -
171 - $response = $this->http()->query( 'myItems', $query, $funcArgs )->post();
172 -
173 - if ( $response ) {
174 - // $user = $this->utils('options')->get('user');
175 -
176 - // $user['is_verified'] = true;
177 - // $this->utils('options')->set('user', $user);
70 + return $this->error( 'invalid_my_favourites_response', __( $response->get_error_message(), 'templately' ), 'profile/my-favourites', $response->get_error_code() );
178 71 }
179 72
180 73 return $response;
181 74 }
182 75 }