PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / trunk
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! vtrunk
3.8.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 All 112 releases
templately / modules / profile-collections / REST / Profile.php

Profile.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! trunk, at modules/profile-collections/REST/Profile.php

112 lines 3.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\Modules\ProfileCollections\REST;
4
5 use Templately\API\API;
6
7 class Profile extends API {
8
9 public function register_routes() {
10 $this->get( 'profile/download-history', [ $this, 'get_download_history' ] );
11 $this->get( 'profile/my-favourites', [ $this, 'get_my_favourites' ] );
12 $this->get( 'profile/purchased-items', [ $this, 'get_my_purchased_items' ] );
13 }
14
15 public function get_download_history() {
16 $page = $this->get_param( 'page', 1, 'intval' );
17 $per_page = $this->get_param( 'per_page', 10, 'intval' );
18
19 $response = $this->http()->mutation( 'myDownloadHistory', 'data{ name, thumbnail, downloaded_at, slug, type }, current_page, total_page, total', [
20 'api_key' => $this->api_key,
21 'per_page' => $per_page,
22 "page" => $page
23 ] )->post();
24
25 if ( is_wp_error( $response ) ) {
26 return $this->error( 'invalid_download_history_response', __( $response->get_error_message(), 'templately' ), 'profile/download-history' );
27 }
28
29 if ( isset( $response['total'] ) ) {
30 $this->utils( 'options' )->set( 'total_download_counts', $response['total'] );
31 }
32
33 return $response;
34 }
35
36 public function get_my_favourites() {
37 $type = $this->get_param( 'itemType', 'all' );
38 $plan = $this->get_param( 'plan', 'all' );
39 $plan_type = $this->get_plan( $plan );
40 $page = $this->get_param( 'page', 1, 'intval' );
41 $per_page = $this->get_param( 'per_page', 20, 'intval' );
42
43 $funcArgs = [
44 'api_key' => $this->api_key,
45 "page" => $page,
46 "per_page" => $per_page,
47 "plan_type" => $plan_type
48 ];
49
50 if ( $type != 'all' ) {
51 $funcArgs['type'] = $type;
52 }
53
54 $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();
55
56 if ( is_wp_error( $response ) ) {
57 return $this->error( 'invalid_my_favourites_response', __( $response->get_error_message(), 'templately' ), 'profile/my-favourites' );
58 }
59
60 return $response;
61 }
62
63 /**
64 * The buyer's purchased items.
65 *
66 * `platform` is OMITTED unless a caller explicitly asks for one. The cloud's
67 * `myItems` resolver applies the platform filter only `when(! empty($args['platform']))`,
68 * so sending nothing means "every platform" — which is what both callers want and
69 * neither ever asked for: the paged My Items table sends no platform, and the
70 * owned-item INDEX (`all=true`, the thing that decides whether a pack shows
71 * "Purchase This Pack" or "Build Full Website") sends none either.
72 *
73 * This defaulted to `'elementor'`, so the index only ever contained Elementor
74 * purchases. A Gutenberg pack the user had just bought stayed unowned forever — the
75 * detail page kept offering to sell it back to them, through reloads and re-syncs,
76 * because the answer it cached had the purchase filtered out server-side.
77 */
78 public function get_my_purchased_items() {
79 $page = $this->get_param( 'page', 1, 'intval' );
80 $per_page = $this->get_param( 'per_page', 10, 'intval' );
81 $_all = $this->get_param( 'all', false );
82 $platform = $this->get_param( 'platform', '' );
83
84 $funcArgs = [
85 'api_key' => $this->api_key,
86 'page' => $page,
87 'per_page' => $per_page
88 ];
89
90 if ( ! empty( $platform ) ) {
91 $funcArgs['platform'] = $platform;
92 }
93
94 $query = 'total_page, current_page, data { id, item_id, name, slug, type, platform, thumbnail, purchased_at }';
95
96 if ( $_all ) {
97 $query = 'total_page, current_page, data { id, item_id, type, platform }';
98 $funcArgs['per_page'] = -1;
99 }
100
101 $response = $this->http()->query( 'myItems', $query, $funcArgs )->post();
102
103 if ( $response ) {
104 // $user = $this->utils('options')->get('user');
105
106 // $user['is_verified'] = true;
107 // $this->utils('options')->set('user', $user);
108 }
109
110 return $response;
111 }
112 }