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