| @@ -10,13 +10,12 @@ | ||
| 10 | 10 | $this->get( 'profile/sync', [ $this, 'sync' ] ); |
| 11 | 11 | $this->get( 'profile/verified', [ $this, 'verified' ] ); |
| 12 | 12 | $this->get( 'profile/download-history', [ $this, 'get_download_history' ] ); |
| 13 | 13 | $this->get( 'profile/my-favourites', [ $this, 'get_my_favourites' ] ); |
| 14 | - $this->get( 'profile/purchased-items', [ $this, 'get_my_purchased_items' ] ); | |
| 15 | 14 | } |
| 16 | 15 | |
| 17 | 16 | 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 } }'; | |
| 17 | + $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 } }'; | |
| 19 | 18 | |
| 20 | 19 | $funcArgs = [ |
| 21 | 20 | 'api_key' => $this->api_key, |
| 22 | 21 | 'site_url' => home_url( '/' ), |
| @@ -22,68 +21,60 @@ | ||
| 22 | 21 | 'site_url' => home_url( '/' ), |
| 23 | 22 | 'ip' => Helper::get_ip() |
| 24 | 23 | ]; |
| 25 | 24 | |
| 26 | - $response = $this->http()->mutation( 'connectWithApiKey', $query, $funcArgs )->post(); | |
| 25 | + $response = $this->http()->mutation( | |
| 26 | + 'connectWithApiKey', | |
| 27 | + $query, | |
| 28 | + $funcArgs | |
| 29 | + )->post(); | |
| 27 | 30 | |
| 28 | - if ( is_wp_error( $response ) ) { | |
| 31 | + if( is_wp_error( $response ) ) { | |
| 29 | 32 | return $response; |
| 30 | 33 | } |
| 31 | 34 | |
| 32 | 35 | $meta = [ |
| 33 | 36 | 'is_globally_signed' => Login::is_globally_signed(), |
| 34 | - 'signed_as_global' => Login::signed_as_global() | |
| 37 | + 'signed_as_global' => Login::signed_as_global(), | |
| 35 | 38 | ]; |
| 36 | 39 | |
| 37 | - if ( ! empty( $response['user']['my_cloud']['last_pushed'] ) ) { | |
| 40 | + if( ! empty( $response['user']['my_cloud']['last_pushed'] ) ) { | |
| 38 | 41 | $_cloud_activity = unserialize( $response['user']['my_cloud']['last_pushed'] ); |
| 39 | - $this->utils( 'options' )->set( 'cloud_activity', $_cloud_activity ); | |
| 42 | + $this->utils('options')->set( 'cloud_activity', $_cloud_activity ); | |
| 40 | 43 | $meta['cloud_activity'] = $_cloud_activity; |
| 41 | 44 | unset( $response['user']['my_cloud']['last_pushed'] ); |
| 42 | 45 | } |
| 43 | 46 | |
| 44 | - if ( ! empty( $response['user']['favourites'] ) ) { | |
| 45 | - $_favourites = $this->utils( 'helper' )->normalizeFavourites( $response['user']['favourites'] ); | |
| 46 | - $this->utils( 'options' )->set( 'favourites', $_favourites ); | |
| 47 | + if( ! empty( $response['user']['favourites'] ) ) { | |
| 48 | + $_favourites = $this->utils('helper')->normalizeFavourites( $response['user']['favourites'] ); | |
| 49 | + $this->utils('options')->set('favourites', $_favourites); | |
| 47 | 50 | |
| 48 | 51 | unset( $response['user']['favourites'] ); |
| 49 | 52 | $meta['favourites'] = $_favourites; |
| 50 | 53 | } |
| 51 | 54 | |
| 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 | - $this->utils( 'options' )->set( 'user', $response['user'] ); | |
| 55 | + $this->utils('options')->set('user', $response['user']); | |
| 69 | 56 | $response['user']['meta'] = Login::get_instance()->user_meta( $meta ); |
| 70 | 57 | |
| 71 | 58 | return $this->success( $response ); |
| 72 | 59 | } |
| 73 | 60 | |
| 74 | - public function verified() { | |
| 61 | + public function verified(){ | |
| 75 | 62 | $funcArgs = [ |
| 76 | - 'api_key' => $this->api_key | |
| 63 | + 'api_key' => $this->api_key | |
| 77 | 64 | ]; |
| 78 | 65 | |
| 79 | - $response = $this->http()->query( 'isVerifiedUser', '', $funcArgs )->post(); | |
| 66 | + $response = $this->http()->query( | |
| 67 | + 'isVerifiedUser', | |
| 68 | + '', | |
| 69 | + $funcArgs | |
| 70 | + )->post(); | |
| 80 | 71 | |
| 81 | - if ( $response ) { | |
| 82 | - $user = $this->utils( 'options' )->get( 'user' ); | |
| 72 | + if( $response ) { | |
| 73 | + $user = $this->utils('options')->get('user'); | |
| 83 | 74 | |
| 84 | 75 | $user['is_verified'] = true; |
| 85 | - $this->utils( 'options' )->set( 'user', $user ); | |
| 76 | + $this->utils('options')->set('user', $user); | |
| 86 | 77 | } |
| 87 | 78 | |
| 88 | 79 | return $response; |
| 89 | 80 | } |
| @@ -91,22 +82,27 @@ | ||
| 91 | 82 | public function get_download_history() { |
| 92 | 83 | $page = $this->get_param( 'page', 1, 'intval' ); |
| 93 | 84 | $per_page = $this->get_param( 'per_page', 10, 'intval' ); |
| 94 | 85 | |
| 95 | - $response = $this->http()->mutation( 'myDownloadHistory', 'data{ name, thumbnail, downloaded_at, slug, type }, current_page, total_page, total', [ | |
| 86 | + $response = $this->http()->mutation( | |
| 87 | + 'myDownloadHistory', | |
| 88 | + 'data{ name, thumbnail, downloaded_at, slug, type }, current_page, total_page', | |
| 89 | + [ | |
| 96 | 90 | 'api_key' => $this->api_key, |
| 97 | 91 | 'per_page' => $per_page, |
| 98 | 92 | "page" => $page |
| 99 | - ] )->post(); | |
| 93 | + ] | |
| 94 | + )->post(); | |
| 100 | 95 | |
| 101 | 96 | if ( is_wp_error( $response ) ) { |
| 102 | - return $this->error( 'invalid_download_history_response', __( $response->get_error_message(), 'templately' ), 'profile/download-history', $response->get_error_code() ); | |
| 97 | + return $this->error( | |
| 98 | + 'invalid_download_history_response', | |
| 99 | + __( $response->get_error_message(), 'templately' ), | |
| 100 | + 'profile/download-history', | |
| 101 | + $response->get_error_code() | |
| 102 | + ); | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if ( isset( $response['total'] ) ) { | |
| 106 | - $this->utils( 'options' )->set( 'total_download_counts', $response['total'] ); | |
| 107 | - } | |
| 108 | - | |
| 109 | 105 | return $response; |
| 110 | 106 | } |
| 111 | 107 | |
| 112 | 108 | public function get_my_favourites() { |
| @@ -122,47 +118,21 @@ | ||
| 122 | 118 | "per_page" => $per_page, |
| 123 | 119 | "plan_type" => $plan_type |
| 124 | 120 | ]; |
| 125 | 121 | |
| 126 | - if ( $type != 'all' ) { | |
| 122 | + if( $type != 'all' ) { | |
| 127 | 123 | $funcArgs['type'] = $type; |
| 128 | 124 | } |
| 129 | 125 | |
| 130 | - $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(); | |
| 126 | + $response = $this->http()->mutation( | |
| 127 | + 'myFavouriteItem', | |
| 128 | + 'total_page, current_page, data { id, name, rating, type, slug, favourite_count, thumbnail, thumbnail2, thumbnail3, price, author{ display_name, name, joined } }', | |
| 129 | + $funcArgs | |
| 130 | + )->post(); | |
| 131 | 131 | |
| 132 | 132 | if ( is_wp_error( $response ) ) { |
| 133 | 133 | return $this->error( 'invalid_my_favourites_response', __( $response->get_error_message(), 'templately' ), 'profile/my-favourites', $response->get_error_code() ); |
| 134 | - } | |
| 135 | - | |
| 136 | - return $response; | |
| 137 | - } | |
| 138 | - | |
| 139 | - public function get_my_purchased_items() { | |
| 140 | - $page = $this->get_param( 'page', 1, 'intval' ); | |
| 141 | - $per_page = $this->get_param( 'per_page', 10, 'intval' ); | |
| 142 | - $_all = $this->get_param( 'all', false ); | |
| 143 | - | |
| 144 | - $funcArgs = [ | |
| 145 | - 'api_key' => $this->api_key, | |
| 146 | - 'page' => $page, | |
| 147 | - 'per_page' => $per_page | |
| 148 | - ]; | |
| 149 | - | |
| 150 | - $query = 'total_page, current_page, data { id, item_id, name, slug, type, platform, thumbnail, purchased_at }'; | |
| 151 | - | |
| 152 | - if ( $_all ) { | |
| 153 | - $query = 'total_page, current_page, data { id, item_id, type, platform }'; | |
| 154 | - $funcArgs['per_page'] = -1; | |
| 155 | - } | |
| 156 | - | |
| 157 | - $response = $this->http()->query( 'myItems', $query, $funcArgs )->post(); | |
| 158 | - | |
| 159 | - if ( $response ) { | |
| 160 | - // $user = $this->utils('options')->get('user'); | |
| 161 | - | |
| 162 | - // $user['is_verified'] = true; | |
| 163 | - // $this->utils('options')->set('user', $user); | |
| 164 | 134 | } |
| 165 | 135 | |
| 166 | 136 | return $response; |
| 167 | 137 | } |
| 168 | 138 | } |