| @@ -11,9 +11,9 @@ | ||
| 11 | 11 | public function permission_check( WP_REST_Request $request ) { |
| 12 | 12 | $this->request = $request; |
| 13 | 13 | |
| 14 | 14 | $_route = $request->get_route(); |
| 15 | - if( $_route === '/templately/v1/items/favourite' || $_route === '/templately/v1/items/rating' ) { | |
| 15 | + if( $_route === '/templately/v1/items/favourite' ) { | |
| 16 | 16 | return parent::permission_check( $request ); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | return true; |
| @@ -22,12 +22,9 @@ | ||
| 22 | 22 | public function register_routes() { |
| 23 | 23 | $this->get( 'items', [ $this, 'get_items' ], [ |
| 24 | 24 | 'type' => [ |
| 25 | 25 | 'default' => 'items', |
| 26 | - 'required' => false, | |
| 27 | - // 'validate_callback' => function( $param, $request, $key ){ | |
| 28 | - // return in_array( $param, [ 'items', 'sections', 'blocks', 'packs', 'pages' ], true ); | |
| 29 | - // } | |
| 26 | + 'required' => false | |
| 30 | 27 | ], |
| 31 | 28 | 'platform' => [ |
| 32 | 29 | 'default' => 'elementor', |
| 33 | 30 | 'required' => false |
| @@ -59,9 +56,8 @@ | ||
| 59 | 56 | ], |
| 60 | 57 | ] ); |
| 61 | 58 | |
| 62 | 59 | $this->post( 'items/favourite', [ $this, 'set_favourite' ] ); |
| 63 | - $this->post( 'items/rating', [ $this, 'set_rating' ] ); | |
| 64 | 60 | $this->get( 'items-count', [ $this, 'get_counts' ] ); |
| 65 | 61 | $this->get( 'featured-items', [ $this, 'featured_items' ] ); |
| 66 | 62 | } |
| 67 | 63 | |
| @@ -70,10 +66,9 @@ | ||
| 70 | 66 | * |
| 71 | 67 | * @return string |
| 72 | 68 | */ |
| 73 | 69 | public function get_query_types( $type = 'blocks' ) { |
| 74 | - $item_types = ( $type === 'blocks' || $type === 'sections' ) ? 'items' : trim( $type ); | |
| 75 | - return in_array( $item_types, [ 'items', 'pages', 'packs' ], true ) ? $item_types : false; | |
| 70 | + return ( $type === 'blocks' || $type === 'sections' ) ? 'items' : trim( $type ); | |
| 76 | 71 | } |
| 77 | 72 | |
| 78 | 73 | public function get_items( WP_REST_Request $request ) { |
| 79 | 74 | $_type = $this->get_param( 'type', 'blocks' ); |
| @@ -81,9 +76,8 @@ | ||
| 81 | 76 | $plan = $this->get_param( 'plan', 'all' ); |
| 82 | 77 | $plan_type = $this->get_plan( $plan ); |
| 83 | 78 | $platform = $this->get_param( 'platform', 'elementor' ); |
| 84 | 79 | $search = $this->get_param( 'search' ); |
| 85 | - $include_search = $this->get_param( 'include_search' ); | |
| 86 | 80 | $page = $this->get_param( 'page', 1, 'intval' ); |
| 87 | 81 | $per_page = $this->get_param( 'per_page', 40, 'intval' ); |
| 88 | 82 | $template_type_id = $this->get_param( 'template_type_id', 0, 'intval' ); |
| 89 | 83 | $category_id = $this->get_param( 'category_id', 0, 'intval' ); |
| @@ -117,21 +111,13 @@ | ||
| 117 | 111 | if ( ! empty( $search ) ) { |
| 118 | 112 | $funcArgs['search'] = $search; |
| 119 | 113 | } |
| 120 | 114 | |
| 121 | - if ( ! empty( $include_search ) ) { | |
| 122 | - $funcArgs['include_search'] = $include_search; | |
| 123 | - } | |
| 124 | - | |
| 125 | - $query = 'total_page, current_page, data { id, fullsite_import, name, price, rating, downloads, type, template_type{ slug }, slug, favourite_count, thumbnail, thumbnail2, thumbnail3 }'; | |
| 115 | + $query = 'total_page, current_page, data { id, name, price, rating, downloads, type, slug, favourite_count, thumbnail, thumbnail2, thumbnail3 }'; | |
| 126 | 116 | if( $type !== 'packs' ) { |
| 127 | - $query = 'total_page, current_page, data { id, name, price, rating, downloads, type, template_type{ slug }, slug, favourite_count, dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }, thumbnail }'; | |
| 117 | + $query = 'total_page, current_page, data { id, name, price, rating, downloads, type, slug, favourite_count, dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }, thumbnail }'; | |
| 128 | 118 | } |
| 129 | 119 | |
| 130 | - if( $type === false ) { | |
| 131 | - return $this->error( 'invalid_type_call', __( 'Invalid Type Call', 'templately' ) ); | |
| 132 | - } | |
| 133 | - | |
| 134 | 120 | return $this->http()->query( |
| 135 | 121 | $type, |
| 136 | 122 | $query, |
| 137 | 123 | $funcArgs |
| @@ -151,17 +137,13 @@ | ||
| 151 | 137 | '400' |
| 152 | 138 | ); |
| 153 | 139 | } |
| 154 | 140 | |
| 155 | - if( $type === false ) { | |
| 156 | - return $this->error( 'invalid_type_call', __( 'Invalid Type Call', 'templately' ) ); | |
| 157 | - } | |
| 141 | + $items_params = 'id, name, rating, type, description, slug, price, features, favourite_count, thumbnail, downloads, categories{ id, name, slug }, dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }, tags{ name, id }, categories{ name, id }, screenshots{ url }, banner, pack{ name, slug, items{ id, price, name, type, slug, thumbnail } }, live_url, template_type{ id, name, slug }'; | |
| 142 | + $params = 'data { ' . $items_params . ' }'; | |
| 158 | 143 | |
| 159 | - $items_params = 'id, name, rating, type, description, slug, price, features, favourite_count, thumbnail, downloads, categories{ id, name, slug }, dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }, tags{ name, id }, categories{ name, id }, screenshots{ url }, banner, pack{ id, name, slug, items{ id, price, name, type, slug, thumbnail } }, live_url, template_type{ id, name, slug }'; | |
| 160 | - $params = 'data { ' . $items_params . ', variations { name, slug, type, platform } }'; | |
| 161 | - | |
| 162 | 144 | if ( $type == 'packs' ) { |
| 163 | - $params = 'data { id, fullsite_import, has_settings, name, rating, type, slug, live_url, price, features, favourite_count, thumbnail, downloads, categories{ id, name, slug }, items { ' . $items_params . ' }, variations { name, slug, type, platform } }'; | |
| 145 | + $params = 'data { id, name, rating, type, slug, live_url, price, features, favourite_count, thumbnail, downloads, categories{ id, name, slug }, items { ' . $items_params . ' } }'; | |
| 164 | 146 | } |
| 165 | 147 | |
| 166 | 148 | $response = $this->http()->query( $type, $params, [ 'slug' => $slug ] )->post(); |
| 167 | 149 | |
| @@ -290,56 +272,8 @@ | ||
| 290 | 272 | |
| 291 | 273 | return $_response; |
| 292 | 274 | } |
| 293 | 275 | |
| 294 | - public function set_rating(){ | |
| 295 | - $type_id = $this->get_param( 'type_id', 0, 'intval' ); | |
| 296 | - $itemType = $this->get_param( 'itemType', 'pack' ); | |
| 297 | - $rating = $this->get_param( 'rating', 5, 'intval' ); | |
| 298 | - | |
| 299 | - $query = 'status, message, data'; | |
| 300 | - | |
| 301 | - $funcArgs = [ | |
| 302 | - 'api_key' => $this->api_key, | |
| 303 | - 'type_id' => $type_id, | |
| 304 | - 'type' => $itemType, | |
| 305 | - 'rating' => $rating, | |
| 306 | - ]; | |
| 307 | - | |
| 308 | - $response = $this->http()->mutation( | |
| 309 | - 'review', | |
| 310 | - $query, | |
| 311 | - $funcArgs | |
| 312 | - )->post(); | |
| 313 | - | |
| 314 | - if( is_wp_error( $response ) ) { | |
| 315 | - return $response; | |
| 316 | - } | |
| 317 | - | |
| 318 | - if( empty( $response['data'] ) ) { | |
| 319 | - return $this->error( | |
| 320 | - 'invalid_response', | |
| 321 | - __('Something went wrong.', 'templately'), | |
| 322 | - '/items\/rating', | |
| 323 | - '404' | |
| 324 | - ); | |
| 325 | - } | |
| 326 | - | |
| 327 | - if( ! empty( $response['data'] ) && $response['status'] === 'success' ) { | |
| 328 | - $response['data'] = json_decode( $response['data'], true ); | |
| 329 | - | |
| 330 | - $_ratings = $this->utils('options')->get('reviews', []); | |
| 331 | - // $_reviews = $this->utils( 'helper' )->normalizeReviews( $response['user']['reviews'] ); | |
| 332 | - $_ratings[ $itemType ][ $type_id ] = $rating; | |
| 333 | - $this->utils('options')->set('reviews', $_ratings); | |
| 334 | - | |
| 335 | - $_ratings[ $itemType ][ "avg_$type_id" ] = (float) $response['data']['avg_rating']; | |
| 336 | - $response['data']['reviews'] = $_ratings; | |
| 337 | - } | |
| 338 | - | |
| 339 | - return $response; | |
| 340 | - } | |
| 341 | - | |
| 342 | 276 | public function get_counts(){ |
| 343 | 277 | $defaults = Database::get_transient( 'counts' ); |
| 344 | 278 | if( $defaults ) { |
| 345 | 279 | return $defaults; |
| @@ -431,27 +365,19 @@ | ||
| 431 | 365 | } |
| 432 | 366 | |
| 433 | 367 | /** |
| 434 | 368 | * Get Featured Item List |
| 435 | - * @param WP_REST_Request $request | |
| 436 | 369 | * @return mixed |
| 437 | 370 | */ |
| 438 | - public function featured_items(WP_REST_Request $request){ | |
| 371 | + public function featured_items(){ | |
| 439 | 372 | $defaults = Database::get_transient( 'featuredItems' ); |
| 440 | 373 | if( $defaults ) { |
| 441 | 374 | return $defaults; |
| 442 | 375 | } |
| 443 | 376 | |
| 444 | - $platform = $request->get_param( 'platform' ); | |
| 445 | - $funcArgs = [ | |
| 446 | - // 'page' => 1, | |
| 447 | - // 'per_page' => 10, | |
| 448 | - 'platform' => $platform, | |
| 449 | - ]; | |
| 450 | 377 | $response = $this->http()->query( |
| 451 | 378 | 'featuredItems', |
| 452 | - 'data{ id, name, slug, price, type, thumbnail }', | |
| 453 | - $funcArgs | |
| 379 | + 'data{ id, name, slug, price, type, thumbnail }' | |
| 454 | 380 | )->post(); |
| 455 | 381 | |
| 456 | 382 | if( ! is_wp_error( $response ) ) { |
| 457 | 383 | Database::set_transient( 'featuredItems', $response ); |