PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 2.2.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v2.2.2
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 +135 -141 3.7.32.2.2 View file →
@@ -5,181 +5,175 @@
5 5 use Templately\Utils\Helper;
6 6
7 7 class Profile extends API {
8 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 - }
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 16
17 - public function sync() {
18 - // Keep the `subscription` field set in step with `Login::login()` — the
19 - // Subscription screen renders from whichever of the two answered last, so a
20 - // field missing here silently degrades the card after a profile sync.
21 - $query = 'status, message, user{ id, name, first_name, last_name, display_name, email, profile_photo, joined, is_verified, is_restricted_company_user, api_key, plan, plan_expire_at, my_cloud{ limit, usages, last_pushed }, favourites{ id, type }, show_notice, reviews{ type, type_id, rating }, subscription { id, name, sites, subscription_plan_id, ends_at, plan_type, cancel_at_period_end } }';
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 }';
22 19
23 - $funcArgs = [
24 - 'api_key' => $this->api_key,
25 - 'site_url' => home_url( '/' ),
26 - 'ip' => Helper::get_ip()
27 - ];
20 + $funcArgs = [
21 + 'api_key' => $this->api_key,
22 + 'site_url' => home_url( '/' ),
23 + 'ip' => Helper::get_ip()
24 + ];
28 25
29 - $response = $this->http()->mutation( 'connectWithApiKey', $query, $funcArgs )->post();
26 + $response = $this->http()->mutation(
27 + 'connectWithApiKey',
28 + $query,
29 + $funcArgs
30 + )->post();
30 31
31 - if ( is_wp_error( $response ) ) {
32 - return $response;
33 - }
32 + if ( is_wp_error( $response ) ) {
33 + return $response;
34 + }
34 35
35 - $meta = [
36 - 'is_globally_signed' => Login::is_globally_signed(),
37 - 'signed_as_global' => Login::signed_as_global()
38 - ];
36 + $meta = [
37 + 'is_globally_signed' => Login::is_globally_signed(),
38 + 'signed_as_global' => Login::signed_as_global()
39 + ];
39 40
40 - if ( ! empty( $response['user']['my_cloud']['last_pushed'] ) ) {
41 - $_cloud_activity = unserialize( $response['user']['my_cloud']['last_pushed'] );
42 - $this->utils( 'options' )->set( 'cloud_activity', $_cloud_activity );
43 - $meta['cloud_activity'] = $_cloud_activity;
44 - unset( $response['user']['my_cloud']['last_pushed'] );
45 - }
41 + if ( ! empty( $response['user']['my_cloud']['last_pushed'] ) ) {
42 + $_cloud_activity = unserialize( $response['user']['my_cloud']['last_pushed'] );
43 + $this->utils( 'options' )->set( 'cloud_activity', $_cloud_activity );
44 + $meta['cloud_activity'] = $_cloud_activity;
45 + unset( $response['user']['my_cloud']['last_pushed'] );
46 + }
46 47
47 - if ( ! empty( $response['user']['favourites'] ) ) {
48 - $_favourites = $this->utils( 'helper' )->normalizeFavourites( $response['user']['favourites'] );
49 - $this->utils( 'options' )->set( 'favourites', $_favourites );
48 + if ( ! empty( $response['user']['favourites'] ) ) {
49 + $_favourites = $this->utils( 'helper' )->normalizeFavourites( $response['user']['favourites'] );
50 + $this->utils( 'options' )->set( 'favourites', $_favourites );
50 51
51 - unset( $response['user']['favourites'] );
52 - $meta['favourites'] = $_favourites;
53 - }
52 + unset( $response['user']['favourites'] );
53 + $meta['favourites'] = $_favourites;
54 + }
54 55
55 - if ( ! empty( $response['user']['reviews'] ) ) {
56 - $_reviews = $this->utils( 'helper' )->normalizeReviews( $response['user']['reviews'] );
57 - $this->utils( 'options' )->set( 'reviews', $_reviews );
56 + $this->utils( 'options' )->set( 'user', $response['user'] );
57 + $response['user']['meta'] = Login::get_instance()->user_meta( $meta );
58 58
59 - unset( $response['user']['reviews'] );
60 - $meta['reviews'] = $_reviews;
61 - }
59 + return $this->success( $response );
60 + }
62 61
63 - if ( ! empty( $response['user']['reviews'] ) ) {
64 - $_reviews = $this->utils( 'helper' )->normalizeReviews( $response['user']['reviews'] );
65 - $this->utils( 'options' )->set( 'reviews', $_reviews );
62 + public function verified() {
63 + $funcArgs = [
64 + 'api_key' => $this->api_key
65 + ];
66 66
67 - unset( $response['user']['reviews'] );
68 - $meta['reviews'] = $_reviews;
69 - }
67 + $response = $this->http()->query(
68 + 'isVerifiedUser',
69 + '',
70 + $funcArgs
71 + )->post();
70 72
71 - if ( ! empty( $response['user'] ) && is_array( $response['user'] ) ) {
72 - /**
73 - * The cloud API key must never be persisted here or sent to the client.
74 - * Under a global login this key belongs to the admin, while any user with
75 - * `delete_posts` can reach this endpoint. Login and SignUp already drop it.
76 - */
77 - unset( $response['user']['api_key'] );
73 + if ( $response ) {
74 + $user = $this->utils( 'options' )->get( 'user' );
78 75
79 - $response['user']['site_url'] = base64_encode( home_url( '/' ) );
80 - $response['user']['ip'] = Helper::get_ip();
81 - }
76 + $user['is_verified'] = true;
77 + $this->utils( 'options' )->set( 'user', $user );
78 + }
82 79
83 - $this->utils( 'options' )->set( 'user', $response['user'] );
84 - $response['user']['meta'] = Login::get_instance()->user_meta( $meta );
80 + return $response;
81 + }
85 82
86 - return $this->success( $response );
87 - }
83 + public function get_download_history() {
84 + $page = $this->get_param( 'page', 1, 'intval' );
85 + $per_page = $this->get_param( 'per_page', 10, 'intval' );
88 86
89 - public function verified() {
90 - $funcArgs = [
91 - 'api_key' => $this->api_key
92 - ];
87 + $response = $this->http()->mutation(
88 + 'myDownloadHistory',
89 + 'data{ name, thumbnail, downloaded_at, slug, type }, current_page, total_page, total',
90 + [
91 + 'api_key' => $this->api_key,
92 + 'per_page' => $per_page,
93 + "page" => $page
94 + ]
95 + )->post();
93 96
94 - $response = $this->http()->query( 'isVerifiedUser', '', $funcArgs )->post();
97 + if ( is_wp_error( $response ) ) {
98 + return $this->error(
99 + 'invalid_download_history_response',
100 + __( $response->get_error_message(), 'templately' ),
101 + 'profile/download-history',
102 + $response->get_error_code()
103 + );
104 + }
95 105
96 - if ( $response && !is_wp_error( $response ) ) {
97 - $user = $this->utils( 'options' )->get( 'user' );
106 + if ( isset( $response['total'] ) ) {
107 + $this->utils( 'options' )->set( 'total_downlaod_counts', $response['total'] );
108 + }
98 109
99 - $user['is_verified'] = true;
100 - $this->utils( 'options' )->set( 'user', $user );
101 - }
110 + return $response;
111 + }
102 112
103 - return $response;
104 - }
113 + public function get_my_favourites() {
114 + $type = $this->get_param( 'itemType', 'all' );
115 + $plan = $this->get_param( 'plan', 'all' );
116 + $plan_type = $this->get_plan( $plan );
117 + $page = $this->get_param( 'page', 1, 'intval' );
118 + $per_page = $this->get_param( 'per_page', 20, 'intval' );
105 119
106 - public function get_download_history() {
107 - $page = $this->get_param( 'page', 1, 'intval' );
108 - $per_page = $this->get_param( 'per_page', 10, 'intval' );
120 + $funcArgs = [
121 + 'api_key' => $this->api_key,
122 + "page" => $page,
123 + "per_page" => $per_page,
124 + "plan_type" => $plan_type
125 + ];
109 126
110 - $response = $this->http()->mutation( 'myDownloadHistory', 'data{ name, thumbnail, downloaded_at, slug, type }, current_page, total_page, total', [
111 - 'api_key' => $this->api_key,
112 - 'per_page' => $per_page,
113 - "page" => $page
114 - ] )->post();
127 + if ( $type != 'all' ) {
128 + $funcArgs['type'] = $type;
129 + }
115 130
116 - if ( is_wp_error( $response ) ) {
117 - return $this->error( 'invalid_download_history_response', __( $response->get_error_message(), 'templately' ), 'profile/download-history' );
118 - }
131 + $response = $this->http()->mutation(
132 + 'myFavouriteItem',
133 + 'total_page, current_page, data { id, name, rating, type, slug, favourite_count, thumbnail, thumbnail2, thumbnail3, price, author{ display_name, name, joined } }',
134 + $funcArgs
135 + )->post();
119 136
120 - if ( isset( $response['total'] ) ) {
121 - $this->utils( 'options' )->set( 'total_download_counts', $response['total'] );
122 - }
137 + if ( is_wp_error( $response ) ) {
138 + return $this->error( 'invalid_my_favourites_response', __( $response->get_error_message(), 'templately' ), 'profile/my-favourites', $response->get_error_code() );
139 + }
123 140
124 - return $response;
125 - }
141 + return $response;
142 + }
126 143
127 - public function get_my_favourites() {
128 - $type = $this->get_param( 'itemType', 'all' );
129 - $plan = $this->get_param( 'plan', 'all' );
130 - $plan_type = $this->get_plan( $plan );
131 - $page = $this->get_param( 'page', 1, 'intval' );
132 - $per_page = $this->get_param( 'per_page', 20, 'intval' );
144 + public function get_my_purchased_items() {
145 + $page = $this->get_param( 'page', 1, 'intval' );
146 + $per_page = $this->get_param( 'per_page', 10, 'intval' );
147 + $_all = $this->get_param( 'all', false );
133 148
134 - $funcArgs = [
135 - 'api_key' => $this->api_key,
136 - "page" => $page,
137 - "per_page" => $per_page,
138 - "plan_type" => $plan_type
139 - ];
149 + $funcArgs = [
150 + 'api_key' => $this->api_key,
151 + 'page' => $page,
152 + 'per_page' => $per_page
153 + ];
140 154
141 - if ( $type != 'all' ) {
142 - $funcArgs['type'] = $type;
143 - }
155 + $query = 'total_page, current_page, data { id, item_id, name, slug, type, platform, thumbnail, purchased_at }';
144 156
145 - $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();
157 + if ( $_all ) {
158 + $query = 'total_page, current_page, data { id, item_id, type, platform }';
159 + $funcArgs['per_page'] = -1;
160 + }
146 161
147 - if ( is_wp_error( $response ) ) {
148 - return $this->error( 'invalid_my_favourites_response', __( $response->get_error_message(), 'templately' ), 'profile/my-favourites' );
149 - }
162 + $response = $this->http()->query(
163 + 'myItems',
164 + $query,
165 + $funcArgs
166 + )->post();
150 167
151 - return $response;
152 - }
168 + // dlog( $response );
153 169
154 - public function get_my_purchased_items() {
155 - $page = $this->get_param( 'page', 1, 'intval' );
156 - $per_page = $this->get_param( 'per_page', 10, 'intval' );
157 - $_all = $this->get_param( 'all', false );
158 - $platform = $this->get_param( 'platform', 'elementor' );
170 + if ( $response ) {
171 + // $user = $this->utils('options')->get('user');
159 172
160 - $funcArgs = [
161 - 'api_key' => $this->api_key,
162 - 'platform' => $platform,
163 - 'page' => $page,
164 - 'per_page' => $per_page
165 - ];
173 + // $user['is_verified'] = true;
174 + // $this->utils('options')->set('user', $user);
175 + }
166 176
167 - $query = 'total_page, current_page, data { id, item_id, name, slug, type, platform, thumbnail, purchased_at }';
168 -
169 - if ( $_all ) {
170 - $query = 'total_page, current_page, data { id, item_id, type, platform }';
171 - $funcArgs['per_page'] = -1;
172 - }
173 -
174 - $response = $this->http()->query( 'myItems', $query, $funcArgs )->post();
175 -
176 - if ( $response ) {
177 - // $user = $this->utils('options')->get('user');
178 -
179 - // $user['is_verified'] = true;
180 - // $this->utils('options')->set('user', $user);
181 - }
182 -
183 - return $response;
184 - }
177 + return $response;
178 + }
185 179 }